From pmc@citylink.dinoex.sub.de  Sun Dec  4 18:13:34 2011
Return-Path: <pmc@citylink.dinoex.sub.de>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id 68DA5106566B
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  4 Dec 2011 18:13:34 +0000 (UTC)
	(envelope-from pmc@citylink.dinoex.sub.de)
Received: from uucp.dinoex.sub.de (uucp.dinoex.sub.de [194.45.71.2])
	by mx1.freebsd.org (Postfix) with ESMTP id C65C88FC0A
	for <FreeBSD-gnats-submit@freebsd.org>; Sun,  4 Dec 2011 18:13:33 +0000 (UTC)
Received: from uucp.dinoex.sub.de (uucp@uucp.dinoex.sub.de [194.45.71.2] (may be forged))
	by uucp.dinoex.sub.de (8.14.4/8.14.4) with ESMTP id pB4ID4hG058429
	(version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO)
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 Dec 2011 19:13:05 +0100 (CET)
	(envelope-from pmc@citylink.dinoex.sub.de)
Received: from citylink.dinoex.sub.de (uucp@localhost)
	by uucp.dinoex.sub.de (8.14.4/8.14.4/Submit) with UUCP id pB4ID4dm058428
	for FreeBSD-gnats-submit@freebsd.org; Sun, 4 Dec 2011 19:13:04 +0100 (CET)
	(envelope-from pmc@citylink.dinoex.sub.de)
Received: from gate.oper.dinoex.org (gate-e [192.168.98.2])
	by citylink.dinoex.sub.de (8.14.5/8.14.5) with ESMTP id pB4HxA2l024710
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 Dec 2011 18:59:11 +0100 (CET)
	(envelope-from pmc@disp.oper.dinoex.org)
Received: from disp.oper.dinoex.org (disp-e.oper.dinoex.org [192.168.97.18])
	by gate.oper.dinoex.org (8.14.5/8.14.5) with ESMTP id pB4Hv3Xq024470
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 Dec 2011 18:57:03 +0100 (CET)
	(envelope-from pmc@disp.oper.dinoex.org)
Received: from disp.oper.dinoex.org (localhost [127.0.0.1])
	by disp.oper.dinoex.org (8.14.5/8.14.5) with ESMTP id pB4Hu6Zc088715
	for <FreeBSD-gnats-submit@freebsd.org>; Sun, 4 Dec 2011 18:56:06 +0100 (CET)
	(envelope-from pmc@disp.oper.dinoex.org)
Received: (from pmc@localhost)
	by disp.oper.dinoex.org (8.14.5/8.14.5/Submit) id pB4Hu6pq088714;
	Sun, 4 Dec 2011 18:56:06 +0100 (CET)
	(envelope-from pmc)
Message-Id: <201112041756.pB4Hu6pq088714@disp.oper.dinoex.org>
Date: Sun, 4 Dec 2011 18:56:06 +0100 (CET)
From: Peter <pmc@citylink.dinoex.sub.org>
Reply-To: Peter <pmc@citylink.dinoex.sub.org>
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [fix][sym]driver tries to nego synch trans with everyone
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         163064
>Category:       kern
>Synopsis:       [sym] [patch] driver tries to nego synch trans with everyone
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mjacob
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Sun Dec 04 18:20:08 UTC 2011
>Closed-Date:    Mon Feb 25 14:07:43 UTC 2013
>Last-Modified:  Mon Feb 25 14:10:00 UTC 2013
>Originator:     Peter Much
>Release:        FreeBSD 7.4-STABLE i386
>Organization:
n/a
>Environment:
System: FreeBSD disp.oper.dinoex.org 7.4-STABLE FreeBSD 7.4-STABLE #0: Sun Dec 4 07:09:44 CET 2011 root@disp.oper.dinoex.org:/usr/src/sys/i386/compile/D1R74V1 i386

 Scanner: Mustek MFS-6000CX
 Controller: Symbios 810a
 Driver: sym

>Description:

The scanner gets detected, but is inaccessible.
Long time ago, I figured that the sym driver tries to negotiate synchronous
transfer, and the scanner seems to not like this at all, and things
go into some indefinite state. Then I created a crude hack to avoid
this. 
With Rel. 7 that crude hack seemed to no longer work. (In fact it
did still work - the real problem was that "camcontrol" is flawed
since Rel. 7, see bin/163053.)
So I started to search for the root cause.

Q: why does the driver try to negotiate synchronous with everybody,
even with devices that have no idea about synch transfers?

And, _if_ it does so deliberately, shouldn't there be a quirk to
switch it off for devices that misbehave?

I finally found the reason: in sym_hipd.c:sym_update_trans() there is
a range-check done for the synchronous parameters.
This range-check seems to disregard the possibility that there could
be *no* synchronous transfer intended, i.e. the parameter could be 0.

>How-To-Repeat:

Activate the DEBUG_NEGO option in sym_hipd.c 
>         #define DEBUG_FLAGS (0x0200)
and watch the negotiation messages.

Thats an U160 disk on a 1010-33 controller - I guess thats how it is 
supposed to work:
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): wide msgin: 1-2-3-1.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): wide msgout: 1-2-3-1.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): sync msgin: 1-3-1-a-7f.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): sync msgout: 1-3-1-a-1f.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): wide msgout: 1-2-3-1.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): wide msgin: 1-2-3-1.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): sync msgout: 1-3-1-a-1f.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): sync msgin: 1-3-1-a-1f.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): ppr msgout: 1-6-4-9-0-3e-1-2.
Dec  3 17:49:51 <kern.crit> disp kernel: (probe2:sym0:0:2:0): ppr msgin: 1-6-4-9-0-3e-1-2.

Thats a CDrom on a 810a controller - it can do sync transfers, but we
see the controller starts negotiation with someway strange parameters:
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgout: 1-3-1-19-0.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgin: 1-3-1-19-0.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgout: 1-3-1-19-8.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgin: 1-3-1-19-8.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgout: 1-3-1-19-8.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgin: 1-3-1-19-8.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgout: 1-3-1-19-8.
Dec  4 06:01:41 <kern.crit> disp kernel: (probe35:sym2:0:5:0): sync msgin: 1-3-1-19-8.

Thats a scanner - it has no idea about sync transfers, and seems to
ignore the messages:
Dec  4 02:28:58 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:28:59 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:29:16 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:29:45 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:30:03 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:30:05 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:30:05 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.
Dec  4 02:30:18 <kern.crit> disp kernel: (probe1:sym2:0:1:0): sync msgout: 1-3-1-19-0.

Thats the Mustek scanner - it seems to be pissed off and will not
work - while the driver insists and retries:
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): sync msgout: 1-3-1-19-0.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): phase change 6-7 6@01ab17a8 resid=4.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): sync msgout: 1-3-1-19-0.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): phase change 6-7 6@01ab17a8 resid=4.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): sync msgout: 1-3-1-19-0.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): phase change 6-7 6@01ab17a8 resid=4.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): sync msgout: 1-3-1-19-0.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): phase change 6-7 6@01ab17a8 resid=4.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): sync msgout: 1-3-1-19-0.
Dec  3 18:24:42 <kern.crit> disp kernel: (probe33:sym2:0:3:0): phase change 6-7 6@01ab17a8 resid=4.
...


>Fix:

*** sys/dev/sym/sym_hipd.c.orig	Thu Dec  1 05:26:17 2011
--- sys/dev/sym/sym_hipd.c	Sun Dec  4 06:35:57 2011
***************
*** 8291,8297 ****
  	 */
  	if (tip->width  > SYM_SETUP_MAX_WIDE) tip->width  = SYM_SETUP_MAX_WIDE;
  	if (tip->offset > SYM_SETUP_MAX_OFFS) tip->offset = SYM_SETUP_MAX_OFFS;
! 	if (tip->period < SYM_SETUP_MIN_SYNC) tip->period = SYM_SETUP_MIN_SYNC;
  
  	/*
  	 *  Scale against actual controller BUS width.
--- 8291,8298 ----
  	 */
  	if (tip->width  > SYM_SETUP_MAX_WIDE) tip->width  = SYM_SETUP_MAX_WIDE;
  	if (tip->offset > SYM_SETUP_MAX_OFFS) tip->offset = SYM_SETUP_MAX_OFFS;
! 	if (tip->period < SYM_SETUP_MIN_SYNC && tip->period != 0) 
! 	  tip->period = SYM_SETUP_MIN_SYNC;
  
  	/*
  	 *  Scale against actual controller BUS width.
***************
*** 8319,8325 ****
  			tip->offset = np->maxoffs_dt;
  	}
  	else {
! 		if (tip->period < np->minsync)
  			tip->period = np->minsync;
  		if (tip->period > np->maxsync)
  			tip->period = np->maxsync;
--- 8320,8326 ----
  			tip->offset = np->maxoffs_dt;
  	}
  	else {
! 		if (tip->period < np->minsync && tip->period != 0)
  			tip->period = np->minsync;
  		if (tip->period > np->maxsync)
  			tip->period = np->maxsync;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-scsi 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Sun Feb 24 23:19:25 UTC 2013 
Responsible-Changed-Why:  
Over to maintainer(s). 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163064 
State-Changed-From-To: open->closed 
State-Changed-By: mjacob 
State-Changed-When: Mon Feb 25 14:06:51 UTC 2013 
State-Changed-Why:  
Applied the patch, with slight changes to handle just 
offset being zero. 


Responsible-Changed-From-To: freebsd-scsi->mjacob 
Responsible-Changed-By: mjacob 
Responsible-Changed-When: Mon Feb 25 14:06:51 UTC 2013 
Responsible-Changed-Why:  
Applied the patch, with slight changes to handle just 
offset being zero. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=163064 

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/163064: commit references a PR
Date: Mon, 25 Feb 2013 14:06:37 +0000 (UTC)

 Author: mjacob
 Date: Mon Feb 25 14:06:24 2013
 New Revision: 247266
 URL: http://svnweb.freebsd.org/changeset/base/247266
 
 Log:
   Don't try and negotiate sync mode if either period or offset are zero.
   
   PR:		kern/163064
   Partially Submitted by:	Peter <pmc@citylink.dinoex.sub.org>
   MFC after:	1 month
 
 Modified:
   head/sys/dev/sym/sym_hipd.c
 
 Modified: head/sys/dev/sym/sym_hipd.c
 ==============================================================================
 --- head/sys/dev/sym/sym_hipd.c	Mon Feb 25 12:33:31 2013	(r247265)
 +++ head/sys/dev/sym/sym_hipd.c	Mon Feb 25 14:06:24 2013	(r247266)
 @@ -8211,8 +8211,13 @@ static void sym_update_trans(hcb_p np, t
  	 *  Scale against driver configuration limits.
  	 */
  	if (tip->width  > SYM_SETUP_MAX_WIDE) tip->width  = SYM_SETUP_MAX_WIDE;
 -	if (tip->offset > SYM_SETUP_MAX_OFFS) tip->offset = SYM_SETUP_MAX_OFFS;
 -	if (tip->period < SYM_SETUP_MIN_SYNC) tip->period = SYM_SETUP_MIN_SYNC;
 +	if (tip->period && tip->offset) {
 +		if (tip->offset > SYM_SETUP_MAX_OFFS) tip->offset = SYM_SETUP_MAX_OFFS;
 +		if (tip->period < SYM_SETUP_MIN_SYNC) tip->period = SYM_SETUP_MIN_SYNC;
 +	} else {
 +		tip->offset = 0;
 +		tip->period = 0;
 +	}
  
  	/*
  	 *  Scale against actual controller BUS width.
 @@ -8231,21 +8236,23 @@ static void sym_update_trans(hcb_p np, t
  	/*
  	 *  Scale period factor and offset against controller limits.
  	 */
 -	if (tip->options & PPR_OPT_DT) {
 -		if (tip->period < np->minsync_dt)
 -			tip->period = np->minsync_dt;
 -		if (tip->period > np->maxsync_dt)
 -			tip->period = np->maxsync_dt;
 -		if (tip->offset > np->maxoffs_dt)
 -			tip->offset = np->maxoffs_dt;
 -	}
 -	else {
 -		if (tip->period < np->minsync)
 -			tip->period = np->minsync;
 -		if (tip->period > np->maxsync)
 -			tip->period = np->maxsync;
 -		if (tip->offset > np->maxoffs)
 -			tip->offset = np->maxoffs;
 +	if (tip->offset && tip->period) {
 +		if (tip->options & PPR_OPT_DT) {
 +			if (tip->period < np->minsync_dt)
 +				tip->period = np->minsync_dt;
 +			if (tip->period > np->maxsync_dt)
 +				tip->period = np->maxsync_dt;
 +			if (tip->offset > np->maxoffs_dt)
 +				tip->offset = np->maxoffs_dt;
 +		}
 +		else {
 +			if (tip->period < np->minsync)
 +				tip->period = np->minsync;
 +			if (tip->period > np->maxsync)
 +				tip->period = np->maxsync;
 +			if (tip->offset > np->maxoffs)
 +				tip->offset = np->maxoffs;
 +		}
  	}
  }
  
 _______________________________________________
 svn-src-all@freebsd.org mailing list
 http://lists.freebsd.org/mailman/listinfo/svn-src-all
 To unsubscribe, send any mail to "svn-src-all-unsubscribe@freebsd.org"
 
>Unformatted:
