1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.91 $
6 * Date: $Date: 2003/02/05 15:09:34 $
7 * Purpose: Contains functions to initialize the MACs and PHYs
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2003 SysKonnect GmbH.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * The information in this file is provided "AS IS" without warranty.
22 ******************************************************************************/
24 /******************************************************************************
29 * Revision 1.91 2003/02/05 15:09:34 rschmidt
30 * Removed setting of 'Collision Test'-bit in SkGmInitPhyMarv().
31 * Disabled auto-update for speed, duplex and flow-control when
32 * auto-negotiation is not enabled (Bug Id #10766).
35 * Revision 1.90 2003/01/29 13:35:19 rschmidt
36 * Increment Rx FIFO Overflow counter only in DEBUG-mode.
37 * Corrected define for blinking active LED.
39 * Revision 1.89 2003/01/28 16:37:45 rschmidt
40 * Changed init for blinking active LED
42 * Revision 1.88 2003/01/28 10:09:38 rschmidt
43 * Added debug outputs in SkGmInitMac().
44 * Added customized init of LED registers in SkGmInitPhyMarv(),
45 * for blinking active LED (#ifdef ACT_LED_BLINK) and
46 * for normal duplex LED (#ifdef DUP_LED_NORMAL).
49 * Revision 1.87 2002/12/10 14:39:05 rschmidt
50 * Improved initialization of GPHY in SkGmInitPhyMarv().
53 * Revision 1.86 2002/12/09 15:01:12 rschmidt
54 * Added setup of Ext. PHY Specific Ctrl Reg (downshift feature).
56 * Revision 1.85 2002/12/05 14:09:16 rschmidt
57 * Improved avoiding endless loop in SkGmPhyWrite(), SkGmPhyWrite().
58 * Added additional advertising for 10Base-T when 100Base-T is selected.
59 * Added case SK_PHY_MARV_FIBER for YUKON Fiber adapter.
62 * Revision 1.84 2002/11/15 12:50:09 rschmidt
63 * Changed SkGmCableDiagStatus() when getting results.
65 * Revision 1.83 2002/11/13 10:28:29 rschmidt
66 * Added some typecasts to avoid compiler warnings.
68 * Revision 1.82 2002/11/13 09:20:46 rschmidt
69 * Replaced for(..) with do {} while (...) in SkXmUpdateStats().
70 * Replaced 2 macros GM_IN16() with 1 GM_IN32() in SkGmMacStatistic().
71 * Added SkGmCableDiagStatus() for Virtual Cable Test (VCT).
74 * Revision 1.81 2002/10/28 14:28:08 rschmidt
75 * Changed MAC address setup for GMAC in SkGmInitMac().
76 * Optimized handling of counter overflow IRQ in SkGmOverflowStatus().
79 * Revision 1.80 2002/10/14 15:29:44 rschmidt
80 * Corrected disabling of all PHY IRQs.
81 * Added WA for deviation #16 (address used for pause packets).
82 * Set Pause Mode in SkMacRxTxEnable() only for Genesis.
83 * Added IRQ and counter for Receive FIFO Overflow in DEBUG-mode.
84 * SkXmTimeStamp() replaced by SkMacTimeStamp().
85 * Added clearing of GMAC Tx FIFO Underrun IRQ in SkGmIrq().
88 * Revision 1.79 2002/10/10 15:55:36 mkarl
89 * changes for PLinkSpeedUsed
91 * Revision 1.78 2002/09/12 09:39:51 rwahl
92 * Removed deactivate code for SIRQ overflow event separate for TX/RX.
94 * Revision 1.77 2002/09/09 12:26:37 mkarl
95 * added handling for Yukon to SkXmTimeStamp
97 * Revision 1.76 2002/08/21 16:41:16 rschmidt
98 * Added bit GPC_ENA_XC (Enable MDI crossover) in HWCFG_MODE.
99 * Added forced speed settings in SkGmInitPhyMarv().
100 * Added settings of full/half duplex capabilities for YUKON Fiber.
103 * Revision 1.75 2002/08/16 15:12:01 rschmidt
104 * Replaced all if(GIChipId == CHIP_ID_GENESIS) with new entry GIGenesis.
105 * Added function SkMacHashing() for ADDR-Module.
106 * Removed functions SkXmClrSrcCheck(), SkXmClrHashAddr() (calls replaced
108 * Removed functions SkGmGetMuxConfig().
109 * Added HWCFG_MODE init for YUKON Fiber.
110 * Changed initialization of GPHY in SkGmInitPhyMarv().
111 * Changed check of parameter in SkXmMacStatistic().
114 * Revision 1.74 2002/08/12 14:00:17 rschmidt
115 * Replaced usage of Broadcom PHY Ids with defines.
116 * Corrected error messages in SkGmMacStatistic().
117 * Made SkMacPromiscMode() public for ADDR-Modul.
120 * Revision 1.73 2002/08/08 16:26:24 rschmidt
121 * Improved reset sequence for YUKON in SkGmHardRst() and SkGmInitMac().
122 * Replaced XMAC Rx High Watermark init value with SK_XM_RX_HI_WM.
125 * Revision 1.72 2002/07/24 15:11:19 rschmidt
126 * Fixed wrong placement of parenthesis.
129 * Revision 1.71 2002/07/23 16:05:18 rschmidt
130 * Added global functions for PHY: SkGePhyRead(), SkGePhyWrite().
131 * Fixed Tx Counter Overflow IRQ (Bug ID #10730).
134 * Revision 1.70 2002/07/18 14:27:27 rwahl
135 * Fixed syntax error.
137 * Revision 1.69 2002/07/17 17:08:47 rwahl
138 * Fixed check in SkXmMacStatistic().
140 * Revision 1.68 2002/07/16 07:35:24 rwahl
141 * Removed check for cleared mib counter in SkGmResetCounter().
143 * Revision 1.67 2002/07/15 18:35:56 rwahl
144 * Added SkXmUpdateStats(), SkGmUpdateStats(), SkXmMacStatistic(),
145 * SkGmMacStatistic(), SkXmResetCounter(), SkGmResetCounter(),
146 * SkXmOverflowStatus(), SkGmOverflowStatus().
147 * Changes to SkXmIrq() & SkGmIrq(): Combined SIRQ Overflow for both
149 * Changes to SkGmInitMac(): call to SkGmResetCounter().
152 * Revision 1.66 2002/07/15 15:59:30 rschmidt
153 * Added PHY Address in SkXmPhyRead(), SkXmPhyWrite().
154 * Added MIB Clear Counter in SkGmInitMac().
155 * Added Duplex and Flow-Control settings.
156 * Reset all Multicast filtering Hash reg. in SkGmInitMac().
157 * Added new function: SkGmGetMuxConfig().
160 * Revision 1.65 2002/06/10 09:35:39 rschmidt
161 * Replaced C++ comments (//).
162 * Added #define VCPU around VCPUwaitTime.
165 * Revision 1.64 2002/06/05 08:41:10 rschmidt
166 * Added function for XMAC2: SkXmTimeStamp().
167 * Added function for YUKON: SkGmSetRxCmd().
168 * Changed SkGmInitMac() resp. SkGmHardRst().
169 * Fixed wrong variable in SkXmAutoNegLipaXmac() (debug mode).
170 * SkXmRxTxEnable() replaced by SkMacRxTxEnable().
173 * Revision 1.63 2002/04/25 13:04:44 rschmidt
174 * Changes for handling YUKON.
175 * Use of #ifdef OTHER_PHY to eliminate code for unused Phy types.
176 * Macros for XMAC PHY access PHY_READ(), PHY_WRITE() replaced
177 * by functions SkXmPhyRead(), SkXmPhyWrite();
178 * Removed use of PRxCmd to setup XMAC.
179 * Added define PHY_B_AS_PAUSE_MSK for BCom Pause Res.
180 * Added setting of XM_RX_DIS_CEXT in SkXmInitMac().
181 * Removed status parameter from MAC IRQ handler SkMacIrq(),
182 * SkXmIrq() and SkGmIrq().
183 * SkXmAutoNegLipa...() for ext. Phy replaced by SkMacAutoNegLipaPhy().
184 * Added SkMac...() functions to handle both XMAC and GMAC.
185 * Added functions for YUKON: SkGmHardRst(), SkGmSoftRst(),
186 * SkGmSetRxTxEn(), SkGmIrq(), SkGmInitMac(), SkGmInitPhyMarv(),
187 * SkGmAutoNegDoneMarv(), SkGmPhyRead(), SkGmPhyWrite().
188 * Changes for V-CPU support.
191 * Revision 1.62 2001/08/06 09:50:14 rschmidt
192 * Workaround BCOM Errata #1 for the C5 type.
195 * Revision 1.61 2001/02/09 15:40:59 rassmann
198 * Revision 1.60 2001/02/07 15:02:01 cgoos
199 * Added workaround for Fujitsu switch link down.
201 * Revision 1.59 2001/01/10 09:38:06 cgoos
202 * Fixed Broadcom C0/A1 Id check for workaround.
204 * Revision 1.58 2000/11/29 11:30:38 cgoos
205 * Changed DEBUG sections with NW output to xDEBUG
207 * Revision 1.57 2000/11/27 12:40:40 rassmann
208 * Suppressing preamble after first access to BCom, not before (#10556).
210 * Revision 1.56 2000/11/09 12:32:48 rassmann
213 * Revision 1.55 2000/11/09 11:30:10 rassmann
214 * WA: Waiting after releasing reset until BCom chip is accessible.
216 * Revision 1.54 2000/10/02 14:10:27 rassmann
217 * Reading BCOM PHY after releasing reset until it returns a valid value.
219 * Revision 1.53 2000/07/27 12:22:11 gklug
220 * fix: possible endless loop in XmHardRst.
222 * Revision 1.52 2000/05/22 08:48:31 malthoff
223 * Fix: #10523 errata valid for all BCOM PHYs.
225 * Revision 1.51 2000/05/17 12:52:18 malthoff
226 * Fixes BCom link errata (#10523).
228 * Revision 1.50 1999/11/22 13:40:14 cgoos
229 * Changed license header to GPL.
231 * Revision 1.49 1999/11/22 08:12:13 malthoff
232 * Add workaround for power consumption feature of BCom C0 chip.
234 * Revision 1.48 1999/11/16 08:39:01 malthoff
235 * Fix: MDIO preamble suppression is port dependent.
237 * Revision 1.47 1999/08/27 08:55:35 malthoff
238 * 1000BT: Optimizing MDIO transfer by oppressing MDIO preamble.
240 * Revision 1.46 1999/08/13 11:01:12 malthoff
241 * Fix for 1000BT: pFlowCtrlMode was not set correctly.
243 * Revision 1.45 1999/08/12 19:18:28 malthoff
244 * 1000BT Fixes: Do not owerwrite XM_MMU_CMD.
245 * Do not execute BCOM A1 workaround for B1 chips.
246 * Fix pause frame setting.
247 * Always set PHY_B_AC_TX_TST in PHY_BCOM_AUX_CTRL.
249 * Revision 1.44 1999/08/03 15:23:48 cgoos
250 * Fixed setting of PHY interrupt mask in half duplex mode.
252 * Revision 1.43 1999/08/03 15:22:17 cgoos
253 * Added some debug output.
254 * Disabled XMac GP0 interrupt for external PHYs.
256 * Revision 1.42 1999/08/02 08:39:23 malthoff
257 * BCOM PHY: TX LED: To get the mono flop behaviour it is required
258 * to set the LED Traffic Mode bit in PHY_BCOM_P_EXT_CTRL.
260 * Revision 1.41 1999/07/30 06:54:31 malthoff
261 * Add temp. workarounds for the BCOM Phy revision A1.
263 * Revision 1.40 1999/06/01 07:43:26 cgoos
264 * Changed Link Mode Status in SkXmAutoNegDone... from FULL/HALF to
267 * Revision 1.39 1999/05/19 07:29:51 cgoos
268 * Changes for 1000Base-T.
270 * Revision 1.38 1999/04/08 14:35:10 malthoff
271 * Add code for enabling signal detect. Enabling signal detect is disabled.
273 * Revision 1.37 1999/03/12 13:42:54 malthoff
274 * Add: Jumbo Frame Support.
275 * Add: Receive modes SK_LENERR_OK_ON/OFF and
276 * SK_BIG_PK_OK_ON/OFF in SkXmSetRxCmd().
278 * Revision 1.36 1999/03/08 10:10:55 gklug
279 * fix: AutoSensing did switch to next mode even if LiPa indicated offline
281 * Revision 1.35 1999/02/22 15:16:41 malthoff
282 * Remove some compiler warnings.
284 * Revision 1.34 1999/01/22 09:19:59 gklug
285 * fix: Init DupMode and InitPauseMd are now called in RxTxEnable
287 * Revision 1.33 1998/12/11 15:19:11 gklug
288 * chg: lipa autoneg stati
289 * chg: debug messages
290 * chg: do NOT use spurious XmIrq
292 * Revision 1.32 1998/12/10 11:08:44 malthoff
293 * bug fix: pAC has been used for IOs in SkXmHardRst().
294 * SkXmInitPhy() is also called for the Diag in SkXmInitMac().
296 * Revision 1.31 1998/12/10 10:39:11 gklug
297 * fix: do 4 RESETS of the XMAC at the beginning
298 * fix: dummy read interrupt source register BEFORE initializing the Phy
299 * add: debug messages
300 * fix: Linkpartners autoneg capability cannot be shown by TX_PAGE interrupt
302 * Revision 1.30 1998/12/07 12:18:32 gklug
303 * add: refinement of autosense mode: take into account the autoneg cap of LiPa
305 * Revision 1.29 1998/12/07 07:12:29 gklug
306 * fix: if page is received the link is down.
308 * Revision 1.28 1998/12/01 10:12:47 gklug
309 * chg: if spurious IRQ from XMAC encountered, save it
311 * Revision 1.27 1998/11/26 07:33:38 gklug
312 * add: InitPhy call is now in XmInit function
314 * Revision 1.26 1998/11/18 13:38:24 malthoff
315 * 'Imsk' is also unused in SkXmAutoNegDone.
317 * Revision 1.25 1998/11/18 13:28:01 malthoff
318 * Remove unused variable 'Reg' in SkXmAutoNegDone().
320 * Revision 1.24 1998/11/18 13:18:45 gklug
321 * add: workaround for xmac errata #1
322 * add: detect Link Down also when Link partner requested config
323 * chg: XMIrq is only used when link is up
325 * Revision 1.23 1998/11/04 07:07:04 cgoos
326 * Added function SkXmRxTxEnable.
328 * Revision 1.22 1998/10/30 07:35:54 gklug
329 * fix: serve LinkDown interrupt when link is already down
331 * Revision 1.21 1998/10/29 15:32:03 gklug
332 * fix: Link Down signaling
334 * Revision 1.20 1998/10/29 11:17:27 gklug
335 * fix: AutoNegDone bug
337 * Revision 1.19 1998/10/29 10:14:43 malthoff
338 * Add endainesss comment for reading/writing MAC addresses.
340 * Revision 1.18 1998/10/28 07:48:55 cgoos
341 * Fix: ASS somtimes signaled although link is up.
343 * Revision 1.17 1998/10/26 07:55:39 malthoff
344 * Fix in SkXmInitPauseMd(): Pause Mode
345 * was disabled and not enabled.
346 * Fix in SkXmAutoNegDone(): Checking Mode bits
347 * always failed, becaues of some missing braces.
349 * Revision 1.16 1998/10/22 09:46:52 gklug
350 * fix SysKonnectFileId typo
352 * Revision 1.15 1998/10/21 05:51:37 gklug
353 * add: para DoLoop to InitPhy function for loopback set-up
355 * Revision 1.14 1998/10/16 10:59:23 malthoff
356 * Remove Lint warning for dummy reads.
358 * Revision 1.13 1998/10/15 14:01:20 malthoff
359 * Fix: SkXmAutoNegDone() is (int) but does not return a value.
361 * Revision 1.12 1998/10/14 14:45:04 malthoff
362 * Remove SKERR_SIRQ_E0xx and SKERR_SIRQ_E0xxMSG by
363 * SKERR_HWI_Exx and SKERR_HWI_E0xxMSG to be independent
364 * from the Sirq module.
366 * Revision 1.11 1998/10/14 13:59:01 gklug
367 * add: InitPhy function
369 * Revision 1.10 1998/10/14 11:20:57 malthoff
370 * Make SkXmAutoNegDone() public, because it's
371 * used in diagnostics, too.
372 * The Link Up event to the RLMT is issued in SkXmIrq().
373 * SkXmIrq() is not available in diagnostics.
374 * Use PHY_READ when reading PHY registers.
376 * Revision 1.9 1998/10/14 05:50:10 cgoos
377 * Added definition for Para.
379 * Revision 1.8 1998/10/14 05:41:28 gklug
381 * add: auto-negotiation done function
383 * Revision 1.7 1998/10/09 06:55:20 malthoff
384 * The configuration of the XMACs Tx Request Threshold
385 * depends from the drivers port usage now. The port
386 * usage is configured in GIPortUsage.
388 * Revision 1.6 1998/10/05 07:48:00 malthoff
391 * Revision 1.5 1998/10/01 07:03:54 gklug
392 * add: dummy function for XMAC ISR
394 * Revision 1.4 1998/09/30 12:37:44 malthoff
395 * Add SkXmSetRxCmd() and related code.
397 * Revision 1.3 1998/09/28 13:26:40 malthoff
398 * Add SkXmInitMac(), SkXmInitDupMd(), and SkXmInitPauseMd()
400 * Revision 1.2 1998/09/16 14:34:21 malthoff
401 * Add SkXmClrExactAddr(), SkXmClrSrcCheck(),
402 * SkXmClrHashAddr(), SkXmFlushTxFifo(),
403 * SkXmFlushRxFifo(), and SkXmHardRst().
404 * Finish Coding of SkXmSoftRst().
405 * The sources may be compiled now.
407 * Revision 1.1 1998/09/04 10:05:56 malthoff
411 ******************************************************************************/
417 #include "h/skdrv1st.h"
418 #include "h/skdrv2nd.h"
420 /* typedefs *******************************************************************/
422 /* BCOM PHY magic pattern list */
423 typedef struct s_PhyHack {
424 int PhyReg; /* Phy register */
425 SK_U16 PhyVal; /* Value to write */
428 /* local variables ************************************************************/
429 static const char SysKonnectFileId[] =
430 "@(#)$Id: skxmac2.c,v 1.91 2003/02/05 15:09:34 rschmidt Exp $ (C) SK ";
432 BCOM_HACK BcomRegA1Hack[] = {
433 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1104 }, { 0x17, 0x0013 },
434 { 0x15, 0x0404 }, { 0x17, 0x8006 }, { 0x15, 0x0132 }, { 0x17, 0x8006 },
435 { 0x15, 0x0232 }, { 0x17, 0x800D }, { 0x15, 0x000F }, { 0x18, 0x0420 },
438 BCOM_HACK BcomRegC0Hack[] = {
439 { 0x18, 0x0c20 }, { 0x17, 0x0012 }, { 0x15, 0x1204 }, { 0x17, 0x0013 },
440 { 0x15, 0x0A04 }, { 0x18, 0x0420 },
444 /* function prototypes ********************************************************/
445 static void SkXmInitPhyXmac(SK_AC*, SK_IOC, int, SK_BOOL);
446 static void SkXmInitPhyBcom(SK_AC*, SK_IOC, int, SK_BOOL);
447 static void SkGmInitPhyMarv(SK_AC*, SK_IOC, int, SK_BOOL);
448 static int SkXmAutoNegDoneXmac(SK_AC*, SK_IOC, int);
449 static int SkXmAutoNegDoneBcom(SK_AC*, SK_IOC, int);
450 static int SkGmAutoNegDoneMarv(SK_AC*, SK_IOC, int);
452 static void SkXmInitPhyLone(SK_AC*, SK_IOC, int, SK_BOOL);
453 static void SkXmInitPhyNat (SK_AC*, SK_IOC, int, SK_BOOL);
454 static int SkXmAutoNegDoneLone(SK_AC*, SK_IOC, int);
455 static int SkXmAutoNegDoneNat (SK_AC*, SK_IOC, int);
456 #endif /* OTHER_PHY */
459 /******************************************************************************
461 * SkXmPhyRead() - Read from XMAC PHY register
463 * Description: reads a 16-bit word from XMAC PHY or ext. PHY
469 SK_AC *pAC, /* Adapter Context */
470 SK_IOC IoC, /* I/O Context */
471 int Port, /* Port Index (MAC_1 + n) */
472 int PhyReg, /* Register Address (Offset) */
473 SK_U16 *pVal) /* Pointer to Value */
478 pPrt = &pAC->GIni.GP[Port];
480 /* write the PHY register's address */
481 XM_OUT16(IoC, Port, XM_PHY_ADDR, PhyReg | pPrt->PhyAddr);
483 /* get the PHY register's value */
484 XM_IN16(IoC, Port, XM_PHY_DATA, pVal);
486 if (pPrt->PhyType != SK_PHY_XMAC) {
488 XM_IN16(IoC, Port, XM_MMU_CMD, &Mmu);
489 /* wait until 'Ready' is set */
490 } while ((Mmu & XM_MMU_PHY_RDY) == 0);
492 /* get the PHY register's value */
493 XM_IN16(IoC, Port, XM_PHY_DATA, pVal);
498 /******************************************************************************
500 * SkXmPhyWrite() - Write to XMAC PHY register
502 * Description: writes a 16-bit word to XMAC PHY or ext. PHY
508 SK_AC *pAC, /* Adapter Context */
509 SK_IOC IoC, /* I/O Context */
510 int Port, /* Port Index (MAC_1 + n) */
511 int PhyReg, /* Register Address (Offset) */
512 SK_U16 Val) /* Value */
517 pPrt = &pAC->GIni.GP[Port];
519 if (pPrt->PhyType != SK_PHY_XMAC) {
521 XM_IN16(IoC, Port, XM_MMU_CMD, &Mmu);
522 /* wait until 'Busy' is cleared */
523 } while ((Mmu & XM_MMU_PHY_BUSY) != 0);
526 /* write the PHY register's address */
527 XM_OUT16(IoC, Port, XM_PHY_ADDR, PhyReg | pPrt->PhyAddr);
529 /* write the PHY register's value */
530 XM_OUT16(IoC, Port, XM_PHY_DATA, Val);
532 if (pPrt->PhyType != SK_PHY_XMAC) {
534 XM_IN16(IoC, Port, XM_MMU_CMD, &Mmu);
535 /* wait until 'Busy' is cleared */
536 } while ((Mmu & XM_MMU_PHY_BUSY) != 0);
541 /******************************************************************************
543 * SkGmPhyRead() - Read from GPHY register
545 * Description: reads a 16-bit word from GPHY through MDIO
551 SK_AC *pAC, /* Adapter Context */
552 SK_IOC IoC, /* I/O Context */
553 int Port, /* Port Index (MAC_1 + n) */
554 int PhyReg, /* Register Address (Offset) */
555 SK_U16 *pVal) /* Pointer to Value */
563 VCPUgetTime(&SimCyle, &SimLowTime);
564 VCPUprintf(0, "SkGmPhyRead(%u), SimCyle=%u, SimLowTime=%u\n",
565 PhyReg, SimCyle, SimLowTime);
568 pPrt = &pAC->GIni.GP[Port];
570 /* set PHY-Register offset and 'Read' OpCode (= 1) */
571 *pVal = (SK_U16)(GM_SMI_CT_PHY_AD(pPrt->PhyAddr) |
572 GM_SMI_CT_REG_AD(PhyReg) | GM_SMI_CT_OP_RD);
574 GM_OUT16(IoC, Port, GM_SMI_CTRL, *pVal);
576 GM_IN16(IoC, Port, GM_SMI_CTRL, &Ctrl);
578 /* additional check for MDC/MDIO activity */
579 if ((Ctrl & GM_SMI_CT_BUSY) == 0) {
584 *pVal |= GM_SMI_CT_BUSY;
591 GM_IN16(IoC, Port, GM_SMI_CTRL, &Ctrl);
593 /* wait until 'ReadValid' is set */
594 } while (Ctrl == *pVal);
596 /* get the PHY register's value */
597 GM_IN16(IoC, Port, GM_SMI_DATA, pVal);
600 VCPUgetTime(&SimCyle, &SimLowTime);
601 VCPUprintf(0, "VCPUgetTime(), SimCyle=%u, SimLowTime=%u\n",
602 SimCyle, SimLowTime);
607 /******************************************************************************
609 * SkGmPhyWrite() - Write to GPHY register
611 * Description: writes a 16-bit word to GPHY through MDIO
617 SK_AC *pAC, /* Adapter Context */
618 SK_IOC IoC, /* I/O Context */
619 int Port, /* Port Index (MAC_1 + n) */
620 int PhyReg, /* Register Address (Offset) */
621 SK_U16 Val) /* Value */
630 VCPUgetTime(&SimCyle, &SimLowTime);
631 VCPUprintf(0, "SkGmPhyWrite(Reg=%u, Val=0x%04x), SimCyle=%u, SimLowTime=%u\n",
632 PhyReg, Val, SimCyle, SimLowTime);
635 pPrt = &pAC->GIni.GP[Port];
637 /* write the PHY register's value */
638 GM_OUT16(IoC, Port, GM_SMI_DATA, Val);
640 /* set PHY-Register offset and 'Write' OpCode (= 0) */
641 Val = GM_SMI_CT_PHY_AD(pPrt->PhyAddr) | GM_SMI_CT_REG_AD(PhyReg);
643 GM_OUT16(IoC, Port, GM_SMI_CTRL, Val);
645 GM_IN16(IoC, Port, GM_SMI_CTRL, &Ctrl);
647 /* additional check for MDC/MDIO activity */
648 if ((Ctrl & GM_SMI_CT_BUSY) == 0) {
652 Val |= GM_SMI_CT_BUSY;
656 /* read Timer value */
657 SK_IN32(IoC, B2_TI_VAL, &DWord);
662 GM_IN16(IoC, Port, GM_SMI_CTRL, &Ctrl);
664 /* wait until 'Busy' is cleared */
665 } while (Ctrl == Val);
668 VCPUgetTime(&SimCyle, &SimLowTime);
669 VCPUprintf(0, "VCPUgetTime(), SimCyle=%u, SimLowTime=%u\n",
670 SimCyle, SimLowTime);
675 /******************************************************************************
677 * SkGePhyRead() - Read from PHY register
679 * Description: calls a read PHY routine dep. on board type
685 SK_AC *pAC, /* Adapter Context */
686 SK_IOC IoC, /* I/O Context */
687 int Port, /* Port Index (MAC_1 + n) */
688 int PhyReg, /* Register Address (Offset) */
689 SK_U16 *pVal) /* Pointer to Value */
691 void (*r_func)(SK_AC *pAC, SK_IOC IoC, int Port, int Reg, SK_U16 *pVal);
693 if (pAC->GIni.GIGenesis) {
694 r_func = SkXmPhyRead;
697 r_func = SkGmPhyRead;
700 r_func(pAC, IoC, Port, PhyReg, pVal);
704 /******************************************************************************
706 * SkGePhyWrite() - Write to PHY register
708 * Description: calls a write PHY routine dep. on board type
714 SK_AC *pAC, /* Adapter Context */
715 SK_IOC IoC, /* I/O Context */
716 int Port, /* Port Index (MAC_1 + n) */
717 int PhyReg, /* Register Address (Offset) */
718 SK_U16 Val) /* Value */
720 void (*w_func)(SK_AC *pAC, SK_IOC IoC, int Port, int Reg, SK_U16 Val);
722 if (pAC->GIni.GIGenesis) {
723 w_func = SkXmPhyWrite;
726 w_func = SkGmPhyWrite;
729 w_func(pAC, IoC, Port, PhyReg, Val);
733 /******************************************************************************
735 * SkMacPromiscMode() - Enable / Disable Promiscuous Mode
738 * enables / disables promiscuous mode by setting Mode Register (XMAC) or
739 * Receive Control Register (GMAC) dep. on board type
744 void SkMacPromiscMode(
745 SK_AC *pAC, /* adapter context */
746 SK_IOC IoC, /* IO context */
747 int Port, /* Port Index (MAC_1 + n) */
748 SK_BOOL Enable) /* Enable / Disable */
753 if (pAC->GIni.GIGenesis) {
755 XM_IN32(IoC, Port, XM_MODE, &MdReg);
756 /* enable or disable promiscuous mode */
758 MdReg |= XM_MD_ENA_PROM;
761 MdReg &= ~XM_MD_ENA_PROM;
763 /* setup Mode Register */
764 XM_OUT32(IoC, Port, XM_MODE, MdReg);
768 GM_IN16(IoC, Port, GM_RX_CTRL, &RcReg);
770 /* enable or disable unicast and multicast filtering */
772 RcReg &= ~(GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
775 RcReg |= (GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
777 /* setup Receive Control Register */
778 GM_OUT16(IoC, Port, GM_RX_CTRL, RcReg);
780 } /* SkMacPromiscMode*/
783 /******************************************************************************
785 * SkMacHashing() - Enable / Disable Hashing
788 * enables / disables hashing by setting Mode Register (XMAC) or
789 * Receive Control Register (GMAC) dep. on board type
795 SK_AC *pAC, /* adapter context */
796 SK_IOC IoC, /* IO context */
797 int Port, /* Port Index (MAC_1 + n) */
798 SK_BOOL Enable) /* Enable / Disable */
803 if (pAC->GIni.GIGenesis) {
805 XM_IN32(IoC, Port, XM_MODE, &MdReg);
806 /* enable or disable hashing */
808 MdReg |= XM_MD_ENA_HASH;
811 MdReg &= ~XM_MD_ENA_HASH;
813 /* setup Mode Register */
814 XM_OUT32(IoC, Port, XM_MODE, MdReg);
818 GM_IN16(IoC, Port, GM_RX_CTRL, &RcReg);
820 /* enable or disable multicast filtering */
822 RcReg |= GM_RXCR_MCF_ENA;
825 RcReg &= ~GM_RXCR_MCF_ENA;
827 /* setup Receive Control Register */
828 GM_OUT16(IoC, Port, GM_RX_CTRL, RcReg);
834 /******************************************************************************
836 * SkXmSetRxCmd() - Modify the value of the XMAC's Rx Command Register
840 * - FCS stripping, SK_STRIP_FCS_ON/OFF
841 * - pad byte stripping, SK_STRIP_PAD_ON/OFF
842 * - don't set XMR_FS_ERR in status SK_LENERR_OK_ON/OFF
843 * for inrange length error frames
844 * - don't set XMR_FS_ERR in status SK_BIG_PK_OK_ON/OFF
845 * for frames > 1514 bytes
846 * - enable Rx of own packets SK_SELF_RX_ON/OFF
848 * for incoming packets may be enabled/disabled by this function.
849 * Additional modes may be added later.
850 * Multiple modes can be enabled/disabled at the same time.
851 * The new configuration is written to the Rx Command register immediately.
856 static void SkXmSetRxCmd(
857 SK_AC *pAC, /* adapter context */
858 SK_IOC IoC, /* IO context */
859 int Port, /* Port Index (MAC_1 + n) */
860 int Mode) /* Mode is SK_STRIP_FCS_ON/OFF, SK_STRIP_PAD_ON/OFF,
861 SK_LENERR_OK_ON/OFF, or SK_BIG_PK_OK_ON/OFF */
866 XM_IN16(IoC, Port, XM_RX_CMD, &OldRxCmd);
870 switch (Mode & (SK_STRIP_FCS_ON | SK_STRIP_FCS_OFF)) {
871 case SK_STRIP_FCS_ON:
872 RxCmd |= XM_RX_STRIP_FCS;
874 case SK_STRIP_FCS_OFF:
875 RxCmd &= ~XM_RX_STRIP_FCS;
879 switch (Mode & (SK_STRIP_PAD_ON | SK_STRIP_PAD_OFF)) {
880 case SK_STRIP_PAD_ON:
881 RxCmd |= XM_RX_STRIP_PAD;
883 case SK_STRIP_PAD_OFF:
884 RxCmd &= ~XM_RX_STRIP_PAD;
888 switch (Mode & (SK_LENERR_OK_ON | SK_LENERR_OK_OFF)) {
889 case SK_LENERR_OK_ON:
890 RxCmd |= XM_RX_LENERR_OK;
892 case SK_LENERR_OK_OFF:
893 RxCmd &= ~XM_RX_LENERR_OK;
897 switch (Mode & (SK_BIG_PK_OK_ON | SK_BIG_PK_OK_OFF)) {
898 case SK_BIG_PK_OK_ON:
899 RxCmd |= XM_RX_BIG_PK_OK;
901 case SK_BIG_PK_OK_OFF:
902 RxCmd &= ~XM_RX_BIG_PK_OK;
906 switch (Mode & (SK_SELF_RX_ON | SK_SELF_RX_OFF)) {
908 RxCmd |= XM_RX_SELF_RX;
911 RxCmd &= ~XM_RX_SELF_RX;
915 /* Write the new mode to the Rx command register if required */
916 if (OldRxCmd != RxCmd) {
917 XM_OUT16(IoC, Port, XM_RX_CMD, RxCmd);
922 /******************************************************************************
924 * SkGmSetRxCmd() - Modify the value of the GMAC's Rx Control Register
928 * - FCS (CRC) stripping, SK_STRIP_FCS_ON/OFF
929 * - don't set GMR_FS_LONG_ERR SK_BIG_PK_OK_ON/OFF
930 * for frames > 1514 bytes
931 * - enable Rx of own packets SK_SELF_RX_ON/OFF
933 * for incoming packets may be enabled/disabled by this function.
934 * Additional modes may be added later.
935 * Multiple modes can be enabled/disabled at the same time.
936 * The new configuration is written to the Rx Command register immediately.
941 static void SkGmSetRxCmd(
942 SK_AC *pAC, /* adapter context */
943 SK_IOC IoC, /* IO context */
944 int Port, /* Port Index (MAC_1 + n) */
945 int Mode) /* Mode is SK_STRIP_FCS_ON/OFF, SK_STRIP_PAD_ON/OFF,
946 SK_LENERR_OK_ON/OFF, or SK_BIG_PK_OK_ON/OFF */
951 if ((Mode & (SK_STRIP_FCS_ON | SK_STRIP_FCS_OFF)) != 0) {
953 GM_IN16(IoC, Port, GM_RX_CTRL, &OldRxCmd);
957 if ((Mode & SK_STRIP_FCS_ON) != 0) {
958 RxCmd |= GM_RXCR_CRC_DIS;
961 RxCmd &= ~GM_RXCR_CRC_DIS;
963 /* Write the new mode to the Rx control register if required */
964 if (OldRxCmd != RxCmd) {
965 GM_OUT16(IoC, Port, GM_RX_CTRL, RxCmd);
969 if ((Mode & (SK_BIG_PK_OK_ON | SK_BIG_PK_OK_OFF)) != 0) {
971 GM_IN16(IoC, Port, GM_SERIAL_MODE, &OldRxCmd);
975 if ((Mode & SK_BIG_PK_OK_ON) != 0) {
976 RxCmd |= GM_SMOD_JUMBO_ENA;
979 RxCmd &= ~GM_SMOD_JUMBO_ENA;
981 /* Write the new mode to the Rx control register if required */
982 if (OldRxCmd != RxCmd) {
983 GM_OUT16(IoC, Port, GM_SERIAL_MODE, RxCmd);
989 /******************************************************************************
991 * SkMacSetRxCmd() - Modify the value of the MAC's Rx Control Register
993 * Description: modifies the MAC's Rx Control reg. dep. on board type
999 SK_AC *pAC, /* adapter context */
1000 SK_IOC IoC, /* IO context */
1001 int Port, /* Port Index (MAC_1 + n) */
1002 int Mode) /* Rx Mode */
1004 if (pAC->GIni.GIGenesis) {
1006 SkXmSetRxCmd(pAC, IoC, Port, Mode);
1010 SkGmSetRxCmd(pAC, IoC, Port, Mode);
1012 } /* SkMacSetRxCmd */
1015 /******************************************************************************
1017 * SkMacCrcGener() - Enable / Disable CRC Generation
1019 * Description: enables / disables CRC generation dep. on board type
1025 SK_AC *pAC, /* adapter context */
1026 SK_IOC IoC, /* IO context */
1027 int Port, /* Port Index (MAC_1 + n) */
1028 SK_BOOL Enable) /* Enable / Disable */
1032 if (pAC->GIni.GIGenesis) {
1034 XM_IN16(IoC, Port, XM_TX_CMD, &Word);
1037 Word &= ~XM_TX_NO_CRC;
1040 Word |= XM_TX_NO_CRC;
1042 /* setup Tx Command Register */
1043 XM_OUT16(pAC, Port, XM_TX_CMD, Word);
1047 GM_IN16(IoC, Port, GM_TX_CTRL, &Word);
1050 Word &= ~GM_TXCR_CRC_DIS;
1053 Word |= GM_TXCR_CRC_DIS;
1055 /* setup Tx Control Register */
1056 GM_OUT16(IoC, Port, GM_TX_CTRL, Word);
1058 } /* SkMacCrcGener*/
1060 #endif /* SK_DIAG */
1063 /******************************************************************************
1065 * SkXmClrExactAddr() - Clear Exact Match Address Registers
1068 * All Exact Match Address registers of the XMAC 'Port' will be
1069 * cleared starting with 'StartNum' up to (and including) the
1070 * Exact Match address number of 'StopNum'.
1075 void SkXmClrExactAddr(
1076 SK_AC *pAC, /* adapter context */
1077 SK_IOC IoC, /* IO context */
1078 int Port, /* Port Index (MAC_1 + n) */
1079 int StartNum, /* Begin with this Address Register Index (0..15) */
1080 int StopNum) /* Stop after finished with this Register Idx (0..15) */
1083 SK_U16 ZeroAddr[3] = {0x0000, 0x0000, 0x0000};
1085 if ((unsigned)StartNum > 15 || (unsigned)StopNum > 15 ||
1086 StartNum > StopNum) {
1088 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E001, SKERR_HWI_E001MSG);
1092 for (i = StartNum; i <= StopNum; i++) {
1093 XM_OUTADDR(IoC, Port, XM_EXM(i), &ZeroAddr[0]);
1095 } /* SkXmClrExactAddr */
1098 /******************************************************************************
1100 * SkMacFlushTxFifo() - Flush the MAC's transmit FIFO
1103 * Flush the transmit FIFO of the MAC specified by the index 'Port'
1108 void SkMacFlushTxFifo(
1109 SK_AC *pAC, /* adapter context */
1110 SK_IOC IoC, /* IO context */
1111 int Port) /* Port Index (MAC_1 + n) */
1115 if (pAC->GIni.GIGenesis) {
1117 XM_IN32(IoC, Port, XM_MODE, &MdReg);
1119 XM_OUT32(IoC, Port, XM_MODE, MdReg | XM_MD_FTF);
1122 /* no way to flush the FIFO we have to issue a reset */
1125 } /* SkMacFlushTxFifo */
1128 /******************************************************************************
1130 * SkMacFlushRxFifo() - Flush the MAC's receive FIFO
1133 * Flush the receive FIFO of the MAC specified by the index 'Port'
1138 void SkMacFlushRxFifo(
1139 SK_AC *pAC, /* adapter context */
1140 SK_IOC IoC, /* IO context */
1141 int Port) /* Port Index (MAC_1 + n) */
1145 if (pAC->GIni.GIGenesis) {
1147 XM_IN32(IoC, Port, XM_MODE, &MdReg);
1149 XM_OUT32(IoC, Port, XM_MODE, MdReg | XM_MD_FRF);
1152 /* no way to flush the FIFO we have to issue a reset */
1155 } /* SkMacFlushRxFifo */
1158 /******************************************************************************
1160 * SkXmSoftRst() - Do a XMAC software reset
1163 * The PHY registers should not be destroyed during this
1164 * kind of software reset. Therefore the XMAC Software Reset
1165 * (XM_GP_RES_MAC bit in XM_GP_PORT) must not be used!
1167 * The software reset is done by
1168 * - disabling the Rx and Tx state machine,
1169 * - resetting the statistics module,
1170 * - clear all other significant XMAC Mode,
1171 * Command, and Control Registers
1172 * - clearing the Hash Register and the
1173 * Exact Match Address registers, and
1174 * - flushing the XMAC's Rx and Tx FIFOs.
1177 * Another requirement when stopping the XMAC is to
1178 * avoid sending corrupted frames on the network.
1179 * Disabling the Tx state machine will NOT interrupt
1180 * the currently transmitted frame. But we must take care
1181 * that the Tx FIFO is cleared AFTER the current frame
1182 * is complete sent to the network.
1184 * It takes about 12ns to send a frame with 1538 bytes.
1185 * One PCI clock goes at least 15ns (66MHz). Therefore
1186 * after reading XM_GP_PORT back, we are sure that the
1187 * transmitter is disabled AND idle. And this means
1188 * we may flush the transmit FIFO now.
1193 static void SkXmSoftRst(
1194 SK_AC *pAC, /* adapter context */
1195 SK_IOC IoC, /* IO context */
1196 int Port) /* Port Index (MAC_1 + n) */
1198 SK_U16 ZeroAddr[4] = {0x0000, 0x0000, 0x0000, 0x0000};
1200 /* reset the statistics module */
1201 XM_OUT32(IoC, Port, XM_GP_PORT, XM_GP_RES_STAT);
1203 /* disable all XMAC IRQs */
1204 XM_OUT16(IoC, Port, XM_IMSK, 0xffff);
1206 XM_OUT32(IoC, Port, XM_MODE, 0); /* clear Mode Reg */
1208 XM_OUT16(IoC, Port, XM_TX_CMD, 0); /* reset TX CMD Reg */
1209 XM_OUT16(IoC, Port, XM_RX_CMD, 0); /* reset RX CMD Reg */
1211 /* disable all PHY IRQs */
1212 switch (pAC->GIni.GP[Port].PhyType) {
1214 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_INT_MASK, 0xffff);
1218 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_INT_ENAB, 0);
1222 SkXmPhyWrite(pAC, IoC, Port, PHY_NAT_INT_MASK, 0xffff); */
1224 #endif /* OTHER_PHY */
1227 /* clear the Hash Register */
1228 XM_OUTHASH(IoC, Port, XM_HSM, &ZeroAddr);
1230 /* clear the Exact Match Address registers */
1231 SkXmClrExactAddr(pAC, IoC, Port, 0, 15);
1233 /* clear the Source Check Address registers */
1234 XM_OUTHASH(IoC, Port, XM_SRC_CHK, &ZeroAddr);
1239 /******************************************************************************
1241 * SkXmHardRst() - Do a XMAC hardware reset
1244 * The XMAC of the specified 'Port' and all connected devices
1245 * (PHY and SERDES) will receive a reset signal on its *Reset pins.
1246 * External PHYs must be reset be clearing a bit in the GPIO register
1247 * (Timing requirements: Broadcom: 400ns, Level One: none, National: 80ns).
1250 * It is absolutely necessary to reset the SW_RST Bit first
1251 * before calling this function.
1256 static void SkXmHardRst(
1257 SK_AC *pAC, /* adapter context */
1258 SK_IOC IoC, /* IO context */
1259 int Port) /* Port Index (MAC_1 + n) */
1266 for (i = 0; i < 4; i++) {
1267 /* TX_MFF_CTRL1 has 32 bits, but only the lowest 16 bits are used */
1268 SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1272 if (TOut++ > 10000) {
1274 * Adapter seems to be in RESET state.
1275 * Registers cannot be written.
1280 SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_SET_MAC_RST);
1282 SK_IN16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), &Word);
1284 } while ((Word & MFF_SET_MAC_RST) == 0);
1287 /* For external PHYs there must be special handling */
1288 if (pAC->GIni.GP[Port].PhyType != SK_PHY_XMAC) {
1289 /* reset external PHY */
1290 SK_IN32(IoC, B2_GP_IO, &Reg);
1292 Reg |= GP_DIR_0; /* set to output */
1296 Reg |= GP_DIR_2; /* set to output */
1299 SK_OUT32(IoC, B2_GP_IO, Reg);
1302 SK_IN32(IoC, B2_GP_IO, &Reg);
1308 /******************************************************************************
1310 * SkGmSoftRst() - Do a GMAC software reset
1313 * The GPHY registers should not be destroyed during this
1314 * kind of software reset.
1319 static void SkGmSoftRst(
1320 SK_AC *pAC, /* adapter context */
1321 SK_IOC IoC, /* IO context */
1322 int Port) /* Port Index (MAC_1 + n) */
1324 SK_U16 EmptyHash[4] = {0x0000, 0x0000, 0x0000, 0x0000};
1327 /* reset the statistics module */
1329 /* disable all GMAC IRQs */
1330 SK_OUT8(IoC, GMAC_IRQ_MSK, 0);
1332 /* disable all PHY IRQs */
1333 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_INT_MASK, 0);
1335 /* clear the Hash Register */
1336 GM_OUTHASH(IoC, Port, GM_MC_ADDR_H1, EmptyHash);
1338 /* Enable Unicast and Multicast filtering */
1339 GM_IN16(IoC, Port, GM_RX_CTRL, &RxCtrl);
1341 GM_OUT16(IoC, Port, GM_RX_CTRL,
1342 RxCtrl | GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA);
1347 /******************************************************************************
1349 * SkGmHardRst() - Do a GMAC hardware reset
1354 * It is absolutely necessary to reset the SW_RST Bit first
1355 * before calling this function.
1360 static void SkGmHardRst(
1361 SK_AC *pAC, /* adapter context */
1362 SK_IOC IoC, /* IO context */
1363 int Port) /* Port Index (MAC_1 + n) */
1365 /* set GPHY Control reset */
1366 SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), GPC_RST_SET);
1368 /* set GMAC Control reset */
1369 SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_SET);
1374 /******************************************************************************
1376 * SkMacSoftRst() - Do a MAC software reset
1378 * Description: calls a MAC software reset routine dep. on board type
1384 SK_AC *pAC, /* adapter context */
1385 SK_IOC IoC, /* IO context */
1386 int Port) /* Port Index (MAC_1 + n) */
1390 pPrt = &pAC->GIni.GP[Port];
1392 /* disable receiver and transmitter */
1393 SkMacRxTxDisable(pAC, IoC, Port);
1395 if (pAC->GIni.GIGenesis) {
1397 SkXmSoftRst(pAC, IoC, Port);
1401 SkGmSoftRst(pAC, IoC, Port);
1404 /* flush the MAC's Rx and Tx FIFOs */
1405 SkMacFlushTxFifo(pAC, IoC, Port);
1407 SkMacFlushRxFifo(pAC, IoC, Port);
1409 pPrt->PState = SK_PRT_STOP;
1411 } /* SkMacSoftRst */
1414 /******************************************************************************
1416 * SkMacHardRst() - Do a MAC hardware reset
1418 * Description: calls a MAC hardware reset routine dep. on board type
1424 SK_AC *pAC, /* adapter context */
1425 SK_IOC IoC, /* IO context */
1426 int Port) /* Port Index (MAC_1 + n) */
1429 if (pAC->GIni.GIGenesis) {
1431 SkXmHardRst(pAC, IoC, Port);
1435 SkGmHardRst(pAC, IoC, Port);
1438 pAC->GIni.GP[Port].PState = SK_PRT_RESET;
1440 } /* SkMacHardRst */
1443 /******************************************************************************
1445 * SkXmInitMac() - Initialize the XMAC II
1448 * Initialize the XMAC of the specified port.
1449 * The XMAC must be reset or stopped before calling this function.
1452 * The XMAC's Rx and Tx state machine is still disabled when returning.
1458 SK_AC *pAC, /* adapter context */
1459 SK_IOC IoC, /* IO context */
1460 int Port) /* Port Index (MAC_1 + n) */
1467 pPrt = &pAC->GIni.GP[Port];
1469 if (pPrt->PState == SK_PRT_STOP) {
1470 /* Port State: SK_PRT_STOP */
1471 /* Verify that the reset bit is cleared */
1472 SK_IN16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), &SWord);
1474 if ((SWord & MFF_SET_MAC_RST) != 0) {
1475 /* PState does not match HW state */
1476 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E006, SKERR_HWI_E006MSG);
1478 pPrt->PState = SK_PRT_RESET;
1482 if (pPrt->PState == SK_PRT_RESET) {
1485 * Note: The SW reset is self clearing, therefore there is
1486 * nothing to do here.
1488 SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_CLR_MAC_RST);
1490 /* Ensure that XMAC reset release is done (errata from LReinbold?) */
1491 SK_IN16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), &SWord);
1493 /* Clear PHY reset */
1494 if (pPrt->PhyType != SK_PHY_XMAC) {
1496 SK_IN32(IoC, B2_GP_IO, &Reg);
1499 Reg |= (GP_DIR_0 | GP_IO_0); /* set to output */
1502 Reg |= (GP_DIR_2 | GP_IO_2); /* set to output */
1504 SK_OUT32(IoC, B2_GP_IO, Reg);
1506 /* Enable GMII interface */
1507 XM_OUT16(IoC, Port, XM_HW_CFG, XM_HW_GMII_MD);
1509 /* read Id from external PHY (all have the same address) */
1510 SkXmPhyRead(pAC, IoC, Port, PHY_XMAC_ID1, &pPrt->PhyId1);
1513 * Optimize MDIO transfer by suppressing preamble.
1514 * Must be done AFTER first access to BCOM chip.
1516 XM_IN16(IoC, Port, XM_MMU_CMD, &SWord);
1518 XM_OUT16(IoC, Port, XM_MMU_CMD, SWord | XM_MMU_NO_PRE);
1520 if (pPrt->PhyId1 == PHY_BCOM_ID1_C0) {
1522 * Workaround BCOM Errata for the C0 type.
1523 * Write magic patterns to reserved registers.
1526 while (BcomRegC0Hack[i].PhyReg != 0) {
1527 SkXmPhyWrite(pAC, IoC, Port, BcomRegC0Hack[i].PhyReg,
1528 BcomRegC0Hack[i].PhyVal);
1532 else if (pPrt->PhyId1 == PHY_BCOM_ID1_A1) {
1534 * Workaround BCOM Errata for the A1 type.
1535 * Write magic patterns to reserved registers.
1538 while (BcomRegA1Hack[i].PhyReg != 0) {
1539 SkXmPhyWrite(pAC, IoC, Port, BcomRegA1Hack[i].PhyReg,
1540 BcomRegA1Hack[i].PhyVal);
1546 * Workaround BCOM Errata (#10523) for all BCom PHYs.
1547 * Disable Power Management after reset.
1549 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, &SWord);
1551 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUX_CTRL,
1552 (SK_U16)(SWord | PHY_B_AC_DIS_PM));
1554 /* PHY LED initialization is done in SkGeXmitLED() */
1557 /* Dummy read the Interrupt source register */
1558 XM_IN16(IoC, Port, XM_ISRC, &SWord);
1561 * The auto-negotiation process starts immediately after
1562 * clearing the reset. The auto-negotiation process should be
1563 * started by the SIRQ, therefore stop it here immediately.
1565 SkMacInitPhy(pAC, IoC, Port, SK_FALSE);
1568 /* temp. code: enable signal detect */
1569 /* WARNING: do not override GMII setting above */
1570 XM_OUT16(pAC, Port, XM_HW_CFG, XM_HW_COM4SIG);
1575 * configure the XMACs Station Address
1576 * B2_MAC_2 = xx xx xx xx xx x1 is programmed to XMAC A
1577 * B2_MAC_3 = xx xx xx xx xx x2 is programmed to XMAC B
1579 for (i = 0; i < 3; i++) {
1581 * The following 2 statements are together endianess
1582 * independent. Remember this when changing.
1584 SK_IN16(IoC, (B2_MAC_2 + Port * 8 + i * 2), &SWord);
1586 XM_OUT16(IoC, Port, (XM_SA + i * 2), SWord);
1589 /* Tx Inter Packet Gap (XM_TX_IPG): use default */
1590 /* Tx High Water Mark (XM_TX_HI_WM): use default */
1591 /* Tx Low Water Mark (XM_TX_LO_WM): use default */
1592 /* Host Request Threshold (XM_HT_THR): use default */
1593 /* Rx Request Threshold (XM_RX_THR): use default */
1594 /* Rx Low Water Mark (XM_RX_LO_WM): use default */
1596 /* configure Rx High Water Mark (XM_RX_HI_WM) */
1597 XM_OUT16(IoC, Port, XM_RX_HI_WM, SK_XM_RX_HI_WM);
1599 /* Configure Tx Request Threshold */
1600 SWord = SK_XM_THR_SL; /* for single port */
1602 if (pAC->GIni.GIMacsFound > 1) {
1603 switch (pAC->GIni.GIPortUsage) {
1605 SWord = SK_XM_THR_REDL; /* redundant link */
1608 SWord = SK_XM_THR_MULL; /* load balancing */
1611 SWord = SK_XM_THR_JUMBO; /* jumbo frames */
1614 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E014, SKERR_HWI_E014MSG);
1618 XM_OUT16(IoC, Port, XM_TX_THR, SWord);
1620 /* setup register defaults for the Tx Command Register */
1621 XM_OUT16(IoC, Port, XM_TX_CMD, XM_TX_AUTO_PAD);
1623 /* setup register defaults for the Rx Command Register */
1624 SWord = XM_RX_STRIP_FCS | XM_RX_LENERR_OK;
1626 if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
1627 SWord |= XM_RX_BIG_PK_OK;
1630 if (pPrt->PLinkModeConf == SK_LMODE_HALF) {
1632 * If in manual half duplex mode the other side might be in
1633 * full duplex mode, so ignore if a carrier extension is not seen
1634 * on frames received
1636 SWord |= XM_RX_DIS_CEXT;
1639 XM_OUT16(IoC, Port, XM_RX_CMD, SWord);
1642 * setup register defaults for the Mode Register
1643 * - Don't strip error frames to avoid Store & Forward
1645 * - Enable 'Check Station Address' bit
1646 * - Enable 'Check Address Array' bit
1648 XM_OUT32(IoC, Port, XM_MODE, XM_DEF_MODE);
1651 * Initialize the Receive Counter Event Mask (XM_RX_EV_MSK)
1652 * - Enable all bits excepting 'Octets Rx OK Low CntOv'
1653 * and 'Octets Rx OK Hi Cnt Ov'.
1655 XM_OUT32(IoC, Port, XM_RX_EV_MSK, XMR_DEF_MSK);
1658 * Initialize the Transmit Counter Event Mask (XM_TX_EV_MSK)
1659 * - Enable all bits excepting 'Octets Tx OK Low CntOv'
1660 * and 'Octets Tx OK Hi Cnt Ov'.
1662 XM_OUT32(IoC, Port, XM_TX_EV_MSK, XMT_DEF_MSK);
1665 * Do NOT init XMAC interrupt mask here.
1666 * All interrupts remain disable until link comes up!
1670 * Any additional configuration changes may be done now.
1671 * The last action is to enable the Rx and Tx state machine.
1672 * This should be done after the auto-negotiation process
1673 * has been completed successfully.
1677 /******************************************************************************
1679 * SkGmInitMac() - Initialize the GMAC
1682 * Initialize the GMAC of the specified port.
1683 * The GMAC must be reset or stopped before calling this function.
1686 * The GMAC's Rx and Tx state machine is still disabled when returning.
1692 SK_AC *pAC, /* adapter context */
1693 SK_IOC IoC, /* IO context */
1694 int Port) /* Port Index (MAC_1 + n) */
1701 pPrt = &pAC->GIni.GP[Port];
1703 if (pPrt->PState == SK_PRT_STOP) {
1704 /* Port State: SK_PRT_STOP */
1705 /* Verify that the reset bit is cleared */
1706 SK_IN32(IoC, MR_ADDR(Port, GMAC_CTRL), &DWord);
1708 if ((DWord & GMC_RST_SET) != 0) {
1709 /* PState does not match HW state */
1710 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E006, SKERR_HWI_E006MSG);
1712 pPrt->PState = SK_PRT_RESET;
1716 if (pPrt->PState == SK_PRT_RESET) {
1717 /* set GPHY Control reset */
1718 SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), GPC_RST_SET);
1720 /* set GMAC Control reset */
1721 SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_SET);
1723 /* clear GMAC Control reset */
1724 SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_CLR);
1726 /* set GMAC Control reset */
1727 SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_RST_SET);
1729 /* set HWCFG_MODE */
1730 DWord = GPC_INT_POL_HI | GPC_DIS_FC | GPC_DIS_SLEEP |
1731 GPC_ENA_XC | GPC_ANEG_ADV_ALL_M | GPC_ENA_PAUSE |
1732 (pAC->GIni.GICopperType ? GPC_HWCFG_GMII_COP :
1733 GPC_HWCFG_GMII_FIB);
1735 /* set GPHY Control reset */
1736 SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), DWord | GPC_RST_SET);
1738 /* release GPHY Control reset */
1739 SK_OUT32(IoC, MR_ADDR(Port, GPHY_CTRL), DWord | GPC_RST_CLR);
1741 /* clear GMAC Control reset */
1742 SK_OUT32(IoC, MR_ADDR(Port, GMAC_CTRL), GMC_PAUSE_ON | GMC_RST_CLR);
1744 /* Dummy read the Interrupt source register */
1745 SK_IN16(IoC, GMAC_IRQ_SRC, &SWord);
1748 /* read Id from PHY */
1749 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_ID1, &pPrt->PhyId1);
1751 SkGmInitPhyMarv(pAC, IoC, Port, SK_FALSE);
1755 (void)SkGmResetCounter(pAC, IoC, Port);
1759 /* speed settings */
1760 switch (pPrt->PLinkSpeed) {
1761 case SK_LSPEED_AUTO:
1762 case SK_LSPEED_1000MBPS:
1763 SWord |= GM_GPCR_SPEED_1000 | GM_GPCR_SPEED_100;
1765 case SK_LSPEED_100MBPS:
1766 SWord |= GM_GPCR_SPEED_100;
1768 case SK_LSPEED_10MBPS:
1772 /* duplex settings */
1773 if (pPrt->PLinkMode != SK_LMODE_HALF) {
1774 /* set full duplex */
1775 SWord |= GM_GPCR_DUP_FULL;
1778 /* flow control settings */
1779 switch (pPrt->PFlowCtrlMode) {
1780 case SK_FLOW_MODE_NONE:
1781 /* disable auto-negotiation for flow-control */
1782 SWord |= GM_GPCR_FC_TX_DIS | GM_GPCR_FC_RX_DIS;
1784 case SK_FLOW_MODE_LOC_SEND:
1785 SWord |= GM_GPCR_FC_RX_DIS;
1787 case SK_FLOW_MODE_SYMMETRIC:
1789 case SK_FLOW_MODE_SYM_OR_REM:
1790 /* enable auto-negotiation for flow-control and */
1791 /* enable Rx and Tx of pause frames */
1795 /* Auto-negotiation ? */
1796 if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) {
1797 /* disable auto-update for speed, duplex and flow-control */
1798 SWord |= GM_GPCR_AU_ALL_DIS;
1801 /* setup General Purpose Control Register */
1802 GM_OUT16(IoC, Port, GM_GP_CTRL, SWord);
1804 /* setup Transmit Control Register */
1805 GM_OUT16(IoC, Port, GM_TX_CTRL, GM_TXCR_COL_THR);
1807 /* setup Receive Control Register */
1808 GM_OUT16(IoC, Port, GM_RX_CTRL, GM_RXCR_UCF_ENA | GM_RXCR_MCF_ENA |
1811 /* setup Transmit Flow Control Register */
1812 GM_OUT16(IoC, Port, GM_TX_FLOW_CTRL, 0xffff);
1814 /* setup Transmit Parameter Register */
1816 GM_IN16(IoC, Port, GM_TX_PARAM, &SWord);
1819 SWord = JAM_LEN_VAL(3) | JAM_IPG_VAL(11) | IPG_JAM_DATA(26);
1821 GM_OUT16(IoC, Port, GM_TX_PARAM, SWord);
1823 /* configure the Serial Mode Register */
1825 GM_IN16(IoC, Port, GM_SERIAL_MODE, &SWord);
1828 SWord = GM_SMOD_VLAN_ENA | IPG_VAL_FAST_ETH;
1830 if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
1831 /* enable jumbo mode (Max. Frame Length = 9018) */
1832 SWord |= GM_SMOD_JUMBO_ENA;
1835 GM_OUT16(IoC, Port, GM_SERIAL_MODE, SWord);
1838 * configure the GMACs Station Addresses
1839 * in PROM you can find our addresses at:
1840 * B2_MAC_1 = xx xx xx xx xx x0 virtual address
1841 * B2_MAC_2 = xx xx xx xx xx x1 is programmed to GMAC A
1842 * B2_MAC_3 = xx xx xx xx xx x2 is reserved for DualPort
1845 for (i = 0; i < 3; i++) {
1847 * The following 2 statements are together endianess
1848 * independent. Remember this when changing.
1850 /* physical address: will be used for pause frames */
1851 SK_IN16(IoC, (B2_MAC_2 + Port * 8 + i * 2), &SWord);
1854 /* WA for deviation #16 */
1855 if (pAC->GIni.GIChipRev == 0) {
1856 /* swap the address bytes */
1857 SWord = ((SWord & 0xff00) >> 8) | ((SWord & 0x00ff) << 8);
1859 /* write to register in reversed order */
1860 GM_OUT16(IoC, Port, (GM_SRC_ADDR_1L + (2 - i) * 4), SWord);
1863 GM_OUT16(IoC, Port, (GM_SRC_ADDR_1L + i * 4), SWord);
1866 GM_OUT16(IoC, Port, (GM_SRC_ADDR_1L + i * 4), SWord);
1867 #endif /* WA_DEV_16 */
1869 /* virtual address: will be used for data */
1870 SK_IN16(IoC, (B2_MAC_1 + Port * 8 + i * 2), &SWord);
1872 GM_OUT16(IoC, Port, (GM_SRC_ADDR_2L + i * 4), SWord);
1874 /* reset Multicast filtering Hash registers 1-3 */
1875 GM_OUT16(IoC, Port, GM_MC_ADDR_H1 + 4*i, 0);
1878 /* reset Multicast filtering Hash register 4 */
1879 GM_OUT16(IoC, Port, GM_MC_ADDR_H4, 0);
1881 /* enable interrupt mask for counter overflows */
1882 GM_OUT16(IoC, Port, GM_TX_IRQ_MSK, 0);
1883 GM_OUT16(IoC, Port, GM_RX_IRQ_MSK, 0);
1884 GM_OUT16(IoC, Port, GM_TR_IRQ_MSK, 0);
1886 /* read General Purpose Status */
1887 GM_IN16(IoC, Port, GM_GP_STAT, &SWord);
1889 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
1890 ("MAC Stat Reg=0x%04X\n", SWord));
1893 c_print("MAC Stat Reg=0x%04X\n", SWord);
1894 #endif /* SK_DIAG */
1899 /******************************************************************************
1901 * SkXmInitDupMd() - Initialize the XMACs Duplex Mode
1904 * This function initializes the XMACs Duplex Mode.
1905 * It should be called after successfully finishing
1906 * the Auto-negotiation Process
1912 SK_AC *pAC, /* adapter context */
1913 SK_IOC IoC, /* IO context */
1914 int Port) /* Port Index (MAC_1 + n) */
1916 switch (pAC->GIni.GP[Port].PLinkModeStatus) {
1917 case SK_LMODE_STAT_AUTOHALF:
1918 case SK_LMODE_STAT_HALF:
1919 /* Configuration Actions for Half Duplex Mode */
1921 * XM_BURST = default value. We are probable not quick
1922 * enough at the 'XMAC' bus to burst 8kB.
1923 * The XMAC stops bursting if no transmit frames
1924 * are available or the burst limit is exceeded.
1926 /* XM_TX_RT_LIM = default value (15) */
1927 /* XM_TX_STIME = default value (0xff = 4096 bit times) */
1929 case SK_LMODE_STAT_AUTOFULL:
1930 case SK_LMODE_STAT_FULL:
1931 /* Configuration Actions for Full Duplex Mode */
1933 * The duplex mode is configured by the PHY,
1934 * therefore it seems to be that there is nothing
1938 case SK_LMODE_STAT_UNKNOWN:
1940 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E007, SKERR_HWI_E007MSG);
1943 } /* SkXmInitDupMd */
1946 /******************************************************************************
1948 * SkXmInitPauseMd() - initialize the Pause Mode to be used for this port
1951 * This function initializes the Pause Mode which should
1952 * be used for this port.
1953 * It should be called after successfully finishing
1954 * the Auto-negotiation Process
1959 void SkXmInitPauseMd(
1960 SK_AC *pAC, /* adapter context */
1961 SK_IOC IoC, /* IO context */
1962 int Port) /* Port Index (MAC_1 + n) */
1968 pPrt = &pAC->GIni.GP[Port];
1970 XM_IN16(IoC, Port, XM_MMU_CMD, &Word);
1972 if (pPrt->PFlowCtrlStatus == SK_FLOW_STAT_NONE ||
1973 pPrt->PFlowCtrlStatus == SK_FLOW_STAT_LOC_SEND) {
1975 /* Disable Pause Frame Reception */
1976 Word |= XM_MMU_IGN_PF;
1980 * enabling pause frame reception is required for 1000BT
1981 * because the XMAC is not reset if the link is going down
1983 /* Enable Pause Frame Reception */
1984 Word &= ~XM_MMU_IGN_PF;
1987 XM_OUT16(IoC, Port, XM_MMU_CMD, Word);
1989 XM_IN32(IoC, Port, XM_MODE, &DWord);
1991 if (pPrt->PFlowCtrlStatus == SK_FLOW_STAT_SYMMETRIC ||
1992 pPrt->PFlowCtrlStatus == SK_FLOW_STAT_LOC_SEND) {
1995 * Configure Pause Frame Generation
1996 * Use internal and external Pause Frame Generation.
1997 * Sending pause frames is edge triggered.
1998 * Send a Pause frame with the maximum pause time if
1999 * internal oder external FIFO full condition occurs.
2000 * Send a zero pause time frame to re-start transmission.
2003 /* XM_PAUSE_DA = '010000C28001' (default) */
2005 /* XM_MAC_PTIME = 0xffff (maximum) */
2006 /* remember this value is defined in big endian (!) */
2007 XM_OUT16(IoC, Port, XM_MAC_PTIME, 0xffff);
2009 /* Set Pause Mode in Mode Register */
2010 DWord |= XM_PAUSE_MODE;
2012 /* Set Pause Mode in MAC Rx FIFO */
2013 SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_ENA_PAUSE);
2017 * disable pause frame generation is required for 1000BT
2018 * because the XMAC is not reset if the link is going down
2020 /* Disable Pause Mode in Mode Register */
2021 DWord &= ~XM_PAUSE_MODE;
2023 /* Disable Pause Mode in MAC Rx FIFO */
2024 SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_DIS_PAUSE);
2027 XM_OUT32(IoC, Port, XM_MODE, DWord);
2028 } /* SkXmInitPauseMd*/
2031 /******************************************************************************
2033 * SkXmInitPhyXmac() - Initialize the XMAC Phy registers
2035 * Description: initializes all the XMACs Phy registers
2042 static void SkXmInitPhyXmac(
2043 SK_AC *pAC, /* adapter context */
2044 SK_IOC IoC, /* IO context */
2045 int Port, /* Port Index (MAC_1 + n) */
2046 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2051 pPrt = &pAC->GIni.GP[Port];
2054 /* Auto-negotiation ? */
2055 if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) {
2056 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2057 ("InitPhyXmac: no auto-negotiation Port %d\n", Port));
2058 /* Set DuplexMode in Config register */
2059 if (pPrt->PLinkMode == SK_LMODE_FULL) {
2060 Ctrl |= PHY_CT_DUP_MD;
2064 * Do NOT enable Auto-negotiation here. This would hold
2065 * the link down because no IDLEs are transmitted
2069 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2070 ("InitPhyXmac: with auto-negotiation Port %d\n", Port));
2071 /* Set Auto-negotiation advertisement */
2073 /* Set Full/half duplex capabilities */
2074 switch (pPrt->PLinkMode) {
2075 case SK_LMODE_AUTOHALF:
2076 Ctrl |= PHY_X_AN_HD;
2078 case SK_LMODE_AUTOFULL:
2079 Ctrl |= PHY_X_AN_FD;
2081 case SK_LMODE_AUTOBOTH:
2082 Ctrl |= PHY_X_AN_FD | PHY_X_AN_HD;
2085 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E015,
2089 switch (pPrt->PFlowCtrlMode) {
2090 case SK_FLOW_MODE_NONE:
2091 Ctrl |= PHY_X_P_NO_PAUSE;
2093 case SK_FLOW_MODE_LOC_SEND:
2094 Ctrl |= PHY_X_P_ASYM_MD;
2096 case SK_FLOW_MODE_SYMMETRIC:
2097 Ctrl |= PHY_X_P_SYM_MD;
2099 case SK_FLOW_MODE_SYM_OR_REM:
2100 Ctrl |= PHY_X_P_BOTH_MD;
2103 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
2107 /* Write AutoNeg Advertisement Register */
2108 SkXmPhyWrite(pAC, IoC, Port, PHY_XMAC_AUNE_ADV, Ctrl);
2110 /* Restart Auto-negotiation */
2111 Ctrl = PHY_CT_ANE | PHY_CT_RE_CFG;
2115 /* Set the Phy Loopback bit, too */
2116 Ctrl |= PHY_CT_LOOP;
2119 /* Write to the Phy control register */
2120 SkXmPhyWrite(pAC, IoC, Port, PHY_XMAC_CTRL, Ctrl);
2121 } /* SkXmInitPhyXmac */
2124 /******************************************************************************
2126 * SkXmInitPhyBcom() - Initialize the Broadcom Phy registers
2128 * Description: initializes all the Broadcom Phy registers
2135 static void SkXmInitPhyBcom(
2136 SK_AC *pAC, /* adapter context */
2137 SK_IOC IoC, /* IO context */
2138 int Port, /* Port Index (MAC_1 + n) */
2139 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2148 Ctrl1 = PHY_CT_SP1000;
2150 Ctrl3 = PHY_SEL_TYPE;
2151 Ctrl4 = PHY_B_PEC_EN_LTR;
2152 Ctrl5 = PHY_B_AC_TX_TST;
2154 pPrt = &pAC->GIni.GP[Port];
2156 /* manually Master/Slave ? */
2157 if (pPrt->PMSMode != SK_MS_MODE_AUTO) {
2158 Ctrl2 |= PHY_B_1000C_MSE;
2160 if (pPrt->PMSMode == SK_MS_MODE_MASTER) {
2161 Ctrl2 |= PHY_B_1000C_MSC;
2164 /* Auto-negotiation ? */
2165 if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) {
2166 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2167 ("InitPhyBcom: no auto-negotiation Port %d\n", Port));
2168 /* Set DuplexMode in Config register */
2169 Ctrl1 |= (pPrt->PLinkMode == SK_LMODE_FULL ? PHY_CT_DUP_MD : 0);
2171 /* Determine Master/Slave manually if not already done */
2172 if (pPrt->PMSMode == SK_MS_MODE_AUTO) {
2173 Ctrl2 |= PHY_B_1000C_MSE; /* set it to Slave */
2177 * Do NOT enable Auto-negotiation here. This would hold
2178 * the link down because no IDLES are transmitted
2182 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2183 ("InitPhyBcom: with auto-negotiation Port %d\n", Port));
2184 /* Set Auto-negotiation advertisement */
2187 * Workaround BCOM Errata #1 for the C5 type.
2188 * 1000Base-T Link Acquisition Failure in Slave Mode
2189 * Set Repeater/DTE bit 10 of the 1000Base-T Control Register
2191 Ctrl2 |= PHY_B_1000C_RD;
2193 /* Set Full/half duplex capabilities */
2194 switch (pPrt->PLinkMode) {
2195 case SK_LMODE_AUTOHALF:
2196 Ctrl2 |= PHY_B_1000C_AHD;
2198 case SK_LMODE_AUTOFULL:
2199 Ctrl2 |= PHY_B_1000C_AFD;
2201 case SK_LMODE_AUTOBOTH:
2202 Ctrl2 |= PHY_B_1000C_AFD | PHY_B_1000C_AHD;
2205 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E015,
2209 switch (pPrt->PFlowCtrlMode) {
2210 case SK_FLOW_MODE_NONE:
2211 Ctrl3 |= PHY_B_P_NO_PAUSE;
2213 case SK_FLOW_MODE_LOC_SEND:
2214 Ctrl3 |= PHY_B_P_ASYM_MD;
2216 case SK_FLOW_MODE_SYMMETRIC:
2217 Ctrl3 |= PHY_B_P_SYM_MD;
2219 case SK_FLOW_MODE_SYM_OR_REM:
2220 Ctrl3 |= PHY_B_P_BOTH_MD;
2223 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
2227 /* Restart Auto-negotiation */
2228 Ctrl1 |= PHY_CT_ANE | PHY_CT_RE_CFG;
2231 /* Initialize LED register here? */
2232 /* No. Please do it in SkDgXmitLed() (if required) and swap
2233 init order of LEDs and XMAC. (MAl) */
2235 /* Write 1000Base-T Control Register */
2236 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_1000T_CTRL, Ctrl2);
2237 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2238 ("1000B-T Ctrl Reg=0x%04X\n", Ctrl2));
2240 /* Write AutoNeg Advertisement Register */
2241 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUNE_ADV, Ctrl3);
2242 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2243 ("Auto-Neg. Adv. Reg=0x%04X\n", Ctrl3));
2246 /* Set the Phy Loopback bit, too */
2247 Ctrl1 |= PHY_CT_LOOP;
2250 if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
2251 /* configure FIFO to high latency for transmission of ext. packets */
2252 Ctrl4 |= PHY_B_PEC_HIGH_LA;
2254 /* configure reception of extended packets */
2255 Ctrl5 |= PHY_B_AC_LONG_PACK;
2257 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, Ctrl5);
2260 /* Configure LED Traffic Mode and Jumbo Frame usage if specified */
2261 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_P_EXT_CTRL, Ctrl4);
2263 /* Write to the Phy control register */
2264 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_CTRL, Ctrl1);
2265 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2266 ("PHY Control Reg=0x%04X\n", Ctrl1));
2267 } /* SkXmInitPhyBcom */
2270 /******************************************************************************
2272 * SkGmInitPhyMarv() - Initialize the Marvell Phy registers
2274 * Description: initializes all the Marvell Phy registers
2281 static void SkGmInitPhyMarv(
2282 SK_AC *pAC, /* adapter context */
2283 SK_IOC IoC, /* IO context */
2284 int Port, /* Port Index (MAC_1 + n) */
2285 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2299 VCPUprintf(0, "SkGmInitPhyMarv(), Port=%u, DoLoop=%u\n",
2303 pPrt = &pAC->GIni.GP[Port];
2305 /* Auto-negotiation ? */
2306 if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) {
2314 /* Read Ext. PHY Specific Control */
2315 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_EXT_CTRL, &ExtPhyCtrl);
2317 ExtPhyCtrl &= ~(PHY_M_EC_M_DSC_MSK | PHY_M_EC_S_DSC_MSK |
2318 PHY_M_EC_MAC_S_MSK);
2320 ExtPhyCtrl |= PHY_M_EC_M_DSC(1) | PHY_M_EC_S_DSC(1) |
2321 PHY_M_EC_MAC_S(MAC_TX_CLK_25_MHZ);
2323 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_EXT_CTRL, ExtPhyCtrl);
2324 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2325 ("Ext.PHYCtrl=0x%04X\n", ExtPhyCtrl));
2327 /* Read PHY Control */
2328 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_CTRL, &PhyCtrl);
2330 /* Assert software reset */
2331 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_CTRL,
2332 (SK_U16)(PhyCtrl | PHY_CT_RESET));
2336 PhyCtrl = 0 /* PHY_CT_COL_TST */;
2338 AutoNegAdv = PHY_SEL_TYPE;
2340 /* manually Master/Slave ? */
2341 if (pPrt->PMSMode != SK_MS_MODE_AUTO) {
2342 /* enable Manual Master/Slave */
2343 C1000BaseT |= PHY_M_1000C_MSE;
2345 if (pPrt->PMSMode == SK_MS_MODE_MASTER) {
2346 C1000BaseT |= PHY_M_1000C_MSC; /* set it to Master */
2350 /* Auto-negotiation ? */
2352 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2353 ("InitPhyMarv: no auto-negotiation Port %d\n", Port));
2355 if (pPrt->PLinkMode == SK_LMODE_FULL) {
2356 /* Set Full Duplex Mode */
2357 PhyCtrl |= PHY_CT_DUP_MD;
2360 /* Set Master/Slave manually if not already done */
2361 if (pPrt->PMSMode == SK_MS_MODE_AUTO) {
2362 C1000BaseT |= PHY_M_1000C_MSE; /* set it to Slave */
2366 switch (pPrt->PLinkSpeed) {
2367 case SK_LSPEED_AUTO:
2368 case SK_LSPEED_1000MBPS:
2369 PhyCtrl |= PHY_CT_SP1000;
2371 case SK_LSPEED_100MBPS:
2372 PhyCtrl |= PHY_CT_SP100;
2374 case SK_LSPEED_10MBPS:
2377 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E019,
2382 PhyCtrl |= PHY_CT_RESET;
2385 * Do NOT enable Auto-negotiation here. This would hold
2386 * the link down because no IDLES are transmitted
2390 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2391 ("InitPhyMarv: with auto-negotiation Port %d\n", Port));
2393 PhyCtrl |= PHY_CT_ANE;
2395 if (pAC->GIni.GICopperType) {
2396 /* Set Speed capabilities */
2397 switch (pPrt->PLinkSpeed) {
2398 case SK_LSPEED_AUTO:
2399 C1000BaseT |= PHY_M_1000C_AHD | PHY_M_1000C_AFD;
2400 AutoNegAdv |= PHY_M_AN_100_FD | PHY_M_AN_100_HD |
2401 PHY_M_AN_10_FD | PHY_M_AN_10_HD;
2403 case SK_LSPEED_1000MBPS:
2404 C1000BaseT |= PHY_M_1000C_AHD | PHY_M_1000C_AFD;
2406 case SK_LSPEED_100MBPS:
2407 AutoNegAdv |= PHY_M_AN_100_FD | PHY_M_AN_100_HD |
2408 PHY_M_AN_10_FD | PHY_M_AN_10_HD;
2410 case SK_LSPEED_10MBPS:
2411 AutoNegAdv |= PHY_M_AN_10_FD | PHY_M_AN_10_HD;
2414 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E019,
2418 /* Set Full/half duplex capabilities */
2419 switch (pPrt->PLinkMode) {
2420 case SK_LMODE_AUTOHALF:
2421 C1000BaseT &= ~PHY_M_1000C_AFD;
2422 AutoNegAdv &= ~(PHY_M_AN_100_FD | PHY_M_AN_10_FD);
2424 case SK_LMODE_AUTOFULL:
2425 C1000BaseT &= ~PHY_M_1000C_AHD;
2426 AutoNegAdv &= ~(PHY_M_AN_100_HD | PHY_M_AN_10_HD);
2428 case SK_LMODE_AUTOBOTH:
2431 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E015,
2435 /* Set Auto-negotiation advertisement */
2436 switch (pPrt->PFlowCtrlMode) {
2437 case SK_FLOW_MODE_NONE:
2438 AutoNegAdv |= PHY_B_P_NO_PAUSE;
2440 case SK_FLOW_MODE_LOC_SEND:
2441 AutoNegAdv |= PHY_B_P_ASYM_MD;
2443 case SK_FLOW_MODE_SYMMETRIC:
2444 AutoNegAdv |= PHY_B_P_SYM_MD;
2446 case SK_FLOW_MODE_SYM_OR_REM:
2447 AutoNegAdv |= PHY_B_P_BOTH_MD;
2450 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
2454 else { /* special defines for FIBER (88E1011S only) */
2456 /* Set Full/half duplex capabilities */
2457 switch (pPrt->PLinkMode) {
2458 case SK_LMODE_AUTOHALF:
2459 AutoNegAdv |= PHY_M_AN_1000X_AHD;
2461 case SK_LMODE_AUTOFULL:
2462 AutoNegAdv |= PHY_M_AN_1000X_AFD;
2464 case SK_LMODE_AUTOBOTH:
2465 AutoNegAdv |= PHY_M_AN_1000X_AHD | PHY_M_AN_1000X_AFD;
2468 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E015,
2472 /* Set Auto-negotiation advertisement */
2473 switch (pPrt->PFlowCtrlMode) {
2474 case SK_FLOW_MODE_NONE:
2475 AutoNegAdv |= PHY_M_P_NO_PAUSE_X;
2477 case SK_FLOW_MODE_LOC_SEND:
2478 AutoNegAdv |= PHY_M_P_ASYM_MD_X;
2480 case SK_FLOW_MODE_SYMMETRIC:
2481 AutoNegAdv |= PHY_M_P_SYM_MD_X;
2483 case SK_FLOW_MODE_SYM_OR_REM:
2484 AutoNegAdv |= PHY_M_P_BOTH_MD_X;
2487 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
2493 /* Restart Auto-negotiation */
2494 PhyCtrl |= PHY_CT_RE_CFG;
2500 * E-mail from Gu Lin (08-03-2002):
2503 /* Program PHY register 30 as 16'h0708 for simulation speed up */
2504 SkGmPhyWrite(pAC, IoC, Port, 30, 0x0708);
2510 /* Write 1000Base-T Control Register */
2511 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_1000T_CTRL, C1000BaseT);
2512 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2513 ("1000B-T Ctrl=0x%04X\n", C1000BaseT));
2515 /* Write AutoNeg Advertisement Register */
2516 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_AUNE_ADV, AutoNegAdv);
2517 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2518 ("Auto-Neg.Ad.=0x%04X\n", AutoNegAdv));
2522 /* Set the PHY Loopback bit */
2523 PhyCtrl |= PHY_CT_LOOP;
2525 /* Program PHY register 16 as 16'h0400 to force link good */
2526 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_PHY_CTRL, PHY_M_PC_FL_GOOD);
2529 if (pPrt->PLinkSpeed != SK_LSPEED_AUTO) {
2530 /* Write Ext. PHY Specific Control */
2531 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_EXT_CTRL,
2532 (SK_U16)((pPrt->PLinkSpeed + 2) << 4));
2535 else if (pPrt->PLinkSpeed == SK_LSPEED_10MBPS) {
2536 /* Write PHY Specific Control */
2537 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_PHY_CTRL, PHY_M_PC_EN_DET_MSK);
2542 /* Write to the PHY Control register */
2543 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_CTRL, PhyCtrl);
2549 LedCtrl = PHY_M_LED_PULS_DUR(PULS_170MS) | PHY_M_LED_BLINK_RT(BLINK_84MS);
2551 #ifdef ACT_LED_BLINK
2552 LedCtrl |= PHY_M_LEDC_RX_CTRL | PHY_M_LEDC_TX_CTRL;
2553 #endif /* ACT_LED_BLINK */
2555 #ifdef DUP_LED_NORMAL
2556 LedCtrl |= PHY_M_LEDC_DP_CTRL;
2557 #endif /* DUP_LED_NORMAL */
2559 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_LED_CTRL, LedCtrl);
2564 c_print("Set PHY Ctrl=0x%04X\n", PhyCtrl);
2565 c_print("Set 1000 B-T=0x%04X\n", C1000BaseT);
2566 c_print("Set Auto-Neg=0x%04X\n", AutoNegAdv);
2567 c_print("Set Ext Ctrl=0x%04X\n", ExtPhyCtrl);
2568 #endif /* SK_DIAG */
2571 /* Read PHY Control */
2572 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_CTRL, &PhyCtrl);
2573 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2574 ("PHY Ctrl Reg.=0x%04X\n", PhyCtrl));
2576 /* Read 1000Base-T Control Register */
2577 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_1000T_CTRL, &C1000BaseT);
2578 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2579 ("1000B-T Ctrl =0x%04X\n", C1000BaseT));
2581 /* Read AutoNeg Advertisement Register */
2582 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_AUNE_ADV, &AutoNegAdv);
2583 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2584 ("Auto-Neg. Ad.=0x%04X\n", AutoNegAdv));
2586 /* Read Ext. PHY Specific Control */
2587 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_EXT_CTRL, &ExtPhyCtrl);
2588 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2589 ("Ext PHY Ctrl=0x%04X\n", ExtPhyCtrl));
2591 /* Read PHY Status */
2592 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_STAT, &PhyStat);
2593 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2594 ("PHY Stat Reg.=0x%04X\n", PhyStat));
2595 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_STAT, &PhyStat1);
2596 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2597 ("PHY Stat Reg.=0x%04X\n", PhyStat1));
2599 /* Read PHY Specific Status */
2600 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_PHY_STAT, &PhySpecStat);
2601 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2602 ("PHY Spec Stat=0x%04X\n", PhySpecStat));
2606 c_print("PHY Ctrl Reg=0x%04X\n", PhyCtrl);
2607 c_print("PHY 1000 Reg=0x%04X\n", C1000BaseT);
2608 c_print("PHY AnAd Reg=0x%04X\n", AutoNegAdv);
2609 c_print("Ext Ctrl Reg=0x%04X\n", ExtPhyCtrl);
2610 c_print("PHY Stat Reg=0x%04X\n", PhyStat);
2611 c_print("PHY Stat Reg=0x%04X\n", PhyStat1);
2612 c_print("PHY Spec Reg=0x%04X\n", PhySpecStat);
2613 #endif /* SK_DIAG */
2615 } /* SkGmInitPhyMarv */
2619 /******************************************************************************
2621 * SkXmInitPhyLone() - Initialize the Level One Phy registers
2623 * Description: initializes all the Level One Phy registers
2630 static void SkXmInitPhyLone(
2631 SK_AC *pAC, /* adapter context */
2632 SK_IOC IoC, /* IO context */
2633 int Port, /* Port Index (MAC_1 + n) */
2634 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2641 Ctrl1 = PHY_CT_SP1000;
2643 Ctrl3 = PHY_SEL_TYPE;
2645 pPrt = &pAC->GIni.GP[Port];
2647 /* manually Master/Slave ? */
2648 if (pPrt->PMSMode != SK_MS_MODE_AUTO) {
2649 Ctrl2 |= PHY_L_1000C_MSE;
2651 if (pPrt->PMSMode == SK_MS_MODE_MASTER) {
2652 Ctrl2 |= PHY_L_1000C_MSC;
2655 /* Auto-negotiation ? */
2656 if (pPrt->PLinkMode == SK_LMODE_HALF || pPrt->PLinkMode == SK_LMODE_FULL) {
2658 * level one spec say: "1000Mbps: manual mode not allowed"
2659 * but lets see what happens...
2661 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2662 ("InitPhyLone: no auto-negotiation Port %d\n", Port));
2663 /* Set DuplexMode in Config register */
2664 Ctrl1 = (pPrt->PLinkMode == SK_LMODE_FULL ? PHY_CT_DUP_MD : 0);
2666 /* Determine Master/Slave manually if not already done */
2667 if (pPrt->PMSMode == SK_MS_MODE_AUTO) {
2668 Ctrl2 |= PHY_L_1000C_MSE; /* set it to Slave */
2672 * Do NOT enable Auto-negotiation here. This would hold
2673 * the link down because no IDLES are transmitted
2677 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2678 ("InitPhyLone: with auto-negotiation Port %d\n", Port));
2679 /* Set Auto-negotiation advertisement */
2681 /* Set Full/half duplex capabilities */
2682 switch (pPrt->PLinkMode) {
2683 case SK_LMODE_AUTOHALF:
2684 Ctrl2 |= PHY_L_1000C_AHD;
2686 case SK_LMODE_AUTOFULL:
2687 Ctrl2 |= PHY_L_1000C_AFD;
2689 case SK_LMODE_AUTOBOTH:
2690 Ctrl2 |= PHY_L_1000C_AFD | PHY_L_1000C_AHD;
2693 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E015,
2697 switch (pPrt->PFlowCtrlMode) {
2698 case SK_FLOW_MODE_NONE:
2699 Ctrl3 |= PHY_L_P_NO_PAUSE;
2701 case SK_FLOW_MODE_LOC_SEND:
2702 Ctrl3 |= PHY_L_P_ASYM_MD;
2704 case SK_FLOW_MODE_SYMMETRIC:
2705 Ctrl3 |= PHY_L_P_SYM_MD;
2707 case SK_FLOW_MODE_SYM_OR_REM:
2708 Ctrl3 |= PHY_L_P_BOTH_MD;
2711 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
2715 /* Restart Auto-negotiation */
2716 Ctrl1 = PHY_CT_ANE | PHY_CT_RE_CFG;
2720 /* Initialize LED register here ? */
2721 /* No. Please do it in SkDgXmitLed() (if required) and swap
2722 init order of LEDs and XMAC. (MAl) */
2724 /* Write 1000Base-T Control Register */
2725 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_1000T_CTRL, Ctrl2);
2726 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2727 ("1000B-T Ctrl Reg=0x%04X\n", Ctrl2));
2729 /* Write AutoNeg Advertisement Register */
2730 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_AUNE_ADV, Ctrl3);
2731 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2732 ("Auto-Neg. Adv. Reg=0x%04X\n", Ctrl3));
2736 /* Set the Phy Loopback bit, too */
2737 Ctrl1 |= PHY_CT_LOOP;
2740 /* Write to the Phy control register */
2741 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_CTRL, Ctrl1);
2742 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2743 ("PHY Control Reg=0x%04X\n", Ctrl1));
2744 } /* SkXmInitPhyLone */
2747 /******************************************************************************
2749 * SkXmInitPhyNat() - Initialize the National Phy registers
2751 * Description: initializes all the National Phy registers
2758 static void SkXmInitPhyNat(
2759 SK_AC *pAC, /* adapter context */
2760 SK_IOC IoC, /* IO context */
2761 int Port, /* Port Index (MAC_1 + n) */
2762 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2764 /* todo: National */
2765 } /* SkXmInitPhyNat */
2766 #endif /* OTHER_PHY */
2769 /******************************************************************************
2771 * SkMacInitPhy() - Initialize the PHY registers
2773 * Description: calls the Init PHY routines dep. on board type
2781 SK_AC *pAC, /* adapter context */
2782 SK_IOC IoC, /* IO context */
2783 int Port, /* Port Index (MAC_1 + n) */
2784 SK_BOOL DoLoop) /* Should a Phy LoopBack be set-up? */
2788 pPrt = &pAC->GIni.GP[Port];
2790 switch (pPrt->PhyType) {
2792 SkXmInitPhyXmac(pAC, IoC, Port, DoLoop);
2795 SkXmInitPhyBcom(pAC, IoC, Port, DoLoop);
2797 case SK_PHY_MARV_COPPER:
2798 case SK_PHY_MARV_FIBER:
2799 SkGmInitPhyMarv(pAC, IoC, Port, DoLoop);
2803 SkXmInitPhyLone(pAC, IoC, Port, DoLoop);
2806 SkXmInitPhyNat(pAC, IoC, Port, DoLoop);
2808 #endif /* OTHER_PHY */
2810 } /* SkMacInitPhy */
2814 /******************************************************************************
2816 * SkXmAutoNegLipaXmac() - Decides whether Link Partner could do auto-neg
2818 * This function analyses the Interrupt status word. If any of the
2819 * Auto-negotiating interrupt bits are set, the PLipaAutoNeg variable
2822 void SkXmAutoNegLipaXmac(
2823 SK_AC *pAC, /* adapter context */
2824 SK_IOC IoC, /* IO context */
2825 int Port, /* Port Index (MAC_1 + n) */
2826 SK_U16 IStatus) /* Interrupt Status word to analyse */
2830 pPrt = &pAC->GIni.GP[Port];
2832 if (pPrt->PLipaAutoNeg != SK_LIPA_AUTO &&
2833 (IStatus & (XM_IS_LIPA_RC | XM_IS_RX_PAGE | XM_IS_AND)) != 0) {
2835 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2836 ("AutoNegLipa: AutoNeg detected on Port %d, IStatus=0x%04x\n",
2838 pPrt->PLipaAutoNeg = SK_LIPA_AUTO;
2840 } /* SkXmAutoNegLipaXmac */
2843 /******************************************************************************
2845 * SkMacAutoNegLipaPhy() - Decides whether Link Partner could do auto-neg
2847 * This function analyses the PHY status word.
2848 * If any of the Auto-negotiating bits are set, the PLipaAutoNeg variable
2851 void SkMacAutoNegLipaPhy(
2852 SK_AC *pAC, /* adapter context */
2853 SK_IOC IoC, /* IO context */
2854 int Port, /* Port Index (MAC_1 + n) */
2855 SK_U16 PhyStat) /* PHY Status word to analyse */
2859 pPrt = &pAC->GIni.GP[Port];
2861 if (pPrt->PLipaAutoNeg != SK_LIPA_AUTO &&
2862 (PhyStat & PHY_ST_AN_OVER) != 0) {
2864 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2865 ("AutoNegLipa: AutoNeg detected on Port %d, PhyStat=0x%04x\n",
2867 pPrt->PLipaAutoNeg = SK_LIPA_AUTO;
2869 } /* SkMacAutoNegLipaPhy */
2870 #endif /* SK_DIAG */
2873 /******************************************************************************
2875 * SkXmAutoNegDoneXmac() - Auto-negotiation handling
2878 * This function handles the auto-negotiation if the Done bit is set.
2882 * SK_AND_DUP_CAP Duplex capability error happened
2883 * SK_AND_OTHER Other error happened
2885 static int SkXmAutoNegDoneXmac(
2886 SK_AC *pAC, /* adapter context */
2887 SK_IOC IoC, /* IO context */
2888 int Port) /* Port Index (MAC_1 + n) */
2891 SK_U16 ResAb; /* Resolved Ability */
2892 SK_U16 LPAb; /* Link Partner Ability */
2894 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2895 ("AutoNegDoneXmac, Port %d\n",Port));
2897 pPrt = &pAC->GIni.GP[Port];
2899 /* Get PHY parameters */
2900 SkXmPhyRead(pAC, IoC, Port, PHY_XMAC_AUNE_LP, &LPAb);
2901 SkXmPhyRead(pAC, IoC, Port, PHY_XMAC_RES_ABI, &ResAb);
2903 if ((LPAb & PHY_X_AN_RFB) != 0) {
2904 /* At least one of the remote fault bit is set */
2906 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2907 ("AutoNegFail: Remote fault bit set Port %d\n", Port));
2908 pPrt->PAutoNegFail = SK_TRUE;
2909 return(SK_AND_OTHER);
2912 /* Check Duplex mismatch */
2913 if ((ResAb & (PHY_X_RS_HD | PHY_X_RS_FD)) == PHY_X_RS_FD) {
2914 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOFULL;
2916 else if ((ResAb & (PHY_X_RS_HD | PHY_X_RS_FD)) == PHY_X_RS_HD) {
2917 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOHALF;
2921 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2922 ("AutoNegFail: Duplex mode mismatch Port %d\n", Port));
2923 pPrt->PAutoNegFail = SK_TRUE;
2924 return(SK_AND_DUP_CAP);
2927 /* Check PAUSE mismatch */
2928 /* We are NOT using chapter 4.23 of the Xaqti manual */
2929 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
2930 if ((pPrt->PFlowCtrlMode == SK_FLOW_MODE_SYMMETRIC ||
2931 pPrt->PFlowCtrlMode == SK_FLOW_MODE_SYM_OR_REM) &&
2932 (LPAb & PHY_X_P_SYM_MD) != 0) {
2933 /* Symmetric PAUSE */
2934 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_SYMMETRIC;
2936 else if (pPrt->PFlowCtrlMode == SK_FLOW_MODE_SYM_OR_REM &&
2937 (LPAb & PHY_X_RS_PAUSE) == PHY_X_P_ASYM_MD) {
2938 /* Enable PAUSE receive, disable PAUSE transmit */
2939 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_REM_SEND;
2941 else if (pPrt->PFlowCtrlMode == SK_FLOW_MODE_LOC_SEND &&
2942 (LPAb & PHY_X_RS_PAUSE) == PHY_X_P_BOTH_MD) {
2943 /* Disable PAUSE receive, enable PAUSE transmit */
2944 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_LOC_SEND;
2947 /* PAUSE mismatch -> no PAUSE */
2948 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
2950 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_1000MBPS;
2953 } /* SkXmAutoNegDoneXmac */
2956 /******************************************************************************
2958 * SkXmAutoNegDoneBcom() - Auto-negotiation handling
2961 * This function handles the auto-negotiation if the Done bit is set.
2965 * SK_AND_DUP_CAP Duplex capability error happened
2966 * SK_AND_OTHER Other error happened
2968 static int SkXmAutoNegDoneBcom(
2969 SK_AC *pAC, /* adapter context */
2970 SK_IOC IoC, /* IO context */
2971 int Port) /* Port Index (MAC_1 + n) */
2974 SK_U16 LPAb; /* Link Partner Ability */
2975 SK_U16 AuxStat; /* Auxiliary Status */
2979 SK_U16 ResAb; /* Resolved Ability */
2982 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2983 ("AutoNegDoneBcom, Port %d\n", Port));
2984 pPrt = &pAC->GIni.GP[Port];
2986 /* Get PHY parameters */
2987 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUNE_LP, &LPAb);
2990 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_1000T_STAT, &ResAb);
2993 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUX_STAT, &AuxStat);
2995 if ((LPAb & PHY_B_AN_RF) != 0) {
2996 /* Remote fault bit is set: Error */
2997 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
2998 ("AutoNegFail: Remote fault bit set Port %d\n", Port));
2999 pPrt->PAutoNegFail = SK_TRUE;
3000 return(SK_AND_OTHER);
3003 /* Check Duplex mismatch */
3004 if ((AuxStat & PHY_B_AS_AN_RES_MSK) == PHY_B_RES_1000FD) {
3005 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOFULL;
3007 else if ((AuxStat & PHY_B_AS_AN_RES_MSK) == PHY_B_RES_1000HD) {
3008 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOHALF;
3012 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3013 ("AutoNegFail: Duplex mode mismatch Port %d\n", Port));
3014 pPrt->PAutoNegFail = SK_TRUE;
3015 return(SK_AND_DUP_CAP);
3020 /* Check Master/Slave resolution */
3021 if ((ResAb & PHY_B_1000S_MSF) != 0) {
3022 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3023 ("Master/Slave Fault Port %d\n", Port));
3024 pPrt->PAutoNegFail = SK_TRUE;
3025 pPrt->PMSStatus = SK_MS_STAT_FAULT;
3026 return(SK_AND_OTHER);
3029 pPrt->PMSStatus = ((ResAb & PHY_B_1000S_MSR) != 0) ?
3030 SK_MS_STAT_MASTER : SK_MS_STAT_SLAVE;
3033 /* Check PAUSE mismatch */
3034 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
3035 if ((AuxStat & PHY_B_AS_PAUSE_MSK) == PHY_B_AS_PAUSE_MSK) {
3036 /* Symmetric PAUSE */
3037 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_SYMMETRIC;
3039 else if ((AuxStat & PHY_B_AS_PAUSE_MSK) == PHY_B_AS_PRR) {
3040 /* Enable PAUSE receive, disable PAUSE transmit */
3041 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_REM_SEND;
3043 else if ((AuxStat & PHY_B_AS_PAUSE_MSK) == PHY_B_AS_PRT) {
3044 /* Disable PAUSE receive, enable PAUSE transmit */
3045 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_LOC_SEND;
3048 /* PAUSE mismatch -> no PAUSE */
3049 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
3051 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_1000MBPS;
3054 } /* SkXmAutoNegDoneBcom */
3057 /******************************************************************************
3059 * SkGmAutoNegDoneMarv() - Auto-negotiation handling
3062 * This function handles the auto-negotiation if the Done bit is set.
3066 * SK_AND_DUP_CAP Duplex capability error happened
3067 * SK_AND_OTHER Other error happened
3069 static int SkGmAutoNegDoneMarv(
3070 SK_AC *pAC, /* adapter context */
3071 SK_IOC IoC, /* IO context */
3072 int Port) /* Port Index (MAC_1 + n) */
3075 SK_U16 LPAb; /* Link Partner Ability */
3076 SK_U16 ResAb; /* Resolved Ability */
3077 SK_U16 AuxStat; /* Auxiliary Status */
3079 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3080 ("AutoNegDoneMarv, Port %d\n", Port));
3081 pPrt = &pAC->GIni.GP[Port];
3083 /* Get PHY parameters */
3084 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_AUNE_LP, &LPAb);
3086 if ((LPAb & PHY_M_AN_RF) != 0) {
3087 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3088 ("AutoNegFail: Remote fault bit set Port %d\n", Port));
3089 pPrt->PAutoNegFail = SK_TRUE;
3090 return(SK_AND_OTHER);
3093 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_1000T_STAT, &ResAb);
3095 /* Check Master/Slave resolution */
3096 if ((ResAb & PHY_B_1000S_MSF) != 0) {
3097 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3098 ("Master/Slave Fault Port %d\n", Port));
3099 pPrt->PAutoNegFail = SK_TRUE;
3100 pPrt->PMSStatus = SK_MS_STAT_FAULT;
3101 return(SK_AND_OTHER);
3104 pPrt->PMSStatus = ((ResAb & PHY_B_1000S_MSR) != 0) ?
3105 (SK_U8)SK_MS_STAT_MASTER : (SK_U8)SK_MS_STAT_SLAVE;
3107 /* Read PHY Specific Status */
3108 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_PHY_STAT, &AuxStat);
3110 /* Check Speed & Duplex resolved */
3111 if ((AuxStat & PHY_M_PS_SPDUP_RES) == 0) {
3112 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3113 ("AutoNegFail: Speed & Duplex not resolved Port %d\n", Port));
3114 pPrt->PAutoNegFail = SK_TRUE;
3115 pPrt->PLinkModeStatus = SK_LMODE_STAT_UNKNOWN;
3116 return(SK_AND_DUP_CAP);
3119 if ((AuxStat & PHY_M_PS_FULL_DUP) != 0) {
3120 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOFULL;
3123 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOHALF;
3126 /* Check PAUSE mismatch */
3127 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
3128 if ((AuxStat & PHY_M_PS_PAUSE_MSK) == PHY_M_PS_PAUSE_MSK) {
3129 /* Symmetric PAUSE */
3130 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_SYMMETRIC;
3132 else if ((AuxStat & PHY_M_PS_PAUSE_MSK) == PHY_M_PS_RX_P_EN) {
3133 /* Enable PAUSE receive, disable PAUSE transmit */
3134 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_REM_SEND;
3136 else if ((AuxStat & PHY_M_PS_PAUSE_MSK) == PHY_M_PS_TX_P_EN) {
3137 /* Disable PAUSE receive, enable PAUSE transmit */
3138 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_LOC_SEND;
3141 /* PAUSE mismatch -> no PAUSE */
3142 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
3145 /* set used link speed */
3146 switch ((unsigned)(AuxStat & PHY_M_PS_SPEED_MSK)) {
3147 case (unsigned)PHY_M_PS_SPEED_1000:
3148 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_1000MBPS;
3150 case PHY_M_PS_SPEED_100:
3151 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_100MBPS;
3154 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_10MBPS;
3158 } /* SkGmAutoNegDoneMarv */
3162 /******************************************************************************
3164 * SkXmAutoNegDoneLone() - Auto-negotiation handling
3167 * This function handles the auto-negotiation if the Done bit is set.
3171 * SK_AND_DUP_CAP Duplex capability error happened
3172 * SK_AND_OTHER Other error happened
3174 static int SkXmAutoNegDoneLone(
3175 SK_AC *pAC, /* adapter context */
3176 SK_IOC IoC, /* IO context */
3177 int Port) /* Port Index (MAC_1 + n) */
3180 SK_U16 ResAb; /* Resolved Ability */
3181 SK_U16 LPAb; /* Link Partner Ability */
3182 SK_U16 QuickStat; /* Auxiliary Status */
3184 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3185 ("AutoNegDoneLone, Port %d\n",Port));
3186 pPrt = &pAC->GIni.GP[Port];
3188 /* Get PHY parameters */
3189 SkXmPhyRead(pAC, IoC, Port, PHY_LONE_AUNE_LP, &LPAb);
3190 SkXmPhyRead(pAC, IoC, Port, PHY_LONE_1000T_STAT, &ResAb);
3191 SkXmPhyRead(pAC, IoC, Port, PHY_LONE_Q_STAT, &QuickStat);
3193 if ((LPAb & PHY_L_AN_RF) != 0) {
3194 /* Remote fault bit is set */
3196 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3197 ("AutoNegFail: Remote fault bit set Port %d\n", Port));
3198 pPrt->PAutoNegFail = SK_TRUE;
3199 return(SK_AND_OTHER);
3202 /* Check Duplex mismatch */
3203 if ((QuickStat & PHY_L_QS_DUP_MOD) != 0) {
3204 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOFULL;
3207 pPrt->PLinkModeStatus = SK_LMODE_STAT_AUTOHALF;
3210 /* Check Master/Slave resolution */
3211 if ((ResAb & PHY_L_1000S_MSF) != 0) {
3213 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
3214 ("Master/Slave Fault Port %d\n", Port));
3215 pPrt->PAutoNegFail = SK_TRUE;
3216 pPrt->PMSStatus = SK_MS_STAT_FAULT;
3217 return(SK_AND_OTHER);
3219 else if (ResAb & PHY_L_1000S_MSR) {
3220 pPrt->PMSStatus = SK_MS_STAT_MASTER;
3223 pPrt->PMSStatus = SK_MS_STAT_SLAVE;
3226 /* Check PAUSE mismatch */
3227 /* We are using IEEE 802.3z/D5.0 Table 37-4 */
3228 /* we must manually resolve the abilities here */
3229 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
3230 switch (pPrt->PFlowCtrlMode) {
3231 case SK_FLOW_MODE_NONE:
3234 case SK_FLOW_MODE_LOC_SEND:
3235 if ((QuickStat & (PHY_L_QS_PAUSE | PHY_L_QS_AS_PAUSE)) ==
3236 (PHY_L_QS_PAUSE | PHY_L_QS_AS_PAUSE)) {
3237 /* Disable PAUSE receive, enable PAUSE transmit */
3238 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_LOC_SEND;
3241 case SK_FLOW_MODE_SYMMETRIC:
3242 if ((QuickStat & PHY_L_QS_PAUSE) != 0) {
3243 /* Symmetric PAUSE */
3244 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_SYMMETRIC;
3247 case SK_FLOW_MODE_SYM_OR_REM:
3248 if ((QuickStat & (PHY_L_QS_PAUSE | PHY_L_QS_AS_PAUSE)) ==
3249 PHY_L_QS_AS_PAUSE) {
3250 /* Enable PAUSE receive, disable PAUSE transmit */
3251 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_REM_SEND;
3253 else if ((QuickStat & PHY_L_QS_PAUSE) != 0) {
3254 /* Symmetric PAUSE */
3255 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_SYMMETRIC;
3259 SK_ERR_LOG(pAC, SK_ERRCL_SW | SK_ERRCL_INIT, SKERR_HWI_E016,
3264 } /* SkXmAutoNegDoneLone */
3267 /******************************************************************************
3269 * SkXmAutoNegDoneNat() - Auto-negotiation handling
3272 * This function handles the auto-negotiation if the Done bit is set.
3276 * SK_AND_DUP_CAP Duplex capability error happened
3277 * SK_AND_OTHER Other error happened
3279 static int SkXmAutoNegDoneNat(
3280 SK_AC *pAC, /* adapter context */
3281 SK_IOC IoC, /* IO context */
3282 int Port) /* Port Index (MAC_1 + n) */
3284 /* todo: National */
3286 } /* SkXmAutoNegDoneNat */
3287 #endif /* OTHER_PHY */
3290 /******************************************************************************
3292 * SkMacAutoNegDone() - Auto-negotiation handling
3294 * Description: calls the auto-negotiation done routines dep. on board type
3298 * SK_AND_DUP_CAP Duplex capability error happened
3299 * SK_AND_OTHER Other error happened
3301 int SkMacAutoNegDone(
3302 SK_AC *pAC, /* adapter context */
3303 SK_IOC IoC, /* IO context */
3304 int Port) /* Port Index (MAC_1 + n) */
3309 pPrt = &pAC->GIni.GP[Port];
3311 switch (pPrt->PhyType) {
3313 Rtv = SkXmAutoNegDoneXmac(pAC, IoC, Port);
3316 Rtv = SkXmAutoNegDoneBcom(pAC, IoC, Port);
3318 case SK_PHY_MARV_COPPER:
3319 case SK_PHY_MARV_FIBER:
3320 Rtv = SkGmAutoNegDoneMarv(pAC, IoC, Port);
3324 Rtv = SkXmAutoNegDoneLone(pAC, IoC, Port);
3327 Rtv = SkXmAutoNegDoneNat(pAC, IoC, Port);
3329 #endif /* OTHER_PHY */
3331 return(SK_AND_OTHER);
3334 if (Rtv != SK_AND_OK) {
3338 /* We checked everything and may now enable the link */
3339 pPrt->PAutoNegFail = SK_FALSE;
3341 SkMacRxTxEnable(pAC, IoC, Port);
3344 } /* SkMacAutoNegDone */
3347 /******************************************************************************
3349 * SkXmSetRxTxEn() - Special Set Rx/Tx Enable and some features in XMAC
3352 * sets MAC or PHY LoopBack and Duplex Mode in the MMU Command Reg.
3357 static void SkXmSetRxTxEn(
3358 SK_AC *pAC, /* Adapter Context */
3359 SK_IOC IoC, /* IO context */
3360 int Port, /* Port Index (MAC_1 + n) */
3361 int Para) /* Parameter to set: MAC or PHY LoopBack, Duplex Mode */
3365 XM_IN16(IoC, Port, XM_MMU_CMD, &Word);
3367 switch (Para & (SK_MAC_LOOPB_ON | SK_MAC_LOOPB_OFF)) {
3368 case SK_MAC_LOOPB_ON:
3369 Word |= XM_MMU_MAC_LB;
3371 case SK_MAC_LOOPB_OFF:
3372 Word &= ~XM_MMU_MAC_LB;
3376 switch (Para & (SK_PHY_LOOPB_ON | SK_PHY_LOOPB_OFF)) {
3377 case SK_PHY_LOOPB_ON:
3378 Word |= XM_MMU_GMII_LOOP;
3380 case SK_PHY_LOOPB_OFF:
3381 Word &= ~XM_MMU_GMII_LOOP;
3385 switch (Para & (SK_PHY_FULLD_ON | SK_PHY_FULLD_OFF)) {
3386 case SK_PHY_FULLD_ON:
3387 Word |= XM_MMU_GMII_FD;
3389 case SK_PHY_FULLD_OFF:
3390 Word &= ~XM_MMU_GMII_FD;
3394 XM_OUT16(IoC, Port, XM_MMU_CMD, Word | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
3396 /* dummy read to ensure writing */
3397 XM_IN16(IoC, Port, XM_MMU_CMD, &Word);
3399 } /* SkXmSetRxTxEn */
3402 /******************************************************************************
3404 * SkGmSetRxTxEn() - Special Set Rx/Tx Enable and some features in GMAC
3407 * sets MAC LoopBack and Duplex Mode in the General Purpose Control Reg.
3412 static void SkGmSetRxTxEn(
3413 SK_AC *pAC, /* Adapter Context */
3414 SK_IOC IoC, /* IO context */
3415 int Port, /* Port Index (MAC_1 + n) */
3416 int Para) /* Parameter to set: MAC LoopBack, Duplex Mode */
3420 GM_IN16(IoC, Port, GM_GP_CTRL, &Ctrl);
3422 switch (Para & (SK_MAC_LOOPB_ON | SK_MAC_LOOPB_OFF)) {
3423 case SK_MAC_LOOPB_ON:
3424 Ctrl |= GM_GPCR_LOOP_ENA;
3426 case SK_MAC_LOOPB_OFF:
3427 Ctrl &= ~GM_GPCR_LOOP_ENA;
3431 switch (Para & (SK_PHY_FULLD_ON | SK_PHY_FULLD_OFF)) {
3432 case SK_PHY_FULLD_ON:
3433 Ctrl |= GM_GPCR_DUP_FULL;
3435 case SK_PHY_FULLD_OFF:
3436 Ctrl &= ~GM_GPCR_DUP_FULL;
3440 GM_OUT16(IoC, Port, GM_GP_CTRL, Ctrl | GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
3442 /* dummy read to ensure writing */
3443 GM_IN16(IoC, Port, GM_GP_CTRL, &Ctrl);
3445 } /* SkGmSetRxTxEn */
3448 /******************************************************************************
3450 * SkMacSetRxTxEn() - Special Set Rx/Tx Enable and parameters
3452 * Description: calls the Special Set Rx/Tx Enable routines dep. on board type
3456 void SkMacSetRxTxEn(
3457 SK_AC *pAC, /* Adapter Context */
3458 SK_IOC IoC, /* IO context */
3459 int Port, /* Port Index (MAC_1 + n) */
3462 if (pAC->GIni.GIGenesis) {
3464 SkXmSetRxTxEn(pAC, IoC, Port, Para);
3468 SkGmSetRxTxEn(pAC, IoC, Port, Para);
3471 } /* SkMacSetRxTxEn */
3474 /******************************************************************************
3476 * SkMacRxTxEnable() - Enable Rx/Tx activity if port is up
3478 * Description: enables Rx/Tx dep. on board type
3482 * != 0 Error happened
3484 int SkMacRxTxEnable(
3485 SK_AC *pAC, /* adapter context */
3486 SK_IOC IoC, /* IO context */
3487 int Port) /* Port Index (MAC_1 + n) */
3490 SK_U16 Reg; /* 16-bit register value */
3491 SK_U16 IntMask; /* MAC interrupt mask */
3494 pPrt = &pAC->GIni.GP[Port];
3496 if (!pPrt->PHWLinkUp) {
3497 /* The Hardware link is NOT up */
3501 if ((pPrt->PLinkMode == SK_LMODE_AUTOHALF ||
3502 pPrt->PLinkMode == SK_LMODE_AUTOFULL ||
3503 pPrt->PLinkMode == SK_LMODE_AUTOBOTH) &&
3504 pPrt->PAutoNegFail) {
3505 /* Auto-negotiation is not done or failed */
3509 if (pAC->GIni.GIGenesis) {
3510 /* set Duplex Mode and Pause Mode */
3511 SkXmInitDupMd(pAC, IoC, Port);
3513 SkXmInitPauseMd(pAC, IoC, Port);
3516 * Initialize the Interrupt Mask Register. Default IRQs are...
3517 * - Link Asynchronous Event
3518 * - Link Partner requests config
3519 * - Auto Negotiation Done
3520 * - Rx Counter Event Overflow
3521 * - Tx Counter Event Overflow
3522 * - Transmit FIFO Underrun
3524 IntMask = XM_DEF_MSK;
3527 /* add IRQ for Receive FIFO Overflow */
3528 IntMask &= ~XM_IS_RXF_OV;
3531 if (pPrt->PhyType != SK_PHY_XMAC) {
3532 /* disable GP0 interrupt bit */
3533 IntMask |= XM_IS_INP_ASS;
3535 XM_OUT16(IoC, Port, XM_IMSK, IntMask);
3537 /* get MMU Command Reg. */
3538 XM_IN16(IoC, Port, XM_MMU_CMD, &Reg);
3540 if (pPrt->PhyType != SK_PHY_XMAC &&
3541 (pPrt->PLinkModeStatus == SK_LMODE_STAT_FULL ||
3542 pPrt->PLinkModeStatus == SK_LMODE_STAT_AUTOFULL)) {
3543 /* set to Full Duplex */
3544 Reg |= XM_MMU_GMII_FD;
3547 switch (pPrt->PhyType) {
3550 * Workaround BCOM Errata (#10523) for all BCom Phys
3551 * Enable Power Management after link up
3553 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, &SWord);
3554 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUX_CTRL,
3555 (SK_U16)(SWord & ~PHY_B_AC_DIS_PM));
3556 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_INT_MASK, PHY_B_DEF_MSK);
3560 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_INT_ENAB, PHY_L_DEF_MSK);
3564 SkXmPhyWrite(pAC, IoC, Port, PHY_NAT_INT_MASK, PHY_N_DEF_MSK); */
3565 /* no interrupts possible from National ??? */
3567 #endif /* OTHER_PHY */
3571 XM_OUT16(IoC, Port, XM_MMU_CMD, Reg | XM_MMU_ENA_RX | XM_MMU_ENA_TX);
3575 * Initialize the Interrupt Mask Register. Default IRQs are...
3576 * - Rx Counter Event Overflow
3577 * - Tx Counter Event Overflow
3578 * - Transmit FIFO Underrun
3580 IntMask = GMAC_DEF_MSK;
3583 /* add IRQ for Receive FIFO Overrun */
3584 IntMask |= GM_IS_RX_FF_OR;
3587 SK_OUT8(IoC, GMAC_IRQ_MSK, (SK_U8)IntMask);
3589 /* get General Purpose Control */
3590 GM_IN16(IoC, Port, GM_GP_CTRL, &Reg);
3592 if (pPrt->PLinkModeStatus == SK_LMODE_STAT_FULL ||
3593 pPrt->PLinkModeStatus == SK_LMODE_STAT_AUTOFULL) {
3594 /* set to Full Duplex */
3595 Reg |= GM_GPCR_DUP_FULL;
3599 GM_OUT16(IoC, Port, GM_GP_CTRL, Reg | GM_GPCR_RX_ENA | GM_GPCR_TX_ENA);
3602 /* Enable all PHY interrupts */
3603 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_INT_MASK, PHY_M_DEF_MSK);
3609 } /* SkMacRxTxEnable */
3612 /******************************************************************************
3614 * SkMacRxTxDisable() - Disable Receiver and Transmitter
3616 * Description: disables Rx/Tx dep. on board type
3620 void SkMacRxTxDisable(
3621 SK_AC *pAC, /* Adapter Context */
3622 SK_IOC IoC, /* IO context */
3623 int Port) /* Port Index (MAC_1 + n) */
3627 if (pAC->GIni.GIGenesis) {
3629 XM_IN16(IoC, Port, XM_MMU_CMD, &Word);
3631 XM_OUT16(IoC, Port, XM_MMU_CMD, Word & ~(XM_MMU_ENA_RX | XM_MMU_ENA_TX));
3633 /* dummy read to ensure writing */
3634 XM_IN16(IoC, Port, XM_MMU_CMD, &Word);
3638 GM_IN16(IoC, Port, GM_GP_CTRL, &Word);
3640 GM_OUT16(IoC, Port, GM_GP_CTRL, Word & ~(GM_GPCR_RX_ENA | GM_GPCR_TX_ENA));
3642 /* dummy read to ensure writing */
3643 GM_IN16(IoC, Port, GM_GP_CTRL, &Word);
3645 } /* SkMacRxTxDisable */
3648 /******************************************************************************
3650 * SkMacIrqDisable() - Disable IRQ from MAC
3652 * Description: sets the IRQ-mask to disable IRQ dep. on board type
3656 void SkMacIrqDisable(
3657 SK_AC *pAC, /* Adapter Context */
3658 SK_IOC IoC, /* IO context */
3659 int Port) /* Port Index (MAC_1 + n) */
3664 pPrt = &pAC->GIni.GP[Port];
3666 if (pAC->GIni.GIGenesis) {
3668 /* disable all XMAC IRQs */
3669 XM_OUT16(IoC, Port, XM_IMSK, 0xffff);
3671 /* Disable all PHY interrupts */
3672 switch (pPrt->PhyType) {
3674 /* Make sure that PHY is initialized */
3675 if (pPrt->PState != SK_PRT_RESET) {
3676 /* NOT allowed if BCOM is in RESET state */
3677 /* Workaround BCOM Errata (#10523) all BCom */
3678 /* Disable Power Management if link is down */
3679 SkXmPhyRead(pAC, IoC, Port, PHY_BCOM_AUX_CTRL, &Word);
3680 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_AUX_CTRL,
3681 (SK_U16)(Word | PHY_B_AC_DIS_PM));
3682 SkXmPhyWrite(pAC, IoC, Port, PHY_BCOM_INT_MASK, 0xffff);
3687 SkXmPhyWrite(pAC, IoC, Port, PHY_LONE_INT_ENAB, 0);
3691 SkXmPhyWrite(pAC, IoC, Port, PHY_NAT_INT_MASK, 0xffff); */
3693 #endif /* OTHER_PHY */
3697 /* disable all GMAC IRQs */
3698 SK_OUT8(IoC, GMAC_IRQ_MSK, 0);
3701 /* Disable all PHY interrupts */
3702 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_INT_MASK, 0);
3705 } /* SkMacIrqDisable */
3709 /******************************************************************************
3711 * SkXmSendCont() - Enable / Disable Send Continuous Mode
3713 * Description: enable / disable Send Continuous Mode on XMAC
3719 SK_AC *pAC, /* adapter context */
3720 SK_IOC IoC, /* IO context */
3721 int Port, /* Port Index (MAC_1 + n) */
3722 SK_BOOL Enable) /* Enable / Disable */
3726 XM_IN32(IoC, Port, XM_MODE, &MdReg);
3729 MdReg |= XM_MD_TX_CONT;
3732 MdReg &= ~XM_MD_TX_CONT;
3734 /* setup Mode Register */
3735 XM_OUT32(IoC, Port, XM_MODE, MdReg);
3739 /******************************************************************************
3741 * SkMacTimeStamp() - Enable / Disable Time Stamp
3743 * Description: enable / disable Time Stamp generation for Rx packets
3748 void SkMacTimeStamp(
3749 SK_AC *pAC, /* adapter context */
3750 SK_IOC IoC, /* IO context */
3751 int Port, /* Port Index (MAC_1 + n) */
3752 SK_BOOL Enable) /* Enable / Disable */
3757 if (pAC->GIni.GIGenesis) {
3759 XM_IN32(IoC, Port, XM_MODE, &MdReg);
3765 MdReg &= ~XM_MD_ATS;
3767 /* setup Mode Register */
3768 XM_OUT32(IoC, Port, XM_MODE, MdReg);
3772 TimeCtrl = GMT_ST_START | GMT_ST_CLR_IRQ;
3775 TimeCtrl = GMT_ST_STOP | GMT_ST_CLR_IRQ;
3777 /* Start/Stop Time Stamp Timer */
3778 SK_OUT8(pAC, GMAC_TI_ST_CTRL, TimeCtrl);
3780 } /* SkMacTimeStamp*/
3784 /******************************************************************************
3786 * SkXmIrq() - Interrupt Service Routine
3788 * Description: services an Interrupt Request of the XMAC
3791 * With an external PHY, some interrupt bits are not meaningfull any more:
3792 * - LinkAsyncEvent (bit #14) XM_IS_LNK_AE
3793 * - LinkPartnerReqConfig (bit #10) XM_IS_LIPA_RC
3794 * - Page Received (bit #9) XM_IS_RX_PAGE
3795 * - NextPageLoadedForXmt (bit #8) XM_IS_TX_PAGE
3796 * - AutoNegDone (bit #7) XM_IS_AND
3797 * Also probably not valid any more is the GP0 input bit:
3798 * - GPRegisterBit0set XM_IS_INP_ASS
3804 SK_AC *pAC, /* adapter context */
3805 SK_IOC IoC, /* IO context */
3806 int Port) /* Port Index (MAC_1 + n) */
3810 SK_U16 IStatus; /* Interrupt status read from the XMAC */
3813 pPrt = &pAC->GIni.GP[Port];
3815 XM_IN16(IoC, Port, XM_ISRC, &IStatus);
3817 /* LinkPartner Auto-negable? */
3818 if (pPrt->PhyType == SK_PHY_XMAC) {
3819 SkXmAutoNegLipaXmac(pAC, IoC, Port, IStatus);
3822 /* mask bits that are not used with ext. PHY */
3823 IStatus &= ~(XM_IS_LNK_AE | XM_IS_LIPA_RC |
3824 XM_IS_RX_PAGE | XM_IS_TX_PAGE |
3825 XM_IS_AND | XM_IS_INP_ASS);
3828 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_IRQ,
3829 ("XmacIrq Port %d Isr 0x%04x\n", Port, IStatus));
3831 if (!pPrt->PHWLinkUp) {
3832 /* Spurious XMAC interrupt */
3833 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_IRQ,
3834 ("SkXmIrq: spurious interrupt on Port %d\n", Port));
3838 if ((IStatus & XM_IS_INP_ASS) != 0) {
3839 /* Reread ISR Register if link is not in sync */
3840 XM_IN16(IoC, Port, XM_ISRC, &IStatus2);
3842 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_IRQ,
3843 ("SkXmIrq: Link async. Double check Port %d 0x%04x 0x%04x\n",
3844 Port, IStatus, IStatus2));
3845 IStatus &= ~XM_IS_INP_ASS;
3846 IStatus |= IStatus2;
3849 if ((IStatus & XM_IS_LNK_AE) != 0) {
3850 /* not used, GP0 is used instead */
3853 if ((IStatus & XM_IS_TX_ABORT) != 0) {
3857 if ((IStatus & XM_IS_FRC_INT) != 0) {
3858 /* not used, use ASIC IRQ instead if needed */
3861 if ((IStatus & (XM_IS_INP_ASS | XM_IS_LIPA_RC | XM_IS_RX_PAGE)) != 0) {
3862 SkHWLinkDown(pAC, IoC, Port);
3864 /* Signal to RLMT */
3865 Para.Para32[0] = (SK_U32)Port;
3866 SkEventQueue(pAC, SKGE_RLMT, SK_RLMT_LINK_DOWN, Para);
3868 /* Start workaround Errata #2 timer */
3869 SkTimerStart(pAC, IoC, &pPrt->PWaTimer, SK_WA_INA_TIME,
3870 SKGE_HWAC, SK_HWEV_WATIM, Para);
3873 if ((IStatus & XM_IS_RX_PAGE) != 0) {
3877 if ((IStatus & XM_IS_TX_PAGE) != 0) {
3881 if ((IStatus & XM_IS_AND) != 0) {
3882 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_IRQ,
3883 ("SkXmIrq: AND on link that is up Port %d\n", Port));
3886 if ((IStatus & XM_IS_TSC_OV) != 0) {
3890 /* Combined Tx & Rx Counter Overflow SIRQ Event */
3891 if ((IStatus & (XM_IS_RXC_OV | XM_IS_TXC_OV)) != 0) {
3892 Para.Para32[0] = (SK_U32)Port;
3893 Para.Para32[1] = (SK_U32)IStatus;
3894 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_SIRQ_OVERFLOW, Para);
3897 if ((IStatus & XM_IS_RXF_OV) != 0) {
3898 /* normal situation -> no effect */
3904 if ((IStatus & XM_IS_TXF_UR) != 0) {
3905 /* may NOT happen -> error log */
3906 SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_SIRQ_E020, SKERR_SIRQ_E020MSG);
3909 if ((IStatus & XM_IS_TX_COMP) != 0) {
3910 /* not served here */
3913 if ((IStatus & XM_IS_RX_COMP) != 0) {
3914 /* not served here */
3919 /******************************************************************************
3921 * SkGmIrq() - Interrupt Service Routine
3923 * Description: services an Interrupt Request of the GMAC
3931 SK_AC *pAC, /* adapter context */
3932 SK_IOC IoC, /* IO context */
3933 int Port) /* Port Index (MAC_1 + n) */
3937 SK_U8 IStatus; /* Interrupt status */
3939 pPrt = &pAC->GIni.GP[Port];
3941 SK_IN8(IoC, GMAC_IRQ_SRC, &IStatus);
3943 /* LinkPartner Auto-negable? */
3944 SkMacAutoNegLipaPhy(pAC, IoC, Port, IStatus);
3946 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_IRQ,
3947 ("GmacIrq Port %d Isr 0x%04x\n", Port, IStatus));
3949 /* Combined Tx & Rx Counter Overflow SIRQ Event */
3950 if (IStatus & (GM_IS_RX_CO_OV | GM_IS_TX_CO_OV)) {
3951 /* these IRQs will be cleared by reading GMACs register */
3952 Para.Para32[0] = (SK_U32)Port;
3953 Para.Para32[1] = (SK_U32)IStatus;
3954 SkPnmiEvent(pAC, IoC, SK_PNMI_EVT_SIRQ_OVERFLOW, Para);
3957 if (IStatus & GM_IS_RX_FF_OR) {
3958 /* clear GMAC Rx FIFO Overrun IRQ */
3959 SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_CLI_RX_FO);
3965 if (IStatus & GM_IS_TX_FF_UR) {
3966 /* clear GMAC Tx FIFO Underrun IRQ */
3967 SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_CLI_TX_FU);
3968 /* may NOT happen -> error log */
3969 SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_SIRQ_E020, SKERR_SIRQ_E020MSG);
3972 if (IStatus & GM_IS_TX_COMPL) {
3973 /* not served here */
3976 if (IStatus & GM_IS_RX_COMPL) {
3977 /* not served here */
3981 /******************************************************************************
3983 * SkMacIrq() - Interrupt Service Routine for MAC
3985 * Description: calls the Interrupt Service Routine dep. on board type
3991 SK_AC *pAC, /* adapter context */
3992 SK_IOC IoC, /* IO context */
3993 int Port) /* Port Index (MAC_1 + n) */
3996 if (pAC->GIni.GIGenesis) {
3998 SkXmIrq(pAC, IoC, Port);
4002 SkGmIrq(pAC, IoC, Port);
4006 #endif /* !SK_DIAG */
4008 /******************************************************************************
4010 * SkXmUpdateStats() - Force the XMAC to output the current statistic
4013 * The XMAC holds its statistic internally. To obtain the current
4014 * values a command must be sent so that the statistic data will
4015 * be written to a predefined memory area on the adapter.
4019 * 1: something went wrong
4021 int SkXmUpdateStats(
4022 SK_AC *pAC, /* adapter context */
4023 SK_IOC IoC, /* IO context */
4024 unsigned int Port) /* Port Index (MAC_1 + n) */
4030 pPrt = &pAC->GIni.GP[Port];
4033 /* Send an update command to XMAC specified */
4034 XM_OUT16(IoC, Port, XM_STAT_CMD, XM_SC_SNP_TXC | XM_SC_SNP_RXC);
4037 * It is an auto-clearing register. If the command bits
4038 * went to zero again, the statistics are transferred.
4039 * Normally the command should be executed immediately.
4040 * But just to be sure we execute a loop.
4044 XM_IN16(IoC, Port, XM_STAT_CMD, &StatReg);
4046 if (++WaitIndex > 10) {
4048 SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E021, SKERR_HWI_E021MSG);
4052 } while ((StatReg & (XM_SC_SNP_TXC | XM_SC_SNP_RXC)) != 0);
4055 } /* SkXmUpdateStats */
4057 /******************************************************************************
4059 * SkGmUpdateStats() - Force the GMAC to output the current statistic
4062 * Empty function for GMAC. Statistic data is accessible in direct way.
4066 * 1: something went wrong
4068 int SkGmUpdateStats(
4069 SK_AC *pAC, /* adapter context */
4070 SK_IOC IoC, /* IO context */
4071 unsigned int Port) /* Port Index (MAC_1 + n) */
4076 /******************************************************************************
4078 * SkXmMacStatistic() - Get XMAC counter value
4081 * Gets the 32bit counter value. Except for the octet counters
4082 * the lower 32bit are counted in hardware and the upper 32bit
4083 * must be counted in software by monitoring counter overflow interrupts.
4087 * 1: something went wrong
4089 int SkXmMacStatistic(
4090 SK_AC *pAC, /* adapter context */
4091 SK_IOC IoC, /* IO context */
4092 unsigned int Port, /* Port Index (MAC_1 + n) */
4093 SK_U16 StatAddr, /* MIB counter base address */
4094 SK_U32 *pVal) /* ptr to return statistic value */
4096 if ((StatAddr < XM_TXF_OK) || (StatAddr > XM_RXF_MAX_SZ)) {
4098 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E022, SKERR_HWI_E022MSG);
4103 XM_IN32(IoC, Port, StatAddr, pVal);
4106 } /* SkXmMacStatistic */
4108 /******************************************************************************
4110 * SkGmMacStatistic() - Get GMAC counter value
4113 * Gets the 32bit counter value. Except for the octet counters
4114 * the lower 32bit are counted in hardware and the upper 32bit
4115 * must be counted in software by monitoring counter overflow interrupts.
4119 * 1: something went wrong
4121 int SkGmMacStatistic(
4122 SK_AC *pAC, /* adapter context */
4123 SK_IOC IoC, /* IO context */
4124 unsigned int Port, /* Port Index (MAC_1 + n) */
4125 SK_U16 StatAddr, /* MIB counter base address */
4126 SK_U32 *pVal) /* ptr to return statistic value */
4129 if ((StatAddr < GM_RXF_UC_OK) || (StatAddr > GM_TXE_FIFO_UR)) {
4131 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E022, SKERR_HWI_E022MSG);
4133 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
4134 ("SkGmMacStat: wrong MIB counter 0x%04X\n", StatAddr));
4138 GM_IN32(IoC, Port, StatAddr, pVal);
4141 } /* SkGmMacStatistic */
4143 /******************************************************************************
4145 * SkXmResetCounter() - Clear MAC statistic counter
4148 * Force the XMAC to clear its statistic counter.
4152 * 1: something went wrong
4154 int SkXmResetCounter(
4155 SK_AC *pAC, /* adapter context */
4156 SK_IOC IoC, /* IO context */
4157 unsigned int Port) /* Port Index (MAC_1 + n) */
4159 XM_OUT16(IoC, Port, XM_STAT_CMD, XM_SC_CLR_RXC | XM_SC_CLR_TXC);
4160 /* Clear two times according to Errata #3 */
4161 XM_OUT16(IoC, Port, XM_STAT_CMD, XM_SC_CLR_RXC | XM_SC_CLR_TXC);
4164 } /* SkXmResetCounter */
4166 /******************************************************************************
4168 * SkGmResetCounter() - Clear MAC statistic counter
4171 * Force GMAC to clear its statistic counter.
4175 * 1: something went wrong
4177 int SkGmResetCounter(
4178 SK_AC *pAC, /* adapter context */
4179 SK_IOC IoC, /* IO context */
4180 unsigned int Port) /* Port Index (MAC_1 + n) */
4182 SK_U16 Reg; /* Phy Address Register */
4186 GM_IN16(IoC, Port, GM_PHY_ADDR, &Reg);
4189 /* set MIB Clear Counter Mode */
4190 GM_OUT16(IoC, Port, GM_PHY_ADDR, Reg | GM_PAR_MIB_CLR);
4192 /* read all MIB Counters with Clear Mode set */
4193 for (i = 0; i < GM_MIB_CNT_SIZE; i++) {
4194 /* the reset is performed only when the lower 16 bits are read */
4195 GM_IN16(IoC, Port, GM_MIB_CNT_BASE + 8*i, &Word);
4198 /* clear MIB Clear Counter Mode */
4199 GM_OUT16(IoC, Port, GM_PHY_ADDR, Reg);
4203 } /* SkGmResetCounter */
4205 /******************************************************************************
4207 * SkXmOverflowStatus() - Gets the status of counter overflow interrupt
4210 * Checks the source causing an counter overflow interrupt. On success the
4211 * resulting counter overflow status is written to <pStatus>, whereas the
4212 * upper dword stores the XMAC ReceiveCounterEvent register and the lower
4213 * dword the XMAC TransmitCounterEvent register.
4216 * For XMAC the interrupt source is a self-clearing register, so the source
4217 * must be checked only once. SIRQ module does another check to be sure
4218 * that no interrupt get lost during process time.
4222 * 1: something went wrong
4224 int SkXmOverflowStatus(
4225 SK_AC *pAC, /* adapter context */
4226 SK_IOC IoC, /* IO context */
4227 unsigned int Port, /* Port Index (MAC_1 + n) */
4228 SK_U16 IStatus, /* Interupt Status from MAC */
4229 SK_U64 *pStatus) /* ptr for return overflow status value */
4231 SK_U64 Status; /* Overflow status */
4236 if ((IStatus & XM_IS_RXC_OV) != 0) {
4238 XM_IN32(IoC, Port, XM_RX_CNT_EV, &RegVal);
4239 Status |= (SK_U64)RegVal << 32;
4242 if ((IStatus & XM_IS_TXC_OV) != 0) {
4244 XM_IN32(IoC, Port, XM_TX_CNT_EV, &RegVal);
4245 Status |= (SK_U64)RegVal;
4251 } /* SkXmOverflowStatus */
4254 /******************************************************************************
4256 * SkGmOverflowStatus() - Gets the status of counter overflow interrupt
4259 * Checks the source causing an counter overflow interrupt. On success the
4260 * resulting counter overflow status is written to <pStatus>, whereas the
4261 * the following bit coding is used:
4263 * 55:48 - TxRx interrupt register bit7:0
4264 * 32:47 - Rx interrupt register
4266 * 23:16 - TxRx interrupt register bit15:8
4267 * 15:0 - Tx interrupt register
4271 * 1: something went wrong
4273 int SkGmOverflowStatus(
4274 SK_AC *pAC, /* adapter context */
4275 SK_IOC IoC, /* IO context */
4276 unsigned int Port, /* Port Index (MAC_1 + n) */
4277 SK_U16 IStatus, /* Interupt Status from MAC */
4278 SK_U64 *pStatus) /* ptr for return overflow status value */
4280 SK_U64 Status; /* Overflow status */
4285 if ((IStatus & GM_IS_RX_CO_OV) != 0) {
4286 /* this register is self-clearing after read */
4287 GM_IN16(IoC, Port, GM_RX_IRQ_SRC, &RegVal);
4288 Status |= (SK_U64)RegVal << 32;
4291 if ((IStatus & GM_IS_TX_CO_OV) != 0) {
4292 /* this register is self-clearing after read */
4293 GM_IN16(IoC, Port, GM_TX_IRQ_SRC, &RegVal);
4294 Status |= (SK_U64)RegVal;
4297 /* this register is self-clearing after read */
4298 GM_IN16(IoC, Port, GM_TR_IRQ_SRC, &RegVal);
4299 /* Rx overflow interrupt register bits (LoByte)*/
4300 Status |= (SK_U64)((SK_U8)RegVal) << 48;
4301 /* Tx overflow interrupt register bits (HiByte)*/
4302 Status |= (SK_U64)(RegVal >> 8) << 16;
4307 } /* SkGmOverflowStatus */
4309 /******************************************************************************
4311 * SkGmCableDiagStatus() - Starts / Gets status of cable diagnostic test
4314 * starts the cable diagnostic test if 'StartTest' is true
4315 * gets the results if 'StartTest' is true
4317 * NOTE: this test is meaningful only when link is down
4321 * 1: no YUKON copper
4322 * 2: test in progress
4324 int SkGmCableDiagStatus(
4325 SK_AC *pAC, /* adapter context */
4326 SK_IOC IoC, /* IO context */
4327 int Port, /* Port Index (MAC_1 + n) */
4328 SK_BOOL StartTest) /* flag for start / get result */
4334 pPrt = &pAC->GIni.GP[Port];
4336 if (pPrt->PhyType != SK_PHY_MARV_COPPER) {
4342 /* only start the cable test */
4343 if ((pPrt->PhyId1 & PHY_I1_REV_MSK) < 4) {
4344 /* apply TDR workaround from Marvell */
4345 SkGmPhyWrite(pAC, IoC, Port, 29, 0x001e);
4347 SkGmPhyWrite(pAC, IoC, Port, 30, 0xcc00);
4348 SkGmPhyWrite(pAC, IoC, Port, 30, 0xc800);
4349 SkGmPhyWrite(pAC, IoC, Port, 30, 0xc400);
4350 SkGmPhyWrite(pAC, IoC, Port, 30, 0xc000);
4351 SkGmPhyWrite(pAC, IoC, Port, 30, 0xc100);
4354 /* set address to 0 for MDI[0] */
4355 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_EXT_ADR, 0);
4357 /* Read Cable Diagnostic Reg */
4358 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_CABLE_DIAG, &RegVal);
4360 /* start Cable Diagnostic Test */
4361 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_CABLE_DIAG,
4362 (SK_U16)(RegVal | PHY_M_CABD_ENA_TEST));
4367 /* Read Cable Diagnostic Reg */
4368 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_CABLE_DIAG, &RegVal);
4370 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_CTRL,
4371 ("PHY Cable Diag.=0x%04X\n", RegVal));
4373 if ((RegVal & PHY_M_CABD_ENA_TEST) != 0) {
4374 /* test is running */
4378 /* get the test results */
4379 for (i = 0; i < 4; i++) {
4380 /* set address to i for MDI[i] */
4381 SkGmPhyWrite(pAC, IoC, Port, PHY_MARV_EXT_ADR, (SK_U16)i);
4383 /* get Cable Diagnostic values */
4384 SkGmPhyRead(pAC, IoC, Port, PHY_MARV_CABLE_DIAG, &RegVal);
4386 pPrt->PMdiPairLen[i] = (SK_U8)(RegVal & PHY_M_CABD_DIST_MSK);
4388 pPrt->PMdiPairSts[i] = (SK_U8)((RegVal & PHY_M_CABD_STAT_MSK) >> 13);
4392 } /* SkGmCableDiagStatus */
4394 #endif /* CONFIG_SK98 */