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 (CONFIG_COMMANDS & CFG_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(
33 LM_REQUESTED_MEDIA_TYPE RequestedMediaType,
34 PLM_MEDIA_TYPE pMediaType, PLM_LINE_SPEED pLineSpeed,
35 PLM_DUPLEX_MODE pDuplexMode);
37 static LM_STATUS LM_InitBcm540xPhy(PLM_DEVICE_BLOCK pDevice);
39 __inline static LM_VOID LM_ServiceRxInterrupt(PLM_DEVICE_BLOCK pDevice);
40 __inline static LM_VOID LM_ServiceTxInterrupt(PLM_DEVICE_BLOCK pDevice);
42 static LM_STATUS LM_ForceAutoNegBcm540xPhy(PLM_DEVICE_BLOCK pDevice,
43 LM_REQUESTED_MEDIA_TYPE RequestedMediaType);
44 static LM_STATUS LM_ForceAutoNeg(PLM_DEVICE_BLOCK pDevice,
45 LM_REQUESTED_MEDIA_TYPE RequestedMediaType);
46 static LM_UINT32 GetPhyAdFlowCntrlSettings(PLM_DEVICE_BLOCK pDevice);
47 STATIC LM_STATUS LM_SetFlowControl(PLM_DEVICE_BLOCK pDevice,
48 LM_UINT32 LocalPhyAd, LM_UINT32 RemotePhyAd);
49 #if INCLUDE_TBI_SUPPORT
50 STATIC LM_STATUS LM_SetupFiberPhy(PLM_DEVICE_BLOCK pDevice);
51 STATIC LM_STATUS LM_InitBcm800xPhy(PLM_DEVICE_BLOCK pDevice);
53 STATIC LM_STATUS LM_SetupCopperPhy(PLM_DEVICE_BLOCK pDevice);
54 STATIC PLM_ADAPTER_INFO LM_GetAdapterInfoBySsid(LM_UINT16 Svid, LM_UINT16 Ssid);
55 STATIC LM_STATUS LM_DmaTest(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
56 LM_PHYSICAL_ADDRESS BufferPhy, LM_UINT32 BufferSize);
57 STATIC LM_STATUS LM_HaltCpu(PLM_DEVICE_BLOCK pDevice,LM_UINT32 cpu_number);
58 STATIC LM_STATUS LM_ResetChip(PLM_DEVICE_BLOCK pDevice);
59 STATIC LM_STATUS LM_Test4GBoundary(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket,
62 /******************************************************************************/
63 /* External functions. */
64 /******************************************************************************/
66 LM_STATUS LM_LoadRlsFirmware(PLM_DEVICE_BLOCK pDevice);
69 /******************************************************************************/
73 /******************************************************************************/
76 PLM_DEVICE_BLOCK pDevice,
80 #if PCIX_TARGET_WORKAROUND
81 MM_ACQUIRE_UNDI_LOCK(pDevice);
83 MM_WriteConfig32(pDevice, T3_PCI_REG_ADDR_REG, Register);
84 MM_ReadConfig32(pDevice, T3_PCI_REG_DATA_REG, &Value32);
85 #if PCIX_TARGET_WORKAROUND
86 MM_RELEASE_UNDI_LOCK(pDevice);
93 /******************************************************************************/
97 /******************************************************************************/
100 PLM_DEVICE_BLOCK pDevice,
104 #if PCIX_TARGET_WORKAROUND
105 MM_ACQUIRE_UNDI_LOCK(pDevice);
107 MM_WriteConfig32(pDevice, T3_PCI_REG_ADDR_REG, Register);
108 MM_WriteConfig32(pDevice, T3_PCI_REG_DATA_REG, Value32);
109 #if PCIX_TARGET_WORKAROUND
110 MM_RELEASE_UNDI_LOCK(pDevice);
115 /******************************************************************************/
119 /******************************************************************************/
122 PLM_DEVICE_BLOCK pDevice,
126 MM_ACQUIRE_UNDI_LOCK(pDevice);
127 #ifdef BIG_ENDIAN_HOST
128 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
129 Value32 = REG_RD(pDevice, PciCfg.MemWindowData);
130 /* Value32 = REG_RD(pDevice,uIntMem.Mbuf[(MemAddr & 0x7fff)/4]); */
132 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
133 MM_ReadConfig32(pDevice, T3_PCI_MEM_WIN_DATA_REG, &Value32);
135 MM_RELEASE_UNDI_LOCK(pDevice);
141 /******************************************************************************/
145 /******************************************************************************/
148 PLM_DEVICE_BLOCK pDevice,
151 MM_ACQUIRE_UNDI_LOCK(pDevice);
152 #ifdef BIG_ENDIAN_HOST
153 REG_WR(pDevice,PciCfg.MemWindowBaseAddr,MemAddr);
154 REG_WR(pDevice,uIntMem.Mbuf[(MemAddr & 0x7fff)/4],Value32);
156 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
157 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_DATA_REG, Value32);
159 MM_RELEASE_UNDI_LOCK(pDevice);
163 /******************************************************************************/
167 /******************************************************************************/
170 PLM_DEVICE_BLOCK pDevice) {
174 LM_UINT32 StdBdAdded = 0;
175 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
176 LM_UINT32 JumboBdAdded = 0;
177 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
179 Lmstatus = LM_STATUS_SUCCESS;
181 pPacket = (PLM_PACKET) QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
183 switch(pPacket->u.Rx.RcvProdRing) {
184 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
185 case T3_JUMBO_RCV_PROD_RING: /* Jumbo Receive Ring. */
186 /* Initialize the buffer descriptor. */
188 &pDevice->pRxJumboBdVirt[pDevice->RxJumboProdIdx];
189 pRcvBd->Flags = RCV_BD_FLAG_END | RCV_BD_FLAG_JUMBO_RING;
190 pRcvBd->Len = (LM_UINT16) pDevice->RxJumboBufferSize;
192 /* Initialize the receive buffer pointer */
193 #if 0 /* Jimmy, deleted in new */
194 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
195 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
197 MM_MapRxDma(pDevice, pPacket, &pRcvBd->HostAddr);
199 /* The opaque field may point to an offset from a fix addr. */
200 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR(pPacket) -
201 MM_UINT_PTR(pDevice->pPacketDescBase));
203 /* Update the producer index. */
204 pDevice->RxJumboProdIdx = (pDevice->RxJumboProdIdx + 1) &
205 T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
209 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
211 case T3_STD_RCV_PROD_RING: /* Standard Receive Ring. */
212 /* Initialize the buffer descriptor. */
213 pRcvBd = &pDevice->pRxStdBdVirt[pDevice->RxStdProdIdx];
214 pRcvBd->Flags = RCV_BD_FLAG_END;
215 pRcvBd->Len = MAX_STD_RCV_BUFFER_SIZE;
217 /* Initialize the receive buffer pointer */
218 #if 0 /* Jimmy, deleted in new replaced with MM_MapRxDma */
219 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
220 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
222 MM_MapRxDma(pDevice, pPacket, &pRcvBd->HostAddr);
224 /* The opaque field may point to an offset from a fix addr. */
225 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR(pPacket) -
226 MM_UINT_PTR(pDevice->pPacketDescBase));
228 /* Update the producer index. */
229 pDevice->RxStdProdIdx = (pDevice->RxStdProdIdx + 1) &
230 T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
235 case T3_UNKNOWN_RCV_PROD_RING:
237 Lmstatus = LM_STATUS_FAILURE;
241 /* Bail out if there is any error. */
242 if(Lmstatus != LM_STATUS_SUCCESS)
247 pPacket = (PLM_PACKET) QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
251 /* Update the procedure index. */
254 MB_REG_WR(pDevice, Mailbox.RcvStdProdIdx.Low, pDevice->RxStdProdIdx);
256 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
259 MB_REG_WR(pDevice, Mailbox.RcvJumboProdIdx.Low,
260 pDevice->RxJumboProdIdx);
262 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
265 } /* LM_QueueRxPackets */
268 /******************************************************************************/
272 /******************************************************************************/
275 PLM_DEVICE_BLOCK pDevice)
280 /* Intialize clock period and state machine. */
281 Value32 = SEEPROM_ADDR_CLK_PERD(SEEPROM_CLOCK_PERIOD) |
282 SEEPROM_ADDR_FSM_RESET;
283 REG_WR(pDevice, Grc.EepromAddr, Value32);
285 for(j = 0; j < 100; j++)
290 /* Serial eeprom access using the Grc.EepromAddr/EepromData registers. */
291 Value32 = REG_RD(pDevice, Grc.LocalCtrl);
292 REG_WR(pDevice, Grc.LocalCtrl, Value32 | GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM);
294 /* Set the 5701 compatibility mode if we are using EEPROM. */
295 if(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
296 T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5701)
298 Value32 = REG_RD(pDevice, Nvram.Config1);
299 if((Value32 & FLASH_INTERFACE_ENABLE) == 0)
301 /* Use the new interface to read EEPROM. */
302 Value32 &= ~FLASH_COMPAT_BYPASS;
304 REG_WR(pDevice, Nvram.Config1, Value32);
310 /******************************************************************************/
314 /******************************************************************************/
317 PLM_DEVICE_BLOCK pDevice,
326 if(Offset > SEEPROM_CHIP_SIZE)
328 return LM_STATUS_FAILURE;
331 Dev = Offset / SEEPROM_CHIP_SIZE;
332 Addr = Offset % SEEPROM_CHIP_SIZE;
334 Value32 = REG_RD(pDevice, Grc.EepromAddr);
335 Value32 &= ~(SEEPROM_ADDR_ADDRESS_MASK | SEEPROM_ADDR_DEV_ID_MASK |
336 SEEPROM_ADDR_RW_MASK);
337 REG_WR(pDevice, Grc.EepromAddr, Value32 | SEEPROM_ADDR_DEV_ID(Dev) |
338 SEEPROM_ADDR_ADDRESS(Addr) | SEEPROM_ADDR_START | SEEPROM_ADDR_READ);
340 for(j = 0; j < 1000; j++)
342 Value32 = REG_RD(pDevice, Grc.EepromAddr);
343 if(Value32 & SEEPROM_ADDR_COMPLETE)
350 if(Value32 & SEEPROM_ADDR_COMPLETE)
352 Value32 = REG_RD(pDevice, Grc.EepromData);
355 return LM_STATUS_SUCCESS;
358 return LM_STATUS_FAILURE;
359 } /* LM_EepromRead */
362 /******************************************************************************/
366 /******************************************************************************/
369 PLM_DEVICE_BLOCK pDevice,
377 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
378 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
380 Status = LM_EepromRead(pDevice, Offset, pData);
384 /* Determine if we have flash or EEPROM. */
385 Value32 = REG_RD(pDevice, Nvram.Config1);
386 if(Value32 & FLASH_INTERFACE_ENABLE)
388 if(Value32 & FLASH_SSRAM_BUFFERRED_MODE)
390 Offset = ((Offset/BUFFERED_FLASH_PAGE_SIZE) <<
391 BUFFERED_FLASH_PAGE_POS) +
392 (Offset % BUFFERED_FLASH_PAGE_SIZE);
396 REG_WR(pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
397 for (j = 0; j < 1000; j++)
399 if (REG_RD(pDevice, Nvram.SwArb) & SW_ARB_GNT1)
407 return LM_STATUS_FAILURE;
410 /* Read from flash or EEPROM with the new 5703/02 interface. */
411 REG_WR(pDevice, Nvram.Addr, Offset & NVRAM_ADDRESS_MASK);
413 REG_WR(pDevice, Nvram.Cmd, NVRAM_CMD_RD | NVRAM_CMD_DO_IT |
414 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
416 /* Wait for the done bit to clear. */
417 for(j = 0; j < 500; j++)
421 Value32 = REG_RD(pDevice, Nvram.Cmd);
422 if(!(Value32 & NVRAM_CMD_DONE))
428 /* Wait for the done bit. */
429 if(!(Value32 & NVRAM_CMD_DONE))
431 for(j = 0; j < 500; j++)
435 Value32 = REG_RD(pDevice, Nvram.Cmd);
436 if(Value32 & NVRAM_CMD_DONE)
440 *pData = REG_RD(pDevice, Nvram.ReadData);
442 /* Change the endianess. */
443 *pData = ((*pData & 0xff) << 24)| ((*pData & 0xff00) << 8)|
444 ((*pData & 0xff0000) >> 8) | ((*pData >> 24) & 0xff);
451 REG_WR(pDevice, Nvram.SwArb, SW_ARB_REQ_CLR1);
452 if(Value32 & NVRAM_CMD_DONE)
454 Status = LM_STATUS_SUCCESS;
458 Status = LM_STATUS_FAILURE;
467 LM_ReadVPD(PLM_DEVICE_BLOCK pDevice)
469 LM_UINT32 Vpd_arr[256/4];
470 LM_UINT8 *Vpd = (LM_UINT8 *) &Vpd_arr[0];
471 LM_UINT32 *Vpd_dptr = &Vpd_arr[0];
475 /* Read PN from VPD */
476 for (j = 0; j < 256; j += 4, Vpd_dptr++ )
478 if (LM_NvramRead(pDevice, 0x100 + j, &Value32) != LM_STATUS_SUCCESS) {
479 printf("BCM570x: LM_ReadVPD: VPD read failed"
480 " (no EEPROM onboard)\n");
483 *Vpd_dptr = cpu_to_le32(Value32);
485 for (j = 0; j < 256; )
487 unsigned int Vpd_r_len;
488 unsigned int Vpd_r_end;
490 if ((Vpd[j] == 0x82) || (Vpd[j] == 0x91))
492 j = j + 3 + Vpd[j + 1] + (Vpd[j + 2] << 8);
494 else if (Vpd[j] == 0x90)
496 Vpd_r_len = Vpd[j + 1] + (Vpd[j + 2] << 8);
498 Vpd_r_end = Vpd_r_len + j;
499 while (j < Vpd_r_end)
501 if ((Vpd[j] == 'P') && (Vpd[j + 1] == 'N'))
503 unsigned int len = Vpd[j + 2];
507 memcpy(pDevice->PartNo, &Vpd[j + 3], len);
529 LM_ReadBootCodeVersion(PLM_DEVICE_BLOCK pDevice)
531 LM_UINT32 Value32, offset, ver_offset;
534 if (LM_NvramRead(pDevice, 0x0, &Value32) != LM_STATUS_SUCCESS)
536 if (Value32 != 0xaa559966)
538 if (LM_NvramRead(pDevice, 0xc, &offset) != LM_STATUS_SUCCESS)
541 offset = ((offset & 0xff) << 24)| ((offset & 0xff00) << 8)|
542 ((offset & 0xff0000) >> 8) | ((offset >> 24) & 0xff);
543 if (LM_NvramRead(pDevice, offset, &Value32) != LM_STATUS_SUCCESS)
545 if ((Value32 == 0x0300000e) &&
546 (LM_NvramRead(pDevice, offset + 4, &Value32) == LM_STATUS_SUCCESS) &&
549 if (LM_NvramRead(pDevice, offset + 8, &ver_offset) != LM_STATUS_SUCCESS)
551 ver_offset = ((ver_offset & 0xff0000) >> 8) |
552 ((ver_offset >> 24) & 0xff);
553 for (i = 0; i < 16; i += 4) {
554 if (LM_NvramRead(pDevice, offset + ver_offset + i, &Value32) !=
559 *((LM_UINT32 *) &pDevice->BootCodeVer[i]) = cpu_to_le32(Value32);
565 if (LM_NvramRead(pDevice, 0x94, &Value32) != LM_STATUS_SUCCESS)
569 c = ((Value32 & 0xff0000) >> 16);
572 pDevice->BootCodeVer[i++] = c + '0';
575 pDevice->BootCodeVer[i++] = (c / 10) + '0';
576 pDevice->BootCodeVer[i++] = (c % 10) + '0';
578 pDevice->BootCodeVer[i++] = '.';
579 c = (Value32 & 0xff000000) >> 24;
581 pDevice->BootCodeVer[i++] = c + '0';
584 pDevice->BootCodeVer[i++] = (c / 10) + '0';
585 pDevice->BootCodeVer[i++] = (c % 10) + '0';
587 pDevice->BootCodeVer[i] = 0;
592 LM_GetBusSpeed(PLM_DEVICE_BLOCK pDevice)
594 LM_UINT32 PciState = pDevice->PciState;
598 if (PciState & T3_PCI_STATE_32BIT_PCI_BUS)
600 strcpy(pDevice->BusSpeedStr, "32-bit ");
604 strcpy(pDevice->BusSpeedStr, "64-bit ");
606 if (PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)
608 strcat(pDevice->BusSpeedStr, "PCI ");
609 if (PciState & T3_PCI_STATE_HIGH_BUS_SPEED)
620 strcat(pDevice->BusSpeedStr, "PCIX ");
621 if (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE)
627 ClockCtrl = REG_RD(pDevice, PciCfg.ClockCtrl) & 0x1f;
652 strcat(pDevice->BusSpeedStr, SpeedStr);
655 /******************************************************************************/
657 /* This routine initializes default parameters and reads the PCI */
658 /* configurations. */
661 /* LM_STATUS_SUCCESS */
662 /******************************************************************************/
665 PLM_DEVICE_BLOCK pDevice)
667 PLM_ADAPTER_INFO pAdapterInfo;
671 LM_UINT32 EeSigFound;
672 LM_UINT32 EePhyTypeSerdes = 0;
673 LM_UINT32 EePhyLedMode = 0;
674 LM_UINT32 EePhyId = 0;
676 /* Get Device Id and Vendor Id */
677 Status = MM_ReadConfig32(pDevice, PCI_VENDOR_ID_REG, &Value32);
678 if(Status != LM_STATUS_SUCCESS)
682 pDevice->PciVendorId = (LM_UINT16) Value32;
683 pDevice->PciDeviceId = (LM_UINT16) (Value32 >> 16);
685 /* If we are not getting the write adapter, exit. */
686 if((Value32 != T3_PCI_ID_BCM5700) &&
687 (Value32 != T3_PCI_ID_BCM5701) &&
688 (Value32 != T3_PCI_ID_BCM5702) &&
689 (Value32 != T3_PCI_ID_BCM5702x) &&
690 (Value32 != T3_PCI_ID_BCM5702FE) &&
691 (Value32 != T3_PCI_ID_BCM5703) &&
692 (Value32 != T3_PCI_ID_BCM5703x) &&
693 (Value32 != T3_PCI_ID_BCM5704))
695 return LM_STATUS_FAILURE;
698 Status = MM_ReadConfig32(pDevice, PCI_REV_ID_REG, &Value32);
699 if(Status != LM_STATUS_SUCCESS)
703 pDevice->PciRevId = (LM_UINT8) Value32;
706 Status = MM_ReadConfig32(pDevice, PCI_INT_LINE_REG, &Value32);
707 if(Status != LM_STATUS_SUCCESS)
711 pDevice->Irq = (LM_UINT8) Value32;
713 /* Get interrupt pin. */
714 pDevice->IntPin = (LM_UINT8) (Value32 >> 8);
716 /* Get chip revision id. */
717 Status = MM_ReadConfig32(pDevice, T3_PCI_MISC_HOST_CTRL_REG, &Value32);
718 pDevice->ChipRevId = Value32 >> 16;
720 /* Get subsystem vendor. */
721 Status = MM_ReadConfig32(pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG, &Value32);
722 if(Status != LM_STATUS_SUCCESS)
726 pDevice->SubsystemVendorId = (LM_UINT16) Value32;
728 /* Get PCI subsystem id. */
729 pDevice->SubsystemId = (LM_UINT16) (Value32 >> 16);
731 /* Get the cache line size. */
732 MM_ReadConfig32(pDevice, PCI_CACHE_LINE_SIZE_REG, &Value32);
733 pDevice->CacheLineSize = (LM_UINT8) Value32;
734 pDevice->SavedCacheLineReg = Value32;
736 if(pDevice->ChipRevId != T3_CHIP_ID_5703_A1 &&
737 pDevice->ChipRevId != T3_CHIP_ID_5703_A2 &&
738 pDevice->ChipRevId != T3_CHIP_ID_5704_A0)
740 pDevice->UndiFix = FALSE;
742 #if !PCIX_TARGET_WORKAROUND
743 pDevice->UndiFix = FALSE;
745 /* Map the memory base to system address space. */
746 if (!pDevice->UndiFix)
748 Status = MM_MapMemBase(pDevice);
749 if(Status != LM_STATUS_SUCCESS)
753 /* Initialize the memory view pointer. */
754 pDevice->pMemView = (PT3_STD_MEM_MAP) pDevice->pMappedMemBase;
757 #if PCIX_TARGET_WORKAROUND
758 /* store whether we are in PCI are PCI-X mode */
759 pDevice->EnablePciXFix = FALSE;
761 MM_ReadConfig32(pDevice, T3_PCI_STATE_REG, &Value32);
762 if((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0)
764 /* Enable PCI-X workaround only if we are running on 5700 BX. */
765 if(T3_CHIP_REV(pDevice->ChipRevId) == T3_CHIP_REV_5700_BX)
767 pDevice->EnablePciXFix = TRUE;
770 if (pDevice->UndiFix)
772 pDevice->EnablePciXFix = TRUE;
775 /* Bx bug: due to the "byte_enable bug" in PCI-X mode, the power */
776 /* management register may be clobbered which may cause the */
777 /* BCM5700 to go into D3 state. While in this state, we will */
778 /* not have memory mapped register access. As a workaround, we */
779 /* need to restore the device to D0 state. */
780 MM_ReadConfig32(pDevice, T3_PCI_PM_STATUS_CTRL_REG, &Value32);
781 Value32 |= T3_PM_PME_ASSERTED;
782 Value32 &= ~T3_PM_POWER_STATE_MASK;
783 Value32 |= T3_PM_POWER_STATE_D0;
784 MM_WriteConfig32(pDevice, T3_PCI_PM_STATUS_CTRL_REG, Value32);
786 /* read the current PCI command word */
787 MM_ReadConfig32(pDevice, PCI_COMMAND_REG, &Value32);
789 /* Make sure bus-mastering is enabled. */
790 Value32 |= PCI_BUSMASTER_ENABLE;
792 #if PCIX_TARGET_WORKAROUND
793 /* if we are in PCI-X mode, also make sure mem-mapping and SERR#/PERR#
795 if (pDevice->EnablePciXFix == TRUE) {
796 Value32 |= (PCI_MEM_SPACE_ENABLE | PCI_SYSTEM_ERROR_ENABLE |
797 PCI_PARITY_ERROR_ENABLE);
799 if (pDevice->UndiFix)
801 Value32 &= ~PCI_MEM_SPACE_ENABLE;
806 if(pDevice->EnableMWI)
808 Value32 |= PCI_MEMORY_WRITE_INVALIDATE;
811 Value32 &= (~PCI_MEMORY_WRITE_INVALIDATE);
814 /* Error out if mem-mapping is NOT enabled for PCI systems */
815 if (!(Value32 | PCI_MEM_SPACE_ENABLE))
817 return LM_STATUS_FAILURE;
820 /* save the value we are going to write into the PCI command word */
821 pDevice->PciCommandStatusWords = Value32;
823 Status = MM_WriteConfig32(pDevice, PCI_COMMAND_REG, Value32);
824 if(Status != LM_STATUS_SUCCESS)
829 /* Set power state to D0. */
830 LM_SetPowerState(pDevice, LM_POWER_STATE_D0);
832 #ifdef BIG_ENDIAN_PCI
833 pDevice->MiscHostCtrl =
834 MISC_HOST_CTRL_MASK_PCI_INT |
835 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
836 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
837 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
838 #else /* No CPU Swap modes for PCI IO */
840 /* Setup the mode registers. */
841 pDevice->MiscHostCtrl =
842 MISC_HOST_CTRL_MASK_PCI_INT |
843 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
844 #ifdef BIG_ENDIAN_HOST
845 MISC_HOST_CTRL_ENABLE_ENDIAN_BYTE_SWAP |
846 #endif /* BIG_ENDIAN_HOST */
847 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
848 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
849 #endif /* !BIG_ENDIAN_PCI */
851 /* write to PCI misc host ctr first in order to enable indirect accesses */
852 MM_WriteConfig32(pDevice, T3_PCI_MISC_HOST_CTRL_REG, pDevice->MiscHostCtrl);
854 REG_WR(pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl);
856 #ifdef BIG_ENDIAN_PCI
857 Value32 = GRC_MODE_WORD_SWAP_DATA|
858 GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
860 /* No CPU Swap modes for PCI IO */
861 #ifdef BIG_ENDIAN_HOST
862 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
863 GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
865 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
867 #endif /* !BIG_ENDIAN_PCI */
869 REG_WR(pDevice, Grc.Mode, Value32);
871 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
873 REG_WR(pDevice, Grc.LocalCtrl, GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
874 GRC_MISC_LOCAL_CTRL_GPIO_OE1);
878 /* Enable indirect memory access */
879 REG_WR(pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
881 if (REG_RD(pDevice, PciCfg.ClockCtrl) & T3_PCI_44MHZ_CORE_CLOCK)
883 REG_WR(pDevice, PciCfg.ClockCtrl, T3_PCI_44MHZ_CORE_CLOCK |
884 T3_PCI_SELECT_ALTERNATE_CLOCK);
885 REG_WR(pDevice, PciCfg.ClockCtrl, T3_PCI_SELECT_ALTERNATE_CLOCK);
886 MM_Wait(40); /* required delay is 27usec */
888 REG_WR(pDevice, PciCfg.ClockCtrl, 0);
889 REG_WR(pDevice, PciCfg.MemWindowBaseAddr, 0);
891 #if PCIX_TARGET_WORKAROUND
892 MM_ReadConfig32(pDevice, T3_PCI_STATE_REG, &Value32);
893 if ((pDevice->EnablePciXFix == FALSE) &&
894 ((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0))
896 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
897 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
898 pDevice->ChipRevId == T3_CHIP_ID_5701_B2 ||
899 pDevice->ChipRevId == T3_CHIP_ID_5701_B5)
901 __raw_writel(0, &(pDevice->pMemView->uIntMem.MemBlock32K[0x300]));
902 __raw_writel(0, &(pDevice->pMemView->uIntMem.MemBlock32K[0x301]));
903 __raw_writel(0xffffffff, &(pDevice->pMemView->uIntMem.MemBlock32K[0x301]));
904 if (__raw_readl(&(pDevice->pMemView->uIntMem.MemBlock32K[0x300])))
906 pDevice->EnablePciXFix = TRUE;
913 * This code was at the beginning of else block below, but that's
914 * a bug if node address in shared memory.
917 LM_NvramInit(pDevice);
919 /* Get the node address. First try to get in from the shared memory. */
920 /* If the signature is not present, then get it from the NVRAM. */
921 Value32 = MEM_RD_OFFSET(pDevice, T3_MAC_ADDR_HIGH_MAILBOX);
922 if((Value32 >> 16) == 0x484b)
925 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 8);
926 pDevice->NodeAddress[1] = (LM_UINT8) Value32;
928 Value32 = MEM_RD_OFFSET(pDevice, T3_MAC_ADDR_LOW_MAILBOX);
930 pDevice->NodeAddress[2] = (LM_UINT8) (Value32 >> 24);
931 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 16);
932 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 8);
933 pDevice->NodeAddress[5] = (LM_UINT8) Value32;
935 Status = LM_STATUS_SUCCESS;
939 Status = LM_NvramRead(pDevice, 0x7c, &Value32);
940 if(Status == LM_STATUS_SUCCESS)
942 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 16);
943 pDevice->NodeAddress[1] = (LM_UINT8) (Value32 >> 24);
945 Status = LM_NvramRead(pDevice, 0x80, &Value32);
947 pDevice->NodeAddress[2] = (LM_UINT8) Value32;
948 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 8);
949 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 16);
950 pDevice->NodeAddress[5] = (LM_UINT8) (Value32 >> 24);
954 /* Assign a default address. */
955 if(Status != LM_STATUS_SUCCESS)
958 printk(KERN_ERR "Cannot get MAC addr from NVRAM. Using default.\n");
960 pDevice->NodeAddress[0] = 0x00; pDevice->NodeAddress[1] = 0x10;
961 pDevice->NodeAddress[2] = 0x18; pDevice->NodeAddress[3] = 0x68;
962 pDevice->NodeAddress[4] = 0x61; pDevice->NodeAddress[5] = 0x76;
965 pDevice->PermanentNodeAddress[0] = pDevice->NodeAddress[0];
966 pDevice->PermanentNodeAddress[1] = pDevice->NodeAddress[1];
967 pDevice->PermanentNodeAddress[2] = pDevice->NodeAddress[2];
968 pDevice->PermanentNodeAddress[3] = pDevice->NodeAddress[3];
969 pDevice->PermanentNodeAddress[4] = pDevice->NodeAddress[4];
970 pDevice->PermanentNodeAddress[5] = pDevice->NodeAddress[5];
972 /* Initialize the default values. */
973 pDevice->NoTxPseudoHdrChksum = FALSE;
974 pDevice->NoRxPseudoHdrChksum = FALSE;
975 pDevice->NicSendBd = FALSE;
976 pDevice->TxPacketDescCnt = DEFAULT_TX_PACKET_DESC_COUNT;
977 pDevice->RxStdDescCnt = DEFAULT_STD_RCV_DESC_COUNT;
978 pDevice->RxCoalescingTicks = DEFAULT_RX_COALESCING_TICKS;
979 pDevice->TxCoalescingTicks = DEFAULT_TX_COALESCING_TICKS;
980 pDevice->RxMaxCoalescedFrames = DEFAULT_RX_MAX_COALESCED_FRAMES;
981 pDevice->TxMaxCoalescedFrames = DEFAULT_TX_MAX_COALESCED_FRAMES;
982 pDevice->RxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
983 pDevice->TxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
984 pDevice->RxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
985 pDevice->TxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
986 pDevice->StatsCoalescingTicks = DEFAULT_STATS_COALESCING_TICKS;
987 pDevice->EnableMWI = FALSE;
988 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
989 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
990 pDevice->DisableAutoNeg = FALSE;
991 pDevice->PhyIntMode = T3_PHY_INT_MODE_AUTO;
992 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_AUTO;
993 pDevice->LedMode = LED_MODE_AUTO;
994 pDevice->ResetPhyOnInit = TRUE;
995 pDevice->DelayPciGrant = TRUE;
996 pDevice->UseTaggedStatus = FALSE;
997 pDevice->OneDmaAtOnce = BAD_DEFAULT_VALUE;
999 pDevice->DmaMbufLowMark = T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO;
1000 pDevice->RxMacMbufLowMark = T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO;
1001 pDevice->MbufHighMark = T3_DEF_MBUF_HIGH_WMARK_JUMBO;
1003 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_AUTO;
1004 pDevice->TaskOffloadCap = LM_TASK_OFFLOAD_NONE;
1005 pDevice->FlowControlCap = LM_FLOW_CONTROL_AUTO_PAUSE;
1006 pDevice->EnableTbi = FALSE;
1007 #if INCLUDE_TBI_SUPPORT
1008 pDevice->PollTbiLink = BAD_DEFAULT_VALUE;
1011 switch (T3_ASIC_REV(pDevice->ChipRevId))
1013 case T3_ASIC_REV_5704:
1014 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
1015 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE64;
1018 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
1019 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE96;
1023 pDevice->LinkStatus = LM_STATUS_LINK_DOWN;
1024 pDevice->QueueRxPackets = TRUE;
1026 pDevice->EnableWireSpeed = TRUE;
1028 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1029 pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
1030 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1032 /* Make this is a known adapter. */
1033 pAdapterInfo = LM_GetAdapterInfoBySsid(pDevice->SubsystemVendorId,
1034 pDevice->SubsystemId);
1036 pDevice->BondId = REG_RD(pDevice, Grc.MiscCfg) & GRC_MISC_BD_ID_MASK;
1037 if (pDevice->BondId != GRC_MISC_BD_ID_5700 &&
1038 pDevice->BondId != GRC_MISC_BD_ID_5701 &&
1039 pDevice->BondId != GRC_MISC_BD_ID_5702FE &&
1040 pDevice->BondId != GRC_MISC_BD_ID_5703 &&
1041 pDevice->BondId != GRC_MISC_BD_ID_5703S &&
1042 pDevice->BondId != GRC_MISC_BD_ID_5704 &&
1043 pDevice->BondId != GRC_MISC_BD_ID_5704CIOBE)
1045 return LM_STATUS_UNKNOWN_ADAPTER;
1048 pDevice->SplitModeEnable = SPLIT_MODE_DISABLE;
1049 if ((pDevice->ChipRevId == T3_CHIP_ID_5704_A0) &&
1050 (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE))
1052 pDevice->SplitModeEnable = SPLIT_MODE_ENABLE;
1053 pDevice->SplitModeMaxReq = SPLIT_MODE_5704_MAX_REQ;
1056 /* Get Eeprom info. */
1057 Value32 = MEM_RD_OFFSET(pDevice, T3_NIC_DATA_SIG_ADDR);
1058 if (Value32 == T3_NIC_DATA_SIG)
1061 Value32 = MEM_RD_OFFSET(pDevice, T3_NIC_DATA_NIC_CFG_ADDR);
1063 /* Determine PHY type. */
1064 switch (Value32 & T3_NIC_CFG_PHY_TYPE_MASK)
1066 case T3_NIC_CFG_PHY_TYPE_COPPER:
1067 EePhyTypeSerdes = FALSE;
1070 case T3_NIC_CFG_PHY_TYPE_FIBER:
1071 EePhyTypeSerdes = TRUE;
1075 EePhyTypeSerdes = FALSE;
1079 /* Determine PHY led mode. */
1080 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1081 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
1083 switch(Value32 & T3_NIC_CFG_LED_MODE_MASK)
1085 case T3_NIC_CFG_LED_MODE_TRIPLE_SPEED:
1086 EePhyLedMode = LED_MODE_THREE_LINK;
1089 case T3_NIC_CFG_LED_MODE_LINK_SPEED:
1090 EePhyLedMode = LED_MODE_LINK10;
1094 EePhyLedMode = LED_MODE_AUTO;
1100 switch(Value32 & T3_NIC_CFG_LED_MODE_MASK)
1102 case T3_NIC_CFG_LED_MODE_OPEN_DRAIN:
1103 EePhyLedMode = LED_MODE_OPEN_DRAIN;
1106 case T3_NIC_CFG_LED_MODE_OUTPUT:
1107 EePhyLedMode = LED_MODE_OUTPUT;
1111 EePhyLedMode = LED_MODE_AUTO;
1115 if(pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1116 pDevice->ChipRevId == T3_CHIP_ID_5703_A2)
1118 /* Enable EEPROM write protection. */
1119 if(Value32 & T3_NIC_EEPROM_WP)
1121 pDevice->EepromWp = TRUE;
1125 /* Get the PHY Id. */
1126 Value32 = MEM_RD_OFFSET(pDevice, T3_NIC_DATA_PHY_ID_ADDR);
1129 EePhyId = (((Value32 & T3_NIC_PHY_ID1_MASK) >> 16) &
1130 PHY_ID1_OUI_MASK) << 10;
1132 Value32 = Value32 & T3_NIC_PHY_ID2_MASK;
1134 EePhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1135 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 & PHY_ID2_REV_MASK);
1147 /* Set the PHY address. */
1148 pDevice->PhyAddr = PHY_DEVICE_ID;
1150 /* Disable auto polling. */
1151 pDevice->MiMode = 0xc0000;
1152 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
1155 /* Get the PHY id. */
1156 LM_ReadPhy(pDevice, PHY_ID1_REG, &Value32);
1157 pDevice->PhyId = (Value32 & PHY_ID1_OUI_MASK) << 10;
1159 LM_ReadPhy(pDevice, PHY_ID2_REG, &Value32);
1160 pDevice->PhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1161 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 & PHY_ID2_REV_MASK);
1163 /* Set the EnableTbi flag to false if we have a copper PHY. */
1164 switch(pDevice->PhyId & PHY_ID_MASK)
1166 case PHY_BCM5400_PHY_ID:
1167 pDevice->EnableTbi = FALSE;
1170 case PHY_BCM5401_PHY_ID:
1171 pDevice->EnableTbi = FALSE;
1174 case PHY_BCM5411_PHY_ID:
1175 pDevice->EnableTbi = FALSE;
1178 case PHY_BCM5701_PHY_ID:
1179 pDevice->EnableTbi = FALSE;
1182 case PHY_BCM5703_PHY_ID:
1183 pDevice->EnableTbi = FALSE;
1186 case PHY_BCM5704_PHY_ID:
1187 pDevice->EnableTbi = FALSE;
1190 case PHY_BCM8002_PHY_ID:
1191 pDevice->EnableTbi = TRUE;
1198 pDevice->PhyId = pAdapterInfo->PhyId;
1199 pDevice->EnableTbi = pAdapterInfo->Serdes;
1201 else if (EeSigFound)
1203 pDevice->PhyId = EePhyId;
1204 pDevice->EnableTbi = EePhyTypeSerdes;
1209 /* Bail out if we don't know the copper PHY id. */
1210 if(UNKNOWN_PHY_ID(pDevice->PhyId) && !pDevice->EnableTbi)
1212 return LM_STATUS_FAILURE;
1215 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703)
1217 if((pDevice->SavedCacheLineReg & 0xff00) < 0x4000)
1219 pDevice->SavedCacheLineReg &= 0xffff00ff;
1220 pDevice->SavedCacheLineReg |= 0x4000;
1223 /* Change driver parameters. */
1224 Status = MM_GetConfig(pDevice);
1225 if(Status != LM_STATUS_SUCCESS)
1230 #if INCLUDE_5701_AX_FIX
1231 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1232 pDevice->ChipRevId == T3_CHIP_ID_5701_B0)
1234 pDevice->ResetPhyOnInit = TRUE;
1238 /* Save the current phy link status. */
1239 if(!pDevice->EnableTbi)
1241 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
1242 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
1244 /* If we don't have link reset the PHY. */
1245 if(!(Value32 & PHY_STATUS_LINK_PASS) || pDevice->ResetPhyOnInit)
1248 LM_WritePhy(pDevice, PHY_CTRL_REG, PHY_CTRL_PHY_RESET);
1250 for(j = 0; j < 100; j++)
1254 LM_ReadPhy(pDevice, PHY_CTRL_REG, &Value32);
1255 if(Value32 && !(Value32 & PHY_CTRL_PHY_RESET))
1263 #if INCLUDE_5701_AX_FIX
1264 /* 5701_AX_BX bug: only advertises 10mb speed. */
1265 if(pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1266 pDevice->ChipRevId == T3_CHIP_ID_5701_B0)
1269 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
1270 PHY_AN_AD_10BASET_HALF | PHY_AN_AD_10BASET_FULL |
1271 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
1272 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
1273 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
1274 pDevice->advertising = Value32;
1276 Value32 = BCM540X_AN_AD_1000BASET_HALF |
1277 BCM540X_AN_AD_1000BASET_FULL | BCM540X_CONFIG_AS_MASTER |
1278 BCM540X_ENABLE_CONFIG_AS_MASTER;
1279 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, Value32);
1280 pDevice->advertising1000 = Value32;
1282 LM_WritePhy(pDevice, PHY_CTRL_REG, PHY_CTRL_AUTO_NEG_ENABLE |
1283 PHY_CTRL_RESTART_AUTO_NEG);
1286 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703)
1288 LM_WritePhy(pDevice, 0x18, 0x0c00);
1289 LM_WritePhy(pDevice, 0x17, 0x201f);
1290 LM_WritePhy(pDevice, 0x15, 0x2aaa);
1292 if(pDevice->ChipRevId == T3_CHIP_ID_5704_A0)
1294 LM_WritePhy(pDevice, 0x1c, 0x8d68);
1295 LM_WritePhy(pDevice, 0x1c, 0x8d68);
1297 /* Enable Ethernet@WireSpeed. */
1298 if(pDevice->EnableWireSpeed)
1300 LM_WritePhy(pDevice, 0x18, 0x7007);
1301 LM_ReadPhy(pDevice, 0x18, &Value32);
1302 LM_WritePhy(pDevice, 0x18, Value32 | BIT_15 | BIT_4);
1307 /* Turn off tap power management. */
1308 if((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
1310 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x0c20);
1311 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
1312 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1804);
1313 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
1314 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1204);
1315 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1316 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0132);
1317 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1318 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0232);
1319 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
1320 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
1325 #if INCLUDE_TBI_SUPPORT
1326 pDevice->IgnoreTbiLinkChange = FALSE;
1328 if(pDevice->EnableTbi)
1330 pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_NONE;
1331 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
1332 if ((pDevice->PollTbiLink == BAD_DEFAULT_VALUE) ||
1333 pDevice->DisableAutoNeg)
1335 pDevice->PollTbiLink = FALSE;
1340 pDevice->PollTbiLink = FALSE;
1342 #endif /* INCLUDE_TBI_SUPPORT */
1344 /* UseTaggedStatus is only valid for 5701 and later. */
1345 if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
1347 pDevice->UseTaggedStatus = FALSE;
1349 pDevice->CoalesceMode = 0;
1353 pDevice->CoalesceMode = HOST_COALESCE_CLEAR_TICKS_ON_RX_BD_EVENT |
1354 HOST_COALESCE_CLEAR_TICKS_ON_TX_BD_EVENT;
1357 /* Set the status block size. */
1358 if(T3_CHIP_REV(pDevice->ChipRevId) != T3_CHIP_REV_5700_AX &&
1359 T3_CHIP_REV(pDevice->ChipRevId) != T3_CHIP_REV_5700_BX)
1361 pDevice->CoalesceMode |= HOST_COALESCE_32_BYTE_STATUS_MODE;
1364 /* Check the DURING_INT coalescing ticks parameters. */
1365 if(pDevice->UseTaggedStatus)
1367 if(pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE)
1369 pDevice->RxCoalescingTicksDuringInt =
1370 DEFAULT_RX_COALESCING_TICKS_DURING_INT;
1373 if(pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE)
1375 pDevice->TxCoalescingTicksDuringInt =
1376 DEFAULT_TX_COALESCING_TICKS_DURING_INT;
1379 if(pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE)
1381 pDevice->RxMaxCoalescedFramesDuringInt =
1382 DEFAULT_RX_MAX_COALESCED_FRAMES_DURING_INT;
1385 if(pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE)
1387 pDevice->TxMaxCoalescedFramesDuringInt =
1388 DEFAULT_TX_MAX_COALESCED_FRAMES_DURING_INT;
1393 if(pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE)
1395 pDevice->RxCoalescingTicksDuringInt = 0;
1398 if(pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE)
1400 pDevice->TxCoalescingTicksDuringInt = 0;
1403 if(pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE)
1405 pDevice->RxMaxCoalescedFramesDuringInt = 0;
1408 if(pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE)
1410 pDevice->TxMaxCoalescedFramesDuringInt = 0;
1414 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1415 if(pDevice->RxMtu <= (MAX_STD_RCV_BUFFER_SIZE - 8 /* CRC */))
1417 pDevice->RxJumboDescCnt = 0;
1418 if(pDevice->RxMtu <= MAX_ETHERNET_PACKET_SIZE_NO_CRC)
1420 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1425 pDevice->RxJumboBufferSize = (pDevice->RxMtu + 8 /* CRC + VLAN */ +
1426 COMMON_CACHE_LINE_SIZE-1) & ~COMMON_CACHE_LINE_MASK;
1428 if(pDevice->RxJumboBufferSize > MAX_JUMBO_RCV_BUFFER_SIZE)
1430 pDevice->RxJumboBufferSize = DEFAULT_JUMBO_RCV_BUFFER_SIZE;
1431 pDevice->RxMtu = pDevice->RxJumboBufferSize - 8 /* CRC + VLAN */;
1433 pDevice->TxMtu = pDevice->RxMtu;
1437 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1438 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1440 pDevice->RxPacketDescCnt =
1441 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1442 pDevice->RxJumboDescCnt +
1443 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1444 pDevice->RxStdDescCnt;
1446 if(pDevice->TxMtu < MAX_ETHERNET_PACKET_SIZE_NO_CRC)
1448 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1451 if(pDevice->TxMtu > MAX_JUMBO_TX_BUFFER_SIZE)
1453 pDevice->TxMtu = MAX_JUMBO_TX_BUFFER_SIZE;
1456 /* Configure the proper ways to get link change interrupt. */
1457 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO)
1459 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
1461 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1465 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
1468 else if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
1470 /* Auto-polling does not work on 5700_AX and 5700_BX. */
1471 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
1473 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1477 /* Determine the method to get link change status. */
1478 if(pDevice->LinkChngMode == T3_LINK_CHNG_MODE_AUTO)
1480 /* The link status bit in the status block does not work on 5700_AX */
1481 /* and 5700_BX chips. */
1482 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
1484 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_REG;
1488 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_BLOCK;
1492 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT ||
1493 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
1495 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_REG;
1498 /* Configure PHY led mode. */
1499 if(pDevice->LedMode == LED_MODE_AUTO)
1501 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1502 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
1504 if(pDevice->SubsystemVendorId == T3_SVID_DELL)
1506 pDevice->LedMode = LED_MODE_LINK10;
1510 pDevice->LedMode = LED_MODE_THREE_LINK;
1512 if(EeSigFound && EePhyLedMode != LED_MODE_AUTO)
1514 pDevice->LedMode = EePhyLedMode;
1518 /* bug? 5701 in LINK10 mode does not seem to work when */
1519 /* PhyIntMode is LINK_READY. */
1520 if(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
1521 #if INCLUDE_TBI_SUPPORT
1522 pDevice->EnableTbi == FALSE &&
1524 pDevice->LedMode == LED_MODE_LINK10)
1526 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1527 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_REG;
1530 if(pDevice->EnableTbi)
1532 pDevice->LedMode = LED_MODE_THREE_LINK;
1537 if(EeSigFound && EePhyLedMode != LED_MODE_AUTO)
1539 pDevice->LedMode = EePhyLedMode;
1543 pDevice->LedMode = LED_MODE_OPEN_DRAIN;
1548 /* Enable OneDmaAtOnce. */
1549 if(pDevice->OneDmaAtOnce == BAD_DEFAULT_VALUE)
1551 pDevice->OneDmaAtOnce = FALSE;
1554 if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1555 pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1556 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
1557 pDevice->ChipRevId == T3_CHIP_ID_5701_B2)
1559 pDevice->WolSpeed = WOL_SPEED_10MB;
1563 pDevice->WolSpeed = WOL_SPEED_100MB;
1567 pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
1569 /* Turn off task offloading on Ax. */
1570 if(pDevice->ChipRevId == T3_CHIP_ID_5700_B0)
1572 pDevice->TaskOffloadCap &= ~(LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
1573 LM_TASK_OFFLOAD_TX_UDP_CHECKSUM);
1575 pDevice->PciState = REG_RD(pDevice, PciCfg.PciState);
1576 LM_ReadVPD(pDevice);
1577 LM_ReadBootCodeVersion(pDevice);
1578 LM_GetBusSpeed(pDevice);
1580 return LM_STATUS_SUCCESS;
1581 } /* LM_GetAdapterInfo */
1583 STATIC PLM_ADAPTER_INFO
1584 LM_GetAdapterInfoBySsid(
1588 static LM_ADAPTER_INFO AdapterArr[] =
1590 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A6, PHY_BCM5401_PHY_ID, 0},
1591 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A5, PHY_BCM5701_PHY_ID, 0},
1592 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700T6, PHY_BCM8002_PHY_ID, 1},
1593 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A9, 0, 1 },
1594 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T1, PHY_BCM5701_PHY_ID, 0},
1595 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T8, PHY_BCM5701_PHY_ID, 0},
1596 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A7, 0, 1},
1597 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A10, PHY_BCM5701_PHY_ID, 0},
1598 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A12, PHY_BCM5701_PHY_ID, 0},
1599 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax1, PHY_BCM5701_PHY_ID, 0},
1600 { T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax2, PHY_BCM5701_PHY_ID, 0},
1602 { T3_SVID_3COM, T3_SSID_3COM_3C996T, PHY_BCM5401_PHY_ID, 0 },
1603 { T3_SVID_3COM, T3_SSID_3COM_3C996BT, PHY_BCM5701_PHY_ID, 0 },
1604 { T3_SVID_3COM, T3_SSID_3COM_3C996SX, 0, 1 },
1605 { T3_SVID_3COM, T3_SSID_3COM_3C1000T, PHY_BCM5701_PHY_ID, 0 },
1606 { T3_SVID_3COM, T3_SSID_3COM_3C940BR01, PHY_BCM5701_PHY_ID, 0 },
1608 { T3_SVID_DELL, T3_SSID_DELL_VIPER, PHY_BCM5401_PHY_ID, 0 },
1609 { T3_SVID_DELL, T3_SSID_DELL_JAGUAR, PHY_BCM5401_PHY_ID, 0 },
1610 { T3_SVID_DELL, T3_SSID_DELL_MERLOT, PHY_BCM5411_PHY_ID, 0 },
1611 { T3_SVID_DELL, T3_SSID_DELL_SLIM_MERLOT, PHY_BCM5411_PHY_ID, 0 },
1613 { T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE, PHY_BCM5701_PHY_ID, 0 },
1614 { T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE_2, PHY_BCM5701_PHY_ID, 0 },
1615 { T3_SVID_COMPAQ, T3_SSID_COMPAQ_CHANGELING, 0, 1 },
1616 { T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780, PHY_BCM5701_PHY_ID, 0 },
1617 { T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780_2, PHY_BCM5701_PHY_ID, 0 },
1622 for(j = 0; j < sizeof(AdapterArr)/sizeof(LM_ADAPTER_INFO); j++)
1624 if(AdapterArr[j].Svid == Svid && AdapterArr[j].Ssid == Ssid)
1626 return &AdapterArr[j];
1634 /******************************************************************************/
1636 /* This routine sets up receive/transmit buffer descriptions queues. */
1639 /* LM_STATUS_SUCCESS */
1640 /******************************************************************************/
1642 LM_InitializeAdapter(
1643 PLM_DEVICE_BLOCK pDevice)
1645 LM_PHYSICAL_ADDRESS MemPhy;
1652 /* Set power state to D0. */
1653 LM_SetPowerState(pDevice, LM_POWER_STATE_D0);
1655 /* Intialize the queues. */
1656 QQ_InitQueue(&pDevice->RxPacketReceivedQ.Container,
1657 MAX_RX_PACKET_DESC_COUNT);
1658 QQ_InitQueue(&pDevice->RxPacketFreeQ.Container,
1659 MAX_RX_PACKET_DESC_COUNT);
1661 QQ_InitQueue(&pDevice->TxPacketFreeQ.Container,MAX_TX_PACKET_DESC_COUNT);
1662 QQ_InitQueue(&pDevice->TxPacketActiveQ.Container,MAX_TX_PACKET_DESC_COUNT);
1663 QQ_InitQueue(&pDevice->TxPacketXmittedQ.Container,MAX_TX_PACKET_DESC_COUNT);
1665 /* Allocate shared memory for: status block, the buffers for receive */
1666 /* rings -- standard, mini, jumbo, and return rings. */
1667 Size = T3_STATUS_BLOCK_SIZE + sizeof(T3_STATS_BLOCK) +
1668 T3_STD_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD) +
1669 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1670 T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD) +
1671 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1672 T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD);
1674 /* Memory for host based Send BD. */
1675 if(pDevice->NicSendBd == FALSE)
1677 Size += sizeof(T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
1680 /* Allocate the memory block. */
1681 Status = MM_AllocateSharedMemory(pDevice, Size, (PLM_VOID) &pMemVirt, &MemPhy, FALSE);
1682 if(Status != LM_STATUS_SUCCESS)
1687 /* Program DMA Read/Write */
1688 if (pDevice->PciState & T3_PCI_STATE_NOT_PCI_X_BUS)
1690 pDevice->DmaReadWriteCtrl = 0x763f000f;
1694 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5704)
1696 pDevice->DmaReadWriteCtrl = 0x761f0000;
1700 pDevice->DmaReadWriteCtrl = 0x761b000f;
1702 if(pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1703 pDevice->ChipRevId == T3_CHIP_ID_5703_A2)
1705 pDevice->OneDmaAtOnce = TRUE;
1708 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5703)
1710 pDevice->DmaReadWriteCtrl &= 0xfffffff0;
1713 if(pDevice->OneDmaAtOnce)
1715 pDevice->DmaReadWriteCtrl |= DMA_CTRL_WRITE_ONE_DMA_AT_ONCE;
1717 REG_WR(pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
1719 if (LM_DmaTest(pDevice, pMemVirt, MemPhy, 0x400) != LM_STATUS_SUCCESS)
1721 return LM_STATUS_FAILURE;
1725 pDevice->pStatusBlkVirt = (PT3_STATUS_BLOCK) pMemVirt;
1726 pDevice->StatusBlkPhy = MemPhy;
1727 pMemVirt += T3_STATUS_BLOCK_SIZE;
1728 LM_INC_PHYSICAL_ADDRESS(&MemPhy, T3_STATUS_BLOCK_SIZE);
1730 /* Statistics block. */
1731 pDevice->pStatsBlkVirt = (PT3_STATS_BLOCK) pMemVirt;
1732 pDevice->StatsBlkPhy = MemPhy;
1733 pMemVirt += sizeof(T3_STATS_BLOCK);
1734 LM_INC_PHYSICAL_ADDRESS(&MemPhy, sizeof(T3_STATS_BLOCK));
1736 /* Receive standard BD buffer. */
1737 pDevice->pRxStdBdVirt = (PT3_RCV_BD) pMemVirt;
1738 pDevice->RxStdBdPhy = MemPhy;
1740 pMemVirt += T3_STD_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD);
1741 LM_INC_PHYSICAL_ADDRESS(&MemPhy,
1742 T3_STD_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD));
1744 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1745 /* Receive jumbo BD buffer. */
1746 pDevice->pRxJumboBdVirt = (PT3_RCV_BD) pMemVirt;
1747 pDevice->RxJumboBdPhy = MemPhy;
1749 pMemVirt += T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD);
1750 LM_INC_PHYSICAL_ADDRESS(&MemPhy,
1751 T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD));
1752 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1754 /* Receive return BD buffer. */
1755 pDevice->pRcvRetBdVirt = (PT3_RCV_BD) pMemVirt;
1756 pDevice->RcvRetBdPhy = MemPhy;
1758 pMemVirt += T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD);
1759 LM_INC_PHYSICAL_ADDRESS(&MemPhy,
1760 T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof(T3_RCV_BD));
1762 /* Set up Send BD. */
1763 if(pDevice->NicSendBd == FALSE)
1765 pDevice->pSendBdVirt = (PT3_SND_BD) pMemVirt;
1766 pDevice->SendBdPhy = MemPhy;
1768 pMemVirt += sizeof(T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
1769 LM_INC_PHYSICAL_ADDRESS(&MemPhy,
1770 sizeof(T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT);
1774 pDevice->pSendBdVirt = (PT3_SND_BD)
1775 pDevice->pMemView->uIntMem.First32k.BufferDesc;
1776 pDevice->SendBdPhy.High = 0;
1777 pDevice->SendBdPhy.Low = T3_NIC_SND_BUFFER_DESC_ADDR;
1780 /* Allocate memory for packet descriptors. */
1781 Size = (pDevice->RxPacketDescCnt +
1782 pDevice->TxPacketDescCnt) * MM_PACKET_DESC_SIZE;
1783 Status = MM_AllocateMemory(pDevice, Size, (PLM_VOID *) &pPacket);
1784 if(Status != LM_STATUS_SUCCESS)
1788 pDevice->pPacketDescBase = (PLM_VOID) pPacket;
1790 /* Create transmit packet descriptors from the memory block and add them */
1791 /* to the TxPacketFreeQ for each send ring. */
1792 for(j = 0; j < pDevice->TxPacketDescCnt; j++)
1797 /* Queue the descriptor in the TxPacketFreeQ of the 'k' ring. */
1798 QQ_PushTail(&pDevice->TxPacketFreeQ.Container, pPacket);
1800 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1801 /* is the total size of the packet descriptor including the */
1802 /* os-specific extensions in the UM_PACKET structure. */
1803 pPacket = (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1806 /* Create receive packet descriptors from the memory block and add them */
1807 /* to the RxPacketFreeQ. Create the Standard packet descriptors. */
1808 for(j = 0; j < pDevice->RxStdDescCnt; j++)
1810 /* Receive producer ring. */
1811 pPacket->u.Rx.RcvProdRing = T3_STD_RCV_PROD_RING;
1813 /* Receive buffer size. */
1814 pPacket->u.Rx.RxBufferSize = MAX_STD_RCV_BUFFER_SIZE;
1816 /* Add the descriptor to RxPacketFreeQ. */
1817 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
1819 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1820 /* is the total size of the packet descriptor including the */
1821 /* os-specific extensions in the UM_PACKET structure. */
1822 pPacket = (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1825 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
1826 /* Create the Jumbo packet descriptors. */
1827 for(j = 0; j < pDevice->RxJumboDescCnt; j++)
1829 /* Receive producer ring. */
1830 pPacket->u.Rx.RcvProdRing = T3_JUMBO_RCV_PROD_RING;
1832 /* Receive buffer size. */
1833 pPacket->u.Rx.RxBufferSize = pDevice->RxJumboBufferSize;
1835 /* Add the descriptor to RxPacketFreeQ. */
1836 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
1838 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1839 /* is the total size of the packet descriptor including the */
1840 /* os-specific extensions in the UM_PACKET structure. */
1841 pPacket = (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1843 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1845 /* Initialize the rest of the packet descriptors. */
1846 Status = MM_InitializeUmPackets(pDevice);
1847 if(Status != LM_STATUS_SUCCESS)
1852 /* Default receive mask. */
1853 pDevice->ReceiveMask = LM_ACCEPT_MULTICAST | LM_ACCEPT_BROADCAST |
1856 /* Make sure we are in the first 32k memory window or NicSendBd. */
1857 REG_WR(pDevice, PciCfg.MemWindowBaseAddr, 0);
1859 /* Initialize the hardware. */
1860 Status = LM_ResetAdapter(pDevice);
1861 if(Status != LM_STATUS_SUCCESS)
1866 /* We are done with initialization. */
1867 pDevice->InitDone = TRUE;
1869 return LM_STATUS_SUCCESS;
1870 } /* LM_InitializeAdapter */
1873 /******************************************************************************/
1875 /* This function Enables/Disables a given block. */
1878 /* LM_STATUS_SUCCESS */
1879 /******************************************************************************/
1882 PLM_DEVICE_BLOCK pDevice,
1883 LM_UINT32 mask,LM_UINT32 cntrl)
1886 LM_UINT32 MaxWaitCnt;
1891 for(i = 0 ; i < 32; i++)
1893 if(!(mask & (1 << i)))
1898 case T3_BLOCK_DMA_RD:
1899 data = REG_RD(pDevice, DmaRead.Mode);
1900 if (cntrl == LM_DISABLE)
1902 data &= ~DMA_READ_MODE_ENABLE;
1903 REG_WR(pDevice, DmaRead.Mode, data);
1904 for(j = 0; j < MaxWaitCnt; j++)
1906 if(!(REG_RD(pDevice, DmaRead.Mode) & DMA_READ_MODE_ENABLE))
1912 REG_WR(pDevice, DmaRead.Mode, data | DMA_READ_MODE_ENABLE);
1915 case T3_BLOCK_DMA_COMP:
1916 data = REG_RD(pDevice,DmaComp.Mode);
1917 if (cntrl == LM_DISABLE)
1919 data &= ~DMA_COMP_MODE_ENABLE;
1920 REG_WR(pDevice, DmaComp.Mode, data);
1921 for(j = 0; j < MaxWaitCnt; j++)
1923 if(!(REG_RD(pDevice, DmaComp.Mode) & DMA_COMP_MODE_ENABLE))
1929 REG_WR(pDevice, DmaComp.Mode, data | DMA_COMP_MODE_ENABLE);
1932 case T3_BLOCK_RX_BD_INITIATOR:
1933 data = REG_RD(pDevice, RcvBdIn.Mode);
1934 if (cntrl == LM_DISABLE)
1936 data &= ~RCV_BD_IN_MODE_ENABLE;
1937 REG_WR(pDevice, RcvBdIn.Mode,data);
1938 for(j = 0; j < MaxWaitCnt; j++)
1940 if(!(REG_RD(pDevice, RcvBdIn.Mode) & RCV_BD_IN_MODE_ENABLE))
1946 REG_WR(pDevice, RcvBdIn.Mode,data | RCV_BD_IN_MODE_ENABLE);
1949 case T3_BLOCK_RX_BD_COMP:
1950 data = REG_RD(pDevice, RcvBdComp.Mode);
1951 if (cntrl == LM_DISABLE)
1953 data &= ~RCV_BD_COMP_MODE_ENABLE;
1954 REG_WR(pDevice, RcvBdComp.Mode,data);
1955 for(j = 0; j < MaxWaitCnt; j++)
1957 if(!(REG_RD(pDevice, RcvBdComp.Mode) & RCV_BD_COMP_MODE_ENABLE))
1963 REG_WR(pDevice, RcvBdComp.Mode,data | RCV_BD_COMP_MODE_ENABLE);
1966 case T3_BLOCK_DMA_WR:
1967 data = REG_RD(pDevice, DmaWrite.Mode);
1968 if (cntrl == LM_DISABLE)
1970 data &= ~DMA_WRITE_MODE_ENABLE;
1971 REG_WR(pDevice, DmaWrite.Mode,data);
1973 for(j = 0; j < MaxWaitCnt; j++)
1975 if(!(REG_RD(pDevice, DmaWrite.Mode) & DMA_WRITE_MODE_ENABLE))
1981 REG_WR(pDevice, DmaWrite.Mode,data | DMA_WRITE_MODE_ENABLE);
1984 case T3_BLOCK_MSI_HANDLER:
1985 data = REG_RD(pDevice, Msi.Mode);
1986 if (cntrl == LM_DISABLE)
1988 data &= ~MSI_MODE_ENABLE;
1989 REG_WR(pDevice, Msi.Mode, data);
1990 for(j = 0; j < MaxWaitCnt; j++)
1992 if(!(REG_RD(pDevice, Msi.Mode) & MSI_MODE_ENABLE))
1998 REG_WR(pDevice, Msi.Mode, data |MSI_MODE_ENABLE);
2001 case T3_BLOCK_RX_LIST_PLMT:
2002 data = REG_RD(pDevice, RcvListPlmt.Mode);
2003 if (cntrl == LM_DISABLE)
2005 data &= ~RCV_LIST_PLMT_MODE_ENABLE;
2006 REG_WR(pDevice, RcvListPlmt.Mode,data);
2007 for(j = 0; j < MaxWaitCnt; j++)
2009 if(!(REG_RD(pDevice, RcvListPlmt.Mode) & RCV_LIST_PLMT_MODE_ENABLE))
2015 REG_WR(pDevice, RcvListPlmt.Mode,data | RCV_LIST_PLMT_MODE_ENABLE);
2018 case T3_BLOCK_RX_LIST_SELECTOR:
2019 data = REG_RD(pDevice, RcvListSel.Mode);
2020 if (cntrl == LM_DISABLE)
2022 data &= ~RCV_LIST_SEL_MODE_ENABLE;
2023 REG_WR(pDevice, RcvListSel.Mode,data);
2024 for(j = 0; j < MaxWaitCnt; j++)
2026 if(!(REG_RD(pDevice, RcvListSel.Mode) & RCV_LIST_SEL_MODE_ENABLE))
2032 REG_WR(pDevice, RcvListSel.Mode,data |RCV_LIST_SEL_MODE_ENABLE);
2035 case T3_BLOCK_RX_DATA_INITIATOR:
2036 data = REG_RD(pDevice, RcvDataBdIn.Mode);
2037 if (cntrl == LM_DISABLE)
2039 data &= ~RCV_DATA_BD_IN_MODE_ENABLE;
2040 REG_WR(pDevice, RcvDataBdIn.Mode,data);
2041 for(j = 0; j < MaxWaitCnt; j++)
2043 if(!(REG_RD(pDevice, RcvDataBdIn.Mode) & RCV_DATA_BD_IN_MODE_ENABLE))
2049 REG_WR(pDevice, RcvDataBdIn.Mode, data | RCV_DATA_BD_IN_MODE_ENABLE);
2052 case T3_BLOCK_RX_DATA_COMP:
2053 data = REG_RD(pDevice, RcvDataComp.Mode);
2054 if (cntrl == LM_DISABLE)
2056 data &= ~RCV_DATA_COMP_MODE_ENABLE;
2057 REG_WR(pDevice, RcvDataComp.Mode,data);
2058 for(j = 0; j < MaxWaitCnt; j++)
2060 if(!(REG_RD(pDevice, RcvDataBdIn.Mode) & RCV_DATA_COMP_MODE_ENABLE))
2066 REG_WR(pDevice, RcvDataComp.Mode,data | RCV_DATA_COMP_MODE_ENABLE);
2069 case T3_BLOCK_HOST_COALESING:
2070 data = REG_RD(pDevice, HostCoalesce.Mode);
2071 if (cntrl == LM_DISABLE)
2073 data &= ~HOST_COALESCE_ENABLE;
2074 REG_WR(pDevice, HostCoalesce.Mode, data);
2075 for(j = 0; j < MaxWaitCnt; j++)
2077 if(!(REG_RD(pDevice, SndBdIn.Mode) & HOST_COALESCE_ENABLE))
2083 REG_WR(pDevice, HostCoalesce.Mode, data | HOST_COALESCE_ENABLE);
2086 case T3_BLOCK_MAC_RX_ENGINE:
2087 if(cntrl == LM_DISABLE)
2089 pDevice->RxMode &= ~RX_MODE_ENABLE;
2090 REG_WR(pDevice, MacCtrl.RxMode, pDevice->RxMode);
2091 for(j = 0; j < MaxWaitCnt; j++)
2093 if(!(REG_RD(pDevice, MacCtrl.RxMode) & RX_MODE_ENABLE))
2102 pDevice->RxMode |= RX_MODE_ENABLE;
2103 REG_WR(pDevice, MacCtrl.RxMode, pDevice->RxMode);
2107 case T3_BLOCK_MBUF_CLUSTER_FREE:
2108 data = REG_RD(pDevice, MbufClusterFree.Mode);
2109 if (cntrl == LM_DISABLE)
2111 data &= ~MBUF_CLUSTER_FREE_MODE_ENABLE;
2112 REG_WR(pDevice, MbufClusterFree.Mode,data);
2113 for(j = 0; j < MaxWaitCnt; j++)
2115 if(!(REG_RD(pDevice, MbufClusterFree.Mode) & MBUF_CLUSTER_FREE_MODE_ENABLE))
2121 REG_WR(pDevice, MbufClusterFree.Mode, data | MBUF_CLUSTER_FREE_MODE_ENABLE);
2124 case T3_BLOCK_SEND_BD_INITIATOR:
2125 data = REG_RD(pDevice, SndBdIn.Mode);
2126 if (cntrl == LM_DISABLE)
2128 data &= ~SND_BD_IN_MODE_ENABLE;
2129 REG_WR(pDevice, SndBdIn.Mode, data);
2130 for(j = 0; j < MaxWaitCnt; j++)
2132 if(!(REG_RD(pDevice, SndBdIn.Mode) & SND_BD_IN_MODE_ENABLE))
2138 REG_WR(pDevice, SndBdIn.Mode, data | SND_BD_IN_MODE_ENABLE);
2141 case T3_BLOCK_SEND_BD_COMP:
2142 data = REG_RD(pDevice, SndBdComp.Mode);
2143 if (cntrl == LM_DISABLE)
2145 data &= ~SND_BD_COMP_MODE_ENABLE;
2146 REG_WR(pDevice, SndBdComp.Mode, data);
2147 for(j = 0; j < MaxWaitCnt; j++)
2149 if(!(REG_RD(pDevice, SndBdComp.Mode) & SND_BD_COMP_MODE_ENABLE))
2155 REG_WR(pDevice, SndBdComp.Mode, data | SND_BD_COMP_MODE_ENABLE);
2158 case T3_BLOCK_SEND_BD_SELECTOR:
2159 data = REG_RD(pDevice, SndBdSel.Mode);
2160 if (cntrl == LM_DISABLE)
2162 data &= ~SND_BD_SEL_MODE_ENABLE;
2163 REG_WR(pDevice, SndBdSel.Mode, data);
2164 for(j = 0; j < MaxWaitCnt; j++)
2166 if(!(REG_RD(pDevice, SndBdSel.Mode) & SND_BD_SEL_MODE_ENABLE))
2172 REG_WR(pDevice, SndBdSel.Mode, data | SND_BD_SEL_MODE_ENABLE);
2175 case T3_BLOCK_SEND_DATA_INITIATOR:
2176 data = REG_RD(pDevice, SndDataIn.Mode);
2177 if (cntrl == LM_DISABLE)
2179 data &= ~T3_SND_DATA_IN_MODE_ENABLE;
2180 REG_WR(pDevice, SndDataIn.Mode,data);
2181 for(j = 0; j < MaxWaitCnt; j++)
2183 if(!(REG_RD(pDevice, SndDataIn.Mode) & T3_SND_DATA_IN_MODE_ENABLE))
2189 REG_WR(pDevice, SndDataIn.Mode,data | T3_SND_DATA_IN_MODE_ENABLE);
2192 case T3_BLOCK_SEND_DATA_COMP:
2193 data = REG_RD(pDevice, SndDataComp.Mode);
2194 if (cntrl == LM_DISABLE)
2196 data &= ~SND_DATA_COMP_MODE_ENABLE;
2197 REG_WR(pDevice, SndDataComp.Mode, data);
2198 for(j = 0; j < MaxWaitCnt; j++)
2200 if(!(REG_RD(pDevice, SndDataComp.Mode) & SND_DATA_COMP_MODE_ENABLE))
2206 REG_WR(pDevice, SndDataComp.Mode,data | SND_DATA_COMP_MODE_ENABLE);
2209 case T3_BLOCK_MAC_TX_ENGINE:
2210 if(cntrl == LM_DISABLE)
2212 pDevice->TxMode &= ~TX_MODE_ENABLE;
2213 REG_WR(pDevice, MacCtrl.TxMode, pDevice->TxMode);
2214 for(j = 0; j < MaxWaitCnt; j++)
2216 if(!(REG_RD(pDevice, MacCtrl.TxMode) & TX_MODE_ENABLE))
2223 pDevice->TxMode |= TX_MODE_ENABLE;
2224 REG_WR(pDevice, MacCtrl.TxMode, pDevice->TxMode);
2228 case T3_BLOCK_MEM_ARBITOR:
2229 data = REG_RD(pDevice, MemArbiter.Mode);
2230 if (cntrl == LM_DISABLE)
2232 data &= ~T3_MEM_ARBITER_MODE_ENABLE;
2233 REG_WR(pDevice, MemArbiter.Mode, data);
2234 for(j = 0; j < MaxWaitCnt; j++)
2236 if(!(REG_RD(pDevice, MemArbiter.Mode) & T3_MEM_ARBITER_MODE_ENABLE))
2242 REG_WR(pDevice, MemArbiter.Mode,data|T3_MEM_ARBITER_MODE_ENABLE);
2245 case T3_BLOCK_MBUF_MANAGER:
2246 data = REG_RD(pDevice, BufMgr.Mode);
2247 if (cntrl == LM_DISABLE)
2249 data &= ~BUFMGR_MODE_ENABLE;
2250 REG_WR(pDevice, BufMgr.Mode,data);
2251 for(j = 0; j < MaxWaitCnt; j++)
2253 if(!(REG_RD(pDevice, BufMgr.Mode) & BUFMGR_MODE_ENABLE))
2259 REG_WR(pDevice, BufMgr.Mode,data | BUFMGR_MODE_ENABLE);
2262 case T3_BLOCK_MAC_GLOBAL:
2263 if(cntrl == LM_DISABLE)
2265 pDevice->MacMode &= ~(MAC_MODE_ENABLE_TDE |
2266 MAC_MODE_ENABLE_RDE |
2267 MAC_MODE_ENABLE_FHDE);
2271 pDevice->MacMode |= (MAC_MODE_ENABLE_TDE |
2272 MAC_MODE_ENABLE_RDE |
2273 MAC_MODE_ENABLE_FHDE);
2275 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
2279 return LM_STATUS_FAILURE;
2284 return LM_STATUS_FAILURE;
2288 return LM_STATUS_SUCCESS;
2291 /******************************************************************************/
2293 /* This function reinitializes the adapter. */
2296 /* LM_STATUS_SUCCESS */
2297 /******************************************************************************/
2300 PLM_DEVICE_BLOCK pDevice)
2306 /* Disable interrupt. */
2307 LM_DisableInterrupt(pDevice);
2309 /* May get a spurious interrupt */
2310 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED;
2312 /* Disable transmit and receive DMA engines. Abort all pending requests. */
2313 if(pDevice->InitDone)
2318 pDevice->ShuttingDown = FALSE;
2320 LM_ResetChip(pDevice);
2322 /* Bug: Athlon fix for B3 silicon only. This bit does not do anything */
2323 /* in other chip revisions. */
2324 if(pDevice->DelayPciGrant)
2326 Value32 = REG_RD(pDevice, PciCfg.ClockCtrl);
2327 REG_WR(pDevice, PciCfg.ClockCtrl, Value32 | BIT_31);
2330 if(pDevice->ChipRevId == T3_CHIP_ID_5704_A0)
2332 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))
2334 Value32 = REG_RD(pDevice, PciCfg.PciState);
2335 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
2336 REG_WR(pDevice, PciCfg.PciState, Value32);
2340 /* Enable TaggedStatus mode. */
2341 if(pDevice->UseTaggedStatus)
2343 pDevice->MiscHostCtrl |= MISC_HOST_CTRL_ENABLE_TAGGED_STATUS_MODE;
2346 /* Restore PCI configuration registers. */
2347 MM_WriteConfig32(pDevice, PCI_CACHE_LINE_SIZE_REG,
2348 pDevice->SavedCacheLineReg);
2349 MM_WriteConfig32(pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
2350 (pDevice->SubsystemId << 16) | pDevice->SubsystemVendorId);
2352 /* Clear the statistics block. */
2353 for(j = 0x0300; j < 0x0b00; j++)
2355 MEM_WR_OFFSET(pDevice, j, 0);
2358 /* Initialize the statistis Block */
2359 pDevice->pStatusBlkVirt->Status = 0;
2360 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
2361 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
2362 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
2364 for(j = 0; j < 16; j++)
2366 pDevice->pStatusBlkVirt->Idx[j].RcvProdIdx = 0;
2367 pDevice->pStatusBlkVirt->Idx[j].SendConIdx = 0;
2370 for(k = 0; k < T3_STD_RCV_RCB_ENTRY_COUNT ;k++)
2372 pDevice->pRxStdBdVirt[k].HostAddr.High = 0;
2373 pDevice->pRxStdBdVirt[k].HostAddr.Low = 0;
2376 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2377 /* Receive jumbo BD buffer. */
2378 for(k = 0; k < T3_JUMBO_RCV_RCB_ENTRY_COUNT; k++)
2380 pDevice->pRxJumboBdVirt[k].HostAddr.High = 0;
2381 pDevice->pRxJumboBdVirt[k].HostAddr.Low = 0;
2385 REG_WR(pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
2387 /* GRC mode control register. */
2388 #ifdef BIG_ENDIAN_PCI /* Jimmy, this ifdef block deleted in new code! */
2390 GRC_MODE_WORD_SWAP_DATA |
2391 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2392 GRC_MODE_INT_ON_MAC_ATTN |
2393 GRC_MODE_HOST_STACK_UP;
2395 /* No CPU Swap modes for PCI IO */
2397 #ifdef BIG_ENDIAN_HOST
2398 GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
2399 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2400 GRC_MODE_BYTE_SWAP_DATA |
2401 GRC_MODE_WORD_SWAP_DATA |
2403 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2404 GRC_MODE_BYTE_SWAP_DATA |
2405 GRC_MODE_WORD_SWAP_DATA |
2407 GRC_MODE_INT_ON_MAC_ATTN |
2408 GRC_MODE_HOST_STACK_UP;
2409 #endif /* !BIG_ENDIAN_PCI */
2411 /* Configure send BD mode. */
2412 if(pDevice->NicSendBd == FALSE)
2414 Value32 |= GRC_MODE_HOST_SEND_BDS;
2418 Value32 |= GRC_MODE_4X_NIC_BASED_SEND_RINGS;
2421 /* Configure pseudo checksum mode. */
2422 if(pDevice->NoTxPseudoHdrChksum)
2424 Value32 |= GRC_MODE_TX_NO_PSEUDO_HEADER_CHKSUM;
2427 if(pDevice->NoRxPseudoHdrChksum)
2429 Value32 |= GRC_MODE_RX_NO_PSEUDO_HEADER_CHKSUM;
2432 REG_WR(pDevice, Grc.Mode, Value32);
2434 /* Setup the timer prescalar register. */
2435 REG_WR(pDevice, Grc.MiscCfg, 65 << 1); /* Clock is alwasy 66Mhz. */
2437 /* Set up the MBUF pool base address and size. */
2438 REG_WR(pDevice, BufMgr.MbufPoolAddr, pDevice->MbufBase);
2439 REG_WR(pDevice, BufMgr.MbufPoolSize, pDevice->MbufSize);
2441 /* Set up the DMA descriptor pool base address and size. */
2442 REG_WR(pDevice, BufMgr.DmaDescPoolAddr, T3_NIC_DMA_DESC_POOL_ADDR);
2443 REG_WR(pDevice, BufMgr.DmaDescPoolSize, T3_NIC_DMA_DESC_POOL_SIZE);
2445 /* Configure MBUF and Threshold watermarks */
2446 /* Configure the DMA read MBUF low water mark. */
2447 if(pDevice->DmaMbufLowMark)
2449 REG_WR(pDevice, BufMgr.MbufReadDmaLowWaterMark,
2450 pDevice->DmaMbufLowMark);
2454 if(pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE)
2456 REG_WR(pDevice, BufMgr.MbufReadDmaLowWaterMark,
2457 T3_DEF_DMA_MBUF_LOW_WMARK);
2461 REG_WR(pDevice, BufMgr.MbufReadDmaLowWaterMark,
2462 T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO);
2466 /* Configure the MAC Rx MBUF low water mark. */
2467 if(pDevice->RxMacMbufLowMark)
2469 REG_WR(pDevice, BufMgr.MbufMacRxLowWaterMark,
2470 pDevice->RxMacMbufLowMark);
2474 if(pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE)
2476 REG_WR(pDevice, BufMgr.MbufMacRxLowWaterMark,
2477 T3_DEF_RX_MAC_MBUF_LOW_WMARK);
2481 REG_WR(pDevice, BufMgr.MbufMacRxLowWaterMark,
2482 T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO);
2486 /* Configure the MBUF high water mark. */
2487 if(pDevice->MbufHighMark)
2489 REG_WR(pDevice, BufMgr.MbufHighWaterMark, pDevice->MbufHighMark);
2493 if(pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE)
2495 REG_WR(pDevice, BufMgr.MbufHighWaterMark,
2496 T3_DEF_MBUF_HIGH_WMARK);
2500 REG_WR(pDevice, BufMgr.MbufHighWaterMark,
2501 T3_DEF_MBUF_HIGH_WMARK_JUMBO);
2505 REG_WR(pDevice, BufMgr.DmaLowWaterMark, T3_DEF_DMA_DESC_LOW_WMARK);
2506 REG_WR(pDevice, BufMgr.DmaHighWaterMark, T3_DEF_DMA_DESC_HIGH_WMARK);
2508 /* Enable buffer manager. */
2509 REG_WR(pDevice, BufMgr.Mode, BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
2511 for(j = 0 ;j < 2000; j++)
2513 if(REG_RD(pDevice, BufMgr.Mode) & BUFMGR_MODE_ENABLE)
2520 return LM_STATUS_FAILURE;
2523 /* Enable the FTQs. */
2524 REG_WR(pDevice, Ftq.Reset, 0xffffffff);
2525 REG_WR(pDevice, Ftq.Reset, 0);
2527 /* Wait until FTQ is ready */
2528 for(j = 0; j < 2000; j++)
2530 if(REG_RD(pDevice, Ftq.Reset) == 0)
2537 return LM_STATUS_FAILURE;
2540 /* Initialize the Standard Receive RCB. */
2541 REG_WR(pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.High,
2542 pDevice->RxStdBdPhy.High);
2543 REG_WR(pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.Low,
2544 pDevice->RxStdBdPhy.Low);
2545 REG_WR(pDevice, RcvDataBdIn.StdRcvRcb.u.MaxLen_Flags,
2546 MAX_STD_RCV_BUFFER_SIZE << 16);
2548 /* Initialize the Jumbo Receive RCB. */
2549 REG_WR(pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags,
2550 T3_RCB_FLAG_RING_DISABLED);
2551 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2552 REG_WR(pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.High,
2553 pDevice->RxJumboBdPhy.High);
2554 REG_WR(pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.Low,
2555 pDevice->RxJumboBdPhy.Low);
2557 REG_WR(pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags, 0);
2559 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
2561 /* Initialize the Mini Receive RCB. */
2562 REG_WR(pDevice, RcvDataBdIn.MiniRcvRcb.u.MaxLen_Flags,
2563 T3_RCB_FLAG_RING_DISABLED);
2566 REG_WR(pDevice, RcvDataBdIn.StdRcvRcb.NicRingAddr,
2567 (LM_UINT32) T3_NIC_STD_RCV_BUFFER_DESC_ADDR);
2568 REG_WR(pDevice, RcvDataBdIn.JumboRcvRcb.NicRingAddr,
2569 (LM_UINT32) T3_NIC_JUMBO_RCV_BUFFER_DESC_ADDR);
2572 /* Receive BD Ring replenish threshold. */
2573 REG_WR(pDevice, RcvBdIn.StdRcvThreshold, pDevice->RxStdDescCnt/8);
2574 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2575 REG_WR(pDevice, RcvBdIn.JumboRcvThreshold, pDevice->RxJumboDescCnt/8);
2576 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
2578 /* Disable all the unused rings. */
2579 for(j = 0; j < T3_MAX_SEND_RCB_COUNT; j++) {
2580 MEM_WR(pDevice, SendRcb[j].u.MaxLen_Flags, T3_RCB_FLAG_RING_DISABLED);
2583 /* Initialize the indices. */
2584 pDevice->SendProdIdx = 0;
2585 pDevice->SendConIdx = 0;
2587 MB_REG_WR(pDevice, Mailbox.SendHostProdIdx[0].Low, 0);
2588 MB_REG_WR(pDevice, Mailbox.SendNicProdIdx[0].Low, 0);
2590 /* Set up host or NIC based send RCB. */
2591 if(pDevice->NicSendBd == FALSE)
2593 MEM_WR(pDevice, SendRcb[0].HostRingAddr.High,
2594 pDevice->SendBdPhy.High);
2595 MEM_WR(pDevice, SendRcb[0].HostRingAddr.Low,
2596 pDevice->SendBdPhy.Low);
2598 /* Set up the NIC ring address in the RCB. */
2599 MEM_WR(pDevice, SendRcb[0].NicRingAddr,T3_NIC_SND_BUFFER_DESC_ADDR);
2601 /* Setup the RCB. */
2602 MEM_WR(pDevice, SendRcb[0].u.MaxLen_Flags,
2603 T3_SEND_RCB_ENTRY_COUNT << 16);
2605 for(k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++)
2607 pDevice->pSendBdVirt[k].HostAddr.High = 0;
2608 pDevice->pSendBdVirt[k].HostAddr.Low = 0;
2613 MEM_WR(pDevice, SendRcb[0].HostRingAddr.High, 0);
2614 MEM_WR(pDevice, SendRcb[0].HostRingAddr.Low, 0);
2615 MEM_WR(pDevice, SendRcb[0].NicRingAddr,
2616 pDevice->SendBdPhy.Low);
2618 for(k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++)
2620 __raw_writel(0, &(pDevice->pSendBdVirt[k].HostAddr.High));
2621 __raw_writel(0, &(pDevice->pSendBdVirt[k].HostAddr.Low));
2622 __raw_writel(0, &(pDevice->pSendBdVirt[k].u1.Len_Flags));
2623 pDevice->ShadowSendBd[k].HostAddr.High = 0;
2624 pDevice->ShadowSendBd[k].u1.Len_Flags = 0;
2627 atomic_set(&pDevice->SendBdLeft, T3_SEND_RCB_ENTRY_COUNT-1);
2629 /* Configure the receive return rings. */
2630 for(j = 0; j < T3_MAX_RCV_RETURN_RCB_COUNT; j++)
2632 MEM_WR(pDevice, RcvRetRcb[j].u.MaxLen_Flags, T3_RCB_FLAG_RING_DISABLED);
2635 pDevice->RcvRetConIdx = 0;
2637 MEM_WR(pDevice, RcvRetRcb[0].HostRingAddr.High,
2638 pDevice->RcvRetBdPhy.High);
2639 MEM_WR(pDevice, RcvRetRcb[0].HostRingAddr.Low,
2640 pDevice->RcvRetBdPhy.Low);
2642 /* Set up the NIC ring address in the RCB. */
2643 /* Not very clear from the spec. I am guessing that for Receive */
2644 /* Return Ring, NicRingAddr is not used. */
2645 MEM_WR(pDevice, RcvRetRcb[0].NicRingAddr, 0);
2647 /* Setup the RCB. */
2648 MEM_WR(pDevice, RcvRetRcb[0].u.MaxLen_Flags,
2649 T3_RCV_RETURN_RCB_ENTRY_COUNT << 16);
2651 /* Reinitialize RX ring producer index */
2652 MB_REG_WR(pDevice, Mailbox.RcvStdProdIdx.Low, 0);
2653 MB_REG_WR(pDevice, Mailbox.RcvJumboProdIdx.Low, 0);
2654 MB_REG_WR(pDevice, Mailbox.RcvMiniProdIdx.Low, 0);
2656 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
2657 pDevice->RxJumboProdIdx = 0;
2658 pDevice->RxJumboQueuedCnt = 0;
2661 /* Reinitialize our copy of the indices. */
2662 pDevice->RxStdProdIdx = 0;
2663 pDevice->RxStdQueuedCnt = 0;
2665 #if T3_JUMBO_RCV_ENTRY_COUNT
2666 pDevice->RxJumboProdIdx = 0;
2667 #endif /* T3_JUMBO_RCV_ENTRY_COUNT */
2669 /* Configure the MAC address. */
2670 LM_SetMacAddress(pDevice, pDevice->NodeAddress);
2672 /* Initialize the transmit random backoff seed. */
2673 Value32 = (pDevice->NodeAddress[0] + pDevice->NodeAddress[1] +
2674 pDevice->NodeAddress[2] + pDevice->NodeAddress[3] +
2675 pDevice->NodeAddress[4] + pDevice->NodeAddress[5]) &
2676 MAC_TX_BACKOFF_SEED_MASK;
2677 REG_WR(pDevice, MacCtrl.TxBackoffSeed, Value32);
2679 /* Receive MTU. Frames larger than the MTU is marked as oversized. */
2680 REG_WR(pDevice, MacCtrl.MtuSize, pDevice->RxMtu + 8); /* CRC + VLAN. */
2682 /* Configure Time slot/IPG per 802.3 */
2683 REG_WR(pDevice, MacCtrl.TxLengths, 0x2620);
2686 * Configure Receive Rules so that packets don't match
2687 * Programmble rule will be queued to Return Ring 1
2689 REG_WR(pDevice, MacCtrl.RcvRuleCfg, RX_RULE_DEFAULT_CLASS);
2692 * Configure to have 16 Classes of Services (COS) and one
2693 * queue per class. Bad frames are queued to RRR#1.
2694 * And frames don't match rules are also queued to COS#1.
2696 REG_WR(pDevice, RcvListPlmt.Config, 0x181);
2698 /* Enable Receive Placement Statistics */
2699 REG_WR(pDevice, RcvListPlmt.StatsEnableMask,0xffffff);
2700 REG_WR(pDevice, RcvListPlmt.StatsCtrl, RCV_LIST_STATS_ENABLE);
2702 /* Enable Send Data Initator Statistics */
2703 REG_WR(pDevice, SndDataIn.StatsEnableMask,0xffffff);
2704 REG_WR(pDevice, SndDataIn.StatsCtrl,
2705 T3_SND_DATA_IN_STATS_CTRL_ENABLE | \
2706 T3_SND_DATA_IN_STATS_CTRL_FASTER_UPDATE);
2708 /* Disable the host coalescing state machine before configuring it's */
2710 REG_WR(pDevice, HostCoalesce.Mode, 0);
2711 for(j = 0; j < 2000; j++)
2713 Value32 = REG_RD(pDevice, HostCoalesce.Mode);
2714 if(!(Value32 & HOST_COALESCE_ENABLE))
2721 /* Host coalescing configurations. */
2722 REG_WR(pDevice, HostCoalesce.RxCoalescingTicks, pDevice->RxCoalescingTicks);
2723 REG_WR(pDevice, HostCoalesce.TxCoalescingTicks, pDevice->TxCoalescingTicks);
2724 REG_WR(pDevice, HostCoalesce.RxMaxCoalescedFrames,
2725 pDevice->RxMaxCoalescedFrames);
2726 REG_WR(pDevice, HostCoalesce.TxMaxCoalescedFrames,
2727 pDevice->TxMaxCoalescedFrames);
2728 REG_WR(pDevice, HostCoalesce.RxCoalescedTickDuringInt,
2729 pDevice->RxCoalescingTicksDuringInt);
2730 REG_WR(pDevice, HostCoalesce.TxCoalescedTickDuringInt,
2731 pDevice->TxCoalescingTicksDuringInt);
2732 REG_WR(pDevice, HostCoalesce.RxMaxCoalescedFramesDuringInt,
2733 pDevice->RxMaxCoalescedFramesDuringInt);
2734 REG_WR(pDevice, HostCoalesce.TxMaxCoalescedFramesDuringInt,
2735 pDevice->TxMaxCoalescedFramesDuringInt);
2737 /* Initialize the address of the status block. The NIC will DMA */
2738 /* the status block to this memory which resides on the host. */
2739 REG_WR(pDevice, HostCoalesce.StatusBlkHostAddr.High,
2740 pDevice->StatusBlkPhy.High);
2741 REG_WR(pDevice, HostCoalesce.StatusBlkHostAddr.Low,
2742 pDevice->StatusBlkPhy.Low);
2744 /* Initialize the address of the statistics block. The NIC will DMA */
2745 /* the statistics to this block of memory. */
2746 REG_WR(pDevice, HostCoalesce.StatsBlkHostAddr.High,
2747 pDevice->StatsBlkPhy.High);
2748 REG_WR(pDevice, HostCoalesce.StatsBlkHostAddr.Low,
2749 pDevice->StatsBlkPhy.Low);
2751 REG_WR(pDevice, HostCoalesce.StatsCoalescingTicks,
2752 pDevice->StatsCoalescingTicks);
2754 REG_WR(pDevice, HostCoalesce.StatsBlkNicAddr, 0x300);
2755 REG_WR(pDevice, HostCoalesce.StatusBlkNicAddr,0xb00);
2757 /* Enable Host Coalesing state machine */
2758 REG_WR(pDevice, HostCoalesce.Mode, HOST_COALESCE_ENABLE |
2759 pDevice->CoalesceMode);
2761 /* Enable the Receive BD Completion state machine. */
2762 REG_WR(pDevice, RcvBdComp.Mode, RCV_BD_COMP_MODE_ENABLE |
2763 RCV_BD_COMP_MODE_ATTN_ENABLE);
2765 /* Enable the Receive List Placement state machine. */
2766 REG_WR(pDevice, RcvListPlmt.Mode, RCV_LIST_PLMT_MODE_ENABLE);
2768 /* Enable the Receive List Selector state machine. */
2769 REG_WR(pDevice, RcvListSel.Mode, RCV_LIST_SEL_MODE_ENABLE |
2770 RCV_LIST_SEL_MODE_ATTN_ENABLE);
2772 /* Enable transmit DMA, clear statistics. */
2773 pDevice->MacMode = MAC_MODE_ENABLE_TX_STATISTICS |
2774 MAC_MODE_ENABLE_RX_STATISTICS | MAC_MODE_ENABLE_TDE |
2775 MAC_MODE_ENABLE_RDE | MAC_MODE_ENABLE_FHDE;
2776 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode |
2777 MAC_MODE_CLEAR_RX_STATISTICS | MAC_MODE_CLEAR_TX_STATISTICS);
2779 /* GRC miscellaneous local control register. */
2780 pDevice->GrcLocalCtrl = GRC_MISC_LOCAL_CTRL_INT_ON_ATTN |
2781 GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM;
2783 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
2785 pDevice->GrcLocalCtrl |= GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
2786 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1;
2789 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
2792 /* Reset RX counters. */
2793 for(j = 0; j < sizeof(LM_RX_COUNTERS); j++)
2795 ((PLM_UINT8) &pDevice->RxCounters)[j] = 0;
2798 /* Reset TX counters. */
2799 for(j = 0; j < sizeof(LM_TX_COUNTERS); j++)
2801 ((PLM_UINT8) &pDevice->TxCounters)[j] = 0;
2804 MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 0);
2806 /* Enable the DMA Completion state machine. */
2807 REG_WR(pDevice, DmaComp.Mode, DMA_COMP_MODE_ENABLE);
2809 /* Enable the DMA Write state machine. */
2810 Value32 = DMA_WRITE_MODE_ENABLE |
2811 DMA_WRITE_MODE_TARGET_ABORT_ATTN_ENABLE |
2812 DMA_WRITE_MODE_MASTER_ABORT_ATTN_ENABLE |
2813 DMA_WRITE_MODE_PARITY_ERROR_ATTN_ENABLE |
2814 DMA_WRITE_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2815 DMA_WRITE_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2816 DMA_WRITE_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2817 DMA_WRITE_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2818 DMA_WRITE_MODE_LONG_READ_ATTN_ENABLE;
2819 REG_WR(pDevice, DmaWrite.Mode, Value32);
2821 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))
2823 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0)
2825 Value16 = REG_RD(pDevice, PciCfg.PciXCommand);
2826 Value16 &= ~(PCIX_CMD_MAX_SPLIT_MASK | PCIX_CMD_MAX_BURST_MASK);
2827 Value16 |= ((PCIX_CMD_MAX_BURST_CPIOB << PCIX_CMD_MAX_BURST_SHL) &
2828 PCIX_CMD_MAX_BURST_MASK);
2829 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE)
2831 Value16 |= (pDevice->SplitModeMaxReq << PCIX_CMD_MAX_SPLIT_SHL)
2832 & PCIX_CMD_MAX_SPLIT_MASK;
2834 REG_WR(pDevice, PciCfg.PciXCommand, Value16);
2838 /* Enable the Read DMA state machine. */
2839 Value32 = DMA_READ_MODE_ENABLE |
2840 DMA_READ_MODE_TARGET_ABORT_ATTN_ENABLE |
2841 DMA_READ_MODE_MASTER_ABORT_ATTN_ENABLE |
2842 DMA_READ_MODE_PARITY_ERROR_ATTN_ENABLE |
2843 DMA_READ_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2844 DMA_READ_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2845 DMA_READ_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2846 DMA_READ_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2847 DMA_READ_MODE_LONG_READ_ATTN_ENABLE;
2849 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE)
2851 Value32 |= DMA_READ_MODE_SPLIT_ENABLE;
2853 REG_WR(pDevice, DmaRead.Mode, Value32);
2855 /* Enable the Receive Data Completion state machine. */
2856 REG_WR(pDevice, RcvDataComp.Mode, RCV_DATA_COMP_MODE_ENABLE |
2857 RCV_DATA_COMP_MODE_ATTN_ENABLE);
2859 /* Enable the Mbuf Cluster Free state machine. */
2860 REG_WR(pDevice, MbufClusterFree.Mode, MBUF_CLUSTER_FREE_MODE_ENABLE);
2862 /* Enable the Send Data Completion state machine. */
2863 REG_WR(pDevice, SndDataComp.Mode, SND_DATA_COMP_MODE_ENABLE);
2865 /* Enable the Send BD Completion state machine. */
2866 REG_WR(pDevice, SndBdComp.Mode, SND_BD_COMP_MODE_ENABLE |
2867 SND_BD_COMP_MODE_ATTN_ENABLE);
2869 /* Enable the Receive BD Initiator state machine. */
2870 REG_WR(pDevice, RcvBdIn.Mode, RCV_BD_IN_MODE_ENABLE |
2871 RCV_BD_IN_MODE_BD_IN_DIABLED_RCB_ATTN_ENABLE);
2873 /* Enable the Receive Data and Receive BD Initiator state machine. */
2874 REG_WR(pDevice, RcvDataBdIn.Mode, RCV_DATA_BD_IN_MODE_ENABLE |
2875 RCV_DATA_BD_IN_MODE_INVALID_RING_SIZE);
2877 /* Enable the Send Data Initiator state machine. */
2878 REG_WR(pDevice, SndDataIn.Mode, T3_SND_DATA_IN_MODE_ENABLE);
2880 /* Enable the Send BD Initiator state machine. */
2881 REG_WR(pDevice, SndBdIn.Mode, SND_BD_IN_MODE_ENABLE |
2882 SND_BD_IN_MODE_ATTN_ENABLE);
2884 /* Enable the Send BD Selector state machine. */
2885 REG_WR(pDevice, SndBdSel.Mode, SND_BD_SEL_MODE_ENABLE |
2886 SND_BD_SEL_MODE_ATTN_ENABLE);
2888 #if INCLUDE_5701_AX_FIX
2889 /* Load the firmware for the 5701_A0 workaround. */
2890 if(pDevice->ChipRevId == T3_CHIP_ID_5701_A0)
2892 LM_LoadRlsFirmware(pDevice);
2896 /* Enable the transmitter. */
2897 pDevice->TxMode = TX_MODE_ENABLE;
2898 REG_WR(pDevice, MacCtrl.TxMode, pDevice->TxMode);
2900 /* Enable the receiver. */
2901 pDevice->RxMode = RX_MODE_ENABLE;
2902 REG_WR(pDevice, MacCtrl.RxMode, pDevice->RxMode);
2904 if (pDevice->RestoreOnWakeUp)
2906 pDevice->RestoreOnWakeUp = FALSE;
2907 pDevice->DisableAutoNeg = pDevice->WakeUpDisableAutoNeg;
2908 pDevice->RequestedMediaType = pDevice->WakeUpRequestedMediaType;
2911 /* Disable auto polling. */
2912 pDevice->MiMode = 0xc0000;
2913 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
2915 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
2916 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
2918 Value32 = LED_CTRL_PHY_MODE_1;
2922 if(pDevice->LedMode == LED_MODE_OUTPUT)
2924 Value32 = LED_CTRL_PHY_MODE_2;
2928 Value32 = LED_CTRL_PHY_MODE_1;
2931 REG_WR(pDevice, MacCtrl.LedCtrl, Value32);
2933 /* Activate Link to enable MAC state machine */
2934 REG_WR(pDevice, MacCtrl.MiStatus, MI_STATUS_ENABLE_LINK_STATUS_ATTN);
2936 if (pDevice->EnableTbi)
2938 REG_WR(pDevice, MacCtrl.RxMode, RX_MODE_RESET);
2940 REG_WR(pDevice, MacCtrl.RxMode, pDevice->RxMode);
2941 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1)
2943 REG_WR(pDevice, MacCtrl.SerdesCfg, 0x616000);
2946 /* Setup the phy chip. */
2947 LM_SetupPhy(pDevice);
2949 if (!pDevice->EnableTbi) {
2950 /* Clear CRC stats */
2951 LM_ReadPhy(pDevice, 0x1e, &Value32);
2952 LM_WritePhy(pDevice, 0x1e, Value32 | 0x8000);
2953 LM_ReadPhy(pDevice, 0x14, &Value32);
2956 /* Set up the receive mask. */
2957 LM_SetReceiveMask(pDevice, pDevice->ReceiveMask);
2959 /* Queue Rx packet buffers. */
2960 if(pDevice->QueueRxPackets)
2962 LM_QueueRxPackets(pDevice);
2965 /* Enable interrupt to the host. */
2966 if(pDevice->InitDone)
2968 LM_EnableInterrupt(pDevice);
2971 return LM_STATUS_SUCCESS;
2972 } /* LM_ResetAdapter */
2975 /******************************************************************************/
2977 /* This routine disables the adapter from generating interrupts. */
2980 /* LM_STATUS_SUCCESS */
2981 /******************************************************************************/
2983 LM_DisableInterrupt(
2984 PLM_DEVICE_BLOCK pDevice)
2986 REG_WR(pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl |
2987 MISC_HOST_CTRL_MASK_PCI_INT);
2988 MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 1);
2990 return LM_STATUS_SUCCESS;
2994 /******************************************************************************/
2996 /* This routine enables the adapter to generate interrupts. */
2999 /* LM_STATUS_SUCCESS */
3000 /******************************************************************************/
3003 PLM_DEVICE_BLOCK pDevice)
3005 REG_WR(pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl &
3006 ~MISC_HOST_CTRL_MASK_PCI_INT);
3007 MB_REG_WR(pDevice, Mailbox.Interrupt[0].Low, 0);
3009 if(pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED)
3011 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
3012 GRC_MISC_LOCAL_CTRL_SET_INT);
3015 return LM_STATUS_SUCCESS;
3019 /******************************************************************************/
3021 /* This routine puts a packet on the wire if there is a transmit DMA */
3022 /* descriptor available; otherwise the packet is queued for later */
3023 /* transmission. If the second argue is NULL, this routine will put */
3024 /* the queued packet on the wire if possible. */
3027 /* LM_STATUS_SUCCESS */
3028 /******************************************************************************/
3031 LM_SendPacket(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
3033 LM_UINT32 FragCount;
3035 PT3_SND_BD pShadowSendBd;
3036 LM_UINT32 Value32, Len;
3039 if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700) {
3040 return LM_5700SendPacket(pDevice, pPacket);
3043 /* Update the SendBdLeft count. */
3044 atomic_sub(pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3046 /* Initalize the send buffer descriptors. */
3047 Idx = pDevice->SendProdIdx;
3049 pSendBd = &pDevice->pSendBdVirt[Idx];
3051 /* Next producer index. */
3052 if (pDevice->NicSendBd == TRUE)
3054 T3_64BIT_HOST_ADDR paddr;
3056 pShadowSendBd = &pDevice->ShadowSendBd[Idx];
3057 for(FragCount = 0; ; )
3059 MM_MapTxDma(pDevice, pPacket, &paddr, &Len, FragCount);
3060 /* Initialize the pointer to the send buffer fragment. */
3061 if (paddr.High != pShadowSendBd->HostAddr.High)
3063 __raw_writel(paddr.High, &(pSendBd->HostAddr.High));
3064 pShadowSendBd->HostAddr.High = paddr.High;
3066 __raw_writel(paddr.Low, &(pSendBd->HostAddr.Low));
3068 /* Setup the control flags and send buffer size. */
3069 Value32 = (Len << 16) | pPacket->Flags;
3071 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3074 if (FragCount >= pPacket->u.Tx.FragCount)
3076 Value32 |= SND_BD_FLAG_END;
3077 if (Value32 != pShadowSendBd->u1.Len_Flags)
3079 __raw_writel(Value32, &(pSendBd->u1.Len_Flags));
3080 pShadowSendBd->u1.Len_Flags = Value32;
3082 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
3083 __raw_writel(pPacket->VlanTag, &(pSendBd->u2.VlanTag));
3089 if (Value32 != pShadowSendBd->u1.Len_Flags)
3091 __raw_writel(Value32, &(pSendBd->u1.Len_Flags));
3092 pShadowSendBd->u1.Len_Flags = Value32;
3094 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
3095 __raw_writel(pPacket->VlanTag, &(pSendBd->u2.VlanTag));
3103 pSendBd = &pDevice->pSendBdVirt[0];
3104 pShadowSendBd = &pDevice->ShadowSendBd[0];
3108 /* Put the packet descriptor in the ActiveQ. */
3109 QQ_PushTail(&pDevice->TxPacketActiveQ.Container, pPacket);
3112 MB_REG_WR(pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3117 for(FragCount = 0; ; )
3119 /* Initialize the pointer to the send buffer fragment. */
3120 MM_MapTxDma(pDevice, pPacket, &pSendBd->HostAddr, &Len, FragCount);
3122 pSendBd->u2.VlanTag = pPacket->VlanTag;
3124 /* Setup the control flags and send buffer size. */
3125 Value32 = (Len << 16) | pPacket->Flags;
3127 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3130 if (FragCount >= pPacket->u.Tx.FragCount)
3132 pSendBd->u1.Len_Flags = Value32 | SND_BD_FLAG_END;
3137 pSendBd->u1.Len_Flags = Value32;
3142 pSendBd = &pDevice->pSendBdVirt[0];
3146 /* Put the packet descriptor in the ActiveQ. */
3147 QQ_PushTail(&pDevice->TxPacketActiveQ.Container, pPacket);
3150 MB_REG_WR(pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
3154 /* Update the producer index. */
3155 pDevice->SendProdIdx = Idx;
3157 return LM_STATUS_SUCCESS;
3162 LM_SendPacket(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
3164 LM_UINT32 FragCount;
3165 PT3_SND_BD pSendBd, pTmpSendBd, pShadowSendBd;
3166 T3_SND_BD NicSendBdArr[MAX_FRAGMENT_COUNT];
3167 LM_UINT32 StartIdx, Idx;
3171 /* Initalize the send buffer descriptors. */
3172 StartIdx = Idx = pDevice->SendProdIdx;
3174 if (pDevice->NicSendBd)
3176 pTmpSendBd = pSendBd = &NicSendBdArr[0];
3180 pTmpSendBd = pSendBd = &pDevice->pSendBdVirt[Idx];
3183 /* Next producer index. */
3184 for(FragCount = 0; ; )
3186 LM_UINT32 Value32, Len;
3188 /* Initialize the pointer to the send buffer fragment. */
3189 MM_MapTxDma(pDevice, pPacket, &pSendBd->HostAddr, &Len, FragCount);
3191 pSendBd->u2.VlanTag = pPacket->VlanTag;
3193 /* Setup the control flags and send buffer size. */
3194 Value32 = (Len << 16) | pPacket->Flags;
3196 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3199 if (FragCount >= pPacket->u.Tx.FragCount)
3201 pSendBd->u1.Len_Flags = Value32 | SND_BD_FLAG_END;
3206 pSendBd->u1.Len_Flags = Value32;
3209 if ((Idx == 0) && !pDevice->NicSendBd)
3211 pSendBd = &pDevice->pSendBdVirt[0];
3214 if (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
3216 if (LM_Test4GBoundary(pDevice, pPacket, pTmpSendBd) ==
3219 if (MM_CoalesceTxBuffer(pDevice, pPacket) != LM_STATUS_SUCCESS)
3221 QQ_PushHead(&pDevice->TxPacketFreeQ.Container, pPacket);
3222 return LM_STATUS_FAILURE;
3229 /* Put the packet descriptor in the ActiveQ. */
3230 QQ_PushTail(&pDevice->TxPacketActiveQ.Container, pPacket);
3232 if (pDevice->NicSendBd)
3234 pSendBd = &pDevice->pSendBdVirt[StartIdx];
3235 pShadowSendBd = &pDevice->ShadowSendBd[StartIdx];
3237 while (StartIdx != Idx)
3241 if ((Value32 = pTmpSendBd->HostAddr.High) !=
3242 pShadowSendBd->HostAddr.High)
3244 __raw_writel(Value32, &(pSendBd->HostAddr.High));
3245 pShadowSendBd->HostAddr.High = Value32;
3248 __raw_writel(pTmpSendBd->HostAddr.Low, &(pSendBd->HostAddr.Low));
3250 if ((Value32 = pTmpSendBd->u1.Len_Flags) !=
3251 pShadowSendBd->u1.Len_Flags)
3253 __raw_writel(Value32, &(pSendBd->u1.Len_Flags));
3254 pShadowSendBd->u1.Len_Flags = Value32;
3257 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG)
3259 __raw_writel(pTmpSendBd->u2.VlanTag, &(pSendBd->u2.VlanTag));
3262 StartIdx = (StartIdx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3264 pSendBd = &pDevice->pSendBdVirt[0];
3270 MB_REG_WR(pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3272 if(T3_CHIP_REV(pDevice->ChipRevId) == T3_CHIP_REV_5700_BX)
3274 MB_REG_WR(pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3280 MB_REG_WR(pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
3282 if(T3_CHIP_REV(pDevice->ChipRevId) == T3_CHIP_REV_5700_BX)
3284 MB_REG_WR(pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
3288 /* Update the SendBdLeft count. */
3289 atomic_sub(pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3291 /* Update the producer index. */
3292 pDevice->SendProdIdx = Idx;
3294 return LM_STATUS_SUCCESS;
3298 LM_Test4GBoundary(PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket,
3302 LM_UINT32 Idx, Base, Len;
3304 Idx = pDevice->SendProdIdx;
3305 for(FragCount = 0; ; )
3307 Len = pSendBd->u1.Len_Flags >> 16;
3308 if (((Base = pSendBd->HostAddr.Low) > 0xffffdcc0) &&
3309 (pSendBd->HostAddr.High == 0) &&
3310 ((Base + 8 + Len) < Base))
3312 return LM_STATUS_SUCCESS;
3315 if (FragCount >= pPacket->u.Tx.FragCount)
3320 if (!pDevice->NicSendBd)
3322 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3325 pSendBd = &pDevice->pSendBdVirt[0];
3329 return LM_STATUS_FAILURE;
3332 /******************************************************************************/
3336 /******************************************************************************/
3337 __inline static unsigned long
3339 unsigned char *pBuffer,
3340 unsigned long BufferSize) {
3347 for(j = 0; j < BufferSize; j++)
3351 for(k = 0; k < 8; k++)
3365 } /* ComputeCrc32 */
3368 /******************************************************************************/
3370 /* This routine sets the receive control register according to ReceiveMask */
3373 /* LM_STATUS_SUCCESS */
3374 /******************************************************************************/
3377 PLM_DEVICE_BLOCK pDevice,
3379 LM_UINT32 ReceiveMask;
3385 RxMode = pDevice->RxMode;
3387 if(Mask & LM_ACCEPT_UNICAST)
3389 Mask &= ~LM_ACCEPT_UNICAST;
3392 if(Mask & LM_ACCEPT_MULTICAST)
3394 Mask &= ~LM_ACCEPT_MULTICAST;
3397 if(Mask & LM_ACCEPT_ALL_MULTICAST)
3399 Mask &= ~LM_ACCEPT_ALL_MULTICAST;
3402 if(Mask & LM_ACCEPT_BROADCAST)
3404 Mask &= ~LM_ACCEPT_BROADCAST;
3407 RxMode &= ~RX_MODE_PROMISCUOUS_MODE;
3408 if(Mask & LM_PROMISCUOUS_MODE)
3410 RxMode |= RX_MODE_PROMISCUOUS_MODE;
3411 Mask &= ~LM_PROMISCUOUS_MODE;
3414 RxMode &= ~(RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED);
3415 if(Mask & LM_ACCEPT_ERROR_PACKET)
3417 RxMode |= RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED;
3418 Mask &= ~LM_ACCEPT_ERROR_PACKET;
3421 /* Make sure all the bits are valid before committing changes. */
3424 return LM_STATUS_FAILURE;
3427 /* Commit the new filter. */
3428 pDevice->RxMode = RxMode;
3429 REG_WR(pDevice, MacCtrl.RxMode, RxMode);
3431 pDevice->ReceiveMask = ReceiveMask;
3433 /* Set up the MC hash table. */
3434 if(ReceiveMask & LM_ACCEPT_ALL_MULTICAST)
3436 for(k = 0; k < 4; k++)
3438 REG_WR(pDevice, MacCtrl.HashReg[k], 0xffffffff);
3441 else if(ReceiveMask & LM_ACCEPT_MULTICAST)
3443 LM_UINT32 HashReg[4];
3445 HashReg[0] = 0; HashReg[1] = 0; HashReg[2] = 0; HashReg[3] = 0;
3446 for(j = 0; j < pDevice->McEntryCount; j++)
3452 Crc32 = ComputeCrc32(pDevice->McTable[j], ETHERNET_ADDRESS_SIZE);
3454 /* The most significant 7 bits of the CRC32 (no inversion), */
3455 /* are used to index into one of the possible 128 bit positions. */
3456 Bitpos = ~Crc32 & 0x7f;
3458 /* Hash register index. */
3459 RegIndex = (Bitpos & 0x60) >> 5;
3461 /* Bit to turn on within a hash register. */
3464 /* Enable the multicast bit. */
3465 HashReg[RegIndex] |= (1 << Bitpos);
3468 /* REV_AX has problem with multicast filtering where it uses both */
3469 /* DA and SA to perform hashing. */
3470 for(k = 0; k < 4; k++)
3472 REG_WR(pDevice, MacCtrl.HashReg[k], HashReg[k]);
3477 /* Reject all multicast frames. */
3478 for(j = 0; j < 4; j++)
3480 REG_WR(pDevice, MacCtrl.HashReg[j], 0);
3484 /* By default, Tigon3 will accept broadcast frames. We need to setup */
3485 if(ReceiveMask & LM_ACCEPT_BROADCAST)
3487 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3488 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3489 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3490 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3491 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3492 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3493 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3494 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3498 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3499 REJECT_BROADCAST_RULE1_RULE);
3500 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3501 REJECT_BROADCAST_RULE1_VALUE);
3502 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3503 REJECT_BROADCAST_RULE2_RULE);
3504 REG_WR(pDevice, MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3505 REJECT_BROADCAST_RULE2_VALUE);
3508 /* disable the rest of the rules. */
3509 for(j = RCV_LAST_RULE_IDX; j < 16; j++)
3511 REG_WR(pDevice, MacCtrl.RcvRules[j].Rule, 0);
3512 REG_WR(pDevice, MacCtrl.RcvRules[j].Value, 0);
3515 return LM_STATUS_SUCCESS;
3516 } /* LM_SetReceiveMask */
3519 /******************************************************************************/
3521 /* Disable the interrupt and put the transmitter and receiver engines in */
3522 /* an idle state. Also aborts all pending send requests and receive */
3526 /* LM_STATUS_SUCCESS */
3527 /******************************************************************************/
3530 PLM_DEVICE_BLOCK pDevice)
3535 LM_DisableInterrupt(pDevice);
3537 /* Disable all the state machines. */
3538 LM_CntrlBlock(pDevice,T3_BLOCK_MAC_RX_ENGINE,LM_DISABLE);
3539 LM_CntrlBlock(pDevice,T3_BLOCK_RX_BD_INITIATOR,LM_DISABLE);
3540 LM_CntrlBlock(pDevice,T3_BLOCK_RX_LIST_PLMT,LM_DISABLE);
3541 LM_CntrlBlock(pDevice,T3_BLOCK_RX_LIST_SELECTOR,LM_DISABLE);
3542 LM_CntrlBlock(pDevice,T3_BLOCK_RX_DATA_INITIATOR,LM_DISABLE);
3543 LM_CntrlBlock(pDevice,T3_BLOCK_RX_DATA_COMP,LM_DISABLE);
3544 LM_CntrlBlock(pDevice,T3_BLOCK_RX_BD_COMP,LM_DISABLE);
3546 LM_CntrlBlock(pDevice,T3_BLOCK_SEND_BD_SELECTOR,LM_DISABLE);
3547 LM_CntrlBlock(pDevice,T3_BLOCK_SEND_BD_INITIATOR,LM_DISABLE);
3548 LM_CntrlBlock(pDevice,T3_BLOCK_SEND_DATA_INITIATOR,LM_DISABLE);
3549 LM_CntrlBlock(pDevice,T3_BLOCK_DMA_RD,LM_DISABLE);
3550 LM_CntrlBlock(pDevice,T3_BLOCK_SEND_DATA_COMP,LM_DISABLE);
3551 LM_CntrlBlock(pDevice,T3_BLOCK_DMA_COMP,LM_DISABLE);
3552 LM_CntrlBlock(pDevice,T3_BLOCK_SEND_BD_COMP,LM_DISABLE);
3555 pDevice->MacMode &= ~MAC_MODE_ENABLE_TDE;
3556 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
3558 LM_CntrlBlock(pDevice,T3_BLOCK_MAC_TX_ENGINE,LM_DISABLE);
3559 LM_CntrlBlock(pDevice,T3_BLOCK_HOST_COALESING,LM_DISABLE);
3560 LM_CntrlBlock(pDevice,T3_BLOCK_DMA_WR,LM_DISABLE);
3561 LM_CntrlBlock(pDevice,T3_BLOCK_MBUF_CLUSTER_FREE,LM_DISABLE);
3563 /* Reset all FTQs */
3564 REG_WR(pDevice, Ftq.Reset, 0xffffffff);
3565 REG_WR(pDevice, Ftq.Reset, 0x0);
3567 LM_CntrlBlock(pDevice,T3_BLOCK_MBUF_MANAGER,LM_DISABLE);
3568 LM_CntrlBlock(pDevice,T3_BLOCK_MEM_ARBITOR,LM_DISABLE);
3570 MM_ACQUIRE_INT_LOCK(pDevice);
3572 /* Abort packets that have already queued to go out. */
3573 pPacket = (PLM_PACKET) QQ_PopHead(&pDevice->TxPacketActiveQ.Container);
3577 pPacket->PacketStatus = LM_STATUS_TRANSMIT_ABORTED;
3578 pDevice->TxCounters.TxPacketAbortedCnt++;
3580 atomic_add(pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3582 QQ_PushTail(&pDevice->TxPacketXmittedQ.Container, pPacket);
3584 pPacket = (PLM_PACKET)
3585 QQ_PopHead(&pDevice->TxPacketActiveQ.Container);
3588 /* Cleanup the receive return rings. */
3589 LM_ServiceRxInterrupt(pDevice);
3591 /* Don't want to indicate rx packets in Ndis miniport shutdown context. */
3592 /* Doing so may cause system crash. */
3593 if(!pDevice->ShuttingDown)
3595 /* Indicate packets to the protocol. */
3596 MM_IndicateTxPackets(pDevice);
3598 /* Indicate received packets to the protocols. */
3599 MM_IndicateRxPackets(pDevice);
3603 /* Move the receive packet descriptors in the ReceivedQ to the */
3607 pPacket = (PLM_PACKET) QQ_PopHead(
3608 &pDevice->RxPacketReceivedQ.Container);
3613 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
3617 /* Clean up the Std Receive Producer ring. */
3618 Idx = pDevice->pStatusBlkVirt->RcvStdConIdx;
3620 while(Idx != pDevice->RxStdProdIdx) {
3621 pPacket = (PLM_PACKET) (MM_UINT_PTR(pDevice->pPacketDescBase) +
3622 MM_UINT_PTR(pDevice->pRxStdBdVirt[Idx].Opaque));
3624 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
3626 Idx = (Idx + 1) & T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
3629 /* Reinitialize our copy of the indices. */
3630 pDevice->RxStdProdIdx = 0;
3632 #if T3_JUMBO_RCV_RCB_ENTRY_COUNT
3633 /* Clean up the Jumbo Receive Producer ring. */
3634 Idx = pDevice->pStatusBlkVirt->RcvJumboConIdx;
3636 while(Idx != pDevice->RxJumboProdIdx) {
3637 pPacket = (PLM_PACKET) (MM_UINT_PTR(pDevice->pPacketDescBase) +
3638 MM_UINT_PTR(pDevice->pRxJumboBdVirt[Idx].Opaque));
3640 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
3642 Idx = (Idx + 1) & T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
3645 /* Reinitialize our copy of the indices. */
3646 pDevice->RxJumboProdIdx = 0;
3647 #endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
3649 MM_RELEASE_INT_LOCK(pDevice);
3651 /* Initialize the statistis Block */
3652 pDevice->pStatusBlkVirt->Status = 0;
3653 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
3654 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
3655 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
3657 return LM_STATUS_SUCCESS;
3661 /******************************************************************************/
3663 /* Disable the interrupt and put the transmitter and receiver engines in */
3664 /* an idle state. Aborts all pending send requests and receive buffers. */
3665 /* Also free all the receive buffers. */
3668 /* LM_STATUS_SUCCESS */
3669 /******************************************************************************/
3672 PLM_DEVICE_BLOCK pDevice) {
3678 /* Get the number of entries in the queue. */
3679 EntryCnt = QQ_GetEntryCnt(&pDevice->RxPacketFreeQ.Container);
3681 /* Make sure all the packets have been accounted for. */
3682 for(EntryCnt = 0; EntryCnt < pDevice->RxPacketDescCnt; EntryCnt++)
3684 pPacket = (PLM_PACKET) QQ_PopHead(&pDevice->RxPacketFreeQ.Container);
3688 MM_FreeRxBuffer(pDevice, pPacket);
3690 QQ_PushTail(&pDevice->RxPacketFreeQ.Container, pPacket);
3693 LM_ResetChip(pDevice);
3695 /* Restore PCI configuration registers. */
3696 MM_WriteConfig32(pDevice, PCI_CACHE_LINE_SIZE_REG,
3697 pDevice->SavedCacheLineReg);
3698 LM_RegWrInd(pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
3699 (pDevice->SubsystemId << 16) | pDevice->SubsystemVendorId);
3701 /* Reprogram the MAC address. */
3702 LM_SetMacAddress(pDevice, pDevice->NodeAddress);
3704 return LM_STATUS_SUCCESS;
3709 LM_ResetChip(PLM_DEVICE_BLOCK pDevice)
3714 /* Wait for access to the nvram interface before resetting. This is */
3715 /* a workaround to prevent EEPROM corruption. */
3716 if(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
3717 T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5701)
3719 /* Request access to the flash interface. */
3720 REG_WR(pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
3722 for(j = 0; j < 100000; j++)
3724 Value32 = REG_RD(pDevice, Nvram.SwArb);
3725 if(Value32 & SW_ARB_GNT1)
3734 REG_WR(pDevice, Grc.MiscCfg, GRC_MISC_CFG_CORE_CLOCK_RESET);
3735 MM_Wait(40); MM_Wait(40); MM_Wait(40);
3737 /* make sure we re-enable indirect accesses */
3738 MM_WriteConfig32(pDevice, T3_PCI_MISC_HOST_CTRL_REG,
3739 pDevice->MiscHostCtrl);
3741 /* Set MAX PCI retry to zero. */
3742 Value32 = T3_PCI_STATE_PCI_ROM_ENABLE | T3_PCI_STATE_PCI_ROM_RETRY_ENABLE;
3743 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0)
3745 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))
3747 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
3750 MM_WriteConfig32(pDevice, T3_PCI_STATE_REG, Value32);
3752 /* Restore PCI command register. */
3753 MM_WriteConfig32(pDevice, PCI_COMMAND_REG,
3754 pDevice->PciCommandStatusWords);
3756 /* Disable PCI-X relaxed ordering bit. */
3757 MM_ReadConfig32(pDevice, PCIX_CAP_REG, &Value32);
3758 Value32 &= ~PCIX_ENABLE_RELAXED_ORDERING;
3759 MM_WriteConfig32(pDevice, PCIX_CAP_REG, Value32);
3761 /* Enable memory arbiter. */
3762 REG_WR(pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
3764 #ifdef BIG_ENDIAN_PCI /* This from jfd */
3765 Value32 = GRC_MODE_WORD_SWAP_DATA|
3766 GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
3768 #ifdef BIG_ENDIAN_HOST
3769 /* Reconfigure the mode register. */
3770 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
3771 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
3772 GRC_MODE_BYTE_SWAP_DATA |
3773 GRC_MODE_WORD_SWAP_DATA;
3775 /* Reconfigure the mode register. */
3776 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
3779 REG_WR(pDevice, Grc.Mode, Value32);
3781 /* Prevent PXE from restarting. */
3782 MEM_WR_OFFSET(pDevice, 0x0b50, T3_MAGIC_NUM);
3784 if(pDevice->EnableTbi) {
3785 pDevice->MacMode = MAC_MODE_PORT_MODE_TBI;
3786 REG_WR(pDevice, MacCtrl.Mode, MAC_MODE_PORT_MODE_TBI);
3789 REG_WR(pDevice, MacCtrl.Mode, 0);
3792 /* Wait for the firmware to finish initialization. */
3793 for(j = 0; j < 100000; j++)
3797 Value32 = MEM_RD_OFFSET(pDevice, 0x0b50);
3798 if(Value32 == ~T3_MAGIC_NUM)
3803 return LM_STATUS_SUCCESS;
3806 /******************************************************************************/
3810 /******************************************************************************/
3811 __inline static void
3812 LM_ServiceTxInterrupt(
3813 PLM_DEVICE_BLOCK pDevice) {
3818 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
3820 /* Get our copy of the consumer index. The buffer descriptors */
3821 /* that are in between the consumer indices are freed. */
3822 SwConIdx = pDevice->SendConIdx;
3824 /* Move the packets from the TxPacketActiveQ that are sent out to */
3825 /* the TxPacketXmittedQ. Packets that are sent use the */
3826 /* descriptors that are between SwConIdx and HwConIdx. */
3827 while(SwConIdx != HwConIdx)
3829 /* Get the packet that was sent from the TxPacketActiveQ. */
3830 pPacket = (PLM_PACKET) QQ_PopHead(
3831 &pDevice->TxPacketActiveQ.Container);
3833 /* Set the return status. */
3834 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3836 /* Put the packet in the TxPacketXmittedQ for indication later. */
3837 QQ_PushTail(&pDevice->TxPacketXmittedQ.Container, pPacket);
3839 /* Move to the next packet's BD. */
3840 SwConIdx = (SwConIdx + pPacket->u.Tx.FragCount) &
3841 T3_SEND_RCB_ENTRY_COUNT_MASK;
3843 /* Update the number of unused BDs. */
3844 atomic_add(pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3846 /* Get the new updated HwConIdx. */
3847 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
3850 /* Save the new SwConIdx. */
3851 pDevice->SendConIdx = SwConIdx;
3853 } /* LM_ServiceTxInterrupt */
3856 /******************************************************************************/
3860 /******************************************************************************/
3861 __inline static void
3862 LM_ServiceRxInterrupt(
3863 PLM_DEVICE_BLOCK pDevice) {
3866 LM_UINT32 HwRcvRetProdIdx;
3867 LM_UINT32 SwRcvRetConIdx;
3869 /* Loop thru the receive return rings for received packets. */
3870 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
3872 SwRcvRetConIdx = pDevice->RcvRetConIdx;
3873 while(SwRcvRetConIdx != HwRcvRetProdIdx)
3875 pRcvBd = &pDevice->pRcvRetBdVirt[SwRcvRetConIdx];
3877 /* Get the received packet descriptor. */
3878 pPacket = (PLM_PACKET) (MM_UINT_PTR(pDevice->pPacketDescBase) +
3879 MM_UINT_PTR(pRcvBd->Opaque));
3881 /* Check the error flag. */
3882 if(pRcvBd->ErrorFlag &&
3883 pRcvBd->ErrorFlag != RCV_BD_ERR_ODD_NIBBLED_RCVD_MII)
3885 pPacket->PacketStatus = LM_STATUS_FAILURE;
3887 pDevice->RxCounters.RxPacketErrCnt++;
3889 if(pRcvBd->ErrorFlag & RCV_BD_ERR_BAD_CRC)
3891 pDevice->RxCounters.RxErrCrcCnt++;
3894 if(pRcvBd->ErrorFlag & RCV_BD_ERR_COLL_DETECT)
3896 pDevice->RxCounters.RxErrCollCnt++;
3899 if(pRcvBd->ErrorFlag & RCV_BD_ERR_LINK_LOST_DURING_PKT)
3901 pDevice->RxCounters.RxErrLinkLostCnt++;
3904 if(pRcvBd->ErrorFlag & RCV_BD_ERR_PHY_DECODE_ERR)
3906 pDevice->RxCounters.RxErrPhyDecodeCnt++;
3909 if(pRcvBd->ErrorFlag & RCV_BD_ERR_ODD_NIBBLED_RCVD_MII)
3911 pDevice->RxCounters.RxErrOddNibbleCnt++;
3914 if(pRcvBd->ErrorFlag & RCV_BD_ERR_MAC_ABORT)
3916 pDevice->RxCounters.RxErrMacAbortCnt++;
3919 if(pRcvBd->ErrorFlag & RCV_BD_ERR_LEN_LT_64)
3921 pDevice->RxCounters.RxErrShortPacketCnt++;
3924 if(pRcvBd->ErrorFlag & RCV_BD_ERR_TRUNC_NO_RESOURCES)
3926 pDevice->RxCounters.RxErrNoResourceCnt++;
3929 if(pRcvBd->ErrorFlag & RCV_BD_ERR_GIANT_FRAME_RCVD)
3931 pDevice->RxCounters.RxErrLargePacketCnt++;
3936 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3937 pPacket->PacketSize = pRcvBd->Len - 4;
3939 pPacket->Flags = pRcvBd->Flags;
3940 if(pRcvBd->Flags & RCV_BD_FLAG_VLAN_TAG)
3942 pPacket->VlanTag = pRcvBd->VlanTag;
3945 pPacket->u.Rx.TcpUdpChecksum = pRcvBd->TcpUdpCksum;
3948 /* Put the packet descriptor containing the received packet */
3949 /* buffer in the RxPacketReceivedQ for indication later. */
3950 QQ_PushTail(&pDevice->RxPacketReceivedQ.Container, pPacket);
3952 /* Go to the next buffer descriptor. */
3953 SwRcvRetConIdx = (SwRcvRetConIdx + 1) &
3954 T3_RCV_RETURN_RCB_ENTRY_COUNT_MASK;
3956 /* Get the updated HwRcvRetProdIdx. */
3957 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
3960 pDevice->RcvRetConIdx = SwRcvRetConIdx;
3962 /* Update the receive return ring consumer index. */
3963 MB_REG_WR(pDevice, Mailbox.RcvRetConIdx[0].Low, SwRcvRetConIdx);
3964 } /* LM_ServiceRxInterrupt */
3967 /******************************************************************************/
3969 /* This is the interrupt event handler routine. It acknowledges all */
3970 /* pending interrupts and process all pending events. */
3973 /* LM_STATUS_SUCCESS */
3974 /******************************************************************************/
3976 LM_ServiceInterrupts(
3977 PLM_DEVICE_BLOCK pDevice)
3980 int ServicePhyInt = FALSE;
3982 /* Setup the phy chip whenever the link status changes. */
3983 if(pDevice->LinkChngMode == T3_LINK_CHNG_MODE_USE_STATUS_REG)
3985 Value32 = REG_RD(pDevice, MacCtrl.Status);
3986 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT)
3988 if (Value32 & MAC_STATUS_MI_INTERRUPT)
3990 ServicePhyInt = TRUE;
3993 else if(Value32 & MAC_STATUS_LINK_STATE_CHANGED)
3995 ServicePhyInt = TRUE;
4000 if(pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_LINK_CHANGED_STATUS)
4002 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED |
4003 (pDevice->pStatusBlkVirt->Status & ~STATUS_BLOCK_LINK_CHANGED_STATUS);
4004 ServicePhyInt = TRUE;
4007 #if INCLUDE_TBI_SUPPORT
4008 if (pDevice->IgnoreTbiLinkChange == TRUE)
4010 ServicePhyInt = FALSE;
4013 if (ServicePhyInt == TRUE)
4015 LM_SetupPhy(pDevice);
4018 /* Service receive and transmit interrupts. */
4019 LM_ServiceRxInterrupt(pDevice);
4020 LM_ServiceTxInterrupt(pDevice);
4022 /* No spinlock for this queue since this routine is serialized. */
4023 if(!QQ_Empty(&pDevice->RxPacketReceivedQ.Container))
4025 /* Indicate receive packets. */
4026 MM_IndicateRxPackets(pDevice);
4027 /* LM_QueueRxPackets(pDevice); */
4030 /* No spinlock for this queue since this routine is serialized. */
4031 if(!QQ_Empty(&pDevice->TxPacketXmittedQ.Container))
4033 MM_IndicateTxPackets(pDevice);
4036 return LM_STATUS_SUCCESS;
4037 } /* LM_ServiceInterrupts */
4040 /******************************************************************************/
4044 /******************************************************************************/
4047 PLM_DEVICE_BLOCK pDevice,
4048 PLM_UINT8 pMcAddress) {
4052 pEntry = pDevice->McTable[0];
4053 for(j = 0; j < pDevice->McEntryCount; j++)
4055 if(IS_ETH_ADDRESS_EQUAL(pEntry, pMcAddress))
4057 /* Found a match, increment the instance count. */
4058 pEntry[LM_MC_INSTANCE_COUNT_INDEX] += 1;
4060 return LM_STATUS_SUCCESS;
4063 pEntry += LM_MC_ENTRY_SIZE;
4066 if(pDevice->McEntryCount >= LM_MAX_MC_TABLE_SIZE)
4068 return LM_STATUS_FAILURE;
4071 pEntry = pDevice->McTable[pDevice->McEntryCount];
4073 COPY_ETH_ADDRESS(pMcAddress, pEntry);
4074 pEntry[LM_MC_INSTANCE_COUNT_INDEX] = 1;
4076 pDevice->McEntryCount++;
4078 LM_SetReceiveMask(pDevice, pDevice->ReceiveMask | LM_ACCEPT_MULTICAST);
4080 return LM_STATUS_SUCCESS;
4081 } /* LM_MulticastAdd */
4084 /******************************************************************************/
4088 /******************************************************************************/
4091 PLM_DEVICE_BLOCK pDevice,
4092 PLM_UINT8 pMcAddress) {
4096 pEntry = pDevice->McTable[0];
4097 for(j = 0; j < pDevice->McEntryCount; j++)
4099 if(IS_ETH_ADDRESS_EQUAL(pEntry, pMcAddress))
4101 /* Found a match, decrement the instance count. */
4102 pEntry[LM_MC_INSTANCE_COUNT_INDEX] -= 1;
4104 /* No more instance left, remove the address from the table. */
4105 /* Move the last entry in the table to the delete slot. */
4106 if(pEntry[LM_MC_INSTANCE_COUNT_INDEX] == 0 &&
4107 pDevice->McEntryCount > 1)
4111 pDevice->McTable[pDevice->McEntryCount-1], pEntry);
4112 pEntry[LM_MC_INSTANCE_COUNT_INDEX] =
4113 pDevice->McTable[pDevice->McEntryCount-1]
4114 [LM_MC_INSTANCE_COUNT_INDEX];
4116 pDevice->McEntryCount--;
4118 /* Update the receive mask if the table is empty. */
4119 if(pDevice->McEntryCount == 0)
4121 LM_SetReceiveMask(pDevice,
4122 pDevice->ReceiveMask & ~LM_ACCEPT_MULTICAST);
4125 return LM_STATUS_SUCCESS;
4128 pEntry += LM_MC_ENTRY_SIZE;
4131 return LM_STATUS_FAILURE;
4132 } /* LM_MulticastDel */
4135 /******************************************************************************/
4139 /******************************************************************************/
4142 PLM_DEVICE_BLOCK pDevice) {
4143 pDevice->McEntryCount = 0;
4145 LM_SetReceiveMask(pDevice, pDevice->ReceiveMask & ~LM_ACCEPT_MULTICAST);
4147 return LM_STATUS_SUCCESS;
4148 } /* LM_MulticastClear */
4151 /******************************************************************************/
4155 /******************************************************************************/
4158 PLM_DEVICE_BLOCK pDevice,
4159 PLM_UINT8 pMacAddress)
4163 for(j = 0; j < 4; j++)
4165 REG_WR(pDevice, MacCtrl.MacAddr[j].High,
4166 (pMacAddress[0] << 8) | pMacAddress[1]);
4167 REG_WR(pDevice, MacCtrl.MacAddr[j].Low,
4168 (pMacAddress[2] << 24) | (pMacAddress[3] << 16) |
4169 (pMacAddress[4] << 8) | pMacAddress[5]);
4172 return LM_STATUS_SUCCESS;
4176 /******************************************************************************/
4178 /* Sets up the default line speed, and duplex modes based on the requested */
4183 /******************************************************************************/
4185 LM_TranslateRequestedMediaType(
4186 LM_REQUESTED_MEDIA_TYPE RequestedMediaType,
4187 PLM_MEDIA_TYPE pMediaType,
4188 PLM_LINE_SPEED pLineSpeed,
4189 PLM_DUPLEX_MODE pDuplexMode) {
4190 *pMediaType = LM_MEDIA_TYPE_AUTO;
4191 *pLineSpeed = LM_LINE_SPEED_UNKNOWN;
4192 *pDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4194 /* determine media type */
4195 switch(RequestedMediaType) {
4196 case LM_REQUESTED_MEDIA_TYPE_BNC:
4197 *pMediaType = LM_MEDIA_TYPE_BNC;
4198 *pLineSpeed = LM_LINE_SPEED_10MBPS;
4199 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4202 case LM_REQUESTED_MEDIA_TYPE_UTP_AUTO:
4203 *pMediaType = LM_MEDIA_TYPE_UTP;
4206 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS:
4207 *pMediaType = LM_MEDIA_TYPE_UTP;
4208 *pLineSpeed = LM_LINE_SPEED_10MBPS;
4209 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4212 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX:
4213 *pMediaType = LM_MEDIA_TYPE_UTP;
4214 *pLineSpeed = LM_LINE_SPEED_10MBPS;
4215 *pDuplexMode = LM_DUPLEX_MODE_FULL;
4218 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS:
4219 *pMediaType = LM_MEDIA_TYPE_UTP;
4220 *pLineSpeed = LM_LINE_SPEED_100MBPS;
4221 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4224 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX:
4225 *pMediaType = LM_MEDIA_TYPE_UTP;
4226 *pLineSpeed = LM_LINE_SPEED_100MBPS;
4227 *pDuplexMode = LM_DUPLEX_MODE_FULL;
4230 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS:
4231 *pMediaType = LM_MEDIA_TYPE_UTP;
4232 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
4233 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4236 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX:
4237 *pMediaType = LM_MEDIA_TYPE_UTP;
4238 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
4239 *pDuplexMode = LM_DUPLEX_MODE_FULL;
4242 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS:
4243 *pMediaType = LM_MEDIA_TYPE_FIBER;
4244 *pLineSpeed = LM_LINE_SPEED_100MBPS;
4245 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4248 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS_FULL_DUPLEX:
4249 *pMediaType = LM_MEDIA_TYPE_FIBER;
4250 *pLineSpeed = LM_LINE_SPEED_100MBPS;
4251 *pDuplexMode = LM_DUPLEX_MODE_FULL;
4254 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS:
4255 *pMediaType = LM_MEDIA_TYPE_FIBER;
4256 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
4257 *pDuplexMode = LM_DUPLEX_MODE_HALF;
4260 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX:
4261 *pMediaType = LM_MEDIA_TYPE_FIBER;
4262 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
4263 *pDuplexMode = LM_DUPLEX_MODE_FULL;
4270 return LM_STATUS_SUCCESS;
4271 } /* LM_TranslateRequestedMediaType */
4273 /******************************************************************************/
4277 /* LM_STATUS_LINK_ACTIVE */
4278 /* LM_STATUS_LINK_DOWN */
4279 /******************************************************************************/
4282 PLM_DEVICE_BLOCK pDevice)
4284 LM_LINE_SPEED CurrentLineSpeed;
4285 LM_DUPLEX_MODE CurrentDuplexMode;
4286 LM_STATUS CurrentLinkStatus;
4290 #if 1 /* jmb: bugfix -- moved here, out of code that sets initial pwr state */
4291 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x2);
4293 if((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID)
4295 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4296 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4298 if(!pDevice->InitDone)
4303 if(!(Value32 & PHY_STATUS_LINK_PASS))
4305 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x0c20);
4307 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
4308 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1804);
4310 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
4311 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1204);
4313 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
4314 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0132);
4316 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
4317 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0232);
4319 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
4320 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
4322 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4323 for(j = 0; j < 1000; j++)
4327 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4328 if(Value32 & PHY_STATUS_LINK_PASS)
4335 if((pDevice->PhyId & PHY_ID_REV_MASK) == PHY_BCM5401_B0_REV)
4337 if(!(Value32 & PHY_STATUS_LINK_PASS) &&
4338 (pDevice->OldLineSpeed == LM_LINE_SPEED_1000MBPS))
4340 LM_WritePhy(pDevice, PHY_CTRL_REG, PHY_CTRL_PHY_RESET);
4341 for(j = 0; j < 100; j++)
4345 LM_ReadPhy(pDevice, PHY_CTRL_REG, &Value32);
4346 if(!(Value32 & PHY_CTRL_PHY_RESET))
4353 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x0c20);
4355 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
4356 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1804);
4358 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
4359 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x1204);
4361 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
4362 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0132);
4364 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
4365 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0232);
4367 LM_WritePhy(pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
4368 LM_WritePhy(pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
4373 else if(pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
4374 pDevice->ChipRevId == T3_CHIP_ID_5701_B0)
4376 /* Bug: 5701 A0, B0 TX CRC workaround. */
4377 LM_WritePhy(pDevice, 0x15, 0x0a75);
4378 LM_WritePhy(pDevice, 0x1c, 0x8c68);
4379 LM_WritePhy(pDevice, 0x1c, 0x8d68);
4380 LM_WritePhy(pDevice, 0x1c, 0x8c68);
4383 /* Acknowledge interrupts. */
4384 LM_ReadPhy(pDevice, BCM540X_INT_STATUS_REG, &Value32);
4385 LM_ReadPhy(pDevice, BCM540X_INT_STATUS_REG, &Value32);
4387 /* Configure the interrupt mask. */
4388 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT)
4390 LM_WritePhy(pDevice, BCM540X_INT_MASK_REG, ~BCM540X_INT_LINK_CHANGE);
4393 /* Configure PHY led mode. */
4394 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701 ||
4395 (T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700))
4397 if(pDevice->LedMode == LED_MODE_THREE_LINK)
4399 LM_WritePhy(pDevice, BCM540X_EXT_CTRL_REG,
4400 BCM540X_EXT_CTRL_LINK3_LED_MODE);
4404 LM_WritePhy(pDevice, BCM540X_EXT_CTRL_REG, 0);
4408 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4410 /* Get current link and duplex mode. */
4411 for(j = 0; j < 100; j++)
4413 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4414 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
4416 if(Value32 & PHY_STATUS_LINK_PASS)
4423 if(Value32 & PHY_STATUS_LINK_PASS)
4426 /* Determine the current line and duplex settings. */
4427 LM_ReadPhy(pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4428 for(j = 0; j < 2000; j++)
4432 LM_ReadPhy(pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4439 switch(Value32 & BCM540X_AUX_SPEED_MASK)
4441 case BCM540X_AUX_10BASET_HD:
4442 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4443 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4446 case BCM540X_AUX_10BASET_FD:
4447 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4448 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4451 case BCM540X_AUX_100BASETX_HD:
4452 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4453 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4456 case BCM540X_AUX_100BASETX_FD:
4457 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4458 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4461 case BCM540X_AUX_100BASET_HD:
4462 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4463 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4466 case BCM540X_AUX_100BASET_FD:
4467 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4468 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4473 CurrentLineSpeed = LM_LINE_SPEED_UNKNOWN;
4474 CurrentDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4478 /* Make sure we are in auto-neg mode. */
4479 for (j = 0; j < 200; j++)
4481 LM_ReadPhy(pDevice, PHY_CTRL_REG, &Value32);
4482 if(Value32 && Value32 != 0x7fff)
4487 if(Value32 == 0 && pDevice->RequestedMediaType ==
4488 LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS)
4496 /* Use the current line settings for "auto" mode. */
4497 if(pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO ||
4498 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_UTP_AUTO)
4500 if(Value32 & PHY_CTRL_AUTO_NEG_ENABLE)
4502 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4504 /* We may be exiting low power mode and the link is in */
4505 /* 10mb. In this case, we need to restart autoneg. */
4506 LM_ReadPhy(pDevice, BCM540X_1000BASET_CTRL_REG, &Value32);
4507 pDevice->advertising1000 = Value32;
4508 /* 5702FE supports 10/100Mb only. */
4509 if(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5703 ||
4510 pDevice->BondId != GRC_MISC_BD_ID_5702FE)
4512 if(!(Value32 & (BCM540X_AN_AD_1000BASET_HALF |
4513 BCM540X_AN_AD_1000BASET_FULL)))
4515 CurrentLinkStatus = LM_STATUS_LINK_SETTING_MISMATCH;
4521 CurrentLinkStatus = LM_STATUS_LINK_SETTING_MISMATCH;
4526 /* Force line settings. */
4527 /* Use the current setting if it matches the user's requested */
4529 LM_ReadPhy(pDevice, PHY_CTRL_REG, &Value32);
4530 if((pDevice->LineSpeed == CurrentLineSpeed) &&
4531 (pDevice->DuplexMode == CurrentDuplexMode))
4533 if ((pDevice->DisableAutoNeg &&
4534 !(Value32 & PHY_CTRL_AUTO_NEG_ENABLE)) ||
4535 (!pDevice->DisableAutoNeg &&
4536 (Value32 & PHY_CTRL_AUTO_NEG_ENABLE)))
4538 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4542 CurrentLinkStatus = LM_STATUS_LINK_SETTING_MISMATCH;
4547 CurrentLinkStatus = LM_STATUS_LINK_SETTING_MISMATCH;
4551 /* Save line settings. */
4552 pDevice->LineSpeed = CurrentLineSpeed;
4553 pDevice->DuplexMode = CurrentDuplexMode;
4554 pDevice->MediaType = LM_MEDIA_TYPE_UTP;
4557 return CurrentLinkStatus;
4558 } /* LM_InitBcm540xPhy */
4560 /******************************************************************************/
4564 /******************************************************************************/
4567 PLM_DEVICE_BLOCK pDevice,
4568 LM_UINT32 LocalPhyAd,
4569 LM_UINT32 RemotePhyAd)
4571 LM_FLOW_CONTROL FlowCap;
4573 /* Resolve flow control. */
4574 FlowCap = LM_FLOW_CONTROL_NONE;
4576 /* See Table 28B-3 of 802.3ab-1999 spec. */
4577 if(pDevice->FlowControlCap & LM_FLOW_CONTROL_AUTO_PAUSE)
4579 if(LocalPhyAd & PHY_AN_AD_PAUSE_CAPABLE)
4581 if(LocalPhyAd & PHY_AN_AD_ASYM_PAUSE)
4583 if(RemotePhyAd & PHY_LINK_PARTNER_PAUSE_CAPABLE)
4585 FlowCap = LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4586 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4588 else if(RemotePhyAd & PHY_LINK_PARTNER_ASYM_PAUSE)
4590 FlowCap = LM_FLOW_CONTROL_RECEIVE_PAUSE;
4595 if(RemotePhyAd & PHY_LINK_PARTNER_PAUSE_CAPABLE)
4597 FlowCap = LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4598 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4602 else if(LocalPhyAd & PHY_AN_AD_ASYM_PAUSE)
4604 if((RemotePhyAd & PHY_LINK_PARTNER_PAUSE_CAPABLE) &&
4605 (RemotePhyAd & PHY_LINK_PARTNER_ASYM_PAUSE))
4607 FlowCap = LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4613 FlowCap = pDevice->FlowControlCap;
4616 /* Enable/disable rx PAUSE. */
4617 pDevice->RxMode &= ~RX_MODE_ENABLE_FLOW_CONTROL;
4618 if(FlowCap & LM_FLOW_CONTROL_RECEIVE_PAUSE &&
4619 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4620 pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE))
4622 pDevice->FlowControl |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
4623 pDevice->RxMode |= RX_MODE_ENABLE_FLOW_CONTROL;
4626 REG_WR(pDevice, MacCtrl.RxMode, pDevice->RxMode);
4628 /* Enable/disable tx PAUSE. */
4629 pDevice->TxMode &= ~TX_MODE_ENABLE_FLOW_CONTROL;
4630 if(FlowCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE &&
4631 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4632 pDevice->FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE))
4634 pDevice->FlowControl |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4635 pDevice->TxMode |= TX_MODE_ENABLE_FLOW_CONTROL;
4638 REG_WR(pDevice, MacCtrl.TxMode, pDevice->TxMode);
4640 return LM_STATUS_SUCCESS;
4644 #if INCLUDE_TBI_SUPPORT
4645 /******************************************************************************/
4649 /******************************************************************************/
4652 PLM_DEVICE_BLOCK pDevice)
4657 Value32 = REG_RD(pDevice, MacCtrl.Status);
4659 /* Reset the SERDES during init and when we have link. */
4660 if(!pDevice->InitDone || Value32 & MAC_STATUS_PCS_SYNCED)
4662 /* Set PLL lock range. */
4663 LM_WritePhy(pDevice, 0x16, 0x8007);
4665 /* Software reset. */
4666 LM_WritePhy(pDevice, 0x00, 0x8000);
4668 /* Wait for reset to complete. */
4669 for(j = 0; j < 500; j++)
4674 /* Config mode; seletct PMA/Ch 1 regs. */
4675 LM_WritePhy(pDevice, 0x10, 0x8411);
4677 /* Enable auto-lock and comdet, select txclk for tx. */
4678 LM_WritePhy(pDevice, 0x11, 0x0a10);
4680 LM_WritePhy(pDevice, 0x18, 0x00a0);
4681 LM_WritePhy(pDevice, 0x16, 0x41ff);
4683 /* Assert and deassert POR. */
4684 LM_WritePhy(pDevice, 0x13, 0x0400);
4686 LM_WritePhy(pDevice, 0x13, 0x0000);
4688 LM_WritePhy(pDevice, 0x11, 0x0a50);
4690 LM_WritePhy(pDevice, 0x11, 0x0a10);
4692 /* Delay for signal to stabilize. */
4693 for(j = 0; j < 15000; j++)
4698 /* Deselect the channel register so we can read the PHY id later. */
4699 LM_WritePhy(pDevice, 0x10, 0x8011);
4702 return LM_STATUS_SUCCESS;
4706 /******************************************************************************/
4710 /******************************************************************************/
4713 PLM_DEVICE_BLOCK pDevice)
4715 LM_STATUS CurrentLinkStatus;
4716 AUTONEG_STATUS AnStatus = 0;
4721 pDevice->MacMode &= ~(MAC_MODE_HALF_DUPLEX | MAC_MODE_PORT_MODE_MASK);
4723 /* Initialize the send_config register. */
4724 REG_WR(pDevice, MacCtrl.TxAutoNeg, 0);
4726 /* Enable TBI and full duplex mode. */
4727 pDevice->MacMode |= MAC_MODE_PORT_MODE_TBI;
4728 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
4730 /* Initialize the BCM8002 SERDES PHY. */
4731 switch(pDevice->PhyId & PHY_ID_MASK)
4733 case PHY_BCM8002_PHY_ID:
4734 LM_InitBcm800xPhy(pDevice);
4741 /* Enable link change interrupt. */
4742 REG_WR(pDevice, MacCtrl.MacEvent, MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
4744 /* Default to link down. */
4745 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4747 /* Get the link status. */
4748 Value32 = REG_RD(pDevice, MacCtrl.Status);
4749 if(Value32 & MAC_STATUS_PCS_SYNCED)
4751 if((pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO) ||
4752 (pDevice->DisableAutoNeg == FALSE))
4754 /* auto-negotiation mode. */
4755 /* Initialize the autoneg default capaiblities. */
4756 AutonegInit(&pDevice->AnInfo);
4758 /* Set the context pointer to point to the main device structure. */
4759 pDevice->AnInfo.pContext = pDevice;
4761 /* Setup flow control advertisement register. */
4762 Value32 = GetPhyAdFlowCntrlSettings(pDevice);
4763 if(Value32 & PHY_AN_AD_PAUSE_CAPABLE)
4765 pDevice->AnInfo.mr_adv_sym_pause = 1;
4769 pDevice->AnInfo.mr_adv_sym_pause = 0;
4772 if(Value32 & PHY_AN_AD_ASYM_PAUSE)
4774 pDevice->AnInfo.mr_adv_asym_pause = 1;
4778 pDevice->AnInfo.mr_adv_asym_pause = 0;
4781 /* Try to autoneg up to six times. */
4782 if (pDevice->IgnoreTbiLinkChange)
4790 for (j = 0; j < Cnt; j++)
4792 REG_WR(pDevice, MacCtrl.TxAutoNeg, 0);
4794 Value32 = pDevice->MacMode & ~MAC_MODE_PORT_MODE_MASK;
4795 REG_WR(pDevice, MacCtrl.Mode, Value32);
4798 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode |
4799 MAC_MODE_SEND_CONFIGS);
4803 pDevice->AnInfo.State = AN_STATE_UNKNOWN;
4804 pDevice->AnInfo.CurrentTime_us = 0;
4806 REG_WR(pDevice, Grc.Timer, 0);
4807 for(k = 0; (pDevice->AnInfo.CurrentTime_us < 75000) &&
4810 AnStatus = Autoneg8023z(&pDevice->AnInfo);
4812 if((AnStatus == AUTONEG_STATUS_DONE) ||
4813 (AnStatus == AUTONEG_STATUS_FAILED))
4818 pDevice->AnInfo.CurrentTime_us = REG_RD(pDevice, Grc.Timer);
4821 if((AnStatus == AUTONEG_STATUS_DONE) ||
4822 (AnStatus == AUTONEG_STATUS_FAILED))
4828 if (!(REG_RD(pDevice, MacCtrl.Status) &
4829 MAC_STATUS_PCS_SYNCED)) {
4835 /* Stop sending configs. */
4836 MM_AnTxIdle(&pDevice->AnInfo);
4838 /* Resolve flow control settings. */
4839 if((AnStatus == AUTONEG_STATUS_DONE) &&
4840 pDevice->AnInfo.mr_an_complete && pDevice->AnInfo.mr_link_ok &&
4841 pDevice->AnInfo.mr_lp_adv_full_duplex)
4843 LM_UINT32 RemotePhyAd;
4844 LM_UINT32 LocalPhyAd;
4847 if(pDevice->AnInfo.mr_adv_sym_pause)
4849 LocalPhyAd |= PHY_AN_AD_PAUSE_CAPABLE;
4852 if(pDevice->AnInfo.mr_adv_asym_pause)
4854 LocalPhyAd |= PHY_AN_AD_ASYM_PAUSE;
4858 if(pDevice->AnInfo.mr_lp_adv_sym_pause)
4860 RemotePhyAd |= PHY_LINK_PARTNER_PAUSE_CAPABLE;
4863 if(pDevice->AnInfo.mr_lp_adv_asym_pause)
4865 RemotePhyAd |= PHY_LINK_PARTNER_ASYM_PAUSE;
4868 LM_SetFlowControl(pDevice, LocalPhyAd, RemotePhyAd);
4870 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4872 for (j = 0; j < 30; j++)
4875 REG_WR(pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4876 MAC_STATUS_CFG_CHANGED);
4878 if ((REG_RD(pDevice, MacCtrl.Status) &
4879 (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED)) == 0)
4882 if (pDevice->PollTbiLink)
4884 Value32 = REG_RD(pDevice, MacCtrl.Status);
4885 if (Value32 & MAC_STATUS_RECEIVING_CFG)
4887 pDevice->IgnoreTbiLinkChange = TRUE;
4891 pDevice->IgnoreTbiLinkChange = FALSE;
4894 Value32 = REG_RD(pDevice, MacCtrl.Status);
4895 if (CurrentLinkStatus == LM_STATUS_LINK_DOWN &&
4896 (Value32 & MAC_STATUS_PCS_SYNCED) &&
4897 ((Value32 & MAC_STATUS_RECEIVING_CFG) == 0))
4899 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4904 /* We are forcing line speed. */
4905 pDevice->FlowControlCap &= ~LM_FLOW_CONTROL_AUTO_PAUSE;
4906 LM_SetFlowControl(pDevice, 0, 0);
4908 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4909 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode |
4910 MAC_MODE_SEND_CONFIGS);
4913 /* Set the link polarity bit. */
4914 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
4915 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
4917 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED |
4918 (pDevice->pStatusBlkVirt->Status & ~STATUS_BLOCK_LINK_CHANGED_STATUS);
4920 for (j = 0; j < 100; j++)
4922 REG_WR(pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4923 MAC_STATUS_CFG_CHANGED);
4925 if ((REG_RD(pDevice, MacCtrl.Status) &
4926 (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED)) == 0)
4930 Value32 = REG_RD(pDevice, MacCtrl.Status);
4931 if((Value32 & MAC_STATUS_PCS_SYNCED) == 0)
4933 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4934 if (pDevice->DisableAutoNeg == FALSE)
4936 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode |
4937 MAC_MODE_SEND_CONFIGS);
4939 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
4943 /* Initialize the current link status. */
4944 if(CurrentLinkStatus == LM_STATUS_LINK_ACTIVE)
4946 pDevice->LineSpeed = LM_LINE_SPEED_1000MBPS;
4947 pDevice->DuplexMode = LM_DUPLEX_MODE_FULL;
4948 REG_WR(pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4949 LED_CTRL_1000MBPS_LED_ON);
4953 pDevice->LineSpeed = LM_LINE_SPEED_UNKNOWN;
4954 pDevice->DuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4955 REG_WR(pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4956 LED_CTRL_OVERRIDE_TRAFFIC_LED);
4959 /* Indicate link status. */
4960 if (pDevice->LinkStatus != CurrentLinkStatus) {
4961 pDevice->LinkStatus = CurrentLinkStatus;
4962 MM_IndicateStatus(pDevice, CurrentLinkStatus);
4965 return LM_STATUS_SUCCESS;
4967 #endif /* INCLUDE_TBI_SUPPORT */
4970 /******************************************************************************/
4974 /******************************************************************************/
4977 PLM_DEVICE_BLOCK pDevice)
4979 LM_STATUS CurrentLinkStatus;
4982 /* Assume there is not link first. */
4983 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4985 /* Disable phy link change attention. */
4986 REG_WR(pDevice, MacCtrl.MacEvent, 0);
4988 /* Clear link change attention. */
4989 REG_WR(pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4990 MAC_STATUS_CFG_CHANGED);
4992 /* Disable auto-polling for the moment. */
4993 pDevice->MiMode = 0xc0000;
4994 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
4997 /* Determine the requested line speed and duplex. */
4998 pDevice->OldLineSpeed = pDevice->LineSpeed;
4999 LM_TranslateRequestedMediaType(pDevice->RequestedMediaType,
5000 &pDevice->MediaType, &pDevice->LineSpeed, &pDevice->DuplexMode);
5002 /* Initialize the phy chip. */
5003 switch(pDevice->PhyId & PHY_ID_MASK)
5005 case PHY_BCM5400_PHY_ID:
5006 case PHY_BCM5401_PHY_ID:
5007 case PHY_BCM5411_PHY_ID:
5008 case PHY_BCM5701_PHY_ID:
5009 case PHY_BCM5703_PHY_ID:
5010 case PHY_BCM5704_PHY_ID:
5011 CurrentLinkStatus = LM_InitBcm540xPhy(pDevice);
5018 if(CurrentLinkStatus == LM_STATUS_LINK_SETTING_MISMATCH)
5020 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
5023 /* Setup flow control. */
5024 pDevice->FlowControl = LM_FLOW_CONTROL_NONE;
5025 if(CurrentLinkStatus == LM_STATUS_LINK_ACTIVE)
5027 LM_FLOW_CONTROL FlowCap; /* Flow control capability. */
5029 FlowCap = LM_FLOW_CONTROL_NONE;
5031 if(pDevice->DuplexMode == LM_DUPLEX_MODE_FULL)
5033 if(pDevice->DisableAutoNeg == FALSE ||
5034 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO ||
5035 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_UTP_AUTO)
5037 LM_UINT32 ExpectedPhyAd;
5038 LM_UINT32 LocalPhyAd;
5039 LM_UINT32 RemotePhyAd;
5041 LM_ReadPhy(pDevice, PHY_AN_AD_REG, &LocalPhyAd);
5042 pDevice->advertising = LocalPhyAd;
5043 LocalPhyAd &= (PHY_AN_AD_ASYM_PAUSE | PHY_AN_AD_PAUSE_CAPABLE);
5045 ExpectedPhyAd = GetPhyAdFlowCntrlSettings(pDevice);
5047 if(LocalPhyAd != ExpectedPhyAd)
5049 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
5053 LM_ReadPhy(pDevice, PHY_LINK_PARTNER_ABILITY_REG,
5056 LM_SetFlowControl(pDevice, LocalPhyAd, RemotePhyAd);
5061 pDevice->FlowControlCap &= ~LM_FLOW_CONTROL_AUTO_PAUSE;
5062 LM_SetFlowControl(pDevice, 0, 0);
5067 if(CurrentLinkStatus == LM_STATUS_LINK_DOWN)
5069 LM_ForceAutoNeg(pDevice, pDevice->RequestedMediaType);
5071 /* If we force line speed, we make get link right away. */
5072 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
5073 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
5074 if(Value32 & PHY_STATUS_LINK_PASS)
5076 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
5080 /* GMII interface. */
5081 pDevice->MacMode &= ~MAC_MODE_PORT_MODE_MASK;
5082 if(CurrentLinkStatus == LM_STATUS_LINK_ACTIVE)
5084 if(pDevice->LineSpeed == LM_LINE_SPEED_100MBPS ||
5085 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS)
5087 pDevice->MacMode |= MAC_MODE_PORT_MODE_MII;
5091 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
5095 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
5098 /* Set the MAC to operate in the appropriate duplex mode. */
5099 pDevice->MacMode &= ~MAC_MODE_HALF_DUPLEX;
5100 if(pDevice->DuplexMode == LM_DUPLEX_MODE_HALF)
5102 pDevice->MacMode |= MAC_MODE_HALF_DUPLEX;
5105 /* Set the link polarity bit. */
5106 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
5107 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
5109 if((pDevice->LedMode == LED_MODE_LINK10) ||
5110 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE &&
5111 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS))
5113 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
5118 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE)
5120 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
5124 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5125 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5127 Value32 = LED_CTRL_PHY_MODE_1;
5131 if(pDevice->LedMode == LED_MODE_OUTPUT)
5133 Value32 = LED_CTRL_PHY_MODE_2;
5137 Value32 = LED_CTRL_PHY_MODE_1;
5140 REG_WR(pDevice, MacCtrl.LedCtrl, Value32);
5143 REG_WR(pDevice, MacCtrl.Mode, pDevice->MacMode);
5145 /* Enable auto polling. */
5146 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
5148 pDevice->MiMode |= MI_MODE_AUTO_POLLING_ENABLE;
5149 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
5152 /* Enable phy link change attention. */
5153 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT)
5155 REG_WR(pDevice, MacCtrl.MacEvent, MAC_EVENT_ENABLE_MI_INTERRUPT);
5159 REG_WR(pDevice, MacCtrl.MacEvent,
5160 MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
5162 if ((T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700) &&
5163 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) &&
5164 (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
5165 (((pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) &&
5166 (pDevice->PciState & T3_PCI_STATE_BUS_SPEED_HIGH)) ||
5167 !(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)))
5170 REG_WR(pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
5171 MAC_STATUS_CFG_CHANGED);
5172 MEM_WR_OFFSET(pDevice, T3_FIRMWARE_MAILBOX,
5173 T3_MAGIC_NUM_DISABLE_DMAW_ON_LINK_CHANGE);
5176 /* Indicate link status. */
5177 if (pDevice->LinkStatus != CurrentLinkStatus) {
5178 pDevice->LinkStatus = CurrentLinkStatus;
5179 MM_IndicateStatus(pDevice, CurrentLinkStatus);
5182 return LM_STATUS_SUCCESS;
5183 } /* LM_SetupCopperPhy */
5185 /******************************************************************************/
5189 /******************************************************************************/
5192 PLM_DEVICE_BLOCK pDevice)
5197 #if INCLUDE_TBI_SUPPORT
5198 if(pDevice->EnableTbi)
5200 LmStatus = LM_SetupFiberPhy(pDevice);
5203 #endif /* INCLUDE_TBI_SUPPORT */
5205 LmStatus = LM_SetupCopperPhy(pDevice);
5207 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0)
5209 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))
5211 Value32 = REG_RD(pDevice, PciCfg.PciState);
5212 REG_WR(pDevice, PciCfg.PciState,
5213 Value32 | T3_PCI_STATE_RETRY_SAME_DMA);
5216 if ((pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
5217 (pDevice->DuplexMode == LM_DUPLEX_MODE_HALF))
5219 REG_WR(pDevice, MacCtrl.TxLengths, 0x26ff);
5223 REG_WR(pDevice, MacCtrl.TxLengths, 0x2620);
5229 /******************************************************************************/
5233 /******************************************************************************/
5236 PLM_DEVICE_BLOCK pDevice,
5238 PLM_UINT32 pData32) {
5242 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
5244 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode &
5245 ~MI_MODE_AUTO_POLLING_ENABLE);
5249 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
5250 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) << MI_COM_FIRST_PHY_REG_ADDR_BIT) |
5251 MI_COM_CMD_READ | MI_COM_START;
5253 REG_WR(pDevice, MacCtrl.MiCom, Value32);
5255 for(j = 0; j < 20; j++)
5259 Value32 = REG_RD(pDevice, MacCtrl.MiCom);
5261 if(!(Value32 & MI_COM_BUSY))
5264 Value32 = REG_RD(pDevice, MacCtrl.MiCom);
5265 Value32 &= MI_COM_PHY_DATA_MASK;
5270 if(Value32 & MI_COM_BUSY)
5277 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
5279 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
5285 /******************************************************************************/
5289 /******************************************************************************/
5292 PLM_DEVICE_BLOCK pDevice,
5298 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
5300 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode &
5301 ~MI_MODE_AUTO_POLLING_ENABLE);
5305 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
5306 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) << MI_COM_FIRST_PHY_REG_ADDR_BIT) |
5307 (Data32 & MI_COM_PHY_DATA_MASK) | MI_COM_CMD_WRITE | MI_COM_START;
5309 REG_WR(pDevice, MacCtrl.MiCom, Value32);
5311 for(j = 0; j < 20; j++)
5315 Value32 = REG_RD(pDevice, MacCtrl.MiCom);
5317 if(!(Value32 & MI_COM_BUSY))
5324 if(pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING)
5326 REG_WR(pDevice, MacCtrl.MiMode, pDevice->MiMode);
5332 /******************************************************************************/
5336 /******************************************************************************/
5339 PLM_DEVICE_BLOCK pDevice,
5340 LM_POWER_STATE PowerLevel) {
5341 LM_UINT32 PmeSupport;
5345 /* make sureindirect accesses are enabled*/
5346 MM_WriteConfig32(pDevice, T3_PCI_MISC_HOST_CTRL_REG, pDevice->MiscHostCtrl);
5348 /* Clear the PME_ASSERT bit and the power state bits. Also enable */
5350 MM_ReadConfig32(pDevice, T3_PCI_PM_STATUS_CTRL_REG, &PmCtrl);
5352 PmCtrl |= T3_PM_PME_ASSERTED;
5353 PmCtrl &= ~T3_PM_POWER_STATE_MASK;
5355 /* Set the appropriate power state. */
5356 if(PowerLevel == LM_POWER_STATE_D0)
5359 /* Bring the card out of low power mode. */
5360 PmCtrl |= T3_PM_POWER_STATE_D0;
5361 MM_WriteConfig32(pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
5363 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
5365 #if 0 /* Bugfix by jmb...can't call WritePhy here because pDevice not fully initialized */
5366 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x02);
5369 return LM_STATUS_SUCCESS;
5371 else if(PowerLevel == LM_POWER_STATE_D1)
5373 PmCtrl |= T3_PM_POWER_STATE_D1;
5375 else if(PowerLevel == LM_POWER_STATE_D2)
5377 PmCtrl |= T3_PM_POWER_STATE_D2;
5379 else if(PowerLevel == LM_POWER_STATE_D3)
5381 PmCtrl |= T3_PM_POWER_STATE_D3;
5385 return LM_STATUS_FAILURE;
5387 PmCtrl |= T3_PM_PME_ENABLE;
5389 /* Mask out all interrupts so LM_SetupPhy won't be called while we are */
5390 /* setting new line speed. */
5391 Value32 = REG_RD(pDevice, PciCfg.MiscHostCtrl);
5392 REG_WR(pDevice, PciCfg.MiscHostCtrl, Value32 | MISC_HOST_CTRL_MASK_PCI_INT);
5394 if(!pDevice->RestoreOnWakeUp)
5396 pDevice->RestoreOnWakeUp = TRUE;
5397 pDevice->WakeUpDisableAutoNeg = pDevice->DisableAutoNeg;
5398 pDevice->WakeUpRequestedMediaType = pDevice->RequestedMediaType;
5401 /* Force auto-negotiation to 10 line speed. */
5402 pDevice->DisableAutoNeg = FALSE;
5403 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
5404 LM_SetupPhy(pDevice);
5406 /* Put the driver in the initial state, and go through the power down */
5410 MM_ReadConfig32(pDevice, T3_PCI_PM_CAP_REG, &PmeSupport);
5412 if (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE)
5416 LM_WritePhy(pDevice, BCM5401_AUX_CTRL, 0x5a);
5420 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5421 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5423 Value32 = LED_CTRL_PHY_MODE_1;
5427 if(pDevice->LedMode == LED_MODE_OUTPUT)
5429 Value32 = LED_CTRL_PHY_MODE_2;
5433 Value32 = LED_CTRL_PHY_MODE_1;
5437 Value32 = MAC_MODE_PORT_MODE_MII;
5438 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700)
5440 if(pDevice->LedMode == LED_MODE_LINK10 ||
5441 pDevice->WolSpeed == WOL_SPEED_10MB)
5443 Value32 |= MAC_MODE_LINK_POLARITY;
5448 Value32 |= MAC_MODE_LINK_POLARITY;
5450 REG_WR(pDevice, MacCtrl.Mode, Value32);
5451 MM_Wait(40); MM_Wait(40); MM_Wait(40);
5453 /* Always enable magic packet wake-up if we have vaux. */
5454 if((PmeSupport & T3_PCI_PM_CAP_PME_D3COLD) &&
5455 (pDevice->WakeUpModeCap & LM_WAKE_UP_MODE_MAGIC_PACKET))
5457 Value32 |= MAC_MODE_DETECT_MAGIC_PACKET_ENABLE;
5460 REG_WR(pDevice, MacCtrl.Mode, Value32);
5462 /* Enable the receiver. */
5463 REG_WR(pDevice, MacCtrl.RxMode, RX_MODE_ENABLE);
5466 /* Disable tx/rx clocks, and seletect an alternate clock. */
5467 if(pDevice->WolSpeed == WOL_SPEED_100MB)
5469 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5470 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5472 Value32 = T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5473 T3_PCI_SELECT_ALTERNATE_CLOCK;
5477 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK;
5479 REG_WR(pDevice, PciCfg.ClockCtrl, Value32);
5483 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5484 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5486 Value32 = T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5487 T3_PCI_SELECT_ALTERNATE_CLOCK | T3_PCI_44MHZ_CORE_CLOCK;
5491 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5492 T3_PCI_44MHZ_CORE_CLOCK;
5495 REG_WR(pDevice, PciCfg.ClockCtrl, Value32);
5499 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5500 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5502 Value32 = T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5503 T3_PCI_44MHZ_CORE_CLOCK;
5507 Value32 = T3_PCI_44MHZ_CORE_CLOCK;
5510 REG_WR(pDevice, PciCfg.ClockCtrl, Value32);
5514 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5515 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5517 Value32 = T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5518 T3_PCI_SELECT_ALTERNATE_CLOCK |
5519 T3_PCI_POWER_DOWN_PCI_PLL133;
5523 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5524 T3_PCI_POWER_DOWN_PCI_PLL133;
5527 REG_WR(pDevice, PciCfg.ClockCtrl, Value32);
5532 if(!pDevice->EepromWp && (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE))
5534 /* Switch adapter to auxilliary power. */
5535 if(T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5536 T3_ASIC_REV(pDevice->ChipRevId) == T3_ASIC_REV_5701)
5538 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5539 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5540 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5541 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5542 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5543 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5544 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5549 /* GPIO0 = 0, GPIO1 = 1, GPIO2 = 1. */
5550 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5551 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5552 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5553 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5554 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5555 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5558 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 1. */
5559 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5560 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5561 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5562 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5563 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5564 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5565 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5568 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5569 REG_WR(pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5570 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5571 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5572 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5573 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5574 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5579 /* Set the phy to low power mode. */
5580 /* Put the the hardware in low power mode. */
5581 MM_WriteConfig32(pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
5583 return LM_STATUS_SUCCESS;
5584 } /* LM_SetPowerState */
5587 /******************************************************************************/
5591 /******************************************************************************/
5593 GetPhyAdFlowCntrlSettings(
5594 PLM_DEVICE_BLOCK pDevice)
5600 /* Auto negotiation flow control only when autonegotiation is enabled. */
5601 if(pDevice->DisableAutoNeg == FALSE ||
5602 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO ||
5603 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_UTP_AUTO)
5605 /* Please refer to Table 28B-3 of the 802.3ab-1999 spec. */
5606 if((pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE) ||
5607 ((pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE) &&
5608 (pDevice->FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE)))
5610 Value32 |= PHY_AN_AD_PAUSE_CAPABLE;
5612 else if(pDevice->FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE)
5614 Value32 |= PHY_AN_AD_ASYM_PAUSE;
5616 else if(pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE)
5618 Value32 |= PHY_AN_AD_PAUSE_CAPABLE | PHY_AN_AD_ASYM_PAUSE;
5626 /******************************************************************************/
5630 /* LM_STATUS_FAILURE */
5631 /* LM_STATUS_SUCCESS */
5633 /******************************************************************************/
5635 LM_ForceAutoNegBcm540xPhy(
5636 PLM_DEVICE_BLOCK pDevice,
5637 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
5639 LM_MEDIA_TYPE MediaType;
5640 LM_LINE_SPEED LineSpeed;
5641 LM_DUPLEX_MODE DuplexMode;
5642 LM_UINT32 NewPhyCtrl;
5646 /* Get the interface type, line speed, and duplex mode. */
5647 LM_TranslateRequestedMediaType(RequestedMediaType, &MediaType, &LineSpeed,
5650 if (pDevice->RestoreOnWakeUp)
5652 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5653 pDevice->advertising1000 = 0;
5654 Value32 = PHY_AN_AD_10BASET_FULL | PHY_AN_AD_10BASET_HALF;
5655 if (pDevice->WolSpeed == WOL_SPEED_100MB)
5657 Value32 |= PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5659 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5660 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
5661 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
5662 pDevice->advertising = Value32;
5664 /* Setup the auto-negotiation advertisement register. */
5665 else if(LineSpeed == LM_LINE_SPEED_UNKNOWN)
5667 /* Setup the 10/100 Mbps auto-negotiation advertisement register. */
5668 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
5669 PHY_AN_AD_10BASET_HALF | PHY_AN_AD_10BASET_FULL |
5670 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5671 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
5673 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
5674 pDevice->advertising = Value32;
5676 /* Advertise 1000Mbps */
5677 Value32 = BCM540X_AN_AD_1000BASET_HALF | BCM540X_AN_AD_1000BASET_FULL;
5679 #if INCLUDE_5701_AX_FIX
5680 /* Bug: workaround for CRC error in gigabit mode when we are in */
5681 /* slave mode. This will force the PHY to operate in */
5683 if(pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
5684 pDevice->ChipRevId == T3_CHIP_ID_5701_B0)
5686 Value32 |= BCM540X_CONFIG_AS_MASTER |
5687 BCM540X_ENABLE_CONFIG_AS_MASTER;
5691 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, Value32);
5692 pDevice->advertising1000 = Value32;
5696 if(LineSpeed == LM_LINE_SPEED_1000MBPS)
5698 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5699 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
5701 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
5702 pDevice->advertising = Value32;
5704 if(DuplexMode != LM_DUPLEX_MODE_FULL)
5706 Value32 = BCM540X_AN_AD_1000BASET_HALF;
5710 Value32 = BCM540X_AN_AD_1000BASET_FULL;
5713 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, Value32);
5714 pDevice->advertising1000 = Value32;
5716 else if(LineSpeed == LM_LINE_SPEED_100MBPS)
5718 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5719 pDevice->advertising1000 = 0;
5721 if(DuplexMode != LM_DUPLEX_MODE_FULL)
5723 Value32 = PHY_AN_AD_100BASETX_HALF;
5727 Value32 = PHY_AN_AD_100BASETX_FULL;
5730 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5731 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
5733 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
5734 pDevice->advertising = Value32;
5736 else if(LineSpeed == LM_LINE_SPEED_10MBPS)
5738 LM_WritePhy(pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5739 pDevice->advertising1000 = 0;
5741 if(DuplexMode != LM_DUPLEX_MODE_FULL)
5743 Value32 = PHY_AN_AD_10BASET_HALF;
5747 Value32 = PHY_AN_AD_10BASET_FULL;
5750 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5751 Value32 |= GetPhyAdFlowCntrlSettings(pDevice);
5753 LM_WritePhy(pDevice, PHY_AN_AD_REG, Value32);
5754 pDevice->advertising = Value32;
5758 /* Force line speed if auto-negotiation is disabled. */
5759 if(pDevice->DisableAutoNeg && LineSpeed != LM_LINE_SPEED_UNKNOWN)
5761 /* This code path is executed only when there is link. */
5762 pDevice->MediaType = MediaType;
5763 pDevice->LineSpeed = LineSpeed;
5764 pDevice->DuplexMode = DuplexMode;
5766 /* Force line seepd. */
5770 case LM_LINE_SPEED_10MBPS:
5771 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_10MBPS;
5773 case LM_LINE_SPEED_100MBPS:
5774 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_100MBPS;
5776 case LM_LINE_SPEED_1000MBPS:
5777 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5780 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5784 if(DuplexMode == LM_DUPLEX_MODE_FULL)
5786 NewPhyCtrl |= PHY_CTRL_FULL_DUPLEX_MODE;
5789 /* Don't do anything if the PHY_CTRL is already what we wanted. */
5790 LM_ReadPhy(pDevice, PHY_CTRL_REG, &Value32);
5791 if(Value32 != NewPhyCtrl)
5793 /* Temporary bring the link down before forcing line speed. */
5794 LM_WritePhy(pDevice, PHY_CTRL_REG, PHY_CTRL_LOOPBACK_MODE);
5796 /* Wait for link to go down. */
5797 for(Cnt = 0; Cnt < 15000; Cnt++)
5801 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
5802 LM_ReadPhy(pDevice, PHY_STATUS_REG, &Value32);
5804 if(!(Value32 & PHY_STATUS_LINK_PASS))
5811 LM_WritePhy(pDevice, PHY_CTRL_REG, NewPhyCtrl);
5817 LM_WritePhy(pDevice, PHY_CTRL_REG, PHY_CTRL_AUTO_NEG_ENABLE |
5818 PHY_CTRL_RESTART_AUTO_NEG);
5821 return LM_STATUS_SUCCESS;
5822 } /* LM_ForceAutoNegBcm540xPhy */
5825 /******************************************************************************/
5829 /******************************************************************************/
5832 PLM_DEVICE_BLOCK pDevice,
5833 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
5837 /* Initialize the phy chip. */
5838 switch(pDevice->PhyId & PHY_ID_MASK)
5840 case PHY_BCM5400_PHY_ID:
5841 case PHY_BCM5401_PHY_ID:
5842 case PHY_BCM5411_PHY_ID:
5843 case PHY_BCM5701_PHY_ID:
5844 case PHY_BCM5703_PHY_ID:
5845 case PHY_BCM5704_PHY_ID:
5846 LmStatus = LM_ForceAutoNegBcm540xPhy(pDevice, RequestedMediaType);
5850 LmStatus = LM_STATUS_FAILURE;
5855 } /* LM_ForceAutoNeg */
5857 /******************************************************************************/
5861 /******************************************************************************/
5862 LM_STATUS LM_LoadFirmware(PLM_DEVICE_BLOCK pDevice,
5863 PT3_FWIMG_INFO pFwImg,
5870 if (LoadCpu & T3_RX_CPU_ID)
5872 if (LM_HaltCpu(pDevice,T3_RX_CPU_ID) != LM_STATUS_SUCCESS)
5874 return LM_STATUS_FAILURE;
5877 /* First of all clear scrach pad memory */
5878 for (i = 0; i < T3_RX_CPU_SPAD_SIZE; i+=4)
5880 LM_RegWrInd(pDevice,T3_RX_CPU_SPAD_ADDR+i,0);
5883 /* Copy code first */
5884 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5885 for (i = 0; i <= pFwImg->Text.Length; i+=4)
5887 LM_RegWrInd(pDevice,address+i,
5888 ((LM_UINT32 *)pFwImg->Text.Buffer)[i/4]);
5891 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5892 for (i = 0; i <= pFwImg->ROnlyData.Length; i+=4)
5894 LM_RegWrInd(pDevice,address+i,
5895 ((LM_UINT32 *)pFwImg->ROnlyData.Buffer)[i/4]);
5898 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5899 for (i= 0; i <= pFwImg->Data.Length; i+=4)
5901 LM_RegWrInd(pDevice,address+i,
5902 ((LM_UINT32 *)pFwImg->Data.Buffer)[i/4]);
5906 if (LoadCpu & T3_TX_CPU_ID)
5908 if (LM_HaltCpu(pDevice,T3_TX_CPU_ID) != LM_STATUS_SUCCESS)
5910 return LM_STATUS_FAILURE;
5913 /* First of all clear scrach pad memory */
5914 for (i = 0; i < T3_TX_CPU_SPAD_SIZE; i+=4)
5916 LM_RegWrInd(pDevice,T3_TX_CPU_SPAD_ADDR+i,0);
5919 /* Copy code first */
5920 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5921 for (i= 0; i <= pFwImg->Text.Length; i+=4)
5923 LM_RegWrInd(pDevice,address+i,
5924 ((LM_UINT32 *)pFwImg->Text.Buffer)[i/4]);
5927 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5928 for (i= 0; i <= pFwImg->ROnlyData.Length; i+=4)
5930 LM_RegWrInd(pDevice,address+i,
5931 ((LM_UINT32 *)pFwImg->ROnlyData.Buffer)[i/4]);
5934 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5935 for (i= 0; i <= pFwImg->Data.Length; i+=4)
5937 LM_RegWrInd(pDevice,address+i,
5938 ((LM_UINT32 *)pFwImg->Data.Buffer)[i/4]);
5942 if (StartCpu & T3_RX_CPU_ID)
5945 REG_WR(pDevice,rxCpu.reg.state, 0xffffffff);
5946 REG_WR(pDevice,rxCpu.reg.PC,pFwImg->StartAddress);
5947 for (i = 0 ; i < 5; i++)
5949 if (pFwImg->StartAddress == REG_RD(pDevice,rxCpu.reg.PC))
5952 REG_WR(pDevice,rxCpu.reg.state, 0xffffffff);
5953 REG_WR(pDevice,rxCpu.reg.mode,CPU_MODE_HALT);
5954 REG_WR(pDevice,rxCpu.reg.PC,pFwImg->StartAddress);
5958 REG_WR(pDevice,rxCpu.reg.state, 0xffffffff);
5959 REG_WR(pDevice,rxCpu.reg.mode, 0);
5962 if (StartCpu & T3_TX_CPU_ID)
5965 REG_WR(pDevice,txCpu.reg.state, 0xffffffff);
5966 REG_WR(pDevice,txCpu.reg.PC,pFwImg->StartAddress);
5967 for (i = 0 ; i < 5; i++)
5969 if (pFwImg->StartAddress == REG_RD(pDevice,txCpu.reg.PC))
5972 REG_WR(pDevice,txCpu.reg.state, 0xffffffff);
5973 REG_WR(pDevice,txCpu.reg.mode,CPU_MODE_HALT);
5974 REG_WR(pDevice,txCpu.reg.PC,pFwImg->StartAddress);
5978 REG_WR(pDevice,txCpu.reg.state, 0xffffffff);
5979 REG_WR(pDevice,txCpu.reg.mode, 0);
5982 return LM_STATUS_SUCCESS;
5985 STATIC LM_STATUS LM_HaltCpu(PLM_DEVICE_BLOCK pDevice,LM_UINT32 cpu_number)
5989 if (cpu_number == T3_RX_CPU_ID)
5991 for (i = 0 ; i < 10000; i++)
5993 REG_WR(pDevice,rxCpu.reg.state, 0xffffffff);
5994 REG_WR(pDevice,rxCpu.reg.mode,CPU_MODE_HALT);
5996 if (REG_RD(pDevice,rxCpu.reg.mode) & CPU_MODE_HALT)
6000 REG_WR(pDevice,rxCpu.reg.state, 0xffffffff);
6001 REG_WR(pDevice,rxCpu.reg.mode,CPU_MODE_HALT);
6006 for (i = 0 ; i < 10000; i++)
6008 REG_WR(pDevice,txCpu.reg.state, 0xffffffff);
6009 REG_WR(pDevice,txCpu.reg.mode,CPU_MODE_HALT);
6011 if (REG_RD(pDevice,txCpu.reg.mode) & CPU_MODE_HALT)
6016 return (( i == 10000) ? LM_STATUS_FAILURE : LM_STATUS_SUCCESS);
6021 LM_BlinkLED(PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlinkDurationSec)
6027 if(BlinkDurationSec == 0)
6031 if(BlinkDurationSec > 120)
6033 BlinkDurationSec = 120;
6036 Oldcfg = REG_RD(pDevice, MacCtrl.LedCtrl);
6037 for(j = 0; j < BlinkDurationSec * 2; j++)
6041 /* Turn on the LEDs. */
6042 REG_WR(pDevice, MacCtrl.LedCtrl,
6043 LED_CTRL_OVERRIDE_LINK_LED |
6044 LED_CTRL_1000MBPS_LED_ON |
6045 LED_CTRL_100MBPS_LED_ON |
6046 LED_CTRL_10MBPS_LED_ON |
6047 LED_CTRL_OVERRIDE_TRAFFIC_LED |
6048 LED_CTRL_BLINK_TRAFFIC_LED |
6049 LED_CTRL_TRAFFIC_LED);
6053 /* Turn off the LEDs. */
6054 REG_WR(pDevice, MacCtrl.LedCtrl,
6055 LED_CTRL_OVERRIDE_LINK_LED |
6056 LED_CTRL_OVERRIDE_TRAFFIC_LED);
6060 current->state = TASK_INTERRUPTIBLE;
6061 if (schedule_timeout(HZ/2) != 0) {
6066 udelay(100000); /* 1s sleep */
6069 REG_WR(pDevice, MacCtrl.LedCtrl, Oldcfg);
6073 int t3_do_dma(PLM_DEVICE_BLOCK pDevice,
6074 LM_PHYSICAL_ADDRESS host_addr_phy, int length,
6077 T3_DMA_DESC dma_desc;
6079 LM_UINT32 dma_desc_addr;
6082 REG_WR(pDevice, BufMgr.Mode, 0);
6083 REG_WR(pDevice, Ftq.Reset, 0);
6085 dma_desc.host_addr.High = host_addr_phy.High;
6086 dma_desc.host_addr.Low = host_addr_phy.Low;
6087 dma_desc.nic_mbuf = 0x2100;
6088 dma_desc.len = length;
6089 dma_desc.flags = 0x00000004; /* Generate Rx-CPU event */
6093 dma_desc.cqid_sqid = (T3_QID_RX_BD_COMP << 8) |
6094 T3_QID_DMA_HIGH_PRI_READ;
6095 REG_WR(pDevice, DmaRead.Mode, DMA_READ_MODE_ENABLE);
6099 dma_desc.cqid_sqid = (T3_QID_RX_DATA_COMP << 8) |
6100 T3_QID_DMA_HIGH_PRI_WRITE;
6101 REG_WR(pDevice, DmaWrite.Mode, DMA_WRITE_MODE_ENABLE);
6104 dma_desc_addr = T3_NIC_DMA_DESC_POOL_ADDR;
6106 /* Writing this DMA descriptor to DMA memory */
6107 for (i = 0; i < sizeof(T3_DMA_DESC); i += 4)
6109 value32 = *((PLM_UINT32) (((PLM_UINT8) &dma_desc) + i));
6110 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_ADDR_REG, dma_desc_addr+i);
6111 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_DATA_REG, cpu_to_le32(value32));
6113 MM_WriteConfig32(pDevice, T3_PCI_MEM_WIN_ADDR_REG, 0);
6116 REG_WR(pDevice, Ftq.DmaHighReadFtqFifoEnqueueDequeue, dma_desc_addr);
6118 REG_WR(pDevice, Ftq.DmaHighWriteFtqFifoEnqueueDequeue, dma_desc_addr);
6120 for (i = 0; i < 40; i++)
6123 value32 = REG_RD(pDevice, Ftq.RcvBdCompFtqFifoEnqueueDequeue);
6125 value32 = REG_RD(pDevice, Ftq.RcvDataCompFtqFifoEnqueueDequeue);
6127 if ((value32 & 0xffff) == dma_desc_addr)
6133 return LM_STATUS_SUCCESS;
6137 LM_DmaTest(PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
6138 LM_PHYSICAL_ADDRESS BufferPhy, LM_UINT32 BufferSize)
6142 int dma_success = 0;
6144 if(T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
6145 T3_ASIC_REV(pDevice->ChipRevId) != T3_ASIC_REV_5701)
6147 return LM_STATUS_SUCCESS;
6149 while (!dma_success)
6151 /* Fill data with incremental patterns */
6152 ptr = (LM_UINT32 *)pBufferVirt;
6153 for (j = 0; j < BufferSize/4; j++)
6156 if (t3_do_dma(pDevice,BufferPhy,BufferSize, 1) == LM_STATUS_FAILURE)
6158 return LM_STATUS_FAILURE;
6162 ptr = (LM_UINT32 *)pBufferVirt;
6163 /* Fill data with zero */
6164 for (j = 0; j < BufferSize/4; j++)
6167 if (t3_do_dma(pDevice,BufferPhy,BufferSize, 0) == LM_STATUS_FAILURE)
6169 return LM_STATUS_FAILURE;
6173 /* Check for data */
6174 ptr = (LM_UINT32 *)pBufferVirt;
6175 for (j = 0; j < BufferSize/4; j++)
6179 if ((pDevice->DmaReadWriteCtrl & DMA_CTRL_WRITE_BOUNDARY_MASK)
6180 == DMA_CTRL_WRITE_BOUNDARY_DISABLE)
6182 pDevice->DmaReadWriteCtrl = (pDevice->DmaReadWriteCtrl &
6183 ~DMA_CTRL_WRITE_BOUNDARY_MASK) |
6184 DMA_CTRL_WRITE_BOUNDARY_16;
6185 REG_WR(pDevice, PciCfg.DmaReadWriteCtrl,
6186 pDevice->DmaReadWriteCtrl);
6191 return LM_STATUS_FAILURE;
6195 if (j == (BufferSize/4))
6198 return LM_STATUS_SUCCESS;
6200 #endif /* CFG_CMD_NET, !CONFIG_NET_MULTI, CONFIG_TIGON3 */