Author: landonf
Date: Tue May 23 22:30:15 2017
New Revision: 318760
URL: https://svnweb.freebsd.org/changeset/base/318760

Log:
  bhnd(4): Fix a SPROM identification regression introduced in r315866
  
  In r315866, we introduced a direct read of the 8-bit sromrev field from the
  memory mapped SPROM/OTP device. On OTP devices that require 16-bit access
  alignment, this read fails, preventing identification of the SPROM layout.
  
  So, let's perform an aligned read of the combined 16-bit sromrev/crc field
  instead.
  
  Approved by:  adrian (mentor, implicit)

Modified:
  head/sys/dev/bhnd/nvram/bhnd_nvram_data_sprom.c
  head/sys/dev/bhnd/nvram/bhnd_sprom.c

Modified: head/sys/dev/bhnd/nvram/bhnd_nvram_data_sprom.c
==============================================================================
--- head/sys/dev/bhnd/nvram/bhnd_nvram_data_sprom.c     Tue May 23 22:11:45 
2017        (r318759)
+++ head/sys/dev/bhnd/nvram/bhnd_nvram_data_sprom.c     Tue May 23 22:30:15 
2017        (r318760)
@@ -184,6 +184,7 @@ bhnd_nvram_sprom_ident(struct bhnd_nvram
                u_char                   buf[512];
                size_t                   nread;
                uint16_t                 magic;
+               uint8_t                  srevcrc[2];
                uint8_t                  srev;
                bool                     crc_valid;
                bool                     have_magic;
@@ -224,12 +225,15 @@ bhnd_nvram_sprom_ident(struct bhnd_nvram
                        nbytes += nr;
                }
 
-               /* Read SPROM revision */
-               error = bhnd_nvram_io_read(io, layout->srev_offset, &srev,
-                   sizeof(srev));
+               /* Read 8-bit SPROM revision, maintaining 16-bit size alignment
+                * required by some OTP/SPROM chipsets. */
+               error = bhnd_nvram_io_read(io, layout->srev_offset, &srevcrc,
+                   sizeof(srevcrc));
                if (error)
                        return (error);
 
+               srev = srevcrc[0];
+
                /* Early sromrev 1 devices (specifically some BCM440x enet
                 * cards) are reported to have been incorrectly programmed
                 * with a revision of 0x10. */

Modified: head/sys/dev/bhnd/nvram/bhnd_sprom.c
==============================================================================
--- head/sys/dev/bhnd/nvram/bhnd_sprom.c        Tue May 23 22:11:45 2017        
(r318759)
+++ head/sys/dev/bhnd/nvram/bhnd_sprom.c        Tue May 23 22:30:15 2017        
(r318760)
@@ -120,9 +120,9 @@ bhnd_sprom_attach(device_t dev, bus_size
 
        sprom_size = r_size - offset;
 
-       /* Allocate an I/O context for the SPROM parser. SPROM reads do not
-        * appear to require any specific alignment. */
-       io = bhnd_nvram_iores_new(r, offset, sprom_size, 1);
+       /* Allocate an I/O context for the SPROM parser. All SPROM reads
+        * must be 16-bit aligned */
+       io = bhnd_nvram_iores_new(r, offset, sprom_size, sizeof(uint16_t));
        if (io == NULL) {
                error = ENXIO;
                goto failed;
_______________________________________________
svn-src-head@freebsd.org mailing list
https://lists.freebsd.org/mailman/listinfo/svn-src-head
To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"

Reply via email to