Skip to content

Commit

Permalink
[B57XX] Implemented diseans's suggested improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
nothotscott authored and DarkFire01 committed Nov 11, 2024
1 parent 17cbf44 commit 59052db
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 48 deletions.
3 changes: 1 addition & 2 deletions drivers/network/dd/b57xx/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@

add_definitions(
-DNDIS50_MINIPORT
-DNDIS_MINIPORT_DRIVER
-DNDIS_LEGACY_MINIPORT)
-DNDIS51_MINIPORT)

list(APPEND SOURCE
ndis.c
Expand Down
2 changes: 1 addition & 1 deletion drivers/network/dd/b57xx/b57xxhw.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

#define IEEE_802_ADDR_LENGTH 6

#define MAXIMUM_MULTICAST_ADDRESSES 16
#define MAXIMUM_MULTICAST_ADDRESSES 32

#define MAX_ATTEMPTS 1000
#define MAX_ATTEMPTS_PHY 5000
Expand Down
26 changes: 8 additions & 18 deletions drivers/network/dd/b57xx/hardware.c
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ NTAPI
NICConfigureAdapter(_In_ PB57XX_ADAPTER Adapter)
{
UINT i;
ULONG AdditionalFrameSize = sizeof(ETH_HEADER) + 4;
ULONG AdditionalFrameSize = sizeof(ETH_HEADER);
ULONG Alignment = Adapter->PciState.CacheLineSize;

ASSERT(Adapter->PciState.DeviceID != 0);
Expand Down Expand Up @@ -601,8 +601,8 @@ NICSoftReset(_In_ PB57XX_ADAPTER Adapter)
B57XXWriteRegister(Adapter, B57XX_REG_ETH_TX_RND_BACKOFF, Value);

/* Initialization Procedure step 54: Configure the Message Transfer Unit MTU size */
// We need to include VLAN tags for the MTU
B57XXWriteRegister(Adapter, B57XX_REG_ETH_RX_MTU_SIZE, Adapter->MaxFrameSize + 4);
// We need to include VLAN tag (4 bytes) & frame check sequence (4 bytes) for the MTU
B57XXWriteRegister(Adapter, B57XX_REG_ETH_RX_MTU_SIZE, Adapter->MaxFrameSize + 8);

/* Initialization Procedure step 55: Configure IPG for transmit */
B57XXWriteRegister(Adapter, B57XX_REG_ETH_TX_LENGTH, 0x2620);
Expand Down Expand Up @@ -1236,16 +1236,12 @@ NICTransmitPacket(_In_ PB57XX_ADAPTER Adapter,
Index = (Index + 1) % Adapter->SendProducer[0].Count;
Adapter->SendProducer[0].ProducerIndex = Index;
B57XXWriteMailbox(Adapter, B57XX_MBOX_TXP_HOST_RING_INDEX1, Index);

if (Index == Adapter->SendProducer[0].ConsumerIndex)
{
NDIS_MinDbgPrint("Send ring is full\n");
Adapter->SendProducer[0].RingFull = TRUE;
}

return NDIS_STATUS_SUCCESS;
}



VOID
NTAPI
NICEnableInterrupts(_In_ PB57XX_ADAPTER Adapter)
Expand Down Expand Up @@ -1323,8 +1319,8 @@ NICQueryStatisticCounter(_In_ PB57XX_ADAPTER Adapter,
case OID_GEN_RCV_OK:
*pValue64 = Adapter->Statistics.ReceiveSuccesses;
break;
case OID_GEN_XMIT_ERROR:
*pValue64 = Adapter->Statistics.TransmitErrors;
case OID_GEN_XMIT_ERROR: // dot3StatsInternalMacTransmitErrors
B57XXReadStatistic(Adapter, 0x330, 0x0818, FALSE, pValue64);
break;
case OID_GEN_RCV_ERROR:
*pValue64 = Adapter->Statistics.ReceiveErrors;
Expand Down Expand Up @@ -1561,7 +1557,6 @@ ULONG
B57XXComputeInverseCrc32(_In_ PUCHAR pBuffer,
_In_ ULONG BufferSize)
{
ULONG Tmp;
ULONG Reg = 0xFFFFFFFF;

for(ULONG i = 0; i < BufferSize; i++)
Expand All @@ -1570,12 +1565,7 @@ B57XXComputeInverseCrc32(_In_ PUCHAR pBuffer,

for(ULONG j = 0; j < 8; j++)
{
Tmp = Reg & 0x01;
Reg >>= 1;
if(Tmp)
{
Reg ^= 0xEDB88320;
}
Reg = (Reg >> 1) ^ (-(LONG)(Reg & 0x01) & 0xEDB88320);
}
}
return Reg;
Expand Down
8 changes: 0 additions & 8 deletions drivers/network/dd/b57xx/info.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,8 +82,6 @@ MiniportQueryInformation(_In_ NDIS_HANDLE MiniportAdapterContext,
} GenericInfo;
PVOID CopySource = &GenericInfo;
ULONG CopyLength = sizeof(ULONG);

NdisAcquireSpinLock(&Adapter->InfoLock);

switch (Oid)
{
Expand Down Expand Up @@ -290,8 +288,6 @@ MiniportQueryInformation(_In_ NDIS_HANDLE MiniportAdapterContext,


Exit:
NdisReleaseSpinLock(&Adapter->InfoLock);

return Status;
}

Expand All @@ -307,8 +303,6 @@ MiniportSetInformation(_In_ NDIS_HANDLE MiniportAdapterContext,
NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
PB57XX_ADAPTER Adapter = (PB57XX_ADAPTER)MiniportAdapterContext;
ULONG GenericULong;

NdisAcquireSpinLock(&Adapter->InfoLock);

switch (Oid)
{
Expand Down Expand Up @@ -409,8 +403,6 @@ MiniportSetInformation(_In_ NDIS_HANDLE MiniportAdapterContext,
*BytesNeeded = 0;
}

NdisReleaseSpinLock(&Adapter->InfoLock);

NDIS_MinDbgPrint("Set Info on OID 0x%x: %s(0x%x) (%d, %d)\n",
Oid,
Status == NDIS_STATUS_SUCCESS ? "Completed" : "Failed",
Expand Down
8 changes: 8 additions & 0 deletions drivers/network/dd/b57xx/interrupt.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,13 @@ MiniportHandleInterrupt(_In_ NDIS_HANDLE MiniportAdapterContext)
LinkStateChange = TRUE;
NDIS_MinDbgPrint("Link state change\n");

NdisDprReleaseSpinLock(&Adapter->Interrupt.Lock);
NdisMIndicateStatus(Adapter->MiniportAdapterHandle,
NICUpdateLinkStatus(Adapter),
NULL,
0);
NdisMIndicateStatusComplete(Adapter->MiniportAdapterHandle);
NdisDprAcquireSpinLock(&Adapter->Interrupt.Lock);
}

/* Process any received frames (receive interrupts) */
Expand All @@ -116,13 +118,15 @@ MiniportHandleInterrupt(_In_ NDIS_HANDLE MiniportAdapterContext)
BufferBase = (PCHAR)Adapter->StandardProducer.HostBuffer +
Adapter->StandardProducer.FrameBufferLength * pReceiveDescriptor->Index;

NdisDprReleaseSpinLock(&Adapter->Interrupt.Lock);
NdisMEthIndicateReceive(Adapter->MiniportAdapterHandle,
NULL,
BufferBase,
sizeof(ETH_HEADER),
BufferBase + sizeof(ETH_HEADER),
pReceiveDescriptor->Length - sizeof(ETH_HEADER),
pReceiveDescriptor->Length - sizeof(ETH_HEADER));
NdisDprAcquireSpinLock(&Adapter->Interrupt.Lock);
GotAny = TRUE;

Adapter->Statistics.ReceiveSuccesses++;
Expand All @@ -138,7 +142,9 @@ MiniportHandleInterrupt(_In_ NDIS_HANDLE MiniportAdapterContext)
if (GotAny)
{
NICReceiveSignalComplete(Adapter);
NdisDprReleaseSpinLock(&Adapter->Interrupt.Lock);
NdisMEthIndicateReceiveComplete(Adapter->MiniportAdapterHandle);
NdisDprAcquireSpinLock(&Adapter->Interrupt.Lock);
}

/* Process any completed frames (transmit interrupts) */
Expand All @@ -147,9 +153,11 @@ MiniportHandleInterrupt(_In_ NDIS_HANDLE MiniportAdapterContext)
{
ConsumerIndex = Adapter->SendProducer[0].ConsumerIndex;

NdisDprReleaseSpinLock(&Adapter->Interrupt.Lock);
NdisMSendComplete(Adapter->MiniportAdapterHandle,
Adapter->SendProducer[0].pPacketList[ConsumerIndex],
NDIS_STATUS_SUCCESS);
NdisDprAcquireSpinLock(&Adapter->Interrupt.Lock);
Adapter->SendProducer[0].RingFull = FALSE;

Adapter->Statistics.TransmitSuccesses++;
Expand Down
51 changes: 34 additions & 17 deletions drivers/network/dd/b57xx/ndis.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,6 @@ MiniportInitialize(_Out_ PNDIS_STATUS OpenErrorStatus,
Adapter->HardwareStatus = NdisHardwareStatusNotReady;
NdisAllocateSpinLock(&Adapter->Interrupt.Lock);
NdisAllocateSpinLock(&Adapter->SendLock);
NdisAllocateSpinLock(&Adapter->InfoLock);

/* Notify NDIS of some characteristics of our NIC */
NdisMSetAttributesEx(Adapter->MiniportAdapterHandle,
Expand Down Expand Up @@ -481,35 +480,53 @@ MiniportSend(_In_ NDIS_HANDLE MiniportAdapterContext,
_In_ PNDIS_PACKET Packet,
_In_ UINT Flags)
{
NDIS_STATUS Status;
PB57XX_ADAPTER Adapter = (PB57XX_ADAPTER)MiniportAdapterContext;
NDIS_STATUS Status = NDIS_STATUS_PENDING;
PSCATTER_GATHER_LIST SGList = NDIS_PER_PACKET_INFO_FROM_PACKET(Packet,
ScatterGatherListPacketInfo);


NdisAcquireSpinLock(&Adapter->SendLock);
LONG BusyDescriptors = Adapter->SendProducer[0].ProducerIndex -
Adapter->SendProducer[0].ConsumerIndex;

ASSERT(SGList != NULL);
ASSERT(SGList->NumberOfElements >= 1);

NdisDprAcquireSpinLock(&Adapter->SendLock);

if (BusyDescriptors < 0)
{
BusyDescriptors += Adapter->SendProducer[0].Count;
}

if (Adapter->SendProducer[0].RingFull == TRUE ||
BusyDescriptors + SGList->NumberOfElements > Adapter->SendProducer[0].Count)
{
/* Force NDIS to resubmit the send */
Status = NDIS_STATUS_RESOURCES;
goto Exit;
}

for (UINT i = 0; i < SGList->NumberOfElements; i++)
{
ASSERT(SGList->Elements[i].Length <= Adapter->MaxFrameSize);

Adapter->SendProducer[0].pPacketList[Adapter->SendProducer[0].ProducerIndex] = Packet;

Status = NICTransmitPacket(Adapter,
SGList->Elements[i].Address,
SGList->Elements[i].Length,
i == SGList->NumberOfElements - 1 ? B57XX_SBD_PACKET_END : 0);
if (Status != NDIS_STATUS_SUCCESS)
{
Adapter->Statistics.TransmitErrors++;
}
NICTransmitPacket(Adapter,
SGList->Elements[i].Address,
SGList->Elements[i].Length,
i == SGList->NumberOfElements - 1 ? B57XX_SBD_PACKET_END : 0);
}

NdisReleaseSpinLock(&Adapter->SendLock);
if (Adapter->SendProducer[0].ProducerIndex == Adapter->SendProducer[0].ConsumerIndex)
{
NDIS_MinDbgPrint("Send ring is full\n");
Adapter->SendProducer[0].RingFull = TRUE;
}

Exit:
NdisDprReleaseSpinLock(&Adapter->SendLock);

return NDIS_STATUS_PENDING;
return Status;
}

NTSTATUS
Expand All @@ -536,9 +553,9 @@ DriverEntry(_In_ PDRIVER_OBJECT DriverObject,
Characteristics.SendHandler = MiniportSend;
Characteristics.SetInformationHandler = MiniportSetInformation;
Characteristics.TransferDataHandler = NULL;
/*Characteristics.ReturnPacketHandler = NULL;
Characteristics.ReturnPacketHandler = NULL;
Characteristics.SendPacketsHandler = NULL;
Characteristics.AllocateCompleteHandler = NULL;*/
Characteristics.AllocateCompleteHandler = NULL;

NdisMInitializeWrapper(&WrapperHandle, DriverObject, RegistryPath, NULL);
if (!WrapperHandle)
Expand Down
3 changes: 3 additions & 0 deletions drivers/network/dd/b57xx/netb57xx.inf
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ DefaultDestDir = 12
[Manufacturer]
%BroadcomMfg% = BroadcomMfg

[ControlFlags]
ExcludeFromSelect = *

[BroadcomMfg]
%Broadcom5700.DeviceDesc% = B57XX.Inst.ndi,PCI\VEN_14E4&DEV_1644
%Broadcom5701.DeviceDesc% = B57XX.Inst.ndi,PCI\VEN_14E4&DEV_1645
Expand Down
2 changes: 0 additions & 2 deletions drivers/network/dd/b57xx/nic.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@ typedef struct _B57XX_ADAPTER
NDIS_PHYSICAL_ADDRESS HostAddress;
ULONG64 TransmitSuccesses;
ULONG64 ReceiveSuccesses;
ULONG64 TransmitErrors;
ULONG64 ReceiveErrors;
ULONG64 ReceiveBufferErrors;
} Statistics;
Expand All @@ -90,7 +89,6 @@ typedef struct _B57XX_ADAPTER
MAC_ADDRESS MulticastList[MAXIMUM_MULTICAST_ADDRESSES];
ULONG MulticastListSize;

NDIS_SPIN_LOCK InfoLock;
ULONG PacketFilter;
USHORT LinkStatus;
} B57XX_ADAPTER, *PB57XX_ADAPTER;
Expand Down

0 comments on commit 59052db

Please sign in to comment.