--- src/sys/dev/disk/aha/aha.c 2005/06/20 02:56:09 1.10 +++ src/sys/dev/disk/aha/aha.c 2005/09/11 13:03:16 1.11 @@ -60,6 +60,7 @@ */ #include +#include #include #include #include @@ -85,7 +86,7 @@ struct aha_softc *aha_softcs[NAHATOT]; -#define PRVERB(x) if (bootverbose) printf x +#define PRVERB(x) do { if (bootverbose) device_printf x; } while(0) /* Macro to determine that a rev is potentially a new valid one * so that the driver doesn't keep breaking on new revs as it @@ -97,6 +98,8 @@ struct aha_softc *aha_softcs[NAHATOT]; static __inline void ahanextinbox(struct aha_softc *aha); static __inline void ahanextoutbox(struct aha_softc *aha); +#define aha_name(aha) device_get_nameunit(aha->dev) + static __inline void ahanextinbox(struct aha_softc *aha) { @@ -204,13 +207,14 @@ static u_int16_t aha_board_ports[] = /* Exported functions */ struct aha_softc * -aha_alloc(int unit, bus_space_tag_t tag, bus_space_handle_t bsh) +aha_alloc(device_t dev, bus_space_tag_t tag, bus_space_handle_t bsh) { - struct aha_softc *aha; + struct aha_softc *aha; + int unit = device_get_unit(dev); if (unit != AHA_TEMP_UNIT) { if (unit >= NAHATOT) { - printf("aha: unit number (%d) too high\n", unit); + device_printf(dev, "unit number (%d) too high\n", unit); return NULL; } @@ -218,7 +222,7 @@ aha_alloc(int unit, bus_space_tag_t tag, * Allocate a storage area for us */ if (aha_softcs[unit]) { - printf("aha%d: memory already allocated\n", unit); + device_printf(dev, "memory already allocated\n"); return NULL; } } @@ -227,13 +231,13 @@ aha_alloc(int unit, bus_space_tag_t tag, SLIST_INIT(&aha->free_aha_ccbs); LIST_INIT(&aha->pending_ccbs); SLIST_INIT(&aha->sg_maps); - aha->unit = unit; + aha->dev = dev; aha->tag = tag; aha->bsh = bsh; aha->ccb_sg_opcode = INITIATOR_SG_CCB_WRESID; aha->ccb_ccb_opcode = INITIATOR_CCB_WRESID; - if (aha->unit != AHA_TEMP_UNIT) { + if (unit != AHA_TEMP_UNIT) { aha_softcs[unit] = aha; } return (aha); @@ -242,6 +246,8 @@ aha_alloc(int unit, bus_space_tag_t tag, void aha_free(struct aha_softc *aha) { + int unit = device_get_unit(aha->dev); + switch (aha->init_level) { default: case 8: @@ -287,8 +293,8 @@ aha_free(struct aha_softc *aha) case 0: break; } - if (aha->unit != AHA_TEMP_UNIT) { - aha_softcs[aha->unit] = NULL; + if (unit != AHA_TEMP_UNIT) { + aha_softcs[unit] = NULL; } free(aha, M_DEVBUF); } @@ -313,14 +319,13 @@ aha_probe(struct aha_softc* aha) if ((status == 0) || (status & (DIAG_ACTIVE|CMD_REG_BUSY| STATUS_REG_RSVD)) != 0) { - PRVERB(("%s: status reg test failed %x\n", aha_name(aha), - status)); + PRVERB((aha->dev, "status reg test failed %x\n", status)); return (ENXIO); } intstat = aha_inb(aha, INTSTAT_REG); if ((intstat & INTSTAT_REG_RSVD) != 0) { - PRVERB(("%s: Failed Intstat Reg Test\n", aha_name(aha))); + PRVERB((aha->dev, "Failed Intstat Reg Test\n")); return (ENXIO); } @@ -330,7 +335,7 @@ aha_probe(struct aha_softc* aha) * looking at a BusLogic. */ if ((error = ahareset(aha, /*hard_reset*/TRUE)) != 0) { - PRVERB(("%s: Failed Reset\n", aha_name(aha))); + PRVERB((aha->dev, "Failed Reset\n")); return (ENXIO); } @@ -342,7 +347,7 @@ aha_probe(struct aha_softc* aha) (u_int8_t*)&board_id, sizeof(board_id), DEFAULT_CMD_TIMEOUT); if (error != 0) { - PRVERB(("%s: INQUIRE failed %x\n", aha_name(aha), error)); + PRVERB((aha->dev, "INQUIRE failed %x\n", error)); return (ENXIO); } aha->fw_major = board_id.firmware_rev_major; @@ -378,8 +383,7 @@ aha_probe(struct aha_softc* aha) DELAY(10000); status = aha_inb(aha, GEOMETRY_REG); if (status != 0xff && status != 0x00 && status != 0x7f) { - PRVERB(("%s: Geometry Register test failed 0x%x\n", - aha_name(aha), status)); + PRVERB((aha->dev, "Geometry Register test failed 0x%x\n", status)); return (ENXIO); } } @@ -448,8 +452,7 @@ aha_fetch_adapter_info(struct aha_softc /*paramlen*/2, NULL, 0, DEFAULT_CMD_TIMEOUT); } if (aha->boardid < 0x41) - printf("%s: Warning: aha-1542A won't likely work.\n", - aha_name(aha)); + device_printf(aha->dev, "Warning: aha-1542A won't likely work.\n"); aha->max_sg = 17; /* Need >= 17 to do 64k I/O */ aha->diff_bus = 0; @@ -462,8 +465,8 @@ aha_fetch_adapter_info(struct aha_softc /*paramlen*/1, (u_int8_t*)&setup_info, sizeof(setup_info), DEFAULT_CMD_TIMEOUT); if (error != 0) { - printf("%s: aha_fetch_adapter_info - Failed " - "Get Setup Info\n", aha_name(aha)); + device_printf(aha->dev, "aha_fetch_adapter_info - Failed " + "Get Setup Info\n"); return (error); } if (setup_info.initiate_sync != 0) { @@ -480,8 +483,7 @@ aha_fetch_adapter_info(struct aha_softc (u_int8_t*)&config_data, sizeof(config_data), DEFAULT_CMD_TIMEOUT); if (error != 0) { - printf("%s: aha_fetch_adapter_info - Failed Get Config\n", - aha_name(aha)); + device_printf(aha->dev, "aha_fetch_adapter_info - Failed Get Config\n"); return (error); } aha->scsi_id = config_data.scsi_id; @@ -495,12 +497,11 @@ int aha_init(struct aha_softc* aha) { /* Announce the Adapter */ - printf("%s: AHA-%s FW Rev. %c.%c (ID=%x) ", aha_name(aha), + device_printf(aha->dev, "AHA-%s FW Rev. %c.%c (ID=%x) ", aha->model, aha->fw_major, aha->fw_minor, aha->boardid); if (aha->diff_bus != 0) printf("Diff "); - printf("SCSI Host Adapter, SCSI ID %d, %d CCBs\n", aha->scsi_id, aha->max_ccbs); @@ -611,8 +612,8 @@ aha_init(struct aha_softc* aha) ahaallocccbs(aha); if (aha->num_ccbs == 0) { - printf("%s: aha_init - Unable to allocate initial ccbs\n", - aha_name(aha)); + device_printf(aha->dev, + "aha_init - Unable to allocate initial ccbs\n"); goto error_exit; } @@ -648,7 +649,7 @@ aha_attach(struct aha_softc *aha) /* * Construct our SIM entry */ - aha->sim = cam_sim_alloc(ahaaction, ahapoll, "aha", aha, aha->unit, + aha->sim = cam_sim_alloc(ahaaction, ahapoll, "aha", aha, device_get_unit(aha->dev), 2, tagged_dev_openings, devq); cam_simq_release(devq); if (aha->sim == NULL) { @@ -671,15 +672,6 @@ aha_attach(struct aha_softc *aha) return (0); } -char * -aha_name(struct aha_softc *aha) -{ - static char name[10]; - - snprintf(name, sizeof(name), "aha%d", aha->unit); - return (name); -} - void aha_find_probe_range(int ioport, int *port_index, int *max_port_index) { @@ -801,7 +793,7 @@ ahagetccb(struct aha_softc *aha) ahaallocccbs(aha); accb = SLIST_FIRST(&aha->free_aha_ccbs); if (accb == NULL) - printf("%s: Can't malloc ACCB\n", aha_name(aha)); + device_printf(aha->dev, "Can't malloc ACCB\n"); else { SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links); aha->active_ccbs++; @@ -1106,8 +1098,9 @@ ahaexecuteccb(void *arg, bus_dma_segment if (error != 0) { if (error != EFBIG) - printf("%s: Unexepected error 0x%x returned from " - "bus_dmamap_load\n", aha_name(aha), error); + device_printf(aha->dev, + "Unexepected error 0x%x returned from " + "bus_dmamap_load\n", error); if (ccb->ccb_h.status == CAM_REQ_INPROG) { xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); ccb->ccb_h.status = CAM_REQ_TOO_BIG|CAM_DEV_QFRZN; @@ -1187,9 +1180,9 @@ ahaexecuteccb(void *arg, bus_dma_segment * hung, one of the pending transactions will * timeout causing us to start recovery operations. */ - printf("%s: Encountered busy mailbox with %d out of %d " - "commands active!!!", aha_name(aha), aha->active_ccbs, - aha->max_ccbs); + device_printf(aha->dev, + "Encountered busy mailbox with %d out of %d " + "commands active!!!", aha->active_ccbs, aha->max_ccbs); callout_stop(&ccb->ccb_h.timeout_ch); if (nseg != 0) bus_dmamap_unload(aha->buffer_dmat, accb->dmamap); @@ -1253,8 +1246,9 @@ ahadone(struct aha_softc *aha, struct ah csio = &accb->ccb->csio; if ((accb->flags & ACCB_ACTIVE) == 0) { - printf("%s: ahadone - Attempt to free non-active ACCB %p\n", - aha_name(aha), (void *)accb); + device_printf(aha->dev, + "ahadone - Attempt to free non-active ACCB %p\n", + (void *)accb); return; } @@ -1307,7 +1301,7 @@ ahadone(struct aha_softc *aha, struct ah ccb_h = LIST_NEXT(ccb_h, sim_links.le); } } - printf("%s: No longer in timeout\n", aha_name(aha)); + device_printf(aha->dev, "No longer in timeout\n"); return; } @@ -1315,12 +1309,12 @@ ahadone(struct aha_softc *aha, struct ah switch (comp_code) { case AMBI_FREE: - printf("%s: ahadone - CCB completed with free status!\n", - aha_name(aha)); + device_printf(aha->dev, + "ahadone - CCB completed with free status!\n"); break; case AMBI_NOT_FOUND: - printf("%s: ahadone - CCB Abort failed to find CCB\n", - aha_name(aha)); + device_printf(aha->dev, + "ahadone - CCB Abort failed to find CCB\n"); break; case AMBI_ABORT: case AMBI_ERROR: @@ -1378,8 +1372,8 @@ ahadone(struct aha_softc *aha, struct ah panic("%s: Invalid CCB Opcode %x hccb = %p", aha_name(aha), accb->hccb.opcode, &accb->hccb); - printf("%s: AHA-1540A detected, compensating\n", - aha_name(aha)); + device_printf(aha->dev, + "AHA-1540A detected, compensating\n"); aha->ccb_sg_opcode = INITIATOR_SG_CCB; aha->ccb_ccb_opcode = INITIATOR_CCB; xpt_freeze_devq(ccb->ccb_h.path, /*count*/1); @@ -1449,9 +1443,8 @@ ahareset(struct aha_softc* aha, int hard DELAY(100); } if (timeout == 0) { - PRVERB(("%s: ahareset - Diagnostic Active failed to " - "assert. status = 0x%x\n", aha_name(aha), - status)); + PRVERB((aha->dev, "ahareset - Diagnostic Active failed to " + "assert. status = 0x%x\n", status)); return (ETIMEDOUT); } @@ -1478,21 +1471,18 @@ ahareset(struct aha_softc* aha, int hard DELAY(100); } if (timeout == 0) { - printf("%s: ahareset - Host adapter failed to come ready. " - "status = 0x%x\n", aha_name(aha), status); + device_printf(aha->dev, "ahareset - Host adapter failed to " + "come ready. status = 0x%x\n", status); return (ETIMEDOUT); } /* If the diagnostics failed, tell the user */ if ((status & DIAG_FAIL) != 0 || (status & HA_READY) == 0) { - printf("%s: ahareset - Adapter failed diagnostics\n", - aha_name(aha)); - + device_printf(aha->dev, "ahareset - Adapter failed diagnostics\n"); if ((status & DATAIN_REG_READY) != 0) - printf("%s: ahareset - Host Adapter Error " - "code = 0x%x\n", aha_name(aha), - aha_inb(aha, DATAIN_REG)); + device_printf(aha->dev, "ahareset - Host Adapter " + "Error code = 0x%x\n", aha_inb(aha, DATAIN_REG)); return (ENXIO); } @@ -1560,8 +1550,7 @@ aha_cmd(struct aha_softc *aha, aha_op_t crit_exit(); if (timeout == 0) { - printf("%s: aha_cmd: Timeout waiting for adapter idle\n", - aha_name(aha)); + device_printf(aha->dev, "aha_cmd: Timeout waiting for adapter idle\n"); return (ETIMEDOUT); } aha->command_cmp = 0; @@ -1586,8 +1575,8 @@ aha_cmd(struct aha_softc *aha, aha_op_t DELAY(100); } if (timeout == 0) { - printf("%s: aha_cmd: Timeout waiting for adapter ready, " - "status = 0x%x\n", aha_name(aha), status); + device_printf(aha->dev, "aha_cmd: Timeout waiting for adapter " + "ready, status = 0x%x\n", status); return (ETIMEDOUT); } @@ -1628,8 +1617,8 @@ aha_cmd(struct aha_softc *aha, aha_op_t } } if (timeout == 0) { - printf("%s: aha_cmd: Timeout sending parameters, " - "status = 0x%x\n", aha_name(aha), status); + device_printf(aha->dev, "aha_cmd: Timeout sending parameters, " + "status = 0x%x\n", status); error = ETIMEDOUT; } @@ -1663,9 +1652,8 @@ aha_cmd(struct aha_softc *aha, aha_op_t if (reply_len < reply_buf_size) { *reply_data++ = data; } else { - printf("%s: aha_cmd - Discarded reply data " - "byte for opcode 0x%x\n", aha_name(aha), - opcode); + device_printf(aha->dev, "aha_cmd - Discarded reply data " + "byte for opcode 0x%x\n", opcode); } /* * Reset timeout to ensure at least a second @@ -1677,10 +1665,9 @@ aha_cmd(struct aha_softc *aha, aha_op_t DELAY(100); } if (cmd_timeout == 0) { - printf("%s: aha_cmd: Timeout waiting for reply data and " - "command complete.\n%s: status = 0x%x, intstat = 0x%x, " - "reply_len = %d\n", aha_name(aha), aha_name(aha), status, - intstat, reply_len); + device_printf(aha->dev, "aha_cmd: Timeout: status = 0x%x, " + "intstat = 0x%x, reply_len = %d\n", status, intstat, + reply_len); return (ETIMEDOUT); } @@ -1699,7 +1686,7 @@ aha_cmd(struct aha_softc *aha, aha_op_t * If the command was rejected by the controller, tell the caller. */ if ((saved_status & CMD_INVALID) != 0) { - PRVERB(("%s: Invalid Command 0x%x\n", aha_name(aha), opcode)); + PRVERB((aha->dev, "Invalid Command 0x%x\n", opcode)); /* * Some early adapters may not recover properly from * an invalid command. If it appears that the controller @@ -1719,16 +1706,15 @@ aha_cmd(struct aha_softc *aha, aha_op_t if (param_len > 0) { /* The controller did not accept the full argument list */ - PRVERB(("%s: Controller did not accept full argument list " - "(%d > 0)\n", - aha_name(aha), param_len)); + PRVERB((aha->dev, "Controller did not accept full argument " + "list (%d > 0)\n", param_len)); return (E2BIG); } if (reply_len != reply_buf_size) { /* Too much or too little data received */ - PRVERB(("%s: Too much or too little data received (%d != %d)\n", - aha_name(aha), reply_len, reply_buf_size)); + PRVERB((aha->dev,"data received mistmatch (%d != %d)\n", + reply_len, reply_buf_size)); return (EMSGSIZE); } @@ -1757,7 +1743,8 @@ ahainitmboxes(struct aha_softc *aha) /*reply_len*/0, DEFAULT_CMD_TIMEOUT); if (error != 0) - printf("ahainitmboxes: Initialization command failed\n"); + device_printf(aha->dev, + "ahainitmboxes: Initialization command failed\n"); return (error); } @@ -1789,8 +1776,9 @@ ahafetchtransinfo(struct aha_softc *aha, DEFAULT_CMD_TIMEOUT); if (error != 0) { - printf("%s: ahafetchtransinfo - Inquire Setup Info Failed %d\n", - aha_name(aha), error); + device_printf(aha->dev, + "ahafetchtransinfo - Inquire Setup Info Failed %d\n", + error); return; } @@ -1867,12 +1855,14 @@ ahatimeout(void *arg) ccb = accb->ccb; aha = (struct aha_softc *)ccb->ccb_h.ccb_aha_ptr; xpt_print_path(ccb->ccb_h.path); + /* XXX */ printf("CCB %p - timed out\n", (void *)accb); crit_enter(); if ((accb->flags & ACCB_ACTIVE) == 0) { xpt_print_path(ccb->ccb_h.path); + /* XXX */ printf("CCB %p - timed out CCB already completed\n", (void *)accb); crit_exit(); @@ -1917,7 +1907,7 @@ ahatimeout(void *arg) */ ccb->ccb_h.status = CAM_CMD_TIMEOUT; ahareset(aha, /*hardreset*/TRUE); - printf("%s: No longer in timeout\n", aha_name(aha)); + device_printf(aha->dev, "No longer in timeout\n"); } else { /* * Send a Bus Device Reset message: