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 =========================================================*/
13 /* $Id: nsp_cs.h,v 1.19 2003/08/18 11:09:19 elca Exp $ */
26 /************************************
27 * Some useful macros...
29 #define NUMBER(arr) ((int) (sizeof(arr) / sizeof(arr[0]))) /* from XtNumber() in /usr/X11R6/include/X11/Intrinsic.h */
30 #define BIT(x) (1L << (x))
31 #define MIN(a,b) ((a) > (b) ? (b) : (a))
33 /* SCSI initiator must be ID 7 */
34 #define NSP_INITIATOR_ID 7
36 #define NSP_SELTIMEOUT 200
38 /***************************************************************************
39 * register definitions
40 ***************************************************************************/
41 /*========================================================================
43 ========================================================================*/
44 #define IRQCONTROL 0x00 /* R */
45 # define IRQCONTROL_RESELECT_CLEAR BIT(0)
46 # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1)
47 # define IRQCONTROL_TIMER_CLEAR BIT(2)
48 # define IRQCONTROL_FIFO_CLEAR BIT(3)
49 # define IRQCONTROL_ALLMASK 0xff
50 # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \
51 IRQCONTROL_PHASE_CHANGE_CLEAR | \
52 IRQCONTROL_TIMER_CLEAR | \
53 IRQCONTROL_FIFO_CLEAR )
54 # define IRQCONTROL_IRQDISABLE 0xf0
56 #define IRQSTATUS 0x00 /* W */
57 # define IRQSTATUS_SCSI BIT(0)
58 # define IRQSTATUS_TIMER BIT(2)
59 # define IRQSTATUS_FIFO BIT(3)
60 # define IRQSTATUS_MASK 0x0f
62 #define IFSELECT 0x01 /* W */
63 # define IF_IFSEL BIT(0)
64 # define IF_REGSEL BIT(2)
66 #define FIFOSTATUS 0x01 /* R */
67 # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f
68 # define FIFOSTATUS_CHIP_ID_MASK 0x70
69 # define FIFOSTATUS_FULL_EMPTY BIT(7)
71 #define INDEXREG 0x02 /* R/W */
72 #define DATAREG 0x03 /* R/W */
73 #define FIFODATA 0x04 /* R/W */
74 #define FIFODATA1 0x05 /* R/W */
75 #define FIFODATA2 0x06 /* R/W */
76 #define FIFODATA3 0x07 /* R/W */
78 /*====================================================================
80 ====================================================================*/
81 #define EXTBUSCTRL 0x10 /* R/W,deleted */
83 #define CLOCKDIV 0x11 /* R/W */
84 # define CLOCK_40M 0x02
85 # define CLOCK_20M 0x01
86 # define FAST_20 BIT(2)
88 #define TERMPWRCTRL 0x13 /* R/W */
89 # define POWER_ON BIT(0)
91 #define SCSIIRQMODE 0x15 /* R/W */
92 # define SCSI_PHASE_CHANGE_EI BIT(0)
93 # define RESELECT_EI BIT(4)
94 # define FIFO_IRQ_EI BIT(5)
95 # define SCSI_RESET_IRQ_EI BIT(6)
97 #define IRQPHASESENCE 0x16 /* R */
98 # define LATCHED_MSG BIT(0)
99 # define LATCHED_IO BIT(1)
100 # define LATCHED_CD BIT(2)
101 # define LATCHED_BUS_FREE BIT(3)
102 # define PHASE_CHANGE_IRQ BIT(4)
103 # define RESELECT_IRQ BIT(5)
104 # define FIFO_IRQ BIT(6)
105 # define SCSI_RESET_IRQ BIT(7)
107 #define TIMERCOUNT 0x17 /* R/W */
109 #define SCSIBUSCTRL 0x18 /* R/W */
110 # define SCSI_SEL BIT(0)
111 # define SCSI_RST BIT(1)
112 # define SCSI_DATAOUT_ENB BIT(2)
113 # define SCSI_ATN BIT(3)
114 # define SCSI_ACK BIT(4)
115 # define SCSI_BSY BIT(5)
116 # define AUTODIRECTION BIT(6)
117 # define ACKENB BIT(7)
119 #define SCSIBUSMON 0x19 /* R */
121 #define SETARBIT 0x1A /* W */
122 # define ARBIT_GO BIT(0)
123 # define ARBIT_FLAG_CLEAR BIT(1)
125 #define ARBITSTATUS 0x1A /* R */
126 /*# define ARBIT_GO BIT(0)*/
127 # define ARBIT_WIN BIT(1)
128 # define ARBIT_FAIL BIT(2)
129 # define RESELECT_FLAG BIT(3)
131 #define PARITYCTRL 0x1B /* W */
132 #define PARITYSTATUS 0x1B /* R */
134 #define COMMANDCTRL 0x1C /* W */
135 # define CLEAR_COMMAND_POINTER BIT(0)
136 # define AUTO_COMMAND_GO BIT(1)
138 #define RESELECTID 0x1C /* R */
139 #define COMMANDDATA 0x1D /* R/W */
141 #define POINTERCLR 0x1E /* W */
142 # define POINTER_CLEAR BIT(0)
143 # define ACK_COUNTER_CLEAR BIT(1)
144 # define REQ_COUNTER_CLEAR BIT(2)
145 # define HOST_COUNTER_CLEAR BIT(3)
146 # define READ_SOURCE (BIT(4) | BIT(5))
147 # define ACK_COUNTER (0)
148 # define REQ_COUNTER (BIT(4))
149 # define HOST_COUNTER (BIT(5))
151 #define TRANSFERCOUNT 0x1E /* R */
153 #define TRANSFERMODE 0x20 /* R/W */
154 # define MODE_MEM8 BIT(0)
155 # define MODE_MEM32 BIT(1)
156 # define MODE_ADR24 BIT(2)
157 # define MODE_ADR32 BIT(3)
158 # define MODE_IO8 BIT(4)
159 # define MODE_IO32 BIT(5)
160 # define TRANSFER_GO BIT(6)
161 # define BRAIND BIT(7)
163 #define SYNCREG 0x21 /* R/W */
164 # define SYNCREG_OFFSET_MASK 0x0f
165 # define SYNCREG_PERIOD_MASK 0xf0
166 # define SYNCREG_PERIOD_SHIFT 4
168 #define SCSIDATALATCH 0x22 /* W */
169 #define SCSIDATAIN 0x22 /* R */
170 #define SCSIDATAWITHACK 0x23 /* R/W */
171 #define SCAMCONTROL 0x24 /* W */
172 #define SCAMSTATUS 0x24 /* R */
173 #define SCAMDATA 0x25 /* R/W */
175 #define OTHERCONTROL 0x26 /* R/W */
176 # define TPL_ROM_WRITE_EN BIT(0)
177 # define TPWR_OUT BIT(1)
178 # define TPWR_SENSE BIT(2)
179 # define RA8_CONTROL BIT(3)
181 #define ACKWIDTH 0x27 /* R/W */
182 #define CLRTESTPNT 0x28 /* W */
183 #define ACKCNTLD 0x29 /* W */
184 #define REQCNTLD 0x2A /* W */
185 #define HSTCNTLD 0x2B /* W */
186 #define CHECKSUM 0x2C /* R/W */
188 /************************************************************************
189 * Input status bit definitions.
190 ************************************************************************/
191 #define S_MESSAGE BIT(0) /* Message line from SCSI bus */
192 #define S_IO BIT(1) /* Input/Output line from SCSI bus */
193 #define S_CD BIT(2) /* Command/Data line from SCSI bus */
194 #define S_BUSY BIT(3) /* Busy line from SCSI bus */
195 #define S_ACK BIT(4) /* Acknowlege line from SCSI bus */
196 #define S_REQUEST BIT(5) /* Request line from SCSI bus */
197 #define S_SELECT BIT(6) /* */
198 #define S_ATN BIT(7) /* */
200 /***********************************************************************
201 * Useful Bus Monitor status combinations.
202 ***********************************************************************/
203 #define BUSMON_SEL S_SELECT
204 #define BUSMON_BSY S_BUSY
205 #define BUSMON_REQ S_REQUEST
206 #define BUSMON_IO S_IO
207 #define BUSMON_ACK S_ACK
208 #define BUSMON_BUS_FREE 0
209 #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST )
210 #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST )
211 #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST )
212 #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST )
213 #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST )
214 #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST )
215 #define BUSMON_SELECT ( S_IO | S_SELECT )
216 #define BUSMON_RESELECT ( S_IO | S_SELECT )
217 #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT )
219 #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK )
220 #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK )
221 #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK )
222 #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK )
223 #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK )
224 #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK )
225 #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK )
227 /*====================================================================*/
229 typedef struct scsi_info_t {
231 struct Scsi_Host *host;
232 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,74))
237 struct bus_operations *bus;
243 /* synchronous transfer negotiation data */
244 typedef struct _sync_data {
245 unsigned int SyncNegotiation;
246 #define SYNC_NOT_YET 0
250 unsigned int SyncPeriod;
251 unsigned int SyncOffset;
252 unsigned char SyncRegister;
253 unsigned char AckWidth;
256 typedef struct _nsp_hw_data {
257 unsigned int BaseAddress;
258 unsigned int NumAddress;
259 unsigned int IrqNumber;
261 unsigned long MmioAddress;
262 #define NSP_MMIO_OFFSET 0x0800
263 unsigned long MmioLength;
265 unsigned char ScsiClockDiv;
267 unsigned char TransferMode;
270 int SelectionTimeOut;
271 Scsi_Cmnd *CurrentSC;
276 #define MSGBUF_SIZE 20
277 unsigned char MsgBuffer[MSGBUF_SIZE];
281 sync_data Sync[N_TARGET];
283 char nspinfo[110]; /* description */
286 scsi_info_t *ScsiInfo; /* attach <-> detect glue */
290 int CmdId; /* Accepted command serial number.
291 Used for debugging. */
296 /****************************************************************************
300 /* Card service functions */
301 static dev_link_t *nsp_cs_attach (void);
302 static void nsp_cs_detach (dev_link_t *link);
303 static void nsp_cs_release(dev_link_t *link);
304 static void nsp_cs_config (dev_link_t *link);
305 static int nsp_cs_event (event_t event, int priority, event_callback_args_t *args);
307 /* Linux SCSI subsystem specific functions */
308 static struct Scsi_Host *nsp_detect (Scsi_Host_Template *sht);
309 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0))
310 static int nsp_detect_old (Scsi_Host_Template *sht);
311 static int nsp_release_old(struct Scsi_Host *shpnt);
313 static const char *nsp_info (struct Scsi_Host *shpnt);
314 static int nsp_proc_info (
315 #if (LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73))
316 struct Scsi_Host *host,
322 #if !(LINUX_VERSION_CODE > KERNEL_VERSION(2,5,73))
326 static int nsp_queuecommand(Scsi_Cmnd *SCpnt, void (* done)(Scsi_Cmnd *SCpnt));
329 /*static int nsp_eh_abort (Scsi_Cmnd *SCpnt);*/
330 /*static int nsp_eh_device_reset(Scsi_Cmnd *SCpnt);*/
331 static int nsp_eh_bus_reset (Scsi_Cmnd *SCpnt);
332 static int nsp_eh_host_reset (Scsi_Cmnd *SCpnt);
333 static int nsp_bus_reset (nsp_hw_data *data);
336 static int nsphw_init (nsp_hw_data *data);
337 static int nsphw_start_selection(Scsi_Cmnd *SCpnt);
338 static void nsp_start_timer (Scsi_Cmnd *SCpnt, int time);
339 static int nsp_fifo_count (Scsi_Cmnd *SCpnt);
340 static void nsp_pio_read (Scsi_Cmnd *SCpnt);
341 static void nsp_pio_write (Scsi_Cmnd *SCpnt);
342 static int nsp_nexus (Scsi_Cmnd *SCpnt);
343 static void nsp_scsi_done (Scsi_Cmnd *SCpnt);
344 static int nsp_analyze_sdtr (Scsi_Cmnd *SCpnt);
345 static int nsp_negate_signal (Scsi_Cmnd *SCpnt, unsigned char mask, char *str);
346 static int nsp_expect_signal (Scsi_Cmnd *SCpnt, unsigned char current_phase, unsigned char mask);
347 static int nsp_xfer (Scsi_Cmnd *SCpnt, int phase);
348 static int nsp_dataphase_bypass (Scsi_Cmnd *SCpnt);
349 static int nsp_reselected (Scsi_Cmnd *SCpnt);
350 static struct Scsi_Host *nsp_detect(Scsi_Host_Template *sht);
352 /* Interrupt handler */
353 //static irqreturn_t nspintr(int irq, void *dev_id, struct pt_regs *regs);
355 /* Module entry point*/
356 static int __init nsp_cs_init(void);
357 static void __exit nsp_cs_exit(void);
362 static void show_command (Scsi_Cmnd *SCpnt);
363 static void show_phase (Scsi_Cmnd *SCpnt);
364 static void show_busphase(unsigned char stat);
365 static void show_message (nsp_hw_data *data);
367 # define show_command(ptr) /* */
368 # define show_phase(SCpnt) /* */
369 # define show_busphase(stat) /* */
370 # define show_message(data) /* */
405 /**************************************************************************
408 #define MSG_COMMAND_COMPLETE 0x00
409 #define MSG_EXTENDED 0x01
410 #define MSG_ABORT 0x06
411 #define MSG_NO_OPERATION 0x08
412 #define MSG_BUS_DEVICE_RESET 0x0c
414 #define MSG_EXT_SDTR 0x01
417 /**************************************************************************
418 * Compatibility functions
422 #if (LINUX_VERSION_CODE < KERNEL_VERSION(2,6,0))
423 # define scsi_register_host(template) scsi_register_module(MODULE_SCSI_HA, template)
424 # define scsi_unregister_host(template) scsi_unregister_module(MODULE_SCSI_HA, template)
425 # define scsi_host_put(host) scsi_unregister(host)
427 typedef void irqreturn_t;
428 # define IRQ_NONE /* */
429 # define IRQ_HANDLED /* */
430 # define IRQ_RETVAL(x) /* */
432 /* This is ad-hoc version of scsi_host_get_next() */
433 static inline struct Scsi_Host *scsi_host_get_next(struct Scsi_Host *host)
436 return scsi_hostlist;
442 /* This is ad-hoc version of scsi_host_hn_get() */
443 static inline struct Scsi_Host *scsi_host_hn_get(unsigned short hostno)
445 struct Scsi_Host *host;
447 for (host = scsi_host_get_next(NULL); host != NULL;
448 host = scsi_host_get_next(host)) {
449 if (host->host_no == hostno) {
457 static void cs_error(client_handle_t handle, int func, int ret)
459 error_info_t err = { func, ret };
460 pcmcia_report_error(handle, &err);
463 /* scatter-gather table */
464 # define BUFFER_ADDR (SCpnt->SCp.buffer->address)
468 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,0))
469 /* scatter-gather table */
470 # define BUFFER_ADDR ((char *)((unsigned int)(SCpnt->SCp.buffer->page) + SCpnt->SCp.buffer->offset))
473 #endif /*__nsp_cs__*/