[VNIC] Initial checkin of VNIC code. Not yet fully functional.
[mirror/winof/.git] / ulp / inic / kernel / vnic_netpath.c
1 \r
2 #include "vnic_adapter.h"\r
3 \r
4 extern vnic_globals_t   g_vnic;\r
5 \r
6 \r
7 void\r
8 netpath_init(\r
9                 IN                      Netpath_t                       *pNetpath,\r
10                 IN                      vnic_adapter_t          *p_adapter )\r
11 {\r
12         int i;\r
13 \r
14         VNIC_ENTER( VNIC_DBG_FUNC );\r
15 \r
16         pNetpath->p_adapter    = p_adapter;\r
17         pNetpath->carrier    = 0;\r
18         pNetpath->pViport    = NULL;\r
19         pNetpath->timerState = NETPATH_TS_IDLE;\r
20 \r
21         for ( i = 0; i < INICNP_NUM_EVENTS; i++ )\r
22         {\r
23                 p_adapter->np_event[i].p_adapter = p_adapter;\r
24                 p_adapter->np_event[i].event_num = (uint8_t)i;\r
25                 InitializeListHead( &p_adapter->np_event[i].listPtrs );\r
26         }\r
27 \r
28         VNIC_EXIT( VNIC_DBG_FUNC );\r
29         return;\r
30 }\r
31 \r
32 \r
33 BOOLEAN\r
34 netpath_addPath (\r
35                                  Netpath_t              *pNetpath,\r
36                                  viport_t               *pViport )\r
37 {\r
38 \r
39         if( pNetpath->pViport )\r
40         {\r
41                 return FALSE;\r
42         }\r
43         else\r
44         {\r
45                 pNetpath->pViport = pViport;\r
46                 viport_setParent( pViport, pNetpath );\r
47                 return TRUE;\r
48         }\r
49 }\r
50 \r
51 BOOLEAN\r
52 netpath_removePath(\r
53                                    Netpath_t            *pNetpath,\r
54                                    viport_t                     *pViport)\r
55 {\r
56         if( pNetpath->pViport != pViport )\r
57         {\r
58                 return FALSE;\r
59         }\r
60         else\r
61         {\r
62                 pNetpath->pViport = NULL;\r
63                 viport_unsetParent( pViport, pNetpath );\r
64                 return TRUE;\r
65         }\r
66 }\r
67 \r
68 \r
69 BOOLEAN netpath_setUnicast(Netpath_t *pNetpath, uint8_t *pAddress)\r
70 {\r
71         BOOLEAN ret = FALSE;\r
72 \r
73         // TODO: Not called anywhere!!!\r
74         VNIC_TRACE( VNIC_DBG_NETPATH | VNIC_DBG_INFO,\r
75                 ("Set %s MAC to %02X:%02X:%02X:%02X:%02X:%02X\n",\r
76                 netpath_to_string(pNetpath->p_adapter, pNetpath),\r
77                 pAddress[0],\r
78                 pAddress[1],\r
79                 pAddress[2],\r
80                 pAddress[3],\r
81                 pAddress[4],\r
82                 pAddress[5]) );\r
83 \r
84         if (pNetpath->pViport)\r
85         {\r
86                 ret = viport_setUnicast( pNetpath->pViport, pAddress );\r
87         }\r
88         return ret;\r
89 }\r
90 \r
91 \r
92 int netpath_maxMtu(Netpath_t *pNetpath)\r
93 {\r
94         int ret = MAX_PARAM_VALUE;\r
95 \r
96         if (pNetpath->pViport) {\r
97                 ret = viport_maxMtu(pNetpath->pViport);\r
98         }\r
99         return ret;\r
100 }\r
101 \r
102 BOOLEAN\r
103 netpath_xmitPacket(\r
104                 IN              Netpath_t                       *pNetpath,\r
105                 IN              NDIS_PACKET     * const p_packet )\r
106 {\r
107         BOOLEAN ret = FALSE;\r
108 \r
109         if ( pNetpath->pViport )\r
110         {\r
111                 ret = viport_xmitPacket(pNetpath->pViport, p_packet );\r
112         }\r
113         return ret;\r
114 }\r
115 \r
116 \r
117 void\r
118 netpath_stopXmit(\r
119         IN              Netpath_t               *pNetpath )\r
120 \r
121 {\r
122 \r
123         VNIC_ENTER( VNIC_DBG_NETPATH );\r
124 \r
125         if (pNetpath == pNetpath->p_adapter->p_currentPath )\r
126         {\r
127                 InterlockedCompareExchange( &pNetpath->p_adapter->xmitStarted, 0, 1 );\r
128         }\r
129 #ifdef INIC_STATISTICS\r
130                 if ( pNetpath->p_adapter->statistics.xmitRef == 0)\r
131                 {\r
132                         pNetpath->p_adapter->statistics.xmitRef = get_time_stamp_ms();\r
133                 }\r
134 #endif /* INIC_STATISTICS */\r
135         return;\r
136 }\r
137 \r
138 void netpath_restartXmit(\r
139                 IN              Netpath_t               *pNetpath )\r
140 {\r
141                 VNIC_ENTER( VNIC_DBG_NETPATH );\r
142 \r
143         if (pNetpath == pNetpath->p_adapter->p_currentPath )\r
144         {\r
145                 InterlockedCompareExchange( &pNetpath->p_adapter->xmitStarted, 1, 0 );\r
146         }\r
147 #ifdef INIC_STATISTICS\r
148                 if (pNetpath->p_adapter->statistics.xmitRef != 0)\r
149                 {\r
150                         pNetpath->p_adapter->statistics.xmitOffTime +=\r
151                                 get_time_stamp_ms() - pNetpath->p_adapter->statistics.xmitRef;\r
152                         pNetpath->p_adapter->statistics.xmitOffNum++;\r
153                         pNetpath->p_adapter->statistics.xmitRef = 0;\r
154                 }\r
155 #endif /* INIC_STATISTICS */\r
156         return;\r
157 }\r
158 \r
159 // Viport on input calls this\r
160 void netpath_recvPacket(\r
161                 IN              Netpath_t               *pNetpath,\r
162                 IN              NDIS_PACKET*    p_packet )\r
163 {\r
164         #ifdef INIC_STATISTICS\r
165         extern cycles_t recvRef;\r
166 #endif /* INIC_STATISTICS */\r
167 \r
168         VNIC_ENTER( VNIC_DBG_NETPATH );\r
169 \r
170 #ifdef INIC_STATISTICS\r
171         pNetpath->p_adapter->statistics.recvTime += get_time_stamp_ms() - recvRef;\r
172         pNetpath->p_adapter->statistics.recvNum++;\r
173 #endif /* INIC_STATISTICS */\r
174 \r
175         NdisMIndicateReceivePacket( pNetpath->p_adapter->h_handle, &p_packet, 1 );\r
176 \r
177         return;\r
178 }\r
179 \r
180 void netpath_tx_timeout(\r
181                 IN              Netpath_t               *pNetpath )\r
182 {\r
183         if ( pNetpath->pViport )\r
184         {\r
185                 viport_failure( pNetpath->pViport );\r
186         }\r
187 }\r
188 \r
189 const char *\r
190 netpath_to_string(\r
191                 IN              vnic_adapter_t          *p_adapter,\r
192                 IN              Netpath_t                       *pNetpath )\r
193 {\r
194         if ( !pNetpath )\r
195         {\r
196                 return "NULL";\r
197         }\r
198         else if ( pNetpath == &p_adapter->primaryPath )\r
199         {\r
200                 return "PRIMARY";\r
201         }\r
202         else if ( pNetpath == &p_adapter->secondaryPath )\r
203         {\r
204                 return "SECONDARY";\r
205         } else\r
206         {\r
207                 return "UNKNOWN";\r
208         }\r
209 }\r
210 \r
211 \r
212 static BOOLEAN\r
213 __netpath_npevent_register(vnic_adapter_t *p_adapter, Netpath_t *pNetpath)\r
214 {\r
215         VNIC_ENTER( VNIC_DBG_NETPATH );\r
216 \r
217         UNUSED_PARAM( pNetpath );\r
218         p_adapter->state = INIC_REGISTERED;\r
219         return TRUE;\r
220 }\r
221 \r
222 static const char * const inicNPEventStr[] = {\r
223         "PRIMARY CONNECTED",\r
224         "PRIMARY DISCONNECTED",\r
225         "PRIMARY CARRIER",\r
226         "PRIMARY NO CARRIER",\r
227         "PRIMARY TIMER EXPIRED",\r
228         "SETLINK",\r
229 \r
230         "SECONDARY CONNECTED",\r
231         "SECONDARY DISCONNECTED",\r
232         "SECONDARY CARRIER",\r
233         "SECONDARY NO CARRIER",\r
234         "SECONDARY TIMER EXPIRED",\r
235         "FREE INIC",\r
236 };\r
237 \r