blob: 23deee69974b3eeed03af5a59a7286208f276ad4 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 *
3 * Copyright (C) 2002 Intersil Americas Inc.
4 * Copyright (C) 2003-2004 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>_
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 *
19 */
20
Linus Torvalds1da177e2005-04-16 15:20:36 -070021#include <linux/module.h>
22#include <linux/types.h>
23#include <linux/delay.h>
24
25#include <asm/uaccess.h>
26#include <asm/io.h>
27
28#include "prismcompat.h"
29#include "isl_38xx.h"
30#include "islpci_dev.h"
31#include "islpci_mgt.h"
32
33/******************************************************************************
34 Device Interface & Control functions
35******************************************************************************/
36
37/**
38 * isl38xx_disable_interrupts - disable all interrupts
39 * @device: pci memory base address
40 *
41 * Instructs the device to disable all interrupt reporting by asserting
42 * the IRQ line. New events may still show up in the interrupt identification
43 * register located at offset %ISL38XX_INT_IDENT_REG.
44 */
45void
46isl38xx_disable_interrupts(void __iomem *device)
47{
48 isl38xx_w32_flush(device, 0x00000000, ISL38XX_INT_EN_REG);
49 udelay(ISL38XX_WRITEIO_DELAY);
50}
51
52void
53isl38xx_handle_sleep_request(isl38xx_control_block *control_block,
54 int *powerstate, void __iomem *device_base)
55{
56 /* device requests to go into sleep mode
57 * check whether the transmit queues for data and management are empty */
58 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ))
59 /* data tx queue not empty */
60 return;
61
62 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
63 /* management tx queue not empty */
64 return;
65
66 /* check also whether received frames are pending */
67 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_DATA_LQ))
68 /* data rx queue not empty */
69 return;
70
71 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_MGMTQ))
72 /* management rx queue not empty */
73 return;
74
75#if VERBOSE > SHOW_ERROR_MESSAGES
76 DEBUG(SHOW_TRACING, "Device going to sleep mode\n");
77#endif
78
79 /* all queues are empty, allow the device to go into sleep mode */
80 *powerstate = ISL38XX_PSM_POWERSAVE_STATE;
81
82 /* assert the Sleep interrupt in the Device Interrupt Register */
83 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_SLEEP,
84 ISL38XX_DEV_INT_REG);
85 udelay(ISL38XX_WRITEIO_DELAY);
86}
87
88void
89isl38xx_handle_wakeup(isl38xx_control_block *control_block,
90 int *powerstate, void __iomem *device_base)
91{
92 /* device is in active state, update the powerstate flag */
93 *powerstate = ISL38XX_PSM_ACTIVE_STATE;
94
95 /* now check whether there are frames pending for the card */
96 if (!isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ)
97 && !isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
98 return;
99
100#if VERBOSE > SHOW_ERROR_MESSAGES
101 DEBUG(SHOW_ANYTHING, "Wake up handler trigger the device\n");
102#endif
103
104 /* either data or management transmit queue has a frame pending
105 * trigger the device by setting the Update bit in the Device Int reg */
106 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
107 ISL38XX_DEV_INT_REG);
108 udelay(ISL38XX_WRITEIO_DELAY);
109}
110
111void
112isl38xx_trigger_device(int asleep, void __iomem *device_base)
113{
Roger Whilede7fe962005-11-07 20:57:58 +0100114 u32 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700115
116#if VERBOSE > SHOW_ERROR_MESSAGES
Roger Whilede7fe962005-11-07 20:57:58 +0100117 u32 counter = 0;
Olaf Hering05ab1952005-05-26 01:16:51 +0200118 struct timeval current_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
120#endif
121
122 /* check whether the device is in power save mode */
123 if (asleep) {
124 /* device is in powersave, trigger the device for wakeup */
125#if VERBOSE > SHOW_ERROR_MESSAGES
126 do_gettimeofday(&current_time);
127 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
128 current_time.tv_sec, (long)current_time.tv_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700129
130 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
131 current_time.tv_sec, (long)current_time.tv_usec,
132 readl(device_base + ISL38XX_CTRL_STAT_REG));
Olaf Hering05ab1952005-05-26 01:16:51 +0200133#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
135 reg = readl(device_base + ISL38XX_INT_IDENT_REG);
136 if (reg == 0xabadface) {
137#if VERBOSE > SHOW_ERROR_MESSAGES
138 do_gettimeofday(&current_time);
139 DEBUG(SHOW_TRACING,
140 "%08li.%08li Device register abadface\n",
141 current_time.tv_sec, (long)current_time.tv_usec);
142#endif
143 /* read the Device Status Register until Sleepmode bit is set */
144 while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
145 (reg & ISL38XX_CTRL_STAT_SLEEPMODE) == 0) {
146 udelay(ISL38XX_WRITEIO_DELAY);
Roger Whilede7fe962005-11-07 20:57:58 +0100147#if VERBOSE > SHOW_ERROR_MESSAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148 counter++;
Roger Whilede7fe962005-11-07 20:57:58 +0100149#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700150 }
151
Olaf Hering05ab1952005-05-26 01:16:51 +0200152#if VERBOSE > SHOW_ERROR_MESSAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153 DEBUG(SHOW_TRACING,
154 "%08li.%08li Device register read %08x\n",
155 current_time.tv_sec, (long)current_time.tv_usec,
156 readl(device_base + ISL38XX_CTRL_STAT_REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700157 do_gettimeofday(&current_time);
158 DEBUG(SHOW_TRACING,
159 "%08li.%08li Device asleep counter %i\n",
160 current_time.tv_sec, (long)current_time.tv_usec,
161 counter);
162#endif
163 }
164 /* assert the Wakeup interrupt in the Device Interrupt Register */
165 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_WAKEUP,
166 ISL38XX_DEV_INT_REG);
Roger Whilecbf7c422005-11-14 11:50:46 +0100167
168#if VERBOSE > SHOW_ERROR_MESSAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169 udelay(ISL38XX_WRITEIO_DELAY);
170
171 /* perform another read on the Device Status Register */
172 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173 do_gettimeofday(&current_time);
174 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
175 current_time.tv_sec, (long)current_time.tv_usec, reg);
176#endif
177 } else {
178 /* device is (still) awake */
179#if VERBOSE > SHOW_ERROR_MESSAGES
180 DEBUG(SHOW_TRACING, "Device is in active state\n");
181#endif
182 /* trigger the device by setting the Update bit in the Device Int reg */
183
184 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
185 ISL38XX_DEV_INT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186 }
187}
188
189void
190isl38xx_interface_reset(void __iomem *device_base, dma_addr_t host_address)
191{
192#if VERBOSE > SHOW_ERROR_MESSAGES
193 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx_interface_reset\n");
194#endif
195
196 /* load the address of the control block in the device */
197 isl38xx_w32_flush(device_base, host_address, ISL38XX_CTRL_BLK_BASE_REG);
198 udelay(ISL38XX_WRITEIO_DELAY);
199
200 /* set the reset bit in the Device Interrupt Register */
201 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_RESET, ISL38XX_DEV_INT_REG);
202 udelay(ISL38XX_WRITEIO_DELAY);
203
204 /* enable the interrupt for detecting initialization */
205
206 /* Note: Do not enable other interrupts here. We want the
207 * device to have come up first 100% before allowing any other
208 * interrupts. */
209 isl38xx_w32_flush(device_base, ISL38XX_INT_IDENT_INIT, ISL38XX_INT_EN_REG);
210 udelay(ISL38XX_WRITEIO_DELAY); /* allow complete full reset */
211}
212
213void
214isl38xx_enable_common_interrupts(void __iomem *device_base) {
215 u32 reg;
216 reg = ( ISL38XX_INT_IDENT_UPDATE |
217 ISL38XX_INT_IDENT_SLEEP | ISL38XX_INT_IDENT_WAKEUP);
218 isl38xx_w32_flush(device_base, reg, ISL38XX_INT_EN_REG);
219 udelay(ISL38XX_WRITEIO_DELAY);
220}
221
222int
223isl38xx_in_queue(isl38xx_control_block *cb, int queue)
224{
225 const s32 delta = (le32_to_cpu(cb->driver_curr_frag[queue]) -
226 le32_to_cpu(cb->device_curr_frag[queue]));
227
228 /* determine the amount of fragments in the queue depending on the type
229 * of the queue, either transmit or receive */
230
231 BUG_ON(delta < 0); /* driver ptr must be ahead of device ptr */
232
233 switch (queue) {
234 /* send queues */
235 case ISL38XX_CB_TX_MGMTQ:
236 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
237 case ISL38XX_CB_TX_DATA_LQ:
238 case ISL38XX_CB_TX_DATA_HQ:
239 BUG_ON(delta > ISL38XX_CB_TX_QSIZE);
240 return delta;
241 break;
242
243 /* receive queues */
244 case ISL38XX_CB_RX_MGMTQ:
245 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
246 return ISL38XX_CB_MGMT_QSIZE - delta;
247 break;
248
249 case ISL38XX_CB_RX_DATA_LQ:
250 case ISL38XX_CB_RX_DATA_HQ:
251 BUG_ON(delta > ISL38XX_CB_RX_QSIZE);
252 return ISL38XX_CB_RX_QSIZE - delta;
253 break;
254 }
255 BUG();
256 return 0;
257}