1 /*- 2 * Implementation of SCSI Direct Access Peripheral driver for CAM. 3 * 4 * Copyright (c) 1997 Justin T. Gibbs. 5 * All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 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. 15 * 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 26 * SUCH DAMAGE. 27 */ 28 29 #include <sys/cdefs.h> 30 __FBSDID("$FreeBSD$"); 31 32 #include <sys/param.h> 33 34 #ifdef _KERNEL 35 #include <sys/systm.h> 36 #include <sys/kernel.h> 37 #include <sys/bio.h> 38 #include <sys/sysctl.h> 39 #include <sys/taskqueue.h> 40 #include <sys/lock.h> 41 #include <sys/mutex.h> 42 #include <sys/conf.h> 43 #include <sys/devicestat.h> 44 #include <sys/eventhandler.h> 45 #include <sys/malloc.h> 46 #include <sys/cons.h> 47 #include <sys/endian.h> 48 #include <sys/proc.h> 49 #include <sys/sbuf.h> 50 #include <geom/geom.h> 51 #include <geom/geom_disk.h> 52 #endif /* _KERNEL */ 53 54 #ifndef _KERNEL 55 #include <stdio.h> 56 #include <string.h> 57 #endif /* _KERNEL */ 58 59 #include <cam/cam.h> 60 #include <cam/cam_ccb.h> 61 #include <cam/cam_periph.h> 62 #include <cam/cam_xpt_periph.h> 63 #include <cam/cam_sim.h> 64 #include <cam/cam_iosched.h> 65 66 #include <cam/scsi/scsi_message.h> 67 #include <cam/scsi/scsi_da.h> 68 69 #ifdef _KERNEL 70 /* 71 * Note that there are probe ordering dependencies here. The order isn't 72 * controlled by this enumeration, but by explicit state transitions in 73 * dastart() and dadone(). Here are some of the dependencies: 74 * 75 * 1. RC should come first, before RC16, unless there is evidence that RC16 76 * is supported. 77 * 2. BDC needs to come before any of the ATA probes, or the ZONE probe. 78 * 3. The ATA probes should go in this order: 79 * ATA -> LOGDIR -> IDDIR -> SUP -> ATA_ZONE 80 */ 81 typedef enum { 82 DA_STATE_PROBE_RC, 83 DA_STATE_PROBE_RC16, 84 DA_STATE_PROBE_LBP, 85 DA_STATE_PROBE_BLK_LIMITS, 86 DA_STATE_PROBE_BDC, 87 DA_STATE_PROBE_ATA, 88 DA_STATE_PROBE_ATA_LOGDIR, 89 DA_STATE_PROBE_ATA_IDDIR, 90 DA_STATE_PROBE_ATA_SUP, 91 DA_STATE_PROBE_ATA_ZONE, 92 DA_STATE_PROBE_ZONE, 93 DA_STATE_NORMAL 94 } da_state; 95 96 typedef enum { 97 DA_FLAG_PACK_INVALID = 0x000001, 98 DA_FLAG_NEW_PACK = 0x000002, 99 DA_FLAG_PACK_LOCKED = 0x000004, 100 DA_FLAG_PACK_REMOVABLE = 0x000008, 101 DA_FLAG_NEED_OTAG = 0x000020, 102 DA_FLAG_WAS_OTAG = 0x000040, 103 DA_FLAG_RETRY_UA = 0x000080, 104 DA_FLAG_OPEN = 0x000100, 105 DA_FLAG_SCTX_INIT = 0x000200, 106 DA_FLAG_CAN_RC16 = 0x000400, 107 DA_FLAG_PROBED = 0x000800, 108 DA_FLAG_DIRTY = 0x001000, 109 DA_FLAG_ANNOUNCED = 0x002000, 110 DA_FLAG_CAN_ATA_DMA = 0x004000, 111 DA_FLAG_CAN_ATA_LOG = 0x008000, 112 DA_FLAG_CAN_ATA_IDLOG = 0x010000, 113 DA_FLAG_CAN_ATA_SUPCAP = 0x020000, 114 DA_FLAG_CAN_ATA_ZONE = 0x040000 115 } da_flags; 116 117 typedef enum { 118 DA_Q_NONE = 0x00, 119 DA_Q_NO_SYNC_CACHE = 0x01, 120 DA_Q_NO_6_BYTE = 0x02, 121 DA_Q_NO_PREVENT = 0x04, 122 DA_Q_4K = 0x08, 123 DA_Q_NO_RC16 = 0x10, 124 DA_Q_NO_UNMAP = 0x20, 125 DA_Q_RETRY_BUSY = 0x40, 126 DA_Q_SMR_DM = 0x80, 127 DA_Q_STRICT_UNMAP = 0x100 128 } da_quirks; 129 130 #define DA_Q_BIT_STRING \ 131 "\020" \ 132 "\001NO_SYNC_CACHE" \ 133 "\002NO_6_BYTE" \ 134 "\003NO_PREVENT" \ 135 "\0044K" \ 136 "\005NO_RC16" \ 137 "\006NO_UNMAP" \ 138 "\007RETRY_BUSY" \ 139 "\010SMR_DM" \ 140 "\011STRICT_UNMAP" 141 142 typedef enum { 143 DA_CCB_PROBE_RC = 0x01, 144 DA_CCB_PROBE_RC16 = 0x02, 145 DA_CCB_PROBE_LBP = 0x03, 146 DA_CCB_PROBE_BLK_LIMITS = 0x04, 147 DA_CCB_PROBE_BDC = 0x05, 148 DA_CCB_PROBE_ATA = 0x06, 149 DA_CCB_BUFFER_IO = 0x07, 150 DA_CCB_DUMP = 0x0A, 151 DA_CCB_DELETE = 0x0B, 152 DA_CCB_TUR = 0x0C, 153 DA_CCB_PROBE_ZONE = 0x0D, 154 DA_CCB_PROBE_ATA_LOGDIR = 0x0E, 155 DA_CCB_PROBE_ATA_IDDIR = 0x0F, 156 DA_CCB_PROBE_ATA_SUP = 0x10, 157 DA_CCB_PROBE_ATA_ZONE = 0x11, 158 DA_CCB_TYPE_MASK = 0x1F, 159 DA_CCB_RETRY_UA = 0x20 160 } da_ccb_state; 161 162 /* 163 * Order here is important for method choice 164 * 165 * We prefer ATA_TRIM as tests run against a Sandforce 2281 SSD attached to 166 * LSI 2008 (mps) controller (FW: v12, Drv: v14) resulted 20% quicker deletes 167 * using ATA_TRIM than the corresponding UNMAP results for a real world mysql 168 * import taking 5mins. 169 * 170 */ 171 typedef enum { 172 DA_DELETE_NONE, 173 DA_DELETE_DISABLE, 174 DA_DELETE_ATA_TRIM, 175 DA_DELETE_UNMAP, 176 DA_DELETE_WS16, 177 DA_DELETE_WS10, 178 DA_DELETE_ZERO, 179 DA_DELETE_MIN = DA_DELETE_ATA_TRIM, 180 DA_DELETE_MAX = DA_DELETE_ZERO 181 } da_delete_methods; 182 183 /* 184 * For SCSI, host managed drives show up as a separate device type. For 185 * ATA, host managed drives also have a different device signature. 186 * XXX KDM figure out the ATA host managed signature. 187 */ 188 typedef enum { 189 DA_ZONE_NONE = 0x00, 190 DA_ZONE_DRIVE_MANAGED = 0x01, 191 DA_ZONE_HOST_AWARE = 0x02, 192 DA_ZONE_HOST_MANAGED = 0x03 193 } da_zone_mode; 194 195 /* 196 * We distinguish between these interface cases in addition to the drive type: 197 * o ATA drive behind a SCSI translation layer that knows about ZBC/ZAC 198 * o ATA drive behind a SCSI translation layer that does not know about 199 * ZBC/ZAC, and so needs to be managed via ATA passthrough. In this 200 * case, we would need to share the ATA code with the ada(4) driver. 201 * o SCSI drive. 202 */ 203 typedef enum { 204 DA_ZONE_IF_SCSI, 205 DA_ZONE_IF_ATA_PASS, 206 DA_ZONE_IF_ATA_SAT, 207 } da_zone_interface; 208 209 typedef enum { 210 DA_ZONE_FLAG_RZ_SUP = 0x0001, 211 DA_ZONE_FLAG_OPEN_SUP = 0x0002, 212 DA_ZONE_FLAG_CLOSE_SUP = 0x0004, 213 DA_ZONE_FLAG_FINISH_SUP = 0x0008, 214 DA_ZONE_FLAG_RWP_SUP = 0x0010, 215 DA_ZONE_FLAG_SUP_MASK = (DA_ZONE_FLAG_RZ_SUP | 216 DA_ZONE_FLAG_OPEN_SUP | 217 DA_ZONE_FLAG_CLOSE_SUP | 218 DA_ZONE_FLAG_FINISH_SUP | 219 DA_ZONE_FLAG_RWP_SUP), 220 DA_ZONE_FLAG_URSWRZ = 0x0020, 221 DA_ZONE_FLAG_OPT_SEQ_SET = 0x0040, 222 DA_ZONE_FLAG_OPT_NONSEQ_SET = 0x0080, 223 DA_ZONE_FLAG_MAX_SEQ_SET = 0x0100, 224 DA_ZONE_FLAG_SET_MASK = (DA_ZONE_FLAG_OPT_SEQ_SET | 225 DA_ZONE_FLAG_OPT_NONSEQ_SET | 226 DA_ZONE_FLAG_MAX_SEQ_SET) 227 } da_zone_flags; 228 229 static struct da_zone_desc { 230 da_zone_flags value; 231 const char *desc; 232 } da_zone_desc_table[] = { 233 {DA_ZONE_FLAG_RZ_SUP, "Report Zones" }, 234 {DA_ZONE_FLAG_OPEN_SUP, "Open" }, 235 {DA_ZONE_FLAG_CLOSE_SUP, "Close" }, 236 {DA_ZONE_FLAG_FINISH_SUP, "Finish" }, 237 {DA_ZONE_FLAG_RWP_SUP, "Reset Write Pointer" }, 238 }; 239 240 typedef void da_delete_func_t (struct cam_periph *periph, union ccb *ccb, 241 struct bio *bp); 242 static da_delete_func_t da_delete_trim; 243 static da_delete_func_t da_delete_unmap; 244 static da_delete_func_t da_delete_ws; 245 246 static const void * da_delete_functions[] = { 247 NULL, 248 NULL, 249 da_delete_trim, 250 da_delete_unmap, 251 da_delete_ws, 252 da_delete_ws, 253 da_delete_ws 254 }; 255 256 static const char *da_delete_method_names[] = 257 { "NONE", "DISABLE", "ATA_TRIM", "UNMAP", "WS16", "WS10", "ZERO" }; 258 static const char *da_delete_method_desc[] = 259 { "NONE", "DISABLED", "ATA TRIM", "UNMAP", "WRITE SAME(16) with UNMAP", 260 "WRITE SAME(10) with UNMAP", "ZERO" }; 261 262 /* Offsets into our private area for storing information */ 263 #define ccb_state ppriv_field0 264 #define ccb_bp ppriv_ptr1 265 266 struct disk_params { 267 u_int8_t heads; 268 u_int32_t cylinders; 269 u_int8_t secs_per_track; 270 u_int32_t secsize; /* Number of bytes/sector */ 271 u_int64_t sectors; /* total number sectors */ 272 u_int stripesize; 273 u_int stripeoffset; 274 }; 275 276 #define UNMAP_RANGE_MAX 0xffffffff 277 #define UNMAP_HEAD_SIZE 8 278 #define UNMAP_RANGE_SIZE 16 279 #define UNMAP_MAX_RANGES 2048 /* Protocol Max is 4095 */ 280 #define UNMAP_BUF_SIZE ((UNMAP_MAX_RANGES * UNMAP_RANGE_SIZE) + \ 281 UNMAP_HEAD_SIZE) 282 283 #define WS10_MAX_BLKS 0xffff 284 #define WS16_MAX_BLKS 0xffffffff 285 #define ATA_TRIM_MAX_RANGES ((UNMAP_BUF_SIZE / \ 286 (ATA_DSM_RANGE_SIZE * ATA_DSM_BLK_SIZE)) * ATA_DSM_BLK_SIZE) 287 288 #define DA_WORK_TUR (1 << 16) 289 290 struct da_softc { 291 struct cam_iosched_softc *cam_iosched; 292 struct bio_queue_head delete_run_queue; 293 LIST_HEAD(, ccb_hdr) pending_ccbs; 294 int refcount; /* Active xpt_action() calls */ 295 da_state state; 296 da_flags flags; 297 da_quirks quirks; 298 int minimum_cmd_size; 299 int error_inject; 300 int trim_max_ranges; 301 int delete_available; /* Delete methods possibly available */ 302 da_zone_mode zone_mode; 303 da_zone_interface zone_interface; 304 da_zone_flags zone_flags; 305 struct ata_gp_log_dir ata_logdir; 306 int valid_logdir_len; 307 struct ata_identify_log_pages ata_iddir; 308 int valid_iddir_len; 309 uint64_t optimal_seq_zones; 310 uint64_t optimal_nonseq_zones; 311 uint64_t max_seq_zones; 312 u_int maxio; 313 uint32_t unmap_max_ranges; 314 uint32_t unmap_max_lba; /* Max LBAs in UNMAP req */ 315 uint32_t unmap_gran; 316 uint32_t unmap_gran_align; 317 uint64_t ws_max_blks; 318 da_delete_methods delete_method_pref; 319 da_delete_methods delete_method; 320 da_delete_func_t *delete_func; 321 int unmappedio; 322 int rotating; 323 struct disk_params params; 324 struct disk *disk; 325 union ccb saved_ccb; 326 struct task sysctl_task; 327 struct sysctl_ctx_list sysctl_ctx; 328 struct sysctl_oid *sysctl_tree; 329 struct callout sendordered_c; 330 uint64_t wwpn; 331 uint8_t unmap_buf[UNMAP_BUF_SIZE]; 332 struct scsi_read_capacity_data_long rcaplong; 333 struct callout mediapoll_c; 334 #ifdef CAM_IO_STATS 335 struct sysctl_ctx_list sysctl_stats_ctx; 336 struct sysctl_oid *sysctl_stats_tree; 337 u_int errors; 338 u_int timeouts; 339 u_int invalidations; 340 #endif 341 #define DA_ANNOUNCETMP_SZ 80 342 char announce_temp[DA_ANNOUNCETMP_SZ]; 343 #define DA_ANNOUNCE_SZ 400 344 char announcebuf[DA_ANNOUNCE_SZ]; 345 }; 346 347 #define dadeleteflag(softc, delete_method, enable) \ 348 if (enable) { \ 349 softc->delete_available |= (1 << delete_method); \ 350 } else { \ 351 softc->delete_available &= ~(1 << delete_method); \ 352 } 353 354 struct da_quirk_entry { 355 struct scsi_inquiry_pattern inq_pat; 356 da_quirks quirks; 357 }; 358 359 static const char quantum[] = "QUANTUM"; 360 static const char microp[] = "MICROP"; 361 362 static struct da_quirk_entry da_quirk_table[] = 363 { 364 /* SPI, FC devices */ 365 { 366 /* 367 * Fujitsu M2513A MO drives. 368 * Tested devices: M2513A2 firmware versions 1200 & 1300. 369 * (dip switch selects whether T_DIRECT or T_OPTICAL device) 370 * Reported by: W.Scholten <whs@xs4all.nl> 371 */ 372 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"}, 373 /*quirks*/ DA_Q_NO_SYNC_CACHE 374 }, 375 { 376 /* See above. */ 377 {T_OPTICAL, SIP_MEDIA_REMOVABLE, "FUJITSU", "M2513A", "*"}, 378 /*quirks*/ DA_Q_NO_SYNC_CACHE 379 }, 380 { 381 /* 382 * This particular Fujitsu drive doesn't like the 383 * synchronize cache command. 384 * Reported by: Tom Jackson <toj@gorilla.net> 385 */ 386 {T_DIRECT, SIP_MEDIA_FIXED, "FUJITSU", "M2954*", "*"}, 387 /*quirks*/ DA_Q_NO_SYNC_CACHE 388 }, 389 { 390 /* 391 * This drive doesn't like the synchronize cache command 392 * either. Reported by: Matthew Jacob <mjacob@feral.com> 393 * in NetBSD PR kern/6027, August 24, 1998. 394 */ 395 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2217*", "*"}, 396 /*quirks*/ DA_Q_NO_SYNC_CACHE 397 }, 398 { 399 /* 400 * This drive doesn't like the synchronize cache command 401 * either. Reported by: Hellmuth Michaelis (hm@kts.org) 402 * (PR 8882). 403 */ 404 {T_DIRECT, SIP_MEDIA_FIXED, microp, "2112*", "*"}, 405 /*quirks*/ DA_Q_NO_SYNC_CACHE 406 }, 407 { 408 /* 409 * Doesn't like the synchronize cache command. 410 * Reported by: Blaz Zupan <blaz@gold.amis.net> 411 */ 412 {T_DIRECT, SIP_MEDIA_FIXED, "NEC", "D3847*", "*"}, 413 /*quirks*/ DA_Q_NO_SYNC_CACHE 414 }, 415 { 416 /* 417 * Doesn't like the synchronize cache command. 418 * Reported by: Blaz Zupan <blaz@gold.amis.net> 419 */ 420 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "MAVERICK 540S", "*"}, 421 /*quirks*/ DA_Q_NO_SYNC_CACHE 422 }, 423 { 424 /* 425 * Doesn't like the synchronize cache command. 426 */ 427 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS525S", "*"}, 428 /*quirks*/ DA_Q_NO_SYNC_CACHE 429 }, 430 { 431 /* 432 * Doesn't like the synchronize cache command. 433 * Reported by: walter@pelissero.de 434 */ 435 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "LPS540S", "*"}, 436 /*quirks*/ DA_Q_NO_SYNC_CACHE 437 }, 438 { 439 /* 440 * Doesn't work correctly with 6 byte reads/writes. 441 * Returns illegal request, and points to byte 9 of the 442 * 6-byte CDB. 443 * Reported by: Adam McDougall <bsdx@spawnet.com> 444 */ 445 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 4*", "*"}, 446 /*quirks*/ DA_Q_NO_6_BYTE 447 }, 448 { 449 /* See above. */ 450 {T_DIRECT, SIP_MEDIA_FIXED, quantum, "VIKING 2*", "*"}, 451 /*quirks*/ DA_Q_NO_6_BYTE 452 }, 453 { 454 /* 455 * Doesn't like the synchronize cache command. 456 * Reported by: walter@pelissero.de 457 */ 458 {T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CP3500*", "*"}, 459 /*quirks*/ DA_Q_NO_SYNC_CACHE 460 }, 461 { 462 /* 463 * The CISS RAID controllers do not support SYNC_CACHE 464 */ 465 {T_DIRECT, SIP_MEDIA_FIXED, "COMPAQ", "RAID*", "*"}, 466 /*quirks*/ DA_Q_NO_SYNC_CACHE 467 }, 468 { 469 /* 470 * The STEC SSDs sometimes hang on UNMAP. 471 */ 472 {T_DIRECT, SIP_MEDIA_FIXED, "STEC", "*", "*"}, 473 /*quirks*/ DA_Q_NO_UNMAP 474 }, 475 { 476 /* 477 * VMware returns BUSY status when storage has transient 478 * connectivity problems, so better wait. 479 * Also VMware returns odd errors on misaligned UNMAPs. 480 */ 481 {T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*"}, 482 /*quirks*/ DA_Q_RETRY_BUSY | DA_Q_STRICT_UNMAP 483 }, 484 /* USB mass storage devices supported by umass(4) */ 485 { 486 /* 487 * EXATELECOM (Sigmatel) i-Bead 100/105 USB Flash MP3 Player 488 * PR: kern/51675 489 */ 490 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EXATEL", "i-BEAD10*", "*"}, 491 /*quirks*/ DA_Q_NO_SYNC_CACHE 492 }, 493 { 494 /* 495 * Power Quotient Int. (PQI) USB flash key 496 * PR: kern/53067 497 */ 498 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "USB Flash Disk*", 499 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 500 }, 501 { 502 /* 503 * Creative Nomad MUVO mp3 player (USB) 504 * PR: kern/53094 505 */ 506 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "NOMAD_MUVO", "*"}, 507 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT 508 }, 509 { 510 /* 511 * Jungsoft NEXDISK USB flash key 512 * PR: kern/54737 513 */ 514 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JUNGSOFT", "NEXDISK*", "*"}, 515 /*quirks*/ DA_Q_NO_SYNC_CACHE 516 }, 517 { 518 /* 519 * FreeDik USB Mini Data Drive 520 * PR: kern/54786 521 */ 522 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FreeDik*", "Mini Data Drive", 523 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 524 }, 525 { 526 /* 527 * Sigmatel USB Flash MP3 Player 528 * PR: kern/57046 529 */ 530 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SigmaTel", "MSCN", "*"}, 531 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT 532 }, 533 { 534 /* 535 * Neuros USB Digital Audio Computer 536 * PR: kern/63645 537 */ 538 {T_DIRECT, SIP_MEDIA_REMOVABLE, "NEUROS", "dig. audio comp.", 539 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 540 }, 541 { 542 /* 543 * SEAGRAND NP-900 MP3 Player 544 * PR: kern/64563 545 */ 546 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SEAGRAND", "NP-900*", "*"}, 547 /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT 548 }, 549 { 550 /* 551 * iRiver iFP MP3 player (with UMS Firmware) 552 * PR: kern/54881, i386/63941, kern/66124 553 */ 554 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iRiver", "iFP*", "*"}, 555 /*quirks*/ DA_Q_NO_SYNC_CACHE 556 }, 557 { 558 /* 559 * Frontier Labs NEX IA+ Digital Audio Player, rev 1.10/0.01 560 * PR: kern/70158 561 */ 562 {T_DIRECT, SIP_MEDIA_REMOVABLE, "FL" , "Nex*", "*"}, 563 /*quirks*/ DA_Q_NO_SYNC_CACHE 564 }, 565 { 566 /* 567 * ZICPlay USB MP3 Player with FM 568 * PR: kern/75057 569 */ 570 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ACTIONS*" , "USB DISK*", "*"}, 571 /*quirks*/ DA_Q_NO_SYNC_CACHE 572 }, 573 { 574 /* 575 * TEAC USB floppy mechanisms 576 */ 577 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TEAC" , "FD-05*", "*"}, 578 /*quirks*/ DA_Q_NO_SYNC_CACHE 579 }, 580 { 581 /* 582 * Kingston DataTraveler II+ USB Pen-Drive. 583 * Reported by: Pawel Jakub Dawidek <pjd@FreeBSD.org> 584 */ 585 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston" , "DataTraveler II+", 586 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 587 }, 588 { 589 /* 590 * USB DISK Pro PMAP 591 * Reported by: jhs 592 * PR: usb/96381 593 */ 594 {T_DIRECT, SIP_MEDIA_REMOVABLE, " ", "USB DISK Pro", "PMAP"}, 595 /*quirks*/ DA_Q_NO_SYNC_CACHE 596 }, 597 { 598 /* 599 * Motorola E398 Mobile Phone (TransFlash memory card). 600 * Reported by: Wojciech A. Koszek <dunstan@FreeBSD.czest.pl> 601 * PR: usb/89889 602 */ 603 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Motorola" , "Motorola Phone", 604 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 605 }, 606 { 607 /* 608 * Qware BeatZkey! Pro 609 * PR: usb/79164 610 */ 611 {T_DIRECT, SIP_MEDIA_REMOVABLE, "GENERIC", "USB DISK DEVICE", 612 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 613 }, 614 { 615 /* 616 * Time DPA20B 1GB MP3 Player 617 * PR: usb/81846 618 */ 619 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB2.0*", "(FS) FLASH DISK*", 620 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 621 }, 622 { 623 /* 624 * Samsung USB key 128Mb 625 * PR: usb/90081 626 */ 627 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB-DISK", "FreeDik-FlashUsb", 628 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 629 }, 630 { 631 /* 632 * Kingston DataTraveler 2.0 USB Flash memory. 633 * PR: usb/89196 634 */ 635 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler 2.0", 636 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 637 }, 638 { 639 /* 640 * Creative MUVO Slim mp3 player (USB) 641 * PR: usb/86131 642 */ 643 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CREATIVE", "MuVo Slim", 644 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE|DA_Q_NO_PREVENT 645 }, 646 { 647 /* 648 * United MP5512 Portable MP3 Player (2-in-1 USB DISK/MP3) 649 * PR: usb/80487 650 */ 651 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "MUSIC DISK", 652 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 653 }, 654 { 655 /* 656 * SanDisk Micro Cruzer 128MB 657 * PR: usb/75970 658 */ 659 {T_DIRECT, SIP_MEDIA_REMOVABLE, "SanDisk" , "Micro Cruzer", 660 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 661 }, 662 { 663 /* 664 * TOSHIBA TransMemory USB sticks 665 * PR: kern/94660 666 */ 667 {T_DIRECT, SIP_MEDIA_REMOVABLE, "TOSHIBA", "TransMemory", 668 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 669 }, 670 { 671 /* 672 * PNY USB 3.0 Flash Drives 673 */ 674 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PNY", "USB 3.0 FD*", 675 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_RC16 676 }, 677 { 678 /* 679 * PNY USB Flash keys 680 * PR: usb/75578, usb/72344, usb/65436 681 */ 682 {T_DIRECT, SIP_MEDIA_REMOVABLE, "*" , "USB DISK*", 683 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 684 }, 685 { 686 /* 687 * Genesys GL3224 688 */ 689 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*", 690 "120?"}, /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_4K | DA_Q_NO_RC16 691 }, 692 { 693 /* 694 * Genesys 6-in-1 Card Reader 695 * PR: usb/94647 696 */ 697 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Generic*", "STORAGE DEVICE*", 698 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 699 }, 700 { 701 /* 702 * Rekam Digital CAMERA 703 * PR: usb/98713 704 */ 705 {T_DIRECT, SIP_MEDIA_REMOVABLE, "CAMERA*", "4MP-9J6*", 706 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 707 }, 708 { 709 /* 710 * iRiver H10 MP3 player 711 * PR: usb/102547 712 */ 713 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "H10*", 714 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 715 }, 716 { 717 /* 718 * iRiver U10 MP3 player 719 * PR: usb/92306 720 */ 721 {T_DIRECT, SIP_MEDIA_REMOVABLE, "iriver", "U10*", 722 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 723 }, 724 { 725 /* 726 * X-Micro Flash Disk 727 * PR: usb/96901 728 */ 729 {T_DIRECT, SIP_MEDIA_REMOVABLE, "X-Micro", "Flash Disk", 730 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 731 }, 732 { 733 /* 734 * EasyMP3 EM732X USB 2.0 Flash MP3 Player 735 * PR: usb/96546 736 */ 737 {T_DIRECT, SIP_MEDIA_REMOVABLE, "EM732X", "MP3 Player*", 738 "1.00"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 739 }, 740 { 741 /* 742 * Denver MP3 player 743 * PR: usb/107101 744 */ 745 {T_DIRECT, SIP_MEDIA_REMOVABLE, "DENVER", "MP3 PLAYER", 746 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 747 }, 748 { 749 /* 750 * Philips USB Key Audio KEY013 751 * PR: usb/68412 752 */ 753 {T_DIRECT, SIP_MEDIA_REMOVABLE, "PHILIPS", "Key*", "*"}, 754 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT 755 }, 756 { 757 /* 758 * JNC MP3 Player 759 * PR: usb/94439 760 */ 761 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JNC*" , "MP3 Player*", 762 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 763 }, 764 { 765 /* 766 * SAMSUNG MP0402H 767 * PR: usb/108427 768 */ 769 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "MP0402H", "*"}, 770 /*quirks*/ DA_Q_NO_SYNC_CACHE 771 }, 772 { 773 /* 774 * I/O Magic USB flash - Giga Bank 775 * PR: usb/108810 776 */ 777 {T_DIRECT, SIP_MEDIA_FIXED, "GS-Magic", "stor*", "*"}, 778 /*quirks*/ DA_Q_NO_SYNC_CACHE 779 }, 780 { 781 /* 782 * JoyFly 128mb USB Flash Drive 783 * PR: 96133 784 */ 785 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "Flash Disk*", 786 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 787 }, 788 { 789 /* 790 * ChipsBnk usb stick 791 * PR: 103702 792 */ 793 {T_DIRECT, SIP_MEDIA_REMOVABLE, "ChipsBnk", "USB*", 794 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 795 }, 796 { 797 /* 798 * Storcase (Kingston) InfoStation IFS FC2/SATA-R 201A 799 * PR: 129858 800 */ 801 {T_DIRECT, SIP_MEDIA_FIXED, "IFS", "FC2/SATA-R*", 802 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 803 }, 804 { 805 /* 806 * Samsung YP-U3 mp3-player 807 * PR: 125398 808 */ 809 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Samsung", "YP-U3", 810 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 811 }, 812 { 813 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Netac", "OnlyDisk*", 814 "2000"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 815 }, 816 { 817 /* 818 * Sony Cyber-Shot DSC cameras 819 * PR: usb/137035 820 */ 821 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Sony", "Sony DSC", "*"}, 822 /*quirks*/ DA_Q_NO_SYNC_CACHE | DA_Q_NO_PREVENT 823 }, 824 { 825 {T_DIRECT, SIP_MEDIA_REMOVABLE, "Kingston", "DataTraveler G3", 826 "1.00"}, /*quirks*/ DA_Q_NO_PREVENT 827 }, 828 { 829 /* At least several Transcent USB sticks lie on RC16. */ 830 {T_DIRECT, SIP_MEDIA_REMOVABLE, "JetFlash", "Transcend*", 831 "*"}, /*quirks*/ DA_Q_NO_RC16 832 }, 833 { 834 /* 835 * I-O Data USB Flash Disk 836 * PR: usb/211716 837 */ 838 {T_DIRECT, SIP_MEDIA_REMOVABLE, "I-O DATA", "USB Flash Disk*", 839 "*"}, /*quirks*/ DA_Q_NO_RC16 840 }, 841 /* ATA/SATA devices over SAS/USB/... */ 842 { 843 /* Hitachi Advanced Format (4k) drives */ 844 { T_DIRECT, SIP_MEDIA_FIXED, "Hitachi", "H??????????E3*", "*" }, 845 /*quirks*/DA_Q_4K 846 }, 847 { 848 /* Micron Advanced Format (4k) drives */ 849 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Micron 5100 MTFDDAK*", "*" }, 850 /*quirks*/DA_Q_4K 851 }, 852 { 853 /* Samsung Advanced Format (4k) drives */ 854 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD155UI*", "*" }, 855 /*quirks*/DA_Q_4K 856 }, 857 { 858 /* Samsung Advanced Format (4k) drives */ 859 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD155UI*", "*" }, 860 /*quirks*/DA_Q_4K 861 }, 862 { 863 /* Samsung Advanced Format (4k) drives */ 864 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG HD204UI*", "*" }, 865 /*quirks*/DA_Q_4K 866 }, 867 { 868 /* Samsung Advanced Format (4k) drives */ 869 { T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HD204UI*", "*" }, 870 /*quirks*/DA_Q_4K 871 }, 872 { 873 /* Seagate Barracuda Green Advanced Format (4k) drives */ 874 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DL*", "*" }, 875 /*quirks*/DA_Q_4K 876 }, 877 { 878 /* Seagate Barracuda Green Advanced Format (4k) drives */ 879 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DL", "*", "*" }, 880 /*quirks*/DA_Q_4K 881 }, 882 { 883 /* Seagate Barracuda Green Advanced Format (4k) drives */ 884 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???DM*", "*" }, 885 /*quirks*/DA_Q_4K 886 }, 887 { 888 /* Seagate Barracuda Green Advanced Format (4k) drives */ 889 { T_DIRECT, SIP_MEDIA_FIXED, "ST???DM*", "*", "*" }, 890 /*quirks*/DA_Q_4K 891 }, 892 { 893 /* Seagate Barracuda Green Advanced Format (4k) drives */ 894 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST????DM*", "*" }, 895 /*quirks*/DA_Q_4K 896 }, 897 { 898 /* Seagate Barracuda Green Advanced Format (4k) drives */ 899 { T_DIRECT, SIP_MEDIA_FIXED, "ST????DM", "*", "*" }, 900 /*quirks*/DA_Q_4K 901 }, 902 { 903 /* Seagate Momentus Advanced Format (4k) drives */ 904 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500423AS*", "*" }, 905 /*quirks*/DA_Q_4K 906 }, 907 { 908 /* Seagate Momentus Advanced Format (4k) drives */ 909 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "3AS*", "*" }, 910 /*quirks*/DA_Q_4K 911 }, 912 { 913 /* Seagate Momentus Advanced Format (4k) drives */ 914 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9500424AS*", "*" }, 915 /*quirks*/DA_Q_4K 916 }, 917 { 918 /* Seagate Momentus Advanced Format (4k) drives */ 919 { T_DIRECT, SIP_MEDIA_FIXED, "ST950042", "4AS*", "*" }, 920 /*quirks*/DA_Q_4K 921 }, 922 { 923 /* Seagate Momentus Advanced Format (4k) drives */ 924 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640423AS*", "*" }, 925 /*quirks*/DA_Q_4K 926 }, 927 { 928 /* Seagate Momentus Advanced Format (4k) drives */ 929 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "3AS*", "*" }, 930 /*quirks*/DA_Q_4K 931 }, 932 { 933 /* Seagate Momentus Advanced Format (4k) drives */ 934 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9640424AS*", "*" }, 935 /*quirks*/DA_Q_4K 936 }, 937 { 938 /* Seagate Momentus Advanced Format (4k) drives */ 939 { T_DIRECT, SIP_MEDIA_FIXED, "ST964042", "4AS*", "*" }, 940 /*quirks*/DA_Q_4K 941 }, 942 { 943 /* Seagate Momentus Advanced Format (4k) drives */ 944 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750420AS*", "*" }, 945 /*quirks*/DA_Q_4K 946 }, 947 { 948 /* Seagate Momentus Advanced Format (4k) drives */ 949 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "0AS*", "*" }, 950 /*quirks*/DA_Q_4K 951 }, 952 { 953 /* Seagate Momentus Advanced Format (4k) drives */ 954 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750422AS*", "*" }, 955 /*quirks*/DA_Q_4K 956 }, 957 { 958 /* Seagate Momentus Advanced Format (4k) drives */ 959 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "2AS*", "*" }, 960 /*quirks*/DA_Q_4K 961 }, 962 { 963 /* Seagate Momentus Advanced Format (4k) drives */ 964 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST9750423AS*", "*" }, 965 /*quirks*/DA_Q_4K 966 }, 967 { 968 /* Seagate Momentus Advanced Format (4k) drives */ 969 { T_DIRECT, SIP_MEDIA_FIXED, "ST975042", "3AS*", "*" }, 970 /*quirks*/DA_Q_4K 971 }, 972 { 973 /* Seagate Momentus Thin Advanced Format (4k) drives */ 974 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST???LT*", "*" }, 975 /*quirks*/DA_Q_4K 976 }, 977 { 978 /* Seagate Momentus Thin Advanced Format (4k) drives */ 979 { T_DIRECT, SIP_MEDIA_FIXED, "ST???LT*", "*", "*" }, 980 /*quirks*/DA_Q_4K 981 }, 982 { 983 /* WDC Caviar Green Advanced Format (4k) drives */ 984 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RS*", "*" }, 985 /*quirks*/DA_Q_4K 986 }, 987 { 988 /* WDC Caviar Green Advanced Format (4k) drives */ 989 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RS*", "*" }, 990 /*quirks*/DA_Q_4K 991 }, 992 { 993 /* WDC Caviar Green Advanced Format (4k) drives */ 994 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD????RX*", "*" }, 995 /*quirks*/DA_Q_4K 996 }, 997 { 998 /* WDC Caviar Green Advanced Format (4k) drives */ 999 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "??RX*", "*" }, 1000 /*quirks*/DA_Q_4K 1001 }, 1002 { 1003 /* WDC Caviar Green Advanced Format (4k) drives */ 1004 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RS*", "*" }, 1005 /*quirks*/DA_Q_4K 1006 }, 1007 { 1008 /* WDC Caviar Green Advanced Format (4k) drives */ 1009 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RS*", "*" }, 1010 /*quirks*/DA_Q_4K 1011 }, 1012 { 1013 /* WDC Caviar Green Advanced Format (4k) drives */ 1014 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD??????RX*", "*" }, 1015 /*quirks*/DA_Q_4K 1016 }, 1017 { 1018 /* WDC Caviar Green Advanced Format (4k) drives */ 1019 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "????RX*", "*" }, 1020 /*quirks*/DA_Q_4K 1021 }, 1022 { 1023 /* WDC Scorpio Black Advanced Format (4k) drives */ 1024 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PKT*", "*" }, 1025 /*quirks*/DA_Q_4K 1026 }, 1027 { 1028 /* WDC Scorpio Black Advanced Format (4k) drives */ 1029 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PKT*", "*" }, 1030 /*quirks*/DA_Q_4K 1031 }, 1032 { 1033 /* WDC Scorpio Black Advanced Format (4k) drives */ 1034 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PKT*", "*" }, 1035 /*quirks*/DA_Q_4K 1036 }, 1037 { 1038 /* WDC Scorpio Black Advanced Format (4k) drives */ 1039 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PKT*", "*" }, 1040 /*quirks*/DA_Q_4K 1041 }, 1042 { 1043 /* WDC Scorpio Blue Advanced Format (4k) drives */ 1044 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD???PVT*", "*" }, 1045 /*quirks*/DA_Q_4K 1046 }, 1047 { 1048 /* WDC Scorpio Blue Advanced Format (4k) drives */ 1049 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "?PVT*", "*" }, 1050 /*quirks*/DA_Q_4K 1051 }, 1052 { 1053 /* WDC Scorpio Blue Advanced Format (4k) drives */ 1054 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "WDC WD?????PVT*", "*" }, 1055 /*quirks*/DA_Q_4K 1056 }, 1057 { 1058 /* WDC Scorpio Blue Advanced Format (4k) drives */ 1059 { T_DIRECT, SIP_MEDIA_FIXED, "WDC WD??", "???PVT*", "*" }, 1060 /*quirks*/DA_Q_4K 1061 }, 1062 { 1063 /* 1064 * Olympus FE-210 camera 1065 */ 1066 {T_DIRECT, SIP_MEDIA_REMOVABLE, "OLYMPUS", "FE210*", 1067 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 1068 }, 1069 { 1070 /* 1071 * LG UP3S MP3 player 1072 */ 1073 {T_DIRECT, SIP_MEDIA_REMOVABLE, "LG", "UP3S", 1074 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 1075 }, 1076 { 1077 /* 1078 * Laser MP3-2GA13 MP3 player 1079 */ 1080 {T_DIRECT, SIP_MEDIA_REMOVABLE, "USB 2.0", "(HS) Flash Disk", 1081 "*"}, /*quirks*/ DA_Q_NO_SYNC_CACHE 1082 }, 1083 { 1084 /* 1085 * LaCie external 250GB Hard drive des by Porsche 1086 * Submitted by: Ben Stuyts <ben@altesco.nl> 1087 * PR: 121474 1088 */ 1089 {T_DIRECT, SIP_MEDIA_FIXED, "SAMSUNG", "HM250JI", "*"}, 1090 /*quirks*/ DA_Q_NO_SYNC_CACHE 1091 }, 1092 /* SATA SSDs */ 1093 { 1094 /* 1095 * Corsair Force 2 SSDs 1096 * 4k optimised & trim only works in 4k requests + 4k aligned 1097 */ 1098 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair CSSD-F*", "*" }, 1099 /*quirks*/DA_Q_4K 1100 }, 1101 { 1102 /* 1103 * Corsair Force 3 SSDs 1104 * 4k optimised & trim only works in 4k requests + 4k aligned 1105 */ 1106 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force 3*", "*" }, 1107 /*quirks*/DA_Q_4K 1108 }, 1109 { 1110 /* 1111 * Corsair Neutron GTX SSDs 1112 * 4k optimised & trim only works in 4k requests + 4k aligned 1113 */ 1114 { T_DIRECT, SIP_MEDIA_FIXED, "*", "Corsair Neutron GTX*", "*" }, 1115 /*quirks*/DA_Q_4K 1116 }, 1117 { 1118 /* 1119 * Corsair Force GT & GS SSDs 1120 * 4k optimised & trim only works in 4k requests + 4k aligned 1121 */ 1122 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Corsair Force G*", "*" }, 1123 /*quirks*/DA_Q_4K 1124 }, 1125 { 1126 /* 1127 * Crucial M4 SSDs 1128 * 4k optimised & trim only works in 4k requests + 4k aligned 1129 */ 1130 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "M4-CT???M4SSD2*", "*" }, 1131 /*quirks*/DA_Q_4K 1132 }, 1133 { 1134 /* 1135 * Crucial RealSSD C300 SSDs 1136 * 4k optimised 1137 */ 1138 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "C300-CTFDDAC???MAG*", 1139 "*" }, /*quirks*/DA_Q_4K 1140 }, 1141 { 1142 /* 1143 * Intel 320 Series SSDs 1144 * 4k optimised & trim only works in 4k requests + 4k aligned 1145 */ 1146 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2CW*", "*" }, 1147 /*quirks*/DA_Q_4K 1148 }, 1149 { 1150 /* 1151 * Intel 330 Series SSDs 1152 * 4k optimised & trim only works in 4k requests + 4k aligned 1153 */ 1154 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2CT*", "*" }, 1155 /*quirks*/DA_Q_4K 1156 }, 1157 { 1158 /* 1159 * Intel 510 Series SSDs 1160 * 4k optimised & trim only works in 4k requests + 4k aligned 1161 */ 1162 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2MH*", "*" }, 1163 /*quirks*/DA_Q_4K 1164 }, 1165 { 1166 /* 1167 * Intel 520 Series SSDs 1168 * 4k optimised & trim only works in 4k requests + 4k aligned 1169 */ 1170 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BW*", "*" }, 1171 /*quirks*/DA_Q_4K 1172 }, 1173 { 1174 /* 1175 * Intel S3610 Series SSDs 1176 * 4k optimised & trim only works in 4k requests + 4k aligned 1177 */ 1178 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSC2BX*", "*" }, 1179 /*quirks*/DA_Q_4K 1180 }, 1181 { 1182 /* 1183 * Intel X25-M Series SSDs 1184 * 4k optimised & trim only works in 4k requests + 4k aligned 1185 */ 1186 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "INTEL SSDSA2M*", "*" }, 1187 /*quirks*/DA_Q_4K 1188 }, 1189 { 1190 /* 1191 * Kingston E100 Series SSDs 1192 * 4k optimised & trim only works in 4k requests + 4k aligned 1193 */ 1194 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SE100S3*", "*" }, 1195 /*quirks*/DA_Q_4K 1196 }, 1197 { 1198 /* 1199 * Kingston HyperX 3k SSDs 1200 * 4k optimised & trim only works in 4k requests + 4k aligned 1201 */ 1202 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "KINGSTON SH103S3*", "*" }, 1203 /*quirks*/DA_Q_4K 1204 }, 1205 { 1206 /* 1207 * Marvell SSDs (entry taken from OpenSolaris) 1208 * 4k optimised & trim only works in 4k requests + 4k aligned 1209 */ 1210 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "MARVELL SD88SA02*", "*" }, 1211 /*quirks*/DA_Q_4K 1212 }, 1213 { 1214 /* 1215 * OCZ Agility 2 SSDs 1216 * 4k optimised & trim only works in 4k requests + 4k aligned 1217 */ 1218 { T_DIRECT, SIP_MEDIA_FIXED, "*", "OCZ-AGILITY2*", "*" }, 1219 /*quirks*/DA_Q_4K 1220 }, 1221 { 1222 /* 1223 * OCZ Agility 3 SSDs 1224 * 4k optimised & trim only works in 4k requests + 4k aligned 1225 */ 1226 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-AGILITY3*", "*" }, 1227 /*quirks*/DA_Q_4K 1228 }, 1229 { 1230 /* 1231 * OCZ Deneva R Series SSDs 1232 * 4k optimised & trim only works in 4k requests + 4k aligned 1233 */ 1234 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "DENRSTE251M45*", "*" }, 1235 /*quirks*/DA_Q_4K 1236 }, 1237 { 1238 /* 1239 * OCZ Vertex 2 SSDs (inc pro series) 1240 * 4k optimised & trim only works in 4k requests + 4k aligned 1241 */ 1242 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ?VERTEX2*", "*" }, 1243 /*quirks*/DA_Q_4K 1244 }, 1245 { 1246 /* 1247 * OCZ Vertex 3 SSDs 1248 * 4k optimised & trim only works in 4k requests + 4k aligned 1249 */ 1250 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX3*", "*" }, 1251 /*quirks*/DA_Q_4K 1252 }, 1253 { 1254 /* 1255 * OCZ Vertex 4 SSDs 1256 * 4k optimised & trim only works in 4k requests + 4k aligned 1257 */ 1258 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "OCZ-VERTEX4*", "*" }, 1259 /*quirks*/DA_Q_4K 1260 }, 1261 { 1262 /* 1263 * Samsung 750 Series SSDs 1264 * 4k optimised & trim only works in 4k requests + 4k aligned 1265 */ 1266 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 750*", "*" }, 1267 /*quirks*/DA_Q_4K 1268 }, 1269 { 1270 /* 1271 * Samsung 830 Series SSDs 1272 * 4k optimised & trim only works in 4k requests + 4k aligned 1273 */ 1274 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG SSD 830 Series*", "*" }, 1275 /*quirks*/DA_Q_4K 1276 }, 1277 { 1278 /* 1279 * Samsung 840 SSDs 1280 * 4k optimised & trim only works in 4k requests + 4k aligned 1281 */ 1282 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 840*", "*" }, 1283 /*quirks*/DA_Q_4K 1284 }, 1285 { 1286 /* 1287 * Samsung 845 SSDs 1288 * 4k optimised & trim only works in 4k requests + 4k aligned 1289 */ 1290 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 845*", "*" }, 1291 /*quirks*/DA_Q_4K 1292 }, 1293 { 1294 /* 1295 * Samsung 850 SSDs 1296 * 4k optimised & trim only works in 4k requests + 4k aligned 1297 */ 1298 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "Samsung SSD 850*", "*" }, 1299 /*quirks*/DA_Q_4K 1300 }, 1301 { 1302 /* 1303 * Samsung 843T Series SSDs (MZ7WD*) 1304 * Samsung PM851 Series SSDs (MZ7TE*) 1305 * Samsung PM853T Series SSDs (MZ7GE*) 1306 * Samsung SM863 Series SSDs (MZ7KM*) 1307 * 4k optimised 1308 */ 1309 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SAMSUNG MZ7*", "*" }, 1310 /*quirks*/DA_Q_4K 1311 }, 1312 { 1313 /* 1314 * SuperTalent TeraDrive CT SSDs 1315 * 4k optimised & trim only works in 4k requests + 4k aligned 1316 */ 1317 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "FTM??CT25H*", "*" }, 1318 /*quirks*/DA_Q_4K 1319 }, 1320 { 1321 /* 1322 * XceedIOPS SATA SSDs 1323 * 4k optimised 1324 */ 1325 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "SG9XCS2D*", "*" }, 1326 /*quirks*/DA_Q_4K 1327 }, 1328 { 1329 /* 1330 * Hama Innostor USB-Stick 1331 */ 1332 { T_DIRECT, SIP_MEDIA_REMOVABLE, "Innostor", "Innostor*", "*" }, 1333 /*quirks*/DA_Q_NO_RC16 1334 }, 1335 { 1336 /* 1337 * Seagate Lamarr 8TB Shingled Magnetic Recording (SMR) 1338 * Drive Managed SATA hard drive. This drive doesn't report 1339 * in firmware that it is a drive managed SMR drive. 1340 */ 1341 { T_DIRECT, SIP_MEDIA_FIXED, "ATA", "ST8000AS0002*", "*" }, 1342 /*quirks*/DA_Q_SMR_DM 1343 }, 1344 { 1345 /* 1346 * MX-ES USB Drive by Mach Xtreme 1347 */ 1348 { T_DIRECT, SIP_MEDIA_REMOVABLE, "MX", "MXUB3*", "*"}, 1349 /*quirks*/DA_Q_NO_RC16 1350 }, 1351 }; 1352 1353 static disk_strategy_t dastrategy; 1354 static dumper_t dadump; 1355 static periph_init_t dainit; 1356 static void daasync(void *callback_arg, u_int32_t code, 1357 struct cam_path *path, void *arg); 1358 static void dasysctlinit(void *context, int pending); 1359 static int dasysctlsofttimeout(SYSCTL_HANDLER_ARGS); 1360 static int dacmdsizesysctl(SYSCTL_HANDLER_ARGS); 1361 static int dadeletemethodsysctl(SYSCTL_HANDLER_ARGS); 1362 static int dazonemodesysctl(SYSCTL_HANDLER_ARGS); 1363 static int dazonesupsysctl(SYSCTL_HANDLER_ARGS); 1364 static int dadeletemaxsysctl(SYSCTL_HANDLER_ARGS); 1365 static void dadeletemethodset(struct da_softc *softc, 1366 da_delete_methods delete_method); 1367 static off_t dadeletemaxsize(struct da_softc *softc, 1368 da_delete_methods delete_method); 1369 static void dadeletemethodchoose(struct da_softc *softc, 1370 da_delete_methods default_method); 1371 static void daprobedone(struct cam_periph *periph, union ccb *ccb); 1372 1373 static periph_ctor_t daregister; 1374 static periph_dtor_t dacleanup; 1375 static periph_start_t dastart; 1376 static periph_oninv_t daoninvalidate; 1377 static void dazonedone(struct cam_periph *periph, union ccb *ccb); 1378 static void dadone(struct cam_periph *periph, 1379 union ccb *done_ccb); 1380 static int daerror(union ccb *ccb, u_int32_t cam_flags, 1381 u_int32_t sense_flags); 1382 static void daprevent(struct cam_periph *periph, int action); 1383 static void dareprobe(struct cam_periph *periph); 1384 static void dasetgeom(struct cam_periph *periph, uint32_t block_len, 1385 uint64_t maxsector, 1386 struct scsi_read_capacity_data_long *rcaplong, 1387 size_t rcap_size); 1388 static timeout_t dasendorderedtag; 1389 static void dashutdown(void *arg, int howto); 1390 static timeout_t damediapoll; 1391 1392 #ifndef DA_DEFAULT_POLL_PERIOD 1393 #define DA_DEFAULT_POLL_PERIOD 3 1394 #endif 1395 1396 #ifndef DA_DEFAULT_TIMEOUT 1397 #define DA_DEFAULT_TIMEOUT 60 /* Timeout in seconds */ 1398 #endif 1399 1400 #ifndef DA_DEFAULT_SOFTTIMEOUT 1401 #define DA_DEFAULT_SOFTTIMEOUT 0 1402 #endif 1403 1404 #ifndef DA_DEFAULT_RETRY 1405 #define DA_DEFAULT_RETRY 4 1406 #endif 1407 1408 #ifndef DA_DEFAULT_SEND_ORDERED 1409 #define DA_DEFAULT_SEND_ORDERED 1 1410 #endif 1411 1412 static int da_poll_period = DA_DEFAULT_POLL_PERIOD; 1413 static int da_retry_count = DA_DEFAULT_RETRY; 1414 static int da_default_timeout = DA_DEFAULT_TIMEOUT; 1415 static sbintime_t da_default_softtimeout = DA_DEFAULT_SOFTTIMEOUT; 1416 static int da_send_ordered = DA_DEFAULT_SEND_ORDERED; 1417 1418 static SYSCTL_NODE(_kern_cam, OID_AUTO, da, CTLFLAG_RD, 0, 1419 "CAM Direct Access Disk driver"); 1420 SYSCTL_INT(_kern_cam_da, OID_AUTO, poll_period, CTLFLAG_RWTUN, 1421 &da_poll_period, 0, "Media polling period in seconds"); 1422 SYSCTL_INT(_kern_cam_da, OID_AUTO, retry_count, CTLFLAG_RWTUN, 1423 &da_retry_count, 0, "Normal I/O retry count"); 1424 SYSCTL_INT(_kern_cam_da, OID_AUTO, default_timeout, CTLFLAG_RWTUN, 1425 &da_default_timeout, 0, "Normal I/O timeout (in seconds)"); 1426 SYSCTL_INT(_kern_cam_da, OID_AUTO, send_ordered, CTLFLAG_RWTUN, 1427 &da_send_ordered, 0, "Send Ordered Tags"); 1428 1429 SYSCTL_PROC(_kern_cam_da, OID_AUTO, default_softtimeout, 1430 CTLTYPE_UINT | CTLFLAG_RW, NULL, 0, dasysctlsofttimeout, "I", 1431 "Soft I/O timeout (ms)"); 1432 TUNABLE_INT64("kern.cam.da.default_softtimeout", &da_default_softtimeout); 1433 1434 /* 1435 * DA_ORDEREDTAG_INTERVAL determines how often, relative 1436 * to the default timeout, we check to see whether an ordered 1437 * tagged transaction is appropriate to prevent simple tag 1438 * starvation. Since we'd like to ensure that there is at least 1439 * 1/2 of the timeout length left for a starved transaction to 1440 * complete after we've sent an ordered tag, we must poll at least 1441 * four times in every timeout period. This takes care of the worst 1442 * case where a starved transaction starts during an interval that 1443 * meets the requirement "don't send an ordered tag" test so it takes 1444 * us two intervals to determine that a tag must be sent. 1445 */ 1446 #ifndef DA_ORDEREDTAG_INTERVAL 1447 #define DA_ORDEREDTAG_INTERVAL 4 1448 #endif 1449 1450 static struct periph_driver dadriver = 1451 { 1452 dainit, "da", 1453 TAILQ_HEAD_INITIALIZER(dadriver.units), /* generation */ 0 1454 }; 1455 1456 PERIPHDRIVER_DECLARE(da, dadriver); 1457 1458 static MALLOC_DEFINE(M_SCSIDA, "scsi_da", "scsi_da buffers"); 1459 1460 static int 1461 daopen(struct disk *dp) 1462 { 1463 struct cam_periph *periph; 1464 struct da_softc *softc; 1465 int error; 1466 1467 periph = (struct cam_periph *)dp->d_drv1; 1468 if (cam_periph_acquire(periph) != CAM_REQ_CMP) { 1469 return (ENXIO); 1470 } 1471 1472 cam_periph_lock(periph); 1473 if ((error = cam_periph_hold(periph, PRIBIO|PCATCH)) != 0) { 1474 cam_periph_unlock(periph); 1475 cam_periph_release(periph); 1476 return (error); 1477 } 1478 1479 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH, 1480 ("daopen\n")); 1481 1482 softc = (struct da_softc *)periph->softc; 1483 dareprobe(periph); 1484 1485 /* Wait for the disk size update. */ 1486 error = cam_periph_sleep(periph, &softc->disk->d_mediasize, PRIBIO, 1487 "dareprobe", 0); 1488 if (error != 0) 1489 xpt_print(periph->path, "unable to retrieve capacity data\n"); 1490 1491 if (periph->flags & CAM_PERIPH_INVALID) 1492 error = ENXIO; 1493 1494 if (error == 0 && (softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 && 1495 (softc->quirks & DA_Q_NO_PREVENT) == 0) 1496 daprevent(periph, PR_PREVENT); 1497 1498 if (error == 0) { 1499 softc->flags &= ~DA_FLAG_PACK_INVALID; 1500 softc->flags |= DA_FLAG_OPEN; 1501 } 1502 1503 cam_periph_unhold(periph); 1504 cam_periph_unlock(periph); 1505 1506 if (error != 0) 1507 cam_periph_release(periph); 1508 1509 return (error); 1510 } 1511 1512 static int 1513 daclose(struct disk *dp) 1514 { 1515 struct cam_periph *periph; 1516 struct da_softc *softc; 1517 union ccb *ccb; 1518 int error; 1519 1520 periph = (struct cam_periph *)dp->d_drv1; 1521 softc = (struct da_softc *)periph->softc; 1522 cam_periph_lock(periph); 1523 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE | CAM_DEBUG_PERIPH, 1524 ("daclose\n")); 1525 1526 if (cam_periph_hold(periph, PRIBIO) == 0) { 1527 1528 /* Flush disk cache. */ 1529 if ((softc->flags & DA_FLAG_DIRTY) != 0 && 1530 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0 && 1531 (softc->flags & DA_FLAG_PACK_INVALID) == 0) { 1532 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); 1533 scsi_synchronize_cache(&ccb->csio, /*retries*/1, 1534 /*cbfcnp*/dadone, MSG_SIMPLE_Q_TAG, 1535 /*begin_lba*/0, /*lb_count*/0, SSD_FULL_SIZE, 1536 5 * 60 * 1000); 1537 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0, 1538 /*sense_flags*/SF_RETRY_UA | SF_QUIET_IR, 1539 softc->disk->d_devstat); 1540 softc->flags &= ~DA_FLAG_DIRTY; 1541 xpt_release_ccb(ccb); 1542 } 1543 1544 /* Allow medium removal. */ 1545 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0 && 1546 (softc->quirks & DA_Q_NO_PREVENT) == 0) 1547 daprevent(periph, PR_ALLOW); 1548 1549 cam_periph_unhold(periph); 1550 } 1551 1552 /* 1553 * If we've got removeable media, mark the blocksize as 1554 * unavailable, since it could change when new media is 1555 * inserted. 1556 */ 1557 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) != 0) 1558 softc->disk->d_devstat->flags |= DEVSTAT_BS_UNAVAILABLE; 1559 1560 softc->flags &= ~DA_FLAG_OPEN; 1561 while (softc->refcount != 0) 1562 cam_periph_sleep(periph, &softc->refcount, PRIBIO, "daclose", 1); 1563 cam_periph_unlock(periph); 1564 cam_periph_release(periph); 1565 return (0); 1566 } 1567 1568 static void 1569 daschedule(struct cam_periph *periph) 1570 { 1571 struct da_softc *softc = (struct da_softc *)periph->softc; 1572 1573 if (softc->state != DA_STATE_NORMAL) 1574 return; 1575 1576 cam_iosched_schedule(softc->cam_iosched, periph); 1577 } 1578 1579 /* 1580 * Actually translate the requested transfer into one the physical driver 1581 * can understand. The transfer is described by a buf and will include 1582 * only one physical transfer. 1583 */ 1584 static void 1585 dastrategy(struct bio *bp) 1586 { 1587 struct cam_periph *periph; 1588 struct da_softc *softc; 1589 1590 periph = (struct cam_periph *)bp->bio_disk->d_drv1; 1591 softc = (struct da_softc *)periph->softc; 1592 1593 cam_periph_lock(periph); 1594 1595 /* 1596 * If the device has been made invalid, error out 1597 */ 1598 if ((softc->flags & DA_FLAG_PACK_INVALID)) { 1599 cam_periph_unlock(periph); 1600 biofinish(bp, NULL, ENXIO); 1601 return; 1602 } 1603 1604 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastrategy(%p)\n", bp)); 1605 1606 /* 1607 * Zone commands must be ordered, because they can depend on the 1608 * effects of previously issued commands, and they may affect 1609 * commands after them. 1610 */ 1611 if (bp->bio_cmd == BIO_ZONE) 1612 bp->bio_flags |= BIO_ORDERED; 1613 1614 /* 1615 * Place it in the queue of disk activities for this disk 1616 */ 1617 cam_iosched_queue_work(softc->cam_iosched, bp); 1618 1619 /* 1620 * Schedule ourselves for performing the work. 1621 */ 1622 daschedule(periph); 1623 cam_periph_unlock(periph); 1624 1625 return; 1626 } 1627 1628 static int 1629 dadump(void *arg, void *virtual, vm_offset_t physical, off_t offset, size_t length) 1630 { 1631 struct cam_periph *periph; 1632 struct da_softc *softc; 1633 u_int secsize; 1634 struct ccb_scsiio csio; 1635 struct disk *dp; 1636 int error = 0; 1637 1638 dp = arg; 1639 periph = dp->d_drv1; 1640 softc = (struct da_softc *)periph->softc; 1641 cam_periph_lock(periph); 1642 secsize = softc->params.secsize; 1643 1644 if ((softc->flags & DA_FLAG_PACK_INVALID) != 0) { 1645 cam_periph_unlock(periph); 1646 return (ENXIO); 1647 } 1648 1649 if (length > 0) { 1650 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 1651 csio.ccb_h.ccb_state = DA_CCB_DUMP; 1652 scsi_read_write(&csio, 1653 /*retries*/0, 1654 dadone, 1655 MSG_ORDERED_Q_TAG, 1656 /*read*/SCSI_RW_WRITE, 1657 /*byte2*/0, 1658 /*minimum_cmd_size*/ softc->minimum_cmd_size, 1659 offset / secsize, 1660 length / secsize, 1661 /*data_ptr*/(u_int8_t *) virtual, 1662 /*dxfer_len*/length, 1663 /*sense_len*/SSD_FULL_SIZE, 1664 da_default_timeout * 1000); 1665 xpt_polled_action((union ccb *)&csio); 1666 1667 error = cam_periph_error((union ccb *)&csio, 1668 0, SF_NO_RECOVERY | SF_NO_RETRY, NULL); 1669 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0) 1670 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0, 1671 /*reduction*/0, /*timeout*/0, /*getcount_only*/0); 1672 if (error != 0) 1673 printf("Aborting dump due to I/O error.\n"); 1674 cam_periph_unlock(periph); 1675 return (error); 1676 } 1677 1678 /* 1679 * Sync the disk cache contents to the physical media. 1680 */ 1681 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) { 1682 1683 xpt_setup_ccb(&csio.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 1684 csio.ccb_h.ccb_state = DA_CCB_DUMP; 1685 scsi_synchronize_cache(&csio, 1686 /*retries*/0, 1687 /*cbfcnp*/dadone, 1688 MSG_SIMPLE_Q_TAG, 1689 /*begin_lba*/0,/* Cover the whole disk */ 1690 /*lb_count*/0, 1691 SSD_FULL_SIZE, 1692 5 * 1000); 1693 xpt_polled_action((union ccb *)&csio); 1694 1695 error = cam_periph_error((union ccb *)&csio, 1696 0, SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, NULL); 1697 if ((csio.ccb_h.status & CAM_DEV_QFRZN) != 0) 1698 cam_release_devq(csio.ccb_h.path, /*relsim_flags*/0, 1699 /*reduction*/0, /*timeout*/0, /*getcount_only*/0); 1700 if (error != 0) 1701 xpt_print(periph->path, "Synchronize cache failed\n"); 1702 } 1703 cam_periph_unlock(periph); 1704 return (error); 1705 } 1706 1707 static int 1708 dagetattr(struct bio *bp) 1709 { 1710 int ret; 1711 struct cam_periph *periph; 1712 1713 periph = (struct cam_periph *)bp->bio_disk->d_drv1; 1714 cam_periph_lock(periph); 1715 ret = xpt_getattr(bp->bio_data, bp->bio_length, bp->bio_attribute, 1716 periph->path); 1717 cam_periph_unlock(periph); 1718 if (ret == 0) 1719 bp->bio_completed = bp->bio_length; 1720 return ret; 1721 } 1722 1723 static void 1724 dainit(void) 1725 { 1726 cam_status status; 1727 1728 /* 1729 * Install a global async callback. This callback will 1730 * receive async callbacks like "new device found". 1731 */ 1732 status = xpt_register_async(AC_FOUND_DEVICE, daasync, NULL, NULL); 1733 1734 if (status != CAM_REQ_CMP) { 1735 printf("da: Failed to attach master async callback " 1736 "due to status 0x%x!\n", status); 1737 } else if (da_send_ordered) { 1738 1739 /* Register our shutdown event handler */ 1740 if ((EVENTHANDLER_REGISTER(shutdown_post_sync, dashutdown, 1741 NULL, SHUTDOWN_PRI_DEFAULT)) == NULL) 1742 printf("dainit: shutdown event registration failed!\n"); 1743 } 1744 } 1745 1746 /* 1747 * Callback from GEOM, called when it has finished cleaning up its 1748 * resources. 1749 */ 1750 static void 1751 dadiskgonecb(struct disk *dp) 1752 { 1753 struct cam_periph *periph; 1754 1755 periph = (struct cam_periph *)dp->d_drv1; 1756 cam_periph_release(periph); 1757 } 1758 1759 static void 1760 daoninvalidate(struct cam_periph *periph) 1761 { 1762 struct da_softc *softc; 1763 1764 softc = (struct da_softc *)periph->softc; 1765 1766 /* 1767 * De-register any async callbacks. 1768 */ 1769 xpt_register_async(0, daasync, periph, periph->path); 1770 1771 softc->flags |= DA_FLAG_PACK_INVALID; 1772 #ifdef CAM_IO_STATS 1773 softc->invalidations++; 1774 #endif 1775 1776 /* 1777 * Return all queued I/O with ENXIO. 1778 * XXX Handle any transactions queued to the card 1779 * with XPT_ABORT_CCB. 1780 */ 1781 cam_iosched_flush(softc->cam_iosched, NULL, ENXIO); 1782 1783 /* 1784 * Tell GEOM that we've gone away, we'll get a callback when it is 1785 * done cleaning up its resources. 1786 */ 1787 disk_gone(softc->disk); 1788 } 1789 1790 static void 1791 dacleanup(struct cam_periph *periph) 1792 { 1793 struct da_softc *softc; 1794 1795 softc = (struct da_softc *)periph->softc; 1796 1797 cam_periph_unlock(periph); 1798 1799 cam_iosched_fini(softc->cam_iosched); 1800 1801 /* 1802 * If we can't free the sysctl tree, oh well... 1803 */ 1804 if ((softc->flags & DA_FLAG_SCTX_INIT) != 0) { 1805 #ifdef CAM_IO_STATS 1806 if (sysctl_ctx_free(&softc->sysctl_stats_ctx) != 0) 1807 xpt_print(periph->path, 1808 "can't remove sysctl stats context\n"); 1809 #endif 1810 if (sysctl_ctx_free(&softc->sysctl_ctx) != 0) 1811 xpt_print(periph->path, 1812 "can't remove sysctl context\n"); 1813 } 1814 1815 callout_drain(&softc->mediapoll_c); 1816 disk_destroy(softc->disk); 1817 callout_drain(&softc->sendordered_c); 1818 free(softc, M_DEVBUF); 1819 cam_periph_lock(periph); 1820 } 1821 1822 static void 1823 daasync(void *callback_arg, u_int32_t code, 1824 struct cam_path *path, void *arg) 1825 { 1826 struct cam_periph *periph; 1827 struct da_softc *softc; 1828 1829 periph = (struct cam_periph *)callback_arg; 1830 switch (code) { 1831 case AC_FOUND_DEVICE: 1832 { 1833 struct ccb_getdev *cgd; 1834 cam_status status; 1835 1836 cgd = (struct ccb_getdev *)arg; 1837 if (cgd == NULL) 1838 break; 1839 1840 if (cgd->protocol != PROTO_SCSI) 1841 break; 1842 if (SID_QUAL(&cgd->inq_data) != SID_QUAL_LU_CONNECTED) 1843 break; 1844 if (SID_TYPE(&cgd->inq_data) != T_DIRECT 1845 && SID_TYPE(&cgd->inq_data) != T_RBC 1846 && SID_TYPE(&cgd->inq_data) != T_OPTICAL 1847 && SID_TYPE(&cgd->inq_data) != T_ZBC_HM) 1848 break; 1849 1850 /* 1851 * Allocate a peripheral instance for 1852 * this device and start the probe 1853 * process. 1854 */ 1855 status = cam_periph_alloc(daregister, daoninvalidate, 1856 dacleanup, dastart, 1857 "da", CAM_PERIPH_BIO, 1858 path, daasync, 1859 AC_FOUND_DEVICE, cgd); 1860 1861 if (status != CAM_REQ_CMP 1862 && status != CAM_REQ_INPROG) 1863 printf("daasync: Unable to attach to new device " 1864 "due to status 0x%x\n", status); 1865 return; 1866 } 1867 case AC_ADVINFO_CHANGED: 1868 { 1869 uintptr_t buftype; 1870 1871 buftype = (uintptr_t)arg; 1872 if (buftype == CDAI_TYPE_PHYS_PATH) { 1873 struct da_softc *softc; 1874 1875 softc = periph->softc; 1876 disk_attr_changed(softc->disk, "GEOM::physpath", 1877 M_NOWAIT); 1878 } 1879 break; 1880 } 1881 case AC_UNIT_ATTENTION: 1882 { 1883 union ccb *ccb; 1884 int error_code, sense_key, asc, ascq; 1885 1886 softc = (struct da_softc *)periph->softc; 1887 ccb = (union ccb *)arg; 1888 1889 /* 1890 * Handle all UNIT ATTENTIONs except our own, 1891 * as they will be handled by daerror(). 1892 */ 1893 if (xpt_path_periph(ccb->ccb_h.path) != periph && 1894 scsi_extract_sense_ccb(ccb, 1895 &error_code, &sense_key, &asc, &ascq)) { 1896 if (asc == 0x2A && ascq == 0x09) { 1897 xpt_print(ccb->ccb_h.path, 1898 "Capacity data has changed\n"); 1899 softc->flags &= ~DA_FLAG_PROBED; 1900 dareprobe(periph); 1901 } else if (asc == 0x28 && ascq == 0x00) { 1902 softc->flags &= ~DA_FLAG_PROBED; 1903 disk_media_changed(softc->disk, M_NOWAIT); 1904 } else if (asc == 0x3F && ascq == 0x03) { 1905 xpt_print(ccb->ccb_h.path, 1906 "INQUIRY data has changed\n"); 1907 softc->flags &= ~DA_FLAG_PROBED; 1908 dareprobe(periph); 1909 } 1910 } 1911 cam_periph_async(periph, code, path, arg); 1912 break; 1913 } 1914 case AC_SCSI_AEN: 1915 softc = (struct da_softc *)periph->softc; 1916 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) { 1917 if (cam_periph_acquire(periph) == CAM_REQ_CMP) { 1918 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR); 1919 daschedule(periph); 1920 } 1921 } 1922 /* FALLTHROUGH */ 1923 case AC_SENT_BDR: 1924 case AC_BUS_RESET: 1925 { 1926 struct ccb_hdr *ccbh; 1927 1928 softc = (struct da_softc *)periph->softc; 1929 /* 1930 * Don't fail on the expected unit attention 1931 * that will occur. 1932 */ 1933 softc->flags |= DA_FLAG_RETRY_UA; 1934 LIST_FOREACH(ccbh, &softc->pending_ccbs, periph_links.le) 1935 ccbh->ccb_state |= DA_CCB_RETRY_UA; 1936 break; 1937 } 1938 case AC_INQ_CHANGED: 1939 softc = (struct da_softc *)periph->softc; 1940 softc->flags &= ~DA_FLAG_PROBED; 1941 dareprobe(periph); 1942 break; 1943 default: 1944 break; 1945 } 1946 cam_periph_async(periph, code, path, arg); 1947 } 1948 1949 static void 1950 dasysctlinit(void *context, int pending) 1951 { 1952 struct cam_periph *periph; 1953 struct da_softc *softc; 1954 char tmpstr[80], tmpstr2[80]; 1955 struct ccb_trans_settings cts; 1956 1957 periph = (struct cam_periph *)context; 1958 /* 1959 * periph was held for us when this task was enqueued 1960 */ 1961 if (periph->flags & CAM_PERIPH_INVALID) { 1962 cam_periph_release(periph); 1963 return; 1964 } 1965 1966 softc = (struct da_softc *)periph->softc; 1967 snprintf(tmpstr, sizeof(tmpstr), "CAM DA unit %d", periph->unit_number); 1968 snprintf(tmpstr2, sizeof(tmpstr2), "%d", periph->unit_number); 1969 1970 sysctl_ctx_init(&softc->sysctl_ctx); 1971 softc->flags |= DA_FLAG_SCTX_INIT; 1972 softc->sysctl_tree = SYSCTL_ADD_NODE_WITH_LABEL(&softc->sysctl_ctx, 1973 SYSCTL_STATIC_CHILDREN(_kern_cam_da), OID_AUTO, tmpstr2, 1974 CTLFLAG_RD, 0, tmpstr, "device_index"); 1975 if (softc->sysctl_tree == NULL) { 1976 printf("dasysctlinit: unable to allocate sysctl tree\n"); 1977 cam_periph_release(periph); 1978 return; 1979 } 1980 1981 /* 1982 * Now register the sysctl handler, so the user can change the value on 1983 * the fly. 1984 */ 1985 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 1986 OID_AUTO, "delete_method", CTLTYPE_STRING | CTLFLAG_RWTUN, 1987 softc, 0, dadeletemethodsysctl, "A", 1988 "BIO_DELETE execution method"); 1989 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 1990 OID_AUTO, "delete_max", CTLTYPE_U64 | CTLFLAG_RW, 1991 softc, 0, dadeletemaxsysctl, "Q", 1992 "Maximum BIO_DELETE size"); 1993 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 1994 OID_AUTO, "minimum_cmd_size", CTLTYPE_INT | CTLFLAG_RW, 1995 &softc->minimum_cmd_size, 0, dacmdsizesysctl, "I", 1996 "Minimum CDB size"); 1997 1998 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 1999 OID_AUTO, "zone_mode", CTLTYPE_STRING | CTLFLAG_RD, 2000 softc, 0, dazonemodesysctl, "A", 2001 "Zone Mode"); 2002 SYSCTL_ADD_PROC(&softc->sysctl_ctx, SYSCTL_CHILDREN(softc->sysctl_tree), 2003 OID_AUTO, "zone_support", CTLTYPE_STRING | CTLFLAG_RD, 2004 softc, 0, dazonesupsysctl, "A", 2005 "Zone Support"); 2006 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, 2007 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, 2008 "optimal_seq_zones", CTLFLAG_RD, &softc->optimal_seq_zones, 2009 "Optimal Number of Open Sequential Write Preferred Zones"); 2010 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, 2011 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, 2012 "optimal_nonseq_zones", CTLFLAG_RD, 2013 &softc->optimal_nonseq_zones, 2014 "Optimal Number of Non-Sequentially Written Sequential Write " 2015 "Preferred Zones"); 2016 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, 2017 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, 2018 "max_seq_zones", CTLFLAG_RD, &softc->max_seq_zones, 2019 "Maximum Number of Open Sequential Write Required Zones"); 2020 2021 SYSCTL_ADD_INT(&softc->sysctl_ctx, 2022 SYSCTL_CHILDREN(softc->sysctl_tree), 2023 OID_AUTO, 2024 "error_inject", 2025 CTLFLAG_RW, 2026 &softc->error_inject, 2027 0, 2028 "error_inject leaf"); 2029 2030 SYSCTL_ADD_INT(&softc->sysctl_ctx, 2031 SYSCTL_CHILDREN(softc->sysctl_tree), 2032 OID_AUTO, 2033 "unmapped_io", 2034 CTLFLAG_RD, 2035 &softc->unmappedio, 2036 0, 2037 "Unmapped I/O leaf"); 2038 2039 SYSCTL_ADD_INT(&softc->sysctl_ctx, 2040 SYSCTL_CHILDREN(softc->sysctl_tree), 2041 OID_AUTO, 2042 "rotating", 2043 CTLFLAG_RD, 2044 &softc->rotating, 2045 0, 2046 "Rotating media"); 2047 2048 /* 2049 * Add some addressing info. 2050 */ 2051 memset(&cts, 0, sizeof (cts)); 2052 xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); 2053 cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; 2054 cts.type = CTS_TYPE_CURRENT_SETTINGS; 2055 cam_periph_lock(periph); 2056 xpt_action((union ccb *)&cts); 2057 cam_periph_unlock(periph); 2058 if (cts.ccb_h.status != CAM_REQ_CMP) { 2059 cam_periph_release(periph); 2060 return; 2061 } 2062 if (cts.protocol == PROTO_SCSI && cts.transport == XPORT_FC) { 2063 struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc; 2064 if (fc->valid & CTS_FC_VALID_WWPN) { 2065 softc->wwpn = fc->wwpn; 2066 SYSCTL_ADD_UQUAD(&softc->sysctl_ctx, 2067 SYSCTL_CHILDREN(softc->sysctl_tree), 2068 OID_AUTO, "wwpn", CTLFLAG_RD, 2069 &softc->wwpn, "World Wide Port Name"); 2070 } 2071 } 2072 2073 #ifdef CAM_IO_STATS 2074 /* 2075 * Now add some useful stats. 2076 * XXX These should live in cam_periph and be common to all periphs 2077 */ 2078 softc->sysctl_stats_tree = SYSCTL_ADD_NODE(&softc->sysctl_stats_ctx, 2079 SYSCTL_CHILDREN(softc->sysctl_tree), OID_AUTO, "stats", 2080 CTLFLAG_RD, 0, "Statistics"); 2081 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx, 2082 SYSCTL_CHILDREN(softc->sysctl_stats_tree), 2083 OID_AUTO, 2084 "errors", 2085 CTLFLAG_RD, 2086 &softc->errors, 2087 0, 2088 "Transport errors reported by the SIM"); 2089 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx, 2090 SYSCTL_CHILDREN(softc->sysctl_stats_tree), 2091 OID_AUTO, 2092 "timeouts", 2093 CTLFLAG_RD, 2094 &softc->timeouts, 2095 0, 2096 "Device timeouts reported by the SIM"); 2097 SYSCTL_ADD_INT(&softc->sysctl_stats_ctx, 2098 SYSCTL_CHILDREN(softc->sysctl_stats_tree), 2099 OID_AUTO, 2100 "pack_invalidations", 2101 CTLFLAG_RD, 2102 &softc->invalidations, 2103 0, 2104 "Device pack invalidations"); 2105 #endif 2106 2107 cam_iosched_sysctl_init(softc->cam_iosched, &softc->sysctl_ctx, 2108 softc->sysctl_tree); 2109 2110 cam_periph_release(periph); 2111 } 2112 2113 static int 2114 dadeletemaxsysctl(SYSCTL_HANDLER_ARGS) 2115 { 2116 int error; 2117 uint64_t value; 2118 struct da_softc *softc; 2119 2120 softc = (struct da_softc *)arg1; 2121 2122 value = softc->disk->d_delmaxsize; 2123 error = sysctl_handle_64(oidp, &value, 0, req); 2124 if ((error != 0) || (req->newptr == NULL)) 2125 return (error); 2126 2127 /* only accept values smaller than the calculated value */ 2128 if (value > dadeletemaxsize(softc, softc->delete_method)) { 2129 return (EINVAL); 2130 } 2131 softc->disk->d_delmaxsize = value; 2132 2133 return (0); 2134 } 2135 2136 static int 2137 dacmdsizesysctl(SYSCTL_HANDLER_ARGS) 2138 { 2139 int error, value; 2140 2141 value = *(int *)arg1; 2142 2143 error = sysctl_handle_int(oidp, &value, 0, req); 2144 2145 if ((error != 0) 2146 || (req->newptr == NULL)) 2147 return (error); 2148 2149 /* 2150 * Acceptable values here are 6, 10, 12 or 16. 2151 */ 2152 if (value < 6) 2153 value = 6; 2154 else if ((value > 6) 2155 && (value <= 10)) 2156 value = 10; 2157 else if ((value > 10) 2158 && (value <= 12)) 2159 value = 12; 2160 else if (value > 12) 2161 value = 16; 2162 2163 *(int *)arg1 = value; 2164 2165 return (0); 2166 } 2167 2168 static int 2169 dasysctlsofttimeout(SYSCTL_HANDLER_ARGS) 2170 { 2171 sbintime_t value; 2172 int error; 2173 2174 value = da_default_softtimeout / SBT_1MS; 2175 2176 error = sysctl_handle_int(oidp, (int *)&value, 0, req); 2177 if ((error != 0) || (req->newptr == NULL)) 2178 return (error); 2179 2180 /* XXX Should clip this to a reasonable level */ 2181 if (value > da_default_timeout * 1000) 2182 return (EINVAL); 2183 2184 da_default_softtimeout = value * SBT_1MS; 2185 return (0); 2186 } 2187 2188 static void 2189 dadeletemethodset(struct da_softc *softc, da_delete_methods delete_method) 2190 { 2191 2192 softc->delete_method = delete_method; 2193 softc->disk->d_delmaxsize = dadeletemaxsize(softc, delete_method); 2194 softc->delete_func = da_delete_functions[delete_method]; 2195 2196 if (softc->delete_method > DA_DELETE_DISABLE) 2197 softc->disk->d_flags |= DISKFLAG_CANDELETE; 2198 else 2199 softc->disk->d_flags &= ~DISKFLAG_CANDELETE; 2200 } 2201 2202 static off_t 2203 dadeletemaxsize(struct da_softc *softc, da_delete_methods delete_method) 2204 { 2205 off_t sectors; 2206 2207 switch(delete_method) { 2208 case DA_DELETE_UNMAP: 2209 sectors = (off_t)softc->unmap_max_lba; 2210 break; 2211 case DA_DELETE_ATA_TRIM: 2212 sectors = (off_t)ATA_DSM_RANGE_MAX * softc->trim_max_ranges; 2213 break; 2214 case DA_DELETE_WS16: 2215 sectors = omin(softc->ws_max_blks, WS16_MAX_BLKS); 2216 break; 2217 case DA_DELETE_ZERO: 2218 case DA_DELETE_WS10: 2219 sectors = omin(softc->ws_max_blks, WS10_MAX_BLKS); 2220 break; 2221 default: 2222 return 0; 2223 } 2224 2225 return (off_t)softc->params.secsize * 2226 omin(sectors, softc->params.sectors); 2227 } 2228 2229 static void 2230 daprobedone(struct cam_periph *periph, union ccb *ccb) 2231 { 2232 struct da_softc *softc; 2233 2234 softc = (struct da_softc *)periph->softc; 2235 2236 dadeletemethodchoose(softc, DA_DELETE_NONE); 2237 2238 if (bootverbose && (softc->flags & DA_FLAG_ANNOUNCED) == 0) { 2239 char buf[80]; 2240 int i, sep; 2241 2242 snprintf(buf, sizeof(buf), "Delete methods: <"); 2243 sep = 0; 2244 for (i = 0; i <= DA_DELETE_MAX; i++) { 2245 if ((softc->delete_available & (1 << i)) == 0 && 2246 i != softc->delete_method) 2247 continue; 2248 if (sep) 2249 strlcat(buf, ",", sizeof(buf)); 2250 strlcat(buf, da_delete_method_names[i], 2251 sizeof(buf)); 2252 if (i == softc->delete_method) 2253 strlcat(buf, "(*)", sizeof(buf)); 2254 sep = 1; 2255 } 2256 strlcat(buf, ">", sizeof(buf)); 2257 printf("%s%d: %s\n", periph->periph_name, 2258 periph->unit_number, buf); 2259 } 2260 2261 /* 2262 * Since our peripheral may be invalidated by an error 2263 * above or an external event, we must release our CCB 2264 * before releasing the probe lock on the peripheral. 2265 * The peripheral will only go away once the last lock 2266 * is removed, and we need it around for the CCB release 2267 * operation. 2268 */ 2269 xpt_release_ccb(ccb); 2270 softc->state = DA_STATE_NORMAL; 2271 softc->flags |= DA_FLAG_PROBED; 2272 daschedule(periph); 2273 wakeup(&softc->disk->d_mediasize); 2274 if ((softc->flags & DA_FLAG_ANNOUNCED) == 0) { 2275 softc->flags |= DA_FLAG_ANNOUNCED; 2276 cam_periph_unhold(periph); 2277 } else 2278 cam_periph_release_locked(periph); 2279 } 2280 2281 static void 2282 dadeletemethodchoose(struct da_softc *softc, da_delete_methods default_method) 2283 { 2284 int i, methods; 2285 2286 /* If available, prefer the method requested by user. */ 2287 i = softc->delete_method_pref; 2288 methods = softc->delete_available | (1 << DA_DELETE_DISABLE); 2289 if (methods & (1 << i)) { 2290 dadeletemethodset(softc, i); 2291 return; 2292 } 2293 2294 /* Use the pre-defined order to choose the best performing delete. */ 2295 for (i = DA_DELETE_MIN; i <= DA_DELETE_MAX; i++) { 2296 if (i == DA_DELETE_ZERO) 2297 continue; 2298 if (softc->delete_available & (1 << i)) { 2299 dadeletemethodset(softc, i); 2300 return; 2301 } 2302 } 2303 2304 /* Fallback to default. */ 2305 dadeletemethodset(softc, default_method); 2306 } 2307 2308 static int 2309 dadeletemethodsysctl(SYSCTL_HANDLER_ARGS) 2310 { 2311 char buf[16]; 2312 const char *p; 2313 struct da_softc *softc; 2314 int i, error, methods, value; 2315 2316 softc = (struct da_softc *)arg1; 2317 2318 value = softc->delete_method; 2319 if (value < 0 || value > DA_DELETE_MAX) 2320 p = "UNKNOWN"; 2321 else 2322 p = da_delete_method_names[value]; 2323 strncpy(buf, p, sizeof(buf)); 2324 error = sysctl_handle_string(oidp, buf, sizeof(buf), req); 2325 if (error != 0 || req->newptr == NULL) 2326 return (error); 2327 methods = softc->delete_available | (1 << DA_DELETE_DISABLE); 2328 for (i = 0; i <= DA_DELETE_MAX; i++) { 2329 if (strcmp(buf, da_delete_method_names[i]) == 0) 2330 break; 2331 } 2332 if (i > DA_DELETE_MAX) 2333 return (EINVAL); 2334 softc->delete_method_pref = i; 2335 dadeletemethodchoose(softc, DA_DELETE_NONE); 2336 return (0); 2337 } 2338 2339 static int 2340 dazonemodesysctl(SYSCTL_HANDLER_ARGS) 2341 { 2342 char tmpbuf[40]; 2343 struct da_softc *softc; 2344 int error; 2345 2346 softc = (struct da_softc *)arg1; 2347 2348 switch (softc->zone_mode) { 2349 case DA_ZONE_DRIVE_MANAGED: 2350 snprintf(tmpbuf, sizeof(tmpbuf), "Drive Managed"); 2351 break; 2352 case DA_ZONE_HOST_AWARE: 2353 snprintf(tmpbuf, sizeof(tmpbuf), "Host Aware"); 2354 break; 2355 case DA_ZONE_HOST_MANAGED: 2356 snprintf(tmpbuf, sizeof(tmpbuf), "Host Managed"); 2357 break; 2358 case DA_ZONE_NONE: 2359 default: 2360 snprintf(tmpbuf, sizeof(tmpbuf), "Not Zoned"); 2361 break; 2362 } 2363 2364 error = sysctl_handle_string(oidp, tmpbuf, sizeof(tmpbuf), req); 2365 2366 return (error); 2367 } 2368 2369 static int 2370 dazonesupsysctl(SYSCTL_HANDLER_ARGS) 2371 { 2372 char tmpbuf[180]; 2373 struct da_softc *softc; 2374 struct sbuf sb; 2375 int error, first; 2376 unsigned int i; 2377 2378 softc = (struct da_softc *)arg1; 2379 2380 error = 0; 2381 first = 1; 2382 sbuf_new(&sb, tmpbuf, sizeof(tmpbuf), 0); 2383 2384 for (i = 0; i < sizeof(da_zone_desc_table) / 2385 sizeof(da_zone_desc_table[0]); i++) { 2386 if (softc->zone_flags & da_zone_desc_table[i].value) { 2387 if (first == 0) 2388 sbuf_printf(&sb, ", "); 2389 else 2390 first = 0; 2391 sbuf_cat(&sb, da_zone_desc_table[i].desc); 2392 } 2393 } 2394 2395 if (first == 1) 2396 sbuf_printf(&sb, "None"); 2397 2398 sbuf_finish(&sb); 2399 2400 error = sysctl_handle_string(oidp, sbuf_data(&sb), sbuf_len(&sb), req); 2401 2402 return (error); 2403 } 2404 2405 static cam_status 2406 daregister(struct cam_periph *periph, void *arg) 2407 { 2408 struct da_softc *softc; 2409 struct ccb_pathinq cpi; 2410 struct ccb_getdev *cgd; 2411 char tmpstr[80]; 2412 caddr_t match; 2413 2414 cgd = (struct ccb_getdev *)arg; 2415 if (cgd == NULL) { 2416 printf("daregister: no getdev CCB, can't register device\n"); 2417 return(CAM_REQ_CMP_ERR); 2418 } 2419 2420 softc = (struct da_softc *)malloc(sizeof(*softc), M_DEVBUF, 2421 M_NOWAIT|M_ZERO); 2422 2423 if (softc == NULL) { 2424 printf("daregister: Unable to probe new device. " 2425 "Unable to allocate softc\n"); 2426 return(CAM_REQ_CMP_ERR); 2427 } 2428 2429 if (cam_iosched_init(&softc->cam_iosched, periph) != 0) { 2430 printf("daregister: Unable to probe new device. " 2431 "Unable to allocate iosched memory\n"); 2432 free(softc, M_DEVBUF); 2433 return(CAM_REQ_CMP_ERR); 2434 } 2435 2436 LIST_INIT(&softc->pending_ccbs); 2437 softc->state = DA_STATE_PROBE_RC; 2438 bioq_init(&softc->delete_run_queue); 2439 if (SID_IS_REMOVABLE(&cgd->inq_data)) 2440 softc->flags |= DA_FLAG_PACK_REMOVABLE; 2441 softc->unmap_max_ranges = UNMAP_MAX_RANGES; 2442 softc->unmap_max_lba = UNMAP_RANGE_MAX; 2443 softc->unmap_gran = 0; 2444 softc->unmap_gran_align = 0; 2445 softc->ws_max_blks = WS16_MAX_BLKS; 2446 softc->trim_max_ranges = ATA_TRIM_MAX_RANGES; 2447 softc->rotating = 1; 2448 2449 periph->softc = softc; 2450 2451 /* 2452 * See if this device has any quirks. 2453 */ 2454 match = cam_quirkmatch((caddr_t)&cgd->inq_data, 2455 (caddr_t)da_quirk_table, 2456 nitems(da_quirk_table), 2457 sizeof(*da_quirk_table), scsi_inquiry_match); 2458 2459 if (match != NULL) 2460 softc->quirks = ((struct da_quirk_entry *)match)->quirks; 2461 else 2462 softc->quirks = DA_Q_NONE; 2463 2464 /* Check if the SIM does not want 6 byte commands */ 2465 bzero(&cpi, sizeof(cpi)); 2466 xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 2467 cpi.ccb_h.func_code = XPT_PATH_INQ; 2468 xpt_action((union ccb *)&cpi); 2469 if (cpi.ccb_h.status == CAM_REQ_CMP && (cpi.hba_misc & PIM_NO_6_BYTE)) 2470 softc->quirks |= DA_Q_NO_6_BYTE; 2471 2472 if (SID_TYPE(&cgd->inq_data) == T_ZBC_HM) 2473 softc->zone_mode = DA_ZONE_HOST_MANAGED; 2474 else if (softc->quirks & DA_Q_SMR_DM) 2475 softc->zone_mode = DA_ZONE_DRIVE_MANAGED; 2476 else 2477 softc->zone_mode = DA_ZONE_NONE; 2478 2479 if (softc->zone_mode != DA_ZONE_NONE) { 2480 if (scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) { 2481 if (scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) 2482 softc->zone_interface = DA_ZONE_IF_ATA_SAT; 2483 else 2484 softc->zone_interface = DA_ZONE_IF_ATA_PASS; 2485 } else 2486 softc->zone_interface = DA_ZONE_IF_SCSI; 2487 } 2488 2489 TASK_INIT(&softc->sysctl_task, 0, dasysctlinit, periph); 2490 2491 /* 2492 * Take an exclusive refcount on the periph while dastart is called 2493 * to finish the probe. The reference will be dropped in dadone at 2494 * the end of probe. 2495 */ 2496 (void)cam_periph_hold(periph, PRIBIO); 2497 2498 /* 2499 * Schedule a periodic event to occasionally send an 2500 * ordered tag to a device. 2501 */ 2502 callout_init_mtx(&softc->sendordered_c, cam_periph_mtx(periph), 0); 2503 callout_reset(&softc->sendordered_c, 2504 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL, 2505 dasendorderedtag, softc); 2506 2507 cam_periph_unlock(periph); 2508 /* 2509 * RBC devices don't have to support READ(6), only READ(10). 2510 */ 2511 if (softc->quirks & DA_Q_NO_6_BYTE || SID_TYPE(&cgd->inq_data) == T_RBC) 2512 softc->minimum_cmd_size = 10; 2513 else 2514 softc->minimum_cmd_size = 6; 2515 2516 /* 2517 * Load the user's default, if any. 2518 */ 2519 snprintf(tmpstr, sizeof(tmpstr), "kern.cam.da.%d.minimum_cmd_size", 2520 periph->unit_number); 2521 TUNABLE_INT_FETCH(tmpstr, &softc->minimum_cmd_size); 2522 2523 /* 2524 * 6, 10, 12 and 16 are the currently permissible values. 2525 */ 2526 if (softc->minimum_cmd_size > 12) 2527 softc->minimum_cmd_size = 16; 2528 else if (softc->minimum_cmd_size > 10) 2529 softc->minimum_cmd_size = 12; 2530 else if (softc->minimum_cmd_size > 6) 2531 softc->minimum_cmd_size = 10; 2532 else 2533 softc->minimum_cmd_size = 6; 2534 2535 /* Predict whether device may support READ CAPACITY(16). */ 2536 if (SID_ANSI_REV(&cgd->inq_data) >= SCSI_REV_SPC3 && 2537 (softc->quirks & DA_Q_NO_RC16) == 0) { 2538 softc->flags |= DA_FLAG_CAN_RC16; 2539 softc->state = DA_STATE_PROBE_RC16; 2540 } 2541 2542 /* 2543 * Register this media as a disk. 2544 */ 2545 softc->disk = disk_alloc(); 2546 softc->disk->d_devstat = devstat_new_entry(periph->periph_name, 2547 periph->unit_number, 0, 2548 DEVSTAT_BS_UNAVAILABLE, 2549 SID_TYPE(&cgd->inq_data) | 2550 XPORT_DEVSTAT_TYPE(cpi.transport), 2551 DEVSTAT_PRIORITY_DISK); 2552 softc->disk->d_open = daopen; 2553 softc->disk->d_close = daclose; 2554 softc->disk->d_strategy = dastrategy; 2555 softc->disk->d_dump = dadump; 2556 softc->disk->d_getattr = dagetattr; 2557 softc->disk->d_gone = dadiskgonecb; 2558 softc->disk->d_name = "da"; 2559 softc->disk->d_drv1 = periph; 2560 if (cpi.maxio == 0) 2561 softc->maxio = DFLTPHYS; /* traditional default */ 2562 else if (cpi.maxio > MAXPHYS) 2563 softc->maxio = MAXPHYS; /* for safety */ 2564 else 2565 softc->maxio = cpi.maxio; 2566 softc->disk->d_maxsize = softc->maxio; 2567 softc->disk->d_unit = periph->unit_number; 2568 softc->disk->d_flags = DISKFLAG_DIRECT_COMPLETION | DISKFLAG_CANZONE; 2569 if ((softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) 2570 softc->disk->d_flags |= DISKFLAG_CANFLUSHCACHE; 2571 if ((cpi.hba_misc & PIM_UNMAPPED) != 0) { 2572 softc->unmappedio = 1; 2573 softc->disk->d_flags |= DISKFLAG_UNMAPPED_BIO; 2574 } 2575 cam_strvis(softc->disk->d_descr, cgd->inq_data.vendor, 2576 sizeof(cgd->inq_data.vendor), sizeof(softc->disk->d_descr)); 2577 strlcat(softc->disk->d_descr, " ", sizeof(softc->disk->d_descr)); 2578 cam_strvis(&softc->disk->d_descr[strlen(softc->disk->d_descr)], 2579 cgd->inq_data.product, sizeof(cgd->inq_data.product), 2580 sizeof(softc->disk->d_descr) - strlen(softc->disk->d_descr)); 2581 softc->disk->d_hba_vendor = cpi.hba_vendor; 2582 softc->disk->d_hba_device = cpi.hba_device; 2583 softc->disk->d_hba_subvendor = cpi.hba_subvendor; 2584 softc->disk->d_hba_subdevice = cpi.hba_subdevice; 2585 2586 /* 2587 * Acquire a reference to the periph before we register with GEOM. 2588 * We'll release this reference once GEOM calls us back (via 2589 * dadiskgonecb()) telling us that our provider has been freed. 2590 */ 2591 if (cam_periph_acquire(periph) != CAM_REQ_CMP) { 2592 xpt_print(periph->path, "%s: lost periph during " 2593 "registration!\n", __func__); 2594 cam_periph_lock(periph); 2595 return (CAM_REQ_CMP_ERR); 2596 } 2597 2598 disk_create(softc->disk, DISK_VERSION); 2599 cam_periph_lock(periph); 2600 2601 /* 2602 * Add async callbacks for events of interest. 2603 * I don't bother checking if this fails as, 2604 * in most cases, the system will function just 2605 * fine without them and the only alternative 2606 * would be to not attach the device on failure. 2607 */ 2608 xpt_register_async(AC_SENT_BDR | AC_BUS_RESET | AC_LOST_DEVICE | 2609 AC_ADVINFO_CHANGED | AC_SCSI_AEN | AC_UNIT_ATTENTION | 2610 AC_INQ_CHANGED, daasync, periph, periph->path); 2611 2612 /* 2613 * Emit an attribute changed notification just in case 2614 * physical path information arrived before our async 2615 * event handler was registered, but after anyone attaching 2616 * to our disk device polled it. 2617 */ 2618 disk_attr_changed(softc->disk, "GEOM::physpath", M_NOWAIT); 2619 2620 /* 2621 * Schedule a periodic media polling events. 2622 */ 2623 callout_init_mtx(&softc->mediapoll_c, cam_periph_mtx(periph), 0); 2624 if ((softc->flags & DA_FLAG_PACK_REMOVABLE) && 2625 (cgd->inq_flags & SID_AEN) == 0 && 2626 da_poll_period != 0) 2627 callout_reset(&softc->mediapoll_c, da_poll_period * hz, 2628 damediapoll, periph); 2629 2630 xpt_schedule(periph, CAM_PRIORITY_DEV); 2631 2632 return(CAM_REQ_CMP); 2633 } 2634 2635 static int 2636 da_zone_bio_to_scsi(int disk_zone_cmd) 2637 { 2638 switch (disk_zone_cmd) { 2639 case DISK_ZONE_OPEN: 2640 return ZBC_OUT_SA_OPEN; 2641 case DISK_ZONE_CLOSE: 2642 return ZBC_OUT_SA_CLOSE; 2643 case DISK_ZONE_FINISH: 2644 return ZBC_OUT_SA_FINISH; 2645 case DISK_ZONE_RWP: 2646 return ZBC_OUT_SA_RWP; 2647 } 2648 2649 return -1; 2650 } 2651 2652 static int 2653 da_zone_cmd(struct cam_periph *periph, union ccb *ccb, struct bio *bp, 2654 int *queue_ccb) 2655 { 2656 struct da_softc *softc; 2657 int error; 2658 2659 error = 0; 2660 2661 if (bp->bio_cmd != BIO_ZONE) { 2662 error = EINVAL; 2663 goto bailout; 2664 } 2665 2666 softc = periph->softc; 2667 2668 switch (bp->bio_zone.zone_cmd) { 2669 case DISK_ZONE_OPEN: 2670 case DISK_ZONE_CLOSE: 2671 case DISK_ZONE_FINISH: 2672 case DISK_ZONE_RWP: { 2673 int zone_flags; 2674 int zone_sa; 2675 uint64_t lba; 2676 2677 zone_sa = da_zone_bio_to_scsi(bp->bio_zone.zone_cmd); 2678 if (zone_sa == -1) { 2679 xpt_print(periph->path, "Cannot translate zone " 2680 "cmd %#x to SCSI\n", bp->bio_zone.zone_cmd); 2681 error = EINVAL; 2682 goto bailout; 2683 } 2684 2685 zone_flags = 0; 2686 lba = bp->bio_zone.zone_params.rwp.id; 2687 2688 if (bp->bio_zone.zone_params.rwp.flags & 2689 DISK_ZONE_RWP_FLAG_ALL) 2690 zone_flags |= ZBC_OUT_ALL; 2691 2692 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) { 2693 scsi_zbc_out(&ccb->csio, 2694 /*retries*/ da_retry_count, 2695 /*cbfcnp*/ dadone, 2696 /*tag_action*/ MSG_SIMPLE_Q_TAG, 2697 /*service_action*/ zone_sa, 2698 /*zone_id*/ lba, 2699 /*zone_flags*/ zone_flags, 2700 /*data_ptr*/ NULL, 2701 /*dxfer_len*/ 0, 2702 /*sense_len*/ SSD_FULL_SIZE, 2703 /*timeout*/ da_default_timeout * 1000); 2704 } else { 2705 /* 2706 * Note that in this case, even though we can 2707 * technically use NCQ, we don't bother for several 2708 * reasons: 2709 * 1. It hasn't been tested on a SAT layer that 2710 * supports it. This is new as of SAT-4. 2711 * 2. Even when there is a SAT layer that supports 2712 * it, that SAT layer will also probably support 2713 * ZBC -> ZAC translation, since they are both 2714 * in the SAT-4 spec. 2715 * 3. Translation will likely be preferable to ATA 2716 * passthrough. LSI / Avago at least single 2717 * steps ATA passthrough commands in the HBA, 2718 * regardless of protocol, so unless that 2719 * changes, there is a performance penalty for 2720 * doing ATA passthrough no matter whether 2721 * you're using NCQ/FPDMA, DMA or PIO. 2722 * 4. It requires a 32-byte CDB, which at least at 2723 * this point in CAM requires a CDB pointer, which 2724 * would require us to allocate an additional bit 2725 * of storage separate from the CCB. 2726 */ 2727 error = scsi_ata_zac_mgmt_out(&ccb->csio, 2728 /*retries*/ da_retry_count, 2729 /*cbfcnp*/ dadone, 2730 /*tag_action*/ MSG_SIMPLE_Q_TAG, 2731 /*use_ncq*/ 0, 2732 /*zm_action*/ zone_sa, 2733 /*zone_id*/ lba, 2734 /*zone_flags*/ zone_flags, 2735 /*data_ptr*/ NULL, 2736 /*dxfer_len*/ 0, 2737 /*cdb_storage*/ NULL, 2738 /*cdb_storage_len*/ 0, 2739 /*sense_len*/ SSD_FULL_SIZE, 2740 /*timeout*/ da_default_timeout * 1000); 2741 if (error != 0) { 2742 error = EINVAL; 2743 xpt_print(periph->path, 2744 "scsi_ata_zac_mgmt_out() returned an " 2745 "error!"); 2746 goto bailout; 2747 } 2748 } 2749 *queue_ccb = 1; 2750 2751 break; 2752 } 2753 case DISK_ZONE_REPORT_ZONES: { 2754 uint8_t *rz_ptr; 2755 uint32_t num_entries, alloc_size; 2756 struct disk_zone_report *rep; 2757 2758 rep = &bp->bio_zone.zone_params.report; 2759 2760 num_entries = rep->entries_allocated; 2761 if (num_entries == 0) { 2762 xpt_print(periph->path, "No entries allocated for " 2763 "Report Zones request\n"); 2764 error = EINVAL; 2765 goto bailout; 2766 } 2767 alloc_size = sizeof(struct scsi_report_zones_hdr) + 2768 (sizeof(struct scsi_report_zones_desc) * num_entries); 2769 alloc_size = min(alloc_size, softc->disk->d_maxsize); 2770 rz_ptr = malloc(alloc_size, M_SCSIDA, M_NOWAIT | M_ZERO); 2771 if (rz_ptr == NULL) { 2772 xpt_print(periph->path, "Unable to allocate memory " 2773 "for Report Zones request\n"); 2774 error = ENOMEM; 2775 goto bailout; 2776 } 2777 2778 if (softc->zone_interface != DA_ZONE_IF_ATA_PASS) { 2779 scsi_zbc_in(&ccb->csio, 2780 /*retries*/ da_retry_count, 2781 /*cbcfnp*/ dadone, 2782 /*tag_action*/ MSG_SIMPLE_Q_TAG, 2783 /*service_action*/ ZBC_IN_SA_REPORT_ZONES, 2784 /*zone_start_lba*/ rep->starting_id, 2785 /*zone_options*/ rep->rep_options, 2786 /*data_ptr*/ rz_ptr, 2787 /*dxfer_len*/ alloc_size, 2788 /*sense_len*/ SSD_FULL_SIZE, 2789 /*timeout*/ da_default_timeout * 1000); 2790 } else { 2791 /* 2792 * Note that in this case, even though we can 2793 * technically use NCQ, we don't bother for several 2794 * reasons: 2795 * 1. It hasn't been tested on a SAT layer that 2796 * supports it. This is new as of SAT-4. 2797 * 2. Even when there is a SAT layer that supports 2798 * it, that SAT layer will also probably support 2799 * ZBC -> ZAC translation, since they are both 2800 * in the SAT-4 spec. 2801 * 3. Translation will likely be preferable to ATA 2802 * passthrough. LSI / Avago at least single 2803 * steps ATA passthrough commands in the HBA, 2804 * regardless of protocol, so unless that 2805 * changes, there is a performance penalty for 2806 * doing ATA passthrough no matter whether 2807 * you're using NCQ/FPDMA, DMA or PIO. 2808 * 4. It requires a 32-byte CDB, which at least at 2809 * this point in CAM requires a CDB pointer, which 2810 * would require us to allocate an additional bit 2811 * of storage separate from the CCB. 2812 */ 2813 error = scsi_ata_zac_mgmt_in(&ccb->csio, 2814 /*retries*/ da_retry_count, 2815 /*cbcfnp*/ dadone, 2816 /*tag_action*/ MSG_SIMPLE_Q_TAG, 2817 /*use_ncq*/ 0, 2818 /*zm_action*/ ATA_ZM_REPORT_ZONES, 2819 /*zone_id*/ rep->starting_id, 2820 /*zone_flags*/ rep->rep_options, 2821 /*data_ptr*/ rz_ptr, 2822 /*dxfer_len*/ alloc_size, 2823 /*cdb_storage*/ NULL, 2824 /*cdb_storage_len*/ 0, 2825 /*sense_len*/ SSD_FULL_SIZE, 2826 /*timeout*/ da_default_timeout * 1000); 2827 if (error != 0) { 2828 error = EINVAL; 2829 xpt_print(periph->path, 2830 "scsi_ata_zac_mgmt_in() returned an " 2831 "error!"); 2832 goto bailout; 2833 } 2834 } 2835 2836 /* 2837 * For BIO_ZONE, this isn't normally needed. However, it 2838 * is used by devstat_end_transaction_bio() to determine 2839 * how much data was transferred. 2840 */ 2841 /* 2842 * XXX KDM we have a problem. But I'm not sure how to fix 2843 * it. devstat uses bio_bcount - bio_resid to calculate 2844 * the amount of data transferred. The GEOM disk code 2845 * uses bio_length - bio_resid to calculate the amount of 2846 * data in bio_completed. We have different structure 2847 * sizes above and below the ada(4) driver. So, if we 2848 * use the sizes above, the amount transferred won't be 2849 * quite accurate for devstat. If we use different sizes 2850 * for bio_bcount and bio_length (above and below 2851 * respectively), then the residual needs to match one or 2852 * the other. Everything is calculated after the bio 2853 * leaves the driver, so changing the values around isn't 2854 * really an option. For now, just set the count to the 2855 * passed in length. This means that the calculations 2856 * above (e.g. bio_completed) will be correct, but the 2857 * amount of data reported to devstat will be slightly 2858 * under or overstated. 2859 */ 2860 bp->bio_bcount = bp->bio_length; 2861 2862 *queue_ccb = 1; 2863 2864 break; 2865 } 2866 case DISK_ZONE_GET_PARAMS: { 2867 struct disk_zone_disk_params *params; 2868 2869 params = &bp->bio_zone.zone_params.disk_params; 2870 bzero(params, sizeof(*params)); 2871 2872 switch (softc->zone_mode) { 2873 case DA_ZONE_DRIVE_MANAGED: 2874 params->zone_mode = DISK_ZONE_MODE_DRIVE_MANAGED; 2875 break; 2876 case DA_ZONE_HOST_AWARE: 2877 params->zone_mode = DISK_ZONE_MODE_HOST_AWARE; 2878 break; 2879 case DA_ZONE_HOST_MANAGED: 2880 params->zone_mode = DISK_ZONE_MODE_HOST_MANAGED; 2881 break; 2882 default: 2883 case DA_ZONE_NONE: 2884 params->zone_mode = DISK_ZONE_MODE_NONE; 2885 break; 2886 } 2887 2888 if (softc->zone_flags & DA_ZONE_FLAG_URSWRZ) 2889 params->flags |= DISK_ZONE_DISK_URSWRZ; 2890 2891 if (softc->zone_flags & DA_ZONE_FLAG_OPT_SEQ_SET) { 2892 params->optimal_seq_zones = softc->optimal_seq_zones; 2893 params->flags |= DISK_ZONE_OPT_SEQ_SET; 2894 } 2895 2896 if (softc->zone_flags & DA_ZONE_FLAG_OPT_NONSEQ_SET) { 2897 params->optimal_nonseq_zones = 2898 softc->optimal_nonseq_zones; 2899 params->flags |= DISK_ZONE_OPT_NONSEQ_SET; 2900 } 2901 2902 if (softc->zone_flags & DA_ZONE_FLAG_MAX_SEQ_SET) { 2903 params->max_seq_zones = softc->max_seq_zones; 2904 params->flags |= DISK_ZONE_MAX_SEQ_SET; 2905 } 2906 if (softc->zone_flags & DA_ZONE_FLAG_RZ_SUP) 2907 params->flags |= DISK_ZONE_RZ_SUP; 2908 2909 if (softc->zone_flags & DA_ZONE_FLAG_OPEN_SUP) 2910 params->flags |= DISK_ZONE_OPEN_SUP; 2911 2912 if (softc->zone_flags & DA_ZONE_FLAG_CLOSE_SUP) 2913 params->flags |= DISK_ZONE_CLOSE_SUP; 2914 2915 if (softc->zone_flags & DA_ZONE_FLAG_FINISH_SUP) 2916 params->flags |= DISK_ZONE_FINISH_SUP; 2917 2918 if (softc->zone_flags & DA_ZONE_FLAG_RWP_SUP) 2919 params->flags |= DISK_ZONE_RWP_SUP; 2920 break; 2921 } 2922 default: 2923 break; 2924 } 2925 bailout: 2926 return (error); 2927 } 2928 2929 static void 2930 dastart(struct cam_periph *periph, union ccb *start_ccb) 2931 { 2932 struct da_softc *softc; 2933 2934 softc = (struct da_softc *)periph->softc; 2935 2936 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dastart\n")); 2937 2938 skipstate: 2939 switch (softc->state) { 2940 case DA_STATE_NORMAL: 2941 { 2942 struct bio *bp; 2943 uint8_t tag_code; 2944 2945 more: 2946 bp = cam_iosched_next_bio(softc->cam_iosched); 2947 if (bp == NULL) { 2948 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) { 2949 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR); 2950 scsi_test_unit_ready(&start_ccb->csio, 2951 /*retries*/ da_retry_count, 2952 dadone, 2953 MSG_SIMPLE_Q_TAG, 2954 SSD_FULL_SIZE, 2955 da_default_timeout * 1000); 2956 start_ccb->ccb_h.ccb_bp = NULL; 2957 start_ccb->ccb_h.ccb_state = DA_CCB_TUR; 2958 xpt_action(start_ccb); 2959 } else 2960 xpt_release_ccb(start_ccb); 2961 break; 2962 } 2963 2964 if (bp->bio_cmd == BIO_DELETE) { 2965 if (softc->delete_func != NULL) { 2966 softc->delete_func(periph, start_ccb, bp); 2967 goto out; 2968 } else { 2969 /* Not sure this is possible, but failsafe by lying and saying "sure, done." */ 2970 biofinish(bp, NULL, 0); 2971 goto more; 2972 } 2973 } 2974 2975 if (cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR)) { 2976 cam_iosched_clr_work_flags(softc->cam_iosched, DA_WORK_TUR); 2977 cam_periph_release_locked(periph); /* XXX is this still valid? I think so but unverified */ 2978 } 2979 2980 if ((bp->bio_flags & BIO_ORDERED) != 0 || 2981 (softc->flags & DA_FLAG_NEED_OTAG) != 0) { 2982 softc->flags &= ~DA_FLAG_NEED_OTAG; 2983 softc->flags |= DA_FLAG_WAS_OTAG; 2984 tag_code = MSG_ORDERED_Q_TAG; 2985 } else { 2986 tag_code = MSG_SIMPLE_Q_TAG; 2987 } 2988 2989 switch (bp->bio_cmd) { 2990 case BIO_WRITE: 2991 case BIO_READ: 2992 { 2993 void *data_ptr; 2994 int rw_op; 2995 2996 biotrack(bp, __func__); 2997 2998 if (bp->bio_cmd == BIO_WRITE) { 2999 softc->flags |= DA_FLAG_DIRTY; 3000 rw_op = SCSI_RW_WRITE; 3001 } else { 3002 rw_op = SCSI_RW_READ; 3003 } 3004 3005 data_ptr = bp->bio_data; 3006 if ((bp->bio_flags & (BIO_UNMAPPED|BIO_VLIST)) != 0) { 3007 rw_op |= SCSI_RW_BIO; 3008 data_ptr = bp; 3009 } 3010 3011 scsi_read_write(&start_ccb->csio, 3012 /*retries*/da_retry_count, 3013 /*cbfcnp*/dadone, 3014 /*tag_action*/tag_code, 3015 rw_op, 3016 /*byte2*/0, 3017 softc->minimum_cmd_size, 3018 /*lba*/bp->bio_pblkno, 3019 /*block_count*/bp->bio_bcount / 3020 softc->params.secsize, 3021 data_ptr, 3022 /*dxfer_len*/ bp->bio_bcount, 3023 /*sense_len*/SSD_FULL_SIZE, 3024 da_default_timeout * 1000); 3025 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) 3026 start_ccb->csio.bio = bp; 3027 #endif 3028 break; 3029 } 3030 case BIO_FLUSH: 3031 /* 3032 * BIO_FLUSH doesn't currently communicate 3033 * range data, so we synchronize the cache 3034 * over the whole disk. We also force 3035 * ordered tag semantics the flush applies 3036 * to all previously queued I/O. 3037 */ 3038 scsi_synchronize_cache(&start_ccb->csio, 3039 /*retries*/1, 3040 /*cbfcnp*/dadone, 3041 MSG_ORDERED_Q_TAG, 3042 /*begin_lba*/0, 3043 /*lb_count*/0, 3044 SSD_FULL_SIZE, 3045 da_default_timeout*1000); 3046 break; 3047 case BIO_ZONE: { 3048 int error, queue_ccb; 3049 3050 queue_ccb = 0; 3051 3052 error = da_zone_cmd(periph, start_ccb, bp,&queue_ccb); 3053 if ((error != 0) 3054 || (queue_ccb == 0)) { 3055 biofinish(bp, NULL, error); 3056 xpt_release_ccb(start_ccb); 3057 return; 3058 } 3059 break; 3060 } 3061 } 3062 start_ccb->ccb_h.ccb_state = DA_CCB_BUFFER_IO; 3063 start_ccb->ccb_h.flags |= CAM_UNLOCKED; 3064 start_ccb->ccb_h.softtimeout = sbttotv(da_default_softtimeout); 3065 3066 out: 3067 LIST_INSERT_HEAD(&softc->pending_ccbs, 3068 &start_ccb->ccb_h, periph_links.le); 3069 3070 /* We expect a unit attention from this device */ 3071 if ((softc->flags & DA_FLAG_RETRY_UA) != 0) { 3072 start_ccb->ccb_h.ccb_state |= DA_CCB_RETRY_UA; 3073 softc->flags &= ~DA_FLAG_RETRY_UA; 3074 } 3075 3076 start_ccb->ccb_h.ccb_bp = bp; 3077 softc->refcount++; 3078 cam_periph_unlock(periph); 3079 xpt_action(start_ccb); 3080 cam_periph_lock(periph); 3081 softc->refcount--; 3082 3083 /* May have more work to do, so ensure we stay scheduled */ 3084 daschedule(periph); 3085 break; 3086 } 3087 case DA_STATE_PROBE_RC: 3088 { 3089 struct scsi_read_capacity_data *rcap; 3090 3091 rcap = (struct scsi_read_capacity_data *) 3092 malloc(sizeof(*rcap), M_SCSIDA, M_NOWAIT|M_ZERO); 3093 if (rcap == NULL) { 3094 printf("dastart: Couldn't malloc read_capacity data\n"); 3095 /* da_free_periph??? */ 3096 break; 3097 } 3098 scsi_read_capacity(&start_ccb->csio, 3099 /*retries*/da_retry_count, 3100 dadone, 3101 MSG_SIMPLE_Q_TAG, 3102 rcap, 3103 SSD_FULL_SIZE, 3104 /*timeout*/5000); 3105 start_ccb->ccb_h.ccb_bp = NULL; 3106 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC; 3107 xpt_action(start_ccb); 3108 break; 3109 } 3110 case DA_STATE_PROBE_RC16: 3111 { 3112 struct scsi_read_capacity_data_long *rcaplong; 3113 3114 rcaplong = (struct scsi_read_capacity_data_long *) 3115 malloc(sizeof(*rcaplong), M_SCSIDA, M_NOWAIT|M_ZERO); 3116 if (rcaplong == NULL) { 3117 printf("dastart: Couldn't malloc read_capacity data\n"); 3118 /* da_free_periph??? */ 3119 break; 3120 } 3121 scsi_read_capacity_16(&start_ccb->csio, 3122 /*retries*/ da_retry_count, 3123 /*cbfcnp*/ dadone, 3124 /*tag_action*/ MSG_SIMPLE_Q_TAG, 3125 /*lba*/ 0, 3126 /*reladr*/ 0, 3127 /*pmi*/ 0, 3128 /*rcap_buf*/ (uint8_t *)rcaplong, 3129 /*rcap_buf_len*/ sizeof(*rcaplong), 3130 /*sense_len*/ SSD_FULL_SIZE, 3131 /*timeout*/ da_default_timeout * 1000); 3132 start_ccb->ccb_h.ccb_bp = NULL; 3133 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_RC16; 3134 xpt_action(start_ccb); 3135 break; 3136 } 3137 case DA_STATE_PROBE_LBP: 3138 { 3139 struct scsi_vpd_logical_block_prov *lbp; 3140 3141 if (!scsi_vpd_supported_page(periph, SVPD_LBP)) { 3142 /* 3143 * If we get here we don't support any SBC-3 delete 3144 * methods with UNMAP as the Logical Block Provisioning 3145 * VPD page support is required for devices which 3146 * support it according to T10/1799-D Revision 31 3147 * however older revisions of the spec don't mandate 3148 * this so we currently don't remove these methods 3149 * from the available set. 3150 */ 3151 softc->state = DA_STATE_PROBE_BLK_LIMITS; 3152 goto skipstate; 3153 } 3154 3155 lbp = (struct scsi_vpd_logical_block_prov *) 3156 malloc(sizeof(*lbp), M_SCSIDA, M_NOWAIT|M_ZERO); 3157 3158 if (lbp == NULL) { 3159 printf("dastart: Couldn't malloc lbp data\n"); 3160 /* da_free_periph??? */ 3161 break; 3162 } 3163 3164 scsi_inquiry(&start_ccb->csio, 3165 /*retries*/da_retry_count, 3166 /*cbfcnp*/dadone, 3167 /*tag_action*/MSG_SIMPLE_Q_TAG, 3168 /*inq_buf*/(u_int8_t *)lbp, 3169 /*inq_len*/sizeof(*lbp), 3170 /*evpd*/TRUE, 3171 /*page_code*/SVPD_LBP, 3172 /*sense_len*/SSD_MIN_SIZE, 3173 /*timeout*/da_default_timeout * 1000); 3174 start_ccb->ccb_h.ccb_bp = NULL; 3175 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_LBP; 3176 xpt_action(start_ccb); 3177 break; 3178 } 3179 case DA_STATE_PROBE_BLK_LIMITS: 3180 { 3181 struct scsi_vpd_block_limits *block_limits; 3182 3183 if (!scsi_vpd_supported_page(periph, SVPD_BLOCK_LIMITS)) { 3184 /* Not supported skip to next probe */ 3185 softc->state = DA_STATE_PROBE_BDC; 3186 goto skipstate; 3187 } 3188 3189 block_limits = (struct scsi_vpd_block_limits *) 3190 malloc(sizeof(*block_limits), M_SCSIDA, M_NOWAIT|M_ZERO); 3191 3192 if (block_limits == NULL) { 3193 printf("dastart: Couldn't malloc block_limits data\n"); 3194 /* da_free_periph??? */ 3195 break; 3196 } 3197 3198 scsi_inquiry(&start_ccb->csio, 3199 /*retries*/da_retry_count, 3200 /*cbfcnp*/dadone, 3201 /*tag_action*/MSG_SIMPLE_Q_TAG, 3202 /*inq_buf*/(u_int8_t *)block_limits, 3203 /*inq_len*/sizeof(*block_limits), 3204 /*evpd*/TRUE, 3205 /*page_code*/SVPD_BLOCK_LIMITS, 3206 /*sense_len*/SSD_MIN_SIZE, 3207 /*timeout*/da_default_timeout * 1000); 3208 start_ccb->ccb_h.ccb_bp = NULL; 3209 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BLK_LIMITS; 3210 xpt_action(start_ccb); 3211 break; 3212 } 3213 case DA_STATE_PROBE_BDC: 3214 { 3215 struct scsi_vpd_block_characteristics *bdc; 3216 3217 if (!scsi_vpd_supported_page(periph, SVPD_BDC)) { 3218 softc->state = DA_STATE_PROBE_ATA; 3219 goto skipstate; 3220 } 3221 3222 bdc = (struct scsi_vpd_block_characteristics *) 3223 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO); 3224 3225 if (bdc == NULL) { 3226 printf("dastart: Couldn't malloc bdc data\n"); 3227 /* da_free_periph??? */ 3228 break; 3229 } 3230 3231 scsi_inquiry(&start_ccb->csio, 3232 /*retries*/da_retry_count, 3233 /*cbfcnp*/dadone, 3234 /*tag_action*/MSG_SIMPLE_Q_TAG, 3235 /*inq_buf*/(u_int8_t *)bdc, 3236 /*inq_len*/sizeof(*bdc), 3237 /*evpd*/TRUE, 3238 /*page_code*/SVPD_BDC, 3239 /*sense_len*/SSD_MIN_SIZE, 3240 /*timeout*/da_default_timeout * 1000); 3241 start_ccb->ccb_h.ccb_bp = NULL; 3242 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_BDC; 3243 xpt_action(start_ccb); 3244 break; 3245 } 3246 case DA_STATE_PROBE_ATA: 3247 { 3248 struct ata_params *ata_params; 3249 3250 if (!scsi_vpd_supported_page(periph, SVPD_ATA_INFORMATION)) { 3251 if ((softc->zone_mode == DA_ZONE_HOST_AWARE) 3252 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) { 3253 /* 3254 * Note that if the ATA VPD page isn't 3255 * supported, we aren't talking to an ATA 3256 * device anyway. Support for that VPD 3257 * page is mandatory for SCSI to ATA (SAT) 3258 * translation layers. 3259 */ 3260 softc->state = DA_STATE_PROBE_ZONE; 3261 goto skipstate; 3262 } 3263 daprobedone(periph, start_ccb); 3264 break; 3265 } 3266 3267 ata_params = (struct ata_params*) 3268 malloc(sizeof(*ata_params), M_SCSIDA,M_NOWAIT|M_ZERO); 3269 3270 if (ata_params == NULL) { 3271 xpt_print(periph->path, "Couldn't malloc ata_params " 3272 "data\n"); 3273 /* da_free_periph??? */ 3274 break; 3275 } 3276 3277 scsi_ata_identify(&start_ccb->csio, 3278 /*retries*/da_retry_count, 3279 /*cbfcnp*/dadone, 3280 /*tag_action*/MSG_SIMPLE_Q_TAG, 3281 /*data_ptr*/(u_int8_t *)ata_params, 3282 /*dxfer_len*/sizeof(*ata_params), 3283 /*sense_len*/SSD_FULL_SIZE, 3284 /*timeout*/da_default_timeout * 1000); 3285 start_ccb->ccb_h.ccb_bp = NULL; 3286 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA; 3287 xpt_action(start_ccb); 3288 break; 3289 } 3290 case DA_STATE_PROBE_ATA_LOGDIR: 3291 { 3292 struct ata_gp_log_dir *log_dir; 3293 int retval; 3294 3295 retval = 0; 3296 3297 if ((softc->flags & DA_FLAG_CAN_ATA_LOG) == 0) { 3298 /* 3299 * If we don't have log support, not much point in 3300 * trying to probe zone support. 3301 */ 3302 daprobedone(periph, start_ccb); 3303 break; 3304 } 3305 3306 /* 3307 * If we have an ATA device (the SCSI ATA Information VPD 3308 * page should be present and the ATA identify should have 3309 * succeeded) and it supports logs, ask for the log directory. 3310 */ 3311 3312 log_dir = malloc(sizeof(*log_dir), M_SCSIDA, M_NOWAIT|M_ZERO); 3313 if (log_dir == NULL) { 3314 xpt_print(periph->path, "Couldn't malloc log_dir " 3315 "data\n"); 3316 daprobedone(periph, start_ccb); 3317 break; 3318 } 3319 3320 retval = scsi_ata_read_log(&start_ccb->csio, 3321 /*retries*/ da_retry_count, 3322 /*cbfcnp*/ dadone, 3323 /*tag_action*/ MSG_SIMPLE_Q_TAG, 3324 /*log_address*/ ATA_LOG_DIRECTORY, 3325 /*page_number*/ 0, 3326 /*block_count*/ 1, 3327 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ? 3328 AP_PROTO_DMA : AP_PROTO_PIO_IN, 3329 /*data_ptr*/ (uint8_t *)log_dir, 3330 /*dxfer_len*/ sizeof(*log_dir), 3331 /*sense_len*/ SSD_FULL_SIZE, 3332 /*timeout*/ da_default_timeout * 1000); 3333 3334 if (retval != 0) { 3335 xpt_print(periph->path, "scsi_ata_read_log() failed!"); 3336 free(log_dir, M_SCSIDA); 3337 daprobedone(periph, start_ccb); 3338 break; 3339 } 3340 start_ccb->ccb_h.ccb_bp = NULL; 3341 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_LOGDIR; 3342 xpt_action(start_ccb); 3343 break; 3344 } 3345 case DA_STATE_PROBE_ATA_IDDIR: 3346 { 3347 struct ata_identify_log_pages *id_dir; 3348 int retval; 3349 3350 retval = 0; 3351 3352 /* 3353 * Check here to see whether the Identify Device log is 3354 * supported in the directory of logs. If so, continue 3355 * with requesting the log of identify device pages. 3356 */ 3357 if ((softc->flags & DA_FLAG_CAN_ATA_IDLOG) == 0) { 3358 daprobedone(periph, start_ccb); 3359 break; 3360 } 3361 3362 id_dir = malloc(sizeof(*id_dir), M_SCSIDA, M_NOWAIT | M_ZERO); 3363 if (id_dir == NULL) { 3364 xpt_print(periph->path, "Couldn't malloc id_dir " 3365 "data\n"); 3366 daprobedone(periph, start_ccb); 3367 break; 3368 } 3369 3370 retval = scsi_ata_read_log(&start_ccb->csio, 3371 /*retries*/ da_retry_count, 3372 /*cbfcnp*/ dadone, 3373 /*tag_action*/ MSG_SIMPLE_Q_TAG, 3374 /*log_address*/ ATA_IDENTIFY_DATA_LOG, 3375 /*page_number*/ ATA_IDL_PAGE_LIST, 3376 /*block_count*/ 1, 3377 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ? 3378 AP_PROTO_DMA : AP_PROTO_PIO_IN, 3379 /*data_ptr*/ (uint8_t *)id_dir, 3380 /*dxfer_len*/ sizeof(*id_dir), 3381 /*sense_len*/ SSD_FULL_SIZE, 3382 /*timeout*/ da_default_timeout * 1000); 3383 3384 if (retval != 0) { 3385 xpt_print(periph->path, "scsi_ata_read_log() failed!"); 3386 free(id_dir, M_SCSIDA); 3387 daprobedone(periph, start_ccb); 3388 break; 3389 } 3390 start_ccb->ccb_h.ccb_bp = NULL; 3391 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_IDDIR; 3392 xpt_action(start_ccb); 3393 break; 3394 } 3395 case DA_STATE_PROBE_ATA_SUP: 3396 { 3397 struct ata_identify_log_sup_cap *sup_cap; 3398 int retval; 3399 3400 retval = 0; 3401 3402 /* 3403 * Check here to see whether the Supported Capabilities log 3404 * is in the list of Identify Device logs. 3405 */ 3406 if ((softc->flags & DA_FLAG_CAN_ATA_SUPCAP) == 0) { 3407 daprobedone(periph, start_ccb); 3408 break; 3409 } 3410 3411 sup_cap = malloc(sizeof(*sup_cap), M_SCSIDA, M_NOWAIT|M_ZERO); 3412 if (sup_cap == NULL) { 3413 xpt_print(periph->path, "Couldn't malloc sup_cap " 3414 "data\n"); 3415 daprobedone(periph, start_ccb); 3416 break; 3417 } 3418 3419 retval = scsi_ata_read_log(&start_ccb->csio, 3420 /*retries*/ da_retry_count, 3421 /*cbfcnp*/ dadone, 3422 /*tag_action*/ MSG_SIMPLE_Q_TAG, 3423 /*log_address*/ ATA_IDENTIFY_DATA_LOG, 3424 /*page_number*/ ATA_IDL_SUP_CAP, 3425 /*block_count*/ 1, 3426 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ? 3427 AP_PROTO_DMA : AP_PROTO_PIO_IN, 3428 /*data_ptr*/ (uint8_t *)sup_cap, 3429 /*dxfer_len*/ sizeof(*sup_cap), 3430 /*sense_len*/ SSD_FULL_SIZE, 3431 /*timeout*/ da_default_timeout * 1000); 3432 3433 if (retval != 0) { 3434 xpt_print(periph->path, "scsi_ata_read_log() failed!"); 3435 free(sup_cap, M_SCSIDA); 3436 daprobedone(periph, start_ccb); 3437 break; 3438 3439 } 3440 3441 start_ccb->ccb_h.ccb_bp = NULL; 3442 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_SUP; 3443 xpt_action(start_ccb); 3444 break; 3445 } 3446 case DA_STATE_PROBE_ATA_ZONE: 3447 { 3448 struct ata_zoned_info_log *ata_zone; 3449 int retval; 3450 3451 retval = 0; 3452 3453 /* 3454 * Check here to see whether the zoned device information 3455 * page is supported. If so, continue on to request it. 3456 * If not, skip to DA_STATE_PROBE_LOG or done. 3457 */ 3458 if ((softc->flags & DA_FLAG_CAN_ATA_ZONE) == 0) { 3459 daprobedone(periph, start_ccb); 3460 break; 3461 } 3462 ata_zone = malloc(sizeof(*ata_zone), M_SCSIDA, 3463 M_NOWAIT|M_ZERO); 3464 if (ata_zone == NULL) { 3465 xpt_print(periph->path, "Couldn't malloc ata_zone " 3466 "data\n"); 3467 daprobedone(periph, start_ccb); 3468 break; 3469 } 3470 3471 retval = scsi_ata_read_log(&start_ccb->csio, 3472 /*retries*/ da_retry_count, 3473 /*cbfcnp*/ dadone, 3474 /*tag_action*/ MSG_SIMPLE_Q_TAG, 3475 /*log_address*/ ATA_IDENTIFY_DATA_LOG, 3476 /*page_number*/ ATA_IDL_ZDI, 3477 /*block_count*/ 1, 3478 /*protocol*/ softc->flags & DA_FLAG_CAN_ATA_DMA ? 3479 AP_PROTO_DMA : AP_PROTO_PIO_IN, 3480 /*data_ptr*/ (uint8_t *)ata_zone, 3481 /*dxfer_len*/ sizeof(*ata_zone), 3482 /*sense_len*/ SSD_FULL_SIZE, 3483 /*timeout*/ da_default_timeout * 1000); 3484 3485 if (retval != 0) { 3486 xpt_print(periph->path, "scsi_ata_read_log() failed!"); 3487 free(ata_zone, M_SCSIDA); 3488 daprobedone(periph, start_ccb); 3489 break; 3490 } 3491 start_ccb->ccb_h.ccb_bp = NULL; 3492 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ATA_ZONE; 3493 xpt_action(start_ccb); 3494 3495 break; 3496 } 3497 case DA_STATE_PROBE_ZONE: 3498 { 3499 struct scsi_vpd_zoned_bdc *bdc; 3500 3501 /* 3502 * Note that this page will be supported for SCSI protocol 3503 * devices that support ZBC (SMR devices), as well as ATA 3504 * protocol devices that are behind a SAT (SCSI to ATA 3505 * Translation) layer that supports converting ZBC commands 3506 * to their ZAC equivalents. 3507 */ 3508 if (!scsi_vpd_supported_page(periph, SVPD_ZONED_BDC)) { 3509 daprobedone(periph, start_ccb); 3510 break; 3511 } 3512 bdc = (struct scsi_vpd_zoned_bdc *) 3513 malloc(sizeof(*bdc), M_SCSIDA, M_NOWAIT|M_ZERO); 3514 3515 if (bdc == NULL) { 3516 xpt_release_ccb(start_ccb); 3517 xpt_print(periph->path, "Couldn't malloc zone VPD " 3518 "data\n"); 3519 break; 3520 } 3521 scsi_inquiry(&start_ccb->csio, 3522 /*retries*/da_retry_count, 3523 /*cbfcnp*/dadone, 3524 /*tag_action*/MSG_SIMPLE_Q_TAG, 3525 /*inq_buf*/(u_int8_t *)bdc, 3526 /*inq_len*/sizeof(*bdc), 3527 /*evpd*/TRUE, 3528 /*page_code*/SVPD_ZONED_BDC, 3529 /*sense_len*/SSD_FULL_SIZE, 3530 /*timeout*/da_default_timeout * 1000); 3531 start_ccb->ccb_h.ccb_bp = NULL; 3532 start_ccb->ccb_h.ccb_state = DA_CCB_PROBE_ZONE; 3533 xpt_action(start_ccb); 3534 break; 3535 } 3536 } 3537 } 3538 3539 /* 3540 * In each of the methods below, while its the caller's 3541 * responsibility to ensure the request will fit into a 3542 * single device request, we might have changed the delete 3543 * method due to the device incorrectly advertising either 3544 * its supported methods or limits. 3545 * 3546 * To prevent this causing further issues we validate the 3547 * against the methods limits, and warn which would 3548 * otherwise be unnecessary. 3549 */ 3550 static void 3551 da_delete_unmap(struct cam_periph *periph, union ccb *ccb, struct bio *bp) 3552 { 3553 struct da_softc *softc = (struct da_softc *)periph->softc;; 3554 struct bio *bp1; 3555 uint8_t *buf = softc->unmap_buf; 3556 struct scsi_unmap_desc *d = (void *)&buf[UNMAP_HEAD_SIZE]; 3557 uint64_t lba, lastlba = (uint64_t)-1; 3558 uint64_t totalcount = 0; 3559 uint64_t count; 3560 uint32_t c, lastcount = 0, ranges = 0; 3561 3562 /* 3563 * Currently this doesn't take the UNMAP 3564 * Granularity and Granularity Alignment 3565 * fields into account. 3566 * 3567 * This could result in both unoptimal unmap 3568 * requests as as well as UNMAP calls unmapping 3569 * fewer LBA's than requested. 3570 */ 3571 3572 bzero(softc->unmap_buf, sizeof(softc->unmap_buf)); 3573 bp1 = bp; 3574 do { 3575 /* 3576 * Note: ada and da are different in how they store the 3577 * pending bp's in a trim. ada stores all of them in the 3578 * trim_req.bps. da stores all but the first one in the 3579 * delete_run_queue. ada then completes all the bps in 3580 * its adadone() loop. da completes all the bps in the 3581 * delete_run_queue in dadone, and relies on the biodone 3582 * after to complete. This should be reconciled since there's 3583 * no real reason to do it differently. XXX 3584 */ 3585 if (bp1 != bp) 3586 bioq_insert_tail(&softc->delete_run_queue, bp1); 3587 lba = bp1->bio_pblkno; 3588 count = bp1->bio_bcount / softc->params.secsize; 3589 3590 /* Try to extend the previous range. */ 3591 if (lba == lastlba) { 3592 c = omin(count, UNMAP_RANGE_MAX - lastcount); 3593 lastlba += c; 3594 lastcount += c; 3595 scsi_ulto4b(lastcount, d[ranges - 1].length); 3596 count -= c; 3597 lba += c; 3598 totalcount += c; 3599 } else if ((softc->quirks & DA_Q_STRICT_UNMAP) && 3600 softc->unmap_gran != 0) { 3601 /* Align length of the previous range. */ 3602 if ((c = lastcount % softc->unmap_gran) != 0) { 3603 if (lastcount <= c) { 3604 totalcount -= lastcount; 3605 lastlba = (uint64_t)-1; 3606 lastcount = 0; 3607 ranges--; 3608 } else { 3609 totalcount -= c; 3610 lastlba -= c; 3611 lastcount -= c; 3612 scsi_ulto4b(lastcount, d[ranges - 1].length); 3613 } 3614 } 3615 /* Align beginning of the new range. */ 3616 c = (lba - softc->unmap_gran_align) % softc->unmap_gran; 3617 if (c != 0) { 3618 c = softc->unmap_gran - c; 3619 if (count <= c) { 3620 count = 0; 3621 } else { 3622 lba += c; 3623 count -= c; 3624 } 3625 } 3626 } 3627 3628 while (count > 0) { 3629 c = omin(count, UNMAP_RANGE_MAX); 3630 if (totalcount + c > softc->unmap_max_lba || 3631 ranges >= softc->unmap_max_ranges) { 3632 xpt_print(periph->path, 3633 "%s issuing short delete %ld > %ld" 3634 "|| %d >= %d", 3635 da_delete_method_desc[softc->delete_method], 3636 totalcount + c, softc->unmap_max_lba, 3637 ranges, softc->unmap_max_ranges); 3638 break; 3639 } 3640 scsi_u64to8b(lba, d[ranges].lba); 3641 scsi_ulto4b(c, d[ranges].length); 3642 lba += c; 3643 totalcount += c; 3644 ranges++; 3645 count -= c; 3646 lastlba = lba; 3647 lastcount = c; 3648 } 3649 bp1 = cam_iosched_next_trim(softc->cam_iosched); 3650 if (bp1 == NULL) 3651 break; 3652 if (ranges >= softc->unmap_max_ranges || 3653 totalcount + bp1->bio_bcount / 3654 softc->params.secsize > softc->unmap_max_lba) { 3655 cam_iosched_put_back_trim(softc->cam_iosched, bp1); 3656 break; 3657 } 3658 } while (1); 3659 3660 /* Align length of the last range. */ 3661 if ((softc->quirks & DA_Q_STRICT_UNMAP) && softc->unmap_gran != 0 && 3662 (c = lastcount % softc->unmap_gran) != 0) { 3663 if (lastcount <= c) 3664 ranges--; 3665 else 3666 scsi_ulto4b(lastcount - c, d[ranges - 1].length); 3667 } 3668 3669 scsi_ulto2b(ranges * 16 + 6, &buf[0]); 3670 scsi_ulto2b(ranges * 16, &buf[2]); 3671 3672 scsi_unmap(&ccb->csio, 3673 /*retries*/da_retry_count, 3674 /*cbfcnp*/dadone, 3675 /*tag_action*/MSG_SIMPLE_Q_TAG, 3676 /*byte2*/0, 3677 /*data_ptr*/ buf, 3678 /*dxfer_len*/ ranges * 16 + 8, 3679 /*sense_len*/SSD_FULL_SIZE, 3680 da_default_timeout * 1000); 3681 ccb->ccb_h.ccb_state = DA_CCB_DELETE; 3682 ccb->ccb_h.flags |= CAM_UNLOCKED; 3683 cam_iosched_submit_trim(softc->cam_iosched); 3684 } 3685 3686 static void 3687 da_delete_trim(struct cam_periph *periph, union ccb *ccb, struct bio *bp) 3688 { 3689 struct da_softc *softc = (struct da_softc *)periph->softc; 3690 struct bio *bp1; 3691 uint8_t *buf = softc->unmap_buf; 3692 uint64_t lastlba = (uint64_t)-1; 3693 uint64_t count; 3694 uint64_t lba; 3695 uint32_t lastcount = 0, c, requestcount; 3696 int ranges = 0, off, block_count; 3697 3698 bzero(softc->unmap_buf, sizeof(softc->unmap_buf)); 3699 bp1 = bp; 3700 do { 3701 if (bp1 != bp)//XXX imp XXX 3702 bioq_insert_tail(&softc->delete_run_queue, bp1); 3703 lba = bp1->bio_pblkno; 3704 count = bp1->bio_bcount / softc->params.secsize; 3705 requestcount = count; 3706 3707 /* Try to extend the previous range. */ 3708 if (lba == lastlba) { 3709 c = omin(count, ATA_DSM_RANGE_MAX - lastcount); 3710 lastcount += c; 3711 off = (ranges - 1) * 8; 3712 buf[off + 6] = lastcount & 0xff; 3713 buf[off + 7] = (lastcount >> 8) & 0xff; 3714 count -= c; 3715 lba += c; 3716 } 3717 3718 while (count > 0) { 3719 c = omin(count, ATA_DSM_RANGE_MAX); 3720 off = ranges * 8; 3721 3722 buf[off + 0] = lba & 0xff; 3723 buf[off + 1] = (lba >> 8) & 0xff; 3724 buf[off + 2] = (lba >> 16) & 0xff; 3725 buf[off + 3] = (lba >> 24) & 0xff; 3726 buf[off + 4] = (lba >> 32) & 0xff; 3727 buf[off + 5] = (lba >> 40) & 0xff; 3728 buf[off + 6] = c & 0xff; 3729 buf[off + 7] = (c >> 8) & 0xff; 3730 lba += c; 3731 ranges++; 3732 count -= c; 3733 lastcount = c; 3734 if (count != 0 && ranges == softc->trim_max_ranges) { 3735 xpt_print(periph->path, 3736 "%s issuing short delete %ld > %ld\n", 3737 da_delete_method_desc[softc->delete_method], 3738 requestcount, 3739 (softc->trim_max_ranges - ranges) * 3740 ATA_DSM_RANGE_MAX); 3741 break; 3742 } 3743 } 3744 lastlba = lba; 3745 bp1 = cam_iosched_next_trim(softc->cam_iosched); 3746 if (bp1 == NULL) 3747 break; 3748 if (bp1->bio_bcount / softc->params.secsize > 3749 (softc->trim_max_ranges - ranges) * ATA_DSM_RANGE_MAX) { 3750 cam_iosched_put_back_trim(softc->cam_iosched, bp1); 3751 break; 3752 } 3753 } while (1); 3754 3755 block_count = howmany(ranges, ATA_DSM_BLK_RANGES); 3756 scsi_ata_trim(&ccb->csio, 3757 /*retries*/da_retry_count, 3758 /*cbfcnp*/dadone, 3759 /*tag_action*/MSG_SIMPLE_Q_TAG, 3760 block_count, 3761 /*data_ptr*/buf, 3762 /*dxfer_len*/block_count * ATA_DSM_BLK_SIZE, 3763 /*sense_len*/SSD_FULL_SIZE, 3764 da_default_timeout * 1000); 3765 ccb->ccb_h.ccb_state = DA_CCB_DELETE; 3766 ccb->ccb_h.flags |= CAM_UNLOCKED; 3767 cam_iosched_submit_trim(softc->cam_iosched); 3768 } 3769 3770 /* 3771 * We calculate ws_max_blks here based off d_delmaxsize instead 3772 * of using softc->ws_max_blks as it is absolute max for the 3773 * device not the protocol max which may well be lower. 3774 */ 3775 static void 3776 da_delete_ws(struct cam_periph *periph, union ccb *ccb, struct bio *bp) 3777 { 3778 struct da_softc *softc; 3779 struct bio *bp1; 3780 uint64_t ws_max_blks; 3781 uint64_t lba; 3782 uint64_t count; /* forward compat with WS32 */ 3783 3784 softc = (struct da_softc *)periph->softc; 3785 ws_max_blks = softc->disk->d_delmaxsize / softc->params.secsize; 3786 lba = bp->bio_pblkno; 3787 count = 0; 3788 bp1 = bp; 3789 do { 3790 if (bp1 != bp)//XXX imp XXX 3791 bioq_insert_tail(&softc->delete_run_queue, bp1); 3792 count += bp1->bio_bcount / softc->params.secsize; 3793 if (count > ws_max_blks) { 3794 xpt_print(periph->path, 3795 "%s issuing short delete %ld > %ld\n", 3796 da_delete_method_desc[softc->delete_method], 3797 count, ws_max_blks); 3798 count = omin(count, ws_max_blks); 3799 break; 3800 } 3801 bp1 = cam_iosched_next_trim(softc->cam_iosched); 3802 if (bp1 == NULL) 3803 break; 3804 if (lba + count != bp1->bio_pblkno || 3805 count + bp1->bio_bcount / 3806 softc->params.secsize > ws_max_blks) { 3807 cam_iosched_put_back_trim(softc->cam_iosched, bp1); 3808 break; 3809 } 3810 } while (1); 3811 3812 scsi_write_same(&ccb->csio, 3813 /*retries*/da_retry_count, 3814 /*cbfcnp*/dadone, 3815 /*tag_action*/MSG_SIMPLE_Q_TAG, 3816 /*byte2*/softc->delete_method == 3817 DA_DELETE_ZERO ? 0 : SWS_UNMAP, 3818 softc->delete_method == DA_DELETE_WS16 ? 16 : 10, 3819 /*lba*/lba, 3820 /*block_count*/count, 3821 /*data_ptr*/ __DECONST(void *, zero_region), 3822 /*dxfer_len*/ softc->params.secsize, 3823 /*sense_len*/SSD_FULL_SIZE, 3824 da_default_timeout * 1000); 3825 ccb->ccb_h.ccb_state = DA_CCB_DELETE; 3826 ccb->ccb_h.flags |= CAM_UNLOCKED; 3827 cam_iosched_submit_trim(softc->cam_iosched); 3828 } 3829 3830 static int 3831 cmd6workaround(union ccb *ccb) 3832 { 3833 struct scsi_rw_6 cmd6; 3834 struct scsi_rw_10 *cmd10; 3835 struct da_softc *softc; 3836 u_int8_t *cdb; 3837 struct bio *bp; 3838 int frozen; 3839 3840 cdb = ccb->csio.cdb_io.cdb_bytes; 3841 softc = (struct da_softc *)xpt_path_periph(ccb->ccb_h.path)->softc; 3842 3843 if (ccb->ccb_h.ccb_state == DA_CCB_DELETE) { 3844 da_delete_methods old_method = softc->delete_method; 3845 3846 /* 3847 * Typically there are two reasons for failure here 3848 * 1. Delete method was detected as supported but isn't 3849 * 2. Delete failed due to invalid params e.g. too big 3850 * 3851 * While we will attempt to choose an alternative delete method 3852 * this may result in short deletes if the existing delete 3853 * requests from geom are big for the new method chosen. 3854 * 3855 * This method assumes that the error which triggered this 3856 * will not retry the io otherwise a panic will occur 3857 */ 3858 dadeleteflag(softc, old_method, 0); 3859 dadeletemethodchoose(softc, DA_DELETE_DISABLE); 3860 if (softc->delete_method == DA_DELETE_DISABLE) 3861 xpt_print(ccb->ccb_h.path, 3862 "%s failed, disabling BIO_DELETE\n", 3863 da_delete_method_desc[old_method]); 3864 else 3865 xpt_print(ccb->ccb_h.path, 3866 "%s failed, switching to %s BIO_DELETE\n", 3867 da_delete_method_desc[old_method], 3868 da_delete_method_desc[softc->delete_method]); 3869 3870 while ((bp = bioq_takefirst(&softc->delete_run_queue)) != NULL) 3871 cam_iosched_queue_work(softc->cam_iosched, bp); 3872 cam_iosched_queue_work(softc->cam_iosched, 3873 (struct bio *)ccb->ccb_h.ccb_bp); 3874 ccb->ccb_h.ccb_bp = NULL; 3875 return (0); 3876 } 3877 3878 /* Detect unsupported PREVENT ALLOW MEDIUM REMOVAL. */ 3879 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 && 3880 (*cdb == PREVENT_ALLOW) && 3881 (softc->quirks & DA_Q_NO_PREVENT) == 0) { 3882 if (bootverbose) 3883 xpt_print(ccb->ccb_h.path, 3884 "PREVENT ALLOW MEDIUM REMOVAL not supported.\n"); 3885 softc->quirks |= DA_Q_NO_PREVENT; 3886 return (0); 3887 } 3888 3889 /* Detect unsupported SYNCHRONIZE CACHE(10). */ 3890 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) == 0 && 3891 (*cdb == SYNCHRONIZE_CACHE) && 3892 (softc->quirks & DA_Q_NO_SYNC_CACHE) == 0) { 3893 if (bootverbose) 3894 xpt_print(ccb->ccb_h.path, 3895 "SYNCHRONIZE CACHE(10) not supported.\n"); 3896 softc->quirks |= DA_Q_NO_SYNC_CACHE; 3897 softc->disk->d_flags &= ~DISKFLAG_CANFLUSHCACHE; 3898 return (0); 3899 } 3900 3901 /* Translation only possible if CDB is an array and cmd is R/W6 */ 3902 if ((ccb->ccb_h.flags & CAM_CDB_POINTER) != 0 || 3903 (*cdb != READ_6 && *cdb != WRITE_6)) 3904 return 0; 3905 3906 xpt_print(ccb->ccb_h.path, "READ(6)/WRITE(6) not supported, " 3907 "increasing minimum_cmd_size to 10.\n"); 3908 softc->minimum_cmd_size = 10; 3909 3910 bcopy(cdb, &cmd6, sizeof(struct scsi_rw_6)); 3911 cmd10 = (struct scsi_rw_10 *)cdb; 3912 cmd10->opcode = (cmd6.opcode == READ_6) ? READ_10 : WRITE_10; 3913 cmd10->byte2 = 0; 3914 scsi_ulto4b(scsi_3btoul(cmd6.addr), cmd10->addr); 3915 cmd10->reserved = 0; 3916 scsi_ulto2b(cmd6.length, cmd10->length); 3917 cmd10->control = cmd6.control; 3918 ccb->csio.cdb_len = sizeof(*cmd10); 3919 3920 /* Requeue request, unfreezing queue if necessary */ 3921 frozen = (ccb->ccb_h.status & CAM_DEV_QFRZN) != 0; 3922 ccb->ccb_h.status = CAM_REQUEUE_REQ; 3923 xpt_action(ccb); 3924 if (frozen) { 3925 cam_release_devq(ccb->ccb_h.path, 3926 /*relsim_flags*/0, 3927 /*reduction*/0, 3928 /*timeout*/0, 3929 /*getcount_only*/0); 3930 } 3931 return (ERESTART); 3932 } 3933 3934 static void 3935 dazonedone(struct cam_periph *periph, union ccb *ccb) 3936 { 3937 struct da_softc *softc; 3938 struct bio *bp; 3939 3940 softc = periph->softc; 3941 bp = (struct bio *)ccb->ccb_h.ccb_bp; 3942 3943 switch (bp->bio_zone.zone_cmd) { 3944 case DISK_ZONE_OPEN: 3945 case DISK_ZONE_CLOSE: 3946 case DISK_ZONE_FINISH: 3947 case DISK_ZONE_RWP: 3948 break; 3949 case DISK_ZONE_REPORT_ZONES: { 3950 uint32_t avail_len; 3951 struct disk_zone_report *rep; 3952 struct scsi_report_zones_hdr *hdr; 3953 struct scsi_report_zones_desc *desc; 3954 struct disk_zone_rep_entry *entry; 3955 uint32_t num_alloced, hdr_len, num_avail; 3956 uint32_t num_to_fill, i; 3957 int ata; 3958 3959 rep = &bp->bio_zone.zone_params.report; 3960 avail_len = ccb->csio.dxfer_len - ccb->csio.resid; 3961 /* 3962 * Note that bio_resid isn't normally used for zone 3963 * commands, but it is used by devstat_end_transaction_bio() 3964 * to determine how much data was transferred. Because 3965 * the size of the SCSI/ATA data structures is different 3966 * than the size of the BIO interface structures, the 3967 * amount of data actually transferred from the drive will 3968 * be different than the amount of data transferred to 3969 * the user. 3970 */ 3971 bp->bio_resid = ccb->csio.resid; 3972 num_alloced = rep->entries_allocated; 3973 hdr = (struct scsi_report_zones_hdr *)ccb->csio.data_ptr; 3974 if (avail_len < sizeof(*hdr)) { 3975 /* 3976 * Is there a better error than EIO here? We asked 3977 * for at least the header, and we got less than 3978 * that. 3979 */ 3980 bp->bio_error = EIO; 3981 bp->bio_flags |= BIO_ERROR; 3982 bp->bio_resid = bp->bio_bcount; 3983 break; 3984 } 3985 3986 if (softc->zone_interface == DA_ZONE_IF_ATA_PASS) 3987 ata = 1; 3988 else 3989 ata = 0; 3990 3991 hdr_len = ata ? le32dec(hdr->length) : 3992 scsi_4btoul(hdr->length); 3993 if (hdr_len > 0) 3994 rep->entries_available = hdr_len / sizeof(*desc); 3995 else 3996 rep->entries_available = 0; 3997 /* 3998 * NOTE: using the same values for the BIO version of the 3999 * same field as the SCSI/ATA values. This means we could 4000 * get some additional values that aren't defined in bio.h 4001 * if more values of the same field are defined later. 4002 */ 4003 rep->header.same = hdr->byte4 & SRZ_SAME_MASK; 4004 rep->header.maximum_lba = ata ? le64dec(hdr->maximum_lba) : 4005 scsi_8btou64(hdr->maximum_lba); 4006 /* 4007 * If the drive reports no entries that match the query, 4008 * we're done. 4009 */ 4010 if (hdr_len == 0) { 4011 rep->entries_filled = 0; 4012 break; 4013 } 4014 4015 num_avail = min((avail_len - sizeof(*hdr)) / sizeof(*desc), 4016 hdr_len / sizeof(*desc)); 4017 /* 4018 * If the drive didn't return any data, then we're done. 4019 */ 4020 if (num_avail == 0) { 4021 rep->entries_filled = 0; 4022 break; 4023 } 4024 4025 num_to_fill = min(num_avail, rep->entries_allocated); 4026 /* 4027 * If the user didn't allocate any entries for us to fill, 4028 * we're done. 4029 */ 4030 if (num_to_fill == 0) { 4031 rep->entries_filled = 0; 4032 break; 4033 } 4034 4035 for (i = 0, desc = &hdr->desc_list[0], entry=&rep->entries[0]; 4036 i < num_to_fill; i++, desc++, entry++) { 4037 /* 4038 * NOTE: we're mapping the values here directly 4039 * from the SCSI/ATA bit definitions to the bio.h 4040 * definitons. There is also a warning in 4041 * disk_zone.h, but the impact is that if 4042 * additional values are added in the SCSI/ATA 4043 * specs these will be visible to consumers of 4044 * this interface. 4045 */ 4046 entry->zone_type = desc->zone_type & SRZ_TYPE_MASK; 4047 entry->zone_condition = 4048 (desc->zone_flags & SRZ_ZONE_COND_MASK) >> 4049 SRZ_ZONE_COND_SHIFT; 4050 entry->zone_flags |= desc->zone_flags & 4051 (SRZ_ZONE_NON_SEQ|SRZ_ZONE_RESET); 4052 entry->zone_length = 4053 ata ? le64dec(desc->zone_length) : 4054 scsi_8btou64(desc->zone_length); 4055 entry->zone_start_lba = 4056 ata ? le64dec(desc->zone_start_lba) : 4057 scsi_8btou64(desc->zone_start_lba); 4058 entry->write_pointer_lba = 4059 ata ? le64dec(desc->write_pointer_lba) : 4060 scsi_8btou64(desc->write_pointer_lba); 4061 } 4062 rep->entries_filled = num_to_fill; 4063 break; 4064 } 4065 case DISK_ZONE_GET_PARAMS: 4066 default: 4067 /* 4068 * In theory we should not get a GET_PARAMS bio, since it 4069 * should be handled without queueing the command to the 4070 * drive. 4071 */ 4072 panic("%s: Invalid zone command %d", __func__, 4073 bp->bio_zone.zone_cmd); 4074 break; 4075 } 4076 4077 if (bp->bio_zone.zone_cmd == DISK_ZONE_REPORT_ZONES) 4078 free(ccb->csio.data_ptr, M_SCSIDA); 4079 } 4080 4081 static void 4082 dadone(struct cam_periph *periph, union ccb *done_ccb) 4083 { 4084 struct da_softc *softc; 4085 struct ccb_scsiio *csio; 4086 u_int32_t priority; 4087 da_ccb_state state; 4088 4089 softc = (struct da_softc *)periph->softc; 4090 priority = done_ccb->ccb_h.pinfo.priority; 4091 4092 CAM_DEBUG(periph->path, CAM_DEBUG_TRACE, ("dadone\n")); 4093 4094 csio = &done_ccb->csio; 4095 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) 4096 if (csio->bio != NULL) 4097 biotrack(csio->bio, __func__); 4098 #endif 4099 state = csio->ccb_h.ccb_state & DA_CCB_TYPE_MASK; 4100 switch (state) { 4101 case DA_CCB_BUFFER_IO: 4102 case DA_CCB_DELETE: 4103 { 4104 struct bio *bp, *bp1; 4105 4106 cam_periph_lock(periph); 4107 bp = (struct bio *)done_ccb->ccb_h.ccb_bp; 4108 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 4109 int error; 4110 int sf; 4111 4112 if ((csio->ccb_h.ccb_state & DA_CCB_RETRY_UA) != 0) 4113 sf = SF_RETRY_UA; 4114 else 4115 sf = 0; 4116 4117 error = daerror(done_ccb, CAM_RETRY_SELTO, sf); 4118 if (error == ERESTART) { 4119 /* 4120 * A retry was scheduled, so 4121 * just return. 4122 */ 4123 cam_periph_unlock(periph); 4124 return; 4125 } 4126 bp = (struct bio *)done_ccb->ccb_h.ccb_bp; 4127 if (error != 0) { 4128 int queued_error; 4129 4130 /* 4131 * return all queued I/O with EIO, so that 4132 * the client can retry these I/Os in the 4133 * proper order should it attempt to recover. 4134 */ 4135 queued_error = EIO; 4136 4137 if (error == ENXIO 4138 && (softc->flags & DA_FLAG_PACK_INVALID)== 0) { 4139 /* 4140 * Catastrophic error. Mark our pack as 4141 * invalid. 4142 */ 4143 /* 4144 * XXX See if this is really a media 4145 * XXX change first? 4146 */ 4147 xpt_print(periph->path, 4148 "Invalidating pack\n"); 4149 softc->flags |= DA_FLAG_PACK_INVALID; 4150 #ifdef CAM_IO_STATS 4151 softc->invalidations++; 4152 #endif 4153 queued_error = ENXIO; 4154 } 4155 cam_iosched_flush(softc->cam_iosched, NULL, 4156 queued_error); 4157 if (bp != NULL) { 4158 bp->bio_error = error; 4159 bp->bio_resid = bp->bio_bcount; 4160 bp->bio_flags |= BIO_ERROR; 4161 } 4162 } else if (bp != NULL) { 4163 if (state == DA_CCB_DELETE) 4164 bp->bio_resid = 0; 4165 else 4166 bp->bio_resid = csio->resid; 4167 bp->bio_error = 0; 4168 if (bp->bio_resid != 0) 4169 bp->bio_flags |= BIO_ERROR; 4170 } 4171 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 4172 cam_release_devq(done_ccb->ccb_h.path, 4173 /*relsim_flags*/0, 4174 /*reduction*/0, 4175 /*timeout*/0, 4176 /*getcount_only*/0); 4177 } else if (bp != NULL) { 4178 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 4179 panic("REQ_CMP with QFRZN"); 4180 if (bp->bio_cmd == BIO_ZONE) 4181 dazonedone(periph, done_ccb); 4182 else if (state == DA_CCB_DELETE) 4183 bp->bio_resid = 0; 4184 else 4185 bp->bio_resid = csio->resid; 4186 if ((csio->resid > 0) 4187 && (bp->bio_cmd != BIO_ZONE)) 4188 bp->bio_flags |= BIO_ERROR; 4189 if (softc->error_inject != 0) { 4190 bp->bio_error = softc->error_inject; 4191 bp->bio_resid = bp->bio_bcount; 4192 bp->bio_flags |= BIO_ERROR; 4193 softc->error_inject = 0; 4194 } 4195 } 4196 4197 if (bp != NULL) 4198 biotrack(bp, __func__); 4199 LIST_REMOVE(&done_ccb->ccb_h, periph_links.le); 4200 if (LIST_EMPTY(&softc->pending_ccbs)) 4201 softc->flags |= DA_FLAG_WAS_OTAG; 4202 4203 cam_iosched_bio_complete(softc->cam_iosched, bp, done_ccb); 4204 xpt_release_ccb(done_ccb); 4205 if (state == DA_CCB_DELETE) { 4206 TAILQ_HEAD(, bio) queue; 4207 4208 TAILQ_INIT(&queue); 4209 TAILQ_CONCAT(&queue, &softc->delete_run_queue.queue, bio_queue); 4210 softc->delete_run_queue.insert_point = NULL; 4211 /* 4212 * Normally, the xpt_release_ccb() above would make sure 4213 * that when we have more work to do, that work would 4214 * get kicked off. However, we specifically keep 4215 * delete_running set to 0 before the call above to 4216 * allow other I/O to progress when many BIO_DELETE 4217 * requests are pushed down. We set delete_running to 0 4218 * and call daschedule again so that we don't stall if 4219 * there are no other I/Os pending apart from BIO_DELETEs. 4220 */ 4221 cam_iosched_trim_done(softc->cam_iosched); 4222 daschedule(periph); 4223 cam_periph_unlock(periph); 4224 while ((bp1 = TAILQ_FIRST(&queue)) != NULL) { 4225 TAILQ_REMOVE(&queue, bp1, bio_queue); 4226 bp1->bio_error = bp->bio_error; 4227 if (bp->bio_flags & BIO_ERROR) { 4228 bp1->bio_flags |= BIO_ERROR; 4229 bp1->bio_resid = bp1->bio_bcount; 4230 } else 4231 bp1->bio_resid = 0; 4232 biodone(bp1); 4233 } 4234 } else { 4235 daschedule(periph); 4236 cam_periph_unlock(periph); 4237 } 4238 if (bp != NULL) 4239 biodone(bp); 4240 return; 4241 } 4242 case DA_CCB_PROBE_RC: 4243 case DA_CCB_PROBE_RC16: 4244 { 4245 struct scsi_read_capacity_data *rdcap; 4246 struct scsi_read_capacity_data_long *rcaplong; 4247 char *announce_buf; 4248 int lbp; 4249 4250 lbp = 0; 4251 rdcap = NULL; 4252 rcaplong = NULL; 4253 /* XXX TODO: can this be a malloc? */ 4254 announce_buf = softc->announce_temp; 4255 bzero(announce_buf, DA_ANNOUNCETMP_SZ); 4256 4257 if (state == DA_CCB_PROBE_RC) 4258 rdcap =(struct scsi_read_capacity_data *)csio->data_ptr; 4259 else 4260 rcaplong = (struct scsi_read_capacity_data_long *) 4261 csio->data_ptr; 4262 4263 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4264 struct disk_params *dp; 4265 uint32_t block_size; 4266 uint64_t maxsector; 4267 u_int lalba; /* Lowest aligned LBA. */ 4268 4269 if (state == DA_CCB_PROBE_RC) { 4270 block_size = scsi_4btoul(rdcap->length); 4271 maxsector = scsi_4btoul(rdcap->addr); 4272 lalba = 0; 4273 4274 /* 4275 * According to SBC-2, if the standard 10 4276 * byte READ CAPACITY command returns 2^32, 4277 * we should issue the 16 byte version of 4278 * the command, since the device in question 4279 * has more sectors than can be represented 4280 * with the short version of the command. 4281 */ 4282 if (maxsector == 0xffffffff) { 4283 free(rdcap, M_SCSIDA); 4284 xpt_release_ccb(done_ccb); 4285 softc->state = DA_STATE_PROBE_RC16; 4286 xpt_schedule(periph, priority); 4287 return; 4288 } 4289 } else { 4290 block_size = scsi_4btoul(rcaplong->length); 4291 maxsector = scsi_8btou64(rcaplong->addr); 4292 lalba = scsi_2btoul(rcaplong->lalba_lbp); 4293 } 4294 4295 /* 4296 * Because GEOM code just will panic us if we 4297 * give them an 'illegal' value we'll avoid that 4298 * here. 4299 */ 4300 if (block_size == 0) { 4301 block_size = 512; 4302 if (maxsector == 0) 4303 maxsector = -1; 4304 } 4305 if (block_size >= MAXPHYS) { 4306 xpt_print(periph->path, 4307 "unsupportable block size %ju\n", 4308 (uintmax_t) block_size); 4309 announce_buf = NULL; 4310 cam_periph_invalidate(periph); 4311 } else { 4312 /* 4313 * We pass rcaplong into dasetgeom(), 4314 * because it will only use it if it is 4315 * non-NULL. 4316 */ 4317 dasetgeom(periph, block_size, maxsector, 4318 rcaplong, sizeof(*rcaplong)); 4319 lbp = (lalba & SRC16_LBPME_A); 4320 dp = &softc->params; 4321 snprintf(announce_buf, DA_ANNOUNCETMP_SZ, 4322 "%juMB (%ju %u byte sectors)", 4323 ((uintmax_t)dp->secsize * dp->sectors) / 4324 (1024 * 1024), 4325 (uintmax_t)dp->sectors, dp->secsize); 4326 } 4327 } else { 4328 int error; 4329 4330 /* 4331 * Retry any UNIT ATTENTION type errors. They 4332 * are expected at boot. 4333 */ 4334 error = daerror(done_ccb, CAM_RETRY_SELTO, 4335 SF_RETRY_UA|SF_NO_PRINT); 4336 if (error == ERESTART) { 4337 /* 4338 * A retry was scheuled, so 4339 * just return. 4340 */ 4341 return; 4342 } else if (error != 0) { 4343 int asc, ascq; 4344 int sense_key, error_code; 4345 int have_sense; 4346 cam_status status; 4347 struct ccb_getdev cgd; 4348 4349 /* Don't wedge this device's queue */ 4350 status = done_ccb->ccb_h.status; 4351 if ((status & CAM_DEV_QFRZN) != 0) 4352 cam_release_devq(done_ccb->ccb_h.path, 4353 /*relsim_flags*/0, 4354 /*reduction*/0, 4355 /*timeout*/0, 4356 /*getcount_only*/0); 4357 4358 4359 xpt_setup_ccb(&cgd.ccb_h, 4360 done_ccb->ccb_h.path, 4361 CAM_PRIORITY_NORMAL); 4362 cgd.ccb_h.func_code = XPT_GDEV_TYPE; 4363 xpt_action((union ccb *)&cgd); 4364 4365 if (scsi_extract_sense_ccb(done_ccb, 4366 &error_code, &sense_key, &asc, &ascq)) 4367 have_sense = TRUE; 4368 else 4369 have_sense = FALSE; 4370 4371 /* 4372 * If we tried READ CAPACITY(16) and failed, 4373 * fallback to READ CAPACITY(10). 4374 */ 4375 if ((state == DA_CCB_PROBE_RC16) && 4376 (softc->flags & DA_FLAG_CAN_RC16) && 4377 (((csio->ccb_h.status & CAM_STATUS_MASK) == 4378 CAM_REQ_INVALID) || 4379 ((have_sense) && 4380 (error_code == SSD_CURRENT_ERROR) && 4381 (sense_key == SSD_KEY_ILLEGAL_REQUEST)))) { 4382 softc->flags &= ~DA_FLAG_CAN_RC16; 4383 free(rdcap, M_SCSIDA); 4384 xpt_release_ccb(done_ccb); 4385 softc->state = DA_STATE_PROBE_RC; 4386 xpt_schedule(periph, priority); 4387 return; 4388 } 4389 4390 /* 4391 * Attach to anything that claims to be a 4392 * direct access or optical disk device, 4393 * as long as it doesn't return a "Logical 4394 * unit not supported" (0x25) error. 4395 * "Internal Target Failure" (0x44) is also 4396 * special and typically means that the 4397 * device is a SATA drive behind a SATL 4398 * translation that's fallen into a 4399 * terminally fatal state. 4400 */ 4401 if ((have_sense) 4402 && (asc != 0x25) && (asc != 0x44) 4403 && (error_code == SSD_CURRENT_ERROR)) { 4404 const char *sense_key_desc; 4405 const char *asc_desc; 4406 4407 dasetgeom(periph, 512, -1, NULL, 0); 4408 scsi_sense_desc(sense_key, asc, ascq, 4409 &cgd.inq_data, 4410 &sense_key_desc, 4411 &asc_desc); 4412 snprintf(announce_buf, 4413 DA_ANNOUNCETMP_SZ, 4414 "Attempt to query device " 4415 "size failed: %s, %s", 4416 sense_key_desc, asc_desc); 4417 } else { 4418 if (have_sense) 4419 scsi_sense_print( 4420 &done_ccb->csio); 4421 else { 4422 xpt_print(periph->path, 4423 "got CAM status %#x\n", 4424 done_ccb->ccb_h.status); 4425 } 4426 4427 xpt_print(periph->path, "fatal error, " 4428 "failed to attach to device\n"); 4429 4430 announce_buf = NULL; 4431 4432 /* 4433 * Free up resources. 4434 */ 4435 cam_periph_invalidate(periph); 4436 } 4437 } 4438 } 4439 free(csio->data_ptr, M_SCSIDA); 4440 if (announce_buf != NULL && 4441 ((softc->flags & DA_FLAG_ANNOUNCED) == 0)) { 4442 struct sbuf sb; 4443 4444 sbuf_new(&sb, softc->announcebuf, DA_ANNOUNCE_SZ, 4445 SBUF_FIXEDLEN); 4446 xpt_announce_periph_sbuf(periph, &sb, announce_buf); 4447 xpt_announce_quirks_sbuf(periph, &sb, softc->quirks, 4448 DA_Q_BIT_STRING); 4449 sbuf_finish(&sb); 4450 sbuf_putbuf(&sb); 4451 4452 /* 4453 * Create our sysctl variables, now that we know 4454 * we have successfully attached. 4455 */ 4456 /* increase the refcount */ 4457 if (cam_periph_acquire(periph) == CAM_REQ_CMP) { 4458 4459 taskqueue_enqueue(taskqueue_thread, 4460 &softc->sysctl_task); 4461 } else { 4462 /* XXX This message is useless! */ 4463 xpt_print(periph->path, "fatal error, " 4464 "could not acquire reference count\n"); 4465 } 4466 } 4467 4468 /* We already probed the device. */ 4469 if (softc->flags & DA_FLAG_PROBED) { 4470 daprobedone(periph, done_ccb); 4471 return; 4472 } 4473 4474 /* Ensure re-probe doesn't see old delete. */ 4475 softc->delete_available = 0; 4476 dadeleteflag(softc, DA_DELETE_ZERO, 1); 4477 if (lbp && (softc->quirks & DA_Q_NO_UNMAP) == 0) { 4478 /* 4479 * Based on older SBC-3 spec revisions 4480 * any of the UNMAP methods "may" be 4481 * available via LBP given this flag so 4482 * we flag all of them as available and 4483 * then remove those which further 4484 * probes confirm aren't available 4485 * later. 4486 * 4487 * We could also check readcap(16) p_type 4488 * flag to exclude one or more invalid 4489 * write same (X) types here 4490 */ 4491 dadeleteflag(softc, DA_DELETE_WS16, 1); 4492 dadeleteflag(softc, DA_DELETE_WS10, 1); 4493 dadeleteflag(softc, DA_DELETE_UNMAP, 1); 4494 4495 xpt_release_ccb(done_ccb); 4496 softc->state = DA_STATE_PROBE_LBP; 4497 xpt_schedule(periph, priority); 4498 return; 4499 } 4500 4501 xpt_release_ccb(done_ccb); 4502 softc->state = DA_STATE_PROBE_BDC; 4503 xpt_schedule(periph, priority); 4504 return; 4505 } 4506 case DA_CCB_PROBE_LBP: 4507 { 4508 struct scsi_vpd_logical_block_prov *lbp; 4509 4510 lbp = (struct scsi_vpd_logical_block_prov *)csio->data_ptr; 4511 4512 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4513 /* 4514 * T10/1799-D Revision 31 states at least one of these 4515 * must be supported but we don't currently enforce this. 4516 */ 4517 dadeleteflag(softc, DA_DELETE_WS16, 4518 (lbp->flags & SVPD_LBP_WS16)); 4519 dadeleteflag(softc, DA_DELETE_WS10, 4520 (lbp->flags & SVPD_LBP_WS10)); 4521 dadeleteflag(softc, DA_DELETE_UNMAP, 4522 (lbp->flags & SVPD_LBP_UNMAP)); 4523 } else { 4524 int error; 4525 error = daerror(done_ccb, CAM_RETRY_SELTO, 4526 SF_RETRY_UA|SF_NO_PRINT); 4527 if (error == ERESTART) 4528 return; 4529 else if (error != 0) { 4530 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 4531 /* Don't wedge this device's queue */ 4532 cam_release_devq(done_ccb->ccb_h.path, 4533 /*relsim_flags*/0, 4534 /*reduction*/0, 4535 /*timeout*/0, 4536 /*getcount_only*/0); 4537 } 4538 4539 /* 4540 * Failure indicates we don't support any SBC-3 4541 * delete methods with UNMAP 4542 */ 4543 } 4544 } 4545 4546 free(lbp, M_SCSIDA); 4547 xpt_release_ccb(done_ccb); 4548 softc->state = DA_STATE_PROBE_BLK_LIMITS; 4549 xpt_schedule(periph, priority); 4550 return; 4551 } 4552 case DA_CCB_PROBE_BLK_LIMITS: 4553 { 4554 struct scsi_vpd_block_limits *block_limits; 4555 4556 block_limits = (struct scsi_vpd_block_limits *)csio->data_ptr; 4557 4558 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4559 uint32_t max_txfer_len = scsi_4btoul( 4560 block_limits->max_txfer_len); 4561 uint32_t max_unmap_lba_cnt = scsi_4btoul( 4562 block_limits->max_unmap_lba_cnt); 4563 uint32_t max_unmap_blk_cnt = scsi_4btoul( 4564 block_limits->max_unmap_blk_cnt); 4565 uint32_t unmap_gran = scsi_4btoul( 4566 block_limits->opt_unmap_grain); 4567 uint32_t unmap_gran_align = scsi_4btoul( 4568 block_limits->unmap_grain_align); 4569 uint64_t ws_max_blks = scsi_8btou64( 4570 block_limits->max_write_same_length); 4571 4572 if (max_txfer_len != 0) { 4573 softc->disk->d_maxsize = MIN(softc->maxio, 4574 (off_t)max_txfer_len * softc->params.secsize); 4575 } 4576 4577 /* 4578 * We should already support UNMAP but we check lba 4579 * and block count to be sure 4580 */ 4581 if (max_unmap_lba_cnt != 0x00L && 4582 max_unmap_blk_cnt != 0x00L) { 4583 softc->unmap_max_lba = max_unmap_lba_cnt; 4584 softc->unmap_max_ranges = min(max_unmap_blk_cnt, 4585 UNMAP_MAX_RANGES); 4586 if (unmap_gran > 1) { 4587 softc->unmap_gran = unmap_gran; 4588 if (unmap_gran_align & 0x80000000) { 4589 softc->unmap_gran_align = 4590 unmap_gran_align & 4591 0x7fffffff; 4592 } 4593 } 4594 } else { 4595 /* 4596 * Unexpected UNMAP limits which means the 4597 * device doesn't actually support UNMAP 4598 */ 4599 dadeleteflag(softc, DA_DELETE_UNMAP, 0); 4600 } 4601 4602 if (ws_max_blks != 0x00L) 4603 softc->ws_max_blks = ws_max_blks; 4604 } else { 4605 int error; 4606 error = daerror(done_ccb, CAM_RETRY_SELTO, 4607 SF_RETRY_UA|SF_NO_PRINT); 4608 if (error == ERESTART) 4609 return; 4610 else if (error != 0) { 4611 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 4612 /* Don't wedge this device's queue */ 4613 cam_release_devq(done_ccb->ccb_h.path, 4614 /*relsim_flags*/0, 4615 /*reduction*/0, 4616 /*timeout*/0, 4617 /*getcount_only*/0); 4618 } 4619 4620 /* 4621 * Failure here doesn't mean UNMAP is not 4622 * supported as this is an optional page. 4623 */ 4624 softc->unmap_max_lba = 1; 4625 softc->unmap_max_ranges = 1; 4626 } 4627 } 4628 4629 free(block_limits, M_SCSIDA); 4630 xpt_release_ccb(done_ccb); 4631 softc->state = DA_STATE_PROBE_BDC; 4632 xpt_schedule(periph, priority); 4633 return; 4634 } 4635 case DA_CCB_PROBE_BDC: 4636 { 4637 struct scsi_vpd_block_device_characteristics *bdc; 4638 4639 bdc = (struct scsi_vpd_block_device_characteristics *) 4640 csio->data_ptr; 4641 4642 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4643 uint32_t valid_len; 4644 4645 /* 4646 * Disable queue sorting for non-rotational media 4647 * by default. 4648 */ 4649 u_int16_t old_rate = softc->disk->d_rotation_rate; 4650 4651 valid_len = csio->dxfer_len - csio->resid; 4652 if (SBDC_IS_PRESENT(bdc, valid_len, 4653 medium_rotation_rate)) { 4654 softc->disk->d_rotation_rate = 4655 scsi_2btoul(bdc->medium_rotation_rate); 4656 if (softc->disk->d_rotation_rate == 4657 SVPD_BDC_RATE_NON_ROTATING) { 4658 cam_iosched_set_sort_queue( 4659 softc->cam_iosched, 0); 4660 softc->rotating = 0; 4661 } 4662 if (softc->disk->d_rotation_rate != old_rate) { 4663 disk_attr_changed(softc->disk, 4664 "GEOM::rotation_rate", M_NOWAIT); 4665 } 4666 } 4667 if ((SBDC_IS_PRESENT(bdc, valid_len, flags)) 4668 && (softc->zone_mode == DA_ZONE_NONE)) { 4669 int ata_proto; 4670 4671 if (scsi_vpd_supported_page(periph, 4672 SVPD_ATA_INFORMATION)) 4673 ata_proto = 1; 4674 else 4675 ata_proto = 0; 4676 4677 /* 4678 * The Zoned field will only be set for 4679 * Drive Managed and Host Aware drives. If 4680 * they are Host Managed, the device type 4681 * in the standard INQUIRY data should be 4682 * set to T_ZBC_HM (0x14). 4683 */ 4684 if ((bdc->flags & SVPD_ZBC_MASK) == 4685 SVPD_HAW_ZBC) { 4686 softc->zone_mode = DA_ZONE_HOST_AWARE; 4687 softc->zone_interface = (ata_proto) ? 4688 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI; 4689 } else if ((bdc->flags & SVPD_ZBC_MASK) == 4690 SVPD_DM_ZBC) { 4691 softc->zone_mode =DA_ZONE_DRIVE_MANAGED; 4692 softc->zone_interface = (ata_proto) ? 4693 DA_ZONE_IF_ATA_SAT : DA_ZONE_IF_SCSI; 4694 } else if ((bdc->flags & SVPD_ZBC_MASK) != 4695 SVPD_ZBC_NR) { 4696 xpt_print(periph->path, "Unknown zoned " 4697 "type %#x", 4698 bdc->flags & SVPD_ZBC_MASK); 4699 } 4700 } 4701 } else { 4702 int error; 4703 error = daerror(done_ccb, CAM_RETRY_SELTO, 4704 SF_RETRY_UA|SF_NO_PRINT); 4705 if (error == ERESTART) 4706 return; 4707 else if (error != 0) { 4708 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 4709 /* Don't wedge this device's queue */ 4710 cam_release_devq(done_ccb->ccb_h.path, 4711 /*relsim_flags*/0, 4712 /*reduction*/0, 4713 /*timeout*/0, 4714 /*getcount_only*/0); 4715 } 4716 } 4717 } 4718 4719 free(bdc, M_SCSIDA); 4720 xpt_release_ccb(done_ccb); 4721 softc->state = DA_STATE_PROBE_ATA; 4722 xpt_schedule(periph, priority); 4723 return; 4724 } 4725 case DA_CCB_PROBE_ATA: 4726 { 4727 int i; 4728 struct ata_params *ata_params; 4729 int continue_probe; 4730 int error; 4731 int16_t *ptr; 4732 4733 ata_params = (struct ata_params *)csio->data_ptr; 4734 ptr = (uint16_t *)ata_params; 4735 continue_probe = 0; 4736 error = 0; 4737 4738 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4739 uint16_t old_rate; 4740 4741 for (i = 0; i < sizeof(*ata_params) / 2; i++) 4742 ptr[i] = le16toh(ptr[i]); 4743 if (ata_params->support_dsm & ATA_SUPPORT_DSM_TRIM && 4744 (softc->quirks & DA_Q_NO_UNMAP) == 0) { 4745 dadeleteflag(softc, DA_DELETE_ATA_TRIM, 1); 4746 if (ata_params->max_dsm_blocks != 0) 4747 softc->trim_max_ranges = min( 4748 softc->trim_max_ranges, 4749 ata_params->max_dsm_blocks * 4750 ATA_DSM_BLK_RANGES); 4751 } 4752 /* 4753 * Disable queue sorting for non-rotational media 4754 * by default. 4755 */ 4756 old_rate = softc->disk->d_rotation_rate; 4757 softc->disk->d_rotation_rate = 4758 ata_params->media_rotation_rate; 4759 if (softc->disk->d_rotation_rate == 4760 ATA_RATE_NON_ROTATING) { 4761 cam_iosched_set_sort_queue(softc->cam_iosched, 0); 4762 softc->rotating = 0; 4763 } 4764 if (softc->disk->d_rotation_rate != old_rate) { 4765 disk_attr_changed(softc->disk, 4766 "GEOM::rotation_rate", M_NOWAIT); 4767 } 4768 4769 if (ata_params->capabilities1 & ATA_SUPPORT_DMA) 4770 softc->flags |= DA_FLAG_CAN_ATA_DMA; 4771 4772 if (ata_params->support.extension & 4773 ATA_SUPPORT_GENLOG) 4774 softc->flags |= DA_FLAG_CAN_ATA_LOG; 4775 4776 /* 4777 * At this point, if we have a SATA host aware drive, 4778 * we communicate via ATA passthrough unless the 4779 * SAT layer supports ZBC -> ZAC translation. In 4780 * that case, 4781 */ 4782 /* 4783 * XXX KDM figure out how to detect a host managed 4784 * SATA drive. 4785 */ 4786 if (softc->zone_mode == DA_ZONE_NONE) { 4787 /* 4788 * Note that we don't override the zone 4789 * mode or interface if it has already been 4790 * set. This is because it has either been 4791 * set as a quirk, or when we probed the 4792 * SCSI Block Device Characteristics page, 4793 * the zoned field was set. The latter 4794 * means that the SAT layer supports ZBC to 4795 * ZAC translation, and we would prefer to 4796 * use that if it is available. 4797 */ 4798 if ((ata_params->support3 & 4799 ATA_SUPPORT_ZONE_MASK) == 4800 ATA_SUPPORT_ZONE_HOST_AWARE) { 4801 softc->zone_mode = DA_ZONE_HOST_AWARE; 4802 softc->zone_interface = 4803 DA_ZONE_IF_ATA_PASS; 4804 } else if ((ata_params->support3 & 4805 ATA_SUPPORT_ZONE_MASK) == 4806 ATA_SUPPORT_ZONE_DEV_MANAGED) { 4807 softc->zone_mode =DA_ZONE_DRIVE_MANAGED; 4808 softc->zone_interface = 4809 DA_ZONE_IF_ATA_PASS; 4810 } 4811 } 4812 4813 } else { 4814 error = daerror(done_ccb, CAM_RETRY_SELTO, 4815 SF_RETRY_UA|SF_NO_PRINT); 4816 if (error == ERESTART) 4817 return; 4818 else if (error != 0) { 4819 if ((done_ccb->ccb_h.status & 4820 CAM_DEV_QFRZN) != 0) { 4821 /* Don't wedge this device's queue */ 4822 cam_release_devq(done_ccb->ccb_h.path, 4823 /*relsim_flags*/0, 4824 /*reduction*/0, 4825 /*timeout*/0, 4826 /*getcount_only*/0); 4827 } 4828 } 4829 } 4830 4831 free(ata_params, M_SCSIDA); 4832 if ((softc->zone_mode == DA_ZONE_HOST_AWARE) 4833 || (softc->zone_mode == DA_ZONE_HOST_MANAGED)) { 4834 /* 4835 * If the ATA IDENTIFY failed, we could be talking 4836 * to a SCSI drive, although that seems unlikely, 4837 * since the drive did report that it supported the 4838 * ATA Information VPD page. If the ATA IDENTIFY 4839 * succeeded, and the SAT layer doesn't support 4840 * ZBC -> ZAC translation, continue on to get the 4841 * directory of ATA logs, and complete the rest of 4842 * the ZAC probe. If the SAT layer does support 4843 * ZBC -> ZAC translation, we want to use that, 4844 * and we'll probe the SCSI Zoned Block Device 4845 * Characteristics VPD page next. 4846 */ 4847 if ((error == 0) 4848 && (softc->flags & DA_FLAG_CAN_ATA_LOG) 4849 && (softc->zone_interface == DA_ZONE_IF_ATA_PASS)) 4850 softc->state = DA_STATE_PROBE_ATA_LOGDIR; 4851 else 4852 softc->state = DA_STATE_PROBE_ZONE; 4853 continue_probe = 1; 4854 } 4855 if (continue_probe != 0) { 4856 xpt_release_ccb(done_ccb); 4857 xpt_schedule(periph, priority); 4858 return; 4859 } else 4860 daprobedone(periph, done_ccb); 4861 return; 4862 } 4863 case DA_CCB_PROBE_ATA_LOGDIR: 4864 { 4865 int error; 4866 4867 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4868 error = 0; 4869 softc->valid_logdir_len = 0; 4870 bzero(&softc->ata_logdir, sizeof(softc->ata_logdir)); 4871 softc->valid_logdir_len = 4872 csio->dxfer_len - csio->resid; 4873 if (softc->valid_logdir_len > 0) 4874 bcopy(csio->data_ptr, &softc->ata_logdir, 4875 min(softc->valid_logdir_len, 4876 sizeof(softc->ata_logdir))); 4877 /* 4878 * Figure out whether the Identify Device log is 4879 * supported. The General Purpose log directory 4880 * has a header, and lists the number of pages 4881 * available for each GP log identified by the 4882 * offset into the list. 4883 */ 4884 if ((softc->valid_logdir_len >= 4885 ((ATA_IDENTIFY_DATA_LOG + 1) * sizeof(uint16_t))) 4886 && (le16dec(softc->ata_logdir.header) == 4887 ATA_GP_LOG_DIR_VERSION) 4888 && (le16dec(&softc->ata_logdir.num_pages[ 4889 (ATA_IDENTIFY_DATA_LOG * 4890 sizeof(uint16_t)) - sizeof(uint16_t)]) > 0)){ 4891 softc->flags |= DA_FLAG_CAN_ATA_IDLOG; 4892 } else { 4893 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG; 4894 } 4895 } else { 4896 error = daerror(done_ccb, CAM_RETRY_SELTO, 4897 SF_RETRY_UA|SF_NO_PRINT); 4898 if (error == ERESTART) 4899 return; 4900 else if (error != 0) { 4901 /* 4902 * If we can't get the ATA log directory, 4903 * then ATA logs are effectively not 4904 * supported even if the bit is set in the 4905 * identify data. 4906 */ 4907 softc->flags &= ~(DA_FLAG_CAN_ATA_LOG | 4908 DA_FLAG_CAN_ATA_IDLOG); 4909 if ((done_ccb->ccb_h.status & 4910 CAM_DEV_QFRZN) != 0) { 4911 /* Don't wedge this device's queue */ 4912 cam_release_devq(done_ccb->ccb_h.path, 4913 /*relsim_flags*/0, 4914 /*reduction*/0, 4915 /*timeout*/0, 4916 /*getcount_only*/0); 4917 } 4918 } 4919 } 4920 4921 free(csio->data_ptr, M_SCSIDA); 4922 4923 if ((error == 0) 4924 && (softc->flags & DA_FLAG_CAN_ATA_IDLOG)) { 4925 softc->state = DA_STATE_PROBE_ATA_IDDIR; 4926 xpt_release_ccb(done_ccb); 4927 xpt_schedule(periph, priority); 4928 return; 4929 } 4930 daprobedone(periph, done_ccb); 4931 return; 4932 } 4933 case DA_CCB_PROBE_ATA_IDDIR: 4934 { 4935 int error; 4936 4937 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 4938 off_t entries_offset, max_entries; 4939 error = 0; 4940 4941 softc->valid_iddir_len = 0; 4942 bzero(&softc->ata_iddir, sizeof(softc->ata_iddir)); 4943 softc->flags &= ~(DA_FLAG_CAN_ATA_SUPCAP | 4944 DA_FLAG_CAN_ATA_ZONE); 4945 softc->valid_iddir_len = 4946 csio->dxfer_len - csio->resid; 4947 if (softc->valid_iddir_len > 0) 4948 bcopy(csio->data_ptr, &softc->ata_iddir, 4949 min(softc->valid_iddir_len, 4950 sizeof(softc->ata_iddir))); 4951 4952 entries_offset = 4953 __offsetof(struct ata_identify_log_pages,entries); 4954 max_entries = softc->valid_iddir_len - entries_offset; 4955 if ((softc->valid_iddir_len > (entries_offset + 1)) 4956 && (le64dec(softc->ata_iddir.header) == 4957 ATA_IDLOG_REVISION) 4958 && (softc->ata_iddir.entry_count > 0)) { 4959 int num_entries, i; 4960 4961 num_entries = softc->ata_iddir.entry_count; 4962 num_entries = min(num_entries, 4963 softc->valid_iddir_len - entries_offset); 4964 for (i = 0; i < num_entries && 4965 i < max_entries; i++) { 4966 if (softc->ata_iddir.entries[i] == 4967 ATA_IDL_SUP_CAP) 4968 softc->flags |= 4969 DA_FLAG_CAN_ATA_SUPCAP; 4970 else if (softc->ata_iddir.entries[i]== 4971 ATA_IDL_ZDI) 4972 softc->flags |= 4973 DA_FLAG_CAN_ATA_ZONE; 4974 4975 if ((softc->flags & 4976 DA_FLAG_CAN_ATA_SUPCAP) 4977 && (softc->flags & 4978 DA_FLAG_CAN_ATA_ZONE)) 4979 break; 4980 } 4981 } 4982 } else { 4983 error = daerror(done_ccb, CAM_RETRY_SELTO, 4984 SF_RETRY_UA|SF_NO_PRINT); 4985 if (error == ERESTART) 4986 return; 4987 else if (error != 0) { 4988 /* 4989 * If we can't get the ATA Identify Data log 4990 * directory, then it effectively isn't 4991 * supported even if the ATA Log directory 4992 * a non-zero number of pages present for 4993 * this log. 4994 */ 4995 softc->flags &= ~DA_FLAG_CAN_ATA_IDLOG; 4996 if ((done_ccb->ccb_h.status & 4997 CAM_DEV_QFRZN) != 0) { 4998 /* Don't wedge this device's queue */ 4999 cam_release_devq(done_ccb->ccb_h.path, 5000 /*relsim_flags*/0, 5001 /*reduction*/0, 5002 /*timeout*/0, 5003 /*getcount_only*/0); 5004 } 5005 } 5006 } 5007 5008 free(csio->data_ptr, M_SCSIDA); 5009 5010 if ((error == 0) 5011 && (softc->flags & DA_FLAG_CAN_ATA_SUPCAP)) { 5012 softc->state = DA_STATE_PROBE_ATA_SUP; 5013 xpt_release_ccb(done_ccb); 5014 xpt_schedule(periph, priority); 5015 return; 5016 } 5017 daprobedone(periph, done_ccb); 5018 return; 5019 } 5020 case DA_CCB_PROBE_ATA_SUP: 5021 { 5022 int error; 5023 5024 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 5025 uint32_t valid_len; 5026 size_t needed_size; 5027 struct ata_identify_log_sup_cap *sup_cap; 5028 error = 0; 5029 5030 sup_cap = (struct ata_identify_log_sup_cap *) 5031 csio->data_ptr; 5032 valid_len = csio->dxfer_len - csio->resid; 5033 needed_size = 5034 __offsetof(struct ata_identify_log_sup_cap, 5035 sup_zac_cap) + 1 + sizeof(sup_cap->sup_zac_cap); 5036 if (valid_len >= needed_size) { 5037 uint64_t zoned, zac_cap; 5038 5039 zoned = le64dec(sup_cap->zoned_cap); 5040 if (zoned & ATA_ZONED_VALID) { 5041 /* 5042 * This should have already been 5043 * set, because this is also in the 5044 * ATA identify data. 5045 */ 5046 if ((zoned & ATA_ZONED_MASK) == 5047 ATA_SUPPORT_ZONE_HOST_AWARE) 5048 softc->zone_mode = 5049 DA_ZONE_HOST_AWARE; 5050 else if ((zoned & ATA_ZONED_MASK) == 5051 ATA_SUPPORT_ZONE_DEV_MANAGED) 5052 softc->zone_mode = 5053 DA_ZONE_DRIVE_MANAGED; 5054 } 5055 5056 zac_cap = le64dec(sup_cap->sup_zac_cap); 5057 if (zac_cap & ATA_SUP_ZAC_CAP_VALID) { 5058 if (zac_cap & ATA_REPORT_ZONES_SUP) 5059 softc->zone_flags |= 5060 DA_ZONE_FLAG_RZ_SUP; 5061 if (zac_cap & ATA_ND_OPEN_ZONE_SUP) 5062 softc->zone_flags |= 5063 DA_ZONE_FLAG_OPEN_SUP; 5064 if (zac_cap & ATA_ND_CLOSE_ZONE_SUP) 5065 softc->zone_flags |= 5066 DA_ZONE_FLAG_CLOSE_SUP; 5067 if (zac_cap & ATA_ND_FINISH_ZONE_SUP) 5068 softc->zone_flags |= 5069 DA_ZONE_FLAG_FINISH_SUP; 5070 if (zac_cap & ATA_ND_RWP_SUP) 5071 softc->zone_flags |= 5072 DA_ZONE_FLAG_RWP_SUP; 5073 } else { 5074 /* 5075 * This field was introduced in 5076 * ACS-4, r08 on April 28th, 2015. 5077 * If the drive firmware was written 5078 * to an earlier spec, it won't have 5079 * the field. So, assume all 5080 * commands are supported. 5081 */ 5082 softc->zone_flags |= 5083 DA_ZONE_FLAG_SUP_MASK; 5084 } 5085 5086 } 5087 } else { 5088 error = daerror(done_ccb, CAM_RETRY_SELTO, 5089 SF_RETRY_UA|SF_NO_PRINT); 5090 if (error == ERESTART) 5091 return; 5092 else if (error != 0) { 5093 /* 5094 * If we can't get the ATA Identify Data 5095 * Supported Capabilities page, clear the 5096 * flag... 5097 */ 5098 softc->flags &= ~DA_FLAG_CAN_ATA_SUPCAP; 5099 /* 5100 * And clear zone capabilities. 5101 */ 5102 softc->zone_flags &= ~DA_ZONE_FLAG_SUP_MASK; 5103 if ((done_ccb->ccb_h.status & 5104 CAM_DEV_QFRZN) != 0) { 5105 /* Don't wedge this device's queue */ 5106 cam_release_devq(done_ccb->ccb_h.path, 5107 /*relsim_flags*/0, 5108 /*reduction*/0, 5109 /*timeout*/0, 5110 /*getcount_only*/0); 5111 } 5112 } 5113 } 5114 5115 free(csio->data_ptr, M_SCSIDA); 5116 5117 if ((error == 0) 5118 && (softc->flags & DA_FLAG_CAN_ATA_ZONE)) { 5119 softc->state = DA_STATE_PROBE_ATA_ZONE; 5120 xpt_release_ccb(done_ccb); 5121 xpt_schedule(periph, priority); 5122 return; 5123 } 5124 daprobedone(periph, done_ccb); 5125 return; 5126 } 5127 case DA_CCB_PROBE_ATA_ZONE: 5128 { 5129 int error; 5130 5131 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 5132 struct ata_zoned_info_log *zi_log; 5133 uint32_t valid_len; 5134 size_t needed_size; 5135 5136 zi_log = (struct ata_zoned_info_log *)csio->data_ptr; 5137 5138 valid_len = csio->dxfer_len - csio->resid; 5139 needed_size = __offsetof(struct ata_zoned_info_log, 5140 version_info) + 1 + sizeof(zi_log->version_info); 5141 if (valid_len >= needed_size) { 5142 uint64_t tmpvar; 5143 5144 tmpvar = le64dec(zi_log->zoned_cap); 5145 if (tmpvar & ATA_ZDI_CAP_VALID) { 5146 if (tmpvar & ATA_ZDI_CAP_URSWRZ) 5147 softc->zone_flags |= 5148 DA_ZONE_FLAG_URSWRZ; 5149 else 5150 softc->zone_flags &= 5151 ~DA_ZONE_FLAG_URSWRZ; 5152 } 5153 tmpvar = le64dec(zi_log->optimal_seq_zones); 5154 if (tmpvar & ATA_ZDI_OPT_SEQ_VALID) { 5155 softc->zone_flags |= 5156 DA_ZONE_FLAG_OPT_SEQ_SET; 5157 softc->optimal_seq_zones = (tmpvar & 5158 ATA_ZDI_OPT_SEQ_MASK); 5159 } else { 5160 softc->zone_flags &= 5161 ~DA_ZONE_FLAG_OPT_SEQ_SET; 5162 softc->optimal_seq_zones = 0; 5163 } 5164 5165 tmpvar =le64dec(zi_log->optimal_nonseq_zones); 5166 if (tmpvar & ATA_ZDI_OPT_NS_VALID) { 5167 softc->zone_flags |= 5168 DA_ZONE_FLAG_OPT_NONSEQ_SET; 5169 softc->optimal_nonseq_zones = 5170 (tmpvar & ATA_ZDI_OPT_NS_MASK); 5171 } else { 5172 softc->zone_flags &= 5173 ~DA_ZONE_FLAG_OPT_NONSEQ_SET; 5174 softc->optimal_nonseq_zones = 0; 5175 } 5176 5177 tmpvar = le64dec(zi_log->max_seq_req_zones); 5178 if (tmpvar & ATA_ZDI_MAX_SEQ_VALID) { 5179 softc->zone_flags |= 5180 DA_ZONE_FLAG_MAX_SEQ_SET; 5181 softc->max_seq_zones = 5182 (tmpvar & ATA_ZDI_MAX_SEQ_MASK); 5183 } else { 5184 softc->zone_flags &= 5185 ~DA_ZONE_FLAG_MAX_SEQ_SET; 5186 softc->max_seq_zones = 0; 5187 } 5188 } 5189 } else { 5190 error = daerror(done_ccb, CAM_RETRY_SELTO, 5191 SF_RETRY_UA|SF_NO_PRINT); 5192 if (error == ERESTART) 5193 return; 5194 else if (error != 0) { 5195 softc->flags &= ~DA_FLAG_CAN_ATA_ZONE; 5196 softc->flags &= ~DA_ZONE_FLAG_SET_MASK; 5197 5198 if ((done_ccb->ccb_h.status & 5199 CAM_DEV_QFRZN) != 0) { 5200 /* Don't wedge this device's queue */ 5201 cam_release_devq(done_ccb->ccb_h.path, 5202 /*relsim_flags*/0, 5203 /*reduction*/0, 5204 /*timeout*/0, 5205 /*getcount_only*/0); 5206 } 5207 } 5208 5209 } 5210 free(csio->data_ptr, M_SCSIDA); 5211 5212 daprobedone(periph, done_ccb); 5213 return; 5214 } 5215 case DA_CCB_PROBE_ZONE: 5216 { 5217 int error; 5218 5219 if ((csio->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_CMP) { 5220 uint32_t valid_len; 5221 size_t needed_len; 5222 struct scsi_vpd_zoned_bdc *zoned_bdc; 5223 5224 error = 0; 5225 zoned_bdc = (struct scsi_vpd_zoned_bdc *) 5226 csio->data_ptr; 5227 valid_len = csio->dxfer_len - csio->resid; 5228 needed_len = __offsetof(struct scsi_vpd_zoned_bdc, 5229 max_seq_req_zones) + 1 + 5230 sizeof(zoned_bdc->max_seq_req_zones); 5231 if ((valid_len >= needed_len) 5232 && (scsi_2btoul(zoned_bdc->page_length) >= 5233 SVPD_ZBDC_PL)) { 5234 if (zoned_bdc->flags & SVPD_ZBDC_URSWRZ) 5235 softc->zone_flags |= 5236 DA_ZONE_FLAG_URSWRZ; 5237 else 5238 softc->zone_flags &= 5239 ~DA_ZONE_FLAG_URSWRZ; 5240 softc->optimal_seq_zones = 5241 scsi_4btoul(zoned_bdc->optimal_seq_zones); 5242 softc->zone_flags |= DA_ZONE_FLAG_OPT_SEQ_SET; 5243 softc->optimal_nonseq_zones = scsi_4btoul( 5244 zoned_bdc->optimal_nonseq_zones); 5245 softc->zone_flags |= 5246 DA_ZONE_FLAG_OPT_NONSEQ_SET; 5247 softc->max_seq_zones = 5248 scsi_4btoul(zoned_bdc->max_seq_req_zones); 5249 softc->zone_flags |= DA_ZONE_FLAG_MAX_SEQ_SET; 5250 } 5251 /* 5252 * All of the zone commands are mandatory for SCSI 5253 * devices. 5254 * 5255 * XXX KDM this is valid as of September 2015. 5256 * Re-check this assumption once the SAT spec is 5257 * updated to support SCSI ZBC to ATA ZAC mapping. 5258 * Since ATA allows zone commands to be reported 5259 * as supported or not, this may not necessarily 5260 * be true for an ATA device behind a SAT (SCSI to 5261 * ATA Translation) layer. 5262 */ 5263 softc->zone_flags |= DA_ZONE_FLAG_SUP_MASK; 5264 } else { 5265 error = daerror(done_ccb, CAM_RETRY_SELTO, 5266 SF_RETRY_UA|SF_NO_PRINT); 5267 if (error == ERESTART) 5268 return; 5269 else if (error != 0) { 5270 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { 5271 /* Don't wedge this device's queue */ 5272 cam_release_devq(done_ccb->ccb_h.path, 5273 /*relsim_flags*/0, 5274 /*reduction*/0, 5275 /*timeout*/0, 5276 /*getcount_only*/0); 5277 } 5278 } 5279 } 5280 daprobedone(periph, done_ccb); 5281 return; 5282 } 5283 case DA_CCB_DUMP: 5284 /* No-op. We're polling */ 5285 return; 5286 case DA_CCB_TUR: 5287 { 5288 if ((done_ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 5289 5290 if (daerror(done_ccb, CAM_RETRY_SELTO, 5291 SF_RETRY_UA | SF_NO_RECOVERY | SF_NO_PRINT) == 5292 ERESTART) 5293 return; 5294 if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) 5295 cam_release_devq(done_ccb->ccb_h.path, 5296 /*relsim_flags*/0, 5297 /*reduction*/0, 5298 /*timeout*/0, 5299 /*getcount_only*/0); 5300 } 5301 xpt_release_ccb(done_ccb); 5302 cam_periph_release_locked(periph); 5303 return; 5304 } 5305 default: 5306 break; 5307 } 5308 xpt_release_ccb(done_ccb); 5309 } 5310 5311 static void 5312 dareprobe(struct cam_periph *periph) 5313 { 5314 struct da_softc *softc; 5315 cam_status status; 5316 5317 softc = (struct da_softc *)periph->softc; 5318 5319 /* Probe in progress; don't interfere. */ 5320 if (softc->state != DA_STATE_NORMAL) 5321 return; 5322 5323 status = cam_periph_acquire(periph); 5324 KASSERT(status == CAM_REQ_CMP, 5325 ("dareprobe: cam_periph_acquire failed")); 5326 5327 if (softc->flags & DA_FLAG_CAN_RC16) 5328 softc->state = DA_STATE_PROBE_RC16; 5329 else 5330 softc->state = DA_STATE_PROBE_RC; 5331 5332 xpt_schedule(periph, CAM_PRIORITY_DEV); 5333 } 5334 5335 static int 5336 daerror(union ccb *ccb, u_int32_t cam_flags, u_int32_t sense_flags) 5337 { 5338 struct da_softc *softc; 5339 struct cam_periph *periph; 5340 int error, error_code, sense_key, asc, ascq; 5341 5342 #if defined(BUF_TRACKING) || defined(FULL_BUF_TRACKING) 5343 if (ccb->csio.bio != NULL) 5344 biotrack(ccb->csio.bio, __func__); 5345 #endif 5346 5347 periph = xpt_path_periph(ccb->ccb_h.path); 5348 softc = (struct da_softc *)periph->softc; 5349 5350 /* 5351 * Automatically detect devices that do not support 5352 * READ(6)/WRITE(6) and upgrade to using 10 byte cdbs. 5353 */ 5354 error = 0; 5355 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INVALID) { 5356 error = cmd6workaround(ccb); 5357 } else if (scsi_extract_sense_ccb(ccb, 5358 &error_code, &sense_key, &asc, &ascq)) { 5359 if (sense_key == SSD_KEY_ILLEGAL_REQUEST) 5360 error = cmd6workaround(ccb); 5361 /* 5362 * If the target replied with CAPACITY DATA HAS CHANGED UA, 5363 * query the capacity and notify upper layers. 5364 */ 5365 else if (sense_key == SSD_KEY_UNIT_ATTENTION && 5366 asc == 0x2A && ascq == 0x09) { 5367 xpt_print(periph->path, "Capacity data has changed\n"); 5368 softc->flags &= ~DA_FLAG_PROBED; 5369 dareprobe(periph); 5370 sense_flags |= SF_NO_PRINT; 5371 } else if (sense_key == SSD_KEY_UNIT_ATTENTION && 5372 asc == 0x28 && ascq == 0x00) { 5373 softc->flags &= ~DA_FLAG_PROBED; 5374 disk_media_changed(softc->disk, M_NOWAIT); 5375 } else if (sense_key == SSD_KEY_UNIT_ATTENTION && 5376 asc == 0x3F && ascq == 0x03) { 5377 xpt_print(periph->path, "INQUIRY data has changed\n"); 5378 softc->flags &= ~DA_FLAG_PROBED; 5379 dareprobe(periph); 5380 sense_flags |= SF_NO_PRINT; 5381 } else if (sense_key == SSD_KEY_NOT_READY && 5382 asc == 0x3a && (softc->flags & DA_FLAG_PACK_INVALID) == 0) { 5383 softc->flags |= DA_FLAG_PACK_INVALID; 5384 disk_media_gone(softc->disk, M_NOWAIT); 5385 } 5386 } 5387 if (error == ERESTART) 5388 return (ERESTART); 5389 5390 #ifdef CAM_IO_STATS 5391 switch (ccb->ccb_h.status & CAM_STATUS_MASK) { 5392 case CAM_CMD_TIMEOUT: 5393 softc->timeouts++; 5394 break; 5395 case CAM_REQ_ABORTED: 5396 case CAM_REQ_CMP_ERR: 5397 case CAM_REQ_TERMIO: 5398 case CAM_UNREC_HBA_ERROR: 5399 case CAM_DATA_RUN_ERR: 5400 softc->errors++; 5401 break; 5402 default: 5403 break; 5404 } 5405 #endif 5406 5407 /* 5408 * XXX 5409 * Until we have a better way of doing pack validation, 5410 * don't treat UAs as errors. 5411 */ 5412 sense_flags |= SF_RETRY_UA; 5413 5414 if (softc->quirks & DA_Q_RETRY_BUSY) 5415 sense_flags |= SF_RETRY_BUSY; 5416 return(cam_periph_error(ccb, cam_flags, sense_flags, 5417 &softc->saved_ccb)); 5418 } 5419 5420 static void 5421 damediapoll(void *arg) 5422 { 5423 struct cam_periph *periph = arg; 5424 struct da_softc *softc = periph->softc; 5425 5426 if (!cam_iosched_has_work_flags(softc->cam_iosched, DA_WORK_TUR) && 5427 LIST_EMPTY(&softc->pending_ccbs)) { 5428 if (cam_periph_acquire(periph) == CAM_REQ_CMP) { 5429 cam_iosched_set_work_flags(softc->cam_iosched, DA_WORK_TUR); 5430 daschedule(periph); 5431 } 5432 } 5433 /* Queue us up again */ 5434 if (da_poll_period != 0) 5435 callout_schedule(&softc->mediapoll_c, da_poll_period * hz); 5436 } 5437 5438 static void 5439 daprevent(struct cam_periph *periph, int action) 5440 { 5441 struct da_softc *softc; 5442 union ccb *ccb; 5443 int error; 5444 5445 softc = (struct da_softc *)periph->softc; 5446 5447 if (((action == PR_ALLOW) 5448 && (softc->flags & DA_FLAG_PACK_LOCKED) == 0) 5449 || ((action == PR_PREVENT) 5450 && (softc->flags & DA_FLAG_PACK_LOCKED) != 0)) { 5451 return; 5452 } 5453 5454 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); 5455 5456 scsi_prevent(&ccb->csio, 5457 /*retries*/1, 5458 /*cbcfp*/dadone, 5459 MSG_SIMPLE_Q_TAG, 5460 action, 5461 SSD_FULL_SIZE, 5462 5000); 5463 5464 error = cam_periph_runccb(ccb, daerror, CAM_RETRY_SELTO, 5465 SF_RETRY_UA | SF_NO_PRINT, softc->disk->d_devstat); 5466 5467 if (error == 0) { 5468 if (action == PR_ALLOW) 5469 softc->flags &= ~DA_FLAG_PACK_LOCKED; 5470 else 5471 softc->flags |= DA_FLAG_PACK_LOCKED; 5472 } 5473 5474 xpt_release_ccb(ccb); 5475 } 5476 5477 static void 5478 dasetgeom(struct cam_periph *periph, uint32_t block_len, uint64_t maxsector, 5479 struct scsi_read_capacity_data_long *rcaplong, size_t rcap_len) 5480 { 5481 struct ccb_calc_geometry ccg; 5482 struct da_softc *softc; 5483 struct disk_params *dp; 5484 u_int lbppbe, lalba; 5485 int error; 5486 5487 softc = (struct da_softc *)periph->softc; 5488 5489 dp = &softc->params; 5490 dp->secsize = block_len; 5491 dp->sectors = maxsector + 1; 5492 if (rcaplong != NULL) { 5493 lbppbe = rcaplong->prot_lbppbe & SRC16_LBPPBE; 5494 lalba = scsi_2btoul(rcaplong->lalba_lbp); 5495 lalba &= SRC16_LALBA_A; 5496 } else { 5497 lbppbe = 0; 5498 lalba = 0; 5499 } 5500 5501 if (lbppbe > 0) { 5502 dp->stripesize = block_len << lbppbe; 5503 dp->stripeoffset = (dp->stripesize - block_len * lalba) % 5504 dp->stripesize; 5505 } else if (softc->quirks & DA_Q_4K) { 5506 dp->stripesize = 4096; 5507 dp->stripeoffset = 0; 5508 } else if (softc->unmap_gran != 0) { 5509 dp->stripesize = block_len * softc->unmap_gran; 5510 dp->stripeoffset = (dp->stripesize - block_len * 5511 softc->unmap_gran_align) % dp->stripesize; 5512 } else { 5513 dp->stripesize = 0; 5514 dp->stripeoffset = 0; 5515 } 5516 /* 5517 * Have the controller provide us with a geometry 5518 * for this disk. The only time the geometry 5519 * matters is when we boot and the controller 5520 * is the only one knowledgeable enough to come 5521 * up with something that will make this a bootable 5522 * device. 5523 */ 5524 xpt_setup_ccb(&ccg.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 5525 ccg.ccb_h.func_code = XPT_CALC_GEOMETRY; 5526 ccg.block_size = dp->secsize; 5527 ccg.volume_size = dp->sectors; 5528 ccg.heads = 0; 5529 ccg.secs_per_track = 0; 5530 ccg.cylinders = 0; 5531 xpt_action((union ccb*)&ccg); 5532 if ((ccg.ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP) { 5533 /* 5534 * We don't know what went wrong here- but just pick 5535 * a geometry so we don't have nasty things like divide 5536 * by zero. 5537 */ 5538 dp->heads = 255; 5539 dp->secs_per_track = 255; 5540 dp->cylinders = dp->sectors / (255 * 255); 5541 if (dp->cylinders == 0) { 5542 dp->cylinders = 1; 5543 } 5544 } else { 5545 dp->heads = ccg.heads; 5546 dp->secs_per_track = ccg.secs_per_track; 5547 dp->cylinders = ccg.cylinders; 5548 } 5549 5550 /* 5551 * If the user supplied a read capacity buffer, and if it is 5552 * different than the previous buffer, update the data in the EDT. 5553 * If it's the same, we don't bother. This avoids sending an 5554 * update every time someone opens this device. 5555 */ 5556 if ((rcaplong != NULL) 5557 && (bcmp(rcaplong, &softc->rcaplong, 5558 min(sizeof(softc->rcaplong), rcap_len)) != 0)) { 5559 struct ccb_dev_advinfo cdai; 5560 5561 xpt_setup_ccb(&cdai.ccb_h, periph->path, CAM_PRIORITY_NORMAL); 5562 cdai.ccb_h.func_code = XPT_DEV_ADVINFO; 5563 cdai.buftype = CDAI_TYPE_RCAPLONG; 5564 cdai.flags = CDAI_FLAG_STORE; 5565 cdai.bufsiz = rcap_len; 5566 cdai.buf = (uint8_t *)rcaplong; 5567 xpt_action((union ccb *)&cdai); 5568 if ((cdai.ccb_h.status & CAM_DEV_QFRZN) != 0) 5569 cam_release_devq(cdai.ccb_h.path, 0, 0, 0, FALSE); 5570 if (cdai.ccb_h.status != CAM_REQ_CMP) { 5571 xpt_print(periph->path, "%s: failed to set read " 5572 "capacity advinfo\n", __func__); 5573 /* Use cam_error_print() to decode the status */ 5574 cam_error_print((union ccb *)&cdai, CAM_ESF_CAM_STATUS, 5575 CAM_EPF_ALL); 5576 } else { 5577 bcopy(rcaplong, &softc->rcaplong, 5578 min(sizeof(softc->rcaplong), rcap_len)); 5579 } 5580 } 5581 5582 softc->disk->d_sectorsize = softc->params.secsize; 5583 softc->disk->d_mediasize = softc->params.secsize * (off_t)softc->params.sectors; 5584 softc->disk->d_stripesize = softc->params.stripesize; 5585 softc->disk->d_stripeoffset = softc->params.stripeoffset; 5586 /* XXX: these are not actually "firmware" values, so they may be wrong */ 5587 softc->disk->d_fwsectors = softc->params.secs_per_track; 5588 softc->disk->d_fwheads = softc->params.heads; 5589 softc->disk->d_devstat->block_size = softc->params.secsize; 5590 softc->disk->d_devstat->flags &= ~DEVSTAT_BS_UNAVAILABLE; 5591 5592 error = disk_resize(softc->disk, M_NOWAIT); 5593 if (error != 0) 5594 xpt_print(periph->path, "disk_resize(9) failed, error = %d\n", error); 5595 } 5596 5597 static void 5598 dasendorderedtag(void *arg) 5599 { 5600 struct da_softc *softc = arg; 5601 5602 if (da_send_ordered) { 5603 if (!LIST_EMPTY(&softc->pending_ccbs)) { 5604 if ((softc->flags & DA_FLAG_WAS_OTAG) == 0) 5605 softc->flags |= DA_FLAG_NEED_OTAG; 5606 softc->flags &= ~DA_FLAG_WAS_OTAG; 5607 } 5608 } 5609 /* Queue us up again */ 5610 callout_reset(&softc->sendordered_c, 5611 (da_default_timeout * hz) / DA_ORDEREDTAG_INTERVAL, 5612 dasendorderedtag, softc); 5613 } 5614 5615 /* 5616 * Step through all DA peripheral drivers, and if the device is still open, 5617 * sync the disk cache to physical media. 5618 */ 5619 static void 5620 dashutdown(void * arg, int howto) 5621 { 5622 struct cam_periph *periph; 5623 struct da_softc *softc; 5624 union ccb *ccb; 5625 int error; 5626 5627 CAM_PERIPH_FOREACH(periph, &dadriver) { 5628 softc = (struct da_softc *)periph->softc; 5629 if (SCHEDULER_STOPPED()) { 5630 /* If we paniced with the lock held, do not recurse. */ 5631 if (!cam_periph_owned(periph) && 5632 (softc->flags & DA_FLAG_OPEN)) { 5633 dadump(softc->disk, NULL, 0, 0, 0); 5634 } 5635 continue; 5636 } 5637 cam_periph_lock(periph); 5638 5639 /* 5640 * We only sync the cache if the drive is still open, and 5641 * if the drive is capable of it.. 5642 */ 5643 if (((softc->flags & DA_FLAG_OPEN) == 0) 5644 || (softc->quirks & DA_Q_NO_SYNC_CACHE)) { 5645 cam_periph_unlock(periph); 5646 continue; 5647 } 5648 5649 ccb = cam_periph_getccb(periph, CAM_PRIORITY_NORMAL); 5650 scsi_synchronize_cache(&ccb->csio, 5651 /*retries*/0, 5652 /*cbfcnp*/dadone, 5653 MSG_SIMPLE_Q_TAG, 5654 /*begin_lba*/0, /* whole disk */ 5655 /*lb_count*/0, 5656 SSD_FULL_SIZE, 5657 60 * 60 * 1000); 5658 5659 error = cam_periph_runccb(ccb, daerror, /*cam_flags*/0, 5660 /*sense_flags*/ SF_NO_RECOVERY | SF_NO_RETRY | SF_QUIET_IR, 5661 softc->disk->d_devstat); 5662 if (error != 0) 5663 xpt_print(periph->path, "Synchronize cache failed\n"); 5664 xpt_release_ccb(ccb); 5665 cam_periph_unlock(periph); 5666 } 5667 } 5668 5669 #else /* !_KERNEL */ 5670 5671 /* 5672 * XXX These are only left out of the kernel build to silence warnings. If, 5673 * for some reason these functions are used in the kernel, the ifdefs should 5674 * be moved so they are included both in the kernel and userland. 5675 */ 5676 void 5677 scsi_format_unit(struct ccb_scsiio *csio, u_int32_t retries, 5678 void (*cbfcnp)(struct cam_periph *, union ccb *), 5679 u_int8_t tag_action, u_int8_t byte2, u_int16_t ileave, 5680 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5681 u_int32_t timeout) 5682 { 5683 struct scsi_format_unit *scsi_cmd; 5684 5685 scsi_cmd = (struct scsi_format_unit *)&csio->cdb_io.cdb_bytes; 5686 scsi_cmd->opcode = FORMAT_UNIT; 5687 scsi_cmd->byte2 = byte2; 5688 scsi_ulto2b(ileave, scsi_cmd->interleave); 5689 5690 cam_fill_csio(csio, 5691 retries, 5692 cbfcnp, 5693 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, 5694 tag_action, 5695 data_ptr, 5696 dxfer_len, 5697 sense_len, 5698 sizeof(*scsi_cmd), 5699 timeout); 5700 } 5701 5702 void 5703 scsi_read_defects(struct ccb_scsiio *csio, uint32_t retries, 5704 void (*cbfcnp)(struct cam_periph *, union ccb *), 5705 uint8_t tag_action, uint8_t list_format, 5706 uint32_t addr_desc_index, uint8_t *data_ptr, 5707 uint32_t dxfer_len, int minimum_cmd_size, 5708 uint8_t sense_len, uint32_t timeout) 5709 { 5710 uint8_t cdb_len; 5711 5712 /* 5713 * These conditions allow using the 10 byte command. Otherwise we 5714 * need to use the 12 byte command. 5715 */ 5716 if ((minimum_cmd_size <= 10) 5717 && (addr_desc_index == 0) 5718 && (dxfer_len <= SRDD10_MAX_LENGTH)) { 5719 struct scsi_read_defect_data_10 *cdb10; 5720 5721 cdb10 = (struct scsi_read_defect_data_10 *) 5722 &csio->cdb_io.cdb_bytes; 5723 5724 cdb_len = sizeof(*cdb10); 5725 bzero(cdb10, cdb_len); 5726 cdb10->opcode = READ_DEFECT_DATA_10; 5727 cdb10->format = list_format; 5728 scsi_ulto2b(dxfer_len, cdb10->alloc_length); 5729 } else { 5730 struct scsi_read_defect_data_12 *cdb12; 5731 5732 cdb12 = (struct scsi_read_defect_data_12 *) 5733 &csio->cdb_io.cdb_bytes; 5734 5735 cdb_len = sizeof(*cdb12); 5736 bzero(cdb12, cdb_len); 5737 cdb12->opcode = READ_DEFECT_DATA_12; 5738 cdb12->format = list_format; 5739 scsi_ulto4b(dxfer_len, cdb12->alloc_length); 5740 scsi_ulto4b(addr_desc_index, cdb12->address_descriptor_index); 5741 } 5742 5743 cam_fill_csio(csio, 5744 retries, 5745 cbfcnp, 5746 /*flags*/ CAM_DIR_IN, 5747 tag_action, 5748 data_ptr, 5749 dxfer_len, 5750 sense_len, 5751 cdb_len, 5752 timeout); 5753 } 5754 5755 void 5756 scsi_sanitize(struct ccb_scsiio *csio, u_int32_t retries, 5757 void (*cbfcnp)(struct cam_periph *, union ccb *), 5758 u_int8_t tag_action, u_int8_t byte2, u_int16_t control, 5759 u_int8_t *data_ptr, u_int32_t dxfer_len, u_int8_t sense_len, 5760 u_int32_t timeout) 5761 { 5762 struct scsi_sanitize *scsi_cmd; 5763 5764 scsi_cmd = (struct scsi_sanitize *)&csio->cdb_io.cdb_bytes; 5765 scsi_cmd->opcode = SANITIZE; 5766 scsi_cmd->byte2 = byte2; 5767 scsi_cmd->control = control; 5768 scsi_ulto2b(dxfer_len, scsi_cmd->length); 5769 5770 cam_fill_csio(csio, 5771 retries, 5772 cbfcnp, 5773 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, 5774 tag_action, 5775 data_ptr, 5776 dxfer_len, 5777 sense_len, 5778 sizeof(*scsi_cmd), 5779 timeout); 5780 } 5781 5782 #endif /* _KERNEL */ 5783 5784 void 5785 scsi_zbc_out(struct ccb_scsiio *csio, uint32_t retries, 5786 void (*cbfcnp)(struct cam_periph *, union ccb *), 5787 uint8_t tag_action, uint8_t service_action, uint64_t zone_id, 5788 uint8_t zone_flags, uint8_t *data_ptr, uint32_t dxfer_len, 5789 uint8_t sense_len, uint32_t timeout) 5790 { 5791 struct scsi_zbc_out *scsi_cmd; 5792 5793 scsi_cmd = (struct scsi_zbc_out *)&csio->cdb_io.cdb_bytes; 5794 scsi_cmd->opcode = ZBC_OUT; 5795 scsi_cmd->service_action = service_action; 5796 scsi_u64to8b(zone_id, scsi_cmd->zone_id); 5797 scsi_cmd->zone_flags = zone_flags; 5798 5799 cam_fill_csio(csio, 5800 retries, 5801 cbfcnp, 5802 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, 5803 tag_action, 5804 data_ptr, 5805 dxfer_len, 5806 sense_len, 5807 sizeof(*scsi_cmd), 5808 timeout); 5809 } 5810 5811 void 5812 scsi_zbc_in(struct ccb_scsiio *csio, uint32_t retries, 5813 void (*cbfcnp)(struct cam_periph *, union ccb *), 5814 uint8_t tag_action, uint8_t service_action, uint64_t zone_start_lba, 5815 uint8_t zone_options, uint8_t *data_ptr, uint32_t dxfer_len, 5816 uint8_t sense_len, uint32_t timeout) 5817 { 5818 struct scsi_zbc_in *scsi_cmd; 5819 5820 scsi_cmd = (struct scsi_zbc_in *)&csio->cdb_io.cdb_bytes; 5821 scsi_cmd->opcode = ZBC_IN; 5822 scsi_cmd->service_action = service_action; 5823 scsi_ulto4b(dxfer_len, scsi_cmd->length); 5824 scsi_u64to8b(zone_start_lba, scsi_cmd->zone_start_lba); 5825 scsi_cmd->zone_options = zone_options; 5826 5827 cam_fill_csio(csio, 5828 retries, 5829 cbfcnp, 5830 /*flags*/ (dxfer_len > 0) ? CAM_DIR_IN : CAM_DIR_NONE, 5831 tag_action, 5832 data_ptr, 5833 dxfer_len, 5834 sense_len, 5835 sizeof(*scsi_cmd), 5836 timeout); 5837 5838 } 5839 5840 int 5841 scsi_ata_zac_mgmt_out(struct ccb_scsiio *csio, uint32_t retries, 5842 void (*cbfcnp)(struct cam_periph *, union ccb *), 5843 uint8_t tag_action, int use_ncq, 5844 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags, 5845 uint8_t *data_ptr, uint32_t dxfer_len, 5846 uint8_t *cdb_storage, size_t cdb_storage_len, 5847 uint8_t sense_len, uint32_t timeout) 5848 { 5849 uint8_t command_out, protocol, ata_flags; 5850 uint16_t features_out; 5851 uint32_t sectors_out, auxiliary; 5852 int retval; 5853 5854 retval = 0; 5855 5856 if (use_ncq == 0) { 5857 command_out = ATA_ZAC_MANAGEMENT_OUT; 5858 features_out = (zm_action & 0xf) | (zone_flags << 8); 5859 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS; 5860 if (dxfer_len == 0) { 5861 protocol = AP_PROTO_NON_DATA; 5862 ata_flags |= AP_FLAG_TLEN_NO_DATA; 5863 sectors_out = 0; 5864 } else { 5865 protocol = AP_PROTO_DMA; 5866 ata_flags |= AP_FLAG_TLEN_SECT_CNT | 5867 AP_FLAG_TDIR_TO_DEV; 5868 sectors_out = ((dxfer_len >> 9) & 0xffff); 5869 } 5870 auxiliary = 0; 5871 } else { 5872 ata_flags = AP_FLAG_BYT_BLOK_BLOCKS; 5873 if (dxfer_len == 0) { 5874 command_out = ATA_NCQ_NON_DATA; 5875 features_out = ATA_NCQ_ZAC_MGMT_OUT; 5876 /* 5877 * We're assuming the SCSI to ATA translation layer 5878 * will set the NCQ tag number in the tag field. 5879 * That isn't clear from the SAT-4 spec (as of rev 05). 5880 */ 5881 sectors_out = 0; 5882 ata_flags |= AP_FLAG_TLEN_NO_DATA; 5883 } else { 5884 command_out = ATA_SEND_FPDMA_QUEUED; 5885 /* 5886 * Note that we're defaulting to normal priority, 5887 * and assuming that the SCSI to ATA translation 5888 * layer will insert the NCQ tag number in the tag 5889 * field. That isn't clear in the SAT-4 spec (as 5890 * of rev 05). 5891 */ 5892 sectors_out = ATA_SFPDMA_ZAC_MGMT_OUT << 8; 5893 5894 ata_flags |= AP_FLAG_TLEN_FEAT | 5895 AP_FLAG_TDIR_TO_DEV; 5896 5897 /* 5898 * For SEND FPDMA QUEUED, the transfer length is 5899 * encoded in the FEATURE register, and 0 means 5900 * that 65536 512 byte blocks are to be tranferred. 5901 * In practice, it seems unlikely that we'll see 5902 * a transfer that large, and it may confuse the 5903 * the SAT layer, because generally that means that 5904 * 0 bytes should be transferred. 5905 */ 5906 if (dxfer_len == (65536 * 512)) { 5907 features_out = 0; 5908 } else if (dxfer_len <= (65535 * 512)) { 5909 features_out = ((dxfer_len >> 9) & 0xffff); 5910 } else { 5911 /* The transfer is too big. */ 5912 retval = 1; 5913 goto bailout; 5914 } 5915 5916 } 5917 5918 auxiliary = (zm_action & 0xf) | (zone_flags << 8); 5919 protocol = AP_PROTO_FPDMA; 5920 } 5921 5922 protocol |= AP_EXTEND; 5923 5924 retval = scsi_ata_pass(csio, 5925 retries, 5926 cbfcnp, 5927 /*flags*/ (dxfer_len > 0) ? CAM_DIR_OUT : CAM_DIR_NONE, 5928 tag_action, 5929 /*protocol*/ protocol, 5930 /*ata_flags*/ ata_flags, 5931 /*features*/ features_out, 5932 /*sector_count*/ sectors_out, 5933 /*lba*/ zone_id, 5934 /*command*/ command_out, 5935 /*device*/ 0, 5936 /*icc*/ 0, 5937 /*auxiliary*/ auxiliary, 5938 /*control*/ 0, 5939 /*data_ptr*/ data_ptr, 5940 /*dxfer_len*/ dxfer_len, 5941 /*cdb_storage*/ cdb_storage, 5942 /*cdb_storage_len*/ cdb_storage_len, 5943 /*minimum_cmd_size*/ 0, 5944 /*sense_len*/ SSD_FULL_SIZE, 5945 /*timeout*/ timeout); 5946 5947 bailout: 5948 5949 return (retval); 5950 } 5951 5952 int 5953 scsi_ata_zac_mgmt_in(struct ccb_scsiio *csio, uint32_t retries, 5954 void (*cbfcnp)(struct cam_periph *, union ccb *), 5955 uint8_t tag_action, int use_ncq, 5956 uint8_t zm_action, uint64_t zone_id, uint8_t zone_flags, 5957 uint8_t *data_ptr, uint32_t dxfer_len, 5958 uint8_t *cdb_storage, size_t cdb_storage_len, 5959 uint8_t sense_len, uint32_t timeout) 5960 { 5961 uint8_t command_out, protocol; 5962 uint16_t features_out, sectors_out; 5963 uint32_t auxiliary; 5964 int ata_flags; 5965 int retval; 5966 5967 retval = 0; 5968 ata_flags = AP_FLAG_TDIR_FROM_DEV | AP_FLAG_BYT_BLOK_BLOCKS; 5969 5970 if (use_ncq == 0) { 5971 command_out = ATA_ZAC_MANAGEMENT_IN; 5972 /* XXX KDM put a macro here */ 5973 features_out = (zm_action & 0xf) | (zone_flags << 8); 5974 sectors_out = dxfer_len >> 9; /* XXX KDM macro */ 5975 protocol = AP_PROTO_DMA; 5976 ata_flags |= AP_FLAG_TLEN_SECT_CNT; 5977 auxiliary = 0; 5978 } else { 5979 ata_flags |= AP_FLAG_TLEN_FEAT; 5980 5981 command_out = ATA_RECV_FPDMA_QUEUED; 5982 sectors_out = ATA_RFPDMA_ZAC_MGMT_IN << 8; 5983 5984 /* 5985 * For RECEIVE FPDMA QUEUED, the transfer length is 5986 * encoded in the FEATURE register, and 0 means 5987 * that 65536 512 byte blocks are to be tranferred. 5988 * In practice, it seems unlikely that we'll see 5989 * a transfer that large, and it may confuse the 5990 * the SAT layer, because generally that means that 5991 * 0 bytes should be transferred. 5992 */ 5993 if (dxfer_len == (65536 * 512)) { 5994 features_out = 0; 5995 } else if (dxfer_len <= (65535 * 512)) { 5996 features_out = ((dxfer_len >> 9) & 0xffff); 5997 } else { 5998 /* The transfer is too big. */ 5999 retval = 1; 6000 goto bailout; 6001 } 6002 auxiliary = (zm_action & 0xf) | (zone_flags << 8), 6003 protocol = AP_PROTO_FPDMA; 6004 } 6005 6006 protocol |= AP_EXTEND; 6007 6008 retval = scsi_ata_pass(csio, 6009 retries, 6010 cbfcnp, 6011 /*flags*/ CAM_DIR_IN, 6012 tag_action, 6013 /*protocol*/ protocol, 6014 /*ata_flags*/ ata_flags, 6015 /*features*/ features_out, 6016 /*sector_count*/ sectors_out, 6017 /*lba*/ zone_id, 6018 /*command*/ command_out, 6019 /*device*/ 0, 6020 /*icc*/ 0, 6021 /*auxiliary*/ auxiliary, 6022 /*control*/ 0, 6023 /*data_ptr*/ data_ptr, 6024 /*dxfer_len*/ (dxfer_len >> 9) * 512, /* XXX KDM */ 6025 /*cdb_storage*/ cdb_storage, 6026 /*cdb_storage_len*/ cdb_storage_len, 6027 /*minimum_cmd_size*/ 0, 6028 /*sense_len*/ SSD_FULL_SIZE, 6029 /*timeout*/ timeout); 6030 6031 bailout: 6032 return (retval); 6033 } 6034