From 9930418fd77780cd00176fe0f82bb1ee3ba83ff6 Mon Sep 17 00:00:00 2001 From: Siarzhuk Zharski Date: Tue, 1 May 2012 19:54:01 +0200 Subject: [PATCH] Fix the device lookup algorithm * Fix the device lookup algorithm - sync with correct version used in usb_asix; * Small code style fix. --- .../network/usb_davicom/DavicomDevice.h | 12 +++--- .../drivers/network/usb_davicom/Driver.cpp | 37 ++++++++++--------- .../drivers/network/usb_davicom/Driver.h | 2 +- 3 files changed, 25 insertions(+), 26 deletions(-) diff --git a/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h b/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h index d8441bd11e..4d94f5fb75 100644 --- a/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h +++ b/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h @@ -63,14 +63,12 @@ struct DM9601NotifyData { struct DeviceInfo { - union Id { - uint16 fIds[2]; - uint32 fKey; - } fId; + uint16 fIds[2]; + const char* fName; - inline uint16 VendorId() { return fId.fIds[0]; } - inline uint16 ProductId() { return fId.fIds[1]; } - inline uint32 Key() { return fId.fKey; } + inline uint16 VendorId() { return fIds[0]; } + inline uint16 ProductId() { return fIds[1]; } + inline uint32 Key() { return fIds[0] << 16 | fIds[1]; } }; class DavicomDevice { diff --git a/src/add-ons/kernel/drivers/network/usb_davicom/Driver.cpp b/src/add-ons/kernel/drivers/network/usb_davicom/Driver.cpp index bdb2caede4..1e85b40af7 100644 --- a/src/add-ons/kernel/drivers/network/usb_davicom/Driver.cpp +++ b/src/add-ons/kernel/drivers/network/usb_davicom/Driver.cpp @@ -33,16 +33,16 @@ mutex gDriverLock; // IMPORTANT: keep entries sorted by ids to let the // binary search lookup procedure work correctly !!! DeviceInfo gSupportedDevices[] = { - { { { 0x01e1, 0x9601 } }, "Noname DM9601" }, - { { { 0x07aa, 0x9601 } }, "Corega FEther USB-TXC" }, - { { { 0x0a46, 0x0268 } }, "ShanTou ST268 USB NIC" }, - { { { 0x0a46, 0x6688 } }, "ZT6688 USB NIC" }, - { { { 0x0a46, 0x8515 } }, "ADMtek ADM8515 USB NIC" }, - { { { 0x0a46, 0x9000 } }, "DM9000E" }, - { { { 0x0a46, 0x9601 } }, "Davicom DM9601" }, - { { { 0x0a47, 0x9601 } }, "Hirose USB-100" }, - { { { 0x0fe6, 0x8101 } }, "Sunrising SR9600" }, - { { { 0x0fe6, 0x9700 } }, "Kontron DM9601" } + { { 0x01e1, 0x9601 }, "Noname DM9601" }, + { { 0x07aa, 0x9601 }, "Corega FEther USB-TXC" }, + { { 0x0a46, 0x0268 }, "ShanTou ST268 USB NIC" }, + { { 0x0a46, 0x6688 }, "ZT6688 USB NIC" }, + { { 0x0a46, 0x8515 }, "ADMtek ADM8515 USB NIC" }, + { { 0x0a46, 0x9000 }, "DM9000E" }, + { { 0x0a46, 0x9601 }, "Davicom DM9601" }, + { { 0x0a47, 0x9601 }, "Hirose USB-100" }, + { { 0x0fe6, 0x8101 }, "Sunrising SR9600" }, + { { 0x0fe6, 0x9700 }, "Kontron DM9601" } }; @@ -57,22 +57,23 @@ lookup_and_create_device(usb_device device) return NULL; } - TRACE("trying %#06x:%#06x.\n", + TRACE("trying %#06x:%#06x.\n", deviceDescriptor->vendor_id, deviceDescriptor->product_id); - + // use binary search to lookup device in table - DeviceInfo::Id id = { { deviceDescriptor->vendor_id, - deviceDescriptor->product_id } }; + uint32 id = deviceDescriptor->vendor_id << 16 + | deviceDescriptor->product_id; int left = -1; int right = _countof(gSupportedDevices); - while((right - left) > 1) { + while ((right - left) > 1) { int i = (left + right) / 2; - ((gSupportedDevices[i].Key() < id.fKey) ? left : right) = i; + ((gSupportedDevices[i].Key() < id) ? left : right) = i; } - if(gSupportedDevices[right].Key() == id.fKey) + if (gSupportedDevices[right].Key() == id) return new DavicomDevice(device, gSupportedDevices[right]); + TRACE_ALWAYS("Search for %#x failed %d-%d.\n", id, left, right); return NULL; } @@ -194,7 +195,7 @@ init_driver() const size_t count = _countof(gSupportedDevices); static usb_support_descriptor sDescriptors[count] = {{ 0 }}; - for(size_t i = 0; i < count; i++) { + for (size_t i = 0; i < count; i++) { sDescriptors[i].vendor = gSupportedDevices[i].VendorId(); sDescriptors[i].product = gSupportedDevices[i].ProductId(); } diff --git a/src/add-ons/kernel/drivers/network/usb_davicom/Driver.h b/src/add-ons/kernel/drivers/network/usb_davicom/Driver.h index 0b4be0213e..7fe15ed4a7 100644 --- a/src/add-ons/kernel/drivers/network/usb_davicom/Driver.h +++ b/src/add-ons/kernel/drivers/network/usb_davicom/Driver.h @@ -24,7 +24,7 @@ #define MAX_DEVICES 8 -const char* const kVersion = "ver.0.9.4"; +const char* const kVersion = "ver.0.9.5"; extern usb_module_info *gUSBModule;