[haiku-commits] r34986 - haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom

  • From: pulkomandy@xxxxxxxxx
  • To: haiku-commits@xxxxxxxxxxxxx
  • Date: Sun, 10 Jan 2010 14:57:25 +0100 (CET)

Author: pulkomandy
Date: 2010-01-10 14:57:24 +0100 (Sun, 10 Jan 2010)
New Revision: 34986
Changeset: http://dev.haiku-os.org/changeset/34986/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 progress on davicom usb ethernet driver. The device is now initialized, 
and only the interrupt handlers are missing.


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 12:53:56 UTC (rev 34985)
+++ 
haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.cpp    
    2010-01-10 13:57:24 UTC (rev 34986)
@@ -29,8 +29,24 @@
 
 
 // Registers
+#define NCR 0x00       // Network control
+#define RCR 0x05       // RX Control
 #define PAR 0x10       // 6 bits - Physical address (MAC)
+#define GPCR 0x1E      // General purpose control
+#define GPR 0x1F       // General purpose
 
+#define NCR_LBK                        0x06    // Loopback mode
+
+#define RCR_DIS_LONG   0x20    // Discard long packet
+#define RCR_DIS_CRC            0x10    // Discard CRC error packet
+#define RCR_ALL                        0x08    // Pass all multicast
+#define RCR_PRMSC              0x02    // Promiscuous
+#define RCR_RXEN               0x01    // RX enable
+
+#define GPCR_GEP_CNTL0 0x01    // Power Down function
+
+#define GPR_GEP_GEPIO0 0x01    // Power down
+
 //TODO: multicast support
 //TODO: set media state support
 
@@ -60,10 +76,34 @@
                USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN,
                READ_REGISTER, 0, reg, size, buffer, &actualLength);
        if (size != actualLength) TRACE_ALWAYS("Size mismatch reading register 
! asked %d got %d",size,actualLength);
-       return B_OK;
+       return result;
 }
 
 
+status_t
+DavicomDevice::_WriteRegister(uint8 reg, size_t size, uint8* buffer)
+{
+       if (size > 255) return B_BAD_VALUE;
+       size_t actualLength;
+       status_t result = gUSBModule->send_request(fDevice, 
+               USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
+               WRITE_REGISTER, 0, reg, size, buffer, &actualLength);
+       if (size != actualLength) TRACE_ALWAYS("Size mismatch reading register 
! asked %d got %d",size,actualLength);
+       return result;
+}
+
+
+status_t
+DavicomDevice::_Write1Register(uint8 reg, uint8 value)
+{
+       size_t actualLength;
+       status_t result = gUSBModule->send_request(fDevice, 
+               USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
+               WRITE1_REGISTER, 0, reg, 1, &value, &actualLength);
+       return result;
+}
+
+
 DavicomDevice::DavicomDevice(usb_device device, const char *description)
        :       fStatus(B_ERROR),
                fOpen(false),
@@ -411,7 +451,7 @@
        ether_address address;
        status_t result = ReadMACAddress(&address);
        if(result != B_OK) {
-               TRACE_ALWAYS("Error of reading MAC address:%#010x\n", result);
+               TRACE_ALWAYS("Error reading MAC address:%#010x\n", result);
                return result;
        }
 
@@ -443,7 +483,7 @@
                = gUSBModule->get_device_descriptor(device);
 
        if (deviceDescriptor == NULL) {
-               TRACE_ALWAYS("Error of getting USB device descriptor.\n");
+               TRACE_ALWAYS("Error getting USB device descriptor.\n");
                return B_ERROR;
        }
 
@@ -609,27 +649,29 @@
 status_t
 DavicomDevice::SetPromiscuousMode(bool on)
 {
-       uint16 rxcontrol = 0;
-       
-       status_t result = ReadRXControlRegister(&rxcontrol);
-       if(result != B_OK) {
-               TRACE_ALWAYS("Error of reading RX Control:%#010x\n", result);
+
+       /* load multicast filter and update promiscious mode bit */
+       uint8_t rxmode;
+
+       status_t result = _ReadRegister(RCR, 1, &rxmode);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error reading RX Control:%#010x\n", result);
                return result;
        }
+       rxmode &= ~(RCR_ALL | RCR_PRMSC);
 
-       if(on) 
-               rxcontrol |= fPromiscuousBits;
-       else
-               rxcontrol &= ~fPromiscuousBits;
+       if (on)
+               rxmode |= RCR_ALL | RCR_PRMSC;
+/*     else if (ifp->if_flags & IFF_ALLMULTI)
+               rxmode |= RCR_ALL; */
 
-       result = WriteRXControlRegister(rxcontrol);
-       
-       if(result != B_OK ) {
-               TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", 
rxcontrol, result);
-       }
-       
-       TRACE_RET(result);
-       return result; 
+       /* write new mode bits */
+       result = _Write1Register(RCR, rxmode);
+       if(result != B_OK) {
+               TRACE_ALWAYS("Error writing %#04x to RX Control:%#010x\n", 
rxmode, result);
+       } 
+
+       return result;
 }
 
 
@@ -698,35 +740,60 @@
 status_t
 DavicomDevice::StartDevice()
 {
-       size_t actualLength = 0;
-/*ASX
-       for(size_t i = 0; i < sizeof(fIPG)/sizeof(fIPG[0]); i++) {
-               
-               status_t result = gUSBModule->send_request(fDevice, 
-                                       USB_REQTYPE_VENDOR | 
USB_REQTYPE_DEVICE_OUT,
-                                       WRITE_IPG0, 0, 0, sizeof(fIPG[i]), 
&fIPG[i], &actualLength);
-       
-               if(result != B_OK) {
-                       TRACE_ALWAYS("Error writing IPG%d: %#010x\n", i, 
result);
-                       return result;
-               }
+       uint8 tmp_reg;
 
-               if(actualLength != sizeof(fIPG[i])) {
-                       TRACE_ALWAYS("Mismatch of written IPG%d data. "
-                                       "%d bytes of %d written.\n", i, 
actualLength, sizeof(fIPG[i]));
-               }
+       /* disable loopback  */
+       status_t result = _ReadRegister(NCR, 1, &tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error reading NCR: %#010x.\n", result);
+               return result;
        }
-       uint16 rxcontrol = RXCTL_START | RXCTL_MULTICAST 
-                                                       | RXCTL_UNICAST | 
RXCTL_BROADCAST;
-       status_t result = WriteRXControlRegister(rxcontrol);
-       if(result != B_OK) {
-               TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", 
rxcontrol, result);
-       } 
+       tmp_reg &= ~NCR_LBK;
+       result = _Write1Register(NCR, tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error writing %#02X to NCR: %#010x.\n", tmp_reg, 
result);
+               return result;
+       }
 
-       TRACE_RET(result);
-       return result; 
-*/
-       return B_ERROR;
+       /* Initialize RX control register */
+       result = _ReadRegister(RCR, 1, &tmp_reg);
+       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);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error writing %#02X to RCR: %#010x.\n", tmp_reg, 
result);
+               return result;
+       }
+
+       /* clear POWER_DOWN state of internal PHY */
+       result = _ReadRegister(GPCR, 1, &tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error reading GPCR: %#010x.\n", result);
+               return result;
+       }
+       tmp_reg &= GPCR_GEP_CNTL0;
+       result = _Write1Register(GPCR, tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error writing %#02X to GPCR: %#010x.\n", tmp_reg, 
result);
+               return result;
+       }
+
+       result = _ReadRegister(GPR, 1, &tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error reading GPR: %#010x.\n", result);
+               return result;
+       }
+       tmp_reg &= ~GPR_GEP_GEPIO0;
+       result = _Write1Register(GPR, tmp_reg);
+       if (result != B_OK) {
+               TRACE_ALWAYS("Error writing %#02X to GPR: %#010x.\n", tmp_reg, 
result);
+               return result;
+       }
+
+       return B_OK;
 }
 
 
@@ -775,6 +842,7 @@
        if (linkStateChange && fLinkStateChangeSem >= B_OK)
                release_sem_etc(fLinkStateChangeSem, 1, B_DO_NOT_RESCHEDULE);
 */
+       TRACE_ALWAYS("OnNotify not implemented\n");
        return B_ERROR; // shoulb be B_OK when implemented :)
 }
 
@@ -814,6 +882,7 @@
                                                linkState->speed / 1000,
                                                (linkState->media & 
IFM_FULL_DUPLEX) ? "full" : "half");
 */
+       TRACE_ALWAYS("GetLinkState not implemented\n");
        return B_ERROR; // B_OK
 }
 

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 12:53:56 UTC (rev 34985)
+++ haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom/DavicomDevice.h  
2010-01-10 13:57:24 UTC (rev 34986)
@@ -55,6 +55,8 @@
                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);
 
 protected:
                /* overrides */


Other related posts:

  • » [haiku-commits] r34986 - haiku/trunk/src/add-ons/kernel/drivers/network/usb_davicom - pulkomandy