2 * Copyright (C) 2002 Intersil Americas Inc.
3 * Copyright (C) 2003-2004 Luis R. Rodriguez <mcgrof@ruslug.rutgers.edu>_
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see <http://www.gnu.org/licenses/>.
19 #include <linux/module.h>
20 #include <linux/types.h>
21 #include <linux/delay.h>
23 #include <asm/uaccess.h>
26 #include "prismcompat.h"
28 #include "islpci_dev.h"
29 #include "islpci_mgt.h"
31 /******************************************************************************
32 Device Interface & Control functions
33 ******************************************************************************/
36 * isl38xx_disable_interrupts - disable all interrupts
37 * @device: pci memory base address
39 * Instructs the device to disable all interrupt reporting by asserting
40 * the IRQ line. New events may still show up in the interrupt identification
41 * register located at offset %ISL38XX_INT_IDENT_REG.
44 isl38xx_disable_interrupts(void __iomem
*device
)
46 isl38xx_w32_flush(device
, 0x00000000, ISL38XX_INT_EN_REG
);
47 udelay(ISL38XX_WRITEIO_DELAY
);
51 isl38xx_handle_sleep_request(isl38xx_control_block
*control_block
,
52 int *powerstate
, void __iomem
*device_base
)
54 /* device requests to go into sleep mode
55 * check whether the transmit queues for data and management are empty */
56 if (isl38xx_in_queue(control_block
, ISL38XX_CB_TX_DATA_LQ
))
57 /* data tx queue not empty */
60 if (isl38xx_in_queue(control_block
, ISL38XX_CB_TX_MGMTQ
))
61 /* management tx queue not empty */
64 /* check also whether received frames are pending */
65 if (isl38xx_in_queue(control_block
, ISL38XX_CB_RX_DATA_LQ
))
66 /* data rx queue not empty */
69 if (isl38xx_in_queue(control_block
, ISL38XX_CB_RX_MGMTQ
))
70 /* management rx queue not empty */
73 #if VERBOSE > SHOW_ERROR_MESSAGES
74 DEBUG(SHOW_TRACING
, "Device going to sleep mode\n");
77 /* all queues are empty, allow the device to go into sleep mode */
78 *powerstate
= ISL38XX_PSM_POWERSAVE_STATE
;
80 /* assert the Sleep interrupt in the Device Interrupt Register */
81 isl38xx_w32_flush(device_base
, ISL38XX_DEV_INT_SLEEP
,
83 udelay(ISL38XX_WRITEIO_DELAY
);
87 isl38xx_handle_wakeup(isl38xx_control_block
*control_block
,
88 int *powerstate
, void __iomem
*device_base
)
90 /* device is in active state, update the powerstate flag */
91 *powerstate
= ISL38XX_PSM_ACTIVE_STATE
;
93 /* now check whether there are frames pending for the card */
94 if (!isl38xx_in_queue(control_block
, ISL38XX_CB_TX_DATA_LQ
)
95 && !isl38xx_in_queue(control_block
, ISL38XX_CB_TX_MGMTQ
))
98 #if VERBOSE > SHOW_ERROR_MESSAGES
99 DEBUG(SHOW_ANYTHING
, "Wake up handler trigger the device\n");
102 /* either data or management transmit queue has a frame pending
103 * trigger the device by setting the Update bit in the Device Int reg */
104 isl38xx_w32_flush(device_base
, ISL38XX_DEV_INT_UPDATE
,
105 ISL38XX_DEV_INT_REG
);
106 udelay(ISL38XX_WRITEIO_DELAY
);
110 isl38xx_trigger_device(int asleep
, void __iomem
*device_base
)
114 #if VERBOSE > SHOW_ERROR_MESSAGES
116 struct timeval current_time
;
117 DEBUG(SHOW_FUNCTION_CALLS
, "isl38xx trigger device\n");
120 /* check whether the device is in power save mode */
122 /* device is in powersave, trigger the device for wakeup */
123 #if VERBOSE > SHOW_ERROR_MESSAGES
124 do_gettimeofday(¤t_time
);
125 DEBUG(SHOW_TRACING
, "%08li.%08li Device wakeup triggered\n",
126 current_time
.tv_sec
, (long)current_time
.tv_usec
);
128 DEBUG(SHOW_TRACING
, "%08li.%08li Device register read %08x\n",
129 current_time
.tv_sec
, (long)current_time
.tv_usec
,
130 readl(device_base
+ ISL38XX_CTRL_STAT_REG
));
133 reg
= readl(device_base
+ ISL38XX_INT_IDENT_REG
);
134 if (reg
== 0xabadface) {
135 #if VERBOSE > SHOW_ERROR_MESSAGES
136 do_gettimeofday(¤t_time
);
138 "%08li.%08li Device register abadface\n",
139 current_time
.tv_sec
, (long)current_time
.tv_usec
);
141 /* read the Device Status Register until Sleepmode bit is set */
142 while (reg
= readl(device_base
+ ISL38XX_CTRL_STAT_REG
),
143 (reg
& ISL38XX_CTRL_STAT_SLEEPMODE
) == 0) {
144 udelay(ISL38XX_WRITEIO_DELAY
);
145 #if VERBOSE > SHOW_ERROR_MESSAGES
150 #if VERBOSE > SHOW_ERROR_MESSAGES
152 "%08li.%08li Device register read %08x\n",
153 current_time
.tv_sec
, (long)current_time
.tv_usec
,
154 readl(device_base
+ ISL38XX_CTRL_STAT_REG
));
155 do_gettimeofday(¤t_time
);
157 "%08li.%08li Device asleep counter %i\n",
158 current_time
.tv_sec
, (long)current_time
.tv_usec
,
162 /* assert the Wakeup interrupt in the Device Interrupt Register */
163 isl38xx_w32_flush(device_base
, ISL38XX_DEV_INT_WAKEUP
,
164 ISL38XX_DEV_INT_REG
);
166 #if VERBOSE > SHOW_ERROR_MESSAGES
167 udelay(ISL38XX_WRITEIO_DELAY
);
169 /* perform another read on the Device Status Register */
170 reg
= readl(device_base
+ ISL38XX_CTRL_STAT_REG
);
171 do_gettimeofday(¤t_time
);
172 DEBUG(SHOW_TRACING
, "%08li.%08li Device register read %08x\n",
173 current_time
.tv_sec
, (long)current_time
.tv_usec
, reg
);
176 /* device is (still) awake */
177 #if VERBOSE > SHOW_ERROR_MESSAGES
178 DEBUG(SHOW_TRACING
, "Device is in active state\n");
180 /* trigger the device by setting the Update bit in the Device Int reg */
182 isl38xx_w32_flush(device_base
, ISL38XX_DEV_INT_UPDATE
,
183 ISL38XX_DEV_INT_REG
);
188 isl38xx_interface_reset(void __iomem
*device_base
, dma_addr_t host_address
)
190 #if VERBOSE > SHOW_ERROR_MESSAGES
191 DEBUG(SHOW_FUNCTION_CALLS
, "isl38xx_interface_reset\n");
194 /* load the address of the control block in the device */
195 isl38xx_w32_flush(device_base
, host_address
, ISL38XX_CTRL_BLK_BASE_REG
);
196 udelay(ISL38XX_WRITEIO_DELAY
);
198 /* set the reset bit in the Device Interrupt Register */
199 isl38xx_w32_flush(device_base
, ISL38XX_DEV_INT_RESET
, ISL38XX_DEV_INT_REG
);
200 udelay(ISL38XX_WRITEIO_DELAY
);
202 /* enable the interrupt for detecting initialization */
204 /* Note: Do not enable other interrupts here. We want the
205 * device to have come up first 100% before allowing any other
207 isl38xx_w32_flush(device_base
, ISL38XX_INT_IDENT_INIT
, ISL38XX_INT_EN_REG
);
208 udelay(ISL38XX_WRITEIO_DELAY
); /* allow complete full reset */
212 isl38xx_enable_common_interrupts(void __iomem
*device_base
)
216 reg
= ISL38XX_INT_IDENT_UPDATE
| ISL38XX_INT_IDENT_SLEEP
|
217 ISL38XX_INT_IDENT_WAKEUP
;
218 isl38xx_w32_flush(device_base
, reg
, ISL38XX_INT_EN_REG
);
219 udelay(ISL38XX_WRITEIO_DELAY
);
223 isl38xx_in_queue(isl38xx_control_block
*cb
, int queue
)
225 const s32 delta
= (le32_to_cpu(cb
->driver_curr_frag
[queue
]) -
226 le32_to_cpu(cb
->device_curr_frag
[queue
]));
228 /* determine the amount of fragments in the queue depending on the type
229 * of the queue, either transmit or receive */
231 BUG_ON(delta
< 0); /* driver ptr must be ahead of device ptr */
235 case ISL38XX_CB_TX_MGMTQ
:
236 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
);
244 case ISL38XX_CB_RX_MGMTQ
:
245 BUG_ON(delta
> ISL38XX_CB_MGMT_QSIZE
);
246 return ISL38XX_CB_MGMT_QSIZE
- delta
;
248 case ISL38XX_CB_RX_DATA_LQ
:
249 case ISL38XX_CB_RX_DATA_HQ
:
250 BUG_ON(delta
> ISL38XX_CB_RX_QSIZE
);
251 return ISL38XX_CB_RX_QSIZE
- delta
;