style cleanup; tab fixes; no functional change

git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40363 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Alexander von Gluck IV
2011-02-05 16:59:02 +00:00
parent 96a8b92d21
commit 04249af074
3 changed files with 180 additions and 127 deletions
@@ -14,6 +14,7 @@
#include "Driver.h"
BeceemCPU::BeceemCPU()
{
TRACE("Debug: Load CPU handler\n");
@@ -32,9 +33,9 @@ BeceemCPU::CPUInit(WIMAX_DEVICE* swmxdevice)
status_t
BeceemCPU::CPURun()
{
unsigned int value = 0;
unsigned int clkReg = 0;
if (BizarroReadRegister(CLOCK_RESET_CNTRL_REG_1, sizeof(value), &value)
if (BizarroReadRegister(CLOCK_RESET_CNTRL_REG_1, sizeof(clkReg), &clkReg)
!= B_OK) {
TRACE_ALWAYS("Error: Read of clock reset reg failure\n");
@@ -42,12 +43,12 @@ BeceemCPU::CPURun()
}
if (pwmxdevice->CPUFlashBoot) {
value&=(~(1<<30));
clkReg &= (~(1<<30));
} else {
value |=(1<<30);
clkReg |= (1<<30);
}
if (BizarroWriteRegister(CLOCK_RESET_CNTRL_REG_1, sizeof(value), &value)
if (BizarroWriteRegister(CLOCK_RESET_CNTRL_REG_1, sizeof(clkReg), &clkReg)
!= B_OK) {
TRACE_ALWAYS("Error: Write of clock reset reg failure\n");
@@ -31,6 +31,7 @@
mutex gUSBLock;
// auto-release helper class
class USBSmartLock {
public:
@@ -375,7 +376,8 @@ BeceemDevice::Read(uint8 *buffer, size_t *numBytes)
}
// Safely tidy up after a major device hiccup
if (fStatusRead != B_OK && fStatusRead != B_CANCELED && !pwmxdevice->driverHalt) {
if (fStatusRead != B_OK && fStatusRead != B_CANCELED
&& !pwmxdevice->driverHalt) {
TRACE_ALWAYS("Error: Device status error:%#010x\n", fStatusRead);
result = gUSBModule->clear_feature(fReadEndpoint,
USB_FEATURE_ENDPOINT_HALT);
@@ -431,13 +433,15 @@ BeceemDevice::Write(const uint8 *buffer, size_t *numBytes)
}
if (!fHasConnection) {
TRACE_ALWAYS("Error writing %d bytes to device while WiMAX connection down.\n",
TRACE_ALWAYS("Error writing %d bytes to device"
" while WiMAX connection down.\n",
numBytesToWrite);
return B_ERROR;
}
if (fTXBufferFull) {
TRACE_ALWAYS("Error writing %d bytes to device while TX buffer full.\n",
TRACE_ALWAYS("Error writing %d bytes to device"
" while TX buffer full.\n",
numBytesToWrite);
return B_ERROR;
}
@@ -476,7 +480,8 @@ BeceemDevice::Write(const uint8 *buffer, size_t *numBytes)
USB_FEATURE_ENDPOINT_HALT);
if (result != B_OK) {
TRACE_ALWAYS("Error during clearing of HALT state:%#010x\n", result);
TRACE_ALWAYS("Error during clearing of HALT state:"
" %#010x\n", result);
return result;
}
}
@@ -652,7 +657,7 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
{
BizarroReadRegister(SYS_CFG, sizeof(value), &value);
pwmxdevice->syscfgBefFw = value;
if((value & 0x60)== 0)
if ((value & 0x60)== 0)
{
TRACE("Debug: CPU is FlashBoot\n");
pwmxdevice->CPUFlashBoot = true;
@@ -683,18 +688,21 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
// Each bcm chip has a custom binary config
// telling the device about itself (how it was designed)
if (PushConfig(CONF_BEGIN_ADDR) != B_OK) {
TRACE_ALWAYS("Vendor configuration push failed, aborting device setup.\n");
TRACE_ALWAYS("Vendor configuration push failed."
" Aborting device setup.\n");
return B_ERROR;
}
// Set up GPIO (nvmVer 5+ is double sized)
if (pwmxdevice->nvmVerMajor < 5) {
TRACE("Debug: VerMajor < 5 PARAM pointer\n");
NVMRead(GPIO_PARAM_POINTER, 2, (unsigned int*)&pwmxdevice->hwParamPtr);
NVMRead(GPIO_PARAM_POINTER, 2,
(unsigned int*)&pwmxdevice->hwParamPtr);
pwmxdevice->hwParamPtr = ntohs(pwmxdevice->hwParamPtr);
} else {
TRACE("Debug: VerMajor 5+ PARAM pointer\n");
NVMRead(GPIO_PARAM_POINTER_MAP5, 4, (unsigned int*)&pwmxdevice->hwParamPtr);
NVMRead(GPIO_PARAM_POINTER_MAP5, 4,
(unsigned int*)&pwmxdevice->hwParamPtr);
// TODO : NVM : validate v5+ nvm params a-la ValidateDSDParamsChecksum
pwmxdevice->hwParamPtr = ntohl(pwmxdevice->hwParamPtr);
}
@@ -749,13 +757,14 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
address.ebyte[3], address.ebyte[4], address.ebyte[5]);
if (deviceReplugged) {
// this might be the same device that was replugged - read the MAC address
// (which should be at the same index) to make sure
// this might be the same device that was replugged - read the
// mac address (which should be at the same index) to make sure
if (memcmp(&address, &fMACAddress, sizeof(address)) != 0) {
TRACE_ALWAYS("Cannot replace device with MAC address:"
"%02x:%02x:%02x:%02x:%02x:%02x\n",
fMACAddress.ebyte[0], fMACAddress.ebyte[1], fMACAddress.ebyte[2],
fMACAddress.ebyte[3], fMACAddress.ebyte[4], fMACAddress.ebyte[5]);
fMACAddress.ebyte[0], fMACAddress.ebyte[1],
fMACAddress.ebyte[2], fMACAddress.ebyte[3],
fMACAddress.ebyte[4], fMACAddress.ebyte[5]);
return B_BAD_VALUE; // is not the same
}
} else
@@ -769,8 +778,9 @@ BeceemDevice::SetupDevice(bool deviceReplugged)
// TODO : Preserve stability
// Things will break past this point until things are more complete
// Prevent completion of device initilization to preseve system stability.
// Things will break past this point until the ethernet interface is more
// complete. Prevent completion of device initilization to preseve system
// and network stack stability.
#if 1
TRACE_ALWAYS("A Beceem WiMax device was attached, "
@@ -833,12 +843,14 @@ BeceemDevice::_SetupEndpoints()
= gUSBModule->get_nth_configuration(fDevice, 0);
if (config == NULL) {
TRACE_ALWAYS("Error: Failed to get USB device configuration.\n");
TRACE_ALWAYS("Error: Failed to get USB"
" device configuration.\n");
return B_ERROR;
}
if (config->interface_count <= 0) {
TRACE_ALWAYS("Error: No interfaces found in USB device configuration\n");
TRACE_ALWAYS("Error: No interfaces found"
" in USB device configuration\n");
return B_ERROR;
}
@@ -871,8 +883,8 @@ BeceemDevice::_SetupEndpoints()
== USB_ENDPOINT_ADDR_DIR_OUT)
writeEndpoint = ep;
else
TRACE_ALWAYS("Warning: BULK USB Endpoint %d (%#04x) is unknown.\n",
ep, epd->attributes);
TRACE_ALWAYS("Warning: BULK USB Endpoint"
" %d (%#04x) is unknown.\n", ep, epd->attributes);
} else if ((epd->attributes & USB_ENDPOINT_ATTR_MASK)
== USB_ENDPOINT_ATTR_ISOCHRONOUS) {
// Isochronous endpoint
@@ -968,11 +980,12 @@ BeceemDevice::_NotifyCallback(void *cookie, int32 status, void *data,
}
if (status != B_OK) {
TRACE_ALWAYS("Device status error:%#010x\n", status);
TRACE_ALWAYS("Device status error :%#010x\n", status);
status_t result = gUSBModule->clear_feature(device->fNotifyEndpoint,
USB_FEATURE_ENDPOINT_HALT);
USB_FEATURE_ENDPOINT_HALT);
if (result != B_OK)
TRACE_ALWAYS("Error during clearing of HALT state:%#010x.\n", result);
TRACE_ALWAYS("Error during clearing of HALT state:"
" %#010x.\n", result);
}
// parse data in overriden class
@@ -1029,42 +1042,19 @@ BeceemDevice::LoadConfig()
if (file_size != sizeof(VENDORCFG))
{
TRACE_ALWAYS("Error: Size mismatch in vendor configuration structure!\n");
TRACE_ALWAYS("Error: Size mismatch in vendor configuration struct!\n");
close(fh);
free(buffer);
return B_ERROR;
} else {
TRACE_ALWAYS("Info: Found valid vendor configuration %ld bytes long.\n", file_size);
TRACE_ALWAYS("Info: Found valid vendor configuration"
" %ld bytes long.\n", file_size);
}
// we copy the configuration into our fancy struct to know what the device knows
// we copy the configuration into our struct to know what the device knows
memcpy(&pwmxdevice->vendorcfg, buffer, sizeof(VENDORCFG));
TRACE("Debug: Vendor Config: Config File Version is 0x%x\n", pwmxdevice->vendorcfg.m_u32CfgVersion);
TRACE("Debug: Vendor Config: Center Frequency is 0x%x\n", pwmxdevice->vendorcfg.m_u32CenterFrequency);
TRACE("Debug: Vendor Config: Band A Scan = 0x%x\n", pwmxdevice->vendorcfg.m_u32BandAScan);
TRACE("Debug: Vendor Config: Band B Scan = 0x%x\n", pwmxdevice->vendorcfg.m_u32BandBScan);
TRACE("Debug: Vendor Config: Band C Scan = 0x%x\n", pwmxdevice->vendorcfg.m_u32BandCScan);
TRACE("Debug: Vendor Config: PHS Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32PHSEnable);
TRACE("Debug: Vendor Config: Handoff Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32HoEnable);
TRACE("Debug: Vendor Config: HO Reserved1 = 0x%x\n", pwmxdevice->vendorcfg.m_u32HoReserved1);
TRACE("Debug: Vendor Config: HO Reserved2 = 0x%x\n", pwmxdevice->vendorcfg.m_u32HoReserved2);
TRACE("Debug: Vendor Config: MIMO Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32MimoEnable);
TRACE("Debug: Vendor Config: PKMv2 Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32SecurityEnable);
TRACE("Debug: Vendor Config: Power Saving Modes Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32PowerSavingModesEnable);
TRACE("Debug: Vendor Config: Power Saving Mode Options = 0x%x\n", pwmxdevice->vendorcfg.m_u32PowerSavingModeOptions);
TRACE("Debug: Vendor Config: ARQ Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32ArqEnable);
TRACE("Debug: Vendor Config: Harq Enable = 0x%x\n", pwmxdevice->vendorcfg.m_u32HarqEnable);
TRACE("Debug: Vendor Config: EEPROM Flag = 0x%x\n", pwmxdevice->vendorcfg.m_u32EEPROMFlag);
TRACE("Debug: Vendor Config: Customize = 0x%x\n", pwmxdevice->vendorcfg.m_u32Customize);
TRACE("Debug: Vendor Config: Bandwidth = 0x%x\n", pwmxdevice->vendorcfg.m_u32ConfigBW);
TRACE("Debug: Vendor Config: RadioParameter = 0x%x\n", pwmxdevice->vendorcfg.m_u32RadioParameter);
TRACE("Debug: Vendor Config: HostDrvrConfig1 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig1);
TRACE("Debug: Vendor Config: HostDrvrConfig2 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig2);
TRACE("Debug: Vendor Config: HostDrvrConfig3 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig3);
TRACE("Debug: Vendor Config: HostDrvrConfig4 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig4);
TRACE("Debug: Vendor Config: HostDrvrConfig5 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig5);
TRACE("Debug: Vendor Config: HostDrvrConfig6 is 0x%x\n", pwmxdevice->vendorcfg.HostDrvrConfig6);
DumpConfig();
close(fh);
free(buffer);
@@ -1073,6 +1063,62 @@ BeceemDevice::LoadConfig()
}
void
BeceemDevice::DumpConfig()
{
TRACE("Debug: Vendor Config: Config File Version is 0x%x\n",
pwmxdevice->vendorcfg.m_u32CfgVersion);
TRACE("Debug: Vendor Config: Center Frequency is 0x%x\n",
pwmxdevice->vendorcfg.m_u32CenterFrequency);
TRACE("Debug: Vendor Config: Band A Scan = 0x%x\n",
pwmxdevice->vendorcfg.m_u32BandAScan);
TRACE("Debug: Vendor Config: Band B Scan = 0x%x\n",
pwmxdevice->vendorcfg.m_u32BandBScan);
TRACE("Debug: Vendor Config: Band C Scan = 0x%x\n",
pwmxdevice->vendorcfg.m_u32BandCScan);
TRACE("Debug: Vendor Config: PHS Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32PHSEnable);
TRACE("Debug: Vendor Config: Handoff Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32HoEnable);
TRACE("Debug: Vendor Config: HO Reserved1 = 0x%x\n",
pwmxdevice->vendorcfg.m_u32HoReserved1);
TRACE("Debug: Vendor Config: HO Reserved2 = 0x%x\n",
pwmxdevice->vendorcfg.m_u32HoReserved2);
TRACE("Debug: Vendor Config: MIMO Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32MimoEnable);
TRACE("Debug: Vendor Config: PKMv2 Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32SecurityEnable);
TRACE("Debug: Vendor Config: Power Saving Modes Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32PowerSavingModesEnable);
TRACE("Debug: Vendor Config: Power Saving Mode Options = 0x%x\n",
pwmxdevice->vendorcfg.m_u32PowerSavingModeOptions);
TRACE("Debug: Vendor Config: ARQ Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32ArqEnable);
TRACE("Debug: Vendor Config: Harq Enable = 0x%x\n",
pwmxdevice->vendorcfg.m_u32HarqEnable);
TRACE("Debug: Vendor Config: EEPROM Flag = 0x%x\n",
pwmxdevice->vendorcfg.m_u32EEPROMFlag);
TRACE("Debug: Vendor Config: Customize = 0x%x\n",
pwmxdevice->vendorcfg.m_u32Customize);
TRACE("Debug: Vendor Config: Bandwidth = 0x%x\n",
pwmxdevice->vendorcfg.m_u32ConfigBW);
TRACE("Debug: Vendor Config: RadioParameter = 0x%x\n",
pwmxdevice->vendorcfg.m_u32RadioParameter);
TRACE("Debug: Vendor Config: HostDrvrConfig1 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig1);
TRACE("Debug: Vendor Config: HostDrvrConfig2 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig2);
TRACE("Debug: Vendor Config: HostDrvrConfig3 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig3);
TRACE("Debug: Vendor Config: HostDrvrConfig4 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig4);
TRACE("Debug: Vendor Config: HostDrvrConfig5 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig5);
TRACE("Debug: Vendor Config: HostDrvrConfig6 is 0x%x\n",
pwmxdevice->vendorcfg.HostDrvrConfig6);
}
status_t
BeceemDevice::PushConfig(unsigned int loc)
{
@@ -2,13 +2,13 @@
* Beceem WiMax USB Driver.
* Copyright (c) 2010 Alexander von Gluck <[email protected]>
* Distributed under the terms of the GNU General Public License.
*
*
* Based on GPL code developed by: Beceem Communications Pvt. Ltd
*
*
* Driver for USB Ethernet Control Model devices
* Copyright (C) 2008 Michael Lotz <[email protected]>
* Distributed under the terms of the MIT license.
*
*
* Description: Wrangle Beceem wimax usb device
*/
@@ -29,7 +29,8 @@
#define MAX_USB_IO_RETRIES 1
#define MAX_USB_TRANSFER 255
class BeceemDevice
class BeceemDevice
:
public BeceemNVM,
public BeceemDDR,
@@ -38,95 +39,100 @@ class BeceemDevice
{
public:
BeceemDevice(usb_device device, const char *description);
virtual ~BeceemDevice();
BeceemDevice(usb_device device,
const char *description);
virtual ~BeceemDevice();
status_t InitCheck() { return fStatus; };
status_t InitCheck() { return fStatus; };
status_t Open(uint32 flags);
bool IsOpen() { return fOpen; };
status_t Open(uint32 flags);
bool IsOpen() { return fOpen; };
status_t Close();
status_t Free();
status_t Close();
status_t Free();
status_t Read(uint8 *buffer, size_t *numBytes);
status_t Write(const uint8 *buffer, size_t *numBytes);
status_t Control(uint32 op, void *buffer, size_t length);
status_t LoadConfig();
status_t PushConfig(unsigned int loc);
status_t PushFirmware(unsigned int loc);
status_t Read(uint8 *buffer, size_t *numBytes);
status_t Write(const uint8 *buffer, size_t *numBytes);
status_t Control(uint32 op, void *buffer, size_t length);
status_t LoadConfig();
void DumpConfig();
status_t PushConfig(unsigned int loc);
status_t PushFirmware(unsigned int loc);
void Removed();
void Removed();
status_t CompareAndReattach(usb_device device);
virtual status_t SetupDevice(bool deviceReplugged);
status_t CompareAndReattach(usb_device device);
virtual status_t SetupDevice(bool deviceReplugged);
status_t ReadRegister(unsigned int reg, size_t size, uint32_t* buffer);
status_t WriteRegister(unsigned int reg, size_t size, uint32_t* buffer);
status_t BizarroReadRegister(unsigned int reg, size_t size, uint32_t* buffer);
status_t BizarroWriteRegister(unsigned int reg, size_t size, uint32_t* buffer);
status_t ReadRegister(unsigned int reg,
size_t size, uint32_t* buffer);
status_t WriteRegister(unsigned int reg,
size_t size, uint32_t* buffer);
status_t BizarroReadRegister(unsigned int reg,
size_t size, uint32_t* buffer);
status_t BizarroWriteRegister(unsigned int reg,
size_t size, uint32_t* buffer);
private:
static void _ReadCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
static void _WriteCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
static void _NotifyCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
static void _ReadCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
static void _WriteCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
static void _NotifyCallback(void *cookie, int32 status,
void *data, uint32 actualLength);
status_t _SetupEndpoints();
status_t _SetupEndpoints();
status_t IdentifyChipset();
status_t IdentifyChipset();
static const int kFrameSize = 1518;
static const uint8 kRXHeaderSize = 3;
static const uint8 kTXHeaderSize = 2;
static const int kFrameSize = 1518;
static const uint8 kRXHeaderSize = 3;
static const uint8 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);
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);
// state tracking
status_t fStatus;
bool fOpen;
vint32 fInsideNotify;
usb_device fDevice;
uint16 fVendorID;
uint16 fProductID;
const char * fDescription;
bool fNonBlocking;
// Our driver device struct
struct WIMAX_DEVICE *pwmxdevice;
// state tracking
status_t fStatus;
bool fOpen;
vint32 fInsideNotify;
usb_device fDevice;
uint16 fVendorID;
uint16 fProductID;
const char * fDescription;
bool fNonBlocking;
// pipes for notifications and data io
usb_pipe fNotifyEndpoint;
usb_pipe fReadEndpoint;
usb_pipe fWriteEndpoint;
struct WIMAX_DEVICE *pwmxdevice;
// Our driver device struct
// data stores for async usb transfers
uint32 fActualLengthRead;
uint32 fActualLengthWrite;
int32 fStatusRead;
int32 fStatusWrite;
sem_id fNotifyReadSem;
sem_id fNotifyWriteSem;
// pipes for notifications and data io
usb_pipe fNotifyEndpoint;
usb_pipe fReadEndpoint;
usb_pipe fWriteEndpoint;
uint8 * fNotifyBuffer;
uint32 fNotifyBufferLength;
// data stores for async usb transfers
uint32 fActualLengthRead;
uint32 fActualLengthWrite;
int32 fStatusRead;
int32 fStatusWrite;
sem_id fNotifyReadSem;
sem_id fNotifyWriteSem;
// connection data
sem_id fLinkStateChangeSem;
ether_address_t fMACAddress;
bool fHasConnection;
bool fTXBufferFull;
uint8 * fNotifyBuffer;
uint32 fNotifyBufferLength;
// connection data
sem_id fLinkStateChangeSem;
ether_address_t fMACAddress;
bool fHasConnection;
bool fTXBufferFull;
};
#endif //_USB_BECEEM_DEVICE_H_
#endif /*_USB_BECEEM_DEVICE_H_*/