|
1 /* |
|
2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 // Ethernet.h |
|
18 // |
|
19 // |
|
20 /** @file ethernet.h |
|
21 Base classes for implementating ethernet support (Kernel-side only) |
|
22 @internalComponent |
|
23 */ |
|
24 |
|
25 #ifndef __ETHERNET_H__ |
|
26 #define __ETHERNET_H__ |
|
27 #include <platform.h> |
|
28 #include <d32ethernet.h> |
|
29 #include <e32ver.h> |
|
30 |
|
31 /** @addtogroup enet Ethernet Drivers |
|
32 * Kernel Ethernet Support |
|
33 */ |
|
34 |
|
35 /** @addtogroup enet_ldd Driver LDD's |
|
36 * @ingroup enet |
|
37 */ |
|
38 |
|
39 const TInt KEthernetMajorVersionNumber = 1; |
|
40 const TInt KEthernetMinorVersionNumber = 0; |
|
41 const TInt KEthernetBuildVersionNumber = KE32BuildVersionNumber; |
|
42 |
|
43 /** |
|
44 @publishedPartner |
|
45 @released |
|
46 */ |
|
47 const TInt KTxWorkBudgetLimit = 10; |
|
48 |
|
49 // Card Rx constants. |
|
50 const TInt KNumRXBuffers = 40; |
|
51 /** |
|
52 @publishedPartner |
|
53 @released |
|
54 */ |
|
55 const TInt KIRQWorkBudgetLimit = 4; |
|
56 /** |
|
57 @publishedPartner |
|
58 @released |
|
59 */ |
|
60 const TInt KRxWorkBudgetLimit = 6; |
|
61 |
|
62 /** |
|
63 @publishedPartner |
|
64 @released |
|
65 */ |
|
66 const TInt KMaxEthernetPacket = 1518; |
|
67 /** |
|
68 @publishedPartner |
|
69 @released |
|
70 */ |
|
71 const TUint16 CRC_LEN = 4; |
|
72 |
|
73 /** @addtogroup enet_pdd Driver PDD's |
|
74 * @ingroup enet |
|
75 * @{ |
|
76 */ |
|
77 |
|
78 /** |
|
79 Different Stop Modes |
|
80 @publishedPartner |
|
81 @released |
|
82 */ |
|
83 enum TStopMode |
|
84 { |
|
85 EStopNormal, /**< Finish sending and then stop */ |
|
86 EStopEmergency /**< Just stop now */ |
|
87 }; |
|
88 |
|
89 |
|
90 class DChannelEthernet; |
|
91 |
|
92 |
|
93 /** |
|
94 Ethernet driver base class |
|
95 The base class for an ethernet driver that doesn't support power control |
|
96 @publishedPartner |
|
97 @released |
|
98 */ |
|
99 class DEthernet : public DBase |
|
100 { |
|
101 public: |
|
102 /** |
|
103 * Start receiving frames |
|
104 * @return KErrNone if driver started |
|
105 */ |
|
106 virtual TInt Start() =0; |
|
107 /** |
|
108 * Stop receiving frames |
|
109 * @param aMode The stop mode |
|
110 */ |
|
111 virtual void Stop(TStopMode aMode) =0; |
|
112 |
|
113 /** |
|
114 * Validate a new config |
|
115 * Validates a new configuration should be called before Configure |
|
116 * @param aConfig is the configuration to be validated |
|
117 * @return ETrue or EFalse if the Configuration is allowed |
|
118 * @see Configure() |
|
119 */ |
|
120 virtual TInt ValidateConfig(const TEthernetConfigV01 &aConfig) const =0; |
|
121 /** |
|
122 * Configure the device |
|
123 * Reconfigure the device using the new configuration supplied. |
|
124 * This should not change the MAC address. |
|
125 * @param aConfig The new configuration |
|
126 * @see ValidateConfig() |
|
127 * @see MacConfigure() |
|
128 */ |
|
129 virtual TInt Configure(TEthernetConfigV01 &aConfig) =0; |
|
130 /** |
|
131 * Change the MAC address |
|
132 * Attempt to change the MAC address of the device |
|
133 * @param aConfig A Configuration containing the new MAC |
|
134 * @see Configure() |
|
135 */ |
|
136 virtual void MacConfigure(TEthernetConfigV01 &aConfig) =0; |
|
137 /** |
|
138 * Get the current config from the chip |
|
139 * This returns the current configuration of the chip with the folling fields |
|
140 * The Transmit Speed |
|
141 * The Duplex Setting |
|
142 * The MAC address |
|
143 * @param aConfig is a TEthernetConfigV01 referance that will be filled in |
|
144 */ |
|
145 virtual void GetConfig(TEthernetConfigV01 &aConfig) const =0; |
|
146 /** |
|
147 * Check a configuration |
|
148 * @param aConfig a reference to the structure TEthernetConfigV01 with configuration to check |
|
149 */ |
|
150 virtual void CheckConfig(TEthernetConfigV01& aConfig)=0; |
|
151 |
|
152 /** |
|
153 * Querie the device's capibilitys |
|
154 * @param aCaps To be filled in with the capibilites |
|
155 */ |
|
156 virtual void Caps(TDes8 &aCaps) const =0; |
|
157 |
|
158 /** |
|
159 * Transmit data |
|
160 * @param aBuffer referance to the data to be sent |
|
161 * @return KErrNone if the data has been sent |
|
162 */ |
|
163 virtual TInt Send(TBuf8<KMaxEthernetPacket+32> &aBuffer) =0; |
|
164 /** |
|
165 * Retrieve data from the device |
|
166 * Pull the received data out of the device and into the supplied buffer. |
|
167 * Need to be told if the buffer is OK to use as if it not we could dump |
|
168 * the waiting frame in order to clear the interrupt if necessory. |
|
169 * @param aBuffer Referance to the buffer to be used to store the data in |
|
170 * @param okToUse Bool to indicate if the buffer is usable |
|
171 * @return KErrNone if the buffer has been filled. |
|
172 */ |
|
173 virtual TInt ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, |
|
174 TBool okToUse) =0; |
|
175 |
|
176 /** |
|
177 * Disables all IRQ's |
|
178 * @return The IRQ level before it was changed |
|
179 * @see RestoreIrqs() |
|
180 */ |
|
181 virtual TInt DisableIrqs()=0; |
|
182 /** |
|
183 * Restore the IRQ's to the supplied level |
|
184 * @param aIrq The level to set the irqs to. |
|
185 * @see DisableIrqs() |
|
186 */ |
|
187 virtual void RestoreIrqs(TInt aIrq)=0; |
|
188 /** |
|
189 * Return the DFC Queue that this device should use |
|
190 * @param aUnit The Channel number |
|
191 * @return Then DFC Queue to use |
|
192 */ |
|
193 virtual TDfcQue* DfcQ(TInt aUnit)=0; |
|
194 /** |
|
195 * The Receive Isr for the device |
|
196 */ |
|
197 inline void ReceiveIsr(); |
|
198 |
|
199 #ifdef ETH_CHIP_IO_ENABLED |
|
200 virtual TInt BgeChipIOCtrl(TPckgBuf<TChipIOInfo> &aIOData)=0; |
|
201 #endif |
|
202 /** |
|
203 * A pointer to the logical device drivers channel that owns this device |
|
204 */ |
|
205 DChannelEthernet * iLdd ; |
|
206 }; |
|
207 |
|
208 /** @} */ // End of pdd group |
|
209 |
|
210 /** |
|
211 * @addtogroup enet_ldd_nopm_nopccard Ethernet LDD Not PCMCIA and No Power Managment |
|
212 * @ingroup enet_ldd |
|
213 * @ingroup enet_misa |
|
214 * @ingroup enet_wins |
|
215 * @{ |
|
216 */ |
|
217 |
|
218 /** |
|
219 Ethernet logical device |
|
220 The class representing the ethernet logical device |
|
221 @internalComponent |
|
222 */ |
|
223 class DDeviceEthernet : public DLogicalDevice |
|
224 { |
|
225 public: |
|
226 /** |
|
227 * The constructor |
|
228 */ |
|
229 DDeviceEthernet(); |
|
230 /** |
|
231 * Install the device |
|
232 */ |
|
233 virtual TInt Install(); |
|
234 /** |
|
235 * Get the Capabilites of the device |
|
236 * @param aDes descriptor that will contain the returned capibilites |
|
237 */ |
|
238 virtual void GetCaps(TDes8 &aDes) const; |
|
239 /** |
|
240 * Create a logical channel to the device |
|
241 */ |
|
242 virtual TInt Create(DLogicalChannelBase*& aChannel); |
|
243 }; |
|
244 |
|
245 |
|
246 /** |
|
247 Stores the Tx and RX buffers for use in a ethernet logical channel |
|
248 @internalComponent |
|
249 */ |
|
250 class DChannelEthernetFIFO |
|
251 { |
|
252 public: |
|
253 /** |
|
254 * The TX Buffer |
|
255 */ |
|
256 TBuf8<KMaxEthernetPacket+32> iTxBuf; |
|
257 |
|
258 /** |
|
259 * The constructor |
|
260 */ |
|
261 DChannelEthernetFIFO(); |
|
262 /** |
|
263 * The destructor |
|
264 */ |
|
265 ~DChannelEthernetFIFO(); |
|
266 /** |
|
267 * Get a empty receive buffer |
|
268 * @return NULL or a pointer to the free buffer |
|
269 */ |
|
270 TBuf8<KMaxEthernetPacket+32> * GetFree(); |
|
271 /** |
|
272 * Get the next full buffer |
|
273 * @return NULL or a pointer to the full buffer |
|
274 */ |
|
275 TBuf8<KMaxEthernetPacket+32> * GetNext(); |
|
276 /** |
|
277 * Move on to the next full buffer |
|
278 */ |
|
279 void SetNext(); |
|
280 |
|
281 private: |
|
282 /** |
|
283 * The array of receive buffers |
|
284 */ |
|
285 TBuf8<KMaxEthernetPacket+32> iRxBuf[KNumRXBuffers]; |
|
286 /** |
|
287 * Index into the array of the next full buffer |
|
288 */ |
|
289 TInt iRxQueIterNext; |
|
290 /** |
|
291 * Index into the array of the next empty buffer |
|
292 */ |
|
293 TInt iRxQueIterFree; |
|
294 /** |
|
295 * Count of the number of empty buffers |
|
296 */ |
|
297 TInt iNumFree; |
|
298 }; |
|
299 |
|
300 /** |
|
301 The logical channel for ethernet devices |
|
302 The basic ethernet logical channel that doesn't support |
|
303 power control or PCCard ethernet devices |
|
304 @internalComponent |
|
305 */ |
|
306 class DChannelEthernet : public DLogicalChannel |
|
307 { |
|
308 public: |
|
309 /** |
|
310 * The state of the logical channel |
|
311 */ |
|
312 enum TState |
|
313 { |
|
314 EOpen, /**< The channel is open */ |
|
315 EActive, /**< The channel is open and busy */ |
|
316 EClosed /**< The channel is closed */ |
|
317 }; |
|
318 |
|
319 /** |
|
320 * Requests that can be made on the channel |
|
321 */ |
|
322 enum TRequest |
|
323 { |
|
324 ERx=1, /**< Receive a frame */ |
|
325 ETx=2, /**< Transmit a frame */ |
|
326 EAll=0xff /**< Complete/cancel all outstanding requests */ |
|
327 }; |
|
328 |
|
329 /** |
|
330 * The constructor |
|
331 */ |
|
332 DChannelEthernet(); |
|
333 /** |
|
334 * The destructor |
|
335 */ |
|
336 ~DChannelEthernet(); |
|
337 |
|
338 /** |
|
339 * The ISR function for the channel |
|
340 * This is called by the pycical channels ISR when data is received |
|
341 * It passes a empty buffer to the PDD for it to store the frame in |
|
342 */ |
|
343 virtual void ReceiveIsr(); |
|
344 |
|
345 protected: |
|
346 /** |
|
347 * Create a logical ethernet channel |
|
348 * @param aUnit The channel number to create |
|
349 * @param anInfo not used, can be NULL |
|
350 * @param aVer The minimun driver version allowed |
|
351 * @return KErrNone if channel created |
|
352 */ |
|
353 virtual TInt DoCreate(TInt aUnit, const TDesC8* anInfo, const TVersion& aVer); |
|
354 /** |
|
355 * Handle a message from the channels user |
|
356 * @param aMsg The message to handle |
|
357 */ |
|
358 virtual void HandleMsg(TMessageBase* aMsg); |
|
359 /** |
|
360 * Cancel an outstanding request |
|
361 * @param aMask A mask containing the requests to be canceled |
|
362 */ |
|
363 void DoCancel(TInt aMask); |
|
364 /** |
|
365 * Preform a control operation on the channel |
|
366 * Control operations are: |
|
367 * - Get the current configuration |
|
368 * - Configure the channel |
|
369 * - Set the MAC address for the channel |
|
370 * - Get the capibilities of the channel |
|
371 * @param aId The operation to preform |
|
372 * @param a1 The data to use with the operation |
|
373 * @param a2 can be NULL - not used |
|
374 * @return KErrNone if operation done |
|
375 */ |
|
376 TInt DoControl(TInt aId, TAny* a1, TAny* a2); |
|
377 /** |
|
378 * Preform an asynchros operation on the channel |
|
379 * Operations are: |
|
380 * - Read data from the channel |
|
381 * - Write data to the channel |
|
382 * @param aId The operation to perform |
|
383 * @param aStatus The status object to use when complete |
|
384 * @param a1 The data to use |
|
385 * @param a2 The length of the data to use |
|
386 * @return KErrNone if operation started ok |
|
387 * @see Complete() |
|
388 */ |
|
389 TInt DoRequest(TInt aId, TRequestStatus* aStatus, TAny* a1, TAny* a2); |
|
390 |
|
391 //Override sendMsg to copy clients memory in client context for WDP. |
|
392 virtual TInt SendMsg(TMessageBase* aMsg); |
|
393 |
|
394 TInt SendControl(TMessageBase* aMsg); |
|
395 |
|
396 TInt SendRequest(TMessageBase* aMsg); |
|
397 |
|
398 /** |
|
399 * Start the channel receiving |
|
400 */ |
|
401 void Start(); |
|
402 /** |
|
403 * Shutdown the channel |
|
404 */ |
|
405 void Shutdown(); |
|
406 |
|
407 /** |
|
408 * Complete an RX request |
|
409 * Is run as the RX DFC and reads a buffer from the receive FIFO into |
|
410 * the users buffer |
|
411 */ |
|
412 void DoCompleteRx(); |
|
413 /** |
|
414 * Completes an outstanding request |
|
415 * @param aMask Specifies what request to complete |
|
416 * @param aReason The reason the request is complete |
|
417 * @see DoRequest() |
|
418 */ |
|
419 void Complete(TInt aMask, TInt aReason); |
|
420 |
|
421 /** |
|
422 * Disables all IRQ's |
|
423 * @return The IRQ level before it was changed |
|
424 * @see RestoreIrqs() |
|
425 */ |
|
426 inline TInt DisableIrqs(); |
|
427 /** |
|
428 * Restore the IRQ's to the supplied level |
|
429 * @param aIrq The level to set the irqs to. |
|
430 * @see DisableIrqs() |
|
431 */ |
|
432 inline void RestoreIrqs(TInt aIrq); |
|
433 |
|
434 /** |
|
435 * Calls the PDD's start method |
|
436 * @return KErrNone if the PDD started ok |
|
437 */ |
|
438 inline TInt PddStart(); |
|
439 /** |
|
440 * Calls the PDD's Validate method |
|
441 * @param aConfig The configuration to be validated |
|
442 * @return KErrNone if config is valid |
|
443 */ |
|
444 inline TInt ValidateConfig(const TEthernetConfigV01 &aConfig) const; |
|
445 /** |
|
446 * Calls the PDD's Configure method |
|
447 * Should call Validate first |
|
448 * Will not change the MAC address |
|
449 * @param aConfig The new configuration |
|
450 * @see ValidateConfig() |
|
451 */ |
|
452 inline void PddConfigure(TEthernetConfigV01 &aConfig); |
|
453 /** |
|
454 * Calls the PDD's MacConfigure method |
|
455 * Will not change anything but the MAC address |
|
456 * @param aConfig A configuration containing the new MAC address |
|
457 */ |
|
458 inline void MacConfigure(TEthernetConfigV01 &aConfig); |
|
459 /** |
|
460 * Calls the PDD's ChheckConfig Method |
|
461 * @param aConfig The config to check |
|
462 */ |
|
463 inline void PddCheckConfig(TEthernetConfigV01 &aConfig); |
|
464 |
|
465 /** |
|
466 * Calls the PDD's get capibilities method |
|
467 * @param aCaps Filled in with the PDD capibilites on return |
|
468 */ |
|
469 inline void PddCaps(TDes8 &aCaps) const; |
|
470 |
|
471 /** |
|
472 * Sends data using the PDD |
|
473 * @param aBuffer A referance to a buffer to be sent |
|
474 * @return KErrNone if buffer sent |
|
475 */ |
|
476 inline TInt PddSend(TBuf8<KMaxEthernetPacket+32> &aBuffer); |
|
477 /** |
|
478 * Receive a frame from the PDD |
|
479 * @param aBuffer A referance to the buffer that the frame is to be put in |
|
480 * @param okToUse Flag to say if the buffer is valid |
|
481 * @return KErrNone if the buffer now contains a frame |
|
482 */ |
|
483 inline TInt PddReceive(TBuf8<KMaxEthernetPacket+32> &aBuffer, TBool okToUse); |
|
484 |
|
485 private: |
|
486 /** |
|
487 * The DFC called by the kernel |
|
488 * @param aPtr A pointer to the channel object |
|
489 */ |
|
490 static void CompleteRxDfc(TAny* aPtr); |
|
491 |
|
492 /** |
|
493 * Start a read request |
|
494 * @param aRxDes The buffer to be filled with data |
|
495 * @param aLength The max size frame that can fit in the buffer |
|
496 */ |
|
497 void InitiateRead(TAny* aRxDes, TInt aLength); |
|
498 /** |
|
499 * Start a write request |
|
500 * @param aTxDes The buffer containing the frame to be sent |
|
501 * @param aLength The length of the frame to be sent |
|
502 */ |
|
503 void InitiateWrite(TAny* aTxDes, TInt aLength); |
|
504 /** |
|
505 * Validates and set a new configuration |
|
506 * @param c The configuration to try |
|
507 * @return KErrNone if new configuration set |
|
508 */ |
|
509 TInt SetConfig(TEthernetConfigV01& c); |
|
510 /** |
|
511 * Validates and sets a new MAC address |
|
512 * @param c The configuration containing the MAC to be set |
|
513 * @return KErrNone if the MAC is set ok |
|
514 */ |
|
515 TInt SetMAC(TEthernetConfigV01& c); |
|
516 |
|
517 /** |
|
518 * The current channel configuration |
|
519 */ |
|
520 TEthernetConfigV01 iConfig; |
|
521 |
|
522 /** |
|
523 * Pointer to the client thread |
|
524 */ |
|
525 DThread* iClient; |
|
526 |
|
527 /** |
|
528 * Current state of the LDD |
|
529 */ |
|
530 TState iStatus; |
|
531 |
|
532 /** |
|
533 * The receive complete DFC |
|
534 */ |
|
535 TDfc iRxCompleteDfc; |
|
536 |
|
537 /** |
|
538 * Records if the channel is being shutdown |
|
539 */ |
|
540 TBool iShutdown; // ETrue means device is being closed |
|
541 |
|
542 /** |
|
543 * The length of the clients buffer |
|
544 */ |
|
545 TInt iRxLength; |
|
546 |
|
547 /** |
|
548 * The TX and RX buffers |
|
549 */ |
|
550 DChannelEthernetFIFO iFIFO; |
|
551 |
|
552 //Read request to store user request status for WDP |
|
553 TClientBufferRequest* iReadRequest; |
|
554 //Read buffer to pin client buffer in client context for WDP |
|
555 TClientBuffer* iClientReadBuffer; |
|
556 |
|
557 //Write request to store user request status for WDP |
|
558 TClientRequest* iWriteRequest; |
|
559 |
|
560 #ifdef ETH_CHIP_IO_ENABLED |
|
561 TPckgBuf<TChipIOInfo> iChipInfo; |
|
562 #endif |
|
563 }; |
|
564 /** @} */ |
|
565 |
|
566 #include <drivers/ethernet.inl> |
|
567 |
|
568 #endif |