Fix the device lookup algorithm

* Fix the device lookup algorithm - sync with correct version used in usb_asix;
* Small code style fix.
This commit is contained in:
Siarzhuk Zharski
2012-05-01 20:32:44 +02:00
parent aa19448875
commit 9930418fd7
3 changed files with 25 additions and 26 deletions
@@ -63,14 +63,12 @@ struct DM9601NotifyData {
struct DeviceInfo { struct DeviceInfo {
union Id {
uint16 fIds[2]; uint16 fIds[2];
uint32 fKey;
} fId;
const char* fName; const char* fName;
inline uint16 VendorId() { return fId.fIds[0]; } inline uint16 VendorId() { return fIds[0]; }
inline uint16 ProductId() { return fId.fIds[1]; } inline uint16 ProductId() { return fIds[1]; }
inline uint32 Key() { return fId.fKey; } inline uint32 Key() { return fIds[0] << 16 | fIds[1]; }
}; };
class DavicomDevice { class DavicomDevice {
@@ -33,16 +33,16 @@ mutex gDriverLock;
// IMPORTANT: keep entries sorted by ids to let the // IMPORTANT: keep entries sorted by ids to let the
// binary search lookup procedure work correctly !!! // binary search lookup procedure work correctly !!!
DeviceInfo gSupportedDevices[] = { DeviceInfo gSupportedDevices[] = {
{ { { 0x01e1, 0x9601 } }, "Noname DM9601" }, { { 0x01e1, 0x9601 }, "Noname DM9601" },
{ { { 0x07aa, 0x9601 } }, "Corega FEther USB-TXC" }, { { 0x07aa, 0x9601 }, "Corega FEther USB-TXC" },
{ { { 0x0a46, 0x0268 } }, "ShanTou ST268 USB NIC" }, { { 0x0a46, 0x0268 }, "ShanTou ST268 USB NIC" },
{ { { 0x0a46, 0x6688 } }, "ZT6688 USB NIC" }, { { 0x0a46, 0x6688 }, "ZT6688 USB NIC" },
{ { { 0x0a46, 0x8515 } }, "ADMtek ADM8515 USB NIC" }, { { 0x0a46, 0x8515 }, "ADMtek ADM8515 USB NIC" },
{ { { 0x0a46, 0x9000 } }, "DM9000E" }, { { 0x0a46, 0x9000 }, "DM9000E" },
{ { { 0x0a46, 0x9601 } }, "Davicom DM9601" }, { { 0x0a46, 0x9601 }, "Davicom DM9601" },
{ { { 0x0a47, 0x9601 } }, "Hirose USB-100" }, { { 0x0a47, 0x9601 }, "Hirose USB-100" },
{ { { 0x0fe6, 0x8101 } }, "Sunrising SR9600" }, { { 0x0fe6, 0x8101 }, "Sunrising SR9600" },
{ { { 0x0fe6, 0x9700 } }, "Kontron DM9601" } { { 0x0fe6, 0x9700 }, "Kontron DM9601" }
}; };
@@ -61,18 +61,19 @@ lookup_and_create_device(usb_device device)
deviceDescriptor->vendor_id, deviceDescriptor->product_id); deviceDescriptor->vendor_id, deviceDescriptor->product_id);
// use binary search to lookup device in table // use binary search to lookup device in table
DeviceInfo::Id id = { { deviceDescriptor->vendor_id, uint32 id = deviceDescriptor->vendor_id << 16
deviceDescriptor->product_id } }; | deviceDescriptor->product_id;
int left = -1; int left = -1;
int right = _countof(gSupportedDevices); int right = _countof(gSupportedDevices);
while ((right - left) > 1) { while ((right - left) > 1) {
int i = (left + right) / 2; 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]); return new DavicomDevice(device, gSupportedDevices[right]);
TRACE_ALWAYS("Search for %#x failed %d-%d.\n", id, left, right);
return NULL; return NULL;
} }
@@ -24,7 +24,7 @@
#define MAX_DEVICES 8 #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; extern usb_module_info *gUSBModule;