1 /*---------------------------------------------------------------------------*
2   Project:  Horizon
3   File:     peth.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 #ifndef NN_NETWORK_PETH_H
17 #define NN_NETWORK_PETH_H
18 
19 #include <nnet.h>
20 
21 #ifdef  __cplusplus
22 extern "C" {
23 #endif
24 
25 /*---------------------------------------------------------------------------*
26  * Definitions
27  *---------------------------------------------------------------------------*/
28 #define PETH_DEVICE_1               0           /* Only 1 interface can be used with this driver */
29 
30 #define PETH_VENDOR_NINTENDO        0x0000
31 #define PETH_COMMON_CONF_VERSION    0x1100
32 #define PETH_INS_CONF_VERSION       0x2100
33 
34 /* Please see man pages for details
35 
36  */
37 #define PETH_ERROR_BASE                          0xffff9000
38 #define PETH_ERROR_CODE(code)                    ((s32)(PETH_ERROR_BASE|(code)))
39 enum {
40     PETH_ERR_PARAM        = PETH_ERROR_CODE(1),     /* Parameter error */
41     PETH_ERR_INIT         = PETH_ERROR_CODE(2),     /* Cannot run because it is in initialized state */
42     PETH_ERR_FINISH       = PETH_ERROR_CODE(3),     /* Cannot run because it is in terminated state */
43     PETH_ERR_CONFVER      = PETH_ERROR_CODE(4),     /* Setting version error */
44     PETH_ERR_STATE        = PETH_ERROR_CODE(5),     /* State error */
45     PETH_ERR_EXIST        = PETH_ERROR_CODE(6),     /* Already created */
46     PETH_ERR_NOMEM        = PETH_ERROR_CODE(7),     /* Insufficient memory */
47     PETH_ERR_TIMEOUT      = PETH_ERROR_CODE(8),     /* timeout */
48     PETH_ERR_NONE         = 0                       /* Normal end */
49 };
50 
51 /* Please see man pages for details
52 
53  */
54 #define PETH_MEM_BASE                            0x00050000
55 #define PETH_MEM_NAME(name)                    ((s32)(PETH_MEM_BASE|(name)))
56 enum {
57     PETH_MEM_INSTANCE = PETH_MEM_NAME(1)
58 };
59 
60 /* Please see man pages for details
61 
62  */
63 enum {
64     PETH_STATE_INIT = 0,        /* Initial state */
65     PETH_STATE_ACTIVE,          /* Connection completed state */
66     PETH_STATE_ABORT            /* Connection completed state */
67 };
68 
69 /*---------------------------------------------------------------------------*
70  * Types/Declarations
71  *---------------------------------------------------------------------------*/
72 #define PETH_MAC_LEN            6
73 
74 /* Please see man pages for details
75 
76  */
77 typedef struct PETHProtocolList {
78     u16 protocol;                   /* IP, ARP, etc. */
79     NNETInstance *upper_ins;            /* Upper instance */
80     NOSMessageQueueId mq_receive;   /* Queue to insert packet when above protocol is received */
81 } PETHProtocolList;
82 
83 /* Please see man pages for details
84 
85  */
86 #define PETH_PROTOCOL_NUM   8   /* ARP, RARP, IP, PPPoE Discovery, PPPoE Session */
87 #define PETH_UPPER_NUM      2   /* Number of upper layers   */
88 #define PETH_MQ_NUM         16  /* Size of queue to pass to upper layers */
89 #define PETH_MAX_SEND_LEN   1600
90 typedef struct PETHMessage {
91     NOSMessageQueue mq; /* Receive queue for upper layers */
92     NOSMessage  mqarray[PETH_MQ_NUM];   /* Receive queue instance for upper layers */
93 } PETHMessage;
94 
95 typedef struct PETHInstance {
96     NNETInstance ins;                   /* Instance information common to all layers */
97 
98     PETHProtocolList upper_protocol[PETH_PROTOCOL_NUM]; /* Upper protocol and message queue for sending */
99     s32 upper_protocol_count;
100 
101     PETHMessage upper_mq[PETH_UPPER_NUM];   /* Receive queue for upper layers */
102 
103     s32 upper_ins_count;
104 
105     s32 state;
106 
107     u8 macaddr[PETH_MAC_LEN];   /* Local MAC address */
108     u16 pad;
109     u8 sendBuf[PETH_MAX_SEND_LEN];  /* Send buffer */
110 
111 } PETHInstance;
112 
113 /*
114     Get NNETInstance from WCM instance
115 */
PETH_GetNNETInstance(PETHInstance * peth_ins)116 static inline NNETInstance *PETH_GetNNETInstance(PETHInstance *peth_ins)
117 {
118     return &peth_ins->ins;
119 }
120 
121 /*
122     Get WCM instance from NNETInstance
123 */
PETH_GetPETHInstance(NNETInstance * ins)124 static inline PETHInstance *PETH_GetPETHInstance(NNETInstance *ins)
125 {
126     return (PETHInstance *)ins;
127 }
128 
129 /*---------------------------------------------------------------------------*
130  * Function Prototypes
131  *---------------------------------------------------------------------------*/
132 /* PETH_main.c */
133 extern s32 PETH_Init(const NNETAllocator *allocator);
134 extern s32 PETH_Finish(void);
135 extern s32 PETH_StartupIns(NNETInstance *ins, s32 timeout);
136 extern s32 PETH_CleanupIns(NNETInstance *ins, s32 timeout);
137 extern s32 PETH_AbortIns(NNETInstance *ins);
138 extern s32 PETH_CreateIns(PETHInstance **peth_ins);
139 extern s32 PETH_DestroyIns(PETHInstance *peth_ins);
140 extern s32 PETH_GetStateIns(PETHInstance *peth_ins);
141 extern s32 PETH_GetUpperAPI(NNETEthernetAPI *wcm_api, PETHInstance *peth_ins);
142 extern s32 PETH_SetUpper(NNETInstance *ins, NNETInstance *upper_ins, u32 *receive_id, u16 entry[]);
143 extern s32 PETH_ClearUpper(NNETInstance *ins, NNETInstance *upper_ins);
144 extern s32 PETH_GetMacAddr(NNETInstance *ins, u8 *macaddr);
145 extern s32 PETH_SetMulticastAddr(NNETInstance *ins, u8 *macaddr);
146 extern s32 PETH_ClearMulticastAddr(NNETInstance *ins, u8 *macaddr);
147 extern s32 PETH_Send(NNETInstance *ins, u8 *dstMAC, NOSMessageBuf *mbuf);
148 extern s32 PETH_Receive(NNETInstance *ins, u32 receive_id, NOSMessageBuf **mbuf);
149 extern s32 PETH_CancelReceive(NNETInstance *ins, u32 receive_id);
150 
151 
152 #ifdef  __cplusplus
153 }
154 #endif
155 
156 /* NN_NETWORK_PETH_H */
157 #endif
158