1 |
1626 |
jcastillo |
/*
|
2 |
|
|
* sym53c416.c
|
3 |
|
|
* Low-level SCSI driver for sym53c416 chip.
|
4 |
|
|
* Copyright (C) 1998 Lieven Willems (lw_linux@hotmail.com)
|
5 |
|
|
*
|
6 |
|
|
* LILO command line usage: sym53c416=<PORTBASE>[,<IRQ>]
|
7 |
|
|
*
|
8 |
|
|
* This program is free software; you can redistribute it and/or modify it
|
9 |
|
|
* under the terms of the GNU General Public License as published by the
|
10 |
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
11 |
|
|
* later version.
|
12 |
|
|
*
|
13 |
|
|
* This program is distributed in the hope that it will be useful, but
|
14 |
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
15 |
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
16 |
|
|
* General Public License for more details.
|
17 |
|
|
*
|
18 |
|
|
*/
|
19 |
|
|
|
20 |
|
|
#include <linux/module.h>
|
21 |
|
|
#include <linux/kernel.h>
|
22 |
|
|
#include <linux/types.h>
|
23 |
|
|
#include <linux/string.h>
|
24 |
|
|
#include <linux/ioport.h>
|
25 |
|
|
#include <linux/sched.h>
|
26 |
|
|
#include <linux/interrupt.h>
|
27 |
|
|
#include <linux/delay.h>
|
28 |
|
|
#include <linux/sched.h>
|
29 |
|
|
#include <linux/proc_fs.h>
|
30 |
|
|
#include <asm/dma.h>
|
31 |
|
|
#include <asm/system.h>
|
32 |
|
|
#include <asm/io.h>
|
33 |
|
|
#include <linux/blk.h>
|
34 |
|
|
#include "scsi.h"
|
35 |
|
|
#include "hosts.h"
|
36 |
|
|
#include "sd.h"
|
37 |
|
|
#include "sym53c416.h"
|
38 |
|
|
|
39 |
|
|
#define VERSION_STRING "Version 1.0.0"
|
40 |
|
|
|
41 |
|
|
#define TC_LOW 0x00 /* Transfer counter low */
|
42 |
|
|
#define TC_MID 0x01 /* Transfer counter mid */
|
43 |
|
|
#define SCSI_FIFO 0x02 /* SCSI FIFO register */
|
44 |
|
|
#define COMMAND_REG 0x03 /* Command Register */
|
45 |
|
|
#define STATUS_REG 0x04 /* Status Register (READ) */
|
46 |
|
|
#define DEST_BUS_ID 0x04 /* Destination Bus ID (WRITE) */
|
47 |
|
|
#define INT_REG 0x05 /* Interrupt Register (READ) */
|
48 |
|
|
#define TOM 0x05 /* Time out multiplier (WRITE) */
|
49 |
|
|
#define STP 0x06 /* Synchronous Transfer period */
|
50 |
|
|
#define SYNC_OFFSET 0x07 /* Synchronous Offset */
|
51 |
|
|
#define CONF_REG_1 0x08 /* Configuration register 1 */
|
52 |
|
|
#define CONF_REG_2 0x0B /* Configuration register 2 */
|
53 |
|
|
#define CONF_REG_3 0x0C /* Configuration register 3 */
|
54 |
|
|
#define CONF_REG_4 0x0D /* Configuration register 4 */
|
55 |
|
|
#define TC_HIGH 0x0E /* Transfer counter high */
|
56 |
|
|
#define PIO_FIFO_1 0x10 /* PIO FIFO register 1 */
|
57 |
|
|
#define PIO_FIFO_2 0x11 /* PIO FIFO register 2 */
|
58 |
|
|
#define PIO_FIFO_3 0x12 /* PIO FIFO register 3 */
|
59 |
|
|
#define PIO_FIFO_4 0x13 /* PIO FIFO register 4 */
|
60 |
|
|
#define PIO_FIFO_CNT 0x14 /* PIO FIFO count */
|
61 |
|
|
#define PIO_INT_REG 0x15 /* PIO interrupt register */
|
62 |
|
|
#define CONF_REG_5 0x16 /* Configuration register 5 */
|
63 |
|
|
#define FEATURE_EN 0x1D /* Feature Enable register */
|
64 |
|
|
|
65 |
|
|
/* Configuration register 1 entries: */
|
66 |
|
|
/* Bits 2-0: SCSI ID of host adapter */
|
67 |
|
|
#define SCM 0x80 /* Slow Cable Mode */
|
68 |
|
|
#define SRID 0x40 /* SCSI Reset Interrupt Disable */
|
69 |
|
|
#define PTM 0x20 /* Parity Test Mode */
|
70 |
|
|
#define EPC 0x10 /* Enable Parity Checking */
|
71 |
|
|
#define CTME 0x08 /* Special Test Mode */
|
72 |
|
|
|
73 |
|
|
/* Configuration register 2 entries: */
|
74 |
|
|
#define FE 0x40 /* Features Enable */
|
75 |
|
|
#define SCSI2 0x08 /* SCSI 2 Enable */
|
76 |
|
|
#define TBPA 0x04 /* Target Bad Parity Abort */
|
77 |
|
|
|
78 |
|
|
/* Configuration register 3 entries: */
|
79 |
|
|
#define IDMRC 0x80 /* ID Message Reserved Check */
|
80 |
|
|
#define QTE 0x40 /* Queue Tag Enable */
|
81 |
|
|
#define CDB10 0x20 /* Command Descriptor Block 10 */
|
82 |
|
|
#define FSCSI 0x10 /* FastSCSI */
|
83 |
|
|
#define FCLK 0x08 /* FastClock */
|
84 |
|
|
|
85 |
|
|
/* Configuration register 4 entries: */
|
86 |
|
|
#define RBS 0x08 /* Register bank select */
|
87 |
|
|
#define EAN 0x04 /* Enable Active Negotiation */
|
88 |
|
|
|
89 |
|
|
/* Configuration register 5 entries: */
|
90 |
|
|
#define LPSR 0x80 /* Lower Power SCSI Reset */
|
91 |
|
|
#define IE 0x20 /* Interrupt Enable */
|
92 |
|
|
#define LPM 0x02 /* Low Power Mode */
|
93 |
|
|
#define WSE0 0x01 /* 0WS Enable */
|
94 |
|
|
|
95 |
|
|
/* Interrupt register entries: */
|
96 |
|
|
#define SRST 0x80 /* SCSI Reset */
|
97 |
|
|
#define ILCMD 0x40 /* Illegal Command */
|
98 |
|
|
#define DIS 0x20 /* Disconnect */
|
99 |
|
|
#define BS 0x10 /* Bus Service */
|
100 |
|
|
#define FC 0x08 /* Function Complete */
|
101 |
|
|
#define RESEL 0x04 /* Reselected */
|
102 |
|
|
#define SI 0x03 /* Selection Interrupt */
|
103 |
|
|
|
104 |
|
|
/* Status Register Entries: */
|
105 |
|
|
#define SCI 0x80 /* SCSI Core Int */
|
106 |
|
|
#define GE 0x40 /* Gross Error */
|
107 |
|
|
#define PE 0x20 /* Parity Error */
|
108 |
|
|
#define TC 0x10 /* Terminal Count */
|
109 |
|
|
#define VGC 0x08 /* Valid Group Code */
|
110 |
|
|
#define PHBITS 0x07 /* Phase bits */
|
111 |
|
|
|
112 |
|
|
/* PIO Interrupt Register Entries: */
|
113 |
|
|
#define SCI 0x80 /* SCSI Core Int */
|
114 |
|
|
#define PFI 0x40 /* PIO FIFO Interrupt */
|
115 |
|
|
#define FULL 0x20 /* PIO FIFO Full */
|
116 |
|
|
#define EMPTY 0x10 /* PIO FIFO Empty */
|
117 |
|
|
#define CE 0x08 /* Collision Error */
|
118 |
|
|
#define OUE 0x04 /* Overflow / Underflow error */
|
119 |
|
|
#define FIE 0x02 /* Full Interrupt Enable */
|
120 |
|
|
#define EIE 0x01 /* Empty Interrupt Enable */
|
121 |
|
|
|
122 |
|
|
/* SYM53C416 SCSI phases (lower 3 bits of SYM53C416_STATUS_REG) */
|
123 |
|
|
#define PHASE_DATA_OUT 0x00
|
124 |
|
|
#define PHASE_DATA_IN 0x01
|
125 |
|
|
#define PHASE_COMMAND 0x02
|
126 |
|
|
#define PHASE_STATUS 0x03
|
127 |
|
|
#define PHASE_RESERVED_1 0x04
|
128 |
|
|
#define PHASE_RESERVED_2 0x05
|
129 |
|
|
#define PHASE_MESSAGE_OUT 0x06
|
130 |
|
|
#define PHASE_MESSAGE_IN 0x07
|
131 |
|
|
|
132 |
|
|
/* SYM53C416 core commands */
|
133 |
|
|
#define NOOP 0x00
|
134 |
|
|
#define FLUSH_FIFO 0x01
|
135 |
|
|
#define RESET_CHIP 0x02
|
136 |
|
|
#define RESET_SCSI_BUS 0x03
|
137 |
|
|
#define DISABLE_SEL_RESEL 0x45
|
138 |
|
|
#define RESEL_SEQ 0x40
|
139 |
|
|
#define SEL_WITHOUT_ATN_SEQ 0x41
|
140 |
|
|
#define SEL_WITH_ATN_SEQ 0x42
|
141 |
|
|
#define SEL_WITH_ATN_AND_STOP_SEQ 0x43
|
142 |
|
|
#define ENABLE_SEL_RESEL 0x44
|
143 |
|
|
#define SEL_WITH_ATN3_SEQ 0x46
|
144 |
|
|
#define RESEL3_SEQ 0x47
|
145 |
|
|
#define SND_MSG 0x20
|
146 |
|
|
#define SND_STAT 0x21
|
147 |
|
|
#define SND_DATA 0x22
|
148 |
|
|
#define DISCONNECT_SEQ 0x23
|
149 |
|
|
#define TERMINATE_SEQ 0x24
|
150 |
|
|
#define TARGET_COMM_COMPLETE_SEQ 0x25
|
151 |
|
|
#define DISCONN 0x27
|
152 |
|
|
#define RECV_MSG_SEQ 0x28
|
153 |
|
|
#define RECV_CMD 0x29
|
154 |
|
|
#define RECV_DATA 0x2A
|
155 |
|
|
#define RECV_CMD_SEQ 0x2B
|
156 |
|
|
#define TARGET_ABORT_PIO 0x04
|
157 |
|
|
#define TRANSFER_INFORMATION 0x10
|
158 |
|
|
#define INIT_COMM_COMPLETE_SEQ 0x11
|
159 |
|
|
#define MSG_ACCEPTED 0x12
|
160 |
|
|
#define TRANSFER_PAD 0x18
|
161 |
|
|
#define SET_ATN 0x1A
|
162 |
|
|
#define RESET_ATN 0x1B
|
163 |
|
|
#define ILLEGAL 0xFF
|
164 |
|
|
|
165 |
|
|
#define PIO_MODE 0x80
|
166 |
|
|
|
167 |
|
|
#define IO_RANGE 0x20 /* 0x00 - 0x1F */
|
168 |
|
|
#define ID "sym53c416"
|
169 |
|
|
#define PIO_SIZE 128 /* Size of PIO fifo is 128 bytes */
|
170 |
|
|
|
171 |
|
|
#define READ_TIMEOUT 150
|
172 |
|
|
#define WRITE_TIMEOUT 150
|
173 |
|
|
|
174 |
|
|
#ifdef MODULE
|
175 |
|
|
|
176 |
|
|
#define sym53c416_base sym53c416
|
177 |
|
|
#define sym53c416_base_1 sym53c416_1
|
178 |
|
|
#define sym53c416_base_2 sym53c416_2
|
179 |
|
|
#define sym53c416_base_3 sym53c416_3
|
180 |
|
|
|
181 |
|
|
static unsigned short sym53c416_base = 0;
|
182 |
|
|
static unsigned int sym53c416_irq = 0;
|
183 |
|
|
static unsigned short sym53c416_base_1 = 0;
|
184 |
|
|
static unsigned int sym53c416_irq_1 = 0;
|
185 |
|
|
static unsigned short sym53c416_base_2 = 0;
|
186 |
|
|
static unsigned int sym53c416_irq_2 = 0;
|
187 |
|
|
static unsigned short sym53c416_base_3 = 0;
|
188 |
|
|
static unsigned int sym53c416_irq_3 = 0;
|
189 |
|
|
|
190 |
|
|
#endif
|
191 |
|
|
|
192 |
|
|
/* #define DEBUG */
|
193 |
|
|
|
194 |
|
|
/* Macro for debugging purposes */
|
195 |
|
|
|
196 |
|
|
#ifdef DEBUG
|
197 |
|
|
#define DEB(x) x
|
198 |
|
|
#else
|
199 |
|
|
#define DEB(x)
|
200 |
|
|
#endif
|
201 |
|
|
|
202 |
|
|
#define MAXHOSTS 4
|
203 |
|
|
|
204 |
|
|
enum phases
|
205 |
|
|
{
|
206 |
|
|
idle,
|
207 |
|
|
data_out,
|
208 |
|
|
data_in,
|
209 |
|
|
command_ph,
|
210 |
|
|
status_ph,
|
211 |
|
|
message_out,
|
212 |
|
|
message_in
|
213 |
|
|
};
|
214 |
|
|
|
215 |
|
|
typedef struct
|
216 |
|
|
{
|
217 |
|
|
int base;
|
218 |
|
|
int irq;
|
219 |
|
|
int scsi_id;
|
220 |
|
|
} host;
|
221 |
|
|
|
222 |
|
|
host hosts[MAXHOSTS] = {
|
223 |
|
|
{0, 0, SYM53C416_SCSI_ID},
|
224 |
|
|
{0, 0, SYM53C416_SCSI_ID},
|
225 |
|
|
{0, 0, SYM53C416_SCSI_ID},
|
226 |
|
|
{0, 0, SYM53C416_SCSI_ID}
|
227 |
|
|
};
|
228 |
|
|
|
229 |
|
|
static int host_index = 0;
|
230 |
|
|
|
231 |
|
|
static char info[120];
|
232 |
|
|
|
233 |
|
|
static Scsi_Cmnd *current_command = NULL;
|
234 |
|
|
|
235 |
|
|
struct proc_dir_entry proc_scsi_sym53c416 = {PROC_SCSI_SYM53C416, 7, ID, S_IFDIR | S_IRUGO | S_IXUGO, 2};
|
236 |
|
|
|
237 |
|
|
int fastpio = 1;
|
238 |
|
|
|
239 |
|
|
int probeaddrs[] = {0x200, 0x220, 0x240, 0};
|
240 |
|
|
|
241 |
|
|
static void sym53c416_set_transfer_counter(int base, unsigned int len)
|
242 |
|
|
{
|
243 |
|
|
/* Program Transfer Counter */
|
244 |
|
|
outb(len & 0x0000FF, base + TC_LOW);
|
245 |
|
|
outb((len & 0x00FF00) >> 8, base + TC_MID);
|
246 |
|
|
outb((len & 0xFF0000) >> 16, base + TC_HIGH);
|
247 |
|
|
}
|
248 |
|
|
|
249 |
|
|
/* Returns the number of bytes read */
|
250 |
|
|
static __inline__ unsigned int sym53c416_read(int base, unsigned char *buffer, unsigned int len)
|
251 |
|
|
{
|
252 |
|
|
unsigned int orig_len = len;
|
253 |
|
|
unsigned long flags = 0;
|
254 |
|
|
unsigned int bytes_left;
|
255 |
|
|
int i;
|
256 |
|
|
int timeout = READ_TIMEOUT;
|
257 |
|
|
|
258 |
|
|
/* Do transfer */
|
259 |
|
|
save_flags(flags);
|
260 |
|
|
cli();
|
261 |
|
|
while(len && timeout)
|
262 |
|
|
{
|
263 |
|
|
bytes_left = inb(base + PIO_FIFO_CNT); /* Number of bytes in the PIO FIFO */
|
264 |
|
|
if(fastpio && bytes_left > 3)
|
265 |
|
|
{
|
266 |
|
|
insl(base + PIO_FIFO_1, buffer, bytes_left >> 2);
|
267 |
|
|
buffer += bytes_left & 0xFC;
|
268 |
|
|
len -= bytes_left & 0xFC;
|
269 |
|
|
}
|
270 |
|
|
else if(bytes_left > 0)
|
271 |
|
|
{
|
272 |
|
|
len -= bytes_left;
|
273 |
|
|
for(; bytes_left > 0; bytes_left--)
|
274 |
|
|
*(buffer++) = inb(base + PIO_FIFO_1);
|
275 |
|
|
}
|
276 |
|
|
else
|
277 |
|
|
{
|
278 |
|
|
i = jiffies + timeout;
|
279 |
|
|
restore_flags(flags);
|
280 |
|
|
while(jiffies < i && (inb(base + PIO_INT_REG) & EMPTY) && timeout)
|
281 |
|
|
if(inb(base + PIO_INT_REG) & SCI)
|
282 |
|
|
timeout = 0;
|
283 |
|
|
save_flags(flags);
|
284 |
|
|
cli();
|
285 |
|
|
if(inb(base + PIO_INT_REG) & EMPTY)
|
286 |
|
|
timeout = 0;
|
287 |
|
|
}
|
288 |
|
|
}
|
289 |
|
|
restore_flags(flags);
|
290 |
|
|
return orig_len - len;
|
291 |
|
|
}
|
292 |
|
|
|
293 |
|
|
/* Returns the number of bytes written */
|
294 |
|
|
static __inline__ unsigned int sym53c416_write(int base, unsigned char *buffer, unsigned int len)
|
295 |
|
|
{
|
296 |
|
|
unsigned int orig_len = len;
|
297 |
|
|
unsigned long flags = 0;
|
298 |
|
|
unsigned int bufferfree;
|
299 |
|
|
unsigned int i;
|
300 |
|
|
unsigned int timeout = WRITE_TIMEOUT;
|
301 |
|
|
|
302 |
|
|
/* Do transfer */
|
303 |
|
|
save_flags(flags);
|
304 |
|
|
cli();
|
305 |
|
|
while(len && timeout)
|
306 |
|
|
{
|
307 |
|
|
bufferfree = PIO_SIZE - inb(base + PIO_FIFO_CNT);
|
308 |
|
|
if(bufferfree > len)
|
309 |
|
|
bufferfree = len;
|
310 |
|
|
if(fastpio && bufferfree > 3)
|
311 |
|
|
{
|
312 |
|
|
outsl(base + PIO_FIFO_1, buffer, bufferfree >> 2);
|
313 |
|
|
buffer += bufferfree & 0xFC;
|
314 |
|
|
len -= bufferfree & 0xFC;
|
315 |
|
|
}
|
316 |
|
|
else if(bufferfree > 0)
|
317 |
|
|
{
|
318 |
|
|
len -= bufferfree;
|
319 |
|
|
for(; bufferfree > 0; bufferfree--)
|
320 |
|
|
outb(*(buffer++), base + PIO_FIFO_1);
|
321 |
|
|
}
|
322 |
|
|
else
|
323 |
|
|
{
|
324 |
|
|
i = jiffies + timeout;
|
325 |
|
|
restore_flags(flags);
|
326 |
|
|
while(jiffies < i && (inb(base + PIO_INT_REG) & FULL) && timeout)
|
327 |
|
|
;
|
328 |
|
|
save_flags(flags);
|
329 |
|
|
cli();
|
330 |
|
|
if(inb(base + PIO_INT_REG) & FULL)
|
331 |
|
|
timeout = 0;
|
332 |
|
|
}
|
333 |
|
|
}
|
334 |
|
|
restore_flags(flags);
|
335 |
|
|
return orig_len - len;
|
336 |
|
|
}
|
337 |
|
|
|
338 |
|
|
static void sym53c416_intr_handle(int irq, void *dev_id, struct pt_regs *regs)
|
339 |
|
|
{
|
340 |
|
|
int base = 0;
|
341 |
|
|
int i;
|
342 |
|
|
unsigned long flags = 0;
|
343 |
|
|
unsigned char status_reg, pio_int_reg, int_reg;
|
344 |
|
|
struct scatterlist *sglist;
|
345 |
|
|
unsigned int sgcount;
|
346 |
|
|
unsigned int tot_trans = 0;
|
347 |
|
|
|
348 |
|
|
/* We search the base address of the host adapter which caused the interrupt */
|
349 |
|
|
for(i = 0; i < host_index && !base; i++)
|
350 |
|
|
if(irq == hosts[i].irq)
|
351 |
|
|
base = hosts[i].base;
|
352 |
|
|
/* If no adapter found, we cannot handle the interrupt. Leave a message */
|
353 |
|
|
/* and continue. This should never happen... */
|
354 |
|
|
if(!base)
|
355 |
|
|
{
|
356 |
|
|
printk("sym53c416: No host adapter defined for interrupt %d\n", irq);
|
357 |
|
|
return;
|
358 |
|
|
}
|
359 |
|
|
/* Now we have the base address and we can start handling the interrupt */
|
360 |
|
|
save_flags(flags);
|
361 |
|
|
cli();
|
362 |
|
|
status_reg = inb(base + STATUS_REG);
|
363 |
|
|
pio_int_reg = inb(base + PIO_INT_REG);
|
364 |
|
|
int_reg = inb(base + INT_REG);
|
365 |
|
|
restore_flags(flags);
|
366 |
|
|
|
367 |
|
|
/* First, we handle error conditions */
|
368 |
|
|
if(int_reg & SCI) /* SCSI Reset */
|
369 |
|
|
{
|
370 |
|
|
printk("sym53c416: Warning: Reset received\n");
|
371 |
|
|
current_command->SCp.phase = idle;
|
372 |
|
|
current_command->result = DID_RESET << 16;
|
373 |
|
|
current_command->scsi_done(current_command);
|
374 |
|
|
return;
|
375 |
|
|
}
|
376 |
|
|
if(int_reg & ILCMD) /* Illegal Command */
|
377 |
|
|
{
|
378 |
|
|
printk("sym53c416: Warning: Illegal Command: 0x%02x\n", inb(base + COMMAND_REG));
|
379 |
|
|
current_command->SCp.phase = idle;
|
380 |
|
|
current_command->result = DID_ERROR << 16;
|
381 |
|
|
current_command->scsi_done(current_command);
|
382 |
|
|
return;
|
383 |
|
|
}
|
384 |
|
|
if(status_reg & GE) /* Gross Error */
|
385 |
|
|
{
|
386 |
|
|
printk("sym53c416: Warning: Gross Error\n");
|
387 |
|
|
current_command->SCp.phase = idle;
|
388 |
|
|
current_command->result = DID_ERROR << 16;
|
389 |
|
|
current_command->scsi_done(current_command);
|
390 |
|
|
return;
|
391 |
|
|
}
|
392 |
|
|
if(status_reg & PE) /* Parity Error */
|
393 |
|
|
{
|
394 |
|
|
printk("sym53c416: Warning: Parity Error\n");
|
395 |
|
|
current_command->SCp.phase = idle;
|
396 |
|
|
current_command->result = DID_PARITY << 16;
|
397 |
|
|
current_command->scsi_done(current_command);
|
398 |
|
|
return;
|
399 |
|
|
}
|
400 |
|
|
if(pio_int_reg & (CE | OUE))
|
401 |
|
|
{
|
402 |
|
|
printk("sym53c416: Warning: PIO Interrupt Error\n");
|
403 |
|
|
current_command->SCp.phase = idle;
|
404 |
|
|
current_command->result = DID_ERROR << 16;
|
405 |
|
|
current_command->scsi_done(current_command);
|
406 |
|
|
return;
|
407 |
|
|
}
|
408 |
|
|
if(int_reg & DIS) /* Disconnect */
|
409 |
|
|
{
|
410 |
|
|
if(current_command->SCp.phase != message_in)
|
411 |
|
|
current_command->result = DID_NO_CONNECT << 16;
|
412 |
|
|
else
|
413 |
|
|
current_command->result = (current_command->SCp.Status & 0xFF) | ((current_command->SCp.Message & 0xFF) << 8) | (DID_OK << 16);
|
414 |
|
|
current_command->SCp.phase = idle;
|
415 |
|
|
current_command->scsi_done(current_command);
|
416 |
|
|
return;
|
417 |
|
|
}
|
418 |
|
|
/* Now we handle SCSI phases */
|
419 |
|
|
switch(status_reg & PHBITS) /* Filter SCSI phase out of status reg */
|
420 |
|
|
{
|
421 |
|
|
case PHASE_DATA_OUT:
|
422 |
|
|
{
|
423 |
|
|
if(int_reg & BS)
|
424 |
|
|
{
|
425 |
|
|
current_command->SCp.phase = data_out;
|
426 |
|
|
outb(FLUSH_FIFO, base + COMMAND_REG);
|
427 |
|
|
sym53c416_set_transfer_counter(base, current_command->request_bufflen);
|
428 |
|
|
outb(TRANSFER_INFORMATION | PIO_MODE, base + COMMAND_REG);
|
429 |
|
|
if(!current_command->use_sg)
|
430 |
|
|
tot_trans = sym53c416_write(base, current_command->request_buffer, current_command->request_bufflen);
|
431 |
|
|
else
|
432 |
|
|
{
|
433 |
|
|
sgcount = current_command->use_sg;
|
434 |
|
|
sglist = current_command->request_buffer;
|
435 |
|
|
while(sgcount--)
|
436 |
|
|
{
|
437 |
|
|
tot_trans += sym53c416_write(base, sglist->address, sglist->length);
|
438 |
|
|
sglist++;
|
439 |
|
|
}
|
440 |
|
|
}
|
441 |
|
|
if(tot_trans < current_command->underflow)
|
442 |
|
|
printk("sym53c416: Warning: underflow, wrote %d bytes, request for %d bytes\n", tot_trans, current_command->underflow);
|
443 |
|
|
}
|
444 |
|
|
break;
|
445 |
|
|
}
|
446 |
|
|
case PHASE_DATA_IN:
|
447 |
|
|
{
|
448 |
|
|
if(int_reg & BS)
|
449 |
|
|
{
|
450 |
|
|
current_command->SCp.phase = data_in;
|
451 |
|
|
outb(FLUSH_FIFO, base + COMMAND_REG);
|
452 |
|
|
sym53c416_set_transfer_counter(base, current_command->request_bufflen);
|
453 |
|
|
outb(TRANSFER_INFORMATION | PIO_MODE, base + COMMAND_REG);
|
454 |
|
|
if(!current_command->use_sg)
|
455 |
|
|
tot_trans = sym53c416_read(base, current_command->request_buffer, current_command->request_bufflen);
|
456 |
|
|
else
|
457 |
|
|
{
|
458 |
|
|
sgcount = current_command->use_sg;
|
459 |
|
|
sglist = current_command->request_buffer;
|
460 |
|
|
while(sgcount--)
|
461 |
|
|
{
|
462 |
|
|
tot_trans += sym53c416_read(base, sglist->address, sglist->length);
|
463 |
|
|
sglist++;
|
464 |
|
|
}
|
465 |
|
|
}
|
466 |
|
|
if(tot_trans < current_command->underflow)
|
467 |
|
|
printk("sym53c416: Warning: underflow, read %d bytes, request for %d bytes\n", tot_trans, current_command->underflow);
|
468 |
|
|
}
|
469 |
|
|
break;
|
470 |
|
|
}
|
471 |
|
|
case PHASE_COMMAND:
|
472 |
|
|
{
|
473 |
|
|
current_command->SCp.phase = command_ph;
|
474 |
|
|
printk("sym53c416: Warning: Unknown interrupt in command phase\n");
|
475 |
|
|
break;
|
476 |
|
|
}
|
477 |
|
|
case PHASE_STATUS:
|
478 |
|
|
{
|
479 |
|
|
current_command->SCp.phase = status_ph;
|
480 |
|
|
outb(FLUSH_FIFO, base + COMMAND_REG);
|
481 |
|
|
outb(INIT_COMM_COMPLETE_SEQ, base + COMMAND_REG);
|
482 |
|
|
break;
|
483 |
|
|
}
|
484 |
|
|
case PHASE_RESERVED_1:
|
485 |
|
|
case PHASE_RESERVED_2:
|
486 |
|
|
{
|
487 |
|
|
printk("sym53c416: Warning: Reserved phase\n");
|
488 |
|
|
break;
|
489 |
|
|
}
|
490 |
|
|
case PHASE_MESSAGE_OUT:
|
491 |
|
|
{
|
492 |
|
|
current_command->SCp.phase = message_out;
|
493 |
|
|
outb(SET_ATN, base + COMMAND_REG);
|
494 |
|
|
outb(MSG_ACCEPTED, base + COMMAND_REG);
|
495 |
|
|
break;
|
496 |
|
|
}
|
497 |
|
|
case PHASE_MESSAGE_IN:
|
498 |
|
|
{
|
499 |
|
|
current_command->SCp.phase = message_in;
|
500 |
|
|
current_command->SCp.Status = inb(base + SCSI_FIFO);
|
501 |
|
|
current_command->SCp.Message = inb(base + SCSI_FIFO);
|
502 |
|
|
if(current_command->SCp.Message == SAVE_POINTERS || current_command->SCp.Message == DISCONNECT)
|
503 |
|
|
outb(SET_ATN, base + COMMAND_REG);
|
504 |
|
|
outb(MSG_ACCEPTED, base + COMMAND_REG);
|
505 |
|
|
break;
|
506 |
|
|
}
|
507 |
|
|
}
|
508 |
|
|
}
|
509 |
|
|
|
510 |
|
|
static void sym53c416_init(int base, int scsi_id)
|
511 |
|
|
{
|
512 |
|
|
outb(RESET_CHIP, base + COMMAND_REG);
|
513 |
|
|
outb(NOOP, base + COMMAND_REG);
|
514 |
|
|
outb(0x99, base + TOM); /* Time out of 250 ms */
|
515 |
|
|
outb(0x05, base + STP);
|
516 |
|
|
outb(0x00, base + SYNC_OFFSET);
|
517 |
|
|
outb(EPC | scsi_id, base + CONF_REG_1);
|
518 |
|
|
outb(FE | SCSI2 | TBPA, base + CONF_REG_2);
|
519 |
|
|
outb(IDMRC | QTE | CDB10 | FSCSI | FCLK, base + CONF_REG_3);
|
520 |
|
|
outb(0x83 | EAN, base + CONF_REG_4);
|
521 |
|
|
outb(IE | WSE0, base + CONF_REG_5);
|
522 |
|
|
outb(0, base + FEATURE_EN);
|
523 |
|
|
}
|
524 |
|
|
|
525 |
|
|
static int sym53c416_probeirq(int base, int scsi_id)
|
526 |
|
|
{
|
527 |
|
|
int irq, irqs, i;
|
528 |
|
|
|
529 |
|
|
/* Clear interrupt register */
|
530 |
|
|
inb(base + INT_REG);
|
531 |
|
|
/* Start probing for irq's */
|
532 |
|
|
irqs = probe_irq_on();
|
533 |
|
|
/* Reinit chip */
|
534 |
|
|
sym53c416_init(base, scsi_id);
|
535 |
|
|
/* Cause interrupt */
|
536 |
|
|
outb(NOOP, base + COMMAND_REG);
|
537 |
|
|
outb(ILLEGAL, base + COMMAND_REG);
|
538 |
|
|
outb(0x07, base + DEST_BUS_ID);
|
539 |
|
|
outb(0x00, base + DEST_BUS_ID);
|
540 |
|
|
/* Wait for interrupt to occur */
|
541 |
|
|
i = jiffies + 20;
|
542 |
|
|
while(i > jiffies && !(inb(base + STATUS_REG) & SCI))
|
543 |
|
|
barrier();
|
544 |
|
|
if(i <= jiffies) /* timed out */
|
545 |
|
|
return 0;
|
546 |
|
|
/* Get occurred irq */
|
547 |
|
|
irq = probe_irq_off(irqs);
|
548 |
|
|
sym53c416_init(base, scsi_id);
|
549 |
|
|
return irq;
|
550 |
|
|
}
|
551 |
|
|
|
552 |
|
|
/* Setup: sym53c416=base,irq */
|
553 |
|
|
void sym53c416_setup(char *str, int *ints)
|
554 |
|
|
{
|
555 |
|
|
int i;
|
556 |
|
|
|
557 |
|
|
if(host_index >= MAXHOSTS)
|
558 |
|
|
{
|
559 |
|
|
printk("sym53c416.c: Too many hosts defined\n");
|
560 |
|
|
}
|
561 |
|
|
else
|
562 |
|
|
{
|
563 |
|
|
if(ints[0] < 1 || ints[0] > 2)
|
564 |
|
|
{
|
565 |
|
|
printk("sym53c416.c: Wrong number of parameters:\n");
|
566 |
|
|
printk("sym53c416.c: usage: sym53c416=<base>[,<irq>]\n");
|
567 |
|
|
}
|
568 |
|
|
else
|
569 |
|
|
{
|
570 |
|
|
for(i = 0; i < host_index && i >= 0; i++)
|
571 |
|
|
if(hosts[i].base == ints[1])
|
572 |
|
|
i = -2;
|
573 |
|
|
if(i >= 0)
|
574 |
|
|
{
|
575 |
|
|
hosts[host_index].base = ints[1];
|
576 |
|
|
hosts[host_index].irq = (ints[0] == 2)? ints[2] : 0;
|
577 |
|
|
host_index++;
|
578 |
|
|
}
|
579 |
|
|
}
|
580 |
|
|
}
|
581 |
|
|
}
|
582 |
|
|
|
583 |
|
|
static int sym53c416_test(int base)
|
584 |
|
|
{
|
585 |
|
|
outb(RESET_CHIP, base + COMMAND_REG);
|
586 |
|
|
outb(NOOP, base + COMMAND_REG);
|
587 |
|
|
if(inb(base + COMMAND_REG) != NOOP)
|
588 |
|
|
return 0;
|
589 |
|
|
if(!inb(base + TC_HIGH) || inb(base + TC_HIGH) == 0xFF)
|
590 |
|
|
return 0;
|
591 |
|
|
if((inb(base + PIO_INT_REG) & (FULL | EMPTY | CE | OUE | FIE | EIE)) != EMPTY)
|
592 |
|
|
return 0;
|
593 |
|
|
return 1;
|
594 |
|
|
}
|
595 |
|
|
|
596 |
|
|
void sym53c416_probe(void)
|
597 |
|
|
{
|
598 |
|
|
int *base = probeaddrs;
|
599 |
|
|
int ints[2];
|
600 |
|
|
|
601 |
|
|
ints[0] = 1;
|
602 |
|
|
for(; *base; base++)
|
603 |
|
|
if(!check_region(*base, IO_RANGE) && sym53c416_test(*base))
|
604 |
|
|
{
|
605 |
|
|
ints[1] = *base;
|
606 |
|
|
sym53c416_setup(NULL, ints);
|
607 |
|
|
}
|
608 |
|
|
}
|
609 |
|
|
|
610 |
|
|
int sym53c416_detect(Scsi_Host_Template *tpnt)
|
611 |
|
|
{
|
612 |
|
|
unsigned long flags;
|
613 |
|
|
struct Scsi_Host * shpnt = NULL;
|
614 |
|
|
int i;
|
615 |
|
|
int count;
|
616 |
|
|
|
617 |
|
|
#ifdef MODULE
|
618 |
|
|
int ints[3];
|
619 |
|
|
|
620 |
|
|
ints[0] = 2;
|
621 |
|
|
if(sym53c416_base)
|
622 |
|
|
{
|
623 |
|
|
ints[1] = sym53c416_base;
|
624 |
|
|
ints[2] = sym53c416_irq;
|
625 |
|
|
sym53c416_setup(NULL, ints);
|
626 |
|
|
}
|
627 |
|
|
if(sym53c416_base_1)
|
628 |
|
|
{
|
629 |
|
|
ints[1] = sym53c416_base_1;
|
630 |
|
|
ints[2] = sym53c416_irq_1;
|
631 |
|
|
sym53c416_setup(NULL, ints);
|
632 |
|
|
}
|
633 |
|
|
if(sym53c416_base_2)
|
634 |
|
|
{
|
635 |
|
|
ints[1] = sym53c416_base_2;
|
636 |
|
|
ints[2] = sym53c416_irq_2;
|
637 |
|
|
sym53c416_setup(NULL, ints);
|
638 |
|
|
}
|
639 |
|
|
if(sym53c416_base_3)
|
640 |
|
|
{
|
641 |
|
|
ints[1] = sym53c416_base_3;
|
642 |
|
|
ints[2] = sym53c416_irq_3;
|
643 |
|
|
sym53c416_setup(NULL, ints);
|
644 |
|
|
}
|
645 |
|
|
#endif
|
646 |
|
|
|
647 |
|
|
printk("sym53c416.c: %s\n", VERSION_STRING);
|
648 |
|
|
|
649 |
|
|
sym53c416_probe();
|
650 |
|
|
|
651 |
|
|
/* Now we register and set up each host adapter found... */
|
652 |
|
|
for(count = 0, i = 0; i < host_index; i++)
|
653 |
|
|
if(!sym53c416_test(hosts[i].base))
|
654 |
|
|
printk("No sym53c416 found at address 0x%03x\n", hosts[i].base);
|
655 |
|
|
else
|
656 |
|
|
{
|
657 |
|
|
if(hosts[i].irq == 0)
|
658 |
|
|
/* We don't have an irq yet, so we should probe for one */
|
659 |
|
|
if((hosts[i].irq = sym53c416_probeirq(hosts[i].base, hosts[i].scsi_id)) == 0)
|
660 |
|
|
printk("irq autoprobing failed for sym53c416 at address 0x%03x\n", hosts[i].base);
|
661 |
|
|
if(hosts[i].irq && !check_region(hosts[i].base, IO_RANGE))
|
662 |
|
|
{
|
663 |
|
|
shpnt = scsi_register(tpnt, 0);
|
664 |
|
|
save_flags(flags);
|
665 |
|
|
cli();
|
666 |
|
|
/* Request for specified IRQ */
|
667 |
|
|
if(request_irq(hosts[i].irq, sym53c416_intr_handle, 0, ID, NULL))
|
668 |
|
|
{
|
669 |
|
|
restore_flags(flags);
|
670 |
|
|
printk("Unable to assign IRQ %d\n", hosts[i].irq);
|
671 |
|
|
scsi_unregister(shpnt);
|
672 |
|
|
}
|
673 |
|
|
else
|
674 |
|
|
{
|
675 |
|
|
/* Inform the kernel of our IO range */
|
676 |
|
|
request_region(hosts[i].base, IO_RANGE, ID);
|
677 |
|
|
shpnt->unique_id = hosts[i].base;
|
678 |
|
|
shpnt->io_port = hosts[i].base;
|
679 |
|
|
shpnt->n_io_port = IO_RANGE;
|
680 |
|
|
shpnt->irq = hosts[i].irq;
|
681 |
|
|
shpnt->this_id = hosts[i].scsi_id;
|
682 |
|
|
sym53c416_init(hosts[i].base, hosts[i].scsi_id);
|
683 |
|
|
count++;
|
684 |
|
|
restore_flags(flags);
|
685 |
|
|
}
|
686 |
|
|
}
|
687 |
|
|
}
|
688 |
|
|
return count;
|
689 |
|
|
}
|
690 |
|
|
|
691 |
|
|
const char *sym53c416_info(struct Scsi_Host *SChost)
|
692 |
|
|
{
|
693 |
|
|
int i;
|
694 |
|
|
int base = SChost->io_port;
|
695 |
|
|
int irq = SChost->irq;
|
696 |
|
|
int scsi_id = 0;
|
697 |
|
|
int rev = inb(base + TC_HIGH);
|
698 |
|
|
|
699 |
|
|
for(i = 0; i < host_index; i++)
|
700 |
|
|
if(hosts[i].base == base)
|
701 |
|
|
scsi_id = hosts[i].scsi_id;
|
702 |
|
|
sprintf(info, "Symbios Logic 53c416 (rev. %d) at 0x%03x, irq %d, SCSI-ID %d, %s pio", rev, base, irq, scsi_id, (fastpio)? "fast" : "slow");
|
703 |
|
|
return info;
|
704 |
|
|
}
|
705 |
|
|
|
706 |
|
|
int sym53c416_queuecommand(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
|
707 |
|
|
{
|
708 |
|
|
int base;
|
709 |
|
|
unsigned long flags = 0;
|
710 |
|
|
int i;
|
711 |
|
|
|
712 |
|
|
/* Store base register as we can have more than one controller in the system */
|
713 |
|
|
base = SCpnt->host->io_port;
|
714 |
|
|
current_command = SCpnt; /* set current command */
|
715 |
|
|
current_command->scsi_done = done; /* set ptr to done function */
|
716 |
|
|
current_command->SCp.phase = command_ph; /* currect phase is the command phase */
|
717 |
|
|
current_command->SCp.Status = 0;
|
718 |
|
|
current_command->SCp.Message = 0;
|
719 |
|
|
|
720 |
|
|
save_flags(flags);
|
721 |
|
|
cli();
|
722 |
|
|
outb(SCpnt->target, base + DEST_BUS_ID); /* Set scsi id target */
|
723 |
|
|
outb(FLUSH_FIFO, base + COMMAND_REG); /* Flush SCSI and PIO FIFO's */
|
724 |
|
|
/* Write SCSI command into the SCSI fifo */
|
725 |
|
|
for(i = 0; i < SCpnt->cmd_len; i++)
|
726 |
|
|
outb(SCpnt->cmnd[i], base + SCSI_FIFO);
|
727 |
|
|
/* Start selection sequence */
|
728 |
|
|
outb(SEL_WITHOUT_ATN_SEQ, base + COMMAND_REG);
|
729 |
|
|
/* Now an interrupt will be generated which we will catch in out interrupt routine */
|
730 |
|
|
restore_flags(flags);
|
731 |
|
|
return 0;
|
732 |
|
|
}
|
733 |
|
|
|
734 |
|
|
static void internal_done(Scsi_Cmnd *SCpnt)
|
735 |
|
|
{
|
736 |
|
|
SCpnt->SCp.Status++;
|
737 |
|
|
}
|
738 |
|
|
|
739 |
|
|
int sym53c416_command(Scsi_Cmnd *SCpnt)
|
740 |
|
|
{
|
741 |
|
|
sym53c416_queuecommand(SCpnt, internal_done);
|
742 |
|
|
SCpnt->SCp.Status = 0;
|
743 |
|
|
while(!SCpnt->SCp.Status)
|
744 |
|
|
barrier();
|
745 |
|
|
return SCpnt->result;
|
746 |
|
|
}
|
747 |
|
|
|
748 |
|
|
int sym53c416_abort(Scsi_Cmnd *SCpnt)
|
749 |
|
|
{
|
750 |
|
|
printk("sym53c416_abort\n");
|
751 |
|
|
|
752 |
|
|
/* We don't know how to abort for the moment */
|
753 |
|
|
return SCSI_ABORT_SNOOZE;
|
754 |
|
|
}
|
755 |
|
|
|
756 |
|
|
int sym53c416_reset(Scsi_Cmnd *SCpnt, unsigned int reset_flags)
|
757 |
|
|
{
|
758 |
|
|
int base;
|
759 |
|
|
int scsi_id = -1;
|
760 |
|
|
int i;
|
761 |
|
|
|
762 |
|
|
printk("sym53c416_reset\n");
|
763 |
|
|
base = SCpnt->host->io_port;
|
764 |
|
|
/* search scsi_id */
|
765 |
|
|
for(i = 0; i < host_index && scsi_id != -1; i++)
|
766 |
|
|
if(hosts[i].base == base)
|
767 |
|
|
scsi_id = hosts[i].scsi_id;
|
768 |
|
|
outb(RESET_CHIP, base + COMMAND_REG);
|
769 |
|
|
outb(NOOP | PIO_MODE, base + COMMAND_REG);
|
770 |
|
|
outb(RESET_SCSI_BUS, base + COMMAND_REG);
|
771 |
|
|
sym53c416_init(base, scsi_id);
|
772 |
|
|
return SCSI_RESET_PENDING;
|
773 |
|
|
}
|
774 |
|
|
|
775 |
|
|
int sym53c416_bios_param(Disk *disk, kdev_t dev, int *ip)
|
776 |
|
|
{
|
777 |
|
|
int size;
|
778 |
|
|
|
779 |
|
|
size = disk->capacity;
|
780 |
|
|
ip[0] = 64; /* heads */
|
781 |
|
|
ip[1] = 32; /* sectors */
|
782 |
|
|
if((ip[2] = size >> 11) > 1024) /* cylinders, test for big disk */
|
783 |
|
|
{
|
784 |
|
|
ip[0] = 255; /* heads */
|
785 |
|
|
ip[1] = 63; /* sectors */
|
786 |
|
|
ip[2] = size / (255 * 63); /* cylinders */
|
787 |
|
|
}
|
788 |
|
|
return 0;
|
789 |
|
|
}
|
790 |
|
|
|
791 |
|
|
/* Loadable module support */
|
792 |
|
|
#ifdef MODULE
|
793 |
|
|
|
794 |
|
|
#if LINUX_VERSION_CODE >= LinuxVersionCode(2,1,26)
|
795 |
|
|
MODULE_AUTHOR("Lieven Willems");
|
796 |
|
|
MODULE_PARM(sym53c416, "1-2i");
|
797 |
|
|
MODULE_PARM(sym53c416_1, "1-2i");
|
798 |
|
|
MODULE_PARM(sym53c416_2, "1-2i");
|
799 |
|
|
MODULE_PARM(sym53c416_3, "1-2i");
|
800 |
|
|
#endif
|
801 |
|
|
|
802 |
|
|
Scsi_Host_Template driver_template = SYM53C416;
|
803 |
|
|
|
804 |
|
|
#include "scsi_module.c"
|
805 |
|
|
#endif
|