18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-or-later */
28c2ecf20Sopenharmony_ci/*
38c2ecf20Sopenharmony_ci * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
48c2ecf20Sopenharmony_ci * of PCI-SCSI IO processors.
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Copyright (C) 1999-2001  Gerard Roudier <groudier@free.fr>
78c2ecf20Sopenharmony_ci *
88c2ecf20Sopenharmony_ci * This driver is derived from the Linux sym53c8xx driver.
98c2ecf20Sopenharmony_ci * Copyright (C) 1998-2000  Gerard Roudier
108c2ecf20Sopenharmony_ci *
118c2ecf20Sopenharmony_ci * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
128c2ecf20Sopenharmony_ci * a port of the FreeBSD ncr driver to Linux-1.2.13.
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The original ncr driver has been written for 386bsd and FreeBSD by
158c2ecf20Sopenharmony_ci *         Wolfgang Stanglmeier        <wolf@cologne.de>
168c2ecf20Sopenharmony_ci *         Stefan Esser                <se@mi.Uni-Koeln.de>
178c2ecf20Sopenharmony_ci * Copyright (C) 1994  Wolfgang Stanglmeier
188c2ecf20Sopenharmony_ci *
198c2ecf20Sopenharmony_ci * Other major contributions:
208c2ecf20Sopenharmony_ci *
218c2ecf20Sopenharmony_ci * NVRAM detection and reading.
228c2ecf20Sopenharmony_ci * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
238c2ecf20Sopenharmony_ci *
248c2ecf20Sopenharmony_ci *-----------------------------------------------------------------------------
258c2ecf20Sopenharmony_ci */
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ci#ifndef	SYM_FW_H
288c2ecf20Sopenharmony_ci#define	SYM_FW_H
298c2ecf20Sopenharmony_ci/*
308c2ecf20Sopenharmony_ci *  Macro used to generate interfaces for script A.
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#define SYM_GEN_FW_A(s)							\
338c2ecf20Sopenharmony_ci	SYM_GEN_A(s, start)		SYM_GEN_A(s, getjob_begin)	\
348c2ecf20Sopenharmony_ci	SYM_GEN_A(s, getjob_end)					\
358c2ecf20Sopenharmony_ci	SYM_GEN_A(s, select)		SYM_GEN_A(s, wf_sel_done)	\
368c2ecf20Sopenharmony_ci	SYM_GEN_A(s, send_ident)					\
378c2ecf20Sopenharmony_ci	SYM_GEN_A(s, dispatch)		SYM_GEN_A(s, init)		\
388c2ecf20Sopenharmony_ci	SYM_GEN_A(s, clrack)		SYM_GEN_A(s, complete_error)	\
398c2ecf20Sopenharmony_ci	SYM_GEN_A(s, done)		SYM_GEN_A(s, done_end)		\
408c2ecf20Sopenharmony_ci	SYM_GEN_A(s, idle)		SYM_GEN_A(s, ungetjob)		\
418c2ecf20Sopenharmony_ci	SYM_GEN_A(s, reselect)						\
428c2ecf20Sopenharmony_ci	SYM_GEN_A(s, resel_tag)		SYM_GEN_A(s, resel_dsa)		\
438c2ecf20Sopenharmony_ci	SYM_GEN_A(s, resel_no_tag)					\
448c2ecf20Sopenharmony_ci	SYM_GEN_A(s, data_in)		SYM_GEN_A(s, data_in2)		\
458c2ecf20Sopenharmony_ci	SYM_GEN_A(s, data_out)		SYM_GEN_A(s, data_out2)		\
468c2ecf20Sopenharmony_ci	SYM_GEN_A(s, pm0_data)		SYM_GEN_A(s, pm1_data)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ci/*
498c2ecf20Sopenharmony_ci *  Macro used to generate interfaces for script B.
508c2ecf20Sopenharmony_ci */
518c2ecf20Sopenharmony_ci#define SYM_GEN_FW_B(s)							\
528c2ecf20Sopenharmony_ci	SYM_GEN_B(s, no_data)						\
538c2ecf20Sopenharmony_ci	SYM_GEN_B(s, sel_for_abort)	SYM_GEN_B(s, sel_for_abort_1)	\
548c2ecf20Sopenharmony_ci	SYM_GEN_B(s, msg_bad)		SYM_GEN_B(s, msg_weird)		\
558c2ecf20Sopenharmony_ci	SYM_GEN_B(s, wdtr_resp)		SYM_GEN_B(s, send_wdtr)		\
568c2ecf20Sopenharmony_ci	SYM_GEN_B(s, sdtr_resp)		SYM_GEN_B(s, send_sdtr)		\
578c2ecf20Sopenharmony_ci	SYM_GEN_B(s, ppr_resp)		SYM_GEN_B(s, send_ppr)		\
588c2ecf20Sopenharmony_ci	SYM_GEN_B(s, nego_bad_phase)					\
598c2ecf20Sopenharmony_ci	SYM_GEN_B(s, ident_break) 	SYM_GEN_B(s, ident_break_atn)	\
608c2ecf20Sopenharmony_ci	SYM_GEN_B(s, sdata_in)		SYM_GEN_B(s, resel_bad_lun)	\
618c2ecf20Sopenharmony_ci	SYM_GEN_B(s, bad_i_t_l)		SYM_GEN_B(s, bad_i_t_l_q)	\
628c2ecf20Sopenharmony_ci	SYM_GEN_B(s, wsr_ma_helper)
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci/*
658c2ecf20Sopenharmony_ci *  Macro used to generate interfaces for script Z.
668c2ecf20Sopenharmony_ci */
678c2ecf20Sopenharmony_ci#define SYM_GEN_FW_Z(s)							\
688c2ecf20Sopenharmony_ci	SYM_GEN_Z(s, snooptest)		SYM_GEN_Z(s, snoopend)
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ci/*
718c2ecf20Sopenharmony_ci *  Generates structure interface that contains
728c2ecf20Sopenharmony_ci *  offsets within script A, B and Z.
738c2ecf20Sopenharmony_ci */
748c2ecf20Sopenharmony_ci#define	SYM_GEN_A(s, label)	s label;
758c2ecf20Sopenharmony_ci#define	SYM_GEN_B(s, label)	s label;
768c2ecf20Sopenharmony_ci#define	SYM_GEN_Z(s, label)	s label;
778c2ecf20Sopenharmony_cistruct sym_fwa_ofs {
788c2ecf20Sopenharmony_ci	SYM_GEN_FW_A(u_short)
798c2ecf20Sopenharmony_ci};
808c2ecf20Sopenharmony_cistruct sym_fwb_ofs {
818c2ecf20Sopenharmony_ci	SYM_GEN_FW_B(u_short)
828c2ecf20Sopenharmony_ci	SYM_GEN_B(u_short, start64)
838c2ecf20Sopenharmony_ci	SYM_GEN_B(u_short, pm_handle)
848c2ecf20Sopenharmony_ci};
858c2ecf20Sopenharmony_cistruct sym_fwz_ofs {
868c2ecf20Sopenharmony_ci	SYM_GEN_FW_Z(u_short)
878c2ecf20Sopenharmony_ci};
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci/*
908c2ecf20Sopenharmony_ci *  Generates structure interface that contains
918c2ecf20Sopenharmony_ci *  bus addresses within script A, B and Z.
928c2ecf20Sopenharmony_ci */
938c2ecf20Sopenharmony_cistruct sym_fwa_ba {
948c2ecf20Sopenharmony_ci	SYM_GEN_FW_A(u32)
958c2ecf20Sopenharmony_ci};
968c2ecf20Sopenharmony_cistruct sym_fwb_ba {
978c2ecf20Sopenharmony_ci	SYM_GEN_FW_B(u32)
988c2ecf20Sopenharmony_ci	SYM_GEN_B(u32, start64);
998c2ecf20Sopenharmony_ci	SYM_GEN_B(u32, pm_handle);
1008c2ecf20Sopenharmony_ci};
1018c2ecf20Sopenharmony_cistruct sym_fwz_ba {
1028c2ecf20Sopenharmony_ci	SYM_GEN_FW_Z(u32)
1038c2ecf20Sopenharmony_ci};
1048c2ecf20Sopenharmony_ci#undef	SYM_GEN_A
1058c2ecf20Sopenharmony_ci#undef	SYM_GEN_B
1068c2ecf20Sopenharmony_ci#undef	SYM_GEN_Z
1078c2ecf20Sopenharmony_ci
1088c2ecf20Sopenharmony_ci/*
1098c2ecf20Sopenharmony_ci *  Let cc know about the name of the controller data structure.
1108c2ecf20Sopenharmony_ci *  We need this for function prototype declarations just below.
1118c2ecf20Sopenharmony_ci */
1128c2ecf20Sopenharmony_cistruct sym_hcb;
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ci/*
1158c2ecf20Sopenharmony_ci *  Generic structure that defines a firmware.
1168c2ecf20Sopenharmony_ci */
1178c2ecf20Sopenharmony_cistruct sym_fw {
1188c2ecf20Sopenharmony_ci	char	*name;		/* Name we want to print out	*/
1198c2ecf20Sopenharmony_ci	u32	*a_base;	/* Pointer to script A template	*/
1208c2ecf20Sopenharmony_ci	int	a_size;		/* Size of script A		*/
1218c2ecf20Sopenharmony_ci	struct	sym_fwa_ofs
1228c2ecf20Sopenharmony_ci		*a_ofs;		/* Useful offsets in script A	*/
1238c2ecf20Sopenharmony_ci	u32	*b_base;	/* Pointer to script B template	*/
1248c2ecf20Sopenharmony_ci	int	b_size;		/* Size of script B		*/
1258c2ecf20Sopenharmony_ci	struct	sym_fwb_ofs
1268c2ecf20Sopenharmony_ci		*b_ofs;		/* Useful offsets in script B	*/
1278c2ecf20Sopenharmony_ci	u32	*z_base;	/* Pointer to script Z template	*/
1288c2ecf20Sopenharmony_ci	int	z_size;		/* Size of script Z		*/
1298c2ecf20Sopenharmony_ci	struct	sym_fwz_ofs
1308c2ecf20Sopenharmony_ci		*z_ofs;		/* Useful offsets in script Z	*/
1318c2ecf20Sopenharmony_ci	/* Setup and patch methods for this firmware */
1328c2ecf20Sopenharmony_ci	void	(*setup)(struct sym_hcb *, struct sym_fw *);
1338c2ecf20Sopenharmony_ci	void	(*patch)(struct Scsi_Host *);
1348c2ecf20Sopenharmony_ci};
1358c2ecf20Sopenharmony_ci
1368c2ecf20Sopenharmony_ci/*
1378c2ecf20Sopenharmony_ci *  Macro used to declare a firmware.
1388c2ecf20Sopenharmony_ci */
1398c2ecf20Sopenharmony_ci#define SYM_FW_ENTRY(fw, name)					\
1408c2ecf20Sopenharmony_ci{								\
1418c2ecf20Sopenharmony_ci	name,							\
1428c2ecf20Sopenharmony_ci	(u32 *) &fw##a_scr, sizeof(fw##a_scr), &fw##a_ofs,	\
1438c2ecf20Sopenharmony_ci	(u32 *) &fw##b_scr, sizeof(fw##b_scr), &fw##b_ofs,	\
1448c2ecf20Sopenharmony_ci	(u32 *) &fw##z_scr, sizeof(fw##z_scr), &fw##z_ofs,	\
1458c2ecf20Sopenharmony_ci	fw##_setup, fw##_patch					\
1468c2ecf20Sopenharmony_ci}
1478c2ecf20Sopenharmony_ci
1488c2ecf20Sopenharmony_ci/*
1498c2ecf20Sopenharmony_ci *  Macros used from the C code to get useful
1508c2ecf20Sopenharmony_ci *  SCRIPTS bus addresses.
1518c2ecf20Sopenharmony_ci */
1528c2ecf20Sopenharmony_ci#define SCRIPTA_BA(np, label)	(np->fwa_bas.label)
1538c2ecf20Sopenharmony_ci#define SCRIPTB_BA(np, label)	(np->fwb_bas.label)
1548c2ecf20Sopenharmony_ci#define SCRIPTZ_BA(np, label)	(np->fwz_bas.label)
1558c2ecf20Sopenharmony_ci
1568c2ecf20Sopenharmony_ci/*
1578c2ecf20Sopenharmony_ci *  Macros used by scripts definitions.
1588c2ecf20Sopenharmony_ci *
1598c2ecf20Sopenharmony_ci *  HADDR_1 generates a reference to a field of the controller data.
1608c2ecf20Sopenharmony_ci *  HADDR_2 generates a reference to a field of the controller data
1618c2ecf20Sopenharmony_ci *          with offset.
1628c2ecf20Sopenharmony_ci *  RADDR_1 generates a reference to a script processor register.
1638c2ecf20Sopenharmony_ci *  RADDR_2 generates a reference to a script processor register
1648c2ecf20Sopenharmony_ci *          with offset.
1658c2ecf20Sopenharmony_ci *  PADDR_A generates a reference to another part of script A.
1668c2ecf20Sopenharmony_ci *  PADDR_B generates a reference to another part of script B.
1678c2ecf20Sopenharmony_ci *
1688c2ecf20Sopenharmony_ci *  SYM_GEN_PADDR_A and SYM_GEN_PADDR_B are used to define respectively
1698c2ecf20Sopenharmony_ci *  the PADDR_A and PADDR_B macros for each firmware by setting argument
1708c2ecf20Sopenharmony_ci *  `s' to the name of the corresponding structure.
1718c2ecf20Sopenharmony_ci *
1728c2ecf20Sopenharmony_ci *  SCR_DATA_ZERO is used to allocate a DWORD of data in scripts areas.
1738c2ecf20Sopenharmony_ci */
1748c2ecf20Sopenharmony_ci
1758c2ecf20Sopenharmony_ci#define	RELOC_SOFTC	0x40000000
1768c2ecf20Sopenharmony_ci#define	RELOC_LABEL_A	0x50000000
1778c2ecf20Sopenharmony_ci#define	RELOC_REGISTER	0x60000000
1788c2ecf20Sopenharmony_ci#define	RELOC_LABEL_B	0x80000000
1798c2ecf20Sopenharmony_ci#define	RELOC_MASK	0xf0000000
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#define	HADDR_1(label)	   (RELOC_SOFTC    | offsetof(struct sym_hcb, label))
1828c2ecf20Sopenharmony_ci#define	HADDR_2(label,ofs) (RELOC_SOFTC    | \
1838c2ecf20Sopenharmony_ci				(offsetof(struct sym_hcb, label)+(ofs)))
1848c2ecf20Sopenharmony_ci#define	RADDR_1(label)	   (RELOC_REGISTER | REG(label))
1858c2ecf20Sopenharmony_ci#define	RADDR_2(label,ofs) (RELOC_REGISTER | ((REG(label))+(ofs)))
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define SYM_GEN_PADDR_A(s, label) (RELOC_LABEL_A  | offsetof(s, label))
1888c2ecf20Sopenharmony_ci#define SYM_GEN_PADDR_B(s, label) (RELOC_LABEL_B  | offsetof(s, label))
1898c2ecf20Sopenharmony_ci
1908c2ecf20Sopenharmony_ci#define SCR_DATA_ZERO	0xf00ff00f
1918c2ecf20Sopenharmony_ci
1928c2ecf20Sopenharmony_ci#endif	/* SYM_FW_H */
193