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
43 #include <linux/completion.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>
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"
67 * Configuration addendum for Linux.
69 #define SYM_CONF_TIMER_INTERVAL ((HZ+1)/2)
71 #undef SYM_OPT_HANDLE_DEVICE_QUEUEING
72 #define SYM_OPT_LIMIT_COMMAND_REORDERING
75 * Print a message with severity.
77 #define printf_emerg(args...) printk(KERN_EMERG args)
78 #define printf_alert(args...) printk(KERN_ALERT args)
79 #define printf_crit(args...) printk(KERN_CRIT args)
80 #define printf_err(args...) printk(KERN_ERR args)
81 #define printf_warning(args...) printk(KERN_WARNING args)
82 #define printf_notice(args...) printk(KERN_NOTICE args)
83 #define printf_info(args...) printk(KERN_INFO args)
84 #define printf_debug(args...) printk(KERN_DEBUG args)
85 #define printf(args...) printk(args)
88 * A 'read barrier' flushes any data that have been prefetched
89 * by the processor due to out of order execution. Such a barrier
90 * must notably be inserted prior to looking at data that have
91 * been DMAed, assuming that program does memory READs in proper
92 * order and that the device ensured proper ordering of WRITEs.
94 * A 'write barrier' prevents any previous WRITEs to pass further
95 * WRITEs. Such barriers must be inserted each time another agent
96 * relies on ordering of WRITEs.
98 * Note that, due to posting of PCI memory writes, we also must
99 * insert dummy PCI read transactions when some ordering involving
100 * both directions over the PCI does matter. PCI transactions are
101 * fully ordered in each direction.
104 #define MEMORY_READ_BARRIER() rmb()
105 #define MEMORY_WRITE_BARRIER() wmb()
108 * IO functions definition for big/little endian CPU support.
109 * For now, PCI chips are only supported in little endian addressing mode,
114 #define readw_l2b readw
115 #define readl_l2b readl
116 #define writew_b2l writew
117 #define writel_b2l writel
119 #else /* little endian */
121 #define readw_raw readw
122 #define readl_raw readl
123 #define writew_raw writew
124 #define writel_raw writel
128 #ifdef SYM_CONF_CHIP_BIG_ENDIAN
129 #error "Chips in BIG ENDIAN addressing mode are not (yet) supported"
133 * If the CPU and the chip use same endian-ness addressing,
134 * no byte reordering is needed for script patching.
135 * Macro cpu_to_scr() is to be used for script patching.
136 * Macro scr_to_cpu() is to be used for getting a DWORD
140 #define cpu_to_scr(dw) cpu_to_le32(dw)
141 #define scr_to_cpu(dw) le32_to_cpu(dw)
144 * These ones are used as return code from
145 * error recovery handlers under Linux.
147 #define SCSI_SUCCESS SUCCESS
148 #define SCSI_FAILED FAILED
151 * System specific target data structure.
152 * None for now, under Linux.
154 /* #define SYM_HAVE_STCB */
157 * System specific lun data structure.
159 #define SYM_HAVE_SLCB
161 u_short reqtags; /* Number of tags requested by user */
162 u_short scdev_depth; /* Queue depth set in select_queue_depth() */
166 * System specific command data structure.
167 * Not needed under Linux.
169 /* struct sym_sccb */
172 * System specific host data structure.
176 * Chip and controller indentification.
181 struct pci_dev *device;
183 struct Scsi_Host *host;
185 void __iomem * ioaddr; /* MMIO kernel io address */
186 void __iomem * ramaddr; /* RAM kernel io address */
187 u_short io_ws; /* IO window size */
189 struct timer_list timer; /* Timer handler link header */
191 u_long settle_time; /* Resetting the SCSI BUS */
192 u_char settle_time_valid;
196 * Return the name of the controller.
198 #define sym_name(np) (np)->s.inst_name
203 * The IO macros require a struct called 's' and are abused in sym_nvram.c
206 struct pci_dev *pdev;
207 unsigned long mmio_base;
208 unsigned long ram_base;
210 void __iomem *ioaddr;
211 void __iomem *ramaddr;
213 struct sym_chip chip;
214 struct sym_nvram *nvram;
220 * Driver host data structure.
224 struct completion *io_reset; /* PCI error handling */
227 static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
229 return ((struct host_data *)host->hostdata)->ncb;
233 #include "sym_hipd.h"
236 * Set the status field of a CAM CCB.
239 sym_set_cam_status(struct scsi_cmnd *cmd, int status)
241 cmd->result &= ~(0xff << 16);
242 cmd->result |= (status << 16);
246 * Get the status field of a CAM CCB.
249 sym_get_cam_status(struct scsi_cmnd *cmd)
251 return host_byte(cmd->result);
255 * Build CAM result for a successful IO and for a failed IO.
257 static __inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
259 scsi_set_resid(cmd, resid);
260 cmd->result = (((DID_OK) << 16) + ((cp->ssss_status) & 0x7f));
262 void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
264 void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
265 #define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
266 void sym_xpt_async_bus_reset(struct sym_hcb *np);
267 void sym_xpt_async_sent_bdr(struct sym_hcb *np, int target);
268 int sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
269 void sym_log_bus_error(struct sym_hcb *np);
270 void sym_dump_registers(struct sym_hcb *np);
272 #endif /* SYM_GLUE_H */