From nobody@FreeBSD.org  Thu Jan 26 02:05:12 2012
Return-Path: <nobody@FreeBSD.org>
Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34])
	by hub.freebsd.org (Postfix) with ESMTP id E5EBA1065677
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 02:05:12 +0000 (UTC)
	(envelope-from nobody@FreeBSD.org)
Received: from red.freebsd.org (red.freebsd.org [IPv6:2001:4f8:fff6::22])
	by mx1.freebsd.org (Postfix) with ESMTP id D56578FC1A
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 02:05:12 +0000 (UTC)
Received: from red.freebsd.org (localhost [127.0.0.1])
	by red.freebsd.org (8.14.4/8.14.4) with ESMTP id q0Q25CQt047489
	for <freebsd-gnats-submit@FreeBSD.org>; Thu, 26 Jan 2012 02:05:12 GMT
	(envelope-from nobody@red.freebsd.org)
Received: (from nobody@localhost)
	by red.freebsd.org (8.14.4/8.14.4/Submit) id q0Q25CU4047488;
	Thu, 26 Jan 2012 02:05:12 GMT
	(envelope-from nobody)
Message-Id: <201201260205.q0Q25CU4047488@red.freebsd.org>
Date: Thu, 26 Jan 2012 02:05:12 GMT
From: Justin Hibbits <jrh29@alumni.cwru.edu>
To: freebsd-gnats-submit@FreeBSD.org
Subject: if_wi needs fix for big endian architectures.
X-Send-Pr-Version: www-3.1
X-GNATS-Notify:

>Number:         164499
>Category:       kern
>Synopsis:       [wi] [patch] if_wi needs fix for big endian architectures.
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    freebsd-wireless
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          sw-bug
>Submitter-Id:   current-users
>Arrival-Date:   Thu Jan 26 02:10:01 UTC 2012
>Closed-Date:    Mon Jul 29 05:48:58 UTC 2013
>Last-Modified:  Mon Jul 29 05:48:58 UTC 2013
>Originator:     Justin Hibbits
>Release:        CURRENT
>Organization:
>Environment:
>Description:
if_wi(4) byte-swaps twice on big endian when reading from the device.  The attached patch fixes this by calling the streaming read.

Patch discussed with adrian@.
>How-To-Repeat:

>Fix:


Patch attached with submission follows:

Index: sys/dev/wi/if_wi.c
===================================================================
--- sys/dev/wi/if_wi.c	(revision 230483)
+++ sys/dev/wi/if_wi.c	(working copy)
@@ -1898,8 +1898,7 @@
 static int
 wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
 {
-	u_int16_t *ptr;
-	int i, error, cnt;
+	int error, cnt;
 
 	if (buflen == 0)
 		return 0;
@@ -1908,9 +1907,7 @@
 			return error;
 	}
 	cnt = (buflen + 1) / 2;
-	ptr = (u_int16_t *)buf;
-	for (i = 0; i < cnt; i++)
-		*ptr++ = CSR_READ_2(sc, WI_DATA0);
+	CSR_READ_MULTI_STREAM_2(sc, WI_DATA0, (u_int16_t *)buf, cnt);
 	sc->sc_bap_off += cnt * 2;
 	return 0;
 }
@@ -1918,8 +1915,7 @@
 static int
 wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
 {
-	u_int16_t *ptr;
-	int i, error, cnt;
+	int error, cnt;
 
 	if (buflen == 0)
 		return 0;
@@ -1929,9 +1925,7 @@
 			return error;
 	}
 	cnt = (buflen + 1) / 2;
-	ptr = (u_int16_t *)buf;
-	for (i = 0; i < cnt; i++)
-		CSR_WRITE_2(sc, WI_DATA0, ptr[i]);
+	CSR_WRITE_MULTI_STREAM_2(sc, WI_DATA0, (u_int16_t *)buf, cnt);
 	sc->sc_bap_off += cnt * 2;
 
 	return 0;


>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->freebsd-wireless 
Responsible-Changed-By: linimon 
Responsible-Changed-When: Thu Jan 26 02:22:27 UTC 2012 
Responsible-Changed-Why:  
Over to maintainer(s). 

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

From: dfilter@FreeBSD.ORG (dfilter service)
To: bug-followup@FreeBSD.org
Cc:  
Subject: Re: kern/164499: commit references a PR
Date: Mon, 29 Jul 2013 05:39:28 +0000 (UTC)

 Author: jhibbits
 Date: Mon Jul 29 05:39:20 2013
 New Revision: 253756
 URL: http://svnweb.freebsd.org/changeset/base/253756
 
 Log:
   Use the streaming functions for reading/writing the BAP fields on wi(4).  This
   fixes wi(4) device access on big endian architectures.
   
   PR:		kern/164499
   Reviewed by:	adrian
   Obtained from:	NetBSD
 
 Modified:
   head/sys/dev/wi/if_wi.c
 
 Modified: head/sys/dev/wi/if_wi.c
 ==============================================================================
 --- head/sys/dev/wi/if_wi.c	Sun Jul 28 20:11:31 2013	(r253755)
 +++ head/sys/dev/wi/if_wi.c	Mon Jul 29 05:39:20 2013	(r253756)
 @@ -1905,8 +1905,7 @@ wi_seek_bap(struct wi_softc *sc, int id,
  static int
  wi_read_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
  {
 -	u_int16_t *ptr;
 -	int i, error, cnt;
 +	int error, cnt;
  
  	if (buflen == 0)
  		return 0;
 @@ -1915,9 +1914,7 @@ wi_read_bap(struct wi_softc *sc, int id,
  			return error;
  	}
  	cnt = (buflen + 1) / 2;
 -	ptr = (u_int16_t *)buf;
 -	for (i = 0; i < cnt; i++)
 -		*ptr++ = CSR_READ_2(sc, WI_DATA0);
 +	CSR_READ_MULTI_STREAM_2(sc, WI_DATA0, (u_int16_t *)buf, cnt);
  	sc->sc_bap_off += cnt * 2;
  	return 0;
  }
 @@ -1925,8 +1922,7 @@ wi_read_bap(struct wi_softc *sc, int id,
  static int
  wi_write_bap(struct wi_softc *sc, int id, int off, void *buf, int buflen)
  {
 -	u_int16_t *ptr;
 -	int i, error, cnt;
 +	int error, cnt;
  
  	if (buflen == 0)
  		return 0;
 @@ -1936,9 +1932,7 @@ wi_write_bap(struct wi_softc *sc, int id
  			return error;
  	}
  	cnt = (buflen + 1) / 2;
 -	ptr = (u_int16_t *)buf;
 -	for (i = 0; i < cnt; i++)
 -		CSR_WRITE_2(sc, WI_DATA0, ptr[i]);
 +	CSR_WRITE_MULTI_STREAM_2(sc, WI_DATA0, (u_int16_t *)buf, cnt);
  	sc->sc_bap_off += cnt * 2;
  
  	return 0;
 _______________________________________________
 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"
 
State-Changed-From-To: open->closed 
State-Changed-By: jhibbits 
State-Changed-When: Mon Jul 29 05:47:28 UTC 2013 
State-Changed-Why:  
Patch committed in r253756. 

http://www.freebsd.org/cgi/query-pr.cgi?pr=164499 
>Unformatted:
