Style fixes, notably the pointer style and struct keyword used
iconsintently. Respect the 80 columns limit, update copyright, used calloc instead of malloc. No functional changes (hopefully) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@40597 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2003-2005
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
/* Copyright (c) 2003-2011
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
* This file is released under the MIT license
|
||||
*/
|
||||
#include <KernelExport.h>
|
||||
@@ -17,7 +17,6 @@
|
||||
#include "wb840.h"
|
||||
|
||||
|
||||
|
||||
#define MAX_CARDS 4
|
||||
|
||||
extern char* gDevNameList[];
|
||||
@@ -52,13 +51,11 @@ wb840_open(const char *name, uint32 flags, void** cookie)
|
||||
return B_BUSY;
|
||||
|
||||
// Allocate a wb_device structure
|
||||
if (!(data = (wb_device *)malloc(sizeof(wb_device)))) {
|
||||
if (!(data = (wb_device*)calloc(1, sizeof(wb_device)))) {
|
||||
sOpenMask &= ~(1L << i);
|
||||
return B_NO_MEMORY;
|
||||
}
|
||||
|
||||
memset(data, 0, sizeof(wb_device));
|
||||
|
||||
*cookie = data;
|
||||
|
||||
#ifdef DEBUG
|
||||
@@ -70,26 +67,27 @@ wb840_open(const char *name, uint32 flags, void** cookie)
|
||||
data->deviceName = gDevNameList[i];
|
||||
data->blockFlag = 0;
|
||||
data->reg_base = data->pciInfo->u.h0.base_registers[0];
|
||||
data->wb_cachesize = gPci->read_pci_config(data->pciInfo->bus, data->pciInfo->device,
|
||||
data->pciInfo->function, PCI_line_size, sizeof (PCI_line_size)) & 0xff;
|
||||
data->wb_cachesize = gPci->read_pci_config(data->pciInfo->bus,
|
||||
data->pciInfo->device, data->pciInfo->function, PCI_line_size,
|
||||
sizeof(PCI_line_size)) & 0xff;
|
||||
|
||||
wb_read_eeprom(data, &data->MAC_Address, 0, 3, false);
|
||||
|
||||
status = wb_create_semaphores(data);
|
||||
if (status < B_OK) {
|
||||
LOG((DEVICE_NAME ": Couldn't create semaphores\n"));
|
||||
LOG((DEVICE_NAME": couldn't create semaphores\n"));
|
||||
goto err;
|
||||
}
|
||||
|
||||
status = wb_stop(data);
|
||||
if (status < B_OK) {
|
||||
LOG((DEVICE_NAME": Can't stop device\n"));
|
||||
LOG((DEVICE_NAME": can't stop device\n"));
|
||||
goto err1;
|
||||
}
|
||||
|
||||
status = wb_initPHYs(data);
|
||||
if (status < B_OK) {
|
||||
LOG((DEVICE_NAME": Can't init PHYs\n"));
|
||||
LOG((DEVICE_NAME": can't init PHYs\n"));
|
||||
goto err1;
|
||||
}
|
||||
|
||||
@@ -100,11 +98,11 @@ wb840_open(const char *name, uint32 flags, void** cookie)
|
||||
status = install_io_interrupt_handler(data->irq, wb_interrupt, data, 0);
|
||||
if (status < B_OK) {
|
||||
LOG((DEVICE_NAME
|
||||
" can't install interrupt handler: %s\n", strerror(status)));
|
||||
": can't install interrupt handler: %s\n", strerror(status)));
|
||||
goto err1;
|
||||
}
|
||||
|
||||
LOG(("Interrupts installed at irq line %x\n", data->irq));
|
||||
LOG((DEVICE_NAME ": interrupts installed at irq line %x\n", data->irq));
|
||||
|
||||
status = wb_create_rings(data);
|
||||
if (status < B_OK) {
|
||||
@@ -167,7 +165,8 @@ wb840_read(void* cookie, off_t position, void *buf, size_t* num_bytes)
|
||||
current = device->rxCurrent;
|
||||
check = device->rxDescriptor[current].wb_status;
|
||||
if (check & WB_RXSTAT_OWN) {
|
||||
LOG(("ERROR: read: buffer %d still in use: %x\n", (int)current, (int)status));
|
||||
LOG((DEVICE_NAME ":ERROR: read: buffer %d still in use: %x\n",
|
||||
(int)current, (int)status));
|
||||
atomic_and(&device->rxLock, 0);
|
||||
*num_bytes = 0;
|
||||
return B_BUSY;
|
||||
@@ -231,7 +230,8 @@ wb840_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
|
||||
status = acquire_sem_etc(device->txSem, 1, B_TIMEOUT, ETHER_TRANSMIT_TIMEOUT);
|
||||
if (status < B_OK) {
|
||||
write32(device->reg_base + WB_TXSTART, 0xFFFFFFFF);
|
||||
LOG(("write: acquiring sem failed: %ld, %s\n", status, strerror(status)));
|
||||
LOG((DEVICE_NAME": write: acquiring sem failed: %ld, %s\n",
|
||||
status, strerror(status)));
|
||||
atomic_add(&device->txLock, -1);
|
||||
*num_bytes = 0;
|
||||
return status;
|
||||
@@ -256,7 +256,8 @@ wb840_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
|
||||
acquire_spinlock(&device->txSpinlock);
|
||||
|
||||
device->txDescriptor[current].wb_ctl = WB_TXCTL_TLINK | frameSize;
|
||||
device->txDescriptor[current].wb_ctl |= WB_TXCTL_FIRSTFRAG | WB_TXCTL_LASTFRAG;
|
||||
device->txDescriptor[current].wb_ctl |= WB_TXCTL_FIRSTFRAG
|
||||
| WB_TXCTL_LASTFRAG;
|
||||
device->txDescriptor[current].wb_status = WB_TXSTAT_OWN;
|
||||
device->txSent++;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2003-2004
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
/* Copyright (c) 2003-2011
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
*/
|
||||
#include "debug.h"
|
||||
#include <Debug.h>
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* Copyright (c) 2003-2005
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
/* Copyright (c) 2003-2011
|
||||
* Stefano Ceccherini <[email protected]>. All rights reserved.
|
||||
* This file is released under the MIT license
|
||||
*/
|
||||
#include "device.h"
|
||||
@@ -27,7 +27,8 @@
|
||||
struct mii_chip_info
|
||||
{
|
||||
const char* name;
|
||||
uint16 id0, id1;
|
||||
uint16 id0;
|
||||
uint16 id1;
|
||||
uint8 types;
|
||||
};
|
||||
|
||||
@@ -74,7 +75,7 @@ wb_put_rx_descriptor(volatile wb_desc *descriptor)
|
||||
|
||||
|
||||
void
|
||||
wb_enable_interrupts(struct wb_device *device)
|
||||
wb_enable_interrupts(wb_device* device)
|
||||
{
|
||||
write32(device->reg_base + WB_IMR, WB_INTRS);
|
||||
write32(device->reg_base + WB_ISR, 0xFFFFFFFF);
|
||||
@@ -82,7 +83,7 @@ wb_enable_interrupts(struct wb_device *device)
|
||||
|
||||
|
||||
void
|
||||
wb_disable_interrupts(struct wb_device *device)
|
||||
wb_disable_interrupts(wb_device* device)
|
||||
{
|
||||
write32(device->reg_base + WB_IMR, 0L);
|
||||
write32(device->reg_base + WB_ISR, 0L);
|
||||
@@ -123,7 +124,7 @@ wb_initPHYs(wb_device *device)
|
||||
// this MII is not accessable
|
||||
continue;
|
||||
|
||||
mii = (struct mii_phy *)malloc(sizeof(struct mii_phy));
|
||||
mii = (struct mii_phy*)calloc(1, sizeof(struct mii_phy));
|
||||
if (mii == NULL)
|
||||
return B_NO_MEMORY;
|
||||
|
||||
@@ -135,15 +136,18 @@ wb_initPHYs(wb_device *device)
|
||||
device->firstPHY = mii;
|
||||
|
||||
while (gMIIChips[i].name != NULL) {
|
||||
if (gMIIChips[i].id0 == mii->id0 && gMIIChips[i].id1 == (mii->id1 & 0xfff0)) {
|
||||
if (gMIIChips[i].id0 == mii->id0
|
||||
&& gMIIChips[i].id1 == (mii->id1 & 0xfff0)) {
|
||||
dprintf("Found MII PHY: %s\n", gMIIChips[i].name);
|
||||
mii->types = gMIIChips[i].types;
|
||||
break;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
if (gMIIChips[i].name == NULL)
|
||||
dprintf("Unknown MII PHY transceiver: id = (%x, %x).\n",mii->id0, mii->id1);
|
||||
if (gMIIChips[i].name == NULL) {
|
||||
dprintf("Unknown MII PHY transceiver: id = (%x, %x).\n",
|
||||
mii->id0, mii->id1);
|
||||
}
|
||||
}
|
||||
|
||||
if (device->firstPHY == NULL) {
|
||||
@@ -183,14 +187,16 @@ wb_init(wb_device *device)
|
||||
break;
|
||||
}
|
||||
|
||||
write32(device->reg_base + WB_BUSCTL, WB_BUSCTL_MUSTBEONE|WB_BUSCTL_ARBITRATION);
|
||||
write32(device->reg_base + WB_BUSCTL,
|
||||
WB_BUSCTL_MUSTBEONE | WB_BUSCTL_ARBITRATION);
|
||||
WB_SETBIT(device->reg_base + WB_BUSCTL, WB_BURSTLEN_16LONG);
|
||||
|
||||
write32(device->reg_base + WB_BUSCTL_SKIPLEN, WB_SKIPLEN_4LONG);
|
||||
|
||||
// Disable early TX/RX interrupt, as we can't take advantage
|
||||
// from them, at least for now.
|
||||
WB_CLRBIT(device->reg_base + WB_NETCFG, (WB_NETCFG_TX_EARLY_ON|WB_NETCFG_RX_EARLY_ON));
|
||||
WB_CLRBIT(device->reg_base + WB_NETCFG,
|
||||
(WB_NETCFG_TX_EARLY_ON | WB_NETCFG_RX_EARLY_ON));
|
||||
|
||||
wb_set_rx_filter(device);
|
||||
}
|
||||
@@ -248,7 +254,7 @@ wb_stop(wb_device *device)
|
||||
|
||||
|
||||
static void
|
||||
wb_updateLink(struct wb_device *device)
|
||||
wb_updateLink(wb_device* device)
|
||||
{
|
||||
if (!device->autoNegotiationComplete) {
|
||||
int32 mode = wb_read_mode(device);
|
||||
@@ -279,7 +285,7 @@ wb_updateLink(struct wb_device *device)
|
||||
int32
|
||||
wb_tick(timer* arg)
|
||||
{
|
||||
struct wb_device *device = (wb_device*)arg;
|
||||
wb_device* device = (wb_device*)arg;
|
||||
|
||||
wb_updateLink(device);
|
||||
|
||||
@@ -301,7 +307,7 @@ wb_set_rx_filter(wb_device *device)
|
||||
|
||||
/***************** Interrupt handling ******************************/
|
||||
static status_t
|
||||
wb_rxok(struct wb_device *device)
|
||||
wb_rxok(wb_device* device)
|
||||
{
|
||||
uint32 releaseRxSem = 0;
|
||||
int16 limit;
|
||||
@@ -309,12 +315,14 @@ wb_rxok(struct wb_device *device)
|
||||
acquire_spinlock(&device->rxSpinlock);
|
||||
|
||||
for (limit = device->rxFree; limit > 0; limit--) {
|
||||
if (device->rxDescriptor[device->rxInterruptIndex].wb_status & WB_RXSTAT_OWN) {
|
||||
if (device->rxDescriptor[device->rxInterruptIndex].wb_status
|
||||
& WB_RXSTAT_OWN) {
|
||||
break;
|
||||
}
|
||||
|
||||
releaseRxSem++;
|
||||
device->rxInterruptIndex = (device->rxInterruptIndex + 1) & WB_RX_CNT_MASK;
|
||||
device->rxInterruptIndex = (device->rxInterruptIndex + 1)
|
||||
& WB_RX_CNT_MASK;
|
||||
device->rxFree--;
|
||||
}
|
||||
|
||||
@@ -333,7 +341,7 @@ wb_rxok(struct wb_device *device)
|
||||
|
||||
|
||||
static status_t
|
||||
wb_tx_nobuf(struct wb_device *info)
|
||||
wb_tx_nobuf(wb_device* info)
|
||||
{
|
||||
int16 releaseTxSem = 0;
|
||||
int16 limit;
|
||||
@@ -379,7 +387,7 @@ wb_tx_nobuf(struct wb_device *info)
|
||||
int32
|
||||
wb_interrupt(void* arg)
|
||||
{
|
||||
struct wb_device *device = (wb_device*)arg;
|
||||
wb_device* device = (wb_device*)arg;
|
||||
int32 retval = B_UNHANDLED_INTERRUPT;
|
||||
uint32 status;
|
||||
|
||||
@@ -483,7 +491,7 @@ print_address(ether_address_t *addr)
|
||||
|
||||
|
||||
status_t
|
||||
wb_create_semaphores(struct wb_device *device)
|
||||
wb_create_semaphores(wb_device* device)
|
||||
{
|
||||
device->rxSem = create_sem(0, "wb840 receive");
|
||||
if (device->rxSem < B_OK) {
|
||||
@@ -519,46 +527,57 @@ wb_delete_semaphores(wb_device *device)
|
||||
|
||||
|
||||
status_t
|
||||
wb_create_rings(struct wb_device *device)
|
||||
wb_create_rings(wb_device* device)
|
||||
{
|
||||
int i;
|
||||
|
||||
device->rxArea = create_area("wb840 rx buffer", (void **)&device->rxBuffer[0],
|
||||
B_ANY_KERNEL_ADDRESS, ROUND_TO_PAGE_SIZE(WB_BUFBYTES * WB_RX_LIST_CNT),
|
||||
device->rxArea = create_area("wb840 rx buffer",
|
||||
(void**)&device->rxBuffer[0], B_ANY_KERNEL_ADDRESS,
|
||||
ROUND_TO_PAGE_SIZE(WB_BUFBYTES * WB_RX_LIST_CNT),
|
||||
B_32_BIT_FULL_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
if (device->rxArea < B_OK)
|
||||
return device->rxArea;
|
||||
|
||||
for (i = 1; i < WB_RX_LIST_CNT; i++)
|
||||
device->rxBuffer[i] = (void *)(((uint32)device->rxBuffer[0]) + (i * WB_BUFBYTES));
|
||||
for (i = 1; i < WB_RX_LIST_CNT; i++) {
|
||||
device->rxBuffer[i] = (void*)(((uint32)device->rxBuffer[0])
|
||||
+ (i * WB_BUFBYTES));
|
||||
}
|
||||
|
||||
for (i = 0; i < WB_RX_LIST_CNT; i++) {
|
||||
device->rxDescriptor[i].wb_status = 0;
|
||||
device->rxDescriptor[i].wb_ctl = WB_RXCTL_RLINK;
|
||||
wb_put_rx_descriptor(&device->rxDescriptor[i]);
|
||||
device->rxDescriptor[i].wb_data = physicalAddress(device->rxBuffer[i], WB_BUFBYTES);
|
||||
device->rxDescriptor[i].wb_next = physicalAddress(&device->rxDescriptor[(i + 1) & WB_RX_CNT_MASK],
|
||||
device->rxDescriptor[i].wb_data = physicalAddress(
|
||||
device->rxBuffer[i], WB_BUFBYTES);
|
||||
device->rxDescriptor[i].wb_next = physicalAddress(
|
||||
&device->rxDescriptor[(i + 1) & WB_RX_CNT_MASK],
|
||||
sizeof(struct wb_desc));
|
||||
}
|
||||
|
||||
device->rxFree = WB_RX_LIST_CNT;
|
||||
|
||||
device->txArea = create_area("wb840 tx buffer", (void **)&device->txBuffer[0],
|
||||
B_ANY_KERNEL_ADDRESS, ROUND_TO_PAGE_SIZE(WB_BUFBYTES * WB_TX_LIST_CNT),
|
||||
device->txArea = create_area("wb840 tx buffer",
|
||||
(void**)&device->txBuffer[0], B_ANY_KERNEL_ADDRESS,
|
||||
ROUND_TO_PAGE_SIZE(WB_BUFBYTES * WB_TX_LIST_CNT),
|
||||
B_32_BIT_FULL_LOCK, B_READ_AREA | B_WRITE_AREA);
|
||||
|
||||
if (device->txArea < B_OK) {
|
||||
delete_area(device->rxArea);
|
||||
return device->txArea;
|
||||
}
|
||||
|
||||
for (i = 1; i < WB_TX_LIST_CNT; i++)
|
||||
device->txBuffer[i] = (void *)(((uint32)device->txBuffer[0]) + (i * WB_BUFBYTES));
|
||||
for (i = 1; i < WB_TX_LIST_CNT; i++) {
|
||||
device->txBuffer[i] = (void*)(((uint32)device->txBuffer[0])
|
||||
+ (i * WB_BUFBYTES));
|
||||
}
|
||||
|
||||
for (i = 0; i < WB_TX_LIST_CNT; i++) {
|
||||
device->txDescriptor[i].wb_status = 0;
|
||||
device->txDescriptor[i].wb_ctl = WB_TXCTL_TLINK;
|
||||
device->txDescriptor[i].wb_data = physicalAddress(device->txBuffer[i], WB_BUFBYTES);
|
||||
device->txDescriptor[i].wb_next = physicalAddress(&device->txDescriptor[(i + 1) & WB_TX_CNT_MASK],
|
||||
device->txDescriptor[i].wb_data = physicalAddress(
|
||||
device->txBuffer[i], WB_BUFBYTES);
|
||||
device->txDescriptor[i].wb_next = physicalAddress(
|
||||
&device->txDescriptor[(i + 1) & WB_TX_CNT_MASK],
|
||||
sizeof(struct wb_desc));
|
||||
}
|
||||
|
||||
@@ -574,7 +593,7 @@ wb_create_rings(struct wb_device *device)
|
||||
|
||||
|
||||
void
|
||||
wb_delete_rings(struct wb_device *device)
|
||||
wb_delete_rings(wb_device* device)
|
||||
{
|
||||
delete_area(device->rxArea);
|
||||
delete_area(device->txArea);
|
||||
@@ -584,8 +603,10 @@ wb_delete_rings(struct wb_device *device)
|
||||
int32
|
||||
wb_read_mode(wb_device* info)
|
||||
{
|
||||
uint16 autoAdv, autoLinkPartner;
|
||||
int32 speed, duplex;
|
||||
uint16 autoAdv;
|
||||
uint16 autoLinkPartner;
|
||||
int32 speed;
|
||||
int32 duplex;
|
||||
|
||||
uint16 status = mii_readstatus(info);
|
||||
if (!(status & MII_STATUS_LINK)) {
|
||||
@@ -595,11 +616,14 @@ wb_read_mode(wb_device *info)
|
||||
|
||||
// auto negotiation completed
|
||||
autoAdv = wb_miibus_readreg(info, info->phy, MII_AUTONEG_ADV);
|
||||
autoLinkPartner = wb_miibus_readreg(info, info->phy, MII_AUTONEG_LINK_PARTNER);
|
||||
autoLinkPartner = wb_miibus_readreg(info, info->phy,
|
||||
MII_AUTONEG_LINK_PARTNER);
|
||||
status = autoAdv & autoLinkPartner;
|
||||
|
||||
speed = status & (MII_NWAY_TX | MII_NWAY_TX_FDX) ? LINK_SPEED_100_MBIT : LINK_SPEED_10_MBIT;
|
||||
duplex = status & (MII_NWAY_TX_FDX | MII_NWAY_T_FDX) ? LINK_FULL_DUPLEX : LINK_HALF_DUPLEX;
|
||||
speed = status & (MII_NWAY_TX | MII_NWAY_TX_FDX)
|
||||
? LINK_SPEED_100_MBIT : LINK_SPEED_10_MBIT;
|
||||
duplex = status & (MII_NWAY_TX_FDX | MII_NWAY_T_FDX)
|
||||
? LINK_FULL_DUPLEX : LINK_HALF_DUPLEX;
|
||||
|
||||
info->autoNegotiationComplete = true;
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright (c) 2003-2004 Stefano Ceccherini ([email protected])
|
||||
* Copyright (c) 2003-2004 Stefano Ceccherini ([email protected])
|
||||
* Copyright (c) 1997, 1998
|
||||
* Bill Paul <[email protected]>. All rights reserved.
|
||||
*
|
||||
@@ -480,6 +480,9 @@ enum link_modes {
|
||||
#define CP_VENDORID 0x11F6
|
||||
#define CP_DEVICEID_RL100 0x2011
|
||||
|
||||
/*
|
||||
* Utility Macros
|
||||
*/
|
||||
#define WB_SETBIT(reg, x) write32(reg, read32(reg) | x)
|
||||
#define WB_CLRBIT(reg, x) write32(reg, read32(reg) & ~x)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user