Author: pulkomandy Date: 2010-01-10 21:29:02 +0100 (Sun, 10 Jan 2010) New Revision: 34993 Changeset: http://dev.haiku-os.org/changeset/34993/haiku Modified: haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.cpp haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h Log: - Some style fixes, as pointed out by Siarzhuk Zharski. - Haiku doesn't like the ethernet maximal frame size to be set to 0. This drops the CPU usage and some calls to read/write are now occuring. Modified: haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.cpp =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.cpp 2010-01-10 19:45:05 UTC (rev 34992) +++ haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.cpp 2010-01-10 20:29:02 UTC (rev 34993) @@ -118,7 +118,6 @@ fDevice(device), fDescription(description), fNonBlocking(false), - fFrameSize(0), fNotifyEndpoint(0), fReadEndpoint(0), fWriteEndpoint(0), @@ -127,11 +126,7 @@ fNotifyBuffer(NULL), fLinkStateChangeSem(-1), fHasConnection(false), - fUseTRXHeader(false), - fReadNodeIDRequest(kInvalidRequest), - fReadRXControlRequest(kInvalidRequest), - fWriteRXControlRequest(kInvalidRequest), - fPromiscuousBits(0) + fUseTRXHeader(false) { const usb_device_descriptor *deviceDescriptor = gUSBModule->get_device_descriptor(device); @@ -162,7 +157,7 @@ return; } - fNotifyBuffer = (uint8*)malloc(8); + fNotifyBuffer = (uint8*)malloc(kNotifyBufferSize); if (fNotifyBuffer == NULL) { TRACE_ALWAYS("Error allocating notify buffer\n"); return; @@ -208,7 +203,7 @@ // setup state notifications result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer, - 8, _NotifyCallback, this); + kNotifyBufferSize, _NotifyCallback, this); if(result != B_OK) { TRACE_ALWAYS("Error of requesting notify interrupt:%#010x\n", result); return result; @@ -395,7 +390,7 @@ return B_OK; case ETHER_GETFRAMESIZE: - *(uint32 *)buffer = fFrameSize; + *(uint32 *)buffer = 1518 /* fFrameSize */; return B_OK; case ETHER_NONBLOCK: @@ -718,7 +713,7 @@ // schedule next notification buffer gUSBModule->queue_interrupt(device->fNotifyEndpoint, device->fNotifyBuffer, - 8, _NotifyCallback, device); + kNotifyBufferSize, _NotifyCallback, device); atomic_add(&device->fInsideNotify, -1); } @@ -726,58 +721,58 @@ status_t DavicomDevice::StartDevice() { - uint8 tmp_reg; + uint8 registerValue = 0; /* disable loopback */ - status_t result = _ReadRegister(NCR, 1, &tmp_reg); + status_t result = _ReadRegister(NCR, 1, ®isterValue); if (result != B_OK) { TRACE_ALWAYS("Error reading NCR: %#010x.\n", result); return result; } - if (tmp_reg & NCR_EXT_PHY) + if (registerValue & NCR_EXT_PHY) TRACE_ALWAYS("Device uses external PHY\n"); - tmp_reg &= ~NCR_LBK; - result = _Write1Register(NCR, tmp_reg); + registerValue &= ~NCR_LBK; + result = _Write1Register(NCR, registerValue); if (result != B_OK) { - TRACE_ALWAYS("Error writing %#02X to NCR: %#010x.\n", tmp_reg, result); + TRACE_ALWAYS("Error writing %#02X to NCR: %#010x.\n", registerValue, result); return result; } /* Initialize RX control register */ - result = _ReadRegister(RCR, 1, &tmp_reg); + result = _ReadRegister(RCR, 1, ®isterValue); if (result != B_OK) { TRACE_ALWAYS("Error reading RCR: %#010x.\n", result); return result; } - tmp_reg &= RCR_DIS_LONG & RCR_DIS_CRC & RCR_RXEN; - result = _Write1Register(RCR, tmp_reg); + registerValue &= RCR_DIS_LONG & RCR_DIS_CRC & RCR_RXEN; + result = _Write1Register(RCR, registerValue); if (result != B_OK) { - TRACE_ALWAYS("Error writing %#02X to RCR: %#010x.\n", tmp_reg, result); + TRACE_ALWAYS("Error writing %#02X to RCR: %#010x.\n", registerValue, result); return result; } /* clear POWER_DOWN state of internal PHY */ - result = _ReadRegister(GPCR, 1, &tmp_reg); + result = _ReadRegister(GPCR, 1, ®isterValue); if (result != B_OK) { TRACE_ALWAYS("Error reading GPCR: %#010x.\n", result); return result; } - tmp_reg &= GPCR_GEP_CNTL0; - result = _Write1Register(GPCR, tmp_reg); + registerValue &= GPCR_GEP_CNTL0; + result = _Write1Register(GPCR, registerValue); if (result != B_OK) { - TRACE_ALWAYS("Error writing %#02X to GPCR: %#010x.\n", tmp_reg, result); + TRACE_ALWAYS("Error writing %#02X to GPCR: %#010x.\n", registerValue, result); return result; } - result = _ReadRegister(GPR, 1, &tmp_reg); + result = _ReadRegister(GPR, 1, ®isterValue); if (result != B_OK) { TRACE_ALWAYS("Error reading GPR: %#010x.\n", result); return result; } - tmp_reg &= ~GPR_GEP_GEPIO0; - result = _Write1Register(GPR, tmp_reg); + registerValue &= ~GPR_GEP_GEPIO0; + result = _Write1Register(GPR, registerValue); if (result != B_OK) { - TRACE_ALWAYS("Error writing %#02X to GPR: %#010x.\n", tmp_reg, result); + TRACE_ALWAYS("Error writing %#02X to GPR: %#010x.\n", registerValue, result); return result; } @@ -788,7 +783,7 @@ status_t DavicomDevice::OnNotify(uint32 actualLength) { - if (actualLength < 8) { + if (actualLength != kNotifyBufferSize) { TRACE_ALWAYS("Data underrun error. %d of 8 bytes received\n", actualLength); return B_BAD_DATA; @@ -802,14 +797,14 @@ // 6 = Transmit packet counter // 7 = GPR - bool linkIsUp = (fNotifyBuffer[0] & 0x40) != 0; + bool linkIsUp = (fNotifyBuffer[0] & NSR_LINKST) != 0; bool linkStateChange = linkIsUp != fHasConnection; fHasConnection = linkIsUp; if(linkStateChange) { TRACE("Link is now %s at %s Mb/s\n", - fHasConnection ? "up" : "down", fNotifyBuffer[0]&0x80?"10":"100"); + fHasConnection ? "up" : "down", (fNotifyBuffer[0] & NSR_SPEED) ? "10" : "100"); } if (linkStateChange && fLinkStateChangeSem >= B_OK) @@ -820,12 +815,14 @@ status_t DavicomDevice::GetLinkState(ether_link_state *linkState) { - uint8 tmp_reg; - status_t result = _ReadRegister(NSR,1,&tmp_reg); - if (result != B_OK) + uint8 registerValue = 0; + status_t result = _ReadRegister(NSR, 1, ®isterValue); + if (result != B_OK) { + TRACE_ALWAYS("Error reading NSR register! %x\n",result); return result; + } - if (tmp_reg & NSR_SPEED) + if (registerValue & NSR_SPEED) linkState->speed = 10000; else linkState->speed = 100000; @@ -835,16 +832,18 @@ uint16 mediumStatus = IFM_ETHER | IFM_100_TX; if (fHasConnection) { mediumStatus |= IFM_ACTIVE; - result = _ReadRegister(NCR,1,&tmp_reg); - if (result != B_OK) + result = _ReadRegister(NCR, 1, ®isterValue); + if (result != B_OK) { + TRACE_ALWAYS("Error reading NCR register! %x\n",result); return result; + } - if (tmp_reg & NCR_FDX) + if (registerValue & NCR_FDX) mediumStatus |= IFM_FULL_DUPLEX; else mediumStatus |= IFM_HALF_DUPLEX; - if (tmp_reg & NCR_LBK) + if (registerValue & NCR_LBK) mediumStatus |= IFM_LOOP; } Modified: haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h =================================================================== --- haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h 2010-01-10 19:45:05 UTC (rev 34992) +++ haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h 2010-01-10 20:29:02 UTC (rev 34993) @@ -54,10 +54,12 @@ status_t _SetupEndpoints(); - 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); + 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); +static const int kFrameSize = 1518; + protected: /* overrides */ virtual status_t StartDevice() ; @@ -79,9 +81,6 @@ const char * fDescription; bool fNonBlocking; - // interface and device infos - uint16 fFrameSize; - // pipes for notifications and data io usb_pipe fNotifyEndpoint; usb_pipe fReadEndpoint; @@ -96,6 +95,7 @@ sem_id fNotifyWriteSem; uint8 * fNotifyBuffer; +static const int kNotifyBufferSize = 8; // connection data sem_id fLinkStateChangeSem; @@ -103,10 +103,6 @@ bool fHasConnection; bool fUseTRXHeader; uint8 fIPG[3]; - uint8 fReadNodeIDRequest; - uint8 fReadRXControlRequest; - uint8 fWriteRXControlRequest; - uint16 fPromiscuousBits; }; #endif //_USB_Davicom_DEVICE_H_