usb_asix: style cleanup

* While I was in the neighbourhood
* No functional change
This commit is contained in:
Alexander von Gluck IV
2013-04-04 23:36:16 -05:00
parent b208c3fa3b
commit 57419ce54f
4 changed files with 176 additions and 182 deletions
@@ -37,29 +37,29 @@ struct TRXHeader {
ASIXDevice::ASIXDevice(usb_device device, DeviceInfo& deviceInfo) ASIXDevice::ASIXDevice(usb_device device, DeviceInfo& deviceInfo)
: :
fDevice(device), fDevice(device),
fStatus(B_ERROR), fStatus(B_ERROR),
fOpen(false), fOpen(false),
fRemoved(false), fRemoved(false),
fHasConnection(false), fHasConnection(false),
fNonBlocking(false), fNonBlocking(false),
fInsideNotify(0), fInsideNotify(0),
fFrameSize(0), fFrameSize(0),
fNotifyEndpoint(0), fNotifyEndpoint(0),
fReadEndpoint(0), fReadEndpoint(0),
fWriteEndpoint(0), fWriteEndpoint(0),
fActualLengthRead(0), fActualLengthRead(0),
fActualLengthWrite(0), fActualLengthWrite(0),
fStatusRead(B_OK), fStatusRead(B_OK),
fStatusWrite(B_OK), fStatusWrite(B_OK),
fNotifyReadSem(-1), fNotifyReadSem(-1),
fNotifyWriteSem(-1), fNotifyWriteSem(-1),
fNotifyBuffer(NULL), fNotifyBuffer(NULL),
fNotifyBufferLength(0), fNotifyBufferLength(0),
fLinkStateChangeSem(-1), fLinkStateChangeSem(-1),
fUseTRXHeader(false), fUseTRXHeader(false),
fReadNodeIDRequest(kInvalidRequest) fReadNodeIDRequest(kInvalidRequest)
{ {
fDeviceInfo = deviceInfo; fDeviceInfo = deviceInfo;
@@ -72,14 +72,14 @@ ASIXDevice::ASIXDevice(usb_device device, DeviceInfo& deviceInfo)
fNotifyReadSem = create_sem(0, DRIVER_NAME"_notify_read"); fNotifyReadSem = create_sem(0, DRIVER_NAME"_notify_read");
if (fNotifyReadSem < B_OK) { if (fNotifyReadSem < B_OK) {
TRACE_ALWAYS("Error of creating read notify semaphore:%#010x\n", TRACE_ALWAYS("Error of creating read notify semaphore:%#010x\n",
fNotifyReadSem); fNotifyReadSem);
return; return;
} }
fNotifyWriteSem = create_sem(0, DRIVER_NAME"_notify_write"); fNotifyWriteSem = create_sem(0, DRIVER_NAME"_notify_write");
if (fNotifyWriteSem < B_OK) { if (fNotifyWriteSem < B_OK) {
TRACE_ALWAYS("Error of creating write notify semaphore:%#010x\n", TRACE_ALWAYS("Error of creating write notify semaphore:%#010x\n",
fNotifyWriteSem); fNotifyWriteSem);
return; return;
} }
@@ -122,7 +122,7 @@ ASIXDevice::Open(uint32 flags)
// setup state notifications // setup state notifications
result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer, result = gUSBModule->queue_interrupt(fNotifyEndpoint, fNotifyBuffer,
fNotifyBufferLength, _NotifyCallback, this); fNotifyBufferLength, _NotifyCallback, this);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of requesting notify interrupt:%#010x\n", result); TRACE_ALWAYS("Error of requesting notify interrupt:%#010x\n", result);
return result; return result;
@@ -170,7 +170,7 @@ ASIXDevice::Read(uint8 *buffer, size_t *numBytes)
if (fRemoved) { if (fRemoved) {
TRACE_ALWAYS("Error of receiving %d bytes from removed device.\n", TRACE_ALWAYS("Error of receiving %d bytes from removed device.\n",
numBytesToRead); numBytesToRead);
return B_DEVICE_NOT_FOUND; return B_DEVICE_NOT_FOUND;
} }
@@ -186,7 +186,8 @@ ASIXDevice::Read(uint8 *buffer, size_t *numBytes)
size_t chunkCount = fUseTRXHeader ? 2 : 1 ; size_t chunkCount = fUseTRXHeader ? 2 : 1 ;
status_t result = gUSBModule->queue_bulk_v(fReadEndpoint, status_t result = gUSBModule->queue_bulk_v(fReadEndpoint,
&rxData[startIndex], chunkCount, _ReadCallback, this); &rxData[startIndex], chunkCount, _ReadCallback, this);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of queue_bulk_v request:%#010x\n", result); TRACE_ALWAYS("Error of queue_bulk_v request:%#010x\n", result);
return result; return result;
@@ -205,7 +206,7 @@ ASIXDevice::Read(uint8 *buffer, size_t *numBytes)
USB_FEATURE_ENDPOINT_HALT); USB_FEATURE_ENDPOINT_HALT);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error during clearing of HALT state:%#010x.\n", TRACE_ALWAYS("Error during clearing of HALT state:%#010x.\n",
result); result);
return result; return result;
} }
} }
@@ -213,13 +214,13 @@ ASIXDevice::Read(uint8 *buffer, size_t *numBytes)
if (fUseTRXHeader) { if (fUseTRXHeader) {
if (fActualLengthRead < sizeof(TRXHeader)) { if (fActualLengthRead < sizeof(TRXHeader)) {
TRACE_ALWAYS("Error: no place for TRXHeader:only %d of %d bytes.\n", TRACE_ALWAYS("Error: no place for TRXHeader:only %d of %d bytes.\n",
fActualLengthRead, sizeof(TRXHeader)); fActualLengthRead, sizeof(TRXHeader));
return B_ERROR; // TODO: ??? return B_ERROR; // TODO: ???
} }
if (!header.IsValid()) { if (!header.IsValid()) {
TRACE_ALWAYS("Error:TRX Header is invalid: len:%#04x; ilen:%#04x\n", TRACE_ALWAYS("Error:TRX Header is invalid: len:%#04x; ilen:%#04x\n",
header.fLength, header.fInvertedLength); header.fLength, header.fInvertedLength);
return B_ERROR; // TODO: ??? return B_ERROR; // TODO: ???
} }
@@ -227,7 +228,7 @@ ASIXDevice::Read(uint8 *buffer, size_t *numBytes)
if (fActualLengthRead - sizeof(TRXHeader) > header.Length()) { if (fActualLengthRead - sizeof(TRXHeader) > header.Length()) {
TRACE_ALWAYS("MISMATCH of the frame length: hdr %d; received:%d\n", TRACE_ALWAYS("MISMATCH of the frame length: hdr %d; received:%d\n",
header.Length(), fActualLengthRead - sizeof(TRXHeader)); header.Length(), fActualLengthRead - sizeof(TRXHeader));
} }
} else { } else {
@@ -248,7 +249,7 @@ ASIXDevice::Write(const uint8 *buffer, size_t *numBytes)
if (fRemoved) { if (fRemoved) {
TRACE_ALWAYS("Error of writing %d bytes to removed device.\n", TRACE_ALWAYS("Error of writing %d bytes to removed device.\n",
numBytesToWrite); numBytesToWrite);
return B_DEVICE_NOT_FOUND; return B_DEVICE_NOT_FOUND;
} }
@@ -264,7 +265,8 @@ ASIXDevice::Write(const uint8 *buffer, size_t *numBytes)
size_t chunkCount = fUseTRXHeader ? 2 : 1 ; size_t chunkCount = fUseTRXHeader ? 2 : 1 ;
status_t result = gUSBModule->queue_bulk_v(fWriteEndpoint, status_t result = gUSBModule->queue_bulk_v(fWriteEndpoint,
&txData[startIndex], chunkCount, _WriteCallback, this); &txData[startIndex], chunkCount, _WriteCallback, this);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of queue_bulk_v request:%#010x\n", result); TRACE_ALWAYS("Error of queue_bulk_v request:%#010x\n", result);
return result; return result;
@@ -380,17 +382,18 @@ ASIXDevice::SetupDevice(bool deviceReplugged)
} }
TRACE("MAC address is:%02x:%02x:%02x:%02x:%02x:%02x\n", TRACE("MAC address is:%02x:%02x:%02x:%02x:%02x:%02x\n",
address.ebyte[0], address.ebyte[1], address.ebyte[2], address.ebyte[0], address.ebyte[1], address.ebyte[2],
address.ebyte[3], address.ebyte[4], address.ebyte[5]); address.ebyte[3], address.ebyte[4], address.ebyte[5]);
if (deviceReplugged) { if (deviceReplugged) {
// this might be the same device that was replugged - read the MAC // this might be the same device that was replugged - read the MAC
// address (which should be at the same index) to make sure // address (which should be at the same index) to make sure
if (memcmp(&address, &fMACAddress, sizeof(address)) != 0) { if (memcmp(&address, &fMACAddress, sizeof(address)) != 0) {
TRACE_ALWAYS("Cannot replace device with MAC address:" TRACE_ALWAYS("Cannot replace device with MAC address:"
"%02x:%02x:%02x:%02x:%02x:%02x\n", "%02x:%02x:%02x:%02x:%02x:%02x\n", fMACAddress.ebyte[0],
fMACAddress.ebyte[0], fMACAddress.ebyte[1], fMACAddress.ebyte[2], fMACAddress.ebyte[1], fMACAddress.ebyte[2],
fMACAddress.ebyte[3], fMACAddress.ebyte[4], fMACAddress.ebyte[5]); fMACAddress.ebyte[3], fMACAddress.ebyte[4],
fMACAddress.ebyte[5]);
return B_BAD_VALUE; // is not the same return B_BAD_VALUE; // is not the same
} }
} else } else
@@ -473,30 +476,26 @@ ASIXDevice::_SetupEndpoints()
for (size_t ep = 0; ep < interface->endpoint_count; ep++) { for (size_t ep = 0; ep < interface->endpoint_count; ep++) {
usb_endpoint_descriptor *epd = interface->endpoint[ep].descr; usb_endpoint_descriptor *epd = interface->endpoint[ep].descr;
if ((epd->attributes & USB_ENDPOINT_ATTR_MASK) if ((epd->attributes & USB_ENDPOINT_ATTR_MASK)
== USB_ENDPOINT_ATTR_INTERRUPT) == USB_ENDPOINT_ATTR_INTERRUPT) {
{
notifyEndpoint = ep; notifyEndpoint = ep;
continue; continue;
} }
if ((epd->attributes & USB_ENDPOINT_ATTR_MASK) if ((epd->attributes & USB_ENDPOINT_ATTR_MASK)
!= USB_ENDPOINT_ATTR_BULK) != USB_ENDPOINT_ATTR_BULK) {
{
TRACE_ALWAYS("Error: USB endpoint type %#04x is unknown.\n", TRACE_ALWAYS("Error: USB endpoint type %#04x is unknown.\n",
epd->attributes); epd->attributes);
continue; continue;
} }
if ((epd->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN) if ((epd->endpoint_address & USB_ENDPOINT_ADDR_DIR_IN)
== USB_ENDPOINT_ADDR_DIR_IN) == USB_ENDPOINT_ADDR_DIR_IN) {
{
readEndpoint = ep; readEndpoint = ep;
continue; continue;
} }
if ((epd->endpoint_address & USB_ENDPOINT_ADDR_DIR_OUT) if ((epd->endpoint_address & USB_ENDPOINT_ADDR_DIR_OUT)
== USB_ENDPOINT_ADDR_DIR_OUT) == USB_ENDPOINT_ADDR_DIR_OUT) {
{
writeEndpoint = ep; writeEndpoint = ep;
continue; continue;
} }
@@ -504,16 +503,16 @@ ASIXDevice::_SetupEndpoints()
if (notifyEndpoint == -1 || readEndpoint == -1 || writeEndpoint == -1) { if (notifyEndpoint == -1 || readEndpoint == -1 || writeEndpoint == -1) {
TRACE_ALWAYS("Error: not all USB endpoints were found: " TRACE_ALWAYS("Error: not all USB endpoints were found: "
"notify:%d; read:%d; write:%d\n", "notify:%d; read:%d; write:%d\n", notifyEndpoint, readEndpoint,
notifyEndpoint, readEndpoint, writeEndpoint); writeEndpoint);
return B_ERROR; return B_ERROR;
} }
gUSBModule->set_configuration(fDevice, config); gUSBModule->set_configuration(fDevice, config);
fNotifyEndpoint = interface->endpoint[notifyEndpoint].handle; fNotifyEndpoint = interface->endpoint[notifyEndpoint].handle;
fReadEndpoint = interface->endpoint[readEndpoint ].handle; fReadEndpoint = interface->endpoint[readEndpoint].handle;
fWriteEndpoint = interface->endpoint[writeEndpoint ].handle; fWriteEndpoint = interface->endpoint[writeEndpoint].handle;
return B_OK; return B_OK;
} }
@@ -524,9 +523,9 @@ ASIXDevice::ReadMACAddress(ether_address_t *address)
{ {
size_t actual_length = 0; size_t actual_length = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, fReadNodeIDRequest,
fReadNodeIDRequest, 0, 0, sizeof(ether_address), 0, 0, sizeof(ether_address), address, &actual_length);
address, &actual_length);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of reading MAC address:%#010x\n", result); TRACE_ALWAYS("Error of reading MAC address:%#010x\n", result);
return result; return result;
@@ -549,14 +548,13 @@ ASIXDevice::ReadRXControlRegister(uint16 *rxcontrol)
*rxcontrol = 0; *rxcontrol = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, READ_RX_CONTROL,
READ_RX_CONTROL, 0, 0, 0, 0, sizeof(*rxcontrol), rxcontrol, &actual_length);
sizeof(*rxcontrol), rxcontrol, &actual_length);
if (sizeof(*rxcontrol) != actual_length) { if (sizeof(*rxcontrol) != actual_length) {
TRACE_ALWAYS("Mismatch during reading RX control register." TRACE_ALWAYS("Mismatch during reading RX control register."
"Read %d bytes instead of %d.\n", "Read %d bytes instead of %d.\n", actual_length,
actual_length, sizeof(*rxcontrol)); sizeof(*rxcontrol));
} }
return result; return result;
@@ -567,8 +565,8 @@ status_t
ASIXDevice::WriteRXControlRegister(uint16 rxcontrol) ASIXDevice::WriteRXControlRegister(uint16 rxcontrol)
{ {
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_RX_CONTROL,
WRITE_RX_CONTROL, rxcontrol, 0, 0, 0, 0); rxcontrol, 0, 0, 0, 0);
return result; return result;
} }
@@ -578,9 +576,8 @@ ASIXDevice::StopDevice()
{ {
status_t result = WriteRXControlRegister(0); status_t result = WriteRXControlRegister(0);
if (result != B_OK) { if (result != B_OK)
TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", 0, result); TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", 0, result);
}
TRACE_RET(result); TRACE_RET(result);
return result; return result;
@@ -607,7 +604,7 @@ ASIXDevice::SetPromiscuousMode(bool on)
if (result != B_OK ) { if (result != B_OK ) {
TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n",
rxcontrol, result); rxcontrol, result);
} }
TRACE_RET(result); TRACE_RET(result);
@@ -681,9 +678,9 @@ ASIXDevice::ModifyMulticastTable(bool join, ether_address_t* group)
// write multicast hash table // write multicast hash table
size_t actualLength = 0; size_t actualLength = 0;
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_MF_ARRAY,
WRITE_MF_ARRAY, 0, 0, 0, 0, hashLength, hashTable, &actualLength);
hashLength, hashTable, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error writing hash table in MAR: %#010x.\n", result); TRACE_ALWAYS("Error writing hash table in MAR: %#010x.\n", result);
return result; return result;
@@ -691,7 +688,7 @@ ASIXDevice::ModifyMulticastTable(bool join, ether_address_t* group)
if (actualLength != hashLength) if (actualLength != hashLength)
TRACE_ALWAYS("Incomplete writing of hash table: %d bytes of %d\n", TRACE_ALWAYS("Incomplete writing of hash table: %d bytes of %d\n",
actualLength, hashLength); actualLength, hashLength);
result = WriteRXControlRegister(rxcontrol); result = WriteRXControlRegister(rxcontrol);
if (result != B_OK) if (result != B_OK)
@@ -124,8 +124,8 @@ const uint16 maxFrameSize = 1518;
AX88172Device::AX88172Device(usb_device device, DeviceInfo& deviceInfo) AX88172Device::AX88172Device(usb_device device, DeviceInfo& deviceInfo)
: :
ASIXDevice(device, deviceInfo) ASIXDevice(device, deviceInfo)
{ {
fStatus = InitDevice(); fStatus = InitDevice();
} }
@@ -175,8 +175,8 @@ AX88172Device::StartDevice()
for (size_t i = 0; i < sizeof(fIPG) / sizeof(fIPG[0]); i++) { for (size_t i = 0; i < sizeof(fIPG) / sizeof(fIPG[0]); i++) {
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_IPG0,
WRITE_IPG0, 0, 0, sizeof(fIPG[i]), &fIPG[i], &actualLength); 0, 0, sizeof(fIPG[i]), &fIPG[i], &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error writing IPG%d: %#010x\n", i, result); TRACE_ALWAYS("Error writing IPG%d: %#010x\n", i, result);
@@ -193,7 +193,7 @@ AX88172Device::StartDevice()
status_t result = WriteRXControlRegister(rxcontrol); status_t result = WriteRXControlRegister(rxcontrol);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n",
rxcontrol, result); rxcontrol, result);
} }
TRACE_RET(result); TRACE_RET(result);
@@ -206,7 +206,7 @@ AX88172Device::OnNotify(uint32 actualLength)
{ {
if (actualLength < sizeof(AX88172Notify)) { if (actualLength < sizeof(AX88172Notify)) {
TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n", TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n",
actualLength, sizeof(AX88172Notify)); actualLength, sizeof(AX88172Notify));
return B_BAD_DATA; return B_BAD_DATA;
} }
@@ -214,7 +214,7 @@ AX88172Device::OnNotify(uint32 actualLength)
if (notification->btA1 != 0xa1) { if (notification->btA1 != 0xa1) {
TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n", TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n",
notification->btA1); notification->btA1);
} }
uint phyIndex = 0; uint phyIndex = 0;
@@ -222,11 +222,13 @@ AX88172Device::OnNotify(uint32 actualLength)
switch(fMII.ActivePHY()) { switch(fMII.ActivePHY()) {
case PrimaryPHY: case PrimaryPHY:
phyIndex = 1; phyIndex = 1;
linkIsUp = (notification->btNN & LINK_STATE_PHY1) == LINK_STATE_PHY1; linkIsUp = (notification->btNN & LINK_STATE_PHY1)
== LINK_STATE_PHY1;
break; break;
case SecondaryPHY: case SecondaryPHY:
phyIndex = 2; phyIndex = 2;
linkIsUp = (notification->btNN & LINK_STATE_PHY2) == LINK_STATE_PHY2; linkIsUp = (notification->btNN & LINK_STATE_PHY2)
== LINK_STATE_PHY2;
break; break;
default: default:
case CurrentPHY: case CurrentPHY:
@@ -239,7 +241,7 @@ AX88172Device::OnNotify(uint32 actualLength)
if (linkStateChange) { if (linkStateChange) {
TRACE("Link state of PHY%d has been changed to '%s'\n", TRACE("Link state of PHY%d has been changed to '%s'\n",
phyIndex, fHasConnection ? "up" : "down"); phyIndex, fHasConnection ? "up" : "down");
} }
if (linkStateChange && fLinkStateChangeSem >= B_OK) if (linkStateChange && fLinkStateChangeSem >= B_OK)
@@ -275,15 +277,15 @@ AX88172Device::GetLinkState(ether_link_state *linkState)
linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0); linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0);
linkState->media |= mediumStatus & (ANLPAR_TX_FD | ANLPAR_10_FD) ? linkState->media |= mediumStatus & (ANLPAR_TX_FD | ANLPAR_10_FD) ?
IFM_FULL_DUPLEX : IFM_HALF_DUPLEX; IFM_FULL_DUPLEX : IFM_HALF_DUPLEX;
linkState->speed = mediumStatus & (ANLPAR_TX_FD | ANLPAR_TX_HD) linkState->speed = mediumStatus & (ANLPAR_TX_FD | ANLPAR_TX_HD)
? 100000000 : 10000000; ? 100000000 : 10000000;
TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n", TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n",
(linkState->media & IFM_ACTIVE) ? "active" : "inactive", (linkState->media & IFM_ACTIVE) ? "active" : "inactive",
linkState->speed / 1000000, linkState->speed / 1000000,
(linkState->media & IFM_FULL_DUPLEX) ? "full" : "half"); (linkState->media & IFM_FULL_DUPLEX) ? "full" : "half");
return B_OK; return B_OK;
} }
@@ -158,8 +158,8 @@ const uint16 maxFrameSize = 1536;
AX88178Device::AX88178Device(usb_device device, DeviceInfo& deviceInfo) AX88178Device::AX88178Device(usb_device device, DeviceInfo& deviceInfo)
: :
ASIXDevice(device, deviceInfo) ASIXDevice(device, deviceInfo)
{ {
fStatus = InitDevice(); fStatus = InitDevice();
} }
@@ -202,8 +202,8 @@ AX88178Device::SetupDevice(bool deviceReplugged)
size_t actualLength = 0; size_t actualLength = 0;
// get the "magic" word from EEPROM // get the "magic" word from EEPROM
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SROM_ENABLE,
WRITE_SROM_ENABLE, 0, 0, 0, 0, &actualLength); 0, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of enabling SROM access:%#010x\n", result); TRACE_ALWAYS("Error of enabling SROM access:%#010x\n", result);
@@ -212,9 +212,8 @@ AX88178Device::SetupDevice(bool deviceReplugged)
uint16 eepromData = 0; uint16 eepromData = 0;
status_t op_result = gUSBModule->send_request(fDevice, status_t op_result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, READ_SROM,
READ_SROM, 0x17, 0, 0x17, 0, sizeof(eepromData), &eepromData, &actualLength);
sizeof(eepromData), &eepromData, &actualLength);
if (op_result != B_OK) { if (op_result != B_OK) {
TRACE_ALWAYS("Error of reading SROM data:%#010x\n", result); TRACE_ALWAYS("Error of reading SROM data:%#010x\n", result);
@@ -222,13 +221,12 @@ AX88178Device::SetupDevice(bool deviceReplugged)
if (actualLength != sizeof(eepromData)) { if (actualLength != sizeof(eepromData)) {
TRACE_ALWAYS("Mismatch of reading SROM data." TRACE_ALWAYS("Mismatch of reading SROM data."
"Read %d bytes instead of %d\n", "Read %d bytes instead of %d\n", actualLength, sizeof(eepromData));
actualLength, sizeof(eepromData));
} }
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SROM_DISABLE,
WRITE_SROM_DISABLE, 0, 0, 0, 0, &actualLength); 0, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of disabling SROM access: %#010x\n", result); TRACE_ALWAYS("Error of disabling SROM access: %#010x\n", result);
@@ -261,15 +259,14 @@ AX88178Device::SetupDevice(bool deviceReplugged)
for (size_t i = from; i <= to; i++) { for (size_t i = from; i <= to; i++) {
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_GPIOS,
WRITE_GPIOS, GPIOCommands[i].value, GPIOCommands[i].value, 0, 0, 0, &actualLength);
0, 0, 0, &actualLength);
snooze(GPIOCommands[i].delay); snooze(GPIOCommands[i].delay);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of GPIO setup command %d:[%#04x]: %#010x\n", TRACE_ALWAYS("Error of GPIO setup command %d:[%#04x]: %#010x\n",
i, GPIOCommands[i].value, result); i, GPIOCommands[i].value, result);
return result; return result;
} }
} }
@@ -277,8 +274,8 @@ AX88178Device::SetupDevice(bool deviceReplugged)
uint8 uSWReset = 0; uint8 uSWReset = 0;
// finally a bit of exercises for SW reset register... // finally a bit of exercises for SW reset register...
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SOFT_RESET,
WRITE_SOFT_RESET, uSWReset, 0, 0, 0, &actualLength); uSWReset, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of SW reset to %#02x: %#010x\n", uSWReset, result); TRACE_ALWAYS("Error of SW reset to %#02x: %#010x\n", uSWReset, result);
@@ -289,8 +286,8 @@ AX88178Device::SetupDevice(bool deviceReplugged)
uSWReset = SW_RESET_PRL | SW_RESET_BIT6; uSWReset = SW_RESET_PRL | SW_RESET_BIT6;
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SOFT_RESET,
WRITE_SOFT_RESET, uSWReset, 0, 0, 0, &actualLength); uSWReset, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of SW reset to %#02x: %#010x\n", uSWReset, result); TRACE_ALWAYS("Error of SW reset to %#02x: %#010x\n", uSWReset, result);
@@ -317,8 +314,8 @@ AX88178Device::StartDevice()
{ {
size_t actualLength = 0; size_t actualLength = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_IPGS,
WRITE_IPGS, 0, 0, sizeof(fIPG), fIPG, &actualLength); 0, 0, sizeof(fIPG), fIPG, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of writing IPGs:%#010x\n", result); TRACE_ALWAYS("Error of writing IPGs:%#010x\n", result);
@@ -327,14 +324,14 @@ AX88178Device::StartDevice()
if (actualLength != sizeof(fIPG)) { if (actualLength != sizeof(fIPG)) {
TRACE_ALWAYS("Mismatch of written IPGs data. " TRACE_ALWAYS("Mismatch of written IPGs data. "
"%d bytes of %d written.\n", actualLength, sizeof(fIPG)); "%d bytes of %d written.\n", actualLength, sizeof(fIPG));
} }
uint16 rxcontrol = RXCTL_START | RXCTL_BROADCAST; uint16 rxcontrol = RXCTL_START | RXCTL_BROADCAST;
result = WriteRXControlRegister(rxcontrol); result = WriteRXControlRegister(rxcontrol);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n", TRACE_ALWAYS("Error of writing %#04x RX Control:%#010x\n",
rxcontrol, result); rxcontrol, result);
} }
TRACE_RET(result); TRACE_RET(result);
@@ -347,7 +344,7 @@ AX88178Device::OnNotify(uint32 actualLength)
{ {
if (actualLength < sizeof(AX88178_Notify)) { if (actualLength < sizeof(AX88178_Notify)) {
TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n", TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n",
actualLength, sizeof(AX88178_Notify)); actualLength, sizeof(AX88178_Notify));
return B_BAD_DATA; return B_BAD_DATA;
} }
@@ -355,7 +352,7 @@ AX88178Device::OnNotify(uint32 actualLength)
if (notification->btA1 != 0xa1) { if (notification->btA1 != 0xa1) {
TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n", TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n",
notification->btA1); notification->btA1);
} }
uint phyIndex = 0; uint phyIndex = 0;
@@ -363,11 +360,13 @@ AX88178Device::OnNotify(uint32 actualLength)
switch(fMII.ActivePHY()) { switch(fMII.ActivePHY()) {
case PrimaryPHY: case PrimaryPHY:
phyIndex = 1; phyIndex = 1;
linkIsUp = (notification->btBB & LINK_STATE_PPLS) == LINK_STATE_PPLS; linkIsUp = (notification->btBB & LINK_STATE_PPLS)
== LINK_STATE_PPLS;
break; break;
case SecondaryPHY: case SecondaryPHY:
phyIndex = 2; phyIndex = 2;
linkIsUp = (notification->btBB & LINK_STATE_SPLS) == LINK_STATE_SPLS; linkIsUp = (notification->btBB & LINK_STATE_SPLS)
== LINK_STATE_SPLS;
break; break;
default: default:
case CurrentPHY: case CurrentPHY:
@@ -380,7 +379,7 @@ AX88178Device::OnNotify(uint32 actualLength)
if (linkStateChange) { if (linkStateChange) {
TRACE("Link state of PHY%d has been changed to '%s'\n", TRACE("Link state of PHY%d has been changed to '%s'\n",
phyIndex, fHasConnection ? "up" : "down"); phyIndex, fHasConnection ? "up" : "down");
} }
if (linkStateChange && fLinkStateChangeSem >= B_OK) if (linkStateChange && fLinkStateChangeSem >= B_OK)
@@ -396,9 +395,8 @@ AX88178Device::GetLinkState(ether_link_state *linkState)
size_t actualLength = 0; size_t actualLength = 0;
uint16 mediumStatus = 0; uint16 mediumStatus = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, READ_MEDIUM_STATUS,
READ_MEDIUM_STATUS, 0, 0, sizeof(mediumStatus), 0, 0, sizeof(mediumStatus), &mediumStatus, &actualLength);
&mediumStatus, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of reading medium status:%#010x.\n", result); TRACE_ALWAYS("Error of reading medium status:%#010x.\n", result);
@@ -415,19 +413,19 @@ AX88178Device::GetLinkState(ether_link_state *linkState)
linkState->quality = 1000; linkState->quality = 1000;
linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0); linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0);
linkState->media |= (mediumStatus & MEDIUM_STATE_FD) ? linkState->media |= (mediumStatus & MEDIUM_STATE_FD) ?
IFM_FULL_DUPLEX : IFM_HALF_DUPLEX; IFM_FULL_DUPLEX : IFM_HALF_DUPLEX;
linkState->speed = (mediumStatus & MEDIUM_STATE_PS_100) linkState->speed = (mediumStatus & MEDIUM_STATE_PS_100)
? 100000000 : 10000000; ? 100000000 : 10000000;
linkState->speed = (mediumStatus & MEDIUM_STATE_GM) ? linkState->speed = (mediumStatus & MEDIUM_STATE_GM) ?
1000000000 : linkState->speed; 1000000000 : linkState->speed;
TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n", TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n",
(linkState->media & IFM_ACTIVE) ? "active" : "inactive", (linkState->media & IFM_ACTIVE) ? "active" : "inactive",
linkState->speed / 1000000, linkState->speed / 1000000,
(linkState->media & IFM_FULL_DUPLEX) ? "full" : "half"); (linkState->media & IFM_FULL_DUPLEX) ? "full" : "half");
return B_OK; return B_OK;
} }
@@ -203,8 +203,8 @@ const uint16 maxFrameSize = 1536;
AX88772Device::AX88772Device(usb_device device, DeviceInfo& deviceInfo) AX88772Device::AX88772Device(usb_device device, DeviceInfo& deviceInfo)
: :
ASIXDevice(device, deviceInfo) ASIXDevice(device, deviceInfo)
{ {
fStatus = InitDevice(); fStatus = InitDevice();
} }
@@ -290,12 +290,10 @@ AX88772Device::SetupDevice(bool deviceReplugged)
size_t actualLength = 0; size_t actualLength = 0;
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_MEDIUM_MODE,
WRITE_MEDIUM_MODE, MEDIUM_STATE_FD | MEDIUM_STATE_BIT2 | MEDIUM_STATE_RFC
MEDIUM_STATE_FD | MEDIUM_STATE_BIT2 | | MEDIUM_STATE_TFC | MEDIUM_STATE_RE | MEDIUM_STATE_PS_100,
MEDIUM_STATE_RFC| MEDIUM_STATE_TFC | 0, 0, 0, &actualLength);
MEDIUM_STATE_RE | MEDIUM_STATE_PS_100,
0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of setting medium mode: %#010x\n", result); TRACE_ALWAYS("Error of setting medium mode: %#010x\n", result);
@@ -313,8 +311,8 @@ AX88772Device::_SetupAX88772()
// enable GPIO2 - magic from FreeBSD's if_axe // enable GPIO2 - magic from FreeBSD's if_axe
uint16 GPIOs = GPIO_OO_2EN | GPIO_IO_2 | GPIO_RSE; uint16 GPIOs = GPIO_OO_2EN | GPIO_IO_2 | GPIO_RSE;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_GPIOS,
WRITE_GPIOS, GPIOs, 0, 0, 0, &actualLength); GPIOs, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of wrinting GPIOs: %#010x\n", result); TRACE_ALWAYS("Error of wrinting GPIOs: %#010x\n", result);
@@ -323,16 +321,16 @@ AX88772Device::_SetupAX88772()
// select PHY // select PHY
bool useEmbeddedPHY = fMII.PHYID() == PHYIDEmbedded; bool useEmbeddedPHY = fMII.PHYID() == PHYIDEmbedded;
uint16 selectPHY = useEmbeddedPHY ? uint16 selectPHY = useEmbeddedPHY
SW_PHY_SEL_STATUS_INT : SW_PHY_SEL_STATUS_EXT; ? SW_PHY_SEL_STATUS_INT : SW_PHY_SEL_STATUS_EXT;
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT,
WRITE_PHY_SEL, selectPHY, 0, 0, 0, &actualLength); WRITE_PHY_SEL, selectPHY, 0, 0, 0, &actualLength);
snooze(10000); snooze(10000);
TRACE("Selecting %s PHY[%#02x].\n", TRACE("Selecting %s PHY[%#02x].\n",
useEmbeddedPHY ? "embedded" : "external", selectPHY); useEmbeddedPHY ? "embedded" : "external", selectPHY);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of selecting PHY:%#010x\n", result); TRACE_ALWAYS("Error of selecting PHY:%#010x\n", result);
@@ -362,15 +360,14 @@ AX88772Device::_SetupAX88772()
for (size_t i = from; i <= to; i++) { for (size_t i = from; i <= to; i++) {
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SOFT_RESET,
WRITE_SOFT_RESET, resetCommands[i].reset, resetCommands[i].reset, 0, 0, 0, &actualLength);
0, 0, 0, &actualLength);
snooze(resetCommands[i].delay); snooze(resetCommands[i].delay);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of SW reset command %d:[%#04x]: %#010x\n", TRACE_ALWAYS("Error of SW reset command %d:[%#04x]: %#010x\n",
i, resetCommands[i].reset, result); i, resetCommands[i].reset, result);
return result; return result;
} }
} }
@@ -386,19 +383,19 @@ AX88772Device::_WakeupPHY()
{ {
// select PHY // select PHY
bool useEmbeddedPHY = fMII.PHYID() == PHYIDEmbedded; bool useEmbeddedPHY = fMII.PHYID() == PHYIDEmbedded;
uint16 selectPHY = useEmbeddedPHY ? uint16 selectPHY = useEmbeddedPHY
SW_PHY_SEL_STATUS_INT : SW_PHY_SEL_STATUS_EXT; ? SW_PHY_SEL_STATUS_INT : SW_PHY_SEL_STATUS_EXT;
selectPHY |= SW_PHY_SEL_STATUS_SS_MII | SW_PHY_SEL_STATUS_SS_ENB; selectPHY |= SW_PHY_SEL_STATUS_SS_MII | SW_PHY_SEL_STATUS_SS_ENB;
size_t actualLength = 0; size_t actualLength = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_PHY_SEL,
WRITE_PHY_SEL, selectPHY, 0, 0, 0, &actualLength); selectPHY, 0, 0, 0, &actualLength);
snooze(31000); snooze(31000);
TRACE("Selecting %s PHY[%#02x].\n", TRACE("Selecting %s PHY[%#02x].\n",
useEmbeddedPHY ? "embedded" : "external", selectPHY); useEmbeddedPHY ? "embedded" : "external", selectPHY);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of selecting PHY:%#010x\n", result); TRACE_ALWAYS("Error of selecting PHY:%#010x\n", result);
@@ -417,15 +414,14 @@ AX88772Device::_WakeupPHY()
for (size_t i = 0; i < _countof(resetCommands); i++) { for (size_t i = 0; i < _countof(resetCommands); i++) {
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_SOFT_RESET,
WRITE_SOFT_RESET, resetCommands[i].reset, resetCommands[i].reset, 0, 0, 0, &actualLength);
0, 0, 0, &actualLength);
snooze(resetCommands[i].delay); snooze(resetCommands[i].delay);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of SW reset command %d:[%#04x]: %#010x\n", TRACE_ALWAYS("Error of SW reset command %d:[%#04x]: %#010x\n",
i, resetCommands[i].reset, result); i, resetCommands[i].reset, result);
return result; return result;
} }
} }
@@ -440,8 +436,8 @@ AX88772Device::_SetupAX88772A()
// Reload EEPROM // Reload EEPROM
size_t actualLength = 0; size_t actualLength = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_GPIOS,
WRITE_GPIOS, GPIO_RSE, 0, 0, 0, &actualLength); GPIO_RSE, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of reloading EEPROM: %#010x\n", result); TRACE_ALWAYS("Error of reloading EEPROM: %#010x\n", result);
@@ -466,8 +462,8 @@ AX88772Device::_SetupAX88772B()
// Reload EEPROM // Reload EEPROM
size_t actualLength = 0; size_t actualLength = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_GPIOS,
WRITE_GPIOS, GPIO_RSE, 0, 0, 0, &actualLength); GPIO_RSE, 0, 0, 0, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of reloading EEPROM: %#010x\n", result); TRACE_ALWAYS("Error of reloading EEPROM: %#010x\n", result);
@@ -491,8 +487,8 @@ AX88772Device::StartDevice()
{ {
size_t actualLength = 0; size_t actualLength = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_OUT, WRITE_IPGS,
WRITE_IPGS, 0, 0, sizeof(fIPG), fIPG, &actualLength); 0, 0, sizeof(fIPG), fIPG, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of writing IPGs:%#010x\n", result); TRACE_ALWAYS("Error of writing IPGs:%#010x\n", result);
@@ -501,12 +497,12 @@ AX88772Device::StartDevice()
if (actualLength != sizeof(fIPG)) { if (actualLength != sizeof(fIPG)) {
TRACE_ALWAYS("Mismatch of written IPGs data. " TRACE_ALWAYS("Mismatch of written IPGs data. "
"%d bytes of %d written.\n", actualLength, sizeof(fIPG)); "%d bytes of %d written.\n", actualLength, sizeof(fIPG));
} }
uint16 rxcontrol = 0; uint16 rxcontrol = 0;
// AX88772B uses different maximum frame burst configuration. // AX88772B uses different maximum frame burst configuration.
if (fDeviceInfo.fType == DeviceInfo::AX88772B) { if (fDeviceInfo.fType == DeviceInfo::AX88772B) {
result = gUSBModule->send_request(fDevice, result = gUSBModule->send_request(fDevice,
@@ -524,7 +520,7 @@ AX88772Device::StartDevice()
} else { } else {
// TODO: FreeBSD documents this to speed up xfers, I don't // TODO: FreeBSD documents this to speed up xfers, I don't
// have the hardware to test however. // have the hardware to test however.
//rxcontrol = RXCTL_USB_MFB_MAX; // rxcontrol = RXCTL_USB_MFB_MAX;
} }
rxcontrol |= RXCTL_START | RXCTL_BROADCAST; rxcontrol |= RXCTL_START | RXCTL_BROADCAST;
@@ -544,15 +540,15 @@ AX88772Device::OnNotify(uint32 actualLength)
{ {
if (actualLength < sizeof(AX88772_Notify)) { if (actualLength < sizeof(AX88772_Notify)) {
TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n", TRACE_ALWAYS("Data underrun error. %d of %d bytes received\n",
actualLength, sizeof(AX88772_Notify)); actualLength, sizeof(AX88772_Notify));
return B_BAD_DATA; return B_BAD_DATA;
} }
AX88772_Notify *notification = (AX88772_Notify *)fNotifyBuffer; AX88772_Notify *notification = (AX88772_Notify *)fNotifyBuffer;
if (notification->btA1 != 0xa1) { if (notification->btA1 != 0xa1) {
TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n", TRACE_ALWAYS("Notify magic byte is invalid: %#02x\n",
notification->btA1); notification->btA1);
} }
uint phyIndex = 0; uint phyIndex = 0;
@@ -560,11 +556,13 @@ AX88772Device::OnNotify(uint32 actualLength)
switch(fMII.ActivePHY()) { switch(fMII.ActivePHY()) {
case PrimaryPHY: case PrimaryPHY:
phyIndex = 1; phyIndex = 1;
linkIsUp = (notification->btBB & LINK_STATE_PPLS) == LINK_STATE_PPLS; linkIsUp = (notification->btBB & LINK_STATE_PPLS)
== LINK_STATE_PPLS;
break; break;
case SecondaryPHY: case SecondaryPHY:
phyIndex = 2; phyIndex = 2;
linkIsUp = (notification->btBB & LINK_STATE_SPLS) == LINK_STATE_SPLS; linkIsUp = (notification->btBB & LINK_STATE_SPLS)
== LINK_STATE_SPLS;
break; break;
default: default:
case CurrentPHY: case CurrentPHY:
@@ -577,7 +575,7 @@ AX88772Device::OnNotify(uint32 actualLength)
if (linkStateChange) { if (linkStateChange) {
TRACE("Link state of PHY%d has been changed to '%s'\n", TRACE("Link state of PHY%d has been changed to '%s'\n",
phyIndex, fHasConnection ? "up" : "down"); phyIndex, fHasConnection ? "up" : "down");
} }
if (linkStateChange && fLinkStateChangeSem >= B_OK) if (linkStateChange && fLinkStateChangeSem >= B_OK)
@@ -593,9 +591,8 @@ AX88772Device::GetLinkState(ether_link_state *linkState)
size_t actualLength = 0; size_t actualLength = 0;
uint16 mediumStatus = 0; uint16 mediumStatus = 0;
status_t result = gUSBModule->send_request(fDevice, status_t result = gUSBModule->send_request(fDevice,
USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, USB_REQTYPE_VENDOR | USB_REQTYPE_DEVICE_IN, READ_MEDIUM_STATUS,
READ_MEDIUM_STATUS, 0, 0, sizeof(mediumStatus), 0, 0, sizeof(mediumStatus), &mediumStatus, &actualLength);
&mediumStatus, &actualLength);
if (result != B_OK) { if (result != B_OK) {
TRACE_ALWAYS("Error of reading medium status:%#010x.\n", result); TRACE_ALWAYS("Error of reading medium status:%#010x.\n", result);
@@ -604,25 +601,25 @@ AX88772Device::GetLinkState(ether_link_state *linkState)
if (actualLength != sizeof(mediumStatus)) { if (actualLength != sizeof(mediumStatus)) {
TRACE_ALWAYS("Mismatch of reading medium status." TRACE_ALWAYS("Mismatch of reading medium status."
"Read %d bytes instead of %d\n", "Read %d bytes instead of %d\n", actualLength,
actualLength, sizeof(mediumStatus)); sizeof(mediumStatus));
} }
TRACE_FLOW("Medium status is %#04x\n", mediumStatus); TRACE_FLOW("Medium status is %#04x\n", mediumStatus);
linkState->quality = 1000; linkState->quality = 1000;
linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0); linkState->media = IFM_ETHER | (fHasConnection ? IFM_ACTIVE : 0);
linkState->media |= (mediumStatus & MEDIUM_STATE_FD) ? linkState->media |= (mediumStatus & MEDIUM_STATE_FD) ?
IFM_FULL_DUPLEX : IFM_HALF_DUPLEX; IFM_FULL_DUPLEX : IFM_HALF_DUPLEX;
linkState->speed = (mediumStatus & MEDIUM_STATE_PS_100) linkState->speed = (mediumStatus & MEDIUM_STATE_PS_100)
? 100000000 : 10000000; ? 100000000 : 10000000;
TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n", TRACE_FLOW("Medium state: %s, %lld MBit/s, %s duplex.\n",
(linkState->media & IFM_ACTIVE) ? "active" : "inactive", (linkState->media & IFM_ACTIVE) ? "active" : "inactive",
linkState->speed / 1000000, linkState->speed / 1000000,
(linkState->media & IFM_FULL_DUPLEX) ? "full" : "half"); (linkState->media & IFM_FULL_DUPLEX) ? "full" : "half");
return B_OK; return B_OK;
} }