3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 *------------------------------------------------------------------------------
11 * et1310_pm.c - All power management related code (not completely implemented)
13 *------------------------------------------------------------------------------
17 * This software is provided subject to the following terms and conditions,
18 * which you should read carefully before using the software. Using this
19 * software indicates your acceptance of these terms and conditions. If you do
20 * not agree with these terms and conditions, do not use the software.
22 * Copyright © 2005 Agere Systems Inc.
23 * All rights reserved.
25 * Redistribution and use in source or binary forms, with or without
26 * modifications, are permitted provided that the following conditions are met:
28 * . Redistributions of source code must retain the above copyright notice, this
29 * list of conditions and the following Disclaimer as comments in the code as
30 * well as in the documentation and/or other materials provided with the
33 * . Redistributions in binary form must reproduce the above copyright notice,
34 * this list of conditions and the following Disclaimer in the documentation
35 * and/or other materials provided with the distribution.
37 * . Neither the name of Agere Systems Inc. nor the names of the contributors
38 * may be used to endorse or promote products derived from this software
39 * without specific prior written permission.
43 * THIS SOFTWARE IS PROVIDED
\93AS IS
\94 AND ANY EXPRESS OR IMPLIED WARRANTIES,
44 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
45 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
46 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
47 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
48 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
49 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
50 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
51 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
52 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
53 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
58 #include "et131x_version.h"
59 #include "et131x_debug.h"
60 #include "et131x_defs.h"
62 #include <linux/init.h>
63 #include <linux/module.h>
64 #include <linux/types.h>
65 #include <linux/kernel.h>
67 #include <linux/sched.h>
68 #include <linux/ptrace.h>
69 #include <linux/slab.h>
70 #include <linux/ctype.h>
71 #include <linux/string.h>
72 #include <linux/timer.h>
73 #include <linux/interrupt.h>
75 #include <linux/delay.h>
77 #include <asm/system.h>
78 #include <asm/bitops.h>
80 #include <linux/netdevice.h>
81 #include <linux/etherdevice.h>
82 #include <linux/skbuff.h>
83 #include <linux/if_arp.h>
84 #include <linux/ioport.h>
86 #include "et1310_phy.h"
87 #include "et1310_pm.h"
88 #include "et1310_jagcore.h"
89 #include "et1310_mac.h"
90 #include "et1310_rx.h"
92 #include "et131x_adapter.h"
93 #include "et131x_initpci.h"
95 /* Data for debugging facilities */
96 #ifdef CONFIG_ET131X_DEBUG
97 extern dbg_info_t *et131x_dbginfo;
98 #endif /* CONFIG_ET131X_DEBUG */
101 * EnablePhyComa - called when network cable is unplugged
102 * @pAdapter: pointer to our adapter structure
104 * driver receive an phy status change interrupt while in D0 and check that
105 * phy_status is down.
107 * -- gate off JAGCore;
108 * -- set gigE PHY in Coma mode
109 * -- wake on phy_interrupt; Perform software reset JAGCore,
110 * re-initialize jagcore and gigE PHY
112 * Add D0-ASPM-PhyLinkDown Support:
113 * -- while in D0, when there is a phy_interrupt indicating phy link
114 * down status, call the MPSetPhyComa routine to enter this active
115 * state power saving mode
116 * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt
117 * indicating linkup status, call the MPDisablePhyComa routine to
118 * restore JAGCore and gigE PHY
120 void EnablePhyComa(struct et131x_adapter *pAdapter)
122 unsigned long lockflags;
123 PM_CSR_t GlobalPmCSR;
124 int32_t LoopCounter = 10;
126 DBG_ENTER(et131x_dbginfo);
128 GlobalPmCSR.value = readl(&pAdapter->CSRAddress->global.pm_csr.value);
130 /* Save the GbE PHY speed and duplex modes. Need to restore this
131 * when cable is plugged back in
133 pAdapter->PoMgmt.PowerDownSpeed = pAdapter->AiForceSpeed;
134 pAdapter->PoMgmt.PowerDownDuplex = pAdapter->AiForceDpx;
136 /* Stop sending packets. */
137 spin_lock_irqsave(&pAdapter->SendHWLock, lockflags);
138 MP_SET_FLAG(pAdapter, fMP_ADAPTER_LOWER_POWER);
139 spin_unlock_irqrestore(&pAdapter->SendHWLock, lockflags);
141 /* Wait for outstanding Receive packets */
142 while ((MP_GET_RCV_REF(pAdapter) != 0) && (LoopCounter-- > 0)) {
146 /* Gate off JAGCore 3 clock domains */
147 GlobalPmCSR.bits.pm_sysclk_gate = 0;
148 GlobalPmCSR.bits.pm_txclk_gate = 0;
149 GlobalPmCSR.bits.pm_rxclk_gate = 0;
150 writel(GlobalPmCSR.value, &pAdapter->CSRAddress->global.pm_csr.value);
152 /* Program gigE PHY in to Coma mode */
153 GlobalPmCSR.bits.pm_phy_sw_coma = 1;
154 writel(GlobalPmCSR.value, &pAdapter->CSRAddress->global.pm_csr.value);
156 DBG_LEAVE(et131x_dbginfo);
160 * DisablePhyComa - Disable the Phy Coma Mode
161 * @pAdapter: pointer to our adapter structure
163 void DisablePhyComa(struct et131x_adapter *pAdapter)
165 PM_CSR_t GlobalPmCSR;
167 DBG_ENTER(et131x_dbginfo);
169 GlobalPmCSR.value = readl(&pAdapter->CSRAddress->global.pm_csr.value);
171 /* Disable phy_sw_coma register and re-enable JAGCore clocks */
172 GlobalPmCSR.bits.pm_sysclk_gate = 1;
173 GlobalPmCSR.bits.pm_txclk_gate = 1;
174 GlobalPmCSR.bits.pm_rxclk_gate = 1;
175 GlobalPmCSR.bits.pm_phy_sw_coma = 0;
176 writel(GlobalPmCSR.value, &pAdapter->CSRAddress->global.pm_csr.value);
178 /* Restore the GbE PHY speed and duplex modes;
179 * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY
181 pAdapter->AiForceSpeed = pAdapter->PoMgmt.PowerDownSpeed;
182 pAdapter->AiForceDpx = pAdapter->PoMgmt.PowerDownDuplex;
184 /* Re-initialize the send structures */
185 et131x_init_send(pAdapter);
187 /* Reset the RFD list and re-start RU */
188 et131x_reset_recv(pAdapter);
190 /* Bring the device back to the state it was during init prior to
191 * autonegotiation being complete. This way, when we get the auto-neg
192 * complete interrupt, we can complete init by calling ConfigMacREGS2.
194 et131x_soft_reset(pAdapter);
196 /* setup et1310 as per the documentation ?? */
197 et131x_adapter_setup(pAdapter);
199 /* Allow Tx to restart */
200 MP_CLEAR_FLAG(pAdapter, fMP_ADAPTER_LOWER_POWER);
202 /* Need to re-enable Rx. */
203 et131x_rx_dma_enable(pAdapter);
205 DBG_LEAVE(et131x_dbginfo);