[openfirmware] r1378 - dev/usb2/device/net
svn at openfirmware.info
svn at openfirmware.info
Fri Sep 25 03:44:24 CEST 2009
Author: wmb
Date: 2009-09-25 03:44:24 +0200 (Fri, 25 Sep 2009)
New Revision: 1378
Modified:
dev/usb2/device/net/ax8817x.fth
dev/usb2/device/net/common.fth
dev/usb2/device/net/ethernet.fth
dev/usb2/device/net/pegasus.fth
Log:
USB Ethernet - improvements in startup reliability, especially for ASIX chips.
Modified: dev/usb2/device/net/ax8817x.fth
===================================================================
--- dev/usb2/device/net/ax8817x.fth 2009-09-24 10:22:16 UTC (rev 1377)
+++ dev/usb2/device/net/ax8817x.fth 2009-09-25 01:44:24 UTC (rev 1378)
@@ -161,7 +161,9 @@
\ But, I've seen loop count as high as d# 1020.
\ I increase the loop count in case the partner is slow in negotiating.
\ And if there's no connection at all, let's not wait too long.
- d# 2000 0 do ax-link-up? ?leave 1 ms loop
+ ax-mii-sw
+ d# 2000 0 do 1 ax-mii@ 4 and ?leave 1 ms loop
+ ax-mii-hw
;
: select-phy ( -- )
@@ -204,6 +206,7 @@
: rx-ctl! ( n -- ) h# 10 control! ; \ AX_CMD_WRITE_RX_CTL
: ax-start-nic ( -- )
+ ax-auto-neg-wait
h# 8c my-args " promiscuous" $= if 1 or then rx-ctl!
;
: ax-stop-nic ( -- ) 0 rx-ctl! ;
@@ -219,7 +222,6 @@
ax-get-mac-address 2drop
ax-set-ipg
ax-init-mii
- ax-auto-neg-wait
ax-start-nic
;
@@ -229,6 +231,10 @@
['] ax-start-nic to start-nic
['] ax-stop-nic to stop-nic
['] ax-get-mac-address to get-mac-address
+ ['] ax-mii@ to mii@
+ ['] ax-mii! to mii!
+ ['] ax-mii-sw to mii{
+ ['] ax-mii-hw to }mii
vid h# 2001 = pid h# 1a00 = and if h# 009f.9d9f to ax-gpio then
vid h# 07b8 = pid h# 420a = and if h# 001f.1d1f to ax-gpio then
d# 2048 to /inbuf
Modified: dev/usb2/device/net/common.fth
===================================================================
--- dev/usb2/device/net/common.fth 2009-09-24 10:22:16 UTC (rev 1377)
+++ dev/usb2/device/net/common.fth 2009-09-25 01:44:24 UTC (rev 1378)
@@ -21,6 +21,10 @@
defer reset-nic ( -- ) ' noop to reset-nic
defer start-nic ( -- ) ' noop to start-nic
defer stop-nic ( -- ) ' noop to stop-nic
+defer mii{ ( -- ) ' noop to mii{ \ Acquire
+defer }mii ( -- ) ' noop to }mii \ Release
+defer mii@ ( reg -- val ) ' noop to mii@
+defer mii! ( val reg -- ) ' drop to mii@
external
defer get-mac-address ( -- adr len ) ' mac-adr$ to get-mac-address
Modified: dev/usb2/device/net/ethernet.fth
===================================================================
--- dev/usb2/device/net/ethernet.fth 2009-09-24 10:22:16 UTC (rev 1377)
+++ dev/usb2/device/net/ethernet.fth 2009-09-25 01:44:24 UTC (rev 1378)
@@ -27,43 +27,21 @@
then
;
-: init-net ( -- )
- init-nic
- mac-adr$ encode-bytes " local-mac-address" property ( )
+: stop-net ( -- )
+ stop-nic
+ end-bulk-in
+ free-buf
;
-external
-
-: close ( -- )
- opencount @ 1- 0 max opencount !
- opencount @ 0= if
- end-bulk-in
- stop-nic
- free-buf
- then
+: loopback{ ( -- )
+ mii{ 0 mii@ h# 4000 or 0 mii! }mii
;
-
-: open ( -- ok? )
- my-args " debug" $= if debug-on then
- device set-target
- opencount @ 0= if
- first-open? if
- init-net
- false to first-open?
- ?make-mac-address-property
- then
- link-up? 0= if
- ." Network not connected." cr
- false exit
- then
- init-buf
- start-nic
- inbuf /inbuf bulk-in-pipe begin-bulk-in
- then
- opencount @ 1+ opencount !
- true
+: }loopback ( -- )
+ mii{ 0 mii@ h# 4000 invert and 0 mii! }mii
;
+external
+
: copy-packet ( adr len -- len' )
dup outbuf le-w! tuck outbuf 2 + swap move 2 +
;
@@ -175,6 +153,80 @@
headers
+\ This loopback test is a reliability improvement. The AX88772,
+\ and perhaps other chips, sometimes loses the first received
+\ packet. That's annoying, as the first packet is often a
+\ reply that we care about, thus causing a timeout and retry.
+\ We work around that by sending ourselves a few loopback packets
+\ until we receive one. In most cases, the first loopback packet
+\ is received correctly, and if not, the second one is okay.
+\ We try 5 times just to be safe, exiting as soon as we "win".
+
+0 value scratch-buf
+: clear-rx ( -- )
+ d# 200 0 do
+ scratch-buf d# 2000 read -2 = ?leave
+ loop
+;
+
+create test-packet
+ h# ff c, h# ff c, h# ff c, h# ff c, h# ff c, h# ff c, \ Dst - broadcast
+ h# 01 c, h# 02 c, h# 03 c, h# 04 c, h# 05 c, h# 06 c, \ Src - junk
+ h# 00 c, h# 00 c, \ Type - junk
+ here h# 40 dup allot erase \ Junk data
+here test-packet - constant /tp
+
+: try-loopback? ( -- okay? )
+ test-packet /tp write /tp <> if false exit then
+ 2 ms
+ scratch-buf d# 2000 read /tp =
+;
+: loopback-test ( -- )
+ d# 2000 alloc-mem to scratch-buf
+ loopback{
+ clear-rx
+ 5 0 do try-loopback? ?leave loop
+ }loopback
+ scratch-buf d# 2000 free-mem
+;
+
+external
+
+: close ( -- )
+ opencount @ 1- 0 max opencount !
+ opencount @ 0= if stop-net then
+;
+
+: open ( -- ok? )
+ my-args " debug" $= if debug-on then
+ device set-target
+ opencount @ 0= if
+ init-buf
+ inbuf /inbuf bulk-in-pipe begin-bulk-in
+
+ first-open? if
+ false to first-open?
+ init-nic
+ mac-adr$ encode-bytes " local-mac-address" property ( )
+ ?make-mac-address-property
+ else
+ start-nic
+ then
+
+ link-up? 0= if
+ ." Network not connected." cr
+ stop-net
+ false exit
+ then
+
+ loopback-test
+ then
+ opencount @ 1+ opencount !
+ true
+;
+
+headers
+
: init ( -- )
init
device set-target
Modified: dev/usb2/device/net/pegasus.fth
===================================================================
--- dev/usb2/device/net/pegasus.fth 2009-09-24 10:22:16 UTC (rev 1377)
+++ dev/usb2/device/net/pegasus.fth 2009-09-25 01:44:24 UTC (rev 1378)
@@ -115,7 +115,7 @@
: pg-sync-link-status ( -- )
\ Delayed loop until link-up is detected.
- 5 0 do pg-link-up? if unloop exit then d# 1000 ms loop
+ d# 500 0 do pg-link-up? if unloop exit then d# 10 ms loop
;
: pg-init-nic ( -- )
@@ -129,6 +129,7 @@
;
: pg-start-nic ( -- )
+ pg-sync-link-status
\ force 100Mbps full-duplex
h# 0130c9 ec0 3 pg-write-reg
;
@@ -151,6 +152,8 @@
['] pg-stop-nic to stop-nic
['] pg-get-mac-address to get-mac-address
['] pg-unwrap-msg to unwrap-msg
+ ['] pg-mii@ to mii@
+ ['] pg-mii! to mii!
;
: init ( -- ) init vid pid pegasus? if init-pegasus then ;
More information about the openfirmware
mailing list