Skip to content

Commit

Permalink
Merge pull request #4 from idigdoug/upgrade
Browse files Browse the repository at this point in the history
Upgrade to rtl_bsd_drv v1.100
  • Loading branch information
idigdoug authored Nov 4, 2024
2 parents ef86259 + b0cd71f commit 2d5ccf2
Show file tree
Hide file tree
Showing 15 changed files with 75,874 additions and 28,573 deletions.
10 changes: 5 additions & 5 deletions adapter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ RtAdapterSetLinkLayerCapabilities(
adapter->MaxSpeed);

NetAdapterSetLinkLayerCapabilities(adapter->NetAdapter, &linkLayerCapabilities);
NetAdapterSetLinkLayerMtuSize(adapter->NetAdapter, adapter->bsdData.mtu);
NetAdapterSetLinkLayerMtuSize(adapter->NetAdapter, adapter->bsdData.if_net.if_mtu);
NetAdapterSetPermanentLinkLayerAddress(adapter->NetAdapter, &adapter->PermanentAddress);
NetAdapterSetCurrentLinkLayerAddress(adapter->NetAdapter, &adapter->CurrentAddress);
}
Expand Down Expand Up @@ -200,7 +200,7 @@ RtAdapterSetOffloadCapabilities(

const struct re_softc* sc = &adapter->bsdData;

BOOLEAN txSupported = (sc->if_capenable & IFCAP_TXCSUM) != 0;
BOOLEAN txSupported = (sc->if_net.if_capenable & IFCAP_TXCSUM) != 0;
if (txSupported) {
auto const layer3Flags = NetAdapterOffloadLayer3FlagIPv4NoOptions |
NetAdapterOffloadLayer3FlagIPv4WithOptions |
Expand All @@ -222,7 +222,7 @@ RtAdapterSetOffloadCapabilities(
NetAdapterOffloadSetTxChecksumCapabilities(adapter->NetAdapter, &txChecksumOffloadCapabilities);
}

BOOLEAN rxSupported = (sc->if_capenable & IFCAP_RXCSUM) != 0;
BOOLEAN rxSupported = (sc->if_net.if_capenable & IFCAP_RXCSUM) != 0;
if (rxSupported) {
NET_ADAPTER_OFFLOAD_RX_CHECKSUM_CAPABILITIES rxChecksumOffloadCapabilities;

Expand All @@ -233,7 +233,7 @@ RtAdapterSetOffloadCapabilities(
NetAdapterOffloadSetRxChecksumCapabilities(adapter->NetAdapter, &rxChecksumOffloadCapabilities);
}

BOOLEAN gsoSupported = (sc->if_capenable & IFCAP_TSO) != 0;
BOOLEAN gsoSupported = (sc->if_net.if_capenable & IFCAP_TSO) != 0;
if (gsoSupported) {
NET_ADAPTER_OFFLOAD_GSO_CAPABILITIES gsoOffloadCapabilities;

Expand All @@ -258,7 +258,7 @@ RtAdapterSetOffloadCapabilities(
NetAdapterOffloadSetGsoCapabilities(adapter->NetAdapter, &gsoOffloadCapabilities);
}

BOOLEAN ieee8021qSupported = (sc->if_capenable & IFCAP_VLAN_HWTAGGING) != 0;
BOOLEAN ieee8021qSupported = (sc->if_net.if_capenable & IFCAP_VLAN_HWTAGGING) != 0;
if (ieee8021qSupported) {
const NET_ADAPTER_OFFLOAD_IEEE8021Q_TAG_FLAGS ieee8021qTaggingFlag = NetAdapterOffloadIeee8021PriorityTaggingFlag |
NetAdapterOffloadIeee8021VlanTaggingFlag;
Expand Down
3 changes: 2 additions & 1 deletion adapter.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include "bsd.h"
#include "if_re_bsd.h"
#include "bsdexport.h"

Expand Down Expand Up @@ -140,4 +141,4 @@ GetMulticastBit(
_In_ NET_ADAPTER_LINK_LAYER_ADDRESS const* address,
_Out_ _Post_satisfies_(*byte < MAX_NIC_MULTICAST_REG) UCHAR* byte,
_Out_ UCHAR* value
);
);
91 changes: 31 additions & 60 deletions bsd.h
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
#pragma once

#pragma warning (disable: 4005)
#pragma warning (disable: 4083)
#include <stdint.h>
#pragma warning(default: 4005)
#pragma warning(default: 4083)
#include <intrin.h>
#define __NO_STRICT_ALIGNMENT

// Driver Options

Expand All @@ -14,23 +9,18 @@
#define interrupt_mitigation 1
#define phy_power_saving 1
#define phy_mdix_mode RE_ETH_PHY_AUTO_MDI_MDIX
#define max_rx_mbuf_sz MJUM9BYTES

#define RE_CSUM_FEATURES_IPV4 (CSUM_IP | CSUM_TCP | CSUM_UDP)
#define RE_CSUM_FEATURES_IPV6 (CSUM_TCP_IPV6 | CSUM_UDP_IPV6)
#define RE_CSUM_FEATURES (RE_CSUM_FEATURES_IPV4 | RE_CSUM_FEATURES_IPV6)


// BSD Compat

#define __FBSDID(id)

#define MJUM9BYTES (9 * 1024) /* jumbo cluster 9k */
#define MJUM16BYTES (16 * 1024) /* jumbo cluster 16k */

#define u_int8_t uint8_t
#define u_int16_t uint16_t
#define u_int32_t uint32_t
#define u_int64_t uint64_t

#define __P(x) x

#define DELAY(x) KeStallExecutionProcessor(x)
Expand All @@ -43,8 +33,6 @@

#define ntohs(x) RtlUshortByteSwap(x)

#define caddr_t uintptr_t

#define ENXIO 6 /* Device not configured */
#define EOPNOTSUPP 45 /* Operation not supported */

Expand All @@ -58,8 +46,6 @@
#define device_printf(dev, x, ...) __nop()
#endif

#define DBGPRINT1(dev, x, ...) DbgPrint(x, __VA_ARGS__)

#if !defined(_ARM_) && !defined(_ARM64_)
#define WRITE_REGISTER_NOFENCE_ULONG WRITE_REGISTER_ULONG
#define WRITE_REGISTER_NOFENCE_USHORT WRITE_REGISTER_USHORT
Expand All @@ -70,51 +56,36 @@
#define READ_REGISTER_NOFENCE_UCHAR READ_REGISTER_UCHAR
#endif

/*
* register space access macros
*/
#define CSR_WRITE_4(sc, reg, val) ((sc->prohibit_access_reg)?__nop():WRITE_REGISTER_NOFENCE_ULONG((PULONG)MmioAddr(sc, reg), val))
#define CSR_WRITE_2(sc, reg, val) ((sc->prohibit_access_reg)?__nop():WRITE_REGISTER_NOFENCE_USHORT((PUSHORT)MmioAddr(sc, reg), val))
#define CSR_WRITE_1(sc, reg, val) ((sc->prohibit_access_reg)?__nop():WRITE_REGISTER_NOFENCE_UCHAR((PUCHAR)MmioAddr(sc, reg), val))

#define CSR_READ_4(sc, reg) ((sc->prohibit_access_reg)?0xFFFFFFFF:READ_REGISTER_NOFENCE_ULONG((PULONG)MmioAddr(sc, reg)))
#define CSR_READ_2(sc, reg) ((sc->prohibit_access_reg)?0xFFFF:READ_REGISTER_NOFENCE_USHORT((PUSHORT)MmioAddr(sc, reg)))
#define CSR_READ_1(sc, reg) ((sc->prohibit_access_reg)?0xFF:READ_REGISTER_NOFENCE_UCHAR((PUCHAR)MmioAddr(sc, reg)))

#if DISABLED_CODE
/* cmac write/read MMIO register */
#define RE_CMAC_WRITE_1(sc, reg, val) ((sc->prohibit_access_reg)?:bus_space_write_1(sc->re_cmac_tag, sc->re_cmac_handle, reg, val))
#define RE_CMAC_WRITE_2(sc, reg, val) ((sc->prohibit_access_reg)?:bus_space_write_2(sc->re_cmac_tag, sc->re_cmac_handle, reg, val))
#define RE_CMAC_WRITE_4(sc, reg, val) ((sc->prohibit_access_reg)?:bus_space_write_4(sc->re_cmac_tag, sc->re_cmac_handle, reg, val))
#define RE_CMAC_READ_1(sc, reg) ((sc->prohibit_access_reg)?0xFF:bus_space_read_1(sc->re_cmac_tag, sc->re_cmac_handle, reg))
#define RE_CMAC_READ_2(sc, reg) ((sc->prohibit_access_reg)?0xFFFF:bus_space_read_2(sc->re_cmac_tag, sc->re_cmac_handle, reg))
#define RE_CMAC_READ_4(sc, reg) (sc->prohibit_access_reg)?0xFFFFFFFF:bus_space_read_4(sc->re_cmac_tag, sc->re_cmac_handle, reg))
#endif

#define RE_LOCK(_sc) WdfSpinLockAcquire(_sc->dev->Lock)
#define RE_UNLOCK(_sc) WdfSpinLockRelease(_sc->dev->Lock)
#define RE_LOCK_ASSERT(_sc)

#include "mii.h"
#include "ethernet.h"
#include "if.h"
#include "mbuf.h"

extern "C" NTSYSAPI ULONG RtlRandomEx(
_Inout_ PULONG Seed
);

static inline void
random_ether_addr(u_int8_t* dst)
{
LARGE_INTEGER TickCount;
/* Try to generate a more random seed */
KeQueryTickCount(&TickCount);

for (int i = 0; i < 6; i++) {
dst[i] = RtlRandomEx(&TickCount.LowPart) % 0xff;
}

dst[0] &= 0xfe;
dst[0] |= 0x02;
}
typedef signed char int8_t;
typedef unsigned char uint8_t;
typedef signed short int16_t;
typedef unsigned short uint16_t;
typedef signed int int32_t;
typedef unsigned int uint32_t;
typedef signed long long int64_t;
typedef unsigned long long uint64_t;

typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;
typedef uint64_t u_int64_t;
typedef uintptr_t caddr_t;

struct ifnet {
uint16_t if_mtu;
int if_capenable;
int if_hwassist;
};

// Placeholder types - fields are not used on WIN32.

typedef char bus_dma_tag_t;
typedef char bus_dmamap_t;
typedef char bus_dma_segment_t;
typedef char bus_addr_t;
struct bus_dma_tag_common { char x; };
2 changes: 1 addition & 1 deletion bsdexport.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ int re_ifmedia_upd(struct re_softc* sc);
int re_ifmedia_upd_8125(struct re_softc* sc);

void re_rar_set(struct re_softc* sc, u_int8_t* eaddr);
void re_set_rx_packet_filter(struct re_softc* sc);
void re_set_rx_packet_filter(struct re_softc* sc);
18 changes: 9 additions & 9 deletions device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ RtInitializeHardware(
RtlZeroMemory(&adapter->bsdData, sizeof(adapter->bsdData));

adapter->bsdData.dev = adapter;
adapter->bsdData.mtu = ETHERMTU;
adapter->bsdData.if_net.if_mtu = ETHERMTU;
adapter->bsdData.eee_enable = adapter->EEEEnable ? 1 : 0;

UINT16 devID = ConfigRead16(adapter, 2);
Expand All @@ -149,23 +149,23 @@ RtInitializeHardware(
re_init_software_variable(&adapter->bsdData);

if ((sc->re_type == MACFG_24) || (sc->re_type == MACFG_25) || (sc->re_type == MACFG_26))
sc->if_hwassist |= CSUM_TCP | CSUM_UDP;
sc->if_net.if_hwassist |= CSUM_TCP | CSUM_UDP;
else
sc->if_hwassist |= RE_CSUM_FEATURES;
sc->if_capenable = IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6;
sc->if_net.if_hwassist |= RE_CSUM_FEATURES;
sc->if_net.if_capenable = IFCAP_HWCSUM | IFCAP_HWCSUM_IPV6;
/* TSO capability setup */
if (sc->re_if_flags & RL_FLAG_8168G_PLUS) {
sc->if_hwassist |= CSUM_TSO;
sc->if_capenable |= IFCAP_TSO;
sc->if_net.if_hwassist |= CSUM_TSO;
sc->if_net.if_capenable |= IFCAP_TSO;
}
/* RTL8169/RTL8101E/RTL8168B not support TSO v6 */
if (!(sc->re_if_flags & RL_FLAG_DESCV2)) {
sc->if_hwassist &= ~(CSUM_IP6_TSO |
sc->if_net.if_hwassist &= ~(CSUM_IP6_TSO |
CSUM_TCP_IPV6 |
CSUM_UDP_IPV6);
sc->if_capenable &= ~(IFCAP_TSO6 | IFCAP_HWCSUM_IPV6);
sc->if_net.if_capenable &= ~(IFCAP_TSO6 | IFCAP_HWCSUM_IPV6);
}
sc->if_capenable |= IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING;
sc->if_net.if_capenable |= IFCAP_VLAN_MTU | IFCAP_VLAN_HWTAGGING;

adapter->bsdData.re_rx_cstag = 1;
adapter->bsdData.re_tx_cstag = 1;
Expand Down
Loading

0 comments on commit 2d5ccf2

Please sign in to comment.