[VNIC] Initial checkin of VNIC code. Not yet fully functional.
[mirror/winof/.git] / ulp / inic / kernel / vnic_viport.h
1 /*\r
2  * Copyright (c) 2005 SilverStorm Technologies.  All rights reserved.\r
3  *\r
4  * This software is available to you under the OpenIB.org BSD license\r
5  * below:\r
6  *\r
7  *     Redistribution and use in source and binary forms, with or\r
8  *     without modification, are permitted provided that the following\r
9  *     conditions are met:\r
10  *\r
11  *      - Redistributions of source code must retain the above\r
12  *        copyright notice, this list of conditions and the following\r
13  *        disclaimer.\r
14  *\r
15  *      - Redistributions in binary form must reproduce the above\r
16  *        copyright notice, this list of conditions and the following\r
17  *        disclaimer in the documentation and/or other materials\r
18  *        provided with the distribution.\r
19  *\r
20  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,\r
21  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r
22  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r
23  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS\r
24  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN\r
25  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN\r
26  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\r
27  * SOFTWARE.\r
28  *\r
29  * $Id$\r
30  */\r
31 #ifndef _VNIC_VIPORT_H_\r
32 #define _VNIC_VIPORT_H_\r
33 \r
34 typedef struct _mc_list {\r
35         uint8_t                         mc_addr[MAC_ADDR_LEN];\r
36 } mc_list_t;\r
37 \r
38 typedef enum {\r
39         VIPORT_DISCONNECTED,\r
40         VIPORT_CONNECTED\r
41 } viport_state_t;\r
42 \r
43 typedef enum {\r
44         LINK_UNINITIALIZED,\r
45         LINK_INITIALIZE,\r
46         LINK_INITIALIZECONTROL,\r
47         LINK_INITIALIZEDATA,\r
48         LINK_CONTROLCONNECT,\r
49         LINK_CONTROLCONNECTWAIT,\r
50         LINK_INITINICREQ,\r
51         LINK_INITINICRSP,\r
52         LINK_BEGINDATAPATH,\r
53         LINK_CONFIGDATAPATHREQ,\r
54         LINK_CONFIGDATAPATHRSP,\r
55         LINK_DATACONNECT,\r
56         LINK_DATACONNECTWAIT,\r
57         LINK_XCHGPOOLREQ,\r
58         LINK_XCHGPOOLRSP,\r
59         LINK_INITIALIZED,\r
60         LINK_IDLE,\r
61         LINK_IDLING,\r
62         LINK_CONFIGLINKREQ,\r
63         LINK_CONFIGLINKRSP,\r
64         LINK_CONFIGADDRSREQ,\r
65         LINK_CONFIGADDRSRSP,\r
66         LINK_REPORTSTATREQ,\r
67         LINK_REPORTSTATRSP,\r
68         LINK_HEARTBEATREQ,\r
69         LINK_HEARTBEATRSP,\r
70         LINK_RESET,\r
71         LINK_RESETRSP,\r
72         LINK_RESETCONTROL,\r
73         LINK_RESETCONTROLRSP,\r
74         LINK_DATADISCONNECT,\r
75         LINK_CONTROLDISCONNECT,\r
76         LINK_CLEANUPDATA,\r
77         LINK_CLEANUPCONTROL,\r
78         LINK_DISCONNECTED,\r
79         LINK_RETRYWAIT\r
80 } LinkState_t;\r
81 \r
82 /* index entries */\r
83 #define BROADCAST_ADDR       0\r
84 #define UNICAST_ADDR         1\r
85 #define MCAST_ADDR_START     2\r
86 #define MAX_MCAST               (MAX_ADDR_ARRAY - MCAST_ADDR_START)\r
87 \r
88 #define currentMacAddress    macAddresses[UNICAST_ADDR].address\r
89 \r
90 #define NEED_STATS           0x00000001\r
91 #define NEED_ADDRESS_CONFIG  0x00000002\r
92 #define NEED_LINK_CONFIG     0x00000004\r
93 #define MCAST_OVERFLOW       0x00000008\r
94 #define SYNC_QUERY                      0x80000000\r
95 \r
96 typedef enum {\r
97         NETPATH_TS_IDLE,\r
98         NETPATH_TS_ACTIVE,\r
99         NETPATH_TS_EXPIRED\r
100 } netpathTS_t;\r
101 \r
102 \r
103 typedef struct {\r
104         LIST_ENTRY                              listPtrs;\r
105         struct _vnic_adapter    *p_adapter;\r
106         uint8_t                                 event_num;\r
107 } InicNPEvent_t;\r
108 \r
109 typedef enum {\r
110         INICNP_CONNECTED = 0,\r
111         INICNP_DISCONNECTED,\r
112         INICNP_LINKUP,\r
113         INICNP_LINKDOWN,\r
114         INICNP_TIMEREXPIRED,\r
115         INICNP_UNIVERSAL1,\r
116         /* SECONDARYOFFSET MUST ALWAYS COME AT THE END */\r
117         INICNP_SECONDARYOFFSET\r
118 } InicNPEventPos_t;\r
119 \r
120 #define INICNP_NUM_EVENTS (2 * INICNP_SECONDARYOFFSET)\r
121 \r
122 #define INIC_PRINP_CONNECTED    INICNP_CONNECTED\r
123 #define INIC_PRINP_DISCONNECTED INICNP_DISCONNECTED\r
124 #define INIC_PRINP_LINKUP       INICNP_LINKUP\r
125 #define INIC_PRINP_LINKDOWN     INICNP_LINKDOWN\r
126 #define INIC_PRINP_TIMEREXPIRED INICNP_TIMEREXPIRED\r
127 #define INIC_NP_SETLINK         INICNP_UNIVERSAL1\r
128 \r
129 #define INIC_SECNP_CONNECTED    (INICNP_CONNECTED + INICNP_SECONDARYOFFSET)\r
130 #define INIC_SECNP_DISCONNECTED (INICNP_DISCONNECTED + INICNP_SECONDARYOFFSET)\r
131 #define INIC_SECNP_LINKUP       (INICNP_LINKUP + INICNP_SECONDARYOFFSET)\r
132 #define INIC_SECNP_LINKDOWN     (INICNP_LINKDOWN + INICNP_SECONDARYOFFSET)\r
133 #define INIC_SECNP_TIMEREXPIRED (INICNP_TIMEREXPIRED + INICNP_SECONDARYOFFSET)\r
134 #define INIC_NP_FREEINIC        (INICNP_UNIVERSAL1 + INICNP_SECONDARYOFFSET)\r
135 \r
136 \r
137 typedef struct Netpath {\r
138         volatile LONG                   carrier;\r
139         struct _vnic_adapter    *p_adapter;\r
140         struct _viport                  *pViport;\r
141         size_t                                  pathIdx;\r
142         uint64_t                                connectTime;\r
143         netpathTS_t                             timerState;\r
144 } Netpath_t;\r
145 \r
146 typedef enum {\r
147         WAIT,\r
148         DELAY,\r
149         NOW\r
150 } conn_wait_state_t;\r
151 \r
152 typedef struct _viport {\r
153         LIST_ENTRY                                              listPtrs;\r
154         KSPIN_LOCK                                              lock;\r
155         cl_obj_t                                                obj;\r
156         cl_qlist_t                                              send_pending_list;\r
157         struct _vnic_adapter                    *p_adapter;\r
158         struct Netpath                                  *p_netpath;\r
159         struct ViportConfig                             port_config;\r
160         struct Control                                  control;\r
161         struct Data                                             data;\r
162         uint64_t                                                iocGuid;\r
163         uint64_t                                                portGuid;\r
164 \r
165         // connected/disconnected state of control and data QPs.\r
166         viport_state_t                                  state;\r
167 \r
168         // State machine state?\r
169         LinkState_t                                             linkState;\r
170 \r
171         Inic_CmdReportStatisticsRsp_t   stats;\r
172         uint64_t                                                lastStatsTime;\r
173         uint32_t                                                featuresSupported;\r
174         uint8_t                                                 hwMacAddress[MAC_ADDR_LEN];\r
175         uint16_t                                                defaultVlan;\r
176         uint16_t                                                numMacAddresses;\r
177         Inic_AddressOp_t                                *macAddresses;\r
178         int32_t                                                 addrs_query_done;\r
179 \r
180         // Indicates actions (to the VEx) that need to be taken.\r
181         volatile LONG                                   updates;\r
182         // ???\r
183         uint8_t                                                 flags;\r
184         // TODO: Can we eliminate newFlags?\r
185         uint8_t                                                 newFlags;\r
186 \r
187         uint16_t                                                mtu;\r
188         uint16_t                                                newMtu;\r
189         uint32_t                                                errored;\r
190         uint32_t                                                disconnect;\r
191         volatile LONG                                   timerActive;\r
192         cl_timer_t                                              timer;\r
193         cl_event_t                                              conn_event;\r
194 \r
195 } viport_t;\r
196 \r
197 \r
198 BOOLEAN\r
199 viport_xmitPacket(\r
200                 viport_t*       const   p_viport,\r
201                 NDIS_PACKET* const      p_pkt );\r
202 \r
203 BOOLEAN \r
204 viport_config_defaults(\r
205                 IN      viport_t   *p_viport );\r
206 \r
207 uint32_t\r
208 viport_get_adapter_name(\r
209                 IN      viport_t        *p_viport );\r
210 \r
211 void     viport_cleanup(viport_t *p_viport );\r
212 void     viport_setPath(viport_t *pViport, ib_path_rec_t *path, uint64_t *guid);\r
213 BOOLEAN  viport_setParent(viport_t *pViport, struct Netpath *pNetpath);\r
214 BOOLEAN  viport_unsetParent(viport_t *pViport, struct Netpath *pNetpath);\r
215 void     viport_free(viport_t *pViport);\r
216 void     viport_disconnect(viport_t *pViport);\r
217 NDIS_STATUS  viport_setLink(viport_t *pViport, uint8_t flags, uint16_t mtu);\r
218 NDIS_STATUS  viport_getStats(viport_t *pViport );\r
219 \r
220 void    viport_timer( viport_t *p_viport, int timeout );\r
221 void    viport_timerStop( viport_t *p_viport );\r
222 \r
223 void     viport_linkUp(viport_t *pViport);\r
224 void     viport_linkDown(viport_t *pViport);\r
225 void     viport_stopXmit(viport_t *pViport);\r
226 void     viport_restartXmit(viport_t *pViport);\r
227 void     viport_recvPacket(viport_t *pViport, NDIS_PACKET *pkt );\r
228 void     viport_failure(viport_t *pViport);\r
229 BOOLEAN  viport_setUnicast(viport_t *pViport, uint8_t *pAddress);\r
230 NDIS_STATUS viport_setMulticast( viport_t *pViport );\r
231 #define  viport_portGuid(pViport) ((pViport)->portGuid)\r
232 #define  viport_maxMtu(pViport) data_maxMtu(&(pViport)->data)\r
233 \r
234 #define  viport_getHwAddr(pViport,pAddress) \\r
235                         cl_memcpy(pAddress, (pViport)->hwMacAddress, MAC_ADDR_LEN)\r
236 \r
237 #define  viport_features(pViport) ((pViport)->featuresSupported)\r
238 #define  viport_canTxCsum(pViport) (((pViport)->featuresSupported & \\r
239         (INIC_FEAT_IPV4_CSUM_TX|INIC_FEAT_TCP_CSUM_TX|INIC_FEAT_UDP_CSUM_TX)) \\r
240         == (INIC_FEAT_IPV4_CSUM_TX|INIC_FEAT_TCP_CSUM_TX|INIC_FEAT_UDP_CSUM_TX))\r
241 \r
242 \r
243 void    netpath_init( struct Netpath *pNetpath, struct _vnic_adapter *p_adapter );\r
244 BOOLEAN netpath_addPath(struct Netpath *pNetpath, viport_t *pViport);\r
245 BOOLEAN netpath_removePath(struct Netpath *pNetpath, viport_t *pViport);\r
246 BOOLEAN netpath_getStats(struct Netpath *pNetpath );\r
247 BOOLEAN netpath_setUnicast(struct Netpath *pNetpath, uint8_t *pAddress);\r
248 BOOLEAN netpath_setMulticast(struct Netpath *pNetpath, mc_list_t *mc_list,\r
249         int mc_count);\r
250 int     netpath_maxMtu(struct Netpath *pNetpath);\r
251 \r
252 BOOLEAN\r
253 netpath_xmitPacket(\r
254                 struct Netpath*                 pNetpath,\r
255                 NDIS_PACKET*  const             p_pkt );\r
256 void   \r
257 netpath_recvPacket(\r
258                 struct Netpath*         pNetpath,\r
259                 NDIS_PACKET*            p_pkt );\r
260 \r
261 void    netpath_stopXmit(struct Netpath *pNetpath );\r
262 void    netpath_restartXmit(struct Netpath *pNetpath );\r
263 \r
264 void    netpath_kick(struct Netpath *pNetpath);\r
265 void    netpath_timer(struct Netpath *pNetpath, int timeout);\r
266 void    netpath_tx_timeout(struct Netpath *pNetpath);\r
267 \r
268 const char * netpath_to_string(struct _vnic_adapter *p_adapter, struct Netpath *pNetpath);\r
269 #define netpath_getHwAddr(pNetpath, pAddress) viport_getHwAddr((pNetpath)->pViport, pAddress)\r
270 #define netpath_isConnected(pNetpath) (pNetpath->state == NETPATH_CONNECTED)\r
271 #define netpath_canTxCsum(pNetpath) viport_canTxCsum(pNetpath->pViport)\r
272 \r
273 ib_api_status_t\r
274 viport_control_connect(\r
275            IN           viport_t*       const   p_viport );\r
276 ib_api_status_t\r
277 viport_data_connect(\r
278            IN           viport_t*       const   p_viport );\r
279 \r
280 NDIS_STATUS\r
281 _viport_process_query(\r
282                 IN              viport_t*       const   p_viport,\r
283                 IN              BOOLEAN                         sync );\r
284 \r
285 \r
286 #endif /* _VNIC_VIPORT_H_ */\r