Martin Pieuchot <[email protected]> writes:

> On 15/04/15(Wed) 10:46, attila wrote:
>> Martin Pieuchot <[email protected]> writes:
>> 
>> > On 14/04/15(Tue) 15:22, attila wrote:
>> >> Martin Pieuchot <[email protected]> writes:
>> >> >> 
>> >> >> static const struct usb_devno ualea_devs[] = {
>> >> >>        { USB_VENDOR_ARANEUS,   USB_PRODUCT_ARANEUS_ALEA }
>> >> >> };
>> >> >
>> >> > Is it possible to match your device based on the content of the device
>> >> > descriptor instead of whitelisting IDs?  Whitelisting means that if the
>> >> > company produce a compatible device with a new ID we'll need to modify
>> >> > the driver.
>> >> >
>> >> 
>> >> Sadly, I don't think it is possible... you mean by looking at
>> >> bDeviceClass/bDeviceSubClass/bDeviceProtocol?  He only gives me zeroes
>> >> [...]
>> >> Perhaps I am misunderstanding; is there something else in there I
>> >> could/should match on?  I've changed the attach routine in the updated
>> >> version to check vendor/product/iface, at least.
>> >
>> > I was thinking at bInterfaceClass and bInterfaceProtocol but when they
>> > are both to "vendor defined" (255), matching against the ID is the right
>> > thing to do. 
>> >
>> >> I looked and it appears that M_ZERO is used when allocating the memory
>> >> for all of these structures, so I take it that explicit zeroing of
>> >> things when tearing down is neither required nor desired?  I removed
>> >> this kind of thing from ualea.c because it looked like it wasn't
>> >> necessary.
>> >
>> > That's right.
>> >
>> >> I'm attaching the updated driver.
>> >> 
>> >> Thank you for the critique.  I suppose I need to write a man page for
>> >> this as well... working on it.
>> >
>> > Perfect, I'll put it in tree together with your driver :)
>> >
>> 
>> Man page attached.  I am also attaching an updated copy of the driver
>> (only copyright changed).
>> 
>> Thanks so much for your help.  I look forward to contributing more.
>
> Committed thanks.  I removed some unneeded headers and applied jmc@'s
> tweak.
>
> In the future I'd suggest you to send unified diff against the CVS tree,
> it's easier to apply & test!

After this was committed I received a critique of the driver from the
person behind the Alea II (Andreas Gustafsson) who made a few pretty
good points.  He felt trying to pull all the entropy off of the device
that would theoretically be available every second was a losing
strategy for several reasons.  Most importantly I ended up calling
add_true_randomness() in bursts of 3200 calls every trip through
ualea_task() whereas rnd_event_space[] in rnd.c only has 64 entries on
a 32bit machine (42 on amd64); this almost surely means that the vast
majority of my calls are no-ops... not so useful, it appears.

The attached diff cranks the buffer size way down and now we call
add_true_randomness() 32 times every 100ms.  When I crank ALEA_MSECS
below 100ms I start to notice the load increases on the machine with
an Alea II plugged in.  I guess this is because the stuff that happens
in ualea_task() happens in the context of a process and that process
always appears to be runnable when ALEA_MSECS is e.g. 10ms.  I crank
the read timeout up to 5000ms because that's what he recommends in his
sample code; under normal circumstances we never time out.

The diff also explicitly looks for endpoint #1 because that's the
endpoint that Andreas says to use, not necc. the first one that I
find; as it turns out now the first one I find is the right one but
just to be safe it's better to check explicitly.

Maybe now this is closer to production-worthy.  All feedback and
comments most welcome.

>
> Cheers,
> Martin

Pax, -A
--
[email protected] | http://trac.haqistan.net/~attila
keyid E6CC1EDB | 4D91 1B98 A210 1D71 2A0E  AC29 9677 D0A6 E6CC 1EDB

Index: ualea.c
===================================================================
RCS file: /cvs/src/sys/dev/usb/ualea.c,v
retrieving revision 1.1
diff -u -p -r1.1 ualea.c
--- ualea.c     16 Apr 2015 08:55:21 -0000      1.1
+++ ualea.c     16 Apr 2015 20:34:59 -0000
@@ -36,9 +36,10 @@
 #include <dev/rndvar.h>
 
 #define ALEA_IFACE             0
+#define ALEA_ENDPOINT          1
 #define ALEA_MSECS             100
-#define ALEA_READ_TIMEOUT      1000
-#define ALEA_BUFSIZ            ((1024/8)*100)  /* 100 kbits */
+#define ALEA_READ_TIMEOUT      5000
+#define ALEA_BUFSIZ            128
 
 #define DEVNAME(_sc) ((_sc)->sc_dev.dv_xname)
 
@@ -101,7 +102,8 @@ ualea_attach(struct device *parent, stru
                        return;
                }
                if (UE_GET_DIR(ed->bEndpointAddress) == UE_DIR_IN &&
-                   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK) {
+                   UE_GET_XFERTYPE(ed->bmAttributes) == UE_BULK &&
+                   UE_GET_ADDR(ed->bEndpointAddress) == ALEA_ENDPOINT) {
                        ep_ibulk = ed->bEndpointAddress;
                        break;
                }

Reply via email to