Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 13 | #ifndef __nsp_cs__ |
| 14 | #define __nsp_cs__ |
| 15 | |
| 16 | /* for debugging */ |
| 17 | //#define NSP_DEBUG 9 |
| 18 | |
| 19 | /* |
| 20 | #define static |
| 21 | #define inline |
| 22 | */ |
| 23 | |
| 24 | /************************************ |
| 25 | * Some useful macros... |
| 26 | */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 27 | |
| 28 | /* SCSI initiator must be ID 7 */ |
| 29 | #define NSP_INITIATOR_ID 7 |
| 30 | |
| 31 | #define NSP_SELTIMEOUT 200 |
| 32 | |
| 33 | /*************************************************************************** |
| 34 | * register definitions |
| 35 | ***************************************************************************/ |
| 36 | /*======================================================================== |
| 37 | * base register |
| 38 | ========================================================================*/ |
| 39 | #define IRQCONTROL 0x00 /* R */ |
| 40 | # define IRQCONTROL_RESELECT_CLEAR BIT(0) |
| 41 | # define IRQCONTROL_PHASE_CHANGE_CLEAR BIT(1) |
| 42 | # define IRQCONTROL_TIMER_CLEAR BIT(2) |
| 43 | # define IRQCONTROL_FIFO_CLEAR BIT(3) |
| 44 | # define IRQCONTROL_ALLMASK 0xff |
| 45 | # define IRQCONTROL_ALLCLEAR (IRQCONTROL_RESELECT_CLEAR | \ |
| 46 | IRQCONTROL_PHASE_CHANGE_CLEAR | \ |
| 47 | IRQCONTROL_TIMER_CLEAR | \ |
| 48 | IRQCONTROL_FIFO_CLEAR ) |
| 49 | # define IRQCONTROL_IRQDISABLE 0xf0 |
| 50 | |
| 51 | #define IRQSTATUS 0x00 /* W */ |
| 52 | # define IRQSTATUS_SCSI BIT(0) |
| 53 | # define IRQSTATUS_TIMER BIT(2) |
| 54 | # define IRQSTATUS_FIFO BIT(3) |
| 55 | # define IRQSTATUS_MASK 0x0f |
| 56 | |
| 57 | #define IFSELECT 0x01 /* W */ |
| 58 | # define IF_IFSEL BIT(0) |
| 59 | # define IF_REGSEL BIT(2) |
| 60 | |
| 61 | #define FIFOSTATUS 0x01 /* R */ |
| 62 | # define FIFOSTATUS_CHIP_REVISION_MASK 0x0f |
| 63 | # define FIFOSTATUS_CHIP_ID_MASK 0x70 |
| 64 | # define FIFOSTATUS_FULL_EMPTY BIT(7) |
| 65 | |
| 66 | #define INDEXREG 0x02 /* R/W */ |
| 67 | #define DATAREG 0x03 /* R/W */ |
| 68 | #define FIFODATA 0x04 /* R/W */ |
| 69 | #define FIFODATA1 0x05 /* R/W */ |
| 70 | #define FIFODATA2 0x06 /* R/W */ |
| 71 | #define FIFODATA3 0x07 /* R/W */ |
| 72 | |
| 73 | /*==================================================================== |
| 74 | * indexed register |
| 75 | ====================================================================*/ |
| 76 | #define EXTBUSCTRL 0x10 /* R/W,deleted */ |
| 77 | |
| 78 | #define CLOCKDIV 0x11 /* R/W */ |
| 79 | # define CLOCK_40M 0x02 |
| 80 | # define CLOCK_20M 0x01 |
| 81 | # define FAST_20 BIT(2) |
| 82 | |
| 83 | #define TERMPWRCTRL 0x13 /* R/W */ |
| 84 | # define POWER_ON BIT(0) |
| 85 | |
| 86 | #define SCSIIRQMODE 0x15 /* R/W */ |
| 87 | # define SCSI_PHASE_CHANGE_EI BIT(0) |
| 88 | # define RESELECT_EI BIT(4) |
| 89 | # define FIFO_IRQ_EI BIT(5) |
| 90 | # define SCSI_RESET_IRQ_EI BIT(6) |
| 91 | |
| 92 | #define IRQPHASESENCE 0x16 /* R */ |
| 93 | # define LATCHED_MSG BIT(0) |
| 94 | # define LATCHED_IO BIT(1) |
| 95 | # define LATCHED_CD BIT(2) |
| 96 | # define LATCHED_BUS_FREE BIT(3) |
| 97 | # define PHASE_CHANGE_IRQ BIT(4) |
| 98 | # define RESELECT_IRQ BIT(5) |
| 99 | # define FIFO_IRQ BIT(6) |
| 100 | # define SCSI_RESET_IRQ BIT(7) |
| 101 | |
| 102 | #define TIMERCOUNT 0x17 /* R/W */ |
| 103 | |
| 104 | #define SCSIBUSCTRL 0x18 /* R/W */ |
| 105 | # define SCSI_SEL BIT(0) |
| 106 | # define SCSI_RST BIT(1) |
| 107 | # define SCSI_DATAOUT_ENB BIT(2) |
| 108 | # define SCSI_ATN BIT(3) |
| 109 | # define SCSI_ACK BIT(4) |
| 110 | # define SCSI_BSY BIT(5) |
| 111 | # define AUTODIRECTION BIT(6) |
| 112 | # define ACKENB BIT(7) |
| 113 | |
| 114 | #define SCSIBUSMON 0x19 /* R */ |
| 115 | |
| 116 | #define SETARBIT 0x1A /* W */ |
| 117 | # define ARBIT_GO BIT(0) |
| 118 | # define ARBIT_FLAG_CLEAR BIT(1) |
| 119 | |
| 120 | #define ARBITSTATUS 0x1A /* R */ |
| 121 | /*# define ARBIT_GO BIT(0)*/ |
| 122 | # define ARBIT_WIN BIT(1) |
| 123 | # define ARBIT_FAIL BIT(2) |
| 124 | # define RESELECT_FLAG BIT(3) |
| 125 | |
| 126 | #define PARITYCTRL 0x1B /* W */ |
| 127 | #define PARITYSTATUS 0x1B /* R */ |
| 128 | |
| 129 | #define COMMANDCTRL 0x1C /* W */ |
| 130 | # define CLEAR_COMMAND_POINTER BIT(0) |
| 131 | # define AUTO_COMMAND_GO BIT(1) |
| 132 | |
| 133 | #define RESELECTID 0x1C /* R */ |
| 134 | #define COMMANDDATA 0x1D /* R/W */ |
| 135 | |
| 136 | #define POINTERCLR 0x1E /* W */ |
| 137 | # define POINTER_CLEAR BIT(0) |
| 138 | # define ACK_COUNTER_CLEAR BIT(1) |
| 139 | # define REQ_COUNTER_CLEAR BIT(2) |
| 140 | # define HOST_COUNTER_CLEAR BIT(3) |
| 141 | # define READ_SOURCE (BIT(4) | BIT(5)) |
| 142 | # define ACK_COUNTER (0) |
| 143 | # define REQ_COUNTER (BIT(4)) |
| 144 | # define HOST_COUNTER (BIT(5)) |
| 145 | |
| 146 | #define TRANSFERCOUNT 0x1E /* R */ |
| 147 | |
| 148 | #define TRANSFERMODE 0x20 /* R/W */ |
| 149 | # define MODE_MEM8 BIT(0) |
| 150 | # define MODE_MEM32 BIT(1) |
| 151 | # define MODE_ADR24 BIT(2) |
| 152 | # define MODE_ADR32 BIT(3) |
| 153 | # define MODE_IO8 BIT(4) |
| 154 | # define MODE_IO32 BIT(5) |
| 155 | # define TRANSFER_GO BIT(6) |
| 156 | # define BRAIND BIT(7) |
| 157 | |
| 158 | #define SYNCREG 0x21 /* R/W */ |
| 159 | # define SYNCREG_OFFSET_MASK 0x0f |
| 160 | # define SYNCREG_PERIOD_MASK 0xf0 |
| 161 | # define SYNCREG_PERIOD_SHIFT 4 |
| 162 | |
| 163 | #define SCSIDATALATCH 0x22 /* W */ |
| 164 | #define SCSIDATAIN 0x22 /* R */ |
| 165 | #define SCSIDATAWITHACK 0x23 /* R/W */ |
| 166 | #define SCAMCONTROL 0x24 /* W */ |
| 167 | #define SCAMSTATUS 0x24 /* R */ |
| 168 | #define SCAMDATA 0x25 /* R/W */ |
| 169 | |
| 170 | #define OTHERCONTROL 0x26 /* R/W */ |
| 171 | # define TPL_ROM_WRITE_EN BIT(0) |
| 172 | # define TPWR_OUT BIT(1) |
| 173 | # define TPWR_SENSE BIT(2) |
| 174 | # define RA8_CONTROL BIT(3) |
| 175 | |
| 176 | #define ACKWIDTH 0x27 /* R/W */ |
| 177 | #define CLRTESTPNT 0x28 /* W */ |
| 178 | #define ACKCNTLD 0x29 /* W */ |
| 179 | #define REQCNTLD 0x2A /* W */ |
| 180 | #define HSTCNTLD 0x2B /* W */ |
| 181 | #define CHECKSUM 0x2C /* R/W */ |
| 182 | |
| 183 | /************************************************************************ |
| 184 | * Input status bit definitions. |
| 185 | ************************************************************************/ |
| 186 | #define S_MESSAGE BIT(0) /* Message line from SCSI bus */ |
| 187 | #define S_IO BIT(1) /* Input/Output line from SCSI bus */ |
| 188 | #define S_CD BIT(2) /* Command/Data line from SCSI bus */ |
| 189 | #define S_BUSY BIT(3) /* Busy line from SCSI bus */ |
Daniel Mack | 3ad2f3f | 2010-02-03 08:01:28 +0800 | [diff] [blame] | 190 | #define S_ACK BIT(4) /* Acknowledge line from SCSI bus */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | #define S_REQUEST BIT(5) /* Request line from SCSI bus */ |
| 192 | #define S_SELECT BIT(6) /* */ |
| 193 | #define S_ATN BIT(7) /* */ |
| 194 | |
| 195 | /*********************************************************************** |
| 196 | * Useful Bus Monitor status combinations. |
| 197 | ***********************************************************************/ |
| 198 | #define BUSMON_SEL S_SELECT |
| 199 | #define BUSMON_BSY S_BUSY |
| 200 | #define BUSMON_REQ S_REQUEST |
| 201 | #define BUSMON_IO S_IO |
| 202 | #define BUSMON_ACK S_ACK |
| 203 | #define BUSMON_BUS_FREE 0 |
| 204 | #define BUSMON_COMMAND ( S_BUSY | S_CD | S_REQUEST ) |
| 205 | #define BUSMON_MESSAGE_IN ( S_BUSY | S_CD | S_IO | S_MESSAGE | S_REQUEST ) |
| 206 | #define BUSMON_MESSAGE_OUT ( S_BUSY | S_CD | S_MESSAGE | S_REQUEST ) |
| 207 | #define BUSMON_DATA_IN ( S_BUSY | S_IO | S_REQUEST ) |
| 208 | #define BUSMON_DATA_OUT ( S_BUSY | S_REQUEST ) |
| 209 | #define BUSMON_STATUS ( S_BUSY | S_CD | S_IO | S_REQUEST ) |
| 210 | #define BUSMON_SELECT ( S_IO | S_SELECT ) |
| 211 | #define BUSMON_RESELECT ( S_IO | S_SELECT ) |
| 212 | #define BUSMON_PHASE_MASK ( S_CD | S_IO | S_MESSAGE | S_SELECT ) |
| 213 | |
| 214 | #define BUSPHASE_SELECT ( BUSMON_SELECT & BUSMON_PHASE_MASK ) |
| 215 | #define BUSPHASE_COMMAND ( BUSMON_COMMAND & BUSMON_PHASE_MASK ) |
| 216 | #define BUSPHASE_MESSAGE_IN ( BUSMON_MESSAGE_IN & BUSMON_PHASE_MASK ) |
| 217 | #define BUSPHASE_MESSAGE_OUT ( BUSMON_MESSAGE_OUT & BUSMON_PHASE_MASK ) |
| 218 | #define BUSPHASE_DATA_IN ( BUSMON_DATA_IN & BUSMON_PHASE_MASK ) |
| 219 | #define BUSPHASE_DATA_OUT ( BUSMON_DATA_OUT & BUSMON_PHASE_MASK ) |
| 220 | #define BUSPHASE_STATUS ( BUSMON_STATUS & BUSMON_PHASE_MASK ) |
| 221 | |
| 222 | /*====================================================================*/ |
| 223 | |
| 224 | typedef struct scsi_info_t { |
Dominik Brodowski | fd23823 | 2006-03-05 10:45:09 +0100 | [diff] [blame] | 225 | struct pcmcia_device *p_dev; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 226 | struct Scsi_Host *host; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 227 | int stop; |
| 228 | } scsi_info_t; |
| 229 | |
| 230 | |
| 231 | /* synchronous transfer negotiation data */ |
| 232 | typedef struct _sync_data { |
| 233 | unsigned int SyncNegotiation; |
| 234 | #define SYNC_NOT_YET 0 |
| 235 | #define SYNC_OK 1 |
| 236 | #define SYNC_NG 2 |
| 237 | |
| 238 | unsigned int SyncPeriod; |
| 239 | unsigned int SyncOffset; |
| 240 | unsigned char SyncRegister; |
| 241 | unsigned char AckWidth; |
| 242 | } sync_data; |
| 243 | |
| 244 | typedef struct _nsp_hw_data { |
| 245 | unsigned int BaseAddress; |
| 246 | unsigned int NumAddress; |
| 247 | unsigned int IrqNumber; |
| 248 | |
| 249 | unsigned long MmioAddress; |
| 250 | #define NSP_MMIO_OFFSET 0x0800 |
| 251 | unsigned long MmioLength; |
| 252 | |
| 253 | unsigned char ScsiClockDiv; |
| 254 | |
| 255 | unsigned char TransferMode; |
| 256 | |
| 257 | int TimerCount; |
| 258 | int SelectionTimeOut; |
Henrik Kretzschmar | 0fc82d5 | 2006-10-10 14:41:41 -0700 | [diff] [blame] | 259 | struct scsi_cmnd *CurrentSC; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | //int CurrnetTarget; |
| 261 | |
| 262 | int FifoCount; |
| 263 | |
| 264 | #define MSGBUF_SIZE 20 |
| 265 | unsigned char MsgBuffer[MSGBUF_SIZE]; |
| 266 | int MsgLen; |
| 267 | |
| 268 | #define N_TARGET 8 |
| 269 | sync_data Sync[N_TARGET]; |
| 270 | |
| 271 | char nspinfo[110]; /* description */ |
| 272 | spinlock_t Lock; |
| 273 | |
| 274 | scsi_info_t *ScsiInfo; /* attach <-> detect glue */ |
| 275 | |
| 276 | |
| 277 | #ifdef NSP_DEBUG |
| 278 | int CmdId; /* Accepted command serial number. |
| 279 | Used for debugging. */ |
| 280 | #endif |
| 281 | } nsp_hw_data; |
| 282 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 283 | /**************************************************************************** |
| 284 | * |
| 285 | */ |
| 286 | |
| 287 | /* Card service functions */ |
Dominik Brodowski | cc3b486 | 2005-11-14 21:23:14 +0100 | [diff] [blame] | 288 | static void nsp_cs_detach (struct pcmcia_device *p_dev); |
Dominik Brodowski | fba395e | 2006-03-31 17:21:06 +0200 | [diff] [blame] | 289 | static void nsp_cs_release(struct pcmcia_device *link); |
Dominik Brodowski | 15b99ac | 2006-03-31 17:26:06 +0200 | [diff] [blame] | 290 | static int nsp_cs_config (struct pcmcia_device *link); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 291 | |
| 292 | /* Linux SCSI subsystem specific functions */ |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 293 | static struct Scsi_Host *nsp_detect (struct scsi_host_template *sht); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 294 | static const char *nsp_info (struct Scsi_Host *shpnt); |
| 295 | static int nsp_proc_info ( |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | struct Scsi_Host *host, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 297 | char *buffer, |
| 298 | char **start, |
| 299 | off_t offset, |
| 300 | int length, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 301 | int inout); |
Henrik Kretzschmar | 0fc82d5 | 2006-10-10 14:41:41 -0700 | [diff] [blame] | 302 | static int nsp_queuecommand(struct scsi_cmnd *SCpnt, |
| 303 | void (* done)(struct scsi_cmnd *SCpnt)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 304 | |
| 305 | /* Error handler */ |
Henrik Kretzschmar | 0fc82d5 | 2006-10-10 14:41:41 -0700 | [diff] [blame] | 306 | /*static int nsp_eh_abort (struct scsi_cmnd *SCpnt);*/ |
| 307 | /*static int nsp_eh_device_reset(struct scsi_cmnd *SCpnt);*/ |
| 308 | static int nsp_eh_bus_reset (struct scsi_cmnd *SCpnt); |
| 309 | static int nsp_eh_host_reset (struct scsi_cmnd *SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | static int nsp_bus_reset (nsp_hw_data *data); |
| 311 | |
| 312 | /* */ |
| 313 | static int nsphw_init (nsp_hw_data *data); |
Henrik Kretzschmar | 0fc82d5 | 2006-10-10 14:41:41 -0700 | [diff] [blame] | 314 | static int nsphw_start_selection(struct scsi_cmnd *SCpnt); |
| 315 | static void nsp_start_timer (struct scsi_cmnd *SCpnt, int time); |
| 316 | static int nsp_fifo_count (struct scsi_cmnd *SCpnt); |
| 317 | static void nsp_pio_read (struct scsi_cmnd *SCpnt); |
| 318 | static void nsp_pio_write (struct scsi_cmnd *SCpnt); |
| 319 | static int nsp_nexus (struct scsi_cmnd *SCpnt); |
| 320 | static void nsp_scsi_done (struct scsi_cmnd *SCpnt); |
| 321 | static int nsp_analyze_sdtr (struct scsi_cmnd *SCpnt); |
| 322 | static int nsp_negate_signal (struct scsi_cmnd *SCpnt, |
| 323 | unsigned char mask, char *str); |
| 324 | static int nsp_expect_signal (struct scsi_cmnd *SCpnt, |
| 325 | unsigned char current_phase, |
| 326 | unsigned char mask); |
| 327 | static int nsp_xfer (struct scsi_cmnd *SCpnt, int phase); |
| 328 | static int nsp_dataphase_bypass (struct scsi_cmnd *SCpnt); |
| 329 | static int nsp_reselected (struct scsi_cmnd *SCpnt); |
Christoph Hellwig | d0be4a7d | 2005-10-31 18:31:40 +0100 | [diff] [blame] | 330 | static struct Scsi_Host *nsp_detect(struct scsi_host_template *sht); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 331 | |
| 332 | /* Interrupt handler */ |
David Howells | 7d12e78 | 2006-10-05 14:55:46 +0100 | [diff] [blame] | 333 | //static irqreturn_t nspintr(int irq, void *dev_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | |
| 335 | /* Module entry point*/ |
| 336 | static int __init nsp_cs_init(void); |
| 337 | static void __exit nsp_cs_exit(void); |
| 338 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | /* Debug */ |
| 340 | #ifdef NSP_DEBUG |
Henrik Kretzschmar | 0fc82d5 | 2006-10-10 14:41:41 -0700 | [diff] [blame] | 341 | static void show_command (struct scsi_cmnd *SCpnt); |
| 342 | static void show_phase (struct scsi_cmnd *SCpnt); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | static void show_busphase(unsigned char stat); |
| 344 | static void show_message (nsp_hw_data *data); |
| 345 | #else |
| 346 | # define show_command(ptr) /* */ |
| 347 | # define show_phase(SCpnt) /* */ |
| 348 | # define show_busphase(stat) /* */ |
| 349 | # define show_message(data) /* */ |
| 350 | #endif |
| 351 | |
| 352 | /* |
| 353 | * SCSI phase |
| 354 | */ |
| 355 | enum _scsi_phase { |
| 356 | PH_UNDETERMINED , |
| 357 | PH_ARBSTART , |
| 358 | PH_SELSTART , |
| 359 | PH_SELECTED , |
| 360 | PH_COMMAND , |
| 361 | PH_DATA , |
| 362 | PH_STATUS , |
| 363 | PH_MSG_IN , |
| 364 | PH_MSG_OUT , |
| 365 | PH_DISCONNECT , |
| 366 | PH_RESELECT , |
| 367 | PH_ABORT , |
| 368 | PH_RESET |
| 369 | }; |
| 370 | |
| 371 | enum _data_in_out { |
| 372 | IO_UNKNOWN, |
| 373 | IO_IN, |
| 374 | IO_OUT |
| 375 | }; |
| 376 | |
| 377 | enum _burst_mode { |
| 378 | BURST_IO8 = 0, |
| 379 | BURST_IO32 = 1, |
| 380 | BURST_MEM32 = 2, |
| 381 | }; |
| 382 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 383 | /************************************************************************** |
| 384 | * SCSI messaage |
| 385 | */ |
| 386 | #define MSG_COMMAND_COMPLETE 0x00 |
| 387 | #define MSG_EXTENDED 0x01 |
| 388 | #define MSG_ABORT 0x06 |
| 389 | #define MSG_NO_OPERATION 0x08 |
| 390 | #define MSG_BUS_DEVICE_RESET 0x0c |
| 391 | |
| 392 | #define MSG_EXT_SDTR 0x01 |
| 393 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 394 | /* scatter-gather table */ |
Jens Axboe | 45711f1 | 2007-10-22 21:19:53 +0200 | [diff] [blame] | 395 | # define BUFFER_ADDR ((char *)((sg_virt(SCpnt->SCp.buffer)))) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | |
| 397 | #endif /*__nsp_cs__*/ |
| 398 | /* end */ |