Index: projects/sendfile/sbin/fsck/fsck.c =================================================================== --- projects/sendfile/sbin/fsck/fsck.c (revision 274764) +++ projects/sendfile/sbin/fsck/fsck.c (revision 274765) @@ -1,581 +1,585 @@ /* $NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $ */ /* * Copyright (c) 1996 Christos Zoulas. All rights reserved. * Copyright (c) 1980, 1989, 1993, 1994 * The Regents of the University of California. 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. Neither the name of the University nor the names of its contributors * may be used to endorse or promote products derived from this software * without specific prior written permission. * * THIS SOFTWARE IS PROVIDED BY THE REGENTS 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 REGENTS 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. * * From: @(#)mount.c 8.19 (Berkeley) 4/19/94 * From: $NetBSD: mount.c,v 1.24 1995/11/18 03:34:29 cgd Exp * $NetBSD: fsck.c,v 1.30 2003/08/07 10:04:15 agc Exp $ */ #include __FBSDID("$FreeBSD$"); #include #include #include #include -#include +#define FSTYPENAMES +#include #include #include #include #include #include #include #include #include #include #include #include #include #include "fsutil.h" static enum { IN_LIST, NOT_IN_LIST } which = NOT_IN_LIST; static TAILQ_HEAD(fstypelist, entry) opthead, selhead; struct entry { char *type; char *options; TAILQ_ENTRY(entry) entries; }; static char *options = NULL; static int flags = 0; static int forceflag = 0; static int checkfs(const char *, const char *, const char *, const char *, pid_t *); static int selected(const char *); static void addoption(char *); static const char *getoptions(const char *); static void addentry(struct fstypelist *, const char *, const char *); static void maketypelist(char *); static void catopt(char **, const char *); static void mangle(char *, int *, const char ** volatile *, int *); -static const char *getfstype(const char *); +static const char *getfslab(const char *); static void usage(void) __dead2; static int isok(struct fstab *); -static struct { - const char *ptype; - const char *name; -} ptype_map[] = { - { "ufs", "ffs" }, - { "ffs", "ffs" }, - { "fat", "msdosfs" }, - { "efi", "msdosfs" }, - { NULL, NULL }, -}; - int main(int argc, char *argv[]) { struct fstab *fs; int i, rval = 0; const char *vfstype = NULL; char globopt[3]; const char *etc_fstab; globopt[0] = '-'; globopt[2] = '\0'; TAILQ_INIT(&selhead); TAILQ_INIT(&opthead); etc_fstab = NULL; while ((i = getopt(argc, argv, "BCdvpfFnyl:t:T:c:")) != -1) switch (i) { case 'B': if (flags & CHECK_BACKGRD) errx(1, "Cannot specify -B and -F."); flags |= DO_BACKGRD; break; case 'd': flags |= CHECK_DEBUG; break; case 'v': flags |= CHECK_VERBOSE; break; case 'F': if (flags & DO_BACKGRD) errx(1, "Cannot specify -B and -F."); flags |= CHECK_BACKGRD; break; case 'p': flags |= CHECK_PREEN; /*FALLTHROUGH*/ case 'C': flags |= CHECK_CLEAN; /*FALLTHROUGH*/ case 'n': case 'y': globopt[1] = i; catopt(&options, globopt); break; case 'f': forceflag = 1; globopt[1] = i; catopt(&options, globopt); break; case 'l': warnx("Ignoring obsolete -l option\n"); break; case 'T': if (*optarg) addoption(optarg); break; case 't': if (!TAILQ_EMPTY(&selhead)) errx(1, "only one -t option may be specified."); maketypelist(optarg); vfstype = optarg; break; case 'c': etc_fstab = optarg; break; case '?': default: usage(); /* NOTREACHED */ } argc -= optind; argv += optind; if (etc_fstab != NULL) setfstab(etc_fstab); if (argc == 0) return checkfstab(flags, isok, checkfs); #define BADTYPE(type) \ (strcmp(type, FSTAB_RO) && \ strcmp(type, FSTAB_RW) && strcmp(type, FSTAB_RQ)) for (; argc--; argv++) { const char *spec, *mntpt, *type, *cp; char device[MAXPATHLEN]; struct statfs *mntp; mntpt = NULL; spec = *argv; cp = strrchr(spec, '/'); if (cp == 0) { (void)snprintf(device, sizeof(device), "%s%s", _PATH_DEV, spec); spec = device; } mntp = getmntpt(spec); if (mntp != NULL) { spec = mntp->f_mntfromname; mntpt = mntp->f_mntonname; } if ((fs = getfsfile(spec)) == NULL && (fs = getfsspec(spec)) == NULL) { if (vfstype == NULL) - vfstype = getfstype(spec); + vfstype = getfslab(spec); if (vfstype == NULL) errx(1, "Could not determine filesystem type"); type = vfstype; devcheck(spec); } else { spec = fs->fs_spec; type = fs->fs_vfstype; mntpt = fs->fs_file; if (BADTYPE(fs->fs_type)) errx(1, "%s has unknown file system type.", spec); } if ((flags & CHECK_BACKGRD) && checkfs(type, spec, mntpt, "-F", NULL) == 0) { printf("%s: DEFER FOR BACKGROUND CHECKING\n", *argv); continue; } if ((flags & DO_BACKGRD) && forceflag == 0 && checkfs(type, spec, mntpt, "-F", NULL) != 0) continue; rval |= checkfs(type, spec, mntpt, NULL, NULL); } return rval; } static int isok(struct fstab *fs) { int i; if (fs->fs_passno == 0) return (0); if (BADTYPE(fs->fs_type)) return (0); if (!selected(fs->fs_vfstype)) return (0); /* * If the -B flag has been given, then process the needed * background checks. Background checks cannot be run on * file systems that will be mounted read-only or that were * not mounted at boot time (typically those marked `noauto'). * If these basic tests are passed, check with the file system * itself to see if it is willing to do background checking * by invoking its check program with the -F flag. */ if (flags & DO_BACKGRD) { if (!strcmp(fs->fs_type, FSTAB_RO)) return (0); if (getmntpt(fs->fs_spec) == NULL) return (0); if (checkfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, "-F", 0)) return (0); return (1); } /* * If the -F flag has been given, then consider deferring the * check to background. Background checks cannot be run on * file systems that will be mounted read-only or that will * not be mounted at boot time (e.g., marked `noauto'). If * these basic tests are passed, check with the file system * itself to see if it is willing to defer to background * checking by invoking its check program with the -F flag. */ if ((flags & CHECK_BACKGRD) == 0 || !strcmp(fs->fs_type, FSTAB_RO)) return (1); for (i = strlen(fs->fs_mntops) - 6; i >= 0; i--) if (!strncmp(&fs->fs_mntops[i], "noauto", 6)) break; if (i >= 0) return (1); if (checkfs(fs->fs_vfstype, fs->fs_spec, fs->fs_file, "-F", NULL) != 0) return (1); printf("%s: DEFER FOR BACKGROUND CHECKING\n", fs->fs_spec); return (0); } static int checkfs(const char *pvfstype, const char *spec, const char *mntpt, const char *auxopt, pid_t *pidp) { const char ** volatile argv; pid_t pid; int argc, i, status, maxargc; char *optbuf, execbase[MAXPATHLEN]; char *vfstype = NULL; const char *extra = NULL; #ifdef __GNUC__ /* Avoid vfork clobbering */ (void) &optbuf; (void) &vfstype; #endif /* * We convert the vfstype to lowercase and any spaces to underscores * to not confuse the issue * * XXX This is a kludge to make automatic filesystem type guessing * from the disklabel work for "4.2BSD" filesystems. It does a * very limited subset of transliteration to a normalised form of * filesystem name, and we do not seem to enforce a filesystem * name character set. */ vfstype = strdup(pvfstype); if (vfstype == NULL) perr("strdup(pvfstype)"); for (i = 0; i < (int)strlen(vfstype); i++) { vfstype[i] = tolower(vfstype[i]); if (vfstype[i] == ' ') vfstype[i] = '_'; } extra = getoptions(vfstype); optbuf = NULL; if (options) catopt(&optbuf, options); if (extra) catopt(&optbuf, extra); if (auxopt) catopt(&optbuf, auxopt); else if (flags & DO_BACKGRD) catopt(&optbuf, "-B"); maxargc = 64; argv = emalloc(sizeof(char *) * maxargc); (void) snprintf(execbase, sizeof(execbase), "fsck_%s", vfstype); argc = 0; argv[argc++] = execbase; if (optbuf) mangle(optbuf, &argc, &argv, &maxargc); argv[argc++] = spec; argv[argc] = NULL; if (flags & (CHECK_DEBUG|CHECK_VERBOSE)) { (void)printf("start %s %swait", mntpt, pidp ? "no" : ""); for (i = 0; i < argc; i++) (void)printf(" %s", argv[i]); (void)printf("\n"); } switch (pid = vfork()) { case -1: /* Error. */ warn("vfork"); if (optbuf) free(optbuf); free(vfstype); return (1); case 0: /* Child. */ if ((flags & CHECK_DEBUG) && auxopt == NULL) _exit(0); /* Go find an executable. */ execvP(execbase, _PATH_SYSPATH, __DECONST(char * const *, argv)); if (spec) warn("exec %s for %s in %s", execbase, spec, _PATH_SYSPATH); else warn("exec %s in %s", execbase, _PATH_SYSPATH); _exit(1); /* NOTREACHED */ default: /* Parent. */ if (optbuf) free(optbuf); free(vfstype); if (pidp) { *pidp = pid; return 0; } if (waitpid(pid, &status, 0) < 0) { warn("waitpid"); return (1); } if (WIFEXITED(status)) { if (WEXITSTATUS(status) != 0) return (WEXITSTATUS(status)); } else if (WIFSIGNALED(status)) { warnx("%s: %s", spec, strsignal(WTERMSIG(status))); return (1); } break; } return (0); } static int selected(const char *type) { struct entry *e; /* If no type specified, it's always selected. */ TAILQ_FOREACH(e, &selhead, entries) if (!strncmp(e->type, type, MFSNAMELEN)) return which == IN_LIST ? 1 : 0; return which == IN_LIST ? 0 : 1; } static const char * getoptions(const char *type) { struct entry *e; TAILQ_FOREACH(e, &opthead, entries) if (!strncmp(e->type, type, MFSNAMELEN)) return e->options; return ""; } static void addoption(char *optstr) { char *newoptions; struct entry *e; if ((newoptions = strchr(optstr, ':')) == NULL) errx(1, "Invalid option string"); *newoptions++ = '\0'; TAILQ_FOREACH(e, &opthead, entries) if (!strncmp(e->type, optstr, MFSNAMELEN)) { catopt(&e->options, newoptions); return; } addentry(&opthead, optstr, newoptions); } static void addentry(struct fstypelist *list, const char *type, const char *opts) { struct entry *e; e = emalloc(sizeof(struct entry)); e->type = estrdup(type); e->options = estrdup(opts); TAILQ_INSERT_TAIL(list, e, entries); } static void maketypelist(char *fslist) { char *ptr; if ((fslist == NULL) || (fslist[0] == '\0')) errx(1, "empty type list"); if (fslist[0] == 'n' && fslist[1] == 'o') { fslist += 2; which = NOT_IN_LIST; } else which = IN_LIST; while ((ptr = strsep(&fslist, ",")) != NULL) addentry(&selhead, ptr, ""); } static void catopt(char **sp, const char *o) { char *s; size_t i, j; s = *sp; if (s) { i = strlen(s); j = i + 1 + strlen(o) + 1; s = erealloc(s, j); (void)snprintf(s + i, j, ",%s", o); } else s = estrdup(o); *sp = s; } static void mangle(char *opts, int *argcp, const char ** volatile *argvp, int *maxargcp) { char *p, *s; int argc, maxargc; const char **argv; argc = *argcp; argv = *argvp; maxargc = *maxargcp; for (s = opts; (p = strsep(&s, ",")) != NULL;) { /* Always leave space for one more argument and the NULL. */ if (argc >= maxargc - 3) { maxargc <<= 1; argv = erealloc(argv, maxargc * sizeof(char *)); } if (*p != '\0') { if (*p == '-') { argv[argc++] = p; p = strchr(p, '='); if (p) { *p = '\0'; argv[argc++] = p+1; } } else { argv[argc++] = "-o"; argv[argc++] = p; } } } *argcp = argc; *argvp = argv; *maxargcp = maxargc; } + static const char * -getfstype(const char *str) +getfslab(const char *str) { - struct diocgattr_arg attr; - int fd, i; + struct disklabel dl; + int fd; + char p; + const char *vfstype; + u_char t; + /* deduce the file system type from the disk label */ if ((fd = open(str, O_RDONLY)) == -1) err(1, "cannot open `%s'", str); - strncpy(attr.name, "PART::type", sizeof(attr.name)); - memset(&attr.value, 0, sizeof(attr.value)); - attr.len = sizeof(attr.value); - if (ioctl(fd, DIOCGATTR, &attr) == -1) { + if (ioctl(fd, DIOCGDINFO, &dl) == -1) { (void) close(fd); return(NULL); } + (void) close(fd); - for (i = 0; ptype_map[i].ptype != NULL; i++) - if (strstr(attr.value.str, ptype_map[i].ptype) != NULL) - return (ptype_map[i].name); - return (NULL); + + p = str[strlen(str) - 1]; + + if ((p - 'a') >= dl.d_npartitions) + errx(1, "partition `%s' is not defined on disk", str); + + if ((t = dl.d_partitions[p - 'a'].p_fstype) >= FSMAXTYPES) + errx(1, "partition `%s' is not of a legal vfstype", + str); + + if ((vfstype = fstypenames[t]) == NULL) + errx(1, "vfstype `%s' on partition `%s' is not supported", + fstypenames[t], str); + + return vfstype; } static void usage(void) { static const char common[] = "[-Cdfnpvy] [-B | -F] [-T fstype:fsoptions] [-t fstype] [-c fstab]"; (void)fprintf(stderr, "usage: %s %s [special | node] ...\n", getprogname(), common); exit(1); } Index: projects/sendfile/sbin =================================================================== --- projects/sendfile/sbin (revision 274764) +++ projects/sendfile/sbin (revision 274765) Property changes on: projects/sendfile/sbin ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sbin:r274755-274762 Index: projects/sendfile/sys/cam/scsi/scsi_low.c =================================================================== --- projects/sendfile/sys/cam/scsi/scsi_low.c (revision 274764) +++ projects/sendfile/sys/cam/scsi/scsi_low.c (revision 274765) @@ -1,4290 +1,4209 @@ /* $NecBSD: scsi_low.c,v 1.24.10.8 2001/06/26 07:39:44 honda Exp $ */ /* $NetBSD$ */ #include __FBSDID("$FreeBSD$"); #define SCSI_LOW_STATICS #define SCSI_LOW_DEBUG #define SCSI_LOW_NEGOTIATE_BEFORE_SENSE #define SCSI_LOW_START_UP_CHECK /* #define SCSI_LOW_INFO_DETAIL */ /* #define SCSI_LOW_QCLEAR_AFTER_CA */ /* #define SCSI_LOW_FLAGS_QUIRKS_OK */ #define SCSI_LOW_FLAGS_QUIRKS_OK /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. All rights reserved. * * [Ported for FreeBSD CAM] * Copyright (c) 2000, 2001 * MITSUNAGA Noriaki, NOKUBI Hirotaka and TAKAHASHI Yoshihiro. * 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. */ /* * When our host is reselected, * nexus establish processes are little complicated. * Normal steps are followings: * 1) Our host selected by target => target nexus (slp->sl_Tnexus) * 2) Identify msgin => lun nexus (slp->sl_Lnexus) * 3) Qtag msg => ccb nexus (slp->sl_Qnexus) */ #include "opt_ddb.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /************************************************************** * Constants **************************************************************/ #define SCSI_LOW_POLL_HZ 1000 /* functions return values */ #define SCSI_LOW_START_NO_QTAG 0 #define SCSI_LOW_START_QTAG 1 #define SCSI_LOW_DONE_COMPLETE 0 #define SCSI_LOW_DONE_RETRY 1 /* internal disk flags */ #define SCSI_LOW_DISK_DISC 0x00000001 #define SCSI_LOW_DISK_QTAG 0x00000002 #define SCSI_LOW_DISK_LINK 0x00000004 #define SCSI_LOW_DISK_PARITY 0x00000008 #define SCSI_LOW_DISK_SYNC 0x00010000 #define SCSI_LOW_DISK_WIDE_16 0x00020000 #define SCSI_LOW_DISK_WIDE_32 0x00040000 #define SCSI_LOW_DISK_WIDE (SCSI_LOW_DISK_WIDE_16 | SCSI_LOW_DISK_WIDE_32) #define SCSI_LOW_DISK_LFLAGS 0x0000ffff #define SCSI_LOW_DISK_TFLAGS 0xffff0000 static MALLOC_DEFINE(M_SCSILOW, "SCSI low", "SCSI low buffers"); /************************************************************** * Declarations **************************************************************/ /* static */ void scsi_low_info(struct scsi_low_softc *, struct targ_info *, u_char *); static void scsi_low_engage(void *); static struct slccb *scsi_low_establish_ccb(struct targ_info *, struct lun_info *, scsi_low_tag_t); static int scsi_low_done(struct scsi_low_softc *, struct slccb *); static int scsi_low_setup_done(struct scsi_low_softc *, struct slccb *); static void scsi_low_bus_release(struct scsi_low_softc *, struct targ_info *); static void scsi_low_twiddle_wait(void); static struct lun_info *scsi_low_alloc_li(struct targ_info *, int, int); static struct targ_info *scsi_low_alloc_ti(struct scsi_low_softc *, int); static void scsi_low_calcf_lun(struct lun_info *); static void scsi_low_calcf_target(struct targ_info *); static void scsi_low_calcf_show(struct lun_info *); static void scsi_low_reset_nexus(struct scsi_low_softc *, int); static void scsi_low_reset_nexus_target(struct scsi_low_softc *, struct targ_info *, int); static void scsi_low_reset_nexus_lun(struct scsi_low_softc *, struct lun_info *, int); static int scsi_low_init(struct scsi_low_softc *, u_int); static void scsi_low_start(struct scsi_low_softc *); static void scsi_low_free_ti(struct scsi_low_softc *); static int scsi_low_alloc_qtag(struct slccb *); static int scsi_low_dealloc_qtag(struct slccb *); static int scsi_low_enqueue(struct scsi_low_softc *, struct targ_info *, struct lun_info *, struct slccb *, u_int, u_int); static int scsi_low_message_enqueue(struct scsi_low_softc *, struct targ_info *, struct lun_info *, u_int); static void scsi_low_unit_ready_cmd(struct slccb *); static void scsi_low_timeout(void *); static int scsi_low_timeout_check(struct scsi_low_softc *); #ifdef SCSI_LOW_START_UP_CHECK static int scsi_low_start_up(struct scsi_low_softc *); #endif /* SCSI_LOW_START_UP_CHECK */ static int scsi_low_abort_ccb(struct scsi_low_softc *, struct slccb *); static struct slccb *scsi_low_revoke_ccb(struct scsi_low_softc *, struct slccb *, int); int scsi_low_version_major = 2; int scsi_low_version_minor = 17; static struct scsi_low_softc_tab sl_tab = LIST_HEAD_INITIALIZER(sl_tab); +static struct mtx sl_tab_lock; +MTX_SYSINIT(sl_tab_lock, &sl_tab_lock, "scsi low table", MTX_DEF); /************************************************************** * Debug, Run test and Statics **************************************************************/ #ifdef SCSI_LOW_INFO_DETAIL #define SCSI_LOW_INFO(slp, ti, s) scsi_low_info((slp), (ti), (s)) #else /* !SCSI_LOW_INFO_DETAIL */ #define SCSI_LOW_INFO(slp, ti, s) device_printf((slp)->sl_dev, "%s\n", (s)) #endif /* !SCSI_LOW_INFO_DETAIL */ #ifdef SCSI_LOW_STATICS static struct scsi_low_statics { int nexus_win; int nexus_fail; int nexus_disconnected; int nexus_reselected; int nexus_conflict; } scsi_low_statics; #endif /* SCSI_LOW_STATICS */ #ifdef SCSI_LOW_DEBUG #define SCSI_LOW_DEBUG_DONE 0x00001 #define SCSI_LOW_DEBUG_DISC 0x00002 #define SCSI_LOW_DEBUG_SENSE 0x00004 #define SCSI_LOW_DEBUG_CALCF 0x00008 #define SCSI_LOW_DEBUG_ACTION 0x10000 int scsi_low_debug = 0; #define SCSI_LOW_MAX_ATTEN_CHECK 32 #define SCSI_LOW_ATTEN_CHECK 0x0001 #define SCSI_LOW_CMDLNK_CHECK 0x0002 #define SCSI_LOW_ABORT_CHECK 0x0004 #define SCSI_LOW_NEXUS_CHECK 0x0008 int scsi_low_test = 0; int scsi_low_test_id = 0; static void scsi_low_test_abort(struct scsi_low_softc *, struct targ_info *, struct lun_info *); static void scsi_low_test_cmdlnk(struct scsi_low_softc *, struct slccb *); static void scsi_low_test_atten(struct scsi_low_softc *, struct targ_info *, u_int); #define SCSI_LOW_DEBUG_TEST_GO(fl, id) \ ((scsi_low_test & (fl)) != 0 && (scsi_low_test_id & (1 << (id))) == 0) #define SCSI_LOW_DEBUG_GO(fl, id) \ ((scsi_low_debug & (fl)) != 0 && (scsi_low_test_id & (1 << (id))) == 0) #endif /* SCSI_LOW_DEBUG */ /************************************************************** * CCB **************************************************************/ GENERIC_CCB_STATIC_ALLOC(scsi_low, slccb) GENERIC_CCB(scsi_low, slccb, ccb_chain) /************************************************************** * Inline functions **************************************************************/ #define SCSI_LOW_INLINE static __inline SCSI_LOW_INLINE void scsi_low_activate_qtag(struct slccb *); SCSI_LOW_INLINE void scsi_low_deactivate_qtag(struct slccb *); SCSI_LOW_INLINE void scsi_low_ccb_message_assert(struct slccb *, u_int); SCSI_LOW_INLINE void scsi_low_ccb_message_exec(struct scsi_low_softc *, struct slccb *); SCSI_LOW_INLINE void scsi_low_ccb_message_retry(struct slccb *); SCSI_LOW_INLINE void scsi_low_ccb_message_clear(struct slccb *); SCSI_LOW_INLINE void scsi_low_init_msgsys(struct scsi_low_softc *, struct targ_info *); SCSI_LOW_INLINE void scsi_low_activate_qtag(cb) struct slccb *cb; { struct lun_info *li = cb->li; if (cb->ccb_tag != SCSI_LOW_UNKTAG) return; li->li_nqio ++; cb->ccb_tag = cb->ccb_otag; } SCSI_LOW_INLINE void scsi_low_deactivate_qtag(cb) struct slccb *cb; { struct lun_info *li = cb->li; if (cb->ccb_tag == SCSI_LOW_UNKTAG) return; li->li_nqio --; cb->ccb_tag = SCSI_LOW_UNKTAG; } SCSI_LOW_INLINE void scsi_low_ccb_message_exec(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { scsi_low_assert_msg(slp, cb->ti, cb->ccb_msgoutflag, 0); cb->ccb_msgoutflag = 0; } SCSI_LOW_INLINE void scsi_low_ccb_message_assert(cb, msg) struct slccb *cb; u_int msg; { cb->ccb_msgoutflag = cb->ccb_omsgoutflag = msg; } SCSI_LOW_INLINE void scsi_low_ccb_message_retry(cb) struct slccb *cb; { cb->ccb_msgoutflag = cb->ccb_omsgoutflag; } SCSI_LOW_INLINE void scsi_low_ccb_message_clear(cb) struct slccb *cb; { cb->ccb_msgoutflag = 0; } SCSI_LOW_INLINE void scsi_low_init_msgsys(slp, ti) struct scsi_low_softc *slp; struct targ_info *ti; { ti->ti_msginptr = 0; ti->ti_emsgflags = ti->ti_msgflags = ti->ti_omsgflags = 0; SCSI_LOW_DEASSERT_ATN(slp); SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_NULL); } /*============================================================= * START OF OS switch (All OS depend fucntions should be here) =============================================================*/ /* common os depend utitlities */ #define SCSI_LOW_CMD_RESIDUAL_CHK 0x0001 #define SCSI_LOW_CMD_ORDERED_QTAG 0x0002 #define SCSI_LOW_CMD_ABORT_WARNING 0x0004 static u_int8_t scsi_low_cmd_flags[256] = { /* 0 1 2 3 4 5 6 7 8 9 a b c d e f */ /*0*/ 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 5, 0, 0, 0, 0, 0, /*1*/ 0, 0, 0, 0, 0, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, /*2*/ 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 5, 0, 0, 0, 5, 5, /*3*/ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 5, }; struct scsi_low_error_code { int error_bits; int error_code; }; static struct slccb *scsi_low_find_ccb(struct scsi_low_softc *, u_int, u_int, void *); static int scsi_low_translate_error_code(struct slccb *, struct scsi_low_error_code *); static struct slccb * scsi_low_find_ccb(slp, target, lun, osdep) struct scsi_low_softc *slp; u_int target, lun; void *osdep; { struct targ_info *ti; struct lun_info *li; struct slccb *cb; ti = slp->sl_ti[target]; li = scsi_low_alloc_li(ti, lun, 0); if (li == NULL) return NULL; if ((cb = slp->sl_Qnexus) != NULL && cb->osdep == osdep) return cb; TAILQ_FOREACH(cb, &slp->sl_start, ccb_chain) { if (cb->osdep == osdep) return cb; } TAILQ_FOREACH(cb, &li->li_discq, ccb_chain) { if (cb->osdep == osdep) return cb; } return NULL; } static int scsi_low_translate_error_code(cb, tp) struct slccb *cb; struct scsi_low_error_code *tp; { if (cb->ccb_error == 0) return tp->error_code; for (tp ++; (cb->ccb_error & tp->error_bits) == 0; tp ++) ; return tp->error_code; } /************************************************************** * SCSI INTERFACE (CAM) **************************************************************/ #define SCSI_LOW_MALLOC(size) malloc((size), M_SCSILOW, M_NOWAIT) #define SCSI_LOW_FREE(pt) free((pt), M_SCSILOW) #define SCSI_LOW_ALLOC_CCB(flags) scsi_low_get_ccb() static void scsi_low_poll_cam(struct cam_sim *); void scsi_low_scsi_action_cam(struct cam_sim *, union ccb *); static int scsi_low_attach_cam(struct scsi_low_softc *); -static int scsi_low_world_start_cam(struct scsi_low_softc *); -static int scsi_low_dettach_cam(struct scsi_low_softc *); +static int scsi_low_detach_cam(struct scsi_low_softc *); static int scsi_low_ccb_setup_cam(struct scsi_low_softc *, struct slccb *); static int scsi_low_done_cam(struct scsi_low_softc *, struct slccb *); -static void scsi_low_timeout_cam(struct scsi_low_softc *, int, int); -struct scsi_low_osdep_funcs scsi_low_osdep_funcs_cam = { - scsi_low_attach_cam, - scsi_low_world_start_cam, - scsi_low_dettach_cam, - scsi_low_ccb_setup_cam, - scsi_low_done_cam, - scsi_low_timeout_cam -}; - struct scsi_low_error_code scsi_low_error_code_cam[] = { {0, CAM_REQ_CMP}, {SENSEIO, CAM_AUTOSNS_VALID | CAM_REQ_CMP_ERR}, {SENSEERR, CAM_AUTOSENSE_FAIL}, {UACAERR, CAM_SCSI_STATUS_ERROR}, {BUSYERR | STATERR, CAM_SCSI_STATUS_ERROR}, {SELTIMEOUTIO, CAM_SEL_TIMEOUT}, {TIMEOUTIO, CAM_CMD_TIMEOUT}, {PDMAERR, CAM_DATA_RUN_ERR}, {PARITYERR, CAM_UNCOR_PARITY}, {UBFERR, CAM_UNEXP_BUSFREE}, {ABORTIO, CAM_REQ_ABORTED}, {-1, CAM_UNREC_HBA_ERROR} }; #define SIM2SLP(sim) ((struct scsi_low_softc *) cam_sim_softc((sim))) /* XXX: * Please check a polling hz, currently we assume scsi_low_poll() is * called each 1 ms. */ #define SCSI_LOW_CAM_POLL_HZ 1000 /* OK ? */ static void scsi_low_poll_cam(sim) struct cam_sim *sim; { struct scsi_low_softc *slp = SIM2SLP(sim); + SCSI_LOW_ASSERT_LOCKED(slp); (*slp->sl_funcs->scsi_low_poll) (slp); - if (slp->sl_si.si_poll_count ++ >= + if (slp->sl_poll_count ++ >= SCSI_LOW_CAM_POLL_HZ / SCSI_LOW_TIMEOUT_HZ) { - slp->sl_si.si_poll_count = 0; + slp->sl_poll_count = 0; scsi_low_timeout_check(slp); } } void scsi_low_scsi_action_cam(sim, ccb) struct cam_sim *sim; union ccb *ccb; { struct scsi_low_softc *slp = SIM2SLP(sim); struct targ_info *ti; struct lun_info *li; struct slccb *cb; u_int lun, flags, msg, target; - int s, rv; + int rv; + SCSI_LOW_ASSERT_LOCKED(slp); target = (u_int) (ccb->ccb_h.target_id); lun = (u_int) ccb->ccb_h.target_lun; #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_ACTION, target) != 0) { device_printf(slp->sl_dev, "cam_action: func code 0x%x target: %d, lun: %d\n", ccb->ccb_h.func_code, target, lun); } #endif /* SCSI_LOW_DEBUG */ switch (ccb->ccb_h.func_code) { case XPT_SCSI_IO: /* Execute the requested I/O operation */ #ifdef SCSI_LOW_DIAGNOSTIC if (target == CAM_TARGET_WILDCARD || lun == CAM_LUN_WILDCARD) { device_printf(slp->sl_dev, "invalid target/lun\n"); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } #endif /* SCSI_LOW_DIAGNOSTIC */ if (((cb = SCSI_LOW_ALLOC_CCB(1)) == NULL)) { ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_done(ccb); return; } ti = slp->sl_ti[target]; cb->osdep = ccb; cb->bp = NULL; if ((ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0) flags = CCB_AUTOSENSE | CCB_SCSIIO; else flags = CCB_SCSIIO; - s = splcam(); li = scsi_low_alloc_li(ti, lun, 1); if (ti->ti_setup_msg != 0) { scsi_low_message_enqueue(slp, ti, li, CCB_AUTOSENSE); } scsi_low_enqueue(slp, ti, li, cb, flags, 0); #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_ABORT_CHECK, target) != 0) { scsi_low_test_abort(slp, ti, li); } #endif /* SCSI_LOW_DEBUG */ - splx(s); break; case XPT_EN_LUN: /* Enable LUN as a target */ case XPT_TARGET_IO: /* Execute target I/O request */ case XPT_ACCEPT_TARGET_IO: /* Accept Host Target Mode CDB */ case XPT_CONT_TARGET_IO: /* Continue Host Target I/O Connection*/ /* XXX Implement */ ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); break; case XPT_ABORT: /* Abort the specified CCB */ #ifdef SCSI_LOW_DIAGNOSTIC if (target == CAM_TARGET_WILDCARD || lun == CAM_LUN_WILDCARD) { device_printf(slp->sl_dev, "invalid target/lun\n"); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } #endif /* SCSI_LOW_DIAGNOSTIC */ - s = splcam(); cb = scsi_low_find_ccb(slp, target, lun, ccb->cab.abort_ccb); rv = scsi_low_abort_ccb(slp, cb); - splx(s); if (rv == 0) ccb->ccb_h.status = CAM_REQ_CMP; else ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); break; case XPT_SET_TRAN_SETTINGS: { struct ccb_trans_settings_scsi *scsi; struct ccb_trans_settings_spi *spi; struct ccb_trans_settings *cts; u_int val; #ifdef SCSI_LOW_DIAGNOSTIC if (target == CAM_TARGET_WILDCARD) { device_printf(slp->sl_dev, "invalid target\n"); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } #endif /* SCSI_LOW_DIAGNOSTIC */ cts = &ccb->cts; ti = slp->sl_ti[target]; if (lun == CAM_LUN_WILDCARD) lun = 0; - s = splcam(); scsi = &cts->proto_specific.scsi; spi = &cts->xport_specific.spi; if ((spi->valid & (CTS_SPI_VALID_BUS_WIDTH | CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET)) != 0) { if (spi->valid & CTS_SPI_VALID_BUS_WIDTH) { val = spi->bus_width; if (val < ti->ti_width) ti->ti_width = val; } if (spi->valid & CTS_SPI_VALID_SYNC_RATE) { val = spi->sync_period; if (val == 0 || val > ti->ti_maxsynch.period) ti->ti_maxsynch.period = val; } if (spi->valid & CTS_SPI_VALID_SYNC_OFFSET) { val = spi->sync_offset; if (val < ti->ti_maxsynch.offset) ti->ti_maxsynch.offset = val; } ti->ti_flags_valid |= SCSI_LOW_TARG_FLAGS_QUIRKS_VALID; scsi_low_calcf_target(ti); } if ((spi->valid & CTS_SPI_FLAGS_DISC_ENB) != 0 || (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) { li = scsi_low_alloc_li(ti, lun, 1); if (spi->valid & CTS_SPI_FLAGS_DISC_ENB) { li->li_quirks |= SCSI_LOW_DISK_DISC; } else { li->li_quirks &= ~SCSI_LOW_DISK_DISC; } if (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) { li->li_quirks |= SCSI_LOW_DISK_QTAG; } else { li->li_quirks &= ~SCSI_LOW_DISK_QTAG; } li->li_flags_valid |= SCSI_LOW_LUN_FLAGS_QUIRKS_VALID; scsi_low_calcf_target(ti); scsi_low_calcf_lun(li); if ((slp->sl_show_result & SHOW_CALCF_RES) != 0) scsi_low_calcf_show(li); } - splx(s); ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); break; } case XPT_GET_TRAN_SETTINGS: { struct ccb_trans_settings *cts; u_int diskflags; cts = &ccb->cts; #ifdef SCSI_LOW_DIAGNOSTIC if (target == CAM_TARGET_WILDCARD) { device_printf(slp->sl_dev, "invalid target\n"); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } #endif /* SCSI_LOW_DIAGNOSTIC */ ti = slp->sl_ti[target]; if (lun == CAM_LUN_WILDCARD) lun = 0; - s = splcam(); li = scsi_low_alloc_li(ti, lun, 1); if (li != NULL && cts->type == CTS_TYPE_CURRENT_SETTINGS) { struct ccb_trans_settings_scsi *scsi = &cts->proto_specific.scsi; struct ccb_trans_settings_spi *spi = &cts->xport_specific.spi; #ifdef SCSI_LOW_DIAGNOSTIC if (li->li_flags_valid != SCSI_LOW_LUN_FLAGS_ALL_VALID) { ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; device_printf(slp->sl_dev, "invalid GET_TRANS_CURRENT_SETTINGS call\n"); goto settings_out; } #endif /* SCSI_LOW_DIAGNOSTIC */ cts->protocol = PROTO_SCSI; cts->protocol_version = SCSI_REV_2; cts->transport = XPORT_SPI; cts->transport_version = 2; scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB; diskflags = li->li_diskflags & li->li_cfgflags; if (diskflags & SCSI_LOW_DISK_DISC) spi->flags |= CTS_SPI_FLAGS_DISC_ENB; if (diskflags & SCSI_LOW_DISK_QTAG) scsi->flags |= CTS_SCSI_FLAGS_TAG_ENB; spi->sync_period = ti->ti_maxsynch.period; spi->valid |= CTS_SPI_VALID_SYNC_RATE; spi->sync_offset = ti->ti_maxsynch.offset; spi->valid |= CTS_SPI_VALID_SYNC_OFFSET; spi->valid |= CTS_SPI_VALID_BUS_WIDTH; spi->bus_width = ti->ti_width; if (cts->ccb_h.target_lun != CAM_LUN_WILDCARD) { scsi->valid = CTS_SCSI_VALID_TQ; spi->valid |= CTS_SPI_VALID_DISC; } else scsi->valid = 0; } else ccb->ccb_h.status = CAM_FUNC_NOTAVAIL; settings_out: - splx(s); xpt_done(ccb); break; } case XPT_CALC_GEOMETRY: { /* not yet HN2 */ cam_calc_geometry(&ccb->ccg, /*extended*/1); xpt_done(ccb); break; } case XPT_RESET_BUS: /* Reset the specified SCSI bus */ - s = splcam(); scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, NULL); - splx(s); ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); break; case XPT_TERM_IO: /* Terminate the I/O process */ ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); break; case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */ #ifdef SCSI_LOW_DIAGNOSTIC if (target == CAM_TARGET_WILDCARD) { device_printf(slp->sl_dev, "invalid target\n"); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); return; } #endif /* SCSI_LOW_DIAGNOSTIC */ msg = SCSI_LOW_MSG_RESET; if (((cb = SCSI_LOW_ALLOC_CCB(1)) == NULL)) { ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_done(ccb); return; } ti = slp->sl_ti[target]; if (lun == CAM_LUN_WILDCARD) lun = 0; cb->osdep = ccb; cb->bp = NULL; if ((ccb->ccb_h.flags & CAM_DIS_AUTOSENSE) == 0) flags = CCB_AUTOSENSE | CCB_NORETRY | CCB_URGENT; else flags = CCB_NORETRY | CCB_URGENT; - s = splcam(); li = scsi_low_alloc_li(ti, lun, 1); scsi_low_enqueue(slp, ti, li, cb, flags, msg); - splx(s); break; case XPT_PATH_INQ: { /* Path routing inquiry */ struct ccb_pathinq *cpi = &ccb->cpi; cpi->version_num = scsi_low_version_major; cpi->hba_inquiry = PI_TAG_ABLE | PI_LINKED_CDB; ti = slp->sl_ti[slp->sl_hostid]; /* host id */ if (ti->ti_width > SCSI_LOW_BUS_WIDTH_8) cpi->hba_inquiry |= PI_WIDE_16; if (ti->ti_width > SCSI_LOW_BUS_WIDTH_16) cpi->hba_inquiry |= PI_WIDE_32; if (ti->ti_maxsynch.offset > 0) cpi->hba_inquiry |= PI_SDTR_ABLE; cpi->target_sprt = 0; cpi->hba_misc = 0; cpi->hba_eng_cnt = 0; cpi->max_target = slp->sl_ntargs - 1; cpi->max_lun = slp->sl_nluns - 1; cpi->initiator_id = slp->sl_hostid; cpi->bus_id = cam_sim_bus(sim); cpi->base_transfer_speed = 3300; cpi->transport = XPORT_SPI; cpi->transport_version = 2; cpi->protocol = PROTO_SCSI; cpi->protocol_version = SCSI_REV_2; strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN); strncpy(cpi->hba_vid, "SCSI_LOW", HBA_IDLEN); strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN); cpi->unit_number = cam_sim_unit(sim); cpi->ccb_h.status = CAM_REQ_CMP; xpt_done(ccb); break; } default: printf("scsi_low: non support func_code = %d ", ccb->ccb_h.func_code); ccb->ccb_h.status = CAM_REQ_INVALID; xpt_done(ccb); break; } } static int scsi_low_attach_cam(slp) struct scsi_low_softc *slp; { struct cam_devq *devq; int tagged_openings; devq = cam_simq_alloc(SCSI_LOW_NCCB); if (devq == NULL) return (ENOMEM); /* * ask the adapter what subunits are present */ tagged_openings = min(slp->sl_openings, SCSI_LOW_MAXNEXUS); - slp->sl_si.sim = cam_sim_alloc(scsi_low_scsi_action_cam, + slp->sl_sim = cam_sim_alloc(scsi_low_scsi_action_cam, scsi_low_poll_cam, device_get_name(slp->sl_dev), slp, - device_get_unit(slp->sl_dev), &Giant, + device_get_unit(slp->sl_dev), &slp->sl_lock, slp->sl_openings, tagged_openings, devq); - if (slp->sl_si.sim == NULL) { + if (slp->sl_sim == NULL) { cam_simq_free(devq); return ENODEV; } - if (xpt_bus_register(slp->sl_si.sim, NULL, 0) != CAM_SUCCESS) { - free(slp->sl_si.sim, M_SCSILOW); + SCSI_LOW_LOCK(slp); + if (xpt_bus_register(slp->sl_sim, slp->sl_dev, 0) != CAM_SUCCESS) { + cam_sim_free(slp->sl_sim, TRUE); + SCSI_LOW_UNLOCK(slp); return ENODEV; } - if (xpt_create_path(&slp->sl_si.path, /*periph*/NULL, - cam_sim_path(slp->sl_si.sim), CAM_TARGET_WILDCARD, + if (xpt_create_path(&slp->sl_path, /*periph*/NULL, + cam_sim_path(slp->sl_sim), CAM_TARGET_WILDCARD, CAM_LUN_WILDCARD) != CAM_REQ_CMP) { - xpt_bus_deregister(cam_sim_path(slp->sl_si.sim)); - cam_sim_free(slp->sl_si.sim, /*free_simq*/TRUE); + xpt_bus_deregister(cam_sim_path(slp->sl_sim)); + cam_sim_free(slp->sl_sim, /*free_simq*/TRUE); + SCSI_LOW_UNLOCK(slp); return ENODEV; } slp->sl_show_result = SHOW_CALCF_RES; /* OK ? */ + SCSI_LOW_UNLOCK(slp); return 0; } static int -scsi_low_world_start_cam(slp) +scsi_low_detach_cam(slp) struct scsi_low_softc *slp; { + xpt_async(AC_LOST_DEVICE, slp->sl_path, NULL); + xpt_free_path(slp->sl_path); + xpt_bus_deregister(cam_sim_path(slp->sl_sim)); + cam_sim_free(slp->sl_sim, /* free_devq */ TRUE); return 0; } static int -scsi_low_dettach_cam(slp) - struct scsi_low_softc *slp; -{ - - xpt_async(AC_LOST_DEVICE, slp->sl_si.path, NULL); - xpt_free_path(slp->sl_si.path); - xpt_bus_deregister(cam_sim_path(slp->sl_si.sim)); - cam_sim_free(slp->sl_si.sim, /* free_devq */ TRUE); - return 0; -} - -static int scsi_low_ccb_setup_cam(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { union ccb *ccb = (union ccb *) cb->osdep; if ((cb->ccb_flags & CCB_SCSIIO) != 0) { cb->ccb_scp.scp_cmd = ccb->csio.cdb_io.cdb_bytes; cb->ccb_scp.scp_cmdlen = (int) ccb->csio.cdb_len; cb->ccb_scp.scp_data = ccb->csio.data_ptr; cb->ccb_scp.scp_datalen = (int) ccb->csio.dxfer_len; if((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_OUT) cb->ccb_scp.scp_direction = SCSI_LOW_WRITE; else /* if((ccb->ccb_h.flags & CAM_DIR_MASK) == CAM_DIR_IN) */ cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = ccb->ccb_h.timeout / 1000; } else { scsi_low_unit_ready_cmd(cb); } return SCSI_LOW_START_QTAG; } static int scsi_low_done_cam(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { union ccb *ccb; ccb = (union ccb *) cb->osdep; if (cb->ccb_error == 0) { ccb->ccb_h.status = CAM_REQ_CMP; ccb->csio.resid = 0; } else { if (cb->ccb_rcnt >= slp->sl_max_retry) cb->ccb_error |= ABORTIO; if ((cb->ccb_flags & CCB_NORETRY) == 0 && (cb->ccb_error & ABORTIO) == 0) return EJUSTRETURN; if ((cb->ccb_error & SENSEIO) != 0) { memcpy(&ccb->csio.sense_data, &cb->ccb_sense, sizeof(ccb->csio.sense_data)); } ccb->ccb_h.status = scsi_low_translate_error_code(cb, &scsi_low_error_code_cam[0]); #ifdef SCSI_LOW_DIAGNOSTIC if ((cb->ccb_flags & CCB_SILENT) == 0 && cb->ccb_scp.scp_cmdlen > 0 && (scsi_low_cmd_flags[cb->ccb_scp.scp_cmd[0]] & SCSI_LOW_CMD_ABORT_WARNING) != 0) { device_printf(slp->sl_dev, "WARNING: scsi_low IO abort\n"); scsi_low_print(slp, NULL); } #endif /* SCSI_LOW_DIAGNOSTIC */ } if ((ccb->ccb_h.status & CAM_STATUS_MASK) == 0) ccb->ccb_h.status |= CAM_REQ_CMP_ERR; if (cb->ccb_scp.scp_status == ST_UNKNOWN) ccb->csio.scsi_status = 0; /* XXX */ else ccb->csio.scsi_status = cb->ccb_scp.scp_status; if ((cb->ccb_flags & CCB_NOSDONE) == 0) xpt_done(ccb); return 0; } -static void -scsi_low_timeout_cam(slp, ch, action) - struct scsi_low_softc *slp; - int ch; - int action; -{ - - switch (ch) - { - case SCSI_LOW_TIMEOUT_CH_IO: - switch (action) - { - case SCSI_LOW_TIMEOUT_START: - slp->sl_si.timeout_ch = timeout(scsi_low_timeout, slp, - hz / SCSI_LOW_TIMEOUT_HZ); - break; - case SCSI_LOW_TIMEOUT_STOP: - untimeout(scsi_low_timeout, slp, slp->sl_si.timeout_ch); - break; - } - break; - - case SCSI_LOW_TIMEOUT_CH_ENGAGE: - switch (action) - { - case SCSI_LOW_TIMEOUT_START: - slp->sl_si.engage_ch = timeout(scsi_low_engage, slp, 1); - break; - case SCSI_LOW_TIMEOUT_STOP: - untimeout(scsi_low_engage, slp, slp->sl_si.engage_ch); - break; - } - break; - case SCSI_LOW_TIMEOUT_CH_RECOVER: - break; - } -} - -/*============================================================= - * END OF OS switch (All OS depend fucntions should be above) - =============================================================*/ - /************************************************************** * scsi low deactivate and activate **************************************************************/ int scsi_low_is_busy(slp) struct scsi_low_softc *slp; { if (slp->sl_nio > 0) return EBUSY; return 0; } int scsi_low_deactivate(slp) struct scsi_low_softc *slp; { - int s; - s = splcam(); slp->sl_flags |= HW_INACTIVE; - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_STOP); - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_ENGAGE, SCSI_LOW_TIMEOUT_STOP); - splx(s); + callout_stop(&slp->sl_timeout_timer); + callout_stop(&slp->sl_engage_timer); return 0; } int scsi_low_activate(slp) struct scsi_low_softc *slp; { - int error, s; + int error; - s = splcam(); slp->sl_flags &= ~HW_INACTIVE; if ((error = scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, NULL)) != 0) { slp->sl_flags |= HW_INACTIVE; - splx(s); return error; } slp->sl_timeout_count = 0; - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_START); - splx(s); + callout_reset(&slp->sl_timeout_timer, hz / SCSI_LOW_TIMEOUT_HZ, + scsi_low_timeout, slp); return 0; } /************************************************************** * scsi low log **************************************************************/ #ifdef SCSI_LOW_DIAGNOSTIC static void scsi_low_msg_log_init(struct scsi_low_msg_log *); static void scsi_low_msg_log_write(struct scsi_low_msg_log *, u_int8_t *, int); static void scsi_low_msg_log_show(struct scsi_low_msg_log *, char *, int); static void scsi_low_msg_log_init(slmlp) struct scsi_low_msg_log *slmlp; { slmlp->slml_ptr = 0; } static void scsi_low_msg_log_write(slmlp, datap, len) struct scsi_low_msg_log *slmlp; u_int8_t *datap; int len; { int ptr, ind; if (slmlp->slml_ptr >= SCSI_LOW_MSG_LOG_DATALEN) return; ptr = slmlp->slml_ptr ++; for (ind = 0; ind < sizeof(slmlp->slml_msg[0]) && ind < len; ind ++) slmlp->slml_msg[ptr].msg[ind] = datap[ind]; for ( ; ind < sizeof(slmlp->slml_msg[0]); ind ++) slmlp->slml_msg[ptr].msg[ind] = 0; } static void scsi_low_msg_log_show(slmlp, s, len) struct scsi_low_msg_log *slmlp; char *s; int len; { int ptr, ind; printf("%s: (%d) ", s, slmlp->slml_ptr); for (ptr = 0; ptr < slmlp->slml_ptr; ptr ++) { for (ind = 0; ind < len && ind < sizeof(slmlp->slml_msg[0]); ind ++) { printf("[%x]", (u_int) slmlp->slml_msg[ptr].msg[ind]); } printf(">"); } printf("\n"); } #endif /* SCSI_LOW_DIAGNOSTIC */ /************************************************************** * power control **************************************************************/ static void scsi_low_engage(arg) void *arg; { struct scsi_low_softc *slp = arg; - int s = splcam(); + SCSI_LOW_ASSERT_LOCKED(slp); switch (slp->sl_rstep) { case 0: slp->sl_rstep ++; (*slp->sl_funcs->scsi_low_power) (slp, SCSI_LOW_ENGAGE); - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) (slp, - SCSI_LOW_TIMEOUT_CH_ENGAGE, SCSI_LOW_TIMEOUT_START); + callout_reset(&slp->sl_engage_timer, hz / 1000, + scsi_low_engage, slp); break; case 1: slp->sl_rstep ++; slp->sl_flags &= ~HW_RESUME; scsi_low_start(slp); break; case 2: break; } - splx(s); } static int scsi_low_init(slp, flags) struct scsi_low_softc *slp; u_int flags; { int rv = 0; slp->sl_flags |= HW_INITIALIZING; /* clear power control timeout */ if ((slp->sl_flags & HW_POWERCTRL) != 0) { - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) (slp, - SCSI_LOW_TIMEOUT_CH_ENGAGE, SCSI_LOW_TIMEOUT_STOP); + callout_stop(&slp->sl_engage_timer); slp->sl_flags &= ~(HW_POWDOWN | HW_RESUME); slp->sl_active = 1; slp->sl_powc = SCSI_LOW_POWDOWN_TC; } /* reset current nexus */ scsi_low_reset_nexus(slp, flags); if ((slp->sl_flags & HW_INACTIVE) != 0) { rv = EBUSY; goto out; } if (flags != SCSI_LOW_RESTART_SOFT) { rv = ((*slp->sl_funcs->scsi_low_init) (slp, flags)); } out: slp->sl_flags &= ~HW_INITIALIZING; return rv; } /************************************************************** * allocate lun_info **************************************************************/ static struct lun_info * scsi_low_alloc_li(ti, lun, alloc) struct targ_info *ti; int lun; int alloc; { struct scsi_low_softc *slp = ti->ti_sc; struct lun_info *li; li = LIST_FIRST(&ti->ti_litab); if (li != NULL) { if (li->li_lun == lun) return li; while ((li = LIST_NEXT(li, lun_chain)) != NULL) { if (li->li_lun == lun) { LIST_REMOVE(li, lun_chain); LIST_INSERT_HEAD(&ti->ti_litab, li, lun_chain); return li; } } } if (alloc == 0) return li; li = SCSI_LOW_MALLOC(ti->ti_lunsize); if (li == NULL) panic("no lun info mem"); bzero(li, ti->ti_lunsize); li->li_lun = lun; li->li_ti = ti; li->li_cfgflags = SCSI_LOW_SYNC | SCSI_LOW_LINK | SCSI_LOW_DISC | SCSI_LOW_QTAG; li->li_quirks = li->li_diskflags = SCSI_LOW_DISK_LFLAGS; li->li_flags_valid = SCSI_LOW_LUN_FLAGS_USER_VALID; #ifdef SCSI_LOW_FLAGS_QUIRKS_OK li->li_flags_valid |= SCSI_LOW_LUN_FLAGS_QUIRKS_VALID; #endif /* SCSI_LOW_FLAGS_QUIRKS_OK */ li->li_qtagbits = (u_int) -1; TAILQ_INIT(&li->li_discq); LIST_INSERT_HEAD(&ti->ti_litab, li, lun_chain); /* host specific structure initialization per lun */ if (slp->sl_funcs->scsi_low_lun_init != NULL) (*slp->sl_funcs->scsi_low_lun_init) (slp, ti, li, SCSI_LOW_INFO_ALLOC); scsi_low_calcf_lun(li); return li; } /************************************************************** * allocate targ_info **************************************************************/ static struct targ_info * scsi_low_alloc_ti(slp, targ) struct scsi_low_softc *slp; int targ; { struct targ_info *ti; if (TAILQ_FIRST(&slp->sl_titab) == NULL) TAILQ_INIT(&slp->sl_titab); ti = SCSI_LOW_MALLOC(slp->sl_targsize); if (ti == NULL) panic("%s short of memory", device_get_nameunit(slp->sl_dev)); bzero(ti, slp->sl_targsize); ti->ti_id = targ; ti->ti_sc = slp; slp->sl_ti[targ] = ti; TAILQ_INSERT_TAIL(&slp->sl_titab, ti, ti_chain); LIST_INIT(&ti->ti_litab); ti->ti_quirks = ti->ti_diskflags = SCSI_LOW_DISK_TFLAGS; ti->ti_owidth = SCSI_LOW_BUS_WIDTH_8; ti->ti_flags_valid = SCSI_LOW_TARG_FLAGS_USER_VALID; #ifdef SCSI_LOW_FLAGS_QUIRKS_OK ti->ti_flags_valid |= SCSI_LOW_TARG_FLAGS_QUIRKS_VALID; #endif /* SCSI_LOW_FLAGS_QUIRKS_OK */ if (slp->sl_funcs->scsi_low_targ_init != NULL) { (*slp->sl_funcs->scsi_low_targ_init) (slp, ti, SCSI_LOW_INFO_ALLOC); } scsi_low_calcf_target(ti); return ti; } static void scsi_low_free_ti(slp) struct scsi_low_softc *slp; { struct targ_info *ti, *tib; struct lun_info *li, *nli; for (ti = TAILQ_FIRST(&slp->sl_titab); ti; ti = tib) { for (li = LIST_FIRST(&ti->ti_litab); li != NULL; li = nli) { if (slp->sl_funcs->scsi_low_lun_init != NULL) { (*slp->sl_funcs->scsi_low_lun_init) (slp, ti, li, SCSI_LOW_INFO_DEALLOC); } nli = LIST_NEXT(li, lun_chain); SCSI_LOW_FREE(li); } if (slp->sl_funcs->scsi_low_targ_init != NULL) { (*slp->sl_funcs->scsi_low_targ_init) (slp, ti, SCSI_LOW_INFO_DEALLOC); } tib = TAILQ_NEXT(ti, ti_chain); SCSI_LOW_FREE(ti); } } /************************************************************** * timeout **************************************************************/ void scsi_low_bus_idle(slp) struct scsi_low_softc *slp; { slp->sl_retry_sel = 0; if (slp->sl_Tnexus == NULL) scsi_low_start(slp); } static void scsi_low_timeout(arg) void *arg; { struct scsi_low_softc *slp = arg; - int s; - s = splcam(); + SCSI_LOW_ASSERT_LOCKED(slp); (void) scsi_low_timeout_check(slp); - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_START); - splx(s); + callout_schedule(&slp->sl_timeout_timer, hz / SCSI_LOW_TIMEOUT_HZ); } static int scsi_low_timeout_check(slp) struct scsi_low_softc *slp; { struct targ_info *ti; struct lun_info *li; struct slccb *cb = NULL; /* XXX */ /* selection restart */ if (slp->sl_retry_sel != 0) { slp->sl_retry_sel = 0; if (slp->sl_Tnexus != NULL) goto step1; cb = TAILQ_FIRST(&slp->sl_start); if (cb == NULL) goto step1; if (cb->ccb_selrcnt >= SCSI_LOW_MAX_SELECTION_RETRY) { cb->ccb_flags |= CCB_NORETRY; cb->ccb_error |= SELTIMEOUTIO; if (scsi_low_revoke_ccb(slp, cb, 1) != NULL) panic("%s: ccb not finished", device_get_nameunit(slp->sl_dev)); } if (slp->sl_Tnexus == NULL) scsi_low_start(slp); } /* call hardware timeout */ step1: if (slp->sl_funcs->scsi_low_timeout != NULL) { (*slp->sl_funcs->scsi_low_timeout) (slp); } if (slp->sl_timeout_count ++ < SCSI_LOW_TIMEOUT_CHECK_INTERVAL * SCSI_LOW_TIMEOUT_HZ) return 0; slp->sl_timeout_count = 0; if (slp->sl_nio > 0) { if ((cb = slp->sl_Qnexus) != NULL) { cb->ccb_tc -= SCSI_LOW_TIMEOUT_CHECK_INTERVAL; if (cb->ccb_tc < 0) goto bus_reset; } else if (slp->sl_disc == 0) { if ((cb = TAILQ_FIRST(&slp->sl_start)) == NULL) return 0; cb->ccb_tc -= SCSI_LOW_TIMEOUT_CHECK_INTERVAL; if (cb->ccb_tc < 0) goto bus_reset; } else for (ti = TAILQ_FIRST(&slp->sl_titab); ti != NULL; ti = TAILQ_NEXT(ti, ti_chain)) { if (ti->ti_disc == 0) continue; for (li = LIST_FIRST(&ti->ti_litab); li != NULL; li = LIST_NEXT(li, lun_chain)) { for (cb = TAILQ_FIRST(&li->li_discq); cb != NULL; cb = TAILQ_NEXT(cb, ccb_chain)) { cb->ccb_tc -= SCSI_LOW_TIMEOUT_CHECK_INTERVAL; if (cb->ccb_tc < 0) goto bus_reset; } } } } else if ((slp->sl_flags & HW_POWERCTRL) != 0) { if ((slp->sl_flags & (HW_POWDOWN | HW_RESUME)) != 0) return 0; if (slp->sl_active != 0) { slp->sl_powc = SCSI_LOW_POWDOWN_TC; slp->sl_active = 0; return 0; } slp->sl_powc --; if (slp->sl_powc < 0) { slp->sl_powc = SCSI_LOW_POWDOWN_TC; slp->sl_flags |= HW_POWDOWN; (*slp->sl_funcs->scsi_low_power) (slp, SCSI_LOW_POWDOWN); } } return 0; bus_reset: cb->ccb_error |= TIMEOUTIO; device_printf(slp->sl_dev, "slccb (0x%lx) timeout!\n", (u_long) cb); scsi_low_info(slp, NULL, "scsi bus hangup. try to recover."); scsi_low_init(slp, SCSI_LOW_RESTART_HARD); scsi_low_start(slp); return ERESTART; } static int scsi_low_abort_ccb(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { struct targ_info *ti; struct lun_info *li; u_int msg; if (cb == NULL) return EINVAL; if ((cb->ccb_omsgoutflag & (SCSI_LOW_MSG_ABORT | SCSI_LOW_MSG_ABORT_QTAG)) != 0) return EBUSY; ti = cb->ti; li = cb->li; if (cb->ccb_tag == SCSI_LOW_UNKTAG) msg = SCSI_LOW_MSG_ABORT; else msg = SCSI_LOW_MSG_ABORT_QTAG; cb->ccb_error |= ABORTIO; cb->ccb_flags |= CCB_NORETRY; scsi_low_ccb_message_assert(cb, msg); if (cb == slp->sl_Qnexus) { scsi_low_assert_msg(slp, ti, msg, 1); } else if ((cb->ccb_flags & CCB_DISCQ) != 0) { if (scsi_low_revoke_ccb(slp, cb, 0) == NULL) panic("%s: revoked ccb done", device_get_nameunit(slp->sl_dev)); cb->ccb_flags |= CCB_STARTQ; TAILQ_INSERT_HEAD(&slp->sl_start, cb, ccb_chain); if (slp->sl_Tnexus == NULL) scsi_low_start(slp); } else { if (scsi_low_revoke_ccb(slp, cb, 1) != NULL) panic("%s: revoked ccb retried", device_get_nameunit(slp->sl_dev)); } return 0; } /************************************************************** * Generic SCSI INTERFACE **************************************************************/ int scsi_low_attach(slp, openings, ntargs, nluns, targsize, lunsize) struct scsi_low_softc *slp; int openings, ntargs, nluns, targsize, lunsize; { struct targ_info *ti; struct lun_info *li; - int s, i, nccb, rv; + int i, nccb, rv; - slp->sl_osdep_fp = &scsi_low_osdep_funcs_cam; - - if (slp->sl_osdep_fp == NULL) - panic("scsi_low: interface not spcified"); - if (ntargs > SCSI_LOW_NTARGETS) { printf("scsi_low: %d targets are too large\n", ntargs); printf("change kernel options SCSI_LOW_NTARGETS"); return EINVAL; } if (openings <= 0) slp->sl_openings = (SCSI_LOW_NCCB / ntargs); else slp->sl_openings = openings; slp->sl_ntargs = ntargs; slp->sl_nluns = nluns; slp->sl_max_retry = SCSI_LOW_MAX_RETRY; if (lunsize < sizeof(struct lun_info)) lunsize = sizeof(struct lun_info); if (targsize < sizeof(struct targ_info)) targsize = sizeof(struct targ_info); slp->sl_targsize = targsize; for (i = 0; i < ntargs; i ++) { ti = scsi_low_alloc_ti(slp, i); ti->ti_lunsize = lunsize; li = scsi_low_alloc_li(ti, 0, 1); } /* initialize queue */ nccb = openings * ntargs; if (nccb >= SCSI_LOW_NCCB || nccb <= 0) nccb = SCSI_LOW_NCCB; scsi_low_init_ccbque(nccb); TAILQ_INIT(&slp->sl_start); /* call os depend attach */ - s = splcam(); - rv = (*slp->sl_osdep_fp->scsi_low_osdep_attach) (slp); + rv = scsi_low_attach_cam(slp); if (rv != 0) { - splx(s); device_printf(slp->sl_dev, "scsi_low_attach: osdep attach failed\n"); - return EINVAL; + return (rv); } /* check hardware */ DELAY(1000); /* wait for 1ms */ + SCSI_LOW_LOCK(slp); if (scsi_low_init(slp, SCSI_LOW_RESTART_HARD) != 0) { - splx(s); device_printf(slp->sl_dev, "scsi_low_attach: initialization failed\n"); + SCSI_LOW_UNLOCK(slp); return EINVAL; } /* start watch dog */ slp->sl_timeout_count = 0; - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_IO, SCSI_LOW_TIMEOUT_START); + callout_reset(&slp->sl_timeout_timer, hz / SCSI_LOW_TIMEOUT_HZ, + scsi_low_timeout, slp); + mtx_lock(&sl_tab_lock); LIST_INSERT_HEAD(&sl_tab, slp, sl_chain); + mtx_unlock(&sl_tab_lock); /* fake call */ scsi_low_abort_ccb(slp, scsi_low_find_ccb(slp, 0, 0, NULL)); #ifdef SCSI_LOW_START_UP_CHECK /* probing devices */ scsi_low_start_up(slp); #endif /* SCSI_LOW_START_UP_CHECK */ + SCSI_LOW_UNLOCK(slp); - /* call os depend attach done*/ - (*slp->sl_osdep_fp->scsi_low_osdep_world_start) (slp); - splx(s); return 0; } int -scsi_low_dettach(slp) +scsi_low_detach(slp) struct scsi_low_softc *slp; { - int s, rv; + int rv; - s = splcam(); + SCSI_LOW_LOCK(slp); if (scsi_low_is_busy(slp) != 0) { - splx(s); + SCSI_LOW_UNLOCK(slp); return EBUSY; } scsi_low_deactivate(slp); - rv = (*slp->sl_osdep_fp->scsi_low_osdep_dettach) (slp); + rv = scsi_low_detach_cam(slp); if (rv != 0) { - splx(s); + SCSI_LOW_UNLOCK(slp); return EBUSY; } scsi_low_free_ti(slp); + SCSI_LOW_UNLOCK(slp); + callout_drain(&slp->sl_timeout_timer); + callout_drain(&slp->sl_engage_timer); + mtx_lock(&sl_tab_lock); LIST_REMOVE(slp, sl_chain); - splx(s); + mtx_unlock(&sl_tab_lock); return 0; } /************************************************************** * Generic enqueue **************************************************************/ static int scsi_low_enqueue(slp, ti, li, cb, flags, msg) struct scsi_low_softc *slp; struct targ_info *ti; struct lun_info *li; struct slccb *cb; u_int flags, msg; { cb->ti = ti; cb->li = li; scsi_low_ccb_message_assert(cb, msg); cb->ccb_otag = cb->ccb_tag = SCSI_LOW_UNKTAG; scsi_low_alloc_qtag(cb); cb->ccb_flags = flags | CCB_STARTQ; cb->ccb_tc = cb->ccb_tcmax = SCSI_LOW_MIN_TOUT; cb->ccb_error |= PENDINGIO; if ((flags & CCB_URGENT) != 0) { TAILQ_INSERT_HEAD(&slp->sl_start, cb, ccb_chain); } else { TAILQ_INSERT_TAIL(&slp->sl_start, cb, ccb_chain); } slp->sl_nio ++; if (slp->sl_Tnexus == NULL) scsi_low_start(slp); return 0; } static int scsi_low_message_enqueue(slp, ti, li, flags) struct scsi_low_softc *slp; struct targ_info *ti; struct lun_info *li; u_int flags; { struct slccb *cb; u_int tmsgflags; tmsgflags = ti->ti_setup_msg; ti->ti_setup_msg = 0; flags |= CCB_NORETRY; if ((cb = SCSI_LOW_ALLOC_CCB(1)) == NULL) return ENOMEM; cb->osdep = NULL; cb->bp = NULL; scsi_low_enqueue(slp, ti, li, cb, flags, tmsgflags); return 0; } /************************************************************** * Generic Start & Done **************************************************************/ #define SLSC_MODE_SENSE_SHORT 0x1a static u_int8_t ss_cmd[6] = {START_STOP, 0, 0, 0, SSS_START, 0}; static u_int8_t sms_cmd[6] = {SLSC_MODE_SENSE_SHORT, 0x08, 0x0a, 0, sizeof(struct scsi_low_mode_sense_data), 0}; static u_int8_t inq_cmd[6] = {INQUIRY, 0, 0, 0, sizeof(struct scsi_low_inq_data), 0}; static u_int8_t unit_ready_cmd[6]; static int scsi_low_setup_start(struct scsi_low_softc *, struct targ_info *, struct lun_info *, struct slccb *); static int scsi_low_sense_abort_start(struct scsi_low_softc *, struct targ_info *, struct lun_info *, struct slccb *); static int scsi_low_resume(struct scsi_low_softc *); static void scsi_low_unit_ready_cmd(cb) struct slccb *cb; { cb->ccb_scp.scp_cmd = unit_ready_cmd; cb->ccb_scp.scp_cmdlen = sizeof(unit_ready_cmd); cb->ccb_scp.scp_datalen = 0; cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = 15; } static int scsi_low_sense_abort_start(slp, ti, li, cb) struct scsi_low_softc *slp; struct targ_info *ti; struct lun_info *li; struct slccb *cb; { cb->ccb_scp.scp_cmdlen = 6; bzero(cb->ccb_scsi_cmd, cb->ccb_scp.scp_cmdlen); cb->ccb_scsi_cmd[0] = REQUEST_SENSE; cb->ccb_scsi_cmd[4] = sizeof(cb->ccb_sense); cb->ccb_scp.scp_cmd = cb->ccb_scsi_cmd; cb->ccb_scp.scp_data = (u_int8_t *) &cb->ccb_sense; cb->ccb_scp.scp_datalen = sizeof(cb->ccb_sense); cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = 15; scsi_low_ccb_message_clear(cb); if ((cb->ccb_flags & CCB_CLEARQ) != 0) { scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); } else { bzero(&cb->ccb_sense, sizeof(cb->ccb_sense)); #ifdef SCSI_LOW_NEGOTIATE_BEFORE_SENSE scsi_low_assert_msg(slp, ti, ti->ti_setup_msg_done, 0); #endif /* SCSI_LOW_NEGOTIATE_BEFORE_SENSE */ } return SCSI_LOW_START_NO_QTAG; } static int scsi_low_setup_start(slp, ti, li, cb) struct scsi_low_softc *slp; struct targ_info *ti; struct lun_info *li; struct slccb *cb; { switch(li->li_state) { case SCSI_LOW_LUN_SLEEP: scsi_low_unit_ready_cmd(cb); break; case SCSI_LOW_LUN_START: cb->ccb_scp.scp_cmd = ss_cmd; cb->ccb_scp.scp_cmdlen = sizeof(ss_cmd); cb->ccb_scp.scp_datalen = 0; cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = 30; break; case SCSI_LOW_LUN_INQ: cb->ccb_scp.scp_cmd = inq_cmd; cb->ccb_scp.scp_cmdlen = sizeof(inq_cmd); cb->ccb_scp.scp_data = (u_int8_t *)&li->li_inq; cb->ccb_scp.scp_datalen = sizeof(li->li_inq); cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = 15; break; case SCSI_LOW_LUN_MODEQ: cb->ccb_scp.scp_cmd = sms_cmd; cb->ccb_scp.scp_cmdlen = sizeof(sms_cmd); cb->ccb_scp.scp_data = (u_int8_t *)&li->li_sms; cb->ccb_scp.scp_datalen = sizeof(li->li_sms); cb->ccb_scp.scp_direction = SCSI_LOW_READ; cb->ccb_tcmax = 15; return SCSI_LOW_START_QTAG; default: panic("%s: no setup phase", device_get_nameunit(slp->sl_dev)); } return SCSI_LOW_START_NO_QTAG; } static int scsi_low_resume(slp) struct scsi_low_softc *slp; { if (slp->sl_flags & HW_RESUME) return EJUSTRETURN; slp->sl_flags &= ~HW_POWDOWN; if (slp->sl_funcs->scsi_low_power != NULL) { slp->sl_flags |= HW_RESUME; slp->sl_rstep = 0; (*slp->sl_funcs->scsi_low_power) (slp, SCSI_LOW_ENGAGE); - (*slp->sl_osdep_fp->scsi_low_osdep_timeout) - (slp, SCSI_LOW_TIMEOUT_CH_ENGAGE, - SCSI_LOW_TIMEOUT_START); + callout_reset(&slp->sl_engage_timer, hz / 1000, + scsi_low_engage, slp); return EJUSTRETURN; } return 0; } static void scsi_low_start(slp) struct scsi_low_softc *slp; { struct targ_info *ti; struct lun_info *li; struct slccb *cb; int rv; /* check hardware exists or under initializations ? */ if ((slp->sl_flags & (HW_INACTIVE | HW_INITIALIZING)) != 0) return; /* check hardware power up ? */ if ((slp->sl_flags & HW_POWERCTRL) != 0) { slp->sl_active ++; if (slp->sl_flags & (HW_POWDOWN | HW_RESUME)) { if (scsi_low_resume(slp) == EJUSTRETURN) return; } } /* setup nexus */ #ifdef SCSI_LOW_DIAGNOSTIC if (slp->sl_Tnexus || slp->sl_Lnexus || slp->sl_Qnexus) { scsi_low_info(slp, NULL, "NEXUS INCOSISTENT"); panic("%s: inconsistent", device_get_nameunit(slp->sl_dev)); } #endif /* SCSI_LOW_DIAGNOSTIC */ for (cb = TAILQ_FIRST(&slp->sl_start); cb != NULL; cb = TAILQ_NEXT(cb, ccb_chain)) { li = cb->li; if (li->li_disc == 0) { goto scsi_low_cmd_start; } else if (li->li_nqio > 0) { if (li->li_nqio < li->li_maxnqio || (cb->ccb_flags & (CCB_SENSE | CCB_CLEARQ)) != 0) goto scsi_low_cmd_start; } } return; scsi_low_cmd_start: cb->ccb_flags &= ~CCB_STARTQ; TAILQ_REMOVE(&slp->sl_start, cb, ccb_chain); ti = cb->ti; /* clear all error flag bits (for restart) */ cb->ccb_error = 0; cb->ccb_datalen = -1; cb->ccb_scp.scp_status = ST_UNKNOWN; /* setup nexus pointer */ slp->sl_Qnexus = cb; slp->sl_Lnexus = li; slp->sl_Tnexus = ti; /* initialize msgsys */ scsi_low_init_msgsys(slp, ti); /* exec cmd */ if ((cb->ccb_flags & (CCB_SENSE | CCB_CLEARQ)) != 0) { /* CA state or forced abort */ rv = scsi_low_sense_abort_start(slp, ti, li, cb); } else if (li->li_state >= SCSI_LOW_LUN_OK) { cb->ccb_flags &= ~CCB_INTERNAL; - rv = (*slp->sl_osdep_fp->scsi_low_osdep_ccb_setup) (slp, cb); + rv = scsi_low_ccb_setup_cam(slp, cb); if (cb->ccb_msgoutflag != 0) { scsi_low_ccb_message_exec(slp, cb); } } else { cb->ccb_flags |= CCB_INTERNAL; rv = scsi_low_setup_start(slp, ti, li, cb); } /* allocate qtag */ #define SCSI_LOW_QTAG_OK (SCSI_LOW_QTAG | SCSI_LOW_DISC) if (rv == SCSI_LOW_START_QTAG && (li->li_flags & SCSI_LOW_QTAG_OK) == SCSI_LOW_QTAG_OK && li->li_maxnqio > 0) { u_int qmsg; scsi_low_activate_qtag(cb); if ((scsi_low_cmd_flags[cb->ccb_scp.scp_cmd[0]] & SCSI_LOW_CMD_ORDERED_QTAG) != 0) qmsg = SCSI_LOW_MSG_ORDERED_QTAG; else if ((cb->ccb_flags & CCB_URGENT) != 0) qmsg = SCSI_LOW_MSG_HEAD_QTAG; else qmsg = SCSI_LOW_MSG_SIMPLE_QTAG; scsi_low_assert_msg(slp, ti, qmsg, 0); } /* timeout */ if (cb->ccb_tcmax < SCSI_LOW_MIN_TOUT) cb->ccb_tcmax = SCSI_LOW_MIN_TOUT; cb->ccb_tc = cb->ccb_tcmax; /* setup saved scsi data pointer */ cb->ccb_sscp = cb->ccb_scp; /* setup current scsi pointer */ slp->sl_scp = cb->ccb_sscp; slp->sl_error = cb->ccb_error; /* assert always an identify msg */ scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_IDENTIFY, 0); /* debug section */ #ifdef SCSI_LOW_DIAGNOSTIC scsi_low_msg_log_init(&ti->ti_log_msgin); scsi_low_msg_log_init(&ti->ti_log_msgout); #endif /* SCSI_LOW_DIAGNOSTIC */ /* selection start */ slp->sl_selid = cb; rv = ((*slp->sl_funcs->scsi_low_start_bus) (slp, cb)); if (rv == SCSI_LOW_START_OK) { #ifdef SCSI_LOW_STATICS scsi_low_statics.nexus_win ++; #endif /* SCSI_LOW_STATICS */ return; } scsi_low_arbit_fail(slp, cb); #ifdef SCSI_LOW_STATICS scsi_low_statics.nexus_fail ++; #endif /* SCSI_LOW_STATICS */ } void scsi_low_arbit_fail(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { struct targ_info *ti = cb->ti; scsi_low_deactivate_qtag(cb); scsi_low_ccb_message_retry(cb); cb->ccb_flags |= CCB_STARTQ; TAILQ_INSERT_HEAD(&slp->sl_start, cb, ccb_chain); scsi_low_bus_release(slp, ti); cb->ccb_selrcnt ++; if (slp->sl_disc == 0) { #ifdef SCSI_LOW_DIAGNOSTIC device_printf(slp->sl_dev, "try selection again\n"); #endif /* SCSI_LOW_DIAGNOSTIC */ slp->sl_retry_sel = 1; } } static void scsi_low_bus_release(slp, ti) struct scsi_low_softc *slp; struct targ_info *ti; { if (ti->ti_disc > 0) { SCSI_LOW_SETUP_PHASE(ti, PH_DISC); } else { SCSI_LOW_SETUP_PHASE(ti, PH_NULL); } /* clear all nexus pointer */ slp->sl_Qnexus = NULL; slp->sl_Lnexus = NULL; slp->sl_Tnexus = NULL; /* clear selection assert */ slp->sl_selid = NULL; /* clear nexus data */ slp->sl_scp.scp_direction = SCSI_LOW_RWUNK; /* clear phase change counter */ slp->sl_ph_count = 0; } static int scsi_low_setup_done(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { struct targ_info *ti; struct lun_info *li; ti = cb->ti; li = cb->li; if (cb->ccb_rcnt >= slp->sl_max_retry) { cb->ccb_error |= ABORTIO; return SCSI_LOW_DONE_COMPLETE; } /* XXX: special huck for selection timeout */ if (li->li_state == SCSI_LOW_LUN_SLEEP && (cb->ccb_error & SELTIMEOUTIO) != 0) { cb->ccb_error |= ABORTIO; return SCSI_LOW_DONE_COMPLETE; } switch(li->li_state) { case SCSI_LOW_LUN_INQ: if (cb->ccb_error != 0) { li->li_diskflags &= ~(SCSI_LOW_DISK_LINK | SCSI_LOW_DISK_QTAG); if (li->li_lun > 0) goto resume; ti->ti_diskflags &= ~(SCSI_LOW_DISK_SYNC | SCSI_LOW_DISK_WIDE); } else if ((li->li_inq.sd_version & 7) >= 2 || (li->li_inq.sd_len >= 4)) { if ((li->li_inq.sd_support & 0x2) == 0) li->li_diskflags &= ~SCSI_LOW_DISK_QTAG; if ((li->li_inq.sd_support & 0x8) == 0) li->li_diskflags &= ~SCSI_LOW_DISK_LINK; if (li->li_lun > 0) goto resume; if ((li->li_inq.sd_support & 0x10) == 0) ti->ti_diskflags &= ~SCSI_LOW_DISK_SYNC; if ((li->li_inq.sd_support & 0x20) == 0) ti->ti_diskflags &= ~SCSI_LOW_DISK_WIDE_16; if ((li->li_inq.sd_support & 0x40) == 0) ti->ti_diskflags &= ~SCSI_LOW_DISK_WIDE_32; } else { li->li_diskflags &= ~(SCSI_LOW_DISK_QTAG | SCSI_LOW_DISK_LINK); if (li->li_lun > 0) goto resume; ti->ti_diskflags &= ~SCSI_LOW_DISK_WIDE; } ti->ti_flags_valid |= SCSI_LOW_TARG_FLAGS_DISK_VALID; resume: scsi_low_calcf_target(ti); scsi_low_calcf_lun(li); break; case SCSI_LOW_LUN_MODEQ: if (cb->ccb_error != 0) { if (cb->ccb_error & SENSEIO) { #ifdef SCSI_LOW_DEBUG if (scsi_low_debug & SCSI_LOW_DEBUG_SENSE) { int error_code, sense_key, asc, ascq; scsi_extract_sense(&cb->ccb_sense, &error_code, &sense_key, &asc, &ascq); printf("SENSE: [%x][%x][%x][%x]\n", error_code, sense_key, asc, ascq); } #endif /* SCSI_LOW_DEBUG */ } else { li->li_diskflags &= ~SCSI_LOW_DISK_QTAG; } } else if ((li->li_sms.sms_cmp.cmp_page & 0x3f) == 0x0a) { if (li->li_sms.sms_cmp.cmp_qc & 0x02) li->li_qflags |= SCSI_LOW_QFLAG_CA_QCLEAR; else li->li_qflags &= ~SCSI_LOW_QFLAG_CA_QCLEAR; if ((li->li_sms.sms_cmp.cmp_qc & 0x01) != 0) li->li_diskflags &= ~SCSI_LOW_DISK_QTAG; } li->li_flags_valid |= SCSI_LOW_LUN_FLAGS_DISK_VALID; scsi_low_calcf_lun(li); break; default: break; } li->li_state ++; if (li->li_state == SCSI_LOW_LUN_OK) { scsi_low_calcf_target(ti); scsi_low_calcf_lun(li); if (li->li_flags_valid == SCSI_LOW_LUN_FLAGS_ALL_VALID && (slp->sl_show_result & SHOW_CALCF_RES) != 0) { scsi_low_calcf_show(li); } } cb->ccb_rcnt --; return SCSI_LOW_DONE_RETRY; } static int scsi_low_done(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { int rv; if (cb->ccb_error == 0) { if ((cb->ccb_flags & (CCB_SENSE | CCB_CLEARQ)) != 0) { #ifdef SCSI_LOW_QCLEAR_AFTER_CA /* XXX: * SCSI-2 draft suggests * page 0x0a QErr bit determins if * the target aborts or continues * the queueing io's after CA state resolved. * However many targets seem not to support * the page 0x0a. Thus we should manually clear the * queuing io's after CA state. */ if ((cb->ccb_flags & CCB_CLEARQ) == 0) { cb->ccb_rcnt --; cb->ccb_flags |= CCB_CLEARQ; goto retry; } #endif /* SCSI_LOW_QCLEAR_AFTER_CA */ if ((cb->ccb_flags & CCB_SENSE) != 0) cb->ccb_error |= (SENSEIO | ABORTIO); cb->ccb_flags &= ~(CCB_SENSE | CCB_CLEARQ); } else switch (cb->ccb_sscp.scp_status) { case ST_GOOD: case ST_MET: case ST_INTERGOOD: case ST_INTERMET: if (cb->ccb_datalen == 0 || cb->ccb_scp.scp_datalen == 0) break; if (cb->ccb_scp.scp_cmdlen > 0 && (scsi_low_cmd_flags[cb->ccb_scp.scp_cmd[0]] & SCSI_LOW_CMD_RESIDUAL_CHK) == 0) break; cb->ccb_error |= PDMAERR; break; case ST_BUSY: case ST_QUEFULL: cb->ccb_error |= (BUSYERR | STATERR); break; case ST_CONFLICT: cb->ccb_error |= (STATERR | ABORTIO); break; case ST_CHKCOND: case ST_CMDTERM: if (cb->ccb_flags & (CCB_AUTOSENSE | CCB_INTERNAL)) { cb->ccb_rcnt --; cb->ccb_flags |= CCB_SENSE; goto retry; } cb->ccb_error |= (UACAERR | STATERR | ABORTIO); break; case ST_UNKNOWN: default: cb->ccb_error |= FATALIO; break; } } else { if (cb->ccb_flags & CCB_SENSE) { cb->ccb_error |= (SENSEERR | ABORTIO); } cb->ccb_flags &= ~(CCB_CLEARQ | CCB_SENSE); } /* internal ccb */ if ((cb->ccb_flags & CCB_INTERNAL) != 0) { if (scsi_low_setup_done(slp, cb) == SCSI_LOW_DONE_RETRY) goto retry; } /* check a ccb msgout flag */ if (cb->ccb_omsgoutflag != 0) { #define SCSI_LOW_MSG_ABORT_OK (SCSI_LOW_MSG_ABORT | \ SCSI_LOW_MSG_ABORT_QTAG | \ SCSI_LOW_MSG_CLEAR_QTAG | \ SCSI_LOW_MSG_TERMIO) if ((cb->ccb_omsgoutflag & SCSI_LOW_MSG_ABORT_OK) != 0) { cb->ccb_error |= ABORTIO; } } /* call OS depend done */ if (cb->osdep != NULL) { - rv = (*slp->sl_osdep_fp->scsi_low_osdep_done) (slp, cb); + rv = scsi_low_done_cam(slp, cb); if (rv == EJUSTRETURN) goto retry; } else if (cb->ccb_error != 0) { if (cb->ccb_rcnt >= slp->sl_max_retry) cb->ccb_error |= ABORTIO; if ((cb->ccb_flags & CCB_NORETRY) == 0 && (cb->ccb_error & ABORTIO) == 0) goto retry; } /* free our target */ #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_DONE, cb->ti->ti_id) != 0) { printf(">> SCSI_LOW_DONE_COMPLETE ===============\n"); scsi_low_print(slp, NULL); } #endif /* SCSI_LOW_DEBUG */ scsi_low_deactivate_qtag(cb); scsi_low_dealloc_qtag(cb); scsi_low_free_ccb(cb); slp->sl_nio --; return SCSI_LOW_DONE_COMPLETE; retry: #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_DONE, cb->ti->ti_id) != 0) { printf("** SCSI_LOW_DONE_RETRY ===============\n"); scsi_low_print(slp, NULL); } #endif /* SCSI_LOW_DEBUG */ cb->ccb_rcnt ++; scsi_low_deactivate_qtag(cb); scsi_low_ccb_message_retry(cb); return SCSI_LOW_DONE_RETRY; } /************************************************************** * Reset **************************************************************/ static void scsi_low_reset_nexus_target(slp, ti, fdone) struct scsi_low_softc *slp; struct targ_info *ti; int fdone; { struct lun_info *li; for (li = LIST_FIRST(&ti->ti_litab); li != NULL; li = LIST_NEXT(li, lun_chain)) { scsi_low_reset_nexus_lun(slp, li, fdone); li->li_state = SCSI_LOW_LUN_SLEEP; li->li_maxnqio = 0; } ti->ti_disc = 0; ti->ti_setup_msg = 0; ti->ti_setup_msg_done = 0; ti->ti_osynch.offset = ti->ti_osynch.period = 0; ti->ti_owidth = SCSI_LOW_BUS_WIDTH_8; ti->ti_diskflags = SCSI_LOW_DISK_TFLAGS; ti->ti_flags_valid &= ~SCSI_LOW_TARG_FLAGS_DISK_VALID; if (slp->sl_funcs->scsi_low_targ_init != NULL) { ((*slp->sl_funcs->scsi_low_targ_init) (slp, ti, SCSI_LOW_INFO_REVOKE)); } scsi_low_calcf_target(ti); for (li = LIST_FIRST(&ti->ti_litab); li != NULL; li = LIST_NEXT(li, lun_chain)) { li->li_flags = 0; li->li_diskflags = SCSI_LOW_DISK_LFLAGS; li->li_flags_valid &= ~SCSI_LOW_LUN_FLAGS_DISK_VALID; if (slp->sl_funcs->scsi_low_lun_init != NULL) { ((*slp->sl_funcs->scsi_low_lun_init) (slp, ti, li, SCSI_LOW_INFO_REVOKE)); } scsi_low_calcf_lun(li); } } static void scsi_low_reset_nexus(slp, fdone) struct scsi_low_softc *slp; int fdone; { struct targ_info *ti; struct slccb *cb, *topcb; if ((cb = slp->sl_Qnexus) != NULL) { topcb = scsi_low_revoke_ccb(slp, cb, fdone); } else { topcb = NULL; } for (ti = TAILQ_FIRST(&slp->sl_titab); ti != NULL; ti = TAILQ_NEXT(ti, ti_chain)) { scsi_low_reset_nexus_target(slp, ti, fdone); scsi_low_bus_release(slp, ti); scsi_low_init_msgsys(slp, ti); } if (topcb != NULL) { topcb->ccb_flags |= CCB_STARTQ; TAILQ_INSERT_HEAD(&slp->sl_start, topcb, ccb_chain); } slp->sl_disc = 0; slp->sl_retry_sel = 0; slp->sl_flags &= ~HW_PDMASTART; } /* misc */ static int tw_pos; static char tw_chars[] = "|/-\\"; #define TWIDDLEWAIT 10000 static void scsi_low_twiddle_wait(void) { cnputc('\b'); cnputc(tw_chars[tw_pos++]); tw_pos %= (sizeof(tw_chars) - 1); DELAY(TWIDDLEWAIT); } void scsi_low_bus_reset(slp) struct scsi_low_softc *slp; { int i; (*slp->sl_funcs->scsi_low_bus_reset) (slp); device_printf(slp->sl_dev, "try to reset scsi bus "); for (i = 0; i <= SCSI2_RESET_DELAY / TWIDDLEWAIT ; i++) scsi_low_twiddle_wait(); cnputc('\b'); printf("\n"); } int scsi_low_restart(slp, flags, s) struct scsi_low_softc *slp; int flags; u_char *s; { int error; if (s != NULL) device_printf(slp->sl_dev, "scsi bus restart. reason: %s\n", s); if ((error = scsi_low_init(slp, flags)) != 0) return error; scsi_low_start(slp); return 0; } /************************************************************** * disconnect and reselect **************************************************************/ #define MSGCMD_LUN(msg) (msg & 0x07) static struct slccb * scsi_low_establish_ccb(ti, li, tag) struct targ_info *ti; struct lun_info *li; scsi_low_tag_t tag; { struct scsi_low_softc *slp = ti->ti_sc; struct slccb *cb; if (li == NULL) return NULL; cb = TAILQ_FIRST(&li->li_discq); for ( ; cb != NULL; cb = TAILQ_NEXT(cb, ccb_chain)) if (cb->ccb_tag == tag) goto found; return cb; /* * establish our ccb nexus */ found: #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_NEXUS_CHECK, ti->ti_id) != 0) { device_printf(slp->sl_dev, "nexus(0x%lx) abort check start\n", (u_long) cb); cb->ccb_flags |= (CCB_NORETRY | CCB_SILENT); scsi_low_revoke_ccb(slp, cb, 1); return NULL; } if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_ATTEN_CHECK, ti->ti_id) != 0) { if (cb->ccb_omsgoutflag == 0) scsi_low_ccb_message_assert(cb, SCSI_LOW_MSG_NOOP); } #endif /* SCSI_LOW_DEBUG */ TAILQ_REMOVE(&li->li_discq, cb, ccb_chain); cb->ccb_flags &= ~CCB_DISCQ; slp->sl_Qnexus = cb; slp->sl_scp = cb->ccb_sscp; slp->sl_error |= cb->ccb_error; slp->sl_disc --; ti->ti_disc --; li->li_disc --; /* inform "ccb nexus established" to the host driver */ (*slp->sl_funcs->scsi_low_establish_ccb_nexus) (slp); /* check msg */ if (cb->ccb_msgoutflag != 0) { scsi_low_ccb_message_exec(slp, cb); } return cb; } struct targ_info * scsi_low_reselected(slp, targ) struct scsi_low_softc *slp; u_int targ; { struct targ_info *ti; struct slccb *cb; u_char *s; /* * Check select vs reselected collision. */ if ((cb = slp->sl_selid) != NULL) { scsi_low_arbit_fail(slp, cb); #ifdef SCSI_LOW_STATICS scsi_low_statics.nexus_conflict ++; #endif /* SCSI_LOW_STATICS */ } /* * Check if no current active nexus. */ if (slp->sl_Tnexus != NULL) { s = "host busy"; goto world_restart; } /* * Check a valid target id asserted ? */ if (targ >= slp->sl_ntargs || targ == slp->sl_hostid) { s = "scsi id illegal"; goto world_restart; } /* * Check the target scsi status. */ ti = slp->sl_ti[targ]; if (ti->ti_phase != PH_DISC && ti->ti_phase != PH_NULL) { s = "phase mismatch"; goto world_restart; } /* * Setup init msgsys */ slp->sl_error = 0; scsi_low_init_msgsys(slp, ti); /* * Establish our target nexus */ SCSI_LOW_SETUP_PHASE(ti, PH_RESEL); slp->sl_Tnexus = ti; #ifdef SCSI_LOW_STATICS scsi_low_statics.nexus_reselected ++; #endif /* SCSI_LOW_STATICS */ return ti; world_restart: device_printf(slp->sl_dev, "reselect(%x:unknown) %s\n", targ, s); scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "reselect: scsi world confused"); return NULL; } /************************************************************** * cmd out pointer setup **************************************************************/ int scsi_low_cmd(slp, ti) struct scsi_low_softc *slp; struct targ_info *ti; { struct slccb *cb = slp->sl_Qnexus; slp->sl_ph_count ++; if (cb == NULL) { /* * no ccb, abort! */ slp->sl_scp.scp_cmd = (u_int8_t *) &unit_ready_cmd; slp->sl_scp.scp_cmdlen = sizeof(unit_ready_cmd); slp->sl_scp.scp_datalen = 0; slp->sl_scp.scp_direction = SCSI_LOW_READ; slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); SCSI_LOW_INFO(slp, ti, "CMDOUT: ccb nexus not found"); return EINVAL; } else { #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_CMDLNK_CHECK, ti->ti_id)) { scsi_low_test_cmdlnk(slp, cb); } #endif /* SCSI_LOW_DEBUG */ } return 0; } /************************************************************** * data out pointer setup **************************************************************/ int scsi_low_data(slp, ti, bp, direction) struct scsi_low_softc *slp; struct targ_info *ti; struct buf **bp; int direction; { struct slccb *cb = slp->sl_Qnexus; if (cb != NULL && direction == cb->ccb_sscp.scp_direction) { *bp = cb->bp; return 0; } slp->sl_error |= (FATALIO | PDMAERR); slp->sl_scp.scp_datalen = 0; slp->sl_scp.scp_direction = direction; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); if (ti->ti_ophase != ti->ti_phase) { char *s; if (cb == NULL) s = "DATA PHASE: ccb nexus not found"; else s = "DATA PHASE: xfer direction mismatch"; SCSI_LOW_INFO(slp, ti, s); } *bp = NULL; return EINVAL; } /************************************************************** * MSG_SYS **************************************************************/ #define MSGINPTR_CLR(ti) {(ti)->ti_msginptr = 0; (ti)->ti_msginlen = 0;} #define MSGIN_PERIOD(ti) ((ti)->ti_msgin[3]) #define MSGIN_OFFSET(ti) ((ti)->ti_msgin[4]) #define MSGIN_WIDTHP(ti) ((ti)->ti_msgin[3]) #define MSGIN_DATA_LAST 0x30 static int scsi_low_errfunc_synch(struct scsi_low_softc *, u_int); static int scsi_low_errfunc_wide(struct scsi_low_softc *, u_int); static int scsi_low_errfunc_identify(struct scsi_low_softc *, u_int); static int scsi_low_errfunc_qtag(struct scsi_low_softc *, u_int); static int scsi_low_msgfunc_synch(struct scsi_low_softc *); static int scsi_low_msgfunc_wide(struct scsi_low_softc *); static int scsi_low_msgfunc_identify(struct scsi_low_softc *); static int scsi_low_msgfunc_abort(struct scsi_low_softc *); static int scsi_low_msgfunc_qabort(struct scsi_low_softc *); static int scsi_low_msgfunc_qtag(struct scsi_low_softc *); static int scsi_low_msgfunc_reset(struct scsi_low_softc *); struct scsi_low_msgout_data { u_int md_flags; u_int8_t md_msg; int (*md_msgfunc)(struct scsi_low_softc *); int (*md_errfunc)(struct scsi_low_softc *, u_int); #define MSG_RELEASE_ATN 0x0001 u_int md_condition; }; struct scsi_low_msgout_data scsi_low_msgout_data[] = { /* 0 */ {SCSI_LOW_MSG_RESET, MSG_RESET, scsi_low_msgfunc_reset, NULL, MSG_RELEASE_ATN}, /* 1 */ {SCSI_LOW_MSG_REJECT, MSG_REJECT, NULL, NULL, MSG_RELEASE_ATN}, /* 2 */ {SCSI_LOW_MSG_PARITY, MSG_PARITY, NULL, NULL, MSG_RELEASE_ATN}, /* 3 */ {SCSI_LOW_MSG_ERROR, MSG_I_ERROR, NULL, NULL, MSG_RELEASE_ATN}, /* 4 */ {SCSI_LOW_MSG_IDENTIFY, MSG_IDENTIFY, scsi_low_msgfunc_identify, scsi_low_errfunc_identify, 0}, /* 5 */ {SCSI_LOW_MSG_ABORT, MSG_ABORT, scsi_low_msgfunc_abort, NULL, MSG_RELEASE_ATN}, /* 6 */ {SCSI_LOW_MSG_TERMIO, MSG_TERM_IO, NULL, NULL, MSG_RELEASE_ATN}, /* 7 */ {SCSI_LOW_MSG_SIMPLE_QTAG, MSG_SIMPLE_QTAG, scsi_low_msgfunc_qtag, scsi_low_errfunc_qtag, 0}, /* 8 */ {SCSI_LOW_MSG_ORDERED_QTAG, MSG_ORDERED_QTAG, scsi_low_msgfunc_qtag, scsi_low_errfunc_qtag, 0}, /* 9 */{SCSI_LOW_MSG_HEAD_QTAG, MSG_HEAD_QTAG, scsi_low_msgfunc_qtag, scsi_low_errfunc_qtag, 0}, /* 10 */ {SCSI_LOW_MSG_ABORT_QTAG, MSG_ABORT_QTAG, scsi_low_msgfunc_qabort, NULL, MSG_RELEASE_ATN}, /* 11 */ {SCSI_LOW_MSG_CLEAR_QTAG, MSG_CLEAR_QTAG, scsi_low_msgfunc_abort, NULL, MSG_RELEASE_ATN}, /* 12 */{SCSI_LOW_MSG_WIDE, MSG_EXTEND, scsi_low_msgfunc_wide, scsi_low_errfunc_wide, MSG_RELEASE_ATN}, /* 13 */{SCSI_LOW_MSG_SYNCH, MSG_EXTEND, scsi_low_msgfunc_synch, scsi_low_errfunc_synch, MSG_RELEASE_ATN}, /* 14 */{SCSI_LOW_MSG_NOOP, MSG_NOOP, NULL, NULL, MSG_RELEASE_ATN}, /* 15 */{SCSI_LOW_MSG_ALL, 0}, }; static int scsi_low_msginfunc_ext(struct scsi_low_softc *); static int scsi_low_synch(struct scsi_low_softc *); static int scsi_low_wide(struct scsi_low_softc *); static int scsi_low_msginfunc_msg_reject(struct scsi_low_softc *); static int scsi_low_msginfunc_rejop(struct scsi_low_softc *); static int scsi_low_msginfunc_rp(struct scsi_low_softc *); static int scsi_low_msginfunc_sdp(struct scsi_low_softc *); static int scsi_low_msginfunc_disc(struct scsi_low_softc *); static int scsi_low_msginfunc_cc(struct scsi_low_softc *); static int scsi_low_msginfunc_lcc(struct scsi_low_softc *); static int scsi_low_msginfunc_parity(struct scsi_low_softc *); static int scsi_low_msginfunc_noop(struct scsi_low_softc *); static int scsi_low_msginfunc_simple_qtag(struct scsi_low_softc *); static int scsi_low_msginfunc_i_wide_residue(struct scsi_low_softc *); struct scsi_low_msgin_data { u_int md_len; int (*md_msgfunc)(struct scsi_low_softc *); }; struct scsi_low_msgin_data scsi_low_msgin_data[] = { /* 0 */ {1, scsi_low_msginfunc_cc}, /* 1 */ {2, scsi_low_msginfunc_ext}, /* 2 */ {1, scsi_low_msginfunc_sdp}, /* 3 */ {1, scsi_low_msginfunc_rp}, /* 4 */ {1, scsi_low_msginfunc_disc}, /* 5 */ {1, scsi_low_msginfunc_rejop}, /* 6 */ {1, scsi_low_msginfunc_rejop}, /* 7 */ {1, scsi_low_msginfunc_msg_reject}, /* 8 */ {1, scsi_low_msginfunc_noop}, /* 9 */ {1, scsi_low_msginfunc_parity}, /* a */ {1, scsi_low_msginfunc_lcc}, /* b */ {1, scsi_low_msginfunc_lcc}, /* c */ {1, scsi_low_msginfunc_rejop}, /* d */ {2, scsi_low_msginfunc_rejop}, /* e */ {1, scsi_low_msginfunc_rejop}, /* f */ {1, scsi_low_msginfunc_rejop}, /* 0x10 */ {1, scsi_low_msginfunc_rejop}, /* 0x11 */ {1, scsi_low_msginfunc_rejop}, /* 0x12 */ {1, scsi_low_msginfunc_rejop}, /* 0x13 */ {1, scsi_low_msginfunc_rejop}, /* 0x14 */ {1, scsi_low_msginfunc_rejop}, /* 0x15 */ {1, scsi_low_msginfunc_rejop}, /* 0x16 */ {1, scsi_low_msginfunc_rejop}, /* 0x17 */ {1, scsi_low_msginfunc_rejop}, /* 0x18 */ {1, scsi_low_msginfunc_rejop}, /* 0x19 */ {1, scsi_low_msginfunc_rejop}, /* 0x1a */ {1, scsi_low_msginfunc_rejop}, /* 0x1b */ {1, scsi_low_msginfunc_rejop}, /* 0x1c */ {1, scsi_low_msginfunc_rejop}, /* 0x1d */ {1, scsi_low_msginfunc_rejop}, /* 0x1e */ {1, scsi_low_msginfunc_rejop}, /* 0x1f */ {1, scsi_low_msginfunc_rejop}, /* 0x20 */ {2, scsi_low_msginfunc_simple_qtag}, /* 0x21 */ {2, scsi_low_msginfunc_rejop}, /* 0x22 */ {2, scsi_low_msginfunc_rejop}, /* 0x23 */ {2, scsi_low_msginfunc_i_wide_residue}, /* 0x24 */ {2, scsi_low_msginfunc_rejop}, /* 0x25 */ {2, scsi_low_msginfunc_rejop}, /* 0x26 */ {2, scsi_low_msginfunc_rejop}, /* 0x27 */ {2, scsi_low_msginfunc_rejop}, /* 0x28 */ {2, scsi_low_msginfunc_rejop}, /* 0x29 */ {2, scsi_low_msginfunc_rejop}, /* 0x2a */ {2, scsi_low_msginfunc_rejop}, /* 0x2b */ {2, scsi_low_msginfunc_rejop}, /* 0x2c */ {2, scsi_low_msginfunc_rejop}, /* 0x2d */ {2, scsi_low_msginfunc_rejop}, /* 0x2e */ {2, scsi_low_msginfunc_rejop}, /* 0x2f */ {2, scsi_low_msginfunc_rejop}, /* 0x30 */ {1, scsi_low_msginfunc_rejop} /* default rej op */ }; /************************************************************** * msgout **************************************************************/ static int scsi_low_msgfunc_synch(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; int ptr = ti->ti_msgoutlen; ti->ti_msgoutstr[ptr + 1] = MSG_EXTEND_SYNCHLEN; ti->ti_msgoutstr[ptr + 2] = MSG_EXTEND_SYNCHCODE; ti->ti_msgoutstr[ptr + 3] = ti->ti_maxsynch.period; ti->ti_msgoutstr[ptr + 4] = ti->ti_maxsynch.offset; return MSG_EXTEND_SYNCHLEN + 2; } static int scsi_low_msgfunc_wide(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; int ptr = ti->ti_msgoutlen; ti->ti_msgoutstr[ptr + 1] = MSG_EXTEND_WIDELEN; ti->ti_msgoutstr[ptr + 2] = MSG_EXTEND_WIDECODE; ti->ti_msgoutstr[ptr + 3] = ti->ti_width; return MSG_EXTEND_WIDELEN + 2; } static int scsi_low_msgfunc_identify(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; struct lun_info *li = slp->sl_Lnexus; struct slccb *cb = slp->sl_Qnexus; int ptr = ti->ti_msgoutlen; u_int8_t msg; msg = MSG_IDENTIFY; if (cb == NULL) { slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); SCSI_LOW_INFO(slp, ti, "MSGOUT: nexus unknown"); } else { if (scsi_low_is_disconnect_ok(cb) != 0) msg |= (MSG_IDENTIFY_DISCPRIV | li->li_lun); else msg |= li->li_lun; if (ti->ti_phase == PH_MSGOUT) { (*slp->sl_funcs->scsi_low_establish_lun_nexus) (slp); if (cb->ccb_tag == SCSI_LOW_UNKTAG) { (*slp->sl_funcs->scsi_low_establish_ccb_nexus) (slp); } } } ti->ti_msgoutstr[ptr + 0] = msg; return 1; } static int scsi_low_msgfunc_abort(slp) struct scsi_low_softc *slp; { SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_ABORT); return 1; } static int scsi_low_msgfunc_qabort(slp) struct scsi_low_softc *slp; { SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_TERM); return 1; } static int scsi_low_msgfunc_reset(slp) struct scsi_low_softc *slp; { SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_RESET); return 1; } static int scsi_low_msgfunc_qtag(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; struct slccb *cb = slp->sl_Qnexus; int ptr = ti->ti_msgoutlen; if (cb == NULL || cb->ccb_tag == SCSI_LOW_UNKTAG) { ti->ti_msgoutstr[ptr + 0] = MSG_NOOP; return 1; } else { ti->ti_msgoutstr[ptr + 1] = (u_int8_t) cb->ccb_tag; if (ti->ti_phase == PH_MSGOUT) { (*slp->sl_funcs->scsi_low_establish_ccb_nexus) (slp); } } return 2; } /* * The following functions are called when targets give unexpected * responces in msgin (after msgout). */ static int scsi_low_errfunc_identify(slp, msgflags) struct scsi_low_softc *slp; u_int msgflags; { if (slp->sl_Lnexus != NULL) { slp->sl_Lnexus->li_cfgflags &= ~SCSI_LOW_DISC; scsi_low_calcf_lun(slp->sl_Lnexus); } return 0; } static int scsi_low_errfunc_synch(slp, msgflags) struct scsi_low_softc *slp; u_int msgflags; { struct targ_info *ti = slp->sl_Tnexus; MSGIN_PERIOD(ti) = 0; MSGIN_OFFSET(ti) = 0; scsi_low_synch(slp); return 0; } static int scsi_low_errfunc_wide(slp, msgflags) struct scsi_low_softc *slp; u_int msgflags; { struct targ_info *ti = slp->sl_Tnexus; MSGIN_WIDTHP(ti) = 0; scsi_low_wide(slp); return 0; } static int scsi_low_errfunc_qtag(slp, msgflags) struct scsi_low_softc *slp; u_int msgflags; { if ((msgflags & SCSI_LOW_MSG_REJECT) != 0) { if (slp->sl_Qnexus != NULL) { scsi_low_deactivate_qtag(slp->sl_Qnexus); } if (slp->sl_Lnexus != NULL) { slp->sl_Lnexus->li_cfgflags &= ~SCSI_LOW_QTAG; scsi_low_calcf_lun(slp->sl_Lnexus); } device_printf(slp->sl_dev, "scsi_low: qtag msg rejected\n"); } return 0; } int scsi_low_msgout(slp, ti, fl) struct scsi_low_softc *slp; struct targ_info *ti; u_int fl; { struct scsi_low_msgout_data *mdp; int len = 0; #ifdef SCSI_LOW_DIAGNOSTIC if (ti != slp->sl_Tnexus) { scsi_low_print(slp, NULL); panic("scsi_low_msgout: Target nexus inconsistent"); } #endif /* SCSI_LOW_DIAGNOSTIC */ slp->sl_ph_count ++; if (slp->sl_ph_count > SCSI_LOW_MAX_PHCHANGES) { device_printf(slp->sl_dev, "too many phase changes\n"); slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); } /* STEP I. * Scsi phase changes. * Previously msgs asserted are accepted by our target or * processed by scsi_low_msgin. * Thus clear all saved informations. */ if ((fl & SCSI_LOW_MSGOUT_INIT) != 0) { ti->ti_omsgflags = 0; ti->ti_emsgflags = 0; } else if (slp->sl_atten == 0) { /* STEP II. * We did not assert attention, however still our target required * msgs. Resend previous msgs. */ ti->ti_msgflags |= ti->ti_omsgflags; ti->ti_omsgflags = 0; #ifdef SCSI_LOW_DIAGNOSTIC device_printf(slp->sl_dev, "scsi_low_msgout: retry msgout\n"); #endif /* SCSI_LOW_DIAGNOSTIC */ } /* STEP III. * We have no msgs. send MSG_NOOP (OK?) */ if (scsi_low_is_msgout_continue(ti, 0) == 0) scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_NOOP, 0); /* STEP IV. * Process all msgs */ ti->ti_msgoutlen = 0; slp->sl_clear_atten = 0; mdp = &scsi_low_msgout_data[0]; for ( ; mdp->md_flags != SCSI_LOW_MSG_ALL; mdp ++) { if ((ti->ti_msgflags & mdp->md_flags) != 0) { ti->ti_omsgflags |= mdp->md_flags; ti->ti_msgflags &= ~mdp->md_flags; ti->ti_emsgflags = mdp->md_flags; ti->ti_msgoutstr[ti->ti_msgoutlen] = mdp->md_msg; if (mdp->md_msgfunc != NULL) len = (*mdp->md_msgfunc) (slp); else len = 1; #ifdef SCSI_LOW_DIAGNOSTIC scsi_low_msg_log_write(&ti->ti_log_msgout, &ti->ti_msgoutstr[ti->ti_msgoutlen], len); #endif /* SCSI_LOW_DIAGNOSTIC */ ti->ti_msgoutlen += len; if ((mdp->md_condition & MSG_RELEASE_ATN) != 0) { slp->sl_clear_atten = 1; break; } if ((fl & SCSI_LOW_MSGOUT_UNIFY) == 0 || ti->ti_msgflags == 0) break; if (ti->ti_msgoutlen >= SCSI_LOW_MAX_MSGLEN - 5) break; } } if (scsi_low_is_msgout_continue(ti, 0) == 0) slp->sl_clear_atten = 1; return ti->ti_msgoutlen; } /************************************************************** * msgin **************************************************************/ static int scsi_low_msginfunc_noop(slp) struct scsi_low_softc *slp; { return 0; } static int scsi_low_msginfunc_rejop(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; u_int8_t msg = ti->ti_msgin[0]; device_printf(slp->sl_dev, "MSGIN: msg 0x%x rejected\n", (u_int) msg); scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_REJECT, 0); return 0; } static int scsi_low_msginfunc_cc(slp) struct scsi_low_softc *slp; { struct lun_info *li; SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_CMDC); /* validate status */ if (slp->sl_Qnexus == NULL) return ENOENT; slp->sl_Qnexus->ccb_sscp.scp_status = slp->sl_scp.scp_status; li = slp->sl_Lnexus; switch (slp->sl_scp.scp_status) { case ST_GOOD: li->li_maxnqio = li->li_maxnexus; break; case ST_CHKCOND: li->li_maxnqio = 0; if (li->li_qflags & SCSI_LOW_QFLAG_CA_QCLEAR) scsi_low_reset_nexus_lun(slp, li, 0); break; case ST_BUSY: li->li_maxnqio = 0; break; case ST_QUEFULL: if (li->li_maxnexus >= li->li_nqio) li->li_maxnexus = li->li_nqio - 1; li->li_maxnqio = li->li_maxnexus; break; case ST_INTERGOOD: case ST_INTERMET: slp->sl_error |= MSGERR; break; default: break; } return 0; } static int scsi_low_msginfunc_lcc(slp) struct scsi_low_softc *slp; { struct targ_info *ti; struct lun_info *li; struct slccb *ncb, *cb; ti = slp->sl_Tnexus; li = slp->sl_Lnexus; if ((cb = slp->sl_Qnexus) == NULL) goto bad; cb->ccb_sscp.scp_status = slp->sl_scp.scp_status; switch (slp->sl_scp.scp_status) { case ST_INTERGOOD: case ST_INTERMET: li->li_maxnqio = li->li_maxnexus; break; default: slp->sl_error |= MSGERR; break; } if ((li->li_flags & SCSI_LOW_LINK) == 0) goto bad; cb->ccb_error |= slp->sl_error; if (cb->ccb_error != 0) goto bad; for (ncb = TAILQ_FIRST(&slp->sl_start); ncb != NULL; ncb = TAILQ_NEXT(ncb, ccb_chain)) { if (ncb->li == li) goto cmd_link_start; } bad: SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_LCTERM); scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_REJECT, 0); return EIO; cmd_link_start: ncb->ccb_flags &= ~CCB_STARTQ; TAILQ_REMOVE(&slp->sl_start, ncb, ccb_chain); scsi_low_dealloc_qtag(ncb); ncb->ccb_tag = cb->ccb_tag; ncb->ccb_otag = cb->ccb_otag; cb->ccb_tag = SCSI_LOW_UNKTAG; cb->ccb_otag = SCSI_LOW_UNKTAG; if (scsi_low_done(slp, cb) == SCSI_LOW_DONE_RETRY) panic("%s: linked ccb retried", device_get_nameunit(slp->sl_dev)); slp->sl_Qnexus = ncb; slp->sl_ph_count = 0; ncb->ccb_error = 0; ncb->ccb_datalen = -1; ncb->ccb_scp.scp_status = ST_UNKNOWN; ncb->ccb_flags &= ~CCB_INTERNAL; scsi_low_init_msgsys(slp, ti); - (*slp->sl_osdep_fp->scsi_low_osdep_ccb_setup) (slp, ncb); + scsi_low_ccb_setup_cam(slp, ncb); if (ncb->ccb_tcmax < SCSI_LOW_MIN_TOUT) ncb->ccb_tcmax = SCSI_LOW_MIN_TOUT; ncb->ccb_tc = ncb->ccb_tcmax; /* setup saved scsi data pointer */ ncb->ccb_sscp = ncb->ccb_scp; slp->sl_scp = ncb->ccb_sscp; slp->sl_error = ncb->ccb_error; #ifdef SCSI_LOW_DIAGNOSTIC scsi_low_msg_log_init(&ti->ti_log_msgin); scsi_low_msg_log_init(&ti->ti_log_msgout); #endif /* SCSI_LOW_DIAGNOSTIC */ return EJUSTRETURN; } static int scsi_low_msginfunc_disc(slp) struct scsi_low_softc *slp; { SCSI_LOW_SETUP_MSGPHASE(slp, MSGPH_DISC); return 0; } static int scsi_low_msginfunc_sdp(slp) struct scsi_low_softc *slp; { struct slccb *cb = slp->sl_Qnexus; if (cb != NULL) { cb->ccb_sscp.scp_datalen = slp->sl_scp.scp_datalen; cb->ccb_sscp.scp_data = slp->sl_scp.scp_data; } else scsi_low_assert_msg(slp, slp->sl_Tnexus, SCSI_LOW_MSG_REJECT, 0); return 0; } static int scsi_low_msginfunc_rp(slp) struct scsi_low_softc *slp; { if (slp->sl_Qnexus != NULL) slp->sl_scp = slp->sl_Qnexus->ccb_sscp; else scsi_low_assert_msg(slp, slp->sl_Tnexus, SCSI_LOW_MSG_REJECT, 0); return 0; } static int scsi_low_synch(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; u_int period = 0, offset = 0, speed; u_char *s; int error; if ((MSGIN_PERIOD(ti) >= ti->ti_maxsynch.period && MSGIN_OFFSET(ti) <= ti->ti_maxsynch.offset) || MSGIN_OFFSET(ti) == 0) { if ((offset = MSGIN_OFFSET(ti)) != 0) period = MSGIN_PERIOD(ti); s = offset ? "synchronous" : "async"; } else { /* XXX: * Target seems to be brain damaged. * Force async transfer. */ ti->ti_maxsynch.period = 0; ti->ti_maxsynch.offset = 0; device_printf(slp->sl_dev, "target brain damaged. async transfer\n"); return EINVAL; } ti->ti_maxsynch.period = period; ti->ti_maxsynch.offset = offset; error = (*slp->sl_funcs->scsi_low_msg) (slp, ti, SCSI_LOW_MSG_SYNCH); if (error != 0) { /* XXX: * Current period and offset are not acceptable * for our adapter. * The adapter changes max synch and max offset. */ device_printf(slp->sl_dev, "synch neg failed. retry synch msg neg ...\n"); return error; } ti->ti_osynch = ti->ti_maxsynch; if (offset > 0) { ti->ti_setup_msg_done |= SCSI_LOW_MSG_SYNCH; } /* inform data */ if ((slp->sl_show_result & SHOW_SYNCH_NEG) != 0) { #ifdef SCSI_LOW_NEGOTIATE_BEFORE_SENSE struct slccb *cb = slp->sl_Qnexus; if (cb != NULL && (cb->ccb_flags & CCB_SENSE) != 0) return 0; #endif /* SCSI_LOW_NEGOTIATE_BEFORE_SENSE */ device_printf(slp->sl_dev, "(%d:*): <%s> offset %d period %dns ", ti->ti_id, s, offset, period * 4); if (period != 0) { speed = 1000 * 10 / (period * 4); printf("%d.%d M/s", speed / 10, speed % 10); } printf("\n"); } return 0; } static int scsi_low_wide(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; int error; ti->ti_width = MSGIN_WIDTHP(ti); error = (*slp->sl_funcs->scsi_low_msg) (slp, ti, SCSI_LOW_MSG_WIDE); if (error != 0) { /* XXX: * Current width is not acceptable for our adapter. * The adapter changes max width. */ device_printf(slp->sl_dev, "wide neg failed. retry wide msg neg ...\n"); return error; } ti->ti_owidth = ti->ti_width; if (ti->ti_width > SCSI_LOW_BUS_WIDTH_8) { ti->ti_setup_msg_done |= (SCSI_LOW_MSG_SYNCH | SCSI_LOW_MSG_WIDE); } /* inform data */ if ((slp->sl_show_result & SHOW_WIDE_NEG) != 0) { #ifdef SCSI_LOW_NEGOTIATE_BEFORE_SENSE struct slccb *cb = slp->sl_Qnexus; if (cb != NULL && (cb->ccb_flags & CCB_SENSE) != 0) return 0; #endif /* SCSI_LOW_NEGOTIATE_BEFORE_SENSE */ device_printf(slp->sl_dev, "(%d:*): transfer width %d bits\n", ti->ti_id, 1 << (3 + ti->ti_width)); } return 0; } static int scsi_low_msginfunc_simple_qtag(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; scsi_low_tag_t etag = (scsi_low_tag_t) ti->ti_msgin[1]; if (slp->sl_Qnexus != NULL) { if (slp->sl_Qnexus->ccb_tag != etag) { slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); SCSI_LOW_INFO(slp, ti, "MSGIN: qtag mismatch"); } } else if (scsi_low_establish_ccb(ti, slp->sl_Lnexus, etag) == NULL) { #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_NEXUS_CHECK, ti->ti_id)) return 0; #endif /* SCSI_LOW_DEBUG */ slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT_QTAG, 0); SCSI_LOW_INFO(slp, ti, "MSGIN: taged ccb not found"); } return 0; } static int scsi_low_msginfunc_i_wide_residue(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; struct slccb *cb = slp->sl_Qnexus; int res = (int) ti->ti_msgin[1]; if (cb == NULL || res <= 0 || (ti->ti_width == SCSI_LOW_BUS_WIDTH_16 && res > 1) || (ti->ti_width == SCSI_LOW_BUS_WIDTH_32 && res > 3)) return EINVAL; if (slp->sl_scp.scp_datalen + res > cb->ccb_scp.scp_datalen) return EINVAL; slp->sl_scp.scp_datalen += res; slp->sl_scp.scp_data -= res; scsi_low_data_finish(slp); return 0; } static int scsi_low_msginfunc_ext(slp) struct scsi_low_softc *slp; { struct slccb *cb = slp->sl_Qnexus; struct lun_info *li = slp->sl_Lnexus; struct targ_info *ti = slp->sl_Tnexus; int count, retry; u_int32_t *ptr; if (ti->ti_msginptr == 2) { ti->ti_msginlen = ti->ti_msgin[1] + 2; return 0; } switch (MKMSG_EXTEND(ti->ti_msgin[1], ti->ti_msgin[2])) { case MKMSG_EXTEND(MSG_EXTEND_MDPLEN, MSG_EXTEND_MDPCODE): if (cb == NULL) break; ptr = (u_int32_t *)(&ti->ti_msgin[3]); count = (int) htonl((long) (*ptr)); if(slp->sl_scp.scp_datalen - count < 0 || slp->sl_scp.scp_datalen - count > cb->ccb_scp.scp_datalen) break; slp->sl_scp.scp_datalen -= count; slp->sl_scp.scp_data += count; return 0; case MKMSG_EXTEND(MSG_EXTEND_SYNCHLEN, MSG_EXTEND_SYNCHCODE): if (li == NULL) break; retry = scsi_low_synch(slp); if (retry != 0 || (ti->ti_emsgflags & SCSI_LOW_MSG_SYNCH) == 0) scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_SYNCH, 0); #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_ATTEN_CHECK, ti->ti_id)) { scsi_low_test_atten(slp, ti, SCSI_LOW_MSG_SYNCH); } #endif /* SCSI_LOW_DEBUG */ return 0; case MKMSG_EXTEND(MSG_EXTEND_WIDELEN, MSG_EXTEND_WIDECODE): if (li == NULL) break; retry = scsi_low_wide(slp); if (retry != 0 || (ti->ti_emsgflags & SCSI_LOW_MSG_WIDE) == 0) scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_WIDE, 0); return 0; default: break; } scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_REJECT, 0); return EINVAL; } static int scsi_low_msginfunc_parity(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; /* only I -> T, invalid! */ scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_REJECT, 0); return 0; } static int scsi_low_msginfunc_msg_reject(slp) struct scsi_low_softc *slp; { struct targ_info *ti = slp->sl_Tnexus; struct scsi_low_msgout_data *mdp; u_int msgflags; if (ti->ti_emsgflags != 0) { device_printf(slp->sl_dev, "msg flags [0x%x] rejected\n", ti->ti_emsgflags); msgflags = SCSI_LOW_MSG_REJECT; mdp = &scsi_low_msgout_data[0]; for ( ; mdp->md_flags != SCSI_LOW_MSG_ALL; mdp ++) { if ((ti->ti_emsgflags & mdp->md_flags) != 0) { ti->ti_emsgflags &= ~mdp->md_flags; if (mdp->md_errfunc != NULL) (*mdp->md_errfunc) (slp, msgflags); break; } } return 0; } else { SCSI_LOW_INFO(slp, ti, "MSGIN: rejected msg not found"); slp->sl_error |= MSGERR; } return EINVAL; } int scsi_low_msgin(slp, ti, c) struct scsi_low_softc *slp; struct targ_info *ti; u_int c; { struct scsi_low_msgin_data *sdp; struct lun_info *li; u_int8_t msg; #ifdef SCSI_LOW_DIAGNOSTIC if (ti != slp->sl_Tnexus) { scsi_low_print(slp, NULL); panic("scsi_low_msgin: Target nexus inconsistent"); } #endif /* SCSI_LOW_DIAGNOSTIC */ /* * Phase changes, clear the pointer. */ if (ti->ti_ophase != ti->ti_phase) { MSGINPTR_CLR(ti); ti->ti_msgin_parity_error = 0; slp->sl_ph_count ++; if (slp->sl_ph_count > SCSI_LOW_MAX_PHCHANGES) { device_printf(slp->sl_dev, "too many phase changes\n"); slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); } } /* * Store a current messages byte into buffer and * wait for the completion of the current msg. */ ti->ti_msgin[ti->ti_msginptr ++] = (u_int8_t) c; if (ti->ti_msginptr >= SCSI_LOW_MAX_MSGLEN) { ti->ti_msginptr = SCSI_LOW_MAX_MSGLEN - 1; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_REJECT, 0); } /* * Check parity errors. */ if ((c & SCSI_LOW_DATA_PE) != 0) { ti->ti_msgin_parity_error ++; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_PARITY, 0); goto out; } if (ti->ti_msgin_parity_error != 0) goto out; /* * Calculate messages length. */ msg = ti->ti_msgin[0]; if (msg < MSGIN_DATA_LAST) sdp = &scsi_low_msgin_data[msg]; else sdp = &scsi_low_msgin_data[MSGIN_DATA_LAST]; if (ti->ti_msginlen == 0) { ti->ti_msginlen = sdp->md_len; } /* * Check comletion. */ if (ti->ti_msginptr < ti->ti_msginlen) return EJUSTRETURN; /* * Do process. */ if ((msg & MSG_IDENTIFY) == 0) { if (((*sdp->md_msgfunc) (slp)) == EJUSTRETURN) return EJUSTRETURN; } else { li = slp->sl_Lnexus; if (li == NULL) { li = scsi_low_alloc_li(ti, MSGCMD_LUN(msg), 0); if (li == NULL) goto badlun; slp->sl_Lnexus = li; (*slp->sl_funcs->scsi_low_establish_lun_nexus) (slp); } else { if (MSGCMD_LUN(msg) != li->li_lun) goto badlun; } if (slp->sl_Qnexus == NULL && li->li_nqio == 0) { if (!scsi_low_establish_ccb(ti, li, SCSI_LOW_UNKTAG)) { #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_NEXUS_CHECK, ti->ti_id) != 0) { goto out; } #endif /* SCSI_LOW_DEBUG */ goto badlun; } } } goto out; /* * Msg process completed, reset msgin pointer and assert ATN if desired. */ badlun: slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 0); SCSI_LOW_INFO(slp, ti, "MSGIN: identify wrong"); out: if (ti->ti_msginptr < ti->ti_msginlen) return EJUSTRETURN; #ifdef SCSI_LOW_DIAGNOSTIC scsi_low_msg_log_write(&ti->ti_log_msgin, &ti->ti_msgin[0], ti->ti_msginlen); #endif /* SCSI_LOW_DIAGNOSTIC */ MSGINPTR_CLR(ti); return 0; } /********************************************************** * disconnect **********************************************************/ int scsi_low_disconnected(slp, ti) struct scsi_low_softc *slp; struct targ_info *ti; { struct slccb *cb = slp->sl_Qnexus; /* check phase completion */ switch (slp->sl_msgphase) { case MSGPH_RESET: scsi_low_statusin(slp, slp->sl_Tnexus, ST_GOOD); scsi_low_msginfunc_cc(slp); scsi_low_reset_nexus_target(slp, slp->sl_Tnexus, 0); goto io_resume; case MSGPH_ABORT: scsi_low_statusin(slp, slp->sl_Tnexus, ST_GOOD); scsi_low_msginfunc_cc(slp); scsi_low_reset_nexus_lun(slp, slp->sl_Lnexus, 0); goto io_resume; case MSGPH_TERM: scsi_low_statusin(slp, slp->sl_Tnexus, ST_GOOD); scsi_low_msginfunc_cc(slp); goto io_resume; case MSGPH_DISC: if (cb != NULL) { struct lun_info *li; li = cb->li; TAILQ_INSERT_TAIL(&li->li_discq, cb, ccb_chain); cb->ccb_flags |= CCB_DISCQ; cb->ccb_error |= slp->sl_error; li->li_disc ++; ti->ti_disc ++; slp->sl_disc ++; } #ifdef SCSI_LOW_STATICS scsi_low_statics.nexus_disconnected ++; #endif /* SCSI_LOW_STATICS */ #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_DISC, ti->ti_id) != 0) { printf("## SCSI_LOW_DISCONNECTED ===============\n"); scsi_low_print(slp, NULL); } #endif /* SCSI_LOW_DEBUG */ break; case MSGPH_NULL: slp->sl_error |= FATALIO; if (ti->ti_phase == PH_SELSTART) slp->sl_error |= SELTIMEOUTIO; else slp->sl_error |= UBFERR; /* fall through */ case MSGPH_LCTERM: case MSGPH_CMDC: io_resume: if (cb == NULL) break; #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_TEST_GO(SCSI_LOW_ATTEN_CHECK, ti->ti_id)) { if (cb->ccb_omsgoutflag == SCSI_LOW_MSG_NOOP && (cb->ccb_msgoutflag != 0 || (ti->ti_msgflags & SCSI_LOW_MSG_NOOP))) { scsi_low_info(slp, ti, "ATTEN CHECK FAILED"); } } #endif /* SCSI_LOW_DEBUG */ cb->ccb_error |= slp->sl_error; if (scsi_low_done(slp, cb) == SCSI_LOW_DONE_RETRY) { cb->ccb_flags |= CCB_STARTQ; TAILQ_INSERT_HEAD(&slp->sl_start, cb, ccb_chain); } break; } scsi_low_bus_release(slp, ti); scsi_low_start(slp); return 1; } /********************************************************** * TAG operations **********************************************************/ static int scsi_low_alloc_qtag(cb) struct slccb *cb; { struct lun_info *li = cb->li; scsi_low_tag_t etag; if (cb->ccb_otag != SCSI_LOW_UNKTAG) return 0; #ifndef SCSI_LOW_ALT_QTAG_ALLOCATE etag = ffs(li->li_qtagbits); if (etag == 0) return ENOSPC; li->li_qtagbits &= ~(1 << (etag - 1)); cb->ccb_otag = etag; return 0; #else /* SCSI_LOW_ALT_QTAG_ALLOCATE */ for (etag = li->li_qd ; li->li_qd < SCSI_LOW_MAXNEXUS; li->li_qd ++) if (li->li_qtagarray[li->li_qd] == 0) goto found; for (li->li_qd = 0; li->li_qd < etag; li->li_qd ++) if (li->li_qtagarray[li->li_qd] == 0) goto found; return ENOSPC; found: li->li_qtagarray[li->li_qd] ++; cb->ccb_otag = (li->li_qd ++); return 0; #endif /* SCSI_LOW_ALT_QTAG_ALLOCATE */ } static int scsi_low_dealloc_qtag(cb) struct slccb *cb; { struct lun_info *li = cb->li; scsi_low_tag_t etag; if (cb->ccb_otag == SCSI_LOW_UNKTAG) return 0; #ifndef SCSI_LOW_ALT_QTAG_ALLOCATE etag = cb->ccb_otag - 1; #ifdef SCSI_LOW_DIAGNOSTIC if (etag >= sizeof(li->li_qtagbits) * NBBY) panic("scsi_low_dealloc_tag: illegal tag"); #endif /* SCSI_LOW_DIAGNOSTIC */ li->li_qtagbits |= (1 << etag); #else /* SCSI_LOW_ALT_QTAG_ALLOCATE */ etag = cb->ccb_otag; #ifdef SCSI_LOW_DIAGNOSTIC if (etag >= SCSI_LOW_MAXNEXUS) panic("scsi_low_dealloc_tag: illegal tag"); #endif /* SCSI_LOW_DIAGNOSTIC */ li->li_qtagarray[etag] --; #endif /* SCSI_LOW_ALT_QTAG_ALLOCATE */ cb->ccb_otag = SCSI_LOW_UNKTAG; return 0; } static struct slccb * scsi_low_revoke_ccb(slp, cb, fdone) struct scsi_low_softc *slp; struct slccb *cb; int fdone; { struct targ_info *ti = cb->ti; struct lun_info *li = cb->li; #ifdef SCSI_LOW_DIAGNOSTIC if ((cb->ccb_flags & (CCB_STARTQ | CCB_DISCQ)) == (CCB_STARTQ | CCB_DISCQ)) { panic("%s: ccb in both queue", device_get_nameunit(slp->sl_dev)); } #endif /* SCSI_LOW_DIAGNOSTIC */ if ((cb->ccb_flags & CCB_STARTQ) != 0) { TAILQ_REMOVE(&slp->sl_start, cb, ccb_chain); } if ((cb->ccb_flags & CCB_DISCQ) != 0) { TAILQ_REMOVE(&li->li_discq, cb, ccb_chain); li->li_disc --; ti->ti_disc --; slp->sl_disc --; } cb->ccb_flags &= ~(CCB_STARTQ | CCB_DISCQ | CCB_SENSE | CCB_CLEARQ | CCB_INTERNAL); if (fdone != 0 && (cb->ccb_rcnt ++ >= slp->sl_max_retry || (cb->ccb_flags & CCB_NORETRY) != 0)) { cb->ccb_error |= FATALIO; cb->ccb_flags &= ~CCB_AUTOSENSE; if (scsi_low_done(slp, cb) != SCSI_LOW_DONE_COMPLETE) panic("%s: done ccb retried", device_get_nameunit(slp->sl_dev)); return NULL; } else { cb->ccb_error |= PENDINGIO; scsi_low_deactivate_qtag(cb); scsi_low_ccb_message_retry(cb); cb->ccb_tc = cb->ccb_tcmax = SCSI_LOW_MIN_TOUT; return cb; } } static void scsi_low_reset_nexus_lun(slp, li, fdone) struct scsi_low_softc *slp; struct lun_info *li; int fdone; { struct slccb *cb, *ncb, *ecb; if (li == NULL) return; ecb = NULL; for (cb = TAILQ_FIRST(&li->li_discq); cb != NULL; cb = ncb) { ncb = TAILQ_NEXT(cb, ccb_chain); cb = scsi_low_revoke_ccb(slp, cb, fdone); if (cb != NULL) { /* * presumely keep ordering of io */ cb->ccb_flags |= CCB_STARTQ; if (ecb == NULL) { TAILQ_INSERT_HEAD(&slp->sl_start,\ cb, ccb_chain); } else { TAILQ_INSERT_AFTER(&slp->sl_start,\ ecb, cb, ccb_chain); } ecb = cb; } } } /************************************************************** * Qurik setup **************************************************************/ static void scsi_low_calcf_lun(li) struct lun_info *li; { struct targ_info *ti = li->li_ti; struct scsi_low_softc *slp = ti->ti_sc; u_int cfgflags, diskflags; if (li->li_flags_valid == SCSI_LOW_LUN_FLAGS_ALL_VALID) cfgflags = li->li_cfgflags; else cfgflags = 0; diskflags = li->li_diskflags & li->li_quirks; /* disconnect */ li->li_flags &= ~SCSI_LOW_DISC; if ((slp->sl_cfgflags & CFG_NODISC) == 0 && (diskflags & SCSI_LOW_DISK_DISC) != 0 && (cfgflags & SCSI_LOW_DISC) != 0) li->li_flags |= SCSI_LOW_DISC; /* parity */ li->li_flags |= SCSI_LOW_NOPARITY; if ((slp->sl_cfgflags & CFG_NOPARITY) == 0 && (diskflags & SCSI_LOW_DISK_PARITY) != 0 && (cfgflags & SCSI_LOW_NOPARITY) == 0) li->li_flags &= ~SCSI_LOW_NOPARITY; /* qtag */ if ((slp->sl_cfgflags & CFG_NOQTAG) == 0 && (cfgflags & SCSI_LOW_QTAG) != 0 && (diskflags & SCSI_LOW_DISK_QTAG) != 0) { li->li_flags |= SCSI_LOW_QTAG; li->li_maxnexus = SCSI_LOW_MAXNEXUS; li->li_maxnqio = li->li_maxnexus; } else { li->li_flags &= ~SCSI_LOW_QTAG; li->li_maxnexus = 0; li->li_maxnqio = li->li_maxnexus; } /* cmd link */ li->li_flags &= ~SCSI_LOW_LINK; if ((cfgflags & SCSI_LOW_LINK) != 0 && (diskflags & SCSI_LOW_DISK_LINK) != 0) li->li_flags |= SCSI_LOW_LINK; /* compatible flags */ li->li_flags &= ~SCSI_LOW_SYNC; if (ti->ti_maxsynch.offset > 0) li->li_flags |= SCSI_LOW_SYNC; #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_CALCF, ti->ti_id) != 0) { scsi_low_calcf_show(li); } #endif /* SCSI_LOW_DEBUG */ } static void scsi_low_calcf_target(ti) struct targ_info *ti; { struct scsi_low_softc *slp = ti->ti_sc; u_int offset, period, diskflags; diskflags = ti->ti_diskflags & ti->ti_quirks; /* synch */ if ((slp->sl_cfgflags & CFG_ASYNC) == 0 && (diskflags & SCSI_LOW_DISK_SYNC) != 0) { offset = ti->ti_maxsynch.offset; period = ti->ti_maxsynch.period; if (offset == 0 || period == 0) offset = period = 0; } else { offset = period = 0; } ti->ti_maxsynch.offset = offset; ti->ti_maxsynch.period = period; /* wide */ if ((diskflags & SCSI_LOW_DISK_WIDE_32) == 0 && ti->ti_width > SCSI_LOW_BUS_WIDTH_16) ti->ti_width = SCSI_LOW_BUS_WIDTH_16; if ((diskflags & SCSI_LOW_DISK_WIDE_16) == 0 && ti->ti_width > SCSI_LOW_BUS_WIDTH_8) ti->ti_width = SCSI_LOW_BUS_WIDTH_8; if (ti->ti_flags_valid == SCSI_LOW_TARG_FLAGS_ALL_VALID) { if (ti->ti_maxsynch.offset != ti->ti_osynch.offset || ti->ti_maxsynch.period != ti->ti_osynch.period) ti->ti_setup_msg |= SCSI_LOW_MSG_SYNCH; if (ti->ti_width != ti->ti_owidth) ti->ti_setup_msg |= (SCSI_LOW_MSG_WIDE | SCSI_LOW_MSG_SYNCH); ti->ti_osynch = ti->ti_maxsynch; ti->ti_owidth = ti->ti_width; } #ifdef SCSI_LOW_DEBUG if (SCSI_LOW_DEBUG_GO(SCSI_LOW_DEBUG_CALCF, ti->ti_id) != 0) { device_printf(slp->sl_dev, "(%d:*): max period(%dns) offset(%d) width(%d)\n", ti->ti_id, ti->ti_maxsynch.period * 4, ti->ti_maxsynch.offset, ti->ti_width); } #endif /* SCSI_LOW_DEBUG */ } static void scsi_low_calcf_show(li) struct lun_info *li; { struct targ_info *ti = li->li_ti; struct scsi_low_softc *slp = ti->ti_sc; device_printf(slp->sl_dev, "(%d:%d): period(%d ns) offset(%d) width(%d) flags 0x%b\n", ti->ti_id, li->li_lun, ti->ti_maxsynch.period * 4, ti->ti_maxsynch.offset, ti->ti_width, li->li_flags, SCSI_LOW_BITS); } #ifdef SCSI_LOW_START_UP_CHECK /************************************************************** * scsi world start up **************************************************************/ static int scsi_low_poll(struct scsi_low_softc *, struct slccb *); static int scsi_low_start_up(slp) struct scsi_low_softc *slp; { struct targ_info *ti; struct lun_info *li; struct slccb *cb; int target, lun; device_printf(slp->sl_dev, "scsi_low: probing all devices ....\n"); for (target = 0; target < slp->sl_ntargs; target ++) { if (target == slp->sl_hostid) { if ((slp->sl_show_result & SHOW_PROBE_RES) != 0) { device_printf(slp->sl_dev, "scsi_low: target %d (host card)\n", target); } continue; } if ((slp->sl_show_result & SHOW_PROBE_RES) != 0) { device_printf(slp->sl_dev, "scsi_low: target %d lun ", target); } ti = slp->sl_ti[target]; for (lun = 0; lun < slp->sl_nluns; lun ++) { if ((cb = SCSI_LOW_ALLOC_CCB(1)) == NULL) break; cb->osdep = NULL; cb->bp = NULL; li = scsi_low_alloc_li(ti, lun, 1); scsi_low_enqueue(slp, ti, li, cb, CCB_AUTOSENSE | CCB_POLLED, 0); scsi_low_poll(slp, cb); if (li->li_state != SCSI_LOW_LUN_OK) break; if ((slp->sl_show_result & SHOW_PROBE_RES) != 0) { printf("%d ", lun); } } if ((slp->sl_show_result & SHOW_PROBE_RES) != 0) { printf("\n"); } } return 0; } static int scsi_low_poll(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { int tcount; tcount = 0; while (slp->sl_nio > 0) { DELAY((1000 * 1000) / SCSI_LOW_POLL_HZ); (*slp->sl_funcs->scsi_low_poll) (slp); if (tcount ++ < SCSI_LOW_POLL_HZ / SCSI_LOW_TIMEOUT_HZ) continue; tcount = 0; scsi_low_timeout_check(slp); } return 0; } #endif /* SCSI_LOW_START_UP_CHECK */ /********************************************************** * DEBUG SECTION **********************************************************/ #ifdef SCSI_LOW_DEBUG static void scsi_low_test_abort(slp, ti, li) struct scsi_low_softc *slp; struct targ_info *ti; struct lun_info *li; { struct slccb *acb; if (li->li_disc > 1) { acb = TAILQ_FIRST(&li->li_discq); if (scsi_low_abort_ccb(slp, acb) == 0) { device_printf(slp->sl_dev, "aborting ccb(0x%lx) start\n", (u_long) acb); } } } static void scsi_low_test_atten(slp, ti, msg) struct scsi_low_softc *slp; struct targ_info *ti; u_int msg; { if (slp->sl_ph_count < SCSI_LOW_MAX_ATTEN_CHECK) scsi_low_assert_msg(slp, ti, msg, 0); else device_printf(slp->sl_dev, "atten check OK\n"); } static void scsi_low_test_cmdlnk(slp, cb) struct scsi_low_softc *slp; struct slccb *cb; { #define SCSI_LOW_CMDLNK_NOK (CCB_INTERNAL | CCB_SENSE | CCB_CLEARQ) if ((cb->ccb_flags & SCSI_LOW_CMDLNK_NOK) != 0) return; memcpy(cb->ccb_scsi_cmd, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); cb->ccb_scsi_cmd[slp->sl_scp.scp_cmdlen - 1] |= 1; slp->sl_scp.scp_cmd = cb->ccb_scsi_cmd; } #endif /* SCSI_LOW_DEBUG */ /* static */ void scsi_low_info(slp, ti, s) struct scsi_low_softc *slp; struct targ_info *ti; u_char *s; { if (slp == NULL) slp = LIST_FIRST(&sl_tab); if (s == NULL) s = "no message"; printf(">>>>> SCSI_LOW_INFO(0x%lx): %s\n", (u_long) slp->sl_Tnexus, s); if (ti == NULL) { TAILQ_FOREACH(ti, &slp->sl_titab, ti_chain) { scsi_low_print(slp, ti); } } else { scsi_low_print(slp, ti); } } static u_char *phase[] = { "FREE", "ARBSTART", "SELSTART", "SELECTED", "CMDOUT", "DATA", "MSGIN", "MSGOUT", "STATIN", "DISC", "RESEL" }; void scsi_low_print(slp, ti) struct scsi_low_softc *slp; struct targ_info *ti; { struct lun_info *li; struct slccb *cb; struct sc_p *sp; if (ti == NULL || ti == slp->sl_Tnexus) { ti = slp->sl_Tnexus; li = slp->sl_Lnexus; cb = slp->sl_Qnexus; } else { li = LIST_FIRST(&ti->ti_litab); cb = TAILQ_FIRST(&li->li_discq); } sp = &slp->sl_scp; device_printf(slp->sl_dev, "=== NEXUS T(0x%lx) L(0x%lx) Q(0x%lx) NIO(%d) ===\n", (u_long) ti, (u_long) li, (u_long) cb, slp->sl_nio); /* target stat */ if (ti != NULL) { u_int flags = 0, maxnqio = 0, nqio = 0; int lun = CAM_LUN_WILDCARD; if (li != NULL) { lun = li->li_lun; flags = li->li_flags; maxnqio = li->li_maxnqio; nqio = li->li_nqio; } device_printf(slp->sl_dev, "(%d:%d) ph<%s> => ph<%s> DISC(%d) QIO(%d:%d)\n", ti->ti_id, lun, phase[(int) ti->ti_ophase], phase[(int) ti->ti_phase], ti->ti_disc, nqio, maxnqio); if (cb != NULL) { printf("CCB: cmd[0] 0x%x clen 0x%x dlen 0x%x<0x%x stat 0x%x err %b\n", (u_int) cb->ccb_scp.scp_cmd[0], cb->ccb_scp.scp_cmdlen, cb->ccb_datalen, cb->ccb_scp.scp_datalen, (u_int) cb->ccb_sscp.scp_status, cb->ccb_error, SCSI_LOW_ERRORBITS); } printf("MSGIN: ptr(%x) [%x][%x][%x][%x][%x] attention: %d\n", (u_int) (ti->ti_msginptr), (u_int) (ti->ti_msgin[0]), (u_int) (ti->ti_msgin[1]), (u_int) (ti->ti_msgin[2]), (u_int) (ti->ti_msgin[3]), (u_int) (ti->ti_msgin[4]), slp->sl_atten); printf("MSGOUT: msgflags 0x%x [%x][%x][%x][%x][%x] msgoutlen %d C_FLAGS: %b\n", (u_int) ti->ti_msgflags, (u_int) (ti->ti_msgoutstr[0]), (u_int) (ti->ti_msgoutstr[1]), (u_int) (ti->ti_msgoutstr[2]), (u_int) (ti->ti_msgoutstr[3]), (u_int) (ti->ti_msgoutstr[4]), ti->ti_msgoutlen, flags, SCSI_LOW_BITS); #ifdef SCSI_LOW_DIAGNOSTIC scsi_low_msg_log_show(&ti->ti_log_msgin, "MIN LOG ", 2); scsi_low_msg_log_show(&ti->ti_log_msgout, "MOUT LOG", 2); #endif /* SCSI_LOW_DIAGNOSTIC */ } printf("SCB: daddr 0x%lx dlen 0x%x stat 0x%x err %b\n", (u_long) sp->scp_data, sp->scp_datalen, (u_int) sp->scp_status, slp->sl_error, SCSI_LOW_ERRORBITS); } Index: projects/sendfile/sys/cam/scsi/scsi_low.h =================================================================== --- projects/sendfile/sys/cam/scsi/scsi_low.h (revision 274764) +++ projects/sendfile/sys/cam/scsi/scsi_low.h (revision 274765) @@ -1,825 +1,791 @@ /* $FreeBSD$ */ /* $NecBSD: scsi_low.h,v 1.24.10.5 2001/06/26 07:31:46 honda Exp $ */ /* $NetBSD$ */ #define SCSI_LOW_DIAGNOSTIC #define SCSI_LOW_ALT_QTAG_ALLOCATE /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. All rights reserved. * * [Ported for FreeBSD CAM] * Copyright (c) 2000, 2001 * MITSUNAGA Noriaki, NOKUBI Hirotaka and TAKAHASHI Yoshihiro. * 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. */ #ifndef _SCSI_LOW_H_ #define _SCSI_LOW_H_ -/*================================================ - * Scsi low OSDEP - * (All os depend structures should be here!) - ================================================*/ /******** includes *******************************/ #include #include #include #include #include #include #include #include #include /******** functions macro ************************/ #undef MSG_IDENTIFY -/******** os depend interface structures **********/ -typedef struct scsi_sense_data scsi_low_osdep_sense_data_t; - -struct scsi_low_osdep_interface { - device_t si_dev; - - struct cam_sim *sim; - struct cam_path *path; - - int si_poll_count; - - struct callout_handle engage_ch; - struct callout_handle timeout_ch; -#ifdef SCSI_LOW_POWFUNC - struct callout_handle recover_ch; -#endif -}; - -/******** os depend interface functions *************/ -struct slccb; -struct scsi_low_softc; -#define SCSI_LOW_TIMEOUT_STOP 0 -#define SCSI_LOW_TIMEOUT_START 1 -#define SCSI_LOW_TIMEOUT_CH_IO 0 -#define SCSI_LOW_TIMEOUT_CH_ENGAGE 1 -#define SCSI_LOW_TIMEOUT_CH_RECOVER 2 - -struct scsi_low_osdep_funcs { - int (*scsi_low_osdep_attach) \ - (struct scsi_low_softc *); - int (*scsi_low_osdep_world_start) \ - (struct scsi_low_softc *); - int (*scsi_low_osdep_dettach) \ - (struct scsi_low_softc *); - int (*scsi_low_osdep_ccb_setup) \ - (struct scsi_low_softc *, struct slccb *); - int (*scsi_low_osdep_done) \ - (struct scsi_low_softc *, struct slccb *); - void (*scsi_low_osdep_timeout) \ - (struct scsi_low_softc *, int, int); -}; - /*================================================ * Generic Scsi Low header file - * (All os depend structures should be above!) ================================================*/ /************************************************* * Scsi low definitions *************************************************/ #define SCSI_LOW_SYNC DVF_SCSI_SYNC #define SCSI_LOW_DISC DVF_SCSI_DISC #define SCSI_LOW_WAIT DVF_SCSI_WAIT #define SCSI_LOW_LINK DVF_SCSI_LINK #define SCSI_LOW_QTAG DVF_SCSI_QTAG #define SCSI_LOW_NOPARITY DVF_SCSI_NOPARITY #define SCSI_LOW_SAVESP DVF_SCSI_SAVESP #define SCSI_LOW_DEFCFG DVF_SCSI_DEFCFG #define SCSI_LOW_BITS DVF_SCSI_BITS #define SCSI_LOW_PERIOD(n) DVF_SCSI_PERIOD(n) #define SCSI_LOW_OFFSET(n) DVF_SCSI_OFFSET(n) /* host scsi id and targets macro */ #ifndef SCSI_LOW_NTARGETS #define SCSI_LOW_NTARGETS 8 #endif /* SCSI_LOW_NTARGETS */ #define SCSI_LOW_NCCB 128 #define SCSI_LOW_MAX_RETRY 3 #define SCSI_LOW_MAX_SELECTION_RETRY 10 /* timeout control macro */ #define SCSI_LOW_TIMEOUT_HZ 10 #define SCSI_LOW_MIN_TOUT 12 #define SCSI_LOW_TIMEOUT_CHECK_INTERVAL 1 #define SCSI_LOW_POWDOWN_TC 15 #define SCSI_LOW_MAX_PHCHANGES 256 #define SCSI2_RESET_DELAY 5000000 /* msg */ #define SCSI_LOW_MAX_MSGLEN 32 #define SCSI_LOW_MSG_LOG_DATALEN 8 /************************************************* * Scsi Data Pointer *************************************************/ /* scsi pointer */ struct sc_p { u_int8_t *scp_data; int scp_datalen; u_int8_t *scp_cmd; int scp_cmdlen; u_int8_t scp_direction; #define SCSI_LOW_RWUNK (-1) #define SCSI_LOW_WRITE 0 #define SCSI_LOW_READ 1 u_int8_t scp_status; u_int8_t scp_spare[2]; }; /************************************************* * Command Control Block Structure *************************************************/ typedef int scsi_low_tag_t; struct targ_info; #define SCSI_LOW_UNKLUN ((u_int) -1) #define SCSI_LOW_UNKTAG ((scsi_low_tag_t) -1) struct slccb { TAILQ_ENTRY(slccb) ccb_chain; void *osdep; /* os depend structure */ struct targ_info *ti; /* targ_info */ struct lun_info *li; /* lun info */ struct buf *bp; /* io bufs */ scsi_low_tag_t ccb_tag; /* effective qtag */ scsi_low_tag_t ccb_otag; /* allocated qtag */ /***************************************** * Scsi data pointers (original and saved) *****************************************/ struct sc_p ccb_scp; /* given */ struct sc_p ccb_sscp; /* saved scsi data pointer */ int ccb_datalen; /* transfered data counter */ /***************************************** * Msgout *****************************************/ u_int ccb_msgoutflag; u_int ccb_omsgoutflag; /***************************************** * Error or Timeout counters *****************************************/ u_int ccb_flags; #define CCB_INTERNAL 0x0001 #define CCB_SENSE 0x0002 #define CCB_CLEARQ 0x0004 #define CCB_DISCQ 0x0008 #define CCB_STARTQ 0x0010 #define CCB_POLLED 0x0100 /* polling ccb */ #define CCB_NORETRY 0x0200 /* do NOT retry */ #define CCB_AUTOSENSE 0x0400 /* do a sence after CA */ #define CCB_URGENT 0x0800 /* an urgent ccb */ #define CCB_NOSDONE 0x1000 /* do not call an os done routine */ #define CCB_SCSIIO 0x2000 /* a normal scsi io coming from upper layer */ #define CCB_SILENT 0x4000 /* no terminate messages */ u_int ccb_error; int ccb_rcnt; /* retry counter */ int ccb_selrcnt; /* selection retry counter */ int ccb_tc; /* timer counter */ int ccb_tcmax; /* max timeout */ /***************************************** * Sense data buffer *****************************************/ u_int8_t ccb_scsi_cmd[12]; - scsi_low_osdep_sense_data_t ccb_sense; + struct scsi_sense_data ccb_sense; }; /************************************************* * Slccb functions *************************************************/ GENERIC_CCB_ASSERT(scsi_low, slccb) /************************************************* * Target and Lun structures *************************************************/ struct scsi_low_softc; LIST_HEAD(scsi_low_softc_tab, scsi_low_softc); TAILQ_HEAD(targ_info_tab, targ_info); LIST_HEAD(lun_info_tab, lun_info); struct lun_info { int li_lun; struct targ_info *li_ti; /* my target */ LIST_ENTRY(lun_info) lun_chain; /* targ_info link */ struct slccbtab li_discq; /* disconnect queue */ /* * qtag control */ int li_maxnexus; int li_maxnqio; int li_nqio; int li_disc; #define SCSI_LOW_MAXNEXUS (sizeof(u_int) * NBBY) u_int li_qtagbits; #ifdef SCSI_LOW_ALT_QTAG_ALLOCATE u_int8_t li_qtagarray[SCSI_LOW_MAXNEXUS]; u_int li_qd; #endif /* SCSI_LOW_ALT_QTAG_ALLOCATE */ #define SCSI_LOW_QFLAG_CA_QCLEAR 0x01 u_int li_qflags; /* * lun state */ #define SCSI_LOW_LUN_SLEEP 0x00 #define SCSI_LOW_LUN_START 0x01 #define SCSI_LOW_LUN_INQ 0x02 #define SCSI_LOW_LUN_MODEQ 0x03 #define SCSI_LOW_LUN_OK 0x04 u_int li_state; /* target lun state */ /* * lun control flags */ u_int li_flags_valid; /* valid flags */ #define SCSI_LOW_LUN_FLAGS_USER_VALID 0x0001 #define SCSI_LOW_LUN_FLAGS_DISK_VALID 0x0002 #define SCSI_LOW_LUN_FLAGS_QUIRKS_VALID 0x0004 #define SCSI_LOW_LUN_FLAGS_ALL_VALID \ (SCSI_LOW_LUN_FLAGS_USER_VALID | \ SCSI_LOW_LUN_FLAGS_DISK_VALID | SCSI_LOW_LUN_FLAGS_QUIRKS_VALID) u_int li_flags; /* real lun control flags */ u_int li_cfgflags; /* lun control flags given by user */ u_int li_diskflags; /* lun control flags given by hardware info */ u_int li_quirks; /* lun control flags given by upper layer */ /* inq buffer */ struct scsi_low_inq_data { u_int8_t sd_type; u_int8_t sd_sp1; u_int8_t sd_version; u_int8_t sd_resp; u_int8_t sd_len; u_int8_t sd_sp2[2]; u_int8_t sd_support; } __packed li_inq; /* modeq buffer */ struct scsi_low_mode_sense_data { u_int8_t sms_header[4]; struct { u_int8_t cmp_page; u_int8_t cmp_length; u_int8_t cmp_rlec; u_int8_t cmp_qc; u_int8_t cmp_eca; u_int8_t cmp_spare[3]; } __packed sms_cmp; } li_sms; }; struct scsi_low_msg_log { int slml_ptr; struct { u_int8_t msg[2]; } slml_msg[SCSI_LOW_MSG_LOG_DATALEN]; }; struct targ_info { TAILQ_ENTRY(targ_info) ti_chain; /* targ_info link */ struct scsi_low_softc *ti_sc; /* our softc */ u_int ti_id; /* scsi id */ /* * Lun chain */ struct lun_info_tab ti_litab; /* lun chain */ /* * total disconnected nexus */ int ti_disc; /* * Scsi phase control */ #define PH_NULL 0x00 #define PH_ARBSTART 0x01 #define PH_SELSTART 0x02 #define PH_SELECTED 0x03 #define PH_CMD 0x04 #define PH_DATA 0x05 #define PH_MSGIN 0x06 #define PH_MSGOUT 0x07 #define PH_STAT 0x08 #define PH_DISC 0x09 #define PH_RESEL 0x0a u_int ti_phase; /* scsi phase */ u_int ti_ophase; /* old scsi phase */ /* * Msg in */ u_int ti_msginptr; /* msgin ptr */ u_int ti_msginlen; /* expected msg length */ int ti_msgin_parity_error; /* parity error detected */ u_int8_t ti_msgin[SCSI_LOW_MAX_MSGLEN]; /* msgin buffer */ /* * Msg out */ u_int ti_msgflags; /* msgs to be asserted */ u_int ti_omsgflags; /* msgs asserted */ u_int ti_emsgflags; /* a msg currently asserted */ #define SCSI_LOW_MSG_RESET 0x00000001 #define SCSI_LOW_MSG_REJECT 0x00000002 #define SCSI_LOW_MSG_PARITY 0x00000004 #define SCSI_LOW_MSG_ERROR 0x00000008 #define SCSI_LOW_MSG_IDENTIFY 0x00000010 #define SCSI_LOW_MSG_ABORT 0x00000020 #define SCSI_LOW_MSG_TERMIO 0x00000040 #define SCSI_LOW_MSG_SIMPLE_QTAG 0x00000080 #define SCSI_LOW_MSG_ORDERED_QTAG 0x00000100 #define SCSI_LOW_MSG_HEAD_QTAG 0x00000200 #define SCSI_LOW_MSG_ABORT_QTAG 0x00000400 #define SCSI_LOW_MSG_CLEAR_QTAG 0x00000800 #define SCSI_LOW_MSG_WIDE 0x00001000 #define SCSI_LOW_MSG_SYNCH 0x00002000 #define SCSI_LOW_MSG_NOOP 0x00004000 #define SCSI_LOW_MSG_LAST 0x00008000 #define SCSI_LOW_MSG_ALL 0xffffffff /* msgout buffer */ u_int8_t ti_msgoutstr[SCSI_LOW_MAX_MSGLEN]; /* scsi msgout */ u_int ti_msgoutlen; /* msgout strlen */ /* * target initialize msgout */ u_int ti_setup_msg; /* setup msgout requests */ u_int ti_setup_msg_done; /* * synch and wide data info */ u_int ti_flags_valid; /* valid flags */ #define SCSI_LOW_TARG_FLAGS_USER_VALID 0x0001 #define SCSI_LOW_TARG_FLAGS_DISK_VALID 0x0002 #define SCSI_LOW_TARG_FLAGS_QUIRKS_VALID 0x0004 #define SCSI_LOW_TARG_FLAGS_ALL_VALID \ (SCSI_LOW_TARG_FLAGS_USER_VALID | \ SCSI_LOW_TARG_FLAGS_DISK_VALID | SCSI_LOW_TARG_FLAGS_QUIRKS_VALID) u_int ti_diskflags; /* given target disk flags */ u_int ti_quirks; /* given target quirk */ struct synch { u_int8_t offset; u_int8_t period; } ti_osynch, ti_maxsynch; /* synch data */ #define SCSI_LOW_BUS_WIDTH_8 0 #define SCSI_LOW_BUS_WIDTH_16 1 #define SCSI_LOW_BUS_WIDTH_32 2 u_int ti_owidth, ti_width; /* * lun info size. */ int ti_lunsize; #ifdef SCSI_LOW_DIAGNOSTIC struct scsi_low_msg_log ti_log_msgout; struct scsi_low_msg_log ti_log_msgin; #endif /* SCSI_LOW_DIAGNOSTIC */ }; /************************************************* * COMMON HEADER STRUCTURE *************************************************/ struct scsi_low_softc; struct proc; typedef struct scsi_low_softc *sc_low_t; #define SCSI_LOW_START_OK 0 #define SCSI_LOW_START_FAIL 1 #define SCSI_LOW_INFO_ALLOC 0 #define SCSI_LOW_INFO_REVOKE 1 #define SCSI_LOW_INFO_DEALLOC 2 #define SCSI_LOW_POWDOWN 1 #define SCSI_LOW_ENGAGE 2 #define SC_LOW_INIT_T (int (*)(sc_low_t, int)) #define SC_LOW_BUSRST_T (void (*)(sc_low_t)) #define SC_LOW_TARG_INIT_T (int (*)(sc_low_t, struct targ_info *, int)) #define SC_LOW_LUN_INIT_T (int (*)(sc_low_t, struct targ_info *, struct lun_info *, int)) #define SC_LOW_SELECT_T (int (*)(sc_low_t, struct slccb *)) #define SC_LOW_ATTEN_T (void (*)(sc_low_t)) #define SC_LOW_NEXUS_T (int (*)(sc_low_t)) #define SC_LOW_MSG_T (int (*)(sc_low_t, struct targ_info *, u_int)) #define SC_LOW_POLL_T (int (*)(void *)) #define SC_LOW_POWER_T (int (*)(sc_low_t, u_int)) #define SC_LOW_TIMEOUT_T (int (*)(sc_low_t)) struct scsi_low_funcs { int (*scsi_low_init)(sc_low_t, int); void (*scsi_low_bus_reset)(sc_low_t); int (*scsi_low_targ_init)(sc_low_t, struct targ_info *, int); int (*scsi_low_lun_init)(sc_low_t, struct targ_info *, struct lun_info *, int); int (*scsi_low_start_bus)(sc_low_t, struct slccb *); int (*scsi_low_establish_lun_nexus)(sc_low_t); int (*scsi_low_establish_ccb_nexus)(sc_low_t); void (*scsi_low_attention)(sc_low_t); int (*scsi_low_msg)(sc_low_t, struct targ_info *, u_int); int (*scsi_low_timeout)(sc_low_t); int (*scsi_low_poll)(void *); int (*scsi_low_power)(sc_low_t, u_int); int (*scsi_low_ioctl)(sc_low_t, u_long, caddr_t, int, struct proc *); }; struct scsi_low_softc { - /* os depend structure */ - struct scsi_low_osdep_interface sl_si; -#define sl_dev sl_si.si_dev - struct scsi_low_osdep_funcs *sl_osdep_fp; + device_t sl_dev; + + struct cam_sim *sl_sim; + struct cam_path *sl_path; + + int sl_poll_count; + + struct mtx sl_lock; + struct callout sl_engage_timer; + struct callout sl_timeout_timer; +#ifdef SCSI_LOW_POWFUNC + struct callout sl_recover_timer; +#endif /* our chain */ LIST_ENTRY(scsi_low_softc) sl_chain; /* my targets */ struct targ_info *sl_ti[SCSI_LOW_NTARGETS]; struct targ_info_tab sl_titab; /* current active T_L_Q nexus */ struct targ_info *sl_Tnexus; /* Target nexus */ struct lun_info *sl_Lnexus; /* Lun nexus */ struct slccb *sl_Qnexus; /* Qtag nexus */ int sl_nexus_call; /* ccb start queue */ struct slccbtab sl_start; /* retry limit and phase change counter */ int sl_max_retry; int sl_ph_count; int sl_timeout_count; /* selection & total num disconnect targets */ int sl_nio; int sl_disc; int sl_retry_sel; struct slccb *sl_selid; /* attention */ int sl_atten; /* ATN asserted */ int sl_clear_atten; /* negate ATN required */ /* scsi phase suggested by scsi msg */ u_int sl_msgphase; #define MSGPH_NULL 0x00 /* no msg */ #define MSGPH_DISC 0x01 /* disconnect msg */ #define MSGPH_CMDC 0x02 /* cmd complete msg */ #define MSGPH_ABORT 0x03 /* abort seq */ #define MSGPH_TERM 0x04 /* current io terminate */ #define MSGPH_LCTERM 0x05 /* cmd link terminated */ #define MSGPH_RESET 0x06 /* reset target */ /* error */ u_int sl_error; /* error flags */ #define FATALIO 0x0001 /* generic io error & retry io */ #define ABORTIO 0x0002 /* generic io error & terminate io */ #define TIMEOUTIO 0x0004 /* watch dog timeout */ #define SELTIMEOUTIO 0x0008 /* selection timeout */ #define PDMAERR 0x0010 /* dma xfer error */ #define MSGERR 0x0020 /* msgsys error */ #define PARITYERR 0x0040 /* parity error */ #define BUSYERR 0x0080 /* target busy error */ #define STATERR 0x0100 /* status error */ #define UACAERR 0x0200 /* target CA state, no sense check */ #define SENSEIO 0x1000 /* cmd not excuted but sense data ok */ #define SENSEERR 0x2000 /* cmd not excuted and sense data bad */ #define UBFERR 0x4000 /* unexpected bus free */ #define PENDINGIO 0x8000 /* ccb start not yet */ #define SCSI_LOW_ERRORBITS "\020\017ubferr\016senseerr\015senseio\012uacaerr\011staterr\010busy\007parity\006msgerr\005pdmaerr\004seltimeout\003timeout\002abort\001fatal" /* current scsi data pointer */ struct sc_p sl_scp; /* power control */ u_int sl_active; /* host is busy state */ int sl_powc; /* power down timer counter */ u_int sl_rstep; /* resume step */ /* configuration flags */ u_int sl_flags; #define HW_POWDOWN 0x0001 #define HW_RESUME 0x0002 #define HW_PDMASTART 0x0004 #define HW_INACTIVE 0x0008 #define HW_POWERCTRL 0x0010 #define HW_INITIALIZING 0x0020 #define HW_READ_PADDING 0x1000 #define HW_WRITE_PADDING 0x2000 u_int sl_cfgflags; #define CFG_NODISC 0x0001 #define CFG_NOPARITY 0x0002 #define CFG_NOATTEN 0x0004 #define CFG_ASYNC 0x0008 #define CFG_NOQTAG 0x0010 int sl_show_result; #define SHOW_SYNCH_NEG 0x0001 #define SHOW_WIDE_NEG 0x0002 #define SHOW_CALCF_RES 0x0010 #define SHOW_PROBE_RES 0x0020 #define SHOW_ALL_NEG -1 /* host informations */ u_int sl_hostid; int sl_nluns; int sl_ntargs; int sl_openings; /* interface functions */ struct scsi_low_funcs *sl_funcs; /* targinfo size */ int sl_targsize; }; +#define SCSI_LOW_LOCK(sl) mtx_lock(&(sl)->sl_lock) +#define SCSI_LOW_UNLOCK(sl) mtx_unlock(&(sl)->sl_lock) +#define SCSI_LOW_ASSERT_LOCKED(sl) mtx_assert(&(sl)->sl_lock, MA_OWNED) + /************************************************* * SCSI LOW service functions *************************************************/ /* * Scsi low attachment function. */ int scsi_low_attach(struct scsi_low_softc *, int, int, int, int, int); -int scsi_low_dettach(struct scsi_low_softc *); +int scsi_low_detach(struct scsi_low_softc *); /* * Scsi low interface activate or deactivate functions */ int scsi_low_is_busy(struct scsi_low_softc *); int scsi_low_activate(struct scsi_low_softc *); int scsi_low_deactivate(struct scsi_low_softc *); /* * Scsi phase "bus service" functions. * These functions are corresponding to each scsi bus phaeses. */ /* bus idle phase (other initiators or targets release bus) */ void scsi_low_bus_idle(struct scsi_low_softc *); /* arbitration and selection phase */ void scsi_low_arbit_fail(struct scsi_low_softc *, struct slccb *); static __inline void scsi_low_arbit_win(struct scsi_low_softc *); /* msgout phase */ #define SCSI_LOW_MSGOUT_INIT 0x00000001 #define SCSI_LOW_MSGOUT_UNIFY 0x00000002 int scsi_low_msgout(struct scsi_low_softc *, struct targ_info *, u_int); /* msgin phase */ #define SCSI_LOW_DATA_PE 0x80000000 int scsi_low_msgin(struct scsi_low_softc *, struct targ_info *, u_int); /* statusin phase */ static __inline int scsi_low_statusin(struct scsi_low_softc *, struct targ_info *, u_int); /* data phase */ int scsi_low_data(struct scsi_low_softc *, struct targ_info *, struct buf **, int); static __inline void scsi_low_data_finish(struct scsi_low_softc *); /* cmd phase */ int scsi_low_cmd(struct scsi_low_softc *, struct targ_info *); /* reselection phase */ struct targ_info *scsi_low_reselected(struct scsi_low_softc *, u_int); /* disconnection phase */ int scsi_low_disconnected(struct scsi_low_softc *, struct targ_info *); /* * Scsi bus restart function. * Canncel all established nexuses => scsi system initialized => restart jobs. */ #define SCSI_LOW_RESTART_HARD 1 #define SCSI_LOW_RESTART_SOFT 0 int scsi_low_restart(struct scsi_low_softc *, int, u_char *); /* * Scsi utility fucntions */ /* print current status */ void scsi_low_print(struct scsi_low_softc *, struct targ_info *); /* bus reset utility */ void scsi_low_bus_reset(struct scsi_low_softc *); /************************************************* * Message macro defs *************************************************/ #define SCSI_LOW_SETUP_PHASE(ti, phase) \ { \ (ti)->ti_ophase = ti->ti_phase; \ (ti)->ti_phase = (phase); \ } #define SCSI_LOW_SETUP_MSGPHASE(slp, PHASE) \ { \ (slp)->sl_msgphase = (PHASE); \ } #define SCSI_LOW_ASSERT_ATN(slp) \ { \ (slp)->sl_atten = 1; \ } #define SCSI_LOW_DEASSERT_ATN(slp) \ { \ (slp)->sl_atten = 0; \ } /************************************************* * Inline functions *************************************************/ static __inline void scsi_low_attention(struct scsi_low_softc *); static __inline int scsi_low_is_msgout_continue(struct targ_info *, u_int); static __inline int scsi_low_assert_msg(struct scsi_low_softc *, struct targ_info *, u_int, int); static __inline int scsi_low_is_disconnect_ok(struct slccb *); static __inline int scsi_low_is_msgout_continue(ti, mask) struct targ_info *ti; u_int mask; { return ((ti->ti_msgflags & (~mask)) != 0); } static __inline int scsi_low_is_disconnect_ok(cb) struct slccb *cb; { return ((cb->li->li_flags & SCSI_LOW_DISC) != 0 && (cb->ccb_flags & (CCB_SENSE | CCB_CLEARQ)) == 0); } static __inline void scsi_low_attention(slp) struct scsi_low_softc *slp; { if (slp->sl_atten != 0) return; (*slp->sl_funcs->scsi_low_attention) (slp); SCSI_LOW_ASSERT_ATN(slp); } static __inline int scsi_low_assert_msg(slp, ti, msg, now) struct scsi_low_softc *slp; struct targ_info *ti; u_int msg; int now; { ti->ti_msgflags |= msg; if (now != 0) scsi_low_attention(slp); return 0; } static __inline void scsi_low_arbit_win(slp) struct scsi_low_softc *slp; { slp->sl_selid = NULL; } static __inline void scsi_low_data_finish(slp) struct scsi_low_softc *slp; { if (slp->sl_Qnexus != NULL) { slp->sl_Qnexus->ccb_datalen = slp->sl_scp.scp_datalen; } } static __inline int scsi_low_statusin(slp, ti, c) struct scsi_low_softc *slp; struct targ_info *ti; u_int c; { slp->sl_ph_count ++; if ((c & SCSI_LOW_DATA_PE) != 0) { scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ERROR, 0); return EIO; } slp->sl_scp.scp_status = (u_int8_t) c; return 0; } /************************************************* * Message out defs *************************************************/ /* XXX: use scsi_message.h */ #define ST_GOOD 0x00 #define ST_CHKCOND 0x02 #define ST_MET 0x04 #define ST_BUSY 0x08 #define ST_INTERGOOD 0x10 #define ST_INTERMET 0x14 #define ST_CONFLICT 0x18 #define ST_CMDTERM 0x22 #define ST_QUEFULL 0x28 #define ST_UNKNOWN 0xff #define MSG_COMP 0x00 #define MSG_EXTEND 0x01 #define MKMSG_EXTEND(XLEN, XCODE) ((((u_int)(XLEN)) << NBBY) | ((u_int)(XCODE))) #define MSG_EXTEND_MDPCODE 0x00 #define MSG_EXTEND_MDPLEN 0x05 #define MSG_EXTEND_SYNCHCODE 0x01 #define MSG_EXTEND_SYNCHLEN 0x03 #define MSG_EXTEND_WIDECODE 0x03 #define MSG_EXTEND_WIDELEN 0x02 #define MSG_SAVESP 0x02 #define MSG_RESTORESP 0x03 #define MSG_DISCON 0x04 #define MSG_I_ERROR 0x05 #define MSG_ABORT 0x06 #define MSG_REJECT 0x07 #define MSG_NOOP 0x08 #define MSG_PARITY 0x09 #define MSG_LCOMP 0x0a #define MSG_LCOMP_F 0x0b #define MSG_RESET 0x0c #define MSG_ABORT_QTAG 0x0d #define MSG_CLEAR_QTAG 0x0e #define MSG_TERM_IO 0x11 #define MSG_SIMPLE_QTAG 0x20 #define MSG_HEAD_QTAG 0x21 #define MSG_ORDERED_QTAG 0x22 #define MSG_IDENTIFY 0x80 #define MSG_IDENTIFY_DISCPRIV 0x40 #endif /* !_SCSI_LOW_H_ */ Index: projects/sendfile/sys/cam/scsi/scsi_xpt.c =================================================================== --- projects/sendfile/sys/cam/scsi/scsi_xpt.c (revision 274764) +++ projects/sendfile/sys/cam/scsi/scsi_xpt.c (revision 274765) @@ -1,3011 +1,2995 @@ /*- * Implementation of the SCSI Transport * * Copyright (c) 1997, 1998, 1999 Justin T. Gibbs. * Copyright (c) 1997, 1998, 1999 Kenneth D. Merry. * 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include /* for xpt_print below */ #include "opt_cam.h" struct scsi_quirk_entry { struct scsi_inquiry_pattern inq_pat; u_int8_t quirks; #define CAM_QUIRK_NOLUNS 0x01 #define CAM_QUIRK_NOVPDS 0x02 #define CAM_QUIRK_HILUNS 0x04 #define CAM_QUIRK_NOHILUNS 0x08 #define CAM_QUIRK_NORPTLUNS 0x10 u_int mintags; u_int maxtags; }; #define SCSI_QUIRK(dev) ((struct scsi_quirk_entry *)((dev)->quirk)) static int cam_srch_hi = 0; static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS); SYSCTL_PROC(_kern_cam, OID_AUTO, cam_srch_hi, CTLTYPE_INT | CTLFLAG_RWTUN, 0, 0, sysctl_cam_search_luns, "I", "allow search above LUN 7 for SCSI3 and greater devices"); #define CAM_SCSI2_MAXLUN 8 #define CAM_CAN_GET_SIMPLE_LUN(x, i) \ ((((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ RPL_LUNDATA_ATYP_PERIPH) || \ (((x)->luns[i].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ RPL_LUNDATA_ATYP_FLAT)) #define CAM_GET_SIMPLE_LUN(lp, i, lval) \ if (((lp)->luns[(i)].lundata[0] & RPL_LUNDATA_ATYP_MASK) == \ RPL_LUNDATA_ATYP_PERIPH) { \ (lval) = (lp)->luns[(i)].lundata[1]; \ } else { \ (lval) = (lp)->luns[(i)].lundata[0]; \ (lval) &= RPL_LUNDATA_FLAT_LUN_MASK; \ (lval) <<= 8; \ (lval) |= (lp)->luns[(i)].lundata[1]; \ } #define CAM_GET_LUN(lp, i, lval) \ (lval) = scsi_8btou64((lp)->luns[(i)].lundata); \ (lval) = CAM_EXTLUN_BYTE_SWIZZLE(lval); /* * If we're not quirked to search <= the first 8 luns * and we are either quirked to search above lun 8, * or we're > SCSI-2 and we've enabled hilun searching, * or we're > SCSI-2 and the last lun was a success, * we can look for luns above lun 8. */ #define CAN_SRCH_HI_SPARSE(dv) \ (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2 && cam_srch_hi))) #define CAN_SRCH_HI_DENSE(dv) \ (((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_NOHILUNS) == 0) \ && ((SCSI_QUIRK(dv)->quirks & CAM_QUIRK_HILUNS) \ || (SID_ANSI_REV(&dv->inq_data) > SCSI_REV_2))) static periph_init_t probe_periph_init; static struct periph_driver probe_driver = { probe_periph_init, "probe", TAILQ_HEAD_INITIALIZER(probe_driver.units), /* generation */ 0, CAM_PERIPH_DRV_EARLY }; PERIPHDRIVER_DECLARE(probe, probe_driver); typedef enum { PROBE_TUR, PROBE_INQUIRY, /* this counts as DV0 for Basic Domain Validation */ PROBE_FULL_INQUIRY, PROBE_REPORT_LUNS, PROBE_MODE_SENSE, PROBE_SUPPORTED_VPD_LIST, PROBE_DEVICE_ID, PROBE_SERIAL_NUM, PROBE_TUR_FOR_NEGOTIATION, PROBE_INQUIRY_BASIC_DV1, PROBE_INQUIRY_BASIC_DV2, PROBE_DV_EXIT, PROBE_DONE, PROBE_INVALID } probe_action; static char *probe_action_text[] = { "PROBE_TUR", "PROBE_INQUIRY", "PROBE_FULL_INQUIRY", "PROBE_REPORT_LUNS", "PROBE_MODE_SENSE", "PROBE_SUPPORTED_VPD_LIST", "PROBE_DEVICE_ID", "PROBE_SERIAL_NUM", "PROBE_TUR_FOR_NEGOTIATION", "PROBE_INQUIRY_BASIC_DV1", "PROBE_INQUIRY_BASIC_DV2", "PROBE_DV_EXIT", "PROBE_DONE", "PROBE_INVALID" }; #define PROBE_SET_ACTION(softc, newaction) \ do { \ char **text; \ text = probe_action_text; \ CAM_DEBUG((softc)->periph->path, CAM_DEBUG_PROBE, \ ("Probe %s to %s\n", text[(softc)->action], \ text[(newaction)])); \ (softc)->action = (newaction); \ } while(0) typedef enum { PROBE_INQUIRY_CKSUM = 0x01, PROBE_SERIAL_CKSUM = 0x02, PROBE_NO_ANNOUNCE = 0x04, PROBE_EXTLUN = 0x08 } probe_flags; typedef struct { TAILQ_HEAD(, ccb_hdr) request_ccbs; probe_action action; union ccb saved_ccb; probe_flags flags; MD5_CTX context; u_int8_t digest[16]; struct cam_periph *periph; } probe_softc; static const char quantum[] = "QUANTUM"; static const char sony[] = "SONY"; static const char west_digital[] = "WDIGTL"; static const char samsung[] = "SAMSUNG"; static const char seagate[] = "SEAGATE"; static const char microp[] = "MICROP"; static struct scsi_quirk_entry scsi_quirk_table[] = { { /* Reports QUEUE FULL for temporary resource shortages */ { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP39100*", "*" }, /*quirks*/0, /*mintags*/24, /*maxtags*/32 }, { /* Reports QUEUE FULL for temporary resource shortages */ { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP34550*", "*" }, /*quirks*/0, /*mintags*/24, /*maxtags*/32 }, { /* Reports QUEUE FULL for temporary resource shortages */ { T_DIRECT, SIP_MEDIA_FIXED, quantum, "XP32275*", "*" }, /*quirks*/0, /*mintags*/24, /*maxtags*/32 }, { /* Broken tagged queuing drive */ { T_DIRECT, SIP_MEDIA_FIXED, microp, "4421-07*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* Broken tagged queuing drive */ { T_DIRECT, SIP_MEDIA_FIXED, "HP", "C372*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* Broken tagged queuing drive */ { T_DIRECT, SIP_MEDIA_FIXED, microp, "3391*", "x43h" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* * Unfortunately, the Quantum Atlas III has the same * problem as the Atlas II drives above. * Reported by: "Johan Granlund" * * For future reference, the drive with the problem was: * QUANTUM QM39100TD-SW N1B0 * * It's possible that Quantum will fix the problem in later * firmware revisions. If that happens, the quirk entry * will need to be made specific to the firmware revisions * with the problem. * */ /* Reports QUEUE FULL for temporary resource shortages */ { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM39100*", "*" }, /*quirks*/0, /*mintags*/24, /*maxtags*/32 }, { /* * 18 Gig Atlas III, same problem as the 9G version. * Reported by: Andre Albsmeier * * * For future reference, the drive with the problem was: * QUANTUM QM318000TD-S N491 */ /* Reports QUEUE FULL for temporary resource shortages */ { T_DIRECT, SIP_MEDIA_FIXED, quantum, "QM318000*", "*" }, /*quirks*/0, /*mintags*/24, /*maxtags*/32 }, { /* * Broken tagged queuing drive * Reported by: Bret Ford * and: Martin Renters */ { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST410800*", "71*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, /* * The Seagate Medalist Pro drives have very poor write * performance with anything more than 2 tags. * * Reported by: Paul van der Zwan * Drive: * * Reported by: Jeremy Lea * Drive: * * No one has actually reported that the 9G version * (ST39140*) of the Medalist Pro has the same problem, but * we're assuming that it does because the 4G and 6.5G * versions of the drive are broken. */ { { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST34520*", "*"}, /*quirks*/0, /*mintags*/2, /*maxtags*/2 }, { { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST36530*", "*"}, /*quirks*/0, /*mintags*/2, /*maxtags*/2 }, { { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST39140*", "*"}, /*quirks*/0, /*mintags*/2, /*maxtags*/2 }, { /* * Experiences command timeouts under load with a * tag count higher than 55. */ { T_DIRECT, SIP_MEDIA_FIXED, seagate, "ST3146855LW", "*"}, /*quirks*/0, /*mintags*/2, /*maxtags*/55 }, { /* * Slow when tagged queueing is enabled. Write performance * steadily drops off with more and more concurrent * transactions. Best sequential write performance with * tagged queueing turned off and write caching turned on. * * PR: kern/10398 * Submitted by: Hideaki Okada * Drive: DCAS-34330 w/ "S65A" firmware. * * The drive with the problem had the "S65A" firmware * revision, and has also been reported (by Stephen J. * Roznowski ) for a drive with the "S61A" * firmware revision. * * Although no one has reported problems with the 2 gig * version of the DCAS drive, the assumption is that it * has the same problems as the 4 gig version. Therefore * this quirk entries disables tagged queueing for all * DCAS drives. */ { T_DIRECT, SIP_MEDIA_FIXED, "IBM", "DCAS*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* Broken tagged queuing drive */ { T_DIRECT, SIP_MEDIA_REMOVABLE, "iomega", "jaz*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* Broken tagged queuing drive */ { T_DIRECT, SIP_MEDIA_FIXED, "CONNER", "CFP2107*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* This does not support other than LUN 0 */ { T_DIRECT, SIP_MEDIA_FIXED, "VMware*", "*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 }, { /* * Broken tagged queuing drive. * Submitted by: * NAKAJI Hiroyuki * in PR kern/9535 */ { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN34324U*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* * Slow when tagged queueing is enabled. (1.5MB/sec versus * 8MB/sec.) * Submitted by: Andrew Gallatin * Best performance with these drives is achieved with * tagged queueing turned off, and write caching turned on. */ { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "WDE*", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* * Slow when tagged queueing is enabled. (1.5MB/sec versus * 8MB/sec.) * Submitted by: Andrew Gallatin * Best performance with these drives is achieved with * tagged queueing turned off, and write caching turned on. */ { T_DIRECT, SIP_MEDIA_FIXED, west_digital, "ENTERPRISE", "*" }, /*quirks*/0, /*mintags*/0, /*maxtags*/0 }, { /* * Doesn't handle queue full condition correctly, * so we need to limit maxtags to what the device * can handle instead of determining this automatically. */ { T_DIRECT, SIP_MEDIA_FIXED, samsung, "WN321010S*", "*" }, /*quirks*/0, /*mintags*/2, /*maxtags*/32 }, { /* Really only one LUN */ { T_ENCLOSURE, SIP_MEDIA_FIXED, "SUN", "SENA", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* I can't believe we need a quirk for DPT volumes. */ { T_ANY, SIP_MEDIA_FIXED|SIP_MEDIA_REMOVABLE, "DPT", "*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/255 }, { /* * Many Sony CDROM drives don't like multi-LUN probing. */ { T_CDROM, SIP_MEDIA_REMOVABLE, sony, "CD-ROM CDU*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * This drive doesn't like multiple LUN probing. * Submitted by: Parag Patel */ { T_WORM, SIP_MEDIA_REMOVABLE, sony, "CD-R CDU9*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { { T_WORM, SIP_MEDIA_REMOVABLE, "YAMAHA", "CDR100*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * The 8200 doesn't like multi-lun probing, and probably * don't like serial number requests either. */ { T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", "EXB-8200*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * Let's try the same as above, but for a drive that says * it's an IPL-6860 but is actually an EXB 8200. */ { T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "EXABYTE", "IPL-6860*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * These Hitachi drives don't like multi-lun probing. * The PR submitter has a DK319H, but says that the Linux * kernel has a similar work-around for the DK312 and DK314, * so all DK31* drives are quirked here. * PR: misc/18793 * Submitted by: Paul Haddad */ { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK31*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/2, /*maxtags*/255 }, { /* * The Hitachi CJ series with J8A8 firmware apparantly has * problems with tagged commands. * PR: 23536 * Reported by: amagai@nue.org */ { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "DK32CJ*", "J8A8" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * These are the large storage arrays. * Submitted by: William Carrel */ { T_DIRECT, SIP_MEDIA_FIXED, "HITACHI", "OPEN*", "*" }, CAM_QUIRK_HILUNS, 2, 1024 }, { /* * This old revision of the TDC3600 is also SCSI-1, and * hangs upon serial number probing. */ { T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "TANDBERG", " TDC 3600", "U07:" }, CAM_QUIRK_NOVPDS, /*mintags*/0, /*maxtags*/0 }, { /* * Would repond to all LUNs if asked for. */ { T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "CALIPER", "CP150", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* * Would repond to all LUNs if asked for. */ { T_SEQUENTIAL, SIP_MEDIA_REMOVABLE, "KENNEDY", "96X2*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* Submitted by: Matthew Dodd */ { T_PROCESSOR, SIP_MEDIA_FIXED, "Cabletrn", "EA41*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* Submitted by: Matthew Dodd */ { T_PROCESSOR, SIP_MEDIA_FIXED, "CABLETRN", "EA41*", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* TeraSolutions special settings for TRC-22 RAID */ { T_DIRECT, SIP_MEDIA_FIXED, "TERASOLU", "TRC-22", "*" }, /*quirks*/0, /*mintags*/55, /*maxtags*/255 }, { /* Veritas Storage Appliance */ { T_DIRECT, SIP_MEDIA_FIXED, "VERITAS", "*", "*" }, CAM_QUIRK_HILUNS, /*mintags*/2, /*maxtags*/1024 }, { /* * Would respond to all LUNs. Device type and removable * flag are jumper-selectable. */ { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, "MaxOptix", "Tahiti 1", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { /* EasyRAID E5A aka. areca ARC-6010 */ { T_DIRECT, SIP_MEDIA_FIXED, "easyRAID", "*", "*" }, CAM_QUIRK_NOHILUNS, /*mintags*/2, /*maxtags*/255 }, { { T_ENCLOSURE, SIP_MEDIA_FIXED, "DP", "BACKPLANE", "*" }, CAM_QUIRK_NOLUNS, /*mintags*/0, /*maxtags*/0 }, { { T_DIRECT, SIP_MEDIA_REMOVABLE, "Garmin", "*", "*" }, CAM_QUIRK_NORPTLUNS, /*mintags*/2, /*maxtags*/255 }, { /* Default tagged queuing parameters for all devices */ { T_ANY, SIP_MEDIA_REMOVABLE|SIP_MEDIA_FIXED, /*vendor*/"*", /*product*/"*", /*revision*/"*" }, /*quirks*/0, /*mintags*/2, /*maxtags*/255 }, }; static const int scsi_quirk_table_size = sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table); static cam_status proberegister(struct cam_periph *periph, void *arg); static void probeschedule(struct cam_periph *probe_periph); static void probestart(struct cam_periph *periph, union ccb *start_ccb); static void proberequestdefaultnegotiation(struct cam_periph *periph); static int proberequestbackoff(struct cam_periph *periph, struct cam_ed *device); static void probedone(struct cam_periph *periph, union ccb *done_ccb); static void probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new, probe_flags flags); static void probecleanup(struct cam_periph *periph); static void scsi_find_quirk(struct cam_ed *device); static void scsi_scan_bus(struct cam_periph *periph, union ccb *ccb); static void scsi_scan_lun(struct cam_periph *periph, struct cam_path *path, cam_flags flags, union ccb *ccb); static void xptscandone(struct cam_periph *periph, union ccb *done_ccb); static struct cam_ed * scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id); static void scsi_devise_transport(struct cam_path *path); static void scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, int async_update); static void scsi_toggle_tags(struct cam_path *path); static void scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg); static void scsi_action(union ccb *start_ccb); static void scsi_announce_periph(struct cam_periph *periph); static struct xpt_xport scsi_xport = { .alloc_device = scsi_alloc_device, .action = scsi_action, .async = scsi_dev_async, .announce = scsi_announce_periph, }; struct xpt_xport * scsi_get_xport(void) { return (&scsi_xport); } static void probe_periph_init() { } static cam_status proberegister(struct cam_periph *periph, void *arg) { union ccb *request_ccb; /* CCB representing the probe request */ cam_status status; probe_softc *softc; request_ccb = (union ccb *)arg; if (request_ccb == NULL) { printf("proberegister: no probe CCB, " "can't register device\n"); return(CAM_REQ_CMP_ERR); } softc = (probe_softc *)malloc(sizeof(*softc), M_CAMXPT, M_NOWAIT); if (softc == NULL) { printf("proberegister: Unable to probe new device. " "Unable to allocate softc\n"); return(CAM_REQ_CMP_ERR); } TAILQ_INIT(&softc->request_ccbs); TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, periph_links.tqe); softc->flags = 0; periph->softc = softc; softc->periph = periph; softc->action = PROBE_INVALID; status = cam_periph_acquire(periph); if (status != CAM_REQ_CMP) { return (status); } CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe started\n")); scsi_devise_transport(periph->path); /* * Ensure we've waited at least a bus settle * delay before attempting to probe the device. * For HBAs that don't do bus resets, this won't make a difference. */ cam_periph_freeze_after_event(periph, &periph->path->bus->last_reset, scsi_delay); probeschedule(periph); return(CAM_REQ_CMP); } static void probeschedule(struct cam_periph *periph) { struct ccb_pathinq cpi; union ccb *ccb; probe_softc *softc; softc = (probe_softc *)periph->softc; ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); xpt_setup_ccb(&cpi.ccb_h, periph->path, CAM_PRIORITY_NONE); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); /* * If a device has gone away and another device, or the same one, * is back in the same place, it should have a unit attention * condition pending. It will not report the unit attention in * response to an inquiry, which may leave invalid transfer * negotiations in effect. The TUR will reveal the unit attention * condition. Only send the TUR for lun 0, since some devices * will get confused by commands other than inquiry to non-existent * luns. If you think a device has gone away start your scan from * lun 0. This will insure that any bogus transfer settings are * invalidated. * * If we haven't seen the device before and the controller supports * some kind of transfer negotiation, negotiate with the first * sent command if no bus reset was performed at startup. This * ensures that the device is not confused by transfer negotiation * settings left over by loader or BIOS action. */ if (((ccb->ccb_h.path->device->flags & CAM_DEV_UNCONFIGURED) == 0) && (ccb->ccb_h.target_lun == 0)) { PROBE_SET_ACTION(softc, PROBE_TUR); } else if ((cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) != 0 && (cpi.hba_misc & PIM_NOBUSRESET) != 0) { proberequestdefaultnegotiation(periph); PROBE_SET_ACTION(softc, PROBE_INQUIRY); } else { PROBE_SET_ACTION(softc, PROBE_INQUIRY); } if (ccb->crcn.flags & CAM_EXPECT_INQ_CHANGE) softc->flags |= PROBE_NO_ANNOUNCE; else softc->flags &= ~PROBE_NO_ANNOUNCE; if (cpi.hba_misc & PIM_EXTLUNS) softc->flags |= PROBE_EXTLUN; else softc->flags &= ~PROBE_EXTLUN; xpt_schedule(periph, CAM_PRIORITY_XPT); } static void probestart(struct cam_periph *periph, union ccb *start_ccb) { /* Probe the device that our peripheral driver points to */ struct ccb_scsiio *csio; probe_softc *softc; CAM_DEBUG(start_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probestart\n")); softc = (probe_softc *)periph->softc; csio = &start_ccb->csio; again: switch (softc->action) { case PROBE_TUR: case PROBE_TUR_FOR_NEGOTIATION: case PROBE_DV_EXIT: { scsi_test_unit_ready(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, /*timeout*/60000); break; } case PROBE_INQUIRY: case PROBE_FULL_INQUIRY: case PROBE_INQUIRY_BASIC_DV1: case PROBE_INQUIRY_BASIC_DV2: { u_int inquiry_len; struct scsi_inquiry_data *inq_buf; inq_buf = &periph->path->device->inq_data; /* * If the device is currently configured, we calculate an * MD5 checksum of the inquiry data, and if the serial number * length is greater than 0, add the serial number data * into the checksum as well. Once the inquiry and the * serial number check finish, we attempt to figure out * whether we still have the same device. */ if ((periph->path->device->flags & CAM_DEV_UNCONFIGURED) == 0) { MD5Init(&softc->context); MD5Update(&softc->context, (unsigned char *)inq_buf, sizeof(struct scsi_inquiry_data)); softc->flags |= PROBE_INQUIRY_CKSUM; if (periph->path->device->serial_num_len > 0) { MD5Update(&softc->context, periph->path->device->serial_num, periph->path->device->serial_num_len); softc->flags |= PROBE_SERIAL_CKSUM; } MD5Final(softc->digest, &softc->context); } if (softc->action == PROBE_INQUIRY) inquiry_len = SHORT_INQUIRY_LENGTH; else inquiry_len = SID_ADDITIONAL_LENGTH(inq_buf); /* * Some parallel SCSI devices fail to send an * ignore wide residue message when dealing with * odd length inquiry requests. Round up to be * safe. */ inquiry_len = roundup2(inquiry_len, 2); if (softc->action == PROBE_INQUIRY_BASIC_DV1 || softc->action == PROBE_INQUIRY_BASIC_DV2) { inq_buf = malloc(inquiry_len, M_CAMXPT, M_NOWAIT); } if (inq_buf == NULL) { xpt_print(periph->path, "malloc failure- skipping Basic" "Domain Validation\n"); PROBE_SET_ACTION(softc, PROBE_DV_EXIT); scsi_test_unit_ready(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, SSD_FULL_SIZE, /*timeout*/60000); break; } scsi_inquiry(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, (u_int8_t *)inq_buf, inquiry_len, /*evpd*/FALSE, /*page_code*/0, SSD_MIN_SIZE, /*timeout*/60 * 1000); break; } case PROBE_REPORT_LUNS: { void *rp; rp = malloc(periph->path->target->rpl_size, M_CAMXPT, M_NOWAIT | M_ZERO); if (rp == NULL) { struct scsi_inquiry_data *inq_buf; inq_buf = &periph->path->device->inq_data; xpt_print(periph->path, "Unable to alloc report luns storage\n"); if (INQ_DATA_TQ_ENABLED(inq_buf)) PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); else PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); goto again; } scsi_report_luns(csio, 5, probedone, MSG_SIMPLE_Q_TAG, RPL_REPORT_DEFAULT, rp, periph->path->target->rpl_size, SSD_FULL_SIZE, 60000); break; break; } case PROBE_MODE_SENSE: { void *mode_buf; int mode_buf_len; mode_buf_len = sizeof(struct scsi_mode_header_6) + sizeof(struct scsi_mode_blk_desc) + sizeof(struct scsi_control_page); mode_buf = malloc(mode_buf_len, M_CAMXPT, M_NOWAIT); if (mode_buf != NULL) { scsi_mode_sense(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, /*dbd*/FALSE, SMS_PAGE_CTRL_CURRENT, SMS_CONTROL_MODE_PAGE, mode_buf, mode_buf_len, SSD_FULL_SIZE, /*timeout*/60000); break; } xpt_print(periph->path, "Unable to mode sense control page - " "malloc failure\n"); PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); } /* FALLTHROUGH */ case PROBE_SUPPORTED_VPD_LIST: { struct scsi_vpd_supported_page_list *vpd_list; struct cam_ed *device; vpd_list = NULL; device = periph->path->device; if ((SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOVPDS) == 0) vpd_list = malloc(sizeof(*vpd_list), M_CAMXPT, M_NOWAIT | M_ZERO); if (vpd_list != NULL) { scsi_inquiry(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, (u_int8_t *)vpd_list, sizeof(*vpd_list), /*evpd*/TRUE, SVPD_SUPPORTED_PAGE_LIST, SSD_MIN_SIZE, /*timeout*/60 * 1000); break; } done: /* * We'll have to do without, let our probedone * routine finish up for us. */ start_ccb->csio.data_ptr = NULL; cam_freeze_devq(periph->path); cam_periph_doacquire(periph); probedone(periph, start_ccb); return; } case PROBE_DEVICE_ID: { struct scsi_vpd_device_id *devid; devid = NULL; if (scsi_vpd_supported_page(periph, SVPD_DEVICE_ID)) devid = malloc(SVPD_DEVICE_ID_MAX_SIZE, M_CAMXPT, M_NOWAIT | M_ZERO); if (devid != NULL) { scsi_inquiry(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, (uint8_t *)devid, SVPD_DEVICE_ID_MAX_SIZE, /*evpd*/TRUE, SVPD_DEVICE_ID, SSD_MIN_SIZE, /*timeout*/60 * 1000); break; } goto done; } case PROBE_SERIAL_NUM: { struct scsi_vpd_unit_serial_number *serial_buf; struct cam_ed* device; serial_buf = NULL; device = periph->path->device; if (device->serial_num != NULL) { free(device->serial_num, M_CAMXPT); device->serial_num = NULL; device->serial_num_len = 0; } if (scsi_vpd_supported_page(periph, SVPD_UNIT_SERIAL_NUMBER)) serial_buf = (struct scsi_vpd_unit_serial_number *) malloc(sizeof(*serial_buf), M_CAMXPT, M_NOWAIT|M_ZERO); if (serial_buf != NULL) { scsi_inquiry(csio, /*retries*/4, probedone, MSG_SIMPLE_Q_TAG, (u_int8_t *)serial_buf, sizeof(*serial_buf), /*evpd*/TRUE, SVPD_UNIT_SERIAL_NUMBER, SSD_MIN_SIZE, /*timeout*/60 * 1000); break; } goto done; } default: panic("probestart: invalid action state 0x%x\n", softc->action); } start_ccb->ccb_h.flags |= CAM_DEV_QFREEZE; cam_periph_doacquire(periph); xpt_action(start_ccb); } static void proberequestdefaultnegotiation(struct cam_periph *periph) { struct ccb_trans_settings cts; xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; cts.type = CTS_TYPE_USER_SETTINGS; xpt_action((union ccb *)&cts); if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) { return; } cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; xpt_action((union ccb *)&cts); } /* * Backoff Negotiation Code- only pertinent for SPI devices. */ static int proberequestbackoff(struct cam_periph *periph, struct cam_ed *device) { struct ccb_trans_settings cts; struct ccb_trans_settings_spi *spi; memset(&cts, 0, sizeof (cts)); xpt_setup_ccb(&cts.ccb_h, periph->path, CAM_PRIORITY_NONE); cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; xpt_action((union ccb *)&cts); if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) { if (bootverbose) { xpt_print(periph->path, "failed to get current device settings\n"); } return (0); } if (cts.transport != XPORT_SPI) { if (bootverbose) { xpt_print(periph->path, "not SPI transport\n"); } return (0); } spi = &cts.xport_specific.spi; /* * We cannot renegotiate sync rate if we don't have one. */ if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) { if (bootverbose) { xpt_print(periph->path, "no sync rate known\n"); } return (0); } /* * We'll assert that we don't have to touch PPR options- the * SIM will see what we do with period and offset and adjust * the PPR options as appropriate. */ /* * A sync rate with unknown or zero offset is nonsensical. * A sync period of zero means Async. */ if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0 || spi->sync_offset == 0 || spi->sync_period == 0) { if (bootverbose) { xpt_print(periph->path, "no sync rate available\n"); } return (0); } if (device->flags & CAM_DEV_DV_HIT_BOTTOM) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("hit async: giving up on DV\n")); return (0); } /* * Jump sync_period up by one, but stop at 5MHz and fall back to Async. * We don't try to remember 'last' settings to see if the SIM actually * gets into the speed we want to set. We check on the SIM telling * us that a requested speed is bad, but otherwise don't try and * check the speed due to the asynchronous and handshake nature * of speed setting. */ spi->valid = CTS_SPI_VALID_SYNC_RATE | CTS_SPI_VALID_SYNC_OFFSET; for (;;) { spi->sync_period++; if (spi->sync_period >= 0xf) { spi->sync_period = 0; spi->sync_offset = 0; CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("setting to async for DV\n")); /* * Once we hit async, we don't want to try * any more settings. */ device->flags |= CAM_DEV_DV_HIT_BOTTOM; } else if (bootverbose) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("DV: period 0x%x\n", spi->sync_period)); printf("setting period to 0x%x\n", spi->sync_period); } cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; xpt_action((union ccb *)&cts); if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) { break; } CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("DV: failed to set period 0x%x\n", spi->sync_period)); if (spi->sync_period == 0) { return (0); } } return (1); } #define CCB_COMPLETED_OK(ccb) (((ccb).status & CAM_STATUS_MASK) == CAM_REQ_CMP) static void probedone(struct cam_periph *periph, union ccb *done_ccb) { probe_softc *softc; struct cam_path *path; u_int32_t priority; CAM_DEBUG(done_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("probedone\n")); softc = (probe_softc *)periph->softc; path = done_ccb->ccb_h.path; priority = done_ccb->ccb_h.pinfo.priority; switch (softc->action) { case PROBE_TUR: { if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) { if (cam_periph_error(done_ccb, 0, SF_NO_PRINT, NULL) == ERESTART) { outr: /* Drop freeze taken due to CAM_DEV_QFREEZE */ cam_release_devq(path, 0, 0, 0, FALSE); return; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } PROBE_SET_ACTION(softc, PROBE_INQUIRY); xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); out: /* Drop freeze taken due to CAM_DEV_QFREEZE and release. */ cam_release_devq(path, 0, 0, 0, FALSE); cam_periph_release_locked(periph); return; } case PROBE_INQUIRY: case PROBE_FULL_INQUIRY: { if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { struct scsi_inquiry_data *inq_buf; u_int8_t periph_qual; path->device->flags |= CAM_DEV_INQUIRY_DATA_VALID; scsi_find_quirk(path->device); inq_buf = &path->device->inq_data; periph_qual = SID_QUAL(inq_buf); if (periph_qual == SID_QUAL_LU_CONNECTED) { u_int8_t len; /* * We conservatively request only * SHORT_INQUIRY_LEN bytes of inquiry * information during our first try * at sending an INQUIRY. If the device * has more information to give, * perform a second request specifying * the amount of information the device * is willing to give. */ len = inq_buf->additional_length + offsetof(struct scsi_inquiry_data, additional_length) + 1; if (softc->action == PROBE_INQUIRY && len > SHORT_INQUIRY_LENGTH) { PROBE_SET_ACTION(softc, PROBE_FULL_INQUIRY); xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } scsi_devise_transport(path); if (path->device->lun_id == 0 && SID_ANSI_REV(inq_buf) > SCSI_REV_SPC2 && (SCSI_QUIRK(path->device)->quirks & CAM_QUIRK_NORPTLUNS) == 0) { PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS); /* * Start with room for *one* lun. */ periph->path->target->rpl_size = 16; } else if (INQ_DATA_TQ_ENABLED(inq_buf)) PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); else PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); if (path->device->flags & CAM_DEV_UNCONFIGURED) { path->device->flags &= ~CAM_DEV_UNCONFIGURED; xpt_acquire_device(path->device); } xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } else if (path->device->lun_id == 0 && SID_ANSI_REV(inq_buf) >= SCSI_REV_SPC2 && (SCSI_QUIRK(path->device)->quirks & CAM_QUIRK_NORPTLUNS) == 0) { PROBE_SET_ACTION(softc, PROBE_REPORT_LUNS); periph->path->target->rpl_size = 16; xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } } else if (cam_periph_error(done_ccb, 0, done_ccb->ccb_h.target_lun > 0 ? SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA, &softc->saved_ccb) == ERESTART) { goto outr; } else { if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } path->device->flags &= ~CAM_DEV_INQUIRY_DATA_VALID; } /* * If we get to this point, we got an error status back * from the inquiry and the error status doesn't require * automatically retrying the command. Therefore, the * inquiry failed. If we had inquiry information before * for this device, but this latest inquiry command failed, * the device has probably gone away. If this device isn't * already marked unconfigured, notify the peripheral * drivers that this device is no more. */ if ((path->device->flags & CAM_DEV_UNCONFIGURED) == 0) /* Send the async notification. */ xpt_async(AC_LOST_DEVICE, path, NULL); PROBE_SET_ACTION(softc, PROBE_INVALID); xpt_release_ccb(done_ccb); break; } case PROBE_REPORT_LUNS: { struct ccb_scsiio *csio; struct scsi_report_luns_data *lp; u_int nlun, maxlun; csio = &done_ccb->csio; lp = (struct scsi_report_luns_data *)csio->data_ptr; nlun = scsi_4btoul(lp->length) / 8; maxlun = (csio->dxfer_len / 8) - 1; if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) { if (cam_periph_error(done_ccb, 0, done_ccb->ccb_h.target_lun > 0 ? SF_RETRY_UA|SF_QUIET_IR : SF_RETRY_UA, &softc->saved_ccb) == ERESTART) { goto outr; } if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { xpt_release_devq(done_ccb->ccb_h.path, 1, TRUE); } free(lp, M_CAMXPT); lp = NULL; } else if (nlun > maxlun) { /* * Reallocate and retry to cover all luns */ CAM_DEBUG(path, CAM_DEBUG_PROBE, ("Probe: reallocating REPORT_LUNS for %u luns\n", nlun)); free(lp, M_CAMXPT); path->target->rpl_size = (nlun << 3) + 8; xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } else if (nlun == 0) { /* * If there don't appear to be any luns, bail. */ free(lp, M_CAMXPT); lp = NULL; } else { lun_id_t lun; int idx; CAM_DEBUG(path, CAM_DEBUG_PROBE, ("Probe: %u lun(s) reported\n", nlun)); CAM_GET_LUN(lp, 0, lun); /* * If the first lun is not lun 0, then either there * is no lun 0 in the list, or the list is unsorted. */ if (lun != 0) { for (idx = 0; idx < nlun; idx++) { CAM_GET_LUN(lp, idx, lun); if (lun == 0) { break; } } if (idx != nlun) { uint8_t tlun[8]; memcpy(tlun, lp->luns[0].lundata, 8); memcpy(lp->luns[0].lundata, lp->luns[idx].lundata, 8); memcpy(lp->luns[idx].lundata, tlun, 8); CAM_DEBUG(path, CAM_DEBUG_PROBE, ("lun 0 in position %u\n", idx)); } } /* * If we have an old lun list, We can either * retest luns that appear to have been dropped, * or just nuke them. We'll opt for the latter. * This function will also install the new list * in the target structure. */ probe_purge_old(path, lp, softc->flags); lp = NULL; } if (path->device->flags & CAM_DEV_INQUIRY_DATA_VALID && SID_QUAL(&path->device->inq_data) == SID_QUAL_LU_CONNECTED) { struct scsi_inquiry_data *inq_buf; inq_buf = &path->device->inq_data; if (INQ_DATA_TQ_ENABLED(inq_buf)) PROBE_SET_ACTION(softc, PROBE_MODE_SENSE); else PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } if (lp) { free(lp, M_CAMXPT); } PROBE_SET_ACTION(softc, PROBE_INVALID); xpt_release_ccb(done_ccb); break; } case PROBE_MODE_SENSE: { struct ccb_scsiio *csio; struct scsi_mode_header_6 *mode_hdr; csio = &done_ccb->csio; mode_hdr = (struct scsi_mode_header_6 *)csio->data_ptr; if (cam_ccb_status(done_ccb) == CAM_REQ_CMP) { struct scsi_control_page *page; u_int8_t *offset; offset = ((u_int8_t *)&mode_hdr[1]) + mode_hdr->blk_desc_len; page = (struct scsi_control_page *)offset; path->device->queue_flags = page->queue_flags; } else if (cam_periph_error(done_ccb, 0, SF_RETRY_UA|SF_NO_PRINT, &softc->saved_ccb) == ERESTART) { goto outr; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } xpt_release_ccb(done_ccb); free(mode_hdr, M_CAMXPT); PROBE_SET_ACTION(softc, PROBE_SUPPORTED_VPD_LIST); xpt_schedule(periph, priority); goto out; } case PROBE_SUPPORTED_VPD_LIST: { struct ccb_scsiio *csio; struct scsi_vpd_supported_page_list *page_list; csio = &done_ccb->csio; page_list = (struct scsi_vpd_supported_page_list *)csio->data_ptr; if (path->device->supported_vpds != NULL) { free(path->device->supported_vpds, M_CAMXPT); path->device->supported_vpds = NULL; path->device->supported_vpds_len = 0; } if (page_list == NULL) { /* * Don't process the command as it was never sent */ } else if (CCB_COMPLETED_OK(csio->ccb_h)) { /* Got vpd list */ path->device->supported_vpds_len = page_list->length + SVPD_SUPPORTED_PAGES_HDR_LEN; path->device->supported_vpds = (uint8_t *)page_list; xpt_release_ccb(done_ccb); PROBE_SET_ACTION(softc, PROBE_DEVICE_ID); xpt_schedule(periph, priority); goto out; } else if (cam_periph_error(done_ccb, 0, SF_RETRY_UA|SF_NO_PRINT, &softc->saved_ccb) == ERESTART) { goto outr; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } if (page_list) free(page_list, M_CAMXPT); /* No VPDs available, skip to device check. */ csio->data_ptr = NULL; goto probe_device_check; } case PROBE_DEVICE_ID: { struct scsi_vpd_device_id *devid; struct ccb_scsiio *csio; uint32_t length = 0; csio = &done_ccb->csio; devid = (struct scsi_vpd_device_id *)csio->data_ptr; /* Clean up from previous instance of this device */ if (path->device->device_id != NULL) { path->device->device_id_len = 0; free(path->device->device_id, M_CAMXPT); path->device->device_id = NULL; } if (devid == NULL) { /* Don't process the command as it was never sent */ } else if (CCB_COMPLETED_OK(csio->ccb_h)) { length = scsi_2btoul(devid->length); if (length != 0) { /* * NB: device_id_len is actual response * size, not buffer size. */ path->device->device_id_len = length + SVPD_DEVICE_ID_HDR_LEN; path->device->device_id = (uint8_t *)devid; } } else if (cam_periph_error(done_ccb, 0, SF_RETRY_UA, &softc->saved_ccb) == ERESTART) { goto outr; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } /* Free the device id space if we don't use it */ if (devid && length == 0) free(devid, M_CAMXPT); xpt_release_ccb(done_ccb); PROBE_SET_ACTION(softc, PROBE_SERIAL_NUM); xpt_schedule(periph, priority); goto out; } probe_device_check: case PROBE_SERIAL_NUM: { struct ccb_scsiio *csio; struct scsi_vpd_unit_serial_number *serial_buf; u_int32_t priority; int changed; int have_serialnum; changed = 1; have_serialnum = 0; csio = &done_ccb->csio; priority = done_ccb->ccb_h.pinfo.priority; serial_buf = (struct scsi_vpd_unit_serial_number *)csio->data_ptr; if (serial_buf == NULL) { /* * Don't process the command as it was never sent */ } else if (cam_ccb_status(done_ccb) == CAM_REQ_CMP && (serial_buf->length > 0)) { have_serialnum = 1; path->device->serial_num = (u_int8_t *)malloc((serial_buf->length + 1), M_CAMXPT, M_NOWAIT); if (path->device->serial_num != NULL) { memcpy(path->device->serial_num, serial_buf->serial_num, serial_buf->length); path->device->serial_num_len = serial_buf->length; path->device->serial_num[serial_buf->length] = '\0'; } } else if (cam_periph_error(done_ccb, 0, SF_RETRY_UA|SF_NO_PRINT, &softc->saved_ccb) == ERESTART) { goto outr; } else if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } /* * Let's see if we have seen this device before. */ if ((softc->flags & PROBE_INQUIRY_CKSUM) != 0) { MD5_CTX context; u_int8_t digest[16]; MD5Init(&context); MD5Update(&context, (unsigned char *)&path->device->inq_data, sizeof(struct scsi_inquiry_data)); if (have_serialnum) MD5Update(&context, serial_buf->serial_num, serial_buf->length); MD5Final(digest, &context); if (bcmp(softc->digest, digest, 16) == 0) changed = 0; /* * XXX Do we need to do a TUR in order to ensure * that the device really hasn't changed??? */ if ((changed != 0) && ((softc->flags & PROBE_NO_ANNOUNCE) == 0)) xpt_async(AC_LOST_DEVICE, path, NULL); } if (serial_buf != NULL) free(serial_buf, M_CAMXPT); if (changed != 0) { /* * Now that we have all the necessary * information to safely perform transfer * negotiations... Controllers don't perform * any negotiation or tagged queuing until * after the first XPT_SET_TRAN_SETTINGS ccb is * received. So, on a new device, just retrieve * the user settings, and set them as the current * settings to set the device up. */ proberequestdefaultnegotiation(periph); xpt_release_ccb(done_ccb); /* * Perform a TUR to allow the controller to * perform any necessary transfer negotiation. */ PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); xpt_schedule(periph, priority); goto out; } xpt_release_ccb(done_ccb); break; } case PROBE_TUR_FOR_NEGOTIATION: case PROBE_DV_EXIT: if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) { cam_periph_error(done_ccb, 0, SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); } if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } /* * Do Domain Validation for lun 0 on devices that claim * to support Synchronous Transfer modes. */ if (softc->action == PROBE_TUR_FOR_NEGOTIATION && done_ccb->ccb_h.target_lun == 0 && (path->device->inq_data.flags & SID_Sync) != 0 && (path->device->flags & CAM_DEV_IN_DV) == 0) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Begin Domain Validation\n")); path->device->flags |= CAM_DEV_IN_DV; xpt_release_ccb(done_ccb); PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV1); xpt_schedule(periph, priority); goto out; } if (softc->action == PROBE_DV_EXIT) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Leave Domain Validation\n")); } if (path->device->flags & CAM_DEV_UNCONFIGURED) { path->device->flags &= ~CAM_DEV_UNCONFIGURED; xpt_acquire_device(path->device); } path->device->flags &= ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { /* Inform the XPT that a new device has been found */ done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; xpt_action(done_ccb); xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb); } PROBE_SET_ACTION(softc, PROBE_DONE); xpt_release_ccb(done_ccb); break; case PROBE_INQUIRY_BASIC_DV1: case PROBE_INQUIRY_BASIC_DV2: { struct scsi_inquiry_data *nbuf; struct ccb_scsiio *csio; if (cam_ccb_status(done_ccb) != CAM_REQ_CMP) { cam_periph_error(done_ccb, 0, SF_NO_PRINT | SF_NO_RECOVERY | SF_NO_RETRY, NULL); } if ((done_ccb->ccb_h.status & CAM_DEV_QFRZN) != 0) { /* Don't wedge the queue */ xpt_release_devq(done_ccb->ccb_h.path, /*count*/1, /*run_queue*/TRUE); } csio = &done_ccb->csio; nbuf = (struct scsi_inquiry_data *)csio->data_ptr; if (bcmp(nbuf, &path->device->inq_data, SHORT_INQUIRY_LENGTH)) { xpt_print(path, "inquiry data fails comparison at DV%d step\n", softc->action == PROBE_INQUIRY_BASIC_DV1 ? 1 : 2); if (proberequestbackoff(periph, path->device)) { path->device->flags &= ~CAM_DEV_IN_DV; PROBE_SET_ACTION(softc, PROBE_TUR_FOR_NEGOTIATION); } else { /* give up */ PROBE_SET_ACTION(softc, PROBE_DV_EXIT); } free(nbuf, M_CAMXPT); xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } free(nbuf, M_CAMXPT); if (softc->action == PROBE_INQUIRY_BASIC_DV1) { PROBE_SET_ACTION(softc, PROBE_INQUIRY_BASIC_DV2); xpt_release_ccb(done_ccb); xpt_schedule(periph, priority); goto out; } if (softc->action == PROBE_INQUIRY_BASIC_DV2) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Leave Domain Validation Successfully\n")); } if (path->device->flags & CAM_DEV_UNCONFIGURED) { path->device->flags &= ~CAM_DEV_UNCONFIGURED; xpt_acquire_device(path->device); } path->device->flags &= ~(CAM_DEV_IN_DV|CAM_DEV_DV_HIT_BOTTOM); if ((softc->flags & PROBE_NO_ANNOUNCE) == 0) { /* Inform the XPT that a new device has been found */ done_ccb->ccb_h.func_code = XPT_GDEV_TYPE; xpt_action(done_ccb); xpt_async(AC_FOUND_DEVICE, done_ccb->ccb_h.path, done_ccb); } PROBE_SET_ACTION(softc, PROBE_DONE); xpt_release_ccb(done_ccb); break; } default: panic("probedone: invalid action state 0x%x\n", softc->action); } done_ccb = (union ccb *)TAILQ_FIRST(&softc->request_ccbs); TAILQ_REMOVE(&softc->request_ccbs, &done_ccb->ccb_h, periph_links.tqe); done_ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(done_ccb); if (TAILQ_FIRST(&softc->request_ccbs) == NULL) { CAM_DEBUG(periph->path, CAM_DEBUG_PROBE, ("Probe completed\n")); /* Drop freeze taken due to CAM_DEV_QFREEZE flag set. */ cam_release_devq(path, 0, 0, 0, FALSE); cam_periph_release_locked(periph); cam_periph_invalidate(periph); cam_periph_release_locked(periph); } else { probeschedule(periph); goto out; } } static void probe_purge_old(struct cam_path *path, struct scsi_report_luns_data *new, probe_flags flags) { struct cam_path *tp; struct scsi_report_luns_data *old; u_int idx1, idx2, nlun_old, nlun_new; lun_id_t this_lun; u_int8_t *ol, *nl; if (path->target == NULL) { return; } mtx_lock(&path->target->luns_mtx); old = path->target->luns; path->target->luns = new; mtx_unlock(&path->target->luns_mtx); if (old == NULL) return; nlun_old = scsi_4btoul(old->length) / 8; nlun_new = scsi_4btoul(new->length) / 8; /* * We are not going to assume sorted lists. Deal. */ for (idx1 = 0; idx1 < nlun_old; idx1++) { ol = old->luns[idx1].lundata; for (idx2 = 0; idx2 < nlun_new; idx2++) { nl = new->luns[idx2].lundata; if (memcmp(nl, ol, 8) == 0) { break; } } if (idx2 < nlun_new) { continue; } /* * An 'old' item not in the 'new' list. * Nuke it. Except that if it is lun 0, * that would be what the probe state * machine is currently working on, * so we won't do that. */ CAM_GET_LUN(old, idx1, this_lun); if (this_lun == 0) { continue; } /* * We also cannot nuke it if it is * not in a lun format we understand * and replace the LUN with a "simple" LUN * if that is all the HBA supports. */ if (!(flags & PROBE_EXTLUN)) { if (!CAM_CAN_GET_SIMPLE_LUN(old, idx1)) continue; CAM_GET_SIMPLE_LUN(old, idx1, this_lun); } if (xpt_create_path(&tp, NULL, xpt_path_path_id(path), xpt_path_target_id(path), this_lun) == CAM_REQ_CMP) { xpt_async(AC_LOST_DEVICE, tp, NULL); xpt_free_path(tp); } } free(old, M_CAMXPT); } static void probecleanup(struct cam_periph *periph) { free(periph->softc, M_CAMXPT); } static void scsi_find_quirk(struct cam_ed *device) { struct scsi_quirk_entry *quirk; caddr_t match; match = cam_quirkmatch((caddr_t)&device->inq_data, (caddr_t)scsi_quirk_table, sizeof(scsi_quirk_table) / sizeof(*scsi_quirk_table), sizeof(*scsi_quirk_table), scsi_inquiry_match); if (match == NULL) panic("xpt_find_quirk: device didn't match wildcard entry!!"); quirk = (struct scsi_quirk_entry *)match; device->quirk = quirk; device->mintags = quirk->mintags; device->maxtags = quirk->maxtags; } static int sysctl_cam_search_luns(SYSCTL_HANDLER_ARGS) { int error, val; val = cam_srch_hi; error = sysctl_handle_int(oidp, &val, 0, req); if (error != 0 || req->newptr == NULL) return (error); if (val == 0 || val == 1) { cam_srch_hi = val; return (0); } else { return (EINVAL); } } typedef struct { union ccb *request_ccb; struct ccb_pathinq *cpi; int counter; int lunindex[0]; } scsi_scan_bus_info; /* * To start a scan, request_ccb is an XPT_SCAN_BUS ccb. * As the scan progresses, scsi_scan_bus is used as the * callback on completion function. */ static void scsi_scan_bus(struct cam_periph *periph, union ccb *request_ccb) { struct mtx *mtx; CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("scsi_scan_bus\n")); switch (request_ccb->ccb_h.func_code) { case XPT_SCAN_BUS: case XPT_SCAN_TGT: { scsi_scan_bus_info *scan_info; union ccb *work_ccb, *reset_ccb; struct cam_path *path; u_int i; u_int low_target, max_target; u_int initiator_id; /* Find out the characteristics of the bus */ work_ccb = xpt_alloc_ccb_nowait(); if (work_ccb == NULL) { request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_done(request_ccb); return; } xpt_setup_ccb(&work_ccb->ccb_h, request_ccb->ccb_h.path, request_ccb->ccb_h.pinfo.priority); work_ccb->ccb_h.func_code = XPT_PATH_INQ; xpt_action(work_ccb); if (work_ccb->ccb_h.status != CAM_REQ_CMP) { request_ccb->ccb_h.status = work_ccb->ccb_h.status; xpt_free_ccb(work_ccb); xpt_done(request_ccb); return; } if ((work_ccb->cpi.hba_misc & PIM_NOINITIATOR) != 0) { /* * Can't scan the bus on an adapter that * cannot perform the initiator role. */ request_ccb->ccb_h.status = CAM_REQ_CMP; xpt_free_ccb(work_ccb); xpt_done(request_ccb); return; } /* We may need to reset bus first, if we haven't done it yet. */ if ((work_ccb->cpi.hba_inquiry & (PI_WIDE_32|PI_WIDE_16|PI_SDTR_ABLE)) && !(work_ccb->cpi.hba_misc & PIM_NOBUSRESET) && !timevalisset(&request_ccb->ccb_h.path->bus->last_reset) && (reset_ccb = xpt_alloc_ccb_nowait()) != NULL) { xpt_setup_ccb(&reset_ccb->ccb_h, request_ccb->ccb_h.path, CAM_PRIORITY_NONE); reset_ccb->ccb_h.func_code = XPT_RESET_BUS; xpt_action(reset_ccb); if (reset_ccb->ccb_h.status != CAM_REQ_CMP) { request_ccb->ccb_h.status = reset_ccb->ccb_h.status; xpt_free_ccb(reset_ccb); xpt_free_ccb(work_ccb); xpt_done(request_ccb); return; } xpt_free_ccb(reset_ccb); } /* Save some state for use while we probe for devices */ scan_info = (scsi_scan_bus_info *) malloc(sizeof(scsi_scan_bus_info) + (work_ccb->cpi.max_target * sizeof (u_int)), M_CAMXPT, M_ZERO|M_NOWAIT); if (scan_info == NULL) { request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_free_ccb(work_ccb); xpt_done(request_ccb); return; } CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("SCAN start for %p\n", scan_info)); scan_info->request_ccb = request_ccb; scan_info->cpi = &work_ccb->cpi; /* Cache on our stack so we can work asynchronously */ max_target = scan_info->cpi->max_target; low_target = 0; initiator_id = scan_info->cpi->initiator_id; /* * We can scan all targets in parallel, or do it sequentially. */ if (request_ccb->ccb_h.func_code == XPT_SCAN_TGT) { max_target = low_target = request_ccb->ccb_h.target_id; scan_info->counter = 0; } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) { max_target = 0; scan_info->counter = 0; } else { scan_info->counter = scan_info->cpi->max_target + 1; if (scan_info->cpi->initiator_id < scan_info->counter) { scan_info->counter--; } } mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path); mtx_unlock(mtx); for (i = low_target; i <= max_target; i++) { cam_status status; if (i == initiator_id) continue; status = xpt_create_path(&path, NULL, request_ccb->ccb_h.path_id, i, 0); if (status != CAM_REQ_CMP) { printf("scsi_scan_bus: xpt_create_path failed" " with status %#x, bus scan halted\n", status); free(scan_info, M_CAMXPT); request_ccb->ccb_h.status = status; xpt_free_ccb(work_ccb); xpt_done(request_ccb); break; } work_ccb = xpt_alloc_ccb_nowait(); if (work_ccb == NULL) { xpt_free_ccb((union ccb *)scan_info->cpi); free(scan_info, M_CAMXPT); xpt_free_path(path); request_ccb->ccb_h.status = CAM_RESRC_UNAVAIL; xpt_done(request_ccb); break; } xpt_setup_ccb(&work_ccb->ccb_h, path, request_ccb->ccb_h.pinfo.priority); work_ccb->ccb_h.func_code = XPT_SCAN_LUN; work_ccb->ccb_h.cbfcnp = scsi_scan_bus; work_ccb->ccb_h.flags |= CAM_UNLOCKED; work_ccb->ccb_h.ppriv_ptr0 = scan_info; work_ccb->crcn.flags = request_ccb->crcn.flags; xpt_action(work_ccb); } mtx_lock(mtx); break; } case XPT_SCAN_LUN: { cam_status status; struct cam_path *path, *oldpath; scsi_scan_bus_info *scan_info; struct cam_et *target; struct cam_ed *device, *nextdev; int next_target; path_id_t path_id; target_id_t target_id; lun_id_t lun_id; oldpath = request_ccb->ccb_h.path; status = cam_ccb_status(request_ccb); scan_info = (scsi_scan_bus_info *)request_ccb->ccb_h.ppriv_ptr0; path_id = request_ccb->ccb_h.path_id; target_id = request_ccb->ccb_h.target_id; lun_id = request_ccb->ccb_h.target_lun; target = request_ccb->ccb_h.path->target; next_target = 1; mtx = xpt_path_mtx(scan_info->request_ccb->ccb_h.path); mtx_lock(mtx); mtx_lock(&target->luns_mtx); if (target->luns) { lun_id_t first; u_int nluns = scsi_4btoul(target->luns->length) / 8; /* * Make sure we skip over lun 0 if it's the first member * of the list as we've actually just finished probing * it. */ CAM_GET_LUN(target->luns, 0, first); if (first == 0 && scan_info->lunindex[target_id] == 0) { scan_info->lunindex[target_id]++; } /* * Skip any LUNs that the HBA can't deal with. */ while (scan_info->lunindex[target_id] < nluns) { if (scan_info->cpi->hba_misc & PIM_EXTLUNS) { CAM_GET_LUN(target->luns, scan_info->lunindex[target_id], lun_id); break; } if (CAM_CAN_GET_SIMPLE_LUN(target->luns, scan_info->lunindex[target_id])) { CAM_GET_SIMPLE_LUN(target->luns, scan_info->lunindex[target_id], lun_id); break; } scan_info->lunindex[target_id]++; } if (scan_info->lunindex[target_id] < nluns) { mtx_unlock(&target->luns_mtx); next_target = 0; CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_PROBE, ("next lun to try at index %u is %jx\n", scan_info->lunindex[target_id], (uintmax_t)lun_id)); scan_info->lunindex[target_id]++; } else { mtx_unlock(&target->luns_mtx); - /* - * We're done with scanning all luns. - * - * Nuke the bogus device for lun 0 if lun 0 - * wasn't on the list. - */ - if (first != 0) { - TAILQ_FOREACH(device, - &target->ed_entries, links) { - if (device->lun_id == 0) { - break; - } - } - if (device) { - xpt_release_device(device); - } - } + /* We're done with scanning all luns. */ } } else { mtx_unlock(&target->luns_mtx); device = request_ccb->ccb_h.path->device; /* Continue sequential LUN scan if: */ /* -- we have more LUNs that need recheck */ mtx_lock(&target->bus->eb_mtx); nextdev = device; while ((nextdev = TAILQ_NEXT(nextdev, links)) != NULL) if ((nextdev->flags & CAM_DEV_UNCONFIGURED) == 0) break; mtx_unlock(&target->bus->eb_mtx); if (nextdev != NULL) { next_target = 0; /* -- stop if CAM_QUIRK_NOLUNS is set. */ } else if (SCSI_QUIRK(device)->quirks & CAM_QUIRK_NOLUNS) { next_target = 1; /* -- this LUN is connected and its SCSI version * allows more LUNs. */ } else if ((device->flags & CAM_DEV_UNCONFIGURED) == 0) { if (lun_id < (CAM_SCSI2_MAXLUN-1) || CAN_SRCH_HI_DENSE(device)) next_target = 0; /* -- this LUN is disconnected, its SCSI version * allows more LUNs and we guess they may be. */ } else if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) { if (lun_id < (CAM_SCSI2_MAXLUN-1) || CAN_SRCH_HI_SPARSE(device)) next_target = 0; } if (next_target == 0) { lun_id++; if (lun_id > scan_info->cpi->max_lun) next_target = 1; } } /* * Check to see if we scan any further luns. */ if (next_target) { int done; /* * Free the current request path- we're done with it. */ xpt_free_path(oldpath); hop_again: done = 0; if (scan_info->request_ccb->ccb_h.func_code == XPT_SCAN_TGT) { done = 1; } else if (scan_info->cpi->hba_misc & PIM_SEQSCAN) { scan_info->counter++; if (scan_info->counter == scan_info->cpi->initiator_id) { scan_info->counter++; } if (scan_info->counter >= scan_info->cpi->max_target+1) { done = 1; } } else { scan_info->counter--; if (scan_info->counter == 0) { done = 1; } } if (done) { mtx_unlock(mtx); xpt_free_ccb(request_ccb); xpt_free_ccb((union ccb *)scan_info->cpi); request_ccb = scan_info->request_ccb; CAM_DEBUG(request_ccb->ccb_h.path, CAM_DEBUG_TRACE, ("SCAN done for %p\n", scan_info)); free(scan_info, M_CAMXPT); request_ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(request_ccb); break; } if ((scan_info->cpi->hba_misc & PIM_SEQSCAN) == 0) { mtx_unlock(mtx); xpt_free_ccb(request_ccb); break; } status = xpt_create_path(&path, NULL, scan_info->request_ccb->ccb_h.path_id, scan_info->counter, 0); if (status != CAM_REQ_CMP) { mtx_unlock(mtx); printf("scsi_scan_bus: xpt_create_path failed" " with status %#x, bus scan halted\n", status); xpt_free_ccb(request_ccb); xpt_free_ccb((union ccb *)scan_info->cpi); request_ccb = scan_info->request_ccb; free(scan_info, M_CAMXPT); request_ccb->ccb_h.status = status; xpt_done(request_ccb); break; } xpt_setup_ccb(&request_ccb->ccb_h, path, request_ccb->ccb_h.pinfo.priority); request_ccb->ccb_h.func_code = XPT_SCAN_LUN; request_ccb->ccb_h.cbfcnp = scsi_scan_bus; request_ccb->ccb_h.flags |= CAM_UNLOCKED; request_ccb->ccb_h.ppriv_ptr0 = scan_info; request_ccb->crcn.flags = scan_info->request_ccb->crcn.flags; } else { status = xpt_create_path(&path, NULL, path_id, target_id, lun_id); /* * Free the old request path- we're done with it. We * do this *after* creating the new path so that * we don't remove a target that has our lun list * in the case that lun 0 is not present. */ xpt_free_path(oldpath); if (status != CAM_REQ_CMP) { printf("scsi_scan_bus: xpt_create_path failed " "with status %#x, halting LUN scan\n", status); goto hop_again; } xpt_setup_ccb(&request_ccb->ccb_h, path, request_ccb->ccb_h.pinfo.priority); request_ccb->ccb_h.func_code = XPT_SCAN_LUN; request_ccb->ccb_h.cbfcnp = scsi_scan_bus; request_ccb->ccb_h.flags |= CAM_UNLOCKED; request_ccb->ccb_h.ppriv_ptr0 = scan_info; request_ccb->crcn.flags = scan_info->request_ccb->crcn.flags; } mtx_unlock(mtx); xpt_action(request_ccb); break; } default: break; } } static void scsi_scan_lun(struct cam_periph *periph, struct cam_path *path, cam_flags flags, union ccb *request_ccb) { struct ccb_pathinq cpi; cam_status status; struct cam_path *new_path; struct cam_periph *old_periph; int lock; CAM_DEBUG(path, CAM_DEBUG_TRACE, ("scsi_scan_lun\n")); xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); if (cpi.ccb_h.status != CAM_REQ_CMP) { if (request_ccb != NULL) { request_ccb->ccb_h.status = cpi.ccb_h.status; xpt_done(request_ccb); } return; } if ((cpi.hba_misc & PIM_NOINITIATOR) != 0) { /* * Can't scan the bus on an adapter that * cannot perform the initiator role. */ if (request_ccb != NULL) { request_ccb->ccb_h.status = CAM_REQ_CMP; xpt_done(request_ccb); } return; } if (request_ccb == NULL) { request_ccb = xpt_alloc_ccb_nowait(); if (request_ccb == NULL) { xpt_print(path, "scsi_scan_lun: can't allocate CCB, " "can't continue\n"); return; } status = xpt_create_path(&new_path, NULL, path->bus->path_id, path->target->target_id, path->device->lun_id); if (status != CAM_REQ_CMP) { xpt_print(path, "scsi_scan_lun: can't create path, " "can't continue\n"); xpt_free_ccb(request_ccb); return; } xpt_setup_ccb(&request_ccb->ccb_h, new_path, CAM_PRIORITY_XPT); request_ccb->ccb_h.cbfcnp = xptscandone; request_ccb->ccb_h.func_code = XPT_SCAN_LUN; request_ccb->ccb_h.flags |= CAM_UNLOCKED; request_ccb->crcn.flags = flags; } lock = (xpt_path_owned(path) == 0); if (lock) xpt_path_lock(path); if ((old_periph = cam_periph_find(path, "probe")) != NULL) { if ((old_periph->flags & CAM_PERIPH_INVALID) == 0) { probe_softc *softc; softc = (probe_softc *)old_periph->softc; TAILQ_INSERT_TAIL(&softc->request_ccbs, &request_ccb->ccb_h, periph_links.tqe); } else { request_ccb->ccb_h.status = CAM_REQ_CMP_ERR; xpt_done(request_ccb); } } else { status = cam_periph_alloc(proberegister, NULL, probecleanup, probestart, "probe", CAM_PERIPH_BIO, request_ccb->ccb_h.path, NULL, 0, request_ccb); if (status != CAM_REQ_CMP) { xpt_print(path, "scsi_scan_lun: cam_alloc_periph " "returned an error, can't continue probe\n"); request_ccb->ccb_h.status = status; xpt_done(request_ccb); } } if (lock) xpt_path_unlock(path); } static void xptscandone(struct cam_periph *periph, union ccb *done_ccb) { xpt_free_path(done_ccb->ccb_h.path); xpt_free_ccb(done_ccb); } static struct cam_ed * scsi_alloc_device(struct cam_eb *bus, struct cam_et *target, lun_id_t lun_id) { struct scsi_quirk_entry *quirk; struct cam_ed *device; device = xpt_alloc_device(bus, target, lun_id); if (device == NULL) return (NULL); /* * Take the default quirk entry until we have inquiry * data and can determine a better quirk to use. */ quirk = &scsi_quirk_table[scsi_quirk_table_size - 1]; device->quirk = (void *)quirk; device->mintags = quirk->mintags; device->maxtags = quirk->maxtags; bzero(&device->inq_data, sizeof(device->inq_data)); device->inq_flags = 0; device->queue_flags = 0; device->serial_num = NULL; device->serial_num_len = 0; device->device_id = NULL; device->device_id_len = 0; device->supported_vpds = NULL; device->supported_vpds_len = 0; return (device); } static void scsi_devise_transport(struct cam_path *path) { struct ccb_pathinq cpi; struct ccb_trans_settings cts; struct scsi_inquiry_data *inq_buf; /* Get transport information from the SIM */ xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); inq_buf = NULL; if ((path->device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0) inq_buf = &path->device->inq_data; path->device->protocol = PROTO_SCSI; path->device->protocol_version = inq_buf != NULL ? SID_ANSI_REV(inq_buf) : cpi.protocol_version; path->device->transport = cpi.transport; path->device->transport_version = cpi.transport_version; /* * Any device not using SPI3 features should * be considered SPI2 or lower. */ if (inq_buf != NULL) { if (path->device->transport == XPORT_SPI && (inq_buf->spi3data & SID_SPI_MASK) == 0 && path->device->transport_version > 2) path->device->transport_version = 2; } else { struct cam_ed* otherdev; for (otherdev = TAILQ_FIRST(&path->target->ed_entries); otherdev != NULL; otherdev = TAILQ_NEXT(otherdev, links)) { if (otherdev != path->device) break; } if (otherdev != NULL) { /* * Initially assume the same versioning as * prior luns for this target. */ path->device->protocol_version = otherdev->protocol_version; path->device->transport_version = otherdev->transport_version; } else { /* Until we know better, opt for safty */ path->device->protocol_version = 2; if (path->device->transport == XPORT_SPI) path->device->transport_version = 2; else path->device->transport_version = 0; } } /* * XXX * For a device compliant with SPC-2 we should be able * to determine the transport version supported by * scrutinizing the version descriptors in the * inquiry buffer. */ /* Tell the controller what we think */ xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE); cts.ccb_h.func_code = XPT_SET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; cts.transport = path->device->transport; cts.transport_version = path->device->transport_version; cts.protocol = path->device->protocol; cts.protocol_version = path->device->protocol_version; cts.proto_specific.valid = 0; cts.xport_specific.valid = 0; xpt_action((union ccb *)&cts); } static void scsi_dev_advinfo(union ccb *start_ccb) { struct cam_ed *device; struct ccb_dev_advinfo *cdai; off_t amt; start_ccb->ccb_h.status = CAM_REQ_INVALID; device = start_ccb->ccb_h.path->device; cdai = &start_ccb->cdai; switch(cdai->buftype) { case CDAI_TYPE_SCSI_DEVID: if (cdai->flags & CDAI_FLAG_STORE) return; cdai->provsiz = device->device_id_len; if (device->device_id_len == 0) break; amt = device->device_id_len; if (cdai->provsiz > cdai->bufsiz) amt = cdai->bufsiz; memcpy(cdai->buf, device->device_id, amt); break; case CDAI_TYPE_SERIAL_NUM: if (cdai->flags & CDAI_FLAG_STORE) return; cdai->provsiz = device->serial_num_len; if (device->serial_num_len == 0) break; amt = device->serial_num_len; if (cdai->provsiz > cdai->bufsiz) amt = cdai->bufsiz; memcpy(cdai->buf, device->serial_num, amt); break; case CDAI_TYPE_PHYS_PATH: if (cdai->flags & CDAI_FLAG_STORE) { if (device->physpath != NULL) { free(device->physpath, M_CAMXPT); device->physpath = NULL; } device->physpath_len = cdai->bufsiz; /* Clear existing buffer if zero length */ if (cdai->bufsiz == 0) break; device->physpath = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT); if (device->physpath == NULL) { start_ccb->ccb_h.status = CAM_REQ_ABORTED; return; } memcpy(device->physpath, cdai->buf, cdai->bufsiz); } else { cdai->provsiz = device->physpath_len; if (device->physpath_len == 0) break; amt = device->physpath_len; if (cdai->provsiz > cdai->bufsiz) amt = cdai->bufsiz; memcpy(cdai->buf, device->physpath, amt); } break; case CDAI_TYPE_RCAPLONG: if (cdai->flags & CDAI_FLAG_STORE) { if (device->rcap_buf != NULL) { free(device->rcap_buf, M_CAMXPT); device->rcap_buf = NULL; } device->rcap_len = cdai->bufsiz; /* Clear existing buffer if zero length */ if (cdai->bufsiz == 0) break; device->rcap_buf = malloc(cdai->bufsiz, M_CAMXPT, M_NOWAIT); if (device->rcap_buf == NULL) { start_ccb->ccb_h.status = CAM_REQ_ABORTED; return; } memcpy(device->rcap_buf, cdai->buf, cdai->bufsiz); } else { cdai->provsiz = device->rcap_len; if (device->rcap_len == 0) break; amt = device->rcap_len; if (cdai->provsiz > cdai->bufsiz) amt = cdai->bufsiz; memcpy(cdai->buf, device->rcap_buf, amt); } break; default: return; } start_ccb->ccb_h.status = CAM_REQ_CMP; if (cdai->flags & CDAI_FLAG_STORE) { xpt_async(AC_ADVINFO_CHANGED, start_ccb->ccb_h.path, (void *)(uintptr_t)cdai->buftype); } } static void scsi_action(union ccb *start_ccb) { switch (start_ccb->ccb_h.func_code) { case XPT_SET_TRAN_SETTINGS: { scsi_set_transfer_settings(&start_ccb->cts, start_ccb->ccb_h.path, /*async_update*/FALSE); break; } case XPT_SCAN_BUS: case XPT_SCAN_TGT: scsi_scan_bus(start_ccb->ccb_h.path->periph, start_ccb); break; case XPT_SCAN_LUN: scsi_scan_lun(start_ccb->ccb_h.path->periph, start_ccb->ccb_h.path, start_ccb->crcn.flags, start_ccb); break; case XPT_DEV_ADVINFO: { scsi_dev_advinfo(start_ccb); break; } default: xpt_action_default(start_ccb); break; } } static void scsi_set_transfer_settings(struct ccb_trans_settings *cts, struct cam_path *path, int async_update) { struct ccb_pathinq cpi; struct ccb_trans_settings cur_cts; struct ccb_trans_settings_scsi *scsi; struct ccb_trans_settings_scsi *cur_scsi; struct scsi_inquiry_data *inq_data; struct cam_ed *device; if (path == NULL || (device = path->device) == NULL) { cts->ccb_h.status = CAM_PATH_INVALID; xpt_done((union ccb *)cts); return; } if (cts->protocol == PROTO_UNKNOWN || cts->protocol == PROTO_UNSPECIFIED) { cts->protocol = device->protocol; cts->protocol_version = device->protocol_version; } if (cts->protocol_version == PROTO_VERSION_UNKNOWN || cts->protocol_version == PROTO_VERSION_UNSPECIFIED) cts->protocol_version = device->protocol_version; if (cts->protocol != device->protocol) { xpt_print(path, "Uninitialized Protocol %x:%x?\n", cts->protocol, device->protocol); cts->protocol = device->protocol; } if (cts->protocol_version > device->protocol_version) { if (bootverbose) { xpt_print(path, "Down reving Protocol " "Version from %d to %d?\n", cts->protocol_version, device->protocol_version); } cts->protocol_version = device->protocol_version; } if (cts->transport == XPORT_UNKNOWN || cts->transport == XPORT_UNSPECIFIED) { cts->transport = device->transport; cts->transport_version = device->transport_version; } if (cts->transport_version == XPORT_VERSION_UNKNOWN || cts->transport_version == XPORT_VERSION_UNSPECIFIED) cts->transport_version = device->transport_version; if (cts->transport != device->transport) { xpt_print(path, "Uninitialized Transport %x:%x?\n", cts->transport, device->transport); cts->transport = device->transport; } if (cts->transport_version > device->transport_version) { if (bootverbose) { xpt_print(path, "Down reving Transport " "Version from %d to %d?\n", cts->transport_version, device->transport_version); } cts->transport_version = device->transport_version; } /* * Nothing more of interest to do unless * this is a device connected via the * SCSI protocol. */ if (cts->protocol != PROTO_SCSI) { if (async_update == FALSE) xpt_action_default((union ccb *)cts); return; } inq_data = &device->inq_data; scsi = &cts->proto_specific.scsi; xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NONE); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); /* SCSI specific sanity checking */ if ((cpi.hba_inquiry & PI_TAG_ABLE) == 0 || (INQ_DATA_TQ_ENABLED(inq_data)) == 0 || (device->queue_flags & SCP_QUEUE_DQUE) != 0 || (device->mintags == 0)) { /* * Can't tag on hardware that doesn't support tags, * doesn't have it enabled, or has broken tag support. */ scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; } if (async_update == FALSE) { /* * Perform sanity checking against what the * controller and device can do. */ xpt_setup_ccb(&cur_cts.ccb_h, path, CAM_PRIORITY_NONE); cur_cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; cur_cts.type = cts->type; xpt_action((union ccb *)&cur_cts); if (cam_ccb_status((union ccb *)&cur_cts) != CAM_REQ_CMP) { return; } cur_scsi = &cur_cts.proto_specific.scsi; if ((scsi->valid & CTS_SCSI_VALID_TQ) == 0) { scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; scsi->flags |= cur_scsi->flags & CTS_SCSI_FLAGS_TAG_ENB; } if ((cur_scsi->valid & CTS_SCSI_VALID_TQ) == 0) scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; } /* SPI specific sanity checking */ if (cts->transport == XPORT_SPI && async_update == FALSE) { u_int spi3caps; struct ccb_trans_settings_spi *spi; struct ccb_trans_settings_spi *cur_spi; spi = &cts->xport_specific.spi; cur_spi = &cur_cts.xport_specific.spi; /* Fill in any gaps in what the user gave us */ if ((spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) spi->sync_period = cur_spi->sync_period; if ((cur_spi->valid & CTS_SPI_VALID_SYNC_RATE) == 0) spi->sync_period = 0; if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0) spi->sync_offset = cur_spi->sync_offset; if ((cur_spi->valid & CTS_SPI_VALID_SYNC_OFFSET) == 0) spi->sync_offset = 0; if ((spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0) spi->ppr_options = cur_spi->ppr_options; if ((cur_spi->valid & CTS_SPI_VALID_PPR_OPTIONS) == 0) spi->ppr_options = 0; if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0) spi->bus_width = cur_spi->bus_width; if ((cur_spi->valid & CTS_SPI_VALID_BUS_WIDTH) == 0) spi->bus_width = 0; if ((spi->valid & CTS_SPI_VALID_DISC) == 0) { spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB; spi->flags |= cur_spi->flags & CTS_SPI_FLAGS_DISC_ENB; } if ((cur_spi->valid & CTS_SPI_VALID_DISC) == 0) spi->flags &= ~CTS_SPI_FLAGS_DISC_ENB; if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0 && (inq_data->flags & SID_Sync) == 0 && cts->type == CTS_TYPE_CURRENT_SETTINGS) || ((cpi.hba_inquiry & PI_SDTR_ABLE) == 0)) { /* Force async */ spi->sync_period = 0; spi->sync_offset = 0; } switch (spi->bus_width) { case MSG_EXT_WDTR_BUS_32_BIT: if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0 || (inq_data->flags & SID_WBus32) != 0 || cts->type == CTS_TYPE_USER_SETTINGS) && (cpi.hba_inquiry & PI_WIDE_32) != 0) break; /* Fall Through to 16-bit */ case MSG_EXT_WDTR_BUS_16_BIT: if (((device->flags & CAM_DEV_INQUIRY_DATA_VALID) == 0 || (inq_data->flags & SID_WBus16) != 0 || cts->type == CTS_TYPE_USER_SETTINGS) && (cpi.hba_inquiry & PI_WIDE_16) != 0) { spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT; break; } /* Fall Through to 8-bit */ default: /* New bus width?? */ case MSG_EXT_WDTR_BUS_8_BIT: /* All targets can do this */ spi->bus_width = MSG_EXT_WDTR_BUS_8_BIT; break; } spi3caps = cpi.xport_specific.spi.ppr_options; if ((device->flags & CAM_DEV_INQUIRY_DATA_VALID) != 0 && cts->type == CTS_TYPE_CURRENT_SETTINGS) spi3caps &= inq_data->spi3data; if ((spi3caps & SID_SPI_CLOCK_DT) == 0) spi->ppr_options &= ~MSG_EXT_PPR_DT_REQ; if ((spi3caps & SID_SPI_IUS) == 0) spi->ppr_options &= ~MSG_EXT_PPR_IU_REQ; if ((spi3caps & SID_SPI_QAS) == 0) spi->ppr_options &= ~MSG_EXT_PPR_QAS_REQ; /* No SPI Transfer settings are allowed unless we are wide */ if (spi->bus_width == 0) spi->ppr_options = 0; if ((spi->valid & CTS_SPI_VALID_DISC) && ((spi->flags & CTS_SPI_FLAGS_DISC_ENB) == 0)) { /* * Can't tag queue without disconnection. */ scsi->flags &= ~CTS_SCSI_FLAGS_TAG_ENB; scsi->valid |= CTS_SCSI_VALID_TQ; } /* * If we are currently performing tagged transactions to * this device and want to change its negotiation parameters, * go non-tagged for a bit to give the controller a chance to * negotiate unhampered by tag messages. */ if (cts->type == CTS_TYPE_CURRENT_SETTINGS && (device->inq_flags & SID_CmdQue) != 0 && (scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0 && (spi->flags & (CTS_SPI_VALID_SYNC_RATE| CTS_SPI_VALID_SYNC_OFFSET| CTS_SPI_VALID_BUS_WIDTH)) != 0) scsi_toggle_tags(path); } if (cts->type == CTS_TYPE_CURRENT_SETTINGS && (scsi->valid & CTS_SCSI_VALID_TQ) != 0) { int device_tagenb; /* * If we are transitioning from tags to no-tags or * vice-versa, we need to carefully freeze and restart * the queue so that we don't overlap tagged and non-tagged * commands. We also temporarily stop tags if there is * a change in transfer negotiation settings to allow * "tag-less" negotiation. */ if ((device->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 || (device->inq_flags & SID_CmdQue) != 0) device_tagenb = TRUE; else device_tagenb = FALSE; if (((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0 && device_tagenb == FALSE) || ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) == 0 && device_tagenb == TRUE)) { if ((scsi->flags & CTS_SCSI_FLAGS_TAG_ENB) != 0) { /* * Delay change to use tags until after a * few commands have gone to this device so * the controller has time to perform transfer * negotiations without tagged messages getting * in the way. */ device->tag_delay_count = CAM_TAG_DELAY_COUNT; device->flags |= CAM_DEV_TAG_AFTER_COUNT; } else { xpt_stop_tags(path); } } } if (async_update == FALSE) xpt_action_default((union ccb *)cts); } static void scsi_toggle_tags(struct cam_path *path) { struct cam_ed *dev; /* * Give controllers a chance to renegotiate * before starting tag operations. We * "toggle" tagged queuing off then on * which causes the tag enable command delay * counter to come into effect. */ dev = path->device; if ((dev->flags & CAM_DEV_TAG_AFTER_COUNT) != 0 || ((dev->inq_flags & SID_CmdQue) != 0 && (dev->inq_flags & (SID_Sync|SID_WBus16|SID_WBus32)) != 0)) { struct ccb_trans_settings cts; xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NONE); cts.protocol = PROTO_SCSI; cts.protocol_version = PROTO_VERSION_UNSPECIFIED; cts.transport = XPORT_UNSPECIFIED; cts.transport_version = XPORT_VERSION_UNSPECIFIED; cts.proto_specific.scsi.flags = 0; cts.proto_specific.scsi.valid = CTS_SCSI_VALID_TQ; scsi_set_transfer_settings(&cts, path, /*async_update*/TRUE); cts.proto_specific.scsi.flags = CTS_SCSI_FLAGS_TAG_ENB; scsi_set_transfer_settings(&cts, path, /*async_update*/TRUE); } } /* * Handle any per-device event notifications that require action by the XPT. */ static void scsi_dev_async(u_int32_t async_code, struct cam_eb *bus, struct cam_et *target, struct cam_ed *device, void *async_arg) { cam_status status; struct cam_path newpath; /* * We only need to handle events for real devices. */ if (target->target_id == CAM_TARGET_WILDCARD || device->lun_id == CAM_LUN_WILDCARD) return; /* * We need our own path with wildcards expanded to * handle certain types of events. */ if ((async_code == AC_SENT_BDR) || (async_code == AC_BUS_RESET) || (async_code == AC_INQ_CHANGED)) status = xpt_compile_path(&newpath, NULL, bus->path_id, target->target_id, device->lun_id); else status = CAM_REQ_CMP_ERR; if (status == CAM_REQ_CMP) { /* * Allow transfer negotiation to occur in a * tag free environment and after settle delay. */ if (async_code == AC_SENT_BDR || async_code == AC_BUS_RESET) { cam_freeze_devq(&newpath); cam_release_devq(&newpath, RELSIM_RELEASE_AFTER_TIMEOUT, /*reduction*/0, /*timeout*/scsi_delay, /*getcount_only*/0); scsi_toggle_tags(&newpath); } if (async_code == AC_INQ_CHANGED) { /* * We've sent a start unit command, or * something similar to a device that * may have caused its inquiry data to * change. So we re-scan the device to * refresh the inquiry data for it. */ scsi_scan_lun(newpath.periph, &newpath, CAM_EXPECT_INQ_CHANGE, NULL); } xpt_release_path(&newpath); } else if (async_code == AC_LOST_DEVICE && (device->flags & CAM_DEV_UNCONFIGURED) == 0) { device->flags |= CAM_DEV_UNCONFIGURED; xpt_release_device(device); } else if (async_code == AC_TRANSFER_NEG) { struct ccb_trans_settings *settings; struct cam_path path; settings = (struct ccb_trans_settings *)async_arg; xpt_compile_path(&path, NULL, bus->path_id, target->target_id, device->lun_id); scsi_set_transfer_settings(settings, &path, /*async_update*/TRUE); xpt_release_path(&path); } } static void scsi_announce_periph(struct cam_periph *periph) { struct ccb_pathinq cpi; struct ccb_trans_settings cts; struct cam_path *path = periph->path; u_int speed; u_int freq; u_int mb; cam_periph_assert(periph, MA_OWNED); xpt_setup_ccb(&cts.ccb_h, path, CAM_PRIORITY_NORMAL); cts.ccb_h.func_code = XPT_GET_TRAN_SETTINGS; cts.type = CTS_TYPE_CURRENT_SETTINGS; xpt_action((union ccb*)&cts); if (cam_ccb_status((union ccb *)&cts) != CAM_REQ_CMP) return; /* Ask the SIM for its base transfer speed */ xpt_setup_ccb(&cpi.ccb_h, path, CAM_PRIORITY_NORMAL); cpi.ccb_h.func_code = XPT_PATH_INQ; xpt_action((union ccb *)&cpi); /* Report connection speed */ speed = cpi.base_transfer_speed; freq = 0; if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) { struct ccb_trans_settings_spi *spi = &cts.xport_specific.spi; if ((spi->valid & CTS_SPI_VALID_SYNC_OFFSET) != 0 && spi->sync_offset != 0) { freq = scsi_calc_syncsrate(spi->sync_period); speed = freq; } if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0) speed *= (0x01 << spi->bus_width); } if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) { struct ccb_trans_settings_fc *fc = &cts.xport_specific.fc; if (fc->valid & CTS_FC_VALID_SPEED) speed = fc->bitrate; } if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SAS) { struct ccb_trans_settings_sas *sas = &cts.xport_specific.sas; if (sas->valid & CTS_SAS_VALID_SPEED) speed = sas->bitrate; } mb = speed / 1000; if (mb > 0) printf("%s%d: %d.%03dMB/s transfers", periph->periph_name, periph->unit_number, mb, speed % 1000); else printf("%s%d: %dKB/s transfers", periph->periph_name, periph->unit_number, speed); /* Report additional information about SPI connections */ if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_SPI) { struct ccb_trans_settings_spi *spi; spi = &cts.xport_specific.spi; if (freq != 0) { printf(" (%d.%03dMHz%s, offset %d", freq / 1000, freq % 1000, (spi->ppr_options & MSG_EXT_PPR_DT_REQ) != 0 ? " DT" : "", spi->sync_offset); } if ((spi->valid & CTS_SPI_VALID_BUS_WIDTH) != 0 && spi->bus_width > 0) { if (freq != 0) { printf(", "); } else { printf(" ("); } printf("%dbit)", 8 * (0x01 << spi->bus_width)); } else if (freq != 0) { printf(")"); } } if (cts.ccb_h.status == CAM_REQ_CMP && cts.transport == XPORT_FC) { struct ccb_trans_settings_fc *fc; fc = &cts.xport_specific.fc; if (fc->valid & CTS_FC_VALID_WWNN) printf(" WWNN 0x%llx", (long long) fc->wwnn); if (fc->valid & CTS_FC_VALID_WWPN) printf(" WWPN 0x%llx", (long long) fc->wwpn); if (fc->valid & CTS_FC_VALID_PORT) printf(" PortID 0x%x", fc->port); } printf("\n"); } Index: projects/sendfile/sys/dev/ct/bshw_machdep.c =================================================================== --- projects/sendfile/sys/dev/ct/bshw_machdep.c (revision 274764) +++ projects/sendfile/sys/dev/ct/bshw_machdep.c (revision 274765) @@ -1,742 +1,743 @@ /* $NecBSD: bshw_machdep.c,v 1.8.12.6 2001/06/29 06:28:05 honda Exp $ */ #include __FBSDID("$FreeBSD$"); /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #include "opt_ddb.h" #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include #include #include #include #include #define BSHW_IO_CONTROL_FLAGS 0 u_int bshw_io_control = BSHW_IO_CONTROL_FLAGS; int bshw_data_read_bytes = 4096; int bshw_data_write_bytes = 4096; /********************************************************* * OS dep part *********************************************************/ typedef unsigned long vaddr_t; /********************************************************* * GENERIC MACHDEP FUNCTIONS *********************************************************/ void bshw_synch_setup(struct ct_softc *ct, struct targ_info *ti) { struct ct_bus_access_handle *chp = &ct->sc_ch; struct ct_targ_info *cti = (void *) ti; struct bshw_softc *bs = ct->ct_hw; struct bshw *hw = bs->sc_hw; if (hw->hw_sregaddr == 0) return; ct_cr_write_1(chp, hw->hw_sregaddr + ti->ti_id, cti->cti_syncreg); if (hw->hw_flags & BSHW_DOUBLE_DMACHAN) { ct_cr_write_1(chp, hw->hw_sregaddr + ti->ti_id + 8, cti->cti_syncreg); } } void bshw_bus_reset(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct bshw_softc *bs = ct->ct_hw; struct bshw *hw = bs->sc_hw; bus_addr_t offs; u_int8_t regv; int i; /* open hardware busmaster mode */ if (hw->hw_dma_init != NULL && ((*hw->hw_dma_init)(ct)) != 0) { device_printf(slp->sl_dev, "change mode using external DMA (%x)\n", (u_int)ct_cr_read_1(chp, 0x37)); } /* clear hardware synch registers */ offs = hw->hw_sregaddr; if (offs != 0) { for (i = 0; i < 8; i ++, offs ++) { ct_cr_write_1(chp, offs, 0); if ((hw->hw_flags & BSHW_DOUBLE_DMACHAN) != 0) ct_cr_write_1(chp, offs + 8, 0); } } /* disable interrupt & assert reset */ regv = ct_cr_read_1(chp, wd3s_mbank); regv |= MBR_RST; regv &= ~MBR_IEN; ct_cr_write_1(chp, wd3s_mbank, regv); DELAY(500000); /* reset signal off */ regv &= ~MBR_RST; ct_cr_write_1(chp, wd3s_mbank, regv); /* interrupt enable */ regv |= MBR_IEN; ct_cr_write_1(chp, wd3s_mbank, regv); } /* probe */ int bshw_read_settings(struct ct_bus_access_handle *chp, struct bshw_softc *bs) { static int irq_tbl[] = { 3, 5, 6, 9, 12, 13 }; bs->sc_hostid = (ct_cr_read_1(chp, wd3s_auxc) & AUXCR_HIDM); bs->sc_irq = irq_tbl[(ct_cr_read_1(chp, wd3s_auxc) >> 3) & 7]; bs->sc_drq = ct_cmdp_read_1(chp) & 3; return 0; } /********************************************************* * DMA PIO TRANSFER (SMIT) *********************************************************/ #define LC_SMIT_TIMEOUT 2 /* 2 sec: timeout for a fifo status ready */ #define LC_SMIT_OFFSET 0x1000 #define LC_FSZ DEV_BSIZE #define LC_SFSZ 0x0c #define LC_REST (LC_FSZ - LC_SFSZ) #define BSHW_LC_FSET 0x36 #define BSHW_LC_FCTRL 0x44 #define FCTRL_EN 0x01 #define FCTRL_WRITE 0x02 #define SF_ABORT 0x08 #define SF_RDY 0x10 static __inline void bshw_lc_smit_start(struct ct_softc *, int, u_int); static __inline void bshw_lc_smit_stop(struct ct_softc *); static int bshw_lc_smit_fstat(struct ct_softc *, int, int); static __inline void bshw_lc_smit_stop(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; ct_cr_write_1(chp, BSHW_LC_FCTRL, 0); ct_cmdp_write_1(chp, CMDP_DMER); } static __inline void bshw_lc_smit_start(struct ct_softc *ct, int count, u_int direction) { struct ct_bus_access_handle *chp = &ct->sc_ch; u_int8_t pval, val; val = ct_cr_read_1(chp, BSHW_LC_FSET); cthw_set_count(chp, count); pval = FCTRL_EN; if (direction == SCSI_LOW_WRITE) pval |= (val & 0xe0) | FCTRL_WRITE; ct_cr_write_1(chp, BSHW_LC_FCTRL, pval); ct_cr_write_1(chp, wd3s_cmd, WD3S_TFR_INFO); } static int bshw_lc_smit_fstat(struct ct_softc *ct, int wc, int read) { struct ct_bus_access_handle *chp = &ct->sc_ch; u_int8_t stat; while (wc -- > 0) { chp->ch_bus_weight(chp); stat = ct_cmdp_read_1(chp); if (read == SCSI_LOW_READ) { if ((stat & SF_RDY) != 0) return 0; if ((stat & SF_ABORT) != 0) return EIO; } else { if ((stat & SF_ABORT) != 0) return EIO; if ((stat & SF_RDY) != 0) return 0; } } device_printf(ct->sc_sclow.sl_dev, "SMIT fifo status timeout\n"); return EIO; } void bshw_smit_xfer_stop(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct bshw_softc *bs = ct->ct_hw; struct targ_info *ti; struct sc_p *sp = &slp->sl_scp; u_int count; bshw_lc_smit_stop(ct); ti = slp->sl_Tnexus; if (ti == NULL) return; if (ti->ti_phase == PH_DATA) { count = cthw_get_count(&ct->sc_ch); if (count < bs->sc_sdatalen) { if (sp->scp_direction == SCSI_LOW_READ && count != bs->sc_edatalen) goto bad; count = bs->sc_sdatalen - count; if (count > (u_int) sp->scp_datalen) goto bad; sp->scp_data += count; sp->scp_datalen -= count; } else if (count > bs->sc_sdatalen) { bad: device_printf(slp->sl_dev, "smit_xfer_end: cnt error\n"); slp->sl_error |= PDMAERR; } scsi_low_data_finish(slp); } else { device_printf(slp->sl_dev, "smit_xfer_end: phase miss\n"); slp->sl_error |= PDMAERR; } } int bshw_smit_xfer_start(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct bshw_softc *bs = ct->ct_hw; struct sc_p *sp = &slp->sl_scp; struct targ_info *ti = slp->sl_Tnexus; struct ct_targ_info *cti = (void *) ti; u_int datalen, count, io_control; int wc; u_int8_t *data; io_control = bs->sc_io_control | bshw_io_control; if ((io_control & BSHW_SMIT_BLOCK) != 0) return EINVAL; if ((slp->sl_scp.scp_datalen % DEV_BSIZE) != 0) return EINVAL; datalen = sp->scp_datalen; if (slp->sl_scp.scp_direction == SCSI_LOW_READ) { if ((io_control & BSHW_READ_INTERRUPT_DRIVEN) != 0 && datalen > bshw_data_read_bytes) datalen = bshw_data_read_bytes; } else { if ((io_control & BSHW_WRITE_INTERRUPT_DRIVEN) != 0 && datalen > bshw_data_write_bytes) datalen = bshw_data_write_bytes; } bs->sc_sdatalen = datalen; data = sp->scp_data; wc = LC_SMIT_TIMEOUT * 1024 * 1024; ct_cr_write_1(chp, wd3s_ctrl, ct->sc_creg | CR_DMA); bshw_lc_smit_start(ct, datalen, sp->scp_direction); if (sp->scp_direction == SCSI_LOW_READ) { do { if (bshw_lc_smit_fstat(ct, wc, SCSI_LOW_READ)) break; count = (datalen > LC_FSZ ? LC_FSZ : datalen); - bus_space_read_region_4(chp->ch_memt, chp->ch_memh, + bus_read_region_4(chp->ch_mem, LC_SMIT_OFFSET, (u_int32_t *) data, count >> 2); data += count; datalen -= count; } while (datalen > 0); bs->sc_edatalen = datalen; } else { do { if (bshw_lc_smit_fstat(ct, wc, SCSI_LOW_WRITE)) break; if (cti->cti_syncreg == 0) { /* XXX: * If async transfer, reconfirm a scsi phase * again. Unless C bus might hang up. */ if (bshw_lc_smit_fstat(ct, wc, SCSI_LOW_WRITE)) break; } count = (datalen > LC_SFSZ ? LC_SFSZ : datalen); - bus_space_write_region_4(chp->ch_memt, chp->ch_memh, + bus_write_region_4(chp->ch_mem, LC_SMIT_OFFSET, (u_int32_t *) data, count >> 2); data += count; datalen -= count; if (bshw_lc_smit_fstat(ct, wc, SCSI_LOW_WRITE)) break; count = (datalen > LC_REST ? LC_REST : datalen); - bus_space_write_region_4(chp->ch_memt, chp->ch_memh, + bus_write_region_4(chp->ch_mem, LC_SMIT_OFFSET + LC_SFSZ, (u_int32_t *) data, count >> 2); data += count; datalen -= count; } while (datalen > 0); } return 0; } /********************************************************* * DMA TRANSFER (BS) *********************************************************/ static __inline void bshw_dma_write_1 \ (struct ct_bus_access_handle *, bus_addr_t, u_int8_t); static void bshw_dmastart(struct ct_softc *); static void bshw_dmadone(struct ct_softc *); int bshw_dma_xfer_start(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct sc_p *sp = &slp->sl_scp; struct ct_bus_access_handle *chp = &ct->sc_ch; struct bshw_softc *bs = ct->ct_hw; vaddr_t va, endva, phys, nphys; u_int io_control; io_control = bs->sc_io_control | bshw_io_control; if ((io_control & BSHW_DMA_BLOCK) != 0 && sp->scp_datalen < 256) return EINVAL; ct_cr_write_1(chp, wd3s_ctrl, ct->sc_creg | CR_DMA); phys = vtophys((vaddr_t) sp->scp_data); if (phys >= bs->sc_minphys) { /* setup segaddr */ bs->sc_segaddr = bs->sc_bounce_phys; /* setup seglen */ bs->sc_seglen = sp->scp_datalen; if (bs->sc_seglen > bs->sc_bounce_size) bs->sc_seglen = bs->sc_bounce_size; /* setup bufp */ bs->sc_bufp = bs->sc_bounce_addr; if (sp->scp_direction == SCSI_LOW_WRITE) bcopy(sp->scp_data, bs->sc_bufp, bs->sc_seglen); } else { /* setup segaddr */ bs->sc_segaddr = (u_int8_t *) phys; /* setup seglen */ endva = (vaddr_t) round_page((vaddr_t) sp->scp_data + sp->scp_datalen); for (va = (vaddr_t) sp->scp_data; ; phys = nphys) { if ((va += PAGE_SIZE) >= endva) { bs->sc_seglen = sp->scp_datalen; break; } nphys = vtophys(va); if (phys + PAGE_SIZE != nphys || nphys >= bs->sc_minphys) { bs->sc_seglen = (u_int8_t *) trunc_page(va) - sp->scp_data; break; } } /* setup bufp */ bs->sc_bufp = NULL; } bshw_dmastart(ct); cthw_set_count(chp, bs->sc_seglen); ct_cr_write_1(chp, wd3s_cmd, WD3S_TFR_INFO); return 0; } void bshw_dma_xfer_stop(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct sc_p *sp = &slp->sl_scp; struct bshw_softc *bs = ct->ct_hw; struct targ_info *ti; u_int count, transbytes; bshw_dmadone(ct); ti = slp->sl_Tnexus; if (ti == NULL) return; if (ti->ti_phase == PH_DATA) { count = cthw_get_count(&ct->sc_ch); if (count < (u_int) bs->sc_seglen) { transbytes = bs->sc_seglen - count; if (bs->sc_bufp != NULL && sp->scp_direction == SCSI_LOW_READ) bcopy(bs->sc_bufp, sp->scp_data, transbytes); sp->scp_data += transbytes; sp->scp_datalen -= transbytes; } else if (count > (u_int) bs->sc_seglen) { device_printf(slp->sl_dev, "port data %x != seglen %x\n", count, bs->sc_seglen); slp->sl_error |= PDMAERR; } scsi_low_data_finish(slp); } else { device_printf(slp->sl_dev, "extra DMA interrupt\n"); slp->sl_error |= PDMAERR; } bs->sc_bufp = NULL; } /* common dma settings */ #undef DMA1_SMSK #define DMA1_SMSK (0x15) #undef DMA1_MODE #define DMA1_MODE (0x17) #undef DMA1_FFC #define DMA1_FFC (0x19) #undef DMA1_CHN #define DMA1_CHN(c) (0x01 + ((c) << 2)) #define DMA37SM_SET 0x04 #define DMA37MD_WRITE 0x04 #define DMA37MD_READ 0x08 #define DMA37MD_SINGLE 0x40 static bus_addr_t dmapageport[4] = { 0x27, 0x21, 0x23, 0x25 }; static __inline void bshw_dma_write_1(struct ct_bus_access_handle *chp, bus_addr_t port, u_int8_t val) { CT_BUS_WEIGHT(chp); outb(port, val); } static void bshw_dmastart(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct bshw_softc *bs = ct->ct_hw; struct ct_bus_access_handle *chp = &ct->sc_ch; int chan = bs->sc_drq; bus_addr_t waport; u_int8_t regv, *phys = bs->sc_segaddr; u_int nbytes = bs->sc_seglen; /* flush cpu cache */ (*bs->sc_dmasync_before) (ct); /* * Program one of DMA channels 0..3. These are * byte mode channels. */ /* set dma channel mode, and reset address ff */ if (slp->sl_scp.scp_direction == SCSI_LOW_READ) regv = DMA37MD_WRITE | DMA37MD_SINGLE | chan; else regv = DMA37MD_READ | DMA37MD_SINGLE | chan; bshw_dma_write_1(chp, DMA1_MODE, regv); bshw_dma_write_1(chp, DMA1_FFC, 0); /* send start address */ waport = DMA1_CHN(chan); bshw_dma_write_1(chp, waport, (u_int) phys); bshw_dma_write_1(chp, waport, ((u_int) phys) >> 8); bshw_dma_write_1(chp, dmapageport[chan], ((u_int) phys) >> 16); /* send count */ bshw_dma_write_1(chp, waport + 2, --nbytes); bshw_dma_write_1(chp, waport + 2, nbytes >> 8); /* vendor unique hook */ if (bs->sc_hw->hw_dma_start) (*bs->sc_hw->hw_dma_start)(ct); bshw_dma_write_1(chp, DMA1_SMSK, chan); ct_cmdp_write_1(chp, CMDP_DMES); } static void bshw_dmadone(struct ct_softc *ct) { struct bshw_softc *bs = ct->ct_hw; struct ct_bus_access_handle *chp = &ct->sc_ch; bshw_dma_write_1(chp, DMA1_SMSK, (bs->sc_drq | DMA37SM_SET)); ct_cmdp_write_1(chp, CMDP_DMER); /* vendor unique hook */ if (bs->sc_hw->hw_dma_stop) (*bs->sc_hw->hw_dma_stop) (ct); /* flush cpu cache */ (*bs->sc_dmasync_after) (ct); } /********************************************** * VENDOR UNIQUE DMA FUNCS **********************************************/ static int bshw_dma_init_sc98(struct ct_softc *); static void bshw_dma_start_sc98(struct ct_softc *); static void bshw_dma_stop_sc98(struct ct_softc *); static int bshw_dma_init_texa(struct ct_softc *); static void bshw_dma_start_elecom(struct ct_softc *); static void bshw_dma_stop_elecom(struct ct_softc *); static int bshw_dma_init_texa(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; u_int8_t regval; if ((regval = ct_cr_read_1(chp, 0x37)) & 0x08) return 0; ct_cr_write_1(chp, 0x37, regval | 0x08); regval = ct_cr_read_1(chp, 0x3f); ct_cr_write_1(chp, 0x3f, regval | 0x08); return 1; } static int bshw_dma_init_sc98(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; if (ct_cr_read_1(chp, 0x37) & 0x08) return 0; /* If your card is SC98 with bios ver 1.01 or 1.02 under no PCI */ ct_cr_write_1(chp, 0x37, 0x1a); ct_cr_write_1(chp, 0x3f, 0x1a); #if 0 /* only valid for IO */ ct_cr_write_1(chp, 0x40, 0xf4); ct_cr_write_1(chp, 0x41, 0x9); ct_cr_write_1(chp, 0x43, 0xff); ct_cr_write_1(chp, 0x46, 0x4e); ct_cr_write_1(chp, 0x48, 0xf4); ct_cr_write_1(chp, 0x49, 0x9); ct_cr_write_1(chp, 0x4b, 0xff); ct_cr_write_1(chp, 0x4e, 0x4e); #endif return 1; } static void bshw_dma_start_sc98(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; ct_cr_write_1(chp, 0x73, 0x32); ct_cr_write_1(chp, 0x74, 0x23); } static void bshw_dma_stop_sc98(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; ct_cr_write_1(chp, 0x73, 0x43); ct_cr_write_1(chp, 0x74, 0x34); } static void bshw_dma_start_elecom(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; u_int8_t tmp = ct_cr_read_1(chp, 0x4c); ct_cr_write_1(chp, 0x32, tmp & 0xdf); } static void bshw_dma_stop_elecom(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; u_int8_t tmp = ct_cr_read_1(chp, 0x4c); ct_cr_write_1(chp, 0x32, tmp | 0x20); } static struct bshw bshw_generic = { BSHW_SYNC_RELOAD, 0, NULL, NULL, NULL, }; static struct bshw bshw_sc98 = { BSHW_DOUBLE_DMACHAN, 0x60, bshw_dma_init_sc98, bshw_dma_start_sc98, bshw_dma_stop_sc98, }; static struct bshw bshw_texa = { BSHW_DOUBLE_DMACHAN, 0x60, bshw_dma_init_texa, NULL, NULL, }; static struct bshw bshw_elecom = { 0, 0x38, NULL, bshw_dma_start_elecom, bshw_dma_stop_elecom, }; static struct bshw bshw_lc_smit = { BSHW_SMFIFO | BSHW_DOUBLE_DMACHAN, 0x60, NULL, NULL, NULL, }; static struct bshw bshw_lha20X = { BSHW_DOUBLE_DMACHAN, 0x60, NULL, NULL, NULL, }; /* hw tabs */ static dvcfg_hw_t bshw_hwsel_array[] = { /* 0x00 */ &bshw_generic, /* 0x01 */ &bshw_sc98, /* 0x02 */ &bshw_texa, /* 0x03 */ &bshw_elecom, /* 0x04 */ &bshw_lc_smit, /* 0x05 */ &bshw_lha20X, }; struct dvcfg_hwsel bshw_hwsel = { DVCFG_HWSEL_SZ(bshw_hwsel_array), bshw_hwsel_array }; Index: projects/sendfile/sys/dev/ct/ct.c =================================================================== --- projects/sendfile/sys/dev/ct/ct.c (revision 274764) +++ projects/sendfile/sys/dev/ct/ct.c (revision 274765) @@ -1,1229 +1,1242 @@ /* $NecBSD: ct.c,v 1.13.12.5 2001/06/26 07:31:53 honda Exp $ */ #include __FBSDID("$FreeBSD$"); /* $NetBSD$ */ #define CT_DEBUG #define CT_IO_CONTROL_FLAGS (CT_USE_CCSEQ | CT_FAST_INTR) /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * * Copyright (c) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #define CT_NTARGETS 8 #define CT_NLUNS 8 #define CT_RESET_DEFAULT 2000 #define CT_DELAY_MAX (2 * 1000 * 1000) #define CT_DELAY_INTERVAL (1) /*************************************************** * DEBUG ***************************************************/ #ifdef CT_DEBUG int ct_debug; #endif /* CT_DEBUG */ /*************************************************** * IO control ***************************************************/ #define CT_USE_CCSEQ 0x0100 #define CT_FAST_INTR 0x0200 u_int ct_io_control = CT_IO_CONTROL_FLAGS; /*************************************************** * default data ***************************************************/ u_int8_t cthw_cmdlevel[256] = { /* 0 1 2 3 4 5 6 7 8 9 A B C E D F */ /*0*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 , /*1*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*2*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,1 ,0 ,1 ,0 ,0 ,0 ,0 ,0 , /*3*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*4*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*5*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*6*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*7*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*8*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*9*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*A*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*B*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*C*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*D*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*E*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , /*F*/0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , }; #if 0 /* default synch data table */ /* A 10 6.6 5.0 4.0 3.3 2.8 2.5 2.0 M/s */ /* X 100 150 200 250 300 350 400 500 ns */ static struct ct_synch_data ct_synch_data_FSCSI[] = { {25, 0xa0}, {37, 0xb0}, {50, 0x20}, {62, 0xd0}, {75, 0x30}, {87, 0xf0}, {100, 0x40}, {125, 0x50}, {0, 0} }; static struct ct_synch_data ct_synch_data_SCSI[] = { {50, 0x20}, {75, 0x30}, {100, 0x40}, {125, 0x50}, {0, 0} }; #endif /*************************************************** * DEVICE STRUCTURE ***************************************************/ extern struct cfdriver ct_cd; /***************************************************************** * Interface functions *****************************************************************/ static int ct_xfer(struct ct_softc *, u_int8_t *, int, int, u_int *); static void ct_io_xfer(struct ct_softc *); static int ct_reselected(struct ct_softc *, u_int8_t); static void ct_phase_error(struct ct_softc *, u_int8_t); static int ct_start_selection(struct ct_softc *, struct slccb *); static int ct_msg(struct ct_softc *, struct targ_info *, u_int); static int ct_world_start(struct ct_softc *, int); static __inline void cthw_phase_bypass(struct ct_softc *, u_int8_t); static int cthw_chip_reset(struct ct_bus_access_handle *, int *, int, int); static void cthw_bus_reset(struct ct_softc *); static int ct_ccb_nexus_establish(struct ct_softc *); static int ct_lun_nexus_establish(struct ct_softc *); static int ct_target_nexus_establish(struct ct_softc *, int, int); static void cthw_attention(struct ct_softc *); static int ct_targ_init(struct ct_softc *, struct targ_info *, int); static int ct_unbusy(struct ct_softc *); static void ct_attention(struct ct_softc *); static struct ct_synch_data *ct_make_synch_table(struct ct_softc *); static int ct_catch_intr(struct ct_softc *); +static int ct_poll(void *); struct scsi_low_funcs ct_funcs = { SC_LOW_INIT_T ct_world_start, SC_LOW_BUSRST_T cthw_bus_reset, SC_LOW_TARG_INIT_T ct_targ_init, SC_LOW_LUN_INIT_T NULL, SC_LOW_SELECT_T ct_start_selection, SC_LOW_NEXUS_T ct_lun_nexus_establish, SC_LOW_NEXUS_T ct_ccb_nexus_establish, SC_LOW_ATTEN_T cthw_attention, SC_LOW_MSG_T ct_msg, SC_LOW_TIMEOUT_T NULL, - SC_LOW_POLL_T ctintr, + SC_LOW_POLL_T ct_poll, NULL, /* SC_LOW_POWER_T cthw_power, */ }; /************************************************** * HW functions **************************************************/ static __inline void cthw_phase_bypass(struct ct_softc *ct, u_int8_t ph) { struct ct_bus_access_handle *chp = &ct->sc_ch; ct_cr_write_1(chp, wd3s_cph, ph); ct_cr_write_1(chp, wd3s_cmd, WD3S_SELECT_ATN_TFR); } static void cthw_bus_reset(struct ct_softc *ct) { /* * wd33c93 does not have bus reset function. */ if (ct->ct_bus_reset != NULL) ((*ct->ct_bus_reset) (ct)); } static int cthw_chip_reset(struct ct_bus_access_handle *chp, int *chiprevp, int chipclk, int hostid) { #define CT_SELTIMEOUT_20MHz_REGV (0x80) u_int8_t aux, regv; u_int seltout; int wc; /* issue abort cmd */ ct_cr_write_1(chp, wd3s_cmd, WD3S_ABORT); DELAY(1000); /* 1ms wait */ (void) ct_stat_read_1(chp); (void) ct_cr_read_1(chp, wd3s_stat); /* setup chip registers */ regv = 0; seltout = CT_SELTIMEOUT_20MHz_REGV; switch (chipclk) { case 8: case 10: seltout = (seltout * chipclk) / 20; regv = IDR_FS_8_10; break; case 12: case 15: seltout = (seltout * chipclk) / 20; regv = IDR_FS_12_15; break; case 16: case 20: seltout = (seltout * chipclk) / 20; regv = IDR_FS_16_20; break; default: panic("ct: illegal chip clk rate"); break; } regv |= IDR_EHP | hostid | IDR_RAF | IDR_EAF; ct_cr_write_1(chp, wd3s_oid, regv); ct_cr_write_1(chp, wd3s_cmd, WD3S_RESET); for (wc = CT_RESET_DEFAULT; wc > 0; wc --) { aux = ct_stat_read_1(chp); if (aux != 0xff && (aux & STR_INT)) { regv = ct_cr_read_1(chp, wd3s_stat); if (regv == BSR_RESET || regv == BSR_AFM_RESET) break; ct_cr_write_1(chp, wd3s_cmd, WD3S_RESET); } DELAY(1); } if (wc == 0) return ENXIO; ct_cr_write_1(chp, wd3s_tout, seltout); ct_cr_write_1(chp, wd3s_sid, SIDR_RESEL); ct_cr_write_1(chp, wd3s_ctrl, CR_DEFAULT); ct_cr_write_1(chp, wd3s_synch, 0); if (chiprevp != NULL) { *chiprevp = CT_WD33C93; if (regv == BSR_RESET) goto out; *chiprevp = CT_WD33C93_A; ct_cr_write_1(chp, wd3s_qtag, 0xaa); if (ct_cr_read_1(chp, wd3s_qtag) != 0xaa) { ct_cr_write_1(chp, wd3s_qtag, 0x0); goto out; } ct_cr_write_1(chp, wd3s_qtag, 0x55); if (ct_cr_read_1(chp, wd3s_qtag) != 0x55) { ct_cr_write_1(chp, wd3s_qtag, 0x0); goto out; } ct_cr_write_1(chp, wd3s_qtag, 0x0); *chiprevp = CT_WD33C93_B; } out: (void) ct_stat_read_1(chp); (void) ct_cr_read_1(chp, wd3s_stat); return 0; } static struct ct_synch_data * ct_make_synch_table(struct ct_softc *ct) { struct ct_synch_data *sdtp, *sdp; u_int base, i, period; sdtp = sdp = &ct->sc_default_sdt[0]; if ((ct->sc_chipclk % 5) == 0) base = 1000 / (5 * 2); /* 5 MHz type */ else base = 1000 / (4 * 2); /* 4 MHz type */ if (ct->sc_chiprev >= CT_WD33C93_B) { /* fast scsi */ for (i = 2; i < 8; i ++, sdp ++) { period = (base * i) / 2; if (period >= 200) /* 5 MHz */ break; sdp->cs_period = period / 4; sdp->cs_syncr = (i * 0x10) | 0x80; } } for (i = 2; i < 8; i ++, sdp ++) { period = (base * i); if (period > 500) /* 2 MHz */ break; sdp->cs_period = period / 4; sdp->cs_syncr = (i * 0x10); } sdp->cs_period = 0; sdp->cs_syncr = 0; return sdtp; } /************************************************** * Attach & Probe **************************************************/ int ctprobesubr(struct ct_bus_access_handle *chp, u_int dvcfg, int hsid, u_int chipclk, int *chiprevp) { #if 0 if ((ct_stat_read_1(chp) & STR_BSY) != 0) return 0; #endif if (cthw_chip_reset(chp, chiprevp, chipclk, hsid) != 0) return 0; return 1; } void ctattachsubr(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; ct->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */ slp->sl_funcs = &ct_funcs; slp->sl_flags |= HW_READ_PADDING; (void) scsi_low_attach(slp, 0, CT_NTARGETS, CT_NLUNS, sizeof(struct ct_targ_info), 0); } /************************************************** * SCSI LOW interface functions **************************************************/ static void cthw_attention(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; ct->sc_atten = 1; if ((ct_stat_read_1(chp) & (STR_BSY | STR_CIP)) != 0) return; ct_cr_write_1(chp, wd3s_cmd, WD3S_ASSERT_ATN); DELAY(10); if ((ct_stat_read_1(chp) & STR_LCI) == 0) ct->sc_atten = 0; ct_unbusy(ct); return; } static void ct_attention(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; if (slp->sl_atten == 0) { ct_unbusy(ct); scsi_low_attention(slp); } else if (ct->sc_atten != 0) { ct_unbusy(ct); cthw_attention(ct); } } static int ct_targ_init(struct ct_softc *ct, struct targ_info *ti, int action) { struct ct_targ_info *cti = (void *) ti; if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE) { if (ct->sc_sdp == NULL) { ct->sc_sdp = ct_make_synch_table(ct); } switch (ct->sc_chiprev) { default: ti->ti_maxsynch.offset = 5; break; case CT_WD33C93_A: case CT_AM33C93_A: ti->ti_maxsynch.offset = 12; break; case CT_WD33C93_B: case CT_WD33C93_C: ti->ti_maxsynch.offset = 12; break; } ti->ti_maxsynch.period = ct->sc_sdp[0].cs_period; ti->ti_width = SCSI_LOW_BUS_WIDTH_8; cti->cti_syncreg = 0; } return 0; } static int ct_world_start(struct ct_softc *ct, int fdone) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; if (ct->sc_sdp == NULL) { ct->sc_sdp = ct_make_synch_table(ct); } if (slp->sl_cfgflags & CFG_NOPARITY) ct->sc_creg = CR_DEFAULT; else ct->sc_creg = CR_DEFAULT_HP; if (ct->sc_dma & CT_DMA_DMASTART) (*ct->ct_dma_xfer_stop) (ct); if (ct->sc_dma & CT_DMA_PIOSTART) (*ct->ct_pio_xfer_stop) (ct); ct->sc_dma = 0; ct->sc_atten = 0; cthw_chip_reset(chp, NULL, ct->sc_chipclk, slp->sl_hostid); scsi_low_bus_reset(slp); cthw_chip_reset(chp, NULL, ct->sc_chipclk, slp->sl_hostid); return 0; } static int ct_start_selection(struct ct_softc *ct, struct slccb *cb) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct targ_info *ti = slp->sl_Tnexus; struct lun_info *li = slp->sl_Lnexus; int s, satok; u_int8_t cmd; ct->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; ct->sc_atten = 0; satok = 0; if (scsi_low_is_disconnect_ok(cb) != 0) { if (ct->sc_chiprev >= CT_WD33C93_A) satok = 1; else if (cthw_cmdlevel[slp->sl_scp.scp_cmd[0]] != 0) satok = 1; } if (satok != 0 && scsi_low_is_msgout_continue(ti, SCSI_LOW_MSG_IDENTIFY) == 0) { cmd = WD3S_SELECT_ATN_TFR; ct->sc_satgo = CT_SAT_GOING; } else { cmd = WD3S_SELECT_ATN; ct->sc_satgo = 0; } if ((ct_stat_read_1(chp) & (STR_BSY | STR_INT | STR_CIP)) != 0) return SCSI_LOW_START_FAIL; if ((ct->sc_satgo & CT_SAT_GOING) != 0) { (void) scsi_low_msgout(slp, ti, SCSI_LOW_MSGOUT_INIT); scsi_low_cmd(slp, ti); ct_cr_write_1(chp, wd3s_oid, slp->sl_scp.scp_cmdlen); ct_write_cmds(chp, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); } else { /* anyway attention assert */ SCSI_LOW_ASSERT_ATN(slp); } ct_target_nexus_establish(ct, li->li_lun, slp->sl_scp.scp_direction); s = splhigh(); if ((ct_stat_read_1(chp) & (STR_BSY | STR_INT | STR_CIP)) == 0) { /* XXX: * Reload a lun again here. */ ct_cr_write_1(chp, wd3s_lun, li->li_lun); ct_cr_write_1(chp, wd3s_cmd, cmd); if ((ct_stat_read_1(chp) & STR_LCI) == 0) { splx(s); SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART); return SCSI_LOW_START_OK; } } splx(s); return SCSI_LOW_START_FAIL; } static int ct_msg(struct ct_softc *ct, struct targ_info *ti, u_int msg) { struct ct_bus_access_handle *chp = &ct->sc_ch; struct ct_targ_info *cti = (void *) ti; struct ct_synch_data *csp = ct->sc_sdp; u_int offset, period; int error; if ((msg & SCSI_LOW_MSG_WIDE) != 0) { if (ti->ti_width != SCSI_LOW_BUS_WIDTH_8) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; return EINVAL; } return 0; } if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; offset = ti->ti_maxsynch.offset; period = ti->ti_maxsynch.period; for ( ; csp->cs_period != 0; csp ++) { if (period == csp->cs_period) break; } if (ti->ti_maxsynch.period != 0 && csp->cs_period == 0) { ti->ti_maxsynch.period = 0; ti->ti_maxsynch.offset = 0; cti->cti_syncreg = 0; error = EINVAL; } else { cti->cti_syncreg = ((offset & 0x0f) | csp->cs_syncr); error = 0; } if (ct->ct_synch_setup != 0) (*ct->ct_synch_setup) (ct, ti); ct_cr_write_1(chp, wd3s_synch, cti->cti_syncreg); return error; } /************************************************* * *************************************************/ static int ct_xfer(struct ct_softc *ct, u_int8_t *data, int len, int direction, u_int *statp) { struct ct_bus_access_handle *chp = &ct->sc_ch; int wc; register u_int8_t aux; *statp = 0; if (len == 1) { ct_cr_write_1(chp, wd3s_cmd, WD3S_SBT | WD3S_TFR_INFO); } else { cthw_set_count(chp, len); ct_cr_write_1(chp, wd3s_cmd, WD3S_TFR_INFO); } aux = ct_stat_read_1(chp); if ((aux & STR_LCI) != 0) { cthw_set_count(chp, 0); return len; } for (wc = 0; wc < ct->sc_tmaxcnt; wc ++) { /* check data ready */ if ((aux & (STR_BSY | STR_DBR)) == (STR_BSY | STR_DBR)) { if (direction == SCSI_LOW_READ) { *data = ct_cr_read_1(chp, wd3s_data); if ((aux & STR_PE) != 0) *statp |= SCSI_LOW_DATA_PE; } else { ct_cr_write_1(chp, wd3s_data, *data); } len --; if (len <= 0) break; data ++; } else { DELAY(1); } /* check phase miss */ aux = ct_stat_read_1(chp); if ((aux & STR_INT) != 0) break; } return len; } #define CT_PADDING_BUF_SIZE 32 static void ct_io_xfer(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct sc_p *sp = &slp->sl_scp; u_int stat; int len; u_int8_t pbuf[CT_PADDING_BUF_SIZE]; /* polling mode */ ct_cr_write_1(chp, wd3s_ctrl, ct->sc_creg); if (sp->scp_datalen <= 0) { slp->sl_error |= PDMAERR; if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) bzero(pbuf, CT_PADDING_BUF_SIZE); ct_xfer(ct, pbuf, CT_PADDING_BUF_SIZE, sp->scp_direction, &stat); } else { len = ct_xfer(ct, sp->scp_data, sp->scp_datalen, sp->scp_direction, &stat); sp->scp_data += (sp->scp_datalen - len); sp->scp_datalen = len; } } /************************************************** * **************************************************/ struct ct_err { u_char *pe_msg; u_int pe_err; u_int pe_errmsg; int pe_done; }; struct ct_err ct_cmderr[] = { /*0*/ { "illegal cmd", FATALIO, SCSI_LOW_MSG_ABORT, 1}, /*1*/ { "unexpected bus free", FATALIO, 0, 1}, /*2*/ { NULL, SELTIMEOUTIO, 0, 1}, /*3*/ { "scsi bus parity error", PARITYERR, SCSI_LOW_MSG_ERROR, 0}, /*4*/ { "scsi bus parity error", PARITYERR, SCSI_LOW_MSG_ERROR, 0}, /*5*/ { "unknown" , FATALIO, SCSI_LOW_MSG_ABORT, 1}, /*6*/ { "miss reselection (target mode)", FATALIO, SCSI_LOW_MSG_ABORT, 0}, /*7*/ { "wrong status byte", PARITYERR, SCSI_LOW_MSG_ERROR, 0}, }; static void ct_phase_error(struct ct_softc *ct, u_int8_t scsi_status) { struct scsi_low_softc *slp = &ct->sc_sclow; struct targ_info *ti = slp->sl_Tnexus; struct ct_err *pep; u_int msg = 0; if ((scsi_status & BSR_CM) == BSR_CMDERR && (scsi_status & BSR_PHVALID) == 0) { pep = &ct_cmderr[scsi_status & BSR_PM]; slp->sl_error |= pep->pe_err; if ((pep->pe_err & PARITYERR) != 0) { if (ti->ti_phase == PH_MSGIN) msg = SCSI_LOW_MSG_PARITY; else msg = SCSI_LOW_MSG_ERROR; } else msg = pep->pe_errmsg; if (msg != 0) scsi_low_assert_msg(slp, slp->sl_Tnexus, msg, 1); if (pep->pe_msg != NULL) { device_printf(slp->sl_dev, "phase error: %s", pep->pe_msg); scsi_low_print(slp, slp->sl_Tnexus); } if (pep->pe_done != 0) scsi_low_disconnected(slp, ti); } else { slp->sl_error |= FATALIO; scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "phase error"); } } /************************************************** * ### SCSI PHASE SEQUENCER ### **************************************************/ static int ct_reselected(struct ct_softc *ct, u_int8_t scsi_status) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct targ_info *ti; u_int sid; u_int8_t regv; ct->sc_atten = 0; ct->sc_satgo &= ~CT_SAT_GOING; regv = ct_cr_read_1(chp, wd3s_sid); if ((regv & SIDR_VALID) == 0) return EJUSTRETURN; sid = regv & SIDR_IDM; if ((ti = scsi_low_reselected(slp, sid)) == NULL) return EJUSTRETURN; ct_target_nexus_establish(ct, 0, SCSI_LOW_READ); if (scsi_status != BSR_AFM_RESEL) return EJUSTRETURN; SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); regv = ct_cr_read_1(chp, wd3s_data); if (scsi_low_msgin(slp, ti, (u_int) regv) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) { /* XXX: scsi_low_attetion */ scsi_low_attention(slp); } } if (ct->sc_atten != 0) { ct_attention(ct); } ct_cr_write_1(chp, wd3s_cmd, WD3S_NEGATE_ACK); return EJUSTRETURN; } static int ct_target_nexus_establish(struct ct_softc *ct, int lun, int dir) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct targ_info *ti = slp->sl_Tnexus; struct ct_targ_info *cti = (void *) ti; if (dir == SCSI_LOW_WRITE) ct_cr_write_1(chp, wd3s_did, ti->ti_id); else ct_cr_write_1(chp, wd3s_did, ti->ti_id | DIDR_DPD); ct_cr_write_1(chp, wd3s_lun, lun); ct_cr_write_1(chp, wd3s_ctrl, ct->sc_creg | CR_DMA); ct_cr_write_1(chp, wd3s_cph, 0); ct_cr_write_1(chp, wd3s_synch, cti->cti_syncreg); cthw_set_count(chp, 0); return 0; } static int ct_lun_nexus_establish(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct lun_info *li = slp->sl_Lnexus; ct_cr_write_1(chp, wd3s_lun, li->li_lun); return 0; } static int ct_ccb_nexus_establish(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct lun_info *li = slp->sl_Lnexus; struct targ_info *ti = slp->sl_Tnexus; struct ct_targ_info *cti = (void *) ti; struct slccb *cb = slp->sl_Qnexus; ct->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; if ((ct->sc_satgo & CT_SAT_GOING) != 0) { ct_cr_write_1(chp, wd3s_oid, slp->sl_scp.scp_cmdlen); ct_write_cmds(chp, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); } if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) ct_cr_write_1(chp, wd3s_did, ti->ti_id); else ct_cr_write_1(chp, wd3s_did, ti->ti_id | DIDR_DPD); ct_cr_write_1(chp, wd3s_lun, li->li_lun); ct_cr_write_1(chp, wd3s_synch, cti->cti_syncreg); return 0; } static int ct_unbusy(struct ct_softc *ct) { struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; int wc; register u_int8_t regv; for (wc = 0; wc < CT_DELAY_MAX / CT_DELAY_INTERVAL; wc ++) { regv = ct_stat_read_1(chp); if ((regv & (STR_BSY | STR_CIP)) == 0) return 0; if (regv == (u_int8_t) -1) return EIO; DELAY(CT_DELAY_INTERVAL); } device_printf(slp->sl_dev, "unbusy timeout\n"); return EBUSY; } static int ct_catch_intr(struct ct_softc *ct) { struct ct_bus_access_handle *chp = &ct->sc_ch; int wc; register u_int8_t regv; for (wc = 0; wc < CT_DELAY_MAX / CT_DELAY_INTERVAL; wc ++) { regv = ct_stat_read_1(chp); if ((regv & (STR_INT | STR_BSY | STR_CIP)) == STR_INT) return 0; DELAY(CT_DELAY_INTERVAL); } return EJUSTRETURN; } -int +void ctintr(void *arg) +{ + struct ct_softc *ct = arg; + struct scsi_low_softc *slp = &ct->sc_sclow; + + SCSI_LOW_LOCK(slp); + ct_poll(ct); + SCSI_LOW_UNLOCK(slp); +} + +static int +ct_poll(void *arg) { struct ct_softc *ct = arg; struct scsi_low_softc *slp = &ct->sc_sclow; struct ct_bus_access_handle *chp = &ct->sc_ch; struct targ_info *ti; struct buf *bp; u_int derror, flags; int len, satgo, error; u_int8_t scsi_status, regv; again: if (slp->sl_flags & HW_INACTIVE) return 0; /************************************************** * Get status & bus phase **************************************************/ if ((ct_stat_read_1(chp) & STR_INT) == 0) return 0; scsi_status = ct_cr_read_1(chp, wd3s_stat); if (scsi_status == ((u_int8_t) -1)) return 1; /************************************************** * Check reselection, or nexus **************************************************/ if (scsi_status == BSR_RESEL || scsi_status == BSR_AFM_RESEL) { if (ct_reselected(ct, scsi_status) == EJUSTRETURN) return 1; } if ((ti = slp->sl_Tnexus) == NULL) return 1; /************************************************** * Debug section **************************************************/ #ifdef CT_DEBUG if (ct_debug > 0) { scsi_low_print(slp, NULL); device_printf(slp->sl_dev, "scsi_status 0x%x\n\n", (u_int) scsi_status); #ifdef KDB if (ct_debug > 1) kdb_enter(KDB_WHY_CAM, "ct"); #endif /* KDB */ } #endif /* CT_DEBUG */ /************************************************** * Internal scsi phase **************************************************/ satgo = ct->sc_satgo; ct->sc_satgo &= ~CT_SAT_GOING; switch (ti->ti_phase) { case PH_SELSTART: if ((satgo & CT_SAT_GOING) == 0) { if (scsi_status != BSR_SELECTED) { ct_phase_error(ct, scsi_status); return 1; } scsi_low_arbit_win(slp); SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); return 1; } else { scsi_low_arbit_win(slp); SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); /* XXX */ } break; case PH_RESEL: if ((scsi_status & BSR_PHVALID) == 0 || (scsi_status & BSR_PM) != BSR_MSGIN) { scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "phase miss after reselect"); return 1; } break; default: if (slp->sl_flags & HW_PDMASTART) { slp->sl_flags &= ~HW_PDMASTART; if (ct->sc_dma & CT_DMA_DMASTART) { (*ct->ct_dma_xfer_stop) (ct); ct->sc_dma &= ~CT_DMA_DMASTART; } else if (ct->sc_dma & CT_DMA_PIOSTART) { (*ct->ct_pio_xfer_stop) (ct); ct->sc_dma &= ~CT_DMA_PIOSTART; } else { scsi_low_data_finish(slp); } } break; } /************************************************** * parse scsi phase **************************************************/ if (scsi_status & BSR_PHVALID) { /************************************************** * Normal SCSI phase. **************************************************/ if ((scsi_status & BSR_CM) == BSR_CMDABT) { ct_phase_error(ct, scsi_status); return 1; } switch (scsi_status & BSR_PM) { case BSR_DATAOUT: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_WRITE) != 0) { ct_attention(ct); } goto common_data_phase; case BSR_DATAIN: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_READ) != 0) { ct_attention(ct); } common_data_phase: if (slp->sl_scp.scp_datalen > 0) { slp->sl_flags |= HW_PDMASTART; if ((ct->sc_xmode & CT_XMODE_PIO) != 0) { error = (*ct->ct_pio_xfer_start) (ct); if (error == 0) { ct->sc_dma |= CT_DMA_PIOSTART; return 1; } } if ((ct->sc_xmode & CT_XMODE_DMA) != 0) { error = (*ct->ct_dma_xfer_start) (ct); if (error == 0) { ct->sc_dma |= CT_DMA_DMASTART; return 1; } } } else { if (slp->sl_scp.scp_direction == SCSI_LOW_READ) { if (!(slp->sl_flags & HW_READ_PADDING)) { device_printf(slp->sl_dev, "read padding required\n"); return 1; } } else { if (!(slp->sl_flags & HW_WRITE_PADDING)) { device_printf(slp->sl_dev, "write padding required\n"); return 1; } } slp->sl_flags |= HW_PDMASTART; } ct_io_xfer(ct); return 1; case BSR_CMDOUT: SCSI_LOW_SETUP_PHASE(ti, PH_CMD); if (scsi_low_cmd(slp, ti) != 0) { ct_attention(ct); } if (ct_xfer(ct, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen, SCSI_LOW_WRITE, &derror) != 0) { device_printf(slp->sl_dev, "scsi cmd xfer short\n"); } return 1; case BSR_STATIN: SCSI_LOW_SETUP_PHASE(ti, PH_STAT); if ((ct_io_control & CT_USE_CCSEQ) != 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0 || ct->sc_atten != 0) { ct_xfer(ct, ®v, 1, SCSI_LOW_READ, &derror); scsi_low_statusin(slp, ti, regv | derror); } else { ct->sc_satgo |= CT_SAT_GOING; cthw_set_count(chp, 0); cthw_phase_bypass(ct, 0x41); } } else { ct_xfer(ct, ®v, 1, SCSI_LOW_READ, &derror); scsi_low_statusin(slp, ti, regv | derror); } return 1; case BSR_UNSPINFO0: case BSR_UNSPINFO1: device_printf(slp->sl_dev, "illegal bus phase (0x%x)\n", (u_int) scsi_status); scsi_low_print(slp, ti); return 1; case BSR_MSGOUT: SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); flags = SCSI_LOW_MSGOUT_UNIFY; if (ti->ti_ophase != ti->ti_phase) flags |= SCSI_LOW_MSGOUT_INIT; len = scsi_low_msgout(slp, ti, flags); if (len > 1 && slp->sl_atten == 0) { ct_attention(ct); } if (ct_xfer(ct, ti->ti_msgoutstr, len, SCSI_LOW_WRITE, &derror) != 0) { device_printf(slp->sl_dev, "scsi msgout xfer short\n"); } SCSI_LOW_DEASSERT_ATN(slp); ct->sc_atten = 0; return 1; case BSR_MSGIN:/* msg in */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); ct_xfer(ct, ®v, 1, SCSI_LOW_READ, &derror); if (scsi_low_msgin(slp, ti, regv | derror) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) { /* XXX: scsi_low_attetion */ scsi_low_attention(slp); } } if ((ct_io_control & CT_FAST_INTR) != 0) { if (ct_catch_intr(ct) == 0) goto again; } return 1; } } else { /************************************************** * Special SCSI phase **************************************************/ switch (scsi_status) { case BSR_SATSDP: /* SAT with save data pointer */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); ct->sc_satgo |= CT_SAT_GOING; scsi_low_msgin(slp, ti, MSG_SAVESP); cthw_phase_bypass(ct, 0x41); return 1; case BSR_SATFIN: /* SAT COMPLETE */ /* * emulate statusin => msgin */ SCSI_LOW_SETUP_PHASE(ti, PH_STAT); scsi_low_statusin(slp, ti, ct_cr_read_1(chp, wd3s_lun)); SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); scsi_low_msgin(slp, ti, MSG_COMP); scsi_low_disconnected(slp, ti); return 1; case BSR_ACKREQ: /* negate ACK */ if (ct->sc_atten != 0) { ct_attention(ct); } ct_cr_write_1(chp, wd3s_cmd, WD3S_NEGATE_ACK); if ((ct_io_control & CT_FAST_INTR) != 0) { /* XXX: * Should clear a pending interrupt and * sync with a next interrupt! */ ct_catch_intr(ct); } return 1; case BSR_DISC: /* disconnect */ if (slp->sl_msgphase == MSGPH_NULL && (satgo & CT_SAT_GOING) != 0) { /* * emulate disconnect msg */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); scsi_low_msgin(slp, ti, MSG_DISCON); } scsi_low_disconnected(slp, ti); return 1; default: break; } } ct_phase_error(ct, scsi_status); return 1; } Index: projects/sendfile/sys/dev/ct/ct_isa.c =================================================================== --- projects/sendfile/sys/dev/ct/ct_isa.c (revision 274764) +++ projects/sendfile/sys/dev/ct/ct_isa.c (revision 274765) @@ -1,390 +1,382 @@ /* $NecBSD: ct_isa.c,v 1.6 1999/07/26 06:32:01 honda Exp $ */ #include __FBSDID("$FreeBSD$"); /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998 * NetBSD/pc98 porting staff. 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. */ #define SCSIBUS_RESCAN #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define BSHW_IOSZ 0x08 #define BSHW_IOBASE 0xcc0 #define BSHW_MEMSZ (PAGE_SIZE * 2) static int ct_isa_match(device_t); static int ct_isa_attach(device_t); static int ct_space_map(device_t, struct bshw *, struct resource **, struct resource **); static void ct_space_unmap(device_t, struct ct_softc *); static struct bshw *ct_find_hw(device_t); static void ct_dmamap(void *, bus_dma_segment_t *, int, int); static void ct_isa_bus_access_weight(struct ct_bus_access_handle *); static void ct_isa_dmasync_before(struct ct_softc *); static void ct_isa_dmasync_after(struct ct_softc *); struct ct_isa_softc { struct ct_softc sc_ct; struct bshw_softc sc_bshw; }; static struct isa_pnp_id ct_pnp_ids[] = { { 0x0100e7b1, "Logitec LHA-301" }, { 0x110154dc, "I-O DATA SC-98III" }, { 0x4120acb4, "MELCO IFC-NN" }, { 0, NULL } }; static device_method_t ct_isa_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ct_isa_match), DEVMETHOD(device_attach, ct_isa_attach), { 0, 0 } }; static driver_t ct_isa_driver = { "ct", ct_isa_methods, sizeof(struct ct_isa_softc), }; static devclass_t ct_devclass; DRIVER_MODULE(ct, isa, ct_isa_driver, ct_devclass, 0, 0); static int ct_isa_match(device_t dev) { struct bshw *hw; struct resource *port_res, *mem_res; struct ct_bus_access_handle ch; int rv; if (ISA_PNP_PROBE(device_get_parent(dev), dev, ct_pnp_ids) == ENXIO) return ENXIO; switch (isa_get_logicalid(dev)) { case 0x0100e7b1: /* LHA-301 */ case 0x110154dc: /* SC-98III */ case 0x4120acb4: /* IFC-NN */ /* XXX - force to SMIT mode */ device_set_flags(dev, device_get_flags(dev) | 0x40000); break; } if (isa_get_port(dev) == -1) bus_set_resource(dev, SYS_RES_IOPORT, 0, BSHW_IOBASE, BSHW_IOSZ); if ((hw = ct_find_hw(dev)) == NULL) return ENXIO; if (ct_space_map(dev, hw, &port_res, &mem_res) != 0) return ENXIO; bzero(&ch, sizeof(ch)); - ch.ch_iot = rman_get_bustag(port_res); - ch.ch_ioh = rman_get_bushandle(port_res), + ch.ch_io = port_res; ch.ch_bus_weight = ct_isa_bus_access_weight; rv = ctprobesubr(&ch, 0, BSHW_DEFAULT_HOSTID, BSHW_DEFAULT_CHIPCLK, NULL); if (rv != 0) { struct bshw_softc bshw_tab; struct bshw_softc *bs = &bshw_tab; memset(bs, 0, sizeof(*bs)); bshw_read_settings(&ch, bs); bus_set_resource(dev, SYS_RES_IRQ, 0, bs->sc_irq, 1); bus_set_resource(dev, SYS_RES_DRQ, 0, bs->sc_drq, 1); } bus_release_resource(dev, SYS_RES_IOPORT, 0, port_res); if (mem_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, 0, mem_res); if (rv != 0) - return 0; + return (BUS_PROBE_DEFAULT); return ENXIO; } static int ct_isa_attach(device_t dev) { struct ct_isa_softc *pct = device_get_softc(dev); struct ct_softc *ct = &pct->sc_ct; struct ct_bus_access_handle *chp = &ct->sc_ch; struct scsi_low_softc *slp = &ct->sc_sclow; struct bshw_softc *bs = &pct->sc_bshw; struct bshw *hw; int irq_rid, drq_rid, chiprev; u_int8_t *vaddr; bus_addr_t addr; - intrmask_t s; hw = ct_find_hw(dev); if (ct_space_map(dev, hw, &ct->port_res, &ct->mem_res) != 0) { device_printf(dev, "bus io mem map failed\n"); return ENXIO; } - bzero(chp, sizeof(*chp)); - chp->ch_iot = rman_get_bustag(ct->port_res); - chp->ch_ioh = rman_get_bushandle(ct->port_res); - if (ct->mem_res) { - chp->ch_memt = rman_get_bustag(ct->mem_res); - chp->ch_memh = rman_get_bushandle(ct->mem_res); - } + chp->ch_io = ct->port_res; + chp->ch_mem = ct->mem_res; chp->ch_bus_weight = ct_isa_bus_access_weight; irq_rid = 0; ct->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &irq_rid, RF_ACTIVE); drq_rid = 0; ct->drq_res = bus_alloc_resource_any(dev, SYS_RES_DRQ, &drq_rid, RF_ACTIVE); if (ct->irq_res == NULL || ct->drq_res == NULL) { ct_space_unmap(dev, ct); return ENXIO; } if (ctprobesubr(chp, 0, BSHW_DEFAULT_HOSTID, BSHW_DEFAULT_CHIPCLK, &chiprev) == 0) { device_printf(dev, "hardware missing\n"); ct_space_unmap(dev, ct); return ENXIO; } /* setup DMA map */ if (bus_dma_tag_create(NULL, 1, 0, BUS_SPACE_MAXADDR_24BIT, BUS_SPACE_MAXADDR, NULL, NULL, MAXBSIZE, 1, BUS_SPACE_MAXSIZE_32BIT, BUS_DMA_ALLOCNOW, NULL, NULL, &ct->sc_dmat) != 0) { device_printf(dev, "can't set up ISA DMA map\n"); ct_space_unmap(dev, ct); return ENXIO; } if (bus_dmamem_alloc(ct->sc_dmat, (void **)&vaddr, BUS_DMA_NOWAIT, &ct->sc_dmamapt) != 0) { device_printf(dev, "can't set up ISA DMA map\n"); ct_space_unmap(dev, ct); return ENXIO; } bus_dmamap_load(ct->sc_dmat, ct->sc_dmamapt, vaddr, MAXBSIZE, ct_dmamap, &addr, BUS_DMA_NOWAIT); /* setup machdep softc */ bs->sc_hw = hw; bs->sc_io_control = 0; bs->sc_bounce_phys = (u_int8_t *)addr; bs->sc_bounce_addr = vaddr; bs->sc_bounce_size = MAXBSIZE; bs->sc_minphys = (1 << 24); bs->sc_dmasync_before = ct_isa_dmasync_before; bs->sc_dmasync_after = ct_isa_dmasync_after; bshw_read_settings(chp, bs); /* setup ct driver softc */ ct->ct_hw = bs; ct->ct_dma_xfer_start = bshw_dma_xfer_start; ct->ct_pio_xfer_start = bshw_smit_xfer_start; ct->ct_dma_xfer_stop = bshw_dma_xfer_stop; ct->ct_pio_xfer_stop = bshw_smit_xfer_stop; ct->ct_bus_reset = bshw_bus_reset; ct->ct_synch_setup = bshw_synch_setup; ct->sc_xmode = CT_XMODE_DMA; - if (chp->ch_memh != NULL) + if (chp->ch_mem != NULL) ct->sc_xmode |= CT_XMODE_PIO; ct->sc_chiprev = chiprev; switch (chiprev) { case CT_WD33C93: /* s = "WD33C93"; */ ct->sc_chipclk = 8; break; case CT_WD33C93_A: if (DVCFG_MAJOR(device_get_flags(dev)) > 0) { /* s = "AM33C93_A"; */ ct->sc_chipclk = 20; ct->sc_chiprev = CT_AM33C93_A; } else { /* s = "WD33C93_A"; */ ct->sc_chipclk = 10; } break; case CT_AM33C93_A: /* s = "AM33C93_A"; */ ct->sc_chipclk = 20; break; default: case CT_WD33C93_B: /* s = "WD33C93_B"; */ ct->sc_chipclk = 20; break; } #if 0 printf("%s: chiprev %s chipclk %d MHz\n", slp->sl_dev.dv_xname, s, ct->sc_chipclk); #endif slp->sl_dev = dev; slp->sl_hostid = bs->sc_hostid; slp->sl_cfgflags = device_get_flags(dev); + mtx_init(&slp->sl_lock, "ct", NULL, MTX_DEF); - s = splcam(); ctattachsubr(ct); - splx(s); - if (bus_setup_intr(dev, ct->irq_res, INTR_TYPE_CAM, - NULL, (driver_intr_t *)ctintr, ct, &ct->sc_ih)) { + if (bus_setup_intr(dev, ct->irq_res, INTR_TYPE_CAM | INTR_MPSAFE, + NULL, ctintr, ct, &ct->sc_ih)) { ct_space_unmap(dev, ct); return ENXIO; } return 0; } static struct bshw * ct_find_hw(device_t dev) { return DVCFG_HW(&bshw_hwsel, DVCFG_MAJOR(device_get_flags(dev))); } static int ct_space_map(device_t dev, struct bshw *hw, struct resource **iohp, struct resource **memhp) { int port_rid, mem_rid; *memhp = NULL; port_rid = 0; - *iohp = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid, 0, ~0, + *iohp = bus_alloc_resource(dev, SYS_RES_IOPORT, &port_rid, 0ul, ~0ul, BSHW_IOSZ, RF_ACTIVE); if (*iohp == NULL) return ENXIO; if ((hw->hw_flags & BSHW_SMFIFO) == 0 || isa_get_maddr(dev) == -1) return 0; mem_rid = 0; - *memhp = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid, 0, ~0, + *memhp = bus_alloc_resource(dev, SYS_RES_MEMORY, &mem_rid, 0ul, ~0ul, BSHW_MEMSZ, RF_ACTIVE); if (*memhp == NULL) { bus_release_resource(dev, SYS_RES_IOPORT, port_rid, *iohp); return ENXIO; } return 0; } static void ct_space_unmap(device_t dev, struct ct_softc *ct) { if (ct->port_res != NULL) bus_release_resource(dev, SYS_RES_IOPORT, 0, ct->port_res); if (ct->mem_res != NULL) bus_release_resource(dev, SYS_RES_MEMORY, 0, ct->mem_res); if (ct->irq_res != NULL) bus_release_resource(dev, SYS_RES_IRQ, 0, ct->irq_res); if (ct->drq_res != NULL) bus_release_resource(dev, SYS_RES_DRQ, 0, ct->drq_res); } static void ct_dmamap(void *arg, bus_dma_segment_t *seg, int nseg, int error) { bus_addr_t *addr = (bus_addr_t *)arg; *addr = seg->ds_addr; } static void ct_isa_bus_access_weight(struct ct_bus_access_handle *chp) { outb(0x5f, 0); } static void ct_isa_dmasync_before(struct ct_softc *ct) { if (need_pre_dma_flush) wbinvd(); } static void ct_isa_dmasync_after(struct ct_softc *ct) { if (need_post_dma_flush) invd(); } Index: projects/sendfile/sys/dev/ct/ct_machdep.h =================================================================== --- projects/sendfile/sys/dev/ct/ct_machdep.h (revision 274764) +++ projects/sendfile/sys/dev/ct/ct_machdep.h (revision 274765) @@ -1,196 +1,186 @@ /* $FreeBSD$ */ /* $NecBSD: ct_machdep.h,v 1.4.12.2 2001/06/20 06:13:34 honda Exp $ */ /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #ifndef _CT_MACHDEP_H_ #define _CT_MACHDEP_H_ #include "opt_ct.h" /* * Principal rules: * 1) do not use bus_space_write/read_X directly in ct.c. * 2) do not use port offset defs directly in ct.c. */ /* special weight if requried */ #ifdef CT_BUS_WEIGHT #undef CT_BUS_WEIGHT #define CT_BUS_WEIGHT(chp) \ { \ if ((chp)->ch_bus_weight != NULL) \ (chp)->ch_bus_weight((chp)); \ } #else /* !CT_BUS_WEIGHT */ #define CT_BUS_WEIGHT(chp) #endif /* !CT_BUS_WEIGHT */ /* port offset */ #ifndef CT_USE_RELOCATE_OFFSET #define addr_port 0 #define stat_port 0 #define ctrl_port 2 #define cmd_port 4 #else /* CT_USE_RELOCATE_OFFSET */ #define addr_port ((chp)->ch_offset[0]) #define stat_port ((chp)->ch_offset[1]) #define ctrl_port ((chp)->ch_offset[2]) #define cmd_port ((chp)->ch_offset[3]) #endif /* CT_USE_RELOCATE_OFFSET */ /* * All port accesses primitive methods */ static __inline u_int8_t ct_stat_read_1 (struct ct_bus_access_handle *); static __inline u_int8_t ct_cmdp_read_1 (struct ct_bus_access_handle *); static __inline void ct_cmdp_write_1 (struct ct_bus_access_handle *, u_int8_t); static __inline u_int8_t ct_cr_read_1 (struct ct_bus_access_handle *, bus_addr_t); static __inline void ct_cr_write_1 (struct ct_bus_access_handle *, bus_addr_t, u_int8_t); static __inline void ct_write_cmds (struct ct_bus_access_handle *, u_int8_t *, int); static __inline u_int cthw_get_count (struct ct_bus_access_handle *); static __inline void cthw_set_count (struct ct_bus_access_handle *, u_int); static __inline u_int8_t ct_stat_read_1(struct ct_bus_access_handle *chp) { u_int8_t regv; - regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, stat_port); + regv = bus_read_1(chp->ch_io, stat_port); CT_BUS_WEIGHT(chp) return regv; } static __inline void cthw_set_count(struct ct_bus_access_handle *chp, u_int count) { - bus_space_tag_t bst = chp->ch_iot; - bus_space_handle_t bsh = chp->ch_ioh; - bus_space_write_1(bst, bsh, addr_port, wd3s_cnt); + bus_write_1(chp->ch_io, addr_port, wd3s_cnt); CT_BUS_WEIGHT(chp) - bus_space_write_1(bst, bsh, ctrl_port, count >> 16); + bus_write_1(chp->ch_io, ctrl_port, count >> 16); CT_BUS_WEIGHT(chp) - bus_space_write_1(bst, bsh, ctrl_port, count >> 8); + bus_write_1(chp->ch_io, ctrl_port, count >> 8); CT_BUS_WEIGHT(chp) - bus_space_write_1(bst, bsh, ctrl_port, count); + bus_write_1(chp->ch_io, ctrl_port, count); CT_BUS_WEIGHT(chp) } static __inline u_int cthw_get_count(struct ct_bus_access_handle *chp) { - bus_space_tag_t bst = chp->ch_iot; - bus_space_handle_t bsh = chp->ch_ioh; u_int count; - bus_space_write_1(bst, bsh, addr_port, wd3s_cnt); + bus_write_1(chp->ch_io, addr_port, wd3s_cnt); CT_BUS_WEIGHT(chp) - count = (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 16); + count = (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 16); CT_BUS_WEIGHT(chp) - count += (((u_int) bus_space_read_1(bst, bsh, ctrl_port)) << 8); + count += (((u_int) bus_read_1(chp->ch_io, ctrl_port)) << 8); CT_BUS_WEIGHT(chp) - count += ((u_int) bus_space_read_1(bst, bsh, ctrl_port)); + count += ((u_int) bus_read_1(chp->ch_io, ctrl_port)); CT_BUS_WEIGHT(chp) return count; } static __inline void ct_write_cmds(struct ct_bus_access_handle *chp, u_int8_t *cmd, int len) { - bus_space_tag_t bst = chp->ch_iot; - bus_space_handle_t bsh = chp->ch_ioh; int i; - bus_space_write_1(bst, bsh, addr_port, wd3s_cdb); + bus_write_1(chp->ch_io, addr_port, wd3s_cdb); CT_BUS_WEIGHT(chp) for (i = 0; i < len; i ++) { - bus_space_write_1(bst, bsh, ctrl_port, cmd[i]); + bus_write_1(chp->ch_io, ctrl_port, cmd[i]); CT_BUS_WEIGHT(chp) } } static __inline u_int8_t ct_cr_read_1(struct ct_bus_access_handle *chp, bus_addr_t offs) { - bus_space_tag_t bst = chp->ch_iot; - bus_space_handle_t bsh = chp->ch_ioh; u_int8_t regv; - bus_space_write_1(bst, bsh, addr_port, offs); + bus_write_1(chp->ch_io, addr_port, offs); CT_BUS_WEIGHT(chp) - regv = bus_space_read_1(bst, bsh, ctrl_port); + regv = bus_read_1(chp->ch_io, ctrl_port); CT_BUS_WEIGHT(chp) return regv; } static __inline void ct_cr_write_1(struct ct_bus_access_handle *chp, bus_addr_t offs, u_int8_t val) { - bus_space_tag_t bst = chp->ch_iot; - bus_space_handle_t bsh = chp->ch_ioh; - bus_space_write_1(bst, bsh, addr_port, offs); + bus_write_1(chp->ch_io, addr_port, offs); CT_BUS_WEIGHT(chp) - bus_space_write_1(bst, bsh, ctrl_port, val); + bus_write_1(chp->ch_io, ctrl_port, val); CT_BUS_WEIGHT(chp) } static __inline u_int8_t ct_cmdp_read_1(struct ct_bus_access_handle *chp) { u_int8_t regv; - regv = bus_space_read_1(chp->ch_iot, chp->ch_ioh, cmd_port); + regv = bus_read_1(chp->ch_io, cmd_port); CT_BUS_WEIGHT(chp) return regv; } static __inline void ct_cmdp_write_1(struct ct_bus_access_handle *chp, u_int8_t val) { - bus_space_write_1(chp->ch_iot, chp->ch_ioh, cmd_port, val); + bus_write_1(chp->ch_io, cmd_port, val); CT_BUS_WEIGHT(chp) } #endif /* !_CT_MACHDEP_H_ */ Index: projects/sendfile/sys/dev/ct/ctvar.h =================================================================== --- projects/sendfile/sys/dev/ct/ctvar.h (revision 274764) +++ projects/sendfile/sys/dev/ct/ctvar.h (revision 274765) @@ -1,136 +1,129 @@ /* $FreeBSD$ */ /* $NecBSD: ctvar.h,v 1.4.14.3 2001/06/20 06:13:34 honda Exp $ */ /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #ifndef _CTVAR_H_ #define _CTVAR_H_ /* * ctvar.h * Generic wd33c93 chip driver's definitions */ /***************************************************************** * Host adapter structure *****************************************************************/ struct ct_bus_access_handle { - bus_space_tag_t ch_iot; /* core chip ctrl port tag */ - bus_space_tag_t ch_delayt; /* delay port tag */ - bus_space_tag_t ch_datat; /* data port tag (pio) */ - bus_space_tag_t ch_memt; /* data port tag (shm) */ + struct resource *ch_io; /* core chip ctrl port */ + struct resource *ch_mem; /* data port (shm) */ - bus_space_handle_t ch_ioh; - bus_space_handle_t ch_delaybah; - bus_space_handle_t ch_datah; - bus_space_handle_t ch_memh; - void (*ch_bus_weight)(struct ct_bus_access_handle *); #ifdef CT_USE_RELOCATE_OFFSET bus_addr_t ch_offset[4]; #endif /* CT_USE_RELOCATE_OFFSET */ }; struct ct_softc { struct scsi_low_softc sc_sclow; /* generic data */ struct ct_bus_access_handle sc_ch; /* bus access handle */ struct resource *port_res; struct resource *mem_res; struct resource *irq_res; struct resource *drq_res; bus_dma_tag_t sc_dmat; /* data DMA tag */ bus_dmamap_t sc_dmamapt; /* data DMAMAP tag */ void *sc_ih; int sc_chiprev; /* chip version */ #define CT_WD33C93 0x00000 #define CT_WD33C93_A 0x10000 #define CT_AM33C93_A 0x10001 #define CT_WD33C93_B 0x20000 #define CT_WD33C93_C 0x30000 int sc_xmode; #define CT_XMODE_PIO 1 #define CT_XMODE_DMA 2 int sc_dma; /* dma transfer start */ #define CT_DMA_PIOSTART 1 #define CT_DMA_DMASTART 2 int sc_satgo; /* combination cmd start */ #define CT_SAT_GOING 1 int sc_tmaxcnt; int sc_atten; /* attention */ u_int8_t sc_creg; /* control register value */ int sc_chipclk; /* chipclk 0, 10, 15, 20 */ struct ct_synch_data { u_int cs_period; u_int cs_syncr; } *sc_sdp; /* synchronous data table pt */ struct ct_synch_data sc_default_sdt[16]; /* * Machdep stuff. */ void *ct_hw; /* point to bshw_softc etc ... */ int (*ct_dma_xfer_start)(struct ct_softc *); int (*ct_pio_xfer_start)(struct ct_softc *); void (*ct_dma_xfer_stop)(struct ct_softc *); void (*ct_pio_xfer_stop)(struct ct_softc *); void (*ct_bus_reset)(struct ct_softc *); void (*ct_synch_setup)(struct ct_softc *, struct targ_info *); }; /***************************************************************** * Lun information *****************************************************************/ struct ct_targ_info { struct targ_info cti_ti; u_int8_t cti_syncreg; }; /***************************************************************** * PROTO *****************************************************************/ int ctprobesubr(struct ct_bus_access_handle *, u_int, int, u_int, int *); void ctattachsubr(struct ct_softc *); -int ctintr(void *); +void ctintr(void *); #endif /* !_CTVAR_H_ */ Index: projects/sendfile/sys/dev/ncv/ncr53c500.c =================================================================== --- projects/sendfile/sys/dev/ncv/ncr53c500.c (revision 274764) +++ projects/sendfile/sys/dev/ncv/ncr53c500.c (revision 274765) @@ -1,1289 +1,1238 @@ /* $NecBSD: ncr53c500.c,v 1.30.12.3 2001/06/26 07:31:41 honda Exp $ */ /* $NetBSD$ */ #define NCV_DEBUG #define NCV_STATICS #define NCV_IO_CONTROL_FLAGS (0) /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include +#include #include #include #include #include #include #include #include #include #define NCV_MAX_DATA_SIZE (64 * 1024) #define NCV_DELAY_MAX (2 * 1000 * 1000) #define NCV_DELAY_INTERVAL (1) #define NCV_PADDING_SIZE (32) /*************************************************** * IO control ***************************************************/ #define NCV_READ_INTERRUPTS_DRIVEN 0x0001 #define NCV_WRITE_INTERRUPTS_DRIVEN 0x0002 #define NCV_ENABLE_FAST_SCSI 0x0010 #define NCV_FAST_INTERRUPTS 0x0100 u_int ncv_io_control = NCV_IO_CONTROL_FLAGS; int ncv_data_read_bytes = 4096; int ncv_data_write_bytes = 4096; /*************************************************** * DEBUG ***************************************************/ #ifdef NCV_DEBUG static int ncv_debug; #endif /* NCV_DEBUG */ #ifdef NCV_STATICS static struct ncv_statics { int disconnect; int reselect; } ncv_statics; #endif /* NCV_STATICS */ /*************************************************** * DEVICE STRUCTURE ***************************************************/ extern struct cfdriver ncv_cd; /************************************************************** * DECLARE **************************************************************/ /* static */ static void ncv_pio_read(struct ncv_softc *, u_int8_t *, u_int); static void ncv_pio_write(struct ncv_softc *, u_int8_t *, u_int); static int ncv_msg(struct ncv_softc *, struct targ_info *, u_int); static int ncv_reselected(struct ncv_softc *); static int ncv_disconnected(struct ncv_softc *, struct targ_info *); -static __inline void ncvhw_set_count(bus_space_tag_t, bus_space_handle_t, int); -static __inline u_int ncvhw_get_count(bus_space_tag_t, bus_space_handle_t); -static __inline void ncvhw_select_register_0(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static __inline void ncvhw_select_register_1(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static __inline void ncvhw_fpush(bus_space_tag_t, bus_space_handle_t, u_int8_t *, int); +static __inline void ncvhw_set_count(struct resource *, int); +static __inline u_int ncvhw_get_count(struct resource *); +static __inline void ncvhw_select_register_0(struct resource *, struct ncv_hw *); +static __inline void ncvhw_select_register_1(struct resource *, struct ncv_hw *); +static __inline void ncvhw_fpush(struct resource *, u_int8_t *, int); static void ncv_pdma_end(struct ncv_softc *sc, struct targ_info *); static int ncv_world_start(struct ncv_softc *, int); static void ncvhw_bus_reset(struct ncv_softc *); -static void ncvhw_reset(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static int ncvhw_check(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); -static void ncvhw_init(bus_space_tag_t, bus_space_handle_t, struct ncv_hw *); +static void ncvhw_reset(struct resource *, struct ncv_hw *); +static int ncvhw_check(struct resource *, struct ncv_hw *); +static void ncvhw_init(struct resource *, struct ncv_hw *); static int ncvhw_start_selection(struct ncv_softc *sc, struct slccb *); static void ncvhw_attention(struct ncv_softc *); static int ncv_ccb_nexus_establish(struct ncv_softc *); static int ncv_lun_nexus_establish(struct ncv_softc *); static int ncv_target_nexus_establish(struct ncv_softc *); static int ncv_targ_init(struct ncv_softc *, struct targ_info *, int); static int ncv_catch_intr(struct ncv_softc *); #ifdef NCV_POWER_CONTROL static int ncvhw_power(struct ncv_softc *, u_int); #endif /* NCV_POWER_CONTROL */ static __inline void ncv_setup_and_start_pio(struct ncv_softc *, u_int); struct scsi_low_funcs ncv_funcs = { SC_LOW_INIT_T ncv_world_start, SC_LOW_BUSRST_T ncvhw_bus_reset, SC_LOW_TARG_INIT_T ncv_targ_init, SC_LOW_LUN_INIT_T NULL, SC_LOW_SELECT_T ncvhw_start_selection, SC_LOW_NEXUS_T ncv_lun_nexus_establish, SC_LOW_NEXUS_T ncv_ccb_nexus_establish, SC_LOW_ATTEN_T ncvhw_attention, SC_LOW_MSG_T ncv_msg, SC_LOW_TIMEOUT_T NULL, SC_LOW_POLL_T ncvintr, NULL, /* SC_LOW_POWER_T ncvhw_power, */ }; /************************************************************** * hwfuncs **************************************************************/ static __inline void -ncvhw_select_register_0(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_select_register_0(struct resource *res, struct ncv_hw *hw) { - bus_space_write_1(iot, ioh, cr0_cfg4, hw->hw_cfg4); + bus_write_1(res, cr0_cfg4, hw->hw_cfg4); } static __inline void -ncvhw_select_register_1(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_select_register_1(struct resource *res, struct ncv_hw *hw) { - bus_space_write_1(iot, ioh, cr1_cfg5, hw->hw_cfg5); + bus_write_1(res, cr1_cfg5, hw->hw_cfg5); } static __inline void -ncvhw_fpush(iot, ioh, buf, len) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int8_t *buf; - int len; +ncvhw_fpush(struct resource *res, u_int8_t *buf, int len) { int ptr; for (ptr = 0; ptr < len; ptr ++) - bus_space_write_1(iot, ioh, cr0_sfifo, buf[ptr]); + bus_write_1(res, cr0_sfifo, buf[ptr]); } static __inline void -ncvhw_set_count(iot, ioh, count) - bus_space_tag_t iot; - bus_space_handle_t ioh; - int count; +ncvhw_set_count(struct resource *res, int count) { - bus_space_write_1(iot, ioh, cr0_tclsb, (u_int8_t) count); - bus_space_write_1(iot, ioh, cr0_tcmsb, (u_int8_t) (count >> NBBY)); - bus_space_write_1(iot, ioh, cr0_tchsb, (u_int8_t) (count >> (NBBY * 2))); + bus_write_1(res, cr0_tclsb, (u_int8_t) count); + bus_write_1(res, cr0_tcmsb, (u_int8_t) (count >> NBBY)); + bus_write_1(res, cr0_tchsb, (u_int8_t) (count >> (NBBY * 2))); } static __inline u_int -ncvhw_get_count(iot, ioh) - bus_space_tag_t iot; - bus_space_handle_t ioh; +ncvhw_get_count(struct resource *res) { u_int count; - count = (u_int) bus_space_read_1(iot, ioh, cr0_tclsb); - count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tcmsb)) << NBBY; - count |= ((u_int) bus_space_read_1(iot, ioh, cr0_tchsb)) << (NBBY * 2); + count = (u_int) bus_read_1(res, cr0_tclsb); + count |= ((u_int) bus_read_1(res, cr0_tcmsb)) << NBBY; + count |= ((u_int) bus_read_1(res, cr0_tchsb)) << (NBBY * 2); return count; } static int -ncvhw_check(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_check(struct resource *res, struct ncv_hw *hw) { u_int8_t stat; - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); - if (bus_space_read_1(iot, ioh, cr0_cmd) != (CMD_NOP | CMD_DMA)) + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_cmd, CMD_NOP | CMD_DMA); + if (bus_read_1(res, cr0_cmd) != (CMD_NOP | CMD_DMA)) { #ifdef NCV_DEBUG printf("ncv: cr0_cmd CMD_NOP|CMD_DMA failed\n"); #endif /* NCV_DEBUG */ return ENODEV; } - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - if (bus_space_read_1(iot, ioh, cr0_cmd) != CMD_NOP) + bus_write_1(res, cr0_cmd, CMD_NOP); + if (bus_read_1(res, cr0_cmd) != CMD_NOP) { #ifdef NCV_DEBUG printf("ncv: cr0_cmd CMD_NOP failed\n"); #endif /* NCV_DEBUG */ return ENODEV; } /* hardware reset */ - ncvhw_reset(iot, ioh, hw); - ncvhw_init(iot, ioh, hw); + ncvhw_reset(res, hw); + ncvhw_init(res, hw); /* bus reset */ - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_RSTSCSI); + bus_write_1(res, cr0_cmd, CMD_NOP | CMD_DMA); DELAY(100 * 1000); /* check response */ - bus_space_read_1(iot, ioh, cr0_stat); - stat = bus_space_read_1(iot, ioh, cr0_istat); + bus_read_1(res, cr0_stat); + stat = bus_read_1(res, cr0_istat); DELAY(1000); if (((stat & INTR_SBR) == 0) || - (bus_space_read_1(iot, ioh, cr0_istat) & INTR_SBR)) + (bus_read_1(res, cr0_istat) & INTR_SBR)) { #ifdef NCV_DEBUG printf("ncv: cr0_istat SCSI BUS RESET failed\n"); #endif /* NCV_DEBUG */ return ENODEV; } return 0; } static void -ncvhw_reset(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_reset(struct resource *res, struct ncv_hw *hw) { - ncvhw_select_register_0(iot, ioh, hw); + ncvhw_select_register_0(res, hw); /* dummy cmd twice */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); /* chip reset */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTCHIP); + bus_write_1(res, cr0_cmd, CMD_RSTCHIP); /* again dummy cmd twice */ - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); + bus_write_1(res, cr0_cmd, CMD_NOP); } static void -ncvhw_init(iot, ioh, hw) - bus_space_tag_t iot; - bus_space_handle_t ioh; - struct ncv_hw *hw; +ncvhw_init(struct resource *res, struct ncv_hw *hw) { - ncvhw_select_register_0(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr0_clk, hw->hw_clk); - bus_space_write_1(iot, ioh, cr0_srtout, SEL_TOUT); - bus_space_write_1(iot, ioh, cr0_period, 0); - bus_space_write_1(iot, ioh, cr0_offs, 0); + ncvhw_select_register_0(res, hw); + bus_write_1(res, cr0_clk, hw->hw_clk); + bus_write_1(res, cr0_srtout, SEL_TOUT); + bus_write_1(res, cr0_period, 0); + bus_write_1(res, cr0_offs, 0); - bus_space_write_1(iot, ioh, cr0_cfg1, hw->hw_cfg1); - bus_space_write_1(iot, ioh, cr0_cfg2, hw->hw_cfg2); - bus_space_write_1(iot, ioh, cr0_cfg3, hw->hw_cfg3); - bus_space_write_1(iot, ioh, cr0_tchsb, 0); + bus_write_1(res, cr0_cfg1, hw->hw_cfg1); + bus_write_1(res, cr0_cfg2, hw->hw_cfg2); + bus_write_1(res, cr0_cfg3, hw->hw_cfg3); + bus_write_1(res, cr0_tchsb, 0); - ncvhw_select_register_1(iot, ioh, hw); - bus_space_write_1(iot, ioh, cr1_fstat, 0x0); - bus_space_write_1(iot, ioh, cr1_pflag, 0x0); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE); + ncvhw_select_register_1(res, hw); + bus_write_1(res, cr1_fstat, 0x0); + bus_write_1(res, cr1_pflag, 0x0); + bus_write_1(res, cr1_atacmd, ATACMD_ENGAGE); - ncvhw_select_register_0(iot, ioh, hw); + ncvhw_select_register_0(res, hw); } #ifdef NCV_POWER_CONTROL static int ncvhw_power(sc, flags) struct ncv_softc *sc; u_int flags; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; if (flags == SCSI_LOW_POWDOWN) { device_printf(slp->sl_dev, "power down\n"); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_POWDOWN); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_atacmd, ATACMD_POWDOWN); } else { switch (sc->sc_rstep) { case 0: device_printf(slp->sl_dev, "resume step O\n"); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_atacmd, ATACMD_ENGAGE); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_atacmd, ATACMD_ENGAGE); break; case 1: device_printf(slp->sl_dev, "resume step I\n"); - ncvhw_reset(iot, ioh, &sc->sc_hw); - ncvhw_init(iot, ioh, &sc->sc_hw); + ncvhw_reset(res, &sc->sc_hw); + ncvhw_init(res, &sc->sc_hw); break; } } return 0; } #endif /* NCV_POWER_CONTROL */ /************************************************************** * scsi low interface **************************************************************/ static void ncvhw_attention(sc) struct ncv_softc *sc; { - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, CMD_SETATN); + bus_write_1(sc->port_res, cr0_cmd, CMD_SETATN); DELAY(10); } static void ncvhw_bus_reset(sc) struct ncv_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_RSTSCSI); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_NOP | CMD_DMA); + ncvhw_select_register_0(sc->port_res, &sc->sc_hw); + bus_write_1(sc->port_res, cr0_cmd, CMD_FLUSH); + bus_write_1(sc->port_res, cr0_cmd, CMD_RSTSCSI); + bus_write_1(sc->port_res, cr0_cmd, CMD_NOP | CMD_DMA); } static int ncvhw_start_selection(sc, cb) struct ncv_softc *sc; struct slccb *cb; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti = cb->ti; - int s, len; + int len; u_int flags; u_int8_t cmd; sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; sc->sc_compseq = 0; if (scsi_low_is_msgout_continue(ti, SCSI_LOW_MSG_IDENTIFY) == 0) { cmd = CMD_SELATN; sc->sc_selstop = 0; flags = SCSI_LOW_MSGOUT_UNIFY | SCSI_LOW_MSGOUT_INIT; } else if (scsi_low_is_msgout_continue(ti, SCSI_LOW_MSG_IDENTIFY | SCSI_LOW_MSG_SIMPLE_QTAG) == 0) { cmd = CMD_SELATN3; sc->sc_selstop = 0; flags = SCSI_LOW_MSGOUT_UNIFY | SCSI_LOW_MSGOUT_INIT; } else { cmd = CMD_SELATNS; sc->sc_selstop = 1; flags = SCSI_LOW_MSGOUT_INIT; } - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0) + ncvhw_select_register_0(res, &sc->sc_hw); + if ((bus_read_1(res, cr0_stat) & STAT_INT) != 0) return SCSI_LOW_START_FAIL; ncv_target_nexus_establish(sc); len = scsi_low_msgout(slp, ti, flags); if (sc->sc_selstop == 0) scsi_low_cmd(slp, ti); - s = splhigh(); - if ((bus_space_read_1(iot, ioh, cr0_stat) & STAT_INT) != 0) - { - splx(s); + if ((bus_read_1(res, cr0_stat) & STAT_INT) != 0) return SCSI_LOW_START_FAIL; - } - bus_space_write_1(iot, ioh, cr0_dstid, ti->ti_id); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len); + bus_write_1(res, cr0_dstid, ti->ti_id); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + ncvhw_fpush(res, ti->ti_msgoutstr, len); if (sc->sc_selstop == 0) { - ncvhw_fpush(iot, ioh, + ncvhw_fpush(res, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); } - bus_space_write_1(iot, ioh, cr0_cmd, cmd); - splx(s); + bus_write_1(res, cr0_cmd, cmd); SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART); return SCSI_LOW_START_OK; } static int ncv_world_start(sc, fdone) struct ncv_softc *sc; int fdone; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; u_int8_t stat; if ((slp->sl_cfgflags & CFG_NOPARITY) == 0) sc->sc_hw.hw_cfg1 |= C1_PARENB; else sc->sc_hw.hw_cfg1 &= ~C1_PARENB; - ncvhw_reset(iot, ioh, &sc->sc_hw); - ncvhw_init(iot, ioh, &sc->sc_hw); + ncvhw_reset(res, &sc->sc_hw); + ncvhw_init(res, &sc->sc_hw); scsi_low_bus_reset(slp); - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_stat); - stat = bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat); + ncvhw_select_register_0(res, &sc->sc_hw); + bus_read_1(res, cr0_stat); + stat = bus_read_1(res, cr0_istat); DELAY(1000); if (((stat & INTR_SBR) == 0) || - (bus_space_read_1(sc->sc_iot, sc->sc_ioh, cr0_istat) & INTR_SBR)) + (bus_read_1(res, cr0_istat) & INTR_SBR)) return ENODEV; return 0; } static int ncv_msg(sc, ti, msg) struct ncv_softc *sc; struct targ_info *ti; u_int msg; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct ncv_targ_info *nti = (void *) ti; u_int hwcycle, period; if ((msg & SCSI_LOW_MSG_WIDE) != 0) { if (ti->ti_width != SCSI_LOW_BUS_WIDTH_8) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; return EINVAL; } return 0; } if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; period = ti->ti_maxsynch.period; hwcycle = (sc->sc_hw.hw_clk == 0) ? 40 : (5 * sc->sc_hw.hw_clk); hwcycle = 1000 / hwcycle; if (period < 200 / 4 && period >= 100 / 4) nti->nti_reg_cfg3 |= sc->sc_hw.hw_cfg3_fscsi; else nti->nti_reg_cfg3 &= ~sc->sc_hw.hw_cfg3_fscsi; period = ((period * 40 / hwcycle) + 5) / 10; nti->nti_reg_period = period & 0x1f; nti->nti_reg_offset = ti->ti_maxsynch.offset; - bus_space_write_1(iot, ioh, cr0_period, nti->nti_reg_period); - bus_space_write_1(iot, ioh, cr0_offs, nti->nti_reg_offset); - bus_space_write_1(iot, ioh, cr0_cfg3, nti->nti_reg_cfg3); + bus_write_1(res, cr0_period, nti->nti_reg_period); + bus_write_1(res, cr0_offs, nti->nti_reg_offset); + bus_write_1(res, cr0_cfg3, nti->nti_reg_cfg3); return 0; } static int ncv_targ_init(sc, ti, action) struct ncv_softc *sc; struct targ_info *ti; int action; { struct ncv_targ_info *nti = (void *) ti; if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; ti->ti_maxsynch.period = sc->sc_hw.hw_mperiod; ti->ti_maxsynch.offset = sc->sc_hw.hw_moffset; nti->nti_reg_cfg3 = sc->sc_hw.hw_cfg3; nti->nti_reg_period = 0; nti->nti_reg_offset = 0; } return 0; } /************************************************************** * General probe attach **************************************************************/ static int ncv_setup_img(struct ncv_hw *, u_int, int); static int ncv_setup_img(hw, dvcfg, hostid) struct ncv_hw *hw; u_int dvcfg; int hostid; { if (NCV_CLKFACTOR(dvcfg) > CLK_35M_F) { printf("ncv: invalid dvcfg flags\n"); return EINVAL; } if (NCV_C5IMG(dvcfg) != 0) { hw->hw_cfg5 = NCV_C5IMG(dvcfg); hw->hw_clk = NCV_CLKFACTOR(dvcfg); if ((ncv_io_control & NCV_ENABLE_FAST_SCSI) != 0 && (NCV_SPECIAL(dvcfg) & NCVHWCFG_MAX10M) != 0) hw->hw_mperiod = 100 / 4; if (NCV_SPECIAL(dvcfg) & NCVHWCFG_FIFOBUG) hw->hw_cfg3_fclk = 0x04; if (NCV_SPECIAL(dvcfg) & NCVHWCFG_SCSI1) hw->hw_cfg2 &= ~C2_SCSI2; if (NCV_SPECIAL(dvcfg) & NCVHWCFG_SLOW) hw->hw_cfg1 |= C1_SLOW; } /* setup configuration image 3 */ if (hw->hw_clk != CLK_40M_F && hw->hw_clk <= CLK_25M_F) hw->hw_cfg3 &= ~hw->hw_cfg3_fclk; else hw->hw_cfg3 |= hw->hw_cfg3_fclk; /* setup configuration image 1 */ hw->hw_cfg1 = (hw->hw_cfg1 & 0xf0) | hostid; return 0; } int -ncvprobesubr(iot, ioh, dvcfg, hsid) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int dvcfg; - int hsid; +ncvprobesubr(struct resource *res, u_int dvcfg, int hsid) { struct ncv_hw hwtab; hwtab = ncv_template; if (ncv_setup_img(&hwtab, dvcfg, hsid)) return 0; - if (ncvhw_check(iot, ioh, &hwtab) != 0) + if (ncvhw_check(res, &hwtab) != 0) return 0; return 1; } void ncvattachsubr(sc) struct ncv_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; printf("\n"); sc->sc_hw = ncv_template; ncv_setup_img(&sc->sc_hw, slp->sl_cfgflags, slp->sl_hostid); slp->sl_funcs = &ncv_funcs; slp->sl_flags |= HW_READ_PADDING; sc->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */ (void) scsi_low_attach(slp, 0, NCV_NTARGETS, NCV_NLUNS, sizeof(struct ncv_targ_info), 0); } /************************************************************** * PDMA **************************************************************/ static __inline void ncv_setup_and_start_pio(sc, reqlen) struct ncv_softc *sc; u_int reqlen; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - ncvhw_set_count(iot, ioh, reqlen); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS | CMD_DMA); + ncvhw_select_register_0(res, &sc->sc_hw); + ncvhw_set_count(res, reqlen); + bus_write_1(res, cr0_cmd, CMD_TRANS | CMD_DMA); - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_fstat, FIFO_EN); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_fstat, FIFO_EN); } static void ncv_pdma_end(sc, ti) struct ncv_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int len; slp->sl_flags &= ~HW_PDMASTART; if (slp->sl_Qnexus == NULL) { slp->sl_error |= PDMAERR; goto out; } if (ti->ti_phase == PH_DATA) { - len = ncvhw_get_count(sc->sc_iot, sc->sc_ioh); + len = ncvhw_get_count(res); if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) - len += (bus_space_read_1(sc->sc_iot, sc->sc_ioh, + len += (bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK); if ((u_int) len <= (u_int) sc->sc_sdatalen) { if ((slp->sl_scp.scp_direction == SCSI_LOW_READ) && sc->sc_tdatalen != len) goto bad; len = sc->sc_sdatalen - len; if ((u_int) len > (u_int) slp->sl_scp.scp_datalen) goto bad; slp->sl_scp.scp_data += len; slp->sl_scp.scp_datalen -= len; } else { bad: if ((slp->sl_error & PDMAERR) == 0) { device_printf(slp->sl_dev, "strange cnt hw 0x%x soft 0x%x\n", len, slp->sl_scp.scp_datalen); } slp->sl_error |= PDMAERR; } scsi_low_data_finish(slp); } else { device_printf(slp->sl_dev, "data phase miss\n"); slp->sl_error |= PDMAERR; } out: - ncvhw_select_register_1(iot, ioh, &sc->sc_hw); - bus_space_write_1(iot, ioh, cr1_fstat, 0); - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_1(res, &sc->sc_hw); + bus_write_1(res, cr1_fstat, 0); + ncvhw_select_register_0(res, &sc->sc_hw); } static void ncv_pio_read(sc, buf, reqlen) struct ncv_softc *sc; u_int8_t *buf; u_int reqlen; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int tout; register u_int8_t fstat; ncv_setup_and_start_pio(sc, reqlen); slp->sl_flags |= HW_PDMASTART; sc->sc_sdatalen = reqlen; tout = sc->sc_tmaxcnt; while (reqlen >= FIFO_F_SZ && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat == (u_int8_t) -1) goto out; if (fstat & FIFO_F) { #define NCV_FAST32_ACCESS #ifdef NCV_FAST32_ACCESS - bus_space_read_multi_4(iot, ioh, cr1_fdata, + bus_read_multi_4(res, cr1_fdata, (u_int32_t *) buf, FIFO_F_SZ / 4); #else /* !NCV_FAST32_ACCESS */ - bus_space_read_multi_2(iot, ioh, cr1_fdata, + bus_read_multi_2(res, cr1_fdata, (u_int16_t *) buf, FIFO_F_SZ / 2); #endif /* !NCV_FAST32_ACCESS */ buf += FIFO_F_SZ; reqlen -= FIFO_F_SZ; } else { if (fstat & FIFO_BRK) break; DELAY(1); } } while (reqlen > 0 && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if ((fstat & FIFO_E) == 0) { - *buf++ = bus_space_read_1(iot, ioh, cr1_fdata); + *buf++ = bus_read_1(res, cr1_fdata); reqlen --; } else { if (fstat & FIFO_BRK) break; DELAY(1); } } out: - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_0(res, &sc->sc_hw); sc->sc_tdatalen = reqlen; } static void ncv_pio_write(sc, buf, reqlen) struct ncv_softc *sc; u_int8_t *buf; u_int reqlen; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int tout; register u_int8_t fstat; ncv_setup_and_start_pio(sc, reqlen); sc->sc_sdatalen = reqlen; tout = sc->sc_tmaxcnt; slp->sl_flags |= HW_PDMASTART; while (reqlen >= FIFO_F_SZ && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat & FIFO_BRK) goto done; if ((fstat & FIFO_E) != 0) { #ifdef NCV_FAST32_ACCESS - bus_space_write_multi_4(iot, ioh, cr1_fdata, + bus_write_multi_4(res, cr1_fdata, (u_int32_t *) buf, FIFO_F_SZ / 4); #else /* !NCV_FAST32_ACCESS */ - bus_space_write_multi_2(iot, ioh, cr1_fdata, + bus_write_multi_2(res, cr1_fdata, (u_int16_t *) buf, FIFO_F_SZ / 2); #endif /* !NCV_FAST32_ACCESS */ buf += FIFO_F_SZ; reqlen -= FIFO_F_SZ; } else { DELAY(1); } } while (reqlen > 0 && tout -- > 0) { - fstat = bus_space_read_1(iot, ioh, cr1_fstat); + fstat = bus_read_1(res, cr1_fstat); if (fstat & FIFO_BRK) break; if ((fstat & FIFO_F) == 0) /* fifo not full */ { - bus_space_write_1(iot, ioh, cr1_fdata, *buf++); + bus_write_1(res, cr1_fdata, *buf++); reqlen --; } else { DELAY(1); } } done: - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); + ncvhw_select_register_0(res, &sc->sc_hw); } /************************************************************** * disconnect & reselect (HW low) **************************************************************/ static int ncv_reselected(sc) struct ncv_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti; u_int sid; - if ((bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK) != 2) + if ((bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK) != 2) { device_printf(slp->sl_dev, "illegal fifo bytes\n"); scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "chip confused"); return EJUSTRETURN; } - sid = (u_int) bus_space_read_1(iot, ioh, cr0_sfifo); + sid = (u_int) bus_read_1(res, cr0_sfifo); sid &= ~(1 << slp->sl_hostid); sid = ffs(sid) - 1; ti = scsi_low_reselected((struct scsi_low_softc *) sc, sid); if (ti == NULL) return EJUSTRETURN; #ifdef NCV_STATICS ncv_statics.reselect ++; #endif /* NCV_STATICS */ - bus_space_write_1(iot, ioh, cr0_dstid, sid); + bus_write_1(res, cr0_dstid, sid); return 0; } static int ncv_disconnected(sc, ti) struct ncv_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_ENSEL); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_ENSEL); #ifdef NCV_STATICS ncv_statics.disconnect ++; #endif /* NCV_STATICS */ scsi_low_disconnected(slp, ti); return 1; } /************************************************************** * SEQUENCER **************************************************************/ static int ncv_target_nexus_establish(sc) struct ncv_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; struct targ_info *ti = slp->sl_Tnexus; struct ncv_targ_info *nti = (void *) ti; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; - bus_space_write_1(iot, ioh, cr0_period, nti->nti_reg_period); - bus_space_write_1(iot, ioh, cr0_offs, nti->nti_reg_offset); - bus_space_write_1(iot, ioh, cr0_cfg3, nti->nti_reg_cfg3); + bus_write_1(res, cr0_period, nti->nti_reg_period); + bus_write_1(res, cr0_offs, nti->nti_reg_offset); + bus_write_1(res, cr0_cfg3, nti->nti_reg_cfg3); return 0; } static int ncv_lun_nexus_establish(sc) struct ncv_softc *sc; { return 0; } static int ncv_ccb_nexus_establish(sc) struct ncv_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; struct slccb *cb = slp->sl_Qnexus; sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; return 0; } static int ncv_catch_intr(sc) struct ncv_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; int wc; register u_int8_t status; for (wc = 0; wc < NCV_DELAY_MAX / NCV_DELAY_INTERVAL; wc ++) { - status = bus_space_read_1(iot, ioh, cr0_stat); + status = bus_read_1(res, cr0_stat); if ((status & STAT_INT) != 0) return 0; DELAY(NCV_DELAY_INTERVAL); } return EJUSTRETURN; } int ncvintr(arg) void *arg; { struct ncv_softc *sc = arg; struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; + struct resource *res = sc->port_res; struct targ_info *ti; struct buf *bp; u_int derror, flags; int len; u_int8_t regv, status, ireason; again: if (slp->sl_flags & HW_INACTIVE) return 0; /******************************************** * Status ********************************************/ - ncvhw_select_register_0(iot, ioh, &sc->sc_hw); - status = bus_space_read_1(iot, ioh, cr0_stat); + ncvhw_select_register_0(res, &sc->sc_hw); + status = bus_read_1(res, cr0_stat); if ((status & STAT_INT) == 0 || status == (u_int8_t) -1) return 0; - ireason = bus_space_read_1(iot, ioh, cr0_istat); + ireason = bus_read_1(res, cr0_istat); if ((ireason & INTR_SBR) != 0) { u_int8_t val; /* avoid power off hangup */ - val = bus_space_read_1(iot, ioh, cr0_cfg1); - bus_space_write_1(iot, ioh, cr0_cfg1, val | C1_SRR); + val = bus_read_1(res, cr0_cfg1); + bus_write_1(res, cr0_cfg1, val | C1_SRR); /* status init */ scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT, "bus reset (power off?)"); return 1; } /******************************************** * Debug section ********************************************/ #ifdef NCV_DEBUG if (ncv_debug) { scsi_low_print(slp, NULL); device_printf(slp->sl_dev, "st %x ist %x\n\n", status, ireason); #ifdef KDB if (ncv_debug > 1) kdb_enter(KDB_WHY_CAM, "ncv"); #endif /* KDB */ } #endif /* NCV_DEBUG */ /******************************************** * Reselect or Disconnect or Nexus check ********************************************/ /* (I) reselect */ if (ireason == INTR_RESELECT) { if (ncv_reselected(sc) == EJUSTRETURN) return 1; } /* (II) nexus */ if ((ti = slp->sl_Tnexus) == NULL) return 0; derror = 0; if ((status & (STAT_PE | STAT_GE)) != 0) { slp->sl_error |= PARITYERR; if ((status & PHASE_MASK) == MESSAGE_IN_PHASE) scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_PARITY, 0); else scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ERROR, 1); derror = SCSI_LOW_DATA_PE; } if ((ireason & (INTR_DIS | INTR_ILL)) != 0) { if ((ireason & INTR_ILL) == 0) return ncv_disconnected(sc, ti); slp->sl_error |= FATALIO; scsi_low_restart(slp, SCSI_LOW_RESTART_HARD, "illegal cmd"); return 1; } /******************************************** * Internal scsi phase ********************************************/ switch (ti->ti_phase) { case PH_SELSTART: scsi_low_arbit_win(slp); SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); if (sc->sc_selstop == 0) { /* XXX: * Here scsi phases expected are * DATA PHASE: * MSGIN : target wants to disconnect the host. * STATUSIN : immediate command completed. * CMD PHASE : command out failed * MSGOUT : identify command failed. */ if ((status & PHASE_MASK) != MESSAGE_OUT_PHASE) break; } else { if ((status & PHASE_MASK) != MESSAGE_OUT_PHASE) break; if ((ireason & INTR_FC) != 0) { SCSI_LOW_ASSERT_ATN(slp); } } SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); break; case PH_RESEL: ncv_target_nexus_establish(sc); if ((status & PHASE_MASK) != MESSAGE_IN_PHASE) { device_printf(slp->sl_dev, "unexpected phase after reselect\n"); slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); return 1; } break; default: if ((slp->sl_flags & HW_PDMASTART) != 0) { ncv_pdma_end(sc, ti); } break; } /******************************************** * Scsi phase sequencer ********************************************/ switch (status & PHASE_MASK) { case DATA_OUT_PHASE: /* data out */ SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_WRITE) != 0) { scsi_low_attention(slp); } if (slp->sl_scp.scp_datalen <= 0) { if ((ireason & INTR_BS) == 0) break; if ((slp->sl_error & PDMAERR) == 0) device_printf(slp->sl_dev, "data underrun\n"); slp->sl_error |= PDMAERR; if ((slp->sl_flags & HW_WRITE_PADDING) != 0) { u_int8_t padding[NCV_PADDING_SIZE]; bzero(padding, sizeof(padding)); ncv_pio_write(sc, padding, sizeof(padding)); } else { device_printf(slp->sl_dev, "write padding required\n"); } } else { len = slp->sl_scp.scp_datalen; if ((ncv_io_control & NCV_WRITE_INTERRUPTS_DRIVEN) != 0) { if (len > ncv_data_write_bytes) len = ncv_data_write_bytes; } ncv_pio_write(sc, slp->sl_scp.scp_data, len); } break; case DATA_IN_PHASE: /* data in */ SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_READ) != 0) { scsi_low_attention(slp); } if (slp->sl_scp.scp_datalen <= 0) { if ((ireason & INTR_BS) == 0) break; if ((slp->sl_error & PDMAERR) == 0) device_printf(slp->sl_dev, "data overrun\n"); slp->sl_error |= PDMAERR; if ((slp->sl_flags & HW_READ_PADDING) != 0) { u_int8_t padding[NCV_PADDING_SIZE]; ncv_pio_read(sc, padding, sizeof(padding)); } else { device_printf(slp->sl_dev, "read padding required\n"); break; } } else { len = slp->sl_scp.scp_datalen; if ((ncv_io_control & NCV_READ_INTERRUPTS_DRIVEN) != 0) { if (len > ncv_data_read_bytes) len = ncv_data_read_bytes; } ncv_pio_read(sc, slp->sl_scp.scp_data, len); } break; case COMMAND_PHASE: /* cmd out */ SCSI_LOW_SETUP_PHASE(ti, PH_CMD); if (scsi_low_cmd(slp, ti) != 0) { scsi_low_attention(slp); } - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - ncvhw_fpush(iot, ioh, + bus_write_1(res, cr0_cmd, CMD_FLUSH); + ncvhw_fpush(res, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + bus_write_1(res, cr0_cmd, CMD_TRANS); break; case STATUS_PHASE: /* status in */ SCSI_LOW_SETUP_PHASE(ti, PH_STAT); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_ICCS); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_ICCS); sc->sc_compseq = 1; break; default: break; case MESSAGE_OUT_PHASE: /* msg out */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_FLUSH); flags = SCSI_LOW_MSGOUT_UNIFY; if (ti->ti_ophase != ti->ti_phase) flags |= SCSI_LOW_MSGOUT_INIT; len = scsi_low_msgout(slp, ti, flags); if (len > 1 && slp->sl_atten == 0) { scsi_low_attention(slp); } - ncvhw_fpush(iot, ioh, ti->ti_msgoutstr, len); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + ncvhw_fpush(res, ti->ti_msgoutstr, len); + bus_write_1(res, cr0_cmd, CMD_TRANS); SCSI_LOW_DEASSERT_ATN(slp); break; case MESSAGE_IN_PHASE: /* msg in */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); - len = bus_space_read_1(iot, ioh, cr0_sffl) & CR0_SFFLR_BMASK; + len = bus_read_1(res, cr0_sffl) & CR0_SFFLR_BMASK; if (sc->sc_compseq != 0) { sc->sc_compseq = 0; if ((ireason & INTR_FC) && len == 2) { - regv = bus_space_read_1(iot, ioh, cr0_sfifo); + regv = bus_read_1(res, cr0_sfifo); scsi_low_statusin(slp, ti, regv | derror); len --; } else { slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); - bus_space_write_1(sc->sc_iot, sc->sc_ioh, - cr0_cmd, CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); break; } } else if (ireason & INTR_BS) { - bus_space_write_1(iot, ioh, cr0_cmd, CMD_FLUSH); - bus_space_write_1(iot, ioh, cr0_cmd, CMD_TRANS); + bus_write_1(res, cr0_cmd, CMD_FLUSH); + bus_write_1(res, cr0_cmd, CMD_TRANS); if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0) { if (ncv_catch_intr(sc) == 0) goto again; } break; } if ((ireason & INTR_FC) && len == 1) { - regv = bus_space_read_1(sc->sc_iot, sc->sc_ioh, - cr0_sfifo); + regv = bus_read_1(res, cr0_sfifo); if (scsi_low_msgin(slp, ti, regv | derror) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) { scsi_low_attention(slp); } } - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, - CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); if ((ncv_io_control & NCV_FAST_INTERRUPTS) != 0) { /* XXX: * clear a pending interrupt and sync with * a next interrupt! */ ncv_catch_intr(sc); } } else { slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); - bus_space_write_1(sc->sc_iot, sc->sc_ioh, cr0_cmd, - CMD_MSGOK); + bus_write_1(res, cr0_cmd, CMD_MSGOK); } break; } return 1; } Index: projects/sendfile/sys/dev/ncv/ncr53c500_pccard.c =================================================================== --- projects/sendfile/sys/dev/ncv/ncr53c500_pccard.c (revision 274764) +++ projects/sendfile/sys/dev/ncv/ncr53c500_pccard.c (revision 274765) @@ -1,347 +1,336 @@ /* $NecBSD: ncr53c500_pisa.c,v 1.28 1998/11/26 01:59:11 honda Exp $ */ /* $NetBSD$ */ /*- * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998 * Naofumi HONDA. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define KME_KXLC004_01 0x100 #define OFFSET_KME_KXLC004_01 0x10 #include "pccarddevs.h" static int ncvprobe(device_t devi); static int ncvattach(device_t devi); static void ncv_card_unload(device_t); static const struct ncv_product { struct pccard_product prod; int flags; } ncv_products[] = { { PCMCIA_CARD(EPSON, SC200), 0}, { PCMCIA_CARD(PANASONIC, KXLC002), 0xb4d00000 }, { PCMCIA_CARD(PANASONIC, KXLC003), 0xb4d00000 }, /* untested */ { PCMCIA_CARD(PANASONIC, KXLC004), 0xb4d00100 }, { PCMCIA_CARD(MACNICA, MPS100), 0xb6250000 }, { PCMCIA_CARD(MACNICA, MPS110), 0 }, { PCMCIA_CARD(NEC, PC9801N_J03R), 0 }, { PCMCIA_CARD(NEWMEDIA, BASICS_SCSI), 0 }, { PCMCIA_CARD(QLOGIC, PC05), 0x84d00000 }, #define FLAGS_REX5572 0x84d00000 { PCMCIA_CARD(RATOC, REX5572), FLAGS_REX5572 }, { PCMCIA_CARD(RATOC, REX9530), 0x84d00000 }, { { NULL }, 0 } }; /* * Additional code for FreeBSD new-bus PCCard frontend */ static void ncv_pccard_intr(void * arg) { + struct ncv_softc *sc; + + sc = arg; + SCSI_LOW_LOCK(&sc->sc_sclow); ncvintr(arg); + SCSI_LOW_UNLOCK(&sc->sc_sclow); } static void ncv_release_resource(device_t dev) { struct ncv_softc *sc = device_get_softc(dev); if (sc->ncv_intrhand) { bus_teardown_intr(dev, sc->irq_res, sc->ncv_intrhand); } if (sc->port_res) { bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, sc->port_res); } if (sc->port_res_dmy) { bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid_dmy, sc->port_res_dmy); } if (sc->irq_res) { bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); } if (sc->mem_res) { bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); } + mtx_destroy(&sc->sc_sclow.sl_lock); } static int ncv_alloc_resource(device_t dev) { struct ncv_softc *sc = device_get_softc(dev); u_int32_t flags = device_get_flags(dev); u_long ioaddr, iosize, maddr, msize; int error; bus_addr_t offset = 0; if(flags & KME_KXLC004_01) offset = OFFSET_KME_KXLC004_01; error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize); if (error || (iosize < (offset + NCVIOSZ))) { return(ENOMEM); } + mtx_init(&sc->sc_sclow.sl_lock, "ncv", NULL, MTX_DEF); sc->port_rid = 0; sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, ioaddr+offset, ioaddr+iosize-offset, iosize-offset, RF_ACTIVE); if (sc->port_res == NULL) { ncv_release_resource(dev); return(ENOMEM); } if (offset != 0) { sc->port_rid_dmy = 0; sc->port_res_dmy = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid_dmy, ioaddr, ioaddr+offset, offset, RF_ACTIVE); if (sc->port_res_dmy == NULL) { printf("Warning: cannot allocate IOPORT partially.\n"); } } else { sc->port_rid_dmy = 0; sc->port_res_dmy = NULL; } sc->irq_rid = 0; sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE); if (sc->irq_res == NULL) { ncv_release_resource(dev); return(ENOMEM); } error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize); if (error) { return(0); /* XXX */ } /* no need to allocate memory if not configured */ if (maddr == 0 || msize == 0) { return(0); } sc->mem_rid = 0; sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE); if (sc->mem_res == NULL) { ncv_release_resource(dev); return(ENOMEM); } return(0); } static int ncv_pccard_probe(device_t dev) { const struct ncv_product *pp; const char *vendorstr; const char *prodstr; if ((pp = (const struct ncv_product *) pccard_product_lookup(dev, (const struct pccard_product *) ncv_products, sizeof(ncv_products[0]), NULL)) != NULL) { if (pp->prod.pp_name != NULL) device_set_desc(dev, pp->prod.pp_name); device_set_flags(dev, pp->flags); return(0); } if (pccard_get_vendor_str(dev, &vendorstr)) return(EIO); if (pccard_get_product_str(dev, &prodstr)) return(EIO); if (strcmp(vendorstr, "RATOC System Inc.") == 0 && strncmp(prodstr, "SOUND/SCSI2 CARD", 16) == 0) { device_set_desc(dev, "RATOC REX-5572"); device_set_flags(dev, FLAGS_REX5572); - return (0); + return (BUS_PROBE_DEFAULT); } return(EIO); } static int ncv_pccard_attach(device_t dev) { struct ncv_softc *sc = device_get_softc(dev); int error; - bzero(sc, sizeof(struct ncv_softc)); - error = ncv_alloc_resource(dev); if (error) { return(error); } if (ncvprobe(dev) == 0) { ncv_release_resource(dev); return(ENXIO); } - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, ncv_pccard_intr, (void *)sc, &sc->ncv_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, ncv_pccard_intr, sc, &sc->ncv_intrhand); if (error) { ncv_release_resource(dev); return(error); } if (ncvattach(dev) == 0) { ncv_release_resource(dev); return(ENXIO); } return(0); } static int ncv_pccard_detach(device_t dev) { ncv_card_unload(dev); ncv_release_resource(dev); return (0); } static device_method_t ncv_pccard_methods[] = { /* Device interface */ DEVMETHOD(device_probe, ncv_pccard_probe), DEVMETHOD(device_attach, ncv_pccard_attach), DEVMETHOD(device_detach, ncv_pccard_detach), { 0, 0 } }; static driver_t ncv_pccard_driver = { "ncv", ncv_pccard_methods, sizeof(struct ncv_softc), }; static devclass_t ncv_devclass; MODULE_DEPEND(ncv, scsi_low, 1, 1, 1); DRIVER_MODULE(ncv, pccard, ncv_pccard_driver, ncv_devclass, 0, 0); static void ncv_card_unload(device_t devi) { struct ncv_softc *sc = device_get_softc(devi); - intrmask_t s; - s = splcam(); - scsi_low_deactivate((struct scsi_low_softc *)sc); - scsi_low_dettach(&sc->sc_sclow); - splx(s); + scsi_low_deactivate(&sc->sc_sclow); + scsi_low_detach(&sc->sc_sclow); } static int ncvprobe(device_t devi) { int rv; struct ncv_softc *sc = device_get_softc(devi); u_int32_t flags = device_get_flags(devi); - rv = ncvprobesubr(rman_get_bustag(sc->port_res), - rman_get_bushandle(sc->port_res), + rv = ncvprobesubr(sc->port_res, flags, NCV_HOSTID); return rv; } static int ncvattach(device_t devi) { struct ncv_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(devi); - intrmask_t s; - char dvname[16]; /* SCSI_LOW_DVNAME_LEN */ - strcpy(dvname, "ncv"); - sc = device_get_softc(devi); - if (sc == NULL) { - return(0); - } slp = &sc->sc_sclow; slp->sl_dev = devi; - sc->sc_iot = rman_get_bustag(sc->port_res); - sc->sc_ioh = rman_get_bushandle(sc->port_res); - slp->sl_hostid = NCV_HOSTID; slp->sl_cfgflags = flags; - s = splcam(); ncvattachsubr(sc); - splx(s); return(NCVIOSZ); } Index: projects/sendfile/sys/dev/ncv/ncr53c500var.h =================================================================== --- projects/sendfile/sys/dev/ncv/ncr53c500var.h (revision 274764) +++ projects/sendfile/sys/dev/ncv/ncr53c500var.h (revision 274765) @@ -1,87 +1,83 @@ /* $FreeBSD$ */ /* $NecBSD: ncr53c500var.h,v 1.11.18.1 2001/06/08 06:27:45 honda Exp $ */ /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1995, 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #ifndef _NCR53C500VAR_H_ #define _NCR53C500VAR_H_ /***************************************************************** * Host adapter structure *****************************************************************/ struct ncv_softc { struct scsi_low_softc sc_sclow; /* generic data */ - bus_space_tag_t sc_iot; - bus_space_tag_t sc_memt; - bus_space_handle_t sc_ioh; - int port_rid; int port_rid_dmy; int irq_rid; int mem_rid; struct resource *port_res; struct resource *port_res_dmy; struct resource *irq_res; struct resource *mem_res; void *ncv_intrhand; int sc_tmaxcnt; int sc_selstop; /* sel atn stop asserted */ int sc_compseq; /* completion seq cmd asserted */ int sc_sdatalen; /* start datalen */ int sc_tdatalen; /* temp xfer data len */ struct ncv_hw sc_hw; /* hardware register images */ }; /***************************************************************** * Lun information *****************************************************************/ struct ncv_targ_info { struct targ_info nti_ti; u_int8_t nti_reg_cfg3; /* cfg3 images per lun */ u_int8_t nti_reg_offset; /* synch offset register per lun */ u_int8_t nti_reg_period; /* synch period register per lun */ }; /***************************************************************** * Proto *****************************************************************/ -int ncvprobesubr(bus_space_tag_t, bus_space_handle_t ioh, u_int, int); +int ncvprobesubr(struct resource *, u_int, int); void ncvattachsubr(struct ncv_softc *); int ncvintr(void *); #endif /* !_NCR53C500VAR_H_ */ Index: projects/sendfile/sys/dev/nsp/nsp.c =================================================================== --- projects/sendfile/sys/dev/nsp/nsp.c (revision 274764) +++ projects/sendfile/sys/dev/nsp/nsp.c (revision 274765) @@ -1,1878 +1,1815 @@ /* $NecBSD: nsp.c,v 1.21.12.6 2001/06/29 06:27:52 honda Exp $ */ /* $NetBSD$ */ #define NSP_DEBUG #define NSP_STATICS #define NSP_IO_CONTROL_FLAGS \ (NSP_READ_SUSPEND_IO | NSP_WRITE_SUSPEND_IO | \ NSP_READ_FIFO_INTERRUPTS | NSP_WRITE_FIFO_INTERRUPTS | \ NSP_USE_MEMIO | NSP_WAIT_FOR_SELECT) /*- * Copyright (c) 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * * Copyright (c) 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include +#include #include #include #include #include #include /*************************************************** * USER SETTINGS ***************************************************/ /* DEVICE CONFIGURATION FLAGS (MINOR) * * 0x01 DISCONNECT OFF * 0x02 PARITY LINE OFF * 0x04 IDENTIFY MSG OFF ( = single lun) * 0x08 SYNC TRANSFER OFF */ /*************************************************** * PARAMS ***************************************************/ #define NSP_NTARGETS 8 #define NSP_NLUNS 8 #define NSP_MAX_DATA_SIZE (64 * 1024) #define NSP_SELTIMEOUT (200) #define NSP_DELAY_MAX (2 * 1000 * 1000) #define NSP_DELAY_INTERVAL (1) #define NSP_TIMER_1MS (1000 / 51) /*************************************************** * DEBUG ***************************************************/ #ifdef NSP_DEBUG int nsp_debug; #endif /* NSP_DEBUG */ #ifdef NSP_STATICS struct nsp_statics { int arbit_conflict_1; int arbit_conflict_2; int device_data_write; int device_busy; int disconnect; int reselect; int data_phase_bypass; } nsp_statics; #endif /* NSP_STATICS */ /*************************************************** * IO control ***************************************************/ #define NSP_READ_SUSPEND_IO 0x0001 #define NSP_WRITE_SUSPEND_IO 0x0002 #define NSP_USE_MEMIO 0x0004 #define NSP_READ_FIFO_INTERRUPTS 0x0010 #define NSP_WRITE_FIFO_INTERRUPTS 0x0020 #define NSP_WAIT_FOR_SELECT 0x0100 u_int nsp_io_control = NSP_IO_CONTROL_FLAGS; int nsp_read_suspend_bytes = DEV_BSIZE; int nsp_write_suspend_bytes = DEV_BSIZE; int nsp_read_interrupt_bytes = 4096; int nsp_write_interrupt_bytes = 4096; /*************************************************** * DEVICE STRUCTURE ***************************************************/ extern struct cfdriver nsp_cd; /************************************************************** * DECLARE **************************************************************/ #define NSP_FIFO_ON 1 #define NSP_FIFO_OFF 0 static void nsp_pio_read(struct nsp_softc *, int); static void nsp_pio_write(struct nsp_softc *, int); static int nsp_xfer(struct nsp_softc *, u_int8_t *, int, int, int); static int nsp_msg(struct nsp_softc *, struct targ_info *, u_int); static int nsp_reselected(struct nsp_softc *); static int nsp_disconnected(struct nsp_softc *, struct targ_info *); static void nsp_pdma_end(struct nsp_softc *, struct targ_info *); static void nsphw_init(struct nsp_softc *); static int nsp_target_nexus_establish(struct nsp_softc *); static int nsp_lun_nexus_establish(struct nsp_softc *); static int nsp_ccb_nexus_establish(struct nsp_softc *); static int nsp_world_start(struct nsp_softc *, int); static int nsphw_start_selection(struct nsp_softc *sc, struct slccb *); static void nsphw_bus_reset(struct nsp_softc *); static void nsphw_attention(struct nsp_softc *); static u_int nsp_fifo_count(struct nsp_softc *); static u_int nsp_request_count(struct nsp_softc *); static int nsp_negate_signal(struct nsp_softc *, u_int8_t, u_char *); static int nsp_expect_signal(struct nsp_softc *, u_int8_t, u_int8_t); static void nsp_start_timer(struct nsp_softc *, int); static void nsp_setup_fifo(struct nsp_softc *, int, int, int); static int nsp_targ_init(struct nsp_softc *, struct targ_info *, int); static void nsphw_selection_done_and_expect_msgout(struct nsp_softc *); static void nsp_data_padding(struct nsp_softc *, int, u_int); static int nsp_timeout(struct nsp_softc *); static int nsp_read_fifo(struct nsp_softc *, int); static int nsp_write_fifo(struct nsp_softc *, int); static int nsp_phase_match(struct nsp_softc *, u_int8_t, u_int8_t); static int nsp_wait_interrupt(struct nsp_softc *); struct scsi_low_funcs nspfuncs = { SC_LOW_INIT_T nsp_world_start, SC_LOW_BUSRST_T nsphw_bus_reset, SC_LOW_TARG_INIT_T nsp_targ_init, SC_LOW_LUN_INIT_T NULL, SC_LOW_SELECT_T nsphw_start_selection, SC_LOW_NEXUS_T nsp_lun_nexus_establish, SC_LOW_NEXUS_T nsp_ccb_nexus_establish, SC_LOW_ATTEN_T nsphw_attention, SC_LOW_MSG_T nsp_msg, SC_LOW_TIMEOUT_T nsp_timeout, SC_LOW_POLL_T nspintr, NULL, }; /**************************************************** * hwfuncs ****************************************************/ -static __inline u_int8_t nsp_cr_read_1(bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t ofs); -static __inline void nsp_cr_write_1(bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t ofs, u_int8_t va); - -static __inline u_int8_t -nsp_cr_read_1(bst, bsh, ofs) - bus_space_tag_t bst; - bus_space_handle_t bsh; - bus_addr_t ofs; +static __inline uint8_t +nsp_cr_read_1(struct resource *res, bus_addr_t ofs) { - - bus_space_write_1(bst, bsh, nsp_idxr, ofs); - return bus_space_read_1(bst, bsh, nsp_datar); + + bus_write_1(res, nsp_idxr, ofs); + return bus_read_1(res, nsp_datar); } static __inline void -nsp_cr_write_1(bus_space_tag_t bst, bus_space_handle_t bsh, bus_addr_t ofs, - u_int8_t va) +nsp_cr_write_1(struct resource *res, bus_addr_t ofs, uint8_t va) { - bus_space_write_1(bst, bsh, nsp_idxr, ofs); - bus_space_write_1(bst, bsh, nsp_datar, va); + bus_write_1(res, nsp_idxr, ofs); + bus_write_1(res, nsp_datar, va); } static int nsp_expect_signal(struct nsp_softc *sc, u_int8_t curphase, u_int8_t mask) { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int wc; u_int8_t ph, isrc; for (wc = 0; wc < NSP_DELAY_MAX / NSP_DELAY_INTERVAL; wc ++) { - ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if (ph == (u_int8_t) -1) return -1; - isrc = bus_space_read_1(bst, bsh, nsp_irqsr); + isrc = bus_read_1(sc->port_res, nsp_irqsr); if (isrc & IRQSR_SCSI) return 0; if ((ph & mask) != 0 && (ph & SCBUSMON_PHMASK) == curphase) return 1; DELAY(NSP_DELAY_INTERVAL); } device_printf(slp->sl_dev, "nsp_expect_signal timeout\n"); return -1; } static void nsphw_init(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; /* block all interrupts */ - bus_space_write_1(bst, bsh, nsp_irqcr, IRQCR_ALLMASK); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_ALLMASK); /* setup SCSI interface */ - bus_space_write_1(bst, bsh, nsp_ifselr, IFSELR_IFSEL); + bus_write_1(sc->port_res, nsp_ifselr, IFSELR_IFSEL); - nsp_cr_write_1(bst, bsh, NSPR_SCIENR, 0); + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, 0); - nsp_cr_write_1(bst, bsh, NSPR_XFERMR, XFERMR_IO8); - nsp_cr_write_1(bst, bsh, NSPR_CLKDIVR, sc->sc_iclkdiv); + nsp_cr_write_1(sc->port_res, NSPR_XFERMR, XFERMR_IO8); + nsp_cr_write_1(sc->port_res, NSPR_CLKDIVR, sc->sc_iclkdiv); - nsp_cr_write_1(bst, bsh, NSPR_SCIENR, sc->sc_icr); - nsp_cr_write_1(bst, bsh, NSPR_PARITYR, sc->sc_parr); - nsp_cr_write_1(bst, bsh, NSPR_PTCLRR, + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); + nsp_cr_write_1(sc->port_res, NSPR_PARITYR, sc->sc_parr); + nsp_cr_write_1(sc->port_res, NSPR_PTCLRR, PTCLRR_ACK | PTCLRR_REQ | PTCLRR_HOST | PTCLRR_RSS); /* setup fifo asic */ - bus_space_write_1(bst, bsh, nsp_ifselr, IFSELR_REGSEL); - nsp_cr_write_1(bst, bsh, NSPR_TERMPWRC, 0); - if ((nsp_cr_read_1(bst, bsh, NSPR_OCR) & OCR_TERMPWRS) == 0) - nsp_cr_write_1(bst, bsh, NSPR_TERMPWRC, TERMPWRC_POWON); + bus_write_1(sc->port_res, nsp_ifselr, IFSELR_REGSEL); + nsp_cr_write_1(sc->port_res, NSPR_TERMPWRC, 0); + if ((nsp_cr_read_1(sc->port_res, NSPR_OCR) & OCR_TERMPWRS) == 0) + nsp_cr_write_1(sc->port_res, NSPR_TERMPWRC, TERMPWRC_POWON); - nsp_cr_write_1(bst, bsh, NSPR_XFERMR, XFERMR_IO8); - nsp_cr_write_1(bst, bsh, NSPR_CLKDIVR, sc->sc_clkdiv); - nsp_cr_write_1(bst, bsh, NSPR_TIMERCNT, 0); - nsp_cr_write_1(bst, bsh, NSPR_TIMERCNT, 0); + nsp_cr_write_1(sc->port_res, NSPR_XFERMR, XFERMR_IO8); + nsp_cr_write_1(sc->port_res, NSPR_CLKDIVR, sc->sc_clkdiv); + nsp_cr_write_1(sc->port_res, NSPR_TIMERCNT, 0); + nsp_cr_write_1(sc->port_res, NSPR_TIMERCNT, 0); - nsp_cr_write_1(bst, bsh, NSPR_SYNCR, 0); - nsp_cr_write_1(bst, bsh, NSPR_ACKWIDTH, 0); + nsp_cr_write_1(sc->port_res, NSPR_SYNCR, 0); + nsp_cr_write_1(sc->port_res, NSPR_ACKWIDTH, 0); /* enable interrupts and ack them */ - nsp_cr_write_1(bst, bsh, NSPR_SCIENR, sc->sc_icr); - bus_space_write_1(bst, bsh, nsp_irqcr, IRQSR_MASK); + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); + bus_write_1(sc->port_res, nsp_irqcr, IRQSR_MASK); nsp_setup_fifo(sc, NSP_FIFO_OFF, SCSI_LOW_READ, 0); } /**************************************************** * scsi low interface ****************************************************/ static void nsphw_attention(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int8_t cr; - cr = nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR)/* & ~SCBUSCR_ACK */; - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr | SCBUSCR_ATN); + cr = nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR)/* & ~SCBUSCR_ACK */; + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr | SCBUSCR_ATN); DELAY(10); } static void nsphw_bus_reset(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int i; - bus_space_write_1(bst, bsh, nsp_irqcr, IRQCR_ALLMASK); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_ALLMASK); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, SCBUSCR_RST); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, SCBUSCR_RST); DELAY(100 * 1000); /* 100ms */ - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, 0); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, 0); for (i = 0; i < 5; i ++) - (void) nsp_cr_read_1(bst, bsh, NSPR_IRQPHS); + (void) nsp_cr_read_1(sc->port_res, NSPR_IRQPHS); - bus_space_write_1(bst, bsh, nsp_irqcr, IRQSR_MASK); + bus_write_1(sc->port_res, nsp_irqcr, IRQSR_MASK); } static void nsphw_selection_done_and_expect_msgout(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; /* clear ack counter */ sc->sc_cnt = 0; - nsp_cr_write_1(bst, bsh, NSPR_PTCLRR, PTCLRR_PT | PTCLRR_ACK | + nsp_cr_write_1(sc->port_res, NSPR_PTCLRR, PTCLRR_PT | PTCLRR_ACK | PTCLRR_REQ | PTCLRR_HOST); /* deassert sel and assert atten */ sc->sc_seltout = 0; - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, sc->sc_busc); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, sc->sc_busc); DELAY(1); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, sc->sc_busc | SCBUSCR_ADIR | SCBUSCR_ACKEN); SCSI_LOW_ASSERT_ATN(slp); } static int nsphw_start_selection(sc, cb) struct nsp_softc *sc; struct slccb *cb; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; struct targ_info *ti = cb->ti; register u_int8_t arbs, ph; - int s, wc; + int wc; wc = sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; sc->sc_dataout_timeout = 0; /* check bus free */ - s = splhigh(); - ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if (ph != SCBUSMON_FREE) { - splx(s); #ifdef NSP_STATICS nsp_statics.arbit_conflict_1 ++; #endif /* NSP_STATICS */ return SCSI_LOW_START_FAIL; } /* start arbitration */ - nsp_cr_write_1(bst, bsh, NSPR_ARBITS, ARBITS_EXEC); - splx(s); + nsp_cr_write_1(sc->port_res, NSPR_ARBITS, ARBITS_EXEC); SCSI_LOW_SETUP_PHASE(ti, PH_ARBSTART); do { /* XXX: what a stupid chip! */ - arbs = nsp_cr_read_1(bst, bsh, NSPR_ARBITS); + arbs = nsp_cr_read_1(sc->port_res, NSPR_ARBITS); DELAY(1); } while ((arbs & (ARBITS_WIN | ARBITS_FAIL)) == 0 && wc -- > 0); if ((arbs & ARBITS_WIN) == 0) { - nsp_cr_write_1(bst, bsh, NSPR_ARBITS, ARBITS_CLR); + nsp_cr_write_1(sc->port_res, NSPR_ARBITS, ARBITS_CLR); #ifdef NSP_STATICS nsp_statics.arbit_conflict_2 ++; #endif /* NSP_STATICS */ return SCSI_LOW_START_FAIL; } /* assert select line */ SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART); scsi_low_arbit_win(slp); - s = splhigh(); DELAY(3); - nsp_cr_write_1(bst, bsh, NSPR_DATA, + nsp_cr_write_1(sc->port_res, NSPR_DATA, sc->sc_idbit | (1 << ti->ti_id)); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, SCBUSCR_SEL | SCBUSCR_BSY | sc->sc_busc); DELAY(3); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, SCBUSCR_SEL | + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, SCBUSCR_SEL | SCBUSCR_BSY | SCBUSCR_DOUT | sc->sc_busc); - nsp_cr_write_1(bst, bsh, NSPR_ARBITS, ARBITS_CLR); + nsp_cr_write_1(sc->port_res, NSPR_ARBITS, ARBITS_CLR); DELAY(3); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, SCBUSCR_SEL | SCBUSCR_DOUT | sc->sc_busc); DELAY(1); if ((nsp_io_control & NSP_WAIT_FOR_SELECT) != 0) { #define NSP_FIRST_SEL_WAIT 300 #define NSP_SEL_CHECK_INTERVAL 10 /* wait for a selection response */ for (wc = 0; wc < NSP_FIRST_SEL_WAIT / NSP_SEL_CHECK_INTERVAL; wc ++) { - ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((ph & SCBUSMON_BSY) == 0) { DELAY(NSP_SEL_CHECK_INTERVAL); continue; } DELAY(1); - ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((ph & SCBUSMON_BSY) != 0) { nsphw_selection_done_and_expect_msgout(sc); - splx(s); SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); return SCSI_LOW_START_OK; } } } - splx(s); /* check a selection timeout */ nsp_start_timer(sc, NSP_TIMER_1MS); sc->sc_seltout = 1; return SCSI_LOW_START_OK; } static int nsp_world_start(sc, fdone) struct nsp_softc *sc; int fdone; { struct scsi_low_softc *slp = &sc->sc_sclow; sc->sc_cnt = 0; sc->sc_seltout = 0; if ((slp->sl_cfgflags & CFG_NOATTEN) == 0) sc->sc_busc = SCBUSCR_ATN; else sc->sc_busc = 0; if ((slp->sl_cfgflags & CFG_NOPARITY) == 0) sc->sc_parr = PARITYR_ENABLE | PARITYR_CLEAR; else sc->sc_parr = 0; sc->sc_icr = (SCIENR_SCCHG | SCIENR_RESEL | SCIENR_RST); nsphw_init(sc); scsi_low_bus_reset(slp); return 0; } struct ncp_synch_data { u_int min_period; u_int max_period; u_int chip_period; u_int ack_width; }; static struct ncp_synch_data ncp_sync_data_40M[] = { {0x0c,0x0c,0x1,0}, /* 20MB 50ns*/ {0x19,0x19,0x3,1}, /* 10MB 100ns*/ {0x1a,0x25,0x5,2}, /* 7.5MB 150ns*/ {0x26,0x32,0x7,3}, /* 5MB 200ns*/ {0x0, 0, 0, 0} }; static struct ncp_synch_data ncp_sync_data_20M[] = { {0x19,0x19,0x1,0}, /* 10MB 100ns*/ {0x1a,0x25,0x2,0}, /* 7.5MB 150ns*/ {0x26,0x32,0x3,1}, /* 5MB 200ns*/ {0x0, 0, 0, 0} }; static int nsp_msg(sc, ti, msg) struct nsp_softc *sc; struct targ_info *ti; u_int msg; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; struct ncp_synch_data *sdp; struct nsp_targ_info *nti = (void *) ti; u_int period, offset; int i, error; if ((msg & SCSI_LOW_MSG_WIDE) != 0) { if (ti->ti_width != SCSI_LOW_BUS_WIDTH_8) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; return EINVAL; } return 0; } if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; period = ti->ti_maxsynch.period; offset = ti->ti_maxsynch.offset; if (sc->sc_iclkdiv == CLKDIVR_20M) sdp = &ncp_sync_data_20M[0]; else sdp = &ncp_sync_data_40M[0]; for (i = 0; sdp->max_period != 0; i ++, sdp ++) { if (period >= sdp->min_period && period <= sdp->max_period) break; } if (period != 0 && sdp->max_period == 0) { /* * NO proper period/offset found, * Retry neg with the target. */ ti->ti_maxsynch.period = 0; ti->ti_maxsynch.offset = 0; nti->nti_reg_syncr = 0; nti->nti_reg_ackwidth = 0; error = EINVAL; } else { nti->nti_reg_syncr = (sdp->chip_period << SYNCR_PERS) | (offset & SYNCR_OFFM); nti->nti_reg_ackwidth = sdp->ack_width; error = 0; } - nsp_cr_write_1(bst, bsh, NSPR_SYNCR, nti->nti_reg_syncr); - nsp_cr_write_1(bst, bsh, NSPR_ACKWIDTH, nti->nti_reg_ackwidth); + nsp_cr_write_1(sc->port_res, NSPR_SYNCR, nti->nti_reg_syncr); + nsp_cr_write_1(sc->port_res, NSPR_ACKWIDTH, nti->nti_reg_ackwidth); return error; } static int nsp_targ_init(sc, ti, action) struct nsp_softc *sc; struct targ_info *ti; int action; { struct nsp_targ_info *nti = (void *) ti; if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; ti->ti_maxsynch.period = 100 / 4; ti->ti_maxsynch.offset = 15; nti->nti_reg_syncr = 0; nti->nti_reg_ackwidth = 0; } return 0; } static void nsp_start_timer(sc, time) struct nsp_softc *sc; int time; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; sc->sc_timer = time; - nsp_cr_write_1(bst, bsh, NSPR_TIMERCNT, time); + nsp_cr_write_1(sc->port_res, NSPR_TIMERCNT, time); } /************************************************************** * General probe attach **************************************************************/ int -nspprobesubr(iot, ioh, dvcfg) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int dvcfg; +nspprobesubr(struct resource *res, u_int dvcfg) { u_int8_t regv; - regv = bus_space_read_1(iot, ioh, nsp_fifosr); + regv = bus_read_1(res, nsp_fifosr); if (regv < 0x11 || regv >= 0x20) return 0; return 1; } void nspattachsubr(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - printf("\n"); - sc->sc_idbit = (1 << slp->sl_hostid); slp->sl_flags |= HW_READ_PADDING; slp->sl_funcs = &nspfuncs; sc->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */ (void) scsi_low_attach(slp, 0, NSP_NTARGETS, NSP_NLUNS, sizeof(struct nsp_targ_info), 0); } /************************************************************** * PDMA functions **************************************************************/ static u_int nsp_fifo_count(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int count; - nsp_cr_write_1(bst, bsh, NSPR_PTCLRR, PTCLRR_RSS_ACK | PTCLRR_PT); - count = bus_space_read_1(bst, bsh, nsp_datar); - count += (((u_int) bus_space_read_1(bst, bsh, nsp_datar)) << 8); - count += (((u_int) bus_space_read_1(bst, bsh, nsp_datar)) << 16); + nsp_cr_write_1(sc->port_res, NSPR_PTCLRR, PTCLRR_RSS_ACK | PTCLRR_PT); + count = bus_read_1(sc->port_res, nsp_datar); + count += (((u_int) bus_read_1(sc->port_res, nsp_datar)) << 8); + count += (((u_int) bus_read_1(sc->port_res, nsp_datar)) << 16); return count; } static u_int nsp_request_count(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int count; - nsp_cr_write_1(bst, bsh, NSPR_PTCLRR, PTCLRR_RSS_REQ | PTCLRR_PT); - count = bus_space_read_1(bst, bsh, nsp_datar); - count += (((u_int) bus_space_read_1(bst, bsh, nsp_datar)) << 8); - count += (((u_int) bus_space_read_1(bst, bsh, nsp_datar)) << 16); + nsp_cr_write_1(sc->port_res, NSPR_PTCLRR, PTCLRR_RSS_REQ | PTCLRR_PT); + count = bus_read_1(sc->port_res, nsp_datar); + count += (((u_int) bus_read_1(sc->port_res, nsp_datar)) << 8); + count += (((u_int) bus_read_1(sc->port_res, nsp_datar)) << 16); return count; } static void nsp_setup_fifo(sc, on, direction, datalen) struct nsp_softc *sc; int on; int direction; int datalen; { u_int8_t xfermode; sc->sc_suspendio = 0; if (on == NSP_FIFO_OFF) { xfermode = XFERMR_IO8; goto out; } /* check if suspend io OK ? */ if (datalen > 0) { if (direction == SCSI_LOW_READ) { if ((nsp_io_control & NSP_READ_SUSPEND_IO) != 0 && (datalen % nsp_read_suspend_bytes) == 0) sc->sc_suspendio = nsp_read_suspend_bytes; } else { if ((nsp_io_control & NSP_WRITE_SUSPEND_IO) != 0 && (datalen % nsp_write_suspend_bytes) == 0) sc->sc_suspendio = nsp_write_suspend_bytes; } } /* determine a transfer type */ if (datalen < DEV_BSIZE || (datalen & 3) != 0) { - if (sc->sc_memh != 0 && + if (sc->mem_res != NULL && (nsp_io_control & NSP_USE_MEMIO) != 0) xfermode = XFERMR_XEN | XFERMR_MEM8; else xfermode = XFERMR_XEN | XFERMR_IO8; } else { - if (sc->sc_memh != 0 && + if (sc->mem_res != NULL && (nsp_io_control & NSP_USE_MEMIO) != 0) xfermode = XFERMR_XEN | XFERMR_MEM32; else xfermode = XFERMR_XEN | XFERMR_IO32; if (sc->sc_suspendio > 0) xfermode |= XFERMR_FIFOEN; } out: sc->sc_xfermr = xfermode; - nsp_cr_write_1(sc->sc_iot, sc->sc_ioh, NSPR_XFERMR, sc->sc_xfermr); + nsp_cr_write_1(sc->port_res, NSPR_XFERMR, sc->sc_xfermr); } static void nsp_pdma_end(sc, ti) struct nsp_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; struct slccb *cb = slp->sl_Qnexus; u_int len = 0, cnt; sc->sc_dataout_timeout = 0; slp->sl_flags &= ~HW_PDMASTART; nsp_setup_fifo(sc, NSP_FIFO_OFF, SCSI_LOW_READ, 0); if ((sc->sc_icr & SCIENR_FIFO) != 0) { sc->sc_icr &= ~SCIENR_FIFO; - nsp_cr_write_1(sc->sc_iot, sc->sc_ioh, NSPR_SCIENR, sc->sc_icr); + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); } if (cb == NULL) { slp->sl_error |= PDMAERR; return; } if (ti->ti_phase == PH_DATA) { cnt = nsp_fifo_count(sc); if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) { len = sc->sc_cnt - cnt; if (sc->sc_cnt >= cnt && slp->sl_scp.scp_datalen + len <= cb->ccb_scp.scp_datalen) { slp->sl_scp.scp_data -= len; slp->sl_scp.scp_datalen += len; } else { slp->sl_error |= PDMAERR; device_printf(slp->sl_dev, "len %x >= datalen %x\n", len, slp->sl_scp.scp_datalen); } } else if (slp->sl_scp.scp_direction == SCSI_LOW_READ) { if (sc->sc_cnt != cnt || sc->sc_cnt > cb->ccb_scp.scp_datalen) { slp->sl_error |= PDMAERR; device_printf(slp->sl_dev, "data read count error %x != %x (%x)\n", sc->sc_cnt, cnt, cb->ccb_scp.scp_datalen); } } sc->sc_cnt = cnt; scsi_low_data_finish(slp); } else { device_printf(slp->sl_dev, "data phase miss\n"); slp->sl_error |= PDMAERR; } } #define RFIFO_CRIT 64 #define WFIFO_CRIT 32 static void nsp_data_padding(sc, direction, count) struct nsp_softc *sc; int direction; u_int count; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; if (count > NSP_MAX_DATA_SIZE) count = NSP_MAX_DATA_SIZE; - nsp_cr_write_1(bst, bsh, NSPR_XFERMR, XFERMR_XEN | XFERMR_IO8); + nsp_cr_write_1(sc->port_res, NSPR_XFERMR, XFERMR_XEN | XFERMR_IO8); if (direction == SCSI_LOW_READ) { while (count -- > 0) - (void) bus_space_read_1(bst, bsh, nsp_fifodr); + (void) bus_read_1(sc->port_res, nsp_fifodr); } else { while (count -- > 0) - (void) bus_space_write_1(bst, bsh, nsp_fifodr, 0); + (void) bus_write_1(sc->port_res, nsp_fifodr, 0); } - nsp_cr_write_1(bst, bsh, NSPR_XFERMR, sc->sc_xfermr); + nsp_cr_write_1(sc->port_res, NSPR_XFERMR, sc->sc_xfermr); } static int nsp_read_fifo(sc, suspendio) struct nsp_softc *sc; int suspendio; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int res; res = nsp_fifo_count(sc); if (res == sc->sc_cnt) return 0; #ifdef NSP_DEBUG if (res < sc->sc_cnt || res == (u_int) -1) { device_printf(slp->sl_dev, "strange fifo ack count 0x%x < 0x%x\n", res, sc->sc_cnt); return 0; } #endif /* NSP_DEBUG */ res = res - sc->sc_cnt; if (res > slp->sl_scp.scp_datalen) { if ((slp->sl_error & PDMAERR) == 0) { device_printf(slp->sl_dev, "data overrun 0x%x > 0x%x\n", res, slp->sl_scp.scp_datalen); } slp->sl_error |= PDMAERR; slp->sl_scp.scp_datalen = 0; if ((slp->sl_flags & HW_READ_PADDING) == 0) { device_printf(slp->sl_dev, "read padding required\n"); return 0; } nsp_data_padding(sc, SCSI_LOW_READ, res); sc->sc_cnt += res; return 1; /* padding start */ } if (suspendio > 0 && slp->sl_scp.scp_datalen >= suspendio) res = suspendio; if ((sc->sc_xfermr & (XFERMR_MEM32 | XFERMR_MEM8)) != 0) { if ((sc->sc_xfermr & XFERMR_MEM32) != 0) { res &= ~3; - bus_space_read_region_4(sc->sc_memt, sc->sc_memh, 0, + bus_read_region_4(sc->mem_res, 0, (u_int32_t *) slp->sl_scp.scp_data, res >> 2); } else { - bus_space_read_region_1(sc->sc_memt, sc->sc_memh, 0, + bus_read_region_1(sc->mem_res, 0, (u_int8_t *) slp->sl_scp.scp_data, res); } } else { if ((sc->sc_xfermr & XFERMR_IO32) != 0) { res &= ~3; - bus_space_read_multi_4(bst, bsh, nsp_fifodr, + bus_read_multi_4(sc->port_res, nsp_fifodr, (u_int32_t *) slp->sl_scp.scp_data, res >> 2); } else { - bus_space_read_multi_1(bst, bsh, nsp_fifodr, + bus_read_multi_1(sc->port_res, nsp_fifodr, (u_int8_t *) slp->sl_scp.scp_data, res); } } - if (nsp_cr_read_1(bst, bsh, NSPR_PARITYR) & PARITYR_PE) + if (nsp_cr_read_1(sc->port_res, NSPR_PARITYR) & PARITYR_PE) { - nsp_cr_write_1(bst, bsh, NSPR_PARITYR, + nsp_cr_write_1(sc->port_res, NSPR_PARITYR, PARITYR_ENABLE | PARITYR_CLEAR); scsi_low_assert_msg(slp, slp->sl_Tnexus, SCSI_LOW_MSG_ERROR, 1); } slp->sl_scp.scp_data += res; slp->sl_scp.scp_datalen -= res; sc->sc_cnt += res; return 0; } static int nsp_write_fifo(sc, suspendio) struct nsp_softc *sc; int suspendio; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int res; register u_int8_t stat; if (suspendio > 0) { #ifdef NSP_DEBUG if ((slp->sl_scp.scp_datalen % WFIFO_CRIT) != 0) { device_printf(slp->sl_dev, "strange write length 0x%x\n", slp->sl_scp.scp_datalen); } #endif /* NSP_DEBUG */ res = slp->sl_scp.scp_datalen % suspendio; if (res == 0) { res = suspendio; } } else { res = WFIFO_CRIT; } if (res > slp->sl_scp.scp_datalen) res = slp->sl_scp.scp_datalen; /* XXX: reconfirm! */ - stat = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON) & SCBUSMON_PHMASK; + stat = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON) & SCBUSMON_PHMASK; if (stat != PHASE_DATAOUT) return 0; if ((sc->sc_xfermr & (XFERMR_MEM32 | XFERMR_MEM8)) != 0) { if ((sc->sc_xfermr & XFERMR_MEM32) != 0) { - bus_space_write_region_4(sc->sc_memt, sc->sc_memh, 0, + bus_write_region_4(sc->mem_res, 0, (u_int32_t *) slp->sl_scp.scp_data, res >> 2); } else { - bus_space_write_region_1(sc->sc_memt, sc->sc_memh, 0, + bus_write_region_1(sc->mem_res, 0, (u_int8_t *) slp->sl_scp.scp_data, res); } } else { if ((sc->sc_xfermr & XFERMR_IO32) != 0) { - bus_space_write_multi_4(bst, bsh, nsp_fifodr, + bus_write_multi_4(sc->port_res, nsp_fifodr, (u_int32_t *) slp->sl_scp.scp_data, res >> 2); } else { - bus_space_write_multi_1(bst, bsh, nsp_fifodr, + bus_write_multi_1(sc->port_res, nsp_fifodr, (u_int8_t *) slp->sl_scp.scp_data, res); } } slp->sl_scp.scp_datalen -= res; slp->sl_scp.scp_data += res; sc->sc_cnt += res; return 0; } static int nsp_wait_interrupt(sc) struct nsp_softc *sc; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int tout; register u_int8_t isrc; for (tout = 0; tout < DEV_BSIZE / 10; tout ++) { - isrc = bus_space_read_1(bst, bsh, nsp_irqsr); + isrc = bus_read_1(sc->port_res, nsp_irqsr); if ((isrc & (IRQSR_SCSI | IRQSR_FIFO)) != 0) { if ((isrc & IRQSR_FIFO) != 0) { - bus_space_write_1(bst, bsh, + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_FIFOCL); } return 1; } DELAY(1); } return 0; } static void nsp_pio_read(sc, suspendio) struct nsp_softc *sc; int suspendio; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int tout, padding, datalen; register u_int8_t stat, fstat; padding = 0; tout = sc->sc_tmaxcnt; slp->sl_flags |= HW_PDMASTART; datalen = slp->sl_scp.scp_datalen; ReadLoop: while (1) { - stat = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + stat = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if (stat == (u_int8_t) -1) return; /* out of data phase */ if ((stat & SCBUSMON_PHMASK) != PHASE_DATAIN) { nsp_read_fifo(sc, 0); return; } /* data phase */ - fstat = bus_space_read_1(bst, bsh, nsp_fifosr); + fstat = bus_read_1(sc->port_res, nsp_fifosr); if ((fstat & FIFOSR_FULLEMP) != 0) { if ((sc->sc_icr & SCIENR_FIFO) != 0) { - bus_space_write_1(bst, bsh, nsp_irqcr, + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_FIFOCL); } if (suspendio > 0) { padding |= nsp_read_fifo(sc, suspendio); } else { padding |= nsp_read_fifo(sc, 0); } if ((sc->sc_icr & SCIENR_FIFO) != 0) break; } else { if (padding == 0 && slp->sl_scp.scp_datalen <= 0) return; if ((sc->sc_icr & SCIENR_FIFO) != 0) break; DELAY(1); } if ((-- tout) <= 0) { device_printf(slp->sl_dev, "nsp_pio_read: timeout\n"); return; } } if (slp->sl_scp.scp_datalen > 0 && slp->sl_scp.scp_datalen > datalen - nsp_read_interrupt_bytes) { if (nsp_wait_interrupt(sc) != 0) goto ReadLoop; } } static void nsp_pio_write(sc, suspendio) struct nsp_softc *sc; int suspendio; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; u_int rcount, acount; int tout, datalen; register u_int8_t stat, fstat; tout = sc->sc_tmaxcnt; slp->sl_flags |= HW_PDMASTART; datalen = slp->sl_scp.scp_datalen; WriteLoop: while (1) { - stat = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON) & SCBUSMON_PHMASK; + stat = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON) & SCBUSMON_PHMASK; if (stat != PHASE_DATAOUT) return; if (slp->sl_scp.scp_datalen <= 0) { if (sc->sc_dataout_timeout == 0) sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ; return; } - fstat = bus_space_read_1(bst, bsh, nsp_fifosr); + fstat = bus_read_1(sc->port_res, nsp_fifosr); if ((fstat & FIFOSR_FULLEMP) != 0) { if ((sc->sc_icr & SCIENR_FIFO) != 0) { - bus_space_write_1(bst, bsh, nsp_irqcr, + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_FIFOCL); } if (suspendio > 0) { /* XXX:IMPORTANT: * To avoid timeout of pcmcia bus * (not scsi bus!), we should check * the scsi device sends us request * signals, which means the scsi device * is ready to recieve data without * heavy delays. */ if ((slp->sl_scp.scp_datalen % suspendio) == 0) { /* Step I: * fill the nsp fifo, and waiting for * the fifo empty. */ nsp_write_fifo(sc, 0); } else { /* Step II: * check the request singals. */ acount = nsp_fifo_count(sc); rcount = nsp_request_count(sc); if (rcount <= acount) { nsp_write_fifo(sc, 0); #ifdef NSP_STATICS nsp_statics.device_busy ++; #endif /* NSP_STATICS */ } else { nsp_write_fifo(sc, suspendio); #ifdef NSP_STATICS nsp_statics.device_data_write ++; #endif /* NSP_STATICS */ } } } else { nsp_write_fifo(sc, 0); } if ((sc->sc_icr & SCIENR_FIFO) != 0) break; } else { if ((sc->sc_icr & SCIENR_FIFO) != 0) break; DELAY(1); } if ((-- tout) <= 0) { device_printf(slp->sl_dev, "nsp_pio_write: timeout\n"); return; } } if (slp->sl_scp.scp_datalen > 0 && slp->sl_scp.scp_datalen > datalen - nsp_write_interrupt_bytes) { if (nsp_wait_interrupt(sc) != 0) goto WriteLoop; } } static int nsp_negate_signal(struct nsp_softc *sc, u_int8_t mask, u_char *s) { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int wc; u_int8_t regv; for (wc = 0; wc < NSP_DELAY_MAX / NSP_DELAY_INTERVAL; wc ++) { - regv = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + regv = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if (regv == (u_int8_t) -1) return -1; if ((regv & mask) == 0) return 1; DELAY(NSP_DELAY_INTERVAL); } device_printf(slp->sl_dev, "%s nsp_negate_signal timeout\n", s); return -1; } static int nsp_xfer(sc, buf, len, phase, clear_atn) struct nsp_softc *sc; u_int8_t *buf; int len; int phase; int clear_atn; { - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int ptr, rv; for (ptr = 0; len > 0; len --, ptr ++) { rv = nsp_expect_signal(sc, phase, SCBUSMON_REQ); if (rv <= 0) goto out; if (len == 1 && clear_atn != 0) { - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, SCBUSCR_ADIR | SCBUSCR_ACKEN); SCSI_LOW_DEASSERT_ATN(&sc->sc_sclow); } if (phase & SCBUSMON_IO) { - buf[ptr] = nsp_cr_read_1(bst, bsh, NSPR_DATAACK); + buf[ptr] = nsp_cr_read_1(sc->port_res, NSPR_DATAACK); } else { - nsp_cr_write_1(bst, bsh, NSPR_DATAACK, buf[ptr]); + nsp_cr_write_1(sc->port_res, NSPR_DATAACK, buf[ptr]); } nsp_negate_signal(sc, SCBUSMON_ACK, "xfer"); } out: return len; } /************************************************************** * disconnect & reselect (HW low) **************************************************************/ static int nsp_reselected(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; struct targ_info *ti; u_int sid; u_int8_t cr; - sid = (u_int) nsp_cr_read_1(bst, bsh, NSPR_RESELR); + sid = (u_int) nsp_cr_read_1(sc->port_res, NSPR_RESELR); sid &= ~sc->sc_idbit; sid = ffs(sid) - 1; if ((ti = scsi_low_reselected(slp, sid)) == NULL) return EJUSTRETURN; nsp_negate_signal(sc, SCBUSMON_SEL, "reselect"); - cr = nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR); + cr = nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR); cr &= ~(SCBUSCR_BSY | SCBUSCR_ATN); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); cr |= SCBUSCR_ADIR | SCBUSCR_ACKEN; - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); #ifdef NSP_STATICS nsp_statics.reselect ++; #endif /* NSP_STATCIS */ return EJUSTRETURN; } static int nsp_disconnected(sc, ti) struct nsp_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; - nsp_cr_write_1(bst, bsh, NSPR_PTCLRR, PTCLRR_PT | PTCLRR_ACK | + nsp_cr_write_1(sc->port_res, NSPR_PTCLRR, PTCLRR_PT | PTCLRR_ACK | PTCLRR_REQ | PTCLRR_HOST); if ((sc->sc_icr & SCIENR_FIFO) != 0) { sc->sc_icr &= ~SCIENR_FIFO; - nsp_cr_write_1(bst, bsh, NSPR_SCIENR, sc->sc_icr); + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); } sc->sc_cnt = 0; sc->sc_dataout_timeout = 0; #ifdef NSP_STATICS nsp_statics.disconnect ++; #endif /* NSP_STATICS */ scsi_low_disconnected(slp, ti); return 1; } /************************************************************** * SEQUENCER **************************************************************/ static void nsp_error(struct nsp_softc *, u_char *, u_int8_t, u_int8_t, u_int8_t); static void nsp_error(struct nsp_softc * sc, u_char *s, u_int8_t isrc, u_int8_t ph, u_int8_t irqphs) { struct scsi_low_softc *slp = &sc->sc_sclow; device_printf(slp->sl_dev, "%s\n", s); device_printf(slp->sl_dev, "isrc 0x%x scmon 0x%x irqphs 0x%x\n", (u_int) isrc, (u_int) ph, (u_int) irqphs); } static int nsp_target_nexus_establish(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; struct targ_info *ti = slp->sl_Tnexus; struct nsp_targ_info *nti = (void *) ti; /* setup synch transfer registers */ - nsp_cr_write_1(bst, bsh, NSPR_SYNCR, nti->nti_reg_syncr); - nsp_cr_write_1(bst, bsh, NSPR_ACKWIDTH, nti->nti_reg_ackwidth); + nsp_cr_write_1(sc->port_res, NSPR_SYNCR, nti->nti_reg_syncr); + nsp_cr_write_1(sc->port_res, NSPR_ACKWIDTH, nti->nti_reg_ackwidth); /* setup pdma fifo (minimum) */ nsp_setup_fifo(sc, NSP_FIFO_ON, SCSI_LOW_READ, 0); return 0; } static int nsp_lun_nexus_establish(sc) struct nsp_softc *sc; { return 0; } static int nsp_ccb_nexus_establish(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; struct slccb *cb = slp->sl_Qnexus; sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; /* setup pdma fifo */ nsp_setup_fifo(sc, NSP_FIFO_ON, slp->sl_scp.scp_direction, slp->sl_scp.scp_datalen); if (slp->sl_scp.scp_direction == SCSI_LOW_READ) { if (sc->sc_suspendio > 0 && (nsp_io_control & NSP_READ_FIFO_INTERRUPTS) != 0) { sc->sc_icr |= SCIENR_FIFO; - nsp_cr_write_1(sc->sc_iot, sc->sc_ioh, + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); } } else { if (sc->sc_suspendio > 0 && (nsp_io_control & NSP_WRITE_FIFO_INTERRUPTS) != 0) { sc->sc_icr |= SCIENR_FIFO; - nsp_cr_write_1(sc->sc_iot, sc->sc_ioh, + nsp_cr_write_1(sc->port_res, NSPR_SCIENR, sc->sc_icr); } } return 0; } static int nsp_phase_match(struct nsp_softc *sc, u_int8_t phase, u_int8_t stat) { struct scsi_low_softc *slp = &sc->sc_sclow; if ((stat & SCBUSMON_PHMASK) != phase) { device_printf(slp->sl_dev, "phase mismatch 0x%x != 0x%x\n", (u_int) phase, (u_int) stat); return EINVAL; } if ((stat & SCBUSMON_REQ) == 0) return EINVAL; return 0; } int nspintr(arg) void *arg; { struct nsp_softc *sc = arg; struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; struct targ_info *ti; struct buf *bp; u_int derror, flags; int len, rv; u_int8_t isrc, ph, irqphs, cr, regv; /******************************************* * interrupt check *******************************************/ if (slp->sl_flags & HW_INACTIVE) return 0; - bus_space_write_1(bst, bsh, nsp_irqcr, IRQCR_IRQDIS); - isrc = bus_space_read_1(bst, bsh, nsp_irqsr); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_IRQDIS); + isrc = bus_read_1(sc->port_res, nsp_irqsr); if (isrc == (u_int8_t) -1 || (isrc & IRQSR_MASK) == 0) { - bus_space_write_1(bst, bsh, nsp_irqcr, 0); + bus_write_1(sc->port_res, nsp_irqcr, 0); return 0; } /* XXX: IMPORTANT * Do not read an irqphs register if no scsi phase interrupt. * Unless, you should lose a scsi phase interrupt. */ - ph = nsp_cr_read_1(bst, bsh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((isrc & IRQSR_SCSI) != 0) { - irqphs = nsp_cr_read_1(bst, bsh, NSPR_IRQPHS); + irqphs = nsp_cr_read_1(sc->port_res, NSPR_IRQPHS); } else irqphs = 0; /* * timer interrupt handler (scsi vs timer interrupts) */ if (sc->sc_timer != 0) { - nsp_cr_write_1(bst, bsh, NSPR_TIMERCNT, 0); - nsp_cr_write_1(bst, bsh, NSPR_TIMERCNT, 0); + nsp_cr_write_1(sc->port_res, NSPR_TIMERCNT, 0); + nsp_cr_write_1(sc->port_res, NSPR_TIMERCNT, 0); sc->sc_timer = 0; } /* check a timer interrupt */ regv = 0; if ((isrc & IRQSR_TIMER) != 0) { if ((isrc & IRQSR_MASK) == IRQSR_TIMER && sc->sc_seltout == 0) { - bus_space_write_1(bst, bsh, nsp_irqcr, IRQCR_TIMERCL); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_TIMERCL); return 1; } regv |= IRQCR_TIMERCL; } /* check a fifo interrupt */ if ((isrc & IRQSR_FIFO) != 0) { regv |= IRQCR_FIFOCL; } /* OK. enable all interrupts */ - bus_space_write_1(bst, bsh, nsp_irqcr, regv); + bus_write_1(sc->port_res, nsp_irqcr, regv); /******************************************* * debug section *******************************************/ #ifdef NSP_DEBUG if (nsp_debug) { nsp_error(sc, "current status", isrc, ph, irqphs); scsi_low_print(slp, NULL); #ifdef KDB if (nsp_debug > 1) kdb_enter(KDB_WHY_CAM, "nsp"); #endif /* KDB */ } #endif /* NSP_DEBUG */ /******************************************* * Parse hardware SCSI irq reasons register *******************************************/ if ((isrc & IRQSR_SCSI) != 0) { if ((irqphs & IRQPHS_RST) != 0) { scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT, "bus reset (power off?)"); return 1; } if ((irqphs & IRQPHS_RSEL) != 0) { - bus_space_write_1(bst, bsh, nsp_irqcr, IRQCR_RESCL); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_RESCL); if (nsp_reselected(sc) == EJUSTRETURN) return 1; } if ((irqphs & (IRQPHS_PCHG | IRQPHS_LBF)) == 0) return 1; } /******************************************* * nexus check *******************************************/ if ((ti = slp->sl_Tnexus) == NULL) { /* unknown scsi phase changes */ nsp_error(sc, "unknown scsi phase changes", isrc, ph, irqphs); return 0; } /******************************************* * aribitration & selection *******************************************/ switch (ti->ti_phase) { case PH_SELSTART: if ((ph & SCBUSMON_BSY) == 0) { if (sc->sc_seltout >= NSP_SELTIMEOUT) { sc->sc_seltout = 0; - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, 0); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, 0); return nsp_disconnected(sc, ti); } sc->sc_seltout ++; nsp_start_timer(sc, NSP_TIMER_1MS); return 1; } SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); nsphw_selection_done_and_expect_msgout(sc); return 1; case PH_SELECTED: if ((isrc & IRQSR_SCSI) == 0) return 1; nsp_target_nexus_establish(sc); break; case PH_RESEL: if ((isrc & IRQSR_SCSI) == 0) return 1; nsp_target_nexus_establish(sc); if ((ph & SCBUSMON_PHMASK) != PHASE_MSGIN) { device_printf(slp->sl_dev, "unexpected phase after reselect\n"); slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); return 1; } break; case PH_DATA: if ((isrc & IRQSR_SCSI) != 0) break; if ((isrc & IRQSR_FIFO) != 0) { if (NSP_IS_PHASE_DATA(ph) == 0) return 1; irqphs = (ph & IRQPHS_PHMASK); break; } return 1; default: if ((isrc & IRQSR_SCSI) == 0) return 1; break; } /******************************************* * data phase control *******************************************/ if (slp->sl_flags & HW_PDMASTART) { if ((isrc & IRQSR_SCSI) != 0 && NSP_IS_IRQPHS_DATA(irqphs) == 0) { if (slp->sl_scp.scp_direction == SCSI_LOW_READ) nsp_pio_read(sc, 0); nsp_pdma_end(sc, ti); } } /******************************************* * scsi seq *******************************************/ if (slp->sl_msgphase != 0 && (irqphs & IRQPHS_LBF) != 0) return nsp_disconnected(sc, ti); /* check unexpected bus free state */ if (ph == 0) { nsp_error(sc, "unexpected bus free", isrc, ph, irqphs); return nsp_disconnected(sc, ti); } /* check normal scsi phase */ switch (irqphs & IRQPHS_PHMASK) { case IRQPHS_CMD: if (nsp_phase_match(sc, PHASE_CMD, ph) != 0) return 1; SCSI_LOW_SETUP_PHASE(ti, PH_CMD); if (scsi_low_cmd(slp, ti) != 0) { scsi_low_attention(slp); } - nsp_cr_write_1(bst, bsh, NSPR_CMDCR, CMDCR_PTCLR); + nsp_cr_write_1(sc->port_res, NSPR_CMDCR, CMDCR_PTCLR); for (len = 0; len < slp->sl_scp.scp_cmdlen; len ++) - nsp_cr_write_1(bst, bsh, NSPR_CMDDR, + nsp_cr_write_1(sc->port_res, NSPR_CMDDR, slp->sl_scp.scp_cmd[len]); - nsp_cr_write_1(bst, bsh, NSPR_CMDCR, CMDCR_PTCLR | CMDCR_EXEC); + nsp_cr_write_1(sc->port_res, NSPR_CMDCR, CMDCR_PTCLR | CMDCR_EXEC); break; case IRQPHS_DATAOUT: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_WRITE) != 0) { scsi_low_attention(slp); } nsp_pio_write(sc, sc->sc_suspendio); break; case IRQPHS_DATAIN: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_READ) != 0) { scsi_low_attention(slp); } nsp_pio_read(sc, sc->sc_suspendio); break; case IRQPHS_STATUS: if (nsp_phase_match(sc, PHASE_STATUS, ph) != 0) return 1; SCSI_LOW_SETUP_PHASE(ti, PH_STAT); - regv = nsp_cr_read_1(bst, bsh, NSPR_DATA); - if (nsp_cr_read_1(bst, bsh, NSPR_PARITYR) & PARITYR_PE) + regv = nsp_cr_read_1(sc->port_res, NSPR_DATA); + if (nsp_cr_read_1(sc->port_res, NSPR_PARITYR) & PARITYR_PE) { - nsp_cr_write_1(bst, bsh, NSPR_PARITYR, + nsp_cr_write_1(sc->port_res, NSPR_PARITYR, PARITYR_ENABLE | PARITYR_CLEAR); derror = SCSI_LOW_DATA_PE; } else derror = 0; /* assert ACK */ - cr = SCBUSCR_ACK | nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + cr = SCBUSCR_ACK | nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); if (scsi_low_statusin(slp, ti, derror | regv) != 0) { scsi_low_attention(slp); } /* check REQ nagated */ nsp_negate_signal(sc, SCBUSMON_REQ, "statin"); /* deassert ACK */ - cr = nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR) & (~SCBUSCR_ACK); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + cr = nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR) & (~SCBUSCR_ACK); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); break; case IRQPHS_MSGOUT: if (nsp_phase_match(sc, PHASE_MSGOUT, ph) != 0) return 1; #ifdef NSP_MSGOUT_SERIALIZE /* * XXX: NSP QUIRK * NSP invoke interrupts only in the case of scsi phase changes, * therefore we should poll the scsi phase here to catch * the next "msg out" if exists (no scsi phase changes). */ rv = len = 16; do { SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); flags = (ti->ti_ophase != ti->ti_phase) ? SCSI_LOW_MSGOUT_INIT : 0; len = scsi_low_msgout(slp, ti, flags); if (len > 1 && slp->sl_atten == 0) { scsi_low_attention(slp); } if (nsp_xfer(sc, ti->ti_msgoutstr, len, PHASE_MSGOUT, slp->sl_clear_atten) != 0) { slp->sl_error |= FATALIO; nsp_error(sc, "MSGOUT: xfer short", isrc, ph, irqphs); } /* catch a next signal */ rv = nsp_expect_signal(sc, PHASE_MSGOUT, SCBUSMON_REQ); } while (rv > 0 && len -- > 0); #else /* !NSP_MSGOUT_SERIALIZE */ SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); flags = SCSI_LOW_MSGOUT_UNIFY; if (ti->ti_ophase != ti->ti_phase) flags |= SCSI_LOW_MSGOUT_INIT; len = scsi_low_msgout(slp, ti, flags); if (len > 1 && slp->sl_atten == 0) { scsi_low_attention(slp); } if (nsp_xfer(sc, ti->ti_msgoutstr, len, PHASE_MSGOUT, slp->sl_clear_atten) != 0) { nsp_error(sc, "MSGOUT: xfer short", isrc, ph, irqphs); } #endif /* !NSP_MSGOUT_SERIALIZE */ break; case IRQPHS_MSGIN: if (nsp_phase_match(sc, PHASE_MSGIN, ph) != 0) return 1; /* * XXX: NSP QUIRK * NSP invoke interrupts only in the case of scsi phase changes, * therefore we should poll the scsi phase here to catch * the next "msg in" if exists (no scsi phase changes). */ rv = len = 16; do { SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); /* read a data */ - regv = nsp_cr_read_1(bst, bsh, NSPR_DATA); - if (nsp_cr_read_1(bst, bsh, NSPR_PARITYR) & PARITYR_PE) + regv = nsp_cr_read_1(sc->port_res, NSPR_DATA); + if (nsp_cr_read_1(sc->port_res, NSPR_PARITYR) & PARITYR_PE) { - nsp_cr_write_1(bst, bsh, + nsp_cr_write_1(sc->port_res, NSPR_PARITYR, PARITYR_ENABLE | PARITYR_CLEAR); derror = SCSI_LOW_DATA_PE; } else { derror = 0; } /* assert ack */ - cr = nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR) | SCBUSCR_ACK; - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + cr = nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR) | SCBUSCR_ACK; + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); if (scsi_low_msgin(slp, ti, regv | derror) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) { scsi_low_attention(slp); } } /* check REQ nagated */ nsp_negate_signal(sc, SCBUSMON_REQ, "msgin"); /* deassert ack */ - cr = nsp_cr_read_1(bst, bsh, NSPR_SCBUSCR) & (~SCBUSCR_ACK); - nsp_cr_write_1(bst, bsh, NSPR_SCBUSCR, cr); + cr = nsp_cr_read_1(sc->port_res, NSPR_SCBUSCR) & (~SCBUSCR_ACK); + nsp_cr_write_1(sc->port_res, NSPR_SCBUSCR, cr); /* catch a next signal */ rv = nsp_expect_signal(sc, PHASE_MSGIN, SCBUSMON_REQ); } while (rv > 0 && len -- > 0); break; default: slp->sl_error |= FATALIO; nsp_error(sc, "unknown scsi phase", isrc, ph, irqphs); break; } return 1; #if 0 timerout: nsp_start_timer(sc, NSP_TIMER_1MS); return 0; #endif } static int nsp_timeout(sc) struct nsp_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; int tout; u_int8_t ph, regv; if (slp->sl_Tnexus == NULL) return 0; - ph = nsp_cr_read_1(iot, ioh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); switch (ph & SCBUSMON_PHMASK) { case PHASE_DATAOUT: if (sc->sc_dataout_timeout == 0) break; /* check a fifo empty */ - regv = bus_space_read_1(iot, ioh, nsp_fifosr); + regv = bus_read_1(sc->port_res, nsp_fifosr); if ((regv & FIFOSR_FULLEMP) == 0) break; - bus_space_write_1(iot, ioh, nsp_irqcr, IRQCR_FIFOCL); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_FIFOCL); /* check still requested */ - ph = nsp_cr_read_1(iot, ioh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((ph & SCBUSMON_REQ) == 0) break; /* check timeout */ if ((-- sc->sc_dataout_timeout) > 0) break; slp->sl_error |= PDMAERR; if ((slp->sl_flags & HW_WRITE_PADDING) == 0) { device_printf(slp->sl_dev, "write padding required\n"); break; } tout = NSP_DELAY_MAX; while (tout -- > 0) { - ph = nsp_cr_read_1(iot, ioh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((ph & SCBUSMON_PHMASK) != PHASE_DATAOUT) break; - regv = bus_space_read_1(iot, ioh, nsp_fifosr); + regv = bus_read_1(sc->port_res, nsp_fifosr); if ((regv & FIFOSR_FULLEMP) == 0) { DELAY(1); continue; } - bus_space_write_1(iot, ioh, nsp_irqcr, IRQCR_FIFOCL); + bus_write_1(sc->port_res, nsp_irqcr, IRQCR_FIFOCL); nsp_data_padding(sc, SCSI_LOW_WRITE, 32); } - ph = nsp_cr_read_1(iot, ioh, NSPR_SCBUSMON); + ph = nsp_cr_read_1(sc->port_res, NSPR_SCBUSMON); if ((ph & SCBUSMON_PHMASK) == PHASE_DATAOUT) sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ; break; default: break; } return 0; } Index: projects/sendfile/sys/dev/nsp/nsp_pccard.c =================================================================== --- projects/sendfile/sys/dev/nsp/nsp_pccard.c (revision 274764) +++ projects/sendfile/sys/dev/nsp/nsp_pccard.c (revision 274765) @@ -1,304 +1,291 @@ /* $NecBSD: nsp_pisa.c,v 1.4 1999/04/15 01:35:54 kmatsuda Exp $ */ /* $NetBSD$ */ /*- * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1998 * NetBSD/pc98 porting staff. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #define NSP_HOSTID 7 #include "pccarddevs.h" #define PIO_MODE 0x100 /* pd_flags */ static int nspprobe(device_t devi); static int nspattach(device_t devi); static void nsp_card_unload (device_t); const struct pccard_product nsp_products[] = { PCMCIA_CARD(IODATA3, CBSC16), PCMCIA_CARD(PANASONIC, KME), PCMCIA_CARD(WORKBIT2, NINJA_SCSI3), PCMCIA_CARD(WORKBIT, ULTRA_NINJA_16), { NULL } }; /* * Additional code for FreeBSD new-bus PC Card frontend */ static void nsp_pccard_intr(void * arg) { - nspintr(arg); + struct nsp_softc *sc; + + sc = arg; + SCSI_LOW_LOCK(&sc->sc_sclow); + nspintr(sc); + SCSI_LOW_UNLOCK(&sc->sc_sclow); } static void nsp_release_resource(device_t dev) { struct nsp_softc *sc = device_get_softc(dev); if (sc->nsp_intrhand) bus_teardown_intr(dev, sc->irq_res, sc->nsp_intrhand); if (sc->port_res) bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, sc->port_res); if (sc->irq_res) bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); if (sc->mem_res) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); + mtx_destroy(&sc->sc_sclow.sl_lock); } static int nsp_alloc_resource(device_t dev) { struct nsp_softc *sc = device_get_softc(dev); u_long ioaddr, iosize, maddr, msize; int error; error = bus_get_resource(dev, SYS_RES_IOPORT, 0, &ioaddr, &iosize); if (error || iosize < NSP_IOSIZE) return(ENOMEM); + mtx_init(&sc->sc_sclow.sl_lock, "nsp", NULL, MTX_DEF); sc->port_rid = 0; sc->port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->port_rid, 0, ~0, NSP_IOSIZE, RF_ACTIVE); if (sc->port_res == NULL) { nsp_release_resource(dev); return(ENOMEM); } sc->irq_rid = 0; sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE); if (sc->irq_res == NULL) { nsp_release_resource(dev); return(ENOMEM); } error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize); if (error) return(0); /* XXX */ /* No need to allocate memory if not configured and it's in PIO mode */ if (maddr == 0 || msize == 0) { if ((device_get_flags(dev) & PIO_MODE) == 0) { printf("Memory window was not configured. Configure or use in PIO mode."); nsp_release_resource(dev); return(ENOMEM); } /* no need to allocate memory if PIO mode */ return(0); } sc->mem_rid = 0; sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE); if (sc->mem_res == NULL) { nsp_release_resource(dev); return(ENOMEM); } return(0); } static int nsp_pccard_probe(device_t dev) { const struct pccard_product *pp; if ((pp = pccard_product_lookup(dev, nsp_products, sizeof(nsp_products[0]), NULL)) != NULL) { if (pp->pp_name) device_set_desc(dev, pp->pp_name); - return(0); + return (BUS_PROBE_DEFAULT); } return(EIO); } static int nsp_pccard_attach(device_t dev) { struct nsp_softc *sc = device_get_softc(dev); int error; error = nsp_alloc_resource(dev); if (error) return(error); if (nspprobe(dev) == 0) { nsp_release_resource(dev); return(ENXIO); } - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, nsp_pccard_intr, (void *)sc, &sc->nsp_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, nsp_pccard_intr, sc, &sc->nsp_intrhand); if (error) { nsp_release_resource(dev); return(error); } if (nspattach(dev) == 0) { nsp_release_resource(dev); return(ENXIO); } return(0); } static int nsp_pccard_detach(device_t dev) { nsp_card_unload(dev); nsp_release_resource(dev); return (0); } static device_method_t nsp_pccard_methods[] = { /* Device interface */ DEVMETHOD(device_probe, nsp_pccard_probe), DEVMETHOD(device_attach, nsp_pccard_attach), DEVMETHOD(device_detach, nsp_pccard_detach), { 0, 0 } }; static driver_t nsp_pccard_driver = { "nsp", nsp_pccard_methods, sizeof(struct nsp_softc), }; static devclass_t nsp_devclass; MODULE_DEPEND(nsp, scsi_low, 1, 1, 1); DRIVER_MODULE(nsp, pccard, nsp_pccard_driver, nsp_devclass, 0, 0); static void nsp_card_unload(device_t devi) { struct nsp_softc *sc = device_get_softc(devi); - intrmask_t s; - s = splcam(); - scsi_low_deactivate((struct scsi_low_softc *)sc); - scsi_low_dettach(&sc->sc_sclow); - splx(s); + scsi_low_deactivate(&sc->sc_sclow); + scsi_low_detach(&sc->sc_sclow); } static int nspprobe(device_t devi) { int rv; struct nsp_softc *sc = device_get_softc(devi); - rv = nspprobesubr(rman_get_bustag(sc->port_res), - rman_get_bushandle(sc->port_res), + rv = nspprobesubr(sc->port_res, device_get_flags(devi)); return rv; } static int nspattach(device_t devi) { struct nsp_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(devi); u_int iobase = bus_get_resource_start(devi, SYS_RES_IOPORT, 0); - intrmask_t s; - char dvname[16]; - strcpy(dvname,"nsp"); - if (iobase == 0) { - printf("%s: no ioaddr is given\n", dvname); - return (0); + device_printf(devi, "no ioaddr is given\n"); + return (ENXIO); } sc = device_get_softc(devi); - if (sc == NULL) - return (0); - slp = &sc->sc_sclow; slp->sl_dev = devi; - sc->sc_iot = rman_get_bustag(sc->port_res); - sc->sc_ioh = rman_get_bushandle(sc->port_res); if (sc->mem_res == NULL) { - printf("WARNING: CANNOT GET Memory RESOURCE going PIO mode"); + device_printf(devi, + "WARNING: CANNOT GET Memory RESOURCE going PIO mode\n"); flags |= PIO_MODE; } - if ((flags & PIO_MODE) == 0) { - sc->sc_memt = rman_get_bustag(sc->mem_res); - sc->sc_memh = rman_get_bushandle(sc->mem_res); - } else { - sc->sc_memh = 0; - } /* slp->sl_irq = devi->pd_irq; */ sc->sc_iclkdiv = CLKDIVR_20M; sc->sc_clkdiv = CLKDIVR_40M; slp->sl_hostid = NSP_HOSTID; slp->sl_cfgflags = flags; - s = splcam(); nspattachsubr(sc); - splx(s); return(NSP_IOSIZE); } Index: projects/sendfile/sys/dev/nsp/nspvar.h =================================================================== --- projects/sendfile/sys/dev/nsp/nspvar.h (revision 274764) +++ projects/sendfile/sys/dev/nsp/nspvar.h (revision 274765) @@ -1,96 +1,91 @@ /* $FreeBSD$ */ /* $NecBSD: nspvar.h,v 1.7.14.5 2001/06/29 06:27:54 honda Exp $ */ /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * * Copyright (c) 1998, 1999, 2000, 2001 * Naofumi HONDA. 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. */ #ifndef _NSPVAR_H_ #define _NSPVAR_H_ /***************************************************************** * Host adapter structure *****************************************************************/ struct nsp_softc { struct scsi_low_softc sc_sclow; /* generic data */ - bus_space_tag_t sc_iot; - bus_space_handle_t sc_ioh; - bus_space_tag_t sc_memt; - bus_space_handle_t sc_memh; - int port_rid; int irq_rid; int mem_rid; struct resource *port_res; struct resource *irq_res; struct resource *mem_res; void *nsp_intrhand; int sc_tmaxcnt; /* timeout count */ int sc_seltout; /* selection timeout counter */ int sc_timer; /* timer start */ int sc_suspendio; /* SMIT: data suspendio bytes */ u_int8_t sc_xfermr; /* SMIT: fifo control reg */ int sc_dataout_timeout; /* data out timeout counter */ u_int sc_idbit; /* host id bit pattern */ u_int sc_cnt; /* fifo R/W count (host) */ u_int8_t sc_iclkdiv; /* scsi chip clock divisor */ u_int8_t sc_clkdiv; /* asic chip clock divisor */ u_int8_t sc_icr; /* interrupt control reg */ u_int8_t sc_busc; /* busc registers */ u_int8_t sc_parr; /* parity control register */ }; /***************************************************************** * Lun information *****************************************************************/ struct nsp_targ_info { struct targ_info nti_ti; /* generic lun info */ u_int8_t nti_reg_syncr; /* sync registers per devices */ u_int8_t nti_reg_ackwidth; /* ackwidth per devices */ }; /***************************************************************** * Proto *****************************************************************/ -int nspprobesubr(bus_space_tag_t, bus_space_handle_t, u_int); +int nspprobesubr(struct resource *, u_int); void nspattachsubr(struct nsp_softc *); int nspintr(void *); #endif /* !_NSPVAR_H_ */ Index: projects/sendfile/sys/dev/stg/tmc18c30.c =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30.c (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30.c (revision 274765) @@ -1,1377 +1,1327 @@ /* $NecBSD: tmc18c30.c,v 1.28.12.3 2001/06/19 04:35:48 honda Exp $ */ /* $NetBSD$ */ #define STG_DEBUG #define STG_STATICS #define STG_IO_CONTROL_FLAGS (STG_FIFO_INTERRUPTS | STG_WAIT_FOR_SELECT) /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998, 1999 * Kouichi Matsuda. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include +#include #include #include #include #include #include /*************************************************** * USER SETTINGS ***************************************************/ /* DEVICE CONFIGURATION FLAGS (MINOR) * * 0x01 DISCONNECT OFF * 0x02 PARITY LINE OFF * 0x04 IDENTIFY MSG OFF ( = single lun) * 0x08 SYNC TRANSFER OFF */ /* #define STG_SYNC_SUPPORT */ /* NOT YET but easy */ /* For the 512 fifo type: change below */ #define TMC18C30_FIFOSZ 0x800 #define TMC18C30_FCBSZ 0x200 #define TMC18C50_FIFOSZ 0x2000 #define TMC18C50_FCBSZ 0x400 #define STG_MAX_DATA_SIZE (64 * 1024) #define STG_DELAY_MAX (2 * 1000 * 1000) #define STG_DELAY_INTERVAL (1) #define STG_DELAY_SELECT_POLLING_MAX (5 * 1000 * 1000) /*************************************************** * PARAMS ***************************************************/ #define STG_NTARGETS 8 #define STG_NLUNS 8 /*************************************************** * DEBUG ***************************************************/ #ifdef STG_DEBUG static int stg_debug; #endif /* STG_DEBUG */ #ifdef STG_STATICS static struct stg_statics { int arbit_fail_0; int arbit_fail_1; int disconnect; int reselect; } stg_statics; #endif /* STG_STATICS */ /*************************************************** * IO control flags ***************************************************/ #define STG_FIFO_INTERRUPTS 0x0001 #define STG_WAIT_FOR_SELECT 0x0100 int stg_io_control = STG_IO_CONTROL_FLAGS; /*************************************************** * DEVICE STRUCTURE ***************************************************/ extern struct cfdriver stg_cd; /************************************************************** * DECLARE **************************************************************/ /* static */ static void stg_pio_read(struct stg_softc *, struct targ_info *, u_int); static void stg_pio_write(struct stg_softc *, struct targ_info *, u_int); static int stg_xfer(struct stg_softc *, u_int8_t *, int, int, int); static int stg_msg(struct stg_softc *, struct targ_info *, u_int); static int stg_reselected(struct stg_softc *); static int stg_disconnected(struct stg_softc *, struct targ_info *); static __inline void stg_pdma_end(struct stg_softc *, struct targ_info *); static int stghw_select_targ_wait(struct stg_softc *, int); static int stghw_check(struct stg_softc *); static void stghw_init(struct stg_softc *); static int stg_negate_signal(struct stg_softc *, u_int8_t, u_char *); static int stg_expect_signal(struct stg_softc *, u_int8_t, u_int8_t); static int stg_world_start(struct stg_softc *, int); static int stghw_start_selection(struct stg_softc *sc, struct slccb *); static void stghw_bus_reset(struct stg_softc *); static void stghw_attention(struct stg_softc *); static int stg_target_nexus_establish(struct stg_softc *); static int stg_lun_nexus_establish(struct stg_softc *); static int stg_ccb_nexus_establish(struct stg_softc *); static int stg_targ_init(struct stg_softc *, struct targ_info *, int); static __inline void stghw_bcr_write_1(struct stg_softc *, u_int8_t); static int stg_timeout(struct stg_softc *); static void stg_selection_done_and_expect_msgout(struct stg_softc *); struct scsi_low_funcs stgfuncs = { SC_LOW_INIT_T stg_world_start, SC_LOW_BUSRST_T stghw_bus_reset, SC_LOW_TARG_INIT_T stg_targ_init, SC_LOW_LUN_INIT_T NULL, SC_LOW_SELECT_T stghw_start_selection, SC_LOW_NEXUS_T stg_lun_nexus_establish, SC_LOW_NEXUS_T stg_ccb_nexus_establish, SC_LOW_ATTEN_T stghw_attention, SC_LOW_MSG_T stg_msg, SC_LOW_TIMEOUT_T stg_timeout, SC_LOW_POLL_T stgintr, NULL, }; /**************************************************** * hwfuncs ****************************************************/ static __inline void stghw_bcr_write_1(struct stg_softc *sc, u_int8_t bcv) { - bus_space_write_1(sc->sc_iot, sc->sc_ioh, tmc_bctl, bcv); + bus_write_1(sc->port_res, tmc_bctl, bcv); sc->sc_busimg = bcv; } static int stghw_check(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; u_int fcbsize, fcb; u_int16_t lsb, msb; - lsb = bus_space_read_1(iot, ioh, tmc_idlsb); - msb = bus_space_read_1(iot, ioh, tmc_idmsb); + lsb = bus_read_1(sc->port_res, tmc_idlsb); + msb = bus_read_1(sc->port_res, tmc_idmsb); switch (msb << 8 | lsb) { case 0x6127: /* TMCCHIP_1800 not supported. (it's my policy) */ sc->sc_chip = TMCCHIP_1800; return EINVAL; case 0x60e9: - if (bus_space_read_1(iot, ioh, tmc_cfg2) & 0x02) + if (bus_read_1(sc->port_res, tmc_cfg2) & 0x02) { sc->sc_chip = TMCCHIP_18C30; sc->sc_fsz = TMC18C30_FIFOSZ; fcbsize = TMC18C30_FCBSZ; } else { sc->sc_chip = TMCCHIP_18C50; sc->sc_fsz = TMC18C50_FIFOSZ; fcbsize = TMC18C50_FCBSZ; } break; default: sc->sc_chip = TMCCHIP_UNK; return ENODEV; } sc->sc_fcRinit = FCTL_INTEN; sc->sc_fcWinit = FCTL_PARENB | FCTL_INTEN; if (slp->sl_cfgflags & CFG_NOATTEN) sc->sc_imsg = 0; else sc->sc_imsg = BCTL_ATN; sc->sc_busc = BCTL_BUSEN; sc->sc_wthold = fcbsize + 256; sc->sc_rthold = fcbsize - 256; sc->sc_maxwsize = sc->sc_fsz; fcb = fcbsize / (sc->sc_fsz / 16); sc->sc_icinit = ICTL_CD | ICTL_SEL | ICTL_ARBIT | fcb; return 0; } static void stghw_init(sc) struct stg_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; - bus_space_write_1(iot, ioh, tmc_ictl, 0); + bus_write_1(sc->port_res, tmc_ictl, 0); stghw_bcr_write_1(sc, BCTL_BUSFREE); - bus_space_write_1(iot, ioh, tmc_fctl, + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO | FCTL_CLRINT); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); - bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); - bus_space_write_1(iot, ioh, tmc_ssctl, 0); + bus_write_1(sc->port_res, tmc_ssctl, 0); } static int stg_targ_init(sc, ti, action) struct stg_softc *sc; struct targ_info *ti; int action; { struct stg_targ_info *sti = (void *) ti; if (action == SCSI_LOW_INFO_ALLOC || action == SCSI_LOW_INFO_REVOKE) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; ti->ti_maxsynch.period = 0; ti->ti_maxsynch.offset = 0; sti->sti_reg_synch = 0; } return 0; } /**************************************************** * scsi low interface ****************************************************/ static void stghw_attention(sc) struct stg_softc *sc; { sc->sc_busc |= BCTL_ATN; sc->sc_busimg |= BCTL_ATN; - bus_space_write_1(sc->sc_iot, sc->sc_ioh, tmc_bctl, sc->sc_busimg); + bus_write_1(sc->port_res, tmc_bctl, sc->sc_busimg); DELAY(10); } static void stghw_bus_reset(sc) struct stg_softc *sc; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; - bus_space_write_1(iot, ioh, tmc_ictl, 0); - bus_space_write_1(iot, ioh, tmc_fctl, 0); + bus_write_1(sc->port_res, tmc_ictl, 0); + bus_write_1(sc->port_res, tmc_fctl, 0); stghw_bcr_write_1(sc, BCTL_RST); DELAY(100000); stghw_bcr_write_1(sc, BCTL_BUSFREE); } static int stghw_start_selection(sc, cb) struct stg_softc *sc; struct slccb *cb; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct targ_info *ti = cb->ti; register u_int8_t stat; - int s; sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; sc->sc_dataout_timeout = 0; sc->sc_ubf_timeout = 0; stghw_bcr_write_1(sc, BCTL_BUSFREE); - bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit); + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); - s = splhigh(); - stat = bus_space_read_1(iot, ioh, tmc_astat); + stat = bus_read_1(sc->port_res, tmc_astat); if ((stat & ASTAT_INT) != 0) { - splx(s); return SCSI_LOW_START_FAIL; } - bus_space_write_1(iot, ioh, tmc_scsiid, sc->sc_idbit); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_ARBIT); - splx(s); + bus_write_1(sc->port_res, tmc_scsiid, sc->sc_idbit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_ARBIT); SCSI_LOW_SETUP_PHASE(ti, PH_ARBSTART); return SCSI_LOW_START_OK; } static int stg_world_start(sc, fdone) struct stg_softc *sc; int fdone; { struct scsi_low_softc *slp = &sc->sc_sclow; int error; if ((slp->sl_cfgflags & CFG_NOPARITY) == 0) sc->sc_fcRinit |= FCTL_PARENB; else sc->sc_fcRinit &= ~FCTL_PARENB; if ((error = stghw_check(sc)) != 0) return error; stghw_init(sc); scsi_low_bus_reset(slp); stghw_init(sc); return 0; } static int stg_msg(sc, ti, msg) struct stg_softc *sc; struct targ_info *ti; u_int msg; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct stg_targ_info *sti = (void *) ti; u_int period, offset; if ((msg & SCSI_LOW_MSG_WIDE) != 0) { if (ti->ti_width != SCSI_LOW_BUS_WIDTH_8) { ti->ti_width = SCSI_LOW_BUS_WIDTH_8; return EINVAL; } return 0; } if ((msg & SCSI_LOW_MSG_SYNCH) == 0) return 0; period = ti->ti_maxsynch.period; offset = ti->ti_maxsynch.offset; period = period << 2; if (period >= 200) { sti->sti_reg_synch = (period - 200) / 50; if (period % 50) sti->sti_reg_synch ++; sti->sti_reg_synch |= SSCTL_SYNCHEN; } else if (period >= 100) { sti->sti_reg_synch = (period - 100) / 50; if (period % 50) sti->sti_reg_synch ++; sti->sti_reg_synch |= SSCTL_SYNCHEN | SSCTL_FSYNCHEN; } - bus_space_write_1(iot, ioh, tmc_ssctl, sti->sti_reg_synch); + bus_write_1(sc->port_res, tmc_ssctl, sti->sti_reg_synch); return 0; } /************************************************************** * General probe attach **************************************************************/ int -stgprobesubr(iot, ioh, dvcfg) - bus_space_tag_t iot; - bus_space_handle_t ioh; - u_int dvcfg; +stgprobesubr(struct resource *res, u_int dvcfg) { u_int16_t lsb, msb; - lsb = bus_space_read_1(iot, ioh, tmc_idlsb); - msb = bus_space_read_1(iot, ioh, tmc_idmsb); + lsb = bus_read_1(res, tmc_idlsb); + msb = bus_read_1(res, tmc_idmsb); switch (msb << 8 | lsb) { default: return 0; case 0x6127: /* not support! */ return 0; case 0x60e9: return 1; } return 0; } void stgattachsubr(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; printf("\n"); sc->sc_idbit = (1 << slp->sl_hostid); slp->sl_funcs = &stgfuncs; sc->sc_tmaxcnt = SCSI_LOW_MIN_TOUT * 1000 * 1000; /* default */ slp->sl_flags |= HW_READ_PADDING; slp->sl_cfgflags |= CFG_ASYNC; /* XXX */ (void) scsi_low_attach(slp, 0, STG_NTARGETS, STG_NLUNS, sizeof(struct stg_targ_info), 0); } /************************************************************** * PDMA functions **************************************************************/ static __inline void stg_pdma_end(sc, ti) struct stg_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct slccb *cb = slp->sl_Qnexus; u_int len, tres; slp->sl_flags &= ~HW_PDMASTART; sc->sc_icinit &= ~ICTL_FIFO; sc->sc_dataout_timeout = 0; if (cb == NULL) { slp->sl_error |= PDMAERR; goto out; } if (ti->ti_phase == PH_DATA) { - len = bus_space_read_2(iot, ioh, tmc_fdcnt); + len = bus_read_2(sc->port_res, tmc_fdcnt); if (slp->sl_scp.scp_direction == SCSI_LOW_WRITE) { if (len != 0) { tres = len + slp->sl_scp.scp_datalen; if (tres <= (u_int) cb->ccb_scp.scp_datalen) { slp->sl_scp.scp_data -= len; slp->sl_scp.scp_datalen = tres; } else { slp->sl_error |= PDMAERR; device_printf(slp->sl_dev, "len %x >= datalen %x\n", len, slp->sl_scp.scp_datalen); } } } else if (slp->sl_scp.scp_direction == SCSI_LOW_READ) { if (len != 0) { slp->sl_error |= PDMAERR; device_printf(slp->sl_dev, "len %x left in fifo\n", len); } } scsi_low_data_finish(slp); } else { device_printf(slp->sl_dev, "data phase miss\n"); slp->sl_error |= PDMAERR; } out: - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); } static void stg_pio_read(sc, ti, thold) struct stg_softc *sc; struct targ_info *ti; u_int thold; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct sc_p *sp = &slp->sl_scp; - int s, tout; + int tout; u_int res; u_int8_t stat; if ((slp->sl_flags & HW_PDMASTART) == 0) { - bus_space_write_1(iot, ioh, tmc_fctl, + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_FIFOEN); slp->sl_flags |= HW_PDMASTART; } tout = sc->sc_tmaxcnt; while (tout -- > 0) { if (thold > 0) { - s = splhigh(); - res = bus_space_read_2(iot, ioh, tmc_fdcnt); + res = bus_read_2(sc->port_res, tmc_fdcnt); if (res < thold) { - bus_space_write_1(iot, ioh, tmc_ictl, + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); - splx(s); break; } - splx(s); } else { - stat = bus_space_read_1(iot, ioh, tmc_bstat); - res = bus_space_read_2(iot, ioh, tmc_fdcnt); + stat = bus_read_1(sc->port_res, tmc_bstat); + res = bus_read_2(sc->port_res, tmc_fdcnt); if (res == 0) { if ((stat & PHASE_MASK) != DATA_IN_PHASE) break; if (sp->scp_datalen <= 0) break; DELAY(1); continue; } } /* The assumtion res != 0 is valid here */ if (res > sp->scp_datalen) { if (res == (u_int) -1) break; slp->sl_error |= PDMAERR; if ((slp->sl_flags & HW_READ_PADDING) == 0) { device_printf(slp->sl_dev, "read padding required\n"); break; } sp->scp_datalen = 0; if (res > STG_MAX_DATA_SIZE) res = STG_MAX_DATA_SIZE; while (res -- > 0) { - (void) bus_space_read_1(iot, ioh, tmc_rfifo); + (void) bus_read_1(sc->port_res, tmc_rfifo); } continue; } sp->scp_datalen -= res; if (res & 1) { - *sp->scp_data = bus_space_read_1(iot, ioh, tmc_rfifo); + *sp->scp_data = bus_read_1(sc->port_res, tmc_rfifo); sp->scp_data ++; res --; } - bus_space_read_multi_2(iot, ioh, tmc_rfifo, + bus_read_multi_2(sc->port_res, tmc_rfifo, (u_int16_t *) sp->scp_data, res >> 1); sp->scp_data += res; } if (tout <= 0) device_printf(slp->sl_dev, "pio read timeout\n"); } static void stg_pio_write(sc, ti, thold) struct stg_softc *sc; struct targ_info *ti; u_int thold; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct sc_p *sp = &slp->sl_scp; u_int res; - int s, tout; + int tout; register u_int8_t stat; if ((slp->sl_flags & HW_PDMASTART) == 0) { stat = sc->sc_fcWinit | FCTL_FIFOEN | FCTL_FIFOW; - bus_space_write_1(iot, ioh, tmc_fctl, stat | FCTL_CLRFIFO); - bus_space_write_1(iot, ioh, tmc_fctl, stat); + bus_write_1(sc->port_res, tmc_fctl, stat | FCTL_CLRFIFO); + bus_write_1(sc->port_res, tmc_fctl, stat); slp->sl_flags |= HW_PDMASTART; } tout = sc->sc_tmaxcnt; while (tout -- > 0) { - stat = bus_space_read_1(iot, ioh, tmc_bstat); + stat = bus_read_1(sc->port_res, tmc_bstat); if ((stat & PHASE_MASK) != DATA_OUT_PHASE) break; if (sp->scp_datalen <= 0) { if (sc->sc_dataout_timeout == 0) sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ; break; } if (thold > 0) { - s = splhigh(); - res = bus_space_read_2(iot, ioh, tmc_fdcnt); + res = bus_read_2(sc->port_res, tmc_fdcnt); if (res > thold) { - bus_space_write_1(iot, ioh, tmc_ictl, + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); - splx(s); break; } - splx(s); } else { - res = bus_space_read_2(iot, ioh, tmc_fdcnt); + res = bus_read_2(sc->port_res, tmc_fdcnt); if (res > sc->sc_maxwsize / 2) { DELAY(1); continue; } } if (res == (u_int) -1) break; res = sc->sc_maxwsize - res; if (res > sp->scp_datalen) res = sp->scp_datalen; sp->scp_datalen -= res; if ((res & 0x1) != 0) { - bus_space_write_1(iot, ioh, tmc_wfifo, *sp->scp_data); + bus_write_1(sc->port_res, tmc_wfifo, *sp->scp_data); sp->scp_data ++; res --; } - bus_space_write_multi_2(iot, ioh, tmc_wfifo, + bus_write_multi_2(sc->port_res, tmc_wfifo, (u_int16_t *) sp->scp_data, res >> 1); sp->scp_data += res; } if (tout <= 0) device_printf(slp->sl_dev, "pio write timeout\n"); } static int stg_negate_signal(struct stg_softc *sc, u_int8_t mask, u_char *s) { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int wc; u_int8_t regv; for (wc = 0; wc < STG_DELAY_MAX / STG_DELAY_INTERVAL; wc ++) { - regv = bus_space_read_1(bst, bsh, tmc_bstat); + regv = bus_read_1(sc->port_res, tmc_bstat); if (regv == (u_int8_t) -1) return -1; if ((regv & mask) == 0) return 1; DELAY(STG_DELAY_INTERVAL); } device_printf(slp->sl_dev, "%s stg_negate_signal timeout\n", s); return -1; } static int stg_expect_signal(struct stg_softc *sc, u_int8_t phase, u_int8_t mask) { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t bst = sc->sc_iot; - bus_space_handle_t bsh = sc->sc_ioh; int wc; u_int8_t ph; phase &= PHASE_MASK; for (wc = 0; wc < STG_DELAY_MAX / STG_DELAY_INTERVAL; wc ++) { - ph = bus_space_read_1(bst, bsh, tmc_bstat); + ph = bus_read_1(sc->port_res, tmc_bstat); if (ph == (u_int8_t) -1) return -1; if ((ph & PHASE_MASK) != phase) return 0; if ((ph & mask) != 0) return 1; DELAY(STG_DELAY_INTERVAL); } device_printf(slp->sl_dev, "stg_expect_signal timeout\n"); return -1; } static int stg_xfer(sc, buf, len, phase, clear_atn) struct stg_softc *sc; u_int8_t *buf; int len; int phase; int clear_atn; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; int rv, ptr; if (phase & BSTAT_IO) - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); else - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcWinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcWinit); for (ptr = 0; len > 0; len --) { rv = stg_expect_signal(sc, phase, BSTAT_REQ); if (rv <= 0) goto bad; if (len == 1 && clear_atn != 0) { sc->sc_busc &= ~BCTL_ATN; stghw_bcr_write_1(sc, sc->sc_busc); SCSI_LOW_DEASSERT_ATN(&sc->sc_sclow); } if (phase & BSTAT_IO) { - buf[ptr ++] = bus_space_read_1(iot, ioh, tmc_rdata); + buf[ptr ++] = bus_read_1(sc->port_res, tmc_rdata); } else { - bus_space_write_1(iot, ioh, tmc_wdata, buf[ptr ++]); + bus_write_1(sc->port_res, tmc_wdata, buf[ptr ++]); } stg_negate_signal(sc, BSTAT_ACK, "xfer"); } bad: - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); return len; } /************************************************************** * disconnect & reselect (HW low) **************************************************************/ static int stg_reselected(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; int tout; u_int sid; u_int8_t regv; if (slp->sl_selid != NULL) { /* XXX: * Selection vs Reselection conflicts. */ - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, BCTL_BUSFREE); } else if (slp->sl_Tnexus != NULL) { device_printf(slp->sl_dev, "unexpected termination\n"); stg_disconnected(sc, slp->sl_Tnexus); } /* XXX: * We should ack the reselection as soon as possible, * because the target would abort the current reselection seq * due to reselection timeout. */ tout = STG_DELAY_SELECT_POLLING_MAX; while (tout -- > 0) { - regv = bus_space_read_1(iot, ioh, tmc_bstat); + regv = bus_read_1(sc->port_res, tmc_bstat); if ((regv & (BSTAT_IO | BSTAT_SEL | BSTAT_BSY)) == (BSTAT_IO | BSTAT_SEL)) { DELAY(1); - regv = bus_space_read_1(iot, ioh, tmc_bstat); + regv = bus_read_1(sc->port_res, tmc_bstat); if ((regv & (BSTAT_IO | BSTAT_SEL | BSTAT_BSY)) == (BSTAT_IO | BSTAT_SEL)) goto reselect_start; } DELAY(1); } device_printf(slp->sl_dev, "reselction timeout I\n"); return EJUSTRETURN; reselect_start: - sid = (u_int) bus_space_read_1(iot, ioh, tmc_scsiid); + sid = (u_int) bus_read_1(sc->port_res, tmc_scsiid); if ((sid & sc->sc_idbit) == 0) { /* not us */ return EJUSTRETURN; } - bus_space_write_1(iot, ioh, tmc_fctl, + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO | FCTL_CLRINT); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, sc->sc_busc | BCTL_BSY); while (tout -- > 0) { - regv = bus_space_read_1(iot, ioh, tmc_bstat); + regv = bus_read_1(sc->port_res, tmc_bstat); if ((regv & (BSTAT_SEL | BSTAT_BSY)) == BSTAT_BSY) goto reselected; DELAY(1); } device_printf(slp->sl_dev, "reselction timeout II\n"); return EJUSTRETURN; reselected: sid &= ~sc->sc_idbit; sid = ffs(sid) - 1; if (scsi_low_reselected(slp, sid) == NULL) return EJUSTRETURN; #ifdef STG_STATICS stg_statics.reselect ++; #endif /* STG_STATICS */ return EJUSTRETURN; } static int stg_disconnected(sc, ti) struct stg_softc *sc; struct targ_info *ti; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; /* clear bus status & fifo */ - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, BCTL_BUSFREE); sc->sc_icinit &= ~ICTL_FIFO; sc->sc_busc &= ~BCTL_ATN; sc->sc_dataout_timeout = 0; sc->sc_ubf_timeout = 0; #ifdef STG_STATICS stg_statics.disconnect ++; #endif /* STG_STATICS */ scsi_low_disconnected(slp, ti); return 1; } /************************************************************** * SEQUENCER **************************************************************/ static int stg_target_nexus_establish(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct targ_info *ti = slp->sl_Tnexus; struct stg_targ_info *sti = (void *) ti; - bus_space_write_1(iot, ioh, tmc_ssctl, sti->sti_reg_synch); + bus_write_1(sc->port_res, tmc_ssctl, sti->sti_reg_synch); if ((stg_io_control & STG_FIFO_INTERRUPTS) != 0) { sc->sc_icinit |= ICTL_FIFO; } return 0; } static int stg_lun_nexus_establish(sc) struct stg_softc *sc; { return 0; } static int stg_ccb_nexus_establish(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; struct slccb *cb = slp->sl_Qnexus; sc->sc_tmaxcnt = cb->ccb_tcmax * 1000 * 1000; return 0; } #define STGHW_SELECT_INTERVAL 10 static int stghw_select_targ_wait(sc, mu) struct stg_softc *sc; int mu; { - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; mu = mu / STGHW_SELECT_INTERVAL; while (mu -- > 0) { - if ((bus_space_read_1(iot, ioh, tmc_bstat) & BSTAT_BSY) == 0) + if ((bus_read_1(sc->port_res, tmc_bstat) & BSTAT_BSY) == 0) { DELAY(STGHW_SELECT_INTERVAL); continue; } DELAY(1); - if ((bus_space_read_1(iot, ioh, tmc_bstat) & BSTAT_BSY) != 0) + if ((bus_read_1(sc->port_res, tmc_bstat) & BSTAT_BSY) != 0) { return 0; } } return ENXIO; } static void stg_selection_done_and_expect_msgout(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, sc->sc_imsg | sc->sc_busc); SCSI_LOW_ASSERT_ATN(slp); } int stgintr(arg) void *arg; { struct stg_softc *sc = arg; struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; struct targ_info *ti; struct buf *bp; u_int derror, flags; - int len, s; + int len; u_int8_t status, astatus, regv; /******************************************* * interrupt check *******************************************/ if (slp->sl_flags & HW_INACTIVE) return 0; - astatus = bus_space_read_1(iot, ioh, tmc_astat); - status = bus_space_read_1(iot, ioh, tmc_bstat); + astatus = bus_read_1(sc->port_res, tmc_astat); + status = bus_read_1(sc->port_res, tmc_bstat); if ((astatus & ASTAT_STATMASK) == 0 || astatus == (u_int8_t) -1) return 0; - bus_space_write_1(iot, ioh, tmc_ictl, 0); + bus_write_1(sc->port_res, tmc_ictl, 0); if (astatus & ASTAT_SCSIRST) { - bus_space_write_1(iot, ioh, tmc_fctl, + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit | FCTL_CLRFIFO); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); - bus_space_write_1(iot, ioh, tmc_ictl, 0); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_ictl, 0); scsi_low_restart(slp, SCSI_LOW_RESTART_SOFT, "bus reset (power off?)"); return 1; } /******************************************* * debug section *******************************************/ #ifdef STG_DEBUG if (stg_debug) { scsi_low_print(slp, NULL); device_printf(slp->sl_dev, "st %x ist %x\n\n", status, astatus); #ifdef KDB if (stg_debug > 1) kdb_enter(KDB_WHY_CAM, "stg"); #endif /* KDB */ } #endif /* STG_DEBUG */ /******************************************* * reselection & nexus *******************************************/ if ((status & RESEL_PHASE_MASK)== PHASE_RESELECTED) { if (stg_reselected(sc) == EJUSTRETURN) goto out; } if ((ti = slp->sl_Tnexus) == NULL) return 0; derror = 0; if ((astatus & ASTAT_PARERR) != 0 && ti->ti_phase != PH_ARBSTART && (sc->sc_fcRinit & FCTL_PARENB) != 0) { slp->sl_error |= PARITYERR; derror = SCSI_LOW_DATA_PE; if ((status & PHASE_MASK) == MESSAGE_IN_PHASE) scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_PARITY, 0); else scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ERROR, 1); } /******************************************* * aribitration & selection *******************************************/ switch (ti->ti_phase) { case PH_ARBSTART: if ((astatus & ASTAT_ARBIT) == 0) { #ifdef STG_STATICS stg_statics.arbit_fail_0 ++; #endif /* STG_STATICS */ goto arb_fail; } - status = bus_space_read_1(iot, ioh, tmc_bstat); + status = bus_read_1(sc->port_res, tmc_bstat); if ((status & BSTAT_IO) != 0) { /* XXX: * Selection vs Reselection conflicts. */ #ifdef STG_STATICS stg_statics.arbit_fail_1 ++; #endif /* STG_STATICS */ arb_fail: - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, BCTL_BUSFREE); scsi_low_arbit_fail(slp, slp->sl_Qnexus); goto out; } /* * selection assert start. */ SCSI_LOW_SETUP_PHASE(ti, PH_SELSTART); scsi_low_arbit_win(slp); - s = splhigh(); - bus_space_write_1(iot, ioh, tmc_scsiid, + bus_write_1(sc->port_res, tmc_scsiid, sc->sc_idbit | (1 << ti->ti_id)); stghw_bcr_write_1(sc, sc->sc_imsg | sc->sc_busc | BCTL_SEL); - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcWinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcWinit); if ((stg_io_control & STG_WAIT_FOR_SELECT) != 0) { /* selection abort delay 200 + 100 micro sec */ if (stghw_select_targ_wait(sc, 300) == 0) { SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); stg_selection_done_and_expect_msgout(sc); } } - splx(s); goto out; case PH_SELSTART: if ((status & BSTAT_BSY) == 0) { /* selection timeout delay 250 ms */ if (stghw_select_targ_wait(sc, 250 * 1000) != 0) { stg_disconnected(sc, ti); goto out; } } SCSI_LOW_SETUP_PHASE(ti, PH_SELECTED); stg_selection_done_and_expect_msgout(sc); goto out; case PH_SELECTED: if ((status & BSTAT_REQ) == 0) goto out; stg_target_nexus_establish(sc); break; case PH_RESEL: if ((status & BSTAT_REQ) == 0) goto out; /* clear a busy line */ - bus_space_write_1(iot, ioh, tmc_fctl, sc->sc_fcRinit); + bus_write_1(sc->port_res, tmc_fctl, sc->sc_fcRinit); stghw_bcr_write_1(sc, sc->sc_busc); stg_target_nexus_establish(sc); if ((status & PHASE_MASK) != MESSAGE_IN_PHASE) { device_printf(slp->sl_dev, "unexpected phase after reselect\n"); slp->sl_error |= FATALIO; scsi_low_assert_msg(slp, ti, SCSI_LOW_MSG_ABORT, 1); goto out; } break; } /******************************************* * data phase *******************************************/ if ((slp->sl_flags & HW_PDMASTART) && STG_IS_PHASE_DATA(status) == 0) { if (slp->sl_scp.scp_direction == SCSI_LOW_READ) stg_pio_read(sc, ti, 0); stg_pdma_end(sc, ti); } /******************************************* * scsi seq *******************************************/ switch (status & PHASE_MASK) { case COMMAND_PHASE: if (stg_expect_signal(sc, COMMAND_PHASE, BSTAT_REQ) <= 0) break; SCSI_LOW_SETUP_PHASE(ti, PH_CMD); if (scsi_low_cmd(slp, ti) != 0) { scsi_low_attention(slp); } if (stg_xfer(sc, slp->sl_scp.scp_cmd, slp->sl_scp.scp_cmdlen, COMMAND_PHASE, 0) != 0) { device_printf(slp->sl_dev, "CMDOUT short\n"); } break; case DATA_OUT_PHASE: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_WRITE) != 0) { scsi_low_attention(slp); } if ((sc->sc_icinit & ICTL_FIFO) != 0) stg_pio_write(sc, ti, sc->sc_wthold); else stg_pio_write(sc, ti, 0); break; case DATA_IN_PHASE: SCSI_LOW_SETUP_PHASE(ti, PH_DATA); if (scsi_low_data(slp, ti, &bp, SCSI_LOW_READ) != 0) { scsi_low_attention(slp); } if ((sc->sc_icinit & ICTL_FIFO) != 0) stg_pio_read(sc, ti, sc->sc_rthold); else stg_pio_read(sc, ti, 0); break; case STATUS_PHASE: regv = stg_expect_signal(sc, STATUS_PHASE, BSTAT_REQ); if (regv <= 0) break; SCSI_LOW_SETUP_PHASE(ti, PH_STAT); - regv = bus_space_read_1(iot, ioh, tmc_sdna); + regv = bus_read_1(sc->port_res, tmc_sdna); if (scsi_low_statusin(slp, ti, regv | derror) != 0) { scsi_low_attention(slp); } - if (regv != bus_space_read_1(iot, ioh, tmc_rdata)) + if (regv != bus_read_1(sc->port_res, tmc_rdata)) { device_printf(slp->sl_dev, "STATIN: data mismatch\n"); } stg_negate_signal(sc, BSTAT_ACK, "statin"); break; case MESSAGE_OUT_PHASE: if (stg_expect_signal(sc, MESSAGE_OUT_PHASE, BSTAT_REQ) <= 0) break; SCSI_LOW_SETUP_PHASE(ti, PH_MSGOUT); flags = (ti->ti_ophase != ti->ti_phase) ? SCSI_LOW_MSGOUT_INIT : 0; len = scsi_low_msgout(slp, ti, flags); if (len > 1 && slp->sl_atten == 0) { scsi_low_attention(slp); } if (stg_xfer(sc, ti->ti_msgoutstr, len, MESSAGE_OUT_PHASE, slp->sl_clear_atten) != 0) { device_printf(slp->sl_dev, "MSGOUT short\n"); } else { if (slp->sl_msgphase >= MSGPH_ABORT) { stg_disconnected(sc, ti); } } break; case MESSAGE_IN_PHASE: /* confirm phase and req signal */ if (stg_expect_signal(sc, MESSAGE_IN_PHASE, BSTAT_REQ) <= 0) break; SCSI_LOW_SETUP_PHASE(ti, PH_MSGIN); /* read data with NOACK */ - regv = bus_space_read_1(iot, ioh, tmc_sdna); + regv = bus_read_1(sc->port_res, tmc_sdna); if (scsi_low_msgin(slp, ti, derror | regv) == 0) { if (scsi_low_is_msgout_continue(ti, 0) != 0) { scsi_low_attention(slp); } } /* read data with ACK */ - if (regv != bus_space_read_1(iot, ioh, tmc_rdata)) + if (regv != bus_read_1(sc->port_res, tmc_rdata)) { device_printf(slp->sl_dev, "MSGIN: data mismatch\n"); } /* wait for the ack negated */ stg_negate_signal(sc, BSTAT_ACK, "msgin"); if (slp->sl_msgphase != 0 && slp->sl_msgphase < MSGPH_ABORT) { stg_disconnected(sc, ti); } break; case BUSFREE_PHASE: device_printf(slp->sl_dev, "unexpected disconnect\n"); stg_disconnected(sc, ti); break; default: slp->sl_error |= FATALIO; device_printf(slp->sl_dev, "unknown phase bus %x intr %x\n", status, astatus); break; } out: - bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit); + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); return 1; } static int stg_timeout(sc) struct stg_softc *sc; { struct scsi_low_softc *slp = &sc->sc_sclow; - bus_space_tag_t iot = sc->sc_iot; - bus_space_handle_t ioh = sc->sc_ioh; int tout, count; u_int8_t status; if (slp->sl_Tnexus == NULL) return 0; - status = bus_space_read_1(iot, ioh, tmc_bstat); + status = bus_read_1(sc->port_res, tmc_bstat); if ((status & PHASE_MASK) == 0) { if (sc->sc_ubf_timeout ++ == 0) return 0; device_printf(slp->sl_dev, "unexpected bus free detected\n"); slp->sl_error |= FATALIO; scsi_low_print(slp, slp->sl_Tnexus); stg_disconnected(sc, slp->sl_Tnexus); return 0; } switch (status & PHASE_MASK) { case DATA_OUT_PHASE: if (sc->sc_dataout_timeout == 0) break; if ((status & BSTAT_REQ) == 0) break; - if (bus_space_read_2(iot, ioh, tmc_fdcnt) != 0) + if (bus_read_2(sc->port_res, tmc_fdcnt) != 0) break; if ((-- sc->sc_dataout_timeout) > 0) break; slp->sl_error |= PDMAERR; if ((slp->sl_flags & HW_WRITE_PADDING) == 0) { device_printf(slp->sl_dev, "write padding required\n"); break; } - bus_space_write_1(iot, ioh, tmc_ictl, 0); + bus_write_1(sc->port_res, tmc_ictl, 0); tout = STG_DELAY_MAX; while (tout --) { - status = bus_space_read_1(iot, ioh, tmc_bstat); + status = bus_read_1(sc->port_res, tmc_bstat); if ((status & PHASE_MASK) != DATA_OUT_PHASE) break; - if (bus_space_read_2(iot, ioh, tmc_fdcnt) != 0) + if (bus_read_2(sc->port_res, tmc_fdcnt) != 0) { DELAY(1); continue; } for (count = sc->sc_maxwsize; count > 0; count --) - bus_space_write_1(iot, ioh, tmc_wfifo, 0); + bus_write_1(sc->port_res, tmc_wfifo, 0); } - status = bus_space_read_1(iot, ioh, tmc_bstat); + status = bus_read_1(sc->port_res, tmc_bstat); if ((status & PHASE_MASK) == DATA_OUT_PHASE) sc->sc_dataout_timeout = SCSI_LOW_TIMEOUT_HZ; - bus_space_write_1(iot, ioh, tmc_ictl, sc->sc_icinit); + bus_write_1(sc->port_res, tmc_ictl, sc->sc_icinit); break; default: break; } return 0; } Index: projects/sendfile/sys/dev/stg/tmc18c30_isa.c =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30_isa.c (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30_isa.c (revision 274765) @@ -1,129 +1,129 @@ /* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */ /* $NetBSD$ */ /*- * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Kouichi Matsuda. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int stg_isa_probe(device_t dev) { struct stg_softc *sc = device_get_softc(dev); int error; sc->port_rid = 0; sc->irq_rid = 0; error = stg_alloc_resource(dev); if (error) { return(error); } if (stg_probe(dev) == 0) { stg_release_resource(dev); return(ENXIO); } stg_release_resource(dev); - return(0); + return (BUS_PROBE_DEFAULT); } static int stg_isa_attach(device_t dev) { struct stg_softc *sc = device_get_softc(dev); int error; sc->port_rid = 0; sc->irq_rid = 0; error = stg_alloc_resource(dev); if (error) { return(error); } - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, stg_intr, (void *)sc, &sc->stg_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, stg_intr, sc, &sc->stg_intrhand); if (error) { stg_release_resource(dev); return(error); } if (stg_attach(dev) == 0) { stg_release_resource(dev); return(ENXIO); } return(0); } static device_method_t stg_isa_methods[] = { /* Device interface */ DEVMETHOD(device_probe, stg_isa_probe), DEVMETHOD(device_attach, stg_isa_attach), DEVMETHOD(device_detach, stg_detach), { 0, 0 } }; static driver_t stg_isa_driver = { "stg", stg_isa_methods, sizeof(struct stg_softc), }; DRIVER_MODULE(stg, isa, stg_isa_driver, stg_devclass, 0, 0); MODULE_DEPEND(stg, scsi_low, 1, 1, 1); Index: projects/sendfile/sys/dev/stg/tmc18c30_pccard.c =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30_pccard.c (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30_pccard.c (revision 274765) @@ -1,138 +1,138 @@ /* $NecBSD: tmc18c30_pisa.c,v 1.22 1998/11/26 01:59:21 honda Exp $ */ /* $NetBSD$ */ /*- * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Kouichi Matsuda. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include "pccarddevs.h" static const struct pccard_product stg_products[] = { PCMCIA_CARD(FUTUREDOMAIN, SCSI2GO), PCMCIA_CARD(IBM, SCSICARD), PCMCIA_CARD(RATOC, REX5536), PCMCIA_CARD(RATOC, REX5536AM), PCMCIA_CARD(RATOC, REX5536M), { NULL } }; /* * Additional code for FreeBSD new-bus PC Card frontend */ static int stg_pccard_probe(device_t dev) { const struct pccard_product *pp; if ((pp = pccard_product_lookup(dev, stg_products, sizeof(stg_products[0]), NULL)) != NULL) { if (pp->pp_name != NULL) device_set_desc(dev, pp->pp_name); - return(0); + return (BUS_PROBE_DEFAULT); } return(EIO); } static int stg_pccard_attach(device_t dev) { struct stg_softc *sc = device_get_softc(dev); int error; sc->port_rid = 0; sc->irq_rid = 0; error = stg_alloc_resource(dev); if (error) { return(error); } if (stg_probe(dev) == 0) { stg_release_resource(dev); return(ENXIO); } - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, stg_intr, (void *)sc, &sc->stg_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, stg_intr, sc, &sc->stg_intrhand); if (error) { stg_release_resource(dev); return(error); } if (stg_attach(dev) == 0) { stg_release_resource(dev); return(ENXIO); } return(0); } static device_method_t stg_pccard_methods[] = { /* Device interface */ DEVMETHOD(device_probe, stg_pccard_probe), DEVMETHOD(device_attach, stg_pccard_attach), DEVMETHOD(device_detach, stg_detach), { 0, 0 } }; static driver_t stg_pccard_driver = { "stg", stg_pccard_methods, sizeof(struct stg_softc), }; DRIVER_MODULE(stg, pccard, stg_pccard_driver, stg_devclass, 0, 0); MODULE_DEPEND(stg, scsi_low, 1, 1, 1); Index: projects/sendfile/sys/dev/stg/tmc18c30_pci.c =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30_pci.c (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30_pci.c (revision 274765) @@ -1,134 +1,134 @@ /*- * Copyright (c) 2003 Bob Bishop * All rights reserved. * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Kouichi Matsuda. 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. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static struct _pcsid { u_int32_t type; const char *desc; } pci_ids[] = { { 0x00001036, "Adaptec AHA-2920/A,Future Domain TMC-18XX/3260" }, { 0x00000000, NULL } }; static int stg_pci_probe(device_t dev) { u_int32_t type = pci_get_devid(dev); struct _pcsid *stg = pci_ids; while (stg->type && stg->type != type) ++stg; if (stg->desc) { device_set_desc(dev, stg->desc); return (BUS_PROBE_DEFAULT); } return (ENXIO); } static int stg_pci_attach(device_t dev) { struct stg_softc *sc = device_get_softc(dev); int error; sc->port_rid = PCIR_BAR(0); sc->irq_rid = 0; error = stg_alloc_resource(dev); if (error) { return(error); } /* XXXX remove INTR_ENTROPY below for MFC */ - error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY, - NULL, stg_intr, (void *)sc, &sc->stg_intrhand); + error = bus_setup_intr(dev, sc->irq_res, INTR_TYPE_CAM | INTR_ENTROPY | + INTR_MPSAFE, NULL, stg_intr, sc, &sc->stg_intrhand); if (error) { stg_release_resource(dev); return(error); } if (stg_attach(dev) == 0) { stg_release_resource(dev); return(ENXIO); } return(0); } static device_method_t stg_pci_methods[] = { /* Device interface */ DEVMETHOD(device_probe, stg_pci_probe), DEVMETHOD(device_attach, stg_pci_attach), DEVMETHOD(device_detach, stg_detach), { 0, 0 } }; static driver_t stg_pci_driver = { "stg", stg_pci_methods, sizeof(struct stg_softc), }; DRIVER_MODULE(stg, pci, stg_pci_driver, stg_devclass, 0, 0); MODULE_DEPEND(stg, scsi_low, 1, 1, 1); MODULE_DEPEND(stg, pci, 1, 1, 1); Index: projects/sendfile/sys/dev/stg/tmc18c30_subr.c =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30_subr.c (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30_subr.c (revision 274765) @@ -1,183 +1,176 @@ /*- * [Ported for FreeBSD] * Copyright (c) 2000 * Noriaki Mitsunaga, Mitsuru Iwasaki and Takanori Watanabe. * All rights reserved. * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Kouichi Matsuda. 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. * */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #define STG_HOSTID 7 devclass_t stg_devclass; int stg_alloc_resource(device_t dev) { struct stg_softc * sc = device_get_softc(dev); u_long maddr, msize; int error; + mtx_init(&sc->sc_sclow.sl_lock, "stg", NULL, MTX_DEF); sc->port_res = bus_alloc_resource_any(dev, SYS_RES_IOPORT, &sc->port_rid, RF_ACTIVE); if (sc->port_res == NULL) { stg_release_resource(dev); return(ENOMEM); } sc->irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->irq_rid, RF_ACTIVE); if (sc->irq_res == NULL) { stg_release_resource(dev); return(ENOMEM); } error = bus_get_resource(dev, SYS_RES_MEMORY, 0, &maddr, &msize); if (error) { return(0); /* XXX */ } /* no need to allocate memory if not configured */ if (maddr == 0 || msize == 0) { return(0); } sc->mem_res = bus_alloc_resource_any(dev, SYS_RES_MEMORY, &sc->mem_rid, RF_ACTIVE); if (sc->mem_res == NULL) { stg_release_resource(dev); return(ENOMEM); } return(0); } void stg_release_resource(device_t dev) { struct stg_softc *sc = device_get_softc(dev); if (sc->stg_intrhand) bus_teardown_intr(dev, sc->irq_res, sc->stg_intrhand); if (sc->port_res) bus_release_resource(dev, SYS_RES_IOPORT, sc->port_rid, sc->port_res); if (sc->irq_res) bus_release_resource(dev, SYS_RES_IRQ, sc->irq_rid, sc->irq_res); if (sc->mem_res) bus_release_resource(dev, SYS_RES_MEMORY, sc->mem_rid, sc->mem_res); - return; + mtx_destroy(&sc->sc_sclow.sl_lock); } int stg_probe(device_t dev) { int rv; struct stg_softc *sc = device_get_softc(dev); - rv = stgprobesubr(rman_get_bustag(sc->port_res), - rman_get_bushandle(sc->port_res), + rv = stgprobesubr(sc->port_res, device_get_flags(dev)); return rv; } int stg_attach(device_t dev) { struct stg_softc *sc; struct scsi_low_softc *slp; u_int32_t flags = device_get_flags(dev); - intrmask_t s; - char dvname[16]; sc = device_get_softc(dev); - strcpy(dvname,"stg"); - slp = &sc->sc_sclow; slp->sl_dev = dev; - sc->sc_iot = rman_get_bustag(sc->port_res); - sc->sc_ioh = rman_get_bushandle(sc->port_res); slp->sl_hostid = STG_HOSTID; slp->sl_cfgflags = flags; - s = splcam(); stgattachsubr(sc); - splx(s); return(STGIOSZ); } int -stg_detach (device_t dev) +stg_detach(device_t dev) { struct stg_softc *sc = device_get_softc(dev); - intrmask_t s; - s = splcam(); - scsi_low_deactivate((struct scsi_low_softc *)sc); - scsi_low_dettach(&sc->sc_sclow); - splx(s); + scsi_low_deactivate(&sc->sc_sclow); + scsi_low_detach(&sc->sc_sclow); stg_release_resource(dev); return (0); } void -stg_intr (void *arg) +stg_intr(void *arg) { - stgintr(arg); - return; + struct stg_softc *sc; + + sc = arg; + SCSI_LOW_LOCK(&sc->sc_sclow); + stgintr(sc); + SCSI_LOW_UNLOCK(&sc->sc_sclow); } Index: projects/sendfile/sys/dev/stg/tmc18c30var.h =================================================================== --- projects/sendfile/sys/dev/stg/tmc18c30var.h (revision 274764) +++ projects/sendfile/sys/dev/stg/tmc18c30var.h (revision 274765) @@ -1,95 +1,91 @@ /* $FreeBSD$ */ /* $NecBSD: tmc18c30var.h,v 1.12.18.2 2001/06/13 05:51:23 honda Exp $ */ /* $NetBSD$ */ /*- * [NetBSD for NEC PC-98 series] * Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001 * NetBSD/pc98 porting staff. All rights reserved. * Copyright (c) 1996, 1997, 1998, 1999, 2000, 2001 * Naofumi HONDA. All rights reserved. * Copyright (c) 1996, 1997, 1998 * Kouichi Matsuda. 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. */ #ifndef _TMC18C30VAR_H_ #define _TMC18C30VAR_H_ /***************************************************************** * Host adapter structure *****************************************************************/ struct stg_softc { struct scsi_low_softc sc_sclow; /* generic data */ - bus_space_tag_t sc_iot; - bus_space_tag_t sc_memt; - bus_space_handle_t sc_ioh; - int port_rid; int irq_rid; int mem_rid; struct resource *port_res; struct resource *irq_res; struct resource *mem_res; void *stg_intrhand; int sc_tmaxcnt; u_int sc_chip; /* chip type */ u_int sc_fsz; /* fifo size */ u_int sc_idbit; /* host id bit */ u_int sc_wthold; /* write thread */ u_int sc_rthold; /* read thread */ u_int sc_maxwsize; /* max write size */ int sc_dataout_timeout; /* data out timeout counter */ int sc_ubf_timeout; /* unexpected bus free timeout */ u_int8_t sc_fcWinit; /* write flags */ u_int8_t sc_fcRinit; /* read flags */ u_int8_t sc_icinit; /* interrupt masks */ u_int8_t sc_busc; /* default bus control register */ u_int8_t sc_imsg; /* identify msg required */ u_int8_t sc_busimg; /* bus control register image */ }; /***************************************************************** * Lun information *****************************************************************/ struct stg_targ_info { struct targ_info sti_ti; /* generic data */ u_int8_t sti_reg_synch; /* synch register per lun */ }; /***************************************************************** * Proto *****************************************************************/ -int stgprobesubr(bus_space_tag_t, bus_space_handle_t, u_int); +int stgprobesubr(struct resource *, u_int); void stgattachsubr(struct stg_softc *); int stgintr(void *); #endif /* !_TMC18C30VAR_H_ */ Index: projects/sendfile/sys/dev/wl/if_wl.c =================================================================== --- projects/sendfile/sys/dev/wl/if_wl.c (revision 274764) +++ projects/sendfile/sys/dev/wl/if_wl.c (revision 274765) @@ -1,2644 +1,2620 @@ /*- * 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 all copyright * notices, this list of conditions and the following disclaimer. * 2. The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. * */ /* * if_wl.c - original MACH, then BSDI ISA wavelan driver * ported to mach by Anders Klemets * to BSDI by Robert Morris * to FreeBSD by Jim Binkley * to FreeBSD 2.2+ by Michael Smith * * 2.2 update: * Changed interface to match 2.1-2.2 differences. * Implement IRQ selection logic in wlprobe() * Implement PSA updating. * Pruned heading comments for relevance. * Ripped out all the 'interface counters' cruft. * Cut the missing-interrupt timer back to 100ms. * 2.2.1 update: * now supports all multicast mode (mrouted will work), * but unfortunately must do that by going into promiscuous mode * NWID sysctl added so that normally promiscuous mode is NWID-specific * but can be made NWID-inspecific * 7/14/97 jrb * * Work done: * Ported to FreeBSD, got promiscuous mode working with bpfs, * and rewired timer routine. The i82586 will hang occasionally on output * and the watchdog timer will kick it if so and log an entry. * 2 second timeout there. Apparently the chip loses an interrupt. * Code borrowed from if_ie.c for watchdog timer. * * The wavelan card is a 2mbit radio modem that emulates ethernet; * i.e., it uses MAC addresses. This should not be a surprise since * it uses an ethernet controller as a major hw item. * It can broadcast, unicast or apparently multicast in a base cell * using an omni-directional antennae that is * about 800 feet around the base cell barring walls and metal. * With directional antennae, it can be used point to point over a mile * or so apparently (haven't tried that). * * There are ISA and pcmcia versions (not supported by this code). * The ISA card has an Intel 82586 lan controller on it. It consists * of 2 pieces of hw, the lan controller (intel) and a radio-modem. * The latter has an extra set of controller registers that has nothing * to do with the i82586 and allows setting and monitoring of radio * signal strength, etc. There is a nvram area called the PSA that * contains a number of setup variables including the IRQ and so-called * NWID or Network ID. The NWID must be set the same for all radio * cards to communicate (unless you are using the ATT/NCR roaming feature * with their access points. There is no support for that here. Roaming * involves a link-layer beacon sent out from the access points. End * stations monitor the signal strength and only use the strongest * access point). This driver assumes that the base ISA port, IRQ, * and NWID are first set in nvram via the dos-side "instconf.exe" utility * supplied with the card. This driver takes the ISA port from * the kernel configuration setup, and then determines the IRQ either * from the kernel config (if an explicit IRQ is set) or from the * PSA on the card if not. * The hw also magically just uses the IRQ set in the nvram. * The NWID is used magically as well by the radio-modem * to determine which packets to keep or throw out. * * sample config: * * device wl0 at isa? port 0x300 net irq ? * * Ifdefs: * 1. WLDEBUG. (off) - if turned on enables IFF_DEBUG set via ifconfig debug * 2. MULTICAST (on) - turned on and works up to and including mrouted * 3. WLCACHE (off) - define to turn on a signal strength * (and other metric) cache that is indexed by sender MAC address. * Apps can read this out to learn the remote signal strength of a * sender. Note that it has a switch so that it only stores * broadcast/multicast senders but it could be set to store unicast * too only. Size is hardwired in if_wl_wavelan.h * * one further note: promiscuous mode is a curious thing. In this driver, * promiscuous mode apparently CAN catch ALL packets and ignore the NWID * setting. This is probably more useful in a sense (for snoopers) if * you are interested in all traffic as opposed to if you are interested * in just your own. There is a driver specific sysctl to turn promiscuous * from just promiscuous to wildly promiscuous... * * This driver also knows how to load the synthesizers in the 2.4 Gz * ISA Half-card, Product number 847647476 (USA/FCC IEEE Channel set). * This product consists of a "mothercard" that contains the 82586, * NVRAM that holds the PSA, and the ISA-buss interface custom ASIC. * The radio transceiver is a "daughtercard" called the WaveMODEM which * connects to the mothercard through two single-inline connectors: a * 20-pin connector provides DC-power and modem signals, and a 3-pin * connector which exports the antenna connection. The code herein * loads the receive and transmit synthesizers and the corresponding * transmitter output power value from an EEPROM controlled through * additional registers via the MMC. The EEPROM address selected * are those whose values are preset by the DOS utility programs * provided with the product, and this provides compatible operation * with the DOS Packet Driver software. A future modification will * add the necessary functionality to this driver and to the wlconfig * utility to completely replace the DOS Configuration Utilities. * The 2.4 Gz WaveMODEM is described in document number 407-024692/E, * and is available through Lucent Technologies OEM supply channels. * --RAB 1997/06/08. */ #define MULTICAST 1 /* * Olivetti PC586 Mach Ethernet driver v1.0 * Copyright Ing. C. Olivetti & C. S.p.A. 1988, 1989 * All rights reserved. * */ /* Copyright 1988, 1989 by Olivetti Advanced Technology Center, Inc., Cupertino, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Olivetti not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. OLIVETTI DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL OLIVETTI BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUR OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ /* Copyright 1988, 1989 by Intel Corporation, Santa Clara, California. All Rights Reserved Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appears in all copies and that both the copyright notice and this permission notice appear in supporting documentation, and that the name of Intel not be used in advertising or publicity pertaining to distribution of the software without specific, written prior permission. INTEL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL INTEL BE LIABLE FOR ANY SPECIAL, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include __FBSDID("$FreeBSD$"); /* * NOTE: * by rvb: * 1. The best book on the 82586 is: * LAN Components User's Manual by Intel * The copy I found was dated 1984. This really tells you * what the state machines are doing * 2. In the current design, we only do one write at a time, * though the hardware is capable of chaining and possibly * even batching. The problem is that we only make one * transmit buffer available in sram space. */ #include "opt_wavelan.h" #include "opt_inet.h" #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #ifdef INET #include #include #include #include #endif #include #include /* was 1000 in original, fed to DELAY(x) */ #define DELAYCONST 1000 #include /* Definitions for the Intel chip */ #include #include static char t_packet[ETHERMTU + sizeof(struct ether_header) + sizeof(long)]; -struct wl_softc{ +struct wl_softc { + device_t dev; struct ifnet *ifp; u_char psa[0x40]; u_char nwid[2]; /* current radio modem nwid */ - short base; - short unit; int flags; int tbusy; /* flag to determine if xmit is busy */ u_short begin_fd; u_short end_fd; u_short end_rbd; u_short hacr; /* latest host adapter CR command */ short mode; u_char chan24; /* 2.4 Gz: channel number/EEPROM Area # */ u_short freq24; /* 2.4 Gz: resulting frequency */ int rid_ioport; int rid_irq; struct resource *res_ioport; struct resource *res_irq; void *intr_cookie; - bus_space_tag_t bt; - bus_space_handle_t bh; struct mtx wl_mtx; - struct callout_handle watchdog_ch; + struct callout watchdog_timer; #ifdef WLCACHE int w_sigitems; /* number of cached entries */ /* array of cache entries */ struct w_sigcache w_sigcache[ MAXCACHEITEMS ]; int w_nextcache; /* next free cache entry */ int w_wrapindex; /* next "free" cache entry */ #endif }; #define WL_LOCK(_sc) mtx_lock(&(_sc)->wl_mtx) #define WL_LOCK_ASSERT(_sc) mtx_assert(&(_sc)->wl_mtx, MA_OWNED) #define WL_UNLOCK(_sc) mtx_unlock(&(_sc)->wl_mtx) static int wlprobe(device_t); static int wlattach(device_t); static int wldetach(device_t); static device_method_t wl_methods[] = { DEVMETHOD(device_probe, wlprobe), DEVMETHOD(device_attach, wlattach), DEVMETHOD(device_detach, wldetach), { 0, 0} }; static driver_t wl_driver = { "wl", wl_methods, sizeof (struct wl_softc) }; devclass_t wl_devclass; DRIVER_MODULE(wl, isa, wl_driver, wl_devclass, 0, 0); MODULE_DEPEND(wl, isa, 1, 1, 1); MODULE_DEPEND(wl, ether, 1, 1, 1); static struct isa_pnp_id wl_ids[] = { {0, NULL} }; /* * XXX The Wavelan appears to be prone to dropping stuff if you talk to * it too fast. This disgusting hack inserts a delay after each packet * is queued which helps avoid this behaviour on fast systems. */ static int wl_xmit_delay = 250; SYSCTL_INT(_machdep, OID_AUTO, wl_xmit_delay, CTLFLAG_RW, &wl_xmit_delay, 0, ""); /* * not XXX, but ZZZ (bizarre). * promiscuous mode can be toggled to ignore NWIDs. By default, * it does not. Caution should be exercised about combining * this mode with IFF_ALLMULTI which puts this driver in * promiscuous mode. */ static int wl_ignore_nwid = 0; SYSCTL_INT(_machdep, OID_AUTO, wl_ignore_nwid, CTLFLAG_RW, &wl_ignore_nwid, 0, ""); /* * Emit diagnostics about transmission problems */ static int xmt_watch = 0; SYSCTL_INT(_machdep, OID_AUTO, wl_xmit_watch, CTLFLAG_RW, &xmt_watch, 0, ""); /* * Collect SNR statistics */ static int gathersnr = 0; SYSCTL_INT(_machdep, OID_AUTO, wl_gather_snr, CTLFLAG_RW, &gathersnr, 0, ""); static int wl_allocate_resources(device_t device); static int wl_deallocate_resources(device_t device); static void wlstart(struct ifnet *ifp); +static void wlstart_locked(struct ifnet *ifp); static void wlinit(void *xsc); +static void wlinit_locked(struct wl_softc *sc); static int wlioctl(struct ifnet *ifp, u_long cmd, caddr_t data); -static timeout_t wlwatchdog; +static void wlwatchdog(void *arg); static void wlintr(void *arg); static void wlxmt(struct wl_softc *sc, struct mbuf *m); static int wldiag(struct wl_softc *sc); static int wlconfig(struct wl_softc *sc); static int wlcmd(struct wl_softc *sc, char *str); static void wlmmcstat(struct wl_softc *sc); static u_short wlbldru(struct wl_softc *sc); -static u_short wlmmcread(u_int base, u_short reg); +static u_short wlmmcread(struct wl_softc *sc, u_short reg); static void wlinitmmc(struct wl_softc *sc); static int wlhwrst(struct wl_softc *sc); static void wlrustrt(struct wl_softc *sc); static void wlbldcu(struct wl_softc *sc); static int wlack(struct wl_softc *sc); static int wlread(struct wl_softc *sc, u_short fd_p); static void getsnr(struct wl_softc *sc); static void wlrcv(struct wl_softc *sc); static int wlrequeue(struct wl_softc *sc, u_short fd_p); static void wlsftwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc); static void wlhdwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc); #ifdef WLDEBUG static void wltbd(struct wl_softc *sc); #endif -static void wlgetpsa(int base, u_char *buf); +static void wlgetpsa(struct wl_softc *sc, u_char *buf); static void wlsetpsa(struct wl_softc *sc); static u_short wlpsacrc(u_char *buf); static void wldump(struct wl_softc *sc); #ifdef WLCACHE -static void wl_cache_store(struct wl_softc *, int, struct ether_header *, struct mbuf *); +static void wl_cache_store(struct wl_softc *, struct ether_header *, struct mbuf *); static void wl_cache_zero(struct wl_softc *sc); #endif /* array for maping irq numbers to values for the irq parameter register */ static int irqvals[16] = { 0, 0, 0, 0x01, 0x02, 0x04, 0, 0x08, 0, 0, 0x10, 0x20, 0x40, 0, 0, 0x80 }; /* * wlprobe: * * This function "probes" or checks for the WaveLAN board on the bus to * see if it is there. As far as I can tell, the best break between this * routine and the attach code is to simply determine whether the board * is configured in properly. Currently my approach to this is to write * and read a word from the SRAM on the board being probed. If the word * comes back properly then we assume the board is there. The config * code expects to see a successful return from the probe routine before * attach will be called. * * input : address device is mapped to, and unit # being checked * output : a '1' is returned if the board exists, and a 0 otherwise * */ static int wlprobe(device_t device) { struct wl_softc *sc; - short base; char *str = "wl%d: board out of range [0..%d]\n"; u_char inbuf[100]; - unsigned long junk, oldpri, sirq; + unsigned long junk, sirq; int error, irq; error = ISA_PNP_PROBE(device_get_parent(device), device, wl_ids); if (error == ENXIO || error == 0) return (error); sc = device_get_softc(device); error = wl_allocate_resources(device); if (error) goto errexit; - base = rman_get_start(sc->res_ioport); - /* TBD. not true. * regular CMD() will not work, since no softc yet */ -#define PCMD(base, hacr) outw((base), (hacr)) +#define PCMD(sc, hacr) WL_WRITE_2((sc), HACR, (hacr)) - oldpri = splimp(); - PCMD(base, HACR_RESET); /* reset the board */ + PCMD(sc, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ - PCMD(base, HACR_RESET); /* reset the board */ + PCMD(sc, HACR_RESET); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ - splx(oldpri); /* clear reset command and set PIO#1 in autoincrement mode */ - PCMD(base, HACR_DEFAULT); - PCMD(base, HACR_DEFAULT); - outw(PIOR1(base), 0); /* go to beginning of RAM */ - outsw(PIOP1(base), str, strlen(str)/2+1); /* write string */ + PCMD(sc, HACR_DEFAULT); + PCMD(sc, HACR_DEFAULT); + WL_WRITE_2(sc, PIOR1, 0); /* go to beginning of RAM */ + WL_WRITE_MULTI_2(sc, PIOP1, str, strlen(str)/2+1); /* write string */ - outw(PIOR1(base), 0); /* rewind */ - insw(PIOP1(base), inbuf, strlen(str)/2+1); /* read result */ + WL_WRITE_2(sc, PIOR1, 0); /* rewind */ + WL_READ_MULTI_2(sc, PIOP1, inbuf, strlen(str)/2+1); /* read result */ if (bcmp(str, inbuf, strlen(str))) { error = ENXIO; goto errexit; } sc->chan24 = 0; /* 2.4 Gz: config channel */ sc->freq24 = 0; /* 2.4 Gz: frequency */ /* read the PSA from the board into temporary storage */ - wlgetpsa(base, inbuf); + wlgetpsa(sc, inbuf); /* We read the IRQ value from the PSA on the board. */ for (irq = 15; irq >= 0; irq--) if (irqvals[irq] == inbuf[WLPSA_IRQNO]) break; if ((irq == 0) || (irqvals[irq] == 0)){ - printf("wl%d: PSA corrupt (invalid IRQ value)\n", - device_get_unit(device)); + device_printf(device, "PSA corrupt (invalid IRQ value)\n"); } else { /* * If the IRQ requested by the PSA is already claimed by another * device, the board won't work, but the user can still access the * driver to change the IRQ. */ if (bus_get_resource(device, SYS_RES_IRQ, 0, &sirq, &junk)) goto errexit; if (irq != (int)sirq) - printf("wl%d: board is configured for interrupt %d\n", - device_get_unit(device), irq); + device_printf(device, "board is configured for interrupt %d\n", + irq); } wl_deallocate_resources(device); return (0); errexit: wl_deallocate_resources(device); return (error); } /* * wlattach: * * This function attaches a WaveLAN board to the "system". The rest of * runtime structures are initialized here (this routine is called after * a successful probe of the board). Once the ethernet address is read * and stored, the board's ifnet structure is attached and readied. * * input : isa_dev structure setup in autoconfig * output : board structs and ifnet is setup * */ static int wlattach(device_t device) { struct wl_softc *sc; - short base; int error, i, j; - int unit; struct ifnet *ifp; u_char eaddr[6]; sc = device_get_softc(device); + sc->dev = device; ifp = sc->ifp = if_alloc(IFT_ETHER); if (ifp == NULL) { device_printf(device, "can not if_alloc()\n"); return (ENOSPC); } mtx_init(&sc->wl_mtx, device_get_nameunit(device), MTX_NETWORK_LOCK, - MTX_DEF | MTX_RECURSE); + MTX_DEF); + callout_init_mtx(&sc->watchdog_timer, &sc->wl_mtx, 0); error = wl_allocate_resources(device); if (error) { wl_deallocate_resources(device); return (ENXIO); } - base = rman_get_start(sc->res_ioport); - unit = device_get_unit(device); - #ifdef WLDEBUG - printf("wlattach: base %x, unit %d\n", base, unit); + printf("wlattach: base %lx, unit %d\n", rman_get_start(sc->res_ioport), + device_get_unit(device)); #endif - sc->base = base; - sc->unit = unit; sc->flags = 0; sc->mode = 0; sc->hacr = HACR_RESET; - callout_handle_init(&sc->watchdog_ch); CMD(sc); /* reset the board */ DELAY(DELAYCONST); /* >> 4 clocks at 6MHz */ /* clear reset command and set PIO#2 in parameter access mode */ sc->hacr = (HACR_DEFAULT & ~HACR_16BITS); CMD(sc); /* Read the PSA from the board for our later reference */ - wlgetpsa(base, sc->psa); + wlgetpsa(sc, sc->psa); /* fetch NWID */ sc->nwid[0] = sc->psa[WLPSA_NWID]; sc->nwid[1] = sc->psa[WLPSA_NWID+1]; /* fetch MAC address - decide which one first */ if (sc->psa[WLPSA_MACSEL] & 1) j = WLPSA_LOCALMAC; else j = WLPSA_UNIMAC; for (i=0; i < WAVELAN_ADDR_SIZE; ++i) eaddr[i] = sc->psa[j + i]; /* enter normal 16 bit mode operation */ sc->hacr = HACR_DEFAULT; CMD(sc); wlinitmmc(sc); - outw(PIOR1(base), OFFSET_SCB + 8); /* address of scb_crcerrs */ - outw(PIOP1(base), 0); /* clear scb_crcerrs */ - outw(PIOP1(base), 0); /* clear scb_alnerrs */ - outw(PIOP1(base), 0); /* clear scb_rscerrs */ - outw(PIOP1(base), 0); /* clear scb_ovrnerrs */ + WL_WRITE_2(sc, PIOR1, OFFSET_SCB + 8); /* address of scb_crcerrs */ + WL_WRITE_2(sc, PIOP1, 0); /* clear scb_crcerrs */ + WL_WRITE_2(sc, PIOP1, 0); /* clear scb_alnerrs */ + WL_WRITE_2(sc, PIOP1, 0); /* clear scb_rscerrs */ + WL_WRITE_2(sc, PIOP1, 0); /* clear scb_ovrnerrs */ ifp->if_softc = sc; ifp->if_mtu = WAVELAN_MTU; ifp->if_flags = IFF_BROADCAST | IFF_SIMPLEX; #ifdef WLDEBUG ifp->if_flags |= IFF_DEBUG; #endif #if MULTICAST ifp->if_flags |= IFF_MULTICAST; #endif /* MULTICAST */ if_initname(ifp, device_get_name(device), device_get_unit(device)); ifp->if_init = wlinit; ifp->if_start = wlstart; ifp->if_ioctl = wlioctl; ifp->if_snd.ifq_maxlen = ifqmaxlen; /* no entries ifp->if_done ifp->if_reset */ ether_ifattach(ifp, eaddr); if_printf(ifp, "NWID 0x%02x%02x", sc->nwid[0], sc->nwid[1]); if (sc->freq24) printf(", Freq %d MHz",sc->freq24); /* 2.4 Gz */ printf("\n"); /* 2.4 Gz */ bus_setup_intr(device, sc->res_irq, INTR_TYPE_NET, NULL, wlintr, sc, &sc->intr_cookie); if (bootverbose) wldump(sc); return (0); } static int wldetach(device_t device) { struct wl_softc *sc = device_get_softc(device); - device_t parent = device_get_parent(device); struct ifnet *ifp; ifp = sc->ifp; ether_ifdetach(ifp); WL_LOCK(sc); /* reset the board */ sc->hacr = HACR_RESET; CMD(sc); sc->hacr = HACR_DEFAULT; CMD(sc); + callout_stop(&sc->watchdog_timer); + WL_UNLOCK(sc); + callout_drain(&sc->watchdog_timer); if (sc->intr_cookie != NULL) { - BUS_TEARDOWN_INTR(parent, device, sc->res_irq, sc->intr_cookie); + bus_teardown_intr(device, sc->res_irq, sc->intr_cookie); sc->intr_cookie = NULL; } - bus_generic_detach(device); wl_deallocate_resources(device); - WL_UNLOCK(sc); if_free(ifp); mtx_destroy(&sc->wl_mtx); return (0); } static int wl_allocate_resources(device_t device) { struct wl_softc *sc = device_get_softc(device); int ports = 16; /* Number of ports */ sc->res_ioport = bus_alloc_resource(device, SYS_RES_IOPORT, &sc->rid_ioport, 0ul, ~0ul, ports, RF_ACTIVE); if (sc->res_ioport == NULL) goto errexit; sc->res_irq = bus_alloc_resource_any(device, SYS_RES_IRQ, &sc->rid_irq, RF_SHAREABLE|RF_ACTIVE); if (sc->res_irq == NULL) goto errexit; return (0); errexit: wl_deallocate_resources(device); return (ENXIO); } static int wl_deallocate_resources(device_t device) { struct wl_softc *sc = device_get_softc(device); if (sc->res_irq != 0) { bus_release_resource(device, SYS_RES_IRQ, sc->rid_irq, sc->res_irq); sc->res_irq = 0; } if (sc->res_ioport != 0) { bus_release_resource(device, SYS_RES_IOPORT, sc->rid_ioport, sc->res_ioport); sc->res_ioport = 0; } return (0); } /* * Print out interesting information about the 82596. */ static void wldump(struct wl_softc *sc) { - int base = sc->base; int i; - printf("hasr %04x\n", inw(HASR(base))); + printf("hasr %04x\n", WL_READ_2(sc, HASR)); printf("scb at %04x:\n ", OFFSET_SCB); - outw(PIOR1(base), OFFSET_SCB); + WL_WRITE_2(sc, PIOR1, OFFSET_SCB); for (i = 0; i < 8; i++) - printf("%04x ", inw(PIOP1(base))); + printf("%04x ", WL_READ_2(sc, PIOP1)); printf("\n"); printf("cu at %04x:\n ", OFFSET_CU); - outw(PIOR1(base), OFFSET_CU); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); for (i = 0; i < 8; i++) - printf("%04x ", inw(PIOP1(base))); + printf("%04x ", WL_READ_2(sc, PIOP1)); printf("\n"); printf("tbd at %04x:\n ", OFFSET_TBD); - outw(PIOR1(base), OFFSET_TBD); + WL_WRITE_2(sc, PIOR1, OFFSET_TBD); for (i = 0; i < 4; i++) - printf("%04x ", inw(PIOP1(base))); + printf("%04x ", WL_READ_2(sc, PIOP1)); printf("\n"); } /* Initialize the Modem Management Controller */ static void wlinitmmc(struct wl_softc *sc) { - int base = sc->base; int configured; int mode = sc->mode; int i; /* 2.4 Gz */ /* enter 8 bit operation */ sc->hacr = (HACR_DEFAULT & ~HACR_16BITS); CMD(sc); configured = sc->psa[WLPSA_CONFIGURED] & 1; /* * Set default modem control parameters. Taken from NCR document * 407-0024326 Rev. A */ MMC_WRITE(MMC_JABBER_ENABLE, 0x01); MMC_WRITE(MMC_ANTEN_SEL, 0x02); MMC_WRITE(MMC_IFS, 0x20); MMC_WRITE(MMC_MOD_DELAY, 0x04); MMC_WRITE(MMC_JAM_TIME, 0x38); MMC_WRITE(MMC_DECAY_PRM, 0x00); /* obsolete ? */ MMC_WRITE(MMC_DECAY_UPDAT_PRM, 0x00); if (!configured) { MMC_WRITE(MMC_LOOPT_SEL, 0x00); if (sc->psa[WLPSA_COMPATNO] & 1) { MMC_WRITE(MMC_THR_PRE_SET, 0x01); /* 0x04 for AT and 0x01 for MCA */ } else { MMC_WRITE(MMC_THR_PRE_SET, 0x04); /* 0x04 for AT and 0x01 for MCA */ } MMC_WRITE(MMC_QUALITY_THR, 0x03); } else { /* use configuration defaults from parameter storage area */ if (sc->psa[WLPSA_NWIDENABLE] & 1) { if ((mode & (MOD_PROM | MOD_ENAL)) && wl_ignore_nwid) { MMC_WRITE(MMC_LOOPT_SEL, 0x40); } else { MMC_WRITE(MMC_LOOPT_SEL, 0x00); } } else { MMC_WRITE(MMC_LOOPT_SEL, 0x40); /* disable network id check */ } MMC_WRITE(MMC_THR_PRE_SET, sc->psa[WLPSA_THRESH]); MMC_WRITE(MMC_QUALITY_THR, sc->psa[WLPSA_QUALTHRESH]); } MMC_WRITE(MMC_FREEZE, 0x00); MMC_WRITE(MMC_ENCR_ENABLE, 0x00); MMC_WRITE(MMC_NETW_ID_L,sc->nwid[1]); /* set NWID */ MMC_WRITE(MMC_NETW_ID_H,sc->nwid[0]); /* enter normal 16 bit mode operation */ sc->hacr = HACR_DEFAULT; CMD(sc); CMD(sc); /* virtualpc1 needs this! */ if (sc->psa[WLPSA_COMPATNO]== /* 2.4 Gz: half-card ver */ WLPSA_COMPATNO_WL24B) { /* 2.4 Gz */ i=sc->chan24<<4; /* 2.4 Gz: position ch # */ MMC_WRITE(MMC_EEADDR,i+0x0f); /* 2.4 Gz: named ch, wc=16 */ MMC_WRITE(MMC_EECTRL,MMC_EECTRL_DWLD+ /* 2.4 Gz: Download Synths */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: Read EEPROM */ for (i=0; i<1000; ++i) { /* 2.4 Gz: wait for download */ DELAY(40); /* 2.4 Gz */ - if ((wlmmcread(base,MMC_EECTRLstat) /* 2.4 Gz: check DWLD and */ + if ((wlmmcread(sc, MMC_EECTRLstat) /* 2.4 Gz: check DWLD and */ &(MMC_EECTRLstat_DWLD /* 2.4 Gz: EEBUSY */ +MMC_EECTRLstat_EEBUSY))==0) /* 2.4 Gz: */ break; /* 2.4 Gz: download finished */ } /* 2.4 Gz */ if (i==1000) printf("wl: synth load failed\n"); /* 2.4 Gz */ MMC_WRITE(MMC_EEADDR,0x61); /* 2.4 Gz: default pwr, wc=2 */ MMC_WRITE(MMC_EECTRL,MMC_EECTRL_DWLD+ /* 2.4 Gz: Download Xmit Pwr */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: Read EEPROM */ for (i=0; i<1000; ++i) { /* 2.4 Gz: wait for download */ DELAY(40); /* 2.4 Gz */ - if ((wlmmcread(base,MMC_EECTRLstat) /* 2.4 Gz: check DWLD and */ + if ((wlmmcread(sc, MMC_EECTRLstat) /* 2.4 Gz: check DWLD and */ &(MMC_EECTRLstat_DWLD /* 2.4 Gz: EEBUSY */ +MMC_EECTRLstat_EEBUSY))==0) /* 2.4 Gz: */ break; /* 2.4 Gz: download finished */ } /* 2.4 Gz */ if (i==1000) printf("wl: xmit pwr load failed\n"); /* 2.4 Gz */ MMC_WRITE(MMC_ANALCTRL, /* 2.4 Gz: EXT ant+polarity */ MMC_ANALCTRL_ANTPOL + /* 2.4 Gz: */ MMC_ANALCTRL_EXTANT); /* 2.4 Gz: */ i=sc->chan24<<4; /* 2.4 Gz: position ch # */ MMC_WRITE(MMC_EEADDR,i); /* 2.4 Gz: get frequency */ MMC_WRITE(MMC_EECTRL, /* 2.4 Gz: EEPROM read */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: */ DELAY(40); /* 2.4 Gz */ - i = wlmmcread(base,MMC_EEDATALrv) /* 2.4 Gz: freq val */ - + (wlmmcread(base,MMC_EEDATAHrv)<<8); /* 2.4 Gz */ + i = wlmmcread(sc, MMC_EEDATALrv) /* 2.4 Gz: freq val */ + + (wlmmcread(sc, MMC_EEDATAHrv)<<8); /* 2.4 Gz */ sc->freq24 = (i>>6)+2400; /* 2.4 Gz: save real freq */ } } /* * wlinit: * * Another routine that interfaces the "if" layer to this driver. * Simply resets the structures that are used by "upper layers". * As well as calling wlhwrst that does reset the WaveLAN board. * * input : softc pointer for this interface * output : structures (if structs) and board are reset * */ static void wlinit(void *xsc) { struct wl_softc *sc = xsc; + + WL_LOCK(sc); + wlinit_locked(sc); + WL_UNLOCK(sc); +} + +static void +wlinit_locked(struct wl_softc *sc) +{ struct ifnet *ifp = sc->ifp; int stat; - u_long oldpri; #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlinit()\n",sc->unit); + if_printf(ifp, "entered wlinit()\n"); #endif - WL_LOCK(sc); - oldpri = splimp(); + WL_LOCK_ASSERT(sc); if ((stat = wlhwrst(sc)) == TRUE) { sc->ifp->if_drv_flags |= IFF_DRV_RUNNING; /* same as DSF_RUNNING */ /* * OACTIVE is used by upper-level routines * and must be set */ sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; /* same as tbusy below */ sc->flags |= DSF_RUNNING; sc->tbusy = 0; - untimeout(wlwatchdog, sc, sc->watchdog_ch); + callout_stop(&sc->watchdog_timer); - wlstart(ifp); + wlstart_locked(ifp); } else { - printf("wl%d init(): trouble resetting board.\n", sc->unit); + if_printf(ifp, "init(): trouble resetting board.\n"); } - splx(oldpri); - WL_UNLOCK(sc); } /* * wlhwrst: * * This routine resets the WaveLAN board that corresponds to the * board number passed in. * * input : board number to do a hardware reset * output : board is reset * */ static int wlhwrst(struct wl_softc *sc) { #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlhwrst()\n", sc->unit); + if_printf(sc->ifp, "entered wlhwrst()\n"); #endif sc->hacr = HACR_RESET; CMD(sc); /* reset the board */ /* clear reset command and set PIO#1 in autoincrement mode */ sc->hacr = HACR_DEFAULT; CMD(sc); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) wlmmcstat(sc); /* Display MMC registers */ #endif /* WLDEBUG */ wlbldcu(sc); /* set up command unit structures */ if (wldiag(sc) == 0) return(0); if (wlconfig(sc) == 0) return(0); /* * insert code for loopback test here */ wlrustrt(sc); /* start receive unit */ /* enable interrupts */ sc->hacr = (HACR_DEFAULT | HACR_INTRON); CMD(sc); return(1); } /* * wlbldcu: * * This function builds up the command unit structures. It inits * the scp, iscp, scb, cb, tbd, and tbuf. * */ static void wlbldcu(struct wl_softc *sc) { - short base = sc->base; scp_t scp; iscp_t iscp; scb_t scb; ac_t cb; tbd_t tbd; int i; bzero(&scp, sizeof(scp)); scp.scp_sysbus = 0; scp.scp_iscp = OFFSET_ISCP; scp.scp_iscp_base = 0; - outw(PIOR1(base), OFFSET_SCP); - outsw(PIOP1(base), &scp, sizeof(scp_t)/2); + WL_WRITE_2(sc, PIOR1, OFFSET_SCP); + WL_WRITE_MULTI_2(sc, PIOP1, &scp, sizeof(scp_t)/2); bzero(&iscp, sizeof(iscp)); iscp.iscp_busy = 1; iscp.iscp_scb_offset = OFFSET_SCB; iscp.iscp_scb = 0; iscp.iscp_scb_base = 0; - outw(PIOR1(base), OFFSET_ISCP); - outsw(PIOP1(base), &iscp, sizeof(iscp_t)/2); + WL_WRITE_2(sc, PIOR1, OFFSET_ISCP); + WL_WRITE_MULTI_2(sc, PIOP1, &iscp, sizeof(iscp_t)/2); scb.scb_status = 0; scb.scb_command = SCB_RESET; scb.scb_cbl_offset = OFFSET_CU; scb.scb_rfa_offset = OFFSET_RU; scb.scb_crcerrs = 0; scb.scb_alnerrs = 0; scb.scb_rscerrs = 0; scb.scb_ovrnerrs = 0; - outw(PIOR1(base), OFFSET_SCB); - outsw(PIOP1(base), &scb, sizeof(scb_t)/2); + WL_WRITE_2(sc, PIOR1, OFFSET_SCB); + WL_WRITE_MULTI_2(sc, PIOP1, &scb, sizeof(scb_t)/2); SET_CHAN_ATTN(sc); - outw(PIOR0(base), OFFSET_ISCP + 0); /* address of iscp_busy */ - for (i = 1000000; inw(PIOP0(base)) && (i-- > 0); ) + WL_WRITE_2(sc, PIOR0, OFFSET_ISCP + 0); /* address of iscp_busy */ + for (i = 1000000; WL_READ_2(sc, PIOP0) && (i-- > 0); ) continue; if (i <= 0) - printf("wl%d bldcu(): iscp_busy timeout.\n", sc->unit); - outw(PIOR0(base), OFFSET_SCB + 0); /* address of scb_status */ + device_printf(sc->dev, "bldcu(): iscp_busy timeout.\n"); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 0); /* address of scb_status */ for (i = STATUS_TRIES; i-- > 0; ) { - if (inw(PIOP0(base)) == (SCB_SW_CX|SCB_SW_CNA)) + if (WL_READ_2(sc, PIOP0) == (SCB_SW_CX|SCB_SW_CNA)) break; } if (i <= 0) - printf("wl%d bldcu(): not ready after reset.\n", sc->unit); + device_printf(sc->dev, "bldcu(): not ready after reset.\n"); wlack(sc); cb.ac_status = 0; cb.ac_command = AC_CW_EL; /* NOP */ cb.ac_link_offset = OFFSET_CU; - outw(PIOR1(base), OFFSET_CU); - outsw(PIOP1(base), &cb, 6/2); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_MULTI_2(sc, PIOP1, &cb, 6/2); tbd.act_count = 0; tbd.next_tbd_offset = I82586NULL; tbd.buffer_addr = 0; tbd.buffer_base = 0; - outw(PIOR1(base), OFFSET_TBD); - outsw(PIOP1(base), &tbd, sizeof(tbd_t)/2); + WL_WRITE_2(sc, PIOR1, OFFSET_TBD); + WL_WRITE_MULTI_2(sc, PIOP1, &tbd, sizeof(tbd_t)/2); } /* * wlstart: * * send a packet * * input : board number * output : stuff sent to board if any there * */ static void wlstart(struct ifnet *ifp) { + struct wl_softc *sc = ifp->if_softc; + + WL_LOCK(sc); + wlstart_locked(ifp); + WL_UNLOCK(sc); +} + +static void +wlstart_locked(struct ifnet *ifp) +{ struct mbuf *m; struct wl_softc *sc = ifp->if_softc; - short base = sc->base; int scb_status, cu_status, scb_command; - WL_LOCK(sc); + WL_LOCK_ASSERT(sc); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("%s: entered wlstart()\n", ifp->if_xname); + if_printf(ifp, "entered wlstart()\n"); #endif - outw(PIOR1(base), OFFSET_CU); - cu_status = inw(PIOP1(base)); - outw(PIOR0(base),OFFSET_SCB + 0); /* scb_status */ - scb_status = inw(PIOP0(base)); - outw(PIOR0(base), OFFSET_SCB + 2); - scb_command = inw(PIOP0(base)); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + cu_status = WL_READ_2(sc, PIOP1); + WL_WRITE_2(sc, PIOR0,OFFSET_SCB + 0); /* scb_status */ + scb_status = WL_READ_2(sc, PIOP0); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 2); + scb_command = WL_READ_2(sc, PIOP0); /* * don't need OACTIVE check as tbusy here checks to see * if we are already busy */ if (sc->tbusy) { if ((scb_status & 0x0700) == SCB_CUS_IDLE && (cu_status & AC_SW_B) == 0){ sc->tbusy = 0; - untimeout(wlwatchdog, sc, sc->watchdog_ch); + callout_stop(&sc->watchdog_timer); sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; /* * This is probably just a race. The xmt'r is just * became idle but WE have masked interrupts so ... */ #ifdef WLDEBUG - printf("%s: CU idle, scb %04x %04x cu %04x\n", - ifp->if_xname, scb_status, scb_command, cu_status); + if_printf(ifp, "CU idle, scb %04x %04x cu %04x\n", + scb_status, scb_command, cu_status); #endif if (xmt_watch) printf("!!"); } else { - WL_UNLOCK(sc); return; /* genuinely still busy */ } } else if ((scb_status & 0x0700) == SCB_CUS_ACTV || (cu_status & AC_SW_B)){ #ifdef WLDEBUG - printf("%s: CU unexpectedly busy; scb %04x cu %04x\n", - ifp->if_xname, scb_status, cu_status); + if_printf(ifp, "CU unexpectedly busy; scb %04x cu %04x\n", + scb_status, cu_status); #endif - if (xmt_watch) printf("%s: busy?!",ifp->if_xname); - WL_UNLOCK(sc); + if (xmt_watch) + if_printf(ifp, "busy?!\n"); return; /* hey, why are we busy? */ } /* get ourselves some data */ - ifp = sc->ifp; IF_DEQUEUE(&ifp->if_snd, m); - if (m != (struct mbuf *)0) { + if (m != NULL) { /* let BPF see it before we commit it */ BPF_MTAP(ifp, m); sc->tbusy++; /* set the watchdog timer so that if the board * fails to interrupt we will restart */ - /* try 10 ticks, not very long */ - sc->watchdog_ch = timeout(wlwatchdog, sc, 10); + /* try 10 ms, not very long */ + callout_reset(&sc->watchdog_timer, hz / 100, wlwatchdog, sc); sc->ifp->if_drv_flags |= IFF_DRV_OACTIVE; if_inc_counter(sc->ifp, IFCOUNTER_OPACKETS, 1); wlxmt(sc, m); } else { sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; } - WL_UNLOCK(sc); return; } /* * wlread: * * This routine does the actual copy of data (including ethernet header * structure) from the WaveLAN to an mbuf chain that will be passed up * to the "if" (network interface) layer. NOTE: we currently * don't handle trailer protocols, so if that is needed, it will * (at least in part) be added here. For simplicities sake, this * routine copies the receive buffers from the board into a local (stack) * buffer until the frame has been copied from the board. Once in * the local buffer, the contents are copied to an mbuf chain that * is then enqueued onto the appropriate "if" queue. * * input : board number, and a frame descriptor address * output : the packet is put into an mbuf chain, and passed up * assumes : if any errors occur, packet is "dropped on the floor" * */ static int wlread(struct wl_softc *sc, u_short fd_p) { struct ifnet *ifp = sc->ifp; - short base = sc->base; fd_t fd; struct ether_header *eh; struct mbuf *m; rbd_t rbd; u_char *mb_p; u_short mlen, len; u_short bytes_in_msg, bytes_in_mbuf, bytes; WL_LOCK_ASSERT(sc); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlread()\n", sc->unit); + if_printf(ifp, "entered wlread()\n"); #endif if (!((ifp->if_flags & IFF_UP) && (ifp->if_drv_flags & IFF_DRV_RUNNING))) { - printf("%s read(): board is not running.\n", ifp->if_xname); + if_printf(ifp, "read(): board is not running.\n"); sc->hacr &= ~HACR_INTRON; CMD(sc); /* turn off interrupts */ } /* * Collect message size. */ - outw(PIOR1(base), fd_p); - insw(PIOP1(base), &fd, sizeof(fd_t)/2); + WL_WRITE_2(sc, PIOR1, fd_p); + WL_READ_MULTI_2(sc, PIOP1, &fd, sizeof(fd_t)/2); if (fd.rbd_offset == I82586NULL) { if (wlhwrst(sc) != TRUE) { sc->hacr &= ~HACR_INTRON; CMD(sc); /* turn off interrupts */ - printf("wl%d read(): hwrst trouble.\n", sc->unit); + if_printf(ifp, "read(): hwrst trouble.\n"); } return 0; } - outw(PIOR1(base), fd.rbd_offset); - insw(PIOP1(base), &rbd, sizeof(rbd_t)/2); + WL_WRITE_2(sc, PIOR1, fd.rbd_offset); + WL_READ_MULTI_2(sc, PIOP1, &rbd, sizeof(rbd_t)/2); bytes_in_msg = rbd.status & RBD_SW_COUNT; /* * Allocate a cluster'd mbuf to receive the packet. */ m = m_getcl(M_NOWAIT, MT_DATA, M_PKTHDR); if (m == NULL) { if (wlhwrst(sc) != TRUE) { sc->hacr &= ~HACR_INTRON; CMD(sc); /* turn off interrupts */ - printf("wl%d read(): hwrst trouble.\n", sc->unit); + if_printf(ifp, "read(): hwrst trouble.\n"); } return 0; } m->m_pkthdr.len = m->m_len = MCLBYTES; m_adj(m, ETHER_ALIGN); /* align IP header */ /* * Collect the message data. */ mlen = 0; mb_p = mtod(m, u_char *); bytes_in_mbuf = m->m_len; /* Put the ethernet header inside the mbuf. */ bcopy(&fd.destination[0], mb_p, 14); mb_p += 14; mlen += 14; bytes_in_mbuf -= 14; bytes = min(bytes_in_mbuf, bytes_in_msg); for (;;) { if (bytes & 1) { len = bytes + 1; } else { len = bytes; } - outw(PIOR1(base), rbd.buffer_addr); - insw(PIOP1(base), mb_p, len/2); + WL_WRITE_2(sc, PIOR1, rbd.buffer_addr); + WL_READ_MULTI_2(sc, PIOP1, mb_p, len/2); mlen += bytes; if (bytes > bytes_in_mbuf) { /* XXX something wrong, a packet should fit in 1 cluster */ m_freem(m); - printf("wl%d read(): packet too large (%u > %u)\n", - sc->unit, bytes, bytes_in_mbuf); + if_printf(ifp, "read(): packet too large (%u > %u)\n", + bytes, bytes_in_mbuf); if (wlhwrst(sc) != TRUE) { sc->hacr &= ~HACR_INTRON; CMD(sc); /* turn off interrupts */ - printf("wl%d read(): hwrst trouble.\n", sc->unit); + if_printf(ifp, "read(): hwrst trouble.\n"); } return 0; } mb_p += bytes; bytes_in_mbuf -= bytes; bytes_in_msg -= bytes; if (bytes_in_msg == 0) { if (rbd.status & RBD_SW_EOF || rbd.next_rbd_offset == I82586NULL) { break; } - outw(PIOR1(base), rbd.next_rbd_offset); - insw(PIOP1(base), &rbd, sizeof(rbd_t)/2); + WL_WRITE_2(sc, PIOR1, rbd.next_rbd_offset); + WL_READ_MULTI_2(sc, PIOP1, &rbd, sizeof(rbd_t)/2); bytes_in_msg = rbd.status & RBD_SW_COUNT; } else { rbd.buffer_addr += bytes; } bytes = min(bytes_in_mbuf, bytes_in_msg); } m->m_pkthdr.len = m->m_len = mlen; m->m_pkthdr.rcvif = ifp; /* * If hw is in promiscuous mode (note that I said hardware, not if * IFF_PROMISC is set in ifnet flags), then if this is a unicast * packet and the MAC dst is not us, drop it. This check in normally * inside ether_input(), but IFF_MULTI causes hw promisc without * a bpf listener, so this is wrong. * Greg Troxel , 1998-08-07 */ /* * TBD: also discard packets where NWID does not match. * However, there does not appear to be a way to read the nwid * for a received packet. -gdt 1998-08-07 */ /* XXX verify mbuf length */ eh = mtod(m, struct ether_header *); if ( #ifdef WL_USE_IFNET_PROMISC_CHECK /* not defined */ (sc->ifp->if_flags & (IFF_PROMISC|IFF_ALLMULTI)) #else /* hw is in promisc mode if this is true */ (sc->mode & (MOD_PROM | MOD_ENAL)) #endif && (eh->ether_dhost[0] & 1) == 0 && /* !mcast and !bcast */ bcmp(eh->ether_dhost, IF_LLADDR(sc->ifp), sizeof(eh->ether_dhost)) != 0 ) { m_freem(m); return 1; } #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: wlrecv %u bytes\n", sc->unit, mlen); + if_printf(ifp, "wlrecv %u bytes\n", mlen); #endif #ifdef WLCACHE - wl_cache_store(sc, base, eh, m); + wl_cache_store(sc, eh, m); #endif /* * received packet is now in a chain of mbuf's. next step is * to pass the packet upwards. */ WL_UNLOCK(sc); (*ifp->if_input)(ifp, m); WL_LOCK(sc); return 1; } /* * wlioctl: * * This routine processes an ioctl request from the "if" layer * above. * * input : pointer the appropriate "if" struct, command, and data * output : based on command appropriate action is taken on the * WaveLAN board(s) or related structures * return : error is returned containing exit conditions * */ static int wlioctl(struct ifnet *ifp, u_long cmd, caddr_t data) { struct ifreq *ifr = (struct ifreq *)data; struct wl_softc *sc = ifp->if_softc; - short base = sc->base; short mode = 0; - int opri, error = 0; + int error = 0; struct thread *td = curthread; /* XXX */ int irq, irqval, i, isroot; - caddr_t up; + char psa_buf[0x40]; + char eeprom_buf[0x80]; #ifdef WLCACHE - int size; + size_t size; char * cpt; #endif - WL_LOCK(sc); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("%s: entered wlioctl()\n", ifp->if_xname); + if_printf(ifp, "entered wlioctl()\n"); #endif - opri = splimp(); switch (cmd) { case SIOCSIFFLAGS: + WL_LOCK(sc); if (ifp->if_flags & IFF_ALLMULTI) { mode |= MOD_ENAL; } if (ifp->if_flags & IFF_PROMISC) { mode |= MOD_PROM; } if (ifp->if_flags & IFF_LINK0) { mode |= MOD_PROM; } /* * force a complete reset if the recieve multicast/ * promiscuous mode changes so that these take * effect immediately. * */ if (sc->mode != mode) { sc->mode = mode; if (sc->flags & DSF_RUNNING) { sc->flags &= ~DSF_RUNNING; - wlinit(sc); + wlinit_locked(sc); } } /* if interface is marked DOWN and still running then * stop it. */ if ((ifp->if_flags & IFF_UP) == 0 && sc->flags & DSF_RUNNING) { - printf("%s ioctl(): board is not running\n", ifp->if_xname); + if_printf(ifp, "ioctl(): board is not running\n"); sc->flags &= ~DSF_RUNNING; sc->hacr &= ~HACR_INTRON; CMD(sc); /* turn off interrupts */ } /* else if interface is UP and RUNNING, start it */ else if (ifp->if_flags & IFF_UP && (sc->flags & DSF_RUNNING) == 0) { - wlinit(sc); + wlinit_locked(sc); } /* if WLDEBUG set on interface, then printf rf-modem regs */ if (ifp->if_flags & IFF_DEBUG) wlmmcstat(sc); + WL_UNLOCK(sc); break; #if MULTICAST case SIOCADDMULTI: case SIOCDELMULTI: wlinit(sc); break; #endif /* MULTICAST */ /* DEVICE SPECIFIC */ /* copy the PSA out to the caller */ case SIOCGWLPSA: - /* pointer to buffer in user space */ - up = (void *)ifr->ifr_data; /* work out if they're root */ isroot = (priv_check(td, PRIV_NET80211_GETKEY) == 0); - + + bzero(psa_buf, sizeof(psa_buf)); + WL_LOCK(sc); for (i = 0; i < 0x40; i++) { /* don't hand the DES key out to non-root users */ if ((i > WLPSA_DESKEY) && (i < (WLPSA_DESKEY + 8)) && !isroot) continue; - if (subyte((up + i), sc->psa[i])) { - WL_UNLOCK(sc); - return(EFAULT); - } + psa_buf[i] = sc->psa[i]; } + WL_UNLOCK(sc); + + error = copyout(psa_buf, ifr->ifr_data, sizeof(psa_buf)); break; /* copy the PSA in from the caller; we only copy _some_ values */ case SIOCSWLPSA: /* root only */ if ((error = priv_check(td, PRIV_DRIVER))) break; - error = EINVAL; /* assume the worst */ - /* pointer to buffer in user space containing data */ - up = (void *)ifr->ifr_data; - - /* check validity of input range */ - for (i = 0; i < 0x40; i++) - if (fubyte(up + i) < 0) { - WL_UNLOCK(sc); - return(EFAULT); - } + error = copyin(ifr->ifr_data, psa_buf, sizeof(psa_buf)); + if (error) + break; + /* check IRQ value */ - irqval = fubyte(up+WLPSA_IRQNO); + irqval = psa_buf[WLPSA_IRQNO]; for (irq = 15; irq >= 0; irq--) if (irqvals[irq] == irqval) break; if (irq == 0) /* oops */ break; + WL_LOCK(sc); /* new IRQ */ sc->psa[WLPSA_IRQNO] = irqval; /* local MAC */ for (i = 0; i < 6; i++) - sc->psa[WLPSA_LOCALMAC+i] = fubyte(up+WLPSA_LOCALMAC+i); + sc->psa[WLPSA_LOCALMAC + i] = psa_buf[WLPSA_LOCALMAC + i]; /* MAC select */ - sc->psa[WLPSA_MACSEL] = fubyte(up+WLPSA_MACSEL); + sc->psa[WLPSA_MACSEL] = psa_buf[WLPSA_MACSEL]; /* default nwid */ - sc->psa[WLPSA_NWID] = fubyte(up+WLPSA_NWID); - sc->psa[WLPSA_NWID+1] = fubyte(up+WLPSA_NWID+1); + sc->psa[WLPSA_NWID] = psa_buf[WLPSA_NWID]; + sc->psa[WLPSA_NWID + 1] = psa_buf[WLPSA_NWID + 1]; - error = 0; wlsetpsa(sc); /* update the PSA */ + WL_UNLOCK(sc); break; /* get the current NWID out of the sc since we stored it there */ case SIOCGWLCNWID: + WL_LOCK(sc); ifr->ifr_data = (caddr_t) (sc->nwid[0] << 8 | sc->nwid[1]); + WL_UNLOCK(sc); break; /* * change the nwid dynamically. This * ONLY changes the radio modem and does not * change the PSA. * * 2 steps: * 1. save in softc "soft registers" * 2. save in radio modem (MMC) */ case SIOCSWLCNWID: /* root only */ if ((error = priv_check(td, PRIV_DRIVER))) break; + WL_LOCK(sc); if (!(ifp->if_flags & IFF_UP)) { error = EIO; /* only allowed while up */ } else { /* * soft c nwid shadows radio modem setting */ sc->nwid[0] = (int)ifr->ifr_data >> 8; sc->nwid[1] = (int)ifr->ifr_data & 0xff; MMC_WRITE(MMC_NETW_ID_L,sc->nwid[1]); MMC_WRITE(MMC_NETW_ID_H,sc->nwid[0]); } + WL_UNLOCK(sc); break; /* copy the EEPROM in 2.4 Gz WaveMODEM out to the caller */ case SIOCGWLEEPROM: /* root only */ if ((error = priv_check(td, PRIV_DRIVER))) break; - /* pointer to buffer in user space */ - up = (void *)ifr->ifr_data; - + + bzero(eeprom_buf, sizeof(eeprom_buf)); + WL_LOCK(sc); for (i=0x00; i<0x80; ++i) { /* 2.4 Gz: size of EEPROM */ MMC_WRITE(MMC_EEADDR,i); /* 2.4 Gz: get frequency */ MMC_WRITE(MMC_EECTRL, /* 2.4 Gz: EEPROM read */ MMC_EECTRL_EEOP_READ); /* 2.4 Gz: */ DELAY(40); /* 2.4 Gz */ - if (subyte(up + 2*i, /* 2.4 Gz: pass low byte of */ - wlmmcread(base,MMC_EEDATALrv))) {/* 2.4 Gz: EEPROM word */ - WL_UNLOCK(sc); - return(EFAULT); /* 2.4 Gz: */ - } - if (subyte(up + 2*i+1, /* 2.4 Gz: pass hi byte of */ - wlmmcread(base,MMC_EEDATALrv))) {/* 2.4 Gz: EEPROM word */ - WL_UNLOCK(sc); - return(EFAULT); /* 2.4 Gz: */ - } + eeprom_buf[2 * i] = /* 2.4 Gz: pass low byte of */ + wlmmcread(sc, MMC_EEDATALrv); /* 2.4 Gz: EEPROM word */ + eeprom_buf[2 * i + 1] = /* 2.4 Gz: pass hi byte of */ + wlmmcread(sc, MMC_EEDATALrv); /* 2.4 Gz: EEPROM word */ } + WL_UNLOCK(sc); + error = copyout(ifr->ifr_data, eeprom_buf, sizeof(eeprom_buf)); break; #ifdef WLCACHE /* zero (Delete) the wl cache */ case SIOCDWLCACHE: /* root only */ if ((error = priv_check(td, PRIV_DRIVER))) break; + WL_LOCK(sc); wl_cache_zero(sc); + WL_UNLOCK(sc); break; /* read out the number of used cache elements */ case SIOCGWLCITEM: + WL_LOCK(sc); ifr->ifr_data = (caddr_t) sc->w_sigitems; + WL_UNLOCK(sc); break; /* read out the wl cache */ case SIOCGWLCACHE: - /* pointer to buffer in user space */ - up = (void *)ifr->ifr_data; - cpt = (char *) &sc->w_sigcache[0]; + WL_LOCK(sc); size = sc->w_sigitems * sizeof(struct w_sigcache); - - for (i = 0; i < size; i++) { - if (subyte((up + i), *cpt++)) { - WL_UNLOCK(sc); - return(EFAULT); - } + cpt = malloc(size, M_DEVBUF, M_NOWAIT | M_ZERO); + if (cpt == NULL) { + WL_UNLOCK(sc); + return (ENOMEM); } + + bcopy(sc->w_sigcache, cpt, size); + WL_UNLOCK(sc); + + error = copyout(cpt, ifr->ifr_data, size); + free(cpt, M_DEVBUF); break; #endif default: error = ether_ioctl(ifp, cmd, data); break; } - splx(opri); - WL_UNLOCK(sc); return (error); } /* * wlwatchdog(): * * Called if the timer set in wlstart expires before an interrupt is received * from the wavelan. It seems to lose interrupts sometimes. * The watchdog routine gets called if the transmitter failed to interrupt * * input : which board is timing out * output : board reset * */ static void wlwatchdog(void *vsc) { struct wl_softc *sc = vsc; - int unit = sc->unit; - log(LOG_ERR, "wl%d: wavelan device timeout on xmit\n", unit); - WL_LOCK(sc); + log(LOG_ERR, "%s: wavelan device timeout on xmit\n", sc->ifp->if_xname); if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); - wlinit(sc); - WL_UNLOCK(sc); + wlinit_locked(sc); } /* * wlintr: * * This function is the interrupt handler for the WaveLAN * board. This routine will be called whenever either a packet * is received, or a packet has successfully been transfered and * the unit is ready to transmit another packet. * * input : board number that interrupted * output : either a packet is received, or a packet is transfered * */ static void wlintr(void *arg) { struct wl_softc *sc = (struct wl_softc *)arg; - short base = sc->base; int ac_status; u_short int_type, int_type1; WL_LOCK(sc); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: wlintr() called\n", sc->unit); + if_printf(sc->ifp, "wlintr() called\n"); #endif - if ((int_type = inw(HASR(base))) & HASR_MMC_INTR) { + if ((int_type = WL_READ_2(sc, HASR)) & HASR_MMC_INTR) { /* handle interrupt from the modem management controler */ /* This will clear the interrupt condition */ - (void) wlmmcread(base,MMC_DCE_STATUS); /* ignored for now */ + (void) wlmmcread(sc, MMC_DCE_STATUS); /* ignored for now */ } if (!(int_type & HASR_INTR)){ /* return if no interrupt from 82586 */ /* commented out. jrb. it happens when reinit occurs printf("wlintr: int_type %x, dump follows\n", int_type); - wldump(unit); + wldump(sc); */ WL_UNLOCK(sc); return; } if (gathersnr) getsnr(sc); for (;;) { - outw(PIOR0(base), OFFSET_SCB + 0); /* get scb status */ - int_type = (inw(PIOP0(base)) & SCB_SW_INT); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 0); /* get scb status */ + int_type = (WL_READ_2(sc, PIOP0) & SCB_SW_INT); if (int_type == 0) /* no interrupts left */ break; int_type1 = wlack(sc); /* acknowledge interrupt(s) */ /* make sure no bits disappeared (others may appear) */ if ((int_type & int_type1) != int_type) printf("wlack() int bits disappeared : %04x != int_type %04x\n", int_type1, int_type); int_type = int_type1; /* go with the new status */ /* * incoming packet */ if (int_type & SCB_SW_FR) { if_inc_counter(sc->ifp, IFCOUNTER_IPACKETS, 1); wlrcv(sc); } /* * receiver not ready */ if (int_type & SCB_SW_RNR) { if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d intr(): receiver overrun! begin_fd = %x\n", - sc->unit, sc->begin_fd); + if_printf(sc->ifp, "intr(): receiver overrun! begin_fd = %x\n", + sc->begin_fd); #endif wlrustrt(sc); } /* * CU not ready */ if (int_type & SCB_SW_CNA) { /* * At present, we don't care about CNA's. We * believe they are a side effect of XMT. */ } if (int_type & SCB_SW_CX) { /* * At present, we only request Interrupt for * XMT. */ - outw(PIOR1(base), OFFSET_CU); /* get command status */ - ac_status = inw(PIOP1(base)); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); /* get command status */ + ac_status = WL_READ_2(sc, PIOP1); if (xmt_watch) { /* report some anomalies */ if (sc->tbusy == 0) { - printf("wl%d: xmt intr but not busy, CU %04x\n", - sc->unit, ac_status); + if_printf(sc->ifp, "xmt intr but not busy, CU %04x\n", + ac_status); } if (ac_status == 0) { - printf("wl%d: xmt intr but ac_status == 0\n", sc->unit); + if_printf(sc->ifp, "xmt intr but ac_status == 0\n"); } if (ac_status & AC_SW_A) { - printf("wl%d: xmt aborted\n", sc->unit); + if_printf(sc->ifp, "xmt aborted\n"); } #ifdef notdef if (ac_status & TC_CARRIER) { - printf("wl%d: no carrier\n", sc->unit); + if_printf(sc->ifp, "no carrier\n"); } #endif /* notdef */ if (ac_status & TC_CLS) { - printf("wl%d: no CTS\n", sc->unit); + if_printf(sc->ifp, "no CTS\n"); } if (ac_status & TC_DMA) { - printf("wl%d: DMA underrun\n", sc->unit); + if_printf(sc->ifp, "DMA underrun\n"); } if (ac_status & TC_DEFER) { - printf("wl%d: xmt deferred\n", sc->unit); + if_printf(sc->ifp, "xmt deferred\n"); } if (ac_status & TC_SQE) { - printf("wl%d: heart beat\n", sc->unit); + if_printf(sc->ifp, "heart beat\n"); } if (ac_status & TC_COLLISION) { - printf("wl%d: too many collisions\n", sc->unit); + if_printf(sc->ifp, "too many collisions\n"); } } /* if the transmit actually failed, or returned some status */ if ((!(ac_status & AC_SW_OK)) || (ac_status & 0xfff)) { if (ac_status & (TC_COLLISION | TC_CLS | TC_DMA)) { if_inc_counter(sc->ifp, IFCOUNTER_OERRORS, 1); } /* count collisions */ if_inc_counter(sc->ifp, IFCOUNTER_COLLISIONS, (ac_status & 0xf)); /* if TC_COLLISION set and collision count zero, 16 collisions */ if ((ac_status & 0x20) == 0x20) { if_inc_counter(sc->ifp, IFCOUNTER_COLLISIONS, 0x10); } } sc->tbusy = 0; - untimeout(wlwatchdog, sc, sc->watchdog_ch); + callout_stop(&sc->watchdog_timer); sc->ifp->if_drv_flags &= ~IFF_DRV_OACTIVE; - wlstart(sc->ifp); + wlstart_locked(sc->ifp); } } WL_UNLOCK(sc); return; } /* * wlrcv: * * This routine is called by the interrupt handler to initiate a * packet transfer from the board to the "if" layer above this * driver. This routine checks if a buffer has been successfully * received by the WaveLAN. If so, the routine wlread is called * to do the actual transfer of the board data (including the * ethernet header) into a packet (consisting of an mbuf chain). * * input : number of the board to check * output : if a packet is available, it is "sent up" * */ static void wlrcv(struct wl_softc *sc) { - short base = sc->base; u_short fd_p, status, offset, link_offset; #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlrcv()\n", sc->unit); + if_printf(sc->ifp, "entered wlrcv()\n"); #endif for (fd_p = sc->begin_fd; fd_p != I82586NULL; fd_p = sc->begin_fd) { - outw(PIOR0(base), fd_p + 0); /* address of status */ - status = inw(PIOP0(base)); - outw(PIOR1(base), fd_p + 4); /* address of link_offset */ - link_offset = inw(PIOP1(base)); - offset = inw(PIOP1(base)); /* rbd_offset */ + WL_WRITE_2(sc, PIOR0, fd_p + 0); /* address of status */ + status = WL_READ_2(sc, PIOP0); + WL_WRITE_2(sc, PIOR1, fd_p + 4); /* address of link_offset */ + link_offset = WL_READ_2(sc, PIOP1); + offset = WL_READ_2(sc, PIOP1); /* rbd_offset */ if (status == 0xffff || offset == 0xffff /*I82586NULL*/) { if (wlhwrst(sc) != TRUE) - printf("wl%d rcv(): hwrst ffff trouble.\n", sc->unit); + if_printf(sc->ifp, "rcv(): hwrst ffff trouble.\n"); return; } else if (status & AC_SW_C) { if (status == (RFD_DONE|RFD_RSC)) { /* lost one */ #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d RCV: RSC %x\n", sc->unit, status); + if_printf(sc->ifp, "RCV: RSC %x\n", status); #endif if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); } else if (!(status & RFD_OK)) { - printf("wl%d RCV: !OK %x\n", sc->unit, status); + if_printf(sc->ifp, "RCV: !OK %x\n", status); if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); } else if (status & 0xfff) { /* can't happen */ - printf("wl%d RCV: ERRs %x\n", sc->unit, status); + if_printf(sc->ifp, "RCV: ERRs %x\n", status); if_inc_counter(sc->ifp, IFCOUNTER_IERRORS, 1); } else if (!wlread(sc, fd_p)) return; if (!wlrequeue(sc, fd_p)) { /* abort on chain error */ if (wlhwrst(sc) != TRUE) - printf("wl%d rcv(): hwrst trouble.\n", sc->unit); + if_printf(sc->ifp, "rcv(): hwrst trouble.\n"); return; } sc->begin_fd = link_offset; } else { break; } } return; } /* * wlrequeue: * * This routine puts rbd's used in the last receive back onto the * free list for the next receive. * */ static int wlrequeue(struct wl_softc *sc, u_short fd_p) { - short base = sc->base; fd_t fd; u_short l_rbdp, f_rbdp, rbd_offset; - outw(PIOR0(base), fd_p + 6); - rbd_offset = inw(PIOP0(base)); + WL_WRITE_2(sc, PIOR0, fd_p + 6); + rbd_offset = WL_READ_2(sc, PIOP0); if ((f_rbdp = rbd_offset) != I82586NULL) { l_rbdp = f_rbdp; for (;;) { - outw(PIOR0(base), l_rbdp + 0); /* address of status */ - if (inw(PIOP0(base)) & RBD_SW_EOF) + WL_WRITE_2(sc, PIOR0, l_rbdp + 0); /* address of status */ + if (WL_READ_2(sc, PIOP0) & RBD_SW_EOF) break; - outw(PIOP0(base), 0); - outw(PIOR0(base), l_rbdp + 2); /* next_rbd_offset */ - if ((l_rbdp = inw(PIOP0(base))) == I82586NULL) + WL_WRITE_2(sc, PIOP0, 0); + WL_WRITE_2(sc, PIOR0, l_rbdp + 2); /* next_rbd_offset */ + if ((l_rbdp = WL_READ_2(sc, PIOP0)) == I82586NULL) break; } - outw(PIOP0(base), 0); - outw(PIOR0(base), l_rbdp + 2); /* next_rbd_offset */ - outw(PIOP0(base), I82586NULL); - outw(PIOR0(base), l_rbdp + 8); /* address of size */ - outw(PIOP0(base), inw(PIOP0(base)) | AC_CW_EL); - outw(PIOR0(base), sc->end_rbd + 2); - outw(PIOP0(base), f_rbdp); /* end_rbd->next_rbd_offset */ - outw(PIOR0(base), sc->end_rbd + 8); /* size */ - outw(PIOP0(base), inw(PIOP0(base)) & ~AC_CW_EL); + WL_WRITE_2(sc, PIOP0, 0); + WL_WRITE_2(sc, PIOR0, l_rbdp + 2); /* next_rbd_offset */ + WL_WRITE_2(sc, PIOP0, I82586NULL); + WL_WRITE_2(sc, PIOR0, l_rbdp + 8); /* address of size */ + WL_WRITE_2(sc, PIOP0, WL_READ_2(sc, PIOP0) | AC_CW_EL); + WL_WRITE_2(sc, PIOR0, sc->end_rbd + 2); + WL_WRITE_2(sc, PIOP0, f_rbdp); /* end_rbd->next_rbd_offset */ + WL_WRITE_2(sc, PIOR0, sc->end_rbd + 8); /* size */ + WL_WRITE_2(sc, PIOP0, WL_READ_2(sc, PIOP0) & ~AC_CW_EL); sc->end_rbd = l_rbdp; } fd.status = 0; fd.command = AC_CW_EL; fd.link_offset = I82586NULL; fd.rbd_offset = I82586NULL; - outw(PIOR1(base), fd_p); - outsw(PIOP1(base), &fd, 8/2); + WL_WRITE_2(sc, PIOR1, fd_p); + WL_WRITE_MULTI_2(sc, PIOP1, &fd, 8/2); - outw(PIOR1(base), sc->end_fd + 2); /* addr of command */ - outw(PIOP1(base), 0); /* command = 0 */ - outw(PIOP1(base), fd_p); /* end_fd->link_offset = fd_p */ + WL_WRITE_2(sc, PIOR1, sc->end_fd + 2); /* addr of command */ + WL_WRITE_2(sc, PIOP1, 0); /* command = 0 */ + WL_WRITE_2(sc, PIOP1, fd_p); /* end_fd->link_offset = fd_p */ sc->end_fd = fd_p; return 1; } #ifdef WLDEBUG static int xmt_debug = 0; #endif /* WLDEBUG */ /* * wlxmt: * * This routine fills in the appropriate registers and memory * locations on the WaveLAN board and starts the board off on * the transmit. * * input : pointers to board of interest's softc and the mbuf * output : board memory and registers are set for xfer and attention * */ static void wlxmt(struct wl_softc *sc, struct mbuf *m) { u_short xmtdata_p = OFFSET_TBUF; u_short xmtshort_p; struct mbuf *tm_p = m; struct ether_header *eh_p = mtod(m, struct ether_header *); u_char *mb_p = mtod(m, u_char *) + sizeof(struct ether_header); u_short count = m->m_len - sizeof(struct ether_header); ac_t cb; u_short tbd_p = OFFSET_TBD; u_short len, clen = 0; - short base = sc->base; int spin; #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("%s: entered wlxmt()\n", sc->ifp->if_xname); + if_printf(sc->ifp, "entered wlxmt()\n"); #endif cb.ac_status = 0; cb.ac_command = (AC_CW_EL|AC_TRANSMIT|AC_CW_I); cb.ac_link_offset = I82586NULL; - outw(PIOR1(base), OFFSET_CU); - outsw(PIOP1(base), &cb, 6/2); - outw(PIOP1(base), OFFSET_TBD); /* cb.cmd.transmit.tbd_offset */ - outsw(PIOP1(base), eh_p->ether_dhost, WAVELAN_ADDR_SIZE/2); - outw(PIOP1(base), eh_p->ether_type); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_MULTI_2(sc, PIOP1, &cb, 6/2); + WL_WRITE_2(sc, PIOP1, OFFSET_TBD); /* cb.cmd.transmit.tbd_offset */ + WL_WRITE_MULTI_2(sc, PIOP1, eh_p->ether_dhost, WAVELAN_ADDR_SIZE/2); + WL_WRITE_2(sc, PIOP1, eh_p->ether_type); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) { if (xmt_debug) { printf("XMT mbuf: L%d @%p ", count, (void *)mb_p); printf("ether type %x\n", eh_p->ether_type); } } #endif /* WLDEBUG */ - outw(PIOR0(base), OFFSET_TBD); - outw(PIOP0(base), 0); /* act_count */ - outw(PIOR1(base), OFFSET_TBD + 4); - outw(PIOP1(base), xmtdata_p); /* buffer_addr */ - outw(PIOP1(base), 0); /* buffer_base */ + WL_WRITE_2(sc, PIOR0, OFFSET_TBD); + WL_WRITE_2(sc, PIOP0, 0); /* act_count */ + WL_WRITE_2(sc, PIOR1, OFFSET_TBD + 4); + WL_WRITE_2(sc, PIOP1, xmtdata_p); /* buffer_addr */ + WL_WRITE_2(sc, PIOP1, 0); /* buffer_base */ for (;;) { if (count) { if (clen + count > WAVELAN_MTU) break; if (count & 1) len = count + 1; else len = count; - outw(PIOR1(base), xmtdata_p); - outsw(PIOP1(base), mb_p, len/2); + WL_WRITE_2(sc, PIOR1, xmtdata_p); + WL_WRITE_MULTI_2(sc, PIOP1, mb_p, len/2); clen += count; - outw(PIOR0(base), tbd_p); /* address of act_count */ - outw(PIOP0(base), inw(PIOP0(base)) + count); + WL_WRITE_2(sc, PIOR0, tbd_p); /* address of act_count */ + WL_WRITE_2(sc, PIOP0, WL_READ_2(sc, PIOP0) + count); xmtdata_p += len; if ((tm_p = tm_p->m_next) == (struct mbuf *)0) break; if (count & 1) { /* go to the next descriptor */ - outw(PIOR0(base), tbd_p + 2); + WL_WRITE_2(sc, PIOR0, tbd_p + 2); tbd_p += sizeof (tbd_t); - outw(PIOP0(base), tbd_p); /* next_tbd_offset */ - outw(PIOR0(base), tbd_p); - outw(PIOP0(base), 0); /* act_count */ - outw(PIOR1(base), tbd_p + 4); - outw(PIOP1(base), xmtdata_p); /* buffer_addr */ - outw(PIOP1(base), 0); /* buffer_base */ + WL_WRITE_2(sc, PIOP0, tbd_p); /* next_tbd_offset */ + WL_WRITE_2(sc, PIOR0, tbd_p); + WL_WRITE_2(sc, PIOP0, 0); /* act_count */ + WL_WRITE_2(sc, PIOR1, tbd_p + 4); + WL_WRITE_2(sc, PIOP1, xmtdata_p); /* buffer_addr */ + WL_WRITE_2(sc, PIOP1, 0); /* buffer_base */ /* at the end -> coallesce remaining mbufs */ if (tbd_p == OFFSET_TBD + (N_TBD-1) * sizeof (tbd_t)) { wlsftwsleaze(&count, &mb_p, &tm_p, sc); continue; } /* next mbuf short -> coallesce as needed */ if ( (tm_p->m_next == (struct mbuf *) 0) || #define HDW_THRESHOLD 55 tm_p->m_len > HDW_THRESHOLD) /* ok */; else { wlhdwsleaze(&count, &mb_p, &tm_p, sc); continue; } } } else if ((tm_p = tm_p->m_next) == (struct mbuf *)0) break; count = tm_p->m_len; mb_p = mtod(tm_p, u_char *); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) if (xmt_debug) printf("mbuf+ L%d @%p ", count, (void *)mb_p); #endif /* WLDEBUG */ } #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) if (xmt_debug) printf("CLEN = %d\n", clen); #endif /* WLDEBUG */ - outw(PIOR0(base), tbd_p); + WL_WRITE_2(sc, PIOR0, tbd_p); if (clen < ETHERMIN) { - outw(PIOP0(base), inw(PIOP0(base)) + ETHERMIN - clen); - outw(PIOR1(base), xmtdata_p); + WL_WRITE_2(sc, PIOP0, WL_READ_2(sc, PIOP0) + ETHERMIN - clen); + WL_WRITE_2(sc, PIOR1, xmtdata_p); for (xmtshort_p = xmtdata_p; clen < ETHERMIN; clen += 2) - outw(PIOP1(base), 0); + WL_WRITE_2(sc, PIOP1, 0); } - outw(PIOP0(base), inw(PIOP0(base)) | TBD_SW_EOF); - outw(PIOR0(base), tbd_p + 2); - outw(PIOP0(base), I82586NULL); + WL_WRITE_2(sc, PIOP0, WL_READ_2(sc, PIOP0) | TBD_SW_EOF); + WL_WRITE_2(sc, PIOR0, tbd_p + 2); + WL_WRITE_2(sc, PIOP0, I82586NULL); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) { if (xmt_debug) { wltbd(sc); printf("\n"); } } #endif /* WLDEBUG */ - outw(PIOR0(base), OFFSET_SCB + 2); /* address of scb_command */ + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 2); /* address of scb_command */ /* * wait for 586 to clear previous command, complain if it takes * too long */ for (spin = 1;;spin = (spin + 1) % 10000) { - if (inw(PIOP0(base)) == 0) { /* it's done, we can go */ + if (WL_READ_2(sc, PIOP0) == 0) { /* it's done, we can go */ break; } if ((spin == 0) && xmt_watch) { /* not waking up, and we care */ - printf("%s: slow accepting xmit\n", sc->ifp->if_xname); + if_printf(sc->ifp, "slow accepting xmit\n"); } } - outw(PIOP0(base), SCB_CU_STRT); /* new command */ + WL_WRITE_2(sc, PIOP0, SCB_CU_STRT); /* new command */ SET_CHAN_ATTN(sc); m_freem(m); /* XXX * Pause to avoid transmit overrun problems. * The required delay tends to vary with platform type, and may be * related to interrupt loss. */ if (wl_xmit_delay) { DELAY(wl_xmit_delay); } return; } /* * wlbldru: * * This function builds the linear linked lists of fd's and * rbd's. Based on page 4-32 of 1986 Intel microcom handbook. * */ static u_short wlbldru(struct wl_softc *sc) { - short base = sc->base; fd_t fd; rbd_t rbd; u_short fd_p = OFFSET_RU; u_short rbd_p = OFFSET_RBD; int i; sc->begin_fd = fd_p; for (i = 0; i < N_FD; i++) { fd.status = 0; fd.command = 0; fd.link_offset = fd_p + sizeof(fd_t); fd.rbd_offset = I82586NULL; - outw(PIOR1(base), fd_p); - outsw(PIOP1(base), &fd, 8/2); + WL_WRITE_2(sc, PIOR1, fd_p); + WL_WRITE_MULTI_2(sc, PIOP1, &fd, 8/2); fd_p = fd.link_offset; } fd_p -= sizeof(fd_t); sc->end_fd = fd_p; - outw(PIOR1(base), fd_p + 2); - outw(PIOP1(base), AC_CW_EL); /* command */ - outw(PIOP1(base), I82586NULL); /* link_offset */ + WL_WRITE_2(sc, PIOR1, fd_p + 2); + WL_WRITE_2(sc, PIOP1, AC_CW_EL); /* command */ + WL_WRITE_2(sc, PIOP1, I82586NULL); /* link_offset */ fd_p = OFFSET_RU; - outw(PIOR0(base), fd_p + 6); /* address of rbd_offset */ - outw(PIOP0(base), rbd_p); - outw(PIOR1(base), rbd_p); + WL_WRITE_2(sc, PIOR0, fd_p + 6); /* address of rbd_offset */ + WL_WRITE_2(sc, PIOP0, rbd_p); + WL_WRITE_2(sc, PIOR1, rbd_p); for (i = 0; i < N_RBD; i++) { rbd.status = 0; rbd.buffer_addr = rbd_p + sizeof(rbd_t) + 2; rbd.buffer_base = 0; rbd.size = RCVBUFSIZE; if (i != N_RBD-1) { rbd_p += sizeof(ru_t); rbd.next_rbd_offset = rbd_p; } else { rbd.next_rbd_offset = I82586NULL; rbd.size |= AC_CW_EL; sc->end_rbd = rbd_p; } - outsw(PIOP1(base), &rbd, sizeof(rbd_t)/2); - outw(PIOR1(base), rbd_p); + WL_WRITE_MULTI_2(sc, PIOP1, &rbd, sizeof(rbd_t)/2); + WL_WRITE_2(sc, PIOR1, rbd_p); } return sc->begin_fd; } /* * wlrustrt: * * This routine starts the receive unit running. First checks if the * board is actually ready, then the board is instructed to receive * packets again. * */ static void wlrustrt(struct wl_softc *sc) { - short base = sc->base; u_short rfa; #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlrustrt()\n", sc->unit); + if_printf(sc->ifp, "entered wlrustrt()\n"); #endif - outw(PIOR0(base), OFFSET_SCB); - if (inw(PIOP0(base)) & SCB_RUS_READY){ + WL_WRITE_2(sc, PIOR0, OFFSET_SCB); + if (WL_READ_2(sc, PIOP0) & SCB_RUS_READY){ printf("wlrustrt: RUS_READY\n"); return; } - outw(PIOR0(base), OFFSET_SCB + 2); - outw(PIOP0(base), SCB_RU_STRT); /* command */ + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 2); + WL_WRITE_2(sc, PIOP0, SCB_RU_STRT); /* command */ rfa = wlbldru(sc); - outw(PIOR0(base), OFFSET_SCB + 6); /* address of scb_rfa_offset */ - outw(PIOP0(base), rfa); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 6); /* address of scb_rfa_offset */ + WL_WRITE_2(sc, PIOP0, rfa); SET_CHAN_ATTN(sc); return; } /* * wldiag: * * This routine does a 586 op-code number 7, and obtains the * diagnose status for the WaveLAN. * */ static int wldiag(struct wl_softc *sc) { - short base = sc->base; short status; #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wldiag()\n", sc->unit); + if_printf(sc->ifp, "entered wldiag()\n"); #endif - outw(PIOR0(base), OFFSET_SCB); - status = inw(PIOP0(base)); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB); + status = WL_READ_2(sc, PIOP0); if (status & SCB_SW_INT) { /* state is 2000 which seems ok - printf("wl%d diag(): unexpected initial state %\n", - sc->unit, inw(PIOP0(base))); + if_printf(sc->ifp, "diag(): unexpected initial state %\n", + WL_READ_2(sc, PIOP0)); */ wlack(sc); } - outw(PIOR1(base), OFFSET_CU); - outw(PIOP1(base), 0); /* ac_status */ - outw(PIOP1(base), AC_DIAGNOSE|AC_CW_EL);/* ac_command */ + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_2(sc, PIOP1, 0); /* ac_status */ + WL_WRITE_2(sc, PIOP1, AC_DIAGNOSE|AC_CW_EL);/* ac_command */ if (wlcmd(sc, "diag()") == 0) return 0; - outw(PIOR0(base), OFFSET_CU); - if (inw(PIOP0(base)) & 0x0800) { - printf("wl%d: i82586 Self Test failed!\n", sc->unit); + WL_WRITE_2(sc, PIOR0, OFFSET_CU); + if (WL_READ_2(sc, PIOP0) & 0x0800) { + if_printf(sc->ifp, "i82586 Self Test failed!\n"); return 0; } return TRUE; } /* * wlconfig: * * This routine does a standard config of the WaveLAN board. * */ static int wlconfig(struct wl_softc *sc) { configure_t configure; - short base = sc->base; #if MULTICAST struct ifmultiaddr *ifma; u_char *addrp; int cnt = 0; #endif /* MULTICAST */ #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: entered wlconfig()\n", sc->unit); + if_printf(sc->ifp, "entered wlconfig()\n"); #endif - outw(PIOR0(base), OFFSET_SCB); - if (inw(PIOP0(base)) & SCB_SW_INT) { + WL_WRITE_2(sc, PIOR0, OFFSET_SCB); + if (WL_READ_2(sc, PIOP0) & SCB_SW_INT) { /* - printf("wl%d config(): unexpected initial state %x\n", - sc->unit, inw(PIOP0(base))); + if_printf(sc->ifp, "config(): unexpected initial state %x\n", + WL_READ_2(sc, PIOP0)); */ } wlack(sc); - outw(PIOR1(base), OFFSET_CU); - outw(PIOP1(base), 0); /* ac_status */ - outw(PIOP1(base), AC_CONFIGURE|AC_CW_EL); /* ac_command */ + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_2(sc, PIOP1, 0); /* ac_status */ + WL_WRITE_2(sc, PIOP1, AC_CONFIGURE|AC_CW_EL); /* ac_command */ /* jrb hack */ configure.fifolim_bytecnt = 0x080c; configure.addrlen_mode = 0x0600; configure.linprio_interframe = 0x2060; configure.slot_time = 0xf200; configure.hardware = 0x0008; /* tx even w/o CD */ configure.min_frame_len = 0x0040; #if 0 /* This is the configuration block suggested by Marc Meertens * in an e-mail message to John * Ioannidis on 10 Nov 92. */ configure.fifolim_bytecnt = 0x040c; configure.addrlen_mode = 0x0600; configure.linprio_interframe = 0x2060; configure.slot_time = 0xf000; configure.hardware = 0x0008; /* tx even w/o CD */ configure.min_frame_len = 0x0040; #else /* * below is the default board configuration from p2-28 from 586 book */ configure.fifolim_bytecnt = 0x080c; configure.addrlen_mode = 0x2600; configure.linprio_interframe = 0x7820; /* IFS=120, ACS=2 */ configure.slot_time = 0xf00c; /* slottime=12 */ configure.hardware = 0x0008; /* tx even w/o CD */ configure.min_frame_len = 0x0040; #endif if (sc->mode & (MOD_PROM | MOD_ENAL)) configure.hardware |= 1; - outw(PIOR1(base), OFFSET_CU + 6); - outsw(PIOP1(base), &configure, sizeof(configure_t)/2); + WL_WRITE_2(sc, PIOR1, OFFSET_CU + 6); + WL_WRITE_MULTI_2(sc, PIOP1, &configure, sizeof(configure_t)/2); if (wlcmd(sc, "config()-configure") == 0) return 0; #if MULTICAST - outw(PIOR1(base), OFFSET_CU); - outw(PIOP1(base), 0); /* ac_status */ - outw(PIOP1(base), AC_MCSETUP|AC_CW_EL); /* ac_command */ - outw(PIOR1(base), OFFSET_CU + 8); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_2(sc, PIOP1, 0); /* ac_status */ + WL_WRITE_2(sc, PIOP1, AC_MCSETUP|AC_CW_EL); /* ac_command */ + WL_WRITE_2(sc, PIOR1, OFFSET_CU + 8); if_maddr_rlock(sc->ifp); TAILQ_FOREACH(ifma, &sc->ifp->if_multiaddrs, ifma_link) { if (ifma->ifma_addr->sa_family != AF_LINK) continue; addrp = LLADDR((struct sockaddr_dl *)ifma->ifma_addr); - outw(PIOP1(base), addrp[0] + (addrp[1] << 8)); - outw(PIOP1(base), addrp[2] + (addrp[3] << 8)); - outw(PIOP1(base), addrp[4] + (addrp[5] << 8)); + WL_WRITE_2(sc, PIOP1, addrp[0] + (addrp[1] << 8)); + WL_WRITE_2(sc, PIOP1, addrp[2] + (addrp[3] << 8)); + WL_WRITE_2(sc, PIOP1, addrp[4] + (addrp[5] << 8)); ++cnt; } if_maddr_runlock(sc->ifp); - outw(PIOR1(base), OFFSET_CU + 6); /* mc-cnt */ - outw(PIOP1(base), cnt * WAVELAN_ADDR_SIZE); + WL_WRITE_2(sc, PIOR1, OFFSET_CU + 6); /* mc-cnt */ + WL_WRITE_2(sc, PIOP1, cnt * WAVELAN_ADDR_SIZE); if (wlcmd(sc, "config()-mcaddress") == 0) return 0; #endif /* MULTICAST */ - outw(PIOR1(base), OFFSET_CU); - outw(PIOP1(base), 0); /* ac_status */ - outw(PIOP1(base), AC_IASETUP|AC_CW_EL); /* ac_command */ - outw(PIOR1(base), OFFSET_CU + 6); - outsw(PIOP1(base), IF_LLADDR(sc->ifp), WAVELAN_ADDR_SIZE/2); + WL_WRITE_2(sc, PIOR1, OFFSET_CU); + WL_WRITE_2(sc, PIOP1, 0); /* ac_status */ + WL_WRITE_2(sc, PIOP1, AC_IASETUP|AC_CW_EL); /* ac_command */ + WL_WRITE_2(sc, PIOR1, OFFSET_CU + 6); + WL_WRITE_MULTI_2(sc, PIOP1, IF_LLADDR(sc->ifp), WAVELAN_ADDR_SIZE/2); if (wlcmd(sc, "config()-address") == 0) return(0); wlinitmmc(sc); return(1); } /* * wlcmd: * * Set channel attention bit and busy wait until command has * completed. Then acknowledge the command completion. */ static int wlcmd(struct wl_softc *sc, char *str) { - short base = sc->base; int i; - outw(PIOR0(base), OFFSET_SCB + 2); /* address of scb_command */ - outw(PIOP0(base), SCB_CU_STRT); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 2); /* address of scb_command */ + WL_WRITE_2(sc, PIOP0, SCB_CU_STRT); SET_CHAN_ATTN(sc); - outw(PIOR0(base), OFFSET_CU); + WL_WRITE_2(sc, PIOR0, OFFSET_CU); for (i = 0; i < 0xffff; i++) - if (inw(PIOP0(base)) & AC_SW_C) + if (WL_READ_2(sc, PIOP0) & AC_SW_C) break; - if (i == 0xffff || !(inw(PIOP0(base)) & AC_SW_OK)) { - printf("wl%d: %s failed; status = %d, inw = %x, outw = %x\n", - sc->unit, str, inw(PIOP0(base)) & AC_SW_OK, inw(PIOP0(base)), inw(PIOR0(base))); - outw(PIOR0(base), OFFSET_SCB); - printf("scb_status %x\n", inw(PIOP0(base))); - outw(PIOR0(base), OFFSET_SCB+2); - printf("scb_command %x\n", inw(PIOP0(base))); - outw(PIOR0(base), OFFSET_SCB+4); - printf("scb_cbl %x\n", inw(PIOP0(base))); - outw(PIOR0(base), OFFSET_CU+2); - printf("cu_cmd %x\n", inw(PIOP0(base))); + if (i == 0xffff || !(WL_READ_2(sc, PIOP0) & AC_SW_OK)) { + if_printf(sc->ifp, "%s failed; status = %d, inw = %x, outw = %x\n", + str, WL_READ_2(sc, PIOP0) & AC_SW_OK, WL_READ_2(sc, PIOP0), + WL_READ_2(sc, PIOR0)); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB); + printf("scb_status %x\n", WL_READ_2(sc, PIOP0)); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB+2); + printf("scb_command %x\n", WL_READ_2(sc, PIOP0)); + WL_WRITE_2(sc, PIOR0, OFFSET_SCB+4); + printf("scb_cbl %x\n", WL_READ_2(sc, PIOP0)); + WL_WRITE_2(sc, PIOR0, OFFSET_CU+2); + printf("cu_cmd %x\n", WL_READ_2(sc, PIOP0)); return(0); } - outw(PIOR0(base), OFFSET_SCB); - if ((inw(PIOP0(base)) & SCB_SW_INT) && (inw(PIOP0(base)) != SCB_SW_CNA)) { + WL_WRITE_2(sc, PIOR0, OFFSET_SCB); + if ((WL_READ_2(sc, PIOP0) & SCB_SW_INT) && + (WL_READ_2(sc, PIOP0) != SCB_SW_CNA)) { /* - printf("wl%d %s: unexpected final state %x\n", - sc->unit, str, inw(PIOP0(base))); + if_printf(sc->ifp, "%s: unexpected final state %x\n", + str, WL_READ_2(sc, PIOP0)); */ } wlack(sc); return(TRUE); } /* * wlack: if the 82596 wants attention because it has finished * sending or receiving a packet, acknowledge its desire and * return bits indicating the kind of attention. wlack() returns * these bits so that the caller can service exactly the * conditions that wlack() acknowledged. */ static int wlack(struct wl_softc *sc) { int i; u_short cmd; - short base = sc->base; - outw(PIOR1(base), OFFSET_SCB); - if (!(cmd = (inw(PIOP1(base)) & SCB_SW_INT))) + WL_WRITE_2(sc, PIOR1, OFFSET_SCB); + if (!(cmd = (WL_READ_2(sc, PIOP1) & SCB_SW_INT))) return(0); #ifdef WLDEBUG if (sc->ifp->if_flags & IFF_DEBUG) - printf("wl%d: doing a wlack()\n", sc->unit); + if_printf(sc->ifp, "doing a wlack()\n"); #endif - outw(PIOP1(base), cmd); + WL_WRITE_2(sc, PIOP1, cmd); SET_CHAN_ATTN(sc); - outw(PIOR0(base), OFFSET_SCB + 2); /* address of scb_command */ - for (i = 1000000; inw(PIOP0(base)) && (i-- > 0); ) + WL_WRITE_2(sc, PIOR0, OFFSET_SCB + 2); /* address of scb_command */ + for (i = 1000000; WL_READ_2(sc, PIOP0) && (i-- > 0); ) continue; if (i < 1) - printf("wl%d wlack(): board not accepting command.\n", sc->unit); + if_printf(sc->ifp, "wlack(): board not accepting command.\n"); return(cmd); } #ifdef WLDEBUG static void wltbd(struct wl_softc *sc) { - short base = sc->base; u_short tbd_p = OFFSET_TBD; tbd_t tbd; int i = 0; int sum = 0; for (;;) { - outw(PIOR1(base), tbd_p); - insw(PIOP1(base), &tbd, sizeof(tbd_t)/2); + WL_WRITE_2(sc, PIOR1, tbd_p); + WL_READ_MULTI_2(sc, PIOP1, &tbd, sizeof(tbd_t)/2); sum += (tbd.act_count & ~TBD_SW_EOF); printf("%d: addr %x, count %d (%d), next %x, base %x\n", i++, tbd.buffer_addr, (tbd.act_count & ~TBD_SW_EOF), sum, tbd.next_tbd_offset, tbd.buffer_base); if (tbd.act_count & TBD_SW_EOF) break; tbd_p = tbd.next_tbd_offset; } } #endif static void wlhdwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc) { struct mbuf *tm_p = *tm_pp; u_char *mb_p = *mb_pp; u_short count = 0; u_char *cp; int len; /* * can we get a run that will be coallesced or * that terminates before breaking */ do { count += tm_p->m_len; if (tm_p->m_len & 1) break; } while ((tm_p = tm_p->m_next) != (struct mbuf *)0); if ( (tm_p == (struct mbuf *)0) || count > HDW_THRESHOLD) { *countp = (*tm_pp)->m_len; *mb_pp = mtod((*tm_pp), u_char *); return; } /* we need to copy */ tm_p = *tm_pp; mb_p = *mb_pp; count = 0; cp = (u_char *) t_packet; for (;;) { bcopy(mtod(tm_p, u_char *), cp, len = tm_p->m_len); count += len; if (count > HDW_THRESHOLD) break; cp += len; if (tm_p->m_next == (struct mbuf *)0) break; tm_p = tm_p->m_next; } *countp = count; *mb_pp = (u_char *) t_packet; *tm_pp = tm_p; return; } static void wlsftwsleaze(u_short *countp, u_char **mb_pp, struct mbuf **tm_pp, struct wl_softc *sc) { struct mbuf *tm_p = *tm_pp; u_short count = 0; u_char *cp = (u_char *) t_packet; int len; /* we need to copy */ for (;;) { bcopy(mtod(tm_p, u_char *), cp, len = tm_p->m_len); count += len; cp += len; if (tm_p->m_next == (struct mbuf *)0) break; tm_p = tm_p->m_next; } *countp = count; *mb_pp = (u_char *) t_packet; *tm_pp = tm_p; return; } static void wlmmcstat(struct wl_softc *sc) { - short base = sc->base; u_short tmp; - printf("wl%d: DCE_STATUS: 0x%x, ", sc->unit, - wlmmcread(base,MMC_DCE_STATUS) & 0x0f); - tmp = wlmmcread(base,MMC_CORRECT_NWID_H) << 8; - tmp |= wlmmcread(base,MMC_CORRECT_NWID_L); + device_printf(sc->dev, "DCE_STATUS: 0x%x, ", + wlmmcread(sc, MMC_DCE_STATUS) & 0x0f); + tmp = wlmmcread(sc, MMC_CORRECT_NWID_H) << 8; + tmp |= wlmmcread(sc, MMC_CORRECT_NWID_L); printf("Correct NWID's: %d, ", tmp); - tmp = wlmmcread(base,MMC_WRONG_NWID_H) << 8; - tmp |= wlmmcread(base,MMC_WRONG_NWID_L); + tmp = wlmmcread(sc, MMC_WRONG_NWID_H) << 8; + tmp |= wlmmcread(sc, MMC_WRONG_NWID_L); printf("Wrong NWID's: %d\n", tmp); - printf("THR_PRE_SET: 0x%x, ", wlmmcread(base,MMC_THR_PRE_SET)); + printf("THR_PRE_SET: 0x%x, ", wlmmcread(sc, MMC_THR_PRE_SET)); printf("SIGNAL_LVL: %d, SILENCE_LVL: %d\n", - wlmmcread(base,MMC_SIGNAL_LVL), - wlmmcread(base,MMC_SILENCE_LVL)); + wlmmcread(sc, MMC_SIGNAL_LVL), + wlmmcread(sc, MMC_SILENCE_LVL)); printf("SIGN_QUAL: 0x%x, NETW_ID: %x:%x, DES: %d\n", - wlmmcread(base,MMC_SIGN_QUAL), - wlmmcread(base,MMC_NETW_ID_H), - wlmmcread(base,MMC_NETW_ID_L), - wlmmcread(base,MMC_DES_AVAIL)); + wlmmcread(sc, MMC_SIGN_QUAL), + wlmmcread(sc, MMC_NETW_ID_H), + wlmmcread(sc, MMC_NETW_ID_L), + wlmmcread(sc, MMC_DES_AVAIL)); } static u_short -wlmmcread(u_int base, u_short reg) +wlmmcread(struct wl_softc *sc, u_short reg) { - while (inw(HASR(base)) & HASR_MMC_BUSY) + while (WL_READ_2(sc, HASR) & HASR_MMC_BUSY) continue; - outw(MMCR(base),reg << 1); - while (inw(HASR(base)) & HASR_MMC_BUSY) + WL_WRITE_2(sc, MMCR,reg << 1); + while (WL_READ_2(sc, HASR) & HASR_MMC_BUSY) continue; - return (u_short)inw(MMCR(base)) >> 8; + return (u_short)WL_READ_2(sc, MMCR) >> 8; } static void getsnr(struct wl_softc *sc) { MMC_WRITE(MMC_FREEZE,1); /* * SNR retrieval procedure : * - * read signal level : wlmmcread(base, MMC_SIGNAL_LVL); - * read silence level : wlmmcread(base, MMC_SILENCE_LVL); + * read signal level : wlmmcread(sc, MMC_SIGNAL_LVL); + * read silence level : wlmmcread(sc, MMC_SILENCE_LVL); */ MMC_WRITE(MMC_FREEZE,0); /* * SNR is signal:silence ratio. */ } /* ** wlgetpsa ** -** Reads the psa for the wavelan at (base) into (buf) +** Reads the psa for the wavelan at (sc) into (buf) */ static void -wlgetpsa(int base, u_char *buf) +wlgetpsa(struct wl_softc *sc, u_char *buf) { int i; - PCMD(base, HACR_DEFAULT & ~HACR_16BITS); - PCMD(base, HACR_DEFAULT & ~HACR_16BITS); + PCMD(sc, HACR_DEFAULT & ~HACR_16BITS); + PCMD(sc, HACR_DEFAULT & ~HACR_16BITS); for (i = 0; i < 0x40; i++) { - outw(PIOR2(base), i); - buf[i] = inb(PIOP2(base)); + WL_WRITE_2(sc, PIOR2, i); + buf[i] = WL_READ_1(sc, PIOP2); } - PCMD(base, HACR_DEFAULT); - PCMD(base, HACR_DEFAULT); + PCMD(sc, HACR_DEFAULT); + PCMD(sc, HACR_DEFAULT); } /* ** wlsetpsa ** ** Writes the psa for wavelan (unit) from the softc back to the ** board. Updates the CRC and sets the CRC OK flag. ** ** Do not call this when the board is operating, as it doesn't ** preserve the hacr. */ static void wlsetpsa(struct wl_softc *sc) { - short base = sc->base; - int i, oldpri; + int i; u_short crc; crc = wlpsacrc(sc->psa); /* calculate CRC of PSA */ sc->psa[WLPSA_CRCLOW] = crc & 0xff; sc->psa[WLPSA_CRCHIGH] = (crc >> 8) & 0xff; sc->psa[WLPSA_CRCOK] = 0x55; /* default to 'bad' until programming complete */ - oldpri = splimp(); /* ick, long pause */ + PCMD(sc, HACR_DEFAULT & ~HACR_16BITS); + PCMD(sc, HACR_DEFAULT & ~HACR_16BITS); - PCMD(base, HACR_DEFAULT & ~HACR_16BITS); - PCMD(base, HACR_DEFAULT & ~HACR_16BITS); - for (i = 0; i < 0x40; i++) { DELAY(DELAYCONST); - outw(PIOR2(base),i); /* write param memory */ + WL_WRITE_2(sc, PIOR2, i); /* write param memory */ DELAY(DELAYCONST); - outb(PIOP2(base), sc->psa[i]); + WL_WRITE_1(sc, PIOP2, sc->psa[i]); } DELAY(DELAYCONST); - outw(PIOR2(base),WLPSA_CRCOK); /* update CRC flag*/ + WL_WRITE_2(sc, PIOR2, WLPSA_CRCOK); /* update CRC flag*/ DELAY(DELAYCONST); sc->psa[WLPSA_CRCOK] = 0xaa; /* OK now */ - outb(PIOP2(base), 0xaa); /* all OK */ + WL_WRITE_1(sc, PIOP2, 0xaa); /* all OK */ DELAY(DELAYCONST); - PCMD(base, HACR_DEFAULT); - PCMD(base, HACR_DEFAULT); - - splx(oldpri); + PCMD(sc, HACR_DEFAULT); + PCMD(sc, HACR_DEFAULT); } /* ** CRC routine provided by Christopher Giordano , ** from original code by Tomi Mikkonen (tomitm@remedy.fi) */ static u_int crc16_table[16] = { 0x0000, 0xCC01, 0xD801, 0x1400, 0xF001, 0x3C00, 0x2800, 0xE401, 0xA001, 0x6C00, 0x7800, 0xB401, 0x5000, 0x9C01, 0x8801, 0x4400 }; static u_short wlpsacrc(u_char *buf) { u_short crc = 0; int i, r1; for (i = 0; i < 0x3d; i++, buf++) { /* lower 4 bits */ r1 = crc16_table[crc & 0xF]; crc = (crc >> 4) & 0x0FFF; crc = crc ^ r1 ^ crc16_table[*buf & 0xF]; /* upper 4 bits */ r1 = crc16_table[crc & 0xF]; crc = (crc >> 4) & 0x0FFF; crc = crc ^ r1 ^ crc16_table[(*buf >> 4) & 0xF]; } return(crc); } #ifdef WLCACHE /* * wl_cache_store * * take input packet and cache various radio hw characteristics * indexed by MAC address. * * Some things to think about: * note that no space is malloced. * We might hash the mac address if the cache were bigger. * It is not clear that the cache is big enough. * It is also not clear how big it should be. * The cache is IP-specific. We don't care about that as * we want it to be IP-specific. * The last N recv. packets are saved. This will tend * to reward agents and mobile hosts that beacon. * That is probably fine for mobile ip. */ /* globals for wavelan signal strength cache */ /* this should go into softc structure above. */ /* set true if you want to limit cache items to broadcast/mcast * only packets (not unicast) */ static int wl_cache_mcastonly = 1; SYSCTL_INT(_machdep, OID_AUTO, wl_cache_mcastonly, CTLFLAG_RW, &wl_cache_mcastonly, 0, ""); /* set true if you want to limit cache items to IP packets only */ static int wl_cache_iponly = 1; SYSCTL_INT(_machdep, OID_AUTO, wl_cache_iponly, CTLFLAG_RW, &wl_cache_iponly, 0, ""); /* zero out the cache */ static void wl_cache_zero(struct wl_softc *sc) { bzero(&sc->w_sigcache[0], sizeof(struct w_sigcache) * MAXCACHEITEMS); sc->w_sigitems = 0; sc->w_nextcache = 0; sc->w_wrapindex = 0; } /* store hw signal info in cache. * index is MAC address, but an ip src gets stored too * There are two filters here controllable via sysctl: * throw out unicast (on by default, but can be turned off) * throw out non-ip (on by default, but can be turned off) */ static -void wl_cache_store (struct wl_softc *sc, int base, struct ether_header *eh, - struct mbuf *m) +void wl_cache_store (struct wl_softc *sc, struct ether_header *eh, + struct mbuf *m) { #ifdef INET struct ip *ip = NULL; /* Avoid GCC warning */ int i; int signal, silence; int w_insertcache; /* computed index for cache entry storage */ int ipflag = wl_cache_iponly; #endif /* filters: * 1. ip only * 2. configurable filter to throw out unicast packets, * keep multicast only. */ #ifdef INET /* reject if not IP packet */ if ( wl_cache_iponly && (ntohs(eh->ether_type) != 0x800)) { return; } /* check if broadcast or multicast packet. we toss * unicast packets */ if (wl_cache_mcastonly && ((eh->ether_dhost[0] & 1) == 0)) { return; } /* find the ip header. we want to store the ip_src * address. use the mtod macro(in mbuf.h) * to typecast m to struct ip * */ if (ipflag) { ip = mtod(m, struct ip *); } /* do a linear search for a matching MAC address * in the cache table * . MAC address is 6 bytes, * . var w_nextcache holds total number of entries already cached */ for (i = 0; i < sc->w_nextcache; i++) { if (! bcmp(eh->ether_shost, sc->w_sigcache[i].macsrc, 6 )) { /* Match!, * so we already have this entry, * update the data, and LRU age */ break; } } /* did we find a matching mac address? * if yes, then overwrite a previously existing cache entry */ if (i < sc->w_nextcache ) { w_insertcache = i; } /* else, have a new address entry,so * add this new entry, * if table full, then we need to replace entry */ else { /* check for space in cache table * note: w_nextcache also holds number of entries * added in the cache table */ if ( sc->w_nextcache < MAXCACHEITEMS ) { w_insertcache = sc->w_nextcache; sc->w_nextcache++; sc->w_sigitems = sc->w_nextcache; } /* no space found, so simply wrap with wrap index * and "zap" the next entry */ else { if (sc->w_wrapindex == MAXCACHEITEMS) { sc->w_wrapindex = 0; } w_insertcache = sc->w_wrapindex++; } } /* invariant: w_insertcache now points at some slot * in cache. */ if (w_insertcache < 0 || w_insertcache >= MAXCACHEITEMS) { log(LOG_ERR, "wl_cache_store, bad index: %d of [0..%d], gross cache error\n", w_insertcache, MAXCACHEITEMS); return; } /* store items in cache * .ipsrc * .macsrc * .signal (0..63) ,silence (0..63) ,quality (0..15) */ if (ipflag) { sc->w_sigcache[w_insertcache].ipsrc = ip->ip_src.s_addr; } bcopy( eh->ether_shost, sc->w_sigcache[w_insertcache].macsrc, 6); - signal = sc->w_sigcache[w_insertcache].signal = wlmmcread(base, MMC_SIGNAL_LVL) & 0x3f; - silence = sc->w_sigcache[w_insertcache].silence = wlmmcread(base, MMC_SILENCE_LVL) & 0x3f; - sc->w_sigcache[w_insertcache].quality = wlmmcread(base, MMC_SIGN_QUAL) & 0x0f; + signal = sc->w_sigcache[w_insertcache].signal = wlmmcread(sc, MMC_SIGNAL_LVL) & 0x3f; + silence = sc->w_sigcache[w_insertcache].silence = wlmmcread(sc, MMC_SILENCE_LVL) & 0x3f; + sc->w_sigcache[w_insertcache].quality = wlmmcread(sc, MMC_SIGN_QUAL) & 0x0f; if (signal > 0) sc->w_sigcache[w_insertcache].snr = signal - silence; else sc->w_sigcache[w_insertcache].snr = 0; #endif /* INET */ } #endif /* WLCACHE */ Index: projects/sendfile/sys/dev/wl/if_wl.h =================================================================== --- projects/sendfile/sys/dev/wl/if_wl.h (revision 274764) +++ projects/sendfile/sys/dev/wl/if_wl.h (revision 274765) @@ -1,121 +1,133 @@ /*- * 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 all copyright * notices, this list of conditions and the following disclaimer. * 2. The names of the authors may not be used to endorse or promote products * derived from this software without specific prior written permission * * THIS SOFTWARE IS PROVIDED BY THE AUTHORS ``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 AUTHORS 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. * * $FreeBSD$ */ /* Definitions for WaveLAN driver */ #ifndef _IF_WL_H #define _IF_WL_H #define STATUS_TRIES 15000 #define N_FD 100 #define N_RBD 100 #define N_TBD 72 #define RCVBUFSIZE 540 #define I82586NULL 0xffff #define DSF_RUNNING 1 #define MOD_ENAL 1 #define MOD_PROM 2 typedef struct { rbd_t r; char rbd_pad[2]; char rbuffer[RCVBUFSIZE]; } ru_t; /* Board 64k RAM layout. Offsets from 0x0000 */ #define OFFSET_RU 0x0000 /* 0x64 * fd_t = 0x898 */ #define OFFSET_RBD 0x0900 /* 0x64 * ru_t = 0xd7a0 */ #define OFFSET_CU 0xe0a0 /* 0x100 */ #define OFFSET_TBD 0xe1a0 /* 0x48 * tbd_t = 0x240 */ #define OFFSET_TBUF 0xe3e0 /* 0x1bfe */ #define OFFSET_SCB 0xffde /* 0x1 * scb_t = 0x10 */ #define OFFSET_ISCP 0xffee /* 0x1 * iscp_t = 0x8 */ #define OFFSET_SCP 0xfff6 /* 0x1 * scp_t = 0xa */ /* WaveLAN host interface definitions */ -#define HACR(base) (base) /* Host Adapter Command Register */ -#define HASR(base) (base) /* Host Adapter Status Register */ -#define MMCR(base) (base+0x2) /* Modem Management Ctrl Register */ -#define PIOR0(base) (base+0x4) /* Program I/O Address Register 0 */ -#define PIOP0(base) (base+0x6) /* Program I/O Port 0 */ -#define PIOR1(base) (base+0x8) /* Program I/O Address Register 1 */ -#define PIOP1(base) (base+0xa) /* Program I/O Port 1 */ -#define PIOR2(base) (base+0xc) /* Program I/O Address Register 2 */ -#define PIOP2(base) (base+0xe) /* Program I/O Port 2 */ +#define HACR 0x0 /* Host Adapter Command Register */ +#define HASR 0x0 /* Host Adapter Status Register */ +#define MMCR 0x2 /* Modem Management Ctrl Register */ +#define PIOR0 0x4 /* Program I/O Address Register 0 */ +#define PIOP0 0x6 /* Program I/O Port 0 */ +#define PIOR1 0x8 /* Program I/O Address Register 1 */ +#define PIOP1 0xa /* Program I/O Port 1 */ +#define PIOR2 0xc /* Program I/O Address Register 2 */ +#define PIOP2 0xe /* Program I/O Port 2 */ /* Program I/O Mode Register values */ #define STATIC_PIO 0 /* Mode 1: static mode */ #define AUTOINCR_PIO 1 /* Mode 2: auto increment mode */ #define AUTODECR_PIO 2 /* Mode 3: auto decrement mode */ #define PARAM_ACCESS_PIO 3 /* Mode 4: LAN parameter access mode */ #define PIO_MASK 3 /* register mask */ #define PIOM(cmd,piono) ((u_short)cmd << 10 << (piono * 2)) /* Host Adapter status register definitions */ #define HASR_INTR 0x0001 /* Interrupt request from 82586 */ #define HASR_MMC_INTR 0x0002 /* Interrupt request from MMC */ #define HASR_MMC_BUSY 0x0004 /* MMC busy indication */ #define HASR_PARA_BUSY 0x0008 /* LAN parameter storage area busy */ /* Host Adapter command register definitions */ #define HACR_RESET 0x0001 /* Reset board */ #define HACR_CA 0x0002 /* Set Channel Attention for 82586 */ #define HACR_16BITS 0x0004 /* 1==16 bits operation, 0==8 bits */ #define HACR_OUT1 0x0008 /* General purpose output pin */ #define HACR_OUT2 0x0010 /* General purpose output pin */ #define HACR_MASK_82586 0x0020 /* Mask 82586 interrupts, 1==unmask */ #define HACR_MASK_MMC 0x0040 /* Mask MMC interrupts, 1==unmask */ #define HACR_INTR_CLEN 0x0080 /* interrupt status clear enable */ #define HACR_DEFAULT (HACR_OUT1 | HACR_OUT2 | HACR_16BITS | PIOM(STATIC_PIO, 0) | PIOM(AUTOINCR_PIO, 1) | PIOM(PARAM_ACCESS_PIO, 2)) #define HACR_INTRON (HACR_MASK_82586 | HACR_MASK_MMC | HACR_INTR_CLEN) -#define CMD(sc) \ + +#define WL_READ_1(sc, reg) bus_read_1((sc)->res_ioport, (reg)) +#define WL_READ_2(sc, reg) bus_read_2((sc)->res_ioport, (reg)) +#define WL_READ_MULTI_2(sc, reg, buf, len) \ + bus_read_multi_2((sc)->res_ioport, (reg), (uint16_t *)(buf), (len)) +#define WL_WRITE_1(sc, reg, val) \ + bus_write_1((sc)->res_ioport, (reg), (val)) +#define WL_WRITE_2(sc, reg, val) \ + bus_write_2((sc)->res_ioport, (reg), (val)) +#define WL_WRITE_MULTI_2(sc, reg, buf, len) \ + bus_write_multi_2((sc)->res_ioport, (reg), (uint16_t *)(buf), (len)) + +#define CMD(sc) \ { \ - outw(HACR(sc->base),sc->hacr); \ + WL_WRITE_2(sc, HACR, sc->hacr); \ /* delay for 50 us, might only be needed sometimes */ \ DELAY(DELAYCONST); \ } /* macro for setting the channel attention bit. No delays here since * it is used in critical sections */ #define SET_CHAN_ATTN(sc) \ { \ - outw(HACR(sc->base),sc->hacr | HACR_CA); \ + WL_WRITE_2(sc, HACR, sc->hacr | HACR_CA); \ } #define MMC_WRITE(cmd,val) \ - while(inw(HASR(sc->base)) & HASR_MMC_BUSY) ; \ - outw(MMCR(sc->base), \ + while (WL_READ_2(sc, HASR) & HASR_MMC_BUSY) ; \ + WL_WRITE_2(sc, MMCR, \ (u_short)(((u_short)(val) << 8) | ((cmd) << 1) | 1)) #endif /* _IF_WL_H */ Index: projects/sendfile/sys/i386/isa/spic.c =================================================================== --- projects/sendfile/sys/i386/isa/spic.c (revision 274764) +++ projects/sendfile/sys/i386/isa/spic.c (revision 274765) @@ -1,554 +1,562 @@ /*- * Copyright (c) 2000 Nick Sayer * 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. * * 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. */ /* spic -- the Sony Programmable I/O Controller * * This device exists on most recent Sony laptops. It is the means by which * you can watch the Jog Dial and some other functions. * * At the moment, this driver merely tries to turn the jog dial into a * device that moused can park on, with the intent of supplying a Z axis * and mouse button out of the jog dial. I suspect that this device will * end up having to support at least 2 different minor devices: One to be * the jog wheel device for moused to camp out on and the other to perform * all of the other miscellaneous functions of this device. But for now, * the jog wheel is all you get. * * At the moment, the data sent back by the device is rather primitive. * It sends a single character per event: * u = up, d = down -- that's the jog button * l = left, r = right -- that's the dial. * "left" and "right" are rather capricious. They actually represent * ccw and cw, respectively * * What documentation exists is thanks to Andrew Tridge, and his page at * http://samba.org/picturebook/ Special thanks also to Ian Dowse, who * also provided sample code upon which this driver was based. */ #include __FBSDID("$FreeBSD$"); #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include #include static int spic_pollrate; SYSCTL_INT(_machdep, OID_AUTO, spic_pollrate, CTLFLAG_RW, &spic_pollrate, 0, "") ; devclass_t spic_devclass; static d_open_t spicopen; static d_close_t spicclose; static d_read_t spicread; static d_ioctl_t spicioctl; static d_poll_t spicpoll; static struct cdevsw spic_cdevsw = { .d_version = D_VERSION, - .d_flags = D_NEEDGIANT, .d_open = spicopen, .d_close = spicclose, .d_read = spicread, .d_ioctl = spicioctl, .d_poll = spicpoll, .d_name = "spic", }; #define SCBUFLEN 128 struct spic_softc { u_int sc_port_addr; u_char sc_intr; struct resource *sc_port_res,*sc_intr_res; int sc_port_rid,sc_intr_rid; int sc_opened; int sc_sleeping; int sc_buttonlast; - struct callout_handle sc_timeout_ch; + struct callout sc_timeout; + struct mtx sc_lock; device_t sc_dev; + struct cdev *sc_cdev; struct selinfo sc_rsel; u_char sc_buf[SCBUFLEN]; int sc_count; int sc_model; }; static void write_port1(struct spic_softc *sc, u_char val) { DELAY(10); outb(sc->sc_port_addr, val); } static void write_port2(struct spic_softc *sc, u_char val) { DELAY(10); outb(sc->sc_port_addr + 4, val); } static u_char read_port1(struct spic_softc *sc) { DELAY(10); return inb(sc->sc_port_addr); } static u_char read_port2(struct spic_softc *sc) { DELAY(10); return inb(sc->sc_port_addr + 4); } static u_char read_port_cst(struct spic_softc *sc) { DELAY(10); return inb(SPIC_CST_IOPORT); } static void busy_wait(struct spic_softc *sc) { int i=0; while(read_port2(sc) & 2) { DELAY(10); if (i++>10000) { printf("spic busy wait abort\n"); return; } } } static void busy_wait_cst(struct spic_softc *sc, int mask) { int i=0; while(read_port_cst(sc) & mask) { DELAY(10); if (i++>10000) { printf("spic busy wait abort\n"); return; } } } static u_char spic_call1(struct spic_softc *sc, u_char dev) { busy_wait(sc); write_port2(sc, dev); read_port2(sc); return read_port1(sc); } static u_char spic_call2(struct spic_softc *sc, u_char dev, u_char fn) { busy_wait(sc); write_port2(sc, dev); busy_wait(sc); write_port1(sc, fn); return read_port1(sc); } static void spic_ecrset(struct spic_softc *sc, u_int16_t addr, u_int16_t value) { busy_wait_cst(sc, 3); outb(SPIC_CST_IOPORT, 0x81); busy_wait_cst(sc, 2); outb(SPIC_DATA_IOPORT, addr); busy_wait_cst(sc, 2); outb(SPIC_DATA_IOPORT, value); busy_wait_cst(sc, 2); } static void spic_type2_srs(struct spic_softc *sc) { spic_ecrset(sc, SPIC_SHIB, (sc->sc_port_addr & 0xFF00) >> 8); spic_ecrset(sc, SPIC_SLOB, sc->sc_port_addr & 0x00FF); spic_ecrset(sc, SPIC_SIRQ, 0x00); /* using polling mode (IRQ=0)*/ DELAY(10); } static int spic_probe(device_t dev) { struct spic_softc *sc; u_char t, spic_irq; sc = device_get_softc(dev); /* * We can only have 1 of these. Attempting to probe for a unit 1 * will destroy the work we did for unit 0 */ if (device_get_unit(dev)) return ENXIO; bzero(sc, sizeof(struct spic_softc)); if (!(sc->sc_port_res = bus_alloc_resource(dev, SYS_RES_IOPORT, &sc->sc_port_rid, 0, ~0, 5, RF_ACTIVE))) { device_printf(dev,"Couldn't map I/O\n"); return ENXIO; } sc->sc_port_addr = (u_short)rman_get_start(sc->sc_port_res); #ifdef notyet if (!(sc->sc_intr_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &sc->sc_intr_rid, RF_ACTIVE))) { device_printf(dev,"Couldn't map IRQ\n"); bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_port_rid, sc->sc_port_res); return ENXIO; } sc->sc_intr = (u_short)rman_get_start(sc->sc_intr_res); switch (sc->sc_intr) { case 0: spic_irq = 3; break; case 5: spic_irq = 0; break; case 0xa: spic_irq = 1; break; case 0xb: spic_irq = 2; break; default: device_printf(dev,"Invalid IRQ\n"); bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_port_rid, sc->sc_port_res); bus_release_resource(dev, SYS_RES_IRQ, sc->sc_intr_rid, sc->sc_intr_res); return ENXIO; } #else spic_irq = 3; #endif #if 0 if (sc->sc_port_addr != 0x10A0) { bus_release_resource(dev, SYS_RES_IOPORT, sc->sc_port_rid, sc->sc_port_res); bus_release_resource(dev, SYS_RES_IRQ, sc->sc_intr_rid, sc->sc_intr_res); return ENXIO; } #endif /* PIIX4 chipset at least? */ if (pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, 0, 4) == PIIX4_DEVID) { sc->sc_model = SPIC_DEVICE_MODEL_TYPE1; } else { /* For newer VAIOs (R505, SRX7, ...) */ sc->sc_model = SPIC_DEVICE_MODEL_TYPE2; } /* * This is an ugly hack. It is necessary until ACPI works correctly. * * The SPIC consists of 2 registers. They are mapped onto I/O by the * PIIX4's General Device 10 function. There is also an interrupt * control port at a somewhat magic location, but this first pass is * polled. * * So the first thing we need to do is map the G10 space in. * */ /* Enable ACPI mode to get Fn key events */ /* XXX This may slow down your VAIO if ACPI is not supported in the kernel. outb(0xb2, 0xf0); */ device_printf(dev,"device model type = %d\n", sc->sc_model); if(sc->sc_model == SPIC_DEVICE_MODEL_TYPE1) { pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10A, sc->sc_port_addr, 2); t = pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, 1); t &= 0xf0; t |= 4; pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, t, 1); outw(SPIC_IRQ_PORT, (inw(SPIC_IRQ_PORT) & ~(0x3 << SPIC_IRQ_SHIFT)) | (spic_irq << SPIC_IRQ_SHIFT)); t = pci_cfgregread(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, 1); t &= 0x1f; t |= 0xc0; pci_cfgregwrite(PIIX4_BUS, PIIX4_SLOT, PIIX4_FUNC, G10L, t, 1); } else { spic_type2_srs(sc); } /* * XXX: Should try and see if there's anything actually there. */ device_set_desc(dev, "Sony Programmable I/O Controller"); return 0; } static int spic_attach(device_t dev) { struct spic_softc *sc; sc = device_get_softc(dev); sc->sc_dev = dev; + mtx_init(&sc->sc_lock, "spic", NULL, MTX_DEF); + callout_init_mtx(&sc->sc_timeout, &sc->sc_lock, 0); spic_pollrate = (hz/50); /* Every 50th of a second */ spic_call1(sc, 0x82); spic_call2(sc, 0x81, 0xff); spic_call1(sc, 0x92); /* There can be only one */ - make_dev(&spic_cdevsw, 0, 0, 0, 0600, "jogdial"); + sc->sc_cdev = make_dev(&spic_cdevsw, 0, 0, 0, 0600, "jogdial"); + sc->sc_cdev->si_drv1 = sc; return 0; } static void spictimeout(void *arg) { struct spic_softc *sc = arg; u_char b, event, param; int j; + mtx_assert(&sc->sc_lock, MA_OWNED); if (!sc->sc_opened) { device_printf(sc->sc_dev, "timeout called while closed!\n"); return; } event = read_port2(sc); param = read_port1(sc); if ((event != 4) && (!(event & 0x1))) switch(event) { case 0x10: /* jog wheel event (type1) */ if (sc->sc_model == SPIC_DEVICE_MODEL_TYPE1) { b = !!(param & 0x40); if (b != sc->sc_buttonlast) { sc->sc_buttonlast = b; sc->sc_buf[sc->sc_count++] = b?'d':'u'; } j = (param & 0xf) | ((param & 0x10)? ~0xf:0); if (j<0) while(j++!=0) { sc->sc_buf[sc->sc_count++] = 'l'; } else if (j>0) while(j--!=0) { sc->sc_buf[sc->sc_count++] = 'r'; } } break; case 0x08: /* jog wheel event (type2) */ case 0x00: /* SPIC_DEVICE_MODEL_TYPE2 returns jog wheel event=0x00 */ if (sc->sc_model == SPIC_DEVICE_MODEL_TYPE2) { b = !!(param & 0x40); if (b != sc->sc_buttonlast) { sc->sc_buttonlast = b; sc->sc_buf[sc->sc_count++] = b?'d':'u'; } j = (param & 0xf) | ((param & 0x10)? ~0xf:0); if (j<0) while(j++!=0) { sc->sc_buf[sc->sc_count++] = 'l'; } else if (j>0) while(j--!=0) { sc->sc_buf[sc->sc_count++] = 'r'; } } break; case 0x60: /* Capture button */ printf("Capture button event: %x\n",param); break; case 0x30: /* Lid switch */ printf("Lid switch event: %x\n",param); break; case 0x0c: /* We must ignore these type of event for C1VP... */ case 0x70: /* Closing/Opening the lid on C1VP */ break; default: printf("Unknown event: event %02x param %02x\n", event, param); break; } else { /* No event. Wait some more */ - sc->sc_timeout_ch = timeout(spictimeout, sc, spic_pollrate); + callout_reset(&sc->sc_timeout, spic_pollrate, spictimeout, sc); return; } if (sc->sc_count) { if (sc->sc_sleeping) { sc->sc_sleeping = 0; wakeup( sc); } selwakeuppri(&sc->sc_rsel, PZERO); } spic_call2(sc, 0x81, 0xff); /* Clear event */ - sc->sc_timeout_ch = timeout(spictimeout, sc, spic_pollrate); + callout_reset(&sc->sc_timeout, spic_pollrate, spictimeout, sc); } static int spicopen(struct cdev *dev, int flag, int fmt, struct thread *td) { struct spic_softc *sc; - sc = devclass_get_softc(spic_devclass, 0); + sc = dev->si_drv1; - if (sc->sc_opened) - return EBUSY; + mtx_lock(&sc->sc_lock); + if (sc->sc_opened) { + mtx_unlock(&sc->sc_lock); + return (EBUSY); + } sc->sc_opened++; sc->sc_count=0; /* Start the polling */ - timeout(spictimeout, sc, spic_pollrate); - return 0; + callout_reset(&sc->sc_timeout, spic_pollrate, spictimeout, sc); + mtx_unlock(&sc->sc_lock); + return (0); } static int spicclose(struct cdev *dev, int flag, int fmt, struct thread *td) { struct spic_softc *sc; - sc = devclass_get_softc(spic_devclass, 0); + sc = dev->si_drv1; + mtx_lock(&sc->sc_lock); /* Stop polling */ - untimeout(spictimeout, sc, sc->sc_timeout_ch); + callout_stop(&sc->sc_timeout); sc->sc_opened = 0; + mtx_unlock(&sc->sc_lock); return 0; } static int spicread(struct cdev *dev, struct uio *uio, int flag) { struct spic_softc *sc; - int l, s, error; + int l, error; u_char buf[SCBUFLEN]; - sc = devclass_get_softc(spic_devclass, 0); + sc = dev->si_drv1; if (uio->uio_resid <= 0) /* What kind of a read is this?! */ - return 0; + return (0); - s = spltty(); + mtx_lock(&sc->sc_lock); while (!(sc->sc_count)) { sc->sc_sleeping=1; - error = tsleep( sc, PZERO | PCATCH, "jogrea", 0); + error = mtx_sleep(sc, &sc->sc_lock, PZERO | PCATCH, "jogrea", 0); sc->sc_sleeping=0; if (error) { - splx(s); - return error; + mtx_unlock(&sc->sc_lock); + return (error); } } - splx(s); - s = spltty(); l = min(uio->uio_resid, sc->sc_count); bcopy(sc->sc_buf, buf, l); sc->sc_count -= l; bcopy(sc->sc_buf + l, sc->sc_buf, l); - splx(s); - return uiomove(buf, l, uio); - + mtx_unlock(&sc->sc_lock); + return (uiomove(buf, l, uio)); } static int spicioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flag, struct thread *td) { struct spic_softc *sc; - sc = devclass_get_softc(spic_devclass, 0); + sc = dev->si_drv1; - return EIO; + return (EIO); } static int spicpoll(struct cdev *dev, int events, struct thread *td) { struct spic_softc *sc; - int revents = 0, s; + int revents = 0; - sc = devclass_get_softc(spic_devclass, 0); - s = spltty(); + sc = dev->si_drv1; + mtx_lock(&sc->sc_lock); if (events & (POLLIN | POLLRDNORM)) { if (sc->sc_count) revents |= events & (POLLIN | POLLRDNORM); else selrecord(td, &sc->sc_rsel); /* Who shall we wake? */ } - splx(s); + mtx_unlock(&sc->sc_lock); - return revents; + return (revents); } static device_method_t spic_methods[] = { DEVMETHOD(device_probe, spic_probe), DEVMETHOD(device_attach, spic_attach), { 0, 0 } }; static driver_t spic_driver = { "spic", spic_methods, sizeof(struct spic_softc), }; DRIVER_MODULE(spic, isa, spic_driver, spic_devclass, 0, 0); Index: projects/sendfile/sys =================================================================== --- projects/sendfile/sys (revision 274764) +++ projects/sendfile/sys (revision 274765) Property changes on: projects/sendfile/sys ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head/sys:r274755-274762 Index: projects/sendfile =================================================================== --- projects/sendfile (revision 274764) +++ projects/sendfile (revision 274765) Property changes on: projects/sendfile ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /head:r274755-274762