[openfirmware] [commit] r3569 - in dev: . bluetooth mmc/sdhci mmc/sdhci/mv8686 usb2/device/wlan

repository service svn at openfirmware.info
Mon Feb 25 09:34:36 CET 2013


Author: wmb
Date: Mon Feb 25 09:34:36 2013
New Revision: 3569
URL: http://tracker.coreboot.org/trac/openfirmware/changeset/3569

Log:
Marvell WLAN driver - Omnibus checkin of changes to the SDIO layer to
make it easier to share code with the Bluetooth driver.  The particular
advantage is to eliminate duplication of firmware downloading between
the WLAN and BT drivers.

Added:
   dev/bluetooth/
Modified:
   dev/libertas.fth
   dev/mmc/sdhci/mv8686/common.fth
   dev/mmc/sdhci/mv8686/fw8686.fth
   dev/mmc/sdhci/mv8686/loadpkg.fth
   dev/mmc/sdhci/mv8686/mv8686.fth
   dev/mmc/sdhci/mv8686/sdio.fth
   dev/mmc/sdhci/sdhci.fth
   dev/usb2/device/wlan/fw8388.fth
   dev/usb2/device/wlan/usb8388.bth
   dev/usb2/device/wlan/usb8388.fth
   dev/usb2/device/wlan/wlan.fth

Modified: dev/libertas.fth
==============================================================================
--- dev/libertas.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/libertas.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -4,6 +4,22 @@
 headers
 hex
 
+false instance value debug?
+
+: debug-on  ( -- )  true to debug?  ;
+: vdump  ( adr len -- )  debug?  if  " dump"  evaluate  else  2drop  then  ;
+
+create mac-adr 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
+6 constant /mac-adr
+: mac-adr$  ( -- adr len )  mac-adr /mac-adr  ;
+
+: max-frame-size  ( -- size )  d# 1514  ;
+
+external
+defer get-mac-address  ( -- adr len )		' mac-adr$ to get-mac-address
+headers
+
+
 \ **************** WPA and WPA2 are not functional yet ******************
 
 \ =======================================================================
@@ -21,7 +37,6 @@
 : .scan  ( adr -- )  " .scan" $call-supplicant  ;
 : .ssids  ( adr len -- )  " .ssids" $call-supplicant  ;
 
-defer load-all-fw  ( -- error? )   ' false to load-all-fw
 defer ?process-eapol		['] 2drop to ?process-eapol
 
 0 value outbuf
@@ -32,10 +47,10 @@
                         \ Override as necessary
 
 : init-buf  ( -- )
-   outbuf 0=  if  /outbuf dma-alloc to outbuf  then
+   outbuf 0=  if  /outbuf " alloc-buffer" $call-parent to outbuf  then
 ;
 : free-buf  ( -- )
-   outbuf  if  outbuf /outbuf dma-free  0 to outbuf  then
+   outbuf  if  outbuf /outbuf " free-buffer" $call-parent  0 to outbuf  then
 ;
 
 \ =======================================================================
@@ -143,27 +158,24 @@
 : set-auth-mode  ( amode -- )  to auth-mode  ;
 headers
 
-: marvel-link-up?  ( -- flag )  driver-state ds-ready >  ;
-
-' marvel-link-up? to link-up?
+: link-up?  ( -- flag )  driver-state ds-ready >  ;
 
 \ =========================================================================
 \ Firmware Command
 \ =========================================================================
 
 struct
-   /fw-transport +
    2 field >fw-cmd		\ Start of command header
    2 field >fw-len
    2 field >fw-seq
    2 field >fw-result
 dup constant /fw-cmd
-dup /fw-transport - constant /fw-cmd-hdr	\ Command header len (less /fw-transport)
+dup constant /fw-cmd-hdr	\ Command header len (less /fw-transport)
    0 field >fw-data		\ Command payload starts here
 drop
 
 : outbuf-out  ( -- error? )
-   outbuf  dup >fw-len le-w@ /fw-transport +  cmd-out
+   outbuf  dup >fw-len le-w@ " cmd-out" $call-parent
 ;
 
 
@@ -191,7 +203,6 @@
 \ =========================================================================
 
 struct
-   /fw-transport +
    4 field >tx-stat
    4 field >tx-ctrl
    4 field >tx-offset
@@ -211,7 +222,6 @@
 constant /tx-hdr
 
 struct
-   /fw-transport +
    1 field >tx14-bsstype
    1 field >tx14-bss#
    2 field >tx14-len
@@ -241,7 +251,7 @@
    dup   outbuf >tx-len  le-w!			( adr len )
    tuck  outbuf >tx-pkt-no-mesh  swap  move		( len )
 
-   /tx-hdr-no-mesh /fw-transport -  outbuf >tx-offset le-l!	( len )  \ Offset from >tx-stat field
+   /tx-hdr-no-mesh outbuf >tx-offset le-l!	( len )  \ Offset from >tx-stat field
    tx-ctrl        outbuf >tx-ctrl   le-l!	( len )
 
    outbuf  swap /tx-hdr-no-mesh +		( adr' len' )
@@ -253,7 +263,7 @@
    dup   outbuf >tx-len  le-w!			( adr len )
    tuck  outbuf >tx-pkt  swap  move		( len )
 
-   /tx-hdr /fw-transport - outbuf >tx-offset le-l!	( len )  \ Offset from >tx-stat field
+   /tx-hdr outbuf >tx-offset le-l!		( len )  \ Offset from >tx-stat field
    tx-ctrl        outbuf >tx-ctrl   le-l!	( len )
 
    mesh-on?  if  1 outbuf >tx-mesh-ttl c!  then	( len )
@@ -270,7 +280,7 @@
    dup   outbuf >tx14-len  le-w!		( adr len )
    tuck  outbuf >tx14-pkt  swap  move		( len )
 
-   /tx14-hdr /fw-transport - outbuf >tx14-offset le-w!	( len )  \ Offset from >tx14-bsstype field
+   /tx14-hdr outbuf >tx14-offset le-w!		( len )  \ Offset from >tx14-bsstype field
    tx-ctrl       outbuf >tx14-ctrl   le-l!	( len )
 
    outbuf  swap /tx14-hdr +			( adr' len' )
@@ -287,7 +297,6 @@
 
 \ Receive packet descriptor
 struct
-   /fw-transport +
    2 field >rx-stat
    1 field >rx-snr
    1 field >rx-ctrl
@@ -310,7 +319,6 @@
 constant /rx-min
 
 struct
-   /fw-transport +
    1 field >rx14-bsstype
    1 field >rx14-bss#
    2 field >rx14-len
@@ -358,7 +366,7 @@
    /rx-min <  if  drop  true exit  then		( adr )  \ Invalid packet: too small
 
    \ Go to the payload, skipping the descriptor header
-   dup  dup >rx-offset le-l@ + /fw-transport +	( adr data-adr )
+   dup  dup >rx-offset le-l@ +		( adr data-adr )
    swap >rx-len le-w@			( data-adr data-len )
 
    \ Remove snap header by moving the MAC addresses up
@@ -374,7 +382,7 @@
 
    \ Go to the payload, skipping the descriptor header
    >r							( r: adr )
-   r@  r@ >rx14-offset le-w@ +  /fw-transport +		( data-adr r: adr )
+   r@  r@ >rx14-offset le-w@ +  			( data-adr r: adr )
    r@ >rx14-len le-w@					( data-adr data-len  r: adr )
 
    r> >rx14-type c@  case				( data-adr data-len )
@@ -505,7 +513,7 @@
    dup .cmd                              ( len cmd )
    resp-wait-short to resp-wait          ( len cmd )
    outbuf /outbuf erase                  ( len cmd )
-   outbuf /fw-transport + to x  0 to /x  ( len cmd )
+   outbuf to x  0 to /x                  ( len cmd )
    ( len cmd )      +xw    \ fw-cmd      ( len )
    /fw-cmd-hdr +    +xw	   \ fw-len 	 ( )  
    fw-seq++         +xw    \ fw-seq      ( )
@@ -530,9 +538,9 @@
 0 instance value backlog
 0 value debug-tx-feedback?
 : process-ind  ( adr len -- )
-   drop
-   true to got-indicator?
-   4 + le-l@  dup to last-event
+   drop                              ( adr )
+   true to got-indicator?            ( adr )
+   le-l@  dup to last-event          ( event-code )
    dup h# 10000 u>=  if              ( event-code )
       \ TX feedback from thin firmware
       backlog 1- 0 max  to backlog   ( event-code )
@@ -590,9 +598,8 @@
    true to got-response?	( )
 ;
 
-: process-rx  ( adr len -- )
-   over packet-type  case
-      \ Encoding must agree with packet-type
+: process-rx  ( adr len type -- )
+   case
       0  of  process-request  endof	\ Response & request
       1  of  process-data     endof	\ Data
       2  of  process-ind      endof	\ Indication
@@ -601,9 +608,9 @@
 ;
 
 : check-for-rx  ( -- )
-   got-packet?  if		( error | buf len 0 )
-      0= if  2dup vdump process-rx	 then	( )
-      recycle-packet		( )
+   " got-packet?" $call-parent  if	( error | buf len type 0 )
+      0= if  process-rx  then	( )
+      " recycle-packet" $call-parent		( )
    then				( )
 ;
 
@@ -690,9 +697,8 @@
 \ =========================================================================
 
 : reset-wlan  ( -- )
-   " wlan-reset" evaluate
    driver-is-not-ready
-   reset-host-bus
+   " reset-host-bus" $call-parent
 ;
 : sleep  ( -- )  reset-wlan  ;
 : wake  ( -- )  ;
@@ -1692,7 +1698,6 @@
 : ?reassociate  ( -- )
    driver-state ds-disconnected and  if  do-associate drop  then
 ;
-' ?reassociate to start-nic
 
 : disassociate  ( mac$ -- )
    dup 2+ h# 26 ( CMD_802_11_DISASSOCIATE ) prepare-cmd
@@ -1794,7 +1799,7 @@
    mac-adr$  mac-adr$  broadcast-mac$  0  h# c0  set-802.11-header
    h# 0002  0 +pkt-data  le-w!  \ Reason code: auth no longer valid
    packet-buf  /802.11-header 2 +   wrap-802.11    ( adr len )
-   data-out
+   " data-out" $call-parent
    r> set-tx-ctrl
 ;
 
@@ -2100,18 +2105,6 @@
    ?make-mac-address-property drop
 ;
 
-: ?load-fw  ( -- error? )
-   driver-state ds-not-ready =  if
-      load-all-fw  if
-         ." Failed to download firmware" cr
-         true exit
-      then
-      ds-ready to driver-state
-   then
-   multifunction?  if  init-function  then
-   ?make-mac-address-property
-;
-
 false instance value use-promiscuous?
 
 external
@@ -2134,15 +2127,18 @@
    repeat drop
 ;
 
+\ Maybe handle this in parent's close method
+: release-bus-resources  ( -- )  " release-bus-resources" $call-parent  ;
+
 : open  ( -- ok? )
    my-args parse-args
-   set-parent-channel
    " " set-ssid  \ Instance buffers aren't necessarily initially 0
+   my-space " set-address" $call-parent \ Set SDIO function number if necessary
    opencount @ 0=  if
       init-buf
-      driver-is-not-ready
-      /inbuf /outbuf setup-bus-io  if  free-buf false exit  then
-      ?load-fw  if  release-bus-resources free-buf false exit  then
+      ds-ready to driver-state
+      " multifunction?" $call-parent  if  init-function  then
+      ?make-mac-address-property  if  release-bus-resources free-buf false exit  then
       set-fw-params
       my-args " supplicant" $open-package to supplicant-ih
       supplicant-ih 0=  if  release-bus-resources free-buf false exit  then
@@ -2152,7 +2148,7 @@
          link-up? 0=  if
             do-associate 0=  if  free-buf false exit  then
          then
-         start-nic
+         ?reassociate
       then
    then
    force-open?  0=  if
@@ -2171,10 +2167,9 @@
       mesh-stop drop
       link-up?  if  target-mac$ deauthenticate  then
       ['] 2drop to ?process-eapol
-      stop-nic
       mac-off
       supplicant-ih ?dup  if  close-package 0 to supplicant-ih  then
-      multifunction?  if  shutdown-function  then
+      " multifunction?" $call-parent  if  shutdown-function  then
       release-bus-resources
       driver-is-not-ready
    then
@@ -2185,20 +2180,20 @@
 : write-force  ( adr len -- actual )
    tuck					( actual adr len )
    wrap-ethernet			( actual adr' len' )
-   data-out                             ( actual )
+   " data-out" $call-parent             ( actual )
 ;
 
 : read-force  ( adr len -- actual )
-   got-packet?  0=  if  		( adr len )
+   " got-packet?" $call-parent  0=  if	( adr len )
       2drop  -2  exit
-   then                                 ( adr len [ error | buf actual 0 ] )
+   then                                 ( adr len [ error | buf actual type 0 ] )
 
    if	\ receive error			( adr len )
-      recycle-packet			( adr len )
+      " recycle-packet" $call-parent	( adr len )
       2drop  -1  exit
-   then					( adr len buf actual )
+   then					( adr len buf actual type )
 
-   false to got-data?			( adr len buf actual )
+   false to got-data?			( adr len buf actual type )
    process-rx				( adr len )
 
    got-data?  if			( adr len )
@@ -2207,7 +2202,7 @@
       2drop -2				\ No data
    then					( actual )
 
-   recycle-packet			( actual )
+   " recycle-packet" $call-parent	( actual )
 ;
 
 0 instance value /packet
@@ -2240,7 +2235,7 @@
    " "(01 08 02 04 0b 16 0c 12 18 24 32 04 30 48 e0 ec)"   ( tags-adr tags-len )
    tuck   6 +pkt-data  swap  move                          ( tags-size )
    packet-buf  swap /802.11-header +  6 +   wrap-802.11    ( adr len )
-   data-out
+   " data-out" $call-parent
 ;
 
 : authenticate-reply  ( -- )
@@ -2250,7 +2245,7 @@
    0          4 +pkt-data  le-w!   \ Status - okay
    
    packet-buf  /802.11-header 6 +   wrap-802.11    ( adr len )
-   data-out
+   " data-out" $call-parent
 ;
 
 defer handle-data  ' noop is handle-data
@@ -2297,7 +2292,7 @@
    packet-buf  swap /802.11-header +  6 +  wrap-802.11  ( len padr plen )
    begin  backlog 8 >=  while  process-mgmt-frame  repeat
    backlog 1+ to backlog
-   data-out                                             ( len )
+   " data-out" " $call-parent                           ( len )
    throttle
 ;
 
@@ -2339,7 +2334,7 @@
       0					( adr 0 )
    then					( adr ihandle|0 )
 
-   dup  0=  if  ." Can't open obp-tftp support package" stop-nic abort  then
+   dup  0=  if  ." Can't open obp-tftp support package" abort  then
 					( adr ihandle )
 
    >r
@@ -2348,7 +2343,7 @@
    throw
 ;
 
-: reset  ( -- flag )  reset-nic  ;
+: reset  ( -- flag )  true  ;
 
 : do-disassociate  ( -- )
    " target-mac$" $call-supplicant disassociate

Modified: dev/mmc/sdhci/mv8686/common.fth
==============================================================================
--- dev/mmc/sdhci/mv8686/common.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/mv8686/common.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -28,10 +28,6 @@
 ;
 : /string  ( adr len cnt -- adr+n len-n )  tuck - -rot + swap  ;
 
-create mac-adr 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c, 0 c,
-6 constant /mac-adr
-: mac-adr$  ( -- adr len )  mac-adr /mac-adr  ;
-
 : null$  ( -- adr len )  " "  ;
 
 \ Big endian operations
@@ -58,25 +54,6 @@
 : vldump ( adr len -- )  debug?  if  " ldump" evaluate  else  2drop  then  ;
 : vtype  ( adr len -- )  debug?  if  type cr  else  2drop  then  ;
 
-
-defer link-up?	       ( -- up? )		' true to link-up?
-defer reset-nic        ( -- )			' noop to reset-nic
-defer start-nic        ( -- )			' noop to start-nic
-defer stop-nic         ( -- )			' noop to stop-nic
-
-external
-defer get-mac-address  ( -- adr len )		' mac-adr$ to get-mac-address
-headers
-
-: max-frame-size  ( -- size )  d# 1514  ;
-
-: property-or-abort  ( name$ -- n )
-   2dup get-my-property  if          ( name$ )
-      ." Can't find property " type cr  stop-nic abort
-   then                              ( name$ value$ )
-   2swap 2drop  decode-int  nip nip  ( n )
-;
-
 : find-fw  ( $ -- adr len )
    over " rom:" comp  if
       \ Not a dropin

Modified: dev/mmc/sdhci/mv8686/fw8686.fth
==============================================================================
--- dev/mmc/sdhci/mv8686/fw8686.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/mv8686/fw8686.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -6,6 +6,8 @@
 \ Firmware download data structures
 \ =======================================================================
 
+0 value fw-buf
+
 h# fedc constant FIRMWARE_READY
 
 fw-blksz 2 * 4 - constant /fw-tx
@@ -21,7 +23,7 @@
 0 value fw-tx-len
 0 value dn-retry
 
-: fw-dn-blksz  ( -- blksz )  host-f1-rd-base-0-reg 1 sdio-reg-w@  ;
+: fw-dn-blksz  ( -- blksz )  host-f1-rd-base-0-reg sdio-w@  ;
 : wait-for-fw-dn-blksz  ( -- blksz )
    \ Wait for the first non-zero value
    d# 5000 0  do  fw-dn-blksz dup  ?leave  drop  loop
@@ -41,9 +43,9 @@
    0 to dn-idx  0 to dn-retry
    begin
       fw-len dn-idx - fw-tx-len min		( len )
-      fw-adr dn-idx + outbuf 2 pick move	( len )
-      outbuf over sdio-fw! <>  if
-         4 config-reg 1 sdio-reg!		\ FN1 CFG = write iomem fail
+      fw-adr dn-idx + fw-buf 2 pick move	( len )
+      fw-buf over sdio-fw! <>  if
+         4 config-reg sdio-b!		\ FN1 CFG = write iomem fail
       then
       sdio-poll-dl-ready 0=  if  ." Download fw died" cr true exit  then
       fw-dn-blksz ?dup 0=  if  false exit  then
@@ -73,7 +75,7 @@
    fw-download-ok? 0=  if  true exit  then
 
    mv8787?  if
-      2 config-reg 1 sdio-reg!             \ Host power up
+      2 config-reg sdio-b!             \ Host power up
    then
    false
 ;
@@ -84,14 +86,14 @@
    begin
       sdio-poll-dl-ready 0=  if  true exit  then
       fw-len dn-idx - /fw-tx min		( len )
-      dup outbuf le-l!				( len )
-      fw-adr dn-idx + outbuf 4 + 2 pick move	( len )
+      dup fw-buf le-l!				( len )
+      fw-adr dn-idx + fw-buf 4 + 2 pick move	( len )
       dn-idx over + to dn-idx                   ( len )
-      outbuf swap 4 + sdio-fw! drop		( )
+      fw-buf swap 4 + sdio-fw! drop		( )
    dn-idx fw-len >=  until
    \ Write last EOF data
-   outbuf fw-blksz erase
-   outbuf fw-blksz sdio-fw! drop
+   fw-buf fw-blksz erase
+   fw-buf fw-blksz sdio-fw! drop
    false
 ;
 
@@ -101,12 +103,14 @@
    (download-helper)
 ;
 
-: load-sdio-fw  ( -- error? )
+: free-fw-buf  ( -- )  fw-buf d# 2048 dma-free  ;
+: load-all-fw  ( -- error? )
+   d# 2048 dma-alloc to fw-buf
    helper?  if
       wlan-helper find-fw dup  if  ( adr len )
          2dup download-helper      ( adr len error? )
          -rot free-mem             ( error? )
-	 if  true exit  then       ( )
+	 if  free-fw-buf true exit  then       ( )
       else                         ( adr len )
          2drop                     ( )
       then                         ( )
@@ -118,8 +122,39 @@
    else                     ( adr len )
       2drop  true           ( error? )
    then                     ( error? )
+   free-fw-buf              ( error? )
+;
+
+false value fw-active?
+: set-address  ( function# -- )
+   init-function
+   fw-active? 0=  if
+      load-all-fw  if
+         ." Marvell WLAN module firmware load failed" cr
+         abort
+      then
+      true to fw-active?
+   then
+   mv8787?  if
+      card-rx-unit-reg sdio-b@ to rx-shift
+   then
+;
+: reset-host-bus  ( -- )  " wlan-reset" evaluate  false to fw-active?  ;
+
+0 value open-count
+: open  ( -- flag )
+   set-parent-channel
+   open-count  if
+      true
+   else
+      setup-bus-io  0=
+   then  ( okay? )
+   dup  if  open-count 1+ to open-count  then
+;
+: close  ( -- )
+   open-count 1 =  if  false to fw-active?  then
+   open-count 1-  0 max  to open-count
 ;
-' load-sdio-fw to load-all-fw
 
 \ LICENSE_BEGIN
 \ Copyright (c) 2007 FirmWorks

Modified: dev/mmc/sdhci/mv8686/loadpkg.fth
==============================================================================
--- dev/mmc/sdhci/mv8686/loadpkg.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/mv8686/loadpkg.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -1,7 +1,24 @@
+" sdio" name
 fload ${BP}/dev/mmc/sdhci/mv8686/common.fth	\ Ethernet common variables and routines
 fload ${BP}/dev/mmc/sdhci/mv8686/ring.fth	\ Receive ring management
 fload ${BP}/dev/mmc/sdhci/mv8686/sdio.fth	\ SDIO interface routines
 fload ${BP}/dev/mmc/sdhci/mv8686/mv8686.fth	\ SDIO I/O interface for Marvell 8686
-fload ${BP}/dev/libertas.fth			\ Marvell "Libertas" common code
 fload ${BP}/dev/mmc/sdhci/mv8686/fw8686.fth	\ Marvell firmware download for SDIO
-\ fload ${BP}/dev/mmc/sdhci/mv8686/wlan.fth	\ External interface methods
+
+1 " #size-cells" integer-property
+1 " #address-cells" integer-property
+: decode-unit  ( adr len -- phys )  push-hex $number if  0  then  pop-base  ;
+: encode-unit  ( phys -- adr len )  push-hex (u.) pop-base  ;
+
+new-device
+1 to my-space
+my-space 1 reg
+fload ${BP}/dev/libertas.fth			\ Marvell "Libertas" common code
+finish-device
+
+new-device
+2 to my-space
+my-space 1 reg
+" bluetooth" name
+fload ${BP}/dev/bluetooth/marvell-hci.fth	\ Bluetooth driver
+finish-device

Modified: dev/mmc/sdhci/mv8686/mv8686.fth
==============================================================================
--- dev/mmc/sdhci/mv8686/mv8686.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/mv8686/mv8686.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -4,8 +4,6 @@
 headers
 hex
 
-0 0 encode-bytes  " fullmac" property
-
 \ =======================================================================
 \ Wireless environment variables
 \    wlan-fw             e.g., rom:mv8686.bin, disk:\mv8686.bin
@@ -29,44 +27,69 @@
 2 field >fw-type
 constant /fw-transport
 
-: packet-type  ( adr -- type )
-   >fw-type le-w@  case
-      CMD_TYPE_CMD    of  0  endof
-      CMD_TYPE_DATA   of  1  endof
-      CMD_TYPE_EVENT  of  2  endof
-   endcase
+: bt-packet-len&type  ( adr -- len type )
+   /fw-transport -  dup le-l@  h# ffffff and  /fw-transport -   swap 3 + c@
 ;
 
 : cmd-out  ( adr len -- error? )
-   read-poll
+   /fw-transport negate /string         ( adr' len' )
+   read-poll                            ( len )
    2dup swap >fw-plen le-w!             ( len )
    CMD_TYPE_CMD 2 pick >fw-type le-w!   ( len )
-
-   2dup vdump				( adr len )
    packet-out				( error? )
 ;
 
 : data-out  ( adr len -- )
-   read-poll
+   /fw-transport negate /string         ( adr' len' )
+   read-poll                            ( adr len )
    2dup swap >fw-plen le-w!             ( adr len )
    CMD_TYPE_DATA 2 pick >fw-type le-w!  ( adr len )
    packet-out-async
 ;
 
-: got-packet?  ( -- false | error true | buf len 0 true )
-   read-poll            ( )
+: decode-header  ( buf len -- dadr dlen 8686-type )
+   drop                              ( buf )
+   dup /fw-transport + swap          ( dadr buf )
+   dup >fw-plen le-w@  swap          ( dadr dlen )
+   >fw-type le-w@  case
+      CMD_TYPE_CMD    of  0  endof
+      CMD_TYPE_DATA   of  1  endof
+      CMD_TYPE_EVENT  of  2  endof
+   endcase                           ( dadr dlen 8686-type )
+;
+: got-packet?  ( -- false | error true | buf len type 0 true )
+   read-poll                 ( )
 
-   get-queued?  if  	( buf len )
-      0  true           ( buf len 0 true )
-   else                 ( )
-      false             ( false )
+   get-queued?  if  	     ( buf len )
+      decode-header          ( dadr dlen type )
+      0  true                ( buf len 0 true )
+   else                      ( )
+      false                  ( false )
+   then
+;
+: decode-bt-header  ( buf len -- dadr dlen type )
+   drop                      ( buf )
+   \ SDIO specific header - length: byte[2:0], type: byte[3]
+   \ (HCI_COMMAND = 1, ACL_DATA = 2, SCO_DATA = 3, EVENT=4, 0xFE = Vendor)
+   dup /fw-transport + swap       ( dadr buf )
+   dup le-l@  h# ffffff and swap  ( dadr dlen buf )
+   3 + c@                         ( dadr dlen type )
+;
+
+: got-bt-packet?  ( -- false | dadr dlen type true )
+   read-poll                    ( )
+
+   get-queued?  if  	        ( buf len )
+      decode-bt-header true     ( dadr dlen type true )
+   else                         ( )
+      false                     ( false )
    then
 ;
 : recycle-packet  ( -- )  recycle-queued  ;
 
 0 value rca   \ Relative card address
 
-: set-parent-channel  ( -- )  rca my-unit set-address  ;
+: set-parent-channel  ( -- )  rca my-unit " set-address" $call-parent  ;
 
 : release-bus-resources  ( -- )  drain-queue detach-card  ;
 
@@ -75,20 +98,19 @@
 ;
 
 : make-my-properties  ( -- )
-   get-address dup to rca
+   " get-address" $call-parent dup to rca
    encode-int " assigned-address" property
 ;
 
-: setup-bus-io  ( /inbuf /outbuf -- error? )
-   2drop
+: setup-bus-io  ( -- error? )
    init-queue
    ?attach-card 0=  if  ." Failed to attach card" cr true exit  then
    make-my-properties
-   init-device
    false
 ;
 
-: reset-host-bus  ( -- )  ;
+: alloc-buffer  ( len -- adr )  /fw-transport +  dma-alloc  ;
+: free-buffer  ( adr len -- )  /fw-transport negate /string  dma-free  ;
 
 \ LICENSE_BEGIN
 \ Copyright (c) 2009 FirmWorks

Modified: dev/mmc/sdhci/mv8686/sdio.fth
==============================================================================
--- dev/mmc/sdhci/mv8686/sdio.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/mv8686/sdio.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -4,14 +4,16 @@
 hex
 headers
 
-: sdio-reg@  ( reg# function# -- value )  " sdio-reg@" $call-parent  ;
-: sdio-reg!  ( value reg# function# -- )  " sdio-reg!" $call-parent  ;
-: sdio-reg-w@  ( reg# function# -- w.value )
-   2dup sdio-reg@  -rot      ( low  reg# function# )
-   swap 1+ swap  sdio-reg@   ( low high )
-   bwjoin                    ( w.value )
+0 instance value function#
+0 instance value rx-shift
+
+: sdio-b@  ( reg# function# -- value )  function# " sdio-reg@" $call-parent  ;
+: sdio-b!  ( value reg# function# -- )  function# " sdio-reg!" $call-parent  ;
+: sdio-w@  ( reg# -- w.value )
+   dup sdio-b@        ( reg# low  )
+   swap 1+ sdio-b@    ( low high )
+   bwjoin             ( w.value )
 ;
-: sdio-w@  ( reg# -- w.value )  1 sdio-reg-w@  ;
 
 false instance value multifunction?
 false instance value helper?
@@ -26,7 +28,7 @@
 : default-fw$  ( -- adr len )  fw-name-adr fw-name-len  ;
 : set-default-fw$  ( adr len -- )  to fw-name-len  to fw-name-adr  ;
 
-0 value ioport
+0 instance value ioport
 d# 256 constant blksz			\ Block size for data tx/rx
 d# 256 constant fw-blksz
 
@@ -50,8 +52,8 @@
 h# 6c constant card-misc-cfg-reg
 h# 60 constant card-fw-status0-reg
 \ h# 61 constant card-fw-status1-reg
-\ h# 62 constant card-rx-len-reg
-\ h# 63 constant card-rx-unit-reg
+h# 62 constant card-rx-len-reg
+h# 63 constant card-rx-unit-reg
 h# 78 constant ioport-reg
 
 : ?set-module-property  ( adr len -- )
@@ -67,9 +69,9 @@
 ;
 
 : mv8686-rx-ready?  ( -- len )
-   host-intstatus-reg 1 sdio-reg@
+   host-intstatus-reg sdio-b@
    dup 0=  if  exit  then
-   dup invert 3 and host-intstatus-reg 1 sdio-reg!  \ Clear UP_LD bit
+   dup invert 3 and host-intstatus-reg sdio-b!  \ Clear UP_LD bit
    1 and  if
       sdio-fw-status@
    else
@@ -106,15 +108,32 @@
        2drop
     then
 ;
+
 0 instance value rx-port#
 0 instance value wr-bitmap
 0 instance value rd-bitmap
+: bt-update-bitmaps  ( -- len )
+   card-status-reg sdio-b@
+   dup  1 and  if  1 to wr-bitmap  then
+   2 and   if  1 to rd-bitmap  then
+;
+: mv8787-bt-rx-ready?  ( -- len )
+   rd-bitmap  if                                ( )
+      0 to rd-bitmap                            ( )
+      card-rx-len-reg sdio-b@  rx-shift lshift  ( len )
+      \ XXX round up to multiple of blocksize ?  Maybe sdhci already does it
+   else                                         ( )
+      bt-update-bitmaps                         ( )
+      0                                         ( len )
+   then                                         ( len )
+;
+
 : update-bitmaps  ( -- )
-   host-intstatus-reg 1 sdio-reg@
+   host-intstatus-reg sdio-b@
    dup 2 and  if  wr-bitmap-reg sdio-w@ to wr-bitmap  then
    1 and  if  rd-bitmap-reg sdio-w@ to rd-bitmap  then
 ;
-: mv8787-rx-ready?  ( -- len )
+: mv8787-wlan-rx-ready?  ( -- len )
    rd-bitmap  dup  if          ( bitmap )
       d# 16 0  do              ( bitmap )
 	 dup 1 and  if         ( bitmap )
@@ -129,6 +148,9 @@
       update-bitmaps           ( 0 )
    then
 ;
+: mv8787-rx-ready?  ( -- len )
+   function# 1 =  if  mv8787-wlan-rx-ready?  else  mv8787-bt-rx-ready?  then
+;
 
 : mv8787-get-ctrl-port  ( -- n )
    0
@@ -168,8 +190,8 @@
     h# 6c to card-misc-cfg-reg
     h# 60 to card-fw-status0-reg
 \   h# 61 to card-fw-status1-reg
-\   h# 62 to card-rx-len-reg
-\   h# 63 to card-rx-unit-reg
+    h# 62 to card-rx-len-reg
+    h# 63 to card-rx-unit-reg
     h# 78 to ioport-reg
     d# 256 to blksz
     d# 256 to fw-blksz
@@ -183,6 +205,8 @@
     true to multifunction?
 ;
 
+: set-block-size  ( n -- )  to blksz  ;
+
 : set-version  ( -- error? )
    " sdio-card-id" $call-parent  case
       h# 02df9103  of  use-mv8686 false  endof
@@ -195,14 +219,13 @@
 
 : roundup-blksz  ( n -- n' )  blksz 1- + blksz / blksz *  ;
 
-: set-address  ( rca slot -- )  " set-address" $call-parent  ;
 : get-address  ( -- rca )       " get-address" $call-parent  ;
 : attach-card  ( -- ok?  )  " attach-sdio-card" $call-parent  ;
 : detach-card  ( -- )       " detach-sdio-card" $call-parent  ;
 
 : sdio-poll-dl-ready  ( -- ready? )
    false d# 100 0  do
-      card-status-reg 1 sdio-reg@
+      card-status-reg sdio-b@
       h# 9 tuck and =  if  drop true leave  then
       d# 100 usec
    loop
@@ -210,47 +233,51 @@
 ;
 
 : sdio-fw!  ( adr len -- actual )
-   >r >r ioport 1 true r> r> fw-blksz false " r/w-ioblocks" $call-parent
+   >r >r ioport function# true r> r> fw-blksz false " r/w-ioblocks" $call-parent
 ;
 
-: init-device  ( -- )
-   ioport-reg 3 bounds  do  i 1 sdio-reg@  loop		\ Read the IO port
-   0 bljoin to ioport
+: init-function  ( function# -- )
+   0 to function#                ( function# )
 
-   7 0 sdio-reg@  h# 20 or  7 0 sdio-reg!	\ Enable async interrupt mode
+   1 over lshift      2 sdio-b!	 ( function# ) \ Enable IO function
+   1 over lshift 1 or 4 sdio-b!	 ( function# ) \ Enable interrupts for function and card
 
-   2 2 0 sdio-reg!	\ Enable IO function 1 (2 = 1 << 1)
-   3 4 0 sdio-reg!	\ Enable interrupts (1) for function 1 (1 << 1)
+   7 sdio-b@  h# 20 or  7 sdio-b!  ( function# )	\ Enable async interrupt mode
+
+   to function#
+
+   ioport-reg 3 bounds  do  i sdio-b@  loop		\ Read the IO port
+   0 bljoin to ioport
 
    mv8787?  if
       \ Set host interrupt reset to "read to clear"
-      host-int-rsr-reg 1 sdio-reg@  h# 3f or  host-int-rsr-reg 1 sdio-reg!
+      host-int-rsr-reg sdio-b@  h# 3f or  host-int-rsr-reg sdio-b!
 
       \ Set Dnld/upld to "auto reset"
-      card-misc-cfg-reg 1 sdio-reg@   h# 10 or  card-misc-cfg-reg 1 sdio-reg!
+      card-misc-cfg-reg sdio-b@   h# 10 or  card-misc-cfg-reg sdio-b!
    then
    \ Newer revisions of the 8787 firmware empirically require that this
    \ be enabled early, before firmware download.  Older versions, and
    \ 8686 firmware, appear to be content with it either here or after
    \ firmware startup.
-   3  host-int-mask-reg 1 sdio-reg!  \ Enable upload (1) and download (2)
+   3  host-int-mask-reg sdio-b!  \ Enable upload (1) and download (2)
 ;
 
 : sdio-blocks@  ( adr len -- actual )
    >r >r
-   rx-port# ioport +  1 true  r> r>  blksz true  " r/w-ioblocks" $call-parent  ( actual )
+   rx-port# ioport +  function# true  r> r>  blksz true  " r/w-ioblocks" $call-parent  ( actual )
 ;
 
 \ : sdio-blocks!  ( adr len -- actual )
-\    >r >r x-get-write-port ioport + 1 true r> r> blksz false " r/w-ioblocks" $call-parent
+\    >r >r x-get-write-port ioport + function# true r> r> blksz false " r/w-ioblocks" $call-parent
 \ ;
 
-\ 1 is the function number
 : (sdio-blocks!)  ( adr len port# -- actual )
-   ioport +  -rot    ( port#  adr len )
-   1 true  2swap     ( port#  function# inc?  adr len )
+   ioport +  -rot          ( port#  adr len )
+   function# true  2swap   ( port#  function# inc?  adr len )
    blksz false " r/w-ioblocks" $call-parent
 ;
+: sdio-blocks!  ( adr len -- actual )  0 (sdio-blocks!)  ;
 
 \ 0 is the control port number
 : packet-out  ( adr len -- error? )  tuck  get-ctrl-port  (sdio-blocks!)  <>  ;

Modified: dev/mmc/sdhci/sdhci.fth
==============================================================================
--- dev/mmc/sdhci/sdhci.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/mmc/sdhci/sdhci.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -1090,7 +1090,7 @@
       cis at +                    ( offset' tuple-code )
       dup h# ff <>
    while                       ( offset tuple-code )
-      \ Another potentially interesting tuples si h# 15 from which
+      \ Another potentially interesting tuple is h# 15 from which
       \ you can get strings naming the product.
       case
 	 h# 20  of  parse-funcid  endof

Modified: dev/usb2/device/wlan/fw8388.fth
==============================================================================
--- dev/usb2/device/wlan/fw8388.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/usb2/device/wlan/fw8388.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -84,11 +84,11 @@
 
 : wait-cmd-fw-dl-ack  ( -- acked? )
    d# 100 0  do			( )
-      got-packet?  if		( error | buf len 0 )
+      got-packet?  if		( error | buf len type 0 )
          if			( )
             false		( acked? )
-         else			( buf len )
-            cmd-fw-dl-ok?	( acked? )
+         else			( buf len type )
+            drop cmd-fw-dl-ok?	( acked? )
          then			( acked? )
          recycle-packet         ( acked? )
          unloop exit
@@ -99,12 +99,12 @@
 ;
 
 : download-fw-init  ( -- )
-   outbuf /boot-cmd erase
-   boot-magic outbuf >boot-magic le-l!
-   cmd-fw-dl  outbuf >boot-cmd   c!
+   fw-buf /boot-cmd erase
+   boot-magic fw-buf >boot-magic le-l!
+   cmd-fw-dl  fw-buf >boot-cmd   c!
 
    5 0  do
-      outbuf /boot-cmd packet-out drop
+      fw-buf /boot-cmd packet-out drop
       wait-cmd-fw-dl-ack  if  leave  then
    loop
 ;
@@ -118,8 +118,8 @@
 
 : wait-fw-dl-ack  ( -- )
    d# 500 0  do				( )
-      got-packet?  if			( error | buf len 0 )
-         0= if  process-dl-resp  then	( )
+      got-packet?  if			( error | buf len tupe 0 )
+         0= if  drop process-dl-resp  then	( )
          recycle-packet			( )
          leave
       then				( )
@@ -130,11 +130,11 @@
 : (download-fw)  ( adr len -- )
    bounds  begin		( end start )
       dl-seq++				\ Increment sequence number
-      dup outbuf /dl-header move	\ Move header to outbuf
-      dl-seq outbuf >dl-seq le-l!	\ Add sequence number to outbuf
-      dup /dl-header + outbuf >dl-data 2 pick >dl-len le-l@ dup >r move
-					\ Move payload to outbuf
-      outbuf r@ /dl-header + 4 + packet-out drop
+      dup fw-buf /dl-header move	\ Move header to outbuf
+      dl-seq fw-buf >dl-seq le-l!	\ Add sequence number to outbuf
+      dup /dl-header + fw-buf >dl-data 2 pick >dl-len le-l@ dup >r move
+					\ Move payload to fw-buf
+      fw-buf r@ /dl-header + 4 + packet-out drop
 					\ Send command
       wait-fw-dl-ack			\ Wait for ACK
       r> + /dl-header +			\ Advance pointer
@@ -179,13 +179,13 @@
    false
 ;
 
-: load-8388-fw  ( -- error? )
+: load-all-fw  ( -- error? )
+   d# 2048 dma-alloc to fw-buf   
    wlan-fw find-fw  ( adr len )
    dup  if  download-fw  else  2drop true  then
+   fw-buf d# 2048 dma-free
 ;
 
-' load-8388-fw to load-all-fw
-
 \ LICENSE_BEGIN
 \ Copyright (c) 2007 FirmWorks
 \ 

Modified: dev/usb2/device/wlan/usb8388.bth
==============================================================================
--- dev/usb2/device/wlan/usb8388.bth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/usb2/device/wlan/usb8388.bth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -13,9 +13,9 @@
 fload ${BP}/dev/usb2/device/common.fth		\ USB device driver common routines
 fload ${BP}/dev/usb2/device/wlan/common.fth	\ Ethernet common variables and routines
 fload ${BP}/dev/usb2/device/wlan/usb8388.fth	\ USB I/O interface for Marvell 8388
+fload ${BP}/dev/usb2/device/wlan/fw8388.fth	\ Marvell firmware download for USB
 fload ${BP}/dev/libertas.fth			\ Marvell "Libertas" common code
 \ fload ${BP}/dev/usb2/device/wlan/wlan.fth	\ External interface methods
-fload ${BP}/dev/usb2/device/wlan/fw8388.fth	\ Marvell firmware download for USB
 
 end0
 

Modified: dev/usb2/device/wlan/usb8388.fth
==============================================================================
--- dev/usb2/device/wlan/usb8388.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/usb2/device/wlan/usb8388.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -42,34 +42,45 @@
 h# beef.face constant TYPE_USB_INDICATION
 
 : cmd-out  ( adr len -- error? )
+   /fw-transport negate /string                 ( adr' len' )
    TYPE_USB_REQUEST 2 pick >fw-transport le-l!	( adr len )
    2dup vdump 					( adr len )
    packet-out					( error? )
 ;
 
 : data-out  ( adr len -- )
+   /fw-transport negate /string                 ( adr' len' )
    TYPE_USB_DATA 2 pick >fw-transport le-l!	( adr len )
    packet-out-async
 ;
 
-\ Translate the USB/8388 type codes into more abstract codes, which
-\ happen to be the codes used by the 8686
-: packet-type  ( adr -- type )
-   >fw-transport le-l@  case
+\ Translate the USB/8388 type codes into uniform code numbers
+: decode-header  ( buf len -- dadr dlen type )
+   over le-l@ >r                   ( buf len  r: usb-type )
+   /fw-transport /string           ( dadr dlen  r: usb-type )
+   r>  case                        
       TYPE_USB_REQUEST     of  0  endof
       TYPE_USB_DATA        of  1  endof
       TYPE_USB_INDICATION  of  2  endof
-   endcase
+   endcase                         ( dadr dlen type )
 ;
 
-: got-packet?  ( -- false | error true | buf len 0 true )  bulk-in-ready?  ;
+: got-packet?  ( -- false | error true | buf len type 0 true )
+   bulk-in-ready?  if           ( error | buf len 0 )
+      ?dup 0=   if              ( dadr dlen )
+         decode-header  0       ( dadr dlen type 0 )
+      then                      ( error | buf len 0 )
+   else                         ( )
+      false                     ( false )
+   then    ( false | error true | buf len 0 true )
+;
 : recycle-packet  ( -- )  restart-bulk-in  ;
 
 : end-out-ring  ( -- )  " end-out-ring" $call-parent  ;
 
 : set-parent-channel  ( -- )  set-device  device set-target  ;
 
-: setup-bus-io  ( /inbuf /outbuf -- error? )
+: setup-bus-io  ( -- error? )
    reset?  if
       configuration set-config  if
          ." Failed to set USB configuration for wireless" cr
@@ -77,14 +88,14 @@
       then
       bulk-in-pipe bulk-out-pipe reset-bulk-toggles
    then
-   4 bulk-out-pipe " begin-out-ring" $call-parent   ( /inbuf )
-   h# 40 bulk-in-pipe  " begin-in-ring"  $call-parent
+   d# 2048     4 bulk-out-pipe " begin-out-ring" $call-parent
+   d# 2048 h# 40 bulk-in-pipe  " begin-in-ring"  $call-parent
    false
 ;
 
 : release-bus-resources  ( -- )  end-bulk-in end-out-ring  ;
 
-: reset-host-bus  ( -- )  ;
+: reset-host-bus  ( -- )  " wlan-reset" evaluate  ;
 
 0 value vid
 0 value pid
@@ -97,6 +108,8 @@
 ;
 
 init
+XXX need open and close methods and open needs to call setup-bus-io
+XXX need alloc-buffer and free-buffer method
 
 \ LICENSE_BEGIN
 \ Copyright (c) 2009 FirmWorks

Modified: dev/usb2/device/wlan/wlan.fth
==============================================================================
--- dev/usb2/device/wlan/wlan.fth	Fri Feb 22 07:11:28 2013	(r3568)
+++ dev/usb2/device/wlan/wlan.fth	Mon Feb 25 09:34:36 2013	(r3569)
@@ -124,14 +124,14 @@
 : read-force  ( adr len -- actual )
    got-packet?  0=  if  		( adr len )
       2drop  -2  exit
-   then                                 ( adr len [ error | buf actual 0 ] )
+   then                                 ( adr len [ error | buf actual type 0 ] )
 
    if	\ receive error			( adr len )
       recycle-packet			( adr len )
       2drop  -1  exit
-   then					( adr len buf actual )
+   then					( adr len buf actual type )
 
-   false to got-data?			( adr len buf actual )
+   false to got-data?			( adr len buf actual type )
    process-rx				( adr len )
    recycle-packet			( adr len )
 



More information about the openfirmware mailing list