1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     hioeth.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: 12449 $
11  *---------------------------------------------------------------------------
12 
13 
14 */
15 
16 
17 #ifndef NN_NETWORK_HIOETH_H
18 #define NN_NETWORK_HIOETH_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 HIOETH_DEVICE_1               0           /* Only 1 interface can be used with this driver */
31 
32 #define HIOETH_VENDOR_NINTENDO        0x0000
33 #define HIOETH_COMMON_CONF_VERSION    0x1100
34 #define HIOETH_INS_CONF_VERSION       0x2100
35 
36 /* Please see man pages for details
37 
38  */
39 #define HIOETH_ERROR_BASE                          0xffff9000
40 #define HIOETH_ERROR_CODE(code)                    ((s32)(HIOETH_ERROR_BASE | (code)))
41 enum
42 {
43     HIOETH_ERR_PARAM = HIOETH_ERROR_CODE(1),            /* Parameter error */
44     HIOETH_ERR_INIT = HIOETH_ERROR_CODE(2),             /* Cannot run because it is in initialized state */
45     HIOETH_ERR_FINISH = HIOETH_ERROR_CODE(3),           /* Cannot run because it is in terminated state */
46     HIOETH_ERR_CONFVER = HIOETH_ERROR_CODE(4),          /* Setting version error */
47     HIOETH_ERR_STATE = HIOETH_ERROR_CODE(5),            /* State error */
48     HIOETH_ERR_EXIST = HIOETH_ERROR_CODE(6),            /* Already created */
49     HIOETH_ERR_NOMEM = HIOETH_ERROR_CODE(7),            /* Insufficient memory */
50     HIOETH_ERR_TIMEOUT = HIOETH_ERROR_CODE(8),          /* timeout */
51     HIOETH_ERR_IO = HIOETH_ERROR_CODE(8),
52     HIOETH_ERR_NONE = 0                                 /* Normal end */
53 };
54 
55 /* Please see man pages for details
56 
57  */
58 #define HIOETH_MEM_BASE                            0x00050000
59 #define HIOETH_MEM_NAME(name)                    ((s32)(HIOETH_MEM_BASE | (name)))
60 enum
61 {
62     HIOETH_MEM_INSTANCE = HIOETH_MEM_NAME(1)
63 };
64 
65 /* Please see man pages for details
66 
67  */
68 enum
69 {
70     HIOETH_STATE_INIT = 0,        /* Initial state */
71     HIOETH_STATE_ACTIVE,          /* Connection completed state */
72     HIOETH_STATE_DESTROY,
73     HIOETH_STATE_ABORT            /* Connection completed state */
74 };
75 
76 /*---------------------------------------------------------------------------*
77  * Types/Declarations
78  *---------------------------------------------------------------------------*/
79 
80 /* Please see man pages for details
81 
82  */
83 #define HIOETH_UPPER_NUM      2                             /* Number of upper layers   */
84 #define HIOETH_MQ_NUM         16                            /* Size of queue to pass to upper layers */
85 #define HIOETH_MAX_SEND_LEN   1600
86 #define HIOETH_MAX_RECV_LEN   1600
87 #define HIOETH_STACK_SIZE     4096
88 
89 typedef struct HIOETHQueuePair
90 {
91     NOSMessageQueue mq;                                     /* Receive queue for upper layers */
92     NOSMessage      msg[HIOETH_MQ_NUM];                     /* Receive queue instance for upper layers */
93 } HIOETHQueuePair;
94 
95 typedef struct HIOETHInstance
96 {
97     NNETInstance        netIns;                             /* Instance information common to all layers */
98     NNETProtocolList    protocolList;
99 
100     HIOETHQueuePair     upper_mq[HIOETH_UPPER_NUM];          /* Receive queue for upper layers */
101     s32 upper_ins_count;
102 
103     s32 state;
104     s32 handleHostToTarget;
105     s32 handleTargetToHost;
106 
107     u8  macaddr[NNET_ETH_ALEN];                             /* Local MAC address */
108     u16 pad;
109 
110     u8  sendBuf[HIOETH_MAX_SEND_LEN];                       /* Send buffer */
111     u8  recvBuf[HIOETH_MAX_RECV_LEN];
112     u32 recvBufPos;
113     NOSThread   thread;
114     NOSThreadId threadId;
115     u8 stack[HIOETH_STACK_SIZE];
116 
117 } HIOETHInstance;
118 
119 /*
120     Get NNETInstance from WCM instance
121 */
HIOETH_GetNNETInstance(HIOETHInstance * pHioIns)122 static inline NNETInstance* HIOETH_GetNNETInstance(HIOETHInstance* pHioIns)
123 {
124     return &pHioIns->netIns;
125 }
126 
127 /*
128     Get WCM instance from NNETInstance
129 */
HIOETH_GetHIOETHInstance(NNETInstance * pNetIns)130 static inline HIOETHInstance* HIOETH_GetHIOETHInstance(NNETInstance* pNetIns)
131 {
132     return (HIOETHInstance*)pNetIns;
133 }
134 
135 /*---------------------------------------------------------------------------*
136  * Function Prototypes
137  *---------------------------------------------------------------------------*/
138 /* HIOETH_main.c */
139 extern s32 HIOETH_Init(const NNETAllocator* allocator);
140 extern s32 HIOETH_Finish(void);
141 extern s32 HIOETH_StartupIns(NNETInstance* ins, s32 timeout);
142 extern s32 HIOETH_CleanupIns(NNETInstance* ins, s32 timeout);
143 extern s32 HIOETH_AbortIns(NNETInstance* ins);
144 extern s32 HIOETH_CreateIns(HIOETHInstance** peth_ins);
145 extern s32 HIOETH_DestroyIns(HIOETHInstance* peth_ins);
146 extern s32 HIOETH_GetStateIns(HIOETHInstance* peth_ins);
147 extern s32 HIOETH_GetUpperAPI(NNETEthernetAPI* wcm_api, HIOETHInstance* peth_ins);
148 extern s32 HIOETH_SetUpper(NNETInstance * ins, NNETInstance * upper_ins, u32* receive_id, u16 entry[]);
149 extern s32 HIOETH_ClearUpper(NNETInstance* ins, NNETInstance* upper_ins);
150 extern s32 HIOETH_GetMacAddr(NNETInstance* ins, u8* macaddr);
151 extern s32 HIOETH_SetMulticastAddr(NNETInstance* ins, u8* macaddr);
152 extern s32 HIOETH_ClearMulticastAddr(NNETInstance* ins, u8* macaddr);
153 extern s32 HIOETH_Send(NNETInstance* ins, u8* dstMAC, NOSMessageBuf* mbuf);
154 extern s32 HIOETH_Receive(NNETInstance* ins, u32 receive_id, NOSMessageBuf** mbuf);
155 extern s32 HIOETH_CancelReceive(NNETInstance* ins, u32 receive_id);
156 
157 
158 #ifdef  __cplusplus
159 }
160 #endif
161 
162 /* NN_NETWORK_HIOETH_H */
163 #endif
164