scsi: fas216: fix sense buffer initialization
[linux/fpc-iii.git] / drivers / scsi / arm / fas216.c
blob80aa67df41fd7dd071fd0a215b8ec5fdd1e6b23a
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/proc_fs.h>
43 #include <linux/delay.h>
44 #include <linux/bitops.h>
45 #include <linux/init.h>
46 #include <linux/interrupt.h>
48 #include <asm/dma.h>
49 #include <asm/io.h>
50 #include <asm/irq.h>
51 #include <asm/ecard.h>
53 #include "../scsi.h"
54 #include <scsi/scsi_dbg.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_param(level_mask, int, 0644);
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 return readb(info->scsi.io_base + off);
148 static inline void fas216_writeb(FAS216_Info *info, unsigned int reg, unsigned int val)
150 unsigned int off = reg << info->scsi.io_shift;
151 writeb(val, info->scsi.io_base + off);
154 static void fas216_dumpstate(FAS216_Info *info)
156 unsigned char is, stat, inst;
158 is = fas216_readb(info, REG_IS);
159 stat = fas216_readb(info, REG_STAT);
160 inst = fas216_readb(info, REG_INST);
162 printk("FAS216: CTCL=%02X CTCM=%02X CMD=%02X STAT=%02X"
163 " INST=%02X IS=%02X CFIS=%02X",
164 fas216_readb(info, REG_CTCL),
165 fas216_readb(info, REG_CTCM),
166 fas216_readb(info, REG_CMD), stat, inst, is,
167 fas216_readb(info, REG_CFIS));
168 printk(" CNTL1=%02X CNTL2=%02X CNTL3=%02X CTCH=%02X\n",
169 fas216_readb(info, REG_CNTL1),
170 fas216_readb(info, REG_CNTL2),
171 fas216_readb(info, REG_CNTL3),
172 fas216_readb(info, REG_CTCH));
175 static void print_SCp(struct scsi_pointer *SCp, const char *prefix, const char *suffix)
177 printk("%sptr %p this_residual 0x%x buffer %p buffers_residual 0x%x%s",
178 prefix, SCp->ptr, SCp->this_residual, SCp->buffer,
179 SCp->buffers_residual, suffix);
182 #ifdef CHECK_STRUCTURE
183 static void fas216_dumpinfo(FAS216_Info *info)
185 static int used = 0;
186 int i;
188 if (used++)
189 return;
191 printk("FAS216_Info=\n");
192 printk(" { magic_start=%lX host=%p SCpnt=%p origSCpnt=%p\n",
193 info->magic_start, info->host, info->SCpnt,
194 info->origSCpnt);
195 printk(" scsi={ io_shift=%X irq=%X cfg={ %X %X %X %X }\n",
196 info->scsi.io_shift, info->scsi.irq,
197 info->scsi.cfg[0], info->scsi.cfg[1], info->scsi.cfg[2],
198 info->scsi.cfg[3]);
199 printk(" type=%p phase=%X\n",
200 info->scsi.type, info->scsi.phase);
201 print_SCp(&info->scsi.SCp, " SCp={ ", " }\n");
202 printk(" msgs async_stp=%X disconnectable=%d aborting=%d }\n",
203 info->scsi.async_stp,
204 info->scsi.disconnectable, info->scsi.aborting);
205 printk(" stats={ queues=%X removes=%X fins=%X reads=%X writes=%X miscs=%X\n"
206 " disconnects=%X aborts=%X bus_resets=%X host_resets=%X}\n",
207 info->stats.queues, info->stats.removes, info->stats.fins,
208 info->stats.reads, info->stats.writes, info->stats.miscs,
209 info->stats.disconnects, info->stats.aborts, info->stats.bus_resets,
210 info->stats.host_resets);
211 printk(" ifcfg={ clockrate=%X select_timeout=%X asyncperiod=%X sync_max_depth=%X }\n",
212 info->ifcfg.clockrate, info->ifcfg.select_timeout,
213 info->ifcfg.asyncperiod, info->ifcfg.sync_max_depth);
214 for (i = 0; i < 8; i++) {
215 printk(" busyluns[%d]=%08lx dev[%d]={ disconnect_ok=%d stp=%X sof=%X sync_state=%X }\n",
216 i, info->busyluns[i], i,
217 info->device[i].disconnect_ok, info->device[i].stp,
218 info->device[i].sof, info->device[i].sync_state);
220 printk(" dma={ transfer_type=%X setup=%p pseudo=%p stop=%p }\n",
221 info->dma.transfer_type, info->dma.setup,
222 info->dma.pseudo, info->dma.stop);
223 printk(" internal_done=%X magic_end=%lX }\n",
224 info->internal_done, info->magic_end);
227 static void __fas216_checkmagic(FAS216_Info *info, const char *func)
229 int corruption = 0;
230 if (info->magic_start != MAGIC) {
231 printk(KERN_CRIT "FAS216 Error: magic at start corrupted\n");
232 corruption++;
234 if (info->magic_end != MAGIC) {
235 printk(KERN_CRIT "FAS216 Error: magic at end corrupted\n");
236 corruption++;
238 if (corruption) {
239 fas216_dumpinfo(info);
240 panic("scsi memory space corrupted in %s", func);
243 #define fas216_checkmagic(info) __fas216_checkmagic((info), __func__)
244 #else
245 #define fas216_checkmagic(info)
246 #endif
248 static const char *fas216_bus_phase(int stat)
250 static const char *phases[] = {
251 "DATA OUT", "DATA IN",
252 "COMMAND", "STATUS",
253 "MISC OUT", "MISC IN",
254 "MESG OUT", "MESG IN"
257 return phases[stat & STAT_BUSMASK];
260 static const char *fas216_drv_phase(FAS216_Info *info)
262 static const char *phases[] = {
263 [PHASE_IDLE] = "idle",
264 [PHASE_SELECTION] = "selection",
265 [PHASE_COMMAND] = "command",
266 [PHASE_DATAOUT] = "data out",
267 [PHASE_DATAIN] = "data in",
268 [PHASE_MSGIN] = "message in",
269 [PHASE_MSGIN_DISCONNECT]= "disconnect",
270 [PHASE_MSGOUT_EXPECT] = "expect message out",
271 [PHASE_MSGOUT] = "message out",
272 [PHASE_STATUS] = "status",
273 [PHASE_DONE] = "done",
276 if (info->scsi.phase < ARRAY_SIZE(phases) &&
277 phases[info->scsi.phase])
278 return phases[info->scsi.phase];
279 return "???";
282 static char fas216_target(FAS216_Info *info)
284 if (info->SCpnt)
285 return '0' + info->SCpnt->device->id;
286 else
287 return 'H';
290 static void
291 fas216_do_log(FAS216_Info *info, char target, char *fmt, va_list ap)
293 static char buf[1024];
295 vsnprintf(buf, sizeof(buf), fmt, ap);
296 printk("scsi%d.%c: %s", info->host->host_no, target, buf);
299 static void fas216_log_command(FAS216_Info *info, int level,
300 struct scsi_cmnd *SCpnt, char *fmt, ...)
302 va_list args;
304 if (level != 0 && !(level & level_mask))
305 return;
307 va_start(args, fmt);
308 fas216_do_log(info, '0' + SCpnt->device->id, fmt, args);
309 va_end(args);
311 printk(" CDB: ");
312 __scsi_print_command(SCpnt->cmnd);
315 static void
316 fas216_log_target(FAS216_Info *info, int level, int target, char *fmt, ...)
318 va_list args;
320 if (level != 0 && !(level & level_mask))
321 return;
323 if (target < 0)
324 target = 'H';
325 else
326 target += '0';
328 va_start(args, fmt);
329 fas216_do_log(info, target, fmt, args);
330 va_end(args);
332 printk("\n");
335 static void fas216_log(FAS216_Info *info, int level, char *fmt, ...)
337 va_list args;
339 if (level != 0 && !(level & level_mask))
340 return;
342 va_start(args, fmt);
343 fas216_do_log(info, fas216_target(info), fmt, args);
344 va_end(args);
346 printk("\n");
349 #define PH_SIZE 32
351 static struct { int stat, ssr, isr, ph; } ph_list[PH_SIZE];
352 static int ph_ptr;
354 static void add_debug_list(int stat, int ssr, int isr, int ph)
356 ph_list[ph_ptr].stat = stat;
357 ph_list[ph_ptr].ssr = ssr;
358 ph_list[ph_ptr].isr = isr;
359 ph_list[ph_ptr].ph = ph;
361 ph_ptr = (ph_ptr + 1) & (PH_SIZE-1);
364 static struct { int command; void *from; } cmd_list[8];
365 static int cmd_ptr;
367 static void fas216_cmd(FAS216_Info *info, unsigned int command)
369 cmd_list[cmd_ptr].command = command;
370 cmd_list[cmd_ptr].from = __builtin_return_address(0);
372 cmd_ptr = (cmd_ptr + 1) & 7;
374 fas216_writeb(info, REG_CMD, command);
377 static void print_debug_list(void)
379 int i;
381 i = ph_ptr;
383 printk(KERN_ERR "SCSI IRQ trail\n");
384 do {
385 printk(" %02x:%02x:%02x:%1x",
386 ph_list[i].stat, ph_list[i].ssr,
387 ph_list[i].isr, ph_list[i].ph);
388 i = (i + 1) & (PH_SIZE - 1);
389 if (((i ^ ph_ptr) & 7) == 0)
390 printk("\n");
391 } while (i != ph_ptr);
392 if ((i ^ ph_ptr) & 7)
393 printk("\n");
395 i = cmd_ptr;
396 printk(KERN_ERR "FAS216 commands: ");
397 do {
398 printk("%02x:%p ", cmd_list[i].command, cmd_list[i].from);
399 i = (i + 1) & 7;
400 } while (i != cmd_ptr);
401 printk("\n");
404 static void fas216_done(FAS216_Info *info, unsigned int result);
407 * fas216_get_last_msg - retrive last message from the list
408 * @info: interface to search
409 * @pos: current fifo position
411 * Retrieve a last message from the list, using position in fifo.
413 static inline unsigned short
414 fas216_get_last_msg(FAS216_Info *info, int pos)
416 unsigned short packed_msg = NOP;
417 struct message *msg;
418 int msgnr = 0;
420 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
421 if (pos >= msg->fifo)
422 break;
425 if (msg) {
426 if (msg->msg[0] == EXTENDED_MESSAGE)
427 packed_msg = EXTENDED_MESSAGE | msg->msg[2] << 8;
428 else
429 packed_msg = msg->msg[0];
432 fas216_log(info, LOG_MESSAGES,
433 "Message: %04x found at position %02x\n", packed_msg, pos);
435 return packed_msg;
439 * fas216_syncperiod - calculate STP register value
440 * @info: state structure for interface connected to device
441 * @ns: period in ns (between subsequent bytes)
443 * Calculate value to be loaded into the STP register for a given period
444 * in ns. Returns a value suitable for REG_STP.
446 static int fas216_syncperiod(FAS216_Info *info, int ns)
448 int value = (info->ifcfg.clockrate * ns) / 1000;
450 fas216_checkmagic(info);
452 if (value < 4)
453 value = 4;
454 else if (value > 35)
455 value = 35;
457 return value & 31;
461 * fas216_set_sync - setup FAS216 chip for specified transfer period.
462 * @info: state structure for interface connected to device
463 * @target: target
465 * Correctly setup FAS216 chip for specified transfer period.
466 * Notes : we need to switch the chip out of FASTSCSI mode if we have
467 * a transfer period >= 200ns - otherwise the chip will violate
468 * the SCSI timings.
470 static void fas216_set_sync(FAS216_Info *info, int target)
472 unsigned int cntl3;
474 fas216_writeb(info, REG_SOF, info->device[target].sof);
475 fas216_writeb(info, REG_STP, info->device[target].stp);
477 cntl3 = info->scsi.cfg[2];
478 if (info->device[target].period >= (200 / 4))
479 cntl3 = cntl3 & ~CNTL3_FASTSCSI;
481 fas216_writeb(info, REG_CNTL3, cntl3);
484 /* Synchronous transfer support
486 * Note: The SCSI II r10 spec says (5.6.12):
488 * (2) Due to historical problems with early host adapters that could
489 * not accept an SDTR message, some targets may not initiate synchronous
490 * negotiation after a power cycle as required by this standard. Host
491 * adapters that support synchronous mode may avoid the ensuing failure
492 * modes when the target is independently power cycled by initiating a
493 * synchronous negotiation on each REQUEST SENSE and INQUIRY command.
494 * This approach increases the SCSI bus overhead and is not recommended
495 * for new implementations. The correct method is to respond to an
496 * SDTR message with a MESSAGE REJECT message if the either the
497 * initiator or target devices does not support synchronous transfers
498 * or does not want to negotiate for synchronous transfers at the time.
499 * Using the correct method assures compatibility with wide data
500 * transfers and future enhancements.
502 * We will always initiate a synchronous transfer negotiation request on
503 * every INQUIRY or REQUEST SENSE message, unless the target itself has
504 * at some point performed a synchronous transfer negotiation request, or
505 * we have synchronous transfers disabled for this device.
509 * fas216_handlesync - Handle a synchronous transfer message
510 * @info: state structure for interface
511 * @msg: message from target
513 * Handle a synchronous transfer message from the target
515 static void fas216_handlesync(FAS216_Info *info, char *msg)
517 struct fas216_device *dev = &info->device[info->SCpnt->device->id];
518 enum { sync, async, none, reject } res = none;
520 #ifdef SCSI2_SYNC
521 switch (msg[0]) {
522 case MESSAGE_REJECT:
523 /* Synchronous transfer request failed.
524 * Note: SCSI II r10:
526 * SCSI devices that are capable of synchronous
527 * data transfers shall not respond to an SDTR
528 * message with a MESSAGE REJECT message.
530 * Hence, if we get this condition, we disable
531 * negotiation for this device.
533 if (dev->sync_state == neg_inprogress) {
534 dev->sync_state = neg_invalid;
535 res = async;
537 break;
539 case EXTENDED_MESSAGE:
540 switch (dev->sync_state) {
541 /* We don't accept synchronous transfer requests.
542 * Respond with a MESSAGE_REJECT to prevent a
543 * synchronous transfer agreement from being reached.
545 case neg_invalid:
546 res = reject;
547 break;
549 /* We were not negotiating a synchronous transfer,
550 * but the device sent us a negotiation request.
551 * Honour the request by sending back a SDTR
552 * message containing our capability, limited by
553 * the targets capability.
555 default:
556 fas216_cmd(info, CMD_SETATN);
557 if (msg[4] > info->ifcfg.sync_max_depth)
558 msg[4] = info->ifcfg.sync_max_depth;
559 if (msg[3] < 1000 / info->ifcfg.clockrate)
560 msg[3] = 1000 / info->ifcfg.clockrate;
562 msgqueue_flush(&info->scsi.msgs);
563 msgqueue_addmsg(&info->scsi.msgs, 5,
564 EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
565 msg[3], msg[4]);
566 info->scsi.phase = PHASE_MSGOUT_EXPECT;
568 /* This is wrong. The agreement is not in effect
569 * until this message is accepted by the device
571 dev->sync_state = neg_targcomplete;
572 res = sync;
573 break;
575 /* We initiated the synchronous transfer negotiation,
576 * and have successfully received a response from the
577 * target. The synchronous transfer agreement has been
578 * reached. Note: if the values returned are out of our
579 * bounds, we must reject the message.
581 case neg_inprogress:
582 res = reject;
583 if (msg[4] <= info->ifcfg.sync_max_depth &&
584 msg[3] >= 1000 / info->ifcfg.clockrate) {
585 dev->sync_state = neg_complete;
586 res = sync;
588 break;
591 #else
592 res = reject;
593 #endif
595 switch (res) {
596 case sync:
597 dev->period = msg[3];
598 dev->sof = msg[4];
599 dev->stp = fas216_syncperiod(info, msg[3] * 4);
600 fas216_set_sync(info, info->SCpnt->device->id);
601 break;
603 case reject:
604 fas216_cmd(info, CMD_SETATN);
605 msgqueue_flush(&info->scsi.msgs);
606 msgqueue_addmsg(&info->scsi.msgs, 1, MESSAGE_REJECT);
607 info->scsi.phase = PHASE_MSGOUT_EXPECT;
609 case async:
610 dev->period = info->ifcfg.asyncperiod / 4;
611 dev->sof = 0;
612 dev->stp = info->scsi.async_stp;
613 fas216_set_sync(info, info->SCpnt->device->id);
614 break;
616 case none:
617 break;
622 * fas216_updateptrs - update data pointers after transfer suspended/paused
623 * @info: interface's local pointer to update
624 * @bytes_transferred: number of bytes transferred
626 * Update data pointers after transfer suspended/paused
628 static void fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
630 struct scsi_pointer *SCp = &info->scsi.SCp;
632 fas216_checkmagic(info);
634 BUG_ON(bytes_transferred < 0);
636 SCp->phase -= bytes_transferred;
638 while (bytes_transferred != 0) {
639 if (SCp->this_residual > bytes_transferred)
640 break;
642 * We have used up this buffer. Move on to the
643 * next buffer.
645 bytes_transferred -= SCp->this_residual;
646 if (!next_SCp(SCp) && bytes_transferred) {
647 printk(KERN_WARNING "scsi%d.%c: out of buffers\n",
648 info->host->host_no, '0' + info->SCpnt->device->id);
649 return;
653 SCp->this_residual -= bytes_transferred;
654 if (SCp->this_residual)
655 SCp->ptr += bytes_transferred;
656 else
657 SCp->ptr = NULL;
661 * fas216_pio - transfer data off of/on to card using programmed IO
662 * @info: interface to transfer data to/from
663 * @direction: direction to transfer data (DMA_OUT/DMA_IN)
665 * Transfer data off of/on to card using programmed IO.
666 * Notes: this is incredibly slow.
668 static void fas216_pio(FAS216_Info *info, fasdmadir_t direction)
670 struct scsi_pointer *SCp = &info->scsi.SCp;
672 fas216_checkmagic(info);
674 if (direction == DMA_OUT)
675 fas216_writeb(info, REG_FF, get_next_SCp_byte(SCp));
676 else
677 put_next_SCp_byte(SCp, fas216_readb(info, REG_FF));
679 if (SCp->this_residual == 0)
680 next_SCp(SCp);
683 static void fas216_set_stc(FAS216_Info *info, unsigned int length)
685 fas216_writeb(info, REG_STCL, length);
686 fas216_writeb(info, REG_STCM, length >> 8);
687 fas216_writeb(info, REG_STCH, length >> 16);
690 static unsigned int fas216_get_ctc(FAS216_Info *info)
692 return fas216_readb(info, REG_CTCL) +
693 (fas216_readb(info, REG_CTCM) << 8) +
694 (fas216_readb(info, REG_CTCH) << 16);
698 * fas216_cleanuptransfer - clean up after a transfer has completed.
699 * @info: interface to clean up
701 * Update the data pointers according to the number of bytes transferred
702 * on the SCSI bus.
704 static void fas216_cleanuptransfer(FAS216_Info *info)
706 unsigned long total, residual, fifo;
707 fasdmatype_t dmatype = info->dma.transfer_type;
709 info->dma.transfer_type = fasdma_none;
712 * PIO transfers do not need to be cleaned up.
714 if (dmatype == fasdma_pio || dmatype == fasdma_none)
715 return;
717 if (dmatype == fasdma_real_all)
718 total = info->scsi.SCp.phase;
719 else
720 total = info->scsi.SCp.this_residual;
722 residual = fas216_get_ctc(info);
724 fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
726 fas216_log(info, LOG_BUFFER, "cleaning up from previous "
727 "transfer: length 0x%06x, residual 0x%x, fifo %d",
728 total, residual, fifo);
731 * If we were performing Data-Out, the transfer counter
732 * counts down each time a byte is transferred by the
733 * host to the FIFO. This means we must include the
734 * bytes left in the FIFO from the transfer counter.
736 if (info->scsi.phase == PHASE_DATAOUT)
737 residual += fifo;
739 fas216_updateptrs(info, total - residual);
743 * fas216_transfer - Perform a DMA/PIO transfer off of/on to card
744 * @info: interface from which device disconnected from
746 * Start a DMA/PIO transfer off of/on to card
748 static void fas216_transfer(FAS216_Info *info)
750 fasdmadir_t direction;
751 fasdmatype_t dmatype;
753 fas216_log(info, LOG_BUFFER,
754 "starttransfer: buffer %p length 0x%06x reqlen 0x%06x",
755 info->scsi.SCp.ptr, info->scsi.SCp.this_residual,
756 info->scsi.SCp.phase);
758 if (!info->scsi.SCp.ptr) {
759 fas216_log(info, LOG_ERROR, "null buffer passed to "
760 "fas216_starttransfer");
761 print_SCp(&info->scsi.SCp, "SCp: ", "\n");
762 print_SCp(&info->SCpnt->SCp, "Cmnd SCp: ", "\n");
763 return;
767 * If we have a synchronous transfer agreement in effect, we must
768 * use DMA mode. If we are using asynchronous transfers, we may
769 * use DMA mode or PIO mode.
771 if (info->device[info->SCpnt->device->id].sof)
772 dmatype = fasdma_real_all;
773 else
774 dmatype = fasdma_pio;
776 if (info->scsi.phase == PHASE_DATAOUT)
777 direction = DMA_OUT;
778 else
779 direction = DMA_IN;
781 if (info->dma.setup)
782 dmatype = info->dma.setup(info->host, &info->scsi.SCp,
783 direction, dmatype);
784 info->dma.transfer_type = dmatype;
786 if (dmatype == fasdma_real_all)
787 fas216_set_stc(info, info->scsi.SCp.phase);
788 else
789 fas216_set_stc(info, info->scsi.SCp.this_residual);
791 switch (dmatype) {
792 case fasdma_pio:
793 fas216_log(info, LOG_BUFFER, "PIO transfer");
794 fas216_writeb(info, REG_SOF, 0);
795 fas216_writeb(info, REG_STP, info->scsi.async_stp);
796 fas216_cmd(info, CMD_TRANSFERINFO);
797 fas216_pio(info, direction);
798 break;
800 case fasdma_pseudo:
801 fas216_log(info, LOG_BUFFER, "pseudo transfer");
802 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
803 info->dma.pseudo(info->host, &info->scsi.SCp,
804 direction, info->SCpnt->transfersize);
805 break;
807 case fasdma_real_block:
808 fas216_log(info, LOG_BUFFER, "block dma transfer");
809 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
810 break;
812 case fasdma_real_all:
813 fas216_log(info, LOG_BUFFER, "total dma transfer");
814 fas216_cmd(info, CMD_TRANSFERINFO | CMD_WITHDMA);
815 break;
817 default:
818 fas216_log(info, LOG_BUFFER | LOG_ERROR,
819 "invalid FAS216 DMA type");
820 break;
825 * fas216_stoptransfer - Stop a DMA transfer onto / off of the card
826 * @info: interface from which device disconnected from
828 * Called when we switch away from DATA IN or DATA OUT phases.
830 static void fas216_stoptransfer(FAS216_Info *info)
832 fas216_checkmagic(info);
834 if (info->dma.transfer_type == fasdma_real_all ||
835 info->dma.transfer_type == fasdma_real_block)
836 info->dma.stop(info->host, &info->scsi.SCp);
838 fas216_cleanuptransfer(info);
840 if (info->scsi.phase == PHASE_DATAIN) {
841 unsigned int fifo;
844 * If we were performing Data-In, then the FIFO counter
845 * contains the number of bytes not transferred via DMA
846 * from the on-board FIFO. Read them manually.
848 fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
849 while (fifo && info->scsi.SCp.ptr) {
850 *info->scsi.SCp.ptr = fas216_readb(info, REG_FF);
851 fas216_updateptrs(info, 1);
852 fifo--;
854 } else {
856 * After a Data-Out phase, there may be unsent
857 * bytes left in the FIFO. Flush them out.
859 fas216_cmd(info, CMD_FLUSHFIFO);
863 static void fas216_aborttransfer(FAS216_Info *info)
865 fas216_checkmagic(info);
867 if (info->dma.transfer_type == fasdma_real_all ||
868 info->dma.transfer_type == fasdma_real_block)
869 info->dma.stop(info->host, &info->scsi.SCp);
871 info->dma.transfer_type = fasdma_none;
872 fas216_cmd(info, CMD_FLUSHFIFO);
875 static void fas216_kick(FAS216_Info *info);
878 * fas216_disconnected_intr - handle device disconnection
879 * @info: interface from which device disconnected from
881 * Handle device disconnection
883 static void fas216_disconnect_intr(FAS216_Info *info)
885 unsigned long flags;
887 fas216_checkmagic(info);
889 fas216_log(info, LOG_CONNECT, "disconnect phase=%02x",
890 info->scsi.phase);
892 msgqueue_flush(&info->scsi.msgs);
894 switch (info->scsi.phase) {
895 case PHASE_SELECTION: /* while selecting - no target */
896 case PHASE_SELSTEPS:
897 fas216_done(info, DID_NO_CONNECT);
898 break;
900 case PHASE_MSGIN_DISCONNECT: /* message in - disconnecting */
901 info->scsi.disconnectable = 1;
902 info->scsi.phase = PHASE_IDLE;
903 info->stats.disconnects += 1;
904 spin_lock_irqsave(&info->host_lock, flags);
905 if (info->scsi.phase == PHASE_IDLE)
906 fas216_kick(info);
907 spin_unlock_irqrestore(&info->host_lock, flags);
908 break;
910 case PHASE_DONE: /* at end of command - complete */
911 fas216_done(info, DID_OK);
912 break;
914 case PHASE_MSGOUT: /* message out - possible ABORT message */
915 if (fas216_get_last_msg(info, info->scsi.msgin_fifo) == ABORT) {
916 info->scsi.aborting = 0;
917 fas216_done(info, DID_ABORT);
918 break;
921 default: /* huh? */
922 printk(KERN_ERR "scsi%d.%c: unexpected disconnect in phase %s\n",
923 info->host->host_no, fas216_target(info), fas216_drv_phase(info));
924 print_debug_list();
925 fas216_stoptransfer(info);
926 fas216_done(info, DID_ERROR);
927 break;
932 * fas216_reselected_intr - start reconnection of a device
933 * @info: interface which was reselected
935 * Start reconnection of a device
937 static void
938 fas216_reselected_intr(FAS216_Info *info)
940 unsigned int cfis, i;
941 unsigned char msg[4];
942 unsigned char target, lun, tag;
944 fas216_checkmagic(info);
946 WARN_ON(info->scsi.phase == PHASE_SELECTION ||
947 info->scsi.phase == PHASE_SELSTEPS);
949 cfis = fas216_readb(info, REG_CFIS);
951 fas216_log(info, LOG_CONNECT, "reconnect phase=%02x cfis=%02x",
952 info->scsi.phase, cfis);
954 cfis &= CFIS_CF;
956 if (cfis < 2 || cfis > 4) {
957 printk(KERN_ERR "scsi%d.H: incorrect number of bytes after reselect\n",
958 info->host->host_no);
959 goto bad_message;
962 for (i = 0; i < cfis; i++)
963 msg[i] = fas216_readb(info, REG_FF);
965 if (!(msg[0] & (1 << info->host->this_id)) ||
966 !(msg[1] & 0x80))
967 goto initiator_error;
969 target = msg[0] & ~(1 << info->host->this_id);
970 target = ffs(target) - 1;
971 lun = msg[1] & 7;
972 tag = 0;
974 if (cfis >= 3) {
975 if (msg[2] != SIMPLE_QUEUE_TAG)
976 goto initiator_error;
978 tag = msg[3];
981 /* set up for synchronous transfers */
982 fas216_writeb(info, REG_SDID, target);
983 fas216_set_sync(info, target);
984 msgqueue_flush(&info->scsi.msgs);
986 fas216_log(info, LOG_CONNECT, "Reconnected: target %1x lun %1x tag %02x",
987 target, lun, tag);
989 if (info->scsi.disconnectable && info->SCpnt) {
990 info->scsi.disconnectable = 0;
991 if (info->SCpnt->device->id == target &&
992 info->SCpnt->device->lun == lun &&
993 info->SCpnt->tag == tag) {
994 fas216_log(info, LOG_CONNECT, "reconnected previously executing command");
995 } else {
996 queue_add_cmd_tail(&info->queues.disconnected, info->SCpnt);
997 fas216_log(info, LOG_CONNECT, "had to move command to disconnected queue");
998 info->SCpnt = NULL;
1001 if (!info->SCpnt) {
1002 info->SCpnt = queue_remove_tgtluntag(&info->queues.disconnected,
1003 target, lun, tag);
1004 fas216_log(info, LOG_CONNECT, "had to get command");
1007 if (info->SCpnt) {
1009 * Restore data pointer from SAVED data pointer
1011 info->scsi.SCp = info->SCpnt->SCp;
1013 fas216_log(info, LOG_CONNECT, "data pointers: [%p, %X]",
1014 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1015 info->scsi.phase = PHASE_MSGIN;
1016 } else {
1018 * Our command structure not found - abort the
1019 * command on the target. Since we have no
1020 * record of this command, we can't send
1021 * an INITIATOR DETECTED ERROR message.
1023 fas216_cmd(info, CMD_SETATN);
1025 #if 0
1026 if (tag)
1027 msgqueue_addmsg(&info->scsi.msgs, 2, ABORT_TAG, tag);
1028 else
1029 #endif
1030 msgqueue_addmsg(&info->scsi.msgs, 1, ABORT);
1031 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1032 info->scsi.aborting = 1;
1035 fas216_cmd(info, CMD_MSGACCEPTED);
1036 return;
1038 initiator_error:
1039 printk(KERN_ERR "scsi%d.H: error during reselection: bytes",
1040 info->host->host_no);
1041 for (i = 0; i < cfis; i++)
1042 printk(" %02x", msg[i]);
1043 printk("\n");
1044 bad_message:
1045 fas216_cmd(info, CMD_SETATN);
1046 msgqueue_flush(&info->scsi.msgs);
1047 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1048 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1049 fas216_cmd(info, CMD_MSGACCEPTED);
1052 static void fas216_parse_message(FAS216_Info *info, unsigned char *message, int msglen)
1054 int i;
1056 switch (message[0]) {
1057 case COMMAND_COMPLETE:
1058 if (msglen != 1)
1059 goto unrecognised;
1061 printk(KERN_ERR "scsi%d.%c: command complete with no "
1062 "status in MESSAGE_IN?\n",
1063 info->host->host_no, fas216_target(info));
1064 break;
1066 case SAVE_POINTERS:
1067 if (msglen != 1)
1068 goto unrecognised;
1071 * Save current data pointer to SAVED data pointer
1072 * SCSI II standard says that we must not acknowledge
1073 * this until we have really saved pointers.
1074 * NOTE: we DO NOT save the command nor status pointers
1075 * as required by the SCSI II standard. These always
1076 * point to the start of their respective areas.
1078 info->SCpnt->SCp = info->scsi.SCp;
1079 info->SCpnt->SCp.sent_command = 0;
1080 fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER,
1081 "save data pointers: [%p, %X]",
1082 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1083 break;
1085 case RESTORE_POINTERS:
1086 if (msglen != 1)
1087 goto unrecognised;
1090 * Restore current data pointer from SAVED data pointer
1092 info->scsi.SCp = info->SCpnt->SCp;
1093 fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER,
1094 "restore data pointers: [%p, 0x%x]",
1095 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1096 break;
1098 case DISCONNECT:
1099 if (msglen != 1)
1100 goto unrecognised;
1102 info->scsi.phase = PHASE_MSGIN_DISCONNECT;
1103 break;
1105 case MESSAGE_REJECT:
1106 if (msglen != 1)
1107 goto unrecognised;
1109 switch (fas216_get_last_msg(info, info->scsi.msgin_fifo)) {
1110 case EXTENDED_MESSAGE | EXTENDED_SDTR << 8:
1111 fas216_handlesync(info, message);
1112 break;
1114 default:
1115 fas216_log(info, 0, "reject, last message 0x%04x",
1116 fas216_get_last_msg(info, info->scsi.msgin_fifo));
1118 break;
1120 case NOP:
1121 break;
1123 case EXTENDED_MESSAGE:
1124 if (msglen < 3)
1125 goto unrecognised;
1127 switch (message[2]) {
1128 case EXTENDED_SDTR: /* Sync transfer negotiation request/reply */
1129 fas216_handlesync(info, message);
1130 break;
1132 default:
1133 goto unrecognised;
1135 break;
1137 default:
1138 goto unrecognised;
1140 return;
1142 unrecognised:
1143 fas216_log(info, 0, "unrecognised message, rejecting");
1144 printk("scsi%d.%c: message was", info->host->host_no, fas216_target(info));
1145 for (i = 0; i < msglen; i++)
1146 printk("%s%02X", i & 31 ? " " : "\n ", message[i]);
1147 printk("\n");
1150 * Something strange seems to be happening here -
1151 * I can't use SETATN since the chip gives me an
1152 * invalid command interrupt when I do. Weird.
1154 fas216_cmd(info, CMD_NOP);
1155 fas216_dumpstate(info);
1156 fas216_cmd(info, CMD_SETATN);
1157 msgqueue_flush(&info->scsi.msgs);
1158 msgqueue_addmsg(&info->scsi.msgs, 1, MESSAGE_REJECT);
1159 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1160 fas216_dumpstate(info);
1163 static int fas216_wait_cmd(FAS216_Info *info, int cmd)
1165 int tout;
1166 int stat;
1168 fas216_cmd(info, cmd);
1170 for (tout = 1000; tout; tout -= 1) {
1171 stat = fas216_readb(info, REG_STAT);
1172 if (stat & (STAT_INT|STAT_PARITYERROR))
1173 break;
1174 udelay(1);
1177 return stat;
1180 static int fas216_get_msg_byte(FAS216_Info *info)
1182 unsigned int stat = fas216_wait_cmd(info, CMD_MSGACCEPTED);
1184 if ((stat & STAT_INT) == 0)
1185 goto timedout;
1187 if ((stat & STAT_BUSMASK) != STAT_MESGIN)
1188 goto unexpected_phase_change;
1190 fas216_readb(info, REG_INST);
1192 stat = fas216_wait_cmd(info, CMD_TRANSFERINFO);
1194 if ((stat & STAT_INT) == 0)
1195 goto timedout;
1197 if (stat & STAT_PARITYERROR)
1198 goto parity_error;
1200 if ((stat & STAT_BUSMASK) != STAT_MESGIN)
1201 goto unexpected_phase_change;
1203 fas216_readb(info, REG_INST);
1205 return fas216_readb(info, REG_FF);
1207 timedout:
1208 fas216_log(info, LOG_ERROR, "timed out waiting for message byte");
1209 return -1;
1211 unexpected_phase_change:
1212 fas216_log(info, LOG_ERROR, "unexpected phase change: status = %02x", stat);
1213 return -2;
1215 parity_error:
1216 fas216_log(info, LOG_ERROR, "parity error during message in phase");
1217 return -3;
1221 * fas216_message - handle a function done interrupt from FAS216 chip
1222 * @info: interface which caused function done interrupt
1224 * Handle a function done interrupt from FAS216 chip
1226 static void fas216_message(FAS216_Info *info)
1228 unsigned char *message = info->scsi.message;
1229 unsigned int msglen = 1;
1230 int msgbyte = 0;
1232 fas216_checkmagic(info);
1234 message[0] = fas216_readb(info, REG_FF);
1236 if (message[0] == EXTENDED_MESSAGE) {
1237 msgbyte = fas216_get_msg_byte(info);
1239 if (msgbyte >= 0) {
1240 message[1] = msgbyte;
1242 for (msglen = 2; msglen < message[1] + 2; msglen++) {
1243 msgbyte = fas216_get_msg_byte(info);
1245 if (msgbyte >= 0)
1246 message[msglen] = msgbyte;
1247 else
1248 break;
1253 if (msgbyte == -3)
1254 goto parity_error;
1256 #ifdef DEBUG_MESSAGES
1258 int i;
1260 printk("scsi%d.%c: message in: ",
1261 info->host->host_no, fas216_target(info));
1262 for (i = 0; i < msglen; i++)
1263 printk("%02X ", message[i]);
1264 printk("\n");
1266 #endif
1268 fas216_parse_message(info, message, msglen);
1269 fas216_cmd(info, CMD_MSGACCEPTED);
1270 return;
1272 parity_error:
1273 fas216_cmd(info, CMD_SETATN);
1274 msgqueue_flush(&info->scsi.msgs);
1275 msgqueue_addmsg(&info->scsi.msgs, 1, MSG_PARITY_ERROR);
1276 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1277 fas216_cmd(info, CMD_MSGACCEPTED);
1278 return;
1282 * fas216_send_command - send command after all message bytes have been sent
1283 * @info: interface which caused bus service
1285 * Send a command to a target after all message bytes have been sent
1287 static void fas216_send_command(FAS216_Info *info)
1289 int i;
1291 fas216_checkmagic(info);
1293 fas216_cmd(info, CMD_NOP|CMD_WITHDMA);
1294 fas216_cmd(info, CMD_FLUSHFIFO);
1296 /* load command */
1297 for (i = info->scsi.SCp.sent_command; i < info->SCpnt->cmd_len; i++)
1298 fas216_writeb(info, REG_FF, info->SCpnt->cmnd[i]);
1300 fas216_cmd(info, CMD_TRANSFERINFO);
1302 info->scsi.phase = PHASE_COMMAND;
1306 * fas216_send_messageout - handle bus service to send a message
1307 * @info: interface which caused bus service
1309 * Handle bus service to send a message.
1310 * Note: We do not allow the device to change the data direction!
1312 static void fas216_send_messageout(FAS216_Info *info, int start)
1314 unsigned int tot_msglen = msgqueue_msglength(&info->scsi.msgs);
1316 fas216_checkmagic(info);
1318 fas216_cmd(info, CMD_FLUSHFIFO);
1320 if (tot_msglen) {
1321 struct message *msg;
1322 int msgnr = 0;
1324 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1325 int i;
1327 for (i = start; i < msg->length; i++)
1328 fas216_writeb(info, REG_FF, msg->msg[i]);
1330 msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
1331 start = 0;
1333 } else
1334 fas216_writeb(info, REG_FF, NOP);
1336 fas216_cmd(info, CMD_TRANSFERINFO);
1338 info->scsi.phase = PHASE_MSGOUT;
1342 * fas216_busservice_intr - handle bus service interrupt from FAS216 chip
1343 * @info: interface which caused bus service interrupt
1344 * @stat: Status register contents
1345 * @is: SCSI Status register contents
1347 * Handle a bus service interrupt from FAS216 chip
1349 static void fas216_busservice_intr(FAS216_Info *info, unsigned int stat, unsigned int is)
1351 fas216_checkmagic(info);
1353 fas216_log(info, LOG_BUSSERVICE,
1354 "bus service: stat=%02x is=%02x phase=%02x",
1355 stat, is, info->scsi.phase);
1357 switch (info->scsi.phase) {
1358 case PHASE_SELECTION:
1359 if ((is & IS_BITS) != IS_MSGBYTESENT)
1360 goto bad_is;
1361 break;
1363 case PHASE_SELSTEPS:
1364 switch (is & IS_BITS) {
1365 case IS_SELARB:
1366 case IS_MSGBYTESENT:
1367 goto bad_is;
1369 case IS_NOTCOMMAND:
1370 case IS_EARLYPHASE:
1371 if ((stat & STAT_BUSMASK) == STAT_MESGIN)
1372 break;
1373 goto bad_is;
1375 case IS_COMPLETE:
1376 break;
1379 default:
1380 break;
1383 fas216_cmd(info, CMD_NOP);
1385 #define STATE(st,ph) ((ph) << 3 | (st))
1386 /* This table describes the legal SCSI state transitions,
1387 * as described by the SCSI II spec.
1389 switch (STATE(stat & STAT_BUSMASK, info->scsi.phase)) {
1390 case STATE(STAT_DATAIN, PHASE_SELSTEPS):/* Sel w/ steps -> Data In */
1391 case STATE(STAT_DATAIN, PHASE_MSGOUT): /* Message Out -> Data In */
1392 case STATE(STAT_DATAIN, PHASE_COMMAND): /* Command -> Data In */
1393 case STATE(STAT_DATAIN, PHASE_MSGIN): /* Message In -> Data In */
1394 info->scsi.phase = PHASE_DATAIN;
1395 fas216_transfer(info);
1396 return;
1398 case STATE(STAT_DATAIN, PHASE_DATAIN): /* Data In -> Data In */
1399 case STATE(STAT_DATAOUT, PHASE_DATAOUT):/* Data Out -> Data Out */
1400 fas216_cleanuptransfer(info);
1401 fas216_transfer(info);
1402 return;
1404 case STATE(STAT_DATAOUT, PHASE_SELSTEPS):/* Sel w/ steps-> Data Out */
1405 case STATE(STAT_DATAOUT, PHASE_MSGOUT): /* Message Out -> Data Out */
1406 case STATE(STAT_DATAOUT, PHASE_COMMAND):/* Command -> Data Out */
1407 case STATE(STAT_DATAOUT, PHASE_MSGIN): /* Message In -> Data Out */
1408 fas216_cmd(info, CMD_FLUSHFIFO);
1409 info->scsi.phase = PHASE_DATAOUT;
1410 fas216_transfer(info);
1411 return;
1413 case STATE(STAT_STATUS, PHASE_DATAOUT): /* Data Out -> Status */
1414 case STATE(STAT_STATUS, PHASE_DATAIN): /* Data In -> Status */
1415 fas216_stoptransfer(info);
1416 case STATE(STAT_STATUS, PHASE_SELSTEPS):/* Sel w/ steps -> Status */
1417 case STATE(STAT_STATUS, PHASE_MSGOUT): /* Message Out -> Status */
1418 case STATE(STAT_STATUS, PHASE_COMMAND): /* Command -> Status */
1419 case STATE(STAT_STATUS, PHASE_MSGIN): /* Message In -> Status */
1420 fas216_cmd(info, CMD_INITCMDCOMPLETE);
1421 info->scsi.phase = PHASE_STATUS;
1422 return;
1424 case STATE(STAT_MESGIN, PHASE_DATAOUT): /* Data Out -> Message In */
1425 case STATE(STAT_MESGIN, PHASE_DATAIN): /* Data In -> Message In */
1426 fas216_stoptransfer(info);
1427 case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */
1428 case STATE(STAT_MESGIN, PHASE_SELSTEPS):/* Sel w/ steps -> Message In */
1429 case STATE(STAT_MESGIN, PHASE_MSGOUT): /* Message Out -> Message In */
1430 info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
1431 fas216_cmd(info, CMD_FLUSHFIFO);
1432 fas216_cmd(info, CMD_TRANSFERINFO);
1433 info->scsi.phase = PHASE_MSGIN;
1434 return;
1436 case STATE(STAT_MESGIN, PHASE_MSGIN):
1437 info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
1438 fas216_cmd(info, CMD_TRANSFERINFO);
1439 return;
1441 case STATE(STAT_COMMAND, PHASE_MSGOUT): /* Message Out -> Command */
1442 case STATE(STAT_COMMAND, PHASE_MSGIN): /* Message In -> Command */
1443 fas216_send_command(info);
1444 info->scsi.phase = PHASE_COMMAND;
1445 return;
1449 * Selection -> Message Out
1451 case STATE(STAT_MESGOUT, PHASE_SELECTION):
1452 fas216_send_messageout(info, 1);
1453 return;
1456 * Message Out -> Message Out
1458 case STATE(STAT_MESGOUT, PHASE_SELSTEPS):
1459 case STATE(STAT_MESGOUT, PHASE_MSGOUT):
1461 * If we get another message out phase, this usually
1462 * means some parity error occurred. Resend complete
1463 * set of messages. If we have more than one byte to
1464 * send, we need to assert ATN again.
1466 if (info->device[info->SCpnt->device->id].parity_check) {
1468 * We were testing... good, the device
1469 * supports parity checking.
1471 info->device[info->SCpnt->device->id].parity_check = 0;
1472 info->device[info->SCpnt->device->id].parity_enabled = 1;
1473 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
1476 if (msgqueue_msglength(&info->scsi.msgs) > 1)
1477 fas216_cmd(info, CMD_SETATN);
1478 /*FALLTHROUGH*/
1481 * Any -> Message Out
1483 case STATE(STAT_MESGOUT, PHASE_MSGOUT_EXPECT):
1484 fas216_send_messageout(info, 0);
1485 return;
1487 /* Error recovery rules.
1488 * These either attempt to abort or retry the operation.
1489 * TODO: we need more of these
1491 case STATE(STAT_COMMAND, PHASE_COMMAND):/* Command -> Command */
1492 /* error - we've sent out all the command bytes
1493 * we have.
1494 * NOTE: we need SAVE DATA POINTERS/RESTORE DATA POINTERS
1495 * to include the command bytes sent for this to work
1496 * correctly.
1498 printk(KERN_ERR "scsi%d.%c: "
1499 "target trying to receive more command bytes\n",
1500 info->host->host_no, fas216_target(info));
1501 fas216_cmd(info, CMD_SETATN);
1502 fas216_set_stc(info, 15);
1503 fas216_cmd(info, CMD_PADBYTES | CMD_WITHDMA);
1504 msgqueue_flush(&info->scsi.msgs);
1505 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1506 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1507 return;
1510 if (info->scsi.phase == PHASE_MSGIN_DISCONNECT) {
1511 printk(KERN_ERR "scsi%d.%c: disconnect message received, but bus service %s?\n",
1512 info->host->host_no, fas216_target(info),
1513 fas216_bus_phase(stat));
1514 msgqueue_flush(&info->scsi.msgs);
1515 fas216_cmd(info, CMD_SETATN);
1516 msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
1517 info->scsi.phase = PHASE_MSGOUT_EXPECT;
1518 info->scsi.aborting = 1;
1519 fas216_cmd(info, CMD_TRANSFERINFO);
1520 return;
1522 printk(KERN_ERR "scsi%d.%c: bus phase %s after %s?\n",
1523 info->host->host_no, fas216_target(info),
1524 fas216_bus_phase(stat),
1525 fas216_drv_phase(info));
1526 print_debug_list();
1527 return;
1529 bad_is:
1530 fas216_log(info, 0, "bus service at step %d?", is & IS_BITS);
1531 fas216_dumpstate(info);
1532 print_debug_list();
1534 fas216_done(info, DID_ERROR);
1538 * fas216_funcdone_intr - handle a function done interrupt from FAS216 chip
1539 * @info: interface which caused function done interrupt
1540 * @stat: Status register contents
1541 * @is: SCSI Status register contents
1543 * Handle a function done interrupt from FAS216 chip
1545 static void fas216_funcdone_intr(FAS216_Info *info, unsigned int stat, unsigned int is)
1547 unsigned int fifo_len = fas216_readb(info, REG_CFIS) & CFIS_CF;
1549 fas216_checkmagic(info);
1551 fas216_log(info, LOG_FUNCTIONDONE,
1552 "function done: stat=%02x is=%02x phase=%02x",
1553 stat, is, info->scsi.phase);
1555 switch (info->scsi.phase) {
1556 case PHASE_STATUS: /* status phase - read status and msg */
1557 if (fifo_len != 2) {
1558 fas216_log(info, 0, "odd number of bytes in FIFO: %d", fifo_len);
1561 * Read status then message byte.
1563 info->scsi.SCp.Status = fas216_readb(info, REG_FF);
1564 info->scsi.SCp.Message = fas216_readb(info, REG_FF);
1565 info->scsi.phase = PHASE_DONE;
1566 fas216_cmd(info, CMD_MSGACCEPTED);
1567 break;
1569 case PHASE_IDLE:
1570 case PHASE_SELECTION:
1571 case PHASE_SELSTEPS:
1572 break;
1574 case PHASE_MSGIN: /* message in phase */
1575 if ((stat & STAT_BUSMASK) == STAT_MESGIN) {
1576 info->scsi.msgin_fifo = fifo_len;
1577 fas216_message(info);
1578 break;
1581 default:
1582 fas216_log(info, 0, "internal phase %s for function done?"
1583 " What do I do with this?",
1584 fas216_target(info), fas216_drv_phase(info));
1588 static void fas216_bus_reset(FAS216_Info *info)
1590 neg_t sync_state;
1591 int i;
1593 msgqueue_flush(&info->scsi.msgs);
1595 sync_state = neg_invalid;
1597 #ifdef SCSI2_SYNC
1598 if (info->ifcfg.capabilities & (FASCAP_DMA|FASCAP_PSEUDODMA))
1599 sync_state = neg_wait;
1600 #endif
1602 info->scsi.phase = PHASE_IDLE;
1603 info->SCpnt = NULL; /* bug! */
1604 memset(&info->scsi.SCp, 0, sizeof(info->scsi.SCp));
1606 for (i = 0; i < 8; i++) {
1607 info->device[i].disconnect_ok = info->ifcfg.disconnect_ok;
1608 info->device[i].sync_state = sync_state;
1609 info->device[i].period = info->ifcfg.asyncperiod / 4;
1610 info->device[i].stp = info->scsi.async_stp;
1611 info->device[i].sof = 0;
1612 info->device[i].wide_xfer = 0;
1615 info->rst_bus_status = 1;
1616 wake_up(&info->eh_wait);
1620 * fas216_intr - handle interrupts to progress a command
1621 * @info: interface to service
1623 * Handle interrupts from the interface to progress a command
1625 irqreturn_t fas216_intr(FAS216_Info *info)
1627 unsigned char inst, is, stat;
1628 int handled = IRQ_NONE;
1630 fas216_checkmagic(info);
1632 stat = fas216_readb(info, REG_STAT);
1633 is = fas216_readb(info, REG_IS);
1634 inst = fas216_readb(info, REG_INST);
1636 add_debug_list(stat, is, inst, info->scsi.phase);
1638 if (stat & STAT_INT) {
1639 if (inst & INST_BUSRESET) {
1640 fas216_log(info, 0, "bus reset detected");
1641 fas216_bus_reset(info);
1642 scsi_report_bus_reset(info->host, 0);
1643 } else if (inst & INST_ILLEGALCMD) {
1644 fas216_log(info, LOG_ERROR, "illegal command given\n");
1645 fas216_dumpstate(info);
1646 print_debug_list();
1647 } else if (inst & INST_DISCONNECT)
1648 fas216_disconnect_intr(info);
1649 else if (inst & INST_RESELECTED) /* reselected */
1650 fas216_reselected_intr(info);
1651 else if (inst & INST_BUSSERVICE) /* bus service request */
1652 fas216_busservice_intr(info, stat, is);
1653 else if (inst & INST_FUNCDONE) /* function done */
1654 fas216_funcdone_intr(info, stat, is);
1655 else
1656 fas216_log(info, 0, "unknown interrupt received:"
1657 " phase %s inst %02X is %02X stat %02X",
1658 fas216_drv_phase(info), inst, is, stat);
1659 handled = IRQ_HANDLED;
1661 return handled;
1664 static void __fas216_start_command(FAS216_Info *info, struct scsi_cmnd *SCpnt)
1666 int tot_msglen;
1668 /* following what the ESP driver says */
1669 fas216_set_stc(info, 0);
1670 fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
1672 /* flush FIFO */
1673 fas216_cmd(info, CMD_FLUSHFIFO);
1675 /* load bus-id and timeout */
1676 fas216_writeb(info, REG_SDID, BUSID(SCpnt->device->id));
1677 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
1679 /* synchronous transfers */
1680 fas216_set_sync(info, SCpnt->device->id);
1682 tot_msglen = msgqueue_msglength(&info->scsi.msgs);
1684 #ifdef DEBUG_MESSAGES
1686 struct message *msg;
1687 int msgnr = 0, i;
1689 printk("scsi%d.%c: message out: ",
1690 info->host->host_no, '0' + SCpnt->device->id);
1691 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1692 printk("{ ");
1693 for (i = 0; i < msg->length; i++)
1694 printk("%02x ", msg->msg[i]);
1695 printk("} ");
1697 printk("\n");
1699 #endif
1701 if (tot_msglen == 1 || tot_msglen == 3) {
1703 * We have an easy message length to send...
1705 struct message *msg;
1706 int msgnr = 0, i;
1708 info->scsi.phase = PHASE_SELSTEPS;
1710 /* load message bytes */
1711 while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
1712 for (i = 0; i < msg->length; i++)
1713 fas216_writeb(info, REG_FF, msg->msg[i]);
1714 msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
1717 /* load command */
1718 for (i = 0; i < SCpnt->cmd_len; i++)
1719 fas216_writeb(info, REG_FF, SCpnt->cmnd[i]);
1721 if (tot_msglen == 1)
1722 fas216_cmd(info, CMD_SELECTATN);
1723 else
1724 fas216_cmd(info, CMD_SELECTATN3);
1725 } else {
1727 * We have an unusual number of message bytes to send.
1728 * Load first byte into fifo, and issue SELECT with ATN and
1729 * stop steps.
1731 struct message *msg = msgqueue_getmsg(&info->scsi.msgs, 0);
1733 fas216_writeb(info, REG_FF, msg->msg[0]);
1734 msg->fifo = 1;
1736 fas216_cmd(info, CMD_SELECTATNSTOP);
1741 * Decide whether we need to perform a parity test on this device.
1742 * Can also be used to force parity error conditions during initial
1743 * information transfer phase (message out) for test purposes.
1745 static int parity_test(FAS216_Info *info, int target)
1747 #if 0
1748 if (target == 3) {
1749 info->device[target].parity_check = 0;
1750 return 1;
1752 #endif
1753 return info->device[target].parity_check;
1756 static void fas216_start_command(FAS216_Info *info, struct scsi_cmnd *SCpnt)
1758 int disconnect_ok;
1761 * claim host busy
1763 info->scsi.phase = PHASE_SELECTION;
1764 info->scsi.SCp = SCpnt->SCp;
1765 info->SCpnt = SCpnt;
1766 info->dma.transfer_type = fasdma_none;
1768 if (parity_test(info, SCpnt->device->id))
1769 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_PTE);
1770 else
1771 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
1774 * Don't allow request sense commands to disconnect.
1776 disconnect_ok = SCpnt->cmnd[0] != REQUEST_SENSE &&
1777 info->device[SCpnt->device->id].disconnect_ok;
1780 * build outgoing message bytes
1782 msgqueue_flush(&info->scsi.msgs);
1783 msgqueue_addmsg(&info->scsi.msgs, 1, IDENTIFY(disconnect_ok, SCpnt->device->lun));
1786 * add tag message if required
1788 if (SCpnt->tag)
1789 msgqueue_addmsg(&info->scsi.msgs, 2, SIMPLE_QUEUE_TAG, SCpnt->tag);
1791 do {
1792 #ifdef SCSI2_SYNC
1793 if ((info->device[SCpnt->device->id].sync_state == neg_wait ||
1794 info->device[SCpnt->device->id].sync_state == neg_complete) &&
1795 (SCpnt->cmnd[0] == REQUEST_SENSE ||
1796 SCpnt->cmnd[0] == INQUIRY)) {
1797 info->device[SCpnt->device->id].sync_state = neg_inprogress;
1798 msgqueue_addmsg(&info->scsi.msgs, 5,
1799 EXTENDED_MESSAGE, 3, EXTENDED_SDTR,
1800 1000 / info->ifcfg.clockrate,
1801 info->ifcfg.sync_max_depth);
1802 break;
1804 #endif
1805 } while (0);
1807 __fas216_start_command(info, SCpnt);
1810 static void fas216_allocate_tag(FAS216_Info *info, struct scsi_cmnd *SCpnt)
1812 #ifdef SCSI2_TAG
1814 * tagged queuing - allocate a new tag to this command
1816 if (SCpnt->device->simple_tags && SCpnt->cmnd[0] != REQUEST_SENSE &&
1817 SCpnt->cmnd[0] != INQUIRY) {
1818 SCpnt->device->current_tag += 1;
1819 if (SCpnt->device->current_tag == 0)
1820 SCpnt->device->current_tag = 1;
1821 SCpnt->tag = SCpnt->device->current_tag;
1822 } else
1823 #endif
1824 set_bit(SCpnt->device->id * 8 +
1825 (u8)(SCpnt->device->lun & 0x7), info->busyluns);
1827 info->stats.removes += 1;
1828 switch (SCpnt->cmnd[0]) {
1829 case WRITE_6:
1830 case WRITE_10:
1831 case WRITE_12:
1832 info->stats.writes += 1;
1833 break;
1834 case READ_6:
1835 case READ_10:
1836 case READ_12:
1837 info->stats.reads += 1;
1838 break;
1839 default:
1840 info->stats.miscs += 1;
1841 break;
1845 static void fas216_do_bus_device_reset(FAS216_Info *info,
1846 struct scsi_cmnd *SCpnt)
1848 struct message *msg;
1851 * claim host busy
1853 info->scsi.phase = PHASE_SELECTION;
1854 info->scsi.SCp = SCpnt->SCp;
1855 info->SCpnt = SCpnt;
1856 info->dma.transfer_type = fasdma_none;
1858 fas216_log(info, LOG_ERROR, "sending bus device reset");
1860 msgqueue_flush(&info->scsi.msgs);
1861 msgqueue_addmsg(&info->scsi.msgs, 1, BUS_DEVICE_RESET);
1863 /* following what the ESP driver says */
1864 fas216_set_stc(info, 0);
1865 fas216_cmd(info, CMD_NOP | CMD_WITHDMA);
1867 /* flush FIFO */
1868 fas216_cmd(info, CMD_FLUSHFIFO);
1870 /* load bus-id and timeout */
1871 fas216_writeb(info, REG_SDID, BUSID(SCpnt->device->id));
1872 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
1874 /* synchronous transfers */
1875 fas216_set_sync(info, SCpnt->device->id);
1877 msg = msgqueue_getmsg(&info->scsi.msgs, 0);
1879 fas216_writeb(info, REG_FF, BUS_DEVICE_RESET);
1880 msg->fifo = 1;
1882 fas216_cmd(info, CMD_SELECTATNSTOP);
1886 * fas216_kick - kick a command to the interface
1887 * @info: our host interface to kick
1889 * Kick a command to the interface, interface should be idle.
1890 * Notes: Interrupts are always disabled!
1892 static void fas216_kick(FAS216_Info *info)
1894 struct scsi_cmnd *SCpnt = NULL;
1895 #define TYPE_OTHER 0
1896 #define TYPE_RESET 1
1897 #define TYPE_QUEUE 2
1898 int where_from = TYPE_OTHER;
1900 fas216_checkmagic(info);
1903 * Obtain the next command to process.
1905 do {
1906 if (info->rstSCpnt) {
1907 SCpnt = info->rstSCpnt;
1908 /* don't remove it */
1909 where_from = TYPE_RESET;
1910 break;
1913 if (info->reqSCpnt) {
1914 SCpnt = info->reqSCpnt;
1915 info->reqSCpnt = NULL;
1916 break;
1919 if (info->origSCpnt) {
1920 SCpnt = info->origSCpnt;
1921 info->origSCpnt = NULL;
1922 break;
1925 /* retrieve next command */
1926 if (!SCpnt) {
1927 SCpnt = queue_remove_exclude(&info->queues.issue,
1928 info->busyluns);
1929 where_from = TYPE_QUEUE;
1930 break;
1932 } while (0);
1934 if (!SCpnt) {
1936 * no command pending, so enable reselection.
1938 fas216_cmd(info, CMD_ENABLESEL);
1939 return;
1943 * We're going to start a command, so disable reselection
1945 fas216_cmd(info, CMD_DISABLESEL);
1947 if (info->scsi.disconnectable && info->SCpnt) {
1948 fas216_log(info, LOG_CONNECT,
1949 "moved command for %d to disconnected queue",
1950 info->SCpnt->device->id);
1951 queue_add_cmd_tail(&info->queues.disconnected, info->SCpnt);
1952 info->scsi.disconnectable = 0;
1953 info->SCpnt = NULL;
1956 fas216_log_command(info, LOG_CONNECT | LOG_MESSAGES, SCpnt,
1957 "starting");
1959 switch (where_from) {
1960 case TYPE_QUEUE:
1961 fas216_allocate_tag(info, SCpnt);
1962 case TYPE_OTHER:
1963 fas216_start_command(info, SCpnt);
1964 break;
1965 case TYPE_RESET:
1966 fas216_do_bus_device_reset(info, SCpnt);
1967 break;
1970 fas216_log(info, LOG_CONNECT, "select: data pointers [%p, %X]",
1971 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
1974 * should now get either DISCONNECT or
1975 * (FUNCTION DONE with BUS SERVICE) interrupt
1980 * Clean up from issuing a BUS DEVICE RESET message to a device.
1982 static void fas216_devicereset_done(FAS216_Info *info, struct scsi_cmnd *SCpnt,
1983 unsigned int result)
1985 fas216_log(info, LOG_ERROR, "fas216 device reset complete");
1987 info->rstSCpnt = NULL;
1988 info->rst_dev_status = 1;
1989 wake_up(&info->eh_wait);
1993 * fas216_rq_sns_done - Finish processing automatic request sense command
1994 * @info: interface that completed
1995 * @SCpnt: command that completed
1996 * @result: driver byte of result
1998 * Finish processing automatic request sense command
2000 static void fas216_rq_sns_done(FAS216_Info *info, struct scsi_cmnd *SCpnt,
2001 unsigned int result)
2003 fas216_log_target(info, LOG_CONNECT, SCpnt->device->id,
2004 "request sense complete, result=0x%04x%02x%02x",
2005 result, SCpnt->SCp.Message, SCpnt->SCp.Status);
2007 if (result != DID_OK || SCpnt->SCp.Status != GOOD)
2009 * Something went wrong. Make sure that we don't
2010 * have valid data in the sense buffer that could
2011 * confuse the higher levels.
2013 memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE);
2014 //printk("scsi%d.%c: sense buffer: ", info->host->host_no, '0' + SCpnt->device->id);
2015 //{ int i; for (i = 0; i < 32; i++) printk("%02x ", SCpnt->sense_buffer[i]); printk("\n"); }
2017 * Note that we don't set SCpnt->result, since that should
2018 * reflect the status of the command that we were asked by
2019 * the upper layers to process. This would have been set
2020 * correctly by fas216_std_done.
2022 scsi_eh_restore_cmnd(SCpnt, &info->ses);
2023 SCpnt->scsi_done(SCpnt);
2027 * fas216_std_done - finish processing of standard command
2028 * @info: interface that completed
2029 * @SCpnt: command that completed
2030 * @result: driver byte of result
2032 * Finish processing of standard command
2034 static void
2035 fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsigned int result)
2037 info->stats.fins += 1;
2039 SCpnt->result = result << 16 | info->scsi.SCp.Message << 8 |
2040 info->scsi.SCp.Status;
2042 fas216_log_command(info, LOG_CONNECT, SCpnt,
2043 "command complete, result=0x%08x", SCpnt->result);
2046 * If the driver detected an error, we're all done.
2048 if (host_byte(SCpnt->result) != DID_OK ||
2049 msg_byte(SCpnt->result) != COMMAND_COMPLETE)
2050 goto done;
2053 * If the command returned CHECK_CONDITION or COMMAND_TERMINATED
2054 * status, request the sense information.
2056 if (status_byte(SCpnt->result) == CHECK_CONDITION ||
2057 status_byte(SCpnt->result) == COMMAND_TERMINATED)
2058 goto request_sense;
2061 * If the command did not complete with GOOD status,
2062 * we are all done here.
2064 if (status_byte(SCpnt->result) != GOOD)
2065 goto done;
2068 * We have successfully completed a command. Make sure that
2069 * we do not have any buffers left to transfer. The world
2070 * is not perfect, and we seem to occasionally hit this.
2071 * It can be indicative of a buggy driver, target or the upper
2072 * levels of the SCSI code.
2074 if (info->scsi.SCp.ptr) {
2075 switch (SCpnt->cmnd[0]) {
2076 case INQUIRY:
2077 case START_STOP:
2078 case MODE_SENSE:
2079 break;
2081 default:
2082 printk(KERN_ERR "scsi%d.%c: incomplete data transfer "
2083 "detected: res=%08X ptr=%p len=%X CDB: ",
2084 info->host->host_no, '0' + SCpnt->device->id,
2085 SCpnt->result, info->scsi.SCp.ptr,
2086 info->scsi.SCp.this_residual);
2087 __scsi_print_command(SCpnt->cmnd);
2088 SCpnt->result &= ~(255 << 16);
2089 SCpnt->result |= DID_BAD_TARGET << 16;
2090 goto request_sense;
2094 done:
2095 if (SCpnt->scsi_done) {
2096 SCpnt->scsi_done(SCpnt);
2097 return;
2100 panic("scsi%d.H: null scsi_done function in fas216_done",
2101 info->host->host_no);
2104 request_sense:
2105 if (SCpnt->cmnd[0] == REQUEST_SENSE)
2106 goto done;
2108 scsi_eh_prep_cmnd(SCpnt, &info->ses, NULL, 0, ~0);
2109 fas216_log_target(info, LOG_CONNECT, SCpnt->device->id,
2110 "requesting sense");
2111 init_SCp(SCpnt);
2112 SCpnt->SCp.Message = 0;
2113 SCpnt->SCp.Status = 0;
2114 SCpnt->tag = 0;
2115 SCpnt->host_scribble = (void *)fas216_rq_sns_done;
2118 * Place this command into the high priority "request
2119 * sense" slot. This will be the very next command
2120 * executed, unless a target connects to us.
2122 if (info->reqSCpnt)
2123 printk(KERN_WARNING "scsi%d.%c: losing request command\n",
2124 info->host->host_no, '0' + SCpnt->device->id);
2125 info->reqSCpnt = SCpnt;
2129 * fas216_done - complete processing for current command
2130 * @info: interface that completed
2131 * @result: driver byte of result
2133 * Complete processing for current command
2135 static void fas216_done(FAS216_Info *info, unsigned int result)
2137 void (*fn)(FAS216_Info *, struct scsi_cmnd *, unsigned int);
2138 struct scsi_cmnd *SCpnt;
2139 unsigned long flags;
2141 fas216_checkmagic(info);
2143 if (!info->SCpnt)
2144 goto no_command;
2146 SCpnt = info->SCpnt;
2147 info->SCpnt = NULL;
2148 info->scsi.phase = PHASE_IDLE;
2150 if (info->scsi.aborting) {
2151 fas216_log(info, 0, "uncaught abort - returning DID_ABORT");
2152 result = DID_ABORT;
2153 info->scsi.aborting = 0;
2157 * Sanity check the completion - if we have zero bytes left
2158 * to transfer, we should not have a valid pointer.
2160 if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
2161 printk("scsi%d.%c: zero bytes left to transfer, but "
2162 "buffer pointer still valid: ptr=%p len=%08x CDB: ",
2163 info->host->host_no, '0' + SCpnt->device->id,
2164 info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
2165 info->scsi.SCp.ptr = NULL;
2166 __scsi_print_command(SCpnt->cmnd);
2170 * Clear down this command as completed. If we need to request
2171 * the sense information, fas216_kick will re-assert the busy
2172 * status.
2174 info->device[SCpnt->device->id].parity_check = 0;
2175 clear_bit(SCpnt->device->id * 8 +
2176 (u8)(SCpnt->device->lun & 0x7), info->busyluns);
2178 fn = (void (*)(FAS216_Info *, struct scsi_cmnd *, unsigned int))SCpnt->host_scribble;
2179 fn(info, SCpnt, result);
2181 if (info->scsi.irq) {
2182 spin_lock_irqsave(&info->host_lock, flags);
2183 if (info->scsi.phase == PHASE_IDLE)
2184 fas216_kick(info);
2185 spin_unlock_irqrestore(&info->host_lock, flags);
2187 return;
2189 no_command:
2190 panic("scsi%d.H: null command in fas216_done",
2191 info->host->host_no);
2195 * fas216_queue_command - queue a command for adapter to process.
2196 * @SCpnt: Command to queue
2197 * @done: done function to call once command is complete
2199 * Queue a command for adapter to process.
2200 * Returns: 0 on success, else error.
2201 * Notes: io_request_lock is held, interrupts are disabled.
2203 static int fas216_queue_command_lck(struct scsi_cmnd *SCpnt,
2204 void (*done)(struct scsi_cmnd *))
2206 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2207 int result;
2209 fas216_checkmagic(info);
2211 fas216_log_command(info, LOG_CONNECT, SCpnt,
2212 "received command (%p)", SCpnt);
2214 SCpnt->scsi_done = done;
2215 SCpnt->host_scribble = (void *)fas216_std_done;
2216 SCpnt->result = 0;
2218 init_SCp(SCpnt);
2220 info->stats.queues += 1;
2221 SCpnt->tag = 0;
2223 spin_lock(&info->host_lock);
2226 * Add command into execute queue and let it complete under
2227 * whatever scheme we're using.
2229 result = !queue_add_cmd_ordered(&info->queues.issue, SCpnt);
2232 * If we successfully added the command,
2233 * kick the interface to get it moving.
2235 if (result == 0 && info->scsi.phase == PHASE_IDLE)
2236 fas216_kick(info);
2237 spin_unlock(&info->host_lock);
2239 fas216_log_target(info, LOG_CONNECT, -1, "queue %s",
2240 result ? "failure" : "success");
2242 return result;
2245 DEF_SCSI_QCMD(fas216_queue_command)
2248 * fas216_internal_done - trigger restart of a waiting thread in fas216_noqueue_command
2249 * @SCpnt: Command to wake
2251 * Trigger restart of a waiting thread in fas216_command
2253 static void fas216_internal_done(struct scsi_cmnd *SCpnt)
2255 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2257 fas216_checkmagic(info);
2259 info->internal_done = 1;
2263 * fas216_noqueue_command - process a command for the adapter.
2264 * @SCpnt: Command to queue
2266 * Queue a command for adapter to process.
2267 * Returns: scsi result code.
2268 * Notes: io_request_lock is held, interrupts are disabled.
2270 static int fas216_noqueue_command_lck(struct scsi_cmnd *SCpnt,
2271 void (*done)(struct scsi_cmnd *))
2273 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2275 fas216_checkmagic(info);
2278 * We should only be using this if we don't have an interrupt.
2279 * Provide some "incentive" to use the queueing code.
2281 BUG_ON(info->scsi.irq);
2283 info->internal_done = 0;
2284 fas216_queue_command_lck(SCpnt, fas216_internal_done);
2287 * This wastes time, since we can't return until the command is
2288 * complete. We can't sleep either since we may get re-entered!
2289 * However, we must re-enable interrupts, or else we'll be
2290 * waiting forever.
2292 spin_unlock_irq(info->host->host_lock);
2294 while (!info->internal_done) {
2296 * If we don't have an IRQ, then we must poll the card for
2297 * it's interrupt, and use that to call this driver's
2298 * interrupt routine. That way, we keep the command
2299 * progressing. Maybe we can add some intelligence here
2300 * and go to sleep if we know that the device is going
2301 * to be some time (eg, disconnected).
2303 if (fas216_readb(info, REG_STAT) & STAT_INT) {
2304 spin_lock_irq(info->host->host_lock);
2305 fas216_intr(info);
2306 spin_unlock_irq(info->host->host_lock);
2310 spin_lock_irq(info->host->host_lock);
2312 done(SCpnt);
2314 return 0;
2317 DEF_SCSI_QCMD(fas216_noqueue_command)
2320 * Error handler timeout function. Indicate that we timed out,
2321 * and wake up any error handler process so it can continue.
2323 static void fas216_eh_timer(unsigned long data)
2325 FAS216_Info *info = (FAS216_Info *)data;
2327 fas216_log(info, LOG_ERROR, "error handling timed out\n");
2329 del_timer(&info->eh_timer);
2331 if (info->rst_bus_status == 0)
2332 info->rst_bus_status = -1;
2333 if (info->rst_dev_status == 0)
2334 info->rst_dev_status = -1;
2336 wake_up(&info->eh_wait);
2339 enum res_find {
2340 res_failed, /* not found */
2341 res_success, /* command on issue queue */
2342 res_hw_abort /* command on disconnected dev */
2346 * fas216_do_abort - decide how to abort a command
2347 * @SCpnt: command to abort
2349 * Decide how to abort a command.
2350 * Returns: abort status
2352 static enum res_find fas216_find_command(FAS216_Info *info,
2353 struct scsi_cmnd *SCpnt)
2355 enum res_find res = res_failed;
2357 if (queue_remove_cmd(&info->queues.issue, SCpnt)) {
2359 * The command was on the issue queue, and has not been
2360 * issued yet. We can remove the command from the queue,
2361 * and acknowledge the abort. Neither the device nor the
2362 * interface know about the command.
2364 printk("on issue queue ");
2366 res = res_success;
2367 } else if (queue_remove_cmd(&info->queues.disconnected, SCpnt)) {
2369 * The command was on the disconnected queue. We must
2370 * reconnect with the device if possible, and send it
2371 * an abort message.
2373 printk("on disconnected queue ");
2375 res = res_hw_abort;
2376 } else if (info->SCpnt == SCpnt) {
2377 printk("executing ");
2379 switch (info->scsi.phase) {
2381 * If the interface is idle, and the command is 'disconnectable',
2382 * then it is the same as on the disconnected queue.
2384 case PHASE_IDLE:
2385 if (info->scsi.disconnectable) {
2386 info->scsi.disconnectable = 0;
2387 info->SCpnt = NULL;
2388 res = res_hw_abort;
2390 break;
2392 default:
2393 break;
2395 } else if (info->origSCpnt == SCpnt) {
2397 * The command will be executed next, but a command
2398 * is currently using the interface. This is similar to
2399 * being on the issue queue, except the busylun bit has
2400 * been set.
2402 info->origSCpnt = NULL;
2403 clear_bit(SCpnt->device->id * 8 +
2404 (u8)(SCpnt->device->lun & 0x7), info->busyluns);
2405 printk("waiting for execution ");
2406 res = res_success;
2407 } else
2408 printk("unknown ");
2410 return res;
2414 * fas216_eh_abort - abort this command
2415 * @SCpnt: command to abort
2417 * Abort this command.
2418 * Returns: FAILED if unable to abort
2419 * Notes: io_request_lock is taken, and irqs are disabled
2421 int fas216_eh_abort(struct scsi_cmnd *SCpnt)
2423 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2424 int result = FAILED;
2426 fas216_checkmagic(info);
2428 info->stats.aborts += 1;
2430 printk(KERN_WARNING "scsi%d: abort command ", info->host->host_no);
2431 __scsi_print_command(SCpnt->cmnd);
2433 print_debug_list();
2434 fas216_dumpstate(info);
2436 printk(KERN_WARNING "scsi%d: abort %p ", info->host->host_no, SCpnt);
2438 switch (fas216_find_command(info, SCpnt)) {
2440 * We found the command, and cleared it out. Either
2441 * the command is still known to be executing on the
2442 * target, or the busylun bit is not set.
2444 case res_success:
2445 printk("success\n");
2446 result = SUCCESS;
2447 break;
2450 * We need to reconnect to the target and send it an
2451 * ABORT or ABORT_TAG message. We can only do this
2452 * if the bus is free.
2454 case res_hw_abort:
2458 * We are unable to abort the command for some reason.
2460 default:
2461 case res_failed:
2462 printk("failed\n");
2463 break;
2466 return result;
2470 * fas216_eh_device_reset - Reset the device associated with this command
2471 * @SCpnt: command specifing device to reset
2473 * Reset the device associated with this command.
2474 * Returns: FAILED if unable to reset.
2475 * Notes: We won't be re-entered, so we'll only have one device
2476 * reset on the go at one time.
2478 int fas216_eh_device_reset(struct scsi_cmnd *SCpnt)
2480 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2481 unsigned long flags;
2482 int i, res = FAILED, target = SCpnt->device->id;
2484 fas216_log(info, LOG_ERROR, "device reset for target %d", target);
2486 spin_lock_irqsave(&info->host_lock, flags);
2488 do {
2490 * If we are currently connected to a device, and
2491 * it is the device we want to reset, there is
2492 * nothing we can do here. Chances are it is stuck,
2493 * and we need a bus reset.
2495 if (info->SCpnt && !info->scsi.disconnectable &&
2496 info->SCpnt->device->id == SCpnt->device->id)
2497 break;
2500 * We're going to be resetting this device. Remove
2501 * all pending commands from the driver. By doing
2502 * so, we guarantee that we won't touch the command
2503 * structures except to process the reset request.
2505 queue_remove_all_target(&info->queues.issue, target);
2506 queue_remove_all_target(&info->queues.disconnected, target);
2507 if (info->origSCpnt && info->origSCpnt->device->id == target)
2508 info->origSCpnt = NULL;
2509 if (info->reqSCpnt && info->reqSCpnt->device->id == target)
2510 info->reqSCpnt = NULL;
2511 for (i = 0; i < 8; i++)
2512 clear_bit(target * 8 + i, info->busyluns);
2515 * Hijack this SCSI command structure to send
2516 * a bus device reset message to this device.
2518 SCpnt->host_scribble = (void *)fas216_devicereset_done;
2520 info->rst_dev_status = 0;
2521 info->rstSCpnt = SCpnt;
2523 if (info->scsi.phase == PHASE_IDLE)
2524 fas216_kick(info);
2526 mod_timer(&info->eh_timer, jiffies + 30 * HZ);
2527 spin_unlock_irqrestore(&info->host_lock, flags);
2530 * Wait up to 30 seconds for the reset to complete.
2532 wait_event(info->eh_wait, info->rst_dev_status);
2534 del_timer_sync(&info->eh_timer);
2535 spin_lock_irqsave(&info->host_lock, flags);
2536 info->rstSCpnt = NULL;
2538 if (info->rst_dev_status == 1)
2539 res = SUCCESS;
2540 } while (0);
2542 SCpnt->host_scribble = NULL;
2543 spin_unlock_irqrestore(&info->host_lock, flags);
2545 fas216_log(info, LOG_ERROR, "device reset complete: %s\n",
2546 res == SUCCESS ? "success" : "failed");
2548 return res;
2552 * fas216_eh_bus_reset - Reset the bus associated with the command
2553 * @SCpnt: command specifing bus to reset
2555 * Reset the bus associated with the command.
2556 * Returns: FAILED if unable to reset.
2557 * Notes: Further commands are blocked.
2559 int fas216_eh_bus_reset(struct scsi_cmnd *SCpnt)
2561 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2562 unsigned long flags;
2563 struct scsi_device *SDpnt;
2565 fas216_checkmagic(info);
2566 fas216_log(info, LOG_ERROR, "resetting bus");
2568 info->stats.bus_resets += 1;
2570 spin_lock_irqsave(&info->host_lock, flags);
2573 * Stop all activity on this interface.
2575 fas216_aborttransfer(info);
2576 fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
2579 * Clear any pending interrupts.
2581 while (fas216_readb(info, REG_STAT) & STAT_INT)
2582 fas216_readb(info, REG_INST);
2584 info->rst_bus_status = 0;
2587 * For each attached hard-reset device, clear out
2588 * all command structures. Leave the running
2589 * command in place.
2591 shost_for_each_device(SDpnt, info->host) {
2592 int i;
2594 if (SDpnt->soft_reset)
2595 continue;
2597 queue_remove_all_target(&info->queues.issue, SDpnt->id);
2598 queue_remove_all_target(&info->queues.disconnected, SDpnt->id);
2599 if (info->origSCpnt && info->origSCpnt->device->id == SDpnt->id)
2600 info->origSCpnt = NULL;
2601 if (info->reqSCpnt && info->reqSCpnt->device->id == SDpnt->id)
2602 info->reqSCpnt = NULL;
2603 info->SCpnt = NULL;
2605 for (i = 0; i < 8; i++)
2606 clear_bit(SDpnt->id * 8 + i, info->busyluns);
2609 info->scsi.phase = PHASE_IDLE;
2612 * Reset the SCSI bus. Device cleanup happens in
2613 * the interrupt handler.
2615 fas216_cmd(info, CMD_RESETSCSI);
2617 mod_timer(&info->eh_timer, jiffies + HZ);
2618 spin_unlock_irqrestore(&info->host_lock, flags);
2621 * Wait one second for the interrupt.
2623 wait_event(info->eh_wait, info->rst_bus_status);
2624 del_timer_sync(&info->eh_timer);
2626 fas216_log(info, LOG_ERROR, "bus reset complete: %s\n",
2627 info->rst_bus_status == 1 ? "success" : "failed");
2629 return info->rst_bus_status == 1 ? SUCCESS : FAILED;
2633 * fas216_init_chip - Initialise FAS216 state after reset
2634 * @info: state structure for interface
2636 * Initialise FAS216 state after reset
2638 static void fas216_init_chip(FAS216_Info *info)
2640 unsigned int clock = ((info->ifcfg.clockrate - 1) / 5 + 1) & 7;
2641 fas216_writeb(info, REG_CLKF, clock);
2642 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2643 fas216_writeb(info, REG_CNTL2, info->scsi.cfg[1]);
2644 fas216_writeb(info, REG_CNTL3, info->scsi.cfg[2]);
2645 fas216_writeb(info, REG_STIM, info->ifcfg.select_timeout);
2646 fas216_writeb(info, REG_SOF, 0);
2647 fas216_writeb(info, REG_STP, info->scsi.async_stp);
2648 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2652 * fas216_eh_host_reset - Reset the host associated with this command
2653 * @SCpnt: command specifing host to reset
2655 * Reset the host associated with this command.
2656 * Returns: FAILED if unable to reset.
2657 * Notes: io_request_lock is taken, and irqs are disabled
2659 int fas216_eh_host_reset(struct scsi_cmnd *SCpnt)
2661 FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
2663 spin_lock_irq(info->host->host_lock);
2665 fas216_checkmagic(info);
2667 printk("scsi%d.%c: %s: resetting host\n",
2668 info->host->host_no, '0' + SCpnt->device->id, __func__);
2671 * Reset the SCSI chip.
2673 fas216_cmd(info, CMD_RESETCHIP);
2676 * Ugly ugly ugly!
2677 * We need to release the host_lock and enable
2678 * IRQs if we sleep, but we must relock and disable
2679 * IRQs after the sleep.
2681 spin_unlock_irq(info->host->host_lock);
2682 msleep(50 * 1000/100);
2683 spin_lock_irq(info->host->host_lock);
2686 * Release the SCSI reset.
2688 fas216_cmd(info, CMD_NOP);
2690 fas216_init_chip(info);
2692 spin_unlock_irq(info->host->host_lock);
2693 return SUCCESS;
2696 #define TYPE_UNKNOWN 0
2697 #define TYPE_NCR53C90 1
2698 #define TYPE_NCR53C90A 2
2699 #define TYPE_NCR53C9x 3
2700 #define TYPE_Am53CF94 4
2701 #define TYPE_EmFAS216 5
2702 #define TYPE_QLFAS216 6
2704 static char *chip_types[] = {
2705 "unknown",
2706 "NS NCR53C90",
2707 "NS NCR53C90A",
2708 "NS NCR53C9x",
2709 "AMD Am53CF94",
2710 "Emulex FAS216",
2711 "QLogic FAS216"
2714 static int fas216_detect_type(FAS216_Info *info)
2716 int family, rev;
2719 * Reset the chip.
2721 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2722 udelay(50);
2723 fas216_writeb(info, REG_CMD, CMD_NOP);
2726 * Check to see if control reg 2 is present.
2728 fas216_writeb(info, REG_CNTL3, 0);
2729 fas216_writeb(info, REG_CNTL2, CNTL2_S2FE);
2732 * If we are unable to read back control reg 2
2733 * correctly, it is not present, and we have a
2734 * NCR53C90.
2736 if ((fas216_readb(info, REG_CNTL2) & (~0xe0)) != CNTL2_S2FE)
2737 return TYPE_NCR53C90;
2740 * Now, check control register 3
2742 fas216_writeb(info, REG_CNTL2, 0);
2743 fas216_writeb(info, REG_CNTL3, 0);
2744 fas216_writeb(info, REG_CNTL3, 5);
2747 * If we are unable to read the register back
2748 * correctly, we have a NCR53C90A
2750 if (fas216_readb(info, REG_CNTL3) != 5)
2751 return TYPE_NCR53C90A;
2754 * Now read the ID from the chip.
2756 fas216_writeb(info, REG_CNTL3, 0);
2758 fas216_writeb(info, REG_CNTL3, CNTL3_ADIDCHK);
2759 fas216_writeb(info, REG_CNTL3, 0);
2761 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2762 udelay(50);
2763 fas216_writeb(info, REG_CMD, CMD_WITHDMA | CMD_NOP);
2765 fas216_writeb(info, REG_CNTL2, CNTL2_ENF);
2766 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2767 udelay(50);
2768 fas216_writeb(info, REG_CMD, CMD_NOP);
2770 rev = fas216_readb(info, REG_ID);
2771 family = rev >> 3;
2772 rev &= 7;
2774 switch (family) {
2775 case 0x01:
2776 if (rev == 4)
2777 return TYPE_Am53CF94;
2778 break;
2780 case 0x02:
2781 switch (rev) {
2782 case 2:
2783 return TYPE_EmFAS216;
2784 case 3:
2785 return TYPE_QLFAS216;
2787 break;
2789 default:
2790 break;
2792 printk("family %x rev %x\n", family, rev);
2793 return TYPE_NCR53C9x;
2797 * fas216_reset_state - Initialise driver internal state
2798 * @info: state to initialise
2800 * Initialise driver internal state
2802 static void fas216_reset_state(FAS216_Info *info)
2804 int i;
2806 fas216_checkmagic(info);
2808 fas216_bus_reset(info);
2811 * Clear out all stale info in our state structure
2813 memset(info->busyluns, 0, sizeof(info->busyluns));
2814 info->scsi.disconnectable = 0;
2815 info->scsi.aborting = 0;
2817 for (i = 0; i < 8; i++) {
2818 info->device[i].parity_enabled = 0;
2819 info->device[i].parity_check = 1;
2823 * Drain all commands on disconnected queue
2825 while (queue_remove(&info->queues.disconnected) != NULL);
2828 * Remove executing commands.
2830 info->SCpnt = NULL;
2831 info->reqSCpnt = NULL;
2832 info->rstSCpnt = NULL;
2833 info->origSCpnt = NULL;
2837 * fas216_init - initialise FAS/NCR/AMD SCSI structures.
2838 * @host: a driver-specific filled-out structure
2840 * Initialise FAS/NCR/AMD SCSI structures.
2841 * Returns: 0 on success
2843 int fas216_init(struct Scsi_Host *host)
2845 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2847 info->magic_start = MAGIC;
2848 info->magic_end = MAGIC;
2849 info->host = host;
2850 info->scsi.cfg[0] = host->this_id | CNTL1_PERE;
2851 info->scsi.cfg[1] = CNTL2_ENF | CNTL2_S2FE;
2852 info->scsi.cfg[2] = info->ifcfg.cntl3 |
2853 CNTL3_ADIDCHK | CNTL3_QTAG | CNTL3_G2CB | CNTL3_LBTM;
2854 info->scsi.async_stp = fas216_syncperiod(info, info->ifcfg.asyncperiod);
2856 info->rst_dev_status = -1;
2857 info->rst_bus_status = -1;
2858 init_waitqueue_head(&info->eh_wait);
2859 init_timer(&info->eh_timer);
2860 info->eh_timer.data = (unsigned long)info;
2861 info->eh_timer.function = fas216_eh_timer;
2863 spin_lock_init(&info->host_lock);
2865 memset(&info->stats, 0, sizeof(info->stats));
2867 msgqueue_initialise(&info->scsi.msgs);
2869 if (!queue_initialise(&info->queues.issue))
2870 return -ENOMEM;
2872 if (!queue_initialise(&info->queues.disconnected)) {
2873 queue_free(&info->queues.issue);
2874 return -ENOMEM;
2877 return 0;
2881 * fas216_add - initialise FAS/NCR/AMD SCSI ic.
2882 * @host: a driver-specific filled-out structure
2883 * @dev: parent device
2885 * Initialise FAS/NCR/AMD SCSI ic.
2886 * Returns: 0 on success
2888 int fas216_add(struct Scsi_Host *host, struct device *dev)
2890 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2891 int type, ret;
2893 if (info->ifcfg.clockrate <= 10 || info->ifcfg.clockrate > 40) {
2894 printk(KERN_CRIT "fas216: invalid clock rate %u MHz\n",
2895 info->ifcfg.clockrate);
2896 return -EINVAL;
2899 fas216_reset_state(info);
2900 type = fas216_detect_type(info);
2901 info->scsi.type = chip_types[type];
2903 udelay(300);
2906 * Initialise the chip correctly.
2908 fas216_init_chip(info);
2911 * Reset the SCSI bus. We don't want to see
2912 * the resulting reset interrupt, so mask it
2913 * out.
2915 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0] | CNTL1_DISR);
2916 fas216_writeb(info, REG_CMD, CMD_RESETSCSI);
2919 * scsi standard says wait 250ms
2921 spin_unlock_irq(info->host->host_lock);
2922 msleep(100*1000/100);
2923 spin_lock_irq(info->host->host_lock);
2925 fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
2926 fas216_readb(info, REG_INST);
2928 fas216_checkmagic(info);
2930 ret = scsi_add_host(host, dev);
2931 if (ret)
2932 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2933 else
2934 scsi_scan_host(host);
2936 return ret;
2939 void fas216_remove(struct Scsi_Host *host)
2941 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2943 fas216_checkmagic(info);
2944 scsi_remove_host(host);
2946 fas216_writeb(info, REG_CMD, CMD_RESETCHIP);
2947 scsi_host_put(host);
2951 * fas216_release - release all resources for FAS/NCR/AMD SCSI ic.
2952 * @host: a driver-specific filled-out structure
2954 * release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
2956 void fas216_release(struct Scsi_Host *host)
2958 FAS216_Info *info = (FAS216_Info *)host->hostdata;
2960 queue_free(&info->queues.disconnected);
2961 queue_free(&info->queues.issue);
2964 void fas216_print_host(FAS216_Info *info, struct seq_file *m)
2966 seq_printf(m,
2967 "\n"
2968 "Chip : %s\n"
2969 " Address: 0x%p\n"
2970 " IRQ : %d\n"
2971 " DMA : %d\n",
2972 info->scsi.type, info->scsi.io_base,
2973 info->scsi.irq, info->scsi.dma);
2976 void fas216_print_stats(FAS216_Info *info, struct seq_file *m)
2978 seq_printf(m, "\n"
2979 "Command Statistics:\n"
2980 " Queued : %u\n"
2981 " Issued : %u\n"
2982 " Completed : %u\n"
2983 " Reads : %u\n"
2984 " Writes : %u\n"
2985 " Others : %u\n"
2986 " Disconnects: %u\n"
2987 " Aborts : %u\n"
2988 " Bus resets : %u\n"
2989 " Host resets: %u\n",
2990 info->stats.queues, info->stats.removes,
2991 info->stats.fins, info->stats.reads,
2992 info->stats.writes, info->stats.miscs,
2993 info->stats.disconnects, info->stats.aborts,
2994 info->stats.bus_resets, info->stats.host_resets);
2997 void fas216_print_devices(FAS216_Info *info, struct seq_file *m)
2999 struct fas216_device *dev;
3000 struct scsi_device *scd;
3002 seq_printf(m, "Device/Lun TaggedQ Parity Sync\n");
3004 shost_for_each_device(scd, info->host) {
3005 dev = &info->device[scd->id];
3006 seq_printf(m, " %d/%llu ", scd->id, scd->lun);
3007 if (scd->tagged_supported)
3008 seq_printf(m, "%3sabled(%3d) ",
3009 scd->simple_tags ? "en" : "dis",
3010 scd->current_tag);
3011 else
3012 seq_printf(m, "unsupported ");
3014 seq_printf(m, "%3sabled ", dev->parity_enabled ? "en" : "dis");
3016 if (dev->sof)
3017 seq_printf(m, "offset %d, %d ns\n",
3018 dev->sof, dev->period * 4);
3019 else
3020 seq_printf(m, "async\n");
3024 EXPORT_SYMBOL(fas216_init);
3025 EXPORT_SYMBOL(fas216_add);
3026 EXPORT_SYMBOL(fas216_queue_command);
3027 EXPORT_SYMBOL(fas216_noqueue_command);
3028 EXPORT_SYMBOL(fas216_intr);
3029 EXPORT_SYMBOL(fas216_remove);
3030 EXPORT_SYMBOL(fas216_release);
3031 EXPORT_SYMBOL(fas216_eh_abort);
3032 EXPORT_SYMBOL(fas216_eh_device_reset);
3033 EXPORT_SYMBOL(fas216_eh_bus_reset);
3034 EXPORT_SYMBOL(fas216_eh_host_reset);
3035 EXPORT_SYMBOL(fas216_print_host);
3036 EXPORT_SYMBOL(fas216_print_stats);
3037 EXPORT_SYMBOL(fas216_print_devices);
3039 MODULE_AUTHOR("Russell King");
3040 MODULE_DESCRIPTION("Generic FAS216/NCR53C9x driver core");
3041 MODULE_LICENSE("GPL");