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
98 DA_Q_NO_SYNC_CACHE = 0x01,
99 DA_Q_NO_6_BYTE = 0x02,
100 DA_Q_NO_PREVENT = 0x04,
105 #define DA_Q_BIT_STRING \
107 "\001NO_SYNC_CACHE" \
114 DA_CCB_PROBE_RC = 0x01,
115 DA_CCB_PROBE_RC16 = 0x02,
116 DA_CCB_PROBE_LBP = 0x03,
117 DA_CCB_PROBE_BLK_LIMITS = 0x04,
118 DA_CCB_PROBE_BDC = 0x05,
119 DA_CCB_PROBE_ATA = 0x06,
120 DA_CCB_BUFFER_IO = 0x07,
122 DA_CCB_DELETE = 0x0B,
124 DA_CCB_TYPE_MASK = 0x0F,
125 DA_CCB_RETRY_UA = 0x10
129 * Order here is important for method choice
131 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
132 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
133 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
134 * import taking 5mins.
145 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
146 DA_DELETE_MAX = DA_DELETE_ZERO
149 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
151 static da_delete_func_t da_delete_trim;
152 static da_delete_func_t da_delete_unmap;
153 static da_delete_func_t da_delete_ws;
155 static const void * da_delete_functions[] = {
165 static const char *da_delete_method_names[] =
166 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
167 static const char *da_delete_method_desc[] =
168 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
169 "WRITE SAME(10) with UNMAP", "ZERO" };
171 /* Offsets into our private area for storing information */
172 #define ccb_state ppriv_field0
173 #define ccb_bp ppriv_ptr1
178 u_int8_t secs_per_track;
179 u_int32_t secsize; /* Number of bytes/sector */
180 u_int64_t sectors; /* total number sectors */
185 #define UNMAP_RANGE_MAX 0xffffffff
186 #define UNMAP_HEAD_SIZE 8
187 #define UNMAP_RANGE_SIZE 16
188 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
189 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
192 #define WS10_MAX_BLKS 0xffff
193 #define WS16_MAX_BLKS 0xffffffff
194 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
195 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
198 struct bio_queue_head bio_queue;
199 struct bio_queue_head delete_queue;
200 struct bio_queue_head delete_run_queue;
201 LIST_HEAD(, ccb_hdr) pending_ccbs;
202 int tur; /* TEST UNIT READY should be sent */
203 int refcount; /* Active xpt_action() calls */
208 int minimum_cmd_size;
212 int delete_available; /* Delete methods possibly available */
213 uint32_t unmap_max_ranges;
214 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
215 uint64_t ws_max_blks;
216 da_delete_methods delete_method;
217 da_delete_func_t *delete_func;
218 struct disk_params params;
221 struct task sysctl_task;
222 struct sysctl_ctx_list sysctl_ctx;
223 struct sysctl_oid *sysctl_tree;
224 struct callout sendordered_c;
226 uint8_t unmap_buf[UNMAP_BUF_SIZE];
227 struct scsi_read_capacity_data_long rcaplong;
228 struct callout mediapoll_c;
231 #define dadeleteflag(softc, delete_method, enable) \
233 softc->delete_available |= (1 << delete_method); \
235 softc->delete_available &= ~(1 << delete_method); \
238 struct da_quirk_entry {
239 struct scsi_inquiry_pattern inq_pat;
243 static const char quantum[] = "QUANTUM";
244 static const char microp[] = "MICROP";
246 static struct da_quirk_entry da_quirk_table[] =
248 /* SPI, FC devices */
251 * Fujitsu M2513A MO drives.
252 * Tested devices: M2513A2 firmware versions 1200 & 1300.
253 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
254 * Reported by: W.Scholten <whs@xs4all.nl>
256 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
257 /*quirks*/ DA_Q_NO_SYNC_CACHE
261 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
262 /*quirks*/ DA_Q_NO_SYNC_CACHE
266 * This particular Fujitsu drive doesn't like the
267 * synchronize cache command.
268 * Reported by: Tom Jackson <toj@gorilla.net>
270 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
271 /*quirks*/ DA_Q_NO_SYNC_CACHE
275 * This drive doesn't like the synchronize cache command
276 * either. Reported by: Matthew Jacob <mjacob@feral.com>
277 * in NetBSD PR kern/6027, August 24, 1998.
279 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
280 /*quirks*/ DA_Q_NO_SYNC_CACHE
284 * This drive doesn't like the synchronize cache command
285 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
288 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
289 /*quirks*/ DA_Q_NO_SYNC_CACHE
293 * Doesn't like the synchronize cache command.
294 * Reported by: Blaz Zupan <blaz@gold.amis.net>
296 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
297 /*quirks*/ DA_Q_NO_SYNC_CACHE
301 * Doesn't like the synchronize cache command.
302 * Reported by: Blaz Zupan <blaz@gold.amis.net>
304 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
305 /*quirks*/ DA_Q_NO_SYNC_CACHE
309 * Doesn't like the synchronize cache command.
311 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
312 /*quirks*/ DA_Q_NO_SYNC_CACHE
316 * Doesn't like the synchronize cache command.
317 * Reported by: walter@pelissero.de
319 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
320 /*quirks*/ DA_Q_NO_SYNC_CACHE
324 * Doesn't work correctly with 6 byte reads/writes.
325 * Returns illegal request, and points to byte 9 of the
327 * Reported by: Adam McDougall <bsdx@spawnet.com>
329 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
330 /*quirks*/ DA_Q_NO_6_BYTE
334 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
335 /*quirks*/ DA_Q_NO_6_BYTE
339 * Doesn't like the synchronize cache command.
340 * Reported by: walter@pelissero.de
342 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
343 /*quirks*/ DA_Q_NO_SYNC_CACHE
347 * The CISS RAID controllers do not support SYNC_CACHE
349 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
350 /*quirks*/ DA_Q_NO_SYNC_CACHE
352 /* USB mass storage devices supported by umass(4) */
355 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
358 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
359 /*quirks*/ DA_Q_NO_SYNC_CACHE
363 * Power Quotient Int. (PQI) USB flash key
366 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
367 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
371 * Creative Nomad MUVO mp3 player (USB)
374 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
375 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
379 * Jungsoft NEXDISK USB flash key
382 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
383 /*quirks*/ DA_Q_NO_SYNC_CACHE
387 * FreeDik USB Mini Data Drive
390 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
391 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
395 * Sigmatel USB Flash MP3 Player
398 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
399 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
403 * Neuros USB Digital Audio Computer
406 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
407 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
411 * SEAGRAND NP-900 MP3 Player
414 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
415 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
419 * iRiver iFP MP3 player (with UMS Firmware)
420 * PR: kern/54881, i386/63941, kern/66124
422 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
423 /*quirks*/ DA_Q_NO_SYNC_CACHE
427 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
430 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
431 /*quirks*/ DA_Q_NO_SYNC_CACHE
435 * ZICPlay USB MP3 Player with FM
438 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
439 /*quirks*/ DA_Q_NO_SYNC_CACHE
443 * TEAC USB floppy mechanisms
445 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
446 /*quirks*/ DA_Q_NO_SYNC_CACHE
450 * Kingston DataTraveler II+ USB Pen-Drive.
451 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
453 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
454 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
462 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
463 /*quirks*/ DA_Q_NO_SYNC_CACHE
467 * Motorola E398 Mobile Phone (TransFlash memory card).
468 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
471 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
472 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
476 * Qware BeatZkey! Pro
479 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
480 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
484 * Time DPA20B 1GB MP3 Player
487 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
488 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
492 * Samsung USB key 128Mb
495 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
496 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
500 * Kingston DataTraveler 2.0 USB Flash memory.
503 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
504 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
508 * Creative MUVO Slim mp3 player (USB)
511 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
512 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
516 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
519 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
520 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
524 * SanDisk Micro Cruzer 128MB
527 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
528 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
532 * TOSHIBA TransMemory USB sticks
535 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
536 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
541 * PR: usb/75578, usb/72344, usb/65436
543 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
544 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
548 * Genesys 6-in-1 Card Reader
551 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
552 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
556 * Rekam Digital CAMERA
559 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
560 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
564 * iRiver H10 MP3 player
567 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
568 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
572 * iRiver U10 MP3 player
575 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
576 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
583 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
584 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
588 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
591 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
592 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
599 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
600 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
604 * Philips USB Key Audio KEY013
607 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
608 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
615 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
616 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
623 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
624 /*quirks*/ DA_Q_NO_SYNC_CACHE
628 * I/O Magic USB flash - Giga Bank
631 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
632 /*quirks*/ DA_Q_NO_SYNC_CACHE
636 * JoyFly 128mb USB Flash Drive
639 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
640 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
647 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
648 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
652 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
655 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
656 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
660 * Samsung YP-U3 mp3-player
663 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
664 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
667 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
668 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
672 * Sony Cyber-Shot DSC cameras
675 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
676 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
679 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
680 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
683 /* At least several Transcent USB sticks lie on RC16. */
684 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
685 "*"}, /*quirks*/ DA_Q_NO_RC16
687 /* ATA/SATA devices over SAS/USB/... */
689 /* Hitachi Advanced Format (4k) drives */
690 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
694 /* Samsung Advanced Format (4k) drives */
695 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
699 /* Samsung Advanced Format (4k) drives */
700 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
704 /* Samsung Advanced Format (4k) drives */
705 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
709 /* Samsung Advanced Format (4k) drives */
710 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
714 /* Seagate Barracuda Green Advanced Format (4k) drives */
715 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
719 /* Seagate Barracuda Green Advanced Format (4k) drives */
720 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
724 /* Seagate Barracuda Green Advanced Format (4k) drives */
725 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
729 /* Seagate Barracuda Green Advanced Format (4k) drives */
730 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
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 Momentus Advanced Format (4k) drives */
745 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
749 /* Seagate Momentus Advanced Format (4k) drives */
750 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
754 /* Seagate Momentus Advanced Format (4k) drives */
755 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
759 /* Seagate Momentus Advanced Format (4k) drives */
760 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
764 /* Seagate Momentus Advanced Format (4k) drives */
765 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
769 /* Seagate Momentus Advanced Format (4k) drives */
770 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
774 /* Seagate Momentus Advanced Format (4k) drives */
775 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
779 /* Seagate Momentus Advanced Format (4k) drives */
780 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
784 /* Seagate Momentus Advanced Format (4k) drives */
785 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
789 /* Seagate Momentus Advanced Format (4k) drives */
790 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
794 /* Seagate Momentus Advanced Format (4k) drives */
795 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
799 /* Seagate Momentus Advanced Format (4k) drives */
800 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
804 /* Seagate Momentus Advanced Format (4k) drives */
805 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
809 /* Seagate Momentus Advanced Format (4k) drives */
810 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
814 /* Seagate Momentus Thin Advanced Format (4k) drives */
815 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
819 /* Seagate Momentus Thin Advanced Format (4k) drives */
820 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
824 /* WDC Caviar Green Advanced Format (4k) drives */
825 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
829 /* WDC Caviar Green Advanced Format (4k) drives */
830 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
834 /* WDC Caviar Green Advanced Format (4k) drives */
835 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
839 /* WDC Caviar Green Advanced Format (4k) drives */
840 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
844 /* WDC Caviar Green Advanced Format (4k) drives */
845 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
849 /* WDC Caviar Green Advanced Format (4k) drives */
850 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
854 /* WDC Caviar Green Advanced Format (4k) drives */
855 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
859 /* WDC Caviar Green Advanced Format (4k) drives */
860 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
864 /* WDC Scorpio Black Advanced Format (4k) drives */
865 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
869 /* WDC Scorpio Black Advanced Format (4k) drives */
870 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
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 Blue Advanced Format (4k) drives */
885 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
889 /* WDC Scorpio Blue Advanced Format (4k) drives */
890 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
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*", "*" },
905 * Olympus FE-210 camera
907 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
908 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
914 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
915 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
919 * Laser MP3-2GA13 MP3 player
921 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
922 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
926 * LaCie external 250GB Hard drive des by Porsche
927 * Submitted by: Ben Stuyts <ben@altesco.nl>
930 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
931 /*quirks*/ DA_Q_NO_SYNC_CACHE
936 * Corsair Force 2 SSDs
937 * 4k optimised & trim only works in 4k requests + 4k aligned
939 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
944 * Corsair Force 3 SSDs
945 * 4k optimised & trim only works in 4k requests + 4k aligned
947 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
952 * Corsair Neutron GTX SSDs
953 * 4k optimised & trim only works in 4k requests + 4k aligned
955 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
960 * Corsair Force GT SSDs
961 * 4k optimised & trim only works in 4k requests + 4k aligned
963 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force GT*", "*" },
969 * 4k optimised & trim only works in 4k requests + 4k aligned
971 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
976 * Crucial RealSSD C300 SSDs
979 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
980 "*" }, /*quirks*/DA_Q_4K
984 * Intel 320 Series SSDs
985 * 4k optimised & trim only works in 4k requests + 4k aligned
987 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
992 * Intel 330 Series SSDs
993 * 4k optimised & trim only works in 4k requests + 4k aligned
995 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1000 * Intel 510 Series SSDs
1001 * 4k optimised & trim only works in 4k requests + 4k aligned
1003 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1008 * Intel 520 Series SSDs
1009 * 4k optimised & trim only works in 4k requests + 4k aligned
1011 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1016 * Intel X25-M Series SSDs
1017 * 4k optimised & trim only works in 4k requests + 4k aligned
1019 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1024 * Kingston E100 Series SSDs
1025 * 4k optimised & trim only works in 4k requests + 4k aligned
1027 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1032 * Kingston HyperX 3k SSDs
1033 * 4k optimised & trim only works in 4k requests + 4k aligned
1035 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1040 * Marvell SSDs (entry taken from OpenSolaris)
1041 * 4k optimised & trim only works in 4k requests + 4k aligned
1043 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1048 * OCZ Agility 2 SSDs
1049 * 4k optimised & trim only works in 4k requests + 4k aligned
1051 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1056 * OCZ Agility 3 SSDs
1057 * 4k optimised & trim only works in 4k requests + 4k aligned
1059 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1064 * OCZ Deneva R Series SSDs
1065 * 4k optimised & trim only works in 4k requests + 4k aligned
1067 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1072 * OCZ Vertex 2 SSDs (inc pro series)
1073 * 4k optimised & trim only works in 4k requests + 4k aligned
1075 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1081 * 4k optimised & trim only works in 4k requests + 4k aligned
1083 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1089 * 4k optimised & trim only works in 4k requests + 4k aligned
1091 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1096 * Samsung 830 Series SSDs
1097 * 4k optimised & trim only works in 4k requests + 4k aligned
1099 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1104 * SuperTalent TeraDrive CT SSDs
1105 * 4k optimised & trim only works in 4k requests + 4k aligned
1107 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1112 * XceedIOPS SATA SSDs
1115 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1120 static disk_strategy_t dastrategy;
1121 static dumper_t dadump;
1122 static periph_init_t dainit;
1123 static void daasync(void *callback_arg, u_int32_t code,
1124 struct cam_path *path, void *arg);
1125 static void dasysctlinit(void *context, int pending);
1126 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1127 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1128 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1129 static void dadeletemethodset(struct da_softc *softc,
1130 da_delete_methods delete_method);
1131 static off_t dadeletemaxsize(struct da_softc *softc,
1132 da_delete_methods delete_method);
1133 static void dadeletemethodchoose(struct da_softc *softc,
1134 da_delete_methods default_method);
1135 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1137 static periph_ctor_t daregister;
1138 static periph_dtor_t dacleanup;
1139 static periph_start_t dastart;
1140 static periph_oninv_t daoninvalidate;
1141 static void dadone(struct cam_periph *periph,
1142 union ccb *done_ccb);
1143 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1144 u_int32_t sense_flags);
1145 static void daprevent(struct cam_periph *periph, int action);
1146 static void dareprobe(struct cam_periph *periph);
1147 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1149 struct scsi_read_capacity_data_long *rcaplong,
1151 static timeout_t dasendorderedtag;
1152 static void dashutdown(void *arg, int howto);
1153 static timeout_t damediapoll;
1155 #ifndef DA_DEFAULT_POLL_PERIOD
1156 #define DA_DEFAULT_POLL_PERIOD 3
1159 #ifndef DA_DEFAULT_TIMEOUT
1160 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1163 #ifndef DA_DEFAULT_RETRY
1164 #define DA_DEFAULT_RETRY 4
1167 #ifndef DA_DEFAULT_SEND_ORDERED
1168 #define DA_DEFAULT_SEND_ORDERED 1
1171 #define DA_SIO (softc->sort_io_queue >= 0 ? \
1172 softc->sort_io_queue : cam_sort_io_queues)
1174 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1175 static int da_retry_count = DA_DEFAULT_RETRY;
1176 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1177 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1179 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1180 "CAM Direct Access Disk driver");
1181 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RW,
1182 &da_poll_period, 0, "Media polling period in seconds");
1183 TUNABLE_INT("kern.cam.da.poll_period", &da_poll_period);
1184 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RW,
1185 &da_retry_count, 0, "Normal I/O retry count");
1186 TUNABLE_INT("kern.cam.da.retry_count", &da_retry_count);
1187 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RW,
1188 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1189 TUNABLE_INT("kern.cam.da.default_timeout", &da_default_timeout);
1190 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RW,
1191 &da_send_ordered, 0, "Send Ordered Tags");
1192 TUNABLE_INT("kern.cam.da.send_ordered", &da_send_ordered);
1195 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1196 * to the default timeout, we check to see whether an ordered
1197 * tagged transaction is appropriate to prevent simple tag
1198 * starvation. Since we'd like to ensure that there is at least
1199 * 1/2 of the timeout length left for a starved transaction to
1200 * complete after we've sent an ordered tag, we must poll at least
1201 * four times in every timeout period. This takes care of the worst
1202 * case where a starved transaction starts during an interval that
1203 * meets the requirement "don't send an ordered tag" test so it takes
1204 * us two intervals to determine that a tag must be sent.
1206 #ifndef DA_ORDEREDTAG_INTERVAL
1207 #define DA_ORDEREDTAG_INTERVAL 4
1210 static struct periph_driver dadriver =
1213 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1216 PERIPHDRIVER_DECLARE(da, dadriver);
1218 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1221 daopen(struct disk *dp)
1223 struct cam_periph *periph;
1224 struct da_softc *softc;
1227 periph = (struct cam_periph *)dp->d_drv1;
1228 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1232 cam_periph_lock(periph);
1233 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1234 cam_periph_unlock(periph);
1235 cam_periph_release(periph);
1239 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1242 softc = (struct da_softc *)periph->softc;
1245 /* Wait for the disk size update. */
1246 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1249 xpt_print(periph->path, "unable to retrieve capacity data\n");
1251 if (periph->flags & CAM_PERIPH_INVALID)
1254 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1255 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1256 daprevent(periph, PR_PREVENT);
1259 softc->flags &= ~DA_FLAG_PACK_INVALID;
1260 softc->flags |= DA_FLAG_OPEN;
1263 cam_periph_unhold(periph);
1264 cam_periph_unlock(periph);
1267 cam_periph_release(periph);
1273 daclose(struct disk *dp)
1275 struct cam_periph *periph;
1276 struct da_softc *softc;
1280 periph = (struct cam_periph *)dp->d_drv1;
1281 softc = (struct da_softc *)periph->softc;
1282 cam_periph_lock(periph);
1283 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1286 if (cam_periph_hold(periph, PRIBIO) == 0) {
1288 /* Flush disk cache. */
1289 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1290 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1291 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1292 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1293 scsi_synchronize_cache(&ccb->csio, /*retries*/1,
1294 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG,
1295 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE,
1297 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1298 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1299 softc->disk->d_devstat);
1301 softc->flags &= ~DA_FLAG_DIRTY;
1302 xpt_release_ccb(ccb);
1305 /* Allow medium removal. */
1306 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1307 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1308 daprevent(periph, PR_ALLOW);
1310 cam_periph_unhold(periph);
1314 * If we've got removeable media, mark the blocksize as
1315 * unavailable, since it could change when new media is
1318 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0)
1319 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1321 softc->flags &= ~DA_FLAG_OPEN;
1322 while (softc->refcount != 0)
1323 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1);
1324 cam_periph_unlock(periph);
1325 cam_periph_release(periph);
1330 daschedule(struct cam_periph *periph)
1332 struct da_softc *softc = (struct da_softc *)periph->softc;
1334 if (softc->state != DA_STATE_NORMAL)
1337 /* Check if we have more work to do. */
1338 if (bioq_first(&softc->bio_queue) ||
1339 (!softc->delete_running && bioq_first(&softc->delete_queue)) ||
1341 xpt_schedule(periph, CAM_PRIORITY_NORMAL);
1346 * Actually translate the requested transfer into one the physical driver
1347 * can understand. The transfer is described by a buf and will include
1348 * only one physical transfer.
1351 dastrategy(struct bio *bp)
1353 struct cam_periph *periph;
1354 struct da_softc *softc;
1356 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1357 softc = (struct da_softc *)periph->softc;
1359 cam_periph_lock(periph);
1362 * If the device has been made invalid, error out
1364 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1365 cam_periph_unlock(periph);
1366 biofinish(bp, NULL, ENXIO);
1370 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1373 * Place it in the queue of disk activities for this disk
1375 if (bp->bio_cmd == BIO_DELETE) {
1377 bioq_disksort(&softc->delete_queue, bp);
1379 bioq_insert_tail(&softc->delete_queue, bp);
1380 } else if (DA_SIO) {
1381 bioq_disksort(&softc->bio_queue, bp);
1383 bioq_insert_tail(&softc->bio_queue, bp);
1387 * Schedule ourselves for performing the work.
1390 cam_periph_unlock(periph);
1396 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1398 struct cam_periph *periph;
1399 struct da_softc *softc;
1401 struct ccb_scsiio csio;
1406 periph = dp->d_drv1;
1407 softc = (struct da_softc *)periph->softc;
1408 cam_periph_lock(periph);
1409 secsize = softc->params.secsize;
1411 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1412 cam_periph_unlock(periph);
1417 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1418 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1419 scsi_read_write(&csio,
1423 /*read*/SCSI_RW_WRITE,
1425 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1428 /*data_ptr*/(u_int8_t *) virtual,
1429 /*dxfer_len*/length,
1430 /*sense_len*/SSD_FULL_SIZE,
1431 da_default_timeout * 1000);
1432 xpt_polled_action((union ccb *)&csio);
1434 error = cam_periph_error((union ccb *)&csio,
1435 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1436 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1437 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1438 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1440 printf("Aborting dump due to I/O error.\n");
1441 cam_periph_unlock(periph);
1446 * Sync the disk cache contents to the physical media.
1448 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1450 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1451 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1452 scsi_synchronize_cache(&csio,
1456 /*begin_lba*/0,/* Cover the whole disk */
1460 xpt_polled_action((union ccb *)&csio);
1462 error = cam_periph_error((union ccb *)&csio,
1463 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1464 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1465 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1466 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1468 xpt_print(periph->path, "Synchronize cache failed\n");
1470 cam_periph_unlock(periph);
1475 dagetattr(struct bio *bp)
1478 struct cam_periph *periph;
1480 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1481 cam_periph_lock(periph);
1482 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1484 cam_periph_unlock(periph);
1486 bp->bio_completed = bp->bio_length;
1496 * Install a global async callback. This callback will
1497 * receive async callbacks like "new device found".
1499 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1501 if (status != CAM_REQ_CMP) {
1502 printf("da: Failed to attach master async callback "
1503 "due to status 0x%x!\n", status);
1504 } else if (da_send_ordered) {
1506 /* Register our shutdown event handler */
1507 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1508 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1509 printf("dainit: shutdown event registration failed!\n");
1514 * Callback from GEOM, called when it has finished cleaning up its
1518 dadiskgonecb(struct disk *dp)
1520 struct cam_periph *periph;
1522 periph = (struct cam_periph *)dp->d_drv1;
1523 cam_periph_release(periph);
1527 daoninvalidate(struct cam_periph *periph)
1529 struct da_softc *softc;
1531 softc = (struct da_softc *)periph->softc;
1534 * De-register any async callbacks.
1536 xpt_register_async(0, daasync, periph, periph->path);
1538 softc->flags |= DA_FLAG_PACK_INVALID;
1541 * Return all queued I/O with ENXIO.
1542 * XXX Handle any transactions queued to the card
1543 * with XPT_ABORT_CCB.
1545 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1546 bioq_flush(&softc->delete_queue, NULL, ENXIO);
1549 * Tell GEOM that we've gone away, we'll get a callback when it is
1550 * done cleaning up its resources.
1552 disk_gone(softc->disk);
1556 dacleanup(struct cam_periph *periph)
1558 struct da_softc *softc;
1560 softc = (struct da_softc *)periph->softc;
1562 cam_periph_unlock(periph);
1565 * If we can't free the sysctl tree, oh well...
1567 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1568 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1569 xpt_print(periph->path, "can't remove sysctl context\n");
1572 callout_drain(&softc->mediapoll_c);
1573 disk_destroy(softc->disk);
1574 callout_drain(&softc->sendordered_c);
1575 free(softc, M_DEVBUF);
1576 cam_periph_lock(periph);
1580 daasync(void *callback_arg, u_int32_t code,
1581 struct cam_path *path, void *arg)
1583 struct cam_periph *periph;
1584 struct da_softc *softc;
1586 periph = (struct cam_periph *)callback_arg;
1588 case AC_FOUND_DEVICE:
1590 struct ccb_getdev *cgd;
1593 cgd = (struct ccb_getdev *)arg;
1597 if (cgd->protocol != PROTO_SCSI)
1600 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1601 && SID_TYPE(&cgd->inq_data) != T_RBC
1602 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1606 * Allocate a peripheral instance for
1607 * this device and start the probe
1610 status = cam_periph_alloc(daregister, daoninvalidate,
1612 "da", CAM_PERIPH_BIO,
1614 AC_FOUND_DEVICE, cgd);
1616 if (status != CAM_REQ_CMP
1617 && status != CAM_REQ_INPROG)
1618 printf("daasync: Unable to attach to new device "
1619 "due to status 0x%x\n", status);
1622 case AC_ADVINFO_CHANGED:
1626 buftype = (uintptr_t)arg;
1627 if (buftype == CDAI_TYPE_PHYS_PATH) {
1628 struct da_softc *softc;
1630 softc = periph->softc;
1631 disk_attr_changed(softc->disk, "GEOM::physpath",
1636 case AC_UNIT_ATTENTION:
1639 int error_code, sense_key, asc, ascq;
1641 softc = (struct da_softc *)periph->softc;
1642 ccb = (union ccb *)arg;
1645 * Handle all UNIT ATTENTIONs except our own,
1646 * as they will be handled by daerror().
1648 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1649 scsi_extract_sense_ccb(ccb,
1650 &error_code, &sense_key, &asc, &ascq)) {
1651 if (asc == 0x2A && ascq == 0x09) {
1652 xpt_print(ccb->ccb_h.path,
1653 "capacity data has changed\n");
1655 } else if (asc == 0x28 && ascq == 0x00)
1656 disk_media_changed(softc->disk, M_NOWAIT);
1658 cam_periph_async(periph, code, path, arg);
1662 softc = (struct da_softc *)periph->softc;
1664 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1673 struct ccb_hdr *ccbh;
1675 softc = (struct da_softc *)periph->softc;
1677 * Don't fail on the expected unit attention
1680 softc->flags |= DA_FLAG_RETRY_UA;
1681 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1682 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1688 cam_periph_async(periph, code, path, arg);
1692 dasysctlinit(void *context, int pending)
1694 struct cam_periph *periph;
1695 struct da_softc *softc;
1696 char tmpstr[80], tmpstr2[80];
1697 struct ccb_trans_settings cts;
1699 periph = (struct cam_periph *)context;
1701 * periph was held for us when this task was enqueued
1703 if (periph->flags & CAM_PERIPH_INVALID) {
1704 cam_periph_release(periph);
1708 softc = (struct da_softc *)periph->softc;
1709 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1710 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1712 sysctl_ctx_init(&softc->sysctl_ctx);
1713 softc->flags |= DA_FLAG_SCTX_INIT;
1714 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1715 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1716 CTLFLAG_RD, 0, tmpstr);
1717 if (softc->sysctl_tree == NULL) {
1718 printf("dasysctlinit: unable to allocate sysctl tree\n");
1719 cam_periph_release(periph);
1724 * Now register the sysctl handler, so the user can change the value on
1727 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1728 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RW,
1729 softc, 0, dadeletemethodsysctl, "A",
1730 "BIO_DELETE execution method");
1731 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1732 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1733 softc, 0, dadeletemaxsysctl, "Q",
1734 "Maximum BIO_DELETE size");
1735 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1736 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1737 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1738 "Minimum CDB size");
1739 SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1740 OID_AUTO, "sort_io_queue", CTLFLAG_RW, &softc->sort_io_queue, 0,
1741 "Sort IO queue to try and optimise disk access patterns");
1743 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1744 SYSCTL_CHILDREN(softc->sysctl_tree),
1748 &softc->error_inject,
1750 "error_inject leaf");
1754 * Add some addressing info.
1756 memset(&cts, 0, sizeof (cts));
1757 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1758 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1759 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1760 cam_periph_lock(periph);
1761 xpt_action((union ccb *)&cts);
1762 cam_periph_unlock(periph);
1763 if (cts.ccb_h.status != CAM_REQ_CMP) {
1764 cam_periph_release(periph);
1767 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
1768 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1769 if (fc->valid & CTS_FC_VALID_WWPN) {
1770 softc->wwpn = fc->wwpn;
1771 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1772 SYSCTL_CHILDREN(softc->sysctl_tree),
1773 OID_AUTO, "wwpn", CTLFLAG_RD,
1774 &softc->wwpn, "World Wide Port Name");
1777 cam_periph_release(periph);
1781 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
1785 struct da_softc *softc;
1787 softc = (struct da_softc *)arg1;
1789 value = softc->disk->d_delmaxsize;
1790 error = sysctl_handle_64(oidp, &value, 0, req);
1791 if ((error != 0) || (req->newptr == NULL))
1794 /* only accept values smaller than the calculated value */
1795 if (value > dadeletemaxsize(softc, softc->delete_method)) {
1798 softc->disk->d_delmaxsize = value;
1804 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1808 value = *(int *)arg1;
1810 error = sysctl_handle_int(oidp, &value, 0, req);
1813 || (req->newptr == NULL))
1817 * Acceptable values here are 6, 10, 12 or 16.
1821 else if ((value > 6)
1824 else if ((value > 10)
1827 else if (value > 12)
1830 *(int *)arg1 = value;
1836 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
1840 softc->delete_method = delete_method;
1841 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
1842 softc->delete_func = da_delete_functions[delete_method];
1844 if (softc->delete_method > DA_DELETE_DISABLE)
1845 softc->disk->d_flags |= DISKFLAG_CANDELETE;
1847 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
1851 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
1855 switch(delete_method) {
1856 case DA_DELETE_UNMAP:
1857 sectors = (off_t)softc->unmap_max_lba;
1859 case DA_DELETE_ATA_TRIM:
1860 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
1862 case DA_DELETE_WS16:
1863 sectors = (off_t)min(softc->ws_max_blks, WS16_MAX_BLKS);
1865 case DA_DELETE_ZERO:
1866 case DA_DELETE_WS10:
1867 sectors = (off_t)min(softc->ws_max_blks, WS10_MAX_BLKS);
1873 return (off_t)softc->params.secsize *
1874 min(sectors, (off_t)softc->params.sectors);
1878 daprobedone(struct cam_periph *periph, union ccb *ccb)
1880 struct da_softc *softc;
1882 softc = (struct da_softc *)periph->softc;
1884 dadeletemethodchoose(softc, DA_DELETE_NONE);
1886 if (bootverbose && (softc->flags & DA_FLAG_PROBED) == 0) {
1890 snprintf(buf, sizeof(buf), "Delete methods: <");
1892 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1893 if (softc->delete_available & (1 << i)) {
1895 strlcat(buf, ",", sizeof(buf));
1899 strlcat(buf, da_delete_method_names[i],
1901 if (i == softc->delete_method) {
1902 strlcat(buf, "(*)", sizeof(buf));
1907 if (softc->delete_method == DA_DELETE_NONE)
1908 strlcat(buf, "NONE(*)", sizeof(buf));
1910 strlcat(buf, "DISABLED(*)", sizeof(buf));
1912 strlcat(buf, ">", sizeof(buf));
1913 printf("%s%d: %s\n", periph->periph_name,
1914 periph->unit_number, buf);
1918 * Since our peripheral may be invalidated by an error
1919 * above or an external event, we must release our CCB
1920 * before releasing the probe lock on the peripheral.
1921 * The peripheral will only go away once the last lock
1922 * is removed, and we need it around for the CCB release
1925 xpt_release_ccb(ccb);
1926 softc->state = DA_STATE_NORMAL;
1928 wakeup(&softc->disk->d_mediasize);
1929 if ((softc->flags & DA_FLAG_PROBED) == 0) {
1930 softc->flags |= DA_FLAG_PROBED;
1931 cam_periph_unhold(periph);
1933 cam_periph_release_locked(periph);
1937 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
1939 int i, delete_method;
1941 delete_method = default_method;
1944 * Use the pre-defined order to choose the best
1945 * performing delete.
1947 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1948 if (softc->delete_available & (1 << i)) {
1949 dadeletemethodset(softc, i);
1953 dadeletemethodset(softc, delete_method);
1957 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
1961 struct da_softc *softc;
1962 int i, error, methods, value;
1964 softc = (struct da_softc *)arg1;
1966 value = softc->delete_method;
1967 if (value < 0 || value > DA_DELETE_MAX)
1970 p = da_delete_method_names[value];
1971 strncpy(buf, p, sizeof(buf));
1972 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
1973 if (error != 0 || req->newptr == NULL)
1975 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
1976 for (i = 0; i <= DA_DELETE_MAX; i++) {
1977 if (!(methods & (1 << i)) ||
1978 strcmp(buf, da_delete_method_names[i]) != 0)
1980 dadeletemethodset(softc, i);
1987 daregister(struct cam_periph *periph, void *arg)
1989 struct da_softc *softc;
1990 struct ccb_pathinq cpi;
1991 struct ccb_getdev *cgd;
1995 cgd = (struct ccb_getdev *)arg;
1997 printf("daregister: no getdev CCB, can't register device\n");
1998 return(CAM_REQ_CMP_ERR);
2001 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2004 if (softc == NULL) {
2005 printf("daregister: Unable to probe new device. "
2006 "Unable to allocate softc\n");
2007 return(CAM_REQ_CMP_ERR);
2010 LIST_INIT(&softc->pending_ccbs);
2011 softc->state = DA_STATE_PROBE_RC;
2012 bioq_init(&softc->bio_queue);
2013 bioq_init(&softc->delete_queue);
2014 bioq_init(&softc->delete_run_queue);
2015 if (SID_IS_REMOVABLE(&cgd->inq_data))
2016 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2017 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2018 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2019 softc->ws_max_blks = WS16_MAX_BLKS;
2020 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2021 softc->sort_io_queue = -1;
2023 periph->softc = softc;
2026 * See if this device has any quirks.
2028 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2029 (caddr_t)da_quirk_table,
2030 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
2031 sizeof(*da_quirk_table), scsi_inquiry_match);
2034 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2036 softc->quirks = DA_Q_NONE;
2038 /* Check if the SIM does not want 6 byte commands */
2039 bzero(&cpi, sizeof(cpi));
2040 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2041 cpi.ccb_h.func_code = XPT_PATH_INQ;
2042 xpt_action((union ccb *)&cpi);
2043 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2044 softc->quirks |= DA_Q_NO_6_BYTE;
2046 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2049 * Take an exclusive refcount on the periph while dastart is called
2050 * to finish the probe. The reference will be dropped in dadone at
2053 (void)cam_periph_hold(periph, PRIBIO);
2056 * Schedule a periodic event to occasionally send an
2057 * ordered tag to a device.
2059 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0);
2060 callout_reset(&softc->sendordered_c,
2061 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2062 dasendorderedtag, softc);
2064 cam_periph_unlock(periph);
2066 * RBC devices don't have to support READ(6), only READ(10).
2068 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2069 softc->minimum_cmd_size = 10;
2071 softc->minimum_cmd_size = 6;
2074 * Load the user's default, if any.
2076 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2077 periph->unit_number);
2078 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2081 * 6, 10, 12 and 16 are the currently permissible values.
2083 if (softc->minimum_cmd_size < 6)
2084 softc->minimum_cmd_size = 6;
2085 else if ((softc->minimum_cmd_size > 6)
2086 && (softc->minimum_cmd_size <= 10))
2087 softc->minimum_cmd_size = 10;
2088 else if ((softc->minimum_cmd_size > 10)
2089 && (softc->minimum_cmd_size <= 12))
2090 softc->minimum_cmd_size = 12;
2091 else if (softc->minimum_cmd_size > 12)
2092 softc->minimum_cmd_size = 16;
2094 /* Predict whether device may support READ CAPACITY(16). */
2095 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2096 (softc->quirks & DA_Q_NO_RC16) == 0) {
2097 softc->flags |= DA_FLAG_CAN_RC16;
2098 softc->state = DA_STATE_PROBE_RC16;
2102 * Register this media as a disk.
2104 softc->disk = disk_alloc();
2105 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2106 periph->unit_number, 0,
2107 DEVSTAT_BS_UNAVAILABLE,
2108 SID_TYPE(&cgd->inq_data) |
2109 XPORT_DEVSTAT_TYPE(cpi.transport),
2110 DEVSTAT_PRIORITY_DISK);
2111 softc->disk->d_open = daopen;
2112 softc->disk->d_close = daclose;
2113 softc->disk->d_strategy = dastrategy;
2114 softc->disk->d_dump = dadump;
2115 softc->disk->d_getattr = dagetattr;
2116 softc->disk->d_gone = dadiskgonecb;
2117 softc->disk->d_name = "da";
2118 softc->disk->d_drv1 = periph;
2120 softc->disk->d_maxsize = DFLTPHYS; /* traditional default */
2121 else if (cpi.maxio > MAXPHYS)
2122 softc->disk->d_maxsize = MAXPHYS; /* for safety */
2124 softc->disk->d_maxsize = cpi.maxio;
2125 softc->disk->d_unit = periph->unit_number;
2126 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION;
2127 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2128 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2129 if ((cpi.hba_misc & PIM_UNMAPPED) != 0)
2130 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2131 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2132 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2133 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2134 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2135 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2136 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2137 softc->disk->d_hba_vendor = cpi.hba_vendor;
2138 softc->disk->d_hba_device = cpi.hba_device;
2139 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2140 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2143 * Acquire a reference to the periph before we register with GEOM.
2144 * We'll release this reference once GEOM calls us back (via
2145 * dadiskgonecb()) telling us that our provider has been freed.
2147 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2148 xpt_print(periph->path, "%s: lost periph during "
2149 "registration!\n", __func__);
2150 cam_periph_lock(periph);
2151 return (CAM_REQ_CMP_ERR);
2154 disk_create(softc->disk, DISK_VERSION);
2155 cam_periph_lock(periph);
2158 * Add async callbacks for events of interest.
2159 * I don't bother checking if this fails as,
2160 * in most cases, the system will function just
2161 * fine without them and the only alternative
2162 * would be to not attach the device on failure.
2164 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2165 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION,
2166 daasync, periph, periph->path);
2169 * Emit an attribute changed notification just in case
2170 * physical path information arrived before our async
2171 * event handler was registered, but after anyone attaching
2172 * to our disk device polled it.
2174 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2177 * Schedule a periodic media polling events.
2179 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0);
2180 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2181 (cgd->inq_flags & SID_AEN) == 0 &&
2182 da_poll_period != 0)
2183 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2184 damediapoll, periph);
2186 xpt_schedule(periph, CAM_PRIORITY_DEV);
2188 return(CAM_REQ_CMP);
2192 dastart(struct cam_periph *periph, union ccb *start_ccb)
2194 struct da_softc *softc;
2196 softc = (struct da_softc *)periph->softc;
2198 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2201 switch (softc->state) {
2202 case DA_STATE_NORMAL:
2207 /* Run BIO_DELETE if not running yet. */
2208 if (!softc->delete_running &&
2209 (bp = bioq_first(&softc->delete_queue)) != NULL) {
2210 if (softc->delete_func != NULL) {
2211 softc->delete_func(periph, start_ccb, bp);
2214 bioq_flush(&softc->delete_queue, NULL, 0);
2219 /* Run regular command. */
2220 bp = bioq_takefirst(&softc->bio_queue);
2224 scsi_test_unit_ready(&start_ccb->csio,
2225 /*retries*/ da_retry_count,
2229 da_default_timeout * 1000);
2230 start_ccb->ccb_h.ccb_bp = NULL;
2231 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2232 xpt_action(start_ccb);
2234 xpt_release_ccb(start_ccb);
2239 cam_periph_release_locked(periph);
2242 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2243 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2244 softc->flags &= ~DA_FLAG_NEED_OTAG;
2245 softc->flags |= DA_FLAG_WAS_OTAG;
2246 tag_code = MSG_ORDERED_Q_TAG;
2248 tag_code = MSG_SIMPLE_Q_TAG;
2251 switch (bp->bio_cmd) {
2253 softc->flags |= DA_FLAG_DIRTY;
2256 scsi_read_write(&start_ccb->csio,
2257 /*retries*/da_retry_count,
2259 /*tag_action*/tag_code,
2260 /*read_op*/(bp->bio_cmd == BIO_READ ?
2261 SCSI_RW_READ : SCSI_RW_WRITE) |
2262 ((bp->bio_flags & BIO_UNMAPPED) != 0 ?
2265 softc->minimum_cmd_size,
2266 /*lba*/bp->bio_pblkno,
2267 /*block_count*/bp->bio_bcount /
2268 softc->params.secsize,
2269 /*data_ptr*/ (bp->bio_flags &
2270 BIO_UNMAPPED) != 0 ? (void *)bp :
2272 /*dxfer_len*/ bp->bio_bcount,
2273 /*sense_len*/SSD_FULL_SIZE,
2274 da_default_timeout * 1000);
2278 * BIO_FLUSH doesn't currently communicate
2279 * range data, so we synchronize the cache
2280 * over the whole disk. We also force
2281 * ordered tag semantics the flush applies
2282 * to all previously queued I/O.
2284 scsi_synchronize_cache(&start_ccb->csio,
2291 da_default_timeout*1000);
2294 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
2295 start_ccb->ccb_h.flags |= CAM_UNLOCKED;
2298 LIST_INSERT_HEAD(&softc->pending_ccbs,
2299 &start_ccb->ccb_h, periph_links.le);
2301 /* We expect a unit attention from this device */
2302 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
2303 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
2304 softc->flags &= ~DA_FLAG_RETRY_UA;
2307 start_ccb->ccb_h.ccb_bp = bp;
2309 cam_periph_unlock(periph);
2310 xpt_action(start_ccb);
2311 cam_periph_lock(periph);
2314 /* May have more work to do, so ensure we stay scheduled */
2318 case DA_STATE_PROBE_RC:
2320 struct scsi_read_capacity_data *rcap;
2322 rcap = (struct scsi_read_capacity_data *)
2323 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
2325 printf("dastart: Couldn't malloc read_capacity data\n");
2326 /* da_free_periph??? */
2329 scsi_read_capacity(&start_ccb->csio,
2330 /*retries*/da_retry_count,
2336 start_ccb->ccb_h.ccb_bp = NULL;
2337 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
2338 xpt_action(start_ccb);
2341 case DA_STATE_PROBE_RC16:
2343 struct scsi_read_capacity_data_long *rcaplong;
2345 rcaplong = (struct scsi_read_capacity_data_long *)
2346 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
2347 if (rcaplong == NULL) {
2348 printf("dastart: Couldn't malloc read_capacity data\n");
2349 /* da_free_periph??? */
2352 scsi_read_capacity_16(&start_ccb->csio,
2353 /*retries*/ da_retry_count,
2355 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2359 /*rcap_buf*/ (uint8_t *)rcaplong,
2360 /*rcap_buf_len*/ sizeof(*rcaplong),
2361 /*sense_len*/ SSD_FULL_SIZE,
2362 /*timeout*/ da_default_timeout * 1000);
2363 start_ccb->ccb_h.ccb_bp = NULL;
2364 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
2365 xpt_action(start_ccb);
2368 case DA_STATE_PROBE_LBP:
2370 struct scsi_vpd_logical_block_prov *lbp;
2372 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
2374 * If we get here we don't support any SBC-3 delete
2375 * methods with UNMAP as the Logical Block Provisioning
2376 * VPD page support is required for devices which
2377 * support it according to T10/1799-D Revision 31
2378 * however older revisions of the spec don't mandate
2379 * this so we currently don't remove these methods
2380 * from the available set.
2382 softc->state = DA_STATE_PROBE_BLK_LIMITS;
2386 lbp = (struct scsi_vpd_logical_block_prov *)
2387 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
2390 printf("dastart: Couldn't malloc lbp data\n");
2391 /* da_free_periph??? */
2395 scsi_inquiry(&start_ccb->csio,
2396 /*retries*/da_retry_count,
2398 /*tag_action*/MSG_SIMPLE_Q_TAG,
2399 /*inq_buf*/(u_int8_t *)lbp,
2400 /*inq_len*/sizeof(*lbp),
2402 /*page_code*/SVPD_LBP,
2403 /*sense_len*/SSD_MIN_SIZE,
2404 /*timeout*/da_default_timeout * 1000);
2405 start_ccb->ccb_h.ccb_bp = NULL;
2406 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
2407 xpt_action(start_ccb);
2410 case DA_STATE_PROBE_BLK_LIMITS:
2412 struct scsi_vpd_block_limits *block_limits;
2414 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
2415 /* Not supported skip to next probe */
2416 softc->state = DA_STATE_PROBE_BDC;
2420 block_limits = (struct scsi_vpd_block_limits *)
2421 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
2423 if (block_limits == NULL) {
2424 printf("dastart: Couldn't malloc block_limits data\n");
2425 /* da_free_periph??? */
2429 scsi_inquiry(&start_ccb->csio,
2430 /*retries*/da_retry_count,
2432 /*tag_action*/MSG_SIMPLE_Q_TAG,
2433 /*inq_buf*/(u_int8_t *)block_limits,
2434 /*inq_len*/sizeof(*block_limits),
2436 /*page_code*/SVPD_BLOCK_LIMITS,
2437 /*sense_len*/SSD_MIN_SIZE,
2438 /*timeout*/da_default_timeout * 1000);
2439 start_ccb->ccb_h.ccb_bp = NULL;
2440 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
2441 xpt_action(start_ccb);
2444 case DA_STATE_PROBE_BDC:
2446 struct scsi_vpd_block_characteristics *bdc;
2448 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
2449 softc->state = DA_STATE_PROBE_ATA;
2453 bdc = (struct scsi_vpd_block_characteristics *)
2454 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
2457 printf("dastart: Couldn't malloc bdc data\n");
2458 /* da_free_periph??? */
2462 scsi_inquiry(&start_ccb->csio,
2463 /*retries*/da_retry_count,
2465 /*tag_action*/MSG_SIMPLE_Q_TAG,
2466 /*inq_buf*/(u_int8_t *)bdc,
2467 /*inq_len*/sizeof(*bdc),
2469 /*page_code*/SVPD_BDC,
2470 /*sense_len*/SSD_MIN_SIZE,
2471 /*timeout*/da_default_timeout * 1000);
2472 start_ccb->ccb_h.ccb_bp = NULL;
2473 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
2474 xpt_action(start_ccb);
2477 case DA_STATE_PROBE_ATA:
2479 struct ata_params *ata_params;
2481 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2482 daprobedone(periph, start_ccb);
2486 ata_params = (struct ata_params*)
2487 malloc(sizeof(*ata_params), M_SCSIDA, M_NOWAIT|M_ZERO);
2489 if (ata_params == NULL) {
2490 printf("dastart: Couldn't malloc ata_params data\n");
2491 /* da_free_periph??? */
2495 scsi_ata_identify(&start_ccb->csio,
2496 /*retries*/da_retry_count,
2498 /*tag_action*/MSG_SIMPLE_Q_TAG,
2499 /*data_ptr*/(u_int8_t *)ata_params,
2500 /*dxfer_len*/sizeof(*ata_params),
2501 /*sense_len*/SSD_FULL_SIZE,
2502 /*timeout*/da_default_timeout * 1000);
2503 start_ccb->ccb_h.ccb_bp = NULL;
2504 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
2505 xpt_action(start_ccb);
2512 * In each of the methods below, while its the caller's
2513 * responsibility to ensure the request will fit into a
2514 * single device request, we might have changed the delete
2515 * method due to the device incorrectly advertising either
2516 * its supported methods or limits.
2518 * To prevent this causing further issues we validate the
2519 * against the methods limits, and warn which would
2520 * otherwise be unnecessary.
2523 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2525 struct da_softc *softc = (struct da_softc *)periph->softc;;
2527 uint8_t *buf = softc->unmap_buf;
2528 uint64_t lba, lastlba = (uint64_t)-1;
2529 uint64_t totalcount = 0;
2531 uint32_t lastcount = 0, c;
2532 uint32_t off, ranges = 0;
2535 * Currently this doesn't take the UNMAP
2536 * Granularity and Granularity Alignment
2537 * fields into account.
2539 * This could result in both unoptimal unmap
2540 * requests as as well as UNMAP calls unmapping
2541 * fewer LBA's than requested.
2544 softc->delete_running = 1;
2545 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2548 bioq_remove(&softc->delete_queue, bp1);
2550 bioq_insert_tail(&softc->delete_run_queue, bp1);
2551 lba = bp1->bio_pblkno;
2552 count = bp1->bio_bcount / softc->params.secsize;
2554 /* Try to extend the previous range. */
2555 if (lba == lastlba) {
2556 c = omin(count, UNMAP_RANGE_MAX - lastcount);
2558 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
2560 scsi_ulto4b(lastcount, &buf[off + 8]);
2567 c = omin(count, UNMAP_RANGE_MAX);
2568 if (totalcount + c > softc->unmap_max_lba ||
2569 ranges >= softc->unmap_max_ranges) {
2570 xpt_print(periph->path,
2571 "%s issuing short delete %ld > %ld"
2573 da_delete_method_desc[softc->delete_method],
2574 totalcount + c, softc->unmap_max_lba,
2575 ranges, softc->unmap_max_ranges);
2578 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
2579 scsi_u64to8b(lba, &buf[off + 0]);
2580 scsi_ulto4b(c, &buf[off + 8]);
2588 bp1 = bioq_first(&softc->delete_queue);
2589 if (bp1 == NULL || ranges >= softc->unmap_max_ranges ||
2590 totalcount + bp1->bio_bcount /
2591 softc->params.secsize > softc->unmap_max_lba)
2594 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
2595 scsi_ulto2b(ranges * 16, &buf[2]);
2597 scsi_unmap(&ccb->csio,
2598 /*retries*/da_retry_count,
2600 /*tag_action*/MSG_SIMPLE_Q_TAG,
2603 /*dxfer_len*/ ranges * 16 + 8,
2604 /*sense_len*/SSD_FULL_SIZE,
2605 da_default_timeout * 1000);
2606 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2607 ccb->ccb_h.flags |= CAM_UNLOCKED;
2611 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2613 struct da_softc *softc = (struct da_softc *)periph->softc;
2615 uint8_t *buf = softc->unmap_buf;
2616 uint64_t lastlba = (uint64_t)-1;
2619 uint32_t lastcount = 0, c, requestcount;
2620 int ranges = 0, off, block_count;
2622 softc->delete_running = 1;
2623 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2626 bioq_remove(&softc->delete_queue, bp1);
2628 bioq_insert_tail(&softc->delete_run_queue, bp1);
2629 lba = bp1->bio_pblkno;
2630 count = bp1->bio_bcount / softc->params.secsize;
2631 requestcount = count;
2633 /* Try to extend the previous range. */
2634 if (lba == lastlba) {
2635 c = min(count, ATA_DSM_RANGE_MAX - lastcount);
2637 off = (ranges - 1) * 8;
2638 buf[off + 6] = lastcount & 0xff;
2639 buf[off + 7] = (lastcount >> 8) & 0xff;
2645 c = min(count, ATA_DSM_RANGE_MAX);
2648 buf[off + 0] = lba & 0xff;
2649 buf[off + 1] = (lba >> 8) & 0xff;
2650 buf[off + 2] = (lba >> 16) & 0xff;
2651 buf[off + 3] = (lba >> 24) & 0xff;
2652 buf[off + 4] = (lba >> 32) & 0xff;
2653 buf[off + 5] = (lba >> 40) & 0xff;
2654 buf[off + 6] = c & 0xff;
2655 buf[off + 7] = (c >> 8) & 0xff;
2660 if (count != 0 && ranges == softc->trim_max_ranges) {
2661 xpt_print(periph->path,
2662 "%s issuing short delete %ld > %ld\n",
2663 da_delete_method_desc[softc->delete_method],
2665 (softc->trim_max_ranges - ranges) *
2671 bp1 = bioq_first(&softc->delete_queue);
2672 if (bp1 == NULL || bp1->bio_bcount / softc->params.secsize >
2673 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX)
2677 block_count = (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES;
2678 scsi_ata_trim(&ccb->csio,
2679 /*retries*/da_retry_count,
2681 /*tag_action*/MSG_SIMPLE_Q_TAG,
2684 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
2685 /*sense_len*/SSD_FULL_SIZE,
2686 da_default_timeout * 1000);
2687 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2688 ccb->ccb_h.flags |= CAM_UNLOCKED;
2692 * We calculate ws_max_blks here based off d_delmaxsize instead
2693 * of using softc->ws_max_blks as it is absolute max for the
2694 * device not the protocol max which may well be lower.
2697 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2699 struct da_softc *softc;
2701 uint64_t ws_max_blks;
2703 uint64_t count; /* forward compat with WS32 */
2705 softc = (struct da_softc *)periph->softc;
2706 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
2707 softc->delete_running = 1;
2708 lba = bp->bio_pblkno;
2712 bioq_remove(&softc->delete_queue, bp1);
2714 bioq_insert_tail(&softc->delete_run_queue, bp1);
2715 count += bp1->bio_bcount / softc->params.secsize;
2716 if (count > ws_max_blks) {
2717 xpt_print(periph->path,
2718 "%s issuing short delete %ld > %ld\n",
2719 da_delete_method_desc[softc->delete_method],
2720 count, ws_max_blks);
2721 count = min(count, ws_max_blks);
2724 bp1 = bioq_first(&softc->delete_queue);
2725 if (bp1 == NULL || lba + count != bp1->bio_pblkno ||
2726 count + bp1->bio_bcount /
2727 softc->params.secsize > ws_max_blks)
2731 scsi_write_same(&ccb->csio,
2732 /*retries*/da_retry_count,
2734 /*tag_action*/MSG_SIMPLE_Q_TAG,
2735 /*byte2*/softc->delete_method ==
2736 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
2737 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
2739 /*block_count*/count,
2740 /*data_ptr*/ __DECONST(void *, zero_region),
2741 /*dxfer_len*/ softc->params.secsize,
2742 /*sense_len*/SSD_FULL_SIZE,
2743 da_default_timeout * 1000);
2744 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2745 ccb->ccb_h.flags |= CAM_UNLOCKED;
2749 cmd6workaround(union ccb *ccb)
2751 struct scsi_rw_6 cmd6;
2752 struct scsi_rw_10 *cmd10;
2753 struct da_softc *softc;
2758 cdb = ccb->csio.cdb_io.cdb_bytes;
2759 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
2761 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
2762 da_delete_methods old_method = softc->delete_method;
2765 * Typically there are two reasons for failure here
2766 * 1. Delete method was detected as supported but isn't
2767 * 2. Delete failed due to invalid params e.g. too big
2769 * While we will attempt to choose an alternative delete method
2770 * this may result in short deletes if the existing delete
2771 * requests from geom are big for the new method choosen.
2773 * This method assumes that the error which triggered this
2774 * will not retry the io otherwise a panic will occur
2776 dadeleteflag(softc, old_method, 0);
2777 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
2778 if (softc->delete_method == DA_DELETE_DISABLE)
2779 xpt_print(ccb->ccb_h.path,
2780 "%s failed, disabling BIO_DELETE\n",
2781 da_delete_method_desc[old_method]);
2783 xpt_print(ccb->ccb_h.path,
2784 "%s failed, switching to %s BIO_DELETE\n",
2785 da_delete_method_desc[old_method],
2786 da_delete_method_desc[softc->delete_method]);
2789 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2791 bioq_disksort(&softc->delete_queue, bp);
2793 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2795 bioq_insert_tail(&softc->delete_queue, bp);
2797 bioq_insert_tail(&softc->delete_queue,
2798 (struct bio *)ccb->ccb_h.ccb_bp);
2799 ccb->ccb_h.ccb_bp = NULL;
2803 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
2804 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2805 (*cdb == PREVENT_ALLOW) &&
2806 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
2808 xpt_print(ccb->ccb_h.path,
2809 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
2810 softc->quirks |= DA_Q_NO_PREVENT;
2814 /* Detect unsupported SYNCHRONIZE CACHE(10). */
2815 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2816 (*cdb == SYNCHRONIZE_CACHE) &&
2817 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
2819 xpt_print(ccb->ccb_h.path,
2820 "SYNCHRONIZE CACHE(10) not supported.\n");
2821 softc->quirks |= DA_Q_NO_SYNC_CACHE;
2822 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
2826 /* Translation only possible if CDB is an array and cmd is R/W6 */
2827 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
2828 (*cdb != READ_6 && *cdb != WRITE_6))
2831 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
2832 "increasing minimum_cmd_size to 10.\n");
2833 softc->minimum_cmd_size = 10;
2835 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
2836 cmd10 = (struct scsi_rw_10 *)cdb;
2837 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
2839 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
2840 cmd10->reserved = 0;
2841 scsi_ulto2b(cmd6.length, cmd10->length);
2842 cmd10->control = cmd6.control;
2843 ccb->csio.cdb_len = sizeof(*cmd10);
2845 /* Requeue request, unfreezing queue if necessary */
2846 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
2847 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2850 cam_release_devq(ccb->ccb_h.path,
2854 /*getcount_only*/0);
2860 dadone(struct cam_periph *periph, union ccb *done_ccb)
2862 struct da_softc *softc;
2863 struct ccb_scsiio *csio;
2867 softc = (struct da_softc *)periph->softc;
2868 priority = done_ccb->ccb_h.pinfo.priority;
2870 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
2872 csio = &done_ccb->csio;
2873 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
2875 case DA_CCB_BUFFER_IO:
2878 struct bio *bp, *bp1;
2880 cam_periph_lock(periph);
2881 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2882 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2886 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
2891 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
2892 if (error == ERESTART) {
2894 * A retry was scheduled, so
2897 cam_periph_unlock(periph);
2900 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2905 * return all queued I/O with EIO, so that
2906 * the client can retry these I/Os in the
2907 * proper order should it attempt to recover.
2912 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
2914 * Catastrophic error. Mark our pack as
2918 * XXX See if this is really a media
2921 xpt_print(periph->path,
2922 "Invalidating pack\n");
2923 softc->flags |= DA_FLAG_PACK_INVALID;
2924 queued_error = ENXIO;
2926 bioq_flush(&softc->bio_queue, NULL,
2929 bp->bio_error = error;
2930 bp->bio_resid = bp->bio_bcount;
2931 bp->bio_flags |= BIO_ERROR;
2933 } else if (bp != NULL) {
2934 if (state == DA_CCB_DELETE)
2937 bp->bio_resid = csio->resid;
2939 if (bp->bio_resid != 0)
2940 bp->bio_flags |= BIO_ERROR;
2942 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2943 cam_release_devq(done_ccb->ccb_h.path,
2947 /*getcount_only*/0);
2948 } else if (bp != NULL) {
2949 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2950 panic("REQ_CMP with QFRZN");
2951 if (state == DA_CCB_DELETE)
2954 bp->bio_resid = csio->resid;
2955 if (csio->resid > 0)
2956 bp->bio_flags |= BIO_ERROR;
2957 if (softc->error_inject != 0) {
2958 bp->bio_error = softc->error_inject;
2959 bp->bio_resid = bp->bio_bcount;
2960 bp->bio_flags |= BIO_ERROR;
2961 softc->error_inject = 0;
2965 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
2966 if (LIST_EMPTY(&softc->pending_ccbs))
2967 softc->flags |= DA_FLAG_WAS_OTAG;
2969 xpt_release_ccb(done_ccb);
2970 if (state == DA_CCB_DELETE) {
2971 TAILQ_HEAD(, bio) queue;
2974 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue);
2975 softc->delete_run_queue.insert_point = NULL;
2976 softc->delete_running = 0;
2978 cam_periph_unlock(periph);
2979 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) {
2980 TAILQ_REMOVE(&queue, bp1, bio_queue);
2981 bp1->bio_error = bp->bio_error;
2982 if (bp->bio_flags & BIO_ERROR) {
2983 bp1->bio_flags |= BIO_ERROR;
2984 bp1->bio_resid = bp1->bio_bcount;
2990 cam_periph_unlock(periph);
2995 case DA_CCB_PROBE_RC:
2996 case DA_CCB_PROBE_RC16:
2998 struct scsi_read_capacity_data *rdcap;
2999 struct scsi_read_capacity_data_long *rcaplong;
3000 char announce_buf[80];
3006 if (state == DA_CCB_PROBE_RC)
3007 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
3009 rcaplong = (struct scsi_read_capacity_data_long *)
3012 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3013 struct disk_params *dp;
3014 uint32_t block_size;
3016 u_int lbppbe; /* LB per physical block exponent. */
3017 u_int lalba; /* Lowest aligned LBA. */
3019 if (state == DA_CCB_PROBE_RC) {
3020 block_size = scsi_4btoul(rdcap->length);
3021 maxsector = scsi_4btoul(rdcap->addr);
3026 * According to SBC-2, if the standard 10
3027 * byte READ CAPACITY command returns 2^32,
3028 * we should issue the 16 byte version of
3029 * the command, since the device in question
3030 * has more sectors than can be represented
3031 * with the short version of the command.
3033 if (maxsector == 0xffffffff) {
3034 free(rdcap, M_SCSIDA);
3035 xpt_release_ccb(done_ccb);
3036 softc->state = DA_STATE_PROBE_RC16;
3037 xpt_schedule(periph, priority);
3041 block_size = scsi_4btoul(rcaplong->length);
3042 maxsector = scsi_8btou64(rcaplong->addr);
3043 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3044 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3048 * Because GEOM code just will panic us if we
3049 * give them an 'illegal' value we'll avoid that
3052 if (block_size == 0 && maxsector == 0) {
3056 if (block_size >= MAXPHYS || block_size == 0) {
3057 xpt_print(periph->path,
3058 "unsupportable block size %ju\n",
3059 (uintmax_t) block_size);
3060 announce_buf[0] = '\0';
3061 cam_periph_invalidate(periph);
3064 * We pass rcaplong into dasetgeom(),
3065 * because it will only use it if it is
3068 dasetgeom(periph, block_size, maxsector,
3069 rcaplong, sizeof(*rcaplong));
3070 lbp = (lalba & SRC16_LBPME_A);
3071 dp = &softc->params;
3072 snprintf(announce_buf, sizeof(announce_buf),
3073 "%juMB (%ju %u byte sectors: %dH %dS/T "
3075 (((uintmax_t)dp->secsize *
3076 dp->sectors) / (1024*1024)),
3077 (uintmax_t)dp->sectors,
3078 dp->secsize, dp->heads,
3079 dp->secs_per_track, dp->cylinders);
3084 announce_buf[0] = '\0';
3087 * Retry any UNIT ATTENTION type errors. They
3088 * are expected at boot.
3090 error = daerror(done_ccb, CAM_RETRY_SELTO,
3091 SF_RETRY_UA|SF_NO_PRINT);
3092 if (error == ERESTART) {
3094 * A retry was scheuled, so
3098 } else if (error != 0) {
3100 int sense_key, error_code;
3103 struct ccb_getdev cgd;
3105 /* Don't wedge this device's queue */
3106 status = done_ccb->ccb_h.status;
3107 if ((status & CAM_DEV_QFRZN) != 0)
3108 cam_release_devq(done_ccb->ccb_h.path,
3112 /*getcount_only*/0);
3115 xpt_setup_ccb(&cgd.ccb_h,
3116 done_ccb->ccb_h.path,
3117 CAM_PRIORITY_NORMAL);
3118 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3119 xpt_action((union ccb *)&cgd);
3121 if (scsi_extract_sense_ccb(done_ccb,
3122 &error_code, &sense_key, &asc, &ascq))
3128 * If we tried READ CAPACITY(16) and failed,
3129 * fallback to READ CAPACITY(10).
3131 if ((state == DA_CCB_PROBE_RC16) &&
3132 (softc->flags & DA_FLAG_CAN_RC16) &&
3133 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
3136 (error_code == SSD_CURRENT_ERROR) &&
3137 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
3138 softc->flags &= ~DA_FLAG_CAN_RC16;
3139 free(rdcap, M_SCSIDA);
3140 xpt_release_ccb(done_ccb);
3141 softc->state = DA_STATE_PROBE_RC;
3142 xpt_schedule(periph, priority);
3146 * Attach to anything that claims to be a
3147 * direct access or optical disk device,
3148 * as long as it doesn't return a "Logical
3149 * unit not supported" (0x25) error.
3151 if ((have_sense) && (asc != 0x25)
3152 && (error_code == SSD_CURRENT_ERROR)) {
3153 const char *sense_key_desc;
3154 const char *asc_desc;
3156 dasetgeom(periph, 512, -1, NULL, 0);
3157 scsi_sense_desc(sense_key, asc, ascq,
3161 snprintf(announce_buf,
3162 sizeof(announce_buf),
3163 "Attempt to query device "
3164 "size failed: %s, %s",
3172 xpt_print(periph->path,
3173 "got CAM status %#x\n",
3174 done_ccb->ccb_h.status);
3177 xpt_print(periph->path, "fatal error, "
3178 "failed to attach to device\n");
3181 * Free up resources.
3183 cam_periph_invalidate(periph);
3187 free(csio->data_ptr, M_SCSIDA);
3188 if (announce_buf[0] != '\0' && ((softc->flags & DA_FLAG_PROBED) == 0)) {
3190 * Create our sysctl variables, now that we know
3191 * we have successfully attached.
3193 /* increase the refcount */
3194 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3195 taskqueue_enqueue(taskqueue_thread,
3196 &softc->sysctl_task);
3197 xpt_announce_periph(periph, announce_buf);
3198 xpt_announce_quirks(periph, softc->quirks,
3201 xpt_print(periph->path, "fatal error, "
3202 "could not acquire reference count\n");
3206 /* Ensure re-probe doesn't see old delete. */
3207 softc->delete_available = 0;
3210 * Based on older SBC-3 spec revisions
3211 * any of the UNMAP methods "may" be
3212 * available via LBP given this flag so
3213 * we flag all of them as availble and
3214 * then remove those which further
3215 * probes confirm aren't available
3218 * We could also check readcap(16) p_type
3219 * flag to exclude one or more invalid
3220 * write same (X) types here
3222 dadeleteflag(softc, DA_DELETE_WS16, 1);
3223 dadeleteflag(softc, DA_DELETE_WS10, 1);
3224 dadeleteflag(softc, DA_DELETE_ZERO, 1);
3225 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
3227 xpt_release_ccb(done_ccb);
3228 softc->state = DA_STATE_PROBE_LBP;
3229 xpt_schedule(periph, priority);
3233 xpt_release_ccb(done_ccb);
3234 softc->state = DA_STATE_PROBE_BDC;
3235 xpt_schedule(periph, priority);
3238 case DA_CCB_PROBE_LBP:
3240 struct scsi_vpd_logical_block_prov *lbp;
3242 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
3244 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3246 * T10/1799-D Revision 31 states at least one of these
3247 * must be supported but we don't currently enforce this.
3249 dadeleteflag(softc, DA_DELETE_WS16,
3250 (lbp->flags & SVPD_LBP_WS16));
3251 dadeleteflag(softc, DA_DELETE_WS10,
3252 (lbp->flags & SVPD_LBP_WS10));
3253 dadeleteflag(softc, DA_DELETE_ZERO,
3254 (lbp->flags & SVPD_LBP_WS10));
3255 dadeleteflag(softc, DA_DELETE_UNMAP,
3256 (lbp->flags & SVPD_LBP_UNMAP));
3258 if (lbp->flags & SVPD_LBP_UNMAP) {
3259 free(lbp, M_SCSIDA);
3260 xpt_release_ccb(done_ccb);
3261 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3262 xpt_schedule(periph, priority);
3267 error = daerror(done_ccb, CAM_RETRY_SELTO,
3268 SF_RETRY_UA|SF_NO_PRINT);
3269 if (error == ERESTART)
3271 else if (error != 0) {
3272 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3273 /* Don't wedge this device's queue */
3274 cam_release_devq(done_ccb->ccb_h.path,
3278 /*getcount_only*/0);
3282 * Failure indicates we don't support any SBC-3
3283 * delete methods with UNMAP
3288 free(lbp, M_SCSIDA);
3289 xpt_release_ccb(done_ccb);
3290 softc->state = DA_STATE_PROBE_BDC;
3291 xpt_schedule(periph, priority);
3294 case DA_CCB_PROBE_BLK_LIMITS:
3296 struct scsi_vpd_block_limits *block_limits;
3298 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
3300 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3301 uint32_t max_unmap_lba_cnt = scsi_4btoul(
3302 block_limits->max_unmap_lba_cnt);
3303 uint32_t max_unmap_blk_cnt = scsi_4btoul(
3304 block_limits->max_unmap_blk_cnt);
3305 uint64_t ws_max_blks = scsi_8btou64(
3306 block_limits->max_write_same_length);
3308 * We should already support UNMAP but we check lba
3309 * and block count to be sure
3311 if (max_unmap_lba_cnt != 0x00L &&
3312 max_unmap_blk_cnt != 0x00L) {
3313 softc->unmap_max_lba = max_unmap_lba_cnt;
3314 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
3318 * Unexpected UNMAP limits which means the
3319 * device doesn't actually support UNMAP
3321 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
3324 if (ws_max_blks != 0x00L)
3325 softc->ws_max_blks = ws_max_blks;
3328 error = daerror(done_ccb, CAM_RETRY_SELTO,
3329 SF_RETRY_UA|SF_NO_PRINT);
3330 if (error == ERESTART)
3332 else if (error != 0) {
3333 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3334 /* Don't wedge this device's queue */
3335 cam_release_devq(done_ccb->ccb_h.path,
3339 /*getcount_only*/0);
3343 * Failure here doesn't mean UNMAP is not
3344 * supported as this is an optional page.
3346 softc->unmap_max_lba = 1;
3347 softc->unmap_max_ranges = 1;
3351 free(block_limits, M_SCSIDA);
3352 xpt_release_ccb(done_ccb);
3353 softc->state = DA_STATE_PROBE_BDC;
3354 xpt_schedule(periph, priority);
3357 case DA_CCB_PROBE_BDC:
3359 struct scsi_vpd_block_characteristics *bdc;
3361 bdc = (struct scsi_vpd_block_characteristics *)csio->data_ptr;
3363 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3365 * Disable queue sorting for non-rotational media
3368 u_int16_t old_rate = softc->disk->d_rotation_rate;
3370 softc->disk->d_rotation_rate =
3371 scsi_2btoul(bdc->medium_rotation_rate);
3372 if (softc->disk->d_rotation_rate ==
3373 SVPD_BDC_RATE_NON_ROTATING) {
3374 softc->sort_io_queue = 0;
3376 if (softc->disk->d_rotation_rate != old_rate) {
3377 disk_attr_changed(softc->disk,
3378 "GEOM::rotation_rate", M_NOWAIT);
3382 error = daerror(done_ccb, CAM_RETRY_SELTO,
3383 SF_RETRY_UA|SF_NO_PRINT);
3384 if (error == ERESTART)
3386 else if (error != 0) {
3387 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3388 /* Don't wedge this device's queue */
3389 cam_release_devq(done_ccb->ccb_h.path,
3393 /*getcount_only*/0);
3398 free(bdc, M_SCSIDA);
3399 xpt_release_ccb(done_ccb);
3400 softc->state = DA_STATE_PROBE_ATA;
3401 xpt_schedule(periph, priority);
3404 case DA_CCB_PROBE_ATA:
3407 struct ata_params *ata_params;
3410 ata_params = (struct ata_params *)csio->data_ptr;
3411 ptr = (uint16_t *)ata_params;
3413 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3416 for (i = 0; i < sizeof(*ata_params) / 2; i++)
3417 ptr[i] = le16toh(ptr[i]);
3418 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM) {
3419 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
3420 if (ata_params->max_dsm_blocks != 0)
3421 softc->trim_max_ranges = min(
3422 softc->trim_max_ranges,
3423 ata_params->max_dsm_blocks *
3424 ATA_DSM_BLK_RANGES);
3427 * Disable queue sorting for non-rotational media
3430 old_rate = softc->disk->d_rotation_rate;
3431 softc->disk->d_rotation_rate =
3432 ata_params->media_rotation_rate;
3433 if (softc->disk->d_rotation_rate ==
3434 ATA_RATE_NON_ROTATING) {
3435 softc->sort_io_queue = 0;
3438 if (softc->disk->d_rotation_rate != old_rate) {
3439 disk_attr_changed(softc->disk,
3440 "GEOM::rotation_rate", M_NOWAIT);
3444 error = daerror(done_ccb, CAM_RETRY_SELTO,
3445 SF_RETRY_UA|SF_NO_PRINT);
3446 if (error == ERESTART)
3448 else if (error != 0) {
3449 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3450 /* Don't wedge this device's queue */
3451 cam_release_devq(done_ccb->ccb_h.path,
3455 /*getcount_only*/0);
3460 free(ata_params, M_SCSIDA);
3461 daprobedone(periph, done_ccb);
3465 /* No-op. We're polling */
3469 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3471 if (daerror(done_ccb, CAM_RETRY_SELTO,
3472 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
3475 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
3476 cam_release_devq(done_ccb->ccb_h.path,
3480 /*getcount_only*/0);
3482 xpt_release_ccb(done_ccb);
3483 cam_periph_release_locked(periph);
3489 xpt_release_ccb(done_ccb);
3493 dareprobe(struct cam_periph *periph)
3495 struct da_softc *softc;
3498 softc = (struct da_softc *)periph->softc;
3500 /* Probe in progress; don't interfere. */
3501 if (softc->state != DA_STATE_NORMAL)
3504 status = cam_periph_acquire(periph);
3505 KASSERT(status == CAM_REQ_CMP,
3506 ("dareprobe: cam_periph_acquire failed"));
3508 if (softc->flags & DA_FLAG_CAN_RC16)
3509 softc->state = DA_STATE_PROBE_RC16;
3511 softc->state = DA_STATE_PROBE_RC;
3513 xpt_schedule(periph, CAM_PRIORITY_DEV);
3517 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
3519 struct da_softc *softc;
3520 struct cam_periph *periph;
3521 int error, error_code, sense_key, asc, ascq;
3523 periph = xpt_path_periph(ccb->ccb_h.path);
3524 softc = (struct da_softc *)periph->softc;
3527 * Automatically detect devices that do not support
3528 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
3531 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
3532 error = cmd6workaround(ccb);
3533 } else if (scsi_extract_sense_ccb(ccb,
3534 &error_code, &sense_key, &asc, &ascq)) {
3535 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
3536 error = cmd6workaround(ccb);
3538 * If the target replied with CAPACITY DATA HAS CHANGED UA,
3539 * query the capacity and notify upper layers.
3541 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3542 asc == 0x2A && ascq == 0x09) {
3543 xpt_print(periph->path, "capacity data has changed\n");
3545 sense_flags |= SF_NO_PRINT;
3546 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3547 asc == 0x28 && ascq == 0x00)
3548 disk_media_changed(softc->disk, M_NOWAIT);
3549 else if (sense_key == SSD_KEY_NOT_READY &&
3550 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
3551 softc->flags |= DA_FLAG_PACK_INVALID;
3552 disk_media_gone(softc->disk, M_NOWAIT);
3555 if (error == ERESTART)
3560 * Until we have a better way of doing pack validation,
3561 * don't treat UAs as errors.
3563 sense_flags |= SF_RETRY_UA;
3564 return(cam_periph_error(ccb, cam_flags, sense_flags,
3565 &softc->saved_ccb));
3569 damediapoll(void *arg)
3571 struct cam_periph *periph = arg;
3572 struct da_softc *softc = periph->softc;
3574 if (!softc->tur && LIST_EMPTY(&softc->pending_ccbs)) {
3575 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3580 /* Queue us up again */
3581 if (da_poll_period != 0)
3582 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
3586 daprevent(struct cam_periph *periph, int action)
3588 struct da_softc *softc;
3592 softc = (struct da_softc *)periph->softc;
3594 if (((action == PR_ALLOW)
3595 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
3596 || ((action == PR_PREVENT)
3597 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
3601 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3603 scsi_prevent(&ccb->csio,
3611 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
3612 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
3615 if (action == PR_ALLOW)
3616 softc->flags &= ~DA_FLAG_PACK_LOCKED;
3618 softc->flags |= DA_FLAG_PACK_LOCKED;
3621 xpt_release_ccb(ccb);
3625 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
3626 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
3628 struct ccb_calc_geometry ccg;
3629 struct da_softc *softc;
3630 struct disk_params *dp;
3631 u_int lbppbe, lalba;
3634 softc = (struct da_softc *)periph->softc;
3636 dp = &softc->params;
3637 dp->secsize = block_len;
3638 dp->sectors = maxsector + 1;
3639 if (rcaplong != NULL) {
3640 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3641 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3642 lalba &= SRC16_LALBA_A;
3649 dp->stripesize = block_len << lbppbe;
3650 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
3652 } else if (softc->quirks & DA_Q_4K) {
3653 dp->stripesize = 4096;
3654 dp->stripeoffset = 0;
3657 dp->stripeoffset = 0;
3660 * Have the controller provide us with a geometry
3661 * for this disk. The only time the geometry
3662 * matters is when we boot and the controller
3663 * is the only one knowledgeable enough to come
3664 * up with something that will make this a bootable
3667 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3668 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
3669 ccg.block_size = dp->secsize;
3670 ccg.volume_size = dp->sectors;
3672 ccg.secs_per_track = 0;
3674 xpt_action((union ccb*)&ccg);
3675 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3677 * We don't know what went wrong here- but just pick
3678 * a geometry so we don't have nasty things like divide
3682 dp->secs_per_track = 255;
3683 dp->cylinders = dp->sectors / (255 * 255);
3684 if (dp->cylinders == 0) {
3688 dp->heads = ccg.heads;
3689 dp->secs_per_track = ccg.secs_per_track;
3690 dp->cylinders = ccg.cylinders;
3694 * If the user supplied a read capacity buffer, and if it is
3695 * different than the previous buffer, update the data in the EDT.
3696 * If it's the same, we don't bother. This avoids sending an
3697 * update every time someone opens this device.
3699 if ((rcaplong != NULL)
3700 && (bcmp(rcaplong, &softc->rcaplong,
3701 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
3702 struct ccb_dev_advinfo cdai;
3704 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3705 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
3706 cdai.buftype = CDAI_TYPE_RCAPLONG;
3707 cdai.flags |= CDAI_FLAG_STORE;
3708 cdai.bufsiz = rcap_len;
3709 cdai.buf = (uint8_t *)rcaplong;
3710 xpt_action((union ccb *)&cdai);
3711 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
3712 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
3713 if (cdai.ccb_h.status != CAM_REQ_CMP) {
3714 xpt_print(periph->path, "%s: failed to set read "
3715 "capacity advinfo\n", __func__);
3716 /* Use cam_error_print() to decode the status */
3717 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
3720 bcopy(rcaplong, &softc->rcaplong,
3721 min(sizeof(softc->rcaplong), rcap_len));
3725 softc->disk->d_sectorsize = softc->params.secsize;
3726 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
3727 softc->disk->d_stripesize = softc->params.stripesize;
3728 softc->disk->d_stripeoffset = softc->params.stripeoffset;
3729 /* XXX: these are not actually "firmware" values, so they may be wrong */
3730 softc->disk->d_fwsectors = softc->params.secs_per_track;
3731 softc->disk->d_fwheads = softc->params.heads;
3732 softc->disk->d_devstat->block_size = softc->params.secsize;
3733 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
3735 error = disk_resize(softc->disk, M_NOWAIT);
3737 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error);
3741 dasendorderedtag(void *arg)
3743 struct da_softc *softc = arg;
3745 if (da_send_ordered) {
3746 if (!LIST_EMPTY(&softc->pending_ccbs)) {
3747 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
3748 softc->flags |= DA_FLAG_NEED_OTAG;
3749 softc->flags &= ~DA_FLAG_WAS_OTAG;
3752 /* Queue us up again */
3753 callout_reset(&softc->sendordered_c,
3754 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
3755 dasendorderedtag, softc);
3759 * Step through all DA peripheral drivers, and if the device is still open,
3760 * sync the disk cache to physical media.
3763 dashutdown(void * arg, int howto)
3765 struct cam_periph *periph;
3766 struct da_softc *softc;
3770 CAM_PERIPH_FOREACH(periph, &dadriver) {
3771 softc = (struct da_softc *)periph->softc;
3772 if (SCHEDULER_STOPPED()) {
3773 /* If we paniced with the lock held, do not recurse. */
3774 if (!cam_periph_owned(periph) &&
3775 (softc->flags & DA_FLAG_OPEN)) {
3776 dadump(softc->disk, NULL, 0, 0, 0);
3780 cam_periph_lock(periph);
3783 * We only sync the cache if the drive is still open, and
3784 * if the drive is capable of it..
3786 if (((softc->flags & DA_FLAG_OPEN) == 0)
3787 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
3788 cam_periph_unlock(periph);
3792 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3793 scsi_synchronize_cache(&ccb->csio,
3797 /*begin_lba*/0, /* whole disk */
3802 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
3803 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
3804 softc->disk->d_devstat);
3806 xpt_print(periph->path, "Synchronize cache failed\n");
3807 xpt_release_ccb(ccb);
3808 cam_periph_unlock(periph);
3812 #else /* !_KERNEL */
3815 * XXX This is only left out of the kernel build to silence warnings. If,
3816 * for some reason this function is used in the kernel, the ifdefs should
3817 * be moved so it is included both in the kernel and userland.
3820 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
3821 void (*cbfcnp)(struct cam_periph *, union ccb *),
3822 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
3823 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3826 struct scsi_format_unit *scsi_cmd;
3828 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
3829 scsi_cmd->opcode = FORMAT_UNIT;
3830 scsi_cmd->byte2 = byte2;
3831 scsi_ulto2b(ileave, scsi_cmd->interleave);
3836 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3846 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
3847 void (*cbfcnp)(struct cam_periph *, union ccb *),
3848 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
3849 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3852 struct scsi_sanitize *scsi_cmd;
3854 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
3855 scsi_cmd->opcode = SANITIZE;
3856 scsi_cmd->byte2 = byte2;
3857 scsi_cmd->control = control;
3858 scsi_ulto2b(dxfer_len, scsi_cmd->length);
3863 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3872 #endif /* _KERNEL */