]>
Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /*=======================================================/ |
2 | Header file for nsp_cs.c | |
3 | By: YOKOTA Hiroshi <yokota@netlab.is.tsukuba.ac.jp> | |
4 | ||
5 | Ver.1.0 : Cut unused lines. | |
6 | Ver 0.1 : Initial version. | |
7 | ||
8 | This software may be used and distributed according to the terms of | |
9 | the GNU General Public License. | |
10 | ||
11 | =========================================================*/ | |
12 | ||
13 | /* $Id: nsp_cs.h,v 1.19 2003/08/18 11:09:19 elca Exp $ */ | |
14 | ||
15 | #ifndef __nsp_cs__ | |
16 | #define __nsp_cs__ | |
17 | ||
18 | /* for debugging */ | |
19 | //#define NSP_DEBUG 9 | |
20 | ||
21 | /* | |
22 | #define static | |
23 | #define inline | |
24 | */ | |
25 | ||
26 | /************************************ | |
27 | * Some useful macros... | |
28 | */ | |
29 | #define BIT(x) (1L << (x)) | |
30 | ||
31 | /* SCSI initiator must be ID 7 */ | |
32 | #define NSP_INITIATOR_ID 7 | |
33 | ||
34 | #define NSP_SELTIMEOUT 200 | |
35 | ||
36 | /*************************************************************************** | |
37 | * register definitions | |
38 | ***************************************************************************/ | |
39 | /*======================================================================== | |
40 | * base register | |
41 | ========================================================================*/ | |
42 | #define IRQCONTROL 0x00 /* R */ | |
43 | # define IRQCONTROL_RESELECT_CLEAR BIT(0) | |
44 | # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1) | |
45 | # define IRQCONTROL_TIMER_CLEAR BIT(2) | |
46 | # define IRQCONTROL_FIFO_CLEAR BIT(3) | |
47 | # define IRQCONTROL_ALLMASK 0xff | |
48 | # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \ | |
49 | IRQCONTROL_PHASE_CHANGE_CLEAR | \ | |
50 | IRQCONTROL_TIMER_CLEAR | \ | |
51 | IRQCONTROL_FIFO_CLEAR ) | |
52 | # define IRQCONTROL_IRQDISABLE 0xf0 | |
53 | ||
54 | #define IRQSTATUS 0x00 /* W */ | |
55 | # define IRQSTATUS_SCSI BIT(0) | |
56 | # define IRQSTATUS_TIMER BIT(2) | |
57 | # define IRQSTATUS_FIFO BIT(3) | |
58 | # define IRQSTATUS_MASK 0x0f | |
59 | ||
60 | #define IFSELECT 0x01 /* W */ | |
61 | # define IF_IFSEL BIT(0) | |
62 | # define IF_REGSEL BIT(2) | |
63 | ||
64 | #define FIFOSTATUS 0x01 /* R */ | |
65 | # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f | |
66 | # define FIFOSTATUS_CHIP_ID_MASK 0x70 | |
67 | # define FIFOSTATUS_FULL_EMPTY BIT(7) | |
68 | ||
69 | #define INDEXREG 0x02 /* R/W */ | |
70 | #define DATAREG 0x03 /* R/W */ | |
71 | #define FIFODATA 0x04 /* R/W */ | |
72 | #define FIFODATA1 0x05 /* R/W */ | |
73 | #define FIFODATA2 0x06 /* R/W */ | |
74 | #define FIFODATA3 0x07 /* R/W */ | |
75 | ||
76 | /*==================================================================== | |
77 | * indexed register | |
78 | ====================================================================*/ | |
79 | #define EXTBUSCTRL 0x10 /* R/W,deleted */ | |
80 | ||
81 | #define CLOCKDIV 0x11 /* R/W */ | |
82 | # define CLOCK_40M 0x02 | |
83 | # define CLOCK_20M 0x01 | |
84 | # define FAST_20 BIT(2) | |
85 | ||
86 | #define TERMPWRCTRL 0x13 /* R/W */ | |
87 | # define POWER_ON BIT(0) | |
88 | ||
89 | #define SCSIIRQMODE 0x15 /* R/W */ | |
90 | # define SCSI_PHASE_CHANGE_EI BIT(0) | |
91 | # define RESELECT_EI BIT(4) | |
92 | # define FIFO_IRQ_EI BIT(5) | |
93 | # define SCSI_RESET_IRQ_EI BIT(6) | |
94 | ||
95 | #define IRQPHASESENCE 0x16 /* R */ | |
96 | # define LATCHED_MSG BIT(0) | |
97 | # define LATCHED_IO BIT(1) | |
98 | # define LATCHED_CD BIT(2) | |
99 | # define LATCHED_BUS_FREE BIT(3) | |
100 | # define PHASE_CHANGE_IRQ BIT(4) | |
101 | # define RESELECT_IRQ BIT(5) | |
102 | # define FIFO_IRQ BIT(6) | |
103 | # define SCSI_RESET_IRQ BIT(7) | |
104 | ||
105 | #define TIMERCOUNT 0x17 /* R/W */ | |
106 | ||
107 | #define SCSIBUSCTRL 0x18 /* R/W */ | |
108 | # define SCSI_SEL BIT(0) | |
109 | # define SCSI_RST BIT(1) | |
110 | # define SCSI_DATAOUT_ENB BIT(2) | |
111 | # define SCSI_ATN BIT(3) | |
112 | # define SCSI_ACK BIT(4) | |
113 | # define SCSI_BSY BIT(5) | |
114 | # define AUTODIRECTION BIT(6) | |
115 | # define ACKENB BIT(7) | |
116 | ||
117 | #define SCSIBUSMON 0x19 /* R */ | |
118 | ||
119 | #define SETARBIT 0x1A /* W */ | |
120 | # define ARBIT_GO BIT(0) | |
121 | # define ARBIT_FLAG_CLEAR BIT(1) | |
122 | ||
123 | #define ARBITSTATUS 0x1A /* R */ | |
124 | /*# define ARBIT_GO BIT(0)*/ | |
125 | # define ARBIT_WIN BIT(1) | |
126 | # define ARBIT_FAIL BIT(2) | |
127 | # define RESELECT_FLAG BIT(3) | |
128 | ||
129 | #define PARITYCTRL 0x1B /* W */ | |
130 | #define PARITYSTATUS 0x1B /* R */ | |
131 | ||
132 | #define COMMANDCTRL 0x1C /* W */ | |
133 | # define CLEAR_COMMAND_POINTER BIT(0) | |
134 | # define AUTO_COMMAND_GO BIT(1) | |
135 | ||
136 | #define RESELECTID 0x1C /* R */ | |
137 | #define COMMANDDATA 0x1D /* R/W */ | |
138 | ||
139 | #define POINTERCLR 0x1E /* W */ | |
140 | # define POINTER_CLEAR BIT(0) | |
141 | # define ACK_COUNTER_CLEAR BIT(1) | |
142 | # define REQ_COUNTER_CLEAR BIT(2) | |
143 | # define HOST_COUNTER_CLEAR BIT(3) | |
144 | # define READ_SOURCE (BIT(4) | BIT(5)) | |
145 | # define ACK_COUNTER (0) | |
146 | # define REQ_COUNTER (BIT(4)) | |
147 | # define HOST_COUNTER (BIT(5)) | |
148 | ||
149 | #define TRANSFERCOUNT 0x1E /* R */ | |
150 | ||
151 | #define TRANSFERMODE 0x20 /* R/W */ | |
152 | # define MODE_MEM8 BIT(0) | |
153 | # define MODE_MEM32 BIT(1) | |
154 | # define MODE_ADR24 BIT(2) | |
155 | # define MODE_ADR32 BIT(3) | |
156 | # define MODE_IO8 BIT(4) | |
157 | # define MODE_IO32 BIT(5) | |
158 | # define TRANSFER_GO BIT(6) | |
159 | # define BRAIND BIT(7) | |
160 | ||
161 | #define SYNCREG 0x21 /* R/W */ | |
162 | # define SYNCREG_OFFSET_MASK 0x0f | |
163 | # define SYNCREG_PERIOD_MASK 0xf0 | |
164 | # define SYNCREG_PERIOD_SHIFT 4 | |
165 | ||
166 | #define SCSIDATALATCH 0x22 /* W */ | |
167 | #define SCSIDATAIN 0x22 /* R */ | |
168 | #define SCSIDATAWITHACK 0x23 /* R/W */ | |
169 | #define SCAMCONTROL 0x24 /* W */ | |
170 | #define SCAMSTATUS 0x24 /* R */ | |
171 | #define SCAMDATA 0x25 /* R/W */ | |
172 | ||
173 | #define OTHERCONTROL 0x26 /* R/W */ | |
174 | # define TPL_ROM_WRITE_EN BIT(0) | |
175 | # define TPWR_OUT BIT(1) | |
176 | # define TPWR_SENSE BIT(2) | |
177 | # define RA8_CONTROL BIT(3) | |
178 | ||
179 | #define ACKWIDTH 0x27 /* R/W */ | |
180 | #define CLRTESTPNT 0x28 /* W */ | |
181 | #define ACKCNTLD 0x29 /* W */ | |
182 | #define REQCNTLD 0x2A /* W */ | |
183 | #define HSTCNTLD 0x2B /* W */ | |
184 | #define CHECKSUM 0x2C /* R/W */ | |
185 | ||
186 | /************************************************************************ | |
187 | * Input status bit definitions. | |
188 | ************************************************************************/ | |
189 | #define S_MESSAGE BIT(0) /* Message line from SCSI bus */ | |
190 | #define S_IO BIT(1) /* Input/Output line from SCSI bus */ | |
191 | #define S_CD BIT(2) /* Command/Data line from SCSI bus */ | |
192 | #define S_BUSY BIT(3) /* Busy line from SCSI bus */ | |
193 | #define S_ACK BIT(4) /* Acknowlege line from SCSI bus */ | |
194 | #define S_REQUEST BIT(5) /* Request line from SCSI bus */ | |
195 | #define S_SELECT BIT(6) /* */ | |
196 | #define S_ATN BIT(7) /* */ | |
197 | ||
198 | /*********************************************************************** | |
199 | * Useful Bus Monitor status combinations. | |
200 | ***********************************************************************/ | |
201 | #define BUSMON_SEL S_SELECT | |
202 | #define BUSMON_BSY S_BUSY | |
203 | #define BUSMON_REQ S_REQUEST | |
204 | #define BUSMON_IO S_IO | |
205 | #define BUSMON_ACK S_ACK | |
206 | #define BUSMON_BUS_FREE 0 | |
207 | #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST ) | |
208 | #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST ) | |
209 | #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST ) | |
210 | #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST ) | |
211 | #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST ) | |
212 | #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST ) | |
213 | #define BUSMON_SELECT ( S_IO | S_SELECT ) | |
214 | #define BUSMON_RESELECT ( S_IO | S_SELECT ) | |
215 | #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT ) | |
216 | ||
217 | #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK ) | |
218 | #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK ) | |
219 | #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK ) | |
220 | #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK ) | |
221 | #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK ) | |
222 | #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK ) | |
223 | #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK ) | |
224 | ||
225 | /*====================================================================*/ | |
226 | ||
227 | typedef struct scsi_info_t { | |
fd238232 | 228 | struct pcmcia_device *p_dev; |
1da177e4 LT |
229 | struct Scsi_Host *host; |
230 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74)) | |
231 | dev_node_t node; | |
232 | #else | |
233 | int ndev; | |
234 | dev_node_t node[8]; | |
235 | struct bus_operations *bus; | |
236 | #endif | |
237 | int stop; | |
238 | } scsi_info_t; | |
239 | ||
240 | ||
241 | /* synchronous transfer negotiation data */ | |
242 | typedef struct _sync_data { | |
243 | unsigned int SyncNegotiation; | |
244 | #define SYNC_NOT_YET 0 | |
245 | #define SYNC_OK 1 | |
246 | #define SYNC_NG 2 | |
247 | ||
248 | unsigned int SyncPeriod; | |
249 | unsigned int SyncOffset; | |
250 | unsigned char SyncRegister; | |
251 | unsigned char AckWidth; | |
252 | } sync_data; | |
253 | ||
254 | typedef struct _nsp_hw_data { | |
255 | unsigned int BaseAddress; | |
256 | unsigned int NumAddress; | |
257 | unsigned int IrqNumber; | |
258 | ||
259 | unsigned long MmioAddress; | |
260 | #define NSP_MMIO_OFFSET 0x0800 | |
261 | unsigned long MmioLength; | |
262 | ||
263 | unsigned char ScsiClockDiv; | |
264 | ||
265 | unsigned char TransferMode; | |
266 | ||
267 | int TimerCount; | |
268 | int SelectionTimeOut; | |
269 | Scsi_Cmnd *CurrentSC; | |
270 | //int CurrnetTarget; | |
271 | ||
272 | int FifoCount; | |
273 | ||
274 | #define MSGBUF_SIZE 20 | |
275 | unsigned char MsgBuffer[MSGBUF_SIZE]; | |
276 | int MsgLen; | |
277 | ||
278 | #define N_TARGET 8 | |
279 | sync_data Sync[N_TARGET]; | |
280 | ||
281 | char nspinfo[110]; /* description */ | |
282 | spinlock_t Lock; | |
283 | ||
284 | scsi_info_t *ScsiInfo; /* attach <-> detect glue */ | |
285 | ||
286 | ||
287 | #ifdef NSP_DEBUG | |
288 | int CmdId; /* Accepted command serial number. | |
289 | Used for debugging. */ | |
290 | #endif | |
291 | } nsp_hw_data; | |
292 | ||
293 | ||
294 | /**************************************************************************** | |
295 | * | |
296 | */ | |
297 | ||
298 | /* Card service functions */ | |
cc3b4866 | 299 | static void nsp_cs_detach (struct pcmcia_device *p_dev); |
fba395ee | 300 | static void nsp_cs_release(struct pcmcia_device *link); |
15b99ac1 | 301 | static int nsp_cs_config (struct pcmcia_device *link); |
1da177e4 LT |
302 | |
303 | /* Linux SCSI subsystem specific functions */ | |
d0be4a7d | 304 | static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); |
1da177e4 | 305 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)) |
d0be4a7d | 306 | static int nsp_detect_old (struct scsi_host_template *sht); |
1da177e4 LT |
307 | static int nsp_release_old(struct Scsi_Host *shpnt); |
308 | #endif | |
309 | static const char *nsp_info (struct Scsi_Host *shpnt); | |
310 | static int nsp_proc_info ( | |
311 | #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73)) | |
312 | struct Scsi_Host *host, | |
313 | #endif | |
314 | char *buffer, | |
315 | char **start, | |
316 | off_t offset, | |
317 | int length, | |
318 | #if !(LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73)) | |
319 | int hostno, | |
320 | #endif | |
321 | int inout); | |
322 | static int nsp_queuecommand(Scsi_Cmnd *SCpnt, void (* done)(Scsi_Cmnd *SCpnt)); | |
323 | ||
324 | /* Error handler */ | |
325 | /*static int nsp_eh_abort (Scsi_Cmnd *SCpnt);*/ | |
326 | /*static int nsp_eh_device_reset(Scsi_Cmnd *SCpnt);*/ | |
327 | static int nsp_eh_bus_reset (Scsi_Cmnd *SCpnt); | |
328 | static int nsp_eh_host_reset (Scsi_Cmnd *SCpnt); | |
329 | static int nsp_bus_reset (nsp_hw_data *data); | |
330 | ||
331 | /* */ | |
332 | static int nsphw_init (nsp_hw_data *data); | |
333 | static int nsphw_start_selection(Scsi_Cmnd *SCpnt); | |
334 | static void nsp_start_timer (Scsi_Cmnd *SCpnt, int time); | |
335 | static int nsp_fifo_count (Scsi_Cmnd *SCpnt); | |
336 | static void nsp_pio_read (Scsi_Cmnd *SCpnt); | |
337 | static void nsp_pio_write (Scsi_Cmnd *SCpnt); | |
338 | static int nsp_nexus (Scsi_Cmnd *SCpnt); | |
339 | static void nsp_scsi_done (Scsi_Cmnd *SCpnt); | |
340 | static int nsp_analyze_sdtr (Scsi_Cmnd *SCpnt); | |
341 | static int nsp_negate_signal (Scsi_Cmnd *SCpnt, unsigned char mask, char *str); | |
342 | static int nsp_expect_signal (Scsi_Cmnd *SCpnt, unsigned char current_phase, unsigned char mask); | |
343 | static int nsp_xfer (Scsi_Cmnd *SCpnt, int phase); | |
344 | static int nsp_dataphase_bypass (Scsi_Cmnd *SCpnt); | |
345 | static int nsp_reselected (Scsi_Cmnd *SCpnt); | |
d0be4a7d | 346 | static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht); |
1da177e4 LT |
347 | |
348 | /* Interrupt handler */ | |
349 | //static irqreturn_t nspintr(int irq, void *dev_id, struct pt_regs *regs); | |
350 | ||
351 | /* Module entry point*/ | |
352 | static int __init nsp_cs_init(void); | |
353 | static void __exit nsp_cs_exit(void); | |
354 | ||
355 | ||
356 | /* Debug */ | |
357 | #ifdef NSP_DEBUG | |
358 | static void show_command (Scsi_Cmnd *SCpnt); | |
359 | static void show_phase (Scsi_Cmnd *SCpnt); | |
360 | static void show_busphase(unsigned char stat); | |
361 | static void show_message (nsp_hw_data *data); | |
362 | #else | |
363 | # define show_command(ptr) /* */ | |
364 | # define show_phase(SCpnt) /* */ | |
365 | # define show_busphase(stat) /* */ | |
366 | # define show_message(data) /* */ | |
367 | #endif | |
368 | ||
369 | /* | |
370 | * SCSI phase | |
371 | */ | |
372 | enum _scsi_phase { | |
373 | PH_UNDETERMINED , | |
374 | PH_ARBSTART , | |
375 | PH_SELSTART , | |
376 | PH_SELECTED , | |
377 | PH_COMMAND , | |
378 | PH_DATA , | |
379 | PH_STATUS , | |
380 | PH_MSG_IN , | |
381 | PH_MSG_OUT , | |
382 | PH_DISCONNECT , | |
383 | PH_RESELECT , | |
384 | PH_ABORT , | |
385 | PH_RESET | |
386 | }; | |
387 | ||
388 | enum _data_in_out { | |
389 | IO_UNKNOWN, | |
390 | IO_IN, | |
391 | IO_OUT | |
392 | }; | |
393 | ||
394 | enum _burst_mode { | |
395 | BURST_IO8 = 0, | |
396 | BURST_IO32 = 1, | |
397 | BURST_MEM32 = 2, | |
398 | }; | |
399 | ||
400 | ||
401 | /************************************************************************** | |
402 | * SCSI messaage | |
403 | */ | |
404 | #define MSG_COMMAND_COMPLETE 0x00 | |
405 | #define MSG_EXTENDED 0x01 | |
406 | #define MSG_ABORT 0x06 | |
407 | #define MSG_NO_OPERATION 0x08 | |
408 | #define MSG_BUS_DEVICE_RESET 0x0c | |
409 | ||
410 | #define MSG_EXT_SDTR 0x01 | |
411 | ||
412 | ||
413 | /************************************************************************** | |
414 | * Compatibility functions | |
415 | */ | |
416 | ||
417 | /* for Kernel 2.4 */ | |
418 | #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0)) | |
419 | # define scsi_register_host(template) scsi_register_module(MODULE_SCSI_HA, template) | |
420 | # define scsi_unregister_host(template) scsi_unregister_module(MODULE_SCSI_HA, template) | |
421 | # define scsi_host_put(host) scsi_unregister(host) | |
422 | ||
423 | typedef void irqreturn_t; | |
424 | # define IRQ_NONE /* */ | |
425 | # define IRQ_HANDLED /* */ | |
426 | # define IRQ_RETVAL(x) /* */ | |
427 | ||
428 | /* This is ad-hoc version of scsi_host_get_next() */ | |
429 | static inline struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *host) | |
430 | { | |
431 | if (host == NULL) { | |
432 | return scsi_hostlist; | |
433 | } else { | |
434 | return host->next; | |
435 | } | |
436 | } | |
437 | ||
438 | /* This is ad-hoc version of scsi_host_hn_get() */ | |
439 | static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno) | |
440 | { | |
441 | struct Scsi_Host *host; | |
442 | ||
443 | for (host = scsi_host_get_next(NULL); host != NULL; | |
444 | host = scsi_host_get_next(host)) { | |
445 | if (host->host_no == hostno) { | |
446 | break; | |
447 | } | |
448 | } | |
449 | ||
450 | return host; | |
451 | } | |
452 | ||
fba395ee | 453 | static void cs_error(struct pcmcia_device *handle, int func, int ret) |
1da177e4 LT |
454 | { |
455 | error_info_t err = { func, ret }; | |
456 | pcmcia_report_error(handle, &err); | |
457 | } | |
458 | ||
459 | /* scatter-gather table */ | |
460 | # define BUFFER_ADDR (SCpnt->SCp.buffer->address) | |
461 | #endif | |
462 | ||
463 | /* for Kernel 2.6 */ | |
464 | #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0)) | |
465 | /* scatter-gather table */ | |
466 | # define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset)) | |
467 | #endif | |
468 | ||
469 | #endif /*__nsp_cs__*/ | |
470 | /* end */ |