xref: /OK3568_Linux_fs/kernel/drivers/scsi/sym53c8xx_2/sym_glue.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-or-later */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
4*4882a593Smuzhiyun  * of PCI-SCSI IO processors.
5*4882a593Smuzhiyun  *
6*4882a593Smuzhiyun  * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
7*4882a593Smuzhiyun  *
8*4882a593Smuzhiyun  * This driver is derived from the Linux sym53c8xx driver.
9*4882a593Smuzhiyun  * Copyright (C) 1998-2000  Gerard Roudier
10*4882a593Smuzhiyun  *
11*4882a593Smuzhiyun  * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12*4882a593Smuzhiyun  * a port of the FreeBSD ncr driver to Linux-1.2.13.
13*4882a593Smuzhiyun  *
14*4882a593Smuzhiyun  * The original ncr driver has been written for 386bsd and FreeBSD by
15*4882a593Smuzhiyun  *         Wolfgang Stanglmeier        <wolf@cologne.de>
16*4882a593Smuzhiyun  *         Stefan Esser                <se@mi.Uni-Koeln.de>
17*4882a593Smuzhiyun  * Copyright (C) 1994  Wolfgang Stanglmeier
18*4882a593Smuzhiyun  *
19*4882a593Smuzhiyun  * Other major contributions:
20*4882a593Smuzhiyun  *
21*4882a593Smuzhiyun  * NVRAM detection and reading.
22*4882a593Smuzhiyun  * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
23*4882a593Smuzhiyun  *
24*4882a593Smuzhiyun  *-----------------------------------------------------------------------------
25*4882a593Smuzhiyun  */
26*4882a593Smuzhiyun 
27*4882a593Smuzhiyun #ifndef SYM_GLUE_H
28*4882a593Smuzhiyun #define SYM_GLUE_H
29*4882a593Smuzhiyun 
30*4882a593Smuzhiyun #include <linux/completion.h>
31*4882a593Smuzhiyun #include <linux/delay.h>
32*4882a593Smuzhiyun #include <linux/interrupt.h>
33*4882a593Smuzhiyun #include <linux/ioport.h>
34*4882a593Smuzhiyun #include <linux/pci.h>
35*4882a593Smuzhiyun #include <linux/string.h>
36*4882a593Smuzhiyun #include <linux/timer.h>
37*4882a593Smuzhiyun #include <linux/types.h>
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun #include <asm/io.h>
40*4882a593Smuzhiyun #ifdef __sparc__
41*4882a593Smuzhiyun #  include <asm/irq.h>
42*4882a593Smuzhiyun #endif
43*4882a593Smuzhiyun 
44*4882a593Smuzhiyun #include <scsi/scsi.h>
45*4882a593Smuzhiyun #include <scsi/scsi_cmnd.h>
46*4882a593Smuzhiyun #include <scsi/scsi_device.h>
47*4882a593Smuzhiyun #include <scsi/scsi_transport_spi.h>
48*4882a593Smuzhiyun #include <scsi/scsi_host.h>
49*4882a593Smuzhiyun 
50*4882a593Smuzhiyun #include "sym53c8xx.h"
51*4882a593Smuzhiyun #include "sym_defs.h"
52*4882a593Smuzhiyun #include "sym_misc.h"
53*4882a593Smuzhiyun 
54*4882a593Smuzhiyun /*
55*4882a593Smuzhiyun  * Configuration addendum for Linux.
56*4882a593Smuzhiyun  */
57*4882a593Smuzhiyun #define	SYM_CONF_TIMER_INTERVAL		((HZ+1)/2)
58*4882a593Smuzhiyun 
59*4882a593Smuzhiyun #undef SYM_OPT_HANDLE_DEVICE_QUEUEING
60*4882a593Smuzhiyun #define SYM_OPT_LIMIT_COMMAND_REORDERING
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun  *  Print a message with severity.
64*4882a593Smuzhiyun  */
65*4882a593Smuzhiyun #define printf_emerg(args...)	printk(KERN_EMERG args)
66*4882a593Smuzhiyun #define	printf_alert(args...)	printk(KERN_ALERT args)
67*4882a593Smuzhiyun #define	printf_crit(args...)	printk(KERN_CRIT args)
68*4882a593Smuzhiyun #define	printf_err(args...)	printk(KERN_ERR	args)
69*4882a593Smuzhiyun #define	printf_warning(args...)	printk(KERN_WARNING args)
70*4882a593Smuzhiyun #define	printf_notice(args...)	printk(KERN_NOTICE args)
71*4882a593Smuzhiyun #define	printf_info(args...)	printk(KERN_INFO args)
72*4882a593Smuzhiyun #define	printf_debug(args...)	printk(KERN_DEBUG args)
73*4882a593Smuzhiyun #define	printf(args...)		printk(args)
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun  *  A 'read barrier' flushes any data that have been prefetched
77*4882a593Smuzhiyun  *  by the processor due to out of order execution. Such a barrier
78*4882a593Smuzhiyun  *  must notably be inserted prior to looking at data that have
79*4882a593Smuzhiyun  *  been DMAed, assuming that program does memory READs in proper
80*4882a593Smuzhiyun  *  order and that the device ensured proper ordering of WRITEs.
81*4882a593Smuzhiyun  *
82*4882a593Smuzhiyun  *  A 'write barrier' prevents any previous WRITEs to pass further
83*4882a593Smuzhiyun  *  WRITEs. Such barriers must be inserted each time another agent
84*4882a593Smuzhiyun  *  relies on ordering of WRITEs.
85*4882a593Smuzhiyun  *
86*4882a593Smuzhiyun  *  Note that, due to posting of PCI memory writes, we also must
87*4882a593Smuzhiyun  *  insert dummy PCI read transactions when some ordering involving
88*4882a593Smuzhiyun  *  both directions over the PCI does matter. PCI transactions are
89*4882a593Smuzhiyun  *  fully ordered in each direction.
90*4882a593Smuzhiyun  */
91*4882a593Smuzhiyun 
92*4882a593Smuzhiyun #define MEMORY_READ_BARRIER()	rmb()
93*4882a593Smuzhiyun #define MEMORY_WRITE_BARRIER()	wmb()
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun  *  IO functions definition for big/little endian CPU support.
97*4882a593Smuzhiyun  *  For now, PCI chips are only supported in little endian addressing mode,
98*4882a593Smuzhiyun  */
99*4882a593Smuzhiyun 
100*4882a593Smuzhiyun #ifdef	__BIG_ENDIAN
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun #define	readw_l2b	readw
103*4882a593Smuzhiyun #define	readl_l2b	readl
104*4882a593Smuzhiyun #define	writew_b2l	writew
105*4882a593Smuzhiyun #define	writel_b2l	writel
106*4882a593Smuzhiyun 
107*4882a593Smuzhiyun #else	/* little endian */
108*4882a593Smuzhiyun 
109*4882a593Smuzhiyun #define	readw_raw	readw
110*4882a593Smuzhiyun #define	readl_raw	readl
111*4882a593Smuzhiyun #define	writew_raw	writew
112*4882a593Smuzhiyun #define	writel_raw	writel
113*4882a593Smuzhiyun 
114*4882a593Smuzhiyun #endif /* endian */
115*4882a593Smuzhiyun 
116*4882a593Smuzhiyun #ifdef	SYM_CONF_CHIP_BIG_ENDIAN
117*4882a593Smuzhiyun #error	"Chips in BIG ENDIAN addressing mode are not (yet) supported"
118*4882a593Smuzhiyun #endif
119*4882a593Smuzhiyun 
120*4882a593Smuzhiyun /*
121*4882a593Smuzhiyun  *  If the CPU and the chip use same endian-ness addressing,
122*4882a593Smuzhiyun  *  no byte reordering is needed for script patching.
123*4882a593Smuzhiyun  *  Macro cpu_to_scr() is to be used for script patching.
124*4882a593Smuzhiyun  *  Macro scr_to_cpu() is to be used for getting a DWORD
125*4882a593Smuzhiyun  *  from the script.
126*4882a593Smuzhiyun  */
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun #define cpu_to_scr(dw)	cpu_to_le32(dw)
129*4882a593Smuzhiyun #define scr_to_cpu(dw)	le32_to_cpu(dw)
130*4882a593Smuzhiyun 
131*4882a593Smuzhiyun /*
132*4882a593Smuzhiyun  *  These ones are used as return code from
133*4882a593Smuzhiyun  *  error recovery handlers under Linux.
134*4882a593Smuzhiyun  */
135*4882a593Smuzhiyun #define SCSI_SUCCESS	SUCCESS
136*4882a593Smuzhiyun #define SCSI_FAILED	FAILED
137*4882a593Smuzhiyun 
138*4882a593Smuzhiyun /*
139*4882a593Smuzhiyun  *  System specific target data structure.
140*4882a593Smuzhiyun  *  None for now, under Linux.
141*4882a593Smuzhiyun  */
142*4882a593Smuzhiyun /* #define SYM_HAVE_STCB */
143*4882a593Smuzhiyun 
144*4882a593Smuzhiyun /*
145*4882a593Smuzhiyun  *  System specific lun data structure.
146*4882a593Smuzhiyun  */
147*4882a593Smuzhiyun #define SYM_HAVE_SLCB
148*4882a593Smuzhiyun struct sym_slcb {
149*4882a593Smuzhiyun 	u_short	reqtags;	/* Number of tags requested by user */
150*4882a593Smuzhiyun 	u_short scdev_depth;	/* Queue depth set in select_queue_depth() */
151*4882a593Smuzhiyun };
152*4882a593Smuzhiyun 
153*4882a593Smuzhiyun /*
154*4882a593Smuzhiyun  *  System specific command data structure.
155*4882a593Smuzhiyun  *  Not needed under Linux.
156*4882a593Smuzhiyun  */
157*4882a593Smuzhiyun /* struct sym_sccb */
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun /*
160*4882a593Smuzhiyun  *  System specific host data structure.
161*4882a593Smuzhiyun  */
162*4882a593Smuzhiyun struct sym_shcb {
163*4882a593Smuzhiyun 	/*
164*4882a593Smuzhiyun 	 *  Chip and controller identification.
165*4882a593Smuzhiyun 	 */
166*4882a593Smuzhiyun 	int		unit;
167*4882a593Smuzhiyun 	char		inst_name[16];
168*4882a593Smuzhiyun 	char		chip_name[8];
169*4882a593Smuzhiyun 
170*4882a593Smuzhiyun 	struct Scsi_Host *host;
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun 	void __iomem *	ioaddr;		/* MMIO kernel io address	*/
173*4882a593Smuzhiyun 	void __iomem *	ramaddr;	/* RAM  kernel io address	*/
174*4882a593Smuzhiyun 
175*4882a593Smuzhiyun 	struct timer_list timer;	/* Timer handler link header	*/
176*4882a593Smuzhiyun 	u_long		lasttime;
177*4882a593Smuzhiyun 	u_long		settle_time;	/* Resetting the SCSI BUS	*/
178*4882a593Smuzhiyun 	u_char		settle_time_valid;
179*4882a593Smuzhiyun };
180*4882a593Smuzhiyun 
181*4882a593Smuzhiyun /*
182*4882a593Smuzhiyun  *  Return the name of the controller.
183*4882a593Smuzhiyun  */
184*4882a593Smuzhiyun #define sym_name(np) (np)->s.inst_name
185*4882a593Smuzhiyun 
186*4882a593Smuzhiyun struct sym_nvram;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun /*
189*4882a593Smuzhiyun  * The IO macros require a struct called 's' and are abused in sym_nvram.c
190*4882a593Smuzhiyun  */
191*4882a593Smuzhiyun struct sym_device {
192*4882a593Smuzhiyun 	struct pci_dev *pdev;
193*4882a593Smuzhiyun 	unsigned long mmio_base;
194*4882a593Smuzhiyun 	unsigned long ram_base;
195*4882a593Smuzhiyun 	struct {
196*4882a593Smuzhiyun 		void __iomem *ioaddr;
197*4882a593Smuzhiyun 		void __iomem *ramaddr;
198*4882a593Smuzhiyun 	} s;
199*4882a593Smuzhiyun 	struct sym_chip chip;
200*4882a593Smuzhiyun 	struct sym_nvram *nvram;
201*4882a593Smuzhiyun 	u_char host_id;
202*4882a593Smuzhiyun };
203*4882a593Smuzhiyun 
204*4882a593Smuzhiyun /*
205*4882a593Smuzhiyun  *  Driver host data structure.
206*4882a593Smuzhiyun  */
207*4882a593Smuzhiyun struct sym_data {
208*4882a593Smuzhiyun 	struct sym_hcb *ncb;
209*4882a593Smuzhiyun 	struct completion *io_reset;		/* PCI error handling */
210*4882a593Smuzhiyun 	struct pci_dev *pdev;
211*4882a593Smuzhiyun };
212*4882a593Smuzhiyun 
sym_get_hcb(struct Scsi_Host * host)213*4882a593Smuzhiyun static inline struct sym_hcb * sym_get_hcb(struct Scsi_Host *host)
214*4882a593Smuzhiyun {
215*4882a593Smuzhiyun 	return ((struct sym_data *)host->hostdata)->ncb;
216*4882a593Smuzhiyun }
217*4882a593Smuzhiyun 
218*4882a593Smuzhiyun #include "sym_fw.h"
219*4882a593Smuzhiyun #include "sym_hipd.h"
220*4882a593Smuzhiyun 
221*4882a593Smuzhiyun /*
222*4882a593Smuzhiyun  *  Set the status field of a CAM CCB.
223*4882a593Smuzhiyun  */
224*4882a593Smuzhiyun static inline void
sym_set_cam_status(struct scsi_cmnd * cmd,int status)225*4882a593Smuzhiyun sym_set_cam_status(struct scsi_cmnd *cmd, int status)
226*4882a593Smuzhiyun {
227*4882a593Smuzhiyun 	cmd->result &= ~(0xff  << 16);
228*4882a593Smuzhiyun 	cmd->result |= (status << 16);
229*4882a593Smuzhiyun }
230*4882a593Smuzhiyun 
231*4882a593Smuzhiyun /*
232*4882a593Smuzhiyun  *  Get the status field of a CAM CCB.
233*4882a593Smuzhiyun  */
234*4882a593Smuzhiyun static inline int
sym_get_cam_status(struct scsi_cmnd * cmd)235*4882a593Smuzhiyun sym_get_cam_status(struct scsi_cmnd *cmd)
236*4882a593Smuzhiyun {
237*4882a593Smuzhiyun 	return host_byte(cmd->result);
238*4882a593Smuzhiyun }
239*4882a593Smuzhiyun 
240*4882a593Smuzhiyun /*
241*4882a593Smuzhiyun  *  Build CAM result for a successful IO and for a failed IO.
242*4882a593Smuzhiyun  */
sym_set_cam_result_ok(struct sym_ccb * cp,struct scsi_cmnd * cmd,int resid)243*4882a593Smuzhiyun static inline void sym_set_cam_result_ok(struct sym_ccb *cp, struct scsi_cmnd *cmd, int resid)
244*4882a593Smuzhiyun {
245*4882a593Smuzhiyun 	scsi_set_resid(cmd, resid);
246*4882a593Smuzhiyun 	cmd->result = (DID_OK << 16) | (cp->ssss_status & 0x7f);
247*4882a593Smuzhiyun }
248*4882a593Smuzhiyun void sym_set_cam_result_error(struct sym_hcb *np, struct sym_ccb *cp, int resid);
249*4882a593Smuzhiyun 
250*4882a593Smuzhiyun void sym_xpt_done(struct sym_hcb *np, struct scsi_cmnd *ccb);
251*4882a593Smuzhiyun #define sym_print_addr(cmd, arg...) dev_info(&cmd->device->sdev_gendev , ## arg)
252*4882a593Smuzhiyun void sym_xpt_async_bus_reset(struct sym_hcb *np);
253*4882a593Smuzhiyun int  sym_setup_data_and_start (struct sym_hcb *np, struct scsi_cmnd *csio, struct sym_ccb *cp);
254*4882a593Smuzhiyun void sym_log_bus_error(struct Scsi_Host *);
255*4882a593Smuzhiyun void sym_dump_registers(struct Scsi_Host *);
256*4882a593Smuzhiyun 
257*4882a593Smuzhiyun #endif /* SYM_GLUE_H */
258