From 1da31893fa06c4a2052adfd348aa65836f6a79bf Mon Sep 17 00:00:00 2001 From: mjacob Date: Tue, 1 Aug 2000 06:29:55 +0000 Subject: 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_.h file). Some new macros/functions added- Mailbox Acquire/Relase macros, NANOTIME macros, SNPRINTf and STRNCAT. MemoryBarrier beomes MEMORYBARRIER with much stronger types. --- sys/dev/isp/isp_freebsd.h | 397 +++++++++++++++++++++++++++------------------- 1 file changed, 233 insertions(+), 164 deletions(-) (limited to 'sys/dev/isp/isp_freebsd.h') diff --git a/sys/dev/isp/isp_freebsd.h b/sys/dev/isp/isp_freebsd.h index d2e7832..7a88c9f 100644 --- a/sys/dev/isp/isp_freebsd.h +++ b/sys/dev/isp/isp_freebsd.h @@ -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 @@ -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,119 +116,177 @@ struct isposinfo { tstate_t *lun_hash[LUN_HASH_SIZE]; #endif }; -#define SIMQFRZ_RESOURCE 0x1 -#define SIMQFRZ_LOOPDOWN 0x2 -#define SIMQFRZ_TIMED 0x4 -#define isp_sim isp_osinfo.sim -#define isp_path isp_osinfo.path -#define isp_sim2 isp_osinfo.sim2 -#define isp_path2 isp_osinfo.path2 -#define isp_unit isp_osinfo.unit -#define isp_name isp_osinfo.name - -#define MAXISPREQUEST 256 +/* + * Required Macros/Defines + */ -#include -#include -#include +#define INLINE __inline -#define DFLT_DBLEVEL isp_debug -extern int isp_debug; +#define ISP2100_FABRIC 1 +#define ISP2100_SCRLEN 0x400 -static __inline void isp_lock(struct ispsoftc *); -static __inline void isp_unlock(struct ispsoftc *); +#define MEMZERO bzero +#define MEMCPY(dst, src, amt) bcopy((src), (dst), (amt)) +#define SNPRINTF snprintf +#define STRNCAT strncat +#define USEC_DELAY DELAY -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 NANOTIME_T struct timespec +#define GET_NANOTIME nanotime +#define GET_NANOSEC(x) ((x)->tv_sec * 1000000000 + (x)->tv_nsec) +#define NANOTIME_SUB nanotime_sub -static __inline void -isp_unlock(struct ispsoftc *isp) -{ - if (isp->isp_osinfo.islocked) { - isp->isp_osinfo.islocked = 0; - splx(isp->isp_osinfo.splsaved); - } -} +#define MAXISPREQUEST(isp) 256 -#define ISP_LOCK isp_lock -#define ISP_UNLOCK isp_unlock -#define SERVICING_INTERRUPT(isp) 1 -/* not ready yet... */ -#if 0 -#define SERVICING_INTERRUPT(isp) (intr_nesting_level != 0) +#ifdef __alpha__ +#define MEMORYBARRIER(isp, type, offset, size) alpha_mb() +#else +#define MEMORYBARRIER(isp, type, offset, size) #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_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) -#define XS_NULL(ccb) ccb == NULL -#define XS_ISP(ccb) ((struct ispsoftc *) (ccb)->ccb_h.spriv_ptr1) +#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_LUN(ccb) (ccb)->ccb_h.target_lun -#define XS_TGT(ccb) (ccb)->ccb_h.target_id +#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_RESID(ccb) (ccb)->resid -#define XS_XFRLEN(ccb) (ccb)->dxfer_len +#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_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_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 +#include +#include + +/* + * isp_osinfo definiitions && shorthand + */ +#define SIMQFRZ_RESOURCE 0x1 +#define SIMQFRZ_LOOPDOWN 0x2 +#define SIMQFRZ_TIMED 0x4 + +#define isp_sim isp_osinfo.sim +#define isp_path isp_osinfo.path +#define isp_sim2 isp_osinfo.sim2 +#define isp_path2 isp_osinfo.path2 +#define isp_unit isp_osinfo.unit +#define isp_name isp_osinfo.name + +/* + * prototypes for isp_pci && isp_freebsd to share + */ +extern void isp_attach(struct ispsoftc *); +extern void isp_uninit(struct ispsoftc *); /* - * A little tricky- HBA_NOERROR is "in progress" so - * that XS_CMD_DONE can transition this to CAM_REQ_CMP. + * Locking macros... */ -#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_LOCK isp_lock +#define ISP_UNLOCK isp_unlock + +/* not safely working yet */ +#if 0 +#define SERVICING_INTERRUPT(isp) (intr_nesting_level != 0) +#endif + +/* + * Platform private flags + */ #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? - */ -#define XS_CANTAG(ccb) (((ccb)->ccb_h.flags & CAM_TAG_ACTION_VALID) \ - && (ccb)->tag_action != CAM_TAG_ACTION_NONE) /* - * And our favorite tag is.... + * Platform specific inline functions */ -#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 #endif /* _ISP_FREEBSD_H */ -- cgit v1.1