Skip to content

Commit 57ae7d9

Browse files
authored
Merge pull request #826 from fjtrujy/lwip_mainstream
Lwip mainstream
2 parents 5a63561 + 129754a commit 57ae7d9

9 files changed

Lines changed: 192 additions & 125 deletions

File tree

download_dependencies.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,15 +13,15 @@ if [ "x$1" != "xlocked" ]; then
1313
fi
1414
fi
1515

16-
## Download LWIP
17-
LWIP_REPO_URL="https://github.com/ps2dev/lwip.git"
16+
## Download LWIP (upstream, unpatched)
17+
LWIP_REPO_URL="https://github.com/lwip-tcpip/lwip.git"
1818
LWIP_REPO_FOLDER="common/external_deps/lwip"
19-
LWIP_BRANCH_NAME="ps2-v2.0.3"
19+
LWIP_BRANCH_NAME="STABLE-2_0_3_RELEASE"
2020
if test ! -d "$LWIP_REPO_FOLDER"; then
2121
git clone --depth 1 -b $LWIP_BRANCH_NAME $LWIP_REPO_URL "$LWIP_REPO_FOLDER"_inprogress || exit 1
2222
mv "$LWIP_REPO_FOLDER"_inprogress "$LWIP_REPO_FOLDER"
2323
else
24-
(cd "$LWIP_REPO_FOLDER" && git fetch origin && git reset --hard "origin/${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1
24+
(cd "$LWIP_REPO_FOLDER" && git fetch origin --tags && git reset --hard "${LWIP_BRANCH_NAME}" && git checkout "$LWIP_BRANCH_NAME" && cd - )|| exit 1
2525
fi
2626

2727
## Download libsmb2

ee/network/tcpip/Makefile

Lines changed: 35 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,41 @@ endif
3535

3636
EE_INCS += -I$(LWIP)/src/include -I$(LWIP)/src/include/ipv4
3737

38-
ps2api_OBJECTS = api_lib.o api_msg.o api_netbuf.o err.o sockets.o tcpip.o
39-
ps2api_IPV4 = icmp.o ip.o ip4.o ip4_addr.o ip4_frag.o inet_chksum.o
40-
ps2ip_OBJECTS = sys.o lwip_init.o mem.o netif.o pbuf.o stats.o tcp_in.o tcp_out.o udp.o memp.o tcp.o ethernet.o etharp.o raw.o def.o timeouts.o $(ps2api_IPV4) $(ps2api_OBJECTS)
38+
ps2api_OBJECTS = \
39+
api_lib.o \
40+
api_msg.o \
41+
api_netbuf.o \
42+
err.o \
43+
sockets.o \
44+
tcpip.o
45+
46+
ps2api_IPV4 = \
47+
icmp.o \
48+
ip.o \
49+
ip4.o \
50+
ip4_addr.o \
51+
ip4_frag.o \
52+
inet_chksum.o
53+
54+
ps2ip_OBJECTS = \
55+
sys.o \
56+
lwip_init.o \
57+
mem.o \
58+
netif.o \
59+
pbuf.o \
60+
stats.o \
61+
tcp_in.o \
62+
tcp_out.o \
63+
udp.o \
64+
memp.o \
65+
tcp.o \
66+
ethernet.o \
67+
etharp.o \
68+
raw.o \
69+
def.o \
70+
timeouts.o \
71+
$(ps2api_IPV4) \
72+
$(ps2api_OBJECTS)
4173

4274
ifdef PS2IP_DHCP
4375
ps2ip_OBJECTS += dhcp.o

ee/network/tcpip/src/include/arch/cc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44
#include <errno.h>
55
#include <stdlib.h>
66
#include <stddef.h>
7+
/* Upstream lwIP's sockets.h references struct timeval without including
8+
sys/time.h when LWIP_TIMEVAL_PRIVATE=0. Pull it in via this port header
9+
so every lwIP translation unit (and every consumer that #includes
10+
arch/cc.h transitively through lwip/opt.h) sees struct timeval. */
11+
#include <sys/time.h>
712

813
#define PACK_STRUCT_FIELD(x) x __attribute((packed))
914
#define PACK_STRUCT_STRUCT __attribute((packed))

ee/network/tcpip/src/include/lwipopts.h

Lines changed: 7 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
#ifndef __LWIPOPTS_H__
55
#define __LWIPOPTS_H__
66

7-
/**
8-
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
9-
* use lwIP facilities.
10-
*/
11-
#define NO_SYS 0
12-
137
#define LWIP_TIMEVAL_PRIVATE 0
148

159
/* ---------- Thread options ---------- */
@@ -41,43 +35,16 @@
4135
*/
4236
#define TCPIP_THREAD_PRIO DEFAULT_THREAD_PRIO
4337

44-
/**
45-
* SLIP_THREAD_STACKSIZE: The stack size used by the slipif_loop thread.
46-
* The stack size value itself is platform-dependent, but is passed to
47-
* sys_thread_new() when the thread is created.
48-
*/
49-
#define SLIPIF_THREAD_STACKSIZE DEFAULT_THREAD_STACKSIZE
50-
51-
/**
52-
* SLIPIF_THREAD_PRIO: The priority assigned to the slipif_loop thread.
53-
* The priority value itself is platform-dependent, but is passed to
54-
* sys_thread_new() when the thread is created.
55-
*/
56-
#define SLIPIF_THREAD_PRIO DEFAULT_THREAD_PRIO
57-
58-
/**
59-
* PPP_THREAD_STACKSIZE: The stack size used by the pppInputThread.
60-
* The stack size value itself is platform-dependent, but is passed to
61-
* sys_thread_new() when the thread is created.
62-
*/
63-
#define PPP_THREAD_STACKSIZE DEFAULT_THREAD_STACKSIZE
64-
65-
/**
66-
* PPP_THREAD_PRIO: The priority assigned to the pppInputThread.
67-
* The priority value itself is platform-dependent, but is passed to
68-
* sys_thread_new() when the thread is created.
69-
*/
70-
#define PPP_THREAD_PRIO DEFAULT_THREAD_PRIO
71-
7238
/*
7339
------------------------------------
7440
---------- Memory options ----------
7541
------------------------------------
7642
*/
7743
/**
78-
* MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library
79-
* instead of the lwip internal allocator. Can save code size if you
80-
* already use it.
44+
* MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by the C-library
45+
* instead of lwIP's internal allocator. Default is 0; enabled on EE
46+
* because newlib's malloc is already linked in and the heap pool is
47+
* cheaper than a duplicate lwIP heap.
8148
*/
8249
#define MEM_LIBC_MALLOC 1
8350

@@ -115,12 +82,11 @@
11582
/**
11683
* MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
11784
* for incoming packets.
118-
* (only needed if you use tcpip.c)
85+
* SP193: this should be around the size of the TCP window because the
86+
* TCPIP thread may take a while to execute (non-preemptive multitasking),
87+
* otherwise incoming frames may get dropped.
11988
*/
120-
//SP193: this should be around the size of the TCP window because the TCPIP thread may take a while to execute (non-preemptive multitasking), otherwise incoming frames may get dropped.
121-
#ifndef LWIP_TCPIP_CORE_LOCKING_INPUT
12289
#define MEMP_NUM_TCPIP_MSG_INPKT 50
123-
#endif
12490

12591
/**
12692
* MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
@@ -146,13 +112,6 @@
146112
*/
147113
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
148114

149-
/** SYS_LIGHTWEIGHT_PROT
150-
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
151-
* for certain critical regions during buffer allocation, deallocation and
152-
* memory allocation and deallocation.
153-
*/
154-
#define SYS_LIGHTWEIGHT_PROT 1
155-
156115
/*
157116
---------------------------------
158117
---------- TCP options ----------

iop/network/smap/src/xfer.c

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,10 +51,23 @@ static inline void CopyFromFIFO(volatile u8 *smap_regbase, void *buffer, unsigne
5151

5252
SMAP_REG16(SMAP_R_RXFIFO_RD_PTR) = RxBdPtr;
5353

54-
result = SmapDmaTransfer(smap_regbase, buffer, length, DMAC_TO_MEM);
54+
/* SPD DMA requires a 4-byte aligned destination; fall back to PIO for unaligned buffers. */
55+
if (((uiptr)buffer & 3) == 0) {
56+
result = SmapDmaTransfer(smap_regbase, buffer, length, DMAC_TO_MEM);
5557

56-
for (i = result; (unsigned int)i < length; i += 4) {
57-
((u32 *)buffer)[i / 4] = SMAP_REG32(SMAP_R_RXFIFO_DATA);
58+
for (i = result; (unsigned int)i < length; i += 4) {
59+
((u32 *)buffer)[i / 4] = SMAP_REG32(SMAP_R_RXFIFO_DATA);
60+
}
61+
} else {
62+
u8 *p = (u8 *)buffer;
63+
for (i = 0; (unsigned int)i < length; i += 4) {
64+
u32 v = SMAP_REG32(SMAP_R_RXFIFO_DATA);
65+
p[0] = (u8)v;
66+
p[1] = (u8)(v >> 8);
67+
p[2] = (u8)(v >> 16);
68+
p[3] = (u8)(v >> 24);
69+
p += 4;
70+
}
5871
}
5972
}
6073

@@ -66,10 +79,23 @@ static inline void CopyToFIFO(volatile u8 *smap_regbase, const void *buffer, uns
6679
return;
6780
}
6881

69-
result = SmapDmaTransfer(smap_regbase, (void *)buffer, length, DMAC_FROM_MEM);
82+
/* SPD DMA requires a 4-byte aligned source, and the PIO loop below does
83+
word-sized loads from the buffer. If the pbuf payload is only halfword-
84+
aligned (which lwIP 2.2.1 can produce for some TX paths), a plain lw
85+
raises an IOP Address Error. Detect that and take an unaligned path. */
86+
if (((uiptr)buffer & 3) == 0) {
87+
result = SmapDmaTransfer(smap_regbase, (void *)buffer, length, DMAC_FROM_MEM);
7088

71-
for (i = result; (unsigned int)i < length; i += 4) {
72-
SMAP_REG32(SMAP_R_TXFIFO_DATA) = ((u32 *)buffer)[i / 4];
89+
for (i = result; (unsigned int)i < length; i += 4) {
90+
SMAP_REG32(SMAP_R_TXFIFO_DATA) = ((u32 *)buffer)[i / 4];
91+
}
92+
} else {
93+
const u8 *p = (const u8 *)buffer;
94+
for (i = 0; (unsigned int)i < length; i += 4) {
95+
u32 v = (u32)p[0] | ((u32)p[1] << 8) | ((u32)p[2] << 16) | ((u32)p[3] << 24);
96+
SMAP_REG32(SMAP_R_TXFIFO_DATA) = v;
97+
p += 4;
98+
}
7399
}
74100
}
75101

iop/tcpip/tcpip-base/include/arch/cc.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,11 @@
33

44
#include <errno.h>
55
#include <stddef.h>
6+
/* Upstream lwIP's sockets.h references struct timeval without including
7+
sys/time.h when LWIP_TIMEVAL_PRIVATE=0. Pull it in via this port header
8+
so every lwIP translation unit (and every consumer that #includes
9+
arch/cc.h transitively through lwip/opt.h) sees struct timeval. */
10+
#include <sys/time.h>
611

712
#define BYTE_ORDER LITTLE_ENDIAN
813

iop/tcpip/tcpip-base/include/lwipopts.h

Lines changed: 33 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,6 @@
44
#ifndef __LWIPOPTS_H__
55
#define __LWIPOPTS_H__
66

7-
/**
8-
* NO_SYS==1: Provides VERY minimal functionality. Otherwise,
9-
* use lwIP facilities.
10-
*/
11-
#define NO_SYS 0
12-
137
#define LWIP_TIMEVAL_PRIVATE 0
148

159
/* ---------- Thread options ---------- */
@@ -41,51 +35,26 @@
4135
*/
4236
#define TCPIP_THREAD_PRIO DEFAULT_THREAD_PRIO
4337

44-
/**
45-
* SLIP_THREAD_STACKSIZE: The stack size used by the slipif_loop thread.
46-
* The stack size value itself is platform-dependent, but is passed to
47-
* sys_thread_new() when the thread is created.
48-
*/
49-
#define SLIPIF_THREAD_STACKSIZE DEFAULT_THREAD_STACKSIZE
50-
51-
/**
52-
* SLIPIF_THREAD_PRIO: The priority assigned to the slipif_loop thread.
53-
* The priority value itself is platform-dependent, but is passed to
54-
* sys_thread_new() when the thread is created.
55-
*/
56-
#define SLIPIF_THREAD_PRIO DEFAULT_THREAD_PRIO
57-
58-
/**
59-
* PPP_THREAD_STACKSIZE: The stack size used by the pppInputThread.
60-
* The stack size value itself is platform-dependent, but is passed to
61-
* sys_thread_new() when the thread is created.
62-
*/
63-
#define PPP_THREAD_STACKSIZE DEFAULT_THREAD_STACKSIZE
64-
65-
/**
66-
* PPP_THREAD_PRIO: The priority assigned to the pppInputThread.
67-
* The priority value itself is platform-dependent, but is passed to
68-
* sys_thread_new() when the thread is created.
69-
*/
70-
#define PPP_THREAD_PRIO DEFAULT_THREAD_PRIO
71-
7238
/*
7339
------------------------------------
7440
---------- Memory options ----------
7541
------------------------------------
7642
*/
77-
/**
78-
* MEM_LIBC_MALLOC==1: Use malloc/free/realloc provided by your C-library
79-
* instead of the lwip internal allocator. Can save code size if you
80-
* already use it.
81-
*/
82-
#define MEM_LIBC_MALLOC 0 //FJTRUJY disable it for IOP
83-
8443
/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which
8544
lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2
8645
byte alignment -> define MEM_ALIGNMENT to 2. */
8746
#define MEM_ALIGNMENT 4
8847

48+
/**
49+
* LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT==1: make mem_free() callable from
50+
* any context (ISR/disabled-interrupt) by using SYS_ARCH_PROTECT instead of
51+
* a mutex for critical regions. Required on IOP because SMAP RX interrupts
52+
* invoke pbuf_free() in interrupt-disabled context; taking a mutex there
53+
* would violate the critical section (same effect as ps2dev/lwip's mem.c
54+
* patch, but achieved via upstream lwipopts instead of patching lwIP).
55+
*/
56+
#define LWIP_ALLOW_MEM_FREE_FROM_OTHER_CONTEXT 1
57+
8958
/**
9059
* MEM_SIZE: the size of the heap memory. If the application will send
9160
* a lot of data that needs to be copied, this should be set high.
@@ -94,6 +63,25 @@
9463
Up to TCP_SND_BUF * 2 segments may be transmitted at once, thanks to Nagle and Delayed Ack. */
9564
#define MEM_SIZE (TCP_SND_BUF * 2)
9665

66+
/*
67+
-----------------------------------------------
68+
---------- IP options -------------------------
69+
-----------------------------------------------
70+
*/
71+
/**
72+
* IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets.
73+
* Disabled: PS2 networking targets a local LAN with MTU=1500, and
74+
* TCP negotiates MSS=1460 so fragments never arise in the common
75+
* case. Frees MEMP_NUM_REASSDATA / MEMP_NUM_FRAG_PBUF pool entries.
76+
*/
77+
#define IP_REASSEMBLY 0
78+
79+
/**
80+
* IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU.
81+
* Disabled: TCP_MSS=1460 ensures we never exceed Ethernet MTU=1500.
82+
*/
83+
#define IP_FRAG 0
84+
9785
/*
9886
------------------------------------------------
9987
---------- Internal Memory Pool Sizes ----------
@@ -102,20 +90,11 @@
10290
/**
10391
* MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used
10492
* for incoming packets.
105-
* (only needed if you use tcpip.c)
106-
*/
107-
//SP193: this should be around the size of the TCP window because the TCPIP thread may take a while to execute (non-preemptive multitasking), otherwise incoming frames may get dropped.
108-
#ifndef LWIP_TCPIP_CORE_LOCKING_INPUT
109-
#define MEMP_NUM_TCPIP_MSG_INPKT 24
110-
#endif
111-
112-
/**
113-
* MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used
114-
* for callback/timeout API communication.
115-
* (only needed if you use tcpip.c)
93+
* SP193: this should be around the size of the TCP window because the
94+
* TCPIP thread may take a while to execute (non-preemptive multitasking),
95+
* otherwise incoming frames may get dropped.
11696
*/
117-
//SP193: this should be around the size of MEM_SIZE (in PBUFs), to prevent transmissions from being potentially being dropped.
118-
#define MEMP_NUM_TCPIP_MSG_API 8
97+
#define MEMP_NUM_TCPIP_MSG_INPKT 24
11998

12099
/**
121100
* MEMP_NUM_NETCONN: the number of struct netconns.
@@ -138,13 +117,6 @@
138117
*/
139118
#define LWIP_TCPIP_CORE_LOCKING_INPUT 1
140119

141-
/** SYS_LIGHTWEIGHT_PROT
142-
* define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection
143-
* for certain critical regions during buffer allocation, deallocation and
144-
* memory allocation and deallocation.
145-
*/
146-
#define SYS_LIGHTWEIGHT_PROT 1
147-
148120
/*
149121
---------------------------------
150122
---------- TCP options ----------

0 commit comments

Comments
 (0)