]> git.kernelconcepts.de Git - karo-tx-uboot.git/blob - drivers/net/sk98lin/skgeinit.c
imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
[karo-tx-uboot.git] / drivers / net / sk98lin / skgeinit.c
1 /******************************************************************************
2  *
3  * Name:        skgeinit.c
4  * Project:     GEnesis, PCI Gigabit Ethernet Adapter
5  * Version:     $Revision$
6  * Date:        $Date$
7  * Purpose:     Contains functions to initialize the GE HW
8  *
9  ******************************************************************************/
10
11 /******************************************************************************
12  *
13  *      (C)Copyright 1998-2003 SysKonnect GmbH.
14  *
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.
19  *
20  *      The information in this file is provided "AS IS" without warranty.
21  *
22  ******************************************************************************/
23
24 /******************************************************************************
25  *
26  * History:
27  *
28  *      $Log$
29  *      Revision 1.1.3.1  2011-02-28 14:53:19  lothar
30  *      imported Ka-Ro specific additions to U-Boot 2009.08 for TX28
31  *
32  *      Revision 1.85  2003/02/05 15:30:33  rschmidt
33  *      Corrected setting of GIHstClkFact (Host Clock Factor) and
34  *      GIPollTimerVal (Descr. Poll Timer Init Value) for YUKON.
35  *      Editorial changes.
36  *
37  *      Revision 1.84  2003/01/28 09:57:25  rschmidt
38  *      Added detection of YUKON-Lite Rev. A0 (stored in GIYukonLite).
39  *      Disabled Rx GMAC FIFO Flush for YUKON-Lite Rev. A0.
40  *      Added support for CLK_RUN (YUKON-Lite).
41  *      Added additional check of PME from D3cold for setting GIVauxAvail.
42  *      Editorial changes.
43  *
44  *      Revision 1.83  2002/12/17 16:15:41  rschmidt
45  *      Added default setting of PhyType (Copper) for YUKON.
46  *      Added define around check for HW self test results.
47  *      Editorial changes.
48  *
49  *      Revision 1.82  2002/12/05 13:40:21  rschmidt
50  *      Added setting of Rx GMAC FIFO Flush Mask register.
51  *      Corrected PhyType with new define SK_PHY_MARV_FIBER when
52  *      YUKON Fiber board was found.
53  *      Editorial changes.
54  *
55  *      Revision 1.81  2002/11/15 12:48:35  rschmidt
56  *      Replaced message SKERR_HWI_E018 with SKERR_HWI_E024 for Rx queue error
57  *      in SkGeStopPort().
58  *      Added init for pAC->GIni.GIGenesis with SK_FALSE in YUKON-branch.
59  *      Editorial changes.
60  *
61  *      Revision 1.80  2002/11/12 17:28:30  rschmidt
62  *      Initialized GIPciSlot64 and GIPciClock66 in SkGeInit1().
63  *      Reduced PCI FIFO watermarks for 32bit/33MHz bus in SkGeInitBmu().
64  *      Editorial changes.
65  *
66  *      Revision 1.79  2002/10/21 09:31:02  mkarl
67  *      Changed SkGeInitAssignRamToQueues(), removed call to
68  *      SkGeInitAssignRamToQueues in SkGeInit1 and fixed compiler warning in
69  *      SkGeInit1.
70  *
71  *      Revision 1.78  2002/10/16 15:55:07  mkarl
72  *      Fixed a bug in SkGeInitAssignRamToQueues.
73  *
74  *      Revision 1.77  2002/10/14 15:07:22  rschmidt
75  *      Corrected timeout handling for Rx queue in SkGeStopPort() (#10748)
76  *      Editorial changes.
77  *
78  *      Revision 1.76  2002/10/11 09:24:38  mkarl
79  *      Added check for HW self test results.
80  *
81  *      Revision 1.75  2002/10/09 16:56:44  mkarl
82  *      Now call SkGeInitAssignRamToQueues() in Init Level 1 in order to assign
83  *      the adapter memory to the queues. This default assignment is not suitable
84  *      for dual net mode.
85  *
86  *      Revision 1.74  2002/09/12 08:45:06  rwahl
87  *      Set defaults for PMSCap, PLinkSpeed & PLinkSpeedCap dependent on PHY.
88  *
89  *      Revision 1.73  2002/08/16 15:19:45  rschmidt
90  *      Corrected check for Tx queues in SkGeCheckQSize().
91  *      Added init for new entry GIGenesis and GICopperType
92  *      Replaced all if(GIChipId == CHIP_ID_GENESIS) with new entry GIGenesis.
93  *      Replaced wrong 1st para pAC with IoC in SK_IN/OUT macros.
94  *
95  *      Revision 1.72  2002/08/12 13:38:55  rschmidt
96  *      Added check if VAUX is available (stored in GIVauxAvail)
97  *      Initialized PLinkSpeedCap in Port struct with SK_LSPEED_CAP_1000MBPS
98  *      Editorial changes.
99  *
100  *      Revision 1.71  2002/08/08 16:32:58  rschmidt
101  *      Added check for Tx queues in SkGeCheckQSize().
102  *      Added start of Time Stamp Timer (YUKON) in SkGeInit2().
103  *      Editorial changes.
104  *
105  *      Revision 1.70  2002/07/23 16:04:26  rschmidt
106  *      Added init for GIWolOffs (HW-Bug in YUKON 1st rev.)
107  *      Minor changes
108  *
109  *      Revision 1.69  2002/07/17 17:07:08  rwahl
110  *      - SkGeInit1(): fixed PHY type debug output; corrected init of GIFunc
111  *        table & GIMacType.
112  *      - Editorial changes.
113  *
114  *      Revision 1.68  2002/07/15 18:38:31  rwahl
115  *      Added initialization for MAC type dependent function table.
116  *
117  *      Revision 1.67  2002/07/15 15:45:39  rschmidt
118  *      Added Tx Store & Forward for YUKON (GMAC Tx FIFO is only 1 kB)
119  *      Replaced SK_PHY_MARV by SK_PHY_MARV_COPPER
120  *      Editorial changes
121  *
122  *      Revision 1.66  2002/06/10 09:35:08  rschmidt
123  *      Replaced C++ comments (//)
124  *      Editorial changes
125  *
126  *      Revision 1.65  2002/06/05 08:33:37  rschmidt
127  *      Changed GIRamSize and Reset sequence for YUKON.
128  *      SkMacInit() replaced by SkXmInitMac() resp. SkGmInitMac()
129  *
130  *      Revision 1.64  2002/04/25 13:03:20  rschmidt
131  *      Changes for handling YUKON.
132  *      Removed reference to xmac_ii.h (not necessary).
133  *      Moved all defines into header file.
134  *      Replaced all SkXm...() functions with SkMac...() to handle also
135  *      YUKON's GMAC.
136  *      Added handling for GMAC FIFO in SkGeInitMacFifo(), SkGeStopPort().
137  *      Removed 'goto'-directive from SkGeCfgSync(), SkGeCheckQSize().
138  *      Replaced all XMAC-access macros by functions: SkMacRxTxDisable(),
139  *      SkMacFlushTxFifo().
140  *      Optimized timeout handling in SkGeStopPort().
141  *      Initialized PLinkSpeed in Port struct with SK_LSPEED_AUTO.
142  *      Release of GMAC Link Control reset in SkGeInit1().
143  *      Initialized GIChipId and GIChipRev in GE Init structure.
144  *      Added GIRamSize and PhyType values for YUKON.
145  *      Removed use of PRxCmd to setup XMAC.
146  *      Moved setting of XM_RX_DIS_CEXT to SkXmInitMac().
147  *      Use of SkGeXmitLED() only for GENESIS.
148  *      Changes for V-CPU support.
149  *      Editorial changes.
150  *
151  *      Revision 1.63  2001/04/05 11:02:09  rassmann
152  *      Stop Port check of the STOP bit did not take 2/18 sec as wanted.
153  *
154  *      Revision 1.62  2001/02/07 07:54:21  rassmann
155  *      Corrected copyright.
156  *
157  *      Revision 1.61  2001/01/31 15:31:40  gklug
158  *      fix: problem with autosensing an SR8800 switch
159  *
160  *      Revision 1.60  2000/10/18 12:22:21  cgoos
161  *      Added workaround for half duplex hangup.
162  *
163  *      Revision 1.59  2000/10/10 11:22:06  gklug
164  *      add: in manual half duplex mode ignore carrier extension errors
165  *
166  *      Revision 1.58  2000/10/02 14:10:27  rassmann
167  *      Reading BCOM PHY after releasing reset until it returns a valid value.
168  *
169  *      Revision 1.57  2000/08/03 14:55:28  rassmann
170  *      Waiting for I2C to be ready before de-initializing adapter
171  *      (prevents sensors from hanging up).
172  *
173  *      Revision 1.56  2000/07/27 12:16:48  gklug
174  *      fix: Stop Port check of the STOP bit does now take 2/18 sec as wanted
175  *
176  *      Revision 1.55  1999/11/22 13:32:26  cgoos
177  *      Changed license header to GPL.
178  *
179  *      Revision 1.54  1999/10/26 07:32:54  malthoff
180  *      Initialize PHWLinkUp with SK_FALSE. Required for Diagnostics.
181  *
182  *      Revision 1.53  1999/08/12 19:13:50  malthoff
183  *      Fix for 1000BT. Do not owerwrite XM_MMU_CMD when
184  *      disabling receiver and transmitter. Other bits
185  *      may be lost.
186  *
187  *      Revision 1.52  1999/07/01 09:29:54  gklug
188  *      fix: DoInitRamQueue needs pAC
189  *
190  *      Revision 1.51  1999/07/01 08:42:21  gklug
191  *      chg: use Store & forward for RAM buffer when Jumbos are used
192  *
193  *      Revision 1.50  1999/05/27 13:19:38  cgoos
194  *      Added Tx PCI watermark initialization.
195  *      Removed Tx RAM queue Store & Forward setting.
196  *
197  *      Revision 1.49  1999/05/20 14:32:45  malthoff
198  *      SkGeLinkLED() is completly removed now.
199  *
200  *      Revision 1.48  1999/05/19 07:28:24  cgoos
201  *      SkGeLinkLED no more available for drivers.
202  *      Changes for 1000Base-T.
203  *
204  *      Revision 1.47  1999/04/08 13:57:45  gklug
205  *      add: Init of new port struct fiels PLinkResCt
206  *      chg: StopPort Timer check
207  *
208  *      Revision 1.46  1999/03/25 07:42:15  malthoff
209  *      SkGeStopPort(): Add workaround for cache incoherency.
210  *                      Create error log entry, disable port, and
211  *                      exit loop if it does not terminate.
212  *      Add XM_RX_LENERR_OK to the default value for the
213  *      XMAC receive command register.
214  *
215  *      Revision 1.45  1999/03/12 16:24:47  malthoff
216  *      Remove PPollRxD and PPollTxD.
217  *      Add check for GIPollTimerVal.
218  *
219  *      Revision 1.44  1999/03/12 13:40:23  malthoff
220  *      Fix: SkGeXmitLED(), SK_LED_TST mode does not work.
221  *      Add: Jumbo frame support.
222  *      Chg: Resolution of parameter IntTime in SkGeCfgSync().
223  *
224  *      Revision 1.43  1999/02/09 10:29:46  malthoff
225  *      Bugfix: The previous modification again also for the second location.
226  *
227  *      Revision 1.42  1999/02/09 09:35:16  malthoff
228  *      Bugfix: The bits '66 MHz Capable' and 'NEWCAP are reset while
229  *              clearing the error bits in the PCI status register.
230  *
231  *      Revision 1.41  1999/01/18 13:07:02  malthoff
232  *      Bugfix: Do not use CFG cycles after during Init- or Runtime, because
233  *              they may not be available after Boottime.
234  *
235  *      Revision 1.40  1999/01/11 12:40:49  malthoff
236  *      Bug fix: PCI_STATUS: clearing error bits sets the UDF bit.
237  *
238  *      Revision 1.39  1998/12/11 15:17:33  gklug
239  *      chg: Init LipaAutoNeg with Unknown
240  *
241  *      Revision 1.38  1998/12/10 11:02:57  malthoff
242  *      Disable Error Log Message when calling SkGeInit(level 2)
243  *      more than once.
244  *
245  *      Revision 1.37  1998/12/07 12:18:25  gklug
246  *      add: refinement of autosense mode: take into account the autoneg cap of LiPa
247  *
248  *      Revision 1.36  1998/12/07 07:10:39  gklug
249  *      fix: init values of LinkBroken/ Capabilities for management
250  *
251  *      Revision 1.35  1998/12/02 10:56:20  gklug
252  *      fix: do NOT init LoinkSync Counter.
253  *
254  *      Revision 1.34  1998/12/01 10:53:21  gklug
255  *      add: init of additional Counters for workaround
256  *
257  *      Revision 1.33  1998/12/01 10:00:49  gklug
258  *      add: init PIsave var in Port struct
259  *
260  *      Revision 1.32  1998/11/26 14:50:40  gklug
261  *      chg: Default is autosensing with AUTOFULL mode
262  *
263  *      Revision 1.31  1998/11/25 15:36:16  gklug
264  *      fix: do NOT stop LED Timer when port should be stopped
265  *
266  *      Revision 1.30  1998/11/24 13:15:28  gklug
267  *      add: Init PCkeckPar struct member
268  *
269  *      Revision 1.29  1998/11/18 13:19:27  malthoff
270  *      Disable packet arbiter timeouts on receive side.
271  *      Use maximum timeout value for packet arbiter
272  *      transmit timeouts.
273  *      Add TestStopBit() function to handle stop RX/TX
274  *      problem with active descriptor poll timers.
275  *      Bug Fix: Descriptor Poll Timer not started, because
276  *      GIPollTimerVal was initialized with 0.
277  *
278  *      Revision 1.28  1998/11/13 14:24:26  malthoff
279  *      Bug Fix: SkGeStopPort() may hang if a Packet Arbiter Timout
280  *      is pending or occurs while waiting for TX_STOP and RX_STOP.
281  *      The PA timeout is cleared now while waiting for TX- or RX_STOP.
282  *
283  *      Revision 1.27  1998/11/02 11:04:36  malthoff
284  *      fix the last fix
285  *
286  *      Revision 1.26  1998/11/02 10:37:03  malthoff
287  *      Fix: SkGePollTxD() enables always the synchronounous poll timer.
288  *
289  *      Revision 1.25  1998/10/28 07:12:43  cgoos
290  *      Fixed "LED_STOP" in SkGeLnkSyncCnt, "== SK_INIT_IO" in SkGeInit.
291  *      Removed: Reset of RAM Interface in SkGeStopPort.
292  *
293  *      Revision 1.24  1998/10/27 08:13:12  malthoff
294  *      Remove temporary code.
295  *
296  *      Revision 1.23  1998/10/26 07:45:03  malthoff
297  *      Add Address Calculation Workaround: If the EPROM byte
298  *      Id is 3, the address offset is 512 kB.
299  *      Initialize default values for PLinkMode and PFlowCtrlMode.
300  *
301  *      Revision 1.22  1998/10/22 09:46:47  gklug
302  *      fix SysKonnectFileId typo
303  *
304  *      Revision 1.21  1998/10/20 12:11:56  malthoff
305  *      Don't dendy the Queue config if the size of the unused
306  *      Rx qeueu is zero.
307  *
308  *      Revision 1.20  1998/10/19 07:27:58  malthoff
309  *      SkGeInitRamIface() is public to be called by diagnostics.
310  *
311  *      Revision 1.19  1998/10/16 13:33:45  malthoff
312  *      Fix: enabling descriptor polling is not allowed until
313  *      the descriptor addresses are set. Descriptor polling
314  *      must be handled by the driver.
315  *
316  *      Revision 1.18  1998/10/16 10:58:27  malthoff
317  *      Remove temp. code for Diag prototype.
318  *      Remove lint warning for dummy reads.
319  *      Call SkGeLoadLnkSyncCnt() during SkGeInitPort().
320  *
321  *      Revision 1.17  1998/10/14 09:16:06  malthoff
322  *      Change parameter LimCount and programming of
323  *      the limit counter in SkGeCfgSync().
324  *
325  *      Revision 1.16  1998/10/13 09:21:16  malthoff
326  *      Don't set XM_RX_SELF_RX in RxCmd Reg, because it's
327  *      like a Loopback Mode in half duplex.
328  *
329  *      Revision 1.15  1998/10/09 06:47:40  malthoff
330  *      SkGeInitMacArb(): set recovery counters init value
331  *      to zero although this counters are not uesd.
332  *      Bug fix in Rx Upper/Lower Pause Threshold calculation.
333  *      Add XM_RX_SELF_RX to RxCmd.
334  *
335  *      Revision 1.14  1998/10/06 15:15:53  malthoff
336  *      Make sure no pending IRQ is cleared in SkGeLoadLnkSyncCnt().
337  *
338  *      Revision 1.13  1998/10/06 14:09:36  malthoff
339  *      Add SkGeLoadLnkSyncCnt(). Modify
340  *      the 'port stopped' condition according
341  *      to the current problem report.
342  *
343  *      Revision 1.12  1998/10/05 08:17:21  malthoff
344  *      Add functions: SkGePollRxD(), SkGePollTxD(),
345  *      DoCalcAddr(), SkGeCheckQSize(),
346  *      DoInitRamQueue(), and SkGeCfgSync().
347  *      Add coding for SkGeInitMacArb(), SkGeInitPktArb(),
348  *      SkGeInitMacFifo(), SkGeInitRamBufs(),
349  *      SkGeInitRamIface(), and SkGeInitBmu().
350  *
351  *      Revision 1.11  1998/09/29 08:26:29  malthoff
352  *      bug fix: SkGeInit0() 'i' should be increment.
353  *
354  *      Revision 1.10  1998/09/28 13:19:01  malthoff
355  *      Coding time: Save the done work.
356  *      Modify SkGeLinkLED(), add SkGeXmitLED(),
357  *      define SkGeCheckQSize(), SkGeInitMacArb(),
358  *      SkGeInitPktArb(), SkGeInitMacFifo(),
359  *      SkGeInitRamBufs(), SkGeInitRamIface(),
360  *      and SkGeInitBmu(). Do coding for SkGeStopPort(),
361  *      SkGeInit1(), SkGeInit2(), and SkGeInit3().
362  *      Do coding for SkGeDinit() and SkGeInitPort().
363  *
364  *      Revision 1.9  1998/09/16 14:29:05  malthoff
365  *      Some minor changes.
366  *
367  *      Revision 1.8  1998/09/11 05:29:14  gklug
368  *      add: init state of a port
369  *
370  *      Revision 1.7  1998/09/04 09:26:25  malthoff
371  *      Short temporary modification.
372  *
373  *      Revision 1.6  1998/09/04 08:27:59  malthoff
374  *      Remark the do-while in StopPort() because it never ends
375  *      without a GE adapter.
376  *
377  *      Revision 1.5  1998/09/03 14:05:45  malthoff
378  *      Change comment for SkGeInitPort(). Do not
379  *      repair the queue sizes if invalid.
380  *
381  *      Revision 1.4  1998/09/03 10:03:19  malthoff
382  *      Implement the new interface according to the
383  *      reviewed interface specification.
384  *
385  *      Revision 1.3  1998/08/19 09:11:25  gklug
386  *      fix: struct are removed from c-source (see CCC)
387  *
388  *      Revision 1.2  1998/07/28 12:33:58  malthoff
389  *      Add 'IoC' parameter in function declaration and SK IO macros.
390  *
391  *      Revision 1.1  1998/07/23 09:48:57  malthoff
392  *      Creation. First dummy 'C' file.
393  *      SkGeInit(Level 0) is card_start for GE.
394  *      SkGeDeInit() is card_stop for GE.
395  *
396  *
397  ******************************************************************************/
398
399 #include <config.h>
400
401 #include "h/skdrv1st.h"
402 #include "h/skdrv2nd.h"
403
404 /* global variables ***********************************************************/
405
406 /* local variables ************************************************************/
407
408 static const char SysKonnectFileId[] =
409         "@(#)$Id$ (C) SK ";
410
411 struct s_QOffTab {
412         int     RxQOff;         /* Receive Queue Address Offset */
413         int     XsQOff;         /* Sync Tx Queue Address Offset */
414         int     XaQOff;         /* Async Tx Queue Address Offset */
415 };
416 static struct s_QOffTab QOffTab[] = {
417         {Q_R1, Q_XS1, Q_XA1}, {Q_R2, Q_XS2, Q_XA2}
418 };
419
420
421 /******************************************************************************
422  *
423  *      SkGePollRxD() - Enable / Disable Descriptor Polling of RxD Ring
424  *
425  * Description:
426  *      Enable or disable the descriptor polling of the receive descriptor
427  *      ring (RxD) for port 'Port'.
428  *      The new configuration is *not* saved over any SkGeStopPort() and
429  *      SkGeInitPort() calls.
430  *
431  * Returns:
432  *      nothing
433  */
434 void SkGePollRxD(
435 SK_AC   *pAC,           /* adapter context */
436 SK_IOC  IoC,            /* IO context */
437 int             Port,           /* Port Index (MAC_1 + n) */
438 SK_BOOL PollRxD)        /* SK_TRUE (enable pol.), SK_FALSE (disable pol.) */
439 {
440         SK_GEPORT *pPrt;
441
442         pPrt = &pAC->GIni.GP[Port];
443
444         SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), (PollRxD) ?
445                 CSR_ENA_POL : CSR_DIS_POL);
446 }       /* SkGePollRxD */
447
448
449 /******************************************************************************
450  *
451  *      SkGePollTxD() - Enable / Disable Descriptor Polling of TxD Rings
452  *
453  * Description:
454  *      Enable or disable the descriptor polling of the transmit descriptor
455  *      ring(s) (TxD) for port 'Port'.
456  *      The new configuration is *not* saved over any SkGeStopPort() and
457  *      SkGeInitPort() calls.
458  *
459  * Returns:
460  *      nothing
461  */
462 void SkGePollTxD(
463 SK_AC   *pAC,           /* adapter context */
464 SK_IOC  IoC,            /* IO context */
465 int             Port,           /* Port Index (MAC_1 + n) */
466 SK_BOOL PollTxD)        /* SK_TRUE (enable pol.), SK_FALSE (disable pol.) */
467 {
468         SK_GEPORT *pPrt;
469         SK_U32  DWord;
470
471         pPrt = &pAC->GIni.GP[Port];
472
473         DWord = (PollTxD) ? CSR_ENA_POL : CSR_DIS_POL;
474
475         if (pPrt->PXSQSize != 0) {
476                 SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), DWord);
477         }
478
479         if (pPrt->PXAQSize != 0) {
480                 SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), DWord);
481         }
482 }       /* SkGePollTxD */
483
484
485 /******************************************************************************
486  *
487  *      SkGeYellowLED() - Switch the yellow LED on or off.
488  *
489  * Description:
490  *      Switch the yellow LED on or off.
491  *
492  * Note:
493  *      This function may be called any time after SkGeInit(Level 1).
494  *
495  * Returns:
496  *      nothing
497  */
498 void SkGeYellowLED(
499 SK_AC   *pAC,           /* adapter context */
500 SK_IOC  IoC,            /* IO context */
501 int             State)          /* yellow LED state, 0 = OFF, 0 != ON */
502 {
503         if (State == 0) {
504                 /* Switch yellow LED OFF */
505                 SK_OUT8(IoC, B0_LED, LED_STAT_OFF);
506         }
507         else {
508                 /* Switch yellow LED ON */
509                 SK_OUT8(IoC, B0_LED, LED_STAT_ON);
510         }
511 }       /* SkGeYellowLED */
512
513
514 /******************************************************************************
515  *
516  *      SkGeXmitLED() - Modify the Operational Mode of a transmission LED.
517  *
518  * Description:
519  *      The Rx or Tx LED which is specified by 'Led' will be
520  *      enabled, disabled or switched on in test mode.
521  *
522  * Note:
523  *      'Led' must contain the address offset of the LEDs INI register.
524  *
525  * Usage:
526  *      SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
527  *
528  * Returns:
529  *      nothing
530  */
531 void SkGeXmitLED(
532 SK_AC   *pAC,           /* adapter context */
533 SK_IOC  IoC,            /* IO context */
534 int             Led,            /* offset to the LED Init Value register */
535 int             Mode)           /* Mode may be SK_LED_DIS, SK_LED_ENA, SK_LED_TST */
536 {
537         SK_U32  LedIni;
538
539         switch (Mode) {
540         case SK_LED_ENA:
541                 LedIni = SK_XMIT_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
542                 SK_OUT32(IoC, Led + XMIT_LED_INI, LedIni);
543                 SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
544                 break;
545         case SK_LED_TST:
546                 SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_ON);
547                 SK_OUT32(IoC, Led + XMIT_LED_CNT, 100);
548                 SK_OUT8(IoC, Led + XMIT_LED_CTRL, LED_START);
549                 break;
550         case SK_LED_DIS:
551         default:
552                 /*
553                  * Do NOT stop the LED Timer here. The LED might be
554                  * in on state. But it needs to go off.
555                  */
556                 SK_OUT32(IoC, Led + XMIT_LED_CNT, 0);
557                 SK_OUT8(IoC, Led + XMIT_LED_TST, LED_T_OFF);
558                 break;
559         }
560
561         /*
562          * 1000BT: The Transmit LED is driven by the PHY.
563          * But the default LED configuration is used for
564          * Level One and Broadcom PHYs.
565          * (Broadcom: It may be that PHY_B_PEC_EN_LTR has to be set.)
566          * (In this case it has to be added here. But we will see. XXX)
567          */
568 }       /* SkGeXmitLED */
569
570
571 /******************************************************************************
572  *
573  *      DoCalcAddr() - Calculates the start and the end address of a queue.
574  *
575  * Description:
576  *      This function calculates the start and the end address of a queue.
577  *  Afterwards the 'StartVal' is incremented to the next start position.
578  *      If the port is already initialized the calculated values
579  *      will be checked against the configured values and an
580  *      error will be returned, if they are not equal.
581  *      If the port is not initialized the values will be written to
582  *      *StartAdr and *EndAddr.
583  *
584  * Returns:
585  *      0:      success
586  *      1:      configuration error
587  */
588 static int DoCalcAddr(
589 SK_AC           *pAC,                   /* adapter context */
590 SK_GEPORT       *pPrt,                  /* port index */
591 int                     QuSize,                 /* size of the queue to configure in kB */
592 SK_U32          *StartVal,              /* start value for address calculation */
593 SK_U32          *QuStartAddr,   /* start addr to calculate */
594 SK_U32          *QuEndAddr)             /* end address to calculate */
595 {
596         SK_U32  EndVal;
597         SK_U32  NextStart;
598         int             Rtv;
599
600         Rtv = 0;
601         if (QuSize == 0) {
602                 EndVal = *StartVal;
603                 NextStart = EndVal;
604         }
605         else {
606                 EndVal = *StartVal + ((SK_U32)QuSize * 1024) - 1;
607                 NextStart = EndVal + 1;
608         }
609
610         if (pPrt->PState >= SK_PRT_INIT) {
611                 if (*StartVal != *QuStartAddr || EndVal != *QuEndAddr) {
612                         Rtv = 1;
613                 }
614         }
615         else {
616                 *QuStartAddr = *StartVal;
617                 *QuEndAddr = EndVal;
618         }
619
620         *StartVal = NextStart;
621         return(Rtv);
622 }       /* DoCalcAddr */
623
624 /******************************************************************************
625  *
626  *      SkGeInitAssignRamToQueues() - allocate default queue sizes
627  *
628  * Description:
629  *      This function assigns the memory to the different queues and ports.
630  *      When DualNet is set to SK_TRUE all ports get the same amount of memory.
631  *  Otherwise the first port gets most of the memory and all the
632  *      other ports just the required minimum.
633  *      This function can only be called when pAC->GIni.GIRamSize and
634  *      pAC->GIni.GIMacsFound have been initialized, usually this happens
635  *      at init level 1
636  *
637  * Returns:
638  *      0 - ok
639  *      1 - invalid input values
640  *      2 - not enough memory
641  */
642
643 int SkGeInitAssignRamToQueues(
644 SK_AC   *pAC,                   /* Adapter context */
645 int             ActivePort,             /* Active Port in RLMT mode */
646 SK_BOOL DualNet)                /* adapter context */
647 {
648         int     i;
649         int     UsedKilobytes;                  /* memory already assigned */
650         int     ActivePortKilobytes;    /* memory available for active port */
651         SK_GEPORT *pGePort;
652
653         UsedKilobytes = 0;
654
655         if (ActivePort >= pAC->GIni.GIMacsFound) {
656                 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
657                         ("SkGeInitAssignRamToQueues: ActivePort (%d) invalid\n",
658                         ActivePort));
659                 return(1);
660         }
661         if (((pAC->GIni.GIMacsFound * (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE)) +
662                 ((RAM_QUOTA_SYNC == 0) ? 0 : SK_MIN_TXQ_SIZE)) > pAC->GIni.GIRamSize) {
663                 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
664                         ("SkGeInitAssignRamToQueues: Not enough memory (%d)\n",
665                          pAC->GIni.GIRamSize));
666                 return(2);
667         }
668
669
670         if (DualNet) {
671                 /* every port gets the same amount of memory */
672                 ActivePortKilobytes = pAC->GIni.GIRamSize / pAC->GIni.GIMacsFound;
673                 for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
674
675                         pGePort = &pAC->GIni.GP[i];
676
677                         /* take away the minimum memory for active queues */
678                         ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
679
680                         /* receive queue gets the minimum + 80% of the rest */
681                         pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((
682                                 ActivePortKilobytes * (unsigned long) RAM_QUOTA_RX) / 100))
683                                 + SK_MIN_RXQ_SIZE;
684
685                         ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
686
687                         /* synchronous transmit queue */
688                         pGePort->PXSQSize = 0;
689
690                         /* asynchronous transmit queue */
691                         pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes +
692                                 SK_MIN_TXQ_SIZE);
693                 }
694         }
695         else {
696                 /* Rlmt Mode or single link adapter */
697
698                 /* Set standby queue size defaults for all standby ports */
699                 for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
700
701                         if (i != ActivePort) {
702                                 pGePort = &pAC->GIni.GP[i];
703
704                                 pGePort->PRxQSize = SK_MIN_RXQ_SIZE;
705                                 pGePort->PXAQSize = SK_MIN_TXQ_SIZE;
706                                 pGePort->PXSQSize = 0;
707
708                                 /* Count used RAM */
709                                 UsedKilobytes += pGePort->PRxQSize + pGePort->PXAQSize;
710                         }
711                 }
712                 /* what's left? */
713                 ActivePortKilobytes = pAC->GIni.GIRamSize - UsedKilobytes;
714
715                 /* assign it to the active port */
716                 /* first take away the minimum memory */
717                 ActivePortKilobytes -= (SK_MIN_RXQ_SIZE + SK_MIN_TXQ_SIZE);
718                 pGePort = &pAC->GIni.GP[ActivePort];
719
720                 /* receive queue get's the minimum + 80% of the rest */
721                 pGePort->PRxQSize = (int) (ROUND_QUEUE_SIZE_KB((ActivePortKilobytes *
722                         (unsigned long) RAM_QUOTA_RX) / 100)) + SK_MIN_RXQ_SIZE;
723
724                 ActivePortKilobytes -= (pGePort->PRxQSize - SK_MIN_RXQ_SIZE);
725
726                 /* synchronous transmit queue */
727                 pGePort->PXSQSize = 0;
728
729                 /* asynchronous transmit queue */
730                 pGePort->PXAQSize = (int) ROUND_QUEUE_SIZE_KB(ActivePortKilobytes) +
731                         SK_MIN_TXQ_SIZE;
732         }
733 #ifdef VCPU
734         VCPUprintf(0, "PRxQSize=%u, PXSQSize=%u, PXAQSize=%u\n",
735                 pGePort->PRxQSize, pGePort->PXSQSize, pGePort->PXAQSize);
736 #endif /* VCPU */
737
738         return(0);
739 }       /* SkGeInitAssignRamToQueues */
740
741 /******************************************************************************
742  *
743  *      SkGeCheckQSize() - Checks the Adapters Queue Size Configuration
744  *
745  * Description:
746  *      This function verifies the Queue Size Configuration specified
747  *      in the variables PRxQSize, PXSQSize, and PXAQSize of all
748  *      used ports.
749  *      This requirements must be fullfilled to have a valid configuration:
750  *              - The size of all queues must not exceed GIRamSize.
751  *              - The queue sizes must be specified in units of 8 kB.
752  *              - The size of Rx queues of available ports must not be
753  *                smaller than 16 kB.
754  *              - The size of at least one Tx queue (synch. or asynch.)
755  *        of available ports must not be smaller than 16 kB
756  *        when Jumbo Frames are used.
757  *              - The RAM start and end addresses must not be changed
758  *                for ports which are already initialized.
759  *      Furthermore SkGeCheckQSize() defines the Start and End Addresses
760  *  of all ports and stores them into the HWAC port     structure.
761  *
762  * Returns:
763  *      0:      Queue Size Configuration valid
764  *      1:      Queue Size Configuration invalid
765  */
766 static int SkGeCheckQSize(
767 SK_AC    *pAC,          /* adapter context */
768 int              Port)          /* port index */
769 {
770         SK_GEPORT *pPrt;
771         int     UsedMem;        /* total memory used (max. found ports) */
772         int     i;
773         int     Rtv;
774         int     Rtv2;
775         SK_U32  StartAddr;
776
777         UsedMem = 0;
778         Rtv = 0;
779         for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
780                 pPrt = &pAC->GIni.GP[i];
781
782                 if ((pPrt->PRxQSize & QZ_UNITS) != 0 ||
783                         (pPrt->PXSQSize & QZ_UNITS) != 0 ||
784                         (pPrt->PXAQSize & QZ_UNITS) != 0) {
785
786                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
787                         return(1);
788                 }
789
790                 if (i == Port && pPrt->PRxQSize < SK_MIN_RXQ_SIZE) {
791                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E011, SKERR_HWI_E011MSG);
792                         return(1);
793                 }
794
795                 /*
796                  * the size of at least one Tx queue (synch. or asynch.) has to be > 0.
797                  * if Jumbo Frames are used, this size has to be >= 16 kB.
798                  */
799                 if ((i == Port && pPrt->PXSQSize == 0 && pPrt->PXAQSize == 0) ||
800                         (pAC->GIni.GIPortUsage == SK_JUMBO_LINK &&
801             ((pPrt->PXSQSize > 0 && pPrt->PXSQSize < SK_MIN_TXQ_SIZE) ||
802                          (pPrt->PXAQSize > 0 && pPrt->PXAQSize < SK_MIN_TXQ_SIZE)))) {
803                                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E023, SKERR_HWI_E023MSG);
804                                 return(1);
805                 }
806
807                 UsedMem += pPrt->PRxQSize + pPrt->PXSQSize + pPrt->PXAQSize;
808         }
809
810         if (UsedMem > pAC->GIni.GIRamSize) {
811                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E012, SKERR_HWI_E012MSG);
812                 return(1);
813         }
814
815         /* Now start address calculation */
816         StartAddr = pAC->GIni.GIRamOffs;
817         for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
818                 pPrt = &pAC->GIni.GP[i];
819
820                 /* Calculate/Check values for the receive queue */
821                 Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PRxQSize, &StartAddr,
822                         &pPrt->PRxQRamStart, &pPrt->PRxQRamEnd);
823                 Rtv |= Rtv2;
824
825                 /* Calculate/Check values for the synchronous Tx queue */
826                 Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXSQSize, &StartAddr,
827                         &pPrt->PXsQRamStart, &pPrt->PXsQRamEnd);
828                 Rtv |= Rtv2;
829
830                 /* Calculate/Check values for the asynchronous Tx queue */
831                 Rtv2 = DoCalcAddr(pAC, pPrt, pPrt->PXAQSize, &StartAddr,
832                         &pPrt->PXaQRamStart, &pPrt->PXaQRamEnd);
833                 Rtv |= Rtv2;
834
835                 if (Rtv) {
836                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E013, SKERR_HWI_E013MSG);
837                         return(1);
838                 }
839         }
840
841         return(0);
842 }       /* SkGeCheckQSize */
843
844
845 /******************************************************************************
846  *
847  *      SkGeInitMacArb() - Initialize the MAC Arbiter
848  *
849  * Description:
850  *      This function initializes the MAC Arbiter.
851  *      It must not be called if there is still an
852  *      initialized or active port.
853  *
854  * Returns:
855  *      nothing
856  */
857 static void SkGeInitMacArb(
858 SK_AC   *pAC,           /* adapter context */
859 SK_IOC  IoC)            /* IO context */
860 {
861         /* release local reset */
862         SK_OUT16(IoC, B3_MA_TO_CTRL, MA_RST_CLR);
863
864         /* configure timeout values */
865         SK_OUT8(IoC, B3_MA_TOINI_RX1, SK_MAC_TO_53);
866         SK_OUT8(IoC, B3_MA_TOINI_RX2, SK_MAC_TO_53);
867         SK_OUT8(IoC, B3_MA_TOINI_TX1, SK_MAC_TO_53);
868         SK_OUT8(IoC, B3_MA_TOINI_TX2, SK_MAC_TO_53);
869
870         SK_OUT8(IoC, B3_MA_RCINI_RX1, 0);
871         SK_OUT8(IoC, B3_MA_RCINI_RX2, 0);
872         SK_OUT8(IoC, B3_MA_RCINI_TX1, 0);
873         SK_OUT8(IoC, B3_MA_RCINI_TX2, 0);
874
875         /* recovery values are needed for XMAC II Rev. B2 only */
876         /* Fast Output Enable Mode was intended to use with Rev. B2, but now? */
877
878         /*
879          * There is no start or enable button to push, therefore
880          * the MAC arbiter is configured and enabled now.
881          */
882 }       /* SkGeInitMacArb */
883
884
885 /******************************************************************************
886  *
887  *      SkGeInitPktArb() - Initialize the Packet Arbiter
888  *
889  * Description:
890  *      This function initializes the Packet Arbiter.
891  *      It must not be called if there is still an
892  *      initialized or active port.
893  *
894  * Returns:
895  *      nothing
896  */
897 static void SkGeInitPktArb(
898 SK_AC   *pAC,           /* adapter context */
899 SK_IOC  IoC)            /* IO context */
900 {
901         /* release local reset */
902         SK_OUT16(IoC, B3_PA_CTRL, PA_RST_CLR);
903
904         /* configure timeout values */
905         SK_OUT16(IoC, B3_PA_TOINI_RX1, SK_PKT_TO_MAX);
906         SK_OUT16(IoC, B3_PA_TOINI_RX2, SK_PKT_TO_MAX);
907         SK_OUT16(IoC, B3_PA_TOINI_TX1, SK_PKT_TO_MAX);
908         SK_OUT16(IoC, B3_PA_TOINI_TX2, SK_PKT_TO_MAX);
909
910         /*
911          * enable timeout timers if jumbo frames not used
912          * NOTE: the packet arbiter timeout interrupt is needed for
913          * half duplex hangup workaround
914          */
915         if (pAC->GIni.GIPortUsage != SK_JUMBO_LINK) {
916                 if (pAC->GIni.GIMacsFound == 1) {
917                         SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1);
918                 }
919                 else {
920                         SK_OUT16(IoC, B3_PA_CTRL, PA_ENA_TO_TX1 | PA_ENA_TO_TX2);
921                 }
922         }
923 }       /* SkGeInitPktArb */
924
925
926 /******************************************************************************
927  *
928  *      SkGeInitMacFifo() - Initialize the MAC FIFOs
929  *
930  * Description:
931  *      Initialize all MAC FIFOs of the specified port
932  *
933  * Returns:
934  *      nothing
935  */
936 static void SkGeInitMacFifo(
937 SK_AC   *pAC,           /* adapter context */
938 SK_IOC  IoC,            /* IO context */
939 int             Port)           /* Port Index (MAC_1 + n) */
940 {
941         SK_U16  Word;
942 #ifdef VCPU
943         SK_U32  DWord;
944 #endif /* VCPU */
945         /*
946          * For each FIFO:
947          *      - release local reset
948          *      - use default value for MAC FIFO size
949          *      - setup defaults for the control register
950          *      - enable the FIFO
951          */
952
953         Word = GMF_RX_CTRL_DEF;
954
955         if (pAC->GIni.GIGenesis) {
956                 /* Configure Rx MAC FIFO */
957                 SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_CLR);
958                 SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_RX_CTRL_DEF);
959                 SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_ENA_OP_MD);
960
961                 /* Configure Tx MAC FIFO */
962                 SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_CLR);
963                 SK_OUT16(IoC, MR_ADDR(Port, TX_MFF_CTRL1), MFF_TX_CTRL_DEF);
964                 SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_ENA_OP_MD);
965
966                 /* Enable frame flushing if jumbo frames used */
967                 if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK) {
968                         SK_OUT16(IoC, MR_ADDR(Port, RX_MFF_CTRL1), MFF_ENA_FLUSH);
969                 }
970         }
971         else {
972                 /* set Rx GMAC FIFO Flush Mask */
973                 SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_MSK), (SK_U16)RX_FF_FL_DEF_MSK);
974
975                 if (pAC->GIni.GIYukonLite && pAC->GIni.GIChipId == CHIP_ID_YUKON) {
976
977                         Word &= ~GMF_RX_F_FL_ON;
978                 }
979
980                 /* Configure Rx MAC FIFO */
981                 SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
982                 SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), Word);
983
984                 /* set Rx GMAC FIFO Flush Threshold (default: 0x0a -> 56 bytes) */
985                 SK_OUT16(IoC, MR_ADDR(Port, RX_GMF_FL_THR), RX_GMF_FL_THR_DEF);
986
987                 /* Configure Tx MAC FIFO */
988                 SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_CLR);
989                 SK_OUT16(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U16)GMF_TX_CTRL_DEF);
990
991 #ifdef VCPU
992                 SK_IN32(IoC, MR_ADDR(Port, RX_GMF_AF_THR), &DWord);
993                 SK_IN32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), &DWord);
994 #endif /* VCPU */
995
996                 /* set Tx GMAC FIFO Almost Empty Threshold */
997 /*              SK_OUT32(IoC, MR_ADDR(Port, TX_GMF_AE_THR), 0); */
998         }
999 }       /* SkGeInitMacFifo */
1000
1001
1002 /******************************************************************************
1003  *
1004  *      SkGeLoadLnkSyncCnt() - Load the Link Sync Counter and starts counting
1005  *
1006  * Description:
1007  *      This function starts the Link Sync Counter of the specified
1008  *      port and enables the generation of an Link Sync IRQ.
1009  *      The Link Sync Counter may be used to detect an active link,
1010  *      if autonegotiation is not used.
1011  *
1012  * Note:
1013  *      o To ensure receiving the Link Sync Event the LinkSyncCounter
1014  *        should be initialized BEFORE clearing the XMAC's reset!
1015  *      o Enable IS_LNK_SYNC_M1 and IS_LNK_SYNC_M2 after calling this
1016  *        function.
1017  *
1018  * Returns:
1019  *      nothing
1020  */
1021 void SkGeLoadLnkSyncCnt(
1022 SK_AC   *pAC,           /* adapter context */
1023 SK_IOC  IoC,            /* IO context */
1024 int             Port,           /* Port Index (MAC_1 + n) */
1025 SK_U32  CntVal)         /* Counter value */
1026 {
1027         SK_U32  OrgIMsk;
1028         SK_U32  NewIMsk;
1029         SK_U32  ISrc;
1030         SK_BOOL IrqPend;
1031
1032         /* stop counter */
1033         SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_STOP);
1034
1035         /*
1036          * ASIC problem:
1037          * Each time starting the Link Sync Counter an IRQ is generated
1038          * by the adapter. See problem report entry from 21.07.98
1039          *
1040          * Workaround:  Disable Link Sync IRQ and clear the unexpeced IRQ
1041          *              if no IRQ is already pending.
1042          */
1043         IrqPend = SK_FALSE;
1044         SK_IN32(IoC, B0_ISRC, &ISrc);
1045         SK_IN32(IoC, B0_IMSK, &OrgIMsk);
1046         if (Port == MAC_1) {
1047                 NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M1;
1048                 if ((ISrc & IS_LNK_SYNC_M1) != 0) {
1049                         IrqPend = SK_TRUE;
1050                 }
1051         }
1052         else {
1053                 NewIMsk = OrgIMsk & ~IS_LNK_SYNC_M2;
1054                 if ((ISrc & IS_LNK_SYNC_M2) != 0) {
1055                         IrqPend = SK_TRUE;
1056                 }
1057         }
1058         if (!IrqPend) {
1059                 SK_OUT32(IoC, B0_IMSK, NewIMsk);
1060         }
1061
1062         /* load counter */
1063         SK_OUT32(IoC, MR_ADDR(Port, LNK_SYNC_INI), CntVal);
1064
1065         /* start counter */
1066         SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_START);
1067
1068         if (!IrqPend) {
1069                 /* clear the unexpected IRQ, and restore the interrupt mask */
1070                 SK_OUT8(IoC, MR_ADDR(Port, LNK_SYNC_CTRL), LED_CLR_IRQ);
1071                 SK_OUT32(IoC, B0_IMSK, OrgIMsk);
1072         }
1073 }       /* SkGeLoadLnkSyncCnt*/
1074
1075
1076 /******************************************************************************
1077  *
1078  *      SkGeCfgSync() - Configure synchronous bandwidth for this port.
1079  *
1080  * Description:
1081  *      This function may be used to configure synchronous bandwidth
1082  *      to the specified port. This may be done any time after
1083  *      initializing the port. The configuration values are NOT saved
1084  *      in the HWAC port structure and will be overwritten any
1085  *      time when stopping and starting the port.
1086  *      Any values for the synchronous configuration will be ignored
1087  *      if the size of the synchronous queue is zero!
1088  *
1089  *      The default configuration for the synchronous service is
1090  *      TXA_ENA_FSYNC. This means if the size of
1091  *      the synchronous queue is unequal zero but no specific
1092  *      synchronous bandwidth is configured, the synchronous queue
1093  *      will always have the 'unlimited' transmit priority!
1094  *
1095  *      This mode will be restored if the synchronous bandwidth is
1096  *      deallocated ('IntTime' = 0 and 'LimCount' = 0).
1097  *
1098  * Returns:
1099  *      0:      success
1100  *      1:      parameter configuration error
1101  *      2:      try to configure quality of service although no
1102  *              synchronous queue is configured
1103  */
1104 int SkGeCfgSync(
1105 SK_AC   *pAC,           /* adapter context */
1106 SK_IOC  IoC,            /* IO context */
1107 int             Port,           /* Port Index (MAC_1 + n) */
1108 SK_U32  IntTime,        /* Interval Timer Value in units of 8ns */
1109 SK_U32  LimCount,       /* Number of bytes to transfer during IntTime */
1110 int             SyncMode)       /* Sync Mode: TXA_ENA_ALLOC | TXA_DIS_ALLOC | 0 */
1111 {
1112         int Rtv;
1113
1114         Rtv = 0;
1115
1116         /* check the parameters */
1117         if (LimCount > IntTime ||
1118                 (LimCount == 0 && IntTime != 0) ||
1119                 (LimCount != 0 && IntTime == 0)) {
1120
1121                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
1122                 return(1);
1123         }
1124
1125         if (pAC->GIni.GP[Port].PXSQSize == 0) {
1126                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E009, SKERR_HWI_E009MSG);
1127                 return(2);
1128         }
1129
1130         /* calculate register values */
1131         IntTime = (IntTime / 2) * pAC->GIni.GIHstClkFact / 100;
1132         LimCount = LimCount / 8;
1133
1134         if (IntTime > TXA_MAX_VAL || LimCount > TXA_MAX_VAL) {
1135                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E010, SKERR_HWI_E010MSG);
1136                 return(1);
1137         }
1138
1139         /*
1140          * - Enable 'Force Sync' to ensure the synchronous queue
1141          *   has the priority while configuring the new values.
1142          * - Also 'disable alloc' to ensure the settings complies
1143          *   to the SyncMode parameter.
1144          * - Disable 'Rate Control' to configure the new values.
1145          * - write IntTime and LimCount
1146          * - start 'Rate Control' and disable 'Force Sync'
1147          *   if Interval Timer or Limit Counter not zero.
1148          */
1149         SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
1150                 TXA_ENA_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
1151
1152         SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), IntTime);
1153         SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), LimCount);
1154
1155         SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
1156                 (SK_U8)(SyncMode & (TXA_ENA_ALLOC | TXA_DIS_ALLOC)));
1157
1158         if (IntTime != 0 || LimCount != 0) {
1159                 SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_DIS_FSYNC | TXA_START_RC);
1160         }
1161
1162         return(0);
1163 }       /* SkGeCfgSync */
1164
1165
1166 /******************************************************************************
1167  *
1168  *      DoInitRamQueue() - Initialize the RAM Buffer Address of a single Queue
1169  *
1170  * Desccription:
1171  *      If the queue is used, enable and initialize it.
1172  *      Make sure the queue is still reset, if it is not used.
1173  *
1174  * Returns:
1175  *      nothing
1176  */
1177 static void DoInitRamQueue(
1178 SK_AC   *pAC,                   /* adapter context */
1179 SK_IOC  IoC,                    /* IO context */
1180 int             QuIoOffs,               /* Queue IO Address Offset */
1181 SK_U32  QuStartAddr,    /* Queue Start Address */
1182 SK_U32  QuEndAddr,              /* Queue End Address */
1183 int             QuType)                 /* Queue Type (SK_RX_SRAM_Q|SK_RX_BRAM_Q|SK_TX_RAM_Q) */
1184 {
1185         SK_U32  RxUpThresVal;
1186         SK_U32  RxLoThresVal;
1187
1188         if (QuStartAddr != QuEndAddr) {
1189                 /* calculate thresholds, assume we have a big Rx queue */
1190                 RxUpThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_ULPP) / 8;
1191                 RxLoThresVal = (QuEndAddr + 1 - QuStartAddr - SK_RB_LLPP_B)/8;
1192
1193                 /* build HW address format */
1194                 QuStartAddr = QuStartAddr / 8;
1195                 QuEndAddr = QuEndAddr / 8;
1196
1197                 /* release local reset */
1198                 SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_CLR);
1199
1200                 /* configure addresses */
1201                 SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_START), QuStartAddr);
1202                 SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_END), QuEndAddr);
1203                 SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_WP), QuStartAddr);
1204                 SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RP), QuStartAddr);
1205
1206                 switch (QuType) {
1207                 case SK_RX_SRAM_Q:
1208                         /* configure threshold for small Rx Queue */
1209                         RxLoThresVal += (SK_RB_LLPP_B - SK_RB_LLPP_S) / 8;
1210
1211                         /* continue with SK_RX_BRAM_Q */
1212                 case SK_RX_BRAM_Q:
1213                         /* write threshold for Rx Queue */
1214
1215                         SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_UTPP), RxUpThresVal);
1216                         SK_OUT32(IoC, RB_ADDR(QuIoOffs, RB_RX_LTPP), RxLoThresVal);
1217
1218                         /* the high priority threshold not used */
1219                         break;
1220                 case SK_TX_RAM_Q:
1221                         /*
1222                          * Do NOT use Store & Forward under normal operation due to
1223                          * performance optimization (GENESIS only).
1224                          * But if Jumbo Frames are configured (XMAC Tx FIFO is only 4 kB)
1225                          * or YUKON is used ((GMAC Tx FIFO is only 1 kB)
1226                          * we NEED Store & Forward of the RAM buffer.
1227                          */
1228                         if (pAC->GIni.GIPortUsage == SK_JUMBO_LINK ||
1229                                 !pAC->GIni.GIGenesis) {
1230                                 /* enable Store & Forward Mode for the Tx Side */
1231                                 SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_STFWD);
1232                         }
1233                         break;
1234                 }
1235
1236                 /* set queue operational */
1237                 SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_ENA_OP_MD);
1238         }
1239         else {
1240                 /* ensure the queue is still disabled */
1241                 SK_OUT8(IoC, RB_ADDR(QuIoOffs, RB_CTRL), RB_RST_SET);
1242         }
1243 }       /* DoInitRamQueue */
1244
1245
1246 /******************************************************************************
1247  *
1248  *      SkGeInitRamBufs() - Initialize the RAM Buffer Queues
1249  *
1250  * Description:
1251  *      Initialize all RAM Buffer Queues of the specified port
1252  *
1253  * Returns:
1254  *      nothing
1255  */
1256 static void SkGeInitRamBufs(
1257 SK_AC   *pAC,           /* adapter context */
1258 SK_IOC  IoC,            /* IO context */
1259 int             Port)           /* Port Index (MAC_1 + n) */
1260 {
1261         SK_GEPORT *pPrt;
1262         int RxQType;
1263
1264         pPrt = &pAC->GIni.GP[Port];
1265
1266         if (pPrt->PRxQSize == SK_MIN_RXQ_SIZE) {
1267                 RxQType = SK_RX_SRAM_Q;         /* small Rx Queue */
1268         } else {
1269                 RxQType = SK_RX_BRAM_Q;         /* big Rx Queue */
1270         }
1271
1272         DoInitRamQueue(pAC, IoC, pPrt->PRxQOff, pPrt->PRxQRamStart,
1273                 pPrt->PRxQRamEnd, RxQType);
1274
1275         DoInitRamQueue(pAC, IoC, pPrt->PXsQOff, pPrt->PXsQRamStart,
1276                 pPrt->PXsQRamEnd, SK_TX_RAM_Q);
1277
1278         DoInitRamQueue(pAC, IoC, pPrt->PXaQOff, pPrt->PXaQRamStart,
1279                 pPrt->PXaQRamEnd, SK_TX_RAM_Q);
1280
1281 }       /* SkGeInitRamBufs */
1282
1283
1284 /******************************************************************************
1285  *
1286  *      SkGeInitRamIface() - Initialize the RAM Interface
1287  *
1288  * Description:
1289  *      This function initializes the Adapters RAM Interface.
1290  *
1291  * Note:
1292  *      This function is used in the diagnostics.
1293  *
1294  * Returns:
1295  *      nothing
1296  */
1297 void SkGeInitRamIface(
1298 SK_AC   *pAC,           /* adapter context */
1299 SK_IOC  IoC)            /* IO context */
1300 {
1301         /* release local reset */
1302         SK_OUT16(IoC, B3_RI_CTRL, RI_RST_CLR);
1303
1304         /* configure timeout values */
1305         SK_OUT8(IoC, B3_RI_WTO_R1, SK_RI_TO_53);
1306         SK_OUT8(IoC, B3_RI_WTO_XA1, SK_RI_TO_53);
1307         SK_OUT8(IoC, B3_RI_WTO_XS1, SK_RI_TO_53);
1308         SK_OUT8(IoC, B3_RI_RTO_R1, SK_RI_TO_53);
1309         SK_OUT8(IoC, B3_RI_RTO_XA1, SK_RI_TO_53);
1310         SK_OUT8(IoC, B3_RI_RTO_XS1, SK_RI_TO_53);
1311         SK_OUT8(IoC, B3_RI_WTO_R2, SK_RI_TO_53);
1312         SK_OUT8(IoC, B3_RI_WTO_XA2, SK_RI_TO_53);
1313         SK_OUT8(IoC, B3_RI_WTO_XS2, SK_RI_TO_53);
1314         SK_OUT8(IoC, B3_RI_RTO_R2, SK_RI_TO_53);
1315         SK_OUT8(IoC, B3_RI_RTO_XA2, SK_RI_TO_53);
1316         SK_OUT8(IoC, B3_RI_RTO_XS2, SK_RI_TO_53);
1317
1318 }       /* SkGeInitRamIface */
1319
1320
1321 /******************************************************************************
1322  *
1323  *      SkGeInitBmu() - Initialize the BMU state machines
1324  *
1325  * Description:
1326  *      Initialize all BMU state machines of the specified port
1327  *
1328  * Returns:
1329  *      nothing
1330  */
1331 static void SkGeInitBmu(
1332 SK_AC   *pAC,           /* adapter context */
1333 SK_IOC  IoC,            /* IO context */
1334 int             Port)           /* Port Index (MAC_1 + n) */
1335 {
1336         SK_GEPORT       *pPrt;
1337         SK_U32          RxWm;
1338         SK_U32          TxWm;
1339
1340         pPrt = &pAC->GIni.GP[Port];
1341
1342         RxWm = SK_BMU_RX_WM;
1343         TxWm = SK_BMU_TX_WM;
1344
1345         if (!pAC->GIni.GIPciSlot64 && !pAC->GIni.GIPciClock66) {
1346                 /* for better performance */
1347                 RxWm /= 2;
1348                 TxWm /= 2;
1349         }
1350
1351         /* Rx Queue: Release all local resets and set the watermark */
1352         SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_CLR_RESET);
1353         SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_F), RxWm);
1354
1355         /*
1356          * Tx Queue: Release all local resets if the queue is used !
1357          *              set watermark
1358          */
1359         if (pPrt->PXSQSize != 0) {
1360                 SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_CLR_RESET);
1361                 SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_F), TxWm);
1362         }
1363
1364         if (pPrt->PXAQSize != 0) {
1365                 SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_CLR_RESET);
1366                 SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_F), TxWm);
1367         }
1368         /*
1369          * Do NOT enable the descriptor poll timers here, because
1370          * the descriptor addresses are not specified yet.
1371          */
1372 }       /* SkGeInitBmu */
1373
1374
1375 /******************************************************************************
1376  *
1377  *      TestStopBit() - Test the stop bit of the queue
1378  *
1379  * Description:
1380  *      Stopping a queue is not as simple as it seems to be.
1381  *      If descriptor polling is enabled, it may happen
1382  *      that RX/TX stop is done and SV idle is NOT set.
1383  *      In this case we have to issue another stop command.
1384  *
1385  * Returns:
1386  *      The queues control status register
1387  */
1388 static SK_U32 TestStopBit(
1389 SK_AC   *pAC,           /* Adapter Context */
1390 SK_IOC  IoC,            /* IO Context */
1391 int             QuIoOffs)       /* Queue IO Address Offset */
1392 {
1393         SK_U32  QuCsr;  /* CSR contents */
1394
1395         SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
1396
1397         if ((QuCsr & (CSR_STOP | CSR_SV_IDLE)) == 0) {
1398                 /* Stop Descriptor overridden by start command */
1399                 SK_OUT32(IoC, Q_ADDR(QuIoOffs, Q_CSR), CSR_STOP);
1400
1401                 SK_IN32(IoC, Q_ADDR(QuIoOffs, Q_CSR), &QuCsr);
1402         }
1403
1404         return(QuCsr);
1405 }       /* TestStopBit */
1406
1407
1408 /******************************************************************************
1409  *
1410  *      SkGeStopPort() - Stop the Rx/Tx activity of the port 'Port'.
1411  *
1412  * Description:
1413  *      After calling this function the descriptor rings and Rx and Tx
1414  *      queues of this port may be reconfigured.
1415  *
1416  *      It is possible to stop the receive and transmit path separate or
1417  *      both together.
1418  *
1419  *      Dir =   SK_STOP_TX      Stops the transmit path only and resets the MAC.
1420  *                              The receive queue is still active and
1421  *                              the pending Rx frames may be still transferred
1422  *                              into the RxD.
1423  *              SK_STOP_RX      Stop the receive path. The tansmit path
1424  *                              has to be stopped once before.
1425  *              SK_STOP_ALL     SK_STOP_TX + SK_STOP_RX
1426  *
1427  *      RstMode = SK_SOFT_RST   Resets the MAC. The PHY is still alive.
1428  *                      SK_HARD_RST     Resets the MAC and the PHY.
1429  *
1430  * Example:
1431  *      1) A Link Down event was signaled for a port. Therefore the activity
1432  *      of this port should be stopped and a hardware reset should be issued
1433  *      to enable the workaround of XMAC errata #2. But the received frames
1434  *      should not be discarded.
1435  *              ...
1436  *              SkGeStopPort(pAC, IoC, Port, SK_STOP_TX, SK_HARD_RST);
1437  *              (transfer all pending Rx frames)
1438  *              SkGeStopPort(pAC, IoC, Port, SK_STOP_RX, SK_HARD_RST);
1439  *              ...
1440  *
1441  *      2) An event was issued which request the driver to switch
1442  *      the 'virtual active' link to an other already active port
1443  *      as soon as possible. The frames in the receive queue of this
1444  *      port may be lost. But the PHY must not be reset during this
1445  *      event.
1446  *              ...
1447  *              SkGeStopPort(pAC, IoC, Port, SK_STOP_ALL, SK_SOFT_RST);
1448  *              ...
1449  *
1450  * Extended Description:
1451  *      If SK_STOP_TX is set,
1452  *              o disable the MAC's receive and transmitter to prevent
1453  *                from sending incomplete frames
1454  *              o stop the port's transmit queues before terminating the
1455  *                BMUs to prevent from performing incomplete PCI cycles
1456  *                on the PCI bus
1457  *              - The network Rx and Tx activity and PCI Tx transfer is
1458  *                disabled now.
1459  *              o reset the MAC depending on the RstMode
1460  *              o Stop Interval Timer and Limit Counter of Tx Arbiter,
1461  *                also disable Force Sync bit and Enable Alloc bit.
1462  *              o perform a local reset of the port's Tx path
1463  *                      - reset the PCI FIFO of the async Tx queue
1464  *                      - reset the PCI FIFO of the sync Tx queue
1465  *                      - reset the RAM Buffer async Tx queue
1466  *                      - reset the RAM Buffer sync Tx queue
1467  *                      - reset the MAC Tx FIFO
1468  *              o switch Link and Tx LED off, stop the LED counters
1469  *
1470  *      If SK_STOP_RX is set,
1471  *              o stop the port's receive queue
1472  *              - The path data transfer activity is fully stopped now.
1473  *              o perform a local reset of the port's Rx path
1474  *                      - reset the PCI FIFO of the Rx queue
1475  *                      - reset the RAM Buffer receive queue
1476  *                      - reset the MAC Rx FIFO
1477  *              o switch Rx LED off, stop the LED counter
1478  *
1479  *      If all ports are stopped,
1480  *              o reset the RAM Interface.
1481  *
1482  * Notes:
1483  *      o This function may be called during the driver states RESET_PORT and
1484  *        SWITCH_PORT.
1485  */
1486 void SkGeStopPort(
1487 SK_AC   *pAC,   /* adapter context */
1488 SK_IOC  IoC,    /* I/O context */
1489 int             Port,   /* port to stop (MAC_1 + n) */
1490 int             Dir,    /* Direction to Stop (SK_STOP_RX, SK_STOP_TX, SK_STOP_ALL) */
1491 int             RstMode)/* Reset Mode (SK_SOFT_RST, SK_HARD_RST) */
1492 {
1493 #ifndef SK_DIAG
1494         SK_EVPARA Para;
1495 #endif /* !SK_DIAG */
1496         SK_GEPORT *pPrt;
1497         SK_U32  DWord;
1498         SK_U32  XsCsr;
1499         SK_U32  XaCsr;
1500         SK_U64  ToutStart;
1501         int             i;
1502         int             ToutCnt;
1503
1504         pPrt = &pAC->GIni.GP[Port];
1505
1506         if ((Dir & SK_STOP_TX) != 0) {
1507                 /* disable receiver and transmitter */
1508                 SkMacRxTxDisable(pAC, IoC, Port);
1509
1510                 /* stop both transmit queues */
1511                 /*
1512                  * If the BMU is in the reset state CSR_STOP will terminate
1513                  * immediately.
1514                  */
1515                 SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_STOP);
1516                 SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_STOP);
1517
1518                 ToutStart = SkOsGetTime(pAC);
1519                 ToutCnt = 0;
1520                 do {
1521                         /*
1522                          * Clear packet arbiter timeout to make sure
1523                          * this loop will terminate.
1524                          */
1525                         SK_OUT16(IoC, B3_PA_CTRL, (Port == MAC_1) ? PA_CLR_TO_TX1 :
1526                                 PA_CLR_TO_TX2);
1527
1528                         /*
1529                          * If the transfer stucks at the MAC the STOP command will not
1530                          * terminate if we don't flush the XMAC's transmit FIFO !
1531                          */
1532                         SkMacFlushTxFifo(pAC, IoC, Port);
1533
1534                         XsCsr = TestStopBit(pAC, IoC, pPrt->PXsQOff);
1535                         XaCsr = TestStopBit(pAC, IoC, pPrt->PXaQOff);
1536
1537                         if (SkOsGetTime(pAC) - ToutStart > (SK_TICKS_PER_SEC / 18)) {
1538                                 /*
1539                                  * Timeout of 1/18 second reached.
1540                                  * This needs to be checked at 1/18 sec only.
1541                                  */
1542                                 ToutCnt++;
1543                                 if (ToutCnt > 1) {
1544                                         /* Might be a problem when the driver event handler
1545                                          * calls StopPort again. XXX.
1546                                          */
1547
1548                                         /* Fatal Error, Loop aborted */
1549                                         SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E018,
1550                                                 SKERR_HWI_E018MSG);
1551 #ifndef SK_DIAG
1552                                         Para.Para64 = Port;
1553                                         SkEventQueue(pAC, SKGE_DRV, SK_DRV_PORT_FAIL, Para);
1554 #endif /* !SK_DIAG */
1555                                         return;
1556                                 }
1557                                 /*
1558                                  * Cache incoherency workaround: Assume a start command
1559                                  * has been lost while sending the frame.
1560                                  */
1561                                 ToutStart = SkOsGetTime(pAC);
1562
1563                                 if ((XsCsr & CSR_STOP) != 0) {
1564                                         SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_START);
1565                                 }
1566                                 if ((XaCsr & CSR_STOP) != 0) {
1567                                         SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_START);
1568                                 }
1569                         }
1570
1571                         /*
1572                          * Because of the ASIC problem report entry from 21.08.1998 it is
1573                          * required to wait until CSR_STOP is reset and CSR_SV_IDLE is set.
1574                          */
1575                 } while ((XsCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE ||
1576                                  (XaCsr & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
1577
1578                 /* Reset the MAC depending on the RstMode */
1579                 if (RstMode == SK_SOFT_RST) {
1580                         SkMacSoftRst(pAC, IoC, Port);
1581                 }
1582                 else {
1583                         SkMacHardRst(pAC, IoC, Port);
1584                 }
1585
1586                 /* Disable Force Sync bit and Enable Alloc bit */
1587                 SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL),
1588                         TXA_DIS_FSYNC | TXA_DIS_ALLOC | TXA_STOP_RC);
1589
1590                 /* Stop Interval Timer and Limit Counter of Tx Arbiter */
1591                 SK_OUT32(IoC, MR_ADDR(Port, TXA_ITI_INI), 0L);
1592                 SK_OUT32(IoC, MR_ADDR(Port, TXA_LIM_INI), 0L);
1593
1594                 /* Perform a local reset of the port's Tx path */
1595
1596                 /* Reset the PCI FIFO of the async Tx queue */
1597                 SK_OUT32(IoC, Q_ADDR(pPrt->PXaQOff, Q_CSR), CSR_SET_RESET);
1598                 /* Reset the PCI FIFO of the sync Tx queue */
1599                 SK_OUT32(IoC, Q_ADDR(pPrt->PXsQOff, Q_CSR), CSR_SET_RESET);
1600                 /* Reset the RAM Buffer async Tx queue */
1601                 SK_OUT8(IoC, RB_ADDR(pPrt->PXaQOff, RB_CTRL), RB_RST_SET);
1602                 /* Reset the RAM Buffer sync Tx queue */
1603                 SK_OUT8(IoC, RB_ADDR(pPrt->PXsQOff, RB_CTRL), RB_RST_SET);
1604
1605                 /* Reset Tx MAC FIFO */
1606                 if (pAC->GIni.GIGenesis) {
1607                         /* Note: MFF_RST_SET does NOT reset the XMAC ! */
1608                         SK_OUT8(IoC, MR_ADDR(Port, TX_MFF_CTRL2), MFF_RST_SET);
1609
1610                         /* switch Link and Tx LED off, stop the LED counters */
1611                         /* Link LED is switched off by the RLMT and the Diag itself */
1612                         SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_DIS);
1613                 }
1614                 else {
1615                         /* Reset TX MAC FIFO */
1616                         SK_OUT8(IoC, MR_ADDR(Port, TX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
1617                 }
1618         }
1619
1620         if ((Dir & SK_STOP_RX) != 0) {
1621                 /*
1622                  * The RX Stop Command will not terminate if no buffers
1623                  * are queued in the RxD ring. But it will always reach
1624                  * the Idle state. Therefore we can use this feature to
1625                  * stop the transfer of received packets.
1626                  */
1627                 /* stop the port's receive queue */
1628                 SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_STOP);
1629
1630                 i = 100;
1631                 do {
1632                         /*
1633                          * Clear packet arbiter timeout to make sure
1634                          * this loop will terminate
1635                          */
1636                         SK_OUT16(IoC, B3_PA_CTRL, (Port == MAC_1) ? PA_CLR_TO_RX1 :
1637                                 PA_CLR_TO_RX2);
1638
1639                         DWord = TestStopBit(pAC, IoC, pPrt->PRxQOff);
1640
1641                         /* timeout if i==0 (bug fix for #10748) */
1642                         if (--i == 0) {
1643                                 SK_ERR_LOG(pAC, SK_ERRCL_HW, SKERR_HWI_E024,
1644                                         SKERR_HWI_E024MSG);
1645                                 break;
1646                         }
1647                         /*
1648                          * because of the ASIC problem report entry from 21.08.98
1649                          * it is required to wait until CSR_STOP is reset and
1650                          * CSR_SV_IDLE is set.
1651                          */
1652                 } while ((DWord & (CSR_STOP | CSR_SV_IDLE)) != CSR_SV_IDLE);
1653
1654                 /* The path data transfer activity is fully stopped now */
1655
1656                 /* Perform a local reset of the port's Rx path */
1657
1658                  /*     Reset the PCI FIFO of the Rx queue */
1659                 SK_OUT32(IoC, Q_ADDR(pPrt->PRxQOff, Q_CSR), CSR_SET_RESET);
1660                 /* Reset the RAM Buffer receive queue */
1661                 SK_OUT8(IoC, RB_ADDR(pPrt->PRxQOff, RB_CTRL), RB_RST_SET);
1662
1663                 /* Reset Rx MAC FIFO */
1664                 if (pAC->GIni.GIGenesis) {
1665
1666                         SK_OUT8(IoC, MR_ADDR(Port, RX_MFF_CTRL2), MFF_RST_SET);
1667
1668                         /* switch Rx LED off, stop the LED counter */
1669                         SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_DIS);
1670                 }
1671                 else {
1672                         /* Reset Rx MAC FIFO */
1673                         SK_OUT8(IoC, MR_ADDR(Port, RX_GMF_CTRL_T), (SK_U8)GMF_RST_SET);
1674                 }
1675         }
1676 }       /* SkGeStopPort */
1677
1678
1679 /******************************************************************************
1680  *
1681  *      SkGeInit0() - Level 0 Initialization
1682  *
1683  * Description:
1684  *      - Initialize the BMU address offsets
1685  *
1686  * Returns:
1687  *      nothing
1688  */
1689 static void SkGeInit0(
1690 SK_AC   *pAC,           /* adapter context */
1691 SK_IOC  IoC)            /* IO context */
1692 {
1693         int i;
1694         SK_GEPORT *pPrt;
1695
1696         for (i = 0; i < SK_MAX_MACS; i++) {
1697                 pPrt = &pAC->GIni.GP[i];
1698
1699                 pPrt->PState = SK_PRT_RESET;
1700                 pPrt->PRxQOff = QOffTab[i].RxQOff;
1701                 pPrt->PXsQOff = QOffTab[i].XsQOff;
1702                 pPrt->PXaQOff = QOffTab[i].XaQOff;
1703                 pPrt->PCheckPar = SK_FALSE;
1704                 pPrt->PIsave = 0;
1705                 pPrt->PPrevShorts = 0;
1706                 pPrt->PLinkResCt = 0;
1707                 pPrt->PAutoNegTOCt = 0;
1708                 pPrt->PPrevRx = 0;
1709                 pPrt->PPrevFcs = 0;
1710                 pPrt->PRxLim = SK_DEF_RX_WA_LIM;
1711                 pPrt->PLinkMode = SK_LMODE_AUTOFULL;
1712                 pPrt->PLinkSpeedCap = SK_LSPEED_CAP_1000MBPS;
1713                 pPrt->PLinkSpeed = SK_LSPEED_1000MBPS;
1714                 pPrt->PLinkSpeedUsed = SK_LSPEED_STAT_UNKNOWN;
1715                 pPrt->PLinkModeConf = SK_LMODE_AUTOSENSE;
1716                 pPrt->PFlowCtrlMode = SK_FLOW_MODE_SYM_OR_REM;
1717                 pPrt->PLinkBroken = SK_TRUE; /* See WA code */
1718                 pPrt->PLinkCap = (SK_LMODE_CAP_HALF | SK_LMODE_CAP_FULL |
1719                                 SK_LMODE_CAP_AUTOHALF | SK_LMODE_CAP_AUTOFULL);
1720                 pPrt->PLinkModeStatus = SK_LMODE_STAT_UNKNOWN;
1721                 pPrt->PFlowCtrlCap = SK_FLOW_MODE_SYM_OR_REM;
1722                 pPrt->PFlowCtrlStatus = SK_FLOW_STAT_NONE;
1723                 pPrt->PMSCap = 0;
1724                 pPrt->PMSMode = SK_MS_MODE_AUTO;
1725                 pPrt->PMSStatus = SK_MS_STAT_UNSET;
1726                 pPrt->PAutoNegFail = SK_FALSE;
1727                 pPrt->PLipaAutoNeg = SK_LIPA_UNKNOWN;
1728                 pPrt->PHWLinkUp = SK_FALSE;
1729         }
1730
1731         pAC->GIni.GIPortUsage = SK_RED_LINK;
1732
1733 }       /* SkGeInit0*/
1734
1735 #ifdef SK_PCI_RESET
1736
1737 /******************************************************************************
1738  *
1739  *      SkGePciReset() - Reset PCI interface
1740  *
1741  * Description:
1742  *      o Read PCI configuration.
1743  *      o Change power state to 3.
1744  *      o Change power state to 0.
1745  *      o Restore PCI configuration.
1746  *
1747  * Returns:
1748  *      0:      Success.
1749  *      1:      Power state could not be changed to 3.
1750  */
1751 static int SkGePciReset(
1752 SK_AC   *pAC,           /* adapter context */
1753 SK_IOC  IoC)            /* IO context */
1754 {
1755         int             i;
1756         SK_U16  PmCtlSts;
1757         SK_U32  Bp1;
1758         SK_U32  Bp2;
1759         SK_U16  PciCmd;
1760         SK_U8   Cls;
1761         SK_U8   Lat;
1762         SK_U8   ConfigSpace[PCI_CFG_SIZE];
1763
1764         /*
1765          * Note: Switching to D3 state is like a software reset.
1766          *               Switching from D3 to D0 is a hardware reset.
1767          *               We have to save and restore the configuration space.
1768          */
1769         for (i = 0; i < PCI_CFG_SIZE; i++) {
1770                 SkPciReadCfgDWord(pAC, i*4, &ConfigSpace[i]);
1771         }
1772
1773         /* We know the RAM Interface Arbiter is enabled. */
1774         SkPciWriteCfgWord(pAC, PCI_PM_CTL_STS, PCI_PM_STATE_D3);
1775         SkPciReadCfgWord(pAC, PCI_PM_CTL_STS, &PmCtlSts);
1776
1777         if ((PmCtlSts & PCI_PM_STATE_MSK) != PCI_PM_STATE_D3) {
1778                 return(1);
1779         }
1780
1781         /* Return to D0 state. */
1782         SkPciWriteCfgWord(pAC, PCI_PM_CTL_STS, PCI_PM_STATE_D0);
1783
1784         /* Check for D0 state. */
1785         SkPciReadCfgWord(pAC, PCI_PM_CTL_STS, &PmCtlSts);
1786
1787         if ((PmCtlSts & PCI_PM_STATE_MSK) != PCI_PM_STATE_D0) {
1788                 return(1);
1789         }
1790
1791         /* Check PCI Config Registers. */
1792         SkPciReadCfgWord(pAC, PCI_COMMAND, &PciCmd);
1793         SkPciReadCfgByte(pAC, PCI_CACHE_LSZ, &Cls);
1794         SkPciReadCfgDWord(pAC, PCI_BASE_1ST, &Bp1);
1795         SkPciReadCfgDWord(pAC, PCI_BASE_2ND, &Bp2);
1796         SkPciReadCfgByte(pAC, PCI_LAT_TIM, &Lat);
1797
1798         if (PciCmd != 0 || Cls != 0 || (Bp1 & 0xfffffff0L) != 0 || Bp2 != 1 ||
1799                 Lat != 0) {
1800                 return(1);
1801         }
1802
1803         /* Restore PCI Config Space. */
1804         for (i = 0; i < PCI_CFG_SIZE; i++) {
1805                 SkPciWriteCfgDWord(pAC, i*4, ConfigSpace[i]);
1806         }
1807
1808         return(0);
1809 }       /* SkGePciReset */
1810
1811 #endif /* SK_PCI_RESET */
1812
1813 /******************************************************************************
1814  *
1815  *      SkGeInit1() - Level 1 Initialization
1816  *
1817  * Description:
1818  *      o Do a software reset.
1819  *      o Clear all reset bits.
1820  *      o Verify that the detected hardware is present.
1821  *        Return an error if not.
1822  *      o Get the hardware configuration
1823  *              + Read the number of MACs/Ports.
1824  *              + Read the RAM size.
1825  *              + Read the PCI Revision Id.
1826  *              + Find out the adapters host clock speed
1827  *              + Read and check the PHY type
1828  *
1829  * Returns:
1830  *      0:      success
1831  *      5:      Unexpected PHY type detected
1832  *      6:      HW self test failed
1833  */
1834 static int SkGeInit1(
1835 SK_AC   *pAC,           /* adapter context */
1836 SK_IOC  IoC)            /* IO context */
1837 {
1838         SK_U8   Byte;
1839         SK_U16  Word;
1840         SK_U16  CtrlStat;
1841         SK_U32  FlashAddr;
1842         int     RetVal;
1843         int     i;
1844
1845         RetVal = 0;
1846
1847         /* save CLK_RUN bits (YUKON-Lite) */
1848         SK_IN16(IoC, B0_CTST, &CtrlStat);
1849
1850 #ifdef SK_PCI_RESET
1851         (void)SkGePciReset(pAC, IoC);
1852 #endif /* SK_PCI_RESET */
1853
1854         /* do the SW-reset */
1855         SK_OUT8(IoC, B0_CTST, CS_RST_SET);
1856
1857         /* release the SW-reset */
1858         SK_OUT8(IoC, B0_CTST, CS_RST_CLR);
1859
1860         /* reset all error bits in the PCI STATUS register */
1861         /*
1862          * Note: PCI Cfg cycles cannot be used, because they are not
1863          *               available on some platforms after 'boot time'.
1864          */
1865         SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
1866
1867         SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
1868         SK_OUT16(IoC, PCI_C(PCI_STATUS), Word | PCI_ERRBITS);
1869         SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
1870
1871         /* release Master Reset */
1872         SK_OUT8(IoC, B0_CTST, CS_MRST_CLR);
1873
1874 #ifdef CLK_RUN
1875         CtrlStat |= CS_CLK_RUN_ENA;
1876 #endif /* CLK_RUN */
1877
1878         /* restore CLK_RUN bits */
1879         SK_OUT16(IoC, B0_CTST, CtrlStat &
1880                 (CS_CLK_RUN_HOT | CS_CLK_RUN_RST | CS_CLK_RUN_ENA));
1881
1882         /* read Chip Identification Number */
1883         SK_IN8(IoC, B2_CHIP_ID, &Byte);
1884         pAC->GIni.GIChipId = Byte;
1885
1886         /* read number of MACs */
1887         SK_IN8(IoC, B2_MAC_CFG, &Byte);
1888         pAC->GIni.GIMacsFound = (Byte & CONFIG_SYS_SNG_MAC) ? 1 : 2;
1889
1890         /* get Chip Revision Number */
1891         pAC->GIni.GIChipRev = (SK_U8)((Byte & CONFIG_SYS_CHIP_R_MSK) >> 4);
1892
1893         /* get diff. PCI parameters */
1894         SK_IN16(IoC, B0_CTST, &CtrlStat);
1895
1896         /* read the adapters RAM size */
1897         SK_IN8(IoC, B2_E_0, &Byte);
1898
1899         if (pAC->GIni.GIChipId == CHIP_ID_GENESIS) {
1900
1901                 pAC->GIni.GIGenesis = SK_TRUE;
1902
1903                 if (Byte == 3) {
1904                         /* special case: 4 x 64k x 36, offset = 0x80000 */
1905                         pAC->GIni.GIRamSize = 1024;
1906                         pAC->GIni.GIRamOffs = (SK_U32)512 * 1024;
1907                 }
1908                 else {
1909                         pAC->GIni.GIRamSize = (int)Byte * 512;
1910                         pAC->GIni.GIRamOffs = 0;
1911                 }
1912                 /* all GE adapters work with 53.125 MHz host clock */
1913                 pAC->GIni.GIHstClkFact = SK_FACT_53;
1914
1915                 /* set Descr. Poll Timer Init Value to 250 ms */
1916                 pAC->GIni.GIPollTimerVal =
1917                         SK_DPOLL_DEF * (SK_U32)pAC->GIni.GIHstClkFact / 100;
1918         }
1919         else {
1920                 pAC->GIni.GIGenesis = SK_FALSE;
1921
1922 #ifndef VCPU
1923                 pAC->GIni.GIRamSize = (Byte == 0) ? 128 : (int)Byte * 4;
1924 #else
1925                 pAC->GIni.GIRamSize = 128;
1926 #endif
1927                 pAC->GIni.GIRamOffs = 0;
1928
1929                 /* WA for chip Rev. A */
1930                 pAC->GIni.GIWolOffs = (pAC->GIni.GIChipRev == 0) ? WOL_REG_OFFS : 0;
1931
1932                 /* get PM Capabilities of PCI config space */
1933                 SK_IN16(IoC, PCI_C(PCI_PM_CAP_REG), &Word);
1934
1935                 /* check if VAUX is available */
1936                 if (((CtrlStat & CS_VAUX_AVAIL) != 0) &&
1937                         /* check also if PME from D3cold is set */
1938                         ((Word & PCI_PME_D3C_SUP) != 0)) {
1939                         /* set entry in GE init struct */
1940                         pAC->GIni.GIVauxAvail = SK_TRUE;
1941                 }
1942
1943                 /* save Flash-Address Register */
1944                 SK_IN32(IoC, B2_FAR, &FlashAddr);
1945
1946                 /* test Flash-Address Register */
1947                 SK_OUT8(IoC, B2_FAR + 3, 0xff);
1948                 SK_IN8(IoC, B2_FAR + 3, &Byte);
1949
1950                 pAC->GIni.GIYukonLite = (SK_BOOL)(Byte != 0);
1951
1952                 /* restore Flash-Address Register */
1953                 SK_OUT32(IoC, B2_FAR, FlashAddr);
1954
1955                 for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
1956                         /* set GMAC Link Control reset */
1957                         SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_SET);
1958
1959                         /* clear GMAC Link Control reset */
1960                         SK_OUT16(IoC, MR_ADDR(i, GMAC_LINK_CTRL), GMLC_RST_CLR);
1961                 }
1962                 /* all YU chips work with 78.125 MHz host clock */
1963                 pAC->GIni.GIHstClkFact = SK_FACT_78;
1964
1965                 pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX;        /* 215 ms */
1966         }
1967
1968         /* check if 64-bit PCI Slot is present */
1969         pAC->GIni.GIPciSlot64 = (SK_BOOL)((CtrlStat & CS_BUS_SLOT_SZ) != 0);
1970
1971         /* check if 66 MHz PCI Clock is active */
1972         pAC->GIni.GIPciClock66 = (SK_BOOL)((CtrlStat & CS_BUS_CLOCK) != 0);
1973
1974         /* read PCI HW Revision Id. */
1975         SK_IN8(IoC, PCI_C(PCI_REV_ID), &Byte);
1976         pAC->GIni.GIPciHwRev = Byte;
1977
1978         /* read the PMD type */
1979         SK_IN8(IoC, B2_PMD_TYP, &Byte);
1980         pAC->GIni.GICopperType = (SK_U8)(Byte == 'T');
1981
1982         /* read the PHY type */
1983         SK_IN8(IoC, B2_E_1, &Byte);
1984
1985         Byte &= 0x0f;   /* the PHY type is stored in the lower nibble */
1986         for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
1987
1988                 if (pAC->GIni.GIGenesis) {
1989                         switch (Byte) {
1990                         case SK_PHY_XMAC:
1991                                 pAC->GIni.GP[i].PhyAddr = PHY_ADDR_XMAC;
1992                                 break;
1993                         case SK_PHY_BCOM:
1994                                 pAC->GIni.GP[i].PhyAddr = PHY_ADDR_BCOM;
1995                                 pAC->GIni.GP[i].PMSCap =
1996                                         SK_MS_CAP_AUTO | SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE;
1997                                 break;
1998 #ifdef OTHER_PHY
1999                         case SK_PHY_LONE:
2000                                 pAC->GIni.GP[i].PhyAddr = PHY_ADDR_LONE;
2001                                 break;
2002                         case SK_PHY_NAT:
2003                                 pAC->GIni.GP[i].PhyAddr = PHY_ADDR_NAT;
2004                                 break;
2005 #endif /* OTHER_PHY */
2006                         default:
2007                                 /* ERROR: unexpected PHY type detected */
2008                                 RetVal = 5;
2009                                 break;
2010                         }
2011                 }
2012                 else {
2013                         if (Byte == 0) {
2014                                 /* if this field is not initialized */
2015                                 Byte = SK_PHY_MARV_COPPER;
2016                                 pAC->GIni.GICopperType = SK_TRUE;
2017                         }
2018                         pAC->GIni.GP[i].PhyAddr = PHY_ADDR_MARV;
2019
2020                         if (pAC->GIni.GICopperType) {
2021                                 pAC->GIni.GP[i].PLinkSpeedCap = SK_LSPEED_CAP_AUTO |
2022                                         SK_LSPEED_CAP_10MBPS | SK_LSPEED_CAP_100MBPS |
2023                                         SK_LSPEED_CAP_1000MBPS;
2024                                 pAC->GIni.GP[i].PLinkSpeed = SK_LSPEED_AUTO;
2025                                 pAC->GIni.GP[i].PMSCap =
2026                                         SK_MS_CAP_AUTO | SK_MS_CAP_MASTER | SK_MS_CAP_SLAVE;
2027                         }
2028                         else {
2029                                 Byte = SK_PHY_MARV_FIBER;
2030                         }
2031                 }
2032
2033                 pAC->GIni.GP[i].PhyType = Byte;
2034
2035                 SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
2036                         ("PHY type: %d  PHY addr: %04x\n", Byte,
2037                         pAC->GIni.GP[i].PhyAddr));
2038         }
2039
2040         /* get Mac Type & set function pointers dependent on */
2041         if (pAC->GIni.GIGenesis) {
2042                 pAC->GIni.GIMacType = SK_MAC_XMAC;
2043
2044                 pAC->GIni.GIFunc.pFnMacUpdateStats      = SkXmUpdateStats;
2045                 pAC->GIni.GIFunc.pFnMacStatistic        = SkXmMacStatistic;
2046                 pAC->GIni.GIFunc.pFnMacResetCounter     = SkXmResetCounter;
2047                 pAC->GIni.GIFunc.pFnMacOverflow         = SkXmOverflowStatus;
2048         }
2049         else {
2050                 pAC->GIni.GIMacType = SK_MAC_GMAC;
2051
2052                 pAC->GIni.GIFunc.pFnMacUpdateStats      = SkGmUpdateStats;
2053                 pAC->GIni.GIFunc.pFnMacStatistic        = SkGmMacStatistic;
2054                 pAC->GIni.GIFunc.pFnMacResetCounter     = SkGmResetCounter;
2055                 pAC->GIni.GIFunc.pFnMacOverflow         = SkGmOverflowStatus;
2056
2057 #ifdef SPECIAL_HANDLING
2058                 if (pAC->GIni.GIChipId == CHIP_ID_YUKON) {
2059                         /* check HW self test result */
2060                         SK_IN8(IoC, B2_E_3, &Byte);
2061                         if ((Byte & B2_E3_RES_MASK) != 0) {
2062                                 RetVal = 6;
2063                         }
2064                 }
2065 #endif
2066         }
2067         return(RetVal);
2068 }       /* SkGeInit1 */
2069
2070
2071 /******************************************************************************
2072  *
2073  *      SkGeInit2() - Level 2 Initialization
2074  *
2075  * Description:
2076  *      - start the Blink Source Counter
2077  *      - start the Descriptor Poll Timer
2078  *      - configure the MAC-Arbiter
2079  *      - configure the Packet-Arbiter
2080  *      - enable the Tx Arbiters
2081  *      - enable the RAM Interface Arbiter
2082  *
2083  * Returns:
2084  *      nothing
2085  */
2086 static void SkGeInit2(
2087 SK_AC   *pAC,           /* adapter context */
2088 SK_IOC  IoC)            /* IO context */
2089 {
2090         SK_U32  DWord;
2091         int             i;
2092
2093         /* start the Descriptor Poll Timer */
2094         if (pAC->GIni.GIPollTimerVal != 0) {
2095                 if (pAC->GIni.GIPollTimerVal > SK_DPOLL_MAX) {
2096                         pAC->GIni.GIPollTimerVal = SK_DPOLL_MAX;
2097
2098                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E017, SKERR_HWI_E017MSG);
2099                 }
2100                 SK_OUT32(IoC, B28_DPT_INI, pAC->GIni.GIPollTimerVal);
2101                 SK_OUT8(IoC, B28_DPT_CTRL, DPT_START);
2102         }
2103
2104         if (pAC->GIni.GIGenesis) {
2105                 /* start the Blink Source Counter */
2106                 DWord = SK_BLK_DUR * (SK_U32)pAC->GIni.GIHstClkFact / 100;
2107
2108                 SK_OUT32(IoC, B2_BSC_INI, DWord);
2109                 SK_OUT8(IoC, B2_BSC_CTRL, BSC_START);
2110
2111                 /*
2112                  * Configure the MAC Arbiter and the Packet Arbiter.
2113                  * They will be started once and never be stopped.
2114                  */
2115                 SkGeInitMacArb(pAC, IoC);
2116
2117                 SkGeInitPktArb(pAC, IoC);
2118         }
2119         else {
2120                 /* start Time Stamp Timer */
2121                 SK_OUT8(IoC, GMAC_TI_ST_CTRL, (SK_U8)GMT_ST_START);
2122         }
2123
2124         /* enable the Tx Arbiters */
2125         for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
2126                 SK_OUT8(IoC, MR_ADDR(i, TXA_CTRL), TXA_ENA_ARB);
2127         }
2128
2129         /* enable the RAM Interface Arbiter */
2130         SkGeInitRamIface(pAC, IoC);
2131
2132 }       /* SkGeInit2 */
2133
2134 /******************************************************************************
2135  *
2136  *      SkGeInit() - Initialize the GE Adapter with the specified level.
2137  *
2138  * Description:
2139  *      Level   0:      Initialize the Module structures.
2140  *      Level   1:      Generic Hardware Initialization. The IOP/MemBase pointer has
2141  *                              to be set before calling this level.
2142  *
2143  *                      o Do a software reset.
2144  *                      o Clear all reset bits.
2145  *                      o Verify that the detected hardware is present.
2146  *                        Return an error if not.
2147  *                      o Get the hardware configuration
2148  *                              + Set GIMacsFound with the number of MACs.
2149  *                              + Store the RAM size in GIRamSize.
2150  *                              + Save the PCI Revision ID in GIPciHwRev.
2151  *                      o return an error
2152  *                              if Number of MACs > SK_MAX_MACS
2153  *
2154  *                      After returning from Level 0 the adapter
2155  *                      may be accessed with IO operations.
2156  *
2157  *      Level   2:      start the Blink Source Counter
2158  *
2159  * Returns:
2160  *      0:      success
2161  *      1:      Number of MACs exceeds SK_MAX_MACS      (after level 1)
2162  *      2:      Adapter not present or not accessible
2163  *      3:      Illegal initialization level
2164  *      4:      Initialization Level 1 Call missing
2165  *      5:      Unexpected PHY type detected
2166  *      6:      HW self test failed
2167  */
2168 int     SkGeInit(
2169 SK_AC   *pAC,           /* adapter context */
2170 SK_IOC  IoC,            /* IO context */
2171 int             Level)          /* initialization level */
2172 {
2173         int             RetVal;         /* return value */
2174         SK_U32  DWord;
2175
2176         RetVal = 0;
2177         SK_DBG_MSG(pAC, SK_DBGMOD_HWM, SK_DBGCAT_INIT,
2178                 ("SkGeInit(Level %d)\n", Level));
2179
2180         switch (Level) {
2181         case SK_INIT_DATA:
2182                 /* Initialization Level 0 */
2183                 SkGeInit0(pAC, IoC);
2184                 pAC->GIni.GILevel = SK_INIT_DATA;
2185                 break;
2186
2187         case SK_INIT_IO:
2188                 /* Initialization Level 1 */
2189                 RetVal = SkGeInit1(pAC, IoC);
2190                 if (RetVal != 0) {
2191                         break;
2192                 }
2193
2194                 /* check if the adapter seems to be accessible */
2195                 SK_OUT32(IoC, B2_IRQM_INI, 0x11335577L);
2196                 SK_IN32(IoC, B2_IRQM_INI, &DWord);
2197                 SK_OUT32(IoC, B2_IRQM_INI, 0L);
2198
2199                 if (DWord != 0x11335577L) {
2200                         RetVal = 2;
2201                         break;
2202                 }
2203
2204                 /* check if the number of GIMacsFound matches SK_MAX_MACS */
2205                 if (pAC->GIni.GIMacsFound > SK_MAX_MACS) {
2206                         RetVal = 1;
2207                         break;
2208                 }
2209
2210                 /* Level 1 successfully passed */
2211                 pAC->GIni.GILevel = SK_INIT_IO;
2212                 break;
2213
2214         case SK_INIT_RUN:
2215                 /* Initialization Level 2 */
2216                 if (pAC->GIni.GILevel != SK_INIT_IO) {
2217 #ifndef SK_DIAG
2218                         SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E002, SKERR_HWI_E002MSG);
2219 #endif /* !SK_DIAG */
2220                         RetVal = 4;
2221                         break;
2222                 }
2223                 SkGeInit2(pAC, IoC);
2224
2225                 /* Level 2 successfully passed */
2226                 pAC->GIni.GILevel = SK_INIT_RUN;
2227                 break;
2228
2229         default:
2230                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E003, SKERR_HWI_E003MSG);
2231                 RetVal = 3;
2232                 break;
2233         }
2234
2235         return(RetVal);
2236 }       /* SkGeInit */
2237
2238
2239 /******************************************************************************
2240  *
2241  *      SkGeDeInit() - Deinitialize the adapter
2242  *
2243  * Description:
2244  *      All ports of the adapter will be stopped if not already done.
2245  *      Do a software reset and switch off all LEDs.
2246  *
2247  * Returns:
2248  *      nothing
2249  */
2250 void SkGeDeInit(
2251 SK_AC   *pAC,           /* adapter context */
2252 SK_IOC  IoC)            /* IO context */
2253 {
2254         int     i;
2255         SK_U16  Word;
2256
2257 #ifndef VCPU
2258         /* ensure I2C is ready */
2259         SkI2cWaitIrq(pAC, IoC);
2260 #endif
2261
2262         /* stop all current transfer activity */
2263         for (i = 0; i < pAC->GIni.GIMacsFound; i++) {
2264                 if (pAC->GIni.GP[i].PState != SK_PRT_STOP &&
2265                         pAC->GIni.GP[i].PState != SK_PRT_RESET) {
2266
2267                         SkGeStopPort(pAC, IoC, i, SK_STOP_ALL, SK_HARD_RST);
2268                 }
2269         }
2270
2271         /* Reset all bits in the PCI STATUS register */
2272         /*
2273          * Note: PCI Cfg cycles cannot be used, because they are not
2274          *       available on some platforms after 'boot time'.
2275          */
2276         SK_IN16(IoC, PCI_C(PCI_STATUS), &Word);
2277
2278         SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_ON);
2279         SK_OUT16(IoC, PCI_C(PCI_STATUS), Word | PCI_ERRBITS);
2280         SK_OUT8(IoC, B2_TST_CTRL1, TST_CFG_WRITE_OFF);
2281
2282         /* do the reset, all LEDs are switched off now */
2283         SK_OUT8(IoC, B0_CTST, CS_RST_SET);
2284 }       /* SkGeDeInit */
2285
2286
2287 /******************************************************************************
2288  *
2289  *      SkGeInitPort()  Initialize the specified port.
2290  *
2291  * Description:
2292  *      PRxQSize, PXSQSize, and PXAQSize has to be
2293  *      configured for the specified port before calling this function.
2294  *  The descriptor rings has to be initialized too.
2295  *
2296  *      o (Re)configure queues of the specified port.
2297  *      o configure the MAC of the specified port.
2298  *      o put ASIC and MAC(s) in operational mode.
2299  *      o initialize Rx/Tx and Sync LED
2300  *      o initialize RAM Buffers and MAC FIFOs
2301  *
2302  *      The port is ready to connect when returning.
2303  *
2304  * Note:
2305  *      The MAC's Rx and Tx state machine is still disabled when returning.
2306  *
2307  * Returns:
2308  *      0:      success
2309  *      1:      Queue size initialization error. The configured values
2310  *              for PRxQSize, PXSQSize, or PXAQSize are invalid for one
2311  *              or more queues. The specified port was NOT initialized.
2312  *              An error log entry was generated.
2313  *      2:      The port has to be stopped before it can be initialized again.
2314  */
2315 int SkGeInitPort(
2316 SK_AC   *pAC,           /* adapter context */
2317 SK_IOC  IoC,            /* IO context */
2318 int             Port)           /* Port to configure */
2319 {
2320         SK_GEPORT *pPrt;
2321
2322         pPrt = &pAC->GIni.GP[Port];
2323
2324         if (SkGeCheckQSize(pAC, Port) != 0) {
2325                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E004, SKERR_HWI_E004MSG);
2326                 return(1);
2327         }
2328
2329         if (pPrt->PState == SK_PRT_INIT || pPrt->PState == SK_PRT_RUN) {
2330                 SK_ERR_LOG(pAC, SK_ERRCL_SW, SKERR_HWI_E005, SKERR_HWI_E005MSG);
2331                 return(2);
2332         }
2333
2334         /* configuration ok, initialize the Port now */
2335
2336         if (pAC->GIni.GIGenesis) {
2337                 /* initialize Rx, Tx and Link LED */
2338                 /*
2339                  * If 1000BT Phy needs LED initialization than swap
2340                  * LED and XMAC initialization order
2341                  */
2342                 SkGeXmitLED(pAC, IoC, MR_ADDR(Port, TX_LED_INI), SK_LED_ENA);
2343                 SkGeXmitLED(pAC, IoC, MR_ADDR(Port, RX_LED_INI), SK_LED_ENA);
2344                 /* The Link LED is initialized by RLMT or Diagnostics itself */
2345
2346                 SkXmInitMac(pAC, IoC, Port);
2347         }
2348         else {
2349
2350                 SkGmInitMac(pAC, IoC, Port);
2351         }
2352
2353         /* do NOT initialize the Link Sync Counter */
2354
2355         SkGeInitMacFifo(pAC, IoC, Port);
2356
2357         SkGeInitRamBufs(pAC, IoC, Port);
2358
2359         if (pPrt->PXSQSize != 0) {
2360                 /* enable Force Sync bit if synchronous queue available */
2361                 SK_OUT8(IoC, MR_ADDR(Port, TXA_CTRL), TXA_ENA_FSYNC);
2362         }
2363
2364         SkGeInitBmu(pAC, IoC, Port);
2365
2366         /* mark port as initialized */
2367         pPrt->PState = SK_PRT_INIT;
2368
2369         return(0);
2370 }       /* SkGeInitPort */