aha.c revision 41514
1/* 2 * Generic register and struct definitions for the Adaptech 154x/164x 3 * SCSI host adapters. Product specific probe and attach routines can 4 * be found in: 5 * aha 1540/1542B/1542C/1542CF/1542CP aha_isa.c 6 * 7 * Copyright (c) 1998 M. Warner Losh. 8 * All Rights Reserved. 9 * 10 * 11 * Redistribution and use in source and binary forms, with or without 12 * modification, are permitted provided that the following conditions 13 * are met: 14 * 1. Redistributions of source code must retain the above copyright 15 * notice, this list of conditions, and the following disclaimer, 16 * without modification, immediately at the beginning of the file. 17 * 2. The name of the author may not be used to endorse or promote products 18 * derived from this software without specific prior written permission. 19 * 20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 24 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30 * SUCH DAMAGE. 31 * 32 * Derived from bt.c written by: 33 * 34 * Copyright (c) 1998 Justin T. Gibbs. 35 * All rights reserved. 36 * 37 * Redistribution and use in source and binary forms, with or without 38 * modification, are permitted provided that the following conditions 39 * are met: 40 * 1. Redistributions of source code must retain the above copyright 41 * notice, this list of conditions, and the following disclaimer, 42 * without modification, immediately at the beginning of the file. 43 * 2. The name of the author may not be used to endorse or promote products 44 * derived from this software without specific prior written permission. 45 * 46 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 47 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 48 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 49 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 50 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 51 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 52 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 53 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 55 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 56 * SUCH DAMAGE. 57 * 58 * $Id: aha.c,v 1.13 1998/11/25 19:12:56 imp Exp $ 59 */ 60 61#include <sys/param.h> 62#include <sys/systm.h> 63#include <sys/malloc.h> 64#include <sys/buf.h> 65#include <sys/kernel.h> 66#include <sys/sysctl.h> 67 68#include <machine/bus_pio.h> 69#include <machine/bus.h> 70#include <machine/clock.h> 71 72#include <cam/cam.h> 73#include <cam/cam_ccb.h> 74#include <cam/cam_sim.h> 75#include <cam/cam_xpt_sim.h> 76#include <cam/cam_debug.h> 77 78#include <cam/scsi/scsi_message.h> 79 80#include <vm/vm.h> 81#include <vm/pmap.h> 82 83#include <dev/aha/ahareg.h> 84 85struct aha_softc *aha_softcs[NAHA]; 86 87#define MIN(a, b) ((a) < (b) ? (a) : (b)) 88#define PRVERB(x) if (bootverbose) printf x 89 90/* Macro to determine that a rev is potentially a new valid one 91 * so that the driver doesn't keep breaking on new revs as it 92 * did for the CF and CP. 93 */ 94#define PROBABLY_NEW_BOARD(REV) (REV > 0x43 && REV < 0x56) 95 96/* MailBox Management functions */ 97static __inline void ahanextinbox(struct aha_softc *aha); 98static __inline void ahanextoutbox(struct aha_softc *aha); 99 100static __inline void 101ahanextinbox(struct aha_softc *aha) 102{ 103 if (aha->cur_inbox == aha->last_inbox) 104 aha->cur_inbox = aha->in_boxes; 105 else 106 aha->cur_inbox++; 107} 108 109static __inline void 110ahanextoutbox(struct aha_softc *aha) 111{ 112 if (aha->cur_outbox == aha->last_outbox) 113 aha->cur_outbox = aha->out_boxes; 114 else 115 aha->cur_outbox++; 116} 117 118#define ahautoa24(u,s3) \ 119 (s3)[0] = ((u) >> 16) & 0xff; \ 120 (s3)[1] = ((u) >> 8) & 0xff; \ 121 (s3)[2] = (u) & 0xff; 122 123#define aha_a24tou(s3) \ 124 (((s3)[0] << 16) | ((s3)[1] << 8) | (s3)[2]) 125 126/* CCB Mangement functions */ 127static __inline u_int32_t ahaccbvtop(struct aha_softc *aha, 128 struct aha_ccb *accb); 129static __inline struct aha_ccb* ahaccbptov(struct aha_softc *aha, 130 u_int32_t ccb_addr); 131 132static __inline u_int32_t 133ahaccbvtop(struct aha_softc *aha, struct aha_ccb *accb) 134{ 135 return (aha->aha_ccb_physbase 136 + (u_int32_t)((caddr_t)accb - (caddr_t)aha->aha_ccb_array)); 137} 138static __inline struct aha_ccb * 139ahaccbptov(struct aha_softc *aha, u_int32_t ccb_addr) 140{ 141 return (aha->aha_ccb_array + 142 + ((struct aha_ccb*)ccb_addr-(struct aha_ccb*)aha->aha_ccb_physbase)); 143} 144 145static struct aha_ccb* ahagetccb(struct aha_softc *aha); 146static __inline void ahafreeccb(struct aha_softc *aha, struct aha_ccb *accb); 147static void ahaallocccbs(struct aha_softc *aha); 148static bus_dmamap_callback_t ahaexecuteccb; 149static void ahadone(struct aha_softc *aha, struct aha_ccb *accb, 150 aha_mbi_comp_code_t comp_code); 151 152/* Host adapter command functions */ 153static int ahareset(struct aha_softc* aha, int hard_reset); 154 155/* Initialization functions */ 156static int ahainitmboxes(struct aha_softc *aha); 157static bus_dmamap_callback_t ahamapmboxes; 158static bus_dmamap_callback_t ahamapccbs; 159static bus_dmamap_callback_t ahamapsgs; 160 161/* Transfer Negotiation Functions */ 162static void ahafetchtransinfo(struct aha_softc *aha, 163 struct ccb_trans_settings *cts); 164 165/* CAM SIM entry points */ 166#define ccb_accb_ptr spriv_ptr0 167#define ccb_aha_ptr spriv_ptr1 168static void ahaaction(struct cam_sim *sim, union ccb *ccb); 169static void ahapoll(struct cam_sim *sim); 170 171/* Our timeout handler */ 172timeout_t ahatimeout; 173 174u_long aha_unit = 0; 175 176/* 177 * Do our own re-probe protection until a configuration 178 * manager can do it for us. This ensures that we don't 179 * reprobe a card already found by the EISA or PCI probes. 180 */ 181struct aha_isa_port aha_isa_ports[] = 182{ 183 { 0x130, 0, 4 }, 184 { 0x134, 0, 5 }, 185 { 0x230, 0, 2 }, 186 { 0x234, 0, 3 }, 187 { 0x330, 0, 0 }, 188 { 0x334, 0, 1 } 189}; 190 191/* 192 * I/O ports listed in the order enumerated by the 193 * card for certain op codes. 194 */ 195u_int16_t aha_board_ports[] = 196{ 197 0x330, 198 0x334, 199 0x230, 200 0x234, 201 0x130, 202 0x134 203}; 204 205/* Exported functions */ 206struct aha_softc * 207aha_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh) 208{ 209 struct aha_softc *aha; 210 211 if (unit != AHA_TEMP_UNIT) { 212 if (unit >= NAHA) { 213 printf("aha: unit number (%d) too high\n", unit); 214 return NULL; 215 } 216 217 /* 218 * Allocate a storage area for us 219 */ 220 if (aha_softcs[unit]) { 221 printf("aha%d: memory already allocated\n", unit); 222 return NULL; 223 } 224 } 225 226 aha = malloc(sizeof(struct aha_softc), M_DEVBUF, M_NOWAIT); 227 if (!aha) { 228 printf("aha%d: cannot malloc!\n", unit); 229 return NULL; 230 } 231 bzero(aha, sizeof(struct aha_softc)); 232 SLIST_INIT(&aha->free_aha_ccbs); 233 LIST_INIT(&aha->pending_ccbs); 234 SLIST_INIT(&aha->sg_maps); 235 aha->unit = unit; 236 aha->tag = tag; 237 aha->bsh = bsh; 238 239 if (aha->unit != AHA_TEMP_UNIT) { 240 aha_softcs[unit] = aha; 241 } 242 return (aha); 243} 244 245void 246aha_free(struct aha_softc *aha) 247{ 248 switch (aha->init_level) { 249 default: 250 case 8: 251 { 252 struct sg_map_node *sg_map; 253 254 while ((sg_map = SLIST_FIRST(&aha->sg_maps))!= NULL) { 255 SLIST_REMOVE_HEAD(&aha->sg_maps, links); 256 bus_dmamap_unload(aha->sg_dmat, 257 sg_map->sg_dmamap); 258 bus_dmamem_free(aha->sg_dmat, sg_map->sg_vaddr, 259 sg_map->sg_dmamap); 260 free(sg_map, M_DEVBUF); 261 } 262 bus_dma_tag_destroy(aha->sg_dmat); 263 } 264 case 7: 265 bus_dmamap_unload(aha->ccb_dmat, aha->ccb_dmamap); 266 case 6: 267 bus_dmamap_destroy(aha->ccb_dmat, aha->ccb_dmamap); 268 bus_dmamem_free(aha->ccb_dmat, aha->aha_ccb_array, 269 aha->ccb_dmamap); 270 case 5: 271 bus_dma_tag_destroy(aha->ccb_dmat); 272 case 4: 273 bus_dmamap_unload(aha->mailbox_dmat, aha->mailbox_dmamap); 274 case 3: 275 bus_dmamem_free(aha->mailbox_dmat, aha->in_boxes, 276 aha->mailbox_dmamap); 277 bus_dmamap_destroy(aha->mailbox_dmat, aha->mailbox_dmamap); 278 case 2: 279 bus_dma_tag_destroy(aha->buffer_dmat); 280 case 1: 281 bus_dma_tag_destroy(aha->mailbox_dmat); 282 case 0: 283 } 284 if (aha->unit != AHA_TEMP_UNIT) { 285 aha_softcs[aha->unit] = NULL; 286 } 287 free(aha, M_DEVBUF); 288} 289 290/* 291 * Probe the adapter and verify that the card is an Adaptec. 292 */ 293int 294aha_probe(struct aha_softc* aha) 295{ 296 u_int status; 297 u_int intstat; 298 int error; 299 board_id_data_t board_id; 300 301 /* 302 * See if the three I/O ports look reasonable. 303 * Touch the minimal number of registers in the 304 * failure case. 305 */ 306 status = aha_inb(aha, STATUS_REG); 307 if ((status == 0) 308 || (status & (DIAG_ACTIVE|CMD_REG_BUSY| 309 STATUS_REG_RSVD)) != 0) { 310 PRVERB(("%s: status reg test failed %x\n", aha_name(aha), 311 status)); 312 return (ENXIO); 313 } 314 315 intstat = aha_inb(aha, INTSTAT_REG); 316 if ((intstat & INTSTAT_REG_RSVD) != 0) { 317 PRVERB(("%s: Failed Intstat Reg Test\n", aha_name(aha))); 318 return (ENXIO); 319 } 320 321 /* 322 * Looking good so far. Final test is to reset the 323 * adapter and fetch the board ID and ensure we aren't 324 * looking at a BusLogic. 325 */ 326 if ((error = ahareset(aha, /*hard_reset*/TRUE)) != 0) { 327 if (bootverbose) 328 printf("%s: Failed Reset\n", aha_name(aha)); 329 return (ENXIO); 330 } 331 332 /* 333 * Get the board ID. We use this to see if we're dealing with 334 * a buslogic card or a aha card (or clone). 335 */ 336 error = aha_cmd(aha, AOP_INQUIRE_BOARD_ID, NULL, /*parmlen*/0, 337 (u_int8_t*)&board_id, sizeof(board_id), 338 DEFAULT_CMD_TIMEOUT); 339 if (error != 0) { 340 PRVERB(("%s: INQUIRE failed %x\n", aha_name(aha), error)); 341 return (ENXIO); 342 } 343 aha->fw_major = board_id.firmware_rev_major; 344 aha->fw_minor = board_id.firmware_rev_minor; 345 aha->boardid = board_id.board_type; 346 347 /* 348 * The Buslogic cards have an id of either 0x41 or 0x42. So 349 * if those come up in the probe, we test the geometry register 350 * of the board. Adaptec boards that are this old will not have 351 * this register, and return 0xff, while buslogic cards will return 352 * something different. 353 * 354 * It appears that for reasons unknow, for the for the 355 * aha-1542B cards, we need to wait a little bit before trying 356 * to read the geometry register. I picked 10ms since we have 357 * reports that a for loop to 1000 did the trick, and this 358 * errs on the side of conservatism. Besides, no one will 359 * notice a 10mS delay here, even the 1542B card users :-) 360 * 361 * XXX I'm not sure how this will impact other cloned cards 362 */ 363 if (aha->boardid <= 0x42) { 364 /* Wait 10ms before reading */ 365 DELAY(10000); 366 status = aha_inb(aha, GEOMETRY_REG); 367 if (status != 0xff) { 368 PRVERB(("%s: Geometry Register test failed\n", 369 aha_name(aha))); 370 return (ENXIO); 371 } 372 } 373 374 return (0); 375} 376 377/* 378 * Pull the boards setup information and record it in our softc. 379 */ 380int 381aha_fetch_adapter_info(struct aha_softc *aha) 382{ 383 setup_data_t setup_info; 384 config_data_t config_data; 385 u_int8_t length_param; 386 int error; 387 struct aha_extbios extbios; 388 389 switch (aha->boardid) { 390 case BOARD_1540_16HEAD_BIOS: 391 snprintf(aha->model, sizeof(aha->model), "1540 16 head BIOS"); 392 break; 393 case BOARD_1540_64HEAD_BIOS: 394 snprintf(aha->model, sizeof(aha->model), "1540 64 head BIOS"); 395 break; 396 case BOARD_1542: 397 snprintf(aha->model, sizeof(aha->model), "1540/1542 64 head BIOS"); 398 break; 399 case BOARD_1640: 400 snprintf(aha->model, sizeof(aha->model), "1640"); 401 break; 402 case BOARD_1740: 403 snprintf(aha->model, sizeof(aha->model), "1740A/1742A/1744"); 404 break; 405 case BOARD_1542C: 406 snprintf(aha->model, sizeof(aha->model), "1542C"); 407 break; 408 case BOARD_1542CF: 409 snprintf(aha->model, sizeof(aha->model), "1542CF"); 410 break; 411 case BOARD_1542CP: 412 snprintf(aha->model, sizeof(aha->model), "1542CP"); 413 break; 414 default: 415 snprintf(aha->model, sizeof(aha->model), "Unknown"); 416 break; 417 } 418 /* 419 * If we are a new type of 1542 board (anything newer than a 1542C) 420 * then disable the extended bios so that the 421 * mailbox interface is unlocked. 422 * This is also true for the 1542B Version 3.20. First Adaptec 423 * board that supports >1Gb drives. 424 * No need to check the extended bios flags as some of the 425 * extensions that cause us problems are not flagged in that byte. 426 */ 427 if (PROBABLY_NEW_BOARD(aha->boardid) || 428 (aha->boardid == 0x41 429 && aha->fw_major == 0x31 && 430 aha->fw_minor >= 0x34)) { 431 error = aha_cmd(aha, AOP_RETURN_EXT_BIOS_INFO, NULL, 432 /*paramlen*/0, (u_char *)&extbios, sizeof(extbios), 433 DEFAULT_CMD_TIMEOUT); 434 error = aha_cmd(aha, AOP_MBOX_IF_ENABLE, (u_int8_t *)&extbios, 435 /*paramlen*/2, NULL, 0, DEFAULT_CMD_TIMEOUT); 436 } 437 if (aha->boardid < 0x41) 438 printf("%s: Warning: aha-1542A won't likely work.\n", 439 aha_name(aha)); 440 441 aha->max_sg = 17; /* Need >= 17 to do 64k I/O */ 442 aha->diff_bus = 0; 443 aha->extended_lun = 0; 444 aha->extended_trans = 0; 445 aha->max_ccbs = 16; 446 /* Determine Sync/Wide/Disc settings */ 447 length_param = sizeof(setup_info); 448 error = aha_cmd(aha, AOP_INQUIRE_SETUP_INFO, &length_param, 449 /*paramlen*/1, (u_int8_t*)&setup_info, 450 sizeof(setup_info), DEFAULT_CMD_TIMEOUT); 451 if (error != 0) { 452 printf("%s: aha_fetch_adapter_info - Failed " 453 "Get Setup Info\n", aha_name(aha)); 454 return (error); 455 } 456 if (setup_info.initiate_sync != 0) { 457 aha->sync_permitted = ALL_TARGETS; 458 } 459 aha->disc_permitted = ALL_TARGETS; 460 461 /* We need as many mailboxes as we can have ccbs */ 462 aha->num_boxes = aha->max_ccbs; 463 464 /* Determine our SCSI ID */ 465 466 error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0, 467 (u_int8_t*)&config_data, sizeof(config_data), 468 DEFAULT_CMD_TIMEOUT); 469 if (error != 0) { 470 printf("%s: aha_fetch_adapter_info - Failed Get Config\n", 471 aha_name(aha)); 472 return (error); 473 } 474 aha->scsi_id = config_data.scsi_id; 475 return (0); 476} 477 478/* 479 * Start the board, ready for normal operation 480 */ 481int 482aha_init(struct aha_softc* aha) 483{ 484 /* Announce the Adapter */ 485 printf("%s: AHA-%s FW Rev. %c.%c (ID=%x) ", aha_name(aha), 486 aha->model, aha->fw_major, aha->fw_minor, aha->boardid); 487 488 if (aha->diff_bus != 0) 489 printf("Diff "); 490 491 printf("SCSI Host Adapter, SCSI ID %d, %d CCBs\n", aha->scsi_id, 492 aha->max_ccbs); 493 494 /* 495 * Create our DMA tags. These tags define the kinds of device 496 * accessable memory allocations and memory mappings we will 497 * need to perform during normal operation. 498 * 499 * Unless we need to further restrict the allocation, we rely 500 * on the restrictions of the parent dmat, hence the common 501 * use of MAXADDR and MAXSIZE. 502 */ 503 504 /* DMA tag for mapping buffers into device visible space. */ 505 if (bus_dma_tag_create(aha->parent_dmat, /*alignment*/0, /*boundary*/0, 506 /*lowaddr*/BUS_SPACE_MAXADDR, 507 /*highaddr*/BUS_SPACE_MAXADDR, 508 /*filter*/NULL, /*filterarg*/NULL, 509 /*maxsize*/MAXBSIZE, /*nsegments*/AHA_NSEG, 510 /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT, 511 /*flags*/BUS_DMA_ALLOCNOW, 512 &aha->buffer_dmat) != 0) { 513 goto error_exit; 514 } 515 516 aha->init_level++; 517 /* DMA tag for our mailboxes */ 518 if (bus_dma_tag_create(aha->parent_dmat, /*alignment*/0, /*boundary*/0, 519 /*lowaddr*/BUS_SPACE_MAXADDR, 520 /*highaddr*/BUS_SPACE_MAXADDR, 521 /*filter*/NULL, /*filterarg*/NULL, 522 aha->num_boxes * (sizeof(aha_mbox_in_t) 523 + sizeof(aha_mbox_out_t)), 524 /*nsegments*/1, 525 /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT, 526 /*flags*/0, &aha->mailbox_dmat) != 0) { 527 goto error_exit; 528 } 529 530 aha->init_level++; 531 532 /* Allocation for our mailboxes */ 533 if (bus_dmamem_alloc(aha->mailbox_dmat, (void **)&aha->out_boxes, 534 BUS_DMA_NOWAIT, &aha->mailbox_dmamap) != 0) { 535 goto error_exit; 536 } 537 538 aha->init_level++; 539 540 /* And permanently map them */ 541 bus_dmamap_load(aha->mailbox_dmat, aha->mailbox_dmamap, 542 aha->out_boxes, 543 aha->num_boxes * (sizeof(aha_mbox_in_t) 544 + sizeof(aha_mbox_out_t)), 545 ahamapmboxes, aha, /*flags*/0); 546 547 aha->init_level++; 548 549 aha->in_boxes = (aha_mbox_in_t *)&aha->out_boxes[aha->num_boxes]; 550 551 ahainitmboxes(aha); 552 553 /* DMA tag for our ccb structures */ 554 if (bus_dma_tag_create(aha->parent_dmat, /*alignment*/0, /*boundary*/0, 555 /*lowaddr*/BUS_SPACE_MAXADDR, 556 /*highaddr*/BUS_SPACE_MAXADDR, 557 /*filter*/NULL, /*filterarg*/NULL, 558 aha->max_ccbs * sizeof(struct aha_ccb), 559 /*nsegments*/1, 560 /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT, 561 /*flags*/0, &aha->ccb_dmat) != 0) { 562 goto error_exit; 563 } 564 565 aha->init_level++; 566 567 /* Allocation for our ccbs */ 568 if (bus_dmamem_alloc(aha->ccb_dmat, (void **)&aha->aha_ccb_array, 569 BUS_DMA_NOWAIT, &aha->ccb_dmamap) != 0) { 570 goto error_exit; 571 } 572 573 aha->init_level++; 574 575 /* And permanently map them */ 576 bus_dmamap_load(aha->ccb_dmat, aha->ccb_dmamap, 577 aha->aha_ccb_array, 578 aha->max_ccbs * sizeof(struct aha_ccb), 579 ahamapccbs, aha, /*flags*/0); 580 581 aha->init_level++; 582 583 /* DMA tag for our S/G structures. We allocate in page sized chunks */ 584 if (bus_dma_tag_create(aha->parent_dmat, /*alignment*/0, /*boundary*/0, 585 /*lowaddr*/BUS_SPACE_MAXADDR, 586 /*highaddr*/BUS_SPACE_MAXADDR, 587 /*filter*/NULL, /*filterarg*/NULL, 588 PAGE_SIZE, /*nsegments*/1, 589 /*maxsegsz*/BUS_SPACE_MAXSIZE_24BIT, 590 /*flags*/0, &aha->sg_dmat) != 0) { 591 goto error_exit; 592 } 593 594 aha->init_level++; 595 596 /* Perform initial CCB allocation */ 597 bzero(aha->aha_ccb_array, aha->max_ccbs * sizeof(struct aha_ccb)); 598 ahaallocccbs(aha); 599 600 if (aha->num_ccbs == 0) { 601 printf("%s: aha_init - Unable to allocate initial ccbs\n", 602 aha_name(aha)); 603 goto error_exit; 604 } 605 606 /* 607 * Note that we are going and return (to probe) 608 */ 609 return 0; 610 611error_exit: 612 613 return (ENXIO); 614} 615 616int 617aha_attach(struct aha_softc *aha) 618{ 619 int tagged_dev_openings; 620 struct cam_devq *devq; 621 622 /* 623 * We don't do tagged queueing, since the aha cards don't 624 * support it. 625 */ 626 tagged_dev_openings = 0; 627 628 /* 629 * Create the device queue for our SIM. 630 */ 631 devq = cam_simq_alloc(aha->max_ccbs - 1); 632 if (devq == NULL) 633 return (ENOMEM); 634 635 /* 636 * Construct our SIM entry 637 */ 638 aha->sim = cam_sim_alloc(ahaaction, ahapoll, "aha", aha, aha->unit, 639 2, tagged_dev_openings, devq); 640 if (aha->sim == NULL) { 641 cam_simq_free(devq); 642 return (ENOMEM); 643 } 644 645 if (xpt_bus_register(aha->sim, 0) != CAM_SUCCESS) { 646 cam_sim_free(aha->sim, /*free_devq*/TRUE); 647 return (ENXIO); 648 } 649 650 if (xpt_create_path(&aha->path, /*periph*/NULL, 651 cam_sim_path(aha->sim), CAM_TARGET_WILDCARD, 652 CAM_LUN_WILDCARD) != CAM_REQ_CMP) { 653 xpt_bus_deregister(cam_sim_path(aha->sim)); 654 cam_sim_free(aha->sim, /*free_devq*/TRUE); 655 return (ENXIO); 656 } 657 658 return (0); 659} 660 661char * 662aha_name(struct aha_softc *aha) 663{ 664 static char name[10]; 665 666 snprintf(name, sizeof(name), "aha%d", aha->unit); 667 return (name); 668} 669 670int 671aha_check_probed_iop(u_int ioport) 672{ 673 u_int i; 674 675 for (i=0; i < AHA_NUM_ISAPORTS; i++) { 676 if (aha_isa_ports[i].addr == ioport) { 677 if (aha_isa_ports[i].probed != 0) 678 return (1); 679 else { 680 return (0); 681 } 682 } 683 } 684 return (1); 685} 686 687void 688aha_mark_probed_bio(isa_compat_io_t port) 689{ 690 if (port < BIO_DISABLED) 691 aha_mark_probed_iop(aha_board_ports[port]); 692} 693 694void 695aha_mark_probed_iop(u_int ioport) 696{ 697 u_int i; 698 699 for (i = 0; i < AHA_NUM_ISAPORTS; i++) { 700 if (ioport == aha_isa_ports[i].addr) { 701 aha_isa_ports[i].probed = 1; 702 break; 703 } 704 } 705} 706 707void 708aha_find_probe_range(int ioport, int *port_index, int *max_port_index) 709{ 710 if (ioport > 0) { 711 int i; 712 713 for (i = 0;i < AHA_NUM_ISAPORTS; i++) 714 if (ioport <= aha_isa_ports[i].addr) 715 break; 716 if ((i >= AHA_NUM_ISAPORTS) 717 || (ioport != aha_isa_ports[i].addr)) { 718 printf(" 719aha_isa_probe: Invalid baseport of 0x%x specified. 720aha_isa_probe: Nearest valid baseport is 0x%x. 721aha_isa_probe: Failing probe.\n", 722 ioport, 723 (i < AHA_NUM_ISAPORTS) 724 ? aha_isa_ports[i].addr 725 : aha_isa_ports[AHA_NUM_ISAPORTS - 1].addr); 726 *port_index = *max_port_index = -1; 727 return; 728 } 729 *port_index = *max_port_index = aha_isa_ports[i].bio; 730 } else { 731 *port_index = 0; 732 *max_port_index = AHA_NUM_ISAPORTS - 1; 733 } 734} 735 736int 737aha_iop_from_bio(isa_compat_io_t bio_index) 738{ 739 if (bio_index >= 0 && bio_index < AHA_NUM_ISAPORTS) 740 return (aha_board_ports[bio_index]); 741 return (-1); 742} 743 744static void 745ahaallocccbs(struct aha_softc *aha) 746{ 747 struct aha_ccb *next_ccb; 748 struct sg_map_node *sg_map; 749 bus_addr_t physaddr; 750 aha_sg_t *segs; 751 int newcount; 752 int i; 753 754 next_ccb = &aha->aha_ccb_array[aha->num_ccbs]; 755 756 sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT); 757 758 if (sg_map == NULL) 759 return; 760 761 /* Allocate S/G space for the next batch of CCBS */ 762 if (bus_dmamem_alloc(aha->sg_dmat, (void **)&sg_map->sg_vaddr, 763 BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) { 764 free(sg_map, M_DEVBUF); 765 return; 766 } 767 768 SLIST_INSERT_HEAD(&aha->sg_maps, sg_map, links); 769 770 bus_dmamap_load(aha->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr, 771 PAGE_SIZE, ahamapsgs, aha, /*flags*/0); 772 773 segs = sg_map->sg_vaddr; 774 physaddr = sg_map->sg_physaddr; 775 776 newcount = (PAGE_SIZE / (AHA_NSEG * sizeof(aha_sg_t))); 777 for (i = 0; aha->num_ccbs < aha->max_ccbs && i < newcount; i++) { 778 int error; 779 780 next_ccb->sg_list = segs; 781 next_ccb->sg_list_phys = physaddr; 782 next_ccb->flags = ACCB_FREE; 783 error = bus_dmamap_create(aha->buffer_dmat, /*flags*/0, 784 &next_ccb->dmamap); 785 if (error != 0) 786 break; 787 SLIST_INSERT_HEAD(&aha->free_aha_ccbs, next_ccb, links); 788 segs += AHA_NSEG; 789 physaddr += (AHA_NSEG * sizeof(aha_sg_t)); 790 next_ccb++; 791 aha->num_ccbs++; 792 } 793 794 /* Reserve a CCB for error recovery */ 795 if (aha->recovery_accb == NULL) { 796 aha->recovery_accb = SLIST_FIRST(&aha->free_aha_ccbs); 797 SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links); 798 } 799} 800 801static __inline void 802ahafreeccb(struct aha_softc *aha, struct aha_ccb *accb) 803{ 804 int s; 805 806 s = splcam(); 807 if ((accb->flags & ACCB_ACTIVE) != 0) 808 LIST_REMOVE(&accb->ccb->ccb_h, sim_links.le); 809 if (aha->resource_shortage != 0 810 && (accb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) { 811 accb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 812 aha->resource_shortage = FALSE; 813 } 814 accb->flags = ACCB_FREE; 815 SLIST_INSERT_HEAD(&aha->free_aha_ccbs, accb, links); 816 aha->active_ccbs--; 817 splx(s); 818} 819 820static struct aha_ccb* 821ahagetccb(struct aha_softc *aha) 822{ 823 struct aha_ccb* accb; 824 int s; 825 826 s = splcam(); 827 if ((accb = SLIST_FIRST(&aha->free_aha_ccbs)) != NULL) { 828 SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links); 829 aha->active_ccbs++; 830 } else if (aha->num_ccbs < aha->max_ccbs) { 831 ahaallocccbs(aha); 832 accb = SLIST_FIRST(&aha->free_aha_ccbs); 833 if (accb == NULL) 834 printf("%s: Can't malloc ACCB\n", aha_name(aha)); 835 else { 836 SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links); 837 aha->active_ccbs++; 838 } 839 } 840 splx(s); 841 842 return (accb); 843} 844 845static void 846ahaaction(struct cam_sim *sim, union ccb *ccb) 847{ 848 struct aha_softc *aha; 849 850 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("ahaaction\n")); 851 852 aha = (struct aha_softc *)cam_sim_softc(sim); 853 854 switch (ccb->ccb_h.func_code) { 855 /* Common cases first */ 856 case XPT_SCSI_IO: /* Execute the requested I/O operation */ 857 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */ 858 { 859 struct aha_ccb *accb; 860 struct aha_hccb *hccb; 861 862 /* 863 * get a accb to use. 864 */ 865 if ((accb = ahagetccb(aha)) == NULL) { 866 int s; 867 868 s = splcam(); 869 aha->resource_shortage = TRUE; 870 splx(s); 871 xpt_freeze_simq(aha->sim, /*count*/1); 872 ccb->ccb_h.status = CAM_REQUEUE_REQ; 873 xpt_done(ccb); 874 return; 875 } 876 877 hccb = &accb->hccb; 878 879 /* 880 * So we can find the ACCB when an abort is requested 881 */ 882 accb->ccb = ccb; 883 ccb->ccb_h.ccb_accb_ptr = accb; 884 ccb->ccb_h.ccb_aha_ptr = aha; 885 886 /* 887 * Put all the arguments for the xfer in the accb 888 */ 889 hccb->target = ccb->ccb_h.target_id; 890 hccb->lun = ccb->ccb_h.target_lun; 891 hccb->ahastat = 0; 892 hccb->sdstat = 0; 893 894 if (ccb->ccb_h.func_code == XPT_SCSI_IO) { 895 struct ccb_scsiio *csio; 896 struct ccb_hdr *ccbh; 897 898 csio = &ccb->csio; 899 ccbh = &csio->ccb_h; 900 hccb->opcode = INITIATOR_CCB_WRESID; 901 hccb->datain = (ccb->ccb_h.flags & CAM_DIR_IN) != 0; 902 hccb->dataout = (ccb->ccb_h.flags & CAM_DIR_OUT) != 0; 903 hccb->cmd_len = csio->cdb_len; 904 if (hccb->cmd_len > sizeof(hccb->scsi_cdb)) { 905 ccb->ccb_h.status = CAM_REQ_INVALID; 906 ahafreeccb(aha, accb); 907 xpt_done(ccb); 908 return; 909 } 910 hccb->sense_len = csio->sense_len; 911 if ((ccbh->flags & CAM_CDB_POINTER) != 0) { 912 if ((ccbh->flags & CAM_CDB_PHYS) == 0) { 913 bcopy(csio->cdb_io.cdb_ptr, 914 hccb->scsi_cdb, hccb->cmd_len); 915 } else { 916 /* I guess I could map it in... */ 917 ccbh->status = CAM_REQ_INVALID; 918 ahafreeccb(aha, accb); 919 xpt_done(ccb); 920 return; 921 } 922 } else { 923 bcopy(csio->cdb_io.cdb_bytes, 924 hccb->scsi_cdb, hccb->cmd_len); 925 } 926 /* 927 * If we have any data to send with this command, 928 * map it into bus space. 929 */ 930 /* Only use S/G if there is a transfer */ 931 if ((ccbh->flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 932 if ((ccbh->flags & CAM_SCATTER_VALID) == 0) { 933 /* 934 * We've been given a pointer 935 * to a single buffer. 936 */ 937 if ((ccbh->flags & CAM_DATA_PHYS)==0) { 938 int s; 939 int error; 940 941 s = splsoftvm(); 942 error = bus_dmamap_load( 943 aha->buffer_dmat, 944 accb->dmamap, 945 csio->data_ptr, 946 csio->dxfer_len, 947 ahaexecuteccb, 948 accb, 949 /*flags*/0); 950 if (error == EINPROGRESS) { 951 /* 952 * So as to maintain 953 * ordering, freeze the 954 * controller queue 955 * until our mapping is 956 * returned. 957 */ 958 xpt_freeze_simq(aha->sim, 959 1); 960 csio->ccb_h.status |= 961 CAM_RELEASE_SIMQ; 962 } 963 splx(s); 964 } else { 965 struct bus_dma_segment seg; 966 967 /* Pointer to physical buffer */ 968 seg.ds_addr = 969 (bus_addr_t)csio->data_ptr; 970 seg.ds_len = csio->dxfer_len; 971 ahaexecuteccb(accb, &seg, 1, 0); 972 } 973 } else { 974 struct bus_dma_segment *segs; 975 976 if ((ccbh->flags & CAM_DATA_PHYS) != 0) 977 panic("ahaaction - Physical " 978 "segment pointers " 979 "unsupported"); 980 981 if ((ccbh->flags&CAM_SG_LIST_PHYS)==0) 982 panic("ahaaction - Virtual " 983 "segment addresses " 984 "unsupported"); 985 986 /* Just use the segments provided */ 987 segs = (struct bus_dma_segment *) 988 csio->data_ptr; 989 ahaexecuteccb(accb, segs, 990 csio->sglist_cnt, 0); 991 } 992 } else { 993 ahaexecuteccb(accb, NULL, 0, 0); 994 } 995 } else { 996 hccb->opcode = INITIATOR_BUS_DEV_RESET; 997 /* No data transfer */ 998 hccb->datain = TRUE; 999 hccb->dataout = TRUE; 1000 hccb->cmd_len = 0; 1001 hccb->sense_len = 0; 1002 ahaexecuteccb(accb, NULL, 0, 0); 1003 } 1004 break; 1005 } 1006 case XPT_EN_LUN: /* Enable LUN as a target */ 1007 case XPT_TARGET_IO: /* Execute target I/O request */ 1008 case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */ 1009 case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/ 1010 case XPT_ABORT: /* Abort the specified CCB */ 1011 /* XXX Implement */ 1012 ccb->ccb_h.status = CAM_REQ_INVALID; 1013 xpt_done(ccb); 1014 break; 1015 case XPT_SET_TRAN_SETTINGS: 1016 { 1017 /* XXX Implement */ 1018 ccb->ccb_h.status = CAM_REQ_CMP; 1019 xpt_done(ccb); 1020 break; 1021 } 1022 case XPT_GET_TRAN_SETTINGS: 1023 /* Get default/user set transfer settings for the target */ 1024 { 1025 struct ccb_trans_settings *cts; 1026 u_int target_mask; 1027 1028 cts = &ccb->cts; 1029 target_mask = 0x01 << ccb->ccb_h.target_id; 1030 if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) { 1031 cts->flags = 0; 1032 if ((aha->disc_permitted & target_mask) != 0) 1033 cts->flags |= CCB_TRANS_DISC_ENB; 1034 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 1035 if ((aha->sync_permitted & target_mask) != 0) 1036 cts->sync_period = 50; 1037 else 1038 cts->sync_period = 0; 1039 1040 if (cts->sync_period != 0) 1041 cts->sync_offset = 15; 1042 1043 cts->valid = CCB_TRANS_SYNC_RATE_VALID 1044 | CCB_TRANS_SYNC_OFFSET_VALID 1045 | CCB_TRANS_BUS_WIDTH_VALID 1046 | CCB_TRANS_DISC_VALID 1047 | CCB_TRANS_TQ_VALID; 1048 } else { 1049 ahafetchtransinfo(aha, cts); 1050 } 1051 1052 ccb->ccb_h.status = CAM_REQ_CMP; 1053 xpt_done(ccb); 1054 break; 1055 } 1056 case XPT_CALC_GEOMETRY: 1057 { 1058 struct ccb_calc_geometry *ccg; 1059 u_int32_t size_mb; 1060 u_int32_t secs_per_cylinder; 1061 1062 ccg = &ccb->ccg; 1063 size_mb = ccg->volume_size 1064 / ((1024L * 1024L) / ccg->block_size); 1065 1066 if (size_mb >= 1024 && (aha->extended_trans != 0)) { 1067 if (size_mb >= 2048) { 1068 ccg->heads = 255; 1069 ccg->secs_per_track = 63; 1070 } else { 1071 ccg->heads = 128; 1072 ccg->secs_per_track = 32; 1073 } 1074 } else { 1075 ccg->heads = 64; 1076 ccg->secs_per_track = 32; 1077 } 1078 secs_per_cylinder = ccg->heads * ccg->secs_per_track; 1079 ccg->cylinders = ccg->volume_size / secs_per_cylinder; 1080 ccb->ccb_h.status = CAM_REQ_CMP; 1081 xpt_done(ccb); 1082 break; 1083 } 1084 case XPT_RESET_BUS: /* Reset the specified SCSI bus */ 1085 { 1086 ahareset(aha, /*hardreset*/TRUE); 1087 ccb->ccb_h.status = CAM_REQ_CMP; 1088 xpt_done(ccb); 1089 break; 1090 } 1091 case XPT_TERM_IO: /* Terminate the I/O process */ 1092 /* XXX Implement */ 1093 ccb->ccb_h.status = CAM_REQ_INVALID; 1094 xpt_done(ccb); 1095 break; 1096 case XPT_PATH_INQ: /* Path routing inquiry */ 1097 { 1098 struct ccb_pathinq *cpi = &ccb->cpi; 1099 1100 cpi->version_num = 1; /* XXX??? */ 1101 cpi->hba_inquiry = PI_SDTR_ABLE; 1102 cpi->target_sprt = 0; 1103 cpi->hba_misc = 0; 1104 cpi->hba_eng_cnt = 0; 1105 cpi->max_target = 7; 1106 cpi->max_lun = 7; 1107 cpi->initiator_id = aha->scsi_id; 1108 cpi->bus_id = cam_sim_bus(sim); 1109 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); 1110 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN); 1111 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); 1112 cpi->unit_number = cam_sim_unit(sim); 1113 cpi->ccb_h.status = CAM_REQ_CMP; 1114 xpt_done(ccb); 1115 break; 1116 } 1117 default: 1118 ccb->ccb_h.status = CAM_REQ_INVALID; 1119 xpt_done(ccb); 1120 break; 1121 } 1122} 1123 1124static void 1125ahaexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error) 1126{ 1127 struct aha_ccb *accb; 1128 union ccb *ccb; 1129 struct aha_softc *aha; 1130 int s; 1131 u_int32_t paddr; 1132 1133 accb = (struct aha_ccb *)arg; 1134 ccb = accb->ccb; 1135 aha = (struct aha_softc *)ccb->ccb_h.ccb_aha_ptr; 1136 1137 if (error != 0) { 1138 if (error != EFBIG) 1139 printf("%s: Unexepected error 0x%x returned from " 1140 "bus_dmamap_load\n", aha_name(aha), error); 1141 if (ccb->ccb_h.status == CAM_REQ_INPROG) { 1142 xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); 1143 ccb->ccb_h.status = CAM_REQ_TOO_BIG|CAM_DEV_QFRZN; 1144 } 1145 ahafreeccb(aha, accb); 1146 xpt_done(ccb); 1147 return; 1148 } 1149 1150 if (nseg != 0) { 1151 aha_sg_t *sg; 1152 bus_dma_segment_t *end_seg; 1153 bus_dmasync_op_t op; 1154 1155 end_seg = dm_segs + nseg; 1156 1157 /* Copy the segments into our SG list */ 1158 sg = accb->sg_list; 1159 while (dm_segs < end_seg) { 1160 ahautoa24(dm_segs->ds_len, sg->len); 1161 ahautoa24(dm_segs->ds_addr, sg->addr); 1162 sg++; 1163 dm_segs++; 1164 } 1165 1166 if (nseg > 1) { 1167 accb->hccb.opcode = INITIATOR_SG_CCB_WRESID; 1168 ahautoa24((sizeof(aha_sg_t) * nseg), 1169 accb->hccb.data_len); 1170 ahautoa24(accb->sg_list_phys, accb->hccb.data_addr); 1171 } else { 1172 bcopy(accb->sg_list->len, accb->hccb.data_len, 3); 1173 bcopy(accb->sg_list->addr, accb->hccb.data_addr, 3); 1174 } 1175 1176 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) 1177 op = BUS_DMASYNC_PREREAD; 1178 else 1179 op = BUS_DMASYNC_PREWRITE; 1180 1181 bus_dmamap_sync(aha->buffer_dmat, accb->dmamap, op); 1182 1183 } else { 1184 accb->hccb.opcode = INITIATOR_CCB_WRESID; 1185 ahautoa24(0, accb->hccb.data_len); 1186 ahautoa24(0, accb->hccb.data_addr); 1187 } 1188 1189 s = splcam(); 1190 1191 /* 1192 * Last time we need to check if this CCB needs to 1193 * be aborted. 1194 */ 1195 if (ccb->ccb_h.status != CAM_REQ_INPROG) { 1196 if (nseg != 0) 1197 bus_dmamap_unload(aha->buffer_dmat, accb->dmamap); 1198 ahafreeccb(aha, accb); 1199 xpt_done(ccb); 1200 splx(s); 1201 return; 1202 } 1203 1204 accb->flags = ACCB_ACTIVE; 1205 ccb->ccb_h.status |= CAM_SIM_QUEUED; 1206 LIST_INSERT_HEAD(&aha->pending_ccbs, &ccb->ccb_h, sim_links.le); 1207 1208 ccb->ccb_h.timeout_ch = 1209 timeout(ahatimeout, (caddr_t)accb, 1210 (ccb->ccb_h.timeout * hz) / 1000); 1211 1212 /* Tell the adapter about this command */ 1213 if (aha->cur_outbox->action_code != AMBO_FREE) { 1214 /* 1215 * We should never encounter a busy mailbox. 1216 * If we do, warn the user, and treat it as 1217 * a resource shortage. If the controller is 1218 * hung, one of the pending transactions will 1219 * timeout causing us to start recovery operations. 1220 */ 1221 printf("%s: Encountered busy mailbox with %d out of %d " 1222 "commands active!!!", aha_name(aha), aha->active_ccbs, 1223 aha->max_ccbs); 1224 untimeout(ahatimeout, accb, ccb->ccb_h.timeout_ch); 1225 if (nseg != 0) 1226 bus_dmamap_unload(aha->buffer_dmat, accb->dmamap); 1227 ahafreeccb(aha, accb); 1228 aha->resource_shortage = TRUE; 1229 xpt_freeze_simq(aha->sim, /*count*/1); 1230 ccb->ccb_h.status = CAM_REQUEUE_REQ; 1231 xpt_done(ccb); 1232 return; 1233 } 1234 paddr = ahaccbvtop(aha, accb); 1235 ahautoa24(paddr, aha->cur_outbox->ccb_addr); 1236 aha->cur_outbox->action_code = AMBO_START; 1237 aha_outb(aha, COMMAND_REG, AOP_START_MBOX); 1238 1239 ahanextoutbox(aha); 1240 splx(s); 1241} 1242 1243void 1244aha_intr(void *arg) 1245{ 1246 struct aha_softc *aha; 1247 u_int intstat; 1248 1249 aha = (struct aha_softc *)arg; 1250 while (((intstat = aha_inb(aha, INTSTAT_REG)) & INTR_PENDING) != 0) { 1251 if ((intstat & CMD_COMPLETE) != 0) { 1252 aha->latched_status = aha_inb(aha, STATUS_REG); 1253 aha->command_cmp = TRUE; 1254 } 1255 1256 aha_outb(aha, CONTROL_REG, RESET_INTR); 1257 1258 if ((intstat & IMB_LOADED) != 0) { 1259 while (aha->cur_inbox->comp_code != AMBI_FREE) { 1260 u_int32_t paddr; 1261 paddr = aha_a24tou(aha->cur_inbox->ccb_addr); 1262 ahadone(aha, 1263 ahaccbptov(aha, paddr), 1264 aha->cur_inbox->comp_code); 1265 aha->cur_inbox->comp_code = AMBI_FREE; 1266 ahanextinbox(aha); 1267 } 1268 } 1269 1270 if ((intstat & SCSI_BUS_RESET) != 0) { 1271 ahareset(aha, /*hardreset*/FALSE); 1272 } 1273 } 1274} 1275 1276static void 1277ahadone(struct aha_softc *aha, struct aha_ccb *accb, aha_mbi_comp_code_t comp_code) 1278{ 1279 union ccb *ccb; 1280 struct ccb_scsiio *csio; 1281 1282 ccb = accb->ccb; 1283 csio = &accb->ccb->csio; 1284 1285 if ((accb->flags & ACCB_ACTIVE) == 0) { 1286 printf("%s: ahadone - Attempt to free non-active ACCB %p\n", 1287 aha_name(aha), (void *)accb); 1288 return; 1289 } 1290 1291 if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) { 1292 bus_dmasync_op_t op; 1293 1294 if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) 1295 op = BUS_DMASYNC_POSTREAD; 1296 else 1297 op = BUS_DMASYNC_POSTWRITE; 1298 bus_dmamap_sync(aha->buffer_dmat, accb->dmamap, op); 1299 bus_dmamap_unload(aha->buffer_dmat, accb->dmamap); 1300 } 1301 1302 if (accb == aha->recovery_accb) { 1303 /* 1304 * The recovery ACCB does not have a CCB associated 1305 * with it, so short circuit the normal error handling. 1306 * We now traverse our list of pending CCBs and process 1307 * any that were terminated by the recovery CCBs action. 1308 * We also reinstate timeouts for all remaining, pending, 1309 * CCBs. 1310 */ 1311 struct cam_path *path; 1312 struct ccb_hdr *ccb_h; 1313 cam_status error; 1314 1315 /* Notify all clients that a BDR occured */ 1316 error = xpt_create_path(&path, /*periph*/NULL, 1317 cam_sim_path(aha->sim), 1318 accb->hccb.target, 1319 CAM_LUN_WILDCARD); 1320 1321 if (error == CAM_REQ_CMP) 1322 xpt_async(AC_SENT_BDR, path, NULL); 1323 1324 ccb_h = LIST_FIRST(&aha->pending_ccbs); 1325 while (ccb_h != NULL) { 1326 struct aha_ccb *pending_accb; 1327 1328 pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr; 1329 if (pending_accb->hccb.target == accb->hccb.target) { 1330 pending_accb->hccb.ahastat = AHASTAT_HA_BDR; 1331 ccb_h = LIST_NEXT(ccb_h, sim_links.le); 1332 ahadone(aha, pending_accb, AMBI_ERROR); 1333 } else { 1334 ccb_h->timeout_ch = 1335 timeout(ahatimeout, (caddr_t)pending_accb, 1336 (ccb_h->timeout * hz) / 1000); 1337 ccb_h = LIST_NEXT(ccb_h, sim_links.le); 1338 } 1339 } 1340 printf("%s: No longer in timeout\n", aha_name(aha)); 1341 return; 1342 } 1343 1344 untimeout(ahatimeout, accb, ccb->ccb_h.timeout_ch); 1345 1346 switch (comp_code) { 1347 case AMBI_FREE: 1348 printf("%s: ahadone - CCB completed with free status!\n", 1349 aha_name(aha)); 1350 break; 1351 case AMBI_NOT_FOUND: 1352 printf("%s: ahadone - CCB Abort failed to find CCB\n", 1353 aha_name(aha)); 1354 break; 1355 case AMBI_ABORT: 1356 case AMBI_ERROR: 1357 /* An error occured */ 1358 switch(accb->hccb.ahastat) { 1359 case AHASTAT_DATARUN_ERROR: 1360 if (accb->hccb.data_len <= 0) { 1361 csio->ccb_h.status = CAM_DATA_RUN_ERR; 1362 break; 1363 } 1364 /* FALLTHROUGH */ 1365 case AHASTAT_NOERROR: 1366 csio->scsi_status = accb->hccb.sdstat; 1367 csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR; 1368 switch(csio->scsi_status) { 1369 case SCSI_STATUS_CHECK_COND: 1370 case SCSI_STATUS_CMD_TERMINATED: 1371 csio->ccb_h.status |= CAM_AUTOSNS_VALID; 1372 /* 1373 * The aha writes the sense data at different 1374 * offsets based on the scsi cmd len 1375 */ 1376 bcopy((caddr_t) &accb->hccb.scsi_cdb + 1377 accb->hccb.cmd_len, 1378 (caddr_t) &csio->sense_data, 1379 accb->hccb.sense_len); 1380 break; 1381 default: 1382 break; 1383 case SCSI_STATUS_OK: 1384 csio->ccb_h.status = CAM_REQ_CMP; 1385 break; 1386 } 1387 csio->resid = aha_a24tou(accb->hccb.data_len); 1388 break; 1389 case AHASTAT_SELTIMEOUT: 1390 csio->ccb_h.status = CAM_SEL_TIMEOUT; 1391 break; 1392 case AHASTAT_UNEXPECTED_BUSFREE: 1393 csio->ccb_h.status = CAM_UNEXP_BUSFREE; 1394 break; 1395 case AHASTAT_INVALID_PHASE: 1396 csio->ccb_h.status = CAM_SEQUENCE_FAIL; 1397 break; 1398 case AHASTAT_INVALID_ACTION_CODE: 1399 panic("%s: Inavlid Action code", aha_name(aha)); 1400 break; 1401 case AHASTAT_INVALID_OPCODE: 1402 panic("%s: Inavlid CCB Opcode code %x hccb = %p", 1403 aha_name(aha), accb->hccb.opcode, &accb->hccb); 1404 break; 1405 case AHASTAT_LINKED_CCB_LUN_MISMATCH: 1406 /* We don't even support linked commands... */ 1407 panic("%s: Linked CCB Lun Mismatch", aha_name(aha)); 1408 break; 1409 case AHASTAT_INVALID_CCB_OR_SG_PARAM: 1410 panic("%s: Invalid CCB or SG list", aha_name(aha)); 1411 break; 1412 case AHASTAT_HA_SCSI_BUS_RESET: 1413 if ((csio->ccb_h.status & CAM_STATUS_MASK) 1414 != CAM_CMD_TIMEOUT) 1415 csio->ccb_h.status = CAM_SCSI_BUS_RESET; 1416 break; 1417 case AHASTAT_HA_BDR: 1418 if ((accb->flags & ACCB_DEVICE_RESET) == 0) 1419 csio->ccb_h.status = CAM_BDR_SENT; 1420 else 1421 csio->ccb_h.status = CAM_CMD_TIMEOUT; 1422 break; 1423 } 1424 if (csio->ccb_h.status != CAM_REQ_CMP) { 1425 xpt_freeze_devq(csio->ccb_h.path, /*count*/1); 1426 csio->ccb_h.status |= CAM_DEV_QFRZN; 1427 } 1428 if ((accb->flags & ACCB_RELEASE_SIMQ) != 0) 1429 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 1430 ahafreeccb(aha, accb); 1431 xpt_done(ccb); 1432 break; 1433 case AMBI_OK: 1434 /* All completed without incident */ 1435 /* XXX DO WE NEED TO COPY SENSE BYTES HERE???? XXX */ 1436 ccb->ccb_h.status |= CAM_REQ_CMP; 1437 if ((accb->flags & ACCB_RELEASE_SIMQ) != 0) 1438 ccb->ccb_h.status |= CAM_RELEASE_SIMQ; 1439 ahafreeccb(aha, accb); 1440 xpt_done(ccb); 1441 break; 1442 } 1443} 1444 1445static int 1446ahareset(struct aha_softc* aha, int hard_reset) 1447{ 1448 struct ccb_hdr *ccb_h; 1449 u_int status; 1450 u_int timeout; 1451 u_int8_t reset_type; 1452 1453 if (hard_reset != 0) 1454 reset_type = HARD_RESET; 1455 else 1456 reset_type = SOFT_RESET; 1457 aha_outb(aha, CONTROL_REG, reset_type); 1458 1459 /* Wait 5sec. for Diagnostic start */ 1460 timeout = 5 * 10000; 1461 while (--timeout) { 1462 status = aha_inb(aha, STATUS_REG); 1463 if ((status & DIAG_ACTIVE) != 0) 1464 break; 1465 DELAY(100); 1466 } 1467 if (timeout == 0) { 1468 PRVERB(("%s: ahareset - Diagnostic Active failed to " 1469 "assert. status = 0x%x\n", aha_name(aha), 1470 status)); 1471 return (ETIMEDOUT); 1472 } 1473 1474 /* Wait 10sec. for Diagnostic end */ 1475 timeout = 10 * 10000; 1476 while (--timeout) { 1477 status = aha_inb(aha, STATUS_REG); 1478 if ((status & DIAG_ACTIVE) == 0) 1479 break; 1480 DELAY(100); 1481 } 1482 if (timeout == 0) { 1483 panic("%s: ahareset - Diagnostic Active failed to drop. " 1484 "status = 0x%x\n", aha_name(aha), status); 1485 return (ETIMEDOUT); 1486 } 1487 1488 /* Wait for the host adapter to become ready or report a failure */ 1489 timeout = 10000; 1490 while (--timeout) { 1491 status = aha_inb(aha, STATUS_REG); 1492 if ((status & (DIAG_FAIL|HA_READY|DATAIN_REG_READY)) != 0) 1493 break; 1494 DELAY(100); 1495 } 1496 if (timeout == 0) { 1497 printf("%s: ahareset - Host adapter failed to come ready. " 1498 "status = 0x%x\n", aha_name(aha), status); 1499 return (ETIMEDOUT); 1500 } 1501 1502 /* If the diagnostics failed, tell the user */ 1503 if ((status & DIAG_FAIL) != 0 1504 || (status & HA_READY) == 0) { 1505 printf("%s: ahareset - Adapter failed diagnostics\n", 1506 aha_name(aha)); 1507 1508 if ((status & DATAIN_REG_READY) != 0) 1509 printf("%s: ahareset - Host Adapter Error " 1510 "code = 0x%x\n", aha_name(aha), 1511 aha_inb(aha, DATAIN_REG)); 1512 return (ENXIO); 1513 } 1514 1515 /* If we've allocated mailboxes, initialize them */ 1516 if (aha->init_level > 4) 1517 ahainitmboxes(aha); 1518 1519 /* If we've attached to the XPT, tell it about the event */ 1520 if (aha->path != NULL) 1521 xpt_async(AC_BUS_RESET, aha->path, NULL); 1522 1523 /* 1524 * Perform completion processing for all outstanding CCBs. 1525 */ 1526 while ((ccb_h = LIST_FIRST(&aha->pending_ccbs)) != NULL) { 1527 struct aha_ccb *pending_accb; 1528 1529 pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr; 1530 pending_accb->hccb.ahastat = AHASTAT_HA_SCSI_BUS_RESET; 1531 ahadone(aha, pending_accb, AMBI_ERROR); 1532 } 1533 1534 return (0); 1535} 1536 1537/* 1538 * Send a command to the adapter. 1539 */ 1540int 1541aha_cmd(struct aha_softc *aha, aha_op_t opcode, u_int8_t *params, 1542 u_int param_len, u_int8_t *reply_data, u_int reply_len, 1543 u_int cmd_timeout) 1544{ 1545 u_int timeout; 1546 u_int status; 1547 u_int intstat; 1548 u_int reply_buf_size; 1549 int s; 1550 1551 /* No data returned to start */ 1552 reply_buf_size = reply_len; 1553 reply_len = 0; 1554 intstat = 0; 1555 1556 aha->command_cmp = 0; 1557 /* 1558 * Wait up to 1 sec. for the adapter to become 1559 * ready to accept commands. 1560 */ 1561 timeout = 10000; 1562 while (--timeout) { 1563 1564 status = aha_inb(aha, STATUS_REG); 1565 if ((status & HA_READY) != 0 1566 && (status & CMD_REG_BUSY) == 0) 1567 break; 1568 DELAY(100); 1569 } 1570 if (timeout == 0) { 1571 printf("%s: aha_cmd: Timeout waiting for adapter ready, " 1572 "status = 0x%x\n", aha_name(aha), status); 1573 return (ETIMEDOUT); 1574 } 1575 1576 /* 1577 * Send the opcode followed by any necessary parameter bytes. 1578 */ 1579 aha_outb(aha, COMMAND_REG, opcode); 1580 1581 /* 1582 * Wait for up to 1sec to get the parameter list sent 1583 */ 1584 timeout = 10000; 1585 while (param_len && --timeout) { 1586 DELAY(100); 1587 status = aha_inb(aha, STATUS_REG); 1588 intstat = aha_inb(aha, INTSTAT_REG); 1589 if ((intstat & (INTR_PENDING|CMD_COMPLETE)) 1590 == (INTR_PENDING|CMD_COMPLETE)) 1591 break; 1592 if (aha->command_cmp != 0) { 1593 status = aha->latched_status; 1594 break; 1595 } 1596 if ((status & DATAIN_REG_READY) != 0) 1597 break; 1598 if ((status & CMD_REG_BUSY) == 0) { 1599 aha_outb(aha, COMMAND_REG, *params++); 1600 param_len--; 1601 } 1602 } 1603 if (timeout == 0) { 1604 printf("%s: aha_cmd: Timeout sending parameters, " 1605 "status = 0x%x\n", aha_name(aha), status); 1606 return (ETIMEDOUT); 1607 } 1608 1609 /* 1610 * For all other commands, we wait for any output data 1611 * and the final comand completion interrupt. 1612 */ 1613 while (--cmd_timeout) { 1614 1615 status = aha_inb(aha, STATUS_REG); 1616 intstat = aha_inb(aha, INTSTAT_REG); 1617 if ((intstat & (INTR_PENDING|CMD_COMPLETE)) 1618 == (INTR_PENDING|CMD_COMPLETE)) 1619 break; 1620 1621 if (aha->command_cmp != 0) { 1622 status = aha->latched_status; 1623 break; 1624 } 1625 1626 if ((status & DATAIN_REG_READY) != 0) { 1627 u_int8_t data; 1628 1629 data = aha_inb(aha, DATAIN_REG); 1630 if (reply_len < reply_buf_size) { 1631 *reply_data++ = data; 1632 } else { 1633 printf("%s: aha_cmd - Discarded reply data byte " 1634 "for opcode 0x%x\n", aha_name(aha), 1635 opcode); 1636 } 1637 reply_len++; 1638 } 1639 1640 DELAY(100); 1641 } 1642 if (timeout == 0) { 1643 printf("%s: aha_cmd: Timeout waiting for reply data and " 1644 "command complete.\n%s: status = 0x%x, intstat = 0x%x, " 1645 "reply_len = %d\n", aha_name(aha), aha_name(aha), status, 1646 intstat, reply_len); 1647 return (ETIMEDOUT); 1648 } 1649 1650 /* 1651 * Clear any pending interrupts. Block interrupts so our 1652 * interrupt handler is not re-entered. 1653 */ 1654 s = splcam(); 1655 aha_intr(aha); 1656 splx(s); 1657 1658 /* 1659 * If the command was rejected by the controller, tell the caller. 1660 */ 1661 if ((status & CMD_INVALID) != 0) { 1662 PRVERB(("%s: Invalid Command 0x%x\n", aha_name(aha), opcode)); 1663 /* 1664 * Some early adapters may not recover properly from 1665 * an invalid command. If it appears that the controller 1666 * has wedged (i.e. status was not cleared by our interrupt 1667 * reset above), perform a soft reset. 1668 */ 1669 DELAY(1000); 1670 status = aha_inb(aha, STATUS_REG); 1671 if ((status & (CMD_INVALID|STATUS_REG_RSVD|DATAIN_REG_READY| 1672 CMD_REG_BUSY|DIAG_FAIL|DIAG_ACTIVE)) != 0 1673 || (status & (HA_READY|INIT_REQUIRED)) 1674 != (HA_READY|INIT_REQUIRED)) { 1675 ahareset(aha, /*hard_reset*/FALSE); 1676 } 1677 return (EINVAL); 1678 } 1679 1680 1681 if (param_len > 0) { 1682 /* The controller did not accept the full argument list */ 1683 return (E2BIG); 1684 } 1685 1686 if (reply_len != reply_buf_size) { 1687 /* Too much or too little data received */ 1688 return (EMSGSIZE); 1689 } 1690 1691 /* We were successful */ 1692 return (0); 1693} 1694 1695static int 1696ahainitmboxes(struct aha_softc *aha) 1697{ 1698 int error; 1699 init_24b_mbox_params_t init_mbox; 1700 1701 bzero(aha->in_boxes, sizeof(aha_mbox_in_t) * aha->num_boxes); 1702 bzero(aha->out_boxes, sizeof(aha_mbox_out_t) * aha->num_boxes); 1703 aha->cur_inbox = aha->in_boxes; 1704 aha->last_inbox = aha->in_boxes + aha->num_boxes - 1; 1705 aha->cur_outbox = aha->out_boxes; 1706 aha->last_outbox = aha->out_boxes + aha->num_boxes - 1; 1707 1708 /* Tell the adapter about them */ 1709 init_mbox.num_mboxes = aha->num_boxes; 1710 ahautoa24(aha->mailbox_physbase, init_mbox.base_addr); 1711 error = aha_cmd(aha, AOP_INITIALIZE_MBOX, (u_int8_t *)&init_mbox, 1712 /*parmlen*/sizeof(init_mbox), /*reply_buf*/NULL, 1713 /*reply_len*/0, DEFAULT_CMD_TIMEOUT); 1714 1715 if (error != 0) 1716 printf("ahainitmboxes: Initialization command failed\n"); 1717 return (error); 1718} 1719 1720/* 1721 * Update the XPT's idea of the negotiated transfer 1722 * parameters for a particular target. 1723 */ 1724static void 1725ahafetchtransinfo(struct aha_softc *aha, struct ccb_trans_settings* cts) 1726{ 1727 setup_data_t setup_info; 1728 u_int target; 1729 u_int targ_offset; 1730 u_int sync_period; 1731 int error; 1732 u_int8_t param; 1733 targ_syncinfo_t sync_info; 1734 1735 target = cts->ccb_h.target_id; 1736 targ_offset = (target & 0x7); 1737 1738 /* 1739 * Inquire Setup Information. This command retreives the 1740 * Wide negotiation status for recent adapters as well as 1741 * the sync info for older models. 1742 */ 1743 param = sizeof(setup_info); 1744 error = aha_cmd(aha, AOP_INQUIRE_SETUP_INFO, ¶m, /*paramlen*/1, 1745 (u_int8_t*)&setup_info, sizeof(setup_info), 1746 DEFAULT_CMD_TIMEOUT); 1747 1748 if (error != 0) { 1749 printf("%s: ahafetchtransinfo - Inquire Setup Info Failed\n", 1750 aha_name(aha)); 1751 return; 1752 } 1753 1754 sync_info = setup_info.syncinfo[targ_offset]; 1755 1756 if (sync_info.sync == 0) 1757 cts->sync_offset = 0; 1758 else 1759 cts->sync_offset = sync_info.offset; 1760 1761 cts->bus_width = MSG_EXT_WDTR_BUS_8_BIT; 1762 1763 sync_period = 2000 + (500 * sync_info.period); 1764 1765 /* Convert ns value to standard SCSI sync rate */ 1766 if (cts->sync_offset != 0) 1767 cts->sync_period = scsi_calc_syncparam(sync_period); 1768 else 1769 cts->sync_period = 0; 1770 1771 cts->valid = CCB_TRANS_SYNC_RATE_VALID 1772 | CCB_TRANS_SYNC_OFFSET_VALID 1773 | CCB_TRANS_BUS_WIDTH_VALID; 1774 xpt_async(AC_TRANSFER_NEG, cts->ccb_h.path, cts); 1775} 1776 1777static void 1778ahamapmboxes(void *arg, bus_dma_segment_t *segs, int nseg, int error) 1779{ 1780 struct aha_softc* aha; 1781 1782 aha = (struct aha_softc*)arg; 1783 aha->mailbox_physbase = segs->ds_addr; 1784} 1785 1786static void 1787ahamapccbs(void *arg, bus_dma_segment_t *segs, int nseg, int error) 1788{ 1789 struct aha_softc* aha; 1790 1791 aha = (struct aha_softc*)arg; 1792 aha->aha_ccb_physbase = segs->ds_addr; 1793} 1794 1795static void 1796ahamapsgs(void *arg, bus_dma_segment_t *segs, int nseg, int error) 1797{ 1798 1799 struct aha_softc* aha; 1800 1801 aha = (struct aha_softc*)arg; 1802 SLIST_FIRST(&aha->sg_maps)->sg_physaddr = segs->ds_addr; 1803} 1804 1805static void 1806ahapoll(struct cam_sim *sim) 1807{ 1808 aha_intr(cam_sim_softc(sim)); 1809} 1810 1811void 1812ahatimeout(void *arg) 1813{ 1814 struct aha_ccb *accb; 1815 union ccb *ccb; 1816 struct aha_softc *aha; 1817 int s; 1818 u_int32_t paddr; 1819 1820 accb = (struct aha_ccb *)arg; 1821 ccb = accb->ccb; 1822 aha = (struct aha_softc *)ccb->ccb_h.ccb_aha_ptr; 1823 xpt_print_path(ccb->ccb_h.path); 1824 printf("CCB %p - timed out\n", (void *)accb); 1825 1826 s = splcam(); 1827 1828 if ((accb->flags & ACCB_ACTIVE) == 0) { 1829 xpt_print_path(ccb->ccb_h.path); 1830 printf("CCB %p - timed out CCB already completed\n", 1831 (void *)accb); 1832 splx(s); 1833 return; 1834 } 1835 1836 /* 1837 * In order to simplify the recovery process, we ask the XPT 1838 * layer to halt the queue of new transactions and we traverse 1839 * the list of pending CCBs and remove their timeouts. This 1840 * means that the driver attempts to clear only one error 1841 * condition at a time. In general, timeouts that occur 1842 * close together are related anyway, so there is no benefit 1843 * in attempting to handle errors in parrallel. Timeouts will 1844 * be reinstated when the recovery process ends. 1845 */ 1846 if ((accb->flags & ACCB_DEVICE_RESET) == 0) { 1847 struct ccb_hdr *ccb_h; 1848 1849 if ((accb->flags & ACCB_RELEASE_SIMQ) == 0) { 1850 xpt_freeze_simq(aha->sim, /*count*/1); 1851 accb->flags |= ACCB_RELEASE_SIMQ; 1852 } 1853 1854 ccb_h = LIST_FIRST(&aha->pending_ccbs); 1855 while (ccb_h != NULL) { 1856 struct aha_ccb *pending_accb; 1857 1858 pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr; 1859 untimeout(ahatimeout, pending_accb, ccb_h->timeout_ch); 1860 ccb_h = LIST_NEXT(ccb_h, sim_links.le); 1861 } 1862 } 1863 1864 if ((accb->flags & ACCB_DEVICE_RESET) != 0 1865 || aha->cur_outbox->action_code != AMBO_FREE) { 1866 /* 1867 * Try a full host adapter/SCSI bus reset. 1868 * We do this only if we have already attempted 1869 * to clear the condition with a BDR, or we cannot 1870 * attempt a BDR for lack of mailbox resources. 1871 */ 1872 ccb->ccb_h.status = CAM_CMD_TIMEOUT; 1873 ahareset(aha, /*hardreset*/TRUE); 1874 printf("%s: No longer in timeout\n", aha_name(aha)); 1875 } else { 1876 /* 1877 * Send a Bus Device Reset message: 1878 * The target that is holding up the bus may not 1879 * be the same as the one that triggered this timeout 1880 * (different commands have different timeout lengths), 1881 * but we have no way of determining this from our 1882 * timeout handler. Our strategy here is to queue a 1883 * BDR message to the target of the timed out command. 1884 * If this fails, we'll get another timeout 2 seconds 1885 * later which will attempt a bus reset. 1886 */ 1887 accb->flags |= ACCB_DEVICE_RESET; 1888 ccb->ccb_h.timeout_ch = timeout(ahatimeout, (caddr_t)accb, 2 * hz); 1889 aha->recovery_accb->hccb.opcode = INITIATOR_BUS_DEV_RESET; 1890 1891 /* No Data Transfer */ 1892 aha->recovery_accb->hccb.datain = TRUE; 1893 aha->recovery_accb->hccb.dataout = TRUE; 1894 aha->recovery_accb->hccb.ahastat = 0; 1895 aha->recovery_accb->hccb.sdstat = 0; 1896 aha->recovery_accb->hccb.target = ccb->ccb_h.target_id; 1897 1898 /* Tell the adapter about this command */ 1899 paddr = ahaccbvtop(aha, aha->recovery_accb); 1900 ahautoa24(paddr, aha->cur_outbox->ccb_addr); 1901 aha->cur_outbox->action_code = AMBO_START; 1902 aha_outb(aha, COMMAND_REG, AOP_START_MBOX); 1903 ahanextoutbox(aha); 1904 } 1905 1906 splx(s); 1907} 1908