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,
129 #define DA_Q_BIT_STRING \
131 "\001NO_SYNC_CACHE" \
141 DA_CCB_PROBE_RC = 0x01,
142 DA_CCB_PROBE_RC16 = 0x02,
143 DA_CCB_PROBE_LBP = 0x03,
144 DA_CCB_PROBE_BLK_LIMITS = 0x04,
145 DA_CCB_PROBE_BDC = 0x05,
146 DA_CCB_PROBE_ATA = 0x06,
147 DA_CCB_BUFFER_IO = 0x07,
149 DA_CCB_DELETE = 0x0B,
151 DA_CCB_PROBE_ZONE = 0x0D,
152 DA_CCB_PROBE_ATA_LOGDIR = 0x0E,
153 DA_CCB_PROBE_ATA_IDDIR = 0x0F,
154 DA_CCB_PROBE_ATA_SUP = 0x10,
155 DA_CCB_PROBE_ATA_ZONE = 0x11,
156 DA_CCB_TYPE_MASK = 0x1F,
157 DA_CCB_RETRY_UA = 0x20
161 * Order here is important for method choice
163 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
164 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
165 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
166 * import taking 5mins.
177 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
178 DA_DELETE_MAX = DA_DELETE_ZERO
182 * For SCSI, host managed drives show up as a separate device type. For
183 * ATA, host managed drives also have a different device signature.
184 * XXX KDM figure out the ATA host managed signature.
188 DA_ZONE_DRIVE_MANAGED = 0x01,
189 DA_ZONE_HOST_AWARE = 0x02,
190 DA_ZONE_HOST_MANAGED = 0x03
194 * We distinguish between these interface cases in addition to the drive type:
195 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC
196 * o ATA drive behind a SCSI translation layer that does not know about
197 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this
198 * case, we would need to share the ATA code with the ada(4) driver.
208 DA_ZONE_FLAG_RZ_SUP = 0x0001,
209 DA_ZONE_FLAG_OPEN_SUP = 0x0002,
210 DA_ZONE_FLAG_CLOSE_SUP = 0x0004,
211 DA_ZONE_FLAG_FINISH_SUP = 0x0008,
212 DA_ZONE_FLAG_RWP_SUP = 0x0010,
213 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP |
214 DA_ZONE_FLAG_OPEN_SUP |
215 DA_ZONE_FLAG_CLOSE_SUP |
216 DA_ZONE_FLAG_FINISH_SUP |
217 DA_ZONE_FLAG_RWP_SUP),
218 DA_ZONE_FLAG_URSWRZ = 0x0020,
219 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
220 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
221 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
222 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET |
223 DA_ZONE_FLAG_OPT_NONSEQ_SET |
224 DA_ZONE_FLAG_MAX_SEQ_SET)
227 static struct da_zone_desc {
230 } da_zone_desc_table[] = {
231 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" },
232 {DA_ZONE_FLAG_OPEN_SUP, "Open" },
233 {DA_ZONE_FLAG_CLOSE_SUP, "Close" },
234 {DA_ZONE_FLAG_FINISH_SUP, "Finish" },
235 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
238 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
240 static da_delete_func_t da_delete_trim;
241 static da_delete_func_t da_delete_unmap;
242 static da_delete_func_t da_delete_ws;
244 static const void * da_delete_functions[] = {
254 static const char *da_delete_method_names[] =
255 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
256 static const char *da_delete_method_desc[] =
257 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
258 "WRITE SAME(10) with UNMAP", "ZERO" };
260 /* Offsets into our private area for storing information */
261 #define ccb_state ppriv_field0
262 #define ccb_bp ppriv_ptr1
267 u_int8_t secs_per_track;
268 u_int32_t secsize; /* Number of bytes/sector */
269 u_int64_t sectors; /* total number sectors */
274 #define UNMAP_RANGE_MAX 0xffffffff
275 #define UNMAP_HEAD_SIZE 8
276 #define UNMAP_RANGE_SIZE 16
277 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
278 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
281 #define WS10_MAX_BLKS 0xffff
282 #define WS16_MAX_BLKS 0xffffffff
283 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
284 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
286 #define DA_WORK_TUR (1 << 16)
289 struct cam_iosched_softc *cam_iosched;
290 struct bio_queue_head delete_run_queue;
291 LIST_HEAD(, ccb_hdr) pending_ccbs;
292 int refcount; /* Active xpt_action() calls */
296 int minimum_cmd_size;
299 int delete_available; /* Delete methods possibly available */
300 da_zone_mode zone_mode;
301 da_zone_interface zone_interface;
302 da_zone_flags zone_flags;
303 struct ata_gp_log_dir ata_logdir;
304 int valid_logdir_len;
305 struct ata_identify_log_pages ata_iddir;
307 uint64_t optimal_seq_zones;
308 uint64_t optimal_nonseq_zones;
309 uint64_t max_seq_zones;
311 uint32_t unmap_max_ranges;
312 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
313 uint64_t ws_max_blks;
314 da_delete_methods delete_method_pref;
315 da_delete_methods delete_method;
316 da_delete_func_t *delete_func;
319 struct disk_params params;
322 struct task sysctl_task;
323 struct sysctl_ctx_list sysctl_ctx;
324 struct sysctl_oid *sysctl_tree;
325 struct callout sendordered_c;
327 uint8_t unmap_buf[UNMAP_BUF_SIZE];
328 struct scsi_read_capacity_data_long rcaplong;
329 struct callout mediapoll_c;
331 struct sysctl_ctx_list sysctl_stats_ctx;
332 struct sysctl_oid *sysctl_stats_tree;
339 #define dadeleteflag(softc, delete_method, enable) \
341 softc->delete_available |= (1 << delete_method); \
343 softc->delete_available &= ~(1 << delete_method); \
346 struct da_quirk_entry {
347 struct scsi_inquiry_pattern inq_pat;
351 static const char quantum[] = "QUANTUM";
352 static const char microp[] = "MICROP";
354 static struct da_quirk_entry da_quirk_table[] =
356 /* SPI, FC devices */
359 * Fujitsu M2513A MO drives.
360 * Tested devices: M2513A2 firmware versions 1200 & 1300.
361 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
362 * Reported by: W.Scholten <whs@xs4all.nl>
364 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
365 /*quirks*/ DA_Q_NO_SYNC_CACHE
369 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
370 /*quirks*/ DA_Q_NO_SYNC_CACHE
374 * This particular Fujitsu drive doesn't like the
375 * synchronize cache command.
376 * Reported by: Tom Jackson <toj@gorilla.net>
378 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
379 /*quirks*/ DA_Q_NO_SYNC_CACHE
383 * This drive doesn't like the synchronize cache command
384 * either. Reported by: Matthew Jacob <mjacob@feral.com>
385 * in NetBSD PR kern/6027, August 24, 1998.
387 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
388 /*quirks*/ DA_Q_NO_SYNC_CACHE
392 * This drive doesn't like the synchronize cache command
393 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
396 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
397 /*quirks*/ DA_Q_NO_SYNC_CACHE
401 * Doesn't like the synchronize cache command.
402 * Reported by: Blaz Zupan <blaz@gold.amis.net>
404 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
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, quantum, "MAVERICK 540S", "*"},
413 /*quirks*/ DA_Q_NO_SYNC_CACHE
417 * Doesn't like the synchronize cache command.
419 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
420 /*quirks*/ DA_Q_NO_SYNC_CACHE
424 * Doesn't like the synchronize cache command.
425 * Reported by: walter@pelissero.de
427 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
428 /*quirks*/ DA_Q_NO_SYNC_CACHE
432 * Doesn't work correctly with 6 byte reads/writes.
433 * Returns illegal request, and points to byte 9 of the
435 * Reported by: Adam McDougall <bsdx@spawnet.com>
437 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
438 /*quirks*/ DA_Q_NO_6_BYTE
442 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
443 /*quirks*/ DA_Q_NO_6_BYTE
447 * Doesn't like the synchronize cache command.
448 * Reported by: walter@pelissero.de
450 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
451 /*quirks*/ DA_Q_NO_SYNC_CACHE
455 * The CISS RAID controllers do not support SYNC_CACHE
457 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
458 /*quirks*/ DA_Q_NO_SYNC_CACHE
462 * The STEC SSDs sometimes hang on UNMAP.
464 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
465 /*quirks*/ DA_Q_NO_UNMAP
469 * VMware returns BUSY status when storage has transient
470 * connectivity problems, so better wait.
472 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"},
473 /*quirks*/ DA_Q_RETRY_BUSY
475 /* USB mass storage devices supported by umass(4) */
478 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
481 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
482 /*quirks*/ DA_Q_NO_SYNC_CACHE
486 * Power Quotient Int. (PQI) USB flash key
489 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
490 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
494 * Creative Nomad MUVO mp3 player (USB)
497 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
498 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
502 * Jungsoft NEXDISK USB flash key
505 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
506 /*quirks*/ DA_Q_NO_SYNC_CACHE
510 * FreeDik USB Mini Data Drive
513 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
514 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
518 * Sigmatel USB Flash MP3 Player
521 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
522 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
526 * Neuros USB Digital Audio Computer
529 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
530 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
534 * SEAGRAND NP-900 MP3 Player
537 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
538 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
542 * iRiver iFP MP3 player (with UMS Firmware)
543 * PR: kern/54881, i386/63941, kern/66124
545 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
546 /*quirks*/ DA_Q_NO_SYNC_CACHE
550 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
553 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
554 /*quirks*/ DA_Q_NO_SYNC_CACHE
558 * ZICPlay USB MP3 Player with FM
561 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
562 /*quirks*/ DA_Q_NO_SYNC_CACHE
566 * TEAC USB floppy mechanisms
568 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
569 /*quirks*/ DA_Q_NO_SYNC_CACHE
573 * Kingston DataTraveler II+ USB Pen-Drive.
574 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
576 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
577 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
586 /*quirks*/ DA_Q_NO_SYNC_CACHE
590 * Motorola E398 Mobile Phone (TransFlash memory card).
591 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
594 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
595 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
599 * Qware BeatZkey! Pro
602 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
603 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
607 * Time DPA20B 1GB MP3 Player
610 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
611 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
615 * Samsung USB key 128Mb
618 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
619 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
623 * Kingston DataTraveler 2.0 USB Flash memory.
626 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
627 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
631 * Creative MUVO Slim mp3 player (USB)
634 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
635 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
639 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
642 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
643 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
647 * SanDisk Micro Cruzer 128MB
650 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
651 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
655 * TOSHIBA TransMemory USB sticks
658 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
659 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
663 * PNY USB 3.0 Flash Drives
665 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*",
666 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16
671 * PR: usb/75578, usb/72344, usb/65436
673 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
674 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
678 * Genesys 6-in-1 Card Reader
681 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
682 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
686 * Rekam Digital CAMERA
689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
690 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
694 * iRiver H10 MP3 player
697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
702 * iRiver U10 MP3 player
705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
713 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
714 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
718 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
721 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
722 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
729 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
730 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
734 * Philips USB Key Audio KEY013
737 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
738 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
745 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
746 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
753 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
754 /*quirks*/ DA_Q_NO_SYNC_CACHE
758 * I/O Magic USB flash - Giga Bank
761 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
762 /*quirks*/ DA_Q_NO_SYNC_CACHE
766 * JoyFly 128mb USB Flash Drive
769 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
770 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
777 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
778 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
782 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
785 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
786 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
790 * Samsung YP-U3 mp3-player
793 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
794 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
797 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
798 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
802 * Sony Cyber-Shot DSC cameras
805 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
806 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
809 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
810 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
813 /* At least several Transcent USB sticks lie on RC16. */
814 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
815 "*"}, /*quirks*/ DA_Q_NO_RC16
819 * I-O Data USB Flash Disk
822 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*",
823 "*"}, /*quirks*/ DA_Q_NO_RC16
825 /* ATA/SATA devices over SAS/USB/... */
827 /* Hitachi Advanced Format (4k) drives */
828 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
832 /* Micron Advanced Format (4k) drives */
833 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" },
837 /* Samsung Advanced Format (4k) drives */
838 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
842 /* Samsung Advanced Format (4k) drives */
843 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
847 /* Samsung Advanced Format (4k) drives */
848 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
852 /* Samsung Advanced Format (4k) drives */
853 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
857 /* Seagate Barracuda Green Advanced Format (4k) drives */
858 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
862 /* Seagate Barracuda Green Advanced Format (4k) drives */
863 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
867 /* Seagate Barracuda Green Advanced Format (4k) drives */
868 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
872 /* Seagate Barracuda Green Advanced Format (4k) drives */
873 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
877 /* Seagate Barracuda Green Advanced Format (4k) drives */
878 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
882 /* Seagate Barracuda Green Advanced Format (4k) drives */
883 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
887 /* Seagate Momentus Advanced Format (4k) drives */
888 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
892 /* Seagate Momentus Advanced Format (4k) drives */
893 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
897 /* Seagate Momentus Advanced Format (4k) drives */
898 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
902 /* Seagate Momentus Advanced Format (4k) drives */
903 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
907 /* Seagate Momentus Advanced Format (4k) drives */
908 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
912 /* Seagate Momentus Advanced Format (4k) drives */
913 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
917 /* Seagate Momentus Advanced Format (4k) drives */
918 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
922 /* Seagate Momentus Advanced Format (4k) drives */
923 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
927 /* Seagate Momentus Advanced Format (4k) drives */
928 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
932 /* Seagate Momentus Advanced Format (4k) drives */
933 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
937 /* Seagate Momentus Advanced Format (4k) drives */
938 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
942 /* Seagate Momentus Advanced Format (4k) drives */
943 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
947 /* Seagate Momentus Advanced Format (4k) drives */
948 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
952 /* Seagate Momentus Advanced Format (4k) drives */
953 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
957 /* Seagate Momentus Thin Advanced Format (4k) drives */
958 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
962 /* Seagate Momentus Thin Advanced Format (4k) drives */
963 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
967 /* WDC Caviar Green Advanced Format (4k) drives */
968 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
972 /* WDC Caviar Green Advanced Format (4k) drives */
973 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
977 /* WDC Caviar Green Advanced Format (4k) drives */
978 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
982 /* WDC Caviar Green Advanced Format (4k) drives */
983 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
987 /* WDC Caviar Green Advanced Format (4k) drives */
988 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
992 /* WDC Caviar Green Advanced Format (4k) drives */
993 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
997 /* WDC Caviar Green Advanced Format (4k) drives */
998 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
1002 /* WDC Caviar Green Advanced Format (4k) drives */
1003 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1007 /* WDC Scorpio Black Advanced Format (4k) drives */
1008 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1012 /* WDC Scorpio Black Advanced Format (4k) drives */
1013 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1017 /* WDC Scorpio Black Advanced Format (4k) drives */
1018 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1022 /* WDC Scorpio Black Advanced Format (4k) drives */
1023 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1027 /* WDC Scorpio Blue Advanced Format (4k) drives */
1028 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1032 /* WDC Scorpio Blue Advanced Format (4k) drives */
1033 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1037 /* WDC Scorpio Blue Advanced Format (4k) drives */
1038 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1042 /* WDC Scorpio Blue Advanced Format (4k) drives */
1043 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1048 * Olympus FE-210 camera
1050 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1051 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1055 * LG UP3S MP3 player
1057 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1058 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1062 * Laser MP3-2GA13 MP3 player
1064 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1065 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1069 * LaCie external 250GB Hard drive des by Porsche
1070 * Submitted by: Ben Stuyts <ben@altesco.nl>
1073 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1074 /*quirks*/ DA_Q_NO_SYNC_CACHE
1079 * Corsair Force 2 SSDs
1080 * 4k optimised & trim only works in 4k requests + 4k aligned
1082 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1087 * Corsair Force 3 SSDs
1088 * 4k optimised & trim only works in 4k requests + 4k aligned
1090 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1095 * Corsair Neutron GTX SSDs
1096 * 4k optimised & trim only works in 4k requests + 4k aligned
1098 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1103 * Corsair Force GT & GS SSDs
1104 * 4k optimised & trim only works in 4k requests + 4k aligned
1106 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1112 * 4k optimised & trim only works in 4k requests + 4k aligned
1114 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1119 * Crucial RealSSD C300 SSDs
1122 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1123 "*" }, /*quirks*/DA_Q_4K
1127 * Intel 320 Series SSDs
1128 * 4k optimised & trim only works in 4k requests + 4k aligned
1130 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1135 * Intel 330 Series SSDs
1136 * 4k optimised & trim only works in 4k requests + 4k aligned
1138 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1143 * Intel 510 Series SSDs
1144 * 4k optimised & trim only works in 4k requests + 4k aligned
1146 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1151 * Intel 520 Series SSDs
1152 * 4k optimised & trim only works in 4k requests + 4k aligned
1154 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1159 * Intel S3610 Series SSDs
1160 * 4k optimised & trim only works in 4k requests + 4k aligned
1162 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" },
1167 * Intel X25-M Series SSDs
1168 * 4k optimised & trim only works in 4k requests + 4k aligned
1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1175 * Kingston E100 Series SSDs
1176 * 4k optimised & trim only works in 4k requests + 4k aligned
1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1183 * Kingston HyperX 3k SSDs
1184 * 4k optimised & trim only works in 4k requests + 4k aligned
1186 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1191 * Marvell SSDs (entry taken from OpenSolaris)
1192 * 4k optimised & trim only works in 4k requests + 4k aligned
1194 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1199 * OCZ Agility 2 SSDs
1200 * 4k optimised & trim only works in 4k requests + 4k aligned
1202 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1207 * OCZ Agility 3 SSDs
1208 * 4k optimised & trim only works in 4k requests + 4k aligned
1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1215 * OCZ Deneva R Series SSDs
1216 * 4k optimised & trim only works in 4k requests + 4k aligned
1218 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1223 * OCZ Vertex 2 SSDs (inc pro series)
1224 * 4k optimised & trim only works in 4k requests + 4k aligned
1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1232 * 4k optimised & trim only works in 4k requests + 4k aligned
1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1240 * 4k optimised & trim only works in 4k requests + 4k aligned
1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1247 * Samsung 830 Series SSDs
1248 * 4k optimised & trim only works in 4k requests + 4k aligned
1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1256 * 4k optimised & trim only works in 4k requests + 4k aligned
1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1264 * 4k optimised & trim only works in 4k requests + 4k aligned
1266 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1271 * Samsung 843T Series SSDs (MZ7WD*)
1272 * Samsung PM851 Series SSDs (MZ7TE*)
1273 * Samsung PM853T Series SSDs (MZ7GE*)
1274 * Samsung SM863 Series SSDs (MZ7KM*)
1277 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1282 * SuperTalent TeraDrive CT SSDs
1283 * 4k optimised & trim only works in 4k requests + 4k aligned
1285 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1290 * XceedIOPS SATA SSDs
1293 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1298 * Hama Innostor USB-Stick
1300 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1301 /*quirks*/DA_Q_NO_RC16
1305 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1306 * Drive Managed SATA hard drive. This drive doesn't report
1307 * in firmware that it is a drive managed SMR drive.
1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1310 /*quirks*/DA_Q_SMR_DM
1314 * MX-ES USB Drive by Mach Xtreme
1316 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1317 /*quirks*/DA_Q_NO_RC16
1321 static disk_strategy_t dastrategy;
1322 static dumper_t dadump;
1323 static periph_init_t dainit;
1324 static void daasync(void *callback_arg, u_int32_t code,
1325 struct cam_path *path, void *arg);
1326 static void dasysctlinit(void *context, int pending);
1327 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1328 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1329 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1330 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1331 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1332 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1333 static void dadeletemethodset(struct da_softc *softc,
1334 da_delete_methods delete_method);
1335 static off_t dadeletemaxsize(struct da_softc *softc,
1336 da_delete_methods delete_method);
1337 static void dadeletemethodchoose(struct da_softc *softc,
1338 da_delete_methods default_method);
1339 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1341 static periph_ctor_t daregister;
1342 static periph_dtor_t dacleanup;
1343 static periph_start_t dastart;
1344 static periph_oninv_t daoninvalidate;
1345 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1346 static void dadone(struct cam_periph *periph,
1347 union ccb *done_ccb);
1348 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1349 u_int32_t sense_flags);
1350 static void daprevent(struct cam_periph *periph, int action);
1351 static void dareprobe(struct cam_periph *periph);
1352 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1354 struct scsi_read_capacity_data_long *rcaplong,
1356 static timeout_t dasendorderedtag;
1357 static void dashutdown(void *arg, int howto);
1358 static timeout_t damediapoll;
1360 #ifndef DA_DEFAULT_POLL_PERIOD
1361 #define DA_DEFAULT_POLL_PERIOD 3
1364 #ifndef DA_DEFAULT_TIMEOUT
1365 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1368 #ifndef DA_DEFAULT_SOFTTIMEOUT
1369 #define DA_DEFAULT_SOFTTIMEOUT 0
1372 #ifndef DA_DEFAULT_RETRY
1373 #define DA_DEFAULT_RETRY 4
1376 #ifndef DA_DEFAULT_SEND_ORDERED
1377 #define DA_DEFAULT_SEND_ORDERED 1
1380 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1381 static int da_retry_count = DA_DEFAULT_RETRY;
1382 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1383 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1384 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1386 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1387 "CAM Direct Access Disk driver");
1388 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1389 &da_poll_period, 0, "Media polling period in seconds");
1390 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1391 &da_retry_count, 0, "Normal I/O retry count");
1392 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1393 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1394 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1395 &da_send_ordered, 0, "Send Ordered Tags");
1397 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1398 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1399 "Soft I/O timeout (ms)");
1400 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1403 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1404 * to the default timeout, we check to see whether an ordered
1405 * tagged transaction is appropriate to prevent simple tag
1406 * starvation. Since we'd like to ensure that there is at least
1407 * 1/2 of the timeout length left for a starved transaction to
1408 * complete after we've sent an ordered tag, we must poll at least
1409 * four times in every timeout period. This takes care of the worst
1410 * case where a starved transaction starts during an interval that
1411 * meets the requirement "don't send an ordered tag" test so it takes
1412 * us two intervals to determine that a tag must be sent.
1414 #ifndef DA_ORDEREDTAG_INTERVAL
1415 #define DA_ORDEREDTAG_INTERVAL 4
1418 static struct periph_driver dadriver =
1421 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1424 PERIPHDRIVER_DECLARE(da, dadriver);
1426 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1429 daopen(struct disk *dp)
1431 struct cam_periph *periph;
1432 struct da_softc *softc;
1435 periph = (struct cam_periph *)dp->d_drv1;
1436 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1440 cam_periph_lock(periph);
1441 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1442 cam_periph_unlock(periph);
1443 cam_periph_release(periph);
1447 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1450 softc = (struct da_softc *)periph->softc;
1453 /* Wait for the disk size update. */
1454 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1457 xpt_print(periph->path, "unable to retrieve capacity data\n");
1459 if (periph->flags & CAM_PERIPH_INVALID)
1462 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1463 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1464 daprevent(periph, PR_PREVENT);
1467 softc->flags &= ~DA_FLAG_PACK_INVALID;
1468 softc->flags |= DA_FLAG_OPEN;
1471 cam_periph_unhold(periph);
1472 cam_periph_unlock(periph);
1475 cam_periph_release(periph);
1481 daclose(struct disk *dp)
1483 struct cam_periph *periph;
1484 struct da_softc *softc;
1488 periph = (struct cam_periph *)dp->d_drv1;
1489 softc = (struct da_softc *)periph->softc;
1490 cam_periph_lock(periph);
1491 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1494 if (cam_periph_hold(periph, PRIBIO) == 0) {
1496 /* Flush disk cache. */
1497 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1498 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1499 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1500 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1501 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1502 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1503 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1505 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1506 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1507 softc->disk->d_devstat);
1508 softc->flags &= ~DA_FLAG_DIRTY;
1509 xpt_release_ccb(ccb);
1512 /* Allow medium removal. */
1513 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1514 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1515 daprevent(periph, PR_ALLOW);
1517 cam_periph_unhold(periph);
1521 * If we've got removeable media, mark the blocksize as
1522 * unavailable, since it could change when new media is
1525 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1526 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1528 softc->flags &= ~DA_FLAG_OPEN;
1529 while (softc->refcount != 0)
1530 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1531 cam_periph_unlock(periph);
1532 cam_periph_release(periph);
1537 daschedule(struct cam_periph *periph)
1539 struct da_softc *softc = (struct da_softc *)periph->softc;
1541 if (softc->state != DA_STATE_NORMAL)
1544 cam_iosched_schedule(softc->cam_iosched, periph);
1548 * Actually translate the requested transfer into one the physical driver
1549 * can understand. The transfer is described by a buf and will include
1550 * only one physical transfer.
1553 dastrategy(struct bio *bp)
1555 struct cam_periph *periph;
1556 struct da_softc *softc;
1558 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1559 softc = (struct da_softc *)periph->softc;
1561 cam_periph_lock(periph);
1564 * If the device has been made invalid, error out
1566 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1567 cam_periph_unlock(periph);
1568 biofinish(bp, NULL, ENXIO);
1572 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1575 * Zone commands must be ordered, because they can depend on the
1576 * effects of previously issued commands, and they may affect
1577 * commands after them.
1579 if (bp->bio_cmd == BIO_ZONE)
1580 bp->bio_flags |= BIO_ORDERED;
1583 * Place it in the queue of disk activities for this disk
1585 cam_iosched_queue_work(softc->cam_iosched, bp);
1588 * Schedule ourselves for performing the work.
1591 cam_periph_unlock(periph);
1597 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1599 struct cam_periph *periph;
1600 struct da_softc *softc;
1602 struct ccb_scsiio csio;
1607 periph = dp->d_drv1;
1608 softc = (struct da_softc *)periph->softc;
1609 cam_periph_lock(periph);
1610 secsize = softc->params.secsize;
1612 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1613 cam_periph_unlock(periph);
1618 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1619 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1620 scsi_read_write(&csio,
1624 /*read*/SCSI_RW_WRITE,
1626 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1629 /*data_ptr*/(u_int8_t *) virtual,
1630 /*dxfer_len*/length,
1631 /*sense_len*/SSD_FULL_SIZE,
1632 da_default_timeout * 1000);
1633 xpt_polled_action((union ccb *)&csio);
1635 error = cam_periph_error((union ccb *)&csio,
1636 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1637 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1638 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1639 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1641 printf("Aborting dump due to I/O error.\n");
1642 cam_periph_unlock(periph);
1647 * Sync the disk cache contents to the physical media.
1649 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1651 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1652 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1653 scsi_synchronize_cache(&csio,
1657 /*begin_lba*/0,/* Cover the whole disk */
1661 xpt_polled_action((union ccb *)&csio);
1663 error = cam_periph_error((union ccb *)&csio,
1664 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1665 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1666 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1667 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1669 xpt_print(periph->path, "Synchronize cache failed\n");
1671 cam_periph_unlock(periph);
1676 dagetattr(struct bio *bp)
1679 struct cam_periph *periph;
1681 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1682 cam_periph_lock(periph);
1683 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1685 cam_periph_unlock(periph);
1687 bp->bio_completed = bp->bio_length;
1697 * Install a global async callback. This callback will
1698 * receive async callbacks like "new device found".
1700 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1702 if (status != CAM_REQ_CMP) {
1703 printf("da: Failed to attach master async callback "
1704 "due to status 0x%x!\n", status);
1705 } else if (da_send_ordered) {
1707 /* Register our shutdown event handler */
1708 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1709 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1710 printf("dainit: shutdown event registration failed!\n");
1715 * Callback from GEOM, called when it has finished cleaning up its
1719 dadiskgonecb(struct disk *dp)
1721 struct cam_periph *periph;
1723 periph = (struct cam_periph *)dp->d_drv1;
1724 cam_periph_release(periph);
1728 daoninvalidate(struct cam_periph *periph)
1730 struct da_softc *softc;
1732 softc = (struct da_softc *)periph->softc;
1735 * De-register any async callbacks.
1737 xpt_register_async(0, daasync, periph, periph->path);
1739 softc->flags |= DA_FLAG_PACK_INVALID;
1741 softc->invalidations++;
1745 * Return all queued I/O with ENXIO.
1746 * XXX Handle any transactions queued to the card
1747 * with XPT_ABORT_CCB.
1749 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1752 * Tell GEOM that we've gone away, we'll get a callback when it is
1753 * done cleaning up its resources.
1755 disk_gone(softc->disk);
1759 dacleanup(struct cam_periph *periph)
1761 struct da_softc *softc;
1763 softc = (struct da_softc *)periph->softc;
1765 cam_periph_unlock(periph);
1767 cam_iosched_fini(softc->cam_iosched);
1770 * If we can't free the sysctl tree, oh well...
1772 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1774 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1775 xpt_print(periph->path,
1776 "can't remove sysctl stats context\n");
1778 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1779 xpt_print(periph->path,
1780 "can't remove sysctl context\n");
1783 callout_drain(&softc->mediapoll_c);
1784 disk_destroy(softc->disk);
1785 callout_drain(&softc->sendordered_c);
1786 free(softc, M_DEVBUF);
1787 cam_periph_lock(periph);
1791 daasync(void *callback_arg, u_int32_t code,
1792 struct cam_path *path, void *arg)
1794 struct cam_periph *periph;
1795 struct da_softc *softc;
1797 periph = (struct cam_periph *)callback_arg;
1799 case AC_FOUND_DEVICE:
1801 struct ccb_getdev *cgd;
1804 cgd = (struct ccb_getdev *)arg;
1808 if (cgd->protocol != PROTO_SCSI)
1810 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1812 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1813 && SID_TYPE(&cgd->inq_data) != T_RBC
1814 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1815 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1819 * Allocate a peripheral instance for
1820 * this device and start the probe
1823 status = cam_periph_alloc(daregister, daoninvalidate,
1825 "da", CAM_PERIPH_BIO,
1827 AC_FOUND_DEVICE, cgd);
1829 if (status != CAM_REQ_CMP
1830 && status != CAM_REQ_INPROG)
1831 printf("daasync: Unable to attach to new device "
1832 "due to status 0x%x\n", status);
1835 case AC_ADVINFO_CHANGED:
1839 buftype = (uintptr_t)arg;
1840 if (buftype == CDAI_TYPE_PHYS_PATH) {
1841 struct da_softc *softc;
1843 softc = periph->softc;
1844 disk_attr_changed(softc->disk, "GEOM::physpath",
1849 case AC_UNIT_ATTENTION:
1852 int error_code, sense_key, asc, ascq;
1854 softc = (struct da_softc *)periph->softc;
1855 ccb = (union ccb *)arg;
1858 * Handle all UNIT ATTENTIONs except our own,
1859 * as they will be handled by daerror().
1861 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1862 scsi_extract_sense_ccb(ccb,
1863 &error_code, &sense_key, &asc, &ascq)) {
1864 if (asc == 0x2A && ascq == 0x09) {
1865 xpt_print(ccb->ccb_h.path,
1866 "Capacity data has changed\n");
1867 softc->flags &= ~DA_FLAG_PROBED;
1869 } else if (asc == 0x28 && ascq == 0x00) {
1870 softc->flags &= ~DA_FLAG_PROBED;
1871 disk_media_changed(softc->disk, M_NOWAIT);
1872 } else if (asc == 0x3F && ascq == 0x03) {
1873 xpt_print(ccb->ccb_h.path,
1874 "INQUIRY data has changed\n");
1875 softc->flags &= ~DA_FLAG_PROBED;
1879 cam_periph_async(periph, code, path, arg);
1883 softc = (struct da_softc *)periph->softc;
1884 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1885 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1886 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1894 struct ccb_hdr *ccbh;
1896 softc = (struct da_softc *)periph->softc;
1898 * Don't fail on the expected unit attention
1901 softc->flags |= DA_FLAG_RETRY_UA;
1902 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1903 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1906 case AC_INQ_CHANGED:
1907 softc = (struct da_softc *)periph->softc;
1908 softc->flags &= ~DA_FLAG_PROBED;
1914 cam_periph_async(periph, code, path, arg);
1918 dasysctlinit(void *context, int pending)
1920 struct cam_periph *periph;
1921 struct da_softc *softc;
1922 char tmpstr[80], tmpstr2[80];
1923 struct ccb_trans_settings cts;
1925 periph = (struct cam_periph *)context;
1927 * periph was held for us when this task was enqueued
1929 if (periph->flags & CAM_PERIPH_INVALID) {
1930 cam_periph_release(periph);
1934 softc = (struct da_softc *)periph->softc;
1935 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1936 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1938 sysctl_ctx_init(&softc->sysctl_ctx);
1939 softc->flags |= DA_FLAG_SCTX_INIT;
1940 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
1941 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1942 CTLFLAG_RD, 0, tmpstr, "device_index");
1943 if (softc->sysctl_tree == NULL) {
1944 printf("dasysctlinit: unable to allocate sysctl tree\n");
1945 cam_periph_release(periph);
1950 * Now register the sysctl handler, so the user can change the value on
1953 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1954 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1955 softc, 0, dadeletemethodsysctl, "A",
1956 "BIO_DELETE execution method");
1957 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1958 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1959 softc, 0, dadeletemaxsysctl, "Q",
1960 "Maximum BIO_DELETE size");
1961 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1962 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1963 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1964 "Minimum CDB size");
1966 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1967 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1968 softc, 0, dazonemodesysctl, "A",
1970 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1971 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
1972 softc, 0, dazonesupsysctl, "A",
1974 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1975 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1976 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
1977 "Optimal Number of Open Sequential Write Preferred Zones");
1978 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1979 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1980 "optimal_nonseq_zones", CTLFLAG_RD,
1981 &softc->optimal_nonseq_zones,
1982 "Optimal Number of Non-Sequentially Written Sequential Write "
1984 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1985 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1986 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
1987 "Maximum Number of Open Sequential Write Required Zones");
1989 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1990 SYSCTL_CHILDREN(softc->sysctl_tree),
1994 &softc->error_inject,
1996 "error_inject leaf");
1998 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1999 SYSCTL_CHILDREN(softc->sysctl_tree),
2005 "Unmapped I/O leaf");
2007 SYSCTL_ADD_INT(&softc->sysctl_ctx,
2008 SYSCTL_CHILDREN(softc->sysctl_tree),
2017 * Add some addressing info.
2019 memset(&cts, 0, sizeof (cts));
2020 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2021 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2022 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2023 cam_periph_lock(periph);
2024 xpt_action((union ccb *)&cts);
2025 cam_periph_unlock(periph);
2026 if (cts.ccb_h.status != CAM_REQ_CMP) {
2027 cam_periph_release(periph);
2030 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2031 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2032 if (fc->valid & CTS_FC_VALID_WWPN) {
2033 softc->wwpn = fc->wwpn;
2034 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2035 SYSCTL_CHILDREN(softc->sysctl_tree),
2036 OID_AUTO, "wwpn", CTLFLAG_RD,
2037 &softc->wwpn, "World Wide Port Name");
2043 * Now add some useful stats.
2044 * XXX These should live in cam_periph and be common to all periphs
2046 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2047 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2048 CTLFLAG_RD, 0, "Statistics");
2049 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2050 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2056 "Transport errors reported by the SIM");
2057 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2058 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2064 "Device timeouts reported by the SIM");
2065 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2066 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2068 "pack_invalidations",
2070 &softc->invalidations,
2072 "Device pack invalidations");
2075 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2076 softc->sysctl_tree);
2078 cam_periph_release(periph);
2082 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2086 struct da_softc *softc;
2088 softc = (struct da_softc *)arg1;
2090 value = softc->disk->d_delmaxsize;
2091 error = sysctl_handle_64(oidp, &value, 0, req);
2092 if ((error != 0) || (req->newptr == NULL))
2095 /* only accept values smaller than the calculated value */
2096 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2099 softc->disk->d_delmaxsize = value;
2105 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2109 value = *(int *)arg1;
2111 error = sysctl_handle_int(oidp, &value, 0, req);
2114 || (req->newptr == NULL))
2118 * Acceptable values here are 6, 10, 12 or 16.
2122 else if ((value > 6)
2125 else if ((value > 10)
2128 else if (value > 12)
2131 *(int *)arg1 = value;
2137 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2142 value = da_default_softtimeout / SBT_1MS;
2144 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2145 if ((error != 0) || (req->newptr == NULL))
2148 /* XXX Should clip this to a reasonable level */
2149 if (value > da_default_timeout * 1000)
2152 da_default_softtimeout = value * SBT_1MS;
2157 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2160 softc->delete_method = delete_method;
2161 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2162 softc->delete_func = da_delete_functions[delete_method];
2164 if (softc->delete_method > DA_DELETE_DISABLE)
2165 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2167 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2171 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2175 switch(delete_method) {
2176 case DA_DELETE_UNMAP:
2177 sectors = (off_t)softc->unmap_max_lba;
2179 case DA_DELETE_ATA_TRIM:
2180 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2182 case DA_DELETE_WS16:
2183 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2185 case DA_DELETE_ZERO:
2186 case DA_DELETE_WS10:
2187 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2193 return (off_t)softc->params.secsize *
2194 omin(sectors, softc->params.sectors);
2198 daprobedone(struct cam_periph *periph, union ccb *ccb)
2200 struct da_softc *softc;
2202 softc = (struct da_softc *)periph->softc;
2204 dadeletemethodchoose(softc, DA_DELETE_NONE);
2206 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2210 snprintf(buf, sizeof(buf), "Delete methods: <");
2212 for (i = 0; i <= DA_DELETE_MAX; i++) {
2213 if ((softc->delete_available & (1 << i)) == 0 &&
2214 i != softc->delete_method)
2217 strlcat(buf, ",", sizeof(buf));
2218 strlcat(buf, da_delete_method_names[i],
2220 if (i == softc->delete_method)
2221 strlcat(buf, "(*)", sizeof(buf));
2224 strlcat(buf, ">", sizeof(buf));
2225 printf("%s%d: %s\n", periph->periph_name,
2226 periph->unit_number, buf);
2230 * Since our peripheral may be invalidated by an error
2231 * above or an external event, we must release our CCB
2232 * before releasing the probe lock on the peripheral.
2233 * The peripheral will only go away once the last lock
2234 * is removed, and we need it around for the CCB release
2237 xpt_release_ccb(ccb);
2238 softc->state = DA_STATE_NORMAL;
2239 softc->flags |= DA_FLAG_PROBED;
2241 wakeup(&softc->disk->d_mediasize);
2242 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2243 softc->flags |= DA_FLAG_ANNOUNCED;
2244 cam_periph_unhold(periph);
2246 cam_periph_release_locked(periph);
2250 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2254 /* If available, prefer the method requested by user. */
2255 i = softc->delete_method_pref;
2256 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2257 if (methods & (1 << i)) {
2258 dadeletemethodset(softc, i);
2262 /* Use the pre-defined order to choose the best performing delete. */
2263 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2264 if (i == DA_DELETE_ZERO)
2266 if (softc->delete_available & (1 << i)) {
2267 dadeletemethodset(softc, i);
2272 /* Fallback to default. */
2273 dadeletemethodset(softc, default_method);
2277 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2281 struct da_softc *softc;
2282 int i, error, methods, value;
2284 softc = (struct da_softc *)arg1;
2286 value = softc->delete_method;
2287 if (value < 0 || value > DA_DELETE_MAX)
2290 p = da_delete_method_names[value];
2291 strncpy(buf, p, sizeof(buf));
2292 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2293 if (error != 0 || req->newptr == NULL)
2295 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2296 for (i = 0; i <= DA_DELETE_MAX; i++) {
2297 if (strcmp(buf, da_delete_method_names[i]) == 0)
2300 if (i > DA_DELETE_MAX)
2302 softc->delete_method_pref = i;
2303 dadeletemethodchoose(softc, DA_DELETE_NONE);
2308 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2311 struct da_softc *softc;
2314 softc = (struct da_softc *)arg1;
2316 switch (softc->zone_mode) {
2317 case DA_ZONE_DRIVE_MANAGED:
2318 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2320 case DA_ZONE_HOST_AWARE:
2321 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2323 case DA_ZONE_HOST_MANAGED:
2324 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2328 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2332 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2338 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2341 struct da_softc *softc;
2346 softc = (struct da_softc *)arg1;
2350 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2352 for (i = 0; i < sizeof(da_zone_desc_table) /
2353 sizeof(da_zone_desc_table[0]); i++) {
2354 if (softc->zone_flags & da_zone_desc_table[i].value) {
2356 sbuf_printf(&sb, ", ");
2359 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2364 sbuf_printf(&sb, "None");
2368 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2374 daregister(struct cam_periph *periph, void *arg)
2376 struct da_softc *softc;
2377 struct ccb_pathinq cpi;
2378 struct ccb_getdev *cgd;
2382 cgd = (struct ccb_getdev *)arg;
2384 printf("daregister: no getdev CCB, can't register device\n");
2385 return(CAM_REQ_CMP_ERR);
2388 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2391 if (softc == NULL) {
2392 printf("daregister: Unable to probe new device. "
2393 "Unable to allocate softc\n");
2394 return(CAM_REQ_CMP_ERR);
2397 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2398 printf("daregister: Unable to probe new device. "
2399 "Unable to allocate iosched memory\n");
2400 free(softc, M_DEVBUF);
2401 return(CAM_REQ_CMP_ERR);
2404 LIST_INIT(&softc->pending_ccbs);
2405 softc->state = DA_STATE_PROBE_RC;
2406 bioq_init(&softc->delete_run_queue);
2407 if (SID_IS_REMOVABLE(&cgd->inq_data))
2408 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2409 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2410 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2411 softc->ws_max_blks = WS16_MAX_BLKS;
2412 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2413 softc->rotating = 1;
2415 periph->softc = softc;
2418 * See if this device has any quirks.
2420 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2421 (caddr_t)da_quirk_table,
2422 nitems(da_quirk_table),
2423 sizeof(*da_quirk_table), scsi_inquiry_match);
2426 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2428 softc->quirks = DA_Q_NONE;
2430 /* Check if the SIM does not want 6 byte commands */
2431 bzero(&cpi, sizeof(cpi));
2432 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2433 cpi.ccb_h.func_code = XPT_PATH_INQ;
2434 xpt_action((union ccb *)&cpi);
2435 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2436 softc->quirks |= DA_Q_NO_6_BYTE;
2438 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2439 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2440 else if (softc->quirks & DA_Q_SMR_DM)
2441 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2443 softc->zone_mode = DA_ZONE_NONE;
2445 if (softc->zone_mode != DA_ZONE_NONE) {
2446 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2447 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2448 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2450 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2452 softc->zone_interface = DA_ZONE_IF_SCSI;
2455 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2458 * Take an exclusive refcount on the periph while dastart is called
2459 * to finish the probe. The reference will be dropped in dadone at
2462 (void)cam_periph_hold(periph, PRIBIO);
2465 * Schedule a periodic event to occasionally send an
2466 * ordered tag to a device.
2468 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2469 callout_reset(&softc->sendordered_c,
2470 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2471 dasendorderedtag, softc);
2473 cam_periph_unlock(periph);
2475 * RBC devices don't have to support READ(6), only READ(10).
2477 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2478 softc->minimum_cmd_size = 10;
2480 softc->minimum_cmd_size = 6;
2483 * Load the user's default, if any.
2485 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2486 periph->unit_number);
2487 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2490 * 6, 10, 12 and 16 are the currently permissible values.
2492 if (softc->minimum_cmd_size < 6)
2493 softc->minimum_cmd_size = 6;
2494 else if ((softc->minimum_cmd_size > 6)
2495 && (softc->minimum_cmd_size <= 10))
2496 softc->minimum_cmd_size = 10;
2497 else if ((softc->minimum_cmd_size > 10)
2498 && (softc->minimum_cmd_size <= 12))
2499 softc->minimum_cmd_size = 12;
2500 else if (softc->minimum_cmd_size > 12)
2501 softc->minimum_cmd_size = 16;
2503 /* Predict whether device may support READ CAPACITY(16). */
2504 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2505 (softc->quirks & DA_Q_NO_RC16) == 0) {
2506 softc->flags |= DA_FLAG_CAN_RC16;
2507 softc->state = DA_STATE_PROBE_RC16;
2511 * Register this media as a disk.
2513 softc->disk = disk_alloc();
2514 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2515 periph->unit_number, 0,
2516 DEVSTAT_BS_UNAVAILABLE,
2517 SID_TYPE(&cgd->inq_data) |
2518 XPORT_DEVSTAT_TYPE(cpi.transport),
2519 DEVSTAT_PRIORITY_DISK);
2520 softc->disk->d_open = daopen;
2521 softc->disk->d_close = daclose;
2522 softc->disk->d_strategy = dastrategy;
2523 softc->disk->d_dump = dadump;
2524 softc->disk->d_getattr = dagetattr;
2525 softc->disk->d_gone = dadiskgonecb;
2526 softc->disk->d_name = "da";
2527 softc->disk->d_drv1 = periph;
2529 softc->maxio = DFLTPHYS; /* traditional default */
2530 else if (cpi.maxio > MAXPHYS)
2531 softc->maxio = MAXPHYS; /* for safety */
2533 softc->maxio = cpi.maxio;
2534 softc->disk->d_maxsize = softc->maxio;
2535 softc->disk->d_unit = periph->unit_number;
2536 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2537 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2538 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2539 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2540 softc->unmappedio = 1;
2541 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2542 xpt_print(periph->path, "UNMAPPED\n");
2544 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2545 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2546 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2547 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2548 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2549 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2550 softc->disk->d_hba_vendor = cpi.hba_vendor;
2551 softc->disk->d_hba_device = cpi.hba_device;
2552 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2553 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2556 * Acquire a reference to the periph before we register with GEOM.
2557 * We'll release this reference once GEOM calls us back (via
2558 * dadiskgonecb()) telling us that our provider has been freed.
2560 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2561 xpt_print(periph->path, "%s: lost periph during "
2562 "registration!\n", __func__);
2563 cam_periph_lock(periph);
2564 return (CAM_REQ_CMP_ERR);
2567 disk_create(softc->disk, DISK_VERSION);
2568 cam_periph_lock(periph);
2571 * Add async callbacks for events of interest.
2572 * I don't bother checking if this fails as,
2573 * in most cases, the system will function just
2574 * fine without them and the only alternative
2575 * would be to not attach the device on failure.
2577 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2578 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2579 AC_INQ_CHANGED, daasync, periph, periph->path);
2582 * Emit an attribute changed notification just in case
2583 * physical path information arrived before our async
2584 * event handler was registered, but after anyone attaching
2585 * to our disk device polled it.
2587 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2590 * Schedule a periodic media polling events.
2592 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2593 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2594 (cgd->inq_flags & SID_AEN) == 0 &&
2595 da_poll_period != 0)
2596 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2597 damediapoll, periph);
2599 xpt_schedule(periph, CAM_PRIORITY_DEV);
2601 return(CAM_REQ_CMP);
2605 da_zone_bio_to_scsi(int disk_zone_cmd)
2607 switch (disk_zone_cmd) {
2608 case DISK_ZONE_OPEN:
2609 return ZBC_OUT_SA_OPEN;
2610 case DISK_ZONE_CLOSE:
2611 return ZBC_OUT_SA_CLOSE;
2612 case DISK_ZONE_FINISH:
2613 return ZBC_OUT_SA_FINISH;
2615 return ZBC_OUT_SA_RWP;
2622 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2625 struct da_softc *softc;
2630 if (bp->bio_cmd != BIO_ZONE) {
2635 softc = periph->softc;
2637 switch (bp->bio_zone.zone_cmd) {
2638 case DISK_ZONE_OPEN:
2639 case DISK_ZONE_CLOSE:
2640 case DISK_ZONE_FINISH:
2641 case DISK_ZONE_RWP: {
2646 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2647 if (zone_sa == -1) {
2648 xpt_print(periph->path, "Cannot translate zone "
2649 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2655 lba = bp->bio_zone.zone_params.rwp.id;
2657 if (bp->bio_zone.zone_params.rwp.flags &
2658 DISK_ZONE_RWP_FLAG_ALL)
2659 zone_flags |= ZBC_OUT_ALL;
2661 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2662 scsi_zbc_out(&ccb->csio,
2663 /*retries*/ da_retry_count,
2665 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2666 /*service_action*/ zone_sa,
2668 /*zone_flags*/ zone_flags,
2671 /*sense_len*/ SSD_FULL_SIZE,
2672 /*timeout*/ da_default_timeout * 1000);
2675 * Note that in this case, even though we can
2676 * technically use NCQ, we don't bother for several
2678 * 1. It hasn't been tested on a SAT layer that
2679 * supports it. This is new as of SAT-4.
2680 * 2. Even when there is a SAT layer that supports
2681 * it, that SAT layer will also probably support
2682 * ZBC -> ZAC translation, since they are both
2683 * in the SAT-4 spec.
2684 * 3. Translation will likely be preferable to ATA
2685 * passthrough. LSI / Avago at least single
2686 * steps ATA passthrough commands in the HBA,
2687 * regardless of protocol, so unless that
2688 * changes, there is a performance penalty for
2689 * doing ATA passthrough no matter whether
2690 * you're using NCQ/FPDMA, DMA or PIO.
2691 * 4. It requires a 32-byte CDB, which at least at
2692 * this point in CAM requires a CDB pointer, which
2693 * would require us to allocate an additional bit
2694 * of storage separate from the CCB.
2696 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2697 /*retries*/ da_retry_count,
2699 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2701 /*zm_action*/ zone_sa,
2703 /*zone_flags*/ zone_flags,
2706 /*cdb_storage*/ NULL,
2707 /*cdb_storage_len*/ 0,
2708 /*sense_len*/ SSD_FULL_SIZE,
2709 /*timeout*/ da_default_timeout * 1000);
2712 xpt_print(periph->path,
2713 "scsi_ata_zac_mgmt_out() returned an "
2722 case DISK_ZONE_REPORT_ZONES: {
2724 uint32_t num_entries, alloc_size;
2725 struct disk_zone_report *rep;
2727 rep = &bp->bio_zone.zone_params.report;
2729 num_entries = rep->entries_allocated;
2730 if (num_entries == 0) {
2731 xpt_print(periph->path, "No entries allocated for "
2732 "Report Zones request\n");
2736 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2737 (sizeof(struct scsi_report_zones_desc) * num_entries);
2738 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2739 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2740 if (rz_ptr == NULL) {
2741 xpt_print(periph->path, "Unable to allocate memory "
2742 "for Report Zones request\n");
2747 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2748 scsi_zbc_in(&ccb->csio,
2749 /*retries*/ da_retry_count,
2751 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2752 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2753 /*zone_start_lba*/ rep->starting_id,
2754 /*zone_options*/ rep->rep_options,
2755 /*data_ptr*/ rz_ptr,
2756 /*dxfer_len*/ alloc_size,
2757 /*sense_len*/ SSD_FULL_SIZE,
2758 /*timeout*/ da_default_timeout * 1000);
2761 * Note that in this case, even though we can
2762 * technically use NCQ, we don't bother for several
2764 * 1. It hasn't been tested on a SAT layer that
2765 * supports it. This is new as of SAT-4.
2766 * 2. Even when there is a SAT layer that supports
2767 * it, that SAT layer will also probably support
2768 * ZBC -> ZAC translation, since they are both
2769 * in the SAT-4 spec.
2770 * 3. Translation will likely be preferable to ATA
2771 * passthrough. LSI / Avago at least single
2772 * steps ATA passthrough commands in the HBA,
2773 * regardless of protocol, so unless that
2774 * changes, there is a performance penalty for
2775 * doing ATA passthrough no matter whether
2776 * you're using NCQ/FPDMA, DMA or PIO.
2777 * 4. It requires a 32-byte CDB, which at least at
2778 * this point in CAM requires a CDB pointer, which
2779 * would require us to allocate an additional bit
2780 * of storage separate from the CCB.
2782 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2783 /*retries*/ da_retry_count,
2785 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2787 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2788 /*zone_id*/ rep->starting_id,
2789 /*zone_flags*/ rep->rep_options,
2790 /*data_ptr*/ rz_ptr,
2791 /*dxfer_len*/ alloc_size,
2792 /*cdb_storage*/ NULL,
2793 /*cdb_storage_len*/ 0,
2794 /*sense_len*/ SSD_FULL_SIZE,
2795 /*timeout*/ da_default_timeout * 1000);
2798 xpt_print(periph->path,
2799 "scsi_ata_zac_mgmt_in() returned an "
2806 * For BIO_ZONE, this isn't normally needed. However, it
2807 * is used by devstat_end_transaction_bio() to determine
2808 * how much data was transferred.
2811 * XXX KDM we have a problem. But I'm not sure how to fix
2812 * it. devstat uses bio_bcount - bio_resid to calculate
2813 * the amount of data transferred. The GEOM disk code
2814 * uses bio_length - bio_resid to calculate the amount of
2815 * data in bio_completed. We have different structure
2816 * sizes above and below the ada(4) driver. So, if we
2817 * use the sizes above, the amount transferred won't be
2818 * quite accurate for devstat. If we use different sizes
2819 * for bio_bcount and bio_length (above and below
2820 * respectively), then the residual needs to match one or
2821 * the other. Everything is calculated after the bio
2822 * leaves the driver, so changing the values around isn't
2823 * really an option. For now, just set the count to the
2824 * passed in length. This means that the calculations
2825 * above (e.g. bio_completed) will be correct, but the
2826 * amount of data reported to devstat will be slightly
2827 * under or overstated.
2829 bp->bio_bcount = bp->bio_length;
2835 case DISK_ZONE_GET_PARAMS: {
2836 struct disk_zone_disk_params *params;
2838 params = &bp->bio_zone.zone_params.disk_params;
2839 bzero(params, sizeof(*params));
2841 switch (softc->zone_mode) {
2842 case DA_ZONE_DRIVE_MANAGED:
2843 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2845 case DA_ZONE_HOST_AWARE:
2846 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2848 case DA_ZONE_HOST_MANAGED:
2849 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2853 params->zone_mode = DISK_ZONE_MODE_NONE;
2857 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2858 params->flags |= DISK_ZONE_DISK_URSWRZ;
2860 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2861 params->optimal_seq_zones = softc->optimal_seq_zones;
2862 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2865 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2866 params->optimal_nonseq_zones =
2867 softc->optimal_nonseq_zones;
2868 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2871 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2872 params->max_seq_zones = softc->max_seq_zones;
2873 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2875 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2876 params->flags |= DISK_ZONE_RZ_SUP;
2878 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2879 params->flags |= DISK_ZONE_OPEN_SUP;
2881 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2882 params->flags |= DISK_ZONE_CLOSE_SUP;
2884 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2885 params->flags |= DISK_ZONE_FINISH_SUP;
2887 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2888 params->flags |= DISK_ZONE_RWP_SUP;
2899 dastart(struct cam_periph *periph, union ccb *start_ccb)
2901 struct da_softc *softc;
2903 softc = (struct da_softc *)periph->softc;
2905 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2908 switch (softc->state) {
2909 case DA_STATE_NORMAL:
2915 bp = cam_iosched_next_bio(softc->cam_iosched);
2917 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2918 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2919 scsi_test_unit_ready(&start_ccb->csio,
2920 /*retries*/ da_retry_count,
2924 da_default_timeout * 1000);
2925 start_ccb->ccb_h.ccb_bp = NULL;
2926 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2927 xpt_action(start_ccb);
2929 xpt_release_ccb(start_ccb);
2933 if (bp->bio_cmd == BIO_DELETE) {
2934 if (softc->delete_func != NULL) {
2935 softc->delete_func(periph, start_ccb, bp);
2938 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2939 biofinish(bp, NULL, 0);
2944 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2945 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2946 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2949 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2950 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2951 softc->flags &= ~DA_FLAG_NEED_OTAG;
2952 softc->flags |= DA_FLAG_WAS_OTAG;
2953 tag_code = MSG_ORDERED_Q_TAG;
2955 tag_code = MSG_SIMPLE_Q_TAG;
2958 switch (bp->bio_cmd) {
2965 biotrack(bp, __func__);
2967 if (bp->bio_cmd == BIO_WRITE) {
2968 softc->flags |= DA_FLAG_DIRTY;
2969 rw_op = SCSI_RW_WRITE;
2971 rw_op = SCSI_RW_READ;
2974 data_ptr = bp->bio_data;
2975 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2976 rw_op |= SCSI_RW_BIO;
2980 scsi_read_write(&start_ccb->csio,
2981 /*retries*/da_retry_count,
2983 /*tag_action*/tag_code,
2986 softc->minimum_cmd_size,
2987 /*lba*/bp->bio_pblkno,
2988 /*block_count*/bp->bio_bcount /
2989 softc->params.secsize,
2991 /*dxfer_len*/ bp->bio_bcount,
2992 /*sense_len*/SSD_FULL_SIZE,
2993 da_default_timeout * 1000);
2994 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
2995 start_ccb->csio.bio = bp;
3001 * BIO_FLUSH doesn't currently communicate
3002 * range data, so we synchronize the cache
3003 * over the whole disk. We also force
3004 * ordered tag semantics the flush applies
3005 * to all previously queued I/O.
3007 scsi_synchronize_cache(&start_ccb->csio,
3014 da_default_timeout*1000);
3017 int error, queue_ccb;
3021 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3023 || (queue_ccb == 0)) {
3024 biofinish(bp, NULL, error);
3025 xpt_release_ccb(start_ccb);
3031 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3032 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3033 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3036 LIST_INSERT_HEAD(&softc->pending_ccbs,
3037 &start_ccb->ccb_h, periph_links.le);
3039 /* We expect a unit attention from this device */
3040 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3041 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3042 softc->flags &= ~DA_FLAG_RETRY_UA;
3045 start_ccb->ccb_h.ccb_bp = bp;
3047 cam_periph_unlock(periph);
3048 xpt_action(start_ccb);
3049 cam_periph_lock(periph);
3052 /* May have more work to do, so ensure we stay scheduled */
3056 case DA_STATE_PROBE_RC:
3058 struct scsi_read_capacity_data *rcap;
3060 rcap = (struct scsi_read_capacity_data *)
3061 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3063 printf("dastart: Couldn't malloc read_capacity data\n");
3064 /* da_free_periph??? */
3067 scsi_read_capacity(&start_ccb->csio,
3068 /*retries*/da_retry_count,
3074 start_ccb->ccb_h.ccb_bp = NULL;
3075 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3076 xpt_action(start_ccb);
3079 case DA_STATE_PROBE_RC16:
3081 struct scsi_read_capacity_data_long *rcaplong;
3083 rcaplong = (struct scsi_read_capacity_data_long *)
3084 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3085 if (rcaplong == NULL) {
3086 printf("dastart: Couldn't malloc read_capacity data\n");
3087 /* da_free_periph??? */
3090 scsi_read_capacity_16(&start_ccb->csio,
3091 /*retries*/ da_retry_count,
3093 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3097 /*rcap_buf*/ (uint8_t *)rcaplong,
3098 /*rcap_buf_len*/ sizeof(*rcaplong),
3099 /*sense_len*/ SSD_FULL_SIZE,
3100 /*timeout*/ da_default_timeout * 1000);
3101 start_ccb->ccb_h.ccb_bp = NULL;
3102 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3103 xpt_action(start_ccb);
3106 case DA_STATE_PROBE_LBP:
3108 struct scsi_vpd_logical_block_prov *lbp;
3110 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3112 * If we get here we don't support any SBC-3 delete
3113 * methods with UNMAP as the Logical Block Provisioning
3114 * VPD page support is required for devices which
3115 * support it according to T10/1799-D Revision 31
3116 * however older revisions of the spec don't mandate
3117 * this so we currently don't remove these methods
3118 * from the available set.
3120 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3124 lbp = (struct scsi_vpd_logical_block_prov *)
3125 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3128 printf("dastart: Couldn't malloc lbp data\n");
3129 /* da_free_periph??? */
3133 scsi_inquiry(&start_ccb->csio,
3134 /*retries*/da_retry_count,
3136 /*tag_action*/MSG_SIMPLE_Q_TAG,
3137 /*inq_buf*/(u_int8_t *)lbp,
3138 /*inq_len*/sizeof(*lbp),
3140 /*page_code*/SVPD_LBP,
3141 /*sense_len*/SSD_MIN_SIZE,
3142 /*timeout*/da_default_timeout * 1000);
3143 start_ccb->ccb_h.ccb_bp = NULL;
3144 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3145 xpt_action(start_ccb);
3148 case DA_STATE_PROBE_BLK_LIMITS:
3150 struct scsi_vpd_block_limits *block_limits;
3152 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3153 /* Not supported skip to next probe */
3154 softc->state = DA_STATE_PROBE_BDC;
3158 block_limits = (struct scsi_vpd_block_limits *)
3159 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3161 if (block_limits == NULL) {
3162 printf("dastart: Couldn't malloc block_limits data\n");
3163 /* da_free_periph??? */
3167 scsi_inquiry(&start_ccb->csio,
3168 /*retries*/da_retry_count,
3170 /*tag_action*/MSG_SIMPLE_Q_TAG,
3171 /*inq_buf*/(u_int8_t *)block_limits,
3172 /*inq_len*/sizeof(*block_limits),
3174 /*page_code*/SVPD_BLOCK_LIMITS,
3175 /*sense_len*/SSD_MIN_SIZE,
3176 /*timeout*/da_default_timeout * 1000);
3177 start_ccb->ccb_h.ccb_bp = NULL;
3178 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3179 xpt_action(start_ccb);
3182 case DA_STATE_PROBE_BDC:
3184 struct scsi_vpd_block_characteristics *bdc;
3186 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3187 softc->state = DA_STATE_PROBE_ATA;
3191 bdc = (struct scsi_vpd_block_characteristics *)
3192 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3195 printf("dastart: Couldn't malloc bdc data\n");
3196 /* da_free_periph??? */
3200 scsi_inquiry(&start_ccb->csio,
3201 /*retries*/da_retry_count,
3203 /*tag_action*/MSG_SIMPLE_Q_TAG,
3204 /*inq_buf*/(u_int8_t *)bdc,
3205 /*inq_len*/sizeof(*bdc),
3207 /*page_code*/SVPD_BDC,
3208 /*sense_len*/SSD_MIN_SIZE,
3209 /*timeout*/da_default_timeout * 1000);
3210 start_ccb->ccb_h.ccb_bp = NULL;
3211 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3212 xpt_action(start_ccb);
3215 case DA_STATE_PROBE_ATA:
3217 struct ata_params *ata_params;
3219 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3220 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3221 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3223 * Note that if the ATA VPD page isn't
3224 * supported, we aren't talking to an ATA
3225 * device anyway. Support for that VPD
3226 * page is mandatory for SCSI to ATA (SAT)
3227 * translation layers.
3229 softc->state = DA_STATE_PROBE_ZONE;
3232 daprobedone(periph, start_ccb);
3236 ata_params = (struct ata_params*)
3237 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3239 if (ata_params == NULL) {
3240 xpt_print(periph->path, "Couldn't malloc ata_params "
3242 /* da_free_periph??? */
3246 scsi_ata_identify(&start_ccb->csio,
3247 /*retries*/da_retry_count,
3249 /*tag_action*/MSG_SIMPLE_Q_TAG,
3250 /*data_ptr*/(u_int8_t *)ata_params,
3251 /*dxfer_len*/sizeof(*ata_params),
3252 /*sense_len*/SSD_FULL_SIZE,
3253 /*timeout*/da_default_timeout * 1000);
3254 start_ccb->ccb_h.ccb_bp = NULL;
3255 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3256 xpt_action(start_ccb);
3259 case DA_STATE_PROBE_ATA_LOGDIR:
3261 struct ata_gp_log_dir *log_dir;
3266 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3268 * If we don't have log support, not much point in
3269 * trying to probe zone support.
3271 daprobedone(periph, start_ccb);
3276 * If we have an ATA device (the SCSI ATA Information VPD
3277 * page should be present and the ATA identify should have
3278 * succeeded) and it supports logs, ask for the log directory.
3281 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3282 if (log_dir == NULL) {
3283 xpt_print(periph->path, "Couldn't malloc log_dir "
3285 daprobedone(periph, start_ccb);
3289 retval = scsi_ata_read_log(&start_ccb->csio,
3290 /*retries*/ da_retry_count,
3292 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3293 /*log_address*/ ATA_LOG_DIRECTORY,
3296 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3297 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3298 /*data_ptr*/ (uint8_t *)log_dir,
3299 /*dxfer_len*/ sizeof(*log_dir),
3300 /*sense_len*/ SSD_FULL_SIZE,
3301 /*timeout*/ da_default_timeout * 1000);
3304 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3305 free(log_dir, M_SCSIDA);
3306 daprobedone(periph, start_ccb);
3309 start_ccb->ccb_h.ccb_bp = NULL;
3310 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3311 xpt_action(start_ccb);
3314 case DA_STATE_PROBE_ATA_IDDIR:
3316 struct ata_identify_log_pages *id_dir;
3322 * Check here to see whether the Identify Device log is
3323 * supported in the directory of logs. If so, continue
3324 * with requesting the log of identify device pages.
3326 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3327 daprobedone(periph, start_ccb);
3331 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3332 if (id_dir == NULL) {
3333 xpt_print(periph->path, "Couldn't malloc id_dir "
3335 daprobedone(periph, start_ccb);
3339 retval = scsi_ata_read_log(&start_ccb->csio,
3340 /*retries*/ da_retry_count,
3342 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3343 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3344 /*page_number*/ ATA_IDL_PAGE_LIST,
3346 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3347 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3348 /*data_ptr*/ (uint8_t *)id_dir,
3349 /*dxfer_len*/ sizeof(*id_dir),
3350 /*sense_len*/ SSD_FULL_SIZE,
3351 /*timeout*/ da_default_timeout * 1000);
3354 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3355 free(id_dir, M_SCSIDA);
3356 daprobedone(periph, start_ccb);
3359 start_ccb->ccb_h.ccb_bp = NULL;
3360 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3361 xpt_action(start_ccb);
3364 case DA_STATE_PROBE_ATA_SUP:
3366 struct ata_identify_log_sup_cap *sup_cap;
3372 * Check here to see whether the Supported Capabilities log
3373 * is in the list of Identify Device logs.
3375 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3376 daprobedone(periph, start_ccb);
3380 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3381 if (sup_cap == NULL) {
3382 xpt_print(periph->path, "Couldn't malloc sup_cap "
3384 daprobedone(periph, start_ccb);
3388 retval = scsi_ata_read_log(&start_ccb->csio,
3389 /*retries*/ da_retry_count,
3391 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3392 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3393 /*page_number*/ ATA_IDL_SUP_CAP,
3395 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3396 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3397 /*data_ptr*/ (uint8_t *)sup_cap,
3398 /*dxfer_len*/ sizeof(*sup_cap),
3399 /*sense_len*/ SSD_FULL_SIZE,
3400 /*timeout*/ da_default_timeout * 1000);
3403 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3404 free(sup_cap, M_SCSIDA);
3405 daprobedone(periph, start_ccb);
3410 start_ccb->ccb_h.ccb_bp = NULL;
3411 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3412 xpt_action(start_ccb);
3415 case DA_STATE_PROBE_ATA_ZONE:
3417 struct ata_zoned_info_log *ata_zone;
3423 * Check here to see whether the zoned device information
3424 * page is supported. If so, continue on to request it.
3425 * If not, skip to DA_STATE_PROBE_LOG or done.
3427 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3428 daprobedone(periph, start_ccb);
3431 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3433 if (ata_zone == NULL) {
3434 xpt_print(periph->path, "Couldn't malloc ata_zone "
3436 daprobedone(periph, start_ccb);
3440 retval = scsi_ata_read_log(&start_ccb->csio,
3441 /*retries*/ da_retry_count,
3443 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3444 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3445 /*page_number*/ ATA_IDL_ZDI,
3447 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3448 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3449 /*data_ptr*/ (uint8_t *)ata_zone,
3450 /*dxfer_len*/ sizeof(*ata_zone),
3451 /*sense_len*/ SSD_FULL_SIZE,
3452 /*timeout*/ da_default_timeout * 1000);
3455 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3456 free(ata_zone, M_SCSIDA);
3457 daprobedone(periph, start_ccb);
3460 start_ccb->ccb_h.ccb_bp = NULL;
3461 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3462 xpt_action(start_ccb);
3466 case DA_STATE_PROBE_ZONE:
3468 struct scsi_vpd_zoned_bdc *bdc;
3471 * Note that this page will be supported for SCSI protocol
3472 * devices that support ZBC (SMR devices), as well as ATA
3473 * protocol devices that are behind a SAT (SCSI to ATA
3474 * Translation) layer that supports converting ZBC commands
3475 * to their ZAC equivalents.
3477 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3478 daprobedone(periph, start_ccb);
3481 bdc = (struct scsi_vpd_zoned_bdc *)
3482 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3485 xpt_release_ccb(start_ccb);
3486 xpt_print(periph->path, "Couldn't malloc zone VPD "
3490 scsi_inquiry(&start_ccb->csio,
3491 /*retries*/da_retry_count,
3493 /*tag_action*/MSG_SIMPLE_Q_TAG,
3494 /*inq_buf*/(u_int8_t *)bdc,
3495 /*inq_len*/sizeof(*bdc),
3497 /*page_code*/SVPD_ZONED_BDC,
3498 /*sense_len*/SSD_FULL_SIZE,
3499 /*timeout*/da_default_timeout * 1000);
3500 start_ccb->ccb_h.ccb_bp = NULL;
3501 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3502 xpt_action(start_ccb);
3509 * In each of the methods below, while its the caller's
3510 * responsibility to ensure the request will fit into a
3511 * single device request, we might have changed the delete
3512 * method due to the device incorrectly advertising either
3513 * its supported methods or limits.
3515 * To prevent this causing further issues we validate the
3516 * against the methods limits, and warn which would
3517 * otherwise be unnecessary.
3520 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3522 struct da_softc *softc = (struct da_softc *)periph->softc;;
3524 uint8_t *buf = softc->unmap_buf;
3525 uint64_t lba, lastlba = (uint64_t)-1;
3526 uint64_t totalcount = 0;
3528 uint32_t lastcount = 0, c;
3529 uint32_t off, ranges = 0;
3532 * Currently this doesn't take the UNMAP
3533 * Granularity and Granularity Alignment
3534 * fields into account.
3536 * This could result in both unoptimal unmap
3537 * requests as as well as UNMAP calls unmapping
3538 * fewer LBA's than requested.
3541 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3545 * Note: ada and da are different in how they store the
3546 * pending bp's in a trim. ada stores all of them in the
3547 * trim_req.bps. da stores all but the first one in the
3548 * delete_run_queue. ada then completes all the bps in
3549 * its adadone() loop. da completes all the bps in the
3550 * delete_run_queue in dadone, and relies on the biodone
3551 * after to complete. This should be reconciled since there's
3552 * no real reason to do it differently. XXX
3555 bioq_insert_tail(&softc->delete_run_queue, bp1);
3556 lba = bp1->bio_pblkno;
3557 count = bp1->bio_bcount / softc->params.secsize;
3559 /* Try to extend the previous range. */
3560 if (lba == lastlba) {
3561 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3563 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
3565 scsi_ulto4b(lastcount, &buf[off + 8]);
3572 c = omin(count, UNMAP_RANGE_MAX);
3573 if (totalcount + c > softc->unmap_max_lba ||
3574 ranges >= softc->unmap_max_ranges) {
3575 xpt_print(periph->path,
3576 "%s issuing short delete %ld > %ld"
3578 da_delete_method_desc[softc->delete_method],
3579 totalcount + c, softc->unmap_max_lba,
3580 ranges, softc->unmap_max_ranges);
3583 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
3584 scsi_u64to8b(lba, &buf[off + 0]);
3585 scsi_ulto4b(c, &buf[off + 8]);
3593 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3596 if (ranges >= softc->unmap_max_ranges ||
3597 totalcount + bp1->bio_bcount /
3598 softc->params.secsize > softc->unmap_max_lba) {
3599 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3603 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3604 scsi_ulto2b(ranges * 16, &buf[2]);
3606 scsi_unmap(&ccb->csio,
3607 /*retries*/da_retry_count,
3609 /*tag_action*/MSG_SIMPLE_Q_TAG,
3612 /*dxfer_len*/ ranges * 16 + 8,
3613 /*sense_len*/SSD_FULL_SIZE,
3614 da_default_timeout * 1000);
3615 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3616 ccb->ccb_h.flags |= CAM_UNLOCKED;
3617 cam_iosched_submit_trim(softc->cam_iosched);
3621 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3623 struct da_softc *softc = (struct da_softc *)periph->softc;
3625 uint8_t *buf = softc->unmap_buf;
3626 uint64_t lastlba = (uint64_t)-1;
3629 uint32_t lastcount = 0, c, requestcount;
3630 int ranges = 0, off, block_count;
3632 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3635 if (bp1 != bp)//XXX imp XXX
3636 bioq_insert_tail(&softc->delete_run_queue, bp1);
3637 lba = bp1->bio_pblkno;
3638 count = bp1->bio_bcount / softc->params.secsize;
3639 requestcount = count;
3641 /* Try to extend the previous range. */
3642 if (lba == lastlba) {
3643 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3645 off = (ranges - 1) * 8;
3646 buf[off + 6] = lastcount & 0xff;
3647 buf[off + 7] = (lastcount >> 8) & 0xff;
3653 c = omin(count, ATA_DSM_RANGE_MAX);
3656 buf[off + 0] = lba & 0xff;
3657 buf[off + 1] = (lba >> 8) & 0xff;
3658 buf[off + 2] = (lba >> 16) & 0xff;
3659 buf[off + 3] = (lba >> 24) & 0xff;
3660 buf[off + 4] = (lba >> 32) & 0xff;
3661 buf[off + 5] = (lba >> 40) & 0xff;
3662 buf[off + 6] = c & 0xff;
3663 buf[off + 7] = (c >> 8) & 0xff;
3668 if (count != 0 && ranges == softc->trim_max_ranges) {
3669 xpt_print(periph->path,
3670 "%s issuing short delete %ld > %ld\n",
3671 da_delete_method_desc[softc->delete_method],
3673 (softc->trim_max_ranges - ranges) *
3679 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3682 if (bp1->bio_bcount / softc->params.secsize >
3683 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3684 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3689 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3690 scsi_ata_trim(&ccb->csio,
3691 /*retries*/da_retry_count,
3693 /*tag_action*/MSG_SIMPLE_Q_TAG,
3696 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3697 /*sense_len*/SSD_FULL_SIZE,
3698 da_default_timeout * 1000);
3699 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3700 ccb->ccb_h.flags |= CAM_UNLOCKED;
3701 cam_iosched_submit_trim(softc->cam_iosched);
3705 * We calculate ws_max_blks here based off d_delmaxsize instead
3706 * of using softc->ws_max_blks as it is absolute max for the
3707 * device not the protocol max which may well be lower.
3710 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3712 struct da_softc *softc;
3714 uint64_t ws_max_blks;
3716 uint64_t count; /* forward compat with WS32 */
3718 softc = (struct da_softc *)periph->softc;
3719 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3720 lba = bp->bio_pblkno;
3724 if (bp1 != bp)//XXX imp XXX
3725 bioq_insert_tail(&softc->delete_run_queue, bp1);
3726 count += bp1->bio_bcount / softc->params.secsize;
3727 if (count > ws_max_blks) {
3728 xpt_print(periph->path,
3729 "%s issuing short delete %ld > %ld\n",
3730 da_delete_method_desc[softc->delete_method],
3731 count, ws_max_blks);
3732 count = omin(count, ws_max_blks);
3735 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3738 if (lba + count != bp1->bio_pblkno ||
3739 count + bp1->bio_bcount /
3740 softc->params.secsize > ws_max_blks) {
3741 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3746 scsi_write_same(&ccb->csio,
3747 /*retries*/da_retry_count,
3749 /*tag_action*/MSG_SIMPLE_Q_TAG,
3750 /*byte2*/softc->delete_method ==
3751 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3752 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3754 /*block_count*/count,
3755 /*data_ptr*/ __DECONST(void *, zero_region),
3756 /*dxfer_len*/ softc->params.secsize,
3757 /*sense_len*/SSD_FULL_SIZE,
3758 da_default_timeout * 1000);
3759 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3760 ccb->ccb_h.flags |= CAM_UNLOCKED;
3761 cam_iosched_submit_trim(softc->cam_iosched);
3765 cmd6workaround(union ccb *ccb)
3767 struct scsi_rw_6 cmd6;
3768 struct scsi_rw_10 *cmd10;
3769 struct da_softc *softc;
3774 cdb = ccb->csio.cdb_io.cdb_bytes;
3775 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3777 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3778 da_delete_methods old_method = softc->delete_method;
3781 * Typically there are two reasons for failure here
3782 * 1. Delete method was detected as supported but isn't
3783 * 2. Delete failed due to invalid params e.g. too big
3785 * While we will attempt to choose an alternative delete method
3786 * this may result in short deletes if the existing delete
3787 * requests from geom are big for the new method chosen.
3789 * This method assumes that the error which triggered this
3790 * will not retry the io otherwise a panic will occur
3792 dadeleteflag(softc, old_method, 0);
3793 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3794 if (softc->delete_method == DA_DELETE_DISABLE)
3795 xpt_print(ccb->ccb_h.path,
3796 "%s failed, disabling BIO_DELETE\n",
3797 da_delete_method_desc[old_method]);
3799 xpt_print(ccb->ccb_h.path,
3800 "%s failed, switching to %s BIO_DELETE\n",
3801 da_delete_method_desc[old_method],
3802 da_delete_method_desc[softc->delete_method]);
3804 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3805 cam_iosched_queue_work(softc->cam_iosched, bp);
3806 cam_iosched_queue_work(softc->cam_iosched,
3807 (struct bio *)ccb->ccb_h.ccb_bp);
3808 ccb->ccb_h.ccb_bp = NULL;
3812 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3813 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3814 (*cdb == PREVENT_ALLOW) &&
3815 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3817 xpt_print(ccb->ccb_h.path,
3818 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3819 softc->quirks |= DA_Q_NO_PREVENT;
3823 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3824 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3825 (*cdb == SYNCHRONIZE_CACHE) &&
3826 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3828 xpt_print(ccb->ccb_h.path,
3829 "SYNCHRONIZE CACHE(10) not supported.\n");
3830 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3831 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3835 /* Translation only possible if CDB is an array and cmd is R/W6 */
3836 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3837 (*cdb != READ_6 && *cdb != WRITE_6))
3840 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3841 "increasing minimum_cmd_size to 10.\n");
3842 softc->minimum_cmd_size = 10;
3844 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3845 cmd10 = (struct scsi_rw_10 *)cdb;
3846 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3848 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3849 cmd10->reserved = 0;
3850 scsi_ulto2b(cmd6.length, cmd10->length);
3851 cmd10->control = cmd6.control;
3852 ccb->csio.cdb_len = sizeof(*cmd10);
3854 /* Requeue request, unfreezing queue if necessary */
3855 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3856 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3859 cam_release_devq(ccb->ccb_h.path,
3863 /*getcount_only*/0);
3869 dazonedone(struct cam_periph *periph, union ccb *ccb)
3871 struct da_softc *softc;
3874 softc = periph->softc;
3875 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3877 switch (bp->bio_zone.zone_cmd) {
3878 case DISK_ZONE_OPEN:
3879 case DISK_ZONE_CLOSE:
3880 case DISK_ZONE_FINISH:
3883 case DISK_ZONE_REPORT_ZONES: {
3885 struct disk_zone_report *rep;
3886 struct scsi_report_zones_hdr *hdr;
3887 struct scsi_report_zones_desc *desc;
3888 struct disk_zone_rep_entry *entry;
3889 uint32_t num_alloced, hdr_len, num_avail;
3890 uint32_t num_to_fill, i;
3893 rep = &bp->bio_zone.zone_params.report;
3894 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3896 * Note that bio_resid isn't normally used for zone
3897 * commands, but it is used by devstat_end_transaction_bio()
3898 * to determine how much data was transferred. Because
3899 * the size of the SCSI/ATA data structures is different
3900 * than the size of the BIO interface structures, the
3901 * amount of data actually transferred from the drive will
3902 * be different than the amount of data transferred to
3905 bp->bio_resid = ccb->csio.resid;
3906 num_alloced = rep->entries_allocated;
3907 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3908 if (avail_len < sizeof(*hdr)) {
3910 * Is there a better error than EIO here? We asked
3911 * for at least the header, and we got less than
3914 bp->bio_error = EIO;
3915 bp->bio_flags |= BIO_ERROR;
3916 bp->bio_resid = bp->bio_bcount;
3920 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3925 hdr_len = ata ? le32dec(hdr->length) :
3926 scsi_4btoul(hdr->length);
3928 rep->entries_available = hdr_len / sizeof(*desc);
3930 rep->entries_available = 0;
3932 * NOTE: using the same values for the BIO version of the
3933 * same field as the SCSI/ATA values. This means we could
3934 * get some additional values that aren't defined in bio.h
3935 * if more values of the same field are defined later.
3937 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3938 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3939 scsi_8btou64(hdr->maximum_lba);
3941 * If the drive reports no entries that match the query,
3945 rep->entries_filled = 0;
3949 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3950 hdr_len / sizeof(*desc));
3952 * If the drive didn't return any data, then we're done.
3954 if (num_avail == 0) {
3955 rep->entries_filled = 0;
3959 num_to_fill = min(num_avail, rep->entries_allocated);
3961 * If the user didn't allocate any entries for us to fill,
3964 if (num_to_fill == 0) {
3965 rep->entries_filled = 0;
3969 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
3970 i < num_to_fill; i++, desc++, entry++) {
3972 * NOTE: we're mapping the values here directly
3973 * from the SCSI/ATA bit definitions to the bio.h
3974 * definitons. There is also a warning in
3975 * disk_zone.h, but the impact is that if
3976 * additional values are added in the SCSI/ATA
3977 * specs these will be visible to consumers of
3980 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
3981 entry->zone_condition =
3982 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
3983 SRZ_ZONE_COND_SHIFT;
3984 entry->zone_flags |= desc->zone_flags &
3985 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
3986 entry->zone_length =
3987 ata ? le64dec(desc->zone_length) :
3988 scsi_8btou64(desc->zone_length);
3989 entry->zone_start_lba =
3990 ata ? le64dec(desc->zone_start_lba) :
3991 scsi_8btou64(desc->zone_start_lba);
3992 entry->write_pointer_lba =
3993 ata ? le64dec(desc->write_pointer_lba) :
3994 scsi_8btou64(desc->write_pointer_lba);
3996 rep->entries_filled = num_to_fill;
3999 case DISK_ZONE_GET_PARAMS:
4002 * In theory we should not get a GET_PARAMS bio, since it
4003 * should be handled without queueing the command to the
4006 panic("%s: Invalid zone command %d", __func__,
4007 bp->bio_zone.zone_cmd);
4011 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
4012 free(ccb->csio.data_ptr, M_SCSIDA);
4016 dadone(struct cam_periph *periph, union ccb *done_ccb)
4018 struct da_softc *softc;
4019 struct ccb_scsiio *csio;
4023 softc = (struct da_softc *)periph->softc;
4024 priority = done_ccb->ccb_h.pinfo.priority;
4026 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4028 csio = &done_ccb->csio;
4029 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4030 if (csio->bio != NULL)
4031 biotrack(csio->bio, __func__);
4033 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4035 case DA_CCB_BUFFER_IO:
4038 struct bio *bp, *bp1;
4040 cam_periph_lock(periph);
4041 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4042 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4046 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4051 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4052 if (error == ERESTART) {
4054 * A retry was scheduled, so
4057 cam_periph_unlock(periph);
4060 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4065 * return all queued I/O with EIO, so that
4066 * the client can retry these I/Os in the
4067 * proper order should it attempt to recover.
4072 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4074 * Catastrophic error. Mark our pack as
4078 * XXX See if this is really a media
4081 xpt_print(periph->path,
4082 "Invalidating pack\n");
4083 softc->flags |= DA_FLAG_PACK_INVALID;
4085 softc->invalidations++;
4087 queued_error = ENXIO;
4089 cam_iosched_flush(softc->cam_iosched, NULL,
4092 bp->bio_error = error;
4093 bp->bio_resid = bp->bio_bcount;
4094 bp->bio_flags |= BIO_ERROR;
4096 } else if (bp != NULL) {
4097 if (state == DA_CCB_DELETE)
4100 bp->bio_resid = csio->resid;
4102 if (bp->bio_resid != 0)
4103 bp->bio_flags |= BIO_ERROR;
4105 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4106 cam_release_devq(done_ccb->ccb_h.path,
4110 /*getcount_only*/0);
4111 } else if (bp != NULL) {
4112 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4113 panic("REQ_CMP with QFRZN");
4114 if (bp->bio_cmd == BIO_ZONE)
4115 dazonedone(periph, done_ccb);
4116 else if (state == DA_CCB_DELETE)
4119 bp->bio_resid = csio->resid;
4120 if ((csio->resid > 0)
4121 && (bp->bio_cmd != BIO_ZONE))
4122 bp->bio_flags |= BIO_ERROR;
4123 if (softc->error_inject != 0) {
4124 bp->bio_error = softc->error_inject;
4125 bp->bio_resid = bp->bio_bcount;
4126 bp->bio_flags |= BIO_ERROR;
4127 softc->error_inject = 0;
4131 biotrack(bp, __func__);
4132 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4133 if (LIST_EMPTY(&softc->pending_ccbs))
4134 softc->flags |= DA_FLAG_WAS_OTAG;
4136 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4137 xpt_release_ccb(done_ccb);
4138 if (state == DA_CCB_DELETE) {
4139 TAILQ_HEAD(, bio) queue;
4142 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4143 softc->delete_run_queue.insert_point = NULL;
4145 * Normally, the xpt_release_ccb() above would make sure
4146 * that when we have more work to do, that work would
4147 * get kicked off. However, we specifically keep
4148 * delete_running set to 0 before the call above to
4149 * allow other I/O to progress when many BIO_DELETE
4150 * requests are pushed down. We set delete_running to 0
4151 * and call daschedule again so that we don't stall if
4152 * there are no other I/Os pending apart from BIO_DELETEs.
4154 cam_iosched_trim_done(softc->cam_iosched);
4156 cam_periph_unlock(periph);
4157 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4158 TAILQ_REMOVE(&queue, bp1, bio_queue);
4159 bp1->bio_error = bp->bio_error;
4160 if (bp->bio_flags & BIO_ERROR) {
4161 bp1->bio_flags |= BIO_ERROR;
4162 bp1->bio_resid = bp1->bio_bcount;
4169 cam_periph_unlock(periph);
4175 case DA_CCB_PROBE_RC:
4176 case DA_CCB_PROBE_RC16:
4178 struct scsi_read_capacity_data *rdcap;
4179 struct scsi_read_capacity_data_long *rcaplong;
4180 char announce_buf[80];
4186 if (state == DA_CCB_PROBE_RC)
4187 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4189 rcaplong = (struct scsi_read_capacity_data_long *)
4192 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4193 struct disk_params *dp;
4194 uint32_t block_size;
4196 u_int lalba; /* Lowest aligned LBA. */
4198 if (state == DA_CCB_PROBE_RC) {
4199 block_size = scsi_4btoul(rdcap->length);
4200 maxsector = scsi_4btoul(rdcap->addr);
4204 * According to SBC-2, if the standard 10
4205 * byte READ CAPACITY command returns 2^32,
4206 * we should issue the 16 byte version of
4207 * the command, since the device in question
4208 * has more sectors than can be represented
4209 * with the short version of the command.
4211 if (maxsector == 0xffffffff) {
4212 free(rdcap, M_SCSIDA);
4213 xpt_release_ccb(done_ccb);
4214 softc->state = DA_STATE_PROBE_RC16;
4215 xpt_schedule(periph, priority);
4219 block_size = scsi_4btoul(rcaplong->length);
4220 maxsector = scsi_8btou64(rcaplong->addr);
4221 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4225 * Because GEOM code just will panic us if we
4226 * give them an 'illegal' value we'll avoid that
4229 if (block_size == 0) {
4234 if (block_size >= MAXPHYS) {
4235 xpt_print(periph->path,
4236 "unsupportable block size %ju\n",
4237 (uintmax_t) block_size);
4238 announce_buf[0] = '\0';
4239 cam_periph_invalidate(periph);
4242 * We pass rcaplong into dasetgeom(),
4243 * because it will only use it if it is
4246 dasetgeom(periph, block_size, maxsector,
4247 rcaplong, sizeof(*rcaplong));
4248 lbp = (lalba & SRC16_LBPME_A);
4249 dp = &softc->params;
4250 snprintf(announce_buf, sizeof(announce_buf),
4251 "%juMB (%ju %u byte sectors)",
4252 ((uintmax_t)dp->secsize * dp->sectors) /
4254 (uintmax_t)dp->sectors, dp->secsize);
4259 announce_buf[0] = '\0';
4262 * Retry any UNIT ATTENTION type errors. They
4263 * are expected at boot.
4265 error = daerror(done_ccb, CAM_RETRY_SELTO,
4266 SF_RETRY_UA|SF_NO_PRINT);
4267 if (error == ERESTART) {
4269 * A retry was scheuled, so
4273 } else if (error != 0) {
4275 int sense_key, error_code;
4278 struct ccb_getdev cgd;
4280 /* Don't wedge this device's queue */
4281 status = done_ccb->ccb_h.status;
4282 if ((status & CAM_DEV_QFRZN) != 0)
4283 cam_release_devq(done_ccb->ccb_h.path,
4287 /*getcount_only*/0);
4290 xpt_setup_ccb(&cgd.ccb_h,
4291 done_ccb->ccb_h.path,
4292 CAM_PRIORITY_NORMAL);
4293 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4294 xpt_action((union ccb *)&cgd);
4296 if (scsi_extract_sense_ccb(done_ccb,
4297 &error_code, &sense_key, &asc, &ascq))
4303 * If we tried READ CAPACITY(16) and failed,
4304 * fallback to READ CAPACITY(10).
4306 if ((state == DA_CCB_PROBE_RC16) &&
4307 (softc->flags & DA_FLAG_CAN_RC16) &&
4308 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4311 (error_code == SSD_CURRENT_ERROR) &&
4312 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4313 softc->flags &= ~DA_FLAG_CAN_RC16;
4314 free(rdcap, M_SCSIDA);
4315 xpt_release_ccb(done_ccb);
4316 softc->state = DA_STATE_PROBE_RC;
4317 xpt_schedule(periph, priority);
4322 * Attach to anything that claims to be a
4323 * direct access or optical disk device,
4324 * as long as it doesn't return a "Logical
4325 * unit not supported" (0x25) error.
4326 * "Internal Target Failure" (0x44) is also
4327 * special and typically means that the
4328 * device is a SATA drive behind a SATL
4329 * translation that's fallen into a
4330 * terminally fatal state.
4333 && (asc != 0x25) && (asc != 0x44)
4334 && (error_code == SSD_CURRENT_ERROR)) {
4335 const char *sense_key_desc;
4336 const char *asc_desc;
4338 dasetgeom(periph, 512, -1, NULL, 0);
4339 scsi_sense_desc(sense_key, asc, ascq,
4343 snprintf(announce_buf,
4344 sizeof(announce_buf),
4345 "Attempt to query device "
4346 "size failed: %s, %s",
4354 xpt_print(periph->path,
4355 "got CAM status %#x\n",
4356 done_ccb->ccb_h.status);
4359 xpt_print(periph->path, "fatal error, "
4360 "failed to attach to device\n");
4363 * Free up resources.
4365 cam_periph_invalidate(periph);
4369 free(csio->data_ptr, M_SCSIDA);
4370 if (announce_buf[0] != '\0' &&
4371 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4373 * Create our sysctl variables, now that we know
4374 * we have successfully attached.
4376 /* increase the refcount */
4377 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4378 taskqueue_enqueue(taskqueue_thread,
4379 &softc->sysctl_task);
4380 xpt_announce_periph(periph, announce_buf);
4381 xpt_announce_quirks(periph, softc->quirks,
4384 xpt_print(periph->path, "fatal error, "
4385 "could not acquire reference count\n");
4389 /* We already probed the device. */
4390 if (softc->flags & DA_FLAG_PROBED) {
4391 daprobedone(periph, done_ccb);
4395 /* Ensure re-probe doesn't see old delete. */
4396 softc->delete_available = 0;
4397 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4398 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4400 * Based on older SBC-3 spec revisions
4401 * any of the UNMAP methods "may" be
4402 * available via LBP given this flag so
4403 * we flag all of them as available and
4404 * then remove those which further
4405 * probes confirm aren't available
4408 * We could also check readcap(16) p_type
4409 * flag to exclude one or more invalid
4410 * write same (X) types here
4412 dadeleteflag(softc, DA_DELETE_WS16, 1);
4413 dadeleteflag(softc, DA_DELETE_WS10, 1);
4414 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4416 xpt_release_ccb(done_ccb);
4417 softc->state = DA_STATE_PROBE_LBP;
4418 xpt_schedule(periph, priority);
4422 xpt_release_ccb(done_ccb);
4423 softc->state = DA_STATE_PROBE_BDC;
4424 xpt_schedule(periph, priority);
4427 case DA_CCB_PROBE_LBP:
4429 struct scsi_vpd_logical_block_prov *lbp;
4431 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4433 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4435 * T10/1799-D Revision 31 states at least one of these
4436 * must be supported but we don't currently enforce this.
4438 dadeleteflag(softc, DA_DELETE_WS16,
4439 (lbp->flags & SVPD_LBP_WS16));
4440 dadeleteflag(softc, DA_DELETE_WS10,
4441 (lbp->flags & SVPD_LBP_WS10));
4442 dadeleteflag(softc, DA_DELETE_UNMAP,
4443 (lbp->flags & SVPD_LBP_UNMAP));
4446 error = daerror(done_ccb, CAM_RETRY_SELTO,
4447 SF_RETRY_UA|SF_NO_PRINT);
4448 if (error == ERESTART)
4450 else if (error != 0) {
4451 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4452 /* Don't wedge this device's queue */
4453 cam_release_devq(done_ccb->ccb_h.path,
4457 /*getcount_only*/0);
4461 * Failure indicates we don't support any SBC-3
4462 * delete methods with UNMAP
4467 free(lbp, M_SCSIDA);
4468 xpt_release_ccb(done_ccb);
4469 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4470 xpt_schedule(periph, priority);
4473 case DA_CCB_PROBE_BLK_LIMITS:
4475 struct scsi_vpd_block_limits *block_limits;
4477 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4479 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4480 uint32_t max_txfer_len = scsi_4btoul(
4481 block_limits->max_txfer_len);
4482 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4483 block_limits->max_unmap_lba_cnt);
4484 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4485 block_limits->max_unmap_blk_cnt);
4486 uint64_t ws_max_blks = scsi_8btou64(
4487 block_limits->max_write_same_length);
4489 if (max_txfer_len != 0) {
4490 softc->disk->d_maxsize = MIN(softc->maxio,
4491 (off_t)max_txfer_len * softc->params.secsize);
4495 * We should already support UNMAP but we check lba
4496 * and block count to be sure
4498 if (max_unmap_lba_cnt != 0x00L &&
4499 max_unmap_blk_cnt != 0x00L) {
4500 softc->unmap_max_lba = max_unmap_lba_cnt;
4501 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4505 * Unexpected UNMAP limits which means the
4506 * device doesn't actually support UNMAP
4508 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4511 if (ws_max_blks != 0x00L)
4512 softc->ws_max_blks = ws_max_blks;
4515 error = daerror(done_ccb, CAM_RETRY_SELTO,
4516 SF_RETRY_UA|SF_NO_PRINT);
4517 if (error == ERESTART)
4519 else if (error != 0) {
4520 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4521 /* Don't wedge this device's queue */
4522 cam_release_devq(done_ccb->ccb_h.path,
4526 /*getcount_only*/0);
4530 * Failure here doesn't mean UNMAP is not
4531 * supported as this is an optional page.
4533 softc->unmap_max_lba = 1;
4534 softc->unmap_max_ranges = 1;
4538 free(block_limits, M_SCSIDA);
4539 xpt_release_ccb(done_ccb);
4540 softc->state = DA_STATE_PROBE_BDC;
4541 xpt_schedule(periph, priority);
4544 case DA_CCB_PROBE_BDC:
4546 struct scsi_vpd_block_device_characteristics *bdc;
4548 bdc = (struct scsi_vpd_block_device_characteristics *)
4551 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4555 * Disable queue sorting for non-rotational media
4558 u_int16_t old_rate = softc->disk->d_rotation_rate;
4560 valid_len = csio->dxfer_len - csio->resid;
4561 if (SBDC_IS_PRESENT(bdc, valid_len,
4562 medium_rotation_rate)) {
4563 softc->disk->d_rotation_rate =
4564 scsi_2btoul(bdc->medium_rotation_rate);
4565 if (softc->disk->d_rotation_rate ==
4566 SVPD_BDC_RATE_NON_ROTATING) {
4567 cam_iosched_set_sort_queue(
4568 softc->cam_iosched, 0);
4569 softc->rotating = 0;
4571 if (softc->disk->d_rotation_rate != old_rate) {
4572 disk_attr_changed(softc->disk,
4573 "GEOM::rotation_rate", M_NOWAIT);
4576 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4577 && (softc->zone_mode == DA_ZONE_NONE)) {
4580 if (scsi_vpd_supported_page(periph,
4581 SVPD_ATA_INFORMATION))
4587 * The Zoned field will only be set for
4588 * Drive Managed and Host Aware drives. If
4589 * they are Host Managed, the device type
4590 * in the standard INQUIRY data should be
4591 * set to T_ZBC_HM (0x14).
4593 if ((bdc->flags & SVPD_ZBC_MASK) ==
4595 softc->zone_mode = DA_ZONE_HOST_AWARE;
4596 softc->zone_interface = (ata_proto) ?
4597 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4598 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4600 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4601 softc->zone_interface = (ata_proto) ?
4602 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4603 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4605 xpt_print(periph->path, "Unknown zoned "
4607 bdc->flags & SVPD_ZBC_MASK);
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);
4628 free(bdc, M_SCSIDA);
4629 xpt_release_ccb(done_ccb);
4630 softc->state = DA_STATE_PROBE_ATA;
4631 xpt_schedule(periph, priority);
4634 case DA_CCB_PROBE_ATA:
4637 struct ata_params *ata_params;
4642 ata_params = (struct ata_params *)csio->data_ptr;
4643 ptr = (uint16_t *)ata_params;
4647 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4650 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4651 ptr[i] = le16toh(ptr[i]);
4652 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4653 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4654 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4655 if (ata_params->max_dsm_blocks != 0)
4656 softc->trim_max_ranges = min(
4657 softc->trim_max_ranges,
4658 ata_params->max_dsm_blocks *
4659 ATA_DSM_BLK_RANGES);
4662 * Disable queue sorting for non-rotational media
4665 old_rate = softc->disk->d_rotation_rate;
4666 softc->disk->d_rotation_rate =
4667 ata_params->media_rotation_rate;
4668 if (softc->disk->d_rotation_rate ==
4669 ATA_RATE_NON_ROTATING) {
4670 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4671 softc->rotating = 0;
4673 if (softc->disk->d_rotation_rate != old_rate) {
4674 disk_attr_changed(softc->disk,
4675 "GEOM::rotation_rate", M_NOWAIT);
4678 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4679 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4681 if (ata_params->support.extension &
4683 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4686 * At this point, if we have a SATA host aware drive,
4687 * we communicate via ATA passthrough unless the
4688 * SAT layer supports ZBC -> ZAC translation. In
4692 * XXX KDM figure out how to detect a host managed
4695 if (softc->zone_mode == DA_ZONE_NONE) {
4697 * Note that we don't override the zone
4698 * mode or interface if it has already been
4699 * set. This is because it has either been
4700 * set as a quirk, or when we probed the
4701 * SCSI Block Device Characteristics page,
4702 * the zoned field was set. The latter
4703 * means that the SAT layer supports ZBC to
4704 * ZAC translation, and we would prefer to
4705 * use that if it is available.
4707 if ((ata_params->support3 &
4708 ATA_SUPPORT_ZONE_MASK) ==
4709 ATA_SUPPORT_ZONE_HOST_AWARE) {
4710 softc->zone_mode = DA_ZONE_HOST_AWARE;
4711 softc->zone_interface =
4712 DA_ZONE_IF_ATA_PASS;
4713 } else if ((ata_params->support3 &
4714 ATA_SUPPORT_ZONE_MASK) ==
4715 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4716 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4717 softc->zone_interface =
4718 DA_ZONE_IF_ATA_PASS;
4723 error = daerror(done_ccb, CAM_RETRY_SELTO,
4724 SF_RETRY_UA|SF_NO_PRINT);
4725 if (error == ERESTART)
4727 else if (error != 0) {
4728 if ((done_ccb->ccb_h.status &
4729 CAM_DEV_QFRZN) != 0) {
4730 /* Don't wedge this device's queue */
4731 cam_release_devq(done_ccb->ccb_h.path,
4735 /*getcount_only*/0);
4740 free(ata_params, M_SCSIDA);
4741 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4742 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4744 * If the ATA IDENTIFY failed, we could be talking
4745 * to a SCSI drive, although that seems unlikely,
4746 * since the drive did report that it supported the
4747 * ATA Information VPD page. If the ATA IDENTIFY
4748 * succeeded, and the SAT layer doesn't support
4749 * ZBC -> ZAC translation, continue on to get the
4750 * directory of ATA logs, and complete the rest of
4751 * the ZAC probe. If the SAT layer does support
4752 * ZBC -> ZAC translation, we want to use that,
4753 * and we'll probe the SCSI Zoned Block Device
4754 * Characteristics VPD page next.
4757 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4758 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4759 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4761 softc->state = DA_STATE_PROBE_ZONE;
4764 if (continue_probe != 0) {
4765 xpt_release_ccb(done_ccb);
4766 xpt_schedule(periph, priority);
4769 daprobedone(periph, done_ccb);
4772 case DA_CCB_PROBE_ATA_LOGDIR:
4776 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4778 softc->valid_logdir_len = 0;
4779 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4780 softc->valid_logdir_len =
4781 csio->dxfer_len - csio->resid;
4782 if (softc->valid_logdir_len > 0)
4783 bcopy(csio->data_ptr, &softc->ata_logdir,
4784 min(softc->valid_logdir_len,
4785 sizeof(softc->ata_logdir)));
4787 * Figure out whether the Identify Device log is
4788 * supported. The General Purpose log directory
4789 * has a header, and lists the number of pages
4790 * available for each GP log identified by the
4791 * offset into the list.
4793 if ((softc->valid_logdir_len >=
4794 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4795 && (le16dec(softc->ata_logdir.header) ==
4796 ATA_GP_LOG_DIR_VERSION)
4797 && (le16dec(&softc->ata_logdir.num_pages[
4798 (ATA_IDENTIFY_DATA_LOG *
4799 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4800 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4802 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4805 error = daerror(done_ccb, CAM_RETRY_SELTO,
4806 SF_RETRY_UA|SF_NO_PRINT);
4807 if (error == ERESTART)
4809 else if (error != 0) {
4811 * If we can't get the ATA log directory,
4812 * then ATA logs are effectively not
4813 * supported even if the bit is set in the
4816 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4817 DA_FLAG_CAN_ATA_IDLOG);
4818 if ((done_ccb->ccb_h.status &
4819 CAM_DEV_QFRZN) != 0) {
4820 /* Don't wedge this device's queue */
4821 cam_release_devq(done_ccb->ccb_h.path,
4825 /*getcount_only*/0);
4830 free(csio->data_ptr, M_SCSIDA);
4833 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4834 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4835 xpt_release_ccb(done_ccb);
4836 xpt_schedule(periph, priority);
4839 daprobedone(periph, done_ccb);
4842 case DA_CCB_PROBE_ATA_IDDIR:
4846 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4847 off_t entries_offset, max_entries;
4850 softc->valid_iddir_len = 0;
4851 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4852 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4853 DA_FLAG_CAN_ATA_ZONE);
4854 softc->valid_iddir_len =
4855 csio->dxfer_len - csio->resid;
4856 if (softc->valid_iddir_len > 0)
4857 bcopy(csio->data_ptr, &softc->ata_iddir,
4858 min(softc->valid_iddir_len,
4859 sizeof(softc->ata_iddir)));
4862 __offsetof(struct ata_identify_log_pages,entries);
4863 max_entries = softc->valid_iddir_len - entries_offset;
4864 if ((softc->valid_iddir_len > (entries_offset + 1))
4865 && (le64dec(softc->ata_iddir.header) ==
4867 && (softc->ata_iddir.entry_count > 0)) {
4870 num_entries = softc->ata_iddir.entry_count;
4871 num_entries = min(num_entries,
4872 softc->valid_iddir_len - entries_offset);
4873 for (i = 0; i < num_entries &&
4874 i < max_entries; i++) {
4875 if (softc->ata_iddir.entries[i] ==
4878 DA_FLAG_CAN_ATA_SUPCAP;
4879 else if (softc->ata_iddir.entries[i]==
4882 DA_FLAG_CAN_ATA_ZONE;
4885 DA_FLAG_CAN_ATA_SUPCAP)
4887 DA_FLAG_CAN_ATA_ZONE))
4892 error = daerror(done_ccb, CAM_RETRY_SELTO,
4893 SF_RETRY_UA|SF_NO_PRINT);
4894 if (error == ERESTART)
4896 else if (error != 0) {
4898 * If we can't get the ATA Identify Data log
4899 * directory, then it effectively isn't
4900 * supported even if the ATA Log directory
4901 * a non-zero number of pages present for
4904 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4905 if ((done_ccb->ccb_h.status &
4906 CAM_DEV_QFRZN) != 0) {
4907 /* Don't wedge this device's queue */
4908 cam_release_devq(done_ccb->ccb_h.path,
4912 /*getcount_only*/0);
4917 free(csio->data_ptr, M_SCSIDA);
4920 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4921 softc->state = DA_STATE_PROBE_ATA_SUP;
4922 xpt_release_ccb(done_ccb);
4923 xpt_schedule(periph, priority);
4926 daprobedone(periph, done_ccb);
4929 case DA_CCB_PROBE_ATA_SUP:
4933 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4936 struct ata_identify_log_sup_cap *sup_cap;
4939 sup_cap = (struct ata_identify_log_sup_cap *)
4941 valid_len = csio->dxfer_len - csio->resid;
4943 __offsetof(struct ata_identify_log_sup_cap,
4944 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
4945 if (valid_len >= needed_size) {
4946 uint64_t zoned, zac_cap;
4948 zoned = le64dec(sup_cap->zoned_cap);
4949 if (zoned & ATA_ZONED_VALID) {
4951 * This should have already been
4952 * set, because this is also in the
4953 * ATA identify data.
4955 if ((zoned & ATA_ZONED_MASK) ==
4956 ATA_SUPPORT_ZONE_HOST_AWARE)
4959 else if ((zoned & ATA_ZONED_MASK) ==
4960 ATA_SUPPORT_ZONE_DEV_MANAGED)
4962 DA_ZONE_DRIVE_MANAGED;
4965 zac_cap = le64dec(sup_cap->sup_zac_cap);
4966 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
4967 if (zac_cap & ATA_REPORT_ZONES_SUP)
4968 softc->zone_flags |=
4969 DA_ZONE_FLAG_RZ_SUP;
4970 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
4971 softc->zone_flags |=
4972 DA_ZONE_FLAG_OPEN_SUP;
4973 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
4974 softc->zone_flags |=
4975 DA_ZONE_FLAG_CLOSE_SUP;
4976 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
4977 softc->zone_flags |=
4978 DA_ZONE_FLAG_FINISH_SUP;
4979 if (zac_cap & ATA_ND_RWP_SUP)
4980 softc->zone_flags |=
4981 DA_ZONE_FLAG_RWP_SUP;
4984 * This field was introduced in
4985 * ACS-4, r08 on April 28th, 2015.
4986 * If the drive firmware was written
4987 * to an earlier spec, it won't have
4988 * the field. So, assume all
4989 * commands are supported.
4991 softc->zone_flags |=
4992 DA_ZONE_FLAG_SUP_MASK;
4997 error = daerror(done_ccb, CAM_RETRY_SELTO,
4998 SF_RETRY_UA|SF_NO_PRINT);
4999 if (error == ERESTART)
5001 else if (error != 0) {
5003 * If we can't get the ATA Identify Data
5004 * Supported Capabilities page, clear the
5007 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
5009 * And clear zone capabilities.
5011 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
5012 if ((done_ccb->ccb_h.status &
5013 CAM_DEV_QFRZN) != 0) {
5014 /* Don't wedge this device's queue */
5015 cam_release_devq(done_ccb->ccb_h.path,
5019 /*getcount_only*/0);
5024 free(csio->data_ptr, M_SCSIDA);
5027 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5028 softc->state = DA_STATE_PROBE_ATA_ZONE;
5029 xpt_release_ccb(done_ccb);
5030 xpt_schedule(periph, priority);
5033 daprobedone(periph, done_ccb);
5036 case DA_CCB_PROBE_ATA_ZONE:
5040 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5041 struct ata_zoned_info_log *zi_log;
5045 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5047 valid_len = csio->dxfer_len - csio->resid;
5048 needed_size = __offsetof(struct ata_zoned_info_log,
5049 version_info) + 1 + sizeof(zi_log->version_info);
5050 if (valid_len >= needed_size) {
5053 tmpvar = le64dec(zi_log->zoned_cap);
5054 if (tmpvar & ATA_ZDI_CAP_VALID) {
5055 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5056 softc->zone_flags |=
5057 DA_ZONE_FLAG_URSWRZ;
5059 softc->zone_flags &=
5060 ~DA_ZONE_FLAG_URSWRZ;
5062 tmpvar = le64dec(zi_log->optimal_seq_zones);
5063 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5064 softc->zone_flags |=
5065 DA_ZONE_FLAG_OPT_SEQ_SET;
5066 softc->optimal_seq_zones = (tmpvar &
5067 ATA_ZDI_OPT_SEQ_MASK);
5069 softc->zone_flags &=
5070 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5071 softc->optimal_seq_zones = 0;
5074 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5075 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5076 softc->zone_flags |=
5077 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5078 softc->optimal_nonseq_zones =
5079 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5081 softc->zone_flags &=
5082 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5083 softc->optimal_nonseq_zones = 0;
5086 tmpvar = le64dec(zi_log->max_seq_req_zones);
5087 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5088 softc->zone_flags |=
5089 DA_ZONE_FLAG_MAX_SEQ_SET;
5090 softc->max_seq_zones =
5091 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5093 softc->zone_flags &=
5094 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5095 softc->max_seq_zones = 0;
5099 error = daerror(done_ccb, CAM_RETRY_SELTO,
5100 SF_RETRY_UA|SF_NO_PRINT);
5101 if (error == ERESTART)
5103 else if (error != 0) {
5104 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5105 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5107 if ((done_ccb->ccb_h.status &
5108 CAM_DEV_QFRZN) != 0) {
5109 /* Don't wedge this device's queue */
5110 cam_release_devq(done_ccb->ccb_h.path,
5114 /*getcount_only*/0);
5119 free(csio->data_ptr, M_SCSIDA);
5121 daprobedone(periph, done_ccb);
5124 case DA_CCB_PROBE_ZONE:
5128 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5131 struct scsi_vpd_zoned_bdc *zoned_bdc;
5134 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5136 valid_len = csio->dxfer_len - csio->resid;
5137 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5138 max_seq_req_zones) + 1 +
5139 sizeof(zoned_bdc->max_seq_req_zones);
5140 if ((valid_len >= needed_len)
5141 && (scsi_2btoul(zoned_bdc->page_length) >=
5143 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5144 softc->zone_flags |=
5145 DA_ZONE_FLAG_URSWRZ;
5147 softc->zone_flags &=
5148 ~DA_ZONE_FLAG_URSWRZ;
5149 softc->optimal_seq_zones =
5150 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5151 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5152 softc->optimal_nonseq_zones = scsi_4btoul(
5153 zoned_bdc->optimal_nonseq_zones);
5154 softc->zone_flags |=
5155 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5156 softc->max_seq_zones =
5157 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5158 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5161 * All of the zone commands are mandatory for SCSI
5164 * XXX KDM this is valid as of September 2015.
5165 * Re-check this assumption once the SAT spec is
5166 * updated to support SCSI ZBC to ATA ZAC mapping.
5167 * Since ATA allows zone commands to be reported
5168 * as supported or not, this may not necessarily
5169 * be true for an ATA device behind a SAT (SCSI to
5170 * ATA Translation) layer.
5172 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5174 error = daerror(done_ccb, CAM_RETRY_SELTO,
5175 SF_RETRY_UA|SF_NO_PRINT);
5176 if (error == ERESTART)
5178 else if (error != 0) {
5179 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5180 /* Don't wedge this device's queue */
5181 cam_release_devq(done_ccb->ccb_h.path,
5185 /*getcount_only*/0);
5189 daprobedone(periph, done_ccb);
5193 /* No-op. We're polling */
5197 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5199 if (daerror(done_ccb, CAM_RETRY_SELTO,
5200 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5203 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5204 cam_release_devq(done_ccb->ccb_h.path,
5208 /*getcount_only*/0);
5210 xpt_release_ccb(done_ccb);
5211 cam_periph_release_locked(periph);
5217 xpt_release_ccb(done_ccb);
5221 dareprobe(struct cam_periph *periph)
5223 struct da_softc *softc;
5226 softc = (struct da_softc *)periph->softc;
5228 /* Probe in progress; don't interfere. */
5229 if (softc->state != DA_STATE_NORMAL)
5232 status = cam_periph_acquire(periph);
5233 KASSERT(status == CAM_REQ_CMP,
5234 ("dareprobe: cam_periph_acquire failed"));
5236 if (softc->flags & DA_FLAG_CAN_RC16)
5237 softc->state = DA_STATE_PROBE_RC16;
5239 softc->state = DA_STATE_PROBE_RC;
5241 xpt_schedule(periph, CAM_PRIORITY_DEV);
5245 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5247 struct da_softc *softc;
5248 struct cam_periph *periph;
5249 int error, error_code, sense_key, asc, ascq;
5251 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5252 if (ccb->csio.bio != NULL)
5253 biotrack(ccb->csio.bio, __func__);
5256 periph = xpt_path_periph(ccb->ccb_h.path);
5257 softc = (struct da_softc *)periph->softc;
5260 * Automatically detect devices that do not support
5261 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5264 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5265 error = cmd6workaround(ccb);
5266 } else if (scsi_extract_sense_ccb(ccb,
5267 &error_code, &sense_key, &asc, &ascq)) {
5268 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5269 error = cmd6workaround(ccb);
5271 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5272 * query the capacity and notify upper layers.
5274 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5275 asc == 0x2A && ascq == 0x09) {
5276 xpt_print(periph->path, "Capacity data has changed\n");
5277 softc->flags &= ~DA_FLAG_PROBED;
5279 sense_flags |= SF_NO_PRINT;
5280 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5281 asc == 0x28 && ascq == 0x00) {
5282 softc->flags &= ~DA_FLAG_PROBED;
5283 disk_media_changed(softc->disk, M_NOWAIT);
5284 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5285 asc == 0x3F && ascq == 0x03) {
5286 xpt_print(periph->path, "INQUIRY data has changed\n");
5287 softc->flags &= ~DA_FLAG_PROBED;
5289 sense_flags |= SF_NO_PRINT;
5290 } else if (sense_key == SSD_KEY_NOT_READY &&
5291 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5292 softc->flags |= DA_FLAG_PACK_INVALID;
5293 disk_media_gone(softc->disk, M_NOWAIT);
5296 if (error == ERESTART)
5300 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5301 case CAM_CMD_TIMEOUT:
5304 case CAM_REQ_ABORTED:
5305 case CAM_REQ_CMP_ERR:
5306 case CAM_REQ_TERMIO:
5307 case CAM_UNREC_HBA_ERROR:
5308 case CAM_DATA_RUN_ERR:
5318 * Until we have a better way of doing pack validation,
5319 * don't treat UAs as errors.
5321 sense_flags |= SF_RETRY_UA;
5323 if (softc->quirks & DA_Q_RETRY_BUSY)
5324 sense_flags |= SF_RETRY_BUSY;
5325 return(cam_periph_error(ccb, cam_flags, sense_flags,
5326 &softc->saved_ccb));
5330 damediapoll(void *arg)
5332 struct cam_periph *periph = arg;
5333 struct da_softc *softc = periph->softc;
5335 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5336 LIST_EMPTY(&softc->pending_ccbs)) {
5337 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5338 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5342 /* Queue us up again */
5343 if (da_poll_period != 0)
5344 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5348 daprevent(struct cam_periph *periph, int action)
5350 struct da_softc *softc;
5354 softc = (struct da_softc *)periph->softc;
5356 if (((action == PR_ALLOW)
5357 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5358 || ((action == PR_PREVENT)
5359 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5363 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5365 scsi_prevent(&ccb->csio,
5373 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5374 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5377 if (action == PR_ALLOW)
5378 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5380 softc->flags |= DA_FLAG_PACK_LOCKED;
5383 xpt_release_ccb(ccb);
5387 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5388 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5390 struct ccb_calc_geometry ccg;
5391 struct da_softc *softc;
5392 struct disk_params *dp;
5393 u_int lbppbe, lalba;
5396 softc = (struct da_softc *)periph->softc;
5398 dp = &softc->params;
5399 dp->secsize = block_len;
5400 dp->sectors = maxsector + 1;
5401 if (rcaplong != NULL) {
5402 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5403 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5404 lalba &= SRC16_LALBA_A;
5411 dp->stripesize = block_len << lbppbe;
5412 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5414 } else if (softc->quirks & DA_Q_4K) {
5415 dp->stripesize = 4096;
5416 dp->stripeoffset = 0;
5419 dp->stripeoffset = 0;
5422 * Have the controller provide us with a geometry
5423 * for this disk. The only time the geometry
5424 * matters is when we boot and the controller
5425 * is the only one knowledgeable enough to come
5426 * up with something that will make this a bootable
5429 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5430 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5431 ccg.block_size = dp->secsize;
5432 ccg.volume_size = dp->sectors;
5434 ccg.secs_per_track = 0;
5436 xpt_action((union ccb*)&ccg);
5437 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5439 * We don't know what went wrong here- but just pick
5440 * a geometry so we don't have nasty things like divide
5444 dp->secs_per_track = 255;
5445 dp->cylinders = dp->sectors / (255 * 255);
5446 if (dp->cylinders == 0) {
5450 dp->heads = ccg.heads;
5451 dp->secs_per_track = ccg.secs_per_track;
5452 dp->cylinders = ccg.cylinders;
5456 * If the user supplied a read capacity buffer, and if it is
5457 * different than the previous buffer, update the data in the EDT.
5458 * If it's the same, we don't bother. This avoids sending an
5459 * update every time someone opens this device.
5461 if ((rcaplong != NULL)
5462 && (bcmp(rcaplong, &softc->rcaplong,
5463 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5464 struct ccb_dev_advinfo cdai;
5466 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5467 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5468 cdai.buftype = CDAI_TYPE_RCAPLONG;
5469 cdai.flags = CDAI_FLAG_STORE;
5470 cdai.bufsiz = rcap_len;
5471 cdai.buf = (uint8_t *)rcaplong;
5472 xpt_action((union ccb *)&cdai);
5473 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5474 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5475 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5476 xpt_print(periph->path, "%s: failed to set read "
5477 "capacity advinfo\n", __func__);
5478 /* Use cam_error_print() to decode the status */
5479 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5482 bcopy(rcaplong, &softc->rcaplong,
5483 min(sizeof(softc->rcaplong), rcap_len));
5487 softc->disk->d_sectorsize = softc->params.secsize;
5488 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5489 softc->disk->d_stripesize = softc->params.stripesize;
5490 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5491 /* XXX: these are not actually "firmware" values, so they may be wrong */
5492 softc->disk->d_fwsectors = softc->params.secs_per_track;
5493 softc->disk->d_fwheads = softc->params.heads;
5494 softc->disk->d_devstat->block_size = softc->params.secsize;
5495 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5497 error = disk_resize(softc->disk, M_NOWAIT);
5499 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5503 dasendorderedtag(void *arg)
5505 struct da_softc *softc = arg;
5507 if (da_send_ordered) {
5508 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5509 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5510 softc->flags |= DA_FLAG_NEED_OTAG;
5511 softc->flags &= ~DA_FLAG_WAS_OTAG;
5514 /* Queue us up again */
5515 callout_reset(&softc->sendordered_c,
5516 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5517 dasendorderedtag, softc);
5521 * Step through all DA peripheral drivers, and if the device is still open,
5522 * sync the disk cache to physical media.
5525 dashutdown(void * arg, int howto)
5527 struct cam_periph *periph;
5528 struct da_softc *softc;
5532 CAM_PERIPH_FOREACH(periph, &dadriver) {
5533 softc = (struct da_softc *)periph->softc;
5534 if (SCHEDULER_STOPPED()) {
5535 /* If we paniced with the lock held, do not recurse. */
5536 if (!cam_periph_owned(periph) &&
5537 (softc->flags & DA_FLAG_OPEN)) {
5538 dadump(softc->disk, NULL, 0, 0, 0);
5542 cam_periph_lock(periph);
5545 * We only sync the cache if the drive is still open, and
5546 * if the drive is capable of it..
5548 if (((softc->flags & DA_FLAG_OPEN) == 0)
5549 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5550 cam_periph_unlock(periph);
5554 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5555 scsi_synchronize_cache(&ccb->csio,
5559 /*begin_lba*/0, /* whole disk */
5564 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5565 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5566 softc->disk->d_devstat);
5568 xpt_print(periph->path, "Synchronize cache failed\n");
5569 xpt_release_ccb(ccb);
5570 cam_periph_unlock(periph);
5574 #else /* !_KERNEL */
5577 * XXX These are only left out of the kernel build to silence warnings. If,
5578 * for some reason these functions are used in the kernel, the ifdefs should
5579 * be moved so they are included both in the kernel and userland.
5582 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5583 void (*cbfcnp)(struct cam_periph *, union ccb *),
5584 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5585 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5588 struct scsi_format_unit *scsi_cmd;
5590 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5591 scsi_cmd->opcode = FORMAT_UNIT;
5592 scsi_cmd->byte2 = byte2;
5593 scsi_ulto2b(ileave, scsi_cmd->interleave);
5598 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5608 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5609 void (*cbfcnp)(struct cam_periph *, union ccb *),
5610 uint8_t tag_action, uint8_t list_format,
5611 uint32_t addr_desc_index, uint8_t *data_ptr,
5612 uint32_t dxfer_len, int minimum_cmd_size,
5613 uint8_t sense_len, uint32_t timeout)
5618 * These conditions allow using the 10 byte command. Otherwise we
5619 * need to use the 12 byte command.
5621 if ((minimum_cmd_size <= 10)
5622 && (addr_desc_index == 0)
5623 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5624 struct scsi_read_defect_data_10 *cdb10;
5626 cdb10 = (struct scsi_read_defect_data_10 *)
5627 &csio->cdb_io.cdb_bytes;
5629 cdb_len = sizeof(*cdb10);
5630 bzero(cdb10, cdb_len);
5631 cdb10->opcode = READ_DEFECT_DATA_10;
5632 cdb10->format = list_format;
5633 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5635 struct scsi_read_defect_data_12 *cdb12;
5637 cdb12 = (struct scsi_read_defect_data_12 *)
5638 &csio->cdb_io.cdb_bytes;
5640 cdb_len = sizeof(*cdb12);
5641 bzero(cdb12, cdb_len);
5642 cdb12->opcode = READ_DEFECT_DATA_12;
5643 cdb12->format = list_format;
5644 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5645 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5651 /*flags*/ CAM_DIR_IN,
5661 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5662 void (*cbfcnp)(struct cam_periph *, union ccb *),
5663 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5664 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5667 struct scsi_sanitize *scsi_cmd;
5669 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5670 scsi_cmd->opcode = SANITIZE;
5671 scsi_cmd->byte2 = byte2;
5672 scsi_cmd->control = control;
5673 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5678 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5687 #endif /* _KERNEL */
5690 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5691 void (*cbfcnp)(struct cam_periph *, union ccb *),
5692 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5693 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5694 uint8_t sense_len, uint32_t timeout)
5696 struct scsi_zbc_out *scsi_cmd;
5698 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5699 scsi_cmd->opcode = ZBC_OUT;
5700 scsi_cmd->service_action = service_action;
5701 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5702 scsi_cmd->zone_flags = zone_flags;
5707 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5717 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5718 void (*cbfcnp)(struct cam_periph *, union ccb *),
5719 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5720 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5721 uint8_t sense_len, uint32_t timeout)
5723 struct scsi_zbc_in *scsi_cmd;
5725 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5726 scsi_cmd->opcode = ZBC_IN;
5727 scsi_cmd->service_action = service_action;
5728 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5729 scsi_cmd->zone_options = zone_options;
5734 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5745 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5746 void (*cbfcnp)(struct cam_periph *, union ccb *),
5747 uint8_t tag_action, int use_ncq,
5748 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5749 uint8_t *data_ptr, uint32_t dxfer_len,
5750 uint8_t *cdb_storage, size_t cdb_storage_len,
5751 uint8_t sense_len, uint32_t timeout)
5753 uint8_t command_out, protocol, ata_flags;
5754 uint16_t features_out;
5755 uint32_t sectors_out, auxiliary;
5761 command_out = ATA_ZAC_MANAGEMENT_OUT;
5762 features_out = (zm_action & 0xf) | (zone_flags << 8);
5763 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5764 if (dxfer_len == 0) {
5765 protocol = AP_PROTO_NON_DATA;
5766 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5769 protocol = AP_PROTO_DMA;
5770 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5771 AP_FLAG_TDIR_TO_DEV;
5772 sectors_out = ((dxfer_len >> 9) & 0xffff);
5776 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5777 if (dxfer_len == 0) {
5778 command_out = ATA_NCQ_NON_DATA;
5779 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5781 * We're assuming the SCSI to ATA translation layer
5782 * will set the NCQ tag number in the tag field.
5783 * That isn't clear from the SAT-4 spec (as of rev 05).
5786 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5788 command_out = ATA_SEND_FPDMA_QUEUED;
5790 * Note that we're defaulting to normal priority,
5791 * and assuming that the SCSI to ATA translation
5792 * layer will insert the NCQ tag number in the tag
5793 * field. That isn't clear in the SAT-4 spec (as
5796 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5798 ata_flags |= AP_FLAG_TLEN_FEAT |
5799 AP_FLAG_TDIR_TO_DEV;
5802 * For SEND FPDMA QUEUED, the transfer length is
5803 * encoded in the FEATURE register, and 0 means
5804 * that 65536 512 byte blocks are to be tranferred.
5805 * In practice, it seems unlikely that we'll see
5806 * a transfer that large, and it may confuse the
5807 * the SAT layer, because generally that means that
5808 * 0 bytes should be transferred.
5810 if (dxfer_len == (65536 * 512)) {
5812 } else if (dxfer_len <= (65535 * 512)) {
5813 features_out = ((dxfer_len >> 9) & 0xffff);
5815 /* The transfer is too big. */
5822 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5823 protocol = AP_PROTO_FPDMA;
5826 protocol |= AP_EXTEND;
5828 retval = scsi_ata_pass(csio,
5831 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5833 /*protocol*/ protocol,
5834 /*ata_flags*/ ata_flags,
5835 /*features*/ features_out,
5836 /*sector_count*/ sectors_out,
5838 /*command*/ command_out,
5841 /*auxiliary*/ auxiliary,
5843 /*data_ptr*/ data_ptr,
5844 /*dxfer_len*/ dxfer_len,
5845 /*cdb_storage*/ cdb_storage,
5846 /*cdb_storage_len*/ cdb_storage_len,
5847 /*minimum_cmd_size*/ 0,
5848 /*sense_len*/ SSD_FULL_SIZE,
5849 /*timeout*/ timeout);
5857 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5858 void (*cbfcnp)(struct cam_periph *, union ccb *),
5859 uint8_t tag_action, int use_ncq,
5860 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5861 uint8_t *data_ptr, uint32_t dxfer_len,
5862 uint8_t *cdb_storage, size_t cdb_storage_len,
5863 uint8_t sense_len, uint32_t timeout)
5865 uint8_t command_out, protocol;
5866 uint16_t features_out, sectors_out;
5872 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5875 command_out = ATA_ZAC_MANAGEMENT_IN;
5876 /* XXX KDM put a macro here */
5877 features_out = (zm_action & 0xf) | (zone_flags << 8);
5878 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5879 protocol = AP_PROTO_DMA;
5880 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5883 ata_flags |= AP_FLAG_TLEN_FEAT;
5885 command_out = ATA_RECV_FPDMA_QUEUED;
5886 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5889 * For RECEIVE FPDMA QUEUED, the transfer length is
5890 * encoded in the FEATURE register, and 0 means
5891 * that 65536 512 byte blocks are to be tranferred.
5892 * In practice, it seems unlikely that we'll see
5893 * a transfer that large, and it may confuse the
5894 * the SAT layer, because generally that means that
5895 * 0 bytes should be transferred.
5897 if (dxfer_len == (65536 * 512)) {
5899 } else if (dxfer_len <= (65535 * 512)) {
5900 features_out = ((dxfer_len >> 9) & 0xffff);
5902 /* The transfer is too big. */
5906 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5907 protocol = AP_PROTO_FPDMA;
5910 protocol |= AP_EXTEND;
5912 retval = scsi_ata_pass(csio,
5915 /*flags*/ CAM_DIR_IN,
5917 /*protocol*/ protocol,
5918 /*ata_flags*/ ata_flags,
5919 /*features*/ features_out,
5920 /*sector_count*/ sectors_out,
5922 /*command*/ command_out,
5925 /*auxiliary*/ auxiliary,
5927 /*data_ptr*/ data_ptr,
5928 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
5929 /*cdb_storage*/ cdb_storage,
5930 /*cdb_storage_len*/ cdb_storage_len,
5931 /*minimum_cmd_size*/ 0,
5932 /*sense_len*/ SSD_FULL_SIZE,
5933 /*timeout*/ timeout);