2001-03-14 07:55:21 +03:00
|
|
|
/* $NetBSD: isp_inline.h,v 1.13 2001/03/14 04:55:21 mjacob Exp $ */
|
2000-08-14 11:06:50 +04:00
|
|
|
/*
|
|
|
|
* This driver, which is contained in NetBSD in the files:
|
|
|
|
*
|
|
|
|
* sys/dev/ic/isp.c
|
2000-12-23 04:37:57 +03:00
|
|
|
* sys/dev/ic/isp_inline.h
|
|
|
|
* sys/dev/ic/isp_netbsd.c
|
|
|
|
* sys/dev/ic/isp_netbsd.h
|
|
|
|
* sys/dev/ic/isp_target.c
|
|
|
|
* sys/dev/ic/isp_target.h
|
|
|
|
* sys/dev/ic/isp_tpublic.h
|
|
|
|
* sys/dev/ic/ispmbox.h
|
|
|
|
* sys/dev/ic/ispreg.h
|
|
|
|
* sys/dev/ic/ispvar.h
|
2000-08-14 11:06:50 +04:00
|
|
|
* sys/microcode/isp/asm_sbus.h
|
|
|
|
* sys/microcode/isp/asm_1040.h
|
|
|
|
* sys/microcode/isp/asm_1080.h
|
|
|
|
* sys/microcode/isp/asm_12160.h
|
|
|
|
* sys/microcode/isp/asm_2100.h
|
|
|
|
* sys/microcode/isp/asm_2200.h
|
|
|
|
* sys/pci/isp_pci.c
|
|
|
|
* sys/sbus/isp_sbus.c
|
|
|
|
*
|
|
|
|
* Is being actively maintained by Matthew Jacob (mjacob@netbsd.org).
|
|
|
|
* This driver also is shared source with FreeBSD, OpenBSD, Linux, Solaris,
|
|
|
|
* Linux versions. This tends to be an interesting maintenance problem.
|
|
|
|
*
|
|
|
|
* Please coordinate with Matthew Jacob on changes you wish to make here.
|
|
|
|
*/
|
1999-10-14 06:16:55 +04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 1999 National Aeronautics & Space Administration
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 3. 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 ``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 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.
|
|
|
|
*/
|
|
|
|
/*
|
|
|
|
* Qlogic HBA inline functions.
|
|
|
|
* mjacob@nas.nasa.gov.
|
|
|
|
*/
|
|
|
|
#ifndef _ISP_INLINE_H
|
|
|
|
#define _ISP_INLINE_H
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Handle Functions.
|
|
|
|
* For each outstanding command there will be a non-zero handle.
|
|
|
|
* There will be at most isp_maxcmds handles, and isp_lasthdls
|
|
|
|
* will be a seed for the last handled allocated.
|
|
|
|
*/
|
|
|
|
|
2001-03-14 07:55:21 +03:00
|
|
|
static INLINE int isp_save_xs(struct ispsoftc *, XS_T *, u_int16_t *);
|
|
|
|
static INLINE XS_T *isp_find_xs(struct ispsoftc *, u_int16_t);
|
|
|
|
static INLINE u_int16_t isp_find_handle(struct ispsoftc *, XS_T *);
|
|
|
|
static INLINE int isp_handle_index(u_int16_t);
|
|
|
|
static INLINE void isp_destroy_handle(struct ispsoftc *, u_int16_t);
|
|
|
|
static INLINE void isp_remove_handle(struct ispsoftc *, XS_T *);
|
1999-10-14 06:16:55 +04:00
|
|
|
|
|
|
|
static INLINE int
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_save_xs(struct ispsoftc *isp, XS_T *xs, u_int16_t *handlep)
|
1999-10-14 06:16:55 +04:00
|
|
|
{
|
|
|
|
int i, j;
|
|
|
|
|
|
|
|
for (j = isp->isp_lasthdls, i = 0; i < (int) isp->isp_maxcmds; i++) {
|
|
|
|
if (isp->isp_xflist[j] == NULL) {
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
if (++j == isp->isp_maxcmds) {
|
|
|
|
j = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (i == isp->isp_maxcmds) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
isp->isp_xflist[j] = xs;
|
|
|
|
*handlep = j+1;
|
|
|
|
if (++j == isp->isp_maxcmds)
|
|
|
|
j = 0;
|
2000-08-14 11:06:50 +04:00
|
|
|
isp->isp_lasthdls = (u_int16_t)j;
|
1999-10-14 06:16:55 +04:00
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-08-02 03:55:09 +04:00
|
|
|
static INLINE XS_T *
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_find_xs(struct ispsoftc *isp, u_int16_t handle)
|
1999-10-14 06:16:55 +04:00
|
|
|
{
|
2001-03-14 07:55:21 +03:00
|
|
|
if (handle < 1 || handle > (u_int16_t) isp->isp_maxcmds) {
|
1999-10-14 06:16:55 +04:00
|
|
|
return (NULL);
|
|
|
|
} else {
|
|
|
|
return (isp->isp_xflist[handle - 1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-14 07:55:21 +03:00
|
|
|
static INLINE u_int16_t
|
|
|
|
isp_find_handle(struct ispsoftc *isp, XS_T *xs)
|
1999-10-14 06:16:55 +04:00
|
|
|
{
|
|
|
|
int i;
|
|
|
|
if (xs != NULL) {
|
|
|
|
for (i = 0; i < isp->isp_maxcmds; i++) {
|
|
|
|
if (isp->isp_xflist[i] == xs) {
|
2001-03-14 07:55:21 +03:00
|
|
|
return ((u_int16_t) i+1);
|
1999-10-14 06:16:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
2000-07-06 02:21:44 +04:00
|
|
|
static INLINE int
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_handle_index(u_int16_t handle)
|
2000-07-06 02:21:44 +04:00
|
|
|
{
|
|
|
|
return (handle-1);
|
|
|
|
}
|
|
|
|
|
1999-10-14 06:16:55 +04:00
|
|
|
static INLINE void
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_destroy_handle(struct ispsoftc *isp, u_int16_t handle)
|
1999-10-14 06:16:55 +04:00
|
|
|
{
|
2001-03-14 07:55:21 +03:00
|
|
|
if (handle > 0 && handle <= (u_int16_t) isp->isp_maxcmds) {
|
2000-07-06 02:21:44 +04:00
|
|
|
isp->isp_xflist[isp_handle_index(handle)] = NULL;
|
1999-10-14 06:16:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static INLINE void
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_remove_handle(struct ispsoftc *isp, XS_T *xs)
|
1999-10-14 06:16:55 +04:00
|
|
|
{
|
|
|
|
isp_destroy_handle(isp, isp_find_handle(isp, xs));
|
|
|
|
}
|
1999-12-04 06:06:54 +03:00
|
|
|
|
|
|
|
static INLINE int
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_getrqentry(struct ispsoftc *, u_int16_t *, u_int16_t *, void **);
|
1999-12-04 06:06:54 +03:00
|
|
|
|
|
|
|
static INLINE int
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_getrqentry(struct ispsoftc *isp, u_int16_t *iptrp,
|
|
|
|
u_int16_t *optrp, void **resultp)
|
1999-12-04 06:06:54 +03:00
|
|
|
{
|
|
|
|
volatile u_int16_t iptr, optr;
|
|
|
|
|
|
|
|
optr = isp->isp_reqodx = ISP_READ(isp, OUTMAILBOX4);
|
|
|
|
iptr = isp->isp_reqidx;
|
|
|
|
*resultp = ISP_QUEUE_ENTRY(isp->isp_rquest, iptr);
|
2000-08-02 03:55:09 +04:00
|
|
|
iptr = ISP_NXT_QENTRY(iptr, RQUEST_QUEUE_LEN(isp));
|
1999-12-04 06:06:54 +03:00
|
|
|
if (iptr == optr) {
|
|
|
|
return (1);
|
|
|
|
}
|
2000-07-06 02:21:44 +04:00
|
|
|
if (optrp)
|
|
|
|
*optrp = optr;
|
|
|
|
if (iptrp)
|
|
|
|
*iptrp = iptr;
|
1999-12-04 06:06:54 +03:00
|
|
|
return (0);
|
|
|
|
}
|
2000-01-06 05:56:20 +03:00
|
|
|
|
2001-03-14 07:55:21 +03:00
|
|
|
static INLINE void isp_print_qentry (struct ispsoftc *, char *, int, void *);
|
2000-01-06 05:56:20 +03:00
|
|
|
|
2000-08-02 03:55:09 +04:00
|
|
|
|
|
|
|
#define TBA (4 * (((QENTRY_LEN >> 2) * 3) + 1) + 1)
|
2000-01-06 05:56:20 +03:00
|
|
|
static INLINE void
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_print_qentry(struct ispsoftc *isp, char *msg, int idx, void *arg)
|
2000-01-06 05:56:20 +03:00
|
|
|
{
|
2000-08-02 03:55:09 +04:00
|
|
|
char buf[TBA];
|
2000-01-06 05:56:20 +03:00
|
|
|
int amt, i, j;
|
|
|
|
u_int8_t *ptr = arg;
|
2000-08-02 03:55:09 +04:00
|
|
|
|
2001-03-02 07:51:14 +03:00
|
|
|
isp_prt(isp, ISP_LOGALL, "%s index %d=>", msg, idx);
|
2000-08-02 03:55:09 +04:00
|
|
|
for (buf[0] = 0, amt = i = 0; i < 4; i++) {
|
|
|
|
buf[0] = 0;
|
2001-03-02 07:51:14 +03:00
|
|
|
SNPRINTF(buf, TBA, " ");
|
2000-01-06 05:56:20 +03:00
|
|
|
for (j = 0; j < (QENTRY_LEN >> 2); j++) {
|
2000-08-02 03:55:09 +04:00
|
|
|
SNPRINTF(buf, TBA, "%s %02x", buf, ptr[amt++] & 0xff);
|
|
|
|
}
|
2001-03-02 07:51:14 +03:00
|
|
|
isp_prt(isp, ISP_LOGALL, buf);
|
2000-08-02 03:55:09 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-03-14 07:55:21 +03:00
|
|
|
static INLINE void isp_print_bytes(struct ispsoftc *, char *, int, void *);
|
2000-08-02 03:55:09 +04:00
|
|
|
|
|
|
|
static INLINE void
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_print_bytes(struct ispsoftc *isp, char *msg, int amt, void *arg)
|
2000-08-02 03:55:09 +04:00
|
|
|
{
|
|
|
|
char buf[128];
|
|
|
|
u_int8_t *ptr = arg;
|
|
|
|
int off;
|
|
|
|
|
2000-08-28 01:43:26 +04:00
|
|
|
if (msg)
|
|
|
|
isp_prt(isp, ISP_LOGALL, "%s:", msg);
|
2000-08-02 03:55:09 +04:00
|
|
|
off = 0;
|
2000-08-28 01:43:26 +04:00
|
|
|
buf[0] = 0;
|
2000-08-02 03:55:09 +04:00
|
|
|
while (off < amt) {
|
|
|
|
int j, to;
|
|
|
|
to = off;
|
|
|
|
for (j = 0; j < 16; j++) {
|
|
|
|
SNPRINTF(buf, 128, "%s %02x", buf, ptr[off++] & 0xff);
|
|
|
|
if (off == amt)
|
|
|
|
break;
|
2000-01-06 05:56:20 +03:00
|
|
|
}
|
2000-08-28 01:43:26 +04:00
|
|
|
isp_prt(isp, ISP_LOGALL, "0x%08x:%s", to, buf);
|
|
|
|
buf[0] = 0;
|
2000-01-06 05:56:20 +03:00
|
|
|
}
|
|
|
|
}
|
2001-02-13 02:29:26 +03:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Do the common path to try and ensure that link is up, we've scanned
|
|
|
|
* the fabric (if we're on a fabric), and that we've synchronized this
|
|
|
|
* all with our own database and done the appropriate logins.
|
|
|
|
*
|
|
|
|
* We repeatedly check for firmware state and loop state after each
|
|
|
|
* action because things may have changed while we were doing this.
|
|
|
|
* Any failure or change of state causes us to return a nonzero value.
|
|
|
|
*
|
|
|
|
* We honor HBA roles in that if we're not in Initiator mode, we don't
|
|
|
|
* attempt to sync up the database (that's for somebody else to do,
|
|
|
|
* if ever).
|
|
|
|
*
|
|
|
|
* We assume we enter here with any locks held.
|
|
|
|
*/
|
|
|
|
|
2001-03-14 07:55:21 +03:00
|
|
|
static INLINE int isp_fc_runstate(struct ispsoftc *, int);
|
2001-02-13 02:29:26 +03:00
|
|
|
|
|
|
|
static INLINE int
|
2001-03-14 07:55:21 +03:00
|
|
|
isp_fc_runstate(struct ispsoftc *isp, int tval)
|
2001-02-13 02:29:26 +03:00
|
|
|
{
|
|
|
|
fcparam *fcp;
|
|
|
|
int *tptr;
|
|
|
|
|
|
|
|
if (IS_SCSI(isp))
|
|
|
|
return (0);
|
|
|
|
|
|
|
|
tptr = tval? &tval : NULL;
|
|
|
|
if (isp_control(isp, ISPCTL_FCLINK_TEST, tptr) != 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
fcp = FCPARAM(isp);
|
|
|
|
if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate < LOOP_PDB_RCVD)
|
|
|
|
return (-1);
|
|
|
|
if (isp_control(isp, ISPCTL_SCAN_FABRIC, NULL) != 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (isp_control(isp, ISPCTL_SCAN_LOOP, NULL) != 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if ((isp->isp_role & ISP_ROLE_INITIATOR) == 0) {
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
if (isp_control(isp, ISPCTL_PDB_SYNC, NULL) != 0) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
if (fcp->isp_fwstate != FW_READY || fcp->isp_loopstate != LOOP_READY) {
|
|
|
|
return (-1);
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
1999-10-14 06:16:55 +04:00
|
|
|
#endif /* _ISP_INLINE_H */
|