Skip to content

Commit

Permalink
Fixing Jumbo Frames may result in the loss of the latter part.
Browse files Browse the repository at this point in the history
Fixing the modification of network card parameters may cause kernel panic.
Correcting some atomic operations.
  • Loading branch information
SongXiaoXi committed May 31, 2023
1 parent 3d979f1 commit 9dcce1d
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 43 deletions.
8 changes: 4 additions & 4 deletions AppleIGC.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1d1;
CURRENT_PROJECT_VERSION = 1.2d1;
DEVELOPMENT_TEAM = "";
EXCLUDED_ARCHS = arm64e;
GCC_PREPROCESSOR_DEFINITIONS = (
Expand All @@ -338,7 +338,7 @@
KERNEL_EXTENSION_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/MacKernelSDK/Headers";
KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
MODULE_NAME = com.sxx.AppleIGC;
MODULE_VERSION = 1.0.0d1;
OTHER_CFLAGS = "";
Expand All @@ -360,7 +360,7 @@
"CODE_SIGN_IDENTITY[sdk=macosx*]" = "-";
CODE_SIGN_STYLE = Automatic;
COMBINE_HIDPI_IMAGES = YES;
CURRENT_PROJECT_VERSION = 1.1d1;
CURRENT_PROJECT_VERSION = 1.2d1;
DEVELOPMENT_TEAM = "";
EXCLUDED_ARCHS = arm64e;
GCC_PREPROCESSOR_DEFINITIONS = __PRIVATE_SPI__;
Expand All @@ -370,7 +370,7 @@
KERNEL_EXTENSION_HEADER_SEARCH_PATHS = "$(PROJECT_DIR)/MacKernelSDK/Headers";
KERNEL_FRAMEWORK_HEADERS = "$(PROJECT_DIR)/MacKernelSDK/Headers";
MACOSX_DEPLOYMENT_TARGET = 10.13;
MARKETING_VERSION = 1.1;
MARKETING_VERSION = 1.2;
MODULE_NAME = com.sxx.AppleIGC;
MODULE_VERSION = 1.0.0d1;
OTHER_CFLAGS = "";
Expand Down
43 changes: 8 additions & 35 deletions AppleIGC/AppleIGC.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1314,12 +1314,6 @@ static int igc_tx_map(struct igc_ring *tx_ring,
u16 i = tx_ring->next_to_use;

UInt32 k,count;
//struct IOPhysicalSegment vec[MAX_SKB_FRAGS];
//frags = tx_ring->netdev->txCursor()->getPhysicalSegmentsWithCoalesce(skb, vec, MAX_SKB_FRAGS);
//if(frags == 0) {
// pr_err("No frags by getPhysicalSegmentsWithCoalesce()\n");
// return FALSE;
//}

// check real count
count = 0;
Expand Down Expand Up @@ -1924,7 +1918,6 @@ static void igc_add_rx_frag(struct igc_ring *rx_ring,
va, MBUF_WAITOK))) {
pr_err("Unexpected mbuf_copyback()\n");
}
//mbuf_pkthdr_setlen(skb, orig_len + size);
#else
unsigned int truesize;

Expand Down Expand Up @@ -2402,21 +2395,9 @@ static struct sk_buff *igc_fetch_rx_buffer(struct igc_ring *rx_ring,
#endif

/* pull page into skb */
#ifdef __APPLE__
igc_add_rx_frag(rx_ring, rx_buffer, skb, /*le16_to_cpu(rx_desc->wb.upper.length)*/size);
igc_add_rx_frag(rx_ring, rx_buffer, skb, size);
igc_reuse_rx_page(rx_ring, rx_buffer);

#else
if (igb_add_rx_frag(rx_ring, rx_buffer, rx_desc, skb)) {
/* hand second half of page back to the ring */
igb_reuse_rx_page(rx_ring, rx_buffer);
} else {
/* we are not reusing the buffer so unmap it */
dma_unmap_page(rx_ring->dev, rx_buffer->dma,
PAGE_SIZE, DMA_FROM_DEVICE);
}

#endif
/* clear contents of rx_buffer */
rx_buffer->page = NULL;

Expand All @@ -2430,11 +2411,9 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
struct igc_ring *rx_ring = q_vector->rx.ring;
struct sk_buff *skb = rx_ring->skb;
u16 cleaned_count = igc_desc_unused(rx_ring);
int /*xdp_status = 0, */rx_buffer_pgcnt;

while (likely(total_packets < budget)) {
union igc_adv_rx_desc *rx_desc;
struct igc_rx_buffer *rx_buffer;
unsigned int size;//, truesize;
//ktime_t timestamp = 0;
//struct xdp_buff xdp;
Expand All @@ -2458,19 +2437,14 @@ static int igc_clean_rx_irq(struct igc_q_vector *q_vector, const int budget)
*/
dma_rmb();

rx_buffer = igc_get_rx_buffer(rx_ring, size, &rx_buffer_pgcnt);

if (!skb) {
skb = igc_fetch_rx_buffer(rx_ring, rx_desc, skb, size);
}
skb = igc_fetch_rx_buffer(rx_ring, rx_desc, skb, size);

/* exit if we failed to retrieve a buffer */
if (!skb) {
rx_ring->rx_stats.alloc_failed++;
break;
}

igc_put_rx_buffer(rx_ring, rx_buffer, rx_buffer_pgcnt);

cleaned_count++;

/* fetch next buffer in frame if non-eop */
Expand Down Expand Up @@ -4288,7 +4262,6 @@ static int igc_sw_init(struct igc_adapter *adapter)
void igc_up(struct igc_adapter *adapter)
{
struct igc_hw *hw = &adapter->hw;
int i = 0;

/* hardware has been reset, we need to reload some things */
igc_configure(adapter);
Expand Down Expand Up @@ -6176,12 +6149,11 @@ IOReturn AppleIGC::enable(IONetworkInterface *netif) {
IOReturn AppleIGC::disable(IONetworkInterface *netif) {
if (enabledForNetif) {
enabledForNetif = false;
stopTxQueue();
#ifndef __PRIVATE_SPI__
stopTxQueue();
transmitQueue->setCapacity(0);
#else
netif->stopOutputThread();
netif->flushOutputQueue();
stopTxQueue();
#endif
watchdogSource->cancelTimeout();
interruptSource->disable();
Expand Down Expand Up @@ -6553,7 +6525,7 @@ IOReturn AppleIGC::outputStart(IONetworkInterface *interface, IOOptionBits optio
u8 hdr_len = 0;

struct IOPhysicalSegment vec[MAX_SKB_FRAGS];
UInt32 frags = tx_ring->netdev->txCursor()->getPhysicalSegmentsWithCoalesce(skb, vec, MAX_SKB_FRAGS);
UInt32 frags = txMbufCursor->getPhysicalSegmentsWithCoalesce(skb, vec, MAX_SKB_FRAGS);
if(frags == 0) {
pr_debug("No frags by getPhysicalSegmentsWithCoalesce()\n");
break;
Expand Down Expand Up @@ -7291,7 +7263,6 @@ IOReturn AppleIGC::getMinPacketSize (UInt32 *minSize) const {


IOReturn AppleIGC::setMaxPacketSize (UInt32 maxSize){
pr_err("AppleIGC::setMaxPacketSize(%d)\n",(int)maxSize);
UInt32 newMtu = maxSize - (ETH_HLEN + ETH_FCS_LEN);
if(newMtu != _mtu){
_mtu = newMtu;
Expand Down Expand Up @@ -7376,6 +7347,8 @@ void AppleIGC::stopTxQueue()
transmitQueue->stop();
transmitQueue->flush();
#endif
netif->stopOutputThread();
netif->flushOutputQueue();
RELEASE(txMbufCursor);
}

Expand Down
20 changes: 16 additions & 4 deletions AppleIGC/igc/kcompat.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,11 @@ static inline __u16 __le16_to_cpup(const __le16 *p)
#endif
#define ALIGN(x,a) (((x)+(a)-1)&~((a)-1))

#define BITS_PER_LONG 32
#if __LP64__
#define BITS_PER_LONG 64
#elif __LP32__
#define BITS_PER_LONG 32
#endif

#define BITS_TO_LONGS(bits) \
(((bits)+BITS_PER_LONG-1)/BITS_PER_LONG)
Expand Down Expand Up @@ -858,10 +862,18 @@ static inline void clear_bit(int nr, volatile unsigned long * addr) {
*addr &= ~(1 << nr);
}


#define BIT_MASK(nr) ((1ul) << ((nr) % BITS_PER_LONG))
#define BIT_WORD(nr) ((nr) / BITS_PER_LONG)

static inline int test_and_set_bit(int nr, volatile unsigned long * addr) {
int rc = test_bit(nr,addr);
set_bit(nr,addr);
return rc;
unsigned long mask = BIT_MASK(nr);
long old;

addr += BIT_WORD(nr);

old = __sync_fetch_and_or(addr, mask);
return !!(old & mask);
}


Expand Down

0 comments on commit 9dcce1d

Please sign in to comment.