1 /*****************************************************************************/
2 /* ips.c -- driver for the Adaptec / IBM ServeRAID controller */
4 /* Written By: Keith Mitchell, IBM Corporation */
5 /* Jack Hammer, Adaptec, Inc. */
6 /* David Jeffery, Adaptec, Inc. */
8 /* Copyright (C) 2000 IBM Corporation */
9 /* Copyright (C) 2002,2003 Adaptec, Inc. */
11 /* This program is free software; you can redistribute it and/or modify */
12 /* it under the terms of the GNU General Public License as published by */
13 /* the Free Software Foundation; either version 2 of the License, or */
14 /* (at your option) any later version. */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU General Public License for more details. */
22 /* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR */
23 /* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT */
24 /* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, */
25 /* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is */
26 /* solely responsible for determining the appropriateness of using and */
27 /* distributing the Program and assumes all risks associated with its */
28 /* exercise of rights under this Agreement, including but not limited to */
29 /* the risks and costs of program errors, damage to or loss of data, */
30 /* programs or equipment, and unavailability or interruption of operations. */
32 /* DISCLAIMER OF LIABILITY */
33 /* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY */
34 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */
35 /* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND */
36 /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR */
37 /* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE */
38 /* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED */
39 /* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES */
41 /* You should have received a copy of the GNU General Public License */
42 /* along with this program; if not, write to the Free Software */
43 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
45 /* Bugs/Comments/Suggestions about this driver should be mailed to: */
48 /* For system support issues, contact your local IBM Customer support. */
49 /* Directions to find IBM Customer Support for each country can be found at: */
50 /* http://www.ibm.com/planetwide/ */
52 /*****************************************************************************/
54 /*****************************************************************************/
57 /* 0.99.02 - Breakup commands that are bigger than 8 * the stripe size */
58 /* 0.99.03 - Make interrupt routine handle all completed request on the */
59 /* adapter not just the first one */
60 /* - Make sure passthru commands get woken up if we run out of */
62 /* - Send all of the commands on the queue at once rather than */
63 /* one at a time since the card will support it. */
64 /* 0.99.04 - Fix race condition in the passthru mechanism -- this required */
65 /* the interface to the utilities to change */
66 /* - Fix error recovery code */
67 /* 0.99.05 - Fix an oops when we get certain passthru commands */
68 /* 1.00.00 - Initial Public Release */
69 /* Functionally equivalent to 0.99.05 */
70 /* 3.60.00 - Bump max commands to 128 for use with firmware 3.60 */
71 /* - Change version to 3.60 to coincide with release numbering. */
72 /* 3.60.01 - Remove bogus error check in passthru routine */
73 /* 3.60.02 - Make DCDB direction based on lookup table */
74 /* - Only allow one DCDB command to a SCSI ID at a time */
75 /* 4.00.00 - Add support for ServeRAID 4 */
76 /* 4.00.01 - Add support for First Failure Data Capture */
77 /* 4.00.02 - Fix problem with PT DCDB with no buffer */
78 /* 4.00.03 - Add alternative passthru interface */
79 /* - Add ability to flash BIOS */
80 /* 4.00.04 - Rename structures/constants to be prefixed with IPS_ */
81 /* 4.00.05 - Remove wish_block from init routine */
82 /* - Use linux/spinlock.h instead of asm/spinlock.h for kernels */
83 /* 2.3.18 and later */
84 /* - Sync with other changes from the 2.3 kernels */
85 /* 4.00.06 - Fix timeout with initial FFDC command */
87 /* 4.10.00 - Add support for ServeRAID 4M/4L */
88 /* 4.10.13 - Fix for dynamic unload and proc file system */
89 /* 4.20.03 - Rename version to coincide with new release schedules */
90 /* Performance fixes */
91 /* Fix truncation of /proc files with cat */
92 /* Merge in changes through kernel 2.4.0test1ac21 */
93 /* 4.20.13 - Fix some failure cases / reset code */
94 /* - Hook into the reboot_notifier to flush the controller cache */
95 /* 4.50.01 - Fix problem when there is a hole in logical drive numbering */
96 /* 4.70.09 - Use a Common ( Large Buffer ) for Flashing from the JCRM CD */
97 /* - Add IPSSEND Flash Support */
98 /* - Set Sense Data for Unknown SCSI Command */
99 /* - Use Slot Number from NVRAM Page 5 */
100 /* - Restore caller's DCDB Structure */
101 /* 4.70.12 - Corrective actions for bad controller ( during initialization )*/
102 /* 4.70.13 - Don't Send CDB's if we already know the device is not present */
103 /* - Don't release HA Lock in ips_next() until SC taken off queue */
104 /* - Unregister SCSI device in ips_release() */
105 /* 4.70.15 - Fix Breakup for very large ( non-SG ) requests in ips_done() */
106 /* 4.71.00 - Change all memory allocations to not use GFP_DMA flag */
107 /* Code Clean-Up for 2.4.x kernel */
108 /* 4.72.00 - Allow for a Scatter-Gather Element to exceed MAX_XFER Size */
109 /* 4.72.01 - I/O Mapped Memory release ( so "insmod ips" does not Fail ) */
110 /* - Don't Issue Internal FFDC Command if there are Active Commands */
111 /* - Close Window for getting too many IOCTL's active */
112 /* 4.80.00 - Make ia64 Safe */
113 /* 4.80.04 - Eliminate calls to strtok() if 2.4.x or greater */
114 /* - Adjustments to Device Queue Depth */
115 /* 4.80.14 - Take all semaphores off stack */
116 /* - Clean Up New_IOCTL path */
117 /* 4.80.20 - Set max_sectors in Scsi_Host structure ( if >= 2.4.7 kernel ) */
118 /* - 5 second delay needed after resetting an i960 adapter */
119 /* 4.80.26 - Clean up potential code problems ( Arjan's recommendations ) */
120 /* 4.90.01 - Version Matching for FirmWare, BIOS, and Driver */
121 /* 4.90.05 - Use New PCI Architecture to facilitate Hot Plug Development */
122 /* 4.90.08 - Increase Delays in Flashing ( Trombone Only - 4H ) */
123 /* 4.90.08 - Data Corruption if First Scatter Gather Element is > 64K */
124 /* 4.90.11 - Don't actually RESET unless it's physically required */
125 /* - Remove unused compile options */
126 /* 5.00.01 - Sarasota ( 5i ) adapters must always be scanned first */
127 /* - Get rid on IOCTL_NEW_COMMAND code */
128 /* - Add Extended DCDB Commands for Tape Support in 5I */
129 /* 5.10.12 - use pci_dma interfaces, update for 2.5 kernel changes */
130 /* 5.10.15 - remove unused code (sem, macros, etc.) */
131 /* 5.30.00 - use __devexit_p() */
132 /* 6.00.00 - Add 6x Adapters and Battery Flash */
133 /* 6.10.00 - Remove 1G Addressing Limitations */
134 /* 6.11.xx - Get VersionInfo buffer off the stack ! DDTS 60401 */
135 /* 6.11.xx - Make Logical Drive Info structure safe for DMA DDTS 60639 */
136 /* 7.10.18 - Add highmem_io flag in SCSI Templete for 2.4 kernels */
137 /* - Fix path/name for scsi_hosts.h include for 2.6 kernels */
138 /* - Fix sort order of 7k */
139 /* - Remove 3 unused "inline" functions */
140 /* 7.12.xx - Use STATIC functions wherever possible */
141 /* - Clean up deprecated MODULE_PARM calls */
142 /* 7.12.05 - Remove Version Matching per IBM request */
143 /*****************************************************************************/
146 * Conditional Compilation directives for this driver:
148 * IPS_DEBUG - Turn on debugging info
152 * debug:<number> - Set debug level to <number>
153 * NOTE: only works when IPS_DEBUG compile directive is used.
154 * 1 - Normal debug messages
155 * 2 - Verbose debug messages
156 * 11 - Method trace (non interrupt)
157 * 12 - Method trace (includes interrupt)
159 * noi2o - Don't use I2O Queues (ServeRAID 4 only)
160 * nommap - Don't use memory mapped I/O
161 * ioctlsize - Initial size of the IOCTL buffer
165 #include <asm/byteorder.h>
166 #include <asm/page.h>
167 #include <linux/stddef.h>
168 #include <linux/string.h>
169 #include <linux/errno.h>
170 #include <linux/kernel.h>
171 #include <linux/ioport.h>
172 #include <linux/slab.h>
173 #include <linux/delay.h>
174 #include <linux/pci.h>
175 #include <linux/proc_fs.h>
176 #include <linux/reboot.h>
177 #include <linux/interrupt.h>
179 #include <linux/blkdev.h>
180 #include <linux/types.h>
181 #include <linux/dma-mapping.h>
185 #include <scsi/scsi_host.h>
189 #include <linux/module.h>
191 #include <linux/stat.h>
193 #include <linux/spinlock.h>
194 #include <linux/init.h>
196 #include <linux/smp.h>
199 static char *ips = NULL;
200 module_param(ips, charp, 0);
206 #define IPS_VERSION_HIGH IPS_VER_MAJOR_STRING "." IPS_VER_MINOR_STRING
207 #define IPS_VERSION_LOW "." IPS_VER_BUILD_STRING " "
209 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
210 DMA_NONE == scb->scsi_cmd->sc_data_direction) ? \
211 PCI_DMA_BIDIRECTIONAL : \
212 scb->scsi_cmd->sc_data_direction)
215 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
216 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
217 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
219 #define METHOD_TRACE(s, i)
221 #define DEBUG_VAR(i, s, v...)
225 * Function prototypes
227 static int ips_detect(struct scsi_host_template *);
228 static int ips_release(struct Scsi_Host *);
229 static int ips_eh_abort(struct scsi_cmnd *);
230 static int ips_eh_reset(struct scsi_cmnd *);
231 static int ips_queue(struct Scsi_Host *, struct scsi_cmnd *);
232 static const char *ips_info(struct Scsi_Host *);
233 static irqreturn_t do_ipsintr(int, void *);
234 static int ips_hainit(ips_ha_t *);
235 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
236 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
237 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
238 static int ips_online(ips_ha_t *, ips_scb_t *);
239 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
240 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
241 static int ips_msense(ips_ha_t *, ips_scb_t *);
242 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
243 static int ips_deallocatescbs(ips_ha_t *, int);
244 static int ips_allocatescbs(ips_ha_t *);
245 static int ips_reset_copperhead(ips_ha_t *);
246 static int ips_reset_copperhead_memio(ips_ha_t *);
247 static int ips_reset_morpheus(ips_ha_t *);
248 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
249 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
250 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
251 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
252 static int ips_isintr_copperhead(ips_ha_t *);
253 static int ips_isintr_copperhead_memio(ips_ha_t *);
254 static int ips_isintr_morpheus(ips_ha_t *);
255 static int ips_wait(ips_ha_t *, int, int);
256 static int ips_write_driver_status(ips_ha_t *, int);
257 static int ips_read_adapter_status(ips_ha_t *, int);
258 static int ips_read_subsystem_parameters(ips_ha_t *, int);
259 static int ips_read_config(ips_ha_t *, int);
260 static int ips_clear_adapter(ips_ha_t *, int);
261 static int ips_readwrite_page5(ips_ha_t *, int, int);
262 static int ips_init_copperhead(ips_ha_t *);
263 static int ips_init_copperhead_memio(ips_ha_t *);
264 static int ips_init_morpheus(ips_ha_t *);
265 static int ips_isinit_copperhead(ips_ha_t *);
266 static int ips_isinit_copperhead_memio(ips_ha_t *);
267 static int ips_isinit_morpheus(ips_ha_t *);
268 static int ips_erase_bios(ips_ha_t *);
269 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
270 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
271 static int ips_erase_bios_memio(ips_ha_t *);
272 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
273 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
274 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
275 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
276 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
277 static void ips_free_flash_copperhead(ips_ha_t * ha);
278 static void ips_get_bios_version(ips_ha_t *, int);
279 static void ips_identify_controller(ips_ha_t *);
280 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
281 static void ips_enable_int_copperhead(ips_ha_t *);
282 static void ips_enable_int_copperhead_memio(ips_ha_t *);
283 static void ips_enable_int_morpheus(ips_ha_t *);
284 static int ips_intr_copperhead(ips_ha_t *);
285 static int ips_intr_morpheus(ips_ha_t *);
286 static void ips_next(ips_ha_t *, int);
287 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
288 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
289 static void ips_done(ips_ha_t *, ips_scb_t *);
290 static void ips_free(ips_ha_t *);
291 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
292 static void ips_freescb(ips_ha_t *, ips_scb_t *);
293 static void ips_setup_funclist(ips_ha_t *);
294 static void ips_statinit(ips_ha_t *);
295 static void ips_statinit_memio(ips_ha_t *);
296 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
297 static void ips_ffdc_reset(ips_ha_t *, int);
298 static void ips_ffdc_time(ips_ha_t *);
299 static uint32_t ips_statupd_copperhead(ips_ha_t *);
300 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
301 static uint32_t ips_statupd_morpheus(ips_ha_t *);
302 static ips_scb_t *ips_getscb(ips_ha_t *);
303 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
304 static void ips_putq_wait_tail(ips_wait_queue_t *, struct scsi_cmnd *);
305 static void ips_putq_copp_tail(ips_copp_queue_t *,
306 ips_copp_wait_item_t *);
307 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
308 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
309 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
310 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *,
312 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
313 ips_copp_wait_item_t *);
314 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
316 static int ips_is_passthru(struct scsi_cmnd *);
317 static int ips_make_passthru(ips_ha_t *, struct scsi_cmnd *, ips_scb_t *, int);
318 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
319 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
320 static void ips_scmd_buf_write(struct scsi_cmnd * scmd, void *data,
322 static void ips_scmd_buf_read(struct scsi_cmnd * scmd, void *data,
325 static int ips_write_info(struct Scsi_Host *, char *, int);
326 static int ips_show_info(struct seq_file *, struct Scsi_Host *);
327 static int ips_host_info(ips_ha_t *, struct seq_file *);
328 static int ips_abort_init(ips_ha_t * ha, int index);
329 static int ips_init_phase2(int index);
331 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
332 static int ips_register_scsi(int index);
334 static int ips_poll_for_flush_complete(ips_ha_t * ha);
335 static void ips_flush_and_reset(ips_ha_t *ha);
340 static const char ips_name[] = "ips";
341 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
342 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
343 static unsigned int ips_next_controller;
344 static unsigned int ips_num_controllers;
345 static unsigned int ips_released_controllers;
346 static int ips_hotplug;
347 static int ips_cmd_timeout = 60;
348 static int ips_reset_timeout = 60 * 5;
349 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
350 static int ips_force_i2o = 1; /* Always use I2O command delivery */
351 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
352 static int ips_cd_boot; /* Booting from Manager CD */
353 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
354 static dma_addr_t ips_flashbusaddr;
355 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
356 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
357 static struct scsi_host_template ips_driver_template = {
358 .detect = ips_detect,
359 .release = ips_release,
361 .queuecommand = ips_queue,
362 .eh_abort_handler = ips_eh_abort,
363 .eh_host_reset_handler = ips_eh_reset,
365 .show_info = ips_show_info,
366 .write_info = ips_write_info,
367 .slave_configure = ips_slave_configure,
368 .bios_param = ips_biosparam,
370 .sg_tablesize = IPS_MAX_SG,
372 .use_clustering = ENABLE_CLUSTERING,
377 /* This table describes all ServeRAID Adapters */
378 static struct pci_device_id ips_pci_table[] = {
379 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
380 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
381 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
385 MODULE_DEVICE_TABLE( pci, ips_pci_table );
387 static char ips_hot_plug_name[] = "ips";
389 static int ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
390 static void ips_remove_device(struct pci_dev *pci_dev);
392 static struct pci_driver ips_pci_driver = {
393 .name = ips_hot_plug_name,
394 .id_table = ips_pci_table,
395 .probe = ips_insert_device,
396 .remove = ips_remove_device,
401 * Necessary forward function protoypes
403 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
405 #define MAX_ADAPTER_NAME 15
407 static char ips_adapter_name[][30] = {
410 "ServeRAID on motherboard",
411 "ServeRAID on motherboard",
428 static struct notifier_block ips_notifier = {
435 static char ips_command_direction[] = {
436 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
437 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
438 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
439 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
440 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
441 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
442 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
443 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
444 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
445 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
446 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
447 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
448 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
449 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
450 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
451 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
452 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
453 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
454 IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
455 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
456 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
457 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
458 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
459 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
460 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
461 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
462 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
463 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
464 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
465 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
466 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
467 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
468 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
469 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
470 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
471 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
472 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
473 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
474 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
475 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
476 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
477 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
478 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
479 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
480 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
481 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
482 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
483 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
484 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
485 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
486 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
490 /****************************************************************************/
492 /* Routine Name: ips_setup */
494 /* Routine Description: */
496 /* setup parameters to the driver */
498 /****************************************************************************/
500 ips_setup(char *ips_str)
506 IPS_OPTION options[] = {
507 {"noi2o", &ips_force_i2o, 0},
508 {"nommap", &ips_force_memio, 0},
509 {"ioctlsize", &ips_ioctlsize, IPS_IOCTL_SIZE},
510 {"cdboot", &ips_cd_boot, 0},
511 {"maxcmds", &MaxLiteCmds, 32},
514 /* Don't use strtok() anymore ( if 2.4 Kernel or beyond ) */
515 /* Search for value */
516 while ((key = strsep(&ips_str, ",."))) {
519 value = strchr(key, ':');
523 * We now have key/value pairs.
524 * Update the variables
526 for (i = 0; i < ARRAY_SIZE(options); i++) {
528 (key, options[i].option_name,
529 strlen(options[i].option_name)) == 0) {
531 *options[i].option_flag =
532 simple_strtoul(value, NULL, 0);
534 *options[i].option_flag =
535 options[i].option_value;
544 __setup("ips=", ips_setup);
546 /****************************************************************************/
548 /* Routine Name: ips_detect */
550 /* Routine Description: */
552 /* Detect and initialize the driver */
554 /* NOTE: this routine is called under the io_request_lock spinlock */
556 /****************************************************************************/
558 ips_detect(struct scsi_host_template * SHT)
562 METHOD_TRACE("ips_detect", 1);
569 for (i = 0; i < ips_num_controllers; i++) {
570 if (ips_register_scsi(i))
572 ips_released_controllers++;
575 return (ips_num_controllers);
578 /****************************************************************************/
579 /* configure the function pointers to use the functions that will work */
580 /* with the found version of the adapter */
581 /****************************************************************************/
583 ips_setup_funclist(ips_ha_t * ha)
589 if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
590 /* morpheus / marco / sebring */
591 ha->func.isintr = ips_isintr_morpheus;
592 ha->func.isinit = ips_isinit_morpheus;
593 ha->func.issue = ips_issue_i2o_memio;
594 ha->func.init = ips_init_morpheus;
595 ha->func.statupd = ips_statupd_morpheus;
596 ha->func.reset = ips_reset_morpheus;
597 ha->func.intr = ips_intr_morpheus;
598 ha->func.enableint = ips_enable_int_morpheus;
599 } else if (IPS_USE_MEMIO(ha)) {
600 /* copperhead w/MEMIO */
601 ha->func.isintr = ips_isintr_copperhead_memio;
602 ha->func.isinit = ips_isinit_copperhead_memio;
603 ha->func.init = ips_init_copperhead_memio;
604 ha->func.statupd = ips_statupd_copperhead_memio;
605 ha->func.statinit = ips_statinit_memio;
606 ha->func.reset = ips_reset_copperhead_memio;
607 ha->func.intr = ips_intr_copperhead;
608 ha->func.erasebios = ips_erase_bios_memio;
609 ha->func.programbios = ips_program_bios_memio;
610 ha->func.verifybios = ips_verify_bios_memio;
611 ha->func.enableint = ips_enable_int_copperhead_memio;
612 if (IPS_USE_I2O_DELIVER(ha))
613 ha->func.issue = ips_issue_i2o_memio;
615 ha->func.issue = ips_issue_copperhead_memio;
618 ha->func.isintr = ips_isintr_copperhead;
619 ha->func.isinit = ips_isinit_copperhead;
620 ha->func.init = ips_init_copperhead;
621 ha->func.statupd = ips_statupd_copperhead;
622 ha->func.statinit = ips_statinit;
623 ha->func.reset = ips_reset_copperhead;
624 ha->func.intr = ips_intr_copperhead;
625 ha->func.erasebios = ips_erase_bios;
626 ha->func.programbios = ips_program_bios;
627 ha->func.verifybios = ips_verify_bios;
628 ha->func.enableint = ips_enable_int_copperhead;
630 if (IPS_USE_I2O_DELIVER(ha))
631 ha->func.issue = ips_issue_i2o;
633 ha->func.issue = ips_issue_copperhead;
637 /****************************************************************************/
639 /* Routine Name: ips_release */
641 /* Routine Description: */
643 /* Remove a driver */
645 /****************************************************************************/
647 ips_release(struct Scsi_Host *sh)
653 METHOD_TRACE("ips_release", 1);
655 scsi_remove_host(sh);
657 for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++) ;
659 if (i == IPS_MAX_ADAPTERS) {
661 "(%s) release, invalid Scsi_Host pointer.\n", ips_name);
671 /* flush the cache on the controller */
672 scb = &ha->scbs[ha->max_cmds - 1];
674 ips_init_scb(ha, scb);
676 scb->timeout = ips_cmd_timeout;
677 scb->cdb[0] = IPS_CMD_FLUSH;
679 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
680 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
681 scb->cmd.flush_cache.state = IPS_NORM_STATE;
682 scb->cmd.flush_cache.reserved = 0;
683 scb->cmd.flush_cache.reserved2 = 0;
684 scb->cmd.flush_cache.reserved3 = 0;
685 scb->cmd.flush_cache.reserved4 = 0;
687 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
690 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) == IPS_FAILURE)
691 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Incomplete Flush.\n");
693 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Complete.\n");
698 /* free extra memory */
702 free_irq(ha->pcidev->irq, ha);
706 ips_released_controllers++;
711 /****************************************************************************/
713 /* Routine Name: ips_halt */
715 /* Routine Description: */
717 /* Perform cleanup when the system reboots */
719 /****************************************************************************/
721 ips_halt(struct notifier_block *nb, ulong event, void *buf)
727 if ((event != SYS_RESTART) && (event != SYS_HALT) &&
728 (event != SYS_POWER_OFF))
729 return (NOTIFY_DONE);
731 for (i = 0; i < ips_next_controller; i++) {
732 ha = (ips_ha_t *) ips_ha[i];
740 /* flush the cache on the controller */
741 scb = &ha->scbs[ha->max_cmds - 1];
743 ips_init_scb(ha, scb);
745 scb->timeout = ips_cmd_timeout;
746 scb->cdb[0] = IPS_CMD_FLUSH;
748 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
749 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
750 scb->cmd.flush_cache.state = IPS_NORM_STATE;
751 scb->cmd.flush_cache.reserved = 0;
752 scb->cmd.flush_cache.reserved2 = 0;
753 scb->cmd.flush_cache.reserved3 = 0;
754 scb->cmd.flush_cache.reserved4 = 0;
756 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
759 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) ==
761 IPS_PRINTK(KERN_WARNING, ha->pcidev,
762 "Incomplete Flush.\n");
764 IPS_PRINTK(KERN_WARNING, ha->pcidev,
765 "Flushing Complete.\n");
771 /****************************************************************************/
773 /* Routine Name: ips_eh_abort */
775 /* Routine Description: */
777 /* Abort a command (using the new error code stuff) */
778 /* Note: this routine is called under the io_request_lock */
779 /****************************************************************************/
780 int ips_eh_abort(struct scsi_cmnd *SC)
783 ips_copp_wait_item_t *item;
785 struct Scsi_Host *host;
787 METHOD_TRACE("ips_eh_abort", 1);
792 host = SC->device->host;
793 ha = (ips_ha_t *) SC->device->host->hostdata;
801 spin_lock(host->host_lock);
803 /* See if the command is on the copp queue */
804 item = ha->copp_waitlist.head;
805 while ((item) && (item->scsi_cmd != SC))
810 ips_removeq_copp(&ha->copp_waitlist, item);
813 /* See if the command is on the wait queue */
814 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
815 /* command not sent yet */
818 /* command must have already been sent */
822 spin_unlock(host->host_lock);
826 /****************************************************************************/
828 /* Routine Name: ips_eh_reset */
830 /* Routine Description: */
832 /* Reset the controller (with new eh error code) */
834 /* NOTE: this routine is called under the io_request_lock spinlock */
836 /****************************************************************************/
837 static int __ips_eh_reset(struct scsi_cmnd *SC)
843 ips_copp_wait_item_t *item;
845 METHOD_TRACE("ips_eh_reset", 1);
852 DEBUG(1, "Reset called with NULL scsi command");
857 ha = (ips_ha_t *) SC->device->host->hostdata;
860 DEBUG(1, "Reset called with NULL ha struct");
868 /* See if the command is on the copp queue */
869 item = ha->copp_waitlist.head;
870 while ((item) && (item->scsi_cmd != SC))
875 ips_removeq_copp(&ha->copp_waitlist, item);
879 /* See if the command is on the wait queue */
880 if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
881 /* command not sent yet */
885 /* An explanation for the casual observer: */
886 /* Part of the function of a RAID controller is automatic error */
887 /* detection and recovery. As such, the only problem that physically */
888 /* resetting an adapter will ever fix is when, for some reason, */
889 /* the driver is not successfully communicating with the adapter. */
890 /* Therefore, we will attempt to flush this adapter. If that succeeds, */
891 /* then there's no real purpose in a physical reset. This will complete */
892 /* much faster and avoids any problems that might be caused by a */
893 /* physical reset ( such as having to fail all the outstanding I/O's ). */
895 if (ha->ioctl_reset == 0) { /* IF Not an IOCTL Requested Reset */
896 scb = &ha->scbs[ha->max_cmds - 1];
898 ips_init_scb(ha, scb);
900 scb->timeout = ips_cmd_timeout;
901 scb->cdb[0] = IPS_CMD_FLUSH;
903 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
904 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
905 scb->cmd.flush_cache.state = IPS_NORM_STATE;
906 scb->cmd.flush_cache.reserved = 0;
907 scb->cmd.flush_cache.reserved2 = 0;
908 scb->cmd.flush_cache.reserved3 = 0;
909 scb->cmd.flush_cache.reserved4 = 0;
911 /* Attempt the flush command */
912 ret = ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_IORL);
913 if (ret == IPS_SUCCESS) {
914 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
915 "Reset Request - Flushed Cache\n");
920 /* Either we can't communicate with the adapter or it's an IOCTL request */
921 /* from a utility. A physical reset is needed at this point. */
923 ha->ioctl_reset = 0; /* Reset the IOCTL Requested Reset Flag */
926 * command must have already been sent
927 * reset the controller
929 IPS_PRINTK(KERN_NOTICE, ha->pcidev, "Resetting controller.\n");
930 ret = (*ha->func.reset) (ha);
933 struct scsi_cmnd *scsi_cmd;
935 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
936 "Controller reset failed - controller now offline.\n");
938 /* Now fail all of the active commands */
939 DEBUG_VAR(1, "(%s%d) Failing active commands",
940 ips_name, ha->host_num);
942 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
943 scb->scsi_cmd->result = DID_ERROR << 16;
944 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
945 ips_freescb(ha, scb);
948 /* Now fail all of the pending commands */
949 DEBUG_VAR(1, "(%s%d) Failing pending commands",
950 ips_name, ha->host_num);
952 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
953 scsi_cmd->result = DID_ERROR;
954 scsi_cmd->scsi_done(scsi_cmd);
961 if (!ips_clear_adapter(ha, IPS_INTR_IORL)) {
962 struct scsi_cmnd *scsi_cmd;
964 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
965 "Controller reset failed - controller now offline.\n");
967 /* Now fail all of the active commands */
968 DEBUG_VAR(1, "(%s%d) Failing active commands",
969 ips_name, ha->host_num);
971 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
972 scb->scsi_cmd->result = DID_ERROR << 16;
973 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
974 ips_freescb(ha, scb);
977 /* Now fail all of the pending commands */
978 DEBUG_VAR(1, "(%s%d) Failing pending commands",
979 ips_name, ha->host_num);
981 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
982 scsi_cmd->result = DID_ERROR << 16;
983 scsi_cmd->scsi_done(scsi_cmd);
991 if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
994 do_gettimeofday(&tv);
995 ha->last_ffdc = tv.tv_sec;
997 ips_ffdc_reset(ha, IPS_INTR_IORL);
1000 /* Now fail all of the active commands */
1001 DEBUG_VAR(1, "(%s%d) Failing active commands", ips_name, ha->host_num);
1003 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1004 scb->scsi_cmd->result = DID_RESET << 16;
1005 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1006 ips_freescb(ha, scb);
1009 /* Reset DCDB active command bits */
1010 for (i = 1; i < ha->nbus; i++)
1011 ha->dcdb_active[i - 1] = 0;
1013 /* Reset the number of active IOCTLs */
1016 ips_next(ha, IPS_INTR_IORL);
1019 #endif /* NO_IPS_RESET */
1023 static int ips_eh_reset(struct scsi_cmnd *SC)
1027 spin_lock_irq(SC->device->host->host_lock);
1028 rc = __ips_eh_reset(SC);
1029 spin_unlock_irq(SC->device->host->host_lock);
1034 /****************************************************************************/
1036 /* Routine Name: ips_queue */
1038 /* Routine Description: */
1040 /* Send a command to the controller */
1043 /* Linux obtains io_request_lock before calling this function */
1045 /****************************************************************************/
1046 static int ips_queue_lck(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *))
1051 METHOD_TRACE("ips_queue", 1);
1053 ha = (ips_ha_t *) SC->device->host->hostdata;
1061 if (ips_is_passthru(SC)) {
1062 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1063 SC->result = DID_BUS_BUSY << 16;
1068 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1069 SC->result = DID_BUS_BUSY << 16;
1075 SC->scsi_done = done;
1077 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1081 SC->device->channel, SC->device->id, SC->device->lun);
1083 /* Check for command to initiator IDs */
1084 if ((scmd_channel(SC) > 0)
1085 && (scmd_id(SC) == ha->ha_id[scmd_channel(SC)])) {
1086 SC->result = DID_NO_CONNECT << 16;
1092 if (ips_is_passthru(SC)) {
1094 ips_copp_wait_item_t *scratch;
1096 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1097 /* There can never be any system activity ( network or disk ), but check */
1098 /* anyway just as a good practice. */
1099 pt = (ips_passthru_t *) scsi_sglist(SC);
1100 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1101 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1102 if (ha->scb_activelist.count != 0) {
1103 SC->result = DID_BUS_BUSY << 16;
1107 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1109 SC->result = DID_OK << 16;
1114 /* allocate space for the scribble */
1115 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1118 SC->result = DID_ERROR << 16;
1124 scratch->scsi_cmd = SC;
1125 scratch->next = NULL;
1127 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1129 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1132 ips_next(ha, IPS_INTR_IORL);
1137 static DEF_SCSI_QCMD(ips_queue)
1139 /****************************************************************************/
1141 /* Routine Name: ips_biosparam */
1143 /* Routine Description: */
1145 /* Set bios geometry for the controller */
1147 /****************************************************************************/
1148 static int ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1149 sector_t capacity, int geom[])
1151 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1156 METHOD_TRACE("ips_biosparam", 1);
1159 /* ?!?! host adater info invalid */
1165 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1166 /* ?!?! Enquiry command failed */
1169 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1170 heads = IPS_NORM_HEADS;
1171 sectors = IPS_NORM_SECTORS;
1173 heads = IPS_COMP_HEADS;
1174 sectors = IPS_COMP_SECTORS;
1177 cylinders = (unsigned long) capacity / (heads * sectors);
1179 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1180 heads, sectors, cylinders);
1184 geom[2] = cylinders;
1189 /****************************************************************************/
1191 /* Routine Name: ips_slave_configure */
1193 /* Routine Description: */
1195 /* Set queue depths on devices once scan is complete */
1197 /****************************************************************************/
1199 ips_slave_configure(struct scsi_device * SDptr)
1204 ha = IPS_HA(SDptr->host);
1205 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1206 min = ha->max_cmds / 2;
1207 if (ha->enq->ucLogDriveCount <= 2)
1208 min = ha->max_cmds - 1;
1209 scsi_change_queue_depth(SDptr, min);
1212 SDptr->skip_ms_page_8 = 1;
1213 SDptr->skip_ms_page_3f = 1;
1217 /****************************************************************************/
1219 /* Routine Name: do_ipsintr */
1221 /* Routine Description: */
1223 /* Wrapper for the interrupt handler */
1225 /****************************************************************************/
1227 do_ipsintr(int irq, void *dev_id)
1230 struct Scsi_Host *host;
1233 METHOD_TRACE("do_ipsintr", 2);
1235 ha = (ips_ha_t *) dev_id;
1238 host = ips_sh[ha->host_num];
1239 /* interrupt during initialization */
1241 (*ha->func.intr) (ha);
1245 spin_lock(host->host_lock);
1248 spin_unlock(host->host_lock);
1252 irqstatus = (*ha->func.intr) (ha);
1254 spin_unlock(host->host_lock);
1256 /* start the next command */
1257 ips_next(ha, IPS_INTR_ON);
1258 return IRQ_RETVAL(irqstatus);
1261 /****************************************************************************/
1263 /* Routine Name: ips_intr_copperhead */
1265 /* Routine Description: */
1267 /* Polling interrupt handler */
1269 /* ASSUMES interrupts are disabled */
1271 /****************************************************************************/
1273 ips_intr_copperhead(ips_ha_t * ha)
1280 METHOD_TRACE("ips_intr", 2);
1288 intrstatus = (*ha->func.isintr) (ha);
1292 * Unexpected/Shared interrupt
1301 intrstatus = (*ha->func.isintr) (ha);
1306 cstatus.value = (*ha->func.statupd) (ha);
1308 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1309 /* Spurious Interrupt ? */
1313 ips_chkstatus(ha, &cstatus);
1314 scb = (ips_scb_t *) sp->scb_addr;
1317 * use the callback function to finish things up
1318 * NOTE: interrupts are OFF for this
1320 (*scb->callback) (ha, scb);
1325 /****************************************************************************/
1327 /* Routine Name: ips_intr_morpheus */
1329 /* Routine Description: */
1331 /* Polling interrupt handler */
1333 /* ASSUMES interrupts are disabled */
1335 /****************************************************************************/
1337 ips_intr_morpheus(ips_ha_t * ha)
1344 METHOD_TRACE("ips_intr_morpheus", 2);
1352 intrstatus = (*ha->func.isintr) (ha);
1356 * Unexpected/Shared interrupt
1365 intrstatus = (*ha->func.isintr) (ha);
1370 cstatus.value = (*ha->func.statupd) (ha);
1372 if (cstatus.value == 0xffffffff)
1373 /* No more to process */
1376 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1377 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1378 "Spurious interrupt; no ccb.\n");
1383 ips_chkstatus(ha, &cstatus);
1384 scb = (ips_scb_t *) sp->scb_addr;
1387 * use the callback function to finish things up
1388 * NOTE: interrupts are OFF for this
1390 (*scb->callback) (ha, scb);
1395 /****************************************************************************/
1397 /* Routine Name: ips_info */
1399 /* Routine Description: */
1401 /* Return info about the driver */
1403 /****************************************************************************/
1405 ips_info(struct Scsi_Host *SH)
1407 static char buffer[256];
1411 METHOD_TRACE("ips_info", 1);
1419 memset(bp, 0, sizeof (buffer));
1421 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1422 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1424 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1426 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1434 ips_write_info(struct Scsi_Host *host, char *buffer, int length)
1437 ips_ha_t *ha = NULL;
1439 /* Find our host structure */
1440 for (i = 0; i < ips_next_controller; i++) {
1442 if (ips_sh[i] == host) {
1443 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1456 ips_show_info(struct seq_file *m, struct Scsi_Host *host)
1459 ips_ha_t *ha = NULL;
1461 /* Find our host structure */
1462 for (i = 0; i < ips_next_controller; i++) {
1464 if (ips_sh[i] == host) {
1465 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1474 return ips_host_info(ha, m);
1477 /*--------------------------------------------------------------------------*/
1478 /* Helper Functions */
1479 /*--------------------------------------------------------------------------*/
1481 /****************************************************************************/
1483 /* Routine Name: ips_is_passthru */
1485 /* Routine Description: */
1487 /* Determine if the specified SCSI command is really a passthru command */
1489 /****************************************************************************/
1490 static int ips_is_passthru(struct scsi_cmnd *SC)
1492 unsigned long flags;
1494 METHOD_TRACE("ips_is_passthru", 1);
1499 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1500 (SC->device->channel == 0) &&
1501 (SC->device->id == IPS_ADAPTER_ID) &&
1502 (SC->device->lun == 0) && scsi_sglist(SC)) {
1503 struct scatterlist *sg = scsi_sglist(SC);
1506 /* kmap_atomic() ensures addressability of the user buffer.*/
1507 /* local_irq_save() protects the KM_IRQ0 address slot. */
1508 local_irq_save(flags);
1509 buffer = kmap_atomic(sg_page(sg)) + sg->offset;
1510 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1511 buffer[2] == 'P' && buffer[3] == 'P') {
1512 kunmap_atomic(buffer - sg->offset);
1513 local_irq_restore(flags);
1516 kunmap_atomic(buffer - sg->offset);
1517 local_irq_restore(flags);
1522 /****************************************************************************/
1524 /* Routine Name: ips_alloc_passthru_buffer */
1526 /* Routine Description: */
1527 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1528 /* is too small or doesn't exist */
1529 /****************************************************************************/
1531 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1534 dma_addr_t dma_busaddr;
1536 if (ha->ioctl_data && length <= ha->ioctl_len)
1538 /* there is no buffer or it's not big enough, allocate a new one */
1539 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1541 /* free the old memory */
1542 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1544 /* use the new memory */
1545 ha->ioctl_data = (char *) bigger_buf;
1546 ha->ioctl_len = length;
1547 ha->ioctl_busaddr = dma_busaddr;
1554 /****************************************************************************/
1556 /* Routine Name: ips_make_passthru */
1558 /* Routine Description: */
1560 /* Make a passthru command out of the info in the Scsi block */
1562 /****************************************************************************/
1564 ips_make_passthru(ips_ha_t *ha, struct scsi_cmnd *SC, ips_scb_t *scb, int intr)
1569 struct scatterlist *sg = scsi_sglist(SC);
1571 METHOD_TRACE("ips_make_passthru", 1);
1573 scsi_for_each_sg(SC, sg, scsi_sg_count(SC), i)
1574 length += sg->length;
1576 if (length < sizeof (ips_passthru_t)) {
1578 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1579 ips_name, ha->host_num);
1580 return (IPS_FAILURE);
1582 if (ips_alloc_passthru_buffer(ha, length)) {
1583 /* allocation failure! If ha->ioctl_data exists, use it to return
1584 some error codes. Return a failed command to the scsi layer. */
1585 if (ha->ioctl_data) {
1586 pt = (ips_passthru_t *) ha->ioctl_data;
1587 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1588 pt->BasicStatus = 0x0B;
1589 pt->ExtendedStatus = 0x00;
1590 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1594 ha->ioctl_datasize = length;
1596 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1597 pt = (ips_passthru_t *) ha->ioctl_data;
1600 * Some notes about the passthru interface used
1602 * IF the scsi op_code == 0x0d then we assume
1603 * that the data came along with/goes with the
1604 * packet we received from the sg driver. In this
1605 * case the CmdBSize field of the pt structure is
1606 * used for the size of the buffer.
1609 switch (pt->CoppCmd) {
1611 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1612 &ips_num_controllers, sizeof (int));
1613 ips_scmd_buf_write(SC, ha->ioctl_data,
1614 sizeof (ips_passthru_t) + sizeof (int));
1615 SC->result = DID_OK << 16;
1617 return (IPS_SUCCESS_IMM);
1619 case IPS_COPPUSRCMD:
1620 case IPS_COPPIOCCMD:
1621 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1622 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1625 "(%s%d) Passthru structure wrong size",
1626 ips_name, ha->host_num);
1628 return (IPS_FAILURE);
1631 if (ha->pcidev->device == IPS_DEVICEID_COPPERHEAD &&
1632 pt->CoppCP.cmd.flashfw.op_code ==
1633 IPS_CMD_RW_BIOSFW) {
1634 ret = ips_flash_copperhead(ha, pt, scb);
1635 ips_scmd_buf_write(SC, ha->ioctl_data,
1636 sizeof (ips_passthru_t));
1639 if (ips_usrcmd(ha, pt, scb))
1640 return (IPS_SUCCESS);
1642 return (IPS_FAILURE);
1649 return (IPS_FAILURE);
1652 /****************************************************************************/
1653 /* Routine Name: ips_flash_copperhead */
1654 /* Routine Description: */
1655 /* Flash the BIOS/FW on a Copperhead style controller */
1656 /****************************************************************************/
1658 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1662 /* Trombone is the only copperhead that can do packet flash, but only
1663 * for firmware. No one said it had to make sense. */
1664 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1665 if (ips_usrcmd(ha, pt, scb))
1670 pt->BasicStatus = 0x0B;
1671 pt->ExtendedStatus = 0;
1672 scb->scsi_cmd->result = DID_OK << 16;
1673 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1674 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1675 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1676 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1677 pt->BasicStatus = 0;
1678 return ips_flash_bios(ha, pt, scb);
1679 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1680 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1681 ha->flash_data = ips_FlashData;
1682 ha->flash_busaddr = ips_flashbusaddr;
1683 ha->flash_len = PAGE_SIZE << 7;
1684 ha->flash_datasize = 0;
1685 } else if (!ha->flash_data) {
1686 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1687 pt->CoppCP.cmd.flashfw.count;
1688 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1690 &ha->flash_busaddr);
1691 if (!ha->flash_data){
1692 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1695 ha->flash_datasize = 0;
1696 ha->flash_len = datasize;
1700 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1702 ips_free_flash_copperhead(ha);
1703 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1704 "failed size sanity check\n");
1708 if (!ha->flash_data)
1710 pt->BasicStatus = 0;
1711 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1712 pt->CoppCP.cmd.flashfw.count);
1713 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1714 if (pt->CoppCP.cmd.flashfw.packet_num ==
1715 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1716 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1717 return ips_flash_bios(ha, pt, scb);
1718 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1719 return ips_flash_firmware(ha, pt, scb);
1721 return IPS_SUCCESS_IMM;
1724 /****************************************************************************/
1725 /* Routine Name: ips_flash_bios */
1726 /* Routine Description: */
1727 /* flashes the bios of a copperhead adapter */
1728 /****************************************************************************/
1730 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1733 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1734 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1735 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1736 (!ha->func.verifybios))
1738 if ((*ha->func.erasebios) (ha)) {
1740 "(%s%d) flash bios failed - unable to erase flash",
1741 ips_name, ha->host_num);
1744 if ((*ha->func.programbios) (ha,
1747 ha->flash_datasize -
1748 IPS_BIOS_HEADER, 0)) {
1750 "(%s%d) flash bios failed - unable to flash",
1751 ips_name, ha->host_num);
1754 if ((*ha->func.verifybios) (ha,
1757 ha->flash_datasize -
1758 IPS_BIOS_HEADER, 0)) {
1760 "(%s%d) flash bios failed - unable to verify flash",
1761 ips_name, ha->host_num);
1764 ips_free_flash_copperhead(ha);
1765 return IPS_SUCCESS_IMM;
1766 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1767 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1768 if (!ha->func.erasebios)
1770 if ((*ha->func.erasebios) (ha)) {
1772 "(%s%d) flash bios failed - unable to erase flash",
1773 ips_name, ha->host_num);
1776 return IPS_SUCCESS_IMM;
1779 pt->BasicStatus = 0x0B;
1780 pt->ExtendedStatus = 0x00;
1781 ips_free_flash_copperhead(ha);
1785 /****************************************************************************/
1787 /* Routine Name: ips_fill_scb_sg_single */
1789 /* Routine Description: */
1790 /* Fill in a single scb sg_list element from an address */
1791 /* return a -1 if a breakup occurred */
1792 /****************************************************************************/
1794 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1795 ips_scb_t * scb, int indx, unsigned int e_len)
1800 if ((scb->data_len + e_len) > ha->max_xfer) {
1801 e_len = ha->max_xfer - scb->data_len;
1802 scb->breakup = indx;
1809 if (IPS_USE_ENH_SGLIST(ha)) {
1810 scb->sg_list.enh_list[indx].address_lo =
1811 cpu_to_le32(pci_dma_lo32(busaddr));
1812 scb->sg_list.enh_list[indx].address_hi =
1813 cpu_to_le32(pci_dma_hi32(busaddr));
1814 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1816 scb->sg_list.std_list[indx].address =
1817 cpu_to_le32(pci_dma_lo32(busaddr));
1818 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1822 scb->data_len += e_len;
1826 /****************************************************************************/
1827 /* Routine Name: ips_flash_firmware */
1828 /* Routine Description: */
1829 /* flashes the firmware of a copperhead adapter */
1830 /****************************************************************************/
1832 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1834 IPS_SG_LIST sg_list;
1835 uint32_t cmd_busaddr;
1837 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1838 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1839 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1840 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1841 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1843 pt->BasicStatus = 0x0B;
1844 pt->ExtendedStatus = 0x00;
1845 ips_free_flash_copperhead(ha);
1848 /* Save the S/G list pointer so it doesn't get clobbered */
1849 sg_list.list = scb->sg_list.list;
1850 cmd_busaddr = scb->scb_busaddr;
1851 /* copy in the CP */
1852 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1853 /* FIX stuff that might be wrong */
1854 scb->sg_list.list = sg_list.list;
1855 scb->scb_busaddr = cmd_busaddr;
1856 scb->bus = scb->scsi_cmd->device->channel;
1857 scb->target_id = scb->scsi_cmd->device->id;
1858 scb->lun = scb->scsi_cmd->device->lun;
1863 scb->callback = ipsintr_done;
1864 scb->timeout = ips_cmd_timeout;
1866 scb->data_len = ha->flash_datasize;
1868 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1870 scb->flags |= IPS_SCB_MAP_SINGLE;
1871 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1872 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1874 scb->timeout = pt->TimeOut;
1875 scb->scsi_cmd->result = DID_OK << 16;
1879 /****************************************************************************/
1880 /* Routine Name: ips_free_flash_copperhead */
1881 /* Routine Description: */
1882 /* release the memory resources used to hold the flash image */
1883 /****************************************************************************/
1885 ips_free_flash_copperhead(ips_ha_t * ha)
1887 if (ha->flash_data == ips_FlashData)
1888 test_and_clear_bit(0, &ips_FlashDataInUse);
1889 else if (ha->flash_data)
1890 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
1892 ha->flash_data = NULL;
1895 /****************************************************************************/
1897 /* Routine Name: ips_usrcmd */
1899 /* Routine Description: */
1901 /* Process a user command and make it ready to send */
1903 /****************************************************************************/
1905 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1907 IPS_SG_LIST sg_list;
1908 uint32_t cmd_busaddr;
1910 METHOD_TRACE("ips_usrcmd", 1);
1912 if ((!scb) || (!pt) || (!ha))
1915 /* Save the S/G list pointer so it doesn't get clobbered */
1916 sg_list.list = scb->sg_list.list;
1917 cmd_busaddr = scb->scb_busaddr;
1918 /* copy in the CP */
1919 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1920 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
1922 /* FIX stuff that might be wrong */
1923 scb->sg_list.list = sg_list.list;
1924 scb->scb_busaddr = cmd_busaddr;
1925 scb->bus = scb->scsi_cmd->device->channel;
1926 scb->target_id = scb->scsi_cmd->device->id;
1927 scb->lun = scb->scsi_cmd->device->lun;
1932 scb->callback = ipsintr_done;
1933 scb->timeout = ips_cmd_timeout;
1934 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
1936 /* we don't support DCDB/READ/WRITE Scatter Gather */
1937 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
1938 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
1939 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
1943 scb->data_len = pt->CmdBSize;
1944 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
1946 scb->data_busaddr = 0L;
1949 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
1950 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
1951 (unsigned long) &scb->
1953 (unsigned long) scb);
1956 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
1957 scb->dcdb.buffer_pointer =
1958 cpu_to_le32(scb->data_busaddr);
1960 scb->cmd.basic_io.sg_addr =
1961 cpu_to_le32(scb->data_busaddr);
1966 scb->timeout = pt->TimeOut;
1968 if (pt->TimeOut <= 10)
1969 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
1970 else if (pt->TimeOut <= 60)
1971 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
1973 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
1976 /* assume success */
1977 scb->scsi_cmd->result = DID_OK << 16;
1983 /****************************************************************************/
1985 /* Routine Name: ips_cleanup_passthru */
1987 /* Routine Description: */
1989 /* Cleanup after a passthru command */
1991 /****************************************************************************/
1993 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
1997 METHOD_TRACE("ips_cleanup_passthru", 1);
1999 if ((!scb) || (!scb->scsi_cmd) || (!scsi_sglist(scb->scsi_cmd))) {
2000 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2001 ips_name, ha->host_num);
2005 pt = (ips_passthru_t *) ha->ioctl_data;
2007 /* Copy data back to the user */
2008 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2009 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2011 pt->BasicStatus = scb->basic_status;
2012 pt->ExtendedStatus = scb->extended_status;
2013 pt->AdapterType = ha->ad_type;
2015 if (ha->pcidev->device == IPS_DEVICEID_COPPERHEAD &&
2016 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2017 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2018 ips_free_flash_copperhead(ha);
2020 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2023 /****************************************************************************/
2025 /* Routine Name: ips_host_info */
2027 /* Routine Description: */
2029 /* The passthru interface for the driver */
2031 /****************************************************************************/
2033 ips_host_info(ips_ha_t *ha, struct seq_file *m)
2035 METHOD_TRACE("ips_host_info", 1);
2037 seq_puts(m, "\nIBM ServeRAID General Information:\n\n");
2039 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2040 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2041 seq_printf(m, "\tController Type : %s\n",
2042 ips_adapter_name[ha->ad_type - 1]);
2044 seq_puts(m, "\tController Type : Unknown\n");
2048 "\tIO region : 0x%x (%d bytes)\n",
2049 ha->io_addr, ha->io_len);
2053 "\tMemory region : 0x%x (%d bytes)\n",
2054 ha->mem_addr, ha->mem_len);
2056 "\tShared memory address : 0x%lx\n",
2057 (unsigned long)ha->mem_ptr);
2060 seq_printf(m, "\tIRQ number : %d\n", ha->pcidev->irq);
2062 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2063 /* That keeps everything happy for "text" operations on the proc file. */
2065 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2066 if (ha->nvram->bios_low[3] == 0) {
2068 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2069 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2070 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2071 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2072 ha->nvram->bios_low[2]);
2076 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2077 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2078 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2079 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2080 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2085 if (ha->enq->CodeBlkVersion[7] == 0) {
2087 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2088 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2089 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2090 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2091 ha->enq->CodeBlkVersion[6]);
2094 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2095 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2096 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2097 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2098 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2101 if (ha->enq->BootBlkVersion[7] == 0) {
2103 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2104 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2105 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2106 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2107 ha->enq->BootBlkVersion[6]);
2110 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2111 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2112 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2113 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2114 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2117 seq_printf(m, "\tDriver Version : %s%s\n",
2118 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2120 seq_printf(m, "\tDriver Build : %d\n",
2123 seq_printf(m, "\tMax Physical Devices : %d\n",
2124 ha->enq->ucMaxPhysicalDevices);
2125 seq_printf(m, "\tMax Active Commands : %d\n",
2127 seq_printf(m, "\tCurrent Queued Commands : %d\n",
2128 ha->scb_waitlist.count);
2129 seq_printf(m, "\tCurrent Active Commands : %d\n",
2130 ha->scb_activelist.count - ha->num_ioctl);
2131 seq_printf(m, "\tCurrent Queued PT Commands : %d\n",
2132 ha->copp_waitlist.count);
2133 seq_printf(m, "\tCurrent Active PT Commands : %d\n",
2141 /****************************************************************************/
2143 /* Routine Name: ips_identify_controller */
2145 /* Routine Description: */
2147 /* Identify this controller */
2149 /****************************************************************************/
2151 ips_identify_controller(ips_ha_t * ha)
2153 METHOD_TRACE("ips_identify_controller", 1);
2155 switch (ha->pcidev->device) {
2156 case IPS_DEVICEID_COPPERHEAD:
2157 if (ha->pcidev->revision <= IPS_REVID_SERVERAID) {
2158 ha->ad_type = IPS_ADTYPE_SERVERAID;
2159 } else if (ha->pcidev->revision == IPS_REVID_SERVERAID2) {
2160 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2161 } else if (ha->pcidev->revision == IPS_REVID_NAVAJO) {
2162 ha->ad_type = IPS_ADTYPE_NAVAJO;
2163 } else if ((ha->pcidev->revision == IPS_REVID_SERVERAID2)
2164 && (ha->slot_num == 0)) {
2165 ha->ad_type = IPS_ADTYPE_KIOWA;
2166 } else if ((ha->pcidev->revision >= IPS_REVID_CLARINETP1) &&
2167 (ha->pcidev->revision <= IPS_REVID_CLARINETP3)) {
2168 if (ha->enq->ucMaxPhysicalDevices == 15)
2169 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2171 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2172 } else if ((ha->pcidev->revision >= IPS_REVID_TROMBONE32) &&
2173 (ha->pcidev->revision <= IPS_REVID_TROMBONE64)) {
2174 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2178 case IPS_DEVICEID_MORPHEUS:
2179 switch (ha->pcidev->subsystem_device) {
2180 case IPS_SUBDEVICEID_4L:
2181 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2184 case IPS_SUBDEVICEID_4M:
2185 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2188 case IPS_SUBDEVICEID_4MX:
2189 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2192 case IPS_SUBDEVICEID_4LX:
2193 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2196 case IPS_SUBDEVICEID_5I2:
2197 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2200 case IPS_SUBDEVICEID_5I1:
2201 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2207 case IPS_DEVICEID_MARCO:
2208 switch (ha->pcidev->subsystem_device) {
2209 case IPS_SUBDEVICEID_6M:
2210 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2212 case IPS_SUBDEVICEID_6I:
2213 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2215 case IPS_SUBDEVICEID_7k:
2216 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2218 case IPS_SUBDEVICEID_7M:
2219 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2226 /****************************************************************************/
2228 /* Routine Name: ips_get_bios_version */
2230 /* Routine Description: */
2232 /* Get the BIOS revision number */
2234 /****************************************************************************/
2236 ips_get_bios_version(ips_ha_t * ha, int intr)
2245 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2248 METHOD_TRACE("ips_get_bios_version", 1);
2253 strncpy(ha->bios_version, " ?", 8);
2255 if (ha->pcidev->device == IPS_DEVICEID_COPPERHEAD) {
2256 if (IPS_USE_MEMIO(ha)) {
2257 /* Memory Mapped I/O */
2260 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2261 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2262 udelay(25); /* 25 us */
2264 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2267 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2268 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2269 udelay(25); /* 25 us */
2271 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2274 /* Get Major version */
2275 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2276 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2277 udelay(25); /* 25 us */
2279 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2281 /* Get Minor version */
2282 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2283 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2284 udelay(25); /* 25 us */
2285 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2287 /* Get SubMinor version */
2288 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2289 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2290 udelay(25); /* 25 us */
2291 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2294 /* Programmed I/O */
2297 outl(0, ha->io_addr + IPS_REG_FLAP);
2298 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2299 udelay(25); /* 25 us */
2301 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2304 outl(1, ha->io_addr + IPS_REG_FLAP);
2305 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2306 udelay(25); /* 25 us */
2308 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2311 /* Get Major version */
2312 outl(0x1FF, ha->io_addr + IPS_REG_FLAP);
2313 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2314 udelay(25); /* 25 us */
2316 major = inb(ha->io_addr + IPS_REG_FLDP);
2318 /* Get Minor version */
2319 outl(0x1FE, ha->io_addr + IPS_REG_FLAP);
2320 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2321 udelay(25); /* 25 us */
2323 minor = inb(ha->io_addr + IPS_REG_FLDP);
2325 /* Get SubMinor version */
2326 outl(0x1FD, ha->io_addr + IPS_REG_FLAP);
2327 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
2328 udelay(25); /* 25 us */
2330 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2334 /* Morpheus Family - Send Command to the card */
2336 buffer = ha->ioctl_data;
2338 memset(buffer, 0, 0x1000);
2340 scb = &ha->scbs[ha->max_cmds - 1];
2342 ips_init_scb(ha, scb);
2344 scb->timeout = ips_cmd_timeout;
2345 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2347 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2348 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2349 scb->cmd.flashfw.type = 1;
2350 scb->cmd.flashfw.direction = 0;
2351 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2352 scb->cmd.flashfw.total_packets = 1;
2353 scb->cmd.flashfw.packet_num = 0;
2354 scb->data_len = 0x1000;
2355 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2357 /* issue the command */
2359 ips_send_wait(ha, scb, ips_cmd_timeout,
2360 intr)) == IPS_FAILURE)
2361 || (ret == IPS_SUCCESS_IMM)
2362 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2363 /* Error occurred */
2368 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2369 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2370 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2371 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2377 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2378 ha->bios_version[1] = '.';
2379 ha->bios_version[2] = hexDigits[major & 0x0F];
2380 ha->bios_version[3] = hexDigits[subminor];
2381 ha->bios_version[4] = '.';
2382 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2383 ha->bios_version[6] = hexDigits[minor & 0x0F];
2384 ha->bios_version[7] = 0;
2387 /****************************************************************************/
2389 /* Routine Name: ips_hainit */
2391 /* Routine Description: */
2393 /* Initialize the controller */
2395 /* NOTE: Assumes to be called from with a lock */
2397 /****************************************************************************/
2399 ips_hainit(ips_ha_t * ha)
2404 METHOD_TRACE("ips_hainit", 1);
2409 if (ha->func.statinit)
2410 (*ha->func.statinit) (ha);
2412 if (ha->func.enableint)
2413 (*ha->func.enableint) (ha);
2416 ha->reset_count = 1;
2417 do_gettimeofday(&tv);
2418 ha->last_ffdc = tv.tv_sec;
2419 ips_ffdc_reset(ha, IPS_INTR_IORL);
2421 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2422 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2423 "unable to read config from controller.\n");
2428 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2429 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2430 "unable to read controller status.\n");
2435 /* Identify this controller */
2436 ips_identify_controller(ha);
2438 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2439 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2440 "unable to read subsystem parameters.\n");
2445 /* write nvram user page 5 */
2446 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2447 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2448 "unable to write driver info to controller.\n");
2453 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2454 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2455 ips_clear_adapter(ha, IPS_INTR_IORL);
2457 /* set limits on SID, LUN, BUS */
2458 ha->ntargets = IPS_MAX_TARGETS + 1;
2460 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2462 switch (ha->conf->logical_drive[0].ucStripeSize) {
2464 ha->max_xfer = 0x10000;
2468 ha->max_xfer = 0x20000;
2472 ha->max_xfer = 0x40000;
2477 ha->max_xfer = 0x80000;
2481 /* setup max concurrent commands */
2482 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2483 /* Use the new method */
2484 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2486 /* use the old method */
2487 switch (ha->conf->logical_drive[0].ucStripeSize) {
2507 /* Limit the Active Commands on a Lite Adapter */
2508 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2509 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2510 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2511 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2512 ha->max_cmds = MaxLiteCmds;
2515 /* set controller IDs */
2516 ha->ha_id[0] = IPS_ADAPTER_ID;
2517 for (i = 1; i < ha->nbus; i++) {
2518 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2519 ha->dcdb_active[i - 1] = 0;
2525 /****************************************************************************/
2527 /* Routine Name: ips_next */
2529 /* Routine Description: */
2531 /* Take the next command off the queue and send it to the controller */
2533 /****************************************************************************/
2535 ips_next(ips_ha_t * ha, int intr)
2538 struct scsi_cmnd *SC;
2539 struct scsi_cmnd *p;
2540 struct scsi_cmnd *q;
2541 ips_copp_wait_item_t *item;
2543 struct Scsi_Host *host;
2544 METHOD_TRACE("ips_next", 1);
2548 host = ips_sh[ha->host_num];
2550 * Block access to the queue function so
2551 * this command won't time out
2553 if (intr == IPS_INTR_ON)
2554 spin_lock(host->host_lock);
2556 if ((ha->subsys->param[3] & 0x300000)
2557 && (ha->scb_activelist.count == 0)) {
2560 do_gettimeofday(&tv);
2562 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2563 ha->last_ffdc = tv.tv_sec;
2569 * Send passthru commands
2570 * These have priority over normal I/O
2571 * but shouldn't affect performance too much
2572 * since we limit the number that can be active
2573 * on the card at any one time
2575 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2576 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2578 item = ips_removeq_copp_head(&ha->copp_waitlist);
2580 if (intr == IPS_INTR_ON)
2581 spin_unlock(host->host_lock);
2582 scb->scsi_cmd = item->scsi_cmd;
2585 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2587 if (intr == IPS_INTR_ON)
2588 spin_lock(host->host_lock);
2591 if (scb->scsi_cmd) {
2592 scb->scsi_cmd->result = DID_ERROR << 16;
2593 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2596 ips_freescb(ha, scb);
2598 case IPS_SUCCESS_IMM:
2599 if (scb->scsi_cmd) {
2600 scb->scsi_cmd->result = DID_OK << 16;
2601 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2604 ips_freescb(ha, scb);
2610 if (ret != IPS_SUCCESS) {
2615 ret = ips_send_cmd(ha, scb);
2617 if (ret == IPS_SUCCESS)
2618 ips_putq_scb_head(&ha->scb_activelist, scb);
2624 if (scb->scsi_cmd) {
2625 scb->scsi_cmd->result = DID_ERROR << 16;
2628 ips_freescb(ha, scb);
2630 case IPS_SUCCESS_IMM:
2631 ips_freescb(ha, scb);
2640 * Send "Normal" I/O commands
2643 p = ha->scb_waitlist.head;
2644 while ((p) && (scb = ips_getscb(ha))) {
2645 if ((scmd_channel(p) > 0)
2647 dcdb_active[scmd_channel(p) -
2648 1] & (1 << scmd_id(p)))) {
2649 ips_freescb(ha, scb);
2650 p = (struct scsi_cmnd *) p->host_scribble;
2655 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2657 if (intr == IPS_INTR_ON)
2658 spin_unlock(host->host_lock); /* Unlock HA after command is taken off queue */
2660 SC->result = DID_OK;
2661 SC->host_scribble = NULL;
2663 scb->target_id = SC->device->id;
2664 scb->lun = SC->device->lun;
2665 scb->bus = SC->device->channel;
2669 scb->callback = ipsintr_done;
2670 scb->timeout = ips_cmd_timeout;
2671 memset(&scb->cmd, 0, 16);
2673 /* copy in the CDB */
2674 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2676 scb->sg_count = scsi_dma_map(SC);
2677 BUG_ON(scb->sg_count < 0);
2678 if (scb->sg_count) {
2679 struct scatterlist *sg;
2682 scb->flags |= IPS_SCB_MAP_SG;
2684 scsi_for_each_sg(SC, sg, scb->sg_count, i) {
2685 if (ips_fill_scb_sg_single
2686 (ha, sg_dma_address(sg), scb, i,
2687 sg_dma_len(sg)) < 0)
2690 scb->dcdb.transfer_length = scb->data_len;
2692 scb->data_busaddr = 0L;
2695 scb->dcdb.transfer_length = 0;
2698 scb->dcdb.cmd_attribute =
2699 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2701 /* Allow a WRITE BUFFER Command to Have no Data */
2702 /* This is Used by Tape Flash Utilites */
2703 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) &&
2704 (scb->data_len == 0))
2705 scb->dcdb.cmd_attribute = 0;
2707 if (!(scb->dcdb.cmd_attribute & 0x3))
2708 scb->dcdb.transfer_length = 0;
2710 if (scb->data_len >= IPS_MAX_XFER) {
2711 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2712 scb->dcdb.transfer_length = 0;
2714 if (intr == IPS_INTR_ON)
2715 spin_lock(host->host_lock);
2717 ret = ips_send_cmd(ha, scb);
2721 ips_putq_scb_head(&ha->scb_activelist, scb);
2724 if (scb->scsi_cmd) {
2725 scb->scsi_cmd->result = DID_ERROR << 16;
2726 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2730 ha->dcdb_active[scb->bus - 1] &=
2731 ~(1 << scb->target_id);
2733 ips_freescb(ha, scb);
2735 case IPS_SUCCESS_IMM:
2737 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2740 ha->dcdb_active[scb->bus - 1] &=
2741 ~(1 << scb->target_id);
2743 ips_freescb(ha, scb);
2749 p = (struct scsi_cmnd *) p->host_scribble;
2753 if (intr == IPS_INTR_ON)
2754 spin_unlock(host->host_lock);
2757 /****************************************************************************/
2759 /* Routine Name: ips_putq_scb_head */
2761 /* Routine Description: */
2763 /* Add an item to the head of the queue */
2765 /* ASSUMED to be called from within the HA lock */
2767 /****************************************************************************/
2769 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2771 METHOD_TRACE("ips_putq_scb_head", 1);
2776 item->q_next = queue->head;
2785 /****************************************************************************/
2787 /* Routine Name: ips_removeq_scb_head */
2789 /* Routine Description: */
2791 /* Remove the head of the queue */
2793 /* ASSUMED to be called from within the HA lock */
2795 /****************************************************************************/
2797 ips_removeq_scb_head(ips_scb_queue_t * queue)
2801 METHOD_TRACE("ips_removeq_scb_head", 1);
2809 queue->head = item->q_next;
2810 item->q_next = NULL;
2812 if (queue->tail == item)
2820 /****************************************************************************/
2822 /* Routine Name: ips_removeq_scb */
2824 /* Routine Description: */
2826 /* Remove an item from a queue */
2828 /* ASSUMED to be called from within the HA lock */
2830 /****************************************************************************/
2832 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
2836 METHOD_TRACE("ips_removeq_scb", 1);
2841 if (item == queue->head) {
2842 return (ips_removeq_scb_head(queue));
2847 while ((p) && (item != p->q_next))
2852 p->q_next = item->q_next;
2857 item->q_next = NULL;
2866 /****************************************************************************/
2868 /* Routine Name: ips_putq_wait_tail */
2870 /* Routine Description: */
2872 /* Add an item to the tail of the queue */
2874 /* ASSUMED to be called from within the HA lock */
2876 /****************************************************************************/
2877 static void ips_putq_wait_tail(ips_wait_queue_t *queue, struct scsi_cmnd *item)
2879 METHOD_TRACE("ips_putq_wait_tail", 1);
2884 item->host_scribble = NULL;
2887 queue->tail->host_scribble = (char *) item;
2897 /****************************************************************************/
2899 /* Routine Name: ips_removeq_wait_head */
2901 /* Routine Description: */
2903 /* Remove the head of the queue */
2905 /* ASSUMED to be called from within the HA lock */
2907 /****************************************************************************/
2908 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *queue)
2910 struct scsi_cmnd *item;
2912 METHOD_TRACE("ips_removeq_wait_head", 1);
2920 queue->head = (struct scsi_cmnd *) item->host_scribble;
2921 item->host_scribble = NULL;
2923 if (queue->tail == item)
2931 /****************************************************************************/
2933 /* Routine Name: ips_removeq_wait */
2935 /* Routine Description: */
2937 /* Remove an item from a queue */
2939 /* ASSUMED to be called from within the HA lock */
2941 /****************************************************************************/
2942 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *queue,
2943 struct scsi_cmnd *item)
2945 struct scsi_cmnd *p;
2947 METHOD_TRACE("ips_removeq_wait", 1);
2952 if (item == queue->head) {
2953 return (ips_removeq_wait_head(queue));
2958 while ((p) && (item != (struct scsi_cmnd *) p->host_scribble))
2959 p = (struct scsi_cmnd *) p->host_scribble;
2963 p->host_scribble = item->host_scribble;
2965 if (!item->host_scribble)
2968 item->host_scribble = NULL;
2977 /****************************************************************************/
2979 /* Routine Name: ips_putq_copp_tail */
2981 /* Routine Description: */
2983 /* Add an item to the tail of the queue */
2985 /* ASSUMED to be called from within the HA lock */
2987 /****************************************************************************/
2989 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
2991 METHOD_TRACE("ips_putq_copp_tail", 1);
2999 queue->tail->next = item;
3009 /****************************************************************************/
3011 /* Routine Name: ips_removeq_copp_head */
3013 /* Routine Description: */
3015 /* Remove the head of the queue */
3017 /* ASSUMED to be called from within the HA lock */
3019 /****************************************************************************/
3020 static ips_copp_wait_item_t *
3021 ips_removeq_copp_head(ips_copp_queue_t * queue)
3023 ips_copp_wait_item_t *item;
3025 METHOD_TRACE("ips_removeq_copp_head", 1);
3033 queue->head = item->next;
3036 if (queue->tail == item)
3044 /****************************************************************************/
3046 /* Routine Name: ips_removeq_copp */
3048 /* Routine Description: */
3050 /* Remove an item from a queue */
3052 /* ASSUMED to be called from within the HA lock */
3054 /****************************************************************************/
3055 static ips_copp_wait_item_t *
3056 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3058 ips_copp_wait_item_t *p;
3060 METHOD_TRACE("ips_removeq_copp", 1);
3065 if (item == queue->head) {
3066 return (ips_removeq_copp_head(queue));
3071 while ((p) && (item != p->next))
3076 p->next = item->next;
3090 /****************************************************************************/
3092 /* Routine Name: ipsintr_blocking */
3094 /* Routine Description: */
3096 /* Finalize an interrupt for internal commands */
3098 /****************************************************************************/
3100 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3102 METHOD_TRACE("ipsintr_blocking", 2);
3104 ips_freescb(ha, scb);
3105 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3106 ha->waitflag = FALSE;
3112 /****************************************************************************/
3114 /* Routine Name: ipsintr_done */
3116 /* Routine Description: */
3118 /* Finalize an interrupt for non-internal commands */
3120 /****************************************************************************/
3122 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3124 METHOD_TRACE("ipsintr_done", 2);
3127 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3128 "Spurious interrupt; scb NULL.\n");
3133 if (scb->scsi_cmd == NULL) {
3134 /* unexpected interrupt */
3135 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3136 "Spurious interrupt; scsi_cmd not set.\n");
3144 /****************************************************************************/
3146 /* Routine Name: ips_done */
3148 /* Routine Description: */
3150 /* Do housekeeping on completed commands */
3151 /* ASSUMED to be called form within the request lock */
3152 /****************************************************************************/
3154 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3158 METHOD_TRACE("ips_done", 1);
3163 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3164 ips_cleanup_passthru(ha, scb);
3168 * Check to see if this command had too much
3169 * data and had to be broke up. If so, queue
3170 * the rest of the data and continue.
3172 if ((scb->breakup) || (scb->sg_break)) {
3173 struct scatterlist *sg;
3174 int i, sg_dma_index, ips_sg_index = 0;
3176 /* we had a data breakup */
3179 sg = scsi_sglist(scb->scsi_cmd);
3181 /* Spin forward to last dma chunk */
3182 sg_dma_index = scb->breakup;
3183 for (i = 0; i < scb->breakup; i++)
3186 /* Take care of possible partial on last chunk */
3187 ips_fill_scb_sg_single(ha,
3189 scb, ips_sg_index++,
3192 for (; sg_dma_index < scsi_sg_count(scb->scsi_cmd);
3193 sg_dma_index++, sg = sg_next(sg)) {
3194 if (ips_fill_scb_sg_single
3197 scb, ips_sg_index++,
3198 sg_dma_len(sg)) < 0)
3202 scb->dcdb.transfer_length = scb->data_len;
3203 scb->dcdb.cmd_attribute |=
3204 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3206 if (!(scb->dcdb.cmd_attribute & 0x3))
3207 scb->dcdb.transfer_length = 0;
3209 if (scb->data_len >= IPS_MAX_XFER) {
3210 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3211 scb->dcdb.transfer_length = 0;
3214 ret = ips_send_cmd(ha, scb);
3218 if (scb->scsi_cmd) {
3219 scb->scsi_cmd->result = DID_ERROR << 16;
3220 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3223 ips_freescb(ha, scb);
3225 case IPS_SUCCESS_IMM:
3226 if (scb->scsi_cmd) {
3227 scb->scsi_cmd->result = DID_ERROR << 16;
3228 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3231 ips_freescb(ha, scb);
3239 } /* end if passthru */
3242 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3245 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3247 ips_freescb(ha, scb);
3250 /****************************************************************************/
3252 /* Routine Name: ips_map_status */
3254 /* Routine Description: */
3256 /* Map Controller Error codes to Linux Error Codes */
3258 /****************************************************************************/
3260 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3264 uint32_t transfer_len;
3265 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3266 IPS_SCSI_INQ_DATA inquiryData;
3268 METHOD_TRACE("ips_map_status", 1);
3272 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3273 ips_name, ha->host_num,
3274 scb->scsi_cmd->device->channel,
3275 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3276 scb->basic_status, scb->extended_status,
3277 scb->extended_status ==
3278 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3279 scb->extended_status ==
3280 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3281 scb->extended_status ==
3282 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3285 /* default driver error */
3286 errcode = DID_ERROR;
3289 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3290 case IPS_CMD_TIMEOUT:
3291 errcode = DID_TIME_OUT;
3294 case IPS_INVAL_OPCO:
3295 case IPS_INVAL_CMD_BLK:
3296 case IPS_INVAL_PARM_BLK:
3298 case IPS_CMD_CMPLT_WERROR:
3301 case IPS_PHYS_DRV_ERROR:
3302 switch (scb->extended_status) {
3303 case IPS_ERR_SEL_TO:
3305 errcode = DID_NO_CONNECT;
3309 case IPS_ERR_OU_RUN:
3310 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3311 (scb->cmd.dcdb.op_code ==
3312 IPS_CMD_EXTENDED_DCDB_SG)) {
3313 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3314 transfer_len = tapeDCDB->transfer_length;
3317 (uint32_t) scb->dcdb.transfer_length;
3320 if ((scb->bus) && (transfer_len < scb->data_len)) {
3321 /* Underrun - set default to no error */
3324 /* Restrict access to physical DASD */
3325 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3326 ips_scmd_buf_read(scb->scsi_cmd,
3327 &inquiryData, sizeof (inquiryData));
3328 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK) {
3329 errcode = DID_TIME_OUT;
3334 errcode = DID_ERROR;
3338 case IPS_ERR_RECOVERY:
3339 /* don't fail recovered errors */
3345 case IPS_ERR_HOST_RESET:
3346 case IPS_ERR_DEV_RESET:
3347 errcode = DID_RESET;
3350 case IPS_ERR_CKCOND:
3352 if ((scb->cmd.dcdb.op_code ==
3353 IPS_CMD_EXTENDED_DCDB)
3354 || (scb->cmd.dcdb.op_code ==
3355 IPS_CMD_EXTENDED_DCDB_SG)) {
3357 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3358 memcpy(scb->scsi_cmd->sense_buffer,
3359 tapeDCDB->sense_info,
3360 SCSI_SENSE_BUFFERSIZE);
3362 memcpy(scb->scsi_cmd->sense_buffer,
3363 scb->dcdb.sense_info,
3364 SCSI_SENSE_BUFFERSIZE);
3366 device_error = 2; /* check condition */
3374 errcode = DID_ERROR;
3380 scb->scsi_cmd->result = device_error | (errcode << 16);
3385 /****************************************************************************/
3387 /* Routine Name: ips_send_wait */
3389 /* Routine Description: */
3391 /* Send a command to the controller and wait for it to return */
3393 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3394 /* actually need to wait. */
3395 /****************************************************************************/
3397 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3401 METHOD_TRACE("ips_send_wait", 1);
3403 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3404 ha->waitflag = TRUE;
3405 ha->cmd_in_progress = scb->cdb[0];
3407 scb->callback = ipsintr_blocking;
3408 ret = ips_send_cmd(ha, scb);
3410 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3413 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3414 ret = ips_wait(ha, timeout, intr);
3419 /****************************************************************************/
3421 /* Routine Name: ips_scmd_buf_write */
3423 /* Routine Description: */
3424 /* Write data to struct scsi_cmnd request_buffer at proper offsets */
3425 /****************************************************************************/
3427 ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
3429 unsigned long flags;
3431 local_irq_save(flags);
3432 scsi_sg_copy_from_buffer(scmd, data, count);
3433 local_irq_restore(flags);
3436 /****************************************************************************/
3438 /* Routine Name: ips_scmd_buf_read */
3440 /* Routine Description: */
3441 /* Copy data from a struct scsi_cmnd to a new, linear buffer */
3442 /****************************************************************************/
3444 ips_scmd_buf_read(struct scsi_cmnd *scmd, void *data, unsigned int count)
3446 unsigned long flags;
3448 local_irq_save(flags);
3449 scsi_sg_copy_to_buffer(scmd, data, count);
3450 local_irq_restore(flags);
3453 /****************************************************************************/
3455 /* Routine Name: ips_send_cmd */
3457 /* Routine Description: */
3459 /* Map SCSI commands to ServeRAID commands for logical drives */
3461 /****************************************************************************/
3463 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3468 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3471 METHOD_TRACE("ips_send_cmd", 1);
3475 if (!scb->scsi_cmd) {
3476 /* internal command */
3479 /* Controller commands can't be issued */
3480 /* to real devices -- fail them */
3481 if ((ha->waitflag == TRUE) &&
3482 (ha->cmd_in_progress == scb->cdb[0])) {
3483 ha->waitflag = FALSE;
3488 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3489 /* command to logical bus -- interpret */
3490 ret = IPS_SUCCESS_IMM;
3492 switch (scb->scsi_cmd->cmnd[0]) {
3493 case ALLOW_MEDIUM_REMOVAL:
3496 case WRITE_FILEMARKS:
3498 scb->scsi_cmd->result = DID_ERROR << 16;
3502 scb->scsi_cmd->result = DID_OK << 16;
3504 case TEST_UNIT_READY:
3506 if (scb->target_id == IPS_ADAPTER_ID) {
3508 * Either we have a TUR
3509 * or we have a SCSI inquiry
3511 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3512 scb->scsi_cmd->result = DID_OK << 16;
3514 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3515 IPS_SCSI_INQ_DATA inquiry;
3518 sizeof (IPS_SCSI_INQ_DATA));
3520 inquiry.DeviceType =
3521 IPS_SCSI_INQ_TYPE_PROCESSOR;
3522 inquiry.DeviceTypeQualifier =
3523 IPS_SCSI_INQ_LU_CONNECTED;
3524 inquiry.Version = IPS_SCSI_INQ_REV2;
3525 inquiry.ResponseDataFormat =
3526 IPS_SCSI_INQ_RD_REV2;
3527 inquiry.AdditionalLength = 31;
3529 IPS_SCSI_INQ_Address16;
3531 IPS_SCSI_INQ_WBus16 |
3533 strncpy(inquiry.VendorId, "IBM ",
3535 strncpy(inquiry.ProductId,
3537 strncpy(inquiry.ProductRevisionLevel,
3540 ips_scmd_buf_write(scb->scsi_cmd,
3544 scb->scsi_cmd->result = DID_OK << 16;
3547 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3548 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3549 scb->cmd.logical_info.reserved = 0;
3550 scb->cmd.logical_info.reserved2 = 0;
3551 scb->data_len = sizeof (IPS_LD_INFO);
3552 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3554 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3561 ips_reqsen(ha, scb);
3562 scb->scsi_cmd->result = DID_OK << 16;
3568 scb->cmd.basic_io.op_code =
3569 (scb->scsi_cmd->cmnd[0] ==
3570 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3571 scb->cmd.basic_io.enhanced_sg = 0;
3572 scb->cmd.basic_io.sg_addr =
3573 cpu_to_le32(scb->data_busaddr);
3575 scb->cmd.basic_io.op_code =
3576 (scb->scsi_cmd->cmnd[0] ==
3577 READ_6) ? IPS_CMD_READ_SG :
3579 scb->cmd.basic_io.enhanced_sg =
3580 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3581 scb->cmd.basic_io.sg_addr =
3582 cpu_to_le32(scb->sg_busaddr);
3585 scb->cmd.basic_io.segment_4G = 0;
3586 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3587 scb->cmd.basic_io.log_drv = scb->target_id;
3588 scb->cmd.basic_io.sg_count = scb->sg_len;
3590 if (scb->cmd.basic_io.lba)
3591 le32_add_cpu(&scb->cmd.basic_io.lba,
3592 le16_to_cpu(scb->cmd.basic_io.
3595 scb->cmd.basic_io.lba =
3597 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3599 (scb->scsi_cmd->cmnd[3]));
3601 scb->cmd.basic_io.sector_count =
3602 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3604 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3605 scb->cmd.basic_io.sector_count =
3614 scb->cmd.basic_io.op_code =
3615 (scb->scsi_cmd->cmnd[0] ==
3616 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3617 scb->cmd.basic_io.enhanced_sg = 0;
3618 scb->cmd.basic_io.sg_addr =
3619 cpu_to_le32(scb->data_busaddr);
3621 scb->cmd.basic_io.op_code =
3622 (scb->scsi_cmd->cmnd[0] ==
3623 READ_10) ? IPS_CMD_READ_SG :
3625 scb->cmd.basic_io.enhanced_sg =
3626 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3627 scb->cmd.basic_io.sg_addr =
3628 cpu_to_le32(scb->sg_busaddr);
3631 scb->cmd.basic_io.segment_4G = 0;
3632 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3633 scb->cmd.basic_io.log_drv = scb->target_id;
3634 scb->cmd.basic_io.sg_count = scb->sg_len;
3636 if (scb->cmd.basic_io.lba)
3637 le32_add_cpu(&scb->cmd.basic_io.lba,
3638 le16_to_cpu(scb->cmd.basic_io.
3641 scb->cmd.basic_io.lba =
3642 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3646 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3649 scb->cmd.basic_io.sector_count =
3650 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3652 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3654 * This is a null condition
3655 * we don't have to do anything
3658 scb->scsi_cmd->result = DID_OK << 16;
3666 scb->scsi_cmd->result = DID_OK << 16;
3670 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3671 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3672 scb->cmd.basic_io.segment_4G = 0;
3673 scb->cmd.basic_io.enhanced_sg = 0;
3674 scb->data_len = sizeof (*ha->enq);
3675 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3680 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3681 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3682 scb->cmd.logical_info.reserved = 0;
3683 scb->cmd.logical_info.reserved2 = 0;
3684 scb->cmd.logical_info.reserved3 = 0;
3685 scb->data_len = sizeof (IPS_LD_INFO);
3686 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3688 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3692 case SEND_DIAGNOSTIC:
3693 case REASSIGN_BLOCKS:
3697 case READ_DEFECT_DATA:
3700 scb->scsi_cmd->result = DID_OK << 16;
3704 /* Set the Return Info to appear like the Command was */
3705 /* attempted, a Check Condition occurred, and Sense */
3706 /* Data indicating an Invalid CDB OpCode is returned. */
3707 sp = (char *) scb->scsi_cmd->sense_buffer;
3709 sp[0] = 0x70; /* Error Code */
3710 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3711 sp[7] = 0x0A; /* Additional Sense Length */
3712 sp[12] = 0x20; /* ASC = Invalid OpCode */
3713 sp[13] = 0x00; /* ASCQ */
3715 device_error = 2; /* Indicate Check Condition */
3716 scb->scsi_cmd->result = device_error | (DID_OK << 16);
3721 if (ret == IPS_SUCCESS_IMM)
3727 /* If we already know the Device is Not there, no need to attempt a Command */
3728 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
3729 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
3730 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
3731 return (IPS_SUCCESS_IMM);
3734 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
3735 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
3736 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
3737 (unsigned long) &scb->
3739 (unsigned long) scb);
3740 scb->cmd.dcdb.reserved = 0;
3741 scb->cmd.dcdb.reserved2 = 0;
3742 scb->cmd.dcdb.reserved3 = 0;
3743 scb->cmd.dcdb.segment_4G = 0;
3744 scb->cmd.dcdb.enhanced_sg = 0;
3746 TimeOut = scb->scsi_cmd->request->timeout;
3748 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
3750 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
3752 scb->cmd.dcdb.op_code =
3753 IPS_CMD_EXTENDED_DCDB_SG;
3754 scb->cmd.dcdb.enhanced_sg =
3755 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3758 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
3759 tapeDCDB->device_address =
3760 ((scb->bus - 1) << 4) | scb->target_id;
3761 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
3762 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
3765 if (TimeOut < (10 * HZ))
3766 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
3767 else if (TimeOut < (60 * HZ))
3768 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
3769 else if (TimeOut < (1200 * HZ))
3770 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
3773 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
3774 tapeDCDB->reserved_for_LUN = 0;
3775 tapeDCDB->transfer_length = scb->data_len;
3776 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
3777 tapeDCDB->buffer_pointer =
3778 cpu_to_le32(scb->sg_busaddr);
3780 tapeDCDB->buffer_pointer =
3781 cpu_to_le32(scb->data_busaddr);
3782 tapeDCDB->sg_count = scb->sg_len;
3783 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
3784 tapeDCDB->scsi_status = 0;
3785 tapeDCDB->reserved = 0;
3786 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
3787 scb->scsi_cmd->cmd_len);
3790 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
3792 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
3793 scb->cmd.dcdb.enhanced_sg =
3794 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3797 scb->dcdb.device_address =
3798 ((scb->bus - 1) << 4) | scb->target_id;
3799 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
3802 if (TimeOut < (10 * HZ))
3803 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
3804 else if (TimeOut < (60 * HZ))
3805 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
3806 else if (TimeOut < (1200 * HZ))
3807 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
3810 scb->dcdb.transfer_length = scb->data_len;
3811 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
3812 scb->dcdb.transfer_length = 0;
3813 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
3814 scb->dcdb.buffer_pointer =
3815 cpu_to_le32(scb->sg_busaddr);
3817 scb->dcdb.buffer_pointer =
3818 cpu_to_le32(scb->data_busaddr);
3819 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
3820 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
3821 scb->dcdb.sg_count = scb->sg_len;
3822 scb->dcdb.reserved = 0;
3823 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
3824 scb->scsi_cmd->cmd_len);
3825 scb->dcdb.scsi_status = 0;
3826 scb->dcdb.reserved2[0] = 0;
3827 scb->dcdb.reserved2[1] = 0;
3828 scb->dcdb.reserved2[2] = 0;
3832 return ((*ha->func.issue) (ha, scb));
3835 /****************************************************************************/
3837 /* Routine Name: ips_chk_status */
3839 /* Routine Description: */
3841 /* Check the status of commands to logical drives */
3842 /* Assumed to be called with the HA lock */
3843 /****************************************************************************/
3845 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
3849 uint8_t basic_status;
3852 IPS_SCSI_INQ_DATA inquiryData;
3854 METHOD_TRACE("ips_chkstatus", 1);
3856 scb = &ha->scbs[pstatus->fields.command_id];
3857 scb->basic_status = basic_status =
3858 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
3859 scb->extended_status = ext_status = pstatus->fields.extended_status;
3862 sp->residue_len = 0;
3863 sp->scb_addr = (void *) scb;
3865 /* Remove the item from the active queue */
3866 ips_removeq_scb(&ha->scb_activelist, scb);
3869 /* internal commands are handled in do_ipsintr */
3872 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
3876 scb->cmd.basic_io.command_id,
3877 scb->bus, scb->target_id, scb->lun);
3879 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
3880 /* passthru - just returns the raw result */
3885 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
3886 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
3888 if (scb->bus == 0) {
3889 if ((basic_status & IPS_GSC_STATUS_MASK) ==
3890 IPS_CMD_RECOVERED_ERROR) {
3892 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
3893 ips_name, ha->host_num,
3894 scb->cmd.basic_io.op_code,
3895 basic_status, ext_status);
3898 switch (scb->scsi_cmd->cmnd[0]) {
3899 case ALLOW_MEDIUM_REMOVAL:
3902 case WRITE_FILEMARKS:
3904 errcode = DID_ERROR;
3910 case TEST_UNIT_READY:
3911 if (!ips_online(ha, scb)) {
3912 errcode = DID_TIME_OUT;
3917 if (ips_online(ha, scb)) {
3918 ips_inquiry(ha, scb);
3920 errcode = DID_TIME_OUT;
3925 ips_reqsen(ha, scb);
3937 if (!ips_online(ha, scb)
3938 || !ips_msense(ha, scb)) {
3939 errcode = DID_ERROR;
3944 if (ips_online(ha, scb))
3947 errcode = DID_TIME_OUT;
3951 case SEND_DIAGNOSTIC:
3952 case REASSIGN_BLOCKS:
3956 errcode = DID_ERROR;
3961 case READ_DEFECT_DATA:
3967 errcode = DID_ERROR;
3970 scb->scsi_cmd->result = errcode << 16;
3971 } else { /* bus == 0 */
3972 /* restrict access to physical drives */
3973 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3974 ips_scmd_buf_read(scb->scsi_cmd,
3975 &inquiryData, sizeof (inquiryData));
3976 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK)
3977 scb->scsi_cmd->result = DID_TIME_OUT << 16;
3980 } else { /* recovered error / success */
3981 if (scb->bus == 0) {
3983 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
3984 ips_name, ha->host_num,
3985 scb->cmd.basic_io.op_code, basic_status,
3989 ips_map_status(ha, scb, sp);
3993 /****************************************************************************/
3995 /* Routine Name: ips_online */
3997 /* Routine Description: */
3999 /* Determine if a logical drive is online */
4001 /****************************************************************************/
4003 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4005 METHOD_TRACE("ips_online", 1);
4007 if (scb->target_id >= IPS_MAX_LD)
4010 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4011 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4015 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4017 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4019 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4021 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4028 /****************************************************************************/
4030 /* Routine Name: ips_inquiry */
4032 /* Routine Description: */
4034 /* Simulate an inquiry command to a logical drive */
4036 /****************************************************************************/
4038 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4040 IPS_SCSI_INQ_DATA inquiry;
4042 METHOD_TRACE("ips_inquiry", 1);
4044 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4046 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4047 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4048 inquiry.Version = IPS_SCSI_INQ_REV2;
4049 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4050 inquiry.AdditionalLength = 31;
4051 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4053 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4054 strncpy(inquiry.VendorId, "IBM ", 8);
4055 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4056 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4058 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4063 /****************************************************************************/
4065 /* Routine Name: ips_rdcap */
4067 /* Routine Description: */
4069 /* Simulate a read capacity command to a logical drive */
4071 /****************************************************************************/
4073 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4075 IPS_SCSI_CAPACITY cap;
4077 METHOD_TRACE("ips_rdcap", 1);
4079 if (scsi_bufflen(scb->scsi_cmd) < 8)
4083 cpu_to_be32(le32_to_cpu
4084 (ha->logical_drive_info->
4085 drive_info[scb->target_id].sector_count) - 1);
4086 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4088 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4093 /****************************************************************************/
4095 /* Routine Name: ips_msense */
4097 /* Routine Description: */
4099 /* Simulate a mode sense command to a logical drive */
4101 /****************************************************************************/
4103 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4108 IPS_SCSI_MODE_PAGE_DATA mdata;
4110 METHOD_TRACE("ips_msense", 1);
4112 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4113 (ha->enq->ucMiscFlag & 0x8) == 0) {
4114 heads = IPS_NORM_HEADS;
4115 sectors = IPS_NORM_SECTORS;
4117 heads = IPS_COMP_HEADS;
4118 sectors = IPS_COMP_SECTORS;
4122 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4123 1) / (heads * sectors);
4125 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4127 mdata.hdr.BlockDescLength = 8;
4129 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4130 case 0x03: /* page 3 */
4131 mdata.pdata.pg3.PageCode = 3;
4132 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4133 mdata.hdr.DataLength =
4134 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4135 mdata.pdata.pg3.TracksPerZone = 0;
4136 mdata.pdata.pg3.AltSectorsPerZone = 0;
4137 mdata.pdata.pg3.AltTracksPerZone = 0;
4138 mdata.pdata.pg3.AltTracksPerVolume = 0;
4139 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4140 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4141 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4142 mdata.pdata.pg3.TrackSkew = 0;
4143 mdata.pdata.pg3.CylinderSkew = 0;
4144 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4148 mdata.pdata.pg4.PageCode = 4;
4149 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4150 mdata.hdr.DataLength =
4151 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4152 mdata.pdata.pg4.CylindersHigh =
4153 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4154 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4155 mdata.pdata.pg4.Heads = heads;
4156 mdata.pdata.pg4.WritePrecompHigh = 0;
4157 mdata.pdata.pg4.WritePrecompLow = 0;
4158 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4159 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4160 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4161 mdata.pdata.pg4.LandingZoneHigh = 0;
4162 mdata.pdata.pg4.LandingZoneLow = 0;
4163 mdata.pdata.pg4.flags = 0;
4164 mdata.pdata.pg4.RotationalOffset = 0;
4165 mdata.pdata.pg4.MediumRotationRate = 0;
4168 mdata.pdata.pg8.PageCode = 8;
4169 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4170 mdata.hdr.DataLength =
4171 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4172 /* everything else is left set to 0 */
4179 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4184 /****************************************************************************/
4186 /* Routine Name: ips_reqsen */
4188 /* Routine Description: */
4190 /* Simulate a request sense command to a logical drive */
4192 /****************************************************************************/
4194 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4196 IPS_SCSI_REQSEN reqsen;
4198 METHOD_TRACE("ips_reqsen", 1);
4200 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4202 reqsen.ResponseCode =
4203 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4204 reqsen.AdditionalLength = 10;
4205 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4206 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4208 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4213 /****************************************************************************/
4215 /* Routine Name: ips_free */
4217 /* Routine Description: */
4219 /* Free any allocated space for this controller */
4221 /****************************************************************************/
4223 ips_free(ips_ha_t * ha)
4226 METHOD_TRACE("ips_free", 1);
4230 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4231 ha->enq, ha->enq_busaddr);
4239 pci_free_consistent(ha->pcidev,
4240 sizeof (IPS_ADAPTER) +
4241 sizeof (IPS_IO_CMD), ha->adapt,
4242 ha->adapt->hw_status_start);
4246 if (ha->logical_drive_info) {
4247 pci_free_consistent(ha->pcidev,
4248 sizeof (IPS_LD_INFO),
4249 ha->logical_drive_info,
4250 ha->logical_drive_info_dma_addr);
4251 ha->logical_drive_info = NULL;
4260 if (ha->ioctl_data) {
4261 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4262 ha->ioctl_data, ha->ioctl_busaddr);
4263 ha->ioctl_data = NULL;
4264 ha->ioctl_datasize = 0;
4267 ips_deallocatescbs(ha, ha->max_cmds);
4269 /* free memory mapped (if applicable) */
4271 iounmap(ha->ioremap_ptr);
4272 ha->ioremap_ptr = NULL;
4281 /****************************************************************************/
4283 /* Routine Name: ips_deallocatescbs */
4285 /* Routine Description: */
4287 /* Free the command blocks */
4289 /****************************************************************************/
4291 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4294 pci_free_consistent(ha->pcidev,
4295 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4296 ha->scbs->sg_list.list,
4297 ha->scbs->sg_busaddr);
4298 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4299 ha->scbs, ha->scbs->scb_busaddr);
4305 /****************************************************************************/
4307 /* Routine Name: ips_allocatescbs */
4309 /* Routine Description: */
4311 /* Allocate the command blocks */
4313 /****************************************************************************/
4315 ips_allocatescbs(ips_ha_t * ha)
4320 dma_addr_t command_dma, sg_dma;
4322 METHOD_TRACE("ips_allocatescbs", 1);
4324 /* Allocate memory for the SCBs */
4326 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4328 if (ha->scbs == NULL)
4331 pci_alloc_consistent(ha->pcidev,
4332 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4333 ha->max_cmds, &sg_dma);
4334 if (ips_sg.list == NULL) {
4335 pci_free_consistent(ha->pcidev,
4336 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4341 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4343 for (i = 0; i < ha->max_cmds; i++) {
4344 scb_p = &ha->scbs[i];
4345 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4346 /* set up S/G list */
4347 if (IPS_USE_ENH_SGLIST(ha)) {
4348 scb_p->sg_list.enh_list =
4349 ips_sg.enh_list + i * IPS_MAX_SG;
4351 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4353 scb_p->sg_list.std_list =
4354 ips_sg.std_list + i * IPS_MAX_SG;
4356 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4359 /* add to the free list */
4360 if (i < ha->max_cmds - 1) {
4361 scb_p->q_next = ha->scb_freelist;
4362 ha->scb_freelist = scb_p;
4370 /****************************************************************************/
4372 /* Routine Name: ips_init_scb */
4374 /* Routine Description: */
4376 /* Initialize a CCB to default values */
4378 /****************************************************************************/
4380 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4382 IPS_SG_LIST sg_list;
4383 uint32_t cmd_busaddr, sg_busaddr;
4384 METHOD_TRACE("ips_init_scb", 1);
4389 sg_list.list = scb->sg_list.list;
4390 cmd_busaddr = scb->scb_busaddr;
4391 sg_busaddr = scb->sg_busaddr;
4393 memset(scb, 0, sizeof (ips_scb_t));
4394 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4396 /* Initialize dummy command bucket */
4397 ha->dummy->op_code = 0xFF;
4398 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4399 + sizeof (IPS_ADAPTER));
4400 ha->dummy->command_id = IPS_MAX_CMDS;
4402 /* set bus address of scb */
4403 scb->scb_busaddr = cmd_busaddr;
4404 scb->sg_busaddr = sg_busaddr;
4405 scb->sg_list.list = sg_list.list;
4408 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4409 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4410 + sizeof (IPS_ADAPTER));
4413 /****************************************************************************/
4415 /* Routine Name: ips_get_scb */
4417 /* Routine Description: */
4419 /* Initialize a CCB to default values */
4421 /* ASSUMED to be called from within a lock */
4423 /****************************************************************************/
4425 ips_getscb(ips_ha_t * ha)
4429 METHOD_TRACE("ips_getscb", 1);
4431 if ((scb = ha->scb_freelist) == NULL) {
4436 ha->scb_freelist = scb->q_next;
4440 ips_init_scb(ha, scb);
4445 /****************************************************************************/
4447 /* Routine Name: ips_free_scb */
4449 /* Routine Description: */
4451 /* Return an unused CCB back to the free list */
4453 /* ASSUMED to be called from within a lock */
4455 /****************************************************************************/
4457 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4460 METHOD_TRACE("ips_freescb", 1);
4461 if (scb->flags & IPS_SCB_MAP_SG)
4462 scsi_dma_unmap(scb->scsi_cmd);
4463 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4464 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4467 /* check to make sure this is not our "special" scb */
4468 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4469 scb->q_next = ha->scb_freelist;
4470 ha->scb_freelist = scb;
4474 /****************************************************************************/
4476 /* Routine Name: ips_isinit_copperhead */
4478 /* Routine Description: */
4480 /* Is controller initialized ? */
4482 /****************************************************************************/
4484 ips_isinit_copperhead(ips_ha_t * ha)
4489 METHOD_TRACE("ips_isinit_copperhead", 1);
4491 isr = inb(ha->io_addr + IPS_REG_HISR);
4492 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4494 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4500 /****************************************************************************/
4502 /* Routine Name: ips_isinit_copperhead_memio */
4504 /* Routine Description: */
4506 /* Is controller initialized ? */
4508 /****************************************************************************/
4510 ips_isinit_copperhead_memio(ips_ha_t * ha)
4515 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4517 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4518 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4520 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4526 /****************************************************************************/
4528 /* Routine Name: ips_isinit_morpheus */
4530 /* Routine Description: */
4532 /* Is controller initialized ? */
4534 /****************************************************************************/
4536 ips_isinit_morpheus(ips_ha_t * ha)
4541 METHOD_TRACE("ips_is_init_morpheus", 1);
4543 if (ips_isintr_morpheus(ha))
4544 ips_flush_and_reset(ha);
4546 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4547 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4551 else if (bits & 0x3)
4557 /****************************************************************************/
4559 /* Routine Name: ips_flush_and_reset */
4561 /* Routine Description: */
4563 /* Perform cleanup ( FLUSH and RESET ) when the adapter is in an unknown */
4564 /* state ( was trying to INIT and an interrupt was already pending ) ... */
4566 /****************************************************************************/
4568 ips_flush_and_reset(ips_ha_t *ha)
4574 dma_addr_t command_dma;
4576 /* Create a usuable SCB */
4577 scb = pci_alloc_consistent(ha->pcidev, sizeof(ips_scb_t), &command_dma);
4579 memset(scb, 0, sizeof(ips_scb_t));
4580 ips_init_scb(ha, scb);
4581 scb->scb_busaddr = command_dma;
4583 scb->timeout = ips_cmd_timeout;
4584 scb->cdb[0] = IPS_CMD_FLUSH;
4586 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
4587 scb->cmd.flush_cache.command_id = IPS_MAX_CMDS; /* Use an ID that would otherwise not exist */
4588 scb->cmd.flush_cache.state = IPS_NORM_STATE;
4589 scb->cmd.flush_cache.reserved = 0;
4590 scb->cmd.flush_cache.reserved2 = 0;
4591 scb->cmd.flush_cache.reserved3 = 0;
4592 scb->cmd.flush_cache.reserved4 = 0;
4594 ret = ips_send_cmd(ha, scb); /* Send the Flush Command */
4596 if (ret == IPS_SUCCESS) {
4597 time = 60 * IPS_ONE_SEC; /* Max Wait time is 60 seconds */
4600 while ((time > 0) && (!done)) {
4601 done = ips_poll_for_flush_complete(ha);
4602 /* This may look evil, but it's only done during extremely rare start-up conditions ! */
4609 /* Now RESET and INIT the adapter */
4610 (*ha->func.reset) (ha);
4612 pci_free_consistent(ha->pcidev, sizeof(ips_scb_t), scb, command_dma);
4616 /****************************************************************************/
4618 /* Routine Name: ips_poll_for_flush_complete */
4620 /* Routine Description: */
4622 /* Poll for the Flush Command issued by ips_flush_and_reset() to complete */
4623 /* All other responses are just taken off the queue and ignored */
4625 /****************************************************************************/
4627 ips_poll_for_flush_complete(ips_ha_t * ha)
4632 cstatus.value = (*ha->func.statupd) (ha);
4634 if (cstatus.value == 0xffffffff) /* If No Interrupt to process */
4637 /* Success is when we see the Flush Command ID */
4638 if (cstatus.fields.command_id == IPS_MAX_CMDS)
4645 /****************************************************************************/
4647 /* Routine Name: ips_enable_int_copperhead */
4649 /* Routine Description: */
4650 /* Turn on interrupts */
4652 /****************************************************************************/
4654 ips_enable_int_copperhead(ips_ha_t * ha)
4656 METHOD_TRACE("ips_enable_int_copperhead", 1);
4658 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4659 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4662 /****************************************************************************/
4664 /* Routine Name: ips_enable_int_copperhead_memio */
4666 /* Routine Description: */
4667 /* Turn on interrupts */
4669 /****************************************************************************/
4671 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4673 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4675 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4676 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4679 /****************************************************************************/
4681 /* Routine Name: ips_enable_int_morpheus */
4683 /* Routine Description: */
4684 /* Turn on interrupts */
4686 /****************************************************************************/
4688 ips_enable_int_morpheus(ips_ha_t * ha)
4692 METHOD_TRACE("ips_enable_int_morpheus", 1);
4694 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4696 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4697 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4700 /****************************************************************************/
4702 /* Routine Name: ips_init_copperhead */
4704 /* Routine Description: */
4706 /* Initialize a copperhead controller */
4708 /****************************************************************************/
4710 ips_init_copperhead(ips_ha_t * ha)
4714 uint8_t PostByte[IPS_MAX_POST_BYTES];
4715 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4718 METHOD_TRACE("ips_init_copperhead", 1);
4720 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4721 for (j = 0; j < 45; j++) {
4722 Isr = inb(ha->io_addr + IPS_REG_HISR);
4723 if (Isr & IPS_BIT_GHI)
4726 /* Delay for 1 Second */
4727 MDELAY(IPS_ONE_SEC);
4731 /* error occurred */
4734 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4735 outb(Isr, ha->io_addr + IPS_REG_HISR);
4738 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4739 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4740 "reset controller fails (post status %x %x).\n",
4741 PostByte[0], PostByte[1]);
4746 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4747 for (j = 0; j < 240; j++) {
4748 Isr = inb(ha->io_addr + IPS_REG_HISR);
4749 if (Isr & IPS_BIT_GHI)
4752 /* Delay for 1 Second */
4753 MDELAY(IPS_ONE_SEC);
4757 /* error occurred */
4760 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4761 outb(Isr, ha->io_addr + IPS_REG_HISR);
4764 for (i = 0; i < 240; i++) {
4765 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
4767 if ((Cbsp & IPS_BIT_OP) == 0)
4770 /* Delay for 1 Second */
4771 MDELAY(IPS_ONE_SEC);
4779 outl(0x1010, ha->io_addr + IPS_REG_CCCR);
4781 /* Enable busmastering */
4782 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
4784 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
4785 /* fix for anaconda64 */
4786 outl(0, ha->io_addr + IPS_REG_NDAE);
4788 /* Enable interrupts */
4789 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
4794 /****************************************************************************/
4796 /* Routine Name: ips_init_copperhead_memio */
4798 /* Routine Description: */
4800 /* Initialize a copperhead controller with memory mapped I/O */
4802 /****************************************************************************/
4804 ips_init_copperhead_memio(ips_ha_t * ha)
4808 uint8_t PostByte[IPS_MAX_POST_BYTES];
4809 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4812 METHOD_TRACE("ips_init_copperhead_memio", 1);
4814 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4815 for (j = 0; j < 45; j++) {
4816 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4817 if (Isr & IPS_BIT_GHI)
4820 /* Delay for 1 Second */
4821 MDELAY(IPS_ONE_SEC);
4825 /* error occurred */
4828 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
4829 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
4832 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4833 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4834 "reset controller fails (post status %x %x).\n",
4835 PostByte[0], PostByte[1]);
4840 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4841 for (j = 0; j < 240; j++) {
4842 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4843 if (Isr & IPS_BIT_GHI)
4846 /* Delay for 1 Second */
4847 MDELAY(IPS_ONE_SEC);
4851 /* error occurred */
4854 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
4855 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
4858 for (i = 0; i < 240; i++) {
4859 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
4861 if ((Cbsp & IPS_BIT_OP) == 0)
4864 /* Delay for 1 Second */
4865 MDELAY(IPS_ONE_SEC);
4869 /* error occurred */
4873 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
4875 /* Enable busmastering */
4876 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
4878 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
4879 /* fix for anaconda64 */
4880 writel(0, ha->mem_ptr + IPS_REG_NDAE);
4882 /* Enable interrupts */
4883 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4885 /* if we get here then everything went OK */
4889 /****************************************************************************/
4891 /* Routine Name: ips_init_morpheus */
4893 /* Routine Description: */
4895 /* Initialize a morpheus controller */
4897 /****************************************************************************/
4899 ips_init_morpheus(ips_ha_t * ha)
4907 METHOD_TRACE("ips_init_morpheus", 1);
4909 /* Wait up to 45 secs for Post */
4910 for (i = 0; i < 45; i++) {
4911 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4913 if (Isr & IPS_BIT_I960_MSG0I)
4916 /* Delay for 1 Second */
4917 MDELAY(IPS_ONE_SEC);
4921 /* error occurred */
4922 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4923 "timeout waiting for post.\n");
4928 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4930 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
4931 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4932 "Flashing Battery PIC, Please wait ...\n");
4934 /* Clear the interrupt bit */
4935 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
4936 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
4938 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
4939 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4942 /* Delay for 1 Second */
4943 MDELAY(IPS_ONE_SEC);
4947 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4948 "timeout waiting for Battery PIC Flash\n");
4954 /* Clear the interrupt bit */
4955 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
4956 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
4958 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
4959 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4960 "reset controller fails (post status %x).\n", Post);
4965 /* Wait up to 240 secs for config bytes */
4966 for (i = 0; i < 240; i++) {
4967 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4969 if (Isr & IPS_BIT_I960_MSG1I)
4972 /* Delay for 1 Second */
4973 MDELAY(IPS_ONE_SEC);
4977 /* error occurred */
4978 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4979 "timeout waiting for config.\n");
4984 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
4986 /* Clear interrupt bit */
4987 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
4988 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
4990 /* Turn on the interrupts */
4991 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4993 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4995 /* if we get here then everything went OK */
4997 /* Since we did a RESET, an EraseStripeLock may be needed */
4998 if (Post == 0xEF10) {
4999 if ((Config == 0x000F) || (Config == 0x0009))
5000 ha->requires_esl = 1;
5006 /****************************************************************************/
5008 /* Routine Name: ips_reset_copperhead */
5010 /* Routine Description: */
5012 /* Reset the controller */
5014 /****************************************************************************/
5016 ips_reset_copperhead(ips_ha_t * ha)
5020 METHOD_TRACE("ips_reset_copperhead", 1);
5022 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5023 ips_name, ha->host_num, ha->io_addr, ha->pcidev->irq);
5027 while (reset_counter < 2) {
5030 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5032 /* Delay for 1 Second */
5033 MDELAY(IPS_ONE_SEC);
5035 outb(0, ha->io_addr + IPS_REG_SCPR);
5037 /* Delay for 1 Second */
5038 MDELAY(IPS_ONE_SEC);
5040 if ((*ha->func.init) (ha))
5042 else if (reset_counter >= 2) {
5051 /****************************************************************************/
5053 /* Routine Name: ips_reset_copperhead_memio */
5055 /* Routine Description: */
5057 /* Reset the controller */
5059 /****************************************************************************/
5061 ips_reset_copperhead_memio(ips_ha_t * ha)
5065 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5067 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5068 ips_name, ha->host_num, ha->mem_addr, ha->pcidev->irq);
5072 while (reset_counter < 2) {
5075 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5077 /* Delay for 1 Second */
5078 MDELAY(IPS_ONE_SEC);
5080 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5082 /* Delay for 1 Second */
5083 MDELAY(IPS_ONE_SEC);
5085 if ((*ha->func.init) (ha))
5087 else if (reset_counter >= 2) {
5096 /****************************************************************************/
5098 /* Routine Name: ips_reset_morpheus */
5100 /* Routine Description: */
5102 /* Reset the controller */
5104 /****************************************************************************/
5106 ips_reset_morpheus(ips_ha_t * ha)
5111 METHOD_TRACE("ips_reset_morpheus", 1);
5113 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5114 ips_name, ha->host_num, ha->mem_addr, ha->pcidev->irq);
5118 while (reset_counter < 2) {
5121 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5123 /* Delay for 5 Seconds */
5124 MDELAY(5 * IPS_ONE_SEC);
5126 /* Do a PCI config read to wait for adapter */
5127 pci_read_config_byte(ha->pcidev, 4, &junk);
5129 if ((*ha->func.init) (ha))
5131 else if (reset_counter >= 2) {
5140 /****************************************************************************/
5142 /* Routine Name: ips_statinit */
5144 /* Routine Description: */
5146 /* Initialize the status queues on the controller */
5148 /****************************************************************************/
5150 ips_statinit(ips_ha_t * ha)
5152 uint32_t phys_status_start;
5154 METHOD_TRACE("ips_statinit", 1);
5156 ha->adapt->p_status_start = ha->adapt->status;
5157 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5158 ha->adapt->p_status_tail = ha->adapt->status;
5160 phys_status_start = ha->adapt->hw_status_start;
5161 outl(phys_status_start, ha->io_addr + IPS_REG_SQSR);
5162 outl(phys_status_start + IPS_STATUS_Q_SIZE,
5163 ha->io_addr + IPS_REG_SQER);
5164 outl(phys_status_start + IPS_STATUS_SIZE,
5165 ha->io_addr + IPS_REG_SQHR);
5166 outl(phys_status_start, ha->io_addr + IPS_REG_SQTR);
5168 ha->adapt->hw_status_tail = phys_status_start;
5171 /****************************************************************************/
5173 /* Routine Name: ips_statinit_memio */
5175 /* Routine Description: */
5177 /* Initialize the status queues on the controller */
5179 /****************************************************************************/
5181 ips_statinit_memio(ips_ha_t * ha)
5183 uint32_t phys_status_start;
5185 METHOD_TRACE("ips_statinit_memio", 1);
5187 ha->adapt->p_status_start = ha->adapt->status;
5188 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5189 ha->adapt->p_status_tail = ha->adapt->status;
5191 phys_status_start = ha->adapt->hw_status_start;
5192 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5193 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5194 ha->mem_ptr + IPS_REG_SQER);
5195 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5196 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5198 ha->adapt->hw_status_tail = phys_status_start;
5201 /****************************************************************************/
5203 /* Routine Name: ips_statupd_copperhead */
5205 /* Routine Description: */
5207 /* Remove an element from the status queue */
5209 /****************************************************************************/
5211 ips_statupd_copperhead(ips_ha_t * ha)
5213 METHOD_TRACE("ips_statupd_copperhead", 1);
5215 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5216 ha->adapt->p_status_tail++;
5217 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5219 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5220 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5223 outl(ha->adapt->hw_status_tail,
5224 ha->io_addr + IPS_REG_SQTR);
5226 return (ha->adapt->p_status_tail->value);
5229 /****************************************************************************/
5231 /* Routine Name: ips_statupd_copperhead_memio */
5233 /* Routine Description: */
5235 /* Remove an element from the status queue */
5237 /****************************************************************************/
5239 ips_statupd_copperhead_memio(ips_ha_t * ha)
5241 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5243 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5244 ha->adapt->p_status_tail++;
5245 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5247 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5248 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5251 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5253 return (ha->adapt->p_status_tail->value);
5256 /****************************************************************************/
5258 /* Routine Name: ips_statupd_morpheus */
5260 /* Routine Description: */
5262 /* Remove an element from the status queue */
5264 /****************************************************************************/
5266 ips_statupd_morpheus(ips_ha_t * ha)
5270 METHOD_TRACE("ips_statupd_morpheus", 1);
5272 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5277 /****************************************************************************/
5279 /* Routine Name: ips_issue_copperhead */
5281 /* Routine Description: */
5283 /* Send a command down to the controller */
5285 /****************************************************************************/
5287 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5292 METHOD_TRACE("ips_issue_copperhead", 1);
5294 if (scb->scsi_cmd) {
5295 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5299 scb->cmd.basic_io.command_id,
5300 scb->bus, scb->target_id, scb->lun);
5302 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5303 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5309 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5312 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5313 if (!(val & IPS_BIT_START_STOP))
5316 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5317 "ips_issue val [0x%x].\n", val);
5318 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5319 "ips_issue semaphore chk timeout.\n");
5321 return (IPS_FAILURE);
5325 outl(scb->scb_busaddr, ha->io_addr + IPS_REG_CCSAR);
5326 outw(IPS_BIT_START_CMD, ha->io_addr + IPS_REG_CCCR);
5328 return (IPS_SUCCESS);
5331 /****************************************************************************/
5333 /* Routine Name: ips_issue_copperhead_memio */
5335 /* Routine Description: */
5337 /* Send a command down to the controller */
5339 /****************************************************************************/
5341 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5346 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5348 if (scb->scsi_cmd) {
5349 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5353 scb->cmd.basic_io.command_id,
5354 scb->bus, scb->target_id, scb->lun);
5356 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5357 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5362 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5365 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5366 if (!(val & IPS_BIT_START_STOP))
5369 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5370 "ips_issue val [0x%x].\n", val);
5371 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5372 "ips_issue semaphore chk timeout.\n");
5374 return (IPS_FAILURE);
5378 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5379 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5381 return (IPS_SUCCESS);
5384 /****************************************************************************/
5386 /* Routine Name: ips_issue_i2o */
5388 /* Routine Description: */
5390 /* Send a command down to the controller */
5392 /****************************************************************************/
5394 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5397 METHOD_TRACE("ips_issue_i2o", 1);
5399 if (scb->scsi_cmd) {
5400 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5404 scb->cmd.basic_io.command_id,
5405 scb->bus, scb->target_id, scb->lun);
5407 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5408 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5411 outl(scb->scb_busaddr, ha->io_addr + IPS_REG_I2O_INMSGQ);
5413 return (IPS_SUCCESS);
5416 /****************************************************************************/
5418 /* Routine Name: ips_issue_i2o_memio */
5420 /* Routine Description: */
5422 /* Send a command down to the controller */
5424 /****************************************************************************/
5426 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5429 METHOD_TRACE("ips_issue_i2o_memio", 1);
5431 if (scb->scsi_cmd) {
5432 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5436 scb->cmd.basic_io.command_id,
5437 scb->bus, scb->target_id, scb->lun);
5439 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5440 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5443 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5445 return (IPS_SUCCESS);
5448 /****************************************************************************/
5450 /* Routine Name: ips_isintr_copperhead */
5452 /* Routine Description: */
5454 /* Test to see if an interrupt is for us */
5456 /****************************************************************************/
5458 ips_isintr_copperhead(ips_ha_t * ha)
5462 METHOD_TRACE("ips_isintr_copperhead", 2);
5464 Isr = inb(ha->io_addr + IPS_REG_HISR);
5467 /* ?!?! Nothing really there */
5470 if (Isr & IPS_BIT_SCE)
5472 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5473 /* status queue overflow or GHI */
5474 /* just clear the interrupt */
5475 outb(Isr, ha->io_addr + IPS_REG_HISR);
5481 /****************************************************************************/
5483 /* Routine Name: ips_isintr_copperhead_memio */
5485 /* Routine Description: */
5487 /* Test to see if an interrupt is for us */
5489 /****************************************************************************/
5491 ips_isintr_copperhead_memio(ips_ha_t * ha)
5495 METHOD_TRACE("ips_isintr_memio", 2);
5497 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5500 /* ?!?! Nothing really there */
5503 if (Isr & IPS_BIT_SCE)
5505 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5506 /* status queue overflow or GHI */
5507 /* just clear the interrupt */
5508 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5514 /****************************************************************************/
5516 /* Routine Name: ips_isintr_morpheus */
5518 /* Routine Description: */
5520 /* Test to see if an interrupt is for us */
5522 /****************************************************************************/
5524 ips_isintr_morpheus(ips_ha_t * ha)
5528 METHOD_TRACE("ips_isintr_morpheus", 2);
5530 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5532 if (Isr & IPS_BIT_I2O_OPQI)
5538 /****************************************************************************/
5540 /* Routine Name: ips_wait */
5542 /* Routine Description: */
5544 /* Wait for a command to complete */
5546 /****************************************************************************/
5548 ips_wait(ips_ha_t * ha, int time, int intr)
5553 METHOD_TRACE("ips_wait", 1);
5558 time *= IPS_ONE_SEC; /* convert seconds */
5560 while ((time > 0) && (!done)) {
5561 if (intr == IPS_INTR_ON) {
5562 if (ha->waitflag == FALSE) {
5567 } else if (intr == IPS_INTR_IORL) {
5568 if (ha->waitflag == FALSE) {
5570 * controller generated an interrupt to
5571 * acknowledge completion of the command
5572 * and ips_intr() has serviced the interrupt.
5580 * NOTE: we already have the io_request_lock so
5581 * even if we get an interrupt it won't get serviced
5582 * until after we finish.
5585 (*ha->func.intr) (ha);
5588 /* This looks like a very evil loop, but it only does this during start-up */
5596 /****************************************************************************/
5598 /* Routine Name: ips_write_driver_status */
5600 /* Routine Description: */
5602 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5604 /****************************************************************************/
5606 ips_write_driver_status(ips_ha_t * ha, int intr)
5608 METHOD_TRACE("ips_write_driver_status", 1);
5610 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5611 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5612 "unable to read NVRAM page 5.\n");
5617 /* check to make sure the page has a valid */
5619 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5621 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5622 ips_name, ha->host_num, ha->nvram->signature);
5623 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5627 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5628 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5629 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5630 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5631 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5632 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5633 ha->nvram->bios_low[3]);
5635 ips_get_bios_version(ha, intr);
5637 /* change values (as needed) */
5638 ha->nvram->operating_system = IPS_OS_LINUX;
5639 ha->nvram->adapter_type = ha->ad_type;
5640 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5641 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5642 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5643 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5645 ha->nvram->versioning = 0; /* Indicate the Driver Does Not Support Versioning */
5647 /* now update the page */
5648 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5649 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5650 "unable to write NVRAM page 5.\n");
5655 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5656 ha->slot_num = ha->nvram->adapter_slot;
5661 /****************************************************************************/
5663 /* Routine Name: ips_read_adapter_status */
5665 /* Routine Description: */
5667 /* Do an Inquiry command to the adapter */
5669 /****************************************************************************/
5671 ips_read_adapter_status(ips_ha_t * ha, int intr)
5676 METHOD_TRACE("ips_read_adapter_status", 1);
5678 scb = &ha->scbs[ha->max_cmds - 1];
5680 ips_init_scb(ha, scb);
5682 scb->timeout = ips_cmd_timeout;
5683 scb->cdb[0] = IPS_CMD_ENQUIRY;
5685 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5686 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5687 scb->cmd.basic_io.sg_count = 0;
5688 scb->cmd.basic_io.lba = 0;
5689 scb->cmd.basic_io.sector_count = 0;
5690 scb->cmd.basic_io.log_drv = 0;
5691 scb->data_len = sizeof (*ha->enq);
5692 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5696 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5697 || (ret == IPS_SUCCESS_IMM)
5698 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5704 /****************************************************************************/
5706 /* Routine Name: ips_read_subsystem_parameters */
5708 /* Routine Description: */
5710 /* Read subsystem parameters from the adapter */
5712 /****************************************************************************/
5714 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
5719 METHOD_TRACE("ips_read_subsystem_parameters", 1);
5721 scb = &ha->scbs[ha->max_cmds - 1];
5723 ips_init_scb(ha, scb);
5725 scb->timeout = ips_cmd_timeout;
5726 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
5728 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
5729 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5730 scb->cmd.basic_io.sg_count = 0;
5731 scb->cmd.basic_io.lba = 0;
5732 scb->cmd.basic_io.sector_count = 0;
5733 scb->cmd.basic_io.log_drv = 0;
5734 scb->data_len = sizeof (*ha->subsys);
5735 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5739 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5740 || (ret == IPS_SUCCESS_IMM)
5741 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5744 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
5748 /****************************************************************************/
5750 /* Routine Name: ips_read_config */
5752 /* Routine Description: */
5754 /* Read the configuration on the adapter */
5756 /****************************************************************************/
5758 ips_read_config(ips_ha_t * ha, int intr)
5764 METHOD_TRACE("ips_read_config", 1);
5766 /* set defaults for initiator IDs */
5767 for (i = 0; i < 4; i++)
5768 ha->conf->init_id[i] = 7;
5770 scb = &ha->scbs[ha->max_cmds - 1];
5772 ips_init_scb(ha, scb);
5774 scb->timeout = ips_cmd_timeout;
5775 scb->cdb[0] = IPS_CMD_READ_CONF;
5777 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
5778 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5779 scb->data_len = sizeof (*ha->conf);
5780 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5784 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5785 || (ret == IPS_SUCCESS_IMM)
5786 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
5788 memset(ha->conf, 0, sizeof (IPS_CONF));
5790 /* reset initiator IDs */
5791 for (i = 0; i < 4; i++)
5792 ha->conf->init_id[i] = 7;
5794 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
5795 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
5796 IPS_CMD_CMPLT_WERROR)
5802 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
5806 /****************************************************************************/
5808 /* Routine Name: ips_readwrite_page5 */
5810 /* Routine Description: */
5812 /* Read nvram page 5 from the adapter */
5814 /****************************************************************************/
5816 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
5821 METHOD_TRACE("ips_readwrite_page5", 1);
5823 scb = &ha->scbs[ha->max_cmds - 1];
5825 ips_init_scb(ha, scb);
5827 scb->timeout = ips_cmd_timeout;
5828 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
5830 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
5831 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
5832 scb->cmd.nvram.page = 5;
5833 scb->cmd.nvram.write = write;
5834 scb->cmd.nvram.reserved = 0;
5835 scb->cmd.nvram.reserved2 = 0;
5836 scb->data_len = sizeof (*ha->nvram);
5837 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
5839 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
5841 /* issue the command */
5843 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5844 || (ret == IPS_SUCCESS_IMM)
5845 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
5847 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
5852 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
5856 /****************************************************************************/
5858 /* Routine Name: ips_clear_adapter */
5860 /* Routine Description: */
5862 /* Clear the stripe lock tables */
5864 /****************************************************************************/
5866 ips_clear_adapter(ips_ha_t * ha, int intr)
5871 METHOD_TRACE("ips_clear_adapter", 1);
5873 scb = &ha->scbs[ha->max_cmds - 1];
5875 ips_init_scb(ha, scb);
5877 scb->timeout = ips_reset_timeout;
5878 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
5880 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
5881 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
5882 scb->cmd.config_sync.channel = 0;
5883 scb->cmd.config_sync.source_target = IPS_POCL;
5884 scb->cmd.config_sync.reserved = 0;
5885 scb->cmd.config_sync.reserved2 = 0;
5886 scb->cmd.config_sync.reserved3 = 0;
5890 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
5891 || (ret == IPS_SUCCESS_IMM)
5892 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5895 /* send unlock stripe command */
5896 ips_init_scb(ha, scb);
5898 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
5899 scb->timeout = ips_reset_timeout;
5901 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
5902 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
5903 scb->cmd.unlock_stripe.log_drv = 0;
5904 scb->cmd.unlock_stripe.control = IPS_CSL;
5905 scb->cmd.unlock_stripe.reserved = 0;
5906 scb->cmd.unlock_stripe.reserved2 = 0;
5907 scb->cmd.unlock_stripe.reserved3 = 0;
5911 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5912 || (ret == IPS_SUCCESS_IMM)
5913 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5919 /****************************************************************************/
5921 /* Routine Name: ips_ffdc_reset */
5923 /* Routine Description: */
5925 /* FFDC: write reset info */
5927 /****************************************************************************/
5929 ips_ffdc_reset(ips_ha_t * ha, int intr)
5933 METHOD_TRACE("ips_ffdc_reset", 1);
5935 scb = &ha->scbs[ha->max_cmds - 1];
5937 ips_init_scb(ha, scb);
5939 scb->timeout = ips_cmd_timeout;
5940 scb->cdb[0] = IPS_CMD_FFDC;
5941 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
5942 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
5943 scb->cmd.ffdc.reset_count = ha->reset_count;
5944 scb->cmd.ffdc.reset_type = 0x80;
5946 /* convert time to what the card wants */
5947 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
5950 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
5953 /****************************************************************************/
5955 /* Routine Name: ips_ffdc_time */
5957 /* Routine Description: */
5959 /* FFDC: write time info */
5961 /****************************************************************************/
5963 ips_ffdc_time(ips_ha_t * ha)
5967 METHOD_TRACE("ips_ffdc_time", 1);
5969 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
5971 scb = &ha->scbs[ha->max_cmds - 1];
5973 ips_init_scb(ha, scb);
5975 scb->timeout = ips_cmd_timeout;
5976 scb->cdb[0] = IPS_CMD_FFDC;
5977 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
5978 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
5979 scb->cmd.ffdc.reset_count = 0;
5980 scb->cmd.ffdc.reset_type = 0;
5982 /* convert time to what the card wants */
5983 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
5986 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
5989 /****************************************************************************/
5991 /* Routine Name: ips_fix_ffdc_time */
5993 /* Routine Description: */
5994 /* Adjust time_t to what the card wants */
5996 /****************************************************************************/
5998 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6005 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6006 int month_lengths[12][2] = { {31, 31},
6020 METHOD_TRACE("ips_fix_ffdc_time", 1);
6022 days = current_time / IPS_SECS_DAY;
6023 rem = current_time % IPS_SECS_DAY;
6025 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6026 rem = rem % IPS_SECS_HOUR;
6027 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6028 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6030 year = IPS_EPOCH_YEAR;
6031 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6034 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6037 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6038 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6039 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6043 scb->cmd.ffdc.yearH = year / 100;
6044 scb->cmd.ffdc.yearL = year % 100;
6046 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6047 days -= month_lengths[i][yleap];
6049 scb->cmd.ffdc.month = i + 1;
6050 scb->cmd.ffdc.day = days + 1;
6053 /****************************************************************************
6054 * BIOS Flash Routines *
6055 ****************************************************************************/
6057 /****************************************************************************/
6059 /* Routine Name: ips_erase_bios */
6061 /* Routine Description: */
6062 /* Erase the BIOS on the adapter */
6064 /****************************************************************************/
6066 ips_erase_bios(ips_ha_t * ha)
6071 METHOD_TRACE("ips_erase_bios", 1);
6075 /* Clear the status register */
6076 outl(0, ha->io_addr + IPS_REG_FLAP);
6077 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6078 udelay(25); /* 25 us */
6080 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6081 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6082 udelay(25); /* 25 us */
6085 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6086 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6087 udelay(25); /* 25 us */
6090 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6091 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6092 udelay(25); /* 25 us */
6095 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6096 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6097 udelay(25); /* 25 us */
6099 timeout = 80000; /* 80 seconds */
6101 while (timeout > 0) {
6102 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6103 outl(0, ha->io_addr + IPS_REG_FLAP);
6104 udelay(25); /* 25 us */
6107 status = inb(ha->io_addr + IPS_REG_FLDP);
6116 /* check for timeout */
6120 /* try to suspend the erase */
6121 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6122 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6123 udelay(25); /* 25 us */
6125 /* wait for 10 seconds */
6127 while (timeout > 0) {
6128 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6129 outl(0, ha->io_addr + IPS_REG_FLAP);
6130 udelay(25); /* 25 us */
6133 status = inb(ha->io_addr + IPS_REG_FLDP);
6145 /* check for valid VPP */
6150 /* check for successful flash */
6152 /* sequence error */
6155 /* Otherwise, we were successful */
6157 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6158 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6159 udelay(25); /* 25 us */
6162 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6163 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6164 udelay(25); /* 25 us */
6169 /****************************************************************************/
6171 /* Routine Name: ips_erase_bios_memio */
6173 /* Routine Description: */
6174 /* Erase the BIOS on the adapter */
6176 /****************************************************************************/
6178 ips_erase_bios_memio(ips_ha_t * ha)
6183 METHOD_TRACE("ips_erase_bios_memio", 1);
6187 /* Clear the status register */
6188 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6189 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6190 udelay(25); /* 25 us */
6192 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6193 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6194 udelay(25); /* 25 us */
6197 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6198 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6199 udelay(25); /* 25 us */
6202 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6203 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6204 udelay(25); /* 25 us */
6207 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6208 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6209 udelay(25); /* 25 us */
6211 timeout = 80000; /* 80 seconds */
6213 while (timeout > 0) {
6214 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6215 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6216 udelay(25); /* 25 us */
6219 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6228 /* check for timeout */
6232 /* try to suspend the erase */
6233 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6234 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6235 udelay(25); /* 25 us */
6237 /* wait for 10 seconds */
6239 while (timeout > 0) {
6240 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6241 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6242 udelay(25); /* 25 us */
6245 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6257 /* check for valid VPP */
6262 /* check for successful flash */
6264 /* sequence error */
6267 /* Otherwise, we were successful */
6269 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6270 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6271 udelay(25); /* 25 us */
6274 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6275 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6276 udelay(25); /* 25 us */
6281 /****************************************************************************/
6283 /* Routine Name: ips_program_bios */
6285 /* Routine Description: */
6286 /* Program the BIOS on the adapter */
6288 /****************************************************************************/
6290 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6297 METHOD_TRACE("ips_program_bios", 1);
6301 for (i = 0; i < buffersize; i++) {
6303 outl(i + offset, ha->io_addr + IPS_REG_FLAP);
6304 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6305 udelay(25); /* 25 us */
6307 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6308 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6309 udelay(25); /* 25 us */
6311 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6312 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6313 udelay(25); /* 25 us */
6315 /* wait up to one second */
6317 while (timeout > 0) {
6318 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6319 outl(0, ha->io_addr + IPS_REG_FLAP);
6320 udelay(25); /* 25 us */
6323 status = inb(ha->io_addr + IPS_REG_FLDP);
6334 outl(0, ha->io_addr + IPS_REG_FLAP);
6335 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6336 udelay(25); /* 25 us */
6338 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6339 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6340 udelay(25); /* 25 us */
6345 /* check the status */
6346 if (status & 0x18) {
6347 /* programming error */
6348 outl(0, ha->io_addr + IPS_REG_FLAP);
6349 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6350 udelay(25); /* 25 us */
6352 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6353 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6354 udelay(25); /* 25 us */
6360 /* Enable reading */
6361 outl(0, ha->io_addr + IPS_REG_FLAP);
6362 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6363 udelay(25); /* 25 us */
6365 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6366 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6367 udelay(25); /* 25 us */
6372 /****************************************************************************/
6374 /* Routine Name: ips_program_bios_memio */
6376 /* Routine Description: */
6377 /* Program the BIOS on the adapter */
6379 /****************************************************************************/
6381 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6388 METHOD_TRACE("ips_program_bios_memio", 1);
6392 for (i = 0; i < buffersize; i++) {
6394 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6395 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6396 udelay(25); /* 25 us */
6398 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6399 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6400 udelay(25); /* 25 us */
6402 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6403 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6404 udelay(25); /* 25 us */
6406 /* wait up to one second */
6408 while (timeout > 0) {
6409 if (ha->pcidev->revision == IPS_REVID_TROMBONE64) {
6410 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6411 udelay(25); /* 25 us */
6414 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6425 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6426 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6427 udelay(25); /* 25 us */
6429 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6430 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6431 udelay(25); /* 25 us */
6436 /* check the status */
6437 if (status & 0x18) {
6438 /* programming error */
6439 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6440 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6441 udelay(25); /* 25 us */
6443 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6444 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6445 udelay(25); /* 25 us */
6451 /* Enable reading */
6452 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6453 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6454 udelay(25); /* 25 us */
6456 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6457 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6458 udelay(25); /* 25 us */
6463 /****************************************************************************/
6465 /* Routine Name: ips_verify_bios */
6467 /* Routine Description: */
6468 /* Verify the BIOS on the adapter */
6470 /****************************************************************************/
6472 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6478 METHOD_TRACE("ips_verify_bios", 1);
6481 outl(0, ha->io_addr + IPS_REG_FLAP);
6482 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6483 udelay(25); /* 25 us */
6485 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6488 outl(1, ha->io_addr + IPS_REG_FLAP);
6489 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6490 udelay(25); /* 25 us */
6491 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6495 for (i = 2; i < buffersize; i++) {
6497 outl(i + offset, ha->io_addr + IPS_REG_FLAP);
6498 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6499 udelay(25); /* 25 us */
6501 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6512 /****************************************************************************/
6514 /* Routine Name: ips_verify_bios_memio */
6516 /* Routine Description: */
6517 /* Verify the BIOS on the adapter */
6519 /****************************************************************************/
6521 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6527 METHOD_TRACE("ips_verify_bios_memio", 1);
6530 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6531 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6532 udelay(25); /* 25 us */
6534 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6537 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6538 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6539 udelay(25); /* 25 us */
6540 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6544 for (i = 2; i < buffersize; i++) {
6546 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6547 if (ha->pcidev->revision == IPS_REVID_TROMBONE64)
6548 udelay(25); /* 25 us */
6551 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6562 /****************************************************************************/
6564 /* Routine Name: ips_abort_init */
6566 /* Routine Description: */
6567 /* cleanup routine for a failed adapter initialization */
6568 /****************************************************************************/
6570 ips_abort_init(ips_ha_t * ha, int index)
6574 ips_ha[index] = NULL;
6575 ips_sh[index] = NULL;
6579 /****************************************************************************/
6581 /* Routine Name: ips_shift_controllers */
6583 /* Routine Description: */
6584 /* helper function for ordering adapters */
6585 /****************************************************************************/
6587 ips_shift_controllers(int lowindex, int highindex)
6589 ips_ha_t *ha_sav = ips_ha[highindex];
6590 struct Scsi_Host *sh_sav = ips_sh[highindex];
6593 for (i = highindex; i > lowindex; i--) {
6594 ips_ha[i] = ips_ha[i - 1];
6595 ips_sh[i] = ips_sh[i - 1];
6596 ips_ha[i]->host_num = i;
6598 ha_sav->host_num = lowindex;
6599 ips_ha[lowindex] = ha_sav;
6600 ips_sh[lowindex] = sh_sav;
6603 /****************************************************************************/
6605 /* Routine Name: ips_order_controllers */
6607 /* Routine Description: */
6608 /* place controllers is the "proper" boot order */
6609 /****************************************************************************/
6611 ips_order_controllers(void)
6613 int i, j, tmp, position = 0;
6614 IPS_NVRAM_P5 *nvram;
6617 nvram = ips_ha[0]->nvram;
6619 if (nvram->adapter_order[0]) {
6620 for (i = 1; i <= nvram->adapter_order[0]; i++) {
6621 for (j = position; j < ips_num_controllers; j++) {
6622 switch (ips_ha[j]->ad_type) {
6623 case IPS_ADTYPE_SERVERAID6M:
6624 case IPS_ADTYPE_SERVERAID7M:
6625 if (nvram->adapter_order[i] == 'M') {
6626 ips_shift_controllers(position,
6631 case IPS_ADTYPE_SERVERAID4L:
6632 case IPS_ADTYPE_SERVERAID4M:
6633 case IPS_ADTYPE_SERVERAID4MX:
6634 case IPS_ADTYPE_SERVERAID4LX:
6635 if (nvram->adapter_order[i] == 'N') {
6636 ips_shift_controllers(position,
6641 case IPS_ADTYPE_SERVERAID6I:
6642 case IPS_ADTYPE_SERVERAID5I2:
6643 case IPS_ADTYPE_SERVERAID5I1:
6644 case IPS_ADTYPE_SERVERAID7k:
6645 if (nvram->adapter_order[i] == 'S') {
6646 ips_shift_controllers(position,
6651 case IPS_ADTYPE_SERVERAID:
6652 case IPS_ADTYPE_SERVERAID2:
6653 case IPS_ADTYPE_NAVAJO:
6654 case IPS_ADTYPE_KIOWA:
6655 case IPS_ADTYPE_SERVERAID3L:
6656 case IPS_ADTYPE_SERVERAID3:
6657 case IPS_ADTYPE_SERVERAID4H:
6658 if (nvram->adapter_order[i] == 'A') {
6659 ips_shift_controllers(position,
6669 /* if adapter_order[0], then ordering is complete */
6672 /* old bios, use older ordering */
6674 for (i = position; i < ips_num_controllers; i++) {
6675 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I2 ||
6676 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I1) {
6677 ips_shift_controllers(position, i);
6682 /* if there were no 5I cards, then don't do any extra ordering */
6685 for (i = position; i < ips_num_controllers; i++) {
6686 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4L ||
6687 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4M ||
6688 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4LX ||
6689 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4MX) {
6690 ips_shift_controllers(position, i);
6698 /****************************************************************************/
6700 /* Routine Name: ips_register_scsi */
6702 /* Routine Description: */
6703 /* perform any registration and setup with the scsi layer */
6704 /****************************************************************************/
6706 ips_register_scsi(int index)
6708 struct Scsi_Host *sh;
6709 ips_ha_t *ha, *oldha = ips_ha[index];
6710 sh = scsi_host_alloc(&ips_driver_template, sizeof (ips_ha_t));
6712 IPS_PRINTK(KERN_WARNING, oldha->pcidev,
6713 "Unable to register controller with SCSI subsystem\n");
6717 memcpy(ha, oldha, sizeof (ips_ha_t));
6718 free_irq(oldha->pcidev->irq, oldha);
6719 /* Install the interrupt handler with the new ha */
6720 if (request_irq(ha->pcidev->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
6721 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6722 "Unable to install interrupt handler\n");
6728 /* Store away needed values for later use */
6729 sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
6730 sh->sg_tablesize = sh->hostt->sg_tablesize;
6731 sh->can_queue = sh->hostt->can_queue;
6732 sh->cmd_per_lun = sh->hostt->cmd_per_lun;
6733 sh->use_clustering = sh->hostt->use_clustering;
6734 sh->max_sectors = 128;
6736 sh->max_id = ha->ntargets;
6737 sh->max_lun = ha->nlun;
6738 sh->max_channel = ha->nbus - 1;
6739 sh->can_queue = ha->max_cmds - 1;
6741 if (scsi_add_host(sh, &ha->pcidev->dev))
6752 free_irq(ha->pcidev->irq, ha);
6758 /*---------------------------------------------------------------------------*/
6759 /* Routine Name: ips_remove_device */
6761 /* Routine Description: */
6762 /* Remove one Adapter ( Hot Plugging ) */
6763 /*---------------------------------------------------------------------------*/
6765 ips_remove_device(struct pci_dev *pci_dev)
6767 struct Scsi_Host *sh = pci_get_drvdata(pci_dev);
6769 pci_set_drvdata(pci_dev, NULL);
6773 pci_release_regions(pci_dev);
6774 pci_disable_device(pci_dev);
6777 /****************************************************************************/
6779 /* Routine Name: ips_module_init */
6781 /* Routine Description: */
6782 /* function called on module load */
6783 /****************************************************************************/
6785 ips_module_init(void)
6787 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
6788 printk(KERN_ERR "ips: This driver has only been tested on the x86/ia64/x86_64 platforms\n");
6789 add_taint(TAINT_CPU_OUT_OF_SPEC, LOCKDEP_STILL_OK);
6792 if (pci_register_driver(&ips_pci_driver) < 0)
6794 ips_driver_template.module = THIS_MODULE;
6795 ips_order_controllers();
6796 if (!ips_detect(&ips_driver_template)) {
6797 pci_unregister_driver(&ips_pci_driver);
6800 register_reboot_notifier(&ips_notifier);
6804 /****************************************************************************/
6806 /* Routine Name: ips_module_exit */
6808 /* Routine Description: */
6809 /* function called on module unload */
6810 /****************************************************************************/
6812 ips_module_exit(void)
6814 pci_unregister_driver(&ips_pci_driver);
6815 unregister_reboot_notifier(&ips_notifier);
6818 module_init(ips_module_init);
6819 module_exit(ips_module_exit);
6821 /*---------------------------------------------------------------------------*/
6822 /* Routine Name: ips_insert_device */
6824 /* Routine Description: */
6825 /* Add One Adapter ( Hot Plug ) */
6828 /* 0 if Successful, else non-zero */
6829 /*---------------------------------------------------------------------------*/
6831 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
6836 METHOD_TRACE("ips_insert_device", 1);
6837 rc = pci_enable_device(pci_dev);
6841 rc = pci_request_regions(pci_dev, "ips");
6845 rc = ips_init_phase1(pci_dev, &index);
6847 rc = ips_init_phase2(index);
6850 if (ips_register_scsi(index)) {
6851 ips_free(ips_ha[index]);
6856 ips_num_controllers++;
6858 ips_next_controller = ips_num_controllers;
6862 goto err_out_regions;
6865 pci_set_drvdata(pci_dev, ips_sh[index]);
6869 pci_release_regions(pci_dev);
6871 pci_disable_device(pci_dev);
6875 /*---------------------------------------------------------------------------*/
6876 /* Routine Name: ips_init_phase1 */
6878 /* Routine Description: */
6879 /* Adapter Initialization */
6882 /* 0 if Successful, else non-zero */
6883 /*---------------------------------------------------------------------------*/
6885 ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
6896 dma_addr_t dma_address;
6897 char __iomem *ioremap_ptr;
6898 char __iomem *mem_ptr;
6901 METHOD_TRACE("ips_init_phase1", 1);
6902 index = IPS_MAX_ADAPTERS;
6903 for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
6904 if (ips_ha[j] == NULL) {
6910 if (index >= IPS_MAX_ADAPTERS)
6913 /* stuff that we get in dev */
6914 bus = pci_dev->bus->number;
6915 func = pci_dev->devfn;
6917 /* Init MEM/IO addresses to 0 */
6923 for (j = 0; j < 2; j++) {
6924 if (!pci_resource_start(pci_dev, j))
6927 if (pci_resource_flags(pci_dev, j) & IORESOURCE_IO) {
6928 io_addr = pci_resource_start(pci_dev, j);
6929 io_len = pci_resource_len(pci_dev, j);
6931 mem_addr = pci_resource_start(pci_dev, j);
6932 mem_len = pci_resource_len(pci_dev, j);
6936 /* setup memory mapped area (if applicable) */
6941 base = mem_addr & PAGE_MASK;
6942 offs = mem_addr - base;
6943 ioremap_ptr = ioremap(base, PAGE_SIZE);
6946 mem_ptr = ioremap_ptr + offs;
6952 /* found a controller */
6953 ha = kzalloc(sizeof (ips_ha_t), GFP_KERNEL);
6955 IPS_PRINTK(KERN_WARNING, pci_dev,
6956 "Unable to allocate temporary ha struct\n");
6960 ips_sh[index] = NULL;
6964 /* Store info in HA structure */
6965 ha->io_addr = io_addr;
6966 ha->io_len = io_len;
6967 ha->mem_addr = mem_addr;
6968 ha->mem_len = mem_len;
6969 ha->mem_ptr = mem_ptr;
6970 ha->ioremap_ptr = ioremap_ptr;
6971 ha->host_num = (uint32_t) index;
6972 ha->slot_num = PCI_SLOT(pci_dev->devfn);
6973 ha->pcidev = pci_dev;
6976 * Set the pci_dev's dma_mask. Not all adapters support 64bit
6977 * addressing so don't enable it if the adapter can't support
6978 * it! Also, don't use 64bit addressing if dma addresses
6979 * are guaranteed to be < 4G.
6981 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
6982 !pci_set_dma_mask(ha->pcidev, DMA_BIT_MASK(64))) {
6983 (ha)->flags |= IPS_HA_ENH_SG;
6985 if (pci_set_dma_mask(ha->pcidev, DMA_BIT_MASK(32)) != 0) {
6986 printk(KERN_WARNING "Unable to set DMA Mask\n");
6987 return ips_abort_init(ha, index);
6990 if(ips_cd_boot && !ips_FlashData){
6991 ips_FlashData = pci_alloc_consistent(pci_dev, PAGE_SIZE << 7,
6995 ha->enq = pci_alloc_consistent(pci_dev, sizeof (IPS_ENQ),
6998 IPS_PRINTK(KERN_WARNING, pci_dev,
6999 "Unable to allocate host inquiry structure\n");
7000 return ips_abort_init(ha, index);
7003 ha->adapt = pci_alloc_consistent(pci_dev, sizeof (IPS_ADAPTER) +
7004 sizeof (IPS_IO_CMD), &dma_address);
7006 IPS_PRINTK(KERN_WARNING, pci_dev,
7007 "Unable to allocate host adapt & dummy structures\n");
7008 return ips_abort_init(ha, index);
7010 ha->adapt->hw_status_start = dma_address;
7011 ha->dummy = (void *) (ha->adapt + 1);
7015 ha->logical_drive_info = pci_alloc_consistent(pci_dev, sizeof (IPS_LD_INFO), &dma_address);
7016 if (!ha->logical_drive_info) {
7017 IPS_PRINTK(KERN_WARNING, pci_dev,
7018 "Unable to allocate logical drive info structure\n");
7019 return ips_abort_init(ha, index);
7021 ha->logical_drive_info_dma_addr = dma_address;
7024 ha->conf = kmalloc(sizeof (IPS_CONF), GFP_KERNEL);
7027 IPS_PRINTK(KERN_WARNING, pci_dev,
7028 "Unable to allocate host conf structure\n");
7029 return ips_abort_init(ha, index);
7032 ha->nvram = kmalloc(sizeof (IPS_NVRAM_P5), GFP_KERNEL);
7035 IPS_PRINTK(KERN_WARNING, pci_dev,
7036 "Unable to allocate host NVRAM structure\n");
7037 return ips_abort_init(ha, index);
7040 ha->subsys = kmalloc(sizeof (IPS_SUBSYS), GFP_KERNEL);
7043 IPS_PRINTK(KERN_WARNING, pci_dev,
7044 "Unable to allocate host subsystem structure\n");
7045 return ips_abort_init(ha, index);
7048 /* the ioctl buffer is now used during adapter initialization, so its
7049 * successful allocation is now required */
7050 if (ips_ioctlsize < PAGE_SIZE)
7051 ips_ioctlsize = PAGE_SIZE;
7053 ha->ioctl_data = pci_alloc_consistent(pci_dev, ips_ioctlsize,
7054 &ha->ioctl_busaddr);
7055 ha->ioctl_len = ips_ioctlsize;
7056 if (!ha->ioctl_data) {
7057 IPS_PRINTK(KERN_WARNING, pci_dev,
7058 "Unable to allocate IOCTL data\n");
7059 return ips_abort_init(ha, index);
7065 ips_setup_funclist(ha);
7067 if ((IPS_IS_MORPHEUS(ha)) || (IPS_IS_MARCO(ha))) {
7068 /* If Morpheus appears dead, reset it */
7069 IsDead = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
7070 if (IsDead == 0xDEADBEEF) {
7071 ips_reset_morpheus(ha);
7076 * Initialize the card if it isn't already
7079 if (!(*ha->func.isinit) (ha)) {
7080 if (!(*ha->func.init) (ha)) {
7082 * Initialization failed
7084 IPS_PRINTK(KERN_WARNING, pci_dev,
7085 "Unable to initialize controller\n");
7086 return ips_abort_init(ha, index);
7094 /*---------------------------------------------------------------------------*/
7095 /* Routine Name: ips_init_phase2 */
7097 /* Routine Description: */
7098 /* Adapter Initialization Phase 2 */
7101 /* 0 if Successful, else non-zero */
7102 /*---------------------------------------------------------------------------*/
7104 ips_init_phase2(int index)
7110 METHOD_TRACE("ips_init_phase2", 1);
7112 ips_ha[index] = NULL;
7116 /* Install the interrupt handler */
7117 if (request_irq(ha->pcidev->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
7118 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7119 "Unable to install interrupt handler\n");
7120 return ips_abort_init(ha, index);
7124 * Allocate a temporary SCB for initialization
7127 if (!ips_allocatescbs(ha)) {
7128 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7129 "Unable to allocate a CCB\n");
7130 free_irq(ha->pcidev->irq, ha);
7131 return ips_abort_init(ha, index);
7134 if (!ips_hainit(ha)) {
7135 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7136 "Unable to initialize controller\n");
7137 free_irq(ha->pcidev->irq, ha);
7138 return ips_abort_init(ha, index);
7140 /* Free the temporary SCB */
7141 ips_deallocatescbs(ha, 1);
7144 if (!ips_allocatescbs(ha)) {
7145 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7146 "Unable to allocate CCBs\n");
7147 free_irq(ha->pcidev->irq, ha);
7148 return ips_abort_init(ha, index);
7154 MODULE_LICENSE("GPL");
7155 MODULE_DESCRIPTION("IBM ServeRAID Adapter Driver " IPS_VER_STRING);
7156 MODULE_VERSION(IPS_VER_STRING);
7160 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7161 * Emacs will notice this stuff at the end of the file and automatically
7162 * adjust the settings for this buffer only. This must remain at the end
7164 * ---------------------------------------------------------------------------
7167 * c-brace-imaginary-offset: 0
7168 * c-brace-offset: -2
7169 * c-argdecl-indent: 2
7170 * c-label-offset: -2
7171 * c-continued-statement-offset: 2
7172 * c-continued-brace-offset: 0
7173 * indent-tabs-mode: nil