|
1 /* |
|
2 * Copyright (c) 2008-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 "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 * ne1_tb\ethernet\smcs9118_ethernet.h |
|
16 * SMCS9118 Ethernet driver header |
|
17 * |
|
18 */ |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 #ifndef __SMCS9118_ETHERNET_H__ |
|
24 #define __SMCS9118_ETHERNET_H__ |
|
25 |
|
26 #include <naviengine.h> |
|
27 #include "shared_ethernet.h" |
|
28 #include <drivers/gpio.h> |
|
29 #include <nkern.h> |
|
30 |
|
31 /** |
|
32 * @addtogroup shared_ethernet |
|
33 * @{ |
|
34 */ |
|
35 |
|
36 // |
|
37 // Driver Constants |
|
38 // |
|
39 |
|
40 _LIT(KEthernetPddName,"Ethernet.Navi9118"); |
|
41 |
|
42 // |
|
43 // SMCS9118 FIFO Registers (see datasheet Figure 5.1) |
|
44 // |
|
45 const TUint32 SMCS9118_RX_DATA_FIFO = (TUint32)(KHwBaseEthernet + 0x00); |
|
46 const TUint32 SMCS9118_TX_DATA_FIFO = (TUint32)(KHwBaseEthernet + 0x20); |
|
47 const TUint32 SMCS9118_RX_STATUS = (TUint32)(KHwBaseEthernet + 0x40); |
|
48 const TUint32 SMCS9118_RX_STATUS_PEEK = (TUint32)(KHwBaseEthernet + 0x44); |
|
49 const TUint32 SMCS9118_TX_STATUS = (TUint32)(KHwBaseEthernet + 0x48); |
|
50 const TUint32 SMCS9118_TX_STATUS_PEEK = (TUint32)(KHwBaseEthernet + 0x4c); |
|
51 |
|
52 // |
|
53 // SMSC9118 System Control and Status Registers - see datasheet section 5.3 |
|
54 // |
|
55 const TUint32 SMCS9118_ID_REV = (TUint32)(KHwBaseEthernet + 0x50); |
|
56 const TUint32 SMCS9118_IRQ_CFG = (TUint32)(KHwBaseEthernet + 0x54); |
|
57 const TUint32 SMCS9118_INT_STS = (TUint32)(KHwBaseEthernet + 0x58); |
|
58 const TUint32 SMCS9118_INT_EN = (TUint32)(KHwBaseEthernet + 0x5c); |
|
59 const TUint32 SMCS9118_BYTE_TEST = (TUint32)(KHwBaseEthernet + 0x64); |
|
60 const TUint32 SMCS9118_FIFO_INT = (TUint32)(KHwBaseEthernet + 0x68); |
|
61 const TUint32 SMCS9118_RX_CFG = (TUint32)(KHwBaseEthernet + 0x6c); |
|
62 const TUint32 SMCS9118_TX_CFG = (TUint32)(KHwBaseEthernet + 0x70); |
|
63 const TUint32 SMCS9118_HW_CFG = (TUint32)(KHwBaseEthernet + 0x74); |
|
64 const TUint32 SMCS9118_RX_DP_CTL = (TUint32)(KHwBaseEthernet + 0x78); |
|
65 const TUint32 SMCS9118_RX_FIFO_INF = (TUint32)(KHwBaseEthernet + 0x7c); |
|
66 const TUint32 SMCS9118_TX_FIFO_INF = (TUint32)(KHwBaseEthernet + 0x80); |
|
67 const TUint32 SMCS9118_PMT_CTRL = (TUint32)(KHwBaseEthernet + 0x84); |
|
68 const TUint32 SMCS9118_GPIO_CFG = (TUint32)(KHwBaseEthernet + 0x88); |
|
69 const TUint32 SMCS9118_GPT_CFG = (TUint32)(KHwBaseEthernet + 0x8c); |
|
70 const TUint32 SMCS9118_GPT_CNT = (TUint32)(KHwBaseEthernet + 0x90); |
|
71 const TUint32 SMCS9118_WORDSWAP = (TUint32)(KHwBaseEthernet + 0x98); |
|
72 const TUint32 SMCS9118_FREE_RUN = (TUint32)(KHwBaseEthernet + 0x9c); |
|
73 const TUint32 SMCS9118_RX_DROP = (TUint32)(KHwBaseEthernet + 0xa0); |
|
74 const TUint32 SMCS9118_MAC_CSR_CMD = (TUint32)(KHwBaseEthernet + 0xa4); |
|
75 const TUint32 SMCS9118_MAC_CSR_DATA = (TUint32)(KHwBaseEthernet + 0xa8); |
|
76 const TUint32 SMCS9118_AFC_CFG = (TUint32)(KHwBaseEthernet + 0xac); |
|
77 const TUint32 SMCS9118_E2P_CMD = (TUint32)(KHwBaseEthernet + 0xb0); |
|
78 const TUint32 SMCS9118_E2P_DATA = (TUint32)(KHwBaseEthernet + 0xb0); |
|
79 |
|
80 // |
|
81 // SMCS9118 MAC CSR register map - see datasheet section 5.4 |
|
82 // |
|
83 const TUint32 SMCS9118_MAC_CR = 0x01; |
|
84 const TUint32 SMCS9118_MAC_ADDRH = 0x02; |
|
85 const TUint32 SMCS9118_MAC_ADDRL = 0x03; |
|
86 const TUint32 SMCS9118_MAC_MII_ACC = 0x06; |
|
87 const TUint32 SMCS9118_MAC_MII_DATA = 0x07; |
|
88 const TUint32 SMCS9118_MAC_FLOW = 0x08; |
|
89 const TUint32 SMCS9118_MAC_VLAN1 = 0x09; |
|
90 const TUint32 SMCS9118_MAC_VLAN2 = 0x0a; |
|
91 const TUint32 SMCS9118_MAC_WUFF = 0x0b; |
|
92 const TUint32 SMCS9118_MAC_WUCSR = 0x0c; |
|
93 |
|
94 // |
|
95 // SMCS9118 PHY control and status registers - see datasheet section 5.5 |
|
96 // |
|
97 const TUint32 SMCS9118_PHY_BCR = 0x00; |
|
98 const TUint32 SMCS9118_PHY_BSR = 0x01; |
|
99 const TUint32 SMCS9118_PHY_ID1 = 0x02; |
|
100 const TUint32 SMCS9118_PHY_ID2 = 0x03; |
|
101 const TUint32 SMCS9118_PHY_AUTONEG_AD = 0x04; |
|
102 const TUint32 SMCS9118_PHY_AUTONEG_LPAR = 0x05; |
|
103 const TUint32 SMCS9118_PHY_AUTONEG_ER = 0x06; |
|
104 const TUint32 SMCS9118_PHY_MCSR = 0x11; |
|
105 const TUint32 SMCS9118_PHY_SMR = 0x12; |
|
106 const TUint32 SMCS9118_PHY_SCSI = 0x1b; |
|
107 const TUint32 SMCS9118_PHY_ISR = 0x1d; |
|
108 const TUint32 SMCS9118_PHY_IMR = 0x1e; |
|
109 const TUint32 SMCS9118_PHY_SCSR = 0x1f; |
|
110 |
|
111 // |
|
112 // SMCS9118 system register values - see datasheet section 3.12.2 |
|
113 // |
|
114 const TUint32 SMCS9118_TX_FIRSTSEG = 0x00002000; // |
|
115 const TUint32 SMCS9118_TX_LASTSEG = 0x00001000; // |
|
116 |
|
117 const TUint32 SMCS9118_RX_ES = 0x00008000; // RX Error Status - see datasheet section 3.13.3 |
|
118 |
|
119 const TUint32 SMCS9118_ID_VAL = 0x01180000; // Chip ID = 0x0118 |
|
120 const TUint32 SMCS9118_ID_MASK = 0xffff0000; // chip id is top 16bits |
|
121 const TUint32 SMCS9118_REV_MASK = 0x0000ffff; // chip revision is bottom 16bits |
|
122 |
|
123 // IRQ_CFG values - see datasheet section 5.3.2 |
|
124 const TUint32 SMCS9118_IRQ_CFG_DEAS = 0x16000000; // Interupt deassert interval |
|
125 const TUint32 SMCS9118_IRQ_CFG_TYPE = 0x00000111; // IRQ_TYPE active low, push-pull |
|
126 |
|
127 // INT_STS values - see datasheet section 5.3.3 |
|
128 const TUint32 SMCS9118_INT_STS_RSFL = 0x00000008; // RX Status FIFO Level Int |
|
129 const TUint32 SMCS9118_RXSTOP_INT = 0x00100000; // RX Status FIFO Level Int |
|
130 const TUint32 SMCS9118_INT_STS_TXE = 0x00002000; // TX error |
|
131 const TUint32 SMCS9118_INT_STS_TX = 0x02212f80; // |
|
132 |
|
133 // INT_EN values - see datasheet section 5.3.4 |
|
134 const TUint32 SMCS9118_INT_EN_RSFL = 0x00000008; // RX Status FIFO Level Int |
|
135 |
|
136 // RX_CFG - see datasheet section 5.3.7 |
|
137 const TUint32 SMCS9118_RX_DUMP = 0x00008000; // RX dump whole FIFO |
|
138 |
|
139 // TX_CFG - see datasheet section 5.3.8 |
|
140 const TUint32 SMCS9118_TX_CFG_TXSAO = 0x00000004; // TX Status allow overrun |
|
141 const TUint32 SMCS9118_TX_CFG_TX_ON = 0x00000002; // TX ON |
|
142 |
|
143 // HW_CFG - see datasheet section 5.3.9 |
|
144 const TUint32 SMCS9118_HW_CFG_SRST = 0x00000001; // Software Reset Time-out |
|
145 const TUint32 SMCS9118_HW_CFG_SF = 0x00100000; // SF - Store and forward |
|
146 |
|
147 // TX FIFO Allocations - see datasheet section 5.3.9.1 |
|
148 const TUint32 SMCS9118_TX_FIFO_SZ = 0x03<<16; // bits 16:19 determine FIFO size |
|
149 const TUint32 SMCS9118_TX_PKT_TAG = 0xabcd0000; |
|
150 |
|
151 // RX FIFO - see datasheet section 5.3.10/5.3.11 |
|
152 const TUint32 SMCS9118_RX_DP_FFWD = 0x80000000; // RX Data FIFO Fast Forward |
|
153 const TUint32 SMCS9118_RX_LEN_MASK = 0x0000ffff; |
|
154 const TUint32 SMCS9118_RX_LEN_SHIFT = 0x10; |
|
155 |
|
156 // TX FIFO - see datasheet section 5.3.12 |
|
157 const TUint32 SMCS9118_TX_SPACE_MASK = 0x0000ffff; |
|
158 const TUint32 SMCS9118_TX_USED_MASK = 0x00ff0000; |
|
159 |
|
160 // PMT_CTRL - see datasheet section 5.3.13 |
|
161 const TUint32 SMCS9118_PMT_PHY_RST = 0x00000400; // Physical reset |
|
162 const TUint32 SMCS9118_PMT_READY = 0x00000001; // Device ready |
|
163 const TUint32 SMCS9118_PM_MODE_D1 = 0x00001000; // D1 Sleep |
|
164 const TUint32 SMCS9118_PM_MODE_D2 = 0x00002000; // D2 Sleep |
|
165 |
|
166 // GPIO_CFG - - see datasheet section 5.3.14 |
|
167 const TUint32 SMCS9118_GPIO_LED_EN = 0x70000000; // LED on |
|
168 const TUint32 SMCS9118_GPIO_GPIOBUF = 0x00070000; // GPIO Buffer Type |
|
169 |
|
170 // MAC_CSR_CMD - see datasheet section 5.3.20 |
|
171 const TUint32 SMCS9118_MAC_CSR_BUSY = 0x80000000; |
|
172 const TUint32 SMCS9118_MAC_CSR_READ = 0x40000000; |
|
173 |
|
174 // Auto Flow Control Config Register - see datasheet section 5.3.22 |
|
175 // BACK_DUR = 4 |
|
176 // AFC_LO = 0x37 |
|
177 // AFC_HI = 0x6e |
|
178 const TUint32 SMCS9118_AFC_CFG_VAL = 0x006e3740; |
|
179 |
|
180 // EEPROM Command Register - see datasheet section 5.3.23 |
|
181 const TUint32 SMCS9118_E2P_CMD_BUSY = 0x80000000; |
|
182 |
|
183 // SMCS9118 MAC control register values - see datasheet section 5.4.1 |
|
184 const TUint32 SMCS9118_MAC_RXALL = 0x80000000; |
|
185 const TUint32 SMCS9118_MAC_TXEN = 0x00000008; |
|
186 const TUint32 SMCS9118_MAC_RXEN = 0x00000004; |
|
187 |
|
188 // SMCS9118 MII access register values - see datasheet section 5.4.6 |
|
189 const TUint32 SMCS9118_PHY_ADDR = 0x00000800; |
|
190 const TUint32 SMCS9118_MII_WRITE = 0x00000002; |
|
191 const TUint32 SMCS9118_MII_BUSY = 0x00000001; |
|
192 |
|
193 |
|
194 // SMCS9118 PHY Basic Control register values - see datasheet section 5.5.1 |
|
195 const TUint32 SMCS9118_PHY_ANEG_EN = 0x00001000; // Auto negotiate enable |
|
196 const TUint32 SMCS9118_PHY_ANEG_RESTART = 0x00000200; // Auto negotiate restart |
|
197 |
|
198 // SMCS9118 PHY Basic Status register values - see datasheet section 5.5.2 |
|
199 const TUint32 SMCS9118_PHY_ANEG_CMPL = 0x00000020; // Auto negotiate complete |
|
200 |
|
201 // SMCS9118 PHY auto negotiate advertisement values - see datasheet section 5.5.5 |
|
202 const TUint32 SMCS9118_PHY_10BT = 0x00000020; |
|
203 const TUint32 SMCS9118_PHY_10BTFD = 0x00000040; |
|
204 const TUint32 SMCS9118_PHY_100BTX = 0x00000080; |
|
205 const TUint32 SMCS9118_PHY_100BTXFD = 0x00000100; |
|
206 const TUint32 SMCS9118_PHY_PAUSE = 0x00000C00; |
|
207 const TUint32 SMCS9118_PHY_DEF_ANEG = SMCS9118_PHY_10BT | |
|
208 SMCS9118_PHY_10BTFD | |
|
209 SMCS9118_PHY_100BTX | |
|
210 SMCS9118_PHY_100BTXFD | |
|
211 SMCS9118_PHY_PAUSE; |
|
212 |
|
213 const TUint32 KEthernetInterruptId = KGpio_Ethernet_Int_Pin; |
|
214 |
|
215 const TUint32 SMCS9118_LOCK_ORDER = 0x03u; |
|
216 |
|
217 // |
|
218 |
|
219 class DEthernetPddFactory : public DPhysicalDevice |
|
220 /** |
|
221 Ethernet PDD factory class |
|
222 */ |
|
223 { |
|
224 public: |
|
225 DEthernetPddFactory(); |
|
226 |
|
227 virtual TInt Install(); |
|
228 virtual void GetCaps(TDes8& aDes) const; |
|
229 virtual TInt Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer); |
|
230 virtual TInt Validate(TInt aUnit, const TDesC8* aInfo, const TVersion& aVer); |
|
231 }; //DEthernetPddFactory |
|
232 |
|
233 |
|
234 |
|
235 |
|
236 class DEthernetSMCS9118Pdd : public DEthernetPdd |
|
237 /** |
|
238 Ethernet PDD class. |
|
239 */ |
|
240 { |
|
241 public: |
|
242 DEthernetSMCS9118Pdd(); |
|
243 ~DEthernetSMCS9118Pdd(); |
|
244 |
|
245 static void Isr(TAny* aPtr); |
|
246 |
|
247 /** |
|
248 * Stop receiving frames |
|
249 * @param aMode The stop mode |
|
250 */ |
|
251 void Stop(TStopMode aMode); |
|
252 |
|
253 /** |
|
254 * Configure the device |
|
255 * Reconfigure the device using the new configuration supplied. |
|
256 * This should not change the MAC address. |
|
257 * @param aConfig The new configuration |
|
258 * @see ValidateConfig() |
|
259 * @see MacConfigure() |
|
260 */ |
|
261 TInt Configure(TEthernetConfigV01 &aConfig) ; |
|
262 /** |
|
263 * Change the MAC address |
|
264 * Attempt to change the MAC address of the device |
|
265 * @param aConfig A Configuration containing the new MAC |
|
266 * @see Configure() |
|
267 */ |
|
268 void MacConfigure(TEthernetConfigV01 &aConfig) ; |
|
269 |
|
270 /** |
|
271 * Transmit data |
|
272 * @param aBuffer referance to the data to be sent |
|
273 * @return KErrNone if the data has been sent |
|
274 */ |
|
275 TInt Send(TBuf8<KMaxEthernetPacket+32> &aBuffer) ; |
|
276 /** |
|
277 * Retrieve data from the device |
|
278 * Pull the received data out of the device and into the supplied buffer. |
|
279 * Need to be told if the buffer is OK to use as if it not we could dump |
|
280 * the waiting frame in order to clear the interrupt if necessory. |
|
281 * @param aBuffer Referance to the buffer to be used to store the data in |
|
282 * @param okToUse Bool to indicate if the buffer is usable |
|
283 * @return KErrNone if the buffer has been filled. |
|
284 */ |
|
285 TInt ReceiveFrame(TBuf8<KMaxEthernetPacket+32> &aBuffer, |
|
286 TBool okToUse) ; |
|
287 |
|
288 TInt DoCreate(); |
|
289 |
|
290 /** |
|
291 * Put the card to sleep |
|
292 */ |
|
293 |
|
294 void Sleep(); |
|
295 /** |
|
296 * Wake the card up |
|
297 */ |
|
298 TInt Wakeup(); |
|
299 |
|
300 protected: |
|
301 /** |
|
302 * Discard a frame |
|
303 */ |
|
304 TInt DiscardFrame(); |
|
305 |
|
306 static void ServiceRxDfc(TAny *aPtr); |
|
307 |
|
308 /** |
|
309 * Does the soft reset of the lan card |
|
310 */ |
|
311 TInt CardSoftReset(); |
|
312 |
|
313 inline TInt32 IsReady(); |
|
314 /** |
|
315 * see data sheet section 6.1, Host Interface Timing |
|
316 * "dummy" reads of the BYTE_TEST register will |
|
317 * guarantee the minimum write-to-read timing restrictions |
|
318 * as listed in Table 6.1 |
|
319 */ |
|
320 inline void ByteTestDelay(TUint32 aCount); |
|
321 |
|
322 /** |
|
323 * Read/Write the MAC registers |
|
324 */ |
|
325 TInt32 ReadMac(TUint32 aReg, TUint32 &aVal); |
|
326 TInt32 WriteMac(TUint32 aReg, TUint32 aVal); |
|
327 |
|
328 /** |
|
329 * Read/Write the PHY registers |
|
330 */ |
|
331 TInt32 ReadPhy(TUint32 aReg, TUint32 &aVal); |
|
332 TInt32 WritePhy(TUint32 aReg, TUint32 aVal); |
|
333 |
|
334 /** |
|
335 * Read a 32bit register |
|
336 */ |
|
337 inline TUint32 Read32(TUint32 aReg); |
|
338 |
|
339 /** |
|
340 * Write a 32bit register |
|
341 */ |
|
342 inline void Write32(TUint32 aReg, TUint32 aVal); |
|
343 |
|
344 /** |
|
345 * Interrupt handling |
|
346 */ |
|
347 inline void ClearInterrupt(TInt aId); |
|
348 inline void UnbindInterrupt(TInt aId); |
|
349 inline TInt BindInterrupt(TInt aId, TGpioIsr aIsr, TAny *aPtr); |
|
350 inline TInt EnableInterrupt(TInt aId); |
|
351 inline TInt DisableInterrupt(TInt aId); |
|
352 |
|
353 /** |
|
354 * lock handling |
|
355 */ |
|
356 inline TInt DriverLock(); |
|
357 inline void DriverUnlock(TInt); |
|
358 |
|
359 protected: |
|
360 TDfc iRxDfc; |
|
361 #ifdef __SMP__ |
|
362 TSpinLock *iDriverLock; |
|
363 #endif |
|
364 }; |
|
365 |
|
366 #include "smcs9118_ethernet.inl" |
|
367 |
|
368 /** @} */ |
|
369 |
|
370 #endif //__SMCS9118_ETHERNET_H__ |