Linux-2.6.12-rc2
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / sym53c8xx_2 / sym_glue.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_GLUE_H
41 #define SYM_GLUE_H
42
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>
50
51 #include <asm/io.h>
52 #ifdef __sparc__
53 # include <asm/irq.h>
54 #endif
55
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>
61
62 #include "sym53c8xx.h"
63 #include "sym_defs.h"
64 #include "sym_misc.h"
65
66 /*
67 * Configuration addendum for Linux.
68 */
69 #define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
70
71 #define SYM_OPT_HANDLE_DIR_UNKNOWN
72 #define SYM_OPT_HANDLE_DEVICE_QUEUEING
73 #define SYM_OPT_LIMIT_COMMAND_REORDERING
74
75 /*
76 * Print a message with severity.
77 */
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)
87
88 /*
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.
94 *
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.
98 *
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.
103 */
104
105 #define MEMORY_READ_BARRIER() rmb()
106 #define MEMORY_WRITE_BARRIER() wmb()
107
108 /*
109 * IO functions definition for big/little endian CPU support.
110 * For now, PCI chips are only supported in little endian addressing mode,
111 */
112
113 #ifdef __BIG_ENDIAN
114
115 #define readw_l2b readw
116 #define readl_l2b readl
117 #define writew_b2l writew
118 #define writel_b2l writel
119
120 #else /* little endian */
121
122 #define readw_raw readw
123 #define readl_raw readl
124 #define writew_raw writew
125 #define writel_raw writel
126
127 #endif /* endian */
128
129 #ifdef SYM_CONF_CHIP_BIG_ENDIAN
130 #error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
131 #endif
132
133 /*
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.
139 */
140
141 #define cpu_to_scr(dw) cpu_to_le32(dw)
142 #define scr_to_cpu(dw) le32_to_cpu(dw)
143
144 /*
145 * Remap some status field values.
146 */
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
156
157 #define CAM_DEV_NOT_THERE DID_NO_CONNECT
158 #define CAM_REQ_INVALID DID_ERROR
159 #define CAM_REQ_TOO_BIG DID_ERROR
160
161 #define CAM_RESRC_UNAVAIL DID_ERROR
162
163 /*
164 * Remap data direction values.
165 */
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
170
171 /*
172 * These ones are used as return code from
173 * error recovery handlers under Linux.
174 */
175 #define SCSI_SUCCESS SUCCESS
176 #define SCSI_FAILED FAILED
177
178 /*
179 * System specific target data structure.
180 * None for now, under Linux.
181 */
182 /* #define SYM_HAVE_STCB */
183
184 /*
185 * System specific lun data structure.
186 */
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() */
191 };
192
193 /*
194 * System specific command data structure.
195 * Not needed under Linux.
196 */
197 /* struct sym_sccb */
198
199 /*
200 * System specific host data structure.
201 */
202 struct sym_shcb {
203 /*
204 * Chip and controller indentification.
205 */
206 int unit;
207 char inst_name[16];
208 char chip_name[8];
209 struct pci_dev *device;
210
211 struct Scsi_Host *host;
212
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 */
217
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;
222 };
223
224 /*
225 * Return the name of the controller.
226 */
227 #define sym_name(np) (np)->s.inst_name
228
229 struct sym_nvram;
230
231 /*
232 * The IO macros require a struct called 's' and are abused in sym_nvram.c
233 */
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;
246 };
247
248 /*
249 * Driver host data structure.
250 */
251 struct host_data {
252 struct sym_hcb *ncb;
253 };
254
255 static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
256 {
257 return ((struct host_data *)host->hostdata)->ncb;
258 }
259
260 #include "sym_fw.h"
261 #include "sym_hipd.h"
262
263 /*
264 * Set the status field of a CAM CCB.
265 */
266 static __inline void
267 sym_set_cam_status(struct scsi_cmnd *cmd, int status)
268 {
269 cmd->result &= ~(0xff << 16);
270 cmd->result |= (status << 16);
271 }
272
273 /*
274 * Get the status field of a CAM CCB.
275 */
276 static __inline int
277 sym_get_cam_status(struct scsi_cmnd *cmd)
278 {
279 return host_byte(cmd->result);
280 }
281
282 /*
283 * Build CAM result for a successful IO and for a failed IO.
284 */
285 static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
286 {
287 cmd->resid = resid;
288 cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
289 }
290 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
291
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);
299
300 #endif /* SYM_GLUE_H */