2 * Implementation of SCSI Direct Access Peripheral driver for CAM.
4 * Copyright (c) 1997 Justin T. Gibbs.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions, and the following disclaimer,
12 * without modification, immediately at the beginning of the file.
13 * 2. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
20 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/cdefs.h>
30 __FBSDID("$FreeBSD$");
32 #include <sys/param.h>
35 #include <sys/systm.h>
36 #include <sys/kernel.h>
38 #include <sys/sysctl.h>
39 #include <sys/taskqueue.h>
41 #include <sys/mutex.h>
43 #include <sys/devicestat.h>
44 #include <sys/eventhandler.h>
45 #include <sys/malloc.h>
47 #include <sys/endian.h>
49 #include <geom/geom.h>
50 #include <geom/geom_disk.h>
59 #include <cam/cam_ccb.h>
60 #include <cam/cam_periph.h>
61 #include <cam/cam_xpt_periph.h>
62 #include <cam/cam_sim.h>
64 #include <cam/scsi/scsi_message.h>
67 #include <cam/scsi/scsi_da.h>
75 DA_STATE_PROBE_BLK_LIMITS,
82 DA_FLAG_PACK_INVALID = 0x001,
83 DA_FLAG_NEW_PACK = 0x002,
84 DA_FLAG_PACK_LOCKED = 0x004,
85 DA_FLAG_PACK_REMOVABLE = 0x008,
86 DA_FLAG_NEED_OTAG = 0x020,
87 DA_FLAG_WAS_OTAG = 0x040,
88 DA_FLAG_RETRY_UA = 0x080,
90 DA_FLAG_SCTX_INIT = 0x200,
91 DA_FLAG_CAN_RC16 = 0x400,
92 DA_FLAG_PROBED = 0x800,
93 DA_FLAG_DIRTY = 0x1000,
94 DA_FLAG_ANNOUNCED = 0x2000
99 DA_Q_NO_SYNC_CACHE = 0x01,
100 DA_Q_NO_6_BYTE = 0x02,
101 DA_Q_NO_PREVENT = 0x04,
107 #define DA_Q_BIT_STRING \
109 "\001NO_SYNC_CACHE" \
116 DA_CCB_PROBE_RC = 0x01,
117 DA_CCB_PROBE_RC16 = 0x02,
118 DA_CCB_PROBE_LBP = 0x03,
119 DA_CCB_PROBE_BLK_LIMITS = 0x04,
120 DA_CCB_PROBE_BDC = 0x05,
121 DA_CCB_PROBE_ATA = 0x06,
122 DA_CCB_BUFFER_IO = 0x07,
124 DA_CCB_DELETE = 0x0B,
126 DA_CCB_TYPE_MASK = 0x0F,
127 DA_CCB_RETRY_UA = 0x10
131 * Order here is important for method choice
133 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
134 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
135 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
136 * import taking 5mins.
147 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
148 DA_DELETE_MAX = DA_DELETE_ZERO
151 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
153 static da_delete_func_t da_delete_trim;
154 static da_delete_func_t da_delete_unmap;
155 static da_delete_func_t da_delete_ws;
157 static const void * da_delete_functions[] = {
167 static const char *da_delete_method_names[] =
168 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
169 static const char *da_delete_method_desc[] =
170 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
171 "WRITE SAME(10) with UNMAP", "ZERO" };
173 /* Offsets into our private area for storing information */
174 #define ccb_state ppriv_field0
175 #define ccb_bp ppriv_ptr1
180 u_int8_t secs_per_track;
181 u_int32_t secsize; /* Number of bytes/sector */
182 u_int64_t sectors; /* total number sectors */
187 #define UNMAP_RANGE_MAX 0xffffffff
188 #define UNMAP_HEAD_SIZE 8
189 #define UNMAP_RANGE_SIZE 16
190 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
191 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
194 #define WS10_MAX_BLKS 0xffff
195 #define WS16_MAX_BLKS 0xffffffff
196 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
197 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
200 struct bio_queue_head bio_queue;
201 struct bio_queue_head delete_queue;
202 struct bio_queue_head delete_run_queue;
203 LIST_HEAD(, ccb_hdr) pending_ccbs;
204 int tur; /* TEST UNIT READY should be sent */
205 int refcount; /* Active xpt_action() calls */
210 int minimum_cmd_size;
214 int delete_available; /* Delete methods possibly available */
216 uint32_t unmap_max_ranges;
217 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
218 uint64_t ws_max_blks;
219 da_delete_methods delete_method;
220 da_delete_func_t *delete_func;
221 struct disk_params params;
224 struct task sysctl_task;
225 struct sysctl_ctx_list sysctl_ctx;
226 struct sysctl_oid *sysctl_tree;
227 struct callout sendordered_c;
229 uint8_t unmap_buf[UNMAP_BUF_SIZE];
230 struct scsi_read_capacity_data_long rcaplong;
231 struct callout mediapoll_c;
234 #define dadeleteflag(softc, delete_method, enable) \
236 softc->delete_available |= (1 << delete_method); \
238 softc->delete_available &= ~(1 << delete_method); \
241 struct da_quirk_entry {
242 struct scsi_inquiry_pattern inq_pat;
246 static const char quantum[] = "QUANTUM";
247 static const char microp[] = "MICROP";
249 static struct da_quirk_entry da_quirk_table[] =
251 /* SPI, FC devices */
254 * Fujitsu M2513A MO drives.
255 * Tested devices: M2513A2 firmware versions 1200 & 1300.
256 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
257 * Reported by: W.Scholten <whs@xs4all.nl>
259 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
260 /*quirks*/ DA_Q_NO_SYNC_CACHE
264 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
265 /*quirks*/ DA_Q_NO_SYNC_CACHE
269 * This particular Fujitsu drive doesn't like the
270 * synchronize cache command.
271 * Reported by: Tom Jackson <toj@gorilla.net>
273 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
274 /*quirks*/ DA_Q_NO_SYNC_CACHE
278 * This drive doesn't like the synchronize cache command
279 * either. Reported by: Matthew Jacob <mjacob@feral.com>
280 * in NetBSD PR kern/6027, August 24, 1998.
282 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
283 /*quirks*/ DA_Q_NO_SYNC_CACHE
287 * This drive doesn't like the synchronize cache command
288 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
291 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
292 /*quirks*/ DA_Q_NO_SYNC_CACHE
296 * Doesn't like the synchronize cache command.
297 * Reported by: Blaz Zupan <blaz@gold.amis.net>
299 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
300 /*quirks*/ DA_Q_NO_SYNC_CACHE
304 * Doesn't like the synchronize cache command.
305 * Reported by: Blaz Zupan <blaz@gold.amis.net>
307 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
308 /*quirks*/ DA_Q_NO_SYNC_CACHE
312 * Doesn't like the synchronize cache command.
314 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
315 /*quirks*/ DA_Q_NO_SYNC_CACHE
319 * Doesn't like the synchronize cache command.
320 * Reported by: walter@pelissero.de
322 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
323 /*quirks*/ DA_Q_NO_SYNC_CACHE
327 * Doesn't work correctly with 6 byte reads/writes.
328 * Returns illegal request, and points to byte 9 of the
330 * Reported by: Adam McDougall <bsdx@spawnet.com>
332 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
333 /*quirks*/ DA_Q_NO_6_BYTE
337 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
338 /*quirks*/ DA_Q_NO_6_BYTE
342 * Doesn't like the synchronize cache command.
343 * Reported by: walter@pelissero.de
345 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
346 /*quirks*/ DA_Q_NO_SYNC_CACHE
350 * The CISS RAID controllers do not support SYNC_CACHE
352 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
353 /*quirks*/ DA_Q_NO_SYNC_CACHE
357 * The STEC 842 sometimes hang on UNMAP.
359 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "S842E800M2", "*"},
360 /*quirks*/ DA_Q_NO_UNMAP
362 /* USB mass storage devices supported by umass(4) */
365 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
368 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
369 /*quirks*/ DA_Q_NO_SYNC_CACHE
373 * Power Quotient Int. (PQI) USB flash key
376 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
377 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
381 * Creative Nomad MUVO mp3 player (USB)
384 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
385 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
389 * Jungsoft NEXDISK USB flash key
392 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
393 /*quirks*/ DA_Q_NO_SYNC_CACHE
397 * FreeDik USB Mini Data Drive
400 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
401 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
405 * Sigmatel USB Flash MP3 Player
408 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
409 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
413 * Neuros USB Digital Audio Computer
416 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
417 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
421 * SEAGRAND NP-900 MP3 Player
424 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
425 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
429 * iRiver iFP MP3 player (with UMS Firmware)
430 * PR: kern/54881, i386/63941, kern/66124
432 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
433 /*quirks*/ DA_Q_NO_SYNC_CACHE
437 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
440 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
441 /*quirks*/ DA_Q_NO_SYNC_CACHE
445 * ZICPlay USB MP3 Player with FM
448 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
449 /*quirks*/ DA_Q_NO_SYNC_CACHE
453 * TEAC USB floppy mechanisms
455 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
456 /*quirks*/ DA_Q_NO_SYNC_CACHE
460 * Kingston DataTraveler II+ USB Pen-Drive.
461 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
463 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
464 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
472 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
473 /*quirks*/ DA_Q_NO_SYNC_CACHE
477 * Motorola E398 Mobile Phone (TransFlash memory card).
478 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
481 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
482 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
486 * Qware BeatZkey! Pro
489 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
490 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
494 * Time DPA20B 1GB MP3 Player
497 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
498 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
502 * Samsung USB key 128Mb
505 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
506 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
510 * Kingston DataTraveler 2.0 USB Flash memory.
513 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
514 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
518 * Creative MUVO Slim mp3 player (USB)
521 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
522 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
526 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
529 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
530 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
534 * SanDisk Micro Cruzer 128MB
537 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
538 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
542 * TOSHIBA TransMemory USB sticks
545 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
546 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
551 * PR: usb/75578, usb/72344, usb/65436
553 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
554 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
558 * Genesys 6-in-1 Card Reader
561 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
562 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
566 * Rekam Digital CAMERA
569 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
570 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
574 * iRiver H10 MP3 player
577 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
578 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
582 * iRiver U10 MP3 player
585 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
586 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
593 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
594 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
598 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
601 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
602 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
609 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
610 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
614 * Philips USB Key Audio KEY013
617 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
618 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
625 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
626 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
633 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
634 /*quirks*/ DA_Q_NO_SYNC_CACHE
638 * I/O Magic USB flash - Giga Bank
641 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
642 /*quirks*/ DA_Q_NO_SYNC_CACHE
646 * JoyFly 128mb USB Flash Drive
649 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
650 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
657 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
658 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
662 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
665 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
666 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
670 * Samsung YP-U3 mp3-player
673 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
674 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
677 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
678 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
682 * Sony Cyber-Shot DSC cameras
685 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
686 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
690 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
693 /* At least several Transcent USB sticks lie on RC16. */
694 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
695 "*"}, /*quirks*/ DA_Q_NO_RC16
697 /* ATA/SATA devices over SAS/USB/... */
699 /* Hitachi Advanced Format (4k) drives */
700 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
704 /* Samsung Advanced Format (4k) drives */
705 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
709 /* Samsung Advanced Format (4k) drives */
710 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
714 /* Samsung Advanced Format (4k) drives */
715 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
719 /* Samsung Advanced Format (4k) drives */
720 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
724 /* Seagate Barracuda Green Advanced Format (4k) drives */
725 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
729 /* Seagate Barracuda Green Advanced Format (4k) drives */
730 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
734 /* Seagate Barracuda Green Advanced Format (4k) drives */
735 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
739 /* Seagate Barracuda Green Advanced Format (4k) drives */
740 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
744 /* Seagate Barracuda Green Advanced Format (4k) drives */
745 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
749 /* Seagate Barracuda Green Advanced Format (4k) drives */
750 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
754 /* Seagate Momentus Advanced Format (4k) drives */
755 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
759 /* Seagate Momentus Advanced Format (4k) drives */
760 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
764 /* Seagate Momentus Advanced Format (4k) drives */
765 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
769 /* Seagate Momentus Advanced Format (4k) drives */
770 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
774 /* Seagate Momentus Advanced Format (4k) drives */
775 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
779 /* Seagate Momentus Advanced Format (4k) drives */
780 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
784 /* Seagate Momentus Advanced Format (4k) drives */
785 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
789 /* Seagate Momentus Advanced Format (4k) drives */
790 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
794 /* Seagate Momentus Advanced Format (4k) drives */
795 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
799 /* Seagate Momentus Advanced Format (4k) drives */
800 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
804 /* Seagate Momentus Advanced Format (4k) drives */
805 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
809 /* Seagate Momentus Advanced Format (4k) drives */
810 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
814 /* Seagate Momentus Advanced Format (4k) drives */
815 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
819 /* Seagate Momentus Advanced Format (4k) drives */
820 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
824 /* Seagate Momentus Thin Advanced Format (4k) drives */
825 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
829 /* Seagate Momentus Thin Advanced Format (4k) drives */
830 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
834 /* WDC Caviar Green Advanced Format (4k) drives */
835 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
839 /* WDC Caviar Green Advanced Format (4k) drives */
840 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
844 /* WDC Caviar Green Advanced Format (4k) drives */
845 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
849 /* WDC Caviar Green Advanced Format (4k) drives */
850 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
854 /* WDC Caviar Green Advanced Format (4k) drives */
855 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
859 /* WDC Caviar Green Advanced Format (4k) drives */
860 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
864 /* WDC Caviar Green Advanced Format (4k) drives */
865 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
869 /* WDC Caviar Green Advanced Format (4k) drives */
870 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
874 /* WDC Scorpio Black Advanced Format (4k) drives */
875 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
879 /* WDC Scorpio Black Advanced Format (4k) drives */
880 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
884 /* WDC Scorpio Black Advanced Format (4k) drives */
885 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
889 /* WDC Scorpio Black Advanced Format (4k) drives */
890 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
894 /* WDC Scorpio Blue Advanced Format (4k) drives */
895 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
899 /* WDC Scorpio Blue Advanced Format (4k) drives */
900 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
904 /* WDC Scorpio Blue Advanced Format (4k) drives */
905 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
909 /* WDC Scorpio Blue Advanced Format (4k) drives */
910 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
915 * Olympus FE-210 camera
917 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
918 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
924 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
925 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
929 * Laser MP3-2GA13 MP3 player
931 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
932 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
936 * LaCie external 250GB Hard drive des by Porsche
937 * Submitted by: Ben Stuyts <ben@altesco.nl>
940 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
941 /*quirks*/ DA_Q_NO_SYNC_CACHE
946 * Corsair Force 2 SSDs
947 * 4k optimised & trim only works in 4k requests + 4k aligned
949 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
954 * Corsair Force 3 SSDs
955 * 4k optimised & trim only works in 4k requests + 4k aligned
957 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
962 * Corsair Neutron GTX SSDs
963 * 4k optimised & trim only works in 4k requests + 4k aligned
965 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
970 * Corsair Force GT SSDs
971 * 4k optimised & trim only works in 4k requests + 4k aligned
973 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force GT*", "*" },
979 * 4k optimised & trim only works in 4k requests + 4k aligned
981 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
986 * Crucial RealSSD C300 SSDs
989 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
990 "*" }, /*quirks*/DA_Q_4K
994 * Intel 320 Series SSDs
995 * 4k optimised & trim only works in 4k requests + 4k aligned
997 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1002 * Intel 330 Series SSDs
1003 * 4k optimised & trim only works in 4k requests + 4k aligned
1005 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1010 * Intel 510 Series SSDs
1011 * 4k optimised & trim only works in 4k requests + 4k aligned
1013 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1018 * Intel 520 Series SSDs
1019 * 4k optimised & trim only works in 4k requests + 4k aligned
1021 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1026 * Intel X25-M Series SSDs
1027 * 4k optimised & trim only works in 4k requests + 4k aligned
1029 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1034 * Kingston E100 Series SSDs
1035 * 4k optimised & trim only works in 4k requests + 4k aligned
1037 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1042 * Kingston HyperX 3k SSDs
1043 * 4k optimised & trim only works in 4k requests + 4k aligned
1045 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1050 * Marvell SSDs (entry taken from OpenSolaris)
1051 * 4k optimised & trim only works in 4k requests + 4k aligned
1053 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1058 * OCZ Agility 2 SSDs
1059 * 4k optimised & trim only works in 4k requests + 4k aligned
1061 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1066 * OCZ Agility 3 SSDs
1067 * 4k optimised & trim only works in 4k requests + 4k aligned
1069 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1074 * OCZ Deneva R Series SSDs
1075 * 4k optimised & trim only works in 4k requests + 4k aligned
1077 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1082 * OCZ Vertex 2 SSDs (inc pro series)
1083 * 4k optimised & trim only works in 4k requests + 4k aligned
1085 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1091 * 4k optimised & trim only works in 4k requests + 4k aligned
1093 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1099 * 4k optimised & trim only works in 4k requests + 4k aligned
1101 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1106 * Samsung 830 Series SSDs
1107 * 4k optimised & trim only works in 4k requests + 4k aligned
1109 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1114 * SuperTalent TeraDrive CT SSDs
1115 * 4k optimised & trim only works in 4k requests + 4k aligned
1117 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1122 * XceedIOPS SATA SSDs
1125 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1130 static disk_strategy_t dastrategy;
1131 static dumper_t dadump;
1132 static periph_init_t dainit;
1133 static void daasync(void *callback_arg, u_int32_t code,
1134 struct cam_path *path, void *arg);
1135 static void dasysctlinit(void *context, int pending);
1136 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1137 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1138 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1139 static void dadeletemethodset(struct da_softc *softc,
1140 da_delete_methods delete_method);
1141 static off_t dadeletemaxsize(struct da_softc *softc,
1142 da_delete_methods delete_method);
1143 static void dadeletemethodchoose(struct da_softc *softc,
1144 da_delete_methods default_method);
1145 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1147 static periph_ctor_t daregister;
1148 static periph_dtor_t dacleanup;
1149 static periph_start_t dastart;
1150 static periph_oninv_t daoninvalidate;
1151 static void dadone(struct cam_periph *periph,
1152 union ccb *done_ccb);
1153 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1154 u_int32_t sense_flags);
1155 static void daprevent(struct cam_periph *periph, int action);
1156 static void dareprobe(struct cam_periph *periph);
1157 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1159 struct scsi_read_capacity_data_long *rcaplong,
1161 static timeout_t dasendorderedtag;
1162 static void dashutdown(void *arg, int howto);
1163 static timeout_t damediapoll;
1165 #ifndef DA_DEFAULT_POLL_PERIOD
1166 #define DA_DEFAULT_POLL_PERIOD 3
1169 #ifndef DA_DEFAULT_TIMEOUT
1170 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1173 #ifndef DA_DEFAULT_RETRY
1174 #define DA_DEFAULT_RETRY 4
1177 #ifndef DA_DEFAULT_SEND_ORDERED
1178 #define DA_DEFAULT_SEND_ORDERED 1
1181 #define DA_SIO (softc->sort_io_queue >= 0 ? \
1182 softc->sort_io_queue : cam_sort_io_queues)
1184 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1185 static int da_retry_count = DA_DEFAULT_RETRY;
1186 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1187 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1189 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1190 "CAM Direct Access Disk driver");
1191 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN,
1192 &da_poll_period, 0, "Media polling period in seconds");
1193 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN,
1194 &da_retry_count, 0, "Normal I/O retry count");
1195 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN,
1196 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1197 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN,
1198 &da_send_ordered, 0, "Send Ordered Tags");
1201 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1202 * to the default timeout, we check to see whether an ordered
1203 * tagged transaction is appropriate to prevent simple tag
1204 * starvation. Since we'd like to ensure that there is at least
1205 * 1/2 of the timeout length left for a starved transaction to
1206 * complete after we've sent an ordered tag, we must poll at least
1207 * four times in every timeout period. This takes care of the worst
1208 * case where a starved transaction starts during an interval that
1209 * meets the requirement "don't send an ordered tag" test so it takes
1210 * us two intervals to determine that a tag must be sent.
1212 #ifndef DA_ORDEREDTAG_INTERVAL
1213 #define DA_ORDEREDTAG_INTERVAL 4
1216 static struct periph_driver dadriver =
1219 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1222 PERIPHDRIVER_DECLARE(da, dadriver);
1224 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1227 daopen(struct disk *dp)
1229 struct cam_periph *periph;
1230 struct da_softc *softc;
1233 periph = (struct cam_periph *)dp->d_drv1;
1234 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1238 cam_periph_lock(periph);
1239 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1240 cam_periph_unlock(periph);
1241 cam_periph_release(periph);
1245 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1248 softc = (struct da_softc *)periph->softc;
1251 /* Wait for the disk size update. */
1252 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1255 xpt_print(periph->path, "unable to retrieve capacity data\n");
1257 if (periph->flags & CAM_PERIPH_INVALID)
1260 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1261 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1262 daprevent(periph, PR_PREVENT);
1265 softc->flags &= ~DA_FLAG_PACK_INVALID;
1266 softc->flags |= DA_FLAG_OPEN;
1269 cam_periph_unhold(periph);
1270 cam_periph_unlock(periph);
1273 cam_periph_release(periph);
1279 daclose(struct disk *dp)
1281 struct cam_periph *periph;
1282 struct da_softc *softc;
1286 periph = (struct cam_periph *)dp->d_drv1;
1287 softc = (struct da_softc *)periph->softc;
1288 cam_periph_lock(periph);
1289 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1292 if (cam_periph_hold(periph, PRIBIO) == 0) {
1294 /* Flush disk cache. */
1295 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1296 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1297 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1298 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1299 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1300 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1301 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1303 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1304 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1305 softc->disk->d_devstat);
1307 softc->flags &= ~DA_FLAG_DIRTY;
1308 xpt_release_ccb(ccb);
1311 /* Allow medium removal. */
1312 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1313 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1314 daprevent(periph, PR_ALLOW);
1316 cam_periph_unhold(periph);
1320 * If we've got removeable media, mark the blocksize as
1321 * unavailable, since it could change when new media is
1324 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1325 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1327 softc->flags &= ~DA_FLAG_OPEN;
1328 while (softc->refcount != 0)
1329 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1330 cam_periph_unlock(periph);
1331 cam_periph_release(periph);
1336 daschedule(struct cam_periph *periph)
1338 struct da_softc *softc = (struct da_softc *)periph->softc;
1340 if (softc->state != DA_STATE_NORMAL)
1343 /* Check if we have more work to do. */
1344 if (bioq_first(&softc->bio_queue) ||
1345 (!softc->delete_running && bioq_first(&softc->delete_queue)) ||
1347 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1352 * Actually translate the requested transfer into one the physical driver
1353 * can understand. The transfer is described by a buf and will include
1354 * only one physical transfer.
1357 dastrategy(struct bio *bp)
1359 struct cam_periph *periph;
1360 struct da_softc *softc;
1362 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1363 softc = (struct da_softc *)periph->softc;
1365 cam_periph_lock(periph);
1368 * If the device has been made invalid, error out
1370 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1371 cam_periph_unlock(periph);
1372 biofinish(bp, NULL, ENXIO);
1376 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1379 * Place it in the queue of disk activities for this disk
1381 if (bp->bio_cmd == BIO_DELETE) {
1382 bioq_disksort(&softc->delete_queue, bp);
1383 } else if (DA_SIO) {
1384 bioq_disksort(&softc->bio_queue, bp);
1386 bioq_insert_tail(&softc->bio_queue, bp);
1390 * Schedule ourselves for performing the work.
1393 cam_periph_unlock(periph);
1399 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1401 struct cam_periph *periph;
1402 struct da_softc *softc;
1404 struct ccb_scsiio csio;
1409 periph = dp->d_drv1;
1410 softc = (struct da_softc *)periph->softc;
1411 cam_periph_lock(periph);
1412 secsize = softc->params.secsize;
1414 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1415 cam_periph_unlock(periph);
1420 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1421 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1422 scsi_read_write(&csio,
1426 /*read*/SCSI_RW_WRITE,
1428 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1431 /*data_ptr*/(u_int8_t *) virtual,
1432 /*dxfer_len*/length,
1433 /*sense_len*/SSD_FULL_SIZE,
1434 da_default_timeout * 1000);
1435 xpt_polled_action((union ccb *)&csio);
1437 error = cam_periph_error((union ccb *)&csio,
1438 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1439 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1440 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1441 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1443 printf("Aborting dump due to I/O error.\n");
1444 cam_periph_unlock(periph);
1449 * Sync the disk cache contents to the physical media.
1451 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1453 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1454 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1455 scsi_synchronize_cache(&csio,
1459 /*begin_lba*/0,/* Cover the whole disk */
1463 xpt_polled_action((union ccb *)&csio);
1465 error = cam_periph_error((union ccb *)&csio,
1466 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1467 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1468 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1469 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1471 xpt_print(periph->path, "Synchronize cache failed\n");
1473 cam_periph_unlock(periph);
1478 dagetattr(struct bio *bp)
1481 struct cam_periph *periph;
1483 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1484 cam_periph_lock(periph);
1485 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1487 cam_periph_unlock(periph);
1489 bp->bio_completed = bp->bio_length;
1499 * Install a global async callback. This callback will
1500 * receive async callbacks like "new device found".
1502 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1504 if (status != CAM_REQ_CMP) {
1505 printf("da: Failed to attach master async callback "
1506 "due to status 0x%x!\n", status);
1507 } else if (da_send_ordered) {
1509 /* Register our shutdown event handler */
1510 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1511 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1512 printf("dainit: shutdown event registration failed!\n");
1517 * Callback from GEOM, called when it has finished cleaning up its
1521 dadiskgonecb(struct disk *dp)
1523 struct cam_periph *periph;
1525 periph = (struct cam_periph *)dp->d_drv1;
1526 cam_periph_release(periph);
1530 daoninvalidate(struct cam_periph *periph)
1532 struct da_softc *softc;
1534 softc = (struct da_softc *)periph->softc;
1537 * De-register any async callbacks.
1539 xpt_register_async(0, daasync, periph, periph->path);
1541 softc->flags |= DA_FLAG_PACK_INVALID;
1544 * Return all queued I/O with ENXIO.
1545 * XXX Handle any transactions queued to the card
1546 * with XPT_ABORT_CCB.
1548 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1549 bioq_flush(&softc->delete_queue, NULL, ENXIO);
1552 * Tell GEOM that we've gone away, we'll get a callback when it is
1553 * done cleaning up its resources.
1555 disk_gone(softc->disk);
1559 dacleanup(struct cam_periph *periph)
1561 struct da_softc *softc;
1563 softc = (struct da_softc *)periph->softc;
1565 cam_periph_unlock(periph);
1568 * If we can't free the sysctl tree, oh well...
1570 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1571 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1572 xpt_print(periph->path, "can't remove sysctl context\n");
1575 callout_drain(&softc->mediapoll_c);
1576 disk_destroy(softc->disk);
1577 callout_drain(&softc->sendordered_c);
1578 free(softc, M_DEVBUF);
1579 cam_periph_lock(periph);
1583 daasync(void *callback_arg, u_int32_t code,
1584 struct cam_path *path, void *arg)
1586 struct cam_periph *periph;
1587 struct da_softc *softc;
1589 periph = (struct cam_periph *)callback_arg;
1591 case AC_FOUND_DEVICE:
1593 struct ccb_getdev *cgd;
1596 cgd = (struct ccb_getdev *)arg;
1600 if (cgd->protocol != PROTO_SCSI)
1603 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1604 && SID_TYPE(&cgd->inq_data) != T_RBC
1605 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1609 * Allocate a peripheral instance for
1610 * this device and start the probe
1613 status = cam_periph_alloc(daregister, daoninvalidate,
1615 "da", CAM_PERIPH_BIO,
1617 AC_FOUND_DEVICE, cgd);
1619 if (status != CAM_REQ_CMP
1620 && status != CAM_REQ_INPROG)
1621 printf("daasync: Unable to attach to new device "
1622 "due to status 0x%x\n", status);
1625 case AC_ADVINFO_CHANGED:
1629 buftype = (uintptr_t)arg;
1630 if (buftype == CDAI_TYPE_PHYS_PATH) {
1631 struct da_softc *softc;
1633 softc = periph->softc;
1634 disk_attr_changed(softc->disk, "GEOM::physpath",
1639 case AC_UNIT_ATTENTION:
1642 int error_code, sense_key, asc, ascq;
1644 softc = (struct da_softc *)periph->softc;
1645 ccb = (union ccb *)arg;
1648 * Handle all UNIT ATTENTIONs except our own,
1649 * as they will be handled by daerror().
1651 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1652 scsi_extract_sense_ccb(ccb,
1653 &error_code, &sense_key, &asc, &ascq)) {
1654 if (asc == 0x2A && ascq == 0x09) {
1655 xpt_print(ccb->ccb_h.path,
1656 "Capacity data has changed\n");
1657 softc->flags &= ~DA_FLAG_PROBED;
1659 } else if (asc == 0x28 && ascq == 0x00) {
1660 softc->flags &= ~DA_FLAG_PROBED;
1661 disk_media_changed(softc->disk, M_NOWAIT);
1662 } else if (asc == 0x3F && ascq == 0x03) {
1663 xpt_print(ccb->ccb_h.path,
1664 "INQUIRY data has changed\n");
1665 softc->flags &= ~DA_FLAG_PROBED;
1669 cam_periph_async(periph, code, path, arg);
1673 softc = (struct da_softc *)periph->softc;
1675 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1684 struct ccb_hdr *ccbh;
1686 softc = (struct da_softc *)periph->softc;
1688 * Don't fail on the expected unit attention
1691 softc->flags |= DA_FLAG_RETRY_UA;
1692 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1693 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1699 cam_periph_async(periph, code, path, arg);
1703 dasysctlinit(void *context, int pending)
1705 struct cam_periph *periph;
1706 struct da_softc *softc;
1707 char tmpstr[80], tmpstr2[80];
1708 struct ccb_trans_settings cts;
1710 periph = (struct cam_periph *)context;
1712 * periph was held for us when this task was enqueued
1714 if (periph->flags & CAM_PERIPH_INVALID) {
1715 cam_periph_release(periph);
1719 softc = (struct da_softc *)periph->softc;
1720 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1721 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1723 sysctl_ctx_init(&softc->sysctl_ctx);
1724 softc->flags |= DA_FLAG_SCTX_INIT;
1725 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1726 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1727 CTLFLAG_RD, 0, tmpstr);
1728 if (softc->sysctl_tree == NULL) {
1729 printf("dasysctlinit: unable to allocate sysctl tree\n");
1730 cam_periph_release(periph);
1735 * Now register the sysctl handler, so the user can change the value on
1738 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1739 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RW,
1740 softc, 0, dadeletemethodsysctl, "A",
1741 "BIO_DELETE execution method");
1742 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1743 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1744 softc, 0, dadeletemaxsysctl, "Q",
1745 "Maximum BIO_DELETE size");
1746 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1747 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1748 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1749 "Minimum CDB size");
1750 SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1751 OID_AUTO, "sort_io_queue", CTLFLAG_RW, &softc->sort_io_queue, 0,
1752 "Sort IO queue to try and optimise disk access patterns");
1754 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1755 SYSCTL_CHILDREN(softc->sysctl_tree),
1759 &softc->error_inject,
1761 "error_inject leaf");
1765 * Add some addressing info.
1767 memset(&cts, 0, sizeof (cts));
1768 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1769 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1770 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1771 cam_periph_lock(periph);
1772 xpt_action((union ccb *)&cts);
1773 cam_periph_unlock(periph);
1774 if (cts.ccb_h.status != CAM_REQ_CMP) {
1775 cam_periph_release(periph);
1778 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
1779 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1780 if (fc->valid & CTS_FC_VALID_WWPN) {
1781 softc->wwpn = fc->wwpn;
1782 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1783 SYSCTL_CHILDREN(softc->sysctl_tree),
1784 OID_AUTO, "wwpn", CTLFLAG_RD,
1785 &softc->wwpn, "World Wide Port Name");
1788 cam_periph_release(periph);
1792 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
1796 struct da_softc *softc;
1798 softc = (struct da_softc *)arg1;
1800 value = softc->disk->d_delmaxsize;
1801 error = sysctl_handle_64(oidp, &value, 0, req);
1802 if ((error != 0) || (req->newptr == NULL))
1805 /* only accept values smaller than the calculated value */
1806 if (value > dadeletemaxsize(softc, softc->delete_method)) {
1809 softc->disk->d_delmaxsize = value;
1815 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1819 value = *(int *)arg1;
1821 error = sysctl_handle_int(oidp, &value, 0, req);
1824 || (req->newptr == NULL))
1828 * Acceptable values here are 6, 10, 12 or 16.
1832 else if ((value > 6)
1835 else if ((value > 10)
1838 else if (value > 12)
1841 *(int *)arg1 = value;
1847 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
1851 softc->delete_method = delete_method;
1852 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
1853 softc->delete_func = da_delete_functions[delete_method];
1855 if (softc->delete_method > DA_DELETE_DISABLE)
1856 softc->disk->d_flags |= DISKFLAG_CANDELETE;
1858 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
1862 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
1866 switch(delete_method) {
1867 case DA_DELETE_UNMAP:
1868 sectors = (off_t)softc->unmap_max_lba;
1870 case DA_DELETE_ATA_TRIM:
1871 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
1873 case DA_DELETE_WS16:
1874 sectors = (off_t)min(softc->ws_max_blks, WS16_MAX_BLKS);
1876 case DA_DELETE_ZERO:
1877 case DA_DELETE_WS10:
1878 sectors = (off_t)min(softc->ws_max_blks, WS10_MAX_BLKS);
1884 return (off_t)softc->params.secsize *
1885 min(sectors, (off_t)softc->params.sectors);
1889 daprobedone(struct cam_periph *periph, union ccb *ccb)
1891 struct da_softc *softc;
1893 softc = (struct da_softc *)periph->softc;
1895 dadeletemethodchoose(softc, DA_DELETE_NONE);
1897 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
1901 snprintf(buf, sizeof(buf), "Delete methods: <");
1903 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1904 if (softc->delete_available & (1 << i)) {
1906 strlcat(buf, ",", sizeof(buf));
1910 strlcat(buf, da_delete_method_names[i],
1912 if (i == softc->delete_method) {
1913 strlcat(buf, "(*)", sizeof(buf));
1918 if (softc->delete_method == DA_DELETE_NONE)
1919 strlcat(buf, "NONE(*)", sizeof(buf));
1921 strlcat(buf, "DISABLED(*)", sizeof(buf));
1923 strlcat(buf, ">", sizeof(buf));
1924 printf("%s%d: %s\n", periph->periph_name,
1925 periph->unit_number, buf);
1929 * Since our peripheral may be invalidated by an error
1930 * above or an external event, we must release our CCB
1931 * before releasing the probe lock on the peripheral.
1932 * The peripheral will only go away once the last lock
1933 * is removed, and we need it around for the CCB release
1936 xpt_release_ccb(ccb);
1937 softc->state = DA_STATE_NORMAL;
1938 softc->flags |= DA_FLAG_PROBED;
1940 wakeup(&softc->disk->d_mediasize);
1941 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
1942 softc->flags |= DA_FLAG_ANNOUNCED;
1943 cam_periph_unhold(periph);
1945 cam_periph_release_locked(periph);
1949 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
1951 int i, delete_method;
1953 delete_method = default_method;
1956 * Use the pre-defined order to choose the best
1957 * performing delete.
1959 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1960 if (softc->delete_available & (1 << i)) {
1961 dadeletemethodset(softc, i);
1965 dadeletemethodset(softc, delete_method);
1969 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
1973 struct da_softc *softc;
1974 int i, error, methods, value;
1976 softc = (struct da_softc *)arg1;
1978 value = softc->delete_method;
1979 if (value < 0 || value > DA_DELETE_MAX)
1982 p = da_delete_method_names[value];
1983 strncpy(buf, p, sizeof(buf));
1984 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1985 if (error != 0 || req->newptr == NULL)
1987 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
1988 for (i = 0; i <= DA_DELETE_MAX; i++) {
1989 if (!(methods & (1 << i)) ||
1990 strcmp(buf, da_delete_method_names[i]) != 0)
1992 dadeletemethodset(softc, i);
1999 daregister(struct cam_periph *periph, void *arg)
2001 struct da_softc *softc;
2002 struct ccb_pathinq cpi;
2003 struct ccb_getdev *cgd;
2007 cgd = (struct ccb_getdev *)arg;
2009 printf("daregister: no getdev CCB, can't register device\n");
2010 return(CAM_REQ_CMP_ERR);
2013 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2016 if (softc == NULL) {
2017 printf("daregister: Unable to probe new device. "
2018 "Unable to allocate softc\n");
2019 return(CAM_REQ_CMP_ERR);
2022 LIST_INIT(&softc->pending_ccbs);
2023 softc->state = DA_STATE_PROBE_RC;
2024 bioq_init(&softc->bio_queue);
2025 bioq_init(&softc->delete_queue);
2026 bioq_init(&softc->delete_run_queue);
2027 if (SID_IS_REMOVABLE(&cgd->inq_data))
2028 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2029 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2030 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2031 softc->ws_max_blks = WS16_MAX_BLKS;
2032 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2033 softc->sort_io_queue = -1;
2035 periph->softc = softc;
2038 * See if this device has any quirks.
2040 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2041 (caddr_t)da_quirk_table,
2042 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
2043 sizeof(*da_quirk_table), scsi_inquiry_match);
2046 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2048 softc->quirks = DA_Q_NONE;
2050 /* Check if the SIM does not want 6 byte commands */
2051 bzero(&cpi, sizeof(cpi));
2052 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2053 cpi.ccb_h.func_code = XPT_PATH_INQ;
2054 xpt_action((union ccb *)&cpi);
2055 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2056 softc->quirks |= DA_Q_NO_6_BYTE;
2058 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2061 * Take an exclusive refcount on the periph while dastart is called
2062 * to finish the probe. The reference will be dropped in dadone at
2065 (void)cam_periph_hold(periph, PRIBIO);
2068 * Schedule a periodic event to occasionally send an
2069 * ordered tag to a device.
2071 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2072 callout_reset(&softc->sendordered_c,
2073 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2074 dasendorderedtag, softc);
2076 cam_periph_unlock(periph);
2078 * RBC devices don't have to support READ(6), only READ(10).
2080 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2081 softc->minimum_cmd_size = 10;
2083 softc->minimum_cmd_size = 6;
2086 * Load the user's default, if any.
2088 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2089 periph->unit_number);
2090 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2093 * 6, 10, 12 and 16 are the currently permissible values.
2095 if (softc->minimum_cmd_size < 6)
2096 softc->minimum_cmd_size = 6;
2097 else if ((softc->minimum_cmd_size > 6)
2098 && (softc->minimum_cmd_size <= 10))
2099 softc->minimum_cmd_size = 10;
2100 else if ((softc->minimum_cmd_size > 10)
2101 && (softc->minimum_cmd_size <= 12))
2102 softc->minimum_cmd_size = 12;
2103 else if (softc->minimum_cmd_size > 12)
2104 softc->minimum_cmd_size = 16;
2106 /* Predict whether device may support READ CAPACITY(16). */
2107 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2108 (softc->quirks & DA_Q_NO_RC16) == 0) {
2109 softc->flags |= DA_FLAG_CAN_RC16;
2110 softc->state = DA_STATE_PROBE_RC16;
2114 * Register this media as a disk.
2116 softc->disk = disk_alloc();
2117 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2118 periph->unit_number, 0,
2119 DEVSTAT_BS_UNAVAILABLE,
2120 SID_TYPE(&cgd->inq_data) |
2121 XPORT_DEVSTAT_TYPE(cpi.transport),
2122 DEVSTAT_PRIORITY_DISK);
2123 softc->disk->d_open = daopen;
2124 softc->disk->d_close = daclose;
2125 softc->disk->d_strategy = dastrategy;
2126 softc->disk->d_dump = dadump;
2127 softc->disk->d_getattr = dagetattr;
2128 softc->disk->d_gone = dadiskgonecb;
2129 softc->disk->d_name = "da";
2130 softc->disk->d_drv1 = periph;
2132 softc->maxio = DFLTPHYS; /* traditional default */
2133 else if (cpi.maxio > MAXPHYS)
2134 softc->maxio = MAXPHYS; /* for safety */
2136 softc->maxio = cpi.maxio;
2137 softc->disk->d_maxsize = softc->maxio;
2138 softc->disk->d_unit = periph->unit_number;
2139 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION;
2140 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2141 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2142 if ((cpi.hba_misc & PIM_UNMAPPED) != 0)
2143 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2144 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2145 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2146 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2147 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2148 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2149 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2150 softc->disk->d_hba_vendor = cpi.hba_vendor;
2151 softc->disk->d_hba_device = cpi.hba_device;
2152 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2153 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2156 * Acquire a reference to the periph before we register with GEOM.
2157 * We'll release this reference once GEOM calls us back (via
2158 * dadiskgonecb()) telling us that our provider has been freed.
2160 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2161 xpt_print(periph->path, "%s: lost periph during "
2162 "registration!\n", __func__);
2163 cam_periph_lock(periph);
2164 return (CAM_REQ_CMP_ERR);
2167 disk_create(softc->disk, DISK_VERSION);
2168 cam_periph_lock(periph);
2171 * Add async callbacks for events of interest.
2172 * I don't bother checking if this fails as,
2173 * in most cases, the system will function just
2174 * fine without them and the only alternative
2175 * would be to not attach the device on failure.
2177 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2178 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION,
2179 daasync, periph, periph->path);
2182 * Emit an attribute changed notification just in case
2183 * physical path information arrived before our async
2184 * event handler was registered, but after anyone attaching
2185 * to our disk device polled it.
2187 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2190 * Schedule a periodic media polling events.
2192 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2193 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2194 (cgd->inq_flags & SID_AEN) == 0 &&
2195 da_poll_period != 0)
2196 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2197 damediapoll, periph);
2199 xpt_schedule(periph, CAM_PRIORITY_DEV);
2201 return(CAM_REQ_CMP);
2205 dastart(struct cam_periph *periph, union ccb *start_ccb)
2207 struct da_softc *softc;
2209 softc = (struct da_softc *)periph->softc;
2211 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2214 switch (softc->state) {
2215 case DA_STATE_NORMAL:
2220 /* Run BIO_DELETE if not running yet. */
2221 if (!softc->delete_running &&
2222 (bp = bioq_first(&softc->delete_queue)) != NULL) {
2223 if (softc->delete_func != NULL) {
2224 softc->delete_func(periph, start_ccb, bp);
2227 bioq_flush(&softc->delete_queue, NULL, 0);
2232 /* Run regular command. */
2233 bp = bioq_takefirst(&softc->bio_queue);
2237 scsi_test_unit_ready(&start_ccb->csio,
2238 /*retries*/ da_retry_count,
2242 da_default_timeout * 1000);
2243 start_ccb->ccb_h.ccb_bp = NULL;
2244 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2245 xpt_action(start_ccb);
2247 xpt_release_ccb(start_ccb);
2252 cam_periph_release_locked(periph);
2255 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2256 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2257 softc->flags &= ~DA_FLAG_NEED_OTAG;
2258 softc->flags |= DA_FLAG_WAS_OTAG;
2259 tag_code = MSG_ORDERED_Q_TAG;
2261 tag_code = MSG_SIMPLE_Q_TAG;
2264 switch (bp->bio_cmd) {
2266 softc->flags |= DA_FLAG_DIRTY;
2269 scsi_read_write(&start_ccb->csio,
2270 /*retries*/da_retry_count,
2272 /*tag_action*/tag_code,
2273 /*read_op*/(bp->bio_cmd == BIO_READ ?
2274 SCSI_RW_READ : SCSI_RW_WRITE) |
2275 ((bp->bio_flags & BIO_UNMAPPED) != 0 ?
2278 softc->minimum_cmd_size,
2279 /*lba*/bp->bio_pblkno,
2280 /*block_count*/bp->bio_bcount /
2281 softc->params.secsize,
2282 /*data_ptr*/ (bp->bio_flags &
2283 BIO_UNMAPPED) != 0 ? (void *)bp :
2285 /*dxfer_len*/ bp->bio_bcount,
2286 /*sense_len*/SSD_FULL_SIZE,
2287 da_default_timeout * 1000);
2291 * BIO_FLUSH doesn't currently communicate
2292 * range data, so we synchronize the cache
2293 * over the whole disk. We also force
2294 * ordered tag semantics the flush applies
2295 * to all previously queued I/O.
2297 scsi_synchronize_cache(&start_ccb->csio,
2304 da_default_timeout*1000);
2307 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
2308 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
2311 LIST_INSERT_HEAD(&softc->pending_ccbs,
2312 &start_ccb->ccb_h, periph_links.le);
2314 /* We expect a unit attention from this device */
2315 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
2316 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
2317 softc->flags &= ~DA_FLAG_RETRY_UA;
2320 start_ccb->ccb_h.ccb_bp = bp;
2322 cam_periph_unlock(periph);
2323 xpt_action(start_ccb);
2324 cam_periph_lock(periph);
2327 /* May have more work to do, so ensure we stay scheduled */
2331 case DA_STATE_PROBE_RC:
2333 struct scsi_read_capacity_data *rcap;
2335 rcap = (struct scsi_read_capacity_data *)
2336 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
2338 printf("dastart: Couldn't malloc read_capacity data\n");
2339 /* da_free_periph??? */
2342 scsi_read_capacity(&start_ccb->csio,
2343 /*retries*/da_retry_count,
2349 start_ccb->ccb_h.ccb_bp = NULL;
2350 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
2351 xpt_action(start_ccb);
2354 case DA_STATE_PROBE_RC16:
2356 struct scsi_read_capacity_data_long *rcaplong;
2358 rcaplong = (struct scsi_read_capacity_data_long *)
2359 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
2360 if (rcaplong == NULL) {
2361 printf("dastart: Couldn't malloc read_capacity data\n");
2362 /* da_free_periph??? */
2365 scsi_read_capacity_16(&start_ccb->csio,
2366 /*retries*/ da_retry_count,
2368 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2372 /*rcap_buf*/ (uint8_t *)rcaplong,
2373 /*rcap_buf_len*/ sizeof(*rcaplong),
2374 /*sense_len*/ SSD_FULL_SIZE,
2375 /*timeout*/ da_default_timeout * 1000);
2376 start_ccb->ccb_h.ccb_bp = NULL;
2377 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
2378 xpt_action(start_ccb);
2381 case DA_STATE_PROBE_LBP:
2383 struct scsi_vpd_logical_block_prov *lbp;
2385 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
2387 * If we get here we don't support any SBC-3 delete
2388 * methods with UNMAP as the Logical Block Provisioning
2389 * VPD page support is required for devices which
2390 * support it according to T10/1799-D Revision 31
2391 * however older revisions of the spec don't mandate
2392 * this so we currently don't remove these methods
2393 * from the available set.
2395 softc->state = DA_STATE_PROBE_BLK_LIMITS;
2399 lbp = (struct scsi_vpd_logical_block_prov *)
2400 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
2403 printf("dastart: Couldn't malloc lbp data\n");
2404 /* da_free_periph??? */
2408 scsi_inquiry(&start_ccb->csio,
2409 /*retries*/da_retry_count,
2411 /*tag_action*/MSG_SIMPLE_Q_TAG,
2412 /*inq_buf*/(u_int8_t *)lbp,
2413 /*inq_len*/sizeof(*lbp),
2415 /*page_code*/SVPD_LBP,
2416 /*sense_len*/SSD_MIN_SIZE,
2417 /*timeout*/da_default_timeout * 1000);
2418 start_ccb->ccb_h.ccb_bp = NULL;
2419 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
2420 xpt_action(start_ccb);
2423 case DA_STATE_PROBE_BLK_LIMITS:
2425 struct scsi_vpd_block_limits *block_limits;
2427 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
2428 /* Not supported skip to next probe */
2429 softc->state = DA_STATE_PROBE_BDC;
2433 block_limits = (struct scsi_vpd_block_limits *)
2434 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
2436 if (block_limits == NULL) {
2437 printf("dastart: Couldn't malloc block_limits data\n");
2438 /* da_free_periph??? */
2442 scsi_inquiry(&start_ccb->csio,
2443 /*retries*/da_retry_count,
2445 /*tag_action*/MSG_SIMPLE_Q_TAG,
2446 /*inq_buf*/(u_int8_t *)block_limits,
2447 /*inq_len*/sizeof(*block_limits),
2449 /*page_code*/SVPD_BLOCK_LIMITS,
2450 /*sense_len*/SSD_MIN_SIZE,
2451 /*timeout*/da_default_timeout * 1000);
2452 start_ccb->ccb_h.ccb_bp = NULL;
2453 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
2454 xpt_action(start_ccb);
2457 case DA_STATE_PROBE_BDC:
2459 struct scsi_vpd_block_characteristics *bdc;
2461 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
2462 softc->state = DA_STATE_PROBE_ATA;
2466 bdc = (struct scsi_vpd_block_characteristics *)
2467 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
2470 printf("dastart: Couldn't malloc bdc data\n");
2471 /* da_free_periph??? */
2475 scsi_inquiry(&start_ccb->csio,
2476 /*retries*/da_retry_count,
2478 /*tag_action*/MSG_SIMPLE_Q_TAG,
2479 /*inq_buf*/(u_int8_t *)bdc,
2480 /*inq_len*/sizeof(*bdc),
2482 /*page_code*/SVPD_BDC,
2483 /*sense_len*/SSD_MIN_SIZE,
2484 /*timeout*/da_default_timeout * 1000);
2485 start_ccb->ccb_h.ccb_bp = NULL;
2486 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
2487 xpt_action(start_ccb);
2490 case DA_STATE_PROBE_ATA:
2492 struct ata_params *ata_params;
2494 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2495 daprobedone(periph, start_ccb);
2499 ata_params = (struct ata_params*)
2500 malloc(sizeof(*ata_params), M_SCSIDA, M_NOWAIT|M_ZERO);
2502 if (ata_params == NULL) {
2503 printf("dastart: Couldn't malloc ata_params data\n");
2504 /* da_free_periph??? */
2508 scsi_ata_identify(&start_ccb->csio,
2509 /*retries*/da_retry_count,
2511 /*tag_action*/MSG_SIMPLE_Q_TAG,
2512 /*data_ptr*/(u_int8_t *)ata_params,
2513 /*dxfer_len*/sizeof(*ata_params),
2514 /*sense_len*/SSD_FULL_SIZE,
2515 /*timeout*/da_default_timeout * 1000);
2516 start_ccb->ccb_h.ccb_bp = NULL;
2517 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
2518 xpt_action(start_ccb);
2525 * In each of the methods below, while its the caller's
2526 * responsibility to ensure the request will fit into a
2527 * single device request, we might have changed the delete
2528 * method due to the device incorrectly advertising either
2529 * its supported methods or limits.
2531 * To prevent this causing further issues we validate the
2532 * against the methods limits, and warn which would
2533 * otherwise be unnecessary.
2536 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2538 struct da_softc *softc = (struct da_softc *)periph->softc;;
2540 uint8_t *buf = softc->unmap_buf;
2541 uint64_t lba, lastlba = (uint64_t)-1;
2542 uint64_t totalcount = 0;
2544 uint32_t lastcount = 0, c;
2545 uint32_t off, ranges = 0;
2548 * Currently this doesn't take the UNMAP
2549 * Granularity and Granularity Alignment
2550 * fields into account.
2552 * This could result in both unoptimal unmap
2553 * requests as as well as UNMAP calls unmapping
2554 * fewer LBA's than requested.
2557 softc->delete_running = 1;
2558 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2561 bioq_remove(&softc->delete_queue, bp1);
2563 bioq_insert_tail(&softc->delete_run_queue, bp1);
2564 lba = bp1->bio_pblkno;
2565 count = bp1->bio_bcount / softc->params.secsize;
2567 /* Try to extend the previous range. */
2568 if (lba == lastlba) {
2569 c = omin(count, UNMAP_RANGE_MAX - lastcount);
2571 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
2573 scsi_ulto4b(lastcount, &buf[off + 8]);
2580 c = omin(count, UNMAP_RANGE_MAX);
2581 if (totalcount + c > softc->unmap_max_lba ||
2582 ranges >= softc->unmap_max_ranges) {
2583 xpt_print(periph->path,
2584 "%s issuing short delete %ld > %ld"
2586 da_delete_method_desc[softc->delete_method],
2587 totalcount + c, softc->unmap_max_lba,
2588 ranges, softc->unmap_max_ranges);
2591 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
2592 scsi_u64to8b(lba, &buf[off + 0]);
2593 scsi_ulto4b(c, &buf[off + 8]);
2601 bp1 = bioq_first(&softc->delete_queue);
2602 if (bp1 == NULL || ranges >= softc->unmap_max_ranges ||
2603 totalcount + bp1->bio_bcount /
2604 softc->params.secsize > softc->unmap_max_lba)
2607 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
2608 scsi_ulto2b(ranges * 16, &buf[2]);
2610 scsi_unmap(&ccb->csio,
2611 /*retries*/da_retry_count,
2613 /*tag_action*/MSG_SIMPLE_Q_TAG,
2616 /*dxfer_len*/ ranges * 16 + 8,
2617 /*sense_len*/SSD_FULL_SIZE,
2618 da_default_timeout * 1000);
2619 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2620 ccb->ccb_h.flags |= CAM_UNLOCKED;
2624 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2626 struct da_softc *softc = (struct da_softc *)periph->softc;
2628 uint8_t *buf = softc->unmap_buf;
2629 uint64_t lastlba = (uint64_t)-1;
2632 uint32_t lastcount = 0, c, requestcount;
2633 int ranges = 0, off, block_count;
2635 softc->delete_running = 1;
2636 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2639 bioq_remove(&softc->delete_queue, bp1);
2641 bioq_insert_tail(&softc->delete_run_queue, bp1);
2642 lba = bp1->bio_pblkno;
2643 count = bp1->bio_bcount / softc->params.secsize;
2644 requestcount = count;
2646 /* Try to extend the previous range. */
2647 if (lba == lastlba) {
2648 c = min(count, ATA_DSM_RANGE_MAX - lastcount);
2650 off = (ranges - 1) * 8;
2651 buf[off + 6] = lastcount & 0xff;
2652 buf[off + 7] = (lastcount >> 8) & 0xff;
2658 c = min(count, ATA_DSM_RANGE_MAX);
2661 buf[off + 0] = lba & 0xff;
2662 buf[off + 1] = (lba >> 8) & 0xff;
2663 buf[off + 2] = (lba >> 16) & 0xff;
2664 buf[off + 3] = (lba >> 24) & 0xff;
2665 buf[off + 4] = (lba >> 32) & 0xff;
2666 buf[off + 5] = (lba >> 40) & 0xff;
2667 buf[off + 6] = c & 0xff;
2668 buf[off + 7] = (c >> 8) & 0xff;
2673 if (count != 0 && ranges == softc->trim_max_ranges) {
2674 xpt_print(periph->path,
2675 "%s issuing short delete %ld > %ld\n",
2676 da_delete_method_desc[softc->delete_method],
2678 (softc->trim_max_ranges - ranges) *
2684 bp1 = bioq_first(&softc->delete_queue);
2685 if (bp1 == NULL || bp1->bio_bcount / softc->params.secsize >
2686 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX)
2690 block_count = (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES;
2691 scsi_ata_trim(&ccb->csio,
2692 /*retries*/da_retry_count,
2694 /*tag_action*/MSG_SIMPLE_Q_TAG,
2697 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
2698 /*sense_len*/SSD_FULL_SIZE,
2699 da_default_timeout * 1000);
2700 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2701 ccb->ccb_h.flags |= CAM_UNLOCKED;
2705 * We calculate ws_max_blks here based off d_delmaxsize instead
2706 * of using softc->ws_max_blks as it is absolute max for the
2707 * device not the protocol max which may well be lower.
2710 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2712 struct da_softc *softc;
2714 uint64_t ws_max_blks;
2716 uint64_t count; /* forward compat with WS32 */
2718 softc = (struct da_softc *)periph->softc;
2719 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
2720 softc->delete_running = 1;
2721 lba = bp->bio_pblkno;
2725 bioq_remove(&softc->delete_queue, bp1);
2727 bioq_insert_tail(&softc->delete_run_queue, bp1);
2728 count += bp1->bio_bcount / softc->params.secsize;
2729 if (count > ws_max_blks) {
2730 xpt_print(periph->path,
2731 "%s issuing short delete %ld > %ld\n",
2732 da_delete_method_desc[softc->delete_method],
2733 count, ws_max_blks);
2734 count = min(count, ws_max_blks);
2737 bp1 = bioq_first(&softc->delete_queue);
2738 if (bp1 == NULL || lba + count != bp1->bio_pblkno ||
2739 count + bp1->bio_bcount /
2740 softc->params.secsize > ws_max_blks)
2744 scsi_write_same(&ccb->csio,
2745 /*retries*/da_retry_count,
2747 /*tag_action*/MSG_SIMPLE_Q_TAG,
2748 /*byte2*/softc->delete_method ==
2749 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
2750 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
2752 /*block_count*/count,
2753 /*data_ptr*/ __DECONST(void *, zero_region),
2754 /*dxfer_len*/ softc->params.secsize,
2755 /*sense_len*/SSD_FULL_SIZE,
2756 da_default_timeout * 1000);
2757 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2758 ccb->ccb_h.flags |= CAM_UNLOCKED;
2762 cmd6workaround(union ccb *ccb)
2764 struct scsi_rw_6 cmd6;
2765 struct scsi_rw_10 *cmd10;
2766 struct da_softc *softc;
2771 cdb = ccb->csio.cdb_io.cdb_bytes;
2772 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
2774 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
2775 da_delete_methods old_method = softc->delete_method;
2778 * Typically there are two reasons for failure here
2779 * 1. Delete method was detected as supported but isn't
2780 * 2. Delete failed due to invalid params e.g. too big
2782 * While we will attempt to choose an alternative delete method
2783 * this may result in short deletes if the existing delete
2784 * requests from geom are big for the new method choosen.
2786 * This method assumes that the error which triggered this
2787 * will not retry the io otherwise a panic will occur
2789 dadeleteflag(softc, old_method, 0);
2790 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
2791 if (softc->delete_method == DA_DELETE_DISABLE)
2792 xpt_print(ccb->ccb_h.path,
2793 "%s failed, disabling BIO_DELETE\n",
2794 da_delete_method_desc[old_method]);
2796 xpt_print(ccb->ccb_h.path,
2797 "%s failed, switching to %s BIO_DELETE\n",
2798 da_delete_method_desc[old_method],
2799 da_delete_method_desc[softc->delete_method]);
2801 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL)
2802 bioq_disksort(&softc->delete_queue, bp);
2803 bioq_disksort(&softc->delete_queue,
2804 (struct bio *)ccb->ccb_h.ccb_bp);
2805 ccb->ccb_h.ccb_bp = NULL;
2809 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
2810 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2811 (*cdb == PREVENT_ALLOW) &&
2812 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
2814 xpt_print(ccb->ccb_h.path,
2815 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
2816 softc->quirks |= DA_Q_NO_PREVENT;
2820 /* Detect unsupported SYNCHRONIZE CACHE(10). */
2821 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2822 (*cdb == SYNCHRONIZE_CACHE) &&
2823 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
2825 xpt_print(ccb->ccb_h.path,
2826 "SYNCHRONIZE CACHE(10) not supported.\n");
2827 softc->quirks |= DA_Q_NO_SYNC_CACHE;
2828 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
2832 /* Translation only possible if CDB is an array and cmd is R/W6 */
2833 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
2834 (*cdb != READ_6 && *cdb != WRITE_6))
2837 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
2838 "increasing minimum_cmd_size to 10.\n");
2839 softc->minimum_cmd_size = 10;
2841 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
2842 cmd10 = (struct scsi_rw_10 *)cdb;
2843 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
2845 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
2846 cmd10->reserved = 0;
2847 scsi_ulto2b(cmd6.length, cmd10->length);
2848 cmd10->control = cmd6.control;
2849 ccb->csio.cdb_len = sizeof(*cmd10);
2851 /* Requeue request, unfreezing queue if necessary */
2852 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
2853 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2856 cam_release_devq(ccb->ccb_h.path,
2860 /*getcount_only*/0);
2866 dadone(struct cam_periph *periph, union ccb *done_ccb)
2868 struct da_softc *softc;
2869 struct ccb_scsiio *csio;
2873 softc = (struct da_softc *)periph->softc;
2874 priority = done_ccb->ccb_h.pinfo.priority;
2876 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
2878 csio = &done_ccb->csio;
2879 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
2881 case DA_CCB_BUFFER_IO:
2884 struct bio *bp, *bp1;
2886 cam_periph_lock(periph);
2887 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2888 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2892 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
2897 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
2898 if (error == ERESTART) {
2900 * A retry was scheduled, so
2903 cam_periph_unlock(periph);
2906 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2911 * return all queued I/O with EIO, so that
2912 * the client can retry these I/Os in the
2913 * proper order should it attempt to recover.
2918 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
2920 * Catastrophic error. Mark our pack as
2924 * XXX See if this is really a media
2927 xpt_print(periph->path,
2928 "Invalidating pack\n");
2929 softc->flags |= DA_FLAG_PACK_INVALID;
2930 queued_error = ENXIO;
2932 bioq_flush(&softc->bio_queue, NULL,
2935 bp->bio_error = error;
2936 bp->bio_resid = bp->bio_bcount;
2937 bp->bio_flags |= BIO_ERROR;
2939 } else if (bp != NULL) {
2940 if (state == DA_CCB_DELETE)
2943 bp->bio_resid = csio->resid;
2945 if (bp->bio_resid != 0)
2946 bp->bio_flags |= BIO_ERROR;
2948 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2949 cam_release_devq(done_ccb->ccb_h.path,
2953 /*getcount_only*/0);
2954 } else if (bp != NULL) {
2955 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2956 panic("REQ_CMP with QFRZN");
2957 if (state == DA_CCB_DELETE)
2960 bp->bio_resid = csio->resid;
2961 if (csio->resid > 0)
2962 bp->bio_flags |= BIO_ERROR;
2963 if (softc->error_inject != 0) {
2964 bp->bio_error = softc->error_inject;
2965 bp->bio_resid = bp->bio_bcount;
2966 bp->bio_flags |= BIO_ERROR;
2967 softc->error_inject = 0;
2971 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
2972 if (LIST_EMPTY(&softc->pending_ccbs))
2973 softc->flags |= DA_FLAG_WAS_OTAG;
2975 xpt_release_ccb(done_ccb);
2976 if (state == DA_CCB_DELETE) {
2977 TAILQ_HEAD(, bio) queue;
2980 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
2981 softc->delete_run_queue.insert_point = NULL;
2982 softc->delete_running = 0;
2984 cam_periph_unlock(periph);
2985 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
2986 TAILQ_REMOVE(&queue, bp1, bio_queue);
2987 bp1->bio_error = bp->bio_error;
2988 if (bp->bio_flags & BIO_ERROR) {
2989 bp1->bio_flags |= BIO_ERROR;
2990 bp1->bio_resid = bp1->bio_bcount;
2996 cam_periph_unlock(periph);
3001 case DA_CCB_PROBE_RC:
3002 case DA_CCB_PROBE_RC16:
3004 struct scsi_read_capacity_data *rdcap;
3005 struct scsi_read_capacity_data_long *rcaplong;
3006 char announce_buf[80];
3012 if (state == DA_CCB_PROBE_RC)
3013 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
3015 rcaplong = (struct scsi_read_capacity_data_long *)
3018 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3019 struct disk_params *dp;
3020 uint32_t block_size;
3022 u_int lalba; /* Lowest aligned LBA. */
3024 if (state == DA_CCB_PROBE_RC) {
3025 block_size = scsi_4btoul(rdcap->length);
3026 maxsector = scsi_4btoul(rdcap->addr);
3030 * According to SBC-2, if the standard 10
3031 * byte READ CAPACITY command returns 2^32,
3032 * we should issue the 16 byte version of
3033 * the command, since the device in question
3034 * has more sectors than can be represented
3035 * with the short version of the command.
3037 if (maxsector == 0xffffffff) {
3038 free(rdcap, M_SCSIDA);
3039 xpt_release_ccb(done_ccb);
3040 softc->state = DA_STATE_PROBE_RC16;
3041 xpt_schedule(periph, priority);
3045 block_size = scsi_4btoul(rcaplong->length);
3046 maxsector = scsi_8btou64(rcaplong->addr);
3047 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3051 * Because GEOM code just will panic us if we
3052 * give them an 'illegal' value we'll avoid that
3055 if (block_size == 0 && maxsector == 0) {
3059 if (block_size >= MAXPHYS || block_size == 0) {
3060 xpt_print(periph->path,
3061 "unsupportable block size %ju\n",
3062 (uintmax_t) block_size);
3063 announce_buf[0] = '\0';
3064 cam_periph_invalidate(periph);
3067 * We pass rcaplong into dasetgeom(),
3068 * because it will only use it if it is
3071 dasetgeom(periph, block_size, maxsector,
3072 rcaplong, sizeof(*rcaplong));
3073 lbp = (lalba & SRC16_LBPME_A);
3074 dp = &softc->params;
3075 snprintf(announce_buf, sizeof(announce_buf),
3076 "%juMB (%ju %u byte sectors: %dH %dS/T "
3078 (((uintmax_t)dp->secsize *
3079 dp->sectors) / (1024*1024)),
3080 (uintmax_t)dp->sectors,
3081 dp->secsize, dp->heads,
3082 dp->secs_per_track, dp->cylinders);
3087 announce_buf[0] = '\0';
3090 * Retry any UNIT ATTENTION type errors. They
3091 * are expected at boot.
3093 error = daerror(done_ccb, CAM_RETRY_SELTO,
3094 SF_RETRY_UA|SF_NO_PRINT);
3095 if (error == ERESTART) {
3097 * A retry was scheuled, so
3101 } else if (error != 0) {
3103 int sense_key, error_code;
3106 struct ccb_getdev cgd;
3108 /* Don't wedge this device's queue */
3109 status = done_ccb->ccb_h.status;
3110 if ((status & CAM_DEV_QFRZN) != 0)
3111 cam_release_devq(done_ccb->ccb_h.path,
3115 /*getcount_only*/0);
3118 xpt_setup_ccb(&cgd.ccb_h,
3119 done_ccb->ccb_h.path,
3120 CAM_PRIORITY_NORMAL);
3121 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3122 xpt_action((union ccb *)&cgd);
3124 if (scsi_extract_sense_ccb(done_ccb,
3125 &error_code, &sense_key, &asc, &ascq))
3131 * If we tried READ CAPACITY(16) and failed,
3132 * fallback to READ CAPACITY(10).
3134 if ((state == DA_CCB_PROBE_RC16) &&
3135 (softc->flags & DA_FLAG_CAN_RC16) &&
3136 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
3139 (error_code == SSD_CURRENT_ERROR) &&
3140 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
3141 softc->flags &= ~DA_FLAG_CAN_RC16;
3142 free(rdcap, M_SCSIDA);
3143 xpt_release_ccb(done_ccb);
3144 softc->state = DA_STATE_PROBE_RC;
3145 xpt_schedule(periph, priority);
3149 * Attach to anything that claims to be a
3150 * direct access or optical disk device,
3151 * as long as it doesn't return a "Logical
3152 * unit not supported" (0x25) error.
3154 if ((have_sense) && (asc != 0x25)
3155 && (error_code == SSD_CURRENT_ERROR)) {
3156 const char *sense_key_desc;
3157 const char *asc_desc;
3159 dasetgeom(periph, 512, -1, NULL, 0);
3160 scsi_sense_desc(sense_key, asc, ascq,
3164 snprintf(announce_buf,
3165 sizeof(announce_buf),
3166 "Attempt to query device "
3167 "size failed: %s, %s",
3175 xpt_print(periph->path,
3176 "got CAM status %#x\n",
3177 done_ccb->ccb_h.status);
3180 xpt_print(periph->path, "fatal error, "
3181 "failed to attach to device\n");
3184 * Free up resources.
3186 cam_periph_invalidate(periph);
3190 free(csio->data_ptr, M_SCSIDA);
3191 if (announce_buf[0] != '\0' &&
3192 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
3194 * Create our sysctl variables, now that we know
3195 * we have successfully attached.
3197 /* increase the refcount */
3198 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3199 taskqueue_enqueue(taskqueue_thread,
3200 &softc->sysctl_task);
3201 xpt_announce_periph(periph, announce_buf);
3202 xpt_announce_quirks(periph, softc->quirks,
3205 xpt_print(periph->path, "fatal error, "
3206 "could not acquire reference count\n");
3210 /* We already probed the device. */
3211 if (softc->flags & DA_FLAG_PROBED) {
3212 daprobedone(periph, done_ccb);
3216 /* Ensure re-probe doesn't see old delete. */
3217 softc->delete_available = 0;
3218 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
3220 * Based on older SBC-3 spec revisions
3221 * any of the UNMAP methods "may" be
3222 * available via LBP given this flag so
3223 * we flag all of them as availble and
3224 * then remove those which further
3225 * probes confirm aren't available
3228 * We could also check readcap(16) p_type
3229 * flag to exclude one or more invalid
3230 * write same (X) types here
3232 dadeleteflag(softc, DA_DELETE_WS16, 1);
3233 dadeleteflag(softc, DA_DELETE_WS10, 1);
3234 dadeleteflag(softc, DA_DELETE_ZERO, 1);
3235 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
3237 xpt_release_ccb(done_ccb);
3238 softc->state = DA_STATE_PROBE_LBP;
3239 xpt_schedule(periph, priority);
3243 xpt_release_ccb(done_ccb);
3244 softc->state = DA_STATE_PROBE_BDC;
3245 xpt_schedule(periph, priority);
3248 case DA_CCB_PROBE_LBP:
3250 struct scsi_vpd_logical_block_prov *lbp;
3252 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
3254 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3256 * T10/1799-D Revision 31 states at least one of these
3257 * must be supported but we don't currently enforce this.
3259 dadeleteflag(softc, DA_DELETE_WS16,
3260 (lbp->flags & SVPD_LBP_WS16));
3261 dadeleteflag(softc, DA_DELETE_WS10,
3262 (lbp->flags & SVPD_LBP_WS10));
3263 dadeleteflag(softc, DA_DELETE_ZERO,
3264 (lbp->flags & SVPD_LBP_WS10));
3265 dadeleteflag(softc, DA_DELETE_UNMAP,
3266 (lbp->flags & SVPD_LBP_UNMAP));
3269 error = daerror(done_ccb, CAM_RETRY_SELTO,
3270 SF_RETRY_UA|SF_NO_PRINT);
3271 if (error == ERESTART)
3273 else if (error != 0) {
3274 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3275 /* Don't wedge this device's queue */
3276 cam_release_devq(done_ccb->ccb_h.path,
3280 /*getcount_only*/0);
3284 * Failure indicates we don't support any SBC-3
3285 * delete methods with UNMAP
3290 free(lbp, M_SCSIDA);
3291 xpt_release_ccb(done_ccb);
3292 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3293 xpt_schedule(periph, priority);
3296 case DA_CCB_PROBE_BLK_LIMITS:
3298 struct scsi_vpd_block_limits *block_limits;
3300 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
3302 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3303 uint32_t max_txfer_len = scsi_4btoul(
3304 block_limits->max_txfer_len);
3305 uint32_t max_unmap_lba_cnt = scsi_4btoul(
3306 block_limits->max_unmap_lba_cnt);
3307 uint32_t max_unmap_blk_cnt = scsi_4btoul(
3308 block_limits->max_unmap_blk_cnt);
3309 uint64_t ws_max_blks = scsi_8btou64(
3310 block_limits->max_write_same_length);
3312 if (max_txfer_len != 0) {
3313 softc->disk->d_maxsize = MIN(softc->maxio,
3314 (off_t)max_txfer_len * softc->params.secsize);
3318 * We should already support UNMAP but we check lba
3319 * and block count to be sure
3321 if (max_unmap_lba_cnt != 0x00L &&
3322 max_unmap_blk_cnt != 0x00L) {
3323 softc->unmap_max_lba = max_unmap_lba_cnt;
3324 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
3328 * Unexpected UNMAP limits which means the
3329 * device doesn't actually support UNMAP
3331 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
3334 if (ws_max_blks != 0x00L)
3335 softc->ws_max_blks = ws_max_blks;
3338 error = daerror(done_ccb, CAM_RETRY_SELTO,
3339 SF_RETRY_UA|SF_NO_PRINT);
3340 if (error == ERESTART)
3342 else if (error != 0) {
3343 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3344 /* Don't wedge this device's queue */
3345 cam_release_devq(done_ccb->ccb_h.path,
3349 /*getcount_only*/0);
3353 * Failure here doesn't mean UNMAP is not
3354 * supported as this is an optional page.
3356 softc->unmap_max_lba = 1;
3357 softc->unmap_max_ranges = 1;
3361 free(block_limits, M_SCSIDA);
3362 xpt_release_ccb(done_ccb);
3363 softc->state = DA_STATE_PROBE_BDC;
3364 xpt_schedule(periph, priority);
3367 case DA_CCB_PROBE_BDC:
3369 struct scsi_vpd_block_characteristics *bdc;
3371 bdc = (struct scsi_vpd_block_characteristics *)csio->data_ptr;
3373 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3375 * Disable queue sorting for non-rotational media
3378 u_int16_t old_rate = softc->disk->d_rotation_rate;
3380 softc->disk->d_rotation_rate =
3381 scsi_2btoul(bdc->medium_rotation_rate);
3382 if (softc->disk->d_rotation_rate ==
3383 SVPD_BDC_RATE_NON_ROTATING) {
3384 softc->sort_io_queue = 0;
3386 if (softc->disk->d_rotation_rate != old_rate) {
3387 disk_attr_changed(softc->disk,
3388 "GEOM::rotation_rate", M_NOWAIT);
3392 error = daerror(done_ccb, CAM_RETRY_SELTO,
3393 SF_RETRY_UA|SF_NO_PRINT);
3394 if (error == ERESTART)
3396 else if (error != 0) {
3397 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3398 /* Don't wedge this device's queue */
3399 cam_release_devq(done_ccb->ccb_h.path,
3403 /*getcount_only*/0);
3408 free(bdc, M_SCSIDA);
3409 xpt_release_ccb(done_ccb);
3410 softc->state = DA_STATE_PROBE_ATA;
3411 xpt_schedule(periph, priority);
3414 case DA_CCB_PROBE_ATA:
3417 struct ata_params *ata_params;
3420 ata_params = (struct ata_params *)csio->data_ptr;
3421 ptr = (uint16_t *)ata_params;
3423 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3426 for (i = 0; i < sizeof(*ata_params) / 2; i++)
3427 ptr[i] = le16toh(ptr[i]);
3428 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
3429 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
3430 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
3431 if (ata_params->max_dsm_blocks != 0)
3432 softc->trim_max_ranges = min(
3433 softc->trim_max_ranges,
3434 ata_params->max_dsm_blocks *
3435 ATA_DSM_BLK_RANGES);
3438 * Disable queue sorting for non-rotational media
3441 old_rate = softc->disk->d_rotation_rate;
3442 softc->disk->d_rotation_rate =
3443 ata_params->media_rotation_rate;
3444 if (softc->disk->d_rotation_rate ==
3445 ATA_RATE_NON_ROTATING) {
3446 softc->sort_io_queue = 0;
3449 if (softc->disk->d_rotation_rate != old_rate) {
3450 disk_attr_changed(softc->disk,
3451 "GEOM::rotation_rate", M_NOWAIT);
3455 error = daerror(done_ccb, CAM_RETRY_SELTO,
3456 SF_RETRY_UA|SF_NO_PRINT);
3457 if (error == ERESTART)
3459 else if (error != 0) {
3460 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3461 /* Don't wedge this device's queue */
3462 cam_release_devq(done_ccb->ccb_h.path,
3466 /*getcount_only*/0);
3471 free(ata_params, M_SCSIDA);
3472 daprobedone(periph, done_ccb);
3476 /* No-op. We're polling */
3480 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3482 if (daerror(done_ccb, CAM_RETRY_SELTO,
3483 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
3486 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
3487 cam_release_devq(done_ccb->ccb_h.path,
3491 /*getcount_only*/0);
3493 xpt_release_ccb(done_ccb);
3494 cam_periph_release_locked(periph);
3500 xpt_release_ccb(done_ccb);
3504 dareprobe(struct cam_periph *periph)
3506 struct da_softc *softc;
3509 softc = (struct da_softc *)periph->softc;
3511 /* Probe in progress; don't interfere. */
3512 if (softc->state != DA_STATE_NORMAL)
3515 status = cam_periph_acquire(periph);
3516 KASSERT(status == CAM_REQ_CMP,
3517 ("dareprobe: cam_periph_acquire failed"));
3519 if (softc->flags & DA_FLAG_CAN_RC16)
3520 softc->state = DA_STATE_PROBE_RC16;
3522 softc->state = DA_STATE_PROBE_RC;
3524 xpt_schedule(periph, CAM_PRIORITY_DEV);
3528 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
3530 struct da_softc *softc;
3531 struct cam_periph *periph;
3532 int error, error_code, sense_key, asc, ascq;
3534 periph = xpt_path_periph(ccb->ccb_h.path);
3535 softc = (struct da_softc *)periph->softc;
3538 * Automatically detect devices that do not support
3539 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
3542 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
3543 error = cmd6workaround(ccb);
3544 } else if (scsi_extract_sense_ccb(ccb,
3545 &error_code, &sense_key, &asc, &ascq)) {
3546 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
3547 error = cmd6workaround(ccb);
3549 * If the target replied with CAPACITY DATA HAS CHANGED UA,
3550 * query the capacity and notify upper layers.
3552 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3553 asc == 0x2A && ascq == 0x09) {
3554 xpt_print(periph->path, "Capacity data has changed\n");
3555 softc->flags &= ~DA_FLAG_PROBED;
3557 sense_flags |= SF_NO_PRINT;
3558 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3559 asc == 0x28 && ascq == 0x00) {
3560 softc->flags &= ~DA_FLAG_PROBED;
3561 disk_media_changed(softc->disk, M_NOWAIT);
3562 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3563 asc == 0x3F && ascq == 0x03) {
3564 xpt_print(periph->path, "INQUIRY data has changed\n");
3565 softc->flags &= ~DA_FLAG_PROBED;
3567 sense_flags |= SF_NO_PRINT;
3568 } else if (sense_key == SSD_KEY_NOT_READY &&
3569 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
3570 softc->flags |= DA_FLAG_PACK_INVALID;
3571 disk_media_gone(softc->disk, M_NOWAIT);
3574 if (error == ERESTART)
3579 * Until we have a better way of doing pack validation,
3580 * don't treat UAs as errors.
3582 sense_flags |= SF_RETRY_UA;
3583 return(cam_periph_error(ccb, cam_flags, sense_flags,
3584 &softc->saved_ccb));
3588 damediapoll(void *arg)
3590 struct cam_periph *periph = arg;
3591 struct da_softc *softc = periph->softc;
3593 if (!softc->tur && LIST_EMPTY(&softc->pending_ccbs)) {
3594 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3599 /* Queue us up again */
3600 if (da_poll_period != 0)
3601 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
3605 daprevent(struct cam_periph *periph, int action)
3607 struct da_softc *softc;
3611 softc = (struct da_softc *)periph->softc;
3613 if (((action == PR_ALLOW)
3614 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
3615 || ((action == PR_PREVENT)
3616 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
3620 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3622 scsi_prevent(&ccb->csio,
3630 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
3631 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
3634 if (action == PR_ALLOW)
3635 softc->flags &= ~DA_FLAG_PACK_LOCKED;
3637 softc->flags |= DA_FLAG_PACK_LOCKED;
3640 xpt_release_ccb(ccb);
3644 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
3645 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
3647 struct ccb_calc_geometry ccg;
3648 struct da_softc *softc;
3649 struct disk_params *dp;
3650 u_int lbppbe, lalba;
3653 softc = (struct da_softc *)periph->softc;
3655 dp = &softc->params;
3656 dp->secsize = block_len;
3657 dp->sectors = maxsector + 1;
3658 if (rcaplong != NULL) {
3659 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3660 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3661 lalba &= SRC16_LALBA_A;
3668 dp->stripesize = block_len << lbppbe;
3669 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
3671 } else if (softc->quirks & DA_Q_4K) {
3672 dp->stripesize = 4096;
3673 dp->stripeoffset = 0;
3676 dp->stripeoffset = 0;
3679 * Have the controller provide us with a geometry
3680 * for this disk. The only time the geometry
3681 * matters is when we boot and the controller
3682 * is the only one knowledgeable enough to come
3683 * up with something that will make this a bootable
3686 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3687 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
3688 ccg.block_size = dp->secsize;
3689 ccg.volume_size = dp->sectors;
3691 ccg.secs_per_track = 0;
3693 xpt_action((union ccb*)&ccg);
3694 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3696 * We don't know what went wrong here- but just pick
3697 * a geometry so we don't have nasty things like divide
3701 dp->secs_per_track = 255;
3702 dp->cylinders = dp->sectors / (255 * 255);
3703 if (dp->cylinders == 0) {
3707 dp->heads = ccg.heads;
3708 dp->secs_per_track = ccg.secs_per_track;
3709 dp->cylinders = ccg.cylinders;
3713 * If the user supplied a read capacity buffer, and if it is
3714 * different than the previous buffer, update the data in the EDT.
3715 * If it's the same, we don't bother. This avoids sending an
3716 * update every time someone opens this device.
3718 if ((rcaplong != NULL)
3719 && (bcmp(rcaplong, &softc->rcaplong,
3720 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
3721 struct ccb_dev_advinfo cdai;
3723 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3724 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
3725 cdai.buftype = CDAI_TYPE_RCAPLONG;
3726 cdai.flags |= CDAI_FLAG_STORE;
3727 cdai.bufsiz = rcap_len;
3728 cdai.buf = (uint8_t *)rcaplong;
3729 xpt_action((union ccb *)&cdai);
3730 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
3731 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
3732 if (cdai.ccb_h.status != CAM_REQ_CMP) {
3733 xpt_print(periph->path, "%s: failed to set read "
3734 "capacity advinfo\n", __func__);
3735 /* Use cam_error_print() to decode the status */
3736 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
3739 bcopy(rcaplong, &softc->rcaplong,
3740 min(sizeof(softc->rcaplong), rcap_len));
3744 softc->disk->d_sectorsize = softc->params.secsize;
3745 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
3746 softc->disk->d_stripesize = softc->params.stripesize;
3747 softc->disk->d_stripeoffset = softc->params.stripeoffset;
3748 /* XXX: these are not actually "firmware" values, so they may be wrong */
3749 softc->disk->d_fwsectors = softc->params.secs_per_track;
3750 softc->disk->d_fwheads = softc->params.heads;
3751 softc->disk->d_devstat->block_size = softc->params.secsize;
3752 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
3754 error = disk_resize(softc->disk, M_NOWAIT);
3756 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
3760 dasendorderedtag(void *arg)
3762 struct da_softc *softc = arg;
3764 if (da_send_ordered) {
3765 if (!LIST_EMPTY(&softc->pending_ccbs)) {
3766 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
3767 softc->flags |= DA_FLAG_NEED_OTAG;
3768 softc->flags &= ~DA_FLAG_WAS_OTAG;
3771 /* Queue us up again */
3772 callout_reset(&softc->sendordered_c,
3773 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
3774 dasendorderedtag, softc);
3778 * Step through all DA peripheral drivers, and if the device is still open,
3779 * sync the disk cache to physical media.
3782 dashutdown(void * arg, int howto)
3784 struct cam_periph *periph;
3785 struct da_softc *softc;
3789 CAM_PERIPH_FOREACH(periph, &dadriver) {
3790 softc = (struct da_softc *)periph->softc;
3791 if (SCHEDULER_STOPPED()) {
3792 /* If we paniced with the lock held, do not recurse. */
3793 if (!cam_periph_owned(periph) &&
3794 (softc->flags & DA_FLAG_OPEN)) {
3795 dadump(softc->disk, NULL, 0, 0, 0);
3799 cam_periph_lock(periph);
3802 * We only sync the cache if the drive is still open, and
3803 * if the drive is capable of it..
3805 if (((softc->flags & DA_FLAG_OPEN) == 0)
3806 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
3807 cam_periph_unlock(periph);
3811 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3812 scsi_synchronize_cache(&ccb->csio,
3816 /*begin_lba*/0, /* whole disk */
3821 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
3822 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
3823 softc->disk->d_devstat);
3825 xpt_print(periph->path, "Synchronize cache failed\n");
3826 xpt_release_ccb(ccb);
3827 cam_periph_unlock(periph);
3831 #else /* !_KERNEL */
3834 * XXX This is only left out of the kernel build to silence warnings. If,
3835 * for some reason this function is used in the kernel, the ifdefs should
3836 * be moved so it is included both in the kernel and userland.
3839 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
3840 void (*cbfcnp)(struct cam_periph *, union ccb *),
3841 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
3842 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3845 struct scsi_format_unit *scsi_cmd;
3847 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
3848 scsi_cmd->opcode = FORMAT_UNIT;
3849 scsi_cmd->byte2 = byte2;
3850 scsi_ulto2b(ileave, scsi_cmd->interleave);
3855 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3865 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
3866 void (*cbfcnp)(struct cam_periph *, union ccb *),
3867 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
3868 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3871 struct scsi_sanitize *scsi_cmd;
3873 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
3874 scsi_cmd->opcode = SANITIZE;
3875 scsi_cmd->byte2 = byte2;
3876 scsi_cmd->control = control;
3877 scsi_ulto2b(dxfer_len, scsi_cmd->length);
3882 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3891 #endif /* _KERNEL */