navienginebsp/ne1_tb/ethernet/smcs9118_ethernet.cpp
changeset 0 5de814552237
equal deleted inserted replaced
-1:000000000000 0:5de814552237
       
     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\shared_ethernet.h
       
    16 * SMCS 9118 Ethernet driver implementation.
       
    17 *
       
    18 */
       
    19 
       
    20 
       
    21 
       
    22 #include "variant.h"
       
    23 #include "smcs9118_ethernet.h"
       
    24 
       
    25 const TUint32 ONE_MSEC				= 1000; // in nanoseconds
       
    26 const TUint32 TWO_SECONDS			= 2000; // in milliseconds
       
    27 const TUint32 SMCS9118_MAC_TIMEOUT	= 50;
       
    28 const TUint32 SMCS9118_MAX_RETRIES	= 100;
       
    29 
       
    30  
       
    31 DEthernetPddFactory::DEthernetPddFactory()
       
    32 	{
       
    33 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    34 	KPROFILE_PRINT("DEthernetPddFactory::DEthernetPddFactory()");
       
    35 	#endif
       
    36 	iVersion=TVersion(KEthernetMajorVersionNumber,
       
    37 			KEthernetMinorVersionNumber,
       
    38 			KEthernetBuildVersionNumber);
       
    39 	}
       
    40 
       
    41 TInt DEthernetPddFactory::Install()
       
    42 	{
       
    43 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    44 	KPROFILE_PRINT("DEthernetPddFactory::Install()");
       
    45 	#endif
       
    46 	return SetName(&KEthernetPddName);
       
    47 	}
       
    48 
       
    49 void DEthernetPddFactory::GetCaps(TDes8& /*aDes*/) const
       
    50 /*
       
    51  * Return the drivers capabilities.
       
    52  */
       
    53 	{
       
    54 	}
       
    55 
       
    56 
       
    57 TInt DEthernetPddFactory::Create(DBase*& aChannel, TInt aUnit, const TDesC8* aInfo, const TVersion& aVer)
       
    58 /*
       
    59  * Create a Driver for the device.
       
    60  */
       
    61 	{
       
    62 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    63 	KPROFILE_PRINT("DEthernetPddFactory::Create()");
       
    64 	#endif
       
    65 	TInt r = Validate(aUnit, aInfo, aVer);
       
    66 	if (r != KErrNone)
       
    67 		{
       
    68 		return r;
       
    69 		}
       
    70 	DEthernetPdd* pP = new DEthernetSMCS9118Pdd;
       
    71 	aChannel = pP;
       
    72 	if (!pP)
       
    73 		{
       
    74 		return KErrNoMemory;
       
    75 		}
       
    76 	r = pP->DoCreate();
       
    77 	return r;
       
    78 	}
       
    79 
       
    80 TInt DEthernetPddFactory::Validate(TInt /*aUnit*/, const TDesC8* /*aInfo*/, const TVersion& aVer)
       
    81 /*
       
    82  *  Validate the requested configuration
       
    83  */
       
    84 	{
       
    85 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
    86 	KPROFILE_PRINT("DEthernetPddFactory::Validate()");
       
    87 	#endif
       
    88 
       
    89 	if (!Kern::QueryVersionSupported(iVersion,aVer))
       
    90 		{
       
    91 		return KErrNotSupported;
       
    92 		}
       
    93 
       
    94 	return KErrNone;
       
    95 	}
       
    96 
       
    97 #ifdef __SMP__
       
    98 TSpinLock DEthernetSMCS9118PddLock(SMCS9118_LOCK_ORDER);
       
    99 #endif
       
   100 DEthernetSMCS9118Pdd::DEthernetSMCS9118Pdd()
       
   101 //Constructor
       
   102 	 :iRxDfc(ServiceRxDfc, this, 1)
       
   103 	{
       
   104 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   105     KPROFILE_PRINT("DEthernetSMCS9118Pdd::DEthernetSMCS9118Pdd()");	
       
   106     #endif
       
   107 
       
   108 #ifdef __SMP__
       
   109 	iDriverLock = &DEthernetSMCS9118PddLock;
       
   110 #endif
       
   111 	iReady = EFalse;
       
   112 	}
       
   113 
       
   114 DEthernetSMCS9118Pdd::~DEthernetSMCS9118Pdd()
       
   115 //Destructor
       
   116 	{
       
   117 
       
   118 	//cancel any pending DFC requests
       
   119 	iRxDfc.Cancel();
       
   120 	
       
   121 	// UnRegister the power handler with Symbian Power Framework
       
   122 	iPowerHandler.RelinquishPower();
       
   123 	iPowerHandler.Remove();
       
   124 
       
   125 	// UnRegister interrupts
       
   126 	DisableInterrupt(iInterruptId);
       
   127 	UnbindInterrupt(iInterruptId);
       
   128 
       
   129 	if (iDfcQ)
       
   130 		iDfcQ->Destroy();
       
   131 	}
       
   132 
       
   133 void DEthernetSMCS9118Pdd::Stop(TStopMode aMode)
       
   134 /**
       
   135  * Stop receiving frames
       
   136  * @param aMode The stop mode
       
   137  */
       
   138 	{
       
   139 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   140 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::Stop()");
       
   141 	#endif
       
   142 
       
   143 	switch (aMode)
       
   144 		{
       
   145 	case EStopNormal:
       
   146 	case EStopEmergency:
       
   147 		iReady = EFalse;
       
   148 		iRxDfc.Cancel();
       
   149 		// disable Rx, Tx
       
   150 		TUint32 status;
       
   151 		TInt32 err = ReadMac(SMCS9118_MAC_CR, status);
       
   152 		status &= ~(SMCS9118_MAC_RXEN | SMCS9118_MAC_TXEN | SMCS9118_MAC_RXALL);
       
   153 		err = WriteMac(SMCS9118_MAC_CR, status);
       
   154 		// clear any pending interrupts
       
   155 		Write32(SMCS9118_INT_EN, 0);
       
   156 		ByteTestDelay(1);
       
   157 		ClearInterrupt(iInterruptId);
       
   158 		// turn off the LED
       
   159 		status = Read32(SMCS9118_GPIO_CFG) & ~SMCS9118_GPIO_LED_EN;
       
   160 		Write32(SMCS9118_GPIO_CFG, status);
       
   161 		ByteTestDelay(1);
       
   162 
       
   163 		break;
       
   164 		}
       
   165 	}
       
   166 
       
   167 TInt DEthernetSMCS9118Pdd::Configure(TEthernetConfigV01& /*aConfig*/)
       
   168 /**
       
   169  * Configure the device
       
   170  * Reconfigure the device using the new configuration supplied.
       
   171  * This should not change the MAC address.
       
   172  * @param aConfig The new configuration
       
   173  * @see ValidateConfig()
       
   174  * @see MacConfigure()
       
   175  * assume iDriverLock not held
       
   176  */
       
   177 	{
       
   178 	TUint32 retry;
       
   179 	TUint32 status;
       
   180 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   181     KPROFILE_PRINT("DEthernetSMCS9118Pdd::Configure()");
       
   182     #endif
       
   183 
       
   184   	if ((status = CardSoftReset()) != (TUint32)KErrNone)
       
   185 		{
       
   186 		return status;
       
   187 		}
       
   188 
       
   189 	TInt irq = DriverLock();
       
   190 	// disable chip interrupts
       
   191 	Write32(SMCS9118_INT_EN, 0);
       
   192 	ByteTestDelay(1);
       
   193 	Write32(SMCS9118_INT_STS, 0xffffffff);
       
   194 	ByteTestDelay(2);
       
   195 	Write32(SMCS9118_FIFO_INT, 0);
       
   196 	ByteTestDelay(1);
       
   197 	Write32(SMCS9118_IRQ_CFG, SMCS9118_IRQ_CFG_DEAS|SMCS9118_IRQ_CFG_TYPE);
       
   198 	ByteTestDelay(3);
       
   199 
       
   200 	// AutoFlowControl setup
       
   201 	Write32(SMCS9118_AFC_CFG, SMCS9118_AFC_CFG_VAL);
       
   202 	ByteTestDelay(1);
       
   203 
       
   204 	// TX FIFO setup
       
   205 	status = Read32(SMCS9118_HW_CFG);
       
   206 	status |= SMCS9118_TX_FIFO_SZ; 
       
   207 	Write32(SMCS9118_HW_CFG, status);
       
   208 	ByteTestDelay(1);
       
   209 
       
   210 	// wait for EEPROM load
       
   211 	retry = SMCS9118_MAX_RETRIES;
       
   212 	do
       
   213 		{
       
   214 		status = Read32(SMCS9118_E2P_CMD);
       
   215 		if (!(status & SMCS9118_E2P_CMD_BUSY))
       
   216 			{
       
   217 			break;
       
   218 			}
       
   219 		Kern::NanoWait(ONE_MSEC);
       
   220 		} while (--retry);
       
   221 	if (retry == 0)
       
   222 		{
       
   223 		DriverUnlock(irq);
       
   224 		return KErrGeneral;
       
   225 		}
       
   226 
       
   227 	// GPIO setup - turn on the LED !
       
   228 	Write32(SMCS9118_GPIO_CFG, SMCS9118_GPIO_GPIOBUF|SMCS9118_GPIO_LED_EN);
       
   229 	ByteTestDelay(1);
       
   230 	
       
   231 	// PHY reset
       
   232 	status = Read32(SMCS9118_PMT_CTRL);
       
   233 	status |= SMCS9118_PMT_PHY_RST; 
       
   234 	Write32(SMCS9118_PMT_CTRL, status);
       
   235 	ByteTestDelay(7);
       
   236 	retry = SMCS9118_MAX_RETRIES;
       
   237 	do
       
   238 		{
       
   239 		status = Read32(SMCS9118_PMT_CTRL);
       
   240 		if (!(status & SMCS9118_PMT_PHY_RST))
       
   241 			{
       
   242 			break;
       
   243 			}
       
   244 		Kern::NanoWait(ONE_MSEC);
       
   245 		} while (--retry);
       
   246 	if (retry == 0)
       
   247 		{
       
   248 		DriverUnlock(irq);
       
   249 		return KErrGeneral;
       
   250 		}
       
   251 	ByteTestDelay(1);
       
   252 
       
   253 	// Auto negotiate setup
       
   254 	TInt32 err = ReadPhy(SMCS9118_PHY_AUTONEG_AD, status);
       
   255 	if (err != KErrNone)
       
   256 		{
       
   257 		DriverUnlock(irq);
       
   258 		return err;
       
   259 		}
       
   260 	status |= SMCS9118_PHY_DEF_ANEG;
       
   261 	err = WritePhy(SMCS9118_PHY_AUTONEG_AD, status);
       
   262 	if (err != KErrNone)
       
   263 		{
       
   264 		DriverUnlock(irq);
       
   265 		return err;
       
   266 		}
       
   267 
       
   268 	err = ReadPhy(SMCS9118_PHY_AUTONEG_AD, status);
       
   269 	if (err != KErrNone)
       
   270 		{
       
   271 		DriverUnlock(irq);
       
   272 		return err;
       
   273 		}
       
   274 
       
   275 	err = ReadPhy(SMCS9118_PHY_BCR, status);
       
   276 	if (err != KErrNone)
       
   277 		{
       
   278 		DriverUnlock(irq);
       
   279 		return err;
       
   280 		}
       
   281 	status |= (SMCS9118_PHY_ANEG_RESTART|SMCS9118_PHY_ANEG_EN);
       
   282 	err = WritePhy(SMCS9118_PHY_BCR, status);
       
   283 	if (err != KErrNone)
       
   284 		{
       
   285 		DriverUnlock(irq);
       
   286 		return err;
       
   287 		}
       
   288 
       
   289 	// wait for auto negotiation
       
   290 	DriverUnlock(irq);
       
   291 	NKern::Sleep(TWO_SECONDS);
       
   292 	irq = DriverLock();
       
   293 
       
   294 	err = ReadPhy(SMCS9118_PHY_BSR, status);
       
   295 	if (err != KErrNone)
       
   296 		{
       
   297 		DriverUnlock(irq);
       
   298 		return err;
       
   299 		}
       
   300 	if (!(status & SMCS9118_PHY_ANEG_CMPL))
       
   301 		{
       
   302 		DriverUnlock(irq);
       
   303 		return KErrGeneral;
       
   304 		}
       
   305 
       
   306 	// update the config based on what we negotiated
       
   307 	if (status & (SMCS9118_PHY_100BTX|SMCS9118_PHY_100BTXFD))
       
   308 		{
       
   309 		iDefaultConfig.iEthSpeed  = KEthSpeed100BaseTX;
       
   310 		}
       
   311 	if (status & (SMCS9118_PHY_10BTFD|SMCS9118_PHY_100BTXFD))
       
   312 		{
       
   313 		iDefaultConfig.iEthDuplex = KEthDuplexFull;
       
   314 		}
       
   315 
       
   316 	// setup store + forward
       
   317 	status = Read32(SMCS9118_HW_CFG);
       
   318 	status |= SMCS9118_HW_CFG_SF; 
       
   319 	Write32(SMCS9118_HW_CFG, status);
       
   320 	ByteTestDelay(1);
       
   321 
       
   322 	// setup Tx and Rx
       
   323 	Write32(SMCS9118_TX_CFG, SMCS9118_TX_CFG_TXSAO|SMCS9118_TX_CFG_TX_ON);
       
   324 	ByteTestDelay(1);
       
   325 
       
   326 	TInt r;
       
   327 	r = WriteMac(SMCS9118_MAC_CR, SMCS9118_MAC_RXEN|SMCS9118_MAC_TXEN|SMCS9118_MAC_RXALL);
       
   328 	if (r != KErrNone)
       
   329 		{
       
   330 		DriverUnlock(irq);
       
   331 		return r;
       
   332 		}
       
   333 
       
   334 	// Enable interrupts to CPU
       
   335     r = EnableInterrupt(iInterruptId);
       
   336     if(r != KErrNone)
       
   337 		{
       
   338 		TInt err;
       
   339     	__KTRACE_OPT(KHARDWARE,Kern::Printf("DEthernetSMSC9118Pdd::Start --- Interrupt::Enable()=%d", r));
       
   340     	
       
   341     	// Disable TX, RX and exit
       
   342 		status &= ~(SMCS9118_MAC_RXEN | SMCS9118_MAC_TXEN | SMCS9118_MAC_RXALL);
       
   343 		err = WriteMac(SMCS9118_MAC_CR, status);
       
   344 		if (err != KErrNone)
       
   345 			{
       
   346 			DriverUnlock(irq);
       
   347 			return err;
       
   348 			}
       
   349 
       
   350 		DriverUnlock(irq);
       
   351 		return r;
       
   352 		}
       
   353     
       
   354 	// Rx Interrupt
       
   355 	Write32(SMCS9118_INT_EN, SMCS9118_INT_EN_RSFL);
       
   356 	ByteTestDelay(1);
       
   357 
       
   358 	DriverUnlock(irq);
       
   359 	return KErrNone;
       
   360 	}
       
   361 
       
   362 
       
   363 void DEthernetSMCS9118Pdd::MacConfigure(TEthernetConfigV01& aConfig)
       
   364 /**
       
   365  * Change the MAC address
       
   366  * Attempt to change the MAC address of the device
       
   367  * @param aConfig A Configuration containing the new MAC
       
   368  * @see Configure()
       
   369  * assume iDriverLock not held
       
   370  */
       
   371 	{
       
   372 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   373     KPROFILE_PRINT("DEthernetSMCS9118Pdd::MacConfigure()");
       
   374     #endif
       
   375 
       
   376 
       
   377 	TUint32 mac, checkMac;
       
   378 	TInt	err;
       
   379 	
       
   380 	TInt irq = DriverLock();
       
   381 	mac = aConfig.iEthAddress[0];
       
   382 	mac |= aConfig.iEthAddress[1]<<8;
       
   383 	mac |= aConfig.iEthAddress[2]<<16;
       
   384 	mac |= aConfig.iEthAddress[3]<<24;
       
   385 
       
   386 	err = WriteMac(SMCS9118_MAC_ADDRL, mac);
       
   387 	if (err)
       
   388 		{
       
   389 		__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetSMCS9118Pdd::MacConfigure() -- Failed to set MAC Address"));
       
   390 		DriverUnlock(irq);
       
   391 		return;
       
   392 		}
       
   393 	err = ReadMac(SMCS9118_MAC_ADDRL, checkMac);
       
   394 	if (err || checkMac != mac)
       
   395 		{
       
   396 		__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetSMCS9118Pdd::MacConfigure() -- Failed to set MAC Address"));
       
   397 		DriverUnlock(irq);
       
   398 		return;
       
   399 		}
       
   400 	
       
   401 	mac = aConfig.iEthAddress[4];
       
   402 	mac |= aConfig.iEthAddress[5]<<8;
       
   403 	err = WriteMac(SMCS9118_MAC_ADDRH, mac);
       
   404 	if (err)
       
   405 		{
       
   406 		__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetSMCS9118Pdd::MacConfigure() -- Failed to set MAC Address"));
       
   407 		DriverUnlock(irq);
       
   408 		return;
       
   409 		}
       
   410 	err = ReadMac(SMCS9118_MAC_ADDRH, checkMac);
       
   411 	if (err || checkMac != mac)
       
   412 		{
       
   413 		__KTRACE_OPT(KHARDWARE, Kern::Printf("DEthernetSMCS9118Pdd::MacConfigure() -- Failed to set MAC Address"));
       
   414 		DriverUnlock(irq);
       
   415 		return;
       
   416 		}
       
   417 	
       
   418 	for (TInt i=0; i<=5; i++)
       
   419 		{
       
   420 		iDefaultConfig.iEthAddress[i] = aConfig.iEthAddress[i];
       
   421 		}
       
   422 
       
   423 	__KTRACE_OPT(KHARDWARE, Kern::Printf("-- MAC address %2x.%2x.%2x.%2x.%2x.%2x",
       
   424 				iDefaultConfig.iEthAddress[0], iDefaultConfig.iEthAddress[1],
       
   425 				iDefaultConfig.iEthAddress[2], iDefaultConfig.iEthAddress[3],
       
   426 				iDefaultConfig.iEthAddress[4], iDefaultConfig.iEthAddress[5]));
       
   427 
       
   428 	DriverUnlock(irq);
       
   429 	return;
       
   430 	}
       
   431 
       
   432 
       
   433 TInt DEthernetSMCS9118Pdd::Send(TBuf8<KMaxEthernetPacket+32>& aBuffer)
       
   434 /**
       
   435  * Transmit data
       
   436  * @param aBuffer reference to the data to be sent
       
   437  * @return KErrNone if the data has been sent
       
   438  * assume iDriverLock not held
       
   439  */
       
   440 	{
       
   441 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   442     KPROFILE_PRINT("DEthernetSMCS9118Pdd::Send()");
       
   443     #endif
       
   444 
       
   445     // Always request for power
       
   446     iPowerHandler.RequestPower();
       
   447 	TUint32* dataP = (TUint32 *)aBuffer.Ptr();
       
   448 	TUint32 length = aBuffer.Length();
       
   449 
       
   450 	TInt irq = DriverLock();
       
   451 	// can it fit
       
   452 	TUint32 status = Read32(SMCS9118_TX_FIFO_INF);
       
   453 	if ((status & SMCS9118_TX_SPACE_MASK) < length)
       
   454 		{
       
   455 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   456 		KPROFILE_PRINT("eth -- Error... Send KErrSMCS9118TxOutOfMenory");
       
   457 		#endif
       
   458 		DriverUnlock(irq);
       
   459 		return KErrTxOutOfMemory;
       
   460 		}
       
   461 
       
   462 	status = (length & 0x7ff) | SMCS9118_TX_FIRSTSEG | SMCS9118_TX_LASTSEG;
       
   463 	Write32(SMCS9118_TX_DATA_FIFO, status);
       
   464 	status = (length & 0x7ff) | SMCS9118_TX_PKT_TAG;
       
   465 	Write32(SMCS9118_TX_DATA_FIFO, status);
       
   466 
       
   467 	// calculate number of full words + remaining bytes
       
   468 	
       
   469 	TUint32 words = length >> 2;
       
   470 	TUint32 bytes = length & 3;
       
   471 
       
   472 	// write words
       
   473 	while (words--)
       
   474 		{
       
   475 		Write32(SMCS9118_TX_DATA_FIFO, *dataP++);
       
   476 		}
       
   477 	
       
   478 	// write bytes
       
   479 	if (bytes)
       
   480 		{
       
   481 		TUint8 *dataBytes = (TUint8*) dataP;
       
   482 		status = 0;
       
   483 		switch (bytes)
       
   484 			{
       
   485 			case 3:
       
   486 				status |= dataBytes[2] << 16;
       
   487 				// fallthrough
       
   488 			case 2:
       
   489 				status |= dataBytes[1] << 8;
       
   490 				// fallthrough
       
   491 			case 1:
       
   492 				status |= dataBytes[0];
       
   493 			}
       
   494 		Write32(SMCS9118_TX_DATA_FIFO, status);
       
   495 		}
       
   496 
       
   497 	// Clear interrupt
       
   498 	TUint32 retries = SMCS9118_MAX_RETRIES;
       
   499 	while(retries-- && !((status = Read32(SMCS9118_INT_STS)) & SMCS9118_INT_STS_TX))
       
   500 		{
       
   501 		ByteTestDelay(1); // delay
       
   502 		}
       
   503 	if (retries == 0 || (status & SMCS9118_INT_STS_TXE))
       
   504 		{
       
   505 		DriverUnlock(irq);
       
   506 		return KErrGeneral;
       
   507 		}
       
   508 	Write32(SMCS9118_INT_STS, SMCS9118_INT_STS_TX);
       
   509 	ByteTestDelay(2);
       
   510 
       
   511 	DriverUnlock(irq);
       
   512 	return KErrNone;
       
   513 	}
       
   514 
       
   515 TInt DEthernetSMCS9118Pdd::DiscardFrame()
       
   516 /**
       
   517  * Discard the frame by fast forwarding over it
       
   518  *
       
   519  * Optional: if this doesn't
       
   520  * clear the frame, stop the receiver, dump the whole RX FIFO
       
   521  * and restart the receiver
       
   522  * assume iDriverLock held
       
   523  */
       
   524 	{
       
   525 	TUint32 retries = SMCS9118_MAX_RETRIES;
       
   526 
       
   527 	// if it is 4 words or less then just read it
       
   528 	TInt32 status = Read32(SMCS9118_RX_STATUS);
       
   529 	TInt32 length = (status >> SMCS9118_RX_LEN_SHIFT) & SMCS9118_RX_LEN_MASK;
       
   530 	TInt32 words = length >> 2;
       
   531 	if (length & 3)
       
   532 		{
       
   533 		words++;
       
   534 		}
       
   535 	if (words <= 4)
       
   536 		{
       
   537 		while (words--)
       
   538 			{
       
   539 			status = Read32(SMCS9118_RX_DATA_FIFO);
       
   540 			}
       
   541 		status =  Read32(SMCS9118_RX_DATA_FIFO);
       
   542 		return KErrNone;
       
   543 		}
       
   544 
       
   545 	// FFWD over the frame
       
   546 	Write32(SMCS9118_RX_DP_CTL, SMCS9118_RX_DP_FFWD);
       
   547 	ByteTestDelay(1);
       
   548 	while((Read32(SMCS9118_RX_DP_CTL) & SMCS9118_RX_DP_FFWD) && --retries)
       
   549 		{
       
   550 		ByteTestDelay(1); // delay
       
   551 		}
       
   552 	if (retries != 0)
       
   553 		{
       
   554 		return KErrNone;
       
   555 		}
       
   556 
       
   557 #ifdef SMCS9118_DUMP_FIFO
       
   558 	// stop the receiver
       
   559 	TUint32 status;
       
   560 	TInt32 err;
       
   561 	err = ReadMac(SMCS9118_MAC_CR, status);
       
   562 	if (err != KErrNone)
       
   563 		{
       
   564 		return err;
       
   565 		}
       
   566 	status &= ~SMCS9118_MAC_RXEN;
       
   567 	err = WriteMac(SMCS9118_MAC_CR, status);
       
   568 	if (err != KErrNone)
       
   569 		{
       
   570 		return err;
       
   571 		}
       
   572 
       
   573 	// wait for reciever to stop
       
   574 	retries = SMCS9118_MAX_RETRIES;
       
   575 	Write32(SMCS9118_RX_DP_CTL, SMCS9118_RX_DP_FFWD);
       
   576 	ByteTestDelay(2);
       
   577 	while((Read32(SMCS9118_INT_STS) & SMCS9118_RXSTOP_INT) && --retries)
       
   578 		{
       
   579 		ByteTestDelay(1); // delay
       
   580 		}
       
   581 	if (retries == 0)
       
   582 		{
       
   583 		return KErrGeneral;
       
   584 		}
       
   585 
       
   586 	// dump the whole FIFO
       
   587 	retries = SMCS9118_MAX_RETRIES;
       
   588 	Write32(SMCS9118_RX_CFG, SMCS9118_RX_DUMP);
       
   589 	ByteTestDelay(1);
       
   590 	while((Read32(SMCS9118_RX_CFG) & SMCS9118_RX_DUMP) && --retries)
       
   591 		{
       
   592 		ByteTestDelay(1); // delay
       
   593 		}
       
   594 	if (retries != 0)
       
   595 		{
       
   596 		// re-enable RX
       
   597 		err = ReadMac(SMCS9118_MAC_CR, status);
       
   598 		if (err != KErrNone)
       
   599 			{
       
   600 			return err;
       
   601 			}
       
   602 		status |= SMCS9118_MAC_RXEN;
       
   603 		err = WriteMac(SMCS9118_MAC_CR, status);
       
   604 		return err;
       
   605 		}
       
   606 #endif
       
   607 	return KErrGeneral;
       
   608 	}
       
   609 
       
   610 
       
   611 
       
   612 TInt DEthernetSMCS9118Pdd::ReceiveFrame(TBuf8<KMaxEthernetPacket+32>& aBuffer, TBool aOkToUse)
       
   613 /**
       
   614  * Retrieve data from the device - called by the RxDFC queued by the (variant's) ISR. 
       
   615  * Pull the received data out of the device and into the supplied buffer.
       
   616  * Need to be told if the buffer is OK to use as if it not we could dump
       
   617  * the waiting frame in order to clear the interrupt if necessory.
       
   618  * @param aBuffer Reference to the buffer to be used to store the data in
       
   619  * @param aOkToUse Bool to indicate if the buffer is usable
       
   620  * @return KErrNone if the buffer has been filled.
       
   621  */
       
   622 	{
       
   623 	TInt32 status;
       
   624 	TUint32 length;
       
   625 	
       
   626 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   627 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::ReceiveFrame()");
       
   628 	#endif
       
   629 	// Always request for power (Needs to be done incase of external wakeup event)
       
   630 	iPowerHandler.RequestPower();
       
   631 
       
   632 	TInt irq = DriverLock();
       
   633 	// If no buffer available dump frame
       
   634 	if (!aOkToUse)
       
   635 		{
       
   636 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   637 		KPROFILE_PRINT("SMCS9118: No Rx buffer available");
       
   638 		#endif
       
   639 
       
   640 		if ((status = DiscardFrame()) == KErrNone)
       
   641 			{
       
   642 			status = KErrGeneral;
       
   643 			}
       
   644 		DriverUnlock(irq);
       
   645 		return status;
       
   646 		}
       
   647 
       
   648 
       
   649 	status = Read32(SMCS9118_RX_FIFO_INF);
       
   650 	if(!(status & 0xffff))
       
   651 		{
       
   652 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   653 		KPROFILE_PRINT("SMCS9118: Empty Rx FIFO");
       
   654 		#endif
       
   655 		DriverUnlock(irq);
       
   656 		return KErrGeneral;
       
   657 		}
       
   658 
       
   659 	// discard bad packets
       
   660 	status = Read32(SMCS9118_RX_STATUS);
       
   661 	length = (status >> SMCS9118_RX_LEN_SHIFT) & SMCS9118_RX_LEN_MASK;
       
   662 	if (status & SMCS9118_RX_ES)
       
   663 		{
       
   664 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   665 		KPROFILE_PRINT("SMCS9118: Bad Rx Packet");
       
   666 		#endif
       
   667 
       
   668 		if ((status = DiscardFrame()) == (TUint32)KErrNone)
       
   669 			{
       
   670 			status = KErrGeneral;
       
   671 			}
       
   672 		DriverUnlock(irq);
       
   673 		return status;
       
   674 		}
       
   675 
       
   676 	TUint32 words = length >> 2;
       
   677 	TUint32 *dataP = (TUint32*) aBuffer.Ptr();
       
   678 
       
   679 	if (length & 3)
       
   680 		{
       
   681 		words++;
       
   682 		}
       
   683 
       
   684 	while (words--)
       
   685 		{
       
   686 		*dataP++ = Read32(SMCS9118_RX_DATA_FIFO);
       
   687 		}
       
   688 	aBuffer.SetLength(length-4);
       
   689 
       
   690 	DriverUnlock(irq);
       
   691 	return KErrNone;
       
   692 	}
       
   693 
       
   694 
       
   695 const TInt KEthernetDfcThreadPriority = 24;
       
   696 _LIT(KEthernetDfcThread,"EthernetDfcThread");
       
   697 
       
   698 
       
   699 TInt DEthernetSMCS9118Pdd::DoCreate()
       
   700 /**
       
   701  * Does the hard and soft reset of the lan card.
       
   702  * Puts the default configuration in iDefaultConfig member
       
   703  */
       
   704 	{
       
   705 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   706 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::DoCreate()");
       
   707 	#endif
       
   708 
       
   709 
       
   710 	// Register the power handler with Symbian Power Framework
       
   711 	iPowerHandler.Add();
       
   712 	TInt r = iPowerHandler.SetEthernetPdd(this);
       
   713 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   714     __KTRACE_OPT(KPOWER, Kern::Printf("iPowerHandler.SetEthernetPdd() returned [%d]",r));
       
   715 	#endif
       
   716 
       
   717 	// Allocate a kernel thread to run the DFC 
       
   718 	r = Kern::DynamicDfcQCreate(iDfcQ, KEthernetDfcThreadPriority, KEthernetDfcThread);
       
   719 
       
   720 	if (r != KErrNone)
       
   721 		{
       
   722 		return r; 	
       
   723 		}
       
   724 
       
   725 #ifdef CPU_AFFINITY_ANY
       
   726 	NKern::ThreadSetCpuAffinity((NThread*) iDfcQ->iThread, KCpuAffinityAny);
       
   727 #endif
       
   728 	
       
   729 	iRxDfc.SetDfcQ(iDfcQ);
       
   730 
       
   731 	TInt irq = DriverLock();
       
   732 	iDefaultConfig.iEthSpeed  = KEthSpeed10BaseT;
       
   733 	iDefaultConfig.iEthDuplex = KEthDuplexHalf;
       
   734 
       
   735 	// detect if SMSC9118 card is available, ignore revision
       
   736 	TUint32 id = Read32(SMCS9118_ID_REV) & SMCS9118_ID_MASK;
       
   737 	if(id != SMCS9118_ID_VAL)
       
   738 		{
       
   739 		DriverUnlock(irq);
       
   740 		return KErrHardwareNotAvailable;
       
   741 		}
       
   742 
       
   743 	TUint32 mac;
       
   744 	r = ReadMac(SMCS9118_MAC_ADDRL, mac);
       
   745 	if (r != KErrNone)
       
   746 		{
       
   747 		DriverUnlock(irq);
       
   748 		return r;
       
   749 		}
       
   750 	
       
   751 	iDefaultConfig.iEthAddress[0] = (TUint8)(mac);
       
   752 	iDefaultConfig.iEthAddress[1] = (TUint8)(mac>>8);
       
   753 	iDefaultConfig.iEthAddress[2] = (TUint8)(mac>>16);
       
   754 	iDefaultConfig.iEthAddress[3] = (TUint8)(mac>>24);
       
   755 	r = ReadMac(SMCS9118_MAC_ADDRH, mac);
       
   756 	if (r != KErrNone)
       
   757 		{
       
   758 		DriverUnlock(irq);
       
   759 		return r;
       
   760 		}
       
   761 	iDefaultConfig.iEthAddress[4] = (TUint8)(mac);
       
   762 	iDefaultConfig.iEthAddress[5] = (TUint8)(mac>>8);
       
   763 
       
   764 	// Serial number is the bottom 4 bytes of the MAC address
       
   765 	TInt serialNum =  (iDefaultConfig.iEthAddress[2] << 24)
       
   766 	                | (iDefaultConfig.iEthAddress[3] << 16)
       
   767 	                | (iDefaultConfig.iEthAddress[4] <<  8)
       
   768 	                | (iDefaultConfig.iEthAddress[5]      );
       
   769 
       
   770 	// Push the serial numberinto the variant config so it can be retrieved via HAL
       
   771 	NE1_TBVariant::SetSerialNumber(serialNum);
       
   772 
       
   773 	iInterruptId = KEthernetInterruptId;
       
   774 
       
   775 	DriverUnlock(irq);
       
   776 	__KTRACE_OPT(KHARDWARE, Kern::Printf("-- MAC address %2x.%2x.%2x.%2x.%2x.%2x",
       
   777 				iDefaultConfig.iEthAddress[0], iDefaultConfig.iEthAddress[1],
       
   778 				iDefaultConfig.iEthAddress[2], iDefaultConfig.iEthAddress[3],
       
   779 				iDefaultConfig.iEthAddress[4], iDefaultConfig.iEthAddress[5]));
       
   780 
       
   781 	// Register ISR
       
   782 	r = BindInterrupt(KEthernetInterruptId, Isr, this);
       
   783     if(r != KErrNone)
       
   784 	{
       
   785 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   786 		KPROFILE_PRINT("-- Error!!! Ethernet failed to bind interrupt.");
       
   787 		#endif
       
   788 		return r;
       
   789 	}
       
   790 	return r;
       
   791 	}
       
   792 
       
   793 void DEthernetSMCS9118Pdd::Sleep()
       
   794 /**
       
   795  * Put the card into D1 sleep
       
   796  * assume iDriverLock not held
       
   797  */
       
   798 	{
       
   799 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   800 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::Sleep()");
       
   801 	#endif
       
   802 
       
   803 	TUint32 status;
       
   804 	TInt irq = DriverLock();
       
   805 	status = Read32(SMCS9118_PMT_CTRL) | SMCS9118_PM_MODE_D1;
       
   806 	Write32(SMCS9118_PMT_CTRL, status);
       
   807 	DriverUnlock(irq);
       
   808 	}
       
   809 
       
   810 TInt DEthernetSMCS9118Pdd::Wakeup()
       
   811 /**
       
   812  * Wake the card up
       
   813  * assume iDriverLock not held
       
   814  */
       
   815 	{
       
   816 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   817 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::Wakeup()");
       
   818 	#endif
       
   819 
       
   820 	TUint32 status;
       
   821 
       
   822 	// has card woken up yet ?
       
   823 	
       
   824 	TInt irq = DriverLock();
       
   825 	TUint32 retry = SMCS9118_MAX_RETRIES;
       
   826 	do
       
   827 		{
       
   828 		Write32(SMCS9118_BYTE_TEST, 0x12345678);
       
   829 		status = Read32(SMCS9118_PMT_CTRL);
       
   830 		if (status & SMCS9118_PMT_READY)
       
   831 			{
       
   832 			break;
       
   833 			}
       
   834 		Kern::NanoWait(ONE_MSEC);
       
   835 		} while (--retry);
       
   836 
       
   837 	if (retry == 0)
       
   838 		{
       
   839 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   840 		KPROFILE_PRINT("-- Error!!! Problem in Wakeup of SMCS9118 card.");
       
   841 		#endif
       
   842 		DriverUnlock(irq);
       
   843 		return KErrGeneral;
       
   844 		}
       
   845 	DriverUnlock(irq);
       
   846 	return KErrNone;
       
   847 	}
       
   848 
       
   849 TInt DEthernetSMCS9118Pdd::CardSoftReset()
       
   850 /**
       
   851  * Does the soft reset of the lan card
       
   852  * assume iDriverLock not held
       
   853  */
       
   854 	{
       
   855 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   856 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::CardSoftReset()");
       
   857 	#endif
       
   858 
       
   859 	TInt32 status;
       
   860 
       
   861 	// wake the card up
       
   862 	status = Wakeup();
       
   863 	if (status != KErrNone)
       
   864 		{
       
   865 		return status;
       
   866 		}
       
   867 
       
   868 	// do soft reset
       
   869 	TInt irq = DriverLock();
       
   870 	status = Read32(SMCS9118_HW_CFG);
       
   871 	status |= SMCS9118_HW_CFG_SRST;
       
   872 	Write32(SMCS9118_HW_CFG, status);
       
   873 
       
   874 	ByteTestDelay(1);
       
   875 
       
   876 	TUint32 retry = SMCS9118_MAX_RETRIES;
       
   877 	do
       
   878 		{
       
   879 		status = Read32(SMCS9118_HW_CFG);
       
   880 		if (!(status & SMCS9118_HW_CFG_SRST))
       
   881 			{
       
   882 			break;
       
   883 			}
       
   884 		Kern::NanoWait(ONE_MSEC);
       
   885 		} while (--retry);
       
   886 
       
   887 	if (retry == 0)
       
   888 		{
       
   889 		DriverUnlock(irq);
       
   890 		#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   891 		KPROFILE_PRINT("-- Error!!! Problem in soft reset of SMCS9118 card.");
       
   892 		#endif
       
   893 		return KErrGeneral;
       
   894 		}
       
   895 
       
   896 	ByteTestDelay(1);
       
   897 	DriverUnlock(irq);
       
   898 
       
   899 	return KErrNone;
       
   900 	}
       
   901 
       
   902 
       
   903 /**
       
   904  * service the Isr
       
   905  */
       
   906 void DEthernetSMCS9118Pdd::Isr(TAny* aPtr)
       
   907 	{
       
   908 
       
   909 	DEthernetSMCS9118Pdd &d=*(DEthernetSMCS9118Pdd*)aPtr;
       
   910 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   911 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::Isr");
       
   912 	#endif
       
   913 
       
   914 	// get interrupt status
       
   915 	TUint32 status = d.Read32(SMCS9118_INT_STS);
       
   916 
       
   917 	if (d.IsReady() && (status & SMCS9118_INT_STS_RSFL))
       
   918 		{
       
   919 		// We received an Rx Interrupt, so clear it
       
   920 		// and queue on dfc
       
   921 		d.Write32(SMCS9118_INT_EN, 0);
       
   922 		d.iRxDfc.Add();
       
   923 		}
       
   924 	else
       
   925 		{
       
   926 		// spurious interrupt ?
       
   927 		d.Write32(SMCS9118_INT_STS, status);
       
   928 		}
       
   929 	d.ClearInterrupt(d.iInterruptId);
       
   930 	}
       
   931 
       
   932 //
       
   933 // Queued by the ISR on a receive interrupt.  Calls into LDD which calls back into 
       
   934 // PDD.ReceiveFrame() to get the data and write it into the LDD managed FIFO. 
       
   935 // Assume iDriverLock not held
       
   936 // 
       
   937 
       
   938 void DEthernetSMCS9118Pdd::ServiceRxDfc(TAny* aPtr)
       
   939 	{
       
   940 	#if defined(INSTR) && defined(KTRACE_SYNCH)
       
   941 	KPROFILE_PRINT("DEthernetSMCS9118Pdd::ServiceRxDfc");
       
   942 	#endif
       
   943 
       
   944 	DEthernetSMCS9118Pdd &d=*(DEthernetSMCS9118Pdd*)aPtr;
       
   945 
       
   946 	d.ReceiveIsr();
       
   947 
       
   948 	TInt irq = d.DriverLock();
       
   949 	// reset status
       
   950 	d.Write32(SMCS9118_INT_STS, SMCS9118_INT_STS_RSFL);
       
   951 	d.ByteTestDelay(2);
       
   952 
       
   953 	// reenable interrupt
       
   954 	d.Write32(SMCS9118_INT_EN, SMCS9118_INT_EN_RSFL);
       
   955 	d.ByteTestDelay(1);
       
   956 	d.DriverUnlock(irq);
       
   957 
       
   958 	return;
       
   959 	}
       
   960 
       
   961 /**
       
   962  * Read a MAC register
       
   963  * assume iDriverLock held
       
   964  */
       
   965 TInt32 DEthernetSMCS9118Pdd::ReadMac(TUint32 aReg, TUint32 &aVal)
       
   966 	{
       
   967 	TUint32 timeout;
       
   968 
       
   969 	for(timeout = 0; timeout < SMCS9118_MAC_TIMEOUT; timeout ++)
       
   970 		{
       
   971 		if(Read32(SMCS9118_MAC_CSR_CMD) & SMCS9118_MAC_CSR_BUSY)
       
   972 			{
       
   973 			Kern::NanoWait(ONE_MSEC);
       
   974 			}
       
   975 		}
       
   976 
       
   977 	TUint32 cmd = 0;
       
   978 
       
   979 	Write32(SMCS9118_MAC_CSR_CMD, cmd);
       
   980 	ByteTestDelay(1);
       
   981 
       
   982 	cmd = (aReg & 0xff) | SMCS9118_MAC_CSR_BUSY | SMCS9118_MAC_CSR_READ;
       
   983 
       
   984 	Write32(SMCS9118_MAC_CSR_CMD, cmd);
       
   985 	ByteTestDelay(1);
       
   986 
       
   987 	for(timeout = 0; timeout < SMCS9118_MAC_TIMEOUT; timeout ++)
       
   988 		{
       
   989 		if(Read32(SMCS9118_MAC_CSR_CMD) & SMCS9118_MAC_CSR_BUSY)
       
   990 			{
       
   991 			Kern::NanoWait(ONE_MSEC);
       
   992 			}
       
   993 		else
       
   994 			{
       
   995 			aVal = Read32(SMCS9118_MAC_CSR_DATA);
       
   996 			return KErrNone;
       
   997 			}
       
   998 		}
       
   999 	return KErrTimedOut;
       
  1000 	}
       
  1001 
       
  1002 /**
       
  1003  * Write a MAC register
       
  1004  * assume iDriverLock held
       
  1005  */
       
  1006 TInt32 DEthernetSMCS9118Pdd::WriteMac(TUint32 aReg, TUint32 aVal)
       
  1007 	{
       
  1008 	if (Read32(SMCS9118_MAC_CSR_CMD) & SMCS9118_MAC_CSR_BUSY)
       
  1009 		{
       
  1010 		return KErrTimedOut;
       
  1011 		}
       
  1012 
       
  1013 	TUint32 cmd = 0;
       
  1014 	TUint32 timeout;
       
  1015 
       
  1016 	Write32(SMCS9118_MAC_CSR_CMD, cmd);
       
  1017 	ByteTestDelay(1);
       
  1018 
       
  1019 	cmd = (aReg & 0xff) | SMCS9118_MAC_CSR_BUSY;
       
  1020 
       
  1021 	Write32(SMCS9118_MAC_CSR_DATA, aVal);
       
  1022 	ByteTestDelay(1);
       
  1023 	Write32(SMCS9118_MAC_CSR_CMD, cmd);
       
  1024 	ByteTestDelay(1);
       
  1025 
       
  1026 	for (timeout = 0; timeout < SMCS9118_MAC_TIMEOUT; timeout ++)
       
  1027 		{
       
  1028 		if(Read32(SMCS9118_MAC_CSR_CMD) & SMCS9118_MAC_CSR_BUSY)
       
  1029 			{
       
  1030 			Kern::NanoWait(ONE_MSEC);
       
  1031 			}
       
  1032 		else
       
  1033 			{
       
  1034 			return KErrNone;
       
  1035 			}
       
  1036 		}
       
  1037 	return KErrTimedOut;
       
  1038 	}
       
  1039 
       
  1040 /**
       
  1041  * Read a PHY register
       
  1042  * assume iDriverLock held
       
  1043  */
       
  1044 TInt32 DEthernetSMCS9118Pdd::ReadPhy(TUint32 aReg, TUint32 &aValue)
       
  1045 	{
       
  1046 	TUint32 cmd;
       
  1047 	TUint32 timeout;
       
  1048 	TInt32 err;
       
  1049 
       
  1050 	// bail out if busy
       
  1051 	err = ReadMac(SMCS9118_MAC_MII_ACC, aValue);
       
  1052 	if (err != KErrNone)
       
  1053 		{
       
  1054 		return err;
       
  1055 		}
       
  1056 		
       
  1057 	if (aValue & SMCS9118_MII_BUSY)
       
  1058 		{
       
  1059 		return KErrTimedOut;
       
  1060 		}
       
  1061 
       
  1062 	cmd = SMCS9118_PHY_ADDR | (aReg << 6) | SMCS9118_MII_BUSY;
       
  1063 
       
  1064 	err = WriteMac(SMCS9118_MAC_MII_ACC, cmd);
       
  1065 	if (err != KErrNone)
       
  1066 		{
       
  1067 		return err;
       
  1068 		}
       
  1069 
       
  1070 	for(timeout = 0; timeout < SMCS9118_MAC_TIMEOUT; timeout++)
       
  1071 		{
       
  1072 		err = ReadMac(SMCS9118_MAC_MII_ACC, aValue);
       
  1073 		if (err != KErrNone)
       
  1074 			{
       
  1075 			return err;
       
  1076 			}
       
  1077 		
       
  1078 		if (!(aValue & SMCS9118_MII_BUSY))
       
  1079 			{
       
  1080 			err = ReadMac(SMCS9118_MAC_MII_DATA, aValue);
       
  1081 			return err;
       
  1082 			}
       
  1083 		}
       
  1084 	return KErrTimedOut;
       
  1085 	}
       
  1086 
       
  1087 /**
       
  1088  * Write a PHY register
       
  1089  * assume iDriverLock held
       
  1090  */
       
  1091 TInt32 DEthernetSMCS9118Pdd::WritePhy(TUint32 aReg, TUint32 aVal)
       
  1092 	{
       
  1093 	TUint32 cmd;
       
  1094 	TUint32 timeout;
       
  1095 	TUint32 status;
       
  1096 	TInt32	err;
       
  1097 
       
  1098 	// bail out if busy
       
  1099 	err = ReadMac(SMCS9118_MAC_MII_ACC, status);
       
  1100 	if (err != KErrNone)
       
  1101 		{
       
  1102 		return err;
       
  1103 		}
       
  1104 		
       
  1105 	if (status & SMCS9118_MII_BUSY)
       
  1106 		{
       
  1107 		return KErrTimedOut;
       
  1108 		}
       
  1109 
       
  1110 	cmd = SMCS9118_PHY_ADDR | (aReg << 6) | SMCS9118_MII_WRITE | SMCS9118_MII_BUSY;
       
  1111 
       
  1112 	err = WriteMac(SMCS9118_MAC_MII_DATA, aVal & 0xffff);
       
  1113 	if (err != KErrNone)
       
  1114 			{
       
  1115 			return err;
       
  1116 			}
       
  1117 	err = WriteMac(SMCS9118_MAC_MII_ACC, cmd);
       
  1118 	if (err != KErrNone)
       
  1119 			{
       
  1120 			return err;
       
  1121 			}
       
  1122 
       
  1123 	for(timeout = 0; timeout < SMCS9118_MAC_TIMEOUT; timeout++)
       
  1124 		{
       
  1125 		err = ReadMac(SMCS9118_MAC_MII_ACC, status);
       
  1126 		if (err != KErrNone)
       
  1127 			{
       
  1128 			return err;
       
  1129 			}
       
  1130 		if(!(status & SMCS9118_MII_BUSY))
       
  1131 			{
       
  1132 			return KErrNone;
       
  1133 			}
       
  1134 		}
       
  1135 	return KErrTimedOut;
       
  1136 	}
       
  1137 // PDD entry point
       
  1138 DECLARE_STANDARD_PDD()
       
  1139 	{
       
  1140 	return new DEthernetPddFactory;
       
  1141 	}