From 966ee6606ecc48c1c4da20308f8061f5ac554982 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 17 Dec 2023 21:12:33 +0100 Subject: [PATCH 1/2] fix wrong definitinon --- ee/libpthreadglue/src/osal.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ee/libpthreadglue/src/osal.c b/ee/libpthreadglue/src/osal.c index d95e40e214e..f829c5c5c27 100644 --- a/ee/libpthreadglue/src/osal.c +++ b/ee/libpthreadglue/src/osal.c @@ -24,7 +24,7 @@ #define POLLING_DELAY_IN_us 100 -#if F___threadInfo +#ifdef F___threadInfo struct OsalThreadInfo __threadInfo[MAX_THREADS]; #endif From 5c5283e0f3141f823e5d7ebe7bb5bd445669a841 Mon Sep 17 00:00:00 2001 From: Francisco Javier Trujillo Mata Date: Sun, 17 Dec 2023 12:46:43 +0100 Subject: [PATCH 2/2] Separate netman by functions --- ee/network/netman/Makefile | 37 +- ee/network/netman/src/include/rpc_server.h | 6 +- ee/network/netman/src/netman.c | 134 +++++-- ee/network/netman/src/rpc_client.c | 437 ++++++++++++--------- ee/network/netman/src/rpc_server.c | 209 ++++++---- 5 files changed, 521 insertions(+), 302 deletions(-) diff --git a/ee/network/netman/Makefile b/ee/network/netman/Makefile index 87bb3b2db57..f90bd306876 100644 --- a/ee/network/netman/Makefile +++ b/ee/network/netman/Makefile @@ -6,9 +6,44 @@ # Licenced under Academic Free License version 2.0 # Review ps2sdk README & LICENSE files for further details. -EE_OBJS = netman.o rpc_server.o rpc_client.o erl-support.o +CORE_OBJS = erl-support.o + +NETMAN_OBJS = \ + __netman_MainNetProtStack.o __netman_IsInitialized.o __netman_IsNetStackInitialized.o __netman_NIFLinkState.o \ + NetManToggleGlobalNetIFLinkState.o NetManGetGlobalNetIFLinkState.o NetManInit.o NetManDeinit.o \ + NetManRegisterNetworkStack.o NetManUnregisterNetworkStack.o NetManNetIFXmit.o NetManIoctl.o \ + NetManNetProtStackAllocRxPacket.o NetManNetProtStackFreeRxPacket.o NetManNetProtStackEnQRxPacket.o \ + NetManTxPacketNext.o NetManTxPacketDeQ.o NetManTxPacketAfter.o NetManNetProtStackReallocRxPacket.o + +RPC_SERVER_OBJS = \ + __NETMAN_RpcSvr_threadID.o __NETMAN_Rx_threadID.o __NETMAN_SifHandlerID.o __rpc_server_IsInitialized.o \ + __rpc_server_IsProcessingRx.o __rpc_server_FrameBufferStatus.o __rpc_server_RxIOPFrameBufferStatus.o \ + __rpc_server_cb_queue.o __rpc_server_cb_srv.o \ + __rpc_server_ClearBufferLen.o _NetManRPCAllocRxBuffers.o _NetManInitRPCServer.o _NetManDeinitRPCServer.o + +RPC_CLIENT_OBJS = \ + __rpc_client_TransmitBuffer.o __rpc_client_ReceiveBuffer.o __NETMAN_rpc_cd.o __NetManIOSemaID.o \ + __NETMAN_Tx_threadID.o __netman_IOPFrameBufferWrPtr.o __netman_IOPFrameBuffer.o \ + __netman_IOPFrameBufferStatus.o __netman_FrameBufferStatus.o __netman_rpc_client_IsInitialized.o \ + __netman_rpc_client_IIsProcessingTx.o __rpc_client_deinitCleanup.o NetManInitRPCClient.o \ + NetManRPCRegisterNetworkStack.o NetManRPCUnregisterNetworkStack.o NetManDeinitRPCClient.o NetManRpcIoctl.o \ + NetManRpcNetIFXmit.o NetManSetMainIF.o NetManQueryMainIF.o NetManSetLinkMode.o + +EE_OBJS = $(CORE_OBJS) $(NETMAN_OBJS) $(RPC_SERVER_OBJS) $(RPC_CLIENT_OBJS) include $(PS2SDKSRC)/Defs.make include $(PS2SDKSRC)/ee/Rules.lib.make include $(PS2SDKSRC)/ee/Rules.make include $(PS2SDKSRC)/ee/Rules.release + +$(NETMAN_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)netman.c + $(DIR_GUARD) + $(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@ + +$(RPC_SERVER_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)rpc_server.c + $(DIR_GUARD) + $(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@ + +$(RPC_CLIENT_OBJS:%=$(EE_OBJS_DIR)%): $(EE_SRC_DIR)rpc_client.c + $(DIR_GUARD) + $(EE_C_COMPILE) -DF_$(*:$(EE_OBJS_DIR)%=%) $< -c -o $@ diff --git a/ee/network/netman/src/include/rpc_server.h b/ee/network/netman/src/include/rpc_server.h index 3c91e1cdb3e..a9f87ee19ff 100644 --- a/ee/network/netman/src/include/rpc_server.h +++ b/ee/network/netman/src/include/rpc_server.h @@ -1,3 +1,3 @@ -int NetManInitRPCServer(void); -void NetManDeinitRPCServer(void); -int NetManRPCAllocRxBuffers(void); +int _NetManInitRPCServer(void); +void _NetManDeinitRPCServer(void); +int _NetManRPCAllocRxBuffers(void); diff --git a/ee/network/netman/src/netman.c b/ee/network/netman/src/netman.c index aead589d0a0..882a1fd7e08 100644 --- a/ee/network/netman/src/netman.c +++ b/ee/network/netman/src/netman.c @@ -8,10 +8,42 @@ #include "rpc_client.h" #include "rpc_server.h" -static struct NetManNetProtStack MainNetProtStack; -static unsigned char IsInitialized=0, IsNetStackInitialized=0; -static char NIFLinkState = 0; +#ifdef F___netman_MainNetProtStack +struct NetManNetProtStack __netman_MainNetProtStack; +#else +extern struct NetManNetProtStack __netman_MainNetProtStack; +#endif + +#ifdef F___netman_IsInitialized +unsigned char __netman_IsInitialized=0; +#else +extern unsigned char __netman_IsInitialized; +#endif + +#ifdef F___netman_IsNetStackInitialized +unsigned char __netman_IsNetStackInitialized=0; +#else +extern unsigned char __netman_IsNetStackInitialized; +#endif + +#ifdef F___netman_NIFLinkState +char __netman_NIFLinkState = 0; +#else +extern char __netman_NIFLinkState; +#endif + +static inline void NetManUpdateStack__netman_NIFLinkState(void) +{ + if(__netman_IsNetStackInitialized) + { + if(__netman_NIFLinkState) + __netman_MainNetProtStack.LinkStateUp(); + else + __netman_MainNetProtStack.LinkStateDown(); + } +} +#ifdef F_NetManToggleGlobalNetIFLinkState /* Upon stack registration on the IOP side, this function will be called. But the network stack won't be updated then because the RPC wouldn't have been completely initialized, which would prevent the stack from performing some actions like sending Gratuitous Arp packets. @@ -19,68 +51,65 @@ static char NIFLinkState = 0; The NIF status updated will be sent again when the RPC is fully initialized, as shown in NetManRegisterNetworkStack(). */ void NetManToggleGlobalNetIFLinkState(unsigned char state) { - NIFLinkState = state; + __netman_NIFLinkState = state; - NetManUpdateStackNIFLinkState(); + NetManUpdateStack__netman_NIFLinkState(); } +#endif +#ifdef F_NetManGetGlobalNetIFLinkState int NetManGetGlobalNetIFLinkState(void) { - return NIFLinkState; -} - -void NetManUpdateStackNIFLinkState(void) -{ - if(IsNetStackInitialized) - { - if(NIFLinkState) - MainNetProtStack.LinkStateUp(); - else - MainNetProtStack.LinkStateDown(); - } + return __netman_NIFLinkState; } +#endif +#ifdef F_NetManInit int NetManInit(void) { int result; - if(!IsInitialized) + if(!__netman_IsInitialized) { - if((result=NetManInitRPCServer())==0) + if((result=_NetManInitRPCServer())==0) { - if((result=NetManInitRPCClient())==0) IsInitialized = 1; + if((result=NetManInitRPCClient())==0) __netman_IsInitialized = 1; } }else result = 0; return result; } +#endif +#ifdef F_NetManDeinit void NetManDeinit(void) { - if(IsInitialized) + if(__netman_IsInitialized) { NetManUnregisterNetworkStack(); NetManDeinitRPCClient(); - NetManDeinitRPCServer(); - IsInitialized = 0; + _NetManDeinitRPCServer(); + __netman_IsInitialized = 0; } } +#endif +#ifdef F_NetManRegisterNetworkStack int NetManRegisterNetworkStack(const struct NetManNetProtStack *stack) { int result; if((result=NetManInit())==0) { - if(!IsNetStackInitialized) + if(!__netman_IsNetStackInitialized) { if((result=NetManRPCRegisterNetworkStack())==0) { - memcpy(&MainNetProtStack, stack, sizeof(MainNetProtStack)); - IsNetStackInitialized=1; - if((result=NetManRPCAllocRxBuffers()) == 0) - NetManUpdateStackNIFLinkState(); + memcpy(&__netman_MainNetProtStack, stack, sizeof(__netman_MainNetProtStack)); + __netman_IsNetStackInitialized=1; + if((result=_NetManRPCAllocRxBuffers()) == 0) + NetManUpdateStack__netman_NIFLinkState(); } } else result=0; @@ -88,62 +117,83 @@ int NetManRegisterNetworkStack(const struct NetManNetProtStack *stack) return result; } +#endif +#ifdef F_NetManUnregisterNetworkStack void NetManUnregisterNetworkStack(void) { - if(IsNetStackInitialized) + if(__netman_IsNetStackInitialized) { NetManRPCUnregisterNetworkStack(); - memset(&MainNetProtStack, 0, sizeof(MainNetProtStack)); + memset(&__netman_MainNetProtStack, 0, sizeof(__netman_MainNetProtStack)); - IsNetStackInitialized=0; + __netman_IsNetStackInitialized=0; } } +#endif +#ifdef F_NetManNetIFXmit void NetManNetIFXmit(void) { - if(IsInitialized) + if(__netman_IsInitialized) NetManRpcNetIFXmit(); } +#endif +#ifdef F_NetManIoctl int NetManIoctl(unsigned int command, void *arg, unsigned int arg_len, void *output, unsigned int length) { - return IsInitialized?NetManRpcIoctl(command, arg, arg_len, output, length):-1; + return __netman_IsInitialized?NetManRpcIoctl(command, arg, arg_len, output, length):-1; } +#endif +#ifdef F_NetManNetProtStackAllocRxPacket void *NetManNetProtStackAllocRxPacket(unsigned int length, void **payload) { - return IsNetStackInitialized?MainNetProtStack.AllocRxPacket(length, payload):NULL; + return __netman_IsNetStackInitialized? __netman_MainNetProtStack.AllocRxPacket(length, payload) : NULL; } +#endif +#ifdef F_NetManNetProtStackFreeRxPacket void NetManNetProtStackFreeRxPacket(void *packet) { - if(IsNetStackInitialized) MainNetProtStack.FreeRxPacket(packet); + if(__netman_IsNetStackInitialized) __netman_MainNetProtStack.FreeRxPacket(packet); } +#endif +#ifdef F_NetManNetProtStackEnQRxPacket void NetManNetProtStackEnQRxPacket(void *packet) { - if(IsNetStackInitialized) - MainNetProtStack.EnQRxPacket(packet); + if(__netman_IsNetStackInitialized) + __netman_MainNetProtStack.EnQRxPacket(packet); } +#endif +#ifdef F_NetManTxPacketNext int NetManTxPacketNext(void **payload) { - return IsInitialized?MainNetProtStack.NextTxPacket(payload):-1; + return __netman_IsInitialized? __netman_MainNetProtStack.NextTxPacket(payload) : -1; } +#endif +#ifdef F_NetManTxPacketDeQ void NetManTxPacketDeQ(void) { - if(IsInitialized) - MainNetProtStack.DeQTxPacket(); + if(__netman_IsInitialized) + __netman_MainNetProtStack.DeQTxPacket(); } +#endif +#ifdef F_NetManTxPacketAfter int NetManTxPacketAfter(void **payload) { - return IsInitialized?MainNetProtStack.AfterTxPacket(payload):-1; + return __netman_IsInitialized? __netman_MainNetProtStack.AfterTxPacket(payload) : -1; } +#endif +#ifdef F_NetManNetProtStackReallocRxPacket void NetManNetProtStackReallocRxPacket(void *packet, unsigned int length) { - if(IsNetStackInitialized) MainNetProtStack.ReallocRxPacket(packet, length); + if(__netman_IsNetStackInitialized) __netman_MainNetProtStack.ReallocRxPacket(packet, length); } +#endif diff --git a/ee/network/netman/src/rpc_client.c b/ee/network/netman/src/rpc_client.c index 6733b8379ed..248e7e88dd7 100644 --- a/ee/network/netman/src/rpc_client.c +++ b/ee/network/netman/src/rpc_client.c @@ -8,51 +8,201 @@ #include "rpc_client.h" -static SifRpcClientData_t NETMAN_rpc_cd; -extern void *_gp; - -static union { +typedef union { s32 mode; struct NetManIoctl IoctlArgs; char netifName[NETMAN_NETIF_NAME_MAX_LEN]; struct NetManRegNetworkStack NetStack; u8 buffer[128]; -}TransmitBuffer ALIGNED(64); +} __attribute__((packed,aligned(64))) trasnmit_buffer_t; -static union { +typedef union { s32 result; struct NetManRegNetworkStackResult NetStackResult; struct NetManIoctlResult IoctlResult; struct NetManQueryMainNetIFResult QueryMainNetIFResult; u8 buffer[128]; -}ReceiveBuffer ALIGNED(64); - -static int NetManIOSemaID = -1, NETMAN_Tx_threadID = -1; -static unsigned char NETMAN_Tx_ThreadStack[0x1000] ALIGNED(16); - -static unsigned short int IOPFrameBufferWrPtr; -static u8 *IOPFrameBuffer = NULL; /* On the IOP side. */ -static struct NetManBD *IOPFrameBufferStatus = NULL; -static struct NetManBD *FrameBufferStatus = NULL; +} __attribute__((packed,aligned(64))) receive_buffer_t; -static unsigned char IsInitialized=0, IsProcessingTx; +extern void *_gp; -static void deinitCleanup(void) +#ifdef F___rpc_client_TransmitBuffer +trasnmit_buffer_t __rpc_client_TransmitBuffer; +#else +extern trasnmit_buffer_t __rpc_client_TransmitBuffer; +#endif + +#ifdef F___rpc_client_ReceiveBuffer +receive_buffer_t __rpc_client_ReceiveBuffer; +#else +extern receive_buffer_t __rpc_client_ReceiveBuffer; +#endif + +#ifdef F___NETMAN_rpc_cd +SifRpcClientData_t __NETMAN_rpc_cd; +#else +extern SifRpcClientData_t __NETMAN_rpc_cd; +#endif + +#ifdef F___NetManIOSemaID +int __NetManIOSemaID = -1; +#else +extern int __NetManIOSemaID; +#endif + +#ifdef F___NETMAN_Tx_threadID +int __NETMAN_Tx_threadID = -1; +#else +extern int __NETMAN_Tx_threadID; +#endif + +#ifdef F___netman_IOPFrameBufferWrPtr +unsigned short int __netman_IOPFrameBufferWrPtr; +#else +extern unsigned short int __netman_IOPFrameBufferWrPtr; +#endif + +#ifdef F___netman_IOPFrameBuffer +u8 *__netman_IOPFrameBuffer = NULL; /* On the IOP side. */ +#else +extern u8 *__netman_IOPFrameBuffer; +#endif + +#ifdef F___netman_IOPFrameBufferStatus +struct NetManBD *__netman_IOPFrameBufferStatus = NULL; +#else +extern struct NetManBD *__netman_IOPFrameBufferStatus; +#endif + +#ifdef F___netman_FrameBufferStatus +struct NetManBD *__netman_FrameBufferStatus = NULL; +#else +extern struct NetManBD *__netman_FrameBufferStatus; +#endif + +#ifdef F___netman_rpc_client_IsInitialized +unsigned char __netman_rpc_client_IsInitialized=0; +#else +extern unsigned char __netman_rpc_client_IsInitialized; +#endif + +#ifdef F___netman_rpc_client_IIsProcessingTx +unsigned char __netman_rpc_client_IIsProcessingTx; +#else +extern unsigned char __netman_rpc_client_IIsProcessingTx; +#endif + +#ifdef F___rpc_client_deinitCleanup +void __rpc_client_deinitCleanup(void) { - if(NetManIOSemaID >= 0) + if(__NetManIOSemaID >= 0) { - DeleteSema(NetManIOSemaID); - NetManIOSemaID = -1; + DeleteSema(__NetManIOSemaID); + __NetManIOSemaID = -1; } - if(NETMAN_Tx_threadID >= 0) + if(__NETMAN_Tx_threadID >= 0) { - TerminateThread(NETMAN_Tx_threadID); - DeleteThread(NETMAN_Tx_threadID); - NETMAN_Tx_threadID = -1; + TerminateThread(__NETMAN_Tx_threadID); + DeleteThread(__NETMAN_Tx_threadID); + __NETMAN_Tx_threadID = -1; } } +#else +extern void __rpc_client_deinitCleanup(void); +#endif + +#ifdef F_NetManInitRPCClient +static unsigned char NETMAN_Tx_ThreadStack[0x1000] ALIGNED(16); + +static void NETMAN_TxThread(void *arg) +{ + static SifCmdHeader_t cmd ALIGNED(64); + SifDmaTransfer_t dmat[2]; + struct NetManPktCmd *npcmd; + int dmat_id, unaligned, unalignedCache; + void *payload, *payloadAligned, *payloadCacheAligned; + volatile struct NetManBD *bd, *bdNext; + + (void)arg; + + while(1) + { + int length, NumTx; + SleepThread(); + + NumTx = 0; + while((length = NetManTxPacketNext(&payload)) > 0) + { + __netman_rpc_client_IIsProcessingTx = 1; + + //Write back D-cache, before performing a DMA transfer. + unaligned = (int)((u32)payload & 15); + unalignedCache = (int)((u32)payload & 63); + payloadAligned = (void*)((u32)payload & ~15); + payloadCacheAligned = (void*)((u32)payload & ~63); + SifWriteBackDCache(payloadCacheAligned, (length + unalignedCache + 63) & ~63); + + do { + //Wait for a spot to be freed up. + bd = UNCACHED_SEG(&__netman_FrameBufferStatus[__netman_IOPFrameBufferWrPtr]); + while(bd->length != 0){} + + //Transfer to IOP RAM + //Determine mode of transfer. + bdNext = UNCACHED_SEG(&__netman_FrameBufferStatus[(__netman_IOPFrameBufferWrPtr + 1) % NETMAN_RPC_BLOCK_SIZE]); + if((NumTx + 1) >= NETMAN_FRAME_GROUP_SIZE || bdNext->length == 0) + { + //Prepare SIFCMD packet + //Record the frame length. + npcmd = (struct NetManPktCmd*)&cmd.opt; + npcmd->length = length; + npcmd->offset = unaligned; + npcmd->id = __netman_IOPFrameBufferWrPtr; + + while((dmat_id = SifSendCmd(NETMAN_SIFCMD_ID, &cmd, sizeof(SifCmdHeader_t), + (void*)payloadAligned, + (void*)&__netman_IOPFrameBuffer[__netman_IOPFrameBufferWrPtr * NETMAN_MAX_FRAME_SIZE], + (length + unaligned + 15) & ~15)) == 0){ }; + } else { + //Record the frame length. + bd->length = length; + bd->offset = unaligned; + + //Normal DMA transfer + dmat[0].src = (void*)payloadAligned; + dmat[0].dest = (void*)&__netman_IOPFrameBuffer[__netman_IOPFrameBufferWrPtr * NETMAN_MAX_FRAME_SIZE]; + dmat[0].size = (length + unaligned + 15) & ~15; + dmat[0].attr = 0; + dmat[1].src = (void*)&__netman_FrameBufferStatus[__netman_IOPFrameBufferWrPtr]; + dmat[1].dest = (void*)&__netman_IOPFrameBufferStatus[__netman_IOPFrameBufferWrPtr]; + dmat[1].size = sizeof(struct NetManBD); + dmat[1].attr = 0; + + while((dmat_id = SifSetDma(dmat, 2)) == 0){ }; + } -static void NETMAN_TxThread(void *arg); + //Increase write pointer by one position. + __netman_IOPFrameBufferWrPtr = (__netman_IOPFrameBufferWrPtr + 1) % NETMAN_RPC_BLOCK_SIZE; + + if((length = NetManTxPacketAfter(&payload)) > 0) + { //Write back the cache of the next packet, while waiting. + unaligned = (int)((u32)payload & 15); + unalignedCache = (int)((u32)payload & 63); + payloadAligned = (void*)((u32)payload & ~15); + payloadCacheAligned = (void*)((u32)payload & ~63); + SifWriteBackDCache(payloadCacheAligned, (length + unalignedCache + 63) & ~63); + } + + NumTx++; + + while(SifDmaStat(dmat_id) >= 0){ }; + NetManTxPacketDeQ(); + } while(length > 0); + + __netman_rpc_client_IIsProcessingTx = 0; + } + } +} int NetManInitRPCClient(void){ static const char NetManID[]="NetMan"; @@ -60,16 +210,16 @@ int NetManInitRPCClient(void){ ee_sema_t SemaData; ee_thread_t thread; - if(!IsInitialized) + if(!__netman_rpc_client_IsInitialized) { SemaData.max_count=1; SemaData.init_count=1; SemaData.option=(u32)NetManID; SemaData.attr=0; - if((NetManIOSemaID=CreateSema(&SemaData)) < 0) + if((__NetManIOSemaID=CreateSema(&SemaData)) < 0) { - deinitCleanup(); - return NetManIOSemaID; + __rpc_client_deinitCleanup(); + return __NetManIOSemaID; } thread.func=&NETMAN_TxThread; @@ -79,53 +229,55 @@ int NetManInitRPCClient(void){ thread.initial_priority=0x56; /* Should be given a higher priority than the protocol stack, so that it can dump frames in the EE and return. */ thread.attr=thread.option=0; - if((NETMAN_Tx_threadID=CreateThread(&thread)) >= 0) + if((__NETMAN_Tx_threadID=CreateThread(&thread)) >= 0) { - IsProcessingTx = 0; - StartThread(NETMAN_Tx_threadID, NULL); + __netman_rpc_client_IIsProcessingTx = 0; + StartThread(__NETMAN_Tx_threadID, NULL); } else { - deinitCleanup(); - return NETMAN_Tx_threadID; + __rpc_client_deinitCleanup(); + return __NETMAN_Tx_threadID; } - while((SifBindRpc(&NETMAN_rpc_cd, NETMAN_RPC_NUMBER, 0)<0)||(NETMAN_rpc_cd.server==NULL)) + while((SifBindRpc(&__NETMAN_rpc_cd, NETMAN_RPC_NUMBER, 0)<0)||(__NETMAN_rpc_cd.server==NULL)) nopdelay(); - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_INIT, 0, NULL, 0, &ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_INIT, 0, NULL, 0, &__rpc_client_ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) { - if((result=ReceiveBuffer.result) == 0) - IsInitialized=1; + if((result=__rpc_client_ReceiveBuffer.result) == 0) + __netman_rpc_client_IsInitialized=1; else - deinitCleanup(); + __rpc_client_deinitCleanup(); }else{ - deinitCleanup(); + __rpc_client_deinitCleanup(); } } else result=0; return result; } +#endif +#ifdef F_NetManRPCRegisterNetworkStack int NetManRPCRegisterNetworkStack(void) { int result; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - if(FrameBufferStatus == NULL) FrameBufferStatus = memalign(64, NETMAN_RPC_BLOCK_SIZE * sizeof(struct NetManBD)); + if(__netman_FrameBufferStatus == NULL) __netman_FrameBufferStatus = memalign(64, NETMAN_RPC_BLOCK_SIZE * sizeof(struct NetManBD)); - if(FrameBufferStatus != NULL) + if(__netman_FrameBufferStatus != NULL) { - memset(UNCACHED_SEG(FrameBufferStatus), 0, NETMAN_RPC_BLOCK_SIZE * sizeof(struct NetManBD)); - TransmitBuffer.NetStack.FrameBufferStatus = FrameBufferStatus; - IOPFrameBufferWrPtr = 0; + memset(UNCACHED_SEG(__netman_FrameBufferStatus), 0, NETMAN_RPC_BLOCK_SIZE * sizeof(struct NetManBD)); + __rpc_client_TransmitBuffer.NetStack.FrameBufferStatus = __netman_FrameBufferStatus; + __netman_IOPFrameBufferWrPtr = 0; - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_REG_NETWORK_STACK, 0, &TransmitBuffer, sizeof(struct NetManRegNetworkStack), &ReceiveBuffer, sizeof(struct NetManRegNetworkStackResult), NULL, NULL))>=0) + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_REG_NETWORK_STACK, 0, &__rpc_client_TransmitBuffer, sizeof(struct NetManRegNetworkStack), &__rpc_client_ReceiveBuffer, sizeof(struct NetManRegNetworkStackResult), NULL, NULL))>=0) { - if((result=ReceiveBuffer.NetStackResult.result) == 0) + if((result=__rpc_client_ReceiveBuffer.NetStackResult.result) == 0) { - IOPFrameBuffer = ReceiveBuffer.NetStackResult.FrameBuffer; - IOPFrameBufferStatus = ReceiveBuffer.NetStackResult.FrameBufferStatus; + __netman_IOPFrameBuffer = __rpc_client_ReceiveBuffer.NetStackResult.FrameBuffer; + __netman_IOPFrameBufferStatus = __rpc_client_ReceiveBuffer.NetStackResult.FrameBufferStatus; } } } @@ -134,48 +286,54 @@ int NetManRPCRegisterNetworkStack(void) result = -ENOMEM; } - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif +#ifdef F_NetManRPCUnregisterNetworkStack int NetManRPCUnregisterNetworkStack(void) { int result; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_UNREG_NETWORK_STACK, 0, NULL, 0, NULL, 0, NULL, NULL); - IOPFrameBuffer = NULL; - IOPFrameBufferWrPtr = 0; + result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_UNREG_NETWORK_STACK, 0, NULL, 0, NULL, 0, NULL, NULL); + __netman_IOPFrameBuffer = NULL; + __netman_IOPFrameBufferWrPtr = 0; - free(FrameBufferStatus); - FrameBufferStatus = NULL; + free(__netman_FrameBufferStatus); + __netman_FrameBufferStatus = NULL; - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif +#ifdef F_NetManDeinitRPCClient void NetManDeinitRPCClient(void) { - if(IsInitialized) + if(__netman_rpc_client_IsInitialized) { - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_DEINIT, 0, NULL, 0, NULL, 0, NULL, NULL); - deinitCleanup(); + SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_DEINIT, 0, NULL, 0, NULL, 0, NULL, NULL); + __rpc_client_deinitCleanup(); - IsInitialized=0; + __netman_rpc_client_IsInitialized=0; } } +#endif +#ifdef F_NetManRpcIoctl int NetManRpcIoctl(unsigned int command, void *args, unsigned int args_len, void *output, unsigned int length) { int result; - struct NetManIoctl *IoctlArgs=&TransmitBuffer.IoctlArgs; + struct NetManIoctl *IoctlArgs=&__rpc_client_TransmitBuffer.IoctlArgs; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); IoctlArgs->command=command; memcpy(IoctlArgs->args, args, args_len); @@ -183,169 +341,88 @@ int NetManRpcIoctl(unsigned int command, void *args, unsigned int args_len, void IoctlArgs->output=output; IoctlArgs->length=length; - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_IOCTL, 0, &TransmitBuffer, sizeof(struct NetManIoctl), &ReceiveBuffer, sizeof(struct NetManIoctlResult), NULL, NULL))>=0) + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_IOCTL, 0, &__rpc_client_TransmitBuffer, sizeof(struct NetManIoctl), &__rpc_client_ReceiveBuffer, sizeof(struct NetManIoctlResult), NULL, NULL))>=0) { - result=ReceiveBuffer.IoctlResult.result; - memcpy(output, ReceiveBuffer.IoctlResult.output, length); + result=__rpc_client_ReceiveBuffer.IoctlResult.result; + memcpy(output, __rpc_client_ReceiveBuffer.IoctlResult.output, length); } - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif -static void NETMAN_TxThread(void *arg) -{ - static SifCmdHeader_t cmd ALIGNED(64); - SifDmaTransfer_t dmat[2]; - struct NetManPktCmd *npcmd; - int dmat_id, unaligned, unalignedCache; - void *payload, *payloadAligned, *payloadCacheAligned; - volatile struct NetManBD *bd, *bdNext; - - (void)arg; - - while(1) - { - int length, NumTx; - SleepThread(); - - NumTx = 0; - while((length = NetManTxPacketNext(&payload)) > 0) - { - IsProcessingTx = 1; - - //Write back D-cache, before performing a DMA transfer. - unaligned = (int)((u32)payload & 15); - unalignedCache = (int)((u32)payload & 63); - payloadAligned = (void*)((u32)payload & ~15); - payloadCacheAligned = (void*)((u32)payload & ~63); - SifWriteBackDCache(payloadCacheAligned, (length + unalignedCache + 63) & ~63); - - do { - //Wait for a spot to be freed up. - bd = UNCACHED_SEG(&FrameBufferStatus[IOPFrameBufferWrPtr]); - while(bd->length != 0){} - - //Transfer to IOP RAM - //Determine mode of transfer. - bdNext = UNCACHED_SEG(&FrameBufferStatus[(IOPFrameBufferWrPtr + 1) % NETMAN_RPC_BLOCK_SIZE]); - if((NumTx + 1) >= NETMAN_FRAME_GROUP_SIZE || bdNext->length == 0) - { - //Prepare SIFCMD packet - //Record the frame length. - npcmd = (struct NetManPktCmd*)&cmd.opt; - npcmd->length = length; - npcmd->offset = unaligned; - npcmd->id = IOPFrameBufferWrPtr; - - while((dmat_id = SifSendCmd(NETMAN_SIFCMD_ID, &cmd, sizeof(SifCmdHeader_t), - (void*)payloadAligned, - (void*)&IOPFrameBuffer[IOPFrameBufferWrPtr * NETMAN_MAX_FRAME_SIZE], - (length + unaligned + 15) & ~15)) == 0){ }; - } else { - //Record the frame length. - bd->length = length; - bd->offset = unaligned; - - //Normal DMA transfer - dmat[0].src = (void*)payloadAligned; - dmat[0].dest = (void*)&IOPFrameBuffer[IOPFrameBufferWrPtr * NETMAN_MAX_FRAME_SIZE]; - dmat[0].size = (length + unaligned + 15) & ~15; - dmat[0].attr = 0; - dmat[1].src = (void*)&FrameBufferStatus[IOPFrameBufferWrPtr]; - dmat[1].dest = (void*)&IOPFrameBufferStatus[IOPFrameBufferWrPtr]; - dmat[1].size = sizeof(struct NetManBD); - dmat[1].attr = 0; - - while((dmat_id = SifSetDma(dmat, 2)) == 0){ }; - } - - //Increase write pointer by one position. - IOPFrameBufferWrPtr = (IOPFrameBufferWrPtr + 1) % NETMAN_RPC_BLOCK_SIZE; - - if((length = NetManTxPacketAfter(&payload)) > 0) - { //Write back the cache of the next packet, while waiting. - unaligned = (int)((u32)payload & 15); - unalignedCache = (int)((u32)payload & 63); - payloadAligned = (void*)((u32)payload & ~15); - payloadCacheAligned = (void*)((u32)payload & ~63); - SifWriteBackDCache(payloadCacheAligned, (length + unalignedCache + 63) & ~63); - } - - NumTx++; - - while(SifDmaStat(dmat_id) >= 0){ }; - NetManTxPacketDeQ(); - } while(length > 0); - - IsProcessingTx = 0; - } - } -} - +#ifdef F_NetManRpcNetIFXmit void NetManRpcNetIFXmit(void) { - if(!IsProcessingTx) - WakeupThread(NETMAN_Tx_threadID); + if(!__netman_rpc_client_IIsProcessingTx) + WakeupThread(__NETMAN_Tx_threadID); } +#endif +#ifdef F_NetManSetMainIF int NetManSetMainIF(const char *name) { int result; - if (!IsInitialized) + if (!__netman_rpc_client_IsInitialized) return -1; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - strncpy(TransmitBuffer.netifName, name, NETMAN_NETIF_NAME_MAX_LEN); - TransmitBuffer.netifName[NETMAN_NETIF_NAME_MAX_LEN-1] = '\0'; - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SET_MAIN_NETIF, 0, &TransmitBuffer, NETMAN_NETIF_NAME_MAX_LEN, &ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) - result=ReceiveBuffer.result; + strncpy(__rpc_client_TransmitBuffer.netifName, name, NETMAN_NETIF_NAME_MAX_LEN); + __rpc_client_TransmitBuffer.netifName[NETMAN_NETIF_NAME_MAX_LEN-1] = '\0'; + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SET_MAIN_NETIF, 0, &__rpc_client_TransmitBuffer, NETMAN_NETIF_NAME_MAX_LEN, &__rpc_client_ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) + result=__rpc_client_ReceiveBuffer.result; - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif +#ifdef F_NetManQueryMainIF int NetManQueryMainIF(char *name) { int result; - if (!IsInitialized) + if (!__netman_rpc_client_IsInitialized) return -1; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_QUERY_MAIN_NETIF, 0, NULL, 0, &ReceiveBuffer, sizeof(struct NetManQueryMainNetIFResult), NULL, NULL))>=0) + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_QUERY_MAIN_NETIF, 0, NULL, 0, &__rpc_client_ReceiveBuffer, sizeof(struct NetManQueryMainNetIFResult), NULL, NULL))>=0) { - if((result=ReceiveBuffer.QueryMainNetIFResult.result) == 0) + if((result=__rpc_client_ReceiveBuffer.QueryMainNetIFResult.result) == 0) { - strncpy(name, ReceiveBuffer.QueryMainNetIFResult.name, NETMAN_NETIF_NAME_MAX_LEN); + strncpy(name, __rpc_client_ReceiveBuffer.QueryMainNetIFResult.name, NETMAN_NETIF_NAME_MAX_LEN); name[NETMAN_NETIF_NAME_MAX_LEN-1] = '\0'; } } - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif +#ifdef F_NetManSetLinkMode int NetManSetLinkMode(int mode) { int result; - if (!IsInitialized) + if (!__netman_rpc_client_IsInitialized) return -1; - WaitSema(NetManIOSemaID); + WaitSema(__NetManIOSemaID); - TransmitBuffer.mode = mode; - if((result=SifCallRpc(&NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SET_LINK_MODE, 0, &TransmitBuffer, sizeof(s32), &ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) - result=ReceiveBuffer.result; + __rpc_client_TransmitBuffer.mode = mode; + if((result=SifCallRpc(&__NETMAN_rpc_cd, NETMAN_IOP_RPC_FUNC_SET_LINK_MODE, 0, &__rpc_client_TransmitBuffer, sizeof(s32), &__rpc_client_ReceiveBuffer, sizeof(s32), NULL, NULL))>=0) + result=__rpc_client_ReceiveBuffer.result; - SignalSema(NetManIOSemaID); + SignalSema(__NetManIOSemaID); return result; } +#endif diff --git a/ee/network/netman/src/rpc_server.c b/ee/network/netman/src/rpc_server.c index 9bb8a13d669..7a95ed42684 100644 --- a/ee/network/netman/src/rpc_server.c +++ b/ee/network/netman/src/rpc_server.c @@ -11,79 +11,136 @@ #include "internal.h" #include "rpc_server.h" -static int NETMAN_RpcSvr_threadID=-1, NETMAN_Rx_threadID=-1, SifHandlerID=-1; -static unsigned char NETMAN_RpcSvr_ThreadStack[0x1000] ALIGNED(16); -static unsigned char NETMAN_Rx_ThreadStack[0x1000] ALIGNED(16); -static unsigned char IsInitialized=0, IsProcessingRx; +#ifdef F___NETMAN_RpcSvr_threadID +int __NETMAN_RpcSvr_threadID=-1; +#else +extern int __NETMAN_RpcSvr_threadID; +#endif + +#ifdef F___NETMAN_Rx_threadID +int __NETMAN_Rx_threadID=-1; +#else +extern int __NETMAN_Rx_threadID; +#endif + +#ifdef F___NETMAN_SifHandlerID +int __NETMAN_SifHandlerID=-1; +#else +extern int __NETMAN_SifHandlerID; +#endif + +#ifdef F___rpc_server_IsInitialized +unsigned char __rpc_server_IsInitialized=0; +#else +extern unsigned char __rpc_server_IsInitialized; +#endif + +#ifdef F___rpc_server_IsProcessingRx +unsigned char __rpc_server_IsProcessingRx; +#else +extern unsigned char __rpc_server_IsProcessingRx; +#endif + +#ifdef F___rpc_server_FrameBufferStatus +struct NetManBD *__rpc_server_FrameBufferStatus = NULL; +#else +extern struct NetManBD *__rpc_server_FrameBufferStatus; +#endif + +#ifdef F___rpc_server_RxIOPFrameBufferStatus +struct NetManBD *__rpc_server_RxIOPFrameBufferStatus; +#else +extern struct NetManBD *__rpc_server_RxIOPFrameBufferStatus; +#endif + +#ifdef F___rpc_server_cb_queue +struct t_SifRpcDataQueue __rpc_server_cb_queue; +#else +extern struct t_SifRpcDataQueue __rpc_server_cb_queue; +#endif + +#ifdef F___rpc_server_cb_srv +struct t_SifRpcServerData __rpc_server_cb_srv; +#else +extern struct t_SifRpcServerData __rpc_server_cb_srv; +#endif -static struct NetManBD *FrameBufferStatus = NULL; -static struct NetManBD *RxIOPFrameBufferStatus; -static unsigned short int RxBufferRdPtr, RxBufferNextRdPtr; extern void *_gp; -static void NETMAN_RxThread(void *arg); - -static void ClearBufferLen(int index, void *packet, void *payload) +#ifdef F___rpc_server_ClearBufferLen +void __rpc_server_ClearBufferLen(int index, void *packet, void *payload) { struct NetManBD *bd; SifDmaTransfer_t dmat; - bd = UNCACHED_SEG(&FrameBufferStatus[index]); + bd = UNCACHED_SEG(&__rpc_server_FrameBufferStatus[index]); bd->length = 0; bd->packet = packet; bd->payload = payload; //Transfer to IOP RAM - dmat.src = (void*)&FrameBufferStatus[index]; - dmat.dest = &RxIOPFrameBufferStatus[index]; + dmat.src = (void*)&__rpc_server_FrameBufferStatus[index]; + dmat.dest = &__rpc_server_RxIOPFrameBufferStatus[index]; dmat.size = sizeof(struct NetManBD); dmat.attr = 0; while(SifSetDma(&dmat, 1) == 0){ }; } +#else +extern void __rpc_server_ClearBufferLen(int index, void *packet, void *payload); +#endif -static s32 HandleRxEvent(s32 channel) +#ifdef F__NetManRPCAllocRxBuffers +int _NetManRPCAllocRxBuffers(void) { - struct NetManBD *bd; - - (void)channel; + int i; - bd = UNCACHED_SEG(&FrameBufferStatus[RxBufferNextRdPtr]); - if(bd->length > 0) + for(i = 0; i < NETMAN_RPC_BLOCK_SIZE; i++) { - iSifSetDChain(); + void *packet, *payload; - if(!IsProcessingRx) + if((packet = NetManNetProtStackAllocRxPacket(NETMAN_NETIF_FRAME_SIZE, &payload)) != NULL) { - IsProcessingRx = 1; - iWakeupThread(NETMAN_Rx_threadID); + __rpc_server_ClearBufferLen(i, packet, payload); + } else { + printf("NETMAN: error - unable to allocate Rx FIFO buffers.\n"); + return -ENOMEM; } } - ExitHandler(); - //Must allow the other SIF handlers to check their states, as it is possible for this handler to block other handlers until FrameBufferStatus is cleared. return 0; } +#endif + +#ifdef F__NetManInitRPCServer +static unsigned char NETMAN_RpcSvr_ThreadStack[0x1000] ALIGNED(16); +static unsigned char NETMAN_Rx_ThreadStack[0x1000] ALIGNED(16); +static unsigned short int RxBufferRdPtr, RxBufferNextRdPtr; -int NetManRPCAllocRxBuffers(void) +static s32 HandleRxEvent(s32 channel) { - int i; + struct NetManBD *bd; - for(i = 0; i < NETMAN_RPC_BLOCK_SIZE; i++) + (void)channel; + + bd = UNCACHED_SEG(&__rpc_server_FrameBufferStatus[RxBufferNextRdPtr]); + if(bd->length > 0) { - void *packet, *payload; + iSifSetDChain(); - if((packet = NetManNetProtStackAllocRxPacket(NETMAN_NETIF_FRAME_SIZE, &payload)) != NULL) + if(!__rpc_server_IsProcessingRx) { - ClearBufferLen(i, packet, payload); - } else { - printf("NETMAN: error - unable to allocate Rx FIFO buffers.\n"); - return -ENOMEM; + __rpc_server_IsProcessingRx = 1; + iWakeupThread(__NETMAN_Rx_threadID); } } + ExitHandler(); + //Must allow the other SIF handlers to check their states, as it is possible for this handler to block other handlers until __rpc_server_FrameBufferStatus is cleared. return 0; } +static void NETMAN_RxThread(void *arg); + /* Main EE RPC thread. */ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) { @@ -95,17 +152,17 @@ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) switch(fnum) { case NETMAN_EE_RPC_FUNC_INIT: - RxIOPFrameBufferStatus = *(void**)buffer; + __rpc_server_RxIOPFrameBufferStatus = *(void**)buffer; //Maintain 64-byte alignment to avoid non-uncached writes to the same cache line from contaminating the line. - if(FrameBufferStatus == NULL) FrameBufferStatus = memalign(64, sizeof(struct NetManBD) * NETMAN_RPC_BLOCK_SIZE); + if(__rpc_server_FrameBufferStatus == NULL) __rpc_server_FrameBufferStatus = memalign(64, sizeof(struct NetManBD) * NETMAN_RPC_BLOCK_SIZE); - if(FrameBufferStatus != NULL) + if(__rpc_server_FrameBufferStatus != NULL) { - memset(UNCACHED_SEG(FrameBufferStatus), 0, sizeof(struct NetManBD) * NETMAN_RPC_BLOCK_SIZE); + memset(UNCACHED_SEG(__rpc_server_FrameBufferStatus), 0, sizeof(struct NetManBD) * NETMAN_RPC_BLOCK_SIZE); RxBufferRdPtr = 0; RxBufferNextRdPtr = 0; - IsProcessingRx = 0; + __rpc_server_IsProcessingRx = 0; thread.func=&NETMAN_RxThread; thread.stack=NETMAN_Rx_ThreadStack; @@ -114,17 +171,17 @@ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) thread.initial_priority=0x59; /* Should be given a lower priority than the protocol stack, so that the protocol stack can process incoming frames. */ thread.attr=thread.option=0; - if((NETMAN_Rx_threadID=CreateThread(&thread)) >= 0) + if((__NETMAN_Rx_threadID=CreateThread(&thread)) >= 0) { - StartThread(NETMAN_Rx_threadID, NULL); + StartThread(__NETMAN_Rx_threadID, NULL); - SifHandlerID = AddDmacHandler(DMAC_SIF0, &HandleRxEvent, 0); + __NETMAN_SifHandlerID = AddDmacHandler(DMAC_SIF0, &HandleRxEvent, 0); EnableDmac(DMAC_SIF0); ((struct NetManEEInitResult *)buffer)->result = 0; - ((struct NetManEEInitResult *)buffer)->FrameBufferStatus = FrameBufferStatus; + ((struct NetManEEInitResult *)buffer)->FrameBufferStatus = __rpc_server_FrameBufferStatus; } else{ - ((struct NetManEEInitResult *)buffer)->result = NETMAN_Rx_threadID; + ((struct NetManEEInitResult *)buffer)->result = __NETMAN_Rx_threadID; } }else{ ((struct NetManEEInitResult *)buffer)->result = -ENOMEM; @@ -132,10 +189,10 @@ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) result=buffer; break; case NETMAN_EE_RPC_FUNC_DEINIT: - if(FrameBufferStatus != NULL) + if(__rpc_server_FrameBufferStatus != NULL) { - free(FrameBufferStatus); - FrameBufferStatus = NULL; + free(__rpc_server_FrameBufferStatus); + __rpc_server_FrameBufferStatus = NULL; } result=NULL; break; @@ -152,18 +209,15 @@ static void *NETMAN_EE_RPC_Handler(int fnum, void *buffer, int NumBytes) return result; } -static struct t_SifRpcDataQueue cb_queue; -static struct t_SifRpcServerData cb_srv; - static void NETMAN_RPC_Thread(void *arg) { static unsigned char cb_rpc_buffer[64] __attribute__((__aligned__(64))); (void)arg; - SifSetRpcQueue(&cb_queue, NETMAN_RpcSvr_threadID); - SifRegisterRpc(&cb_srv, NETMAN_RPC_NUMBER, &NETMAN_EE_RPC_Handler, cb_rpc_buffer, NULL, NULL, &cb_queue); - SifRpcLoop(&cb_queue); + SifSetRpcQueue(&__rpc_server_cb_queue, __NETMAN_RpcSvr_threadID); + SifRegisterRpc(&__rpc_server_cb_srv, NETMAN_RPC_NUMBER, &NETMAN_EE_RPC_Handler, cb_rpc_buffer, NULL, NULL, &__rpc_server_cb_queue); + SifRpcLoop(&__rpc_server_cb_queue); } static void NETMAN_RxThread(void *arg) @@ -179,7 +233,7 @@ static void NETMAN_RxThread(void *arg) void *payload, *payloadNext; void *packet, *packetNext; - bd = UNCACHED_SEG(&FrameBufferStatus[RxBufferRdPtr]); + bd = UNCACHED_SEG(&__rpc_server_FrameBufferStatus[RxBufferRdPtr]); do { DI(); @@ -189,7 +243,7 @@ static void NETMAN_RxThread(void *arg) run = 1; } else { run = 0; - IsProcessingRx = 0; + __rpc_server_IsProcessingRx = 0; } EI(); @@ -203,7 +257,7 @@ static void NETMAN_RxThread(void *arg) //Must successfully allocate a replacement buffer for the input buffer. while((packetNext = NetManNetProtStackAllocRxPacket(NETMAN_NETIF_FRAME_SIZE, &payloadNext)) == NULL){}; RxBufferNextRdPtr = (RxBufferNextRdPtr + 1) % NETMAN_RPC_BLOCK_SIZE; - ClearBufferLen(RxBufferRdPtr, packetNext, payloadNext); + __rpc_server_ClearBufferLen(RxBufferRdPtr, packetNext, payloadNext); //Increment read pointer by one place. RxBufferRdPtr = RxBufferNextRdPtr; @@ -216,12 +270,12 @@ static void NETMAN_RxThread(void *arg) } } -int NetManInitRPCServer(void) +int _NetManInitRPCServer(void) { int result; ee_thread_t ThreadData; - if(!IsInitialized) + if(!__rpc_server_IsInitialized) { ThreadData.func=&NETMAN_RPC_Thread; ThreadData.stack=NETMAN_RpcSvr_ThreadStack; @@ -230,41 +284,44 @@ int NetManInitRPCServer(void) ThreadData.initial_priority=0x57; /* The RPC server thread should be given a higher priority than the protocol stack, so that it can issue commants to the EE and return. */ ThreadData.attr=ThreadData.option=0; - if((NETMAN_RpcSvr_threadID=CreateThread(&ThreadData))>=0) + if((__NETMAN_RpcSvr_threadID=CreateThread(&ThreadData))>=0) { - StartThread(NETMAN_RpcSvr_threadID, NULL); - IsInitialized=1; + StartThread(__NETMAN_RpcSvr_threadID, NULL); + __rpc_server_IsInitialized=1; result=0; } - else result=NETMAN_RpcSvr_threadID; + else result=__NETMAN_RpcSvr_threadID; } else result=0; return result; } +#endif -void NetManDeinitRPCServer(void) +#ifdef F__NetManDeinitRPCServer +void _NetManDeinitRPCServer(void) { - if(IsInitialized) + if(__rpc_server_IsInitialized) { - SifRemoveRpc(&cb_srv, &cb_queue); - SifRemoveRpcQueue(&cb_queue); - RemoveDmacHandler(DMAC_SIF0, SifHandlerID); + SifRemoveRpc(&__rpc_server_cb_srv, &__rpc_server_cb_queue); + SifRemoveRpcQueue(&__rpc_server_cb_queue); + RemoveDmacHandler(DMAC_SIF0, __NETMAN_SifHandlerID); - if(NETMAN_RpcSvr_threadID>=0) + if(__NETMAN_RpcSvr_threadID>=0) { - TerminateThread(NETMAN_RpcSvr_threadID); - DeleteThread(NETMAN_RpcSvr_threadID); - NETMAN_RpcSvr_threadID = -1; + TerminateThread(__NETMAN_RpcSvr_threadID); + DeleteThread(__NETMAN_RpcSvr_threadID); + __NETMAN_RpcSvr_threadID = -1; } - if(NETMAN_Rx_threadID>=0) + if(__NETMAN_Rx_threadID>=0) { - TerminateThread(NETMAN_Rx_threadID); - DeleteThread(NETMAN_Rx_threadID); - NETMAN_Rx_threadID = -1; + TerminateThread(__NETMAN_Rx_threadID); + DeleteThread(__NETMAN_Rx_threadID); + __NETMAN_Rx_threadID = -1; } - IsInitialized=0; + __rpc_server_IsInitialized=0; } } +#endif