initial commit with v2.6.9
[linux-2.6.9-moxart.git] / drivers / scsi / arm / fas216.c
blobbd607455e28555a486398f83bc4dfbb5b6f1fa4a
1 /*
2 * linux/drivers/acorn/scsi/fas216.c
4 * Copyright (C) 1997-2003 Russell King
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License version 2 as
8 * published by the Free Software Foundation.
10 * Based on information in qlogicfas.c by Tom Zerucha, Michael Griffith, and
11 * other sources, including:
12 * the AMD Am53CF94 data sheet
13 * the AMD Am53C94 data sheet
15 * This is a generic driver. To use it, have a look at cumana_2.c. You
16 * should define your own structure that overlays FAS216_Info, eg:
17 * struct my_host_data {
18 * FAS216_Info info;
19 * ... my host specific data ...
20 * };
22 * Changelog:
23 * 30-08-1997 RMK Created
24 * 14-09-1997 RMK Started disconnect support
25 * 08-02-1998 RMK Corrected real DMA support
26 * 15-02-1998 RMK Started sync xfer support
27 * 06-04-1998 RMK Tightened conditions for printing incomplete
28 * transfers
29 * 02-05-1998 RMK Added extra checks in fas216_reset
30 * 24-05-1998 RMK Fixed synchronous transfers with period >= 200ns
31 * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h
32 * 26-08-1998 RMK Improved message support wrt MESSAGE_REJECT
33 * 02-04-2000 RMK Converted to use the new error handling, and
34 * automatically request sense data upon check
35 * condition status from targets.
37 #include <linux/module.h>
38 #include <linux/blkdev.h>
39 #include <linux/kernel.h>
40 #include <linux/string.h>
41 #include <linux/ioport.h>
42 #include <linux/sched.h>
43 #include <linux/proc_fs.h>
44 #include <linux/delay.h>
45 #include <linux/bitops.h>
46 #include <linux/init.h>
47 #include <linux/interrupt.h>
49 #include <asm/dma.h>
50 #include <asm/io.h>
51 #include <asm/irq.h>
52 #include <asm/ecard.h>
54 #include "../scsi.h"
55 #include <scsi/scsi_host.h>
56 #include "fas216.h"
57 #include "scsi.h"
59 /* NOTE: SCSI2 Synchronous transfers *require* DMA according to
60 * the data sheet. This restriction is crazy, especially when
61 * you only want to send 16 bytes! What were the guys who
62 * designed this chip on at that time? Did they read the SCSI2
63 * spec at all? The following sections are taken from the SCSI2
64 * standard (s2r10) concerning this:
66 * > IMPLEMENTORS NOTES:
67 * > (1) Re-negotiation at every selection is not recommended, since a
68 * > significant performance impact is likely.
70 * > The implied synchronous agreement shall remain in effect until a BUS DEVICE
71 * > RESET message is received, until a hard reset condition occurs, or until one
72 * > of the two SCSI devices elects to modify the agreement. The default data
73 * > transfer mode is asynchronous data transfer mode. The default data transfer
74 * > mode is entered at power on, after a BUS DEVICE RESET message, or after a hard
75 * > reset condition.
77 * In total, this means that once you have elected to use synchronous
78 * transfers, you must always use DMA.
80 * I was thinking that this was a good chip until I found this restriction ;(
82 #define SCSI2_SYNC
83 #undef SCSI2_TAG
85 #undef DEBUG_CONNECT
86 #undef DEBUG_MESSAGES
88 #undef CHECK_STRUCTURE
90 #define LOG_CONNECT (1 << 0)
91 #define LOG_BUSSERVICE (1 << 1)
92 #define LOG_FUNCTIONDONE (1 << 2)
93 #define LOG_MESSAGES (1 << 3)
94 #define LOG_BUFFER (1 << 4)
95 #define LOG_ERROR (1 << 8)
97 static int level_mask = LOG_ERROR;
99 MODULE_PARM(level_mask, "i");
101 static int __init fas216_log_setup(char *str)
103 char *s;
105 level_mask = 0;
107 while ((s = strsep(&str, ",")) != NULL) {
108 switch (s[0]) {
109 case 'a':
110 if (strcmp(s, "all") == 0)
111 level_mask |= -1;
112 break;
113 case 'b':
114 if (strncmp(s, "bus", 3) == 0)
115 level_mask |= LOG_BUSSERVICE;
116 if (strncmp(s, "buf", 3) == 0)
117 level_mask |= LOG_BUFFER;
118 break;
119 case 'c':
120 level_mask |= LOG_CONNECT;
121 break;
122 case 'e':
123 level_mask |= LOG_ERROR;
124 break;
125 case 'm':
126 level_mask |= LOG_MESSAGES;
127 break;
128 case 'n':
129 if (strcmp(s, "none") == 0)
130 level_mask = 0;
131 break;
132 case 's':
133 level_mask |= LOG_FUNCTIONDONE;
134 break;
137 return 1;
140 __setup("fas216_logging=", fas216_log_setup);
142 static inline unsigned char fas216_readb(FAS216_Info *info, unsigned int reg)
144 unsigned int off = reg << info->scsi.io_shift;
145 if (info->scsi.io_base)
146 return readb(info->scsi.io_base + off);
147 else
148 return inb(info->scsi.io_port + off);
151 static inline void fas216_writeb(FAS216_Info *info, unsigned int reg, unsigned int val)
153 unsigned int off = reg << info->scsi.io_shift;
154 if (info->scsi.io_base)
155 writeb(val, info->scsi.io_base + off);
156 else
157 outb(val, info->scsi.io_port + off);
160 static void fas216_dumpstate(FAS216_Info *info)
162 unsigned char is, stat, inst;
164 is = fas216_readb(info, REG_IS);
165 stat = fas216_readb(info, REG_STAT);
166 inst = fas216_readb(info, REG_INST);
168 printk("FAS216: CTCL=%02X CTCM=%02X CMD=%02X STAT=%02X"
169 " INST=%02X IS=%02X CFIS=%02X",
170 fas216_readb(info, REG_CTCL),
171 fas216_readb(info, REG_CTCM),
172 fas216_readb(info, REG_CMD), stat, inst, is,
173 fas216_readb(info, REG_CFIS));
174 printk(" CNTL1=%02X CNTL2=%02X CNTL3=%02X CTCH=%02X\n",
175 fas216_readb(info, REG_CNTL1),
176 fas216_readb(info, REG_CNTL2),
177 fas216_readb(info, REG_CNTL3),
178 fas216_readb(info, REG_CTCH));
181 static void print_SCp(Scsi_Pointer *SCp, const char *prefix, const char *suffix)
183 printk("%sptr %p this_residual 0x%x buffer %p buffers_residual 0x%x%s",
184 prefix, SCp->ptr, SCp->this_residual, SCp->buffer,
185 SCp->buffers_residual, suffix);
188 static void fas216_dumpinfo(FAS216_Info *info)
190 static int used = 0;
191 int i;
193 if (used++)
194 return;
196 printk("FAS216_Info=\n");
197 printk(" { magic_start=%lX host=%p SCpnt=%p origSCpnt=%p\n",
198 info->magic_start, info->host, info->SCpnt,
199 info->origSCpnt);
200 printk(" scsi={ io_port=%X io_shift=%X irq=%X cfg={ %X %X %X %X }\n",
201 info->scsi.io_port, info->scsi.io_shift, info->scsi.irq,
202 info->scsi.cfg[0], info->scsi.cfg[1], info->scsi.cfg[2],
203 info->scsi.cfg[3]);
204 printk(" type=%p phase=%X\n",
205 info->scsi.type, info->scsi.phase);
206 print_SCp(&info->scsi.SCp, " SCp={ ", " }\n");
207 printk(" msgs async_stp=%X disconnectable=%d aborting=%d }\n",
208 info->scsi.async_stp,
209 info->scsi.disconnectable, info->scsi.aborting);
210 printk(" stats={ queues=%X removes=%X fins=%X reads=%X writes=%X miscs=%X\n"
211 " disconnects=%X aborts=%X bus_resets=%X host_resets=%X}\n",
212 info->stats.queues, info->stats.removes, info->stats.fins,
213 info->stats.reads, info->stats.writes, info->stats.miscs,
214 info->stats.disconnects, info->stats.aborts, info->stats.bus_resets,
215 info->stats.host_resets);
216 printk(" ifcfg={ clockrate=%X select_timeout=%X asyncperiod=%X sync_max_depth=%X }\n",
217 info->ifcfg.clockrate, info->ifcfg.select_timeout,
218 info->ifcfg.asyncperiod, info->ifcfg.sync_max_depth);
219 for (i = 0; i < 8; i++) {
220 printk(" busyluns[%d]=%08lx dev[%d]={ disconnect_ok=%d stp=%X sof=%X sync_state=%X }\n",
221 i, info->busyluns[i], i,
222 info->device[i].disconnect_ok, info->device[i].stp,
223 info->device[i].sof, info->device[i].sync_state);
225 printk(" dma={ transfer_type=%X setup=%p pseudo=%p stop=%p }\n",
226 info->dma.transfer_type, info->dma.setup,
227 info->dma.pseudo, info->dma.stop);
228 printk(" internal_done=%X magic_end=%lX }\n",
229 info->internal_done, info->magic_end);
232 #ifdef CHECK_STRUCTURE
233 static void __fas216_checkmagic(FAS216_Info *info, const char *func)
235 int corruption = 0;
236 if (info->magic_start != MAGIC) {
237 printk(KERN_CRIT "FAS216 Error: magic at start corrupted\n");
238 corruption++;
240 if (info->magic_end != MAGIC) {
241 printk(KERN_CRIT "FAS216 Error: magic at end corrupted\n");
242 corruption++;
244 if (corruption) {
245 fas216_dumpinfo(info);
246 panic("scsi memory space corrupted in %s", func);
249 #define fas216_checkmagic(info) __fas216_checkmagic((info), __FUNCTION__)
250 #else
251 #define fas216_checkmagic(info)
252 #endif
254 static const char *fas216_bus_phase(int stat)
256 static const char *phases[] = {
257 "DATA OUT", "DATA IN",
258 "COMMAND", "STATUS",
259 "MISC OUT", "MISC IN",
260 "MESG OUT", "MESG IN"
263 return phases[stat & STAT_BUSMASK];
266 static const char *fas216_drv_phase(FAS216_Info *info)
268 static const char *phases[] = {
269 [PHASE_IDLE] = "idle",
270 [PHASE_SELECTION] = "selection",
271 [PHASE_COMMAND] = "command",
272 [PHASE_DATAOUT] = "data out",
273 [PHASE_DATAIN] = "data in",
274 [PHASE_MSGIN] = "message in",
275 [PHASE_MSGIN_DISCONNECT]= "disconnect",
276 [PHASE_MSGOUT_EXPECT] = "expect message out",
277 [PHASE_MSGOUT] = "message out",
278 [PHASE_STATUS] = "status",
279 [PHASE_DONE] = "done",
282 if (info->scsi.phase < ARRAY_SIZE(phases) &&
283 phases[info->scsi.phase])
284 return phases[info->scsi.phase];
285 return "???";
288 static char fas216_target(FAS216_Info *info)
290 if (info->SCpnt)
291 return '0' + info->SCpnt->device->id;
292 else
293 return 'H';
296 static void
297 fas216_do_log(FAS216_Info *info, char target, char *fmt, va_list ap)
299 static char buf[1024];
301 vsnprintf(buf, sizeof(buf), fmt, ap);
302 printk("scsi%d.%c: %s", info->host->host_no, target, buf);
305 static void
306 fas216_log_command(FAS216_Info *info, int level, Scsi_Cmnd *SCpnt, char *fmt, ...)
308 va_list args;
310 if (level != 0 && !(level & level_mask))
311 return;
313 va_start(args, fmt);
314 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args);
315 va_end(args);
317 printk(" CDB: ");
318 print_command(SCpnt->cmnd);
321 static void
322 fas216_log_target(FAS216_Info *info, int level, int target, char *fmt, ...)
324 va_list args;
326 if (level != 0 && !(level & level_mask))
327 return;
329 if (target < 0)
330 target = 'H';
331 else
332 target += '0';
334 va_start(args, fmt);
335 fas216_do_log(info, target, fmt, args);
336 va_end(args);
338 printk("\n");
341 static void fas216_log(FAS216_Info *info, int level, char *fmt, ...)
343 va_list args;
345 if (level != 0 && !(level & level_mask))
346 return;
348 va_start(args, fmt);
349 fas216_do_log(info, fas216_target(info), fmt, args);
350 va_end(args);
352 printk("\n");
355 #define PH_SIZE 32
357 static struct { int stat, ssr, isr, ph; } ph_list[PH_SIZE];
358 static int ph_ptr;
360 static void add_debug_list(int stat, int ssr, int isr, int ph)
362 ph_list[ph_ptr].stat = stat;
363 ph_list[ph_ptr].ssr = ssr;
364 ph_list[ph_ptr].isr = isr;
365 ph_list[ph_ptr].ph = ph;
367 ph_ptr = (ph_ptr + 1) & (PH_SIZE-1);
370 static struct { int command; void *from; } cmd_list[8];
371 static int cmd_ptr;
373 static void fas216_cmd(FAS216_Info *info, unsigned int command)
375 cmd_list[cmd_ptr].command = command;
376 cmd_list[cmd_ptr].from = __builtin_return_address(0);
378 cmd_ptr = (cmd_ptr + 1) & 7;
380 fas216_writeb(info, REG_CMD, command);
383 static void print_debug_list(void)
385 int i;
387 i = ph_ptr;
389 printk(KERN_ERR "SCSI IRQ trail\n");
390 do {
391 printk(" %02x:%02x:%02x:%1x",
392 ph_list[i].stat, ph_list[i].ssr,
393 ph_list[i].isr, ph_list[i].ph);
394 i = (i + 1) & (PH_SIZE - 1);
395 if (((i ^ ph_ptr) & 7) == 0)
396 printk("\n");
397 } while (i != ph_ptr);
398 if ((i ^ ph_ptr) & 7)
399 printk("\n");
401 i = cmd_ptr;
402 printk(KERN_ERR "FAS216 commands: ");
403 do {
404 printk("%02x:%p ", cmd_list[i].command, cmd_list[i].from);
405 i = (i + 1) & 7;
406 } while (i != cmd_ptr);
407 printk("\n");
410 static void fas216_done(FAS216_Info *info, unsigned int result);
413 * fas216_get_last_msg - retrive last message from the list
414 * @info: interface to search
415 * @pos: current fifo position
417 * Retrieve a last message from the list, using position in fifo.
419 static inline unsigned short
420 fas216_get_last_msg(FAS216_Info *info, int pos)
422 unsigned short packed_msg = NOP;
423 struct message *msg;
424 int msgnr = 0;
426 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
427 if (pos >= msg->fifo)
428 break;
431 if (msg) {
432 if (msg->msg[0] == EXTENDED_MESSAGE)
433 packed_msg = EXTENDED_MESSAGE | msg->msg[2] << 8;
434 else
435 packed_msg = msg->msg[0];
438 fas216_log(info, LOG_MESSAGES,
439 "Message: %04x found at position %02x\n", packed_msg, pos);
441 return packed_msg;
445 * fas216_syncperiod - calculate STP register value
446 * @info: state structure for interface connected to device
447 * @ns: period in ns (between subsequent bytes)
449 * Calculate value to be loaded into the STP register for a given period
450 * in ns. Returns a value suitable for REG_STP.
452 static int fas216_syncperiod(FAS216_Info *info, int ns)
454 int value = (info->ifcfg.clockrate * ns) / 1000;
456 fas216_checkmagic(info);
458 if (value < 4)
459 value = 4;
460 else if (value > 35)
461 value = 35;
463 return value & 31;
467 * fas216_set_sync - setup FAS216 chip for specified transfer period.
468 * @info: state structure for interface connected to device
469 * @target: target
471 * Correctly setup FAS216 chip for specified transfer period.
472 * Notes : we need to switch the chip out of FASTSCSI mode if we have
473 * a transfer period >= 200ns - otherwise the chip will violate
474 * the SCSI timings.
476 static void fas216_set_sync(FAS216_Info *info, int target)
478 unsigned int cntl3;
480 fas216_writeb(info, REG_SOF, info->device[target].sof);
481 fas216_writeb(info, REG_STP, info->device[target].stp);
483 cntl3 = info->scsi.cfg[2];
484 if (info->device[target].period >= (200 / 4))
485 cntl3 = cntl3 & ~CNTL3_FASTSCSI;
487 fas216_writeb(info, REG_CNTL3, cntl3);
490 /* Synchronous transfer support
492 * Note: The SCSI II r10 spec says (5.6.12):
494 * (2) Due to historical problems with early host adapters that could
495 * not accept an SDTR message, some targets may not initiate synchronous
496 * negotiation after a power cycle as required by this standard. Host
497 * adapters that support synchronous mode may avoid the ensuing failure
498 * modes when the target is independently power cycled by initiating a
499 * synchronous negotiation on each REQUEST SENSE and INQUIRY command.
500 * This approach increases the SCSI bus overhead and is not recommended
501 * for new implementations. The correct method is to respond to an
502 * SDTR message with a MESSAGE REJECT message if the either the
503 * initiator or target devices does not support synchronous transfers
504 * or does not want to negotiate for synchronous transfers at the time.
505 * Using the correct method assures compatibility with wide data
506 * transfers and future enhancements.
508 * We will always initiate a synchronous transfer negotiation request on
509 * every INQUIRY or REQUEST SENSE message, unless the target itself has
510 * at some point performed a synchronous transfer negotiation request, or
511 * we have synchronous transfers disabled for this device.
515 * fas216_handlesync - Handle a synchronous transfer message
516 * @info: state structure for interface
517 * @msg: message from target
519 * Handle a synchronous transfer message from the target
521 static void fas216_handlesync(FAS216_Info *info, char *msg)
523 struct fas216_device *dev = &info->device[info->SCpnt->device->id];
524 enum { sync, async, none, reject } res = none;
526 #ifdef SCSI2_SYNC
527 switch (msg[0]) {
528 case MESSAGE_REJECT:
529 /* Synchronous transfer request failed.
530 * Note: SCSI II r10:
532 * SCSI devices that are capable of synchronous
533 * data transfers shall not respond to an SDTR
534 * message with a MESSAGE REJECT message.
536 * Hence, if we get this condition, we disable
537 * negotiation for this device.
539 if (dev->sync_state == neg_inprogress) {
540 dev->sync_state = neg_invalid;
541 res = async;
543 break;
545 case EXTENDED_MESSAGE:
546 switch (dev->sync_state) {
547 /* We don't accept synchronous transfer requests.
548 * Respond with a MESSAGE_REJECT to prevent a
549 * synchronous transfer agreement from being reached.
551 case neg_invalid:
552 res = reject;
553 break;
555 /* We were not negotiating a synchronous transfer,
556 * but the device sent us a negotiation request.
557 * Honour the request by sending back a SDTR
558 * message containing our capability, limited by
559 * the targets capability.
561 default:
562 fas216_cmd(info, CMD_SETATN);
563 if (msg[4] > info->ifcfg.sync_max_depth)
564 msg[4] = info->ifcfg.sync_max_depth;
565 if (msg[3] < 1000 / info->ifcfg.clockrate)
566 msg[3] = 1000 / info->ifcfg.clockrate;
568 msgqueue_flush(&info->scsi.msgs);
569 msgqueue_addmsg(&info->scsi.msgs, 5,
570 EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
571 msg[3], msg[4]);
572 info->scsi.phase = PHASE_MSGOUT_EXPECT;
574 /* This is wrong. The agreement is not in effect
575 * until this message is accepted by the device
577 dev->sync_state = neg_targcomplete;
578 res = sync;
579 break;
581 /* We initiated the synchronous transfer negotiation,
582 * and have successfully received a response from the
583 * target. The synchronous transfer agreement has been
584 * reached. Note: if the values returned are out of our
585 * bounds, we must reject the message.
587 case neg_inprogress:
588 res = reject;
589 if (msg[4] <= info->ifcfg.sync_max_depth &&
590 msg[3] >= 1000 / info->ifcfg.clockrate) {
591 dev->sync_state = neg_complete;
592 res = sync;
594 break;
597 #else
598 res = reject;
599 #endif
601 switch (res) {
602 case sync:
603 dev->period = msg[3];
604 dev->sof = msg[4];
605 dev->stp = fas216_syncperiod(info, msg[3] * 4);
606 fas216_set_sync(info, info->SCpnt->device->id);
607 break;
609 case reject:
610 fas216_cmd(info, CMD_SETATN);
611 msgqueue_flush(&info->scsi.msgs);
612 msgqueue_addmsg(&info->scsi.msgs, 1, MESSAGE_REJECT);
613 info->scsi.phase = PHASE_MSGOUT_EXPECT;
615 case async:
616 dev->period = info->ifcfg.asyncperiod / 4;
617 dev->sof = 0;
618 dev->stp = info->scsi.async_stp;
619 fas216_set_sync(info, info->SCpnt->device->id);
620 break;
622 case none:
623 break;
628 * fas216_updateptrs - update data pointers after transfer suspended/paused
629 * @info: interface's local pointer to update
630 * @bytes_transferred: number of bytes transferred
632 * Update data pointers after transfer suspended/paused
634 static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
636 Scsi_Pointer *SCp = &info->scsi.SCp;
638 fas216_checkmagic(info);
640 BUG_ON(bytes_transferred < 0);
642 info->SCpnt->request_bufflen -= bytes_transferred;
644 while (bytes_transferred != 0) {
645 if (SCp->this_residual > bytes_transferred)
646 break;
648 * We have used up this buffer. Move on to the
649 * next buffer.
651 bytes_transferred -= SCp->this_residual;
652 if (!next_SCp(SCp) && bytes_transferred) {
653 printk(KERN_WARNING "scsi%d.%c: out of buffers\n",
654 info->host->host_no, '0' + info->SCpnt->device->id);
655 return;
659 SCp->this_residual -= bytes_transferred;
660 if (SCp->this_residual)
661 SCp->ptr += bytes_transferred;
662 else
663 SCp->ptr = NULL;
667 * fas216_pio - transfer data off of/on to card using programmed IO
668 * @info: interface to transfer data to/from
669 * @direction: direction to transfer data (DMA_OUT/DMA_IN)
671 * Transfer data off of/on to card using programmed IO.
672 * Notes: this is incredibly slow.
674 static void fas216_pio(FAS216_Info *info, fasdmadir_t direction)
676 Scsi_Pointer *SCp = &info->scsi.SCp;
678 fas216_checkmagic(info);
680 if (direction == DMA_OUT)
681 fas216_writeb(info, REG_FF, get_next_SCp_byte(SCp));
682 else
683 put_next_SCp_byte(SCp, fas216_readb(info, REG_FF));
685 if (SCp->this_residual == 0)
686 next_SCp(SCp);
689 static void fas216_set_stc(FAS216_Info *info, unsigned int length)
691 fas216_writeb(info, REG_STCL, length);
692 fas216_writeb(info, REG_STCM, length >> 8);
693 fas216_writeb(info, REG_STCH, length >> 16);
696 static unsigned int fas216_get_ctc(FAS216_Info *info)
698 return fas216_readb(info, REG_CTCL) +
699 (fas216_readb(info, REG_CTCM) << 8) +
700 (fas216_readb(info, REG_CTCH) << 16);
704 * fas216_cleanuptransfer - clean up after a transfer has completed.
705 * @info: interface to clean up
707 * Update the data pointers according to the number of bytes transferred
708 * on the SCSI bus.
710 static void fas216_cleanuptransfer(FAS216_Info *info)
712 unsigned long total, residual, fifo;
713 fasdmatype_t dmatype = info->dma.transfer_type;
715 info->dma.transfer_type = fasdma_none;
718 * PIO transfers do not need to be cleaned up.
720 if (dmatype == fasdma_pio || dmatype == fasdma_none)
721 return;
723 if (dmatype == fasdma_real_all)
724 total = info->SCpnt->request_bufflen;
725 else
726 total = info->scsi.SCp.this_residual;
728 residual = fas216_get_ctc(info);
730 fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
732 fas216_log(info, LOG_BUFFER, "cleaning up from previous "
733 "transfer: length 0x%06x, residual 0x%x, fifo %d",
734 total, residual, fifo);
737 * If we were performing Data-Out, the transfer counter
738 * counts down each time a byte is transferred by the
739 * host to the FIFO. This means we must include the
740 * bytes left in the FIFO from the transfer counter.
742 if (info->scsi.phase == PHASE_DATAOUT)
743 residual += fifo;
745 fas216_updateptrs(info, total - residual);
749 * fas216_transfer - Perform a DMA/PIO transfer off of/on to card
750 * @info: interface from which device disconnected from
752 * Start a DMA/PIO transfer off of/on to card
754 static void fas216_transfer(FAS216_Info *info)
756 fasdmadir_t direction;
757 fasdmatype_t dmatype;
759 fas216_log(info, LOG_BUFFER,
760 "starttransfer: buffer %p length 0x%06x reqlen 0x%06x",
761 info->scsi.SCp.ptr, info->scsi.SCp.this_residual,
762 info->SCpnt->request_bufflen);
764 if (!info->scsi.SCp.ptr) {
765 fas216_log(info, LOG_ERROR, "null buffer passed to "
766 "fas216_starttransfer");
767 print_SCp(&info->scsi.SCp, "SCp: ", "\n");
768 print_SCp(&info->SCpnt->SCp, "Cmnd SCp: ", "\n");
769 return;
773 * If we have a synchronous transfer agreement in effect, we must
774 * use DMA mode. If we are using asynchronous transfers, we may
775 * use DMA mode or PIO mode.
777 if (info->device[info->SCpnt->device->id].sof)
778 dmatype = fasdma_real_all;
779 else
780 dmatype = fasdma_pio;
782 if (info->scsi.phase == PHASE_DATAOUT)
783 direction = DMA_OUT;
784 else
785 direction = DMA_IN;
787 if (info->dma.setup)
788 dmatype = info->dma.setup(info->host, &info->scsi.SCp,
789 direction, dmatype);
790 info->dma.transfer_type = dmatype;
792 if (dmatype == fasdma_real_all)
793 fas216_set_stc(info, info->SCpnt->request_bufflen);
794 else
795 fas216_set_stc(info, info->scsi.SCp.this_residual);
797 switch (dmatype) {
798 case fasdma_pio:
799 fas216_log(info, LOG_BUFFER, "PIO transfer");
800 fas216_writeb(info, REG_SOF, 0);
801 fas216_writeb(info, REG_STP, info->scsi.async_stp);
802 fas216_cmd(info, CMD_TRANSFERINFO);
803 fas216_pio(info, direction);
804 break;
806 case fasdma_pseudo:
807 fas216_log(info, LOG_BUFFER, "pseudo transfer");
808 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
809 info->dma.pseudo(info->host, &info->scsi.SCp,
810 direction, info->SCpnt->transfersize);
811 break;
813 case fasdma_real_block:
814 fas216_log(info, LOG_BUFFER, "block dma transfer");
815 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
816 break;
818 case fasdma_real_all:
819 fas216_log(info, LOG_BUFFER, "total dma transfer");
820 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
821 break;
823 default:
824 fas216_log(info, LOG_BUFFER | LOG_ERROR,
825 "invalid FAS216 DMA type");
826 break;
831 * fas216_stoptransfer - Stop a DMA transfer onto / off of the card
832 * @info: interface from which device disconnected from
834 * Called when we switch away from DATA IN or DATA OUT phases.
836 static void fas216_stoptransfer(FAS216_Info *info)
838 fas216_checkmagic(info);
840 if (info->dma.transfer_type == fasdma_real_all ||
841 info->dma.transfer_type == fasdma_real_block)
842 info->dma.stop(info->host, &info->scsi.SCp);
844 fas216_cleanuptransfer(info);
846 if (info->scsi.phase == PHASE_DATAIN) {
847 unsigned int fifo;
850 * If we were performing Data-In, then the FIFO counter
851 * contains the number of bytes not transferred via DMA
852 * from the on-board FIFO. Read them manually.
854 fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
855 while (fifo && info->scsi.SCp.ptr) {
856 *info->scsi.SCp.ptr = fas216_readb(info, REG_FF);
857 fas216_updateptrs(info, 1);
858 fifo--;
860 } else {
862 * After a Data-Out phase, there may be unsent
863 * bytes left in the FIFO. Flush them out.
865 fas216_cmd(info, CMD_FLUSHFIFO);
869 static void fas216_aborttransfer(FAS216_Info *info)
871 fas216_checkmagic(info);
873 if (info->dma.transfer_type == fasdma_real_all ||
874 info->dma.transfer_type == fasdma_real_block)
875 info->dma.stop(info->host, &info->scsi.SCp);
877 info->dma.transfer_type = fasdma_none;
878 fas216_cmd(info, CMD_FLUSHFIFO);
881 static void fas216_kick(FAS216_Info *info);
884 * fas216_disconnected_intr - handle device disconnection
885 * @info: interface from which device disconnected from
887 * Handle device disconnection
889 static void fas216_disconnect_intr(FAS216_Info *info)
891 unsigned long flags;
893 fas216_checkmagic(info);
895 fas216_log(info, LOG_CONNECT, "disconnect phase=%02x",
896 info->scsi.phase);
898 msgqueue_flush(&info->scsi.msgs);
900 switch (info->scsi.phase) {
901 case PHASE_SELECTION: /* while selecting - no target */
902 case PHASE_SELSTEPS:
903 fas216_done(info, DID_NO_CONNECT);
904 break;
906 case PHASE_MSGIN_DISCONNECT: /* message in - disconnecting */
907 info->scsi.disconnectable = 1;
908 info->scsi.phase = PHASE_IDLE;
909 info->stats.disconnects += 1;
910 spin_lock_irqsave(&info->host_lock, flags);
911 if (info->scsi.phase == PHASE_IDLE)
912 fas216_kick(info);
913 spin_unlock_irqrestore(&info->host_lock, flags);
914 break;
916 case PHASE_DONE: /* at end of command - complete */
917 fas216_done(info, DID_OK);
918 break;
920 case PHASE_MSGOUT: /* message out - possible ABORT message */
921 if (fas216_get_last_msg(info, info->scsi.msgin_fifo) == ABORT) {
922 info->scsi.aborting = 0;
923 fas216_done(info, DID_ABORT);
924 break;
927 default: /* huh? */
928 printk(KERN_ERR "scsi%d.%c: unexpected disconnect in phase %s\n",
929 info->host->host_no, fas216_target(info), fas216_drv_phase(info));
930 print_debug_list();
931 fas216_stoptransfer(info);
932 fas216_done(info, DID_ERROR);
933 break;
938 * fas216_reselected_intr - start reconnection of a device
939 * @info: interface which was reselected
941 * Start reconnection of a device
943 static void
944 fas216_reselected_intr(FAS216_Info *info)
946 unsigned int cfis, i;
947 unsigned char msg[4];
948 unsigned char target, lun, tag;
950 fas216_checkmagic(info);
952 WARN_ON(info->scsi.phase == PHASE_SELECTION ||
953 info->scsi.phase == PHASE_SELSTEPS);
955 cfis = fas216_readb(info, REG_CFIS);
957 fas216_log(info, LOG_CONNECT, "reconnect phase=%02x cfis=%02x",
958 info->scsi.phase, cfis);
960 cfis &= CFIS_CF;
962 if (cfis < 2 || cfis > 4) {
963 printk(KERN_ERR "scsi%d.H: incorrect number of bytes after reselect\n",
964 info->host->host_no);
965 goto bad_message;
968 for (i = 0; i < cfis; i++)
969 msg[i] = fas216_readb(info, REG_FF);
971 if (!(msg[0] & (1 << info->host->this_id)) ||
972 !(msg[1] & 0x80))
973 goto initiator_error;
975 target = msg[0] & ~(1 << info->host->this_id);
976 target = ffs(target) - 1;
977 lun = msg[1] & 7;
978 tag = 0;
980 if (cfis >= 3) {
981 if (msg[2] != SIMPLE_QUEUE_TAG)
982 goto initiator_error;
984 tag = msg[3];
987 /* set up for synchronous transfers */
988 fas216_writeb(info, REG_SDID, target);
989 fas216_set_sync(info, target);
990 msgqueue_flush(&info->scsi.msgs);
992 fas216_log(info, LOG_CONNECT, "Reconnected: target %1x lun %1x tag %02x",
993 target, lun, tag);
995 if (info->scsi.disconnectable && info->SCpnt) {
996 info->scsi.disconnectable = 0;
997 if (info->SCpnt->device->id == target &&
998 info->SCpnt->device->lun == lun &&
999 info->SCpnt->tag == tag) {
1000 fas216_log(info, LOG_CONNECT, "reconnected previously executing command");
1001 } else {
1002 queue_add_cmd_tail(&info->queues.disconnected, info->SCpnt);
1003 fas216_log(info, LOG_CONNECT, "had to move command to disconnected queue");
1004 info->SCpnt = NULL;
1007 if (!info->SCpnt) {
1008 info->SCpnt = queue_remove_tgtluntag(&info->queues.disconnected,
1009 target, lun, tag);
1010 fas216_log(info, LOG_CONNECT, "had to get command");
1013 if (info->SCpnt) {
1015 * Restore data pointer from SAVED data pointer
1017 info->scsi.SCp = info->SCpnt->SCp;
1019 fas216_log(info, LOG_CONNECT, "data pointers: [%p, %X]",
1020 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1021 info->scsi.phase = PHASE_MSGIN;
1022 } else {
1024 * Our command structure not found - abort the
1025 * command on the target. Since we have no
1026 * record of this command, we can't send
1027 * an INITIATOR DETECTED ERROR message.
1029 fas216_cmd(info, CMD_SETATN);
1031 #if 0
1032 if (tag)
1033 msgqueue_addmsg(&info->scsi.msgs, 2, ABORT_TAG, tag);
1034 else
1035 #endif
1036 msgqueue_addmsg(&info->scsi.msgs, 1, ABORT);
1037 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1038 info->scsi.aborting = 1;
1041 fas216_cmd(info, CMD_MSGACCEPTED);
1042 return;
1044 initiator_error:
1045 printk(KERN_ERR "scsi%d.H: error during reselection: bytes",
1046 info->host->host_no);
1047 for (i = 0; i < cfis; i++)
1048 printk(" %02x", msg[i]);
1049 printk("\n");
1050 bad_message:
1051 fas216_cmd(info, CMD_SETATN);
1052 msgqueue_flush(&info->scsi.msgs);
1053 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1054 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1055 fas216_cmd(info, CMD_MSGACCEPTED);
1058 static void fas216_parse_message(FAS216_Info *info, unsigned char *message, int msglen)
1060 int i;
1062 switch (message[0]) {
1063 case COMMAND_COMPLETE:
1064 if (msglen != 1)
1065 goto unrecognised;
1067 printk(KERN_ERR "scsi%d.%c: command complete with no "
1068 "status in MESSAGE_IN?\n",
1069 info->host->host_no, fas216_target(info));
1070 break;
1072 case SAVE_POINTERS:
1073 if (msglen != 1)
1074 goto unrecognised;
1077 * Save current data pointer to SAVED data pointer
1078 * SCSI II standard says that we must not acknowledge
1079 * this until we have really saved pointers.
1080 * NOTE: we DO NOT save the command nor status pointers
1081 * as required by the SCSI II standard. These always
1082 * point to the start of their respective areas.
1084 info->SCpnt->SCp = info->scsi.SCp;
1085 info->SCpnt->SCp.sent_command = 0;
1086 fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER,
1087 "save data pointers: [%p, %X]",
1088 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1089 break;
1091 case RESTORE_POINTERS:
1092 if (msglen != 1)
1093 goto unrecognised;
1096 * Restore current data pointer from SAVED data pointer
1098 info->scsi.SCp = info->SCpnt->SCp;
1099 fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER,
1100 "restore data pointers: [%p, 0x%x]",
1101 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1102 break;
1104 case DISCONNECT:
1105 if (msglen != 1)
1106 goto unrecognised;
1108 info->scsi.phase = PHASE_MSGIN_DISCONNECT;
1109 break;
1111 case MESSAGE_REJECT:
1112 if (msglen != 1)
1113 goto unrecognised;
1115 switch (fas216_get_last_msg(info, info->scsi.msgin_fifo)) {
1116 case EXTENDED_MESSAGE | EXTENDED_SDTR << 8:
1117 fas216_handlesync(info, message);
1118 break;
1120 default:
1121 fas216_log(info, 0, "reject, last message 0x%04x",
1122 fas216_get_last_msg(info, info->scsi.msgin_fifo));
1124 break;
1126 case NOP:
1127 break;
1129 case EXTENDED_MESSAGE:
1130 if (msglen < 3)
1131 goto unrecognised;
1133 switch (message[2]) {
1134 case EXTENDED_SDTR: /* Sync transfer negotiation request/reply */
1135 fas216_handlesync(info, message);
1136 break;
1138 default:
1139 goto unrecognised;
1141 break;
1143 default:
1144 goto unrecognised;
1146 return;
1148 unrecognised:
1149 fas216_log(info, 0, "unrecognised message, rejecting");
1150 printk("scsi%d.%c: message was", info->host->host_no, fas216_target(info));
1151 for (i = 0; i < msglen; i++)
1152 printk("%s%02X", i & 31 ? " " : "\n ", message[i]);
1153 printk("\n");
1156 * Something strange seems to be happening here -
1157 * I can't use SETATN since the chip gives me an
1158 * invalid command interrupt when I do. Weird.
1160 fas216_cmd(info, CMD_NOP);
1161 fas216_dumpstate(info);
1162 fas216_cmd(info, CMD_SETATN);
1163 msgqueue_flush(&info->scsi.msgs);
1164 msgqueue_addmsg(&info->scsi.msgs, 1, MESSAGE_REJECT);
1165 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1166 fas216_dumpstate(info);
1169 static int fas216_wait_cmd(FAS216_Info *info, int cmd)
1171 int tout;
1172 int stat;
1174 fas216_cmd(info, cmd);
1176 for (tout = 1000; tout; tout -= 1) {
1177 stat = fas216_readb(info, REG_STAT);
1178 if (stat & (STAT_INT|STAT_PARITYERROR))
1179 break;
1180 udelay(1);
1183 return stat;
1186 static int fas216_get_msg_byte(FAS216_Info *info)
1188 unsigned int stat = fas216_wait_cmd(info, CMD_MSGACCEPTED);
1190 if ((stat & STAT_INT) == 0)
1191 goto timedout;
1193 if ((stat & STAT_BUSMASK) != STAT_MESGIN)
1194 goto unexpected_phase_change;
1196 fas216_readb(info, REG_INST);
1198 stat = fas216_wait_cmd(info, CMD_TRANSFERINFO);
1200 if ((stat & STAT_INT) == 0)
1201 goto timedout;
1203 if (stat & STAT_PARITYERROR)
1204 goto parity_error;
1206 if ((stat & STAT_BUSMASK) != STAT_MESGIN)
1207 goto unexpected_phase_change;
1209 fas216_readb(info, REG_INST);
1211 return fas216_readb(info, REG_FF);
1213 timedout:
1214 fas216_log(info, LOG_ERROR, "timed out waiting for message byte");
1215 return -1;
1217 unexpected_phase_change:
1218 fas216_log(info, LOG_ERROR, "unexpected phase change: status = %02x", stat);
1219 return -2;
1221 parity_error:
1222 fas216_log(info, LOG_ERROR, "parity error during message in phase");
1223 return -3;
1227 * fas216_message - handle a function done interrupt from FAS216 chip
1228 * @info: interface which caused function done interrupt
1230 * Handle a function done interrupt from FAS216 chip
1232 static void fas216_message(FAS216_Info *info)
1234 unsigned char *message = info->scsi.message;
1235 unsigned int msglen = 1;
1236 int msgbyte = 0;
1238 fas216_checkmagic(info);
1240 message[0] = fas216_readb(info, REG_FF);
1242 if (message[0] == EXTENDED_MESSAGE) {
1243 msgbyte = fas216_get_msg_byte(info);
1245 if (msgbyte >= 0) {
1246 message[1] = msgbyte;
1248 for (msglen = 2; msglen < message[1] + 2; msglen++) {
1249 msgbyte = fas216_get_msg_byte(info);
1251 if (msgbyte >= 0)
1252 message[msglen] = msgbyte;
1253 else
1254 break;
1259 if (msgbyte == -3)
1260 goto parity_error;
1262 #ifdef DEBUG_MESSAGES
1264 int i;
1266 printk("scsi%d.%c: message in: ",
1267 info->host->host_no, fas216_target(info));
1268 for (i = 0; i < msglen; i++)
1269 printk("%02X ", message[i]);
1270 printk("\n");
1272 #endif
1274 fas216_parse_message(info, message, msglen);
1275 fas216_cmd(info, CMD_MSGACCEPTED);
1276 return;
1278 parity_error:
1279 fas216_cmd(info, CMD_SETATN);
1280 msgqueue_flush(&info->scsi.msgs);
1281 msgqueue_addmsg(&info->scsi.msgs, 1, MSG_PARITY_ERROR);
1282 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1283 fas216_cmd(info, CMD_MSGACCEPTED);
1284 return;
1288 * fas216_send_command - send command after all message bytes have been sent
1289 * @info: interface which caused bus service
1291 * Send a command to a target after all message bytes have been sent
1293 static void fas216_send_command(FAS216_Info *info)
1295 int i;
1297 fas216_checkmagic(info);
1299 fas216_cmd(info, CMD_NOP|CMD_WITHDMA);
1300 fas216_cmd(info, CMD_FLUSHFIFO);
1302 /* load command */
1303 for (i = info->scsi.SCp.sent_command; i < info->SCpnt->cmd_len; i++)
1304 fas216_writeb(info, REG_FF, info->SCpnt->cmnd[i]);
1306 fas216_cmd(info, CMD_TRANSFERINFO);
1308 info->scsi.phase = PHASE_COMMAND;
1312 * fas216_send_messageout - handle bus service to send a message
1313 * @info: interface which caused bus service
1315 * Handle bus service to send a message.
1316 * Note: We do not allow the device to change the data direction!
1318 static void fas216_send_messageout(FAS216_Info *info, int start)
1320 unsigned int tot_msglen = msgqueue_msglength(&info->scsi.msgs);
1322 fas216_checkmagic(info);
1324 fas216_cmd(info, CMD_FLUSHFIFO);
1326 if (tot_msglen) {
1327 struct message *msg;
1328 int msgnr = 0;
1330 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1331 int i;
1333 for (i = start; i < msg->length; i++)
1334 fas216_writeb(info, REG_FF, msg->msg[i]);
1336 msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
1337 start = 0;
1339 } else
1340 fas216_writeb(info, REG_FF, NOP);
1342 fas216_cmd(info, CMD_TRANSFERINFO);
1344 info->scsi.phase = PHASE_MSGOUT;
1348 * fas216_busservice_intr - handle bus service interrupt from FAS216 chip
1349 * @info: interface which caused bus service interrupt
1350 * @stat: Status register contents
1351 * @is: SCSI Status register contents
1353 * Handle a bus service interrupt from FAS216 chip
1355 static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigned int is)
1357 fas216_checkmagic(info);
1359 fas216_log(info, LOG_BUSSERVICE,
1360 "bus service: stat=%02x is=%02x phase=%02x",
1361 stat, is, info->scsi.phase);
1363 switch (info->scsi.phase) {
1364 case PHASE_SELECTION:
1365 if ((is & IS_BITS) != IS_MSGBYTESENT)
1366 goto bad_is;
1367 break;
1369 case PHASE_SELSTEPS:
1370 switch (is & IS_BITS) {
1371 case IS_SELARB:
1372 case IS_MSGBYTESENT:
1373 goto bad_is;
1375 case IS_NOTCOMMAND:
1376 case IS_EARLYPHASE:
1377 if ((stat & STAT_BUSMASK) == STAT_MESGIN)
1378 break;
1379 goto bad_is;
1381 case IS_COMPLETE:
1382 break;
1385 default:
1386 break;
1389 fas216_cmd(info, CMD_NOP);
1391 #define STATE(st,ph) ((ph) << 3 | (st))
1392 /* This table describes the legal SCSI state transitions,
1393 * as described by the SCSI II spec.
1395 switch (STATE(stat & STAT_BUSMASK, info->scsi.phase)) {
1396 case STATE(STAT_DATAIN, PHASE_SELSTEPS):/* Sel w/ steps -> Data In */
1397 case STATE(STAT_DATAIN, PHASE_MSGOUT): /* Message Out -> Data In */
1398 case STATE(STAT_DATAIN, PHASE_COMMAND): /* Command -> Data In */
1399 case STATE(STAT_DATAIN, PHASE_MSGIN): /* Message In -> Data In */
1400 info->scsi.phase = PHASE_DATAIN;
1401 fas216_transfer(info);
1402 return;
1404 case STATE(STAT_DATAIN, PHASE_DATAIN): /* Data In -> Data In */
1405 case STATE(STAT_DATAOUT, PHASE_DATAOUT):/* Data Out -> Data Out */
1406 fas216_cleanuptransfer(info);
1407 fas216_transfer(info);
1408 return;
1410 case STATE(STAT_DATAOUT, PHASE_SELSTEPS):/* Sel w/ steps-> Data Out */
1411 case STATE(STAT_DATAOUT, PHASE_MSGOUT): /* Message Out -> Data Out */
1412 case STATE(STAT_DATAOUT, PHASE_COMMAND):/* Command -> Data Out */
1413 case STATE(STAT_DATAOUT, PHASE_MSGIN): /* Message In -> Data Out */
1414 fas216_cmd(info, CMD_FLUSHFIFO);
1415 info->scsi.phase = PHASE_DATAOUT;
1416 fas216_transfer(info);
1417 return;
1419 case STATE(STAT_STATUS, PHASE_DATAOUT): /* Data Out -> Status */
1420 case STATE(STAT_STATUS, PHASE_DATAIN): /* Data In -> Status */
1421 fas216_stoptransfer(info);
1422 case STATE(STAT_STATUS, PHASE_SELSTEPS):/* Sel w/ steps -> Status */
1423 case STATE(STAT_STATUS, PHASE_MSGOUT): /* Message Out -> Status */
1424 case STATE(STAT_STATUS, PHASE_COMMAND): /* Command -> Status */
1425 case STATE(STAT_STATUS, PHASE_MSGIN): /* Message In -> Status */
1426 fas216_cmd(info, CMD_INITCMDCOMPLETE);
1427 info->scsi.phase = PHASE_STATUS;
1428 return;
1430 case STATE(STAT_MESGIN, PHASE_DATAOUT): /* Data Out -> Message In */
1431 case STATE(STAT_MESGIN, PHASE_DATAIN): /* Data In -> Message In */
1432 fas216_stoptransfer(info);
1433 case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */
1434 case STATE(STAT_MESGIN, PHASE_SELSTEPS):/* Sel w/ steps -> Message In */
1435 case STATE(STAT_MESGIN, PHASE_MSGOUT): /* Message Out -> Message In */
1436 info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
1437 fas216_cmd(info, CMD_FLUSHFIFO);
1438 fas216_cmd(info, CMD_TRANSFERINFO);
1439 info->scsi.phase = PHASE_MSGIN;
1440 return;
1442 case STATE(STAT_MESGIN, PHASE_MSGIN):
1443 info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
1444 fas216_cmd(info, CMD_TRANSFERINFO);
1445 return;
1447 case STATE(STAT_COMMAND, PHASE_MSGOUT): /* Message Out -> Command */
1448 case STATE(STAT_COMMAND, PHASE_MSGIN): /* Message In -> Command */
1449 fas216_send_command(info);
1450 info->scsi.phase = PHASE_COMMAND;
1451 return;
1455 * Selection -> Message Out
1457 case STATE(STAT_MESGOUT, PHASE_SELECTION):
1458 fas216_send_messageout(info, 1);
1459 return;
1462 * Message Out -> Message Out
1464 case STATE(STAT_MESGOUT, PHASE_SELSTEPS):
1465 case STATE(STAT_MESGOUT, PHASE_MSGOUT):
1467 * If we get another message out phase, this usually
1468 * means some parity error occurred. Resend complete
1469 * set of messages. If we have more than one byte to
1470 * send, we need to assert ATN again.
1472 if (info->device[info->SCpnt->device->id].parity_check) {
1474 * We were testing... good, the device
1475 * supports parity checking.
1477 info->device[info->SCpnt->device->id].parity_check = 0;
1478 info->device[info->SCpnt->device->id].parity_enabled = 1;
1479 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
1482 if (msgqueue_msglength(&info->scsi.msgs) > 1)
1483 fas216_cmd(info, CMD_SETATN);
1484 /*FALLTHROUGH*/
1487 * Any -> Message Out
1489 case STATE(STAT_MESGOUT, PHASE_MSGOUT_EXPECT):
1490 fas216_send_messageout(info, 0);
1491 return;
1493 /* Error recovery rules.
1494 * These either attempt to abort or retry the operation.
1495 * TODO: we need more of these
1497 case STATE(STAT_COMMAND, PHASE_COMMAND):/* Command -> Command */
1498 /* error - we've sent out all the command bytes
1499 * we have.
1500 * NOTE: we need SAVE DATA POINTERS/RESTORE DATA POINTERS
1501 * to include the command bytes sent for this to work
1502 * correctly.
1504 printk(KERN_ERR "scsi%d.%c: "
1505 "target trying to receive more command bytes\n",
1506 info->host->host_no, fas216_target(info));
1507 fas216_cmd(info, CMD_SETATN);
1508 fas216_set_stc(info, 15);
1509 fas216_cmd(info, CMD_PADBYTES | CMD_WITHDMA);
1510 msgqueue_flush(&info->scsi.msgs);
1511 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1512 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1513 return;
1516 if (info->scsi.phase == PHASE_MSGIN_DISCONNECT) {
1517 printk(KERN_ERR "scsi%d.%c: disconnect message received, but bus service %s?\n",
1518 info->host->host_no, fas216_target(info),
1519 fas216_bus_phase(stat));
1520 msgqueue_flush(&info->scsi.msgs);
1521 fas216_cmd(info, CMD_SETATN);
1522 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1523 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1524 info->scsi.aborting = 1;
1525 fas216_cmd(info, CMD_TRANSFERINFO);
1526 return;
1528 printk(KERN_ERR "scsi%d.%c: bus phase %s after %s?\n",
1529 info->host->host_no, fas216_target(info),
1530 fas216_bus_phase(stat),
1531 fas216_drv_phase(info));
1532 print_debug_list();
1533 return;
1535 bad_is:
1536 fas216_log(info, 0, "bus service at step %d?", is & IS_BITS);
1537 fas216_dumpstate(info);
1538 print_debug_list();
1540 fas216_done(info, DID_ERROR);
1544 * fas216_funcdone_intr - handle a function done interrupt from FAS216 chip
1545 * @info: interface which caused function done interrupt
1546 * @stat: Status register contents
1547 * @is: SCSI Status register contents
1549 * Handle a function done interrupt from FAS216 chip
1551 static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned int is)
1553 unsigned int fifo_len = fas216_readb(info, REG_CFIS) & CFIS_CF;
1555 fas216_checkmagic(info);
1557 fas216_log(info, LOG_FUNCTIONDONE,
1558 "function done: stat=%02x is=%02x phase=%02x",
1559 stat, is, info->scsi.phase);
1561 switch (info->scsi.phase) {
1562 case PHASE_STATUS: /* status phase - read status and msg */
1563 if (fifo_len != 2) {
1564 fas216_log(info, 0, "odd number of bytes in FIFO: %d", fifo_len);
1567 * Read status then message byte.
1569 info->scsi.SCp.Status = fas216_readb(info, REG_FF);
1570 info->scsi.SCp.Message = fas216_readb(info, REG_FF);
1571 info->scsi.phase = PHASE_DONE;
1572 fas216_cmd(info, CMD_MSGACCEPTED);
1573 break;
1575 case PHASE_IDLE:
1576 case PHASE_SELECTION:
1577 case PHASE_SELSTEPS:
1578 break;
1580 case PHASE_MSGIN: /* message in phase */
1581 if ((stat & STAT_BUSMASK) == STAT_MESGIN) {
1582 info->scsi.msgin_fifo = fifo_len;
1583 fas216_message(info);
1584 break;
1587 default:
1588 fas216_log(info, 0, "internal phase %s for function done?"
1589 " What do I do with this?",
1590 fas216_target(info), fas216_drv_phase(info));
1594 static void fas216_bus_reset(FAS216_Info *info)
1596 neg_t sync_state;
1597 int i;
1599 msgqueue_flush(&info->scsi.msgs);
1601 sync_state = neg_invalid;
1603 #ifdef SCSI2_SYNC
1604 if (info->ifcfg.capabilities & (FASCAP_DMA|FASCAP_PSEUDODMA))
1605 sync_state = neg_wait;
1606 #endif
1608 info->scsi.phase = PHASE_IDLE;
1609 info->SCpnt = NULL; /* bug! */
1610 memset(&info->scsi.SCp, 0, sizeof(info->scsi.SCp));
1612 for (i = 0; i < 8; i++) {
1613 info->device[i].disconnect_ok = info->ifcfg.disconnect_ok;
1614 info->device[i].sync_state = sync_state;
1615 info->device[i].period = info->ifcfg.asyncperiod / 4;
1616 info->device[i].stp = info->scsi.async_stp;
1617 info->device[i].sof = 0;
1618 info->device[i].wide_xfer = 0;
1621 info->rst_bus_status = 1;
1622 wake_up(&info->eh_wait);
1626 * fas216_intr - handle interrupts to progress a command
1627 * @info: interface to service
1629 * Handle interrupts from the interface to progress a command
1631 irqreturn_t fas216_intr(FAS216_Info *info)
1633 unsigned char inst, is, stat;
1634 int handled = IRQ_NONE;
1636 fas216_checkmagic(info);
1638 stat = fas216_readb(info, REG_STAT);
1639 is = fas216_readb(info, REG_IS);
1640 inst = fas216_readb(info, REG_INST);
1642 add_debug_list(stat, is, inst, info->scsi.phase);
1644 if (stat & STAT_INT) {
1645 if (inst & INST_BUSRESET) {
1646 fas216_log(info, 0, "bus reset detected");
1647 fas216_bus_reset(info);
1648 scsi_report_bus_reset(info->host, 0);
1649 } else if (inst & INST_ILLEGALCMD) {
1650 fas216_log(info, LOG_ERROR, "illegal command given\n");
1651 fas216_dumpstate(info);
1652 print_debug_list();
1653 } else if (inst & INST_DISCONNECT)
1654 fas216_disconnect_intr(info);
1655 else if (inst & INST_RESELECTED) /* reselected */
1656 fas216_reselected_intr(info);
1657 else if (inst & INST_BUSSERVICE) /* bus service request */
1658 fas216_busservice_intr(info, stat, is);
1659 else if (inst & INST_FUNCDONE) /* function done */
1660 fas216_funcdone_intr(info, stat, is);
1661 else
1662 fas216_log(info, 0, "unknown interrupt received:"
1663 " phase %s inst %02X is %02X stat %02X",
1664 fas216_drv_phase(info), inst, is, stat);
1665 handled = IRQ_HANDLED;
1667 return handled;
1670 static void __fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
1672 int tot_msglen;
1674 /* following what the ESP driver says */
1675 fas216_set_stc(info, 0);
1676 fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
1678 /* flush FIFO */
1679 fas216_cmd(info, CMD_FLUSHFIFO);
1681 /* load bus-id and timeout */
1682 fas216_writeb(info, REG_SDID, BUSID(SCpnt->device->id));
1683 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
1685 /* synchronous transfers */
1686 fas216_set_sync(info, SCpnt->device->id);
1688 tot_msglen = msgqueue_msglength(&info->scsi.msgs);
1690 #ifdef DEBUG_MESSAGES
1692 struct message *msg;
1693 int msgnr = 0, i;
1695 printk("scsi%d.%c: message out: ",
1696 info->host->host_no, '0' + SCpnt->device->id);
1697 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1698 printk("{ ");
1699 for (i = 0; i < msg->length; i++)
1700 printk("%02x ", msg->msg[i]);
1701 printk("} ");
1703 printk("\n");
1705 #endif
1707 if (tot_msglen == 1 || tot_msglen == 3) {
1709 * We have an easy message length to send...
1711 struct message *msg;
1712 int msgnr = 0, i;
1714 info->scsi.phase = PHASE_SELSTEPS;
1716 /* load message bytes */
1717 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1718 for (i = 0; i < msg->length; i++)
1719 fas216_writeb(info, REG_FF, msg->msg[i]);
1720 msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
1723 /* load command */
1724 for (i = 0; i < SCpnt->cmd_len; i++)
1725 fas216_writeb(info, REG_FF, SCpnt->cmnd[i]);
1727 if (tot_msglen == 1)
1728 fas216_cmd(info, CMD_SELECTATN);
1729 else
1730 fas216_cmd(info, CMD_SELECTATN3);
1731 } else {
1733 * We have an unusual number of message bytes to send.
1734 * Load first byte into fifo, and issue SELECT with ATN and
1735 * stop steps.
1737 struct message *msg = msgqueue_getmsg(&info->scsi.msgs, 0);
1739 fas216_writeb(info, REG_FF, msg->msg[0]);
1740 msg->fifo = 1;
1742 fas216_cmd(info, CMD_SELECTATNSTOP);
1747 * Decide whether we need to perform a parity test on this device.
1748 * Can also be used to force parity error conditions during initial
1749 * information transfer phase (message out) for test purposes.
1751 static int parity_test(FAS216_Info *info, int target)
1753 #if 0
1754 if (target == 3) {
1755 info->device[target].parity_check = 0;
1756 return 1;
1758 #endif
1759 return info->device[target].parity_check;
1762 static void fas216_start_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
1764 int disconnect_ok;
1767 * claim host busy
1769 info->scsi.phase = PHASE_SELECTION;
1770 info->scsi.SCp = SCpnt->SCp;
1771 info->SCpnt = SCpnt;
1772 info->dma.transfer_type = fasdma_none;
1774 if (parity_test(info, SCpnt->device->id))
1775 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_PTE);
1776 else
1777 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
1780 * Don't allow request sense commands to disconnect.
1782 disconnect_ok = SCpnt->cmnd[0] != REQUEST_SENSE &&
1783 info->device[SCpnt->device->id].disconnect_ok;
1786 * build outgoing message bytes
1788 msgqueue_flush(&info->scsi.msgs);
1789 msgqueue_addmsg(&info->scsi.msgs, 1, IDENTIFY(disconnect_ok, SCpnt->device->lun));
1792 * add tag message if required
1794 if (SCpnt->tag)
1795 msgqueue_addmsg(&info->scsi.msgs, 2, SIMPLE_QUEUE_TAG, SCpnt->tag);
1797 do {
1798 #ifdef SCSI2_SYNC
1799 if ((info->device[SCpnt->device->id].sync_state == neg_wait ||
1800 info->device[SCpnt->device->id].sync_state == neg_complete) &&
1801 (SCpnt->cmnd[0] == REQUEST_SENSE ||
1802 SCpnt->cmnd[0] == INQUIRY)) {
1803 info->device[SCpnt->device->id].sync_state = neg_inprogress;
1804 msgqueue_addmsg(&info->scsi.msgs, 5,
1805 EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
1806 1000 / info->ifcfg.clockrate,
1807 info->ifcfg.sync_max_depth);
1808 break;
1810 #endif
1811 } while (0);
1813 __fas216_start_command(info, SCpnt);
1816 static void fas216_allocate_tag(FAS216_Info *info, Scsi_Cmnd *SCpnt)
1818 #ifdef SCSI2_TAG
1820 * tagged queuing - allocate a new tag to this command
1822 if (SCpnt->device->simple_tags && SCpnt->cmnd[0] != REQUEST_SENSE &&
1823 SCpnt->cmnd[0] != INQUIRY) {
1824 SCpnt->device->current_tag += 1;
1825 if (SCpnt->device->current_tag == 0)
1826 SCpnt->device->current_tag = 1;
1827 SCpnt->tag = SCpnt->device->current_tag;
1828 } else
1829 #endif
1830 set_bit(SCpnt->device->id * 8 + SCpnt->device->lun, info->busyluns);
1832 info->stats.removes += 1;
1833 switch (SCpnt->cmnd[0]) {
1834 case WRITE_6:
1835 case WRITE_10:
1836 case WRITE_12:
1837 info->stats.writes += 1;
1838 break;
1839 case READ_6:
1840 case READ_10:
1841 case READ_12:
1842 info->stats.reads += 1;
1843 break;
1844 default:
1845 info->stats.miscs += 1;
1846 break;
1850 static void fas216_do_bus_device_reset(FAS216_Info *info, Scsi_Cmnd *SCpnt)
1852 struct message *msg;
1855 * claim host busy
1857 info->scsi.phase = PHASE_SELECTION;
1858 info->scsi.SCp = SCpnt->SCp;
1859 info->SCpnt = SCpnt;
1860 info->dma.transfer_type = fasdma_none;
1862 fas216_log(info, LOG_ERROR, "sending bus device reset");
1864 msgqueue_flush(&info->scsi.msgs);
1865 msgqueue_addmsg(&info->scsi.msgs, 1, BUS_DEVICE_RESET);
1867 /* following what the ESP driver says */
1868 fas216_set_stc(info, 0);
1869 fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
1871 /* flush FIFO */
1872 fas216_cmd(info, CMD_FLUSHFIFO);
1874 /* load bus-id and timeout */
1875 fas216_writeb(info, REG_SDID, BUSID(SCpnt->device->id));
1876 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
1878 /* synchronous transfers */
1879 fas216_set_sync(info, SCpnt->device->id);
1881 msg = msgqueue_getmsg(&info->scsi.msgs, 0);
1883 fas216_writeb(info, REG_FF, BUS_DEVICE_RESET);
1884 msg->fifo = 1;
1886 fas216_cmd(info, CMD_SELECTATNSTOP);
1890 * fas216_kick - kick a command to the interface
1891 * @info: our host interface to kick
1893 * Kick a command to the interface, interface should be idle.
1894 * Notes: Interrupts are always disabled!
1896 static void fas216_kick(FAS216_Info *info)
1898 Scsi_Cmnd *SCpnt = NULL;
1899 #define TYPE_OTHER 0
1900 #define TYPE_RESET 1
1901 #define TYPE_QUEUE 2
1902 int where_from = TYPE_OTHER;
1904 fas216_checkmagic(info);
1907 * Obtain the next command to process.
1909 do {
1910 if (info->rstSCpnt) {
1911 SCpnt = info->rstSCpnt;
1912 /* don't remove it */
1913 where_from = TYPE_RESET;
1914 break;
1917 if (info->reqSCpnt) {
1918 SCpnt = info->reqSCpnt;
1919 info->reqSCpnt = NULL;
1920 break;
1923 if (info->origSCpnt) {
1924 SCpnt = info->origSCpnt;
1925 info->origSCpnt = NULL;
1926 break;
1929 /* retrieve next command */
1930 if (!SCpnt) {
1931 SCpnt = queue_remove_exclude(&info->queues.issue,
1932 info->busyluns);
1933 where_from = TYPE_QUEUE;
1934 break;
1936 } while (0);
1938 if (!SCpnt) {
1940 * no command pending, so enable reselection.
1942 fas216_cmd(info, CMD_ENABLESEL);
1943 return;
1947 * We're going to start a command, so disable reselection
1949 fas216_cmd(info, CMD_DISABLESEL);
1951 if (info->scsi.disconnectable && info->SCpnt) {
1952 fas216_log(info, LOG_CONNECT,
1953 "moved command for %d to disconnected queue",
1954 info->SCpnt->device->id);
1955 queue_add_cmd_tail(&info->queues.disconnected, info->SCpnt);
1956 info->scsi.disconnectable = 0;
1957 info->SCpnt = NULL;
1960 fas216_log_command(info, LOG_CONNECT | LOG_MESSAGES, SCpnt,
1961 "starting");
1963 switch (where_from) {
1964 case TYPE_QUEUE:
1965 fas216_allocate_tag(info, SCpnt);
1966 case TYPE_OTHER:
1967 fas216_start_command(info, SCpnt);
1968 break;
1969 case TYPE_RESET:
1970 fas216_do_bus_device_reset(info, SCpnt);
1971 break;
1974 fas216_log(info, LOG_CONNECT, "select: data pointers [%p, %X]",
1975 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1978 * should now get either DISCONNECT or
1979 * (FUNCTION DONE with BUS SERVICE) interrupt
1984 * Clean up from issuing a BUS DEVICE RESET message to a device.
1986 static void
1987 fas216_devicereset_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
1989 fas216_log(info, LOG_ERROR, "fas216 device reset complete");
1991 info->rstSCpnt = NULL;
1992 info->rst_dev_status = 1;
1993 wake_up(&info->eh_wait);
1997 * fas216_rq_sns_done - Finish processing automatic request sense command
1998 * @info: interface that completed
1999 * @SCpnt: command that completed
2000 * @result: driver byte of result
2002 * Finish processing automatic request sense command
2004 static void
2005 fas216_rq_sns_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
2007 fas216_log_target(info, LOG_CONNECT, SCpnt->device->id,
2008 "request sense complete, result=0x%04x%02x%02x",
2009 result, SCpnt->SCp.Message, SCpnt->SCp.Status);
2011 if (result != DID_OK || SCpnt->SCp.Status != GOOD)
2013 * Something went wrong. Make sure that we don't
2014 * have valid data in the sense buffer that could
2015 * confuse the higher levels.
2017 memset(SCpnt->sense_buffer, 0, sizeof(SCpnt->sense_buffer));
2018 //printk("scsi%d.%c: sense buffer: ", info->host->host_no, '0' + SCpnt->device->id);
2019 //{ int i; for (i = 0; i < 32; i++) printk("%02x ", SCpnt->sense_buffer[i]); printk("\n"); }
2021 * Note that we don't set SCpnt->result, since that should
2022 * reflect the status of the command that we were asked by
2023 * the upper layers to process. This would have been set
2024 * correctly by fas216_std_done.
2026 SCpnt->scsi_done(SCpnt);
2030 * fas216_std_done - finish processing of standard command
2031 * @info: interface that completed
2032 * @SCpnt: command that completed
2033 * @result: driver byte of result
2035 * Finish processing of standard command
2037 static void
2038 fas216_std_done(FAS216_Info *info, Scsi_Cmnd *SCpnt, unsigned int result)
2040 info->stats.fins += 1;
2042 SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 |
2043 info->scsi.SCp.Status;
2045 fas216_log_command(info, LOG_CONNECT, SCpnt,
2046 "command complete, result=0x%08x", SCpnt->result);
2049 * If the driver detected an error, we're all done.
2051 if (host_byte(SCpnt->result) != DID_OK ||
2052 msg_byte(SCpnt->result) != COMMAND_COMPLETE)
2053 goto done;
2056 * If the command returned CHECK_CONDITION or COMMAND_TERMINATED
2057 * status, request the sense information.
2059 if (status_byte(SCpnt->result) == CHECK_CONDITION ||
2060 status_byte(SCpnt->result) == COMMAND_TERMINATED)
2061 goto request_sense;
2064 * If the command did not complete with GOOD status,
2065 * we are all done here.
2067 if (status_byte(SCpnt->result) != GOOD)
2068 goto done;
2071 * We have successfully completed a command. Make sure that
2072 * we do not have any buffers left to transfer. The world
2073 * is not perfect, and we seem to occasionally hit this.
2074 * It can be indicative of a buggy driver, target or the upper
2075 * levels of the SCSI code.
2077 if (info->scsi.SCp.ptr) {
2078 switch (SCpnt->cmnd[0]) {
2079 case INQUIRY:
2080 case START_STOP:
2081 case MODE_SENSE:
2082 break;
2084 default:
2085 printk(KERN_ERR "scsi%d.%c: incomplete data transfer "
2086 "detected: res=%08X ptr=%p len=%X CDB: ",
2087 info->host->host_no, '0' + SCpnt->device->id,
2088 SCpnt->result, info->scsi.SCp.ptr,
2089 info->scsi.SCp.this_residual);
2090 print_command(SCpnt->cmnd);
2091 SCpnt->result &= ~(255 << 16);
2092 SCpnt->result |= DID_BAD_TARGET << 16;
2093 goto request_sense;
2097 done:
2098 if (SCpnt->scsi_done) {
2099 SCpnt->scsi_done(SCpnt);
2100 return;
2103 panic("scsi%d.H: null scsi_done function in fas216_done",
2104 info->host->host_no);
2107 request_sense:
2108 if (SCpnt->cmnd[0] == REQUEST_SENSE)
2109 goto done;
2111 fas216_log_target(info, LOG_CONNECT, SCpnt->device->id,
2112 "requesting sense");
2113 memset(SCpnt->cmnd, 0, sizeof (SCpnt->cmnd));
2114 SCpnt->cmnd[0] = REQUEST_SENSE;
2115 SCpnt->cmnd[1] = SCpnt->device->lun << 5;
2116 SCpnt->cmnd[4] = sizeof(SCpnt->sense_buffer);
2117 SCpnt->cmd_len = COMMAND_SIZE(SCpnt->cmnd[0]);
2118 SCpnt->SCp.buffer = NULL;
2119 SCpnt->SCp.buffers_residual = 0;
2120 SCpnt->SCp.ptr = (char *)SCpnt->sense_buffer;
2121 SCpnt->SCp.this_residual = sizeof(SCpnt->sense_buffer);
2122 SCpnt->SCp.Message = 0;
2123 SCpnt->SCp.Status = 0;
2124 SCpnt->request_bufflen = sizeof(SCpnt->sense_buffer);
2125 SCpnt->sc_data_direction = SCSI_DATA_READ;
2126 SCpnt->use_sg = 0;
2127 SCpnt->tag = 0;
2128 SCpnt->host_scribble = (void *)fas216_rq_sns_done;
2131 * Place this command into the high priority "request
2132 * sense" slot. This will be the very next command
2133 * executed, unless a target connects to us.
2135 if (info->reqSCpnt)
2136 printk(KERN_WARNING "scsi%d.%c: loosing request command\n",
2137 info->host->host_no, '0' + SCpnt->device->id);
2138 info->reqSCpnt = SCpnt;
2142 * fas216_done - complete processing for current command
2143 * @info: interface that completed
2144 * @result: driver byte of result
2146 * Complete processing for current command
2148 static void fas216_done(FAS216_Info *info, unsigned int result)
2150 void (*fn)(FAS216_Info *, Scsi_Cmnd *, unsigned int);
2151 Scsi_Cmnd *SCpnt;
2152 unsigned long flags;
2154 fas216_checkmagic(info);
2156 if (!info->SCpnt)
2157 goto no_command;
2159 SCpnt = info->SCpnt;
2160 info->SCpnt = NULL;
2161 info->scsi.phase = PHASE_IDLE;
2163 if (info->scsi.aborting) {
2164 fas216_log(info, 0, "uncaught abort - returning DID_ABORT");
2165 result = DID_ABORT;
2166 info->scsi.aborting = 0;
2170 * Sanity check the completion - if we have zero bytes left
2171 * to transfer, we should not have a valid pointer.
2173 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
2174 printk("scsi%d.%c: zero bytes left to transfer, but "
2175 "buffer pointer still valid: ptr=%p len=%08x CDB: ",
2176 info->host->host_no, '0' + SCpnt->device->id,
2177 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2178 info->scsi.SCp.ptr = NULL;
2179 print_command(SCpnt->cmnd);
2183 * Clear down this command as completed. If we need to request
2184 * the sense information, fas216_kick will re-assert the busy
2185 * status.
2187 info->device[SCpnt->device->id].parity_check = 0;
2188 clear_bit(SCpnt->device->id * 8 + SCpnt->device->lun, info->busyluns);
2190 fn = (void (*)(FAS216_Info *, Scsi_Cmnd *, unsigned int))SCpnt->host_scribble;
2191 fn(info, SCpnt, result);
2193 if (info->scsi.irq != NO_IRQ) {
2194 spin_lock_irqsave(&info->host_lock, flags);
2195 if (info->scsi.phase == PHASE_IDLE)
2196 fas216_kick(info);
2197 spin_unlock_irqrestore(&info->host_lock, flags);
2199 return;
2201 no_command:
2202 panic("scsi%d.H: null command in fas216_done",
2203 info->host->host_no);
2207 * fas216_queue_command - queue a command for adapter to process.
2208 * @SCpnt: Command to queue
2209 * @done: done function to call once command is complete
2211 * Queue a command for adapter to process.
2212 * Returns: 0 on success, else error.
2213 * Notes: io_request_lock is held, interrupts are disabled.
2215 int fas216_queue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
2217 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2218 int result;
2220 fas216_checkmagic(info);
2222 fas216_log_command(info, LOG_CONNECT, SCpnt,
2223 "received command (%p)", SCpnt);
2225 SCpnt->scsi_done = done;
2226 SCpnt->host_scribble = (void *)fas216_std_done;
2227 SCpnt->result = 0;
2229 init_SCp(SCpnt);
2231 info->stats.queues += 1;
2232 SCpnt->tag = 0;
2234 spin_lock(&info->host_lock);
2237 * Add command into execute queue and let it complete under
2238 * whatever scheme we're using.
2240 result = !queue_add_cmd_ordered(&info->queues.issue, SCpnt);
2243 * If we successfully added the command,
2244 * kick the interface to get it moving.
2246 if (result == 0 && info->scsi.phase == PHASE_IDLE)
2247 fas216_kick(info);
2248 spin_unlock(&info->host_lock);
2250 fas216_log_target(info, LOG_CONNECT, -1, "queue %s",
2251 result ? "failure" : "success");
2253 return result;
2257 * fas216_internal_done - trigger restart of a waiting thread in fas216_noqueue_command
2258 * @SCpnt: Command to wake
2260 * Trigger restart of a waiting thread in fas216_command
2262 static void fas216_internal_done(Scsi_Cmnd *SCpnt)
2264 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2266 fas216_checkmagic(info);
2268 info->internal_done = 1;
2272 * fas216_noqueue_command - process a command for the adapter.
2273 * @SCpnt: Command to queue
2275 * Queue a command for adapter to process.
2276 * Returns: scsi result code.
2277 * Notes: io_request_lock is held, interrupts are disabled.
2279 int fas216_noqueue_command(Scsi_Cmnd *SCpnt, void (*done)(Scsi_Cmnd *))
2281 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2283 fas216_checkmagic(info);
2286 * We should only be using this if we don't have an interrupt.
2287 * Provide some "incentive" to use the queueing code.
2289 BUG_ON(info->scsi.irq != NO_IRQ);
2291 info->internal_done = 0;
2292 fas216_queue_command(SCpnt, fas216_internal_done);
2295 * This wastes time, since we can't return until the command is
2296 * complete. We can't sleep either since we may get re-entered!
2297 * However, we must re-enable interrupts, or else we'll be
2298 * waiting forever.
2300 spin_unlock_irq(info->host->host_lock);
2302 while (!info->internal_done) {
2304 * If we don't have an IRQ, then we must poll the card for
2305 * it's interrupt, and use that to call this driver's
2306 * interrupt routine. That way, we keep the command
2307 * progressing. Maybe we can add some inteligence here
2308 * and go to sleep if we know that the device is going
2309 * to be some time (eg, disconnected).
2311 if (fas216_readb(info, REG_STAT) & STAT_INT) {
2312 spin_lock_irq(info->host->host_lock);
2313 fas216_intr(info);
2314 spin_unlock_irq(info->host->host_lock);
2318 spin_lock_irq(info->host->host_lock);
2320 done(SCpnt);
2322 return 0;
2326 * Error handler timeout function. Indicate that we timed out,
2327 * and wake up any error handler process so it can continue.
2329 static void fas216_eh_timer(unsigned long data)
2331 FAS216_Info *info = (FAS216_Info *)data;
2333 fas216_log(info, LOG_ERROR, "error handling timed out\n");
2335 del_timer(&info->eh_timer);
2337 if (info->rst_bus_status == 0)
2338 info->rst_bus_status = -1;
2339 if (info->rst_dev_status == 0)
2340 info->rst_dev_status = -1;
2342 wake_up(&info->eh_wait);
2345 enum res_find {
2346 res_failed, /* not found */
2347 res_success, /* command on issue queue */
2348 res_hw_abort /* command on disconnected dev */
2352 * fas216_do_abort - decide how to abort a command
2353 * @SCpnt: command to abort
2355 * Decide how to abort a command.
2356 * Returns: abort status
2358 static enum res_find fas216_find_command(FAS216_Info *info, Scsi_Cmnd *SCpnt)
2360 enum res_find res = res_failed;
2362 if (queue_remove_cmd(&info->queues.issue, SCpnt)) {
2364 * The command was on the issue queue, and has not been
2365 * issued yet. We can remove the command from the queue,
2366 * and acknowledge the abort. Neither the device nor the
2367 * interface know about the command.
2369 printk("on issue queue ");
2371 res = res_success;
2372 } else if (queue_remove_cmd(&info->queues.disconnected, SCpnt)) {
2374 * The command was on the disconnected queue. We must
2375 * reconnect with the device if possible, and send it
2376 * an abort message.
2378 printk("on disconnected queue ");
2380 res = res_hw_abort;
2381 } else if (info->SCpnt == SCpnt) {
2382 printk("executing ");
2384 switch (info->scsi.phase) {
2386 * If the interface is idle, and the command is 'disconnectable',
2387 * then it is the same as on the disconnected queue.
2389 case PHASE_IDLE:
2390 if (info->scsi.disconnectable) {
2391 info->scsi.disconnectable = 0;
2392 info->SCpnt = NULL;
2393 res = res_hw_abort;
2395 break;
2397 default:
2398 break;
2400 } else if (info->origSCpnt == SCpnt) {
2402 * The command will be executed next, but a command
2403 * is currently using the interface. This is similar to
2404 * being on the issue queue, except the busylun bit has
2405 * been set.
2407 info->origSCpnt = NULL;
2408 clear_bit(SCpnt->device->id * 8 + SCpnt->device->lun, info->busyluns);
2409 printk("waiting for execution ");
2410 res = res_success;
2411 } else
2412 printk("unknown ");
2414 return res;
2418 * fas216_eh_abort - abort this command
2419 * @SCpnt: command to abort
2421 * Abort this command.
2422 * Returns: FAILED if unable to abort
2423 * Notes: io_request_lock is taken, and irqs are disabled
2425 int fas216_eh_abort(Scsi_Cmnd *SCpnt)
2427 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2428 int result = FAILED;
2430 fas216_checkmagic(info);
2432 info->stats.aborts += 1;
2434 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no);
2435 print_command(SCpnt->data_cmnd);
2437 print_debug_list();
2438 fas216_dumpstate(info);
2440 printk(KERN_WARNING "scsi%d: abort %p ", info->host->host_no, SCpnt);
2442 switch (fas216_find_command(info, SCpnt)) {
2444 * We found the command, and cleared it out. Either
2445 * the command is still known to be executing on the
2446 * target, or the busylun bit is not set.
2448 case res_success:
2449 printk("success\n");
2450 result = SUCCESS;
2451 break;
2454 * We need to reconnect to the target and send it an
2455 * ABORT or ABORT_TAG message. We can only do this
2456 * if the bus is free.
2458 case res_hw_abort:
2462 * We are unable to abort the command for some reason.
2464 default:
2465 case res_failed:
2466 printk("failed\n");
2467 break;
2470 return result;
2474 * fas216_eh_device_reset - Reset the device associated with this command
2475 * @SCpnt: command specifing device to reset
2477 * Reset the device associated with this command.
2478 * Returns: FAILED if unable to reset.
2479 * Notes: We won't be re-entered, so we'll only have one device
2480 * reset on the go at one time.
2482 int fas216_eh_device_reset(Scsi_Cmnd *SCpnt)
2484 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2485 unsigned long flags;
2486 int i, res = FAILED, target = SCpnt->device->id;
2488 fas216_log(info, LOG_ERROR, "device reset for target %d", target);
2490 spin_lock_irqsave(&info->host_lock, flags);
2492 do {
2494 * If we are currently connected to a device, and
2495 * it is the device we want to reset, there is
2496 * nothing we can do here. Chances are it is stuck,
2497 * and we need a bus reset.
2499 if (info->SCpnt && !info->scsi.disconnectable &&
2500 info->SCpnt->device->id == SCpnt->device->id)
2501 break;
2504 * We're going to be resetting this device. Remove
2505 * all pending commands from the driver. By doing
2506 * so, we guarantee that we won't touch the command
2507 * structures except to process the reset request.
2509 queue_remove_all_target(&info->queues.issue, target);
2510 queue_remove_all_target(&info->queues.disconnected, target);
2511 if (info->origSCpnt && info->origSCpnt->device->id == target)
2512 info->origSCpnt = NULL;
2513 if (info->reqSCpnt && info->reqSCpnt->device->id == target)
2514 info->reqSCpnt = NULL;
2515 for (i = 0; i < 8; i++)
2516 clear_bit(target * 8 + i, info->busyluns);
2519 * Hijack this SCSI command structure to send
2520 * a bus device reset message to this device.
2522 SCpnt->host_scribble = (void *)fas216_devicereset_done;
2524 info->rst_dev_status = 0;
2525 info->rstSCpnt = SCpnt;
2527 if (info->scsi.phase == PHASE_IDLE)
2528 fas216_kick(info);
2530 mod_timer(&info->eh_timer, 30 * HZ);
2531 spin_unlock_irqrestore(&info->host_lock, flags);
2534 * Wait up to 30 seconds for the reset to complete.
2536 wait_event(info->eh_wait, info->rst_dev_status);
2538 del_timer_sync(&info->eh_timer);
2539 spin_lock_irqsave(&info->host_lock, flags);
2540 info->rstSCpnt = NULL;
2542 if (info->rst_dev_status == 1)
2543 res = SUCCESS;
2544 } while (0);
2546 SCpnt->host_scribble = NULL;
2547 spin_unlock_irqrestore(&info->host_lock, flags);
2549 fas216_log(info, LOG_ERROR, "device reset complete: %s\n",
2550 res == SUCCESS ? "success" : "failed");
2552 return res;
2556 * fas216_eh_bus_reset - Reset the bus associated with the command
2557 * @SCpnt: command specifing bus to reset
2559 * Reset the bus associated with the command.
2560 * Returns: FAILED if unable to reset.
2561 * Notes: Further commands are blocked.
2563 int fas216_eh_bus_reset(Scsi_Cmnd *SCpnt)
2565 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2566 unsigned long flags;
2567 Scsi_Device *SDpnt;
2569 fas216_checkmagic(info);
2570 fas216_log(info, LOG_ERROR, "resetting bus");
2572 info->stats.bus_resets += 1;
2574 spin_lock_irqsave(&info->host_lock, flags);
2577 * Stop all activity on this interface.
2579 fas216_aborttransfer(info);
2580 fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
2583 * Clear any pending interrupts.
2585 while (fas216_readb(info, REG_STAT) & STAT_INT)
2586 fas216_readb(info, REG_INST);
2588 info->rst_bus_status = 0;
2591 * For each attached hard-reset device, clear out
2592 * all command structures. Leave the running
2593 * command in place.
2595 shost_for_each_device(SDpnt, info->host) {
2596 int i;
2598 if (SDpnt->soft_reset)
2599 continue;
2601 queue_remove_all_target(&info->queues.issue, SDpnt->id);
2602 queue_remove_all_target(&info->queues.disconnected, SDpnt->id);
2603 if (info->origSCpnt && info->origSCpnt->device->id == SDpnt->id)
2604 info->origSCpnt = NULL;
2605 if (info->reqSCpnt && info->reqSCpnt->device->id == SDpnt->id)
2606 info->reqSCpnt = NULL;
2607 info->SCpnt = NULL;
2609 for (i = 0; i < 8; i++)
2610 clear_bit(SDpnt->id * 8 + i, info->busyluns);
2613 info->scsi.phase = PHASE_IDLE;
2616 * Reset the SCSI bus. Device cleanup happens in
2617 * the interrupt handler.
2619 fas216_cmd(info, CMD_RESETSCSI);
2621 mod_timer(&info->eh_timer, jiffies + HZ);
2622 spin_unlock_irqrestore(&info->host_lock, flags);
2625 * Wait one second for the interrupt.
2627 wait_event(info->eh_wait, info->rst_bus_status);
2628 del_timer_sync(&info->eh_timer);
2630 fas216_log(info, LOG_ERROR, "bus reset complete: %s\n",
2631 info->rst_bus_status == 1 ? "success" : "failed");
2633 return info->rst_bus_status == 1 ? SUCCESS : FAILED;
2637 * fas216_init_chip - Initialise FAS216 state after reset
2638 * @info: state structure for interface
2640 * Initialise FAS216 state after reset
2642 static void fas216_init_chip(FAS216_Info *info)
2644 unsigned int clock = ((info->ifcfg.clockrate - 1) / 5 + 1) & 7;
2645 fas216_writeb(info, REG_CLKF, clock);
2646 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2647 fas216_writeb(info, REG_CNTL2, info->scsi.cfg[1]);
2648 fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
2649 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
2650 fas216_writeb(info, REG_SOF, 0);
2651 fas216_writeb(info, REG_STP, info->scsi.async_stp);
2652 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2656 * fas216_eh_host_reset - Reset the host associated with this command
2657 * @SCpnt: command specifing host to reset
2659 * Reset the host associated with this command.
2660 * Returns: FAILED if unable to reset.
2661 * Notes: io_request_lock is taken, and irqs are disabled
2663 int fas216_eh_host_reset(Scsi_Cmnd *SCpnt)
2665 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2667 fas216_checkmagic(info);
2669 printk("scsi%d.%c: %s: resetting host\n",
2670 info->host->host_no, '0' + SCpnt->device->id, __FUNCTION__);
2673 * Reset the SCSI chip.
2675 fas216_cmd(info, CMD_RESETCHIP);
2678 * Ugly ugly ugly!
2679 * We need to release the host_lock and enable
2680 * IRQs if we sleep, but we must relock and disable
2681 * IRQs after the sleep.
2683 spin_unlock_irq(info->host->host_lock);
2684 msleep(50 * 1000/100);
2685 spin_lock_irq(info->host->host_lock);
2688 * Release the SCSI reset.
2690 fas216_cmd(info, CMD_NOP);
2692 fas216_init_chip(info);
2694 return SUCCESS;
2697 #define TYPE_UNKNOWN 0
2698 #define TYPE_NCR53C90 1
2699 #define TYPE_NCR53C90A 2
2700 #define TYPE_NCR53C9x 3
2701 #define TYPE_Am53CF94 4
2702 #define TYPE_EmFAS216 5
2703 #define TYPE_QLFAS216 6
2705 static char *chip_types[] = {
2706 "unknown",
2707 "NS NCR53C90",
2708 "NS NCR53C90A",
2709 "NS NCR53C9x",
2710 "AMD Am53CF94",
2711 "Emulex FAS216",
2712 "QLogic FAS216"
2715 static int fas216_detect_type(FAS216_Info *info)
2717 int family, rev;
2720 * Reset the chip.
2722 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2723 udelay(50);
2724 fas216_writeb(info, REG_CMD, CMD_NOP);
2727 * Check to see if control reg 2 is present.
2729 fas216_writeb(info, REG_CNTL3, 0);
2730 fas216_writeb(info, REG_CNTL2, CNTL2_S2FE);
2733 * If we are unable to read back control reg 2
2734 * correctly, it is not present, and we have a
2735 * NCR53C90.
2737 if ((fas216_readb(info, REG_CNTL2) & (~0xe0)) != CNTL2_S2FE)
2738 return TYPE_NCR53C90;
2741 * Now, check control register 3
2743 fas216_writeb(info, REG_CNTL2, 0);
2744 fas216_writeb(info, REG_CNTL3, 0);
2745 fas216_writeb(info, REG_CNTL3, 5);
2748 * If we are unable to read the register back
2749 * correctly, we have a NCR53C90A
2751 if (fas216_readb(info, REG_CNTL3) != 5)
2752 return TYPE_NCR53C90A;
2755 * Now read the ID from the chip.
2757 fas216_writeb(info, REG_CNTL3, 0);
2759 fas216_writeb(info, REG_CNTL3, CNTL3_ADIDCHK);
2760 fas216_writeb(info, REG_CNTL3, 0);
2762 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2763 udelay(50);
2764 fas216_writeb(info, REG_CMD, CMD_WITHDMA | CMD_NOP);
2766 fas216_writeb(info, REG_CNTL2, CNTL2_ENF);
2767 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2768 udelay(50);
2769 fas216_writeb(info, REG_CMD, CMD_NOP);
2771 rev = fas216_readb(info, REG_ID);
2772 family = rev >> 3;
2773 rev &= 7;
2775 switch (family) {
2776 case 0x01:
2777 if (rev == 4)
2778 return TYPE_Am53CF94;
2779 break;
2781 case 0x02:
2782 switch (rev) {
2783 case 2:
2784 return TYPE_EmFAS216;
2785 case 3:
2786 return TYPE_QLFAS216;
2788 break;
2790 default:
2791 break;
2793 printk("family %x rev %x\n", family, rev);
2794 return TYPE_NCR53C9x;
2798 * fas216_reset_state - Initialise driver internal state
2799 * @info: state to initialise
2801 * Initialise driver internal state
2803 static void fas216_reset_state(FAS216_Info *info)
2805 int i;
2807 fas216_checkmagic(info);
2809 fas216_bus_reset(info);
2812 * Clear out all stale info in our state structure
2814 memset(info->busyluns, 0, sizeof(info->busyluns));
2815 info->scsi.disconnectable = 0;
2816 info->scsi.aborting = 0;
2818 for (i = 0; i < 8; i++) {
2819 info->device[i].parity_enabled = 0;
2820 info->device[i].parity_check = 1;
2824 * Drain all commands on disconnected queue
2826 while (queue_remove(&info->queues.disconnected) != NULL);
2829 * Remove executing commands.
2831 info->SCpnt = NULL;
2832 info->reqSCpnt = NULL;
2833 info->rstSCpnt = NULL;
2834 info->origSCpnt = NULL;
2838 * fas216_init - initialise FAS/NCR/AMD SCSI structures.
2839 * @host: a driver-specific filled-out structure
2841 * Initialise FAS/NCR/AMD SCSI structures.
2842 * Returns: 0 on success
2844 int fas216_init(struct Scsi_Host *host)
2846 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2848 info->magic_start = MAGIC;
2849 info->magic_end = MAGIC;
2850 info->host = host;
2851 info->scsi.cfg[0] = host->this_id | CNTL1_PERE;
2852 info->scsi.cfg[1] = CNTL2_ENF | CNTL2_S2FE;
2853 info->scsi.cfg[2] = info->ifcfg.cntl3 |
2854 CNTL3_ADIDCHK | CNTL3_QTAG | CNTL3_G2CB | CNTL3_LBTM;
2855 info->scsi.async_stp = fas216_syncperiod(info, info->ifcfg.asyncperiod);
2857 info->rst_dev_status = -1;
2858 info->rst_bus_status = -1;
2859 init_waitqueue_head(&info->eh_wait);
2860 init_timer(&info->eh_timer);
2861 info->eh_timer.data = (unsigned long)info;
2862 info->eh_timer.function = fas216_eh_timer;
2864 spin_lock_init(&info->host_lock);
2866 memset(&info->stats, 0, sizeof(info->stats));
2868 msgqueue_initialise(&info->scsi.msgs);
2870 if (!queue_initialise(&info->queues.issue))
2871 return -ENOMEM;
2873 if (!queue_initialise(&info->queues.disconnected)) {
2874 queue_free(&info->queues.issue);
2875 return -ENOMEM;
2878 return 0;
2882 * fas216_add - initialise FAS/NCR/AMD SCSI ic.
2883 * @host: a driver-specific filled-out structure
2884 * @dev: parent device
2886 * Initialise FAS/NCR/AMD SCSI ic.
2887 * Returns: 0 on success
2889 int fas216_add(struct Scsi_Host *host, struct device *dev)
2891 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2892 int type, ret;
2894 if (info->ifcfg.clockrate <= 10 || info->ifcfg.clockrate > 40) {
2895 printk(KERN_CRIT "fas216: invalid clock rate %u MHz\n",
2896 info->ifcfg.clockrate);
2897 return -EINVAL;
2900 fas216_reset_state(info);
2901 type = fas216_detect_type(info);
2902 info->scsi.type = chip_types[type];
2904 udelay(300);
2907 * Initialise the chip correctly.
2909 fas216_init_chip(info);
2912 * Reset the SCSI bus. We don't want to see
2913 * the resulting reset interrupt, so mask it
2914 * out.
2916 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_DISR);
2917 fas216_writeb(info, REG_CMD, CMD_RESETSCSI);
2920 * scsi standard says wait 250ms
2922 spin_unlock_irq(info->host->host_lock);
2923 msleep(100*1000/100);
2924 spin_lock_irq(info->host->host_lock);
2926 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2927 fas216_readb(info, REG_INST);
2929 fas216_checkmagic(info);
2931 ret = scsi_add_host(host, dev);
2932 if (ret)
2933 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2934 else
2935 scsi_scan_host(host);
2937 return ret;
2940 void fas216_remove(struct Scsi_Host *host)
2942 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2944 fas216_checkmagic(info);
2945 scsi_remove_host(host);
2947 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2948 scsi_host_put(host);
2952 * fas216_release - release all resources for FAS/NCR/AMD SCSI ic.
2953 * @host: a driver-specific filled-out structure
2955 * release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
2957 void fas216_release(struct Scsi_Host *host)
2959 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2961 queue_free(&info->queues.disconnected);
2962 queue_free(&info->queues.issue);
2965 int fas216_print_host(FAS216_Info *info, char *buffer)
2967 return sprintf(buffer,
2968 "\n"
2969 "Chip : %s\n"
2970 " Address: 0x%08lx\n"
2971 " IRQ : %d\n"
2972 " DMA : %d\n",
2973 info->scsi.type, info->host->io_port,
2974 info->host->irq, info->host->dma_channel);
2977 int fas216_print_stats(FAS216_Info *info, char *buffer)
2979 char *p = buffer;
2981 p += sprintf(p, "\n"
2982 "Command Statistics:\n"
2983 " Queued : %u\n"
2984 " Issued : %u\n"
2985 " Completed : %u\n"
2986 " Reads : %u\n"
2987 " Writes : %u\n"
2988 " Others : %u\n"
2989 " Disconnects: %u\n"
2990 " Aborts : %u\n"
2991 " Bus resets : %u\n"
2992 " Host resets: %u\n",
2993 info->stats.queues, info->stats.removes,
2994 info->stats.fins, info->stats.reads,
2995 info->stats.writes, info->stats.miscs,
2996 info->stats.disconnects, info->stats.aborts,
2997 info->stats.bus_resets, info->stats.host_resets);
2999 return p - buffer;
3002 int fas216_print_devices(FAS216_Info *info, char *buffer)
3004 struct fas216_device *dev;
3005 Scsi_Device *scd;
3006 char *p = buffer;
3008 p += sprintf(p, "Device/Lun TaggedQ Parity Sync\n");
3010 shost_for_each_device(scd, info->host) {
3011 dev = &info->device[scd->id];
3012 p += sprintf(p, " %d/%d ", scd->id, scd->lun);
3013 if (scd->tagged_supported)
3014 p += sprintf(p, "%3sabled(%3d) ",
3015 scd->simple_tags ? "en" : "dis",
3016 scd->current_tag);
3017 else
3018 p += sprintf(p, "unsupported ");
3020 p += sprintf(p, "%3sabled ", dev->parity_enabled ? "en" : "dis");
3022 if (dev->sof)
3023 p += sprintf(p, "offset %d, %d ns\n",
3024 dev->sof, dev->period * 4);
3025 else
3026 p += sprintf(p, "async\n");
3029 return p - buffer;
3032 EXPORT_SYMBOL(fas216_init);
3033 EXPORT_SYMBOL(fas216_add);
3034 EXPORT_SYMBOL(fas216_queue_command);
3035 EXPORT_SYMBOL(fas216_noqueue_command);
3036 EXPORT_SYMBOL(fas216_intr);
3037 EXPORT_SYMBOL(fas216_remove);
3038 EXPORT_SYMBOL(fas216_release);
3039 EXPORT_SYMBOL(fas216_eh_abort);
3040 EXPORT_SYMBOL(fas216_eh_device_reset);
3041 EXPORT_SYMBOL(fas216_eh_bus_reset);
3042 EXPORT_SYMBOL(fas216_eh_host_reset);
3043 EXPORT_SYMBOL(fas216_print_host);
3044 EXPORT_SYMBOL(fas216_print_stats);
3045 EXPORT_SYMBOL(fas216_print_devices);
3047 MODULE_AUTHOR("Russell King");
3048 MODULE_DESCRIPTION("Generic FAS216/NCR53C9x driver core");
3049 MODULE_LICENSE("GPL");