From owner-svn-src-all@freebsd.org Tue Nov 24 15:32:27 2020 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id 030052E9806; Tue, 24 Nov 2020 15:32:27 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4CgSgt6mVxz4rZ5; Tue, 24 Nov 2020 15:32:26 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id DB49E2122A; Tue, 24 Nov 2020 15:32:26 +0000 (UTC) (envelope-from mav@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id 0AOFWQMH034868; Tue, 24 Nov 2020 15:32:26 GMT (envelope-from mav@FreeBSD.org) Received: (from mav@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id 0AOFWQL0034845; Tue, 24 Nov 2020 15:32:26 GMT (envelope-from mav@FreeBSD.org) Message-Id: <202011241532.0AOFWQL0034845@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: mav set sender to mav@FreeBSD.org using -f From: Alexander Motin Date: Tue, 24 Nov 2020 15:32:26 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r367986 - head/sys/dev/isp X-SVN-Group: head X-SVN-Commit-Author: mav X-SVN-Commit-Paths: head/sys/dev/isp X-SVN-Commit-Revision: 367986 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 24 Nov 2020 15:32:27 -0000 Author: mav Date: Tue Nov 24 15:32:25 2020 New Revision: 367986 URL: https://svnweb.freebsd.org/changeset/base/367986 Log: Remove concept of mbox_sleep_ok. It was broken by design and unused for years due to conflicts between different threads, fighting for the same set of mailbox registers, not designed for multiple requests at a time. So either request has to be synchronous and spin under the lock, or it should be sent asynchronously through the queues as Mailbox Command IOCB or some other way. This removes any OS specifics from the wait code, so it can be inlined. Modified: head/sys/dev/isp/isp.c head/sys/dev/isp/isp_freebsd.c head/sys/dev/isp/isp_freebsd.h head/sys/dev/isp/ispvar.h Modified: head/sys/dev/isp/isp.c ============================================================================== --- head/sys/dev/isp/isp.c Tue Nov 24 14:05:52 2020 (r367985) +++ head/sys/dev/isp/isp.c Tue Nov 24 15:32:25 2020 (r367986) @@ -3216,7 +3216,7 @@ isp_intr_mbox(ispsoftc_t *isp, uint16_t mbox0) continue; isp->isp_mboxtmp[i] = ISP_READ(isp, MBOX_OFF(i)); } - MBOX_NOTIFY_COMPLETE(isp); + isp->isp_mboxbsy = 0; } void @@ -3489,7 +3489,7 @@ isp_intr_async(ispsoftc_t *isp, uint16_t mbox) if (isp->isp_mboxbsy) { isp->isp_obits = 1; isp->isp_mboxtmp[0] = MBOX_HOST_INTERFACE_ERROR; - MBOX_NOTIFY_COMPLETE(isp); + isp->isp_mboxbsy = 0; } /* * It's up to the handler for isp_async to reinit stuff and @@ -4243,7 +4243,7 @@ isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp) { const char *cname, *xname, *sname; char tname[16], mname[16]; - unsigned int ibits, obits, box, opcode; + unsigned int ibits, obits, box, opcode, t, to; opcode = mbp->param[0]; if (opcode > MAX_FC_OPCODE) { @@ -4279,14 +4279,6 @@ isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp) return; } - /* - * Get exclusive usage of mailbox registers. - */ - if (MBOX_ACQUIRE(isp)) { - mbp->param[0] = MBOX_REGS_BUSY; - goto out; - } - for (box = 0; box < ISP_NMBOX(isp); box++) { if (ibits & (1 << box)) { isp_prt(isp, ISP_LOGDEBUG3, "IN mbox %d = 0x%04x", box, @@ -4297,10 +4289,6 @@ isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp) } isp->isp_lastmbxcmd = opcode; - - /* - * We assume that we can't overwrite a previous command. - */ isp->isp_obits = obits; isp->isp_mboxbsy = 1; @@ -4312,14 +4300,24 @@ isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp) /* * While we haven't finished the command, spin our wheels here. */ - MBOX_WAIT_COMPLETE(isp, mbp); + to = (mbp->timeout == 0) ? MBCMD_DEFAULT_TIMEOUT : mbp->timeout; + for (t = 0; t < to; t += 100) { + if (!isp->isp_mboxbsy) + break; + ISP_RUN_ISR(isp); + if (!isp->isp_mboxbsy) + break; + ISP_DELAY(100); + } /* * Did the command time out? */ - if (mbp->param[0] == MBOX_TIMEOUT) { + if (isp->isp_mboxbsy) { isp->isp_mboxbsy = 0; - MBOX_RELEASE(isp); + isp_prt(isp, ISP_LOGWARN, "Mailbox Command (0x%x) Timeout (%uus) (%s:%d)", + isp->isp_lastmbxcmd, to, mbp->func, mbp->lineno); + mbp->param[0] = MBOX_TIMEOUT; goto out; } @@ -4334,8 +4332,6 @@ isp_mboxcmd(ispsoftc_t *isp, mbreg_t *mbp) } } - isp->isp_mboxbsy = 0; - MBOX_RELEASE(isp); out: if (mbp->logval == 0 || mbp->param[0] == MBOX_COMMAND_COMPLETE) return; Modified: head/sys/dev/isp/isp_freebsd.c ============================================================================== --- head/sys/dev/isp/isp_freebsd.c Tue Nov 24 14:05:52 2020 (r367985) +++ head/sys/dev/isp/isp_freebsd.c Tue Nov 24 15:32:25 2020 (r367986) @@ -3250,10 +3250,7 @@ isp_async(ispsoftc_t *isp, ispasync_t cmd, ...) mbox1 = ISP_READ(isp, OUTMAILBOX1); isp_prt(isp, ISP_LOGERR, "Internal Firmware Error @ RISC Address 0x%x", mbox1); #if 0 - mbox1 = isp->isp_osinfo.mbox_sleep_ok; - isp->isp_osinfo.mbox_sleep_ok = 0; isp_reinit(isp, 1); - isp->isp_osinfo.mbox_sleep_ok = mbox1; isp_async(isp, ISPASYNC_FW_RESTARTED, NULL); #endif break; @@ -3357,64 +3354,6 @@ isp_nanotime_sub(struct timespec *b, struct timespec * if (elapsed == 0) elapsed++; return (elapsed); -} - -int -isp_mbox_acquire(ispsoftc_t *isp) -{ - if (isp->isp_osinfo.mboxbsy) { - return (1); - } else { - isp->isp_osinfo.mboxcmd_done = 0; - isp->isp_osinfo.mboxbsy = 1; - return (0); - } -} - -void -isp_mbox_wait_complete(ispsoftc_t *isp, mbreg_t *mbp) -{ - u_int t, to; - - to = (mbp->timeout == 0) ? MBCMD_DEFAULT_TIMEOUT : mbp->timeout; - if (isp->isp_osinfo.mbox_sleep_ok) { - isp->isp_osinfo.mbox_sleep_ok = 0; - isp->isp_osinfo.mbox_sleeping = 1; - msleep_sbt(&isp->isp_osinfo.mboxcmd_done, &isp->isp_lock, - PRIBIO, "ispmbx_sleep", to * SBT_1US, 0, 0); - isp->isp_osinfo.mbox_sleep_ok = 1; - isp->isp_osinfo.mbox_sleeping = 0; - } else { - for (t = 0; t < to; t += 100) { - if (isp->isp_osinfo.mboxcmd_done) - break; - ISP_RUN_ISR(isp); - if (isp->isp_osinfo.mboxcmd_done) - break; - ISP_DELAY(100); - } - } - if (isp->isp_osinfo.mboxcmd_done == 0) { - isp_prt(isp, ISP_LOGWARN, "%s Mailbox Command (0x%x) Timeout (%uus) (%s:%d)", - isp->isp_osinfo.mbox_sleep_ok? "Interrupting" : "Polled", - isp->isp_lastmbxcmd, to, mbp->func, mbp->lineno); - mbp->param[0] = MBOX_TIMEOUT; - isp->isp_osinfo.mboxcmd_done = 1; - } -} - -void -isp_mbox_notify_done(ispsoftc_t *isp) -{ - isp->isp_osinfo.mboxcmd_done = 1; - if (isp->isp_osinfo.mbox_sleeping) - wakeup(&isp->isp_osinfo.mboxcmd_done); -} - -void -isp_mbox_release(ispsoftc_t *isp) -{ - isp->isp_osinfo.mboxbsy = 0; } int Modified: head/sys/dev/isp/isp_freebsd.h ============================================================================== --- head/sys/dev/isp/isp_freebsd.h Tue Nov 24 14:05:52 2020 (r367985) +++ head/sys/dev/isp/isp_freebsd.h Tue Nov 24 15:32:25 2020 (r367986) @@ -269,11 +269,6 @@ struct isposinfo { struct isp_pcmd * pcmd_pool; struct isp_pcmd * pcmd_free; - int mbox_sleeping; - int mbox_sleep_ok; - int mboxbsy; - int mboxcmd_done; - struct callout tmo; /* general timer */ /* @@ -428,11 +423,6 @@ default: \ break; \ } -#define MBOX_ACQUIRE isp_mbox_acquire -#define MBOX_WAIT_COMPLETE isp_mbox_wait_complete -#define MBOX_NOTIFY_COMPLETE isp_mbox_notify_done -#define MBOX_RELEASE isp_mbox_release - #define FC_SCRATCH_ACQUIRE isp_fc_scratch_acquire #define FC_SCRATCH_RELEASE(isp, chan) isp->isp_osinfo.pc.fc[chan].fcbsy = 0 @@ -631,10 +621,6 @@ extern int isp_quickboot_time; void isp_prt(ispsoftc_t *, int level, const char *, ...) __printflike(3, 4); void isp_xs_prt(ispsoftc_t *, XS_T *, int level, const char *, ...) __printflike(4, 5); uint64_t isp_nanotime_sub(struct timespec *, struct timespec *); -int isp_mbox_acquire(ispsoftc_t *); -void isp_mbox_wait_complete(ispsoftc_t *, mbreg_t *); -void isp_mbox_notify_done(ispsoftc_t *); -void isp_mbox_release(ispsoftc_t *); int isp_fc_scratch_acquire(ispsoftc_t *, int); void isp_platform_intr(void *); void isp_platform_intr_resp(void *); Modified: head/sys/dev/isp/ispvar.h ============================================================================== --- head/sys/dev/isp/ispvar.h Tue Nov 24 14:05:52 2020 (r367985) +++ head/sys/dev/isp/ispvar.h Tue Nov 24 15:32:25 2020 (r367986) @@ -831,11 +831,6 @@ void isp_async(ispsoftc_t *, ispasync_t, ...); * various objects so that the ISP's and the system's view * of the same object is consistent. * - * MBOX_ACQUIRE(ispsoftc_t *) acquire lock on mailbox regs - * MBOX_WAIT_COMPLETE(ispsoftc_t *, mbreg_t *) wait for cmd to be done - * MBOX_NOTIFY_COMPLETE(ispsoftc_t *) notification of mbox cmd donee - * MBOX_RELEASE(ispsoftc_t *) release lock on mailbox regs - * * FC_SCRATCH_ACQUIRE(ispsoftc_t *, chan) acquire lock on FC scratch area * return -1 if you cannot * FC_SCRATCH_RELEASE(ispsoftc_t *, chan) acquire lock on FC scratch area