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 /* Samsung Advanced Format (4k) drives */
833 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
837 /* Samsung Advanced Format (4k) drives */
838 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
842 /* Samsung Advanced Format (4k) drives */
843 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
847 /* Samsung Advanced Format (4k) drives */
848 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
852 /* Seagate Barracuda Green Advanced Format (4k) drives */
853 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
857 /* Seagate Barracuda Green Advanced Format (4k) drives */
858 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
862 /* Seagate Barracuda Green Advanced Format (4k) drives */
863 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
867 /* Seagate Barracuda Green Advanced Format (4k) drives */
868 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
872 /* Seagate Barracuda Green Advanced Format (4k) drives */
873 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
877 /* Seagate Barracuda Green Advanced Format (4k) drives */
878 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
882 /* Seagate Momentus Advanced Format (4k) drives */
883 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
887 /* Seagate Momentus Advanced Format (4k) drives */
888 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
892 /* Seagate Momentus Advanced Format (4k) drives */
893 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
897 /* Seagate Momentus Advanced Format (4k) drives */
898 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
902 /* Seagate Momentus Advanced Format (4k) drives */
903 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
907 /* Seagate Momentus Advanced Format (4k) drives */
908 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
912 /* Seagate Momentus Advanced Format (4k) drives */
913 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
917 /* Seagate Momentus Advanced Format (4k) drives */
918 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
922 /* Seagate Momentus Advanced Format (4k) drives */
923 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
927 /* Seagate Momentus Advanced Format (4k) drives */
928 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
932 /* Seagate Momentus Advanced Format (4k) drives */
933 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
937 /* Seagate Momentus Advanced Format (4k) drives */
938 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
942 /* Seagate Momentus Advanced Format (4k) drives */
943 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
947 /* Seagate Momentus Advanced Format (4k) drives */
948 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
952 /* Seagate Momentus Thin Advanced Format (4k) drives */
953 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
957 /* Seagate Momentus Thin Advanced Format (4k) drives */
958 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
962 /* WDC Caviar Green Advanced Format (4k) drives */
963 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
967 /* WDC Caviar Green Advanced Format (4k) drives */
968 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
972 /* WDC Caviar Green Advanced Format (4k) drives */
973 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
977 /* WDC Caviar Green Advanced Format (4k) drives */
978 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
982 /* WDC Caviar Green Advanced Format (4k) drives */
983 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
987 /* WDC Caviar Green Advanced Format (4k) drives */
988 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
992 /* WDC Caviar Green Advanced Format (4k) drives */
993 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
997 /* WDC Caviar Green Advanced Format (4k) drives */
998 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
1002 /* WDC Scorpio Black Advanced Format (4k) drives */
1003 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
1007 /* WDC Scorpio Black Advanced Format (4k) drives */
1008 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
1012 /* WDC Scorpio Black Advanced Format (4k) drives */
1013 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
1017 /* WDC Scorpio Black Advanced Format (4k) drives */
1018 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
1022 /* WDC Scorpio Blue Advanced Format (4k) drives */
1023 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
1027 /* WDC Scorpio Blue Advanced Format (4k) drives */
1028 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
1032 /* WDC Scorpio Blue Advanced Format (4k) drives */
1033 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
1037 /* WDC Scorpio Blue Advanced Format (4k) drives */
1038 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
1043 * Olympus FE-210 camera
1045 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
1046 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1050 * LG UP3S MP3 player
1052 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
1053 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1057 * Laser MP3-2GA13 MP3 player
1059 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
1060 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
1064 * LaCie external 250GB Hard drive des by Porsche
1065 * Submitted by: Ben Stuyts <ben@altesco.nl>
1068 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
1069 /*quirks*/ DA_Q_NO_SYNC_CACHE
1074 * Corsair Force 2 SSDs
1075 * 4k optimised & trim only works in 4k requests + 4k aligned
1077 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
1082 * Corsair Force 3 SSDs
1083 * 4k optimised & trim only works in 4k requests + 4k aligned
1085 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
1090 * Corsair Neutron GTX SSDs
1091 * 4k optimised & trim only works in 4k requests + 4k aligned
1093 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
1098 * Corsair Force GT & GS SSDs
1099 * 4k optimised & trim only works in 4k requests + 4k aligned
1101 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" },
1107 * 4k optimised & trim only works in 4k requests + 4k aligned
1109 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
1114 * Crucial RealSSD C300 SSDs
1117 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
1118 "*" }, /*quirks*/DA_Q_4K
1122 * Intel 320 Series SSDs
1123 * 4k optimised & trim only works in 4k requests + 4k aligned
1125 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1130 * Intel 330 Series SSDs
1131 * 4k optimised & trim only works in 4k requests + 4k aligned
1133 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1138 * Intel 510 Series SSDs
1139 * 4k optimised & trim only works in 4k requests + 4k aligned
1141 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1146 * Intel 520 Series SSDs
1147 * 4k optimised & trim only works in 4k requests + 4k aligned
1149 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1154 * Intel X25-M Series SSDs
1155 * 4k optimised & trim only works in 4k requests + 4k aligned
1157 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1162 * Kingston E100 Series SSDs
1163 * 4k optimised & trim only works in 4k requests + 4k aligned
1165 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1170 * Kingston HyperX 3k SSDs
1171 * 4k optimised & trim only works in 4k requests + 4k aligned
1173 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1178 * Marvell SSDs (entry taken from OpenSolaris)
1179 * 4k optimised & trim only works in 4k requests + 4k aligned
1181 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1186 * OCZ Agility 2 SSDs
1187 * 4k optimised & trim only works in 4k requests + 4k aligned
1189 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1194 * OCZ Agility 3 SSDs
1195 * 4k optimised & trim only works in 4k requests + 4k aligned
1197 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1202 * OCZ Deneva R Series SSDs
1203 * 4k optimised & trim only works in 4k requests + 4k aligned
1205 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1210 * OCZ Vertex 2 SSDs (inc pro series)
1211 * 4k optimised & trim only works in 4k requests + 4k aligned
1213 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1219 * 4k optimised & trim only works in 4k requests + 4k aligned
1221 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1227 * 4k optimised & trim only works in 4k requests + 4k aligned
1229 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1234 * Samsung 830 Series SSDs
1235 * 4k optimised & trim only works in 4k requests + 4k aligned
1237 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1243 * 4k optimised & trim only works in 4k requests + 4k aligned
1245 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" },
1251 * 4k optimised & trim only works in 4k requests + 4k aligned
1253 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" },
1258 * Samsung 843T Series SSDs (MZ7WD*)
1259 * Samsung PM851 Series SSDs (MZ7TE*)
1260 * Samsung PM853T Series SSDs (MZ7GE*)
1261 * Samsung SM863 Series SSDs (MZ7KM*)
1264 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" },
1269 * SuperTalent TeraDrive CT SSDs
1270 * 4k optimised & trim only works in 4k requests + 4k aligned
1272 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1277 * XceedIOPS SATA SSDs
1280 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1285 * Hama Innostor USB-Stick
1287 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" },
1288 /*quirks*/DA_Q_NO_RC16
1292 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
1293 * Drive Managed SATA hard drive. This drive doesn't report
1294 * in firmware that it is a drive managed SMR drive.
1296 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" },
1297 /*quirks*/DA_Q_SMR_DM
1301 * MX-ES USB Drive by Mach Xtreme
1303 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"},
1304 /*quirks*/DA_Q_NO_RC16
1308 static disk_strategy_t dastrategy;
1309 static dumper_t dadump;
1310 static periph_init_t dainit;
1311 static void daasync(void *callback_arg, u_int32_t code,
1312 struct cam_path *path, void *arg);
1313 static void dasysctlinit(void *context, int pending);
1314 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS);
1315 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1316 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1317 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS);
1318 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS);
1319 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1320 static void dadeletemethodset(struct da_softc *softc,
1321 da_delete_methods delete_method);
1322 static off_t dadeletemaxsize(struct da_softc *softc,
1323 da_delete_methods delete_method);
1324 static void dadeletemethodchoose(struct da_softc *softc,
1325 da_delete_methods default_method);
1326 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1328 static periph_ctor_t daregister;
1329 static periph_dtor_t dacleanup;
1330 static periph_start_t dastart;
1331 static periph_oninv_t daoninvalidate;
1332 static void dazonedone(struct cam_periph *periph, union ccb *ccb);
1333 static void dadone(struct cam_periph *periph,
1334 union ccb *done_ccb);
1335 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1336 u_int32_t sense_flags);
1337 static void daprevent(struct cam_periph *periph, int action);
1338 static void dareprobe(struct cam_periph *periph);
1339 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1341 struct scsi_read_capacity_data_long *rcaplong,
1343 static timeout_t dasendorderedtag;
1344 static void dashutdown(void *arg, int howto);
1345 static timeout_t damediapoll;
1347 #ifndef DA_DEFAULT_POLL_PERIOD
1348 #define DA_DEFAULT_POLL_PERIOD 3
1351 #ifndef DA_DEFAULT_TIMEOUT
1352 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1355 #ifndef DA_DEFAULT_SOFTTIMEOUT
1356 #define DA_DEFAULT_SOFTTIMEOUT 0
1359 #ifndef DA_DEFAULT_RETRY
1360 #define DA_DEFAULT_RETRY 4
1363 #ifndef DA_DEFAULT_SEND_ORDERED
1364 #define DA_DEFAULT_SEND_ORDERED 1
1367 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1368 static int da_retry_count = DA_DEFAULT_RETRY;
1369 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1370 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT;
1371 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1373 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1374 "CAM Direct Access Disk driver");
1375 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1376 &da_poll_period, 0, "Media polling period in seconds");
1377 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1378 &da_retry_count, 0, "Normal I/O retry count");
1379 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1380 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1381 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1382 &da_send_ordered, 0, "Send Ordered Tags");
1384 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout,
1385 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I",
1386 "Soft I/O timeout (ms)");
1387 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout);
1390 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1391 * to the default timeout, we check to see whether an ordered
1392 * tagged transaction is appropriate to prevent simple tag
1393 * starvation. Since we'd like to ensure that there is at least
1394 * 1/2 of the timeout length left for a starved transaction to
1395 * complete after we've sent an ordered tag, we must poll at least
1396 * four times in every timeout period. This takes care of the worst
1397 * case where a starved transaction starts during an interval that
1398 * meets the requirement "don't send an ordered tag" test so it takes
1399 * us two intervals to determine that a tag must be sent.
1401 #ifndef DA_ORDEREDTAG_INTERVAL
1402 #define DA_ORDEREDTAG_INTERVAL 4
1405 static struct periph_driver dadriver =
1408 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1411 PERIPHDRIVER_DECLARE(da, dadriver);
1413 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1416 daopen(struct disk *dp)
1418 struct cam_periph *periph;
1419 struct da_softc *softc;
1422 periph = (struct cam_periph *)dp->d_drv1;
1423 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1427 cam_periph_lock(periph);
1428 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1429 cam_periph_unlock(periph);
1430 cam_periph_release(periph);
1434 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1437 softc = (struct da_softc *)periph->softc;
1440 /* Wait for the disk size update. */
1441 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1444 xpt_print(periph->path, "unable to retrieve capacity data\n");
1446 if (periph->flags & CAM_PERIPH_INVALID)
1449 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1450 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1451 daprevent(periph, PR_PREVENT);
1454 softc->flags &= ~DA_FLAG_PACK_INVALID;
1455 softc->flags |= DA_FLAG_OPEN;
1458 cam_periph_unhold(periph);
1459 cam_periph_unlock(periph);
1462 cam_periph_release(periph);
1468 daclose(struct disk *dp)
1470 struct cam_periph *periph;
1471 struct da_softc *softc;
1475 periph = (struct cam_periph *)dp->d_drv1;
1476 softc = (struct da_softc *)periph->softc;
1477 cam_periph_lock(periph);
1478 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1481 if (cam_periph_hold(periph, PRIBIO) == 0) {
1483 /* Flush disk cache. */
1484 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1485 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1486 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1487 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1488 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1489 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1490 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1492 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1493 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1494 softc->disk->d_devstat);
1495 softc->flags &= ~DA_FLAG_DIRTY;
1496 xpt_release_ccb(ccb);
1499 /* Allow medium removal. */
1500 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1501 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1502 daprevent(periph, PR_ALLOW);
1504 cam_periph_unhold(periph);
1508 * If we've got removeable media, mark the blocksize as
1509 * unavailable, since it could change when new media is
1512 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1513 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1515 softc->flags &= ~DA_FLAG_OPEN;
1516 while (softc->refcount != 0)
1517 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1518 cam_periph_unlock(periph);
1519 cam_periph_release(periph);
1524 daschedule(struct cam_periph *periph)
1526 struct da_softc *softc = (struct da_softc *)periph->softc;
1528 if (softc->state != DA_STATE_NORMAL)
1531 cam_iosched_schedule(softc->cam_iosched, periph);
1535 * Actually translate the requested transfer into one the physical driver
1536 * can understand. The transfer is described by a buf and will include
1537 * only one physical transfer.
1540 dastrategy(struct bio *bp)
1542 struct cam_periph *periph;
1543 struct da_softc *softc;
1545 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1546 softc = (struct da_softc *)periph->softc;
1548 cam_periph_lock(periph);
1551 * If the device has been made invalid, error out
1553 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1554 cam_periph_unlock(periph);
1555 biofinish(bp, NULL, ENXIO);
1559 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1562 * Zone commands must be ordered, because they can depend on the
1563 * effects of previously issued commands, and they may affect
1564 * commands after them.
1566 if (bp->bio_cmd == BIO_ZONE)
1567 bp->bio_flags |= BIO_ORDERED;
1570 * Place it in the queue of disk activities for this disk
1572 cam_iosched_queue_work(softc->cam_iosched, bp);
1575 * Schedule ourselves for performing the work.
1578 cam_periph_unlock(periph);
1584 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1586 struct cam_periph *periph;
1587 struct da_softc *softc;
1589 struct ccb_scsiio csio;
1594 periph = dp->d_drv1;
1595 softc = (struct da_softc *)periph->softc;
1596 cam_periph_lock(periph);
1597 secsize = softc->params.secsize;
1599 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1600 cam_periph_unlock(periph);
1605 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1606 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1607 scsi_read_write(&csio,
1611 /*read*/SCSI_RW_WRITE,
1613 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1616 /*data_ptr*/(u_int8_t *) virtual,
1617 /*dxfer_len*/length,
1618 /*sense_len*/SSD_FULL_SIZE,
1619 da_default_timeout * 1000);
1620 xpt_polled_action((union ccb *)&csio);
1622 error = cam_periph_error((union ccb *)&csio,
1623 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1624 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1625 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1626 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1628 printf("Aborting dump due to I/O error.\n");
1629 cam_periph_unlock(periph);
1634 * Sync the disk cache contents to the physical media.
1636 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1638 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1639 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1640 scsi_synchronize_cache(&csio,
1644 /*begin_lba*/0,/* Cover the whole disk */
1648 xpt_polled_action((union ccb *)&csio);
1650 error = cam_periph_error((union ccb *)&csio,
1651 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1652 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1653 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1654 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1656 xpt_print(periph->path, "Synchronize cache failed\n");
1658 cam_periph_unlock(periph);
1663 dagetattr(struct bio *bp)
1666 struct cam_periph *periph;
1668 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1669 cam_periph_lock(periph);
1670 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1672 cam_periph_unlock(periph);
1674 bp->bio_completed = bp->bio_length;
1684 * Install a global async callback. This callback will
1685 * receive async callbacks like "new device found".
1687 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1689 if (status != CAM_REQ_CMP) {
1690 printf("da: Failed to attach master async callback "
1691 "due to status 0x%x!\n", status);
1692 } else if (da_send_ordered) {
1694 /* Register our shutdown event handler */
1695 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1696 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1697 printf("dainit: shutdown event registration failed!\n");
1702 * Callback from GEOM, called when it has finished cleaning up its
1706 dadiskgonecb(struct disk *dp)
1708 struct cam_periph *periph;
1710 periph = (struct cam_periph *)dp->d_drv1;
1711 cam_periph_release(periph);
1715 daoninvalidate(struct cam_periph *periph)
1717 struct da_softc *softc;
1719 softc = (struct da_softc *)periph->softc;
1722 * De-register any async callbacks.
1724 xpt_register_async(0, daasync, periph, periph->path);
1726 softc->flags |= DA_FLAG_PACK_INVALID;
1728 softc->invalidations++;
1732 * Return all queued I/O with ENXIO.
1733 * XXX Handle any transactions queued to the card
1734 * with XPT_ABORT_CCB.
1736 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
1739 * Tell GEOM that we've gone away, we'll get a callback when it is
1740 * done cleaning up its resources.
1742 disk_gone(softc->disk);
1746 dacleanup(struct cam_periph *periph)
1748 struct da_softc *softc;
1750 softc = (struct da_softc *)periph->softc;
1752 cam_periph_unlock(periph);
1754 cam_iosched_fini(softc->cam_iosched);
1757 * If we can't free the sysctl tree, oh well...
1759 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) {
1761 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1762 xpt_print(periph->path,
1763 "can't remove sysctl stats context\n");
1765 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1766 xpt_print(periph->path,
1767 "can't remove sysctl context\n");
1770 callout_drain(&softc->mediapoll_c);
1771 disk_destroy(softc->disk);
1772 callout_drain(&softc->sendordered_c);
1773 free(softc, M_DEVBUF);
1774 cam_periph_lock(periph);
1778 daasync(void *callback_arg, u_int32_t code,
1779 struct cam_path *path, void *arg)
1781 struct cam_periph *periph;
1782 struct da_softc *softc;
1784 periph = (struct cam_periph *)callback_arg;
1786 case AC_FOUND_DEVICE:
1788 struct ccb_getdev *cgd;
1791 cgd = (struct ccb_getdev *)arg;
1795 if (cgd->protocol != PROTO_SCSI)
1797 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED)
1799 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1800 && SID_TYPE(&cgd->inq_data) != T_RBC
1801 && SID_TYPE(&cgd->inq_data) != T_OPTICAL
1802 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM)
1806 * Allocate a peripheral instance for
1807 * this device and start the probe
1810 status = cam_periph_alloc(daregister, daoninvalidate,
1812 "da", CAM_PERIPH_BIO,
1814 AC_FOUND_DEVICE, cgd);
1816 if (status != CAM_REQ_CMP
1817 && status != CAM_REQ_INPROG)
1818 printf("daasync: Unable to attach to new device "
1819 "due to status 0x%x\n", status);
1822 case AC_ADVINFO_CHANGED:
1826 buftype = (uintptr_t)arg;
1827 if (buftype == CDAI_TYPE_PHYS_PATH) {
1828 struct da_softc *softc;
1830 softc = periph->softc;
1831 disk_attr_changed(softc->disk, "GEOM::physpath",
1836 case AC_UNIT_ATTENTION:
1839 int error_code, sense_key, asc, ascq;
1841 softc = (struct da_softc *)periph->softc;
1842 ccb = (union ccb *)arg;
1845 * Handle all UNIT ATTENTIONs except our own,
1846 * as they will be handled by daerror().
1848 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1849 scsi_extract_sense_ccb(ccb,
1850 &error_code, &sense_key, &asc, &ascq)) {
1851 if (asc == 0x2A && ascq == 0x09) {
1852 xpt_print(ccb->ccb_h.path,
1853 "Capacity data has changed\n");
1854 softc->flags &= ~DA_FLAG_PROBED;
1856 } else if (asc == 0x28 && ascq == 0x00) {
1857 softc->flags &= ~DA_FLAG_PROBED;
1858 disk_media_changed(softc->disk, M_NOWAIT);
1859 } else if (asc == 0x3F && ascq == 0x03) {
1860 xpt_print(ccb->ccb_h.path,
1861 "INQUIRY data has changed\n");
1862 softc->flags &= ~DA_FLAG_PROBED;
1866 cam_periph_async(periph, code, path, arg);
1870 softc = (struct da_softc *)periph->softc;
1871 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
1872 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1873 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
1881 struct ccb_hdr *ccbh;
1883 softc = (struct da_softc *)periph->softc;
1885 * Don't fail on the expected unit attention
1888 softc->flags |= DA_FLAG_RETRY_UA;
1889 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1890 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1893 case AC_INQ_CHANGED:
1894 softc = (struct da_softc *)periph->softc;
1895 softc->flags &= ~DA_FLAG_PROBED;
1901 cam_periph_async(periph, code, path, arg);
1905 dasysctlinit(void *context, int pending)
1907 struct cam_periph *periph;
1908 struct da_softc *softc;
1909 char tmpstr[80], tmpstr2[80];
1910 struct ccb_trans_settings cts;
1912 periph = (struct cam_periph *)context;
1914 * periph was held for us when this task was enqueued
1916 if (periph->flags & CAM_PERIPH_INVALID) {
1917 cam_periph_release(periph);
1921 softc = (struct da_softc *)periph->softc;
1922 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1923 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1925 sysctl_ctx_init(&softc->sysctl_ctx);
1926 softc->flags |= DA_FLAG_SCTX_INIT;
1927 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1928 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1929 CTLFLAG_RD, 0, tmpstr);
1930 if (softc->sysctl_tree == NULL) {
1931 printf("dasysctlinit: unable to allocate sysctl tree\n");
1932 cam_periph_release(periph);
1937 * Now register the sysctl handler, so the user can change the value on
1940 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1941 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN,
1942 softc, 0, dadeletemethodsysctl, "A",
1943 "BIO_DELETE execution method");
1944 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1945 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1946 softc, 0, dadeletemaxsysctl, "Q",
1947 "Maximum BIO_DELETE size");
1948 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1949 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1950 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1951 "Minimum CDB size");
1953 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1954 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD,
1955 softc, 0, dazonemodesysctl, "A",
1957 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1958 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD,
1959 softc, 0, dazonesupsysctl, "A",
1961 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1962 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1963 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
1964 "Optimal Number of Open Sequential Write Preferred Zones");
1965 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1966 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1967 "optimal_nonseq_zones", CTLFLAG_RD,
1968 &softc->optimal_nonseq_zones,
1969 "Optimal Number of Non-Sequentially Written Sequential Write "
1971 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1972 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1973 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
1974 "Maximum Number of Open Sequential Write Required Zones");
1976 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1977 SYSCTL_CHILDREN(softc->sysctl_tree),
1981 &softc->error_inject,
1983 "error_inject leaf");
1985 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1986 SYSCTL_CHILDREN(softc->sysctl_tree),
1992 "Unmapped I/O leaf");
1994 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1995 SYSCTL_CHILDREN(softc->sysctl_tree),
2004 * Add some addressing info.
2006 memset(&cts, 0, sizeof (cts));
2007 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
2008 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
2009 cts.type = CTS_TYPE_CURRENT_SETTINGS;
2010 cam_periph_lock(periph);
2011 xpt_action((union ccb *)&cts);
2012 cam_periph_unlock(periph);
2013 if (cts.ccb_h.status != CAM_REQ_CMP) {
2014 cam_periph_release(periph);
2017 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
2018 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
2019 if (fc->valid & CTS_FC_VALID_WWPN) {
2020 softc->wwpn = fc->wwpn;
2021 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
2022 SYSCTL_CHILDREN(softc->sysctl_tree),
2023 OID_AUTO, "wwpn", CTLFLAG_RD,
2024 &softc->wwpn, "World Wide Port Name");
2030 * Now add some useful stats.
2031 * XXX These should live in cam_periph and be common to all periphs
2033 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
2034 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
2035 CTLFLAG_RD, 0, "Statistics");
2036 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2037 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2043 "Transport errors reported by the SIM");
2044 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2045 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2051 "Device timeouts reported by the SIM");
2052 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
2053 SYSCTL_CHILDREN(softc->sysctl_stats_tree),
2055 "pack_invalidations",
2057 &softc->invalidations,
2059 "Device pack invalidations");
2062 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
2063 softc->sysctl_tree);
2065 cam_periph_release(periph);
2069 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
2073 struct da_softc *softc;
2075 softc = (struct da_softc *)arg1;
2077 value = softc->disk->d_delmaxsize;
2078 error = sysctl_handle_64(oidp, &value, 0, req);
2079 if ((error != 0) || (req->newptr == NULL))
2082 /* only accept values smaller than the calculated value */
2083 if (value > dadeletemaxsize(softc, softc->delete_method)) {
2086 softc->disk->d_delmaxsize = value;
2092 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
2096 value = *(int *)arg1;
2098 error = sysctl_handle_int(oidp, &value, 0, req);
2101 || (req->newptr == NULL))
2105 * Acceptable values here are 6, 10, 12 or 16.
2109 else if ((value > 6)
2112 else if ((value > 10)
2115 else if (value > 12)
2118 *(int *)arg1 = value;
2124 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS)
2129 value = da_default_softtimeout / SBT_1MS;
2131 error = sysctl_handle_int(oidp, (int *)&value, 0, req);
2132 if ((error != 0) || (req->newptr == NULL))
2135 /* XXX Should clip this to a reasonable level */
2136 if (value > da_default_timeout * 1000)
2139 da_default_softtimeout = value * SBT_1MS;
2144 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
2147 softc->delete_method = delete_method;
2148 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
2149 softc->delete_func = da_delete_functions[delete_method];
2151 if (softc->delete_method > DA_DELETE_DISABLE)
2152 softc->disk->d_flags |= DISKFLAG_CANDELETE;
2154 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
2158 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
2162 switch(delete_method) {
2163 case DA_DELETE_UNMAP:
2164 sectors = (off_t)softc->unmap_max_lba;
2166 case DA_DELETE_ATA_TRIM:
2167 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
2169 case DA_DELETE_WS16:
2170 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS);
2172 case DA_DELETE_ZERO:
2173 case DA_DELETE_WS10:
2174 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS);
2180 return (off_t)softc->params.secsize *
2181 omin(sectors, softc->params.sectors);
2185 daprobedone(struct cam_periph *periph, union ccb *ccb)
2187 struct da_softc *softc;
2189 softc = (struct da_softc *)periph->softc;
2191 dadeletemethodchoose(softc, DA_DELETE_NONE);
2193 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2197 snprintf(buf, sizeof(buf), "Delete methods: <");
2199 for (i = 0; i <= DA_DELETE_MAX; i++) {
2200 if ((softc->delete_available & (1 << i)) == 0 &&
2201 i != softc->delete_method)
2204 strlcat(buf, ",", sizeof(buf));
2205 strlcat(buf, da_delete_method_names[i],
2207 if (i == softc->delete_method)
2208 strlcat(buf, "(*)", sizeof(buf));
2211 strlcat(buf, ">", sizeof(buf));
2212 printf("%s%d: %s\n", periph->periph_name,
2213 periph->unit_number, buf);
2217 * Since our peripheral may be invalidated by an error
2218 * above or an external event, we must release our CCB
2219 * before releasing the probe lock on the peripheral.
2220 * The peripheral will only go away once the last lock
2221 * is removed, and we need it around for the CCB release
2224 xpt_release_ccb(ccb);
2225 softc->state = DA_STATE_NORMAL;
2226 softc->flags |= DA_FLAG_PROBED;
2228 wakeup(&softc->disk->d_mediasize);
2229 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
2230 softc->flags |= DA_FLAG_ANNOUNCED;
2231 cam_periph_unhold(periph);
2233 cam_periph_release_locked(periph);
2237 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
2241 /* If available, prefer the method requested by user. */
2242 i = softc->delete_method_pref;
2243 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2244 if (methods & (1 << i)) {
2245 dadeletemethodset(softc, i);
2249 /* Use the pre-defined order to choose the best performing delete. */
2250 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
2251 if (i == DA_DELETE_ZERO)
2253 if (softc->delete_available & (1 << i)) {
2254 dadeletemethodset(softc, i);
2259 /* Fallback to default. */
2260 dadeletemethodset(softc, default_method);
2264 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
2268 struct da_softc *softc;
2269 int i, error, methods, value;
2271 softc = (struct da_softc *)arg1;
2273 value = softc->delete_method;
2274 if (value < 0 || value > DA_DELETE_MAX)
2277 p = da_delete_method_names[value];
2278 strncpy(buf, p, sizeof(buf));
2279 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2280 if (error != 0 || req->newptr == NULL)
2282 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2283 for (i = 0; i <= DA_DELETE_MAX; i++) {
2284 if (strcmp(buf, da_delete_method_names[i]) == 0)
2287 if (i > DA_DELETE_MAX)
2289 softc->delete_method_pref = i;
2290 dadeletemethodchoose(softc, DA_DELETE_NONE);
2295 dazonemodesysctl(SYSCTL_HANDLER_ARGS)
2298 struct da_softc *softc;
2301 softc = (struct da_softc *)arg1;
2303 switch (softc->zone_mode) {
2304 case DA_ZONE_DRIVE_MANAGED:
2305 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
2307 case DA_ZONE_HOST_AWARE:
2308 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
2310 case DA_ZONE_HOST_MANAGED:
2311 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
2315 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
2319 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
2325 dazonesupsysctl(SYSCTL_HANDLER_ARGS)
2328 struct da_softc *softc;
2333 softc = (struct da_softc *)arg1;
2337 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0);
2339 for (i = 0; i < sizeof(da_zone_desc_table) /
2340 sizeof(da_zone_desc_table[0]); i++) {
2341 if (softc->zone_flags & da_zone_desc_table[i].value) {
2343 sbuf_printf(&sb, ", ");
2346 sbuf_cat(&sb, da_zone_desc_table[i].desc);
2351 sbuf_printf(&sb, "None");
2355 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req);
2361 daregister(struct cam_periph *periph, void *arg)
2363 struct da_softc *softc;
2364 struct ccb_pathinq cpi;
2365 struct ccb_getdev *cgd;
2369 cgd = (struct ccb_getdev *)arg;
2371 printf("daregister: no getdev CCB, can't register device\n");
2372 return(CAM_REQ_CMP_ERR);
2375 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2378 if (softc == NULL) {
2379 printf("daregister: Unable to probe new device. "
2380 "Unable to allocate softc\n");
2381 return(CAM_REQ_CMP_ERR);
2384 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) {
2385 printf("daregister: Unable to probe new device. "
2386 "Unable to allocate iosched memory\n");
2387 free(softc, M_DEVBUF);
2388 return(CAM_REQ_CMP_ERR);
2391 LIST_INIT(&softc->pending_ccbs);
2392 softc->state = DA_STATE_PROBE_RC;
2393 bioq_init(&softc->delete_run_queue);
2394 if (SID_IS_REMOVABLE(&cgd->inq_data))
2395 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2396 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2397 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2398 softc->ws_max_blks = WS16_MAX_BLKS;
2399 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2400 softc->rotating = 1;
2402 periph->softc = softc;
2405 * See if this device has any quirks.
2407 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2408 (caddr_t)da_quirk_table,
2409 nitems(da_quirk_table),
2410 sizeof(*da_quirk_table), scsi_inquiry_match);
2413 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2415 softc->quirks = DA_Q_NONE;
2417 /* Check if the SIM does not want 6 byte commands */
2418 bzero(&cpi, sizeof(cpi));
2419 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2420 cpi.ccb_h.func_code = XPT_PATH_INQ;
2421 xpt_action((union ccb *)&cpi);
2422 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2423 softc->quirks |= DA_Q_NO_6_BYTE;
2425 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM)
2426 softc->zone_mode = DA_ZONE_HOST_MANAGED;
2427 else if (softc->quirks & DA_Q_SMR_DM)
2428 softc->zone_mode = DA_ZONE_DRIVE_MANAGED;
2430 softc->zone_mode = DA_ZONE_NONE;
2432 if (softc->zone_mode != DA_ZONE_NONE) {
2433 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2434 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC))
2435 softc->zone_interface = DA_ZONE_IF_ATA_SAT;
2437 softc->zone_interface = DA_ZONE_IF_ATA_PASS;
2439 softc->zone_interface = DA_ZONE_IF_SCSI;
2442 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2445 * Take an exclusive refcount on the periph while dastart is called
2446 * to finish the probe. The reference will be dropped in dadone at
2449 (void)cam_periph_hold(periph, PRIBIO);
2452 * Schedule a periodic event to occasionally send an
2453 * ordered tag to a device.
2455 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2456 callout_reset(&softc->sendordered_c,
2457 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2458 dasendorderedtag, softc);
2460 cam_periph_unlock(periph);
2462 * RBC devices don't have to support READ(6), only READ(10).
2464 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2465 softc->minimum_cmd_size = 10;
2467 softc->minimum_cmd_size = 6;
2470 * Load the user's default, if any.
2472 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2473 periph->unit_number);
2474 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2477 * 6, 10, 12 and 16 are the currently permissible values.
2479 if (softc->minimum_cmd_size < 6)
2480 softc->minimum_cmd_size = 6;
2481 else if ((softc->minimum_cmd_size > 6)
2482 && (softc->minimum_cmd_size <= 10))
2483 softc->minimum_cmd_size = 10;
2484 else if ((softc->minimum_cmd_size > 10)
2485 && (softc->minimum_cmd_size <= 12))
2486 softc->minimum_cmd_size = 12;
2487 else if (softc->minimum_cmd_size > 12)
2488 softc->minimum_cmd_size = 16;
2490 /* Predict whether device may support READ CAPACITY(16). */
2491 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2492 (softc->quirks & DA_Q_NO_RC16) == 0) {
2493 softc->flags |= DA_FLAG_CAN_RC16;
2494 softc->state = DA_STATE_PROBE_RC16;
2498 * Register this media as a disk.
2500 softc->disk = disk_alloc();
2501 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2502 periph->unit_number, 0,
2503 DEVSTAT_BS_UNAVAILABLE,
2504 SID_TYPE(&cgd->inq_data) |
2505 XPORT_DEVSTAT_TYPE(cpi.transport),
2506 DEVSTAT_PRIORITY_DISK);
2507 softc->disk->d_open = daopen;
2508 softc->disk->d_close = daclose;
2509 softc->disk->d_strategy = dastrategy;
2510 softc->disk->d_dump = dadump;
2511 softc->disk->d_getattr = dagetattr;
2512 softc->disk->d_gone = dadiskgonecb;
2513 softc->disk->d_name = "da";
2514 softc->disk->d_drv1 = periph;
2516 softc->maxio = DFLTPHYS; /* traditional default */
2517 else if (cpi.maxio > MAXPHYS)
2518 softc->maxio = MAXPHYS; /* for safety */
2520 softc->maxio = cpi.maxio;
2521 softc->disk->d_maxsize = softc->maxio;
2522 softc->disk->d_unit = periph->unit_number;
2523 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
2524 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2525 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2526 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) {
2527 softc->unmappedio = 1;
2528 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2529 xpt_print(periph->path, "UNMAPPED\n");
2531 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2532 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2533 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2534 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2535 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2536 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2537 softc->disk->d_hba_vendor = cpi.hba_vendor;
2538 softc->disk->d_hba_device = cpi.hba_device;
2539 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2540 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2543 * Acquire a reference to the periph before we register with GEOM.
2544 * We'll release this reference once GEOM calls us back (via
2545 * dadiskgonecb()) telling us that our provider has been freed.
2547 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2548 xpt_print(periph->path, "%s: lost periph during "
2549 "registration!\n", __func__);
2550 cam_periph_lock(periph);
2551 return (CAM_REQ_CMP_ERR);
2554 disk_create(softc->disk, DISK_VERSION);
2555 cam_periph_lock(periph);
2558 * Add async callbacks for events of interest.
2559 * I don't bother checking if this fails as,
2560 * in most cases, the system will function just
2561 * fine without them and the only alternative
2562 * would be to not attach the device on failure.
2564 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2565 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION |
2566 AC_INQ_CHANGED, daasync, periph, periph->path);
2569 * Emit an attribute changed notification just in case
2570 * physical path information arrived before our async
2571 * event handler was registered, but after anyone attaching
2572 * to our disk device polled it.
2574 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2577 * Schedule a periodic media polling events.
2579 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2580 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2581 (cgd->inq_flags & SID_AEN) == 0 &&
2582 da_poll_period != 0)
2583 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2584 damediapoll, periph);
2586 xpt_schedule(periph, CAM_PRIORITY_DEV);
2588 return(CAM_REQ_CMP);
2592 da_zone_bio_to_scsi(int disk_zone_cmd)
2594 switch (disk_zone_cmd) {
2595 case DISK_ZONE_OPEN:
2596 return ZBC_OUT_SA_OPEN;
2597 case DISK_ZONE_CLOSE:
2598 return ZBC_OUT_SA_CLOSE;
2599 case DISK_ZONE_FINISH:
2600 return ZBC_OUT_SA_FINISH;
2602 return ZBC_OUT_SA_RWP;
2609 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
2612 struct da_softc *softc;
2617 if (bp->bio_cmd != BIO_ZONE) {
2622 softc = periph->softc;
2624 switch (bp->bio_zone.zone_cmd) {
2625 case DISK_ZONE_OPEN:
2626 case DISK_ZONE_CLOSE:
2627 case DISK_ZONE_FINISH:
2628 case DISK_ZONE_RWP: {
2633 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd);
2634 if (zone_sa == -1) {
2635 xpt_print(periph->path, "Cannot translate zone "
2636 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd);
2642 lba = bp->bio_zone.zone_params.rwp.id;
2644 if (bp->bio_zone.zone_params.rwp.flags &
2645 DISK_ZONE_RWP_FLAG_ALL)
2646 zone_flags |= ZBC_OUT_ALL;
2648 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2649 scsi_zbc_out(&ccb->csio,
2650 /*retries*/ da_retry_count,
2652 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2653 /*service_action*/ zone_sa,
2655 /*zone_flags*/ zone_flags,
2658 /*sense_len*/ SSD_FULL_SIZE,
2659 /*timeout*/ da_default_timeout * 1000);
2662 * Note that in this case, even though we can
2663 * technically use NCQ, we don't bother for several
2665 * 1. It hasn't been tested on a SAT layer that
2666 * supports it. This is new as of SAT-4.
2667 * 2. Even when there is a SAT layer that supports
2668 * it, that SAT layer will also probably support
2669 * ZBC -> ZAC translation, since they are both
2670 * in the SAT-4 spec.
2671 * 3. Translation will likely be preferable to ATA
2672 * passthrough. LSI / Avago at least single
2673 * steps ATA passthrough commands in the HBA,
2674 * regardless of protocol, so unless that
2675 * changes, there is a performance penalty for
2676 * doing ATA passthrough no matter whether
2677 * you're using NCQ/FPDMA, DMA or PIO.
2678 * 4. It requires a 32-byte CDB, which at least at
2679 * this point in CAM requires a CDB pointer, which
2680 * would require us to allocate an additional bit
2681 * of storage separate from the CCB.
2683 error = scsi_ata_zac_mgmt_out(&ccb->csio,
2684 /*retries*/ da_retry_count,
2686 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2688 /*zm_action*/ zone_sa,
2690 /*zone_flags*/ zone_flags,
2693 /*cdb_storage*/ NULL,
2694 /*cdb_storage_len*/ 0,
2695 /*sense_len*/ SSD_FULL_SIZE,
2696 /*timeout*/ da_default_timeout * 1000);
2699 xpt_print(periph->path,
2700 "scsi_ata_zac_mgmt_out() returned an "
2709 case DISK_ZONE_REPORT_ZONES: {
2711 uint32_t num_entries, alloc_size;
2712 struct disk_zone_report *rep;
2714 rep = &bp->bio_zone.zone_params.report;
2716 num_entries = rep->entries_allocated;
2717 if (num_entries == 0) {
2718 xpt_print(periph->path, "No entries allocated for "
2719 "Report Zones request\n");
2723 alloc_size = sizeof(struct scsi_report_zones_hdr) +
2724 (sizeof(struct scsi_report_zones_desc) * num_entries);
2725 alloc_size = min(alloc_size, softc->disk->d_maxsize);
2726 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO);
2727 if (rz_ptr == NULL) {
2728 xpt_print(periph->path, "Unable to allocate memory "
2729 "for Report Zones request\n");
2734 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) {
2735 scsi_zbc_in(&ccb->csio,
2736 /*retries*/ da_retry_count,
2738 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2739 /*service_action*/ ZBC_IN_SA_REPORT_ZONES,
2740 /*zone_start_lba*/ rep->starting_id,
2741 /*zone_options*/ rep->rep_options,
2742 /*data_ptr*/ rz_ptr,
2743 /*dxfer_len*/ alloc_size,
2744 /*sense_len*/ SSD_FULL_SIZE,
2745 /*timeout*/ da_default_timeout * 1000);
2748 * Note that in this case, even though we can
2749 * technically use NCQ, we don't bother for several
2751 * 1. It hasn't been tested on a SAT layer that
2752 * supports it. This is new as of SAT-4.
2753 * 2. Even when there is a SAT layer that supports
2754 * it, that SAT layer will also probably support
2755 * ZBC -> ZAC translation, since they are both
2756 * in the SAT-4 spec.
2757 * 3. Translation will likely be preferable to ATA
2758 * passthrough. LSI / Avago at least single
2759 * steps ATA passthrough commands in the HBA,
2760 * regardless of protocol, so unless that
2761 * changes, there is a performance penalty for
2762 * doing ATA passthrough no matter whether
2763 * you're using NCQ/FPDMA, DMA or PIO.
2764 * 4. It requires a 32-byte CDB, which at least at
2765 * this point in CAM requires a CDB pointer, which
2766 * would require us to allocate an additional bit
2767 * of storage separate from the CCB.
2769 error = scsi_ata_zac_mgmt_in(&ccb->csio,
2770 /*retries*/ da_retry_count,
2772 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2774 /*zm_action*/ ATA_ZM_REPORT_ZONES,
2775 /*zone_id*/ rep->starting_id,
2776 /*zone_flags*/ rep->rep_options,
2777 /*data_ptr*/ rz_ptr,
2778 /*dxfer_len*/ alloc_size,
2779 /*cdb_storage*/ NULL,
2780 /*cdb_storage_len*/ 0,
2781 /*sense_len*/ SSD_FULL_SIZE,
2782 /*timeout*/ da_default_timeout * 1000);
2785 xpt_print(periph->path,
2786 "scsi_ata_zac_mgmt_in() returned an "
2793 * For BIO_ZONE, this isn't normally needed. However, it
2794 * is used by devstat_end_transaction_bio() to determine
2795 * how much data was transferred.
2798 * XXX KDM we have a problem. But I'm not sure how to fix
2799 * it. devstat uses bio_bcount - bio_resid to calculate
2800 * the amount of data transferred. The GEOM disk code
2801 * uses bio_length - bio_resid to calculate the amount of
2802 * data in bio_completed. We have different structure
2803 * sizes above and below the ada(4) driver. So, if we
2804 * use the sizes above, the amount transferred won't be
2805 * quite accurate for devstat. If we use different sizes
2806 * for bio_bcount and bio_length (above and below
2807 * respectively), then the residual needs to match one or
2808 * the other. Everything is calculated after the bio
2809 * leaves the driver, so changing the values around isn't
2810 * really an option. For now, just set the count to the
2811 * passed in length. This means that the calculations
2812 * above (e.g. bio_completed) will be correct, but the
2813 * amount of data reported to devstat will be slightly
2814 * under or overstated.
2816 bp->bio_bcount = bp->bio_length;
2822 case DISK_ZONE_GET_PARAMS: {
2823 struct disk_zone_disk_params *params;
2825 params = &bp->bio_zone.zone_params.disk_params;
2826 bzero(params, sizeof(*params));
2828 switch (softc->zone_mode) {
2829 case DA_ZONE_DRIVE_MANAGED:
2830 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
2832 case DA_ZONE_HOST_AWARE:
2833 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
2835 case DA_ZONE_HOST_MANAGED:
2836 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
2840 params->zone_mode = DISK_ZONE_MODE_NONE;
2844 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ)
2845 params->flags |= DISK_ZONE_DISK_URSWRZ;
2847 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) {
2848 params->optimal_seq_zones = softc->optimal_seq_zones;
2849 params->flags |= DISK_ZONE_OPT_SEQ_SET;
2852 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) {
2853 params->optimal_nonseq_zones =
2854 softc->optimal_nonseq_zones;
2855 params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
2858 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) {
2859 params->max_seq_zones = softc->max_seq_zones;
2860 params->flags |= DISK_ZONE_MAX_SEQ_SET;
2862 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP)
2863 params->flags |= DISK_ZONE_RZ_SUP;
2865 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP)
2866 params->flags |= DISK_ZONE_OPEN_SUP;
2868 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP)
2869 params->flags |= DISK_ZONE_CLOSE_SUP;
2871 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP)
2872 params->flags |= DISK_ZONE_FINISH_SUP;
2874 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP)
2875 params->flags |= DISK_ZONE_RWP_SUP;
2886 dastart(struct cam_periph *periph, union ccb *start_ccb)
2888 struct da_softc *softc;
2890 softc = (struct da_softc *)periph->softc;
2892 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2895 switch (softc->state) {
2896 case DA_STATE_NORMAL:
2902 bp = cam_iosched_next_bio(softc->cam_iosched);
2904 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2905 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2906 scsi_test_unit_ready(&start_ccb->csio,
2907 /*retries*/ da_retry_count,
2911 da_default_timeout * 1000);
2912 start_ccb->ccb_h.ccb_bp = NULL;
2913 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2914 xpt_action(start_ccb);
2916 xpt_release_ccb(start_ccb);
2920 if (bp->bio_cmd == BIO_DELETE) {
2921 if (softc->delete_func != NULL) {
2922 softc->delete_func(periph, start_ccb, bp);
2925 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */
2926 biofinish(bp, NULL, 0);
2931 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) {
2932 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR);
2933 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */
2936 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2937 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2938 softc->flags &= ~DA_FLAG_NEED_OTAG;
2939 softc->flags |= DA_FLAG_WAS_OTAG;
2940 tag_code = MSG_ORDERED_Q_TAG;
2942 tag_code = MSG_SIMPLE_Q_TAG;
2945 switch (bp->bio_cmd) {
2952 biotrack(bp, __func__);
2954 if (bp->bio_cmd == BIO_WRITE) {
2955 softc->flags |= DA_FLAG_DIRTY;
2956 rw_op = SCSI_RW_WRITE;
2958 rw_op = SCSI_RW_READ;
2961 data_ptr = bp->bio_data;
2962 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2963 rw_op |= SCSI_RW_BIO;
2967 scsi_read_write(&start_ccb->csio,
2968 /*retries*/da_retry_count,
2970 /*tag_action*/tag_code,
2973 softc->minimum_cmd_size,
2974 /*lba*/bp->bio_pblkno,
2975 /*block_count*/bp->bio_bcount /
2976 softc->params.secsize,
2978 /*dxfer_len*/ bp->bio_bcount,
2979 /*sense_len*/SSD_FULL_SIZE,
2980 da_default_timeout * 1000);
2981 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
2982 start_ccb->csio.bio = bp;
2988 * BIO_FLUSH doesn't currently communicate
2989 * range data, so we synchronize the cache
2990 * over the whole disk. We also force
2991 * ordered tag semantics the flush applies
2992 * to all previously queued I/O.
2994 scsi_synchronize_cache(&start_ccb->csio,
3001 da_default_timeout*1000);
3004 int error, queue_ccb;
3008 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb);
3010 || (queue_ccb == 0)) {
3011 biofinish(bp, NULL, error);
3012 xpt_release_ccb(start_ccb);
3018 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
3019 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
3020 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout);
3023 LIST_INSERT_HEAD(&softc->pending_ccbs,
3024 &start_ccb->ccb_h, periph_links.le);
3026 /* We expect a unit attention from this device */
3027 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
3028 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
3029 softc->flags &= ~DA_FLAG_RETRY_UA;
3032 start_ccb->ccb_h.ccb_bp = bp;
3034 cam_periph_unlock(periph);
3035 xpt_action(start_ccb);
3036 cam_periph_lock(periph);
3039 /* May have more work to do, so ensure we stay scheduled */
3043 case DA_STATE_PROBE_RC:
3045 struct scsi_read_capacity_data *rcap;
3047 rcap = (struct scsi_read_capacity_data *)
3048 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
3050 printf("dastart: Couldn't malloc read_capacity data\n");
3051 /* da_free_periph??? */
3054 scsi_read_capacity(&start_ccb->csio,
3055 /*retries*/da_retry_count,
3061 start_ccb->ccb_h.ccb_bp = NULL;
3062 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
3063 xpt_action(start_ccb);
3066 case DA_STATE_PROBE_RC16:
3068 struct scsi_read_capacity_data_long *rcaplong;
3070 rcaplong = (struct scsi_read_capacity_data_long *)
3071 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
3072 if (rcaplong == NULL) {
3073 printf("dastart: Couldn't malloc read_capacity data\n");
3074 /* da_free_periph??? */
3077 scsi_read_capacity_16(&start_ccb->csio,
3078 /*retries*/ da_retry_count,
3080 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3084 /*rcap_buf*/ (uint8_t *)rcaplong,
3085 /*rcap_buf_len*/ sizeof(*rcaplong),
3086 /*sense_len*/ SSD_FULL_SIZE,
3087 /*timeout*/ da_default_timeout * 1000);
3088 start_ccb->ccb_h.ccb_bp = NULL;
3089 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
3090 xpt_action(start_ccb);
3093 case DA_STATE_PROBE_LBP:
3095 struct scsi_vpd_logical_block_prov *lbp;
3097 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
3099 * If we get here we don't support any SBC-3 delete
3100 * methods with UNMAP as the Logical Block Provisioning
3101 * VPD page support is required for devices which
3102 * support it according to T10/1799-D Revision 31
3103 * however older revisions of the spec don't mandate
3104 * this so we currently don't remove these methods
3105 * from the available set.
3107 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3111 lbp = (struct scsi_vpd_logical_block_prov *)
3112 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
3115 printf("dastart: Couldn't malloc lbp data\n");
3116 /* da_free_periph??? */
3120 scsi_inquiry(&start_ccb->csio,
3121 /*retries*/da_retry_count,
3123 /*tag_action*/MSG_SIMPLE_Q_TAG,
3124 /*inq_buf*/(u_int8_t *)lbp,
3125 /*inq_len*/sizeof(*lbp),
3127 /*page_code*/SVPD_LBP,
3128 /*sense_len*/SSD_MIN_SIZE,
3129 /*timeout*/da_default_timeout * 1000);
3130 start_ccb->ccb_h.ccb_bp = NULL;
3131 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
3132 xpt_action(start_ccb);
3135 case DA_STATE_PROBE_BLK_LIMITS:
3137 struct scsi_vpd_block_limits *block_limits;
3139 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
3140 /* Not supported skip to next probe */
3141 softc->state = DA_STATE_PROBE_BDC;
3145 block_limits = (struct scsi_vpd_block_limits *)
3146 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
3148 if (block_limits == NULL) {
3149 printf("dastart: Couldn't malloc block_limits data\n");
3150 /* da_free_periph??? */
3154 scsi_inquiry(&start_ccb->csio,
3155 /*retries*/da_retry_count,
3157 /*tag_action*/MSG_SIMPLE_Q_TAG,
3158 /*inq_buf*/(u_int8_t *)block_limits,
3159 /*inq_len*/sizeof(*block_limits),
3161 /*page_code*/SVPD_BLOCK_LIMITS,
3162 /*sense_len*/SSD_MIN_SIZE,
3163 /*timeout*/da_default_timeout * 1000);
3164 start_ccb->ccb_h.ccb_bp = NULL;
3165 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
3166 xpt_action(start_ccb);
3169 case DA_STATE_PROBE_BDC:
3171 struct scsi_vpd_block_characteristics *bdc;
3173 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
3174 softc->state = DA_STATE_PROBE_ATA;
3178 bdc = (struct scsi_vpd_block_characteristics *)
3179 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3182 printf("dastart: Couldn't malloc bdc data\n");
3183 /* da_free_periph??? */
3187 scsi_inquiry(&start_ccb->csio,
3188 /*retries*/da_retry_count,
3190 /*tag_action*/MSG_SIMPLE_Q_TAG,
3191 /*inq_buf*/(u_int8_t *)bdc,
3192 /*inq_len*/sizeof(*bdc),
3194 /*page_code*/SVPD_BDC,
3195 /*sense_len*/SSD_MIN_SIZE,
3196 /*timeout*/da_default_timeout * 1000);
3197 start_ccb->ccb_h.ccb_bp = NULL;
3198 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
3199 xpt_action(start_ccb);
3202 case DA_STATE_PROBE_ATA:
3204 struct ata_params *ata_params;
3206 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
3207 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
3208 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
3210 * Note that if the ATA VPD page isn't
3211 * supported, we aren't talking to an ATA
3212 * device anyway. Support for that VPD
3213 * page is mandatory for SCSI to ATA (SAT)
3214 * translation layers.
3216 softc->state = DA_STATE_PROBE_ZONE;
3219 daprobedone(periph, start_ccb);
3223 ata_params = (struct ata_params*)
3224 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO);
3226 if (ata_params == NULL) {
3227 xpt_print(periph->path, "Couldn't malloc ata_params "
3229 /* da_free_periph??? */
3233 scsi_ata_identify(&start_ccb->csio,
3234 /*retries*/da_retry_count,
3236 /*tag_action*/MSG_SIMPLE_Q_TAG,
3237 /*data_ptr*/(u_int8_t *)ata_params,
3238 /*dxfer_len*/sizeof(*ata_params),
3239 /*sense_len*/SSD_FULL_SIZE,
3240 /*timeout*/da_default_timeout * 1000);
3241 start_ccb->ccb_h.ccb_bp = NULL;
3242 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
3243 xpt_action(start_ccb);
3246 case DA_STATE_PROBE_ATA_LOGDIR:
3248 struct ata_gp_log_dir *log_dir;
3253 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) {
3255 * If we don't have log support, not much point in
3256 * trying to probe zone support.
3258 daprobedone(periph, start_ccb);
3263 * If we have an ATA device (the SCSI ATA Information VPD
3264 * page should be present and the ATA identify should have
3265 * succeeded) and it supports logs, ask for the log directory.
3268 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO);
3269 if (log_dir == NULL) {
3270 xpt_print(periph->path, "Couldn't malloc log_dir "
3272 daprobedone(periph, start_ccb);
3276 retval = scsi_ata_read_log(&start_ccb->csio,
3277 /*retries*/ da_retry_count,
3279 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3280 /*log_address*/ ATA_LOG_DIRECTORY,
3283 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3284 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3285 /*data_ptr*/ (uint8_t *)log_dir,
3286 /*dxfer_len*/ sizeof(*log_dir),
3287 /*sense_len*/ SSD_FULL_SIZE,
3288 /*timeout*/ da_default_timeout * 1000);
3291 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3292 free(log_dir, M_SCSIDA);
3293 daprobedone(periph, start_ccb);
3296 start_ccb->ccb_h.ccb_bp = NULL;
3297 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR;
3298 xpt_action(start_ccb);
3301 case DA_STATE_PROBE_ATA_IDDIR:
3303 struct ata_identify_log_pages *id_dir;
3309 * Check here to see whether the Identify Device log is
3310 * supported in the directory of logs. If so, continue
3311 * with requesting the log of identify device pages.
3313 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) {
3314 daprobedone(periph, start_ccb);
3318 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO);
3319 if (id_dir == NULL) {
3320 xpt_print(periph->path, "Couldn't malloc id_dir "
3322 daprobedone(periph, start_ccb);
3326 retval = scsi_ata_read_log(&start_ccb->csio,
3327 /*retries*/ da_retry_count,
3329 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3330 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3331 /*page_number*/ ATA_IDL_PAGE_LIST,
3333 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3334 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3335 /*data_ptr*/ (uint8_t *)id_dir,
3336 /*dxfer_len*/ sizeof(*id_dir),
3337 /*sense_len*/ SSD_FULL_SIZE,
3338 /*timeout*/ da_default_timeout * 1000);
3341 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3342 free(id_dir, M_SCSIDA);
3343 daprobedone(periph, start_ccb);
3346 start_ccb->ccb_h.ccb_bp = NULL;
3347 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR;
3348 xpt_action(start_ccb);
3351 case DA_STATE_PROBE_ATA_SUP:
3353 struct ata_identify_log_sup_cap *sup_cap;
3359 * Check here to see whether the Supported Capabilities log
3360 * is in the list of Identify Device logs.
3362 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) {
3363 daprobedone(periph, start_ccb);
3367 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO);
3368 if (sup_cap == NULL) {
3369 xpt_print(periph->path, "Couldn't malloc sup_cap "
3371 daprobedone(periph, start_ccb);
3375 retval = scsi_ata_read_log(&start_ccb->csio,
3376 /*retries*/ da_retry_count,
3378 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3379 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3380 /*page_number*/ ATA_IDL_SUP_CAP,
3382 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3383 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3384 /*data_ptr*/ (uint8_t *)sup_cap,
3385 /*dxfer_len*/ sizeof(*sup_cap),
3386 /*sense_len*/ SSD_FULL_SIZE,
3387 /*timeout*/ da_default_timeout * 1000);
3390 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3391 free(sup_cap, M_SCSIDA);
3392 daprobedone(periph, start_ccb);
3397 start_ccb->ccb_h.ccb_bp = NULL;
3398 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP;
3399 xpt_action(start_ccb);
3402 case DA_STATE_PROBE_ATA_ZONE:
3404 struct ata_zoned_info_log *ata_zone;
3410 * Check here to see whether the zoned device information
3411 * page is supported. If so, continue on to request it.
3412 * If not, skip to DA_STATE_PROBE_LOG or done.
3414 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) {
3415 daprobedone(periph, start_ccb);
3418 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA,
3420 if (ata_zone == NULL) {
3421 xpt_print(periph->path, "Couldn't malloc ata_zone "
3423 daprobedone(periph, start_ccb);
3427 retval = scsi_ata_read_log(&start_ccb->csio,
3428 /*retries*/ da_retry_count,
3430 /*tag_action*/ MSG_SIMPLE_Q_TAG,
3431 /*log_address*/ ATA_IDENTIFY_DATA_LOG,
3432 /*page_number*/ ATA_IDL_ZDI,
3434 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ?
3435 AP_PROTO_DMA : AP_PROTO_PIO_IN,
3436 /*data_ptr*/ (uint8_t *)ata_zone,
3437 /*dxfer_len*/ sizeof(*ata_zone),
3438 /*sense_len*/ SSD_FULL_SIZE,
3439 /*timeout*/ da_default_timeout * 1000);
3442 xpt_print(periph->path, "scsi_ata_read_log() failed!");
3443 free(ata_zone, M_SCSIDA);
3444 daprobedone(periph, start_ccb);
3447 start_ccb->ccb_h.ccb_bp = NULL;
3448 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE;
3449 xpt_action(start_ccb);
3453 case DA_STATE_PROBE_ZONE:
3455 struct scsi_vpd_zoned_bdc *bdc;
3458 * Note that this page will be supported for SCSI protocol
3459 * devices that support ZBC (SMR devices), as well as ATA
3460 * protocol devices that are behind a SAT (SCSI to ATA
3461 * Translation) layer that supports converting ZBC commands
3462 * to their ZAC equivalents.
3464 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) {
3465 daprobedone(periph, start_ccb);
3468 bdc = (struct scsi_vpd_zoned_bdc *)
3469 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
3472 xpt_release_ccb(start_ccb);
3473 xpt_print(periph->path, "Couldn't malloc zone VPD "
3477 scsi_inquiry(&start_ccb->csio,
3478 /*retries*/da_retry_count,
3480 /*tag_action*/MSG_SIMPLE_Q_TAG,
3481 /*inq_buf*/(u_int8_t *)bdc,
3482 /*inq_len*/sizeof(*bdc),
3484 /*page_code*/SVPD_ZONED_BDC,
3485 /*sense_len*/SSD_FULL_SIZE,
3486 /*timeout*/da_default_timeout * 1000);
3487 start_ccb->ccb_h.ccb_bp = NULL;
3488 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE;
3489 xpt_action(start_ccb);
3496 * In each of the methods below, while its the caller's
3497 * responsibility to ensure the request will fit into a
3498 * single device request, we might have changed the delete
3499 * method due to the device incorrectly advertising either
3500 * its supported methods or limits.
3502 * To prevent this causing further issues we validate the
3503 * against the methods limits, and warn which would
3504 * otherwise be unnecessary.
3507 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3509 struct da_softc *softc = (struct da_softc *)periph->softc;;
3511 uint8_t *buf = softc->unmap_buf;
3512 uint64_t lba, lastlba = (uint64_t)-1;
3513 uint64_t totalcount = 0;
3515 uint32_t lastcount = 0, c;
3516 uint32_t off, ranges = 0;
3519 * Currently this doesn't take the UNMAP
3520 * Granularity and Granularity Alignment
3521 * fields into account.
3523 * This could result in both unoptimal unmap
3524 * requests as as well as UNMAP calls unmapping
3525 * fewer LBA's than requested.
3528 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3532 * Note: ada and da are different in how they store the
3533 * pending bp's in a trim. ada stores all of them in the
3534 * trim_req.bps. da stores all but the first one in the
3535 * delete_run_queue. ada then completes all the bps in
3536 * its adadone() loop. da completes all the bps in the
3537 * delete_run_queue in dadone, and relies on the biodone
3538 * after to complete. This should be reconciled since there's
3539 * no real reason to do it differently. XXX
3542 bioq_insert_tail(&softc->delete_run_queue, bp1);
3543 lba = bp1->bio_pblkno;
3544 count = bp1->bio_bcount / softc->params.secsize;
3546 /* Try to extend the previous range. */
3547 if (lba == lastlba) {
3548 c = omin(count, UNMAP_RANGE_MAX - lastcount);
3550 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
3552 scsi_ulto4b(lastcount, &buf[off + 8]);
3559 c = omin(count, UNMAP_RANGE_MAX);
3560 if (totalcount + c > softc->unmap_max_lba ||
3561 ranges >= softc->unmap_max_ranges) {
3562 xpt_print(periph->path,
3563 "%s issuing short delete %ld > %ld"
3565 da_delete_method_desc[softc->delete_method],
3566 totalcount + c, softc->unmap_max_lba,
3567 ranges, softc->unmap_max_ranges);
3570 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
3571 scsi_u64to8b(lba, &buf[off + 0]);
3572 scsi_ulto4b(c, &buf[off + 8]);
3580 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3583 if (ranges >= softc->unmap_max_ranges ||
3584 totalcount + bp1->bio_bcount /
3585 softc->params.secsize > softc->unmap_max_lba) {
3586 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3590 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
3591 scsi_ulto2b(ranges * 16, &buf[2]);
3593 scsi_unmap(&ccb->csio,
3594 /*retries*/da_retry_count,
3596 /*tag_action*/MSG_SIMPLE_Q_TAG,
3599 /*dxfer_len*/ ranges * 16 + 8,
3600 /*sense_len*/SSD_FULL_SIZE,
3601 da_default_timeout * 1000);
3602 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3603 ccb->ccb_h.flags |= CAM_UNLOCKED;
3604 cam_iosched_submit_trim(softc->cam_iosched);
3608 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3610 struct da_softc *softc = (struct da_softc *)periph->softc;
3612 uint8_t *buf = softc->unmap_buf;
3613 uint64_t lastlba = (uint64_t)-1;
3616 uint32_t lastcount = 0, c, requestcount;
3617 int ranges = 0, off, block_count;
3619 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
3622 if (bp1 != bp)//XXX imp XXX
3623 bioq_insert_tail(&softc->delete_run_queue, bp1);
3624 lba = bp1->bio_pblkno;
3625 count = bp1->bio_bcount / softc->params.secsize;
3626 requestcount = count;
3628 /* Try to extend the previous range. */
3629 if (lba == lastlba) {
3630 c = omin(count, ATA_DSM_RANGE_MAX - lastcount);
3632 off = (ranges - 1) * 8;
3633 buf[off + 6] = lastcount & 0xff;
3634 buf[off + 7] = (lastcount >> 8) & 0xff;
3640 c = omin(count, ATA_DSM_RANGE_MAX);
3643 buf[off + 0] = lba & 0xff;
3644 buf[off + 1] = (lba >> 8) & 0xff;
3645 buf[off + 2] = (lba >> 16) & 0xff;
3646 buf[off + 3] = (lba >> 24) & 0xff;
3647 buf[off + 4] = (lba >> 32) & 0xff;
3648 buf[off + 5] = (lba >> 40) & 0xff;
3649 buf[off + 6] = c & 0xff;
3650 buf[off + 7] = (c >> 8) & 0xff;
3655 if (count != 0 && ranges == softc->trim_max_ranges) {
3656 xpt_print(periph->path,
3657 "%s issuing short delete %ld > %ld\n",
3658 da_delete_method_desc[softc->delete_method],
3660 (softc->trim_max_ranges - ranges) *
3666 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3669 if (bp1->bio_bcount / softc->params.secsize >
3670 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
3671 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3676 block_count = howmany(ranges, ATA_DSM_BLK_RANGES);
3677 scsi_ata_trim(&ccb->csio,
3678 /*retries*/da_retry_count,
3680 /*tag_action*/MSG_SIMPLE_Q_TAG,
3683 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
3684 /*sense_len*/SSD_FULL_SIZE,
3685 da_default_timeout * 1000);
3686 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3687 ccb->ccb_h.flags |= CAM_UNLOCKED;
3688 cam_iosched_submit_trim(softc->cam_iosched);
3692 * We calculate ws_max_blks here based off d_delmaxsize instead
3693 * of using softc->ws_max_blks as it is absolute max for the
3694 * device not the protocol max which may well be lower.
3697 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
3699 struct da_softc *softc;
3701 uint64_t ws_max_blks;
3703 uint64_t count; /* forward compat with WS32 */
3705 softc = (struct da_softc *)periph->softc;
3706 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
3707 lba = bp->bio_pblkno;
3711 if (bp1 != bp)//XXX imp XXX
3712 bioq_insert_tail(&softc->delete_run_queue, bp1);
3713 count += bp1->bio_bcount / softc->params.secsize;
3714 if (count > ws_max_blks) {
3715 xpt_print(periph->path,
3716 "%s issuing short delete %ld > %ld\n",
3717 da_delete_method_desc[softc->delete_method],
3718 count, ws_max_blks);
3719 count = omin(count, ws_max_blks);
3722 bp1 = cam_iosched_next_trim(softc->cam_iosched);
3725 if (lba + count != bp1->bio_pblkno ||
3726 count + bp1->bio_bcount /
3727 softc->params.secsize > ws_max_blks) {
3728 cam_iosched_put_back_trim(softc->cam_iosched, bp1);
3733 scsi_write_same(&ccb->csio,
3734 /*retries*/da_retry_count,
3736 /*tag_action*/MSG_SIMPLE_Q_TAG,
3737 /*byte2*/softc->delete_method ==
3738 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
3739 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
3741 /*block_count*/count,
3742 /*data_ptr*/ __DECONST(void *, zero_region),
3743 /*dxfer_len*/ softc->params.secsize,
3744 /*sense_len*/SSD_FULL_SIZE,
3745 da_default_timeout * 1000);
3746 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
3747 ccb->ccb_h.flags |= CAM_UNLOCKED;
3748 cam_iosched_submit_trim(softc->cam_iosched);
3752 cmd6workaround(union ccb *ccb)
3754 struct scsi_rw_6 cmd6;
3755 struct scsi_rw_10 *cmd10;
3756 struct da_softc *softc;
3761 cdb = ccb->csio.cdb_io.cdb_bytes;
3762 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
3764 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
3765 da_delete_methods old_method = softc->delete_method;
3768 * Typically there are two reasons for failure here
3769 * 1. Delete method was detected as supported but isn't
3770 * 2. Delete failed due to invalid params e.g. too big
3772 * While we will attempt to choose an alternative delete method
3773 * this may result in short deletes if the existing delete
3774 * requests from geom are big for the new method chosen.
3776 * This method assumes that the error which triggered this
3777 * will not retry the io otherwise a panic will occur
3779 dadeleteflag(softc, old_method, 0);
3780 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
3781 if (softc->delete_method == DA_DELETE_DISABLE)
3782 xpt_print(ccb->ccb_h.path,
3783 "%s failed, disabling BIO_DELETE\n",
3784 da_delete_method_desc[old_method]);
3786 xpt_print(ccb->ccb_h.path,
3787 "%s failed, switching to %s BIO_DELETE\n",
3788 da_delete_method_desc[old_method],
3789 da_delete_method_desc[softc->delete_method]);
3791 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
3792 cam_iosched_queue_work(softc->cam_iosched, bp);
3793 cam_iosched_queue_work(softc->cam_iosched,
3794 (struct bio *)ccb->ccb_h.ccb_bp);
3795 ccb->ccb_h.ccb_bp = NULL;
3799 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
3800 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3801 (*cdb == PREVENT_ALLOW) &&
3802 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
3804 xpt_print(ccb->ccb_h.path,
3805 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
3806 softc->quirks |= DA_Q_NO_PREVENT;
3810 /* Detect unsupported SYNCHRONIZE CACHE(10). */
3811 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
3812 (*cdb == SYNCHRONIZE_CACHE) &&
3813 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
3815 xpt_print(ccb->ccb_h.path,
3816 "SYNCHRONIZE CACHE(10) not supported.\n");
3817 softc->quirks |= DA_Q_NO_SYNC_CACHE;
3818 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
3822 /* Translation only possible if CDB is an array and cmd is R/W6 */
3823 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
3824 (*cdb != READ_6 && *cdb != WRITE_6))
3827 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
3828 "increasing minimum_cmd_size to 10.\n");
3829 softc->minimum_cmd_size = 10;
3831 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
3832 cmd10 = (struct scsi_rw_10 *)cdb;
3833 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
3835 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
3836 cmd10->reserved = 0;
3837 scsi_ulto2b(cmd6.length, cmd10->length);
3838 cmd10->control = cmd6.control;
3839 ccb->csio.cdb_len = sizeof(*cmd10);
3841 /* Requeue request, unfreezing queue if necessary */
3842 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
3843 ccb->ccb_h.status = CAM_REQUEUE_REQ;
3846 cam_release_devq(ccb->ccb_h.path,
3850 /*getcount_only*/0);
3856 dazonedone(struct cam_periph *periph, union ccb *ccb)
3858 struct da_softc *softc;
3861 softc = periph->softc;
3862 bp = (struct bio *)ccb->ccb_h.ccb_bp;
3864 switch (bp->bio_zone.zone_cmd) {
3865 case DISK_ZONE_OPEN:
3866 case DISK_ZONE_CLOSE:
3867 case DISK_ZONE_FINISH:
3870 case DISK_ZONE_REPORT_ZONES: {
3872 struct disk_zone_report *rep;
3873 struct scsi_report_zones_hdr *hdr;
3874 struct scsi_report_zones_desc *desc;
3875 struct disk_zone_rep_entry *entry;
3876 uint32_t num_alloced, hdr_len, num_avail;
3877 uint32_t num_to_fill, i;
3880 rep = &bp->bio_zone.zone_params.report;
3881 avail_len = ccb->csio.dxfer_len - ccb->csio.resid;
3883 * Note that bio_resid isn't normally used for zone
3884 * commands, but it is used by devstat_end_transaction_bio()
3885 * to determine how much data was transferred. Because
3886 * the size of the SCSI/ATA data structures is different
3887 * than the size of the BIO interface structures, the
3888 * amount of data actually transferred from the drive will
3889 * be different than the amount of data transferred to
3892 bp->bio_resid = ccb->csio.resid;
3893 num_alloced = rep->entries_allocated;
3894 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr;
3895 if (avail_len < sizeof(*hdr)) {
3897 * Is there a better error than EIO here? We asked
3898 * for at least the header, and we got less than
3901 bp->bio_error = EIO;
3902 bp->bio_flags |= BIO_ERROR;
3903 bp->bio_resid = bp->bio_bcount;
3907 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS)
3912 hdr_len = ata ? le32dec(hdr->length) :
3913 scsi_4btoul(hdr->length);
3915 rep->entries_available = hdr_len / sizeof(*desc);
3917 rep->entries_available = 0;
3919 * NOTE: using the same values for the BIO version of the
3920 * same field as the SCSI/ATA values. This means we could
3921 * get some additional values that aren't defined in bio.h
3922 * if more values of the same field are defined later.
3924 rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
3925 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) :
3926 scsi_8btou64(hdr->maximum_lba);
3928 * If the drive reports no entries that match the query,
3932 rep->entries_filled = 0;
3936 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
3937 hdr_len / sizeof(*desc));
3939 * If the drive didn't return any data, then we're done.
3941 if (num_avail == 0) {
3942 rep->entries_filled = 0;
3946 num_to_fill = min(num_avail, rep->entries_allocated);
3948 * If the user didn't allocate any entries for us to fill,
3951 if (num_to_fill == 0) {
3952 rep->entries_filled = 0;
3956 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
3957 i < num_to_fill; i++, desc++, entry++) {
3959 * NOTE: we're mapping the values here directly
3960 * from the SCSI/ATA bit definitions to the bio.h
3961 * definitons. There is also a warning in
3962 * disk_zone.h, but the impact is that if
3963 * additional values are added in the SCSI/ATA
3964 * specs these will be visible to consumers of
3967 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
3968 entry->zone_condition =
3969 (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
3970 SRZ_ZONE_COND_SHIFT;
3971 entry->zone_flags |= desc->zone_flags &
3972 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
3973 entry->zone_length =
3974 ata ? le64dec(desc->zone_length) :
3975 scsi_8btou64(desc->zone_length);
3976 entry->zone_start_lba =
3977 ata ? le64dec(desc->zone_start_lba) :
3978 scsi_8btou64(desc->zone_start_lba);
3979 entry->write_pointer_lba =
3980 ata ? le64dec(desc->write_pointer_lba) :
3981 scsi_8btou64(desc->write_pointer_lba);
3983 rep->entries_filled = num_to_fill;
3986 case DISK_ZONE_GET_PARAMS:
3989 * In theory we should not get a GET_PARAMS bio, since it
3990 * should be handled without queueing the command to the
3993 panic("%s: Invalid zone command %d", __func__,
3994 bp->bio_zone.zone_cmd);
3998 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
3999 free(ccb->csio.data_ptr, M_SCSIDA);
4003 dadone(struct cam_periph *periph, union ccb *done_ccb)
4005 struct da_softc *softc;
4006 struct ccb_scsiio *csio;
4010 softc = (struct da_softc *)periph->softc;
4011 priority = done_ccb->ccb_h.pinfo.priority;
4013 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
4015 csio = &done_ccb->csio;
4016 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
4017 if (csio->bio != NULL)
4018 biotrack(csio->bio, __func__);
4020 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
4022 case DA_CCB_BUFFER_IO:
4025 struct bio *bp, *bp1;
4027 cam_periph_lock(periph);
4028 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4029 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
4033 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
4038 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
4039 if (error == ERESTART) {
4041 * A retry was scheduled, so
4044 cam_periph_unlock(periph);
4047 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
4052 * return all queued I/O with EIO, so that
4053 * the client can retry these I/Os in the
4054 * proper order should it attempt to recover.
4059 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
4061 * Catastrophic error. Mark our pack as
4065 * XXX See if this is really a media
4068 xpt_print(periph->path,
4069 "Invalidating pack\n");
4070 softc->flags |= DA_FLAG_PACK_INVALID;
4072 softc->invalidations++;
4074 queued_error = ENXIO;
4076 cam_iosched_flush(softc->cam_iosched, NULL,
4079 bp->bio_error = error;
4080 bp->bio_resid = bp->bio_bcount;
4081 bp->bio_flags |= BIO_ERROR;
4083 } else if (bp != NULL) {
4084 if (state == DA_CCB_DELETE)
4087 bp->bio_resid = csio->resid;
4089 if (bp->bio_resid != 0)
4090 bp->bio_flags |= BIO_ERROR;
4092 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4093 cam_release_devq(done_ccb->ccb_h.path,
4097 /*getcount_only*/0);
4098 } else if (bp != NULL) {
4099 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
4100 panic("REQ_CMP with QFRZN");
4101 if (bp->bio_cmd == BIO_ZONE)
4102 dazonedone(periph, done_ccb);
4103 else if (state == DA_CCB_DELETE)
4106 bp->bio_resid = csio->resid;
4107 if ((csio->resid > 0)
4108 && (bp->bio_cmd != BIO_ZONE))
4109 bp->bio_flags |= BIO_ERROR;
4110 if (softc->error_inject != 0) {
4111 bp->bio_error = softc->error_inject;
4112 bp->bio_resid = bp->bio_bcount;
4113 bp->bio_flags |= BIO_ERROR;
4114 softc->error_inject = 0;
4118 biotrack(bp, __func__);
4119 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
4120 if (LIST_EMPTY(&softc->pending_ccbs))
4121 softc->flags |= DA_FLAG_WAS_OTAG;
4123 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
4124 xpt_release_ccb(done_ccb);
4125 if (state == DA_CCB_DELETE) {
4126 TAILQ_HEAD(, bio) queue;
4129 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
4130 softc->delete_run_queue.insert_point = NULL;
4132 * Normally, the xpt_release_ccb() above would make sure
4133 * that when we have more work to do, that work would
4134 * get kicked off. However, we specifically keep
4135 * delete_running set to 0 before the call above to
4136 * allow other I/O to progress when many BIO_DELETE
4137 * requests are pushed down. We set delete_running to 0
4138 * and call daschedule again so that we don't stall if
4139 * there are no other I/Os pending apart from BIO_DELETEs.
4141 cam_iosched_trim_done(softc->cam_iosched);
4143 cam_periph_unlock(periph);
4144 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
4145 TAILQ_REMOVE(&queue, bp1, bio_queue);
4146 bp1->bio_error = bp->bio_error;
4147 if (bp->bio_flags & BIO_ERROR) {
4148 bp1->bio_flags |= BIO_ERROR;
4149 bp1->bio_resid = bp1->bio_bcount;
4156 cam_periph_unlock(periph);
4162 case DA_CCB_PROBE_RC:
4163 case DA_CCB_PROBE_RC16:
4165 struct scsi_read_capacity_data *rdcap;
4166 struct scsi_read_capacity_data_long *rcaplong;
4167 char announce_buf[80];
4173 if (state == DA_CCB_PROBE_RC)
4174 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
4176 rcaplong = (struct scsi_read_capacity_data_long *)
4179 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4180 struct disk_params *dp;
4181 uint32_t block_size;
4183 u_int lalba; /* Lowest aligned LBA. */
4185 if (state == DA_CCB_PROBE_RC) {
4186 block_size = scsi_4btoul(rdcap->length);
4187 maxsector = scsi_4btoul(rdcap->addr);
4191 * According to SBC-2, if the standard 10
4192 * byte READ CAPACITY command returns 2^32,
4193 * we should issue the 16 byte version of
4194 * the command, since the device in question
4195 * has more sectors than can be represented
4196 * with the short version of the command.
4198 if (maxsector == 0xffffffff) {
4199 free(rdcap, M_SCSIDA);
4200 xpt_release_ccb(done_ccb);
4201 softc->state = DA_STATE_PROBE_RC16;
4202 xpt_schedule(periph, priority);
4206 block_size = scsi_4btoul(rcaplong->length);
4207 maxsector = scsi_8btou64(rcaplong->addr);
4208 lalba = scsi_2btoul(rcaplong->lalba_lbp);
4212 * Because GEOM code just will panic us if we
4213 * give them an 'illegal' value we'll avoid that
4216 if (block_size == 0) {
4221 if (block_size >= MAXPHYS) {
4222 xpt_print(periph->path,
4223 "unsupportable block size %ju\n",
4224 (uintmax_t) block_size);
4225 announce_buf[0] = '\0';
4226 cam_periph_invalidate(periph);
4229 * We pass rcaplong into dasetgeom(),
4230 * because it will only use it if it is
4233 dasetgeom(periph, block_size, maxsector,
4234 rcaplong, sizeof(*rcaplong));
4235 lbp = (lalba & SRC16_LBPME_A);
4236 dp = &softc->params;
4237 snprintf(announce_buf, sizeof(announce_buf),
4238 "%juMB (%ju %u byte sectors)",
4239 ((uintmax_t)dp->secsize * dp->sectors) /
4241 (uintmax_t)dp->sectors, dp->secsize);
4246 announce_buf[0] = '\0';
4249 * Retry any UNIT ATTENTION type errors. They
4250 * are expected at boot.
4252 error = daerror(done_ccb, CAM_RETRY_SELTO,
4253 SF_RETRY_UA|SF_NO_PRINT);
4254 if (error == ERESTART) {
4256 * A retry was scheuled, so
4260 } else if (error != 0) {
4262 int sense_key, error_code;
4265 struct ccb_getdev cgd;
4267 /* Don't wedge this device's queue */
4268 status = done_ccb->ccb_h.status;
4269 if ((status & CAM_DEV_QFRZN) != 0)
4270 cam_release_devq(done_ccb->ccb_h.path,
4274 /*getcount_only*/0);
4277 xpt_setup_ccb(&cgd.ccb_h,
4278 done_ccb->ccb_h.path,
4279 CAM_PRIORITY_NORMAL);
4280 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
4281 xpt_action((union ccb *)&cgd);
4283 if (scsi_extract_sense_ccb(done_ccb,
4284 &error_code, &sense_key, &asc, &ascq))
4290 * If we tried READ CAPACITY(16) and failed,
4291 * fallback to READ CAPACITY(10).
4293 if ((state == DA_CCB_PROBE_RC16) &&
4294 (softc->flags & DA_FLAG_CAN_RC16) &&
4295 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
4298 (error_code == SSD_CURRENT_ERROR) &&
4299 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
4300 softc->flags &= ~DA_FLAG_CAN_RC16;
4301 free(rdcap, M_SCSIDA);
4302 xpt_release_ccb(done_ccb);
4303 softc->state = DA_STATE_PROBE_RC;
4304 xpt_schedule(periph, priority);
4309 * Attach to anything that claims to be a
4310 * direct access or optical disk device,
4311 * as long as it doesn't return a "Logical
4312 * unit not supported" (0x25) error.
4313 * "Internal Target Failure" (0x44) is also
4314 * special and typically means that the
4315 * device is a SATA drive behind a SATL
4316 * translation that's fallen into a
4317 * terminally fatal state.
4320 && (asc != 0x25) && (asc != 0x44)
4321 && (error_code == SSD_CURRENT_ERROR)) {
4322 const char *sense_key_desc;
4323 const char *asc_desc;
4325 dasetgeom(periph, 512, -1, NULL, 0);
4326 scsi_sense_desc(sense_key, asc, ascq,
4330 snprintf(announce_buf,
4331 sizeof(announce_buf),
4332 "Attempt to query device "
4333 "size failed: %s, %s",
4341 xpt_print(periph->path,
4342 "got CAM status %#x\n",
4343 done_ccb->ccb_h.status);
4346 xpt_print(periph->path, "fatal error, "
4347 "failed to attach to device\n");
4350 * Free up resources.
4352 cam_periph_invalidate(periph);
4356 free(csio->data_ptr, M_SCSIDA);
4357 if (announce_buf[0] != '\0' &&
4358 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
4360 * Create our sysctl variables, now that we know
4361 * we have successfully attached.
4363 /* increase the refcount */
4364 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
4365 taskqueue_enqueue(taskqueue_thread,
4366 &softc->sysctl_task);
4367 xpt_announce_periph(periph, announce_buf);
4368 xpt_announce_quirks(periph, softc->quirks,
4371 xpt_print(periph->path, "fatal error, "
4372 "could not acquire reference count\n");
4376 /* We already probed the device. */
4377 if (softc->flags & DA_FLAG_PROBED) {
4378 daprobedone(periph, done_ccb);
4382 /* Ensure re-probe doesn't see old delete. */
4383 softc->delete_available = 0;
4384 dadeleteflag(softc, DA_DELETE_ZERO, 1);
4385 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4387 * Based on older SBC-3 spec revisions
4388 * any of the UNMAP methods "may" be
4389 * available via LBP given this flag so
4390 * we flag all of them as available and
4391 * then remove those which further
4392 * probes confirm aren't available
4395 * We could also check readcap(16) p_type
4396 * flag to exclude one or more invalid
4397 * write same (X) types here
4399 dadeleteflag(softc, DA_DELETE_WS16, 1);
4400 dadeleteflag(softc, DA_DELETE_WS10, 1);
4401 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
4403 xpt_release_ccb(done_ccb);
4404 softc->state = DA_STATE_PROBE_LBP;
4405 xpt_schedule(periph, priority);
4409 xpt_release_ccb(done_ccb);
4410 softc->state = DA_STATE_PROBE_BDC;
4411 xpt_schedule(periph, priority);
4414 case DA_CCB_PROBE_LBP:
4416 struct scsi_vpd_logical_block_prov *lbp;
4418 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
4420 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4422 * T10/1799-D Revision 31 states at least one of these
4423 * must be supported but we don't currently enforce this.
4425 dadeleteflag(softc, DA_DELETE_WS16,
4426 (lbp->flags & SVPD_LBP_WS16));
4427 dadeleteflag(softc, DA_DELETE_WS10,
4428 (lbp->flags & SVPD_LBP_WS10));
4429 dadeleteflag(softc, DA_DELETE_UNMAP,
4430 (lbp->flags & SVPD_LBP_UNMAP));
4433 error = daerror(done_ccb, CAM_RETRY_SELTO,
4434 SF_RETRY_UA|SF_NO_PRINT);
4435 if (error == ERESTART)
4437 else if (error != 0) {
4438 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4439 /* Don't wedge this device's queue */
4440 cam_release_devq(done_ccb->ccb_h.path,
4444 /*getcount_only*/0);
4448 * Failure indicates we don't support any SBC-3
4449 * delete methods with UNMAP
4454 free(lbp, M_SCSIDA);
4455 xpt_release_ccb(done_ccb);
4456 softc->state = DA_STATE_PROBE_BLK_LIMITS;
4457 xpt_schedule(periph, priority);
4460 case DA_CCB_PROBE_BLK_LIMITS:
4462 struct scsi_vpd_block_limits *block_limits;
4464 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
4466 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4467 uint32_t max_txfer_len = scsi_4btoul(
4468 block_limits->max_txfer_len);
4469 uint32_t max_unmap_lba_cnt = scsi_4btoul(
4470 block_limits->max_unmap_lba_cnt);
4471 uint32_t max_unmap_blk_cnt = scsi_4btoul(
4472 block_limits->max_unmap_blk_cnt);
4473 uint64_t ws_max_blks = scsi_8btou64(
4474 block_limits->max_write_same_length);
4476 if (max_txfer_len != 0) {
4477 softc->disk->d_maxsize = MIN(softc->maxio,
4478 (off_t)max_txfer_len * softc->params.secsize);
4482 * We should already support UNMAP but we check lba
4483 * and block count to be sure
4485 if (max_unmap_lba_cnt != 0x00L &&
4486 max_unmap_blk_cnt != 0x00L) {
4487 softc->unmap_max_lba = max_unmap_lba_cnt;
4488 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
4492 * Unexpected UNMAP limits which means the
4493 * device doesn't actually support UNMAP
4495 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
4498 if (ws_max_blks != 0x00L)
4499 softc->ws_max_blks = ws_max_blks;
4502 error = daerror(done_ccb, CAM_RETRY_SELTO,
4503 SF_RETRY_UA|SF_NO_PRINT);
4504 if (error == ERESTART)
4506 else if (error != 0) {
4507 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4508 /* Don't wedge this device's queue */
4509 cam_release_devq(done_ccb->ccb_h.path,
4513 /*getcount_only*/0);
4517 * Failure here doesn't mean UNMAP is not
4518 * supported as this is an optional page.
4520 softc->unmap_max_lba = 1;
4521 softc->unmap_max_ranges = 1;
4525 free(block_limits, M_SCSIDA);
4526 xpt_release_ccb(done_ccb);
4527 softc->state = DA_STATE_PROBE_BDC;
4528 xpt_schedule(periph, priority);
4531 case DA_CCB_PROBE_BDC:
4533 struct scsi_vpd_block_device_characteristics *bdc;
4535 bdc = (struct scsi_vpd_block_device_characteristics *)
4538 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4542 * Disable queue sorting for non-rotational media
4545 u_int16_t old_rate = softc->disk->d_rotation_rate;
4547 valid_len = csio->dxfer_len - csio->resid;
4548 if (SBDC_IS_PRESENT(bdc, valid_len,
4549 medium_rotation_rate)) {
4550 softc->disk->d_rotation_rate =
4551 scsi_2btoul(bdc->medium_rotation_rate);
4552 if (softc->disk->d_rotation_rate ==
4553 SVPD_BDC_RATE_NON_ROTATING) {
4554 cam_iosched_set_sort_queue(
4555 softc->cam_iosched, 0);
4556 softc->rotating = 0;
4558 if (softc->disk->d_rotation_rate != old_rate) {
4559 disk_attr_changed(softc->disk,
4560 "GEOM::rotation_rate", M_NOWAIT);
4563 if ((SBDC_IS_PRESENT(bdc, valid_len, flags))
4564 && (softc->zone_mode == DA_ZONE_NONE)) {
4567 if (scsi_vpd_supported_page(periph,
4568 SVPD_ATA_INFORMATION))
4574 * The Zoned field will only be set for
4575 * Drive Managed and Host Aware drives. If
4576 * they are Host Managed, the device type
4577 * in the standard INQUIRY data should be
4578 * set to T_ZBC_HM (0x14).
4580 if ((bdc->flags & SVPD_ZBC_MASK) ==
4582 softc->zone_mode = DA_ZONE_HOST_AWARE;
4583 softc->zone_interface = (ata_proto) ?
4584 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4585 } else if ((bdc->flags & SVPD_ZBC_MASK) ==
4587 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4588 softc->zone_interface = (ata_proto) ?
4589 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI;
4590 } else if ((bdc->flags & SVPD_ZBC_MASK) !=
4592 xpt_print(periph->path, "Unknown zoned "
4594 bdc->flags & SVPD_ZBC_MASK);
4599 error = daerror(done_ccb, CAM_RETRY_SELTO,
4600 SF_RETRY_UA|SF_NO_PRINT);
4601 if (error == ERESTART)
4603 else if (error != 0) {
4604 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
4605 /* Don't wedge this device's queue */
4606 cam_release_devq(done_ccb->ccb_h.path,
4610 /*getcount_only*/0);
4615 free(bdc, M_SCSIDA);
4616 xpt_release_ccb(done_ccb);
4617 softc->state = DA_STATE_PROBE_ATA;
4618 xpt_schedule(periph, priority);
4621 case DA_CCB_PROBE_ATA:
4624 struct ata_params *ata_params;
4629 ata_params = (struct ata_params *)csio->data_ptr;
4630 ptr = (uint16_t *)ata_params;
4634 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4637 for (i = 0; i < sizeof(*ata_params) / 2; i++)
4638 ptr[i] = le16toh(ptr[i]);
4639 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
4640 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
4641 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
4642 if (ata_params->max_dsm_blocks != 0)
4643 softc->trim_max_ranges = min(
4644 softc->trim_max_ranges,
4645 ata_params->max_dsm_blocks *
4646 ATA_DSM_BLK_RANGES);
4649 * Disable queue sorting for non-rotational media
4652 old_rate = softc->disk->d_rotation_rate;
4653 softc->disk->d_rotation_rate =
4654 ata_params->media_rotation_rate;
4655 if (softc->disk->d_rotation_rate ==
4656 ATA_RATE_NON_ROTATING) {
4657 cam_iosched_set_sort_queue(softc->cam_iosched, 0);
4658 softc->rotating = 0;
4660 if (softc->disk->d_rotation_rate != old_rate) {
4661 disk_attr_changed(softc->disk,
4662 "GEOM::rotation_rate", M_NOWAIT);
4665 if (ata_params->capabilities1 & ATA_SUPPORT_DMA)
4666 softc->flags |= DA_FLAG_CAN_ATA_DMA;
4668 if (ata_params->support.extension &
4670 softc->flags |= DA_FLAG_CAN_ATA_LOG;
4673 * At this point, if we have a SATA host aware drive,
4674 * we communicate via ATA passthrough unless the
4675 * SAT layer supports ZBC -> ZAC translation. In
4679 * XXX KDM figure out how to detect a host managed
4682 if (softc->zone_mode == DA_ZONE_NONE) {
4684 * Note that we don't override the zone
4685 * mode or interface if it has already been
4686 * set. This is because it has either been
4687 * set as a quirk, or when we probed the
4688 * SCSI Block Device Characteristics page,
4689 * the zoned field was set. The latter
4690 * means that the SAT layer supports ZBC to
4691 * ZAC translation, and we would prefer to
4692 * use that if it is available.
4694 if ((ata_params->support3 &
4695 ATA_SUPPORT_ZONE_MASK) ==
4696 ATA_SUPPORT_ZONE_HOST_AWARE) {
4697 softc->zone_mode = DA_ZONE_HOST_AWARE;
4698 softc->zone_interface =
4699 DA_ZONE_IF_ATA_PASS;
4700 } else if ((ata_params->support3 &
4701 ATA_SUPPORT_ZONE_MASK) ==
4702 ATA_SUPPORT_ZONE_DEV_MANAGED) {
4703 softc->zone_mode =DA_ZONE_DRIVE_MANAGED;
4704 softc->zone_interface =
4705 DA_ZONE_IF_ATA_PASS;
4710 error = daerror(done_ccb, CAM_RETRY_SELTO,
4711 SF_RETRY_UA|SF_NO_PRINT);
4712 if (error == ERESTART)
4714 else if (error != 0) {
4715 if ((done_ccb->ccb_h.status &
4716 CAM_DEV_QFRZN) != 0) {
4717 /* Don't wedge this device's queue */
4718 cam_release_devq(done_ccb->ccb_h.path,
4722 /*getcount_only*/0);
4727 free(ata_params, M_SCSIDA);
4728 if ((softc->zone_mode == DA_ZONE_HOST_AWARE)
4729 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) {
4731 * If the ATA IDENTIFY failed, we could be talking
4732 * to a SCSI drive, although that seems unlikely,
4733 * since the drive did report that it supported the
4734 * ATA Information VPD page. If the ATA IDENTIFY
4735 * succeeded, and the SAT layer doesn't support
4736 * ZBC -> ZAC translation, continue on to get the
4737 * directory of ATA logs, and complete the rest of
4738 * the ZAC probe. If the SAT layer does support
4739 * ZBC -> ZAC translation, we want to use that,
4740 * and we'll probe the SCSI Zoned Block Device
4741 * Characteristics VPD page next.
4744 && (softc->flags & DA_FLAG_CAN_ATA_LOG)
4745 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS))
4746 softc->state = DA_STATE_PROBE_ATA_LOGDIR;
4748 softc->state = DA_STATE_PROBE_ZONE;
4751 if (continue_probe != 0) {
4752 xpt_release_ccb(done_ccb);
4753 xpt_schedule(periph, priority);
4756 daprobedone(periph, done_ccb);
4759 case DA_CCB_PROBE_ATA_LOGDIR:
4763 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4765 softc->valid_logdir_len = 0;
4766 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
4767 softc->valid_logdir_len =
4768 csio->dxfer_len - csio->resid;
4769 if (softc->valid_logdir_len > 0)
4770 bcopy(csio->data_ptr, &softc->ata_logdir,
4771 min(softc->valid_logdir_len,
4772 sizeof(softc->ata_logdir)));
4774 * Figure out whether the Identify Device log is
4775 * supported. The General Purpose log directory
4776 * has a header, and lists the number of pages
4777 * available for each GP log identified by the
4778 * offset into the list.
4780 if ((softc->valid_logdir_len >=
4781 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
4782 && (le16dec(softc->ata_logdir.header) ==
4783 ATA_GP_LOG_DIR_VERSION)
4784 && (le16dec(&softc->ata_logdir.num_pages[
4785 (ATA_IDENTIFY_DATA_LOG *
4786 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
4787 softc->flags |= DA_FLAG_CAN_ATA_IDLOG;
4789 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4792 error = daerror(done_ccb, CAM_RETRY_SELTO,
4793 SF_RETRY_UA|SF_NO_PRINT);
4794 if (error == ERESTART)
4796 else if (error != 0) {
4798 * If we can't get the ATA log directory,
4799 * then ATA logs are effectively not
4800 * supported even if the bit is set in the
4803 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG |
4804 DA_FLAG_CAN_ATA_IDLOG);
4805 if ((done_ccb->ccb_h.status &
4806 CAM_DEV_QFRZN) != 0) {
4807 /* Don't wedge this device's queue */
4808 cam_release_devq(done_ccb->ccb_h.path,
4812 /*getcount_only*/0);
4817 free(csio->data_ptr, M_SCSIDA);
4820 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) {
4821 softc->state = DA_STATE_PROBE_ATA_IDDIR;
4822 xpt_release_ccb(done_ccb);
4823 xpt_schedule(periph, priority);
4826 daprobedone(periph, done_ccb);
4829 case DA_CCB_PROBE_ATA_IDDIR:
4833 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4834 off_t entries_offset, max_entries;
4837 softc->valid_iddir_len = 0;
4838 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
4839 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP |
4840 DA_FLAG_CAN_ATA_ZONE);
4841 softc->valid_iddir_len =
4842 csio->dxfer_len - csio->resid;
4843 if (softc->valid_iddir_len > 0)
4844 bcopy(csio->data_ptr, &softc->ata_iddir,
4845 min(softc->valid_iddir_len,
4846 sizeof(softc->ata_iddir)));
4849 __offsetof(struct ata_identify_log_pages,entries);
4850 max_entries = softc->valid_iddir_len - entries_offset;
4851 if ((softc->valid_iddir_len > (entries_offset + 1))
4852 && (le64dec(softc->ata_iddir.header) ==
4854 && (softc->ata_iddir.entry_count > 0)) {
4857 num_entries = softc->ata_iddir.entry_count;
4858 num_entries = min(num_entries,
4859 softc->valid_iddir_len - entries_offset);
4860 for (i = 0; i < num_entries &&
4861 i < max_entries; i++) {
4862 if (softc->ata_iddir.entries[i] ==
4865 DA_FLAG_CAN_ATA_SUPCAP;
4866 else if (softc->ata_iddir.entries[i]==
4869 DA_FLAG_CAN_ATA_ZONE;
4872 DA_FLAG_CAN_ATA_SUPCAP)
4874 DA_FLAG_CAN_ATA_ZONE))
4879 error = daerror(done_ccb, CAM_RETRY_SELTO,
4880 SF_RETRY_UA|SF_NO_PRINT);
4881 if (error == ERESTART)
4883 else if (error != 0) {
4885 * If we can't get the ATA Identify Data log
4886 * directory, then it effectively isn't
4887 * supported even if the ATA Log directory
4888 * a non-zero number of pages present for
4891 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG;
4892 if ((done_ccb->ccb_h.status &
4893 CAM_DEV_QFRZN) != 0) {
4894 /* Don't wedge this device's queue */
4895 cam_release_devq(done_ccb->ccb_h.path,
4899 /*getcount_only*/0);
4904 free(csio->data_ptr, M_SCSIDA);
4907 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) {
4908 softc->state = DA_STATE_PROBE_ATA_SUP;
4909 xpt_release_ccb(done_ccb);
4910 xpt_schedule(periph, priority);
4913 daprobedone(periph, done_ccb);
4916 case DA_CCB_PROBE_ATA_SUP:
4920 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
4923 struct ata_identify_log_sup_cap *sup_cap;
4926 sup_cap = (struct ata_identify_log_sup_cap *)
4928 valid_len = csio->dxfer_len - csio->resid;
4930 __offsetof(struct ata_identify_log_sup_cap,
4931 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
4932 if (valid_len >= needed_size) {
4933 uint64_t zoned, zac_cap;
4935 zoned = le64dec(sup_cap->zoned_cap);
4936 if (zoned & ATA_ZONED_VALID) {
4938 * This should have already been
4939 * set, because this is also in the
4940 * ATA identify data.
4942 if ((zoned & ATA_ZONED_MASK) ==
4943 ATA_SUPPORT_ZONE_HOST_AWARE)
4946 else if ((zoned & ATA_ZONED_MASK) ==
4947 ATA_SUPPORT_ZONE_DEV_MANAGED)
4949 DA_ZONE_DRIVE_MANAGED;
4952 zac_cap = le64dec(sup_cap->sup_zac_cap);
4953 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
4954 if (zac_cap & ATA_REPORT_ZONES_SUP)
4955 softc->zone_flags |=
4956 DA_ZONE_FLAG_RZ_SUP;
4957 if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
4958 softc->zone_flags |=
4959 DA_ZONE_FLAG_OPEN_SUP;
4960 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
4961 softc->zone_flags |=
4962 DA_ZONE_FLAG_CLOSE_SUP;
4963 if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
4964 softc->zone_flags |=
4965 DA_ZONE_FLAG_FINISH_SUP;
4966 if (zac_cap & ATA_ND_RWP_SUP)
4967 softc->zone_flags |=
4968 DA_ZONE_FLAG_RWP_SUP;
4971 * This field was introduced in
4972 * ACS-4, r08 on April 28th, 2015.
4973 * If the drive firmware was written
4974 * to an earlier spec, it won't have
4975 * the field. So, assume all
4976 * commands are supported.
4978 softc->zone_flags |=
4979 DA_ZONE_FLAG_SUP_MASK;
4984 error = daerror(done_ccb, CAM_RETRY_SELTO,
4985 SF_RETRY_UA|SF_NO_PRINT);
4986 if (error == ERESTART)
4988 else if (error != 0) {
4990 * If we can't get the ATA Identify Data
4991 * Supported Capabilities page, clear the
4994 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP;
4996 * And clear zone capabilities.
4998 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK;
4999 if ((done_ccb->ccb_h.status &
5000 CAM_DEV_QFRZN) != 0) {
5001 /* Don't wedge this device's queue */
5002 cam_release_devq(done_ccb->ccb_h.path,
5006 /*getcount_only*/0);
5011 free(csio->data_ptr, M_SCSIDA);
5014 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) {
5015 softc->state = DA_STATE_PROBE_ATA_ZONE;
5016 xpt_release_ccb(done_ccb);
5017 xpt_schedule(periph, priority);
5020 daprobedone(periph, done_ccb);
5023 case DA_CCB_PROBE_ATA_ZONE:
5027 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5028 struct ata_zoned_info_log *zi_log;
5032 zi_log = (struct ata_zoned_info_log *)csio->data_ptr;
5034 valid_len = csio->dxfer_len - csio->resid;
5035 needed_size = __offsetof(struct ata_zoned_info_log,
5036 version_info) + 1 + sizeof(zi_log->version_info);
5037 if (valid_len >= needed_size) {
5040 tmpvar = le64dec(zi_log->zoned_cap);
5041 if (tmpvar & ATA_ZDI_CAP_VALID) {
5042 if (tmpvar & ATA_ZDI_CAP_URSWRZ)
5043 softc->zone_flags |=
5044 DA_ZONE_FLAG_URSWRZ;
5046 softc->zone_flags &=
5047 ~DA_ZONE_FLAG_URSWRZ;
5049 tmpvar = le64dec(zi_log->optimal_seq_zones);
5050 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
5051 softc->zone_flags |=
5052 DA_ZONE_FLAG_OPT_SEQ_SET;
5053 softc->optimal_seq_zones = (tmpvar &
5054 ATA_ZDI_OPT_SEQ_MASK);
5056 softc->zone_flags &=
5057 ~DA_ZONE_FLAG_OPT_SEQ_SET;
5058 softc->optimal_seq_zones = 0;
5061 tmpvar =le64dec(zi_log->optimal_nonseq_zones);
5062 if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
5063 softc->zone_flags |=
5064 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5065 softc->optimal_nonseq_zones =
5066 (tmpvar & ATA_ZDI_OPT_NS_MASK);
5068 softc->zone_flags &=
5069 ~DA_ZONE_FLAG_OPT_NONSEQ_SET;
5070 softc->optimal_nonseq_zones = 0;
5073 tmpvar = le64dec(zi_log->max_seq_req_zones);
5074 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
5075 softc->zone_flags |=
5076 DA_ZONE_FLAG_MAX_SEQ_SET;
5077 softc->max_seq_zones =
5078 (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
5080 softc->zone_flags &=
5081 ~DA_ZONE_FLAG_MAX_SEQ_SET;
5082 softc->max_seq_zones = 0;
5086 error = daerror(done_ccb, CAM_RETRY_SELTO,
5087 SF_RETRY_UA|SF_NO_PRINT);
5088 if (error == ERESTART)
5090 else if (error != 0) {
5091 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE;
5092 softc->flags &= ~DA_ZONE_FLAG_SET_MASK;
5094 if ((done_ccb->ccb_h.status &
5095 CAM_DEV_QFRZN) != 0) {
5096 /* Don't wedge this device's queue */
5097 cam_release_devq(done_ccb->ccb_h.path,
5101 /*getcount_only*/0);
5106 free(csio->data_ptr, M_SCSIDA);
5108 daprobedone(periph, done_ccb);
5111 case DA_CCB_PROBE_ZONE:
5115 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
5118 struct scsi_vpd_zoned_bdc *zoned_bdc;
5121 zoned_bdc = (struct scsi_vpd_zoned_bdc *)
5123 valid_len = csio->dxfer_len - csio->resid;
5124 needed_len = __offsetof(struct scsi_vpd_zoned_bdc,
5125 max_seq_req_zones) + 1 +
5126 sizeof(zoned_bdc->max_seq_req_zones);
5127 if ((valid_len >= needed_len)
5128 && (scsi_2btoul(zoned_bdc->page_length) >=
5130 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ)
5131 softc->zone_flags |=
5132 DA_ZONE_FLAG_URSWRZ;
5134 softc->zone_flags &=
5135 ~DA_ZONE_FLAG_URSWRZ;
5136 softc->optimal_seq_zones =
5137 scsi_4btoul(zoned_bdc->optimal_seq_zones);
5138 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET;
5139 softc->optimal_nonseq_zones = scsi_4btoul(
5140 zoned_bdc->optimal_nonseq_zones);
5141 softc->zone_flags |=
5142 DA_ZONE_FLAG_OPT_NONSEQ_SET;
5143 softc->max_seq_zones =
5144 scsi_4btoul(zoned_bdc->max_seq_req_zones);
5145 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET;
5148 * All of the zone commands are mandatory for SCSI
5151 * XXX KDM this is valid as of September 2015.
5152 * Re-check this assumption once the SAT spec is
5153 * updated to support SCSI ZBC to ATA ZAC mapping.
5154 * Since ATA allows zone commands to be reported
5155 * as supported or not, this may not necessarily
5156 * be true for an ATA device behind a SAT (SCSI to
5157 * ATA Translation) layer.
5159 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK;
5161 error = daerror(done_ccb, CAM_RETRY_SELTO,
5162 SF_RETRY_UA|SF_NO_PRINT);
5163 if (error == ERESTART)
5165 else if (error != 0) {
5166 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
5167 /* Don't wedge this device's queue */
5168 cam_release_devq(done_ccb->ccb_h.path,
5172 /*getcount_only*/0);
5176 daprobedone(periph, done_ccb);
5180 /* No-op. We're polling */
5184 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5186 if (daerror(done_ccb, CAM_RETRY_SELTO,
5187 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
5190 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
5191 cam_release_devq(done_ccb->ccb_h.path,
5195 /*getcount_only*/0);
5197 xpt_release_ccb(done_ccb);
5198 cam_periph_release_locked(periph);
5204 xpt_release_ccb(done_ccb);
5208 dareprobe(struct cam_periph *periph)
5210 struct da_softc *softc;
5213 softc = (struct da_softc *)periph->softc;
5215 /* Probe in progress; don't interfere. */
5216 if (softc->state != DA_STATE_NORMAL)
5219 status = cam_periph_acquire(periph);
5220 KASSERT(status == CAM_REQ_CMP,
5221 ("dareprobe: cam_periph_acquire failed"));
5223 if (softc->flags & DA_FLAG_CAN_RC16)
5224 softc->state = DA_STATE_PROBE_RC16;
5226 softc->state = DA_STATE_PROBE_RC;
5228 xpt_schedule(periph, CAM_PRIORITY_DEV);
5232 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
5234 struct da_softc *softc;
5235 struct cam_periph *periph;
5236 int error, error_code, sense_key, asc, ascq;
5238 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING)
5239 if (ccb->csio.bio != NULL)
5240 biotrack(ccb->csio.bio, __func__);
5243 periph = xpt_path_periph(ccb->ccb_h.path);
5244 softc = (struct da_softc *)periph->softc;
5247 * Automatically detect devices that do not support
5248 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
5251 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
5252 error = cmd6workaround(ccb);
5253 } else if (scsi_extract_sense_ccb(ccb,
5254 &error_code, &sense_key, &asc, &ascq)) {
5255 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
5256 error = cmd6workaround(ccb);
5258 * If the target replied with CAPACITY DATA HAS CHANGED UA,
5259 * query the capacity and notify upper layers.
5261 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5262 asc == 0x2A && ascq == 0x09) {
5263 xpt_print(periph->path, "Capacity data has changed\n");
5264 softc->flags &= ~DA_FLAG_PROBED;
5266 sense_flags |= SF_NO_PRINT;
5267 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5268 asc == 0x28 && ascq == 0x00) {
5269 softc->flags &= ~DA_FLAG_PROBED;
5270 disk_media_changed(softc->disk, M_NOWAIT);
5271 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
5272 asc == 0x3F && ascq == 0x03) {
5273 xpt_print(periph->path, "INQUIRY data has changed\n");
5274 softc->flags &= ~DA_FLAG_PROBED;
5276 sense_flags |= SF_NO_PRINT;
5277 } else if (sense_key == SSD_KEY_NOT_READY &&
5278 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
5279 softc->flags |= DA_FLAG_PACK_INVALID;
5280 disk_media_gone(softc->disk, M_NOWAIT);
5283 if (error == ERESTART)
5287 switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
5288 case CAM_CMD_TIMEOUT:
5291 case CAM_REQ_ABORTED:
5292 case CAM_REQ_CMP_ERR:
5293 case CAM_REQ_TERMIO:
5294 case CAM_UNREC_HBA_ERROR:
5295 case CAM_DATA_RUN_ERR:
5305 * Until we have a better way of doing pack validation,
5306 * don't treat UAs as errors.
5308 sense_flags |= SF_RETRY_UA;
5310 if (softc->quirks & DA_Q_RETRY_BUSY)
5311 sense_flags |= SF_RETRY_BUSY;
5312 return(cam_periph_error(ccb, cam_flags, sense_flags,
5313 &softc->saved_ccb));
5317 damediapoll(void *arg)
5319 struct cam_periph *periph = arg;
5320 struct da_softc *softc = periph->softc;
5322 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) &&
5323 LIST_EMPTY(&softc->pending_ccbs)) {
5324 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
5325 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR);
5329 /* Queue us up again */
5330 if (da_poll_period != 0)
5331 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
5335 daprevent(struct cam_periph *periph, int action)
5337 struct da_softc *softc;
5341 softc = (struct da_softc *)periph->softc;
5343 if (((action == PR_ALLOW)
5344 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
5345 || ((action == PR_PREVENT)
5346 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
5350 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5352 scsi_prevent(&ccb->csio,
5360 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
5361 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
5364 if (action == PR_ALLOW)
5365 softc->flags &= ~DA_FLAG_PACK_LOCKED;
5367 softc->flags |= DA_FLAG_PACK_LOCKED;
5370 xpt_release_ccb(ccb);
5374 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
5375 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
5377 struct ccb_calc_geometry ccg;
5378 struct da_softc *softc;
5379 struct disk_params *dp;
5380 u_int lbppbe, lalba;
5383 softc = (struct da_softc *)periph->softc;
5385 dp = &softc->params;
5386 dp->secsize = block_len;
5387 dp->sectors = maxsector + 1;
5388 if (rcaplong != NULL) {
5389 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
5390 lalba = scsi_2btoul(rcaplong->lalba_lbp);
5391 lalba &= SRC16_LALBA_A;
5398 dp->stripesize = block_len << lbppbe;
5399 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
5401 } else if (softc->quirks & DA_Q_4K) {
5402 dp->stripesize = 4096;
5403 dp->stripeoffset = 0;
5406 dp->stripeoffset = 0;
5409 * Have the controller provide us with a geometry
5410 * for this disk. The only time the geometry
5411 * matters is when we boot and the controller
5412 * is the only one knowledgeable enough to come
5413 * up with something that will make this a bootable
5416 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5417 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
5418 ccg.block_size = dp->secsize;
5419 ccg.volume_size = dp->sectors;
5421 ccg.secs_per_track = 0;
5423 xpt_action((union ccb*)&ccg);
5424 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
5426 * We don't know what went wrong here- but just pick
5427 * a geometry so we don't have nasty things like divide
5431 dp->secs_per_track = 255;
5432 dp->cylinders = dp->sectors / (255 * 255);
5433 if (dp->cylinders == 0) {
5437 dp->heads = ccg.heads;
5438 dp->secs_per_track = ccg.secs_per_track;
5439 dp->cylinders = ccg.cylinders;
5443 * If the user supplied a read capacity buffer, and if it is
5444 * different than the previous buffer, update the data in the EDT.
5445 * If it's the same, we don't bother. This avoids sending an
5446 * update every time someone opens this device.
5448 if ((rcaplong != NULL)
5449 && (bcmp(rcaplong, &softc->rcaplong,
5450 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
5451 struct ccb_dev_advinfo cdai;
5453 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
5454 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
5455 cdai.buftype = CDAI_TYPE_RCAPLONG;
5456 cdai.flags = CDAI_FLAG_STORE;
5457 cdai.bufsiz = rcap_len;
5458 cdai.buf = (uint8_t *)rcaplong;
5459 xpt_action((union ccb *)&cdai);
5460 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
5461 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
5462 if (cdai.ccb_h.status != CAM_REQ_CMP) {
5463 xpt_print(periph->path, "%s: failed to set read "
5464 "capacity advinfo\n", __func__);
5465 /* Use cam_error_print() to decode the status */
5466 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
5469 bcopy(rcaplong, &softc->rcaplong,
5470 min(sizeof(softc->rcaplong), rcap_len));
5474 softc->disk->d_sectorsize = softc->params.secsize;
5475 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
5476 softc->disk->d_stripesize = softc->params.stripesize;
5477 softc->disk->d_stripeoffset = softc->params.stripeoffset;
5478 /* XXX: these are not actually "firmware" values, so they may be wrong */
5479 softc->disk->d_fwsectors = softc->params.secs_per_track;
5480 softc->disk->d_fwheads = softc->params.heads;
5481 softc->disk->d_devstat->block_size = softc->params.secsize;
5482 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
5484 error = disk_resize(softc->disk, M_NOWAIT);
5486 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
5490 dasendorderedtag(void *arg)
5492 struct da_softc *softc = arg;
5494 if (da_send_ordered) {
5495 if (!LIST_EMPTY(&softc->pending_ccbs)) {
5496 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
5497 softc->flags |= DA_FLAG_NEED_OTAG;
5498 softc->flags &= ~DA_FLAG_WAS_OTAG;
5501 /* Queue us up again */
5502 callout_reset(&softc->sendordered_c,
5503 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
5504 dasendorderedtag, softc);
5508 * Step through all DA peripheral drivers, and if the device is still open,
5509 * sync the disk cache to physical media.
5512 dashutdown(void * arg, int howto)
5514 struct cam_periph *periph;
5515 struct da_softc *softc;
5519 CAM_PERIPH_FOREACH(periph, &dadriver) {
5520 softc = (struct da_softc *)periph->softc;
5521 if (SCHEDULER_STOPPED()) {
5522 /* If we paniced with the lock held, do not recurse. */
5523 if (!cam_periph_owned(periph) &&
5524 (softc->flags & DA_FLAG_OPEN)) {
5525 dadump(softc->disk, NULL, 0, 0, 0);
5529 cam_periph_lock(periph);
5532 * We only sync the cache if the drive is still open, and
5533 * if the drive is capable of it..
5535 if (((softc->flags & DA_FLAG_OPEN) == 0)
5536 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
5537 cam_periph_unlock(periph);
5541 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
5542 scsi_synchronize_cache(&ccb->csio,
5546 /*begin_lba*/0, /* whole disk */
5551 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
5552 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
5553 softc->disk->d_devstat);
5555 xpt_print(periph->path, "Synchronize cache failed\n");
5556 xpt_release_ccb(ccb);
5557 cam_periph_unlock(periph);
5561 #else /* !_KERNEL */
5564 * XXX These are only left out of the kernel build to silence warnings. If,
5565 * for some reason these functions are used in the kernel, the ifdefs should
5566 * be moved so they are included both in the kernel and userland.
5569 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
5570 void (*cbfcnp)(struct cam_periph *, union ccb *),
5571 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
5572 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5575 struct scsi_format_unit *scsi_cmd;
5577 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
5578 scsi_cmd->opcode = FORMAT_UNIT;
5579 scsi_cmd->byte2 = byte2;
5580 scsi_ulto2b(ileave, scsi_cmd->interleave);
5585 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5595 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries,
5596 void (*cbfcnp)(struct cam_periph *, union ccb *),
5597 uint8_t tag_action, uint8_t list_format,
5598 uint32_t addr_desc_index, uint8_t *data_ptr,
5599 uint32_t dxfer_len, int minimum_cmd_size,
5600 uint8_t sense_len, uint32_t timeout)
5605 * These conditions allow using the 10 byte command. Otherwise we
5606 * need to use the 12 byte command.
5608 if ((minimum_cmd_size <= 10)
5609 && (addr_desc_index == 0)
5610 && (dxfer_len <= SRDD10_MAX_LENGTH)) {
5611 struct scsi_read_defect_data_10 *cdb10;
5613 cdb10 = (struct scsi_read_defect_data_10 *)
5614 &csio->cdb_io.cdb_bytes;
5616 cdb_len = sizeof(*cdb10);
5617 bzero(cdb10, cdb_len);
5618 cdb10->opcode = READ_DEFECT_DATA_10;
5619 cdb10->format = list_format;
5620 scsi_ulto2b(dxfer_len, cdb10->alloc_length);
5622 struct scsi_read_defect_data_12 *cdb12;
5624 cdb12 = (struct scsi_read_defect_data_12 *)
5625 &csio->cdb_io.cdb_bytes;
5627 cdb_len = sizeof(*cdb12);
5628 bzero(cdb12, cdb_len);
5629 cdb12->opcode = READ_DEFECT_DATA_12;
5630 cdb12->format = list_format;
5631 scsi_ulto4b(dxfer_len, cdb12->alloc_length);
5632 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index);
5638 /*flags*/ CAM_DIR_IN,
5648 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
5649 void (*cbfcnp)(struct cam_periph *, union ccb *),
5650 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
5651 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
5654 struct scsi_sanitize *scsi_cmd;
5656 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
5657 scsi_cmd->opcode = SANITIZE;
5658 scsi_cmd->byte2 = byte2;
5659 scsi_cmd->control = control;
5660 scsi_ulto2b(dxfer_len, scsi_cmd->length);
5665 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5674 #endif /* _KERNEL */
5677 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries,
5678 void (*cbfcnp)(struct cam_periph *, union ccb *),
5679 uint8_t tag_action, uint8_t service_action, uint64_t zone_id,
5680 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len,
5681 uint8_t sense_len, uint32_t timeout)
5683 struct scsi_zbc_out *scsi_cmd;
5685 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes;
5686 scsi_cmd->opcode = ZBC_OUT;
5687 scsi_cmd->service_action = service_action;
5688 scsi_u64to8b(zone_id, scsi_cmd->zone_id);
5689 scsi_cmd->zone_flags = zone_flags;
5694 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5704 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries,
5705 void (*cbfcnp)(struct cam_periph *, union ccb *),
5706 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba,
5707 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len,
5708 uint8_t sense_len, uint32_t timeout)
5710 struct scsi_zbc_in *scsi_cmd;
5712 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes;
5713 scsi_cmd->opcode = ZBC_IN;
5714 scsi_cmd->service_action = service_action;
5715 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba);
5716 scsi_cmd->zone_options = zone_options;
5721 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE,
5732 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries,
5733 void (*cbfcnp)(struct cam_periph *, union ccb *),
5734 uint8_t tag_action, int use_ncq,
5735 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5736 uint8_t *data_ptr, uint32_t dxfer_len,
5737 uint8_t *cdb_storage, size_t cdb_storage_len,
5738 uint8_t sense_len, uint32_t timeout)
5740 uint8_t command_out, protocol, ata_flags;
5741 uint16_t features_out;
5742 uint32_t sectors_out, auxiliary;
5748 command_out = ATA_ZAC_MANAGEMENT_OUT;
5749 features_out = (zm_action & 0xf) | (zone_flags << 8);
5750 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5751 if (dxfer_len == 0) {
5752 protocol = AP_PROTO_NON_DATA;
5753 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5756 protocol = AP_PROTO_DMA;
5757 ata_flags |= AP_FLAG_TLEN_SECT_CNT |
5758 AP_FLAG_TDIR_TO_DEV;
5759 sectors_out = ((dxfer_len >> 9) & 0xffff);
5763 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS;
5764 if (dxfer_len == 0) {
5765 command_out = ATA_NCQ_NON_DATA;
5766 features_out = ATA_NCQ_ZAC_MGMT_OUT;
5768 * We're assuming the SCSI to ATA translation layer
5769 * will set the NCQ tag number in the tag field.
5770 * That isn't clear from the SAT-4 spec (as of rev 05).
5773 ata_flags |= AP_FLAG_TLEN_NO_DATA;
5775 command_out = ATA_SEND_FPDMA_QUEUED;
5777 * Note that we're defaulting to normal priority,
5778 * and assuming that the SCSI to ATA translation
5779 * layer will insert the NCQ tag number in the tag
5780 * field. That isn't clear in the SAT-4 spec (as
5783 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8;
5785 ata_flags |= AP_FLAG_TLEN_FEAT |
5786 AP_FLAG_TDIR_TO_DEV;
5789 * For SEND FPDMA QUEUED, the transfer length is
5790 * encoded in the FEATURE register, and 0 means
5791 * that 65536 512 byte blocks are to be tranferred.
5792 * In practice, it seems unlikely that we'll see
5793 * a transfer that large, and it may confuse the
5794 * the SAT layer, because generally that means that
5795 * 0 bytes should be transferred.
5797 if (dxfer_len == (65536 * 512)) {
5799 } else if (dxfer_len <= (65535 * 512)) {
5800 features_out = ((dxfer_len >> 9) & 0xffff);
5802 /* The transfer is too big. */
5809 auxiliary = (zm_action & 0xf) | (zone_flags << 8);
5810 protocol = AP_PROTO_FPDMA;
5813 protocol |= AP_EXTEND;
5815 retval = scsi_ata_pass(csio,
5818 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
5820 /*protocol*/ protocol,
5821 /*ata_flags*/ ata_flags,
5822 /*features*/ features_out,
5823 /*sector_count*/ sectors_out,
5825 /*command*/ command_out,
5828 /*auxiliary*/ auxiliary,
5830 /*data_ptr*/ data_ptr,
5831 /*dxfer_len*/ dxfer_len,
5832 /*cdb_storage*/ cdb_storage,
5833 /*cdb_storage_len*/ cdb_storage_len,
5834 /*minimum_cmd_size*/ 0,
5835 /*sense_len*/ SSD_FULL_SIZE,
5836 /*timeout*/ timeout);
5844 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries,
5845 void (*cbfcnp)(struct cam_periph *, union ccb *),
5846 uint8_t tag_action, int use_ncq,
5847 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags,
5848 uint8_t *data_ptr, uint32_t dxfer_len,
5849 uint8_t *cdb_storage, size_t cdb_storage_len,
5850 uint8_t sense_len, uint32_t timeout)
5852 uint8_t command_out, protocol;
5853 uint16_t features_out, sectors_out;
5859 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS;
5862 command_out = ATA_ZAC_MANAGEMENT_IN;
5863 /* XXX KDM put a macro here */
5864 features_out = (zm_action & 0xf) | (zone_flags << 8);
5865 sectors_out = dxfer_len >> 9; /* XXX KDM macro */
5866 protocol = AP_PROTO_DMA;
5867 ata_flags |= AP_FLAG_TLEN_SECT_CNT;
5870 ata_flags |= AP_FLAG_TLEN_FEAT;
5872 command_out = ATA_RECV_FPDMA_QUEUED;
5873 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8;
5876 * For RECEIVE FPDMA QUEUED, the transfer length is
5877 * encoded in the FEATURE register, and 0 means
5878 * that 65536 512 byte blocks are to be tranferred.
5879 * In practice, it seems unlikely that we'll see
5880 * a transfer that large, and it may confuse the
5881 * the SAT layer, because generally that means that
5882 * 0 bytes should be transferred.
5884 if (dxfer_len == (65536 * 512)) {
5886 } else if (dxfer_len <= (65535 * 512)) {
5887 features_out = ((dxfer_len >> 9) & 0xffff);
5889 /* The transfer is too big. */
5893 auxiliary = (zm_action & 0xf) | (zone_flags << 8),
5894 protocol = AP_PROTO_FPDMA;
5897 protocol |= AP_EXTEND;
5899 retval = scsi_ata_pass(csio,
5902 /*flags*/ CAM_DIR_IN,
5904 /*protocol*/ protocol,
5905 /*ata_flags*/ ata_flags,
5906 /*features*/ features_out,
5907 /*sector_count*/ sectors_out,
5909 /*command*/ command_out,
5912 /*auxiliary*/ auxiliary,
5914 /*data_ptr*/ data_ptr,
5915 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */
5916 /*cdb_storage*/ cdb_storage,
5917 /*cdb_storage_len*/ cdb_storage_len,
5918 /*minimum_cmd_size*/ 0,
5919 /*sense_len*/ SSD_FULL_SIZE,
5920 /*timeout*/ timeout);