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,
123 DA_CCB_WAITING = 0x08,
125 DA_CCB_DELETE = 0x0B,
127 DA_CCB_TYPE_MASK = 0x0F,
128 DA_CCB_RETRY_UA = 0x10
132 * Order here is important for method choice
134 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to
135 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes
136 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql
137 * import taking 5mins.
148 DA_DELETE_MIN = DA_DELETE_ATA_TRIM,
149 DA_DELETE_MAX = DA_DELETE_ZERO
152 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb,
154 static da_delete_func_t da_delete_trim;
155 static da_delete_func_t da_delete_unmap;
156 static da_delete_func_t da_delete_ws;
158 static const void * da_delete_functions[] = {
168 static const char *da_delete_method_names[] =
169 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" };
170 static const char *da_delete_method_desc[] =
171 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP",
172 "WRITE SAME(10) with UNMAP", "ZERO" };
174 /* Offsets into our private area for storing information */
175 #define ccb_state ppriv_field0
176 #define ccb_bp ppriv_ptr1
181 u_int8_t secs_per_track;
182 u_int32_t secsize; /* Number of bytes/sector */
183 u_int64_t sectors; /* total number sectors */
188 #define UNMAP_RANGE_MAX 0xffffffff
189 #define UNMAP_HEAD_SIZE 8
190 #define UNMAP_RANGE_SIZE 16
191 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */
192 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \
195 #define WS10_MAX_BLKS 0xffff
196 #define WS16_MAX_BLKS 0xffffffff
197 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \
198 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE)
201 struct bio_queue_head bio_queue;
202 struct bio_queue_head delete_queue;
203 struct bio_queue_head delete_run_queue;
204 LIST_HEAD(, ccb_hdr) pending_ccbs;
205 int tur; /* TEST UNIT READY should be sent */
206 int refcount; /* Active xpt_action() calls */
211 int minimum_cmd_size;
215 int delete_available; /* Delete methods possibly available */
217 uint32_t unmap_max_ranges;
218 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */
219 uint64_t ws_max_blks;
220 da_delete_methods delete_method;
221 da_delete_func_t *delete_func;
222 struct disk_params params;
225 struct task sysctl_task;
226 struct sysctl_ctx_list sysctl_ctx;
227 struct sysctl_oid *sysctl_tree;
228 struct callout sendordered_c;
230 uint8_t unmap_buf[UNMAP_BUF_SIZE];
231 struct scsi_read_capacity_data_long rcaplong;
232 struct callout mediapoll_c;
235 #define dadeleteflag(softc, delete_method, enable) \
237 softc->delete_available |= (1 << delete_method); \
239 softc->delete_available &= ~(1 << delete_method); \
242 struct da_quirk_entry {
243 struct scsi_inquiry_pattern inq_pat;
247 static const char quantum[] = "QUANTUM";
248 static const char microp[] = "MICROP";
250 static struct da_quirk_entry da_quirk_table[] =
252 /* SPI, FC devices */
255 * Fujitsu M2513A MO drives.
256 * Tested devices: M2513A2 firmware versions 1200 & 1300.
257 * (dip switch selects whether T_DIRECT or T_OPTICAL device)
258 * Reported by: W.Scholten <whs@xs4all.nl>
260 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
261 /*quirks*/ DA_Q_NO_SYNC_CACHE
265 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"},
266 /*quirks*/ DA_Q_NO_SYNC_CACHE
270 * This particular Fujitsu drive doesn't like the
271 * synchronize cache command.
272 * Reported by: Tom Jackson <toj@gorilla.net>
274 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"},
275 /*quirks*/ DA_Q_NO_SYNC_CACHE
279 * This drive doesn't like the synchronize cache command
280 * either. Reported by: Matthew Jacob <mjacob@feral.com>
281 * in NetBSD PR kern/6027, August 24, 1998.
283 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"},
284 /*quirks*/ DA_Q_NO_SYNC_CACHE
288 * This drive doesn't like the synchronize cache command
289 * either. Reported by: Hellmuth Michaelis (hm@kts.org)
292 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"},
293 /*quirks*/ DA_Q_NO_SYNC_CACHE
297 * Doesn't like the synchronize cache command.
298 * Reported by: Blaz Zupan <blaz@gold.amis.net>
300 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"},
301 /*quirks*/ DA_Q_NO_SYNC_CACHE
305 * Doesn't like the synchronize cache command.
306 * Reported by: Blaz Zupan <blaz@gold.amis.net>
308 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"},
309 /*quirks*/ DA_Q_NO_SYNC_CACHE
313 * Doesn't like the synchronize cache command.
315 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"},
316 /*quirks*/ DA_Q_NO_SYNC_CACHE
320 * Doesn't like the synchronize cache command.
321 * Reported by: walter@pelissero.de
323 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"},
324 /*quirks*/ DA_Q_NO_SYNC_CACHE
328 * Doesn't work correctly with 6 byte reads/writes.
329 * Returns illegal request, and points to byte 9 of the
331 * Reported by: Adam McDougall <bsdx@spawnet.com>
333 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"},
334 /*quirks*/ DA_Q_NO_6_BYTE
338 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"},
339 /*quirks*/ DA_Q_NO_6_BYTE
343 * Doesn't like the synchronize cache command.
344 * Reported by: walter@pelissero.de
346 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"},
347 /*quirks*/ DA_Q_NO_SYNC_CACHE
351 * The CISS RAID controllers do not support SYNC_CACHE
353 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"},
354 /*quirks*/ DA_Q_NO_SYNC_CACHE
358 * The STEC SSDs sometimes hang on UNMAP.
360 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"},
361 /*quirks*/ DA_Q_NO_UNMAP
363 /* USB mass storage devices supported by umass(4) */
366 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player
369 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"},
370 /*quirks*/ DA_Q_NO_SYNC_CACHE
374 * Power Quotient Int. (PQI) USB flash key
377 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*",
378 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
382 * Creative Nomad MUVO mp3 player (USB)
385 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"},
386 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
390 * Jungsoft NEXDISK USB flash key
393 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"},
394 /*quirks*/ DA_Q_NO_SYNC_CACHE
398 * FreeDik USB Mini Data Drive
401 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive",
402 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
406 * Sigmatel USB Flash MP3 Player
409 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"},
410 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
414 * Neuros USB Digital Audio Computer
417 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.",
418 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
422 * SEAGRAND NP-900 MP3 Player
425 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"},
426 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
430 * iRiver iFP MP3 player (with UMS Firmware)
431 * PR: kern/54881, i386/63941, kern/66124
433 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"},
434 /*quirks*/ DA_Q_NO_SYNC_CACHE
438 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01
441 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"},
442 /*quirks*/ DA_Q_NO_SYNC_CACHE
446 * ZICPlay USB MP3 Player with FM
449 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"},
450 /*quirks*/ DA_Q_NO_SYNC_CACHE
454 * TEAC USB floppy mechanisms
456 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"},
457 /*quirks*/ DA_Q_NO_SYNC_CACHE
461 * Kingston DataTraveler II+ USB Pen-Drive.
462 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org>
464 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+",
465 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
473 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"},
474 /*quirks*/ DA_Q_NO_SYNC_CACHE
478 * Motorola E398 Mobile Phone (TransFlash memory card).
479 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl>
482 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone",
483 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
487 * Qware BeatZkey! Pro
490 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE",
491 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
495 * Time DPA20B 1GB MP3 Player
498 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*",
499 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
503 * Samsung USB key 128Mb
506 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb",
507 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
511 * Kingston DataTraveler 2.0 USB Flash memory.
514 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0",
515 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
519 * Creative MUVO Slim mp3 player (USB)
522 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim",
523 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT
527 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3)
530 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK",
531 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
535 * SanDisk Micro Cruzer 128MB
538 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer",
539 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
543 * TOSHIBA TransMemory USB sticks
546 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory",
547 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
552 * PR: usb/75578, usb/72344, usb/65436
554 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*",
555 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
559 * Genesys 6-in-1 Card Reader
562 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*",
563 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
567 * Rekam Digital CAMERA
570 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*",
571 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
575 * iRiver H10 MP3 player
578 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*",
579 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
583 * iRiver U10 MP3 player
586 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*",
587 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
594 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk",
595 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
599 * EasyMP3 EM732X USB 2.0 Flash MP3 Player
602 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*",
603 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
610 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER",
611 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
615 * Philips USB Key Audio KEY013
618 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"},
619 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
626 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*",
627 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
634 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"},
635 /*quirks*/ DA_Q_NO_SYNC_CACHE
639 * I/O Magic USB flash - Giga Bank
642 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"},
643 /*quirks*/ DA_Q_NO_SYNC_CACHE
647 * JoyFly 128mb USB Flash Drive
650 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*",
651 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
658 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*",
659 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
663 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A
666 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*",
667 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
671 * Samsung YP-U3 mp3-player
674 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3",
675 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
678 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*",
679 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
683 * Sony Cyber-Shot DSC cameras
686 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"},
687 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT
690 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3",
691 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT
694 /* At least several Transcent USB sticks lie on RC16. */
695 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*",
696 "*"}, /*quirks*/ DA_Q_NO_RC16
698 /* ATA/SATA devices over SAS/USB/... */
700 /* Hitachi Advanced Format (4k) drives */
701 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" },
705 /* Samsung Advanced Format (4k) drives */
706 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" },
710 /* Samsung Advanced Format (4k) drives */
711 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" },
715 /* Samsung Advanced Format (4k) drives */
716 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" },
720 /* Samsung Advanced Format (4k) drives */
721 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" },
725 /* Seagate Barracuda Green Advanced Format (4k) drives */
726 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" },
730 /* Seagate Barracuda Green Advanced Format (4k) drives */
731 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" },
735 /* Seagate Barracuda Green Advanced Format (4k) drives */
736 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" },
740 /* Seagate Barracuda Green Advanced Format (4k) drives */
741 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" },
745 /* Seagate Barracuda Green Advanced Format (4k) drives */
746 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" },
750 /* Seagate Barracuda Green Advanced Format (4k) drives */
751 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" },
755 /* Seagate Momentus Advanced Format (4k) drives */
756 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" },
760 /* Seagate Momentus Advanced Format (4k) drives */
761 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" },
765 /* Seagate Momentus Advanced Format (4k) drives */
766 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" },
770 /* Seagate Momentus Advanced Format (4k) drives */
771 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" },
775 /* Seagate Momentus Advanced Format (4k) drives */
776 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" },
780 /* Seagate Momentus Advanced Format (4k) drives */
781 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" },
785 /* Seagate Momentus Advanced Format (4k) drives */
786 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" },
790 /* Seagate Momentus Advanced Format (4k) drives */
791 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" },
795 /* Seagate Momentus Advanced Format (4k) drives */
796 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" },
800 /* Seagate Momentus Advanced Format (4k) drives */
801 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" },
805 /* Seagate Momentus Advanced Format (4k) drives */
806 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" },
810 /* Seagate Momentus Advanced Format (4k) drives */
811 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" },
815 /* Seagate Momentus Advanced Format (4k) drives */
816 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" },
820 /* Seagate Momentus Advanced Format (4k) drives */
821 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" },
825 /* Seagate Momentus Thin Advanced Format (4k) drives */
826 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" },
830 /* Seagate Momentus Thin Advanced Format (4k) drives */
831 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" },
835 /* WDC Caviar Green Advanced Format (4k) drives */
836 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" },
840 /* WDC Caviar Green Advanced Format (4k) drives */
841 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" },
845 /* WDC Caviar Green Advanced Format (4k) drives */
846 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" },
850 /* WDC Caviar Green Advanced Format (4k) drives */
851 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" },
855 /* WDC Caviar Green Advanced Format (4k) drives */
856 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" },
860 /* WDC Caviar Green Advanced Format (4k) drives */
861 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" },
865 /* WDC Caviar Green Advanced Format (4k) drives */
866 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" },
870 /* WDC Caviar Green Advanced Format (4k) drives */
871 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" },
875 /* WDC Scorpio Black Advanced Format (4k) drives */
876 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" },
880 /* WDC Scorpio Black Advanced Format (4k) drives */
881 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" },
885 /* WDC Scorpio Black Advanced Format (4k) drives */
886 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" },
890 /* WDC Scorpio Black Advanced Format (4k) drives */
891 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" },
895 /* WDC Scorpio Blue Advanced Format (4k) drives */
896 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" },
900 /* WDC Scorpio Blue Advanced Format (4k) drives */
901 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" },
905 /* WDC Scorpio Blue Advanced Format (4k) drives */
906 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" },
910 /* WDC Scorpio Blue Advanced Format (4k) drives */
911 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" },
916 * Olympus FE-210 camera
918 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*",
919 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
925 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S",
926 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
930 * Laser MP3-2GA13 MP3 player
932 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk",
933 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE
937 * LaCie external 250GB Hard drive des by Porsche
938 * Submitted by: Ben Stuyts <ben@altesco.nl>
941 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"},
942 /*quirks*/ DA_Q_NO_SYNC_CACHE
947 * Corsair Force 2 SSDs
948 * 4k optimised & trim only works in 4k requests + 4k aligned
950 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" },
955 * Corsair Force 3 SSDs
956 * 4k optimised & trim only works in 4k requests + 4k aligned
958 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" },
963 * Corsair Neutron GTX SSDs
964 * 4k optimised & trim only works in 4k requests + 4k aligned
966 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" },
971 * Corsair Force GT SSDs
972 * 4k optimised & trim only works in 4k requests + 4k aligned
974 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force GT*", "*" },
980 * 4k optimised & trim only works in 4k requests + 4k aligned
982 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" },
987 * Crucial RealSSD C300 SSDs
990 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*",
991 "*" }, /*quirks*/DA_Q_4K
995 * Intel 320 Series SSDs
996 * 4k optimised & trim only works in 4k requests + 4k aligned
998 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" },
1003 * Intel 330 Series SSDs
1004 * 4k optimised & trim only works in 4k requests + 4k aligned
1006 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" },
1011 * Intel 510 Series SSDs
1012 * 4k optimised & trim only works in 4k requests + 4k aligned
1014 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" },
1019 * Intel 520 Series SSDs
1020 * 4k optimised & trim only works in 4k requests + 4k aligned
1022 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" },
1027 * Intel X25-M Series SSDs
1028 * 4k optimised & trim only works in 4k requests + 4k aligned
1030 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" },
1035 * Kingston E100 Series SSDs
1036 * 4k optimised & trim only works in 4k requests + 4k aligned
1038 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" },
1043 * Kingston HyperX 3k SSDs
1044 * 4k optimised & trim only works in 4k requests + 4k aligned
1046 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" },
1051 * Marvell SSDs (entry taken from OpenSolaris)
1052 * 4k optimised & trim only works in 4k requests + 4k aligned
1054 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" },
1059 * OCZ Agility 2 SSDs
1060 * 4k optimised & trim only works in 4k requests + 4k aligned
1062 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" },
1067 * OCZ Agility 3 SSDs
1068 * 4k optimised & trim only works in 4k requests + 4k aligned
1070 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" },
1075 * OCZ Deneva R Series SSDs
1076 * 4k optimised & trim only works in 4k requests + 4k aligned
1078 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" },
1083 * OCZ Vertex 2 SSDs (inc pro series)
1084 * 4k optimised & trim only works in 4k requests + 4k aligned
1086 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" },
1092 * 4k optimised & trim only works in 4k requests + 4k aligned
1094 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" },
1100 * 4k optimised & trim only works in 4k requests + 4k aligned
1102 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" },
1107 * Samsung 830 Series SSDs
1108 * 4k optimised & trim only works in 4k requests + 4k aligned
1110 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" },
1115 * SuperTalent TeraDrive CT SSDs
1116 * 4k optimised & trim only works in 4k requests + 4k aligned
1118 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" },
1123 * XceedIOPS SATA SSDs
1126 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" },
1131 static disk_strategy_t dastrategy;
1132 static dumper_t dadump;
1133 static periph_init_t dainit;
1134 static void daasync(void *callback_arg, u_int32_t code,
1135 struct cam_path *path, void *arg);
1136 static void dasysctlinit(void *context, int pending);
1137 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS);
1138 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS);
1139 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS);
1140 static void dadeletemethodset(struct da_softc *softc,
1141 da_delete_methods delete_method);
1142 static off_t dadeletemaxsize(struct da_softc *softc,
1143 da_delete_methods delete_method);
1144 static void dadeletemethodchoose(struct da_softc *softc,
1145 da_delete_methods default_method);
1146 static void daprobedone(struct cam_periph *periph, union ccb *ccb);
1148 static periph_ctor_t daregister;
1149 static periph_dtor_t dacleanup;
1150 static periph_start_t dastart;
1151 static periph_oninv_t daoninvalidate;
1152 static void dadone(struct cam_periph *periph,
1153 union ccb *done_ccb);
1154 static int daerror(union ccb *ccb, u_int32_t cam_flags,
1155 u_int32_t sense_flags);
1156 static void daprevent(struct cam_periph *periph, int action);
1157 static void dareprobe(struct cam_periph *periph);
1158 static void dasetgeom(struct cam_periph *periph, uint32_t block_len,
1160 struct scsi_read_capacity_data_long *rcaplong,
1162 static timeout_t dasendorderedtag;
1163 static void dashutdown(void *arg, int howto);
1164 static timeout_t damediapoll;
1166 #ifndef DA_DEFAULT_POLL_PERIOD
1167 #define DA_DEFAULT_POLL_PERIOD 3
1170 #ifndef DA_DEFAULT_TIMEOUT
1171 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */
1174 #ifndef DA_DEFAULT_RETRY
1175 #define DA_DEFAULT_RETRY 4
1178 #ifndef DA_DEFAULT_SEND_ORDERED
1179 #define DA_DEFAULT_SEND_ORDERED 1
1182 #define DA_SIO (softc->sort_io_queue >= 0 ? \
1183 softc->sort_io_queue : cam_sort_io_queues)
1185 static int da_poll_period = DA_DEFAULT_POLL_PERIOD;
1186 static int da_retry_count = DA_DEFAULT_RETRY;
1187 static int da_default_timeout = DA_DEFAULT_TIMEOUT;
1188 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED;
1190 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0,
1191 "CAM Direct Access Disk driver");
1192 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RW,
1193 &da_poll_period, 0, "Media polling period in seconds");
1194 TUNABLE_INT("kern.cam.da.poll_period", &da_poll_period);
1195 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RW,
1196 &da_retry_count, 0, "Normal I/O retry count");
1197 TUNABLE_INT("kern.cam.da.retry_count", &da_retry_count);
1198 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RW,
1199 &da_default_timeout, 0, "Normal I/O timeout (in seconds)");
1200 TUNABLE_INT("kern.cam.da.default_timeout", &da_default_timeout);
1201 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RW,
1202 &da_send_ordered, 0, "Send Ordered Tags");
1203 TUNABLE_INT("kern.cam.da.send_ordered", &da_send_ordered);
1206 * DA_ORDEREDTAG_INTERVAL determines how often, relative
1207 * to the default timeout, we check to see whether an ordered
1208 * tagged transaction is appropriate to prevent simple tag
1209 * starvation. Since we'd like to ensure that there is at least
1210 * 1/2 of the timeout length left for a starved transaction to
1211 * complete after we've sent an ordered tag, we must poll at least
1212 * four times in every timeout period. This takes care of the worst
1213 * case where a starved transaction starts during an interval that
1214 * meets the requirement "don't send an ordered tag" test so it takes
1215 * us two intervals to determine that a tag must be sent.
1217 #ifndef DA_ORDEREDTAG_INTERVAL
1218 #define DA_ORDEREDTAG_INTERVAL 4
1221 static struct periph_driver dadriver =
1224 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0
1227 PERIPHDRIVER_DECLARE(da, dadriver);
1229 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers");
1232 daopen(struct disk *dp)
1234 struct cam_periph *periph;
1235 struct da_softc *softc;
1238 periph = (struct cam_periph *)dp->d_drv1;
1239 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
1243 cam_periph_lock(periph);
1244 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) {
1245 cam_periph_unlock(periph);
1246 cam_periph_release(periph);
1250 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1253 softc = (struct da_softc *)periph->softc;
1256 /* Wait for the disk size update. */
1257 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO,
1260 xpt_print(periph->path, "unable to retrieve capacity data\n");
1262 if (periph->flags & CAM_PERIPH_INVALID)
1265 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 &&
1266 (softc->quirks & DA_Q_NO_PREVENT) == 0)
1267 daprevent(periph, PR_PREVENT);
1270 softc->flags &= ~DA_FLAG_PACK_INVALID;
1271 softc->flags |= DA_FLAG_OPEN;
1274 cam_periph_unhold(periph);
1275 cam_periph_unlock(periph);
1278 cam_periph_release(periph);
1284 daclose(struct disk *dp)
1286 struct cam_periph *periph;
1287 struct da_softc *softc;
1290 periph = (struct cam_periph *)dp->d_drv1;
1291 cam_periph_lock(periph);
1292 if (cam_periph_hold(periph, PRIBIO) != 0) {
1293 cam_periph_unlock(periph);
1294 cam_periph_release(periph);
1298 softc = (struct da_softc *)periph->softc;
1300 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH,
1303 if ((softc->flags & DA_FLAG_DIRTY) != 0 &&
1304 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 &&
1305 (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
1308 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
1310 scsi_synchronize_cache(&ccb->csio,
1314 /*begin_lba*/0,/* Cover the whole disk */
1319 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
1320 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR,
1321 softc->disk->d_devstat);
1323 softc->flags &= ~DA_FLAG_DIRTY;
1324 xpt_release_ccb(ccb);
1328 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0) {
1329 if ((softc->quirks & DA_Q_NO_PREVENT) == 0)
1330 daprevent(periph, PR_ALLOW);
1332 * If we've got removeable media, mark the blocksize as
1333 * unavailable, since it could change when new media is
1336 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE;
1339 softc->flags &= ~DA_FLAG_OPEN;
1340 cam_periph_unhold(periph);
1341 cam_periph_unlock(periph);
1342 cam_periph_release(periph);
1347 daschedule(struct cam_periph *periph)
1349 struct da_softc *softc = (struct da_softc *)periph->softc;
1352 if (softc->state != DA_STATE_NORMAL)
1355 /* Check if cam_periph_getccb() was called. */
1356 prio = periph->immediate_priority;
1358 /* Check if we have more work to do. */
1359 if (bioq_first(&softc->bio_queue) ||
1360 (!softc->delete_running && bioq_first(&softc->delete_queue)) ||
1362 prio = CAM_PRIORITY_NORMAL;
1365 /* Schedule CCB if any of above is true. */
1366 if (prio != CAM_PRIORITY_NONE)
1367 xpt_schedule(periph, prio);
1371 * Actually translate the requested transfer into one the physical driver
1372 * can understand. The transfer is described by a buf and will include
1373 * only one physical transfer.
1376 dastrategy(struct bio *bp)
1378 struct cam_periph *periph;
1379 struct da_softc *softc;
1381 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1382 softc = (struct da_softc *)periph->softc;
1384 cam_periph_lock(periph);
1387 * If the device has been made invalid, error out
1389 if ((softc->flags & DA_FLAG_PACK_INVALID)) {
1390 cam_periph_unlock(periph);
1391 biofinish(bp, NULL, ENXIO);
1395 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp));
1398 * Place it in the queue of disk activities for this disk
1400 if (bp->bio_cmd == BIO_DELETE) {
1401 if (bp->bio_bcount == 0)
1404 bioq_disksort(&softc->delete_queue, bp);
1406 bioq_insert_tail(&softc->delete_queue, bp);
1407 } else if (DA_SIO) {
1408 bioq_disksort(&softc->bio_queue, bp);
1410 bioq_insert_tail(&softc->bio_queue, bp);
1414 * Schedule ourselves for performing the work.
1417 cam_periph_unlock(periph);
1423 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length)
1425 struct cam_periph *periph;
1426 struct da_softc *softc;
1428 struct ccb_scsiio csio;
1433 periph = dp->d_drv1;
1434 softc = (struct da_softc *)periph->softc;
1435 cam_periph_lock(periph);
1436 secsize = softc->params.secsize;
1438 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) {
1439 cam_periph_unlock(periph);
1444 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1445 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1446 scsi_read_write(&csio,
1450 /*read*/SCSI_RW_WRITE,
1452 /*minimum_cmd_size*/ softc->minimum_cmd_size,
1455 /*data_ptr*/(u_int8_t *) virtual,
1456 /*dxfer_len*/length,
1457 /*sense_len*/SSD_FULL_SIZE,
1458 da_default_timeout * 1000);
1459 xpt_polled_action((union ccb *)&csio);
1461 error = cam_periph_error((union ccb *)&csio,
1462 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL);
1463 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1464 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1465 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1467 printf("Aborting dump due to I/O error.\n");
1468 cam_periph_unlock(periph);
1473 * Sync the disk cache contents to the physical media.
1475 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
1477 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
1478 csio.ccb_h.ccb_state = DA_CCB_DUMP;
1479 scsi_synchronize_cache(&csio,
1483 /*begin_lba*/0,/* Cover the whole disk */
1487 xpt_polled_action((union ccb *)&csio);
1489 error = cam_periph_error((union ccb *)&csio,
1490 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL);
1491 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0)
1492 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0,
1493 /*reduction*/0, /*timeout*/0, /*getcount_only*/0);
1495 xpt_print(periph->path, "Synchronize cache failed\n");
1497 cam_periph_unlock(periph);
1502 dagetattr(struct bio *bp)
1505 struct cam_periph *periph;
1507 periph = (struct cam_periph *)bp->bio_disk->d_drv1;
1508 cam_periph_lock(periph);
1509 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute,
1511 cam_periph_unlock(periph);
1513 bp->bio_completed = bp->bio_length;
1523 * Install a global async callback. This callback will
1524 * receive async callbacks like "new device found".
1526 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL);
1528 if (status != CAM_REQ_CMP) {
1529 printf("da: Failed to attach master async callback "
1530 "due to status 0x%x!\n", status);
1531 } else if (da_send_ordered) {
1533 /* Register our shutdown event handler */
1534 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown,
1535 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL)
1536 printf("dainit: shutdown event registration failed!\n");
1541 * Callback from GEOM, called when it has finished cleaning up its
1545 dadiskgonecb(struct disk *dp)
1547 struct cam_periph *periph;
1549 periph = (struct cam_periph *)dp->d_drv1;
1550 cam_periph_release(periph);
1554 daoninvalidate(struct cam_periph *periph)
1556 struct da_softc *softc;
1558 softc = (struct da_softc *)periph->softc;
1561 * De-register any async callbacks.
1563 xpt_register_async(0, daasync, periph, periph->path);
1565 softc->flags |= DA_FLAG_PACK_INVALID;
1568 * Return all queued I/O with ENXIO.
1569 * XXX Handle any transactions queued to the card
1570 * with XPT_ABORT_CCB.
1572 bioq_flush(&softc->bio_queue, NULL, ENXIO);
1573 bioq_flush(&softc->delete_queue, NULL, ENXIO);
1576 * Tell GEOM that we've gone away, we'll get a callback when it is
1577 * done cleaning up its resources.
1579 disk_gone(softc->disk);
1583 dacleanup(struct cam_periph *periph)
1585 struct da_softc *softc;
1587 softc = (struct da_softc *)periph->softc;
1589 cam_periph_unlock(periph);
1592 * If we can't free the sysctl tree, oh well...
1594 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0
1595 && sysctl_ctx_free(&softc->sysctl_ctx) != 0) {
1596 xpt_print(periph->path, "can't remove sysctl context\n");
1599 callout_drain(&softc->mediapoll_c);
1600 disk_destroy(softc->disk);
1601 callout_drain(&softc->sendordered_c);
1602 free(softc, M_DEVBUF);
1603 cam_periph_lock(periph);
1607 daasync(void *callback_arg, u_int32_t code,
1608 struct cam_path *path, void *arg)
1610 struct cam_periph *periph;
1611 struct da_softc *softc;
1613 periph = (struct cam_periph *)callback_arg;
1615 case AC_FOUND_DEVICE:
1617 struct ccb_getdev *cgd;
1620 cgd = (struct ccb_getdev *)arg;
1624 if (cgd->protocol != PROTO_SCSI)
1627 if (SID_TYPE(&cgd->inq_data) != T_DIRECT
1628 && SID_TYPE(&cgd->inq_data) != T_RBC
1629 && SID_TYPE(&cgd->inq_data) != T_OPTICAL)
1633 * Allocate a peripheral instance for
1634 * this device and start the probe
1637 status = cam_periph_alloc(daregister, daoninvalidate,
1639 "da", CAM_PERIPH_BIO,
1640 cgd->ccb_h.path, daasync,
1641 AC_FOUND_DEVICE, cgd);
1643 if (status != CAM_REQ_CMP
1644 && status != CAM_REQ_INPROG)
1645 printf("daasync: Unable to attach to new device "
1646 "due to status 0x%x\n", status);
1649 case AC_ADVINFO_CHANGED:
1653 buftype = (uintptr_t)arg;
1654 if (buftype == CDAI_TYPE_PHYS_PATH) {
1655 struct da_softc *softc;
1657 softc = periph->softc;
1658 disk_attr_changed(softc->disk, "GEOM::physpath",
1663 case AC_UNIT_ATTENTION:
1666 int error_code, sense_key, asc, ascq;
1668 softc = (struct da_softc *)periph->softc;
1669 ccb = (union ccb *)arg;
1672 * Handle all UNIT ATTENTIONs except our own,
1673 * as they will be handled by daerror().
1675 if (xpt_path_periph(ccb->ccb_h.path) != periph &&
1676 scsi_extract_sense_ccb(ccb,
1677 &error_code, &sense_key, &asc, &ascq)) {
1678 if (asc == 0x2A && ascq == 0x09) {
1679 xpt_print(ccb->ccb_h.path,
1680 "Capacity data has changed\n");
1681 softc->flags &= ~DA_FLAG_PROBED;
1683 } else if (asc == 0x28 && ascq == 0x00) {
1684 softc->flags &= ~DA_FLAG_PROBED;
1685 disk_media_changed(softc->disk, M_NOWAIT);
1686 } else if (asc == 0x3F && ascq == 0x03) {
1687 xpt_print(ccb->ccb_h.path,
1688 "INQUIRY data has changed\n");
1689 softc->flags &= ~DA_FLAG_PROBED;
1693 cam_periph_async(periph, code, path, arg);
1697 softc = (struct da_softc *)periph->softc;
1699 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
1708 struct ccb_hdr *ccbh;
1710 softc = (struct da_softc *)periph->softc;
1712 * Don't fail on the expected unit attention
1715 softc->flags |= DA_FLAG_RETRY_UA;
1716 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le)
1717 ccbh->ccb_state |= DA_CCB_RETRY_UA;
1723 cam_periph_async(periph, code, path, arg);
1727 dasysctlinit(void *context, int pending)
1729 struct cam_periph *periph;
1730 struct da_softc *softc;
1731 char tmpstr[80], tmpstr2[80];
1732 struct ccb_trans_settings cts;
1734 periph = (struct cam_periph *)context;
1736 * periph was held for us when this task was enqueued
1738 if (periph->flags & CAM_PERIPH_INVALID) {
1739 cam_periph_release(periph);
1743 softc = (struct da_softc *)periph->softc;
1744 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number);
1745 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number);
1747 sysctl_ctx_init(&softc->sysctl_ctx);
1748 softc->flags |= DA_FLAG_SCTX_INIT;
1749 softc->sysctl_tree = SYSCTL_ADD_NODE(&softc->sysctl_ctx,
1750 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2,
1751 CTLFLAG_RD, 0, tmpstr);
1752 if (softc->sysctl_tree == NULL) {
1753 printf("dasysctlinit: unable to allocate sysctl tree\n");
1754 cam_periph_release(periph);
1759 * Now register the sysctl handler, so the user can change the value on
1762 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1763 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RW,
1764 softc, 0, dadeletemethodsysctl, "A",
1765 "BIO_DELETE execution method");
1766 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1767 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW,
1768 softc, 0, dadeletemaxsysctl, "Q",
1769 "Maximum BIO_DELETE size");
1770 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1771 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW,
1772 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I",
1773 "Minimum CDB size");
1774 SYSCTL_ADD_INT(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree),
1775 OID_AUTO, "sort_io_queue", CTLFLAG_RW, &softc->sort_io_queue, 0,
1776 "Sort IO queue to try and optimise disk access patterns");
1778 SYSCTL_ADD_INT(&softc->sysctl_ctx,
1779 SYSCTL_CHILDREN(softc->sysctl_tree),
1783 &softc->error_inject,
1785 "error_inject leaf");
1789 * Add some addressing info.
1791 memset(&cts, 0, sizeof (cts));
1792 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE);
1793 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS;
1794 cts.type = CTS_TYPE_CURRENT_SETTINGS;
1795 cam_periph_lock(periph);
1796 xpt_action((union ccb *)&cts);
1797 cam_periph_unlock(periph);
1798 if (cts.ccb_h.status != CAM_REQ_CMP) {
1799 cam_periph_release(periph);
1802 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) {
1803 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc;
1804 if (fc->valid & CTS_FC_VALID_WWPN) {
1805 softc->wwpn = fc->wwpn;
1806 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx,
1807 SYSCTL_CHILDREN(softc->sysctl_tree),
1808 OID_AUTO, "wwpn", CTLFLAG_RD,
1809 &softc->wwpn, "World Wide Port Name");
1812 cam_periph_release(periph);
1816 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS)
1820 struct da_softc *softc;
1822 softc = (struct da_softc *)arg1;
1824 value = softc->disk->d_delmaxsize;
1825 error = sysctl_handle_64(oidp, &value, 0, req);
1826 if ((error != 0) || (req->newptr == NULL))
1829 /* only accept values smaller than the calculated value */
1830 if (value > dadeletemaxsize(softc, softc->delete_method)) {
1833 softc->disk->d_delmaxsize = value;
1839 dacmdsizesysctl(SYSCTL_HANDLER_ARGS)
1843 value = *(int *)arg1;
1845 error = sysctl_handle_int(oidp, &value, 0, req);
1848 || (req->newptr == NULL))
1852 * Acceptable values here are 6, 10, 12 or 16.
1856 else if ((value > 6)
1859 else if ((value > 10)
1862 else if (value > 12)
1865 *(int *)arg1 = value;
1871 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method)
1875 softc->delete_method = delete_method;
1876 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method);
1877 softc->delete_func = da_delete_functions[delete_method];
1879 if (softc->delete_method > DA_DELETE_DISABLE)
1880 softc->disk->d_flags |= DISKFLAG_CANDELETE;
1882 softc->disk->d_flags &= ~DISKFLAG_CANDELETE;
1886 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method)
1890 switch(delete_method) {
1891 case DA_DELETE_UNMAP:
1892 sectors = (off_t)softc->unmap_max_lba;
1894 case DA_DELETE_ATA_TRIM:
1895 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges;
1897 case DA_DELETE_WS16:
1898 sectors = (off_t)min(softc->ws_max_blks, WS16_MAX_BLKS);
1900 case DA_DELETE_ZERO:
1901 case DA_DELETE_WS10:
1902 sectors = (off_t)min(softc->ws_max_blks, WS10_MAX_BLKS);
1908 return (off_t)softc->params.secsize *
1909 min(sectors, (off_t)softc->params.sectors);
1913 daprobedone(struct cam_periph *periph, union ccb *ccb)
1915 struct da_softc *softc;
1917 softc = (struct da_softc *)periph->softc;
1919 dadeletemethodchoose(softc, DA_DELETE_NONE);
1921 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) {
1925 snprintf(buf, sizeof(buf), "Delete methods: <");
1927 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1928 if (softc->delete_available & (1 << i)) {
1930 strlcat(buf, ",", sizeof(buf));
1934 strlcat(buf, da_delete_method_names[i],
1936 if (i == softc->delete_method) {
1937 strlcat(buf, "(*)", sizeof(buf));
1942 if (softc->delete_method == DA_DELETE_NONE)
1943 strlcat(buf, "NONE(*)", sizeof(buf));
1945 strlcat(buf, "DISABLED(*)", sizeof(buf));
1947 strlcat(buf, ">", sizeof(buf));
1948 printf("%s%d: %s\n", periph->periph_name,
1949 periph->unit_number, buf);
1953 * Since our peripheral may be invalidated by an error
1954 * above or an external event, we must release our CCB
1955 * before releasing the probe lock on the peripheral.
1956 * The peripheral will only go away once the last lock
1957 * is removed, and we need it around for the CCB release
1960 xpt_release_ccb(ccb);
1961 softc->state = DA_STATE_NORMAL;
1962 softc->flags |= DA_FLAG_PROBED;
1964 wakeup(&softc->disk->d_mediasize);
1965 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) {
1966 softc->flags |= DA_FLAG_ANNOUNCED;
1967 cam_periph_unhold(periph);
1969 cam_periph_release_locked(periph);
1973 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method)
1975 int i, delete_method;
1977 delete_method = default_method;
1980 * Use the pre-defined order to choose the best
1981 * performing delete.
1983 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) {
1984 if (softc->delete_available & (1 << i)) {
1985 dadeletemethodset(softc, i);
1989 dadeletemethodset(softc, delete_method);
1993 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS)
1997 struct da_softc *softc;
1998 int i, error, methods, value;
2000 softc = (struct da_softc *)arg1;
2002 value = softc->delete_method;
2003 if (value < 0 || value > DA_DELETE_MAX)
2006 p = da_delete_method_names[value];
2007 strncpy(buf, p, sizeof(buf));
2008 error = sysctl_handle_string(oidp, buf, sizeof(buf), req);
2009 if (error != 0 || req->newptr == NULL)
2011 methods = softc->delete_available | (1 << DA_DELETE_DISABLE);
2012 for (i = 0; i <= DA_DELETE_MAX; i++) {
2013 if (!(methods & (1 << i)) ||
2014 strcmp(buf, da_delete_method_names[i]) != 0)
2016 dadeletemethodset(softc, i);
2023 daregister(struct cam_periph *periph, void *arg)
2025 struct da_softc *softc;
2026 struct ccb_pathinq cpi;
2027 struct ccb_getdev *cgd;
2031 cgd = (struct ccb_getdev *)arg;
2033 printf("daregister: no getdev CCB, can't register device\n");
2034 return(CAM_REQ_CMP_ERR);
2037 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF,
2040 if (softc == NULL) {
2041 printf("daregister: Unable to probe new device. "
2042 "Unable to allocate softc\n");
2043 return(CAM_REQ_CMP_ERR);
2046 LIST_INIT(&softc->pending_ccbs);
2047 softc->state = DA_STATE_PROBE_RC;
2048 bioq_init(&softc->bio_queue);
2049 bioq_init(&softc->delete_queue);
2050 bioq_init(&softc->delete_run_queue);
2051 if (SID_IS_REMOVABLE(&cgd->inq_data))
2052 softc->flags |= DA_FLAG_PACK_REMOVABLE;
2053 softc->unmap_max_ranges = UNMAP_MAX_RANGES;
2054 softc->unmap_max_lba = UNMAP_RANGE_MAX;
2055 softc->ws_max_blks = WS16_MAX_BLKS;
2056 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES;
2057 softc->sort_io_queue = -1;
2059 periph->softc = softc;
2062 * See if this device has any quirks.
2064 match = cam_quirkmatch((caddr_t)&cgd->inq_data,
2065 (caddr_t)da_quirk_table,
2066 sizeof(da_quirk_table)/sizeof(*da_quirk_table),
2067 sizeof(*da_quirk_table), scsi_inquiry_match);
2070 softc->quirks = ((struct da_quirk_entry *)match)->quirks;
2072 softc->quirks = DA_Q_NONE;
2074 /* Check if the SIM does not want 6 byte commands */
2075 bzero(&cpi, sizeof(cpi));
2076 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
2077 cpi.ccb_h.func_code = XPT_PATH_INQ;
2078 xpt_action((union ccb *)&cpi);
2079 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE))
2080 softc->quirks |= DA_Q_NO_6_BYTE;
2082 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph);
2085 * Take an exclusive refcount on the periph while dastart is called
2086 * to finish the probe. The reference will be dropped in dadone at
2089 (void)cam_periph_hold(periph, PRIBIO);
2092 * Schedule a periodic event to occasionally send an
2093 * ordered tag to a device.
2095 callout_init_mtx(&softc->sendordered_c, periph->sim->mtx, 0);
2096 callout_reset(&softc->sendordered_c,
2097 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
2098 dasendorderedtag, softc);
2100 cam_periph_unlock(periph);
2102 * RBC devices don't have to support READ(6), only READ(10).
2104 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC)
2105 softc->minimum_cmd_size = 10;
2107 softc->minimum_cmd_size = 6;
2110 * Load the user's default, if any.
2112 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size",
2113 periph->unit_number);
2114 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size);
2117 * 6, 10, 12 and 16 are the currently permissible values.
2119 if (softc->minimum_cmd_size < 6)
2120 softc->minimum_cmd_size = 6;
2121 else if ((softc->minimum_cmd_size > 6)
2122 && (softc->minimum_cmd_size <= 10))
2123 softc->minimum_cmd_size = 10;
2124 else if ((softc->minimum_cmd_size > 10)
2125 && (softc->minimum_cmd_size <= 12))
2126 softc->minimum_cmd_size = 12;
2127 else if (softc->minimum_cmd_size > 12)
2128 softc->minimum_cmd_size = 16;
2130 /* Predict whether device may support READ CAPACITY(16). */
2131 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 &&
2132 (softc->quirks & DA_Q_NO_RC16) == 0) {
2133 softc->flags |= DA_FLAG_CAN_RC16;
2134 softc->state = DA_STATE_PROBE_RC16;
2138 * Register this media as a disk.
2140 softc->disk = disk_alloc();
2141 softc->disk->d_devstat = devstat_new_entry(periph->periph_name,
2142 periph->unit_number, 0,
2143 DEVSTAT_BS_UNAVAILABLE,
2144 SID_TYPE(&cgd->inq_data) |
2145 XPORT_DEVSTAT_TYPE(cpi.transport),
2146 DEVSTAT_PRIORITY_DISK);
2147 softc->disk->d_open = daopen;
2148 softc->disk->d_close = daclose;
2149 softc->disk->d_strategy = dastrategy;
2150 softc->disk->d_dump = dadump;
2151 softc->disk->d_getattr = dagetattr;
2152 softc->disk->d_gone = dadiskgonecb;
2153 softc->disk->d_name = "da";
2154 softc->disk->d_drv1 = periph;
2156 softc->maxio = DFLTPHYS; /* traditional default */
2157 else if (cpi.maxio > MAXPHYS)
2158 softc->maxio = MAXPHYS; /* for safety */
2160 softc->maxio = cpi.maxio;
2161 softc->disk->d_maxsize = softc->maxio;
2162 softc->disk->d_unit = periph->unit_number;
2163 softc->disk->d_flags = 0;
2164 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0)
2165 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE;
2166 if ((cpi.hba_misc & PIM_UNMAPPED) != 0)
2167 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO;
2168 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor,
2169 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr));
2170 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr));
2171 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)],
2172 cgd->inq_data.product, sizeof(cgd->inq_data.product),
2173 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr));
2174 softc->disk->d_hba_vendor = cpi.hba_vendor;
2175 softc->disk->d_hba_device = cpi.hba_device;
2176 softc->disk->d_hba_subvendor = cpi.hba_subvendor;
2177 softc->disk->d_hba_subdevice = cpi.hba_subdevice;
2180 * Acquire a reference to the periph before we register with GEOM.
2181 * We'll release this reference once GEOM calls us back (via
2182 * dadiskgonecb()) telling us that our provider has been freed.
2184 if (cam_periph_acquire(periph) != CAM_REQ_CMP) {
2185 xpt_print(periph->path, "%s: lost periph during "
2186 "registration!\n", __func__);
2187 cam_periph_lock(periph);
2188 return (CAM_REQ_CMP_ERR);
2191 disk_create(softc->disk, DISK_VERSION);
2192 cam_periph_lock(periph);
2195 * Add async callbacks for events of interest.
2196 * I don't bother checking if this fails as,
2197 * in most cases, the system will function just
2198 * fine without them and the only alternative
2199 * would be to not attach the device on failure.
2201 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE |
2202 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION,
2203 daasync, periph, periph->path);
2206 * Emit an attribute changed notification just in case
2207 * physical path information arrived before our async
2208 * event handler was registered, but after anyone attaching
2209 * to our disk device polled it.
2211 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT);
2214 * Schedule a periodic media polling events.
2216 callout_init_mtx(&softc->mediapoll_c, periph->sim->mtx, 0);
2217 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) &&
2218 (cgd->inq_flags & SID_AEN) == 0 &&
2219 da_poll_period != 0)
2220 callout_reset(&softc->mediapoll_c, da_poll_period * hz,
2221 damediapoll, periph);
2223 xpt_schedule(periph, CAM_PRIORITY_DEV);
2225 return(CAM_REQ_CMP);
2229 dastart(struct cam_periph *periph, union ccb *start_ccb)
2231 struct da_softc *softc;
2233 softc = (struct da_softc *)periph->softc;
2235 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n"));
2238 switch (softc->state) {
2239 case DA_STATE_NORMAL:
2244 /* Execute immediate CCB if waiting. */
2245 if (periph->immediate_priority <= periph->pinfo.priority) {
2246 CAM_DEBUG(periph->path, CAM_DEBUG_SUBTRACE,
2247 ("queuing for immediate ccb\n"));
2248 start_ccb->ccb_h.ccb_state = DA_CCB_WAITING;
2249 SLIST_INSERT_HEAD(&periph->ccb_list, &start_ccb->ccb_h,
2251 periph->immediate_priority = CAM_PRIORITY_NONE;
2252 wakeup(&periph->ccb_list);
2253 /* May have more work to do, so ensure we stay scheduled */
2258 /* Run BIO_DELETE if not running yet. */
2259 if (!softc->delete_running &&
2260 (bp = bioq_first(&softc->delete_queue)) != NULL) {
2261 if (softc->delete_func != NULL) {
2262 softc->delete_func(periph, start_ccb, bp);
2265 bioq_flush(&softc->delete_queue, NULL, 0);
2270 /* Run regular command. */
2271 bp = bioq_takefirst(&softc->bio_queue);
2275 scsi_test_unit_ready(&start_ccb->csio,
2276 /*retries*/ da_retry_count,
2280 da_default_timeout * 1000);
2281 start_ccb->ccb_h.ccb_bp = NULL;
2282 start_ccb->ccb_h.ccb_state = DA_CCB_TUR;
2283 xpt_action(start_ccb);
2285 xpt_release_ccb(start_ccb);
2290 cam_periph_release_locked(periph);
2293 if ((bp->bio_flags & BIO_ORDERED) != 0 ||
2294 (softc->flags & DA_FLAG_NEED_OTAG) != 0) {
2295 softc->flags &= ~DA_FLAG_NEED_OTAG;
2296 softc->flags |= DA_FLAG_WAS_OTAG;
2297 tag_code = MSG_ORDERED_Q_TAG;
2299 tag_code = MSG_SIMPLE_Q_TAG;
2302 switch (bp->bio_cmd) {
2304 softc->flags |= DA_FLAG_DIRTY;
2307 scsi_read_write(&start_ccb->csio,
2308 /*retries*/da_retry_count,
2310 /*tag_action*/tag_code,
2311 /*read_op*/(bp->bio_cmd == BIO_READ ?
2312 SCSI_RW_READ : SCSI_RW_WRITE) |
2313 ((bp->bio_flags & BIO_UNMAPPED) != 0 ?
2316 softc->minimum_cmd_size,
2317 /*lba*/bp->bio_pblkno,
2318 /*block_count*/bp->bio_bcount /
2319 softc->params.secsize,
2320 /*data_ptr*/ (bp->bio_flags &
2321 BIO_UNMAPPED) != 0 ? (void *)bp :
2323 /*dxfer_len*/ bp->bio_bcount,
2324 /*sense_len*/SSD_FULL_SIZE,
2325 da_default_timeout * 1000);
2329 * BIO_FLUSH doesn't currently communicate
2330 * range data, so we synchronize the cache
2331 * over the whole disk. We also force
2332 * ordered tag semantics the flush applies
2333 * to all previously queued I/O.
2335 scsi_synchronize_cache(&start_ccb->csio,
2342 da_default_timeout*1000);
2345 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO;
2348 LIST_INSERT_HEAD(&softc->pending_ccbs,
2349 &start_ccb->ccb_h, periph_links.le);
2351 /* We expect a unit attention from this device */
2352 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) {
2353 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA;
2354 softc->flags &= ~DA_FLAG_RETRY_UA;
2357 start_ccb->ccb_h.ccb_bp = bp;
2358 xpt_action(start_ccb);
2360 /* May have more work to do, so ensure we stay scheduled */
2364 case DA_STATE_PROBE_RC:
2366 struct scsi_read_capacity_data *rcap;
2368 rcap = (struct scsi_read_capacity_data *)
2369 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO);
2371 printf("dastart: Couldn't malloc read_capacity data\n");
2372 /* da_free_periph??? */
2375 scsi_read_capacity(&start_ccb->csio,
2376 /*retries*/da_retry_count,
2382 start_ccb->ccb_h.ccb_bp = NULL;
2383 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC;
2384 xpt_action(start_ccb);
2387 case DA_STATE_PROBE_RC16:
2389 struct scsi_read_capacity_data_long *rcaplong;
2391 rcaplong = (struct scsi_read_capacity_data_long *)
2392 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO);
2393 if (rcaplong == NULL) {
2394 printf("dastart: Couldn't malloc read_capacity data\n");
2395 /* da_free_periph??? */
2398 scsi_read_capacity_16(&start_ccb->csio,
2399 /*retries*/ da_retry_count,
2401 /*tag_action*/ MSG_SIMPLE_Q_TAG,
2406 /*sense_len*/ SSD_FULL_SIZE,
2407 /*timeout*/ da_default_timeout * 1000);
2408 start_ccb->ccb_h.ccb_bp = NULL;
2409 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16;
2410 xpt_action(start_ccb);
2413 case DA_STATE_PROBE_LBP:
2415 struct scsi_vpd_logical_block_prov *lbp;
2417 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) {
2419 * If we get here we don't support any SBC-3 delete
2420 * methods with UNMAP as the Logical Block Provisioning
2421 * VPD page support is required for devices which
2422 * support it according to T10/1799-D Revision 31
2423 * however older revisions of the spec don't mandate
2424 * this so we currently don't remove these methods
2425 * from the available set.
2427 softc->state = DA_STATE_PROBE_BLK_LIMITS;
2431 lbp = (struct scsi_vpd_logical_block_prov *)
2432 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO);
2435 printf("dastart: Couldn't malloc lbp data\n");
2436 /* da_free_periph??? */
2440 scsi_inquiry(&start_ccb->csio,
2441 /*retries*/da_retry_count,
2443 /*tag_action*/MSG_SIMPLE_Q_TAG,
2444 /*inq_buf*/(u_int8_t *)lbp,
2445 /*inq_len*/sizeof(*lbp),
2447 /*page_code*/SVPD_LBP,
2448 /*sense_len*/SSD_MIN_SIZE,
2449 /*timeout*/da_default_timeout * 1000);
2450 start_ccb->ccb_h.ccb_bp = NULL;
2451 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP;
2452 xpt_action(start_ccb);
2455 case DA_STATE_PROBE_BLK_LIMITS:
2457 struct scsi_vpd_block_limits *block_limits;
2459 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) {
2460 /* Not supported skip to next probe */
2461 softc->state = DA_STATE_PROBE_BDC;
2465 block_limits = (struct scsi_vpd_block_limits *)
2466 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO);
2468 if (block_limits == NULL) {
2469 printf("dastart: Couldn't malloc block_limits data\n");
2470 /* da_free_periph??? */
2474 scsi_inquiry(&start_ccb->csio,
2475 /*retries*/da_retry_count,
2477 /*tag_action*/MSG_SIMPLE_Q_TAG,
2478 /*inq_buf*/(u_int8_t *)block_limits,
2479 /*inq_len*/sizeof(*block_limits),
2481 /*page_code*/SVPD_BLOCK_LIMITS,
2482 /*sense_len*/SSD_MIN_SIZE,
2483 /*timeout*/da_default_timeout * 1000);
2484 start_ccb->ccb_h.ccb_bp = NULL;
2485 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS;
2486 xpt_action(start_ccb);
2489 case DA_STATE_PROBE_BDC:
2491 struct scsi_vpd_block_characteristics *bdc;
2493 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) {
2494 softc->state = DA_STATE_PROBE_ATA;
2498 bdc = (struct scsi_vpd_block_characteristics *)
2499 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO);
2502 printf("dastart: Couldn't malloc bdc data\n");
2503 /* da_free_periph??? */
2507 scsi_inquiry(&start_ccb->csio,
2508 /*retries*/da_retry_count,
2510 /*tag_action*/MSG_SIMPLE_Q_TAG,
2511 /*inq_buf*/(u_int8_t *)bdc,
2512 /*inq_len*/sizeof(*bdc),
2514 /*page_code*/SVPD_BDC,
2515 /*sense_len*/SSD_MIN_SIZE,
2516 /*timeout*/da_default_timeout * 1000);
2517 start_ccb->ccb_h.ccb_bp = NULL;
2518 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC;
2519 xpt_action(start_ccb);
2522 case DA_STATE_PROBE_ATA:
2524 struct ata_params *ata_params;
2526 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) {
2527 daprobedone(periph, start_ccb);
2531 ata_params = (struct ata_params*)
2532 malloc(sizeof(*ata_params), M_SCSIDA, M_NOWAIT|M_ZERO);
2534 if (ata_params == NULL) {
2535 printf("dastart: Couldn't malloc ata_params data\n");
2536 /* da_free_periph??? */
2540 scsi_ata_identify(&start_ccb->csio,
2541 /*retries*/da_retry_count,
2543 /*tag_action*/MSG_SIMPLE_Q_TAG,
2544 /*data_ptr*/(u_int8_t *)ata_params,
2545 /*dxfer_len*/sizeof(*ata_params),
2546 /*sense_len*/SSD_FULL_SIZE,
2547 /*timeout*/da_default_timeout * 1000);
2548 start_ccb->ccb_h.ccb_bp = NULL;
2549 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA;
2550 xpt_action(start_ccb);
2557 * In each of the methods below, while its the caller's
2558 * responsibility to ensure the request will fit into a
2559 * single device request, we might have changed the delete
2560 * method due to the device incorrectly advertising either
2561 * its supported methods or limits.
2563 * To prevent this causing further issues we validate the
2564 * against the methods limits, and warn which would
2565 * otherwise be unnecessary.
2568 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2570 struct da_softc *softc = (struct da_softc *)periph->softc;;
2572 uint8_t *buf = softc->unmap_buf;
2573 uint64_t lba, lastlba = (uint64_t)-1;
2574 uint64_t totalcount = 0;
2576 uint32_t lastcount = 0, c;
2577 uint32_t off, ranges = 0;
2580 * Currently this doesn't take the UNMAP
2581 * Granularity and Granularity Alignment
2582 * fields into account.
2584 * This could result in both unoptimal unmap
2585 * requests as as well as UNMAP calls unmapping
2586 * fewer LBA's than requested.
2589 softc->delete_running = 1;
2590 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2593 bioq_remove(&softc->delete_queue, bp1);
2595 bioq_insert_tail(&softc->delete_run_queue, bp1);
2596 lba = bp1->bio_pblkno;
2597 count = bp1->bio_bcount / softc->params.secsize;
2599 /* Try to extend the previous range. */
2600 if (lba == lastlba) {
2601 c = omin(count, UNMAP_RANGE_MAX - lastcount);
2603 off = ((ranges - 1) * UNMAP_RANGE_SIZE) +
2605 scsi_ulto4b(lastcount, &buf[off + 8]);
2612 c = omin(count, UNMAP_RANGE_MAX);
2613 if (totalcount + c > softc->unmap_max_lba ||
2614 ranges >= softc->unmap_max_ranges) {
2615 xpt_print(periph->path,
2616 "%s issuing short delete %ld > %ld"
2618 da_delete_method_desc[softc->delete_method],
2619 totalcount + c, softc->unmap_max_lba,
2620 ranges, softc->unmap_max_ranges);
2623 off = (ranges * UNMAP_RANGE_SIZE) + UNMAP_HEAD_SIZE;
2624 scsi_u64to8b(lba, &buf[off + 0]);
2625 scsi_ulto4b(c, &buf[off + 8]);
2633 bp1 = bioq_first(&softc->delete_queue);
2634 if (bp1 == NULL || ranges >= softc->unmap_max_ranges ||
2635 totalcount + bp1->bio_bcount /
2636 softc->params.secsize > softc->unmap_max_lba)
2639 scsi_ulto2b(ranges * 16 + 6, &buf[0]);
2640 scsi_ulto2b(ranges * 16, &buf[2]);
2642 scsi_unmap(&ccb->csio,
2643 /*retries*/da_retry_count,
2645 /*tag_action*/MSG_SIMPLE_Q_TAG,
2648 /*dxfer_len*/ ranges * 16 + 8,
2649 /*sense_len*/SSD_FULL_SIZE,
2650 da_default_timeout * 1000);
2651 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2655 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2657 struct da_softc *softc = (struct da_softc *)periph->softc;
2659 uint8_t *buf = softc->unmap_buf;
2660 uint64_t lastlba = (uint64_t)-1;
2663 uint32_t lastcount = 0, c, requestcount;
2664 int ranges = 0, off, block_count;
2666 softc->delete_running = 1;
2667 bzero(softc->unmap_buf, sizeof(softc->unmap_buf));
2670 bioq_remove(&softc->delete_queue, bp1);
2672 bioq_insert_tail(&softc->delete_run_queue, bp1);
2673 lba = bp1->bio_pblkno;
2674 count = bp1->bio_bcount / softc->params.secsize;
2675 requestcount = count;
2677 /* Try to extend the previous range. */
2678 if (lba == lastlba) {
2679 c = min(count, ATA_DSM_RANGE_MAX - lastcount);
2681 off = (ranges - 1) * 8;
2682 buf[off + 6] = lastcount & 0xff;
2683 buf[off + 7] = (lastcount >> 8) & 0xff;
2689 c = min(count, ATA_DSM_RANGE_MAX);
2692 buf[off + 0] = lba & 0xff;
2693 buf[off + 1] = (lba >> 8) & 0xff;
2694 buf[off + 2] = (lba >> 16) & 0xff;
2695 buf[off + 3] = (lba >> 24) & 0xff;
2696 buf[off + 4] = (lba >> 32) & 0xff;
2697 buf[off + 5] = (lba >> 40) & 0xff;
2698 buf[off + 6] = c & 0xff;
2699 buf[off + 7] = (c >> 8) & 0xff;
2704 if (count != 0 && ranges == softc->trim_max_ranges) {
2705 xpt_print(periph->path,
2706 "%s issuing short delete %ld > %ld\n",
2707 da_delete_method_desc[softc->delete_method],
2709 (softc->trim_max_ranges - ranges) *
2715 bp1 = bioq_first(&softc->delete_queue);
2716 if (bp1 == NULL || bp1->bio_bcount / softc->params.secsize >
2717 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX)
2721 block_count = (ranges + ATA_DSM_BLK_RANGES - 1) / ATA_DSM_BLK_RANGES;
2722 scsi_ata_trim(&ccb->csio,
2723 /*retries*/da_retry_count,
2725 /*tag_action*/MSG_SIMPLE_Q_TAG,
2728 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE,
2729 /*sense_len*/SSD_FULL_SIZE,
2730 da_default_timeout * 1000);
2731 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2735 * We calculate ws_max_blks here based off d_delmaxsize instead
2736 * of using softc->ws_max_blks as it is absolute max for the
2737 * device not the protocol max which may well be lower.
2740 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp)
2742 struct da_softc *softc;
2744 uint64_t ws_max_blks;
2746 uint64_t count; /* forward compat with WS32 */
2748 softc = (struct da_softc *)periph->softc;
2749 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize;
2750 softc->delete_running = 1;
2751 lba = bp->bio_pblkno;
2755 bioq_remove(&softc->delete_queue, bp1);
2757 bioq_insert_tail(&softc->delete_run_queue, bp1);
2758 count += bp1->bio_bcount / softc->params.secsize;
2759 if (count > ws_max_blks) {
2760 xpt_print(periph->path,
2761 "%s issuing short delete %ld > %ld\n",
2762 da_delete_method_desc[softc->delete_method],
2763 count, ws_max_blks);
2764 count = min(count, ws_max_blks);
2767 bp1 = bioq_first(&softc->delete_queue);
2768 if (bp1 == NULL || lba + count != bp1->bio_pblkno ||
2769 count + bp1->bio_bcount /
2770 softc->params.secsize > ws_max_blks)
2774 scsi_write_same(&ccb->csio,
2775 /*retries*/da_retry_count,
2777 /*tag_action*/MSG_SIMPLE_Q_TAG,
2778 /*byte2*/softc->delete_method ==
2779 DA_DELETE_ZERO ? 0 : SWS_UNMAP,
2780 softc->delete_method == DA_DELETE_WS16 ? 16 : 10,
2782 /*block_count*/count,
2783 /*data_ptr*/ __DECONST(void *, zero_region),
2784 /*dxfer_len*/ softc->params.secsize,
2785 /*sense_len*/SSD_FULL_SIZE,
2786 da_default_timeout * 1000);
2787 ccb->ccb_h.ccb_state = DA_CCB_DELETE;
2791 cmd6workaround(union ccb *ccb)
2793 struct scsi_rw_6 cmd6;
2794 struct scsi_rw_10 *cmd10;
2795 struct da_softc *softc;
2800 cdb = ccb->csio.cdb_io.cdb_bytes;
2801 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc;
2803 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) {
2804 da_delete_methods old_method = softc->delete_method;
2807 * Typically there are two reasons for failure here
2808 * 1. Delete method was detected as supported but isn't
2809 * 2. Delete failed due to invalid params e.g. too big
2811 * While we will attempt to choose an alternative delete method
2812 * this may result in short deletes if the existing delete
2813 * requests from geom are big for the new method choosen.
2815 * This method assumes that the error which triggered this
2816 * will not retry the io otherwise a panic will occur
2818 dadeleteflag(softc, old_method, 0);
2819 dadeletemethodchoose(softc, DA_DELETE_DISABLE);
2820 if (softc->delete_method == DA_DELETE_DISABLE)
2821 xpt_print(ccb->ccb_h.path,
2822 "%s failed, disabling BIO_DELETE\n",
2823 da_delete_method_desc[old_method]);
2825 xpt_print(ccb->ccb_h.path,
2826 "%s failed, switching to %s BIO_DELETE\n",
2827 da_delete_method_desc[old_method],
2828 da_delete_method_desc[softc->delete_method]);
2831 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2833 bioq_disksort(&softc->delete_queue, bp);
2835 while ((bp = bioq_takefirst(&softc->delete_run_queue))
2837 bioq_insert_tail(&softc->delete_queue, bp);
2839 bioq_insert_tail(&softc->delete_queue,
2840 (struct bio *)ccb->ccb_h.ccb_bp);
2841 ccb->ccb_h.ccb_bp = NULL;
2845 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */
2846 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2847 (*cdb == PREVENT_ALLOW) &&
2848 (softc->quirks & DA_Q_NO_PREVENT) == 0) {
2850 xpt_print(ccb->ccb_h.path,
2851 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n");
2852 softc->quirks |= DA_Q_NO_PREVENT;
2856 /* Detect unsupported SYNCHRONIZE CACHE(10). */
2857 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 &&
2858 (*cdb == SYNCHRONIZE_CACHE) &&
2859 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) {
2861 xpt_print(ccb->ccb_h.path,
2862 "SYNCHRONIZE CACHE(10) not supported.\n");
2863 softc->quirks |= DA_Q_NO_SYNC_CACHE;
2864 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE;
2868 /* Translation only possible if CDB is an array and cmd is R/W6 */
2869 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 ||
2870 (*cdb != READ_6 && *cdb != WRITE_6))
2873 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, "
2874 "increasing minimum_cmd_size to 10.\n");
2875 softc->minimum_cmd_size = 10;
2877 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6));
2878 cmd10 = (struct scsi_rw_10 *)cdb;
2879 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10;
2881 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr);
2882 cmd10->reserved = 0;
2883 scsi_ulto2b(cmd6.length, cmd10->length);
2884 cmd10->control = cmd6.control;
2885 ccb->csio.cdb_len = sizeof(*cmd10);
2887 /* Requeue request, unfreezing queue if necessary */
2888 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0;
2889 ccb->ccb_h.status = CAM_REQUEUE_REQ;
2892 cam_release_devq(ccb->ccb_h.path,
2896 /*getcount_only*/0);
2902 dadone(struct cam_periph *periph, union ccb *done_ccb)
2904 struct da_softc *softc;
2905 struct ccb_scsiio *csio;
2909 softc = (struct da_softc *)periph->softc;
2910 priority = done_ccb->ccb_h.pinfo.priority;
2912 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n"));
2914 csio = &done_ccb->csio;
2915 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK;
2917 case DA_CCB_BUFFER_IO:
2920 struct bio *bp, *bp1;
2922 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2923 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
2927 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0)
2932 error = daerror(done_ccb, CAM_RETRY_SELTO, sf);
2933 if (error == ERESTART) {
2935 * A retry was scheduled, so
2940 bp = (struct bio *)done_ccb->ccb_h.ccb_bp;
2945 * return all queued I/O with EIO, so that
2946 * the client can retry these I/Os in the
2947 * proper order should it attempt to recover.
2952 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) {
2954 * Catastrophic error. Mark our pack as
2958 * XXX See if this is really a media
2961 xpt_print(periph->path,
2962 "Invalidating pack\n");
2963 softc->flags |= DA_FLAG_PACK_INVALID;
2964 queued_error = ENXIO;
2966 bioq_flush(&softc->bio_queue, NULL,
2969 bp->bio_error = error;
2970 bp->bio_resid = bp->bio_bcount;
2971 bp->bio_flags |= BIO_ERROR;
2973 } else if (bp != NULL) {
2974 if (state == DA_CCB_DELETE)
2977 bp->bio_resid = csio->resid;
2979 if (bp->bio_resid != 0)
2980 bp->bio_flags |= BIO_ERROR;
2982 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2983 cam_release_devq(done_ccb->ccb_h.path,
2987 /*getcount_only*/0);
2988 } else if (bp != NULL) {
2989 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
2990 panic("REQ_CMP with QFRZN");
2991 if (state == DA_CCB_DELETE)
2994 bp->bio_resid = csio->resid;
2995 if (csio->resid > 0)
2996 bp->bio_flags |= BIO_ERROR;
2997 if (softc->error_inject != 0) {
2998 bp->bio_error = softc->error_inject;
2999 bp->bio_resid = bp->bio_bcount;
3000 bp->bio_flags |= BIO_ERROR;
3001 softc->error_inject = 0;
3005 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le);
3006 if (LIST_EMPTY(&softc->pending_ccbs))
3007 softc->flags |= DA_FLAG_WAS_OTAG;
3009 if (state == DA_CCB_DELETE) {
3010 while ((bp1 = bioq_takefirst(&softc->delete_run_queue))
3012 bp1->bio_error = bp->bio_error;
3013 if (bp->bio_flags & BIO_ERROR) {
3014 bp1->bio_flags |= BIO_ERROR;
3015 bp1->bio_resid = bp1->bio_bcount;
3020 softc->delete_running = 0;
3024 } else if (bp != NULL)
3028 case DA_CCB_PROBE_RC:
3029 case DA_CCB_PROBE_RC16:
3031 struct scsi_read_capacity_data *rdcap;
3032 struct scsi_read_capacity_data_long *rcaplong;
3033 char announce_buf[80];
3039 if (state == DA_CCB_PROBE_RC)
3040 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr;
3042 rcaplong = (struct scsi_read_capacity_data_long *)
3045 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3046 struct disk_params *dp;
3047 uint32_t block_size;
3049 u_int lbppbe; /* LB per physical block exponent. */
3050 u_int lalba; /* Lowest aligned LBA. */
3052 if (state == DA_CCB_PROBE_RC) {
3053 block_size = scsi_4btoul(rdcap->length);
3054 maxsector = scsi_4btoul(rdcap->addr);
3059 * According to SBC-2, if the standard 10
3060 * byte READ CAPACITY command returns 2^32,
3061 * we should issue the 16 byte version of
3062 * the command, since the device in question
3063 * has more sectors than can be represented
3064 * with the short version of the command.
3066 if (maxsector == 0xffffffff) {
3067 free(rdcap, M_SCSIDA);
3068 xpt_release_ccb(done_ccb);
3069 softc->state = DA_STATE_PROBE_RC16;
3070 xpt_schedule(periph, priority);
3074 block_size = scsi_4btoul(rcaplong->length);
3075 maxsector = scsi_8btou64(rcaplong->addr);
3076 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3077 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3081 * Because GEOM code just will panic us if we
3082 * give them an 'illegal' value we'll avoid that
3085 if (block_size == 0 && maxsector == 0) {
3089 if (block_size >= MAXPHYS || block_size == 0) {
3090 xpt_print(periph->path,
3091 "unsupportable block size %ju\n",
3092 (uintmax_t) block_size);
3093 announce_buf[0] = '\0';
3094 cam_periph_invalidate(periph);
3097 * We pass rcaplong into dasetgeom(),
3098 * because it will only use it if it is
3101 dasetgeom(periph, block_size, maxsector,
3102 rcaplong, sizeof(*rcaplong));
3103 lbp = (lalba & SRC16_LBPME_A);
3104 dp = &softc->params;
3105 snprintf(announce_buf, sizeof(announce_buf),
3106 "%juMB (%ju %u byte sectors: %dH %dS/T "
3108 (((uintmax_t)dp->secsize *
3109 dp->sectors) / (1024*1024)),
3110 (uintmax_t)dp->sectors,
3111 dp->secsize, dp->heads,
3112 dp->secs_per_track, dp->cylinders);
3117 announce_buf[0] = '\0';
3120 * Retry any UNIT ATTENTION type errors. They
3121 * are expected at boot.
3123 error = daerror(done_ccb, CAM_RETRY_SELTO,
3124 SF_RETRY_UA|SF_NO_PRINT);
3125 if (error == ERESTART) {
3127 * A retry was scheuled, so
3131 } else if (error != 0) {
3133 int sense_key, error_code;
3136 struct ccb_getdev cgd;
3138 /* Don't wedge this device's queue */
3139 status = done_ccb->ccb_h.status;
3140 if ((status & CAM_DEV_QFRZN) != 0)
3141 cam_release_devq(done_ccb->ccb_h.path,
3145 /*getcount_only*/0);
3148 xpt_setup_ccb(&cgd.ccb_h,
3149 done_ccb->ccb_h.path,
3150 CAM_PRIORITY_NORMAL);
3151 cgd.ccb_h.func_code = XPT_GDEV_TYPE;
3152 xpt_action((union ccb *)&cgd);
3154 if (scsi_extract_sense_ccb(done_ccb,
3155 &error_code, &sense_key, &asc, &ascq))
3161 * If we tried READ CAPACITY(16) and failed,
3162 * fallback to READ CAPACITY(10).
3164 if ((state == DA_CCB_PROBE_RC16) &&
3165 (softc->flags & DA_FLAG_CAN_RC16) &&
3166 (((csio->ccb_h.status & CAM_STATUS_MASK) ==
3169 (error_code == SSD_CURRENT_ERROR) &&
3170 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) {
3171 softc->flags &= ~DA_FLAG_CAN_RC16;
3172 free(rdcap, M_SCSIDA);
3173 xpt_release_ccb(done_ccb);
3174 softc->state = DA_STATE_PROBE_RC;
3175 xpt_schedule(periph, priority);
3179 * Attach to anything that claims to be a
3180 * direct access or optical disk device,
3181 * as long as it doesn't return a "Logical
3182 * unit not supported" (0x25) error.
3184 if ((have_sense) && (asc != 0x25)
3185 && (error_code == SSD_CURRENT_ERROR)) {
3186 const char *sense_key_desc;
3187 const char *asc_desc;
3189 dasetgeom(periph, 512, -1, NULL, 0);
3190 scsi_sense_desc(sense_key, asc, ascq,
3194 snprintf(announce_buf,
3195 sizeof(announce_buf),
3196 "Attempt to query device "
3197 "size failed: %s, %s",
3205 xpt_print(periph->path,
3206 "got CAM status %#x\n",
3207 done_ccb->ccb_h.status);
3210 xpt_print(periph->path, "fatal error, "
3211 "failed to attach to device\n");
3214 * Free up resources.
3216 cam_periph_invalidate(periph);
3220 free(csio->data_ptr, M_SCSIDA);
3221 if (announce_buf[0] != '\0' &&
3222 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) {
3224 * Create our sysctl variables, now that we know
3225 * we have successfully attached.
3227 /* increase the refcount */
3228 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3229 taskqueue_enqueue(taskqueue_thread,
3230 &softc->sysctl_task);
3231 xpt_announce_periph(periph, announce_buf);
3232 xpt_announce_quirks(periph, softc->quirks,
3235 xpt_print(periph->path, "fatal error, "
3236 "could not acquire reference count\n");
3240 /* We already probed the device. */
3241 if (softc->flags & DA_FLAG_PROBED) {
3242 daprobedone(periph, done_ccb);
3246 /* Ensure re-probe doesn't see old delete. */
3247 softc->delete_available = 0;
3248 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) {
3250 * Based on older SBC-3 spec revisions
3251 * any of the UNMAP methods "may" be
3252 * available via LBP given this flag so
3253 * we flag all of them as availble and
3254 * then remove those which further
3255 * probes confirm aren't available
3258 * We could also check readcap(16) p_type
3259 * flag to exclude one or more invalid
3260 * write same (X) types here
3262 dadeleteflag(softc, DA_DELETE_WS16, 1);
3263 dadeleteflag(softc, DA_DELETE_WS10, 1);
3264 dadeleteflag(softc, DA_DELETE_ZERO, 1);
3265 dadeleteflag(softc, DA_DELETE_UNMAP, 1);
3267 xpt_release_ccb(done_ccb);
3268 softc->state = DA_STATE_PROBE_LBP;
3269 xpt_schedule(periph, priority);
3273 xpt_release_ccb(done_ccb);
3274 softc->state = DA_STATE_PROBE_BDC;
3275 xpt_schedule(periph, priority);
3278 case DA_CCB_PROBE_LBP:
3280 struct scsi_vpd_logical_block_prov *lbp;
3282 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr;
3284 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3286 * T10/1799-D Revision 31 states at least one of these
3287 * must be supported but we don't currently enforce this.
3289 dadeleteflag(softc, DA_DELETE_WS16,
3290 (lbp->flags & SVPD_LBP_WS16));
3291 dadeleteflag(softc, DA_DELETE_WS10,
3292 (lbp->flags & SVPD_LBP_WS10));
3293 dadeleteflag(softc, DA_DELETE_ZERO,
3294 (lbp->flags & SVPD_LBP_WS10));
3295 dadeleteflag(softc, DA_DELETE_UNMAP,
3296 (lbp->flags & SVPD_LBP_UNMAP));
3299 error = daerror(done_ccb, CAM_RETRY_SELTO,
3300 SF_RETRY_UA|SF_NO_PRINT);
3301 if (error == ERESTART)
3303 else if (error != 0) {
3304 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3305 /* Don't wedge this device's queue */
3306 cam_release_devq(done_ccb->ccb_h.path,
3310 /*getcount_only*/0);
3314 * Failure indicates we don't support any SBC-3
3315 * delete methods with UNMAP
3320 free(lbp, M_SCSIDA);
3321 xpt_release_ccb(done_ccb);
3322 softc->state = DA_STATE_PROBE_BLK_LIMITS;
3323 xpt_schedule(periph, priority);
3326 case DA_CCB_PROBE_BLK_LIMITS:
3328 struct scsi_vpd_block_limits *block_limits;
3330 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr;
3332 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3333 uint32_t max_txfer_len = scsi_4btoul(
3334 block_limits->max_txfer_len);
3335 uint32_t max_unmap_lba_cnt = scsi_4btoul(
3336 block_limits->max_unmap_lba_cnt);
3337 uint32_t max_unmap_blk_cnt = scsi_4btoul(
3338 block_limits->max_unmap_blk_cnt);
3339 uint64_t ws_max_blks = scsi_8btou64(
3340 block_limits->max_write_same_length);
3342 if (max_txfer_len != 0) {
3343 softc->disk->d_maxsize = MIN(softc->maxio,
3344 (off_t)max_txfer_len * softc->params.secsize);
3348 * We should already support UNMAP but we check lba
3349 * and block count to be sure
3351 if (max_unmap_lba_cnt != 0x00L &&
3352 max_unmap_blk_cnt != 0x00L) {
3353 softc->unmap_max_lba = max_unmap_lba_cnt;
3354 softc->unmap_max_ranges = min(max_unmap_blk_cnt,
3358 * Unexpected UNMAP limits which means the
3359 * device doesn't actually support UNMAP
3361 dadeleteflag(softc, DA_DELETE_UNMAP, 0);
3364 if (ws_max_blks != 0x00L)
3365 softc->ws_max_blks = ws_max_blks;
3368 error = daerror(done_ccb, CAM_RETRY_SELTO,
3369 SF_RETRY_UA|SF_NO_PRINT);
3370 if (error == ERESTART)
3372 else if (error != 0) {
3373 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3374 /* Don't wedge this device's queue */
3375 cam_release_devq(done_ccb->ccb_h.path,
3379 /*getcount_only*/0);
3383 * Failure here doesn't mean UNMAP is not
3384 * supported as this is an optional page.
3386 softc->unmap_max_lba = 1;
3387 softc->unmap_max_ranges = 1;
3391 free(block_limits, M_SCSIDA);
3392 xpt_release_ccb(done_ccb);
3393 softc->state = DA_STATE_PROBE_BDC;
3394 xpt_schedule(periph, priority);
3397 case DA_CCB_PROBE_BDC:
3399 struct scsi_vpd_block_characteristics *bdc;
3401 bdc = (struct scsi_vpd_block_characteristics *)csio->data_ptr;
3403 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3405 * Disable queue sorting for non-rotational media
3408 if (scsi_2btoul(bdc->medium_rotation_rate) ==
3409 SVPD_BDC_RATE_NONE_ROTATING)
3410 softc->sort_io_queue = 0;
3413 error = daerror(done_ccb, CAM_RETRY_SELTO,
3414 SF_RETRY_UA|SF_NO_PRINT);
3415 if (error == ERESTART)
3417 else if (error != 0) {
3418 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3419 /* Don't wedge this device's queue */
3420 cam_release_devq(done_ccb->ccb_h.path,
3424 /*getcount_only*/0);
3429 free(bdc, M_SCSIDA);
3430 xpt_release_ccb(done_ccb);
3431 softc->state = DA_STATE_PROBE_ATA;
3432 xpt_schedule(periph, priority);
3435 case DA_CCB_PROBE_ATA:
3438 struct ata_params *ata_params;
3441 ata_params = (struct ata_params *)csio->data_ptr;
3442 ptr = (uint16_t *)ata_params;
3444 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) {
3445 for (i = 0; i < sizeof(*ata_params) / 2; i++)
3446 ptr[i] = le16toh(ptr[i]);
3447 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM &&
3448 (softc->quirks & DA_Q_NO_UNMAP) == 0) {
3449 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1);
3450 if (ata_params->max_dsm_blocks != 0)
3451 softc->trim_max_ranges = min(
3452 softc->trim_max_ranges,
3453 ata_params->max_dsm_blocks *
3454 ATA_DSM_BLK_RANGES);
3457 * Disable queue sorting for non-rotational media
3460 if (ata_params->media_rotation_rate == 1)
3461 softc->sort_io_queue = 0;
3464 error = daerror(done_ccb, CAM_RETRY_SELTO,
3465 SF_RETRY_UA|SF_NO_PRINT);
3466 if (error == ERESTART)
3468 else if (error != 0) {
3469 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) {
3470 /* Don't wedge this device's queue */
3471 cam_release_devq(done_ccb->ccb_h.path,
3475 /*getcount_only*/0);
3480 free(ata_params, M_SCSIDA);
3481 daprobedone(periph, done_ccb);
3484 case DA_CCB_WAITING:
3486 /* Caller will release the CCB */
3487 wakeup(&done_ccb->ccb_h.cbfcnp);
3491 /* No-op. We're polling */
3495 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3497 if (daerror(done_ccb, CAM_RETRY_SELTO,
3498 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) ==
3501 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0)
3502 cam_release_devq(done_ccb->ccb_h.path,
3506 /*getcount_only*/0);
3508 xpt_release_ccb(done_ccb);
3509 cam_periph_release_locked(periph);
3515 xpt_release_ccb(done_ccb);
3519 dareprobe(struct cam_periph *periph)
3521 struct da_softc *softc;
3524 softc = (struct da_softc *)periph->softc;
3526 /* Probe in progress; don't interfere. */
3527 if (softc->state != DA_STATE_NORMAL)
3530 status = cam_periph_acquire(periph);
3531 KASSERT(status == CAM_REQ_CMP,
3532 ("dareprobe: cam_periph_acquire failed"));
3534 if (softc->flags & DA_FLAG_CAN_RC16)
3535 softc->state = DA_STATE_PROBE_RC16;
3537 softc->state = DA_STATE_PROBE_RC;
3539 xpt_schedule(periph, CAM_PRIORITY_DEV);
3543 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags)
3545 struct da_softc *softc;
3546 struct cam_periph *periph;
3547 int error, error_code, sense_key, asc, ascq;
3549 periph = xpt_path_periph(ccb->ccb_h.path);
3550 softc = (struct da_softc *)periph->softc;
3553 * Automatically detect devices that do not support
3554 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs.
3557 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) {
3558 error = cmd6workaround(ccb);
3559 } else if (scsi_extract_sense_ccb(ccb,
3560 &error_code, &sense_key, &asc, &ascq)) {
3561 if (sense_key == SSD_KEY_ILLEGAL_REQUEST)
3562 error = cmd6workaround(ccb);
3564 * If the target replied with CAPACITY DATA HAS CHANGED UA,
3565 * query the capacity and notify upper layers.
3567 else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3568 asc == 0x2A && ascq == 0x09) {
3569 xpt_print(periph->path, "Capacity data has changed\n");
3570 softc->flags &= ~DA_FLAG_PROBED;
3572 sense_flags |= SF_NO_PRINT;
3573 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3574 asc == 0x28 && ascq == 0x00) {
3575 softc->flags &= ~DA_FLAG_PROBED;
3576 disk_media_changed(softc->disk, M_NOWAIT);
3577 } else if (sense_key == SSD_KEY_UNIT_ATTENTION &&
3578 asc == 0x3F && ascq == 0x03) {
3579 xpt_print(periph->path, "INQUIRY data has changed\n");
3580 softc->flags &= ~DA_FLAG_PROBED;
3582 sense_flags |= SF_NO_PRINT;
3583 } else if (sense_key == SSD_KEY_NOT_READY &&
3584 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) {
3585 softc->flags |= DA_FLAG_PACK_INVALID;
3586 disk_media_gone(softc->disk, M_NOWAIT);
3589 if (error == ERESTART)
3594 * Until we have a better way of doing pack validation,
3595 * don't treat UAs as errors.
3597 sense_flags |= SF_RETRY_UA;
3598 return(cam_periph_error(ccb, cam_flags, sense_flags,
3599 &softc->saved_ccb));
3603 damediapoll(void *arg)
3605 struct cam_periph *periph = arg;
3606 struct da_softc *softc = periph->softc;
3608 if (!softc->tur && LIST_EMPTY(&softc->pending_ccbs)) {
3609 if (cam_periph_acquire(periph) == CAM_REQ_CMP) {
3614 /* Queue us up again */
3615 if (da_poll_period != 0)
3616 callout_schedule(&softc->mediapoll_c, da_poll_period * hz);
3620 daprevent(struct cam_periph *periph, int action)
3622 struct da_softc *softc;
3626 softc = (struct da_softc *)periph->softc;
3628 if (((action == PR_ALLOW)
3629 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0)
3630 || ((action == PR_PREVENT)
3631 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) {
3635 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3637 scsi_prevent(&ccb->csio,
3645 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO,
3646 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat);
3649 if (action == PR_ALLOW)
3650 softc->flags &= ~DA_FLAG_PACK_LOCKED;
3652 softc->flags |= DA_FLAG_PACK_LOCKED;
3655 xpt_release_ccb(ccb);
3659 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector,
3660 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len)
3662 struct ccb_calc_geometry ccg;
3663 struct da_softc *softc;
3664 struct disk_params *dp;
3665 u_int lbppbe, lalba;
3667 softc = (struct da_softc *)periph->softc;
3669 dp = &softc->params;
3670 dp->secsize = block_len;
3671 dp->sectors = maxsector + 1;
3672 if (rcaplong != NULL) {
3673 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE;
3674 lalba = scsi_2btoul(rcaplong->lalba_lbp);
3675 lalba &= SRC16_LALBA_A;
3682 dp->stripesize = block_len << lbppbe;
3683 dp->stripeoffset = (dp->stripesize - block_len * lalba) %
3685 } else if (softc->quirks & DA_Q_4K) {
3686 dp->stripesize = 4096;
3687 dp->stripeoffset = 0;
3690 dp->stripeoffset = 0;
3693 * Have the controller provide us with a geometry
3694 * for this disk. The only time the geometry
3695 * matters is when we boot and the controller
3696 * is the only one knowledgeable enough to come
3697 * up with something that will make this a bootable
3700 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3701 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY;
3702 ccg.block_size = dp->secsize;
3703 ccg.volume_size = dp->sectors;
3705 ccg.secs_per_track = 0;
3707 xpt_action((union ccb*)&ccg);
3708 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) {
3710 * We don't know what went wrong here- but just pick
3711 * a geometry so we don't have nasty things like divide
3715 dp->secs_per_track = 255;
3716 dp->cylinders = dp->sectors / (255 * 255);
3717 if (dp->cylinders == 0) {
3721 dp->heads = ccg.heads;
3722 dp->secs_per_track = ccg.secs_per_track;
3723 dp->cylinders = ccg.cylinders;
3727 * If the user supplied a read capacity buffer, and if it is
3728 * different than the previous buffer, update the data in the EDT.
3729 * If it's the same, we don't bother. This avoids sending an
3730 * update every time someone opens this device.
3732 if ((rcaplong != NULL)
3733 && (bcmp(rcaplong, &softc->rcaplong,
3734 min(sizeof(softc->rcaplong), rcap_len)) != 0)) {
3735 struct ccb_dev_advinfo cdai;
3737 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL);
3738 cdai.ccb_h.func_code = XPT_DEV_ADVINFO;
3739 cdai.buftype = CDAI_TYPE_RCAPLONG;
3740 cdai.flags |= CDAI_FLAG_STORE;
3741 cdai.bufsiz = rcap_len;
3742 cdai.buf = (uint8_t *)rcaplong;
3743 xpt_action((union ccb *)&cdai);
3744 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0)
3745 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE);
3746 if (cdai.ccb_h.status != CAM_REQ_CMP) {
3747 xpt_print(periph->path, "%s: failed to set read "
3748 "capacity advinfo\n", __func__);
3749 /* Use cam_error_print() to decode the status */
3750 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS,
3753 bcopy(rcaplong, &softc->rcaplong,
3754 min(sizeof(softc->rcaplong), rcap_len));
3758 softc->disk->d_sectorsize = softc->params.secsize;
3759 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors;
3760 softc->disk->d_stripesize = softc->params.stripesize;
3761 softc->disk->d_stripeoffset = softc->params.stripeoffset;
3762 /* XXX: these are not actually "firmware" values, so they may be wrong */
3763 softc->disk->d_fwsectors = softc->params.secs_per_track;
3764 softc->disk->d_fwheads = softc->params.heads;
3765 softc->disk->d_devstat->block_size = softc->params.secsize;
3766 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE;
3770 dasendorderedtag(void *arg)
3772 struct da_softc *softc = arg;
3774 if (da_send_ordered) {
3775 if (!LIST_EMPTY(&softc->pending_ccbs)) {
3776 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0)
3777 softc->flags |= DA_FLAG_NEED_OTAG;
3778 softc->flags &= ~DA_FLAG_WAS_OTAG;
3781 /* Queue us up again */
3782 callout_reset(&softc->sendordered_c,
3783 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL,
3784 dasendorderedtag, softc);
3788 * Step through all DA peripheral drivers, and if the device is still open,
3789 * sync the disk cache to physical media.
3792 dashutdown(void * arg, int howto)
3794 struct cam_periph *periph;
3795 struct da_softc *softc;
3799 CAM_PERIPH_FOREACH(periph, &dadriver) {
3800 softc = (struct da_softc *)periph->softc;
3801 if (SCHEDULER_STOPPED()) {
3802 /* If we paniced with the lock held, do not recurse. */
3803 if (!cam_periph_owned(periph) &&
3804 (softc->flags & DA_FLAG_OPEN)) {
3805 dadump(softc->disk, NULL, 0, 0, 0);
3809 cam_periph_lock(periph);
3812 * We only sync the cache if the drive is still open, and
3813 * if the drive is capable of it..
3815 if (((softc->flags & DA_FLAG_OPEN) == 0)
3816 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) {
3817 cam_periph_unlock(periph);
3821 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL);
3822 scsi_synchronize_cache(&ccb->csio,
3826 /*begin_lba*/0, /* whole disk */
3831 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0,
3832 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR,
3833 softc->disk->d_devstat);
3835 xpt_print(periph->path, "Synchronize cache failed\n");
3836 xpt_release_ccb(ccb);
3837 cam_periph_unlock(periph);
3841 #else /* !_KERNEL */
3844 * XXX This is only left out of the kernel build to silence warnings. If,
3845 * for some reason this function is used in the kernel, the ifdefs should
3846 * be moved so it is included both in the kernel and userland.
3849 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries,
3850 void (*cbfcnp)(struct cam_periph *, union ccb *),
3851 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave,
3852 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3855 struct scsi_format_unit *scsi_cmd;
3857 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes;
3858 scsi_cmd->opcode = FORMAT_UNIT;
3859 scsi_cmd->byte2 = byte2;
3860 scsi_ulto2b(ileave, scsi_cmd->interleave);
3865 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3875 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries,
3876 void (*cbfcnp)(struct cam_periph *, union ccb *),
3877 u_int8_t tag_action, u_int8_t byte2, u_int16_t control,
3878 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len,
3881 struct scsi_sanitize *scsi_cmd;
3883 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes;
3884 scsi_cmd->opcode = SANITIZE;
3885 scsi_cmd->byte2 = byte2;
3886 scsi_cmd->control = control;
3887 scsi_ulto2b(dxfer_len, scsi_cmd->length);
3892 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE,
3901 #endif /* _KERNEL */