[VNIC] Initial checkin of VNIC code. Not yet fully functional.
[mirror/winof/.git] / ulp / inic / kernel / vnic_ib.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_IB_H_\r
32 #define _VNIC_IB_H_\r
33 \r
34 \r
35 #include <iba/ib_al.h>\r
36 #include <complib/comp_lib.h>\r
37 #include "vnic_trailer.h"\r
38 struct Io;\r
39 \r
40 typedef void (CompRoutine_t)(struct Io *pIo);\r
41 \r
42 #define MAX_HCAS        4\r
43 #define MAX_NUM_SGE 8\r
44 \r
45 #define MAX_PHYS_MEMORY   0xFFFFFFFFFFFFFFFF\r
46 #define CONTROL_SID             0\r
47 #define DATA_SID                1\r
48 \r
49 #include <complib/cl_packon.h>\r
50 typedef union _vnic_sid {\r
51         uint64_t        as_uint64;\r
52         struct {\r
53                 uint8_t         base_id; /* base id for vnic is 0x10 */\r
54                 uint8_t         oui[3];  /* OUI */\r
55                 uint16_t        reserved; /* should be zero */\r
56                 uint8_t         type;     /* control or data */\r
57                 uint8_t         ioc_num;  /* ioc number */\r
58         }s;\r
59 } vnic_sid_t;\r
60 \r
61 typedef union _vnic_ioc_guid {\r
62         uint64_t        as_uint64;\r
63         struct {\r
64                 uint8_t         oui[3];\r
65                 uint8_t         ioc_num;\r
66                 uint32_t        counter;        /* SST device type: 8 bits, counter:24 bits */\r
67         }s;\r
68 } vnic_ioc_guid_t;\r
69 #include <complib/cl_packoff.h>\r
70 \r
71 typedef enum {\r
72         IB_UNINITTED = 0,\r
73         IB_INITTED,\r
74         IB_ATTACHING,\r
75         IB_ATTACHED,\r
76         IB_DETACHING,\r
77         IB_DETACHED,\r
78         IB_DISCONNECTED\r
79 } IbState_t;\r
80 #pragma warning ( disable : 4324 )\r
81 typedef struct _vnic_path_record {\r
82         cl_list_item_t          list_entry;\r
83         uint32_t                        num_entries;\r
84         ib_path_rec_t           path_rec;\r
85 } vnic_path_record_t;\r
86 #pragma warning( default : 4324 )\r
87 \r
88 typedef struct IbQp {\r
89         LIST_ENTRY              listPtrs;\r
90         struct _viport  *pViport;\r
91         struct IbConfig *p_conf;\r
92         NDIS_SPIN_LOCK  qpLock;\r
93         volatile LONG   qpState;\r
94         uint32_t                qpNumber;\r
95         struct IbCa             *pCa;\r
96         uint64_t                portGuid;\r
97         ib_qp_handle_t  qp;\r
98         ib_cq_handle_t  cq;\r
99 #ifdef VNIC_STATISTIC\r
100         struct {\r
101                 int64_t         connectionTime;\r
102                 int64_t         rdmaPostTime;\r
103                 uint32_t        rdmaPostIos;\r
104                 int64_t         rdmaCompTime;\r
105                 uint32_t        rdmaCompIos;\r
106                 int64_t         sendPostTime;\r
107                 uint32_t        sendPostIos;\r
108                 int64_t         sendCompTime;\r
109                 uint32_t        sendCompIos;\r
110                 int64_t         recvPostTime;\r
111                 uint32_t        recvPostIos;\r
112                 int64_t         recvCompTime;\r
113                 uint32_t        recvCompIos;\r
114                 uint32_t        numIos;\r
115                 uint32_t        numCallbacks;\r
116                 uint32_t        maxIos;\r
117         } statistics;\r
118 #endif /* VNIC_STATISTIC */\r
119 } IbQp_t;\r
120 \r
121 typedef struct IbRegion {\r
122         uint64_t                virtAddress;\r
123         net64_t                 len;\r
124         ib_mr_handle_t  h_mr;\r
125         net32_t                 lkey;\r
126         net32_t                 rkey;\r
127 } IbRegion_t;\r
128 \r
129 \r
130 #define VNIC_CA_MAX_PORTS       2\r
131 typedef struct IbCa {\r
132         cl_list_item_t          list_entry;\r
133         net64_t                         caGuid;\r
134         ib_pd_handle_t          hPd;\r
135         IbRegion_t                      region;\r
136         uint32_t                        numPorts;\r
137         uint64_t                        portGuids[VNIC_CA_MAX_PORTS];\r
138 } IbCa_t;\r
139 \r
140 typedef enum _OpType { RECV, RDMA, SEND }OpType_t;\r
141 \r
142 typedef struct Io {\r
143                 LIST_ENTRY                      listPtrs;\r
144                 struct _viport          *pViport;\r
145                 CompRoutine_t           *pRoutine;\r
146                 ib_send_wr_t            wrq;\r
147                 ib_recv_wr_t            r_wrq;\r
148                 ib_wc_status_t          wc_status;\r
149 #ifdef VNIC_STATISTIC\r
150                 int64_t         time;\r
151 #endif /* VNIC_STATISTIC */\r
152                 OpType_t                type;\r
153 } Io_t;\r
154 \r
155 typedef struct RdmaIo {\r
156                 Io_t                            io;\r
157                 ib_local_ds_t           dsList[MAX_NUM_SGE];\r
158                 uint16_t                        index;\r
159                 uint32_t                        len;\r
160                 NDIS_PACKET                     *p_packet;\r
161                 NDIS_BUFFER                     *p_buf;\r
162                 ULONG                           packet_sz;\r
163                 struct ViportTrailer *p_trailer;\r
164                 uint8_t                         data[2* VIPORT_TRAILER_ALIGNMENT];\r
165 } RdmaIo_t;\r
166 \r
167 typedef struct SendIo {\r
168                 Io_t                            io;\r
169                 ib_local_ds_t           dsList;\r
170 } SendIo_t;\r
171 \r
172 typedef struct RecvIo {\r
173                 Io_t                            io;\r
174                 ib_local_ds_t           dsList;\r
175 } RecvIo_t;\r
176 \r
177 void\r
178 ibqp_construct(\r
179         IN      OUT             IbQp_t                  *pQp,\r
180         IN                      struct _viport  *pViport );\r
181 ib_api_status_t ibqp_init(IbQp_t *pQp, uint64_t guid, struct IbConfig *p_conf);\r
182 ib_api_status_t ibqp_connect(IbQp_t *pQp);\r
183 void    ibqp_detach(IbQp_t *pQp);\r
184 void    ibqp_cleanup(IbQp_t *pQp);\r
185 ib_api_status_t ibqp_postSend(IbQp_t *pQp, Io_t *pIo);\r
186 ib_api_status_t ibqp_postRecv(IbQp_t *pQp, Io_t *pIo);\r
187 \r
188 uint8_t  ibca_findPortNum( struct _viport *p_viport, uint64_t guid );\r
189 \r
190 ib_api_status_t\r
191 ibregion_init(\r
192                 IN              struct _viport          *p_viport,\r
193                 OUT             IbRegion_t                      *pRegion,\r
194                 IN              ib_pd_handle_t          hPd,\r
195                 IN              void* __ptr64           vaddr,\r
196                 IN              uint64_t                        len,\r
197                 IN              ib_access_t                     access_ctrl );\r
198 \r
199 void\r
200 ibregion_cleanup(\r
201                                  struct _viport *p_viport,\r
202                                  IbRegion_t *pRegion );\r
203 \r
204 void ib_asyncEvent( ib_async_event_rec_t        *pEventRecord );\r
205 \r
206 #define ibpd_fromCa(pCa) (&(pCa)->pd)\r
207 \r
208 \r
209 #endif /* _VNIC_IB_H_ */\r