1184610Salfred/* SPDX-License-Identifier: GPL-2.0-only */ 2184610Salfred/* 3184610Salfred * linux/drivers/acorn/scsi/fas216.h 4184610Salfred * 5184610Salfred * Copyright (C) 1997-2000 Russell King 6184610Salfred * 7184610Salfred * FAS216 generic driver 8184610Salfred */ 9184610Salfred#ifndef FAS216_H 10184610Salfred#define FAS216_H 11184610Salfred 12184610Salfred#include <scsi/scsi_eh.h> 13184610Salfred 14184610Salfred#include "queue.h" 15184610Salfred#include "msgqueue.h" 16184610Salfred 17184610Salfred/* FAS register definitions */ 18184610Salfred 19184610Salfred/* transfer count low */ 20184610Salfred#define REG_CTCL (0) 21184610Salfred#define REG_STCL (0) 22184610Salfred 23184610Salfred/* transfer count medium */ 24184610Salfred#define REG_CTCM (1) 25184610Salfred#define REG_STCM (1) 26184610Salfred 27184610Salfred/* fifo data */ 28184610Salfred#define REG_FF (2) 29185290Salfred 30185290Salfred/* command */ 31185290Salfred#define REG_CMD (3) 32185290Salfred#define CMD_NOP 0x00 33185290Salfred#define CMD_FLUSHFIFO 0x01 34185290Salfred#define CMD_RESETCHIP 0x02 35185290Salfred#define CMD_RESETSCSI 0x03 36185290Salfred 37185290Salfred#define CMD_TRANSFERINFO 0x10 38185290Salfred#define CMD_INITCMDCOMPLETE 0x11 39194230Sthompsa#define CMD_MSGACCEPTED 0x12 40194230Sthompsa#define CMD_PADBYTES 0x18 41184610Salfred#define CMD_SETATN 0x1a 42194677Sthompsa#define CMD_RSETATN 0x1b 43246122Shselasky 44194677Sthompsa#define CMD_SELECTWOATN 0x41 45246122Shselasky#define CMD_SELECTATN 0x42 46194677Sthompsa#define CMD_SELECTATNSTOP 0x43 47194677Sthompsa#define CMD_ENABLESEL 0x44 48194677Sthompsa#define CMD_DISABLESEL 0x45 49194677Sthompsa#define CMD_SELECTATN3 0x46 50194677Sthompsa#define CMD_RESEL3 0x47 51194677Sthompsa 52246122Shselasky#define CMD_WITHDMA 0x80 53194677Sthompsa 54246122Shselasky/* status register (read) */ 55194677Sthompsa#define REG_STAT (4) 56194677Sthompsa#define STAT_IO (1 << 0) /* IO phase */ 57194677Sthompsa#define STAT_CD (1 << 1) /* CD phase */ 58194677Sthompsa#define STAT_MSG (1 << 2) /* MSG phase */ 59194677Sthompsa#define STAT_TRANSFERDONE (1 << 3) /* Transfer completed */ 60246122Shselasky#define STAT_TRANSFERCNTZ (1 << 4) /* Transfer counter is zero */ 61188942Sthompsa#define STAT_PARITYERROR (1 << 5) /* Parity error */ 62194677Sthompsa#define STAT_REALBAD (1 << 6) /* Something bad */ 63246122Shselasky#define STAT_INT (1 << 7) /* Interrupt */ 64184610Salfred 65194677Sthompsa#define STAT_BUSMASK (STAT_MSG|STAT_CD|STAT_IO) 66194677Sthompsa#define STAT_DATAOUT (0) /* Data out */ 67194677Sthompsa#define STAT_DATAIN (STAT_IO) /* Data in */ 68194677Sthompsa#define STAT_COMMAND (STAT_CD) /* Command out */ 69194677Sthompsa#define STAT_STATUS (STAT_CD|STAT_IO) /* Status In */ 70194677Sthompsa#define STAT_MESGOUT (STAT_MSG|STAT_CD) /* Message out */ 71194677Sthompsa#define STAT_MESGIN (STAT_MSG|STAT_CD|STAT_IO) /* Message In */ 72194677Sthompsa 73194677Sthompsa/* bus ID for select / reselect */ 74194677Sthompsa#define REG_SDID (4) 75194677Sthompsa#define BUSID(target) ((target) & 7) 76194677Sthompsa 77194677Sthompsa/* Interrupt status register (read) */ 78194677Sthompsa#define REG_INST (5) 79194677Sthompsa#define INST_SELWOATN (1 << 0) /* Select w/o ATN */ 80194677Sthompsa#define INST_SELATN (1 << 1) /* Select w/ATN */ 81194677Sthompsa#define INST_RESELECTED (1 << 2) /* Reselected */ 82194677Sthompsa#define INST_FUNCDONE (1 << 3) /* Function done */ 83194677Sthompsa#define INST_BUSSERVICE (1 << 4) /* Bus service */ 84194677Sthompsa#define INST_DISCONNECT (1 << 5) /* Disconnect */ 85194677Sthompsa#define INST_ILLEGALCMD (1 << 6) /* Illegal command */ 86194677Sthompsa#define INST_BUSRESET (1 << 7) /* SCSI Bus reset */ 87184610Salfred 88184610Salfred/* Timeout register (write) */ 89184610Salfred#define REG_STIM (5) 90184610Salfred 91184610Salfred/* Sequence step register (read) */ 92184610Salfred#define REG_IS (6) 93184610Salfred#define IS_BITS 0x07 94186730Salfred#define IS_SELARB 0x00 /* Select & Arb ok */ 95186730Salfred#define IS_MSGBYTESENT 0x01 /* One byte message sent*/ 96186730Salfred#define IS_NOTCOMMAND 0x02 /* Not in command state */ 97186730Salfred#define IS_EARLYPHASE 0x03 /* Early phase change */ 98186730Salfred#define IS_COMPLETE 0x04 /* Command ok */ 99186730Salfred#define IS_SOF 0x08 /* Sync off flag */ 100186730Salfred 101184610Salfred/* Transfer period step (write) */ 102241987Shselasky#define REG_STP (6) 103241987Shselasky 104241987Shselasky/* Synchronous Offset (write) */ 105241987Shselasky#define REG_SOF (7) 106241987Shselasky 107241987Shselasky/* Fifo state register (read) */ 108241987Shselasky#define REG_CFIS (7) 109241987Shselasky#define CFIS_CF 0x1f /* Num bytes in FIFO */ 110241987Shselasky#define CFIS_IS 0xe0 /* Step */ 111241987Shselasky 112241987Shselasky/* config register 1 */ 113184610Salfred#define REG_CNTL1 (8) 114241987Shselasky#define CNTL1_CID (7 << 0) /* Chip ID */ 115273456Shselasky#define CNTL1_STE (1 << 3) /* Self test enable */ 116241987Shselasky#define CNTL1_PERE (1 << 4) /* Parity enable reporting en. */ 117241987Shselasky#define CNTL1_PTE (1 << 5) /* Parity test enable */ 118241987Shselasky#define CNTL1_DISR (1 << 6) /* Disable Irq on SCSI reset */ 119241987Shselasky#define CNTL1_ETM (1 << 7) /* Extended Timing Mode */ 120241987Shselasky 121241987Shselasky/* Clock conversion factor (read) */ 122241987Shselasky#define REG_CLKF (9) 123241987Shselasky#define CLKF_F37MHZ 0x00 /* 35.01 - 40 MHz */ 124184610Salfred#define CLKF_F10MHZ 0x02 /* 10 MHz */ 125184610Salfred#define CLKF_F12MHZ 0x03 /* 10.01 - 15 MHz */ 126184610Salfred#define CLKF_F17MHZ 0x04 /* 15.01 - 20 MHz */ 127184610Salfred#define CLKF_F22MHZ 0x05 /* 20.01 - 25 MHz */ 128184610Salfred#define CLKF_F27MHZ 0x06 /* 25.01 - 30 MHz */ 129184610Salfred#define CLKF_F32MHZ 0x07 /* 30.01 - 35 MHz */ 130184610Salfred 131184610Salfred/* Chip test register (write) */ 132184610Salfred#define REG_FTM (10) 133184610Salfred#define TEST_FTM 0x01 /* Force target mode */ 134184610Salfred#define TEST_FIM 0x02 /* Force initiator mode */ 135184610Salfred#define TEST_FHI 0x04 /* Force high impedance mode */ 136193644Sthompsa 137184610Salfred/* Configuration register 2 (read/write) */ 138184610Salfred#define REG_CNTL2 (11) 139184610Salfred#define CNTL2_PGDP (1 << 0) /* Pass Th/Generate Data Parity */ 140184610Salfred#define CNTL2_PGRP (1 << 1) /* Pass Th/Generate Reg Parity */ 141193644Sthompsa#define CNTL2_ACDPE (1 << 2) /* Abort on Cmd/Data Parity Err */ 142184610Salfred#define CNTL2_S2FE (1 << 3) /* SCSI2 Features Enable */ 143184610Salfred#define CNTL2_TSDR (1 << 4) /* Tristate DREQ */ 144184610Salfred#define CNTL2_SBO (1 << 5) /* Select Byte Order */ 145184610Salfred#define CNTL2_ENF (1 << 6) /* Enable features */ 146192984Sthompsa#define CNTL2_DAE (1 << 7) /* Data Alignment Enable */ 147184610Salfred 148184610Salfred/* Configuration register 3 (read/write) */ 149184610Salfred#define REG_CNTL3 (12) 150184610Salfred#define CNTL3_BS8 (1 << 0) /* Burst size 8 */ 151184610Salfred#define CNTL3_MDM (1 << 1) /* Modify DMA mode */ 152184610Salfred#define CNTL3_LBTM (1 << 2) /* Last Byte Transfer mode */ 153192984Sthompsa#define CNTL3_FASTCLK (1 << 3) /* Fast SCSI clocking */ 154184610Salfred#define CNTL3_FASTSCSI (1 << 4) /* Fast SCSI */ 155184610Salfred#define CNTL3_G2CB (1 << 5) /* Group2 SCSI support */ 156184610Salfred#define CNTL3_QTAG (1 << 6) /* Enable 3 byte msgs */ 157184610Salfred#define CNTL3_ADIDCHK (1 << 7) /* Additional ID check */ 158184610Salfred 159184610Salfred/* High transfer count (read/write) */ 160184610Salfred#define REG_CTCH (14) 161184610Salfred#define REG_STCH (14) 162184610Salfred 163184610Salfred/* ID register (read only) */ 164184610Salfred#define REG_ID (14) 165184610Salfred 166184610Salfred/* Data alignment */ 167184610Salfred#define REG_DAL (15) 168184610Salfred 169184610Salfredtypedef enum { 170184610Salfred PHASE_IDLE, /* we're not planning on doing anything */ 171184610Salfred PHASE_SELECTION, /* selecting a device */ 172184610Salfred PHASE_SELSTEPS, /* selection with command steps */ 173184610Salfred PHASE_COMMAND, /* command sent */ 174184610Salfred PHASE_MESSAGESENT, /* selected, and we're sending cmd */ 175184610Salfred PHASE_DATAOUT, /* data out to device */ 176184610Salfred PHASE_DATAIN, /* data in from device */ 177184610Salfred PHASE_MSGIN, /* message in from device */ 178184610Salfred PHASE_MSGIN_DISCONNECT, /* disconnecting from bus */ 179184610Salfred PHASE_MSGOUT, /* after message out phase */ 180184610Salfred PHASE_MSGOUT_EXPECT, /* expecting message out */ 181184610Salfred PHASE_STATUS, /* status from device */ 182184610Salfred PHASE_DONE /* Command complete */ 183184610Salfred} phase_t; 184184610Salfred 185184610Salfredtypedef enum { 186184610Salfred DMA_OUT, /* DMA from memory to chip */ 187184610Salfred DMA_IN /* DMA from chip to memory */ 188184610Salfred} fasdmadir_t; 189184610Salfred 190184610Salfredtypedef enum { 191184610Salfred fasdma_none, /* No dma */ 192184610Salfred fasdma_pio, /* PIO mode */ 193184610Salfred fasdma_pseudo, /* Pseudo DMA */ 194184610Salfred fasdma_real_block, /* Real DMA, on block by block basis */ 195184610Salfred fasdma_real_all /* Real DMA, on request by request */ 196184610Salfred} fasdmatype_t; 197185290Salfred 198185290Salfredtypedef enum { 199184610Salfred neg_wait, /* Negotiate with device */ 200184610Salfred neg_inprogress, /* Negotiation sent */ 201184610Salfred neg_complete, /* Negotiation complete */ 202184610Salfred neg_targcomplete, /* Target completed negotiation */ 203184610Salfred neg_invalid /* Negotiation not supported */ 204185290Salfred} neg_t; 205185290Salfred 206185290Salfred#define MAGIC 0x441296bdUL 207185290Salfred#define NR_MSGS 8 208185290Salfred 209185290Salfred#define FASCAP_DMA (1 << 0) 210185290Salfred#define FASCAP_PSEUDODMA (1 << 1) 211184610Salfred 212184610Salfredtypedef struct { 213184610Salfred unsigned long magic_start; 214213427Shselasky spinlock_t host_lock; 215185290Salfred struct Scsi_Host *host; /* host */ 216184610Salfred struct scsi_cmnd *SCpnt; /* currently processing command */ 217184610Salfred struct scsi_cmnd *origSCpnt; /* original connecting command */ 218184610Salfred struct scsi_cmnd *reqSCpnt; /* request sense command */ 219184610Salfred struct scsi_cmnd *rstSCpnt; /* reset command */ 220184610Salfred struct scsi_cmnd *pending_SCpnt[8]; /* per-device pending commands */ 221184610Salfred int next_pending; /* next pending device */ 222185290Salfred 223185290Salfred /* 224184610Salfred * Error recovery 225184610Salfred */ 226184610Salfred wait_queue_head_t eh_wait; 227184610Salfred struct timer_list eh_timer; 228184610Salfred unsigned int rst_dev_status; 229184610Salfred unsigned int rst_bus_status; 230184610Salfred 231233771Shselasky /* driver information */ 232233771Shselasky struct { 233213427Shselasky phase_t phase; /* current phase */ 234185290Salfred void __iomem *io_base; /* iomem base of FAS216 */ 235184610Salfred unsigned int io_shift; /* shift to adjust reg offsets by */ 236184610Salfred unsigned char cfg[4]; /* configuration registers */ 237184610Salfred const char *type; /* chip type */ 238184610Salfred unsigned int irq; /* interrupt */ 239184610Salfred int dma; /* dma channel */ 240185290Salfred 241185290Salfred struct scsi_pointer SCp; /* current commands data pointer */ 242185290Salfred 243184610Salfred MsgQueue_t msgs; /* message queue for connected device */ 244184610Salfred 245184610Salfred unsigned int async_stp; /* Async transfer STP value */ 246184610Salfred unsigned char msgin_fifo; /* bytes in fifo at time of message in */ 247184610Salfred unsigned char message[256]; /* last message received from device */ 248184610Salfred 249184610Salfred unsigned char disconnectable:1; /* this command can be disconnected */ 250184610Salfred unsigned char aborting:1; /* aborting command */ 251184610Salfred } scsi; 252185290Salfred 253184610Salfred /* statistics information */ 254184610Salfred struct { 255233771Shselasky unsigned int queues; 256184610Salfred unsigned int removes; 257184610Salfred unsigned int fins; 258184610Salfred unsigned int reads; 259184610Salfred unsigned int writes; 260184610Salfred unsigned int miscs; 261184610Salfred unsigned int disconnects; 262184610Salfred unsigned int aborts; 263233771Shselasky unsigned int bus_resets; 264184610Salfred unsigned int host_resets; 265185290Salfred } stats; 266185290Salfred 267185290Salfred /* configuration information */ 268185290Salfred struct { 269185290Salfred unsigned char clockrate; /* clock rate of FAS device (MHz) */ 270185290Salfred unsigned char select_timeout; /* timeout (R5) */ 271185290Salfred unsigned char sync_max_depth; /* Synchronous xfer max fifo depth */ 272185290Salfred unsigned char wide_max_size; /* Maximum wide transfer size */ 273185290Salfred unsigned char cntl3; /* Control Reg 3 */ 274185290Salfred unsigned int asyncperiod; /* Async transfer period (ns) */ 275359317Shselasky unsigned int capabilities; /* driver capabilities */ 276359317Shselasky unsigned int disconnect_ok:1; /* Disconnects allowed? */ 277359317Shselasky } ifcfg; 278359317Shselasky 279359317Shselasky /* queue handling */ 280192984Sthompsa struct { 281184610Salfred Queue_t issue; /* issue queue */ 282184610Salfred Queue_t disconnected; /* disconnected command queue */ 283184610Salfred } queues; 284184610Salfred 285192984Sthompsa /* per-device info */ 286184610Salfred struct fas216_device { 287192984Sthompsa unsigned char disconnect_ok:1; /* device can disconnect */ 288184610Salfred unsigned char parity_enabled:1; /* parity checking enabled */ 289184610Salfred unsigned char parity_check:1; /* need to check parity checking */ 290184610Salfred unsigned char period; /* sync xfer period in (*4ns) */ 291184610Salfred unsigned char stp; /* synchronous transfer period */ 292185290Salfred unsigned char sof; /* synchronous offset register */ 293185290Salfred unsigned char wide_xfer; /* currently negociated wide transfer */ 294185290Salfred neg_t sync_state; /* synchronous transfer mode */ 295184610Salfred neg_t wide_state; /* wide transfer mode */ 296184610Salfred } device[8]; 297184610Salfred unsigned long busyluns[64/sizeof(unsigned long)];/* array of bits indicating LUNs busy */ 298184610Salfred 299184610Salfred /* dma */ 300184610Salfred struct { 301184610Salfred fasdmatype_t transfer_type; /* current type of DMA transfer */ 302184610Salfred fasdmatype_t (*setup) (struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, fasdmatype_t min_dma); 303184610Salfred void (*pseudo)(struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, int transfer); 304184610Salfred void (*stop) (struct Scsi_Host *host, struct scsi_pointer *SCp); 305184610Salfred } dma; 306184610Salfred 307184610Salfred /* miscellaneous */ 308192984Sthompsa int internal_done; /* flag to indicate request done */ 309184610Salfred struct scsi_eh_save ses; /* holds request sense restore info */ 310185290Salfred unsigned long magic_end; 311192984Sthompsa} FAS216_Info; 312185290Salfred 313185290Salfred/* driver-private data per SCSI command. */ 314185290Salfredstruct fas216_cmd_priv { 315185290Salfred /* 316185290Salfred * @scsi_pointer must be the first member. See also arm_scsi_pointer(). 317192984Sthompsa */ 318185290Salfred struct scsi_pointer scsi_pointer; 319185290Salfred void (*scsi_done)(struct scsi_cmnd *cmd); 320192984Sthompsa}; 321185290Salfred 322185290Salfredstatic inline struct fas216_cmd_priv *fas216_cmd_priv(struct scsi_cmnd *cmd) 323185290Salfred{ 324185290Salfred return scsi_cmd_priv(cmd); 325185290Salfred} 326185290Salfred 327185290Salfred/* Function: int fas216_init (struct Scsi_Host *instance) 328185290Salfred * Purpose : initialise FAS/NCR/AMD SCSI structures. 329185290Salfred * Params : instance - a driver-specific filled-out structure 330185290Salfred * Returns : 0 on success 331192984Sthompsa */ 332185290Salfredextern int fas216_init (struct Scsi_Host *instance); 333192984Sthompsa 334185290Salfred/* Function: int fas216_add (struct Scsi_Host *instance, struct device *dev) 335185290Salfred * Purpose : initialise FAS/NCR/AMD SCSI ic. 336185290Salfred * Params : instance - a driver-specific filled-out structure 337227401Shselasky * Returns : 0 on success 338233771Shselasky */ 339233771Shselaskyextern int fas216_add (struct Scsi_Host *instance, struct device *dev); 340233771Shselasky 341233771Shselasky/* Function: int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt) 342233771Shselasky * Purpose : queue a command for adapter to process. 343233771Shselasky * Params : h - host adapter 344185290Salfred * : SCpnt - Command to queue 345192984Sthompsa * Returns : 0 - success, else error 346185290Salfred */ 347192984Sthompsaextern int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt); 348185290Salfred 349185290Salfred/* Function: int fas216_noqueue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt) 350185290Salfred * Purpose : queue a command for adapter to process, and process it to completion. 351185290Salfred * Params : h - host adapter 352185290Salfred * : SCpnt - Command to queue 353213427Shselasky * Returns : 0 - success, else error 354185290Salfred */ 355227396Shselaskyextern int fas216_noqueue_command(struct Scsi_Host *, struct scsi_cmnd *); 356185290Salfred 357192984Sthompsa/* Function: irqreturn_t fas216_intr (FAS216_Info *info) 358185290Salfred * Purpose : handle interrupts from the interface to progress a command 359192984Sthompsa * Params : info - interface to service 360185290Salfred */ 361185290Salfredextern irqreturn_t fas216_intr (FAS216_Info *info); 362185290Salfred 363185290Salfredextern void fas216_remove (struct Scsi_Host *instance); 364213427Shselasky 365185290Salfred/* Function: void fas216_release (struct Scsi_Host *instance) 366192984Sthompsa * Purpose : release all resources and put everything to bed for FAS/NCR/AMD SCSI ic. 367188947Sthompsa * Params : instance - a driver-specific filled-out structure 368185290Salfred * Returns : 0 on success 369184610Salfred */ 370184610Salfredextern void fas216_release (struct Scsi_Host *instance); 371184610Salfred 372184610Salfredextern void fas216_print_host(FAS216_Info *info, struct seq_file *m); 373184610Salfredextern void fas216_print_stats(FAS216_Info *info, struct seq_file *m); 374184610Salfredextern void fas216_print_devices(FAS216_Info *info, struct seq_file *m); 375184610Salfred 376184610Salfred/* Function: int fas216_eh_abort(struct scsi_cmnd *SCpnt) 377213427Shselasky * Purpose : abort this command 378184610Salfred * Params : SCpnt - command to abort 379184610Salfred * Returns : FAILED if unable to abort 380184610Salfred */ 381184610Salfredextern int fas216_eh_abort(struct scsi_cmnd *SCpnt); 382184610Salfred 383184610Salfred/* Function: int fas216_eh_device_reset(struct scsi_cmnd *SCpnt) 384192984Sthompsa * Purpose : Reset the device associated with this command 385184610Salfred * Params : SCpnt - command specifing device to reset 386184610Salfred * Returns : FAILED if unable to reset 387184610Salfred */ 388184610Salfredextern int fas216_eh_device_reset(struct scsi_cmnd *SCpnt); 389184610Salfred 390184610Salfred/* Function: int fas216_eh_bus_reset(struct scsi_cmnd *SCpnt) 391184610Salfred * Purpose : Reset the complete bus associated with this command 392184610Salfred * Params : SCpnt - command specifing bus to reset 393184610Salfred * Returns : FAILED if unable to reset 394184610Salfred */ 395184610Salfredextern int fas216_eh_bus_reset(struct scsi_cmnd *SCpnt); 396184610Salfred 397184610Salfred/* Function: int fas216_eh_host_reset(struct scsi_cmnd *SCpnt) 398184610Salfred * Purpose : Reset the host associated with this command 399192984Sthompsa * Params : SCpnt - command specifing host to reset 400184610Salfred * Returns : FAILED if unable to reset 401192984Sthompsa */ 402184610Salfredextern int fas216_eh_host_reset(struct scsi_cmnd *SCpnt); 403184610Salfred 404184610Salfred#endif /* FAS216_H */ 405184610Salfred