Now actually sets the amount of bytes read when everything went okay (thanks
to Jack Burton for pointing this out). No longer sets the length on error, since this value is not propagated to the caller anyway in this case. git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7099 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
parent
684349b37a
commit
ac9d54bb91
@ -412,10 +412,8 @@ device_read(void *data, off_t pos, void *buffer, size_t *_length)
|
|||||||
uint32 check;
|
uint32 check;
|
||||||
int16 current;
|
int16 current;
|
||||||
|
|
||||||
if (checkDeviceInfo(info = data) != B_OK) {
|
if (checkDeviceInfo(info = data) != B_OK)
|
||||||
*_length = 0;
|
return B_BAD_VALUE;
|
||||||
return EINVAL;
|
|
||||||
}
|
|
||||||
|
|
||||||
//dprintf("read: rx: isr = %d, free = %d, current = %d\n",
|
//dprintf("read: rx: isr = %d, free = %d, current = %d\n",
|
||||||
// info->rxInterruptIndex, info->rxFree, info->rxCurrent);
|
// info->rxInterruptIndex, info->rxFree, info->rxCurrent);
|
||||||
@ -423,10 +421,8 @@ device_read(void *data, off_t pos, void *buffer, size_t *_length)
|
|||||||
blockFlag = info->blockFlag;
|
blockFlag = info->blockFlag;
|
||||||
|
|
||||||
// read is not reentrant
|
// read is not reentrant
|
||||||
if (atomic_or(&info->rxLock, 1)) {
|
if (atomic_or(&info->rxLock, 1))
|
||||||
*_length = 0;
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
|
||||||
|
|
||||||
//TRACE(("current rx descr: %08x (last = %ld)\n", rxp = read32((uint32)info->registers + SiS900_MAC_Rx_DESCR), (info->rxLast+1) % NUM_Rx_DESCR));
|
//TRACE(("current rx descr: %08x (last = %ld)\n", rxp = read32((uint32)info->registers + SiS900_MAC_Rx_DESCR), (info->rxLast+1) % NUM_Rx_DESCR));
|
||||||
|
|
||||||
@ -434,7 +430,6 @@ device_read(void *data, off_t pos, void *buffer, size_t *_length)
|
|||||||
if ((status = acquire_sem_etc(info->rxSem, 1, B_CAN_INTERRUPT | blockFlag, 0)) != B_NO_ERROR) {
|
if ((status = acquire_sem_etc(info->rxSem, 1, B_CAN_INTERRUPT | blockFlag, 0)) != B_NO_ERROR) {
|
||||||
TRACE(("cannot acquire read sem: %x, %s\n", status, strerror(status)));
|
TRACE(("cannot acquire read sem: %x, %s\n", status, strerror(status)));
|
||||||
atomic_and(&info->rxLock, 0);
|
atomic_and(&info->rxLock, 0);
|
||||||
*_length = 0;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -445,7 +440,6 @@ device_read(void *data, off_t pos, void *buffer, size_t *_length)
|
|||||||
if (!(check & SiS900_DESCR_OWN)) { // the buffer is still in use!
|
if (!(check & SiS900_DESCR_OWN)) { // the buffer is still in use!
|
||||||
TRACE(("ERROR: read: buffer %d still in use: %x\n", current, status));
|
TRACE(("ERROR: read: buffer %d still in use: %x\n", current, status));
|
||||||
atomic_and(&info->rxLock, 0);
|
atomic_and(&info->rxLock, 0);
|
||||||
*_length = 0;
|
|
||||||
return B_BUSY;
|
return B_BUSY;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -461,7 +455,9 @@ device_read(void *data, off_t pos, void *buffer, size_t *_length)
|
|||||||
if (size > MAX_FRAME_SIZE || size > *_length) {
|
if (size > MAX_FRAME_SIZE || size > *_length) {
|
||||||
TRACE(("ERROR read: bad frame size %d\n", size));
|
TRACE(("ERROR read: bad frame size %d\n", size));
|
||||||
size = *_length;
|
size = *_length;
|
||||||
}
|
} else if (size < *_length)
|
||||||
|
*_length = size;
|
||||||
|
|
||||||
memcpy(buffer, (void *)info->rxBuffer[current], size);
|
memcpy(buffer, (void *)info->rxBuffer[current], size);
|
||||||
}
|
}
|
||||||
info->rxCurrent = (current + 1) & NUM_Rx_MASK;
|
info->rxCurrent = (current + 1) & NUM_Rx_MASK;
|
||||||
@ -514,7 +510,6 @@ device_write(void *data, off_t pos, const void *buffer, size_t *_length)
|
|||||||
write32((uint32)info->registers + SiS900_MAC_COMMAND, SiS900_MAC_CMD_Tx_ENABLE);
|
write32((uint32)info->registers + SiS900_MAC_COMMAND, SiS900_MAC_CMD_Tx_ENABLE);
|
||||||
TRACE(("write: acquiring sem failed: %x, %s\n", status, strerror(status)));
|
TRACE(("write: acquiring sem failed: %x, %s\n", status, strerror(status)));
|
||||||
atomic_add(&info->txLock, -1);
|
atomic_add(&info->txLock, -1);
|
||||||
*_length = 0;
|
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -523,7 +518,6 @@ device_write(void *data, off_t pos, const void *buffer, size_t *_length)
|
|||||||
// descriptor is still in use
|
// descriptor is still in use
|
||||||
dprintf(DEVICE_NAME ": card owns buffer %d\n", current);
|
dprintf(DEVICE_NAME ": card owns buffer %d\n", current);
|
||||||
atomic_add(&info->txLock, -1);
|
atomic_add(&info->txLock, -1);
|
||||||
*_length = 0;
|
|
||||||
return B_ERROR;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -549,8 +543,7 @@ device_write(void *data, off_t pos, const void *buffer, size_t *_length)
|
|||||||
|
|
||||||
for (that = 0;that < NUM_Tx_DESCR && (void *)physicalAddress(&info->txDescriptor[that],sizeof(struct buffer_desc)) != b;that++);
|
for (that = 0;that < NUM_Tx_DESCR && (void *)physicalAddress(&info->txDescriptor[that],sizeof(struct buffer_desc)) != b;that++);
|
||||||
|
|
||||||
if (that == NUM_Tx_DESCR)
|
if (that == NUM_Tx_DESCR) {
|
||||||
{
|
|
||||||
//dprintf("not in ring!\n");
|
//dprintf("not in ring!\n");
|
||||||
that = 0;
|
that = 0;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user