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