Core version 2.0 cleanup/rewrite. Things get rearranged and changed

quite a bit so that all of the ports have a similar set of required
macros/definitions (and in similar places in the isp_<platform>.h
file).

Some new macros/functions added- Mailbox Acquire/Relase macros,
NANOTIME macros, SNPRINTf and STRNCAT. MemoryBarrier beomes
MEMORYBARRIER with much stronger types.
This commit is contained in:
Matt Jacob 2000-08-01 06:29:55 +00:00
parent 16dd34376c
commit 18ccaecd45
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=64092

View file

@ -35,7 +35,7 @@
#define _ISP_FREEBSD_H
#define ISP_PLATFORM_VERSION_MAJOR 5
#define ISP_PLATFORM_VERSION_MINOR 2
#define ISP_PLATFORM_VERSION_MINOR 3
#include <sys/param.h>
@ -64,23 +64,7 @@
#include "opt_ddb.h"
#include "opt_isp.h"
/*
* We are now always supporting fabric mode.
*/
#define ISP2100_FABRIC 1
#define ISP2100_SCRLEN 0x400
#ifndef SCSI_CHECK
#define SCSI_CHECK SCSI_STATUS_CHECK_COND
#endif
#ifndef SCSI_BUSY
#define SCSI_BUSY SCSI_STATUS_BUSY
#endif
#ifndef SCSI_QFULL
#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
#endif
#define ISP_SCSI_XFER_T struct ccb_scsiio
typedef void ispfwfunc __P((int, int, int, const u_int16_t **));
#ifdef ISP_TARGET_MODE
@ -132,6 +116,145 @@ struct isposinfo {
tstate_t *lun_hash[LUN_HASH_SIZE];
#endif
};
/*
* Required Macros/Defines
*/
#define INLINE __inline
#define ISP2100_FABRIC 1
#define ISP2100_SCRLEN 0x400
#define MEMZERO bzero
#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
#define SNPRINTF snprintf
#define STRNCAT strncat
#define USEC_DELAY DELAY
#define NANOTIME_T struct timespec
#define GET_NANOTIME nanotime
#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec)
#define NANOTIME_SUB nanotime_sub
#define MAXISPREQUEST(isp) 256
#ifdef __alpha__
#define MEMORYBARRIER(isp, type, offset, size) alpha_mb()
#else
#define MEMORYBARRIER(isp, type, offset, size)
#endif
#define MBOX_ACQUIRE(isp)
#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete
#define MBOX_NOTIFY_COMPLETE(isp) \
if (isp->isp_osinfo.mboxwaiting) { \
isp->isp_osinfo.mboxwaiting = 0; \
wakeup(&isp->isp_osinfo.mboxwaiting); \
} \
isp->isp_mboxbsy = 0
#define MBOX_RELEASE(isp)
#ifndef SCSI_GOOD
#define SCSI_GOOD SCSI_STATUS_OK
#endif
#ifndef SCSI_CHECK
#define SCSI_CHECK SCSI_STATUS_CHECK_COND
#endif
#ifndef SCSI_BUSY
#define SCSI_BUSY SCSI_STATUS_BUSY
#endif
#ifndef SCSI_QFULL
#define SCSI_QFULL SCSI_STATUS_QUEUE_FULL
#endif
#define XS_T struct ccb_scsiio
#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
#define XS_TGT(ccb) (ccb)->ccb_h.target_id
#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
#define XS_CDBP(ccb) \
(((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
(ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
#define XS_CDBLEN(ccb) (ccb)->cdb_len
#define XS_XFRLEN(ccb) (ccb)->dxfer_len
#define XS_TIME(ccb) (ccb)->ccb_h.timeout
#define XS_RESID(ccb) (ccb)->resid
#define XS_STSP(ccb) (&(ccb)->scsi_status)
#define XS_SNSP(ccb) (&(ccb)->sense_data)
#define XS_SNSLEN(ccb) \
imin((sizeof((ccb)->sense_data)), ccb->sense_len)
#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
#define XS_TAG_P(ccb) \
(((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) && \
(ccb)->tag_action != CAM_TAG_ACTION_NONE)
#define XS_TAG_TYPE(ccb) \
((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
(ccb)->ccb_h.status |= v, \
(ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
# define HBA_NOERROR CAM_REQ_INPROG
# define HBA_BOTCH CAM_UNREC_HBA_ERROR
# define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
# define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
# define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
# define HBA_BUSRESET CAM_SCSI_BUS_RESET
# define HBA_ABORTED CAM_REQ_ABORTED
# define HBA_DATAOVR CAM_DATA_RUN_ERR
# define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
#define XS_NOERR(ccb) \
(((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
#define XS_INITERR(ccb) \
XS_SETERR(ccb, CAM_REQ_INPROG), (ccb)->ccb_h.spriv_field0 = 0
#define XS_SAVE_SENSE(xs, sp) \
bcopy(sp->req_sense_data, &(xs)->sense_data, \
imin(XS_SNSLEN(xs), sp->req_sense_len))
#define XS_SET_STATE_STAT(a, b, c)
#define DEFAULT_IID(x) 7
#define DEFAULT_LOOPID(x) 109
#define DEFAULT_NODEWWN(isp) (isp)->isp_osinfo.default_wwn
#define DEFAULT_PORTWWN(isp) \
isp_port_from_node_wwn((isp), (isp)->isp_osinfo.default_wwn)
#define PORT_FROM_NODE_WWN isp_port_from_node_wwn
#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
if((void *)src != (void *)dest) bcopy(src, dest, sizeof (isp_pdb_t))
#define ISP_SWIZZLE_ICB(a, b)
#define ISP_SWIZZLE_REQUEST(a, b)
#define ISP_UNSWIZZLE_RESPONSE(a, b, c)
#define ISP_SWIZZLE_SNS_REQ(a, b)
#define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
#define ISP_SWIZZLE_NVRAM_WORD(isp, x)
/*
* Includes of common header files
*/
#include <dev/isp/ispreg.h>
#include <dev/isp/ispvar.h>
#include <dev/isp/ispmbox.h>
/*
* isp_osinfo definiitions && shorthand
*/
#define SIMQFRZ_RESOURCE 0x1
#define SIMQFRZ_LOOPDOWN 0x2
#define SIMQFRZ_TIMED 0x4
@ -143,108 +266,27 @@ struct isposinfo {
#define isp_unit isp_osinfo.unit
#define isp_name isp_osinfo.name
#define MAXISPREQUEST 256
/*
* prototypes for isp_pci && isp_freebsd to share
*/
extern void isp_attach(struct ispsoftc *);
extern void isp_uninit(struct ispsoftc *);
#include <dev/isp/ispreg.h>
#include <dev/isp/ispvar.h>
#include <dev/isp/ispmbox.h>
#define DFLT_DBLEVEL isp_debug
extern int isp_debug;
static __inline void isp_lock(struct ispsoftc *);
static __inline void isp_unlock(struct ispsoftc *);
static __inline void
isp_lock(struct ispsoftc *isp)
{
int s = splcam();
if (isp->isp_osinfo.islocked == 0) {
isp->isp_osinfo.islocked = 1;
isp->isp_osinfo.splsaved = s;
} else {
splx(s);
}
}
static __inline void
isp_unlock(struct ispsoftc *isp)
{
if (isp->isp_osinfo.islocked) {
isp->isp_osinfo.islocked = 0;
splx(isp->isp_osinfo.splsaved);
}
}
/*
* Locking macros...
*/
#define ISP_LOCK isp_lock
#define ISP_UNLOCK isp_unlock
#define SERVICING_INTERRUPT(isp) 1
/* not ready yet... */
/* not safely working yet */
#if 0
#define SERVICING_INTERRUPT(isp) (intr_nesting_level != 0)
#endif
#define MBOX_WAIT_COMPLETE(isp) \
if (isp->isp_osinfo.intsok == 0 || SERVICING_INTERRUPT(isp)) { \
int j; \
for (j = 0; j < 60 * 2000; j++) { \
if (isp_intr(isp) == 0) { \
SYS_DELAY(500); \
} \
if (isp->isp_mboxbsy == 0) \
break; \
} \
if (isp->isp_mboxbsy != 0) \
printf("%s: mailbox timeout\n", isp->isp_name); \
} else { \
isp->isp_osinfo.mboxwaiting = 1; \
while (isp->isp_mboxbsy != 0) \
(void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO, \
"isp_mailbox", 0);\
}
#define MBOX_NOTIFY_COMPLETE(isp) \
if (isp->isp_osinfo.mboxwaiting) { \
isp->isp_osinfo.mboxwaiting = 0; \
wakeup(&isp->isp_osinfo.mboxwaiting); \
} \
isp->isp_mboxbsy = 0
#define XS_NULL(ccb) ccb == NULL
#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1)
#define XS_LUN(ccb) (ccb)->ccb_h.target_lun
#define XS_TGT(ccb) (ccb)->ccb_h.target_id
#define XS_CHANNEL(ccb) cam_sim_bus(xpt_path_sim((ccb)->ccb_h.path))
#define XS_RESID(ccb) (ccb)->resid
#define XS_XFRLEN(ccb) (ccb)->dxfer_len
#define XS_CDBLEN(ccb) (ccb)->cdb_len
#define XS_CDBP(ccb) (((ccb)->ccb_h.flags & CAM_CDB_POINTER)? \
(ccb)->cdb_io.cdb_ptr : (ccb)->cdb_io.cdb_bytes)
#define XS_STS(ccb) (ccb)->scsi_status
#define XS_TIME(ccb) (ccb)->ccb_h.timeout
#define XS_SNSP(ccb) (&(ccb)->sense_data)
#define XS_SNSLEN(ccb) \
imin((sizeof((ccb)->sense_data)), ccb->sense_len)
#define XS_SNSKEY(ccb) ((ccb)->sense_data.flags & 0xf)
/*
* A little tricky- HBA_NOERROR is "in progress" so
* that XS_CMD_DONE can transition this to CAM_REQ_CMP.
* Platform private flags
*/
#define HBA_NOERROR CAM_REQ_INPROG
#define HBA_BOTCH CAM_UNREC_HBA_ERROR
#define HBA_CMDTIMEOUT CAM_CMD_TIMEOUT
#define HBA_SELTIMEOUT CAM_SEL_TIMEOUT
#define HBA_TGTBSY CAM_SCSI_STATUS_ERROR
#define HBA_BUSRESET CAM_SCSI_BUS_RESET
#define HBA_ABORTED CAM_REQ_ABORTED
#define HBA_DATAOVR CAM_DATA_RUN_ERR
#define HBA_ARQFAIL CAM_AUTOSENSE_FAIL
#define XS_SNS_IS_VALID(ccb) ((ccb)->ccb_h.status |= CAM_AUTOSNS_VALID)
#define XS_IS_SNS_VALID(ccb) (((ccb)->ccb_h.status & CAM_AUTOSNS_VALID) != 0)
#define ISP_SPRIV_ERRSET 0x1
#define ISP_SPRIV_INWDOG 0x2
#define ISP_SPRIV_GRACE 0x4
@ -263,71 +305,89 @@ isp_unlock(struct ispsoftc *isp)
#define XS_CMD_DONE_P(sccb) ((sccb)->ccb_h.spriv_field0 & ISP_SPRIV_DONE)
#define XS_CMD_S_CLEAR(sccb) (sccb)->ccb_h.spriv_field0 = 0
#define XS_SETERR(ccb, v) (ccb)->ccb_h.status &= ~CAM_STATUS_MASK, \
(ccb)->ccb_h.status |= v, \
(ccb)->ccb_h.spriv_field0 |= ISP_SPRIV_ERRSET
#define XS_INITERR(ccb) XS_SETERR(ccb, CAM_REQ_INPROG), \
XS_CMD_S_CLEAR(ccb)
#define XS_ERR(ccb) ((ccb)->ccb_h.status & CAM_STATUS_MASK)
#define XS_NOERR(ccb) \
(((ccb)->ccb_h.spriv_field0 & ISP_SPRIV_ERRSET) == 0 || \
((ccb)->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG)
#define XS_CMD_DONE isp_done
extern void isp_done(struct ccb_scsiio *);
/*
* Can we tag?
* Platform specific inline functions
*/
#define XS_CANTAG(ccb) (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \
&& (ccb)->tag_action != CAM_TAG_ACTION_NONE)
/*
* And our favorite tag is....
*/
#define XS_KINDOF_TAG(ccb) \
((ccb->tag_action == MSG_SIMPLE_Q_TAG)? REQFLAG_STAG : \
((ccb->tag_action == MSG_HEAD_OF_Q_TAG)? REQFLAG_HTAG : REQFLAG_OTAG))
#define CMD_COMPLETE 0
#define CMD_EAGAIN 1
#define CMD_QUEUED 2
#define CMD_RQLATER 3
extern void isp_attach(struct ispsoftc *);
extern void isp_uninit(struct ispsoftc *);
static INLINE void isp_lock(struct ispsoftc *);
static INLINE void
isp_lock(struct ispsoftc *isp)
{
int s = splcam();
if (isp->isp_osinfo.islocked == 0) {
isp->isp_osinfo.islocked = 1;
isp->isp_osinfo.splsaved = s;
} else {
splx(s);
}
}
#define MEMZERO bzero
#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt))
#ifdef __alpha__
#define MemoryBarrier alpha_mb
static INLINE void isp_unlock(struct ispsoftc *);
static INLINE void
isp_unlock(struct ispsoftc *isp)
{
if (isp->isp_osinfo.islocked) {
isp->isp_osinfo.islocked = 0;
splx(isp->isp_osinfo.splsaved);
}
}
static INLINE void isp_mbox_wait_complete(struct ispsoftc *);
static INLINE void
isp_mbox_wait_complete(struct ispsoftc *isp)
{
#ifdef SERVICING_INTERRUPT
if (isp->isp_osinfo.intsok == 0 || SERVICING_INTERRUPT(isp)) {
int j;
for (j = 0; j < 60 * 2000; j++) {
if (isp_intr(isp) == 0) {
USEC_DELAY(500);
}
if (isp->isp_mboxbsy == 0) {
break;
}
}
if (isp->isp_mboxbsy != 0) {
isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
}
} else {
isp->isp_osinfo.mboxwaiting = 1;
while (isp->isp_mboxbsy != 0) {
(void) tsleep(&isp->isp_osinfo.mboxwaiting, PRIBIO,
"isp_mailbox", 0);
}
}
#else
#define MemoryBarrier()
int j;
for (j = 0; j < 60 * 2000; j++) {
if (isp_intr(isp) == 0) {
USEC_DELAY(500);
}
if (isp->isp_mboxbsy == 0) {
break;
}
}
if (isp->isp_mboxbsy != 0) {
isp_prt(isp, ISP_LOGWARN, "mailbox timeout");
}
#endif
}
static INLINE u_int64_t nanotime_sub(struct timespec *, struct timespec *);
static INLINE u_int64_t
nanotime_sub(struct timespec *b, struct timespec *a)
{
u_int64_t elapsed;
struct timespec x = *b;
timespecsub(&x, a);
elapsed = GET_NANOSEC(&x);
if (elapsed == 0)
elapsed++;
return (elapsed);
}
#define DMA_MSW(x) (((x) >> 16) & 0xffff)
#define DMA_LSW(x) (((x) & 0xffff))
#define ISP_UNSWIZZLE_AND_COPY_PDBP(isp, dest, src) \
bcopy(src, dest, sizeof (isp_pdb_t))
#define ISP_SWIZZLE_ICB(a, b)
#define ISP_SWIZZLE_REQUEST(a, b)
#define ISP_UNSWIZZLE_RESPONSE(a, b)
#define ISP_SWIZZLE_SNS_REQ(a, b)
#define ISP_UNSWIZZLE_SNS_RSP(a, b, c)
#define IDPRINTF(lev, x) if (isp->isp_dblev >= (u_int8_t) lev) printf x
#define PRINTF printf
#define CFGPRINTF if (bootverbose || DFLT_DBLEVEL > 1) printf
#define STRNCAT strncat
static __inline char *strncat(char *, const char *, size_t);
static __inline char *
static INLINE char *strncat(char *, const char *, size_t);
static INLINE char *
strncat(char *d, const char *s, size_t c)
{
char *t = d;
@ -345,12 +405,21 @@ strncat(char *d, const char *s, size_t c)
return (t);
}
#define SYS_DELAY(x) DELAY(x)
static INLINE u_int64_t isp_port_from_node_wwn(struct ispsoftc *, u_int64_t);
static INLINE u_int64_t
isp_port_from_node_wwn(struct ispsoftc *isp, u_int64_t node_wwn)
{
u_int64_t rv = node_wwn;
if ((node_wwn >> 60) == 2) {
rv = node_wwn |
(((u_int64_t)(isp->isp_unit+1)) << 48);
}
return (rv);
}
#define FC_FW_READY_DELAY (5 * 1000000)
#define DEFAULT_LOOPID(x) 109
#define DEFAULT_WWN(x) (x)->isp_osinfo.default_wwn
/*
* Common inline functions
*/
#define INLINE __inline
#include <dev/isp/isp_inline.h>
#endif /* _ISP_FREEBSD_H */