Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0-only */
0002 /*
0003  *  linux/drivers/acorn/scsi/fas216.h
0004  *
0005  *  Copyright (C) 1997-2000 Russell King
0006  *
0007  *  FAS216 generic driver
0008  */
0009 #ifndef FAS216_H
0010 #define FAS216_H
0011 
0012 #include <scsi/scsi_eh.h>
0013 
0014 #include "queue.h"
0015 #include "msgqueue.h"
0016 
0017 /* FAS register definitions */
0018 
0019 /* transfer count low */
0020 #define REG_CTCL        (0)
0021 #define REG_STCL        (0)
0022 
0023 /* transfer count medium */
0024 #define REG_CTCM        (1)
0025 #define REG_STCM        (1)
0026 
0027 /* fifo data */
0028 #define REG_FF          (2)
0029 
0030 /* command */
0031 #define REG_CMD         (3)
0032 #define CMD_NOP         0x00
0033 #define CMD_FLUSHFIFO       0x01
0034 #define CMD_RESETCHIP       0x02
0035 #define CMD_RESETSCSI       0x03
0036 
0037 #define CMD_TRANSFERINFO    0x10
0038 #define CMD_INITCMDCOMPLETE 0x11
0039 #define CMD_MSGACCEPTED     0x12
0040 #define CMD_PADBYTES        0x18
0041 #define CMD_SETATN      0x1a
0042 #define CMD_RSETATN     0x1b
0043 
0044 #define CMD_SELECTWOATN     0x41
0045 #define CMD_SELECTATN       0x42
0046 #define CMD_SELECTATNSTOP   0x43
0047 #define CMD_ENABLESEL       0x44
0048 #define CMD_DISABLESEL      0x45
0049 #define CMD_SELECTATN3      0x46
0050 #define CMD_RESEL3      0x47
0051 
0052 #define CMD_WITHDMA     0x80
0053 
0054 /* status register (read) */
0055 #define REG_STAT        (4)
0056 #define STAT_IO         (1 << 0)            /* IO phase     */
0057 #define STAT_CD         (1 << 1)            /* CD phase     */
0058 #define STAT_MSG        (1 << 2)            /* MSG phase        */
0059 #define STAT_TRANSFERDONE   (1 << 3)            /* Transfer completed   */
0060 #define STAT_TRANSFERCNTZ   (1 << 4)            /* Transfer counter is zero */
0061 #define STAT_PARITYERROR    (1 << 5)            /* Parity error     */
0062 #define STAT_REALBAD        (1 << 6)            /* Something bad    */
0063 #define STAT_INT        (1 << 7)            /* Interrupt        */
0064 
0065 #define STAT_BUSMASK        (STAT_MSG|STAT_CD|STAT_IO)
0066 #define STAT_DATAOUT        (0)             /* Data out     */
0067 #define STAT_DATAIN     (STAT_IO)           /* Data in      */
0068 #define STAT_COMMAND        (STAT_CD)           /* Command out      */
0069 #define STAT_STATUS     (STAT_CD|STAT_IO)       /* Status In        */
0070 #define STAT_MESGOUT        (STAT_MSG|STAT_CD)      /* Message out      */
0071 #define STAT_MESGIN     (STAT_MSG|STAT_CD|STAT_IO)  /* Message In       */
0072 
0073 /* bus ID for select / reselect */
0074 #define REG_SDID        (4)
0075 #define BUSID(target)       ((target) & 7)
0076 
0077 /* Interrupt status register (read) */
0078 #define REG_INST        (5)
0079 #define INST_SELWOATN       (1 << 0)            /* Select w/o ATN   */
0080 #define INST_SELATN     (1 << 1)            /* Select w/ATN     */
0081 #define INST_RESELECTED     (1 << 2)            /* Reselected       */
0082 #define INST_FUNCDONE       (1 << 3)            /* Function done    */
0083 #define INST_BUSSERVICE     (1 << 4)            /* Bus service      */
0084 #define INST_DISCONNECT     (1 << 5)            /* Disconnect       */
0085 #define INST_ILLEGALCMD     (1 << 6)            /* Illegal command  */
0086 #define INST_BUSRESET       (1 << 7)            /* SCSI Bus reset   */
0087 
0088 /* Timeout register (write) */
0089 #define REG_STIM        (5)
0090 
0091 /* Sequence step register (read) */
0092 #define REG_IS          (6)
0093 #define IS_BITS         0x07
0094 #define IS_SELARB       0x00                /* Select & Arb ok  */
0095 #define IS_MSGBYTESENT      0x01                /* One byte message sent*/
0096 #define IS_NOTCOMMAND       0x02                /* Not in command state */
0097 #define IS_EARLYPHASE       0x03                /* Early phase change   */
0098 #define IS_COMPLETE     0x04                /* Command ok       */
0099 #define IS_SOF          0x08                /* Sync off flag    */
0100 
0101 /* Transfer period step (write) */
0102 #define REG_STP         (6)
0103 
0104 /* Synchronous Offset (write) */
0105 #define REG_SOF         (7)
0106 
0107 /* Fifo state register (read) */
0108 #define REG_CFIS        (7)
0109 #define CFIS_CF         0x1f                /* Num bytes in FIFO    */
0110 #define CFIS_IS         0xe0                /* Step         */
0111 
0112 /* config register 1 */
0113 #define REG_CNTL1       (8)
0114 #define CNTL1_CID       (7 << 0)            /* Chip ID          */
0115 #define CNTL1_STE       (1 << 3)            /* Self test enable     */
0116 #define CNTL1_PERE      (1 << 4)            /* Parity enable reporting en.  */
0117 #define CNTL1_PTE       (1 << 5)            /* Parity test enable       */
0118 #define CNTL1_DISR      (1 << 6)            /* Disable Irq on SCSI reset    */
0119 #define CNTL1_ETM       (1 << 7)            /* Extended Timing Mode     */
0120 
0121 /* Clock conversion factor (read) */
0122 #define REG_CLKF        (9)
0123 #define CLKF_F37MHZ     0x00                /* 35.01 - 40 MHz       */
0124 #define CLKF_F10MHZ     0x02                /* 10 MHz           */
0125 #define CLKF_F12MHZ     0x03                /* 10.01 - 15 MHz       */
0126 #define CLKF_F17MHZ     0x04                /* 15.01 - 20 MHz       */
0127 #define CLKF_F22MHZ     0x05                /* 20.01 - 25 MHz       */
0128 #define CLKF_F27MHZ     0x06                /* 25.01 - 30 MHz       */
0129 #define CLKF_F32MHZ     0x07                /* 30.01 - 35 MHz       */
0130 
0131 /* Chip test register (write) */
0132 #define REG_FTM         (10)
0133 #define TEST_FTM        0x01                /* Force target mode        */
0134 #define TEST_FIM        0x02                /* Force initiator mode     */
0135 #define TEST_FHI        0x04                /* Force high impedance mode    */
0136 
0137 /* Configuration register 2 (read/write) */
0138 #define REG_CNTL2       (11)
0139 #define CNTL2_PGDP      (1 << 0)            /* Pass Th/Generate Data Parity */
0140 #define CNTL2_PGRP      (1 << 1)            /* Pass Th/Generate Reg Parity  */
0141 #define CNTL2_ACDPE     (1 << 2)            /* Abort on Cmd/Data Parity Err */
0142 #define CNTL2_S2FE      (1 << 3)            /* SCSI2 Features Enable    */
0143 #define CNTL2_TSDR      (1 << 4)            /* Tristate DREQ        */
0144 #define CNTL2_SBO       (1 << 5)            /* Select Byte Order        */
0145 #define CNTL2_ENF       (1 << 6)            /* Enable features      */
0146 #define CNTL2_DAE       (1 << 7)            /* Data Alignment Enable    */
0147 
0148 /* Configuration register 3 (read/write) */
0149 #define REG_CNTL3       (12)
0150 #define CNTL3_BS8       (1 << 0)            /* Burst size 8         */
0151 #define CNTL3_MDM       (1 << 1)            /* Modify DMA mode      */
0152 #define CNTL3_LBTM      (1 << 2)            /* Last Byte Transfer mode  */
0153 #define CNTL3_FASTCLK       (1 << 3)            /* Fast SCSI clocking       */
0154 #define CNTL3_FASTSCSI      (1 << 4)            /* Fast SCSI            */
0155 #define CNTL3_G2CB      (1 << 5)            /* Group2 SCSI support      */
0156 #define CNTL3_QTAG      (1 << 6)            /* Enable 3 byte msgs       */
0157 #define CNTL3_ADIDCHK       (1 << 7)            /* Additional ID check      */
0158 
0159 /* High transfer count (read/write) */
0160 #define REG_CTCH        (14)
0161 #define REG_STCH        (14)
0162 
0163 /* ID register (read only) */
0164 #define REG_ID          (14)
0165 
0166 /* Data alignment */
0167 #define REG_DAL         (15)
0168 
0169 typedef enum {
0170     PHASE_IDLE,                 /* we're not planning on doing anything */
0171     PHASE_SELECTION,                /* selecting a device           */
0172     PHASE_SELSTEPS,                 /* selection with command steps     */
0173     PHASE_COMMAND,                  /* command sent             */
0174     PHASE_MESSAGESENT,              /* selected, and we're sending cmd  */
0175     PHASE_DATAOUT,                  /* data out to device           */
0176     PHASE_DATAIN,                   /* data in from device          */
0177     PHASE_MSGIN,                    /* message in from device       */
0178     PHASE_MSGIN_DISCONNECT,             /* disconnecting from bus       */
0179     PHASE_MSGOUT,                   /* after message out phase      */
0180     PHASE_MSGOUT_EXPECT,                /* expecting message out        */
0181     PHASE_STATUS,                   /* status from device           */
0182     PHASE_DONE                  /* Command complete         */
0183 } phase_t;
0184 
0185 typedef enum {
0186     DMA_OUT,                    /* DMA from memory to chip      */
0187     DMA_IN                      /* DMA from chip to memory      */
0188 } fasdmadir_t;
0189 
0190 typedef enum {
0191     fasdma_none,                    /* No dma               */
0192     fasdma_pio,                 /* PIO mode             */
0193     fasdma_pseudo,                  /* Pseudo DMA               */
0194     fasdma_real_block,              /* Real DMA, on block by block basis    */
0195     fasdma_real_all                 /* Real DMA, on request by request  */
0196 } fasdmatype_t;
0197 
0198 typedef enum {
0199     neg_wait,                   /* Negotiate with device        */
0200     neg_inprogress,                 /* Negotiation sent         */
0201     neg_complete,                   /* Negotiation complete         */
0202     neg_targcomplete,               /* Target completed negotiation     */
0203     neg_invalid                 /* Negotiation not supported        */
0204 } neg_t;
0205 
0206 #define MAGIC   0x441296bdUL
0207 #define NR_MSGS 8
0208 
0209 #define FASCAP_DMA      (1 << 0)
0210 #define FASCAP_PSEUDODMA    (1 << 1)
0211 
0212 typedef struct {
0213     unsigned long       magic_start;
0214     spinlock_t      host_lock;
0215     struct Scsi_Host    *host;          /* host                 */
0216     struct scsi_cmnd    *SCpnt;         /* currently processing command     */
0217     struct scsi_cmnd    *origSCpnt;     /* original connecting command      */
0218     struct scsi_cmnd    *reqSCpnt;      /* request sense command        */
0219     struct scsi_cmnd    *rstSCpnt;      /* reset command            */
0220     struct scsi_cmnd    *pending_SCpnt[8];  /* per-device pending commands      */
0221     int         next_pending;       /* next pending device          */
0222 
0223     /*
0224      * Error recovery
0225      */
0226     wait_queue_head_t   eh_wait;
0227     struct timer_list   eh_timer;
0228     unsigned int        rst_dev_status;
0229     unsigned int        rst_bus_status;
0230 
0231     /* driver information */
0232     struct {
0233         phase_t     phase;          /* current phase            */
0234         void __iomem    *io_base;       /* iomem base of FAS216         */
0235         unsigned int    io_shift;       /* shift to adjust reg offsets by   */
0236         unsigned char   cfg[4];         /* configuration registers      */
0237         const char  *type;          /* chip type                */
0238         unsigned int    irq;            /* interrupt                */
0239         int     dma;            /* dma channel              */
0240 
0241         struct scsi_pointer SCp;            /* current commands data pointer    */
0242 
0243         MsgQueue_t  msgs;           /* message queue for connected device   */
0244 
0245         unsigned int    async_stp;      /* Async transfer STP value     */
0246         unsigned char   msgin_fifo;     /* bytes in fifo at time of message in  */
0247         unsigned char   message[256];       /* last message received from device    */
0248 
0249         unsigned char   disconnectable:1;   /* this command can be disconnected */
0250         unsigned char   aborting:1;     /* aborting command         */
0251     } scsi;
0252 
0253     /* statistics information */
0254     struct {
0255         unsigned int    queues;
0256         unsigned int    removes;
0257         unsigned int    fins;
0258         unsigned int    reads;
0259         unsigned int    writes;
0260         unsigned int    miscs;
0261         unsigned int    disconnects;
0262         unsigned int    aborts;
0263         unsigned int    bus_resets;
0264         unsigned int    host_resets;
0265     } stats;
0266 
0267     /* configuration information */
0268     struct {
0269         unsigned char   clockrate;      /* clock rate of FAS device (MHz)   */
0270         unsigned char   select_timeout;     /* timeout (R5)             */
0271         unsigned char   sync_max_depth;     /* Synchronous xfer max fifo depth  */
0272         unsigned char   wide_max_size;      /* Maximum wide transfer size       */
0273         unsigned char   cntl3;          /* Control Reg 3            */
0274         unsigned int    asyncperiod;        /* Async transfer period (ns)       */
0275         unsigned int    capabilities;       /* driver capabilities          */
0276         unsigned int    disconnect_ok:1;    /* Disconnects allowed?         */
0277     } ifcfg;
0278 
0279     /* queue handling */
0280     struct {
0281             Queue_t     issue;          /* issue queue              */
0282             Queue_t     disconnected;       /* disconnected command queue       */
0283     } queues;
0284 
0285     /* per-device info */
0286     struct fas216_device {
0287         unsigned char   disconnect_ok:1;    /* device can disconnect        */
0288         unsigned char   parity_enabled:1;   /* parity checking enabled      */
0289         unsigned char   parity_check:1;     /* need to check parity checking    */
0290         unsigned char   period;         /* sync xfer period in (*4ns)       */
0291         unsigned char   stp;            /* synchronous transfer period      */
0292         unsigned char   sof;            /* synchronous offset register      */
0293         unsigned char   wide_xfer;      /* currently negociated wide transfer   */
0294         neg_t       sync_state;     /* synchronous transfer mode        */
0295         neg_t       wide_state;     /* wide transfer mode           */
0296     } device[8];
0297     unsigned long   busyluns[64/sizeof(unsigned long)];/* array of bits indicating LUNs busy    */
0298 
0299     /* dma */
0300     struct {
0301         fasdmatype_t    transfer_type;      /* current type of DMA transfer     */
0302         fasdmatype_t    (*setup) (struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, fasdmatype_t min_dma);
0303         void        (*pseudo)(struct Scsi_Host *host, struct scsi_pointer *SCp, fasdmadir_t direction, int transfer);
0304         void        (*stop)  (struct Scsi_Host *host, struct scsi_pointer *SCp);
0305     } dma;
0306 
0307     /* miscellaneous */
0308     int         internal_done;      /* flag to indicate request done */
0309     struct scsi_eh_save ses;        /* holds request sense restore info */
0310     unsigned long       magic_end;
0311 } FAS216_Info;
0312 
0313 /* driver-private data per SCSI command. */
0314 struct fas216_cmd_priv {
0315     /*
0316      * @scsi_pointer must be the first member. See also arm_scsi_pointer().
0317      */
0318     struct scsi_pointer scsi_pointer;
0319     void (*scsi_done)(struct scsi_cmnd *cmd);
0320 };
0321 
0322 static inline struct fas216_cmd_priv *fas216_cmd_priv(struct scsi_cmnd *cmd)
0323 {
0324     return scsi_cmd_priv(cmd);
0325 }
0326 
0327 /* Function: int fas216_init (struct Scsi_Host *instance)
0328  * Purpose : initialise FAS/NCR/AMD SCSI structures.
0329  * Params  : instance - a driver-specific filled-out structure
0330  * Returns : 0 on success
0331  */
0332 extern int fas216_init (struct Scsi_Host *instance);
0333 
0334 /* Function: int fas216_add (struct Scsi_Host *instance, struct device *dev)
0335  * Purpose : initialise FAS/NCR/AMD SCSI ic.
0336  * Params  : instance - a driver-specific filled-out structure
0337  * Returns : 0 on success
0338  */
0339 extern int fas216_add (struct Scsi_Host *instance, struct device *dev);
0340 
0341 /* Function: int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt)
0342  * Purpose : queue a command for adapter to process.
0343  * Params  : h - host adapter
0344  *     : SCpnt - Command to queue
0345  * Returns : 0 - success, else error
0346  */
0347 extern int fas216_queue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt);
0348 
0349 /* Function: int fas216_noqueue_command(struct Scsi_Host *h, struct scsi_cmnd *SCpnt)
0350  * Purpose : queue a command for adapter to process, and process it to completion.
0351  * Params  : h - host adapter
0352  *     : SCpnt - Command to queue
0353  * Returns : 0 - success, else error
0354  */
0355 extern int fas216_noqueue_command(struct Scsi_Host *, struct scsi_cmnd *);
0356 
0357 /* Function: irqreturn_t fas216_intr (FAS216_Info *info)
0358  * Purpose : handle interrupts from the interface to progress a command
0359  * Params  : info - interface to service
0360  */
0361 extern irqreturn_t fas216_intr (FAS216_Info *info);
0362 
0363 extern void fas216_remove (struct Scsi_Host *instance);
0364 
0365 /* Function: void fas216_release (struct Scsi_Host *instance)
0366  * Purpose : release all resources and put everything to bed for FAS/NCR/AMD SCSI ic.
0367  * Params  : instance - a driver-specific filled-out structure
0368  * Returns : 0 on success
0369  */
0370 extern void fas216_release (struct Scsi_Host *instance);
0371 
0372 extern void fas216_print_host(FAS216_Info *info, struct seq_file *m);
0373 extern void fas216_print_stats(FAS216_Info *info, struct seq_file *m);
0374 extern void fas216_print_devices(FAS216_Info *info, struct seq_file *m);
0375 
0376 /* Function: int fas216_eh_abort(struct scsi_cmnd *SCpnt)
0377  * Purpose : abort this command
0378  * Params  : SCpnt - command to abort
0379  * Returns : FAILED if unable to abort
0380  */
0381 extern int fas216_eh_abort(struct scsi_cmnd *SCpnt);
0382 
0383 /* Function: int fas216_eh_device_reset(struct scsi_cmnd *SCpnt)
0384  * Purpose : Reset the device associated with this command
0385  * Params  : SCpnt - command specifing device to reset
0386  * Returns : FAILED if unable to reset
0387  */
0388 extern int fas216_eh_device_reset(struct scsi_cmnd *SCpnt);
0389 
0390 /* Function: int fas216_eh_bus_reset(struct scsi_cmnd *SCpnt)
0391  * Purpose : Reset the complete bus associated with this command
0392  * Params  : SCpnt - command specifing bus to reset
0393  * Returns : FAILED if unable to reset
0394  */
0395 extern int fas216_eh_bus_reset(struct scsi_cmnd *SCpnt);
0396 
0397 /* Function: int fas216_eh_host_reset(struct scsi_cmnd *SCpnt)
0398  * Purpose : Reset the host associated with this command
0399  * Params  : SCpnt - command specifing host to reset
0400  * Returns : FAILED if unable to reset
0401  */
0402 extern int fas216_eh_host_reset(struct scsi_cmnd *SCpnt);
0403 
0404 #endif /* FAS216_H */