1 /*- 2 * SPDX-License-Identifier: BSD-3-Clause 3 * 4 * Device driver optimized for the Symbios/LSI 53C896/53C895A/53C1010 5 * PCI-SCSI controllers. 6 * 7 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr> 8 * 9 * This driver also supports the following Symbios/LSI PCI-SCSI chips: 10 * 53C810A, 53C825A, 53C860, 53C875, 53C876, 53C885, 53C895, 11 * 53C810, 53C815, 53C825 and the 53C1510D is 53C8XX mode. 12 * 13 * 14 * This driver for FreeBSD-CAM is derived from the Linux sym53c8xx driver. 15 * Copyright (C) 1998-1999 Gerard Roudier 16 * 17 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been 18 * a port of the FreeBSD ncr driver to Linux-1.2.13. 19 * 20 * The original ncr driver has been written for 386bsd and FreeBSD by 21 * Wolfgang Stanglmeier <wolf@cologne.de> 22 * Stefan Esser <se@mi.Uni-Koeln.de> 23 * Copyright (C) 1994 Wolfgang Stanglmeier 24 * 25 * The initialisation code, and part of the code that addresses 26 * FreeBSD-CAM services is based on the aic7xxx driver for FreeBSD-CAM 27 * written by Justin T. Gibbs. 28 * 29 * Other major contributions: 30 * 31 * NVRAM detection and reading. 32 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk> 33 * 34 *----------------------------------------------------------------------------- 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 1. Redistributions of source code must retain the above copyright 40 * notice, this list of conditions and the following disclaimer. 41 * 2. Redistributions in binary form must reproduce the above copyright 42 * notice, this list of conditions and the following disclaimer in the 43 * documentation and/or other materials provided with the distribution. 44 * 3. The name of the author may not be used to endorse or promote products 45 * derived from this software without specific prior written permission. 46 * 47 * THIS SOFTWARE IS PROVIDED BY THE AUTHORS AND CONTRIBUTORS ``AS IS'' AND 48 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 49 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 50 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR 51 * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 52 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 53 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 54 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 55 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 56 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 57 * SUCH DAMAGE. 58 */ 59 60 /* $FreeBSD$ */ 61 62 #ifndef SYM_FW_H 63 #define SYM_FW_H 64 /* 65 * Macro used to generate interfaces for script A. 66 */ 67 #define SYM_GEN_FW_A(s) \ 68 SYM_GEN_A(s, start) SYM_GEN_A(s, getjob_begin) \ 69 SYM_GEN_A(s, getjob_end) \ 70 SYM_GEN_A(s, select) SYM_GEN_A(s, wf_sel_done) \ 71 SYM_GEN_A(s, send_ident) \ 72 SYM_GEN_A(s, dispatch) SYM_GEN_A(s, init) \ 73 SYM_GEN_A(s, clrack) SYM_GEN_A(s, complete_error) \ 74 SYM_GEN_A(s, done) SYM_GEN_A(s, done_end) \ 75 SYM_GEN_A(s, idle) SYM_GEN_A(s, ungetjob) \ 76 SYM_GEN_A(s, reselect) \ 77 SYM_GEN_A(s, resel_tag) SYM_GEN_A(s, resel_dsa) \ 78 SYM_GEN_A(s, resel_no_tag) \ 79 SYM_GEN_A(s, data_in) SYM_GEN_A(s, data_in2) \ 80 SYM_GEN_A(s, data_out) SYM_GEN_A(s, data_out2) \ 81 SYM_GEN_A(s, pm0_data) SYM_GEN_A(s, pm1_data) 82 83 /* 84 * Macro used to generate interfaces for script B. 85 */ 86 #define SYM_GEN_FW_B(s) \ 87 SYM_GEN_B(s, no_data) \ 88 SYM_GEN_B(s, sel_for_abort) SYM_GEN_B(s, sel_for_abort_1) \ 89 SYM_GEN_B(s, msg_bad) SYM_GEN_B(s, msg_weird) \ 90 SYM_GEN_B(s, wdtr_resp) SYM_GEN_B(s, send_wdtr) \ 91 SYM_GEN_B(s, sdtr_resp) SYM_GEN_B(s, send_sdtr) \ 92 SYM_GEN_B(s, ppr_resp) SYM_GEN_B(s, send_ppr) \ 93 SYM_GEN_B(s, nego_bad_phase) \ 94 SYM_GEN_B(s, ident_break) SYM_GEN_B(s, ident_break_atn) \ 95 SYM_GEN_B(s, sdata_in) SYM_GEN_B(s, resel_bad_lun) \ 96 SYM_GEN_B(s, bad_i_t_l) SYM_GEN_B(s, bad_i_t_l_q) \ 97 SYM_GEN_B(s, wsr_ma_helper) \ 98 SYM_GEN_B(s, snooptest) SYM_GEN_B(s, snoopend) 99 100 /* 101 * Generates structure interface that contains 102 * offsets within script A and script B. 103 */ 104 #define SYM_GEN_A(s, label) s label; 105 #define SYM_GEN_B(s, label) s label; 106 struct sym_fwa_ofs { 107 SYM_GEN_FW_A(u_short) 108 }; 109 struct sym_fwb_ofs { 110 SYM_GEN_FW_B(u_short) 111 SYM_GEN_B(u_short, start64) 112 SYM_GEN_B(u_short, pm_handle) 113 }; 114 115 /* 116 * Generates structure interface that contains 117 * bus addresses within script A and script B. 118 */ 119 struct sym_fwa_ba { 120 SYM_GEN_FW_A(u32) 121 }; 122 struct sym_fwb_ba { 123 SYM_GEN_FW_B(u32) 124 SYM_GEN_B(u32, start64) 125 SYM_GEN_B(u32, pm_handle) 126 }; 127 #undef SYM_GEN_A 128 #undef SYM_GEN_B 129 130 /* 131 * Let cc know about the name of the controller data structure. 132 * We need this for function prototype declarations just below. 133 */ 134 struct sym_hcb; 135 136 /* 137 * Generic structure that defines a firmware. 138 */ 139 struct sym_fw { 140 const char *name; /* Name we want to print out */ 141 const u32 *a_base;/* Pointer to script A template */ 142 int a_size; /* Size of script A */ 143 const struct sym_fwa_ofs 144 *a_ofs; /* Useful offsets in script A */ 145 const u32 *b_base;/* Pointer to script B template */ 146 int b_size; /* Size of script B */ 147 const struct sym_fwb_ofs 148 *b_ofs; /* Useful offsets in script B */ 149 /* Setup and patch methods for this firmware */ 150 void (*setup)(struct sym_hcb *, const struct sym_fw *); 151 void (*patch)(struct sym_hcb *); 152 }; 153 154 /* 155 * Macro used to declare a firmware. 156 */ 157 #define SYM_FW_ENTRY(fw, name) \ 158 { \ 159 name, \ 160 (const u32 *) &fw##a_scr, sizeof(fw##a_scr), &fw##a_ofs,\ 161 (const u32 *) &fw##b_scr, sizeof(fw##b_scr), &fw##b_ofs,\ 162 fw##_setup, fw##_patch \ 163 } 164 165 /* 166 * Macros used from the C code to get useful 167 * SCRIPTS bus addresses. 168 */ 169 #define SCRIPTA_BA(np, label) (np->fwa_bas.label) 170 #define SCRIPTB_BA(np, label) (np->fwb_bas.label) 171 #define SCRIPTB0_BA(np,label) \ 172 (np->scriptb0_ba + (np->fwb_bas.label - np->scriptb_ba)) 173 174 /* 175 * Macros used by scripts definitions. 176 * 177 * HADDR_1 generates a reference to a field of the controller data. 178 * HADDR_2 generates a reference to a field of the controller data 179 * with offset. 180 * RADDR_1 generates a reference to a script processor register. 181 * RADDR_2 generates a reference to a script processor register 182 * with offset. 183 * PADDR_A generates a reference to another part of script A. 184 * PADDR_B generates a reference to another part of script B. 185 * 186 * SYM_GEN_PADDR_A and SYM_GEN_PADDR_B are used to define respectively 187 * the PADDR_A and PADDR_B macros for each firmware by setting argument 188 * `s' to the name of the corresponding structure. 189 * 190 * SCR_DATA_ZERO is used to allocate a DWORD of data in scripts areas. 191 */ 192 193 #define RELOC_SOFTC 0x40000000 194 #define RELOC_LABEL_A 0x50000000 195 #define RELOC_REGISTER 0x60000000 196 #define RELOC_LABEL_B 0x80000000 197 #define RELOC_MASK 0xf0000000 198 199 #define HADDR_1(label) (RELOC_SOFTC | offsetof(struct sym_hcb, label)) 200 #define HADDR_2(label,ofs) (RELOC_SOFTC | \ 201 (offsetof(struct sym_hcb, label)+(ofs))) 202 #define RADDR_1(label) (RELOC_REGISTER | REG(label)) 203 #define RADDR_2(label,ofs) (RELOC_REGISTER | ((REG(label))+(ofs))) 204 205 #define SYM_GEN_PADDR_A(s, label) (RELOC_LABEL_A | offsetof(s, label)) 206 #define SYM_GEN_PADDR_B(s, label) (RELOC_LABEL_B | offsetof(s, label)) 207 208 #define SCR_DATA_ZERO 0xf00ff00f 209 210 #endif /* SYM_FW_H */ 211