Linux-2.6.12-rc2
[linux-2.6/kvm.git] / drivers / scsi / sym53c8xx_2 / sym_glue.h
blobe943f167fb5108346f3f9eb7f8398468a3c3a138
1 /*
2 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
3 * of PCI-SCSI IO processors.
5 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
7 * This driver is derived from the Linux sym53c8xx driver.
8 * Copyright (C) 1998-2000 Gerard Roudier
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.
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
18 * Other major contributions:
20 * NVRAM detection and reading.
21 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23 *-----------------------------------------------------------------------------
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.
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.
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
40 #ifndef SYM_GLUE_H
41 #define SYM_GLUE_H
43 #include <linux/config.h>
44 #include <linux/delay.h>
45 #include <linux/ioport.h>
46 #include <linux/pci.h>
47 #include <linux/string.h>
48 #include <linux/timer.h>
49 #include <linux/types.h>
51 #include <asm/io.h>
52 #ifdef __sparc__
53 # include <asm/irq.h>
54 #endif
56 #include <scsi/scsi.h>
57 #include <scsi/scsi_cmnd.h>
58 #include <scsi/scsi_device.h>
59 #include <scsi/scsi_transport_spi.h>
60 #include <scsi/scsi_host.h>
62 #include "sym53c8xx.h"
63 #include "sym_defs.h"
64 #include "sym_misc.h"
67 * Configuration addendum for Linux.
69 #define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
71 #define SYM_OPT_HANDLE_DIR_UNKNOWN
72 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
73 #define SYM_OPT_LIMIT_COMMAND_REORDERING
76 * Print a message with severity.
78 #define printf_emerg(args...) printk(KERN_EMERG args)
79 #define printf_alert(args...) printk(KERN_ALERT args)
80 #define printf_crit(args...) printk(KERN_CRIT args)
81 #define printf_err(args...) printk(KERN_ERR args)
82 #define printf_warning(args...) printk(KERN_WARNING args)
83 #define printf_notice(args...) printk(KERN_NOTICE args)
84 #define printf_info(args...) printk(KERN_INFO args)
85 #define printf_debug(args...) printk(KERN_DEBUG args)
86 #define printf(args...) printk(args)
89 * A 'read barrier' flushes any data that have been prefetched
90 * by the processor due to out of order execution. Such a barrier
91 * must notably be inserted prior to looking at data that have
92 * been DMAed, assuming that program does memory READs in proper
93 * order and that the device ensured proper ordering of WRITEs.
95 * A 'write barrier' prevents any previous WRITEs to pass further
96 * WRITEs. Such barriers must be inserted each time another agent
97 * relies on ordering of WRITEs.
99 * Note that, due to posting of PCI memory writes, we also must
100 * insert dummy PCI read transactions when some ordering involving
101 * both directions over the PCI does matter. PCI transactions are
102 * fully ordered in each direction.
105 #define MEMORY_READ_BARRIER() rmb()
106 #define MEMORY_WRITE_BARRIER() wmb()
109 * IO functions definition for big/little endian CPU support.
110 * For now, PCI chips are only supported in little endian addressing mode,
113 #ifdef __BIG_ENDIAN
115 #define readw_l2b readw
116 #define readl_l2b readl
117 #define writew_b2l writew
118 #define writel_b2l writel
120 #else /* little endian */
122 #define readw_raw readw
123 #define readl_raw readl
124 #define writew_raw writew
125 #define writel_raw writel
127 #endif /* endian */
129 #ifdef SYM_CONF_CHIP_BIG_ENDIAN
130 #error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
131 #endif
134 * If the CPU and the chip use same endian-ness addressing,
135 * no byte reordering is needed for script patching.
136 * Macro cpu_to_scr() is to be used for script patching.
137 * Macro scr_to_cpu() is to be used for getting a DWORD
138 * from the script.
141 #define cpu_to_scr(dw) cpu_to_le32(dw)
142 #define scr_to_cpu(dw) le32_to_cpu(dw)
145 * Remap some status field values.
147 #define CAM_REQ_CMP DID_OK
148 #define CAM_SEL_TIMEOUT DID_NO_CONNECT
149 #define CAM_CMD_TIMEOUT DID_TIME_OUT
150 #define CAM_REQ_ABORTED DID_ABORT
151 #define CAM_UNCOR_PARITY DID_PARITY
152 #define CAM_SCSI_BUS_RESET DID_RESET
153 #define CAM_REQUEUE_REQ DID_SOFT_ERROR
154 #define CAM_UNEXP_BUSFREE DID_ERROR
155 #define CAM_SCSI_BUSY DID_BUS_BUSY
157 #define CAM_DEV_NOT_THERE DID_NO_CONNECT
158 #define CAM_REQ_INVALID DID_ERROR
159 #define CAM_REQ_TOO_BIG DID_ERROR
161 #define CAM_RESRC_UNAVAIL DID_ERROR
164 * Remap data direction values.
166 #define CAM_DIR_NONE DMA_NONE
167 #define CAM_DIR_IN DMA_FROM_DEVICE
168 #define CAM_DIR_OUT DMA_TO_DEVICE
169 #define CAM_DIR_UNKNOWN DMA_BIDIRECTIONAL
172 * These ones are used as return code from
173 * error recovery handlers under Linux.
175 #define SCSI_SUCCESS SUCCESS
176 #define SCSI_FAILED FAILED
179 * System specific target data structure.
180 * None for now, under Linux.
182 /* #define SYM_HAVE_STCB */
185 * System specific lun data structure.
187 #define SYM_HAVE_SLCB
188 struct sym_slcb {
189 u_short reqtags; /* Number of tags requested by user */
190 u_short scdev_depth; /* Queue depth set in select_queue_depth() */
194 * System specific command data structure.
195 * Not needed under Linux.
197 /* struct sym_sccb */
200 * System specific host data structure.
202 struct sym_shcb {
204 * Chip and controller indentification.
206 int unit;
207 char inst_name[16];
208 char chip_name[8];
209 struct pci_dev *device;
211 struct Scsi_Host *host;
213 void __iomem * ioaddr; /* MMIO kernel io address */
214 void __iomem * ramaddr; /* RAM kernel io address */
215 u_short io_ws; /* IO window size */
216 int irq; /* IRQ number */
218 struct timer_list timer; /* Timer handler link header */
219 u_long lasttime;
220 u_long settle_time; /* Resetting the SCSI BUS */
221 u_char settle_time_valid;
225 * Return the name of the controller.
227 #define sym_name(np) (np)->s.inst_name
229 struct sym_nvram;
232 * The IO macros require a struct called 's' and are abused in sym_nvram.c
234 struct sym_device {
235 struct pci_dev *pdev;
236 unsigned long mmio_base;
237 unsigned long ram_base;
238 struct {
239 void __iomem *ioaddr;
240 void __iomem *ramaddr;
241 } s;
242 struct sym_chip chip;
243 struct sym_nvram *nvram;
244 u_short device_id;
245 u_char host_id;
249 * Driver host data structure.
251 struct host_data {
252 struct sym_hcb *ncb;
255 static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
257 return ((struct host_data *)host->hostdata)->ncb;
260 #include "sym_fw.h"
261 #include "sym_hipd.h"
264 * Set the status field of a CAM CCB.
266 static __inline void
267 sym_set_cam_status(struct scsi_cmnd *cmd, int status)
269 cmd->result &= ~(0xff << 16);
270 cmd->result |= (status << 16);
274 * Get the status field of a CAM CCB.
276 static __inline int
277 sym_get_cam_status(struct scsi_cmnd *cmd)
279 return host_byte(cmd->result);
283 * Build CAM result for a successful IO and for a failed IO.
285 static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
287 cmd->resid = resid;
288 cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
290 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
292 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
293 #define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
294 void sym_xpt_async_bus_reset(struct sym_hcb *np);
295 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target);
296 int sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
297 void sym_log_bus_error(struct sym_hcb *np);
298 void sym_sniff_inquiry(struct sym_hcb *np, struct scsi_cmnd *cmd, int resid);
300 #endif /* SYM_GLUE_H */