// SPDX-License-Identifier: GPL-2.0-only /* * linux/drivers/acorn/scsi/fas216.c * * Copyright (C) 1997-2003 Russell King * * Based on information in qlogicfas.c by Tom Zerucha, Michael Griffith, and * other sources, including: * the AMD Am53CF94 data sheet * the AMD Am53C94 data sheet * * This is a generic driver. To use it, have a look at cumana_2.c. You * should define your own structure that overlays FAS216_Info, eg: * struct my_host_data { * FAS216_Info info; * ... my host specific data ... * }; * * Changelog: * 30-08-1997 RMK Created * 14-09-1997 RMK Started disconnect support * 08-02-1998 RMK Corrected real DMA support * 15-02-1998 RMK Started sync xfer support * 06-04-1998 RMK Tightened conditions for printing incomplete * transfers * 02-05-1998 RMK Added extra checks in fas216_reset * 24-05-1998 RMK Fixed synchronous transfers with period >= 200ns * 27-06-1998 RMK Changed asm/delay.h to linux/delay.h * 26-08-1998 RMK Improved message support wrt MESSAGE_REJECT * 02-04-2000 RMK Converted to use the new error handling, and * automatically request sense data upon check * condition status from targets.
*/ #include <linux/module.h> #include <linux/blkdev.h> #include <linux/kernel.h> #include <linux/string.h> #include <linux/ioport.h> #include <linux/proc_fs.h> #include <linux/delay.h> #include <linux/bitops.h> #include <linux/init.h> #include <linux/interrupt.h>
/* NOTE: SCSI2 Synchronous transfers *require* DMA according to * the data sheet. This restriction is crazy, especially when * you only want to send 16 bytes! What were the guys who * designed this chip on at that time? Did they read the SCSI2 * spec at all? The following sections are taken from the SCSI2 * standard (s2r10) concerning this: * * > IMPLEMENTORS NOTES: * > (1) Re-negotiation at every selection is not recommended, since a * > significant performance impact is likely. * * > The implied synchronous agreement shall remain in effect until a BUS DEVICE * > RESET message is received, until a hard reset condition occurs, or until one * > of the two SCSI devices elects to modify the agreement. The default data * > transfer mode is asynchronous data transfer mode. The default data transfer * > mode is entered at power on, after a BUS DEVICE RESET message, or after a hard * > reset condition. * * In total, this means that once you have elected to use synchronous * transfers, you must always use DMA. * * I was thinking that this was a good chip until I found this restriction ;(
*/ #define SCSI2_SYNC
printk(KERN_ERR "SCSI IRQ trail\n"); do {
printk(" %02x:%02x:%02x:%1x",
ph_list[i].stat, ph_list[i].ssr,
ph_list[i].isr, ph_list[i].ph);
i = (i + 1) & (PH_SIZE - 1); if (((i ^ ph_ptr) & 7) == 0)
printk("\n");
} while (i != ph_ptr); if ((i ^ ph_ptr) & 7)
printk("\n");
i = cmd_ptr;
printk(KERN_ERR "FAS216 commands: "); do {
printk("%02x:%p ", cmd_list[i].command, cmd_list[i].from);
i = (i + 1) & 7;
} while (i != cmd_ptr);
printk("\n");
}
/** * fas216_get_last_msg - retrive last message from the list * @info: interface to search * @pos: current fifo position * * Retrieve a last message from the list, using position in fifo.
*/ staticinlineunsignedshort
fas216_get_last_msg(FAS216_Info *info, int pos)
{ unsignedshort packed_msg = NOP; struct message *msg; int msgnr = 0;
while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) { if (pos >= msg->fifo) break;
}
if (msg) { if (msg->msg[0] == EXTENDED_MESSAGE)
packed_msg = EXTENDED_MESSAGE | msg->msg[2] << 8; else
packed_msg = msg->msg[0];
}
fas216_log(info, LOG_MESSAGES, "Message: %04x found at position %02x\n", packed_msg, pos);
return packed_msg;
}
/** * fas216_syncperiod - calculate STP register value * @info: state structure for interface connected to device * @ns: period in ns (between subsequent bytes) * * Calculate value to be loaded into the STP register for a given period * in ns. Returns a value suitable for REG_STP.
*/ staticint fas216_syncperiod(FAS216_Info *info, int ns)
{ int value = (info->ifcfg.clockrate * ns) / 1000;
fas216_checkmagic(info);
if (value < 4)
value = 4; elseif (value > 35)
value = 35;
return value & 31;
}
/** * fas216_set_sync - setup FAS216 chip for specified transfer period. * @info: state structure for interface connected to device * @target: target * * Correctly setup FAS216 chip for specified transfer period. * Notes : we need to switch the chip out of FASTSCSI mode if we have * a transfer period >= 200ns - otherwise the chip will violate * the SCSI timings.
*/ staticvoid fas216_set_sync(FAS216_Info *info, int target)
{ unsignedint cntl3;
/* Synchronous transfer support * * Note: The SCSI II r10 spec says (5.6.12): * * (2) Due to historical problems with early host adapters that could * not accept an SDTR message, some targets may not initiate synchronous * negotiation after a power cycle as required by this standard. Host * adapters that support synchronous mode may avoid the ensuing failure * modes when the target is independently power cycled by initiating a * synchronous negotiation on each REQUEST SENSE and INQUIRY command. * This approach increases the SCSI bus overhead and is not recommended * for new implementations. The correct method is to respond to an * SDTR message with a MESSAGE REJECT message if the either the * initiator or target devices does not support synchronous transfers * or does not want to negotiate for synchronous transfers at the time. * Using the correct method assures compatibility with wide data * transfers and future enhancements. * * We will always initiate a synchronous transfer negotiation request on * every INQUIRY or REQUEST SENSE message, unless the target itself has * at some point performed a synchronous transfer negotiation request, or * we have synchronous transfers disabled for this device.
*/
/** * fas216_handlesync - Handle a synchronous transfer message * @info: state structure for interface * @msg: message from target * * Handle a synchronous transfer message from the target
*/ staticvoid fas216_handlesync(FAS216_Info *info, char *msg)
{ struct fas216_device *dev = &info->device[info->SCpnt->device->id]; enum { sync, async, none, reject } res = none;
#ifdef SCSI2_SYNC switch (msg[0]) { case MESSAGE_REJECT: /* Synchronous transfer request failed. * Note: SCSI II r10: * * SCSI devices that are capable of synchronous * data transfers shall not respond to an SDTR * message with a MESSAGE REJECT message. * * Hence, if we get this condition, we disable * negotiation for this device.
*/ if (dev->sync_state == neg_inprogress) {
dev->sync_state = neg_invalid;
res = async;
} break;
case EXTENDED_MESSAGE: switch (dev->sync_state) { /* We don't accept synchronous transfer requests. * Respond with a MESSAGE_REJECT to prevent a * synchronous transfer agreement from being reached.
*/ case neg_invalid:
res = reject; break;
/* We were not negotiating a synchronous transfer, * but the device sent us a negotiation request. * Honour the request by sending back a SDTR * message containing our capability, limited by * the targets capability.
*/ default:
fas216_cmd(info, CMD_SETATN); if (msg[4] > info->ifcfg.sync_max_depth)
msg[4] = info->ifcfg.sync_max_depth; if (msg[3] < 1000 / info->ifcfg.clockrate)
msg[3] = 1000 / info->ifcfg.clockrate;
/* This is wrong. The agreement is not in effect * until this message is accepted by the device
*/
dev->sync_state = neg_targcomplete;
res = sync; break;
/* We initiated the synchronous transfer negotiation, * and have successfully received a response from the * target. The synchronous transfer agreement has been * reached. Note: if the values returned are out of our * bounds, we must reject the message.
*/ case neg_inprogress:
res = reject; if (msg[4] <= info->ifcfg.sync_max_depth &&
msg[3] >= 1000 / info->ifcfg.clockrate) {
dev->sync_state = neg_complete;
res = sync;
} break;
}
} #else
res = reject; #endif
/** * fas216_updateptrs - update data pointers after transfer suspended/paused * @info: interface's local pointer to update * @bytes_transferred: number of bytes transferred * * Update data pointers after transfer suspended/paused
*/ staticvoid fas216_updateptrs(FAS216_Info *info, int bytes_transferred)
{ struct scsi_pointer *SCp = &info->scsi.SCp;
fas216_checkmagic(info);
BUG_ON(bytes_transferred < 0);
SCp->phase -= bytes_transferred;
while (bytes_transferred != 0) { if (SCp->this_residual > bytes_transferred) break; /* * We have used up this buffer. Move on to the * next buffer.
*/
bytes_transferred -= SCp->this_residual; if (!next_SCp(SCp) && bytes_transferred) {
printk(KERN_WARNING "scsi%d.%c: out of buffers\n",
info->host->host_no, '0' + info->SCpnt->device->id); return;
}
}
/** * fas216_pio - transfer data off of/on to card using programmed IO * @info: interface to transfer data to/from * @direction: direction to transfer data (DMA_OUT/DMA_IN) * * Transfer data off of/on to card using programmed IO. * Notes: this is incredibly slow.
*/ staticvoid fas216_pio(FAS216_Info *info, fasdmadir_t direction)
{ struct scsi_pointer *SCp = &info->scsi.SCp;
/** * fas216_cleanuptransfer - clean up after a transfer has completed. * @info: interface to clean up * * Update the data pointers according to the number of bytes transferred * on the SCSI bus.
*/ staticvoid fas216_cleanuptransfer(FAS216_Info *info)
{ unsignedlong total, residual, fifo;
fasdmatype_t dmatype = info->dma.transfer_type;
info->dma.transfer_type = fasdma_none;
/* * PIO transfers do not need to be cleaned up.
*/ if (dmatype == fasdma_pio || dmatype == fasdma_none) return;
if (dmatype == fasdma_real_all)
total = info->scsi.SCp.phase; else
total = info->scsi.SCp.this_residual;
residual = fas216_get_ctc(info);
fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_log(info, LOG_BUFFER, "cleaning up from previous " "transfer: length 0x%06x, residual 0x%x, fifo %d",
total, residual, fifo);
/* * If we were performing Data-Out, the transfer counter * counts down each time a byte is transferred by the * host to the FIFO. This means we must include the * bytes left in the FIFO from the transfer counter.
*/ if (info->scsi.phase == PHASE_DATAOUT)
residual += fifo;
fas216_updateptrs(info, total - residual);
}
/** * fas216_transfer - Perform a DMA/PIO transfer off of/on to card * @info: interface from which device disconnected from * * Start a DMA/PIO transfer off of/on to card
*/ staticvoid fas216_transfer(FAS216_Info *info)
{
fasdmadir_t direction;
fasdmatype_t dmatype;
/* * If we have a synchronous transfer agreement in effect, we must * use DMA mode. If we are using asynchronous transfers, we may * use DMA mode or PIO mode.
*/ if (info->device[info->SCpnt->device->id].sof)
dmatype = fasdma_real_all; else
dmatype = fasdma_pio;
if (info->scsi.phase == PHASE_DATAOUT)
direction = DMA_OUT; else
direction = DMA_IN;
/** * fas216_stoptransfer - Stop a DMA transfer onto / off of the card * @info: interface from which device disconnected from * * Called when we switch away from DATA IN or DATA OUT phases.
*/ staticvoid fas216_stoptransfer(FAS216_Info *info)
{
fas216_checkmagic(info);
if (info->dma.transfer_type == fasdma_real_all ||
info->dma.transfer_type == fasdma_real_block)
info->dma.stop(info->host, &info->scsi.SCp);
fas216_cleanuptransfer(info);
if (info->scsi.phase == PHASE_DATAIN) { unsignedint fifo;
/* * If we were performing Data-In, then the FIFO counter * contains the number of bytes not transferred via DMA * from the on-board FIFO. Read them manually.
*/
fifo = fas216_readb(info, REG_CFIS) & CFIS_CF; while (fifo && info->scsi.SCp.ptr) {
*info->scsi.SCp.ptr = fas216_readb(info, REG_FF);
fas216_updateptrs(info, 1);
fifo--;
}
} else { /* * After a Data-Out phase, there may be unsent * bytes left in the FIFO. Flush them out.
*/
fas216_cmd(info, CMD_FLUSHFIFO);
}
}
if (info->scsi.disconnectable && info->SCpnt) {
info->scsi.disconnectable = 0; if (info->SCpnt->device->id == target &&
info->SCpnt->device->lun == lun &&
scsi_cmd_to_rq(info->SCpnt)->tag == tag) {
fas216_log(info, LOG_CONNECT, "reconnected previously executing command");
} else {
queue_add_cmd_tail(&info->queues.disconnected, info->SCpnt);
fas216_log(info, LOG_CONNECT, "had to move command to disconnected queue");
info->SCpnt = NULL;
}
} if (!info->SCpnt) {
info->SCpnt = queue_remove_tgtluntag(&info->queues.disconnected,
target, lun, tag);
fas216_log(info, LOG_CONNECT, "had to get command");
}
if (info->SCpnt) { /* * Restore data pointer from SAVED data pointer
*/
info->scsi.SCp = *arm_scsi_pointer(info->SCpnt);
fas216_log(info, LOG_CONNECT, "data pointers: [%p, %X]",
info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
info->scsi.phase = PHASE_MSGIN;
} else { /* * Our command structure not found - abort the * command on the target. Since we have no * record of this command, we can't send * an INITIATOR DETECTED ERROR message.
*/
fas216_cmd(info, CMD_SETATN);
initiator_error:
printk(KERN_ERR "scsi%d.H: error during reselection: bytes",
info->host->host_no); for (i = 0; i < cfis; i++)
printk(" %02x", msg[i]);
printk("\n");
bad_message:
fas216_cmd(info, CMD_SETATN);
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
fas216_cmd(info, CMD_MSGACCEPTED);
}
staticvoid fas216_parse_message(FAS216_Info *info, unsignedchar *message, int msglen)
{ struct scsi_pointer *scsi_pointer; int i;
switch (message[0]) { case COMMAND_COMPLETE: if (msglen != 1) goto unrecognised;
printk(KERN_ERR "scsi%d.%c: command complete with no " "status in MESSAGE_IN?\n",
info->host->host_no, fas216_target(info)); break;
case SAVE_POINTERS: if (msglen != 1) goto unrecognised;
/* * Save current data pointer to SAVED data pointer * SCSI II standard says that we must not acknowledge * this until we have really saved pointers. * NOTE: we DO NOT save the command nor status pointers * as required by the SCSI II standard. These always * point to the start of their respective areas.
*/
scsi_pointer = arm_scsi_pointer(info->SCpnt);
*scsi_pointer = info->scsi.SCp;
scsi_pointer->sent_command = 0;
fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER, "save data pointers: [%p, %X]",
info->scsi.SCp.ptr, info->scsi.SCp.this_residual); break;
case RESTORE_POINTERS: if (msglen != 1) goto unrecognised;
/* * Restore current data pointer from SAVED data pointer
*/
info->scsi.SCp = *arm_scsi_pointer(info->SCpnt);
fas216_log(info, LOG_CONNECT | LOG_MESSAGES | LOG_BUFFER, "restore data pointers: [%p, 0x%x]",
info->scsi.SCp.ptr, info->scsi.SCp.this_residual); break;
case DISCONNECT: if (msglen != 1) goto unrecognised;
info->scsi.phase = PHASE_MSGIN_DISCONNECT; break;
case MESSAGE_REJECT: if (msglen != 1) goto unrecognised;
case EXTENDED_MESSAGE: if (msglen < 3) goto unrecognised;
switch (message[2]) { case EXTENDED_SDTR: /* Sync transfer negotiation request/reply */
fas216_handlesync(info, message); break;
default: goto unrecognised;
} break;
default: goto unrecognised;
} return;
unrecognised:
fas216_log(info, 0, "unrecognised message, rejecting");
printk("scsi%d.%c: message was", info->host->host_no, fas216_target(info)); for (i = 0; i < msglen; i++)
printk("%s%02X", i & 31 ? " " : "\n ", message[i]);
printk("\n");
/* * Something strange seems to be happening here - * I can't use SETATN since the chip gives me an * invalid command interrupt when I do. Weird.
*/
fas216_cmd(info, CMD_NOP);
fas216_dumpstate(info);
fas216_cmd(info, CMD_SETATN);
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, MESSAGE_REJECT);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
fas216_dumpstate(info);
}
staticint fas216_wait_cmd(FAS216_Info *info, int cmd)
{ int tout; int stat;
fas216_cmd(info, cmd);
for (tout = 1000; tout; tout -= 1) {
stat = fas216_readb(info, REG_STAT); if (stat & (STAT_INT|STAT_PARITYERROR)) break;
udelay(1);
}
return stat;
}
staticint fas216_get_msg_byte(FAS216_Info *info)
{ unsignedint stat = fas216_wait_cmd(info, CMD_MSGACCEPTED);
if ((stat & STAT_INT) == 0) goto timedout;
if ((stat & STAT_BUSMASK) != STAT_MESGIN) goto unexpected_phase_change;
fas216_readb(info, REG_INST);
stat = fas216_wait_cmd(info, CMD_TRANSFERINFO);
if ((stat & STAT_INT) == 0) goto timedout;
if (stat & STAT_PARITYERROR) goto parity_error;
if ((stat & STAT_BUSMASK) != STAT_MESGIN) goto unexpected_phase_change;
fas216_readb(info, REG_INST);
return fas216_readb(info, REG_FF);
timedout:
fas216_log(info, LOG_ERROR, "timed out waiting for message byte"); return -1;
/** * fas216_send_command - send command after all message bytes have been sent * @info: interface which caused bus service * * Send a command to a target after all message bytes have been sent
*/ staticvoid fas216_send_command(FAS216_Info *info)
{ int i;
/* load command */ for (i = info->scsi.SCp.sent_command; i < info->SCpnt->cmd_len; i++)
fas216_writeb(info, REG_FF, info->SCpnt->cmnd[i]);
fas216_cmd(info, CMD_TRANSFERINFO);
info->scsi.phase = PHASE_COMMAND;
}
/** * fas216_send_messageout - handle bus service to send a message * @info: interface which caused bus service * * Handle bus service to send a message. * Note: We do not allow the device to change the data direction!
*/ staticvoid fas216_send_messageout(FAS216_Info *info, int start)
{ unsignedint tot_msglen = msgqueue_msglength(&info->scsi.msgs);
fas216_checkmagic(info);
fas216_cmd(info, CMD_FLUSHFIFO);
if (tot_msglen) { struct message *msg; int msgnr = 0;
while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) { int i;
for (i = start; i < msg->length; i++)
fas216_writeb(info, REG_FF, msg->msg[i]);
/** * fas216_busservice_intr - handle bus service interrupt from FAS216 chip * @info: interface which caused bus service interrupt * @stat: Status register contents * @is: SCSI Status register contents * * Handle a bus service interrupt from FAS216 chip
*/ staticvoid fas216_busservice_intr(FAS216_Info *info, unsignedint stat, unsignedint is)
{
fas216_checkmagic(info);
fas216_log(info, LOG_BUSSERVICE, "bus service: stat=%02x is=%02x phase=%02x",
stat, is, info->scsi.phase);
switch (info->scsi.phase) { case PHASE_SELECTION: if ((is & IS_BITS) != IS_MSGBYTESENT) goto bad_is; break;
case PHASE_SELSTEPS: switch (is & IS_BITS) { case IS_SELARB: case IS_MSGBYTESENT: goto bad_is;
case IS_NOTCOMMAND: case IS_EARLYPHASE: if ((stat & STAT_BUSMASK) == STAT_MESGIN) break; goto bad_is;
case IS_COMPLETE: break;
} break;
default: break;
}
fas216_cmd(info, CMD_NOP);
#define STATE(st,ph) ((ph) << 3 | (st)) /* This table describes the legal SCSI state transitions, * as described by the SCSI II spec.
*/ switch (STATE(stat & STAT_BUSMASK, info->scsi.phase)) { case STATE(STAT_DATAIN, PHASE_SELSTEPS):/* Sel w/ steps -> Data In */ case STATE(STAT_DATAIN, PHASE_MSGOUT): /* Message Out -> Data In */ case STATE(STAT_DATAIN, PHASE_COMMAND): /* Command -> Data In */ case STATE(STAT_DATAIN, PHASE_MSGIN): /* Message In -> Data In */
info->scsi.phase = PHASE_DATAIN;
fas216_transfer(info); return;
case STATE(STAT_DATAIN, PHASE_DATAIN): /* Data In -> Data In */ case STATE(STAT_DATAOUT, PHASE_DATAOUT):/* Data Out -> Data Out */
fas216_cleanuptransfer(info);
fas216_transfer(info); return;
case STATE(STAT_DATAOUT, PHASE_SELSTEPS):/* Sel w/ steps-> Data Out */ case STATE(STAT_DATAOUT, PHASE_MSGOUT): /* Message Out -> Data Out */ case STATE(STAT_DATAOUT, PHASE_COMMAND):/* Command -> Data Out */ case STATE(STAT_DATAOUT, PHASE_MSGIN): /* Message In -> Data Out */
fas216_cmd(info, CMD_FLUSHFIFO);
info->scsi.phase = PHASE_DATAOUT;
fas216_transfer(info); return;
case STATE(STAT_STATUS, PHASE_DATAOUT): /* Data Out -> Status */ case STATE(STAT_STATUS, PHASE_DATAIN): /* Data In -> Status */
fas216_stoptransfer(info);
fallthrough;
case STATE(STAT_STATUS, PHASE_SELSTEPS):/* Sel w/ steps -> Status */ case STATE(STAT_STATUS, PHASE_MSGOUT): /* Message Out -> Status */ case STATE(STAT_STATUS, PHASE_COMMAND): /* Command -> Status */ case STATE(STAT_STATUS, PHASE_MSGIN): /* Message In -> Status */
fas216_cmd(info, CMD_INITCMDCOMPLETE);
info->scsi.phase = PHASE_STATUS; return;
case STATE(STAT_MESGIN, PHASE_DATAOUT): /* Data Out -> Message In */ case STATE(STAT_MESGIN, PHASE_DATAIN): /* Data In -> Message In */
fas216_stoptransfer(info);
fallthrough;
case STATE(STAT_MESGIN, PHASE_COMMAND): /* Command -> Message In */ case STATE(STAT_MESGIN, PHASE_SELSTEPS):/* Sel w/ steps -> Message In */ case STATE(STAT_MESGIN, PHASE_MSGOUT): /* Message Out -> Message In */
info->scsi.msgin_fifo = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_cmd(info, CMD_FLUSHFIFO);
fas216_cmd(info, CMD_TRANSFERINFO);
info->scsi.phase = PHASE_MSGIN; return;
case STATE(STAT_COMMAND, PHASE_MSGOUT): /* Message Out -> Command */ case STATE(STAT_COMMAND, PHASE_MSGIN): /* Message In -> Command */
fas216_send_command(info);
info->scsi.phase = PHASE_COMMAND; return;
/* * Selection -> Message Out
*/ case STATE(STAT_MESGOUT, PHASE_SELECTION):
fas216_send_messageout(info, 1); return;
/* * Message Out -> Message Out
*/ case STATE(STAT_MESGOUT, PHASE_SELSTEPS): case STATE(STAT_MESGOUT, PHASE_MSGOUT): /* * If we get another message out phase, this usually * means some parity error occurred. Resend complete * set of messages. If we have more than one byte to * send, we need to assert ATN again.
*/ if (info->device[info->SCpnt->device->id].parity_check) { /* * We were testing... good, the device * supports parity checking.
*/
info->device[info->SCpnt->device->id].parity_check = 0;
info->device[info->SCpnt->device->id].parity_enabled = 1;
fas216_writeb(info, REG_CNTL1, info->scsi.cfg[0]);
}
if (msgqueue_msglength(&info->scsi.msgs) > 1)
fas216_cmd(info, CMD_SETATN);
fallthrough;
/* * Any -> Message Out
*/ case STATE(STAT_MESGOUT, PHASE_MSGOUT_EXPECT):
fas216_send_messageout(info, 0); return;
/* Error recovery rules. * These either attempt to abort or retry the operation. * TODO: we need more of these
*/ case STATE(STAT_COMMAND, PHASE_COMMAND):/* Command -> Command */ /* error - we've sent out all the command bytes * we have. * NOTE: we need SAVE DATA POINTERS/RESTORE DATA POINTERS * to include the command bytes sent for this to work * correctly.
*/
printk(KERN_ERR "scsi%d.%c: " "target trying to receive more command bytes\n",
info->host->host_no, fas216_target(info));
fas216_cmd(info, CMD_SETATN);
fas216_set_stc(info, 15);
fas216_cmd(info, CMD_PADBYTES | CMD_WITHDMA);
msgqueue_flush(&info->scsi.msgs);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT; return;
}
if (info->scsi.phase == PHASE_MSGIN_DISCONNECT) {
printk(KERN_ERR "scsi%d.%c: disconnect message received, but bus service %s?\n",
info->host->host_no, fas216_target(info),
fas216_bus_phase(stat));
msgqueue_flush(&info->scsi.msgs);
fas216_cmd(info, CMD_SETATN);
msgqueue_addmsg(&info->scsi.msgs, 1, INITIATOR_ERROR);
info->scsi.phase = PHASE_MSGOUT_EXPECT;
info->scsi.aborting = 1;
fas216_cmd(info, CMD_TRANSFERINFO); return;
}
printk(KERN_ERR "scsi%d.%c: bus phase %s after %s?\n",
info->host->host_no, fas216_target(info),
fas216_bus_phase(stat),
fas216_drv_phase(info));
print_debug_list(); return;
bad_is:
fas216_log(info, 0, "bus service at step %d?", is & IS_BITS);
fas216_dumpstate(info);
print_debug_list();
fas216_done(info, DID_ERROR);
}
/** * fas216_funcdone_intr - handle a function done interrupt from FAS216 chip * @info: interface which caused function done interrupt * @stat: Status register contents * @is: SCSI Status register contents * * Handle a function done interrupt from FAS216 chip
*/ staticvoid fas216_funcdone_intr(FAS216_Info *info, unsignedint stat, unsignedint is)
{ unsignedint fifo_len = fas216_readb(info, REG_CFIS) & CFIS_CF;
fas216_checkmagic(info);
fas216_log(info, LOG_FUNCTIONDONE, "function done: stat=%02x is=%02x phase=%02x",
stat, is, info->scsi.phase);
switch (info->scsi.phase) { case PHASE_STATUS: /* status phase - read status and msg */ if (fifo_len != 2) {
fas216_log(info, 0, "odd number of bytes in FIFO: %d", fifo_len);
} /* * Read status then message byte.
*/
info->scsi.SCp.Status = fas216_readb(info, REG_FF);
info->scsi.SCp.Message = fas216_readb(info, REG_FF);
info->scsi.phase = PHASE_DONE;
fas216_cmd(info, CMD_MSGACCEPTED); break;
case PHASE_IDLE: case PHASE_SELECTION: case PHASE_SELSTEPS: break;
case PHASE_MSGIN: /* message in phase */ if ((stat & STAT_BUSMASK) == STAT_MESGIN) {
info->scsi.msgin_fifo = fifo_len;
fas216_message(info); break;
}
fallthrough;
default:
fas216_log(info, 0, "internal phase %s for function done?" " What do I do with this?",
fas216_target(info), fas216_drv_phase(info));
}
}
staticvoid fas216_bus_reset(FAS216_Info *info)
{
neg_t sync_state; int i;
msgqueue_flush(&info->scsi.msgs);
sync_state = neg_invalid;
#ifdef SCSI2_SYNC if (info->ifcfg.capabilities & (FASCAP_DMA|FASCAP_PSEUDODMA))
sync_state = neg_wait; #endif
/** * fas216_intr - handle interrupts to progress a command * @info: interface to service * * Handle interrupts from the interface to progress a command
*/
irqreturn_t fas216_intr(FAS216_Info *info)
{ unsignedchar inst, is, stat; int handled = IRQ_NONE;
fas216_checkmagic(info);
stat = fas216_readb(info, REG_STAT);
is = fas216_readb(info, REG_IS);
inst = fas216_readb(info, REG_INST);
printk("scsi%d.%c: message out: ",
info->host->host_no, '0' + SCpnt->device->id); while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) {
printk("{ "); for (i = 0; i < msg->length; i++)
printk("%02x ", msg->msg[i]);
printk("} ");
}
printk("\n");
} #endif
if (tot_msglen == 1 || tot_msglen == 3) { /* * We have an easy message length to send...
*/ struct message *msg; int msgnr = 0, i;
info->scsi.phase = PHASE_SELSTEPS;
/* load message bytes */ while ((msg = msgqueue_getmsg(&info->scsi.msgs, msgnr++)) != NULL) { for (i = 0; i < msg->length; i++)
fas216_writeb(info, REG_FF, msg->msg[i]);
msg->fifo = tot_msglen - (fas216_readb(info, REG_CFIS) & CFIS_CF);
}
/* load command */ for (i = 0; i < SCpnt->cmd_len; i++)
fas216_writeb(info, REG_FF, SCpnt->cmnd[i]);
if (tot_msglen == 1)
fas216_cmd(info, CMD_SELECTATN); else
fas216_cmd(info, CMD_SELECTATN3);
} else { /* * We have an unusual number of message bytes to send. * Load first byte into fifo, and issue SELECT with ATN and * stop steps.
*/ struct message *msg = msgqueue_getmsg(&info->scsi.msgs, 0);
/* * Decide whether we need to perform a parity test on this device. * Can also be used to force parity error conditions during initial * information transfer phase (message out) for test purposes.
*/ staticint parity_test(FAS216_Info *info, int target)
{ #if 0 if (target == 3) {
info->device[target].parity_check = 0; return 1;
} #endif return info->device[target].parity_check;
}
staticvoid fas216_start_command(FAS216_Info *info, struct scsi_cmnd *SCpnt)
{ int disconnect_ok;
/* * add tag message if required
*/ if (SCpnt->device->simple_tags)
msgqueue_addmsg(&info->scsi.msgs, 2, SIMPLE_QUEUE_TAG,
scsi_cmd_to_rq(SCpnt)->tag);
switch (where_from) { case TYPE_QUEUE:
fas216_allocate_tag(info, SCpnt);
fallthrough; case TYPE_OTHER:
fas216_start_command(info, SCpnt); break; case TYPE_RESET:
fas216_do_bus_device_reset(info, SCpnt); break;
}
fas216_log(info, LOG_CONNECT, "select: data pointers [%p, %X]",
info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
/* * should now get either DISCONNECT or * (FUNCTION DONE with BUS SERVICE) interrupt
*/
}
/* * Clean up from issuing a BUS DEVICE RESET message to a device.
*/ staticvoid fas216_devicereset_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsignedint result)
{
fas216_log(info, LOG_ERROR, "fas216 device reset complete");
/** * fas216_rq_sns_done - Finish processing automatic request sense command * @info: interface that completed * @SCpnt: command that completed * @result: driver byte of result * * Finish processing automatic request sense command
*/ staticvoid fas216_rq_sns_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsignedint result)
{ struct scsi_pointer *scsi_pointer = arm_scsi_pointer(SCpnt);
fas216_log_target(info, LOG_CONNECT, SCpnt->device->id, "request sense complete, result=0x%04x%02x%02x",
result, scsi_pointer->Message, scsi_pointer->Status);
if (result != DID_OK || scsi_pointer->Status != SAM_STAT_GOOD) /* * Something went wrong. Make sure that we don't * have valid data in the sense buffer that could * confuse the higher levels.
*/
memset(SCpnt->sense_buffer, 0, SCSI_SENSE_BUFFERSIZE); //printk("scsi%d.%c: sense buffer: ", info->host->host_no, '0' + SCpnt->device->id); //{ int i; for (i = 0; i < 32; i++) printk("%02x ", SCpnt->sense_buffer[i]); printk("\n"); } /* * Note that we don't set SCpnt->result, since that should * reflect the status of the command that we were asked by * the upper layers to process. This would have been set * correctly by fas216_std_done.
*/
scsi_eh_restore_cmnd(SCpnt, &info->ses);
fas216_cmd_priv(SCpnt)->scsi_done(SCpnt);
}
/** * fas216_std_done - finish processing of standard command * @info: interface that completed * @SCpnt: command that completed * @result: driver byte of result * * Finish processing of standard command
*/ staticvoid
fas216_std_done(FAS216_Info *info, struct scsi_cmnd *SCpnt, unsignedint result)
{ struct scsi_pointer *scsi_pointer = arm_scsi_pointer(SCpnt);
info->stats.fins += 1;
set_host_byte(SCpnt, result); if (result == DID_OK)
scsi_msg_to_host_byte(SCpnt, info->scsi.SCp.Message);
set_status_byte(SCpnt, info->scsi.SCp.Status);
/* * If the driver detected an error, we're all done.
*/ if (get_host_byte(SCpnt) != DID_OK) goto done;
/* * If the command returned CHECK_CONDITION or COMMAND_TERMINATED * status, request the sense information.
*/ if (get_status_byte(SCpnt) == SAM_STAT_CHECK_CONDITION ||
get_status_byte(SCpnt) == SAM_STAT_COMMAND_TERMINATED) goto request_sense;
/* * If the command did not complete with GOOD status, * we are all done here.
*/ if (get_status_byte(SCpnt) != SAM_STAT_GOOD) goto done;
/* * We have successfully completed a command. Make sure that * we do not have any buffers left to transfer. The world * is not perfect, and we seem to occasionally hit this. * It can be indicative of a buggy driver, target or the upper * levels of the SCSI code.
*/ if (info->scsi.SCp.ptr) { switch (SCpnt->cmnd[0]) { case INQUIRY: case START_STOP: case MODE_SENSE: break;
default:
scmd_printk(KERN_ERR, SCpnt, "incomplete data transfer detected: res=%08X ptr=%p len=%X\n",
SCpnt->result, info->scsi.SCp.ptr,
info->scsi.SCp.this_residual);
scsi_print_command(SCpnt);
set_host_byte(SCpnt, DID_ERROR); goto request_sense;
}
}
done: if (fas216_cmd_priv(SCpnt)->scsi_done) {
fas216_cmd_priv(SCpnt)->scsi_done(SCpnt); return;
}
panic("scsi%d.H: null scsi_done function in fas216_done",
info->host->host_no);
request_sense: if (SCpnt->cmnd[0] == REQUEST_SENSE) goto done;
/* * Place this command into the high priority "request * sense" slot. This will be the very next command * executed, unless a target connects to us.
*/ if (info->reqSCpnt)
printk(KERN_WARNING "scsi%d.%c: losing request command\n",
info->host->host_no, '0' + SCpnt->device->id);
info->reqSCpnt = SCpnt;
}
/** * fas216_done - complete processing for current command * @info: interface that completed * @result: driver byte of result * * Complete processing for current command
*/ staticvoid fas216_done(FAS216_Info *info, unsignedint result)
{ void (*fn)(FAS216_Info *, struct scsi_cmnd *, unsignedint); struct scsi_cmnd *SCpnt; unsignedlong flags;
if (info->scsi.aborting) {
fas216_log(info, 0, "uncaught abort - returning DID_ABORT");
result = DID_ABORT;
info->scsi.aborting = 0;
}
/* * Sanity check the completion - if we have zero bytes left * to transfer, we should not have a valid pointer.
*/ if (info->scsi.SCp.ptr && info->scsi.SCp.this_residual == 0) {
scmd_printk(KERN_INFO, SCpnt, "zero bytes left to transfer, but buffer pointer still valid: ptr=%p len=%08x\n",
info->scsi.SCp.ptr, info->scsi.SCp.this_residual);
info->scsi.SCp.ptr = NULL;
scsi_print_command(SCpnt);
}
/* * Clear down this command as completed. If we need to request * the sense information, fas216_kick will re-assert the busy * status.
*/
info->device[SCpnt->device->id].parity_check = 0;
clear_bit(SCpnt->device->id * 8 +
(u8)(SCpnt->device->lun & 0x7), info->busyluns);
if (info->scsi.irq) {
spin_lock_irqsave(&info->host_lock, flags); if (info->scsi.phase == PHASE_IDLE)
fas216_kick(info);
spin_unlock_irqrestore(&info->host_lock, flags);
} return;
no_command:
panic("scsi%d.H: null command in fas216_done",
info->host->host_no);
}
/** * fas216_queue_command_internal - queue a command for the adapter to process * @SCpnt: Command to queue * @done: done function to call once command is complete * * Queue a command for adapter to process. * Returns: 0 on success, else error. * Notes: io_request_lock is held, interrupts are disabled.
*/ staticint fas216_queue_command_internal(struct scsi_cmnd *SCpnt, void (*done)(struct scsi_cmnd *))
{
FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata; int result;
/* * Add command into execute queue and let it complete under * whatever scheme we're using.
*/
result = !queue_add_cmd_ordered(&info->queues.issue, SCpnt);
/* * If we successfully added the command, * kick the interface to get it moving.
*/ if (result == 0 && info->scsi.phase == PHASE_IDLE)
fas216_kick(info);
spin_unlock(&info->host_lock);
fas216_log_target(info, LOG_CONNECT, -1, "queue %s",
result ? "failure" : "success");
/** * fas216_internal_done - trigger restart of a waiting thread in fas216_noqueue_command * @SCpnt: Command to wake * * Trigger restart of a waiting thread in fas216_command
*/ staticvoid fas216_internal_done(struct scsi_cmnd *SCpnt)
{
FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
fas216_checkmagic(info);
info->internal_done = 1;
}
/** * fas216_noqueue_command - process a command for the adapter. * @SCpnt: Command to queue * * Queue a command for adapter to process. * Returns: scsi result code. * Notes: io_request_lock is held, interrupts are disabled.
*/ staticint fas216_noqueue_command_lck(struct scsi_cmnd *SCpnt)
{
FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata;
fas216_checkmagic(info);
/* * We should only be using this if we don't have an interrupt. * Provide some "incentive" to use the queueing code.
*/
BUG_ON(info->scsi.irq);
/* * This wastes time, since we can't return until the command is * complete. We can't sleep either since we may get re-entered! * However, we must re-enable interrupts, or else we'll be * waiting forever.
*/
spin_unlock_irq(info->host->host_lock);
while (!info->internal_done) { /* * If we don't have an IRQ, then we must poll the card for * it's interrupt, and use that to call this driver's * interrupt routine. That way, we keep the command * progressing. Maybe we can add some intelligence here * and go to sleep if we know that the device is going * to be some time (eg, disconnected).
*/ if (fas216_readb(info, REG_STAT) & STAT_INT) {
spin_lock_irq(info->host->host_lock);
fas216_intr(info);
spin_unlock_irq(info->host->host_lock);
}
}
spin_lock_irq(info->host->host_lock);
scsi_done(SCpnt);
return 0;
}
DEF_SCSI_QCMD(fas216_noqueue_command)
/* * Error handler timeout function. Indicate that we timed out, * and wake up any error handler process so it can continue.
*/ staticvoid fas216_eh_timer(struct timer_list *t)
{
FAS216_Info *info = timer_container_of(info, t, eh_timer);
if (info->rst_bus_status == 0)
info->rst_bus_status = -1; if (info->rst_dev_status == 0)
info->rst_dev_status = -1;
wake_up(&info->eh_wait);
}
enum res_find {
res_failed, /* not found */
res_success, /* command on issue queue */
res_hw_abort /* command on disconnected dev */
};
/** * fas216_do_abort - decide how to abort a command * @SCpnt: command to abort * * Decide how to abort a command. * Returns: abort status
*/ staticenum res_find fas216_find_command(FAS216_Info *info, struct scsi_cmnd *SCpnt)
{ enum res_find res = res_failed;
if (queue_remove_cmd(&info->queues.issue, SCpnt)) { /* * The command was on the issue queue, and has not been * issued yet. We can remove the command from the queue, * and acknowledge the abort. Neither the device nor the * interface know about the command.
*/
printk("on issue queue ");
res = res_success;
} elseif (queue_remove_cmd(&info->queues.disconnected, SCpnt)) { /* * The command was on the disconnected queue. We must * reconnect with the device if possible, and send it * an abort message.
*/
printk("on disconnected queue ");
switch (info->scsi.phase) { /* * If the interface is idle, and the command is 'disconnectable', * then it is the same as on the disconnected queue.
*/ case PHASE_IDLE: if (info->scsi.disconnectable) {
info->scsi.disconnectable = 0;
info->SCpnt = NULL;
res = res_hw_abort;
} break;
default: break;
}
} elseif (info->origSCpnt == SCpnt) { /* * The command will be executed next, but a command * is currently using the interface. This is similar to * being on the issue queue, except the busylun bit has * been set.
*/
info->origSCpnt = NULL;
clear_bit(SCpnt->device->id * 8 +
(u8)(SCpnt->device->lun & 0x7), info->busyluns);
printk("waiting for execution ");
res = res_success;
} else
printk("unknown ");
return res;
}
/** * fas216_eh_abort - abort this command * @SCpnt: command to abort * * Abort this command. * Returns: FAILED if unable to abort * Notes: io_request_lock is taken, and irqs are disabled
*/ int fas216_eh_abort(struct scsi_cmnd *SCpnt)
{
FAS216_Info *info = (FAS216_Info *)SCpnt->device->host->hostdata; int result = FAILED;
switch (fas216_find_command(info, SCpnt)) { /* * We found the command, and cleared it out. Either * the command is still known to be executing on the * target, or the busylun bit is not set.
*/ case res_success:
scmd_printk(KERN_WARNING, SCpnt, "abort %p success\n", SCpnt);
result = SUCCESS; break;
/* * We need to reconnect to the target and send it an * ABORT or ABORT_TAG message. We can only do this * if the bus is free.
*/ case res_hw_abort:
/* * We are unable to abort the command for some reason.
*/ default: case res_failed:
scmd_printk(KERN_WARNING, SCpnt, "abort %p failed\n", SCpnt); break;
}
return result;
}
/** * fas216_eh_device_reset - Reset the device associated with this command * @SCpnt: command specifing device to reset * * Reset the device associated with this command. * Returns: FAILED if unable to reset. * Notes: We won't be re-entered, so we'll only have one device * reset on the go at one time.
*/ int fas216_eh_device_reset(struct scsi_cmnd *SCpnt)
{
--> --------------------
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.