152c9ce25SScott Long /*-
24d846d26SWarner Losh * SPDX-License-Identifier: BSD-2-Clause
3bec9534dSPedro F. Giffuni *
452c9ce25SScott Long * Copyright (c) 2009 Alexander Motin <mav@FreeBSD.org>
552c9ce25SScott Long * All rights reserved.
652c9ce25SScott Long *
752c9ce25SScott Long * Redistribution and use in source and binary forms, with or without
852c9ce25SScott Long * modification, are permitted provided that the following conditions
952c9ce25SScott Long * are met:
1052c9ce25SScott Long * 1. Redistributions of source code must retain the above copyright
1152c9ce25SScott Long * notice, this list of conditions and the following disclaimer,
1252c9ce25SScott Long * without modification, immediately at the beginning of the file.
1352c9ce25SScott Long * 2. Redistributions in binary form must reproduce the above copyright
1452c9ce25SScott Long * notice, this list of conditions and the following disclaimer in the
1552c9ce25SScott Long * documentation and/or other materials provided with the distribution.
1652c9ce25SScott Long *
1752c9ce25SScott Long * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
1852c9ce25SScott Long * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
1952c9ce25SScott Long * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
2052c9ce25SScott Long * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
2152c9ce25SScott Long * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
2252c9ce25SScott Long * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2352c9ce25SScott Long * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2452c9ce25SScott Long * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2552c9ce25SScott Long * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
2652c9ce25SScott Long * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2752c9ce25SScott Long */
2852c9ce25SScott Long
29e3a6d3a4SAlexander Motin #include "opt_ada.h"
30e3a6d3a4SAlexander Motin
3152c9ce25SScott Long #include <sys/param.h>
3252c9ce25SScott Long
3352c9ce25SScott Long #ifdef _KERNEL
3452c9ce25SScott Long #include <sys/systm.h>
3552c9ce25SScott Long #include <sys/kernel.h>
3652c9ce25SScott Long #include <sys/bio.h>
3752c9ce25SScott Long #include <sys/sysctl.h>
3852c9ce25SScott Long #include <sys/taskqueue.h>
3952c9ce25SScott Long #include <sys/lock.h>
4052c9ce25SScott Long #include <sys/mutex.h>
4152c9ce25SScott Long #include <sys/conf.h>
4252c9ce25SScott Long #include <sys/devicestat.h>
4352c9ce25SScott Long #include <sys/eventhandler.h>
4452c9ce25SScott Long #include <sys/malloc.h>
459a6844d5SKenneth D. Merry #include <sys/endian.h>
4652c9ce25SScott Long #include <sys/cons.h>
472f87dfb0SAlexander Motin #include <sys/proc.h>
48fd104c15SRebecca Cran #include <sys/reboot.h>
499a6844d5SKenneth D. Merry #include <sys/sbuf.h>
5013532153SScott Long #include <geom/geom.h>
5152c9ce25SScott Long #include <geom/geom_disk.h>
5252c9ce25SScott Long #endif /* _KERNEL */
5352c9ce25SScott Long
5452c9ce25SScott Long #ifndef _KERNEL
5552c9ce25SScott Long #include <stdio.h>
5652c9ce25SScott Long #include <string.h>
5752c9ce25SScott Long #endif /* _KERNEL */
5852c9ce25SScott Long
5952c9ce25SScott Long #include <cam/cam.h>
6052c9ce25SScott Long #include <cam/cam_ccb.h>
6152c9ce25SScott Long #include <cam/cam_periph.h>
6252c9ce25SScott Long #include <cam/cam_xpt_periph.h>
639a6844d5SKenneth D. Merry #include <cam/scsi/scsi_all.h>
649a6844d5SKenneth D. Merry #include <cam/scsi/scsi_da.h>
6552c9ce25SScott Long #include <cam/cam_sim.h>
66a6e0c5daSWarner Losh #include <cam/cam_iosched.h>
6752c9ce25SScott Long
6852c9ce25SScott Long #include <cam/ata/ata_all.h>
6952c9ce25SScott Long
7052c9ce25SScott Long #ifdef _KERNEL
7152c9ce25SScott Long
7252c9ce25SScott Long #define ATA_MAX_28BIT_LBA 268435455UL
7352c9ce25SScott Long
74a6e0c5daSWarner Losh extern int iosched_debug;
75a6e0c5daSWarner Losh
7652c9ce25SScott Long typedef enum {
771ed6aaf9SAlexander Motin ADA_STATE_RAHEAD,
78f513d14cSAlexander Motin ADA_STATE_WCACHE,
799a6844d5SKenneth D. Merry ADA_STATE_LOGDIR,
809a6844d5SKenneth D. Merry ADA_STATE_IDDIR,
819a6844d5SKenneth D. Merry ADA_STATE_SUP_CAP,
829a6844d5SKenneth D. Merry ADA_STATE_ZONE,
831e637ba6SAlexander Motin ADA_STATE_NORMAL
8452c9ce25SScott Long } ada_state;
8552c9ce25SScott Long
8652c9ce25SScott Long typedef enum {
879a6844d5SKenneth D. Merry ADA_FLAG_CAN_48BIT = 0x00000002,
889a6844d5SKenneth D. Merry ADA_FLAG_CAN_FLUSHCACHE = 0x00000004,
899a6844d5SKenneth D. Merry ADA_FLAG_CAN_NCQ = 0x00000008,
909a6844d5SKenneth D. Merry ADA_FLAG_CAN_DMA = 0x00000010,
919a6844d5SKenneth D. Merry ADA_FLAG_NEED_OTAG = 0x00000020,
929a6844d5SKenneth D. Merry ADA_FLAG_WAS_OTAG = 0x00000040,
939a6844d5SKenneth D. Merry ADA_FLAG_CAN_TRIM = 0x00000080,
949a6844d5SKenneth D. Merry ADA_FLAG_OPEN = 0x00000100,
959a6844d5SKenneth D. Merry ADA_FLAG_SCTX_INIT = 0x00000200,
969a6844d5SKenneth D. Merry ADA_FLAG_CAN_CFA = 0x00000400,
979a6844d5SKenneth D. Merry ADA_FLAG_CAN_POWERMGT = 0x00000800,
989a6844d5SKenneth D. Merry ADA_FLAG_CAN_DMA48 = 0x00001000,
999a6844d5SKenneth D. Merry ADA_FLAG_CAN_LOG = 0x00002000,
1009a6844d5SKenneth D. Merry ADA_FLAG_CAN_IDLOG = 0x00004000,
1019a6844d5SKenneth D. Merry ADA_FLAG_CAN_SUPCAP = 0x00008000,
1029a6844d5SKenneth D. Merry ADA_FLAG_CAN_ZONE = 0x00010000,
1039a6844d5SKenneth D. Merry ADA_FLAG_CAN_WCACHE = 0x00020000,
1049a6844d5SKenneth D. Merry ADA_FLAG_CAN_RAHEAD = 0x00040000,
1059a6844d5SKenneth D. Merry ADA_FLAG_PROBED = 0x00080000,
1069a6844d5SKenneth D. Merry ADA_FLAG_ANNOUNCED = 0x00100000,
1079a6844d5SKenneth D. Merry ADA_FLAG_DIRTY = 0x00200000,
1089a6844d5SKenneth D. Merry ADA_FLAG_CAN_NCQ_TRIM = 0x00400000, /* CAN_TRIM also set */
109cf3ff63eSWarner Losh ADA_FLAG_PIM_ATA_EXT = 0x00800000,
11096eb32bfSWarner Losh ADA_FLAG_UNMAPPEDIO = 0x01000000,
11196eb32bfSWarner Losh ADA_FLAG_ROTATING = 0x02000000
11252c9ce25SScott Long } ada_flags;
113aeab0812SWarner Losh #define ADA_FLAG_STRING \
114aeab0812SWarner Losh "\020" \
115aeab0812SWarner Losh "\002CAN_48BIT" \
116aeab0812SWarner Losh "\003CAN_FLUSHCACHE" \
117aeab0812SWarner Losh "\004CAN_NCQ" \
118aeab0812SWarner Losh "\005CAN_DMA" \
119aeab0812SWarner Losh "\006NEED_OTAG" \
120aeab0812SWarner Losh "\007WAS_OTAG" \
121aeab0812SWarner Losh "\010CAN_TRIM" \
122aeab0812SWarner Losh "\011OPEN" \
123aeab0812SWarner Losh "\012SCTX_INIT" \
124aeab0812SWarner Losh "\013CAN_CFA" \
125aeab0812SWarner Losh "\014CAN_POWERMGT" \
126aeab0812SWarner Losh "\015CAN_DMA48" \
127aeab0812SWarner Losh "\016CAN_LOG" \
128aeab0812SWarner Losh "\017CAN_IDLOG" \
129aeab0812SWarner Losh "\020CAN_SUPCAP" \
130aeab0812SWarner Losh "\021CAN_ZONE" \
131aeab0812SWarner Losh "\022CAN_WCACHE" \
132aeab0812SWarner Losh "\023CAN_RAHEAD" \
133aeab0812SWarner Losh "\024PROBED" \
134aeab0812SWarner Losh "\025ANNOUNCED" \
135aeab0812SWarner Losh "\026DIRTY" \
136aeab0812SWarner Losh "\027CAN_NCQ_TRIM" \
137cf3ff63eSWarner Losh "\030PIM_ATA_EXT" \
13896eb32bfSWarner Losh "\031UNMAPPEDIO" \
13996eb32bfSWarner Losh "\032ROTATING"
14052c9ce25SScott Long
14152c9ce25SScott Long typedef enum {
142d3a460d3SAlexander Motin ADA_Q_NONE = 0x00,
143d3a460d3SAlexander Motin ADA_Q_4K = 0x01,
144a6e0c5daSWarner Losh ADA_Q_NCQ_TRIM_BROKEN = 0x02,
145600fd98fSKenneth D. Merry ADA_Q_LOG_BROKEN = 0x04,
146fb81f266SOleksandr Tymoshenko ADA_Q_SMR_DM = 0x08,
147a49077d3SWarner Losh ADA_Q_NO_TRIM = 0x10,
148a49077d3SWarner Losh ADA_Q_128KB = 0x20
14952c9ce25SScott Long } ada_quirks;
15052c9ce25SScott Long
1516fb5c84eSSteven Hartland #define ADA_Q_BIT_STRING \
1526fb5c84eSSteven Hartland "\020" \
153a6e0c5daSWarner Losh "\0014K" \
154600fd98fSKenneth D. Merry "\002NCQ_TRIM_BROKEN" \
155600fd98fSKenneth D. Merry "\003LOG_BROKEN" \
156fb81f266SOleksandr Tymoshenko "\004SMR_DM" \
157a49077d3SWarner Losh "\005NO_TRIM" \
158a49077d3SWarner Losh "\006128KB"
1596fb5c84eSSteven Hartland
16052c9ce25SScott Long typedef enum {
1611ed6aaf9SAlexander Motin ADA_CCB_RAHEAD = 0x01,
1621ed6aaf9SAlexander Motin ADA_CCB_WCACHE = 0x02,
16352c9ce25SScott Long ADA_CCB_BUFFER_IO = 0x03,
16452c9ce25SScott Long ADA_CCB_DUMP = 0x05,
1651c80ec0aSAlexander Motin ADA_CCB_TRIM = 0x06,
1669a6844d5SKenneth D. Merry ADA_CCB_LOGDIR = 0x07,
1679a6844d5SKenneth D. Merry ADA_CCB_IDDIR = 0x08,
1689a6844d5SKenneth D. Merry ADA_CCB_SUP_CAP = 0x09,
1699a6844d5SKenneth D. Merry ADA_CCB_ZONE = 0x0a,
17052c9ce25SScott Long ADA_CCB_TYPE_MASK = 0x0F,
17152c9ce25SScott Long } ada_ccb_state;
17252c9ce25SScott Long
1739a6844d5SKenneth D. Merry typedef enum {
1749a6844d5SKenneth D. Merry ADA_ZONE_NONE = 0x00,
1759a6844d5SKenneth D. Merry ADA_ZONE_DRIVE_MANAGED = 0x01,
1769a6844d5SKenneth D. Merry ADA_ZONE_HOST_AWARE = 0x02,
1779a6844d5SKenneth D. Merry ADA_ZONE_HOST_MANAGED = 0x03
1789a6844d5SKenneth D. Merry } ada_zone_mode;
1799a6844d5SKenneth D. Merry
1809a6844d5SKenneth D. Merry typedef enum {
1819a6844d5SKenneth D. Merry ADA_ZONE_FLAG_RZ_SUP = 0x0001,
1829a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPEN_SUP = 0x0002,
1839a6844d5SKenneth D. Merry ADA_ZONE_FLAG_CLOSE_SUP = 0x0004,
1849a6844d5SKenneth D. Merry ADA_ZONE_FLAG_FINISH_SUP = 0x0008,
1859a6844d5SKenneth D. Merry ADA_ZONE_FLAG_RWP_SUP = 0x0010,
1869a6844d5SKenneth D. Merry ADA_ZONE_FLAG_SUP_MASK = (ADA_ZONE_FLAG_RZ_SUP |
1879a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPEN_SUP |
1889a6844d5SKenneth D. Merry ADA_ZONE_FLAG_CLOSE_SUP |
1899a6844d5SKenneth D. Merry ADA_ZONE_FLAG_FINISH_SUP |
1909a6844d5SKenneth D. Merry ADA_ZONE_FLAG_RWP_SUP),
1919a6844d5SKenneth D. Merry ADA_ZONE_FLAG_URSWRZ = 0x0020,
1929a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPT_SEQ_SET = 0x0040,
1939a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080,
1949a6844d5SKenneth D. Merry ADA_ZONE_FLAG_MAX_SEQ_SET = 0x0100,
1959a6844d5SKenneth D. Merry ADA_ZONE_FLAG_SET_MASK = (ADA_ZONE_FLAG_OPT_SEQ_SET |
1969a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPT_NONSEQ_SET |
1979a6844d5SKenneth D. Merry ADA_ZONE_FLAG_MAX_SEQ_SET)
1989a6844d5SKenneth D. Merry } ada_zone_flags;
1999a6844d5SKenneth D. Merry
2009a6844d5SKenneth D. Merry static struct ada_zone_desc {
2019a6844d5SKenneth D. Merry ada_zone_flags value;
2029a6844d5SKenneth D. Merry const char *desc;
2039a6844d5SKenneth D. Merry } ada_zone_desc_table[] = {
2049a6844d5SKenneth D. Merry {ADA_ZONE_FLAG_RZ_SUP, "Report Zones" },
2059a6844d5SKenneth D. Merry {ADA_ZONE_FLAG_OPEN_SUP, "Open" },
2069a6844d5SKenneth D. Merry {ADA_ZONE_FLAG_CLOSE_SUP, "Close" },
2079a6844d5SKenneth D. Merry {ADA_ZONE_FLAG_FINISH_SUP, "Finish" },
2089a6844d5SKenneth D. Merry {ADA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" },
2099a6844d5SKenneth D. Merry };
2109a6844d5SKenneth D. Merry
21152c9ce25SScott Long /* Offsets into our private area for storing information */
21252c9ce25SScott Long #define ccb_state ppriv_field0
21352c9ce25SScott Long #define ccb_bp ppriv_ptr1
21452c9ce25SScott Long
215a6e0c5daSWarner Losh typedef enum {
216a6e0c5daSWarner Losh ADA_DELETE_NONE,
217a6e0c5daSWarner Losh ADA_DELETE_DISABLE,
218a6e0c5daSWarner Losh ADA_DELETE_CFA_ERASE,
219a6e0c5daSWarner Losh ADA_DELETE_DSM_TRIM,
220a6e0c5daSWarner Losh ADA_DELETE_NCQ_DSM_TRIM,
221a6e0c5daSWarner Losh ADA_DELETE_MIN = ADA_DELETE_CFA_ERASE,
222a6e0c5daSWarner Losh ADA_DELETE_MAX = ADA_DELETE_NCQ_DSM_TRIM,
223a6e0c5daSWarner Losh } ada_delete_methods;
224a6e0c5daSWarner Losh
225a6e0c5daSWarner Losh static const char *ada_delete_method_names[] =
226a6e0c5daSWarner Losh { "NONE", "DISABLE", "CFA_ERASE", "DSM_TRIM", "NCQ_DSM_TRIM" };
227a6e0c5daSWarner Losh #if 0
228a6e0c5daSWarner Losh static const char *ada_delete_method_desc[] =
229a6e0c5daSWarner Losh { "NONE", "DISABLED", "CFA Erase", "DSM Trim", "DSM Trim via NCQ" };
230a6e0c5daSWarner Losh #endif
231a6e0c5daSWarner Losh
23252c9ce25SScott Long struct disk_params {
2339db2db6bSWarner Losh uint8_t heads;
2349db2db6bSWarner Losh uint8_t secs_per_track;
2359db2db6bSWarner Losh uint32_t cylinders;
2369db2db6bSWarner Losh uint32_t secsize; /* Number of bytes/logical sector */
2379db2db6bSWarner Losh uint64_t sectors; /* Total number sectors */
23852c9ce25SScott Long };
23952c9ce25SScott Long
2401524677aSAlexander Motin #define TRIM_MAX_BLOCKS 8
241c213c551SSteven Hartland #define TRIM_MAX_RANGES (TRIM_MAX_BLOCKS * ATA_DSM_BLK_RANGES)
2421c80ec0aSAlexander Motin struct trim_request {
243c213c551SSteven Hartland uint8_t data[TRIM_MAX_RANGES * ATA_DSM_RANGE_SIZE];
2442030b294SAlexander Motin TAILQ_HEAD(, bio) bps;
2451c80ec0aSAlexander Motin };
2461c80ec0aSAlexander Motin
24752c9ce25SScott Long struct ada_softc {
248a6e0c5daSWarner Losh struct cam_iosched_softc *cam_iosched;
249030844d1SAlexander Motin int outstanding_cmds; /* Number of active commands */
250030844d1SAlexander Motin int refcount; /* Active xpt_action() calls */
25152c9ce25SScott Long ada_state state;
25252c9ce25SScott Long ada_flags flags;
2539a6844d5SKenneth D. Merry ada_zone_mode zone_mode;
2549a6844d5SKenneth D. Merry ada_zone_flags zone_flags;
2559a6844d5SKenneth D. Merry struct ata_gp_log_dir ata_logdir;
2569a6844d5SKenneth D. Merry int valid_logdir_len;
2579a6844d5SKenneth D. Merry struct ata_identify_log_pages ata_iddir;
2589a6844d5SKenneth D. Merry int valid_iddir_len;
2599a6844d5SKenneth D. Merry uint64_t optimal_seq_zones;
2609a6844d5SKenneth D. Merry uint64_t optimal_nonseq_zones;
2619a6844d5SKenneth D. Merry uint64_t max_seq_zones;
26252c9ce25SScott Long ada_quirks quirks;
263a6e0c5daSWarner Losh ada_delete_methods delete_method;
2641c80ec0aSAlexander Motin int trim_max_ranges;
2651ed6aaf9SAlexander Motin int read_ahead;
266e3a6d3a4SAlexander Motin int write_cache;
267d38677d2SWarner Losh #ifdef CAM_TEST_FAILURE
268e3a6d3a4SAlexander Motin int force_read_error;
269e3a6d3a4SAlexander Motin int force_write_error;
270e3a6d3a4SAlexander Motin int periodic_read_error;
271e3a6d3a4SAlexander Motin int periodic_read_count;
272e3a6d3a4SAlexander Motin #endif
27376d843daSAlexander Motin struct ccb_pathinq cpi;
27452c9ce25SScott Long struct disk_params params;
27552c9ce25SScott Long struct disk *disk;
27652c9ce25SScott Long struct task sysctl_task;
27752c9ce25SScott Long struct sysctl_ctx_list sysctl_ctx;
27852c9ce25SScott Long struct sysctl_oid *sysctl_tree;
27952c9ce25SScott Long struct callout sendordered_c;
2801c80ec0aSAlexander Motin struct trim_request trim_req;
281ea657f2cSWarner Losh uint64_t trim_count;
282ea657f2cSWarner Losh uint64_t trim_ranges;
283ea657f2cSWarner Losh uint64_t trim_lbas;
284a6e0c5daSWarner Losh #ifdef CAM_IO_STATS
285a6e0c5daSWarner Losh struct sysctl_ctx_list sysctl_stats_ctx;
286a6e0c5daSWarner Losh struct sysctl_oid *sysctl_stats_tree;
287a6e0c5daSWarner Losh u_int timeouts;
288a6e0c5daSWarner Losh u_int errors;
289a6e0c5daSWarner Losh u_int invalidations;
290a6e0c5daSWarner Losh #endif
2915d01277fSScott Long #define ADA_ANNOUNCETMP_SZ 80
2925d01277fSScott Long char announce_temp[ADA_ANNOUNCETMP_SZ];
2935d01277fSScott Long #define ADA_ANNOUNCE_SZ 400
2945d01277fSScott Long char announce_buffer[ADA_ANNOUNCE_SZ];
29552c9ce25SScott Long };
29652c9ce25SScott Long
2973394d423SEdward Tomasz Napierala static uma_zone_t ada_ccb_zone;
2983394d423SEdward Tomasz Napierala
29952c9ce25SScott Long struct ada_quirk_entry {
30052c9ce25SScott Long struct scsi_inquiry_pattern inq_pat;
30152c9ce25SScott Long ada_quirks quirks;
30252c9ce25SScott Long };
30352c9ce25SScott Long
30430a4094fSAlexander Motin static struct ada_quirk_entry ada_quirk_table[] =
30530a4094fSAlexander Motin {
30630a4094fSAlexander Motin {
307a49077d3SWarner Losh /* Sandisk X400 */
308a49077d3SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "SanDisk?SD8SB8U1T00*", "X4162000*" },
309a49077d3SWarner Losh /*quirks*/ADA_Q_128KB
310a49077d3SWarner Losh },
311a49077d3SWarner Losh {
312d3a460d3SAlexander Motin /* Hitachi Advanced Format (4k) drives */
313d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "Hitachi H??????????E3*", "*" },
314d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
315d3a460d3SAlexander Motin },
316d3a460d3SAlexander Motin {
317d3a460d3SAlexander Motin /* Samsung Advanced Format (4k) drives */
318643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG HD155UI*", "*" },
319643d1826SAlexander Motin /*quirks*/ADA_Q_4K
320643d1826SAlexander Motin },
321643d1826SAlexander Motin {
322643d1826SAlexander Motin /* Samsung Advanced Format (4k) drives */
323d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG HD204UI*", "*" },
324d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
325d3a460d3SAlexander Motin },
326d3a460d3SAlexander Motin {
327d3a460d3SAlexander Motin /* Seagate Barracuda Green Advanced Format (4k) drives */
328d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST????DL*", "*" },
329d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
330d3a460d3SAlexander Motin },
331d3a460d3SAlexander Motin {
332643d1826SAlexander Motin /* Seagate Barracuda Advanced Format (4k) drives */
333643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST???DM*", "*" },
334643d1826SAlexander Motin /*quirks*/ADA_Q_4K
335643d1826SAlexander Motin },
336643d1826SAlexander Motin {
337643d1826SAlexander Motin /* Seagate Barracuda Advanced Format (4k) drives */
338643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST????DM*", "*" },
339643d1826SAlexander Motin /*quirks*/ADA_Q_4K
340643d1826SAlexander Motin },
341643d1826SAlexander Motin {
342d3a460d3SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
343d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9500423AS*", "*" },
344d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
345d3a460d3SAlexander Motin },
346d3a460d3SAlexander Motin {
347d3a460d3SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
348d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9500424AS*", "*" },
349d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
350d3a460d3SAlexander Motin },
351d3a460d3SAlexander Motin {
352d3a460d3SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
353643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9640423AS*", "*" },
354643d1826SAlexander Motin /*quirks*/ADA_Q_4K
355643d1826SAlexander Motin },
356643d1826SAlexander Motin {
357643d1826SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
358643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9640424AS*", "*" },
359643d1826SAlexander Motin /*quirks*/ADA_Q_4K
360643d1826SAlexander Motin },
361643d1826SAlexander Motin {
362643d1826SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
363d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9750420AS*", "*" },
364d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
365d3a460d3SAlexander Motin },
366d3a460d3SAlexander Motin {
367d3a460d3SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
368d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9750422AS*", "*" },
369d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
370d3a460d3SAlexander Motin },
371d3a460d3SAlexander Motin {
372643d1826SAlexander Motin /* Seagate Momentus Advanced Format (4k) drives */
373643d1826SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST9750423AS*", "*" },
374643d1826SAlexander Motin /*quirks*/ADA_Q_4K
375643d1826SAlexander Motin },
376643d1826SAlexander Motin {
377d3a460d3SAlexander Motin /* Seagate Momentus Thin Advanced Format (4k) drives */
378d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST???LT*", "*" },
379d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
380d3a460d3SAlexander Motin },
381d3a460d3SAlexander Motin {
3829073a96aSEitan Adler /* WDC Caviar Red Advanced Format (4k) drives */
3839073a96aSEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD????CX*", "*" },
3849073a96aSEitan Adler /*quirks*/ADA_Q_4K
3859073a96aSEitan Adler },
3869073a96aSEitan Adler {
387d3a460d3SAlexander Motin /* WDC Caviar Green Advanced Format (4k) drives */
388d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD????RS*", "*" },
389d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
390d3a460d3SAlexander Motin },
391d3a460d3SAlexander Motin {
3929073a96aSEitan Adler /* WDC Caviar Green/Red Advanced Format (4k) drives */
393d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD????RX*", "*" },
394d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
395d3a460d3SAlexander Motin },
396d3a460d3SAlexander Motin {
3979073a96aSEitan Adler /* WDC Caviar Red Advanced Format (4k) drives */
3989073a96aSEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD??????CX*", "*" },
3999073a96aSEitan Adler /*quirks*/ADA_Q_4K
4009073a96aSEitan Adler },
4019073a96aSEitan Adler {
4029073a96aSEitan Adler /* WDC Caviar Black Advanced Format (4k) drives */
403d734a3dfSEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD????AZEX*", "*" },
404d734a3dfSEitan Adler /*quirks*/ADA_Q_4K
405d734a3dfSEitan Adler },
406d734a3dfSEitan Adler {
407d734a3dfSEitan Adler /* WDC Caviar Black Advanced Format (4k) drives */
408d734a3dfSEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD????FZEX*", "*" },
4099073a96aSEitan Adler /*quirks*/ADA_Q_4K
4109073a96aSEitan Adler },
4119073a96aSEitan Adler {
412d3a460d3SAlexander Motin /* WDC Caviar Green Advanced Format (4k) drives */
413d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD??????RS*", "*" },
414d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
415d3a460d3SAlexander Motin },
416d3a460d3SAlexander Motin {
417d3a460d3SAlexander Motin /* WDC Caviar Green Advanced Format (4k) drives */
418d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD??????RX*", "*" },
419d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
420d3a460d3SAlexander Motin },
421d3a460d3SAlexander Motin {
422d3a460d3SAlexander Motin /* WDC Scorpio Black Advanced Format (4k) drives */
423d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD???PKT*", "*" },
424d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
425d3a460d3SAlexander Motin },
426d3a460d3SAlexander Motin {
427d3a460d3SAlexander Motin /* WDC Scorpio Black Advanced Format (4k) drives */
428d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD?????PKT*", "*" },
429d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
430d3a460d3SAlexander Motin },
431d3a460d3SAlexander Motin {
432d3a460d3SAlexander Motin /* WDC Scorpio Blue Advanced Format (4k) drives */
433d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD???PVT*", "*" },
434d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
435d3a460d3SAlexander Motin },
436d3a460d3SAlexander Motin {
437d3a460d3SAlexander Motin /* WDC Scorpio Blue Advanced Format (4k) drives */
438d3a460d3SAlexander Motin { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WD?????PVT*", "*" },
439d3a460d3SAlexander Motin /*quirks*/ADA_Q_4K
440d3a460d3SAlexander Motin },
44132fe0ef7SSteven Hartland /* SSDs */
442d3a460d3SAlexander Motin {
4439d3334e1SEitan Adler /*
4449d3334e1SEitan Adler * Corsair Force 2 SSDs
4459d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
4469d3334e1SEitan Adler */
4479d3334e1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair CSSD-F*", "*" },
4489d3334e1SEitan Adler /*quirks*/ADA_Q_4K
4499d3334e1SEitan Adler },
4509d3334e1SEitan Adler {
4519d3334e1SEitan Adler /*
4529d3334e1SEitan Adler * Corsair Force 3 SSDs
4539d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
4549d3334e1SEitan Adler */
4559d3334e1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Force 3*", "*" },
4569d3334e1SEitan Adler /*quirks*/ADA_Q_4K
4579d3334e1SEitan Adler },
4589d3334e1SEitan Adler {
4599d3334e1SEitan Adler /*
460d85805b2SSteven Hartland * Corsair Neutron GTX SSDs
461d85805b2SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
462d85805b2SSteven Hartland */
463d85805b2SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
464d85805b2SSteven Hartland /*quirks*/ADA_Q_4K
465d85805b2SSteven Hartland },
466d85805b2SSteven Hartland {
467d85805b2SSteven Hartland /*
468dc98c62fSSteven Hartland * Corsair Force GT & GS SSDs
4699d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
4709d3334e1SEitan Adler */
471dc98c62fSSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Force G*", "*" },
4729d3334e1SEitan Adler /*quirks*/ADA_Q_4K
4739d3334e1SEitan Adler },
4749d3334e1SEitan Adler {
4759d3334e1SEitan Adler /*
47632fe0ef7SSteven Hartland * Crucial M4 SSDs
4779d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
4789d3334e1SEitan Adler */
47932fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "M4-CT???M4SSD2*", "*" },
4809d3334e1SEitan Adler /*quirks*/ADA_Q_4K
4819d3334e1SEitan Adler },
4829d3334e1SEitan Adler {
4839d3334e1SEitan Adler /*
484555bb680SWarner Losh * Crucial M500 SSDs MU07 firmware
485555bb680SWarner Losh * NCQ Trim works
486a6e0c5daSWarner Losh */
487555bb680SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Crucial CT*M500*", "MU07" },
488a6e0c5daSWarner Losh /*quirks*/0
489a6e0c5daSWarner Losh },
490a6e0c5daSWarner Losh {
491a6e0c5daSWarner Losh /*
492a6e0c5daSWarner Losh * Crucial M500 SSDs all other firmware
493a6e0c5daSWarner Losh * NCQ Trim doesn't work
494a6e0c5daSWarner Losh */
495a6e0c5daSWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Crucial CT*M500*", "*" },
496a6e0c5daSWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
497a6e0c5daSWarner Losh },
498a6e0c5daSWarner Losh {
499a6e0c5daSWarner Losh /*
500a6e0c5daSWarner Losh * Crucial M550 SSDs
501a6e0c5daSWarner Losh * NCQ Trim doesn't work, but only on MU01 firmware
502a6e0c5daSWarner Losh */
503a6e0c5daSWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Crucial CT*M550*", "MU01" },
504a6e0c5daSWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
505a6e0c5daSWarner Losh },
506a6e0c5daSWarner Losh {
507a6e0c5daSWarner Losh /*
508a6e0c5daSWarner Losh * Crucial MX100 SSDs
509a6e0c5daSWarner Losh * NCQ Trim doesn't work, but only on MU01 firmware
510a6e0c5daSWarner Losh */
511a6e0c5daSWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Crucial CT*MX100*", "MU01" },
512a6e0c5daSWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
513a6e0c5daSWarner Losh },
514a6e0c5daSWarner Losh {
515a6e0c5daSWarner Losh /*
5169d3334e1SEitan Adler * Crucial RealSSD C300 SSDs
5179d3334e1SEitan Adler * 4k optimised
5189d3334e1SEitan Adler */
5199d3334e1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "C300-CTFDDAC???MAG*",
5209d3334e1SEitan Adler "*" }, /*quirks*/ADA_Q_4K
5219d3334e1SEitan Adler },
5229d3334e1SEitan Adler {
5239d3334e1SEitan Adler /*
524555bb680SWarner Losh * FCCT M500 SSDs
525555bb680SWarner Losh * NCQ Trim doesn't work
526555bb680SWarner Losh */
527555bb680SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "FCCT*M500*", "*" },
528555bb680SWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
529555bb680SWarner Losh },
530555bb680SWarner Losh {
531555bb680SWarner Losh /*
532883db1c1SEitan Adler * Intel 320 Series SSDs
533883db1c1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
534883db1c1SEitan Adler */
535883db1c1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSA2CW*", "*" },
536883db1c1SEitan Adler /*quirks*/ADA_Q_4K
537883db1c1SEitan Adler },
538883db1c1SEitan Adler {
539883db1c1SEitan Adler /*
5409d3334e1SEitan Adler * Intel 330 Series SSDs
5419d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
5429d3334e1SEitan Adler */
54332fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSC2CT*", "*" },
5449d3334e1SEitan Adler /*quirks*/ADA_Q_4K
5459d3334e1SEitan Adler },
5469d3334e1SEitan Adler {
5479d3334e1SEitan Adler /*
548883db1c1SEitan Adler * Intel 510 Series SSDs
549883db1c1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
550883db1c1SEitan Adler */
551883db1c1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSC2MH*", "*" },
552883db1c1SEitan Adler /*quirks*/ADA_Q_4K
553883db1c1SEitan Adler },
554883db1c1SEitan Adler {
555883db1c1SEitan Adler /*
55632fe0ef7SSteven Hartland * Intel 520 Series SSDs
5579d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
5589d3334e1SEitan Adler */
55932fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSC2BW*", "*" },
56032fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
56132fe0ef7SSteven Hartland },
56232fe0ef7SSteven Hartland {
56332fe0ef7SSteven Hartland /*
56423030355SSean Bruno * Intel S3610 Series SSDs
56523030355SSean Bruno * 4k optimised & trim only works in 4k requests + 4k aligned
56623030355SSean Bruno */
56723030355SSean Bruno { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSC2BX*", "*" },
56823030355SSean Bruno /*quirks*/ADA_Q_4K
56923030355SSean Bruno },
57023030355SSean Bruno {
57123030355SSean Bruno /*
572dce643c8SSteven Hartland * Intel X25-M Series SSDs
573dce643c8SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
574dce643c8SSteven Hartland */
575dce643c8SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "INTEL SSDSA2M*", "*" },
576dce643c8SSteven Hartland /*quirks*/ADA_Q_4K
577dce643c8SSteven Hartland },
578dce643c8SSteven Hartland {
579dce643c8SSteven Hartland /*
580fb81f266SOleksandr Tymoshenko * KingDian S200 60GB P0921B
581fb81f266SOleksandr Tymoshenko * Trimming crash the SSD
582fb81f266SOleksandr Tymoshenko */
583fb81f266SOleksandr Tymoshenko { T_DIRECT, SIP_MEDIA_FIXED, "*", "KingDian S200 *", "*" },
584fb81f266SOleksandr Tymoshenko /*quirks*/ADA_Q_NO_TRIM
585fb81f266SOleksandr Tymoshenko },
586fb81f266SOleksandr Tymoshenko {
587fb81f266SOleksandr Tymoshenko /*
58832fe0ef7SSteven Hartland * Kingston E100 Series SSDs
58932fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
59032fe0ef7SSteven Hartland */
59132fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "KINGSTON SE100S3*", "*" },
5929d3334e1SEitan Adler /*quirks*/ADA_Q_4K
5939d3334e1SEitan Adler },
5949d3334e1SEitan Adler {
5959d3334e1SEitan Adler /*
5969d3334e1SEitan Adler * Kingston HyperX 3k SSDs
5979d3334e1SEitan Adler * 4k optimised & trim only works in 4k requests + 4k aligned
5989d3334e1SEitan Adler */
5999d3334e1SEitan Adler { T_DIRECT, SIP_MEDIA_FIXED, "*", "KINGSTON SH103S3*", "*" },
6009d3334e1SEitan Adler /*quirks*/ADA_Q_4K
6019d3334e1SEitan Adler },
6029d3334e1SEitan Adler {
60332fe0ef7SSteven Hartland /*
604dce643c8SSteven Hartland * Marvell SSDs (entry taken from OpenSolaris)
605dce643c8SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
606dce643c8SSteven Hartland */
607dce643c8SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "MARVELL SD88SA02*", "*" },
608dce643c8SSteven Hartland /*quirks*/ADA_Q_4K
609dce643c8SSteven Hartland },
610dce643c8SSteven Hartland {
611dce643c8SSteven Hartland /*
612555bb680SWarner Losh * Micron M500 SSDs firmware MU07
613a6e0c5daSWarner Losh * NCQ Trim works?
614a6e0c5daSWarner Losh */
615555bb680SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Micron M500*", "MU07" },
616a6e0c5daSWarner Losh /*quirks*/0
617a6e0c5daSWarner Losh },
618a6e0c5daSWarner Losh {
619a6e0c5daSWarner Losh /*
620a6e0c5daSWarner Losh * Micron M500 SSDs all other firmware
621a6e0c5daSWarner Losh * NCQ Trim doesn't work
622a6e0c5daSWarner Losh */
623a6e0c5daSWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Micron M500*", "*" },
624a6e0c5daSWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
625a6e0c5daSWarner Losh },
626a6e0c5daSWarner Losh {
627a6e0c5daSWarner Losh /*
628a6e0c5daSWarner Losh * Micron M5[15]0 SSDs
629a6e0c5daSWarner Losh * NCQ Trim doesn't work, but only MU01 firmware
630a6e0c5daSWarner Losh */
631a6e0c5daSWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "Micron M5[15]0*", "MU01" },
632a6e0c5daSWarner Losh /*quirks*/ADA_Q_NCQ_TRIM_BROKEN
633a6e0c5daSWarner Losh },
634a6e0c5daSWarner Losh {
635a6e0c5daSWarner Losh /*
63623030355SSean Bruno * Micron 5100 SSDs
63723030355SSean Bruno * 4k optimised & trim only works in 4k requests + 4k aligned
63823030355SSean Bruno */
63923030355SSean Bruno { T_DIRECT, SIP_MEDIA_FIXED, "*", "Micron 5100 MTFDDAK*", "*" },
64023030355SSean Bruno /*quirks*/ADA_Q_4K
64123030355SSean Bruno },
64223030355SSean Bruno {
64323030355SSean Bruno /*
644dce643c8SSteven Hartland * OCZ Agility 2 SSDs
645dce643c8SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
646dce643c8SSteven Hartland */
647dce643c8SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
648dce643c8SSteven Hartland /*quirks*/ADA_Q_4K
649dce643c8SSteven Hartland },
650dce643c8SSteven Hartland {
651dce643c8SSteven Hartland /*
65232fe0ef7SSteven Hartland * OCZ Agility 3 SSDs
65332fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
65432fe0ef7SSteven Hartland */
65532fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY3*", "*" },
65632fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
65732fe0ef7SSteven Hartland },
65832fe0ef7SSteven Hartland {
65932fe0ef7SSteven Hartland /*
66032fe0ef7SSteven Hartland * OCZ Deneva R Series SSDs
66132fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
66232fe0ef7SSteven Hartland */
66332fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "DENRSTE251M45*", "*" },
66432fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
66532fe0ef7SSteven Hartland },
66632fe0ef7SSteven Hartland {
66732fe0ef7SSteven Hartland /*
66832fe0ef7SSteven Hartland * OCZ Vertex 2 SSDs (inc pro series)
66932fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
67032fe0ef7SSteven Hartland */
67132fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ?VERTEX2*", "*" },
67232fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
67332fe0ef7SSteven Hartland },
67432fe0ef7SSteven Hartland {
67532fe0ef7SSteven Hartland /*
67632fe0ef7SSteven Hartland * OCZ Vertex 3 SSDs
67732fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
67832fe0ef7SSteven Hartland */
67932fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-VERTEX3*", "*" },
68032fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
68132fe0ef7SSteven Hartland },
68232fe0ef7SSteven Hartland {
68332fe0ef7SSteven Hartland /*
6847f1c7787SSteven Hartland * OCZ Vertex 4 SSDs
6857f1c7787SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
6867f1c7787SSteven Hartland */
6877f1c7787SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-VERTEX4*", "*" },
6887f1c7787SSteven Hartland /*quirks*/ADA_Q_4K
6897f1c7787SSteven Hartland },
6907f1c7787SSteven Hartland {
6917f1c7787SSteven Hartland /*
692989e632aSSean Bruno * Samsung 750 SSDs
693989e632aSSean Bruno * 4k optimised, NCQ TRIM seems to work
694989e632aSSean Bruno */
695989e632aSSean Bruno { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 750*", "*" },
696989e632aSSean Bruno /*quirks*/ADA_Q_4K
697989e632aSSean Bruno },
698989e632aSSean Bruno {
699989e632aSSean Bruno /*
70032fe0ef7SSteven Hartland * Samsung 830 Series SSDs
701a6e0c5daSWarner Losh * 4k optimised, NCQ TRIM Broken (normal TRIM is fine)
70232fe0ef7SSteven Hartland */
70332fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG SSD 830 Series*", "*" },
704a6e0c5daSWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
70532fe0ef7SSteven Hartland },
70632fe0ef7SSteven Hartland {
70732fe0ef7SSteven Hartland /*
708dc98c62fSSteven Hartland * Samsung 840 SSDs
709a6e0c5daSWarner Losh * 4k optimised, NCQ TRIM Broken (normal TRIM is fine)
710dc98c62fSSteven Hartland */
711dc98c62fSSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 840*", "*" },
712a6e0c5daSWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
713dc98c62fSSteven Hartland },
714dc98c62fSSteven Hartland {
715dc98c62fSSteven Hartland /*
716d03ae351SSean Bruno * Samsung 845 SSDs
717d03ae351SSean Bruno * 4k optimised, NCQ TRIM Broken (normal TRIM is fine)
718d03ae351SSean Bruno */
719d03ae351SSean Bruno { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 845*", "*" },
720d03ae351SSean Bruno /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
721d03ae351SSean Bruno },
722d03ae351SSean Bruno {
723d03ae351SSean Bruno /*
724e3a21bd1SGeorge V. Neville-Neil * Samsung 850 SSDs
725a6e0c5daSWarner Losh * 4k optimised, NCQ TRIM broken (normal TRIM fine)
726e3a21bd1SGeorge V. Neville-Neil */
727e3a21bd1SGeorge V. Neville-Neil { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 850*", "*" },
728a6e0c5daSWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
729e3a21bd1SGeorge V. Neville-Neil },
7305f91863aSSean Bruno {
7315f91863aSSean Bruno /*
732c01af41cSAndriy Gapon * Samsung 860 SSDs
733c01af41cSAndriy Gapon * 4k optimised, NCQ TRIM broken (normal TRIM fine)
734c01af41cSAndriy Gapon */
735c01af41cSAndriy Gapon { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 860*", "*" },
736c01af41cSAndriy Gapon /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
737c01af41cSAndriy Gapon },
738c01af41cSAndriy Gapon {
739c01af41cSAndriy Gapon /*
740c01af41cSAndriy Gapon * Samsung 870 SSDs
741c01af41cSAndriy Gapon * 4k optimised, NCQ TRIM broken (normal TRIM fine)
742c01af41cSAndriy Gapon */
743c01af41cSAndriy Gapon { T_DIRECT, SIP_MEDIA_FIXED, "*", "Samsung SSD 870*", "*" },
744c01af41cSAndriy Gapon /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
745c01af41cSAndriy Gapon },
746c01af41cSAndriy Gapon {
747c01af41cSAndriy Gapon /*
748b93ecd35SWarner Losh * Samsung SM863 Series SSDs (MZ7KM*)
749b93ecd35SWarner Losh * 4k optimised, NCQ believed to be working
750b93ecd35SWarner Losh */
751b93ecd35SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG MZ7KM*", "*" },
752b93ecd35SWarner Losh /*quirks*/ADA_Q_4K
753b93ecd35SWarner Losh },
754b93ecd35SWarner Losh {
755b93ecd35SWarner Losh /*
756eae90da9SJean-Sébastien Pédron * Samsung 843T Series SSDs (MZ7WD*)
757eae90da9SJean-Sébastien Pédron * Samsung PM851 Series SSDs (MZ7TE*)
758eae90da9SJean-Sébastien Pédron * Samsung PM853T Series SSDs (MZ7GE*)
759b93ecd35SWarner Losh * 4k optimised, NCQ believed to be broken since these are
760b93ecd35SWarner Losh * appear to be built with the same controllers as the 840/850.
761323e0f6dSSean Bruno */
762eae90da9SJean-Sébastien Pédron { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG MZ7*", "*" },
763b93ecd35SWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
764844b7984SSean Bruno },
765844b7984SSean Bruno {
766844b7984SSean Bruno /*
76716f92ad2SBaptiste Daroussin * Same as for SAMSUNG MZ7* but enable the quirks for SSD
76816f92ad2SBaptiste Daroussin * starting with MZ7* too
76916f92ad2SBaptiste Daroussin */
77016f92ad2SBaptiste Daroussin { T_DIRECT, SIP_MEDIA_FIXED, "*", "MZ7*", "*" },
77116f92ad2SBaptiste Daroussin /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
77216f92ad2SBaptiste Daroussin },
77316f92ad2SBaptiste Daroussin {
77416f92ad2SBaptiste Daroussin /*
775bf95d6a6SWarner Losh * Samsung PM851 Series SSDs Dell OEM
776bf95d6a6SWarner Losh * device model "SAMSUNG SSD PM851 mSATA 256GB"
777bf95d6a6SWarner Losh * 4k optimised, NCQ broken
778bf95d6a6SWarner Losh */
779bf95d6a6SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG SSD PM851*", "*" },
780bf95d6a6SWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
781bf95d6a6SWarner Losh },
782bf95d6a6SWarner Losh {
783bf95d6a6SWarner Losh /*
78432fe0ef7SSteven Hartland * SuperTalent TeraDrive CT SSDs
78532fe0ef7SSteven Hartland * 4k optimised & trim only works in 4k requests + 4k aligned
78632fe0ef7SSteven Hartland */
78732fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "FTM??CT25H*", "*" },
78832fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
78932fe0ef7SSteven Hartland },
79032fe0ef7SSteven Hartland {
79132fe0ef7SSteven Hartland /*
79232fe0ef7SSteven Hartland * XceedIOPS SATA SSDs
79332fe0ef7SSteven Hartland * 4k optimised
79432fe0ef7SSteven Hartland */
79532fe0ef7SSteven Hartland { T_DIRECT, SIP_MEDIA_FIXED, "*", "SG9XCS2D*", "*" },
79632fe0ef7SSteven Hartland /*quirks*/ADA_Q_4K
79732fe0ef7SSteven Hartland },
79832fe0ef7SSteven Hartland {
799600fd98fSKenneth D. Merry /*
800600fd98fSKenneth D. Merry * Samsung drive that doesn't support READ LOG EXT or
801600fd98fSKenneth D. Merry * READ LOG DMA EXT, despite reporting that it does in
802600fd98fSKenneth D. Merry * ATA identify data:
803600fd98fSKenneth D. Merry * SAMSUNG HD200HJ KF100-06
804600fd98fSKenneth D. Merry */
805600fd98fSKenneth D. Merry { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG HD200*", "*" },
806600fd98fSKenneth D. Merry /*quirks*/ADA_Q_LOG_BROKEN
807600fd98fSKenneth D. Merry },
808600fd98fSKenneth D. Merry {
809600fd98fSKenneth D. Merry /*
810600fd98fSKenneth D. Merry * Samsung drive that doesn't support READ LOG EXT or
811600fd98fSKenneth D. Merry * READ LOG DMA EXT, despite reporting that it does in
812600fd98fSKenneth D. Merry * ATA identify data:
813600fd98fSKenneth D. Merry * SAMSUNG HD501LJ CR100-10
814600fd98fSKenneth D. Merry */
815600fd98fSKenneth D. Merry { T_DIRECT, SIP_MEDIA_FIXED, "*", "SAMSUNG HD501*", "*" },
816600fd98fSKenneth D. Merry /*quirks*/ADA_Q_LOG_BROKEN
817600fd98fSKenneth D. Merry },
818600fd98fSKenneth D. Merry {
819600fd98fSKenneth D. Merry /*
820600fd98fSKenneth D. Merry * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR)
821600fd98fSKenneth D. Merry * Drive Managed SATA hard drive. This drive doesn't report
822600fd98fSKenneth D. Merry * in firmware that it is a drive managed SMR drive.
823600fd98fSKenneth D. Merry */
824a4557b05SAlan Somers { T_DIRECT, SIP_MEDIA_FIXED, "*", "ST8000AS000[23]*", "*" },
825600fd98fSKenneth D. Merry /*quirks*/ADA_Q_SMR_DM
826600fd98fSKenneth D. Merry },
827600fd98fSKenneth D. Merry {
828ecca2aa5SScott Long /* WD Green SSD */
829ecca2aa5SScott Long { T_DIRECT, SIP_MEDIA_FIXED, "*", "WDC WDS?????G0*", "*" },
830ecca2aa5SScott Long /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
831ecca2aa5SScott Long },
832ecca2aa5SScott Long {
833a6cef617SWarner Losh /* Seagate IronWolf 110 SATA SSD NCQ Trim is unstable */
834a6cef617SWarner Losh { T_DIRECT, SIP_MEDIA_FIXED, "*", "ZA*NM*", "*" },
835a6cef617SWarner Losh /*quirks*/ADA_Q_4K | ADA_Q_NCQ_TRIM_BROKEN
836a6cef617SWarner Losh },
837a6cef617SWarner Losh {
83830a4094fSAlexander Motin /* Default */
83930a4094fSAlexander Motin {
84030a4094fSAlexander Motin T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED,
84130a4094fSAlexander Motin /*vendor*/"*", /*product*/"*", /*revision*/"*"
84230a4094fSAlexander Motin },
84330a4094fSAlexander Motin /*quirks*/0
84430a4094fSAlexander Motin },
84530a4094fSAlexander Motin };
84652c9ce25SScott Long
84752c9ce25SScott Long static disk_strategy_t adastrategy;
84852c9ce25SScott Long static dumper_t adadump;
84952c9ce25SScott Long static periph_init_t adainit;
8509a6844d5SKenneth D. Merry static void adadiskgonecb(struct disk *dp);
8519a6844d5SKenneth D. Merry static periph_oninv_t adaoninvalidate;
8529a6844d5SKenneth D. Merry static periph_dtor_t adacleanup;
8539db2db6bSWarner Losh static void adaasync(void *callback_arg, uint32_t code,
85452c9ce25SScott Long struct cam_path *path, void *arg);
855cf3ff63eSWarner Losh static int adabitsysctl(SYSCTL_HANDLER_ARGS);
856aeab0812SWarner Losh static int adaflagssysctl(SYSCTL_HANDLER_ARGS);
857aeab0812SWarner Losh static int adazonesupsysctl(SYSCTL_HANDLER_ARGS);
85852c9ce25SScott Long static void adasysctlinit(void *context, int pending);
8599a6844d5SKenneth D. Merry static int adagetattr(struct bio *bp);
8609a6844d5SKenneth D. Merry static void adasetflags(struct ada_softc *softc,
8619a6844d5SKenneth D. Merry struct ccb_getdev *cgd);
86276d843daSAlexander Motin static void adasetgeom(struct ada_softc *softc,
86376d843daSAlexander Motin struct ccb_getdev *cgd);
86452c9ce25SScott Long static periph_ctor_t adaregister;
8659a6844d5SKenneth D. Merry static void ada_dsmtrim(struct ada_softc *softc, struct bio *bp,
8669a6844d5SKenneth D. Merry struct ccb_ataio *ataio);
8679a6844d5SKenneth D. Merry static void ada_cfaerase(struct ada_softc *softc, struct bio *bp,
8689a6844d5SKenneth D. Merry struct ccb_ataio *ataio);
8699a6844d5SKenneth D. Merry static int ada_zone_bio_to_ata(int disk_zone_cmd);
8709a6844d5SKenneth D. Merry static int ada_zone_cmd(struct cam_periph *periph, union ccb *ccb,
8719a6844d5SKenneth D. Merry struct bio *bp, int *queue_ccb);
87252c9ce25SScott Long static periph_start_t adastart;
8739a6844d5SKenneth D. Merry static void adaprobedone(struct cam_periph *periph, union ccb *ccb);
8749a6844d5SKenneth D. Merry static void adazonedone(struct cam_periph *periph, union ccb *ccb);
87552c9ce25SScott Long static void adadone(struct cam_periph *periph,
87652c9ce25SScott Long union ccb *done_ccb);
8779db2db6bSWarner Losh static int adaerror(union ccb *ccb, uint32_t cam_flags,
8789db2db6bSWarner Losh uint32_t sense_flags);
8795773ac11SJohn Baldwin static callout_func_t adasendorderedtag;
88052c9ce25SScott Long static void adashutdown(void *arg, int howto);
881c3d0d168SAlexander Motin static void adasuspend(void *arg);
882c3d0d168SAlexander Motin static void adaresume(void *arg);
88352c9ce25SScott Long
88452c9ce25SScott Long #ifndef ADA_DEFAULT_TIMEOUT
88552c9ce25SScott Long #define ADA_DEFAULT_TIMEOUT 30 /* Timeout in seconds */
88652c9ce25SScott Long #endif
88752c9ce25SScott Long
88852c9ce25SScott Long #ifndef ADA_DEFAULT_RETRY
88952c9ce25SScott Long #define ADA_DEFAULT_RETRY 4
89052c9ce25SScott Long #endif
89152c9ce25SScott Long
89252c9ce25SScott Long #ifndef ADA_DEFAULT_SEND_ORDERED
89352c9ce25SScott Long #define ADA_DEFAULT_SEND_ORDERED 1
89452c9ce25SScott Long #endif
89552c9ce25SScott Long
896fd104c15SRebecca Cran #ifndef ADA_DEFAULT_SPINDOWN_SHUTDOWN
897fd104c15SRebecca Cran #define ADA_DEFAULT_SPINDOWN_SHUTDOWN 1
898fd104c15SRebecca Cran #endif
899fd104c15SRebecca Cran
900c3d0d168SAlexander Motin #ifndef ADA_DEFAULT_SPINDOWN_SUSPEND
901c3d0d168SAlexander Motin #define ADA_DEFAULT_SPINDOWN_SUSPEND 1
902c3d0d168SAlexander Motin #endif
903c3d0d168SAlexander Motin
9041ed6aaf9SAlexander Motin #ifndef ADA_DEFAULT_READ_AHEAD
9051ed6aaf9SAlexander Motin #define ADA_DEFAULT_READ_AHEAD 1
9061ed6aaf9SAlexander Motin #endif
9071ed6aaf9SAlexander Motin
908f513d14cSAlexander Motin #ifndef ADA_DEFAULT_WRITE_CACHE
909f513d14cSAlexander Motin #define ADA_DEFAULT_WRITE_CACHE 1
910f513d14cSAlexander Motin #endif
911f513d14cSAlexander Motin
9121ed6aaf9SAlexander Motin #define ADA_RA (softc->read_ahead >= 0 ? \
9131ed6aaf9SAlexander Motin softc->read_ahead : ada_read_ahead)
9141ed6aaf9SAlexander Motin #define ADA_WC (softc->write_cache >= 0 ? \
9151ed6aaf9SAlexander Motin softc->write_cache : ada_write_cache)
9161ed6aaf9SAlexander Motin
91752c9ce25SScott Long static int ada_retry_count = ADA_DEFAULT_RETRY;
91852c9ce25SScott Long static int ada_default_timeout = ADA_DEFAULT_TIMEOUT;
91952c9ce25SScott Long static int ada_send_ordered = ADA_DEFAULT_SEND_ORDERED;
920fd104c15SRebecca Cran static int ada_spindown_shutdown = ADA_DEFAULT_SPINDOWN_SHUTDOWN;
921c3d0d168SAlexander Motin static int ada_spindown_suspend = ADA_DEFAULT_SPINDOWN_SUSPEND;
9221ed6aaf9SAlexander Motin static int ada_read_ahead = ADA_DEFAULT_READ_AHEAD;
923f513d14cSAlexander Motin static int ada_write_cache = ADA_DEFAULT_WRITE_CACHE;
92413532153SScott Long static int ada_enable_biospeedup = 1;
9256f147a07SEdward Tomasz Napierala static int ada_enable_uma_ccbs = 1;
92652c9ce25SScott Long
9277029da5cSPawel Biernacki static SYSCTL_NODE(_kern_cam, OID_AUTO, ada, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
92852c9ce25SScott Long "CAM Direct Access Disk driver");
929af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, retry_count, CTLFLAG_RWTUN,
93052c9ce25SScott Long &ada_retry_count, 0, "Normal I/O retry count");
931af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
93252c9ce25SScott Long &ada_default_timeout, 0, "Normal I/O timeout (in seconds)");
933af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
93452c9ce25SScott Long &ada_send_ordered, 0, "Send Ordered Tags");
935af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, spindown_shutdown, CTLFLAG_RWTUN,
936fd104c15SRebecca Cran &ada_spindown_shutdown, 0, "Spin down upon shutdown");
937af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, spindown_suspend, CTLFLAG_RWTUN,
938c3d0d168SAlexander Motin &ada_spindown_suspend, 0, "Spin down upon suspend");
939af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, read_ahead, CTLFLAG_RWTUN,
9401ed6aaf9SAlexander Motin &ada_read_ahead, 0, "Enable disk read-ahead");
941af3b2549SHans Petter Selasky SYSCTL_INT(_kern_cam_ada, OID_AUTO, write_cache, CTLFLAG_RWTUN,
942f513d14cSAlexander Motin &ada_write_cache, 0, "Enable disk write cache");
94313532153SScott Long SYSCTL_INT(_kern_cam_ada, OID_AUTO, enable_biospeedup, CTLFLAG_RDTUN,
94413532153SScott Long &ada_enable_biospeedup, 0, "Enable BIO_SPEEDUP processing");
9453394d423SEdward Tomasz Napierala SYSCTL_INT(_kern_cam_ada, OID_AUTO, enable_uma_ccbs, CTLFLAG_RWTUN,
9463394d423SEdward Tomasz Napierala &ada_enable_uma_ccbs, 0, "Use UMA for CCBs");
94752c9ce25SScott Long
94852c9ce25SScott Long /*
94952c9ce25SScott Long * ADA_ORDEREDTAG_INTERVAL determines how often, relative
95052c9ce25SScott Long * to the default timeout, we check to see whether an ordered
95152c9ce25SScott Long * tagged transaction is appropriate to prevent simple tag
95252c9ce25SScott Long * starvation. Since we'd like to ensure that there is at least
95352c9ce25SScott Long * 1/2 of the timeout length left for a starved transaction to
95452c9ce25SScott Long * complete after we've sent an ordered tag, we must poll at least
95552c9ce25SScott Long * four times in every timeout period. This takes care of the worst
95652c9ce25SScott Long * case where a starved transaction starts during an interval that
95752c9ce25SScott Long * meets the requirement "don't send an ordered tag" test so it takes
95852c9ce25SScott Long * us two intervals to determine that a tag must be sent.
95952c9ce25SScott Long */
96052c9ce25SScott Long #ifndef ADA_ORDEREDTAG_INTERVAL
96152c9ce25SScott Long #define ADA_ORDEREDTAG_INTERVAL 4
96252c9ce25SScott Long #endif
96352c9ce25SScott Long
96452c9ce25SScott Long static struct periph_driver adadriver =
96552c9ce25SScott Long {
96652c9ce25SScott Long adainit, "ada",
96752c9ce25SScott Long TAILQ_HEAD_INITIALIZER(adadriver.units), /* generation */ 0
96852c9ce25SScott Long };
96952c9ce25SScott Long
970a6e0c5daSWarner Losh static int adadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
971a6e0c5daSWarner Losh
97252c9ce25SScott Long PERIPHDRIVER_DECLARE(ada, adadriver);
97352c9ce25SScott Long
9749a6844d5SKenneth D. Merry static MALLOC_DEFINE(M_ATADA, "ata_da", "ata_da buffers");
9759a6844d5SKenneth D. Merry
97652c9ce25SScott Long static int
adaopen(struct disk * dp)97752c9ce25SScott Long adaopen(struct disk *dp)
97852c9ce25SScott Long {
97952c9ce25SScott Long struct cam_periph *periph;
98052c9ce25SScott Long struct ada_softc *softc;
98152c9ce25SScott Long int error;
98252c9ce25SScott Long
98352c9ce25SScott Long periph = (struct cam_periph *)dp->d_drv1;
98499e7a4adSScott Long if (cam_periph_acquire(periph) != 0) {
98552c9ce25SScott Long return(ENXIO);
98652c9ce25SScott Long }
98752c9ce25SScott Long
98852c9ce25SScott Long cam_periph_lock(periph);
98952c9ce25SScott Long if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
99052c9ce25SScott Long cam_periph_unlock(periph);
99152c9ce25SScott Long cam_periph_release(periph);
99252c9ce25SScott Long return (error);
99352c9ce25SScott Long }
99452c9ce25SScott Long
995fddde2b8SAlexander Motin CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
996fddde2b8SAlexander Motin ("adaopen\n"));
99752c9ce25SScott Long
9987338ef1aSAlexander Motin softc = (struct ada_softc *)periph->softc;
9997338ef1aSAlexander Motin softc->flags |= ADA_FLAG_OPEN;
100052c9ce25SScott Long
100152c9ce25SScott Long cam_periph_unhold(periph);
100252c9ce25SScott Long cam_periph_unlock(periph);
100352c9ce25SScott Long return (0);
100452c9ce25SScott Long }
100552c9ce25SScott Long
100652c9ce25SScott Long static int
adaclose(struct disk * dp)100752c9ce25SScott Long adaclose(struct disk *dp)
100852c9ce25SScott Long {
100952c9ce25SScott Long struct cam_periph *periph;
101052c9ce25SScott Long struct ada_softc *softc;
101152c9ce25SScott Long union ccb *ccb;
101269114bc0SAlexander Motin int error;
101352c9ce25SScott Long
101452c9ce25SScott Long periph = (struct cam_periph *)dp->d_drv1;
101552c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
1016227d67aaSAlexander Motin cam_periph_lock(periph);
1017fddde2b8SAlexander Motin
1018fddde2b8SAlexander Motin CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1019fddde2b8SAlexander Motin ("adaclose\n"));
1020fddde2b8SAlexander Motin
102152c9ce25SScott Long /* We only sync the cache if the drive is capable of it. */
102269114bc0SAlexander Motin if ((softc->flags & ADA_FLAG_DIRTY) != 0 &&
102369114bc0SAlexander Motin (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) != 0 &&
1024227d67aaSAlexander Motin (periph->flags & CAM_PERIPH_INVALID) == 0 &&
1025227d67aaSAlexander Motin cam_periph_hold(periph, PRIBIO) == 0) {
1026bbfa4aa1SAlexander Motin ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
102752c9ce25SScott Long cam_fill_ataio(&ccb->ataio,
102852c9ce25SScott Long 1,
1029eed99e75SScott Long NULL,
103052c9ce25SScott Long CAM_DIR_NONE,
103152c9ce25SScott Long 0,
103252c9ce25SScott Long NULL,
103352c9ce25SScott Long 0,
103452c9ce25SScott Long ada_default_timeout*1000);
103552c9ce25SScott Long
103652c9ce25SScott Long if (softc->flags & ADA_FLAG_CAN_48BIT)
103752c9ce25SScott Long ata_48bit_cmd(&ccb->ataio, ATA_FLUSHCACHE48, 0, 0, 0);
103852c9ce25SScott Long else
10397606b445SAlexander Motin ata_28bit_cmd(&ccb->ataio, ATA_FLUSHCACHE, 0, 0, 0);
104069114bc0SAlexander Motin error = cam_periph_runccb(ccb, adaerror, /*cam_flags*/0,
104146f118feSAlexander Motin /*sense_flags*/0, softc->disk->d_devstat);
104252c9ce25SScott Long
104369114bc0SAlexander Motin if (error != 0)
104452c9ce25SScott Long xpt_print(periph->path, "Synchronize cache failed\n");
104569114bc0SAlexander Motin softc->flags &= ~ADA_FLAG_DIRTY;
104652c9ce25SScott Long xpt_release_ccb(ccb);
1047227d67aaSAlexander Motin cam_periph_unhold(periph);
104852c9ce25SScott Long }
104952c9ce25SScott Long
105052c9ce25SScott Long softc->flags &= ~ADA_FLAG_OPEN;
1051227d67aaSAlexander Motin
1052227d67aaSAlexander Motin while (softc->refcount != 0)
1053227d67aaSAlexander Motin cam_periph_sleep(periph, &softc->refcount, PRIBIO, "adaclose", 1);
105452c9ce25SScott Long cam_periph_unlock(periph);
105552c9ce25SScott Long cam_periph_release(periph);
105652c9ce25SScott Long return (0);
105752c9ce25SScott Long }
105852c9ce25SScott Long
10591c80ec0aSAlexander Motin static void
adaschedule(struct cam_periph * periph)10601c80ec0aSAlexander Motin adaschedule(struct cam_periph *periph)
10611c80ec0aSAlexander Motin {
10621c80ec0aSAlexander Motin struct ada_softc *softc = (struct ada_softc *)periph->softc;
10631c80ec0aSAlexander Motin
10646bf435dcSAlexander Motin if (softc->state != ADA_STATE_NORMAL)
10656bf435dcSAlexander Motin return;
10666bf435dcSAlexander Motin
1067a6e0c5daSWarner Losh cam_iosched_schedule(softc->cam_iosched, periph);
10681c80ec0aSAlexander Motin }
10691c80ec0aSAlexander Motin
107052c9ce25SScott Long /*
107152c9ce25SScott Long * Actually translate the requested transfer into one the physical driver
107252c9ce25SScott Long * can understand. The transfer is described by a buf and will include
107352c9ce25SScott Long * only one physical transfer.
107452c9ce25SScott Long */
107552c9ce25SScott Long static void
adastrategy(struct bio * bp)107652c9ce25SScott Long adastrategy(struct bio *bp)
107752c9ce25SScott Long {
107852c9ce25SScott Long struct cam_periph *periph;
107952c9ce25SScott Long struct ada_softc *softc;
108052c9ce25SScott Long
108152c9ce25SScott Long periph = (struct cam_periph *)bp->bio_disk->d_drv1;
108252c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
108352c9ce25SScott Long
108452c9ce25SScott Long cam_periph_lock(periph);
108552c9ce25SScott Long
1086fddde2b8SAlexander Motin CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("adastrategy(%p)\n", bp));
1087fddde2b8SAlexander Motin
108852c9ce25SScott Long /*
108952c9ce25SScott Long * If the device has been made invalid, error out
109052c9ce25SScott Long */
10917338ef1aSAlexander Motin if ((periph->flags & CAM_PERIPH_INVALID) != 0) {
109252c9ce25SScott Long cam_periph_unlock(periph);
109352c9ce25SScott Long biofinish(bp, NULL, ENXIO);
109452c9ce25SScott Long return;
109552c9ce25SScott Long }
109652c9ce25SScott Long
109752c9ce25SScott Long /*
10989a6844d5SKenneth D. Merry * Zone commands must be ordered, because they can depend on the
10999a6844d5SKenneth D. Merry * effects of previously issued commands, and they may affect
11009a6844d5SKenneth D. Merry * commands after them.
11019a6844d5SKenneth D. Merry */
11029a6844d5SKenneth D. Merry if (bp->bio_cmd == BIO_ZONE)
11039a6844d5SKenneth D. Merry bp->bio_flags |= BIO_ORDERED;
11049a6844d5SKenneth D. Merry
11059a6844d5SKenneth D. Merry /*
110652c9ce25SScott Long * Place it in the queue of disk activities for this disk
110752c9ce25SScott Long */
1108a6e0c5daSWarner Losh cam_iosched_queue_work(softc->cam_iosched, bp);
110952c9ce25SScott Long
111052c9ce25SScott Long /*
111152c9ce25SScott Long * Schedule ourselves for performing the work.
111252c9ce25SScott Long */
11131c80ec0aSAlexander Motin adaschedule(periph);
111452c9ce25SScott Long cam_periph_unlock(periph);
111552c9ce25SScott Long
111652c9ce25SScott Long return;
111752c9ce25SScott Long }
111852c9ce25SScott Long
111952c9ce25SScott Long static int
adadump(void * arg,void * virtual,off_t offset,size_t length)1120489ba222SMitchell Horne adadump(void *arg, void *virtual, off_t offset, size_t length)
112152c9ce25SScott Long {
112252c9ce25SScott Long struct cam_periph *periph;
112352c9ce25SScott Long struct ada_softc *softc;
112452c9ce25SScott Long u_int secsize;
112505972bafSWarner Losh struct ccb_ataio ataio;
112652c9ce25SScott Long struct disk *dp;
112752c9ce25SScott Long uint64_t lba;
112852c9ce25SScott Long uint16_t count;
11290191d9b3SAlexander Motin int error = 0;
113052c9ce25SScott Long
113152c9ce25SScott Long dp = arg;
113252c9ce25SScott Long periph = dp->d_drv1;
113352c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
113452c9ce25SScott Long secsize = softc->params.secsize;
113552c9ce25SScott Long lba = offset / secsize;
113652c9ce25SScott Long count = length / secsize;
113704e814aeSScott Long if ((periph->flags & CAM_PERIPH_INVALID) != 0)
113852c9ce25SScott Long return (ENXIO);
113952c9ce25SScott Long
114005972bafSWarner Losh memset(&ataio, 0, sizeof(ataio));
114152c9ce25SScott Long if (length > 0) {
114205972bafSWarner Losh xpt_setup_ccb(&ataio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
114305972bafSWarner Losh ataio.ccb_h.ccb_state = ADA_CCB_DUMP;
114405972bafSWarner Losh cam_fill_ataio(&ataio,
114552c9ce25SScott Long 0,
1146eed99e75SScott Long NULL,
114752c9ce25SScott Long CAM_DIR_OUT,
114852c9ce25SScott Long 0,
11499db2db6bSWarner Losh (uint8_t *) virtual,
115052c9ce25SScott Long length,
115152c9ce25SScott Long ada_default_timeout*1000);
115252c9ce25SScott Long if ((softc->flags & ADA_FLAG_CAN_48BIT) &&
115352c9ce25SScott Long (lba + count >= ATA_MAX_28BIT_LBA ||
115452c9ce25SScott Long count >= 256)) {
115505972bafSWarner Losh ata_48bit_cmd(&ataio, ATA_WRITE_DMA48,
115652c9ce25SScott Long 0, lba, count);
115752c9ce25SScott Long } else {
115805972bafSWarner Losh ata_28bit_cmd(&ataio, ATA_WRITE_DMA,
115952c9ce25SScott Long 0, lba, count);
116052c9ce25SScott Long }
116105972bafSWarner Losh error = cam_periph_runccb((union ccb *)&ataio, adaerror,
11622b31251aSWarner Losh 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
11630191d9b3SAlexander Motin if (error != 0)
116452c9ce25SScott Long printf("Aborting dump due to I/O error.\n");
11650191d9b3SAlexander Motin
11660191d9b3SAlexander Motin return (error);
116752c9ce25SScott Long }
116852c9ce25SScott Long
116952c9ce25SScott Long if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) {
117005972bafSWarner Losh xpt_setup_ccb(&ataio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
117152c9ce25SScott Long
117286ddf15eSWarner Losh /*
1173da908789SEnji Cooper * Tell the drive to flush its internal cache. if we
117486ddf15eSWarner Losh * can't flush in 5s we have big problems. No need to
117586ddf15eSWarner Losh * wait the default 60s to detect problems.
117686ddf15eSWarner Losh */
117705972bafSWarner Losh ataio.ccb_h.ccb_state = ADA_CCB_DUMP;
117805972bafSWarner Losh cam_fill_ataio(&ataio,
11790191d9b3SAlexander Motin 0,
1180eed99e75SScott Long NULL,
118152c9ce25SScott Long CAM_DIR_NONE,
118252c9ce25SScott Long 0,
118352c9ce25SScott Long NULL,
118452c9ce25SScott Long 0,
1185a6e0c5daSWarner Losh 5*1000);
118652c9ce25SScott Long
118752c9ce25SScott Long if (softc->flags & ADA_FLAG_CAN_48BIT)
118805972bafSWarner Losh ata_48bit_cmd(&ataio, ATA_FLUSHCACHE48, 0, 0, 0);
118952c9ce25SScott Long else
119005972bafSWarner Losh ata_28bit_cmd(&ataio, ATA_FLUSHCACHE, 0, 0, 0);
119105972bafSWarner Losh error = cam_periph_runccb((union ccb *)&ataio, adaerror,
11922b31251aSWarner Losh 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
11930191d9b3SAlexander Motin if (error != 0)
11940191d9b3SAlexander Motin xpt_print(periph->path, "Synchronize cache failed\n");
119552c9ce25SScott Long }
11960191d9b3SAlexander Motin return (error);
119752c9ce25SScott Long }
119852c9ce25SScott Long
119952c9ce25SScott Long static void
adainit(void)120052c9ce25SScott Long adainit(void)
120152c9ce25SScott Long {
120252c9ce25SScott Long cam_status status;
120352c9ce25SScott Long
12043394d423SEdward Tomasz Napierala ada_ccb_zone = uma_zcreate("ada_ccb",
12053394d423SEdward Tomasz Napierala sizeof(struct ccb_ataio), NULL, NULL, NULL, NULL,
12063394d423SEdward Tomasz Napierala UMA_ALIGN_PTR, 0);
12073394d423SEdward Tomasz Napierala
120852c9ce25SScott Long /*
120952c9ce25SScott Long * Install a global async callback. This callback will
121052c9ce25SScott Long * receive async callbacks like "new device found".
121152c9ce25SScott Long */
121252c9ce25SScott Long status = xpt_register_async(AC_FOUND_DEVICE, adaasync, NULL, NULL);
121352c9ce25SScott Long
121452c9ce25SScott Long if (status != CAM_REQ_CMP) {
121552c9ce25SScott Long printf("ada: Failed to attach master async callback "
121652c9ce25SScott Long "due to status 0x%x!\n", status);
121752c9ce25SScott Long } else if (ada_send_ordered) {
1218c3d0d168SAlexander Motin /* Register our event handlers */
1219c3d0d168SAlexander Motin if ((EVENTHANDLER_REGISTER(power_suspend, adasuspend,
1220c3d0d168SAlexander Motin NULL, EVENTHANDLER_PRI_LAST)) == NULL)
1221c3d0d168SAlexander Motin printf("adainit: power event registration failed!\n");
1222c3d0d168SAlexander Motin if ((EVENTHANDLER_REGISTER(power_resume, adaresume,
1223c3d0d168SAlexander Motin NULL, EVENTHANDLER_PRI_LAST)) == NULL)
1224c3d0d168SAlexander Motin printf("adainit: power event registration failed!\n");
122552c9ce25SScott Long if ((EVENTHANDLER_REGISTER(shutdown_post_sync, adashutdown,
122652c9ce25SScott Long NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
122752c9ce25SScott Long printf("adainit: shutdown event registration failed!\n");
122852c9ce25SScott Long }
122952c9ce25SScott Long }
123052c9ce25SScott Long
12310ba1e4d0SKenneth D. Merry /*
12320ba1e4d0SKenneth D. Merry * Callback from GEOM, called when it has finished cleaning up its
12330ba1e4d0SKenneth D. Merry * resources.
12340ba1e4d0SKenneth D. Merry */
12350ba1e4d0SKenneth D. Merry static void
adadiskgonecb(struct disk * dp)12360ba1e4d0SKenneth D. Merry adadiskgonecb(struct disk *dp)
12370ba1e4d0SKenneth D. Merry {
12380ba1e4d0SKenneth D. Merry struct cam_periph *periph;
12390ba1e4d0SKenneth D. Merry
12400ba1e4d0SKenneth D. Merry periph = (struct cam_periph *)dp->d_drv1;
12410ba1e4d0SKenneth D. Merry
12420ba1e4d0SKenneth D. Merry cam_periph_release(periph);
12430ba1e4d0SKenneth D. Merry }
12440ba1e4d0SKenneth D. Merry
124552c9ce25SScott Long static void
adaoninvalidate(struct cam_periph * periph)124652c9ce25SScott Long adaoninvalidate(struct cam_periph *periph)
124752c9ce25SScott Long {
124852c9ce25SScott Long struct ada_softc *softc;
124952c9ce25SScott Long
125052c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
125152c9ce25SScott Long
125252c9ce25SScott Long /*
125352c9ce25SScott Long * De-register any async callbacks.
125452c9ce25SScott Long */
125552c9ce25SScott Long xpt_register_async(0, adaasync, periph, periph->path);
1256a6e0c5daSWarner Losh #ifdef CAM_IO_STATS
1257a6e0c5daSWarner Losh softc->invalidations++;
1258a6e0c5daSWarner Losh #endif
125952c9ce25SScott Long
126052c9ce25SScott Long /*
1261b43cfe71SWarner Losh * Return all queued I/O with ENXIO. Transactions may be queued up here
1262b43cfe71SWarner Losh * for retry (since we are called while there's other transactions
1263b43cfe71SWarner Losh * pending). Any requests in the hardware will drain before ndacleanup
1264b43cfe71SWarner Losh * is called.
126552c9ce25SScott Long */
1266a6e0c5daSWarner Losh cam_iosched_flush(softc->cam_iosched, NULL, ENXIO);
126752c9ce25SScott Long
126848ae3f4fSWarner Losh /*
126948ae3f4fSWarner Losh * Tell GEOM that we've gone away, we'll get a callback when it is
127048ae3f4fSWarner Losh * done cleaning up its resources.
127148ae3f4fSWarner Losh */
127252c9ce25SScott Long disk_gone(softc->disk);
127352c9ce25SScott Long }
127452c9ce25SScott Long
127552c9ce25SScott Long static void
adacleanup(struct cam_periph * periph)127652c9ce25SScott Long adacleanup(struct cam_periph *periph)
127752c9ce25SScott Long {
127852c9ce25SScott Long struct ada_softc *softc;
127952c9ce25SScott Long
128052c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
128152c9ce25SScott Long
128252c9ce25SScott Long cam_periph_unlock(periph);
128352c9ce25SScott Long
1284a6e0c5daSWarner Losh cam_iosched_fini(softc->cam_iosched);
1285a6e0c5daSWarner Losh
128652c9ce25SScott Long /*
128752c9ce25SScott Long * If we can't free the sysctl tree, oh well...
128852c9ce25SScott Long */
1289a6e0c5daSWarner Losh if ((softc->flags & ADA_FLAG_SCTX_INIT) != 0) {
1290a6e0c5daSWarner Losh #ifdef CAM_IO_STATS
1291a6e0c5daSWarner Losh if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0)
1292a6e0c5daSWarner Losh xpt_print(periph->path,
1293a6e0c5daSWarner Losh "can't remove sysctl stats context\n");
1294a6e0c5daSWarner Losh #endif
1295a6e0c5daSWarner Losh if (sysctl_ctx_free(&softc->sysctl_ctx) != 0)
1296a6e0c5daSWarner Losh xpt_print(periph->path,
1297a6e0c5daSWarner Losh "can't remove sysctl context\n");
129852c9ce25SScott Long }
129952c9ce25SScott Long
130052c9ce25SScott Long disk_destroy(softc->disk);
130152c9ce25SScott Long callout_drain(&softc->sendordered_c);
130252c9ce25SScott Long free(softc, M_DEVBUF);
130352c9ce25SScott Long cam_periph_lock(periph);
130452c9ce25SScott Long }
130552c9ce25SScott Long
130652c9ce25SScott Long static void
adasetdeletemethod(struct ada_softc * softc)1307a6e0c5daSWarner Losh adasetdeletemethod(struct ada_softc *softc)
1308a6e0c5daSWarner Losh {
1309a6e0c5daSWarner Losh
1310a6e0c5daSWarner Losh if (softc->flags & ADA_FLAG_CAN_NCQ_TRIM)
1311a6e0c5daSWarner Losh softc->delete_method = ADA_DELETE_NCQ_DSM_TRIM;
1312a6e0c5daSWarner Losh else if (softc->flags & ADA_FLAG_CAN_TRIM)
1313a6e0c5daSWarner Losh softc->delete_method = ADA_DELETE_DSM_TRIM;
1314a6e0c5daSWarner Losh else if ((softc->flags & ADA_FLAG_CAN_CFA) && !(softc->flags & ADA_FLAG_CAN_48BIT))
1315a6e0c5daSWarner Losh softc->delete_method = ADA_DELETE_CFA_ERASE;
1316a6e0c5daSWarner Losh else
1317a6e0c5daSWarner Losh softc->delete_method = ADA_DELETE_NONE;
1318a6e0c5daSWarner Losh }
1319a6e0c5daSWarner Losh
1320a6e0c5daSWarner Losh static void
adaasync(void * callback_arg,uint32_t code,struct cam_path * path,void * arg)13219db2db6bSWarner Losh adaasync(void *callback_arg, uint32_t code,
132252c9ce25SScott Long struct cam_path *path, void *arg)
132352c9ce25SScott Long {
1324581b2e78SAlexander Motin struct ccb_getdev cgd;
132552c9ce25SScott Long struct cam_periph *periph;
1326f513d14cSAlexander Motin struct ada_softc *softc;
132752c9ce25SScott Long
132852c9ce25SScott Long periph = (struct cam_periph *)callback_arg;
132952c9ce25SScott Long switch (code) {
133052c9ce25SScott Long case AC_FOUND_DEVICE:
133152c9ce25SScott Long {
133252c9ce25SScott Long struct ccb_getdev *cgd;
133352c9ce25SScott Long cam_status status;
133452c9ce25SScott Long
133552c9ce25SScott Long cgd = (struct ccb_getdev *)arg;
133652c9ce25SScott Long if (cgd == NULL)
133752c9ce25SScott Long break;
133852c9ce25SScott Long
133952c9ce25SScott Long if (cgd->protocol != PROTO_ATA)
134052c9ce25SScott Long break;
134152c9ce25SScott Long
134252c9ce25SScott Long /*
134352c9ce25SScott Long * Allocate a peripheral instance for
134452c9ce25SScott Long * this device and start the probe
134552c9ce25SScott Long * process.
134652c9ce25SScott Long */
134752c9ce25SScott Long status = cam_periph_alloc(adaregister, adaoninvalidate,
134852c9ce25SScott Long adacleanup, adastart,
134952c9ce25SScott Long "ada", CAM_PERIPH_BIO,
1350227d67aaSAlexander Motin path, adaasync,
135152c9ce25SScott Long AC_FOUND_DEVICE, cgd);
135252c9ce25SScott Long
135352c9ce25SScott Long if (status != CAM_REQ_CMP
135452c9ce25SScott Long && status != CAM_REQ_INPROG)
135552c9ce25SScott Long printf("adaasync: Unable to attach to new device "
135652c9ce25SScott Long "due to status 0x%x\n", status);
135752c9ce25SScott Long break;
135852c9ce25SScott Long }
1359581b2e78SAlexander Motin case AC_GETDEV_CHANGED:
1360581b2e78SAlexander Motin {
1361581b2e78SAlexander Motin softc = (struct ada_softc *)periph->softc;
1362ec5325dbSEdward Tomasz Napierala memset(&cgd, 0, sizeof(cgd));
1363581b2e78SAlexander Motin xpt_setup_ccb(&cgd.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1364581b2e78SAlexander Motin cgd.ccb_h.func_code = XPT_GDEV_TYPE;
1365581b2e78SAlexander Motin xpt_action((union ccb *)&cgd);
1366581b2e78SAlexander Motin
1367a6e0c5daSWarner Losh /*
136876d843daSAlexander Motin * Update our information based on the new Identify data.
1369a6e0c5daSWarner Losh */
13709a6844d5SKenneth D. Merry adasetflags(softc, &cgd);
137176d843daSAlexander Motin adasetgeom(softc, &cgd);
137276d843daSAlexander Motin disk_resize(softc->disk, M_NOWAIT);
1373581b2e78SAlexander Motin break;
1374581b2e78SAlexander Motin }
13753089bb2eSAlexander Motin case AC_ADVINFO_CHANGED:
13763089bb2eSAlexander Motin {
13773089bb2eSAlexander Motin uintptr_t buftype;
13783089bb2eSAlexander Motin
13793089bb2eSAlexander Motin buftype = (uintptr_t)arg;
13803089bb2eSAlexander Motin if (buftype == CDAI_TYPE_PHYS_PATH) {
13813089bb2eSAlexander Motin struct ada_softc *softc;
13823089bb2eSAlexander Motin
13833089bb2eSAlexander Motin softc = periph->softc;
13843089bb2eSAlexander Motin disk_attr_changed(softc->disk, "GEOM::physpath",
13853089bb2eSAlexander Motin M_NOWAIT);
13863089bb2eSAlexander Motin }
13873089bb2eSAlexander Motin break;
13883089bb2eSAlexander Motin }
1389f513d14cSAlexander Motin case AC_SENT_BDR:
1390f513d14cSAlexander Motin case AC_BUS_RESET:
1391f513d14cSAlexander Motin {
1392f513d14cSAlexander Motin softc = (struct ada_softc *)periph->softc;
1393f513d14cSAlexander Motin if (softc->state != ADA_STATE_NORMAL)
1394f513d14cSAlexander Motin break;
13959a6844d5SKenneth D. Merry if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD)
13961ed6aaf9SAlexander Motin softc->state = ADA_STATE_RAHEAD;
13971d9aaa86SAlexander Motin else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_WCACHE)
1398f513d14cSAlexander Motin softc->state = ADA_STATE_WCACHE;
1399600fd98fSKenneth D. Merry else if ((softc->flags & ADA_FLAG_CAN_LOG)
1400600fd98fSKenneth D. Merry && (softc->zone_mode != ADA_ZONE_NONE))
14019a6844d5SKenneth D. Merry softc->state = ADA_STATE_LOGDIR;
14021ed6aaf9SAlexander Motin else
14031ed6aaf9SAlexander Motin break;
140499e7a4adSScott Long if (cam_periph_acquire(periph) != 0)
1405227d67aaSAlexander Motin softc->state = ADA_STATE_NORMAL;
1406227d67aaSAlexander Motin else
1407f513d14cSAlexander Motin xpt_schedule(periph, CAM_PRIORITY_DEV);
140852c9ce25SScott Long break;
140952c9ce25SScott Long }
1410ae1955cdSWarner Losh default:
1411ae1955cdSWarner Losh break;
1412ae1955cdSWarner Losh }
1413ae1955cdSWarner Losh cam_periph_async(periph, code, path, arg);
141452c9ce25SScott Long }
141552c9ce25SScott Long
14169a6844d5SKenneth D. Merry static int
adazonemodesysctl(SYSCTL_HANDLER_ARGS)14179a6844d5SKenneth D. Merry adazonemodesysctl(SYSCTL_HANDLER_ARGS)
14189a6844d5SKenneth D. Merry {
14199a6844d5SKenneth D. Merry char tmpbuf[40];
14209a6844d5SKenneth D. Merry struct ada_softc *softc;
14219a6844d5SKenneth D. Merry int error;
14229a6844d5SKenneth D. Merry
14239a6844d5SKenneth D. Merry softc = (struct ada_softc *)arg1;
14249a6844d5SKenneth D. Merry
14259a6844d5SKenneth D. Merry switch (softc->zone_mode) {
14269a6844d5SKenneth D. Merry case ADA_ZONE_DRIVE_MANAGED:
14279a6844d5SKenneth D. Merry snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed");
14289a6844d5SKenneth D. Merry break;
14299a6844d5SKenneth D. Merry case ADA_ZONE_HOST_AWARE:
14309a6844d5SKenneth D. Merry snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware");
14319a6844d5SKenneth D. Merry break;
14329a6844d5SKenneth D. Merry case ADA_ZONE_HOST_MANAGED:
14339a6844d5SKenneth D. Merry snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed");
14349a6844d5SKenneth D. Merry break;
14359a6844d5SKenneth D. Merry case ADA_ZONE_NONE:
14369a6844d5SKenneth D. Merry default:
14379a6844d5SKenneth D. Merry snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned");
14389a6844d5SKenneth D. Merry break;
14399a6844d5SKenneth D. Merry }
14409a6844d5SKenneth D. Merry
14419a6844d5SKenneth D. Merry error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req);
14429a6844d5SKenneth D. Merry
14439a6844d5SKenneth D. Merry return (error);
14449a6844d5SKenneth D. Merry }
14459a6844d5SKenneth D. Merry
14469a6844d5SKenneth D. Merry static int
adazonesupsysctl(SYSCTL_HANDLER_ARGS)14479a6844d5SKenneth D. Merry adazonesupsysctl(SYSCTL_HANDLER_ARGS)
14489a6844d5SKenneth D. Merry {
14499a6844d5SKenneth D. Merry struct ada_softc *softc;
14509a6844d5SKenneth D. Merry struct sbuf sb;
14519a6844d5SKenneth D. Merry int error, first;
14529a6844d5SKenneth D. Merry unsigned int i;
14539a6844d5SKenneth D. Merry
14549a6844d5SKenneth D. Merry softc = (struct ada_softc *)arg1;
14559a6844d5SKenneth D. Merry
14569a6844d5SKenneth D. Merry first = 1;
14571b440795SAlexander Motin sbuf_new_for_sysctl(&sb, NULL, 0, req);
14589a6844d5SKenneth D. Merry
14599a6844d5SKenneth D. Merry for (i = 0; i < sizeof(ada_zone_desc_table) /
14609a6844d5SKenneth D. Merry sizeof(ada_zone_desc_table[0]); i++) {
14619a6844d5SKenneth D. Merry if (softc->zone_flags & ada_zone_desc_table[i].value) {
14629a6844d5SKenneth D. Merry if (first == 0)
14631b440795SAlexander Motin sbuf_cat(&sb, ", ");
14649a6844d5SKenneth D. Merry else
14659a6844d5SKenneth D. Merry first = 0;
14669a6844d5SKenneth D. Merry sbuf_cat(&sb, ada_zone_desc_table[i].desc);
14679a6844d5SKenneth D. Merry }
14689a6844d5SKenneth D. Merry }
14699a6844d5SKenneth D. Merry
14709a6844d5SKenneth D. Merry if (first == 1)
1471519b24f0SAlexander Motin sbuf_cat(&sb, "None");
14729a6844d5SKenneth D. Merry
14731b440795SAlexander Motin error = sbuf_finish(&sb);
14741b440795SAlexander Motin sbuf_delete(&sb);
14759a6844d5SKenneth D. Merry return (error);
14769a6844d5SKenneth D. Merry }
14779a6844d5SKenneth D. Merry
147852c9ce25SScott Long static void
adasysctlinit(void * context,int pending)147952c9ce25SScott Long adasysctlinit(void *context, int pending)
148052c9ce25SScott Long {
148152c9ce25SScott Long struct cam_periph *periph;
148252c9ce25SScott Long struct ada_softc *softc;
14834d470952SAlexander Motin char tmpstr[32], tmpstr2[16];
148452c9ce25SScott Long
148552c9ce25SScott Long periph = (struct cam_periph *)context;
1486e3a6d3a4SAlexander Motin
1487e3a6d3a4SAlexander Motin /* periph was held for us when this task was enqueued */
14887338ef1aSAlexander Motin if ((periph->flags & CAM_PERIPH_INVALID) != 0) {
1489e3a6d3a4SAlexander Motin cam_periph_release(periph);
149052c9ce25SScott Long return;
1491e3a6d3a4SAlexander Motin }
149252c9ce25SScott Long
149352c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
149452c9ce25SScott Long snprintf(tmpstr, sizeof(tmpstr), "CAM ADA unit %d",periph->unit_number);
149552c9ce25SScott Long snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
149652c9ce25SScott Long
149752c9ce25SScott Long sysctl_ctx_init(&softc->sysctl_ctx);
149852c9ce25SScott Long softc->flags |= ADA_FLAG_SCTX_INIT;
14994c484fd2SEd Schouten softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx,
150052c9ce25SScott Long SYSCTL_STATIC_CHILDREN(_kern_cam_ada), OID_AUTO, tmpstr2,
15017029da5cSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, 0, tmpstr, "device_index");
150252c9ce25SScott Long if (softc->sysctl_tree == NULL) {
150352c9ce25SScott Long printf("adasysctlinit: unable to allocate sysctl tree\n");
150452c9ce25SScott Long cam_periph_release(periph);
150552c9ce25SScott Long return;
150652c9ce25SScott Long }
150752c9ce25SScott Long
1508a6e0c5daSWarner Losh SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
15097029da5cSPawel Biernacki OID_AUTO, "delete_method",
1510303477d3SAlexander Motin CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_MPSAFE,
1511a6e0c5daSWarner Losh softc, 0, adadeletemethodsysctl, "A",
1512a6e0c5daSWarner Losh "BIO_DELETE execution method");
1513ea657f2cSWarner Losh SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1514ea657f2cSWarner Losh SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1515ea657f2cSWarner Losh "trim_count", CTLFLAG_RD, &softc->trim_count,
1516ea657f2cSWarner Losh "Total number of dsm commands sent");
1517ea657f2cSWarner Losh SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1518ea657f2cSWarner Losh SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1519ea657f2cSWarner Losh "trim_ranges", CTLFLAG_RD, &softc->trim_ranges,
1520ea657f2cSWarner Losh "Total number of ranges in dsm commands");
1521ea657f2cSWarner Losh SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1522ea657f2cSWarner Losh SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
1523ea657f2cSWarner Losh "trim_lbas", CTLFLAG_RD, &softc->trim_lbas,
1524ea657f2cSWarner Losh "Total lbas in the dsm commands sent");
1525e3a6d3a4SAlexander Motin SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
15261ed6aaf9SAlexander Motin OID_AUTO, "read_ahead", CTLFLAG_RW | CTLFLAG_MPSAFE,
15271ed6aaf9SAlexander Motin &softc->read_ahead, 0, "Enable disk read ahead.");
15281ed6aaf9SAlexander Motin SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1529e3a6d3a4SAlexander Motin OID_AUTO, "write_cache", CTLFLAG_RW | CTLFLAG_MPSAFE,
1530e3a6d3a4SAlexander Motin &softc->write_cache, 0, "Enable disk write cache.");
15319a6844d5SKenneth D. Merry SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
15327029da5cSPawel Biernacki OID_AUTO, "zone_mode",
1533303477d3SAlexander Motin CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
15349a6844d5SKenneth D. Merry softc, 0, adazonemodesysctl, "A",
15359a6844d5SKenneth D. Merry "Zone Mode");
15369a6844d5SKenneth D. Merry SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
15377029da5cSPawel Biernacki OID_AUTO, "zone_support",
1538303477d3SAlexander Motin CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
15399a6844d5SKenneth D. Merry softc, 0, adazonesupsysctl, "A",
15409a6844d5SKenneth D. Merry "Zone Support");
15419a6844d5SKenneth D. Merry SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
15429a6844d5SKenneth D. Merry SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
15439a6844d5SKenneth D. Merry "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones,
15449a6844d5SKenneth D. Merry "Optimal Number of Open Sequential Write Preferred Zones");
15459a6844d5SKenneth D. Merry SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
15469a6844d5SKenneth D. Merry SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
15479a6844d5SKenneth D. Merry "optimal_nonseq_zones", CTLFLAG_RD,
15489a6844d5SKenneth D. Merry &softc->optimal_nonseq_zones,
15499a6844d5SKenneth D. Merry "Optimal Number of Non-Sequentially Written Sequential Write "
15509a6844d5SKenneth D. Merry "Preferred Zones");
15519a6844d5SKenneth D. Merry SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
15529a6844d5SKenneth D. Merry SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO,
15539a6844d5SKenneth D. Merry "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones,
15549a6844d5SKenneth D. Merry "Maximum Number of Open Sequential Write Required Zones");
1555aeab0812SWarner Losh SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1556aeab0812SWarner Losh OID_AUTO, "flags", CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_MPSAFE,
1557aeab0812SWarner Losh softc, 0, adaflagssysctl, "A",
1558aeab0812SWarner Losh "Flags for drive");
1559cf3ff63eSWarner Losh SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1560cf3ff63eSWarner Losh OID_AUTO, "unmapped_io", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
1561cf3ff63eSWarner Losh &softc->flags, (u_int)ADA_FLAG_UNMAPPEDIO, adabitsysctl, "I",
1562d24729b2SZhenlei Huang "Use unmapped I/O. This sysctl is *DEPRECATED*, gone in FreeBSD 15");
156396eb32bfSWarner Losh SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
156496eb32bfSWarner Losh OID_AUTO, "rotating", CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_MPSAFE,
156596eb32bfSWarner Losh &softc->flags, (u_int)ADA_FLAG_ROTATING, adabitsysctl, "I",
1566d24729b2SZhenlei Huang "Rotating media. This sysctl is *DEPRECATED*, gone in FreeBSD 15");
15679a6844d5SKenneth D. Merry
1568d38677d2SWarner Losh #ifdef CAM_TEST_FAILURE
1569e3a6d3a4SAlexander Motin /*
1570e3a6d3a4SAlexander Motin * Add a 'door bell' sysctl which allows one to set it from userland
1571e3a6d3a4SAlexander Motin * and cause something bad to happen. For the moment, we only allow
1572e3a6d3a4SAlexander Motin * whacking the next read or write.
1573e3a6d3a4SAlexander Motin */
1574e3a6d3a4SAlexander Motin SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1575e3a6d3a4SAlexander Motin OID_AUTO, "force_read_error", CTLFLAG_RW | CTLFLAG_MPSAFE,
1576e3a6d3a4SAlexander Motin &softc->force_read_error, 0,
1577e3a6d3a4SAlexander Motin "Force a read error for the next N reads.");
1578e3a6d3a4SAlexander Motin SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1579e3a6d3a4SAlexander Motin OID_AUTO, "force_write_error", CTLFLAG_RW | CTLFLAG_MPSAFE,
1580e3a6d3a4SAlexander Motin &softc->force_write_error, 0,
1581e3a6d3a4SAlexander Motin "Force a write error for the next N writes.");
1582e3a6d3a4SAlexander Motin SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1583e3a6d3a4SAlexander Motin OID_AUTO, "periodic_read_error", CTLFLAG_RW | CTLFLAG_MPSAFE,
1584e3a6d3a4SAlexander Motin &softc->periodic_read_error, 0,
1585e3a6d3a4SAlexander Motin "Force a read error every N reads (don't set too low).");
1586d38677d2SWarner Losh SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1587d38677d2SWarner Losh OID_AUTO, "invalidate", CTLTYPE_U64 | CTLFLAG_RW | CTLFLAG_MPSAFE,
1588d38677d2SWarner Losh periph, 0, cam_periph_invalidate_sysctl, "I",
1589d38677d2SWarner Losh "Write 1 to invalidate the drive immediately");
1590e3a6d3a4SAlexander Motin #endif
1591a6e0c5daSWarner Losh
1592a6e0c5daSWarner Losh #ifdef CAM_IO_STATS
1593a6e0c5daSWarner Losh softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx,
1594a6e0c5daSWarner Losh SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats",
15957029da5cSPawel Biernacki CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "Statistics");
1596a6e0c5daSWarner Losh SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
1597a6e0c5daSWarner Losh SYSCTL_CHILDREN(softc->sysctl_stats_tree),
1598a6e0c5daSWarner Losh OID_AUTO, "timeouts", CTLFLAG_RD | CTLFLAG_MPSAFE,
1599a6e0c5daSWarner Losh &softc->timeouts, 0,
1600a6e0c5daSWarner Losh "Device timeouts reported by the SIM");
1601a6e0c5daSWarner Losh SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
1602a6e0c5daSWarner Losh SYSCTL_CHILDREN(softc->sysctl_stats_tree),
1603a6e0c5daSWarner Losh OID_AUTO, "errors", CTLFLAG_RD | CTLFLAG_MPSAFE,
1604a6e0c5daSWarner Losh &softc->errors, 0,
1605a6e0c5daSWarner Losh "Transport errors reported by the SIM.");
1606a6e0c5daSWarner Losh SYSCTL_ADD_INT(&softc->sysctl_stats_ctx,
1607a6e0c5daSWarner Losh SYSCTL_CHILDREN(softc->sysctl_stats_tree),
1608a6e0c5daSWarner Losh OID_AUTO, "pack_invalidations", CTLFLAG_RD | CTLFLAG_MPSAFE,
1609a6e0c5daSWarner Losh &softc->invalidations, 0,
1610a6e0c5daSWarner Losh "Device pack invalidations.");
1611a6e0c5daSWarner Losh #endif
1612a6e0c5daSWarner Losh
1613a6e0c5daSWarner Losh cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx,
1614a6e0c5daSWarner Losh softc->sysctl_tree);
1615a6e0c5daSWarner Losh
161652c9ce25SScott Long cam_periph_release(periph);
161752c9ce25SScott Long }
161852c9ce25SScott Long
1619416494d7SJustin T. Gibbs static int
adagetattr(struct bio * bp)1620416494d7SJustin T. Gibbs adagetattr(struct bio *bp)
1621416494d7SJustin T. Gibbs {
16226884b662SAlexander Motin int ret;
1623416494d7SJustin T. Gibbs struct cam_periph *periph;
1624416494d7SJustin T. Gibbs
162513532153SScott Long if (g_handleattr_int(bp, "GEOM::canspeedup", ada_enable_biospeedup))
162613532153SScott Long return (EJUSTRETURN);
162713532153SScott Long
1628416494d7SJustin T. Gibbs periph = (struct cam_periph *)bp->bio_disk->d_drv1;
16296884b662SAlexander Motin cam_periph_lock(periph);
1630416494d7SJustin T. Gibbs ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1631416494d7SJustin T. Gibbs periph->path);
16326884b662SAlexander Motin cam_periph_unlock(periph);
1633416494d7SJustin T. Gibbs if (ret == 0)
1634416494d7SJustin T. Gibbs bp->bio_completed = bp->bio_length;
1635416494d7SJustin T. Gibbs return ret;
1636416494d7SJustin T. Gibbs }
1637416494d7SJustin T. Gibbs
1638a6e0c5daSWarner Losh static int
adadeletemethodsysctl(SYSCTL_HANDLER_ARGS)1639a6e0c5daSWarner Losh adadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
1640a6e0c5daSWarner Losh {
1641a6e0c5daSWarner Losh char buf[16];
1642a6e0c5daSWarner Losh const char *p;
1643a6e0c5daSWarner Losh struct ada_softc *softc;
1644a6e0c5daSWarner Losh int i, error, value, methods;
1645a6e0c5daSWarner Losh
1646a6e0c5daSWarner Losh softc = (struct ada_softc *)arg1;
1647a6e0c5daSWarner Losh
1648a6e0c5daSWarner Losh value = softc->delete_method;
1649a6e0c5daSWarner Losh if (value < 0 || value > ADA_DELETE_MAX)
1650a6e0c5daSWarner Losh p = "UNKNOWN";
1651a6e0c5daSWarner Losh else
1652a6e0c5daSWarner Losh p = ada_delete_method_names[value];
1653a6e0c5daSWarner Losh strncpy(buf, p, sizeof(buf));
1654a6e0c5daSWarner Losh error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1655a6e0c5daSWarner Losh if (error != 0 || req->newptr == NULL)
1656a6e0c5daSWarner Losh return (error);
1657a6e0c5daSWarner Losh methods = 1 << ADA_DELETE_DISABLE;
1658a6e0c5daSWarner Losh if ((softc->flags & ADA_FLAG_CAN_CFA) &&
1659a6e0c5daSWarner Losh !(softc->flags & ADA_FLAG_CAN_48BIT))
1660a6e0c5daSWarner Losh methods |= 1 << ADA_DELETE_CFA_ERASE;
1661a6e0c5daSWarner Losh if (softc->flags & ADA_FLAG_CAN_TRIM)
1662a6e0c5daSWarner Losh methods |= 1 << ADA_DELETE_DSM_TRIM;
1663a6e0c5daSWarner Losh if (softc->flags & ADA_FLAG_CAN_NCQ_TRIM)
1664a6e0c5daSWarner Losh methods |= 1 << ADA_DELETE_NCQ_DSM_TRIM;
1665a6e0c5daSWarner Losh for (i = 0; i <= ADA_DELETE_MAX; i++) {
1666a6e0c5daSWarner Losh if (!(methods & (1 << i)) ||
1667a6e0c5daSWarner Losh strcmp(buf, ada_delete_method_names[i]) != 0)
1668a6e0c5daSWarner Losh continue;
1669a6e0c5daSWarner Losh softc->delete_method = i;
1670a6e0c5daSWarner Losh return (0);
1671a6e0c5daSWarner Losh }
1672a6e0c5daSWarner Losh return (EINVAL);
1673a6e0c5daSWarner Losh }
1674a6e0c5daSWarner Losh
1675aeab0812SWarner Losh static int
adabitsysctl(SYSCTL_HANDLER_ARGS)1676cf3ff63eSWarner Losh adabitsysctl(SYSCTL_HANDLER_ARGS)
1677cf3ff63eSWarner Losh {
1678cf3ff63eSWarner Losh u_int *flags = arg1;
1679cf3ff63eSWarner Losh u_int test = arg2;
1680cf3ff63eSWarner Losh int tmpout, error;
1681cf3ff63eSWarner Losh
1682cf3ff63eSWarner Losh tmpout = !!(*flags & test);
1683cf3ff63eSWarner Losh error = SYSCTL_OUT(req, &tmpout, sizeof(tmpout));
1684cf3ff63eSWarner Losh if (error || !req->newptr)
1685cf3ff63eSWarner Losh return (error);
1686cf3ff63eSWarner Losh
1687cf3ff63eSWarner Losh return (EPERM);
1688cf3ff63eSWarner Losh }
1689cf3ff63eSWarner Losh
1690cf3ff63eSWarner Losh static int
adaflagssysctl(SYSCTL_HANDLER_ARGS)1691aeab0812SWarner Losh adaflagssysctl(SYSCTL_HANDLER_ARGS)
1692aeab0812SWarner Losh {
1693aeab0812SWarner Losh struct sbuf sbuf;
1694aeab0812SWarner Losh struct ada_softc *softc = arg1;
1695aeab0812SWarner Losh int error;
1696aeab0812SWarner Losh
1697aeab0812SWarner Losh sbuf_new_for_sysctl(&sbuf, NULL, 0, req);
1698aeab0812SWarner Losh if (softc->flags != 0)
1699aeab0812SWarner Losh sbuf_printf(&sbuf, "0x%b", (unsigned)softc->flags, ADA_FLAG_STRING);
1700aeab0812SWarner Losh else
1701519b24f0SAlexander Motin sbuf_putc(&sbuf, '0');
1702aeab0812SWarner Losh error = sbuf_finish(&sbuf);
1703aeab0812SWarner Losh sbuf_delete(&sbuf);
1704aeab0812SWarner Losh
1705aeab0812SWarner Losh return (error);
1706aeab0812SWarner Losh }
1707aeab0812SWarner Losh
17089a6844d5SKenneth D. Merry static void
adasetflags(struct ada_softc * softc,struct ccb_getdev * cgd)17099a6844d5SKenneth D. Merry adasetflags(struct ada_softc *softc, struct ccb_getdev *cgd)
17109a6844d5SKenneth D. Merry {
17119a6844d5SKenneth D. Merry if ((cgd->ident_data.capabilities1 & ATA_SUPPORT_DMA) &&
17129a6844d5SKenneth D. Merry (cgd->inq_flags & SID_DMA))
17139a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_DMA;
17149a6844d5SKenneth D. Merry else
17159a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_DMA;
17169a6844d5SKenneth D. Merry
17179a6844d5SKenneth D. Merry if (cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) {
17189a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_48BIT;
17199a6844d5SKenneth D. Merry if (cgd->inq_flags & SID_DMA48)
17209a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_DMA48;
17219a6844d5SKenneth D. Merry else
17229a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_DMA48;
17239a6844d5SKenneth D. Merry } else
17249a6844d5SKenneth D. Merry softc->flags &= ~(ADA_FLAG_CAN_48BIT | ADA_FLAG_CAN_DMA48);
17259a6844d5SKenneth D. Merry
17269a6844d5SKenneth D. Merry if (cgd->ident_data.support.command2 & ATA_SUPPORT_FLUSHCACHE)
17279a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_FLUSHCACHE;
17289a6844d5SKenneth D. Merry else
17299a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_FLUSHCACHE;
17309a6844d5SKenneth D. Merry
17319a6844d5SKenneth D. Merry if (cgd->ident_data.support.command1 & ATA_SUPPORT_POWERMGT)
17329a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_POWERMGT;
17339a6844d5SKenneth D. Merry else
17349a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_POWERMGT;
17359a6844d5SKenneth D. Merry
17369a6844d5SKenneth D. Merry if ((cgd->ident_data.satacapabilities & ATA_SUPPORT_NCQ) &&
17379a6844d5SKenneth D. Merry (cgd->inq_flags & SID_DMA) && (cgd->inq_flags & SID_CmdQue))
17389a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_NCQ;
17399a6844d5SKenneth D. Merry else
17409a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_NCQ;
17419a6844d5SKenneth D. Merry
17429a6844d5SKenneth D. Merry if ((cgd->ident_data.support_dsm & ATA_SUPPORT_DSM_TRIM) &&
174376d843daSAlexander Motin (cgd->inq_flags & SID_DMA) &&
174476d843daSAlexander Motin (softc->quirks & ADA_Q_NO_TRIM) == 0) {
17459a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_TRIM;
17469a6844d5SKenneth D. Merry softc->trim_max_ranges = TRIM_MAX_RANGES;
17479a6844d5SKenneth D. Merry if (cgd->ident_data.max_dsm_blocks != 0) {
17489a6844d5SKenneth D. Merry softc->trim_max_ranges =
17499a6844d5SKenneth D. Merry min(cgd->ident_data.max_dsm_blocks *
17509a6844d5SKenneth D. Merry ATA_DSM_BLK_RANGES, softc->trim_max_ranges);
17519a6844d5SKenneth D. Merry }
17529a6844d5SKenneth D. Merry /*
17539a6844d5SKenneth D. Merry * If we can do RCVSND_FPDMA_QUEUED commands, we may be able
17549a6844d5SKenneth D. Merry * to do NCQ trims, if we support trims at all. We also need
17559a6844d5SKenneth D. Merry * support from the SIM to do things properly. Perhaps we
17569a6844d5SKenneth D. Merry * should look at log 13 dword 0 bit 0 and dword 1 bit 0 are
17579a6844d5SKenneth D. Merry * set too...
17589a6844d5SKenneth D. Merry */
17599a6844d5SKenneth D. Merry if ((softc->quirks & ADA_Q_NCQ_TRIM_BROKEN) == 0 &&
17609a6844d5SKenneth D. Merry (softc->flags & ADA_FLAG_PIM_ATA_EXT) != 0 &&
17619a6844d5SKenneth D. Merry (cgd->ident_data.satacapabilities2 &
17629a6844d5SKenneth D. Merry ATA_SUPPORT_RCVSND_FPDMA_QUEUED) != 0 &&
17639a6844d5SKenneth D. Merry (softc->flags & ADA_FLAG_CAN_TRIM) != 0)
17649a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_NCQ_TRIM;
17659a6844d5SKenneth D. Merry else
17669a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_NCQ_TRIM;
17679a6844d5SKenneth D. Merry } else
17689a6844d5SKenneth D. Merry softc->flags &= ~(ADA_FLAG_CAN_TRIM | ADA_FLAG_CAN_NCQ_TRIM);
17699a6844d5SKenneth D. Merry
17709a6844d5SKenneth D. Merry if (cgd->ident_data.support.command2 & ATA_SUPPORT_CFA)
17719a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_CFA;
17729a6844d5SKenneth D. Merry else
17739a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_CFA;
17749a6844d5SKenneth D. Merry
17759a6844d5SKenneth D. Merry /*
17769a6844d5SKenneth D. Merry * Now that we've set the appropriate flags, setup the delete
17779a6844d5SKenneth D. Merry * method.
17789a6844d5SKenneth D. Merry */
17799a6844d5SKenneth D. Merry adasetdeletemethod(softc);
17809a6844d5SKenneth D. Merry
1781600fd98fSKenneth D. Merry if ((cgd->ident_data.support.extension & ATA_SUPPORT_GENLOG)
1782600fd98fSKenneth D. Merry && ((softc->quirks & ADA_Q_LOG_BROKEN) == 0))
17839a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_LOG;
17849a6844d5SKenneth D. Merry else
17859a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_LOG;
17869a6844d5SKenneth D. Merry
17879a6844d5SKenneth D. Merry if ((cgd->ident_data.support3 & ATA_SUPPORT_ZONE_MASK) ==
17889a6844d5SKenneth D. Merry ATA_SUPPORT_ZONE_HOST_AWARE)
17899a6844d5SKenneth D. Merry softc->zone_mode = ADA_ZONE_HOST_AWARE;
1790600fd98fSKenneth D. Merry else if (((cgd->ident_data.support3 & ATA_SUPPORT_ZONE_MASK) ==
17919a6844d5SKenneth D. Merry ATA_SUPPORT_ZONE_DEV_MANAGED)
1792600fd98fSKenneth D. Merry || (softc->quirks & ADA_Q_SMR_DM))
17939a6844d5SKenneth D. Merry softc->zone_mode = ADA_ZONE_DRIVE_MANAGED;
17949a6844d5SKenneth D. Merry else
17959a6844d5SKenneth D. Merry softc->zone_mode = ADA_ZONE_NONE;
17969a6844d5SKenneth D. Merry
17979a6844d5SKenneth D. Merry if (cgd->ident_data.support.command1 & ATA_SUPPORT_LOOKAHEAD)
17989a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_RAHEAD;
17999a6844d5SKenneth D. Merry else
18009a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_RAHEAD;
18019a6844d5SKenneth D. Merry
18029a6844d5SKenneth D. Merry if (cgd->ident_data.support.command1 & ATA_SUPPORT_WRITECACHE)
18039a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_WCACHE;
18049a6844d5SKenneth D. Merry else
18059a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_WCACHE;
18069a6844d5SKenneth D. Merry }
18079a6844d5SKenneth D. Merry
180852c9ce25SScott Long static cam_status
adaregister(struct cam_periph * periph,void * arg)180952c9ce25SScott Long adaregister(struct cam_periph *periph, void *arg)
181052c9ce25SScott Long {
181152c9ce25SScott Long struct ada_softc *softc;
181252c9ce25SScott Long struct ccb_getdev *cgd;
181352c9ce25SScott Long struct disk_params *dp;
18145d01277fSScott Long struct sbuf sb;
18155d01277fSScott Long char *announce_buf;
181652c9ce25SScott Long caddr_t match;
18174a3760baSAlexander Motin int quirks;
181852c9ce25SScott Long
181952c9ce25SScott Long cgd = (struct ccb_getdev *)arg;
182052c9ce25SScott Long if (cgd == NULL) {
182152c9ce25SScott Long printf("adaregister: no getdev CCB, can't register device\n");
182252c9ce25SScott Long return(CAM_REQ_CMP_ERR);
182352c9ce25SScott Long }
182452c9ce25SScott Long
182552c9ce25SScott Long softc = (struct ada_softc *)malloc(sizeof(*softc), M_DEVBUF,
182652c9ce25SScott Long M_NOWAIT|M_ZERO);
182752c9ce25SScott Long
182852c9ce25SScott Long if (softc == NULL) {
182952c9ce25SScott Long printf("adaregister: Unable to probe new device. "
183052c9ce25SScott Long "Unable to allocate softc\n");
183152c9ce25SScott Long return(CAM_REQ_CMP_ERR);
183252c9ce25SScott Long }
183352c9ce25SScott Long
18345d01277fSScott Long announce_buf = softc->announce_temp;
18355d01277fSScott Long bzero(announce_buf, ADA_ANNOUNCETMP_SZ);
18365d01277fSScott Long
183752c9ce25SScott Long periph->softc = softc;
183876d843daSAlexander Motin xpt_path_inq(&softc->cpi, periph->path);
183952c9ce25SScott Long
184052c9ce25SScott Long /*
184152c9ce25SScott Long * See if this device has any quirks.
184252c9ce25SScott Long */
184330a4094fSAlexander Motin match = cam_quirkmatch((caddr_t)&cgd->ident_data,
184430a4094fSAlexander Motin (caddr_t)ada_quirk_table,
1845323b076eSPedro F. Giffuni nitems(ada_quirk_table),
184630a4094fSAlexander Motin sizeof(*ada_quirk_table), ata_identify_match);
184752c9ce25SScott Long if (match != NULL)
184852c9ce25SScott Long softc->quirks = ((struct ada_quirk_entry *)match)->quirks;
184952c9ce25SScott Long else
185052c9ce25SScott Long softc->quirks = ADA_Q_NONE;
185152c9ce25SScott Long
185252c9ce25SScott Long TASK_INIT(&softc->sysctl_task, 0, adasysctlinit, periph);
185352c9ce25SScott Long
185452c9ce25SScott Long /*
185590bcc81bSAlexander Motin * Take a reference on the periph while adastart is called to finish
185690bcc81bSAlexander Motin * the probe. The reference will be dropped in adaprobedone at the
185790bcc81bSAlexander Motin * end of probe.
185852c9ce25SScott Long */
185990bcc81bSAlexander Motin (void)cam_periph_acquire(periph);
1860edec59d9SAlexander Motin cam_periph_unlock(periph);
18615d01277fSScott Long snprintf(announce_buf, ADA_ANNOUNCETMP_SZ,
1862d3a460d3SAlexander Motin "kern.cam.ada.%d.quirks", periph->unit_number);
1863d3a460d3SAlexander Motin quirks = softc->quirks;
1864d3a460d3SAlexander Motin TUNABLE_INT_FETCH(announce_buf, &quirks);
1865d3a460d3SAlexander Motin softc->quirks = quirks;
18661ed6aaf9SAlexander Motin softc->read_ahead = -1;
18675d01277fSScott Long snprintf(announce_buf, ADA_ANNOUNCETMP_SZ,
18681ed6aaf9SAlexander Motin "kern.cam.ada.%d.read_ahead", periph->unit_number);
18691ed6aaf9SAlexander Motin TUNABLE_INT_FETCH(announce_buf, &softc->read_ahead);
1870781338b6SAlexander Motin softc->write_cache = -1;
18715d01277fSScott Long snprintf(announce_buf, ADA_ANNOUNCETMP_SZ,
1872781338b6SAlexander Motin "kern.cam.ada.%d.write_cache", periph->unit_number);
1873781338b6SAlexander Motin TUNABLE_INT_FETCH(announce_buf, &softc->write_cache);
18743f54ec85SKenneth D. Merry
18753f54ec85SKenneth D. Merry /*
18763394d423SEdward Tomasz Napierala * Let XPT know we can use UMA-allocated CCBs.
18773394d423SEdward Tomasz Napierala */
18783394d423SEdward Tomasz Napierala if (ada_enable_uma_ccbs) {
18793394d423SEdward Tomasz Napierala KASSERT(ada_ccb_zone != NULL,
18803394d423SEdward Tomasz Napierala ("%s: NULL ada_ccb_zone", __func__));
18813394d423SEdward Tomasz Napierala periph->ccb_zone = ada_ccb_zone;
18823394d423SEdward Tomasz Napierala }
18833394d423SEdward Tomasz Napierala
18843394d423SEdward Tomasz Napierala /*
18853f54ec85SKenneth D. Merry * Set support flags based on the Identify data and quirks.
18863f54ec85SKenneth D. Merry */
18873f54ec85SKenneth D. Merry adasetflags(softc, cgd);
188876d843daSAlexander Motin if (softc->cpi.hba_misc & PIM_ATA_EXT)
188976d843daSAlexander Motin softc->flags |= ADA_FLAG_PIM_ATA_EXT;
18903f54ec85SKenneth D. Merry
189162cc3a63SSteven Hartland /* Disable queue sorting for non-rotational media by default. */
1892a6e0c5daSWarner Losh if (cgd->ident_data.media_rotation_rate == ATA_RATE_NON_ROTATING) {
189396eb32bfSWarner Losh softc->flags &= ~ADA_FLAG_ROTATING;
1894a6e0c5daSWarner Losh } else {
189596eb32bfSWarner Losh softc->flags |= ADA_FLAG_ROTATING;
1896a6e0c5daSWarner Losh }
189752c9ce25SScott Long softc->disk = disk_alloc();
189876d843daSAlexander Motin adasetgeom(softc, cgd);
1899b8b6b5d3SAlexander Motin softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
1900b8b6b5d3SAlexander Motin periph->unit_number, softc->params.secsize,
1901b8b6b5d3SAlexander Motin DEVSTAT_ALL_SUPPORTED,
1902b8b6b5d3SAlexander Motin DEVSTAT_TYPE_DIRECT |
190376d843daSAlexander Motin XPORT_DEVSTAT_TYPE(softc->cpi.transport),
1904b8b6b5d3SAlexander Motin DEVSTAT_PRIORITY_DISK);
190552c9ce25SScott Long softc->disk->d_open = adaopen;
190652c9ce25SScott Long softc->disk->d_close = adaclose;
190752c9ce25SScott Long softc->disk->d_strategy = adastrategy;
1908416494d7SJustin T. Gibbs softc->disk->d_getattr = adagetattr;
1909e07ac3f2SJohn Baldwin if (cam_sim_pollable(periph->sim))
191052c9ce25SScott Long softc->disk->d_dump = adadump;
19110ba1e4d0SKenneth D. Merry softc->disk->d_gone = adadiskgonecb;
191252c9ce25SScott Long softc->disk->d_name = "ada";
191352c9ce25SScott Long softc->disk->d_drv1 = periph;
191452c9ce25SScott Long softc->disk->d_unit = periph->unit_number;
19156f1dd607SWarner Losh
1916*9cbf3d61SWarner Losh if (cam_iosched_init(&softc->cam_iosched, periph, softc->disk,
1917*9cbf3d61SWarner Losh adaschedule) != 0) {
19186f1dd607SWarner Losh printf("adaregister: Unable to probe new device. "
19196f1dd607SWarner Losh "Unable to allocate iosched memory\n");
19206f1dd607SWarner Losh free(softc, M_DEVBUF);
19216f1dd607SWarner Losh return(CAM_REQ_CMP_ERR);
19226f1dd607SWarner Losh }
19236f1dd607SWarner Losh cam_iosched_set_sort_queue(softc->cam_iosched,
19246f1dd607SWarner Losh (softc->flags & ADA_FLAG_ROTATING) ? -1 : 0);
19256f1dd607SWarner Losh
1926edec59d9SAlexander Motin cam_periph_lock(periph);
192752c9ce25SScott Long
192852c9ce25SScott Long dp = &softc->params;
19295d01277fSScott Long snprintf(announce_buf, ADA_ANNOUNCETMP_SZ,
193068546995SAlexander Motin "%juMB (%ju %u byte sectors)",
193168546995SAlexander Motin ((uintmax_t)dp->secsize * dp->sectors) / (1024 * 1024),
193268546995SAlexander Motin (uintmax_t)dp->sectors, dp->secsize);
19335d01277fSScott Long
19345d01277fSScott Long sbuf_new(&sb, softc->announce_buffer, ADA_ANNOUNCE_SZ, SBUF_FIXEDLEN);
19355d01277fSScott Long xpt_announce_periph_sbuf(periph, &sb, announce_buf);
19365d01277fSScott Long xpt_announce_quirks_sbuf(periph, &sb, softc->quirks, ADA_Q_BIT_STRING);
19375d01277fSScott Long sbuf_finish(&sb);
19385d01277fSScott Long sbuf_putbuf(&sb);
1939e3a6d3a4SAlexander Motin
1940e3a6d3a4SAlexander Motin /*
1941e3a6d3a4SAlexander Motin * Create our sysctl variables, now that we know
1942e3a6d3a4SAlexander Motin * we have successfully attached.
1943e3a6d3a4SAlexander Motin */
194499e7a4adSScott Long if (cam_periph_acquire(periph) == 0)
1945e3a6d3a4SAlexander Motin taskqueue_enqueue(taskqueue_thread, &softc->sysctl_task);
1946e3a6d3a4SAlexander Motin
194752c9ce25SScott Long /*
194852c9ce25SScott Long * Add async callbacks for bus reset and
194952c9ce25SScott Long * bus device reset calls. I don't bother
195052c9ce25SScott Long * checking if this fails as, in most cases,
195152c9ce25SScott Long * the system will function just fine without
195252c9ce25SScott Long * them and the only alternative would be to
195352c9ce25SScott Long * not attach the device on failure.
195452c9ce25SScott Long */
19553089bb2eSAlexander Motin xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
1956581b2e78SAlexander Motin AC_GETDEV_CHANGED | AC_ADVINFO_CHANGED,
1957581b2e78SAlexander Motin adaasync, periph, periph->path);
195852c9ce25SScott Long
195952c9ce25SScott Long /*
196052c9ce25SScott Long * Schedule a periodic event to occasionally send an
196152c9ce25SScott Long * ordered tag to a device.
196252c9ce25SScott Long */
1963227d67aaSAlexander Motin callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
19640e5c50bfSAlexander Motin callout_reset_sbt(&softc->sendordered_c,
19650e5c50bfSAlexander Motin SBT_1S / ADA_ORDEREDTAG_INTERVAL * ada_default_timeout, 0,
19660e5c50bfSAlexander Motin adasendorderedtag, softc, C_PREL(1));
196752c9ce25SScott Long
196890bcc81bSAlexander Motin /* Released after probe when disk_create() call pass it to GEOM. */
196990bcc81bSAlexander Motin cam_periph_hold_boot(periph);
197090bcc81bSAlexander Motin
19719a6844d5SKenneth D. Merry if (ADA_RA >= 0 && softc->flags & ADA_FLAG_CAN_RAHEAD) {
19721ed6aaf9SAlexander Motin softc->state = ADA_STATE_RAHEAD;
19739a6844d5SKenneth D. Merry } else if (ADA_WC >= 0 && softc->flags & ADA_FLAG_CAN_WCACHE) {
1974f513d14cSAlexander Motin softc->state = ADA_STATE_WCACHE;
1975600fd98fSKenneth D. Merry } else if ((softc->flags & ADA_FLAG_CAN_LOG)
1976600fd98fSKenneth D. Merry && (softc->zone_mode != ADA_ZONE_NONE)) {
19779a6844d5SKenneth D. Merry softc->state = ADA_STATE_LOGDIR;
1978227d67aaSAlexander Motin } else {
19799a6844d5SKenneth D. Merry /*
19809a6844d5SKenneth D. Merry * Nothing to probe, so we can just transition to the
19819a6844d5SKenneth D. Merry * normal state.
19829a6844d5SKenneth D. Merry */
19839a6844d5SKenneth D. Merry adaprobedone(periph, NULL);
1984227d67aaSAlexander Motin return(CAM_REQ_CMP);
1985227d67aaSAlexander Motin }
19869a6844d5SKenneth D. Merry
1987227d67aaSAlexander Motin xpt_schedule(periph, CAM_PRIORITY_DEV);
198852c9ce25SScott Long return(CAM_REQ_CMP);
198952c9ce25SScott Long }
199052c9ce25SScott Long
1991a6e0c5daSWarner Losh static int
ada_dsmtrim_req_create(struct ada_softc * softc,struct bio * bp,struct trim_request * req)1992a6e0c5daSWarner Losh ada_dsmtrim_req_create(struct ada_softc *softc, struct bio *bp, struct trim_request *req)
199352c9ce25SScott Long {
1994ea657f2cSWarner Losh uint64_t lastlba = (uint64_t)-1, lbas = 0;
19952030b294SAlexander Motin int c, lastcount = 0, off, ranges = 0;
199652c9ce25SScott Long
19971c80ec0aSAlexander Motin bzero(req, sizeof(*req));
19982030b294SAlexander Motin TAILQ_INIT(&req->bps);
19991c80ec0aSAlexander Motin do {
20007ddad071SWarner Losh uint64_t lba = bp->bio_pblkno;
20017ddad071SWarner Losh int count = bp->bio_bcount / softc->params.secsize;
20021c80ec0aSAlexander Motin
200337ddbd16SAlexander Motin /* Try to extend the previous range. */
200437ddbd16SAlexander Motin if (lba == lastlba) {
2005c213c551SSteven Hartland c = min(count, ATA_DSM_RANGE_MAX - lastcount);
200637ddbd16SAlexander Motin lastcount += c;
2007c213c551SSteven Hartland off = (ranges - 1) * ATA_DSM_RANGE_SIZE;
200837ddbd16SAlexander Motin req->data[off + 6] = lastcount & 0xff;
200937ddbd16SAlexander Motin req->data[off + 7] =
201037ddbd16SAlexander Motin (lastcount >> 8) & 0xff;
201137ddbd16SAlexander Motin count -= c;
201237ddbd16SAlexander Motin lba += c;
2013ea657f2cSWarner Losh lbas += c;
201437ddbd16SAlexander Motin }
201537ddbd16SAlexander Motin
201637ddbd16SAlexander Motin while (count > 0) {
2017c213c551SSteven Hartland c = min(count, ATA_DSM_RANGE_MAX);
2018c213c551SSteven Hartland off = ranges * ATA_DSM_RANGE_SIZE;
20191c80ec0aSAlexander Motin req->data[off + 0] = lba & 0xff;
20201c80ec0aSAlexander Motin req->data[off + 1] = (lba >> 8) & 0xff;
20211c80ec0aSAlexander Motin req->data[off + 2] = (lba >> 16) & 0xff;
20221c80ec0aSAlexander Motin req->data[off + 3] = (lba >> 24) & 0xff;
20231c80ec0aSAlexander Motin req->data[off + 4] = (lba >> 32) & 0xff;
20241c80ec0aSAlexander Motin req->data[off + 5] = (lba >> 40) & 0xff;
20251c80ec0aSAlexander Motin req->data[off + 6] = c & 0xff;
20261c80ec0aSAlexander Motin req->data[off + 7] = (c >> 8) & 0xff;
20271c80ec0aSAlexander Motin lba += c;
2028ea657f2cSWarner Losh lbas += c;
20291c80ec0aSAlexander Motin count -= c;
203037ddbd16SAlexander Motin lastcount = c;
20311c80ec0aSAlexander Motin ranges++;
2032c213c551SSteven Hartland /*
2033c213c551SSteven Hartland * Its the caller's responsibility to ensure the
2034c213c551SSteven Hartland * request will fit so we don't need to check for
2035c213c551SSteven Hartland * overrun here
2036c213c551SSteven Hartland */
20371c80ec0aSAlexander Motin }
203837ddbd16SAlexander Motin lastlba = lba;
20397ddad071SWarner Losh TAILQ_INSERT_TAIL(&req->bps, bp, bio_queue);
2040a6e0c5daSWarner Losh
2041a6e0c5daSWarner Losh bp = cam_iosched_next_trim(softc->cam_iosched);
2042a6e0c5daSWarner Losh if (bp == NULL)
20431c80ec0aSAlexander Motin break;
2044a6e0c5daSWarner Losh if (bp->bio_bcount / softc->params.secsize >
2045a6e0c5daSWarner Losh (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) {
2046a6e0c5daSWarner Losh cam_iosched_put_back_trim(softc->cam_iosched, bp);
2047a6e0c5daSWarner Losh break;
2048a6e0c5daSWarner Losh }
20491c80ec0aSAlexander Motin } while (1);
2050ea657f2cSWarner Losh softc->trim_count++;
2051ea657f2cSWarner Losh softc->trim_ranges += ranges;
2052ea657f2cSWarner Losh softc->trim_lbas += lbas;
2053a6e0c5daSWarner Losh
2054a6e0c5daSWarner Losh return (ranges);
2055a6e0c5daSWarner Losh }
2056a6e0c5daSWarner Losh
2057a6e0c5daSWarner Losh static void
ada_dsmtrim(struct ada_softc * softc,struct bio * bp,struct ccb_ataio * ataio)2058a6e0c5daSWarner Losh ada_dsmtrim(struct ada_softc *softc, struct bio *bp, struct ccb_ataio *ataio)
2059a6e0c5daSWarner Losh {
2060a6e0c5daSWarner Losh struct trim_request *req = &softc->trim_req;
2061a6e0c5daSWarner Losh int ranges;
2062a6e0c5daSWarner Losh
2063a6e0c5daSWarner Losh ranges = ada_dsmtrim_req_create(softc, bp, req);
20641c80ec0aSAlexander Motin cam_fill_ataio(ataio,
20651c80ec0aSAlexander Motin ada_retry_count,
20661c80ec0aSAlexander Motin adadone,
20671c80ec0aSAlexander Motin CAM_DIR_OUT,
20681c80ec0aSAlexander Motin 0,
20691c80ec0aSAlexander Motin req->data,
207055e0987aSPedro F. Giffuni howmany(ranges, ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
20711c80ec0aSAlexander Motin ada_default_timeout * 1000);
20721c80ec0aSAlexander Motin ata_48bit_cmd(ataio, ATA_DATA_SET_MANAGEMENT,
207355e0987aSPedro F. Giffuni ATA_DSM_TRIM, 0, howmany(ranges, ATA_DSM_BLK_RANGES));
20747ddad071SWarner Losh }
20757ddad071SWarner Losh
20767ddad071SWarner Losh static void
ada_ncq_dsmtrim(struct ada_softc * softc,struct bio * bp,struct ccb_ataio * ataio)2077a6e0c5daSWarner Losh ada_ncq_dsmtrim(struct ada_softc *softc, struct bio *bp, struct ccb_ataio *ataio)
2078a6e0c5daSWarner Losh {
2079a6e0c5daSWarner Losh struct trim_request *req = &softc->trim_req;
2080a6e0c5daSWarner Losh int ranges;
2081a6e0c5daSWarner Losh
2082a6e0c5daSWarner Losh ranges = ada_dsmtrim_req_create(softc, bp, req);
2083a6e0c5daSWarner Losh cam_fill_ataio(ataio,
2084a6e0c5daSWarner Losh ada_retry_count,
2085a6e0c5daSWarner Losh adadone,
2086a6e0c5daSWarner Losh CAM_DIR_OUT,
2087a6e0c5daSWarner Losh 0,
2088a6e0c5daSWarner Losh req->data,
208955e0987aSPedro F. Giffuni howmany(ranges, ATA_DSM_BLK_RANGES) * ATA_DSM_BLK_SIZE,
2090a6e0c5daSWarner Losh ada_default_timeout * 1000);
2091a6e0c5daSWarner Losh ata_ncq_cmd(ataio,
2092a6e0c5daSWarner Losh ATA_SEND_FPDMA_QUEUED,
2093a6e0c5daSWarner Losh 0,
209455e0987aSPedro F. Giffuni howmany(ranges, ATA_DSM_BLK_RANGES));
2095a6e0c5daSWarner Losh ataio->cmd.sector_count_exp = ATA_SFPDMA_DSM;
2096916d57dfSWarner Losh ataio->ata_flags |= ATA_FLAG_AUX;
2097916d57dfSWarner Losh ataio->aux = 1;
2098a6e0c5daSWarner Losh }
2099a6e0c5daSWarner Losh
2100a6e0c5daSWarner Losh static void
ada_cfaerase(struct ada_softc * softc,struct bio * bp,struct ccb_ataio * ataio)21017ddad071SWarner Losh ada_cfaerase(struct ada_softc *softc, struct bio *bp, struct ccb_ataio *ataio)
21027ddad071SWarner Losh {
2103467298f5SSteven Hartland struct trim_request *req = &softc->trim_req;
21047ddad071SWarner Losh uint64_t lba = bp->bio_pblkno;
21057ddad071SWarner Losh uint16_t count = bp->bio_bcount / softc->params.secsize;
21067ddad071SWarner Losh
2107467298f5SSteven Hartland bzero(req, sizeof(*req));
2108467298f5SSteven Hartland TAILQ_INIT(&req->bps);
2109467298f5SSteven Hartland TAILQ_INSERT_TAIL(&req->bps, bp, bio_queue);
2110467298f5SSteven Hartland
21117ddad071SWarner Losh cam_fill_ataio(ataio,
21127ddad071SWarner Losh ada_retry_count,
21137ddad071SWarner Losh adadone,
21147ddad071SWarner Losh CAM_DIR_NONE,
21157ddad071SWarner Losh 0,
21167ddad071SWarner Losh NULL,
21177ddad071SWarner Losh 0,
21187ddad071SWarner Losh ada_default_timeout*1000);
21197ddad071SWarner Losh
21207ddad071SWarner Losh if (count >= 256)
21217ddad071SWarner Losh count = 0;
21227ddad071SWarner Losh ata_28bit_cmd(ataio, ATA_CFA_ERASE, 0, lba, count);
21237ddad071SWarner Losh }
21247ddad071SWarner Losh
21259a6844d5SKenneth D. Merry static int
ada_zone_bio_to_ata(int disk_zone_cmd)21269a6844d5SKenneth D. Merry ada_zone_bio_to_ata(int disk_zone_cmd)
21279a6844d5SKenneth D. Merry {
21289a6844d5SKenneth D. Merry switch (disk_zone_cmd) {
21299a6844d5SKenneth D. Merry case DISK_ZONE_OPEN:
21309a6844d5SKenneth D. Merry return ATA_ZM_OPEN_ZONE;
21319a6844d5SKenneth D. Merry case DISK_ZONE_CLOSE:
21329a6844d5SKenneth D. Merry return ATA_ZM_CLOSE_ZONE;
21339a6844d5SKenneth D. Merry case DISK_ZONE_FINISH:
21349a6844d5SKenneth D. Merry return ATA_ZM_FINISH_ZONE;
21359a6844d5SKenneth D. Merry case DISK_ZONE_RWP:
21369a6844d5SKenneth D. Merry return ATA_ZM_RWP;
21379a6844d5SKenneth D. Merry }
21389a6844d5SKenneth D. Merry
21399a6844d5SKenneth D. Merry return -1;
21409a6844d5SKenneth D. Merry }
21419a6844d5SKenneth D. Merry
21429a6844d5SKenneth D. Merry static int
ada_zone_cmd(struct cam_periph * periph,union ccb * ccb,struct bio * bp,int * queue_ccb)21439a6844d5SKenneth D. Merry ada_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp,
21449a6844d5SKenneth D. Merry int *queue_ccb)
21459a6844d5SKenneth D. Merry {
21469a6844d5SKenneth D. Merry struct ada_softc *softc;
21479a6844d5SKenneth D. Merry int error;
21489a6844d5SKenneth D. Merry
21499a6844d5SKenneth D. Merry error = 0;
21509a6844d5SKenneth D. Merry
21519a6844d5SKenneth D. Merry if (bp->bio_cmd != BIO_ZONE) {
21529a6844d5SKenneth D. Merry error = EINVAL;
21539a6844d5SKenneth D. Merry goto bailout;
21549a6844d5SKenneth D. Merry }
21559a6844d5SKenneth D. Merry
21569a6844d5SKenneth D. Merry softc = periph->softc;
21579a6844d5SKenneth D. Merry
21589a6844d5SKenneth D. Merry switch (bp->bio_zone.zone_cmd) {
21599a6844d5SKenneth D. Merry case DISK_ZONE_OPEN:
21609a6844d5SKenneth D. Merry case DISK_ZONE_CLOSE:
21619a6844d5SKenneth D. Merry case DISK_ZONE_FINISH:
21629a6844d5SKenneth D. Merry case DISK_ZONE_RWP: {
21639a6844d5SKenneth D. Merry int zone_flags;
21649a6844d5SKenneth D. Merry int zone_sa;
21659a6844d5SKenneth D. Merry uint64_t lba;
21669a6844d5SKenneth D. Merry
21679a6844d5SKenneth D. Merry zone_sa = ada_zone_bio_to_ata(bp->bio_zone.zone_cmd);
21689a6844d5SKenneth D. Merry if (zone_sa == -1) {
21699a6844d5SKenneth D. Merry xpt_print(periph->path, "Cannot translate zone "
21709a6844d5SKenneth D. Merry "cmd %#x to ATA\n", bp->bio_zone.zone_cmd);
21719a6844d5SKenneth D. Merry error = EINVAL;
21729a6844d5SKenneth D. Merry goto bailout;
21739a6844d5SKenneth D. Merry }
21749a6844d5SKenneth D. Merry
21759a6844d5SKenneth D. Merry zone_flags = 0;
21769a6844d5SKenneth D. Merry lba = bp->bio_zone.zone_params.rwp.id;
21779a6844d5SKenneth D. Merry
21789a6844d5SKenneth D. Merry if (bp->bio_zone.zone_params.rwp.flags &
21799a6844d5SKenneth D. Merry DISK_ZONE_RWP_FLAG_ALL)
21809a6844d5SKenneth D. Merry zone_flags |= ZBC_OUT_ALL;
21819a6844d5SKenneth D. Merry
21829a6844d5SKenneth D. Merry ata_zac_mgmt_out(&ccb->ataio,
21839a6844d5SKenneth D. Merry /*retries*/ ada_retry_count,
21849a6844d5SKenneth D. Merry /*cbfcnp*/ adadone,
21859a6844d5SKenneth D. Merry /*use_ncq*/ (softc->flags &
21869a6844d5SKenneth D. Merry ADA_FLAG_PIM_ATA_EXT) ? 1 : 0,
21879a6844d5SKenneth D. Merry /*zm_action*/ zone_sa,
21889a6844d5SKenneth D. Merry /*zone_id*/ lba,
21899a6844d5SKenneth D. Merry /*zone_flags*/ zone_flags,
21909a6844d5SKenneth D. Merry /*sector_count*/ 0,
21919a6844d5SKenneth D. Merry /*data_ptr*/ NULL,
21929a6844d5SKenneth D. Merry /*dxfer_len*/ 0,
21939a6844d5SKenneth D. Merry /*timeout*/ ada_default_timeout * 1000);
21949a6844d5SKenneth D. Merry *queue_ccb = 1;
21959a6844d5SKenneth D. Merry
21969a6844d5SKenneth D. Merry break;
21979a6844d5SKenneth D. Merry }
21989a6844d5SKenneth D. Merry case DISK_ZONE_REPORT_ZONES: {
21999a6844d5SKenneth D. Merry uint8_t *rz_ptr;
22009a6844d5SKenneth D. Merry uint32_t num_entries, alloc_size;
22019a6844d5SKenneth D. Merry struct disk_zone_report *rep;
22029a6844d5SKenneth D. Merry
22039a6844d5SKenneth D. Merry rep = &bp->bio_zone.zone_params.report;
22049a6844d5SKenneth D. Merry
22059a6844d5SKenneth D. Merry num_entries = rep->entries_allocated;
22069a6844d5SKenneth D. Merry if (num_entries == 0) {
22079a6844d5SKenneth D. Merry xpt_print(periph->path, "No entries allocated for "
22089a6844d5SKenneth D. Merry "Report Zones request\n");
22099a6844d5SKenneth D. Merry error = EINVAL;
22109a6844d5SKenneth D. Merry goto bailout;
22119a6844d5SKenneth D. Merry }
22129a6844d5SKenneth D. Merry alloc_size = sizeof(struct scsi_report_zones_hdr) +
22139a6844d5SKenneth D. Merry (sizeof(struct scsi_report_zones_desc) * num_entries);
22149a6844d5SKenneth D. Merry alloc_size = min(alloc_size, softc->disk->d_maxsize);
22159a6844d5SKenneth D. Merry rz_ptr = malloc(alloc_size, M_ATADA, M_NOWAIT | M_ZERO);
22169a6844d5SKenneth D. Merry if (rz_ptr == NULL) {
22179a6844d5SKenneth D. Merry xpt_print(periph->path, "Unable to allocate memory "
22189a6844d5SKenneth D. Merry "for Report Zones request\n");
22199a6844d5SKenneth D. Merry error = ENOMEM;
22209a6844d5SKenneth D. Merry goto bailout;
22219a6844d5SKenneth D. Merry }
22229a6844d5SKenneth D. Merry
22239a6844d5SKenneth D. Merry ata_zac_mgmt_in(&ccb->ataio,
22249a6844d5SKenneth D. Merry /*retries*/ ada_retry_count,
22259a6844d5SKenneth D. Merry /*cbcfnp*/ adadone,
22269a6844d5SKenneth D. Merry /*use_ncq*/ (softc->flags &
22279a6844d5SKenneth D. Merry ADA_FLAG_PIM_ATA_EXT) ? 1 : 0,
22289a6844d5SKenneth D. Merry /*zm_action*/ ATA_ZM_REPORT_ZONES,
22299a6844d5SKenneth D. Merry /*zone_id*/ rep->starting_id,
22309a6844d5SKenneth D. Merry /*zone_flags*/ rep->rep_options,
22319a6844d5SKenneth D. Merry /*data_ptr*/ rz_ptr,
22329a6844d5SKenneth D. Merry /*dxfer_len*/ alloc_size,
22339a6844d5SKenneth D. Merry /*timeout*/ ada_default_timeout * 1000);
22349a6844d5SKenneth D. Merry
22359a6844d5SKenneth D. Merry /*
22369a6844d5SKenneth D. Merry * For BIO_ZONE, this isn't normally needed. However, it
22379a6844d5SKenneth D. Merry * is used by devstat_end_transaction_bio() to determine
22389a6844d5SKenneth D. Merry * how much data was transferred.
22399a6844d5SKenneth D. Merry */
22409a6844d5SKenneth D. Merry /*
22419a6844d5SKenneth D. Merry * XXX KDM we have a problem. But I'm not sure how to fix
22429a6844d5SKenneth D. Merry * it. devstat uses bio_bcount - bio_resid to calculate
22439a6844d5SKenneth D. Merry * the amount of data transferred. The GEOM disk code
22449a6844d5SKenneth D. Merry * uses bio_length - bio_resid to calculate the amount of
22459a6844d5SKenneth D. Merry * data in bio_completed. We have different structure
22469a6844d5SKenneth D. Merry * sizes above and below the ada(4) driver. So, if we
22479a6844d5SKenneth D. Merry * use the sizes above, the amount transferred won't be
22489a6844d5SKenneth D. Merry * quite accurate for devstat. If we use different sizes
22499a6844d5SKenneth D. Merry * for bio_bcount and bio_length (above and below
22509a6844d5SKenneth D. Merry * respectively), then the residual needs to match one or
22519a6844d5SKenneth D. Merry * the other. Everything is calculated after the bio
22529a6844d5SKenneth D. Merry * leaves the driver, so changing the values around isn't
22539a6844d5SKenneth D. Merry * really an option. For now, just set the count to the
22549a6844d5SKenneth D. Merry * passed in length. This means that the calculations
22559a6844d5SKenneth D. Merry * above (e.g. bio_completed) will be correct, but the
22569a6844d5SKenneth D. Merry * amount of data reported to devstat will be slightly
22579a6844d5SKenneth D. Merry * under or overstated.
22589a6844d5SKenneth D. Merry */
22599a6844d5SKenneth D. Merry bp->bio_bcount = bp->bio_length;
22609a6844d5SKenneth D. Merry
22619a6844d5SKenneth D. Merry *queue_ccb = 1;
22629a6844d5SKenneth D. Merry
22639a6844d5SKenneth D. Merry break;
22649a6844d5SKenneth D. Merry }
22659a6844d5SKenneth D. Merry case DISK_ZONE_GET_PARAMS: {
22669a6844d5SKenneth D. Merry struct disk_zone_disk_params *params;
22679a6844d5SKenneth D. Merry
22689a6844d5SKenneth D. Merry params = &bp->bio_zone.zone_params.disk_params;
22699a6844d5SKenneth D. Merry bzero(params, sizeof(*params));
22709a6844d5SKenneth D. Merry
22719a6844d5SKenneth D. Merry switch (softc->zone_mode) {
22729a6844d5SKenneth D. Merry case ADA_ZONE_DRIVE_MANAGED:
22739a6844d5SKenneth D. Merry params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED;
22749a6844d5SKenneth D. Merry break;
22759a6844d5SKenneth D. Merry case ADA_ZONE_HOST_AWARE:
22769a6844d5SKenneth D. Merry params->zone_mode = DISK_ZONE_MODE_HOST_AWARE;
22779a6844d5SKenneth D. Merry break;
22789a6844d5SKenneth D. Merry case ADA_ZONE_HOST_MANAGED:
22799a6844d5SKenneth D. Merry params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED;
22809a6844d5SKenneth D. Merry break;
22819a6844d5SKenneth D. Merry default:
22829a6844d5SKenneth D. Merry case ADA_ZONE_NONE:
22839a6844d5SKenneth D. Merry params->zone_mode = DISK_ZONE_MODE_NONE;
22849a6844d5SKenneth D. Merry break;
22859a6844d5SKenneth D. Merry }
22869a6844d5SKenneth D. Merry
22879a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_URSWRZ)
22889a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_DISK_URSWRZ;
22899a6844d5SKenneth D. Merry
22909a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_OPT_SEQ_SET) {
22919a6844d5SKenneth D. Merry params->optimal_seq_zones = softc->optimal_seq_zones;
22929a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_OPT_SEQ_SET;
22939a6844d5SKenneth D. Merry }
22949a6844d5SKenneth D. Merry
22959a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_OPT_NONSEQ_SET) {
22969a6844d5SKenneth D. Merry params->optimal_nonseq_zones =
22979a6844d5SKenneth D. Merry softc->optimal_nonseq_zones;
22989a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_OPT_NONSEQ_SET;
22999a6844d5SKenneth D. Merry }
23009a6844d5SKenneth D. Merry
23019a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_MAX_SEQ_SET) {
23029a6844d5SKenneth D. Merry params->max_seq_zones = softc->max_seq_zones;
23039a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_MAX_SEQ_SET;
23049a6844d5SKenneth D. Merry }
23059a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_RZ_SUP)
23069a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_RZ_SUP;
23079a6844d5SKenneth D. Merry
23089a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_OPEN_SUP)
23099a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_OPEN_SUP;
23109a6844d5SKenneth D. Merry
23119a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_CLOSE_SUP)
23129a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_CLOSE_SUP;
23139a6844d5SKenneth D. Merry
23149a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_FINISH_SUP)
23159a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_FINISH_SUP;
23169a6844d5SKenneth D. Merry
23179a6844d5SKenneth D. Merry if (softc->zone_flags & ADA_ZONE_FLAG_RWP_SUP)
23189a6844d5SKenneth D. Merry params->flags |= DISK_ZONE_RWP_SUP;
23199a6844d5SKenneth D. Merry break;
23209a6844d5SKenneth D. Merry }
23219a6844d5SKenneth D. Merry default:
23229a6844d5SKenneth D. Merry break;
23239a6844d5SKenneth D. Merry }
23249a6844d5SKenneth D. Merry bailout:
23259a6844d5SKenneth D. Merry return (error);
23269a6844d5SKenneth D. Merry }
23279a6844d5SKenneth D. Merry
23287ddad071SWarner Losh static void
adastart(struct cam_periph * periph,union ccb * start_ccb)23297ddad071SWarner Losh adastart(struct cam_periph *periph, union ccb *start_ccb)
23307ddad071SWarner Losh {
23317ddad071SWarner Losh struct ada_softc *softc = (struct ada_softc *)periph->softc;
23327ddad071SWarner Losh struct ccb_ataio *ataio = &start_ccb->ataio;
23337ddad071SWarner Losh
23347ddad071SWarner Losh CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("adastart\n"));
23357ddad071SWarner Losh
23367ddad071SWarner Losh switch (softc->state) {
23377ddad071SWarner Losh case ADA_STATE_NORMAL:
23387ddad071SWarner Losh {
23397ddad071SWarner Losh struct bio *bp;
23409db2db6bSWarner Losh uint8_t tag_code;
23417ddad071SWarner Losh
2342a6e0c5daSWarner Losh bp = cam_iosched_next_bio(softc->cam_iosched);
23431c80ec0aSAlexander Motin if (bp == NULL) {
23441c80ec0aSAlexander Motin xpt_release_ccb(start_ccb);
23451c80ec0aSAlexander Motin break;
23461c80ec0aSAlexander Motin }
234752c9ce25SScott Long
2348a6e0c5daSWarner Losh if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2349a6e0c5daSWarner Losh (bp->bio_cmd != BIO_DELETE && (softc->flags & ADA_FLAG_NEED_OTAG) != 0)) {
235052c9ce25SScott Long softc->flags &= ~ADA_FLAG_NEED_OTAG;
2351030844d1SAlexander Motin softc->flags |= ADA_FLAG_WAS_OTAG;
235246f118feSAlexander Motin tag_code = 0;
235352c9ce25SScott Long } else {
235446f118feSAlexander Motin tag_code = 1;
235552c9ce25SScott Long }
235652c9ce25SScott Long switch (bp->bio_cmd) {
235752c9ce25SScott Long case BIO_WRITE:
235869114bc0SAlexander Motin case BIO_READ:
235952c9ce25SScott Long {
236052c9ce25SScott Long uint64_t lba = bp->bio_pblkno;
236152c9ce25SScott Long uint16_t count = bp->bio_bcount / softc->params.secsize;
2362a9934668SKenneth D. Merry void *data_ptr;
2363a9934668SKenneth D. Merry int rw_op;
2364a9934668SKenneth D. Merry
2365a9934668SKenneth D. Merry if (bp->bio_cmd == BIO_WRITE) {
2366a9934668SKenneth D. Merry softc->flags |= ADA_FLAG_DIRTY;
2367a9934668SKenneth D. Merry rw_op = CAM_DIR_OUT;
2368a9934668SKenneth D. Merry } else {
2369a9934668SKenneth D. Merry rw_op = CAM_DIR_IN;
2370a9934668SKenneth D. Merry }
2371a9934668SKenneth D. Merry
2372a9934668SKenneth D. Merry data_ptr = bp->bio_data;
2373a9934668SKenneth D. Merry if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) {
2374a9934668SKenneth D. Merry rw_op |= CAM_DATA_BIO;
2375a9934668SKenneth D. Merry data_ptr = bp;
2376a9934668SKenneth D. Merry }
2377a9934668SKenneth D. Merry
2378d38677d2SWarner Losh #ifdef CAM_TEST_FAILURE
2379e3a6d3a4SAlexander Motin int fail = 0;
238052c9ce25SScott Long
2381e3a6d3a4SAlexander Motin /*
2382e3a6d3a4SAlexander Motin * Support the failure ioctls. If the command is a
2383e3a6d3a4SAlexander Motin * read, and there are pending forced read errors, or
2384e3a6d3a4SAlexander Motin * if a write and pending write errors, then fail this
2385e3a6d3a4SAlexander Motin * operation with EIO. This is useful for testing
2386e3a6d3a4SAlexander Motin * purposes. Also, support having every Nth read fail.
2387e3a6d3a4SAlexander Motin *
2388e3a6d3a4SAlexander Motin * This is a rather blunt tool.
2389e3a6d3a4SAlexander Motin */
2390e3a6d3a4SAlexander Motin if (bp->bio_cmd == BIO_READ) {
2391e3a6d3a4SAlexander Motin if (softc->force_read_error) {
2392e3a6d3a4SAlexander Motin softc->force_read_error--;
2393e3a6d3a4SAlexander Motin fail = 1;
2394e3a6d3a4SAlexander Motin }
2395e3a6d3a4SAlexander Motin if (softc->periodic_read_error > 0) {
2396e3a6d3a4SAlexander Motin if (++softc->periodic_read_count >=
2397e3a6d3a4SAlexander Motin softc->periodic_read_error) {
2398e3a6d3a4SAlexander Motin softc->periodic_read_count = 0;
2399e3a6d3a4SAlexander Motin fail = 1;
2400e3a6d3a4SAlexander Motin }
2401e3a6d3a4SAlexander Motin }
2402e3a6d3a4SAlexander Motin } else {
2403e3a6d3a4SAlexander Motin if (softc->force_write_error) {
2404e3a6d3a4SAlexander Motin softc->force_write_error--;
2405e3a6d3a4SAlexander Motin fail = 1;
2406e3a6d3a4SAlexander Motin }
2407e3a6d3a4SAlexander Motin }
2408e3a6d3a4SAlexander Motin if (fail) {
24094beec135SAlexander Motin biofinish(bp, NULL, EIO);
2410e3a6d3a4SAlexander Motin xpt_release_ccb(start_ccb);
2411e3a6d3a4SAlexander Motin adaschedule(periph);
2412e3a6d3a4SAlexander Motin return;
2413e3a6d3a4SAlexander Motin }
2414e3a6d3a4SAlexander Motin #endif
2415abc1e60eSKonstantin Belousov KASSERT((bp->bio_flags & BIO_UNMAPPED) == 0 ||
2416abc1e60eSKonstantin Belousov round_page(bp->bio_bcount + bp->bio_ma_offset) /
2417abc1e60eSKonstantin Belousov PAGE_SIZE == bp->bio_ma_n,
2418abc1e60eSKonstantin Belousov ("Short bio %p", bp));
241952c9ce25SScott Long cam_fill_ataio(ataio,
242052c9ce25SScott Long ada_retry_count,
242152c9ce25SScott Long adadone,
2422a9934668SKenneth D. Merry rw_op,
2423e4cc6558SWarner Losh 0,
2424a9934668SKenneth D. Merry data_ptr,
242552c9ce25SScott Long bp->bio_bcount,
242652c9ce25SScott Long ada_default_timeout*1000);
242752c9ce25SScott Long
242846f118feSAlexander Motin if ((softc->flags & ADA_FLAG_CAN_NCQ) && tag_code) {
242952c9ce25SScott Long if (bp->bio_cmd == BIO_READ) {
243052c9ce25SScott Long ata_ncq_cmd(ataio, ATA_READ_FPDMA_QUEUED,
243152c9ce25SScott Long lba, count);
243252c9ce25SScott Long } else {
243352c9ce25SScott Long ata_ncq_cmd(ataio, ATA_WRITE_FPDMA_QUEUED,
243452c9ce25SScott Long lba, count);
243552c9ce25SScott Long }
243652c9ce25SScott Long } else if ((softc->flags & ADA_FLAG_CAN_48BIT) &&
243752c9ce25SScott Long (lba + count >= ATA_MAX_28BIT_LBA ||
243846f118feSAlexander Motin count > 256)) {
24392e1eb332SMarius Strobl if (softc->flags & ADA_FLAG_CAN_DMA48) {
244052c9ce25SScott Long if (bp->bio_cmd == BIO_READ) {
244152c9ce25SScott Long ata_48bit_cmd(ataio, ATA_READ_DMA48,
244252c9ce25SScott Long 0, lba, count);
244352c9ce25SScott Long } else {
244452c9ce25SScott Long ata_48bit_cmd(ataio, ATA_WRITE_DMA48,
244552c9ce25SScott Long 0, lba, count);
244652c9ce25SScott Long }
244752c9ce25SScott Long } else {
244852c9ce25SScott Long if (bp->bio_cmd == BIO_READ) {
244946f118feSAlexander Motin ata_48bit_cmd(ataio, ATA_READ_MUL48,
245046f118feSAlexander Motin 0, lba, count);
245146f118feSAlexander Motin } else {
245246f118feSAlexander Motin ata_48bit_cmd(ataio, ATA_WRITE_MUL48,
245346f118feSAlexander Motin 0, lba, count);
245446f118feSAlexander Motin }
245546f118feSAlexander Motin }
245646f118feSAlexander Motin } else {
245746f118feSAlexander Motin if (count == 256)
245846f118feSAlexander Motin count = 0;
245946f118feSAlexander Motin if (softc->flags & ADA_FLAG_CAN_DMA) {
246046f118feSAlexander Motin if (bp->bio_cmd == BIO_READ) {
24617606b445SAlexander Motin ata_28bit_cmd(ataio, ATA_READ_DMA,
246252c9ce25SScott Long 0, lba, count);
246352c9ce25SScott Long } else {
24647606b445SAlexander Motin ata_28bit_cmd(ataio, ATA_WRITE_DMA,
246552c9ce25SScott Long 0, lba, count);
246652c9ce25SScott Long }
246746f118feSAlexander Motin } else {
246846f118feSAlexander Motin if (bp->bio_cmd == BIO_READ) {
246946f118feSAlexander Motin ata_28bit_cmd(ataio, ATA_READ_MUL,
247046f118feSAlexander Motin 0, lba, count);
247146f118feSAlexander Motin } else {
247246f118feSAlexander Motin ata_28bit_cmd(ataio, ATA_WRITE_MUL,
247346f118feSAlexander Motin 0, lba, count);
247446f118feSAlexander Motin }
247546f118feSAlexander Motin }
247652c9ce25SScott Long }
247752c9ce25SScott Long break;
24781c80ec0aSAlexander Motin }
2479a6e0c5daSWarner Losh case BIO_DELETE:
2480a6e0c5daSWarner Losh switch (softc->delete_method) {
2481a6e0c5daSWarner Losh case ADA_DELETE_NCQ_DSM_TRIM:
2482a6e0c5daSWarner Losh ada_ncq_dsmtrim(softc, bp, ataio);
2483a6e0c5daSWarner Losh break;
2484a6e0c5daSWarner Losh case ADA_DELETE_DSM_TRIM:
2485a6e0c5daSWarner Losh ada_dsmtrim(softc, bp, ataio);
2486a6e0c5daSWarner Losh break;
2487a6e0c5daSWarner Losh case ADA_DELETE_CFA_ERASE:
2488a6e0c5daSWarner Losh ada_cfaerase(softc, bp, ataio);
2489a6e0c5daSWarner Losh break;
2490a6e0c5daSWarner Losh default:
2491a6e0c5daSWarner Losh biofinish(bp, NULL, EOPNOTSUPP);
2492a6e0c5daSWarner Losh xpt_release_ccb(start_ccb);
2493a6e0c5daSWarner Losh adaschedule(periph);
2494a6e0c5daSWarner Losh return;
2495a6e0c5daSWarner Losh }
2496a6e0c5daSWarner Losh start_ccb->ccb_h.ccb_state = ADA_CCB_TRIM;
2497a6e0c5daSWarner Losh start_ccb->ccb_h.flags |= CAM_UNLOCKED;
2498a6e0c5daSWarner Losh cam_iosched_submit_trim(softc->cam_iosched);
2499a6e0c5daSWarner Losh goto out;
250052c9ce25SScott Long case BIO_FLUSH:
250152c9ce25SScott Long cam_fill_ataio(ataio,
250252c9ce25SScott Long 1,
250352c9ce25SScott Long adadone,
250452c9ce25SScott Long CAM_DIR_NONE,
250546f118feSAlexander Motin 0,
250652c9ce25SScott Long NULL,
250752c9ce25SScott Long 0,
250852c9ce25SScott Long ada_default_timeout*1000);
250952c9ce25SScott Long
251052c9ce25SScott Long if (softc->flags & ADA_FLAG_CAN_48BIT)
251152c9ce25SScott Long ata_48bit_cmd(ataio, ATA_FLUSHCACHE48, 0, 0, 0);
251252c9ce25SScott Long else
25137606b445SAlexander Motin ata_28bit_cmd(ataio, ATA_FLUSHCACHE, 0, 0, 0);
251452c9ce25SScott Long break;
25159a6844d5SKenneth D. Merry case BIO_ZONE: {
25169a6844d5SKenneth D. Merry int error, queue_ccb;
25179a6844d5SKenneth D. Merry
25189a6844d5SKenneth D. Merry queue_ccb = 0;
25199a6844d5SKenneth D. Merry
25209a6844d5SKenneth D. Merry error = ada_zone_cmd(periph, start_ccb, bp, &queue_ccb);
25219a6844d5SKenneth D. Merry if ((error != 0)
25229a6844d5SKenneth D. Merry || (queue_ccb == 0)) {
252399c14fb9SWarner Losh /*
252499c14fb9SWarner Losh * g_io_deliver will recurisvely call start
252599c14fb9SWarner Losh * routine for ENOMEM, so drop the periph
252699c14fb9SWarner Losh * lock to allow that recursion.
252799c14fb9SWarner Losh */
252899c14fb9SWarner Losh if (error == ENOMEM)
252999c14fb9SWarner Losh cam_periph_unlock(periph);
25309a6844d5SKenneth D. Merry biofinish(bp, NULL, error);
253199c14fb9SWarner Losh if (error == ENOMEM)
253299c14fb9SWarner Losh cam_periph_lock(periph);
25339a6844d5SKenneth D. Merry xpt_release_ccb(start_ccb);
25349a6844d5SKenneth D. Merry return;
25359a6844d5SKenneth D. Merry }
25369a6844d5SKenneth D. Merry break;
25379a6844d5SKenneth D. Merry }
2538d176b803SScott Long default:
2539d176b803SScott Long biofinish(bp, NULL, EOPNOTSUPP);
2540d176b803SScott Long xpt_release_ccb(start_ccb);
2541d176b803SScott Long return;
254252c9ce25SScott Long }
254352c9ce25SScott Long start_ccb->ccb_h.ccb_state = ADA_CCB_BUFFER_IO;
2544227d67aaSAlexander Motin start_ccb->ccb_h.flags |= CAM_UNLOCKED;
25451c80ec0aSAlexander Motin out:
254652c9ce25SScott Long start_ccb->ccb_h.ccb_bp = bp;
2547c1bd46c2SAlexander Motin softc->outstanding_cmds++;
2548227d67aaSAlexander Motin softc->refcount++;
2549227d67aaSAlexander Motin cam_periph_unlock(periph);
255052c9ce25SScott Long xpt_action(start_ccb);
2551227d67aaSAlexander Motin cam_periph_lock(periph);
255252c9ce25SScott Long
25531c80ec0aSAlexander Motin /* May have more work to do, so ensure we stay scheduled */
25541c80ec0aSAlexander Motin adaschedule(periph);
255552c9ce25SScott Long break;
255652c9ce25SScott Long }
25571ed6aaf9SAlexander Motin case ADA_STATE_RAHEAD:
2558f513d14cSAlexander Motin case ADA_STATE_WCACHE:
2559f513d14cSAlexander Motin {
2560f513d14cSAlexander Motin cam_fill_ataio(ataio,
2561f513d14cSAlexander Motin 1,
2562f513d14cSAlexander Motin adadone,
2563f513d14cSAlexander Motin CAM_DIR_NONE,
2564f513d14cSAlexander Motin 0,
2565f513d14cSAlexander Motin NULL,
2566f513d14cSAlexander Motin 0,
2567f513d14cSAlexander Motin ada_default_timeout*1000);
2568f513d14cSAlexander Motin
25691ed6aaf9SAlexander Motin if (softc->state == ADA_STATE_RAHEAD) {
25701ed6aaf9SAlexander Motin ata_28bit_cmd(ataio, ATA_SETFEATURES, ADA_RA ?
25711ed6aaf9SAlexander Motin ATA_SF_ENAB_RCACHE : ATA_SF_DIS_RCACHE, 0, 0);
25721ed6aaf9SAlexander Motin start_ccb->ccb_h.ccb_state = ADA_CCB_RAHEAD;
25731ed6aaf9SAlexander Motin } else {
25741ed6aaf9SAlexander Motin ata_28bit_cmd(ataio, ATA_SETFEATURES, ADA_WC ?
2575f513d14cSAlexander Motin ATA_SF_ENAB_WCACHE : ATA_SF_DIS_WCACHE, 0, 0);
2576f513d14cSAlexander Motin start_ccb->ccb_h.ccb_state = ADA_CCB_WCACHE;
25771ed6aaf9SAlexander Motin }
2578cccf4220SAlexander Motin start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE;
2579f513d14cSAlexander Motin xpt_action(start_ccb);
2580f513d14cSAlexander Motin break;
2581f513d14cSAlexander Motin }
25829a6844d5SKenneth D. Merry case ADA_STATE_LOGDIR:
25839a6844d5SKenneth D. Merry {
25849a6844d5SKenneth D. Merry struct ata_gp_log_dir *log_dir;
25859a6844d5SKenneth D. Merry
25869a6844d5SKenneth D. Merry if ((softc->flags & ADA_FLAG_CAN_LOG) == 0) {
25879a6844d5SKenneth D. Merry adaprobedone(periph, start_ccb);
25889a6844d5SKenneth D. Merry break;
25899a6844d5SKenneth D. Merry }
25909a6844d5SKenneth D. Merry
25919a6844d5SKenneth D. Merry log_dir = malloc(sizeof(*log_dir), M_ATADA, M_NOWAIT|M_ZERO);
25929a6844d5SKenneth D. Merry if (log_dir == NULL) {
25939a6844d5SKenneth D. Merry xpt_print(periph->path, "Couldn't malloc log_dir "
25949a6844d5SKenneth D. Merry "data\n");
25959a6844d5SKenneth D. Merry softc->state = ADA_STATE_NORMAL;
25969a6844d5SKenneth D. Merry xpt_release_ccb(start_ccb);
25979a6844d5SKenneth D. Merry break;
25989a6844d5SKenneth D. Merry }
25999a6844d5SKenneth D. Merry
26009a6844d5SKenneth D. Merry ata_read_log(ataio,
26019a6844d5SKenneth D. Merry /*retries*/1,
26029a6844d5SKenneth D. Merry /*cbfcnp*/adadone,
26039a6844d5SKenneth D. Merry /*log_address*/ ATA_LOG_DIRECTORY,
26049a6844d5SKenneth D. Merry /*page_number*/ 0,
26059a6844d5SKenneth D. Merry /*block_count*/ 1,
26069a6844d5SKenneth D. Merry /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ?
26079a6844d5SKenneth D. Merry CAM_ATAIO_DMA : 0,
26089a6844d5SKenneth D. Merry /*data_ptr*/ (uint8_t *)log_dir,
26099a6844d5SKenneth D. Merry /*dxfer_len*/sizeof(*log_dir),
26109a6844d5SKenneth D. Merry /*timeout*/ada_default_timeout*1000);
26119a6844d5SKenneth D. Merry
26129a6844d5SKenneth D. Merry start_ccb->ccb_h.ccb_state = ADA_CCB_LOGDIR;
26139a6844d5SKenneth D. Merry xpt_action(start_ccb);
26149a6844d5SKenneth D. Merry break;
26159a6844d5SKenneth D. Merry }
26169a6844d5SKenneth D. Merry case ADA_STATE_IDDIR:
26179a6844d5SKenneth D. Merry {
26189a6844d5SKenneth D. Merry struct ata_identify_log_pages *id_dir;
26199a6844d5SKenneth D. Merry
26209a6844d5SKenneth D. Merry id_dir = malloc(sizeof(*id_dir), M_ATADA, M_NOWAIT | M_ZERO);
26219a6844d5SKenneth D. Merry if (id_dir == NULL) {
26229a6844d5SKenneth D. Merry xpt_print(periph->path, "Couldn't malloc id_dir "
26239a6844d5SKenneth D. Merry "data\n");
26249a6844d5SKenneth D. Merry adaprobedone(periph, start_ccb);
26259a6844d5SKenneth D. Merry break;
26269a6844d5SKenneth D. Merry }
26279a6844d5SKenneth D. Merry
26289a6844d5SKenneth D. Merry ata_read_log(ataio,
26299a6844d5SKenneth D. Merry /*retries*/1,
26309a6844d5SKenneth D. Merry /*cbfcnp*/adadone,
26319a6844d5SKenneth D. Merry /*log_address*/ ATA_IDENTIFY_DATA_LOG,
26329a6844d5SKenneth D. Merry /*page_number*/ ATA_IDL_PAGE_LIST,
26339a6844d5SKenneth D. Merry /*block_count*/ 1,
26349a6844d5SKenneth D. Merry /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ?
26359a6844d5SKenneth D. Merry CAM_ATAIO_DMA : 0,
26369a6844d5SKenneth D. Merry /*data_ptr*/ (uint8_t *)id_dir,
26379a6844d5SKenneth D. Merry /*dxfer_len*/ sizeof(*id_dir),
26389a6844d5SKenneth D. Merry /*timeout*/ada_default_timeout*1000);
26399a6844d5SKenneth D. Merry
26409a6844d5SKenneth D. Merry start_ccb->ccb_h.ccb_state = ADA_CCB_IDDIR;
26419a6844d5SKenneth D. Merry xpt_action(start_ccb);
26429a6844d5SKenneth D. Merry break;
26439a6844d5SKenneth D. Merry }
26449a6844d5SKenneth D. Merry case ADA_STATE_SUP_CAP:
26459a6844d5SKenneth D. Merry {
26469a6844d5SKenneth D. Merry struct ata_identify_log_sup_cap *sup_cap;
26479a6844d5SKenneth D. Merry
26489a6844d5SKenneth D. Merry sup_cap = malloc(sizeof(*sup_cap), M_ATADA, M_NOWAIT|M_ZERO);
26499a6844d5SKenneth D. Merry if (sup_cap == NULL) {
26509a6844d5SKenneth D. Merry xpt_print(periph->path, "Couldn't malloc sup_cap "
26519a6844d5SKenneth D. Merry "data\n");
26529a6844d5SKenneth D. Merry adaprobedone(periph, start_ccb);
26539a6844d5SKenneth D. Merry break;
26549a6844d5SKenneth D. Merry }
26559a6844d5SKenneth D. Merry
26569a6844d5SKenneth D. Merry ata_read_log(ataio,
26579a6844d5SKenneth D. Merry /*retries*/1,
26589a6844d5SKenneth D. Merry /*cbfcnp*/adadone,
26599a6844d5SKenneth D. Merry /*log_address*/ ATA_IDENTIFY_DATA_LOG,
26609a6844d5SKenneth D. Merry /*page_number*/ ATA_IDL_SUP_CAP,
26619a6844d5SKenneth D. Merry /*block_count*/ 1,
26629a6844d5SKenneth D. Merry /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ?
26639a6844d5SKenneth D. Merry CAM_ATAIO_DMA : 0,
26649a6844d5SKenneth D. Merry /*data_ptr*/ (uint8_t *)sup_cap,
26659a6844d5SKenneth D. Merry /*dxfer_len*/ sizeof(*sup_cap),
26669a6844d5SKenneth D. Merry /*timeout*/ada_default_timeout*1000);
26679a6844d5SKenneth D. Merry
26689a6844d5SKenneth D. Merry start_ccb->ccb_h.ccb_state = ADA_CCB_SUP_CAP;
26699a6844d5SKenneth D. Merry xpt_action(start_ccb);
26709a6844d5SKenneth D. Merry break;
26719a6844d5SKenneth D. Merry }
26729a6844d5SKenneth D. Merry case ADA_STATE_ZONE:
26739a6844d5SKenneth D. Merry {
26749a6844d5SKenneth D. Merry struct ata_zoned_info_log *ata_zone;
26759a6844d5SKenneth D. Merry
26769a6844d5SKenneth D. Merry ata_zone = malloc(sizeof(*ata_zone), M_ATADA, M_NOWAIT|M_ZERO);
26779a6844d5SKenneth D. Merry if (ata_zone == NULL) {
26789a6844d5SKenneth D. Merry xpt_print(periph->path, "Couldn't malloc ata_zone "
26799a6844d5SKenneth D. Merry "data\n");
26809a6844d5SKenneth D. Merry adaprobedone(periph, start_ccb);
26819a6844d5SKenneth D. Merry break;
26829a6844d5SKenneth D. Merry }
26839a6844d5SKenneth D. Merry
26849a6844d5SKenneth D. Merry ata_read_log(ataio,
26859a6844d5SKenneth D. Merry /*retries*/1,
26869a6844d5SKenneth D. Merry /*cbfcnp*/adadone,
26879a6844d5SKenneth D. Merry /*log_address*/ ATA_IDENTIFY_DATA_LOG,
26889a6844d5SKenneth D. Merry /*page_number*/ ATA_IDL_ZDI,
26899a6844d5SKenneth D. Merry /*block_count*/ 1,
26909a6844d5SKenneth D. Merry /*protocol*/ softc->flags & ADA_FLAG_CAN_DMA ?
26919a6844d5SKenneth D. Merry CAM_ATAIO_DMA : 0,
26929a6844d5SKenneth D. Merry /*data_ptr*/ (uint8_t *)ata_zone,
26939a6844d5SKenneth D. Merry /*dxfer_len*/ sizeof(*ata_zone),
26949a6844d5SKenneth D. Merry /*timeout*/ada_default_timeout*1000);
26959a6844d5SKenneth D. Merry
26969a6844d5SKenneth D. Merry start_ccb->ccb_h.ccb_state = ADA_CCB_ZONE;
26979a6844d5SKenneth D. Merry xpt_action(start_ccb);
26989a6844d5SKenneth D. Merry break;
269952c9ce25SScott Long }
270052c9ce25SScott Long }
27019a6844d5SKenneth D. Merry }
27029a6844d5SKenneth D. Merry
27039a6844d5SKenneth D. Merry static void
adaprobedone(struct cam_periph * periph,union ccb * ccb)27049a6844d5SKenneth D. Merry adaprobedone(struct cam_periph *periph, union ccb *ccb)
27059a6844d5SKenneth D. Merry {
27069a6844d5SKenneth D. Merry struct ada_softc *softc;
27079a6844d5SKenneth D. Merry
27089a6844d5SKenneth D. Merry softc = (struct ada_softc *)periph->softc;
27099a6844d5SKenneth D. Merry
27101907e1c0SWarner Losh /*
27111907e1c0SWarner Losh * Since our peripheral may be invalidated by an error we must release
27121907e1c0SWarner Losh * our CCB before releasing the reference on the peripheral. The
27131907e1c0SWarner Losh * peripheral will only go away once the last reference is removed, and
27141907e1c0SWarner Losh * we need it around for the CCB release operation.
27151907e1c0SWarner Losh */
27169a6844d5SKenneth D. Merry if (ccb != NULL)
27179a6844d5SKenneth D. Merry xpt_release_ccb(ccb);
27189a6844d5SKenneth D. Merry
27199a6844d5SKenneth D. Merry softc->state = ADA_STATE_NORMAL;
27209a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_PROBED;
27219a6844d5SKenneth D. Merry adaschedule(periph);
27229a6844d5SKenneth D. Merry if ((softc->flags & ADA_FLAG_ANNOUNCED) == 0) {
27239a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_ANNOUNCED;
272490bcc81bSAlexander Motin
272590bcc81bSAlexander Motin /*
272690bcc81bSAlexander Motin * We'll release this reference once GEOM calls us back via
272790bcc81bSAlexander Motin * adadiskgonecb(), telling us that our provider has been freed.
272890bcc81bSAlexander Motin */
272990bcc81bSAlexander Motin if (cam_periph_acquire(periph) == 0)
273090bcc81bSAlexander Motin disk_create(softc->disk, DISK_VERSION);
273190bcc81bSAlexander Motin
273290bcc81bSAlexander Motin cam_periph_release_boot(periph);
27339a6844d5SKenneth D. Merry }
273490bcc81bSAlexander Motin cam_periph_release_locked(periph);
27359a6844d5SKenneth D. Merry }
27369a6844d5SKenneth D. Merry
27379a6844d5SKenneth D. Merry static void
adazonedone(struct cam_periph * periph,union ccb * ccb)27389a6844d5SKenneth D. Merry adazonedone(struct cam_periph *periph, union ccb *ccb)
27399a6844d5SKenneth D. Merry {
27409a6844d5SKenneth D. Merry struct bio *bp;
27419a6844d5SKenneth D. Merry
27429a6844d5SKenneth D. Merry bp = (struct bio *)ccb->ccb_h.ccb_bp;
27439a6844d5SKenneth D. Merry
27449a6844d5SKenneth D. Merry switch (bp->bio_zone.zone_cmd) {
27459a6844d5SKenneth D. Merry case DISK_ZONE_OPEN:
27469a6844d5SKenneth D. Merry case DISK_ZONE_CLOSE:
27479a6844d5SKenneth D. Merry case DISK_ZONE_FINISH:
27489a6844d5SKenneth D. Merry case DISK_ZONE_RWP:
27499a6844d5SKenneth D. Merry break;
27509a6844d5SKenneth D. Merry case DISK_ZONE_REPORT_ZONES: {
27519a6844d5SKenneth D. Merry uint32_t avail_len;
27529a6844d5SKenneth D. Merry struct disk_zone_report *rep;
27539a6844d5SKenneth D. Merry struct scsi_report_zones_hdr *hdr;
27549a6844d5SKenneth D. Merry struct scsi_report_zones_desc *desc;
27559a6844d5SKenneth D. Merry struct disk_zone_rep_entry *entry;
2756151ba793SAlexander Kabaev uint32_t hdr_len, num_avail;
27579a6844d5SKenneth D. Merry uint32_t num_to_fill, i;
27589a6844d5SKenneth D. Merry
27599a6844d5SKenneth D. Merry rep = &bp->bio_zone.zone_params.report;
27609a6844d5SKenneth D. Merry avail_len = ccb->ataio.dxfer_len - ccb->ataio.resid;
27619a6844d5SKenneth D. Merry /*
27629a6844d5SKenneth D. Merry * Note that bio_resid isn't normally used for zone
27639a6844d5SKenneth D. Merry * commands, but it is used by devstat_end_transaction_bio()
27649a6844d5SKenneth D. Merry * to determine how much data was transferred. Because
27659a6844d5SKenneth D. Merry * the size of the SCSI/ATA data structures is different
27669a6844d5SKenneth D. Merry * than the size of the BIO interface structures, the
27679a6844d5SKenneth D. Merry * amount of data actually transferred from the drive will
27689a6844d5SKenneth D. Merry * be different than the amount of data transferred to
27699a6844d5SKenneth D. Merry * the user.
27709a6844d5SKenneth D. Merry */
27719a6844d5SKenneth D. Merry hdr = (struct scsi_report_zones_hdr *)ccb->ataio.data_ptr;
27729a6844d5SKenneth D. Merry if (avail_len < sizeof(*hdr)) {
27739a6844d5SKenneth D. Merry /*
27749a6844d5SKenneth D. Merry * Is there a better error than EIO here? We asked
27759a6844d5SKenneth D. Merry * for at least the header, and we got less than
27769a6844d5SKenneth D. Merry * that.
27779a6844d5SKenneth D. Merry */
27789a6844d5SKenneth D. Merry bp->bio_error = EIO;
27799a6844d5SKenneth D. Merry bp->bio_flags |= BIO_ERROR;
27809a6844d5SKenneth D. Merry bp->bio_resid = bp->bio_bcount;
27819a6844d5SKenneth D. Merry break;
27829a6844d5SKenneth D. Merry }
27839a6844d5SKenneth D. Merry
27849a6844d5SKenneth D. Merry hdr_len = le32dec(hdr->length);
27859a6844d5SKenneth D. Merry if (hdr_len > 0)
27869a6844d5SKenneth D. Merry rep->entries_available = hdr_len / sizeof(*desc);
27879a6844d5SKenneth D. Merry else
27889a6844d5SKenneth D. Merry rep->entries_available = 0;
27899a6844d5SKenneth D. Merry /*
27909a6844d5SKenneth D. Merry * NOTE: using the same values for the BIO version of the
27919a6844d5SKenneth D. Merry * same field as the SCSI/ATA values. This means we could
27929a6844d5SKenneth D. Merry * get some additional values that aren't defined in bio.h
27939a6844d5SKenneth D. Merry * if more values of the same field are defined later.
27949a6844d5SKenneth D. Merry */
27959a6844d5SKenneth D. Merry rep->header.same = hdr->byte4 & SRZ_SAME_MASK;
27969a6844d5SKenneth D. Merry rep->header.maximum_lba = le64dec(hdr->maximum_lba);
27979a6844d5SKenneth D. Merry /*
27989a6844d5SKenneth D. Merry * If the drive reports no entries that match the query,
27999a6844d5SKenneth D. Merry * we're done.
28009a6844d5SKenneth D. Merry */
28019a6844d5SKenneth D. Merry if (hdr_len == 0) {
28029a6844d5SKenneth D. Merry rep->entries_filled = 0;
28039a6844d5SKenneth D. Merry bp->bio_resid = bp->bio_bcount;
28049a6844d5SKenneth D. Merry break;
28059a6844d5SKenneth D. Merry }
28069a6844d5SKenneth D. Merry
28079a6844d5SKenneth D. Merry num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc),
28089a6844d5SKenneth D. Merry hdr_len / sizeof(*desc));
28099a6844d5SKenneth D. Merry /*
28109a6844d5SKenneth D. Merry * If the drive didn't return any data, then we're done.
28119a6844d5SKenneth D. Merry */
28129a6844d5SKenneth D. Merry if (num_avail == 0) {
28139a6844d5SKenneth D. Merry rep->entries_filled = 0;
28149a6844d5SKenneth D. Merry bp->bio_resid = bp->bio_bcount;
28159a6844d5SKenneth D. Merry break;
28169a6844d5SKenneth D. Merry }
28179a6844d5SKenneth D. Merry
28189a6844d5SKenneth D. Merry num_to_fill = min(num_avail, rep->entries_allocated);
28199a6844d5SKenneth D. Merry /*
28209a6844d5SKenneth D. Merry * If the user didn't allocate any entries for us to fill,
28219a6844d5SKenneth D. Merry * we're done.
28229a6844d5SKenneth D. Merry */
28239a6844d5SKenneth D. Merry if (num_to_fill == 0) {
28249a6844d5SKenneth D. Merry rep->entries_filled = 0;
28259a6844d5SKenneth D. Merry bp->bio_resid = bp->bio_bcount;
28269a6844d5SKenneth D. Merry break;
28279a6844d5SKenneth D. Merry }
28289a6844d5SKenneth D. Merry
28299a6844d5SKenneth D. Merry for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0];
28309a6844d5SKenneth D. Merry i < num_to_fill; i++, desc++, entry++) {
28319a6844d5SKenneth D. Merry /*
28329a6844d5SKenneth D. Merry * NOTE: we're mapping the values here directly
28339a6844d5SKenneth D. Merry * from the SCSI/ATA bit definitions to the bio.h
28349a6844d5SKenneth D. Merry * definitions. There is also a warning in
28359a6844d5SKenneth D. Merry * disk_zone.h, but the impact is that if
28369a6844d5SKenneth D. Merry * additional values are added in the SCSI/ATA
28379a6844d5SKenneth D. Merry * specs these will be visible to consumers of
28389a6844d5SKenneth D. Merry * this interface.
28399a6844d5SKenneth D. Merry */
28409a6844d5SKenneth D. Merry entry->zone_type = desc->zone_type & SRZ_TYPE_MASK;
28419a6844d5SKenneth D. Merry entry->zone_condition =
28429a6844d5SKenneth D. Merry (desc->zone_flags & SRZ_ZONE_COND_MASK) >>
28439a6844d5SKenneth D. Merry SRZ_ZONE_COND_SHIFT;
28449a6844d5SKenneth D. Merry entry->zone_flags |= desc->zone_flags &
28459a6844d5SKenneth D. Merry (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET);
28469a6844d5SKenneth D. Merry entry->zone_length = le64dec(desc->zone_length);
28479a6844d5SKenneth D. Merry entry->zone_start_lba = le64dec(desc->zone_start_lba);
28489a6844d5SKenneth D. Merry entry->write_pointer_lba =
28499a6844d5SKenneth D. Merry le64dec(desc->write_pointer_lba);
28509a6844d5SKenneth D. Merry }
28519a6844d5SKenneth D. Merry rep->entries_filled = num_to_fill;
28529a6844d5SKenneth D. Merry /*
28539a6844d5SKenneth D. Merry * Note that this residual is accurate from the user's
28549a6844d5SKenneth D. Merry * standpoint, but the amount transferred isn't accurate
28559a6844d5SKenneth D. Merry * from the standpoint of what actually came back from the
28569a6844d5SKenneth D. Merry * drive.
28579a6844d5SKenneth D. Merry */
28589a6844d5SKenneth D. Merry bp->bio_resid = bp->bio_bcount - (num_to_fill * sizeof(*entry));
28599a6844d5SKenneth D. Merry break;
28609a6844d5SKenneth D. Merry }
28619a6844d5SKenneth D. Merry case DISK_ZONE_GET_PARAMS:
28629a6844d5SKenneth D. Merry default:
28639a6844d5SKenneth D. Merry /*
28649a6844d5SKenneth D. Merry * In theory we should not get a GET_PARAMS bio, since it
28659a6844d5SKenneth D. Merry * should be handled without queueing the command to the
28669a6844d5SKenneth D. Merry * drive.
28679a6844d5SKenneth D. Merry */
28689a6844d5SKenneth D. Merry panic("%s: Invalid zone command %d", __func__,
28699a6844d5SKenneth D. Merry bp->bio_zone.zone_cmd);
28709a6844d5SKenneth D. Merry break;
28719a6844d5SKenneth D. Merry }
28729a6844d5SKenneth D. Merry
28739a6844d5SKenneth D. Merry if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES)
28749a6844d5SKenneth D. Merry free(ccb->ataio.data_ptr, M_ATADA);
28759a6844d5SKenneth D. Merry }
28769a6844d5SKenneth D. Merry
287752c9ce25SScott Long static void
adadone(struct cam_periph * periph,union ccb * done_ccb)287852c9ce25SScott Long adadone(struct cam_periph *periph, union ccb *done_ccb)
287952c9ce25SScott Long {
288052c9ce25SScott Long struct ada_softc *softc;
288152c9ce25SScott Long struct ccb_ataio *ataio;
2882cccf4220SAlexander Motin struct cam_path *path;
28839a6844d5SKenneth D. Merry uint32_t priority;
28847651b989SAlexander Motin int state;
288552c9ce25SScott Long
288652c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
288752c9ce25SScott Long ataio = &done_ccb->ataio;
2888cccf4220SAlexander Motin path = done_ccb->ccb_h.path;
28899a6844d5SKenneth D. Merry priority = done_ccb->ccb_h.pinfo.priority;
2890fddde2b8SAlexander Motin
2891cccf4220SAlexander Motin CAM_DEBUG(path, CAM_DEBUG_TRACE, ("adadone\n"));
2892fddde2b8SAlexander Motin
28937651b989SAlexander Motin state = ataio->ccb_h.ccb_state & ADA_CCB_TYPE_MASK;
28947651b989SAlexander Motin switch (state) {
289552c9ce25SScott Long case ADA_CCB_BUFFER_IO:
28961c80ec0aSAlexander Motin case ADA_CCB_TRIM:
289752c9ce25SScott Long {
289852c9ce25SScott Long struct bio *bp;
289952c9ce25SScott Long int error;
290052c9ce25SScott Long
2901227d67aaSAlexander Motin cam_periph_lock(periph);
2902a6e0c5daSWarner Losh bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
29037651b989SAlexander Motin if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
29046c8ab086SWarner Losh error = adaerror(done_ccb, CAM_RETRY_SELTO, 0);
290552c9ce25SScott Long if (error == ERESTART) {
290646f118feSAlexander Motin /* A retry was scheduled, so just return. */
2907227d67aaSAlexander Motin cam_periph_unlock(periph);
290852c9ce25SScott Long return;
290952c9ce25SScott Long }
291052c9ce25SScott Long if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2911cccf4220SAlexander Motin cam_release_devq(path,
291252c9ce25SScott Long /*relsim_flags*/0,
291352c9ce25SScott Long /*reduction*/0,
291452c9ce25SScott Long /*timeout*/0,
291552c9ce25SScott Long /*getcount_only*/0);
2916a6e0c5daSWarner Losh /*
2917a6e0c5daSWarner Losh * If we get an error on an NCQ DSM TRIM, fall back
2918a6e0c5daSWarner Losh * to a non-NCQ DSM TRIM forever. Please note that if
2919a6e0c5daSWarner Losh * CAN_NCQ_TRIM is set, CAN_TRIM is necessarily set too.
2920a6e0c5daSWarner Losh * However, for this one trim, we treat it as advisory
2921a6e0c5daSWarner Losh * and return success up the stack.
2922a6e0c5daSWarner Losh */
2923a6e0c5daSWarner Losh if (state == ADA_CCB_TRIM &&
2924a6e0c5daSWarner Losh error != 0 &&
2925a6e0c5daSWarner Losh (softc->flags & ADA_FLAG_CAN_NCQ_TRIM) != 0) {
2926a6e0c5daSWarner Losh softc->flags &= ~ADA_FLAG_CAN_NCQ_TRIM;
2927a6e0c5daSWarner Losh error = 0;
2928a6e0c5daSWarner Losh adasetdeletemethod(softc);
2929a6e0c5daSWarner Losh }
293052c9ce25SScott Long } else {
293152c9ce25SScott Long if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
293252c9ce25SScott Long panic("REQ_CMP with QFRZN");
29339a6844d5SKenneth D. Merry
29347651b989SAlexander Motin error = 0;
29357651b989SAlexander Motin }
29367651b989SAlexander Motin bp->bio_error = error;
29377651b989SAlexander Motin if (error != 0) {
29387651b989SAlexander Motin bp->bio_resid = bp->bio_bcount;
29397651b989SAlexander Motin bp->bio_flags |= BIO_ERROR;
29407651b989SAlexander Motin } else {
29419a6844d5SKenneth D. Merry if (bp->bio_cmd == BIO_ZONE)
29429a6844d5SKenneth D. Merry adazonedone(periph, done_ccb);
29439a6844d5SKenneth D. Merry else if (state == ADA_CCB_TRIM)
29447651b989SAlexander Motin bp->bio_resid = 0;
29457651b989SAlexander Motin else
294652c9ce25SScott Long bp->bio_resid = ataio->resid;
29479a6844d5SKenneth D. Merry
29489a6844d5SKenneth D. Merry if ((bp->bio_resid > 0)
29499a6844d5SKenneth D. Merry && (bp->bio_cmd != BIO_ZONE))
295052c9ce25SScott Long bp->bio_flags |= BIO_ERROR;
295152c9ce25SScott Long }
295252c9ce25SScott Long softc->outstanding_cmds--;
295352c9ce25SScott Long if (softc->outstanding_cmds == 0)
2954030844d1SAlexander Motin softc->flags |= ADA_FLAG_WAS_OTAG;
2955a6e0c5daSWarner Losh
29569754579bSWarner Losh /*
29579754579bSWarner Losh * We need to call cam_iosched before we call biodone so that we
29589754579bSWarner Losh * don't measure any activity that happens in the completion
29599754579bSWarner Losh * routine, which in the case of sendfile can be quite
2960d9a7a61bSWarner Losh * extensive. Release the periph refcount taken in adastart()
2961d9a7a61bSWarner Losh * for each CCB.
29629754579bSWarner Losh */
2963a6e0c5daSWarner Losh cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb);
2964227d67aaSAlexander Motin xpt_release_ccb(done_ccb);
2965d9a7a61bSWarner Losh KASSERT(softc->refcount >= 1, ("adadone softc %p refcount %d", softc, softc->refcount));
2966d9a7a61bSWarner Losh softc->refcount--;
29677651b989SAlexander Motin if (state == ADA_CCB_TRIM) {
29682030b294SAlexander Motin TAILQ_HEAD(, bio) queue;
29692030b294SAlexander Motin struct bio *bp1;
297052c9ce25SScott Long
29712030b294SAlexander Motin TAILQ_INIT(&queue);
29722030b294SAlexander Motin TAILQ_CONCAT(&queue, &softc->trim_req.bps, bio_queue);
29730ac66574SWarner Losh /*
29740ac66574SWarner Losh * Normally, the xpt_release_ccb() above would make sure
29750ac66574SWarner Losh * that when we have more work to do, that work would
29760ac66574SWarner Losh * get kicked off. However, we specifically keep
29770ac66574SWarner Losh * trim_running set to 0 before the call above to allow
29780ac66574SWarner Losh * other I/O to progress when many BIO_DELETE requests
29790ac66574SWarner Losh * are pushed down. We set trim_running to 0 and call
29800ac66574SWarner Losh * daschedule again so that we don't stall if there are
29810ac66574SWarner Losh * no other I/Os pending apart from BIO_DELETEs.
29820ac66574SWarner Losh */
2983a6e0c5daSWarner Losh cam_iosched_trim_done(softc->cam_iosched);
2984227d67aaSAlexander Motin adaschedule(periph);
2985227d67aaSAlexander Motin cam_periph_unlock(periph);
29862030b294SAlexander Motin while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
29872030b294SAlexander Motin TAILQ_REMOVE(&queue, bp1, bio_queue);
29882030b294SAlexander Motin bp1->bio_error = error;
29892030b294SAlexander Motin if (error != 0) {
29901c80ec0aSAlexander Motin bp1->bio_flags |= BIO_ERROR;
29917651b989SAlexander Motin bp1->bio_resid = bp1->bio_bcount;
29927651b989SAlexander Motin } else
29937651b989SAlexander Motin bp1->bio_resid = 0;
29941c80ec0aSAlexander Motin biodone(bp1);
29951c80ec0aSAlexander Motin }
2996227d67aaSAlexander Motin } else {
2997a6e0c5daSWarner Losh adaschedule(periph);
2998227d67aaSAlexander Motin cam_periph_unlock(periph);
299952c9ce25SScott Long biodone(bp);
3000227d67aaSAlexander Motin }
3001227d67aaSAlexander Motin return;
300252c9ce25SScott Long }
30031ed6aaf9SAlexander Motin case ADA_CCB_RAHEAD:
30041ed6aaf9SAlexander Motin {
30051ed6aaf9SAlexander Motin if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
30061ed6aaf9SAlexander Motin if (adaerror(done_ccb, 0, 0) == ERESTART) {
3007cccf4220SAlexander Motin /* Drop freeze taken due to CAM_DEV_QFREEZE */
3008cccf4220SAlexander Motin cam_release_devq(path, 0, 0, 0, FALSE);
30091ed6aaf9SAlexander Motin return;
30101ed6aaf9SAlexander Motin } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3011cccf4220SAlexander Motin cam_release_devq(path,
30121ed6aaf9SAlexander Motin /*relsim_flags*/0,
30131ed6aaf9SAlexander Motin /*reduction*/0,
30141ed6aaf9SAlexander Motin /*timeout*/0,
30151ed6aaf9SAlexander Motin /*getcount_only*/0);
30161ed6aaf9SAlexander Motin }
30171ed6aaf9SAlexander Motin }
30181ed6aaf9SAlexander Motin
30199a6844d5SKenneth D. Merry xpt_release_ccb(done_ccb);
30201ed6aaf9SAlexander Motin softc->state = ADA_STATE_WCACHE;
30219a6844d5SKenneth D. Merry xpt_schedule(periph, priority);
3022cccf4220SAlexander Motin /* Drop freeze taken due to CAM_DEV_QFREEZE */
3023cccf4220SAlexander Motin cam_release_devq(path, 0, 0, 0, FALSE);
30241ed6aaf9SAlexander Motin return;
30251ed6aaf9SAlexander Motin }
3026f513d14cSAlexander Motin case ADA_CCB_WCACHE:
3027f513d14cSAlexander Motin {
3028f513d14cSAlexander Motin if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3029f513d14cSAlexander Motin if (adaerror(done_ccb, 0, 0) == ERESTART) {
30309a6844d5SKenneth D. Merry /* Drop freeze taken due to CAM_DEV_QFREEZE */
30319a6844d5SKenneth D. Merry cam_release_devq(path, 0, 0, 0, FALSE);
30329a6844d5SKenneth D. Merry return;
3033f513d14cSAlexander Motin } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3034cccf4220SAlexander Motin cam_release_devq(path,
3035f513d14cSAlexander Motin /*relsim_flags*/0,
3036f513d14cSAlexander Motin /*reduction*/0,
3037f513d14cSAlexander Motin /*timeout*/0,
3038f513d14cSAlexander Motin /*getcount_only*/0);
3039f513d14cSAlexander Motin }
3040f513d14cSAlexander Motin }
3041f513d14cSAlexander Motin
3042cccf4220SAlexander Motin /* Drop freeze taken due to CAM_DEV_QFREEZE */
3043cccf4220SAlexander Motin cam_release_devq(path, 0, 0, 0, FALSE);
30449a6844d5SKenneth D. Merry
3045600fd98fSKenneth D. Merry if ((softc->flags & ADA_FLAG_CAN_LOG)
3046600fd98fSKenneth D. Merry && (softc->zone_mode != ADA_ZONE_NONE)) {
30479a6844d5SKenneth D. Merry xpt_release_ccb(done_ccb);
30489a6844d5SKenneth D. Merry softc->state = ADA_STATE_LOGDIR;
30499a6844d5SKenneth D. Merry xpt_schedule(periph, priority);
30509a6844d5SKenneth D. Merry } else {
30519a6844d5SKenneth D. Merry adaprobedone(periph, done_ccb);
30529a6844d5SKenneth D. Merry }
30539a6844d5SKenneth D. Merry return;
30549a6844d5SKenneth D. Merry }
30559a6844d5SKenneth D. Merry case ADA_CCB_LOGDIR:
30569a6844d5SKenneth D. Merry {
30579a6844d5SKenneth D. Merry int error;
30589a6844d5SKenneth D. Merry
30599a6844d5SKenneth D. Merry if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
30609a6844d5SKenneth D. Merry error = 0;
30619a6844d5SKenneth D. Merry softc->valid_logdir_len = 0;
30629a6844d5SKenneth D. Merry bzero(&softc->ata_logdir, sizeof(softc->ata_logdir));
30639a6844d5SKenneth D. Merry softc->valid_logdir_len =
30649a6844d5SKenneth D. Merry ataio->dxfer_len - ataio->resid;
30659a6844d5SKenneth D. Merry if (softc->valid_logdir_len > 0)
30669a6844d5SKenneth D. Merry bcopy(ataio->data_ptr, &softc->ata_logdir,
30679a6844d5SKenneth D. Merry min(softc->valid_logdir_len,
30689a6844d5SKenneth D. Merry sizeof(softc->ata_logdir)));
30699a6844d5SKenneth D. Merry /*
30709a6844d5SKenneth D. Merry * Figure out whether the Identify Device log is
30719a6844d5SKenneth D. Merry * supported. The General Purpose log directory
30729a6844d5SKenneth D. Merry * has a header, and lists the number of pages
30739a6844d5SKenneth D. Merry * available for each GP log identified by the
30749a6844d5SKenneth D. Merry * offset into the list.
30759a6844d5SKenneth D. Merry */
30769a6844d5SKenneth D. Merry if ((softc->valid_logdir_len >=
30779a6844d5SKenneth D. Merry ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t)))
30789a6844d5SKenneth D. Merry && (le16dec(softc->ata_logdir.header) ==
30799a6844d5SKenneth D. Merry ATA_GP_LOG_DIR_VERSION)
30809a6844d5SKenneth D. Merry && (le16dec(&softc->ata_logdir.num_pages[
30819a6844d5SKenneth D. Merry (ATA_IDENTIFY_DATA_LOG *
30829a6844d5SKenneth D. Merry sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){
30839a6844d5SKenneth D. Merry softc->flags |= ADA_FLAG_CAN_IDLOG;
30849a6844d5SKenneth D. Merry } else {
30859a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_IDLOG;
30869a6844d5SKenneth D. Merry }
30879a6844d5SKenneth D. Merry } else {
30889a6844d5SKenneth D. Merry error = adaerror(done_ccb, CAM_RETRY_SELTO,
30899a6844d5SKenneth D. Merry SF_RETRY_UA|SF_NO_PRINT);
30909a6844d5SKenneth D. Merry if (error == ERESTART)
30919a6844d5SKenneth D. Merry return;
30929a6844d5SKenneth D. Merry else if (error != 0) {
30939a6844d5SKenneth D. Merry /*
30949a6844d5SKenneth D. Merry * If we can't get the ATA log directory,
30959a6844d5SKenneth D. Merry * then ATA logs are effectively not
30969a6844d5SKenneth D. Merry * supported even if the bit is set in the
30979a6844d5SKenneth D. Merry * identify data.
30989a6844d5SKenneth D. Merry */
30999a6844d5SKenneth D. Merry softc->flags &= ~(ADA_FLAG_CAN_LOG |
31009a6844d5SKenneth D. Merry ADA_FLAG_CAN_IDLOG);
31019a6844d5SKenneth D. Merry if ((done_ccb->ccb_h.status &
31029a6844d5SKenneth D. Merry CAM_DEV_QFRZN) != 0) {
31039a6844d5SKenneth D. Merry /* Don't wedge this device's queue */
31049a6844d5SKenneth D. Merry cam_release_devq(done_ccb->ccb_h.path,
31059a6844d5SKenneth D. Merry /*relsim_flags*/0,
31069a6844d5SKenneth D. Merry /*reduction*/0,
31079a6844d5SKenneth D. Merry /*timeout*/0,
31089a6844d5SKenneth D. Merry /*getcount_only*/0);
31099a6844d5SKenneth D. Merry }
31109a6844d5SKenneth D. Merry }
31119a6844d5SKenneth D. Merry }
31129a6844d5SKenneth D. Merry
31139a6844d5SKenneth D. Merry free(ataio->data_ptr, M_ATADA);
31149a6844d5SKenneth D. Merry
31159a6844d5SKenneth D. Merry if ((error == 0)
31169a6844d5SKenneth D. Merry && (softc->flags & ADA_FLAG_CAN_IDLOG)) {
31179a6844d5SKenneth D. Merry softc->state = ADA_STATE_IDDIR;
31189a6844d5SKenneth D. Merry xpt_release_ccb(done_ccb);
31199a6844d5SKenneth D. Merry xpt_schedule(periph, priority);
31209a6844d5SKenneth D. Merry } else
31219a6844d5SKenneth D. Merry adaprobedone(periph, done_ccb);
31229a6844d5SKenneth D. Merry
31239a6844d5SKenneth D. Merry return;
31249a6844d5SKenneth D. Merry }
31259a6844d5SKenneth D. Merry case ADA_CCB_IDDIR: {
31269a6844d5SKenneth D. Merry int error;
31279a6844d5SKenneth D. Merry
31289a6844d5SKenneth D. Merry if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
31299a6844d5SKenneth D. Merry off_t entries_offset, max_entries;
31309a6844d5SKenneth D. Merry error = 0;
31319a6844d5SKenneth D. Merry
31329a6844d5SKenneth D. Merry softc->valid_iddir_len = 0;
31339a6844d5SKenneth D. Merry bzero(&softc->ata_iddir, sizeof(softc->ata_iddir));
31349a6844d5SKenneth D. Merry softc->flags &= ~(ADA_FLAG_CAN_SUPCAP |
31359a6844d5SKenneth D. Merry ADA_FLAG_CAN_ZONE);
31369a6844d5SKenneth D. Merry softc->valid_iddir_len =
31379a6844d5SKenneth D. Merry ataio->dxfer_len - ataio->resid;
31389a6844d5SKenneth D. Merry if (softc->valid_iddir_len > 0)
31399a6844d5SKenneth D. Merry bcopy(ataio->data_ptr, &softc->ata_iddir,
31409a6844d5SKenneth D. Merry min(softc->valid_iddir_len,
31419a6844d5SKenneth D. Merry sizeof(softc->ata_iddir)));
31429a6844d5SKenneth D. Merry
31439a6844d5SKenneth D. Merry entries_offset =
31449a6844d5SKenneth D. Merry __offsetof(struct ata_identify_log_pages,entries);
31459a6844d5SKenneth D. Merry max_entries = softc->valid_iddir_len - entries_offset;
31469a6844d5SKenneth D. Merry if ((softc->valid_iddir_len > (entries_offset + 1))
31479a6844d5SKenneth D. Merry && (le64dec(softc->ata_iddir.header) ==
31489a6844d5SKenneth D. Merry ATA_IDLOG_REVISION)
31499a6844d5SKenneth D. Merry && (softc->ata_iddir.entry_count > 0)) {
31509a6844d5SKenneth D. Merry int num_entries, i;
31519a6844d5SKenneth D. Merry
31529a6844d5SKenneth D. Merry num_entries = softc->ata_iddir.entry_count;
31539a6844d5SKenneth D. Merry num_entries = min(num_entries,
31549a6844d5SKenneth D. Merry softc->valid_iddir_len - entries_offset);
31559a6844d5SKenneth D. Merry for (i = 0; i < num_entries &&
31569a6844d5SKenneth D. Merry i < max_entries; i++) {
31579a6844d5SKenneth D. Merry if (softc->ata_iddir.entries[i] ==
31589a6844d5SKenneth D. Merry ATA_IDL_SUP_CAP)
31599a6844d5SKenneth D. Merry softc->flags |=
31609a6844d5SKenneth D. Merry ADA_FLAG_CAN_SUPCAP;
31619a6844d5SKenneth D. Merry else if (softc->ata_iddir.entries[i]==
31629a6844d5SKenneth D. Merry ATA_IDL_ZDI)
31639a6844d5SKenneth D. Merry softc->flags |=
31649a6844d5SKenneth D. Merry ADA_FLAG_CAN_ZONE;
31659a6844d5SKenneth D. Merry
31669a6844d5SKenneth D. Merry if ((softc->flags &
31679a6844d5SKenneth D. Merry ADA_FLAG_CAN_SUPCAP)
31689a6844d5SKenneth D. Merry && (softc->flags &
31699a6844d5SKenneth D. Merry ADA_FLAG_CAN_ZONE))
31709a6844d5SKenneth D. Merry break;
31719a6844d5SKenneth D. Merry }
31729a6844d5SKenneth D. Merry }
31739a6844d5SKenneth D. Merry } else {
31749a6844d5SKenneth D. Merry error = adaerror(done_ccb, CAM_RETRY_SELTO,
31759a6844d5SKenneth D. Merry SF_RETRY_UA|SF_NO_PRINT);
31769a6844d5SKenneth D. Merry if (error == ERESTART)
31779a6844d5SKenneth D. Merry return;
31789a6844d5SKenneth D. Merry else if (error != 0) {
31799a6844d5SKenneth D. Merry /*
31809a6844d5SKenneth D. Merry * If we can't get the ATA Identify Data log
31819a6844d5SKenneth D. Merry * directory, then it effectively isn't
31829a6844d5SKenneth D. Merry * supported even if the ATA Log directory
31839a6844d5SKenneth D. Merry * a non-zero number of pages present for
31849a6844d5SKenneth D. Merry * this log.
31859a6844d5SKenneth D. Merry */
31869a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_IDLOG;
31879a6844d5SKenneth D. Merry if ((done_ccb->ccb_h.status &
31889a6844d5SKenneth D. Merry CAM_DEV_QFRZN) != 0) {
31899a6844d5SKenneth D. Merry /* Don't wedge this device's queue */
31909a6844d5SKenneth D. Merry cam_release_devq(done_ccb->ccb_h.path,
31919a6844d5SKenneth D. Merry /*relsim_flags*/0,
31929a6844d5SKenneth D. Merry /*reduction*/0,
31939a6844d5SKenneth D. Merry /*timeout*/0,
31949a6844d5SKenneth D. Merry /*getcount_only*/0);
31959a6844d5SKenneth D. Merry }
31969a6844d5SKenneth D. Merry }
31979a6844d5SKenneth D. Merry }
31989a6844d5SKenneth D. Merry
31999a6844d5SKenneth D. Merry free(ataio->data_ptr, M_ATADA);
32009a6844d5SKenneth D. Merry
32019a6844d5SKenneth D. Merry if ((error == 0)
32029a6844d5SKenneth D. Merry && (softc->flags & ADA_FLAG_CAN_SUPCAP)) {
32039a6844d5SKenneth D. Merry softc->state = ADA_STATE_SUP_CAP;
32049a6844d5SKenneth D. Merry xpt_release_ccb(done_ccb);
32059a6844d5SKenneth D. Merry xpt_schedule(periph, priority);
32069a6844d5SKenneth D. Merry } else
32079a6844d5SKenneth D. Merry adaprobedone(periph, done_ccb);
32089a6844d5SKenneth D. Merry return;
32099a6844d5SKenneth D. Merry }
32109a6844d5SKenneth D. Merry case ADA_CCB_SUP_CAP: {
32119a6844d5SKenneth D. Merry int error;
32129a6844d5SKenneth D. Merry
32139a6844d5SKenneth D. Merry if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
32149a6844d5SKenneth D. Merry uint32_t valid_len;
32159a6844d5SKenneth D. Merry size_t needed_size;
32169a6844d5SKenneth D. Merry struct ata_identify_log_sup_cap *sup_cap;
32179a6844d5SKenneth D. Merry error = 0;
32189a6844d5SKenneth D. Merry
32199a6844d5SKenneth D. Merry sup_cap = (struct ata_identify_log_sup_cap *)
32209a6844d5SKenneth D. Merry ataio->data_ptr;
32219a6844d5SKenneth D. Merry valid_len = ataio->dxfer_len - ataio->resid;
32229a6844d5SKenneth D. Merry needed_size =
32239a6844d5SKenneth D. Merry __offsetof(struct ata_identify_log_sup_cap,
32249a6844d5SKenneth D. Merry sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap);
32259a6844d5SKenneth D. Merry if (valid_len >= needed_size) {
32269a6844d5SKenneth D. Merry uint64_t zoned, zac_cap;
32279a6844d5SKenneth D. Merry
32289a6844d5SKenneth D. Merry zoned = le64dec(sup_cap->zoned_cap);
32299a6844d5SKenneth D. Merry if (zoned & ATA_ZONED_VALID) {
32309a6844d5SKenneth D. Merry /*
32319a6844d5SKenneth D. Merry * This should have already been
32329a6844d5SKenneth D. Merry * set, because this is also in the
32339a6844d5SKenneth D. Merry * ATA identify data.
32349a6844d5SKenneth D. Merry */
32359a6844d5SKenneth D. Merry if ((zoned & ATA_ZONED_MASK) ==
32369a6844d5SKenneth D. Merry ATA_SUPPORT_ZONE_HOST_AWARE)
32379a6844d5SKenneth D. Merry softc->zone_mode =
32389a6844d5SKenneth D. Merry ADA_ZONE_HOST_AWARE;
32399a6844d5SKenneth D. Merry else if ((zoned & ATA_ZONED_MASK) ==
32409a6844d5SKenneth D. Merry ATA_SUPPORT_ZONE_DEV_MANAGED)
32419a6844d5SKenneth D. Merry softc->zone_mode =
32429a6844d5SKenneth D. Merry ADA_ZONE_DRIVE_MANAGED;
32439a6844d5SKenneth D. Merry }
32449a6844d5SKenneth D. Merry
32459a6844d5SKenneth D. Merry zac_cap = le64dec(sup_cap->sup_zac_cap);
32469a6844d5SKenneth D. Merry if (zac_cap & ATA_SUP_ZAC_CAP_VALID) {
32479a6844d5SKenneth D. Merry if (zac_cap & ATA_REPORT_ZONES_SUP)
32489a6844d5SKenneth D. Merry softc->zone_flags |=
32499a6844d5SKenneth D. Merry ADA_ZONE_FLAG_RZ_SUP;
32509a6844d5SKenneth D. Merry if (zac_cap & ATA_ND_OPEN_ZONE_SUP)
32519a6844d5SKenneth D. Merry softc->zone_flags |=
32529a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPEN_SUP;
32539a6844d5SKenneth D. Merry if (zac_cap & ATA_ND_CLOSE_ZONE_SUP)
32549a6844d5SKenneth D. Merry softc->zone_flags |=
32559a6844d5SKenneth D. Merry ADA_ZONE_FLAG_CLOSE_SUP;
32569a6844d5SKenneth D. Merry if (zac_cap & ATA_ND_FINISH_ZONE_SUP)
32579a6844d5SKenneth D. Merry softc->zone_flags |=
32589a6844d5SKenneth D. Merry ADA_ZONE_FLAG_FINISH_SUP;
32599a6844d5SKenneth D. Merry if (zac_cap & ATA_ND_RWP_SUP)
32609a6844d5SKenneth D. Merry softc->zone_flags |=
32619a6844d5SKenneth D. Merry ADA_ZONE_FLAG_RWP_SUP;
32629a6844d5SKenneth D. Merry } else {
32639a6844d5SKenneth D. Merry /*
32649a6844d5SKenneth D. Merry * This field was introduced in
32659a6844d5SKenneth D. Merry * ACS-4, r08 on April 28th, 2015.
32669a6844d5SKenneth D. Merry * If the drive firmware was written
32679a6844d5SKenneth D. Merry * to an earlier spec, it won't have
32689a6844d5SKenneth D. Merry * the field. So, assume all
32699a6844d5SKenneth D. Merry * commands are supported.
32709a6844d5SKenneth D. Merry */
32719a6844d5SKenneth D. Merry softc->zone_flags |=
32729a6844d5SKenneth D. Merry ADA_ZONE_FLAG_SUP_MASK;
32739a6844d5SKenneth D. Merry }
32749a6844d5SKenneth D. Merry }
32759a6844d5SKenneth D. Merry } else {
32769a6844d5SKenneth D. Merry error = adaerror(done_ccb, CAM_RETRY_SELTO,
32779a6844d5SKenneth D. Merry SF_RETRY_UA|SF_NO_PRINT);
32789a6844d5SKenneth D. Merry if (error == ERESTART)
32799a6844d5SKenneth D. Merry return;
32809a6844d5SKenneth D. Merry else if (error != 0) {
32819a6844d5SKenneth D. Merry /*
32829a6844d5SKenneth D. Merry * If we can't get the ATA Identify Data
32839a6844d5SKenneth D. Merry * Supported Capabilities page, clear the
32849a6844d5SKenneth D. Merry * flag...
32859a6844d5SKenneth D. Merry */
32869a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_SUPCAP;
32879a6844d5SKenneth D. Merry /*
32889a6844d5SKenneth D. Merry * And clear zone capabilities.
32899a6844d5SKenneth D. Merry */
32909a6844d5SKenneth D. Merry softc->zone_flags &= ~ADA_ZONE_FLAG_SUP_MASK;
32919a6844d5SKenneth D. Merry if ((done_ccb->ccb_h.status &
32929a6844d5SKenneth D. Merry CAM_DEV_QFRZN) != 0) {
32939a6844d5SKenneth D. Merry /* Don't wedge this device's queue */
32949a6844d5SKenneth D. Merry cam_release_devq(done_ccb->ccb_h.path,
32959a6844d5SKenneth D. Merry /*relsim_flags*/0,
32969a6844d5SKenneth D. Merry /*reduction*/0,
32979a6844d5SKenneth D. Merry /*timeout*/0,
32989a6844d5SKenneth D. Merry /*getcount_only*/0);
32999a6844d5SKenneth D. Merry }
33009a6844d5SKenneth D. Merry }
33019a6844d5SKenneth D. Merry }
33029a6844d5SKenneth D. Merry
33039a6844d5SKenneth D. Merry free(ataio->data_ptr, M_ATADA);
33049a6844d5SKenneth D. Merry
33059a6844d5SKenneth D. Merry if ((error == 0)
33069a6844d5SKenneth D. Merry && (softc->flags & ADA_FLAG_CAN_ZONE)) {
33079a6844d5SKenneth D. Merry softc->state = ADA_STATE_ZONE;
33089a6844d5SKenneth D. Merry xpt_release_ccb(done_ccb);
33099a6844d5SKenneth D. Merry xpt_schedule(periph, priority);
33109a6844d5SKenneth D. Merry } else
33119a6844d5SKenneth D. Merry adaprobedone(periph, done_ccb);
33129a6844d5SKenneth D. Merry return;
33139a6844d5SKenneth D. Merry }
33149a6844d5SKenneth D. Merry case ADA_CCB_ZONE: {
33159a6844d5SKenneth D. Merry int error;
33169a6844d5SKenneth D. Merry
33179a6844d5SKenneth D. Merry if ((ataio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
33189a6844d5SKenneth D. Merry struct ata_zoned_info_log *zi_log;
33199a6844d5SKenneth D. Merry uint32_t valid_len;
33209a6844d5SKenneth D. Merry size_t needed_size;
33219a6844d5SKenneth D. Merry
33229a6844d5SKenneth D. Merry zi_log = (struct ata_zoned_info_log *)ataio->data_ptr;
33239a6844d5SKenneth D. Merry
33249a6844d5SKenneth D. Merry valid_len = ataio->dxfer_len - ataio->resid;
33259a6844d5SKenneth D. Merry needed_size = __offsetof(struct ata_zoned_info_log,
33269a6844d5SKenneth D. Merry version_info) + 1 + sizeof(zi_log->version_info);
33279a6844d5SKenneth D. Merry if (valid_len >= needed_size) {
33289a6844d5SKenneth D. Merry uint64_t tmpvar;
33299a6844d5SKenneth D. Merry
33309a6844d5SKenneth D. Merry tmpvar = le64dec(zi_log->zoned_cap);
33319a6844d5SKenneth D. Merry if (tmpvar & ATA_ZDI_CAP_VALID) {
33329a6844d5SKenneth D. Merry if (tmpvar & ATA_ZDI_CAP_URSWRZ)
33339a6844d5SKenneth D. Merry softc->zone_flags |=
33349a6844d5SKenneth D. Merry ADA_ZONE_FLAG_URSWRZ;
33359a6844d5SKenneth D. Merry else
33369a6844d5SKenneth D. Merry softc->zone_flags &=
33379a6844d5SKenneth D. Merry ~ADA_ZONE_FLAG_URSWRZ;
33389a6844d5SKenneth D. Merry }
33399a6844d5SKenneth D. Merry tmpvar = le64dec(zi_log->optimal_seq_zones);
33409a6844d5SKenneth D. Merry if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) {
33419a6844d5SKenneth D. Merry softc->zone_flags |=
33429a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPT_SEQ_SET;
33439a6844d5SKenneth D. Merry softc->optimal_seq_zones = (tmpvar &
33449a6844d5SKenneth D. Merry ATA_ZDI_OPT_SEQ_MASK);
33459a6844d5SKenneth D. Merry } else {
33469a6844d5SKenneth D. Merry softc->zone_flags &=
33479a6844d5SKenneth D. Merry ~ADA_ZONE_FLAG_OPT_SEQ_SET;
33489a6844d5SKenneth D. Merry softc->optimal_seq_zones = 0;
33499a6844d5SKenneth D. Merry }
33509a6844d5SKenneth D. Merry
33519a6844d5SKenneth D. Merry tmpvar =le64dec(zi_log->optimal_nonseq_zones);
33529a6844d5SKenneth D. Merry if (tmpvar & ATA_ZDI_OPT_NS_VALID) {
33539a6844d5SKenneth D. Merry softc->zone_flags |=
33549a6844d5SKenneth D. Merry ADA_ZONE_FLAG_OPT_NONSEQ_SET;
33559a6844d5SKenneth D. Merry softc->optimal_nonseq_zones =
33569a6844d5SKenneth D. Merry (tmpvar & ATA_ZDI_OPT_NS_MASK);
33579a6844d5SKenneth D. Merry } else {
33589a6844d5SKenneth D. Merry softc->zone_flags &=
33599a6844d5SKenneth D. Merry ~ADA_ZONE_FLAG_OPT_NONSEQ_SET;
33609a6844d5SKenneth D. Merry softc->optimal_nonseq_zones = 0;
33619a6844d5SKenneth D. Merry }
33629a6844d5SKenneth D. Merry
33639a6844d5SKenneth D. Merry tmpvar = le64dec(zi_log->max_seq_req_zones);
33649a6844d5SKenneth D. Merry if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) {
33659a6844d5SKenneth D. Merry softc->zone_flags |=
33669a6844d5SKenneth D. Merry ADA_ZONE_FLAG_MAX_SEQ_SET;
33679a6844d5SKenneth D. Merry softc->max_seq_zones =
33689a6844d5SKenneth D. Merry (tmpvar & ATA_ZDI_MAX_SEQ_MASK);
33699a6844d5SKenneth D. Merry } else {
33709a6844d5SKenneth D. Merry softc->zone_flags &=
33719a6844d5SKenneth D. Merry ~ADA_ZONE_FLAG_MAX_SEQ_SET;
33729a6844d5SKenneth D. Merry softc->max_seq_zones = 0;
33739a6844d5SKenneth D. Merry }
33749a6844d5SKenneth D. Merry }
33759a6844d5SKenneth D. Merry } else {
33769a6844d5SKenneth D. Merry error = adaerror(done_ccb, CAM_RETRY_SELTO,
33779a6844d5SKenneth D. Merry SF_RETRY_UA|SF_NO_PRINT);
33789a6844d5SKenneth D. Merry if (error == ERESTART)
33799a6844d5SKenneth D. Merry return;
33809a6844d5SKenneth D. Merry else if (error != 0) {
33819a6844d5SKenneth D. Merry softc->flags &= ~ADA_FLAG_CAN_ZONE;
33829a6844d5SKenneth D. Merry softc->flags &= ~ADA_ZONE_FLAG_SET_MASK;
33839a6844d5SKenneth D. Merry
33849a6844d5SKenneth D. Merry if ((done_ccb->ccb_h.status &
33859a6844d5SKenneth D. Merry CAM_DEV_QFRZN) != 0) {
33869a6844d5SKenneth D. Merry /* Don't wedge this device's queue */
33879a6844d5SKenneth D. Merry cam_release_devq(done_ccb->ccb_h.path,
33889a6844d5SKenneth D. Merry /*relsim_flags*/0,
33899a6844d5SKenneth D. Merry /*reduction*/0,
33909a6844d5SKenneth D. Merry /*timeout*/0,
33919a6844d5SKenneth D. Merry /*getcount_only*/0);
33929a6844d5SKenneth D. Merry }
33939a6844d5SKenneth D. Merry }
33949a6844d5SKenneth D. Merry }
33959a6844d5SKenneth D. Merry free(ataio->data_ptr, M_ATADA);
33969a6844d5SKenneth D. Merry
33979a6844d5SKenneth D. Merry adaprobedone(periph, done_ccb);
3398f513d14cSAlexander Motin return;
3399f513d14cSAlexander Motin }
340052c9ce25SScott Long case ADA_CCB_DUMP:
340152c9ce25SScott Long /* No-op. We're polling */
340252c9ce25SScott Long return;
340352c9ce25SScott Long default:
340452c9ce25SScott Long break;
340552c9ce25SScott Long }
340652c9ce25SScott Long xpt_release_ccb(done_ccb);
340752c9ce25SScott Long }
340852c9ce25SScott Long
340952c9ce25SScott Long static int
adaerror(union ccb * ccb,uint32_t cam_flags,uint32_t sense_flags)34109db2db6bSWarner Losh adaerror(union ccb *ccb, uint32_t cam_flags, uint32_t sense_flags)
341152c9ce25SScott Long {
3412acfc9b68SWarner Losh #ifdef CAM_IO_STATS
3413a6e0c5daSWarner Losh struct ada_softc *softc;
3414a6e0c5daSWarner Losh struct cam_periph *periph;
3415a6e0c5daSWarner Losh
3416a6e0c5daSWarner Losh periph = xpt_path_periph(ccb->ccb_h.path);
3417a6e0c5daSWarner Losh softc = (struct ada_softc *)periph->softc;
3418a6e0c5daSWarner Losh
3419a6e0c5daSWarner Losh switch (ccb->ccb_h.status & CAM_STATUS_MASK) {
3420a6e0c5daSWarner Losh case CAM_CMD_TIMEOUT:
3421a6e0c5daSWarner Losh softc->timeouts++;
3422a6e0c5daSWarner Losh break;
3423a6e0c5daSWarner Losh case CAM_REQ_ABORTED:
3424a6e0c5daSWarner Losh case CAM_REQ_CMP_ERR:
3425a6e0c5daSWarner Losh case CAM_REQ_TERMIO:
3426a6e0c5daSWarner Losh case CAM_UNREC_HBA_ERROR:
3427a6e0c5daSWarner Losh case CAM_DATA_RUN_ERR:
3428a6e0c5daSWarner Losh case CAM_ATA_STATUS_ERROR:
3429a6e0c5daSWarner Losh softc->errors++;
3430a6e0c5daSWarner Losh break;
3431a6e0c5daSWarner Losh default:
3432a6e0c5daSWarner Losh break;
3433a6e0c5daSWarner Losh }
3434acfc9b68SWarner Losh #endif
343552c9ce25SScott Long
3436553484aeSWarner Losh return(cam_periph_error(ccb, cam_flags, sense_flags));
343752c9ce25SScott Long }
343852c9ce25SScott Long
343952c9ce25SScott Long static void
adasetgeom(struct ada_softc * softc,struct ccb_getdev * cgd)344076d843daSAlexander Motin adasetgeom(struct ada_softc *softc, struct ccb_getdev *cgd)
344152c9ce25SScott Long {
344252c9ce25SScott Long struct disk_params *dp = &softc->params;
34439db2db6bSWarner Losh uint64_t lbasize48;
34449db2db6bSWarner Losh uint32_t lbasize;
344576d843daSAlexander Motin u_int maxio, d_flags;
3446f350bc1dSJessica Clarke size_t tmpsize;
344752c9ce25SScott Long
3448c1bd46c2SAlexander Motin dp->secsize = ata_logical_sector_size(&cgd->ident_data);
344952c9ce25SScott Long if ((cgd->ident_data.atavalid & ATA_FLAG_54_58) &&
345076d843daSAlexander Motin cgd->ident_data.current_heads != 0 &&
345176d843daSAlexander Motin cgd->ident_data.current_sectors != 0) {
345252c9ce25SScott Long dp->heads = cgd->ident_data.current_heads;
345352c9ce25SScott Long dp->secs_per_track = cgd->ident_data.current_sectors;
345452c9ce25SScott Long dp->cylinders = cgd->ident_data.cylinders;
34559db2db6bSWarner Losh dp->sectors = (uint32_t)cgd->ident_data.current_size_1 |
34569db2db6bSWarner Losh ((uint32_t)cgd->ident_data.current_size_2 << 16);
345752c9ce25SScott Long } else {
345852c9ce25SScott Long dp->heads = cgd->ident_data.heads;
345952c9ce25SScott Long dp->secs_per_track = cgd->ident_data.sectors;
346052c9ce25SScott Long dp->cylinders = cgd->ident_data.cylinders;
346199ae1d3bSAlan Somers dp->sectors = cgd->ident_data.cylinders *
34629db2db6bSWarner Losh (uint32_t)(dp->heads * dp->secs_per_track);
346352c9ce25SScott Long }
34649db2db6bSWarner Losh lbasize = (uint32_t)cgd->ident_data.lba_size_1 |
34659db2db6bSWarner Losh ((uint32_t)cgd->ident_data.lba_size_2 << 16);
346652c9ce25SScott Long
346752c9ce25SScott Long /* use the 28bit LBA size if valid or bigger than the CHS mapping */
346852c9ce25SScott Long if (cgd->ident_data.cylinders == 16383 || dp->sectors < lbasize)
346952c9ce25SScott Long dp->sectors = lbasize;
347052c9ce25SScott Long
347152c9ce25SScott Long /* use the 48bit LBA size if valid */
34729db2db6bSWarner Losh lbasize48 = ((uint64_t)cgd->ident_data.lba_size48_1) |
34739db2db6bSWarner Losh ((uint64_t)cgd->ident_data.lba_size48_2 << 16) |
34749db2db6bSWarner Losh ((uint64_t)cgd->ident_data.lba_size48_3 << 32) |
34759db2db6bSWarner Losh ((uint64_t)cgd->ident_data.lba_size48_4 << 48);
347652c9ce25SScott Long if ((cgd->ident_data.support.command2 & ATA_SUPPORT_ADDRESS48) &&
347752c9ce25SScott Long lbasize48 > ATA_MAX_28BIT_LBA)
347852c9ce25SScott Long dp->sectors = lbasize48;
347976d843daSAlexander Motin
348076d843daSAlexander Motin maxio = softc->cpi.maxio; /* Honor max I/O size of SIM */
348176d843daSAlexander Motin if (maxio == 0)
348276d843daSAlexander Motin maxio = DFLTPHYS; /* traditional default */
3483cd853791SKonstantin Belousov else if (maxio > maxphys)
3484cd853791SKonstantin Belousov maxio = maxphys; /* for safety */
348576d843daSAlexander Motin if (softc->flags & ADA_FLAG_CAN_48BIT)
348676d843daSAlexander Motin maxio = min(maxio, 65536 * softc->params.secsize);
348776d843daSAlexander Motin else /* 28bit ATA command limit */
348876d843daSAlexander Motin maxio = min(maxio, 256 * softc->params.secsize);
348976d843daSAlexander Motin if (softc->quirks & ADA_Q_128KB)
349076d843daSAlexander Motin maxio = min(maxio, 128 * 1024);
349176d843daSAlexander Motin softc->disk->d_maxsize = maxio;
349276d843daSAlexander Motin d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE;
349376d843daSAlexander Motin if (softc->flags & ADA_FLAG_CAN_FLUSHCACHE)
349476d843daSAlexander Motin d_flags |= DISKFLAG_CANFLUSHCACHE;
349576d843daSAlexander Motin if (softc->flags & ADA_FLAG_CAN_TRIM) {
349676d843daSAlexander Motin d_flags |= DISKFLAG_CANDELETE;
349776d843daSAlexander Motin softc->disk->d_delmaxsize = softc->params.secsize *
349876d843daSAlexander Motin ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
349976d843daSAlexander Motin } else if ((softc->flags & ADA_FLAG_CAN_CFA) &&
350076d843daSAlexander Motin !(softc->flags & ADA_FLAG_CAN_48BIT)) {
350176d843daSAlexander Motin d_flags |= DISKFLAG_CANDELETE;
350276d843daSAlexander Motin softc->disk->d_delmaxsize = 256 * softc->params.secsize;
350376d843daSAlexander Motin } else
350476d843daSAlexander Motin softc->disk->d_delmaxsize = maxio;
350576d843daSAlexander Motin if ((softc->cpi.hba_misc & PIM_UNMAPPED) != 0) {
350676d843daSAlexander Motin d_flags |= DISKFLAG_UNMAPPED_BIO;
3507cf3ff63eSWarner Losh softc->flags |= ADA_FLAG_UNMAPPEDIO;
350876d843daSAlexander Motin }
350976d843daSAlexander Motin softc->disk->d_flags = d_flags;
3510f350bc1dSJessica Clarke
3511f350bc1dSJessica Clarke /*
3512f350bc1dSJessica Clarke * ata_param_fixup will strip trailing padding spaces and add a NUL,
3513f350bc1dSJessica Clarke * but if the field has no padding (as is common for serial numbers)
3514f350bc1dSJessica Clarke * there will still be no NUL terminator. We cannot use strlcpy, since
3515f350bc1dSJessica Clarke * it keeps reading src until it finds a NUL in order to compute the
3516f350bc1dSJessica Clarke * return value (and will truncate the final character due to having a
3517f350bc1dSJessica Clarke * single dsize rather than separate ssize and dsize), and strncpy does
3518f350bc1dSJessica Clarke * not add a NUL to the destination if it reaches the character limit.
3519f350bc1dSJessica Clarke */
3520f350bc1dSJessica Clarke tmpsize = MIN(sizeof(softc->disk->d_descr) - 1,
3521f350bc1dSJessica Clarke sizeof(cgd->ident_data.model));
3522f350bc1dSJessica Clarke memcpy(softc->disk->d_descr, cgd->ident_data.model, tmpsize);
3523f350bc1dSJessica Clarke softc->disk->d_descr[tmpsize] = '\0';
3524f350bc1dSJessica Clarke
3525f350bc1dSJessica Clarke tmpsize = MIN(sizeof(softc->disk->d_ident) - 1,
3526f350bc1dSJessica Clarke sizeof(cgd->ident_data.serial));
3527f350bc1dSJessica Clarke memcpy(softc->disk->d_ident, cgd->ident_data.serial, tmpsize);
3528f350bc1dSJessica Clarke softc->disk->d_ident[tmpsize] = '\0';
352976d843daSAlexander Motin
353076d843daSAlexander Motin softc->disk->d_sectorsize = softc->params.secsize;
353176d843daSAlexander Motin softc->disk->d_mediasize = (off_t)softc->params.sectors *
353276d843daSAlexander Motin softc->params.secsize;
353376d843daSAlexander Motin if (ata_physical_sector_size(&cgd->ident_data) !=
353476d843daSAlexander Motin softc->params.secsize) {
353576d843daSAlexander Motin softc->disk->d_stripesize =
353676d843daSAlexander Motin ata_physical_sector_size(&cgd->ident_data);
353776d843daSAlexander Motin softc->disk->d_stripeoffset = (softc->disk->d_stripesize -
353876d843daSAlexander Motin ata_logical_sector_offset(&cgd->ident_data)) %
353976d843daSAlexander Motin softc->disk->d_stripesize;
354076d843daSAlexander Motin } else if (softc->quirks & ADA_Q_4K) {
354176d843daSAlexander Motin softc->disk->d_stripesize = 4096;
354276d843daSAlexander Motin softc->disk->d_stripeoffset = 0;
354376d843daSAlexander Motin }
354476d843daSAlexander Motin softc->disk->d_fwsectors = softc->params.secs_per_track;
354576d843daSAlexander Motin softc->disk->d_fwheads = softc->params.heads;
354676d843daSAlexander Motin softc->disk->d_rotation_rate = cgd->ident_data.media_rotation_rate;
3547b5961be1SEdward Tomasz Napierala snprintf(softc->disk->d_attachment, sizeof(softc->disk->d_attachment),
3548b5961be1SEdward Tomasz Napierala "%s%d", softc->cpi.dev_name, softc->cpi.unit_number);
354952c9ce25SScott Long }
355052c9ce25SScott Long
355152c9ce25SScott Long static void
adasendorderedtag(void * arg)355252c9ce25SScott Long adasendorderedtag(void *arg)
355352c9ce25SScott Long {
355452c9ce25SScott Long struct ada_softc *softc = arg;
355552c9ce25SScott Long
355652c9ce25SScott Long if (ada_send_ordered) {
3557030844d1SAlexander Motin if (softc->outstanding_cmds > 0) {
3558030844d1SAlexander Motin if ((softc->flags & ADA_FLAG_WAS_OTAG) == 0)
355952c9ce25SScott Long softc->flags |= ADA_FLAG_NEED_OTAG;
3560030844d1SAlexander Motin softc->flags &= ~ADA_FLAG_WAS_OTAG;
356152c9ce25SScott Long }
356252c9ce25SScott Long }
35630e5c50bfSAlexander Motin
356452c9ce25SScott Long /* Queue us up again */
35650e5c50bfSAlexander Motin callout_schedule_sbt(&softc->sendordered_c,
35660e5c50bfSAlexander Motin SBT_1S / ADA_ORDEREDTAG_INTERVAL * ada_default_timeout, 0,
35670e5c50bfSAlexander Motin C_PREL(1));
356852c9ce25SScott Long }
356952c9ce25SScott Long
357052c9ce25SScott Long /*
357152c9ce25SScott Long * Step through all ADA peripheral drivers, and if the device is still open,
357252c9ce25SScott Long * sync the disk cache to physical media.
357352c9ce25SScott Long */
357452c9ce25SScott Long static void
adaflush(void)3575c3d0d168SAlexander Motin adaflush(void)
357652c9ce25SScott Long {
357752c9ce25SScott Long struct cam_periph *periph;
357852c9ce25SScott Long struct ada_softc *softc;
357909cfadbeSAlexander Motin union ccb *ccb;
35800191d9b3SAlexander Motin int error;
358152c9ce25SScott Long
3582f371c9e2SAlexander Motin CAM_PERIPH_FOREACH(periph, &adadriver) {
358352c9ce25SScott Long softc = (struct ada_softc *)periph->softc;
35842f87dfb0SAlexander Motin if (SCHEDULER_STOPPED()) {
358549dace1dSGordon Bergling /* If we panicked with the lock held, do not recurse. */
35862f87dfb0SAlexander Motin if (!cam_periph_owned(periph) &&
35872f87dfb0SAlexander Motin (softc->flags & ADA_FLAG_OPEN)) {
3588489ba222SMitchell Horne adadump(softc->disk, NULL, 0, 0);
35892f87dfb0SAlexander Motin }
35902f87dfb0SAlexander Motin continue;
35912f87dfb0SAlexander Motin }
35922f87dfb0SAlexander Motin cam_periph_lock(periph);
359352c9ce25SScott Long /*
359452c9ce25SScott Long * We only sync the cache if the drive is still open, and
359552c9ce25SScott Long * if the drive is capable of it..
359652c9ce25SScott Long */
359752c9ce25SScott Long if (((softc->flags & ADA_FLAG_OPEN) == 0) ||
359852c9ce25SScott Long (softc->flags & ADA_FLAG_CAN_FLUSHCACHE) == 0) {
359952c9ce25SScott Long cam_periph_unlock(periph);
360052c9ce25SScott Long continue;
360152c9ce25SScott Long }
360252c9ce25SScott Long
360309cfadbeSAlexander Motin ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
360409cfadbeSAlexander Motin cam_fill_ataio(&ccb->ataio,
36050191d9b3SAlexander Motin 0,
3606eed99e75SScott Long NULL,
360752c9ce25SScott Long CAM_DIR_NONE,
360852c9ce25SScott Long 0,
360952c9ce25SScott Long NULL,
361052c9ce25SScott Long 0,
361152c9ce25SScott Long ada_default_timeout*1000);
361252c9ce25SScott Long if (softc->flags & ADA_FLAG_CAN_48BIT)
361309cfadbeSAlexander Motin ata_48bit_cmd(&ccb->ataio, ATA_FLUSHCACHE48, 0, 0, 0);
361452c9ce25SScott Long else
361509cfadbeSAlexander Motin ata_28bit_cmd(&ccb->ataio, ATA_FLUSHCACHE, 0, 0, 0);
361652c9ce25SScott Long
361709cfadbeSAlexander Motin error = cam_periph_runccb(ccb, adaerror, /*cam_flags*/0,
361809cfadbeSAlexander Motin /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY,
361909cfadbeSAlexander Motin softc->disk->d_devstat);
36200191d9b3SAlexander Motin if (error != 0)
36210191d9b3SAlexander Motin xpt_print(periph->path, "Synchronize cache failed\n");
3622d6794b70SAlexander Motin xpt_release_ccb(ccb);
362352c9ce25SScott Long cam_periph_unlock(periph);
362452c9ce25SScott Long }
3625c3d0d168SAlexander Motin }
3626fd104c15SRebecca Cran
3627c3d0d168SAlexander Motin static void
adaspindown(uint8_t cmd,int flags)3628c3d0d168SAlexander Motin adaspindown(uint8_t cmd, int flags)
3629c3d0d168SAlexander Motin {
3630c3d0d168SAlexander Motin struct cam_periph *periph;
3631c3d0d168SAlexander Motin struct ada_softc *softc;
3632f902366cSWarner Losh struct ccb_ataio local_ccb;
36330191d9b3SAlexander Motin int error;
363415910dc0SAndriy Gapon int mode;
3635fd104c15SRebecca Cran
3636f371c9e2SAlexander Motin CAM_PERIPH_FOREACH(periph, &adadriver) {
363749dace1dSGordon Bergling /* If we panicked with lock held - not recurse here. */
3638fd104c15SRebecca Cran if (cam_periph_owned(periph))
3639fd104c15SRebecca Cran continue;
3640fd104c15SRebecca Cran cam_periph_lock(periph);
3641fd104c15SRebecca Cran softc = (struct ada_softc *)periph->softc;
3642fd104c15SRebecca Cran /*
3643fd104c15SRebecca Cran * We only spin-down the drive if it is capable of it..
3644fd104c15SRebecca Cran */
3645fd104c15SRebecca Cran if ((softc->flags & ADA_FLAG_CAN_POWERMGT) == 0) {
3646fd104c15SRebecca Cran cam_periph_unlock(periph);
3647fd104c15SRebecca Cran continue;
3648fd104c15SRebecca Cran }
3649fd104c15SRebecca Cran
365015910dc0SAndriy Gapon /*
365115910dc0SAndriy Gapon * Additionally check if we would spin up the drive instead of
365215910dc0SAndriy Gapon * spinning it down.
365315910dc0SAndriy Gapon */
365415910dc0SAndriy Gapon if (cmd == ATA_IDLE_IMMEDIATE) {
365515910dc0SAndriy Gapon memset(&local_ccb, 0, sizeof(local_ccb));
365615910dc0SAndriy Gapon xpt_setup_ccb(&local_ccb.ccb_h, periph->path,
365715910dc0SAndriy Gapon CAM_PRIORITY_NORMAL);
365815910dc0SAndriy Gapon local_ccb.ccb_h.ccb_state = ADA_CCB_DUMP;
365915910dc0SAndriy Gapon
366015910dc0SAndriy Gapon cam_fill_ataio(&local_ccb, 0, NULL, CAM_DIR_NONE,
366115910dc0SAndriy Gapon 0, NULL, 0, ada_default_timeout * 1000);
366215910dc0SAndriy Gapon ata_28bit_cmd(&local_ccb, ATA_CHECK_POWER_MODE,
366315910dc0SAndriy Gapon 0, 0, 0);
366415910dc0SAndriy Gapon local_ccb.cmd.flags |= CAM_ATAIO_NEEDRESULT;
366515910dc0SAndriy Gapon
366615910dc0SAndriy Gapon error = cam_periph_runccb((union ccb *)&local_ccb,
366715910dc0SAndriy Gapon adaerror, /*cam_flags*/0,
366815910dc0SAndriy Gapon /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY,
366915910dc0SAndriy Gapon softc->disk->d_devstat);
367015910dc0SAndriy Gapon if (error != 0) {
367115910dc0SAndriy Gapon xpt_print(periph->path,
367215910dc0SAndriy Gapon "Failed to read current power mode\n");
367315910dc0SAndriy Gapon } else {
367415910dc0SAndriy Gapon mode = local_ccb.res.sector_count;
367515910dc0SAndriy Gapon #ifdef DIAGNOSTIC
367615910dc0SAndriy Gapon if (bootverbose) {
367715910dc0SAndriy Gapon xpt_print(periph->path,
367815910dc0SAndriy Gapon "disk power mode 0x%02x\n", mode);
367915910dc0SAndriy Gapon }
368015910dc0SAndriy Gapon #endif
368115910dc0SAndriy Gapon switch (mode) {
368275bc7150SAndriy Gapon case ATA_PM_STANDBY:
368375bc7150SAndriy Gapon case ATA_PM_STANDBY_Y:
368415910dc0SAndriy Gapon if (bootverbose) {
368515910dc0SAndriy Gapon xpt_print(periph->path,
368615910dc0SAndriy Gapon "already spun down\n");
368715910dc0SAndriy Gapon }
368815910dc0SAndriy Gapon cam_periph_unlock(periph);
368915910dc0SAndriy Gapon continue;
369015910dc0SAndriy Gapon default:
369115910dc0SAndriy Gapon break;
369215910dc0SAndriy Gapon }
369315910dc0SAndriy Gapon }
369415910dc0SAndriy Gapon }
369515910dc0SAndriy Gapon
3696fd104c15SRebecca Cran if (bootverbose)
3697fd104c15SRebecca Cran xpt_print(periph->path, "spin-down\n");
3698fd104c15SRebecca Cran
3699f902366cSWarner Losh memset(&local_ccb, 0, sizeof(local_ccb));
3700f902366cSWarner Losh xpt_setup_ccb(&local_ccb.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3701f902366cSWarner Losh local_ccb.ccb_h.ccb_state = ADA_CCB_DUMP;
3702f902366cSWarner Losh
3703f902366cSWarner Losh cam_fill_ataio(&local_ccb,
37040191d9b3SAlexander Motin 0,
3705eed99e75SScott Long NULL,
3706c3d0d168SAlexander Motin CAM_DIR_NONE | flags,
3707fd104c15SRebecca Cran 0,
3708fd104c15SRebecca Cran NULL,
3709fd104c15SRebecca Cran 0,
3710fd104c15SRebecca Cran ada_default_timeout*1000);
3711f902366cSWarner Losh ata_28bit_cmd(&local_ccb, cmd, 0, 0, 0);
3712f902366cSWarner Losh error = cam_periph_runccb((union ccb *)&local_ccb, adaerror,
3713f902366cSWarner Losh /*cam_flags*/0, /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY,
371409cfadbeSAlexander Motin softc->disk->d_devstat);
37150191d9b3SAlexander Motin if (error != 0)
37160191d9b3SAlexander Motin xpt_print(periph->path, "Spin-down disk failed\n");
3717fd104c15SRebecca Cran cam_periph_unlock(periph);
3718fd104c15SRebecca Cran }
371952c9ce25SScott Long }
372052c9ce25SScott Long
3721c3d0d168SAlexander Motin static void
adashutdown(void * arg,int howto)3722c3d0d168SAlexander Motin adashutdown(void *arg, int howto)
3723c3d0d168SAlexander Motin {
372450ee2e2aSWarner Losh int how;
3725c3d0d168SAlexander Motin
372638f8addaSAlexander Motin if ((howto & RB_NOSYNC) != 0)
372738f8addaSAlexander Motin return;
372838f8addaSAlexander Motin
3729c3d0d168SAlexander Motin adaflush();
3730f902366cSWarner Losh
3731f902366cSWarner Losh /*
373250ee2e2aSWarner Losh * STANDBY IMMEDIATE saves any volatile data to the drive. It also spins
373350ee2e2aSWarner Losh * down hard drives. IDLE IMMEDIATE also saves the volatile data without
373450ee2e2aSWarner Losh * a spindown. We send the former when we expect to lose power soon. For
373550ee2e2aSWarner Losh * a warm boot, we send the latter to avoid a thundering herd of spinups
373650ee2e2aSWarner Losh * just after the kernel loads while probing. We have to do something to
373750ee2e2aSWarner Losh * flush the data because the BIOS in many systems resets the HBA
373850ee2e2aSWarner Losh * causing a COMINIT/COMRESET negotiation, which some drives interpret
373950ee2e2aSWarner Losh * as license to toss the volatile data, and others count as unclean
374050ee2e2aSWarner Losh * shutdown when in the Active PM state in SMART attributes.
374150ee2e2aSWarner Losh *
374250ee2e2aSWarner Losh * adaspindown will ensure that we don't send this to a drive that
374350ee2e2aSWarner Losh * doesn't support it.
3744f902366cSWarner Losh */
374550ee2e2aSWarner Losh if (ada_spindown_shutdown != 0) {
374650ee2e2aSWarner Losh how = (howto & (RB_HALT | RB_POWEROFF | RB_POWERCYCLE)) ?
374750ee2e2aSWarner Losh ATA_STANDBY_IMMEDIATE : ATA_IDLE_IMMEDIATE;
374850ee2e2aSWarner Losh adaspindown(how, 0);
374950ee2e2aSWarner Losh }
3750c3d0d168SAlexander Motin }
3751c3d0d168SAlexander Motin
3752c3d0d168SAlexander Motin static void
adasuspend(void * arg)3753c3d0d168SAlexander Motin adasuspend(void *arg)
3754c3d0d168SAlexander Motin {
3755c3d0d168SAlexander Motin
3756c3d0d168SAlexander Motin adaflush();
3757f902366cSWarner Losh /*
3758f902366cSWarner Losh * SLEEP also fushes any volatile data, like STANDBY IMEDIATE,
3759f902366cSWarner Losh * so we don't need to send it as well.
3760f902366cSWarner Losh */
3761c3d0d168SAlexander Motin if (ada_spindown_suspend != 0)
3762c3d0d168SAlexander Motin adaspindown(ATA_SLEEP, CAM_DEV_QFREEZE);
3763c3d0d168SAlexander Motin }
3764c3d0d168SAlexander Motin
3765c3d0d168SAlexander Motin static void
adaresume(void * arg)3766c3d0d168SAlexander Motin adaresume(void *arg)
3767c3d0d168SAlexander Motin {
3768c3d0d168SAlexander Motin struct cam_periph *periph;
3769c3d0d168SAlexander Motin struct ada_softc *softc;
3770c3d0d168SAlexander Motin
3771c3d0d168SAlexander Motin if (ada_spindown_suspend == 0)
3772c3d0d168SAlexander Motin return;
3773c3d0d168SAlexander Motin
3774f371c9e2SAlexander Motin CAM_PERIPH_FOREACH(periph, &adadriver) {
3775c3d0d168SAlexander Motin cam_periph_lock(periph);
3776c3d0d168SAlexander Motin softc = (struct ada_softc *)periph->softc;
3777c3d0d168SAlexander Motin /*
3778c3d0d168SAlexander Motin * We only spin-down the drive if it is capable of it..
3779c3d0d168SAlexander Motin */
3780c3d0d168SAlexander Motin if ((softc->flags & ADA_FLAG_CAN_POWERMGT) == 0) {
3781c3d0d168SAlexander Motin cam_periph_unlock(periph);
3782c3d0d168SAlexander Motin continue;
3783c3d0d168SAlexander Motin }
3784c3d0d168SAlexander Motin
3785c3d0d168SAlexander Motin if (bootverbose)
3786c3d0d168SAlexander Motin xpt_print(periph->path, "resume\n");
3787c3d0d168SAlexander Motin
3788c3d0d168SAlexander Motin /*
3789c3d0d168SAlexander Motin * Drop freeze taken due to CAM_DEV_QFREEZE flag set on
3790c3d0d168SAlexander Motin * sleep request.
3791c3d0d168SAlexander Motin */
3792c3d0d168SAlexander Motin cam_release_devq(periph->path,
3793c3d0d168SAlexander Motin /*relsim_flags*/0,
3794c3d0d168SAlexander Motin /*openings*/0,
3795c3d0d168SAlexander Motin /*timeout*/0,
3796c3d0d168SAlexander Motin /*getcount_only*/0);
3797c3d0d168SAlexander Motin
3798c3d0d168SAlexander Motin cam_periph_unlock(periph);
3799c3d0d168SAlexander Motin }
3800c3d0d168SAlexander Motin }
3801c3d0d168SAlexander Motin
380252c9ce25SScott Long #endif /* _KERNEL */
3803