vserver 1.9.5.x5
[linux-2.6.git] / drivers / scsi / sym53c8xx_2 / sym_hipd.h
1 /*
2  * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family 
3  * of PCI-SCSI IO processors.
4  *
5  * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
6  *
7  * This driver is derived from the Linux sym53c8xx driver.
8  * Copyright (C) 1998-2000  Gerard Roudier
9  *
10  * The sym53c8xx driver is derived from the ncr53c8xx driver that had been 
11  * a port of the FreeBSD ncr driver to Linux-1.2.13.
12  *
13  * The original ncr driver has been written for 386bsd and FreeBSD by
14  *         Wolfgang Stanglmeier        <wolf@cologne.de>
15  *         Stefan Esser                <se@mi.Uni-Koeln.de>
16  * Copyright (C) 1994  Wolfgang Stanglmeier
17  *
18  * Other major contributions:
19  *
20  * NVRAM detection and reading.
21  * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
22  *
23  *-----------------------------------------------------------------------------
24  *
25  * This program is free software; you can redistribute it and/or modify
26  * it under the terms of the GNU General Public License as published by
27  * the Free Software Foundation; either version 2 of the License, or
28  * (at your option) any later version.
29  *
30  * This program is distributed in the hope that it will be useful,
31  * but WITHOUT ANY WARRANTY; without even the implied warranty of
32  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
33  * GNU General Public License for more details.
34  *
35  * You should have received a copy of the GNU General Public License
36  * along with this program; if not, write to the Free Software
37  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
38  */
39
40 #ifndef SYM_HIPD_H
41 #define SYM_HIPD_H
42
43 /*
44  *  Generic driver options.
45  *
46  *  They may be defined in platform specific headers, if they 
47  *  are useful.
48  *
49  *    SYM_OPT_HANDLE_DIR_UNKNOWN
50  *        When this option is set, the SCRIPTS used by the driver 
51  *        are able to handle SCSI transfers with direction not 
52  *        supplied by user.
53  *        (set for Linux-2.0.X)
54  *
55  *    SYM_OPT_HANDLE_DEVICE_QUEUEING
56  *        When this option is set, the driver will use a queue per 
57  *        device and handle QUEUE FULL status requeuing internally.
58  *
59  *    SYM_OPT_LIMIT_COMMAND_REORDERING
60  *        When this option is set, the driver tries to limit tagged 
61  *        command reordering to some reasonnable value.
62  *        (set for Linux)
63  */
64 #if 0
65 #define SYM_OPT_HANDLE_DIR_UNKNOWN
66 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
67 #define SYM_OPT_LIMIT_COMMAND_REORDERING
68 #endif
69
70 /*
71  *  Active debugging tags and verbosity.
72  *  Both DEBUG_FLAGS and sym_verbose can be redefined 
73  *  by the platform specific code to something else.
74  */
75 #define DEBUG_ALLOC     (0x0001)
76 #define DEBUG_PHASE     (0x0002)
77 #define DEBUG_POLL      (0x0004)
78 #define DEBUG_QUEUE     (0x0008)
79 #define DEBUG_RESULT    (0x0010)
80 #define DEBUG_SCATTER   (0x0020)
81 #define DEBUG_SCRIPT    (0x0040)
82 #define DEBUG_TINY      (0x0080)
83 #define DEBUG_TIMING    (0x0100)
84 #define DEBUG_NEGO      (0x0200)
85 #define DEBUG_TAGS      (0x0400)
86 #define DEBUG_POINTER   (0x0800)
87
88 #ifndef DEBUG_FLAGS
89 #define DEBUG_FLAGS     (0x0000)
90 #endif
91
92 #ifndef sym_verbose
93 #define sym_verbose     (np->verbose)
94 #endif
95
96 /*
97  *  These ones should have been already defined.
98  */
99 #ifndef assert
100 #define assert(expression) { \
101         if (!(expression)) { \
102                 (void)panic( \
103                         "assertion \"%s\" failed: file \"%s\", line %d\n", \
104                         #expression, \
105                         __FILE__, __LINE__); \
106         } \
107 }
108 #endif
109
110 /*
111  *  Number of tasks per device we want to handle.
112  */
113 #if     SYM_CONF_MAX_TAG_ORDER > 8
114 #error  "more than 256 tags per logical unit not allowed."
115 #endif
116 #define SYM_CONF_MAX_TASK       (1<<SYM_CONF_MAX_TAG_ORDER)
117
118 /*
119  *  Donnot use more tasks that we can handle.
120  */
121 #ifndef SYM_CONF_MAX_TAG
122 #define SYM_CONF_MAX_TAG        SYM_CONF_MAX_TASK
123 #endif
124 #if     SYM_CONF_MAX_TAG > SYM_CONF_MAX_TASK
125 #undef  SYM_CONF_MAX_TAG
126 #define SYM_CONF_MAX_TAG        SYM_CONF_MAX_TASK
127 #endif
128
129 /*
130  *    This one means 'NO TAG for this job'
131  */
132 #define NO_TAG  (256)
133
134 /*
135  *  Number of SCSI targets.
136  */
137 #if     SYM_CONF_MAX_TARGET > 16
138 #error  "more than 16 targets not allowed."
139 #endif
140
141 /*
142  *  Number of logical units per target.
143  */
144 #if     SYM_CONF_MAX_LUN > 64
145 #error  "more than 64 logical units per target not allowed."
146 #endif
147
148 /*
149  *    Asynchronous pre-scaler (ns). Shall be 40 for 
150  *    the SCSI timings to be compliant.
151  */
152 #define SYM_CONF_MIN_ASYNC (40)
153
154 /*
155  *  Shortest memory chunk is (1<<SYM_MEM_SHIFT), currently 16.
156  *  Actual allocations happen as SYM_MEM_CLUSTER_SIZE sized.
157  *  (1 PAGE at a time is just fine).
158  */
159 #define SYM_MEM_SHIFT   4
160 #define SYM_MEM_CLUSTER_SIZE    (1UL << SYM_MEM_CLUSTER_SHIFT)
161 #define SYM_MEM_CLUSTER_MASK    (SYM_MEM_CLUSTER_SIZE-1)
162
163 /*
164  *  Number of entries in the START and DONE queues.
165  *
166  *  We limit to 1 PAGE in order to succeed allocation of 
167  *  these queues. Each entry is 8 bytes long (2 DWORDS).
168  */
169 #ifdef  SYM_CONF_MAX_START
170 #define SYM_CONF_MAX_QUEUE (SYM_CONF_MAX_START+2)
171 #else
172 #define SYM_CONF_MAX_QUEUE (7*SYM_CONF_MAX_TASK+2)
173 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
174 #endif
175
176 #if     SYM_CONF_MAX_QUEUE > SYM_MEM_CLUSTER_SIZE/8
177 #undef  SYM_CONF_MAX_QUEUE
178 #define SYM_CONF_MAX_QUEUE (SYM_MEM_CLUSTER_SIZE/8)
179 #undef  SYM_CONF_MAX_START
180 #define SYM_CONF_MAX_START (SYM_CONF_MAX_QUEUE-2)
181 #endif
182
183 /*
184  *  For this one, we want a short name :-)
185  */
186 #define MAX_QUEUE       SYM_CONF_MAX_QUEUE
187
188 /*
189  *  Common definitions for both bus space based and legacy IO methods.
190  */
191 #define INB(r)          INB_OFF(offsetof(struct sym_reg,r))
192 #define INW(r)          INW_OFF(offsetof(struct sym_reg,r))
193 #define INL(r)          INL_OFF(offsetof(struct sym_reg,r))
194
195 #define OUTB(r, v)      OUTB_OFF(offsetof(struct sym_reg,r), (v))
196 #define OUTW(r, v)      OUTW_OFF(offsetof(struct sym_reg,r), (v))
197 #define OUTL(r, v)      OUTL_OFF(offsetof(struct sym_reg,r), (v))
198
199 #define OUTONB(r, m)    OUTB(r, INB(r) | (m))
200 #define OUTOFFB(r, m)   OUTB(r, INB(r) & ~(m))
201 #define OUTONW(r, m)    OUTW(r, INW(r) | (m))
202 #define OUTOFFW(r, m)   OUTW(r, INW(r) & ~(m))
203 #define OUTONL(r, m)    OUTL(r, INL(r) | (m))
204 #define OUTOFFL(r, m)   OUTL(r, INL(r) & ~(m))
205
206 /*
207  *  We normally want the chip to have a consistent view
208  *  of driver internal data structures when we restart it.
209  *  Thus these macros.
210  */
211 #define OUTL_DSP(v)                             \
212         do {                                    \
213                 MEMORY_WRITE_BARRIER();         \
214                 OUTL (nc_dsp, (v));             \
215         } while (0)
216
217 #define OUTONB_STD()                            \
218         do {                                    \
219                 MEMORY_WRITE_BARRIER();         \
220                 OUTONB (nc_dcntl, (STD|NOCOM)); \
221         } while (0)
222
223 /*
224  *  Command control block states.
225  */
226 #define HS_IDLE         (0)
227 #define HS_BUSY         (1)
228 #define HS_NEGOTIATE    (2)     /* sync/wide data transfer*/
229 #define HS_DISCONNECT   (3)     /* Disconnected by target */
230 #define HS_WAIT         (4)     /* waiting for resource   */
231
232 #define HS_DONEMASK     (0x80)
233 #define HS_COMPLETE     (4|HS_DONEMASK)
234 #define HS_SEL_TIMEOUT  (5|HS_DONEMASK) /* Selection timeout      */
235 #define HS_UNEXPECTED   (6|HS_DONEMASK) /* Unexpected disconnect  */
236 #define HS_COMP_ERR     (7|HS_DONEMASK) /* Completed with error   */
237
238 /*
239  *  Software Interrupt Codes
240  */
241 #define SIR_BAD_SCSI_STATUS     (1)
242 #define SIR_SEL_ATN_NO_MSG_OUT  (2)
243 #define SIR_MSG_RECEIVED        (3)
244 #define SIR_MSG_WEIRD           (4)
245 #define SIR_NEGO_FAILED         (5)
246 #define SIR_NEGO_PROTO          (6)
247 #define SIR_SCRIPT_STOPPED      (7)
248 #define SIR_REJECT_TO_SEND      (8)
249 #define SIR_SWIDE_OVERRUN       (9)
250 #define SIR_SODL_UNDERRUN       (10)
251 #define SIR_RESEL_NO_MSG_IN     (11)
252 #define SIR_RESEL_NO_IDENTIFY   (12)
253 #define SIR_RESEL_BAD_LUN       (13)
254 #define SIR_TARGET_SELECTED     (14)
255 #define SIR_RESEL_BAD_I_T_L     (15)
256 #define SIR_RESEL_BAD_I_T_L_Q   (16)
257 #define SIR_ABORT_SENT          (17)
258 #define SIR_RESEL_ABORTED       (18)
259 #define SIR_MSG_OUT_DONE        (19)
260 #define SIR_COMPLETE_ERROR      (20)
261 #define SIR_DATA_OVERRUN        (21)
262 #define SIR_BAD_PHASE           (22)
263 #if     SYM_CONF_DMA_ADDRESSING_MODE == 2
264 #define SIR_DMAP_DIRTY          (23)
265 #define SIR_MAX                 (23)
266 #else
267 #define SIR_MAX                 (22)
268 #endif
269
270 /*
271  *  Extended error bit codes.
272  *  xerr_status field of struct sym_ccb.
273  */
274 #define XE_EXTRA_DATA   (1)     /* unexpected data phase         */
275 #define XE_BAD_PHASE    (1<<1)  /* illegal phase (4/5)           */
276 #define XE_PARITY_ERR   (1<<2)  /* unrecovered SCSI parity error */
277 #define XE_SODL_UNRUN   (1<<3)  /* ODD transfer in DATA OUT phase */
278 #define XE_SWIDE_OVRUN  (1<<4)  /* ODD transfer in DATA IN phase */
279
280 /*
281  *  Negotiation status.
282  *  nego_status field of struct sym_ccb.
283  */
284 #define NS_SYNC         (1)
285 #define NS_WIDE         (2)
286 #define NS_PPR          (3)
287
288 /*
289  *  A CCB hashed table is used to retrieve CCB address 
290  *  from DSA value.
291  */
292 #define CCB_HASH_SHIFT          8
293 #define CCB_HASH_SIZE           (1UL << CCB_HASH_SHIFT)
294 #define CCB_HASH_MASK           (CCB_HASH_SIZE-1)
295 #if 1
296 #define CCB_HASH_CODE(dsa)      \
297         (((dsa) >> (_LGRU16_(sizeof(struct sym_ccb)))) & CCB_HASH_MASK)
298 #else
299 #define CCB_HASH_CODE(dsa)      (((dsa) >> 9) & CCB_HASH_MASK)
300 #endif
301
302 #if     SYM_CONF_DMA_ADDRESSING_MODE == 2
303 /*
304  *  We may want to use segment registers for 64 bit DMA.
305  *  16 segments registers -> up to 64 GB addressable.
306  */
307 #define SYM_DMAP_SHIFT  (4)
308 #define SYM_DMAP_SIZE   (1u<<SYM_DMAP_SHIFT)
309 #define SYM_DMAP_MASK   (SYM_DMAP_SIZE-1)
310 #endif
311
312 /*
313  *  Device flags.
314  */
315 #define SYM_DISC_ENABLED        (1)
316 #define SYM_TAGS_ENABLED        (1<<1)
317 #define SYM_SCAN_BOOT_DISABLED  (1<<2)
318 #define SYM_SCAN_LUNS_DISABLED  (1<<3)
319
320 /*
321  *  Host adapter miscellaneous flags.
322  */
323 #define SYM_AVOID_BUS_RESET     (1)
324 #define SYM_SCAN_TARGETS_HILO   (1<<1)
325
326 /*
327  *  Misc.
328  */
329 #define SYM_SNOOP_TIMEOUT (10000000)
330 #define BUS_8_BIT       0
331 #define BUS_16_BIT      1
332
333 /*
334  *  Gather negotiable parameters value
335  */
336 struct sym_trans {
337         u8 scsi_version;
338         u8 spi_version;
339         u8 period;
340         u8 offset;
341         u8 width;
342         u8 options;     /* PPR options */
343 };
344
345 struct sym_tinfo {
346         struct sym_trans curr;
347         struct sym_trans goal;
348 #ifdef  SYM_OPT_ANNOUNCE_TRANSFER_RATE
349         struct sym_trans prev;
350 #endif
351 };
352
353 /*
354  *  Global TCB HEADER.
355  *
356  *  Due to lack of indirect addressing on earlier NCR chips,
357  *  this substructure is copied from the TCB to a global 
358  *  address after selection.
359  *  For SYMBIOS chips that support LOAD/STORE this copy is 
360  *  not needed and thus not performed.
361  */
362 struct sym_tcbh {
363         /*
364          *  Scripts bus addresses of LUN table accessed from scripts.
365          *  LUN #0 is a special case, since multi-lun devices are rare, 
366          *  and we we want to speed-up the general case and not waste 
367          *  resources.
368          */
369         u32     luntbl_sa;      /* bus address of this table    */
370         u32     lun0_sa;        /* bus address of LCB #0        */
371         /*
372          *  Actual SYNC/WIDE IO registers value for this target.
373          *  'sval', 'wval' and 'uval' are read from SCRIPTS and 
374          *  so have alignment constraints.
375          */
376 /*0*/   u_char  uval;           /* -> SCNTL4 register           */
377 /*1*/   u_char  sval;           /* -> SXFER  io register        */
378 /*2*/   u_char  filler1;
379 /*3*/   u_char  wval;           /* -> SCNTL3 io register        */
380 };
381
382 /*
383  *  Target Control Block
384  */
385 struct sym_tcb {
386         /*
387          *  TCB header.
388          *  Assumed at offset 0.
389          */
390 /*0*/   struct sym_tcbh head;
391
392         /*
393          *  LUN table used by the SCRIPTS processor.
394          *  An array of bus addresses is used on reselection.
395          */
396         u32     *luntbl;        /* LCBs bus address table       */
397
398         /*
399          *  LUN table used by the C code.
400          */
401         lcb_p   lun0p;          /* LCB of LUN #0 (usual case)   */
402 #if SYM_CONF_MAX_LUN > 1
403         lcb_p   *lunmp;         /* Other LCBs [1..MAX_LUN]      */
404 #endif
405
406         /*
407          *  Bitmap that tells about LUNs that succeeded at least 
408          *  1 IO and therefore assumed to be a real device.
409          *  Avoid useless allocation of the LCB structure.
410          */
411         u32     lun_map[(SYM_CONF_MAX_LUN+31)/32];
412
413         /*
414          *  Bitmap that tells about LUNs that haven't yet an LCB 
415          *  allocated (not discovered or LCB allocation failed).
416          */
417         u32     busy0_map[(SYM_CONF_MAX_LUN+31)/32];
418
419 #ifdef  SYM_HAVE_STCB
420         /*
421          *  O/S specific data structure.
422          */
423         struct sym_stcb s;
424 #endif
425
426         /*
427          *  Transfer capabilities (SIP)
428          */
429         struct sym_tinfo tinfo;
430
431         /*
432          * Keep track of the CCB used for the negotiation in order
433          * to ensure that only 1 negotiation is queued at a time.
434          */
435         ccb_p   nego_cp;        /* CCB used for the nego                */
436
437         /*
438          *  Set when we want to reset the device.
439          */
440         u_char  to_reset;
441
442         /*
443          *  Other user settable limits and options.
444          *  These limits are read from the NVRAM if present.
445          */
446         u_char  usrflags;
447         u_short usrtags;
448         struct scsi_device *sdev;
449 };
450
451 /*
452  *  Global LCB HEADER.
453  *
454  *  Due to lack of indirect addressing on earlier NCR chips,
455  *  this substructure is copied from the LCB to a global 
456  *  address after selection.
457  *  For SYMBIOS chips that support LOAD/STORE this copy is 
458  *  not needed and thus not performed.
459  */
460 struct sym_lcbh {
461         /*
462          *  SCRIPTS address jumped by SCRIPTS on reselection.
463          *  For not probed logical units, this address points to 
464          *  SCRIPTS that deal with bad LU handling (must be at 
465          *  offset zero of the LCB for that reason).
466          */
467 /*0*/   u32     resel_sa;
468
469         /*
470          *  Task (bus address of a CCB) read from SCRIPTS that points 
471          *  to the unique ITL nexus allowed to be disconnected.
472          */
473         u32     itl_task_sa;
474
475         /*
476          *  Task table bus address (read from SCRIPTS).
477          */
478         u32     itlq_tbl_sa;
479 };
480
481 /*
482  *  Logical Unit Control Block
483  */
484 struct sym_lcb {
485         /*
486          *  TCB header.
487          *  Assumed at offset 0.
488          */
489 /*0*/   struct sym_lcbh head;
490
491         /*
492          *  Task table read from SCRIPTS that contains pointers to 
493          *  ITLQ nexuses. The bus address read from SCRIPTS is 
494          *  inside the header.
495          */
496         u32     *itlq_tbl;      /* Kernel virtual address       */
497
498         /*
499          *  Busy CCBs management.
500          */
501         u_short busy_itlq;      /* Number of busy tagged CCBs   */
502         u_short busy_itl;       /* Number of busy untagged CCBs */
503
504         /*
505          *  Circular tag allocation buffer.
506          */
507         u_short ia_tag;         /* Tag allocation index         */
508         u_short if_tag;         /* Tag release index            */
509         u_char  *cb_tags;       /* Circular tags buffer         */
510
511         /*
512          *  O/S specific data structure.
513          */
514 #ifdef  SYM_HAVE_SLCB
515         struct sym_slcb s;
516 #endif
517
518 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
519         /*
520          *  Optionnaly the driver can handle device queueing, 
521          *  and requeues internally command to redo.
522          */
523         SYM_QUEHEAD
524                 waiting_ccbq;
525         SYM_QUEHEAD
526                 started_ccbq;
527         int     num_sgood;
528         u_short started_tags;
529         u_short started_no_tag;
530         u_short started_max;
531         u_short started_limit;
532 #endif
533
534 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
535         /*
536          *  Optionnaly the driver can try to prevent SCSI 
537          *  IOs from being too much reordering.
538          */
539         u_char          tags_si;        /* Current index to tags sum    */
540         u_short         tags_sum[2];    /* Tags sum counters            */
541         u_short         tags_since;     /* # of tags since last switch  */
542 #endif
543
544         /*
545          *  Set when we want to clear all tasks.
546          */
547         u_char to_clear;
548
549         /*
550          *  Capabilities.
551          */
552         u_char  user_flags;
553         u_char  curr_flags;
554 };
555
556 /*
557  *  Action from SCRIPTS on a task.
558  *  Is part of the CCB, but is also used separately to plug 
559  *  error handling action to perform from SCRIPTS.
560  */
561 struct sym_actscr {
562         u32     start;          /* Jumped by SCRIPTS after selection    */
563         u32     restart;        /* Jumped by SCRIPTS on relection       */
564 };
565
566 /*
567  *  Phase mismatch context.
568  *
569  *  It is part of the CCB and is used as parameters for the 
570  *  DATA pointer. We need two contexts to handle correctly the 
571  *  SAVED DATA POINTER.
572  */
573 struct sym_pmc {
574         struct  sym_tblmove sg; /* Updated interrupted SG block */
575         u32     ret;            /* SCRIPT return address        */
576 };
577
578 /*
579  *  LUN control block lookup.
580  *  We use a direct pointer for LUN #0, and a table of 
581  *  pointers which is only allocated for devices that support 
582  *  LUN(s) > 0.
583  */
584 #if SYM_CONF_MAX_LUN <= 1
585 #define sym_lp(np, tp, lun) (!lun) ? (tp)->lun0p : NULL
586 #else
587 #define sym_lp(np, tp, lun) \
588         (!lun) ? (tp)->lun0p : (tp)->lunmp ? (tp)->lunmp[(lun)] : NULL
589 #endif
590
591 /*
592  *  Status are used by the host and the script processor.
593  *
594  *  The last four bytes (status[4]) are copied to the 
595  *  scratchb register (declared as scr0..scr3) just after the 
596  *  select/reselect, and copied back just after disconnecting.
597  *  Inside the script the XX_REG are used.
598  */
599
600 /*
601  *  Last four bytes (script)
602  */
603 #define  HX_REG scr0
604 #define  HX_PRT nc_scr0
605 #define  HS_REG scr1
606 #define  HS_PRT nc_scr1
607 #define  SS_REG scr2
608 #define  SS_PRT nc_scr2
609 #define  HF_REG scr3
610 #define  HF_PRT nc_scr3
611
612 /*
613  *  Last four bytes (host)
614  */
615 #define  host_xflags   phys.head.status[0]
616 #define  host_status   phys.head.status[1]
617 #define  ssss_status   phys.head.status[2]
618 #define  host_flags    phys.head.status[3]
619
620 /*
621  *  Host flags
622  */
623 #define HF_IN_PM0       1u
624 #define HF_IN_PM1       (1u<<1)
625 #define HF_ACT_PM       (1u<<2)
626 #define HF_DP_SAVED     (1u<<3)
627 #define HF_SENSE        (1u<<4)
628 #define HF_EXT_ERR      (1u<<5)
629 #define HF_DATA_IN      (1u<<6)
630 #ifdef SYM_CONF_IARB_SUPPORT
631 #define HF_HINT_IARB    (1u<<7)
632 #endif
633
634 /*
635  *  More host flags
636  */
637 #if     SYM_CONF_DMA_ADDRESSING_MODE == 2
638 #define HX_DMAP_DIRTY   (1u<<7)
639 #endif
640
641 /*
642  *  Global CCB HEADER.
643  *
644  *  Due to lack of indirect addressing on earlier NCR chips,
645  *  this substructure is copied from the ccb to a global 
646  *  address after selection (or reselection) and copied back 
647  *  before disconnect.
648  *  For SYMBIOS chips that support LOAD/STORE this copy is 
649  *  not needed and thus not performed.
650  */
651
652 struct sym_ccbh {
653         /*
654          *  Start and restart SCRIPTS addresses (must be at 0).
655          */
656 /*0*/   struct sym_actscr go;
657
658         /*
659          *  SCRIPTS jump address that deal with data pointers.
660          *  'savep' points to the position in the script responsible 
661          *  for the actual transfer of data.
662          *  It's written on reception of a SAVE_DATA_POINTER message.
663          */
664         u32     savep;          /* Jump address to saved data pointer   */
665         u32     lastp;          /* SCRIPTS address at end of data       */
666 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
667         u32     wlastp;
668 #endif
669
670         /*
671          *  Status fields.
672          */
673         u8      status[4];
674 };
675
676 /*
677  *  GET/SET the value of the data pointer used by SCRIPTS.
678  *
679  *  We must distinguish between the LOAD/STORE-based SCRIPTS 
680  *  that use directly the header in the CCB, and the NCR-GENERIC 
681  *  SCRIPTS that use the copy of the header in the HCB.
682  */
683 #if     SYM_CONF_GENERIC_SUPPORT
684 #define sym_set_script_dp(np, cp, dp)                           \
685         do {                                                    \
686                 if (np->features & FE_LDSTR)                    \
687                         cp->phys.head.lastp = cpu_to_scr(dp);   \
688                 else                                            \
689                         np->ccb_head.lastp = cpu_to_scr(dp);    \
690         } while (0)
691 #define sym_get_script_dp(np, cp)                               \
692         scr_to_cpu((np->features & FE_LDSTR) ?                  \
693                 cp->phys.head.lastp : np->ccb_head.lastp)
694 #else
695 #define sym_set_script_dp(np, cp, dp)                           \
696         do {                                                    \
697                 cp->phys.head.lastp = cpu_to_scr(dp);           \
698         } while (0)
699
700 #define sym_get_script_dp(np, cp) (cp->phys.head.lastp)
701 #endif
702
703 /*
704  *  Data Structure Block
705  *
706  *  During execution of a ccb by the script processor, the 
707  *  DSA (data structure address) register points to this 
708  *  substructure of the ccb.
709  */
710 struct sym_dsb {
711         /*
712          *  CCB header.
713          *  Also assumed at offset 0 of the sym_ccb structure.
714          */
715 /*0*/   struct sym_ccbh head;
716
717         /*
718          *  Phase mismatch contexts.
719          *  We need two to handle correctly the SAVED DATA POINTER.
720          *  MUST BOTH BE AT OFFSET < 256, due to using 8 bit arithmetic 
721          *  for address calculation from SCRIPTS.
722          */
723         struct sym_pmc pm0;
724         struct sym_pmc pm1;
725
726         /*
727          *  Table data for Script
728          */
729         struct sym_tblsel  select;
730         struct sym_tblmove smsg;
731         struct sym_tblmove smsg_ext;
732         struct sym_tblmove cmd;
733         struct sym_tblmove sense;
734         struct sym_tblmove wresid;
735         struct sym_tblmove data [SYM_CONF_MAX_SG];
736 };
737
738 /*
739  *  Our Command Control Block
740  */
741 struct sym_ccb {
742         /*
743          *  This is the data structure which is pointed by the DSA 
744          *  register when it is executed by the script processor.
745          *  It must be the first entry.
746          */
747         struct sym_dsb phys;
748
749         /*
750          *  Pointer to CAM ccb and related stuff.
751          */
752         struct scsi_cmnd *cam_ccb;      /* CAM scsiio ccb               */
753         u8      cdb_buf[16];    /* Copy of CDB                  */
754         u8      *sns_bbuf;      /* Bounce buffer for sense data */
755 #ifndef SYM_SNS_BBUF_LEN
756 #define SYM_SNS_BBUF_LEN (32)
757 #endif  
758         int     data_len;       /* Total data length            */
759         int     segments;       /* Number of SG segments        */
760
761         u8      order;          /* Tag type (if tagged command) */
762
763         /*
764          *  Miscellaneous status'.
765          */
766         u_char  nego_status;    /* Negotiation status           */
767         u_char  xerr_status;    /* Extended error flags         */
768         u32     extra_bytes;    /* Extraneous bytes transferred */
769
770         /*
771          *  Message areas.
772          *  We prepare a message to be sent after selection.
773          *  We may use a second one if the command is rescheduled 
774          *  due to CHECK_CONDITION or COMMAND TERMINATED.
775          *  Contents are IDENTIFY and SIMPLE_TAG.
776          *  While negotiating sync or wide transfer,
777          *  a SDTR or WDTR message is appended.
778          */
779         u_char  scsi_smsg [12];
780         u_char  scsi_smsg2[12];
781
782         /*
783          *  Auto request sense related fields.
784          */
785         u_char  sensecmd[6];    /* Request Sense command        */
786         u_char  sv_scsi_status; /* Saved SCSI status            */
787         u_char  sv_xerr_status; /* Saved extended status        */
788         int     sv_resid;       /* Saved residual               */
789
790         /*
791          *  O/S specific data structure.
792          */
793 #ifdef  SYM_HAVE_SCCB
794         struct sym_sccb s;
795 #endif
796         /*
797          *  Other fields.
798          */
799         u32     ccb_ba;         /* BUS address of this CCB      */
800         u_short tag;            /* Tag for this transfer        */
801                                 /*  NO_TAG means no tag         */
802         u_char  target;
803         u_char  lun;
804         ccb_p   link_ccbh;      /* Host adapter CCB hash chain  */
805         SYM_QUEHEAD
806                 link_ccbq;      /* Link to free/busy CCB queue  */
807         u32     startp;         /* Initial data pointer         */
808         u32     goalp;          /* Expected last data pointer   */
809 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
810         u32     wgoalp;
811 #endif
812         int     ext_sg;         /* Extreme data pointer, used   */
813         int     ext_ofs;        /*  to calculate the residual.  */
814 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
815         SYM_QUEHEAD
816                 link2_ccbq;     /* Link for device queueing     */
817         u_char  started;        /* CCB queued to the squeue     */
818 #endif
819         u_char  to_abort;       /* Want this IO to be aborted   */
820 #ifdef SYM_OPT_LIMIT_COMMAND_REORDERING
821         u_char  tags_si;        /* Lun tags sum index (0,1)     */
822 #endif
823 };
824
825 #define CCB_BA(cp,lbl)  (cp->ccb_ba + offsetof(struct sym_ccb, lbl))
826
827 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
828 #define sym_goalp(cp) ((cp->host_flags & HF_DATA_IN) ? cp->goalp : cp->wgoalp)
829 #else
830 #define sym_goalp(cp) (cp->goalp)
831 #endif
832
833 /*
834  *  Host Control Block
835  */
836 struct sym_hcb {
837         /*
838          *  Global headers.
839          *  Due to poorness of addressing capabilities, earlier 
840          *  chips (810, 815, 825) copy part of the data structures 
841          *  (CCB, TCB and LCB) in fixed areas.
842          */
843 #if     SYM_CONF_GENERIC_SUPPORT
844         struct sym_ccbh ccb_head;
845         struct sym_tcbh tcb_head;
846         struct sym_lcbh lcb_head;
847 #endif
848         /*
849          *  Idle task and invalid task actions and 
850          *  their bus addresses.
851          */
852         struct sym_actscr idletask, notask, bad_itl, bad_itlq;
853         u32 idletask_ba, notask_ba, bad_itl_ba, bad_itlq_ba;
854
855         /*
856          *  Dummy lun table to protect us against target 
857          *  returning bad lun number on reselection.
858          */
859         u32     *badluntbl;     /* Table physical address       */
860         u32     badlun_sa;      /* SCRIPT handler BUS address   */
861
862         /*
863          *  Bus address of this host control block.
864          */
865         u32     hcb_ba;
866
867         /*
868          *  Bit 32-63 of the on-chip RAM bus address in LE format.
869          *  The START_RAM64 script loads the MMRS and MMWS from this 
870          *  field.
871          */
872         u32     scr_ram_seg;
873
874         /*
875          *  Initial value of some IO register bits.
876          *  These values are assumed to have been set by BIOS, and may 
877          *  be used to probe adapter implementation differences.
878          */
879         u_char  sv_scntl0, sv_scntl3, sv_dmode, sv_dcntl, sv_ctest3, sv_ctest4,
880                 sv_ctest5, sv_gpcntl, sv_stest2, sv_stest4, sv_scntl4,
881                 sv_stest1;
882
883         /*
884          *  Actual initial value of IO register bits used by the 
885          *  driver. They are loaded at initialisation according to  
886          *  features that are to be enabled/disabled.
887          */
888         u_char  rv_scntl0, rv_scntl3, rv_dmode, rv_dcntl, rv_ctest3, rv_ctest4, 
889                 rv_ctest5, rv_stest2, rv_ccntl0, rv_ccntl1, rv_scntl4;
890
891         /*
892          *  Target data.
893          */
894         struct sym_tcb  target[SYM_CONF_MAX_TARGET];
895
896         /*
897          *  Target control block bus address array used by the SCRIPT 
898          *  on reselection.
899          */
900         u32             *targtbl;
901         u32             targtbl_ba;
902
903         /*
904          *  DMA pool handle for this HBA.
905          */
906         m_pool_ident_t  bus_dmat;
907
908         /*
909          *  O/S specific data structure
910          */
911         struct sym_shcb s;
912
913         /*
914          *  Physical bus addresses of the chip.
915          */
916         u32             mmio_ba;        /* MMIO 32 bit BUS address      */
917         int             mmio_ws;        /* MMIO Window size             */
918
919         u32             ram_ba;         /* RAM 32 bit BUS address       */
920         int             ram_ws;         /* RAM window size              */
921
922         /*
923          *  SCRIPTS virtual and physical bus addresses.
924          *  'script'  is loaded in the on-chip RAM if present.
925          *  'scripth' stays in main memory for all chips except the 
926          *  53C895A, 53C896 and 53C1010 that provide 8K on-chip RAM.
927          */
928         u_char          *scripta0;      /* Copy of scripts A, B, Z      */
929         u_char          *scriptb0;
930         u_char          *scriptz0;
931         u32             scripta_ba;     /* Actual scripts A, B, Z       */
932         u32             scriptb_ba;     /* 32 bit bus addresses.        */
933         u32             scriptz_ba;
934         u_short         scripta_sz;     /* Actual size of script A, B, Z*/
935         u_short         scriptb_sz;
936         u_short         scriptz_sz;
937
938         /*
939          *  Bus addresses, setup and patch methods for 
940          *  the selected firmware.
941          */
942         struct sym_fwa_ba fwa_bas;      /* Useful SCRIPTA bus addresses */
943         struct sym_fwb_ba fwb_bas;      /* Useful SCRIPTB bus addresses */
944         struct sym_fwz_ba fwz_bas;      /* Useful SCRIPTZ bus addresses */
945         void            (*fw_setup)(struct sym_hcb *np, struct sym_fw *fw);
946         void            (*fw_patch)(struct sym_hcb *np);
947         char            *fw_name;
948
949         /*
950          *  General controller parameters and configuration.
951          */
952         u_short device_id;      /* PCI device id                */
953         u_char  revision_id;    /* PCI device revision id       */
954         u_int   features;       /* Chip features map            */
955         u_char  myaddr;         /* SCSI id of the adapter       */
956         u_char  maxburst;       /* log base 2 of dwords burst   */
957         u_char  maxwide;        /* Maximum transfer width       */
958         u_char  minsync;        /* Min sync period factor (ST)  */
959         u_char  maxsync;        /* Max sync period factor (ST)  */
960         u_char  maxoffs;        /* Max scsi offset        (ST)  */
961         u_char  minsync_dt;     /* Min sync period factor (DT)  */
962         u_char  maxsync_dt;     /* Max sync period factor (DT)  */
963         u_char  maxoffs_dt;     /* Max scsi offset        (DT)  */
964         u_char  multiplier;     /* Clock multiplier (1,2,4)     */
965         u_char  clock_divn;     /* Number of clock divisors     */
966         u32     clock_khz;      /* SCSI clock frequency in KHz  */
967         u32     pciclk_khz;     /* Estimated PCI clock  in KHz  */
968         /*
969          *  Start queue management.
970          *  It is filled up by the host processor and accessed by the 
971          *  SCRIPTS processor in order to start SCSI commands.
972          */
973         volatile                /* Prevent code optimizations   */
974         u32     *squeue;        /* Start queue virtual address  */
975         u32     squeue_ba;      /* Start queue BUS address      */
976         u_short squeueput;      /* Next free slot of the queue  */
977         u_short actccbs;        /* Number of allocated CCBs     */
978
979         /*
980          *  Command completion queue.
981          *  It is the same size as the start queue to avoid overflow.
982          */
983         u_short dqueueget;      /* Next position to scan        */
984         volatile                /* Prevent code optimizations   */
985         u32     *dqueue;        /* Completion (done) queue      */
986         u32     dqueue_ba;      /* Done queue BUS address       */
987
988         /*
989          *  Miscellaneous buffers accessed by the scripts-processor.
990          *  They shall be DWORD aligned, because they may be read or 
991          *  written with a script command.
992          */
993         u_char          msgout[8];      /* Buffer for MESSAGE OUT       */
994         u_char          msgin [8];      /* Buffer for MESSAGE IN        */
995         u32             lastmsg;        /* Last SCSI message sent       */
996         u32             scratch;        /* Scratch for SCSI receive     */
997                                         /* Also used for cache test     */
998         /*
999          *  Miscellaneous configuration and status parameters.
1000          */
1001         u_char          usrflags;       /* Miscellaneous user flags     */
1002         u_char          scsi_mode;      /* Current SCSI BUS mode        */
1003         u_char          verbose;        /* Verbosity for this controller*/
1004
1005         /*
1006          *  CCB lists and queue.
1007          */
1008         ccb_p *ccbh;                    /* CCBs hashed by DSA value     */
1009                                         /* CCB_HASH_SIZE lists of CCBs  */
1010         SYM_QUEHEAD     free_ccbq;      /* Queue of available CCBs      */
1011         SYM_QUEHEAD     busy_ccbq;      /* Queue of busy CCBs           */
1012
1013         /*
1014          *  During error handling and/or recovery,
1015          *  active CCBs that are to be completed with 
1016          *  error or requeued are moved from the busy_ccbq
1017          *  to the comp_ccbq prior to completion.
1018          */
1019         SYM_QUEHEAD     comp_ccbq;
1020
1021 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1022         SYM_QUEHEAD     dummy_ccbq;
1023 #endif
1024
1025         /*
1026          *  IMMEDIATE ARBITRATION (IARB) control.
1027          *
1028          *  We keep track in 'last_cp' of the last CCB that has been 
1029          *  queued to the SCRIPTS processor and clear 'last_cp' when 
1030          *  this CCB completes. If last_cp is not zero at the moment 
1031          *  we queue a new CCB, we set a flag in 'last_cp' that is 
1032          *  used by the SCRIPTS as a hint for setting IARB.
1033          *  We donnot set more than 'iarb_max' consecutive hints for 
1034          *  IARB in order to leave devices a chance to reselect.
1035          *  By the way, any non zero value of 'iarb_max' is unfair. :)
1036          */
1037 #ifdef SYM_CONF_IARB_SUPPORT
1038         u_short         iarb_max;       /* Max. # consecutive IARB hints*/
1039         u_short         iarb_count;     /* Actual # of these hints      */
1040         ccb_p           last_cp;
1041 #endif
1042
1043         /*
1044          *  Command abort handling.
1045          *  We need to synchronize tightly with the SCRIPTS 
1046          *  processor in order to handle things correctly.
1047          */
1048         u_char          abrt_msg[4];    /* Message to send buffer       */
1049         struct sym_tblmove abrt_tbl;    /* Table for the MOV of it      */
1050         struct sym_tblsel  abrt_sel;    /* Sync params for selection    */
1051         u_char          istat_sem;      /* Tells the chip to stop (SEM) */
1052
1053         /*
1054          *  64 bit DMA handling.
1055          */
1056 #if     SYM_CONF_DMA_ADDRESSING_MODE != 0
1057         u_char  use_dac;                /* Use PCI DAC cycles           */
1058 #if     SYM_CONF_DMA_ADDRESSING_MODE == 2
1059         u_char  dmap_dirty;             /* Dma segments registers dirty */
1060         u32     dmap_bah[SYM_DMAP_SIZE];/* Segment registers map        */
1061 #endif
1062 #endif
1063 };
1064
1065 #define HCB_BA(np, lbl) (np->hcb_ba + offsetof(struct sym_hcb, lbl))
1066
1067
1068 /*
1069  *  FIRMWARES (sym_fw.c)
1070  */
1071 struct sym_fw * sym_find_firmware(struct sym_pci_chip *chip);
1072 void sym_fw_bind_script (struct sym_hcb *np, u32 *start, int len);
1073
1074 /*
1075  *  Driver methods called from O/S specific code.
1076  */
1077 char *sym_driver_name(void);
1078 void sym_print_xerr(ccb_p cp, int x_status);
1079 int sym_reset_scsi_bus(struct sym_hcb *np, int enab_int);
1080 struct sym_pci_chip *
1081 sym_lookup_pci_chip_table (u_short device_id, u_char revision);
1082 void sym_put_start_queue(struct sym_hcb *np, ccb_p cp);
1083 #ifdef SYM_OPT_HANDLE_DEVICE_QUEUEING
1084 void sym_start_next_ccbs(struct sym_hcb *np, lcb_p lp, int maxn);
1085 #endif
1086 void sym_start_up (struct sym_hcb *np, int reason);
1087 void sym_interrupt (struct sym_hcb *np);
1088 int sym_clear_tasks(struct sym_hcb *np, int cam_status, int target, int lun, int task);
1089 ccb_p sym_get_ccb (struct sym_hcb *np, u_char tn, u_char ln, u_char tag_order);
1090 void sym_free_ccb (struct sym_hcb *np, ccb_p cp);
1091 lcb_p sym_alloc_lcb (struct sym_hcb *np, u_char tn, u_char ln);
1092 int sym_queue_scsiio(struct sym_hcb *np, struct scsi_cmnd *csio, ccb_p cp);
1093 int sym_abort_scsiio(struct sym_hcb *np, struct scsi_cmnd *ccb, int timed_out);
1094 int sym_abort_ccb(struct sym_hcb *np, ccb_p cp, int timed_out);
1095 int sym_reset_scsi_target(struct sym_hcb *np, int target);
1096 void sym_hcb_free(struct sym_hcb *np);
1097 int sym_hcb_attach(struct sym_hcb *np, struct sym_fw *fw, struct sym_nvram *nvram);
1098
1099 /*
1100  *  Optionnaly, the driver may provide a function
1101  *  to announce transfer rate changes.
1102  */
1103 #ifdef  SYM_OPT_ANNOUNCE_TRANSFER_RATE
1104 void sym_announce_transfer_rate(struct sym_hcb *np, int target);
1105 #endif
1106
1107 /*
1108  *  Build a scatter/gather entry.
1109  *
1110  *  For 64 bit systems, we use the 8 upper bits of the size field 
1111  *  to provide bus address bits 32-39 to the SCRIPTS processor.
1112  *  This allows the 895A, 896, 1010 to address up to 1 TB of memory.
1113  */
1114
1115 #if   SYM_CONF_DMA_ADDRESSING_MODE == 0
1116 #define sym_build_sge(np, data, badd, len)      \
1117 do {                                            \
1118         (data)->addr = cpu_to_scr(badd);        \
1119         (data)->size = cpu_to_scr(len);         \
1120 } while (0)
1121 #elif SYM_CONF_DMA_ADDRESSING_MODE == 1
1122 #define sym_build_sge(np, data, badd, len)                              \
1123 do {                                                                    \
1124         (data)->addr = cpu_to_scr(badd);                                \
1125         (data)->size = cpu_to_scr((((badd) >> 8) & 0xff000000) + len);  \
1126 } while (0)
1127 #elif SYM_CONF_DMA_ADDRESSING_MODE == 2
1128 int sym_lookup_dmap(struct sym_hcb *np, u32 h, int s);
1129 static __inline void 
1130 sym_build_sge(struct sym_hcb *np, struct sym_tblmove *data, u64 badd, int len)
1131 {
1132         u32 h = (badd>>32);
1133         int s = (h&SYM_DMAP_MASK);
1134
1135         if (h != np->dmap_bah[s])
1136                 goto bad;
1137 good:
1138         (data)->addr = cpu_to_scr(badd);
1139         (data)->size = cpu_to_scr((s<<24) + len);
1140         return;
1141 bad:
1142         s = sym_lookup_dmap(np, h, s);
1143         goto good;
1144 }
1145 #else
1146 #error "Unsupported DMA addressing mode"
1147 #endif
1148
1149 /*
1150  *  Set up data pointers used by SCRIPTS.
1151  *  Called from O/S specific code.
1152  */
1153 static inline void sym_setup_data_pointers(struct sym_hcb *np,
1154                 struct sym_ccb *cp, int dir)
1155 {
1156         u32 lastp, goalp;
1157
1158         /*
1159          *  No segments means no data.
1160          */
1161         if (!cp->segments)
1162                 dir = CAM_DIR_NONE;
1163
1164         /*
1165          *  Set the data pointer.
1166          */
1167         switch(dir) {
1168 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
1169         case CAM_DIR_UNKNOWN:
1170 #endif
1171         case CAM_DIR_OUT:
1172                 goalp = SCRIPTA_BA (np, data_out2) + 8;
1173                 lastp = goalp - 8 - (cp->segments * (2*4));
1174 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
1175                 cp->wgoalp = cpu_to_scr(goalp);
1176                 if (dir != CAM_DIR_UNKNOWN)
1177                         break;
1178                 cp->phys.head.wlastp = cpu_to_scr(lastp);
1179                 /* fall through */
1180 #else
1181                 break;
1182 #endif
1183         case CAM_DIR_IN:
1184                 cp->host_flags |= HF_DATA_IN;
1185                 goalp = SCRIPTA_BA (np, data_in2) + 8;
1186                 lastp = goalp - 8 - (cp->segments * (2*4));
1187                 break;
1188         case CAM_DIR_NONE:
1189         default:
1190 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
1191                 cp->host_flags |= HF_DATA_IN;
1192 #endif
1193                 lastp = goalp = SCRIPTB_BA (np, no_data);
1194                 break;
1195         }
1196
1197         /*
1198          *  Set all pointers values needed by SCRIPTS.
1199          */
1200         cp->phys.head.lastp = cpu_to_scr(lastp);
1201         cp->phys.head.savep = cpu_to_scr(lastp);
1202         cp->startp          = cp->phys.head.savep;
1203         cp->goalp           = cpu_to_scr(goalp);
1204
1205 #ifdef  SYM_OPT_HANDLE_DIR_UNKNOWN
1206         /*
1207          *  If direction is unknown, start at data_io.
1208          */
1209         if (dir == CAM_DIR_UNKNOWN)
1210                 cp->phys.head.savep = cpu_to_scr(SCRIPTB_BA (np, data_io));
1211 #endif
1212 }
1213
1214 /*
1215  *  MEMORY ALLOCATOR.
1216  */
1217
1218 /*
1219  *  Link between free memory chunks of a given size.
1220  */
1221 typedef struct sym_m_link {
1222         struct sym_m_link *next;
1223 } *m_link_p;
1224
1225 /*
1226  *  Virtual to bus physical translation for a given cluster.
1227  *  Such a structure is only useful with DMA abstraction.
1228  */
1229 typedef struct sym_m_vtob {     /* Virtual to Bus address translation */
1230         struct sym_m_vtob *next;
1231 #ifdef  SYM_HAVE_M_SVTOB
1232         struct sym_m_svtob s;   /* OS specific data structure */
1233 #endif
1234         m_addr_t        vaddr;  /* Virtual address */
1235         m_addr_t        baddr;  /* Bus physical address */
1236 } *m_vtob_p;
1237
1238 /* Hash this stuff a bit to speed up translations */
1239 #define VTOB_HASH_SHIFT         5
1240 #define VTOB_HASH_SIZE          (1UL << VTOB_HASH_SHIFT)
1241 #define VTOB_HASH_MASK          (VTOB_HASH_SIZE-1)
1242 #define VTOB_HASH_CODE(m)       \
1243         ((((m_addr_t) (m)) >> SYM_MEM_CLUSTER_SHIFT) & VTOB_HASH_MASK)
1244
1245 /*
1246  *  Memory pool of a given kind.
1247  *  Ideally, we want to use:
1248  *  1) 1 pool for memory we donnot need to involve in DMA.
1249  *  2) The same pool for controllers that require same DMA 
1250  *     constraints and features.
1251  *     The OS specific m_pool_id_t thing and the sym_m_pool_match() 
1252  *     method are expected to tell the driver about.
1253  */
1254 typedef struct sym_m_pool {
1255         m_pool_ident_t  dev_dmat;       /* Identifies the pool (see above) */
1256         m_addr_t (*get_mem_cluster)(struct sym_m_pool *);
1257 #ifdef  SYM_MEM_FREE_UNUSED
1258         void (*free_mem_cluster)(struct sym_m_pool *, m_addr_t);
1259 #endif
1260 #define M_GET_MEM_CLUSTER()             mp->get_mem_cluster(mp)
1261 #define M_FREE_MEM_CLUSTER(p)           mp->free_mem_cluster(mp, p)
1262 #ifdef  SYM_HAVE_M_SPOOL
1263         struct sym_m_spool      s;      /* OS specific data structure */
1264 #endif
1265         int nump;
1266         m_vtob_p vtob[VTOB_HASH_SIZE];
1267         struct sym_m_pool *next;
1268         struct sym_m_link h[SYM_MEM_CLUSTER_SHIFT - SYM_MEM_SHIFT + 1];
1269 } *m_pool_p;
1270
1271 /*
1272  *  Alloc and free non DMAable memory.
1273  */
1274 void sym_mfree_unlocked(void *ptr, int size, char *name);
1275 void *sym_calloc_unlocked(int size, char *name);
1276
1277 /*
1278  *  Alloc, free and translate addresses to bus physical 
1279  *  for DMAable memory.
1280  */
1281 void *__sym_calloc_dma_unlocked(m_pool_ident_t dev_dmat, int size, char *name);
1282 void 
1283 __sym_mfree_dma_unlocked(m_pool_ident_t dev_dmat, void *m,int size, char *name);
1284 u32 __vtobus_unlocked(m_pool_ident_t dev_dmat, void *m);
1285
1286 /*
1287  * Verbs used by the driver code for DMAable memory handling.
1288  * The _uvptv_ macro avoids a nasty warning about pointer to volatile 
1289  * being discarded.
1290  */
1291 #define _uvptv_(p) ((void *)((u_long)(p)))
1292
1293 #define _sym_calloc_dma(np, l, n)       __sym_calloc_dma(np->bus_dmat, l, n)
1294 #define _sym_mfree_dma(np, p, l, n)     \
1295                         __sym_mfree_dma(np->bus_dmat, _uvptv_(p), l, n)
1296 #define sym_calloc_dma(l, n)            _sym_calloc_dma(np, l, n)
1297 #define sym_mfree_dma(p, l, n)          _sym_mfree_dma(np, p, l, n)
1298 #define _vtobus(np, p)                  __vtobus(np->bus_dmat, _uvptv_(p))
1299 #define vtobus(p)                       _vtobus(np, p)
1300
1301 /*
1302  *  Override some function names.
1303  */
1304 #define PRINT_ADDR      sym_print_addr
1305 #define PRINT_TARGET    sym_print_target
1306 #define PRINT_LUN       sym_print_lun
1307 #define UDELAY          sym_udelay
1308
1309 #endif /* SYM_HIPD_H */