1 /*=======================================================/
2 Header file for nsp_cs.c
3 By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp>
5 Ver.1.0 : Cut unused lines.
6 Ver 0.1 : Initial version.
8 This software may be used and distributed according to the terms of
9 the GNU General Public License.
11 =========================================================*/
24 /************************************
25 * Some useful macros...
27 #define BIT(x) (1L << (x))
29 /* SCSI initiator must be ID 7 */
30 #define NSP_INITIATOR_ID 7
32 #define NSP_SELTIMEOUT 200
34 /***************************************************************************
35 * register definitions
36 ***************************************************************************/
37 /*========================================================================
39 ========================================================================*/
40 #define IRQCONTROL 0x00 /* R */
41 # define IRQCONTROL_RESELECT_CLEAR BIT(0)
42 # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1)
43 # define IRQCONTROL_TIMER_CLEAR BIT(2)
44 # define IRQCONTROL_FIFO_CLEAR BIT(3)
45 # define IRQCONTROL_ALLMASK 0xff
46 # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \
47 IRQCONTROL_PHASE_CHANGE_CLEAR | \
48 IRQCONTROL_TIMER_CLEAR | \
49 IRQCONTROL_FIFO_CLEAR )
50 # define IRQCONTROL_IRQDISABLE 0xf0
52 #define IRQSTATUS 0x00 /* W */
53 # define IRQSTATUS_SCSI BIT(0)
54 # define IRQSTATUS_TIMER BIT(2)
55 # define IRQSTATUS_FIFO BIT(3)
56 # define IRQSTATUS_MASK 0x0f
58 #define IFSELECT 0x01 /* W */
59 # define IF_IFSEL BIT(0)
60 # define IF_REGSEL BIT(2)
62 #define FIFOSTATUS 0x01 /* R */
63 # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f
64 # define FIFOSTATUS_CHIP_ID_MASK 0x70
65 # define FIFOSTATUS_FULL_EMPTY BIT(7)
67 #define INDEXREG 0x02 /* R/W */
68 #define DATAREG 0x03 /* R/W */
69 #define FIFODATA 0x04 /* R/W */
70 #define FIFODATA1 0x05 /* R/W */
71 #define FIFODATA2 0x06 /* R/W */
72 #define FIFODATA3 0x07 /* R/W */
74 /*====================================================================
76 ====================================================================*/
77 #define EXTBUSCTRL 0x10 /* R/W,deleted */
79 #define CLOCKDIV 0x11 /* R/W */
80 # define CLOCK_40M 0x02
81 # define CLOCK_20M 0x01
82 # define FAST_20 BIT(2)
84 #define TERMPWRCTRL 0x13 /* R/W */
85 # define POWER_ON BIT(0)
87 #define SCSIIRQMODE 0x15 /* R/W */
88 # define SCSI_PHASE_CHANGE_EI BIT(0)
89 # define RESELECT_EI BIT(4)
90 # define FIFO_IRQ_EI BIT(5)
91 # define SCSI_RESET_IRQ_EI BIT(6)
93 #define IRQPHASESENCE 0x16 /* R */
94 # define LATCHED_MSG BIT(0)
95 # define LATCHED_IO BIT(1)
96 # define LATCHED_CD BIT(2)
97 # define LATCHED_BUS_FREE BIT(3)
98 # define PHASE_CHANGE_IRQ BIT(4)
99 # define RESELECT_IRQ BIT(5)
100 # define FIFO_IRQ BIT(6)
101 # define SCSI_RESET_IRQ BIT(7)
103 #define TIMERCOUNT 0x17 /* R/W */
105 #define SCSIBUSCTRL 0x18 /* R/W */
106 # define SCSI_SEL BIT(0)
107 # define SCSI_RST BIT(1)
108 # define SCSI_DATAOUT_ENB BIT(2)
109 # define SCSI_ATN BIT(3)
110 # define SCSI_ACK BIT(4)
111 # define SCSI_BSY BIT(5)
112 # define AUTODIRECTION BIT(6)
113 # define ACKENB BIT(7)
115 #define SCSIBUSMON 0x19 /* R */
117 #define SETARBIT 0x1A /* W */
118 # define ARBIT_GO BIT(0)
119 # define ARBIT_FLAG_CLEAR BIT(1)
121 #define ARBITSTATUS 0x1A /* R */
122 /*# define ARBIT_GO BIT(0)*/
123 # define ARBIT_WIN BIT(1)
124 # define ARBIT_FAIL BIT(2)
125 # define RESELECT_FLAG BIT(3)
127 #define PARITYCTRL 0x1B /* W */
128 #define PARITYSTATUS 0x1B /* R */
130 #define COMMANDCTRL 0x1C /* W */
131 # define CLEAR_COMMAND_POINTER BIT(0)
132 # define AUTO_COMMAND_GO BIT(1)
134 #define RESELECTID 0x1C /* R */
135 #define COMMANDDATA 0x1D /* R/W */
137 #define POINTERCLR 0x1E /* W */
138 # define POINTER_CLEAR BIT(0)
139 # define ACK_COUNTER_CLEAR BIT(1)
140 # define REQ_COUNTER_CLEAR BIT(2)
141 # define HOST_COUNTER_CLEAR BIT(3)
142 # define READ_SOURCE (BIT(4) | BIT(5))
143 # define ACK_COUNTER (0)
144 # define REQ_COUNTER (BIT(4))
145 # define HOST_COUNTER (BIT(5))
147 #define TRANSFERCOUNT 0x1E /* R */
149 #define TRANSFERMODE 0x20 /* R/W */
150 # define MODE_MEM8 BIT(0)
151 # define MODE_MEM32 BIT(1)
152 # define MODE_ADR24 BIT(2)
153 # define MODE_ADR32 BIT(3)
154 # define MODE_IO8 BIT(4)
155 # define MODE_IO32 BIT(5)
156 # define TRANSFER_GO BIT(6)
157 # define BRAIND BIT(7)
159 #define SYNCREG 0x21 /* R/W */
160 # define SYNCREG_OFFSET_MASK 0x0f
161 # define SYNCREG_PERIOD_MASK 0xf0
162 # define SYNCREG_PERIOD_SHIFT 4
164 #define SCSIDATALATCH 0x22 /* W */
165 #define SCSIDATAIN 0x22 /* R */
166 #define SCSIDATAWITHACK 0x23 /* R/W */
167 #define SCAMCONTROL 0x24 /* W */
168 #define SCAMSTATUS 0x24 /* R */
169 #define SCAMDATA 0x25 /* R/W */
171 #define OTHERCONTROL 0x26 /* R/W */
172 # define TPL_ROM_WRITE_EN BIT(0)
173 # define TPWR_OUT BIT(1)
174 # define TPWR_SENSE BIT(2)
175 # define RA8_CONTROL BIT(3)
177 #define ACKWIDTH 0x27 /* R/W */
178 #define CLRTESTPNT 0x28 /* W */
179 #define ACKCNTLD 0x29 /* W */
180 #define REQCNTLD 0x2A /* W */
181 #define HSTCNTLD 0x2B /* W */
182 #define CHECKSUM 0x2C /* R/W */
184 /************************************************************************
185 * Input status bit definitions.
186 ************************************************************************/
187 #define S_MESSAGE BIT(0) /* Message line from SCSI bus */
188 #define S_IO BIT(1) /* Input/Output line from SCSI bus */
189 #define S_CD BIT(2) /* Command/Data line from SCSI bus */
190 #define S_BUSY BIT(3) /* Busy line from SCSI bus */
191 #define S_ACK BIT(4) /* Acknowlege line from SCSI bus */
192 #define S_REQUEST BIT(5) /* Request line from SCSI bus */
193 #define S_SELECT BIT(6) /* */
194 #define S_ATN BIT(7) /* */
196 /***********************************************************************
197 * Useful Bus Monitor status combinations.
198 ***********************************************************************/
199 #define BUSMON_SEL S_SELECT
200 #define BUSMON_BSY S_BUSY
201 #define BUSMON_REQ S_REQUEST
202 #define BUSMON_IO S_IO
203 #define BUSMON_ACK S_ACK
204 #define BUSMON_BUS_FREE 0
205 #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST )
206 #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST )
207 #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST )
208 #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST )
209 #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST )
210 #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST )
211 #define BUSMON_SELECT ( S_IO | S_SELECT )
212 #define BUSMON_RESELECT ( S_IO | S_SELECT )
213 #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT )
215 #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK )
216 #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK )
217 #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK )
218 #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK )
219 #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK )
220 #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK )
221 #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK )
223 /*====================================================================*/
225 typedef struct scsi_info_t
{
226 struct pcmcia_device
*p_dev
;
227 struct Scsi_Host
*host
;
233 /* synchronous transfer negotiation data */
234 typedef struct _sync_data
{
235 unsigned int SyncNegotiation
;
236 #define SYNC_NOT_YET 0
240 unsigned int SyncPeriod
;
241 unsigned int SyncOffset
;
242 unsigned char SyncRegister
;
243 unsigned char AckWidth
;
246 typedef struct _nsp_hw_data
{
247 unsigned int BaseAddress
;
248 unsigned int NumAddress
;
249 unsigned int IrqNumber
;
251 unsigned long MmioAddress
;
252 #define NSP_MMIO_OFFSET 0x0800
253 unsigned long MmioLength
;
255 unsigned char ScsiClockDiv
;
257 unsigned char TransferMode
;
260 int SelectionTimeOut
;
261 struct scsi_cmnd
*CurrentSC
;
266 #define MSGBUF_SIZE 20
267 unsigned char MsgBuffer
[MSGBUF_SIZE
];
271 sync_data Sync
[N_TARGET
];
273 char nspinfo
[110]; /* description */
276 scsi_info_t
*ScsiInfo
; /* attach <-> detect glue */
280 int CmdId
; /* Accepted command serial number.
281 Used for debugging. */
285 /****************************************************************************
289 /* Card service functions */
290 static void nsp_cs_detach (struct pcmcia_device
*p_dev
);
291 static void nsp_cs_release(struct pcmcia_device
*link
);
292 static int nsp_cs_config (struct pcmcia_device
*link
);
294 /* Linux SCSI subsystem specific functions */
295 static struct Scsi_Host
*nsp_detect (struct scsi_host_template
*sht
);
296 static const char *nsp_info (struct Scsi_Host
*shpnt
);
297 static int nsp_proc_info (
298 struct Scsi_Host
*host
,
304 static int nsp_queuecommand(struct scsi_cmnd
*SCpnt
,
305 void (* done
)(struct scsi_cmnd
*SCpnt
));
308 /*static int nsp_eh_abort (struct scsi_cmnd *SCpnt);*/
309 /*static int nsp_eh_device_reset(struct scsi_cmnd *SCpnt);*/
310 static int nsp_eh_bus_reset (struct scsi_cmnd
*SCpnt
);
311 static int nsp_eh_host_reset (struct scsi_cmnd
*SCpnt
);
312 static int nsp_bus_reset (nsp_hw_data
*data
);
315 static int nsphw_init (nsp_hw_data
*data
);
316 static int nsphw_start_selection(struct scsi_cmnd
*SCpnt
);
317 static void nsp_start_timer (struct scsi_cmnd
*SCpnt
, int time
);
318 static int nsp_fifo_count (struct scsi_cmnd
*SCpnt
);
319 static void nsp_pio_read (struct scsi_cmnd
*SCpnt
);
320 static void nsp_pio_write (struct scsi_cmnd
*SCpnt
);
321 static int nsp_nexus (struct scsi_cmnd
*SCpnt
);
322 static void nsp_scsi_done (struct scsi_cmnd
*SCpnt
);
323 static int nsp_analyze_sdtr (struct scsi_cmnd
*SCpnt
);
324 static int nsp_negate_signal (struct scsi_cmnd
*SCpnt
,
325 unsigned char mask
, char *str
);
326 static int nsp_expect_signal (struct scsi_cmnd
*SCpnt
,
327 unsigned char current_phase
,
329 static int nsp_xfer (struct scsi_cmnd
*SCpnt
, int phase
);
330 static int nsp_dataphase_bypass (struct scsi_cmnd
*SCpnt
);
331 static int nsp_reselected (struct scsi_cmnd
*SCpnt
);
332 static struct Scsi_Host
*nsp_detect(struct scsi_host_template
*sht
);
334 /* Interrupt handler */
335 //static irqreturn_t nspintr(int irq, void *dev_id);
337 /* Module entry point*/
338 static int __init
nsp_cs_init(void);
339 static void __exit
nsp_cs_exit(void);
343 static void show_command (struct scsi_cmnd
*SCpnt
);
344 static void show_phase (struct scsi_cmnd
*SCpnt
);
345 static void show_busphase(unsigned char stat
);
346 static void show_message (nsp_hw_data
*data
);
348 # define show_command(ptr) /* */
349 # define show_phase(SCpnt) /* */
350 # define show_busphase(stat) /* */
351 # define show_message(data) /* */
385 /**************************************************************************
388 #define MSG_COMMAND_COMPLETE 0x00
389 #define MSG_EXTENDED 0x01
390 #define MSG_ABORT 0x06
391 #define MSG_NO_OPERATION 0x08
392 #define MSG_BUS_DEVICE_RESET 0x0c
394 #define MSG_EXT_SDTR 0x01
396 /* scatter-gather table */
397 # define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset))
399 #endif /*__nsp_cs__*/