From kjk1@ukc.ac.uk  Sun Sep 14 12:04:11 1997
Received: from mercury.ukc.ac.uk (mercury.ukc.ac.uk [129.12.21.10])
          by hub.freebsd.org (8.8.7/8.8.7) with SMTP id MAA24063
          for <FreeBSD-gnats-submit@freebsd.org>; Sun, 14 Sep 1997 12:04:03 -0700 (PDT)
Received: from kestrel.ukc.ac.uk by mercury.ukc.ac.uk with SMTP (PP);
          Sun, 14 Sep 1997 20:03:46 +0100
Received: from localhost by kestrel.ukc.ac.uk (5.x/UKC-2.14) id AA18796;
          Sun, 14 Sep 1997 20:03:45 +0100
Message-Id: <Pine.SV4.3.95.970914200044.18738A-100000@kestrel.ukc.ac.uk>
Date: Sun, 14 Sep 1997 20:03:45 +0100 (BST)
From: "K.J.Koster" <kjk1@ukc.ac.uk>
To: FreeBSD-gnats-submit@freebsd.org
Subject: byteswapped ATAPI id strings

>Number:         4538
>Category:       i386
>Synopsis:       byteswapped ATAPI id strings
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    sos
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sun Sep 14 12:10:00 PDT 1997
>Closed-Date:    Mon Feb 28 11:31:20 PST 2000
>Last-Modified:  Mon Feb 28 11:32:51 PST 2000
>Originator:     Kees Jan Koster
>Release:        FreeBSD 2.2.2-RELEASE i386
>Organization:
<Organization of PR author (multiple lines)>
>Environment:
 
Motherboard: DataExpert 8661
cdrom player: BTC 8x ATAPI
previous cdrom player: Pioneer 4x ATAPI
 
dmesg output before applying fix:
wdc0: unit 1 (atapi): <DCX8  1F 0100- 99169./EP1P1.B>, removable, iordis
 
dmesg output after applying fix:
wdc0: unit 1 (atapi): <CD8X  F10 01-09 1996. /PEP1.1>, removable, iordis
 
>Description:
 
The ID string and the revision strings come out byteswapped. It happened
to
both my pioneer and my btc drive. The BIOS autodetection also identifies
the
cdrom player with its bytes swapped, so I blame my BIOS.
 
It annoyed me, so I propose the following kernel config option:
 
  options SWAB_ATAPI_ID
 
>How-To-Repeat:
 
n/a
 
==============================================================
Patch for the LINT kernel (/sys/i386/conf/LINT)
==============================================================
 
*** LINT.orig   Sun Sep 14 18:19:19 1997
--- LINT        Sun Sep 14 18:23:38 1997
***************
*** 641,646 ****
--- 641,653 ----
  options         ATAPI   #Enable ATAPI support for IDE bus
  options               ATAPI_STATIC    #Don't do it as an LKM
  
+ #
+ # In some cases, the ID and revision strings of the ATAPI device come 
out
+ # byteswapped. Use this option to swap them back. This option is purely
+ # cosmetic and has no influence on the operation of the device.
+ #
+ options               SWAB_ATAPI_ID   #Byteswap the ID and revision
strings
+ 
  # IDE CD-ROM driver - requires wdc controller and ATAPI option
  device          wcd0
 
 
==============================================================
Patch for the atapi driver (/sys/i386/isa/atapi.c):
==============================================================
 
*** atapi.c.orig        Fri Jan 17 17:02:33 1997
--- atapi.c     Sun Sep 14 18:14:34 1997
***************
*** 173,178 ****
--- 173,202 ----
  extern int wdstart (int ctrlr);
  extern int wcdattach(struct atapi*, int, struct atapi_params*, int);
  
+ #ifdef SWAB_ATAPI_ID
+ /* copied verbatim from swap.c in the library sources */
+ static void
+ swab(const void *from, void *to, size_t len)
+ {
+         register unsigned long temp;
+         register int n;
+         register char *fp, *tp;
+ 
+         n = (len >> 1) + 1;
+         fp = (char *)from;
+         tp = (char *)to;
+ #define STEP    temp = *fp++,*tp++ = *fp++,*tp++ = temp
+         /* round to multiple of 8 */
+         while ((--n) & 07)
+                 STEP;
+         n >>= 3;
+         while (--n >= 0) {
+                 STEP; STEP; STEP; STEP;
+                 STEP; STEP; STEP; STEP;
+         }
+ }
+ #endif
+ 
  /*
   * Probe the ATAPI device at IDE controller `ctlr', drive `unit'.
   * Called at splbio().
***************
*** 193,204 ****
        if (! ap)
                return (0);
  
        bcopy (ap->model, buf, sizeof(buf)-1);
        buf[sizeof(buf)-1] = 0;
  
        bcopy (ap->revision, revbuf, sizeof(revbuf)-1);
        revbuf[sizeof(revbuf)-1] = 0;
! 
        printf ("wdc%d: unit %d (atapi): <%s/%s>", ctlr, unit, buf,
revbuf);
  
        /* device is removable */
--- 217,235 ----
        if (! ap)
                return (0);
  
+ #ifdef SWAB_ATAPI_ID
+       swab (ap->model, buf, sizeof(buf)-1);
+       buf[sizeof(buf)-1] = 0;
+ 
+       swab (ap->revision, revbuf, sizeof(revbuf)-1);
+       revbuf[sizeof(revbuf)-1] = 0;
+ #else
        bcopy (ap->model, buf, sizeof(buf)-1);
        buf[sizeof(buf)-1] = 0;
  
        bcopy (ap->revision, revbuf, sizeof(revbuf)-1);
        revbuf[sizeof(revbuf)-1] = 0;
! #endif
        printf ("wdc%d: unit %d (atapi): <%s/%s>", ctlr, unit, buf,
revbuf);
  
        /* device is removable */
 
 
==============================================================
Suggested addition to the handbook and to the wcd manual page:
==============================================================
 
(in the section covering device wcd?)
 
In some cases, the ID and revision strings of the ATAPI device come out
byteswapped. Use this option to swap them back. This option is purely
cosmetic and has no influence on the operation of the device.


>Fix:
>Release-Note:
>Audit-Trail:
State-Changed-From-To: open->analyzed 
State-Changed-By: sos 
State-Changed-When: Thu Oct 30 11:46:44 PST 1997 
State-Changed-Why:  

There allready is hooks in the driver to byteswap ID strings,  
as NEC and MITSUMI requieres this too, the solution is therefore 
to add these drives to that logic, not to provide the same 
function once more... 



Responsible-Changed-From-To: freebsd-bugs->sos 
Responsible-Changed-By: sos 
Responsible-Changed-When: Thu Oct 30 11:46:44 PST 1997 
Responsible-Changed-Why:  

I', the atapi man 
State-Changed-From-To: analyzed->closed 
State-Changed-By: sos 
State-Changed-When: Mon Feb 28 11:31:20 PST 2000 
State-Changed-Why:  
no longer relevant. 
edit-pr 5510 
>Unformatted:
X-send-pr-version: 3.2
 
 
