3 * 10/100/1000 Base-T Ethernet Driver for the ET1301 and ET131x series MACs
5 * Copyright © 2005 Agere Systems Inc.
9 * Copyright (c) 2011 Mark Einon <mark.einon@gmail.com>
11 *------------------------------------------------------------------------------
13 * et1310_pm.c - All power management related code (not completely implemented)
15 *------------------------------------------------------------------------------
19 * This software is provided subject to the following terms and conditions,
20 * which you should read carefully before using the software. Using this
21 * software indicates your acceptance of these terms and conditions. If you do
22 * not agree with these terms and conditions, do not use the software.
24 * Copyright © 2005 Agere Systems Inc.
25 * All rights reserved.
27 * Redistribution and use in source or binary forms, with or without
28 * modifications, are permitted provided that the following conditions are met:
30 * . Redistributions of source code must retain the above copyright notice, this
31 * list of conditions and the following Disclaimer as comments in the code as
32 * well as in the documentation and/or other materials provided with the
35 * . Redistributions in binary form must reproduce the above copyright notice,
36 * this list of conditions and the following Disclaimer in the documentation
37 * and/or other materials provided with the distribution.
39 * . Neither the name of Agere Systems Inc. nor the names of the contributors
40 * may be used to endorse or promote products derived from this software
41 * without specific prior written permission.
45 * THIS SOFTWARE IS PROVIDED "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
46 * INCLUDING, BUT NOT LIMITED TO, INFRINGEMENT AND THE IMPLIED WARRANTIES OF
47 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ANY
48 * USE, MODIFICATION OR DISTRIBUTION OF THIS SOFTWARE IS SOLELY AT THE USERS OWN
49 * RISK. IN NO EVENT SHALL AGERE SYSTEMS INC. OR CONTRIBUTORS BE LIABLE FOR ANY
50 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
51 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
52 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
53 * ON ANY THEORY OF LIABILITY, INCLUDING, BUT NOT LIMITED TO, CONTRACT, STRICT
54 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
55 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
60 #include "et131x_version.h"
61 #include "et131x_defs.h"
63 #include <linux/init.h>
64 #include <linux/module.h>
65 #include <linux/types.h>
66 #include <linux/kernel.h>
68 #include <linux/sched.h>
69 #include <linux/ptrace.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 <linux/bitops.h>
78 #include <asm/system.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_rx.h"
88 #include "et131x_adapter.h"
92 * et1310_in_phy_coma - check if the device is in phy coma
93 * @adapter: pointer to our adapter structure
95 * Returns 0 if the device is not in phy coma, 1 if it is in phy coma
97 int et1310_in_phy_coma(struct et131x_adapter *adapter)
101 pmcsr = readl(&adapter->regs->global.pm_csr);
103 return ET_PM_PHY_SW_COMA & pmcsr ? 1 : 0;
107 * et1310_enable_phy_coma - called when network cable is unplugged
108 * @adapter: pointer to our adapter structure
110 * driver receive an phy status change interrupt while in D0 and check that
111 * phy_status is down.
113 * -- gate off JAGCore;
114 * -- set gigE PHY in Coma mode
115 * -- wake on phy_interrupt; Perform software reset JAGCore,
116 * re-initialize jagcore and gigE PHY
118 * Add D0-ASPM-PhyLinkDown Support:
119 * -- while in D0, when there is a phy_interrupt indicating phy link
120 * down status, call the MPSetPhyComa routine to enter this active
121 * state power saving mode
122 * -- while in D0-ASPM-PhyLinkDown mode, when there is a phy_interrupt
123 * indicating linkup status, call the MPDisablePhyComa routine to
124 * restore JAGCore and gigE PHY
126 void et1310_enable_phy_coma(struct et131x_adapter *adapter)
131 pmcsr = readl(&adapter->regs->global.pm_csr);
133 /* Save the GbE PHY speed and duplex modes. Need to restore this
134 * when cable is plugged back in
137 * TODO - when PM is re-enabled, check if we need to
138 * perform a similar task as this -
139 * adapter->pdown_speed = adapter->ai_force_speed;
140 * adapter->pdown_duplex = adapter->ai_force_duplex;
143 /* Stop sending packets. */
144 spin_lock_irqsave(&adapter->send_hw_lock, flags);
145 adapter->flags |= fMP_ADAPTER_LOWER_POWER;
146 spin_unlock_irqrestore(&adapter->send_hw_lock, flags);
148 /* Wait for outstanding Receive packets */
150 /* Gate off JAGCore 3 clock domains */
151 pmcsr &= ~ET_PMCSR_INIT;
152 writel(pmcsr, &adapter->regs->global.pm_csr);
154 /* Program gigE PHY in to Coma mode */
155 pmcsr |= ET_PM_PHY_SW_COMA;
156 writel(pmcsr, &adapter->regs->global.pm_csr);
160 * et1310_disable_phy_coma - Disable the Phy Coma Mode
161 * @adapter: pointer to our adapter structure
163 void et1310_disable_phy_coma(struct et131x_adapter *adapter)
167 pmcsr = readl(&adapter->regs->global.pm_csr);
169 /* Disable phy_sw_coma register and re-enable JAGCore clocks */
170 pmcsr |= ET_PMCSR_INIT;
171 pmcsr &= ~ET_PM_PHY_SW_COMA;
172 writel(pmcsr, &adapter->regs->global.pm_csr);
174 /* Restore the GbE PHY speed and duplex modes;
175 * Reset JAGCore; re-configure and initialize JAGCore and gigE PHY
177 /* TODO - when PM is re-enabled, check if we need to
178 * perform a similar task as this -
179 * adapter->ai_force_speed = adapter->pdown_speed;
180 * adapter->ai_force_duplex = adapter->pdown_duplex;
183 /* Re-initialize the send structures */
184 et131x_init_send(adapter);
186 /* Reset the RFD list and re-start RU */
187 et131x_reset_recv(adapter);
189 /* Bring the device back to the state it was during init prior to
190 * autonegotiation being complete. This way, when we get the auto-neg
191 * complete interrupt, we can complete init by calling ConfigMacREGS2.
193 et131x_soft_reset(adapter);
195 /* setup et1310 as per the documentation ?? */
196 et131x_adapter_setup(adapter);
198 /* Allow Tx to restart */
199 adapter->flags &= ~fMP_ADAPTER_LOWER_POWER;
201 /* Need to re-enable Rx. */
202 et131x_rx_dma_enable(adapter);