2005-01-11 01:17:07 +00:00
|
|
|
/*
|
1998-09-15 07:39:55 +00:00
|
|
|
* Generic register and struct definitions for the Adaptech 154x/164x
|
|
|
|
* SCSI host adapters. Product specific probe and attach routines can
|
|
|
|
* be found in:
|
2005-01-11 01:17:07 +00:00
|
|
|
* aha 1542A/1542B/1542C/1542CF/1542CP aha_isa.c
|
2003-11-09 20:02:47 +00:00
|
|
|
* aha 1640 aha_mca.c
|
2005-01-11 01:17:07 +00:00
|
|
|
*/
|
|
|
|
/*-
|
1998-09-29 06:50:21 +00:00
|
|
|
* Copyright (c) 1998 M. Warner Losh.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
2005-01-11 06:24:40 +00:00
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
1998-09-29 06:50:21 +00:00
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
2005-01-11 06:24:40 +00:00
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
1998-09-29 06:50:21 +00:00
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
1998-09-15 07:39:55 +00:00
|
|
|
*
|
|
|
|
* Derived from bt.c written by:
|
|
|
|
*
|
|
|
|
* Copyright (c) 1998 Justin T. Gibbs.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions, and the following disclaimer,
|
|
|
|
* without modification, immediately at the beginning of the file.
|
|
|
|
* 2. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
|
|
|
|
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
2003-08-24 17:55:58 +00:00
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
#include <sys/param.h>
|
2012-10-16 08:40:09 +00:00
|
|
|
#include <sys/conf.h>
|
2003-11-13 04:14:53 +00:00
|
|
|
#include <sys/bus.h>
|
2003-11-09 20:02:47 +00:00
|
|
|
#include <sys/systm.h>
|
1998-09-15 07:39:55 +00:00
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/kernel.h>
|
2003-07-01 15:52:06 +00:00
|
|
|
#include <sys/lock.h>
|
2006-12-11 18:28:31 +00:00
|
|
|
#include <sys/module.h>
|
2003-07-01 15:52:06 +00:00
|
|
|
#include <sys/mutex.h>
|
2012-10-16 08:40:09 +00:00
|
|
|
#include <sys/rman.h>
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
#include <machine/bus.h>
|
|
|
|
|
|
|
|
#include <cam/cam.h>
|
|
|
|
#include <cam/cam_ccb.h>
|
|
|
|
#include <cam/cam_sim.h>
|
|
|
|
#include <cam/cam_xpt_sim.h>
|
|
|
|
#include <cam/cam_debug.h>
|
|
|
|
|
|
|
|
#include <cam/scsi/scsi_message.h>
|
|
|
|
|
|
|
|
#include <dev/aha/ahareg.h>
|
|
|
|
|
2003-11-13 04:14:53 +00:00
|
|
|
#define PRVERB(x) do { if (bootverbose) device_printf x; } while (0)
|
1998-09-29 06:50:21 +00:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
* did for the CF and CP.
|
|
|
|
*/
|
|
|
|
#define PROBABLY_NEW_BOARD(REV) (REV > 0x43 && REV < 0x56)
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* MailBox Management functions */
|
|
|
|
static __inline void ahanextinbox(struct aha_softc *aha);
|
|
|
|
static __inline void ahanextoutbox(struct aha_softc *aha);
|
|
|
|
|
2003-11-13 04:14:53 +00:00
|
|
|
#define aha_name(aha) device_get_nameunit(aha->dev)
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
static __inline void
|
|
|
|
ahanextinbox(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
if (aha->cur_inbox == aha->last_inbox)
|
|
|
|
aha->cur_inbox = aha->in_boxes;
|
|
|
|
else
|
|
|
|
aha->cur_inbox++;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
ahanextoutbox(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
if (aha->cur_outbox == aha->last_outbox)
|
|
|
|
aha->cur_outbox = aha->out_boxes;
|
|
|
|
else
|
|
|
|
aha->cur_outbox++;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define ahautoa24(u,s3) \
|
|
|
|
(s3)[0] = ((u) >> 16) & 0xff; \
|
|
|
|
(s3)[1] = ((u) >> 8) & 0xff; \
|
|
|
|
(s3)[2] = (u) & 0xff;
|
|
|
|
|
|
|
|
#define aha_a24tou(s3) \
|
|
|
|
(((s3)[0] << 16) | ((s3)[1] << 8) | (s3)[2])
|
|
|
|
|
2008-08-10 15:10:39 +00:00
|
|
|
/* CCB Management functions */
|
2003-11-09 00:51:52 +00:00
|
|
|
static __inline uint32_t ahaccbvtop(struct aha_softc *aha,
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
static __inline struct aha_ccb* ahaccbptov(struct aha_softc *aha,
|
2003-11-09 00:51:52 +00:00
|
|
|
uint32_t ccb_addr);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
2003-11-09 00:51:52 +00:00
|
|
|
static __inline uint32_t
|
1998-11-10 06:44:42 +00:00
|
|
|
ahaccbvtop(struct aha_softc *aha, struct aha_ccb *accb)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
return (aha->aha_ccb_physbase
|
2003-11-09 00:51:52 +00:00
|
|
|
+ (uint32_t)((caddr_t)accb - (caddr_t)aha->aha_ccb_array));
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
static __inline struct aha_ccb *
|
2003-11-09 00:51:52 +00:00
|
|
|
ahaccbptov(struct aha_softc *aha, uint32_t ccb_addr)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
return (aha->aha_ccb_array +
|
2002-10-09 09:30:57 +00:00
|
|
|
+ ((struct aha_ccb*)(uintptr_t)ccb_addr -
|
|
|
|
(struct aha_ccb*)(uintptr_t)aha->aha_ccb_physbase));
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct aha_ccb* ahagetccb(struct aha_softc *aha);
|
1998-11-10 06:44:42 +00:00
|
|
|
static __inline void ahafreeccb(struct aha_softc *aha, struct aha_ccb *accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
static void ahaallocccbs(struct aha_softc *aha);
|
|
|
|
static bus_dmamap_callback_t ahaexecuteccb;
|
1998-11-10 06:44:42 +00:00
|
|
|
static void ahadone(struct aha_softc *aha, struct aha_ccb *accb,
|
1998-09-15 07:39:55 +00:00
|
|
|
aha_mbi_comp_code_t comp_code);
|
2012-10-15 15:59:13 +00:00
|
|
|
static void aha_intr_locked(struct aha_softc *aha);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Host adapter command functions */
|
|
|
|
static int ahareset(struct aha_softc* aha, int hard_reset);
|
|
|
|
|
|
|
|
/* Initialization functions */
|
|
|
|
static int ahainitmboxes(struct aha_softc *aha);
|
|
|
|
static bus_dmamap_callback_t ahamapmboxes;
|
|
|
|
static bus_dmamap_callback_t ahamapccbs;
|
|
|
|
static bus_dmamap_callback_t ahamapsgs;
|
|
|
|
|
|
|
|
/* Transfer Negotiation Functions */
|
|
|
|
static void ahafetchtransinfo(struct aha_softc *aha,
|
|
|
|
struct ccb_trans_settings *cts);
|
|
|
|
|
|
|
|
/* CAM SIM entry points */
|
1998-11-10 06:44:42 +00:00
|
|
|
#define ccb_accb_ptr spriv_ptr0
|
1998-09-15 07:39:55 +00:00
|
|
|
#define ccb_aha_ptr spriv_ptr1
|
|
|
|
static void ahaaction(struct cam_sim *sim, union ccb *ccb);
|
|
|
|
static void ahapoll(struct cam_sim *sim);
|
|
|
|
|
|
|
|
/* Our timeout handler */
|
2012-10-15 15:59:13 +00:00
|
|
|
static void ahatimeout(void *arg);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Exported functions */
|
2003-11-09 19:51:16 +00:00
|
|
|
void
|
2012-10-16 08:40:09 +00:00
|
|
|
aha_alloc(struct aha_softc *aha)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
|
|
|
|
SLIST_INIT(&aha->free_aha_ccbs);
|
|
|
|
LIST_INIT(&aha->pending_ccbs);
|
|
|
|
SLIST_INIT(&aha->sg_maps);
|
1999-01-20 06:21:27 +00:00
|
|
|
aha->ccb_sg_opcode = INITIATOR_SG_CCB_WRESID;
|
|
|
|
aha->ccb_ccb_opcode = INITIATOR_CCB_WRESID;
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_init(&aha->lock, "aha", NULL, MTX_DEF);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
aha_free(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
switch (aha->init_level) {
|
|
|
|
default:
|
|
|
|
case 8:
|
|
|
|
{
|
|
|
|
struct sg_map_node *sg_map;
|
|
|
|
|
|
|
|
while ((sg_map = SLIST_FIRST(&aha->sg_maps))!= NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&aha->sg_maps, links);
|
2003-11-09 00:51:52 +00:00
|
|
|
bus_dmamap_unload(aha->sg_dmat, sg_map->sg_dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
bus_dmamem_free(aha->sg_dmat, sg_map->sg_vaddr,
|
2003-11-09 00:51:52 +00:00
|
|
|
sg_map->sg_dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
free(sg_map, M_DEVBUF);
|
|
|
|
}
|
|
|
|
bus_dma_tag_destroy(aha->sg_dmat);
|
|
|
|
}
|
|
|
|
case 7:
|
|
|
|
bus_dmamap_unload(aha->ccb_dmat, aha->ccb_dmamap);
|
|
|
|
case 6:
|
|
|
|
bus_dmamem_free(aha->ccb_dmat, aha->aha_ccb_array,
|
2003-11-09 00:51:52 +00:00
|
|
|
aha->ccb_dmamap);
|
2014-01-19 20:32:20 +00:00
|
|
|
bus_dmamap_destroy(aha->ccb_dmat, aha->ccb_dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
case 5:
|
|
|
|
bus_dma_tag_destroy(aha->ccb_dmat);
|
|
|
|
case 4:
|
|
|
|
bus_dmamap_unload(aha->mailbox_dmat, aha->mailbox_dmamap);
|
|
|
|
case 3:
|
|
|
|
bus_dmamem_free(aha->mailbox_dmat, aha->in_boxes,
|
2003-11-09 00:51:52 +00:00
|
|
|
aha->mailbox_dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
bus_dmamap_destroy(aha->mailbox_dmat, aha->mailbox_dmamap);
|
|
|
|
case 2:
|
|
|
|
bus_dma_tag_destroy(aha->buffer_dmat);
|
|
|
|
case 1:
|
|
|
|
bus_dma_tag_destroy(aha->mailbox_dmat);
|
|
|
|
case 0:
|
2002-05-24 05:21:36 +00:00
|
|
|
break;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_destroy(&aha->lock);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Probe the adapter and verify that the card is an Adaptec.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aha_probe(struct aha_softc* aha)
|
|
|
|
{
|
|
|
|
u_int status;
|
|
|
|
u_int intstat;
|
|
|
|
int error;
|
1998-10-01 04:53:55 +00:00
|
|
|
board_id_data_t board_id;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* See if the three I/O ports look reasonable.
|
|
|
|
* Touch the minimal number of registers in the
|
|
|
|
* failure case.
|
|
|
|
*/
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
2003-11-09 00:51:52 +00:00
|
|
|
if ((status == 0) ||
|
|
|
|
(status & (DIAG_ACTIVE|CMD_REG_BUSY | STATUS_REG_RSVD)) != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "status reg test failed %x\n", status));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
intstat = aha_inb(aha, INTSTAT_REG);
|
|
|
|
if ((intstat & INTSTAT_REG_RSVD) != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "Failed Intstat Reg Test\n"));
|
1998-11-10 06:44:42 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Looking good so far. Final test is to reset the
|
|
|
|
* adapter and fetch the board ID and ensure we aren't
|
|
|
|
* looking at a BusLogic.
|
|
|
|
*/
|
|
|
|
if ((error = ahareset(aha, /*hard_reset*/TRUE)) != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "Failed Reset\n"));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
1998-10-01 04:53:55 +00:00
|
|
|
* Get the board ID. We use this to see if we're dealing with
|
2003-01-01 18:49:04 +00:00
|
|
|
* a buslogic card or an aha card (or clone).
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
error = aha_cmd(aha, AOP_INQUIRE_BOARD_ID, NULL, /*parmlen*/0,
|
2003-11-09 00:51:52 +00:00
|
|
|
(uint8_t*)&board_id, sizeof(board_id), DEFAULT_CMD_TIMEOUT);
|
1998-10-01 04:53:55 +00:00
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "INQUIRE failed %x\n", error));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
1998-10-01 04:53:55 +00:00
|
|
|
aha->fw_major = board_id.firmware_rev_major;
|
|
|
|
aha->fw_minor = board_id.firmware_rev_minor;
|
|
|
|
aha->boardid = board_id.board_type;
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
1998-10-01 04:53:55 +00:00
|
|
|
* The Buslogic cards have an id of either 0x41 or 0x42. So
|
|
|
|
* if those come up in the probe, we test the geometry register
|
|
|
|
* of the board. Adaptec boards that are this old will not have
|
|
|
|
* this register, and return 0xff, while buslogic cards will return
|
|
|
|
* something different.
|
|
|
|
*
|
1998-11-25 19:12:56 +00:00
|
|
|
* It appears that for reasons unknow, for the for the
|
|
|
|
* aha-1542B cards, we need to wait a little bit before trying
|
|
|
|
* to read the geometry register. I picked 10ms since we have
|
|
|
|
* reports that a for loop to 1000 did the trick, and this
|
|
|
|
* errs on the side of conservatism. Besides, no one will
|
|
|
|
* notice a 10mS delay here, even the 1542B card users :-)
|
|
|
|
*
|
1999-05-11 08:12:11 +00:00
|
|
|
* Some compatible cards return 0 here. Some cards also
|
|
|
|
* seem to return 0x7f.
|
1998-12-15 02:51:54 +00:00
|
|
|
*
|
2003-11-09 20:02:47 +00:00
|
|
|
* XXX I'm not sure how this will impact other cloned cards
|
1998-12-15 02:51:54 +00:00
|
|
|
*
|
|
|
|
* This really should be replaced with the esetup command, since
|
1999-05-11 08:12:11 +00:00
|
|
|
* that appears to be more reliable. This becomes more and more
|
|
|
|
* true over time as we discover more cards that don't read the
|
|
|
|
* geometry register consistantly.
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
1998-10-01 04:53:55 +00:00
|
|
|
if (aha->boardid <= 0x42) {
|
1998-11-25 19:12:56 +00:00
|
|
|
/* Wait 10ms before reading */
|
|
|
|
DELAY(10000);
|
1998-10-01 04:53:55 +00:00
|
|
|
status = aha_inb(aha, GEOMETRY_REG);
|
1999-05-11 08:12:11 +00:00
|
|
|
if (status != 0xff && status != 0x00 && status != 0x7f) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "Geometry Register test failed %#x\n",
|
|
|
|
status));
|
1998-10-01 04:53:55 +00:00
|
|
|
return (ENXIO);
|
1998-11-10 06:44:42 +00:00
|
|
|
}
|
1998-09-29 06:50:21 +00:00
|
|
|
}
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Pull the boards setup information and record it in our softc.
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aha_fetch_adapter_info(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
setup_data_t setup_info;
|
|
|
|
config_data_t config_data;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint8_t length_param;
|
1998-09-15 07:39:55 +00:00
|
|
|
int error;
|
1998-09-29 06:50:21 +00:00
|
|
|
struct aha_extbios extbios;
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-10-01 04:53:55 +00:00
|
|
|
switch (aha->boardid) {
|
1998-09-15 07:39:55 +00:00
|
|
|
case BOARD_1540_16HEAD_BIOS:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1540 16 head BIOS");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1540_64HEAD_BIOS:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1540 64 head BIOS");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1542:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1540/1542 64 head BIOS");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1640:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1640");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1740:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1740A/1742A/1744");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1542C:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1542C");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1542CF:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1542CF");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case BOARD_1542CP:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "1542CP");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
1998-12-04 22:54:57 +00:00
|
|
|
snprintf(aha->model, sizeof(aha->model), "Unknown");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
}
|
1998-09-29 06:50:21 +00:00
|
|
|
/*
|
|
|
|
* If we are a new type of 1542 board (anything newer than a 1542C)
|
|
|
|
* then disable the extended bios so that the
|
|
|
|
* mailbox interface is unlocked.
|
|
|
|
* This is also true for the 1542B Version 3.20. First Adaptec
|
|
|
|
* board that supports >1Gb drives.
|
|
|
|
* No need to check the extended bios flags as some of the
|
|
|
|
* extensions that cause us problems are not flagged in that byte.
|
|
|
|
*/
|
|
|
|
if (PROBABLY_NEW_BOARD(aha->boardid) ||
|
|
|
|
(aha->boardid == 0x41
|
2003-11-09 20:02:47 +00:00
|
|
|
&& aha->fw_major == 0x31 &&
|
1998-10-01 04:53:55 +00:00
|
|
|
aha->fw_minor >= 0x34)) {
|
1998-11-10 06:44:42 +00:00
|
|
|
error = aha_cmd(aha, AOP_RETURN_EXT_BIOS_INFO, NULL,
|
2003-11-09 00:51:52 +00:00
|
|
|
/*paramlen*/0, (u_char *)&extbios, sizeof(extbios),
|
|
|
|
DEFAULT_CMD_TIMEOUT);
|
2003-11-09 17:16:39 +00:00
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"AOP_RETURN_EXT_BIOS_INFO - Failed.");
|
2003-11-09 17:16:39 +00:00
|
|
|
return (error);
|
|
|
|
}
|
2003-11-09 00:51:52 +00:00
|
|
|
error = aha_cmd(aha, AOP_MBOX_IF_ENABLE, (uint8_t *)&extbios,
|
|
|
|
/*paramlen*/2, NULL, 0, DEFAULT_CMD_TIMEOUT);
|
2003-11-09 17:16:39 +00:00
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "AOP_MBOX_IF_ENABLE - Failed.");
|
2003-11-09 17:16:39 +00:00
|
|
|
return (error);
|
|
|
|
}
|
1998-09-29 06:50:21 +00:00
|
|
|
}
|
|
|
|
if (aha->boardid < 0x41)
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "Warning: aha-1542A won't work.\n");
|
1998-09-29 06:50:21 +00:00
|
|
|
|
1998-11-25 19:12:56 +00:00
|
|
|
aha->max_sg = 17; /* Need >= 17 to do 64k I/O */
|
1998-09-15 07:39:55 +00:00
|
|
|
aha->diff_bus = 0;
|
|
|
|
aha->extended_lun = 0;
|
1998-09-29 06:50:21 +00:00
|
|
|
aha->extended_trans = 0;
|
1998-10-15 19:53:30 +00:00
|
|
|
aha->max_ccbs = 16;
|
1998-09-15 07:39:55 +00:00
|
|
|
/* Determine Sync/Wide/Disc settings */
|
|
|
|
length_param = sizeof(setup_info);
|
1998-11-10 06:44:42 +00:00
|
|
|
error = aha_cmd(aha, AOP_INQUIRE_SETUP_INFO, &length_param,
|
2003-11-09 00:51:52 +00:00
|
|
|
/*paramlen*/1, (uint8_t*)&setup_info, sizeof(setup_info),
|
|
|
|
DEFAULT_CMD_TIMEOUT);
|
1998-09-15 07:39:55 +00:00
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "aha_fetch_adapter_info - Failed "
|
|
|
|
"Get Setup Info\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
if (setup_info.initiate_sync != 0) {
|
|
|
|
aha->sync_permitted = ALL_TARGETS;
|
|
|
|
}
|
|
|
|
aha->disc_permitted = ALL_TARGETS;
|
|
|
|
|
|
|
|
/* We need as many mailboxes as we can have ccbs */
|
|
|
|
aha->num_boxes = aha->max_ccbs;
|
|
|
|
|
|
|
|
/* Determine our SCSI ID */
|
1998-11-10 06:44:42 +00:00
|
|
|
error = aha_cmd(aha, AOP_INQUIRE_CONFIG, NULL, /*parmlen*/0,
|
2003-11-09 00:51:52 +00:00
|
|
|
(uint8_t*)&config_data, sizeof(config_data), DEFAULT_CMD_TIMEOUT);
|
1998-09-15 07:39:55 +00:00
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"aha_fetch_adapter_info - Failed Get Config\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
aha->scsi_id = config_data.scsi_id;
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Start the board, ready for normal operation
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
aha_init(struct aha_softc* aha)
|
|
|
|
{
|
|
|
|
/* Announce the Adapter */
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "AHA-%s FW Rev. %c.%c (ID=%x) ",
|
2003-11-09 00:51:52 +00:00
|
|
|
aha->model, aha->fw_major, aha->fw_minor, aha->boardid);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if (aha->diff_bus != 0)
|
|
|
|
printf("Diff ");
|
|
|
|
|
|
|
|
printf("SCSI Host Adapter, SCSI ID %d, %d CCBs\n", aha->scsi_id,
|
2003-11-09 00:51:52 +00:00
|
|
|
aha->max_ccbs);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Create our DMA tags. These tags define the kinds of device
|
2003-11-09 20:02:47 +00:00
|
|
|
* accessible memory allocations and memory mappings we will
|
1998-09-15 07:39:55 +00:00
|
|
|
* need to perform during normal operation.
|
|
|
|
*
|
|
|
|
* Unless we need to further restrict the allocation, we rely
|
|
|
|
* on the restrictions of the parent dmat, hence the common
|
|
|
|
* use of MAXADDR and MAXSIZE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* DMA tag for mapping buffers into device visible space. */
|
2003-11-09 00:51:52 +00:00
|
|
|
if (bus_dma_tag_create( /* parent */ aha->parent_dmat,
|
2003-03-29 09:46:10 +00:00
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ MAXBSIZE,
|
|
|
|
/* nsegments */ AHA_NSEG,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/* flags */ BUS_DMA_ALLOCNOW,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
2012-10-15 15:59:13 +00:00
|
|
|
/* lockarg */ &aha->lock,
|
2003-03-29 09:46:10 +00:00
|
|
|
&aha->buffer_dmat) != 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
/* DMA tag for our mailboxes */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create( /* parent */ aha->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ aha->num_boxes *
|
|
|
|
(sizeof(aha_mbox_in_t) +
|
|
|
|
sizeof(aha_mbox_out_t)),
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/* flags */ 0,
|
2012-10-15 15:59:13 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-03-29 09:46:10 +00:00
|
|
|
&aha->mailbox_dmat) != 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* Allocation for our mailboxes */
|
|
|
|
if (bus_dmamem_alloc(aha->mailbox_dmat, (void **)&aha->out_boxes,
|
2003-11-09 00:51:52 +00:00
|
|
|
BUS_DMA_NOWAIT, &aha->mailbox_dmamap) != 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* And permanently map them */
|
|
|
|
bus_dmamap_load(aha->mailbox_dmat, aha->mailbox_dmamap,
|
2003-11-09 00:51:52 +00:00
|
|
|
aha->out_boxes, aha->num_boxes * (sizeof(aha_mbox_in_t) +
|
|
|
|
sizeof(aha_mbox_out_t)), ahamapmboxes, aha, /*flags*/0);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
aha->in_boxes = (aha_mbox_in_t *)&aha->out_boxes[aha->num_boxes];
|
|
|
|
|
|
|
|
ahainitmboxes(aha);
|
|
|
|
|
|
|
|
/* DMA tag for our ccb structures */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create( /* parent */ aha->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ aha->max_ccbs *
|
|
|
|
sizeof(struct aha_ccb),
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/* flags */ 0,
|
2012-10-15 15:59:13 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-03-29 09:46:10 +00:00
|
|
|
&aha->ccb_dmat) != 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* Allocation for our ccbs */
|
|
|
|
if (bus_dmamem_alloc(aha->ccb_dmat, (void **)&aha->aha_ccb_array,
|
2003-11-09 00:51:52 +00:00
|
|
|
BUS_DMA_NOWAIT, &aha->ccb_dmamap) != 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* And permanently map them */
|
2003-11-09 00:51:52 +00:00
|
|
|
bus_dmamap_load(aha->ccb_dmat, aha->ccb_dmamap, aha->aha_ccb_array,
|
|
|
|
aha->max_ccbs * sizeof(struct aha_ccb), ahamapccbs, aha, /*flags*/0);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* DMA tag for our S/G structures. We allocate in page sized chunks */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create( /* parent */ aha->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ PAGE_SIZE,
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_24BIT,
|
|
|
|
/* flags */ 0,
|
2012-10-15 15:59:13 +00:00
|
|
|
/* lockfunc */ NULL,
|
|
|
|
/* lockarg */ NULL,
|
2003-11-09 00:51:52 +00:00
|
|
|
&aha->sg_dmat) != 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
|
|
|
|
aha->init_level++;
|
|
|
|
|
|
|
|
/* Perform initial CCB allocation */
|
|
|
|
bzero(aha->aha_ccb_array, aha->max_ccbs * sizeof(struct aha_ccb));
|
|
|
|
ahaallocccbs(aha);
|
|
|
|
|
|
|
|
if (aha->num_ccbs == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"aha_init - Unable to allocate initial ccbs\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
goto error_exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Note that we are going and return (to probe)
|
|
|
|
*/
|
2003-11-09 00:51:52 +00:00
|
|
|
return (0);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
error_exit:
|
|
|
|
|
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
aha_attach(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
int tagged_dev_openings;
|
|
|
|
struct cam_devq *devq;
|
|
|
|
|
|
|
|
/*
|
1998-11-25 19:12:56 +00:00
|
|
|
* We don't do tagged queueing, since the aha cards don't
|
|
|
|
* support it.
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
|
|
|
tagged_dev_openings = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the device queue for our SIM.
|
|
|
|
*/
|
|
|
|
devq = cam_simq_alloc(aha->max_ccbs - 1);
|
|
|
|
if (devq == NULL)
|
|
|
|
return (ENOMEM);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct our SIM entry
|
|
|
|
*/
|
2012-10-15 15:59:13 +00:00
|
|
|
aha->sim = cam_sim_alloc(ahaaction, ahapoll, "aha", aha,
|
|
|
|
device_get_unit(aha->dev), &aha->lock, 2, tagged_dev_openings,
|
|
|
|
devq);
|
1998-09-15 07:39:55 +00:00
|
|
|
if (aha->sim == NULL) {
|
|
|
|
cam_simq_free(devq);
|
|
|
|
return (ENOMEM);
|
|
|
|
}
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_lock(&aha->lock);
|
2007-06-17 05:55:54 +00:00
|
|
|
if (xpt_bus_register(aha->sim, aha->dev, 0) != CAM_SUCCESS) {
|
1998-09-15 07:39:55 +00:00
|
|
|
cam_sim_free(aha->sim, /*free_devq*/TRUE);
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_unlock(&aha->lock);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
2003-11-09 00:51:52 +00:00
|
|
|
if (xpt_create_path(&aha->path, /*periph*/NULL, cam_sim_path(aha->sim),
|
|
|
|
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_bus_deregister(cam_sim_path(aha->sim));
|
|
|
|
cam_sim_free(aha->sim, /*free_devq*/TRUE);
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_unlock(&aha->lock);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_unlock(&aha->lock);
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahaallocccbs(struct aha_softc *aha)
|
|
|
|
{
|
|
|
|
struct aha_ccb *next_ccb;
|
|
|
|
struct sg_map_node *sg_map;
|
|
|
|
bus_addr_t physaddr;
|
|
|
|
aha_sg_t *segs;
|
|
|
|
int newcount;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
next_ccb = &aha->aha_ccb_array[aha->num_ccbs];
|
|
|
|
|
|
|
|
sg_map = malloc(sizeof(*sg_map), M_DEVBUF, M_NOWAIT);
|
|
|
|
|
|
|
|
if (sg_map == NULL)
|
|
|
|
return;
|
|
|
|
|
|
|
|
/* Allocate S/G space for the next batch of CCBS */
|
|
|
|
if (bus_dmamem_alloc(aha->sg_dmat, (void **)&sg_map->sg_vaddr,
|
2003-11-09 00:51:52 +00:00
|
|
|
BUS_DMA_NOWAIT, &sg_map->sg_dmamap) != 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
free(sg_map, M_DEVBUF);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SLIST_INSERT_HEAD(&aha->sg_maps, sg_map, links);
|
|
|
|
|
|
|
|
bus_dmamap_load(aha->sg_dmat, sg_map->sg_dmamap, sg_map->sg_vaddr,
|
2003-11-09 00:51:52 +00:00
|
|
|
PAGE_SIZE, ahamapsgs, aha, /*flags*/0);
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
segs = sg_map->sg_vaddr;
|
|
|
|
physaddr = sg_map->sg_physaddr;
|
|
|
|
|
|
|
|
newcount = (PAGE_SIZE / (AHA_NSEG * sizeof(aha_sg_t)));
|
|
|
|
for (i = 0; aha->num_ccbs < aha->max_ccbs && i < newcount; i++) {
|
|
|
|
int error;
|
|
|
|
|
|
|
|
next_ccb->sg_list = segs;
|
|
|
|
next_ccb->sg_list_phys = physaddr;
|
1998-11-10 06:44:42 +00:00
|
|
|
next_ccb->flags = ACCB_FREE;
|
2012-10-15 15:59:13 +00:00
|
|
|
callout_init_mtx(&next_ccb->timer, &aha->lock, 0);
|
1998-09-15 07:39:55 +00:00
|
|
|
error = bus_dmamap_create(aha->buffer_dmat, /*flags*/0,
|
2003-11-09 00:51:52 +00:00
|
|
|
&next_ccb->dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
if (error != 0)
|
|
|
|
break;
|
|
|
|
SLIST_INSERT_HEAD(&aha->free_aha_ccbs, next_ccb, links);
|
|
|
|
segs += AHA_NSEG;
|
|
|
|
physaddr += (AHA_NSEG * sizeof(aha_sg_t));
|
|
|
|
next_ccb++;
|
|
|
|
aha->num_ccbs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Reserve a CCB for error recovery */
|
1998-11-10 06:44:42 +00:00
|
|
|
if (aha->recovery_accb == NULL) {
|
|
|
|
aha->recovery_accb = SLIST_FIRST(&aha->free_aha_ccbs);
|
1998-09-15 07:39:55 +00:00
|
|
|
SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(struct aha_softc *aha, struct aha_ccb *accb)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
|
2012-10-15 15:59:13 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&aha->lock, MA_OWNED);
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_ACTIVE) != 0)
|
|
|
|
LIST_REMOVE(&accb->ccb->ccb_h, sim_links.le);
|
1998-09-15 07:39:55 +00:00
|
|
|
if (aha->resource_shortage != 0
|
2003-11-09 00:51:52 +00:00
|
|
|
&& (accb->ccb->ccb_h.status & CAM_RELEASE_SIMQ) == 0) {
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
|
1998-09-15 07:39:55 +00:00
|
|
|
aha->resource_shortage = FALSE;
|
|
|
|
}
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->flags = ACCB_FREE;
|
|
|
|
SLIST_INSERT_HEAD(&aha->free_aha_ccbs, accb, links);
|
|
|
|
aha->active_ccbs--;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct aha_ccb*
|
|
|
|
ahagetccb(struct aha_softc *aha)
|
|
|
|
{
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb* accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
2012-10-15 15:59:13 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&aha->lock, MA_OWNED);
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb = SLIST_FIRST(&aha->free_aha_ccbs)) != NULL) {
|
1998-09-15 07:39:55 +00:00
|
|
|
SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links);
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->active_ccbs++;
|
1998-09-15 07:39:55 +00:00
|
|
|
} else if (aha->num_ccbs < aha->max_ccbs) {
|
|
|
|
ahaallocccbs(aha);
|
1998-11-10 06:44:42 +00:00
|
|
|
accb = SLIST_FIRST(&aha->free_aha_ccbs);
|
|
|
|
if (accb == NULL)
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "Can't malloc ACCB\n");
|
1998-11-10 06:44:42 +00:00
|
|
|
else {
|
1998-09-15 07:39:55 +00:00
|
|
|
SLIST_REMOVE_HEAD(&aha->free_aha_ccbs, links);
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->active_ccbs++;
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
return (accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahaaction(struct cam_sim *sim, union ccb *ccb)
|
|
|
|
{
|
|
|
|
struct aha_softc *aha;
|
|
|
|
|
|
|
|
CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("ahaaction\n"));
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
aha = (struct aha_softc *)cam_sim_softc(sim);
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_assert(&aha->lock, MA_OWNED);
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
switch (ccb->ccb_h.func_code) {
|
|
|
|
/* Common cases first */
|
|
|
|
case XPT_SCSI_IO: /* Execute the requested I/O operation */
|
2003-11-09 00:51:52 +00:00
|
|
|
case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */ {
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
struct aha_hccb *hccb;
|
|
|
|
|
|
|
|
/*
|
2003-01-01 18:49:04 +00:00
|
|
|
* Get an accb to use.
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb = ahagetccb(aha)) == NULL) {
|
1998-09-15 07:39:55 +00:00
|
|
|
aha->resource_shortage = TRUE;
|
|
|
|
xpt_freeze_simq(aha->sim, /*count*/1);
|
|
|
|
ccb->ccb_h.status = CAM_REQUEUE_REQ;
|
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
1998-11-10 06:44:42 +00:00
|
|
|
hccb = &accb->hccb;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/*
|
1998-11-10 06:44:42 +00:00
|
|
|
* So we can find the ACCB when an abort is requested
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->ccb = ccb;
|
|
|
|
ccb->ccb_h.ccb_accb_ptr = accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb->ccb_h.ccb_aha_ptr = aha;
|
|
|
|
|
|
|
|
/*
|
1998-11-10 06:44:42 +00:00
|
|
|
* Put all the arguments for the xfer in the accb
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
|
|
|
hccb->target = ccb->ccb_h.target_id;
|
|
|
|
hccb->lun = ccb->ccb_h.target_lun;
|
|
|
|
hccb->ahastat = 0;
|
|
|
|
hccb->sdstat = 0;
|
|
|
|
|
|
|
|
if (ccb->ccb_h.func_code == XPT_SCSI_IO) {
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
struct ccb_hdr *ccbh;
|
2013-02-12 16:57:20 +00:00
|
|
|
int error;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
csio = &ccb->csio;
|
|
|
|
ccbh = &csio->ccb_h;
|
1999-01-20 06:21:27 +00:00
|
|
|
hccb->opcode = aha->ccb_ccb_opcode;
|
1998-09-15 07:39:55 +00:00
|
|
|
hccb->datain = (ccb->ccb_h.flags & CAM_DIR_IN) != 0;
|
|
|
|
hccb->dataout = (ccb->ccb_h.flags & CAM_DIR_OUT) != 0;
|
|
|
|
hccb->cmd_len = csio->cdb_len;
|
|
|
|
if (hccb->cmd_len > sizeof(hccb->scsi_cdb)) {
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
hccb->sense_len = csio->sense_len;
|
|
|
|
if ((ccbh->flags & CAM_CDB_POINTER) != 0) {
|
|
|
|
if ((ccbh->flags & CAM_CDB_PHYS) == 0) {
|
|
|
|
bcopy(csio->cdb_io.cdb_ptr,
|
|
|
|
hccb->scsi_cdb, hccb->cmd_len);
|
|
|
|
} else {
|
|
|
|
/* I guess I could map it in... */
|
|
|
|
ccbh->status = CAM_REQ_INVALID;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
bcopy(csio->cdb_io.cdb_bytes,
|
|
|
|
hccb->scsi_cdb, hccb->cmd_len);
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* If we have any data to send with this command,
|
|
|
|
* map it into bus space.
|
|
|
|
*/
|
2013-02-12 16:57:20 +00:00
|
|
|
|
|
|
|
error = bus_dmamap_load_ccb(
|
|
|
|
aha->buffer_dmat,
|
|
|
|
accb->dmamap,
|
|
|
|
ccb,
|
|
|
|
ahaexecuteccb,
|
|
|
|
accb,
|
|
|
|
/*flags*/0);
|
|
|
|
if (error == EINPROGRESS) {
|
|
|
|
/*
|
|
|
|
* So as to maintain ordering, freeze the
|
|
|
|
* controller queue until our mapping is
|
|
|
|
* returned.
|
|
|
|
*/
|
|
|
|
xpt_freeze_simq(aha->sim, 1);
|
|
|
|
csio->ccb_h.status |= CAM_RELEASE_SIMQ;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
hccb->opcode = INITIATOR_BUS_DEV_RESET;
|
|
|
|
/* No data transfer */
|
|
|
|
hccb->datain = TRUE;
|
|
|
|
hccb->dataout = TRUE;
|
|
|
|
hccb->cmd_len = 0;
|
|
|
|
hccb->sense_len = 0;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahaexecuteccb(accb, NULL, 0, 0);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_EN_LUN: /* Enable LUN as a target */
|
|
|
|
case XPT_TARGET_IO: /* Execute target I/O request */
|
|
|
|
case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */
|
|
|
|
case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/
|
|
|
|
case XPT_ABORT: /* Abort the specified CCB */
|
|
|
|
/* XXX Implement */
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_SET_TRAN_SETTINGS:
|
|
|
|
/* XXX Implement */
|
Add a number of interrelated CAM feature enhancements and bug fixes.
NOTE: These changes will require recompilation of any userland
applications, like cdrecord, xmcd, etc., that use the CAM passthrough
interface. A make world is recommended.
camcontrol.[c8]:
- We now support two new commands, "tags" and "negotiate".
- The tags commands allows users to view the number of tagged
openings for a device as well as a number of other related
parameters, and it allows users to set tagged openings for
a device.
- The negotiate command allows users to enable and disable
disconnection and tagged queueing, set sync rates, offsets
and bus width. Note that not all of those features are
available for all controllers. Only the adv, ahc, and ncr
drivers fully support all of the features at this point.
Some cards do not allow the setting of sync rates, offsets and
the like, and some of the drivers don't have any facilities to
do so. Some drivers, like the adw driver, only support enabling
or disabling sync negotiation, but do not support setting sync
rates.
- new description in the camcontrol man page of how to format a disk
- cleanup of the camcontrol inquiry command
- add support in the 'devlist' command for skipping unconfigured devices if
-v was not specified on the command line.
- make use of the new base_transfer_speed in the path inquiry CCB.
- fix CCB bzero cases
cam_xpt.c, cam_sim.[ch], cam_ccb.h:
- new flags on many CCB function codes to designate whether they're
non-immediate, use a user-supplied CCB, and can only be passed from
userland programs via the xpt device. Use these flags in the transport
layer and pass driver to categorize CCBs.
- new flag in the transport layer device matching code for device nodes
that indicates whether a device is unconfigured
- bump the CAM version from 0x10 to 0x11
- Change the CAM ioctls to use the version as their group code, so we can
force users to recompile code even when the CCB size doesn't change.
- add + fill in a new value in the path inquiry CCB, base_transfer_speed.
Remove a corresponding field from the cam_sim structure, and add code to
every SIM to set this field to the proper value.
- Fix the set transfer settings code in the transport layer.
scsi_cd.c:
- make some variables volatile instead of just casting them in various
places
- fix a race condition in the changer code
- attach unless we get a "logical unit not supported" error. This should
fix all of the cases where people have devices that return weird errors
when they don't have media in the drive.
scsi_da.c:
- attach unless we get a "logical unit not supported" error
scsi_pass.c:
- for immediate CCBs, just malloc a CCB to send the user request in. This
gets rid of the 'held' count problem in camcontrol tags.
scsi_pass.h:
- change the CAM ioctls to use the CAM version as their group code.
adv driver:
- Allow changing the sync rate and offset separately.
adw driver
- Allow changing the sync rate and offset separately.
aha driver:
- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.
ahc driver:
- Allow setting offset and sync rate separately
bt driver:
- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.
NCR driver:
- Fix the ultra/ultra 2 negotiation bug
- allow setting both the sync rate and offset separately
Other HBA drivers:
- Put code in to set the base_transfer_speed field for
XPT_GET_TRAN_SETTINGS CCBs.
Reviewed by: gibbs, mjacob (isp), imp (aha)
1999-05-06 20:16:39 +00:00
|
|
|
ccb->ccb_h.status = CAM_PROVIDE_FAIL;
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_GET_TRAN_SETTINGS:
|
|
|
|
/* Get default/user set transfer settings for the target */
|
|
|
|
{
|
2006-10-31 05:53:29 +00:00
|
|
|
struct ccb_trans_settings *cts = &ccb->cts;
|
|
|
|
u_int target_mask = 0x01 << ccb->ccb_h.target_id;
|
|
|
|
struct ccb_trans_settings_scsi *scsi =
|
|
|
|
&cts->proto_specific.scsi;
|
|
|
|
struct ccb_trans_settings_spi *spi =
|
|
|
|
&cts->xport_specific.spi;
|
|
|
|
|
|
|
|
cts->protocol = PROTO_SCSI;
|
|
|
|
cts->protocol_version = SCSI_REV_2;
|
|
|
|
cts->transport = XPORT_SPI;
|
|
|
|
cts->transport_version = 2;
|
|
|
|
if (cts->type == CTS_TYPE_USER_SETTINGS) {
|
|
|
|
spi->flags = 0;
|
|
|
|
if ((aha->disc_permitted & target_mask) != 0)
|
|
|
|
spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
|
|
|
|
if ((aha->sync_permitted & target_mask) != 0) {
|
|
|
|
if (aha->boardid >= BOARD_1542CF)
|
|
|
|
spi->sync_period = 25;
|
|
|
|
else
|
|
|
|
spi->sync_period = 50;
|
|
|
|
} else {
|
|
|
|
spi->sync_period = 0;
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
if (spi->sync_period != 0)
|
|
|
|
spi->sync_offset = 15;
|
|
|
|
|
|
|
|
spi->valid = CTS_SPI_VALID_SYNC_RATE
|
|
|
|
| CTS_SPI_VALID_SYNC_OFFSET
|
|
|
|
| CTS_SPI_VALID_BUS_WIDTH
|
|
|
|
| CTS_SPI_VALID_DISC;
|
|
|
|
scsi->valid = CTS_SCSI_VALID_TQ;
|
|
|
|
} else {
|
|
|
|
ahafetchtransinfo(aha, cts);
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_CALC_GEOMETRY:
|
|
|
|
{
|
|
|
|
struct ccb_calc_geometry *ccg;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint32_t size_mb;
|
|
|
|
uint32_t secs_per_cylinder;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
ccg = &ccb->ccg;
|
|
|
|
size_mb = ccg->volume_size
|
|
|
|
/ ((1024L * 1024L) / ccg->block_size);
|
|
|
|
if (size_mb >= 1024 && (aha->extended_trans != 0)) {
|
|
|
|
if (size_mb >= 2048) {
|
|
|
|
ccg->heads = 255;
|
|
|
|
ccg->secs_per_track = 63;
|
|
|
|
} else {
|
|
|
|
ccg->heads = 128;
|
|
|
|
ccg->secs_per_track = 32;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
ccg->heads = 64;
|
|
|
|
ccg->secs_per_track = 32;
|
|
|
|
}
|
|
|
|
secs_per_cylinder = ccg->heads * ccg->secs_per_track;
|
|
|
|
ccg->cylinders = ccg->volume_size / secs_per_cylinder;
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_RESET_BUS: /* Reset the specified SCSI bus */
|
|
|
|
ahareset(aha, /*hardreset*/TRUE);
|
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_TERM_IO: /* Terminate the I/O process */
|
|
|
|
/* XXX Implement */
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
case XPT_PATH_INQ: /* Path routing inquiry */
|
|
|
|
{
|
|
|
|
struct ccb_pathinq *cpi = &ccb->cpi;
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
cpi->version_num = 1; /* XXX??? */
|
|
|
|
cpi->hba_inquiry = PI_SDTR_ABLE;
|
|
|
|
cpi->target_sprt = 0;
|
|
|
|
cpi->hba_misc = 0;
|
|
|
|
cpi->hba_eng_cnt = 0;
|
1998-10-01 04:53:55 +00:00
|
|
|
cpi->max_target = 7;
|
1998-09-15 07:39:55 +00:00
|
|
|
cpi->max_lun = 7;
|
|
|
|
cpi->initiator_id = aha->scsi_id;
|
|
|
|
cpi->bus_id = cam_sim_bus(sim);
|
Add a number of interrelated CAM feature enhancements and bug fixes.
NOTE: These changes will require recompilation of any userland
applications, like cdrecord, xmcd, etc., that use the CAM passthrough
interface. A make world is recommended.
camcontrol.[c8]:
- We now support two new commands, "tags" and "negotiate".
- The tags commands allows users to view the number of tagged
openings for a device as well as a number of other related
parameters, and it allows users to set tagged openings for
a device.
- The negotiate command allows users to enable and disable
disconnection and tagged queueing, set sync rates, offsets
and bus width. Note that not all of those features are
available for all controllers. Only the adv, ahc, and ncr
drivers fully support all of the features at this point.
Some cards do not allow the setting of sync rates, offsets and
the like, and some of the drivers don't have any facilities to
do so. Some drivers, like the adw driver, only support enabling
or disabling sync negotiation, but do not support setting sync
rates.
- new description in the camcontrol man page of how to format a disk
- cleanup of the camcontrol inquiry command
- add support in the 'devlist' command for skipping unconfigured devices if
-v was not specified on the command line.
- make use of the new base_transfer_speed in the path inquiry CCB.
- fix CCB bzero cases
cam_xpt.c, cam_sim.[ch], cam_ccb.h:
- new flags on many CCB function codes to designate whether they're
non-immediate, use a user-supplied CCB, and can only be passed from
userland programs via the xpt device. Use these flags in the transport
layer and pass driver to categorize CCBs.
- new flag in the transport layer device matching code for device nodes
that indicates whether a device is unconfigured
- bump the CAM version from 0x10 to 0x11
- Change the CAM ioctls to use the version as their group code, so we can
force users to recompile code even when the CCB size doesn't change.
- add + fill in a new value in the path inquiry CCB, base_transfer_speed.
Remove a corresponding field from the cam_sim structure, and add code to
every SIM to set this field to the proper value.
- Fix the set transfer settings code in the transport layer.
scsi_cd.c:
- make some variables volatile instead of just casting them in various
places
- fix a race condition in the changer code
- attach unless we get a "logical unit not supported" error. This should
fix all of the cases where people have devices that return weird errors
when they don't have media in the drive.
scsi_da.c:
- attach unless we get a "logical unit not supported" error
scsi_pass.c:
- for immediate CCBs, just malloc a CCB to send the user request in. This
gets rid of the 'held' count problem in camcontrol tags.
scsi_pass.h:
- change the CAM ioctls to use the CAM version as their group code.
adv driver:
- Allow changing the sync rate and offset separately.
adw driver
- Allow changing the sync rate and offset separately.
aha driver:
- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.
ahc driver:
- Allow setting offset and sync rate separately
bt driver:
- Don't return CAM_REQ_CMP for SET_TRAN_SETTINGS CCBs.
NCR driver:
- Fix the ultra/ultra 2 negotiation bug
- allow setting both the sync rate and offset separately
Other HBA drivers:
- Put code in to set the base_transfer_speed field for
XPT_GET_TRAN_SETTINGS CCBs.
Reviewed by: gibbs, mjacob (isp), imp (aha)
1999-05-06 20:16:39 +00:00
|
|
|
cpi->base_transfer_speed = 3300;
|
1998-09-15 07:39:55 +00:00
|
|
|
strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
|
|
|
|
strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
|
|
|
|
strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
|
|
|
|
cpi->unit_number = cam_sim_unit(sim);
|
2006-10-31 05:53:29 +00:00
|
|
|
cpi->transport = XPORT_SPI;
|
|
|
|
cpi->transport_version = 2;
|
|
|
|
cpi->protocol = PROTO_SCSI;
|
|
|
|
cpi->protocol_version = SCSI_REV_2;
|
1998-09-15 07:39:55 +00:00
|
|
|
cpi->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahaexecuteccb(void *arg, bus_dma_segment_t *dm_segs, int nseg, int error)
|
|
|
|
{
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
union ccb *ccb;
|
|
|
|
struct aha_softc *aha;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint32_t paddr;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
accb = (struct aha_ccb *)arg;
|
|
|
|
ccb = accb->ccb;
|
1998-09-15 07:39:55 +00:00
|
|
|
aha = (struct aha_softc *)ccb->ccb_h.ccb_aha_ptr;
|
|
|
|
|
|
|
|
if (error != 0) {
|
|
|
|
if (error != EFBIG)
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"Unexepected error 0x%x returned from "
|
|
|
|
"bus_dmamap_load\n", error);
|
1998-09-15 07:39:55 +00:00
|
|
|
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;
|
|
|
|
}
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
if (nseg != 0) {
|
|
|
|
aha_sg_t *sg;
|
|
|
|
bus_dma_segment_t *end_seg;
|
2003-05-27 04:59:59 +00:00
|
|
|
bus_dmasync_op_t op;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
end_seg = dm_segs + nseg;
|
|
|
|
|
|
|
|
/* Copy the segments into our SG list */
|
1998-11-10 06:44:42 +00:00
|
|
|
sg = accb->sg_list;
|
1998-09-15 07:39:55 +00:00
|
|
|
while (dm_segs < end_seg) {
|
|
|
|
ahautoa24(dm_segs->ds_len, sg->len);
|
|
|
|
ahautoa24(dm_segs->ds_addr, sg->addr);
|
|
|
|
sg++;
|
|
|
|
dm_segs++;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (nseg > 1) {
|
1999-01-20 06:21:27 +00:00
|
|
|
accb->hccb.opcode = aha->ccb_sg_opcode;
|
1998-09-15 07:39:55 +00:00
|
|
|
ahautoa24((sizeof(aha_sg_t) * nseg),
|
2003-11-09 00:51:52 +00:00
|
|
|
accb->hccb.data_len);
|
1998-11-10 06:44:42 +00:00
|
|
|
ahautoa24(accb->sg_list_phys, accb->hccb.data_addr);
|
1998-09-15 07:39:55 +00:00
|
|
|
} else {
|
1998-11-10 06:44:42 +00:00
|
|
|
bcopy(accb->sg_list->len, accb->hccb.data_len, 3);
|
|
|
|
bcopy(accb->sg_list->addr, accb->hccb.data_addr, 3);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
|
|
|
|
op = BUS_DMASYNC_PREREAD;
|
|
|
|
else
|
|
|
|
op = BUS_DMASYNC_PREWRITE;
|
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
bus_dmamap_sync(aha->buffer_dmat, accb->dmamap, op);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
} else {
|
1998-12-13 00:05:04 +00:00
|
|
|
accb->hccb.opcode = INITIATOR_CCB;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahautoa24(0, accb->hccb.data_len);
|
|
|
|
ahautoa24(0, accb->hccb.data_addr);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Last time we need to check if this CCB needs to
|
|
|
|
* be aborted.
|
|
|
|
*/
|
|
|
|
if (ccb->ccb_h.status != CAM_REQ_INPROG) {
|
|
|
|
if (nseg != 0)
|
1998-11-10 06:44:42 +00:00
|
|
|
bus_dmamap_unload(aha->buffer_dmat, accb->dmamap);
|
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->flags = ACCB_ACTIVE;
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb->ccb_h.status |= CAM_SIM_QUEUED;
|
|
|
|
LIST_INSERT_HEAD(&aha->pending_ccbs, &ccb->ccb_h, sim_links.le);
|
|
|
|
|
2012-10-15 15:59:13 +00:00
|
|
|
callout_reset(&accb->timer, (ccb->ccb_h.timeout * hz) / 1000,
|
|
|
|
ahatimeout, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Tell the adapter about this command */
|
1998-11-10 06:44:42 +00:00
|
|
|
if (aha->cur_outbox->action_code != AMBO_FREE) {
|
|
|
|
/*
|
|
|
|
* We should never encounter a busy mailbox.
|
|
|
|
* If we do, warn the user, and treat it as
|
|
|
|
* a resource shortage. If the controller is
|
|
|
|
* hung, one of the pending transactions will
|
|
|
|
* timeout causing us to start recovery operations.
|
|
|
|
*/
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"Encountered busy mailbox with %d out of %d "
|
|
|
|
"commands active!!!", aha->active_ccbs, aha->max_ccbs);
|
2012-10-16 08:40:09 +00:00
|
|
|
callout_stop(&accb->timer);
|
1998-11-10 06:44:42 +00:00
|
|
|
if (nseg != 0)
|
|
|
|
bus_dmamap_unload(aha->buffer_dmat, accb->dmamap);
|
|
|
|
ahafreeccb(aha, accb);
|
|
|
|
aha->resource_shortage = TRUE;
|
|
|
|
xpt_freeze_simq(aha->sim, /*count*/1);
|
|
|
|
ccb->ccb_h.status = CAM_REQUEUE_REQ;
|
|
|
|
xpt_done(ccb);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
paddr = ahaccbvtop(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
ahautoa24(paddr, aha->cur_outbox->ccb_addr);
|
2003-11-09 20:02:47 +00:00
|
|
|
aha->cur_outbox->action_code = AMBO_START;
|
1998-11-10 06:44:42 +00:00
|
|
|
aha_outb(aha, COMMAND_REG, AOP_START_MBOX);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
ahanextoutbox(aha);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
aha_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct aha_softc *aha;
|
2012-10-15 15:59:13 +00:00
|
|
|
|
|
|
|
aha = arg;
|
|
|
|
mtx_lock(&aha->lock);
|
|
|
|
aha_intr_locked(aha);
|
|
|
|
mtx_unlock(&aha->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
aha_intr_locked(struct aha_softc *aha)
|
|
|
|
{
|
1998-09-15 07:39:55 +00:00
|
|
|
u_int intstat;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint32_t paddr;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
while (((intstat = aha_inb(aha, INTSTAT_REG)) & INTR_PENDING) != 0) {
|
|
|
|
if ((intstat & CMD_COMPLETE) != 0) {
|
|
|
|
aha->latched_status = aha_inb(aha, STATUS_REG);
|
|
|
|
aha->command_cmp = TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
aha_outb(aha, CONTROL_REG, RESET_INTR);
|
|
|
|
|
|
|
|
if ((intstat & IMB_LOADED) != 0) {
|
1998-11-10 06:44:42 +00:00
|
|
|
while (aha->cur_inbox->comp_code != AMBI_FREE) {
|
1998-09-15 07:39:55 +00:00
|
|
|
paddr = aha_a24tou(aha->cur_inbox->ccb_addr);
|
2003-11-09 00:51:52 +00:00
|
|
|
ahadone(aha, ahaccbptov(aha, paddr),
|
|
|
|
aha->cur_inbox->comp_code);
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->cur_inbox->comp_code = AMBI_FREE;
|
1998-09-15 07:39:55 +00:00
|
|
|
ahanextinbox(aha);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((intstat & SCSI_BUS_RESET) != 0) {
|
|
|
|
ahareset(aha, /*hardreset*/FALSE);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
1998-11-10 06:44:42 +00:00
|
|
|
ahadone(struct aha_softc *aha, struct aha_ccb *accb, aha_mbi_comp_code_t comp_code)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
ccb = accb->ccb;
|
|
|
|
csio = &accb->ccb->csio;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_ACTIVE) == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"ahadone - Attempt to free non-active ACCB %p\n",
|
|
|
|
(void *)accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((ccb->ccb_h.flags & CAM_DIR_MASK) != CAM_DIR_NONE) {
|
2003-05-27 04:59:59 +00:00
|
|
|
bus_dmasync_op_t op;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
|
|
|
|
op = BUS_DMASYNC_POSTREAD;
|
|
|
|
else
|
|
|
|
op = BUS_DMASYNC_POSTWRITE;
|
1998-11-10 06:44:42 +00:00
|
|
|
bus_dmamap_sync(aha->buffer_dmat, accb->dmamap, op);
|
|
|
|
bus_dmamap_unload(aha->buffer_dmat, accb->dmamap);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
if (accb == aha->recovery_accb) {
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
1998-11-10 06:44:42 +00:00
|
|
|
* The recovery ACCB does not have a CCB associated
|
1998-09-15 07:39:55 +00:00
|
|
|
* with it, so short circuit the normal error handling.
|
|
|
|
* We now traverse our list of pending CCBs and process
|
|
|
|
* any that were terminated by the recovery CCBs action.
|
|
|
|
* We also reinstate timeouts for all remaining, pending,
|
|
|
|
* CCBs.
|
|
|
|
*/
|
|
|
|
struct cam_path *path;
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
cam_status error;
|
|
|
|
|
|
|
|
/* Notify all clients that a BDR occured */
|
|
|
|
error = xpt_create_path(&path, /*periph*/NULL,
|
2003-11-09 00:51:52 +00:00
|
|
|
cam_sim_path(aha->sim), accb->hccb.target,
|
|
|
|
CAM_LUN_WILDCARD);
|
2003-11-09 20:02:47 +00:00
|
|
|
|
2013-10-22 12:42:49 +00:00
|
|
|
if (error == CAM_REQ_CMP) {
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_async(AC_SENT_BDR, path, NULL);
|
2013-10-22 12:42:49 +00:00
|
|
|
xpt_free_path(path);
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
ccb_h = LIST_FIRST(&aha->pending_ccbs);
|
|
|
|
while (ccb_h != NULL) {
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *pending_accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr;
|
|
|
|
if (pending_accb->hccb.target == accb->hccb.target) {
|
|
|
|
pending_accb->hccb.ahastat = AHASTAT_HA_BDR;
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb_h = LIST_NEXT(ccb_h, sim_links.le);
|
1998-11-10 06:44:42 +00:00
|
|
|
ahadone(aha, pending_accb, AMBI_ERROR);
|
1998-09-15 07:39:55 +00:00
|
|
|
} else {
|
2012-10-15 15:59:13 +00:00
|
|
|
callout_reset(&pending_accb->timer,
|
|
|
|
(ccb_h->timeout * hz) / 1000,
|
|
|
|
ahatimeout, pending_accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb_h = LIST_NEXT(ccb_h, sim_links.le);
|
|
|
|
}
|
|
|
|
}
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "No longer in timeout\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2012-10-15 15:59:13 +00:00
|
|
|
callout_stop(&accb->timer);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
switch (comp_code) {
|
1998-11-10 06:44:42 +00:00
|
|
|
case AMBI_FREE:
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"ahadone - CCB completed with free status!\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
1998-11-10 06:44:42 +00:00
|
|
|
case AMBI_NOT_FOUND:
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"ahadone - CCB Abort failed to find CCB\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
1998-11-10 06:44:42 +00:00
|
|
|
case AMBI_ABORT:
|
|
|
|
case AMBI_ERROR:
|
1998-09-15 07:39:55 +00:00
|
|
|
/* An error occured */
|
1999-01-20 06:21:27 +00:00
|
|
|
if (accb->hccb.opcode < INITIATOR_CCB_WRESID)
|
|
|
|
csio->resid = 0;
|
|
|
|
else
|
|
|
|
csio->resid = aha_a24tou(accb->hccb.data_len);
|
1998-11-10 06:44:42 +00:00
|
|
|
switch(accb->hccb.ahastat) {
|
1998-09-15 07:39:55 +00:00
|
|
|
case AHASTAT_DATARUN_ERROR:
|
1998-12-22 18:14:50 +00:00
|
|
|
{
|
|
|
|
if (csio->resid <= 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
csio->ccb_h.status = CAM_DATA_RUN_ERR;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
/* FALLTHROUGH */
|
1998-12-22 18:14:50 +00:00
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
case AHASTAT_NOERROR:
|
1998-11-10 06:44:42 +00:00
|
|
|
csio->scsi_status = accb->hccb.sdstat;
|
1998-09-15 07:39:55 +00:00
|
|
|
csio->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
|
|
|
|
switch(csio->scsi_status) {
|
|
|
|
case SCSI_STATUS_CHECK_COND:
|
|
|
|
case SCSI_STATUS_CMD_TERMINATED:
|
|
|
|
csio->ccb_h.status |= CAM_AUTOSNS_VALID;
|
|
|
|
/*
|
|
|
|
* The aha writes the sense data at different
|
|
|
|
* offsets based on the scsi cmd len
|
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
bcopy((caddr_t) &accb->hccb.scsi_cdb +
|
2003-11-09 20:02:47 +00:00
|
|
|
accb->hccb.cmd_len,
|
2003-11-09 00:51:52 +00:00
|
|
|
(caddr_t) &csio->sense_data,
|
|
|
|
accb->hccb.sense_len);
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
case SCSI_STATUS_OK:
|
|
|
|
csio->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case AHASTAT_SELTIMEOUT:
|
|
|
|
csio->ccb_h.status = CAM_SEL_TIMEOUT;
|
|
|
|
break;
|
|
|
|
case AHASTAT_UNEXPECTED_BUSFREE:
|
|
|
|
csio->ccb_h.status = CAM_UNEXP_BUSFREE;
|
|
|
|
break;
|
|
|
|
case AHASTAT_INVALID_PHASE:
|
|
|
|
csio->ccb_h.status = CAM_SEQUENCE_FAIL;
|
|
|
|
break;
|
|
|
|
case AHASTAT_INVALID_ACTION_CODE:
|
|
|
|
panic("%s: Inavlid Action code", aha_name(aha));
|
|
|
|
break;
|
|
|
|
case AHASTAT_INVALID_OPCODE:
|
1999-01-20 06:21:27 +00:00
|
|
|
if (accb->hccb.opcode < INITIATOR_CCB_WRESID)
|
|
|
|
panic("%s: Invalid CCB Opcode %x hccb = %p",
|
2003-11-09 00:51:52 +00:00
|
|
|
aha_name(aha), accb->hccb.opcode,
|
|
|
|
&accb->hccb);
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
2005-01-11 01:17:07 +00:00
|
|
|
"AHA-1540A compensation failed\n");
|
1999-01-20 06:21:27 +00:00
|
|
|
xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
|
|
|
|
csio->ccb_h.status = CAM_REQUEUE_REQ;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
case AHASTAT_LINKED_CCB_LUN_MISMATCH:
|
|
|
|
/* We don't even support linked commands... */
|
|
|
|
panic("%s: Linked CCB Lun Mismatch", aha_name(aha));
|
|
|
|
break;
|
|
|
|
case AHASTAT_INVALID_CCB_OR_SG_PARAM:
|
|
|
|
panic("%s: Invalid CCB or SG list", aha_name(aha));
|
|
|
|
break;
|
|
|
|
case AHASTAT_HA_SCSI_BUS_RESET:
|
|
|
|
if ((csio->ccb_h.status & CAM_STATUS_MASK)
|
1999-01-20 06:21:27 +00:00
|
|
|
!= CAM_CMD_TIMEOUT)
|
1998-09-15 07:39:55 +00:00
|
|
|
csio->ccb_h.status = CAM_SCSI_BUS_RESET;
|
|
|
|
break;
|
|
|
|
case AHASTAT_HA_BDR:
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_DEVICE_RESET) == 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
csio->ccb_h.status = CAM_BDR_SENT;
|
|
|
|
else
|
|
|
|
csio->ccb_h.status = CAM_CMD_TIMEOUT;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (csio->ccb_h.status != CAM_REQ_CMP) {
|
|
|
|
xpt_freeze_devq(csio->ccb_h.path, /*count*/1);
|
|
|
|
csio->ccb_h.status |= CAM_DEV_QFRZN;
|
|
|
|
}
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_RELEASE_SIMQ) != 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
1998-11-10 06:44:42 +00:00
|
|
|
case AMBI_OK:
|
1998-09-15 07:39:55 +00:00
|
|
|
/* All completed without incident */
|
|
|
|
/* XXX DO WE NEED TO COPY SENSE BYTES HERE???? XXX */
|
1999-01-20 06:21:27 +00:00
|
|
|
/* I don't think so since it works???? */
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb->ccb_h.status |= CAM_REQ_CMP;
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_RELEASE_SIMQ) != 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
|
1998-11-10 06:44:42 +00:00
|
|
|
ahafreeccb(aha, accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
ahareset(struct aha_softc* aha, int hard_reset)
|
|
|
|
{
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
u_int status;
|
|
|
|
u_int timeout;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint8_t reset_type;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if (hard_reset != 0)
|
|
|
|
reset_type = HARD_RESET;
|
|
|
|
else
|
|
|
|
reset_type = SOFT_RESET;
|
|
|
|
aha_outb(aha, CONTROL_REG, reset_type);
|
|
|
|
|
|
|
|
/* Wait 5sec. for Diagnostic start */
|
|
|
|
timeout = 5 * 10000;
|
|
|
|
while (--timeout) {
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
if ((status & DIAG_ACTIVE) != 0)
|
|
|
|
break;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
if (timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "ahareset - Diagnostic Active failed to "
|
|
|
|
"assert. status = %#x\n", status));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait 10sec. for Diagnostic end */
|
|
|
|
timeout = 10 * 10000;
|
|
|
|
while (--timeout) {
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
if ((status & DIAG_ACTIVE) == 0)
|
|
|
|
break;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
if (timeout == 0) {
|
|
|
|
panic("%s: ahareset - Diagnostic Active failed to drop. "
|
2003-11-09 00:51:52 +00:00
|
|
|
"status = 0x%x\n", aha_name(aha), status);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Wait for the host adapter to become ready or report a failure */
|
|
|
|
timeout = 10000;
|
|
|
|
while (--timeout) {
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
if ((status & (DIAG_FAIL|HA_READY|DATAIN_REG_READY)) != 0)
|
|
|
|
break;
|
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
if (timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "ahareset - Host adapter failed to "
|
|
|
|
"come ready. status = 0x%x\n", status);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If the diagnostics failed, tell the user */
|
|
|
|
if ((status & DIAG_FAIL) != 0
|
|
|
|
|| (status & HA_READY) == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "ahareset - Adapter failed diag\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if ((status & DATAIN_REG_READY) != 0)
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "ahareset - Host Adapter "
|
|
|
|
"Error code = 0x%x\n", aha_inb(aha, DATAIN_REG));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ENXIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* If we've attached to the XPT, tell it about the event */
|
|
|
|
if (aha->path != NULL)
|
|
|
|
xpt_async(AC_BUS_RESET, aha->path, NULL);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Perform completion processing for all outstanding CCBs.
|
|
|
|
*/
|
|
|
|
while ((ccb_h = LIST_FIRST(&aha->pending_ccbs)) != NULL) {
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *pending_accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr;
|
|
|
|
pending_accb->hccb.ahastat = AHASTAT_HA_SCSI_BUS_RESET;
|
|
|
|
ahadone(aha, pending_accb, AMBI_ERROR);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
2003-11-09 17:16:39 +00:00
|
|
|
/* If we've allocated mailboxes, initialize them */
|
|
|
|
/* Must be done after we've aborted our queue, or aha_cmd fails */
|
|
|
|
if (aha->init_level > 4)
|
|
|
|
ahainitmboxes(aha);
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send a command to the adapter.
|
|
|
|
*/
|
|
|
|
int
|
2003-11-09 20:02:47 +00:00
|
|
|
aha_cmd(struct aha_softc *aha, aha_op_t opcode, uint8_t *params,
|
|
|
|
u_int param_len, uint8_t *reply_data, u_int reply_len,
|
1999-05-25 20:15:20 +00:00
|
|
|
u_int cmd_timeout)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
u_int timeout;
|
|
|
|
u_int status;
|
1999-05-25 20:15:20 +00:00
|
|
|
u_int saved_status;
|
1998-09-15 07:39:55 +00:00
|
|
|
u_int intstat;
|
|
|
|
u_int reply_buf_size;
|
1998-12-13 00:05:04 +00:00
|
|
|
int cmd_complete;
|
1999-05-25 20:15:20 +00:00
|
|
|
int error;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* No data returned to start */
|
|
|
|
reply_buf_size = reply_len;
|
|
|
|
reply_len = 0;
|
|
|
|
intstat = 0;
|
1998-12-13 00:05:04 +00:00
|
|
|
cmd_complete = 0;
|
1999-05-25 20:15:20 +00:00
|
|
|
saved_status = 0;
|
|
|
|
error = 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* All commands except for the "start mailbox" and the "enable
|
|
|
|
* outgoing mailbox read interrupt" commands cannot be issued
|
|
|
|
* while there are pending transactions. Freeze our SIMQ
|
|
|
|
* and wait for all completions to occur if necessary.
|
|
|
|
*/
|
2003-11-09 17:16:39 +00:00
|
|
|
timeout = 10000;
|
1999-05-25 20:15:20 +00:00
|
|
|
while (LIST_FIRST(&aha->pending_ccbs) != NULL && --timeout) {
|
|
|
|
/* Fire the interrupt handler in case interrupts are blocked */
|
|
|
|
aha_intr(aha);
|
2003-11-09 17:16:39 +00:00
|
|
|
DELAY(10);
|
1999-05-25 20:15:20 +00:00
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1999-05-25 20:15:20 +00:00
|
|
|
if (timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"aha_cmd: Timeout waiting for adapter idle\n");
|
1999-05-25 20:15:20 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
1998-09-15 07:39:55 +00:00
|
|
|
aha->command_cmp = 0;
|
|
|
|
/*
|
1999-05-25 20:15:20 +00:00
|
|
|
* Wait up to 10 sec. for the adapter to become
|
1998-09-15 07:39:55 +00:00
|
|
|
* ready to accept commands.
|
|
|
|
*/
|
1999-05-25 20:15:20 +00:00
|
|
|
timeout = 100000;
|
1998-09-15 07:39:55 +00:00
|
|
|
while (--timeout) {
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
2003-11-09 00:51:52 +00:00
|
|
|
if ((status & HA_READY) != 0 && (status & CMD_REG_BUSY) == 0)
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
1999-05-25 20:15:20 +00:00
|
|
|
/*
|
|
|
|
* Throw away any pending data which may be
|
|
|
|
* left over from earlier commands that we
|
|
|
|
* timedout on.
|
|
|
|
*/
|
|
|
|
if ((status & DATAIN_REG_READY) != 0)
|
|
|
|
(void)aha_inb(aha, DATAIN_REG);
|
1998-09-15 07:39:55 +00:00
|
|
|
DELAY(100);
|
|
|
|
}
|
|
|
|
if (timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "aha_cmd: Timeout waiting for adapter"
|
|
|
|
" ready, status = 0x%x\n", status);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Send the opcode followed by any necessary parameter bytes.
|
|
|
|
*/
|
|
|
|
aha_outb(aha, COMMAND_REG, opcode);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Wait for up to 1sec to get the parameter list sent
|
|
|
|
*/
|
|
|
|
timeout = 10000;
|
|
|
|
while (param_len && --timeout) {
|
|
|
|
DELAY(100);
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
intstat = aha_inb(aha, INTSTAT_REG);
|
1999-05-25 20:15:20 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
if ((intstat & (INTR_PENDING|CMD_COMPLETE))
|
1998-12-13 00:05:04 +00:00
|
|
|
== (INTR_PENDING|CMD_COMPLETE)) {
|
1999-05-25 20:15:20 +00:00
|
|
|
saved_status = status;
|
1998-12-13 00:05:04 +00:00
|
|
|
cmd_complete = 1;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
1998-12-13 00:05:04 +00:00
|
|
|
}
|
1999-05-25 20:15:20 +00:00
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
if (aha->command_cmp != 0) {
|
1999-05-25 20:15:20 +00:00
|
|
|
saved_status = aha->latched_status;
|
1998-12-13 00:05:04 +00:00
|
|
|
cmd_complete = 1;
|
1998-09-15 07:39:55 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
if ((status & DATAIN_REG_READY) != 0)
|
|
|
|
break;
|
|
|
|
if ((status & CMD_REG_BUSY) == 0) {
|
|
|
|
aha_outb(aha, COMMAND_REG, *params++);
|
|
|
|
param_len--;
|
1999-05-25 20:15:20 +00:00
|
|
|
timeout = 10000;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "aha_cmd: Timeout sending parameters, "
|
|
|
|
"status = 0x%x\n", status);
|
1999-05-25 20:15:20 +00:00
|
|
|
error = ETIMEDOUT;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* For all other commands, we wait for any output data
|
|
|
|
* and the final comand completion interrupt.
|
|
|
|
*/
|
1998-12-13 00:05:04 +00:00
|
|
|
while (cmd_complete == 0 && --cmd_timeout) {
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
intstat = aha_inb(aha, INTSTAT_REG);
|
|
|
|
|
|
|
|
if (aha->command_cmp != 0) {
|
1999-05-25 20:15:20 +00:00
|
|
|
cmd_complete = 1;
|
|
|
|
saved_status = aha->latched_status;
|
|
|
|
} else if ((intstat & (INTR_PENDING|CMD_COMPLETE))
|
|
|
|
== (INTR_PENDING|CMD_COMPLETE)) {
|
|
|
|
/*
|
|
|
|
* Our poll (in case interrupts are blocked)
|
|
|
|
* saw the CMD_COMPLETE interrupt.
|
|
|
|
*/
|
|
|
|
cmd_complete = 1;
|
|
|
|
saved_status = status;
|
1999-10-02 17:40:07 +00:00
|
|
|
}
|
|
|
|
if ((status & DATAIN_REG_READY) != 0) {
|
2003-11-09 00:51:52 +00:00
|
|
|
uint8_t data;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
data = aha_inb(aha, DATAIN_REG);
|
|
|
|
if (reply_len < reply_buf_size) {
|
|
|
|
*reply_data++ = data;
|
|
|
|
} else {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"aha_cmd - Discarded reply data "
|
|
|
|
"byte for opcode 0x%x\n", opcode);
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
1999-05-25 20:15:20 +00:00
|
|
|
/*
|
|
|
|
* Reset timeout to ensure at least a second
|
|
|
|
* between response bytes.
|
|
|
|
*/
|
|
|
|
cmd_timeout = MAX(cmd_timeout, 10000);
|
1998-09-15 07:39:55 +00:00
|
|
|
reply_len++;
|
|
|
|
}
|
|
|
|
DELAY(100);
|
|
|
|
}
|
1999-05-25 20:15:20 +00:00
|
|
|
if (cmd_timeout == 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "aha_cmd: Timeout: status = 0x%x, "
|
|
|
|
"intstat = 0x%x, reply_len = %d\n", status, intstat,
|
|
|
|
reply_len);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (ETIMEDOUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Clear any pending interrupts. Block interrupts so our
|
|
|
|
* interrupt handler is not re-entered.
|
|
|
|
*/
|
|
|
|
aha_intr(aha);
|
2003-11-09 20:02:47 +00:00
|
|
|
|
1999-05-25 20:15:20 +00:00
|
|
|
if (error != 0)
|
|
|
|
return (error);
|
|
|
|
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
|
|
|
* If the command was rejected by the controller, tell the caller.
|
|
|
|
*/
|
1999-05-25 20:15:20 +00:00
|
|
|
if ((saved_status & CMD_INVALID) != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "Invalid Command 0x%x\n", opcode));
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
|
|
|
* Some early adapters may not recover properly from
|
|
|
|
* an invalid command. If it appears that the controller
|
|
|
|
* has wedged (i.e. status was not cleared by our interrupt
|
|
|
|
* reset above), perform a soft reset.
|
|
|
|
*/
|
|
|
|
DELAY(1000);
|
|
|
|
status = aha_inb(aha, STATUS_REG);
|
|
|
|
if ((status & (CMD_INVALID|STATUS_REG_RSVD|DATAIN_REG_READY|
|
|
|
|
CMD_REG_BUSY|DIAG_FAIL|DIAG_ACTIVE)) != 0
|
|
|
|
|| (status & (HA_READY|INIT_REQUIRED))
|
2003-11-09 00:51:52 +00:00
|
|
|
!= (HA_READY|INIT_REQUIRED))
|
1998-10-01 04:53:55 +00:00
|
|
|
ahareset(aha, /*hard_reset*/FALSE);
|
1998-09-15 07:39:55 +00:00
|
|
|
return (EINVAL);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (param_len > 0) {
|
|
|
|
/* The controller did not accept the full argument list */
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "Controller did not accept full argument "
|
|
|
|
"list (%d > 0)\n", param_len));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (E2BIG);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (reply_len != reply_buf_size) {
|
|
|
|
/* Too much or too little data received */
|
2003-11-13 04:14:53 +00:00
|
|
|
PRVERB((aha->dev, "data received mismatch (%d != %d)\n",
|
|
|
|
reply_len, reply_buf_size));
|
1998-09-15 07:39:55 +00:00
|
|
|
return (EMSGSIZE);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* We were successful */
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2003-11-09 20:02:47 +00:00
|
|
|
ahainitmboxes(struct aha_softc *aha)
|
1998-09-15 07:39:55 +00:00
|
|
|
{
|
|
|
|
int error;
|
|
|
|
init_24b_mbox_params_t init_mbox;
|
|
|
|
|
|
|
|
bzero(aha->in_boxes, sizeof(aha_mbox_in_t) * aha->num_boxes);
|
|
|
|
bzero(aha->out_boxes, sizeof(aha_mbox_out_t) * aha->num_boxes);
|
|
|
|
aha->cur_inbox = aha->in_boxes;
|
|
|
|
aha->last_inbox = aha->in_boxes + aha->num_boxes - 1;
|
|
|
|
aha->cur_outbox = aha->out_boxes;
|
|
|
|
aha->last_outbox = aha->out_boxes + aha->num_boxes - 1;
|
|
|
|
|
|
|
|
/* Tell the adapter about them */
|
|
|
|
init_mbox.num_mboxes = aha->num_boxes;
|
|
|
|
ahautoa24(aha->mailbox_physbase, init_mbox.base_addr);
|
2003-11-09 00:51:52 +00:00
|
|
|
error = aha_cmd(aha, AOP_INITIALIZE_MBOX, (uint8_t *)&init_mbox,
|
|
|
|
/*parmlen*/sizeof(init_mbox), /*reply_buf*/NULL,
|
|
|
|
/*reply_len*/0, DEFAULT_CMD_TIMEOUT);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if (error != 0)
|
|
|
|
printf("ahainitmboxes: Initialization command failed\n");
|
|
|
|
return (error);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Update the XPT's idea of the negotiated transfer
|
|
|
|
* parameters for a particular target.
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
ahafetchtransinfo(struct aha_softc *aha, struct ccb_trans_settings* cts)
|
|
|
|
{
|
|
|
|
setup_data_t setup_info;
|
|
|
|
u_int target;
|
|
|
|
u_int targ_offset;
|
|
|
|
u_int sync_period;
|
|
|
|
int error;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint8_t param;
|
1998-09-15 07:39:55 +00:00
|
|
|
targ_syncinfo_t sync_info;
|
2006-10-31 05:53:29 +00:00
|
|
|
struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
target = cts->ccb_h.target_id;
|
|
|
|
targ_offset = (target & 0x7);
|
|
|
|
|
|
|
|
/*
|
1999-05-14 23:10:25 +00:00
|
|
|
* Inquire Setup Information. This command retreives
|
1999-05-25 20:15:20 +00:00
|
|
|
* the sync info for older models.
|
1998-09-15 07:39:55 +00:00
|
|
|
*/
|
|
|
|
param = sizeof(setup_info);
|
1998-11-10 06:44:42 +00:00
|
|
|
error = aha_cmd(aha, AOP_INQUIRE_SETUP_INFO, ¶m, /*paramlen*/1,
|
2003-11-09 00:51:52 +00:00
|
|
|
(uint8_t*)&setup_info, sizeof(setup_info), DEFAULT_CMD_TIMEOUT);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
if (error != 0) {
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev,
|
|
|
|
"ahafetchtransinfo - Inquire Setup Info Failed %d\n",
|
|
|
|
error);
|
1998-09-15 07:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
sync_info = setup_info.syncinfo[targ_offset];
|
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
if (sync_info.sync == 0)
|
|
|
|
spi->sync_offset = 0;
|
|
|
|
else
|
|
|
|
spi->sync_offset = sync_info.offset;
|
|
|
|
|
|
|
|
spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
|
|
|
|
|
|
|
|
if (aha->boardid >= BOARD_1542CF)
|
|
|
|
sync_period = 1000;
|
|
|
|
else
|
|
|
|
sync_period = 2000;
|
|
|
|
sync_period += 500 * sync_info.period;
|
|
|
|
|
|
|
|
/* Convert ns value to standard SCSI sync rate */
|
|
|
|
if (spi->sync_offset != 0)
|
|
|
|
spi->sync_period = scsi_calc_syncparam(sync_period);
|
|
|
|
else
|
|
|
|
spi->sync_period = 0;
|
|
|
|
|
|
|
|
spi->valid = CTS_SPI_VALID_SYNC_RATE
|
|
|
|
| CTS_SPI_VALID_SYNC_OFFSET
|
|
|
|
| CTS_SPI_VALID_BUS_WIDTH;
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_async(AC_TRANSFER_NEG, cts->ccb_h.path, cts);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahamapmboxes(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
struct aha_softc* aha;
|
|
|
|
|
|
|
|
aha = (struct aha_softc*)arg;
|
|
|
|
aha->mailbox_physbase = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahamapccbs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
struct aha_softc* aha;
|
|
|
|
|
|
|
|
aha = (struct aha_softc*)arg;
|
|
|
|
aha->aha_ccb_physbase = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahamapsgs(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
|
|
|
|
struct aha_softc* aha;
|
|
|
|
|
|
|
|
aha = (struct aha_softc*)arg;
|
|
|
|
SLIST_FIRST(&aha->sg_maps)->sg_physaddr = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
ahapoll(struct cam_sim *sim)
|
|
|
|
{
|
2012-10-15 15:59:13 +00:00
|
|
|
aha_intr_locked(cam_sim_softc(sim));
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
1999-04-11 02:55:52 +00:00
|
|
|
static void
|
1998-09-15 07:39:55 +00:00
|
|
|
ahatimeout(void *arg)
|
|
|
|
{
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
union ccb *ccb;
|
|
|
|
struct aha_softc *aha;
|
2003-11-09 00:51:52 +00:00
|
|
|
uint32_t paddr;
|
2003-11-09 17:16:39 +00:00
|
|
|
struct ccb_hdr *ccb_h;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
accb = (struct aha_ccb *)arg;
|
|
|
|
ccb = accb->ccb;
|
1998-09-15 07:39:55 +00:00
|
|
|
aha = (struct aha_softc *)ccb->ccb_h.ccb_aha_ptr;
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_assert(&aha->lock, MA_OWNED);
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
1998-11-10 06:44:42 +00:00
|
|
|
printf("CCB %p - timed out\n", (void *)accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_ACTIVE) == 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
1998-09-17 00:08:29 +00:00
|
|
|
printf("CCB %p - timed out CCB already completed\n",
|
2003-11-09 00:51:52 +00:00
|
|
|
(void *)accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* In order to simplify the recovery process, we ask the XPT
|
|
|
|
* layer to halt the queue of new transactions and we traverse
|
|
|
|
* the list of pending CCBs and remove their timeouts. This
|
|
|
|
* means that the driver attempts to clear only one error
|
|
|
|
* condition at a time. In general, timeouts that occur
|
|
|
|
* close together are related anyway, so there is no benefit
|
|
|
|
* in attempting to handle errors in parrallel. Timeouts will
|
|
|
|
* be reinstated when the recovery process ends.
|
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_DEVICE_RESET) == 0) {
|
|
|
|
if ((accb->flags & ACCB_RELEASE_SIMQ) == 0) {
|
1998-09-15 07:39:55 +00:00
|
|
|
xpt_freeze_simq(aha->sim, /*count*/1);
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->flags |= ACCB_RELEASE_SIMQ;
|
1998-09-15 07:39:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
ccb_h = LIST_FIRST(&aha->pending_ccbs);
|
|
|
|
while (ccb_h != NULL) {
|
1998-11-10 06:44:42 +00:00
|
|
|
struct aha_ccb *pending_accb;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
pending_accb = (struct aha_ccb *)ccb_h->ccb_accb_ptr;
|
2012-10-15 15:59:13 +00:00
|
|
|
callout_stop(&pending_accb->timer);
|
1998-09-15 07:39:55 +00:00
|
|
|
ccb_h = LIST_NEXT(ccb_h, sim_links.le);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
1998-11-10 06:44:42 +00:00
|
|
|
if ((accb->flags & ACCB_DEVICE_RESET) != 0
|
|
|
|
|| aha->cur_outbox->action_code != AMBO_FREE) {
|
1998-09-15 07:39:55 +00:00
|
|
|
/*
|
|
|
|
* Try a full host adapter/SCSI bus reset.
|
|
|
|
* We do this only if we have already attempted
|
|
|
|
* to clear the condition with a BDR, or we cannot
|
|
|
|
* attempt a BDR for lack of mailbox resources.
|
|
|
|
*/
|
|
|
|
ccb->ccb_h.status = CAM_CMD_TIMEOUT;
|
|
|
|
ahareset(aha, /*hardreset*/TRUE);
|
2003-11-13 04:14:53 +00:00
|
|
|
device_printf(aha->dev, "No longer in timeout\n");
|
1998-09-15 07:39:55 +00:00
|
|
|
} else {
|
2003-11-09 20:02:47 +00:00
|
|
|
/*
|
1998-09-15 07:39:55 +00:00
|
|
|
* Send a Bus Device Reset message:
|
|
|
|
* The target that is holding up the bus may not
|
|
|
|
* be the same as the one that triggered this timeout
|
|
|
|
* (different commands have different timeout lengths),
|
|
|
|
* but we have no way of determining this from our
|
|
|
|
* timeout handler. Our strategy here is to queue a
|
|
|
|
* BDR message to the target of the timed out command.
|
|
|
|
* If this fails, we'll get another timeout 2 seconds
|
|
|
|
* later which will attempt a bus reset.
|
|
|
|
*/
|
1998-11-10 06:44:42 +00:00
|
|
|
accb->flags |= ACCB_DEVICE_RESET;
|
2012-10-16 08:40:09 +00:00
|
|
|
callout_reset(&accb->timer, 2 * hz, ahatimeout, accb);
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->recovery_accb->hccb.opcode = INITIATOR_BUS_DEV_RESET;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* No Data Transfer */
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->recovery_accb->hccb.datain = TRUE;
|
|
|
|
aha->recovery_accb->hccb.dataout = TRUE;
|
|
|
|
aha->recovery_accb->hccb.ahastat = 0;
|
|
|
|
aha->recovery_accb->hccb.sdstat = 0;
|
|
|
|
aha->recovery_accb->hccb.target = ccb->ccb_h.target_id;
|
1998-09-15 07:39:55 +00:00
|
|
|
|
|
|
|
/* Tell the adapter about this command */
|
1998-11-10 06:44:42 +00:00
|
|
|
paddr = ahaccbvtop(aha, aha->recovery_accb);
|
1998-09-15 07:39:55 +00:00
|
|
|
ahautoa24(paddr, aha->cur_outbox->ccb_addr);
|
1998-11-10 06:44:42 +00:00
|
|
|
aha->cur_outbox->action_code = AMBO_START;
|
|
|
|
aha_outb(aha, COMMAND_REG, AOP_START_MBOX);
|
1998-09-15 07:39:55 +00:00
|
|
|
ahanextoutbox(aha);
|
|
|
|
}
|
|
|
|
}
|
2000-01-24 07:08:40 +00:00
|
|
|
|
|
|
|
int
|
|
|
|
aha_detach(struct aha_softc *aha)
|
|
|
|
{
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_lock(&aha->lock);
|
2000-01-24 07:08:40 +00:00
|
|
|
xpt_async(AC_LOST_DEVICE, aha->path, NULL);
|
|
|
|
xpt_free_path(aha->path);
|
|
|
|
xpt_bus_deregister(cam_sim_path(aha->sim));
|
|
|
|
cam_sim_free(aha->sim, /*free_devq*/TRUE);
|
2012-10-15 15:59:13 +00:00
|
|
|
mtx_unlock(&aha->lock);
|
|
|
|
/* XXX: Drain all timers? */
|
2000-01-24 07:08:40 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2006-12-11 18:28:31 +00:00
|
|
|
MODULE_DEPEND(aha, cam, 1, 1, 1);
|