3 * Copyright (C) 2002 Intersil Americas Inc.
4 * Copyright (C) 2003-2004 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>_
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
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.
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
21 #define __KERNEL_SYSCALLS__
23 #include <linux/version.h>
24 #include <linux/module.h>
25 #include <linux/types.h>
26 #include <linux/delay.h>
28 #include <asm/uaccess.h>
31 #include "prismcompat.h"
33 #include "islpci_dev.h"
34 #include "islpci_mgt.h"
36 /******************************************************************************
37 Device Interface & Control functions
38 ******************************************************************************/
41 * isl38xx_disable_interrupts - disable all interrupts
42 * @device: pci memory base address
44 * Instructs the device to disable all interrupt reporting by asserting
45 * the IRQ line. New events may still show up in the interrupt identification
46 * register located at offset %ISL38XX_INT_IDENT_REG.
49 isl38xx_disable_interrupts(void *device)
51 isl38xx_w32_flush(device, 0x00000000, ISL38XX_INT_EN_REG);
52 udelay(ISL38XX_WRITEIO_DELAY);
56 isl38xx_handle_sleep_request(isl38xx_control_block *control_block,
57 int *powerstate, void *device_base)
59 /* device requests to go into sleep mode
60 * check whether the transmit queues for data and management are empty */
61 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ))
62 /* data tx queue not empty */
65 if (isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
66 /* management tx queue not empty */
69 /* check also whether received frames are pending */
70 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_DATA_LQ))
71 /* data rx queue not empty */
74 if (isl38xx_in_queue(control_block, ISL38XX_CB_RX_MGMTQ))
75 /* management rx queue not empty */
78 #if VERBOSE > SHOW_ERROR_MESSAGES
79 DEBUG(SHOW_TRACING, "Device going to sleep mode\n");
82 /* all queues are empty, allow the device to go into sleep mode */
83 *powerstate = ISL38XX_PSM_POWERSAVE_STATE;
85 /* assert the Sleep interrupt in the Device Interrupt Register */
86 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_SLEEP,
88 udelay(ISL38XX_WRITEIO_DELAY);
92 isl38xx_handle_wakeup(isl38xx_control_block *control_block,
93 int *powerstate, void *device_base)
95 /* device is in active state, update the powerstate flag */
96 *powerstate = ISL38XX_PSM_ACTIVE_STATE;
98 /* now check whether there are frames pending for the card */
99 if (!isl38xx_in_queue(control_block, ISL38XX_CB_TX_DATA_LQ)
100 && !isl38xx_in_queue(control_block, ISL38XX_CB_TX_MGMTQ))
103 #if VERBOSE > SHOW_ERROR_MESSAGES
104 DEBUG(SHOW_ANYTHING, "Wake up handler trigger the device\n");
107 /* either data or management transmit queue has a frame pending
108 * trigger the device by setting the Update bit in the Device Int reg */
109 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
110 ISL38XX_DEV_INT_REG);
111 udelay(ISL38XX_WRITEIO_DELAY);
115 isl38xx_trigger_device(int asleep, void *device_base)
117 struct timeval current_time;
118 u32 reg, counter = 0;
120 #if VERBOSE > SHOW_ERROR_MESSAGES
121 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx trigger device\n");
124 /* check whether the device is in power save mode */
126 /* device is in powersave, trigger the device for wakeup */
127 #if VERBOSE > SHOW_ERROR_MESSAGES
128 do_gettimeofday(¤t_time);
129 DEBUG(SHOW_TRACING, "%08li.%08li Device wakeup triggered\n",
130 current_time.tv_sec, current_time.tv_usec);
133 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
134 current_time.tv_sec, current_time.tv_usec,
135 readl(device_base + ISL38XX_CTRL_STAT_REG));
136 udelay(ISL38XX_WRITEIO_DELAY);
138 if (reg = readl(device_base + ISL38XX_INT_IDENT_REG),
140 #if VERBOSE > SHOW_ERROR_MESSAGES
141 do_gettimeofday(¤t_time);
143 "%08li.%08li Device register abadface\n",
144 current_time.tv_sec, current_time.tv_usec);
146 /* read the Device Status Register until Sleepmode bit is set */
147 while (reg = readl(device_base + ISL38XX_CTRL_STAT_REG),
148 (reg & ISL38XX_CTRL_STAT_SLEEPMODE) == 0) {
149 udelay(ISL38XX_WRITEIO_DELAY);
154 "%08li.%08li Device register read %08x\n",
155 current_time.tv_sec, current_time.tv_usec,
156 readl(device_base + ISL38XX_CTRL_STAT_REG));
157 udelay(ISL38XX_WRITEIO_DELAY);
159 #if VERBOSE > SHOW_ERROR_MESSAGES
160 do_gettimeofday(¤t_time);
162 "%08li.%08li Device asleep counter %i\n",
163 current_time.tv_sec, current_time.tv_usec,
167 /* assert the Wakeup interrupt in the Device Interrupt Register */
168 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_WAKEUP,
169 ISL38XX_DEV_INT_REG);
170 udelay(ISL38XX_WRITEIO_DELAY);
172 /* perform another read on the Device Status Register */
173 reg = readl(device_base + ISL38XX_CTRL_STAT_REG);
174 udelay(ISL38XX_WRITEIO_DELAY);
176 #if VERBOSE > SHOW_ERROR_MESSAGES
177 do_gettimeofday(¤t_time);
178 DEBUG(SHOW_TRACING, "%08li.%08li Device register read %08x\n",
179 current_time.tv_sec, current_time.tv_usec, reg);
182 /* device is (still) awake */
183 #if VERBOSE > SHOW_ERROR_MESSAGES
184 DEBUG(SHOW_TRACING, "Device is in active state\n");
186 /* trigger the device by setting the Update bit in the Device Int reg */
188 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_UPDATE,
189 ISL38XX_DEV_INT_REG);
190 udelay(ISL38XX_WRITEIO_DELAY);
195 isl38xx_interface_reset(void *device_base, dma_addr_t host_address)
199 #if VERBOSE > SHOW_ERROR_MESSAGES
200 DEBUG(SHOW_FUNCTION_CALLS, "isl38xx_interface_reset \n");
203 /* load the address of the control block in the device */
204 isl38xx_w32_flush(device_base, host_address, ISL38XX_CTRL_BLK_BASE_REG);
205 udelay(ISL38XX_WRITEIO_DELAY);
207 /* set the reset bit in the Device Interrupt Register */
208 isl38xx_w32_flush(device_base, ISL38XX_DEV_INT_RESET,
209 ISL38XX_DEV_INT_REG);
210 udelay(ISL38XX_WRITEIO_DELAY);
212 /* enable the interrupt for detecting initialization */
214 /* Note: Do not enable other interrupts here. We want the
215 * device to have come up first 100% before allowing any other
217 reg = ISL38XX_INT_IDENT_INIT;
219 isl38xx_w32_flush(device_base, reg, ISL38XX_INT_EN_REG);
220 udelay(ISL38XX_WRITEIO_DELAY); /* allow complete full reset */
224 isl38xx_enable_common_interrupts(void *device_base) {
226 reg = ( ISL38XX_INT_IDENT_UPDATE |
227 ISL38XX_INT_IDENT_SLEEP | ISL38XX_INT_IDENT_WAKEUP);
228 isl38xx_w32_flush(device_base, reg, ISL38XX_INT_EN_REG);
229 udelay(ISL38XX_WRITEIO_DELAY);
233 isl38xx_in_queue(isl38xx_control_block *cb, int queue)
235 const s32 delta = (le32_to_cpu(cb->driver_curr_frag[queue]) -
236 le32_to_cpu(cb->device_curr_frag[queue]));
238 /* determine the amount of fragments in the queue depending on the type
239 * of the queue, either transmit or receive */
241 BUG_ON(delta < 0); /* driver ptr must be ahead of device ptr */
245 case ISL38XX_CB_TX_MGMTQ:
246 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
247 case ISL38XX_CB_TX_DATA_LQ:
248 case ISL38XX_CB_TX_DATA_HQ:
249 BUG_ON(delta > ISL38XX_CB_TX_QSIZE);
254 case ISL38XX_CB_RX_MGMTQ:
255 BUG_ON(delta > ISL38XX_CB_MGMT_QSIZE);
256 return ISL38XX_CB_MGMT_QSIZE - delta;
259 case ISL38XX_CB_RX_DATA_LQ:
260 case ISL38XX_CB_RX_DATA_HQ:
261 BUG_ON(delta > ISL38XX_CB_RX_QSIZE);
262 return ISL38XX_CB_RX_QSIZE - delta;