blob: 866c476933c337e7506063702b97ecd07f168b7c [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
21#include <linux/version.h>
22#include <linux/module.h>
23#include <linux/types.h>
24#include <linux/delay.h>
25
26#include <asm/uaccess.h>
27#include <asm/io.h>
28
29#include "prismcompat.h"
30#include "isl_38xx.h"
31#include "islpci_dev.h"
32#include "islpci_mgt.h"
33
34/******************************************************************************
35 Device Interface & Control functions
36******************************************************************************/
37
38/**
39 * isl38xx_disable_interrupts - disable all interrupts
40 * @device: pci memory base address
41 *
42 * Instructs the device to disable all interrupt reporting by asserting
43 * the IRQ line. New events may still show up in the interrupt identification
44 * register located at offset %ISL38XX_INT_IDENT_REG.
45 */
46void
47isl38xx_disable_interrupts(void __iomem *device)
48{
49 isl38xx_w32_flush(device, 0x00000000, ISL38XX_INT_EN_REG);
50 udelay(ISL38XX_WRITEIO_DELAY);
51}
52
53void
54isl38xx_handle_sleep_request(isl38xx_control_block *control_block,
55 int *powerstate, void __iomem *device_base)
56{
57 /* device requests to go into sleep mode
58 * check whether the transmit queues for data and management are empty */
59 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ))
60 /* data tx queue not empty */
61 return;
62
63 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
64 /* management tx queue not empty */
65 return;
66
67 /* check also whether received frames are pending */
68 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_DATA_LQ))
69 /* data rx queue not empty */
70 return;
71
72 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_MGMTQ))
73 /* management rx queue not empty */
74 return;
75
76#if VERBOSE > SHOW_ERROR_MESSAGES
77 DEBUG(SHOW_TRACING, "Device going to sleep mode\n");
78#endif
79
80 /* all queues are empty, allow the device to go into sleep mode */
81 *powerstate = ISL38XX_PSM_POWERSAVE_STATE;
82
83 /* assert the Sleep interrupt in the Device Interrupt Register */
84 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_SLEEP,
85 ISL38XX_DEV_INT_REG);
86 udelay(ISL38XX_WRITEIO_DELAY);
87}
88
89void
90isl38xx_handle_wakeup(isl38xx_control_block *control_block,
91 int *powerstate, void __iomem *device_base)
92{
93 /* device is in active state, update the powerstate flag */
94 *powerstate = ISL38XX_PSM_ACTIVE_STATE;
95
96 /* now check whether there are frames pending for the card */
97 if (!isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ)
98 && !isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
99 return;
100
101#if VERBOSE > SHOW_ERROR_MESSAGES
102 DEBUG(SHOW_ANYTHING, "Wake up handler trigger the device\n");
103#endif
104
105 /* either data or management transmit queue has a frame pending
106 * trigger the device by setting the Update bit in the Device Int reg */
107 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
108 ISL38XX_DEV_INT_REG);
109 udelay(ISL38XX_WRITEIO_DELAY);
110}
111
112void
113isl38xx_trigger_device(int asleep, void __iomem *device_base)
114{
Roger Whilede7fe962005-11-07 20:57:58 +0100115 u32 reg;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116
117#if VERBOSE > SHOW_ERROR_MESSAGES
Roger Whilede7fe962005-11-07 20:57:58 +0100118 u32 counter = 0;
Olaf Hering05ab1952005-05-26 01:16:51 +0200119 struct timeval current_time;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700120 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
121#endif
122
123 /* check whether the device is in power save mode */
124 if (asleep) {
125 /* device is in powersave, trigger the device for wakeup */
126#if VERBOSE > SHOW_ERROR_MESSAGES
127 do_gettimeofday(&current_time);
128 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
129 current_time.tv_sec, (long)current_time.tv_usec);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
132 current_time.tv_sec, (long)current_time.tv_usec,
133 readl(device_base + ISL38XX_CTRL_STAT_REG));
Olaf Hering05ab1952005-05-26 01:16:51 +0200134#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136 reg = readl(device_base + ISL38XX_INT_IDENT_REG);
137 if (reg == 0xabadface) {
138#if VERBOSE > SHOW_ERROR_MESSAGES
139 do_gettimeofday(&current_time);
140 DEBUG(SHOW_TRACING,
141 "%08li.%08li Device register abadface\n",
142 current_time.tv_sec, (long)current_time.tv_usec);
143#endif
144 /* read the Device Status Register until Sleepmode bit is set */
145 while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
146 (reg & ISL38XX_CTRL_STAT_SLEEPMODE) == 0) {
147 udelay(ISL38XX_WRITEIO_DELAY);
Roger Whilede7fe962005-11-07 20:57:58 +0100148#if VERBOSE > SHOW_ERROR_MESSAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149 counter++;
Roger Whilede7fe962005-11-07 20:57:58 +0100150#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151 }
152
Olaf Hering05ab1952005-05-26 01:16:51 +0200153#if VERBOSE > SHOW_ERROR_MESSAGES
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154 DEBUG(SHOW_TRACING,
155 "%08li.%08li Device register read %08x\n",
156 current_time.tv_sec, (long)current_time.tv_usec,
157 readl(device_base + ISL38XX_CTRL_STAT_REG));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700158 do_gettimeofday(&current_time);
159 DEBUG(SHOW_TRACING,
160 "%08li.%08li Device asleep counter %i\n",
161 current_time.tv_sec, (long)current_time.tv_usec,
162 counter);
163#endif
164 }
165 /* assert the Wakeup interrupt in the Device Interrupt Register */
166 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_WAKEUP,
167 ISL38XX_DEV_INT_REG);
168 udelay(ISL38XX_WRITEIO_DELAY);
169
170 /* perform another read on the Device Status Register */
171 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700172
173#if VERBOSE > SHOW_ERROR_MESSAGES
174 do_gettimeofday(&current_time);
175 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
176 current_time.tv_sec, (long)current_time.tv_usec, reg);
177#endif
178 } else {
179 /* device is (still) awake */
180#if VERBOSE > SHOW_ERROR_MESSAGES
181 DEBUG(SHOW_TRACING, "Device is in active state\n");
182#endif
183 /* trigger the device by setting the Update bit in the Device Int reg */
184
185 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
186 ISL38XX_DEV_INT_REG);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187 }
188}
189
190void
191isl38xx_interface_reset(void __iomem *device_base, dma_addr_t host_address)
192{
193#if VERBOSE > SHOW_ERROR_MESSAGES
194 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx_interface_reset\n");
195#endif
196
197 /* load the address of the control block in the device */
198 isl38xx_w32_flush(device_base, host_address, ISL38XX_CTRL_BLK_BASE_REG);
199 udelay(ISL38XX_WRITEIO_DELAY);
200
201 /* set the reset bit in the Device Interrupt Register */
202 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_RESET, ISL38XX_DEV_INT_REG);
203 udelay(ISL38XX_WRITEIO_DELAY);
204
205 /* enable the interrupt for detecting initialization */
206
207 /* Note: Do not enable other interrupts here. We want the
208 * device to have come up first 100% before allowing any other
209 * interrupts. */
210 isl38xx_w32_flush(device_base, ISL38XX_INT_IDENT_INIT, ISL38XX_INT_EN_REG);
211 udelay(ISL38XX_WRITEIO_DELAY); /* allow complete full reset */
212}
213
214void
215isl38xx_enable_common_interrupts(void __iomem *device_base) {
216 u32 reg;
217 reg = ( ISL38XX_INT_IDENT_UPDATE |
218 ISL38XX_INT_IDENT_SLEEP | ISL38XX_INT_IDENT_WAKEUP);
219 isl38xx_w32_flush(device_base, reg, ISL38XX_INT_EN_REG);
220 udelay(ISL38XX_WRITEIO_DELAY);
221}
222
223int
224isl38xx_in_queue(isl38xx_control_block *cb, int queue)
225{
226 const s32 delta = (le32_to_cpu(cb->driver_curr_frag[queue]) -
227 le32_to_cpu(cb->device_curr_frag[queue]));
228
229 /* determine the amount of fragments in the queue depending on the type
230 * of the queue, either transmit or receive */
231
232 BUG_ON(delta < 0); /* driver ptr must be ahead of device ptr */
233
234 switch (queue) {
235 /* send queues */
236 case ISL38XX_CB_TX_MGMTQ:
237 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
238 case ISL38XX_CB_TX_DATA_LQ:
239 case ISL38XX_CB_TX_DATA_HQ:
240 BUG_ON(delta > ISL38XX_CB_TX_QSIZE);
241 return delta;
242 break;
243
244 /* receive queues */
245 case ISL38XX_CB_RX_MGMTQ:
246 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
247 return ISL38XX_CB_MGMT_QSIZE - delta;
248 break;
249
250 case ISL38XX_CB_RX_DATA_LQ:
251 case ISL38XX_CB_RX_DATA_HQ:
252 BUG_ON(delta > ISL38XX_CB_RX_QSIZE);
253 return ISL38XX_CB_RX_QSIZE - delta;
254 break;
255 }
256 BUG();
257 return 0;
258}