vserver 1.9.5.x5
[linux-2.6.git] / drivers / scsi / 53c700.h
1 /* -*- mode: c; c-basic-offset: 8 -*- */
2
3 /* Driver for 53c700 and 53c700-66 chips from NCR and Symbios
4  *
5  * Copyright (C) 2001 by James.Bottomley@HansenPartnership.com
6  */
7
8 #ifndef _53C700_H
9 #define _53C700_H
10
11 #include <linux/interrupt.h>
12 #include <asm/io.h>
13
14 #include <scsi/scsi_device.h>
15
16
17 #if defined(CONFIG_53C700_MEM_MAPPED) && defined(CONFIG_53C700_IO_MAPPED)
18 #define CONFIG_53C700_BOTH_MAPPED
19 #endif
20
21 /* Turn on for general debugging---too verbose for normal use */
22 #undef  NCR_700_DEBUG
23 /* Debug the tag queues, checking hash queue allocation and deallocation
24  * and search for duplicate tags */
25 #undef NCR_700_TAG_DEBUG
26
27 #ifdef NCR_700_DEBUG
28 #define DEBUG(x)        printk x
29 #else
30 #define DEBUG(x)
31 #endif
32
33 /* The number of available command slots */
34 #define NCR_700_COMMAND_SLOTS_PER_HOST  64
35 /* The maximum number of Scatter Gathers we allow */
36 #define NCR_700_SG_SEGMENTS             32
37 /* The maximum number of luns (make this of the form 2^n) */
38 #define NCR_700_MAX_LUNS                32
39 #define NCR_700_LUN_MASK                (NCR_700_MAX_LUNS - 1)
40 /* Maximum number of tags the driver ever allows per device */
41 #define NCR_700_MAX_TAGS                16
42 /* Tag depth the driver starts out with (can be altered in sysfs) */
43 #define NCR_700_DEFAULT_TAGS            4
44 /* This is the default number of commands per LUN in the untagged case.
45  * two is a good value because it means we can have one command active and
46  * one command fully prepared and waiting
47  */
48 #define NCR_700_CMD_PER_LUN             2
49 /* magic byte identifying an internally generated REQUEST_SENSE command */
50 #define NCR_700_INTERNAL_SENSE_MAGIC    0x42
51
52 /* WARNING: Leave this in for now: the dependency preprocessor doesn't
53  * pick up file specific flags, so must define here if they are not
54  * set */
55 #if !defined(CONFIG_53C700_IO_MAPPED) && !defined(CONFIG_53C700_MEM_MAPPED)
56 #error "Config.in must define either CONFIG_53C700_IO_MAPPED or CONFIG_53C700_MEM_MAPPED to use this scsi core."
57 #endif
58
59 struct NCR_700_Host_Parameters;
60
61 /* These are the externally used routines */
62 struct Scsi_Host *NCR_700_detect(struct scsi_host_template *,
63                 struct NCR_700_Host_Parameters *, struct device *,
64                 unsigned long, u8);
65 int NCR_700_release(struct Scsi_Host *host);
66 irqreturn_t NCR_700_intr(int, void *, struct pt_regs *);
67
68
69 enum NCR_700_Host_State {
70         NCR_700_HOST_BUSY,
71         NCR_700_HOST_FREE,
72 };
73
74 struct NCR_700_SG_List {
75         /* The following is a script fragment to move the buffer onto the
76          * bus and then link the next fragment or return */
77         #define SCRIPT_MOVE_DATA_IN             0x09000000
78         #define SCRIPT_MOVE_DATA_OUT            0x08000000
79         __u32   ins;
80         __u32   pAddr;
81         #define SCRIPT_NOP                      0x80000000
82         #define SCRIPT_RETURN                   0x90080000
83 };
84
85 /* We use device->hostdata to store negotiated parameters.  This is
86  * supposed to be a pointer to a device private area, but we cannot
87  * really use it as such since it will never be freed, so just use the
88  * 32 bits to cram the information.  The SYNC negotiation sequence looks
89  * like:
90  * 
91  * If DEV_NEGOTIATED_SYNC not set, tack and SDTR message on to the
92  * initial identify for the device and set DEV_BEGIN_SYNC_NEGOTATION
93  * If we get an SDTR reply, work out the SXFER parameters, squirrel
94  * them away here, clear DEV_BEGIN_SYNC_NEGOTIATION and set
95  * DEV_NEGOTIATED_SYNC.  If we get a REJECT msg, squirrel
96  *
97  *
98  * 0:7  SXFER_REG negotiated value for this device
99  * 8:15 Current queue depth
100  * 16   negotiated SYNC flag
101  * 17 begin SYNC negotiation flag 
102  * 18 device supports tag queueing */
103 #define NCR_700_DEV_NEGOTIATED_SYNC     (1<<16)
104 #define NCR_700_DEV_BEGIN_SYNC_NEGOTIATION      (1<<17)
105 #define NCR_700_DEV_PRINT_SYNC_NEGOTIATION (1<<19)
106
107 static inline void
108 NCR_700_set_depth(struct scsi_device *SDp, __u8 depth)
109 {
110         long l = (long)SDp->hostdata;
111
112         l &= 0xffff00ff;
113         l |= 0xff00 & (depth << 8);
114         SDp->hostdata = (void *)l;
115 }
116 static inline __u8
117 NCR_700_get_depth(struct scsi_device *SDp)
118 {
119         return ((((unsigned long)SDp->hostdata) & 0xff00)>>8);
120 }
121 static inline int
122 NCR_700_is_flag_set(struct scsi_device *SDp, __u32 flag)
123 {
124         return (spi_flags(SDp->sdev_target) & flag) == flag;
125 }
126 static inline int
127 NCR_700_is_flag_clear(struct scsi_device *SDp, __u32 flag)
128 {
129         return (spi_flags(SDp->sdev_target) & flag) == 0;
130 }
131 static inline void
132 NCR_700_set_flag(struct scsi_device *SDp, __u32 flag)
133 {
134         spi_flags(SDp->sdev_target) |= flag;
135 }
136 static inline void
137 NCR_700_clear_flag(struct scsi_device *SDp, __u32 flag)
138 {
139         spi_flags(SDp->sdev_target) &= ~flag;
140 }
141
142 enum NCR_700_tag_neg_state {
143         NCR_700_START_TAG_NEGOTIATION = 0,
144         NCR_700_DURING_TAG_NEGOTIATION = 1,
145         NCR_700_FINISHED_TAG_NEGOTIATION = 2,
146 };
147
148 static inline enum NCR_700_tag_neg_state
149 NCR_700_get_tag_neg_state(struct scsi_device *SDp)
150 {
151         return (enum NCR_700_tag_neg_state)((spi_flags(SDp->sdev_target)>>20) & 0x3);
152 }
153
154 static inline void
155 NCR_700_set_tag_neg_state(struct scsi_device *SDp,
156                           enum NCR_700_tag_neg_state state)
157 {
158         /* clear the slot */
159         spi_flags(SDp->sdev_target) &= ~(0x3 << 20);
160         spi_flags(SDp->sdev_target) |= ((__u32)state) << 20;
161 }
162
163 struct NCR_700_command_slot {
164         struct NCR_700_SG_List  SG[NCR_700_SG_SEGMENTS+1];
165         struct NCR_700_SG_List  *pSG;
166         #define NCR_700_SLOT_MASK 0xFC
167         #define NCR_700_SLOT_MAGIC 0xb8
168         #define NCR_700_SLOT_FREE (0|NCR_700_SLOT_MAGIC) /* slot may be used */
169         #define NCR_700_SLOT_BUSY (1|NCR_700_SLOT_MAGIC) /* slot has command active on HA */
170         #define NCR_700_SLOT_QUEUED (2|NCR_700_SLOT_MAGIC) /* slot has command to be made active on HA */
171         __u8    state;
172         int     tag;
173         __u32   resume_offset;
174         struct scsi_cmnd *cmnd;
175         /* The pci_mapped address of the actual command in cmnd */
176         dma_addr_t      pCmd;
177         __u32           temp;
178         /* if this command is a pci_single mapping, holds the dma address
179          * for later unmapping in the done routine */
180         dma_addr_t      dma_handle;
181         /* historical remnant, now used to link free commands */
182         struct NCR_700_command_slot *ITL_forw;
183 };
184
185 struct NCR_700_Host_Parameters {
186         /* These must be filled in by the calling driver */
187         int     clock;                  /* board clock speed in MHz */
188         unsigned long   base;           /* the base for the port (copied to host) */
189         struct device   *dev;
190         __u32   dmode_extra;    /* adjustable bus settings */
191         __u32   differential:1; /* if we are differential */
192 #ifdef CONFIG_53C700_LE_ON_BE
193         /* This option is for HP only.  Set it if your chip is wired for
194          * little endian on this platform (which is big endian) */
195         __u32   force_le_on_be:1;
196 #endif
197         __u32   chip710:1;      /* set if really a 710 not 700 */
198         __u32   burst_disable:1;        /* set to 1 to disable 710 bursting */
199
200         /* NOTHING BELOW HERE NEEDS ALTERING */
201         __u32   fast:1;         /* if we can alter the SCSI bus clock
202                                    speed (so can negiotiate sync) */
203 #ifdef CONFIG_53C700_BOTH_MAPPED
204         __u32   mem_mapped;     /* set if memory mapped */
205 #endif
206         int     sync_clock;     /* The speed of the SYNC core */
207
208         __u32   *script;                /* pointer to script location */
209         __u32   pScript;                /* physical mem addr of script */
210
211         enum NCR_700_Host_State state; /* protected by state lock */
212         struct scsi_cmnd *cmd;
213         /* Note: pScript contains the single consistent block of
214          * memory.  All the msgin, msgout and status are allocated in
215          * this memory too (at separate cache lines).  TOTAL_MEM_SIZE
216          * represents the total size of this area */
217 #define MSG_ARRAY_SIZE  8
218 #define MSGOUT_OFFSET   (L1_CACHE_ALIGN(sizeof(SCRIPT)))
219         __u8    *msgout;
220 #define MSGIN_OFFSET    (MSGOUT_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
221         __u8    *msgin;
222 #define STATUS_OFFSET   (MSGIN_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
223         __u8    *status;
224 #define SLOTS_OFFSET    (STATUS_OFFSET + L1_CACHE_ALIGN(MSG_ARRAY_SIZE))
225         struct NCR_700_command_slot     *slots;
226 #define TOTAL_MEM_SIZE  (SLOTS_OFFSET + L1_CACHE_ALIGN(sizeof(struct NCR_700_command_slot) * NCR_700_COMMAND_SLOTS_PER_HOST))
227         int     saved_slot_position;
228         int     command_slot_count; /* protected by state lock */
229         __u8    tag_negotiated;
230         __u8    rev;
231         __u8    reselection_id;
232         __u8    min_period;
233
234         /* Free list, singly linked by ITL_forw elements */
235         struct NCR_700_command_slot *free_list;
236         /* Completion for waited for ops, like reset, abort or
237          * device reset.
238          *
239          * NOTE: relies on single threading in the error handler to
240          * have only one outstanding at once */
241         struct completion *eh_complete;
242 };
243
244 /*
245  *      53C700 Register Interface - the offset from the Selected base
246  *      I/O address */
247 #ifdef CONFIG_53C700_LE_ON_BE
248 #define bE      (hostdata->force_le_on_be ? 0 : 3)
249 #define bSWAP   (hostdata->force_le_on_be)
250 #elif defined(__BIG_ENDIAN)
251 #define bE      3
252 #define bSWAP   0
253 #elif defined(__LITTLE_ENDIAN)
254 #define bE      0
255 #define bSWAP   0
256 #else
257 #error "__BIG_ENDIAN or __LITTLE_ENDIAN must be defined, did you include byteorder.h?"
258 #endif
259 #define bS_to_cpu(x)    (bSWAP ? le32_to_cpu(x) : (x))
260 #define bS_to_host(x)   (bSWAP ? cpu_to_le32(x) : (x))
261
262 /* NOTE: These registers are in the LE register space only, the required byte
263  * swapping is done by the NCR_700_{read|write}[b] functions */
264 #define SCNTL0_REG                      0x00
265 #define         FULL_ARBITRATION        0xc0
266 #define         PARITY                  0x08
267 #define         ENABLE_PARITY           0x04
268 #define         AUTO_ATN                0x02
269 #define SCNTL1_REG                      0x01
270 #define         SLOW_BUS                0x80
271 #define         ENABLE_SELECT           0x20
272 #define         ASSERT_RST              0x08
273 #define         ASSERT_EVEN_PARITY      0x04
274 #define SDID_REG                        0x02
275 #define SIEN_REG                        0x03
276 #define         PHASE_MM_INT            0x80
277 #define         FUNC_COMP_INT           0x40
278 #define         SEL_TIMEOUT_INT         0x20
279 #define         SELECT_INT              0x10
280 #define         GROSS_ERR_INT           0x08
281 #define         UX_DISC_INT             0x04
282 #define         RST_INT                 0x02
283 #define         PAR_ERR_INT             0x01
284 #define SCID_REG                        0x04
285 #define SXFER_REG                       0x05
286 #define         ASYNC_OPERATION         0x00
287 #define SODL_REG                        0x06
288 #define SOCL_REG                        0x07
289 #define SFBR_REG                        0x08
290 #define SIDL_REG                        0x09
291 #define SBDL_REG                        0x0A
292 #define SBCL_REG                        0x0B
293 /* read bits */
294 #define         SBCL_IO                 0x01
295 /*write bits */
296 #define         SYNC_DIV_AS_ASYNC       0x00
297 #define         SYNC_DIV_1_0            0x01
298 #define         SYNC_DIV_1_5            0x02
299 #define         SYNC_DIV_2_0            0x03
300 #define DSTAT_REG                       0x0C
301 #define         ILGL_INST_DETECTED      0x01
302 #define         WATCH_DOG_INTERRUPT     0x02
303 #define         SCRIPT_INT_RECEIVED     0x04
304 #define         ABORTED                 0x10
305 #define SSTAT0_REG                      0x0D
306 #define         PARITY_ERROR            0x01
307 #define         SCSI_RESET_DETECTED     0x02
308 #define         UNEXPECTED_DISCONNECT   0x04
309 #define         SCSI_GROSS_ERROR        0x08
310 #define         SELECTED                0x10
311 #define         SELECTION_TIMEOUT       0x20
312 #define         FUNCTION_COMPLETE       0x40
313 #define         PHASE_MISMATCH          0x80
314 #define SSTAT1_REG                      0x0E
315 #define         SIDL_REG_FULL           0x80
316 #define         SODR_REG_FULL           0x40
317 #define         SODL_REG_FULL           0x20
318 #define SSTAT2_REG                      0x0F
319 #define CTEST0_REG                      0x14
320 #define         BTB_TIMER_DISABLE       0x40
321 #define CTEST1_REG                      0x15
322 #define CTEST2_REG                      0x16
323 #define CTEST3_REG                      0x17
324 #define CTEST4_REG                      0x18
325 #define         DISABLE_FIFO            0x00
326 #define         SLBE                    0x10
327 #define         SFWR                    0x08
328 #define         BYTE_LANE0              0x04
329 #define         BYTE_LANE1              0x05
330 #define         BYTE_LANE2              0x06
331 #define         BYTE_LANE3              0x07
332 #define         SCSI_ZMODE              0x20
333 #define         ZMODE                   0x40
334 #define CTEST5_REG                      0x19
335 #define         MASTER_CONTROL          0x10
336 #define         DMA_DIRECTION           0x08
337 #define CTEST7_REG                      0x1B
338 #define         BURST_DISABLE           0x80 /* 710 only */
339 #define         SEL_TIMEOUT_DISABLE     0x10 /* 710 only */
340 #define         DFP                     0x08
341 #define         EVP                     0x04
342 #define         DIFF                    0x01
343 #define CTEST6_REG                      0x1A
344 #define TEMP_REG                        0x1C
345 #define DFIFO_REG                       0x20
346 #define         FLUSH_DMA_FIFO          0x80
347 #define         CLR_FIFO                0x40
348 #define ISTAT_REG                       0x21
349 #define         ABORT_OPERATION         0x80
350 #define         SOFTWARE_RESET_710      0x40
351 #define         DMA_INT_PENDING         0x01
352 #define         SCSI_INT_PENDING        0x02
353 #define         CONNECTED               0x08
354 #define CTEST8_REG                      0x22
355 #define         LAST_DIS_ENBL           0x01
356 #define         SHORTEN_FILTERING       0x04
357 #define         ENABLE_ACTIVE_NEGATION  0x10
358 #define         GENERATE_RECEIVE_PARITY 0x20
359 #define         CLR_FIFO_710            0x04
360 #define         FLUSH_DMA_FIFO_710      0x08
361 #define CTEST9_REG                      0x23
362 #define DBC_REG                         0x24
363 #define DCMD_REG                        0x27
364 #define DNAD_REG                        0x28
365 #define DIEN_REG                        0x39
366 #define         BUS_FAULT               0x20
367 #define         ABORT_INT               0x10
368 #define         INT_INST_INT            0x04
369 #define         WD_INT                  0x02
370 #define         ILGL_INST_INT           0x01
371 #define DCNTL_REG                       0x3B
372 #define         SOFTWARE_RESET          0x01
373 #define         COMPAT_700_MODE         0x01
374 #define         SCRPTS_16BITS           0x20
375 #define         ASYNC_DIV_2_0           0x00
376 #define         ASYNC_DIV_1_5           0x40
377 #define         ASYNC_DIV_1_0           0x80
378 #define         ASYNC_DIV_3_0           0xc0
379 #define DMODE_710_REG                   0x38
380 #define DMODE_700_REG                   0x34
381 #define         BURST_LENGTH_1          0x00
382 #define         BURST_LENGTH_2          0x40
383 #define         BURST_LENGTH_4          0x80
384 #define         BURST_LENGTH_8          0xC0
385 #define         DMODE_FC1               0x10
386 #define         DMODE_FC2               0x20
387 #define         BW16                    32 
388 #define         MODE_286                16
389 #define         IO_XFER                 8
390 #define         FIXED_ADDR              4
391
392 #define DSP_REG                         0x2C
393 #define DSPS_REG                        0x30
394
395 /* Parameters to begin SDTR negotiations.  Empirically, I find that
396  * the 53c700-66 cannot handle an offset >8, so don't change this  */
397 #define NCR_700_MAX_OFFSET      8
398 /* Was hoping the max offset would be greater for the 710, but
399  * empirically it seems to be 8 also */
400 #define NCR_710_MAX_OFFSET      8
401 #define NCR_700_MIN_XFERP       1
402 #define NCR_710_MIN_XFERP       0
403 #define NCR_700_MIN_PERIOD      25 /* for SDTR message, 100ns */
404
405 #define script_patch_32(script, symbol, value) \
406 { \
407         int i; \
408         for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
409                 __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]) + value; \
410                 (script)[A_##symbol##_used[i]] = bS_to_host(val); \
411                 dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
412                 DEBUG((" script, patching %s at %d to 0x%lx\n", \
413                        #symbol, A_##symbol##_used[i], (value))); \
414         } \
415 }
416
417 #define script_patch_32_abs(script, symbol, value) \
418 { \
419         int i; \
420         for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
421                 (script)[A_##symbol##_used[i]] = bS_to_host(value); \
422                 dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
423                 DEBUG((" script, patching %s at %d to 0x%lx\n", \
424                        #symbol, A_##symbol##_used[i], (value))); \
425         } \
426 }
427
428 /* Used for patching the SCSI ID in the SELECT instruction */
429 #define script_patch_ID(script, symbol, value) \
430 { \
431         int i; \
432         for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
433                 __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
434                 val &= 0xff00ffff; \
435                 val |= ((value) & 0xff) << 16; \
436                 (script)[A_##symbol##_used[i]] = bS_to_host(val); \
437                 dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
438                 DEBUG((" script, patching ID field %s at %d to 0x%x\n", \
439                        #symbol, A_##symbol##_used[i], val)); \
440         } \
441 }
442
443 #define script_patch_16(script, symbol, value) \
444 { \
445         int i; \
446         for(i=0; i< (sizeof(A_##symbol##_used) / sizeof(__u32)); i++) { \
447                 __u32 val = bS_to_cpu((script)[A_##symbol##_used[i]]); \
448                 val &= 0xffff0000; \
449                 val |= ((value) & 0xffff); \
450                 (script)[A_##symbol##_used[i]] = bS_to_host(val); \
451                 dma_cache_sync(&(script)[A_##symbol##_used[i]], 4, DMA_TO_DEVICE); \
452                 DEBUG((" script, patching short field %s at %d to 0x%x\n", \
453                        #symbol, A_##symbol##_used[i], val)); \
454         } \
455 }
456
457
458 static inline __u8
459 NCR_700_mem_readb(struct Scsi_Host *host, __u32 reg)
460 {
461         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
462                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
463
464         return readb(host->base + (reg^bE));
465 }
466
467 static inline __u32
468 NCR_700_mem_readl(struct Scsi_Host *host, __u32 reg)
469 {
470         __u32 value = __raw_readl(host->base + reg);
471         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
472                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
473 #if 1
474         /* sanity check the register */
475         if((reg & 0x3) != 0)
476                 BUG();
477 #endif
478
479         return bS_to_cpu(value);
480 }
481
482 static inline void
483 NCR_700_mem_writeb(__u8 value, struct Scsi_Host *host, __u32 reg)
484 {
485         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
486                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
487
488         writeb(value, host->base + (reg^bE));
489 }
490
491 static inline void
492 NCR_700_mem_writel(__u32 value, struct Scsi_Host *host, __u32 reg)
493 {
494         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
495                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
496
497 #if 1
498         /* sanity check the register */
499         if((reg & 0x3) != 0)
500                 BUG();
501 #endif
502
503         __raw_writel(bS_to_host(value), host->base + reg);
504 }
505
506 static inline __u8
507 NCR_700_io_readb(struct Scsi_Host *host, __u32 reg)
508 {
509         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
510                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
511
512         return inb(host->base + (reg^bE));
513 }
514
515 static inline __u32
516 NCR_700_io_readl(struct Scsi_Host *host, __u32 reg)
517 {
518         __u32 value = inl(host->base + reg);
519         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
520                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
521
522 #if 1
523         /* sanity check the register */
524         if((reg & 0x3) != 0)
525                 BUG();
526 #endif
527
528         return bS_to_cpu(value);
529 }
530
531 static inline void
532 NCR_700_io_writeb(__u8 value, struct Scsi_Host *host, __u32 reg)
533 {
534         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
535                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
536
537         outb(value, host->base + (reg^bE));
538 }
539
540 static inline void
541 NCR_700_io_writel(__u32 value, struct Scsi_Host *host, __u32 reg)
542 {
543         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
544                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
545
546 #if 1
547         /* sanity check the register */
548         if((reg & 0x3) != 0)
549                 BUG();
550 #endif
551
552         outl(bS_to_host(value), host->base + reg);
553 }
554
555 #ifdef CONFIG_53C700_BOTH_MAPPED
556
557 static inline __u8
558 NCR_700_readb(struct Scsi_Host *host, __u32 reg)
559 {
560         __u8 val;
561
562         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
563                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
564
565         if(hostdata->mem_mapped)
566                 val = NCR_700_mem_readb(host, reg);
567         else
568                 val = NCR_700_io_readb(host, reg);
569
570         return val;
571 }
572
573 static inline __u32
574 NCR_700_readl(struct Scsi_Host *host, __u32 reg)
575 {
576         __u32 val;
577
578         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
579                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
580
581         if(hostdata->mem_mapped)
582                 val = NCR_700_mem_readl(host, reg);
583         else
584                 val = NCR_700_io_readl(host, reg);
585
586         return val;
587 }
588
589 static inline void
590 NCR_700_writeb(__u8 value, struct Scsi_Host *host, __u32 reg)
591 {
592         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
593                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
594
595         if(hostdata->mem_mapped)
596                 NCR_700_mem_writeb(value, host, reg);
597         else
598                 NCR_700_io_writeb(value, host, reg);
599 }
600
601 static inline void
602 NCR_700_writel(__u32 value, struct Scsi_Host *host, __u32 reg)
603 {
604         const struct NCR_700_Host_Parameters *hostdata __attribute__((unused))
605                 = (struct NCR_700_Host_Parameters *)host->hostdata[0];
606
607         if(hostdata->mem_mapped)
608                 NCR_700_mem_writel(value, host, reg);
609         else
610                 NCR_700_io_writel(value, host, reg);
611 }
612
613 static inline void
614 NCR_700_set_mem_mapped(struct NCR_700_Host_Parameters *hostdata)
615 {
616         hostdata->mem_mapped = 1;
617 }
618
619 static inline void
620 NCR_700_set_io_mapped(struct NCR_700_Host_Parameters *hostdata)
621 {
622         hostdata->mem_mapped = 0;
623 }
624
625
626 #elif defined(CONFIG_53C700_IO_MAPPED)
627
628 #define NCR_700_readb NCR_700_io_readb
629 #define NCR_700_readl NCR_700_io_readl
630 #define NCR_700_writeb NCR_700_io_writeb
631 #define NCR_700_writel NCR_700_io_writel
632
633 #define NCR_700_set_io_mapped(x)
634 #define NCR_700_set_mem_mapped(x)       error I/O mapped only
635
636 #elif defined(CONFIG_53C700_MEM_MAPPED)
637
638 #define NCR_700_readb NCR_700_mem_readb
639 #define NCR_700_readl NCR_700_mem_readl
640 #define NCR_700_writeb NCR_700_mem_writeb
641 #define NCR_700_writel NCR_700_mem_writel
642
643 #define NCR_700_set_io_mapped(x)        error MEM mapped only
644 #define NCR_700_set_mem_mapped(x)
645
646 #else
647 #error neither CONFIG_53C700_MEM_MAPPED nor CONFIG_53C700_IO_MAPPED is set
648 #endif
649
650 #endif