Skip to content

Commit 6f4ddbb

Browse files
committed
add: [smap] implement netdev interface variant
1 parent 8a8020d commit 6f4ddbb

10 files changed

Lines changed: 744 additions & 86 deletions

File tree

iop/network/smap/Makefile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ SMAP_NETMAN ?= 1
1515
# Build against the ps2ip library.
1616
SMAP_PS2IP ?= 0
1717

18+
# Build against the netdev interface.
19+
SMAP_NETDEV ?= 0
20+
1821
# Enable the modular interface.
1922
SMAP_MODULAR ?= 0
2023

@@ -50,6 +53,11 @@ IOP_CFLAGS += -DBUILDING_SMAP_PS2IP=1
5053
IOP_IMPORT_INCS += tcpip/tcpip
5154
endif
5255

56+
ifneq (x$(SMAP_NETDEV),x0)
57+
IOP_CFLAGS += -DBUILDING_SMAP_NETDEV=1
58+
IOP_IMPORT_INCS += network/netman
59+
endif
60+
5361
ifneq (x$(SMAP_MODULAR),x0)
5462
IOP_CFLAGS += -DBUILDING_SMAP_MODULAR=1
5563
endif

iop/network/smap/src/exports.tab

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
1-
#ifdef BUILDING_SMAP_NETMAN
1+
2+
#if defined(BUILDING_SMAP_NETMAN) || defined(BUILDING_SMAP_NETDEV)
23
DECLARE_EXPORT_TABLE(smap, 1, 1)
34
DECLARE_EXPORT(_retonly)
45
DECLARE_EXPORT(_retonly)

iop/network/smap/src/imports.lst

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ I_SetAlarm
99
I_CancelAlarm
1010
#endif
1111
I_USec2SysClock
12+
#ifdef BUILDING_SMAP_NETDEV
13+
I_ChangeThreadPriority
14+
#endif
1215
thbase_IMPORTS_end
1316

1417
stdio_IMPORTS_start
@@ -67,6 +70,18 @@ I_tcpip_callback_with_block
6770
ps2ip_IMPORTS_end
6871
#endif
6972

73+
#ifdef BUILDING_SMAP_NETDEV
74+
netdev_IMPORTS_start
75+
I_sceInetRegisterNetDevice
76+
I_sceInetUnregisterNetDevice
77+
I_sceInetPktEnQ
78+
I_sceInetPktDeQ
79+
I_sceInetPrintf
80+
I_sceInetAllocPkt
81+
I_sceInetFreePkt
82+
netdev_IMPORTS_end
83+
#endif
84+
7085
thevent_IMPORTS_start
7186
I_CreateEventFlag
7287
I_WaitEventFlag

iop/network/smap/src/include/ipstack.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
#ifndef IPSTACK_H
33
#define IPSTACK_H
44

5-
extern int SMAPCommonTxPacketNext(struct SmapDriverData *SmapDrivPrivData, void **data);
6-
extern void SMAPCommonTxPacketDeQ(struct SmapDriverData *SmapDrivPrivData, void **data);
5+
extern int SMAPCommonTxPacketNext(struct SmapDriverData *SmapDrivPrivData, void **data, void **pbuf);
6+
extern void SMAPCommonTxPacketDeQ(struct SmapDriverData *SmapDrivPrivData, void **data, void **pbuf);
77
extern void SMapCommonLinkStateDown(struct SmapDriverData *SmapDrivPrivData);
88
extern void SMapCommonLinkStateUp(struct SmapDriverData *SmapDrivPrivData);
99
extern void *SMapCommonStackAllocRxPacket(struct SmapDriverData *SmapDrivPrivData, u16 LengthRounded, void **payload);
10-
extern void SMapStackEnQRxPacket(struct SmapDriverData *SmapDrivPrivData, void *pbuf);
10+
extern void SMapStackEnQRxPacket(struct SmapDriverData *SmapDrivPrivData, void *pbuf, u16 length);
1111

1212
#endif

iop/network/smap/src/include/irx_imports.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include <dev9.h>
88
#include <intrman.h>
99
#include <loadcore.h>
10+
#ifdef BUILDING_SMAP_NETDEV
11+
#include <netdev.h>
12+
#endif
1013
#ifdef BUILDING_SMAP_NETMAN
1114
#include <netman.h>
1215
#endif

iop/network/smap/src/include/main.h

Lines changed: 55 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,55 @@
1010
#ifdef BUILDING_SMAP_PS2IP
1111
#include <ps2ip.h>
1212
#endif
13+
#ifdef BUILDING_SMAP_NETDEV
14+
#include <netdev.h>
15+
#endif
1316
#ifdef BUILDING_SMAP_MODULAR
1417
#include <smap_modular.h>
1518
#endif
1619

17-
// In the SONY original, all the calls to DEBUG_PRINTF() were to sceInetPrintf().
18-
#define DEBUG_PRINTF(args...) printf("SMAP: "args)
20+
#ifndef BUILDING_SMAP_NETDEV
21+
#define sceInetPrintf(...) printf(__VA_ARGS__)
22+
#endif
23+
24+
#define DEBUG_PRINTF(args...) sceInetPrintf("SMAP: "args)
25+
26+
#ifdef BUILDING_SMAP_NETDEV
27+
struct RuntimeStats_NetDev
28+
{
29+
u32 m_RxErrorVarious[16];
30+
u32 m_TxErrorVarious[16];
31+
u32 m_Rx_Packets;
32+
u32 m_Tx_Packets;
33+
u32 m_Rx_Bytes;
34+
u32 m_Tx_Bytes;
35+
u32 m_Rx_Errors;
36+
u32 m_Tx_Errors;
37+
u32 m_Rx_Dropped;
38+
u32 m_Tx_Dropped;
39+
u32 m_Rx_Broadcast_Packets;
40+
u32 m_Tx_Broadcast_Packets;
41+
u32 m_Rx_Broadcast_Bytes;
42+
u32 m_Tx_Broadcast_Bytes;
43+
u32 m_Rx_Multicast_Packets;
44+
u32 m_Tx_Multicast_Packets;
45+
u32 m_Rx_Multicast_Bytes;
46+
u32 m_Tx_Multicast_Bytes;
47+
u32 m_Multicast;
48+
u32 m_Collisions;
49+
u32 m_Rx_Length_Er;
50+
u32 m_Rx_Over_Er;
51+
u32 m_Rx_Crc_Er;
52+
u32 m_Rx_Frame_Er;
53+
u32 m_Rx_Fifo_Er;
54+
u32 m_Rx_Missed_Er;
55+
u32 m_Tx_Aborted_Er;
56+
u32 m_Tx_Carrier_Er;
57+
u32 m_Tx_Fifo_Er;
58+
u32 m_Tx_Heartbeat_Er;
59+
u32 m_Tx_Window_Er;
60+
};
61+
#endif
1962

2063
// This struct needs to be the exact same layout as struct NetManEthRuntimeStats!
2164
struct RuntimeStats
@@ -47,7 +90,7 @@ struct SmapDriverData
4790
void *packetToSend;
4891
int Dev9IntrEventFlag;
4992
int IntrHandlerThreadID;
50-
unsigned char SmapDriverStarted; // SMAP driver is started.
93+
unsigned char SmapDriverStarting; // SMAP driver is starting.
5194
unsigned char SmapIsInitialized; // SMAP driver is initialized (software)
5295
unsigned char NetDevStopFlag;
5396
unsigned char EnableLinkCheckTimer;
@@ -58,9 +101,15 @@ struct SmapDriverData
58101
iop_sys_clock_t RxIntrPollingTimer;
59102
#endif
60103
struct RuntimeStats RuntimeStats;
104+
#ifdef BUILDING_SMAP_NETDEV
105+
struct RuntimeStats_NetDev RuntimeStats_NetDev;
106+
#endif
61107
#ifdef BUILDING_SMAP_NETMAN
62108
int NetIFID;
63109
#endif
110+
#ifdef BUILDING_SMAP_NETDEV
111+
sceInetDevOps_t m_devops;
112+
#endif
64113
#ifdef BUILDING_SMAP_MODULAR
65114
const SmapModularHookTable_t *HookTable[1];
66115
#endif
@@ -76,11 +125,12 @@ struct SmapDriverData
76125
/* Function prototypes */
77126
extern int DisplayBanner(void);
78127
extern int smap_init(int argc, char *argv[]);
128+
#ifdef BUILDING_SMAP_NETDEV
129+
extern int smap_deinit(void);
130+
#endif
79131
#ifdef BUILDING_SMAP_PS2IP
80132
extern int SMAPInitStart(void);
81133
#endif
82-
extern int SMAPStart(void);
83-
extern void SMAPStop(void);
84134
extern void SMAPXmit(void);
85135
extern int SMAPGetMACAddress(u8 *buffer);
86136
#ifdef BUILDING_SMAP_PS2IP

iop/network/smap/src/ipstack.c

Lines changed: 76 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,11 @@
22
#include "main.h"
33
#include "ipstack.h"
44

5-
int SMAPCommonTxPacketNext(struct SmapDriverData *SmapDrivPrivData, void **data)
5+
#ifdef BUILDING_SMAP_NETDEV
6+
#include <thevent.h>
7+
#endif
8+
9+
int SMAPCommonTxPacketNext(struct SmapDriverData *SmapDrivPrivData, void **data, void **pbuf)
610
{
711
#ifdef BUILDING_SMAP_MODULAR
812
{
@@ -20,15 +24,49 @@ int SMAPCommonTxPacketNext(struct SmapDriverData *SmapDrivPrivData, void **data)
2024
}
2125
#endif
2226
#if defined(BUILDING_SMAP_NETMAN)
27+
(void)SmapDrivPrivData;
28+
(void)pbuf;
2329
return NetManTxPacketNext(data);
2430
#elif defined(BUILDING_SMAP_PS2IP)
31+
(void)SmapDrivPrivData;
32+
(void)pbuf;
2533
return SMapTxPacketNext(data);
34+
#elif defined(BUILDING_SMAP_NETDEV)
35+
while (1) {
36+
sceInetPkt_t *pkt;
37+
u8 *rp;
38+
unsigned int length;
39+
pkt = sceInetPktDeQ(&SmapDrivPrivData->m_devops.sndq);
40+
if (pkt == NULL) {
41+
return 0;
42+
}
43+
rp = pkt->rp;
44+
length = pkt->wp - rp;
45+
if (length == 0 || ((uiptr)rp & 3) != 0) {
46+
sceInetPrintf("smap: dropped\n");
47+
SmapDrivPrivData->RuntimeStats_NetDev.m_Tx_Dropped += 1;
48+
49+
#ifdef BUILDING_SMAP_NETDEV
50+
SmapDrivPrivData->RuntimeStats_NetDev.m_Tx_Bytes += length;
51+
SmapDrivPrivData->RuntimeStats_NetDev.m_Tx_Packets += 1;
52+
#endif
53+
54+
sceInetFreePkt(&SmapDrivPrivData->m_devops, pkt);
55+
continue;
56+
}
57+
*pbuf = pkt;
58+
*data = rp;
59+
return length;
60+
}
2661
#else
62+
(void)SmapDrivPrivData;
63+
(void)data;
64+
(void)pbuf;
2765
return 0;
2866
#endif
2967
}
3068

31-
void SMAPCommonTxPacketDeQ(struct SmapDriverData *SmapDrivPrivData, void **data)
69+
void SMAPCommonTxPacketDeQ(struct SmapDriverData *SmapDrivPrivData, void **data, void **pbuf)
3270
{
3371
#ifdef BUILDING_SMAP_MODULAR
3472
{
@@ -45,9 +83,18 @@ void SMAPCommonTxPacketDeQ(struct SmapDriverData *SmapDrivPrivData, void **data)
4583
(void)data;
4684
#endif
4785
#if defined(BUILDING_SMAP_NETMAN)
86+
(void)SmapDrivPrivData;
87+
(void)pbuf;
4888
NetManTxPacketDeQ();
4989
#elif defined(BUILDING_SMAP_PS2IP)
90+
(void)SmapDrivPrivData;
91+
(void)pbuf;
5092
SMapTxPacketDeQ();
93+
#elif defined(BUILDING_SMAP_NETDEV)
94+
sceInetFreePkt(&SmapDrivPrivData->m_devops, *pbuf);
95+
#else
96+
(void)SmapDrivPrivData;
97+
(void)pbuf;
5198
#endif
5299
}
53100

@@ -96,6 +143,8 @@ void SMapCommonLinkStateUp(struct SmapDriverData *SmapDrivPrivData)
96143
(void)SmapDrivPrivData;
97144

98145
PS2IPLinkStateUp();
146+
#elif defined(BUILDING_SMAP_NETDEV)
147+
SetEventFlag(SmapDrivPrivData->m_devops.evfid, sceInetDevEFP_StartDone);
99148
#else
100149
(void)SmapDrivPrivData;
101150
#endif
@@ -120,8 +169,10 @@ void *SMapCommonStackAllocRxPacket(struct SmapDriverData *SmapDrivPrivData, u16
120169
}
121170
#endif
122171
#if defined(BUILDING_SMAP_NETMAN)
172+
(void)SmapDrivPrivData;
123173
pbuf = NetManNetProtStackAllocRxPacket(LengthRounded, payload);
124174
#elif defined(BUILDING_SMAP_PS2IP)
175+
(void)SmapDrivPrivData;
125176
struct pbuf *pbuf_struct;
126177

127178
pbuf_struct = pbuf_alloc(PBUF_RAW, LengthRounded, PBUF_POOL);
@@ -130,7 +181,15 @@ void *SMapCommonStackAllocRxPacket(struct SmapDriverData *SmapDrivPrivData, u16
130181
if (pbuf_struct != NULL && payload != NULL) {
131182
*payload = pbuf_struct->payload;
132183
}
184+
#elif defined(BUILDING_SMAP_NETDEV)
185+
sceInetPkt_t *pkt;
186+
pkt = sceInetAllocPkt(&SmapDrivPrivData->m_devops, LengthRounded);
187+
if (pkt != NULL && payload != NULL) {
188+
*payload = pkt->wp;
189+
}
190+
pbuf = pkt;
133191
#else
192+
(void)SmapDrivPrivData;
134193
(void)LengthRounded;
135194
if (payload != NULL) {
136195
*payload = NULL;
@@ -140,7 +199,7 @@ void *SMapCommonStackAllocRxPacket(struct SmapDriverData *SmapDrivPrivData, u16
140199
return pbuf;
141200
}
142201

143-
void SMapStackEnQRxPacket(struct SmapDriverData *SmapDrivPrivData, void *pbuf)
202+
void SMapStackEnQRxPacket(struct SmapDriverData *SmapDrivPrivData, void *pbuf, u16 length)
144203
{
145204
#ifdef BUILDING_SMAP_MODULAR
146205
{
@@ -155,10 +214,24 @@ void SMapStackEnQRxPacket(struct SmapDriverData *SmapDrivPrivData, void *pbuf)
155214
}
156215
#endif
157216
#if defined(BUILDING_SMAP_NETMAN)
217+
(void)SmapDrivPrivData;
218+
(void)length;
158219
NetManNetProtStackEnQRxPacket(pbuf);
159220
#elif defined(BUILDING_SMAP_PS2IP)
221+
(void)SmapDrivPrivData;
222+
(void)length;
160223
SMapLowLevelInput(pbuf);
224+
#elif defined(BUILDING_SMAP_NETDEV)
225+
{
226+
sceInetPkt_t *pkt;
227+
228+
pkt = (sceInetPkt_t *)pbuf;
229+
pkt->wp = &pkt->rp[length];
230+
sceInetPktEnQ(&SmapDrivPrivData->m_devops.rcvq, pkt);
231+
}
161232
#else
233+
(void)SmapDrivPrivData;
234+
(void)length;
162235
(void)pbuf;
163236
#endif
164237
}

iop/network/smap/src/main.c

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -269,7 +269,7 @@ void PS2IPLinkStateDown(void)
269269
}
270270
#endif
271271

272-
#ifdef BUILDING_SMAP_NETMAN
272+
#if defined(BUILDING_SMAP_NETMAN) || defined(BUILDING_SMAP_NETDEV)
273273
// While the header of the export table is small, the large size of the export table (as a whole) places it in data instead of sdata.
274274
extern struct irx_export_table _exp_smap __attribute__((section("data")));
275275
#endif
@@ -287,11 +287,24 @@ int _start(int argc, char *argv[])
287287
int numArgs;
288288
char **pArgv;
289289
#endif
290-
#ifdef BUILDING_SMAP_NETMAN
290+
#if defined(BUILDING_SMAP_NETMAN) || defined(BUILDING_SMAP_NETDEV)
291291
int result;
292292
#endif
293293

294-
#ifdef BUILDING_SMAP_NETMAN
294+
#ifdef BUILDING_SMAP_NETDEV
295+
if (argc < 0) {
296+
result = smap_deinit();
297+
if (result == MODULE_NO_RESIDENT_END) {
298+
#ifdef BUILDING_SMAP_MODULAR
299+
ReleaseLibraryEntries(&_exp_smapmodu);
300+
#endif
301+
ReleaseLibraryEntries(&_exp_smap);
302+
}
303+
return result;
304+
}
305+
#endif
306+
307+
#if defined(BUILDING_SMAP_NETMAN) || defined(BUILDING_SMAP_NETDEV)
295308
if (RegisterLibraryEntries(&_exp_smap) != 0) {
296309
DEBUG_PRINTF("module already loaded\n");
297310
return MODULE_NO_RESIDENT_END;
@@ -324,6 +337,8 @@ int _start(int argc, char *argv[])
324337
return MODULE_NO_RESIDENT_END;
325338
} */
326339

340+
(void)argc;
341+
(void)argv;
327342
#ifdef BUILDING_SMAP_PS2IP
328343
// Parse IP args.
329344
DEBUG_PRINTF("argc %d\n", argc);
@@ -348,7 +363,7 @@ int _start(int argc, char *argv[])
348363
}
349364
#endif
350365

351-
#ifdef BUILDING_SMAP_NETMAN
366+
#if defined(BUILDING_SMAP_NETMAN) || defined(BUILDING_SMAP_NETDEV)
352367
if ((result = smap_init(argc, argv)) < 0) {
353368
DEBUG_PRINTF("smap_init -> %d\n", result);
354369
ReleaseLibraryEntries(&_exp_smap);

0 commit comments

Comments
 (0)