blob: e4e004eed6804dc1d1cf08a42fa37ef1ea7b0385 [file] [log] [blame]
wdenkc6097192002-11-03 00:24:07 +00001/******************************************************************************/
2/* */
3/* Broadcom BCM5700 Linux Network Driver, Copyright (c) 2000 Broadcom */
4/* Corporation. */
5/* All rights reserved. */
6/* */
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. */
10/* */
11/* History: */
12/******************************************************************************/
13#include <common.h>
wdenkc6097192002-11-03 00:24:07 +000014#include <asm/types.h>
Shinya Kuribayashi3b904cc2008-06-09 23:37:44 +090015
wdenkc6097192002-11-03 00:24:07 +000016#ifdef CONFIG_BMW
17#include <mpc824x.h>
18#endif
19#include <malloc.h>
20#include <linux/byteorder/big_endian.h>
wdenk6069ff22003-02-28 00:49:47 +000021#include "bcm570x_mm.h"
wdenkc6097192002-11-03 00:24:07 +000022
23#define EMBEDDED 1
24/******************************************************************************/
25/* Local functions. */
26/******************************************************************************/
27
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070028LM_STATUS LM_Abort (PLM_DEVICE_BLOCK pDevice);
29LM_STATUS LM_QueueRxPackets (PLM_DEVICE_BLOCK pDevice);
wdenkc6097192002-11-03 00:24:07 +000030
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070031static LM_STATUS LM_TranslateRequestedMediaType (LM_REQUESTED_MEDIA_TYPE
32 RequestedMediaType,
33 PLM_MEDIA_TYPE pMediaType,
34 PLM_LINE_SPEED pLineSpeed,
35 PLM_DUPLEX_MODE pDuplexMode);
wdenkc6097192002-11-03 00:24:07 +000036
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070037static LM_STATUS LM_InitBcm540xPhy (PLM_DEVICE_BLOCK pDevice);
wdenkc6097192002-11-03 00:24:07 +000038
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070039__inline static LM_VOID LM_ServiceRxInterrupt (PLM_DEVICE_BLOCK pDevice);
40__inline static LM_VOID LM_ServiceTxInterrupt (PLM_DEVICE_BLOCK pDevice);
wdenkc6097192002-11-03 00:24:07 +000041
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070042static LM_STATUS LM_ForceAutoNegBcm540xPhy (PLM_DEVICE_BLOCK pDevice,
43 LM_REQUESTED_MEDIA_TYPE
44 RequestedMediaType);
45static LM_STATUS LM_ForceAutoNeg (PLM_DEVICE_BLOCK pDevice,
46 LM_REQUESTED_MEDIA_TYPE RequestedMediaType);
47static LM_UINT32 GetPhyAdFlowCntrlSettings (PLM_DEVICE_BLOCK pDevice);
48STATIC LM_STATUS LM_SetFlowControl (PLM_DEVICE_BLOCK pDevice,
49 LM_UINT32 LocalPhyAd,
50 LM_UINT32 RemotePhyAd);
wdenkc6097192002-11-03 00:24:07 +000051#if INCLUDE_TBI_SUPPORT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070052STATIC LM_STATUS LM_SetupFiberPhy (PLM_DEVICE_BLOCK pDevice);
53STATIC LM_STATUS LM_InitBcm800xPhy (PLM_DEVICE_BLOCK pDevice);
wdenkc6097192002-11-03 00:24:07 +000054#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070055STATIC LM_STATUS LM_SetupCopperPhy (PLM_DEVICE_BLOCK pDevice);
56STATIC PLM_ADAPTER_INFO LM_GetAdapterInfoBySsid (LM_UINT16 Svid,
57 LM_UINT16 Ssid);
58STATIC LM_STATUS LM_DmaTest (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
59 LM_PHYSICAL_ADDRESS BufferPhy,
60 LM_UINT32 BufferSize);
61STATIC LM_STATUS LM_HaltCpu (PLM_DEVICE_BLOCK pDevice, LM_UINT32 cpu_number);
62STATIC LM_STATUS LM_ResetChip (PLM_DEVICE_BLOCK pDevice);
63STATIC LM_STATUS LM_Test4GBoundary (PLM_DEVICE_BLOCK pDevice,
64 PLM_PACKET pPacket, PT3_SND_BD pSendBd);
wdenkc6097192002-11-03 00:24:07 +000065
66/******************************************************************************/
67/* External functions. */
68/******************************************************************************/
69
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070070LM_STATUS LM_LoadRlsFirmware (PLM_DEVICE_BLOCK pDevice);
wdenkc6097192002-11-03 00:24:07 +000071
72/******************************************************************************/
73/* Description: */
74/* */
75/* Return: */
76/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070077LM_UINT32 LM_RegRdInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Register)
78{
79 LM_UINT32 Value32;
wdenkc6097192002-11-03 00:24:07 +000080
81#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070082 MM_ACQUIRE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +000083#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070084 MM_WriteConfig32 (pDevice, T3_PCI_REG_ADDR_REG, Register);
85 MM_ReadConfig32 (pDevice, T3_PCI_REG_DATA_REG, &Value32);
wdenkc6097192002-11-03 00:24:07 +000086#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070087 MM_RELEASE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +000088#endif
89
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070090 return Value32;
91} /* LM_RegRdInd */
wdenkc6097192002-11-03 00:24:07 +000092
wdenkc6097192002-11-03 00:24:07 +000093/******************************************************************************/
94/* Description: */
95/* */
96/* Return: */
97/******************************************************************************/
98LM_VOID
Vadim Bendeburyf539edc2007-05-24 15:52:25 -070099LM_RegWrInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Register, LM_UINT32 Value32)
100{
wdenkc6097192002-11-03 00:24:07 +0000101
102#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700103 MM_ACQUIRE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000104#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700105 MM_WriteConfig32 (pDevice, T3_PCI_REG_ADDR_REG, Register);
106 MM_WriteConfig32 (pDevice, T3_PCI_REG_DATA_REG, Value32);
wdenkc6097192002-11-03 00:24:07 +0000107#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700108 MM_RELEASE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000109#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700110} /* LM_RegWrInd */
wdenkc6097192002-11-03 00:24:07 +0000111
wdenkc6097192002-11-03 00:24:07 +0000112/******************************************************************************/
113/* Description: */
114/* */
115/* Return: */
116/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700117LM_UINT32 LM_MemRdInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 MemAddr)
118{
119 LM_UINT32 Value32;
wdenkc6097192002-11-03 00:24:07 +0000120
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700121 MM_ACQUIRE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000122#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700123 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
124 Value32 = REG_RD (pDevice, PciCfg.MemWindowData);
125 /* Value32 = REG_RD(pDevice,uIntMem.Mbuf[(MemAddr & 0x7fff)/4]); */
wdenkc6097192002-11-03 00:24:07 +0000126#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700127 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
128 MM_ReadConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG, &Value32);
wdenkc6097192002-11-03 00:24:07 +0000129#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700130 MM_RELEASE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000131
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700132 return Value32;
133} /* LM_MemRdInd */
wdenkc6097192002-11-03 00:24:07 +0000134
wdenkc6097192002-11-03 00:24:07 +0000135/******************************************************************************/
136/* Description: */
137/* */
138/* Return: */
139/******************************************************************************/
140LM_VOID
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700141LM_MemWrInd (PLM_DEVICE_BLOCK pDevice, LM_UINT32 MemAddr, LM_UINT32 Value32)
142{
143 MM_ACQUIRE_UNDI_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000144#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700145 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, MemAddr);
146 REG_WR (pDevice, uIntMem.Mbuf[(MemAddr & 0x7fff) / 4], Value32);
wdenkc6097192002-11-03 00:24:07 +0000147#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700148 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, MemAddr);
149 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG, Value32);
wdenkc6097192002-11-03 00:24:07 +0000150#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700151 MM_RELEASE_UNDI_LOCK (pDevice);
152} /* LM_MemWrInd */
wdenkc6097192002-11-03 00:24:07 +0000153
wdenkc6097192002-11-03 00:24:07 +0000154/******************************************************************************/
155/* Description: */
156/* */
157/* Return: */
158/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700159LM_STATUS LM_QueueRxPackets (PLM_DEVICE_BLOCK pDevice)
160{
161 LM_STATUS Lmstatus;
162 PLM_PACKET pPacket;
163 PT3_RCV_BD pRcvBd;
164 LM_UINT32 StdBdAdded = 0;
wdenkc6097192002-11-03 00:24:07 +0000165#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700166 LM_UINT32 JumboBdAdded = 0;
167#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +0000168
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700169 Lmstatus = LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +0000170
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700171 pPacket = (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
172 while (pPacket) {
173 switch (pPacket->u.Rx.RcvProdRing) {
wdenkc6097192002-11-03 00:24:07 +0000174#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700175 case T3_JUMBO_RCV_PROD_RING: /* Jumbo Receive Ring. */
176 /* Initialize the buffer descriptor. */
177 pRcvBd =
178 &pDevice->pRxJumboBdVirt[pDevice->RxJumboProdIdx];
179 pRcvBd->Flags =
180 RCV_BD_FLAG_END | RCV_BD_FLAG_JUMBO_RING;
181 pRcvBd->Len = (LM_UINT16) pDevice->RxJumboBufferSize;
wdenkc6097192002-11-03 00:24:07 +0000182
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700183 /* Initialize the receive buffer pointer */
184#if 0 /* Jimmy, deleted in new */
185 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
186 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
wdenkc6097192002-11-03 00:24:07 +0000187#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700188 MM_MapRxDma (pDevice, pPacket, &pRcvBd->HostAddr);
wdenkc6097192002-11-03 00:24:07 +0000189
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700190 /* The opaque field may point to an offset from a fix addr. */
191 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR (pPacket) -
192 MM_UINT_PTR (pDevice->
193 pPacketDescBase));
wdenkc6097192002-11-03 00:24:07 +0000194
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700195 /* Update the producer index. */
196 pDevice->RxJumboProdIdx =
197 (pDevice->RxJumboProdIdx +
198 1) & T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
wdenkc6097192002-11-03 00:24:07 +0000199
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700200 JumboBdAdded++;
wdenk8bde7f72003-06-27 21:31:46 +0000201 break;
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700202#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
203
204 case T3_STD_RCV_PROD_RING: /* Standard Receive Ring. */
205 /* Initialize the buffer descriptor. */
206 pRcvBd = &pDevice->pRxStdBdVirt[pDevice->RxStdProdIdx];
207 pRcvBd->Flags = RCV_BD_FLAG_END;
208 pRcvBd->Len = MAX_STD_RCV_BUFFER_SIZE;
209
210 /* Initialize the receive buffer pointer */
211#if 0 /* Jimmy, deleted in new replaced with MM_MapRxDma */
212 pRcvBd->HostAddr.Low = pPacket->u.Rx.RxBufferPhy.Low;
213 pRcvBd->HostAddr.High = pPacket->u.Rx.RxBufferPhy.High;
214#endif
215 MM_MapRxDma (pDevice, pPacket, &pRcvBd->HostAddr);
216
217 /* The opaque field may point to an offset from a fix addr. */
218 pRcvBd->Opaque = (LM_UINT32) (MM_UINT_PTR (pPacket) -
219 MM_UINT_PTR (pDevice->
220 pPacketDescBase));
221
222 /* Update the producer index. */
223 pDevice->RxStdProdIdx = (pDevice->RxStdProdIdx + 1) &
224 T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
225
226 StdBdAdded++;
227 break;
228
229 case T3_UNKNOWN_RCV_PROD_RING:
230 default:
231 Lmstatus = LM_STATUS_FAILURE;
232 break;
233 } /* switch */
234
235 /* Bail out if there is any error. */
236 if (Lmstatus != LM_STATUS_SUCCESS) {
237 break;
wdenk8bde7f72003-06-27 21:31:46 +0000238 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700239
240 pPacket =
241 (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
242 } /* while */
243
244 wmb ();
245 /* Update the procedure index. */
246 if (StdBdAdded) {
247 MB_REG_WR (pDevice, Mailbox.RcvStdProdIdx.Low,
248 pDevice->RxStdProdIdx);
wdenk8bde7f72003-06-27 21:31:46 +0000249 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700250#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
251 if (JumboBdAdded) {
252 MB_REG_WR (pDevice, Mailbox.RcvJumboProdIdx.Low,
253 pDevice->RxJumboProdIdx);
wdenk8bde7f72003-06-27 21:31:46 +0000254 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700255#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
256
257 return Lmstatus;
258} /* LM_QueueRxPackets */
259
260/******************************************************************************/
261/* Description: */
262/* */
263/* Return: */
264/******************************************************************************/
265STATIC LM_VOID LM_NvramInit (PLM_DEVICE_BLOCK pDevice)
266{
267 LM_UINT32 Value32;
268 LM_UINT32 j;
269
270 /* Intialize clock period and state machine. */
271 Value32 = SEEPROM_ADDR_CLK_PERD (SEEPROM_CLOCK_PERIOD) |
272 SEEPROM_ADDR_FSM_RESET;
273 REG_WR (pDevice, Grc.EepromAddr, Value32);
274
275 for (j = 0; j < 100; j++) {
276 MM_Wait (10);
277 }
278
279 /* Serial eeprom access using the Grc.EepromAddr/EepromData registers. */
280 Value32 = REG_RD (pDevice, Grc.LocalCtrl);
281 REG_WR (pDevice, Grc.LocalCtrl,
282 Value32 | GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM);
283
284 /* Set the 5701 compatibility mode if we are using EEPROM. */
285 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
286 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
287 Value32 = REG_RD (pDevice, Nvram.Config1);
288 if ((Value32 & FLASH_INTERFACE_ENABLE) == 0) {
289 /* Use the new interface to read EEPROM. */
290 Value32 &= ~FLASH_COMPAT_BYPASS;
291
292 REG_WR (pDevice, Nvram.Config1, Value32);
293 }
294 }
295} /* LM_NvRamInit */
296
297/******************************************************************************/
298/* Description: */
299/* */
300/* Return: */
301/******************************************************************************/
302STATIC LM_STATUS
303LM_EepromRead (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 * pData)
304{
305 LM_UINT32 Value32;
306 LM_UINT32 Addr;
307 LM_UINT32 Dev;
308 LM_UINT32 j;
309
310 if (Offset > SEEPROM_CHIP_SIZE) {
311 return LM_STATUS_FAILURE;
312 }
313
314 Dev = Offset / SEEPROM_CHIP_SIZE;
315 Addr = Offset % SEEPROM_CHIP_SIZE;
316
317 Value32 = REG_RD (pDevice, Grc.EepromAddr);
318 Value32 &= ~(SEEPROM_ADDR_ADDRESS_MASK | SEEPROM_ADDR_DEV_ID_MASK |
319 SEEPROM_ADDR_RW_MASK);
320 REG_WR (pDevice, Grc.EepromAddr, Value32 | SEEPROM_ADDR_DEV_ID (Dev) |
321 SEEPROM_ADDR_ADDRESS (Addr) | SEEPROM_ADDR_START |
322 SEEPROM_ADDR_READ);
323
324 for (j = 0; j < 1000; j++) {
325 Value32 = REG_RD (pDevice, Grc.EepromAddr);
326 if (Value32 & SEEPROM_ADDR_COMPLETE) {
327 break;
328 }
329 MM_Wait (10);
330 }
331
332 if (Value32 & SEEPROM_ADDR_COMPLETE) {
333 Value32 = REG_RD (pDevice, Grc.EepromData);
334 *pData = Value32;
335
336 return LM_STATUS_SUCCESS;
337 }
338
339 return LM_STATUS_FAILURE;
340} /* LM_EepromRead */
341
342/******************************************************************************/
343/* Description: */
344/* */
345/* Return: */
346/******************************************************************************/
347STATIC LM_STATUS
348LM_NvramRead (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Offset, LM_UINT32 * pData)
349{
350 LM_UINT32 Value32;
351 LM_STATUS Status;
352 LM_UINT32 j;
353
354 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
355 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
356 Status = LM_EepromRead (pDevice, Offset, pData);
357 } else {
358 /* Determine if we have flash or EEPROM. */
359 Value32 = REG_RD (pDevice, Nvram.Config1);
360 if (Value32 & FLASH_INTERFACE_ENABLE) {
361 if (Value32 & FLASH_SSRAM_BUFFERRED_MODE) {
362 Offset = ((Offset / BUFFERED_FLASH_PAGE_SIZE) <<
363 BUFFERED_FLASH_PAGE_POS) +
364 (Offset % BUFFERED_FLASH_PAGE_SIZE);
365 }
366 }
367
368 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
369 for (j = 0; j < 1000; j++) {
370 if (REG_RD (pDevice, Nvram.SwArb) & SW_ARB_GNT1) {
371 break;
372 }
373 MM_Wait (20);
374 }
375 if (j == 1000) {
376 return LM_STATUS_FAILURE;
377 }
378
379 /* Read from flash or EEPROM with the new 5703/02 interface. */
380 REG_WR (pDevice, Nvram.Addr, Offset & NVRAM_ADDRESS_MASK);
381
382 REG_WR (pDevice, Nvram.Cmd, NVRAM_CMD_RD | NVRAM_CMD_DO_IT |
383 NVRAM_CMD_FIRST | NVRAM_CMD_LAST | NVRAM_CMD_DONE);
384
385 /* Wait for the done bit to clear. */
386 for (j = 0; j < 500; j++) {
387 MM_Wait (10);
388
389 Value32 = REG_RD (pDevice, Nvram.Cmd);
390 if (!(Value32 & NVRAM_CMD_DONE)) {
391 break;
392 }
393 }
394
395 /* Wait for the done bit. */
396 if (!(Value32 & NVRAM_CMD_DONE)) {
397 for (j = 0; j < 500; j++) {
398 MM_Wait (10);
399
400 Value32 = REG_RD (pDevice, Nvram.Cmd);
401 if (Value32 & NVRAM_CMD_DONE) {
402 MM_Wait (10);
403
404 *pData =
405 REG_RD (pDevice, Nvram.ReadData);
406
407 /* Change the endianess. */
408 *pData =
409 ((*pData & 0xff) << 24) |
410 ((*pData & 0xff00) << 8) |
411 ((*pData & 0xff0000) >> 8) |
412 ((*pData >> 24) & 0xff);
413
414 break;
415 }
416 }
417 }
418
419 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_CLR1);
420 if (Value32 & NVRAM_CMD_DONE) {
421 Status = LM_STATUS_SUCCESS;
422 } else {
423 Status = LM_STATUS_FAILURE;
424 }
425 }
426
427 return Status;
428} /* LM_NvramRead */
429
430STATIC void LM_ReadVPD (PLM_DEVICE_BLOCK pDevice)
431{
432 LM_UINT32 Vpd_arr[256 / 4];
433 LM_UINT8 *Vpd = (LM_UINT8 *) & Vpd_arr[0];
434 LM_UINT32 *Vpd_dptr = &Vpd_arr[0];
435 LM_UINT32 Value32;
436 unsigned int j;
437
438 /* Read PN from VPD */
439 for (j = 0; j < 256; j += 4, Vpd_dptr++) {
440 if (LM_NvramRead (pDevice, 0x100 + j, &Value32) !=
441 LM_STATUS_SUCCESS) {
442 printf ("BCM570x: LM_ReadVPD: VPD read failed"
443 " (no EEPROM onboard)\n");
444 return;
445 }
446 *Vpd_dptr = cpu_to_le32 (Value32);
447 }
448 for (j = 0; j < 256;) {
449 unsigned int Vpd_r_len;
450 unsigned int Vpd_r_end;
451
452 if ((Vpd[j] == 0x82) || (Vpd[j] == 0x91)) {
453 j = j + 3 + Vpd[j + 1] + (Vpd[j + 2] << 8);
454 } else if (Vpd[j] == 0x90) {
455 Vpd_r_len = Vpd[j + 1] + (Vpd[j + 2] << 8);
456 j += 3;
457 Vpd_r_end = Vpd_r_len + j;
458 while (j < Vpd_r_end) {
459 if ((Vpd[j] == 'P') && (Vpd[j + 1] == 'N')) {
460 unsigned int len = Vpd[j + 2];
461
462 if (len <= 24) {
463 memcpy (pDevice->PartNo,
464 &Vpd[j + 3], len);
465 }
466 break;
467 } else {
468 if (Vpd[j + 2] == 0) {
469 break;
470 }
471 j = j + Vpd[j + 2];
472 }
473 }
474 break;
475 } else {
476 break;
477 }
478 }
wdenkc6097192002-11-03 00:24:07 +0000479}
480
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700481STATIC void LM_ReadBootCodeVersion (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +0000482{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700483 LM_UINT32 Value32, offset, ver_offset;
484 int i;
wdenkc6097192002-11-03 00:24:07 +0000485
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700486 if (LM_NvramRead (pDevice, 0x0, &Value32) != LM_STATUS_SUCCESS)
wdenk8bde7f72003-06-27 21:31:46 +0000487 return;
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700488 if (Value32 != 0xaa559966)
489 return;
490 if (LM_NvramRead (pDevice, 0xc, &offset) != LM_STATUS_SUCCESS)
491 return;
wdenkc6097192002-11-03 00:24:07 +0000492
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700493 offset = ((offset & 0xff) << 24) | ((offset & 0xff00) << 8) |
494 ((offset & 0xff0000) >> 8) | ((offset >> 24) & 0xff);
495 if (LM_NvramRead (pDevice, offset, &Value32) != LM_STATUS_SUCCESS)
496 return;
497 if ((Value32 == 0x0300000e) &&
498 (LM_NvramRead (pDevice, offset + 4, &Value32) == LM_STATUS_SUCCESS)
499 && (Value32 == 0)) {
wdenkc6097192002-11-03 00:24:07 +0000500
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700501 if (LM_NvramRead (pDevice, offset + 8, &ver_offset) !=
502 LM_STATUS_SUCCESS)
503 return;
504 ver_offset = ((ver_offset & 0xff0000) >> 8) |
505 ((ver_offset >> 24) & 0xff);
506 for (i = 0; i < 16; i += 4) {
507 if (LM_NvramRead
508 (pDevice, offset + ver_offset + i,
509 &Value32) != LM_STATUS_SUCCESS) {
510 return;
511 }
512 *((LM_UINT32 *) & pDevice->BootCodeVer[i]) =
513 cpu_to_le32 (Value32);
514 }
515 } else {
516 char c;
wdenkc6097192002-11-03 00:24:07 +0000517
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700518 if (LM_NvramRead (pDevice, 0x94, &Value32) != LM_STATUS_SUCCESS)
519 return;
520
521 i = 0;
522 c = ((Value32 & 0xff0000) >> 16);
523
524 if (c < 10) {
525 pDevice->BootCodeVer[i++] = c + '0';
526 } else {
527 pDevice->BootCodeVer[i++] = (c / 10) + '0';
528 pDevice->BootCodeVer[i++] = (c % 10) + '0';
529 }
530 pDevice->BootCodeVer[i++] = '.';
531 c = (Value32 & 0xff000000) >> 24;
532 if (c < 10) {
533 pDevice->BootCodeVer[i++] = c + '0';
534 } else {
535 pDevice->BootCodeVer[i++] = (c / 10) + '0';
536 pDevice->BootCodeVer[i++] = (c % 10) + '0';
537 }
538 pDevice->BootCodeVer[i] = 0;
wdenk8bde7f72003-06-27 21:31:46 +0000539 }
wdenkc6097192002-11-03 00:24:07 +0000540}
541
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700542STATIC void LM_GetBusSpeed (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +0000543{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700544 LM_UINT32 PciState = pDevice->PciState;
545 LM_UINT32 ClockCtrl;
546 char *SpeedStr = "";
wdenkc6097192002-11-03 00:24:07 +0000547
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700548 if (PciState & T3_PCI_STATE_32BIT_PCI_BUS) {
549 strcpy (pDevice->BusSpeedStr, "32-bit ");
550 } else {
551 strcpy (pDevice->BusSpeedStr, "64-bit ");
wdenk8bde7f72003-06-27 21:31:46 +0000552 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700553 if (PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) {
554 strcat (pDevice->BusSpeedStr, "PCI ");
555 if (PciState & T3_PCI_STATE_HIGH_BUS_SPEED) {
556 SpeedStr = "66MHz";
557 } else {
558 SpeedStr = "33MHz";
559 }
560 } else {
561 strcat (pDevice->BusSpeedStr, "PCIX ");
562 if (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE) {
563 SpeedStr = "133MHz";
564 } else {
565 ClockCtrl = REG_RD (pDevice, PciCfg.ClockCtrl) & 0x1f;
566 switch (ClockCtrl) {
567 case 0:
568 SpeedStr = "33MHz";
569 break;
570
571 case 2:
572 SpeedStr = "50MHz";
573 break;
574
575 case 4:
576 SpeedStr = "66MHz";
577 break;
578
579 case 6:
580 SpeedStr = "100MHz";
581 break;
582
583 case 7:
584 SpeedStr = "133MHz";
585 break;
586 }
587 }
wdenk8bde7f72003-06-27 21:31:46 +0000588 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700589 strcat (pDevice->BusSpeedStr, SpeedStr);
wdenkc6097192002-11-03 00:24:07 +0000590}
591
592/******************************************************************************/
593/* Description: */
594/* This routine initializes default parameters and reads the PCI */
595/* configurations. */
596/* */
597/* Return: */
598/* LM_STATUS_SUCCESS */
599/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700600LM_STATUS LM_GetAdapterInfo (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +0000601{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700602 PLM_ADAPTER_INFO pAdapterInfo;
603 LM_UINT32 Value32;
604 LM_STATUS Status;
605 LM_UINT32 j;
606 LM_UINT32 EeSigFound;
607 LM_UINT32 EePhyTypeSerdes = 0;
608 LM_UINT32 EePhyLedMode = 0;
609 LM_UINT32 EePhyId = 0;
wdenkc6097192002-11-03 00:24:07 +0000610
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700611 /* Get Device Id and Vendor Id */
612 Status = MM_ReadConfig32 (pDevice, PCI_VENDOR_ID_REG, &Value32);
613 if (Status != LM_STATUS_SUCCESS) {
614 return Status;
615 }
616 pDevice->PciVendorId = (LM_UINT16) Value32;
617 pDevice->PciDeviceId = (LM_UINT16) (Value32 >> 16);
wdenkc6097192002-11-03 00:24:07 +0000618
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700619 /* If we are not getting the write adapter, exit. */
620 if ((Value32 != T3_PCI_ID_BCM5700) &&
621 (Value32 != T3_PCI_ID_BCM5701) &&
622 (Value32 != T3_PCI_ID_BCM5702) &&
623 (Value32 != T3_PCI_ID_BCM5702x) &&
624 (Value32 != T3_PCI_ID_BCM5702FE) &&
625 (Value32 != T3_PCI_ID_BCM5703) &&
626 (Value32 != T3_PCI_ID_BCM5703x) && (Value32 != T3_PCI_ID_BCM5704)) {
627 return LM_STATUS_FAILURE;
628 }
wdenkc6097192002-11-03 00:24:07 +0000629
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700630 Status = MM_ReadConfig32 (pDevice, PCI_REV_ID_REG, &Value32);
631 if (Status != LM_STATUS_SUCCESS) {
632 return Status;
633 }
634 pDevice->PciRevId = (LM_UINT8) Value32;
wdenkc6097192002-11-03 00:24:07 +0000635
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700636 /* Get IRQ. */
637 Status = MM_ReadConfig32 (pDevice, PCI_INT_LINE_REG, &Value32);
638 if (Status != LM_STATUS_SUCCESS) {
639 return Status;
640 }
641 pDevice->Irq = (LM_UINT8) Value32;
wdenkc6097192002-11-03 00:24:07 +0000642
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700643 /* Get interrupt pin. */
644 pDevice->IntPin = (LM_UINT8) (Value32 >> 8);
wdenkc6097192002-11-03 00:24:07 +0000645
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700646 /* Get chip revision id. */
647 Status = MM_ReadConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG, &Value32);
648 pDevice->ChipRevId = Value32 >> 16;
wdenkc6097192002-11-03 00:24:07 +0000649
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700650 /* Get subsystem vendor. */
651 Status =
652 MM_ReadConfig32 (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG, &Value32);
653 if (Status != LM_STATUS_SUCCESS) {
654 return Status;
655 }
656 pDevice->SubsystemVendorId = (LM_UINT16) Value32;
wdenkc6097192002-11-03 00:24:07 +0000657
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700658 /* Get PCI subsystem id. */
659 pDevice->SubsystemId = (LM_UINT16) (Value32 >> 16);
wdenkc6097192002-11-03 00:24:07 +0000660
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700661 /* Get the cache line size. */
662 MM_ReadConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG, &Value32);
663 pDevice->CacheLineSize = (LM_UINT8) Value32;
664 pDevice->SavedCacheLineReg = Value32;
wdenkc6097192002-11-03 00:24:07 +0000665
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700666 if (pDevice->ChipRevId != T3_CHIP_ID_5703_A1 &&
667 pDevice->ChipRevId != T3_CHIP_ID_5703_A2 &&
668 pDevice->ChipRevId != T3_CHIP_ID_5704_A0) {
669 pDevice->UndiFix = FALSE;
670 }
wdenkc6097192002-11-03 00:24:07 +0000671#if !PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700672 pDevice->UndiFix = FALSE;
wdenkc6097192002-11-03 00:24:07 +0000673#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700674 /* Map the memory base to system address space. */
675 if (!pDevice->UndiFix) {
676 Status = MM_MapMemBase (pDevice);
677 if (Status != LM_STATUS_SUCCESS) {
678 return Status;
679 }
680 /* Initialize the memory view pointer. */
681 pDevice->pMemView = (PT3_STD_MEM_MAP) pDevice->pMappedMemBase;
wdenk8bde7f72003-06-27 21:31:46 +0000682 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700683#if PCIX_TARGET_WORKAROUND
684 /* store whether we are in PCI are PCI-X mode */
685 pDevice->EnablePciXFix = FALSE;
686
687 MM_ReadConfig32 (pDevice, T3_PCI_STATE_REG, &Value32);
688 if ((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0) {
689 /* Enable PCI-X workaround only if we are running on 5700 BX. */
690 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
691 pDevice->EnablePciXFix = TRUE;
692 }
693 }
694 if (pDevice->UndiFix) {
695 pDevice->EnablePciXFix = TRUE;
696 }
697#endif
698 /* Bx bug: due to the "byte_enable bug" in PCI-X mode, the power */
699 /* management register may be clobbered which may cause the */
700 /* BCM5700 to go into D3 state. While in this state, we will */
701 /* not have memory mapped register access. As a workaround, we */
702 /* need to restore the device to D0 state. */
703 MM_ReadConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, &Value32);
704 Value32 |= T3_PM_PME_ASSERTED;
705 Value32 &= ~T3_PM_POWER_STATE_MASK;
706 Value32 |= T3_PM_POWER_STATE_D0;
707 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, Value32);
708
709 /* read the current PCI command word */
710 MM_ReadConfig32 (pDevice, PCI_COMMAND_REG, &Value32);
711
712 /* Make sure bus-mastering is enabled. */
713 Value32 |= PCI_BUSMASTER_ENABLE;
wdenkc6097192002-11-03 00:24:07 +0000714
715#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700716 /* if we are in PCI-X mode, also make sure mem-mapping and SERR#/PERR#
717 are enabled */
718 if (pDevice->EnablePciXFix == TRUE) {
719 Value32 |= (PCI_MEM_SPACE_ENABLE | PCI_SYSTEM_ERROR_ENABLE |
720 PCI_PARITY_ERROR_ENABLE);
wdenk8bde7f72003-06-27 21:31:46 +0000721 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700722 if (pDevice->UndiFix) {
723 Value32 &= ~PCI_MEM_SPACE_ENABLE;
724 }
wdenkc6097192002-11-03 00:24:07 +0000725#endif
726
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700727 if (pDevice->EnableMWI) {
728 Value32 |= PCI_MEMORY_WRITE_INVALIDATE;
729 } else {
730 Value32 &= (~PCI_MEMORY_WRITE_INVALIDATE);
731 }
wdenkc6097192002-11-03 00:24:07 +0000732
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700733 /* Error out if mem-mapping is NOT enabled for PCI systems */
734 if (!(Value32 | PCI_MEM_SPACE_ENABLE)) {
735 return LM_STATUS_FAILURE;
736 }
wdenkc6097192002-11-03 00:24:07 +0000737
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700738 /* save the value we are going to write into the PCI command word */
739 pDevice->PciCommandStatusWords = Value32;
wdenkc6097192002-11-03 00:24:07 +0000740
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700741 Status = MM_WriteConfig32 (pDevice, PCI_COMMAND_REG, Value32);
742 if (Status != LM_STATUS_SUCCESS) {
743 return Status;
744 }
wdenkc6097192002-11-03 00:24:07 +0000745
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700746 /* Set power state to D0. */
747 LM_SetPowerState (pDevice, LM_POWER_STATE_D0);
wdenkc6097192002-11-03 00:24:07 +0000748
749#ifdef BIG_ENDIAN_PCI
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700750 pDevice->MiscHostCtrl =
751 MISC_HOST_CTRL_MASK_PCI_INT |
752 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
753 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
754 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
755#else /* No CPU Swap modes for PCI IO */
wdenkc6097192002-11-03 00:24:07 +0000756
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700757 /* Setup the mode registers. */
758 pDevice->MiscHostCtrl =
759 MISC_HOST_CTRL_MASK_PCI_INT |
760 MISC_HOST_CTRL_ENABLE_ENDIAN_WORD_SWAP |
wdenkc6097192002-11-03 00:24:07 +0000761#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700762 MISC_HOST_CTRL_ENABLE_ENDIAN_BYTE_SWAP |
763#endif /* BIG_ENDIAN_HOST */
764 MISC_HOST_CTRL_ENABLE_INDIRECT_ACCESS |
765 MISC_HOST_CTRL_ENABLE_PCI_STATE_REG_RW;
766#endif /* !BIG_ENDIAN_PCI */
wdenkc6097192002-11-03 00:24:07 +0000767
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700768 /* write to PCI misc host ctr first in order to enable indirect accesses */
769 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
770 pDevice->MiscHostCtrl);
wdenkc6097192002-11-03 00:24:07 +0000771
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700772 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl);
wdenkc6097192002-11-03 00:24:07 +0000773
774#ifdef BIG_ENDIAN_PCI
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700775 Value32 = GRC_MODE_WORD_SWAP_DATA | GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
wdenkc6097192002-11-03 00:24:07 +0000776#else
777/* No CPU Swap modes for PCI IO */
778#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700779 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
780 GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
wdenkc6097192002-11-03 00:24:07 +0000781#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700782 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
wdenkc6097192002-11-03 00:24:07 +0000783#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700784#endif /* !BIG_ENDIAN_PCI */
wdenkc6097192002-11-03 00:24:07 +0000785
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700786 REG_WR (pDevice, Grc.Mode, Value32);
wdenkc6097192002-11-03 00:24:07 +0000787
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700788 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
789 REG_WR (pDevice, Grc.LocalCtrl,
790 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
791 GRC_MISC_LOCAL_CTRL_GPIO_OE1);
792 }
793 MM_Wait (40);
wdenkc6097192002-11-03 00:24:07 +0000794
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700795 /* Enable indirect memory access */
796 REG_WR (pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
wdenkc6097192002-11-03 00:24:07 +0000797
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700798 if (REG_RD (pDevice, PciCfg.ClockCtrl) & T3_PCI_44MHZ_CORE_CLOCK) {
799 REG_WR (pDevice, PciCfg.ClockCtrl, T3_PCI_44MHZ_CORE_CLOCK |
800 T3_PCI_SELECT_ALTERNATE_CLOCK);
801 REG_WR (pDevice, PciCfg.ClockCtrl,
802 T3_PCI_SELECT_ALTERNATE_CLOCK);
803 MM_Wait (40); /* required delay is 27usec */
804 }
805 REG_WR (pDevice, PciCfg.ClockCtrl, 0);
806 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, 0);
wdenkc6097192002-11-03 00:24:07 +0000807
808#if PCIX_TARGET_WORKAROUND
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700809 MM_ReadConfig32 (pDevice, T3_PCI_STATE_REG, &Value32);
810 if ((pDevice->EnablePciXFix == FALSE) &&
811 ((Value32 & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) == 0)) {
812 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
813 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
814 pDevice->ChipRevId == T3_CHIP_ID_5701_B2 ||
815 pDevice->ChipRevId == T3_CHIP_ID_5701_B5) {
816 __raw_writel (0,
817 &(pDevice->pMemView->uIntMem.
818 MemBlock32K[0x300]));
819 __raw_writel (0,
820 &(pDevice->pMemView->uIntMem.
821 MemBlock32K[0x301]));
822 __raw_writel (0xffffffff,
823 &(pDevice->pMemView->uIntMem.
824 MemBlock32K[0x301]));
825 if (__raw_readl
826 (&(pDevice->pMemView->uIntMem.MemBlock32K[0x300])))
827 {
828 pDevice->EnablePciXFix = TRUE;
829 }
830 }
wdenk8bde7f72003-06-27 21:31:46 +0000831 }
wdenkc6097192002-11-03 00:24:07 +0000832#endif
833#if 1
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700834 /*
835 * This code was at the beginning of else block below, but that's
836 * a bug if node address in shared memory.
837 */
838 MM_Wait (50);
839 LM_NvramInit (pDevice);
wdenkc6097192002-11-03 00:24:07 +0000840#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700841 /* Get the node address. First try to get in from the shared memory. */
842 /* If the signature is not present, then get it from the NVRAM. */
843 Value32 = MEM_RD_OFFSET (pDevice, T3_MAC_ADDR_HIGH_MAILBOX);
844 if ((Value32 >> 16) == 0x484b) {
wdenkc6097192002-11-03 00:24:07 +0000845
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700846 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 8);
847 pDevice->NodeAddress[1] = (LM_UINT8) Value32;
wdenkc6097192002-11-03 00:24:07 +0000848
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700849 Value32 = MEM_RD_OFFSET (pDevice, T3_MAC_ADDR_LOW_MAILBOX);
wdenkc6097192002-11-03 00:24:07 +0000850
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700851 pDevice->NodeAddress[2] = (LM_UINT8) (Value32 >> 24);
852 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 16);
853 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 8);
854 pDevice->NodeAddress[5] = (LM_UINT8) Value32;
wdenkc6097192002-11-03 00:24:07 +0000855
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700856 Status = LM_STATUS_SUCCESS;
857 } else {
858 Status = LM_NvramRead (pDevice, 0x7c, &Value32);
859 if (Status == LM_STATUS_SUCCESS) {
860 pDevice->NodeAddress[0] = (LM_UINT8) (Value32 >> 16);
861 pDevice->NodeAddress[1] = (LM_UINT8) (Value32 >> 24);
wdenkc6097192002-11-03 00:24:07 +0000862
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700863 Status = LM_NvramRead (pDevice, 0x80, &Value32);
wdenkc6097192002-11-03 00:24:07 +0000864
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700865 pDevice->NodeAddress[2] = (LM_UINT8) Value32;
866 pDevice->NodeAddress[3] = (LM_UINT8) (Value32 >> 8);
867 pDevice->NodeAddress[4] = (LM_UINT8) (Value32 >> 16);
868 pDevice->NodeAddress[5] = (LM_UINT8) (Value32 >> 24);
869 }
wdenk8bde7f72003-06-27 21:31:46 +0000870 }
wdenkc6097192002-11-03 00:24:07 +0000871
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700872 /* Assign a default address. */
873 if (Status != LM_STATUS_SUCCESS) {
wdenkc6097192002-11-03 00:24:07 +0000874#ifndef EMBEDDED
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700875 printk (KERN_ERR
876 "Cannot get MAC addr from NVRAM. Using default.\n");
wdenkc6097192002-11-03 00:24:07 +0000877#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700878 pDevice->NodeAddress[0] = 0x00;
879 pDevice->NodeAddress[1] = 0x10;
880 pDevice->NodeAddress[2] = 0x18;
881 pDevice->NodeAddress[3] = 0x68;
882 pDevice->NodeAddress[4] = 0x61;
883 pDevice->NodeAddress[5] = 0x76;
884 }
wdenkc6097192002-11-03 00:24:07 +0000885
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700886 pDevice->PermanentNodeAddress[0] = pDevice->NodeAddress[0];
887 pDevice->PermanentNodeAddress[1] = pDevice->NodeAddress[1];
888 pDevice->PermanentNodeAddress[2] = pDevice->NodeAddress[2];
889 pDevice->PermanentNodeAddress[3] = pDevice->NodeAddress[3];
890 pDevice->PermanentNodeAddress[4] = pDevice->NodeAddress[4];
891 pDevice->PermanentNodeAddress[5] = pDevice->NodeAddress[5];
wdenkc6097192002-11-03 00:24:07 +0000892
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700893 /* Initialize the default values. */
894 pDevice->NoTxPseudoHdrChksum = FALSE;
895 pDevice->NoRxPseudoHdrChksum = FALSE;
896 pDevice->NicSendBd = FALSE;
897 pDevice->TxPacketDescCnt = DEFAULT_TX_PACKET_DESC_COUNT;
898 pDevice->RxStdDescCnt = DEFAULT_STD_RCV_DESC_COUNT;
899 pDevice->RxCoalescingTicks = DEFAULT_RX_COALESCING_TICKS;
900 pDevice->TxCoalescingTicks = DEFAULT_TX_COALESCING_TICKS;
901 pDevice->RxMaxCoalescedFrames = DEFAULT_RX_MAX_COALESCED_FRAMES;
902 pDevice->TxMaxCoalescedFrames = DEFAULT_TX_MAX_COALESCED_FRAMES;
903 pDevice->RxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
904 pDevice->TxCoalescingTicksDuringInt = BAD_DEFAULT_VALUE;
905 pDevice->RxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
906 pDevice->TxMaxCoalescedFramesDuringInt = BAD_DEFAULT_VALUE;
907 pDevice->StatsCoalescingTicks = DEFAULT_STATS_COALESCING_TICKS;
908 pDevice->EnableMWI = FALSE;
909 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
910 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
911 pDevice->DisableAutoNeg = FALSE;
912 pDevice->PhyIntMode = T3_PHY_INT_MODE_AUTO;
913 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_AUTO;
914 pDevice->LedMode = LED_MODE_AUTO;
915 pDevice->ResetPhyOnInit = TRUE;
916 pDevice->DelayPciGrant = TRUE;
917 pDevice->UseTaggedStatus = FALSE;
918 pDevice->OneDmaAtOnce = BAD_DEFAULT_VALUE;
wdenkc6097192002-11-03 00:24:07 +0000919
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700920 pDevice->DmaMbufLowMark = T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO;
921 pDevice->RxMacMbufLowMark = T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO;
922 pDevice->MbufHighMark = T3_DEF_MBUF_HIGH_WMARK_JUMBO;
wdenkc6097192002-11-03 00:24:07 +0000923
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700924 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_AUTO;
925 pDevice->TaskOffloadCap = LM_TASK_OFFLOAD_NONE;
926 pDevice->FlowControlCap = LM_FLOW_CONTROL_AUTO_PAUSE;
927 pDevice->EnableTbi = FALSE;
wdenkc6097192002-11-03 00:24:07 +0000928#if INCLUDE_TBI_SUPPORT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700929 pDevice->PollTbiLink = BAD_DEFAULT_VALUE;
wdenkc6097192002-11-03 00:24:07 +0000930#endif
931
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700932 switch (T3_ASIC_REV (pDevice->ChipRevId)) {
933 case T3_ASIC_REV_5704:
934 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
935 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE64;
936 break;
937 default:
938 pDevice->MbufBase = T3_NIC_MBUF_POOL_ADDR;
939 pDevice->MbufSize = T3_NIC_MBUF_POOL_SIZE96;
940 break;
941 }
wdenkc6097192002-11-03 00:24:07 +0000942
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700943 pDevice->LinkStatus = LM_STATUS_LINK_DOWN;
944 pDevice->QueueRxPackets = TRUE;
wdenkc6097192002-11-03 00:24:07 +0000945
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700946 pDevice->EnableWireSpeed = TRUE;
wdenkc6097192002-11-03 00:24:07 +0000947
948#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700949 pDevice->RxJumboDescCnt = DEFAULT_JUMBO_RCV_DESC_COUNT;
950#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +0000951
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700952 /* Make this is a known adapter. */
953 pAdapterInfo = LM_GetAdapterInfoBySsid (pDevice->SubsystemVendorId,
954 pDevice->SubsystemId);
wdenkc6097192002-11-03 00:24:07 +0000955
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700956 pDevice->BondId = REG_RD (pDevice, Grc.MiscCfg) & GRC_MISC_BD_ID_MASK;
957 if (pDevice->BondId != GRC_MISC_BD_ID_5700 &&
958 pDevice->BondId != GRC_MISC_BD_ID_5701 &&
959 pDevice->BondId != GRC_MISC_BD_ID_5702FE &&
960 pDevice->BondId != GRC_MISC_BD_ID_5703 &&
961 pDevice->BondId != GRC_MISC_BD_ID_5703S &&
962 pDevice->BondId != GRC_MISC_BD_ID_5704 &&
963 pDevice->BondId != GRC_MISC_BD_ID_5704CIOBE) {
964 return LM_STATUS_UNKNOWN_ADAPTER;
wdenk8bde7f72003-06-27 21:31:46 +0000965 }
wdenkc6097192002-11-03 00:24:07 +0000966
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700967 pDevice->SplitModeEnable = SPLIT_MODE_DISABLE;
968 if ((pDevice->ChipRevId == T3_CHIP_ID_5704_A0) &&
969 (pDevice->BondId == GRC_MISC_BD_ID_5704CIOBE)) {
970 pDevice->SplitModeEnable = SPLIT_MODE_ENABLE;
971 pDevice->SplitModeMaxReq = SPLIT_MODE_5704_MAX_REQ;
972 }
wdenkc6097192002-11-03 00:24:07 +0000973
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700974 /* Get Eeprom info. */
975 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_SIG_ADDR);
976 if (Value32 == T3_NIC_DATA_SIG) {
977 EeSigFound = TRUE;
978 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_NIC_CFG_ADDR);
979
980 /* Determine PHY type. */
981 switch (Value32 & T3_NIC_CFG_PHY_TYPE_MASK) {
982 case T3_NIC_CFG_PHY_TYPE_COPPER:
983 EePhyTypeSerdes = FALSE;
984 break;
985
986 case T3_NIC_CFG_PHY_TYPE_FIBER:
987 EePhyTypeSerdes = TRUE;
988 break;
wdenkc6097192002-11-03 00:24:07 +0000989
wdenk8bde7f72003-06-27 21:31:46 +0000990 default:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700991 EePhyTypeSerdes = FALSE;
992 break;
993 }
wdenkc6097192002-11-03 00:24:07 +0000994
Vadim Bendeburyf539edc2007-05-24 15:52:25 -0700995 /* Determine PHY led mode. */
996 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
997 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
998 switch (Value32 & T3_NIC_CFG_LED_MODE_MASK) {
999 case T3_NIC_CFG_LED_MODE_TRIPLE_SPEED:
1000 EePhyLedMode = LED_MODE_THREE_LINK;
1001 break;
wdenkc6097192002-11-03 00:24:07 +00001002
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001003 case T3_NIC_CFG_LED_MODE_LINK_SPEED:
1004 EePhyLedMode = LED_MODE_LINK10;
1005 break;
1006
1007 default:
1008 EePhyLedMode = LED_MODE_AUTO;
1009 break;
1010 }
1011 } else {
1012 switch (Value32 & T3_NIC_CFG_LED_MODE_MASK) {
1013 case T3_NIC_CFG_LED_MODE_OPEN_DRAIN:
1014 EePhyLedMode = LED_MODE_OPEN_DRAIN;
1015 break;
1016
1017 case T3_NIC_CFG_LED_MODE_OUTPUT:
1018 EePhyLedMode = LED_MODE_OUTPUT;
1019 break;
1020
1021 default:
1022 EePhyLedMode = LED_MODE_AUTO;
1023 break;
1024 }
1025 }
1026 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1027 pDevice->ChipRevId == T3_CHIP_ID_5703_A2) {
1028 /* Enable EEPROM write protection. */
1029 if (Value32 & T3_NIC_EEPROM_WP) {
1030 pDevice->EepromWp = TRUE;
1031 }
1032 }
1033
1034 /* Get the PHY Id. */
1035 Value32 = MEM_RD_OFFSET (pDevice, T3_NIC_DATA_PHY_ID_ADDR);
1036 if (Value32) {
1037 EePhyId = (((Value32 & T3_NIC_PHY_ID1_MASK) >> 16) &
1038 PHY_ID1_OUI_MASK) << 10;
1039
1040 Value32 = Value32 & T3_NIC_PHY_ID2_MASK;
1041
1042 EePhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1043 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 &
1044 PHY_ID2_REV_MASK);
1045 } else {
1046 EePhyId = 0;
1047 }
1048 } else {
1049 EeSigFound = FALSE;
wdenk8bde7f72003-06-27 21:31:46 +00001050 }
wdenkc6097192002-11-03 00:24:07 +00001051
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001052 /* Set the PHY address. */
1053 pDevice->PhyAddr = PHY_DEVICE_ID;
wdenkc6097192002-11-03 00:24:07 +00001054
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001055 /* Disable auto polling. */
1056 pDevice->MiMode = 0xc0000;
1057 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
1058 MM_Wait (40);
wdenkc6097192002-11-03 00:24:07 +00001059
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001060 /* Get the PHY id. */
1061 LM_ReadPhy (pDevice, PHY_ID1_REG, &Value32);
1062 pDevice->PhyId = (Value32 & PHY_ID1_OUI_MASK) << 10;
wdenkc6097192002-11-03 00:24:07 +00001063
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001064 LM_ReadPhy (pDevice, PHY_ID2_REG, &Value32);
1065 pDevice->PhyId |= ((Value32 & PHY_ID2_OUI_MASK) << 16) |
1066 (Value32 & PHY_ID2_MODEL_MASK) | (Value32 & PHY_ID2_REV_MASK);
wdenkc6097192002-11-03 00:24:07 +00001067
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001068 /* Set the EnableTbi flag to false if we have a copper PHY. */
1069 switch (pDevice->PhyId & PHY_ID_MASK) {
wdenk8bde7f72003-06-27 21:31:46 +00001070 case PHY_BCM5400_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001071 pDevice->EnableTbi = FALSE;
1072 break;
wdenkc6097192002-11-03 00:24:07 +00001073
wdenk8bde7f72003-06-27 21:31:46 +00001074 case PHY_BCM5401_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001075 pDevice->EnableTbi = FALSE;
1076 break;
wdenkc6097192002-11-03 00:24:07 +00001077
wdenk8bde7f72003-06-27 21:31:46 +00001078 case PHY_BCM5411_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001079 pDevice->EnableTbi = FALSE;
1080 break;
wdenkc6097192002-11-03 00:24:07 +00001081
wdenk8bde7f72003-06-27 21:31:46 +00001082 case PHY_BCM5701_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001083 pDevice->EnableTbi = FALSE;
1084 break;
wdenkc6097192002-11-03 00:24:07 +00001085
wdenk8bde7f72003-06-27 21:31:46 +00001086 case PHY_BCM5703_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001087 pDevice->EnableTbi = FALSE;
1088 break;
wdenkc6097192002-11-03 00:24:07 +00001089
wdenk8bde7f72003-06-27 21:31:46 +00001090 case PHY_BCM5704_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001091 pDevice->EnableTbi = FALSE;
1092 break;
wdenkc6097192002-11-03 00:24:07 +00001093
wdenk8bde7f72003-06-27 21:31:46 +00001094 case PHY_BCM8002_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001095 pDevice->EnableTbi = TRUE;
1096 break;
wdenkc6097192002-11-03 00:24:07 +00001097
wdenk8bde7f72003-06-27 21:31:46 +00001098 default:
wdenkc6097192002-11-03 00:24:07 +00001099
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001100 if (pAdapterInfo) {
1101 pDevice->PhyId = pAdapterInfo->PhyId;
1102 pDevice->EnableTbi = pAdapterInfo->Serdes;
1103 } else if (EeSigFound) {
1104 pDevice->PhyId = EePhyId;
1105 pDevice->EnableTbi = EePhyTypeSerdes;
wdenk8bde7f72003-06-27 21:31:46 +00001106 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001107 break;
1108 }
wdenkc6097192002-11-03 00:24:07 +00001109
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001110 /* Bail out if we don't know the copper PHY id. */
1111 if (UNKNOWN_PHY_ID (pDevice->PhyId) && !pDevice->EnableTbi) {
1112 return LM_STATUS_FAILURE;
1113 }
1114
1115 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5703) {
1116 if ((pDevice->SavedCacheLineReg & 0xff00) < 0x4000) {
1117 pDevice->SavedCacheLineReg &= 0xffff00ff;
1118 pDevice->SavedCacheLineReg |= 0x4000;
1119 }
1120 }
1121 /* Change driver parameters. */
1122 Status = MM_GetConfig (pDevice);
1123 if (Status != LM_STATUS_SUCCESS) {
1124 return Status;
1125 }
1126#if INCLUDE_5701_AX_FIX
1127 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1128 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
1129 pDevice->ResetPhyOnInit = TRUE;
1130 }
1131#endif
1132
1133 /* Save the current phy link status. */
1134 if (!pDevice->EnableTbi) {
1135 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
1136 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
1137
1138 /* If we don't have link reset the PHY. */
1139 if (!(Value32 & PHY_STATUS_LINK_PASS)
1140 || pDevice->ResetPhyOnInit) {
1141
1142 LM_WritePhy (pDevice, PHY_CTRL_REG, PHY_CTRL_PHY_RESET);
1143
1144 for (j = 0; j < 100; j++) {
1145 MM_Wait (10);
1146
1147 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
1148 if (Value32 && !(Value32 & PHY_CTRL_PHY_RESET)) {
1149 MM_Wait (40);
1150 break;
1151 }
1152 }
wdenkc6097192002-11-03 00:24:07 +00001153
1154#if INCLUDE_5701_AX_FIX
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001155 /* 5701_AX_BX bug: only advertises 10mb speed. */
1156 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1157 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
wdenkc6097192002-11-03 00:24:07 +00001158
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001159 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
1160 PHY_AN_AD_10BASET_HALF |
1161 PHY_AN_AD_10BASET_FULL |
1162 PHY_AN_AD_100BASETX_FULL |
1163 PHY_AN_AD_100BASETX_HALF;
1164 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
1165 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
1166 pDevice->advertising = Value32;
wdenkc6097192002-11-03 00:24:07 +00001167
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001168 Value32 = BCM540X_AN_AD_1000BASET_HALF |
1169 BCM540X_AN_AD_1000BASET_FULL |
1170 BCM540X_CONFIG_AS_MASTER |
1171 BCM540X_ENABLE_CONFIG_AS_MASTER;
1172 LM_WritePhy (pDevice,
1173 BCM540X_1000BASET_CTRL_REG,
1174 Value32);
1175 pDevice->advertising1000 = Value32;
wdenkc6097192002-11-03 00:24:07 +00001176
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001177 LM_WritePhy (pDevice, PHY_CTRL_REG,
1178 PHY_CTRL_AUTO_NEG_ENABLE |
1179 PHY_CTRL_RESTART_AUTO_NEG);
1180 }
wdenkc6097192002-11-03 00:24:07 +00001181#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001182 if (T3_ASIC_REV (pDevice->ChipRevId) ==
1183 T3_ASIC_REV_5703) {
1184 LM_WritePhy (pDevice, 0x18, 0x0c00);
1185 LM_WritePhy (pDevice, 0x17, 0x201f);
1186 LM_WritePhy (pDevice, 0x15, 0x2aaa);
1187 }
1188 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
1189 LM_WritePhy (pDevice, 0x1c, 0x8d68);
1190 LM_WritePhy (pDevice, 0x1c, 0x8d68);
1191 }
1192 /* Enable Ethernet@WireSpeed. */
1193 if (pDevice->EnableWireSpeed) {
1194 LM_WritePhy (pDevice, 0x18, 0x7007);
1195 LM_ReadPhy (pDevice, 0x18, &Value32);
1196 LM_WritePhy (pDevice, 0x18,
1197 Value32 | BIT_15 | BIT_4);
1198 }
1199 }
wdenk8bde7f72003-06-27 21:31:46 +00001200 }
wdenkc6097192002-11-03 00:24:07 +00001201
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001202 /* Turn off tap power management. */
1203 if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID) {
1204 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x0c20);
1205 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
1206 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1804);
1207 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
1208 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1204);
1209 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1210 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0132);
1211 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
1212 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0232);
1213 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
1214 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
wdenkc6097192002-11-03 00:24:07 +00001215
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001216 MM_Wait (40);
1217 }
wdenkc6097192002-11-03 00:24:07 +00001218#if INCLUDE_TBI_SUPPORT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001219 pDevice->IgnoreTbiLinkChange = FALSE;
wdenkc6097192002-11-03 00:24:07 +00001220
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001221 if (pDevice->EnableTbi) {
1222 pDevice->WakeUpModeCap = LM_WAKE_UP_MODE_NONE;
1223 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
1224 if ((pDevice->PollTbiLink == BAD_DEFAULT_VALUE) ||
1225 pDevice->DisableAutoNeg) {
1226 pDevice->PollTbiLink = FALSE;
1227 }
1228 } else {
1229 pDevice->PollTbiLink = FALSE;
wdenk8bde7f72003-06-27 21:31:46 +00001230 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001231#endif /* INCLUDE_TBI_SUPPORT */
wdenkc6097192002-11-03 00:24:07 +00001232
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001233 /* UseTaggedStatus is only valid for 5701 and later. */
1234 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1235 pDevice->UseTaggedStatus = FALSE;
wdenkc6097192002-11-03 00:24:07 +00001236
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001237 pDevice->CoalesceMode = 0;
1238 } else {
1239 pDevice->CoalesceMode =
1240 HOST_COALESCE_CLEAR_TICKS_ON_RX_BD_EVENT |
1241 HOST_COALESCE_CLEAR_TICKS_ON_TX_BD_EVENT;
wdenk8bde7f72003-06-27 21:31:46 +00001242 }
wdenkc6097192002-11-03 00:24:07 +00001243
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001244 /* Set the status block size. */
1245 if (T3_CHIP_REV (pDevice->ChipRevId) != T3_CHIP_REV_5700_AX &&
1246 T3_CHIP_REV (pDevice->ChipRevId) != T3_CHIP_REV_5700_BX) {
1247 pDevice->CoalesceMode |= HOST_COALESCE_32_BYTE_STATUS_MODE;
wdenk8bde7f72003-06-27 21:31:46 +00001248 }
wdenkc6097192002-11-03 00:24:07 +00001249
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001250 /* Check the DURING_INT coalescing ticks parameters. */
1251 if (pDevice->UseTaggedStatus) {
1252 if (pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1253 pDevice->RxCoalescingTicksDuringInt =
1254 DEFAULT_RX_COALESCING_TICKS_DURING_INT;
1255 }
wdenkc6097192002-11-03 00:24:07 +00001256
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001257 if (pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1258 pDevice->TxCoalescingTicksDuringInt =
1259 DEFAULT_TX_COALESCING_TICKS_DURING_INT;
1260 }
wdenkc6097192002-11-03 00:24:07 +00001261
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001262 if (pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1263 pDevice->RxMaxCoalescedFramesDuringInt =
1264 DEFAULT_RX_MAX_COALESCED_FRAMES_DURING_INT;
1265 }
wdenkc6097192002-11-03 00:24:07 +00001266
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001267 if (pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1268 pDevice->TxMaxCoalescedFramesDuringInt =
1269 DEFAULT_TX_MAX_COALESCED_FRAMES_DURING_INT;
1270 }
1271 } else {
1272 if (pDevice->RxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1273 pDevice->RxCoalescingTicksDuringInt = 0;
1274 }
wdenkc6097192002-11-03 00:24:07 +00001275
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001276 if (pDevice->TxCoalescingTicksDuringInt == BAD_DEFAULT_VALUE) {
1277 pDevice->TxCoalescingTicksDuringInt = 0;
1278 }
1279
1280 if (pDevice->RxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1281 pDevice->RxMaxCoalescedFramesDuringInt = 0;
1282 }
1283
1284 if (pDevice->TxMaxCoalescedFramesDuringInt == BAD_DEFAULT_VALUE) {
1285 pDevice->TxMaxCoalescedFramesDuringInt = 0;
1286 }
wdenk8bde7f72003-06-27 21:31:46 +00001287 }
wdenkc6097192002-11-03 00:24:07 +00001288
1289#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001290 if (pDevice->RxMtu <= (MAX_STD_RCV_BUFFER_SIZE - 8 /* CRC */ )) {
1291 pDevice->RxJumboDescCnt = 0;
1292 if (pDevice->RxMtu <= MAX_ETHERNET_PACKET_SIZE_NO_CRC) {
1293 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1294 }
1295 } else {
1296 pDevice->RxJumboBufferSize =
1297 (pDevice->RxMtu + 8 /* CRC + VLAN */ +
1298 COMMON_CACHE_LINE_SIZE - 1) & ~COMMON_CACHE_LINE_MASK;
wdenkc6097192002-11-03 00:24:07 +00001299
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001300 if (pDevice->RxJumboBufferSize > MAX_JUMBO_RCV_BUFFER_SIZE) {
1301 pDevice->RxJumboBufferSize =
1302 DEFAULT_JUMBO_RCV_BUFFER_SIZE;
1303 pDevice->RxMtu =
1304 pDevice->RxJumboBufferSize - 8 /* CRC + VLAN */ ;
1305 }
1306 pDevice->TxMtu = pDevice->RxMtu;
wdenkc6097192002-11-03 00:24:07 +00001307
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001308 }
wdenkc6097192002-11-03 00:24:07 +00001309#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001310 pDevice->RxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
1311#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00001312
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001313 pDevice->RxPacketDescCnt =
wdenkc6097192002-11-03 00:24:07 +00001314#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001315 pDevice->RxJumboDescCnt +
1316#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1317 pDevice->RxStdDescCnt;
wdenkc6097192002-11-03 00:24:07 +00001318
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001319 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_SIZE_NO_CRC) {
1320 pDevice->TxMtu = MAX_ETHERNET_PACKET_SIZE_NO_CRC;
wdenk8bde7f72003-06-27 21:31:46 +00001321 }
wdenkc6097192002-11-03 00:24:07 +00001322
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001323 if (pDevice->TxMtu > MAX_JUMBO_TX_BUFFER_SIZE) {
1324 pDevice->TxMtu = MAX_JUMBO_TX_BUFFER_SIZE;
wdenk8bde7f72003-06-27 21:31:46 +00001325 }
wdenkc6097192002-11-03 00:24:07 +00001326
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001327 /* Configure the proper ways to get link change interrupt. */
1328 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO) {
1329 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1330 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1331 } else {
1332 pDevice->PhyIntMode = T3_PHY_INT_MODE_LINK_READY;
wdenk8bde7f72003-06-27 21:31:46 +00001333 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001334 } else if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
1335 /* Auto-polling does not work on 5700_AX and 5700_BX. */
1336 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1337 pDevice->PhyIntMode = T3_PHY_INT_MODE_MI_INTERRUPT;
1338 }
1339 }
wdenkc6097192002-11-03 00:24:07 +00001340
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001341 /* Determine the method to get link change status. */
1342 if (pDevice->LinkChngMode == T3_LINK_CHNG_MODE_AUTO) {
1343 /* The link status bit in the status block does not work on 5700_AX */
1344 /* and 5700_BX chips. */
1345 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
1346 pDevice->LinkChngMode =
1347 T3_LINK_CHNG_MODE_USE_STATUS_REG;
1348 } else {
1349 pDevice->LinkChngMode =
1350 T3_LINK_CHNG_MODE_USE_STATUS_BLOCK;
1351 }
1352 }
1353
1354 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT ||
1355 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
wdenk8bde7f72003-06-27 21:31:46 +00001356 pDevice->LinkChngMode = T3_LINK_CHNG_MODE_USE_STATUS_REG;
wdenk8bde7f72003-06-27 21:31:46 +00001357 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001358
1359 /* Configure PHY led mode. */
1360 if (pDevice->LedMode == LED_MODE_AUTO) {
1361 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1362 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
1363 if (pDevice->SubsystemVendorId == T3_SVID_DELL) {
1364 pDevice->LedMode = LED_MODE_LINK10;
1365 } else {
1366 pDevice->LedMode = LED_MODE_THREE_LINK;
1367
1368 if (EeSigFound && EePhyLedMode != LED_MODE_AUTO) {
1369 pDevice->LedMode = EePhyLedMode;
1370 }
1371 }
1372
1373 /* bug? 5701 in LINK10 mode does not seem to work when */
1374 /* PhyIntMode is LINK_READY. */
1375 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700
1376 &&
1377#if INCLUDE_TBI_SUPPORT
1378 pDevice->EnableTbi == FALSE &&
1379#endif
1380 pDevice->LedMode == LED_MODE_LINK10) {
1381 pDevice->PhyIntMode =
1382 T3_PHY_INT_MODE_MI_INTERRUPT;
1383 pDevice->LinkChngMode =
1384 T3_LINK_CHNG_MODE_USE_STATUS_REG;
1385 }
1386
1387 if (pDevice->EnableTbi) {
1388 pDevice->LedMode = LED_MODE_THREE_LINK;
1389 }
1390 } else {
1391 if (EeSigFound && EePhyLedMode != LED_MODE_AUTO) {
1392 pDevice->LedMode = EePhyLedMode;
1393 } else {
1394 pDevice->LedMode = LED_MODE_OPEN_DRAIN;
1395 }
1396 }
wdenk8bde7f72003-06-27 21:31:46 +00001397 }
wdenkc6097192002-11-03 00:24:07 +00001398
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001399 /* Enable OneDmaAtOnce. */
1400 if (pDevice->OneDmaAtOnce == BAD_DEFAULT_VALUE) {
1401 pDevice->OneDmaAtOnce = FALSE;
1402 }
wdenkc6097192002-11-03 00:24:07 +00001403
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001404 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
1405 pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
1406 pDevice->ChipRevId == T3_CHIP_ID_5701_B0 ||
1407 pDevice->ChipRevId == T3_CHIP_ID_5701_B2) {
1408 pDevice->WolSpeed = WOL_SPEED_10MB;
1409 } else {
1410 pDevice->WolSpeed = WOL_SPEED_100MB;
1411 }
wdenkc6097192002-11-03 00:24:07 +00001412
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001413 /* Offloadings. */
1414 pDevice->TaskToOffload = LM_TASK_OFFLOAD_NONE;
wdenkc6097192002-11-03 00:24:07 +00001415
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001416 /* Turn off task offloading on Ax. */
1417 if (pDevice->ChipRevId == T3_CHIP_ID_5700_B0) {
1418 pDevice->TaskOffloadCap &= ~(LM_TASK_OFFLOAD_TX_TCP_CHECKSUM |
1419 LM_TASK_OFFLOAD_TX_UDP_CHECKSUM);
1420 }
1421 pDevice->PciState = REG_RD (pDevice, PciCfg.PciState);
1422 LM_ReadVPD (pDevice);
1423 LM_ReadBootCodeVersion (pDevice);
1424 LM_GetBusSpeed (pDevice);
wdenkc6097192002-11-03 00:24:07 +00001425
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001426 return LM_STATUS_SUCCESS;
1427} /* LM_GetAdapterInfo */
wdenkc6097192002-11-03 00:24:07 +00001428
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001429STATIC PLM_ADAPTER_INFO LM_GetAdapterInfoBySsid (LM_UINT16 Svid, LM_UINT16 Ssid)
wdenkc6097192002-11-03 00:24:07 +00001430{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001431 static LM_ADAPTER_INFO AdapterArr[] = {
1432 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A6,
1433 PHY_BCM5401_PHY_ID, 0},
1434 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A5,
1435 PHY_BCM5701_PHY_ID, 0},
1436 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700T6,
1437 PHY_BCM8002_PHY_ID, 1},
1438 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95700A9, 0, 1},
1439 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T1,
1440 PHY_BCM5701_PHY_ID, 0},
1441 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701T8,
1442 PHY_BCM5701_PHY_ID, 0},
1443 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A7, 0, 1},
1444 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A10,
1445 PHY_BCM5701_PHY_ID, 0},
1446 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95701A12,
1447 PHY_BCM5701_PHY_ID, 0},
1448 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax1,
1449 PHY_BCM5701_PHY_ID, 0},
1450 {T3_SVID_BROADCOM, T3_SSID_BROADCOM_BCM95703Ax2,
1451 PHY_BCM5701_PHY_ID, 0},
wdenkc6097192002-11-03 00:24:07 +00001452
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001453 {T3_SVID_3COM, T3_SSID_3COM_3C996T, PHY_BCM5401_PHY_ID, 0},
1454 {T3_SVID_3COM, T3_SSID_3COM_3C996BT, PHY_BCM5701_PHY_ID, 0},
1455 {T3_SVID_3COM, T3_SSID_3COM_3C996SX, 0, 1},
1456 {T3_SVID_3COM, T3_SSID_3COM_3C1000T, PHY_BCM5701_PHY_ID, 0},
1457 {T3_SVID_3COM, T3_SSID_3COM_3C940BR01, PHY_BCM5701_PHY_ID, 0},
wdenkc6097192002-11-03 00:24:07 +00001458
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001459 {T3_SVID_DELL, T3_SSID_DELL_VIPER, PHY_BCM5401_PHY_ID, 0},
1460 {T3_SVID_DELL, T3_SSID_DELL_JAGUAR, PHY_BCM5401_PHY_ID, 0},
1461 {T3_SVID_DELL, T3_SSID_DELL_MERLOT, PHY_BCM5411_PHY_ID, 0},
1462 {T3_SVID_DELL, T3_SSID_DELL_SLIM_MERLOT, PHY_BCM5411_PHY_ID, 0},
wdenkc6097192002-11-03 00:24:07 +00001463
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001464 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE, PHY_BCM5701_PHY_ID, 0},
1465 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_BANSHEE_2, PHY_BCM5701_PHY_ID,
1466 0},
1467 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_CHANGELING, 0, 1},
1468 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780, PHY_BCM5701_PHY_ID, 0},
1469 {T3_SVID_COMPAQ, T3_SSID_COMPAQ_NC7780_2, PHY_BCM5701_PHY_ID,
1470 0},
wdenkc6097192002-11-03 00:24:07 +00001471
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001472 };
1473 LM_UINT32 j;
wdenkc6097192002-11-03 00:24:07 +00001474
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001475 for (j = 0; j < sizeof (AdapterArr) / sizeof (LM_ADAPTER_INFO); j++) {
1476 if (AdapterArr[j].Svid == Svid && AdapterArr[j].Ssid == Ssid) {
1477 return &AdapterArr[j];
1478 }
wdenk8bde7f72003-06-27 21:31:46 +00001479 }
wdenkc6097192002-11-03 00:24:07 +00001480
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001481 return NULL;
wdenkc6097192002-11-03 00:24:07 +00001482}
1483
wdenkc6097192002-11-03 00:24:07 +00001484/******************************************************************************/
1485/* Description: */
1486/* This routine sets up receive/transmit buffer descriptions queues. */
1487/* */
1488/* Return: */
1489/* LM_STATUS_SUCCESS */
1490/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001491LM_STATUS LM_InitializeAdapter (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00001492{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001493 LM_PHYSICAL_ADDRESS MemPhy;
1494 PLM_UINT8 pMemVirt;
1495 PLM_PACKET pPacket;
1496 LM_STATUS Status;
1497 LM_UINT32 Size;
1498 LM_UINT32 j;
wdenkc6097192002-11-03 00:24:07 +00001499
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001500 /* Set power state to D0. */
1501 LM_SetPowerState (pDevice, LM_POWER_STATE_D0);
wdenkc6097192002-11-03 00:24:07 +00001502
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001503 /* Intialize the queues. */
1504 QQ_InitQueue (&pDevice->RxPacketReceivedQ.Container,
1505 MAX_RX_PACKET_DESC_COUNT);
1506 QQ_InitQueue (&pDevice->RxPacketFreeQ.Container,
1507 MAX_RX_PACKET_DESC_COUNT);
wdenkc6097192002-11-03 00:24:07 +00001508
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001509 QQ_InitQueue (&pDevice->TxPacketFreeQ.Container,
1510 MAX_TX_PACKET_DESC_COUNT);
1511 QQ_InitQueue (&pDevice->TxPacketActiveQ.Container,
1512 MAX_TX_PACKET_DESC_COUNT);
1513 QQ_InitQueue (&pDevice->TxPacketXmittedQ.Container,
1514 MAX_TX_PACKET_DESC_COUNT);
wdenkc6097192002-11-03 00:24:07 +00001515
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001516 /* Allocate shared memory for: status block, the buffers for receive */
1517 /* rings -- standard, mini, jumbo, and return rings. */
1518 Size = T3_STATUS_BLOCK_SIZE + sizeof (T3_STATS_BLOCK) +
1519 T3_STD_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD) +
wdenkc6097192002-11-03 00:24:07 +00001520#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001521 T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD) +
1522#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
1523 T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
wdenkc6097192002-11-03 00:24:07 +00001524
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001525 /* Memory for host based Send BD. */
1526 if (pDevice->NicSendBd == FALSE) {
1527 Size += sizeof (T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
wdenk8bde7f72003-06-27 21:31:46 +00001528 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001529
1530 /* Allocate the memory block. */
1531 Status =
1532 MM_AllocateSharedMemory (pDevice, Size, (PLM_VOID) & pMemVirt,
1533 &MemPhy, FALSE);
1534 if (Status != LM_STATUS_SUCCESS) {
1535 return Status;
wdenk8bde7f72003-06-27 21:31:46 +00001536 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001537
1538 /* Program DMA Read/Write */
1539 if (pDevice->PciState & T3_PCI_STATE_NOT_PCI_X_BUS) {
1540 pDevice->DmaReadWriteCtrl = 0x763f000f;
1541 } else {
1542 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5704) {
1543 pDevice->DmaReadWriteCtrl = 0x761f0000;
1544 } else {
1545 pDevice->DmaReadWriteCtrl = 0x761b000f;
1546 }
1547 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1 ||
1548 pDevice->ChipRevId == T3_CHIP_ID_5703_A2) {
1549 pDevice->OneDmaAtOnce = TRUE;
1550 }
wdenk8bde7f72003-06-27 21:31:46 +00001551 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001552 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5703) {
1553 pDevice->DmaReadWriteCtrl &= 0xfffffff0;
1554 }
wdenkc6097192002-11-03 00:24:07 +00001555
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001556 if (pDevice->OneDmaAtOnce) {
1557 pDevice->DmaReadWriteCtrl |= DMA_CTRL_WRITE_ONE_DMA_AT_ONCE;
1558 }
1559 REG_WR (pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
wdenkc6097192002-11-03 00:24:07 +00001560
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001561 if (LM_DmaTest (pDevice, pMemVirt, MemPhy, 0x400) != LM_STATUS_SUCCESS) {
1562 return LM_STATUS_FAILURE;
1563 }
wdenkc6097192002-11-03 00:24:07 +00001564
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001565 /* Status block. */
1566 pDevice->pStatusBlkVirt = (PT3_STATUS_BLOCK) pMemVirt;
1567 pDevice->StatusBlkPhy = MemPhy;
1568 pMemVirt += T3_STATUS_BLOCK_SIZE;
1569 LM_INC_PHYSICAL_ADDRESS (&MemPhy, T3_STATUS_BLOCK_SIZE);
wdenkc6097192002-11-03 00:24:07 +00001570
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001571 /* Statistics block. */
1572 pDevice->pStatsBlkVirt = (PT3_STATS_BLOCK) pMemVirt;
1573 pDevice->StatsBlkPhy = MemPhy;
1574 pMemVirt += sizeof (T3_STATS_BLOCK);
1575 LM_INC_PHYSICAL_ADDRESS (&MemPhy, sizeof (T3_STATS_BLOCK));
wdenkc6097192002-11-03 00:24:07 +00001576
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001577 /* Receive standard BD buffer. */
1578 pDevice->pRxStdBdVirt = (PT3_RCV_BD) pMemVirt;
1579 pDevice->RxStdBdPhy = MemPhy;
wdenkc6097192002-11-03 00:24:07 +00001580
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001581 pMemVirt += T3_STD_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1582 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1583 T3_STD_RCV_RCB_ENTRY_COUNT *
1584 sizeof (T3_RCV_BD));
wdenkc6097192002-11-03 00:24:07 +00001585
1586#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001587 /* Receive jumbo BD buffer. */
1588 pDevice->pRxJumboBdVirt = (PT3_RCV_BD) pMemVirt;
1589 pDevice->RxJumboBdPhy = MemPhy;
wdenkc6097192002-11-03 00:24:07 +00001590
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001591 pMemVirt += T3_JUMBO_RCV_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1592 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1593 T3_JUMBO_RCV_RCB_ENTRY_COUNT *
1594 sizeof (T3_RCV_BD));
1595#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00001596
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001597 /* Receive return BD buffer. */
1598 pDevice->pRcvRetBdVirt = (PT3_RCV_BD) pMemVirt;
1599 pDevice->RcvRetBdPhy = MemPhy;
wdenkc6097192002-11-03 00:24:07 +00001600
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001601 pMemVirt += T3_RCV_RETURN_RCB_ENTRY_COUNT * sizeof (T3_RCV_BD);
1602 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1603 T3_RCV_RETURN_RCB_ENTRY_COUNT *
1604 sizeof (T3_RCV_BD));
wdenkc6097192002-11-03 00:24:07 +00001605
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001606 /* Set up Send BD. */
1607 if (pDevice->NicSendBd == FALSE) {
1608 pDevice->pSendBdVirt = (PT3_SND_BD) pMemVirt;
1609 pDevice->SendBdPhy = MemPhy;
wdenkc6097192002-11-03 00:24:07 +00001610
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001611 pMemVirt += sizeof (T3_SND_BD) * T3_SEND_RCB_ENTRY_COUNT;
1612 LM_INC_PHYSICAL_ADDRESS (&MemPhy,
1613 sizeof (T3_SND_BD) *
1614 T3_SEND_RCB_ENTRY_COUNT);
1615 } else {
1616 pDevice->pSendBdVirt = (PT3_SND_BD)
1617 pDevice->pMemView->uIntMem.First32k.BufferDesc;
1618 pDevice->SendBdPhy.High = 0;
1619 pDevice->SendBdPhy.Low = T3_NIC_SND_BUFFER_DESC_ADDR;
1620 }
wdenkc6097192002-11-03 00:24:07 +00001621
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001622 /* Allocate memory for packet descriptors. */
1623 Size = (pDevice->RxPacketDescCnt +
1624 pDevice->TxPacketDescCnt) * MM_PACKET_DESC_SIZE;
1625 Status = MM_AllocateMemory (pDevice, Size, (PLM_VOID *) & pPacket);
1626 if (Status != LM_STATUS_SUCCESS) {
1627 return Status;
1628 }
1629 pDevice->pPacketDescBase = (PLM_VOID) pPacket;
wdenkc6097192002-11-03 00:24:07 +00001630
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001631 /* Create transmit packet descriptors from the memory block and add them */
1632 /* to the TxPacketFreeQ for each send ring. */
1633 for (j = 0; j < pDevice->TxPacketDescCnt; j++) {
1634 /* Ring index. */
1635 pPacket->Flags = 0;
wdenkc6097192002-11-03 00:24:07 +00001636
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001637 /* Queue the descriptor in the TxPacketFreeQ of the 'k' ring. */
1638 QQ_PushTail (&pDevice->TxPacketFreeQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00001639
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001640 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1641 /* is the total size of the packet descriptor including the */
1642 /* os-specific extensions in the UM_PACKET structure. */
1643 pPacket =
1644 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1645 } /* for(j.. */
wdenkc6097192002-11-03 00:24:07 +00001646
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001647 /* Create receive packet descriptors from the memory block and add them */
1648 /* to the RxPacketFreeQ. Create the Standard packet descriptors. */
1649 for (j = 0; j < pDevice->RxStdDescCnt; j++) {
1650 /* Receive producer ring. */
1651 pPacket->u.Rx.RcvProdRing = T3_STD_RCV_PROD_RING;
wdenkc6097192002-11-03 00:24:07 +00001652
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001653 /* Receive buffer size. */
1654 pPacket->u.Rx.RxBufferSize = MAX_STD_RCV_BUFFER_SIZE;
wdenkc6097192002-11-03 00:24:07 +00001655
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001656 /* Add the descriptor to RxPacketFreeQ. */
1657 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00001658
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001659 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1660 /* is the total size of the packet descriptor including the */
1661 /* os-specific extensions in the UM_PACKET structure. */
1662 pPacket =
1663 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1664 } /* for */
wdenkc6097192002-11-03 00:24:07 +00001665
1666#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001667 /* Create the Jumbo packet descriptors. */
1668 for (j = 0; j < pDevice->RxJumboDescCnt; j++) {
1669 /* Receive producer ring. */
1670 pPacket->u.Rx.RcvProdRing = T3_JUMBO_RCV_PROD_RING;
wdenkc6097192002-11-03 00:24:07 +00001671
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001672 /* Receive buffer size. */
1673 pPacket->u.Rx.RxBufferSize = pDevice->RxJumboBufferSize;
wdenkc6097192002-11-03 00:24:07 +00001674
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001675 /* Add the descriptor to RxPacketFreeQ. */
1676 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00001677
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001678 /* Get the pointer to the next descriptor. MM_PACKET_DESC_SIZE */
1679 /* is the total size of the packet descriptor including the */
1680 /* os-specific extensions in the UM_PACKET structure. */
1681 pPacket =
1682 (PLM_PACKET) ((PLM_UINT8) pPacket + MM_PACKET_DESC_SIZE);
1683 } /* for */
1684#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00001685
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001686 /* Initialize the rest of the packet descriptors. */
1687 Status = MM_InitializeUmPackets (pDevice);
1688 if (Status != LM_STATUS_SUCCESS) {
1689 return Status;
1690 }
wdenkc6097192002-11-03 00:24:07 +00001691
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001692 /* if */
1693 /* Default receive mask. */
1694 pDevice->ReceiveMask = LM_ACCEPT_MULTICAST | LM_ACCEPT_BROADCAST |
1695 LM_ACCEPT_UNICAST;
wdenkc6097192002-11-03 00:24:07 +00001696
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001697 /* Make sure we are in the first 32k memory window or NicSendBd. */
1698 REG_WR (pDevice, PciCfg.MemWindowBaseAddr, 0);
wdenkc6097192002-11-03 00:24:07 +00001699
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001700 /* Initialize the hardware. */
1701 Status = LM_ResetAdapter (pDevice);
1702 if (Status != LM_STATUS_SUCCESS) {
1703 return Status;
1704 }
wdenkc6097192002-11-03 00:24:07 +00001705
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001706 /* We are done with initialization. */
1707 pDevice->InitDone = TRUE;
wdenkc6097192002-11-03 00:24:07 +00001708
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001709 return LM_STATUS_SUCCESS;
1710} /* LM_InitializeAdapter */
wdenkc6097192002-11-03 00:24:07 +00001711
wdenkc6097192002-11-03 00:24:07 +00001712/******************************************************************************/
1713/* Description: */
1714/* This function Enables/Disables a given block. */
1715/* */
1716/* Return: */
1717/* LM_STATUS_SUCCESS */
1718/******************************************************************************/
1719LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001720LM_CntrlBlock (PLM_DEVICE_BLOCK pDevice, LM_UINT32 mask, LM_UINT32 cntrl)
wdenkc6097192002-11-03 00:24:07 +00001721{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001722 LM_UINT32 j, i, data;
1723 LM_UINT32 MaxWaitCnt;
wdenkc6097192002-11-03 00:24:07 +00001724
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001725 MaxWaitCnt = 2;
1726 j = 0;
wdenkc6097192002-11-03 00:24:07 +00001727
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001728 for (i = 0; i < 32; i++) {
1729 if (!(mask & (1 << i)))
1730 continue;
wdenkc6097192002-11-03 00:24:07 +00001731
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001732 switch (1 << i) {
1733 case T3_BLOCK_DMA_RD:
1734 data = REG_RD (pDevice, DmaRead.Mode);
1735 if (cntrl == LM_DISABLE) {
1736 data &= ~DMA_READ_MODE_ENABLE;
1737 REG_WR (pDevice, DmaRead.Mode, data);
1738 for (j = 0; j < MaxWaitCnt; j++) {
1739 if (!
1740 (REG_RD (pDevice, DmaRead.Mode) &
1741 DMA_READ_MODE_ENABLE))
1742 break;
1743 MM_Wait (10);
1744 }
1745 } else
1746 REG_WR (pDevice, DmaRead.Mode,
1747 data | DMA_READ_MODE_ENABLE);
1748 break;
wdenkc6097192002-11-03 00:24:07 +00001749
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001750 case T3_BLOCK_DMA_COMP:
1751 data = REG_RD (pDevice, DmaComp.Mode);
1752 if (cntrl == LM_DISABLE) {
1753 data &= ~DMA_COMP_MODE_ENABLE;
1754 REG_WR (pDevice, DmaComp.Mode, data);
1755 for (j = 0; j < MaxWaitCnt; j++) {
1756 if (!
1757 (REG_RD (pDevice, DmaComp.Mode) &
1758 DMA_COMP_MODE_ENABLE))
1759 break;
1760 MM_Wait (10);
1761 }
1762 } else
1763 REG_WR (pDevice, DmaComp.Mode,
1764 data | DMA_COMP_MODE_ENABLE);
1765 break;
wdenkc6097192002-11-03 00:24:07 +00001766
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001767 case T3_BLOCK_RX_BD_INITIATOR:
1768 data = REG_RD (pDevice, RcvBdIn.Mode);
1769 if (cntrl == LM_DISABLE) {
1770 data &= ~RCV_BD_IN_MODE_ENABLE;
1771 REG_WR (pDevice, RcvBdIn.Mode, data);
1772 for (j = 0; j < MaxWaitCnt; j++) {
1773 if (!
1774 (REG_RD (pDevice, RcvBdIn.Mode) &
1775 RCV_BD_IN_MODE_ENABLE))
1776 break;
1777 MM_Wait (10);
1778 }
1779 } else
1780 REG_WR (pDevice, RcvBdIn.Mode,
1781 data | RCV_BD_IN_MODE_ENABLE);
1782 break;
wdenkc6097192002-11-03 00:24:07 +00001783
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001784 case T3_BLOCK_RX_BD_COMP:
1785 data = REG_RD (pDevice, RcvBdComp.Mode);
1786 if (cntrl == LM_DISABLE) {
1787 data &= ~RCV_BD_COMP_MODE_ENABLE;
1788 REG_WR (pDevice, RcvBdComp.Mode, data);
1789 for (j = 0; j < MaxWaitCnt; j++) {
1790 if (!
1791 (REG_RD (pDevice, RcvBdComp.Mode) &
1792 RCV_BD_COMP_MODE_ENABLE))
1793 break;
1794 MM_Wait (10);
1795 }
1796 } else
1797 REG_WR (pDevice, RcvBdComp.Mode,
1798 data | RCV_BD_COMP_MODE_ENABLE);
1799 break;
wdenkc6097192002-11-03 00:24:07 +00001800
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001801 case T3_BLOCK_DMA_WR:
1802 data = REG_RD (pDevice, DmaWrite.Mode);
1803 if (cntrl == LM_DISABLE) {
1804 data &= ~DMA_WRITE_MODE_ENABLE;
1805 REG_WR (pDevice, DmaWrite.Mode, data);
wdenkc6097192002-11-03 00:24:07 +00001806
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001807 for (j = 0; j < MaxWaitCnt; j++) {
1808 if (!
1809 (REG_RD (pDevice, DmaWrite.Mode) &
1810 DMA_WRITE_MODE_ENABLE))
1811 break;
1812 MM_Wait (10);
1813 }
1814 } else
1815 REG_WR (pDevice, DmaWrite.Mode,
1816 data | DMA_WRITE_MODE_ENABLE);
1817 break;
wdenkc6097192002-11-03 00:24:07 +00001818
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001819 case T3_BLOCK_MSI_HANDLER:
1820 data = REG_RD (pDevice, Msi.Mode);
1821 if (cntrl == LM_DISABLE) {
1822 data &= ~MSI_MODE_ENABLE;
1823 REG_WR (pDevice, Msi.Mode, data);
1824 for (j = 0; j < MaxWaitCnt; j++) {
1825 if (!
1826 (REG_RD (pDevice, Msi.Mode) &
1827 MSI_MODE_ENABLE))
1828 break;
1829 MM_Wait (10);
1830 }
1831 } else
1832 REG_WR (pDevice, Msi.Mode,
1833 data | MSI_MODE_ENABLE);
1834 break;
wdenkc6097192002-11-03 00:24:07 +00001835
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001836 case T3_BLOCK_RX_LIST_PLMT:
1837 data = REG_RD (pDevice, RcvListPlmt.Mode);
1838 if (cntrl == LM_DISABLE) {
1839 data &= ~RCV_LIST_PLMT_MODE_ENABLE;
1840 REG_WR (pDevice, RcvListPlmt.Mode, data);
1841 for (j = 0; j < MaxWaitCnt; j++) {
1842 if (!
1843 (REG_RD (pDevice, RcvListPlmt.Mode)
1844 & RCV_LIST_PLMT_MODE_ENABLE))
1845 break;
1846 MM_Wait (10);
1847 }
1848 } else
1849 REG_WR (pDevice, RcvListPlmt.Mode,
1850 data | RCV_LIST_PLMT_MODE_ENABLE);
1851 break;
wdenkc6097192002-11-03 00:24:07 +00001852
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001853 case T3_BLOCK_RX_LIST_SELECTOR:
1854 data = REG_RD (pDevice, RcvListSel.Mode);
1855 if (cntrl == LM_DISABLE) {
1856 data &= ~RCV_LIST_SEL_MODE_ENABLE;
1857 REG_WR (pDevice, RcvListSel.Mode, data);
1858 for (j = 0; j < MaxWaitCnt; j++) {
1859 if (!
1860 (REG_RD (pDevice, RcvListSel.Mode) &
1861 RCV_LIST_SEL_MODE_ENABLE))
1862 break;
1863 MM_Wait (10);
1864 }
1865 } else
1866 REG_WR (pDevice, RcvListSel.Mode,
1867 data | RCV_LIST_SEL_MODE_ENABLE);
1868 break;
wdenkc6097192002-11-03 00:24:07 +00001869
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001870 case T3_BLOCK_RX_DATA_INITIATOR:
1871 data = REG_RD (pDevice, RcvDataBdIn.Mode);
1872 if (cntrl == LM_DISABLE) {
1873 data &= ~RCV_DATA_BD_IN_MODE_ENABLE;
1874 REG_WR (pDevice, RcvDataBdIn.Mode, data);
1875 for (j = 0; j < MaxWaitCnt; j++) {
1876 if (!
1877 (REG_RD (pDevice, RcvDataBdIn.Mode)
1878 & RCV_DATA_BD_IN_MODE_ENABLE))
1879 break;
1880 MM_Wait (10);
1881 }
1882 } else
1883 REG_WR (pDevice, RcvDataBdIn.Mode,
1884 data | RCV_DATA_BD_IN_MODE_ENABLE);
1885 break;
wdenkc6097192002-11-03 00:24:07 +00001886
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001887 case T3_BLOCK_RX_DATA_COMP:
1888 data = REG_RD (pDevice, RcvDataComp.Mode);
1889 if (cntrl == LM_DISABLE) {
1890 data &= ~RCV_DATA_COMP_MODE_ENABLE;
1891 REG_WR (pDevice, RcvDataComp.Mode, data);
1892 for (j = 0; j < MaxWaitCnt; j++) {
1893 if (!
1894 (REG_RD (pDevice, RcvDataBdIn.Mode)
1895 & RCV_DATA_COMP_MODE_ENABLE))
1896 break;
1897 MM_Wait (10);
1898 }
1899 } else
1900 REG_WR (pDevice, RcvDataComp.Mode,
1901 data | RCV_DATA_COMP_MODE_ENABLE);
1902 break;
wdenkc6097192002-11-03 00:24:07 +00001903
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001904 case T3_BLOCK_HOST_COALESING:
1905 data = REG_RD (pDevice, HostCoalesce.Mode);
1906 if (cntrl == LM_DISABLE) {
1907 data &= ~HOST_COALESCE_ENABLE;
1908 REG_WR (pDevice, HostCoalesce.Mode, data);
1909 for (j = 0; j < MaxWaitCnt; j++) {
1910 if (!
1911 (REG_RD (pDevice, SndBdIn.Mode) &
1912 HOST_COALESCE_ENABLE))
1913 break;
1914 MM_Wait (10);
1915 }
1916 } else
1917 REG_WR (pDevice, HostCoalesce.Mode,
1918 data | HOST_COALESCE_ENABLE);
1919 break;
wdenkc6097192002-11-03 00:24:07 +00001920
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001921 case T3_BLOCK_MAC_RX_ENGINE:
1922 if (cntrl == LM_DISABLE) {
1923 pDevice->RxMode &= ~RX_MODE_ENABLE;
1924 REG_WR (pDevice, MacCtrl.RxMode,
1925 pDevice->RxMode);
1926 for (j = 0; j < MaxWaitCnt; j++) {
1927 if (!
1928 (REG_RD (pDevice, MacCtrl.RxMode) &
1929 RX_MODE_ENABLE)) {
1930 break;
1931 }
1932 MM_Wait (10);
1933 }
1934 } else {
1935 pDevice->RxMode |= RX_MODE_ENABLE;
1936 REG_WR (pDevice, MacCtrl.RxMode,
1937 pDevice->RxMode);
wdenk8bde7f72003-06-27 21:31:46 +00001938 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001939 break;
wdenkc6097192002-11-03 00:24:07 +00001940
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001941 case T3_BLOCK_MBUF_CLUSTER_FREE:
1942 data = REG_RD (pDevice, MbufClusterFree.Mode);
1943 if (cntrl == LM_DISABLE) {
1944 data &= ~MBUF_CLUSTER_FREE_MODE_ENABLE;
1945 REG_WR (pDevice, MbufClusterFree.Mode, data);
1946 for (j = 0; j < MaxWaitCnt; j++) {
1947 if (!
1948 (REG_RD
1949 (pDevice,
1950 MbufClusterFree.
1951 Mode) &
1952 MBUF_CLUSTER_FREE_MODE_ENABLE))
1953 break;
1954 MM_Wait (10);
1955 }
1956 } else
1957 REG_WR (pDevice, MbufClusterFree.Mode,
1958 data | MBUF_CLUSTER_FREE_MODE_ENABLE);
1959 break;
wdenkc6097192002-11-03 00:24:07 +00001960
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001961 case T3_BLOCK_SEND_BD_INITIATOR:
1962 data = REG_RD (pDevice, SndBdIn.Mode);
1963 if (cntrl == LM_DISABLE) {
1964 data &= ~SND_BD_IN_MODE_ENABLE;
1965 REG_WR (pDevice, SndBdIn.Mode, data);
1966 for (j = 0; j < MaxWaitCnt; j++) {
1967 if (!
1968 (REG_RD (pDevice, SndBdIn.Mode) &
1969 SND_BD_IN_MODE_ENABLE))
1970 break;
1971 MM_Wait (10);
1972 }
1973 } else
1974 REG_WR (pDevice, SndBdIn.Mode,
1975 data | SND_BD_IN_MODE_ENABLE);
1976 break;
wdenkc6097192002-11-03 00:24:07 +00001977
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001978 case T3_BLOCK_SEND_BD_COMP:
1979 data = REG_RD (pDevice, SndBdComp.Mode);
1980 if (cntrl == LM_DISABLE) {
1981 data &= ~SND_BD_COMP_MODE_ENABLE;
1982 REG_WR (pDevice, SndBdComp.Mode, data);
1983 for (j = 0; j < MaxWaitCnt; j++) {
1984 if (!
1985 (REG_RD (pDevice, SndBdComp.Mode) &
1986 SND_BD_COMP_MODE_ENABLE))
1987 break;
1988 MM_Wait (10);
1989 }
1990 } else
1991 REG_WR (pDevice, SndBdComp.Mode,
1992 data | SND_BD_COMP_MODE_ENABLE);
1993 break;
wdenkc6097192002-11-03 00:24:07 +00001994
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07001995 case T3_BLOCK_SEND_BD_SELECTOR:
1996 data = REG_RD (pDevice, SndBdSel.Mode);
1997 if (cntrl == LM_DISABLE) {
1998 data &= ~SND_BD_SEL_MODE_ENABLE;
1999 REG_WR (pDevice, SndBdSel.Mode, data);
2000 for (j = 0; j < MaxWaitCnt; j++) {
2001 if (!
2002 (REG_RD (pDevice, SndBdSel.Mode) &
2003 SND_BD_SEL_MODE_ENABLE))
2004 break;
2005 MM_Wait (10);
2006 }
2007 } else
2008 REG_WR (pDevice, SndBdSel.Mode,
2009 data | SND_BD_SEL_MODE_ENABLE);
2010 break;
wdenkc6097192002-11-03 00:24:07 +00002011
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002012 case T3_BLOCK_SEND_DATA_INITIATOR:
2013 data = REG_RD (pDevice, SndDataIn.Mode);
2014 if (cntrl == LM_DISABLE) {
2015 data &= ~T3_SND_DATA_IN_MODE_ENABLE;
2016 REG_WR (pDevice, SndDataIn.Mode, data);
2017 for (j = 0; j < MaxWaitCnt; j++) {
2018 if (!
2019 (REG_RD (pDevice, SndDataIn.Mode) &
2020 T3_SND_DATA_IN_MODE_ENABLE))
2021 break;
2022 MM_Wait (10);
2023 }
2024 } else
2025 REG_WR (pDevice, SndDataIn.Mode,
2026 data | T3_SND_DATA_IN_MODE_ENABLE);
2027 break;
wdenkc6097192002-11-03 00:24:07 +00002028
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002029 case T3_BLOCK_SEND_DATA_COMP:
2030 data = REG_RD (pDevice, SndDataComp.Mode);
2031 if (cntrl == LM_DISABLE) {
2032 data &= ~SND_DATA_COMP_MODE_ENABLE;
2033 REG_WR (pDevice, SndDataComp.Mode, data);
2034 for (j = 0; j < MaxWaitCnt; j++) {
2035 if (!
2036 (REG_RD (pDevice, SndDataComp.Mode)
2037 & SND_DATA_COMP_MODE_ENABLE))
2038 break;
2039 MM_Wait (10);
2040 }
2041 } else
2042 REG_WR (pDevice, SndDataComp.Mode,
2043 data | SND_DATA_COMP_MODE_ENABLE);
2044 break;
wdenkc6097192002-11-03 00:24:07 +00002045
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002046 case T3_BLOCK_MAC_TX_ENGINE:
2047 if (cntrl == LM_DISABLE) {
2048 pDevice->TxMode &= ~TX_MODE_ENABLE;
2049 REG_WR (pDevice, MacCtrl.TxMode,
2050 pDevice->TxMode);
2051 for (j = 0; j < MaxWaitCnt; j++) {
2052 if (!
2053 (REG_RD (pDevice, MacCtrl.TxMode) &
2054 TX_MODE_ENABLE))
2055 break;
2056 MM_Wait (10);
2057 }
2058 } else {
2059 pDevice->TxMode |= TX_MODE_ENABLE;
2060 REG_WR (pDevice, MacCtrl.TxMode,
2061 pDevice->TxMode);
2062 }
2063 break;
wdenkc6097192002-11-03 00:24:07 +00002064
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002065 case T3_BLOCK_MEM_ARBITOR:
2066 data = REG_RD (pDevice, MemArbiter.Mode);
2067 if (cntrl == LM_DISABLE) {
2068 data &= ~T3_MEM_ARBITER_MODE_ENABLE;
2069 REG_WR (pDevice, MemArbiter.Mode, data);
2070 for (j = 0; j < MaxWaitCnt; j++) {
2071 if (!
2072 (REG_RD (pDevice, MemArbiter.Mode) &
2073 T3_MEM_ARBITER_MODE_ENABLE))
2074 break;
2075 MM_Wait (10);
2076 }
2077 } else
2078 REG_WR (pDevice, MemArbiter.Mode,
2079 data | T3_MEM_ARBITER_MODE_ENABLE);
2080 break;
wdenkc6097192002-11-03 00:24:07 +00002081
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002082 case T3_BLOCK_MBUF_MANAGER:
2083 data = REG_RD (pDevice, BufMgr.Mode);
2084 if (cntrl == LM_DISABLE) {
2085 data &= ~BUFMGR_MODE_ENABLE;
2086 REG_WR (pDevice, BufMgr.Mode, data);
2087 for (j = 0; j < MaxWaitCnt; j++) {
2088 if (!
2089 (REG_RD (pDevice, BufMgr.Mode) &
2090 BUFMGR_MODE_ENABLE))
2091 break;
2092 MM_Wait (10);
2093 }
2094 } else
2095 REG_WR (pDevice, BufMgr.Mode,
2096 data | BUFMGR_MODE_ENABLE);
2097 break;
wdenkc6097192002-11-03 00:24:07 +00002098
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002099 case T3_BLOCK_MAC_GLOBAL:
2100 if (cntrl == LM_DISABLE) {
2101 pDevice->MacMode &= ~(MAC_MODE_ENABLE_TDE |
2102 MAC_MODE_ENABLE_RDE |
2103 MAC_MODE_ENABLE_FHDE);
2104 } else {
2105 pDevice->MacMode |= (MAC_MODE_ENABLE_TDE |
2106 MAC_MODE_ENABLE_RDE |
2107 MAC_MODE_ENABLE_FHDE);
2108 }
2109 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
2110 break;
wdenkc6097192002-11-03 00:24:07 +00002111
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002112 default:
2113 return LM_STATUS_FAILURE;
2114 } /* switch */
wdenkc6097192002-11-03 00:24:07 +00002115
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002116 if (j >= MaxWaitCnt) {
2117 return LM_STATUS_FAILURE;
2118 }
wdenk8bde7f72003-06-27 21:31:46 +00002119 }
wdenkc6097192002-11-03 00:24:07 +00002120
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002121 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00002122}
2123
2124/******************************************************************************/
2125/* Description: */
2126/* This function reinitializes the adapter. */
2127/* */
2128/* Return: */
2129/* LM_STATUS_SUCCESS */
2130/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002131LM_STATUS LM_ResetAdapter (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00002132{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002133 LM_UINT32 Value32;
2134 LM_UINT16 Value16;
2135 LM_UINT32 j, k;
wdenkc6097192002-11-03 00:24:07 +00002136
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002137 /* Disable interrupt. */
2138 LM_DisableInterrupt (pDevice);
wdenkc6097192002-11-03 00:24:07 +00002139
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002140 /* May get a spurious interrupt */
2141 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED;
wdenkc6097192002-11-03 00:24:07 +00002142
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002143 /* Disable transmit and receive DMA engines. Abort all pending requests. */
2144 if (pDevice->InitDone) {
2145 LM_Abort (pDevice);
wdenk8bde7f72003-06-27 21:31:46 +00002146 }
wdenkc6097192002-11-03 00:24:07 +00002147
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002148 pDevice->ShuttingDown = FALSE;
wdenkc6097192002-11-03 00:24:07 +00002149
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002150 LM_ResetChip (pDevice);
wdenkc6097192002-11-03 00:24:07 +00002151
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002152 /* Bug: Athlon fix for B3 silicon only. This bit does not do anything */
2153 /* in other chip revisions. */
2154 if (pDevice->DelayPciGrant) {
2155 Value32 = REG_RD (pDevice, PciCfg.ClockCtrl);
2156 REG_WR (pDevice, PciCfg.ClockCtrl, Value32 | BIT_31);
2157 }
wdenkc6097192002-11-03 00:24:07 +00002158
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002159 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
2160 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
2161 Value32 = REG_RD (pDevice, PciCfg.PciState);
2162 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
2163 REG_WR (pDevice, PciCfg.PciState, Value32);
2164 }
2165 }
wdenkc6097192002-11-03 00:24:07 +00002166
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002167 /* Enable TaggedStatus mode. */
2168 if (pDevice->UseTaggedStatus) {
2169 pDevice->MiscHostCtrl |=
2170 MISC_HOST_CTRL_ENABLE_TAGGED_STATUS_MODE;
2171 }
wdenkc6097192002-11-03 00:24:07 +00002172
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002173 /* Restore PCI configuration registers. */
2174 MM_WriteConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG,
2175 pDevice->SavedCacheLineReg);
2176 MM_WriteConfig32 (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
2177 (pDevice->SubsystemId << 16) | pDevice->
2178 SubsystemVendorId);
2179
2180 /* Clear the statistics block. */
2181 for (j = 0x0300; j < 0x0b00; j++) {
2182 MEM_WR_OFFSET (pDevice, j, 0);
2183 }
2184
2185 /* Initialize the statistis Block */
2186 pDevice->pStatusBlkVirt->Status = 0;
2187 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
2188 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
2189 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
2190
2191 for (j = 0; j < 16; j++) {
2192 pDevice->pStatusBlkVirt->Idx[j].RcvProdIdx = 0;
2193 pDevice->pStatusBlkVirt->Idx[j].SendConIdx = 0;
2194 }
2195
2196 for (k = 0; k < T3_STD_RCV_RCB_ENTRY_COUNT; k++) {
2197 pDevice->pRxStdBdVirt[k].HostAddr.High = 0;
2198 pDevice->pRxStdBdVirt[k].HostAddr.Low = 0;
2199 }
wdenkc6097192002-11-03 00:24:07 +00002200
2201#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002202 /* Receive jumbo BD buffer. */
2203 for (k = 0; k < T3_JUMBO_RCV_RCB_ENTRY_COUNT; k++) {
2204 pDevice->pRxJumboBdVirt[k].HostAddr.High = 0;
2205 pDevice->pRxJumboBdVirt[k].HostAddr.Low = 0;
2206 }
wdenkc6097192002-11-03 00:24:07 +00002207#endif
2208
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002209 REG_WR (pDevice, PciCfg.DmaReadWriteCtrl, pDevice->DmaReadWriteCtrl);
wdenkc6097192002-11-03 00:24:07 +00002210
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002211 /* GRC mode control register. */
2212#ifdef BIG_ENDIAN_PCI /* Jimmy, this ifdef block deleted in new code! */
2213 Value32 =
2214 GRC_MODE_WORD_SWAP_DATA |
2215 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2216 GRC_MODE_INT_ON_MAC_ATTN | GRC_MODE_HOST_STACK_UP;
wdenkc6097192002-11-03 00:24:07 +00002217#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002218 /* No CPU Swap modes for PCI IO */
2219 Value32 =
wdenkc6097192002-11-03 00:24:07 +00002220#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002221 GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
2222 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2223 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA |
wdenkc6097192002-11-03 00:24:07 +00002224#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002225 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
2226 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA |
wdenkc6097192002-11-03 00:24:07 +00002227#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002228 GRC_MODE_INT_ON_MAC_ATTN | GRC_MODE_HOST_STACK_UP;
2229#endif /* !BIG_ENDIAN_PCI */
wdenkc6097192002-11-03 00:24:07 +00002230
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002231 /* Configure send BD mode. */
2232 if (pDevice->NicSendBd == FALSE) {
2233 Value32 |= GRC_MODE_HOST_SEND_BDS;
2234 } else {
2235 Value32 |= GRC_MODE_4X_NIC_BASED_SEND_RINGS;
wdenk8bde7f72003-06-27 21:31:46 +00002236 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002237
2238 /* Configure pseudo checksum mode. */
2239 if (pDevice->NoTxPseudoHdrChksum) {
2240 Value32 |= GRC_MODE_TX_NO_PSEUDO_HEADER_CHKSUM;
wdenk8bde7f72003-06-27 21:31:46 +00002241 }
wdenkc6097192002-11-03 00:24:07 +00002242
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002243 if (pDevice->NoRxPseudoHdrChksum) {
2244 Value32 |= GRC_MODE_RX_NO_PSEUDO_HEADER_CHKSUM;
wdenk8bde7f72003-06-27 21:31:46 +00002245 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002246
2247 REG_WR (pDevice, Grc.Mode, Value32);
2248
2249 /* Setup the timer prescalar register. */
Wolfgang Denk8ed44d92008-10-19 02:35:50 +02002250 REG_WR (pDevice, Grc.MiscCfg, 65 << 1); /* Clock is alwasy 66MHz. */
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002251
2252 /* Set up the MBUF pool base address and size. */
2253 REG_WR (pDevice, BufMgr.MbufPoolAddr, pDevice->MbufBase);
2254 REG_WR (pDevice, BufMgr.MbufPoolSize, pDevice->MbufSize);
2255
2256 /* Set up the DMA descriptor pool base address and size. */
2257 REG_WR (pDevice, BufMgr.DmaDescPoolAddr, T3_NIC_DMA_DESC_POOL_ADDR);
2258 REG_WR (pDevice, BufMgr.DmaDescPoolSize, T3_NIC_DMA_DESC_POOL_SIZE);
2259
2260 /* Configure MBUF and Threshold watermarks */
2261 /* Configure the DMA read MBUF low water mark. */
2262 if (pDevice->DmaMbufLowMark) {
2263 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2264 pDevice->DmaMbufLowMark);
2265 } else {
2266 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2267 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2268 T3_DEF_DMA_MBUF_LOW_WMARK);
2269 } else {
2270 REG_WR (pDevice, BufMgr.MbufReadDmaLowWaterMark,
2271 T3_DEF_DMA_MBUF_LOW_WMARK_JUMBO);
2272 }
wdenk8bde7f72003-06-27 21:31:46 +00002273 }
wdenkc6097192002-11-03 00:24:07 +00002274
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002275 /* Configure the MAC Rx MBUF low water mark. */
2276 if (pDevice->RxMacMbufLowMark) {
2277 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2278 pDevice->RxMacMbufLowMark);
2279 } else {
2280 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2281 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2282 T3_DEF_RX_MAC_MBUF_LOW_WMARK);
2283 } else {
2284 REG_WR (pDevice, BufMgr.MbufMacRxLowWaterMark,
2285 T3_DEF_RX_MAC_MBUF_LOW_WMARK_JUMBO);
2286 }
wdenk8bde7f72003-06-27 21:31:46 +00002287 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002288
2289 /* Configure the MBUF high water mark. */
2290 if (pDevice->MbufHighMark) {
2291 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2292 pDevice->MbufHighMark);
2293 } else {
2294 if (pDevice->TxMtu < MAX_ETHERNET_PACKET_BUFFER_SIZE) {
2295 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2296 T3_DEF_MBUF_HIGH_WMARK);
2297 } else {
2298 REG_WR (pDevice, BufMgr.MbufHighWaterMark,
2299 T3_DEF_MBUF_HIGH_WMARK_JUMBO);
2300 }
wdenk8bde7f72003-06-27 21:31:46 +00002301 }
wdenkc6097192002-11-03 00:24:07 +00002302
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002303 REG_WR (pDevice, BufMgr.DmaLowWaterMark, T3_DEF_DMA_DESC_LOW_WMARK);
2304 REG_WR (pDevice, BufMgr.DmaHighWaterMark, T3_DEF_DMA_DESC_HIGH_WMARK);
wdenkc6097192002-11-03 00:24:07 +00002305
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002306 /* Enable buffer manager. */
2307 REG_WR (pDevice, BufMgr.Mode,
2308 BUFMGR_MODE_ENABLE | BUFMGR_MODE_ATTN_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002309
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002310 for (j = 0; j < 2000; j++) {
2311 if (REG_RD (pDevice, BufMgr.Mode) & BUFMGR_MODE_ENABLE)
2312 break;
2313 MM_Wait (10);
2314 }
wdenkc6097192002-11-03 00:24:07 +00002315
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002316 if (j >= 2000) {
2317 return LM_STATUS_FAILURE;
2318 }
wdenkc6097192002-11-03 00:24:07 +00002319
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002320 /* Enable the FTQs. */
2321 REG_WR (pDevice, Ftq.Reset, 0xffffffff);
2322 REG_WR (pDevice, Ftq.Reset, 0);
wdenkc6097192002-11-03 00:24:07 +00002323
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002324 /* Wait until FTQ is ready */
2325 for (j = 0; j < 2000; j++) {
2326 if (REG_RD (pDevice, Ftq.Reset) == 0)
2327 break;
2328 MM_Wait (10);
2329 }
wdenkc6097192002-11-03 00:24:07 +00002330
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002331 if (j >= 2000) {
2332 return LM_STATUS_FAILURE;
2333 }
wdenkc6097192002-11-03 00:24:07 +00002334
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002335 /* Initialize the Standard Receive RCB. */
2336 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.High,
2337 pDevice->RxStdBdPhy.High);
2338 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.HostRingAddr.Low,
2339 pDevice->RxStdBdPhy.Low);
2340 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.u.MaxLen_Flags,
2341 MAX_STD_RCV_BUFFER_SIZE << 16);
wdenkc6097192002-11-03 00:24:07 +00002342
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002343 /* Initialize the Jumbo Receive RCB. */
2344 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags,
2345 T3_RCB_FLAG_RING_DISABLED);
wdenkc6097192002-11-03 00:24:07 +00002346#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002347 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.High,
2348 pDevice->RxJumboBdPhy.High);
2349 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.HostRingAddr.Low,
2350 pDevice->RxJumboBdPhy.Low);
wdenkc6097192002-11-03 00:24:07 +00002351
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002352 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.u.MaxLen_Flags, 0);
wdenkc6097192002-11-03 00:24:07 +00002353
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002354#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00002355
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002356 /* Initialize the Mini Receive RCB. */
2357 REG_WR (pDevice, RcvDataBdIn.MiniRcvRcb.u.MaxLen_Flags,
2358 T3_RCB_FLAG_RING_DISABLED);
wdenkc6097192002-11-03 00:24:07 +00002359
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002360 {
2361 REG_WR (pDevice, RcvDataBdIn.StdRcvRcb.NicRingAddr,
2362 (LM_UINT32) T3_NIC_STD_RCV_BUFFER_DESC_ADDR);
2363 REG_WR (pDevice, RcvDataBdIn.JumboRcvRcb.NicRingAddr,
2364 (LM_UINT32) T3_NIC_JUMBO_RCV_BUFFER_DESC_ADDR);
2365 }
wdenkc6097192002-11-03 00:24:07 +00002366
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002367 /* Receive BD Ring replenish threshold. */
2368 REG_WR (pDevice, RcvBdIn.StdRcvThreshold, pDevice->RxStdDescCnt / 8);
wdenkc6097192002-11-03 00:24:07 +00002369#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002370 REG_WR (pDevice, RcvBdIn.JumboRcvThreshold,
2371 pDevice->RxJumboDescCnt / 8);
2372#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00002373
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002374 /* Disable all the unused rings. */
2375 for (j = 0; j < T3_MAX_SEND_RCB_COUNT; j++) {
2376 MEM_WR (pDevice, SendRcb[j].u.MaxLen_Flags,
2377 T3_RCB_FLAG_RING_DISABLED);
2378 } /* for */
wdenkc6097192002-11-03 00:24:07 +00002379
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002380 /* Initialize the indices. */
2381 pDevice->SendProdIdx = 0;
2382 pDevice->SendConIdx = 0;
wdenkc6097192002-11-03 00:24:07 +00002383
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002384 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, 0);
2385 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, 0);
wdenkc6097192002-11-03 00:24:07 +00002386
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002387 /* Set up host or NIC based send RCB. */
2388 if (pDevice->NicSendBd == FALSE) {
2389 MEM_WR (pDevice, SendRcb[0].HostRingAddr.High,
2390 pDevice->SendBdPhy.High);
2391 MEM_WR (pDevice, SendRcb[0].HostRingAddr.Low,
2392 pDevice->SendBdPhy.Low);
2393
2394 /* Set up the NIC ring address in the RCB. */
2395 MEM_WR (pDevice, SendRcb[0].NicRingAddr,
2396 T3_NIC_SND_BUFFER_DESC_ADDR);
2397
2398 /* Setup the RCB. */
2399 MEM_WR (pDevice, SendRcb[0].u.MaxLen_Flags,
2400 T3_SEND_RCB_ENTRY_COUNT << 16);
2401
2402 for (k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++) {
2403 pDevice->pSendBdVirt[k].HostAddr.High = 0;
2404 pDevice->pSendBdVirt[k].HostAddr.Low = 0;
2405 }
2406 } else {
2407 MEM_WR (pDevice, SendRcb[0].HostRingAddr.High, 0);
2408 MEM_WR (pDevice, SendRcb[0].HostRingAddr.Low, 0);
2409 MEM_WR (pDevice, SendRcb[0].NicRingAddr,
2410 pDevice->SendBdPhy.Low);
2411
2412 for (k = 0; k < T3_SEND_RCB_ENTRY_COUNT; k++) {
2413 __raw_writel (0,
2414 &(pDevice->pSendBdVirt[k].HostAddr.High));
2415 __raw_writel (0,
2416 &(pDevice->pSendBdVirt[k].HostAddr.Low));
2417 __raw_writel (0,
2418 &(pDevice->pSendBdVirt[k].u1.Len_Flags));
2419 pDevice->ShadowSendBd[k].HostAddr.High = 0;
2420 pDevice->ShadowSendBd[k].u1.Len_Flags = 0;
2421 }
2422 }
2423 atomic_set (&pDevice->SendBdLeft, T3_SEND_RCB_ENTRY_COUNT - 1);
2424
2425 /* Configure the receive return rings. */
2426 for (j = 0; j < T3_MAX_RCV_RETURN_RCB_COUNT; j++) {
2427 MEM_WR (pDevice, RcvRetRcb[j].u.MaxLen_Flags,
2428 T3_RCB_FLAG_RING_DISABLED);
2429 }
2430
2431 pDevice->RcvRetConIdx = 0;
2432
2433 MEM_WR (pDevice, RcvRetRcb[0].HostRingAddr.High,
2434 pDevice->RcvRetBdPhy.High);
2435 MEM_WR (pDevice, RcvRetRcb[0].HostRingAddr.Low,
2436 pDevice->RcvRetBdPhy.Low);
wdenkc6097192002-11-03 00:24:07 +00002437
wdenk8bde7f72003-06-27 21:31:46 +00002438 /* Set up the NIC ring address in the RCB. */
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002439 /* Not very clear from the spec. I am guessing that for Receive */
2440 /* Return Ring, NicRingAddr is not used. */
2441 MEM_WR (pDevice, RcvRetRcb[0].NicRingAddr, 0);
wdenkc6097192002-11-03 00:24:07 +00002442
wdenk8bde7f72003-06-27 21:31:46 +00002443 /* Setup the RCB. */
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002444 MEM_WR (pDevice, RcvRetRcb[0].u.MaxLen_Flags,
2445 T3_RCV_RETURN_RCB_ENTRY_COUNT << 16);
wdenkc6097192002-11-03 00:24:07 +00002446
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002447 /* Reinitialize RX ring producer index */
2448 MB_REG_WR (pDevice, Mailbox.RcvStdProdIdx.Low, 0);
2449 MB_REG_WR (pDevice, Mailbox.RcvJumboProdIdx.Low, 0);
2450 MB_REG_WR (pDevice, Mailbox.RcvMiniProdIdx.Low, 0);
wdenkc6097192002-11-03 00:24:07 +00002451
2452#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002453 pDevice->RxJumboProdIdx = 0;
2454 pDevice->RxJumboQueuedCnt = 0;
wdenkc6097192002-11-03 00:24:07 +00002455#endif
2456
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002457 /* Reinitialize our copy of the indices. */
2458 pDevice->RxStdProdIdx = 0;
2459 pDevice->RxStdQueuedCnt = 0;
wdenkc6097192002-11-03 00:24:07 +00002460
2461#if T3_JUMBO_RCV_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002462 pDevice->RxJumboProdIdx = 0;
2463#endif /* T3_JUMBO_RCV_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00002464
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002465 /* Configure the MAC address. */
2466 LM_SetMacAddress (pDevice, pDevice->NodeAddress);
wdenkc6097192002-11-03 00:24:07 +00002467
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002468 /* Initialize the transmit random backoff seed. */
2469 Value32 = (pDevice->NodeAddress[0] + pDevice->NodeAddress[1] +
2470 pDevice->NodeAddress[2] + pDevice->NodeAddress[3] +
2471 pDevice->NodeAddress[4] + pDevice->NodeAddress[5]) &
2472 MAC_TX_BACKOFF_SEED_MASK;
2473 REG_WR (pDevice, MacCtrl.TxBackoffSeed, Value32);
wdenkc6097192002-11-03 00:24:07 +00002474
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002475 /* Receive MTU. Frames larger than the MTU is marked as oversized. */
2476 REG_WR (pDevice, MacCtrl.MtuSize, pDevice->RxMtu + 8); /* CRC + VLAN. */
wdenkc6097192002-11-03 00:24:07 +00002477
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002478 /* Configure Time slot/IPG per 802.3 */
2479 REG_WR (pDevice, MacCtrl.TxLengths, 0x2620);
wdenkc6097192002-11-03 00:24:07 +00002480
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002481 /*
2482 * Configure Receive Rules so that packets don't match
2483 * Programmble rule will be queued to Return Ring 1
2484 */
2485 REG_WR (pDevice, MacCtrl.RcvRuleCfg, RX_RULE_DEFAULT_CLASS);
wdenkc6097192002-11-03 00:24:07 +00002486
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002487 /*
2488 * Configure to have 16 Classes of Services (COS) and one
2489 * queue per class. Bad frames are queued to RRR#1.
2490 * And frames don't match rules are also queued to COS#1.
2491 */
2492 REG_WR (pDevice, RcvListPlmt.Config, 0x181);
wdenkc6097192002-11-03 00:24:07 +00002493
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002494 /* Enable Receive Placement Statistics */
2495 REG_WR (pDevice, RcvListPlmt.StatsEnableMask, 0xffffff);
2496 REG_WR (pDevice, RcvListPlmt.StatsCtrl, RCV_LIST_STATS_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002497
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002498 /* Enable Send Data Initator Statistics */
2499 REG_WR (pDevice, SndDataIn.StatsEnableMask, 0xffffff);
2500 REG_WR (pDevice, SndDataIn.StatsCtrl,
2501 T3_SND_DATA_IN_STATS_CTRL_ENABLE |
2502 T3_SND_DATA_IN_STATS_CTRL_FASTER_UPDATE);
wdenkc6097192002-11-03 00:24:07 +00002503
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002504 /* Disable the host coalescing state machine before configuring it's */
2505 /* parameters. */
2506 REG_WR (pDevice, HostCoalesce.Mode, 0);
2507 for (j = 0; j < 2000; j++) {
2508 Value32 = REG_RD (pDevice, HostCoalesce.Mode);
2509 if (!(Value32 & HOST_COALESCE_ENABLE)) {
2510 break;
2511 }
2512 MM_Wait (10);
wdenk8bde7f72003-06-27 21:31:46 +00002513 }
wdenkc6097192002-11-03 00:24:07 +00002514
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002515 /* Host coalescing configurations. */
2516 REG_WR (pDevice, HostCoalesce.RxCoalescingTicks,
2517 pDevice->RxCoalescingTicks);
2518 REG_WR (pDevice, HostCoalesce.TxCoalescingTicks,
2519 pDevice->TxCoalescingTicks);
2520 REG_WR (pDevice, HostCoalesce.RxMaxCoalescedFrames,
2521 pDevice->RxMaxCoalescedFrames);
2522 REG_WR (pDevice, HostCoalesce.TxMaxCoalescedFrames,
2523 pDevice->TxMaxCoalescedFrames);
2524 REG_WR (pDevice, HostCoalesce.RxCoalescedTickDuringInt,
2525 pDevice->RxCoalescingTicksDuringInt);
2526 REG_WR (pDevice, HostCoalesce.TxCoalescedTickDuringInt,
2527 pDevice->TxCoalescingTicksDuringInt);
2528 REG_WR (pDevice, HostCoalesce.RxMaxCoalescedFramesDuringInt,
2529 pDevice->RxMaxCoalescedFramesDuringInt);
2530 REG_WR (pDevice, HostCoalesce.TxMaxCoalescedFramesDuringInt,
2531 pDevice->TxMaxCoalescedFramesDuringInt);
wdenkc6097192002-11-03 00:24:07 +00002532
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002533 /* Initialize the address of the status block. The NIC will DMA */
2534 /* the status block to this memory which resides on the host. */
2535 REG_WR (pDevice, HostCoalesce.StatusBlkHostAddr.High,
2536 pDevice->StatusBlkPhy.High);
2537 REG_WR (pDevice, HostCoalesce.StatusBlkHostAddr.Low,
2538 pDevice->StatusBlkPhy.Low);
wdenkc6097192002-11-03 00:24:07 +00002539
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002540 /* Initialize the address of the statistics block. The NIC will DMA */
2541 /* the statistics to this block of memory. */
2542 REG_WR (pDevice, HostCoalesce.StatsBlkHostAddr.High,
2543 pDevice->StatsBlkPhy.High);
2544 REG_WR (pDevice, HostCoalesce.StatsBlkHostAddr.Low,
2545 pDevice->StatsBlkPhy.Low);
wdenkc6097192002-11-03 00:24:07 +00002546
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002547 REG_WR (pDevice, HostCoalesce.StatsCoalescingTicks,
2548 pDevice->StatsCoalescingTicks);
wdenkc6097192002-11-03 00:24:07 +00002549
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002550 REG_WR (pDevice, HostCoalesce.StatsBlkNicAddr, 0x300);
2551 REG_WR (pDevice, HostCoalesce.StatusBlkNicAddr, 0xb00);
wdenkc6097192002-11-03 00:24:07 +00002552
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002553 /* Enable Host Coalesing state machine */
2554 REG_WR (pDevice, HostCoalesce.Mode, HOST_COALESCE_ENABLE |
2555 pDevice->CoalesceMode);
wdenkc6097192002-11-03 00:24:07 +00002556
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002557 /* Enable the Receive BD Completion state machine. */
2558 REG_WR (pDevice, RcvBdComp.Mode, RCV_BD_COMP_MODE_ENABLE |
2559 RCV_BD_COMP_MODE_ATTN_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002560
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002561 /* Enable the Receive List Placement state machine. */
2562 REG_WR (pDevice, RcvListPlmt.Mode, RCV_LIST_PLMT_MODE_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002563
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002564 /* Enable the Receive List Selector state machine. */
2565 REG_WR (pDevice, RcvListSel.Mode, RCV_LIST_SEL_MODE_ENABLE |
2566 RCV_LIST_SEL_MODE_ATTN_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002567
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002568 /* Enable transmit DMA, clear statistics. */
2569 pDevice->MacMode = MAC_MODE_ENABLE_TX_STATISTICS |
2570 MAC_MODE_ENABLE_RX_STATISTICS | MAC_MODE_ENABLE_TDE |
2571 MAC_MODE_ENABLE_RDE | MAC_MODE_ENABLE_FHDE;
2572 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
2573 MAC_MODE_CLEAR_RX_STATISTICS | MAC_MODE_CLEAR_TX_STATISTICS);
wdenkc6097192002-11-03 00:24:07 +00002574
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002575 /* GRC miscellaneous local control register. */
2576 pDevice->GrcLocalCtrl = GRC_MISC_LOCAL_CTRL_INT_ON_ATTN |
2577 GRC_MISC_LOCAL_CTRL_AUTO_SEEPROM;
wdenkc6097192002-11-03 00:24:07 +00002578
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002579 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2580 pDevice->GrcLocalCtrl |= GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
2581 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1;
wdenk8bde7f72003-06-27 21:31:46 +00002582 }
wdenkc6097192002-11-03 00:24:07 +00002583
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002584 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
2585 MM_Wait (40);
wdenkc6097192002-11-03 00:24:07 +00002586
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002587 /* Reset RX counters. */
2588 for (j = 0; j < sizeof (LM_RX_COUNTERS); j++) {
2589 ((PLM_UINT8) & pDevice->RxCounters)[j] = 0;
2590 }
wdenkc6097192002-11-03 00:24:07 +00002591
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002592 /* Reset TX counters. */
2593 for (j = 0; j < sizeof (LM_TX_COUNTERS); j++) {
2594 ((PLM_UINT8) & pDevice->TxCounters)[j] = 0;
2595 }
wdenkc6097192002-11-03 00:24:07 +00002596
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002597 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 0);
wdenkc6097192002-11-03 00:24:07 +00002598
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002599 /* Enable the DMA Completion state machine. */
2600 REG_WR (pDevice, DmaComp.Mode, DMA_COMP_MODE_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002601
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002602 /* Enable the DMA Write state machine. */
2603 Value32 = DMA_WRITE_MODE_ENABLE |
2604 DMA_WRITE_MODE_TARGET_ABORT_ATTN_ENABLE |
2605 DMA_WRITE_MODE_MASTER_ABORT_ATTN_ENABLE |
2606 DMA_WRITE_MODE_PARITY_ERROR_ATTN_ENABLE |
2607 DMA_WRITE_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2608 DMA_WRITE_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2609 DMA_WRITE_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2610 DMA_WRITE_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2611 DMA_WRITE_MODE_LONG_READ_ATTN_ENABLE;
2612 REG_WR (pDevice, DmaWrite.Mode, Value32);
wdenkc6097192002-11-03 00:24:07 +00002613
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002614 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
2615 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
2616 Value16 = REG_RD (pDevice, PciCfg.PciXCommand);
2617 Value16 &=
2618 ~(PCIX_CMD_MAX_SPLIT_MASK |
2619 PCIX_CMD_MAX_BURST_MASK);
2620 Value16 |=
2621 ((PCIX_CMD_MAX_BURST_CPIOB <<
2622 PCIX_CMD_MAX_BURST_SHL) &
2623 PCIX_CMD_MAX_BURST_MASK);
2624 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE) {
2625 Value16 |=
2626 (pDevice->
2627 SplitModeMaxReq << PCIX_CMD_MAX_SPLIT_SHL)
2628 & PCIX_CMD_MAX_SPLIT_MASK;
2629 }
2630 REG_WR (pDevice, PciCfg.PciXCommand, Value16);
2631 }
2632 }
wdenkc6097192002-11-03 00:24:07 +00002633
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002634 /* Enable the Read DMA state machine. */
2635 Value32 = DMA_READ_MODE_ENABLE |
2636 DMA_READ_MODE_TARGET_ABORT_ATTN_ENABLE |
2637 DMA_READ_MODE_MASTER_ABORT_ATTN_ENABLE |
2638 DMA_READ_MODE_PARITY_ERROR_ATTN_ENABLE |
2639 DMA_READ_MODE_ADDR_OVERFLOW_ATTN_ENABLE |
2640 DMA_READ_MODE_FIFO_OVERRUN_ATTN_ENABLE |
2641 DMA_READ_MODE_FIFO_UNDERRUN_ATTN_ENABLE |
2642 DMA_READ_MODE_FIFO_OVERREAD_ATTN_ENABLE |
2643 DMA_READ_MODE_LONG_READ_ATTN_ENABLE;
wdenkc6097192002-11-03 00:24:07 +00002644
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002645 if (pDevice->SplitModeEnable == SPLIT_MODE_ENABLE) {
2646 Value32 |= DMA_READ_MODE_SPLIT_ENABLE;
2647 }
2648 REG_WR (pDevice, DmaRead.Mode, Value32);
wdenkc6097192002-11-03 00:24:07 +00002649
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002650 /* Enable the Receive Data Completion state machine. */
2651 REG_WR (pDevice, RcvDataComp.Mode, RCV_DATA_COMP_MODE_ENABLE |
2652 RCV_DATA_COMP_MODE_ATTN_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002653
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002654 /* Enable the Mbuf Cluster Free state machine. */
2655 REG_WR (pDevice, MbufClusterFree.Mode, MBUF_CLUSTER_FREE_MODE_ENABLE);
2656
2657 /* Enable the Send Data Completion state machine. */
2658 REG_WR (pDevice, SndDataComp.Mode, SND_DATA_COMP_MODE_ENABLE);
2659
2660 /* Enable the Send BD Completion state machine. */
2661 REG_WR (pDevice, SndBdComp.Mode, SND_BD_COMP_MODE_ENABLE |
2662 SND_BD_COMP_MODE_ATTN_ENABLE);
2663
2664 /* Enable the Receive BD Initiator state machine. */
2665 REG_WR (pDevice, RcvBdIn.Mode, RCV_BD_IN_MODE_ENABLE |
2666 RCV_BD_IN_MODE_BD_IN_DIABLED_RCB_ATTN_ENABLE);
2667
2668 /* Enable the Receive Data and Receive BD Initiator state machine. */
2669 REG_WR (pDevice, RcvDataBdIn.Mode, RCV_DATA_BD_IN_MODE_ENABLE |
2670 RCV_DATA_BD_IN_MODE_INVALID_RING_SIZE);
2671
2672 /* Enable the Send Data Initiator state machine. */
2673 REG_WR (pDevice, SndDataIn.Mode, T3_SND_DATA_IN_MODE_ENABLE);
2674
2675 /* Enable the Send BD Initiator state machine. */
2676 REG_WR (pDevice, SndBdIn.Mode, SND_BD_IN_MODE_ENABLE |
2677 SND_BD_IN_MODE_ATTN_ENABLE);
2678
2679 /* Enable the Send BD Selector state machine. */
2680 REG_WR (pDevice, SndBdSel.Mode, SND_BD_SEL_MODE_ENABLE |
2681 SND_BD_SEL_MODE_ATTN_ENABLE);
wdenkc6097192002-11-03 00:24:07 +00002682
2683#if INCLUDE_5701_AX_FIX
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002684 /* Load the firmware for the 5701_A0 workaround. */
2685 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0) {
2686 LM_LoadRlsFirmware (pDevice);
2687 }
wdenkc6097192002-11-03 00:24:07 +00002688#endif
2689
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002690 /* Enable the transmitter. */
2691 pDevice->TxMode = TX_MODE_ENABLE;
2692 REG_WR (pDevice, MacCtrl.TxMode, pDevice->TxMode);
wdenkc6097192002-11-03 00:24:07 +00002693
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002694 /* Enable the receiver. */
2695 pDevice->RxMode = RX_MODE_ENABLE;
2696 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
wdenkc6097192002-11-03 00:24:07 +00002697
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002698 if (pDevice->RestoreOnWakeUp) {
2699 pDevice->RestoreOnWakeUp = FALSE;
2700 pDevice->DisableAutoNeg = pDevice->WakeUpDisableAutoNeg;
2701 pDevice->RequestedMediaType = pDevice->WakeUpRequestedMediaType;
wdenk8bde7f72003-06-27 21:31:46 +00002702 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002703
2704 /* Disable auto polling. */
2705 pDevice->MiMode = 0xc0000;
2706 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
2707
2708 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
2709 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
2710 Value32 = LED_CTRL_PHY_MODE_1;
2711 } else {
2712 if (pDevice->LedMode == LED_MODE_OUTPUT) {
2713 Value32 = LED_CTRL_PHY_MODE_2;
2714 } else {
2715 Value32 = LED_CTRL_PHY_MODE_1;
2716 }
wdenk8bde7f72003-06-27 21:31:46 +00002717 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002718 REG_WR (pDevice, MacCtrl.LedCtrl, Value32);
wdenkc6097192002-11-03 00:24:07 +00002719
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002720 /* Activate Link to enable MAC state machine */
2721 REG_WR (pDevice, MacCtrl.MiStatus, MI_STATUS_ENABLE_LINK_STATUS_ATTN);
wdenkc6097192002-11-03 00:24:07 +00002722
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002723 if (pDevice->EnableTbi) {
2724 REG_WR (pDevice, MacCtrl.RxMode, RX_MODE_RESET);
2725 MM_Wait (10);
2726 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
2727 if (pDevice->ChipRevId == T3_CHIP_ID_5703_A1) {
2728 REG_WR (pDevice, MacCtrl.SerdesCfg, 0x616000);
2729 }
wdenk8bde7f72003-06-27 21:31:46 +00002730 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002731 /* Setup the phy chip. */
2732 LM_SetupPhy (pDevice);
wdenkc6097192002-11-03 00:24:07 +00002733
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002734 if (!pDevice->EnableTbi) {
2735 /* Clear CRC stats */
2736 LM_ReadPhy (pDevice, 0x1e, &Value32);
2737 LM_WritePhy (pDevice, 0x1e, Value32 | 0x8000);
2738 LM_ReadPhy (pDevice, 0x14, &Value32);
2739 }
wdenkc6097192002-11-03 00:24:07 +00002740
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002741 /* Set up the receive mask. */
2742 LM_SetReceiveMask (pDevice, pDevice->ReceiveMask);
wdenkc6097192002-11-03 00:24:07 +00002743
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002744 /* Queue Rx packet buffers. */
2745 if (pDevice->QueueRxPackets) {
2746 LM_QueueRxPackets (pDevice);
2747 }
wdenkc6097192002-11-03 00:24:07 +00002748
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002749 /* Enable interrupt to the host. */
2750 if (pDevice->InitDone) {
2751 LM_EnableInterrupt (pDevice);
2752 }
wdenkc6097192002-11-03 00:24:07 +00002753
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002754 return LM_STATUS_SUCCESS;
2755} /* LM_ResetAdapter */
wdenkc6097192002-11-03 00:24:07 +00002756
2757/******************************************************************************/
2758/* Description: */
2759/* This routine disables the adapter from generating interrupts. */
2760/* */
2761/* Return: */
2762/* LM_STATUS_SUCCESS */
2763/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002764LM_STATUS LM_DisableInterrupt (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00002765{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002766 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl |
2767 MISC_HOST_CTRL_MASK_PCI_INT);
2768 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 1);
wdenkc6097192002-11-03 00:24:07 +00002769
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002770 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00002771}
2772
wdenkc6097192002-11-03 00:24:07 +00002773/******************************************************************************/
2774/* Description: */
2775/* This routine enables the adapter to generate interrupts. */
2776/* */
2777/* Return: */
2778/* LM_STATUS_SUCCESS */
2779/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002780LM_STATUS LM_EnableInterrupt (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00002781{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002782 REG_WR (pDevice, PciCfg.MiscHostCtrl, pDevice->MiscHostCtrl &
2783 ~MISC_HOST_CTRL_MASK_PCI_INT);
2784 MB_REG_WR (pDevice, Mailbox.Interrupt[0].Low, 0);
wdenkc6097192002-11-03 00:24:07 +00002785
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002786 if (pDevice->pStatusBlkVirt->Status & STATUS_BLOCK_UPDATED) {
2787 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
2788 GRC_MISC_LOCAL_CTRL_SET_INT);
2789 }
wdenkc6097192002-11-03 00:24:07 +00002790
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002791 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00002792}
2793
wdenkc6097192002-11-03 00:24:07 +00002794/******************************************************************************/
2795/* Description: */
2796/* This routine puts a packet on the wire if there is a transmit DMA */
2797/* descriptor available; otherwise the packet is queued for later */
2798/* transmission. If the second argue is NULL, this routine will put */
2799/* the queued packet on the wire if possible. */
2800/* */
2801/* Return: */
2802/* LM_STATUS_SUCCESS */
2803/******************************************************************************/
2804#if 0
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002805LM_STATUS LM_SendPacket (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
wdenkc6097192002-11-03 00:24:07 +00002806{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002807 LM_UINT32 FragCount;
2808 PT3_SND_BD pSendBd;
2809 PT3_SND_BD pShadowSendBd;
2810 LM_UINT32 Value32, Len;
2811 LM_UINT32 Idx;
wdenkc6097192002-11-03 00:24:07 +00002812
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002813 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2814 return LM_5700SendPacket (pDevice, pPacket);
2815 }
wdenkc6097192002-11-03 00:24:07 +00002816
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002817 /* Update the SendBdLeft count. */
2818 atomic_sub (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
wdenkc6097192002-11-03 00:24:07 +00002819
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002820 /* Initalize the send buffer descriptors. */
2821 Idx = pDevice->SendProdIdx;
wdenkc6097192002-11-03 00:24:07 +00002822
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002823 pSendBd = &pDevice->pSendBdVirt[Idx];
wdenkc6097192002-11-03 00:24:07 +00002824
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002825 /* Next producer index. */
2826 if (pDevice->NicSendBd == TRUE) {
2827 T3_64BIT_HOST_ADDR paddr;
wdenkc6097192002-11-03 00:24:07 +00002828
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002829 pShadowSendBd = &pDevice->ShadowSendBd[Idx];
2830 for (FragCount = 0;;) {
2831 MM_MapTxDma (pDevice, pPacket, &paddr, &Len, FragCount);
2832 /* Initialize the pointer to the send buffer fragment. */
2833 if (paddr.High != pShadowSendBd->HostAddr.High) {
2834 __raw_writel (paddr.High,
2835 &(pSendBd->HostAddr.High));
2836 pShadowSendBd->HostAddr.High = paddr.High;
2837 }
2838 __raw_writel (paddr.Low, &(pSendBd->HostAddr.Low));
wdenkc6097192002-11-03 00:24:07 +00002839
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002840 /* Setup the control flags and send buffer size. */
2841 Value32 = (Len << 16) | pPacket->Flags;
wdenkc6097192002-11-03 00:24:07 +00002842
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002843 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
wdenkc6097192002-11-03 00:24:07 +00002844
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002845 FragCount++;
2846 if (FragCount >= pPacket->u.Tx.FragCount) {
2847 Value32 |= SND_BD_FLAG_END;
2848 if (Value32 != pShadowSendBd->u1.Len_Flags) {
2849 __raw_writel (Value32,
2850 &(pSendBd->u1.Len_Flags));
2851 pShadowSendBd->u1.Len_Flags = Value32;
2852 }
2853 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
2854 __raw_writel (pPacket->VlanTag,
2855 &(pSendBd->u2.VlanTag));
2856 }
2857 break;
2858 } else {
2859 if (Value32 != pShadowSendBd->u1.Len_Flags) {
2860 __raw_writel (Value32,
2861 &(pSendBd->u1.Len_Flags));
2862 pShadowSendBd->u1.Len_Flags = Value32;
2863 }
2864 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
2865 __raw_writel (pPacket->VlanTag,
2866 &(pSendBd->u2.VlanTag));
2867 }
2868 }
wdenkc6097192002-11-03 00:24:07 +00002869
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002870 pSendBd++;
2871 pShadowSendBd++;
2872 if (Idx == 0) {
2873 pSendBd = &pDevice->pSendBdVirt[0];
2874 pShadowSendBd = &pDevice->ShadowSendBd[0];
2875 }
2876 } /* for */
wdenkc6097192002-11-03 00:24:07 +00002877
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002878 /* Put the packet descriptor in the ActiveQ. */
2879 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00002880
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002881 wmb ();
2882 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
wdenkc6097192002-11-03 00:24:07 +00002883
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002884 } else {
2885 for (FragCount = 0;;) {
2886 /* Initialize the pointer to the send buffer fragment. */
2887 MM_MapTxDma (pDevice, pPacket, &pSendBd->HostAddr, &Len,
2888 FragCount);
wdenkc6097192002-11-03 00:24:07 +00002889
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002890 pSendBd->u2.VlanTag = pPacket->VlanTag;
wdenkc6097192002-11-03 00:24:07 +00002891
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002892 /* Setup the control flags and send buffer size. */
2893 Value32 = (Len << 16) | pPacket->Flags;
wdenkc6097192002-11-03 00:24:07 +00002894
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002895 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
wdenkc6097192002-11-03 00:24:07 +00002896
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002897 FragCount++;
2898 if (FragCount >= pPacket->u.Tx.FragCount) {
2899 pSendBd->u1.Len_Flags =
2900 Value32 | SND_BD_FLAG_END;
2901 break;
2902 } else {
2903 pSendBd->u1.Len_Flags = Value32;
2904 }
2905 pSendBd++;
2906 if (Idx == 0) {
2907 pSendBd = &pDevice->pSendBdVirt[0];
2908 }
2909 } /* for */
wdenkc6097192002-11-03 00:24:07 +00002910
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002911 /* Put the packet descriptor in the ActiveQ. */
2912 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00002913
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002914 wmb ();
2915 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
wdenkc6097192002-11-03 00:24:07 +00002916
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002917 }
wdenkc6097192002-11-03 00:24:07 +00002918
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002919 /* Update the producer index. */
2920 pDevice->SendProdIdx = Idx;
wdenkc6097192002-11-03 00:24:07 +00002921
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002922 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00002923}
2924#endif
2925
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002926LM_STATUS LM_SendPacket (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket)
wdenkc6097192002-11-03 00:24:07 +00002927{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002928 LM_UINT32 FragCount;
2929 PT3_SND_BD pSendBd, pTmpSendBd, pShadowSendBd;
2930 T3_SND_BD NicSendBdArr[MAX_FRAGMENT_COUNT];
2931 LM_UINT32 StartIdx, Idx;
wdenkc6097192002-11-03 00:24:07 +00002932
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002933 while (1) {
2934 /* Initalize the send buffer descriptors. */
2935 StartIdx = Idx = pDevice->SendProdIdx;
wdenkc6097192002-11-03 00:24:07 +00002936
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002937 if (pDevice->NicSendBd) {
2938 pTmpSendBd = pSendBd = &NicSendBdArr[0];
2939 } else {
2940 pTmpSendBd = pSendBd = &pDevice->pSendBdVirt[Idx];
wdenk8bde7f72003-06-27 21:31:46 +00002941 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002942
2943 /* Next producer index. */
2944 for (FragCount = 0;;) {
2945 LM_UINT32 Value32, Len;
2946
2947 /* Initialize the pointer to the send buffer fragment. */
2948 MM_MapTxDma (pDevice, pPacket, &pSendBd->HostAddr, &Len,
2949 FragCount);
2950
2951 pSendBd->u2.VlanTag = pPacket->VlanTag;
2952
2953 /* Setup the control flags and send buffer size. */
2954 Value32 = (Len << 16) | pPacket->Flags;
2955
2956 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
2957
2958 FragCount++;
2959 if (FragCount >= pPacket->u.Tx.FragCount) {
2960 pSendBd->u1.Len_Flags =
2961 Value32 | SND_BD_FLAG_END;
2962 break;
2963 } else {
2964 pSendBd->u1.Len_Flags = Value32;
2965 }
2966 pSendBd++;
2967 if ((Idx == 0) && !pDevice->NicSendBd) {
2968 pSendBd = &pDevice->pSendBdVirt[0];
2969 }
2970 } /* for */
2971 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
2972 if (LM_Test4GBoundary (pDevice, pPacket, pTmpSendBd) ==
2973 LM_STATUS_SUCCESS) {
2974 if (MM_CoalesceTxBuffer (pDevice, pPacket) !=
2975 LM_STATUS_SUCCESS) {
2976 QQ_PushHead (&pDevice->TxPacketFreeQ.
2977 Container, pPacket);
2978 return LM_STATUS_FAILURE;
2979 }
2980 continue;
2981 }
2982 }
2983 break;
wdenk8bde7f72003-06-27 21:31:46 +00002984 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002985 /* Put the packet descriptor in the ActiveQ. */
2986 QQ_PushTail (&pDevice->TxPacketActiveQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00002987
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002988 if (pDevice->NicSendBd) {
2989 pSendBd = &pDevice->pSendBdVirt[StartIdx];
2990 pShadowSendBd = &pDevice->ShadowSendBd[StartIdx];
wdenkc6097192002-11-03 00:24:07 +00002991
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002992 while (StartIdx != Idx) {
2993 LM_UINT32 Value32;
wdenkc6097192002-11-03 00:24:07 +00002994
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07002995 if ((Value32 = pTmpSendBd->HostAddr.High) !=
2996 pShadowSendBd->HostAddr.High) {
2997 __raw_writel (Value32,
2998 &(pSendBd->HostAddr.High));
2999 pShadowSendBd->HostAddr.High = Value32;
3000 }
wdenkc6097192002-11-03 00:24:07 +00003001
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003002 __raw_writel (pTmpSendBd->HostAddr.Low,
3003 &(pSendBd->HostAddr.Low));
wdenkc6097192002-11-03 00:24:07 +00003004
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003005 if ((Value32 = pTmpSendBd->u1.Len_Flags) !=
3006 pShadowSendBd->u1.Len_Flags) {
3007 __raw_writel (Value32,
3008 &(pSendBd->u1.Len_Flags));
3009 pShadowSendBd->u1.Len_Flags = Value32;
3010 }
wdenkc6097192002-11-03 00:24:07 +00003011
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003012 if (pPacket->Flags & SND_BD_FLAG_VLAN_TAG) {
3013 __raw_writel (pTmpSendBd->u2.VlanTag,
3014 &(pSendBd->u2.VlanTag));
3015 }
wdenkc6097192002-11-03 00:24:07 +00003016
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003017 StartIdx =
3018 (StartIdx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3019 if (StartIdx == 0)
3020 pSendBd = &pDevice->pSendBdVirt[0];
3021 else
3022 pSendBd++;
3023 pTmpSendBd++;
3024 }
3025 wmb ();
3026 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3027
3028 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
3029 MB_REG_WR (pDevice, Mailbox.SendNicProdIdx[0].Low, Idx);
3030 }
3031 } else {
3032 wmb ();
3033 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low, Idx);
3034
3035 if (T3_CHIP_REV (pDevice->ChipRevId) == T3_CHIP_REV_5700_BX) {
3036 MB_REG_WR (pDevice, Mailbox.SendHostProdIdx[0].Low,
3037 Idx);
3038 }
wdenk8bde7f72003-06-27 21:31:46 +00003039 }
wdenkc6097192002-11-03 00:24:07 +00003040
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003041 /* Update the SendBdLeft count. */
3042 atomic_sub (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
wdenkc6097192002-11-03 00:24:07 +00003043
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003044 /* Update the producer index. */
3045 pDevice->SendProdIdx = Idx;
wdenkc6097192002-11-03 00:24:07 +00003046
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003047 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00003048}
3049
3050STATIC LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003051LM_Test4GBoundary (PLM_DEVICE_BLOCK pDevice, PLM_PACKET pPacket,
3052 PT3_SND_BD pSendBd)
wdenkc6097192002-11-03 00:24:07 +00003053{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003054 int FragCount;
3055 LM_UINT32 Idx, Base, Len;
wdenkc6097192002-11-03 00:24:07 +00003056
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003057 Idx = pDevice->SendProdIdx;
3058 for (FragCount = 0;;) {
3059 Len = pSendBd->u1.Len_Flags >> 16;
3060 if (((Base = pSendBd->HostAddr.Low) > 0xffffdcc0) &&
3061 (pSendBd->HostAddr.High == 0) &&
3062 ((Base + 8 + Len) < Base)) {
3063 return LM_STATUS_SUCCESS;
3064 }
3065 FragCount++;
3066 if (FragCount >= pPacket->u.Tx.FragCount) {
3067 break;
3068 }
3069 pSendBd++;
3070 if (!pDevice->NicSendBd) {
3071 Idx = (Idx + 1) & T3_SEND_RCB_ENTRY_COUNT_MASK;
3072 if (Idx == 0) {
3073 pSendBd = &pDevice->pSendBdVirt[0];
3074 }
3075 }
wdenk8bde7f72003-06-27 21:31:46 +00003076 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003077 return LM_STATUS_FAILURE;
wdenkc6097192002-11-03 00:24:07 +00003078}
3079
3080/******************************************************************************/
3081/* Description: */
3082/* */
3083/* Return: */
3084/******************************************************************************/
3085__inline static unsigned long
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003086ComputeCrc32 (unsigned char *pBuffer, unsigned long BufferSize)
3087{
3088 unsigned long Reg;
3089 unsigned long Tmp;
3090 unsigned long j, k;
wdenkc6097192002-11-03 00:24:07 +00003091
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003092 Reg = 0xffffffff;
wdenkc6097192002-11-03 00:24:07 +00003093
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003094 for (j = 0; j < BufferSize; j++) {
3095 Reg ^= pBuffer[j];
wdenkc6097192002-11-03 00:24:07 +00003096
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003097 for (k = 0; k < 8; k++) {
3098 Tmp = Reg & 0x01;
wdenkc6097192002-11-03 00:24:07 +00003099
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003100 Reg >>= 1;
wdenkc6097192002-11-03 00:24:07 +00003101
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003102 if (Tmp) {
3103 Reg ^= 0xedb88320;
3104 }
3105 }
wdenk8bde7f72003-06-27 21:31:46 +00003106 }
wdenkc6097192002-11-03 00:24:07 +00003107
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003108 return ~Reg;
3109} /* ComputeCrc32 */
wdenkc6097192002-11-03 00:24:07 +00003110
wdenkc6097192002-11-03 00:24:07 +00003111/******************************************************************************/
3112/* Description: */
3113/* This routine sets the receive control register according to ReceiveMask */
3114/* */
3115/* Return: */
3116/* LM_STATUS_SUCCESS */
3117/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003118LM_STATUS LM_SetReceiveMask (PLM_DEVICE_BLOCK pDevice, LM_UINT32 Mask)
3119{
3120 LM_UINT32 ReceiveMask;
3121 LM_UINT32 RxMode;
3122 LM_UINT32 j, k;
wdenkc6097192002-11-03 00:24:07 +00003123
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003124 ReceiveMask = Mask;
wdenkc6097192002-11-03 00:24:07 +00003125
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003126 RxMode = pDevice->RxMode;
wdenkc6097192002-11-03 00:24:07 +00003127
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003128 if (Mask & LM_ACCEPT_UNICAST) {
3129 Mask &= ~LM_ACCEPT_UNICAST;
wdenk8bde7f72003-06-27 21:31:46 +00003130 }
wdenkc6097192002-11-03 00:24:07 +00003131
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003132 if (Mask & LM_ACCEPT_MULTICAST) {
3133 Mask &= ~LM_ACCEPT_MULTICAST;
wdenk8bde7f72003-06-27 21:31:46 +00003134 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003135
3136 if (Mask & LM_ACCEPT_ALL_MULTICAST) {
3137 Mask &= ~LM_ACCEPT_ALL_MULTICAST;
wdenk8bde7f72003-06-27 21:31:46 +00003138 }
wdenkc6097192002-11-03 00:24:07 +00003139
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003140 if (Mask & LM_ACCEPT_BROADCAST) {
3141 Mask &= ~LM_ACCEPT_BROADCAST;
3142 }
wdenkc6097192002-11-03 00:24:07 +00003143
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003144 RxMode &= ~RX_MODE_PROMISCUOUS_MODE;
3145 if (Mask & LM_PROMISCUOUS_MODE) {
3146 RxMode |= RX_MODE_PROMISCUOUS_MODE;
3147 Mask &= ~LM_PROMISCUOUS_MODE;
3148 }
wdenkc6097192002-11-03 00:24:07 +00003149
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003150 RxMode &= ~(RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED);
3151 if (Mask & LM_ACCEPT_ERROR_PACKET) {
3152 RxMode |= RX_MODE_ACCEPT_RUNTS | RX_MODE_ACCEPT_OVERSIZED;
3153 Mask &= ~LM_ACCEPT_ERROR_PACKET;
3154 }
wdenkc6097192002-11-03 00:24:07 +00003155
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003156 /* Make sure all the bits are valid before committing changes. */
3157 if (Mask) {
3158 return LM_STATUS_FAILURE;
3159 }
3160
3161 /* Commit the new filter. */
3162 pDevice->RxMode = RxMode;
3163 REG_WR (pDevice, MacCtrl.RxMode, RxMode);
3164
3165 pDevice->ReceiveMask = ReceiveMask;
3166
3167 /* Set up the MC hash table. */
3168 if (ReceiveMask & LM_ACCEPT_ALL_MULTICAST) {
3169 for (k = 0; k < 4; k++) {
3170 REG_WR (pDevice, MacCtrl.HashReg[k], 0xffffffff);
3171 }
3172 } else if (ReceiveMask & LM_ACCEPT_MULTICAST) {
3173 LM_UINT32 HashReg[4];
3174
3175 HashReg[0] = 0;
3176 HashReg[1] = 0;
3177 HashReg[2] = 0;
3178 HashReg[3] = 0;
3179 for (j = 0; j < pDevice->McEntryCount; j++) {
3180 LM_UINT32 RegIndex;
3181 LM_UINT32 Bitpos;
3182 LM_UINT32 Crc32;
3183
3184 Crc32 =
3185 ComputeCrc32 (pDevice->McTable[j],
3186 ETHERNET_ADDRESS_SIZE);
3187
3188 /* The most significant 7 bits of the CRC32 (no inversion), */
3189 /* are used to index into one of the possible 128 bit positions. */
3190 Bitpos = ~Crc32 & 0x7f;
3191
3192 /* Hash register index. */
3193 RegIndex = (Bitpos & 0x60) >> 5;
3194
3195 /* Bit to turn on within a hash register. */
3196 Bitpos &= 0x1f;
3197
3198 /* Enable the multicast bit. */
3199 HashReg[RegIndex] |= (1 << Bitpos);
3200 }
3201
3202 /* REV_AX has problem with multicast filtering where it uses both */
3203 /* DA and SA to perform hashing. */
3204 for (k = 0; k < 4; k++) {
3205 REG_WR (pDevice, MacCtrl.HashReg[k], HashReg[k]);
3206 }
3207 } else {
3208 /* Reject all multicast frames. */
3209 for (j = 0; j < 4; j++) {
3210 REG_WR (pDevice, MacCtrl.HashReg[j], 0);
3211 }
3212 }
3213
3214 /* By default, Tigon3 will accept broadcast frames. We need to setup */
3215 if (ReceiveMask & LM_ACCEPT_BROADCAST) {
3216 REG_WR (pDevice,
3217 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3218 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3219 REG_WR (pDevice,
3220 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3221 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3222 REG_WR (pDevice,
3223 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3224 REJECT_BROADCAST_RULE1_RULE & RCV_DISABLE_RULE_MASK);
3225 REG_WR (pDevice,
3226 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3227 REJECT_BROADCAST_RULE1_VALUE & RCV_DISABLE_RULE_MASK);
3228 } else {
3229 REG_WR (pDevice,
3230 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Rule,
3231 REJECT_BROADCAST_RULE1_RULE);
3232 REG_WR (pDevice,
3233 MacCtrl.RcvRules[RCV_RULE1_REJECT_BROADCAST_IDX].Value,
3234 REJECT_BROADCAST_RULE1_VALUE);
3235 REG_WR (pDevice,
3236 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Rule,
3237 REJECT_BROADCAST_RULE2_RULE);
3238 REG_WR (pDevice,
3239 MacCtrl.RcvRules[RCV_RULE2_REJECT_BROADCAST_IDX].Value,
3240 REJECT_BROADCAST_RULE2_VALUE);
3241 }
3242
3243 /* disable the rest of the rules. */
3244 for (j = RCV_LAST_RULE_IDX; j < 16; j++) {
3245 REG_WR (pDevice, MacCtrl.RcvRules[j].Rule, 0);
3246 REG_WR (pDevice, MacCtrl.RcvRules[j].Value, 0);
3247 }
3248
3249 return LM_STATUS_SUCCESS;
3250} /* LM_SetReceiveMask */
wdenkc6097192002-11-03 00:24:07 +00003251
wdenkc6097192002-11-03 00:24:07 +00003252/******************************************************************************/
3253/* Description: */
3254/* Disable the interrupt and put the transmitter and receiver engines in */
3255/* an idle state. Also aborts all pending send requests and receive */
3256/* buffers. */
3257/* */
3258/* Return: */
3259/* LM_STATUS_SUCCESS */
3260/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003261LM_STATUS LM_Abort (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00003262{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003263 PLM_PACKET pPacket;
3264 LM_UINT Idx;
wdenkc6097192002-11-03 00:24:07 +00003265
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003266 LM_DisableInterrupt (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003267
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003268 /* Disable all the state machines. */
3269 LM_CntrlBlock (pDevice, T3_BLOCK_MAC_RX_ENGINE, LM_DISABLE);
3270 LM_CntrlBlock (pDevice, T3_BLOCK_RX_BD_INITIATOR, LM_DISABLE);
3271 LM_CntrlBlock (pDevice, T3_BLOCK_RX_LIST_PLMT, LM_DISABLE);
3272 LM_CntrlBlock (pDevice, T3_BLOCK_RX_LIST_SELECTOR, LM_DISABLE);
3273 LM_CntrlBlock (pDevice, T3_BLOCK_RX_DATA_INITIATOR, LM_DISABLE);
3274 LM_CntrlBlock (pDevice, T3_BLOCK_RX_DATA_COMP, LM_DISABLE);
3275 LM_CntrlBlock (pDevice, T3_BLOCK_RX_BD_COMP, LM_DISABLE);
wdenkc6097192002-11-03 00:24:07 +00003276
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003277 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_SELECTOR, LM_DISABLE);
3278 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_INITIATOR, LM_DISABLE);
3279 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_DATA_INITIATOR, LM_DISABLE);
3280 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_RD, LM_DISABLE);
3281 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_DATA_COMP, LM_DISABLE);
3282 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_COMP, LM_DISABLE);
3283 LM_CntrlBlock (pDevice, T3_BLOCK_SEND_BD_COMP, LM_DISABLE);
wdenkc6097192002-11-03 00:24:07 +00003284
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003285 /* Clear TDE bit */
3286 pDevice->MacMode &= ~MAC_MODE_ENABLE_TDE;
3287 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
wdenkc6097192002-11-03 00:24:07 +00003288
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003289 LM_CntrlBlock (pDevice, T3_BLOCK_MAC_TX_ENGINE, LM_DISABLE);
3290 LM_CntrlBlock (pDevice, T3_BLOCK_HOST_COALESING, LM_DISABLE);
3291 LM_CntrlBlock (pDevice, T3_BLOCK_DMA_WR, LM_DISABLE);
3292 LM_CntrlBlock (pDevice, T3_BLOCK_MBUF_CLUSTER_FREE, LM_DISABLE);
wdenkc6097192002-11-03 00:24:07 +00003293
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003294 /* Reset all FTQs */
3295 REG_WR (pDevice, Ftq.Reset, 0xffffffff);
3296 REG_WR (pDevice, Ftq.Reset, 0x0);
wdenkc6097192002-11-03 00:24:07 +00003297
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003298 LM_CntrlBlock (pDevice, T3_BLOCK_MBUF_MANAGER, LM_DISABLE);
3299 LM_CntrlBlock (pDevice, T3_BLOCK_MEM_ARBITOR, LM_DISABLE);
wdenkc6097192002-11-03 00:24:07 +00003300
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003301 MM_ACQUIRE_INT_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003302
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003303 /* Abort packets that have already queued to go out. */
3304 pPacket = (PLM_PACKET) QQ_PopHead (&pDevice->TxPacketActiveQ.Container);
3305 while (pPacket) {
wdenkc6097192002-11-03 00:24:07 +00003306
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003307 pPacket->PacketStatus = LM_STATUS_TRANSMIT_ABORTED;
3308 pDevice->TxCounters.TxPacketAbortedCnt++;
wdenkc6097192002-11-03 00:24:07 +00003309
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003310 atomic_add (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
wdenkc6097192002-11-03 00:24:07 +00003311
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003312 QQ_PushTail (&pDevice->TxPacketXmittedQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00003313
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003314 pPacket = (PLM_PACKET)
3315 QQ_PopHead (&pDevice->TxPacketActiveQ.Container);
wdenk8bde7f72003-06-27 21:31:46 +00003316 }
wdenkc6097192002-11-03 00:24:07 +00003317
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003318 /* Cleanup the receive return rings. */
3319 LM_ServiceRxInterrupt (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003320
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003321 /* Don't want to indicate rx packets in Ndis miniport shutdown context. */
3322 /* Doing so may cause system crash. */
3323 if (!pDevice->ShuttingDown) {
3324 /* Indicate packets to the protocol. */
3325 MM_IndicateTxPackets (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003326
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003327 /* Indicate received packets to the protocols. */
3328 MM_IndicateRxPackets (pDevice);
3329 } else {
3330 /* Move the receive packet descriptors in the ReceivedQ to the */
3331 /* free queue. */
3332 for (;;) {
3333 pPacket =
3334 (PLM_PACKET) QQ_PopHead (&pDevice->
3335 RxPacketReceivedQ.
3336 Container);
3337 if (pPacket == NULL) {
3338 break;
3339 }
3340 QQ_PushTail (&pDevice->RxPacketFreeQ.Container,
3341 pPacket);
3342 }
3343 }
wdenkc6097192002-11-03 00:24:07 +00003344
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003345 /* Clean up the Std Receive Producer ring. */
3346 Idx = pDevice->pStatusBlkVirt->RcvStdConIdx;
wdenkc6097192002-11-03 00:24:07 +00003347
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003348 while (Idx != pDevice->RxStdProdIdx) {
3349 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3350 MM_UINT_PTR (pDevice->pRxStdBdVirt[Idx].
3351 Opaque));
3352
3353 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
3354
3355 Idx = (Idx + 1) & T3_STD_RCV_RCB_ENTRY_COUNT_MASK;
3356 } /* while */
3357
3358 /* Reinitialize our copy of the indices. */
3359 pDevice->RxStdProdIdx = 0;
wdenkc6097192002-11-03 00:24:07 +00003360
3361#if T3_JUMBO_RCV_RCB_ENTRY_COUNT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003362 /* Clean up the Jumbo Receive Producer ring. */
3363 Idx = pDevice->pStatusBlkVirt->RcvJumboConIdx;
wdenkc6097192002-11-03 00:24:07 +00003364
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003365 while (Idx != pDevice->RxJumboProdIdx) {
3366 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3367 MM_UINT_PTR (pDevice->
3368 pRxJumboBdVirt[Idx].
3369 Opaque));
wdenkc6097192002-11-03 00:24:07 +00003370
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003371 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
wdenkc6097192002-11-03 00:24:07 +00003372
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003373 Idx = (Idx + 1) & T3_JUMBO_RCV_RCB_ENTRY_COUNT_MASK;
3374 } /* while */
wdenkc6097192002-11-03 00:24:07 +00003375
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003376 /* Reinitialize our copy of the indices. */
3377 pDevice->RxJumboProdIdx = 0;
3378#endif /* T3_JUMBO_RCV_RCB_ENTRY_COUNT */
wdenkc6097192002-11-03 00:24:07 +00003379
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003380 MM_RELEASE_INT_LOCK (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003381
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003382 /* Initialize the statistis Block */
3383 pDevice->pStatusBlkVirt->Status = 0;
3384 pDevice->pStatusBlkVirt->RcvStdConIdx = 0;
3385 pDevice->pStatusBlkVirt->RcvJumboConIdx = 0;
3386 pDevice->pStatusBlkVirt->RcvMiniConIdx = 0;
wdenkc6097192002-11-03 00:24:07 +00003387
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003388 return LM_STATUS_SUCCESS;
3389} /* LM_Abort */
wdenkc6097192002-11-03 00:24:07 +00003390
wdenkc6097192002-11-03 00:24:07 +00003391/******************************************************************************/
3392/* Description: */
3393/* Disable the interrupt and put the transmitter and receiver engines in */
3394/* an idle state. Aborts all pending send requests and receive buffers. */
3395/* Also free all the receive buffers. */
3396/* */
3397/* Return: */
3398/* LM_STATUS_SUCCESS */
3399/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003400LM_STATUS LM_Halt (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00003401{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003402 PLM_PACKET pPacket;
3403 LM_UINT32 EntryCnt;
wdenkc6097192002-11-03 00:24:07 +00003404
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003405 LM_Abort (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003406
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003407 /* Get the number of entries in the queue. */
3408 EntryCnt = QQ_GetEntryCnt (&pDevice->RxPacketFreeQ.Container);
3409
3410 /* Make sure all the packets have been accounted for. */
3411 for (EntryCnt = 0; EntryCnt < pDevice->RxPacketDescCnt; EntryCnt++) {
3412 pPacket =
3413 (PLM_PACKET) QQ_PopHead (&pDevice->RxPacketFreeQ.Container);
3414 if (pPacket == 0)
3415 break;
3416
3417 MM_FreeRxBuffer (pDevice, pPacket);
3418
3419 QQ_PushTail (&pDevice->RxPacketFreeQ.Container, pPacket);
wdenk8bde7f72003-06-27 21:31:46 +00003420 }
wdenkc6097192002-11-03 00:24:07 +00003421
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003422 LM_ResetChip (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003423
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003424 /* Restore PCI configuration registers. */
3425 MM_WriteConfig32 (pDevice, PCI_CACHE_LINE_SIZE_REG,
3426 pDevice->SavedCacheLineReg);
3427 LM_RegWrInd (pDevice, PCI_SUBSYSTEM_VENDOR_ID_REG,
3428 (pDevice->SubsystemId << 16) | pDevice->SubsystemVendorId);
wdenkc6097192002-11-03 00:24:07 +00003429
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003430 /* Reprogram the MAC address. */
3431 LM_SetMacAddress (pDevice, pDevice->NodeAddress);
3432
3433 return LM_STATUS_SUCCESS;
3434} /* LM_Halt */
3435
3436STATIC LM_STATUS LM_ResetChip (PLM_DEVICE_BLOCK pDevice)
3437{
3438 LM_UINT32 Value32;
3439 LM_UINT32 j;
3440
3441 /* Wait for access to the nvram interface before resetting. This is */
3442 /* a workaround to prevent EEPROM corruption. */
3443 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
3444 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
3445 /* Request access to the flash interface. */
3446 REG_WR (pDevice, Nvram.SwArb, SW_ARB_REQ_SET1);
3447
3448 for (j = 0; j < 100000; j++) {
3449 Value32 = REG_RD (pDevice, Nvram.SwArb);
3450 if (Value32 & SW_ARB_GNT1) {
3451 break;
3452 }
3453 MM_Wait (10);
3454 }
wdenk8bde7f72003-06-27 21:31:46 +00003455 }
wdenkc6097192002-11-03 00:24:07 +00003456
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003457 /* Global reset. */
3458 REG_WR (pDevice, Grc.MiscCfg, GRC_MISC_CFG_CORE_CLOCK_RESET);
3459 MM_Wait (40);
3460 MM_Wait (40);
3461 MM_Wait (40);
wdenkc6097192002-11-03 00:24:07 +00003462
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003463 /* make sure we re-enable indirect accesses */
3464 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
3465 pDevice->MiscHostCtrl);
wdenkc6097192002-11-03 00:24:07 +00003466
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003467 /* Set MAX PCI retry to zero. */
3468 Value32 =
3469 T3_PCI_STATE_PCI_ROM_ENABLE | T3_PCI_STATE_PCI_ROM_RETRY_ENABLE;
3470 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
3471 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
3472 Value32 |= T3_PCI_STATE_RETRY_SAME_DMA;
3473 }
3474 }
3475 MM_WriteConfig32 (pDevice, T3_PCI_STATE_REG, Value32);
wdenkc6097192002-11-03 00:24:07 +00003476
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003477 /* Restore PCI command register. */
3478 MM_WriteConfig32 (pDevice, PCI_COMMAND_REG,
3479 pDevice->PciCommandStatusWords);
3480
3481 /* Disable PCI-X relaxed ordering bit. */
3482 MM_ReadConfig32 (pDevice, PCIX_CAP_REG, &Value32);
3483 Value32 &= ~PCIX_ENABLE_RELAXED_ORDERING;
3484 MM_WriteConfig32 (pDevice, PCIX_CAP_REG, Value32);
3485
3486 /* Enable memory arbiter. */
3487 REG_WR (pDevice, MemArbiter.Mode, T3_MEM_ARBITER_MODE_ENABLE);
3488
3489#ifdef BIG_ENDIAN_PCI /* This from jfd */
3490 Value32 = GRC_MODE_WORD_SWAP_DATA | GRC_MODE_WORD_SWAP_NON_FRAME_DATA;
wdenkc6097192002-11-03 00:24:07 +00003491#else
3492#ifdef BIG_ENDIAN_HOST
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003493 /* Reconfigure the mode register. */
3494 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA |
3495 GRC_MODE_WORD_SWAP_NON_FRAME_DATA |
3496 GRC_MODE_BYTE_SWAP_DATA | GRC_MODE_WORD_SWAP_DATA;
wdenkc6097192002-11-03 00:24:07 +00003497#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003498 /* Reconfigure the mode register. */
3499 Value32 = GRC_MODE_BYTE_SWAP_NON_FRAME_DATA | GRC_MODE_BYTE_SWAP_DATA;
wdenkc6097192002-11-03 00:24:07 +00003500#endif
3501#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003502 REG_WR (pDevice, Grc.Mode, Value32);
wdenkc6097192002-11-03 00:24:07 +00003503
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003504 /* Prevent PXE from restarting. */
3505 MEM_WR_OFFSET (pDevice, 0x0b50, T3_MAGIC_NUM);
wdenkc6097192002-11-03 00:24:07 +00003506
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003507 if (pDevice->EnableTbi) {
3508 pDevice->MacMode = MAC_MODE_PORT_MODE_TBI;
3509 REG_WR (pDevice, MacCtrl.Mode, MAC_MODE_PORT_MODE_TBI);
3510 } else {
3511 REG_WR (pDevice, MacCtrl.Mode, 0);
wdenk8bde7f72003-06-27 21:31:46 +00003512 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003513
3514 /* Wait for the firmware to finish initialization. */
3515 for (j = 0; j < 100000; j++) {
3516 MM_Wait (10);
3517
3518 Value32 = MEM_RD_OFFSET (pDevice, 0x0b50);
3519 if (Value32 == ~T3_MAGIC_NUM) {
3520 break;
3521 }
3522 }
3523 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00003524}
3525
3526/******************************************************************************/
3527/* Description: */
3528/* */
3529/* Return: */
3530/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003531__inline static void LM_ServiceTxInterrupt (PLM_DEVICE_BLOCK pDevice)
3532{
3533 PLM_PACKET pPacket;
3534 LM_UINT32 HwConIdx;
3535 LM_UINT32 SwConIdx;
wdenkc6097192002-11-03 00:24:07 +00003536
wdenk8bde7f72003-06-27 21:31:46 +00003537 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
wdenkc6097192002-11-03 00:24:07 +00003538
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003539 /* Get our copy of the consumer index. The buffer descriptors */
3540 /* that are in between the consumer indices are freed. */
3541 SwConIdx = pDevice->SendConIdx;
wdenkc6097192002-11-03 00:24:07 +00003542
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003543 /* Move the packets from the TxPacketActiveQ that are sent out to */
3544 /* the TxPacketXmittedQ. Packets that are sent use the */
3545 /* descriptors that are between SwConIdx and HwConIdx. */
3546 while (SwConIdx != HwConIdx) {
3547 /* Get the packet that was sent from the TxPacketActiveQ. */
3548 pPacket =
3549 (PLM_PACKET) QQ_PopHead (&pDevice->TxPacketActiveQ.
3550 Container);
wdenkc6097192002-11-03 00:24:07 +00003551
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003552 /* Set the return status. */
3553 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3554
3555 /* Put the packet in the TxPacketXmittedQ for indication later. */
3556 QQ_PushTail (&pDevice->TxPacketXmittedQ.Container, pPacket);
3557
3558 /* Move to the next packet's BD. */
3559 SwConIdx = (SwConIdx + pPacket->u.Tx.FragCount) &
3560 T3_SEND_RCB_ENTRY_COUNT_MASK;
3561
3562 /* Update the number of unused BDs. */
3563 atomic_add (pPacket->u.Tx.FragCount, &pDevice->SendBdLeft);
3564
3565 /* Get the new updated HwConIdx. */
3566 HwConIdx = pDevice->pStatusBlkVirt->Idx[0].SendConIdx;
3567 } /* while */
3568
3569 /* Save the new SwConIdx. */
3570 pDevice->SendConIdx = SwConIdx;
3571
3572} /* LM_ServiceTxInterrupt */
wdenkc6097192002-11-03 00:24:07 +00003573
wdenkc6097192002-11-03 00:24:07 +00003574/******************************************************************************/
3575/* Description: */
3576/* */
3577/* Return: */
3578/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003579__inline static void LM_ServiceRxInterrupt (PLM_DEVICE_BLOCK pDevice)
3580{
3581 PLM_PACKET pPacket;
3582 PT3_RCV_BD pRcvBd;
3583 LM_UINT32 HwRcvRetProdIdx;
3584 LM_UINT32 SwRcvRetConIdx;
wdenkc6097192002-11-03 00:24:07 +00003585
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003586 /* Loop thru the receive return rings for received packets. */
wdenk8bde7f72003-06-27 21:31:46 +00003587 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
wdenkc6097192002-11-03 00:24:07 +00003588
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003589 SwRcvRetConIdx = pDevice->RcvRetConIdx;
3590 while (SwRcvRetConIdx != HwRcvRetProdIdx) {
3591 pRcvBd = &pDevice->pRcvRetBdVirt[SwRcvRetConIdx];
wdenkc6097192002-11-03 00:24:07 +00003592
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003593 /* Get the received packet descriptor. */
3594 pPacket = (PLM_PACKET) (MM_UINT_PTR (pDevice->pPacketDescBase) +
3595 MM_UINT_PTR (pRcvBd->Opaque));
wdenkc6097192002-11-03 00:24:07 +00003596
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003597 /* Check the error flag. */
3598 if (pRcvBd->ErrorFlag &&
3599 pRcvBd->ErrorFlag != RCV_BD_ERR_ODD_NIBBLED_RCVD_MII) {
3600 pPacket->PacketStatus = LM_STATUS_FAILURE;
3601
3602 pDevice->RxCounters.RxPacketErrCnt++;
3603
3604 if (pRcvBd->ErrorFlag & RCV_BD_ERR_BAD_CRC) {
3605 pDevice->RxCounters.RxErrCrcCnt++;
3606 }
3607
3608 if (pRcvBd->ErrorFlag & RCV_BD_ERR_COLL_DETECT) {
3609 pDevice->RxCounters.RxErrCollCnt++;
3610 }
3611
3612 if (pRcvBd->ErrorFlag & RCV_BD_ERR_LINK_LOST_DURING_PKT) {
3613 pDevice->RxCounters.RxErrLinkLostCnt++;
3614 }
3615
3616 if (pRcvBd->ErrorFlag & RCV_BD_ERR_PHY_DECODE_ERR) {
3617 pDevice->RxCounters.RxErrPhyDecodeCnt++;
3618 }
3619
3620 if (pRcvBd->ErrorFlag & RCV_BD_ERR_ODD_NIBBLED_RCVD_MII) {
3621 pDevice->RxCounters.RxErrOddNibbleCnt++;
3622 }
3623
3624 if (pRcvBd->ErrorFlag & RCV_BD_ERR_MAC_ABORT) {
3625 pDevice->RxCounters.RxErrMacAbortCnt++;
3626 }
3627
3628 if (pRcvBd->ErrorFlag & RCV_BD_ERR_LEN_LT_64) {
3629 pDevice->RxCounters.RxErrShortPacketCnt++;
3630 }
3631
3632 if (pRcvBd->ErrorFlag & RCV_BD_ERR_TRUNC_NO_RESOURCES) {
3633 pDevice->RxCounters.RxErrNoResourceCnt++;
3634 }
3635
3636 if (pRcvBd->ErrorFlag & RCV_BD_ERR_GIANT_FRAME_RCVD) {
3637 pDevice->RxCounters.RxErrLargePacketCnt++;
3638 }
3639 } else {
3640 pPacket->PacketStatus = LM_STATUS_SUCCESS;
3641 pPacket->PacketSize = pRcvBd->Len - 4;
3642
3643 pPacket->Flags = pRcvBd->Flags;
3644 if (pRcvBd->Flags & RCV_BD_FLAG_VLAN_TAG) {
3645 pPacket->VlanTag = pRcvBd->VlanTag;
3646 }
3647
3648 pPacket->u.Rx.TcpUdpChecksum = pRcvBd->TcpUdpCksum;
3649 }
3650
3651 /* Put the packet descriptor containing the received packet */
3652 /* buffer in the RxPacketReceivedQ for indication later. */
3653 QQ_PushTail (&pDevice->RxPacketReceivedQ.Container, pPacket);
3654
3655 /* Go to the next buffer descriptor. */
3656 SwRcvRetConIdx = (SwRcvRetConIdx + 1) &
3657 T3_RCV_RETURN_RCB_ENTRY_COUNT_MASK;
3658
3659 /* Get the updated HwRcvRetProdIdx. */
3660 HwRcvRetProdIdx = pDevice->pStatusBlkVirt->Idx[0].RcvProdIdx;
3661 } /* while */
3662
3663 pDevice->RcvRetConIdx = SwRcvRetConIdx;
3664
3665 /* Update the receive return ring consumer index. */
3666 MB_REG_WR (pDevice, Mailbox.RcvRetConIdx[0].Low, SwRcvRetConIdx);
3667} /* LM_ServiceRxInterrupt */
wdenkc6097192002-11-03 00:24:07 +00003668
wdenkc6097192002-11-03 00:24:07 +00003669/******************************************************************************/
3670/* Description: */
3671/* This is the interrupt event handler routine. It acknowledges all */
3672/* pending interrupts and process all pending events. */
3673/* */
3674/* Return: */
3675/* LM_STATUS_SUCCESS */
3676/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003677LM_STATUS LM_ServiceInterrupts (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00003678{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003679 LM_UINT32 Value32;
3680 int ServicePhyInt = FALSE;
wdenkc6097192002-11-03 00:24:07 +00003681
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003682 /* Setup the phy chip whenever the link status changes. */
3683 if (pDevice->LinkChngMode == T3_LINK_CHNG_MODE_USE_STATUS_REG) {
3684 Value32 = REG_RD (pDevice, MacCtrl.Status);
3685 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
3686 if (Value32 & MAC_STATUS_MI_INTERRUPT) {
3687 ServicePhyInt = TRUE;
3688 }
3689 } else if (Value32 & MAC_STATUS_LINK_STATE_CHANGED) {
3690 ServicePhyInt = TRUE;
3691 }
3692 } else {
3693 if (pDevice->pStatusBlkVirt->
3694 Status & STATUS_BLOCK_LINK_CHANGED_STATUS) {
3695 pDevice->pStatusBlkVirt->Status =
3696 STATUS_BLOCK_UPDATED | (pDevice->pStatusBlkVirt->
3697 Status &
3698 ~STATUS_BLOCK_LINK_CHANGED_STATUS);
3699 ServicePhyInt = TRUE;
3700 }
wdenk8bde7f72003-06-27 21:31:46 +00003701 }
wdenkc6097192002-11-03 00:24:07 +00003702#if INCLUDE_TBI_SUPPORT
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003703 if (pDevice->IgnoreTbiLinkChange == TRUE) {
3704 ServicePhyInt = FALSE;
3705 }
wdenkc6097192002-11-03 00:24:07 +00003706#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003707 if (ServicePhyInt == TRUE) {
3708 LM_SetupPhy (pDevice);
wdenk8bde7f72003-06-27 21:31:46 +00003709 }
wdenkc6097192002-11-03 00:24:07 +00003710
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003711 /* Service receive and transmit interrupts. */
3712 LM_ServiceRxInterrupt (pDevice);
3713 LM_ServiceTxInterrupt (pDevice);
wdenkc6097192002-11-03 00:24:07 +00003714
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003715 /* No spinlock for this queue since this routine is serialized. */
3716 if (!QQ_Empty (&pDevice->RxPacketReceivedQ.Container)) {
3717 /* Indicate receive packets. */
3718 MM_IndicateRxPackets (pDevice);
3719 /* LM_QueueRxPackets(pDevice); */
wdenk8bde7f72003-06-27 21:31:46 +00003720 }
wdenkc6097192002-11-03 00:24:07 +00003721
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003722 /* No spinlock for this queue since this routine is serialized. */
3723 if (!QQ_Empty (&pDevice->TxPacketXmittedQ.Container)) {
3724 MM_IndicateTxPackets (pDevice);
3725 }
wdenkc6097192002-11-03 00:24:07 +00003726
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003727 return LM_STATUS_SUCCESS;
3728} /* LM_ServiceInterrupts */
wdenkc6097192002-11-03 00:24:07 +00003729
wdenkc6097192002-11-03 00:24:07 +00003730/******************************************************************************/
3731/* Description: */
3732/* */
3733/* Return: */
3734/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003735LM_STATUS LM_MulticastAdd (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress)
wdenkc6097192002-11-03 00:24:07 +00003736{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003737 PLM_UINT8 pEntry;
3738 LM_UINT32 j;
wdenkc6097192002-11-03 00:24:07 +00003739
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003740 pEntry = pDevice->McTable[0];
3741 for (j = 0; j < pDevice->McEntryCount; j++) {
3742 if (IS_ETH_ADDRESS_EQUAL (pEntry, pMcAddress)) {
3743 /* Found a match, increment the instance count. */
3744 pEntry[LM_MC_INSTANCE_COUNT_INDEX] += 1;
wdenkc6097192002-11-03 00:24:07 +00003745
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003746 return LM_STATUS_SUCCESS;
3747 }
3748
3749 pEntry += LM_MC_ENTRY_SIZE;
3750 }
3751
3752 if (pDevice->McEntryCount >= LM_MAX_MC_TABLE_SIZE) {
3753 return LM_STATUS_FAILURE;
3754 }
3755
3756 pEntry = pDevice->McTable[pDevice->McEntryCount];
3757
3758 COPY_ETH_ADDRESS (pMcAddress, pEntry);
3759 pEntry[LM_MC_INSTANCE_COUNT_INDEX] = 1;
3760
3761 pDevice->McEntryCount++;
3762
3763 LM_SetReceiveMask (pDevice, pDevice->ReceiveMask | LM_ACCEPT_MULTICAST);
3764
3765 return LM_STATUS_SUCCESS;
3766} /* LM_MulticastAdd */
3767
3768/******************************************************************************/
3769/* Description: */
3770/* */
3771/* Return: */
3772/******************************************************************************/
3773LM_STATUS LM_MulticastDel (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMcAddress)
3774{
3775 PLM_UINT8 pEntry;
3776 LM_UINT32 j;
3777
3778 pEntry = pDevice->McTable[0];
3779 for (j = 0; j < pDevice->McEntryCount; j++) {
3780 if (IS_ETH_ADDRESS_EQUAL (pEntry, pMcAddress)) {
3781 /* Found a match, decrement the instance count. */
3782 pEntry[LM_MC_INSTANCE_COUNT_INDEX] -= 1;
3783
3784 /* No more instance left, remove the address from the table. */
3785 /* Move the last entry in the table to the delete slot. */
3786 if (pEntry[LM_MC_INSTANCE_COUNT_INDEX] == 0 &&
3787 pDevice->McEntryCount > 1) {
3788
3789 COPY_ETH_ADDRESS (pDevice->
3790 McTable[pDevice->
3791 McEntryCount - 1],
3792 pEntry);
3793 pEntry[LM_MC_INSTANCE_COUNT_INDEX] =
3794 pDevice->McTable[pDevice->McEntryCount - 1]
3795 [LM_MC_INSTANCE_COUNT_INDEX];
3796 }
3797 pDevice->McEntryCount--;
3798
3799 /* Update the receive mask if the table is empty. */
3800 if (pDevice->McEntryCount == 0) {
3801 LM_SetReceiveMask (pDevice,
3802 pDevice->
3803 ReceiveMask &
3804 ~LM_ACCEPT_MULTICAST);
3805 }
3806
3807 return LM_STATUS_SUCCESS;
3808 }
3809
3810 pEntry += LM_MC_ENTRY_SIZE;
3811 }
3812
3813 return LM_STATUS_FAILURE;
3814} /* LM_MulticastDel */
3815
3816/******************************************************************************/
3817/* Description: */
3818/* */
3819/* Return: */
3820/******************************************************************************/
3821LM_STATUS LM_MulticastClear (PLM_DEVICE_BLOCK pDevice)
3822{
3823 pDevice->McEntryCount = 0;
3824
3825 LM_SetReceiveMask (pDevice,
3826 pDevice->ReceiveMask & ~LM_ACCEPT_MULTICAST);
3827
3828 return LM_STATUS_SUCCESS;
3829} /* LM_MulticastClear */
3830
3831/******************************************************************************/
3832/* Description: */
3833/* */
3834/* Return: */
3835/******************************************************************************/
3836LM_STATUS LM_SetMacAddress (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pMacAddress)
3837{
3838 LM_UINT32 j;
3839
3840 for (j = 0; j < 4; j++) {
3841 REG_WR (pDevice, MacCtrl.MacAddr[j].High,
3842 (pMacAddress[0] << 8) | pMacAddress[1]);
3843 REG_WR (pDevice, MacCtrl.MacAddr[j].Low,
3844 (pMacAddress[2] << 24) | (pMacAddress[3] << 16) |
3845 (pMacAddress[4] << 8) | pMacAddress[5]);
3846 }
3847
3848 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00003849}
3850
wdenkc6097192002-11-03 00:24:07 +00003851/******************************************************************************/
3852/* Description: */
3853/* Sets up the default line speed, and duplex modes based on the requested */
3854/* media type. */
3855/* */
3856/* Return: */
3857/* None. */
3858/******************************************************************************/
3859static LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003860LM_TranslateRequestedMediaType (LM_REQUESTED_MEDIA_TYPE RequestedMediaType,
3861 PLM_MEDIA_TYPE pMediaType,
3862 PLM_LINE_SPEED pLineSpeed,
3863 PLM_DUPLEX_MODE pDuplexMode)
3864{
3865 *pMediaType = LM_MEDIA_TYPE_AUTO;
3866 *pLineSpeed = LM_LINE_SPEED_UNKNOWN;
3867 *pDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
wdenkc6097192002-11-03 00:24:07 +00003868
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003869 /* determine media type */
3870 switch (RequestedMediaType) {
wdenk8bde7f72003-06-27 21:31:46 +00003871 case LM_REQUESTED_MEDIA_TYPE_BNC:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003872 *pMediaType = LM_MEDIA_TYPE_BNC;
3873 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3874 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3875 break;
wdenkc6097192002-11-03 00:24:07 +00003876
wdenk8bde7f72003-06-27 21:31:46 +00003877 case LM_REQUESTED_MEDIA_TYPE_UTP_AUTO:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003878 *pMediaType = LM_MEDIA_TYPE_UTP;
3879 break;
wdenkc6097192002-11-03 00:24:07 +00003880
wdenk8bde7f72003-06-27 21:31:46 +00003881 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003882 *pMediaType = LM_MEDIA_TYPE_UTP;
3883 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3884 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3885 break;
wdenkc6097192002-11-03 00:24:07 +00003886
wdenk8bde7f72003-06-27 21:31:46 +00003887 case LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS_FULL_DUPLEX:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003888 *pMediaType = LM_MEDIA_TYPE_UTP;
3889 *pLineSpeed = LM_LINE_SPEED_10MBPS;
3890 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3891 break;
wdenkc6097192002-11-03 00:24:07 +00003892
wdenk8bde7f72003-06-27 21:31:46 +00003893 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003894 *pMediaType = LM_MEDIA_TYPE_UTP;
3895 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3896 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3897 break;
wdenkc6097192002-11-03 00:24:07 +00003898
wdenk8bde7f72003-06-27 21:31:46 +00003899 case LM_REQUESTED_MEDIA_TYPE_UTP_100MBPS_FULL_DUPLEX:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003900 *pMediaType = LM_MEDIA_TYPE_UTP;
3901 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3902 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3903 break;
wdenkc6097192002-11-03 00:24:07 +00003904
wdenk8bde7f72003-06-27 21:31:46 +00003905 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003906 *pMediaType = LM_MEDIA_TYPE_UTP;
3907 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3908 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3909 break;
wdenkc6097192002-11-03 00:24:07 +00003910
wdenk8bde7f72003-06-27 21:31:46 +00003911 case LM_REQUESTED_MEDIA_TYPE_UTP_1000MBPS_FULL_DUPLEX:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003912 *pMediaType = LM_MEDIA_TYPE_UTP;
3913 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3914 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3915 break;
wdenkc6097192002-11-03 00:24:07 +00003916
wdenk8bde7f72003-06-27 21:31:46 +00003917 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003918 *pMediaType = LM_MEDIA_TYPE_FIBER;
3919 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3920 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3921 break;
wdenkc6097192002-11-03 00:24:07 +00003922
wdenk8bde7f72003-06-27 21:31:46 +00003923 case LM_REQUESTED_MEDIA_TYPE_FIBER_100MBPS_FULL_DUPLEX:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003924 *pMediaType = LM_MEDIA_TYPE_FIBER;
3925 *pLineSpeed = LM_LINE_SPEED_100MBPS;
3926 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3927 break;
wdenkc6097192002-11-03 00:24:07 +00003928
wdenk8bde7f72003-06-27 21:31:46 +00003929 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003930 *pMediaType = LM_MEDIA_TYPE_FIBER;
3931 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3932 *pDuplexMode = LM_DUPLEX_MODE_HALF;
3933 break;
wdenkc6097192002-11-03 00:24:07 +00003934
wdenk8bde7f72003-06-27 21:31:46 +00003935 case LM_REQUESTED_MEDIA_TYPE_FIBER_1000MBPS_FULL_DUPLEX:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003936 *pMediaType = LM_MEDIA_TYPE_FIBER;
3937 *pLineSpeed = LM_LINE_SPEED_1000MBPS;
3938 *pDuplexMode = LM_DUPLEX_MODE_FULL;
3939 break;
wdenkc6097192002-11-03 00:24:07 +00003940
wdenk8bde7f72003-06-27 21:31:46 +00003941 default:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003942 break;
3943 } /* switch */
wdenkc6097192002-11-03 00:24:07 +00003944
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003945 return LM_STATUS_SUCCESS;
3946} /* LM_TranslateRequestedMediaType */
wdenkc6097192002-11-03 00:24:07 +00003947
3948/******************************************************************************/
3949/* Description: */
3950/* */
3951/* Return: */
3952/* LM_STATUS_LINK_ACTIVE */
3953/* LM_STATUS_LINK_DOWN */
3954/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003955static LM_STATUS LM_InitBcm540xPhy (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00003956{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003957 LM_LINE_SPEED CurrentLineSpeed;
3958 LM_DUPLEX_MODE CurrentDuplexMode;
3959 LM_STATUS CurrentLinkStatus;
3960 LM_UINT32 Value32;
3961 LM_UINT32 j;
wdenkc6097192002-11-03 00:24:07 +00003962
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003963#if 1 /* jmb: bugfix -- moved here, out of code that sets initial pwr state */
3964 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x2);
wdenkc6097192002-11-03 00:24:07 +00003965#endif
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003966 if ((pDevice->PhyId & PHY_ID_MASK) == PHY_BCM5401_PHY_ID) {
3967 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3968 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
wdenkc6097192002-11-03 00:24:07 +00003969
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003970 if (!pDevice->InitDone) {
3971 Value32 = 0;
wdenk8bde7f72003-06-27 21:31:46 +00003972 }
wdenkc6097192002-11-03 00:24:07 +00003973
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003974 if (!(Value32 & PHY_STATUS_LINK_PASS)) {
3975 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x0c20);
wdenkc6097192002-11-03 00:24:07 +00003976
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07003977 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0012);
3978 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1804);
3979
3980 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x0013);
3981 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x1204);
3982
3983 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
3984 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0132);
3985
3986 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x8006);
3987 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0232);
3988
3989 LM_WritePhy (pDevice, BCM540X_DSP_ADDRESS_REG, 0x201f);
3990 LM_WritePhy (pDevice, BCM540X_DSP_RW_PORT, 0x0a20);
3991
3992 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3993 for (j = 0; j < 1000; j++) {
3994 MM_Wait (10);
3995
3996 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
3997 if (Value32 & PHY_STATUS_LINK_PASS) {
3998 MM_Wait (40);
3999 break;
4000 }
wdenk8bde7f72003-06-27 21:31:46 +00004001 }
wdenkc6097192002-11-03 00:24:07 +00004002
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004003 if ((pDevice->PhyId & PHY_ID_REV_MASK) ==
4004 PHY_BCM5401_B0_REV) {
4005 if (!(Value32 & PHY_STATUS_LINK_PASS)
4006 && (pDevice->OldLineSpeed ==
4007 LM_LINE_SPEED_1000MBPS)) {
4008 LM_WritePhy (pDevice, PHY_CTRL_REG,
4009 PHY_CTRL_PHY_RESET);
4010 for (j = 0; j < 100; j++) {
4011 MM_Wait (10);
wdenkc6097192002-11-03 00:24:07 +00004012
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004013 LM_ReadPhy (pDevice,
4014 PHY_CTRL_REG,
4015 &Value32);
4016 if (!
4017 (Value32 &
4018 PHY_CTRL_PHY_RESET)) {
4019 MM_Wait (40);
4020 break;
4021 }
4022 }
wdenkc6097192002-11-03 00:24:07 +00004023
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004024 LM_WritePhy (pDevice, BCM5401_AUX_CTRL,
4025 0x0c20);
wdenkc6097192002-11-03 00:24:07 +00004026
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004027 LM_WritePhy (pDevice,
4028 BCM540X_DSP_ADDRESS_REG,
4029 0x0012);
4030 LM_WritePhy (pDevice,
4031 BCM540X_DSP_RW_PORT,
4032 0x1804);
wdenkc6097192002-11-03 00:24:07 +00004033
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004034 LM_WritePhy (pDevice,
4035 BCM540X_DSP_ADDRESS_REG,
4036 0x0013);
4037 LM_WritePhy (pDevice,
4038 BCM540X_DSP_RW_PORT,
4039 0x1204);
wdenkc6097192002-11-03 00:24:07 +00004040
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004041 LM_WritePhy (pDevice,
4042 BCM540X_DSP_ADDRESS_REG,
4043 0x8006);
4044 LM_WritePhy (pDevice,
4045 BCM540X_DSP_RW_PORT,
4046 0x0132);
4047
4048 LM_WritePhy (pDevice,
4049 BCM540X_DSP_ADDRESS_REG,
4050 0x8006);
4051 LM_WritePhy (pDevice,
4052 BCM540X_DSP_RW_PORT,
4053 0x0232);
4054
4055 LM_WritePhy (pDevice,
4056 BCM540X_DSP_ADDRESS_REG,
4057 0x201f);
4058 LM_WritePhy (pDevice,
4059 BCM540X_DSP_RW_PORT,
4060 0x0a20);
4061 }
4062 }
wdenk8bde7f72003-06-27 21:31:46 +00004063 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004064 } else if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
4065 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
4066 /* Bug: 5701 A0, B0 TX CRC workaround. */
4067 LM_WritePhy (pDevice, 0x15, 0x0a75);
4068 LM_WritePhy (pDevice, 0x1c, 0x8c68);
4069 LM_WritePhy (pDevice, 0x1c, 0x8d68);
4070 LM_WritePhy (pDevice, 0x1c, 0x8c68);
wdenk8bde7f72003-06-27 21:31:46 +00004071 }
wdenkc6097192002-11-03 00:24:07 +00004072
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004073 /* Acknowledge interrupts. */
4074 LM_ReadPhy (pDevice, BCM540X_INT_STATUS_REG, &Value32);
4075 LM_ReadPhy (pDevice, BCM540X_INT_STATUS_REG, &Value32);
wdenkc6097192002-11-03 00:24:07 +00004076
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004077 /* Configure the interrupt mask. */
4078 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
4079 LM_WritePhy (pDevice, BCM540X_INT_MASK_REG,
4080 ~BCM540X_INT_LINK_CHANGE);
wdenk8bde7f72003-06-27 21:31:46 +00004081 }
wdenkc6097192002-11-03 00:24:07 +00004082
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004083 /* Configure PHY led mode. */
4084 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701 ||
4085 (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700)) {
4086 if (pDevice->LedMode == LED_MODE_THREE_LINK) {
4087 LM_WritePhy (pDevice, BCM540X_EXT_CTRL_REG,
4088 BCM540X_EXT_CTRL_LINK3_LED_MODE);
4089 } else {
4090 LM_WritePhy (pDevice, BCM540X_EXT_CTRL_REG, 0);
wdenk8bde7f72003-06-27 21:31:46 +00004091 }
wdenk8bde7f72003-06-27 21:31:46 +00004092 }
wdenkc6097192002-11-03 00:24:07 +00004093
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004094 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
wdenkc6097192002-11-03 00:24:07 +00004095
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004096 /* Get current link and duplex mode. */
4097 for (j = 0; j < 100; j++) {
4098 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4099 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4100
4101 if (Value32 & PHY_STATUS_LINK_PASS) {
4102 break;
4103 }
4104 MM_Wait (40);
4105 }
4106
4107 if (Value32 & PHY_STATUS_LINK_PASS) {
4108
4109 /* Determine the current line and duplex settings. */
4110 LM_ReadPhy (pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4111 for (j = 0; j < 2000; j++) {
4112 MM_Wait (10);
4113
4114 LM_ReadPhy (pDevice, BCM540X_AUX_STATUS_REG, &Value32);
4115 if (Value32) {
4116 break;
4117 }
4118 }
4119
4120 switch (Value32 & BCM540X_AUX_SPEED_MASK) {
4121 case BCM540X_AUX_10BASET_HD:
4122 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4123 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4124 break;
4125
4126 case BCM540X_AUX_10BASET_FD:
4127 CurrentLineSpeed = LM_LINE_SPEED_10MBPS;
4128 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4129 break;
4130
4131 case BCM540X_AUX_100BASETX_HD:
4132 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4133 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4134 break;
4135
4136 case BCM540X_AUX_100BASETX_FD:
4137 CurrentLineSpeed = LM_LINE_SPEED_100MBPS;
4138 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4139 break;
4140
4141 case BCM540X_AUX_100BASET_HD:
4142 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4143 CurrentDuplexMode = LM_DUPLEX_MODE_HALF;
4144 break;
4145
4146 case BCM540X_AUX_100BASET_FD:
4147 CurrentLineSpeed = LM_LINE_SPEED_1000MBPS;
4148 CurrentDuplexMode = LM_DUPLEX_MODE_FULL;
4149 break;
4150
4151 default:
4152
4153 CurrentLineSpeed = LM_LINE_SPEED_UNKNOWN;
4154 CurrentDuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4155 break;
4156 }
4157
4158 /* Make sure we are in auto-neg mode. */
4159 for (j = 0; j < 200; j++) {
4160 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
4161 if (Value32 && Value32 != 0x7fff) {
4162 break;
4163 }
4164
4165 if (Value32 == 0 && pDevice->RequestedMediaType ==
4166 LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS) {
4167 break;
4168 }
4169
4170 MM_Wait (10);
4171 }
4172
4173 /* Use the current line settings for "auto" mode. */
4174 if (pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO
4175 || pDevice->RequestedMediaType ==
4176 LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
4177 if (Value32 & PHY_CTRL_AUTO_NEG_ENABLE) {
4178 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4179
4180 /* We may be exiting low power mode and the link is in */
4181 /* 10mb. In this case, we need to restart autoneg. */
4182 LM_ReadPhy (pDevice, BCM540X_1000BASET_CTRL_REG,
4183 &Value32);
4184 pDevice->advertising1000 = Value32;
4185 /* 5702FE supports 10/100Mb only. */
4186 if (T3_ASIC_REV (pDevice->ChipRevId) !=
4187 T3_ASIC_REV_5703
4188 || pDevice->BondId !=
4189 GRC_MISC_BD_ID_5702FE) {
4190 if (!
4191 (Value32 &
4192 (BCM540X_AN_AD_1000BASET_HALF |
4193 BCM540X_AN_AD_1000BASET_FULL))) {
4194 CurrentLinkStatus =
4195 LM_STATUS_LINK_SETTING_MISMATCH;
4196 }
4197 }
4198 } else {
4199 CurrentLinkStatus =
4200 LM_STATUS_LINK_SETTING_MISMATCH;
4201 }
4202 } else {
4203 /* Force line settings. */
4204 /* Use the current setting if it matches the user's requested */
4205 /* setting. */
4206 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
4207 if ((pDevice->LineSpeed == CurrentLineSpeed) &&
4208 (pDevice->DuplexMode == CurrentDuplexMode)) {
4209 if ((pDevice->DisableAutoNeg &&
4210 !(Value32 & PHY_CTRL_AUTO_NEG_ENABLE)) ||
4211 (!pDevice->DisableAutoNeg &&
4212 (Value32 & PHY_CTRL_AUTO_NEG_ENABLE))) {
4213 CurrentLinkStatus =
4214 LM_STATUS_LINK_ACTIVE;
4215 } else {
4216 CurrentLinkStatus =
4217 LM_STATUS_LINK_SETTING_MISMATCH;
4218 }
4219 } else {
4220 CurrentLinkStatus =
4221 LM_STATUS_LINK_SETTING_MISMATCH;
4222 }
4223 }
4224
4225 /* Save line settings. */
4226 pDevice->LineSpeed = CurrentLineSpeed;
4227 pDevice->DuplexMode = CurrentDuplexMode;
4228 pDevice->MediaType = LM_MEDIA_TYPE_UTP;
4229 }
4230
4231 return CurrentLinkStatus;
4232} /* LM_InitBcm540xPhy */
wdenkc6097192002-11-03 00:24:07 +00004233
4234/******************************************************************************/
4235/* Description: */
4236/* */
4237/* Return: */
4238/******************************************************************************/
4239LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004240LM_SetFlowControl (PLM_DEVICE_BLOCK pDevice,
4241 LM_UINT32 LocalPhyAd, LM_UINT32 RemotePhyAd)
wdenkc6097192002-11-03 00:24:07 +00004242{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004243 LM_FLOW_CONTROL FlowCap;
wdenkc6097192002-11-03 00:24:07 +00004244
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004245 /* Resolve flow control. */
4246 FlowCap = LM_FLOW_CONTROL_NONE;
wdenkc6097192002-11-03 00:24:07 +00004247
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004248 /* See Table 28B-3 of 802.3ab-1999 spec. */
4249 if (pDevice->FlowControlCap & LM_FLOW_CONTROL_AUTO_PAUSE) {
4250 if (LocalPhyAd & PHY_AN_AD_PAUSE_CAPABLE) {
4251 if (LocalPhyAd & PHY_AN_AD_ASYM_PAUSE) {
4252 if (RemotePhyAd &
4253 PHY_LINK_PARTNER_PAUSE_CAPABLE) {
4254 FlowCap =
4255 LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4256 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4257 } else if (RemotePhyAd &
4258 PHY_LINK_PARTNER_ASYM_PAUSE) {
4259 FlowCap = LM_FLOW_CONTROL_RECEIVE_PAUSE;
4260 }
4261 } else {
4262 if (RemotePhyAd &
4263 PHY_LINK_PARTNER_PAUSE_CAPABLE) {
4264 FlowCap =
4265 LM_FLOW_CONTROL_TRANSMIT_PAUSE |
4266 LM_FLOW_CONTROL_RECEIVE_PAUSE;
4267 }
4268 }
4269 } else if (LocalPhyAd & PHY_AN_AD_ASYM_PAUSE) {
4270 if ((RemotePhyAd & PHY_LINK_PARTNER_PAUSE_CAPABLE) &&
4271 (RemotePhyAd & PHY_LINK_PARTNER_ASYM_PAUSE)) {
4272 FlowCap = LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4273 }
wdenk8bde7f72003-06-27 21:31:46 +00004274 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004275 } else {
4276 FlowCap = pDevice->FlowControlCap;
wdenk8bde7f72003-06-27 21:31:46 +00004277 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004278
4279 /* Enable/disable rx PAUSE. */
4280 pDevice->RxMode &= ~RX_MODE_ENABLE_FLOW_CONTROL;
4281 if (FlowCap & LM_FLOW_CONTROL_RECEIVE_PAUSE &&
4282 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4283 pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE)) {
4284 pDevice->FlowControl |= LM_FLOW_CONTROL_RECEIVE_PAUSE;
4285 pDevice->RxMode |= RX_MODE_ENABLE_FLOW_CONTROL;
4286
wdenk8bde7f72003-06-27 21:31:46 +00004287 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004288 REG_WR (pDevice, MacCtrl.RxMode, pDevice->RxMode);
wdenkc6097192002-11-03 00:24:07 +00004289
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004290 /* Enable/disable tx PAUSE. */
4291 pDevice->TxMode &= ~TX_MODE_ENABLE_FLOW_CONTROL;
4292 if (FlowCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE &&
4293 (pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE ||
4294 pDevice->FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE)) {
4295 pDevice->FlowControl |= LM_FLOW_CONTROL_TRANSMIT_PAUSE;
4296 pDevice->TxMode |= TX_MODE_ENABLE_FLOW_CONTROL;
wdenkc6097192002-11-03 00:24:07 +00004297
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004298 }
4299 REG_WR (pDevice, MacCtrl.TxMode, pDevice->TxMode);
wdenkc6097192002-11-03 00:24:07 +00004300
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004301 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00004302}
4303
wdenkc6097192002-11-03 00:24:07 +00004304#if INCLUDE_TBI_SUPPORT
4305/******************************************************************************/
4306/* Description: */
4307/* */
4308/* Return: */
4309/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004310STATIC LM_STATUS LM_InitBcm800xPhy (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00004311{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004312 LM_UINT32 Value32;
4313 LM_UINT32 j;
wdenkc6097192002-11-03 00:24:07 +00004314
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004315 Value32 = REG_RD (pDevice, MacCtrl.Status);
wdenkc6097192002-11-03 00:24:07 +00004316
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004317 /* Reset the SERDES during init and when we have link. */
4318 if (!pDevice->InitDone || Value32 & MAC_STATUS_PCS_SYNCED) {
4319 /* Set PLL lock range. */
4320 LM_WritePhy (pDevice, 0x16, 0x8007);
wdenkc6097192002-11-03 00:24:07 +00004321
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004322 /* Software reset. */
4323 LM_WritePhy (pDevice, 0x00, 0x8000);
wdenkc6097192002-11-03 00:24:07 +00004324
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004325 /* Wait for reset to complete. */
4326 for (j = 0; j < 500; j++) {
4327 MM_Wait (10);
4328 }
4329
4330 /* Config mode; seletct PMA/Ch 1 regs. */
4331 LM_WritePhy (pDevice, 0x10, 0x8411);
4332
4333 /* Enable auto-lock and comdet, select txclk for tx. */
4334 LM_WritePhy (pDevice, 0x11, 0x0a10);
4335
4336 LM_WritePhy (pDevice, 0x18, 0x00a0);
4337 LM_WritePhy (pDevice, 0x16, 0x41ff);
4338
4339 /* Assert and deassert POR. */
4340 LM_WritePhy (pDevice, 0x13, 0x0400);
4341 MM_Wait (40);
4342 LM_WritePhy (pDevice, 0x13, 0x0000);
4343
4344 LM_WritePhy (pDevice, 0x11, 0x0a50);
4345 MM_Wait (40);
4346 LM_WritePhy (pDevice, 0x11, 0x0a10);
4347
4348 /* Delay for signal to stabilize. */
4349 for (j = 0; j < 15000; j++) {
4350 MM_Wait (10);
4351 }
4352
4353 /* Deselect the channel register so we can read the PHY id later. */
4354 LM_WritePhy (pDevice, 0x10, 0x8011);
wdenk8bde7f72003-06-27 21:31:46 +00004355 }
wdenkc6097192002-11-03 00:24:07 +00004356
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004357 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00004358}
4359
wdenkc6097192002-11-03 00:24:07 +00004360/******************************************************************************/
4361/* Description: */
4362/* */
4363/* Return: */
4364/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004365STATIC LM_STATUS LM_SetupFiberPhy (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00004366{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004367 LM_STATUS CurrentLinkStatus;
4368 AUTONEG_STATUS AnStatus = 0;
4369 LM_UINT32 Value32;
4370 LM_UINT32 Cnt;
4371 LM_UINT32 j, k;
wdenkc6097192002-11-03 00:24:07 +00004372
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004373 pDevice->MacMode &= ~(MAC_MODE_HALF_DUPLEX | MAC_MODE_PORT_MODE_MASK);
wdenkc6097192002-11-03 00:24:07 +00004374
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004375 /* Initialize the send_config register. */
4376 REG_WR (pDevice, MacCtrl.TxAutoNeg, 0);
wdenkc6097192002-11-03 00:24:07 +00004377
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004378 /* Enable TBI and full duplex mode. */
4379 pDevice->MacMode |= MAC_MODE_PORT_MODE_TBI;
4380 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
wdenkc6097192002-11-03 00:24:07 +00004381
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004382 /* Initialize the BCM8002 SERDES PHY. */
4383 switch (pDevice->PhyId & PHY_ID_MASK) {
wdenk8bde7f72003-06-27 21:31:46 +00004384 case PHY_BCM8002_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004385 LM_InitBcm800xPhy (pDevice);
4386 break;
wdenkc6097192002-11-03 00:24:07 +00004387
wdenk8bde7f72003-06-27 21:31:46 +00004388 default:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004389 break;
wdenk8bde7f72003-06-27 21:31:46 +00004390 }
wdenkc6097192002-11-03 00:24:07 +00004391
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004392 /* Enable link change interrupt. */
4393 REG_WR (pDevice, MacCtrl.MacEvent,
4394 MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
wdenkc6097192002-11-03 00:24:07 +00004395
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004396 /* Default to link down. */
wdenk8bde7f72003-06-27 21:31:46 +00004397 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004398
4399 /* Get the link status. */
4400 Value32 = REG_RD (pDevice, MacCtrl.Status);
4401 if (Value32 & MAC_STATUS_PCS_SYNCED) {
4402 if ((pDevice->RequestedMediaType ==
4403 LM_REQUESTED_MEDIA_TYPE_AUTO)
4404 || (pDevice->DisableAutoNeg == FALSE)) {
4405 /* auto-negotiation mode. */
4406 /* Initialize the autoneg default capaiblities. */
4407 AutonegInit (&pDevice->AnInfo);
4408
4409 /* Set the context pointer to point to the main device structure. */
4410 pDevice->AnInfo.pContext = pDevice;
4411
4412 /* Setup flow control advertisement register. */
4413 Value32 = GetPhyAdFlowCntrlSettings (pDevice);
4414 if (Value32 & PHY_AN_AD_PAUSE_CAPABLE) {
4415 pDevice->AnInfo.mr_adv_sym_pause = 1;
4416 } else {
4417 pDevice->AnInfo.mr_adv_sym_pause = 0;
4418 }
4419
4420 if (Value32 & PHY_AN_AD_ASYM_PAUSE) {
4421 pDevice->AnInfo.mr_adv_asym_pause = 1;
4422 } else {
4423 pDevice->AnInfo.mr_adv_asym_pause = 0;
4424 }
4425
4426 /* Try to autoneg up to six times. */
4427 if (pDevice->IgnoreTbiLinkChange) {
4428 Cnt = 1;
4429 } else {
4430 Cnt = 6;
4431 }
4432 for (j = 0; j < Cnt; j++) {
4433 REG_WR (pDevice, MacCtrl.TxAutoNeg, 0);
4434
4435 Value32 =
4436 pDevice->MacMode & ~MAC_MODE_PORT_MODE_MASK;
4437 REG_WR (pDevice, MacCtrl.Mode, Value32);
4438 MM_Wait (20);
4439
4440 REG_WR (pDevice, MacCtrl.Mode,
4441 pDevice->
4442 MacMode | MAC_MODE_SEND_CONFIGS);
4443
4444 MM_Wait (20);
4445
4446 pDevice->AnInfo.State = AN_STATE_UNKNOWN;
4447 pDevice->AnInfo.CurrentTime_us = 0;
4448
4449 REG_WR (pDevice, Grc.Timer, 0);
4450 for (k = 0;
4451 (pDevice->AnInfo.CurrentTime_us < 75000)
4452 && (k < 75000); k++) {
4453 AnStatus =
4454 Autoneg8023z (&pDevice->AnInfo);
4455
4456 if ((AnStatus == AUTONEG_STATUS_DONE) ||
4457 (AnStatus == AUTONEG_STATUS_FAILED))
4458 {
4459 break;
4460 }
4461
4462 pDevice->AnInfo.CurrentTime_us =
4463 REG_RD (pDevice, Grc.Timer);
4464
4465 }
4466 if ((AnStatus == AUTONEG_STATUS_DONE) ||
4467 (AnStatus == AUTONEG_STATUS_FAILED)) {
4468 break;
4469 }
4470 if (j >= 1) {
4471 if (!(REG_RD (pDevice, MacCtrl.Status) &
4472 MAC_STATUS_PCS_SYNCED)) {
4473 break;
4474 }
4475 }
4476 }
4477
4478 /* Stop sending configs. */
4479 MM_AnTxIdle (&pDevice->AnInfo);
4480
4481 /* Resolve flow control settings. */
4482 if ((AnStatus == AUTONEG_STATUS_DONE) &&
4483 pDevice->AnInfo.mr_an_complete
4484 && pDevice->AnInfo.mr_link_ok
4485 && pDevice->AnInfo.mr_lp_adv_full_duplex) {
4486 LM_UINT32 RemotePhyAd;
4487 LM_UINT32 LocalPhyAd;
4488
4489 LocalPhyAd = 0;
4490 if (pDevice->AnInfo.mr_adv_sym_pause) {
4491 LocalPhyAd |= PHY_AN_AD_PAUSE_CAPABLE;
4492 }
4493
4494 if (pDevice->AnInfo.mr_adv_asym_pause) {
4495 LocalPhyAd |= PHY_AN_AD_ASYM_PAUSE;
4496 }
4497
4498 RemotePhyAd = 0;
4499 if (pDevice->AnInfo.mr_lp_adv_sym_pause) {
4500 RemotePhyAd |=
4501 PHY_LINK_PARTNER_PAUSE_CAPABLE;
4502 }
4503
4504 if (pDevice->AnInfo.mr_lp_adv_asym_pause) {
4505 RemotePhyAd |=
4506 PHY_LINK_PARTNER_ASYM_PAUSE;
4507 }
4508
4509 LM_SetFlowControl (pDevice, LocalPhyAd,
4510 RemotePhyAd);
4511
4512 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4513 }
4514 for (j = 0; j < 30; j++) {
4515 MM_Wait (20);
4516 REG_WR (pDevice, MacCtrl.Status,
4517 MAC_STATUS_SYNC_CHANGED |
4518 MAC_STATUS_CFG_CHANGED);
4519 MM_Wait (20);
4520 if ((REG_RD (pDevice, MacCtrl.Status) &
4521 (MAC_STATUS_SYNC_CHANGED |
4522 MAC_STATUS_CFG_CHANGED)) == 0)
4523 break;
4524 }
4525 if (pDevice->PollTbiLink) {
4526 Value32 = REG_RD (pDevice, MacCtrl.Status);
4527 if (Value32 & MAC_STATUS_RECEIVING_CFG) {
4528 pDevice->IgnoreTbiLinkChange = TRUE;
4529 } else {
4530 pDevice->IgnoreTbiLinkChange = FALSE;
4531 }
4532 }
4533 Value32 = REG_RD (pDevice, MacCtrl.Status);
4534 if (CurrentLinkStatus == LM_STATUS_LINK_DOWN &&
4535 (Value32 & MAC_STATUS_PCS_SYNCED) &&
4536 ((Value32 & MAC_STATUS_RECEIVING_CFG) == 0)) {
4537 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4538 }
4539 } else {
4540 /* We are forcing line speed. */
4541 pDevice->FlowControlCap &= ~LM_FLOW_CONTROL_AUTO_PAUSE;
4542 LM_SetFlowControl (pDevice, 0, 0);
4543
4544 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
4545 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
4546 MAC_MODE_SEND_CONFIGS);
4547 }
wdenk8bde7f72003-06-27 21:31:46 +00004548 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004549 /* Set the link polarity bit. */
4550 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
4551 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
wdenkc6097192002-11-03 00:24:07 +00004552
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004553 pDevice->pStatusBlkVirt->Status = STATUS_BLOCK_UPDATED |
4554 (pDevice->pStatusBlkVirt->
4555 Status & ~STATUS_BLOCK_LINK_CHANGED_STATUS);
wdenkc6097192002-11-03 00:24:07 +00004556
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004557 for (j = 0; j < 100; j++) {
4558 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4559 MAC_STATUS_CFG_CHANGED);
4560 MM_Wait (5);
4561 if ((REG_RD (pDevice, MacCtrl.Status) &
4562 (MAC_STATUS_SYNC_CHANGED | MAC_STATUS_CFG_CHANGED)) == 0)
4563 break;
4564 }
wdenkc6097192002-11-03 00:24:07 +00004565
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004566 Value32 = REG_RD (pDevice, MacCtrl.Status);
4567 if ((Value32 & MAC_STATUS_PCS_SYNCED) == 0) {
4568 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4569 if (pDevice->DisableAutoNeg == FALSE) {
4570 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode |
4571 MAC_MODE_SEND_CONFIGS);
4572 MM_Wait (1);
4573 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
4574 }
4575 }
4576
4577 /* Initialize the current link status. */
4578 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4579 pDevice->LineSpeed = LM_LINE_SPEED_1000MBPS;
4580 pDevice->DuplexMode = LM_DUPLEX_MODE_FULL;
4581 REG_WR (pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4582 LED_CTRL_1000MBPS_LED_ON);
4583 } else {
4584 pDevice->LineSpeed = LM_LINE_SPEED_UNKNOWN;
4585 pDevice->DuplexMode = LM_DUPLEX_MODE_UNKNOWN;
4586 REG_WR (pDevice, MacCtrl.LedCtrl, LED_CTRL_OVERRIDE_LINK_LED |
4587 LED_CTRL_OVERRIDE_TRAFFIC_LED);
4588 }
4589
4590 /* Indicate link status. */
4591 if (pDevice->LinkStatus != CurrentLinkStatus) {
4592 pDevice->LinkStatus = CurrentLinkStatus;
4593 MM_IndicateStatus (pDevice, CurrentLinkStatus);
4594 }
4595
4596 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00004597}
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004598#endif /* INCLUDE_TBI_SUPPORT */
wdenkc6097192002-11-03 00:24:07 +00004599
4600/******************************************************************************/
4601/* Description: */
4602/* */
4603/* Return: */
4604/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004605LM_STATUS LM_SetupCopperPhy (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00004606{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004607 LM_STATUS CurrentLinkStatus;
4608 LM_UINT32 Value32;
wdenkc6097192002-11-03 00:24:07 +00004609
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004610 /* Assume there is not link first. */
4611 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
wdenkc6097192002-11-03 00:24:07 +00004612
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004613 /* Disable phy link change attention. */
4614 REG_WR (pDevice, MacCtrl.MacEvent, 0);
wdenkc6097192002-11-03 00:24:07 +00004615
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004616 /* Clear link change attention. */
4617 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4618 MAC_STATUS_CFG_CHANGED);
wdenkc6097192002-11-03 00:24:07 +00004619
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004620 /* Disable auto-polling for the moment. */
4621 pDevice->MiMode = 0xc0000;
4622 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4623 MM_Wait (40);
wdenkc6097192002-11-03 00:24:07 +00004624
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004625 /* Determine the requested line speed and duplex. */
4626 pDevice->OldLineSpeed = pDevice->LineSpeed;
4627 LM_TranslateRequestedMediaType (pDevice->RequestedMediaType,
4628 &pDevice->MediaType,
4629 &pDevice->LineSpeed,
4630 &pDevice->DuplexMode);
wdenkc6097192002-11-03 00:24:07 +00004631
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004632 /* Initialize the phy chip. */
4633 switch (pDevice->PhyId & PHY_ID_MASK) {
wdenk8bde7f72003-06-27 21:31:46 +00004634 case PHY_BCM5400_PHY_ID:
4635 case PHY_BCM5401_PHY_ID:
4636 case PHY_BCM5411_PHY_ID:
4637 case PHY_BCM5701_PHY_ID:
4638 case PHY_BCM5703_PHY_ID:
4639 case PHY_BCM5704_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004640 CurrentLinkStatus = LM_InitBcm540xPhy (pDevice);
4641 break;
wdenkc6097192002-11-03 00:24:07 +00004642
wdenk8bde7f72003-06-27 21:31:46 +00004643 default:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004644 break;
4645 }
wdenkc6097192002-11-03 00:24:07 +00004646
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004647 if (CurrentLinkStatus == LM_STATUS_LINK_SETTING_MISMATCH) {
4648 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4649 }
wdenkc6097192002-11-03 00:24:07 +00004650
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004651 /* Setup flow control. */
4652 pDevice->FlowControl = LM_FLOW_CONTROL_NONE;
4653 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4654 LM_FLOW_CONTROL FlowCap; /* Flow control capability. */
wdenkc6097192002-11-03 00:24:07 +00004655
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004656 FlowCap = LM_FLOW_CONTROL_NONE;
wdenkc6097192002-11-03 00:24:07 +00004657
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004658 if (pDevice->DuplexMode == LM_DUPLEX_MODE_FULL) {
4659 if (pDevice->DisableAutoNeg == FALSE ||
4660 pDevice->RequestedMediaType ==
4661 LM_REQUESTED_MEDIA_TYPE_AUTO
4662 || pDevice->RequestedMediaType ==
4663 LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
4664 LM_UINT32 ExpectedPhyAd;
4665 LM_UINT32 LocalPhyAd;
4666 LM_UINT32 RemotePhyAd;
wdenkc6097192002-11-03 00:24:07 +00004667
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004668 LM_ReadPhy (pDevice, PHY_AN_AD_REG,
4669 &LocalPhyAd);
4670 pDevice->advertising = LocalPhyAd;
4671 LocalPhyAd &=
4672 (PHY_AN_AD_ASYM_PAUSE |
4673 PHY_AN_AD_PAUSE_CAPABLE);
wdenkc6097192002-11-03 00:24:07 +00004674
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004675 ExpectedPhyAd =
4676 GetPhyAdFlowCntrlSettings (pDevice);
wdenkc6097192002-11-03 00:24:07 +00004677
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004678 if (LocalPhyAd != ExpectedPhyAd) {
4679 CurrentLinkStatus = LM_STATUS_LINK_DOWN;
4680 } else {
4681 LM_ReadPhy (pDevice,
4682 PHY_LINK_PARTNER_ABILITY_REG,
4683 &RemotePhyAd);
4684
4685 LM_SetFlowControl (pDevice, LocalPhyAd,
4686 RemotePhyAd);
4687 }
4688 } else {
4689 pDevice->FlowControlCap &=
4690 ~LM_FLOW_CONTROL_AUTO_PAUSE;
4691 LM_SetFlowControl (pDevice, 0, 0);
4692 }
wdenk8bde7f72003-06-27 21:31:46 +00004693 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004694 }
wdenkc6097192002-11-03 00:24:07 +00004695
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004696 if (CurrentLinkStatus == LM_STATUS_LINK_DOWN) {
4697 LM_ForceAutoNeg (pDevice, pDevice->RequestedMediaType);
4698
4699 /* If we force line speed, we make get link right away. */
4700 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4701 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
4702 if (Value32 & PHY_STATUS_LINK_PASS) {
4703 CurrentLinkStatus = LM_STATUS_LINK_ACTIVE;
wdenk8bde7f72003-06-27 21:31:46 +00004704 }
wdenk8bde7f72003-06-27 21:31:46 +00004705 }
wdenkc6097192002-11-03 00:24:07 +00004706
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004707 /* GMII interface. */
4708 pDevice->MacMode &= ~MAC_MODE_PORT_MODE_MASK;
4709 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4710 if (pDevice->LineSpeed == LM_LINE_SPEED_100MBPS ||
4711 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS) {
4712 pDevice->MacMode |= MAC_MODE_PORT_MODE_MII;
4713 } else {
4714 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
4715 }
4716 } else {
4717 pDevice->MacMode |= MAC_MODE_PORT_MODE_GMII;
wdenk8bde7f72003-06-27 21:31:46 +00004718 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004719
4720 /* Set the MAC to operate in the appropriate duplex mode. */
4721 pDevice->MacMode &= ~MAC_MODE_HALF_DUPLEX;
4722 if (pDevice->DuplexMode == LM_DUPLEX_MODE_HALF) {
4723 pDevice->MacMode |= MAC_MODE_HALF_DUPLEX;
wdenk8bde7f72003-06-27 21:31:46 +00004724 }
wdenkc6097192002-11-03 00:24:07 +00004725
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004726 /* Set the link polarity bit. */
4727 pDevice->MacMode &= ~MAC_MODE_LINK_POLARITY;
4728 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
4729 if ((pDevice->LedMode == LED_MODE_LINK10) ||
4730 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE &&
4731 pDevice->LineSpeed == LM_LINE_SPEED_10MBPS)) {
4732 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
4733 }
4734 } else {
4735 if (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) {
4736 pDevice->MacMode |= MAC_MODE_LINK_POLARITY;
4737 }
wdenkc6097192002-11-03 00:24:07 +00004738
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004739 /* Set LED mode. */
4740 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
4741 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
4742 Value32 = LED_CTRL_PHY_MODE_1;
4743 } else {
4744 if (pDevice->LedMode == LED_MODE_OUTPUT) {
4745 Value32 = LED_CTRL_PHY_MODE_2;
4746 } else {
4747 Value32 = LED_CTRL_PHY_MODE_1;
4748 }
4749 }
4750 REG_WR (pDevice, MacCtrl.LedCtrl, Value32);
wdenk8bde7f72003-06-27 21:31:46 +00004751 }
wdenkc6097192002-11-03 00:24:07 +00004752
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004753 REG_WR (pDevice, MacCtrl.Mode, pDevice->MacMode);
wdenkc6097192002-11-03 00:24:07 +00004754
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004755 /* Enable auto polling. */
4756 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4757 pDevice->MiMode |= MI_MODE_AUTO_POLLING_ENABLE;
4758 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
wdenk8bde7f72003-06-27 21:31:46 +00004759 }
wdenkc6097192002-11-03 00:24:07 +00004760
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004761 /* Enable phy link change attention. */
4762 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_MI_INTERRUPT) {
4763 REG_WR (pDevice, MacCtrl.MacEvent,
4764 MAC_EVENT_ENABLE_MI_INTERRUPT);
4765 } else {
4766 REG_WR (pDevice, MacCtrl.MacEvent,
4767 MAC_EVENT_ENABLE_LINK_STATE_CHANGED_ATTN);
wdenk8bde7f72003-06-27 21:31:46 +00004768 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004769 if ((T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) &&
4770 (CurrentLinkStatus == LM_STATUS_LINK_ACTIVE) &&
4771 (pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
4772 (((pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE) &&
4773 (pDevice->PciState & T3_PCI_STATE_BUS_SPEED_HIGH)) ||
4774 !(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE))) {
4775 MM_Wait (120);
4776 REG_WR (pDevice, MacCtrl.Status, MAC_STATUS_SYNC_CHANGED |
4777 MAC_STATUS_CFG_CHANGED);
4778 MEM_WR_OFFSET (pDevice, T3_FIRMWARE_MAILBOX,
4779 T3_MAGIC_NUM_DISABLE_DMAW_ON_LINK_CHANGE);
4780 }
wdenkc6097192002-11-03 00:24:07 +00004781
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004782 /* Indicate link status. */
4783 if (pDevice->LinkStatus != CurrentLinkStatus) {
4784 pDevice->LinkStatus = CurrentLinkStatus;
4785 MM_IndicateStatus (pDevice, CurrentLinkStatus);
4786 }
wdenkc6097192002-11-03 00:24:07 +00004787
wdenk8bde7f72003-06-27 21:31:46 +00004788 return LM_STATUS_SUCCESS;
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004789} /* LM_SetupCopperPhy */
wdenkc6097192002-11-03 00:24:07 +00004790
wdenkc6097192002-11-03 00:24:07 +00004791/******************************************************************************/
4792/* Description: */
4793/* */
4794/* Return: */
4795/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004796LM_STATUS LM_SetupPhy (PLM_DEVICE_BLOCK pDevice)
wdenkc6097192002-11-03 00:24:07 +00004797{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004798 LM_STATUS LmStatus;
4799 LM_UINT32 Value32;
wdenkc6097192002-11-03 00:24:07 +00004800
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004801#if INCLUDE_TBI_SUPPORT
4802 if (pDevice->EnableTbi) {
4803 LmStatus = LM_SetupFiberPhy (pDevice);
4804 } else
4805#endif /* INCLUDE_TBI_SUPPORT */
4806 {
4807 LmStatus = LM_SetupCopperPhy (pDevice);
4808 }
4809 if (pDevice->ChipRevId == T3_CHIP_ID_5704_A0) {
4810 if (!(pDevice->PciState & T3_PCI_STATE_CONVENTIONAL_PCI_MODE)) {
4811 Value32 = REG_RD (pDevice, PciCfg.PciState);
4812 REG_WR (pDevice, PciCfg.PciState,
4813 Value32 | T3_PCI_STATE_RETRY_SAME_DMA);
4814 }
4815 }
4816 if ((pDevice->LineSpeed == LM_LINE_SPEED_1000MBPS) &&
4817 (pDevice->DuplexMode == LM_DUPLEX_MODE_HALF)) {
4818 REG_WR (pDevice, MacCtrl.TxLengths, 0x26ff);
4819 } else {
4820 REG_WR (pDevice, MacCtrl.TxLengths, 0x2620);
4821 }
wdenkc6097192002-11-03 00:24:07 +00004822
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004823 return LmStatus;
wdenkc6097192002-11-03 00:24:07 +00004824}
4825
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07004826/******************************************************************************/
4827/* Description: */
4828/* */
4829/* Return: */
4830/******************************************************************************/
4831LM_VOID
4832LM_ReadPhy (PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg, PLM_UINT32 pData32)
4833{
4834 LM_UINT32 Value32;
4835 LM_UINT32 j;
4836
4837 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4838 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode &
4839 ~MI_MODE_AUTO_POLLING_ENABLE);
4840 MM_Wait (40);
4841 }
4842
4843 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
4844 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) <<
4845 MI_COM_FIRST_PHY_REG_ADDR_BIT) | MI_COM_CMD_READ | MI_COM_START;
4846
4847 REG_WR (pDevice, MacCtrl.MiCom, Value32);
4848
4849 for (j = 0; j < 20; j++) {
4850 MM_Wait (25);
4851
4852 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4853
4854 if (!(Value32 & MI_COM_BUSY)) {
4855 MM_Wait (5);
4856 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4857 Value32 &= MI_COM_PHY_DATA_MASK;
4858 break;
4859 }
4860 }
4861
4862 if (Value32 & MI_COM_BUSY) {
4863 Value32 = 0;
4864 }
4865
4866 *pData32 = Value32;
4867
4868 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4869 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4870 MM_Wait (40);
4871 }
4872} /* LM_ReadPhy */
4873
4874/******************************************************************************/
4875/* Description: */
4876/* */
4877/* Return: */
4878/******************************************************************************/
4879LM_VOID
4880LM_WritePhy (PLM_DEVICE_BLOCK pDevice, LM_UINT32 PhyReg, LM_UINT32 Data32)
4881{
4882 LM_UINT32 Value32;
4883 LM_UINT32 j;
4884
4885 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4886 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode &
4887 ~MI_MODE_AUTO_POLLING_ENABLE);
4888 MM_Wait (40);
4889 }
4890
4891 Value32 = (pDevice->PhyAddr << MI_COM_FIRST_PHY_ADDR_BIT) |
4892 ((PhyReg & MI_COM_PHY_REG_ADDR_MASK) <<
4893 MI_COM_FIRST_PHY_REG_ADDR_BIT) | (Data32 & MI_COM_PHY_DATA_MASK) |
4894 MI_COM_CMD_WRITE | MI_COM_START;
4895
4896 REG_WR (pDevice, MacCtrl.MiCom, Value32);
4897
4898 for (j = 0; j < 20; j++) {
4899 MM_Wait (25);
4900
4901 Value32 = REG_RD (pDevice, MacCtrl.MiCom);
4902
4903 if (!(Value32 & MI_COM_BUSY)) {
4904 MM_Wait (5);
4905 break;
4906 }
4907 }
4908
4909 if (pDevice->PhyIntMode == T3_PHY_INT_MODE_AUTO_POLLING) {
4910 REG_WR (pDevice, MacCtrl.MiMode, pDevice->MiMode);
4911 MM_Wait (40);
4912 }
4913} /* LM_WritePhy */
4914
4915/******************************************************************************/
4916/* Description: */
4917/* */
4918/* Return: */
4919/******************************************************************************/
4920LM_STATUS LM_SetPowerState (PLM_DEVICE_BLOCK pDevice, LM_POWER_STATE PowerLevel)
4921{
4922 LM_UINT32 PmeSupport;
4923 LM_UINT32 Value32;
4924 LM_UINT32 PmCtrl;
4925
4926 /* make sureindirect accesses are enabled */
4927 MM_WriteConfig32 (pDevice, T3_PCI_MISC_HOST_CTRL_REG,
4928 pDevice->MiscHostCtrl);
4929
4930 /* Clear the PME_ASSERT bit and the power state bits. Also enable */
4931 /* the PME bit. */
4932 MM_ReadConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, &PmCtrl);
4933
4934 PmCtrl |= T3_PM_PME_ASSERTED;
4935 PmCtrl &= ~T3_PM_POWER_STATE_MASK;
4936
4937 /* Set the appropriate power state. */
4938 if (PowerLevel == LM_POWER_STATE_D0) {
4939
4940 /* Bring the card out of low power mode. */
4941 PmCtrl |= T3_PM_POWER_STATE_D0;
4942 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
4943
4944 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl);
4945 MM_Wait (40);
4946#if 0 /* Bugfix by jmb...can't call WritePhy here because pDevice not fully initialized */
4947 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x02);
4948#endif
4949
4950 return LM_STATUS_SUCCESS;
4951 } else if (PowerLevel == LM_POWER_STATE_D1) {
4952 PmCtrl |= T3_PM_POWER_STATE_D1;
4953 } else if (PowerLevel == LM_POWER_STATE_D2) {
4954 PmCtrl |= T3_PM_POWER_STATE_D2;
4955 } else if (PowerLevel == LM_POWER_STATE_D3) {
4956 PmCtrl |= T3_PM_POWER_STATE_D3;
4957 } else {
4958 return LM_STATUS_FAILURE;
4959 }
4960 PmCtrl |= T3_PM_PME_ENABLE;
4961
4962 /* Mask out all interrupts so LM_SetupPhy won't be called while we are */
4963 /* setting new line speed. */
4964 Value32 = REG_RD (pDevice, PciCfg.MiscHostCtrl);
4965 REG_WR (pDevice, PciCfg.MiscHostCtrl,
4966 Value32 | MISC_HOST_CTRL_MASK_PCI_INT);
4967
4968 if (!pDevice->RestoreOnWakeUp) {
4969 pDevice->RestoreOnWakeUp = TRUE;
4970 pDevice->WakeUpDisableAutoNeg = pDevice->DisableAutoNeg;
4971 pDevice->WakeUpRequestedMediaType = pDevice->RequestedMediaType;
4972 }
4973
4974 /* Force auto-negotiation to 10 line speed. */
4975 pDevice->DisableAutoNeg = FALSE;
4976 pDevice->RequestedMediaType = LM_REQUESTED_MEDIA_TYPE_UTP_10MBPS;
4977 LM_SetupPhy (pDevice);
4978
4979 /* Put the driver in the initial state, and go through the power down */
4980 /* sequence. */
4981 LM_Halt (pDevice);
4982
4983 MM_ReadConfig32 (pDevice, T3_PCI_PM_CAP_REG, &PmeSupport);
4984
4985 if (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE) {
4986
4987 /* Enable WOL. */
4988 LM_WritePhy (pDevice, BCM5401_AUX_CTRL, 0x5a);
4989 MM_Wait (40);
4990
4991 /* Set LED mode. */
4992 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
4993 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
4994 Value32 = LED_CTRL_PHY_MODE_1;
4995 } else {
4996 if (pDevice->LedMode == LED_MODE_OUTPUT) {
4997 Value32 = LED_CTRL_PHY_MODE_2;
4998 } else {
4999 Value32 = LED_CTRL_PHY_MODE_1;
5000 }
5001 }
5002
5003 Value32 = MAC_MODE_PORT_MODE_MII;
5004 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700) {
5005 if (pDevice->LedMode == LED_MODE_LINK10 ||
5006 pDevice->WolSpeed == WOL_SPEED_10MB) {
5007 Value32 |= MAC_MODE_LINK_POLARITY;
5008 }
5009 } else {
5010 Value32 |= MAC_MODE_LINK_POLARITY;
5011 }
5012 REG_WR (pDevice, MacCtrl.Mode, Value32);
5013 MM_Wait (40);
5014 MM_Wait (40);
5015 MM_Wait (40);
5016
5017 /* Always enable magic packet wake-up if we have vaux. */
5018 if ((PmeSupport & T3_PCI_PM_CAP_PME_D3COLD) &&
5019 (pDevice->WakeUpModeCap & LM_WAKE_UP_MODE_MAGIC_PACKET)) {
5020 Value32 |= MAC_MODE_DETECT_MAGIC_PACKET_ENABLE;
5021 }
5022
5023 REG_WR (pDevice, MacCtrl.Mode, Value32);
5024
5025 /* Enable the receiver. */
5026 REG_WR (pDevice, MacCtrl.RxMode, RX_MODE_ENABLE);
5027 }
5028
5029 /* Disable tx/rx clocks, and seletect an alternate clock. */
5030 if (pDevice->WolSpeed == WOL_SPEED_100MB) {
5031 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5032 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5033 Value32 =
5034 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5035 T3_PCI_SELECT_ALTERNATE_CLOCK;
5036 } else {
5037 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK;
5038 }
5039 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5040
5041 MM_Wait (40);
5042
5043 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5044 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5045 Value32 =
5046 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5047 T3_PCI_SELECT_ALTERNATE_CLOCK |
5048 T3_PCI_44MHZ_CORE_CLOCK;
5049 } else {
5050 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5051 T3_PCI_44MHZ_CORE_CLOCK;
5052 }
5053
5054 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5055
5056 MM_Wait (40);
5057
5058 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5059 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5060 Value32 =
5061 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5062 T3_PCI_44MHZ_CORE_CLOCK;
5063 } else {
5064 Value32 = T3_PCI_44MHZ_CORE_CLOCK;
5065 }
5066
5067 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5068 } else {
5069 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5070 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5071 Value32 =
5072 T3_PCI_DISABLE_RX_CLOCK | T3_PCI_DISABLE_TX_CLOCK |
5073 T3_PCI_SELECT_ALTERNATE_CLOCK |
5074 T3_PCI_POWER_DOWN_PCI_PLL133;
5075 } else {
5076 Value32 = T3_PCI_SELECT_ALTERNATE_CLOCK |
5077 T3_PCI_POWER_DOWN_PCI_PLL133;
5078 }
5079
5080 REG_WR (pDevice, PciCfg.ClockCtrl, Value32);
5081 }
5082
5083 MM_Wait (40);
5084
5085 if (!pDevice->EepromWp
5086 && (pDevice->WakeUpModeCap != LM_WAKE_UP_MODE_NONE)) {
5087 /* Switch adapter to auxilliary power. */
5088 if (T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5700 ||
5089 T3_ASIC_REV (pDevice->ChipRevId) == T3_ASIC_REV_5701) {
5090 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5091 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5092 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5093 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5094 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5095 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5096 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5097 MM_Wait (40);
5098 } else {
5099 /* GPIO0 = 0, GPIO1 = 1, GPIO2 = 1. */
5100 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5101 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5102 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5103 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5104 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5105 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5106 MM_Wait (40);
5107
5108 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 1. */
5109 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5110 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5111 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5112 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5113 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5114 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1 |
5115 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT2);
5116 MM_Wait (40);
5117
5118 /* GPIO0 = 1, GPIO1 = 1, GPIO2 = 0. */
5119 REG_WR (pDevice, Grc.LocalCtrl, pDevice->GrcLocalCtrl |
5120 GRC_MISC_LOCAL_CTRL_GPIO_OE0 |
5121 GRC_MISC_LOCAL_CTRL_GPIO_OE1 |
5122 GRC_MISC_LOCAL_CTRL_GPIO_OE2 |
5123 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT0 |
5124 GRC_MISC_LOCAL_CTRL_GPIO_OUTPUT1);
5125 MM_Wait (40);
5126 }
5127 }
5128
5129 /* Set the phy to low power mode. */
5130 /* Put the the hardware in low power mode. */
5131 MM_WriteConfig32 (pDevice, T3_PCI_PM_STATUS_CTRL_REG, PmCtrl);
5132
5133 return LM_STATUS_SUCCESS;
5134} /* LM_SetPowerState */
5135
5136/******************************************************************************/
5137/* Description: */
5138/* */
5139/* Return: */
5140/******************************************************************************/
5141static LM_UINT32 GetPhyAdFlowCntrlSettings (PLM_DEVICE_BLOCK pDevice)
5142{
5143 LM_UINT32 Value32;
5144
5145 Value32 = 0;
5146
5147 /* Auto negotiation flow control only when autonegotiation is enabled. */
5148 if (pDevice->DisableAutoNeg == FALSE ||
5149 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_AUTO ||
5150 pDevice->RequestedMediaType == LM_REQUESTED_MEDIA_TYPE_UTP_AUTO) {
5151 /* Please refer to Table 28B-3 of the 802.3ab-1999 spec. */
5152 if ((pDevice->FlowControlCap == LM_FLOW_CONTROL_AUTO_PAUSE) ||
5153 ((pDevice->FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE)
5154 && (pDevice->
5155 FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE))) {
5156 Value32 |= PHY_AN_AD_PAUSE_CAPABLE;
5157 } else if (pDevice->
5158 FlowControlCap & LM_FLOW_CONTROL_TRANSMIT_PAUSE) {
5159 Value32 |= PHY_AN_AD_ASYM_PAUSE;
5160 } else if (pDevice->
5161 FlowControlCap & LM_FLOW_CONTROL_RECEIVE_PAUSE) {
5162 Value32 |=
5163 PHY_AN_AD_PAUSE_CAPABLE | PHY_AN_AD_ASYM_PAUSE;
5164 }
5165 }
5166
5167 return Value32;
5168}
wdenkc6097192002-11-03 00:24:07 +00005169
wdenkc6097192002-11-03 00:24:07 +00005170/******************************************************************************/
5171/* Description: */
5172/* */
5173/* Return: */
5174/* LM_STATUS_FAILURE */
5175/* LM_STATUS_SUCCESS */
5176/* */
5177/******************************************************************************/
5178static LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005179LM_ForceAutoNegBcm540xPhy (PLM_DEVICE_BLOCK pDevice,
5180 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
wdenkc6097192002-11-03 00:24:07 +00005181{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005182 LM_MEDIA_TYPE MediaType;
5183 LM_LINE_SPEED LineSpeed;
5184 LM_DUPLEX_MODE DuplexMode;
5185 LM_UINT32 NewPhyCtrl;
5186 LM_UINT32 Value32;
5187 LM_UINT32 Cnt;
wdenkc6097192002-11-03 00:24:07 +00005188
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005189 /* Get the interface type, line speed, and duplex mode. */
5190 LM_TranslateRequestedMediaType (RequestedMediaType, &MediaType,
5191 &LineSpeed, &DuplexMode);
wdenkc6097192002-11-03 00:24:07 +00005192
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005193 if (pDevice->RestoreOnWakeUp) {
5194 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5195 pDevice->advertising1000 = 0;
5196 Value32 = PHY_AN_AD_10BASET_FULL | PHY_AN_AD_10BASET_HALF;
5197 if (pDevice->WolSpeed == WOL_SPEED_100MB) {
5198 Value32 |=
5199 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5200 }
5201 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5202 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
5203 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5204 pDevice->advertising = Value32;
wdenk8bde7f72003-06-27 21:31:46 +00005205 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005206 /* Setup the auto-negotiation advertisement register. */
5207 else if (LineSpeed == LM_LINE_SPEED_UNKNOWN) {
5208 /* Setup the 10/100 Mbps auto-negotiation advertisement register. */
5209 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD |
5210 PHY_AN_AD_10BASET_HALF | PHY_AN_AD_10BASET_FULL |
5211 PHY_AN_AD_100BASETX_FULL | PHY_AN_AD_100BASETX_HALF;
5212 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
wdenkc6097192002-11-03 00:24:07 +00005213
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005214 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5215 pDevice->advertising = Value32;
wdenkc6097192002-11-03 00:24:07 +00005216
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005217 /* Advertise 1000Mbps */
5218 Value32 =
5219 BCM540X_AN_AD_1000BASET_HALF | BCM540X_AN_AD_1000BASET_FULL;
wdenkc6097192002-11-03 00:24:07 +00005220
5221#if INCLUDE_5701_AX_FIX
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005222 /* Bug: workaround for CRC error in gigabit mode when we are in */
5223 /* slave mode. This will force the PHY to operate in */
5224 /* master mode. */
5225 if (pDevice->ChipRevId == T3_CHIP_ID_5701_A0 ||
5226 pDevice->ChipRevId == T3_CHIP_ID_5701_B0) {
5227 Value32 |= BCM540X_CONFIG_AS_MASTER |
5228 BCM540X_ENABLE_CONFIG_AS_MASTER;
5229 }
wdenkc6097192002-11-03 00:24:07 +00005230#endif
5231
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005232 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, Value32);
5233 pDevice->advertising1000 = Value32;
5234 } else {
5235 if (LineSpeed == LM_LINE_SPEED_1000MBPS) {
5236 Value32 = PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5237 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
wdenkc6097192002-11-03 00:24:07 +00005238
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005239 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5240 pDevice->advertising = Value32;
wdenkc6097192002-11-03 00:24:07 +00005241
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005242 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5243 Value32 = BCM540X_AN_AD_1000BASET_HALF;
5244 } else {
5245 Value32 = BCM540X_AN_AD_1000BASET_FULL;
5246 }
wdenkc6097192002-11-03 00:24:07 +00005247
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005248 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG,
5249 Value32);
5250 pDevice->advertising1000 = Value32;
5251 } else if (LineSpeed == LM_LINE_SPEED_100MBPS) {
5252 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5253 pDevice->advertising1000 = 0;
wdenkc6097192002-11-03 00:24:07 +00005254
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005255 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5256 Value32 = PHY_AN_AD_100BASETX_HALF;
5257 } else {
5258 Value32 = PHY_AN_AD_100BASETX_FULL;
5259 }
wdenkc6097192002-11-03 00:24:07 +00005260
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005261 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5262 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
wdenkc6097192002-11-03 00:24:07 +00005263
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005264 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5265 pDevice->advertising = Value32;
5266 } else if (LineSpeed == LM_LINE_SPEED_10MBPS) {
5267 LM_WritePhy (pDevice, BCM540X_1000BASET_CTRL_REG, 0);
5268 pDevice->advertising1000 = 0;
wdenkc6097192002-11-03 00:24:07 +00005269
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005270 if (DuplexMode != LM_DUPLEX_MODE_FULL) {
5271 Value32 = PHY_AN_AD_10BASET_HALF;
5272 } else {
5273 Value32 = PHY_AN_AD_10BASET_FULL;
5274 }
wdenkc6097192002-11-03 00:24:07 +00005275
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005276 Value32 |= PHY_AN_AD_PROTOCOL_802_3_CSMA_CD;
5277 Value32 |= GetPhyAdFlowCntrlSettings (pDevice);
wdenkc6097192002-11-03 00:24:07 +00005278
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005279 LM_WritePhy (pDevice, PHY_AN_AD_REG, Value32);
5280 pDevice->advertising = Value32;
wdenk8bde7f72003-06-27 21:31:46 +00005281 }
wdenk8bde7f72003-06-27 21:31:46 +00005282 }
wdenkc6097192002-11-03 00:24:07 +00005283
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005284 /* Force line speed if auto-negotiation is disabled. */
5285 if (pDevice->DisableAutoNeg && LineSpeed != LM_LINE_SPEED_UNKNOWN) {
5286 /* This code path is executed only when there is link. */
5287 pDevice->MediaType = MediaType;
5288 pDevice->LineSpeed = LineSpeed;
5289 pDevice->DuplexMode = DuplexMode;
wdenkc6097192002-11-03 00:24:07 +00005290
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005291 /* Force line seepd. */
5292 NewPhyCtrl = 0;
5293 switch (LineSpeed) {
5294 case LM_LINE_SPEED_10MBPS:
5295 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_10MBPS;
5296 break;
5297 case LM_LINE_SPEED_100MBPS:
5298 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_100MBPS;
5299 break;
5300 case LM_LINE_SPEED_1000MBPS:
5301 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5302 break;
5303 default:
5304 NewPhyCtrl |= PHY_CTRL_SPEED_SELECT_1000MBPS;
5305 break;
5306 }
5307
5308 if (DuplexMode == LM_DUPLEX_MODE_FULL) {
5309 NewPhyCtrl |= PHY_CTRL_FULL_DUPLEX_MODE;
5310 }
5311
5312 /* Don't do anything if the PHY_CTRL is already what we wanted. */
5313 LM_ReadPhy (pDevice, PHY_CTRL_REG, &Value32);
5314 if (Value32 != NewPhyCtrl) {
5315 /* Temporary bring the link down before forcing line speed. */
5316 LM_WritePhy (pDevice, PHY_CTRL_REG,
5317 PHY_CTRL_LOOPBACK_MODE);
5318
5319 /* Wait for link to go down. */
5320 for (Cnt = 0; Cnt < 15000; Cnt++) {
5321 MM_Wait (10);
5322
5323 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
5324 LM_ReadPhy (pDevice, PHY_STATUS_REG, &Value32);
5325
5326 if (!(Value32 & PHY_STATUS_LINK_PASS)) {
5327 MM_Wait (40);
5328 break;
5329 }
5330 }
5331
5332 LM_WritePhy (pDevice, PHY_CTRL_REG, NewPhyCtrl);
5333 MM_Wait (40);
5334 }
5335 } else {
5336 LM_WritePhy (pDevice, PHY_CTRL_REG, PHY_CTRL_AUTO_NEG_ENABLE |
5337 PHY_CTRL_RESTART_AUTO_NEG);
5338 }
5339
5340 return LM_STATUS_SUCCESS;
5341} /* LM_ForceAutoNegBcm540xPhy */
wdenkc6097192002-11-03 00:24:07 +00005342
wdenkc6097192002-11-03 00:24:07 +00005343/******************************************************************************/
5344/* Description: */
5345/* */
5346/* Return: */
5347/******************************************************************************/
5348static LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005349LM_ForceAutoNeg (PLM_DEVICE_BLOCK pDevice,
5350 LM_REQUESTED_MEDIA_TYPE RequestedMediaType)
wdenkc6097192002-11-03 00:24:07 +00005351{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005352 LM_STATUS LmStatus;
wdenkc6097192002-11-03 00:24:07 +00005353
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005354 /* Initialize the phy chip. */
5355 switch (pDevice->PhyId & PHY_ID_MASK) {
wdenk8bde7f72003-06-27 21:31:46 +00005356 case PHY_BCM5400_PHY_ID:
5357 case PHY_BCM5401_PHY_ID:
5358 case PHY_BCM5411_PHY_ID:
5359 case PHY_BCM5701_PHY_ID:
5360 case PHY_BCM5703_PHY_ID:
5361 case PHY_BCM5704_PHY_ID:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005362 LmStatus =
5363 LM_ForceAutoNegBcm540xPhy (pDevice, RequestedMediaType);
5364 break;
wdenkc6097192002-11-03 00:24:07 +00005365
wdenk8bde7f72003-06-27 21:31:46 +00005366 default:
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005367 LmStatus = LM_STATUS_FAILURE;
5368 break;
5369 }
wdenkc6097192002-11-03 00:24:07 +00005370
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005371 return LmStatus;
5372} /* LM_ForceAutoNeg */
wdenkc6097192002-11-03 00:24:07 +00005373
5374/******************************************************************************/
5375/* Description: */
5376/* */
5377/* Return: */
5378/******************************************************************************/
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005379LM_STATUS LM_LoadFirmware (PLM_DEVICE_BLOCK pDevice,
5380 PT3_FWIMG_INFO pFwImg,
5381 LM_UINT32 LoadCpu, LM_UINT32 StartCpu)
wdenkc6097192002-11-03 00:24:07 +00005382{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005383 LM_UINT32 i;
5384 LM_UINT32 address;
wdenkc6097192002-11-03 00:24:07 +00005385
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005386 if (LoadCpu & T3_RX_CPU_ID) {
5387 if (LM_HaltCpu (pDevice, T3_RX_CPU_ID) != LM_STATUS_SUCCESS) {
5388 return LM_STATUS_FAILURE;
5389 }
5390
5391 /* First of all clear scrach pad memory */
5392 for (i = 0; i < T3_RX_CPU_SPAD_SIZE; i += 4) {
5393 LM_RegWrInd (pDevice, T3_RX_CPU_SPAD_ADDR + i, 0);
5394 }
5395
5396 /* Copy code first */
5397 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5398 for (i = 0; i <= pFwImg->Text.Length; i += 4) {
5399 LM_RegWrInd (pDevice, address + i,
5400 ((LM_UINT32 *) pFwImg->Text.Buffer)[i /
5401 4]);
5402 }
5403
5404 address =
5405 T3_RX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5406 for (i = 0; i <= pFwImg->ROnlyData.Length; i += 4) {
5407 LM_RegWrInd (pDevice, address + i,
5408 ((LM_UINT32 *) pFwImg->ROnlyData.
5409 Buffer)[i / 4]);
5410 }
5411
5412 address = T3_RX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5413 for (i = 0; i <= pFwImg->Data.Length; i += 4) {
5414 LM_RegWrInd (pDevice, address + i,
5415 ((LM_UINT32 *) pFwImg->Data.Buffer)[i /
5416 4]);
5417 }
wdenk8bde7f72003-06-27 21:31:46 +00005418 }
wdenkc6097192002-11-03 00:24:07 +00005419
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005420 if (LoadCpu & T3_TX_CPU_ID) {
5421 if (LM_HaltCpu (pDevice, T3_TX_CPU_ID) != LM_STATUS_SUCCESS) {
5422 return LM_STATUS_FAILURE;
5423 }
5424
5425 /* First of all clear scrach pad memory */
5426 for (i = 0; i < T3_TX_CPU_SPAD_SIZE; i += 4) {
5427 LM_RegWrInd (pDevice, T3_TX_CPU_SPAD_ADDR + i, 0);
5428 }
5429
5430 /* Copy code first */
5431 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Text.Offset & 0xffff);
5432 for (i = 0; i <= pFwImg->Text.Length; i += 4) {
5433 LM_RegWrInd (pDevice, address + i,
5434 ((LM_UINT32 *) pFwImg->Text.Buffer)[i /
5435 4]);
5436 }
5437
5438 address =
5439 T3_TX_CPU_SPAD_ADDR + (pFwImg->ROnlyData.Offset & 0xffff);
5440 for (i = 0; i <= pFwImg->ROnlyData.Length; i += 4) {
5441 LM_RegWrInd (pDevice, address + i,
5442 ((LM_UINT32 *) pFwImg->ROnlyData.
5443 Buffer)[i / 4]);
5444 }
5445
5446 address = T3_TX_CPU_SPAD_ADDR + (pFwImg->Data.Offset & 0xffff);
5447 for (i = 0; i <= pFwImg->Data.Length; i += 4) {
5448 LM_RegWrInd (pDevice, address + i,
5449 ((LM_UINT32 *) pFwImg->Data.Buffer)[i /
5450 4]);
5451 }
wdenk8bde7f72003-06-27 21:31:46 +00005452 }
wdenkc6097192002-11-03 00:24:07 +00005453
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005454 if (StartCpu & T3_RX_CPU_ID) {
5455 /* Start Rx CPU */
5456 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5457 REG_WR (pDevice, rxCpu.reg.PC, pFwImg->StartAddress);
5458 for (i = 0; i < 5; i++) {
5459 if (pFwImg->StartAddress ==
5460 REG_RD (pDevice, rxCpu.reg.PC))
5461 break;
5462
5463 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5464 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
5465 REG_WR (pDevice, rxCpu.reg.PC, pFwImg->StartAddress);
5466 MM_Wait (1000);
5467 }
5468
5469 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5470 REG_WR (pDevice, rxCpu.reg.mode, 0);
wdenk8bde7f72003-06-27 21:31:46 +00005471 }
wdenkc6097192002-11-03 00:24:07 +00005472
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005473 if (StartCpu & T3_TX_CPU_ID) {
5474 /* Start Tx CPU */
5475 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5476 REG_WR (pDevice, txCpu.reg.PC, pFwImg->StartAddress);
5477 for (i = 0; i < 5; i++) {
5478 if (pFwImg->StartAddress ==
5479 REG_RD (pDevice, txCpu.reg.PC))
5480 break;
5481
5482 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5483 REG_WR (pDevice, txCpu.reg.mode, CPU_MODE_HALT);
5484 REG_WR (pDevice, txCpu.reg.PC, pFwImg->StartAddress);
5485 MM_Wait (1000);
5486 }
5487
5488 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5489 REG_WR (pDevice, txCpu.reg.mode, 0);
wdenk8bde7f72003-06-27 21:31:46 +00005490 }
wdenkc6097192002-11-03 00:24:07 +00005491
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005492 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00005493}
5494
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005495STATIC LM_STATUS LM_HaltCpu (PLM_DEVICE_BLOCK pDevice, LM_UINT32 cpu_number)
wdenkc6097192002-11-03 00:24:07 +00005496{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005497 LM_UINT32 i;
wdenkc6097192002-11-03 00:24:07 +00005498
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005499 if (cpu_number == T3_RX_CPU_ID) {
5500 for (i = 0; i < 10000; i++) {
5501 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5502 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
wdenkc6097192002-11-03 00:24:07 +00005503
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005504 if (REG_RD (pDevice, rxCpu.reg.mode) & CPU_MODE_HALT)
5505 break;
5506 }
5507
5508 REG_WR (pDevice, rxCpu.reg.state, 0xffffffff);
5509 REG_WR (pDevice, rxCpu.reg.mode, CPU_MODE_HALT);
5510 MM_Wait (10);
5511 } else {
5512 for (i = 0; i < 10000; i++) {
5513 REG_WR (pDevice, txCpu.reg.state, 0xffffffff);
5514 REG_WR (pDevice, txCpu.reg.mode, CPU_MODE_HALT);
5515
5516 if (REG_RD (pDevice, txCpu.reg.mode) & CPU_MODE_HALT)
5517 break;
5518 }
wdenk8bde7f72003-06-27 21:31:46 +00005519 }
wdenkc6097192002-11-03 00:24:07 +00005520
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005521 return ((i == 10000) ? LM_STATUS_FAILURE : LM_STATUS_SUCCESS);
wdenkc6097192002-11-03 00:24:07 +00005522}
5523
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005524int LM_BlinkLED (PLM_DEVICE_BLOCK pDevice, LM_UINT32 BlinkDurationSec)
wdenkc6097192002-11-03 00:24:07 +00005525{
5526 LM_UINT32 Oldcfg;
5527 int j;
5528 int ret = 0;
5529
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005530 if (BlinkDurationSec == 0) {
wdenkc6097192002-11-03 00:24:07 +00005531 return 0;
wdenk8bde7f72003-06-27 21:31:46 +00005532 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005533 if (BlinkDurationSec > 120) {
wdenk8bde7f72003-06-27 21:31:46 +00005534 BlinkDurationSec = 120;
wdenkc6097192002-11-03 00:24:07 +00005535 }
5536
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005537 Oldcfg = REG_RD (pDevice, MacCtrl.LedCtrl);
5538 for (j = 0; j < BlinkDurationSec * 2; j++) {
5539 if (j % 2) {
wdenk8bde7f72003-06-27 21:31:46 +00005540 /* Turn on the LEDs. */
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005541 REG_WR (pDevice, MacCtrl.LedCtrl,
wdenkc6097192002-11-03 00:24:07 +00005542 LED_CTRL_OVERRIDE_LINK_LED |
5543 LED_CTRL_1000MBPS_LED_ON |
5544 LED_CTRL_100MBPS_LED_ON |
5545 LED_CTRL_10MBPS_LED_ON |
5546 LED_CTRL_OVERRIDE_TRAFFIC_LED |
5547 LED_CTRL_BLINK_TRAFFIC_LED |
5548 LED_CTRL_TRAFFIC_LED);
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005549 } else {
wdenk8bde7f72003-06-27 21:31:46 +00005550 /* Turn off the LEDs. */
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005551 REG_WR (pDevice, MacCtrl.LedCtrl,
wdenkc6097192002-11-03 00:24:07 +00005552 LED_CTRL_OVERRIDE_LINK_LED |
5553 LED_CTRL_OVERRIDE_TRAFFIC_LED);
5554 }
5555
5556#ifndef EMBEDDED
wdenk8bde7f72003-06-27 21:31:46 +00005557 current->state = TASK_INTERRUPTIBLE;
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005558 if (schedule_timeout (HZ / 2) != 0) {
wdenk8bde7f72003-06-27 21:31:46 +00005559 ret = -EINTR;
5560 break;
5561 }
wdenkc6097192002-11-03 00:24:07 +00005562#else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005563 udelay (100000); /* 1s sleep */
wdenkc6097192002-11-03 00:24:07 +00005564#endif
5565 }
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005566 REG_WR (pDevice, MacCtrl.LedCtrl, Oldcfg);
wdenkc6097192002-11-03 00:24:07 +00005567 return ret;
5568}
5569
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005570int t3_do_dma (PLM_DEVICE_BLOCK pDevice,
5571 LM_PHYSICAL_ADDRESS host_addr_phy, int length, int dma_read)
wdenkc6097192002-11-03 00:24:07 +00005572{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005573 T3_DMA_DESC dma_desc;
5574 int i;
5575 LM_UINT32 dma_desc_addr;
5576 LM_UINT32 value32;
wdenkc6097192002-11-03 00:24:07 +00005577
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005578 REG_WR (pDevice, BufMgr.Mode, 0);
5579 REG_WR (pDevice, Ftq.Reset, 0);
wdenkc6097192002-11-03 00:24:07 +00005580
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005581 dma_desc.host_addr.High = host_addr_phy.High;
5582 dma_desc.host_addr.Low = host_addr_phy.Low;
5583 dma_desc.nic_mbuf = 0x2100;
5584 dma_desc.len = length;
5585 dma_desc.flags = 0x00000004; /* Generate Rx-CPU event */
wdenkc6097192002-11-03 00:24:07 +00005586
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005587 if (dma_read) {
5588 dma_desc.cqid_sqid = (T3_QID_RX_BD_COMP << 8) |
5589 T3_QID_DMA_HIGH_PRI_READ;
5590 REG_WR (pDevice, DmaRead.Mode, DMA_READ_MODE_ENABLE);
5591 } else {
5592 dma_desc.cqid_sqid = (T3_QID_RX_DATA_COMP << 8) |
5593 T3_QID_DMA_HIGH_PRI_WRITE;
5594 REG_WR (pDevice, DmaWrite.Mode, DMA_WRITE_MODE_ENABLE);
5595 }
wdenkc6097192002-11-03 00:24:07 +00005596
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005597 dma_desc_addr = T3_NIC_DMA_DESC_POOL_ADDR;
wdenkc6097192002-11-03 00:24:07 +00005598
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005599 /* Writing this DMA descriptor to DMA memory */
5600 for (i = 0; i < sizeof (T3_DMA_DESC); i += 4) {
5601 value32 = *((PLM_UINT32) (((PLM_UINT8) & dma_desc) + i));
5602 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG,
5603 dma_desc_addr + i);
5604 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_DATA_REG,
5605 cpu_to_le32 (value32));
5606 }
5607 MM_WriteConfig32 (pDevice, T3_PCI_MEM_WIN_ADDR_REG, 0);
wdenkc6097192002-11-03 00:24:07 +00005608
wdenk8bde7f72003-06-27 21:31:46 +00005609 if (dma_read)
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005610 REG_WR (pDevice, Ftq.DmaHighReadFtqFifoEnqueueDequeue,
5611 dma_desc_addr);
wdenk8bde7f72003-06-27 21:31:46 +00005612 else
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005613 REG_WR (pDevice, Ftq.DmaHighWriteFtqFifoEnqueueDequeue,
5614 dma_desc_addr);
wdenkc6097192002-11-03 00:24:07 +00005615
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005616 for (i = 0; i < 40; i++) {
5617 if (dma_read)
5618 value32 =
5619 REG_RD (pDevice,
5620 Ftq.RcvBdCompFtqFifoEnqueueDequeue);
5621 else
5622 value32 =
5623 REG_RD (pDevice,
5624 Ftq.RcvDataCompFtqFifoEnqueueDequeue);
wdenkc6097192002-11-03 00:24:07 +00005625
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005626 if ((value32 & 0xffff) == dma_desc_addr)
5627 break;
wdenkc6097192002-11-03 00:24:07 +00005628
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005629 MM_Wait (10);
5630 }
5631
5632 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00005633}
5634
5635STATIC LM_STATUS
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005636LM_DmaTest (PLM_DEVICE_BLOCK pDevice, PLM_UINT8 pBufferVirt,
5637 LM_PHYSICAL_ADDRESS BufferPhy, LM_UINT32 BufferSize)
wdenkc6097192002-11-03 00:24:07 +00005638{
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005639 int j;
5640 LM_UINT32 *ptr;
5641 int dma_success = 0;
wdenkc6097192002-11-03 00:24:07 +00005642
Vadim Bendeburyf539edc2007-05-24 15:52:25 -07005643 if (T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5700 &&
5644 T3_ASIC_REV (pDevice->ChipRevId) != T3_ASIC_REV_5701) {
5645 return LM_STATUS_SUCCESS;
5646 }
5647 while (!dma_success) {
5648 /* Fill data with incremental patterns */
5649 ptr = (LM_UINT32 *) pBufferVirt;
5650 for (j = 0; j < BufferSize / 4; j++)
5651 *ptr++ = j;
5652
5653 if (t3_do_dma (pDevice, BufferPhy, BufferSize, 1) ==
5654 LM_STATUS_FAILURE) {
5655 return LM_STATUS_FAILURE;
5656 }
5657
5658 MM_Wait (40);
5659 ptr = (LM_UINT32 *) pBufferVirt;
5660 /* Fill data with zero */
5661 for (j = 0; j < BufferSize / 4; j++)
5662 *ptr++ = 0;
5663
5664 if (t3_do_dma (pDevice, BufferPhy, BufferSize, 0) ==
5665 LM_STATUS_FAILURE) {
5666 return LM_STATUS_FAILURE;
5667 }
5668
5669 MM_Wait (40);
5670 /* Check for data */
5671 ptr = (LM_UINT32 *) pBufferVirt;
5672 for (j = 0; j < BufferSize / 4; j++) {
5673 if (*ptr++ != j) {
5674 if ((pDevice->
5675 DmaReadWriteCtrl &
5676 DMA_CTRL_WRITE_BOUNDARY_MASK)
5677 == DMA_CTRL_WRITE_BOUNDARY_DISABLE) {
5678 pDevice->DmaReadWriteCtrl =
5679 (pDevice->
5680 DmaReadWriteCtrl &
5681 ~DMA_CTRL_WRITE_BOUNDARY_MASK) |
5682 DMA_CTRL_WRITE_BOUNDARY_16;
5683 REG_WR (pDevice,
5684 PciCfg.DmaReadWriteCtrl,
5685 pDevice->DmaReadWriteCtrl);
5686 break;
5687 } else {
5688 return LM_STATUS_FAILURE;
5689 }
5690 }
5691 }
5692 if (j == (BufferSize / 4))
5693 dma_success = 1;
5694 }
wdenk8bde7f72003-06-27 21:31:46 +00005695 return LM_STATUS_SUCCESS;
wdenkc6097192002-11-03 00:24:07 +00005696}