Bringing usb_davicom to life: part 3 of 3:
* Lot of code refactoring and code style fixes; * Promiscuous mode implemented; * Multicasting support implemented; * Binary-search devices table lookup procedure used instead of switch one. git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@42749 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
File diff suppressed because it is too large
Load Diff
@@ -1,28 +1,109 @@
|
||||
/*
|
||||
* Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
* Copyright (c) 2009 Adrien Destugues <[email protected]>
|
||||
* Copyright (c) 2008, 2011 S.Zharski <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of the
|
||||
* Heavily based on code of the
|
||||
* Driver for USB Ethernet Control Model devices
|
||||
* Copyright (C) 2008 Michael Lotz <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
*/
|
||||
#ifndef _USB_Davicom_DEVICE_H_
|
||||
#define _USB_Davicom_DEVICE_H_
|
||||
#ifndef _USB_DAVICOM_DEVICE_H_
|
||||
#define _USB_DAVICOM_DEVICE_H_
|
||||
|
||||
|
||||
#include <net/if_media.h>
|
||||
#include <ether_driver.h>
|
||||
#include <util/Vector.h>
|
||||
|
||||
#include "Driver.h"
|
||||
|
||||
|
||||
struct DM9601NotifyData {
|
||||
// Network Status Register
|
||||
uint RXRDY :1;
|
||||
uint RXOV :1;
|
||||
uint TX1END :1;
|
||||
uint TX2END :1;
|
||||
uint TXFULL :1;
|
||||
uint WAKEST :1;
|
||||
uint LINKST :1;
|
||||
uint SPEED :1;
|
||||
|
||||
struct {
|
||||
uint :2;
|
||||
uint EC :1;
|
||||
uint COL :1;
|
||||
uint LC :1;
|
||||
uint NC :1;
|
||||
uint LCR :1;
|
||||
uint :1;
|
||||
} __attribute__((__packed__)) TSR1, TSR2;
|
||||
|
||||
// RX Status Register
|
||||
uint FOE :1;
|
||||
uint CE :1;
|
||||
uint AE :1;
|
||||
uint PLE :1;
|
||||
uint RWTO :1;
|
||||
uint LCS :1;
|
||||
uint MF :1;
|
||||
uint RT :1;
|
||||
|
||||
// RX Overflows Count
|
||||
uint RXFU :1;
|
||||
uint ROC :7;
|
||||
|
||||
uint RXC :8;
|
||||
uint TXC :8;
|
||||
uint GPR :8;
|
||||
|
||||
DM9601NotifyData() { memset(this, 0, sizeof(DM9601NotifyData)); }
|
||||
} __attribute__((__packed__));
|
||||
|
||||
|
||||
struct DeviceInfo {
|
||||
union Id {
|
||||
uint16 fIds[2];
|
||||
uint32 fKey;
|
||||
} fId;
|
||||
const char* fName;
|
||||
inline uint16 VendorId() { return fId.fIds[0]; }
|
||||
inline uint16 ProductId() { return fId.fIds[1]; }
|
||||
inline uint32 Key() { return fId.fKey; }
|
||||
};
|
||||
|
||||
class DavicomDevice {
|
||||
|
||||
struct _Statistics {
|
||||
// NSR
|
||||
int txFull;
|
||||
int rxOverflow;
|
||||
int rxOvCount;
|
||||
// RSR
|
||||
int runtFrames;
|
||||
int lateRXCollisions;
|
||||
int rwTOs;
|
||||
int physLayerErros;
|
||||
int alignmentErros;
|
||||
int crcErrors;
|
||||
int overErrors;
|
||||
// TSR 1/2
|
||||
int lateTXCollisions;
|
||||
int lostOfCarrier;
|
||||
int noCarrier;
|
||||
int txCollisions;
|
||||
int excCollisions;
|
||||
|
||||
int notifyCount;
|
||||
int readCount;
|
||||
int writeCount;
|
||||
_Statistics() { memset(this, 0, sizeof(_Statistics)); }
|
||||
};
|
||||
|
||||
public:
|
||||
DavicomDevice(usb_device device, const char *description);
|
||||
virtual ~DavicomDevice();
|
||||
DavicomDevice(usb_device device, DeviceInfo& Info);
|
||||
~DavicomDevice();
|
||||
|
||||
status_t InitCheck() { return fStatus; };
|
||||
|
||||
@@ -40,8 +121,8 @@ public:
|
||||
bool IsRemoved() { return fRemoved; };
|
||||
|
||||
status_t CompareAndReattach(usb_device device);
|
||||
virtual status_t SetupDevice(bool deviceReplugged);
|
||||
|
||||
status_t SetupDevice(bool deviceReplugged);
|
||||
|
||||
private:
|
||||
static void _ReadCallback(void *cookie, int32 status,
|
||||
void *data, uint32 actualLength);
|
||||
@@ -52,6 +133,16 @@ static void _NotifyCallback(void *cookie, int32 status,
|
||||
|
||||
status_t _SetupEndpoints();
|
||||
|
||||
status_t _StartDevice();
|
||||
status_t _StopDevice();
|
||||
status_t _OnNotify(uint32 actualLength);
|
||||
status_t _GetLinkState(ether_link_state *state);
|
||||
status_t _SetPromiscuousMode(bool bOn);
|
||||
uint32 _EthernetCRC32(const uint8* buffer, size_t length);
|
||||
status_t _ModifyMulticastTable(bool join,
|
||||
ether_address_t *group);
|
||||
status_t _ReadMACAddress(ether_address_t *address);
|
||||
|
||||
status_t _ReadRegister(uint8 reg, size_t size, uint8* buffer);
|
||||
status_t _WriteRegister(uint8 reg, size_t size, uint8* buffer);
|
||||
status_t _Write1Register(uint8 reg, uint8 buffer);
|
||||
@@ -60,32 +151,22 @@ static void _NotifyCallback(void *cookie, int32 status,
|
||||
status_t _InitMII();
|
||||
status_t _EnableInterrupts(bool enable);
|
||||
|
||||
static const int kFrameSize = 1518;
|
||||
static const size_t kRXHeaderSize = 3;
|
||||
static const size_t kTXHeaderSize = 2;
|
||||
|
||||
protected:
|
||||
/* overrides */
|
||||
virtual status_t StartDevice() ;
|
||||
virtual status_t StopDevice();
|
||||
virtual status_t OnNotify(uint32 actualLength) ;
|
||||
virtual status_t GetLinkState(ether_link_state *state) ;
|
||||
virtual status_t SetPromiscuousMode(bool bOn);
|
||||
virtual status_t ModifyMulticastTable(bool add, uint8 address);
|
||||
status_t ReadMACAddress(ether_address_t *address);
|
||||
|
||||
// device info
|
||||
usb_device fDevice;
|
||||
DeviceInfo fDeviceInfo;
|
||||
ether_address_t fMACAddress;
|
||||
|
||||
// state tracking
|
||||
status_t fStatus;
|
||||
bool fOpen;
|
||||
bool fRemoved;
|
||||
vint32 fInsideNotify;
|
||||
usb_device fDevice;
|
||||
uint16 fVendorID;
|
||||
uint16 fProductID;
|
||||
const char * fDescription;
|
||||
bool fHasConnection;
|
||||
bool fTXBufferFull;
|
||||
bool fNonBlocking;
|
||||
vint32 fInsideNotify;
|
||||
|
||||
// pipes for notifications and data io
|
||||
// pipes for notifications, data io and tx packet size
|
||||
usb_pipe fNotifyEndpoint;
|
||||
usb_pipe fReadEndpoint;
|
||||
usb_pipe fWriteEndpoint;
|
||||
@@ -98,15 +179,12 @@ const char * fDescription;
|
||||
int32 fStatusWrite;
|
||||
sem_id fNotifyReadSem;
|
||||
sem_id fNotifyWriteSem;
|
||||
|
||||
uint8 * fNotifyBuffer;
|
||||
static const size_t kNotifyBufferSize = 8;
|
||||
|
||||
// connection data
|
||||
sem_id fLinkStateChangeSem;
|
||||
ether_address_t fMACAddress;
|
||||
bool fHasConnection;
|
||||
bool fTXBufferFull;
|
||||
|
||||
DM9601NotifyData* fNotifyData;
|
||||
_Statistics fStats;
|
||||
Vector<uint32> fMulticastHashes;
|
||||
};
|
||||
|
||||
#endif //_USB_Davicom_DEVICE_H_
|
||||
#endif // _USB_DAVICOM_DEVICE_H_
|
||||
|
||||
|
||||
@@ -1,60 +1,53 @@
|
||||
/*
|
||||
* Davicom 9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright 2009 Adrien Destugues <[email protected]>
|
||||
* Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
* Copyright (c) 2009 Adrien Destugues <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of
|
||||
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
|
||||
* Copyright (c) 2008 S.Zharski <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of the
|
||||
* Driver for USB Ethernet Control Model devices
|
||||
* Copyright (C) 2008 Michael Lotz <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef HAIKU_TARGET_PLATFORM_HAIKU
|
||||
#include <lock.h> // for mutex
|
||||
#else
|
||||
#include "BeOSCompatibility.h" // for pseudo mutex
|
||||
#endif
|
||||
#include "Driver.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
#include <lock.h>
|
||||
#include <util/AutoLock.h>
|
||||
|
||||
#include "DavicomDevice.h"
|
||||
#include "Driver.h"
|
||||
#include "Settings.h"
|
||||
|
||||
|
||||
int32 api_version = B_CUR_DRIVER_API_VERSION;
|
||||
static const char *sDeviceBaseName = "net/usb_davicom/";
|
||||
DavicomDevice *gDavicomDevices[MAX_DEVICES];
|
||||
char *gDeviceNames[MAX_DEVICES + 1];
|
||||
usb_module_info *gUSBModule = NULL;
|
||||
|
||||
usb_support_descriptor gSupportedDevices[] = {
|
||||
{ 0, 0, 0, 0x0fe6, 0x8101}, // "Sunrising JP108"
|
||||
{ 0, 0, 0, 0x07aa, 0x9601}, // "Corega FEther USB-TXC"
|
||||
{ 0, 0, 0, 0x0a46, 0x9601}, // "Davicom USB-100"
|
||||
{ 0, 0, 0, 0x0a46, 0x6688}, // "ZT6688 USB NIC"
|
||||
{ 0, 0, 0, 0x0a46, 0x0268}, // "ShanTou ST268 USB NIC"
|
||||
{ 0, 0, 0, 0x0a46, 0x8515}, // "ADMtek ADM8515 USB NIC"
|
||||
{ 0, 0, 0, 0x0a47, 0x9601}, // "Hirose USB-100"
|
||||
{ 0, 0, 0, 0x0a46, 0x9000} // "DM9000E"
|
||||
};
|
||||
|
||||
mutex gDriverLock;
|
||||
// auto-release helper class
|
||||
class DriverSmartLock {
|
||||
public:
|
||||
DriverSmartLock() { mutex_lock(&gDriverLock); }
|
||||
~DriverSmartLock() { mutex_unlock(&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" }
|
||||
};
|
||||
|
||||
|
||||
DavicomDevice *
|
||||
create_davicom_device(usb_device device)
|
||||
lookup_and_create_device(usb_device device)
|
||||
{
|
||||
const usb_device_descriptor *deviceDescriptor
|
||||
= gUSBModule->get_device_descriptor(device);
|
||||
@@ -64,18 +57,22 @@ create_davicom_device(usb_device device)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
#define IDS(__vendor, __product) (((__vendor) << 16) | (__product))
|
||||
TRACE("trying %#06x:%#06x.\n",
|
||||
deviceDescriptor->vendor_id, deviceDescriptor->product_id);
|
||||
|
||||
switch(IDS(deviceDescriptor->vendor_id, deviceDescriptor->product_id)) {
|
||||
case IDS(0x0fe6, 0x8101): return new DavicomDevice(device, "Sunrising JP108");
|
||||
case IDS(0x07aa, 0x9601): return new DavicomDevice(device, "Corega FEther USB-TXC");
|
||||
case IDS(0x0a46, 0x9601): return new DavicomDevice(device, "Davicom USB-100");
|
||||
case IDS(0x0a46, 0x6688): return new DavicomDevice(device, "ZT6688 USB NIC");
|
||||
case IDS(0x0a46, 0x0268): return new DavicomDevice(device, "ShanTou ST268 USB NIC");
|
||||
case IDS(0x0a46, 0x8515): return new DavicomDevice(device, "ADMtek ADM8515 USB NIC");
|
||||
case IDS(0x0a47, 0x9601): return new DavicomDevice(device, "Hirose USB-100");
|
||||
case IDS(0x0a46, 0x9000): return new DavicomDevice(device, "DM9000E");
|
||||
// use binary search to lookup device in table
|
||||
DeviceInfo::Id id = { { deviceDescriptor->vendor_id,
|
||||
deviceDescriptor->product_id } };
|
||||
int left = -1;
|
||||
int right = _countof(gSupportedDevices);
|
||||
while((right - left) > 1) {
|
||||
int i = (left + right) / 2;
|
||||
((gSupportedDevices[i].Key() < id.fKey) ? left : right) = i;
|
||||
}
|
||||
|
||||
if(gSupportedDevices[right].Key() == id.fKey)
|
||||
return new DavicomDevice(device, gSupportedDevices[right]);
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
@@ -85,7 +82,7 @@ usb_davicom_device_added(usb_device device, void **cookie)
|
||||
{
|
||||
*cookie = NULL;
|
||||
|
||||
DriverSmartLock driverLock; // released on exit
|
||||
MutexLocker lock(gDriverLock); // released on exit
|
||||
|
||||
// check if this is a replug of an existing device first
|
||||
for (int32 i = 0; i < MAX_DEVICES; i++) {
|
||||
@@ -101,7 +98,7 @@ usb_davicom_device_added(usb_device device, void **cookie)
|
||||
}
|
||||
|
||||
// no such device yet, create a new one
|
||||
DavicomDevice *davicomDevice = create_davicom_device(device);
|
||||
DavicomDevice *davicomDevice = lookup_and_create_device(device);
|
||||
if (davicomDevice == 0) {
|
||||
return ENODEV;
|
||||
}
|
||||
@@ -140,7 +137,7 @@ usb_davicom_device_added(usb_device device, void **cookie)
|
||||
status_t
|
||||
usb_davicom_device_removed(void *cookie)
|
||||
{
|
||||
DriverSmartLock driverLock; // released on exit
|
||||
MutexLocker lock(gDriverLock); // released on exit
|
||||
|
||||
DavicomDevice *device = (DavicomDevice *)cookie;
|
||||
for (int32 i = 0; i < MAX_DEVICES; i++) {
|
||||
@@ -161,7 +158,7 @@ usb_davicom_device_removed(void *cookie)
|
||||
}
|
||||
|
||||
|
||||
//#pragma mark -
|
||||
// #pragma mark -
|
||||
|
||||
|
||||
status_t
|
||||
@@ -180,9 +177,9 @@ init_driver()
|
||||
return status;
|
||||
|
||||
load_settings();
|
||||
|
||||
|
||||
TRACE_ALWAYS("%s\n", kVersion);
|
||||
|
||||
|
||||
for (int32 i = 0; i < MAX_DEVICES; i++)
|
||||
gDavicomDevices[i] = NULL;
|
||||
|
||||
@@ -194,8 +191,15 @@ init_driver()
|
||||
&usb_davicom_device_removed
|
||||
};
|
||||
|
||||
gUSBModule->register_driver(DRIVER_NAME, gSupportedDevices,
|
||||
sizeof(gSupportedDevices) / sizeof(usb_support_descriptor), NULL);
|
||||
const size_t count = _countof(gSupportedDevices);
|
||||
static usb_support_descriptor sDescriptors[count] = {{ 0 }};
|
||||
|
||||
for(size_t i = 0; i < count; i++) {
|
||||
sDescriptors[i].vendor = gSupportedDevices[i].VendorId();
|
||||
sDescriptors[i].product = gSupportedDevices[i].ProductId();
|
||||
}
|
||||
|
||||
gUSBModule->register_driver(DRIVER_NAME, sDescriptors, count, NULL);
|
||||
gUSBModule->install_notify(DRIVER_NAME, ¬ifyHooks);
|
||||
return B_OK;
|
||||
}
|
||||
@@ -221,7 +225,7 @@ uninit_driver()
|
||||
|
||||
mutex_destroy(&gDriverLock);
|
||||
put_module(B_USB_MODULE_NAME);
|
||||
|
||||
|
||||
release_settings();
|
||||
}
|
||||
|
||||
@@ -229,7 +233,7 @@ uninit_driver()
|
||||
static status_t
|
||||
usb_davicom_open(const char *name, uint32 flags, void **cookie)
|
||||
{
|
||||
DriverSmartLock driverLock; // released on exit
|
||||
MutexLocker lock(gDriverLock); // released on exit
|
||||
|
||||
*cookie = NULL;
|
||||
status_t status = ENODEV;
|
||||
@@ -280,9 +284,9 @@ static status_t
|
||||
usb_davicom_free(void *cookie)
|
||||
{
|
||||
DavicomDevice *device = (DavicomDevice *)cookie;
|
||||
|
||||
DriverSmartLock driverLock; // released on exit
|
||||
|
||||
|
||||
MutexLocker lock(gDriverLock); // released on exit
|
||||
|
||||
status_t status = device->Free();
|
||||
for (int32 i = 0; i < MAX_DEVICES; i++) {
|
||||
if (gDavicomDevices[i] == device) {
|
||||
@@ -307,8 +311,8 @@ publish_devices()
|
||||
gDeviceNames[i] = NULL;
|
||||
}
|
||||
|
||||
DriverSmartLock driverLock; // released on exit
|
||||
|
||||
MutexLocker lock(gDriverLock); // released on exit
|
||||
|
||||
int32 deviceCount = 0;
|
||||
for (int32 i = 0; i < MAX_DEVICES; i++) {
|
||||
if (gDavicomDevices[i] == NULL)
|
||||
@@ -320,7 +324,7 @@ publish_devices()
|
||||
TRACE("publishing %s\n", gDeviceNames[deviceCount]);
|
||||
deviceCount++;
|
||||
} else
|
||||
TRACE_ALWAYS("Error: out of memory during allocating device name.\n");
|
||||
TRACE_ALWAYS("Error: out of memory during allocating dev.name.\n");
|
||||
}
|
||||
|
||||
gDeviceNames[deviceCount] = NULL;
|
||||
@@ -338,8 +342,8 @@ find_device(const char *name)
|
||||
usb_davicom_control,
|
||||
usb_davicom_read,
|
||||
usb_davicom_write,
|
||||
NULL, /* select */
|
||||
NULL /* deselect */
|
||||
NULL, // select
|
||||
NULL // deselect
|
||||
};
|
||||
|
||||
return &deviceHooks;
|
||||
|
||||
@@ -1,44 +1,35 @@
|
||||
/*
|
||||
* Davicom 9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright 2009 Adrien Destugues <[email protected]>
|
||||
* Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
* Copyright (c) 2009 Adrien Destugues <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of :
|
||||
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
|
||||
* Copyright (c) 2008 S.Zharski <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of the
|
||||
* Driver for USB Ethernet Control Model devices
|
||||
* Copyright (C) 2008 Michael Lotz <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef _USB_DAVICOM_DRIVER_H_
|
||||
#define _USB_DAVICOM_DRIVER_H_
|
||||
|
||||
#include <OS.h>
|
||||
#include <KernelExport.h>
|
||||
|
||||
#include <Drivers.h>
|
||||
#include <USB3.h>
|
||||
#include <ether_driver.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#include <util/kernel_cpp.h>
|
||||
|
||||
// extra tracing in debug mode
|
||||
//#define UDAV_TRACE
|
||||
|
||||
#define DRIVER_NAME "usb_davicom"
|
||||
#define MAX_DEVICES 8
|
||||
|
||||
const uint8 kInvalidRequest = 0xff;
|
||||
|
||||
const char* const kVersion = "ver.0.8.3";
|
||||
|
||||
const char* const kVersion = "ver.0.9.4";
|
||||
extern usb_module_info *gUSBModule;
|
||||
|
||||
|
||||
extern "C" {
|
||||
|
||||
status_t usb_davicom_device_added(usb_device device, void **cookie);
|
||||
status_t usb_davicom_device_removed(void *cookie);
|
||||
|
||||
@@ -47,8 +38,9 @@ void uninit_driver();
|
||||
|
||||
const char **publish_devices();
|
||||
device_hooks *find_device(const char *name);
|
||||
|
||||
}
|
||||
|
||||
|
||||
#endif //_USB_DAVICOM_DRIVER_H_
|
||||
#endif // _USB_DAVICOM_DRIVER_H_
|
||||
|
||||
|
||||
@@ -3,6 +3,7 @@ SubDir HAIKU_TOP src add-ons kernel drivers network usb_davicom ;
|
||||
SetSubDirSupportedPlatformsBeOSCompatible ;
|
||||
|
||||
UsePrivateHeaders kernel net ;
|
||||
UsePrivateKernelHeaders ;
|
||||
|
||||
KernelAddon usb_davicom :
|
||||
Driver.cpp
|
||||
|
||||
@@ -1,32 +1,38 @@
|
||||
/*
|
||||
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
|
||||
* Copyright (c) 2008 S.Zharski <[email protected]>
|
||||
* Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of the
|
||||
* Driver for USB Ethernet Control Model devices
|
||||
* Copyright (C) 2008 Michael Lotz <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
*/
|
||||
|
||||
#include <lock.h> // for mutex
|
||||
|
||||
#include "Settings.h"
|
||||
|
||||
#include <malloc.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <driver_settings.h>
|
||||
#include <lock.h>
|
||||
|
||||
#include "Driver.h"
|
||||
|
||||
|
||||
mutex gLogLock;
|
||||
static char *gLogFilePath = NULL;
|
||||
|
||||
bool gTraceOn = false;
|
||||
bool gTruncateLogFile = false;
|
||||
bool gAddTimeStamp = true;
|
||||
bool gTraceState = false;
|
||||
bool gTraceRX = false;
|
||||
bool gTraceTX = false;
|
||||
static char *gLogFilePath = NULL;
|
||||
mutex gLogLock;
|
||||
bool gTraceStats = false;
|
||||
|
||||
static
|
||||
|
||||
static
|
||||
void create_log()
|
||||
{
|
||||
if(gLogFilePath == NULL)
|
||||
if (gLogFilePath == NULL)
|
||||
return;
|
||||
|
||||
int flags = O_WRONLY | O_CREAT | ((gTruncateLogFile) ? O_TRUNC : 0);
|
||||
@@ -35,23 +41,28 @@ void create_log()
|
||||
mutex_init(&gLogLock, DRIVER_NAME"-logging");
|
||||
}
|
||||
|
||||
void load_settings()
|
||||
|
||||
void
|
||||
load_settings()
|
||||
{
|
||||
void *handle = load_driver_settings(DRIVER_NAME);
|
||||
if(handle == 0)
|
||||
if (handle == 0)
|
||||
return;
|
||||
|
||||
gTraceOn = get_driver_boolean_parameter(handle, "trace", gTraceOn, true);
|
||||
gTraceState = get_driver_boolean_parameter(handle, "trace_state", gTraceState, true);
|
||||
gTraceState = get_driver_boolean_parameter(handle,
|
||||
"trace_state", gTraceState, true);
|
||||
gTraceRX = get_driver_boolean_parameter(handle, "trace_rx", gTraceRX, true);
|
||||
gTraceTX = get_driver_boolean_parameter(handle, "trace_tx", gTraceTX, true);
|
||||
gTruncateLogFile = get_driver_boolean_parameter(handle, "truncate_logfile",
|
||||
gTruncateLogFile, true);
|
||||
gAddTimeStamp = get_driver_boolean_parameter(handle, "add_timestamp",
|
||||
gAddTimeStamp, true);
|
||||
const char * logFilePath = get_driver_parameter(handle, "logfile",
|
||||
NULL, "/var/log/"DRIVER_NAME".log");
|
||||
if(logFilePath != NULL) {
|
||||
gTraceStats = get_driver_boolean_parameter(handle,
|
||||
"trace_stats", gTraceStats, true);
|
||||
gTruncateLogFile = get_driver_boolean_parameter(handle,
|
||||
"reset_logfile", gTruncateLogFile, true);
|
||||
gAddTimeStamp = get_driver_boolean_parameter(handle,
|
||||
"add_timestamp", gAddTimeStamp, true);
|
||||
const char * logFilePath = get_driver_parameter(handle,
|
||||
"logfile", NULL, "/var/log/"DRIVER_NAME".log");
|
||||
if (logFilePath != NULL) {
|
||||
gLogFilePath = strdup(logFilePath);
|
||||
}
|
||||
|
||||
@@ -60,39 +71,42 @@ void load_settings()
|
||||
create_log();
|
||||
}
|
||||
|
||||
void release_settings()
|
||||
|
||||
void
|
||||
release_settings()
|
||||
{
|
||||
if(gLogFilePath != NULL) {
|
||||
if (gLogFilePath != NULL) {
|
||||
mutex_destroy(&gLogLock);
|
||||
free(gLogFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void usb_davicom_trace(bool force, const char* func, const char *fmt, ...)
|
||||
{
|
||||
if(!(force || gTraceOn)) {
|
||||
// return;
|
||||
if (!(force || gTraceOn)) {
|
||||
return;
|
||||
}
|
||||
|
||||
va_list arg_list;
|
||||
static const char *prefix = "\33[33m"DRIVER_NAME":\33[0m";
|
||||
static char buffer[1024];
|
||||
char *buf_ptr = buffer;
|
||||
if(gLogFilePath == NULL){
|
||||
if (gLogFilePath == NULL) {
|
||||
strcpy(buffer, prefix);
|
||||
buf_ptr += strlen(prefix);
|
||||
}
|
||||
|
||||
if(gAddTimeStamp) {
|
||||
bigtime_t time = system_time();
|
||||
uint32 msec = time / 1000;
|
||||
uint32 sec = msec / 1000;
|
||||
sprintf(buf_ptr, "%02ld.%02ld.%03ld:",
|
||||
sec / 60, sec % 60, msec % 1000);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
}
|
||||
|
||||
if(func != NULL) {
|
||||
if (gAddTimeStamp) {
|
||||
bigtime_t time = system_time();
|
||||
uint32 msec = time / 1000;
|
||||
uint32 sec = msec / 1000;
|
||||
sprintf(buf_ptr, "%02ld.%02ld.%03ld:",
|
||||
sec / 60, sec % 60, msec % 1000);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
}
|
||||
|
||||
if (func != NULL) {
|
||||
sprintf(buf_ptr, "%s::", func);
|
||||
buf_ptr += strlen(buf_ptr);
|
||||
}
|
||||
@@ -101,7 +115,7 @@ void usb_davicom_trace(bool force, const char* func, const char *fmt, ...)
|
||||
vsprintf(buf_ptr, fmt, arg_list);
|
||||
va_end(arg_list);
|
||||
|
||||
if(gLogFilePath == NULL) {
|
||||
if (gLogFilePath == NULL) {
|
||||
dprintf(buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -1,40 +1,48 @@
|
||||
/*
|
||||
* ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
|
||||
* Copyright (c) 2008 S.Zharski <[email protected]>
|
||||
* Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
* Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
* Heavily based on code of the
|
||||
* Driver for USB Ethernet Control Model devices
|
||||
* Copyright (C) 2008 Michael Lotz <[email protected]>
|
||||
* Distributed under the terms of the MIT license.
|
||||
*
|
||||
*/
|
||||
#ifndef _USB_DAVICOM_SETTINGS_H_
|
||||
#define _USB_DAVICOM_SETTINGS_H_
|
||||
|
||||
#ifndef _USB_DAVICOM_SETTINGS_H_
|
||||
#define _USB_DAVICOM_SETTINGS_H_
|
||||
|
||||
#include <driver_settings.h>
|
||||
#ifdef _countof
|
||||
#warning "_countof(...) WAS ALREADY DEFINED!!! Remove local definition!"
|
||||
#undef _countof
|
||||
#endif
|
||||
#define _countof(array)(sizeof(array) / sizeof(array[0]))
|
||||
|
||||
#include "Driver.h"
|
||||
|
||||
void load_settings();
|
||||
void release_settings();
|
||||
|
||||
void usb_davicom_trace(bool force, const char *func, const char *fmt, ...);
|
||||
|
||||
|
||||
#define TRACE(x...) usb_davicom_trace(false, __func__, x)
|
||||
#define TRACE_ALWAYS(x...) usb_davicom_trace(true, __func__, x)
|
||||
|
||||
|
||||
#ifdef UDAV_TRACE
|
||||
|
||||
extern bool gTraceState;
|
||||
#define TRACE_STATE(x...) usb_davicom_trace(gTraceState, NULL, x)
|
||||
|
||||
extern bool gTraceRX;
|
||||
#define TRACE_RX(x...) usb_davicom_trace(gTraceRX, NULL, x)
|
||||
|
||||
extern bool gTraceTX;
|
||||
extern bool gTraceStats;
|
||||
#define TRACE_STATE(x...) usb_davicom_trace(gTraceState, NULL, x)
|
||||
#define TRACE_STATS(x...) usb_davicom_trace(gTraceStats, NULL, x)
|
||||
#define TRACE_RX(x...) usb_davicom_trace(gTraceRX, NULL, x)
|
||||
#define TRACE_TX(x...) usb_davicom_trace(gTraceTX, NULL, x)
|
||||
|
||||
#define TRACE_RET(result) usb_davicom_trace(false, __func__, \
|
||||
"Returns:%#010x\n", result);
|
||||
#else
|
||||
|
||||
#define TRACE_STATE(x...)
|
||||
#define TRACE_STATS(x...)
|
||||
#define TRACE_RX(x...)
|
||||
#define TRACE_TX(x...)
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // _USB_DAVICOM_SETTINGS_H_
|
||||
|
||||
#endif /*_USB_DAVICOM_SETTINGS_H_*/
|
||||
|
||||
@@ -1,25 +1,25 @@
|
||||
##
|
||||
## ASIX AX88172/AX88772/AX88178 USB 2.0 Ethernet Driver.
|
||||
## Copyright (c) 2008 S.Zharski <[email protected]>
|
||||
## Davicom DM9601 USB 1.1 Ethernet Driver.
|
||||
## Copyright (c) 2008, 2011 Siarzhuk Zharski <[email protected]>
|
||||
## Distributed under the terms of the MIT license.
|
||||
##
|
||||
|
||||
## trace [on|off] - activate additional tracing.
|
||||
## default value: off
|
||||
|
||||
trace on
|
||||
# trace on
|
||||
|
||||
## logfile [full path to private log file]
|
||||
## default path value: /var/log/usb_davicom.log
|
||||
## if disabled - all output goes to syslog
|
||||
|
||||
logfile /var/log/usb_davicom.log
|
||||
# logfile /var/log/usb_davicom.log
|
||||
|
||||
## reset_logfile [on|off] - truncate private log file on driver/system restart
|
||||
## default value: off
|
||||
##
|
||||
|
||||
reset_logfile on
|
||||
# reset_logfile on
|
||||
|
||||
|
||||
## add_timestamp [on|off] - add time of writing the string in private log file.
|
||||
@@ -28,6 +28,12 @@ reset_logfile on
|
||||
|
||||
# add_timestamp off
|
||||
|
||||
###########################################################################
|
||||
##
|
||||
## Following settings are usable only with special version of the driver
|
||||
## compiled with UDAV_TRACE defined. Look into Driver.h for details.
|
||||
##
|
||||
|
||||
## trace_state [on|off] - activate state tracing. Statistic about of
|
||||
## media state.
|
||||
## default value: off
|
||||
@@ -45,3 +51,10 @@ reset_logfile on
|
||||
## default value: off
|
||||
|
||||
# trace_tx on
|
||||
|
||||
## trace_stats [on|off] - activate tx/rx error counters tracing.
|
||||
##
|
||||
## default value: off
|
||||
|
||||
# trace_stats on
|
||||
|
||||
|
||||
Reference in New Issue
Block a user