1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * Device driver for the SYMBIOS/LSILOGIC 53C8XX and 53C1010 family
4 * of PCI-SCSI IO processors.
6 * Copyright (C) 1999-2001 Gerard Roudier <groudier@free.fr>
8 * This driver is derived from the Linux sym53c8xx driver.
9 * Copyright (C) 1998-2000 Gerard Roudier
11 * The sym53c8xx driver is derived from the ncr53c8xx driver that had been
12 * a port of the FreeBSD ncr driver to Linux-1.2.13.
14 * The original ncr driver has been written for 386bsd and FreeBSD by
15 * Wolfgang Stanglmeier <wolf@cologne.de>
16 * Stefan Esser <se@mi.Uni-Koeln.de>
17 * Copyright (C) 1994 Wolfgang Stanglmeier
19 * Other major contributions:
21 * NVRAM detection and reading.
22 * Copyright (C) 1997 Richard Waltham <dormouse@farsrobt.demon.co.uk>
24 *-----------------------------------------------------------------------------
30 * Macros used for all firmwares.
32 #define SYM_GEN_A(s, label) ((short) offsetof(s, label)),
33 #define SYM_GEN_B(s, label) ((short) offsetof(s, label)),
34 #define SYM_GEN_Z(s, label) ((short) offsetof(s, label)),
35 #define PADDR_A(label) SYM_GEN_PADDR_A(struct SYM_FWA_SCR, label)
36 #define PADDR_B(label) SYM_GEN_PADDR_B(struct SYM_FWB_SCR, label)
39 #if SYM_CONF_GENERIC_SUPPORT
41 * Allocate firmware #1 script area.
43 #define SYM_FWA_SCR sym_fw1a_scr
44 #define SYM_FWB_SCR sym_fw1b_scr
45 #define SYM_FWZ_SCR sym_fw1z_scr
47 static struct sym_fwa_ofs sym_fw1a_ofs
= {
48 SYM_GEN_FW_A(struct SYM_FWA_SCR
)
50 static struct sym_fwb_ofs sym_fw1b_ofs
= {
51 SYM_GEN_FW_B(struct SYM_FWB_SCR
)
53 static struct sym_fwz_ofs sym_fw1z_ofs
= {
54 SYM_GEN_FW_Z(struct SYM_FWZ_SCR
)
59 #endif /* SYM_CONF_GENERIC_SUPPORT */
62 * Allocate firmware #2 script area.
64 #define SYM_FWA_SCR sym_fw2a_scr
65 #define SYM_FWB_SCR sym_fw2b_scr
66 #define SYM_FWZ_SCR sym_fw2z_scr
68 static struct sym_fwa_ofs sym_fw2a_ofs
= {
69 SYM_GEN_FW_A(struct SYM_FWA_SCR
)
71 static struct sym_fwb_ofs sym_fw2b_ofs
= {
72 SYM_GEN_FW_B(struct SYM_FWB_SCR
)
73 SYM_GEN_B(struct SYM_FWB_SCR
, start64
)
74 SYM_GEN_B(struct SYM_FWB_SCR
, pm_handle
)
76 static struct sym_fwz_ofs sym_fw2z_ofs
= {
77 SYM_GEN_FW_Z(struct SYM_FWZ_SCR
)
89 #if SYM_CONF_GENERIC_SUPPORT
91 * Patch routine for firmware #1.
94 sym_fw1_patch(struct Scsi_Host
*shost
)
96 struct sym_hcb
*np
= sym_get_hcb(shost
);
97 struct sym_fw1a_scr
*scripta0
;
98 struct sym_fw1b_scr
*scriptb0
;
100 scripta0
= (struct sym_fw1a_scr
*) np
->scripta0
;
101 scriptb0
= (struct sym_fw1b_scr
*) np
->scriptb0
;
104 * Remove LED support if not needed.
106 if (!(np
->features
& FE_LED0
)) {
107 scripta0
->idle
[0] = cpu_to_scr(SCR_NO_OP
);
108 scripta0
->reselected
[0] = cpu_to_scr(SCR_NO_OP
);
109 scripta0
->start
[0] = cpu_to_scr(SCR_NO_OP
);
112 #ifdef SYM_CONF_IARB_SUPPORT
114 * If user does not want to use IMMEDIATE ARBITRATION
115 * when we are reselected while attempting to arbitrate,
116 * patch the SCRIPTS accordingly with a SCRIPT NO_OP.
118 if (!SYM_CONF_SET_IARB_ON_ARB_LOST
)
119 scripta0
->ungetjob
[0] = cpu_to_scr(SCR_NO_OP
);
122 * Patch some data in SCRIPTS.
123 * - start and done queue initial bus address.
124 * - target bus address table bus address.
126 scriptb0
->startpos
[0] = cpu_to_scr(np
->squeue_ba
);
127 scriptb0
->done_pos
[0] = cpu_to_scr(np
->dqueue_ba
);
128 scriptb0
->targtbl
[0] = cpu_to_scr(np
->targtbl_ba
);
130 #endif /* SYM_CONF_GENERIC_SUPPORT */
133 * Patch routine for firmware #2.
136 sym_fw2_patch(struct Scsi_Host
*shost
)
138 struct sym_data
*sym_data
= shost_priv(shost
);
139 struct pci_dev
*pdev
= sym_data
->pdev
;
140 struct sym_hcb
*np
= sym_data
->ncb
;
141 struct sym_fw2a_scr
*scripta0
;
142 struct sym_fw2b_scr
*scriptb0
;
144 scripta0
= (struct sym_fw2a_scr
*) np
->scripta0
;
145 scriptb0
= (struct sym_fw2b_scr
*) np
->scriptb0
;
148 * Remove LED support if not needed.
150 if (!(np
->features
& FE_LED0
)) {
151 scripta0
->idle
[0] = cpu_to_scr(SCR_NO_OP
);
152 scripta0
->reselected
[0] = cpu_to_scr(SCR_NO_OP
);
153 scripta0
->start
[0] = cpu_to_scr(SCR_NO_OP
);
156 #if SYM_CONF_DMA_ADDRESSING_MODE == 2
158 * Remove useless 64 bit DMA specific SCRIPTS,
159 * when this feature is not available.
162 scripta0
->is_dmap_dirty
[0] = cpu_to_scr(SCR_NO_OP
);
163 scripta0
->is_dmap_dirty
[1] = 0;
164 scripta0
->is_dmap_dirty
[2] = cpu_to_scr(SCR_NO_OP
);
165 scripta0
->is_dmap_dirty
[3] = 0;
169 #ifdef SYM_CONF_IARB_SUPPORT
171 * If user does not want to use IMMEDIATE ARBITRATION
172 * when we are reselected while attempting to arbitrate,
173 * patch the SCRIPTS accordingly with a SCRIPT NO_OP.
175 if (!SYM_CONF_SET_IARB_ON_ARB_LOST
)
176 scripta0
->ungetjob
[0] = cpu_to_scr(SCR_NO_OP
);
179 * Patch some variable in SCRIPTS.
180 * - start and done queue initial bus address.
181 * - target bus address table bus address.
183 scriptb0
->startpos
[0] = cpu_to_scr(np
->squeue_ba
);
184 scriptb0
->done_pos
[0] = cpu_to_scr(np
->dqueue_ba
);
185 scriptb0
->targtbl
[0] = cpu_to_scr(np
->targtbl_ba
);
188 * Remove the load of SCNTL4 on reselection if not a C10.
190 if (!(np
->features
& FE_C10
)) {
191 scripta0
->resel_scntl4
[0] = cpu_to_scr(SCR_NO_OP
);
192 scripta0
->resel_scntl4
[1] = cpu_to_scr(0);
196 * Remove a couple of work-arounds specific to C1010 if
197 * they are not desirable. See `sym_fw2.h' for more details.
199 if (!(pdev
->device
== PCI_DEVICE_ID_LSI_53C1010_66
&&
200 pdev
->revision
< 0x1 &&
201 np
->pciclk_khz
< 60000)) {
202 scripta0
->datao_phase
[0] = cpu_to_scr(SCR_NO_OP
);
203 scripta0
->datao_phase
[1] = cpu_to_scr(0);
205 if (!(pdev
->device
== PCI_DEVICE_ID_LSI_53C1010_33
/* &&
206 pdev->revision < 0xff */)) {
207 scripta0
->sel_done
[0] = cpu_to_scr(SCR_NO_OP
);
208 scripta0
->sel_done
[1] = cpu_to_scr(0);
212 * Patch some other variables in SCRIPTS.
213 * These ones are loaded by the SCRIPTS processor.
215 scriptb0
->pm0_data_addr
[0] =
216 cpu_to_scr(np
->scripta_ba
+
217 offsetof(struct sym_fw2a_scr
, pm0_data
));
218 scriptb0
->pm1_data_addr
[0] =
219 cpu_to_scr(np
->scripta_ba
+
220 offsetof(struct sym_fw2a_scr
, pm1_data
));
224 * Fill the data area in scripts.
225 * To be done for all firmwares.
228 sym_fw_fill_data (u32
*in
, u32
*out
)
232 for (i
= 0; i
< SYM_CONF_MAX_SG
; i
++) {
233 *in
++ = SCR_CHMOV_TBL
^ SCR_DATA_IN
;
234 *in
++ = offsetof (struct sym_dsb
, data
[i
]);
235 *out
++ = SCR_CHMOV_TBL
^ SCR_DATA_OUT
;
236 *out
++ = offsetof (struct sym_dsb
, data
[i
]);
241 * Setup useful script bus addresses.
242 * To be done for all firmwares.
245 sym_fw_setup_bus_addresses(struct sym_hcb
*np
, struct sym_fw
*fw
)
252 * Build the bus address table for script A
253 * from the script A offset table.
255 po
= (u_short
*) fw
->a_ofs
;
256 pa
= (u32
*) &np
->fwa_bas
;
257 for (i
= 0 ; i
< sizeof(np
->fwa_bas
)/sizeof(u32
) ; i
++)
258 pa
[i
] = np
->scripta_ba
+ po
[i
];
263 po
= (u_short
*) fw
->b_ofs
;
264 pa
= (u32
*) &np
->fwb_bas
;
265 for (i
= 0 ; i
< sizeof(np
->fwb_bas
)/sizeof(u32
) ; i
++)
266 pa
[i
] = np
->scriptb_ba
+ po
[i
];
271 po
= (u_short
*) fw
->z_ofs
;
272 pa
= (u32
*) &np
->fwz_bas
;
273 for (i
= 0 ; i
< sizeof(np
->fwz_bas
)/sizeof(u32
) ; i
++)
274 pa
[i
] = np
->scriptz_ba
+ po
[i
];
277 #if SYM_CONF_GENERIC_SUPPORT
279 * Setup routine for firmware #1.
282 sym_fw1_setup(struct sym_hcb
*np
, struct sym_fw
*fw
)
284 struct sym_fw1a_scr
*scripta0
;
286 scripta0
= (struct sym_fw1a_scr
*) np
->scripta0
;
289 * Fill variable parts in scripts.
291 sym_fw_fill_data(scripta0
->data_in
, scripta0
->data_out
);
294 * Setup bus addresses used from the C code..
296 sym_fw_setup_bus_addresses(np
, fw
);
298 #endif /* SYM_CONF_GENERIC_SUPPORT */
301 * Setup routine for firmware #2.
304 sym_fw2_setup(struct sym_hcb
*np
, struct sym_fw
*fw
)
306 struct sym_fw2a_scr
*scripta0
;
308 scripta0
= (struct sym_fw2a_scr
*) np
->scripta0
;
311 * Fill variable parts in scripts.
313 sym_fw_fill_data(scripta0
->data_in
, scripta0
->data_out
);
316 * Setup bus addresses used from the C code..
318 sym_fw_setup_bus_addresses(np
, fw
);
322 * Allocate firmware descriptors.
324 #if SYM_CONF_GENERIC_SUPPORT
325 static struct sym_fw sym_fw1
= SYM_FW_ENTRY(sym_fw1
, "NCR-generic");
326 #endif /* SYM_CONF_GENERIC_SUPPORT */
327 static struct sym_fw sym_fw2
= SYM_FW_ENTRY(sym_fw2
, "LOAD/STORE-based");
330 * Find the most appropriate firmware for a chip.
333 sym_find_firmware(struct sym_chip
*chip
)
335 if (chip
->features
& FE_LDSTR
)
337 #if SYM_CONF_GENERIC_SUPPORT
338 else if (!(chip
->features
& (FE_PFEN
|FE_NOPM
|FE_DAC
)))
346 * Bind a script to physical addresses.
348 void sym_fw_bind_script(struct sym_hcb
*np
, u32
*start
, int len
)
350 u32 opcode
, new, old
, tmp1
, tmp2
;
362 * If we forget to change the length
363 * in scripts, a field will be
364 * padded with 0. This is an illegal
368 printf ("%s: ERROR0 IN SCRIPT at %d.\n",
369 sym_name(np
), (int) (cur
-start
));
375 * We use the bogus value 0xf00ff00f ;-)
376 * to reserve data area in SCRIPTS.
378 if (opcode
== SCR_DATA_ZERO
) {
383 if (DEBUG_FLAGS
& DEBUG_SCRIPT
)
384 printf ("%d: <%x>\n", (int) (cur
-start
),
388 * We don't have to decode ALL commands
390 switch (opcode
>> 28) {
393 * LOAD / STORE DSA relative, don't relocate.
399 * LOAD / STORE absolute.
405 * COPY has TWO arguments.
410 if ((tmp1
^ tmp2
) & 3) {
411 printf ("%s: ERROR1 IN SCRIPT at %d.\n",
412 sym_name(np
), (int) (cur
-start
));
415 * If PREFETCH feature not enabled, remove
416 * the NO FLUSH bit if present.
418 if ((opcode
& SCR_NO_FLUSH
) &&
419 !(np
->features
& FE_PFEN
)) {
420 opcode
= (opcode
& ~SCR_NO_FLUSH
);
425 * MOVE/CHMOV (absolute address)
427 if (!(np
->features
& FE_WIDE
))
428 opcode
= (opcode
| OPC_MOVE
);
433 * MOVE/CHMOV (table indirect)
435 if (!(np
->features
& FE_WIDE
))
436 opcode
= (opcode
| OPC_MOVE
);
439 #ifdef SYM_CONF_TARGET_ROLE_SUPPORT
442 * MOVE/CHMOV in target role (absolute address)
444 opcode
&= ~0x20000000;
445 if (!(np
->features
& FE_WIDE
))
446 opcode
= (opcode
& ~OPC_TCHMOVE
);
451 * MOVE/CHMOV in target role (table indirect)
453 opcode
&= ~0x20000000;
454 if (!(np
->features
& FE_WIDE
))
455 opcode
= (opcode
& ~OPC_TCHMOVE
);
462 * don't relocate if relative :-)
464 if (opcode
& 0x00800000)
466 else if ((opcode
& 0xf8400000) == 0x80400000)/*JUMP64*/
483 * Scriptify:) the opcode.
485 *cur
++ = cpu_to_scr(opcode
);
488 * If no relocation, assume 1 argument
489 * and just scriptize:) it.
492 *cur
= cpu_to_scr(*cur
);
498 * Otherwise performs all needed relocations.
503 switch (old
& RELOC_MASK
) {
505 new = (old
& ~RELOC_MASK
) + np
->mmio_ba
;
508 new = (old
& ~RELOC_MASK
) + np
->scripta_ba
;
511 new = (old
& ~RELOC_MASK
) + np
->scriptb_ba
;
514 new = (old
& ~RELOC_MASK
) + np
->hcb_ba
;
518 * Don't relocate a 0 address.
519 * They are mostly used for patched or
520 * script self-modified areas.
529 panic("sym_fw_bind_script: "
530 "weird relocation %x\n", old
);
534 *cur
++ = cpu_to_scr(new);