2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1998-09-15 07:03:43 +00:00
|
|
|
* Generic driver for the Advanced Systems Inc. SCSI controllers
|
|
|
|
* Product specific probe and attach routines can be found in:
|
|
|
|
*
|
|
|
|
* i386/isa/adv_isa.c ABP5140, ABP542, ABP5150, ABP842, ABP852
|
|
|
|
* i386/eisa/adv_eisa.c ABP742, ABP752
|
|
|
|
* pci/adv_pci.c ABP920, ABP930, ABP930U, ABP930UA, ABP940, ABP940U,
|
|
|
|
* ABP940UA, ABP950, ABP960, ABP960U, ABP960UA,
|
|
|
|
* ABP970, ABP970U
|
|
|
|
*
|
2000-01-14 03:33:38 +00:00
|
|
|
* Copyright (c) 1996-2000 Justin Gibbs.
|
1998-09-15 07:03:43 +00:00
|
|
|
* 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.
|
|
|
|
*/
|
2005-01-06 01:43:34 +00:00
|
|
|
/*-
|
1998-09-15 07:03:43 +00:00
|
|
|
* Ported from:
|
|
|
|
* advansys.c - Linux Host Driver for AdvanSys SCSI Adapters
|
|
|
|
*
|
|
|
|
* Copyright (c) 1995-1997 Advanced System Products, Inc.
|
|
|
|
* All Rights Reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that redistributions of source
|
|
|
|
* code retain the above copyright notice and this comment without
|
|
|
|
* modification.
|
|
|
|
*/
|
2003-08-24 17:55:58 +00:00
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
__FBSDID("$FreeBSD$");
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
#include <sys/param.h>
|
2012-10-12 21:31:44 +00:00
|
|
|
#include <sys/conf.h>
|
1998-09-15 07:03:43 +00:00
|
|
|
#include <sys/systm.h>
|
|
|
|
#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>
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
#include <machine/bus.h>
|
2000-04-07 11:32:42 +00:00
|
|
|
#include <machine/resource.h>
|
|
|
|
#include <sys/bus.h>
|
|
|
|
#include <sys/rman.h>
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
#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_all.h>
|
|
|
|
#include <cam/scsi/scsi_message.h>
|
|
|
|
|
|
|
|
#include <vm/vm.h>
|
|
|
|
#include <vm/vm_param.h>
|
|
|
|
#include <vm/pmap.h>
|
|
|
|
|
|
|
|
#include <dev/advansys/advansys.h>
|
|
|
|
|
|
|
|
static void adv_action(struct cam_sim *sim, union ccb *ccb);
|
|
|
|
static void adv_execute_ccb(void *arg, bus_dma_segment_t *dm_segs,
|
|
|
|
int nsegments, int error);
|
2012-10-12 21:31:44 +00:00
|
|
|
static void adv_intr_locked(struct adv_softc *adv);
|
1998-09-15 07:03:43 +00:00
|
|
|
static void adv_poll(struct cam_sim *sim);
|
|
|
|
static void adv_run_doneq(struct adv_softc *adv);
|
|
|
|
static struct adv_ccb_info *
|
|
|
|
adv_alloc_ccb_info(struct adv_softc *adv);
|
|
|
|
static void adv_destroy_ccb_info(struct adv_softc *adv,
|
1998-10-15 23:47:14 +00:00
|
|
|
struct adv_ccb_info *cinfo);
|
1998-09-15 07:03:43 +00:00
|
|
|
static __inline struct adv_ccb_info *
|
|
|
|
adv_get_ccb_info(struct adv_softc *adv);
|
|
|
|
static __inline void adv_free_ccb_info(struct adv_softc *adv,
|
|
|
|
struct adv_ccb_info *cinfo);
|
2000-01-14 03:33:38 +00:00
|
|
|
static __inline void adv_set_state(struct adv_softc *adv, adv_state state);
|
|
|
|
static __inline void adv_clear_state(struct adv_softc *adv, union ccb* ccb);
|
|
|
|
static void adv_clear_state_really(struct adv_softc *adv, union ccb* ccb);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
static __inline struct adv_ccb_info *
|
|
|
|
adv_get_ccb_info(struct adv_softc *adv)
|
|
|
|
{
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
if ((cinfo = SLIST_FIRST(&adv->free_ccb_infos)) != NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&adv->free_ccb_infos, links);
|
|
|
|
} else {
|
|
|
|
cinfo = adv_alloc_ccb_info(adv);
|
|
|
|
}
|
|
|
|
|
|
|
|
return (cinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
adv_free_ccb_info(struct adv_softc *adv, struct adv_ccb_info *cinfo)
|
|
|
|
{
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
cinfo->state = ACCB_FREE;
|
|
|
|
SLIST_INSERT_HEAD(&adv->free_ccb_infos, cinfo, links);
|
|
|
|
}
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
static __inline void
|
|
|
|
adv_set_state(struct adv_softc *adv, adv_state state)
|
|
|
|
{
|
|
|
|
if (adv->state == 0)
|
|
|
|
xpt_freeze_simq(adv->sim, /*count*/1);
|
|
|
|
adv->state |= state;
|
|
|
|
}
|
|
|
|
|
|
|
|
static __inline void
|
|
|
|
adv_clear_state(struct adv_softc *adv, union ccb* ccb)
|
|
|
|
{
|
|
|
|
if (adv->state != 0)
|
|
|
|
adv_clear_state_really(adv, ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_clear_state_really(struct adv_softc *adv, union ccb* ccb)
|
|
|
|
{
|
2012-10-12 21:31:44 +00:00
|
|
|
|
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
2000-01-14 03:33:38 +00:00
|
|
|
if ((adv->state & ADV_BUSDMA_BLOCK_CLEARED) != 0)
|
|
|
|
adv->state &= ~(ADV_BUSDMA_BLOCK_CLEARED|ADV_BUSDMA_BLOCK);
|
|
|
|
if ((adv->state & ADV_RESOURCE_SHORTAGE) != 0) {
|
|
|
|
int openings;
|
|
|
|
|
|
|
|
openings = adv->max_openings - adv->cur_active - ADV_MIN_FREE_Q;
|
|
|
|
if (openings >= adv->openings_needed) {
|
|
|
|
adv->state &= ~ADV_RESOURCE_SHORTAGE;
|
|
|
|
adv->openings_needed = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((adv->state & ADV_IN_TIMEOUT) != 0) {
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
|
|
|
|
cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr;
|
|
|
|
if ((cinfo->state & ACCB_RECOVERY_CCB) != 0) {
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* We now traverse our list of pending CCBs
|
|
|
|
* and reinstate their timeouts.
|
|
|
|
*/
|
|
|
|
ccb_h = LIST_FIRST(&adv->pending_ccbs);
|
|
|
|
while (ccb_h != NULL) {
|
2012-10-12 21:31:44 +00:00
|
|
|
cinfo = ccb_h->ccb_cinfo_ptr;
|
2014-11-21 21:01:24 +00:00
|
|
|
callout_reset_sbt(&cinfo->timer,
|
|
|
|
SBT_1MS * ccb_h->timeout, 0,
|
|
|
|
adv_timeout, ccb_h, 0);
|
2000-01-14 03:33:38 +00:00
|
|
|
ccb_h = LIST_NEXT(ccb_h, sim_links.le);
|
|
|
|
}
|
|
|
|
adv->state &= ~ADV_IN_TIMEOUT;
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev, "No longer in timeout\n");
|
2000-01-14 03:33:38 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
if (adv->state == 0)
|
|
|
|
ccb->ccb_h.status |= CAM_RELEASE_SIMQ;
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
void
|
|
|
|
adv_map(void *arg, bus_dma_segment_t *segs, int nseg, int error)
|
|
|
|
{
|
|
|
|
bus_addr_t* physaddr;
|
|
|
|
|
|
|
|
physaddr = (bus_addr_t*)arg;
|
|
|
|
*physaddr = segs->ds_addr;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_action(struct cam_sim *sim, union ccb *ccb)
|
|
|
|
{
|
|
|
|
struct adv_softc *adv;
|
|
|
|
|
|
|
|
CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("adv_action\n"));
|
|
|
|
|
|
|
|
adv = (struct adv_softc *)cam_sim_softc(sim);
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
switch (ccb->ccb_h.func_code) {
|
|
|
|
/* Common cases first */
|
|
|
|
case XPT_SCSI_IO: /* Execute the requested I/O operation */
|
|
|
|
{
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
struct adv_ccb_info *cinfo;
|
2013-02-12 16:57:20 +00:00
|
|
|
int error;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
ccb_h = &ccb->ccb_h;
|
|
|
|
csio = &ccb->csio;
|
|
|
|
cinfo = adv_get_ccb_info(adv);
|
|
|
|
if (cinfo == NULL)
|
|
|
|
panic("XXX Handle CCB info error!!!");
|
|
|
|
|
|
|
|
ccb_h->ccb_cinfo_ptr = cinfo;
|
2000-01-14 03:33:38 +00:00
|
|
|
cinfo->ccb = ccb;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2013-02-12 16:57:20 +00:00
|
|
|
error = bus_dmamap_load_ccb(adv->buffer_dmat,
|
|
|
|
cinfo->dmamap,
|
|
|
|
ccb,
|
|
|
|
adv_execute_ccb,
|
|
|
|
csio, /*flags*/0);
|
|
|
|
if (error == EINPROGRESS) {
|
|
|
|
/*
|
|
|
|
* So as to maintain ordering, freeze the controller
|
|
|
|
* queue until our mapping is returned.
|
|
|
|
*/
|
|
|
|
adv_set_state(adv, ADV_BUSDMA_BLOCK);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
|
|
|
|
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_EN_LUN: /* Enable LUN as a target */
|
|
|
|
case XPT_ABORT: /* Abort the specified CCB */
|
|
|
|
/* XXX Implement */
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
2006-10-31 05:53:29 +00:00
|
|
|
#define IS_CURRENT_SETTINGS(c) (c->type == CTS_TYPE_CURRENT_SETTINGS)
|
|
|
|
#define IS_USER_SETTINGS(c) (c->type == CTS_TYPE_USER_SETTINGS)
|
1998-09-15 07:03:43 +00:00
|
|
|
case XPT_SET_TRAN_SETTINGS:
|
|
|
|
{
|
2006-10-31 05:53:29 +00:00
|
|
|
struct ccb_trans_settings_scsi *scsi;
|
|
|
|
struct ccb_trans_settings_spi *spi;
|
1998-09-15 07:03:43 +00:00
|
|
|
struct ccb_trans_settings *cts;
|
|
|
|
target_bit_vector targ_mask;
|
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
|
|
|
struct adv_transinfo *tconf;
|
1998-09-15 07:03:43 +00:00
|
|
|
u_int update_type;
|
|
|
|
|
|
|
|
cts = &ccb->cts;
|
|
|
|
targ_mask = ADV_TID_TO_TARGET_MASK(cts->ccb_h.target_id);
|
|
|
|
update_type = 0;
|
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
|
|
|
|
|
|
|
/*
|
|
|
|
* The user must specify which type of settings he wishes
|
|
|
|
* to change.
|
|
|
|
*/
|
2006-10-31 05:53:29 +00:00
|
|
|
if (IS_CURRENT_SETTINGS(cts) && !IS_USER_SETTINGS(cts)) {
|
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
|
|
|
tconf = &adv->tinfo[cts->ccb_h.target_id].current;
|
1998-09-15 07:03:43 +00:00
|
|
|
update_type |= ADV_TRANS_GOAL;
|
2006-10-31 05:53:29 +00:00
|
|
|
} else if (IS_USER_SETTINGS(cts) && !IS_CURRENT_SETTINGS(cts)) {
|
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
|
|
|
tconf = &adv->tinfo[cts->ccb_h.target_id].user;
|
1998-09-15 07:03:43 +00:00
|
|
|
update_type |= ADV_TRANS_USER;
|
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
|
|
|
} else {
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
break;
|
|
|
|
}
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
scsi = &cts->proto_specific.scsi;
|
|
|
|
spi = &cts->xport_specific.spi;
|
|
|
|
if ((update_type & ADV_TRANS_GOAL) != 0) {
|
|
|
|
if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
|
|
|
|
if ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) != 0)
|
|
|
|
adv->disc_enable |= targ_mask;
|
|
|
|
else
|
|
|
|
adv->disc_enable &= ~targ_mask;
|
|
|
|
adv_write_lram_8(adv, ADVV_DISC_ENABLE_B,
|
|
|
|
adv->disc_enable);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
|
|
|
|
if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
|
|
|
|
adv->cmd_qng_enabled |= targ_mask;
|
|
|
|
else
|
|
|
|
adv->cmd_qng_enabled &= ~targ_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((update_type & ADV_TRANS_USER) != 0) {
|
|
|
|
if ((spi->valid & CTS_SPI_VALID_DISC) != 0) {
|
|
|
|
if ((spi->flags & CTS_SPI_VALID_DISC) != 0)
|
|
|
|
adv->user_disc_enable |= targ_mask;
|
|
|
|
else
|
|
|
|
adv->user_disc_enable &= ~targ_mask;
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((scsi->valid & CTS_SCSI_VALID_TQ) != 0) {
|
|
|
|
if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0)
|
|
|
|
adv->user_cmd_qng_enabled |= targ_mask;
|
|
|
|
else
|
|
|
|
adv->user_cmd_qng_enabled &= ~targ_mask;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If the user specifies either the sync rate, or offset,
|
|
|
|
* but not both, the unspecified parameter defaults to its
|
|
|
|
* current value in transfer negotiations.
|
|
|
|
*/
|
|
|
|
if (((spi->valid & CTS_SPI_VALID_SYNC_RATE) != 0)
|
|
|
|
|| ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0)) {
|
|
|
|
/*
|
|
|
|
* If the user provided a sync rate but no offset,
|
|
|
|
* use the current offset.
|
|
|
|
*/
|
|
|
|
if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0)
|
|
|
|
spi->sync_offset = tconf->offset;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
/*
|
|
|
|
* If the user provided an offset but no sync rate,
|
|
|
|
* use the current sync rate.
|
|
|
|
*/
|
|
|
|
if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0)
|
|
|
|
spi->sync_period = tconf->period;
|
|
|
|
|
|
|
|
adv_period_offset_to_sdtr(adv, &spi->sync_period,
|
|
|
|
&spi->sync_offset,
|
|
|
|
cts->ccb_h.target_id);
|
|
|
|
|
|
|
|
adv_set_syncrate(adv, /*struct cam_path */NULL,
|
|
|
|
cts->ccb_h.target_id, spi->sync_period,
|
|
|
|
spi->sync_offset, update_type);
|
|
|
|
}
|
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
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
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_scsi *scsi;
|
|
|
|
struct ccb_trans_settings_spi *spi;
|
1998-09-15 07:03:43 +00:00
|
|
|
struct ccb_trans_settings *cts;
|
|
|
|
struct adv_transinfo *tconf;
|
|
|
|
target_bit_vector target_mask;
|
|
|
|
|
|
|
|
cts = &ccb->cts;
|
|
|
|
target_mask = ADV_TID_TO_TARGET_MASK(cts->ccb_h.target_id);
|
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
scsi = &cts->proto_specific.scsi;
|
|
|
|
spi = &cts->xport_specific.spi;
|
|
|
|
|
|
|
|
cts->protocol = PROTO_SCSI;
|
|
|
|
cts->protocol_version = SCSI_REV_2;
|
|
|
|
cts->transport = XPORT_SPI;
|
|
|
|
cts->transport_version = 2;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2006-10-31 05:53:29 +00:00
|
|
|
scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB;
|
|
|
|
spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
|
|
|
|
if (cts->type == CTS_TYPE_CURRENT_SETTINGS) {
|
|
|
|
tconf = &adv->tinfo[cts->ccb_h.target_id].current;
|
|
|
|
if ((adv->disc_enable & target_mask) != 0)
|
|
|
|
spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
if ((adv->cmd_qng_enabled & target_mask) != 0)
|
|
|
|
scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
|
|
|
|
} else {
|
|
|
|
tconf = &adv->tinfo[cts->ccb_h.target_id].user;
|
|
|
|
if ((adv->user_disc_enable & target_mask) != 0)
|
|
|
|
spi->flags |= CTS_SPI_FLAGS_DISC_ENB;
|
|
|
|
if ((adv->user_cmd_qng_enabled & target_mask) != 0)
|
|
|
|
scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB;
|
|
|
|
}
|
|
|
|
spi->sync_period = tconf->period;
|
|
|
|
spi->sync_offset = tconf->offset;
|
|
|
|
spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT;
|
|
|
|
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;
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_CALC_GEOMETRY:
|
|
|
|
{
|
|
|
|
int extended;
|
|
|
|
|
|
|
|
extended = (adv->control & ADV_CNTL_BIOS_GT_1GB) != 0;
|
2003-06-14 22:17:41 +00:00
|
|
|
cam_calc_geometry(&ccb->ccg, extended);
|
1998-09-15 07:03:43 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case XPT_RESET_BUS: /* Reset the specified SCSI bus */
|
|
|
|
{
|
|
|
|
|
|
|
|
adv_stop_execution(adv);
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_reset_bus(adv, /*initiate_reset*/TRUE);
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_start_execution(adv);
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
|
|
|
cpi->version_num = 1; /* XXX??? */
|
|
|
|
cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE;
|
|
|
|
cpi->target_sprt = 0;
|
|
|
|
cpi->hba_misc = 0;
|
|
|
|
cpi->hba_eng_cnt = 0;
|
|
|
|
cpi->max_target = 7;
|
|
|
|
cpi->max_lun = 7;
|
|
|
|
cpi->initiator_id = adv->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;
|
Always null-terminate ccb_pathinq.(sim_vid|hba_vid|dev_name)
The sim_vid, hba_vid, and dev_name fields of struct ccb_pathinq are
fixed-length strings. AFAICT the only place they're read is in
sbin/camcontrol/camcontrol.c, which assumes they'll be null-terminated.
However, the kernel doesn't null-terminate them. A bunch of copy-pasted code
uses strncpy to write them, and doesn't guarantee null-termination. For at
least 4 drivers (mpr, mps, ciss, and hyperv), the hba_vid field actually
overflows. You can see the result by doing "camcontrol negotiate da0 -v".
This change null-terminates those fields everywhere they're set in the
kernel. It also shortens a few strings to ensure they'll fit within the
16-character field.
PR: 215474
Reported by: Coverity
CID: 1009997 1010000 1010001 1010002 1010003 1010004 1010005
CID: 1331519 1010006 1215097 1010007 1288967 1010008 1306000
CID: 1211924 1010009 1010010 1010011 1010012 1010013 1010014
CID: 1147190 1010017 1010016 1010018 1216435 1010020 1010021
CID: 1010022 1009666 1018185 1010023 1010025 1010026 1010027
CID: 1010028 1010029 1010030 1010031 1010033 1018186 1018187
CID: 1010035 1010036 1010042 1010041 1010040 1010039
Reviewed by: imp, sephe, slm
MFC after: 4 weeks
Sponsored by: Spectra Logic Corp
Differential Revision: https://reviews.freebsd.org/D9037
Differential Revision: https://reviews.freebsd.org/D9038
2017-01-04 20:26:42 +00:00
|
|
|
strlcpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
|
|
|
|
strlcpy(cpi->hba_vid, "Advansys", HBA_IDLEN);
|
|
|
|
strlcpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
|
1998-09-15 07:03:43 +00:00
|
|
|
cpi->unit_number = cam_sim_unit(sim);
|
|
|
|
cpi->ccb_h.status = CAM_REQ_CMP;
|
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:03:43 +00:00
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
|
|
|
ccb->ccb_h.status = CAM_REQ_INVALID;
|
|
|
|
xpt_done(ccb);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Currently, the output of bus_dmammap_load suits our needs just
|
|
|
|
* fine, but should it change, we'd need to do something here.
|
|
|
|
*/
|
|
|
|
#define adv_fixup_dmasegs(adv, dm_segs) (struct adv_sg_entry *)(dm_segs)
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_execute_ccb(void *arg, bus_dma_segment_t *dm_segs,
|
|
|
|
int nsegments, int error)
|
|
|
|
{
|
|
|
|
struct ccb_scsiio *csio;
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
struct cam_sim *sim;
|
|
|
|
struct adv_softc *adv;
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
struct adv_scsi_q scsiq;
|
|
|
|
struct adv_sg_head sghead;
|
|
|
|
|
|
|
|
csio = (struct ccb_scsiio *)arg;
|
|
|
|
ccb_h = &csio->ccb_h;
|
|
|
|
sim = xpt_path_sim(ccb_h->path);
|
|
|
|
adv = (struct adv_softc *)cam_sim_softc(sim);
|
|
|
|
cinfo = (struct adv_ccb_info *)csio->ccb_h.ccb_cinfo_ptr;
|
2012-10-12 21:31:44 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
/*
|
|
|
|
* Setup our done routine to release the simq on
|
|
|
|
* the next ccb that completes.
|
|
|
|
*/
|
|
|
|
if ((adv->state & ADV_BUSDMA_BLOCK) != 0)
|
|
|
|
adv->state |= ADV_BUSDMA_BLOCK_CLEARED;
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
if ((ccb_h->flags & CAM_CDB_POINTER) != 0) {
|
|
|
|
if ((ccb_h->flags & CAM_CDB_PHYS) == 0) {
|
|
|
|
/* XXX Need phystovirt!!!! */
|
|
|
|
/* How about pmap_kenter??? */
|
|
|
|
scsiq.cdbptr = csio->cdb_io.cdb_ptr;
|
|
|
|
} else {
|
|
|
|
scsiq.cdbptr = csio->cdb_io.cdb_ptr;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
scsiq.cdbptr = csio->cdb_io.cdb_bytes;
|
|
|
|
}
|
|
|
|
/*
|
|
|
|
* Build up the request
|
|
|
|
*/
|
|
|
|
scsiq.q1.status = 0;
|
|
|
|
scsiq.q1.q_no = 0;
|
|
|
|
scsiq.q1.cntl = 0;
|
|
|
|
scsiq.q1.sg_queue_cnt = 0;
|
|
|
|
scsiq.q1.target_id = ADV_TID_TO_TARGET_MASK(ccb_h->target_id);
|
|
|
|
scsiq.q1.target_lun = ccb_h->target_lun;
|
|
|
|
scsiq.q1.sense_len = csio->sense_len;
|
|
|
|
scsiq.q1.extra_bytes = 0;
|
2000-01-14 03:33:38 +00:00
|
|
|
scsiq.q2.ccb_index = cinfo - adv->ccb_infos;
|
1998-09-15 07:03:43 +00:00
|
|
|
scsiq.q2.target_ix = ADV_TIDLUN_TO_IX(ccb_h->target_id,
|
|
|
|
ccb_h->target_lun);
|
|
|
|
scsiq.q2.flag = 0;
|
|
|
|
scsiq.q2.cdb_len = csio->cdb_len;
|
|
|
|
if ((ccb_h->flags & CAM_TAG_ACTION_VALID) != 0)
|
|
|
|
scsiq.q2.tag_code = csio->tag_action;
|
|
|
|
else
|
|
|
|
scsiq.q2.tag_code = 0;
|
|
|
|
scsiq.q2.vm_id = 0;
|
|
|
|
|
|
|
|
if (nsegments != 0) {
|
2003-05-27 04:59:59 +00:00
|
|
|
bus_dmasync_op_t op;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
scsiq.q1.data_addr = dm_segs->ds_addr;
|
|
|
|
scsiq.q1.data_cnt = dm_segs->ds_len;
|
|
|
|
if (nsegments > 1) {
|
|
|
|
scsiq.q1.cntl |= QC_SG_HEAD;
|
|
|
|
sghead.entry_cnt
|
|
|
|
= sghead.entry_to_copy
|
|
|
|
= nsegments;
|
|
|
|
sghead.res = 0;
|
|
|
|
sghead.sg_list = adv_fixup_dmasegs(adv, dm_segs);
|
|
|
|
scsiq.sg_head = &sghead;
|
|
|
|
} else {
|
|
|
|
scsiq.sg_head = NULL;
|
|
|
|
}
|
|
|
|
if ((ccb_h->flags & CAM_DIR_MASK) == CAM_DIR_IN)
|
|
|
|
op = BUS_DMASYNC_PREREAD;
|
|
|
|
else
|
|
|
|
op = BUS_DMASYNC_PREWRITE;
|
|
|
|
bus_dmamap_sync(adv->buffer_dmat, cinfo->dmamap, op);
|
|
|
|
} else {
|
|
|
|
scsiq.q1.data_addr = 0;
|
|
|
|
scsiq.q1.data_cnt = 0;
|
|
|
|
scsiq.sg_head = NULL;
|
|
|
|
}
|
|
|
|
|
1998-10-07 03:32:57 +00:00
|
|
|
/*
|
|
|
|
* Last time we need to check if this SCB needs to
|
|
|
|
* be aborted.
|
|
|
|
*/
|
|
|
|
if (ccb_h->status != CAM_REQ_INPROG) {
|
2000-01-14 03:33:38 +00:00
|
|
|
if (nsegments != 0)
|
1998-10-07 03:32:57 +00:00
|
|
|
bus_dmamap_unload(adv->buffer_dmat, cinfo->dmamap);
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_clear_state(adv, (union ccb *)csio);
|
1998-10-07 03:32:57 +00:00
|
|
|
adv_free_ccb_info(adv, cinfo);
|
|
|
|
xpt_done((union ccb *)csio);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
if (adv_execute_scsi_queue(adv, &scsiq, csio->dxfer_len) != 0) {
|
|
|
|
/* Temporary resource shortage */
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_set_state(adv, ADV_RESOURCE_SHORTAGE);
|
|
|
|
if (nsegments != 0)
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dmamap_unload(adv->buffer_dmat, cinfo->dmamap);
|
2000-01-14 03:33:38 +00:00
|
|
|
csio->ccb_h.status = CAM_REQUEUE_REQ;
|
|
|
|
adv_clear_state(adv, (union ccb *)csio);
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_free_ccb_info(adv, cinfo);
|
|
|
|
xpt_done((union ccb *)csio);
|
|
|
|
return;
|
|
|
|
}
|
1998-10-07 03:32:57 +00:00
|
|
|
cinfo->state |= ACCB_ACTIVE;
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb_h->status |= CAM_SIM_QUEUED;
|
|
|
|
LIST_INSERT_HEAD(&adv->pending_ccbs, ccb_h, sim_links.le);
|
|
|
|
/* Schedule our timeout */
|
2014-11-21 21:01:24 +00:00
|
|
|
callout_reset_sbt(&cinfo->timer, SBT_1MS * ccb_h->timeout, 0,
|
|
|
|
adv_timeout, csio, 0);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static struct adv_ccb_info *
|
|
|
|
adv_alloc_ccb_info(struct adv_softc *adv)
|
|
|
|
{
|
|
|
|
int error;
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
cinfo = &adv->ccb_infos[adv->ccb_infos_allocated];
|
1998-09-15 07:03:43 +00:00
|
|
|
cinfo->state = ACCB_FREE;
|
2012-10-12 21:31:44 +00:00
|
|
|
callout_init_mtx(&cinfo->timer, &adv->lock, 0);
|
1998-09-15 07:03:43 +00:00
|
|
|
error = bus_dmamap_create(adv->buffer_dmat, /*flags*/0,
|
|
|
|
&cinfo->dmamap);
|
|
|
|
if (error != 0) {
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev, "Unable to allocate CCB info "
|
|
|
|
"dmamap - error %d\n", error);
|
2000-01-14 03:33:38 +00:00
|
|
|
return (NULL);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
2000-01-14 03:33:38 +00:00
|
|
|
adv->ccb_infos_allocated++;
|
1998-09-15 07:03:43 +00:00
|
|
|
return (cinfo);
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
adv_destroy_ccb_info(struct adv_softc *adv, struct adv_ccb_info *cinfo)
|
|
|
|
{
|
2012-10-12 21:31:44 +00:00
|
|
|
|
|
|
|
callout_drain(&cinfo->timer);
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dmamap_destroy(adv->buffer_dmat, cinfo->dmamap);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_timeout(void *arg)
|
|
|
|
{
|
|
|
|
union ccb *ccb;
|
|
|
|
struct adv_softc *adv;
|
2012-10-12 21:31:44 +00:00
|
|
|
struct adv_ccb_info *cinfo, *cinfo2;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
ccb = (union ccb *)arg;
|
|
|
|
adv = (struct adv_softc *)xpt_path_sim(ccb->ccb_h.path)->softc;
|
|
|
|
cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr;
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Timed out\n");
|
|
|
|
|
|
|
|
/* Have we been taken care of already?? */
|
|
|
|
if (cinfo == NULL || cinfo->state == ACCB_FREE) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
adv_stop_execution(adv);
|
|
|
|
|
|
|
|
if ((cinfo->state & ACCB_ABORT_QUEUED) == 0) {
|
|
|
|
struct ccb_hdr *ccb_h;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2016-05-03 03:41:25 +00:00
|
|
|
* in attempting to handle errors in parallel. Timeouts will
|
1998-09-15 07:03:43 +00:00
|
|
|
* be reinstated when the recovery process ends.
|
|
|
|
*/
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_set_state(adv, ADV_IN_TIMEOUT);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/* This CCB is the CCB representing our recovery actions */
|
|
|
|
cinfo->state |= ACCB_RECOVERY_CCB|ACCB_ABORT_QUEUED;
|
|
|
|
|
|
|
|
ccb_h = LIST_FIRST(&adv->pending_ccbs);
|
|
|
|
while (ccb_h != NULL) {
|
2012-10-12 21:31:44 +00:00
|
|
|
cinfo2 = ccb_h->ccb_cinfo_ptr;
|
|
|
|
callout_stop(&cinfo2->timer);
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb_h = LIST_NEXT(ccb_h, sim_links.le);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* XXX Should send a BDR */
|
|
|
|
/* Attempt an abort as our first tact */
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Attempting abort\n");
|
|
|
|
adv_abort_ccb(adv, ccb->ccb_h.target_id,
|
|
|
|
ccb->ccb_h.target_lun, ccb,
|
|
|
|
CAM_CMD_TIMEOUT, /*queued_only*/FALSE);
|
2012-10-12 21:31:44 +00:00
|
|
|
callout_reset(&cinfo->timer, 2 * hz, adv_timeout, ccb);
|
1998-09-15 07:03:43 +00:00
|
|
|
} else {
|
|
|
|
/* Our attempt to perform an abort failed, go for a reset */
|
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("Resetting bus\n");
|
|
|
|
ccb->ccb_h.status &= ~CAM_STATUS_MASK;
|
|
|
|
ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_reset_bus(adv, /*initiate_reset*/TRUE);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
adv_start_execution(adv);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct adv_softc *
|
2012-10-12 21:31:44 +00:00
|
|
|
adv_alloc(device_t dev, struct resource *res, long offset)
|
1998-09-15 07:03:43 +00:00
|
|
|
{
|
2000-04-07 11:32:42 +00:00
|
|
|
struct adv_softc *adv = device_get_softc(dev);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate a storage area for us
|
|
|
|
*/
|
|
|
|
LIST_INIT(&adv->pending_ccbs);
|
|
|
|
SLIST_INIT(&adv->free_ccb_infos);
|
2000-04-07 11:32:42 +00:00
|
|
|
adv->dev = dev;
|
2012-10-12 21:31:44 +00:00
|
|
|
adv->res = res;
|
|
|
|
adv->reg_off = offset;
|
|
|
|
mtx_init(&adv->lock, "adv", NULL, MTX_DEF);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
return(adv);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_free(struct adv_softc *adv)
|
|
|
|
{
|
|
|
|
switch (adv->init_level) {
|
2000-01-14 03:33:38 +00:00
|
|
|
case 6:
|
1998-09-15 07:03:43 +00:00
|
|
|
{
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
|
|
|
|
while ((cinfo = SLIST_FIRST(&adv->free_ccb_infos)) != NULL) {
|
|
|
|
SLIST_REMOVE_HEAD(&adv->free_ccb_infos, links);
|
1998-10-15 23:47:14 +00:00
|
|
|
adv_destroy_ccb_info(adv, cinfo);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bus_dmamap_unload(adv->sense_dmat, adv->sense_dmamap);
|
|
|
|
}
|
2000-01-14 03:33:38 +00:00
|
|
|
case 5:
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dmamem_free(adv->sense_dmat, adv->sense_buffers,
|
|
|
|
adv->sense_dmamap);
|
2000-01-14 03:33:38 +00:00
|
|
|
case 4:
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dma_tag_destroy(adv->sense_dmat);
|
2000-01-14 03:33:38 +00:00
|
|
|
case 3:
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dma_tag_destroy(adv->buffer_dmat);
|
2000-01-14 03:33:38 +00:00
|
|
|
case 2:
|
1998-09-15 07:03:43 +00:00
|
|
|
bus_dma_tag_destroy(adv->parent_dmat);
|
2000-01-14 03:33:38 +00:00
|
|
|
case 1:
|
2001-02-08 00:00:12 +00:00
|
|
|
if (adv->ccb_infos != NULL)
|
|
|
|
free(adv->ccb_infos, M_DEVBUF);
|
1998-09-15 07:03:43 +00:00
|
|
|
case 0:
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_destroy(&adv->lock);
|
1998-09-15 07:03:43 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
adv_init(struct adv_softc *adv)
|
|
|
|
{
|
|
|
|
struct adv_eeprom_config eeprom_config;
|
|
|
|
int checksum, i;
|
2000-01-14 03:33:38 +00:00
|
|
|
int max_sync;
|
1998-09-15 07:03:43 +00:00
|
|
|
u_int16_t config_lsw;
|
|
|
|
u_int16_t config_msw;
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_lock(&adv->lock);
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_lib_init(adv);
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
/*
|
|
|
|
* Stop script execution.
|
|
|
|
*/
|
|
|
|
adv_write_lram_16(adv, ADV_HALTCODE_W, 0x00FE);
|
|
|
|
adv_stop_execution(adv);
|
|
|
|
if (adv_stop_chip(adv) == 0 || adv_is_chip_halted(adv) == 0) {
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_unlock(&adv->lock);
|
|
|
|
device_printf(adv->dev,
|
|
|
|
"Unable to halt adapter. Initialization failed\n");
|
1998-09-15 07:03:43 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
ADV_OUTW(adv, ADV_REG_PROG_COUNTER, ADV_MCODE_START_ADDR);
|
|
|
|
if (ADV_INW(adv, ADV_REG_PROG_COUNTER) != ADV_MCODE_START_ADDR) {
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_unlock(&adv->lock);
|
|
|
|
device_printf(adv->dev,
|
|
|
|
"Unable to set program counter. Initialization failed\n");
|
1998-09-15 07:03:43 +00:00
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
config_msw = ADV_INW(adv, ADV_CONFIG_MSW);
|
|
|
|
config_lsw = ADV_INW(adv, ADV_CONFIG_LSW);
|
|
|
|
|
|
|
|
if ((config_msw & ADV_CFG_MSW_CLR_MASK) != 0) {
|
2000-01-14 03:33:38 +00:00
|
|
|
config_msw &= ~ADV_CFG_MSW_CLR_MASK;
|
1998-09-15 07:03:43 +00:00
|
|
|
/*
|
|
|
|
* XXX The Linux code flags this as an error,
|
|
|
|
* but what should we report to the user???
|
|
|
|
* It seems that clearing the config register
|
|
|
|
* makes this error recoverable.
|
|
|
|
*/
|
|
|
|
ADV_OUTW(adv, ADV_CONFIG_MSW, config_msw);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Suck in the configuration from the EEProm */
|
|
|
|
checksum = adv_get_eeprom_config(adv, &eeprom_config);
|
|
|
|
|
|
|
|
if (ADV_INW(adv, ADV_CHIP_STATUS) & ADV_CSW_AUTO_CONFIG) {
|
|
|
|
/*
|
|
|
|
* XXX The Linux code sets a warning level for this
|
|
|
|
* condition, yet nothing of meaning is printed to
|
|
|
|
* the user. What does this mean???
|
|
|
|
*/
|
|
|
|
if (adv->chip_version == 3) {
|
2000-01-14 03:33:38 +00:00
|
|
|
if (eeprom_config.cfg_lsw != config_lsw)
|
|
|
|
eeprom_config.cfg_lsw = config_lsw;
|
1998-09-15 07:03:43 +00:00
|
|
|
if (eeprom_config.cfg_msw != config_msw) {
|
2000-01-14 03:33:38 +00:00
|
|
|
eeprom_config.cfg_msw = config_msw;
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (checksum == eeprom_config.chksum) {
|
2000-01-14 03:33:38 +00:00
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
/* Range/Sanity checking */
|
|
|
|
if (eeprom_config.max_total_qng < ADV_MIN_TOTAL_QNG) {
|
|
|
|
eeprom_config.max_total_qng = ADV_MIN_TOTAL_QNG;
|
|
|
|
}
|
|
|
|
if (eeprom_config.max_total_qng > ADV_MAX_TOTAL_QNG) {
|
|
|
|
eeprom_config.max_total_qng = ADV_MAX_TOTAL_QNG;
|
|
|
|
}
|
|
|
|
if (eeprom_config.max_tag_qng > eeprom_config.max_total_qng) {
|
|
|
|
eeprom_config.max_tag_qng = eeprom_config.max_total_qng;
|
|
|
|
}
|
|
|
|
if (eeprom_config.max_tag_qng < ADV_MIN_TAG_Q_PER_DVC) {
|
|
|
|
eeprom_config.max_tag_qng = ADV_MIN_TAG_Q_PER_DVC;
|
|
|
|
}
|
|
|
|
adv->max_openings = eeprom_config.max_total_qng;
|
|
|
|
adv->user_disc_enable = eeprom_config.disc_enable;
|
|
|
|
adv->user_cmd_qng_enabled = eeprom_config.use_cmd_qng;
|
|
|
|
adv->isa_dma_speed = EEPROM_DMA_SPEED(eeprom_config);
|
|
|
|
adv->scsi_id = EEPROM_SCSIID(eeprom_config) & ADV_MAX_TID;
|
|
|
|
EEPROM_SET_SCSIID(eeprom_config, adv->scsi_id);
|
|
|
|
adv->control = eeprom_config.cntl;
|
2000-01-14 03:33:38 +00:00
|
|
|
for (i = 0; i <= ADV_MAX_TID; i++) {
|
|
|
|
u_int8_t sync_data;
|
|
|
|
|
|
|
|
if ((eeprom_config.init_sdtr & (0x1 << i)) == 0)
|
|
|
|
sync_data = 0;
|
|
|
|
else
|
|
|
|
sync_data = eeprom_config.sdtr_data[i];
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_sdtr_to_period_offset(adv,
|
2000-01-14 03:33:38 +00:00
|
|
|
sync_data,
|
1998-09-15 07:03:43 +00:00
|
|
|
&adv->tinfo[i].user.period,
|
|
|
|
&adv->tinfo[i].user.offset,
|
|
|
|
i);
|
2000-01-14 03:33:38 +00:00
|
|
|
}
|
|
|
|
config_lsw = eeprom_config.cfg_lsw;
|
|
|
|
eeprom_config.cfg_msw = config_msw;
|
1998-09-15 07:03:43 +00:00
|
|
|
} else {
|
|
|
|
u_int8_t sync_data;
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev, "Warning EEPROM Checksum mismatch. "
|
|
|
|
"Using default device parameters\n");
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/* Set reasonable defaults since we can't read the EEPROM */
|
|
|
|
adv->isa_dma_speed = /*ADV_DEF_ISA_DMA_SPEED*/1;
|
|
|
|
adv->max_openings = ADV_DEF_MAX_TOTAL_QNG;
|
|
|
|
adv->disc_enable = TARGET_BIT_VECTOR_SET;
|
|
|
|
adv->user_disc_enable = TARGET_BIT_VECTOR_SET;
|
|
|
|
adv->cmd_qng_enabled = TARGET_BIT_VECTOR_SET;
|
|
|
|
adv->user_cmd_qng_enabled = TARGET_BIT_VECTOR_SET;
|
|
|
|
adv->scsi_id = 7;
|
2000-01-14 03:33:38 +00:00
|
|
|
adv->control = 0xFFFF;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if (adv->chip_version == ADV_CHIP_VER_PCI_ULTRA_3050)
|
|
|
|
/* Default to no Ultra to support the 3030 */
|
|
|
|
adv->control &= ~ADV_CNTL_SDTR_ENABLE_ULTRA;
|
1998-09-15 07:03:43 +00:00
|
|
|
sync_data = ADV_DEF_SDTR_OFFSET | (ADV_DEF_SDTR_INDEX << 4);
|
2000-01-14 03:33:38 +00:00
|
|
|
for (i = 0; i <= ADV_MAX_TID; i++) {
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_sdtr_to_period_offset(adv, sync_data,
|
|
|
|
&adv->tinfo[i].user.period,
|
|
|
|
&adv->tinfo[i].user.offset,
|
|
|
|
i);
|
2000-01-14 03:33:38 +00:00
|
|
|
}
|
|
|
|
config_lsw |= ADV_CFG_LSW_SCSI_PARITY_ON;
|
|
|
|
}
|
|
|
|
config_msw &= ~ADV_CFG_MSW_CLR_MASK;
|
|
|
|
config_lsw |= ADV_CFG_LSW_HOST_INT_ON;
|
|
|
|
if ((adv->type & (ADV_PCI|ADV_ULTRA)) == (ADV_PCI|ADV_ULTRA)
|
|
|
|
&& (adv->control & ADV_CNTL_SDTR_ENABLE_ULTRA) == 0)
|
|
|
|
/* 25ns or 10MHz */
|
|
|
|
max_sync = 25;
|
|
|
|
else
|
|
|
|
/* Unlimited */
|
|
|
|
max_sync = 0;
|
|
|
|
for (i = 0; i <= ADV_MAX_TID; i++) {
|
|
|
|
if (adv->tinfo[i].user.period < max_sync)
|
|
|
|
adv->tinfo[i].user.period = max_sync;
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if (adv_test_external_lram(adv) == 0) {
|
|
|
|
if ((adv->type & (ADV_PCI|ADV_ULTRA)) == (ADV_PCI|ADV_ULTRA)) {
|
|
|
|
eeprom_config.max_total_qng =
|
|
|
|
ADV_MAX_PCI_ULTRA_INRAM_TOTAL_QNG;
|
|
|
|
eeprom_config.max_tag_qng =
|
|
|
|
ADV_MAX_PCI_ULTRA_INRAM_TAG_QNG;
|
|
|
|
} else {
|
|
|
|
eeprom_config.cfg_msw |= 0x0800;
|
|
|
|
config_msw |= 0x0800;
|
|
|
|
eeprom_config.max_total_qng =
|
|
|
|
ADV_MAX_PCI_INRAM_TOTAL_QNG;
|
|
|
|
eeprom_config.max_tag_qng = ADV_MAX_INRAM_TAG_QNG;
|
|
|
|
}
|
|
|
|
adv->max_openings = eeprom_config.max_total_qng;
|
|
|
|
}
|
|
|
|
ADV_OUTW(adv, ADV_CONFIG_MSW, config_msw);
|
|
|
|
ADV_OUTW(adv, ADV_CONFIG_LSW, config_lsw);
|
|
|
|
#if 0
|
|
|
|
/*
|
|
|
|
* Don't write the eeprom data back for now.
|
|
|
|
* I'd rather not mess up the user's card. We also don't
|
|
|
|
* fully sanitize the eeprom settings above for the write-back
|
|
|
|
* to be 100% correct.
|
|
|
|
*/
|
1998-09-15 07:03:43 +00:00
|
|
|
if (adv_set_eeprom_config(adv, &eeprom_config) != 0)
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev,
|
|
|
|
"WARNING! Failure writing to EEPROM.\n");
|
2000-01-14 03:33:38 +00:00
|
|
|
#endif
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
adv_set_chip_scsiid(adv, adv->scsi_id);
|
2012-10-12 21:31:44 +00:00
|
|
|
if (adv_init_lram_and_mcode(adv)) {
|
|
|
|
mtx_unlock(&adv->lock);
|
1998-09-15 07:03:43 +00:00
|
|
|
return (1);
|
2012-10-12 21:31:44 +00:00
|
|
|
}
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
adv->disc_enable = adv->user_disc_enable;
|
|
|
|
|
|
|
|
adv_write_lram_8(adv, ADVV_DISC_ENABLE_B, adv->disc_enable);
|
|
|
|
for (i = 0; i <= ADV_MAX_TID; i++) {
|
|
|
|
/*
|
|
|
|
* Start off in async mode.
|
|
|
|
*/
|
|
|
|
adv_set_syncrate(adv, /*struct cam_path */NULL,
|
|
|
|
i, /*period*/0, /*offset*/0,
|
|
|
|
ADV_TRANS_CUR);
|
|
|
|
/*
|
|
|
|
* Enable the use of tagged commands on all targets.
|
|
|
|
* This allows the kernel driver to make up it's own mind
|
|
|
|
* as it sees fit to tag queue instead of having the
|
|
|
|
* firmware try and second guess the tag_code settins.
|
|
|
|
*/
|
|
|
|
adv_write_lram_8(adv, ADVV_MAX_DVC_QNG_BEG + i,
|
|
|
|
adv->max_openings);
|
|
|
|
}
|
|
|
|
adv_write_lram_8(adv, ADVV_USE_TAGGED_QNG_B, TARGET_BIT_VECTOR_SET);
|
|
|
|
adv_write_lram_8(adv, ADVV_CAN_TAGGED_QNG_B, TARGET_BIT_VECTOR_SET);
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev,
|
|
|
|
"AdvanSys %s Host Adapter, SCSI ID %d, queue depth %d\n",
|
|
|
|
(adv->type & ADV_ULTRA) && (max_sync == 0)
|
|
|
|
? "Ultra SCSI" : "SCSI",
|
|
|
|
adv->scsi_id, adv->max_openings);
|
|
|
|
mtx_unlock(&adv->lock);
|
1998-09-15 07:03:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_intr(void *arg)
|
|
|
|
{
|
|
|
|
struct adv_softc *adv;
|
2012-10-12 21:31:44 +00:00
|
|
|
|
|
|
|
adv = arg;
|
|
|
|
mtx_lock(&adv->lock);
|
|
|
|
adv_intr_locked(adv);
|
|
|
|
mtx_unlock(&adv->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_intr_locked(struct adv_softc *adv)
|
|
|
|
{
|
1998-09-15 07:03:43 +00:00
|
|
|
u_int16_t chipstat;
|
|
|
|
u_int16_t saved_ram_addr;
|
|
|
|
u_int8_t ctrl_reg;
|
|
|
|
u_int8_t saved_ctrl_reg;
|
|
|
|
u_int8_t host_flag;
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
2000-01-14 03:33:38 +00:00
|
|
|
chipstat = ADV_INW(adv, ADV_CHIP_STATUS);
|
|
|
|
|
|
|
|
/* Is it for us? */
|
|
|
|
if ((chipstat & (ADV_CSW_INT_PENDING|ADV_CSW_SCSI_RESET_LATCH)) == 0)
|
|
|
|
return;
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
ctrl_reg = ADV_INB(adv, ADV_CHIP_CTRL);
|
|
|
|
saved_ctrl_reg = ctrl_reg & (~(ADV_CC_SCSI_RESET | ADV_CC_CHIP_RESET |
|
|
|
|
ADV_CC_SINGLE_STEP | ADV_CC_DIAG |
|
|
|
|
ADV_CC_TEST));
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if ((chipstat & (ADV_CSW_SCSI_RESET_LATCH|ADV_CSW_SCSI_RESET_ACTIVE))) {
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev, "Detected Bus Reset\n");
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_reset_bus(adv, /*initiate_reset*/FALSE);
|
|
|
|
return;
|
|
|
|
}
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if ((chipstat & ADV_CSW_INT_PENDING) != 0) {
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
saved_ram_addr = ADV_INW(adv, ADV_LRAM_ADDR);
|
|
|
|
host_flag = adv_read_lram_8(adv, ADVV_HOST_FLAG_B);
|
|
|
|
adv_write_lram_8(adv, ADVV_HOST_FLAG_B,
|
|
|
|
host_flag | ADV_HOST_FLAG_IN_ISR);
|
|
|
|
|
|
|
|
adv_ack_interrupt(adv);
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if ((chipstat & ADV_CSW_HALTED) != 0
|
|
|
|
&& (ctrl_reg & ADV_CC_SINGLE_STEP) != 0) {
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_isr_chip_halted(adv);
|
|
|
|
saved_ctrl_reg &= ~ADV_CC_HALT;
|
|
|
|
} else {
|
|
|
|
adv_run_doneq(adv);
|
|
|
|
}
|
|
|
|
ADV_OUTW(adv, ADV_LRAM_ADDR, saved_ram_addr);
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (ADV_INW(adv, ADV_LRAM_ADDR) != saved_ram_addr)
|
|
|
|
panic("adv_intr: Unable to set LRAM addr");
|
|
|
|
#endif
|
|
|
|
adv_write_lram_8(adv, ADVV_HOST_FLAG_B, host_flag);
|
|
|
|
}
|
|
|
|
|
|
|
|
ADV_OUTB(adv, ADV_CHIP_CTRL, saved_ctrl_reg);
|
|
|
|
}
|
|
|
|
|
2002-09-28 17:15:38 +00:00
|
|
|
static void
|
1998-09-15 07:03:43 +00:00
|
|
|
adv_run_doneq(struct adv_softc *adv)
|
|
|
|
{
|
|
|
|
struct adv_q_done_info scsiq;
|
|
|
|
u_int doneq_head;
|
|
|
|
u_int done_qno;
|
|
|
|
|
|
|
|
doneq_head = adv_read_lram_16(adv, ADVV_DONE_Q_TAIL_W) & 0xFF;
|
|
|
|
done_qno = adv_read_lram_8(adv, ADV_QNO_TO_QADDR(doneq_head)
|
|
|
|
+ ADV_SCSIQ_B_FWD);
|
|
|
|
while (done_qno != ADV_QLINK_END) {
|
|
|
|
union ccb* ccb;
|
2000-01-14 03:33:38 +00:00
|
|
|
struct adv_ccb_info *cinfo;
|
1998-09-15 07:03:43 +00:00
|
|
|
u_int done_qaddr;
|
|
|
|
u_int sg_queue_cnt;
|
|
|
|
|
|
|
|
done_qaddr = ADV_QNO_TO_QADDR(done_qno);
|
|
|
|
|
|
|
|
/* Pull status from this request */
|
|
|
|
sg_queue_cnt = adv_copy_lram_doneq(adv, done_qaddr, &scsiq,
|
|
|
|
adv->max_dma_count);
|
|
|
|
|
|
|
|
/* Mark it as free */
|
|
|
|
adv_write_lram_8(adv, done_qaddr + ADV_SCSIQ_B_STATUS,
|
1998-09-20 05:04:05 +00:00
|
|
|
scsiq.q_status & ~(QS_READY|QS_ABORTED));
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/* Process request based on retrieved info */
|
|
|
|
if ((scsiq.cntl & QC_SG_HEAD) != 0) {
|
|
|
|
u_int i;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* S/G based request. Free all of the queue
|
|
|
|
* structures that contained S/G information.
|
|
|
|
*/
|
|
|
|
for (i = 0; i < sg_queue_cnt; i++) {
|
|
|
|
done_qno = adv_read_lram_8(adv, done_qaddr
|
|
|
|
+ ADV_SCSIQ_B_FWD);
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
1998-09-20 05:04:05 +00:00
|
|
|
if (done_qno == ADV_QLINK_END) {
|
1998-09-15 07:03:43 +00:00
|
|
|
panic("adv_qdone: Corrupted SG "
|
|
|
|
"list encountered");
|
|
|
|
}
|
|
|
|
#endif
|
1998-09-20 05:04:05 +00:00
|
|
|
done_qaddr = ADV_QNO_TO_QADDR(done_qno);
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
/* Mark SG queue as free */
|
|
|
|
adv_write_lram_8(adv, done_qaddr
|
|
|
|
+ ADV_SCSIQ_B_STATUS, QS_FREE);
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
sg_queue_cnt = 0;
|
|
|
|
#ifdef DIAGNOSTIC
|
1998-09-20 05:04:05 +00:00
|
|
|
if (adv->cur_active < (sg_queue_cnt + 1))
|
1998-09-15 07:03:43 +00:00
|
|
|
panic("adv_qdone: Attempting to free more "
|
|
|
|
"queues than are active");
|
|
|
|
#endif
|
|
|
|
adv->cur_active -= sg_queue_cnt + 1;
|
|
|
|
|
|
|
|
if ((scsiq.q_status != QS_DONE)
|
|
|
|
&& (scsiq.q_status & QS_ABORTED) == 0)
|
|
|
|
panic("adv_qdone: completed scsiq with unknown status");
|
|
|
|
|
|
|
|
scsiq.remain_bytes += scsiq.extra_bytes;
|
|
|
|
|
|
|
|
if ((scsiq.d3.done_stat == QD_WITH_ERROR) &&
|
|
|
|
(scsiq.d3.host_stat == QHSTA_M_DATA_OVER_RUN)) {
|
|
|
|
if ((scsiq.cntl & (QC_DATA_IN|QC_DATA_OUT)) == 0) {
|
|
|
|
scsiq.d3.done_stat = QD_NO_ERROR;
|
|
|
|
scsiq.d3.host_stat = QHSTA_NO_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
cinfo = &adv->ccb_infos[scsiq.d2.ccb_index];
|
|
|
|
ccb = cinfo->ccb;
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->csio.resid = scsiq.remain_bytes;
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_done(adv, ccb,
|
1998-09-15 07:03:43 +00:00
|
|
|
scsiq.d3.done_stat, scsiq.d3.host_stat,
|
|
|
|
scsiq.d3.scsi_stat, scsiq.q_no);
|
|
|
|
|
|
|
|
doneq_head = done_qno;
|
1998-10-07 03:32:57 +00:00
|
|
|
done_qno = adv_read_lram_8(adv, done_qaddr + ADV_SCSIQ_B_FWD);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
adv_write_lram_16(adv, ADVV_DONE_Q_TAIL_W, doneq_head);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void
|
|
|
|
adv_done(struct adv_softc *adv, union ccb *ccb, u_int done_stat,
|
|
|
|
u_int host_stat, u_int scsi_status, u_int q_no)
|
|
|
|
{
|
|
|
|
struct adv_ccb_info *cinfo;
|
|
|
|
|
2012-10-12 21:31:44 +00:00
|
|
|
if (!dumping)
|
|
|
|
mtx_assert(&adv->lock, MA_OWNED);
|
1998-09-15 07:03:43 +00:00
|
|
|
cinfo = (struct adv_ccb_info *)ccb->ccb_h.ccb_cinfo_ptr;
|
1999-04-07 22:59:12 +00:00
|
|
|
LIST_REMOVE(&ccb->ccb_h, sim_links.le);
|
2012-10-12 21:31:44 +00:00
|
|
|
callout_stop(&cinfo->timer);
|
1998-09-15 07:03:43 +00:00
|
|
|
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:03:43 +00:00
|
|
|
|
|
|
|
if ((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN)
|
|
|
|
op = BUS_DMASYNC_POSTREAD;
|
|
|
|
else
|
|
|
|
op = BUS_DMASYNC_POSTWRITE;
|
|
|
|
bus_dmamap_sync(adv->buffer_dmat, cinfo->dmamap, op);
|
|
|
|
bus_dmamap_unload(adv->buffer_dmat, cinfo->dmamap);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch (done_stat) {
|
|
|
|
case QD_NO_ERROR:
|
1999-04-07 22:59:12 +00:00
|
|
|
if (host_stat == QHSTA_NO_ERROR) {
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
}
|
1999-04-07 22:59:12 +00:00
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("adv_done - queue done without error, "
|
|
|
|
"but host status non-zero(%x)\n", host_stat);
|
|
|
|
/*FALLTHROUGH*/
|
1998-09-15 07:03:43 +00:00
|
|
|
case QD_WITH_ERROR:
|
|
|
|
switch (host_stat) {
|
1999-04-07 22:59:12 +00:00
|
|
|
case QHSTA_M_TARGET_STATUS_BUSY:
|
|
|
|
case QHSTA_M_BAD_QUEUE_FULL_OR_BUSY:
|
|
|
|
/*
|
|
|
|
* Assume that if we were a tagged transaction
|
|
|
|
* the target reported queue full. Otherwise,
|
|
|
|
* report busy. The firmware really should just
|
|
|
|
* pass the original status back up to us even
|
|
|
|
* if it thinks the target was in error for
|
|
|
|
* returning this status as no other transactions
|
|
|
|
* from this initiator are in effect, but this
|
|
|
|
* ignores multi-initiator setups and there is
|
|
|
|
* evidence that the firmware gets its per-device
|
2016-05-03 03:41:25 +00:00
|
|
|
* transaction counts screwed up occasionally.
|
1999-04-07 22:59:12 +00:00
|
|
|
*/
|
|
|
|
ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
|
|
|
|
if ((ccb->ccb_h.flags & CAM_TAG_ACTION_VALID) != 0
|
|
|
|
&& host_stat != QHSTA_M_TARGET_STATUS_BUSY)
|
|
|
|
scsi_status = SCSI_STATUS_QUEUE_FULL;
|
|
|
|
else
|
|
|
|
scsi_status = SCSI_STATUS_BUSY;
|
|
|
|
adv_abort_ccb(adv, ccb->ccb_h.target_id,
|
|
|
|
ccb->ccb_h.target_lun,
|
|
|
|
/*ccb*/NULL, CAM_REQUEUE_REQ,
|
|
|
|
/*queued_only*/TRUE);
|
|
|
|
/*FALLTHROUGH*/
|
|
|
|
case QHSTA_M_NO_AUTO_REQ_SENSE:
|
1998-09-15 07:03:43 +00:00
|
|
|
case QHSTA_NO_ERROR:
|
|
|
|
ccb->csio.scsi_status = scsi_status;
|
|
|
|
switch (scsi_status) {
|
|
|
|
case SCSI_STATUS_CHECK_COND:
|
|
|
|
case SCSI_STATUS_CMD_TERMINATED:
|
|
|
|
ccb->ccb_h.status |= CAM_AUTOSNS_VALID;
|
|
|
|
/* Structure copy */
|
|
|
|
ccb->csio.sense_data =
|
|
|
|
adv->sense_buffers[q_no - 1];
|
|
|
|
/* FALLTHROUGH */
|
|
|
|
case SCSI_STATUS_BUSY:
|
|
|
|
case SCSI_STATUS_RESERV_CONFLICT:
|
|
|
|
case SCSI_STATUS_QUEUE_FULL:
|
|
|
|
case SCSI_STATUS_COND_MET:
|
|
|
|
case SCSI_STATUS_INTERMED:
|
|
|
|
case SCSI_STATUS_INTERMED_COND_MET:
|
|
|
|
ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR;
|
|
|
|
break;
|
|
|
|
case SCSI_STATUS_OK:
|
|
|
|
ccb->ccb_h.status |= CAM_REQ_CMP;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case QHSTA_M_SEL_TIMEOUT:
|
|
|
|
ccb->ccb_h.status = CAM_SEL_TIMEOUT;
|
|
|
|
break;
|
1999-04-07 22:59:12 +00:00
|
|
|
case QHSTA_M_DATA_OVER_RUN:
|
|
|
|
ccb->ccb_h.status = CAM_DATA_RUN_ERR;
|
|
|
|
break;
|
|
|
|
case QHSTA_M_UNEXPECTED_BUS_FREE:
|
|
|
|
ccb->ccb_h.status = CAM_UNEXP_BUSFREE;
|
|
|
|
break;
|
|
|
|
case QHSTA_M_BAD_BUS_PHASE_SEQ:
|
|
|
|
ccb->ccb_h.status = CAM_SEQUENCE_FAIL;
|
1998-09-15 07:03:43 +00:00
|
|
|
break;
|
1999-04-07 22:59:12 +00:00
|
|
|
case QHSTA_M_BAD_CMPL_STATUS_IN:
|
|
|
|
/* No command complete after a status message */
|
|
|
|
ccb->ccb_h.status = CAM_SEQUENCE_FAIL;
|
|
|
|
break;
|
|
|
|
case QHSTA_D_EXE_SCSI_Q_BUSY_TIMEOUT:
|
|
|
|
case QHSTA_M_WTM_TIMEOUT:
|
|
|
|
case QHSTA_M_HUNG_REQ_SCSI_BUS_RESET:
|
|
|
|
/* The SCSI bus hung in a phase */
|
|
|
|
ccb->ccb_h.status = CAM_SEQUENCE_FAIL;
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_reset_bus(adv, /*initiate_reset*/TRUE);
|
1999-04-07 22:59:12 +00:00
|
|
|
break;
|
1999-04-19 21:27:36 +00:00
|
|
|
case QHSTA_M_AUTO_REQ_SENSE_FAIL:
|
|
|
|
ccb->ccb_h.status = CAM_AUTOSENSE_FAIL;
|
|
|
|
break;
|
1999-04-07 22:59:12 +00:00
|
|
|
case QHSTA_D_QDONE_SG_LIST_CORRUPTED:
|
|
|
|
case QHSTA_D_ASC_DVC_ERROR_CODE_SET:
|
|
|
|
case QHSTA_D_HOST_ABORT_FAILED:
|
|
|
|
case QHSTA_D_EXE_SCSI_Q_FAILED:
|
|
|
|
case QHSTA_D_ASPI_NO_BUF_POOL:
|
|
|
|
case QHSTA_M_BAD_TAG_CODE:
|
|
|
|
case QHSTA_D_LRAM_CMP_ERROR:
|
|
|
|
case QHSTA_M_MICRO_CODE_ERROR_HALT:
|
|
|
|
default:
|
|
|
|
panic("%s: Unhandled Host status error %x",
|
2012-10-12 21:31:44 +00:00
|
|
|
device_get_nameunit(adv->dev), host_stat);
|
1999-04-07 22:59:12 +00:00
|
|
|
/* NOTREACHED */
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case QD_ABORTED_BY_HOST:
|
|
|
|
/* Don't clobber any, more explicit, error codes we've set */
|
|
|
|
if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
|
|
|
|
ccb->ccb_h.status = CAM_REQ_ABORTED;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
1998-10-29 17:41:34 +00:00
|
|
|
xpt_print_path(ccb->ccb_h.path);
|
|
|
|
printf("adv_done - queue done with unknown status %x:%x\n",
|
|
|
|
done_stat, host_stat);
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->ccb_h.status = CAM_REQ_CMP_ERR;
|
|
|
|
break;
|
|
|
|
}
|
2000-01-14 03:33:38 +00:00
|
|
|
adv_clear_state(adv, ccb);
|
1998-09-15 07:03:43 +00:00
|
|
|
if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_CMP
|
|
|
|
&& (ccb->ccb_h.status & CAM_DEV_QFRZN) == 0) {
|
|
|
|
xpt_freeze_devq(ccb->ccb_h.path, /*count*/1);
|
|
|
|
ccb->ccb_h.status |= CAM_DEV_QFRZN;
|
|
|
|
}
|
|
|
|
adv_free_ccb_info(adv, cinfo);
|
2000-01-14 03:33:38 +00:00
|
|
|
/*
|
|
|
|
* Null this out so that we catch driver bugs that cause a
|
|
|
|
* ccb to be completed twice.
|
|
|
|
*/
|
|
|
|
ccb->ccb_h.ccb_cinfo_ptr = NULL;
|
1998-09-15 07:03:43 +00:00
|
|
|
ccb->ccb_h.status &= ~CAM_SIM_QUEUED;
|
|
|
|
xpt_done(ccb);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Function to poll for command completion when
|
|
|
|
* interrupts are disabled (crash dumps)
|
|
|
|
*/
|
|
|
|
static void
|
|
|
|
adv_poll(struct cam_sim *sim)
|
|
|
|
{
|
2012-10-12 21:31:44 +00:00
|
|
|
|
|
|
|
adv_intr_locked(cam_sim_softc(sim));
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Attach all the sub-devices we can find
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
adv_attach(adv)
|
|
|
|
struct adv_softc *adv;
|
|
|
|
{
|
|
|
|
struct ccb_setasync csa;
|
|
|
|
struct cam_devq *devq;
|
2000-01-14 03:33:38 +00:00
|
|
|
int max_sg;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Allocate an array of ccb mapping structures. We put the
|
|
|
|
* index of the ccb_info structure into the queue representing
|
|
|
|
* a transaction and use it for mapping the queue to the
|
|
|
|
* upper level SCSI transaction it represents.
|
|
|
|
*/
|
|
|
|
adv->ccb_infos = malloc(sizeof(*adv->ccb_infos) * adv->max_openings,
|
|
|
|
M_DEVBUF, M_NOWAIT);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
2000-01-14 03:33:38 +00:00
|
|
|
if (adv->ccb_infos == NULL)
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENOMEM);
|
2000-01-14 03:33:38 +00:00
|
|
|
|
|
|
|
adv->init_level++;
|
|
|
|
|
1998-09-15 07:03:43 +00:00
|
|
|
/*
|
|
|
|
* Create our DMA tags. These tags define the kinds of device
|
2000-06-14 17:53:40 +00:00
|
|
|
* accessible memory allocations and memory mappings we will
|
1998-09-15 07:03:43 +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.
|
2000-01-14 03:33:38 +00:00
|
|
|
*
|
|
|
|
* The ASC boards use chains of "queues" (the transactional
|
|
|
|
* resources on the board) to represent long S/G lists.
|
|
|
|
* The first queue represents the command and holds a
|
|
|
|
* single address and data pair. The queues that follow
|
|
|
|
* can each hold ADV_SG_LIST_PER_Q entries. Given the
|
|
|
|
* total number of queues, we can express the largest
|
|
|
|
* transaction we can map. We reserve a few queues for
|
|
|
|
* error recovery. Take those into account as well.
|
|
|
|
*
|
|
|
|
* There is a way to take an interrupt to download the
|
|
|
|
* next batch of S/G entries if there are more than 255
|
|
|
|
* of them (the counter in the queue structure is a u_int8_t).
|
|
|
|
* We don't use this feature, so limit the S/G list size
|
|
|
|
* accordingly.
|
1998-09-15 07:03:43 +00:00
|
|
|
*/
|
2000-01-14 03:33:38 +00:00
|
|
|
max_sg = (adv->max_openings - ADV_MIN_FREE_Q - 1) * ADV_SG_LIST_PER_Q;
|
|
|
|
if (max_sg > 255)
|
|
|
|
max_sg = 255;
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/* DMA tag for mapping buffers into device visible space. */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create(
|
|
|
|
/* parent */ adv->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
Separate the parallel scsi knowledge out of the core of the XPT, and
modularize it so that new transports can be created.
Add a transport for SATA
Add a periph+protocol layer for ATA
Add a driver for AHCI-compliant hardware.
Add a maxio field to CAM so that drivers can advertise their max
I/O capability. Modify various drivers so that they are insulated
from the value of MAXPHYS.
The new ATA/SATA code supports AHCI-compliant hardware, and will override
the classic ATA driver if it is loaded as a module at boot time or compiled
into the kernel. The stack now support NCQ (tagged queueing) for increased
performance on modern SATA drives. It also supports port multipliers.
ATA drives are accessed via 'ada' device nodes. ATAPI drives are
accessed via 'cd' device nodes. They can all be enumerated and manipulated
via camcontrol, just like SCSI drives. SCSI commands are not translated to
their ATA equivalents; ATA native commands are used throughout the entire
stack, including camcontrol. See the camcontrol manpage for further
details. Testing this code may require that you update your fstab, and
possibly modify your BIOS to enable AHCI functionality, if available.
This code is very experimental at the moment. The userland ABI/API has
changed, so applications will need to be recompiled. It may change
further in the near future. The 'ada' device name may also change as
more infrastructure is completed in this project. The goal is to
eventually put all CAM busses and devices until newbus, allowing for
interesting topology and management options.
Few functional changes will be seen with existing SCSI/SAS/FC drivers,
though the userland ABI has still changed. In the future, transports
specific modules for SAS and FC may appear in order to better support
the topologies and capabilities of these technologies.
The modularization of CAM and the addition of the ATA/SATA modules is
meant to break CAM out of the mold of being specific to SCSI, letting it
grow to be a framework for arbitrary transports and protocols. It also
allows drivers to be written to support discrete hardware without
jeopardizing the stability of non-related hardware. While only an AHCI
driver is provided now, a Silicon Image driver is also in the works.
Drivers for ICH1-4, ICH5-6, PIIX, classic IDE, and any other hardware
is possible and encouraged. Help with new transports is also encouraged.
Submitted by: scottl, mav
Approved by: re
2009-07-10 08:18:08 +00:00
|
|
|
/* maxsize */ ADV_MAXPHYS,
|
2003-03-29 09:46:10 +00:00
|
|
|
/* nsegments */ max_sg,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ BUS_DMA_ALLOCNOW,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
2012-10-12 21:31:44 +00:00
|
|
|
/* lockarg */ &adv->lock,
|
2003-03-29 09:46:10 +00:00
|
|
|
&adv->buffer_dmat) != 0) {
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
adv->init_level++;
|
|
|
|
|
|
|
|
/* DMA tag for our sense buffers */
|
2003-03-29 09:46:10 +00:00
|
|
|
if (bus_dma_tag_create(
|
|
|
|
/* parent */ adv->parent_dmat,
|
|
|
|
/* alignment */ 1,
|
|
|
|
/* boundary */ 0,
|
|
|
|
/* lowaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* highaddr */ BUS_SPACE_MAXADDR,
|
|
|
|
/* filter */ NULL,
|
|
|
|
/* filterarg */ NULL,
|
|
|
|
/* maxsize */ sizeof(struct scsi_sense_data) *
|
|
|
|
adv->max_openings,
|
|
|
|
/* nsegments */ 1,
|
|
|
|
/* maxsegsz */ BUS_SPACE_MAXSIZE_32BIT,
|
|
|
|
/* flags */ 0,
|
2003-07-01 15:52:06 +00:00
|
|
|
/* lockfunc */ busdma_lock_mutex,
|
2012-10-12 21:31:44 +00:00
|
|
|
/* lockarg */ &adv->lock,
|
2003-03-29 09:46:10 +00:00
|
|
|
&adv->sense_dmat) != 0) {
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adv->init_level++;
|
|
|
|
|
|
|
|
/* Allocation for our sense buffers */
|
|
|
|
if (bus_dmamem_alloc(adv->sense_dmat, (void **)&adv->sense_buffers,
|
|
|
|
BUS_DMA_NOWAIT, &adv->sense_dmamap) != 0) {
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENOMEM);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
adv->init_level++;
|
|
|
|
|
|
|
|
/* And permanently map them */
|
|
|
|
bus_dmamap_load(adv->sense_dmat, adv->sense_dmamap,
|
|
|
|
adv->sense_buffers,
|
|
|
|
sizeof(struct scsi_sense_data)*adv->max_openings,
|
|
|
|
adv_map, &adv->sense_physbase, /*flags*/0);
|
|
|
|
|
|
|
|
adv->init_level++;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Fire up the chip
|
|
|
|
*/
|
|
|
|
if (adv_start_chip(adv) != 1) {
|
2012-10-12 21:31:44 +00:00
|
|
|
device_printf(adv->dev,
|
|
|
|
"Unable to start on board processor. Aborting.\n");
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Create the device queue for our SIM.
|
|
|
|
*/
|
|
|
|
devq = cam_simq_alloc(adv->max_openings);
|
|
|
|
if (devq == NULL)
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENOMEM);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Construct our SIM entry.
|
|
|
|
*/
|
2012-10-12 21:31:44 +00:00
|
|
|
adv->sim = cam_sim_alloc(adv_action, adv_poll, "adv", adv,
|
|
|
|
device_get_unit(adv->dev), &adv->lock, 1, adv->max_openings, devq);
|
1998-09-15 07:03:43 +00:00
|
|
|
if (adv->sim == NULL)
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENOMEM);
|
1998-09-15 07:03:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Register the bus.
|
|
|
|
*
|
|
|
|
* XXX Twin Channel EISA Cards???
|
|
|
|
*/
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_lock(&adv->lock);
|
2007-06-17 05:55:54 +00:00
|
|
|
if (xpt_bus_register(adv->sim, adv->dev, 0) != CAM_SUCCESS) {
|
1998-09-15 07:03:43 +00:00
|
|
|
cam_sim_free(adv->sim, /*free devq*/TRUE);
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_unlock(&adv->lock);
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (xpt_create_path(&adv->path, /*periph*/NULL, cam_sim_path(adv->sim),
|
|
|
|
CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD)
|
2000-05-23 10:12:42 +00:00
|
|
|
!= CAM_REQ_CMP) {
|
|
|
|
xpt_bus_deregister(cam_sim_path(adv->sim));
|
|
|
|
cam_sim_free(adv->sim, /*free devq*/TRUE);
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_unlock(&adv->lock);
|
2000-05-23 10:12:42 +00:00
|
|
|
return (ENXIO);
|
1998-09-15 07:03:43 +00:00
|
|
|
}
|
|
|
|
|
2000-05-23 10:12:42 +00:00
|
|
|
xpt_setup_ccb(&csa.ccb_h, adv->path, /*priority*/5);
|
|
|
|
csa.ccb_h.func_code = XPT_SASYNC_CB;
|
|
|
|
csa.event_enable = AC_FOUND_DEVICE|AC_LOST_DEVICE;
|
|
|
|
csa.callback = advasync;
|
|
|
|
csa.callback_arg = adv;
|
|
|
|
xpt_action((union ccb *)&csa);
|
2012-10-12 21:31:44 +00:00
|
|
|
mtx_unlock(&adv->lock);
|
1998-09-15 07:03:43 +00:00
|
|
|
return (0);
|
|
|
|
}
|
2006-12-11 18:28:31 +00:00
|
|
|
MODULE_DEPEND(adv, cam, 1, 1, 1);
|