0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013 #ifndef __nsp_cs__
0014 #define __nsp_cs__
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029 #define NSP_INITIATOR_ID 7
0030
0031 #define NSP_SELTIMEOUT 200
0032
0033
0034
0035
0036
0037
0038
0039 #define IRQCONTROL 0x00
0040 # define IRQCONTROL_RESELECT_CLEAR BIT(0)
0041 # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1)
0042 # define IRQCONTROL_TIMER_CLEAR BIT(2)
0043 # define IRQCONTROL_FIFO_CLEAR BIT(3)
0044 # define IRQCONTROL_ALLMASK 0xff
0045 # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \
0046 IRQCONTROL_PHASE_CHANGE_CLEAR | \
0047 IRQCONTROL_TIMER_CLEAR | \
0048 IRQCONTROL_FIFO_CLEAR )
0049 # define IRQCONTROL_IRQDISABLE 0xf0
0050
0051 #define IRQSTATUS 0x00
0052 # define IRQSTATUS_SCSI BIT(0)
0053 # define IRQSTATUS_TIMER BIT(2)
0054 # define IRQSTATUS_FIFO BIT(3)
0055 # define IRQSTATUS_MASK 0x0f
0056
0057 #define IFSELECT 0x01
0058 # define IF_IFSEL BIT(0)
0059 # define IF_REGSEL BIT(2)
0060
0061 #define FIFOSTATUS 0x01
0062 # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f
0063 # define FIFOSTATUS_CHIP_ID_MASK 0x70
0064 # define FIFOSTATUS_FULL_EMPTY BIT(7)
0065
0066 #define INDEXREG 0x02
0067 #define DATAREG 0x03
0068 #define FIFODATA 0x04
0069 #define FIFODATA1 0x05
0070 #define FIFODATA2 0x06
0071 #define FIFODATA3 0x07
0072
0073
0074
0075
0076 #define EXTBUSCTRL 0x10
0077
0078 #define CLOCKDIV 0x11
0079 # define CLOCK_40M 0x02
0080 # define CLOCK_20M 0x01
0081 # define FAST_20 BIT(2)
0082
0083 #define TERMPWRCTRL 0x13
0084 # define POWER_ON BIT(0)
0085
0086 #define SCSIIRQMODE 0x15
0087 # define SCSI_PHASE_CHANGE_EI BIT(0)
0088 # define RESELECT_EI BIT(4)
0089 # define FIFO_IRQ_EI BIT(5)
0090 # define SCSI_RESET_IRQ_EI BIT(6)
0091
0092 #define IRQPHASESENCE 0x16
0093 # define LATCHED_MSG BIT(0)
0094 # define LATCHED_IO BIT(1)
0095 # define LATCHED_CD BIT(2)
0096 # define LATCHED_BUS_FREE BIT(3)
0097 # define PHASE_CHANGE_IRQ BIT(4)
0098 # define RESELECT_IRQ BIT(5)
0099 # define FIFO_IRQ BIT(6)
0100 # define SCSI_RESET_IRQ BIT(7)
0101
0102 #define TIMERCOUNT 0x17
0103
0104 #define SCSIBUSCTRL 0x18
0105 # define SCSI_SEL BIT(0)
0106 # define SCSI_RST BIT(1)
0107 # define SCSI_DATAOUT_ENB BIT(2)
0108 # define SCSI_ATN BIT(3)
0109 # define SCSI_ACK BIT(4)
0110 # define SCSI_BSY BIT(5)
0111 # define AUTODIRECTION BIT(6)
0112 # define ACKENB BIT(7)
0113
0114 #define SCSIBUSMON 0x19
0115
0116 #define SETARBIT 0x1A
0117 # define ARBIT_GO BIT(0)
0118 # define ARBIT_FLAG_CLEAR BIT(1)
0119
0120 #define ARBITSTATUS 0x1A
0121
0122 # define ARBIT_WIN BIT(1)
0123 # define ARBIT_FAIL BIT(2)
0124 # define RESELECT_FLAG BIT(3)
0125
0126 #define PARITYCTRL 0x1B
0127 #define PARITYSTATUS 0x1B
0128
0129 #define COMMANDCTRL 0x1C
0130 # define CLEAR_COMMAND_POINTER BIT(0)
0131 # define AUTO_COMMAND_GO BIT(1)
0132
0133 #define RESELECTID 0x1C
0134 #define COMMANDDATA 0x1D
0135
0136 #define POINTERCLR 0x1E
0137 # define POINTER_CLEAR BIT(0)
0138 # define ACK_COUNTER_CLEAR BIT(1)
0139 # define REQ_COUNTER_CLEAR BIT(2)
0140 # define HOST_COUNTER_CLEAR BIT(3)
0141 # define READ_SOURCE (BIT(4) | BIT(5))
0142 # define ACK_COUNTER (0)
0143 # define REQ_COUNTER (BIT(4))
0144 # define HOST_COUNTER (BIT(5))
0145
0146 #define TRANSFERCOUNT 0x1E
0147
0148 #define TRANSFERMODE 0x20
0149 # define MODE_MEM8 BIT(0)
0150 # define MODE_MEM32 BIT(1)
0151 # define MODE_ADR24 BIT(2)
0152 # define MODE_ADR32 BIT(3)
0153 # define MODE_IO8 BIT(4)
0154 # define MODE_IO32 BIT(5)
0155 # define TRANSFER_GO BIT(6)
0156 # define BRAIND BIT(7)
0157
0158 #define SYNCREG 0x21
0159 # define SYNCREG_OFFSET_MASK 0x0f
0160 # define SYNCREG_PERIOD_MASK 0xf0
0161 # define SYNCREG_PERIOD_SHIFT 4
0162
0163 #define SCSIDATALATCH 0x22
0164 #define SCSIDATAIN 0x22
0165 #define SCSIDATAWITHACK 0x23
0166 #define SCAMCONTROL 0x24
0167 #define SCAMSTATUS 0x24
0168 #define SCAMDATA 0x25
0169
0170 #define OTHERCONTROL 0x26
0171 # define TPL_ROM_WRITE_EN BIT(0)
0172 # define TPWR_OUT BIT(1)
0173 # define TPWR_SENSE BIT(2)
0174 # define RA8_CONTROL BIT(3)
0175
0176 #define ACKWIDTH 0x27
0177 #define CLRTESTPNT 0x28
0178 #define ACKCNTLD 0x29
0179 #define REQCNTLD 0x2A
0180 #define HSTCNTLD 0x2B
0181 #define CHECKSUM 0x2C
0182
0183
0184
0185
0186 #define S_MESSAGE BIT(0)
0187 #define S_IO BIT(1)
0188 #define S_CD BIT(2)
0189 #define S_BUSY BIT(3)
0190 #define S_ACK BIT(4)
0191 #define S_REQUEST BIT(5)
0192 #define S_SELECT BIT(6)
0193 #define S_ATN BIT(7)
0194
0195
0196
0197
0198 #define BUSMON_SEL S_SELECT
0199 #define BUSMON_BSY S_BUSY
0200 #define BUSMON_REQ S_REQUEST
0201 #define BUSMON_IO S_IO
0202 #define BUSMON_ACK S_ACK
0203 #define BUSMON_BUS_FREE 0
0204 #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST )
0205 #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST )
0206 #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST )
0207 #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST )
0208 #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST )
0209 #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST )
0210 #define BUSMON_SELECT ( S_IO | S_SELECT )
0211 #define BUSMON_RESELECT ( S_IO | S_SELECT )
0212 #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT )
0213
0214 #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK )
0215 #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK )
0216 #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK )
0217 #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK )
0218 #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK )
0219 #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK )
0220 #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK )
0221
0222
0223
0224 typedef struct scsi_info_t {
0225 struct pcmcia_device *p_dev;
0226 struct Scsi_Host *host;
0227 int stop;
0228 } scsi_info_t;
0229
0230
0231
0232 typedef struct _sync_data {
0233 unsigned int SyncNegotiation;
0234 #define SYNC_NOT_YET 0
0235 #define SYNC_OK 1
0236 #define SYNC_NG 2
0237
0238 unsigned int SyncPeriod;
0239 unsigned int SyncOffset;
0240 unsigned char SyncRegister;
0241 unsigned char AckWidth;
0242 } sync_data;
0243
0244 typedef struct _nsp_hw_data {
0245 unsigned int BaseAddress;
0246 unsigned int NumAddress;
0247 unsigned int IrqNumber;
0248
0249 unsigned long MmioAddress;
0250 #define NSP_MMIO_OFFSET 0x0800
0251 unsigned long MmioLength;
0252
0253 unsigned char ScsiClockDiv;
0254
0255 unsigned char TransferMode;
0256
0257 int TimerCount;
0258 int SelectionTimeOut;
0259 struct scsi_cmnd *CurrentSC;
0260
0261
0262 int FifoCount;
0263
0264 #define MSGBUF_SIZE 20
0265 unsigned char MsgBuffer[MSGBUF_SIZE];
0266 int MsgLen;
0267
0268 #define N_TARGET 8
0269 sync_data Sync[N_TARGET];
0270
0271 char nspinfo[110];
0272 spinlock_t Lock;
0273
0274 scsi_info_t *ScsiInfo;
0275
0276
0277 #ifdef NSP_DEBUG
0278 int CmdId;
0279
0280 #endif
0281 } nsp_hw_data;
0282
0283
0284
0285
0286
0287
0288 static void nsp_cs_detach (struct pcmcia_device *p_dev);
0289 static void nsp_cs_release(struct pcmcia_device *link);
0290 static int nsp_cs_config (struct pcmcia_device *link);
0291
0292
0293 static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht);
0294 static const char *nsp_info (struct Scsi_Host *shpnt);
0295 static int nsp_show_info (struct seq_file *m,
0296 struct Scsi_Host *host);
0297 static int nsp_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *SCpnt);
0298
0299
0300
0301
0302 static int nsp_eh_bus_reset (struct scsi_cmnd *SCpnt);
0303 static int nsp_eh_host_reset (struct scsi_cmnd *SCpnt);
0304 static int nsp_bus_reset (nsp_hw_data *data);
0305
0306
0307 static void nsphw_init (nsp_hw_data *data);
0308 static bool nsphw_start_selection(struct scsi_cmnd *SCpnt);
0309 static void nsp_start_timer (struct scsi_cmnd *SCpnt, int time);
0310 static int nsp_fifo_count (struct scsi_cmnd *SCpnt);
0311 static void nsp_pio_read (struct scsi_cmnd *SCpnt);
0312 static void nsp_pio_write (struct scsi_cmnd *SCpnt);
0313 static int nsp_nexus (struct scsi_cmnd *SCpnt);
0314 static void nsp_scsi_done (struct scsi_cmnd *SCpnt);
0315 static int nsp_analyze_sdtr (struct scsi_cmnd *SCpnt);
0316 static int nsp_negate_signal (struct scsi_cmnd *SCpnt,
0317 unsigned char mask, char *str);
0318 static int nsp_expect_signal (struct scsi_cmnd *SCpnt,
0319 unsigned char current_phase,
0320 unsigned char mask);
0321 static int nsp_xfer (struct scsi_cmnd *SCpnt, int phase);
0322 static int nsp_dataphase_bypass (struct scsi_cmnd *SCpnt);
0323 static void nsp_reselected (struct scsi_cmnd *SCpnt);
0324 static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht);
0325
0326
0327
0328
0329
0330 #ifdef NSP_DEBUG
0331 static void show_command (struct scsi_cmnd *SCpnt);
0332 static void show_phase (struct scsi_cmnd *SCpnt);
0333 static void show_busphase(unsigned char stat);
0334 static void show_message (nsp_hw_data *data);
0335 #else
0336 # define show_command(ptr)
0337 # define show_phase(SCpnt)
0338 # define show_busphase(stat)
0339 # define show_message(data)
0340 #endif
0341
0342
0343
0344
0345 enum _scsi_phase {
0346 PH_UNDETERMINED ,
0347 PH_ARBSTART ,
0348 PH_SELSTART ,
0349 PH_SELECTED ,
0350 PH_COMMAND ,
0351 PH_DATA ,
0352 PH_STATUS ,
0353 PH_MSG_IN ,
0354 PH_MSG_OUT ,
0355 PH_DISCONNECT ,
0356 PH_RESELECT ,
0357 PH_ABORT ,
0358 PH_RESET
0359 };
0360
0361 enum _data_in_out {
0362 IO_UNKNOWN,
0363 IO_IN,
0364 IO_OUT
0365 };
0366
0367 enum _burst_mode {
0368 BURST_IO8 = 0,
0369 BURST_IO32 = 1,
0370 BURST_MEM32 = 2,
0371 };
0372
0373
0374 #define BUFFER_ADDR(SCpnt) ((char *)(sg_virt(nsp_priv(SCpnt)->buffer)))
0375
0376 #endif
0377