Back to home page

OSCL-LXR

 
 

    


0001 /*======================================================================
0002 
0003     NinjaSCSI-3 / NinjaSCSI-32Bi PCMCIA SCSI host adapter card driver
0004       By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
0005 
0006     Ver.2.8   Support 32bit MMIO mode
0007               Support Synchronous Data Transfer Request (SDTR) mode
0008     Ver.2.0   Support 32bit PIO mode
0009     Ver.1.1.2 Fix for scatter list buffer exceeds
0010     Ver.1.1   Support scatter list
0011     Ver.0.1   Initial version
0012 
0013     This software may be used and distributed according to the terms of
0014     the GNU General Public License.
0015 
0016 ======================================================================*/
0017 
0018 /***********************************************************************
0019     This driver is for these PCcards.
0020 
0021     I-O DATA PCSC-F  (Workbit NinjaSCSI-3)
0022             "WBT", "NinjaSCSI-3", "R1.0"
0023     I-O DATA CBSC-II (Workbit NinjaSCSI-32Bi in 16bit mode)
0024             "IO DATA", "CBSC16   ", "1"
0025 
0026 ***********************************************************************/
0027 
0028 #include <linux/module.h>
0029 #include <linux/kernel.h>
0030 #include <linux/init.h>
0031 #include <linux/slab.h>
0032 #include <linux/string.h>
0033 #include <linux/timer.h>
0034 #include <linux/ioport.h>
0035 #include <linux/delay.h>
0036 #include <linux/interrupt.h>
0037 #include <linux/major.h>
0038 #include <linux/blkdev.h>
0039 #include <linux/stat.h>
0040 
0041 #include <asm/io.h>
0042 #include <asm/irq.h>
0043 
0044 #include <scsi/scsi.h>
0045 #include <scsi/scsi_cmnd.h>
0046 #include <scsi/scsi_host.h>
0047 #include <scsi/scsi_ioctl.h>
0048 
0049 #include <pcmcia/cistpl.h>
0050 #include <pcmcia/cisreg.h>
0051 #include <pcmcia/ds.h>
0052 
0053 #include "nsp_cs.h"
0054 
0055 MODULE_AUTHOR("YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>");
0056 MODULE_DESCRIPTION("WorkBit NinjaSCSI-3 / NinjaSCSI-32Bi(16bit) PCMCIA SCSI host adapter module");
0057 MODULE_LICENSE("GPL");
0058 
0059 #include "nsp_io.h"
0060 
0061 /*====================================================================*/
0062 /* Parameters that can be set with 'insmod' */
0063 
0064 static int       nsp_burst_mode = BURST_MEM32;
0065 module_param(nsp_burst_mode, int, 0);
0066 MODULE_PARM_DESC(nsp_burst_mode, "Burst transfer mode (0=io8, 1=io32, 2=mem32(default))");
0067 
0068 /* Release IO ports after configuration? */
0069 static bool       free_ports = 0;
0070 module_param(free_ports, bool, 0);
0071 MODULE_PARM_DESC(free_ports, "Release IO ports after configuration? (default: 0 (=no))");
0072 
0073 static struct scsi_pointer *nsp_priv(struct scsi_cmnd *cmd)
0074 {
0075     return scsi_cmd_priv(cmd);
0076 }
0077 
0078 static struct scsi_host_template nsp_driver_template = {
0079     .proc_name           = "nsp_cs",
0080     .show_info       = nsp_show_info,
0081     .name            = "WorkBit NinjaSCSI-3/32Bi(16bit)",
0082     .info            = nsp_info,
0083     .queuecommand        = nsp_queuecommand,
0084 /*  .eh_abort_handler    = nsp_eh_abort,*/
0085     .eh_bus_reset_handler    = nsp_eh_bus_reset,
0086     .eh_host_reset_handler   = nsp_eh_host_reset,
0087     .can_queue       = 1,
0088     .this_id         = NSP_INITIATOR_ID,
0089     .sg_tablesize        = SG_ALL,
0090     .dma_boundary        = PAGE_SIZE - 1,
0091     .cmd_size        = sizeof(struct scsi_pointer),
0092 };
0093 
0094 static nsp_hw_data nsp_data_base; /* attach <-> detect glue */
0095 
0096 
0097 
0098 /*
0099  * debug, error print
0100  */
0101 #ifndef NSP_DEBUG
0102 # define NSP_DEBUG_MASK     0x000000
0103 # define nsp_msg(type, args...) nsp_cs_message("", 0, (type), args)
0104 # define nsp_dbg(mask, args...) /* */
0105 #else
0106 # define NSP_DEBUG_MASK     0xffffff
0107 # define nsp_msg(type, args...) \
0108     nsp_cs_message (__func__, __LINE__, (type), args)
0109 # define nsp_dbg(mask, args...) \
0110     nsp_cs_dmessage(__func__, __LINE__, (mask), args)
0111 #endif
0112 
0113 #define NSP_DEBUG_QUEUECOMMAND      BIT(0)
0114 #define NSP_DEBUG_REGISTER      BIT(1)
0115 #define NSP_DEBUG_AUTOSCSI      BIT(2)
0116 #define NSP_DEBUG_INTR          BIT(3)
0117 #define NSP_DEBUG_SGLIST        BIT(4)
0118 #define NSP_DEBUG_BUSFREE       BIT(5)
0119 #define NSP_DEBUG_CDB_CONTENTS      BIT(6)
0120 #define NSP_DEBUG_RESELECTION       BIT(7)
0121 #define NSP_DEBUG_MSGINOCCUR        BIT(8)
0122 #define NSP_DEBUG_EEPROM        BIT(9)
0123 #define NSP_DEBUG_MSGOUTOCCUR       BIT(10)
0124 #define NSP_DEBUG_BUSRESET      BIT(11)
0125 #define NSP_DEBUG_RESTART       BIT(12)
0126 #define NSP_DEBUG_SYNC          BIT(13)
0127 #define NSP_DEBUG_WAIT          BIT(14)
0128 #define NSP_DEBUG_TARGETFLAG        BIT(15)
0129 #define NSP_DEBUG_PROC          BIT(16)
0130 #define NSP_DEBUG_INIT          BIT(17)
0131 #define NSP_DEBUG_DATA_IO           BIT(18)
0132 #define NSP_SPECIAL_PRINT_REGISTER  BIT(20)
0133 
0134 #define NSP_DEBUG_BUF_LEN       150
0135 
0136 static inline void nsp_inc_resid(struct scsi_cmnd *SCpnt, int residInc)
0137 {
0138     scsi_set_resid(SCpnt, scsi_get_resid(SCpnt) + residInc);
0139 }
0140 
0141 __printf(4, 5)
0142 static void nsp_cs_message(const char *func, int line, char *type, char *fmt, ...)
0143 {
0144     va_list args;
0145     char buf[NSP_DEBUG_BUF_LEN];
0146 
0147     va_start(args, fmt);
0148     vsnprintf(buf, sizeof(buf), fmt, args);
0149     va_end(args);
0150 
0151 #ifndef NSP_DEBUG
0152     printk("%snsp_cs: %s\n", type, buf);
0153 #else
0154     printk("%snsp_cs: %s (%d): %s\n", type, func, line, buf);
0155 #endif
0156 }
0157 
0158 #ifdef NSP_DEBUG
0159 static void nsp_cs_dmessage(const char *func, int line, int mask, char *fmt, ...)
0160 {
0161     va_list args;
0162     char buf[NSP_DEBUG_BUF_LEN];
0163 
0164     va_start(args, fmt);
0165     vsnprintf(buf, sizeof(buf), fmt, args);
0166     va_end(args);
0167 
0168     if (mask & NSP_DEBUG_MASK) {
0169         printk("nsp_cs-debug: 0x%x %s (%d): %s\n", mask, func, line, buf);
0170     }
0171 }
0172 #endif
0173 
0174 /***********************************************************/
0175 
0176 /*====================================================
0177  * Clenaup parameters and call done() functions.
0178  * You must be set SCpnt->result before call this function.
0179  */
0180 static void nsp_scsi_done(struct scsi_cmnd *SCpnt)
0181 {
0182     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0183 
0184     data->CurrentSC = NULL;
0185 
0186     scsi_done(SCpnt);
0187 }
0188 
0189 static int nsp_queuecommand_lck(struct scsi_cmnd *const SCpnt)
0190 {
0191     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0192 #ifdef NSP_DEBUG
0193     /*unsigned int host_id = SCpnt->device->host->this_id;*/
0194     /*unsigned int base    = SCpnt->device->host->io_port;*/
0195     unsigned char target = scmd_id(SCpnt);
0196 #endif
0197     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0198 
0199     nsp_dbg(NSP_DEBUG_QUEUECOMMAND,
0200         "SCpnt=0x%p target=%d lun=%llu sglist=0x%p bufflen=%d sg_count=%d",
0201         SCpnt, target, SCpnt->device->lun, scsi_sglist(SCpnt),
0202         scsi_bufflen(SCpnt), scsi_sg_count(SCpnt));
0203     //nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "before CurrentSC=0x%p", data->CurrentSC);
0204 
0205     if (data->CurrentSC != NULL) {
0206         nsp_msg(KERN_DEBUG, "CurrentSC!=NULL this can't be happen");
0207         SCpnt->result   = DID_BAD_TARGET << 16;
0208         nsp_scsi_done(SCpnt);
0209         return 0;
0210     }
0211 
0212 #if 0
0213     /* XXX: pcmcia-cs generates SCSI command with "scsi_info" utility.
0214             This makes kernel crash when suspending... */
0215     if (data->ScsiInfo->stop != 0) {
0216         nsp_msg(KERN_INFO, "suspending device. reject command.");
0217         SCpnt->result  = DID_BAD_TARGET << 16;
0218         nsp_scsi_done(SCpnt);
0219         return SCSI_MLQUEUE_HOST_BUSY;
0220     }
0221 #endif
0222 
0223     show_command(SCpnt);
0224 
0225     data->CurrentSC     = SCpnt;
0226 
0227     scsi_pointer->Status       = SAM_STAT_CHECK_CONDITION;
0228     scsi_pointer->Message      = 0;
0229     scsi_pointer->have_data_in = IO_UNKNOWN;
0230     scsi_pointer->sent_command = 0;
0231     scsi_pointer->phase    = PH_UNDETERMINED;
0232     scsi_set_resid(SCpnt, scsi_bufflen(SCpnt));
0233 
0234     /* setup scratch area
0235        SCp.ptr      : buffer pointer
0236        SCp.this_residual    : buffer length
0237        SCp.buffer       : next buffer
0238        SCp.buffers_residual : left buffers in list
0239        SCp.phase        : current state of the command */
0240     if (scsi_bufflen(SCpnt)) {
0241         scsi_pointer->buffer           = scsi_sglist(SCpnt);
0242         scsi_pointer->ptr          = BUFFER_ADDR(SCpnt);
0243         scsi_pointer->this_residual    = scsi_pointer->buffer->length;
0244         scsi_pointer->buffers_residual = scsi_sg_count(SCpnt) - 1;
0245     } else {
0246         scsi_pointer->ptr          = NULL;
0247         scsi_pointer->this_residual    = 0;
0248         scsi_pointer->buffer           = NULL;
0249         scsi_pointer->buffers_residual = 0;
0250     }
0251 
0252     if (!nsphw_start_selection(SCpnt)) {
0253         nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "selection fail");
0254         SCpnt->result   = DID_BUS_BUSY << 16;
0255         nsp_scsi_done(SCpnt);
0256         return 0;
0257     }
0258 
0259 
0260     //nsp_dbg(NSP_DEBUG_QUEUECOMMAND, "out");
0261 #ifdef NSP_DEBUG
0262     data->CmdId++;
0263 #endif
0264     return 0;
0265 }
0266 
0267 static DEF_SCSI_QCMD(nsp_queuecommand)
0268 
0269 /*
0270  * setup PIO FIFO transfer mode and enable/disable to data out
0271  */
0272 static void nsp_setup_fifo(nsp_hw_data *data, bool enabled)
0273 {
0274     unsigned int  base = data->BaseAddress;
0275     unsigned char transfer_mode_reg;
0276 
0277     //nsp_dbg(NSP_DEBUG_DATA_IO, "enabled=%d", enabled);
0278 
0279     if (enabled) {
0280         transfer_mode_reg = TRANSFER_GO | BRAIND;
0281     } else {
0282         transfer_mode_reg = 0;
0283     }
0284 
0285     transfer_mode_reg |= data->TransferMode;
0286 
0287     nsp_index_write(base, TRANSFERMODE, transfer_mode_reg);
0288 }
0289 
0290 static void nsphw_init_sync(nsp_hw_data *data)
0291 {
0292     sync_data tmp_sync = { .SyncNegotiation = SYNC_NOT_YET,
0293                    .SyncPeriod      = 0,
0294                    .SyncOffset      = 0
0295     };
0296     int i;
0297 
0298     /* setup sync data */
0299     for ( i = 0; i < ARRAY_SIZE(data->Sync); i++ ) {
0300         data->Sync[i] = tmp_sync;
0301     }
0302 }
0303 
0304 /*
0305  * Initialize Ninja hardware
0306  */
0307 static void nsphw_init(nsp_hw_data *data)
0308 {
0309     unsigned int base     = data->BaseAddress;
0310 
0311     nsp_dbg(NSP_DEBUG_INIT, "in base=0x%x", base);
0312 
0313     data->ScsiClockDiv = CLOCK_40M | FAST_20;
0314     data->CurrentSC    = NULL;
0315     data->FifoCount    = 0;
0316     data->TransferMode = MODE_IO8;
0317 
0318     nsphw_init_sync(data);
0319 
0320     /* block all interrupts */
0321     nsp_write(base,       IRQCONTROL,   IRQCONTROL_ALLMASK);
0322 
0323     /* setup SCSI interface */
0324     nsp_write(base,       IFSELECT,     IF_IFSEL);
0325 
0326     nsp_index_write(base, SCSIIRQMODE,  0);
0327 
0328     nsp_index_write(base, TRANSFERMODE, MODE_IO8);
0329     nsp_index_write(base, CLOCKDIV,     data->ScsiClockDiv);
0330 
0331     nsp_index_write(base, PARITYCTRL,   0);
0332     nsp_index_write(base, POINTERCLR,   POINTER_CLEAR     |
0333                         ACK_COUNTER_CLEAR |
0334                         REQ_COUNTER_CLEAR |
0335                         HOST_COUNTER_CLEAR);
0336 
0337     /* setup fifo asic */
0338     nsp_write(base,       IFSELECT,     IF_REGSEL);
0339     nsp_index_write(base, TERMPWRCTRL,  0);
0340     if ((nsp_index_read(base, OTHERCONTROL) & TPWR_SENSE) == 0) {
0341         nsp_msg(KERN_INFO, "terminator power on");
0342         nsp_index_write(base, TERMPWRCTRL, POWER_ON);
0343     }
0344 
0345     nsp_index_write(base, TIMERCOUNT,   0);
0346     nsp_index_write(base, TIMERCOUNT,   0); /* requires 2 times!! */
0347 
0348     nsp_index_write(base, SYNCREG,      0);
0349     nsp_index_write(base, ACKWIDTH,     0);
0350 
0351     /* enable interrupts and ack them */
0352     nsp_index_write(base, SCSIIRQMODE,  SCSI_PHASE_CHANGE_EI |
0353                         RESELECT_EI      |
0354                         SCSI_RESET_IRQ_EI    );
0355     nsp_write(base,       IRQCONTROL,   IRQCONTROL_ALLCLEAR);
0356 
0357     nsp_setup_fifo(data, false);
0358 }
0359 
0360 /*
0361  * Start selection phase
0362  */
0363 static bool nsphw_start_selection(struct scsi_cmnd *const SCpnt)
0364 {
0365     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0366     unsigned int  host_id    = SCpnt->device->host->this_id;
0367     unsigned int  base   = SCpnt->device->host->io_port;
0368     unsigned char target     = scmd_id(SCpnt);
0369     nsp_hw_data  *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0370     int       time_out;
0371     unsigned char phase, arbit;
0372 
0373     //nsp_dbg(NSP_DEBUG_RESELECTION, "in");
0374 
0375     phase = nsp_index_read(base, SCSIBUSMON);
0376     if(phase != BUSMON_BUS_FREE) {
0377         //nsp_dbg(NSP_DEBUG_RESELECTION, "bus busy");
0378         return false;
0379     }
0380 
0381     /* start arbitration */
0382     //nsp_dbg(NSP_DEBUG_RESELECTION, "start arbit");
0383     scsi_pointer->phase = PH_ARBSTART;
0384     nsp_index_write(base, SETARBIT, ARBIT_GO);
0385 
0386     time_out = 1000;
0387     do {
0388         /* XXX: what a stupid chip! */
0389         arbit = nsp_index_read(base, ARBITSTATUS);
0390         //nsp_dbg(NSP_DEBUG_RESELECTION, "arbit=%d, wait_count=%d", arbit, wait_count);
0391         udelay(1); /* hold 1.2us */
0392     } while((arbit & (ARBIT_WIN | ARBIT_FAIL)) == 0 &&
0393         (time_out-- != 0));
0394 
0395     if (!(arbit & ARBIT_WIN)) {
0396         //nsp_dbg(NSP_DEBUG_RESELECTION, "arbit fail");
0397         nsp_index_write(base, SETARBIT, ARBIT_FLAG_CLEAR);
0398         return false;
0399     }
0400 
0401     /* assert select line */
0402     //nsp_dbg(NSP_DEBUG_RESELECTION, "assert SEL line");
0403     scsi_pointer->phase = PH_SELSTART;
0404     udelay(3); /* wait 2.4us */
0405     nsp_index_write(base, SCSIDATALATCH, BIT(host_id) | BIT(target));
0406     nsp_index_write(base, SCSIBUSCTRL,   SCSI_SEL | SCSI_BSY                    | SCSI_ATN);
0407     udelay(2); /* wait >1.2us */
0408     nsp_index_write(base, SCSIBUSCTRL,   SCSI_SEL | SCSI_BSY | SCSI_DATAOUT_ENB | SCSI_ATN);
0409     nsp_index_write(base, SETARBIT,      ARBIT_FLAG_CLEAR);
0410     /*udelay(1);*/ /* wait >90ns */
0411     nsp_index_write(base, SCSIBUSCTRL,   SCSI_SEL            | SCSI_DATAOUT_ENB | SCSI_ATN);
0412 
0413     /* check selection timeout */
0414     nsp_start_timer(SCpnt, 1000/51);
0415     data->SelectionTimeOut = 1;
0416 
0417     return true;
0418 }
0419 
0420 struct nsp_sync_table {
0421     unsigned int min_period;
0422     unsigned int max_period;
0423     unsigned int chip_period;
0424     unsigned int ack_width;
0425 };
0426 
0427 static struct nsp_sync_table nsp_sync_table_40M[] = {
0428     {0x0c, 0x0c, 0x1, 0},   /* 20MB   50ns*/
0429     {0x19, 0x19, 0x3, 1},   /* 10MB  100ns*/ 
0430     {0x1a, 0x25, 0x5, 2},   /* 7.5MB 150ns*/ 
0431     {0x26, 0x32, 0x7, 3},   /* 5MB   200ns*/
0432     {   0,    0,   0, 0},
0433 };
0434 
0435 static struct nsp_sync_table nsp_sync_table_20M[] = {
0436     {0x19, 0x19, 0x1, 0},   /* 10MB  100ns*/ 
0437     {0x1a, 0x25, 0x2, 0},   /* 7.5MB 150ns*/ 
0438     {0x26, 0x32, 0x3, 1},   /* 5MB   200ns*/
0439     {   0,    0,   0, 0},
0440 };
0441 
0442 /*
0443  * setup synchronous data transfer mode
0444  */
0445 static int nsp_analyze_sdtr(struct scsi_cmnd *SCpnt)
0446 {
0447     unsigned char          target = scmd_id(SCpnt);
0448 //  unsigned char          lun    = SCpnt->device->lun;
0449     nsp_hw_data           *data   = (nsp_hw_data *)SCpnt->device->host->hostdata;
0450     sync_data         *sync   = &(data->Sync[target]);
0451     struct nsp_sync_table *sync_table;
0452     unsigned int           period, offset;
0453     int            i;
0454 
0455 
0456     nsp_dbg(NSP_DEBUG_SYNC, "in");
0457 
0458     period = sync->SyncPeriod;
0459     offset = sync->SyncOffset;
0460 
0461     nsp_dbg(NSP_DEBUG_SYNC, "period=0x%x, offset=0x%x", period, offset);
0462 
0463     if ((data->ScsiClockDiv & (BIT(0)|BIT(1))) == CLOCK_20M) {
0464         sync_table = nsp_sync_table_20M;
0465     } else {
0466         sync_table = nsp_sync_table_40M;
0467     }
0468 
0469     for ( i = 0; sync_table->max_period != 0; i++, sync_table++) {
0470         if ( period >= sync_table->min_period &&
0471              period <= sync_table->max_period    ) {
0472             break;
0473         }
0474     }
0475 
0476     if (period != 0 && sync_table->max_period == 0) {
0477         /*
0478          * No proper period/offset found
0479          */
0480         nsp_dbg(NSP_DEBUG_SYNC, "no proper period/offset");
0481 
0482         sync->SyncPeriod      = 0;
0483         sync->SyncOffset      = 0;
0484         sync->SyncRegister    = 0;
0485         sync->AckWidth        = 0;
0486 
0487         return false;
0488     }
0489 
0490     sync->SyncRegister    = (sync_table->chip_period << SYNCREG_PERIOD_SHIFT) |
0491                         (offset & SYNCREG_OFFSET_MASK);
0492     sync->AckWidth        = sync_table->ack_width;
0493 
0494     nsp_dbg(NSP_DEBUG_SYNC, "sync_reg=0x%x, ack_width=0x%x", sync->SyncRegister, sync->AckWidth);
0495 
0496     return true;
0497 }
0498 
0499 
0500 /*
0501  * start ninja hardware timer
0502  */
0503 static void nsp_start_timer(struct scsi_cmnd *SCpnt, int time)
0504 {
0505     unsigned int base = SCpnt->device->host->io_port;
0506     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0507 
0508     //nsp_dbg(NSP_DEBUG_INTR, "in SCpnt=0x%p, time=%d", SCpnt, time);
0509     data->TimerCount = time;
0510     nsp_index_write(base, TIMERCOUNT, time);
0511 }
0512 
0513 /*
0514  * wait for bus phase change
0515  */
0516 static int nsp_negate_signal(struct scsi_cmnd *SCpnt, unsigned char mask,
0517                  char *str)
0518 {
0519     unsigned int  base = SCpnt->device->host->io_port;
0520     unsigned char reg;
0521     int       time_out;
0522 
0523     //nsp_dbg(NSP_DEBUG_INTR, "in");
0524 
0525     time_out = 100;
0526 
0527     do {
0528         reg = nsp_index_read(base, SCSIBUSMON);
0529         if (reg == 0xff) {
0530             break;
0531         }
0532     } while ((--time_out != 0) && (reg & mask) != 0);
0533 
0534     if (time_out == 0) {
0535         nsp_msg(KERN_DEBUG, " %s signal off timeout", str);
0536     }
0537 
0538     return 0;
0539 }
0540 
0541 /*
0542  * expect Ninja Irq
0543  */
0544 static int nsp_expect_signal(struct scsi_cmnd *SCpnt,
0545                  unsigned char current_phase,
0546                  unsigned char mask)
0547 {
0548     unsigned int  base   = SCpnt->device->host->io_port;
0549     int       time_out;
0550     unsigned char phase, i_src;
0551 
0552     //nsp_dbg(NSP_DEBUG_INTR, "current_phase=0x%x, mask=0x%x", current_phase, mask);
0553 
0554     time_out = 100;
0555     do {
0556         phase = nsp_index_read(base, SCSIBUSMON);
0557         if (phase == 0xff) {
0558             //nsp_dbg(NSP_DEBUG_INTR, "ret -1");
0559             return -1;
0560         }
0561         i_src = nsp_read(base, IRQSTATUS);
0562         if (i_src & IRQSTATUS_SCSI) {
0563             //nsp_dbg(NSP_DEBUG_INTR, "ret 0 found scsi signal");
0564             return 0;
0565         }
0566         if ((phase & mask) != 0 && (phase & BUSMON_PHASE_MASK) == current_phase) {
0567             //nsp_dbg(NSP_DEBUG_INTR, "ret 1 phase=0x%x", phase);
0568             return 1;
0569         }
0570     } while(time_out-- != 0);
0571 
0572     //nsp_dbg(NSP_DEBUG_INTR, "timeout");
0573     return -1;
0574 }
0575 
0576 /*
0577  * transfer SCSI message
0578  */
0579 static int nsp_xfer(struct scsi_cmnd *const SCpnt, int phase)
0580 {
0581     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0582     unsigned int  base = SCpnt->device->host->io_port;
0583     nsp_hw_data  *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0584     char         *buf  = data->MsgBuffer;
0585     int       len  = min(MSGBUF_SIZE, data->MsgLen);
0586     int       ptr;
0587     int       ret;
0588 
0589     //nsp_dbg(NSP_DEBUG_DATA_IO, "in");
0590     for (ptr = 0; len > 0; len--, ptr++) {
0591 
0592         ret = nsp_expect_signal(SCpnt, phase, BUSMON_REQ);
0593         if (ret <= 0) {
0594             nsp_dbg(NSP_DEBUG_DATA_IO, "xfer quit");
0595             return 0;
0596         }
0597 
0598         /* if last byte, negate ATN */
0599         if (len == 1 && scsi_pointer->phase == PH_MSG_OUT) {
0600             nsp_index_write(base, SCSIBUSCTRL, AUTODIRECTION | ACKENB);
0601         }
0602 
0603         /* read & write message */
0604         if (phase & BUSMON_IO) {
0605             nsp_dbg(NSP_DEBUG_DATA_IO, "read msg");
0606             buf[ptr] = nsp_index_read(base, SCSIDATAWITHACK);
0607         } else {
0608             nsp_dbg(NSP_DEBUG_DATA_IO, "write msg");
0609             nsp_index_write(base, SCSIDATAWITHACK, buf[ptr]);
0610         }
0611         nsp_negate_signal(SCpnt, BUSMON_ACK, "xfer<ack>");
0612 
0613     }
0614     return len;
0615 }
0616 
0617 /*
0618  * get extra SCSI data from fifo
0619  */
0620 static int nsp_dataphase_bypass(struct scsi_cmnd *const SCpnt)
0621 {
0622     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0623     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0624     unsigned int count;
0625 
0626     //nsp_dbg(NSP_DEBUG_DATA_IO, "in");
0627 
0628     if (scsi_pointer->have_data_in != IO_IN) {
0629         return 0;
0630     }
0631 
0632     count = nsp_fifo_count(SCpnt);
0633     if (data->FifoCount == count) {
0634         //nsp_dbg(NSP_DEBUG_DATA_IO, "not use bypass quirk");
0635         return 0;
0636     }
0637 
0638     /*
0639      * XXX: NSP_QUIRK
0640      * data phase skip only occures in case of SCSI_LOW_READ
0641      */
0642     nsp_dbg(NSP_DEBUG_DATA_IO, "use bypass quirk");
0643     scsi_pointer->phase = PH_DATA;
0644     nsp_pio_read(SCpnt);
0645     nsp_setup_fifo(data, false);
0646 
0647     return 0;
0648 }
0649 
0650 /*
0651  * accept reselection
0652  */
0653 static void nsp_reselected(struct scsi_cmnd *SCpnt)
0654 {
0655     unsigned int  base    = SCpnt->device->host->io_port;
0656     unsigned int  host_id = SCpnt->device->host->this_id;
0657     //nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0658     unsigned char bus_reg;
0659     unsigned char id_reg, tmp;
0660     int target;
0661 
0662     nsp_dbg(NSP_DEBUG_RESELECTION, "in");
0663 
0664     id_reg = nsp_index_read(base, RESELECTID);
0665     tmp    = id_reg & (~BIT(host_id));
0666     target = 0;
0667     while(tmp != 0) {
0668         if (tmp & BIT(0)) {
0669             break;
0670         }
0671         tmp >>= 1;
0672         target++;
0673     }
0674 
0675     if (scmd_id(SCpnt) != target) {
0676         nsp_msg(KERN_ERR, "XXX: reselect ID must be %d in this implementation.", target);
0677     }
0678 
0679     nsp_negate_signal(SCpnt, BUSMON_SEL, "reselect<SEL>");
0680 
0681     nsp_nexus(SCpnt);
0682     bus_reg = nsp_index_read(base, SCSIBUSCTRL) & ~(SCSI_BSY | SCSI_ATN);
0683     nsp_index_write(base, SCSIBUSCTRL, bus_reg);
0684     nsp_index_write(base, SCSIBUSCTRL, bus_reg | AUTODIRECTION | ACKENB);
0685 }
0686 
0687 /*
0688  * count how many data transferd
0689  */
0690 static int nsp_fifo_count(struct scsi_cmnd *SCpnt)
0691 {
0692     unsigned int base = SCpnt->device->host->io_port;
0693     unsigned int count;
0694     unsigned int l, m, h;
0695 
0696     nsp_index_write(base, POINTERCLR, POINTER_CLEAR | ACK_COUNTER);
0697 
0698     l     = nsp_index_read(base, TRANSFERCOUNT);
0699     m     = nsp_index_read(base, TRANSFERCOUNT);
0700     h     = nsp_index_read(base, TRANSFERCOUNT);
0701     nsp_index_read(base, TRANSFERCOUNT); /* required this! */
0702 
0703     count = (h << 16) | (m << 8) | (l << 0);
0704 
0705     //nsp_dbg(NSP_DEBUG_DATA_IO, "count=0x%x", count);
0706 
0707     return count;
0708 }
0709 
0710 /* fifo size */
0711 #define RFIFO_CRIT 64
0712 #define WFIFO_CRIT 64
0713 
0714 /*
0715  * read data in DATA IN phase
0716  */
0717 static void nsp_pio_read(struct scsi_cmnd *const SCpnt)
0718 {
0719     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0720     unsigned int  base      = SCpnt->device->host->io_port;
0721     unsigned long mmio_base = SCpnt->device->host->base;
0722     nsp_hw_data  *data      = (nsp_hw_data *)SCpnt->device->host->hostdata;
0723     long          time_out;
0724     int       ocount, res;
0725     unsigned char stat, fifo_stat;
0726 
0727     ocount = data->FifoCount;
0728 
0729     nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p resid=%d ocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d",
0730         SCpnt, scsi_get_resid(SCpnt), ocount, scsi_pointer->ptr,
0731         scsi_pointer->this_residual, scsi_pointer->buffer,
0732         scsi_pointer->buffers_residual);
0733 
0734     time_out = 1000;
0735 
0736     while ((time_out-- != 0) &&
0737            (scsi_pointer->this_residual > 0 ||
0738         scsi_pointer->buffers_residual > 0)) {
0739 
0740         stat = nsp_index_read(base, SCSIBUSMON);
0741         stat &= BUSMON_PHASE_MASK;
0742 
0743 
0744         res = nsp_fifo_count(SCpnt) - ocount;
0745         //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this=0x%x ocount=0x%x res=0x%x", scsi_pointer->ptr, scsi_pointer->this_residual, ocount, res);
0746         if (res == 0) { /* if some data available ? */
0747             if (stat == BUSPHASE_DATA_IN) { /* phase changed? */
0748                 //nsp_dbg(NSP_DEBUG_DATA_IO, " wait for data this=%d", scsi_pointer->this_residual);
0749                 continue;
0750             } else {
0751                 nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x", stat);
0752                 break;
0753             }
0754         }
0755 
0756         fifo_stat = nsp_read(base, FIFOSTATUS);
0757         if ((fifo_stat & FIFOSTATUS_FULL_EMPTY) == 0 &&
0758             stat                                == BUSPHASE_DATA_IN) {
0759             continue;
0760         }
0761 
0762         res = min(res, scsi_pointer->this_residual);
0763 
0764         switch (data->TransferMode) {
0765         case MODE_IO32:
0766             res &= ~(BIT(1)|BIT(0)); /* align 4 */
0767             nsp_fifo32_read(base, scsi_pointer->ptr, res >> 2);
0768             break;
0769         case MODE_IO8:
0770             nsp_fifo8_read(base, scsi_pointer->ptr, res);
0771             break;
0772 
0773         case MODE_MEM32:
0774             res &= ~(BIT(1)|BIT(0)); /* align 4 */
0775             nsp_mmio_fifo32_read(mmio_base, scsi_pointer->ptr,
0776                          res >> 2);
0777             break;
0778 
0779         default:
0780             nsp_dbg(NSP_DEBUG_DATA_IO, "unknown read mode");
0781             return;
0782         }
0783 
0784         nsp_inc_resid(SCpnt, -res);
0785         scsi_pointer->ptr += res;
0786         scsi_pointer->this_residual -= res;
0787         ocount           += res;
0788         //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this_residual=0x%x ocount=0x%x", scsi_pointer->ptr, scsi_pointer->this_residual, ocount);
0789 
0790         /* go to next scatter list if available */
0791         if (scsi_pointer->this_residual == 0 &&
0792             scsi_pointer->buffers_residual != 0 ) {
0793             //nsp_dbg(NSP_DEBUG_DATA_IO, "scatterlist next timeout=%d", time_out);
0794             scsi_pointer->buffers_residual--;
0795             scsi_pointer->buffer = sg_next(scsi_pointer->buffer);
0796             scsi_pointer->ptr = BUFFER_ADDR(SCpnt);
0797             scsi_pointer->this_residual =
0798                 scsi_pointer->buffer->length;
0799             time_out = 1000;
0800 
0801             //nsp_dbg(NSP_DEBUG_DATA_IO, "page: 0x%p, off: 0x%x", scsi_pointer->buffer->page, scsi_pointer->buffer->offset);
0802         }
0803     }
0804 
0805     data->FifoCount = ocount;
0806 
0807     if (time_out < 0) {
0808         nsp_msg(KERN_DEBUG, "pio read timeout resid=%d this_residual=%d buffers_residual=%d",
0809             scsi_get_resid(SCpnt), scsi_pointer->this_residual,
0810             scsi_pointer->buffers_residual);
0811     }
0812     nsp_dbg(NSP_DEBUG_DATA_IO, "read ocount=0x%x", ocount);
0813     nsp_dbg(NSP_DEBUG_DATA_IO, "r cmd=%d resid=0x%x\n", data->CmdId,
0814                                                     scsi_get_resid(SCpnt));
0815 }
0816 
0817 /*
0818  * write data in DATA OUT phase
0819  */
0820 static void nsp_pio_write(struct scsi_cmnd *SCpnt)
0821 {
0822     struct scsi_pointer *scsi_pointer = nsp_priv(SCpnt);
0823     unsigned int  base      = SCpnt->device->host->io_port;
0824     unsigned long mmio_base = SCpnt->device->host->base;
0825     nsp_hw_data  *data      = (nsp_hw_data *)SCpnt->device->host->hostdata;
0826     int       time_out;
0827     int           ocount, res;
0828     unsigned char stat;
0829 
0830     ocount   = data->FifoCount;
0831 
0832     nsp_dbg(NSP_DEBUG_DATA_IO, "in fifocount=%d ptr=0x%p this_residual=%d buffers=0x%p nbuf=%d resid=0x%x",
0833         data->FifoCount, scsi_pointer->ptr, scsi_pointer->this_residual,
0834         scsi_pointer->buffer, scsi_pointer->buffers_residual,
0835         scsi_get_resid(SCpnt));
0836 
0837     time_out = 1000;
0838 
0839     while ((time_out-- != 0) &&
0840            (scsi_pointer->this_residual > 0 ||
0841         scsi_pointer->buffers_residual > 0)) {
0842         stat = nsp_index_read(base, SCSIBUSMON);
0843         stat &= BUSMON_PHASE_MASK;
0844 
0845         if (stat != BUSPHASE_DATA_OUT) {
0846             res = ocount - nsp_fifo_count(SCpnt);
0847 
0848             nsp_dbg(NSP_DEBUG_DATA_IO, "phase changed stat=0x%x, res=%d\n", stat, res);
0849             /* Put back pointer */
0850             nsp_inc_resid(SCpnt, res);
0851             scsi_pointer->ptr -= res;
0852             scsi_pointer->this_residual += res;
0853             ocount -= res;
0854 
0855             break;
0856         }
0857 
0858         res = ocount - nsp_fifo_count(SCpnt);
0859         if (res > 0) { /* write all data? */
0860             nsp_dbg(NSP_DEBUG_DATA_IO, "wait for all data out. ocount=0x%x res=%d", ocount, res);
0861             continue;
0862         }
0863 
0864         res = min(scsi_pointer->this_residual, WFIFO_CRIT);
0865 
0866         //nsp_dbg(NSP_DEBUG_DATA_IO, "ptr=0x%p this=0x%x res=0x%x", scsi_pointer->ptr, scsi_pointer->this_residual, res);
0867         switch (data->TransferMode) {
0868         case MODE_IO32:
0869             res &= ~(BIT(1)|BIT(0)); /* align 4 */
0870             nsp_fifo32_write(base, scsi_pointer->ptr, res >> 2);
0871             break;
0872         case MODE_IO8:
0873             nsp_fifo8_write(base, scsi_pointer->ptr, res);
0874             break;
0875 
0876         case MODE_MEM32:
0877             res &= ~(BIT(1)|BIT(0)); /* align 4 */
0878             nsp_mmio_fifo32_write(mmio_base, scsi_pointer->ptr,
0879                           res >> 2);
0880             break;
0881 
0882         default:
0883             nsp_dbg(NSP_DEBUG_DATA_IO, "unknown write mode");
0884             break;
0885         }
0886 
0887         nsp_inc_resid(SCpnt, -res);
0888         scsi_pointer->ptr += res;
0889         scsi_pointer->this_residual -= res;
0890         ocount += res;
0891 
0892         /* go to next scatter list if available */
0893         if (scsi_pointer->this_residual == 0 &&
0894             scsi_pointer->buffers_residual != 0 ) {
0895             //nsp_dbg(NSP_DEBUG_DATA_IO, "scatterlist next");
0896             scsi_pointer->buffers_residual--;
0897             scsi_pointer->buffer = sg_next(scsi_pointer->buffer);
0898             scsi_pointer->ptr = BUFFER_ADDR(SCpnt);
0899             scsi_pointer->this_residual =
0900                 scsi_pointer->buffer->length;
0901             time_out = 1000;
0902         }
0903     }
0904 
0905     data->FifoCount = ocount;
0906 
0907     if (time_out < 0) {
0908         nsp_msg(KERN_DEBUG, "pio write timeout resid=0x%x",
0909                                                 scsi_get_resid(SCpnt));
0910     }
0911     nsp_dbg(NSP_DEBUG_DATA_IO, "write ocount=0x%x", ocount);
0912     nsp_dbg(NSP_DEBUG_DATA_IO, "w cmd=%d resid=0x%x\n", data->CmdId,
0913                                                     scsi_get_resid(SCpnt));
0914 }
0915 #undef RFIFO_CRIT
0916 #undef WFIFO_CRIT
0917 
0918 /*
0919  * setup synchronous/asynchronous data transfer mode
0920  */
0921 static int nsp_nexus(struct scsi_cmnd *SCpnt)
0922 {
0923     unsigned int   base   = SCpnt->device->host->io_port;
0924     unsigned char  target = scmd_id(SCpnt);
0925 //  unsigned char  lun    = SCpnt->device->lun;
0926     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
0927     sync_data     *sync   = &(data->Sync[target]);
0928 
0929     //nsp_dbg(NSP_DEBUG_DATA_IO, "in SCpnt=0x%p", SCpnt);
0930 
0931     /* setup synch transfer registers */
0932     nsp_index_write(base, SYNCREG,  sync->SyncRegister);
0933     nsp_index_write(base, ACKWIDTH, sync->AckWidth);
0934 
0935     if (scsi_get_resid(SCpnt) % 4 != 0 ||
0936         scsi_get_resid(SCpnt) <= PAGE_SIZE ) {
0937         data->TransferMode = MODE_IO8;
0938     } else if (nsp_burst_mode == BURST_MEM32) {
0939         data->TransferMode = MODE_MEM32;
0940     } else if (nsp_burst_mode == BURST_IO32) {
0941         data->TransferMode = MODE_IO32;
0942     } else {
0943         data->TransferMode = MODE_IO8;
0944     }
0945 
0946     /* setup pdma fifo */
0947     nsp_setup_fifo(data, true);
0948 
0949     /* clear ack counter */
0950     data->FifoCount = 0;
0951     nsp_index_write(base, POINTERCLR, POINTER_CLEAR     |
0952                       ACK_COUNTER_CLEAR |
0953                       REQ_COUNTER_CLEAR |
0954                       HOST_COUNTER_CLEAR);
0955 
0956     return 0;
0957 }
0958 
0959 #include "nsp_message.c"
0960 /*
0961  * interrupt handler
0962  */
0963 static irqreturn_t nspintr(int irq, void *dev_id)
0964 {
0965     unsigned int   base;
0966     unsigned char  irq_status, irq_phase, phase;
0967     struct scsi_cmnd *tmpSC;
0968     struct scsi_pointer *scsi_pointer;
0969     unsigned char  target, lun;
0970     unsigned int  *sync_neg;
0971     int            i, tmp;
0972     nsp_hw_data   *data;
0973 
0974 
0975     //nsp_dbg(NSP_DEBUG_INTR, "dev_id=0x%p", dev_id);
0976     //nsp_dbg(NSP_DEBUG_INTR, "host=0x%p", ((scsi_info_t *)dev_id)->host);
0977 
0978     if (                dev_id        != NULL &&
0979         ((scsi_info_t *)dev_id)->host != NULL  ) {
0980         scsi_info_t *info = (scsi_info_t *)dev_id;
0981 
0982         data = (nsp_hw_data *)info->host->hostdata;
0983     } else {
0984         nsp_dbg(NSP_DEBUG_INTR, "host data wrong");
0985         return IRQ_NONE;
0986     }
0987 
0988     //nsp_dbg(NSP_DEBUG_INTR, "&nsp_data_base=0x%p, dev_id=0x%p", &nsp_data_base, dev_id);
0989 
0990     base = data->BaseAddress;
0991     //nsp_dbg(NSP_DEBUG_INTR, "base=0x%x", base);
0992 
0993     /*
0994      * interrupt check
0995      */
0996     nsp_write(base, IRQCONTROL, IRQCONTROL_IRQDISABLE);
0997     irq_status = nsp_read(base, IRQSTATUS);
0998     //nsp_dbg(NSP_DEBUG_INTR, "irq_status=0x%x", irq_status);
0999     if ((irq_status == 0xff) || ((irq_status & IRQSTATUS_MASK) == 0)) {
1000         nsp_write(base, IRQCONTROL, 0);
1001         //nsp_dbg(NSP_DEBUG_INTR, "no irq/shared irq");
1002         return IRQ_NONE;
1003     }
1004 
1005     /* XXX: IMPORTANT
1006      * Do not read an irq_phase register if no scsi phase interrupt.
1007      * Unless, you should lose a scsi phase interrupt.
1008      */
1009     phase = nsp_index_read(base, SCSIBUSMON);
1010     if((irq_status & IRQSTATUS_SCSI) != 0) {
1011         irq_phase = nsp_index_read(base, IRQPHASESENCE);
1012     } else {
1013         irq_phase = 0;
1014     }
1015 
1016     //nsp_dbg(NSP_DEBUG_INTR, "irq_phase=0x%x", irq_phase);
1017 
1018     /*
1019      * timer interrupt handler (scsi vs timer interrupts)
1020      */
1021     //nsp_dbg(NSP_DEBUG_INTR, "timercount=%d", data->TimerCount);
1022     if (data->TimerCount != 0) {
1023         //nsp_dbg(NSP_DEBUG_INTR, "stop timer");
1024         nsp_index_write(base, TIMERCOUNT, 0);
1025         nsp_index_write(base, TIMERCOUNT, 0);
1026         data->TimerCount = 0;
1027     }
1028 
1029     if ((irq_status & IRQSTATUS_MASK) == IRQSTATUS_TIMER &&
1030         data->SelectionTimeOut == 0) {
1031         //nsp_dbg(NSP_DEBUG_INTR, "timer start");
1032         nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR);
1033         return IRQ_HANDLED;
1034     }
1035 
1036     nsp_write(base, IRQCONTROL, IRQCONTROL_TIMER_CLEAR | IRQCONTROL_FIFO_CLEAR);
1037 
1038     if ((irq_status & IRQSTATUS_SCSI) &&
1039         (irq_phase  & SCSI_RESET_IRQ)) {
1040         nsp_msg(KERN_ERR, "bus reset (power off?)");
1041 
1042         nsphw_init(data);
1043         nsp_bus_reset(data);
1044 
1045         if(data->CurrentSC != NULL) {
1046             tmpSC = data->CurrentSC;
1047             scsi_pointer = nsp_priv(tmpSC);
1048             tmpSC->result = (DID_RESET              << 16) |
1049                 ((scsi_pointer->Message & 0xff) <<  8) |
1050                 ((scsi_pointer->Status  & 0xff) <<  0);
1051             nsp_scsi_done(tmpSC);
1052         }
1053         return IRQ_HANDLED;
1054     }
1055 
1056     if (data->CurrentSC == NULL) {
1057         nsp_msg(KERN_ERR, "CurrentSC==NULL irq_status=0x%x phase=0x%x irq_phase=0x%x this can't be happen. reset everything", irq_status, phase, irq_phase);
1058         nsphw_init(data);
1059         nsp_bus_reset(data);
1060         return IRQ_HANDLED;
1061     }
1062 
1063     tmpSC    = data->CurrentSC;
1064     scsi_pointer = nsp_priv(tmpSC);
1065     target   = tmpSC->device->id;
1066     lun      = tmpSC->device->lun;
1067     sync_neg = &(data->Sync[target].SyncNegotiation);
1068 
1069     /*
1070      * parse hardware SCSI irq reasons register
1071      */
1072     if (irq_status & IRQSTATUS_SCSI) {
1073         if (irq_phase & RESELECT_IRQ) {
1074             nsp_dbg(NSP_DEBUG_INTR, "reselect");
1075             nsp_write(base, IRQCONTROL, IRQCONTROL_RESELECT_CLEAR);
1076             nsp_reselected(tmpSC);
1077             return IRQ_HANDLED;
1078         }
1079 
1080         if ((irq_phase & (PHASE_CHANGE_IRQ | LATCHED_BUS_FREE)) == 0) {
1081             return IRQ_HANDLED;
1082         }
1083     }
1084 
1085     //show_phase(tmpSC);
1086 
1087     switch (scsi_pointer->phase) {
1088     case PH_SELSTART:
1089         // *sync_neg = SYNC_NOT_YET;
1090         if ((phase & BUSMON_BSY) == 0) {
1091             //nsp_dbg(NSP_DEBUG_INTR, "selection count=%d", data->SelectionTimeOut);
1092             if (data->SelectionTimeOut >= NSP_SELTIMEOUT) {
1093                 nsp_dbg(NSP_DEBUG_INTR, "selection time out");
1094                 data->SelectionTimeOut = 0;
1095                 nsp_index_write(base, SCSIBUSCTRL, 0);
1096 
1097                 tmpSC->result   = DID_TIME_OUT << 16;
1098                 nsp_scsi_done(tmpSC);
1099 
1100                 return IRQ_HANDLED;
1101             }
1102             data->SelectionTimeOut += 1;
1103             nsp_start_timer(tmpSC, 1000/51);
1104             return IRQ_HANDLED;
1105         }
1106 
1107         /* attention assert */
1108         //nsp_dbg(NSP_DEBUG_INTR, "attention assert");
1109         data->SelectionTimeOut = 0;
1110         scsi_pointer->phase = PH_SELECTED;
1111         nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN);
1112         udelay(1);
1113         nsp_index_write(base, SCSIBUSCTRL, SCSI_ATN | AUTODIRECTION | ACKENB);
1114         return IRQ_HANDLED;
1115 
1116     case PH_RESELECT:
1117         //nsp_dbg(NSP_DEBUG_INTR, "phase reselect");
1118         // *sync_neg = SYNC_NOT_YET;
1119         if ((phase & BUSMON_PHASE_MASK) != BUSPHASE_MESSAGE_IN) {
1120 
1121             tmpSC->result   = DID_ABORT << 16;
1122             nsp_scsi_done(tmpSC);
1123             return IRQ_HANDLED;
1124         }
1125         fallthrough;
1126     default:
1127         if ((irq_status & (IRQSTATUS_SCSI | IRQSTATUS_FIFO)) == 0) {
1128             return IRQ_HANDLED;
1129         }
1130         break;
1131     }
1132 
1133     /*
1134      * SCSI sequencer
1135      */
1136     //nsp_dbg(NSP_DEBUG_INTR, "start scsi seq");
1137 
1138     /* normal disconnect */
1139     if ((scsi_pointer->phase == PH_MSG_IN ||
1140          scsi_pointer->phase == PH_MSG_OUT) &&
1141         (irq_phase & LATCHED_BUS_FREE) != 0) {
1142         nsp_dbg(NSP_DEBUG_INTR, "normal disconnect irq_status=0x%x, phase=0x%x, irq_phase=0x%x", irq_status, phase, irq_phase);
1143 
1144         //*sync_neg       = SYNC_NOT_YET;
1145 
1146         /* all command complete and return status */
1147         if (scsi_pointer->Message == COMMAND_COMPLETE) {
1148             tmpSC->result = (DID_OK             << 16) |
1149                 ((scsi_pointer->Message & 0xff) <<  8) |
1150                 ((scsi_pointer->Status  & 0xff) <<  0);
1151             nsp_dbg(NSP_DEBUG_INTR, "command complete result=0x%x", tmpSC->result);
1152             nsp_scsi_done(tmpSC);
1153 
1154             return IRQ_HANDLED;
1155         }
1156 
1157         return IRQ_HANDLED;
1158     }
1159 
1160 
1161     /* check unexpected bus free state */
1162     if (phase == 0) {
1163         nsp_msg(KERN_DEBUG, "unexpected bus free. irq_status=0x%x, phase=0x%x, irq_phase=0x%x", irq_status, phase, irq_phase);
1164 
1165         *sync_neg       = SYNC_NG;
1166         tmpSC->result   = DID_ERROR << 16;
1167         nsp_scsi_done(tmpSC);
1168         return IRQ_HANDLED;
1169     }
1170 
1171     switch (phase & BUSMON_PHASE_MASK) {
1172     case BUSPHASE_COMMAND:
1173         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_COMMAND");
1174         if ((phase & BUSMON_REQ) == 0) {
1175             nsp_dbg(NSP_DEBUG_INTR, "REQ == 0");
1176             return IRQ_HANDLED;
1177         }
1178 
1179         scsi_pointer->phase = PH_COMMAND;
1180 
1181         nsp_nexus(tmpSC);
1182 
1183         /* write scsi command */
1184         nsp_dbg(NSP_DEBUG_INTR, "cmd_len=%d", tmpSC->cmd_len);
1185         nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER);
1186         for (i = 0; i < tmpSC->cmd_len; i++) {
1187             nsp_index_write(base, COMMANDDATA, tmpSC->cmnd[i]);
1188         }
1189         nsp_index_write(base, COMMANDCTRL, CLEAR_COMMAND_POINTER | AUTO_COMMAND_GO);
1190         break;
1191 
1192     case BUSPHASE_DATA_OUT:
1193         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_DATA_OUT");
1194 
1195         scsi_pointer->phase        = PH_DATA;
1196         scsi_pointer->have_data_in = IO_OUT;
1197 
1198         nsp_pio_write(tmpSC);
1199 
1200         break;
1201 
1202     case BUSPHASE_DATA_IN:
1203         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_DATA_IN");
1204 
1205         scsi_pointer->phase        = PH_DATA;
1206         scsi_pointer->have_data_in = IO_IN;
1207 
1208         nsp_pio_read(tmpSC);
1209 
1210         break;
1211 
1212     case BUSPHASE_STATUS:
1213         nsp_dataphase_bypass(tmpSC);
1214         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_STATUS");
1215 
1216         scsi_pointer->phase = PH_STATUS;
1217 
1218         scsi_pointer->Status = nsp_index_read(base, SCSIDATAWITHACK);
1219         nsp_dbg(NSP_DEBUG_INTR, "message=0x%x status=0x%x",
1220             scsi_pointer->Message, scsi_pointer->Status);
1221 
1222         break;
1223 
1224     case BUSPHASE_MESSAGE_OUT:
1225         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_MESSAGE_OUT");
1226         if ((phase & BUSMON_REQ) == 0) {
1227             goto timer_out;
1228         }
1229 
1230         scsi_pointer->phase = PH_MSG_OUT;
1231 
1232         //*sync_neg = SYNC_NOT_YET;
1233 
1234         data->MsgLen = i = 0;
1235         data->MsgBuffer[i] = IDENTIFY(true, lun); i++;
1236 
1237         if (*sync_neg == SYNC_NOT_YET) {
1238             data->Sync[target].SyncPeriod = 0;
1239             data->Sync[target].SyncOffset = 0;
1240 
1241             /**/
1242             data->MsgBuffer[i] = EXTENDED_MESSAGE; i++;
1243             data->MsgBuffer[i] = 3;            i++;
1244             data->MsgBuffer[i] = EXTENDED_SDTR; i++;
1245             data->MsgBuffer[i] = 0x0c;         i++;
1246             data->MsgBuffer[i] = 15;           i++;
1247             /**/
1248         }
1249         data->MsgLen = i;
1250 
1251         nsp_analyze_sdtr(tmpSC);
1252         show_message(data);
1253         nsp_message_out(tmpSC);
1254         break;
1255 
1256     case BUSPHASE_MESSAGE_IN:
1257         nsp_dataphase_bypass(tmpSC);
1258         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE_MESSAGE_IN");
1259         if ((phase & BUSMON_REQ) == 0) {
1260             goto timer_out;
1261         }
1262 
1263         scsi_pointer->phase = PH_MSG_IN;
1264         nsp_message_in(tmpSC);
1265 
1266         /**/
1267         if (*sync_neg == SYNC_NOT_YET) {
1268             //nsp_dbg(NSP_DEBUG_INTR, "sync target=%d,lun=%d",target,lun);
1269 
1270             if (data->MsgLen       >= 5            &&
1271                 data->MsgBuffer[0] == EXTENDED_MESSAGE &&
1272                 data->MsgBuffer[1] == 3            &&
1273                 data->MsgBuffer[2] == EXTENDED_SDTR ) {
1274                 data->Sync[target].SyncPeriod = data->MsgBuffer[3];
1275                 data->Sync[target].SyncOffset = data->MsgBuffer[4];
1276                 //nsp_dbg(NSP_DEBUG_INTR, "sync ok, %d %d", data->MsgBuffer[3], data->MsgBuffer[4]);
1277                 *sync_neg = SYNC_OK;
1278             } else {
1279                 data->Sync[target].SyncPeriod = 0;
1280                 data->Sync[target].SyncOffset = 0;
1281                 *sync_neg = SYNC_NG;
1282             }
1283             nsp_analyze_sdtr(tmpSC);
1284         }
1285         /**/
1286 
1287         /* search last messeage byte */
1288         tmp = -1;
1289         for (i = 0; i < data->MsgLen; i++) {
1290             tmp = data->MsgBuffer[i];
1291             if (data->MsgBuffer[i] == EXTENDED_MESSAGE) {
1292                 i += (1 + data->MsgBuffer[i+1]);
1293             }
1294         }
1295         scsi_pointer->Message = tmp;
1296 
1297         nsp_dbg(NSP_DEBUG_INTR, "message=0x%x len=%d",
1298             scsi_pointer->Message, data->MsgLen);
1299         show_message(data);
1300 
1301         break;
1302 
1303     case BUSPHASE_SELECT:
1304     default:
1305         nsp_dbg(NSP_DEBUG_INTR, "BUSPHASE other");
1306 
1307         break;
1308     }
1309 
1310     //nsp_dbg(NSP_DEBUG_INTR, "out");
1311     return IRQ_HANDLED;     
1312 
1313 timer_out:
1314     nsp_start_timer(tmpSC, 1000/102);
1315     return IRQ_HANDLED;
1316 }
1317 
1318 #ifdef NSP_DEBUG
1319 #include "nsp_debug.c"
1320 #endif  /* NSP_DEBUG */
1321 
1322 /*----------------------------------------------------------------*/
1323 /* look for ninja3 card and init if found             */
1324 /*----------------------------------------------------------------*/
1325 static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht)
1326 {
1327     struct Scsi_Host *host; /* registered host structure */
1328     nsp_hw_data *data_b = &nsp_data_base, *data;
1329 
1330     nsp_dbg(NSP_DEBUG_INIT, "this_id=%d", sht->this_id);
1331     host = scsi_host_alloc(&nsp_driver_template, sizeof(nsp_hw_data));
1332     if (host == NULL) {
1333         nsp_dbg(NSP_DEBUG_INIT, "host failed");
1334         return NULL;
1335     }
1336 
1337     memcpy(host->hostdata, data_b, sizeof(nsp_hw_data));
1338     data = (nsp_hw_data *)host->hostdata;
1339     data->ScsiInfo->host = host;
1340 #ifdef NSP_DEBUG
1341     data->CmdId = 0;
1342 #endif
1343 
1344     nsp_dbg(NSP_DEBUG_INIT, "irq=%d,%d", data_b->IrqNumber, ((nsp_hw_data *)host->hostdata)->IrqNumber);
1345 
1346     host->unique_id   = data->BaseAddress;
1347     host->io_port     = data->BaseAddress;
1348     host->n_io_port   = data->NumAddress;
1349     host->irq     = data->IrqNumber;
1350     host->base        = data->MmioAddress;
1351 
1352     spin_lock_init(&(data->Lock));
1353 
1354     snprintf(data->nspinfo,
1355          sizeof(data->nspinfo),
1356          "NinjaSCSI-3/32Bi Driver $Revision: 1.23 $ IO:0x%04lx-0x%04lx MMIO(virt addr):0x%04lx IRQ:%02d",
1357          host->io_port, host->io_port + host->n_io_port - 1,
1358          host->base,
1359          host->irq);
1360     sht->name     = data->nspinfo;
1361 
1362     nsp_dbg(NSP_DEBUG_INIT, "end");
1363 
1364 
1365     return host; /* detect done. */
1366 }
1367 
1368 /*----------------------------------------------------------------*/
1369 /* return info string                         */
1370 /*----------------------------------------------------------------*/
1371 static const char *nsp_info(struct Scsi_Host *shpnt)
1372 {
1373     nsp_hw_data *data = (nsp_hw_data *)shpnt->hostdata;
1374 
1375     return data->nspinfo;
1376 }
1377 
1378 static int nsp_show_info(struct seq_file *m, struct Scsi_Host *host)
1379 {
1380     int id;
1381     int speed;
1382     unsigned long flags;
1383     nsp_hw_data *data;
1384     int hostno;
1385 
1386     hostno = host->host_no;
1387     data = (nsp_hw_data *)host->hostdata;
1388 
1389     seq_puts(m, "NinjaSCSI status\n\n"
1390         "Driver version:        $Revision: 1.23 $\n");
1391     seq_printf(m, "SCSI host No.:         %d\n",          hostno);
1392     seq_printf(m, "IRQ:                   %d\n",          host->irq);
1393     seq_printf(m, "IO:                    0x%lx-0x%lx\n", host->io_port, host->io_port + host->n_io_port - 1);
1394     seq_printf(m, "MMIO(virtual address): 0x%lx-0x%lx\n", host->base, host->base + data->MmioLength - 1);
1395     seq_printf(m, "sg_tablesize:          %d\n",          host->sg_tablesize);
1396 
1397     seq_puts(m, "burst transfer mode:   ");
1398     switch (nsp_burst_mode) {
1399     case BURST_IO8:
1400         seq_puts(m, "io8");
1401         break;
1402     case BURST_IO32:
1403         seq_puts(m, "io32");
1404         break;
1405     case BURST_MEM32:
1406         seq_puts(m, "mem32");
1407         break;
1408     default:
1409         seq_puts(m, "???");
1410         break;
1411     }
1412     seq_putc(m, '\n');
1413 
1414 
1415     spin_lock_irqsave(&(data->Lock), flags);
1416     seq_printf(m, "CurrentSC:             0x%p\n\n",      data->CurrentSC);
1417     spin_unlock_irqrestore(&(data->Lock), flags);
1418 
1419     seq_puts(m, "SDTR status\n");
1420     for(id = 0; id < ARRAY_SIZE(data->Sync); id++) {
1421 
1422         seq_printf(m, "id %d: ", id);
1423 
1424         if (id == host->this_id) {
1425             seq_puts(m, "----- NinjaSCSI-3 host adapter\n");
1426             continue;
1427         }
1428 
1429         switch(data->Sync[id].SyncNegotiation) {
1430         case SYNC_OK:
1431             seq_puts(m, " sync");
1432             break;
1433         case SYNC_NG:
1434             seq_puts(m, "async");
1435             break;
1436         case SYNC_NOT_YET:
1437             seq_puts(m, " none");
1438             break;
1439         default:
1440             seq_puts(m, "?????");
1441             break;
1442         }
1443 
1444         if (data->Sync[id].SyncPeriod != 0) {
1445             speed = 1000000 / (data->Sync[id].SyncPeriod * 4);
1446 
1447             seq_printf(m, " transfer %d.%dMB/s, offset %d",
1448                 speed / 1000,
1449                 speed % 1000,
1450                 data->Sync[id].SyncOffset
1451                 );
1452         }
1453         seq_putc(m, '\n');
1454     }
1455     return 0;
1456 }
1457 
1458 /*---------------------------------------------------------------*/
1459 /* error handler                                                 */
1460 /*---------------------------------------------------------------*/
1461 
1462 /*
1463 static int nsp_eh_abort(struct scsi_cmnd *SCpnt)
1464 {
1465     nsp_dbg(NSP_DEBUG_BUSRESET, "SCpnt=0x%p", SCpnt);
1466 
1467     return nsp_eh_bus_reset(SCpnt);
1468 }*/
1469 
1470 static int nsp_bus_reset(nsp_hw_data *data)
1471 {
1472     unsigned int base = data->BaseAddress;
1473     int      i;
1474 
1475     nsp_write(base, IRQCONTROL, IRQCONTROL_ALLMASK);
1476 
1477     nsp_index_write(base, SCSIBUSCTRL, SCSI_RST);
1478     mdelay(100); /* 100ms */
1479     nsp_index_write(base, SCSIBUSCTRL, 0);
1480     for(i = 0; i < 5; i++) {
1481         nsp_index_read(base, IRQPHASESENCE); /* dummy read */
1482     }
1483 
1484     nsphw_init_sync(data);
1485 
1486     nsp_write(base, IRQCONTROL, IRQCONTROL_ALLCLEAR);
1487 
1488     return SUCCESS;
1489 }
1490 
1491 static int nsp_eh_bus_reset(struct scsi_cmnd *SCpnt)
1492 {
1493     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
1494 
1495     nsp_dbg(NSP_DEBUG_BUSRESET, "SCpnt=0x%p", SCpnt);
1496 
1497     return nsp_bus_reset(data);
1498 }
1499 
1500 static int nsp_eh_host_reset(struct scsi_cmnd *SCpnt)
1501 {
1502     nsp_hw_data *data = (nsp_hw_data *)SCpnt->device->host->hostdata;
1503 
1504     nsp_dbg(NSP_DEBUG_BUSRESET, "in");
1505 
1506     nsphw_init(data);
1507 
1508     return SUCCESS;
1509 }
1510 
1511 
1512 /**********************************************************************
1513   PCMCIA functions
1514 **********************************************************************/
1515 
1516 static int nsp_cs_probe(struct pcmcia_device *link)
1517 {
1518     scsi_info_t  *info;
1519     nsp_hw_data  *data = &nsp_data_base;
1520     int ret;
1521 
1522     nsp_dbg(NSP_DEBUG_INIT, "in");
1523 
1524     /* Create new SCSI device */
1525     info = kzalloc(sizeof(*info), GFP_KERNEL);
1526     if (info == NULL) { return -ENOMEM; }
1527     info->p_dev = link;
1528     link->priv = info;
1529     data->ScsiInfo = info;
1530 
1531     nsp_dbg(NSP_DEBUG_INIT, "info=0x%p", info);
1532 
1533     ret = nsp_cs_config(link);
1534 
1535     nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
1536     return ret;
1537 } /* nsp_cs_attach */
1538 
1539 
1540 static void nsp_cs_detach(struct pcmcia_device *link)
1541 {
1542     nsp_dbg(NSP_DEBUG_INIT, "in, link=0x%p", link);
1543 
1544     ((scsi_info_t *)link->priv)->stop = 1;
1545     nsp_cs_release(link);
1546 
1547     kfree(link->priv);
1548     link->priv = NULL;
1549 } /* nsp_cs_detach */
1550 
1551 
1552 static int nsp_cs_config_check(struct pcmcia_device *p_dev, void *priv_data)
1553 {
1554     nsp_hw_data     *data = priv_data;
1555 
1556     if (p_dev->config_index == 0)
1557         return -ENODEV;
1558 
1559     /* This reserves IO space but doesn't actually enable it */
1560     if (pcmcia_request_io(p_dev) != 0)
1561         goto next_entry;
1562 
1563     if (resource_size(p_dev->resource[2])) {
1564         p_dev->resource[2]->flags |= (WIN_DATA_WIDTH_16 |
1565                     WIN_MEMORY_TYPE_CM |
1566                     WIN_ENABLE);
1567         if (p_dev->resource[2]->end < 0x1000)
1568             p_dev->resource[2]->end = 0x1000;
1569         if (pcmcia_request_window(p_dev, p_dev->resource[2], 0) != 0)
1570             goto next_entry;
1571         if (pcmcia_map_mem_page(p_dev, p_dev->resource[2],
1572                         p_dev->card_addr) != 0)
1573             goto next_entry;
1574 
1575         data->MmioAddress = (unsigned long)
1576             ioremap(p_dev->resource[2]->start,
1577                     resource_size(p_dev->resource[2]));
1578         if (!data->MmioAddress)
1579             goto next_entry;
1580 
1581         data->MmioLength  = resource_size(p_dev->resource[2]);
1582     }
1583     /* If we got this far, we're cool! */
1584     return 0;
1585 
1586 next_entry:
1587     nsp_dbg(NSP_DEBUG_INIT, "next");
1588     pcmcia_disable_device(p_dev);
1589     return -ENODEV;
1590 }
1591 
1592 static int nsp_cs_config(struct pcmcia_device *link)
1593 {
1594     int       ret;
1595     scsi_info_t  *info   = link->priv;
1596     struct Scsi_Host *host;
1597     nsp_hw_data      *data = &nsp_data_base;
1598 
1599     nsp_dbg(NSP_DEBUG_INIT, "in");
1600 
1601     link->config_flags |= CONF_ENABLE_IRQ | CONF_AUTO_CHECK_VCC |
1602         CONF_AUTO_SET_VPP | CONF_AUTO_AUDIO | CONF_AUTO_SET_IOMEM |
1603         CONF_AUTO_SET_IO;
1604 
1605     ret = pcmcia_loop_config(link, nsp_cs_config_check, data);
1606     if (ret)
1607         goto cs_failed;
1608 
1609     if (pcmcia_request_irq(link, nspintr))
1610         goto cs_failed;
1611 
1612     ret = pcmcia_enable_device(link);
1613     if (ret)
1614         goto cs_failed;
1615 
1616     if (free_ports) {
1617         if (link->resource[0]) {
1618             release_region(link->resource[0]->start,
1619                     resource_size(link->resource[0]));
1620         }
1621         if (link->resource[1]) {
1622             release_region(link->resource[1]->start,
1623                     resource_size(link->resource[1]));
1624         }
1625     }
1626 
1627     /* Set port and IRQ */
1628     data->BaseAddress = link->resource[0]->start;
1629     data->NumAddress  = resource_size(link->resource[0]);
1630     data->IrqNumber   = link->irq;
1631 
1632     nsp_dbg(NSP_DEBUG_INIT, "I/O[0x%x+0x%x] IRQ %d",
1633         data->BaseAddress, data->NumAddress, data->IrqNumber);
1634 
1635     nsphw_init(data);
1636 
1637     host = nsp_detect(&nsp_driver_template);
1638 
1639     if (host == NULL) {
1640         nsp_dbg(NSP_DEBUG_INIT, "detect failed");
1641         goto cs_failed;
1642     }
1643 
1644 
1645     ret = scsi_add_host (host, NULL);
1646     if (ret)
1647         goto cs_failed;
1648 
1649     scsi_scan_host(host);
1650 
1651     info->host = host;
1652 
1653     return 0;
1654 
1655  cs_failed:
1656     nsp_dbg(NSP_DEBUG_INIT, "config fail");
1657     nsp_cs_release(link);
1658 
1659     return -ENODEV;
1660 } /* nsp_cs_config */
1661 
1662 
1663 static void nsp_cs_release(struct pcmcia_device *link)
1664 {
1665     scsi_info_t *info = link->priv;
1666     nsp_hw_data *data = NULL;
1667 
1668     if (info->host == NULL) {
1669         nsp_msg(KERN_DEBUG, "unexpected card release call.");
1670     } else {
1671         data = (nsp_hw_data *)info->host->hostdata;
1672     }
1673 
1674     nsp_dbg(NSP_DEBUG_INIT, "link=0x%p", link);
1675 
1676     /* Unlink the device chain */
1677     if (info->host != NULL) {
1678         scsi_remove_host(info->host);
1679     }
1680 
1681     if (resource_size(link->resource[2])) {
1682         if (data != NULL) {
1683             iounmap((void *)(data->MmioAddress));
1684         }
1685     }
1686     pcmcia_disable_device(link);
1687 
1688     if (info->host != NULL) {
1689         scsi_host_put(info->host);
1690     }
1691 } /* nsp_cs_release */
1692 
1693 static int nsp_cs_suspend(struct pcmcia_device *link)
1694 {
1695     scsi_info_t *info = link->priv;
1696     nsp_hw_data *data;
1697 
1698     nsp_dbg(NSP_DEBUG_INIT, "event: suspend");
1699 
1700     if (info->host != NULL) {
1701         nsp_msg(KERN_INFO, "clear SDTR status");
1702 
1703         data = (nsp_hw_data *)info->host->hostdata;
1704 
1705         nsphw_init_sync(data);
1706     }
1707 
1708     info->stop = 1;
1709 
1710     return 0;
1711 }
1712 
1713 static int nsp_cs_resume(struct pcmcia_device *link)
1714 {
1715     scsi_info_t *info = link->priv;
1716     nsp_hw_data *data;
1717 
1718     nsp_dbg(NSP_DEBUG_INIT, "event: resume");
1719 
1720     info->stop = 0;
1721 
1722     if (info->host != NULL) {
1723         nsp_msg(KERN_INFO, "reset host and bus");
1724 
1725         data = (nsp_hw_data *)info->host->hostdata;
1726 
1727         nsphw_init   (data);
1728         nsp_bus_reset(data);
1729     }
1730 
1731     return 0;
1732 }
1733 
1734 /*======================================================================*
1735  *  module entry point
1736  *====================================================================*/
1737 static const struct pcmcia_device_id nsp_cs_ids[] = {
1738     PCMCIA_DEVICE_PROD_ID123("IO DATA", "CBSC16       ", "1", 0x547e66dc, 0x0d63a3fd, 0x51de003a),
1739     PCMCIA_DEVICE_PROD_ID123("KME    ", "SCSI-CARD-001", "1", 0x534c02bc, 0x52008408, 0x51de003a),
1740     PCMCIA_DEVICE_PROD_ID123("KME    ", "SCSI-CARD-002", "1", 0x534c02bc, 0xcb09d5b2, 0x51de003a),
1741     PCMCIA_DEVICE_PROD_ID123("KME    ", "SCSI-CARD-003", "1", 0x534c02bc, 0xbc0ee524, 0x51de003a),
1742     PCMCIA_DEVICE_PROD_ID123("KME    ", "SCSI-CARD-004", "1", 0x534c02bc, 0x226a7087, 0x51de003a),
1743     PCMCIA_DEVICE_PROD_ID123("WBT", "NinjaSCSI-3", "R1.0", 0xc7ba805f, 0xfdc7c97d, 0x6973710e),
1744     PCMCIA_DEVICE_PROD_ID123("WORKBIT", "UltraNinja-16", "1", 0x28191418, 0xb70f4b09, 0x51de003a),
1745     PCMCIA_DEVICE_NULL
1746 };
1747 MODULE_DEVICE_TABLE(pcmcia, nsp_cs_ids);
1748 
1749 static struct pcmcia_driver nsp_driver = {
1750     .owner      = THIS_MODULE,
1751     .name       = "nsp_cs",
1752     .probe      = nsp_cs_probe,
1753     .remove     = nsp_cs_detach,
1754     .id_table   = nsp_cs_ids,
1755     .suspend    = nsp_cs_suspend,
1756     .resume     = nsp_cs_resume,
1757 };
1758 module_pcmcia_driver(nsp_driver);
1759 
1760 /* end */