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  * Redistribution and use in source and binary forms, with or without
26  * modification, are permitted provided that the following conditions
27  * are met:
28  * 1. Redistributions of source code must retain the above copyright
29  *    notice, this list of conditions and the following disclaimer.
30  * 2. The name of the author may not be used to endorse or promote products
31  *    derived from this software without specific prior written permission.
32  *
33  * Where this Software is combined with software released under the terms of
34  * the GNU Public License ("GPL") and the terms of the GPL would require the
35  * combined work to also be released under the terms of the GPL, the terms
36  * and conditions of this License will apply in addition to those of the
37  * GPL with the exception of any terms or conditions of this License that
38  * conflict with, or are expressly prohibited by, the GPL.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND
41  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
42  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
43  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR
44  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
45  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
46  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
47  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
48  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
49  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
50  * SUCH DAMAGE.
51  */
52 
53 #ifndef SYM_GLUE_H
54 #define SYM_GLUE_H
55 
56 #if 0
57 #define SYM_CONF_DMA_ADDRESSING_MODE 2
58 #endif
59 
60 #define LinuxVersionCode(v, p, s) (((v)<<16)+((p)<<8)+(s))
61 #include <linux/version.h>
62 #if	LINUX_VERSION_CODE < LinuxVersionCode(2, 2, 0)
63 #error	"This driver requires a kernel version not lower than 2.2.0"
64 #endif
65 
66 #include <asm/dma.h>
67 #include <asm/io.h>
68 #include <asm/system.h>
69 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,17)
70 #include <linux/spinlock.h>
71 #else
72 #include <asm/spinlock.h>
73 #endif
74 #include <linux/delay.h>
75 #include <linux/signal.h>
76 #include <linux/sched.h>
77 #include <linux/errno.h>
78 #include <linux/pci.h>
79 #include <linux/string.h>
80 #include <linux/mm.h>
81 #include <linux/ioport.h>
82 #include <linux/time.h>
83 #include <linux/timer.h>
84 #include <linux/stat.h>
85 
86 #include <linux/blk.h>
87 
88 #ifdef __sparc__
89 #  include <asm/irq.h>
90 #endif
91 #include <linux/init.h>
92 
93 #ifndef	__init
94 #define	__init
95 #endif
96 #ifndef	__initdata
97 #define	__initdata
98 #endif
99 
100 #include "../scsi.h"
101 #include "../hosts.h"
102 #include "../constants.h"
103 #include "../sd.h"
104 
105 #include <linux/types.h>
106 
107 /*
108  *  Define BITS_PER_LONG for earlier linux versions.
109  */
110 #ifndef	BITS_PER_LONG
111 #if (~0UL) == 0xffffffffUL
112 #define	BITS_PER_LONG	32
113 #else
114 #define	BITS_PER_LONG	64
115 #endif
116 #endif
117 
118 typedef	u_long	vm_offset_t;
119 
120 #ifndef bcopy
121 #define bcopy(s, d, n)	memcpy((d), (s), (n))
122 #endif
123 
124 #ifndef bzero
125 #define bzero(d, n)	memset((d), 0, (n))
126 #endif
127 
128 #ifndef bcmp
129 #define bcmp(a, b, n)	memcmp((a), (b), (n))
130 #endif
131 
132 /*
133  *  General driver includes.
134  */
135 #include "sym53c8xx.h"
136 #include "sym_misc.h"
137 #include "sym_conf.h"
138 #include "sym_defs.h"
139 
140 /*
141  * Configuration addendum for Linux.
142  */
143 #if	LINUX_VERSION_CODE >= LinuxVersionCode(2,3,47)
144 #define	SYM_LINUX_DYNAMIC_DMA_MAPPING
145 #endif
146 
147 #define	SYM_CONF_TIMER_INTERVAL		((HZ+1)/2)
148 
149 #define SYM_OPT_HANDLE_DIR_UNKNOWN
150 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
151 #define SYM_OPT_NVRAM_PRE_READ
152 #define SYM_OPT_SNIFF_INQUIRY
153 #define SYM_OPT_LIMIT_COMMAND_REORDERING
154 #define	SYM_OPT_ANNOUNCE_TRANSFER_RATE
155 
156 #ifdef	SYM_LINUX_DYNAMIC_DMA_MAPPING
157 #define	SYM_OPT_BUS_DMA_ABSTRACTION
158 #endif
159 
160 /*
161  *  Print a message with severity.
162  */
163 #define printf_emerg(args...)	printk(KERN_EMERG args)
164 #define	printf_alert(args...)	printk(KERN_ALERT args)
165 #define	printf_crit(args...)	printk(KERN_CRIT args)
166 #define	printf_err(args...)	printk(KERN_ERR	args)
167 #define	printf_warning(args...)	printk(KERN_WARNING args)
168 #define	printf_notice(args...)	printk(KERN_NOTICE args)
169 #define	printf_info(args...)	printk(KERN_INFO args)
170 #define	printf_debug(args...)	printk(KERN_DEBUG args)
171 #define	printf(args...)		printk(args)
172 
173 /*
174  *  Insert a delay in micro-seconds and milli-seconds.
175  */
176 void sym_udelay(int us);
177 void sym_mdelay(int ms);
178 
179 /*
180  *  Let the compiler know about driver data structure names.
181  */
182 typedef struct sym_tcb *tcb_p;
183 typedef struct sym_lcb *lcb_p;
184 typedef struct sym_ccb *ccb_p;
185 typedef struct sym_hcb *hcb_p;
186 typedef struct sym_stcb *stcb_p;
187 typedef struct sym_slcb *slcb_p;
188 typedef struct sym_sccb *sccb_p;
189 typedef struct sym_shcb *shcb_p;
190 
191 /*
192  *  Define a reference to the O/S dependant IO request.
193  */
194 typedef Scsi_Cmnd *cam_ccb_p;	/* Generic */
195 typedef Scsi_Cmnd *cam_scsiio_p;/* SCSI I/O */
196 
197 
198 /*
199  *  IO functions definition for big/little endian CPU support.
200  *  For now, PCI chips are only supported in little endian addressing mode,
201  */
202 
203 #ifdef	__BIG_ENDIAN
204 
205 #define	inw_l2b		inw
206 #define	inl_l2b		inl
207 #define	outw_b2l	outw
208 #define	outl_b2l	outl
209 #define	readw_l2b	readw
210 #define	readl_l2b	readl
211 #define	writew_b2l	writew
212 #define	writel_b2l	writel
213 
214 #else	/* little endian */
215 
216 #if defined(__i386__)	/* i386 implements full FLAT memory/MMIO model */
217 #define	inw_raw		inw
218 #define	inl_raw		inl
219 #define	outw_raw	outw
220 #define	outl_raw	outl
221 #define readb_raw(a)	(*(volatile unsigned char *) (a))
222 #define readw_raw(a)	(*(volatile unsigned short *) (a))
223 #define readl_raw(a)	(*(volatile unsigned int *) (a))
224 #define writeb_raw(b,a)	((*(volatile unsigned char *) (a)) = (b))
225 #define writew_raw(b,a)	((*(volatile unsigned short *) (a)) = (b))
226 #define writel_raw(b,a)	((*(volatile unsigned int *) (a)) = (b))
227 
228 #else	/* Other little-endian */
229 #define	inw_raw		inw
230 #define	inl_raw		inl
231 #define	outw_raw	outw
232 #define	outl_raw	outl
233 #define	readw_raw	readw
234 #define	readl_raw	readl
235 #define	writew_raw	writew
236 #define	writel_raw	writel
237 
238 #endif
239 #endif
240 
241 #ifdef	SYM_CONF_CHIP_BIG_ENDIAN
242 #error	"Chips in BIG ENDIAN addressing mode are not (yet) supported"
243 #endif
244 
245 
246 /*
247  *  If the chip uses big endian addressing mode over the
248  *  PCI, actual io register addresses for byte and word
249  *  accesses must be changed according to lane routing.
250  *  Btw, sym_offb() and sym_offw() macros only apply to
251  *  constants and so donnot generate bloated code.
252  */
253 
254 #if	defined(SYM_CONF_CHIP_BIG_ENDIAN)
255 
256 #define sym_offb(o)	(((o)&~3)+((~((o)&3))&3))
257 #define sym_offw(o)	(((o)&~3)+((~((o)&3))&2))
258 
259 #else
260 
261 #define sym_offb(o)	(o)
262 #define sym_offw(o)	(o)
263 
264 #endif
265 
266 /*
267  *  If the CPU and the chip use same endian-ness adressing,
268  *  no byte reordering is needed for script patching.
269  *  Macro cpu_to_scr() is to be used for script patching.
270  *  Macro scr_to_cpu() is to be used for getting a DWORD
271  *  from the script.
272  */
273 
274 #if	defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
275 
276 #define cpu_to_scr(dw)	cpu_to_le32(dw)
277 #define scr_to_cpu(dw)	le32_to_cpu(dw)
278 
279 #elif	defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
280 
281 #define cpu_to_scr(dw)	cpu_to_be32(dw)
282 #define scr_to_cpu(dw)	be32_to_cpu(dw)
283 
284 #else
285 
286 #define cpu_to_scr(dw)	(dw)
287 #define scr_to_cpu(dw)	(dw)
288 
289 #endif
290 
291 /*
292  *  Access to the controller chip.
293  *
294  *  If SYM_CONF_IOMAPPED is defined, the driver will use
295  *  normal IOs instead of the MEMORY MAPPED IO method
296  *  recommended by PCI specifications.
297  *  If all PCI bridges, host brigdes and architectures
298  *  would have been correctly designed for PCI, this
299  *  option would be useless.
300  *
301  *  If the CPU and the chip use same endian-ness adressing,
302  *  no byte reordering is needed for accessing chip io
303  *  registers. Functions suffixed by '_raw' are assumed
304  *  to access the chip over the PCI without doing byte
305  *  reordering. Functions suffixed by '_l2b' are
306  *  assumed to perform little-endian to big-endian byte
307  *  reordering, those suffixed by '_b2l' blah, blah,
308  *  blah, ...
309  */
310 
311 #if defined(SYM_CONF_IOMAPPED)
312 
313 /*
314  *  IO mapped only input / ouput
315  */
316 
317 #define	INB_OFF(o)        inb (np->s.io_port + sym_offb(o))
318 #define	OUTB_OFF(o, val)  outb ((val), np->s.io_port + sym_offb(o))
319 
320 #if	defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
321 
322 #define	INW_OFF(o)        inw_l2b (np->s.io_port + sym_offw(o))
323 #define	INL_OFF(o)        inl_l2b (np->s.io_port + (o))
324 
325 #define	OUTW_OFF(o, val)  outw_b2l ((val), np->s.io_port + sym_offw(o))
326 #define	OUTL_OFF(o, val)  outl_b2l ((val), np->s.io_port + (o))
327 
328 #elif	defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
329 
330 #define	INW_OFF(o)        inw_b2l (np->s.io_port + sym_offw(o))
331 #define	INL_OFF(o)        inl_b2l (np->s.io_port + (o))
332 
333 #define	OUTW_OFF(o, val)  outw_l2b ((val), np->s.io_port + sym_offw(o))
334 #define	OUTL_OFF(o, val)  outl_l2b ((val), np->s.io_port + (o))
335 
336 #else
337 
338 #define	INW_OFF(o)        inw_raw (np->s.io_port + sym_offw(o))
339 #define	INL_OFF(o)        inl_raw (np->s.io_port + (o))
340 
341 #define	OUTW_OFF(o, val)  outw_raw ((val), np->s.io_port + sym_offw(o))
342 #define	OUTL_OFF(o, val)  outl_raw ((val), np->s.io_port + (o))
343 
344 #endif	/* ENDIANs */
345 
346 #else	/* defined SYM_CONF_IOMAPPED */
347 
348 /*
349  *  MEMORY mapped IO input / output
350  */
351 
352 #define INB_OFF(o)        readb((char *)np->s.mmio_va + sym_offb(o))
353 #define OUTB_OFF(o, val)  writeb((val), (char *)np->s.mmio_va + sym_offb(o))
354 
355 #if	defined(__BIG_ENDIAN) && !defined(SYM_CONF_CHIP_BIG_ENDIAN)
356 
357 #define INW_OFF(o)        readw_l2b((char *)np->s.mmio_va + sym_offw(o))
358 #define INL_OFF(o)        readl_l2b((char *)np->s.mmio_va + (o))
359 
360 #define OUTW_OFF(o, val)  writew_b2l((val), (char *)np->s.mmio_va + sym_offw(o))
361 #define OUTL_OFF(o, val)  writel_b2l((val), (char *)np->s.mmio_va + (o))
362 
363 #elif	defined(__LITTLE_ENDIAN) && defined(SYM_CONF_CHIP_BIG_ENDIAN)
364 
365 #define INW_OFF(o)        readw_b2l((char *)np->s.mmio_va + sym_offw(o))
366 #define INL_OFF(o)        readl_b2l((char *)np->s.mmio_va + (o))
367 
368 #define OUTW_OFF(o, val)  writew_l2b((val), (char *)np->s.mmio_va + sym_offw(o))
369 #define OUTL_OFF(o, val)  writel_l2b((val), (char *)np->s.mmio_va + (o))
370 
371 #else
372 
373 #define INW_OFF(o)        readw_raw((char *)np->s.mmio_va + sym_offw(o))
374 #define INL_OFF(o)        readl_raw((char *)np->s.mmio_va + (o))
375 
376 #define OUTW_OFF(o, val)  writew_raw((val), (char *)np->s.mmio_va + sym_offw(o))
377 #define OUTL_OFF(o, val)  writel_raw((val), (char *)np->s.mmio_va + (o))
378 
379 #endif
380 
381 #endif	/* defined SYM_CONF_IOMAPPED */
382 
383 #define OUTRAM_OFF(o, a, l) memcpy_toio(np->s.ram_va + (o), (a), (l))
384 
385 /*
386  *  Remap some status field values.
387  */
388 #define CAM_REQ_CMP		DID_OK
389 #define CAM_SEL_TIMEOUT		DID_NO_CONNECT
390 #define CAM_CMD_TIMEOUT		DID_TIME_OUT
391 #define CAM_REQ_ABORTED		DID_ABORT
392 #define CAM_UNCOR_PARITY	DID_PARITY
393 #define CAM_SCSI_BUS_RESET	DID_RESET
394 #define CAM_REQUEUE_REQ		DID_SOFT_ERROR
395 #define	CAM_UNEXP_BUSFREE	DID_ERROR
396 #define	CAM_SCSI_BUSY		DID_BUS_BUSY
397 
398 #define	CAM_DEV_NOT_THERE	DID_NO_CONNECT
399 #define	CAM_REQ_INVALID		DID_ERROR
400 #define	CAM_REQ_TOO_BIG		DID_ERROR
401 
402 #define	CAM_RESRC_UNAVAIL	DID_ERROR
403 
404 /*
405  *  Remap SCSI data direction values.
406  */
407 #ifndef	SCSI_DATA_UNKNOWN
408 #define	SCSI_DATA_UNKNOWN	0
409 #define	SCSI_DATA_WRITE		1
410 #define	SCSI_DATA_READ		2
411 #define	SCSI_DATA_NONE		3
412 #endif
413 #define CAM_DIR_NONE		SCSI_DATA_NONE
414 #define CAM_DIR_IN		SCSI_DATA_READ
415 #define CAM_DIR_OUT		SCSI_DATA_WRITE
416 #define CAM_DIR_UNKNOWN		SCSI_DATA_UNKNOWN
417 
418 /*
419  *  These ones are used as return code from
420  *  error recovery handlers under Linux.
421  */
422 #define SCSI_SUCCESS	SUCCESS
423 #define SCSI_FAILED	FAILED
424 
425 /*
426  *  System specific target data structure.
427  *  None for now, under Linux.
428  */
429 /* #define SYM_HAVE_STCB */
430 
431 /*
432  *  System specific lun data structure.
433  */
434 #define SYM_HAVE_SLCB
435 struct sym_slcb {
436 	u_short	reqtags;	/* Number of tags requested by user */
437 	u_short scdev_depth;	/* Queue depth set in select_queue_depth() */
438 };
439 
440 /*
441  *  System specific command data structure.
442  *  Not needed under Linux.
443  */
444 /* struct sym_sccb */
445 
446 /*
447  *  System specific host data structure.
448  */
449 struct sym_shcb {
450 	/*
451 	 *  Chip and controller indentification.
452 	 */
453 	int		unit;
454 	char		inst_name[16];
455 	char		chip_name[8];
456 	struct pci_dev	*device;
457 
458 	u_char		bus;		/* PCI BUS number		*/
459 	u_char		device_fn;	/* PCI BUS device and function	*/
460 
461 	spinlock_t	smp_lock;	/* Lock for SMP threading       */
462 
463 	vm_offset_t	mmio_va;	/* MMIO kernel virtual address	*/
464 	vm_offset_t	ram_va;		/* RAM  kernel virtual address	*/
465 	u_long		io_port;	/* IO port address cookie	*/
466 	u_short		io_ws;		/* IO window size		*/
467 	int		irq;		/* IRQ number			*/
468 
469 	SYM_QUEHEAD	wait_cmdq;	/* Awaiting SCSI commands	*/
470 	SYM_QUEHEAD	busy_cmdq;	/* Enqueued SCSI commands	*/
471 
472 	struct timer_list timer;	/* Timer handler link header	*/
473 	u_long		lasttime;
474 	u_long		settle_time;	/* Resetting the SCSI BUS	*/
475 	u_char		settle_time_valid;
476 #if LINUX_VERSION_CODE < LinuxVersionCode(2, 4, 0)
477 	u_char		release_stage;	/* Synchronisation on release	*/
478 #endif
479 };
480 
481 /*
482  *  Return the name of the controller.
483  */
484 #define sym_name(np) (np)->s.inst_name
485 
486 /*
487  *  Data structure used as input for the NVRAM reading.
488  *  Must resolve the IO macros and sym_name(), when
489  *  used as sub-field 's' of another structure.
490  */
491 typedef struct {
492 	int	bus;
493 	u_char	device_fn;
494 	u_long	base;
495 	u_long	base_2;
496 	u_long	base_c;
497 	u_long	base_2_c;
498 	int	irq;
499 /* port and address fields to fit INB, OUTB macros */
500 	u_long	io_port;
501 	vm_offset_t mmio_va;
502 	char	inst_name[16];
503 } sym_slot;
504 
505 typedef struct sym_nvram sym_nvram;
506 typedef struct sym_pci_chip sym_chip;
507 
508 typedef struct {
509 	struct pci_dev *pdev;
510 	sym_slot  s;
511 	sym_chip  chip;
512 	sym_nvram *nvram;
513 	u_short device_id;
514 	u_char host_id;
515 #ifdef	SYM_CONF_PQS_PDS_SUPPORT
516 	u_char pqs_pds;
517 #endif
518 	int attach_done;
519 } sym_device;
520 
521 typedef sym_device *sdev_p;
522 
523 /*
524  *  The driver definitions (sym_hipd.h) must know about a
525  *  couple of things related to the memory allocator.
526  */
527 typedef u_long m_addr_t;	/* Enough bits to represent any address */
528 #define SYM_MEM_PAGE_ORDER 0	/* 1 PAGE  maximum */
529 #define SYM_MEM_CLUSTER_SHIFT	(PAGE_SHIFT+SYM_MEM_PAGE_ORDER)
530 #ifdef	MODULE
531 #define SYM_MEM_FREE_UNUSED	/* Free unused pages immediately */
532 #endif
533 #ifdef	SYM_LINUX_DYNAMIC_DMA_MAPPING
534 typedef struct pci_dev *m_pool_ident_t;
535 #endif
536 
537 /*
538  *  Include driver soft definitions.
539  */
540 #include "sym_fw.h"
541 #include "sym_hipd.h"
542 
543 /*
544  *  Memory allocator related stuff.
545  */
546 
547 #define SYM_MEM_GFP_FLAGS	GFP_ATOMIC
548 #define SYM_MEM_WARN	1	/* Warn on failed operations */
549 
550 #define sym_get_mem_cluster()	\
551 	__get_free_pages(SYM_MEM_GFP_FLAGS, SYM_MEM_PAGE_ORDER)
552 #define sym_free_mem_cluster(p)	\
553 	free_pages(p, SYM_MEM_PAGE_ORDER)
554 
555 void *sym_calloc(int size, char *name);
556 void sym_mfree(void *m, int size, char *name);
557 
558 #ifndef	SYM_LINUX_DYNAMIC_DMA_MAPPING
559 /*
560  *  Simple case.
561  *  All the memory assummed DMAable and O/S providing virtual
562  *  to bus physical address translation.
563  */
564 #define __sym_calloc_dma(pool_id, size, name)	sym_calloc(size, name)
565 #define __sym_mfree_dma(pool_id, m, size, name)	sym_mfree(m, size, name)
566 #define __vtobus(b, p)				virt_to_bus(p)
567 
568 #else	/* SYM_LINUX_DYNAMIC_DMA_MAPPING */
569 /*
570  *  Complex case.
571  *  We have to provide the driver memory allocator with methods for
572  *  it to maintain virtual to bus physical address translations.
573  */
574 
575 #define sym_m_pool_match(mp_id1, mp_id2)	(mp_id1 == mp_id2)
576 
sym_m_get_dma_mem_cluster(m_pool_p mp,m_vtob_p vbp)577 static __inline m_addr_t sym_m_get_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
578 {
579 	void *vaddr = 0;
580 	dma_addr_t baddr = 0;
581 
582 	vaddr = pci_alloc_consistent(mp->dev_dmat,SYM_MEM_CLUSTER_SIZE, &baddr);
583 	if (vaddr) {
584 		vbp->vaddr = (m_addr_t) vaddr;
585 		vbp->baddr = (m_addr_t) baddr;
586 	}
587 	return (m_addr_t) vaddr;
588 }
589 
sym_m_free_dma_mem_cluster(m_pool_p mp,m_vtob_p vbp)590 static __inline void sym_m_free_dma_mem_cluster(m_pool_p mp, m_vtob_p vbp)
591 {
592 	pci_free_consistent(mp->dev_dmat, SYM_MEM_CLUSTER_SIZE,
593 	                    (void *)vbp->vaddr, (dma_addr_t)vbp->baddr);
594 }
595 
596 #define sym_m_create_dma_mem_tag(mp)	(0)
597 
598 #define sym_m_delete_dma_mem_tag(mp)	do { ; } while (0)
599 
600 void *__sym_calloc_dma(m_pool_ident_t dev_dmat, int size, char *name);
601 void __sym_mfree_dma(m_pool_ident_t dev_dmat, void *m, int size, char *name);
602 m_addr_t __vtobus(m_pool_ident_t dev_dmat, void *m);
603 
604 #endif	/* SYM_LINUX_DYNAMIC_DMA_MAPPING */
605 
606 /*
607  *  Set the status field of a CAM CCB.
608  */
609 static __inline void
sym_set_cam_status(Scsi_Cmnd * ccb,int status)610 sym_set_cam_status(Scsi_Cmnd  *ccb, int status)
611 {
612 	ccb->result &= ~(0xff  << 16);
613 	ccb->result |= (status << 16);
614 }
615 
616 /*
617  *  Get the status field of a CAM CCB.
618  */
619 static __inline int
sym_get_cam_status(Scsi_Cmnd * ccb)620 sym_get_cam_status(Scsi_Cmnd  *ccb)
621 {
622 	return ((ccb->result >> 16) & 0xff);
623 }
624 
625 /*
626  *  The dma mapping is mostly handled by the
627  *  SCSI layer and the driver glue under Linux.
628  */
629 #define sym_data_dmamap_create(np, cp)		(0)
630 #define sym_data_dmamap_destroy(np, cp)		do { ; } while (0)
631 #define sym_data_dmamap_unload(np, cp)		do { ; } while (0)
632 #define sym_data_dmamap_presync(np, cp)		do { ; } while (0)
633 #define sym_data_dmamap_postsync(np, cp)	do { ; } while (0)
634 
635 /*
636  *  Async handler for negotiations.
637  */
638 void sym_xpt_async_nego_wide(hcb_p np, int target);
639 #define sym_xpt_async_nego_sync(np, target)	\
640 	sym_announce_transfer_rate(np, target)
641 #define sym_xpt_async_nego_ppr(np, target)	\
642 	sym_announce_transfer_rate(np, target)
643 
644 /*
645  *  Build CAM result for a successful IO and for a failed IO.
646  */
sym_set_cam_result_ok(hcb_p np,ccb_p cp,int resid)647 static __inline void sym_set_cam_result_ok(hcb_p np, ccb_p cp, int resid)
648 {
649 	Scsi_Cmnd *cmd = cp->cam_ccb;
650 
651 #if LINUX_VERSION_CODE >= LinuxVersionCode(2,3,99)
652 	cmd->resid = resid;
653 #endif
654 	cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
655 }
656 void sym_set_cam_result_error(hcb_p np, ccb_p cp, int resid);
657 
658 /*
659  *  Other O/S specific methods.
660  */
661 #define sym_cam_target_id(ccb)	(ccb)->target
662 #define sym_cam_target_lun(ccb)	(ccb)->lun
663 #define	sym_freeze_cam_ccb(ccb)	do { ; } while (0)
664 void sym_xpt_done(hcb_p np, cam_ccb_p ccb);
665 void sym_xpt_done2(hcb_p np, cam_ccb_p ccb, int cam_status);
666 void sym_print_addr (ccb_p cp);
667 void sym_xpt_async_bus_reset(hcb_p np);
668 void sym_xpt_async_sent_bdr(hcb_p np, int target);
669 int  sym_setup_data_and_start (hcb_p np, cam_scsiio_p csio, ccb_p cp);
670 void sym_log_bus_error(hcb_p np);
671 #ifdef	SYM_OPT_SNIFF_INQUIRY
672 void sym_sniff_inquiry(hcb_p np, Scsi_Cmnd *cmd, int resid);
673 #endif
674 
675 #endif /* SYM_GLUE_H */
676