1 /******************************************************************************/
3 /* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 Broadcom */
5 /* All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify */
8 /* it under the terms of the GNU General Public License as published by */
9 /* the Free Software Foundation, located in the file LICENSE. */
12 /******************************************************************************/
14 #include <asm/types.h>
15 #if defined(CONFIG_CMD_NET) && !defined(CONFIG_NET_MULTI) && \
16 defined(CONFIG_TIGON3)
21 #include <linux/byteorder/big_endian.h>
22 #include "bcm570x_mm.h"
25 /******************************************************************************/
26 /* Local functions. */
27 /******************************************************************************/
29 LM_STATUS LM_Abort (PLM_DEVICE_BLOCK pDevice);
30 LM_STATUS LM_QueueRxPackets (PLM_DEVICE_BLOCK pDevice);
32 static LM_STATUS LM_TranslateRequestedMediaType (LM_REQUESTED_MEDIA_TYPE
34 PLM_MEDIA_TYPE pMediaType,
35 PLM_LINE_SPEED pLineSpeed,
36 PLM_DUPLEX_MODE pDuplexMode);
38 static LM_STATUS LM_InitBcm540xPhy (PLM_DEVICE_BLOCK pDevice);
40 __inline static LM_VOID LM_ServiceRxInterrupt (PLM_DEVICE_BLOCK pDevice);
41 __inline static LM_VOID LM_ServiceTxInterrupt (PLM_DEVICE_BLOCK pDevice);
43 static LM_STATUS LM_ForceAutoNegBcm540xPhy (PLM_DEVICE_BLOCK pDevice,
44 LM_REQUESTED_MEDIA_TYPE
46 static LM_STATUS LM_ForceAutoNeg (PLM_DEVICE_BLOCK pDevice,
47 LM_REQUESTED_MEDIA_TYPE RequestedMediaType);
48 static LM_UINT32 GetPhyAdFlowCntrlSettings (PLM_DEVICE_BLOCK pDevice);
49 STATIC LM_STATUS LM_SetFlowControl (PLM_DEVICE_BLOCK pDevice,
51 LM_UINT32 RemotePhyAd);
52 #if INCLUDE_TBI_SUPPORT
53 STATIC LM_STATUS LM_SetupFiberPhy (PLM_DEVICE_BLOCK pDevice);
54 STATIC LM_STATUS LM_InitBcm800xPhy (PLM_DEVICE_BLOCK pDevice);
56 STATIC LM_STATUS LM_SetupCopperPhy (PLM_DEVICE_BLOCK pDevice);
57 STATIC PLM_ADAPTER_INFO LM_GetAdapterInfoBySsid (LM_UINT16 Svid,
59 STATIC LM_STATUS LM_DmaTest (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
60 LM_PHYSICAL_ADDRESS BufferPhy,
61 LM_UINT32 BufferSize);
62 STATIC LM_STATUS LM_HaltCpu (PLM_DEVICE_BLOCK pDevice, LM_UINT32 cpu_number);
63 STATIC LM_STATUS LM_ResetChip (PLM_DEVICE_BLOCK pDevice);
64 STATIC LM_STATUS LM_Test4GBoundary (PLM_DEVICE_BLOCK pDevice,
65 PLM_PACKET pPacket, PT3_SND_BD pSendBd);
67 /******************************************************************************/
68 /* External functions. */
69 /******************************************************************************/
71 LM_STATUS LM_LoadRlsFirmware (PLM_DEVICE_BLOCK pDevice);
73 /******************************************************************************/
77 /******************************************************************************/
78 LM_UINT32 LM_RegRdInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Register)
82 #if PCIX_TARGET_WORKAROUND
83 MM_ACQUIRE_UNDI_LOCK (pDevice);
85 MM_WriteConfig32 (pDevice, T3_PCI_REG_ADDR_REG, Register);
86 MM_ReadConfig32 (pDevice, T3_PCI_REG_DATA_REG, &Value32);
87 #if PCIX_TARGET_WORKAROUND
88 MM_RELEASE_UNDI_LOCK (pDevice);
94 /******************************************************************************/
98 /******************************************************************************/
100 LM_RegWrInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Register, LM_UINT32 Value32)
103 #if PCIX_TARGET_WORKAROUND
104 MM_ACQUIRE_UNDI_LOCK (pDevice);
106 MM_WriteConfig32 (pDevice, T3_PCI_REG_ADDR_REG, Register);
107 MM_WriteConfig32 (pDevice, T3_PCI_REG_DATA_REG, Value32);
108 #if PCIX_TARGET_WORKAROUND
109 MM_RELEASE_UNDI_LOCK (pDevice);
113 /******************************************************************************/
117 /******************************************************************************/
118 LM_UINT32 LM_MemRdInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 MemAddr)
122 MM_ACQUIRE_UNDI_LOCK (pDevice);
123 #ifdef BIG_ENDIAN_HOST
124 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
125 Value32 = REG_RD (pDevice, PciCfg.MemWindowData);
126 /* Value32 = REG_RD(pDevice,uIntMem.Mbuf[(MemAddr & 0x7fff)/4]); */
128 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
129 MM_ReadConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG, &Value32);
131 MM_RELEASE_UNDI_LOCK (pDevice);
136 /******************************************************************************/
140 /******************************************************************************/
142 LM_MemWrInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 MemAddr, LM_UINT32 Value32)
144 MM_ACQUIRE_UNDI_LOCK (pDevice);
145 #ifdef BIG_ENDIAN_HOST
146 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, MemAddr);
147 REG_WR (pDevice, uIntMem.Mbuf[(MemAddr & 0x7fff) / 4], Value32);
149 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
150 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG, Value32);
152 MM_RELEASE_UNDI_LOCK (pDevice);
155 /******************************************************************************/
159 /******************************************************************************/
160 LM_STATUS LM_QueueRxPackets (PLM_DEVICE_BLOCK pDevice)
165 LM_UINT32 StdBdAdded = 0;
166 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
167 LM_UINT32 JumboBdAdded = 0;
168 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
170 Lmstatus = LM_STATUS_SUCCESS;
172 pPacket = (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
174 switch (pPacket->u.Rx.RcvProdRing) {
175 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
176 case T3_JUMBO_RCV_PROD_RING: /* Jumbo Receive Ring. */
177 /* Initialize the buffer descriptor. */
179 &pDevice->pRxJumboBdVirt[pDevice->RxJumboProdIdx];
181 RCV_BD_FLAG_END | RCV_BD_FLAG_JUMBO_RING;
182 pRcvBd->Len = (LM_UINT16) pDevice->RxJumboBufferSize;
184 /* Initialize the receive buffer pointer */
185 #if 0 /* Jimmy, deleted in new */
186 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
187 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
189 MM_MapRxDma (pDevice, pPacket, &pRcvBd->HostAddr);
191 /* The opaque field may point to an offset from a fix addr. */
192 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR (pPacket) -
193 MM_UINT_PTR (pDevice->
196 /* Update the producer index. */
197 pDevice->RxJumboProdIdx =
198 (pDevice->RxJumboProdIdx +
199 1) & T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
203 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
205 case T3_STD_RCV_PROD_RING: /* Standard Receive Ring. */
206 /* Initialize the buffer descriptor. */
207 pRcvBd = &pDevice->pRxStdBdVirt[pDevice->RxStdProdIdx];
208 pRcvBd->Flags = RCV_BD_FLAG_END;
209 pRcvBd->Len = MAX_STD_RCV_BUFFER_SIZE;
211 /* Initialize the receive buffer pointer */
212 #if 0 /* Jimmy, deleted in new replaced with MM_MapRxDma */
213 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
214 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
216 MM_MapRxDma (pDevice, pPacket, &pRcvBd->HostAddr);
218 /* The opaque field may point to an offset from a fix addr. */
219 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR (pPacket) -
220 MM_UINT_PTR (pDevice->
223 /* Update the producer index. */
224 pDevice->RxStdProdIdx = (pDevice->RxStdProdIdx + 1) &
225 T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
230 case T3_UNKNOWN_RCV_PROD_RING:
232 Lmstatus = LM_STATUS_FAILURE;
236 /* Bail out if there is any error. */
237 if (Lmstatus != LM_STATUS_SUCCESS) {
242 (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
246 /* Update the procedure index. */
248 MB_REG_WR (pDevice, Mailbox.RcvStdProdIdx.Low,
249 pDevice->RxStdProdIdx);
251 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
253 MB_REG_WR (pDevice, Mailbox.RcvJumboProdIdx.Low,
254 pDevice->RxJumboProdIdx);
256 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
259 } /* LM_QueueRxPackets */
261 /******************************************************************************/
265 /******************************************************************************/
266 STATIC LM_VOID LM_NvramInit (PLM_DEVICE_BLOCK pDevice)
271 /* Intialize clock period and state machine. */
272 Value32 = SEEPROM_ADDR_CLK_PERD (SEEPROM_CLOCK_PERIOD) |
273 SEEPROM_ADDR_FSM_RESET;
274 REG_WR (pDevice, Grc.EepromAddr, Value32);
276 for (j = 0; j < 100; j++) {
280 /* Serial eeprom access using the Grc.EepromAddr/EepromData registers. */
281 Value32 = REG_RD (pDevice, Grc.LocalCtrl);
282 REG_WR (pDevice, Grc.LocalCtrl,
283 Value32 | GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM);
285 /* Set the 5701 compatibility mode if we are using EEPROM. */
286 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
287 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
288 Value32 = REG_RD (pDevice, Nvram.Config1);
289 if ((Value32 & FLASH_INTERFACE_ENABLE) == 0) {
290 /* Use the new interface to read EEPROM. */
291 Value32 &= ~FLASH_COMPAT_BYPASS;
293 REG_WR (pDevice, Nvram.Config1, Value32);
298 /******************************************************************************/
302 /******************************************************************************/
304 LM_EepromRead (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 * pData)
311 if (Offset > SEEPROM_CHIP_SIZE) {
312 return LM_STATUS_FAILURE;
315 Dev = Offset / SEEPROM_CHIP_SIZE;
316 Addr = Offset % SEEPROM_CHIP_SIZE;
318 Value32 = REG_RD (pDevice, Grc.EepromAddr);
319 Value32 &= ~(SEEPROM_ADDR_ADDRESS_MASK | SEEPROM_ADDR_DEV_ID_MASK |
320 SEEPROM_ADDR_RW_MASK);
321 REG_WR (pDevice, Grc.EepromAddr, Value32 | SEEPROM_ADDR_DEV_ID (Dev) |
322 SEEPROM_ADDR_ADDRESS (Addr) | SEEPROM_ADDR_START |
325 for (j = 0; j < 1000; j++) {
326 Value32 = REG_RD (pDevice, Grc.EepromAddr);
327 if (Value32 & SEEPROM_ADDR_COMPLETE) {
333 if (Value32 & SEEPROM_ADDR_COMPLETE) {
334 Value32 = REG_RD (pDevice, Grc.EepromData);
337 return LM_STATUS_SUCCESS;
340 return LM_STATUS_FAILURE;
341 } /* LM_EepromRead */
343 /******************************************************************************/
347 /******************************************************************************/
349 LM_NvramRead (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 * pData)
355 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
356 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
357 Status = LM_EepromRead (pDevice, Offset, pData);
359 /* Determine if we have flash or EEPROM. */
360 Value32 = REG_RD (pDevice, Nvram.Config1);
361 if (Value32 & FLASH_INTERFACE_ENABLE) {
362 if (Value32 & FLASH_SSRAM_BUFFERRED_MODE) {
363 Offset = ((Offset / BUFFERED_FLASH_PAGE_SIZE) <<
364 BUFFERED_FLASH_PAGE_POS) +
365 (Offset % BUFFERED_FLASH_PAGE_SIZE);
369 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
370 for (j = 0; j < 1000; j++) {
371 if (REG_RD (pDevice, Nvram.SwArb) & SW_ARB_GNT1) {
377 return LM_STATUS_FAILURE;
380 /* Read from flash or EEPROM with the new 5703/02 interface. */
381 REG_WR (pDevice, Nvram.Addr, Offset & NVRAM_ADDRESS_MASK);
383 REG_WR (pDevice, Nvram.Cmd, NVRAM_CMD_RD | NVRAM_CMD_DO_IT |
384 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
386 /* Wait for the done bit to clear. */
387 for (j = 0; j < 500; j++) {
390 Value32 = REG_RD (pDevice, Nvram.Cmd);
391 if (!(Value32 & NVRAM_CMD_DONE)) {
396 /* Wait for the done bit. */
397 if (!(Value32 & NVRAM_CMD_DONE)) {
398 for (j = 0; j < 500; j++) {
401 Value32 = REG_RD (pDevice, Nvram.Cmd);
402 if (Value32 & NVRAM_CMD_DONE) {
406 REG_RD (pDevice, Nvram.ReadData);
408 /* Change the endianess. */
410 ((*pData & 0xff) << 24) |
411 ((*pData & 0xff00) << 8) |
412 ((*pData & 0xff0000) >> 8) |
413 ((*pData >> 24) & 0xff);
420 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_CLR1);
421 if (Value32 & NVRAM_CMD_DONE) {
422 Status = LM_STATUS_SUCCESS;
424 Status = LM_STATUS_FAILURE;
431 STATIC void LM_ReadVPD (PLM_DEVICE_BLOCK pDevice)
433 LM_UINT32 Vpd_arr[256 / 4];
434 LM_UINT8 *Vpd = (LM_UINT8 *) & Vpd_arr[0];
435 LM_UINT32 *Vpd_dptr = &Vpd_arr[0];
439 /* Read PN from VPD */
440 for (j = 0; j < 256; j += 4, Vpd_dptr++) {
441 if (LM_NvramRead (pDevice, 0x100 + j, &Value32) !=
443 printf ("BCM570x: LM_ReadVPD: VPD read failed"
444 " (no EEPROM onboard)\n");
447 *Vpd_dptr = cpu_to_le32 (Value32);
449 for (j = 0; j < 256;) {
450 unsigned int Vpd_r_len;
451 unsigned int Vpd_r_end;
453 if ((Vpd[j] == 0x82) || (Vpd[j] == 0x91)) {
454 j = j + 3 + Vpd[j + 1] + (Vpd[j + 2] << 8);
455 } else if (Vpd[j] == 0x90) {
456 Vpd_r_len = Vpd[j + 1] + (Vpd[j + 2] << 8);
458 Vpd_r_end = Vpd_r_len + j;
459 while (j < Vpd_r_end) {
460 if ((Vpd[j] == 'P') && (Vpd[j + 1] == 'N')) {
461 unsigned int len = Vpd[j + 2];
464 memcpy (pDevice->PartNo,
469 if (Vpd[j + 2] == 0) {
482 STATIC void LM_ReadBootCodeVersion (PLM_DEVICE_BLOCK pDevice)
484 LM_UINT32 Value32, offset, ver_offset;
487 if (LM_NvramRead (pDevice, 0x0, &Value32) != LM_STATUS_SUCCESS)
489 if (Value32 != 0xaa559966)
491 if (LM_NvramRead (pDevice, 0xc, &offset) != LM_STATUS_SUCCESS)
494 offset = ((offset & 0xff) << 24) | ((offset & 0xff00) << 8) |
495 ((offset & 0xff0000) >> 8) | ((offset >> 24) & 0xff);
496 if (LM_NvramRead (pDevice, offset, &Value32) != LM_STATUS_SUCCESS)
498 if ((Value32 == 0x0300000e) &&
499 (LM_NvramRead (pDevice, offset + 4, &Value32) == LM_STATUS_SUCCESS)
502 if (LM_NvramRead (pDevice, offset + 8, &ver_offset) !=
505 ver_offset = ((ver_offset & 0xff0000) >> 8) |
506 ((ver_offset >> 24) & 0xff);
507 for (i = 0; i < 16; i += 4) {
509 (pDevice, offset + ver_offset + i,
510 &Value32) != LM_STATUS_SUCCESS) {
513 *((LM_UINT32 *) & pDevice->BootCodeVer[i]) =
514 cpu_to_le32 (Value32);
519 if (LM_NvramRead (pDevice, 0x94, &Value32) != LM_STATUS_SUCCESS)
523 c = ((Value32 & 0xff0000) >> 16);
526 pDevice->BootCodeVer[i++] = c + '0';
528 pDevice->BootCodeVer[i++] = (c / 10) + '0';
529 pDevice->BootCodeVer[i++] = (c % 10) + '0';
531 pDevice->BootCodeVer[i++] = '.';
532 c = (Value32 & 0xff000000) >> 24;
534 pDevice->BootCodeVer[i++] = c + '0';
536 pDevice->BootCodeVer[i++] = (c / 10) + '0';
537 pDevice->BootCodeVer[i++] = (c % 10) + '0';
539 pDevice->BootCodeVer[i] = 0;
543 STATIC void LM_GetBusSpeed (PLM_DEVICE_BLOCK pDevice)
545 LM_UINT32 PciState = pDevice->PciState;
549 if (PciState & T3_PCI_STATE_32BIT_PCI_BUS) {
550 strcpy (pDevice->BusSpeedStr, "32-bit ");
552 strcpy (pDevice->BusSpeedStr, "64-bit ");
554 if (PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) {
555 strcat (pDevice->BusSpeedStr, "PCI ");
556 if (PciState & T3_PCI_STATE_HIGH_BUS_SPEED) {
562 strcat (pDevice->BusSpeedStr, "PCIX ");
563 if (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE) {
566 ClockCtrl = REG_RD (pDevice, PciCfg.ClockCtrl) & 0x1f;
590 strcat (pDevice->BusSpeedStr, SpeedStr);
593 /******************************************************************************/
595 /* This routine initializes default parameters and reads the PCI */
596 /* configurations. */
599 /* LM_STATUS_SUCCESS */
600 /******************************************************************************/
601 LM_STATUS LM_GetAdapterInfo (PLM_DEVICE_BLOCK pDevice)
603 PLM_ADAPTER_INFO pAdapterInfo;
607 LM_UINT32 EeSigFound;
608 LM_UINT32 EePhyTypeSerdes = 0;
609 LM_UINT32 EePhyLedMode = 0;
610 LM_UINT32 EePhyId = 0;
612 /* Get Device Id and Vendor Id */
613 Status = MM_ReadConfig32 (pDevice, PCI_VENDOR_ID_REG, &Value32);
614 if (Status != LM_STATUS_SUCCESS) {
617 pDevice->PciVendorId = (LM_UINT16) Value32;
618 pDevice->PciDeviceId = (LM_UINT16) (Value32 >> 16);
620 /* If we are not getting the write adapter, exit. */
621 if ((Value32 != T3_PCI_ID_BCM5700) &&
622 (Value32 != T3_PCI_ID_BCM5701) &&
623 (Value32 != T3_PCI_ID_BCM5702) &&
624 (Value32 != T3_PCI_ID_BCM5702x) &&
625 (Value32 != T3_PCI_ID_BCM5702FE) &&
626 (Value32 != T3_PCI_ID_BCM5703) &&
627 (Value32 != T3_PCI_ID_BCM5703x) && (Value32 != T3_PCI_ID_BCM5704)) {
628 return LM_STATUS_FAILURE;
631 Status = MM_ReadConfig32 (pDevice, PCI_REV_ID_REG, &Value32);
632 if (Status != LM_STATUS_SUCCESS) {
635 pDevice->PciRevId = (LM_UINT8) Value32;
638 Status = MM_ReadConfig32 (pDevice, PCI_INT_LINE_REG, &Value32);
639 if (Status != LM_STATUS_SUCCESS) {
642 pDevice->Irq = (LM_UINT8) Value32;
644 /* Get interrupt pin. */
645 pDevice->IntPin = (LM_UINT8) (Value32 >> 8);
647 /* Get chip revision id. */
648 Status = MM_ReadConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG, &Value32);
649 pDevice->ChipRevId = Value32 >> 16;
651 /* Get subsystem vendor. */
653 MM_ReadConfig32 (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG, &Value32);
654 if (Status != LM_STATUS_SUCCESS) {
657 pDevice->SubsystemVendorId = (LM_UINT16) Value32;
659 /* Get PCI subsystem id. */
660 pDevice->SubsystemId = (LM_UINT16) (Value32 >> 16);
662 /* Get the cache line size. */
663 MM_ReadConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG, &Value32);
664 pDevice->CacheLineSize = (LM_UINT8) Value32;
665 pDevice->SavedCacheLineReg = Value32;
667 if (pDevice->ChipRevId != T3_CHIP_ID_5703_A1 &&
668 pDevice->ChipRevId != T3_CHIP_ID_5703_A2 &&
669 pDevice->ChipRevId != T3_CHIP_ID_5704_A0) {
670 pDevice->UndiFix = FALSE;
672 #if !PCIX_TARGET_WORKAROUND
673 pDevice->UndiFix = FALSE;
675 /* Map the memory base to system address space. */
676 if (!pDevice->UndiFix) {
677 Status = MM_MapMemBase (pDevice);
678 if (Status != LM_STATUS_SUCCESS) {
681 /* Initialize the memory view pointer. */
682 pDevice->pMemView = (PT3_STD_MEM_MAP) pDevice->pMappedMemBase;
684 #if PCIX_TARGET_WORKAROUND
685 /* store whether we are in PCI are PCI-X mode */
686 pDevice->EnablePciXFix = FALSE;
688 MM_ReadConfig32 (pDevice, T3_PCI_STATE_REG, &Value32);
689 if ((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0) {
690 /* Enable PCI-X workaround only if we are running on 5700 BX. */
691 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
692 pDevice->EnablePciXFix = TRUE;
695 if (pDevice->UndiFix) {
696 pDevice->EnablePciXFix = TRUE;
699 /* Bx bug: due to the "byte_enable bug" in PCI-X mode, the power */
700 /* management register may be clobbered which may cause the */
701 /* BCM5700 to go into D3 state. While in this state, we will */
702 /* not have memory mapped register access. As a workaround, we */
703 /* need to restore the device to D0 state. */
704 MM_ReadConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, &Value32);
705 Value32 |= T3_PM_PME_ASSERTED;
706 Value32 &= ~T3_PM_POWER_STATE_MASK;
707 Value32 |= T3_PM_POWER_STATE_D0;
708 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, Value32);
710 /* read the current PCI command word */
711 MM_ReadConfig32 (pDevice, PCI_COMMAND_REG, &Value32);
713 /* Make sure bus-mastering is enabled. */
714 Value32 |= PCI_BUSMASTER_ENABLE;
716 #if PCIX_TARGET_WORKAROUND
717 /* if we are in PCI-X mode, also make sure mem-mapping and SERR#/PERR#
719 if (pDevice->EnablePciXFix == TRUE) {
720 Value32 |= (PCI_MEM_SPACE_ENABLE | PCI_SYSTEM_ERROR_ENABLE |
721 PCI_PARITY_ERROR_ENABLE);
723 if (pDevice->UndiFix) {
724 Value32 &= ~PCI_MEM_SPACE_ENABLE;
728 if (pDevice->EnableMWI) {
729 Value32 |= PCI_MEMORY_WRITE_INVALIDATE;
731 Value32 &= (~PCI_MEMORY_WRITE_INVALIDATE);
734 /* Error out if mem-mapping is NOT enabled for PCI systems */
735 if (!(Value32 | PCI_MEM_SPACE_ENABLE)) {
736 return LM_STATUS_FAILURE;
739 /* save the value we are going to write into the PCI command word */
740 pDevice->PciCommandStatusWords = Value32;
742 Status = MM_WriteConfig32 (pDevice, PCI_COMMAND_REG, Value32);
743 if (Status != LM_STATUS_SUCCESS) {
747 /* Set power state to D0. */
748 LM_SetPowerState (pDevice, LM_POWER_STATE_D0);
750 #ifdef BIG_ENDIAN_PCI
751 pDevice->MiscHostCtrl =
752 MISC_HOST_CTRL_MASK_PCI_INT |
753 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
754 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
755 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
756 #else /* No CPU Swap modes for PCI IO */
758 /* Setup the mode registers. */
759 pDevice->MiscHostCtrl =
760 MISC_HOST_CTRL_MASK_PCI_INT |
761 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
762 #ifdef BIG_ENDIAN_HOST
763 MISC_HOST_CTRL_ENABLE_ENDIAN_BYTE_SWAP |
764 #endif /* BIG_ENDIAN_HOST */
765 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
766 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
767 #endif /* !BIG_ENDIAN_PCI */
769 /* write to PCI misc host ctr first in order to enable indirect accesses */
770 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
771 pDevice->MiscHostCtrl);
773 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl);
775 #ifdef BIG_ENDIAN_PCI
776 Value32 = GRC_MODE_WORD_SWAP_DATA | GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
778 /* No CPU Swap modes for PCI IO */
779 #ifdef BIG_ENDIAN_HOST
780 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
781 GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
783 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
785 #endif /* !BIG_ENDIAN_PCI */
787 REG_WR (pDevice, Grc.Mode, Value32);
789 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
790 REG_WR (pDevice, Grc.LocalCtrl,
791 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
792 GRC_MISC_LOCAL_CTRL_GPIO_OE1);
796 /* Enable indirect memory access */
797 REG_WR (pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
799 if (REG_RD (pDevice, PciCfg.ClockCtrl) & T3_PCI_44MHZ_CORE_CLOCK) {
800 REG_WR (pDevice, PciCfg.ClockCtrl, T3_PCI_44MHZ_CORE_CLOCK |
801 T3_PCI_SELECT_ALTERNATE_CLOCK);
802 REG_WR (pDevice, PciCfg.ClockCtrl,
803 T3_PCI_SELECT_ALTERNATE_CLOCK);
804 MM_Wait (40); /* required delay is 27usec */
806 REG_WR (pDevice, PciCfg.ClockCtrl, 0);
807 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, 0);
809 #if PCIX_TARGET_WORKAROUND
810 MM_ReadConfig32 (pDevice, T3_PCI_STATE_REG, &Value32);
811 if ((pDevice->EnablePciXFix == FALSE) &&
812 ((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0)) {
813 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
814 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
815 pDevice->ChipRevId == T3_CHIP_ID_5701_B2 ||
816 pDevice->ChipRevId == T3_CHIP_ID_5701_B5) {
818 &(pDevice->pMemView->uIntMem.
819 MemBlock32K[0x300]));
821 &(pDevice->pMemView->uIntMem.
822 MemBlock32K[0x301]));
823 __raw_writel (0xffffffff,
824 &(pDevice->pMemView->uIntMem.
825 MemBlock32K[0x301]));
827 (&(pDevice->pMemView->uIntMem.MemBlock32K[0x300])))
829 pDevice->EnablePciXFix = TRUE;
836 * This code was at the beginning of else block below, but that's
837 * a bug if node address in shared memory.
840 LM_NvramInit (pDevice);
842 /* Get the node address. First try to get in from the shared memory. */
843 /* If the signature is not present, then get it from the NVRAM. */
844 Value32 = MEM_RD_OFFSET (pDevice, T3_MAC_ADDR_HIGH_MAILBOX);
845 if ((Value32 >> 16) == 0x484b) {
847 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 8);
848 pDevice->NodeAddress[1] = (LM_UINT8) Value32;
850 Value32 = MEM_RD_OFFSET (pDevice, T3_MAC_ADDR_LOW_MAILBOX);
852 pDevice->NodeAddress[2] = (LM_UINT8) (Value32 >> 24);
853 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 16);
854 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 8);
855 pDevice->NodeAddress[5] = (LM_UINT8) Value32;
857 Status = LM_STATUS_SUCCESS;
859 Status = LM_NvramRead (pDevice, 0x7c, &Value32);
860 if (Status == LM_STATUS_SUCCESS) {
861 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 16);
862 pDevice->NodeAddress[1] = (LM_UINT8) (Value32 >> 24);
864 Status = LM_NvramRead (pDevice, 0x80, &Value32);
866 pDevice->NodeAddress[2] = (LM_UINT8) Value32;
867 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 8);
868 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 16);
869 pDevice->NodeAddress[5] = (LM_UINT8) (Value32 >> 24);
873 /* Assign a default address. */
874 if (Status != LM_STATUS_SUCCESS) {
877 "Cannot get MAC addr from NVRAM. Using default.\n");
879 pDevice->NodeAddress[0] = 0x00;
880 pDevice->NodeAddress[1] = 0x10;
881 pDevice->NodeAddress[2] = 0x18;
882 pDevice->NodeAddress[3] = 0x68;
883 pDevice->NodeAddress[4] = 0x61;
884 pDevice->NodeAddress[5] = 0x76;
887 pDevice->PermanentNodeAddress[0] = pDevice->NodeAddress[0];
888 pDevice->PermanentNodeAddress[1] = pDevice->NodeAddress[1];
889 pDevice->PermanentNodeAddress[2] = pDevice->NodeAddress[2];
890 pDevice->PermanentNodeAddress[3] = pDevice->NodeAddress[3];
891 pDevice->PermanentNodeAddress[4] = pDevice->NodeAddress[4];
892 pDevice->PermanentNodeAddress[5] = pDevice->NodeAddress[5];
894 /* Initialize the default values. */
895 pDevice->NoTxPseudoHdrChksum = FALSE;
896 pDevice->NoRxPseudoHdrChksum = FALSE;
897 pDevice->NicSendBd = FALSE;
898 pDevice->TxPacketDescCnt = DEFAULT_TX_PACKET_DESC_COUNT;
899 pDevice->RxStdDescCnt = DEFAULT_STD_RCV_DESC_COUNT;
900 pDevice->RxCoalescingTicks = DEFAULT_RX_COALESCING_TICKS;
901 pDevice->TxCoalescingTicks = DEFAULT_TX_COALESCING_TICKS;
902 pDevice->RxMaxCoalescedFrames = DEFAULT_RX_MAX_COALESCED_FRAMES;
903 pDevice->TxMaxCoalescedFrames = DEFAULT_TX_MAX_COALESCED_FRAMES;
904 pDevice->RxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
905 pDevice->TxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
906 pDevice->RxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
907 pDevice->TxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
908 pDevice->StatsCoalescingTicks = DEFAULT_STATS_COALESCING_TICKS;
909 pDevice->EnableMWI = FALSE;
910 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
911 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
912 pDevice->DisableAutoNeg = FALSE;
913 pDevice->PhyIntMode = T3_PHY_INT_MODE_AUTO;
914 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_AUTO;
915 pDevice->LedMode = LED_MODE_AUTO;
916 pDevice->ResetPhyOnInit = TRUE;
917 pDevice->DelayPciGrant = TRUE;
918 pDevice->UseTaggedStatus = FALSE;
919 pDevice->OneDmaAtOnce = BAD_DEFAULT_VALUE;
921 pDevice->DmaMbufLowMark = T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO;
922 pDevice->RxMacMbufLowMark = T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO;
923 pDevice->MbufHighMark = T3_DEF_MBUF_HIGH_WMARK_JUMBO;
925 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_AUTO;
926 pDevice->TaskOffloadCap = LM_TASK_OFFLOAD_NONE;
927 pDevice->FlowControlCap = LM_FLOW_CONTROL_AUTO_PAUSE;
928 pDevice->EnableTbi = FALSE;
929 #if INCLUDE_TBI_SUPPORT
930 pDevice->PollTbiLink = BAD_DEFAULT_VALUE;
933 switch (T3_ASIC_REV (pDevice->ChipRevId)) {
934 case T3_ASIC_REV_5704:
935 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
936 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE64;
939 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
940 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE96;
944 pDevice->LinkStatus = LM_STATUS_LINK_DOWN;
945 pDevice->QueueRxPackets = TRUE;
947 pDevice->EnableWireSpeed = TRUE;
949 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
950 pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
951 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
953 /* Make this is a known adapter. */
954 pAdapterInfo = LM_GetAdapterInfoBySsid (pDevice->SubsystemVendorId,
955 pDevice->SubsystemId);
957 pDevice->BondId = REG_RD (pDevice, Grc.MiscCfg) & GRC_MISC_BD_ID_MASK;
958 if (pDevice->BondId != GRC_MISC_BD_ID_5700 &&
959 pDevice->BondId != GRC_MISC_BD_ID_5701 &&
960 pDevice->BondId != GRC_MISC_BD_ID_5702FE &&
961 pDevice->BondId != GRC_MISC_BD_ID_5703 &&
962 pDevice->BondId != GRC_MISC_BD_ID_5703S &&
963 pDevice->BondId != GRC_MISC_BD_ID_5704 &&
964 pDevice->BondId != GRC_MISC_BD_ID_5704CIOBE) {
965 return LM_STATUS_UNKNOWN_ADAPTER;
968 pDevice->SplitModeEnable = SPLIT_MODE_DISABLE;
969 if ((pDevice->ChipRevId == T3_CHIP_ID_5704_A0) &&
970 (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE)) {
971 pDevice->SplitModeEnable = SPLIT_MODE_ENABLE;
972 pDevice->SplitModeMaxReq = SPLIT_MODE_5704_MAX_REQ;
975 /* Get Eeprom info. */
976 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_SIG_ADDR);
977 if (Value32 == T3_NIC_DATA_SIG) {
979 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_NIC_CFG_ADDR);
981 /* Determine PHY type. */
982 switch (Value32 & T3_NIC_CFG_PHY_TYPE_MASK) {
983 case T3_NIC_CFG_PHY_TYPE_COPPER:
984 EePhyTypeSerdes = FALSE;
987 case T3_NIC_CFG_PHY_TYPE_FIBER:
988 EePhyTypeSerdes = TRUE;
992 EePhyTypeSerdes = FALSE;
996 /* Determine PHY led mode. */
997 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
998 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
999 switch (Value32 & T3_NIC_CFG_LED_MODE_MASK) {
1000 case T3_NIC_CFG_LED_MODE_TRIPLE_SPEED:
1001 EePhyLedMode = LED_MODE_THREE_LINK;
1004 case T3_NIC_CFG_LED_MODE_LINK_SPEED:
1005 EePhyLedMode = LED_MODE_LINK10;
1009 EePhyLedMode = LED_MODE_AUTO;
1013 switch (Value32 & T3_NIC_CFG_LED_MODE_MASK) {
1014 case T3_NIC_CFG_LED_MODE_OPEN_DRAIN:
1015 EePhyLedMode = LED_MODE_OPEN_DRAIN;
1018 case T3_NIC_CFG_LED_MODE_OUTPUT:
1019 EePhyLedMode = LED_MODE_OUTPUT;
1023 EePhyLedMode = LED_MODE_AUTO;
1027 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1028 pDevice->ChipRevId == T3_CHIP_ID_5703_A2) {
1029 /* Enable EEPROM write protection. */
1030 if (Value32 & T3_NIC_EEPROM_WP) {
1031 pDevice->EepromWp = TRUE;
1035 /* Get the PHY Id. */
1036 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_PHY_ID_ADDR);
1038 EePhyId = (((Value32 & T3_NIC_PHY_ID1_MASK) >> 16) &
1039 PHY_ID1_OUI_MASK) << 10;
1041 Value32 = Value32 & T3_NIC_PHY_ID2_MASK;
1043 EePhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1044 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 &
1053 /* Set the PHY address. */
1054 pDevice->PhyAddr = PHY_DEVICE_ID;
1056 /* Disable auto polling. */
1057 pDevice->MiMode = 0xc0000;
1058 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
1061 /* Get the PHY id. */
1062 LM_ReadPhy (pDevice, PHY_ID1_REG, &Value32);
1063 pDevice->PhyId = (Value32 & PHY_ID1_OUI_MASK) << 10;
1065 LM_ReadPhy (pDevice, PHY_ID2_REG, &Value32);
1066 pDevice->PhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1067 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 & PHY_ID2_REV_MASK);
1069 /* Set the EnableTbi flag to false if we have a copper PHY. */
1070 switch (pDevice->PhyId & PHY_ID_MASK) {
1071 case PHY_BCM5400_PHY_ID:
1072 pDevice->EnableTbi = FALSE;
1075 case PHY_BCM5401_PHY_ID:
1076 pDevice->EnableTbi = FALSE;
1079 case PHY_BCM5411_PHY_ID:
1080 pDevice->EnableTbi = FALSE;
1083 case PHY_BCM5701_PHY_ID:
1084 pDevice->EnableTbi = FALSE;
1087 case PHY_BCM5703_PHY_ID:
1088 pDevice->EnableTbi = FALSE;
1091 case PHY_BCM5704_PHY_ID:
1092 pDevice->EnableTbi = FALSE;
1095 case PHY_BCM8002_PHY_ID:
1096 pDevice->EnableTbi = TRUE;
1102 pDevice->PhyId = pAdapterInfo->PhyId;
1103 pDevice->EnableTbi = pAdapterInfo->Serdes;
1104 } else if (EeSigFound) {
1105 pDevice->PhyId = EePhyId;
1106 pDevice->EnableTbi = EePhyTypeSerdes;
1111 /* Bail out if we don't know the copper PHY id. */
1112 if (UNKNOWN_PHY_ID (pDevice->PhyId) && !pDevice->EnableTbi) {
1113 return LM_STATUS_FAILURE;
1116 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5703) {
1117 if ((pDevice->SavedCacheLineReg & 0xff00) < 0x4000) {
1118 pDevice->SavedCacheLineReg &= 0xffff00ff;
1119 pDevice->SavedCacheLineReg |= 0x4000;
1122 /* Change driver parameters. */
1123 Status = MM_GetConfig (pDevice);
1124 if (Status != LM_STATUS_SUCCESS) {
1127 #if INCLUDE_5701_AX_FIX
1128 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1129 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
1130 pDevice->ResetPhyOnInit = TRUE;
1134 /* Save the current phy link status. */
1135 if (!pDevice->EnableTbi) {
1136 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
1137 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
1139 /* If we don't have link reset the PHY. */
1140 if (!(Value32 & PHY_STATUS_LINK_PASS)
1141 || pDevice->ResetPhyOnInit) {
1143 LM_WritePhy (pDevice, PHY_CTRL_REG, PHY_CTRL_PHY_RESET);
1145 for (j = 0; j < 100; j++) {
1148 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
1149 if (Value32 && !(Value32 & PHY_CTRL_PHY_RESET)) {
1155 #if INCLUDE_5701_AX_FIX
1156 /* 5701_AX_BX bug: only advertises 10mb speed. */
1157 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1158 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
1160 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
1161 PHY_AN_AD_10BASET_HALF |
1162 PHY_AN_AD_10BASET_FULL |
1163 PHY_AN_AD_100BASETX_FULL |
1164 PHY_AN_AD_100BASETX_HALF;
1165 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
1166 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
1167 pDevice->advertising = Value32;
1169 Value32 = BCM540X_AN_AD_1000BASET_HALF |
1170 BCM540X_AN_AD_1000BASET_FULL |
1171 BCM540X_CONFIG_AS_MASTER |
1172 BCM540X_ENABLE_CONFIG_AS_MASTER;
1173 LM_WritePhy (pDevice,
1174 BCM540X_1000BASET_CTRL_REG,
1176 pDevice->advertising1000 = Value32;
1178 LM_WritePhy (pDevice, PHY_CTRL_REG,
1179 PHY_CTRL_AUTO_NEG_ENABLE |
1180 PHY_CTRL_RESTART_AUTO_NEG);
1183 if (T3_ASIC_REV (pDevice->ChipRevId) ==
1185 LM_WritePhy (pDevice, 0x18, 0x0c00);
1186 LM_WritePhy (pDevice, 0x17, 0x201f);
1187 LM_WritePhy (pDevice, 0x15, 0x2aaa);
1189 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
1190 LM_WritePhy (pDevice, 0x1c, 0x8d68);
1191 LM_WritePhy (pDevice, 0x1c, 0x8d68);
1193 /* Enable Ethernet@WireSpeed. */
1194 if (pDevice->EnableWireSpeed) {
1195 LM_WritePhy (pDevice, 0x18, 0x7007);
1196 LM_ReadPhy (pDevice, 0x18, &Value32);
1197 LM_WritePhy (pDevice, 0x18,
1198 Value32 | BIT_15 | BIT_4);
1203 /* Turn off tap power management. */
1204 if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID) {
1205 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x0c20);
1206 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
1207 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1804);
1208 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
1209 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1204);
1210 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1211 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0132);
1212 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1213 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0232);
1214 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
1215 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
1219 #if INCLUDE_TBI_SUPPORT
1220 pDevice->IgnoreTbiLinkChange = FALSE;
1222 if (pDevice->EnableTbi) {
1223 pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_NONE;
1224 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
1225 if ((pDevice->PollTbiLink == BAD_DEFAULT_VALUE) ||
1226 pDevice->DisableAutoNeg) {
1227 pDevice->PollTbiLink = FALSE;
1230 pDevice->PollTbiLink = FALSE;
1232 #endif /* INCLUDE_TBI_SUPPORT */
1234 /* UseTaggedStatus is only valid for 5701 and later. */
1235 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1236 pDevice->UseTaggedStatus = FALSE;
1238 pDevice->CoalesceMode = 0;
1240 pDevice->CoalesceMode =
1241 HOST_COALESCE_CLEAR_TICKS_ON_RX_BD_EVENT |
1242 HOST_COALESCE_CLEAR_TICKS_ON_TX_BD_EVENT;
1245 /* Set the status block size. */
1246 if (T3_CHIP_REV (pDevice->ChipRevId) != T3_CHIP_REV_5700_AX &&
1247 T3_CHIP_REV (pDevice->ChipRevId) != T3_CHIP_REV_5700_BX) {
1248 pDevice->CoalesceMode |= HOST_COALESCE_32_BYTE_STATUS_MODE;
1251 /* Check the DURING_INT coalescing ticks parameters. */
1252 if (pDevice->UseTaggedStatus) {
1253 if (pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1254 pDevice->RxCoalescingTicksDuringInt =
1255 DEFAULT_RX_COALESCING_TICKS_DURING_INT;
1258 if (pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1259 pDevice->TxCoalescingTicksDuringInt =
1260 DEFAULT_TX_COALESCING_TICKS_DURING_INT;
1263 if (pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1264 pDevice->RxMaxCoalescedFramesDuringInt =
1265 DEFAULT_RX_MAX_COALESCED_FRAMES_DURING_INT;
1268 if (pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1269 pDevice->TxMaxCoalescedFramesDuringInt =
1270 DEFAULT_TX_MAX_COALESCED_FRAMES_DURING_INT;
1273 if (pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1274 pDevice->RxCoalescingTicksDuringInt = 0;
1277 if (pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1278 pDevice->TxCoalescingTicksDuringInt = 0;
1281 if (pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1282 pDevice->RxMaxCoalescedFramesDuringInt = 0;
1285 if (pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1286 pDevice->TxMaxCoalescedFramesDuringInt = 0;
1290 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1291 if (pDevice->RxMtu <= (MAX_STD_RCV_BUFFER_SIZE - 8 /* CRC */ )) {
1292 pDevice->RxJumboDescCnt = 0;
1293 if (pDevice->RxMtu <= MAX_ETHERNET_PACKET_SIZE_NO_CRC) {
1294 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1297 pDevice->RxJumboBufferSize =
1298 (pDevice->RxMtu + 8 /* CRC + VLAN */ +
1299 COMMON_CACHE_LINE_SIZE - 1) & ~COMMON_CACHE_LINE_MASK;
1301 if (pDevice->RxJumboBufferSize > MAX_JUMBO_RCV_BUFFER_SIZE) {
1302 pDevice->RxJumboBufferSize =
1303 DEFAULT_JUMBO_RCV_BUFFER_SIZE;
1305 pDevice->RxJumboBufferSize - 8 /* CRC + VLAN */ ;
1307 pDevice->TxMtu = pDevice->RxMtu;
1311 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1312 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1314 pDevice->RxPacketDescCnt =
1315 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1316 pDevice->RxJumboDescCnt +
1317 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1318 pDevice->RxStdDescCnt;
1320 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_SIZE_NO_CRC) {
1321 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1324 if (pDevice->TxMtu > MAX_JUMBO_TX_BUFFER_SIZE) {
1325 pDevice->TxMtu = MAX_JUMBO_TX_BUFFER_SIZE;
1328 /* Configure the proper ways to get link change interrupt. */
1329 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO) {
1330 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1331 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1333 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
1335 } else if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
1336 /* Auto-polling does not work on 5700_AX and 5700_BX. */
1337 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1338 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1342 /* Determine the method to get link change status. */
1343 if (pDevice->LinkChngMode == T3_LINK_CHNG_MODE_AUTO) {
1344 /* The link status bit in the status block does not work on 5700_AX */
1345 /* and 5700_BX chips. */
1346 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1347 pDevice->LinkChngMode =
1348 T3_LINK_CHNG_MODE_USE_STATUS_REG;
1350 pDevice->LinkChngMode =
1351 T3_LINK_CHNG_MODE_USE_STATUS_BLOCK;
1355 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT ||
1356 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1357 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_REG;
1360 /* Configure PHY led mode. */
1361 if (pDevice->LedMode == LED_MODE_AUTO) {
1362 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1363 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
1364 if (pDevice->SubsystemVendorId == T3_SVID_DELL) {
1365 pDevice->LedMode = LED_MODE_LINK10;
1367 pDevice->LedMode = LED_MODE_THREE_LINK;
1369 if (EeSigFound && EePhyLedMode != LED_MODE_AUTO) {
1370 pDevice->LedMode = EePhyLedMode;
1374 /* bug? 5701 in LINK10 mode does not seem to work when */
1375 /* PhyIntMode is LINK_READY. */
1376 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700
1378 #if INCLUDE_TBI_SUPPORT
1379 pDevice->EnableTbi == FALSE &&
1381 pDevice->LedMode == LED_MODE_LINK10) {
1382 pDevice->PhyIntMode =
1383 T3_PHY_INT_MODE_MI_INTERRUPT;
1384 pDevice->LinkChngMode =
1385 T3_LINK_CHNG_MODE_USE_STATUS_REG;
1388 if (pDevice->EnableTbi) {
1389 pDevice->LedMode = LED_MODE_THREE_LINK;
1392 if (EeSigFound && EePhyLedMode != LED_MODE_AUTO) {
1393 pDevice->LedMode = EePhyLedMode;
1395 pDevice->LedMode = LED_MODE_OPEN_DRAIN;
1400 /* Enable OneDmaAtOnce. */
1401 if (pDevice->OneDmaAtOnce == BAD_DEFAULT_VALUE) {
1402 pDevice->OneDmaAtOnce = FALSE;
1405 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1406 pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1407 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
1408 pDevice->ChipRevId == T3_CHIP_ID_5701_B2) {
1409 pDevice->WolSpeed = WOL_SPEED_10MB;
1411 pDevice->WolSpeed = WOL_SPEED_100MB;
1415 pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
1417 /* Turn off task offloading on Ax. */
1418 if (pDevice->ChipRevId == T3_CHIP_ID_5700_B0) {
1419 pDevice->TaskOffloadCap &= ~(LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
1420 LM_TASK_OFFLOAD_TX_UDP_CHECKSUM);
1422 pDevice->PciState = REG_RD (pDevice, PciCfg.PciState);
1423 LM_ReadVPD (pDevice);
1424 LM_ReadBootCodeVersion (pDevice);
1425 LM_GetBusSpeed (pDevice);
1427 return LM_STATUS_SUCCESS;
1428 } /* LM_GetAdapterInfo */
1430 STATIC PLM_ADAPTER_INFO LM_GetAdapterInfoBySsid (LM_UINT16 Svid, LM_UINT16 Ssid)
1432 static LM_ADAPTER_INFO AdapterArr[] = {
1433 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A6,
1434 PHY_BCM5401_PHY_ID, 0},
1435 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A5,
1436 PHY_BCM5701_PHY_ID, 0},
1437 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700T6,
1438 PHY_BCM8002_PHY_ID, 1},
1439 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A9, 0, 1},
1440 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T1,
1441 PHY_BCM5701_PHY_ID, 0},
1442 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T8,
1443 PHY_BCM5701_PHY_ID, 0},
1444 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A7, 0, 1},
1445 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A10,
1446 PHY_BCM5701_PHY_ID, 0},
1447 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A12,
1448 PHY_BCM5701_PHY_ID, 0},
1449 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax1,
1450 PHY_BCM5701_PHY_ID, 0},
1451 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax2,
1452 PHY_BCM5701_PHY_ID, 0},
1454 {T3_SVID_3COM, T3_SSID_3COM_3C996T, PHY_BCM5401_PHY_ID, 0},
1455 {T3_SVID_3COM, T3_SSID_3COM_3C996BT, PHY_BCM5701_PHY_ID, 0},
1456 {T3_SVID_3COM, T3_SSID_3COM_3C996SX, 0, 1},
1457 {T3_SVID_3COM, T3_SSID_3COM_3C1000T, PHY_BCM5701_PHY_ID, 0},
1458 {T3_SVID_3COM, T3_SSID_3COM_3C940BR01, PHY_BCM5701_PHY_ID, 0},
1460 {T3_SVID_DELL, T3_SSID_DELL_VIPER, PHY_BCM5401_PHY_ID, 0},
1461 {T3_SVID_DELL, T3_SSID_DELL_JAGUAR, PHY_BCM5401_PHY_ID, 0},
1462 {T3_SVID_DELL, T3_SSID_DELL_MERLOT, PHY_BCM5411_PHY_ID, 0},
1463 {T3_SVID_DELL, T3_SSID_DELL_SLIM_MERLOT, PHY_BCM5411_PHY_ID, 0},
1465 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE, PHY_BCM5701_PHY_ID, 0},
1466 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE_2, PHY_BCM5701_PHY_ID,
1468 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_CHANGELING, 0, 1},
1469 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780, PHY_BCM5701_PHY_ID, 0},
1470 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780_2, PHY_BCM5701_PHY_ID,
1476 for (j = 0; j < sizeof (AdapterArr) / sizeof (LM_ADAPTER_INFO); j++) {
1477 if (AdapterArr[j].Svid == Svid && AdapterArr[j].Ssid == Ssid) {
1478 return &AdapterArr[j];
1485 /******************************************************************************/
1487 /* This routine sets up receive/transmit buffer descriptions queues. */
1490 /* LM_STATUS_SUCCESS */
1491 /******************************************************************************/
1492 LM_STATUS LM_InitializeAdapter (PLM_DEVICE_BLOCK pDevice)
1494 LM_PHYSICAL_ADDRESS MemPhy;
1501 /* Set power state to D0. */
1502 LM_SetPowerState (pDevice, LM_POWER_STATE_D0);
1504 /* Intialize the queues. */
1505 QQ_InitQueue (&pDevice->RxPacketReceivedQ.Container,
1506 MAX_RX_PACKET_DESC_COUNT);
1507 QQ_InitQueue (&pDevice->RxPacketFreeQ.Container,
1508 MAX_RX_PACKET_DESC_COUNT);
1510 QQ_InitQueue (&pDevice->TxPacketFreeQ.Container,
1511 MAX_TX_PACKET_DESC_COUNT);
1512 QQ_InitQueue (&pDevice->TxPacketActiveQ.Container,
1513 MAX_TX_PACKET_DESC_COUNT);
1514 QQ_InitQueue (&pDevice->TxPacketXmittedQ.Container,
1515 MAX_TX_PACKET_DESC_COUNT);
1517 /* Allocate shared memory for: status block, the buffers for receive */
1518 /* rings -- standard, mini, jumbo, and return rings. */
1519 Size = T3_STATUS_BLOCK_SIZE + sizeof (T3_STATS_BLOCK) +
1520 T3_STD_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD) +
1521 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1522 T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD) +
1523 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1524 T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1526 /* Memory for host based Send BD. */
1527 if (pDevice->NicSendBd == FALSE) {
1528 Size += sizeof (T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
1531 /* Allocate the memory block. */
1533 MM_AllocateSharedMemory (pDevice, Size, (PLM_VOID) & pMemVirt,
1535 if (Status != LM_STATUS_SUCCESS) {
1539 /* Program DMA Read/Write */
1540 if (pDevice->PciState & T3_PCI_STATE_NOT_PCI_X_BUS) {
1541 pDevice->DmaReadWriteCtrl = 0x763f000f;
1543 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5704) {
1544 pDevice->DmaReadWriteCtrl = 0x761f0000;
1546 pDevice->DmaReadWriteCtrl = 0x761b000f;
1548 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1549 pDevice->ChipRevId == T3_CHIP_ID_5703_A2) {
1550 pDevice->OneDmaAtOnce = TRUE;
1553 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5703) {
1554 pDevice->DmaReadWriteCtrl &= 0xfffffff0;
1557 if (pDevice->OneDmaAtOnce) {
1558 pDevice->DmaReadWriteCtrl |= DMA_CTRL_WRITE_ONE_DMA_AT_ONCE;
1560 REG_WR (pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
1562 if (LM_DmaTest (pDevice, pMemVirt, MemPhy, 0x400) != LM_STATUS_SUCCESS) {
1563 return LM_STATUS_FAILURE;
1567 pDevice->pStatusBlkVirt = (PT3_STATUS_BLOCK) pMemVirt;
1568 pDevice->StatusBlkPhy = MemPhy;
1569 pMemVirt += T3_STATUS_BLOCK_SIZE;
1570 LM_INC_PHYSICAL_ADDRESS (&MemPhy, T3_STATUS_BLOCK_SIZE);
1572 /* Statistics block. */
1573 pDevice->pStatsBlkVirt = (PT3_STATS_BLOCK) pMemVirt;
1574 pDevice->StatsBlkPhy = MemPhy;
1575 pMemVirt += sizeof (T3_STATS_BLOCK);
1576 LM_INC_PHYSICAL_ADDRESS (&MemPhy, sizeof (T3_STATS_BLOCK));
1578 /* Receive standard BD buffer. */
1579 pDevice->pRxStdBdVirt = (PT3_RCV_BD) pMemVirt;
1580 pDevice->RxStdBdPhy = MemPhy;
1582 pMemVirt += T3_STD_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1583 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1584 T3_STD_RCV_RCB_ENTRY_COUNT *
1585 sizeof (T3_RCV_BD));
1587 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1588 /* Receive jumbo BD buffer. */
1589 pDevice->pRxJumboBdVirt = (PT3_RCV_BD) pMemVirt;
1590 pDevice->RxJumboBdPhy = MemPhy;
1592 pMemVirt += T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1593 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1594 T3_JUMBO_RCV_RCB_ENTRY_COUNT *
1595 sizeof (T3_RCV_BD));
1596 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1598 /* Receive return BD buffer. */
1599 pDevice->pRcvRetBdVirt = (PT3_RCV_BD) pMemVirt;
1600 pDevice->RcvRetBdPhy = MemPhy;
1602 pMemVirt += T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1603 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1604 T3_RCV_RETURN_RCB_ENTRY_COUNT *
1605 sizeof (T3_RCV_BD));
1607 /* Set up Send BD. */
1608 if (pDevice->NicSendBd == FALSE) {
1609 pDevice->pSendBdVirt = (PT3_SND_BD) pMemVirt;
1610 pDevice->SendBdPhy = MemPhy;
1612 pMemVirt += sizeof (T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
1613 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1614 sizeof (T3_SND_BD) *
1615 T3_SEND_RCB_ENTRY_COUNT);
1617 pDevice->pSendBdVirt = (PT3_SND_BD)
1618 pDevice->pMemView->uIntMem.First32k.BufferDesc;
1619 pDevice->SendBdPhy.High = 0;
1620 pDevice->SendBdPhy.Low = T3_NIC_SND_BUFFER_DESC_ADDR;
1623 /* Allocate memory for packet descriptors. */
1624 Size = (pDevice->RxPacketDescCnt +
1625 pDevice->TxPacketDescCnt) * MM_PACKET_DESC_SIZE;
1626 Status = MM_AllocateMemory (pDevice, Size, (PLM_VOID *) & pPacket);
1627 if (Status != LM_STATUS_SUCCESS) {
1630 pDevice->pPacketDescBase = (PLM_VOID) pPacket;
1632 /* Create transmit packet descriptors from the memory block and add them */
1633 /* to the TxPacketFreeQ for each send ring. */
1634 for (j = 0; j < pDevice->TxPacketDescCnt; j++) {
1638 /* Queue the descriptor in the TxPacketFreeQ of the 'k' ring. */
1639 QQ_PushTail (&pDevice->TxPacketFreeQ.Container, pPacket);
1641 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1642 /* is the total size of the packet descriptor including the */
1643 /* os-specific extensions in the UM_PACKET structure. */
1645 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1648 /* Create receive packet descriptors from the memory block and add them */
1649 /* to the RxPacketFreeQ. Create the Standard packet descriptors. */
1650 for (j = 0; j < pDevice->RxStdDescCnt; j++) {
1651 /* Receive producer ring. */
1652 pPacket->u.Rx.RcvProdRing = T3_STD_RCV_PROD_RING;
1654 /* Receive buffer size. */
1655 pPacket->u.Rx.RxBufferSize = MAX_STD_RCV_BUFFER_SIZE;
1657 /* Add the descriptor to RxPacketFreeQ. */
1658 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
1660 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1661 /* is the total size of the packet descriptor including the */
1662 /* os-specific extensions in the UM_PACKET structure. */
1664 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1667 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1668 /* Create the Jumbo packet descriptors. */
1669 for (j = 0; j < pDevice->RxJumboDescCnt; j++) {
1670 /* Receive producer ring. */
1671 pPacket->u.Rx.RcvProdRing = T3_JUMBO_RCV_PROD_RING;
1673 /* Receive buffer size. */
1674 pPacket->u.Rx.RxBufferSize = pDevice->RxJumboBufferSize;
1676 /* Add the descriptor to RxPacketFreeQ. */
1677 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
1679 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1680 /* is the total size of the packet descriptor including the */
1681 /* os-specific extensions in the UM_PACKET structure. */
1683 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1685 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1687 /* Initialize the rest of the packet descriptors. */
1688 Status = MM_InitializeUmPackets (pDevice);
1689 if (Status != LM_STATUS_SUCCESS) {
1694 /* Default receive mask. */
1695 pDevice->ReceiveMask = LM_ACCEPT_MULTICAST | LM_ACCEPT_BROADCAST |
1698 /* Make sure we are in the first 32k memory window or NicSendBd. */
1699 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, 0);
1701 /* Initialize the hardware. */
1702 Status = LM_ResetAdapter (pDevice);
1703 if (Status != LM_STATUS_SUCCESS) {
1707 /* We are done with initialization. */
1708 pDevice->InitDone = TRUE;
1710 return LM_STATUS_SUCCESS;
1711 } /* LM_InitializeAdapter */
1713 /******************************************************************************/
1715 /* This function Enables/Disables a given block. */
1718 /* LM_STATUS_SUCCESS */
1719 /******************************************************************************/
1721 LM_CntrlBlock (PLM_DEVICE_BLOCK pDevice, LM_UINT32 mask, LM_UINT32 cntrl)
1723 LM_UINT32 j, i, data;
1724 LM_UINT32 MaxWaitCnt;
1729 for (i = 0; i < 32; i++) {
1730 if (!(mask & (1 << i)))
1734 case T3_BLOCK_DMA_RD:
1735 data = REG_RD (pDevice, DmaRead.Mode);
1736 if (cntrl == LM_DISABLE) {
1737 data &= ~DMA_READ_MODE_ENABLE;
1738 REG_WR (pDevice, DmaRead.Mode, data);
1739 for (j = 0; j < MaxWaitCnt; j++) {
1741 (REG_RD (pDevice, DmaRead.Mode) &
1742 DMA_READ_MODE_ENABLE))
1747 REG_WR (pDevice, DmaRead.Mode,
1748 data | DMA_READ_MODE_ENABLE);
1751 case T3_BLOCK_DMA_COMP:
1752 data = REG_RD (pDevice, DmaComp.Mode);
1753 if (cntrl == LM_DISABLE) {
1754 data &= ~DMA_COMP_MODE_ENABLE;
1755 REG_WR (pDevice, DmaComp.Mode, data);
1756 for (j = 0; j < MaxWaitCnt; j++) {
1758 (REG_RD (pDevice, DmaComp.Mode) &
1759 DMA_COMP_MODE_ENABLE))
1764 REG_WR (pDevice, DmaComp.Mode,
1765 data | DMA_COMP_MODE_ENABLE);
1768 case T3_BLOCK_RX_BD_INITIATOR:
1769 data = REG_RD (pDevice, RcvBdIn.Mode);
1770 if (cntrl == LM_DISABLE) {
1771 data &= ~RCV_BD_IN_MODE_ENABLE;
1772 REG_WR (pDevice, RcvBdIn.Mode, data);
1773 for (j = 0; j < MaxWaitCnt; j++) {
1775 (REG_RD (pDevice, RcvBdIn.Mode) &
1776 RCV_BD_IN_MODE_ENABLE))
1781 REG_WR (pDevice, RcvBdIn.Mode,
1782 data | RCV_BD_IN_MODE_ENABLE);
1785 case T3_BLOCK_RX_BD_COMP:
1786 data = REG_RD (pDevice, RcvBdComp.Mode);
1787 if (cntrl == LM_DISABLE) {
1788 data &= ~RCV_BD_COMP_MODE_ENABLE;
1789 REG_WR (pDevice, RcvBdComp.Mode, data);
1790 for (j = 0; j < MaxWaitCnt; j++) {
1792 (REG_RD (pDevice, RcvBdComp.Mode) &
1793 RCV_BD_COMP_MODE_ENABLE))
1798 REG_WR (pDevice, RcvBdComp.Mode,
1799 data | RCV_BD_COMP_MODE_ENABLE);
1802 case T3_BLOCK_DMA_WR:
1803 data = REG_RD (pDevice, DmaWrite.Mode);
1804 if (cntrl == LM_DISABLE) {
1805 data &= ~DMA_WRITE_MODE_ENABLE;
1806 REG_WR (pDevice, DmaWrite.Mode, data);
1808 for (j = 0; j < MaxWaitCnt; j++) {
1810 (REG_RD (pDevice, DmaWrite.Mode) &
1811 DMA_WRITE_MODE_ENABLE))
1816 REG_WR (pDevice, DmaWrite.Mode,
1817 data | DMA_WRITE_MODE_ENABLE);
1820 case T3_BLOCK_MSI_HANDLER:
1821 data = REG_RD (pDevice, Msi.Mode);
1822 if (cntrl == LM_DISABLE) {
1823 data &= ~MSI_MODE_ENABLE;
1824 REG_WR (pDevice, Msi.Mode, data);
1825 for (j = 0; j < MaxWaitCnt; j++) {
1827 (REG_RD (pDevice, Msi.Mode) &
1833 REG_WR (pDevice, Msi.Mode,
1834 data | MSI_MODE_ENABLE);
1837 case T3_BLOCK_RX_LIST_PLMT:
1838 data = REG_RD (pDevice, RcvListPlmt.Mode);
1839 if (cntrl == LM_DISABLE) {
1840 data &= ~RCV_LIST_PLMT_MODE_ENABLE;
1841 REG_WR (pDevice, RcvListPlmt.Mode, data);
1842 for (j = 0; j < MaxWaitCnt; j++) {
1844 (REG_RD (pDevice, RcvListPlmt.Mode)
1845 & RCV_LIST_PLMT_MODE_ENABLE))
1850 REG_WR (pDevice, RcvListPlmt.Mode,
1851 data | RCV_LIST_PLMT_MODE_ENABLE);
1854 case T3_BLOCK_RX_LIST_SELECTOR:
1855 data = REG_RD (pDevice, RcvListSel.Mode);
1856 if (cntrl == LM_DISABLE) {
1857 data &= ~RCV_LIST_SEL_MODE_ENABLE;
1858 REG_WR (pDevice, RcvListSel.Mode, data);
1859 for (j = 0; j < MaxWaitCnt; j++) {
1861 (REG_RD (pDevice, RcvListSel.Mode) &
1862 RCV_LIST_SEL_MODE_ENABLE))
1867 REG_WR (pDevice, RcvListSel.Mode,
1868 data | RCV_LIST_SEL_MODE_ENABLE);
1871 case T3_BLOCK_RX_DATA_INITIATOR:
1872 data = REG_RD (pDevice, RcvDataBdIn.Mode);
1873 if (cntrl == LM_DISABLE) {
1874 data &= ~RCV_DATA_BD_IN_MODE_ENABLE;
1875 REG_WR (pDevice, RcvDataBdIn.Mode, data);
1876 for (j = 0; j < MaxWaitCnt; j++) {
1878 (REG_RD (pDevice, RcvDataBdIn.Mode)
1879 & RCV_DATA_BD_IN_MODE_ENABLE))
1884 REG_WR (pDevice, RcvDataBdIn.Mode,
1885 data | RCV_DATA_BD_IN_MODE_ENABLE);
1888 case T3_BLOCK_RX_DATA_COMP:
1889 data = REG_RD (pDevice, RcvDataComp.Mode);
1890 if (cntrl == LM_DISABLE) {
1891 data &= ~RCV_DATA_COMP_MODE_ENABLE;
1892 REG_WR (pDevice, RcvDataComp.Mode, data);
1893 for (j = 0; j < MaxWaitCnt; j++) {
1895 (REG_RD (pDevice, RcvDataBdIn.Mode)
1896 & RCV_DATA_COMP_MODE_ENABLE))
1901 REG_WR (pDevice, RcvDataComp.Mode,
1902 data | RCV_DATA_COMP_MODE_ENABLE);
1905 case T3_BLOCK_HOST_COALESING:
1906 data = REG_RD (pDevice, HostCoalesce.Mode);
1907 if (cntrl == LM_DISABLE) {
1908 data &= ~HOST_COALESCE_ENABLE;
1909 REG_WR (pDevice, HostCoalesce.Mode, data);
1910 for (j = 0; j < MaxWaitCnt; j++) {
1912 (REG_RD (pDevice, SndBdIn.Mode) &
1913 HOST_COALESCE_ENABLE))
1918 REG_WR (pDevice, HostCoalesce.Mode,
1919 data | HOST_COALESCE_ENABLE);
1922 case T3_BLOCK_MAC_RX_ENGINE:
1923 if (cntrl == LM_DISABLE) {
1924 pDevice->RxMode &= ~RX_MODE_ENABLE;
1925 REG_WR (pDevice, MacCtrl.RxMode,
1927 for (j = 0; j < MaxWaitCnt; j++) {
1929 (REG_RD (pDevice, MacCtrl.RxMode) &
1936 pDevice->RxMode |= RX_MODE_ENABLE;
1937 REG_WR (pDevice, MacCtrl.RxMode,
1942 case T3_BLOCK_MBUF_CLUSTER_FREE:
1943 data = REG_RD (pDevice, MbufClusterFree.Mode);
1944 if (cntrl == LM_DISABLE) {
1945 data &= ~MBUF_CLUSTER_FREE_MODE_ENABLE;
1946 REG_WR (pDevice, MbufClusterFree.Mode, data);
1947 for (j = 0; j < MaxWaitCnt; j++) {
1953 MBUF_CLUSTER_FREE_MODE_ENABLE))
1958 REG_WR (pDevice, MbufClusterFree.Mode,
1959 data | MBUF_CLUSTER_FREE_MODE_ENABLE);
1962 case T3_BLOCK_SEND_BD_INITIATOR:
1963 data = REG_RD (pDevice, SndBdIn.Mode);
1964 if (cntrl == LM_DISABLE) {
1965 data &= ~SND_BD_IN_MODE_ENABLE;
1966 REG_WR (pDevice, SndBdIn.Mode, data);
1967 for (j = 0; j < MaxWaitCnt; j++) {
1969 (REG_RD (pDevice, SndBdIn.Mode) &
1970 SND_BD_IN_MODE_ENABLE))
1975 REG_WR (pDevice, SndBdIn.Mode,
1976 data | SND_BD_IN_MODE_ENABLE);
1979 case T3_BLOCK_SEND_BD_COMP:
1980 data = REG_RD (pDevice, SndBdComp.Mode);
1981 if (cntrl == LM_DISABLE) {
1982 data &= ~SND_BD_COMP_MODE_ENABLE;
1983 REG_WR (pDevice, SndBdComp.Mode, data);
1984 for (j = 0; j < MaxWaitCnt; j++) {
1986 (REG_RD (pDevice, SndBdComp.Mode) &
1987 SND_BD_COMP_MODE_ENABLE))
1992 REG_WR (pDevice, SndBdComp.Mode,
1993 data | SND_BD_COMP_MODE_ENABLE);
1996 case T3_BLOCK_SEND_BD_SELECTOR:
1997 data = REG_RD (pDevice, SndBdSel.Mode);
1998 if (cntrl == LM_DISABLE) {
1999 data &= ~SND_BD_SEL_MODE_ENABLE;
2000 REG_WR (pDevice, SndBdSel.Mode, data);
2001 for (j = 0; j < MaxWaitCnt; j++) {
2003 (REG_RD (pDevice, SndBdSel.Mode) &
2004 SND_BD_SEL_MODE_ENABLE))
2009 REG_WR (pDevice, SndBdSel.Mode,
2010 data | SND_BD_SEL_MODE_ENABLE);
2013 case T3_BLOCK_SEND_DATA_INITIATOR:
2014 data = REG_RD (pDevice, SndDataIn.Mode);
2015 if (cntrl == LM_DISABLE) {
2016 data &= ~T3_SND_DATA_IN_MODE_ENABLE;
2017 REG_WR (pDevice, SndDataIn.Mode, data);
2018 for (j = 0; j < MaxWaitCnt; j++) {
2020 (REG_RD (pDevice, SndDataIn.Mode) &
2021 T3_SND_DATA_IN_MODE_ENABLE))
2026 REG_WR (pDevice, SndDataIn.Mode,
2027 data | T3_SND_DATA_IN_MODE_ENABLE);
2030 case T3_BLOCK_SEND_DATA_COMP:
2031 data = REG_RD (pDevice, SndDataComp.Mode);
2032 if (cntrl == LM_DISABLE) {
2033 data &= ~SND_DATA_COMP_MODE_ENABLE;
2034 REG_WR (pDevice, SndDataComp.Mode, data);
2035 for (j = 0; j < MaxWaitCnt; j++) {
2037 (REG_RD (pDevice, SndDataComp.Mode)
2038 & SND_DATA_COMP_MODE_ENABLE))
2043 REG_WR (pDevice, SndDataComp.Mode,
2044 data | SND_DATA_COMP_MODE_ENABLE);
2047 case T3_BLOCK_MAC_TX_ENGINE:
2048 if (cntrl == LM_DISABLE) {
2049 pDevice->TxMode &= ~TX_MODE_ENABLE;
2050 REG_WR (pDevice, MacCtrl.TxMode,
2052 for (j = 0; j < MaxWaitCnt; j++) {
2054 (REG_RD (pDevice, MacCtrl.TxMode) &
2060 pDevice->TxMode |= TX_MODE_ENABLE;
2061 REG_WR (pDevice, MacCtrl.TxMode,
2066 case T3_BLOCK_MEM_ARBITOR:
2067 data = REG_RD (pDevice, MemArbiter.Mode);
2068 if (cntrl == LM_DISABLE) {
2069 data &= ~T3_MEM_ARBITER_MODE_ENABLE;
2070 REG_WR (pDevice, MemArbiter.Mode, data);
2071 for (j = 0; j < MaxWaitCnt; j++) {
2073 (REG_RD (pDevice, MemArbiter.Mode) &
2074 T3_MEM_ARBITER_MODE_ENABLE))
2079 REG_WR (pDevice, MemArbiter.Mode,
2080 data | T3_MEM_ARBITER_MODE_ENABLE);
2083 case T3_BLOCK_MBUF_MANAGER:
2084 data = REG_RD (pDevice, BufMgr.Mode);
2085 if (cntrl == LM_DISABLE) {
2086 data &= ~BUFMGR_MODE_ENABLE;
2087 REG_WR (pDevice, BufMgr.Mode, data);
2088 for (j = 0; j < MaxWaitCnt; j++) {
2090 (REG_RD (pDevice, BufMgr.Mode) &
2091 BUFMGR_MODE_ENABLE))
2096 REG_WR (pDevice, BufMgr.Mode,
2097 data | BUFMGR_MODE_ENABLE);
2100 case T3_BLOCK_MAC_GLOBAL:
2101 if (cntrl == LM_DISABLE) {
2102 pDevice->MacMode &= ~(MAC_MODE_ENABLE_TDE |
2103 MAC_MODE_ENABLE_RDE |
2104 MAC_MODE_ENABLE_FHDE);
2106 pDevice->MacMode |= (MAC_MODE_ENABLE_TDE |
2107 MAC_MODE_ENABLE_RDE |
2108 MAC_MODE_ENABLE_FHDE);
2110 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
2114 return LM_STATUS_FAILURE;
2117 if (j >= MaxWaitCnt) {
2118 return LM_STATUS_FAILURE;
2122 return LM_STATUS_SUCCESS;
2125 /******************************************************************************/
2127 /* This function reinitializes the adapter. */
2130 /* LM_STATUS_SUCCESS */
2131 /******************************************************************************/
2132 LM_STATUS LM_ResetAdapter (PLM_DEVICE_BLOCK pDevice)
2138 /* Disable interrupt. */
2139 LM_DisableInterrupt (pDevice);
2141 /* May get a spurious interrupt */
2142 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED;
2144 /* Disable transmit and receive DMA engines. Abort all pending requests. */
2145 if (pDevice->InitDone) {
2149 pDevice->ShuttingDown = FALSE;
2151 LM_ResetChip (pDevice);
2153 /* Bug: Athlon fix for B3 silicon only. This bit does not do anything */
2154 /* in other chip revisions. */
2155 if (pDevice->DelayPciGrant) {
2156 Value32 = REG_RD (pDevice, PciCfg.ClockCtrl);
2157 REG_WR (pDevice, PciCfg.ClockCtrl, Value32 | BIT_31);
2160 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
2161 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
2162 Value32 = REG_RD (pDevice, PciCfg.PciState);
2163 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
2164 REG_WR (pDevice, PciCfg.PciState, Value32);
2168 /* Enable TaggedStatus mode. */
2169 if (pDevice->UseTaggedStatus) {
2170 pDevice->MiscHostCtrl |=
2171 MISC_HOST_CTRL_ENABLE_TAGGED_STATUS_MODE;
2174 /* Restore PCI configuration registers. */
2175 MM_WriteConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG,
2176 pDevice->SavedCacheLineReg);
2177 MM_WriteConfig32 (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
2178 (pDevice->SubsystemId << 16) | pDevice->
2181 /* Clear the statistics block. */
2182 for (j = 0x0300; j < 0x0b00; j++) {
2183 MEM_WR_OFFSET (pDevice, j, 0);
2186 /* Initialize the statistis Block */
2187 pDevice->pStatusBlkVirt->Status = 0;
2188 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
2189 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
2190 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
2192 for (j = 0; j < 16; j++) {
2193 pDevice->pStatusBlkVirt->Idx[j].RcvProdIdx = 0;
2194 pDevice->pStatusBlkVirt->Idx[j].SendConIdx = 0;
2197 for (k = 0; k < T3_STD_RCV_RCB_ENTRY_COUNT; k++) {
2198 pDevice->pRxStdBdVirt[k].HostAddr.High = 0;
2199 pDevice->pRxStdBdVirt[k].HostAddr.Low = 0;
2202 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2203 /* Receive jumbo BD buffer. */
2204 for (k = 0; k < T3_JUMBO_RCV_RCB_ENTRY_COUNT; k++) {
2205 pDevice->pRxJumboBdVirt[k].HostAddr.High = 0;
2206 pDevice->pRxJumboBdVirt[k].HostAddr.Low = 0;
2210 REG_WR (pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
2212 /* GRC mode control register. */
2213 #ifdef BIG_ENDIAN_PCI /* Jimmy, this ifdef block deleted in new code! */
2215 GRC_MODE_WORD_SWAP_DATA |
2216 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2217 GRC_MODE_INT_ON_MAC_ATTN | GRC_MODE_HOST_STACK_UP;
2219 /* No CPU Swap modes for PCI IO */
2221 #ifdef BIG_ENDIAN_HOST
2222 GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
2223 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2224 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA |
2226 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2227 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA |
2229 GRC_MODE_INT_ON_MAC_ATTN | GRC_MODE_HOST_STACK_UP;
2230 #endif /* !BIG_ENDIAN_PCI */
2232 /* Configure send BD mode. */
2233 if (pDevice->NicSendBd == FALSE) {
2234 Value32 |= GRC_MODE_HOST_SEND_BDS;
2236 Value32 |= GRC_MODE_4X_NIC_BASED_SEND_RINGS;
2239 /* Configure pseudo checksum mode. */
2240 if (pDevice->NoTxPseudoHdrChksum) {
2241 Value32 |= GRC_MODE_TX_NO_PSEUDO_HEADER_CHKSUM;
2244 if (pDevice->NoRxPseudoHdrChksum) {
2245 Value32 |= GRC_MODE_RX_NO_PSEUDO_HEADER_CHKSUM;
2248 REG_WR (pDevice, Grc.Mode, Value32);
2250 /* Setup the timer prescalar register. */
2251 REG_WR (pDevice, Grc.MiscCfg, 65 << 1); /* Clock is alwasy 66Mhz. */
2253 /* Set up the MBUF pool base address and size. */
2254 REG_WR (pDevice, BufMgr.MbufPoolAddr, pDevice->MbufBase);
2255 REG_WR (pDevice, BufMgr.MbufPoolSize, pDevice->MbufSize);
2257 /* Set up the DMA descriptor pool base address and size. */
2258 REG_WR (pDevice, BufMgr.DmaDescPoolAddr, T3_NIC_DMA_DESC_POOL_ADDR);
2259 REG_WR (pDevice, BufMgr.DmaDescPoolSize, T3_NIC_DMA_DESC_POOL_SIZE);
2261 /* Configure MBUF and Threshold watermarks */
2262 /* Configure the DMA read MBUF low water mark. */
2263 if (pDevice->DmaMbufLowMark) {
2264 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2265 pDevice->DmaMbufLowMark);
2267 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2268 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2269 T3_DEF_DMA_MBUF_LOW_WMARK);
2271 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2272 T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO);
2276 /* Configure the MAC Rx MBUF low water mark. */
2277 if (pDevice->RxMacMbufLowMark) {
2278 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2279 pDevice->RxMacMbufLowMark);
2281 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2282 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2283 T3_DEF_RX_MAC_MBUF_LOW_WMARK);
2285 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2286 T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO);
2290 /* Configure the MBUF high water mark. */
2291 if (pDevice->MbufHighMark) {
2292 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2293 pDevice->MbufHighMark);
2295 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2296 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2297 T3_DEF_MBUF_HIGH_WMARK);
2299 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2300 T3_DEF_MBUF_HIGH_WMARK_JUMBO);
2304 REG_WR (pDevice, BufMgr.DmaLowWaterMark, T3_DEF_DMA_DESC_LOW_WMARK);
2305 REG_WR (pDevice, BufMgr.DmaHighWaterMark, T3_DEF_DMA_DESC_HIGH_WMARK);
2307 /* Enable buffer manager. */
2308 REG_WR (pDevice, BufMgr.Mode,
2309 BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
2311 for (j = 0; j < 2000; j++) {
2312 if (REG_RD (pDevice, BufMgr.Mode) & BUFMGR_MODE_ENABLE)
2318 return LM_STATUS_FAILURE;
2321 /* Enable the FTQs. */
2322 REG_WR (pDevice, Ftq.Reset, 0xffffffff);
2323 REG_WR (pDevice, Ftq.Reset, 0);
2325 /* Wait until FTQ is ready */
2326 for (j = 0; j < 2000; j++) {
2327 if (REG_RD (pDevice, Ftq.Reset) == 0)
2333 return LM_STATUS_FAILURE;
2336 /* Initialize the Standard Receive RCB. */
2337 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.High,
2338 pDevice->RxStdBdPhy.High);
2339 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.Low,
2340 pDevice->RxStdBdPhy.Low);
2341 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.u.MaxLen_Flags,
2342 MAX_STD_RCV_BUFFER_SIZE << 16);
2344 /* Initialize the Jumbo Receive RCB. */
2345 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags,
2346 T3_RCB_FLAG_RING_DISABLED);
2347 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2348 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.High,
2349 pDevice->RxJumboBdPhy.High);
2350 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.Low,
2351 pDevice->RxJumboBdPhy.Low);
2353 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags, 0);
2355 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
2357 /* Initialize the Mini Receive RCB. */
2358 REG_WR (pDevice, RcvDataBdIn.MiniRcvRcb.u.MaxLen_Flags,
2359 T3_RCB_FLAG_RING_DISABLED);
2362 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.NicRingAddr,
2363 (LM_UINT32) T3_NIC_STD_RCV_BUFFER_DESC_ADDR);
2364 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.NicRingAddr,
2365 (LM_UINT32) T3_NIC_JUMBO_RCV_BUFFER_DESC_ADDR);
2368 /* Receive BD Ring replenish threshold. */
2369 REG_WR (pDevice, RcvBdIn.StdRcvThreshold, pDevice->RxStdDescCnt / 8);
2370 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2371 REG_WR (pDevice, RcvBdIn.JumboRcvThreshold,
2372 pDevice->RxJumboDescCnt / 8);
2373 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
2375 /* Disable all the unused rings. */
2376 for (j = 0; j < T3_MAX_SEND_RCB_COUNT; j++) {
2377 MEM_WR (pDevice, SendRcb[j].u.MaxLen_Flags,
2378 T3_RCB_FLAG_RING_DISABLED);
2381 /* Initialize the indices. */
2382 pDevice->SendProdIdx = 0;
2383 pDevice->SendConIdx = 0;
2385 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, 0);
2386 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, 0);
2388 /* Set up host or NIC based send RCB. */
2389 if (pDevice->NicSendBd == FALSE) {
2390 MEM_WR (pDevice, SendRcb[0].HostRingAddr.High,
2391 pDevice->SendBdPhy.High);
2392 MEM_WR (pDevice, SendRcb[0].HostRingAddr.Low,
2393 pDevice->SendBdPhy.Low);
2395 /* Set up the NIC ring address in the RCB. */
2396 MEM_WR (pDevice, SendRcb[0].NicRingAddr,
2397 T3_NIC_SND_BUFFER_DESC_ADDR);
2399 /* Setup the RCB. */
2400 MEM_WR (pDevice, SendRcb[0].u.MaxLen_Flags,
2401 T3_SEND_RCB_ENTRY_COUNT << 16);
2403 for (k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++) {
2404 pDevice->pSendBdVirt[k].HostAddr.High = 0;
2405 pDevice->pSendBdVirt[k].HostAddr.Low = 0;
2408 MEM_WR (pDevice, SendRcb[0].HostRingAddr.High, 0);
2409 MEM_WR (pDevice, SendRcb[0].HostRingAddr.Low, 0);
2410 MEM_WR (pDevice, SendRcb[0].NicRingAddr,
2411 pDevice->SendBdPhy.Low);
2413 for (k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++) {
2415 &(pDevice->pSendBdVirt[k].HostAddr.High));
2417 &(pDevice->pSendBdVirt[k].HostAddr.Low));
2419 &(pDevice->pSendBdVirt[k].u1.Len_Flags));
2420 pDevice->ShadowSendBd[k].HostAddr.High = 0;
2421 pDevice->ShadowSendBd[k].u1.Len_Flags = 0;
2424 atomic_set (&pDevice->SendBdLeft, T3_SEND_RCB_ENTRY_COUNT - 1);
2426 /* Configure the receive return rings. */
2427 for (j = 0; j < T3_MAX_RCV_RETURN_RCB_COUNT; j++) {
2428 MEM_WR (pDevice, RcvRetRcb[j].u.MaxLen_Flags,
2429 T3_RCB_FLAG_RING_DISABLED);
2432 pDevice->RcvRetConIdx = 0;
2434 MEM_WR (pDevice, RcvRetRcb[0].HostRingAddr.High,
2435 pDevice->RcvRetBdPhy.High);
2436 MEM_WR (pDevice, RcvRetRcb[0].HostRingAddr.Low,
2437 pDevice->RcvRetBdPhy.Low);
2439 /* Set up the NIC ring address in the RCB. */
2440 /* Not very clear from the spec. I am guessing that for Receive */
2441 /* Return Ring, NicRingAddr is not used. */
2442 MEM_WR (pDevice, RcvRetRcb[0].NicRingAddr, 0);
2444 /* Setup the RCB. */
2445 MEM_WR (pDevice, RcvRetRcb[0].u.MaxLen_Flags,
2446 T3_RCV_RETURN_RCB_ENTRY_COUNT << 16);
2448 /* Reinitialize RX ring producer index */
2449 MB_REG_WR (pDevice, Mailbox.RcvStdProdIdx.Low, 0);
2450 MB_REG_WR (pDevice, Mailbox.RcvJumboProdIdx.Low, 0);
2451 MB_REG_WR (pDevice, Mailbox.RcvMiniProdIdx.Low, 0);
2453 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2454 pDevice->RxJumboProdIdx = 0;
2455 pDevice->RxJumboQueuedCnt = 0;
2458 /* Reinitialize our copy of the indices. */
2459 pDevice->RxStdProdIdx = 0;
2460 pDevice->RxStdQueuedCnt = 0;
2462 #if T3_JUMBO_RCV_ENTRY_COUNT
2463 pDevice->RxJumboProdIdx = 0;
2464 #endif /* T3_JUMBO_RCV_ENTRY_COUNT */
2466 /* Configure the MAC address. */
2467 LM_SetMacAddress (pDevice, pDevice->NodeAddress);
2469 /* Initialize the transmit random backoff seed. */
2470 Value32 = (pDevice->NodeAddress[0] + pDevice->NodeAddress[1] +
2471 pDevice->NodeAddress[2] + pDevice->NodeAddress[3] +
2472 pDevice->NodeAddress[4] + pDevice->NodeAddress[5]) &
2473 MAC_TX_BACKOFF_SEED_MASK;
2474 REG_WR (pDevice, MacCtrl.TxBackoffSeed, Value32);
2476 /* Receive MTU. Frames larger than the MTU is marked as oversized. */
2477 REG_WR (pDevice, MacCtrl.MtuSize, pDevice->RxMtu + 8); /* CRC + VLAN. */
2479 /* Configure Time slot/IPG per 802.3 */
2480 REG_WR (pDevice, MacCtrl.TxLengths, 0x2620);
2483 * Configure Receive Rules so that packets don't match
2484 * Programmble rule will be queued to Return Ring 1
2486 REG_WR (pDevice, MacCtrl.RcvRuleCfg, RX_RULE_DEFAULT_CLASS);
2489 * Configure to have 16 Classes of Services (COS) and one
2490 * queue per class. Bad frames are queued to RRR#1.
2491 * And frames don't match rules are also queued to COS#1.
2493 REG_WR (pDevice, RcvListPlmt.Config, 0x181);
2495 /* Enable Receive Placement Statistics */
2496 REG_WR (pDevice, RcvListPlmt.StatsEnableMask, 0xffffff);
2497 REG_WR (pDevice, RcvListPlmt.StatsCtrl, RCV_LIST_STATS_ENABLE);
2499 /* Enable Send Data Initator Statistics */
2500 REG_WR (pDevice, SndDataIn.StatsEnableMask, 0xffffff);
2501 REG_WR (pDevice, SndDataIn.StatsCtrl,
2502 T3_SND_DATA_IN_STATS_CTRL_ENABLE |
2503 T3_SND_DATA_IN_STATS_CTRL_FASTER_UPDATE);
2505 /* Disable the host coalescing state machine before configuring it's */
2507 REG_WR (pDevice, HostCoalesce.Mode, 0);
2508 for (j = 0; j < 2000; j++) {
2509 Value32 = REG_RD (pDevice, HostCoalesce.Mode);
2510 if (!(Value32 & HOST_COALESCE_ENABLE)) {
2516 /* Host coalescing configurations. */
2517 REG_WR (pDevice, HostCoalesce.RxCoalescingTicks,
2518 pDevice->RxCoalescingTicks);
2519 REG_WR (pDevice, HostCoalesce.TxCoalescingTicks,
2520 pDevice->TxCoalescingTicks);
2521 REG_WR (pDevice, HostCoalesce.RxMaxCoalescedFrames,
2522 pDevice->RxMaxCoalescedFrames);
2523 REG_WR (pDevice, HostCoalesce.TxMaxCoalescedFrames,
2524 pDevice->TxMaxCoalescedFrames);
2525 REG_WR (pDevice, HostCoalesce.RxCoalescedTickDuringInt,
2526 pDevice->RxCoalescingTicksDuringInt);
2527 REG_WR (pDevice, HostCoalesce.TxCoalescedTickDuringInt,
2528 pDevice->TxCoalescingTicksDuringInt);
2529 REG_WR (pDevice, HostCoalesce.RxMaxCoalescedFramesDuringInt,
2530 pDevice->RxMaxCoalescedFramesDuringInt);
2531 REG_WR (pDevice, HostCoalesce.TxMaxCoalescedFramesDuringInt,
2532 pDevice->TxMaxCoalescedFramesDuringInt);
2534 /* Initialize the address of the status block. The NIC will DMA */
2535 /* the status block to this memory which resides on the host. */
2536 REG_WR (pDevice, HostCoalesce.StatusBlkHostAddr.High,
2537 pDevice->StatusBlkPhy.High);
2538 REG_WR (pDevice, HostCoalesce.StatusBlkHostAddr.Low,
2539 pDevice->StatusBlkPhy.Low);
2541 /* Initialize the address of the statistics block. The NIC will DMA */
2542 /* the statistics to this block of memory. */
2543 REG_WR (pDevice, HostCoalesce.StatsBlkHostAddr.High,
2544 pDevice->StatsBlkPhy.High);
2545 REG_WR (pDevice, HostCoalesce.StatsBlkHostAddr.Low,
2546 pDevice->StatsBlkPhy.Low);
2548 REG_WR (pDevice, HostCoalesce.StatsCoalescingTicks,
2549 pDevice->StatsCoalescingTicks);
2551 REG_WR (pDevice, HostCoalesce.StatsBlkNicAddr, 0x300);
2552 REG_WR (pDevice, HostCoalesce.StatusBlkNicAddr, 0xb00);
2554 /* Enable Host Coalesing state machine */
2555 REG_WR (pDevice, HostCoalesce.Mode, HOST_COALESCE_ENABLE |
2556 pDevice->CoalesceMode);
2558 /* Enable the Receive BD Completion state machine. */
2559 REG_WR (pDevice, RcvBdComp.Mode, RCV_BD_COMP_MODE_ENABLE |
2560 RCV_BD_COMP_MODE_ATTN_ENABLE);
2562 /* Enable the Receive List Placement state machine. */
2563 REG_WR (pDevice, RcvListPlmt.Mode, RCV_LIST_PLMT_MODE_ENABLE);
2565 /* Enable the Receive List Selector state machine. */
2566 REG_WR (pDevice, RcvListSel.Mode, RCV_LIST_SEL_MODE_ENABLE |
2567 RCV_LIST_SEL_MODE_ATTN_ENABLE);
2569 /* Enable transmit DMA, clear statistics. */
2570 pDevice->MacMode = MAC_MODE_ENABLE_TX_STATISTICS |
2571 MAC_MODE_ENABLE_RX_STATISTICS | MAC_MODE_ENABLE_TDE |
2572 MAC_MODE_ENABLE_RDE | MAC_MODE_ENABLE_FHDE;
2573 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
2574 MAC_MODE_CLEAR_RX_STATISTICS | MAC_MODE_CLEAR_TX_STATISTICS);
2576 /* GRC miscellaneous local control register. */
2577 pDevice->GrcLocalCtrl = GRC_MISC_LOCAL_CTRL_INT_ON_ATTN |
2578 GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM;
2580 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2581 pDevice->GrcLocalCtrl |= GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
2582 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1;
2585 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
2588 /* Reset RX counters. */
2589 for (j = 0; j < sizeof (LM_RX_COUNTERS); j++) {
2590 ((PLM_UINT8) & pDevice->RxCounters)[j] = 0;
2593 /* Reset TX counters. */
2594 for (j = 0; j < sizeof (LM_TX_COUNTERS); j++) {
2595 ((PLM_UINT8) & pDevice->TxCounters)[j] = 0;
2598 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 0);
2600 /* Enable the DMA Completion state machine. */
2601 REG_WR (pDevice, DmaComp.Mode, DMA_COMP_MODE_ENABLE);
2603 /* Enable the DMA Write state machine. */
2604 Value32 = DMA_WRITE_MODE_ENABLE |
2605 DMA_WRITE_MODE_TARGET_ABORT_ATTN_ENABLE |
2606 DMA_WRITE_MODE_MASTER_ABORT_ATTN_ENABLE |
2607 DMA_WRITE_MODE_PARITY_ERROR_ATTN_ENABLE |
2608 DMA_WRITE_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2609 DMA_WRITE_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2610 DMA_WRITE_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2611 DMA_WRITE_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2612 DMA_WRITE_MODE_LONG_READ_ATTN_ENABLE;
2613 REG_WR (pDevice, DmaWrite.Mode, Value32);
2615 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
2616 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
2617 Value16 = REG_RD (pDevice, PciCfg.PciXCommand);
2619 ~(PCIX_CMD_MAX_SPLIT_MASK |
2620 PCIX_CMD_MAX_BURST_MASK);
2622 ((PCIX_CMD_MAX_BURST_CPIOB <<
2623 PCIX_CMD_MAX_BURST_SHL) &
2624 PCIX_CMD_MAX_BURST_MASK);
2625 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE) {
2628 SplitModeMaxReq << PCIX_CMD_MAX_SPLIT_SHL)
2629 & PCIX_CMD_MAX_SPLIT_MASK;
2631 REG_WR (pDevice, PciCfg.PciXCommand, Value16);
2635 /* Enable the Read DMA state machine. */
2636 Value32 = DMA_READ_MODE_ENABLE |
2637 DMA_READ_MODE_TARGET_ABORT_ATTN_ENABLE |
2638 DMA_READ_MODE_MASTER_ABORT_ATTN_ENABLE |
2639 DMA_READ_MODE_PARITY_ERROR_ATTN_ENABLE |
2640 DMA_READ_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2641 DMA_READ_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2642 DMA_READ_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2643 DMA_READ_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2644 DMA_READ_MODE_LONG_READ_ATTN_ENABLE;
2646 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE) {
2647 Value32 |= DMA_READ_MODE_SPLIT_ENABLE;
2649 REG_WR (pDevice, DmaRead.Mode, Value32);
2651 /* Enable the Receive Data Completion state machine. */
2652 REG_WR (pDevice, RcvDataComp.Mode, RCV_DATA_COMP_MODE_ENABLE |
2653 RCV_DATA_COMP_MODE_ATTN_ENABLE);
2655 /* Enable the Mbuf Cluster Free state machine. */
2656 REG_WR (pDevice, MbufClusterFree.Mode, MBUF_CLUSTER_FREE_MODE_ENABLE);
2658 /* Enable the Send Data Completion state machine. */
2659 REG_WR (pDevice, SndDataComp.Mode, SND_DATA_COMP_MODE_ENABLE);
2661 /* Enable the Send BD Completion state machine. */
2662 REG_WR (pDevice, SndBdComp.Mode, SND_BD_COMP_MODE_ENABLE |
2663 SND_BD_COMP_MODE_ATTN_ENABLE);
2665 /* Enable the Receive BD Initiator state machine. */
2666 REG_WR (pDevice, RcvBdIn.Mode, RCV_BD_IN_MODE_ENABLE |
2667 RCV_BD_IN_MODE_BD_IN_DIABLED_RCB_ATTN_ENABLE);
2669 /* Enable the Receive Data and Receive BD Initiator state machine. */
2670 REG_WR (pDevice, RcvDataBdIn.Mode, RCV_DATA_BD_IN_MODE_ENABLE |
2671 RCV_DATA_BD_IN_MODE_INVALID_RING_SIZE);
2673 /* Enable the Send Data Initiator state machine. */
2674 REG_WR (pDevice, SndDataIn.Mode, T3_SND_DATA_IN_MODE_ENABLE);
2676 /* Enable the Send BD Initiator state machine. */
2677 REG_WR (pDevice, SndBdIn.Mode, SND_BD_IN_MODE_ENABLE |
2678 SND_BD_IN_MODE_ATTN_ENABLE);
2680 /* Enable the Send BD Selector state machine. */
2681 REG_WR (pDevice, SndBdSel.Mode, SND_BD_SEL_MODE_ENABLE |
2682 SND_BD_SEL_MODE_ATTN_ENABLE);
2684 #if INCLUDE_5701_AX_FIX
2685 /* Load the firmware for the 5701_A0 workaround. */
2686 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0) {
2687 LM_LoadRlsFirmware (pDevice);
2691 /* Enable the transmitter. */
2692 pDevice->TxMode = TX_MODE_ENABLE;
2693 REG_WR (pDevice, MacCtrl.TxMode, pDevice->TxMode);
2695 /* Enable the receiver. */
2696 pDevice->RxMode = RX_MODE_ENABLE;
2697 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
2699 if (pDevice->RestoreOnWakeUp) {
2700 pDevice->RestoreOnWakeUp = FALSE;
2701 pDevice->DisableAutoNeg = pDevice->WakeUpDisableAutoNeg;
2702 pDevice->RequestedMediaType = pDevice->WakeUpRequestedMediaType;
2705 /* Disable auto polling. */
2706 pDevice->MiMode = 0xc0000;
2707 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
2709 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
2710 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
2711 Value32 = LED_CTRL_PHY_MODE_1;
2713 if (pDevice->LedMode == LED_MODE_OUTPUT) {
2714 Value32 = LED_CTRL_PHY_MODE_2;
2716 Value32 = LED_CTRL_PHY_MODE_1;
2719 REG_WR (pDevice, MacCtrl.LedCtrl, Value32);
2721 /* Activate Link to enable MAC state machine */
2722 REG_WR (pDevice, MacCtrl.MiStatus, MI_STATUS_ENABLE_LINK_STATUS_ATTN);
2724 if (pDevice->EnableTbi) {
2725 REG_WR (pDevice, MacCtrl.RxMode, RX_MODE_RESET);
2727 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
2728 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1) {
2729 REG_WR (pDevice, MacCtrl.SerdesCfg, 0x616000);
2732 /* Setup the phy chip. */
2733 LM_SetupPhy (pDevice);
2735 if (!pDevice->EnableTbi) {
2736 /* Clear CRC stats */
2737 LM_ReadPhy (pDevice, 0x1e, &Value32);
2738 LM_WritePhy (pDevice, 0x1e, Value32 | 0x8000);
2739 LM_ReadPhy (pDevice, 0x14, &Value32);
2742 /* Set up the receive mask. */
2743 LM_SetReceiveMask (pDevice, pDevice->ReceiveMask);
2745 /* Queue Rx packet buffers. */
2746 if (pDevice->QueueRxPackets) {
2747 LM_QueueRxPackets (pDevice);
2750 /* Enable interrupt to the host. */
2751 if (pDevice->InitDone) {
2752 LM_EnableInterrupt (pDevice);
2755 return LM_STATUS_SUCCESS;
2756 } /* LM_ResetAdapter */
2758 /******************************************************************************/
2760 /* This routine disables the adapter from generating interrupts. */
2763 /* LM_STATUS_SUCCESS */
2764 /******************************************************************************/
2765 LM_STATUS LM_DisableInterrupt (PLM_DEVICE_BLOCK pDevice)
2767 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl |
2768 MISC_HOST_CTRL_MASK_PCI_INT);
2769 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 1);
2771 return LM_STATUS_SUCCESS;
2774 /******************************************************************************/
2776 /* This routine enables the adapter to generate interrupts. */
2779 /* LM_STATUS_SUCCESS */
2780 /******************************************************************************/
2781 LM_STATUS LM_EnableInterrupt (PLM_DEVICE_BLOCK pDevice)
2783 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl &
2784 ~MISC_HOST_CTRL_MASK_PCI_INT);
2785 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 0);
2787 if (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
2788 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
2789 GRC_MISC_LOCAL_CTRL_SET_INT);
2792 return LM_STATUS_SUCCESS;
2795 /******************************************************************************/
2797 /* This routine puts a packet on the wire if there is a transmit DMA */
2798 /* descriptor available; otherwise the packet is queued for later */
2799 /* transmission. If the second argue is NULL, this routine will put */
2800 /* the queued packet on the wire if possible. */
2803 /* LM_STATUS_SUCCESS */
2804 /******************************************************************************/
2806 LM_STATUS LM_SendPacket (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
2808 LM_UINT32 FragCount;
2810 PT3_SND_BD pShadowSendBd;
2811 LM_UINT32 Value32, Len;
2814 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2815 return LM_5700SendPacket (pDevice, pPacket);
2818 /* Update the SendBdLeft count. */
2819 atomic_sub (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
2821 /* Initalize the send buffer descriptors. */
2822 Idx = pDevice->SendProdIdx;
2824 pSendBd = &pDevice->pSendBdVirt[Idx];
2826 /* Next producer index. */
2827 if (pDevice->NicSendBd == TRUE) {
2828 T3_64BIT_HOST_ADDR paddr;
2830 pShadowSendBd = &pDevice->ShadowSendBd[Idx];
2831 for (FragCount = 0;;) {
2832 MM_MapTxDma (pDevice, pPacket, &paddr, &Len, FragCount);
2833 /* Initialize the pointer to the send buffer fragment. */
2834 if (paddr.High != pShadowSendBd->HostAddr.High) {
2835 __raw_writel (paddr.High,
2836 &(pSendBd->HostAddr.High));
2837 pShadowSendBd->HostAddr.High = paddr.High;
2839 __raw_writel (paddr.Low, &(pSendBd->HostAddr.Low));
2841 /* Setup the control flags and send buffer size. */
2842 Value32 = (Len << 16) | pPacket->Flags;
2844 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
2847 if (FragCount >= pPacket->u.Tx.FragCount) {
2848 Value32 |= SND_BD_FLAG_END;
2849 if (Value32 != pShadowSendBd->u1.Len_Flags) {
2850 __raw_writel (Value32,
2851 &(pSendBd->u1.Len_Flags));
2852 pShadowSendBd->u1.Len_Flags = Value32;
2854 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
2855 __raw_writel (pPacket->VlanTag,
2856 &(pSendBd->u2.VlanTag));
2860 if (Value32 != pShadowSendBd->u1.Len_Flags) {
2861 __raw_writel (Value32,
2862 &(pSendBd->u1.Len_Flags));
2863 pShadowSendBd->u1.Len_Flags = Value32;
2865 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
2866 __raw_writel (pPacket->VlanTag,
2867 &(pSendBd->u2.VlanTag));
2874 pSendBd = &pDevice->pSendBdVirt[0];
2875 pShadowSendBd = &pDevice->ShadowSendBd[0];
2879 /* Put the packet descriptor in the ActiveQ. */
2880 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
2883 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
2886 for (FragCount = 0;;) {
2887 /* Initialize the pointer to the send buffer fragment. */
2888 MM_MapTxDma (pDevice, pPacket, &pSendBd->HostAddr, &Len,
2891 pSendBd->u2.VlanTag = pPacket->VlanTag;
2893 /* Setup the control flags and send buffer size. */
2894 Value32 = (Len << 16) | pPacket->Flags;
2896 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
2899 if (FragCount >= pPacket->u.Tx.FragCount) {
2900 pSendBd->u1.Len_Flags =
2901 Value32 | SND_BD_FLAG_END;
2904 pSendBd->u1.Len_Flags = Value32;
2908 pSendBd = &pDevice->pSendBdVirt[0];
2912 /* Put the packet descriptor in the ActiveQ. */
2913 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
2916 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
2920 /* Update the producer index. */
2921 pDevice->SendProdIdx = Idx;
2923 return LM_STATUS_SUCCESS;
2927 LM_STATUS LM_SendPacket (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
2929 LM_UINT32 FragCount;
2930 PT3_SND_BD pSendBd, pTmpSendBd, pShadowSendBd;
2931 T3_SND_BD NicSendBdArr[MAX_FRAGMENT_COUNT];
2932 LM_UINT32 StartIdx, Idx;
2935 /* Initalize the send buffer descriptors. */
2936 StartIdx = Idx = pDevice->SendProdIdx;
2938 if (pDevice->NicSendBd) {
2939 pTmpSendBd = pSendBd = &NicSendBdArr[0];
2941 pTmpSendBd = pSendBd = &pDevice->pSendBdVirt[Idx];
2944 /* Next producer index. */
2945 for (FragCount = 0;;) {
2946 LM_UINT32 Value32, Len;
2948 /* Initialize the pointer to the send buffer fragment. */
2949 MM_MapTxDma (pDevice, pPacket, &pSendBd->HostAddr, &Len,
2952 pSendBd->u2.VlanTag = pPacket->VlanTag;
2954 /* Setup the control flags and send buffer size. */
2955 Value32 = (Len << 16) | pPacket->Flags;
2957 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
2960 if (FragCount >= pPacket->u.Tx.FragCount) {
2961 pSendBd->u1.Len_Flags =
2962 Value32 | SND_BD_FLAG_END;
2965 pSendBd->u1.Len_Flags = Value32;
2968 if ((Idx == 0) && !pDevice->NicSendBd) {
2969 pSendBd = &pDevice->pSendBdVirt[0];
2972 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2973 if (LM_Test4GBoundary (pDevice, pPacket, pTmpSendBd) ==
2974 LM_STATUS_SUCCESS) {
2975 if (MM_CoalesceTxBuffer (pDevice, pPacket) !=
2976 LM_STATUS_SUCCESS) {
2977 QQ_PushHead (&pDevice->TxPacketFreeQ.
2978 Container, pPacket);
2979 return LM_STATUS_FAILURE;
2986 /* Put the packet descriptor in the ActiveQ. */
2987 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
2989 if (pDevice->NicSendBd) {
2990 pSendBd = &pDevice->pSendBdVirt[StartIdx];
2991 pShadowSendBd = &pDevice->ShadowSendBd[StartIdx];
2993 while (StartIdx != Idx) {
2996 if ((Value32 = pTmpSendBd->HostAddr.High) !=
2997 pShadowSendBd->HostAddr.High) {
2998 __raw_writel (Value32,
2999 &(pSendBd->HostAddr.High));
3000 pShadowSendBd->HostAddr.High = Value32;
3003 __raw_writel (pTmpSendBd->HostAddr.Low,
3004 &(pSendBd->HostAddr.Low));
3006 if ((Value32 = pTmpSendBd->u1.Len_Flags) !=
3007 pShadowSendBd->u1.Len_Flags) {
3008 __raw_writel (Value32,
3009 &(pSendBd->u1.Len_Flags));
3010 pShadowSendBd->u1.Len_Flags = Value32;
3013 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
3014 __raw_writel (pTmpSendBd->u2.VlanTag,
3015 &(pSendBd->u2.VlanTag));
3019 (StartIdx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3021 pSendBd = &pDevice->pSendBdVirt[0];
3027 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3029 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
3030 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3034 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
3036 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
3037 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low,
3042 /* Update the SendBdLeft count. */
3043 atomic_sub (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3045 /* Update the producer index. */
3046 pDevice->SendProdIdx = Idx;
3048 return LM_STATUS_SUCCESS;
3052 LM_Test4GBoundary (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket,
3056 LM_UINT32 Idx, Base, Len;
3058 Idx = pDevice->SendProdIdx;
3059 for (FragCount = 0;;) {
3060 Len = pSendBd->u1.Len_Flags >> 16;
3061 if (((Base = pSendBd->HostAddr.Low) > 0xffffdcc0) &&
3062 (pSendBd->HostAddr.High == 0) &&
3063 ((Base + 8 + Len) < Base)) {
3064 return LM_STATUS_SUCCESS;
3067 if (FragCount >= pPacket->u.Tx.FragCount) {
3071 if (!pDevice->NicSendBd) {
3072 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3074 pSendBd = &pDevice->pSendBdVirt[0];
3078 return LM_STATUS_FAILURE;
3081 /******************************************************************************/
3085 /******************************************************************************/
3086 __inline static unsigned long
3087 ComputeCrc32 (unsigned char *pBuffer, unsigned long BufferSize)
3095 for (j = 0; j < BufferSize; j++) {
3098 for (k = 0; k < 8; k++) {
3110 } /* ComputeCrc32 */
3112 /******************************************************************************/
3114 /* This routine sets the receive control register according to ReceiveMask */
3117 /* LM_STATUS_SUCCESS */
3118 /******************************************************************************/
3119 LM_STATUS LM_SetReceiveMask (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Mask)
3121 LM_UINT32 ReceiveMask;
3127 RxMode = pDevice->RxMode;
3129 if (Mask & LM_ACCEPT_UNICAST) {
3130 Mask &= ~LM_ACCEPT_UNICAST;
3133 if (Mask & LM_ACCEPT_MULTICAST) {
3134 Mask &= ~LM_ACCEPT_MULTICAST;
3137 if (Mask & LM_ACCEPT_ALL_MULTICAST) {
3138 Mask &= ~LM_ACCEPT_ALL_MULTICAST;
3141 if (Mask & LM_ACCEPT_BROADCAST) {
3142 Mask &= ~LM_ACCEPT_BROADCAST;
3145 RxMode &= ~RX_MODE_PROMISCUOUS_MODE;
3146 if (Mask & LM_PROMISCUOUS_MODE) {
3147 RxMode |= RX_MODE_PROMISCUOUS_MODE;
3148 Mask &= ~LM_PROMISCUOUS_MODE;
3151 RxMode &= ~(RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED);
3152 if (Mask & LM_ACCEPT_ERROR_PACKET) {
3153 RxMode |= RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED;
3154 Mask &= ~LM_ACCEPT_ERROR_PACKET;
3157 /* Make sure all the bits are valid before committing changes. */
3159 return LM_STATUS_FAILURE;
3162 /* Commit the new filter. */
3163 pDevice->RxMode = RxMode;
3164 REG_WR (pDevice, MacCtrl.RxMode, RxMode);
3166 pDevice->ReceiveMask = ReceiveMask;
3168 /* Set up the MC hash table. */
3169 if (ReceiveMask & LM_ACCEPT_ALL_MULTICAST) {
3170 for (k = 0; k < 4; k++) {
3171 REG_WR (pDevice, MacCtrl.HashReg[k], 0xffffffff);
3173 } else if (ReceiveMask & LM_ACCEPT_MULTICAST) {
3174 LM_UINT32 HashReg[4];
3180 for (j = 0; j < pDevice->McEntryCount; j++) {
3186 ComputeCrc32 (pDevice->McTable[j],
3187 ETHERNET_ADDRESS_SIZE);
3189 /* The most significant 7 bits of the CRC32 (no inversion), */
3190 /* are used to index into one of the possible 128 bit positions. */
3191 Bitpos = ~Crc32 & 0x7f;
3193 /* Hash register index. */
3194 RegIndex = (Bitpos & 0x60) >> 5;
3196 /* Bit to turn on within a hash register. */
3199 /* Enable the multicast bit. */
3200 HashReg[RegIndex] |= (1 << Bitpos);
3203 /* REV_AX has problem with multicast filtering where it uses both */
3204 /* DA and SA to perform hashing. */
3205 for (k = 0; k < 4; k++) {
3206 REG_WR (pDevice, MacCtrl.HashReg[k], HashReg[k]);
3209 /* Reject all multicast frames. */
3210 for (j = 0; j < 4; j++) {
3211 REG_WR (pDevice, MacCtrl.HashReg[j], 0);
3215 /* By default, Tigon3 will accept broadcast frames. We need to setup */
3216 if (ReceiveMask & LM_ACCEPT_BROADCAST) {
3218 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3219 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3221 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3222 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3224 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3225 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3227 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3228 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3231 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3232 REJECT_BROADCAST_RULE1_RULE);
3234 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3235 REJECT_BROADCAST_RULE1_VALUE);
3237 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3238 REJECT_BROADCAST_RULE2_RULE);
3240 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3241 REJECT_BROADCAST_RULE2_VALUE);
3244 /* disable the rest of the rules. */
3245 for (j = RCV_LAST_RULE_IDX; j < 16; j++) {
3246 REG_WR (pDevice, MacCtrl.RcvRules[j].Rule, 0);
3247 REG_WR (pDevice, MacCtrl.RcvRules[j].Value, 0);
3250 return LM_STATUS_SUCCESS;
3251 } /* LM_SetReceiveMask */
3253 /******************************************************************************/
3255 /* Disable the interrupt and put the transmitter and receiver engines in */
3256 /* an idle state. Also aborts all pending send requests and receive */
3260 /* LM_STATUS_SUCCESS */
3261 /******************************************************************************/
3262 LM_STATUS LM_Abort (PLM_DEVICE_BLOCK pDevice)
3267 LM_DisableInterrupt (pDevice);
3269 /* Disable all the state machines. */
3270 LM_CntrlBlock (pDevice, T3_BLOCK_MAC_RX_ENGINE, LM_DISABLE);
3271 LM_CntrlBlock (pDevice, T3_BLOCK_RX_BD_INITIATOR, LM_DISABLE);
3272 LM_CntrlBlock (pDevice, T3_BLOCK_RX_LIST_PLMT, LM_DISABLE);
3273 LM_CntrlBlock (pDevice, T3_BLOCK_RX_LIST_SELECTOR, LM_DISABLE);
3274 LM_CntrlBlock (pDevice, T3_BLOCK_RX_DATA_INITIATOR, LM_DISABLE);
3275 LM_CntrlBlock (pDevice, T3_BLOCK_RX_DATA_COMP, LM_DISABLE);
3276 LM_CntrlBlock (pDevice, T3_BLOCK_RX_BD_COMP, LM_DISABLE);
3278 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_SELECTOR, LM_DISABLE);
3279 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_INITIATOR, LM_DISABLE);
3280 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_DATA_INITIATOR, LM_DISABLE);
3281 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_RD, LM_DISABLE);
3282 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_DATA_COMP, LM_DISABLE);
3283 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_COMP, LM_DISABLE);
3284 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_COMP, LM_DISABLE);
3287 pDevice->MacMode &= ~MAC_MODE_ENABLE_TDE;
3288 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
3290 LM_CntrlBlock (pDevice, T3_BLOCK_MAC_TX_ENGINE, LM_DISABLE);
3291 LM_CntrlBlock (pDevice, T3_BLOCK_HOST_COALESING, LM_DISABLE);
3292 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_WR, LM_DISABLE);
3293 LM_CntrlBlock (pDevice, T3_BLOCK_MBUF_CLUSTER_FREE, LM_DISABLE);
3295 /* Reset all FTQs */
3296 REG_WR (pDevice, Ftq.Reset, 0xffffffff);
3297 REG_WR (pDevice, Ftq.Reset, 0x0);
3299 LM_CntrlBlock (pDevice, T3_BLOCK_MBUF_MANAGER, LM_DISABLE);
3300 LM_CntrlBlock (pDevice, T3_BLOCK_MEM_ARBITOR, LM_DISABLE);
3302 MM_ACQUIRE_INT_LOCK (pDevice);
3304 /* Abort packets that have already queued to go out. */
3305 pPacket = (PLM_PACKET) QQ_PopHead (&pDevice->TxPacketActiveQ.Container);
3308 pPacket->PacketStatus = LM_STATUS_TRANSMIT_ABORTED;
3309 pDevice->TxCounters.TxPacketAbortedCnt++;
3311 atomic_add (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3313 QQ_PushTail (&pDevice->TxPacketXmittedQ.Container, pPacket);
3315 pPacket = (PLM_PACKET)
3316 QQ_PopHead (&pDevice->TxPacketActiveQ.Container);
3319 /* Cleanup the receive return rings. */
3320 LM_ServiceRxInterrupt (pDevice);
3322 /* Don't want to indicate rx packets in Ndis miniport shutdown context. */
3323 /* Doing so may cause system crash. */
3324 if (!pDevice->ShuttingDown) {
3325 /* Indicate packets to the protocol. */
3326 MM_IndicateTxPackets (pDevice);
3328 /* Indicate received packets to the protocols. */
3329 MM_IndicateRxPackets (pDevice);
3331 /* Move the receive packet descriptors in the ReceivedQ to the */
3335 (PLM_PACKET) QQ_PopHead (&pDevice->
3338 if (pPacket == NULL) {
3341 QQ_PushTail (&pDevice->RxPacketFreeQ.Container,
3346 /* Clean up the Std Receive Producer ring. */
3347 Idx = pDevice->pStatusBlkVirt->RcvStdConIdx;
3349 while (Idx != pDevice->RxStdProdIdx) {
3350 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3351 MM_UINT_PTR (pDevice->pRxStdBdVirt[Idx].
3354 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
3356 Idx = (Idx + 1) & T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
3359 /* Reinitialize our copy of the indices. */
3360 pDevice->RxStdProdIdx = 0;
3362 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
3363 /* Clean up the Jumbo Receive Producer ring. */
3364 Idx = pDevice->pStatusBlkVirt->RcvJumboConIdx;
3366 while (Idx != pDevice->RxJumboProdIdx) {
3367 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3368 MM_UINT_PTR (pDevice->
3369 pRxJumboBdVirt[Idx].
3372 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
3374 Idx = (Idx + 1) & T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
3377 /* Reinitialize our copy of the indices. */
3378 pDevice->RxJumboProdIdx = 0;
3379 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
3381 MM_RELEASE_INT_LOCK (pDevice);
3383 /* Initialize the statistis Block */
3384 pDevice->pStatusBlkVirt->Status = 0;
3385 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
3386 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
3387 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
3389 return LM_STATUS_SUCCESS;
3392 /******************************************************************************/
3394 /* Disable the interrupt and put the transmitter and receiver engines in */
3395 /* an idle state. Aborts all pending send requests and receive buffers. */
3396 /* Also free all the receive buffers. */
3399 /* LM_STATUS_SUCCESS */
3400 /******************************************************************************/
3401 LM_STATUS LM_Halt (PLM_DEVICE_BLOCK pDevice)
3408 /* Get the number of entries in the queue. */
3409 EntryCnt = QQ_GetEntryCnt (&pDevice->RxPacketFreeQ.Container);
3411 /* Make sure all the packets have been accounted for. */
3412 for (EntryCnt = 0; EntryCnt < pDevice->RxPacketDescCnt; EntryCnt++) {
3414 (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
3418 MM_FreeRxBuffer (pDevice, pPacket);
3420 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
3423 LM_ResetChip (pDevice);
3425 /* Restore PCI configuration registers. */
3426 MM_WriteConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG,
3427 pDevice->SavedCacheLineReg);
3428 LM_RegWrInd (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
3429 (pDevice->SubsystemId << 16) | pDevice->SubsystemVendorId);
3431 /* Reprogram the MAC address. */
3432 LM_SetMacAddress (pDevice, pDevice->NodeAddress);
3434 return LM_STATUS_SUCCESS;
3437 STATIC LM_STATUS LM_ResetChip (PLM_DEVICE_BLOCK pDevice)
3442 /* Wait for access to the nvram interface before resetting. This is */
3443 /* a workaround to prevent EEPROM corruption. */
3444 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
3445 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
3446 /* Request access to the flash interface. */
3447 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
3449 for (j = 0; j < 100000; j++) {
3450 Value32 = REG_RD (pDevice, Nvram.SwArb);
3451 if (Value32 & SW_ARB_GNT1) {
3459 REG_WR (pDevice, Grc.MiscCfg, GRC_MISC_CFG_CORE_CLOCK_RESET);
3464 /* make sure we re-enable indirect accesses */
3465 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
3466 pDevice->MiscHostCtrl);
3468 /* Set MAX PCI retry to zero. */
3470 T3_PCI_STATE_PCI_ROM_ENABLE | T3_PCI_STATE_PCI_ROM_RETRY_ENABLE;
3471 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
3472 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
3473 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
3476 MM_WriteConfig32 (pDevice, T3_PCI_STATE_REG, Value32);
3478 /* Restore PCI command register. */
3479 MM_WriteConfig32 (pDevice, PCI_COMMAND_REG,
3480 pDevice->PciCommandStatusWords);
3482 /* Disable PCI-X relaxed ordering bit. */
3483 MM_ReadConfig32 (pDevice, PCIX_CAP_REG, &Value32);
3484 Value32 &= ~PCIX_ENABLE_RELAXED_ORDERING;
3485 MM_WriteConfig32 (pDevice, PCIX_CAP_REG, Value32);
3487 /* Enable memory arbiter. */
3488 REG_WR (pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
3490 #ifdef BIG_ENDIAN_PCI /* This from jfd */
3491 Value32 = GRC_MODE_WORD_SWAP_DATA | GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
3493 #ifdef BIG_ENDIAN_HOST
3494 /* Reconfigure the mode register. */
3495 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
3496 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
3497 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA;
3499 /* Reconfigure the mode register. */
3500 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
3503 REG_WR (pDevice, Grc.Mode, Value32);
3505 /* Prevent PXE from restarting. */
3506 MEM_WR_OFFSET (pDevice, 0x0b50, T3_MAGIC_NUM);
3508 if (pDevice->EnableTbi) {
3509 pDevice->MacMode = MAC_MODE_PORT_MODE_TBI;
3510 REG_WR (pDevice, MacCtrl.Mode, MAC_MODE_PORT_MODE_TBI);
3512 REG_WR (pDevice, MacCtrl.Mode, 0);
3515 /* Wait for the firmware to finish initialization. */
3516 for (j = 0; j < 100000; j++) {
3519 Value32 = MEM_RD_OFFSET (pDevice, 0x0b50);
3520 if (Value32 == ~T3_MAGIC_NUM) {
3524 return LM_STATUS_SUCCESS;
3527 /******************************************************************************/
3531 /******************************************************************************/
3532 __inline static void LM_ServiceTxInterrupt (PLM_DEVICE_BLOCK pDevice)
3538 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
3540 /* Get our copy of the consumer index. The buffer descriptors */
3541 /* that are in between the consumer indices are freed. */
3542 SwConIdx = pDevice->SendConIdx;
3544 /* Move the packets from the TxPacketActiveQ that are sent out to */
3545 /* the TxPacketXmittedQ. Packets that are sent use the */
3546 /* descriptors that are between SwConIdx and HwConIdx. */
3547 while (SwConIdx != HwConIdx) {
3548 /* Get the packet that was sent from the TxPacketActiveQ. */
3550 (PLM_PACKET) QQ_PopHead (&pDevice->TxPacketActiveQ.
3553 /* Set the return status. */
3554 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3556 /* Put the packet in the TxPacketXmittedQ for indication later. */
3557 QQ_PushTail (&pDevice->TxPacketXmittedQ.Container, pPacket);
3559 /* Move to the next packet's BD. */
3560 SwConIdx = (SwConIdx + pPacket->u.Tx.FragCount) &
3561 T3_SEND_RCB_ENTRY_COUNT_MASK;
3563 /* Update the number of unused BDs. */
3564 atomic_add (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3566 /* Get the new updated HwConIdx. */
3567 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
3570 /* Save the new SwConIdx. */
3571 pDevice->SendConIdx = SwConIdx;
3573 } /* LM_ServiceTxInterrupt */
3575 /******************************************************************************/
3579 /******************************************************************************/
3580 __inline static void LM_ServiceRxInterrupt (PLM_DEVICE_BLOCK pDevice)
3584 LM_UINT32 HwRcvRetProdIdx;
3585 LM_UINT32 SwRcvRetConIdx;
3587 /* Loop thru the receive return rings for received packets. */
3588 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
3590 SwRcvRetConIdx = pDevice->RcvRetConIdx;
3591 while (SwRcvRetConIdx != HwRcvRetProdIdx) {
3592 pRcvBd = &pDevice->pRcvRetBdVirt[SwRcvRetConIdx];
3594 /* Get the received packet descriptor. */
3595 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3596 MM_UINT_PTR (pRcvBd->Opaque));
3598 /* Check the error flag. */
3599 if (pRcvBd->ErrorFlag &&
3600 pRcvBd->ErrorFlag != RCV_BD_ERR_ODD_NIBBLED_RCVD_MII) {
3601 pPacket->PacketStatus = LM_STATUS_FAILURE;
3603 pDevice->RxCounters.RxPacketErrCnt++;
3605 if (pRcvBd->ErrorFlag & RCV_BD_ERR_BAD_CRC) {
3606 pDevice->RxCounters.RxErrCrcCnt++;
3609 if (pRcvBd->ErrorFlag & RCV_BD_ERR_COLL_DETECT) {
3610 pDevice->RxCounters.RxErrCollCnt++;
3613 if (pRcvBd->ErrorFlag & RCV_BD_ERR_LINK_LOST_DURING_PKT) {
3614 pDevice->RxCounters.RxErrLinkLostCnt++;
3617 if (pRcvBd->ErrorFlag & RCV_BD_ERR_PHY_DECODE_ERR) {
3618 pDevice->RxCounters.RxErrPhyDecodeCnt++;
3621 if (pRcvBd->ErrorFlag & RCV_BD_ERR_ODD_NIBBLED_RCVD_MII) {
3622 pDevice->RxCounters.RxErrOddNibbleCnt++;
3625 if (pRcvBd->ErrorFlag & RCV_BD_ERR_MAC_ABORT) {
3626 pDevice->RxCounters.RxErrMacAbortCnt++;
3629 if (pRcvBd->ErrorFlag & RCV_BD_ERR_LEN_LT_64) {
3630 pDevice->RxCounters.RxErrShortPacketCnt++;
3633 if (pRcvBd->ErrorFlag & RCV_BD_ERR_TRUNC_NO_RESOURCES) {
3634 pDevice->RxCounters.RxErrNoResourceCnt++;
3637 if (pRcvBd->ErrorFlag & RCV_BD_ERR_GIANT_FRAME_RCVD) {
3638 pDevice->RxCounters.RxErrLargePacketCnt++;
3641 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3642 pPacket->PacketSize = pRcvBd->Len - 4;
3644 pPacket->Flags = pRcvBd->Flags;
3645 if (pRcvBd->Flags & RCV_BD_FLAG_VLAN_TAG) {
3646 pPacket->VlanTag = pRcvBd->VlanTag;
3649 pPacket->u.Rx.TcpUdpChecksum = pRcvBd->TcpUdpCksum;
3652 /* Put the packet descriptor containing the received packet */
3653 /* buffer in the RxPacketReceivedQ for indication later. */
3654 QQ_PushTail (&pDevice->RxPacketReceivedQ.Container, pPacket);
3656 /* Go to the next buffer descriptor. */
3657 SwRcvRetConIdx = (SwRcvRetConIdx + 1) &
3658 T3_RCV_RETURN_RCB_ENTRY_COUNT_MASK;
3660 /* Get the updated HwRcvRetProdIdx. */
3661 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
3664 pDevice->RcvRetConIdx = SwRcvRetConIdx;
3666 /* Update the receive return ring consumer index. */
3667 MB_REG_WR (pDevice, Mailbox.RcvRetConIdx[0].Low, SwRcvRetConIdx);
3668 } /* LM_ServiceRxInterrupt */
3670 /******************************************************************************/
3672 /* This is the interrupt event handler routine. It acknowledges all */
3673 /* pending interrupts and process all pending events. */
3676 /* LM_STATUS_SUCCESS */
3677 /******************************************************************************/
3678 LM_STATUS LM_ServiceInterrupts (PLM_DEVICE_BLOCK pDevice)
3681 int ServicePhyInt = FALSE;
3683 /* Setup the phy chip whenever the link status changes. */
3684 if (pDevice->LinkChngMode == T3_LINK_CHNG_MODE_USE_STATUS_REG) {
3685 Value32 = REG_RD (pDevice, MacCtrl.Status);
3686 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
3687 if (Value32 & MAC_STATUS_MI_INTERRUPT) {
3688 ServicePhyInt = TRUE;
3690 } else if (Value32 & MAC_STATUS_LINK_STATE_CHANGED) {
3691 ServicePhyInt = TRUE;
3694 if (pDevice->pStatusBlkVirt->
3695 Status & STATUS_BLOCK_LINK_CHANGED_STATUS) {
3696 pDevice->pStatusBlkVirt->Status =
3697 STATUS_BLOCK_UPDATED | (pDevice->pStatusBlkVirt->
3699 ~STATUS_BLOCK_LINK_CHANGED_STATUS);
3700 ServicePhyInt = TRUE;
3703 #if INCLUDE_TBI_SUPPORT
3704 if (pDevice->IgnoreTbiLinkChange == TRUE) {
3705 ServicePhyInt = FALSE;
3708 if (ServicePhyInt == TRUE) {
3709 LM_SetupPhy (pDevice);
3712 /* Service receive and transmit interrupts. */
3713 LM_ServiceRxInterrupt (pDevice);
3714 LM_ServiceTxInterrupt (pDevice);
3716 /* No spinlock for this queue since this routine is serialized. */
3717 if (!QQ_Empty (&pDevice->RxPacketReceivedQ.Container)) {
3718 /* Indicate receive packets. */
3719 MM_IndicateRxPackets (pDevice);
3720 /* LM_QueueRxPackets(pDevice); */
3723 /* No spinlock for this queue since this routine is serialized. */
3724 if (!QQ_Empty (&pDevice->TxPacketXmittedQ.Container)) {
3725 MM_IndicateTxPackets (pDevice);
3728 return LM_STATUS_SUCCESS;
3729 } /* LM_ServiceInterrupts */
3731 /******************************************************************************/
3735 /******************************************************************************/
3736 LM_STATUS LM_MulticastAdd (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress)
3741 pEntry = pDevice->McTable[0];
3742 for (j = 0; j < pDevice->McEntryCount; j++) {
3743 if (IS_ETH_ADDRESS_EQUAL (pEntry, pMcAddress)) {
3744 /* Found a match, increment the instance count. */
3745 pEntry[LM_MC_INSTANCE_COUNT_INDEX] += 1;
3747 return LM_STATUS_SUCCESS;
3750 pEntry += LM_MC_ENTRY_SIZE;
3753 if (pDevice->McEntryCount >= LM_MAX_MC_TABLE_SIZE) {
3754 return LM_STATUS_FAILURE;
3757 pEntry = pDevice->McTable[pDevice->McEntryCount];
3759 COPY_ETH_ADDRESS (pMcAddress, pEntry);
3760 pEntry[LM_MC_INSTANCE_COUNT_INDEX] = 1;
3762 pDevice->McEntryCount++;
3764 LM_SetReceiveMask (pDevice, pDevice->ReceiveMask | LM_ACCEPT_MULTICAST);
3766 return LM_STATUS_SUCCESS;
3767 } /* LM_MulticastAdd */
3769 /******************************************************************************/
3773 /******************************************************************************/
3774 LM_STATUS LM_MulticastDel (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress)
3779 pEntry = pDevice->McTable[0];
3780 for (j = 0; j < pDevice->McEntryCount; j++) {
3781 if (IS_ETH_ADDRESS_EQUAL (pEntry, pMcAddress)) {
3782 /* Found a match, decrement the instance count. */
3783 pEntry[LM_MC_INSTANCE_COUNT_INDEX] -= 1;
3785 /* No more instance left, remove the address from the table. */
3786 /* Move the last entry in the table to the delete slot. */
3787 if (pEntry[LM_MC_INSTANCE_COUNT_INDEX] == 0 &&
3788 pDevice->McEntryCount > 1) {
3790 COPY_ETH_ADDRESS (pDevice->
3794 pEntry[LM_MC_INSTANCE_COUNT_INDEX] =
3795 pDevice->McTable[pDevice->McEntryCount - 1]
3796 [LM_MC_INSTANCE_COUNT_INDEX];
3798 pDevice->McEntryCount--;
3800 /* Update the receive mask if the table is empty. */
3801 if (pDevice->McEntryCount == 0) {
3802 LM_SetReceiveMask (pDevice,
3805 ~LM_ACCEPT_MULTICAST);
3808 return LM_STATUS_SUCCESS;
3811 pEntry += LM_MC_ENTRY_SIZE;
3814 return LM_STATUS_FAILURE;
3815 } /* LM_MulticastDel */
3817 /******************************************************************************/
3821 /******************************************************************************/
3822 LM_STATUS LM_MulticastClear (PLM_DEVICE_BLOCK pDevice)
3824 pDevice->McEntryCount = 0;
3826 LM_SetReceiveMask (pDevice,
3827 pDevice->ReceiveMask & ~LM_ACCEPT_MULTICAST);
3829 return LM_STATUS_SUCCESS;
3830 } /* LM_MulticastClear */
3832 /******************************************************************************/
3836 /******************************************************************************/
3837 LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMacAddress)
3841 for (j = 0; j < 4; j++) {
3842 REG_WR (pDevice, MacCtrl.MacAddr[j].High,
3843 (pMacAddress[0] << 8) | pMacAddress[1]);
3844 REG_WR (pDevice, MacCtrl.MacAddr[j].Low,
3845 (pMacAddress[2] << 24) | (pMacAddress[3] << 16) |
3846 (pMacAddress[4] << 8) | pMacAddress[5]);
3849 return LM_STATUS_SUCCESS;
3852 /******************************************************************************/
3854 /* Sets up the default line speed, and duplex modes based on the requested */
3859 /******************************************************************************/
3861 LM_TranslateRequestedMediaType (LM_REQUESTED_MEDIA_TYPE RequestedMediaType,
3862 PLM_MEDIA_TYPE pMediaType,
3863 PLM_LINE_SPEED pLineSpeed,
3864 PLM_DUPLEX_MODE pDuplexMode)
3866 *pMediaType = LM_MEDIA_TYPE_AUTO;
3867 *pLineSpeed = LM_LINE_SPEED_UNKNOWN;
3868 *pDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
3870 /* determine media type */
3871 switch (RequestedMediaType) {
3872 case LM_REQUESTED_MEDIA_TYPE_BNC:
3873 *pMediaType = LM_MEDIA_TYPE_BNC;
3874 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3875 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3878 case LM_REQUESTED_MEDIA_TYPE_UTP_AUTO:
3879 *pMediaType = LM_MEDIA_TYPE_UTP;
3882 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS:
3883 *pMediaType = LM_MEDIA_TYPE_UTP;
3884 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3885 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3888 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX:
3889 *pMediaType = LM_MEDIA_TYPE_UTP;
3890 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3891 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3894 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS:
3895 *pMediaType = LM_MEDIA_TYPE_UTP;
3896 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3897 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3900 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX:
3901 *pMediaType = LM_MEDIA_TYPE_UTP;
3902 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3903 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3906 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS:
3907 *pMediaType = LM_MEDIA_TYPE_UTP;
3908 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3909 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3912 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX:
3913 *pMediaType = LM_MEDIA_TYPE_UTP;
3914 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3915 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3918 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS:
3919 *pMediaType = LM_MEDIA_TYPE_FIBER;
3920 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3921 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3924 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS_FULL_DUPLEX:
3925 *pMediaType = LM_MEDIA_TYPE_FIBER;
3926 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3927 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3930 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS:
3931 *pMediaType = LM_MEDIA_TYPE_FIBER;
3932 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3933 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3936 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX:
3937 *pMediaType = LM_MEDIA_TYPE_FIBER;
3938 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3939 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3946 return LM_STATUS_SUCCESS;
3947 } /* LM_TranslateRequestedMediaType */
3949 /******************************************************************************/
3953 /* LM_STATUS_LINK_ACTIVE */
3954 /* LM_STATUS_LINK_DOWN */
3955 /******************************************************************************/
3956 static LM_STATUS LM_InitBcm540xPhy (PLM_DEVICE_BLOCK pDevice)
3958 LM_LINE_SPEED CurrentLineSpeed;
3959 LM_DUPLEX_MODE CurrentDuplexMode;
3960 LM_STATUS CurrentLinkStatus;
3964 #if 1 /* jmb: bugfix -- moved here, out of code that sets initial pwr state */
3965 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x2);
3967 if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID) {
3968 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3969 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3971 if (!pDevice->InitDone) {
3975 if (!(Value32 & PHY_STATUS_LINK_PASS)) {
3976 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x0c20);
3978 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
3979 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1804);
3981 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
3982 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1204);
3984 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
3985 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0132);
3987 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
3988 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0232);
3990 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
3991 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
3993 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3994 for (j = 0; j < 1000; j++) {
3997 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3998 if (Value32 & PHY_STATUS_LINK_PASS) {
4004 if ((pDevice->PhyId & PHY_ID_REV_MASK) ==
4005 PHY_BCM5401_B0_REV) {
4006 if (!(Value32 & PHY_STATUS_LINK_PASS)
4007 && (pDevice->OldLineSpeed ==
4008 LM_LINE_SPEED_1000MBPS)) {
4009 LM_WritePhy (pDevice, PHY_CTRL_REG,
4010 PHY_CTRL_PHY_RESET);
4011 for (j = 0; j < 100; j++) {
4014 LM_ReadPhy (pDevice,
4019 PHY_CTRL_PHY_RESET)) {
4025 LM_WritePhy (pDevice, BCM5401_AUX_CTRL,
4028 LM_WritePhy (pDevice,
4029 BCM540X_DSP_ADDRESS_REG,
4031 LM_WritePhy (pDevice,
4032 BCM540X_DSP_RW_PORT,
4035 LM_WritePhy (pDevice,
4036 BCM540X_DSP_ADDRESS_REG,
4038 LM_WritePhy (pDevice,
4039 BCM540X_DSP_RW_PORT,
4042 LM_WritePhy (pDevice,
4043 BCM540X_DSP_ADDRESS_REG,
4045 LM_WritePhy (pDevice,
4046 BCM540X_DSP_RW_PORT,
4049 LM_WritePhy (pDevice,
4050 BCM540X_DSP_ADDRESS_REG,
4052 LM_WritePhy (pDevice,
4053 BCM540X_DSP_RW_PORT,
4056 LM_WritePhy (pDevice,
4057 BCM540X_DSP_ADDRESS_REG,
4059 LM_WritePhy (pDevice,
4060 BCM540X_DSP_RW_PORT,
4065 } else if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
4066 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
4067 /* Bug: 5701 A0, B0 TX CRC workaround. */
4068 LM_WritePhy (pDevice, 0x15, 0x0a75);
4069 LM_WritePhy (pDevice, 0x1c, 0x8c68);
4070 LM_WritePhy (pDevice, 0x1c, 0x8d68);
4071 LM_WritePhy (pDevice, 0x1c, 0x8c68);
4074 /* Acknowledge interrupts. */
4075 LM_ReadPhy (pDevice, BCM540X_INT_STATUS_REG, &Value32);
4076 LM_ReadPhy (pDevice, BCM540X_INT_STATUS_REG, &Value32);
4078 /* Configure the interrupt mask. */
4079 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
4080 LM_WritePhy (pDevice, BCM540X_INT_MASK_REG,
4081 ~BCM540X_INT_LINK_CHANGE);
4084 /* Configure PHY led mode. */
4085 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701 ||
4086 (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700)) {
4087 if (pDevice->LedMode == LED_MODE_THREE_LINK) {
4088 LM_WritePhy (pDevice, BCM540X_EXT_CTRL_REG,
4089 BCM540X_EXT_CTRL_LINK3_LED_MODE);
4091 LM_WritePhy (pDevice, BCM540X_EXT_CTRL_REG, 0);
4095 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4097 /* Get current link and duplex mode. */
4098 for (j = 0; j < 100; j++) {
4099 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4100 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4102 if (Value32 & PHY_STATUS_LINK_PASS) {
4108 if (Value32 & PHY_STATUS_LINK_PASS) {
4110 /* Determine the current line and duplex settings. */
4111 LM_ReadPhy (pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4112 for (j = 0; j < 2000; j++) {
4115 LM_ReadPhy (pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4121 switch (Value32 & BCM540X_AUX_SPEED_MASK) {
4122 case BCM540X_AUX_10BASET_HD:
4123 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4124 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4127 case BCM540X_AUX_10BASET_FD:
4128 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4129 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4132 case BCM540X_AUX_100BASETX_HD:
4133 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4134 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4137 case BCM540X_AUX_100BASETX_FD:
4138 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4139 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4142 case BCM540X_AUX_100BASET_HD:
4143 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4144 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4147 case BCM540X_AUX_100BASET_FD:
4148 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4149 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4154 CurrentLineSpeed = LM_LINE_SPEED_UNKNOWN;
4155 CurrentDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4159 /* Make sure we are in auto-neg mode. */
4160 for (j = 0; j < 200; j++) {
4161 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
4162 if (Value32 && Value32 != 0x7fff) {
4166 if (Value32 == 0 && pDevice->RequestedMediaType ==
4167 LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS) {
4174 /* Use the current line settings for "auto" mode. */
4175 if (pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO
4176 || pDevice->RequestedMediaType ==
4177 LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
4178 if (Value32 & PHY_CTRL_AUTO_NEG_ENABLE) {
4179 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4181 /* We may be exiting low power mode and the link is in */
4182 /* 10mb. In this case, we need to restart autoneg. */
4183 LM_ReadPhy (pDevice, BCM540X_1000BASET_CTRL_REG,
4185 pDevice->advertising1000 = Value32;
4186 /* 5702FE supports 10/100Mb only. */
4187 if (T3_ASIC_REV (pDevice->ChipRevId) !=
4189 || pDevice->BondId !=
4190 GRC_MISC_BD_ID_5702FE) {
4193 (BCM540X_AN_AD_1000BASET_HALF |
4194 BCM540X_AN_AD_1000BASET_FULL))) {
4196 LM_STATUS_LINK_SETTING_MISMATCH;
4201 LM_STATUS_LINK_SETTING_MISMATCH;
4204 /* Force line settings. */
4205 /* Use the current setting if it matches the user's requested */
4207 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
4208 if ((pDevice->LineSpeed == CurrentLineSpeed) &&
4209 (pDevice->DuplexMode == CurrentDuplexMode)) {
4210 if ((pDevice->DisableAutoNeg &&
4211 !(Value32 & PHY_CTRL_AUTO_NEG_ENABLE)) ||
4212 (!pDevice->DisableAutoNeg &&
4213 (Value32 & PHY_CTRL_AUTO_NEG_ENABLE))) {
4215 LM_STATUS_LINK_ACTIVE;
4218 LM_STATUS_LINK_SETTING_MISMATCH;
4222 LM_STATUS_LINK_SETTING_MISMATCH;
4226 /* Save line settings. */
4227 pDevice->LineSpeed = CurrentLineSpeed;
4228 pDevice->DuplexMode = CurrentDuplexMode;
4229 pDevice->MediaType = LM_MEDIA_TYPE_UTP;
4232 return CurrentLinkStatus;
4233 } /* LM_InitBcm540xPhy */
4235 /******************************************************************************/
4239 /******************************************************************************/
4241 LM_SetFlowControl (PLM_DEVICE_BLOCK pDevice,
4242 LM_UINT32 LocalPhyAd, LM_UINT32 RemotePhyAd)
4244 LM_FLOW_CONTROL FlowCap;
4246 /* Resolve flow control. */
4247 FlowCap = LM_FLOW_CONTROL_NONE;
4249 /* See Table 28B-3 of 802.3ab-1999 spec. */
4250 if (pDevice->FlowControlCap & LM_FLOW_CONTROL_AUTO_PAUSE) {
4251 if (LocalPhyAd & PHY_AN_AD_PAUSE_CAPABLE) {
4252 if (LocalPhyAd & PHY_AN_AD_ASYM_PAUSE) {
4254 PHY_LINK_PARTNER_PAUSE_CAPABLE) {
4256 LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4257 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4258 } else if (RemotePhyAd &
4259 PHY_LINK_PARTNER_ASYM_PAUSE) {
4260 FlowCap = LM_FLOW_CONTROL_RECEIVE_PAUSE;
4264 PHY_LINK_PARTNER_PAUSE_CAPABLE) {
4266 LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4267 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4270 } else if (LocalPhyAd & PHY_AN_AD_ASYM_PAUSE) {
4271 if ((RemotePhyAd & PHY_LINK_PARTNER_PAUSE_CAPABLE) &&
4272 (RemotePhyAd & PHY_LINK_PARTNER_ASYM_PAUSE)) {
4273 FlowCap = LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4277 FlowCap = pDevice->FlowControlCap;
4280 /* Enable/disable rx PAUSE. */
4281 pDevice->RxMode &= ~RX_MODE_ENABLE_FLOW_CONTROL;
4282 if (FlowCap & LM_FLOW_CONTROL_RECEIVE_PAUSE &&
4283 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4284 pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE)) {
4285 pDevice->FlowControl |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
4286 pDevice->RxMode |= RX_MODE_ENABLE_FLOW_CONTROL;
4289 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
4291 /* Enable/disable tx PAUSE. */
4292 pDevice->TxMode &= ~TX_MODE_ENABLE_FLOW_CONTROL;
4293 if (FlowCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE &&
4294 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4295 pDevice->FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE)) {
4296 pDevice->FlowControl |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4297 pDevice->TxMode |= TX_MODE_ENABLE_FLOW_CONTROL;
4300 REG_WR (pDevice, MacCtrl.TxMode, pDevice->TxMode);
4302 return LM_STATUS_SUCCESS;
4305 #if INCLUDE_TBI_SUPPORT
4306 /******************************************************************************/
4310 /******************************************************************************/
4311 STATIC LM_STATUS LM_InitBcm800xPhy (PLM_DEVICE_BLOCK pDevice)
4316 Value32 = REG_RD (pDevice, MacCtrl.Status);
4318 /* Reset the SERDES during init and when we have link. */
4319 if (!pDevice->InitDone || Value32 & MAC_STATUS_PCS_SYNCED) {
4320 /* Set PLL lock range. */
4321 LM_WritePhy (pDevice, 0x16, 0x8007);
4323 /* Software reset. */
4324 LM_WritePhy (pDevice, 0x00, 0x8000);
4326 /* Wait for reset to complete. */
4327 for (j = 0; j < 500; j++) {
4331 /* Config mode; seletct PMA/Ch 1 regs. */
4332 LM_WritePhy (pDevice, 0x10, 0x8411);
4334 /* Enable auto-lock and comdet, select txclk for tx. */
4335 LM_WritePhy (pDevice, 0x11, 0x0a10);
4337 LM_WritePhy (pDevice, 0x18, 0x00a0);
4338 LM_WritePhy (pDevice, 0x16, 0x41ff);
4340 /* Assert and deassert POR. */
4341 LM_WritePhy (pDevice, 0x13, 0x0400);
4343 LM_WritePhy (pDevice, 0x13, 0x0000);
4345 LM_WritePhy (pDevice, 0x11, 0x0a50);
4347 LM_WritePhy (pDevice, 0x11, 0x0a10);
4349 /* Delay for signal to stabilize. */
4350 for (j = 0; j < 15000; j++) {
4354 /* Deselect the channel register so we can read the PHY id later. */
4355 LM_WritePhy (pDevice, 0x10, 0x8011);
4358 return LM_STATUS_SUCCESS;
4361 /******************************************************************************/
4365 /******************************************************************************/
4366 STATIC LM_STATUS LM_SetupFiberPhy (PLM_DEVICE_BLOCK pDevice)
4368 LM_STATUS CurrentLinkStatus;
4369 AUTONEG_STATUS AnStatus = 0;
4374 pDevice->MacMode &= ~(MAC_MODE_HALF_DUPLEX | MAC_MODE_PORT_MODE_MASK);
4376 /* Initialize the send_config register. */
4377 REG_WR (pDevice, MacCtrl.TxAutoNeg, 0);
4379 /* Enable TBI and full duplex mode. */
4380 pDevice->MacMode |= MAC_MODE_PORT_MODE_TBI;
4381 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
4383 /* Initialize the BCM8002 SERDES PHY. */
4384 switch (pDevice->PhyId & PHY_ID_MASK) {
4385 case PHY_BCM8002_PHY_ID:
4386 LM_InitBcm800xPhy (pDevice);
4393 /* Enable link change interrupt. */
4394 REG_WR (pDevice, MacCtrl.MacEvent,
4395 MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
4397 /* Default to link down. */
4398 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4400 /* Get the link status. */
4401 Value32 = REG_RD (pDevice, MacCtrl.Status);
4402 if (Value32 & MAC_STATUS_PCS_SYNCED) {
4403 if ((pDevice->RequestedMediaType ==
4404 LM_REQUESTED_MEDIA_TYPE_AUTO)
4405 || (pDevice->DisableAutoNeg == FALSE)) {
4406 /* auto-negotiation mode. */
4407 /* Initialize the autoneg default capaiblities. */
4408 AutonegInit (&pDevice->AnInfo);
4410 /* Set the context pointer to point to the main device structure. */
4411 pDevice->AnInfo.pContext = pDevice;
4413 /* Setup flow control advertisement register. */
4414 Value32 = GetPhyAdFlowCntrlSettings (pDevice);
4415 if (Value32 & PHY_AN_AD_PAUSE_CAPABLE) {
4416 pDevice->AnInfo.mr_adv_sym_pause = 1;
4418 pDevice->AnInfo.mr_adv_sym_pause = 0;
4421 if (Value32 & PHY_AN_AD_ASYM_PAUSE) {
4422 pDevice->AnInfo.mr_adv_asym_pause = 1;
4424 pDevice->AnInfo.mr_adv_asym_pause = 0;
4427 /* Try to autoneg up to six times. */
4428 if (pDevice->IgnoreTbiLinkChange) {
4433 for (j = 0; j < Cnt; j++) {
4434 REG_WR (pDevice, MacCtrl.TxAutoNeg, 0);
4437 pDevice->MacMode & ~MAC_MODE_PORT_MODE_MASK;
4438 REG_WR (pDevice, MacCtrl.Mode, Value32);
4441 REG_WR (pDevice, MacCtrl.Mode,
4443 MacMode | MAC_MODE_SEND_CONFIGS);
4447 pDevice->AnInfo.State = AN_STATE_UNKNOWN;
4448 pDevice->AnInfo.CurrentTime_us = 0;
4450 REG_WR (pDevice, Grc.Timer, 0);
4452 (pDevice->AnInfo.CurrentTime_us < 75000)
4453 && (k < 75000); k++) {
4455 Autoneg8023z (&pDevice->AnInfo);
4457 if ((AnStatus == AUTONEG_STATUS_DONE) ||
4458 (AnStatus == AUTONEG_STATUS_FAILED))
4463 pDevice->AnInfo.CurrentTime_us =
4464 REG_RD (pDevice, Grc.Timer);
4467 if ((AnStatus == AUTONEG_STATUS_DONE) ||
4468 (AnStatus == AUTONEG_STATUS_FAILED)) {
4472 if (!(REG_RD (pDevice, MacCtrl.Status) &
4473 MAC_STATUS_PCS_SYNCED)) {
4479 /* Stop sending configs. */
4480 MM_AnTxIdle (&pDevice->AnInfo);
4482 /* Resolve flow control settings. */
4483 if ((AnStatus == AUTONEG_STATUS_DONE) &&
4484 pDevice->AnInfo.mr_an_complete
4485 && pDevice->AnInfo.mr_link_ok
4486 && pDevice->AnInfo.mr_lp_adv_full_duplex) {
4487 LM_UINT32 RemotePhyAd;
4488 LM_UINT32 LocalPhyAd;
4491 if (pDevice->AnInfo.mr_adv_sym_pause) {
4492 LocalPhyAd |= PHY_AN_AD_PAUSE_CAPABLE;
4495 if (pDevice->AnInfo.mr_adv_asym_pause) {
4496 LocalPhyAd |= PHY_AN_AD_ASYM_PAUSE;
4500 if (pDevice->AnInfo.mr_lp_adv_sym_pause) {
4502 PHY_LINK_PARTNER_PAUSE_CAPABLE;
4505 if (pDevice->AnInfo.mr_lp_adv_asym_pause) {
4507 PHY_LINK_PARTNER_ASYM_PAUSE;
4510 LM_SetFlowControl (pDevice, LocalPhyAd,
4513 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4515 for (j = 0; j < 30; j++) {
4517 REG_WR (pDevice, MacCtrl.Status,
4518 MAC_STATUS_SYNC_CHANGED |
4519 MAC_STATUS_CFG_CHANGED);
4521 if ((REG_RD (pDevice, MacCtrl.Status) &
4522 (MAC_STATUS_SYNC_CHANGED |
4523 MAC_STATUS_CFG_CHANGED)) == 0)
4526 if (pDevice->PollTbiLink) {
4527 Value32 = REG_RD (pDevice, MacCtrl.Status);
4528 if (Value32 & MAC_STATUS_RECEIVING_CFG) {
4529 pDevice->IgnoreTbiLinkChange = TRUE;
4531 pDevice->IgnoreTbiLinkChange = FALSE;
4534 Value32 = REG_RD (pDevice, MacCtrl.Status);
4535 if (CurrentLinkStatus == LM_STATUS_LINK_DOWN &&
4536 (Value32 & MAC_STATUS_PCS_SYNCED) &&
4537 ((Value32 & MAC_STATUS_RECEIVING_CFG) == 0)) {
4538 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4541 /* We are forcing line speed. */
4542 pDevice->FlowControlCap &= ~LM_FLOW_CONTROL_AUTO_PAUSE;
4543 LM_SetFlowControl (pDevice, 0, 0);
4545 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4546 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
4547 MAC_MODE_SEND_CONFIGS);
4550 /* Set the link polarity bit. */
4551 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
4552 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
4554 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED |
4555 (pDevice->pStatusBlkVirt->
4556 Status & ~STATUS_BLOCK_LINK_CHANGED_STATUS);
4558 for (j = 0; j < 100; j++) {
4559 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4560 MAC_STATUS_CFG_CHANGED);
4562 if ((REG_RD (pDevice, MacCtrl.Status) &
4563 (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED)) == 0)
4567 Value32 = REG_RD (pDevice, MacCtrl.Status);
4568 if ((Value32 & MAC_STATUS_PCS_SYNCED) == 0) {
4569 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4570 if (pDevice->DisableAutoNeg == FALSE) {
4571 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
4572 MAC_MODE_SEND_CONFIGS);
4574 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
4578 /* Initialize the current link status. */
4579 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4580 pDevice->LineSpeed = LM_LINE_SPEED_1000MBPS;
4581 pDevice->DuplexMode = LM_DUPLEX_MODE_FULL;
4582 REG_WR (pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4583 LED_CTRL_1000MBPS_LED_ON);
4585 pDevice->LineSpeed = LM_LINE_SPEED_UNKNOWN;
4586 pDevice->DuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4587 REG_WR (pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4588 LED_CTRL_OVERRIDE_TRAFFIC_LED);
4591 /* Indicate link status. */
4592 if (pDevice->LinkStatus != CurrentLinkStatus) {
4593 pDevice->LinkStatus = CurrentLinkStatus;
4594 MM_IndicateStatus (pDevice, CurrentLinkStatus);
4597 return LM_STATUS_SUCCESS;
4599 #endif /* INCLUDE_TBI_SUPPORT */
4601 /******************************************************************************/
4605 /******************************************************************************/
4606 LM_STATUS LM_SetupCopperPhy (PLM_DEVICE_BLOCK pDevice)
4608 LM_STATUS CurrentLinkStatus;
4611 /* Assume there is not link first. */
4612 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4614 /* Disable phy link change attention. */
4615 REG_WR (pDevice, MacCtrl.MacEvent, 0);
4617 /* Clear link change attention. */
4618 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4619 MAC_STATUS_CFG_CHANGED);
4621 /* Disable auto-polling for the moment. */
4622 pDevice->MiMode = 0xc0000;
4623 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4626 /* Determine the requested line speed and duplex. */
4627 pDevice->OldLineSpeed = pDevice->LineSpeed;
4628 LM_TranslateRequestedMediaType (pDevice->RequestedMediaType,
4629 &pDevice->MediaType,
4630 &pDevice->LineSpeed,
4631 &pDevice->DuplexMode);
4633 /* Initialize the phy chip. */
4634 switch (pDevice->PhyId & PHY_ID_MASK) {
4635 case PHY_BCM5400_PHY_ID:
4636 case PHY_BCM5401_PHY_ID:
4637 case PHY_BCM5411_PHY_ID:
4638 case PHY_BCM5701_PHY_ID:
4639 case PHY_BCM5703_PHY_ID:
4640 case PHY_BCM5704_PHY_ID:
4641 CurrentLinkStatus = LM_InitBcm540xPhy (pDevice);
4648 if (CurrentLinkStatus == LM_STATUS_LINK_SETTING_MISMATCH) {
4649 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4652 /* Setup flow control. */
4653 pDevice->FlowControl = LM_FLOW_CONTROL_NONE;
4654 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4655 LM_FLOW_CONTROL FlowCap; /* Flow control capability. */
4657 FlowCap = LM_FLOW_CONTROL_NONE;
4659 if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL) {
4660 if (pDevice->DisableAutoNeg == FALSE ||
4661 pDevice->RequestedMediaType ==
4662 LM_REQUESTED_MEDIA_TYPE_AUTO
4663 || pDevice->RequestedMediaType ==
4664 LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
4665 LM_UINT32 ExpectedPhyAd;
4666 LM_UINT32 LocalPhyAd;
4667 LM_UINT32 RemotePhyAd;
4669 LM_ReadPhy (pDevice, PHY_AN_AD_REG,
4671 pDevice->advertising = LocalPhyAd;
4673 (PHY_AN_AD_ASYM_PAUSE |
4674 PHY_AN_AD_PAUSE_CAPABLE);
4677 GetPhyAdFlowCntrlSettings (pDevice);
4679 if (LocalPhyAd != ExpectedPhyAd) {
4680 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4682 LM_ReadPhy (pDevice,
4683 PHY_LINK_PARTNER_ABILITY_REG,
4686 LM_SetFlowControl (pDevice, LocalPhyAd,
4690 pDevice->FlowControlCap &=
4691 ~LM_FLOW_CONTROL_AUTO_PAUSE;
4692 LM_SetFlowControl (pDevice, 0, 0);
4697 if (CurrentLinkStatus == LM_STATUS_LINK_DOWN) {
4698 LM_ForceAutoNeg (pDevice, pDevice->RequestedMediaType);
4700 /* If we force line speed, we make get link right away. */
4701 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4702 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4703 if (Value32 & PHY_STATUS_LINK_PASS) {
4704 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4708 /* GMII interface. */
4709 pDevice->MacMode &= ~MAC_MODE_PORT_MODE_MASK;
4710 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4711 if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS ||
4712 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS) {
4713 pDevice->MacMode |= MAC_MODE_PORT_MODE_MII;
4715 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
4718 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
4721 /* Set the MAC to operate in the appropriate duplex mode. */
4722 pDevice->MacMode &= ~MAC_MODE_HALF_DUPLEX;
4723 if (pDevice->DuplexMode == LM_DUPLEX_MODE_HALF) {
4724 pDevice->MacMode |= MAC_MODE_HALF_DUPLEX;
4727 /* Set the link polarity bit. */
4728 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
4729 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
4730 if ((pDevice->LedMode == LED_MODE_LINK10) ||
4731 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE &&
4732 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS)) {
4733 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
4736 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4737 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
4741 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
4742 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
4743 Value32 = LED_CTRL_PHY_MODE_1;
4745 if (pDevice->LedMode == LED_MODE_OUTPUT) {
4746 Value32 = LED_CTRL_PHY_MODE_2;
4748 Value32 = LED_CTRL_PHY_MODE_1;
4751 REG_WR (pDevice, MacCtrl.LedCtrl, Value32);
4754 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
4756 /* Enable auto polling. */
4757 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4758 pDevice->MiMode |= MI_MODE_AUTO_POLLING_ENABLE;
4759 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4762 /* Enable phy link change attention. */
4763 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
4764 REG_WR (pDevice, MacCtrl.MacEvent,
4765 MAC_EVENT_ENABLE_MI_INTERRUPT);
4767 REG_WR (pDevice, MacCtrl.MacEvent,
4768 MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
4770 if ((T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) &&
4771 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) &&
4772 (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
4773 (((pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) &&
4774 (pDevice->PciState & T3_PCI_STATE_BUS_SPEED_HIGH)) ||
4775 !(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))) {
4777 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4778 MAC_STATUS_CFG_CHANGED);
4779 MEM_WR_OFFSET (pDevice, T3_FIRMWARE_MAILBOX,
4780 T3_MAGIC_NUM_DISABLE_DMAW_ON_LINK_CHANGE);
4783 /* Indicate link status. */
4784 if (pDevice->LinkStatus != CurrentLinkStatus) {
4785 pDevice->LinkStatus = CurrentLinkStatus;
4786 MM_IndicateStatus (pDevice, CurrentLinkStatus);
4789 return LM_STATUS_SUCCESS;
4790 } /* LM_SetupCopperPhy */
4792 /******************************************************************************/
4796 /******************************************************************************/
4797 LM_STATUS LM_SetupPhy (PLM_DEVICE_BLOCK pDevice)
4802 #if INCLUDE_TBI_SUPPORT
4803 if (pDevice->EnableTbi) {
4804 LmStatus = LM_SetupFiberPhy (pDevice);
4806 #endif /* INCLUDE_TBI_SUPPORT */
4808 LmStatus = LM_SetupCopperPhy (pDevice);
4810 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
4811 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
4812 Value32 = REG_RD (pDevice, PciCfg.PciState);
4813 REG_WR (pDevice, PciCfg.PciState,
4814 Value32 | T3_PCI_STATE_RETRY_SAME_DMA);
4817 if ((pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
4818 (pDevice->DuplexMode == LM_DUPLEX_MODE_HALF)) {
4819 REG_WR (pDevice, MacCtrl.TxLengths, 0x26ff);
4821 REG_WR (pDevice, MacCtrl.TxLengths, 0x2620);
4827 /******************************************************************************/
4831 /******************************************************************************/
4833 LM_ReadPhy (PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg, PLM_UINT32 pData32)
4838 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4839 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode &
4840 ~MI_MODE_AUTO_POLLING_ENABLE);
4844 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
4845 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) <<
4846 MI_COM_FIRST_PHY_REG_ADDR_BIT) | MI_COM_CMD_READ | MI_COM_START;
4848 REG_WR (pDevice, MacCtrl.MiCom, Value32);
4850 for (j = 0; j < 20; j++) {
4853 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4855 if (!(Value32 & MI_COM_BUSY)) {
4857 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4858 Value32 &= MI_COM_PHY_DATA_MASK;
4863 if (Value32 & MI_COM_BUSY) {
4869 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4870 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4875 /******************************************************************************/
4879 /******************************************************************************/
4881 LM_WritePhy (PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg, LM_UINT32 Data32)
4886 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4887 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode &
4888 ~MI_MODE_AUTO_POLLING_ENABLE);
4892 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
4893 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) <<
4894 MI_COM_FIRST_PHY_REG_ADDR_BIT) | (Data32 & MI_COM_PHY_DATA_MASK) |
4895 MI_COM_CMD_WRITE | MI_COM_START;
4897 REG_WR (pDevice, MacCtrl.MiCom, Value32);
4899 for (j = 0; j < 20; j++) {
4902 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4904 if (!(Value32 & MI_COM_BUSY)) {
4910 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4911 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4916 /******************************************************************************/
4920 /******************************************************************************/
4921 LM_STATUS LM_SetPowerState (PLM_DEVICE_BLOCK pDevice, LM_POWER_STATE PowerLevel)
4923 LM_UINT32 PmeSupport;
4927 /* make sureindirect accesses are enabled */
4928 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
4929 pDevice->MiscHostCtrl);
4931 /* Clear the PME_ASSERT bit and the power state bits. Also enable */
4933 MM_ReadConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, &PmCtrl);
4935 PmCtrl |= T3_PM_PME_ASSERTED;
4936 PmCtrl &= ~T3_PM_POWER_STATE_MASK;
4938 /* Set the appropriate power state. */
4939 if (PowerLevel == LM_POWER_STATE_D0) {
4941 /* Bring the card out of low power mode. */
4942 PmCtrl |= T3_PM_POWER_STATE_D0;
4943 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
4945 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
4947 #if 0 /* Bugfix by jmb...can't call WritePhy here because pDevice not fully initialized */
4948 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x02);
4951 return LM_STATUS_SUCCESS;
4952 } else if (PowerLevel == LM_POWER_STATE_D1) {
4953 PmCtrl |= T3_PM_POWER_STATE_D1;
4954 } else if (PowerLevel == LM_POWER_STATE_D2) {
4955 PmCtrl |= T3_PM_POWER_STATE_D2;
4956 } else if (PowerLevel == LM_POWER_STATE_D3) {
4957 PmCtrl |= T3_PM_POWER_STATE_D3;
4959 return LM_STATUS_FAILURE;
4961 PmCtrl |= T3_PM_PME_ENABLE;
4963 /* Mask out all interrupts so LM_SetupPhy won't be called while we are */
4964 /* setting new line speed. */
4965 Value32 = REG_RD (pDevice, PciCfg.MiscHostCtrl);
4966 REG_WR (pDevice, PciCfg.MiscHostCtrl,
4967 Value32 | MISC_HOST_CTRL_MASK_PCI_INT);
4969 if (!pDevice->RestoreOnWakeUp) {
4970 pDevice->RestoreOnWakeUp = TRUE;
4971 pDevice->WakeUpDisableAutoNeg = pDevice->DisableAutoNeg;
4972 pDevice->WakeUpRequestedMediaType = pDevice->RequestedMediaType;
4975 /* Force auto-negotiation to 10 line speed. */
4976 pDevice->DisableAutoNeg = FALSE;
4977 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
4978 LM_SetupPhy (pDevice);
4980 /* Put the driver in the initial state, and go through the power down */
4984 MM_ReadConfig32 (pDevice, T3_PCI_PM_CAP_REG, &PmeSupport);
4986 if (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE) {
4989 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x5a);
4993 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
4994 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
4995 Value32 = LED_CTRL_PHY_MODE_1;
4997 if (pDevice->LedMode == LED_MODE_OUTPUT) {
4998 Value32 = LED_CTRL_PHY_MODE_2;
5000 Value32 = LED_CTRL_PHY_MODE_1;
5004 Value32 = MAC_MODE_PORT_MODE_MII;
5005 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
5006 if (pDevice->LedMode == LED_MODE_LINK10 ||
5007 pDevice->WolSpeed == WOL_SPEED_10MB) {
5008 Value32 |= MAC_MODE_LINK_POLARITY;
5011 Value32 |= MAC_MODE_LINK_POLARITY;
5013 REG_WR (pDevice, MacCtrl.Mode, Value32);
5018 /* Always enable magic packet wake-up if we have vaux. */
5019 if ((PmeSupport & T3_PCI_PM_CAP_PME_D3COLD) &&
5020 (pDevice->WakeUpModeCap & LM_WAKE_UP_MODE_MAGIC_PACKET)) {
5021 Value32 |= MAC_MODE_DETECT_MAGIC_PACKET_ENABLE;
5024 REG_WR (pDevice, MacCtrl.Mode, Value32);
5026 /* Enable the receiver. */
5027 REG_WR (pDevice, MacCtrl.RxMode, RX_MODE_ENABLE);
5030 /* Disable tx/rx clocks, and seletect an alternate clock. */
5031 if (pDevice->WolSpeed == WOL_SPEED_100MB) {
5032 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5033 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5035 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5036 T3_PCI_SELECT_ALTERNATE_CLOCK;
5038 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK;
5040 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5044 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5045 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5047 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5048 T3_PCI_SELECT_ALTERNATE_CLOCK |
5049 T3_PCI_44MHZ_CORE_CLOCK;
5051 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5052 T3_PCI_44MHZ_CORE_CLOCK;
5055 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5059 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5060 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5062 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5063 T3_PCI_44MHZ_CORE_CLOCK;
5065 Value32 = T3_PCI_44MHZ_CORE_CLOCK;
5068 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5070 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5071 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5073 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5074 T3_PCI_SELECT_ALTERNATE_CLOCK |
5075 T3_PCI_POWER_DOWN_PCI_PLL133;
5077 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5078 T3_PCI_POWER_DOWN_PCI_PLL133;
5081 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5086 if (!pDevice->EepromWp
5087 && (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE)) {
5088 /* Switch adapter to auxilliary power. */
5089 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5090 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5091 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5092 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5093 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5094 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5095 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5096 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5097 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5100 /* GPIO0 = 0, GPIO1 = 1, GPIO2 = 1. */
5101 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5102 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5103 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5104 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5105 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5106 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5109 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 1. */
5110 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5111 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5112 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5113 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5114 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5115 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5116 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5119 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5120 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5121 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5122 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5123 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5124 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5125 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5130 /* Set the phy to low power mode. */
5131 /* Put the the hardware in low power mode. */
5132 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
5134 return LM_STATUS_SUCCESS;
5135 } /* LM_SetPowerState */
5137 /******************************************************************************/
5141 /******************************************************************************/
5142 static LM_UINT32 GetPhyAdFlowCntrlSettings (PLM_DEVICE_BLOCK pDevice)
5148 /* Auto negotiation flow control only when autonegotiation is enabled. */
5149 if (pDevice->DisableAutoNeg == FALSE ||
5150 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO ||
5151 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
5152 /* Please refer to Table 28B-3 of the 802.3ab-1999 spec. */
5153 if ((pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE) ||
5154 ((pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE)
5156 FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE))) {
5157 Value32 |= PHY_AN_AD_PAUSE_CAPABLE;
5158 } else if (pDevice->
5159 FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE) {
5160 Value32 |= PHY_AN_AD_ASYM_PAUSE;
5161 } else if (pDevice->
5162 FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE) {
5164 PHY_AN_AD_PAUSE_CAPABLE | PHY_AN_AD_ASYM_PAUSE;
5171 /******************************************************************************/
5175 /* LM_STATUS_FAILURE */
5176 /* LM_STATUS_SUCCESS */
5178 /******************************************************************************/
5180 LM_ForceAutoNegBcm540xPhy (PLM_DEVICE_BLOCK pDevice,
5181 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
5183 LM_MEDIA_TYPE MediaType;
5184 LM_LINE_SPEED LineSpeed;
5185 LM_DUPLEX_MODE DuplexMode;
5186 LM_UINT32 NewPhyCtrl;
5190 /* Get the interface type, line speed, and duplex mode. */
5191 LM_TranslateRequestedMediaType (RequestedMediaType, &MediaType,
5192 &LineSpeed, &DuplexMode);
5194 if (pDevice->RestoreOnWakeUp) {
5195 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5196 pDevice->advertising1000 = 0;
5197 Value32 = PHY_AN_AD_10BASET_FULL | PHY_AN_AD_10BASET_HALF;
5198 if (pDevice->WolSpeed == WOL_SPEED_100MB) {
5200 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5202 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5203 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5204 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5205 pDevice->advertising = Value32;
5207 /* Setup the auto-negotiation advertisement register. */
5208 else if (LineSpeed == LM_LINE_SPEED_UNKNOWN) {
5209 /* Setup the 10/100 Mbps auto-negotiation advertisement register. */
5210 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
5211 PHY_AN_AD_10BASET_HALF | PHY_AN_AD_10BASET_FULL |
5212 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5213 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5215 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5216 pDevice->advertising = Value32;
5218 /* Advertise 1000Mbps */
5220 BCM540X_AN_AD_1000BASET_HALF | BCM540X_AN_AD_1000BASET_FULL;
5222 #if INCLUDE_5701_AX_FIX
5223 /* Bug: workaround for CRC error in gigabit mode when we are in */
5224 /* slave mode. This will force the PHY to operate in */
5226 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
5227 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
5228 Value32 |= BCM540X_CONFIG_AS_MASTER |
5229 BCM540X_ENABLE_CONFIG_AS_MASTER;
5233 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, Value32);
5234 pDevice->advertising1000 = Value32;
5236 if (LineSpeed == LM_LINE_SPEED_1000MBPS) {
5237 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5238 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5240 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5241 pDevice->advertising = Value32;
5243 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5244 Value32 = BCM540X_AN_AD_1000BASET_HALF;
5246 Value32 = BCM540X_AN_AD_1000BASET_FULL;
5249 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG,
5251 pDevice->advertising1000 = Value32;
5252 } else if (LineSpeed == LM_LINE_SPEED_100MBPS) {
5253 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5254 pDevice->advertising1000 = 0;
5256 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5257 Value32 = PHY_AN_AD_100BASETX_HALF;
5259 Value32 = PHY_AN_AD_100BASETX_FULL;
5262 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5263 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5265 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5266 pDevice->advertising = Value32;
5267 } else if (LineSpeed == LM_LINE_SPEED_10MBPS) {
5268 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5269 pDevice->advertising1000 = 0;
5271 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5272 Value32 = PHY_AN_AD_10BASET_HALF;
5274 Value32 = PHY_AN_AD_10BASET_FULL;
5277 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5278 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5280 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5281 pDevice->advertising = Value32;
5285 /* Force line speed if auto-negotiation is disabled. */
5286 if (pDevice->DisableAutoNeg && LineSpeed != LM_LINE_SPEED_UNKNOWN) {
5287 /* This code path is executed only when there is link. */
5288 pDevice->MediaType = MediaType;
5289 pDevice->LineSpeed = LineSpeed;
5290 pDevice->DuplexMode = DuplexMode;
5292 /* Force line seepd. */
5294 switch (LineSpeed) {
5295 case LM_LINE_SPEED_10MBPS:
5296 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_10MBPS;
5298 case LM_LINE_SPEED_100MBPS:
5299 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_100MBPS;
5301 case LM_LINE_SPEED_1000MBPS:
5302 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5305 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5309 if (DuplexMode == LM_DUPLEX_MODE_FULL) {
5310 NewPhyCtrl |= PHY_CTRL_FULL_DUPLEX_MODE;
5313 /* Don't do anything if the PHY_CTRL is already what we wanted. */
5314 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
5315 if (Value32 != NewPhyCtrl) {
5316 /* Temporary bring the link down before forcing line speed. */
5317 LM_WritePhy (pDevice, PHY_CTRL_REG,
5318 PHY_CTRL_LOOPBACK_MODE);
5320 /* Wait for link to go down. */
5321 for (Cnt = 0; Cnt < 15000; Cnt++) {
5324 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
5325 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
5327 if (!(Value32 & PHY_STATUS_LINK_PASS)) {
5333 LM_WritePhy (pDevice, PHY_CTRL_REG, NewPhyCtrl);
5337 LM_WritePhy (pDevice, PHY_CTRL_REG, PHY_CTRL_AUTO_NEG_ENABLE |
5338 PHY_CTRL_RESTART_AUTO_NEG);
5341 return LM_STATUS_SUCCESS;
5342 } /* LM_ForceAutoNegBcm540xPhy */
5344 /******************************************************************************/
5348 /******************************************************************************/
5350 LM_ForceAutoNeg (PLM_DEVICE_BLOCK pDevice,
5351 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
5355 /* Initialize the phy chip. */
5356 switch (pDevice->PhyId & PHY_ID_MASK) {
5357 case PHY_BCM5400_PHY_ID:
5358 case PHY_BCM5401_PHY_ID:
5359 case PHY_BCM5411_PHY_ID:
5360 case PHY_BCM5701_PHY_ID:
5361 case PHY_BCM5703_PHY_ID:
5362 case PHY_BCM5704_PHY_ID:
5364 LM_ForceAutoNegBcm540xPhy (pDevice, RequestedMediaType);
5368 LmStatus = LM_STATUS_FAILURE;
5373 } /* LM_ForceAutoNeg */
5375 /******************************************************************************/
5379 /******************************************************************************/
5380 LM_STATUS LM_LoadFirmware (PLM_DEVICE_BLOCK pDevice,
5381 PT3_FWIMG_INFO pFwImg,
5382 LM_UINT32 LoadCpu, LM_UINT32 StartCpu)
5387 if (LoadCpu & T3_RX_CPU_ID) {
5388 if (LM_HaltCpu (pDevice, T3_RX_CPU_ID) != LM_STATUS_SUCCESS) {
5389 return LM_STATUS_FAILURE;
5392 /* First of all clear scrach pad memory */
5393 for (i = 0; i < T3_RX_CPU_SPAD_SIZE; i += 4) {
5394 LM_RegWrInd (pDevice, T3_RX_CPU_SPAD_ADDR + i, 0);
5397 /* Copy code first */
5398 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5399 for (i = 0; i <= pFwImg->Text.Length; i += 4) {
5400 LM_RegWrInd (pDevice, address + i,
5401 ((LM_UINT32 *) pFwImg->Text.Buffer)[i /
5406 T3_RX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5407 for (i = 0; i <= pFwImg->ROnlyData.Length; i += 4) {
5408 LM_RegWrInd (pDevice, address + i,
5409 ((LM_UINT32 *) pFwImg->ROnlyData.
5413 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5414 for (i = 0; i <= pFwImg->Data.Length; i += 4) {
5415 LM_RegWrInd (pDevice, address + i,
5416 ((LM_UINT32 *) pFwImg->Data.Buffer)[i /
5421 if (LoadCpu & T3_TX_CPU_ID) {
5422 if (LM_HaltCpu (pDevice, T3_TX_CPU_ID) != LM_STATUS_SUCCESS) {
5423 return LM_STATUS_FAILURE;
5426 /* First of all clear scrach pad memory */
5427 for (i = 0; i < T3_TX_CPU_SPAD_SIZE; i += 4) {
5428 LM_RegWrInd (pDevice, T3_TX_CPU_SPAD_ADDR + i, 0);
5431 /* Copy code first */
5432 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5433 for (i = 0; i <= pFwImg->Text.Length; i += 4) {
5434 LM_RegWrInd (pDevice, address + i,
5435 ((LM_UINT32 *) pFwImg->Text.Buffer)[i /
5440 T3_TX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5441 for (i = 0; i <= pFwImg->ROnlyData.Length; i += 4) {
5442 LM_RegWrInd (pDevice, address + i,
5443 ((LM_UINT32 *) pFwImg->ROnlyData.
5447 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5448 for (i = 0; i <= pFwImg->Data.Length; i += 4) {
5449 LM_RegWrInd (pDevice, address + i,
5450 ((LM_UINT32 *) pFwImg->Data.Buffer)[i /
5455 if (StartCpu & T3_RX_CPU_ID) {
5457 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5458 REG_WR (pDevice, rxCpu.reg.PC, pFwImg->StartAddress);
5459 for (i = 0; i < 5; i++) {
5460 if (pFwImg->StartAddress ==
5461 REG_RD (pDevice, rxCpu.reg.PC))
5464 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5465 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
5466 REG_WR (pDevice, rxCpu.reg.PC, pFwImg->StartAddress);
5470 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5471 REG_WR (pDevice, rxCpu.reg.mode, 0);
5474 if (StartCpu & T3_TX_CPU_ID) {
5476 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5477 REG_WR (pDevice, txCpu.reg.PC, pFwImg->StartAddress);
5478 for (i = 0; i < 5; i++) {
5479 if (pFwImg->StartAddress ==
5480 REG_RD (pDevice, txCpu.reg.PC))
5483 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5484 REG_WR (pDevice, txCpu.reg.mode, CPU_MODE_HALT);
5485 REG_WR (pDevice, txCpu.reg.PC, pFwImg->StartAddress);
5489 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5490 REG_WR (pDevice, txCpu.reg.mode, 0);
5493 return LM_STATUS_SUCCESS;
5496 STATIC LM_STATUS LM_HaltCpu (PLM_DEVICE_BLOCK pDevice, LM_UINT32 cpu_number)
5500 if (cpu_number == T3_RX_CPU_ID) {
5501 for (i = 0; i < 10000; i++) {
5502 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5503 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
5505 if (REG_RD (pDevice, rxCpu.reg.mode) & CPU_MODE_HALT)
5509 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5510 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
5513 for (i = 0; i < 10000; i++) {
5514 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5515 REG_WR (pDevice, txCpu.reg.mode, CPU_MODE_HALT);
5517 if (REG_RD (pDevice, txCpu.reg.mode) & CPU_MODE_HALT)
5522 return ((i == 10000) ? LM_STATUS_FAILURE : LM_STATUS_SUCCESS);
5525 int LM_BlinkLED (PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlinkDurationSec)
5531 if (BlinkDurationSec == 0) {
5534 if (BlinkDurationSec > 120) {
5535 BlinkDurationSec = 120;
5538 Oldcfg = REG_RD (pDevice, MacCtrl.LedCtrl);
5539 for (j = 0; j < BlinkDurationSec * 2; j++) {
5541 /* Turn on the LEDs. */
5542 REG_WR (pDevice, MacCtrl.LedCtrl,
5543 LED_CTRL_OVERRIDE_LINK_LED |
5544 LED_CTRL_1000MBPS_LED_ON |
5545 LED_CTRL_100MBPS_LED_ON |
5546 LED_CTRL_10MBPS_LED_ON |
5547 LED_CTRL_OVERRIDE_TRAFFIC_LED |
5548 LED_CTRL_BLINK_TRAFFIC_LED |
5549 LED_CTRL_TRAFFIC_LED);
5551 /* Turn off the LEDs. */
5552 REG_WR (pDevice, MacCtrl.LedCtrl,
5553 LED_CTRL_OVERRIDE_LINK_LED |
5554 LED_CTRL_OVERRIDE_TRAFFIC_LED);
5558 current->state = TASK_INTERRUPTIBLE;
5559 if (schedule_timeout (HZ / 2) != 0) {
5564 udelay (100000); /* 1s sleep */
5567 REG_WR (pDevice, MacCtrl.LedCtrl, Oldcfg);
5571 int t3_do_dma (PLM_DEVICE_BLOCK pDevice,
5572 LM_PHYSICAL_ADDRESS host_addr_phy, int length, int dma_read)
5574 T3_DMA_DESC dma_desc;
5576 LM_UINT32 dma_desc_addr;
5579 REG_WR (pDevice, BufMgr.Mode, 0);
5580 REG_WR (pDevice, Ftq.Reset, 0);
5582 dma_desc.host_addr.High = host_addr_phy.High;
5583 dma_desc.host_addr.Low = host_addr_phy.Low;
5584 dma_desc.nic_mbuf = 0x2100;
5585 dma_desc.len = length;
5586 dma_desc.flags = 0x00000004; /* Generate Rx-CPU event */
5589 dma_desc.cqid_sqid = (T3_QID_RX_BD_COMP << 8) |
5590 T3_QID_DMA_HIGH_PRI_READ;
5591 REG_WR (pDevice, DmaRead.Mode, DMA_READ_MODE_ENABLE);
5593 dma_desc.cqid_sqid = (T3_QID_RX_DATA_COMP << 8) |
5594 T3_QID_DMA_HIGH_PRI_WRITE;
5595 REG_WR (pDevice, DmaWrite.Mode, DMA_WRITE_MODE_ENABLE);
5598 dma_desc_addr = T3_NIC_DMA_DESC_POOL_ADDR;
5600 /* Writing this DMA descriptor to DMA memory */
5601 for (i = 0; i < sizeof (T3_DMA_DESC); i += 4) {
5602 value32 = *((PLM_UINT32) (((PLM_UINT8) & dma_desc) + i));
5603 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG,
5605 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG,
5606 cpu_to_le32 (value32));
5608 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, 0);
5611 REG_WR (pDevice, Ftq.DmaHighReadFtqFifoEnqueueDequeue,
5614 REG_WR (pDevice, Ftq.DmaHighWriteFtqFifoEnqueueDequeue,
5617 for (i = 0; i < 40; i++) {
5621 Ftq.RcvBdCompFtqFifoEnqueueDequeue);
5625 Ftq.RcvDataCompFtqFifoEnqueueDequeue);
5627 if ((value32 & 0xffff) == dma_desc_addr)
5633 return LM_STATUS_SUCCESS;
5637 LM_DmaTest (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
5638 LM_PHYSICAL_ADDRESS BufferPhy, LM_UINT32 BufferSize)
5642 int dma_success = 0;
5644 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
5645 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
5646 return LM_STATUS_SUCCESS;
5648 while (!dma_success) {
5649 /* Fill data with incremental patterns */
5650 ptr = (LM_UINT32 *) pBufferVirt;
5651 for (j = 0; j < BufferSize / 4; j++)
5654 if (t3_do_dma (pDevice, BufferPhy, BufferSize, 1) ==
5655 LM_STATUS_FAILURE) {
5656 return LM_STATUS_FAILURE;
5660 ptr = (LM_UINT32 *) pBufferVirt;
5661 /* Fill data with zero */
5662 for (j = 0; j < BufferSize / 4; j++)
5665 if (t3_do_dma (pDevice, BufferPhy, BufferSize, 0) ==
5666 LM_STATUS_FAILURE) {
5667 return LM_STATUS_FAILURE;
5671 /* Check for data */
5672 ptr = (LM_UINT32 *) pBufferVirt;
5673 for (j = 0; j < BufferSize / 4; j++) {
5677 DMA_CTRL_WRITE_BOUNDARY_MASK)
5678 == DMA_CTRL_WRITE_BOUNDARY_DISABLE) {
5679 pDevice->DmaReadWriteCtrl =
5682 ~DMA_CTRL_WRITE_BOUNDARY_MASK) |
5683 DMA_CTRL_WRITE_BOUNDARY_16;
5685 PciCfg.DmaReadWriteCtrl,
5686 pDevice->DmaReadWriteCtrl);
5689 return LM_STATUS_FAILURE;
5693 if (j == (BufferSize / 4))
5696 return LM_STATUS_SUCCESS;