1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     nwmeth.h
4   Copyright (C)2009 Nintendo Co., Ltd.  All rights reserved.
5   These coded instructions, statements, and computer programs contain
6   proprietary information of Nintendo of America Inc. and/or Nintendo
7   Company Ltd., and are protected by Federal copyright law. They may
8   not be disclosed to third parties or copied or duplicated in any form,
9   in whole or in part, without the prior written consent of Nintendo.
10   $Rev: 21218 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 
17 #ifndef NN_NETWORK_NWMETH_H
18 #define NN_NETWORK_NWMETH_H
19 
20 #include <nnet.h>
21 #include <nnet/nnet_ext.h>
22 
23 #ifdef  __cplusplus
24 extern "C" {
25 #endif
26 
27 /*---------------------------------------------------------------------------*
28  * Definitions
29  *---------------------------------------------------------------------------*/
30 #define NWMETH_DEVICE_1               0           /* Only 1 interface can be used with this driver */
31 
32 #define NWMETH_USE_MBUF               1
33 
34 #define NWMETH_VENDOR_NINTENDO        0x0000
35 #define NWMETH_COMMON_CONF_VERSION    0x1100
36 #define NWMETH_INS_CONF_VERSION       0x2100
37 
38 /* Please see man pages for details
39 
40  */
41 #define NWMETH_ERROR_BASE                          0xffff9000
42 #define NWMETH_ERROR_CODE(code)                    ((s32)(NWMETH_ERROR_BASE | (code)))
43 enum
44 {
45     NWMETH_ERR_PARAM = NWMETH_ERROR_CODE(1),            /* Parameter error */
46     NWMETH_ERR_INIT = NWMETH_ERROR_CODE(2),             /* Cannot run because it is in initialized state */
47     NWMETH_ERR_FINISH = NWMETH_ERROR_CODE(3),           /* Cannot run because it is in terminated state */
48     NWMETH_ERR_CONFVER = NWMETH_ERROR_CODE(4),          /* Setting version error */
49     NWMETH_ERR_STATE = NWMETH_ERROR_CODE(5),            /* State error */
50     NWMETH_ERR_EXIST = NWMETH_ERROR_CODE(6),            /* Already created */
51     NWMETH_ERR_NOMEM = NWMETH_ERROR_CODE(7),            /* Insufficient memory */
52     NWMETH_ERR_TIMEOUT = NWMETH_ERROR_CODE(8),          /* timeout */
53     NWMETH_ERR_IO = NWMETH_ERROR_CODE(9),
54     NWMETH_ERR_NONE = 0                                 /* Normal end */
55 };
56 
57 /* Please see man pages for details
58 
59  */
60 #define NWMETH_MEM_BASE                            0x00050000
61 #define NWMETH_MEM_NAME(name)                    ((s32)(NWMETH_MEM_BASE | (name)))
62 enum
63 {
64     NWMETH_MEM_INSTANCE = NWMETH_MEM_NAME(1)
65 };
66 
67 /* Please see man pages for details
68 
69  */
70 enum
71 {
72     NWMETH_STATE_INIT = 0,        /* Initial state */
73     NWMETH_STATE_ACTIVE,          /* Connection completed state */
74     NWMETH_STATE_DESTROY,
75     NWMETH_STATE_ABORT            /* Connection completed state */
76 };
77 
78 /*---------------------------------------------------------------------------*
79  * Types/Declarations
80  *---------------------------------------------------------------------------*/
81 
82 /* Please see man pages for details
83 
84  */
85 #define NWMETH_UPPER_NUM            2                       /* Number of upper layers   */
86 #define NWMETH_RXFRAME_BUFFUR_COUNT 16                      /* Size of queue to pass to upper layers */
87 #define NWMETH_STACK_SIZE           4096
88 
89 #define NWMETH_PROTOCOL_ENTRY_MAX   16
90 
91 typedef struct NWMETHQueuePair
92 {
93     NOSMessageQueue mq;                                     /* Receive queue for upper layers */
94     NOSMessage      msg[NWMETH_RXFRAME_BUFFUR_COUNT];       /* Receive queue instance for upper layers */
95 } NWMETHQueuePair;
96 
97 typedef struct NWMETHInstance
98 {
99     NNETInstance        netIns;                             /* Instance information common to all layers */
100     NNETProtocolList    protocolList;
101 
102     NWMETHQueuePair     upper_mq[NWMETH_UPPER_NUM];          /* Receive queue for upper layers */
103     s32 upper_ins_count;
104 
105     s32 state;
106 
107     u8  macaddr[NNET_ETH_ALEN];                             /* Local MAC address */
108     u16 pad;
109 
110     u8  sendBuf[NNET_MAX_SEND_LEN];                         /* Send buffer */
111     u8  recvBuf[NNET_MAX_RECV_LEN];
112     NOSThread   thread;
113     NOSThreadId threadId;
114     u8 stack[NWMETH_STACK_SIZE];
115 
116 } NWMETHInstance;
117 
118 /*
119     Get NNETInstance from WCM instance
120 */
NWMETH_GetNNETInstance(NWMETHInstance * pNwmIns)121 static inline NNETInstance* NWMETH_GetNNETInstance(NWMETHInstance* pNwmIns)
122 {
123     return &pNwmIns->netIns;
124 }
125 
126 /*
127     Get WCM instance from NNETInstance
128 */
NWMETH_GetNWMETHInstance(NNETInstance * pNetIns)129 static inline NWMETHInstance* NWMETH_GetNWMETHInstance(NNETInstance* pNetIns)
130 {
131     return (NWMETHInstance*)pNetIns;
132 }
133 
134 /*---------------------------------------------------------------------------*
135  * Function Prototypes
136  *---------------------------------------------------------------------------*/
137 /* nwmeth_Main.cpp */
138 void* NWMETHi_Alloc(u32 name, u32 size, u32 align);
139 void  NWMETHi_Free(u32 name, void* ptr);
140 
141 s32 NWMETH_Init(const NNETAllocator* allocator);
142 s32 NWMETH_Finish(void);
143 s32 NWMETH_GetMacAddr(NNETInstance* ins, u8* macaddr);
144 
145 void NWMETHi_HandleFrame(NWMETHInstance* pNwmIns, NOSMessageBuf* mbuf);
146 void NWMETHi_HandleFrameRaw(NWMETHInstance* pNwmIns, const u8* pFrame, int len);
147 
148 /* nwmeth_Direct.cpp */
149 s32 NWMETH_CreateInsDirect(NWMETHInstance** pNwmEth);
150 s32 NWMETH_DestroyInsDirect(NWMETHInstance* pNwmEth);
151 s32 NWMETH_GetUpperDirectAPI(NNETEthernetAPI* pEtherAPI, NWMETHInstance* pNwmEth);
152 
153 /* nwmeth_Ipc.cpp */
154 s32 NWMETH_CreateIns(NWMETHInstance** pNwmEth);
155 s32 NWMETH_DestroyIns(NWMETHInstance* pNwmEth);
156 s32 NWMETH_GetUpperAPI(NNETEthernetAPI* pEtherAPI, NWMETHInstance* pNwmEth);
157 
158 
159 #ifdef  __cplusplus
160 }
161 #endif
162 
163 /* NN_NETWORK_NWMETH_H */
164 #endif
165