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: */
46 /* ipslinux@adaptec.com */
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 */
86 /* 4.00.06a - Port to 2.4 (trivial) -- Christoph Hellwig <hch@infradead.org> */
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 whereever 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/version.h>
169 #include <linux/string.h>
170 #include <linux/errno.h>
171 #include <linux/kernel.h>
172 #include <linux/ioport.h>
173 #include <linux/slab.h>
174 #include <linux/delay.h>
175 #include <linux/pci.h>
176 #include <linux/proc_fs.h>
177 #include <linux/reboot.h>
178 #include <linux/interrupt.h>
180 #include <linux/blkdev.h>
181 #include <linux/types.h>
182 #include <linux/dma-mapping.h>
186 #include <scsi/scsi_host.h>
190 #include <linux/module.h>
192 #include <linux/stat.h>
194 #include <linux/spinlock.h>
195 #include <linux/init.h>
197 #include <linux/smp.h>
200 static char *ips = NULL;
201 module_param(ips, charp, 0);
207 #define IPS_VERSION_HIGH "7.12"
208 #define IPS_VERSION_LOW ".05 "
210 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
211 #warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
214 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
215 #include <linux/blk.h>
217 #define IPS_LOCK_SAVE(lock,flags) spin_lock_irqsave(&io_request_lock,flags)
218 #define IPS_UNLOCK_RESTORE(lock,flags) spin_unlock_irqrestore(&io_request_lock,flags)
220 #define __devexit_p(x) x
223 #define IPS_LOCK_SAVE(lock,flags) do{spin_lock(lock);(void)flags;}while(0)
224 #define IPS_UNLOCK_RESTORE(lock,flags) do{spin_unlock(lock);(void)flags;}while(0)
227 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
228 DMA_NONE == scb->scsi_cmd->sc_data_direction) ? \
229 PCI_DMA_BIDIRECTIONAL : \
230 scb->scsi_cmd->sc_data_direction)
233 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
234 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
235 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
237 #define METHOD_TRACE(s, i)
239 #define DEBUG_VAR(i, s, v...)
243 * Function prototypes
245 static int ips_detect(struct scsi_host_template *);
246 static int ips_release(struct Scsi_Host *);
247 static int ips_eh_abort(struct scsi_cmnd *);
248 static int ips_eh_reset(struct scsi_cmnd *);
249 static int ips_queue(struct scsi_cmnd *, void (*)(struct scsi_cmnd *));
250 static const char *ips_info(struct Scsi_Host *);
251 static irqreturn_t do_ipsintr(int, void *);
252 static int ips_hainit(ips_ha_t *);
253 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
254 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
255 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
256 static int ips_online(ips_ha_t *, ips_scb_t *);
257 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
258 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
259 static int ips_msense(ips_ha_t *, ips_scb_t *);
260 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
261 static int ips_deallocatescbs(ips_ha_t *, int);
262 static int ips_allocatescbs(ips_ha_t *);
263 static int ips_reset_copperhead(ips_ha_t *);
264 static int ips_reset_copperhead_memio(ips_ha_t *);
265 static int ips_reset_morpheus(ips_ha_t *);
266 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
267 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
268 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
269 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
270 static int ips_isintr_copperhead(ips_ha_t *);
271 static int ips_isintr_copperhead_memio(ips_ha_t *);
272 static int ips_isintr_morpheus(ips_ha_t *);
273 static int ips_wait(ips_ha_t *, int, int);
274 static int ips_write_driver_status(ips_ha_t *, int);
275 static int ips_read_adapter_status(ips_ha_t *, int);
276 static int ips_read_subsystem_parameters(ips_ha_t *, int);
277 static int ips_read_config(ips_ha_t *, int);
278 static int ips_clear_adapter(ips_ha_t *, int);
279 static int ips_readwrite_page5(ips_ha_t *, int, int);
280 static int ips_init_copperhead(ips_ha_t *);
281 static int ips_init_copperhead_memio(ips_ha_t *);
282 static int ips_init_morpheus(ips_ha_t *);
283 static int ips_isinit_copperhead(ips_ha_t *);
284 static int ips_isinit_copperhead_memio(ips_ha_t *);
285 static int ips_isinit_morpheus(ips_ha_t *);
286 static int ips_erase_bios(ips_ha_t *);
287 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
288 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
289 static int ips_erase_bios_memio(ips_ha_t *);
290 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
291 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
292 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
293 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
294 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
295 static void ips_free_flash_copperhead(ips_ha_t * ha);
296 static void ips_get_bios_version(ips_ha_t *, int);
297 static void ips_identify_controller(ips_ha_t *);
298 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
299 static void ips_enable_int_copperhead(ips_ha_t *);
300 static void ips_enable_int_copperhead_memio(ips_ha_t *);
301 static void ips_enable_int_morpheus(ips_ha_t *);
302 static int ips_intr_copperhead(ips_ha_t *);
303 static int ips_intr_morpheus(ips_ha_t *);
304 static void ips_next(ips_ha_t *, int);
305 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
306 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
307 static void ips_done(ips_ha_t *, ips_scb_t *);
308 static void ips_free(ips_ha_t *);
309 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
310 static void ips_freescb(ips_ha_t *, ips_scb_t *);
311 static void ips_setup_funclist(ips_ha_t *);
312 static void ips_statinit(ips_ha_t *);
313 static void ips_statinit_memio(ips_ha_t *);
314 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
315 static void ips_ffdc_reset(ips_ha_t *, int);
316 static void ips_ffdc_time(ips_ha_t *);
317 static uint32_t ips_statupd_copperhead(ips_ha_t *);
318 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
319 static uint32_t ips_statupd_morpheus(ips_ha_t *);
320 static ips_scb_t *ips_getscb(ips_ha_t *);
321 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
322 static void ips_putq_wait_tail(ips_wait_queue_t *, struct scsi_cmnd *);
323 static void ips_putq_copp_tail(ips_copp_queue_t *,
324 ips_copp_wait_item_t *);
325 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
326 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
327 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
328 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *,
330 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
331 ips_copp_wait_item_t *);
332 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
334 static int ips_is_passthru(struct scsi_cmnd *);
335 static int ips_make_passthru(ips_ha_t *, struct scsi_cmnd *, ips_scb_t *, int);
336 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
337 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
338 static void ips_scmd_buf_write(struct scsi_cmnd * scmd, void *data,
340 static void ips_scmd_buf_read(struct scsi_cmnd * scmd, void *data,
343 static int ips_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
344 static int ips_host_info(ips_ha_t *, char *, off_t, int);
345 static void copy_mem_info(IPS_INFOSTR *, char *, int);
346 static int copy_info(IPS_INFOSTR *, char *, ...);
347 static int ips_abort_init(ips_ha_t * ha, int index);
348 static int ips_init_phase2(int index);
350 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
351 static int ips_register_scsi(int index);
353 static int ips_poll_for_flush_complete(ips_ha_t * ha);
354 static void ips_flush_and_reset(ips_ha_t *ha);
359 static const char ips_name[] = "ips";
360 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
361 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
362 static unsigned int ips_next_controller;
363 static unsigned int ips_num_controllers;
364 static unsigned int ips_released_controllers;
365 static int ips_hotplug;
366 static int ips_cmd_timeout = 60;
367 static int ips_reset_timeout = 60 * 5;
368 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
369 static int ips_force_i2o = 1; /* Always use I2O command delivery */
370 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
371 static int ips_cd_boot; /* Booting from Manager CD */
372 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
373 static dma_addr_t ips_flashbusaddr;
374 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
375 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
376 static struct scsi_host_template ips_driver_template = {
377 .detect = ips_detect,
378 .release = ips_release,
380 .queuecommand = ips_queue,
381 .eh_abort_handler = ips_eh_abort,
382 .eh_host_reset_handler = ips_eh_reset,
384 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
385 .proc_info = ips_proc_info,
386 .slave_configure = ips_slave_configure,
388 .proc_info = ips_proc24_info,
389 .select_queue_depths = ips_select_queue_depth,
391 .bios_param = ips_biosparam,
393 .sg_tablesize = IPS_MAX_SG,
395 .use_clustering = ENABLE_CLUSTERING,
396 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
397 .use_new_eh_code = 1,
399 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
405 /* This table describes all ServeRAID Adapters */
406 static struct pci_device_id ips_pci_table[] = {
407 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
408 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
409 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
413 MODULE_DEVICE_TABLE( pci, ips_pci_table );
415 static char ips_hot_plug_name[] = "ips";
417 static int __devinit ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
418 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
420 static struct pci_driver ips_pci_driver = {
421 .name = ips_hot_plug_name,
422 .id_table = ips_pci_table,
423 .probe = ips_insert_device,
424 .remove = __devexit_p(ips_remove_device),
429 * Necessary forward function protoypes
431 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
433 #define MAX_ADAPTER_NAME 15
435 static char ips_adapter_name[][30] = {
438 "ServeRAID on motherboard",
439 "ServeRAID on motherboard",
456 static struct notifier_block ips_notifier = {
463 static char ips_command_direction[] = {
464 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
465 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
466 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
467 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
468 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
469 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
470 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
471 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
472 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
473 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
474 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
475 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
476 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
477 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
478 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
479 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, 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_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
482 IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
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,
487 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
488 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
489 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
490 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
491 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
492 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
493 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
494 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
495 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
496 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
497 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
498 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
499 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
500 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
501 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
502 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
503 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
504 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
505 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
506 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
507 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
508 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
509 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
510 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
511 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
512 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
513 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
514 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
518 /****************************************************************************/
520 /* Routine Name: ips_setup */
522 /* Routine Description: */
524 /* setup parameters to the driver */
526 /****************************************************************************/
528 ips_setup(char *ips_str)
534 IPS_OPTION options[] = {
535 {"noi2o", &ips_force_i2o, 0},
536 {"nommap", &ips_force_memio, 0},
537 {"ioctlsize", &ips_ioctlsize, IPS_IOCTL_SIZE},
538 {"cdboot", &ips_cd_boot, 0},
539 {"maxcmds", &MaxLiteCmds, 32},
542 /* Don't use strtok() anymore ( if 2.4 Kernel or beyond ) */
543 /* Search for value */
544 while ((key = strsep(&ips_str, ",."))) {
547 value = strchr(key, ':');
551 * We now have key/value pairs.
552 * Update the variables
554 for (i = 0; i < ARRAY_SIZE(options); i++) {
556 (key, options[i].option_name,
557 strlen(options[i].option_name)) == 0) {
559 *options[i].option_flag =
560 simple_strtoul(value, NULL, 0);
562 *options[i].option_flag =
563 options[i].option_value;
572 __setup("ips=", ips_setup);
574 /****************************************************************************/
576 /* Routine Name: ips_detect */
578 /* Routine Description: */
580 /* Detect and initialize the driver */
582 /* NOTE: this routine is called under the io_request_lock spinlock */
584 /****************************************************************************/
586 ips_detect(struct scsi_host_template * SHT)
590 METHOD_TRACE("ips_detect", 1);
597 for (i = 0; i < ips_num_controllers; i++) {
598 if (ips_register_scsi(i))
600 ips_released_controllers++;
603 return (ips_num_controllers);
606 /****************************************************************************/
607 /* configure the function pointers to use the functions that will work */
608 /* with the found version of the adapter */
609 /****************************************************************************/
611 ips_setup_funclist(ips_ha_t * ha)
617 if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
618 /* morpheus / marco / sebring */
619 ha->func.isintr = ips_isintr_morpheus;
620 ha->func.isinit = ips_isinit_morpheus;
621 ha->func.issue = ips_issue_i2o_memio;
622 ha->func.init = ips_init_morpheus;
623 ha->func.statupd = ips_statupd_morpheus;
624 ha->func.reset = ips_reset_morpheus;
625 ha->func.intr = ips_intr_morpheus;
626 ha->func.enableint = ips_enable_int_morpheus;
627 } else if (IPS_USE_MEMIO(ha)) {
628 /* copperhead w/MEMIO */
629 ha->func.isintr = ips_isintr_copperhead_memio;
630 ha->func.isinit = ips_isinit_copperhead_memio;
631 ha->func.init = ips_init_copperhead_memio;
632 ha->func.statupd = ips_statupd_copperhead_memio;
633 ha->func.statinit = ips_statinit_memio;
634 ha->func.reset = ips_reset_copperhead_memio;
635 ha->func.intr = ips_intr_copperhead;
636 ha->func.erasebios = ips_erase_bios_memio;
637 ha->func.programbios = ips_program_bios_memio;
638 ha->func.verifybios = ips_verify_bios_memio;
639 ha->func.enableint = ips_enable_int_copperhead_memio;
640 if (IPS_USE_I2O_DELIVER(ha))
641 ha->func.issue = ips_issue_i2o_memio;
643 ha->func.issue = ips_issue_copperhead_memio;
646 ha->func.isintr = ips_isintr_copperhead;
647 ha->func.isinit = ips_isinit_copperhead;
648 ha->func.init = ips_init_copperhead;
649 ha->func.statupd = ips_statupd_copperhead;
650 ha->func.statinit = ips_statinit;
651 ha->func.reset = ips_reset_copperhead;
652 ha->func.intr = ips_intr_copperhead;
653 ha->func.erasebios = ips_erase_bios;
654 ha->func.programbios = ips_program_bios;
655 ha->func.verifybios = ips_verify_bios;
656 ha->func.enableint = ips_enable_int_copperhead;
658 if (IPS_USE_I2O_DELIVER(ha))
659 ha->func.issue = ips_issue_i2o;
661 ha->func.issue = ips_issue_copperhead;
665 /****************************************************************************/
667 /* Routine Name: ips_release */
669 /* Routine Description: */
671 /* Remove a driver */
673 /****************************************************************************/
675 ips_release(struct Scsi_Host *sh)
681 METHOD_TRACE("ips_release", 1);
683 for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++) ;
685 if (i == IPS_MAX_ADAPTERS) {
687 "(%s) release, invalid Scsi_Host pointer.\n", ips_name);
697 /* flush the cache on the controller */
698 scb = &ha->scbs[ha->max_cmds - 1];
700 ips_init_scb(ha, scb);
702 scb->timeout = ips_cmd_timeout;
703 scb->cdb[0] = IPS_CMD_FLUSH;
705 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
706 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
707 scb->cmd.flush_cache.state = IPS_NORM_STATE;
708 scb->cmd.flush_cache.reserved = 0;
709 scb->cmd.flush_cache.reserved2 = 0;
710 scb->cmd.flush_cache.reserved3 = 0;
711 scb->cmd.flush_cache.reserved4 = 0;
713 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
716 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) == IPS_FAILURE)
717 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Incomplete Flush.\n");
719 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Complete.\n");
724 /* free extra memory */
727 /* Free I/O Region */
729 release_region(ha->io_addr, ha->io_len);
732 free_irq(ha->irq, ha);
737 ips_released_controllers++;
742 /****************************************************************************/
744 /* Routine Name: ips_halt */
746 /* Routine Description: */
748 /* Perform cleanup when the system reboots */
750 /****************************************************************************/
752 ips_halt(struct notifier_block *nb, ulong event, void *buf)
758 if ((event != SYS_RESTART) && (event != SYS_HALT) &&
759 (event != SYS_POWER_OFF))
760 return (NOTIFY_DONE);
762 for (i = 0; i < ips_next_controller; i++) {
763 ha = (ips_ha_t *) ips_ha[i];
771 /* flush the cache on the controller */
772 scb = &ha->scbs[ha->max_cmds - 1];
774 ips_init_scb(ha, scb);
776 scb->timeout = ips_cmd_timeout;
777 scb->cdb[0] = IPS_CMD_FLUSH;
779 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
780 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
781 scb->cmd.flush_cache.state = IPS_NORM_STATE;
782 scb->cmd.flush_cache.reserved = 0;
783 scb->cmd.flush_cache.reserved2 = 0;
784 scb->cmd.flush_cache.reserved3 = 0;
785 scb->cmd.flush_cache.reserved4 = 0;
787 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
790 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) ==
792 IPS_PRINTK(KERN_WARNING, ha->pcidev,
793 "Incomplete Flush.\n");
795 IPS_PRINTK(KERN_WARNING, ha->pcidev,
796 "Flushing Complete.\n");
802 /****************************************************************************/
804 /* Routine Name: ips_eh_abort */
806 /* Routine Description: */
808 /* Abort a command (using the new error code stuff) */
809 /* Note: this routine is called under the io_request_lock */
810 /****************************************************************************/
811 int ips_eh_abort(struct scsi_cmnd *SC)
814 ips_copp_wait_item_t *item;
816 unsigned long cpu_flags;
817 struct Scsi_Host *host;
819 METHOD_TRACE("ips_eh_abort", 1);
824 host = SC->device->host;
825 ha = (ips_ha_t *) SC->device->host->hostdata;
833 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
835 /* See if the command is on the copp queue */
836 item = ha->copp_waitlist.head;
837 while ((item) && (item->scsi_cmd != SC))
842 ips_removeq_copp(&ha->copp_waitlist, item);
845 /* See if the command is on the wait queue */
846 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
847 /* command not sent yet */
850 /* command must have already been sent */
854 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
858 /****************************************************************************/
860 /* Routine Name: ips_eh_reset */
862 /* Routine Description: */
864 /* Reset the controller (with new eh error code) */
866 /* NOTE: this routine is called under the io_request_lock spinlock */
868 /****************************************************************************/
869 static int __ips_eh_reset(struct scsi_cmnd *SC)
875 ips_copp_wait_item_t *item;
877 METHOD_TRACE("ips_eh_reset", 1);
884 DEBUG(1, "Reset called with NULL scsi command");
889 ha = (ips_ha_t *) SC->device->host->hostdata;
892 DEBUG(1, "Reset called with NULL ha struct");
900 /* See if the command is on the copp queue */
901 item = ha->copp_waitlist.head;
902 while ((item) && (item->scsi_cmd != SC))
907 ips_removeq_copp(&ha->copp_waitlist, item);
911 /* See if the command is on the wait queue */
912 if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
913 /* command not sent yet */
917 /* An explanation for the casual observer: */
918 /* Part of the function of a RAID controller is automatic error */
919 /* detection and recovery. As such, the only problem that physically */
920 /* resetting an adapter will ever fix is when, for some reason, */
921 /* the driver is not successfully communicating with the adapter. */
922 /* Therefore, we will attempt to flush this adapter. If that succeeds, */
923 /* then there's no real purpose in a physical reset. This will complete */
924 /* much faster and avoids any problems that might be caused by a */
925 /* physical reset ( such as having to fail all the outstanding I/O's ). */
927 if (ha->ioctl_reset == 0) { /* IF Not an IOCTL Requested Reset */
928 scb = &ha->scbs[ha->max_cmds - 1];
930 ips_init_scb(ha, scb);
932 scb->timeout = ips_cmd_timeout;
933 scb->cdb[0] = IPS_CMD_FLUSH;
935 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
936 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
937 scb->cmd.flush_cache.state = IPS_NORM_STATE;
938 scb->cmd.flush_cache.reserved = 0;
939 scb->cmd.flush_cache.reserved2 = 0;
940 scb->cmd.flush_cache.reserved3 = 0;
941 scb->cmd.flush_cache.reserved4 = 0;
943 /* Attempt the flush command */
944 ret = ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_IORL);
945 if (ret == IPS_SUCCESS) {
946 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
947 "Reset Request - Flushed Cache\n");
952 /* Either we can't communicate with the adapter or it's an IOCTL request */
953 /* from a utility. A physical reset is needed at this point. */
955 ha->ioctl_reset = 0; /* Reset the IOCTL Requested Reset Flag */
958 * command must have already been sent
959 * reset the controller
961 IPS_PRINTK(KERN_NOTICE, ha->pcidev, "Resetting controller.\n");
962 ret = (*ha->func.reset) (ha);
965 struct scsi_cmnd *scsi_cmd;
967 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
968 "Controller reset failed - controller now offline.\n");
970 /* Now fail all of the active commands */
971 DEBUG_VAR(1, "(%s%d) Failing active commands",
972 ips_name, ha->host_num);
974 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
975 scb->scsi_cmd->result = DID_ERROR << 16;
976 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
977 ips_freescb(ha, scb);
980 /* Now fail all of the pending commands */
981 DEBUG_VAR(1, "(%s%d) Failing pending commands",
982 ips_name, ha->host_num);
984 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
985 scsi_cmd->result = DID_ERROR;
986 scsi_cmd->scsi_done(scsi_cmd);
993 if (!ips_clear_adapter(ha, IPS_INTR_IORL)) {
994 struct scsi_cmnd *scsi_cmd;
996 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
997 "Controller reset failed - controller now offline.\n");
999 /* Now fail all of the active commands */
1000 DEBUG_VAR(1, "(%s%d) Failing active commands",
1001 ips_name, ha->host_num);
1003 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1004 scb->scsi_cmd->result = DID_ERROR << 16;
1005 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1006 ips_freescb(ha, scb);
1009 /* Now fail all of the pending commands */
1010 DEBUG_VAR(1, "(%s%d) Failing pending commands",
1011 ips_name, ha->host_num);
1013 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
1014 scsi_cmd->result = DID_ERROR << 16;
1015 scsi_cmd->scsi_done(scsi_cmd);
1023 if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
1026 do_gettimeofday(&tv);
1027 ha->last_ffdc = tv.tv_sec;
1029 ips_ffdc_reset(ha, IPS_INTR_IORL);
1032 /* Now fail all of the active commands */
1033 DEBUG_VAR(1, "(%s%d) Failing active commands", ips_name, ha->host_num);
1035 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1036 scb->scsi_cmd->result =
1037 (DID_RESET << 16) | (SUGGEST_RETRY << 24);
1038 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1039 ips_freescb(ha, scb);
1042 /* Reset DCDB active command bits */
1043 for (i = 1; i < ha->nbus; i++)
1044 ha->dcdb_active[i - 1] = 0;
1046 /* Reset the number of active IOCTLs */
1049 ips_next(ha, IPS_INTR_IORL);
1052 #endif /* NO_IPS_RESET */
1056 static int ips_eh_reset(struct scsi_cmnd *SC)
1060 spin_lock_irq(SC->device->host->host_lock);
1061 rc = __ips_eh_reset(SC);
1062 spin_unlock_irq(SC->device->host->host_lock);
1067 /****************************************************************************/
1069 /* Routine Name: ips_queue */
1071 /* Routine Description: */
1073 /* Send a command to the controller */
1076 /* Linux obtains io_request_lock before calling this function */
1078 /****************************************************************************/
1079 static int ips_queue(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *))
1084 METHOD_TRACE("ips_queue", 1);
1086 ha = (ips_ha_t *) SC->device->host->hostdata;
1094 if (ips_is_passthru(SC)) {
1095 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1096 SC->result = DID_BUS_BUSY << 16;
1101 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1102 SC->result = DID_BUS_BUSY << 16;
1108 SC->scsi_done = done;
1110 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1114 SC->device->channel, SC->device->id, SC->device->lun);
1116 /* Check for command to initiator IDs */
1117 if ((scmd_channel(SC) > 0)
1118 && (scmd_id(SC) == ha->ha_id[scmd_channel(SC)])) {
1119 SC->result = DID_NO_CONNECT << 16;
1125 if (ips_is_passthru(SC)) {
1127 ips_copp_wait_item_t *scratch;
1129 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1130 /* There can never be any system activity ( network or disk ), but check */
1131 /* anyway just as a good practice. */
1132 pt = (ips_passthru_t *) SC->request_buffer;
1133 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1134 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1135 if (ha->scb_activelist.count != 0) {
1136 SC->result = DID_BUS_BUSY << 16;
1140 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1142 SC->result = DID_OK << 16;
1147 /* allocate space for the scribble */
1148 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1151 SC->result = DID_ERROR << 16;
1157 scratch->scsi_cmd = SC;
1158 scratch->next = NULL;
1160 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1162 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1165 ips_next(ha, IPS_INTR_IORL);
1170 /****************************************************************************/
1172 /* Routine Name: ips_biosparam */
1174 /* Routine Description: */
1176 /* Set bios geometry for the controller */
1178 /****************************************************************************/
1180 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1181 ips_biosparam(Disk * disk, kdev_t dev, int geom[])
1183 ips_ha_t *ha = (ips_ha_t *) disk->device->host->hostdata;
1184 unsigned long capacity = disk->capacity;
1186 ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1187 sector_t capacity, int geom[])
1189 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1195 METHOD_TRACE("ips_biosparam", 1);
1198 /* ?!?! host adater info invalid */
1204 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1205 /* ?!?! Enquiry command failed */
1208 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1209 heads = IPS_NORM_HEADS;
1210 sectors = IPS_NORM_SECTORS;
1212 heads = IPS_COMP_HEADS;
1213 sectors = IPS_COMP_SECTORS;
1216 cylinders = (unsigned long) capacity / (heads * sectors);
1218 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1219 heads, sectors, cylinders);
1223 geom[2] = cylinders;
1228 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1230 /* ips_proc24_info is a wrapper around ips_proc_info *
1231 * for compatibility with the 2.4 scsi parameters */
1233 ips_proc24_info(char *buffer, char **start, off_t offset, int length,
1234 int hostno, int func)
1238 for (i = 0; i < ips_next_controller; i++) {
1239 if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
1240 return ips_proc_info(ips_sh[i], buffer, start,
1241 offset, length, func);
1247 /****************************************************************************/
1249 /* Routine Name: ips_select_queue_depth */
1251 /* Routine Description: */
1253 /* Select queue depths for the devices on the contoller */
1255 /****************************************************************************/
1257 ips_select_queue_depth(struct Scsi_Host *host, struct scsi_device * scsi_devs)
1259 struct scsi_device *device;
1265 min = ha->max_cmds / 4;
1267 for (device = scsi_devs; device; device = device->next) {
1268 if (device->host == host) {
1269 if ((device->channel == 0) && (device->type == 0))
1274 for (device = scsi_devs; device; device = device->next) {
1275 if (device->host == host) {
1276 if ((device->channel == 0) && (device->type == 0)) {
1277 device->queue_depth =
1278 (ha->max_cmds - 1) / count;
1279 if (device->queue_depth < min)
1280 device->queue_depth = min;
1282 device->queue_depth = 2;
1285 if (device->queue_depth < 2)
1286 device->queue_depth = 2;
1292 /****************************************************************************/
1294 /* Routine Name: ips_slave_configure */
1296 /* Routine Description: */
1298 /* Set queue depths on devices once scan is complete */
1300 /****************************************************************************/
1302 ips_slave_configure(struct scsi_device * SDptr)
1307 ha = IPS_HA(SDptr->host);
1308 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1309 min = ha->max_cmds / 2;
1310 if (ha->enq->ucLogDriveCount <= 2)
1311 min = ha->max_cmds - 1;
1312 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min);
1315 SDptr->skip_ms_page_8 = 1;
1316 SDptr->skip_ms_page_3f = 1;
1321 /****************************************************************************/
1323 /* Routine Name: do_ipsintr */
1325 /* Routine Description: */
1327 /* Wrapper for the interrupt handler */
1329 /****************************************************************************/
1331 do_ipsintr(int irq, void *dev_id)
1334 unsigned long cpu_flags;
1335 struct Scsi_Host *host;
1338 METHOD_TRACE("do_ipsintr", 2);
1340 ha = (ips_ha_t *) dev_id;
1343 host = ips_sh[ha->host_num];
1344 /* interrupt during initialization */
1346 (*ha->func.intr) (ha);
1350 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
1353 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1357 irqstatus = (*ha->func.intr) (ha);
1359 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1361 /* start the next command */
1362 ips_next(ha, IPS_INTR_ON);
1363 return IRQ_RETVAL(irqstatus);
1366 /****************************************************************************/
1368 /* Routine Name: ips_intr_copperhead */
1370 /* Routine Description: */
1372 /* Polling interrupt handler */
1374 /* ASSUMES interrupts are disabled */
1376 /****************************************************************************/
1378 ips_intr_copperhead(ips_ha_t * ha)
1385 METHOD_TRACE("ips_intr", 2);
1393 intrstatus = (*ha->func.isintr) (ha);
1397 * Unexpected/Shared interrupt
1406 intrstatus = (*ha->func.isintr) (ha);
1411 cstatus.value = (*ha->func.statupd) (ha);
1413 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1414 /* Spurious Interupt ? */
1418 ips_chkstatus(ha, &cstatus);
1419 scb = (ips_scb_t *) sp->scb_addr;
1422 * use the callback function to finish things up
1423 * NOTE: interrupts are OFF for this
1425 (*scb->callback) (ha, scb);
1430 /****************************************************************************/
1432 /* Routine Name: ips_intr_morpheus */
1434 /* Routine Description: */
1436 /* Polling interrupt handler */
1438 /* ASSUMES interrupts are disabled */
1440 /****************************************************************************/
1442 ips_intr_morpheus(ips_ha_t * ha)
1449 METHOD_TRACE("ips_intr_morpheus", 2);
1457 intrstatus = (*ha->func.isintr) (ha);
1461 * Unexpected/Shared interrupt
1470 intrstatus = (*ha->func.isintr) (ha);
1475 cstatus.value = (*ha->func.statupd) (ha);
1477 if (cstatus.value == 0xffffffff)
1478 /* No more to process */
1481 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1482 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1483 "Spurious interrupt; no ccb.\n");
1488 ips_chkstatus(ha, &cstatus);
1489 scb = (ips_scb_t *) sp->scb_addr;
1492 * use the callback function to finish things up
1493 * NOTE: interrupts are OFF for this
1495 (*scb->callback) (ha, scb);
1500 /****************************************************************************/
1502 /* Routine Name: ips_info */
1504 /* Routine Description: */
1506 /* Return info about the driver */
1508 /****************************************************************************/
1510 ips_info(struct Scsi_Host *SH)
1512 static char buffer[256];
1516 METHOD_TRACE("ips_info", 1);
1524 memset(bp, 0, sizeof (buffer));
1526 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1527 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1529 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1531 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1538 /****************************************************************************/
1540 /* Routine Name: ips_proc_info */
1542 /* Routine Description: */
1544 /* The passthru interface for the driver */
1546 /****************************************************************************/
1548 ips_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1549 int length, int func)
1553 ips_ha_t *ha = NULL;
1555 METHOD_TRACE("ips_proc_info", 1);
1557 /* Find our host structure */
1558 for (i = 0; i < ips_next_controller; i++) {
1560 if (ips_sh[i] == host) {
1561 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1578 ret = ips_host_info(ha, buffer, offset, length);
1584 /*--------------------------------------------------------------------------*/
1585 /* Helper Functions */
1586 /*--------------------------------------------------------------------------*/
1588 /****************************************************************************/
1590 /* Routine Name: ips_is_passthru */
1592 /* Routine Description: */
1594 /* Determine if the specified SCSI command is really a passthru command */
1596 /****************************************************************************/
1597 static int ips_is_passthru(struct scsi_cmnd *SC)
1599 unsigned long flags;
1601 METHOD_TRACE("ips_is_passthru", 1);
1606 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1607 (SC->device->channel == 0) &&
1608 (SC->device->id == IPS_ADAPTER_ID) &&
1609 (SC->device->lun == 0) && SC->request_buffer) {
1610 if ((!SC->use_sg) && SC->request_bufflen &&
1611 (((char *) SC->request_buffer)[0] == 'C') &&
1612 (((char *) SC->request_buffer)[1] == 'O') &&
1613 (((char *) SC->request_buffer)[2] == 'P') &&
1614 (((char *) SC->request_buffer)[3] == 'P'))
1616 else if (SC->use_sg) {
1617 struct scatterlist *sg = SC->request_buffer;
1620 /* kmap_atomic() ensures addressability of the user buffer.*/
1621 /* local_irq_save() protects the KM_IRQ0 address slot. */
1622 local_irq_save(flags);
1623 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1624 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1625 buffer[2] == 'P' && buffer[3] == 'P') {
1626 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
1627 local_irq_restore(flags);
1630 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
1631 local_irq_restore(flags);
1637 /****************************************************************************/
1639 /* Routine Name: ips_alloc_passthru_buffer */
1641 /* Routine Description: */
1642 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1643 /* is too small or doesn't exist */
1644 /****************************************************************************/
1646 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1649 dma_addr_t dma_busaddr;
1651 if (ha->ioctl_data && length <= ha->ioctl_len)
1653 /* there is no buffer or it's not big enough, allocate a new one */
1654 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1656 /* free the old memory */
1657 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1659 /* use the new memory */
1660 ha->ioctl_data = (char *) bigger_buf;
1661 ha->ioctl_len = length;
1662 ha->ioctl_busaddr = dma_busaddr;
1669 /****************************************************************************/
1671 /* Routine Name: ips_make_passthru */
1673 /* Routine Description: */
1675 /* Make a passthru command out of the info in the Scsi block */
1677 /****************************************************************************/
1679 ips_make_passthru(ips_ha_t *ha, struct scsi_cmnd *SC, ips_scb_t *scb, int intr)
1685 METHOD_TRACE("ips_make_passthru", 1);
1688 length = SC->request_bufflen;
1690 struct scatterlist *sg = SC->request_buffer;
1692 for (i = 0; i < SC->use_sg; i++)
1693 length += sg[i].length;
1695 if (length < sizeof (ips_passthru_t)) {
1697 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1698 ips_name, ha->host_num);
1699 return (IPS_FAILURE);
1701 if (ips_alloc_passthru_buffer(ha, length)) {
1702 /* allocation failure! If ha->ioctl_data exists, use it to return
1703 some error codes. Return a failed command to the scsi layer. */
1704 if (ha->ioctl_data) {
1705 pt = (ips_passthru_t *) ha->ioctl_data;
1706 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1707 pt->BasicStatus = 0x0B;
1708 pt->ExtendedStatus = 0x00;
1709 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1713 ha->ioctl_datasize = length;
1715 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1716 pt = (ips_passthru_t *) ha->ioctl_data;
1719 * Some notes about the passthru interface used
1721 * IF the scsi op_code == 0x0d then we assume
1722 * that the data came along with/goes with the
1723 * packet we received from the sg driver. In this
1724 * case the CmdBSize field of the pt structure is
1725 * used for the size of the buffer.
1728 switch (pt->CoppCmd) {
1730 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1731 &ips_num_controllers, sizeof (int));
1732 ips_scmd_buf_write(SC, ha->ioctl_data,
1733 sizeof (ips_passthru_t) + sizeof (int));
1734 SC->result = DID_OK << 16;
1736 return (IPS_SUCCESS_IMM);
1738 case IPS_COPPUSRCMD:
1739 case IPS_COPPIOCCMD:
1740 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1741 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1744 "(%s%d) Passthru structure wrong size",
1745 ips_name, ha->host_num);
1747 return (IPS_FAILURE);
1750 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
1751 pt->CoppCP.cmd.flashfw.op_code ==
1752 IPS_CMD_RW_BIOSFW) {
1753 ret = ips_flash_copperhead(ha, pt, scb);
1754 ips_scmd_buf_write(SC, ha->ioctl_data,
1755 sizeof (ips_passthru_t));
1758 if (ips_usrcmd(ha, pt, scb))
1759 return (IPS_SUCCESS);
1761 return (IPS_FAILURE);
1768 return (IPS_FAILURE);
1771 /****************************************************************************/
1772 /* Routine Name: ips_flash_copperhead */
1773 /* Routine Description: */
1774 /* Flash the BIOS/FW on a Copperhead style controller */
1775 /****************************************************************************/
1777 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1781 /* Trombone is the only copperhead that can do packet flash, but only
1782 * for firmware. No one said it had to make sence. */
1783 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1784 if (ips_usrcmd(ha, pt, scb))
1789 pt->BasicStatus = 0x0B;
1790 pt->ExtendedStatus = 0;
1791 scb->scsi_cmd->result = DID_OK << 16;
1792 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1793 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1794 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1795 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1796 pt->BasicStatus = 0;
1797 return ips_flash_bios(ha, pt, scb);
1798 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1799 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1800 ha->flash_data = ips_FlashData;
1801 ha->flash_busaddr = ips_flashbusaddr;
1802 ha->flash_len = PAGE_SIZE << 7;
1803 ha->flash_datasize = 0;
1804 } else if (!ha->flash_data) {
1805 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1806 pt->CoppCP.cmd.flashfw.count;
1807 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1809 &ha->flash_busaddr);
1810 if (!ha->flash_data){
1811 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1814 ha->flash_datasize = 0;
1815 ha->flash_len = datasize;
1819 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1821 ips_free_flash_copperhead(ha);
1822 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1823 "failed size sanity check\n");
1827 if (!ha->flash_data)
1829 pt->BasicStatus = 0;
1830 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1831 pt->CoppCP.cmd.flashfw.count);
1832 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1833 if (pt->CoppCP.cmd.flashfw.packet_num ==
1834 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1835 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1836 return ips_flash_bios(ha, pt, scb);
1837 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1838 return ips_flash_firmware(ha, pt, scb);
1840 return IPS_SUCCESS_IMM;
1843 /****************************************************************************/
1844 /* Routine Name: ips_flash_bios */
1845 /* Routine Description: */
1846 /* flashes the bios of a copperhead adapter */
1847 /****************************************************************************/
1849 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1852 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1853 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1854 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1855 (!ha->func.verifybios))
1857 if ((*ha->func.erasebios) (ha)) {
1859 "(%s%d) flash bios failed - unable to erase flash",
1860 ips_name, ha->host_num);
1863 if ((*ha->func.programbios) (ha,
1866 ha->flash_datasize -
1867 IPS_BIOS_HEADER, 0)) {
1869 "(%s%d) flash bios failed - unable to flash",
1870 ips_name, ha->host_num);
1873 if ((*ha->func.verifybios) (ha,
1876 ha->flash_datasize -
1877 IPS_BIOS_HEADER, 0)) {
1879 "(%s%d) flash bios failed - unable to verify flash",
1880 ips_name, ha->host_num);
1883 ips_free_flash_copperhead(ha);
1884 return IPS_SUCCESS_IMM;
1885 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1886 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1887 if (!ha->func.erasebios)
1889 if ((*ha->func.erasebios) (ha)) {
1891 "(%s%d) flash bios failed - unable to erase flash",
1892 ips_name, ha->host_num);
1895 return IPS_SUCCESS_IMM;
1898 pt->BasicStatus = 0x0B;
1899 pt->ExtendedStatus = 0x00;
1900 ips_free_flash_copperhead(ha);
1904 /****************************************************************************/
1906 /* Routine Name: ips_fill_scb_sg_single */
1908 /* Routine Description: */
1909 /* Fill in a single scb sg_list element from an address */
1910 /* return a -1 if a breakup occurred */
1911 /****************************************************************************/
1913 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1914 ips_scb_t * scb, int indx, unsigned int e_len)
1919 if ((scb->data_len + e_len) > ha->max_xfer) {
1920 e_len = ha->max_xfer - scb->data_len;
1921 scb->breakup = indx;
1928 if (IPS_USE_ENH_SGLIST(ha)) {
1929 scb->sg_list.enh_list[indx].address_lo =
1930 cpu_to_le32(pci_dma_lo32(busaddr));
1931 scb->sg_list.enh_list[indx].address_hi =
1932 cpu_to_le32(pci_dma_hi32(busaddr));
1933 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1935 scb->sg_list.std_list[indx].address =
1936 cpu_to_le32(pci_dma_lo32(busaddr));
1937 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1941 scb->data_len += e_len;
1945 /****************************************************************************/
1946 /* Routine Name: ips_flash_firmware */
1947 /* Routine Description: */
1948 /* flashes the firmware of a copperhead adapter */
1949 /****************************************************************************/
1951 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1953 IPS_SG_LIST sg_list;
1954 uint32_t cmd_busaddr;
1956 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1957 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1958 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1959 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1960 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1962 pt->BasicStatus = 0x0B;
1963 pt->ExtendedStatus = 0x00;
1964 ips_free_flash_copperhead(ha);
1967 /* Save the S/G list pointer so it doesn't get clobbered */
1968 sg_list.list = scb->sg_list.list;
1969 cmd_busaddr = scb->scb_busaddr;
1970 /* copy in the CP */
1971 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1972 /* FIX stuff that might be wrong */
1973 scb->sg_list.list = sg_list.list;
1974 scb->scb_busaddr = cmd_busaddr;
1975 scb->bus = scb->scsi_cmd->device->channel;
1976 scb->target_id = scb->scsi_cmd->device->id;
1977 scb->lun = scb->scsi_cmd->device->lun;
1982 scb->callback = ipsintr_done;
1983 scb->timeout = ips_cmd_timeout;
1985 scb->data_len = ha->flash_datasize;
1987 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1989 scb->flags |= IPS_SCB_MAP_SINGLE;
1990 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1991 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1993 scb->timeout = pt->TimeOut;
1994 scb->scsi_cmd->result = DID_OK << 16;
1998 /****************************************************************************/
1999 /* Routine Name: ips_free_flash_copperhead */
2000 /* Routine Description: */
2001 /* release the memory resources used to hold the flash image */
2002 /****************************************************************************/
2004 ips_free_flash_copperhead(ips_ha_t * ha)
2006 if (ha->flash_data == ips_FlashData)
2007 test_and_clear_bit(0, &ips_FlashDataInUse);
2008 else if (ha->flash_data)
2009 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
2011 ha->flash_data = NULL;
2014 /****************************************************************************/
2016 /* Routine Name: ips_usrcmd */
2018 /* Routine Description: */
2020 /* Process a user command and make it ready to send */
2022 /****************************************************************************/
2024 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
2026 IPS_SG_LIST sg_list;
2027 uint32_t cmd_busaddr;
2029 METHOD_TRACE("ips_usrcmd", 1);
2031 if ((!scb) || (!pt) || (!ha))
2034 /* Save the S/G list pointer so it doesn't get clobbered */
2035 sg_list.list = scb->sg_list.list;
2036 cmd_busaddr = scb->scb_busaddr;
2037 /* copy in the CP */
2038 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
2039 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
2041 /* FIX stuff that might be wrong */
2042 scb->sg_list.list = sg_list.list;
2043 scb->scb_busaddr = cmd_busaddr;
2044 scb->bus = scb->scsi_cmd->device->channel;
2045 scb->target_id = scb->scsi_cmd->device->id;
2046 scb->lun = scb->scsi_cmd->device->lun;
2051 scb->callback = ipsintr_done;
2052 scb->timeout = ips_cmd_timeout;
2053 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
2055 /* we don't support DCDB/READ/WRITE Scatter Gather */
2056 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
2057 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
2058 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
2062 scb->data_len = pt->CmdBSize;
2063 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
2065 scb->data_busaddr = 0L;
2068 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2069 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
2070 (unsigned long) &scb->
2072 (unsigned long) scb);
2075 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2076 scb->dcdb.buffer_pointer =
2077 cpu_to_le32(scb->data_busaddr);
2079 scb->cmd.basic_io.sg_addr =
2080 cpu_to_le32(scb->data_busaddr);
2085 scb->timeout = pt->TimeOut;
2087 if (pt->TimeOut <= 10)
2088 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
2089 else if (pt->TimeOut <= 60)
2090 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
2092 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
2095 /* assume success */
2096 scb->scsi_cmd->result = DID_OK << 16;
2102 /****************************************************************************/
2104 /* Routine Name: ips_cleanup_passthru */
2106 /* Routine Description: */
2108 /* Cleanup after a passthru command */
2110 /****************************************************************************/
2112 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
2116 METHOD_TRACE("ips_cleanup_passthru", 1);
2118 if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
2119 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2120 ips_name, ha->host_num);
2124 pt = (ips_passthru_t *) ha->ioctl_data;
2126 /* Copy data back to the user */
2127 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2128 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2130 pt->BasicStatus = scb->basic_status;
2131 pt->ExtendedStatus = scb->extended_status;
2132 pt->AdapterType = ha->ad_type;
2134 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
2135 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2136 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2137 ips_free_flash_copperhead(ha);
2139 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2142 /****************************************************************************/
2144 /* Routine Name: ips_host_info */
2146 /* Routine Description: */
2148 /* The passthru interface for the driver */
2150 /****************************************************************************/
2152 ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
2156 METHOD_TRACE("ips_host_info", 1);
2160 info.offset = offset;
2164 copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
2166 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2167 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2168 copy_info(&info, "\tController Type : %s\n",
2169 ips_adapter_name[ha->ad_type - 1]);
2172 "\tController Type : Unknown\n");
2176 "\tIO region : 0x%lx (%d bytes)\n",
2177 ha->io_addr, ha->io_len);
2181 "\tMemory region : 0x%lx (%d bytes)\n",
2182 ha->mem_addr, ha->mem_len);
2184 "\tShared memory address : 0x%lx\n",
2188 copy_info(&info, "\tIRQ number : %d\n", ha->irq);
2190 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2191 /* That keeps everything happy for "text" operations on the proc file. */
2193 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2194 if (ha->nvram->bios_low[3] == 0) {
2196 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2197 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2198 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2199 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2200 ha->nvram->bios_low[2]);
2204 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2205 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2206 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2207 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2208 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2213 if (ha->enq->CodeBlkVersion[7] == 0) {
2215 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2216 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2217 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2218 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2219 ha->enq->CodeBlkVersion[6]);
2222 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2223 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2224 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2225 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2226 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2229 if (ha->enq->BootBlkVersion[7] == 0) {
2231 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2232 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2233 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2234 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2235 ha->enq->BootBlkVersion[6]);
2238 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2239 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2240 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2241 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2242 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2245 copy_info(&info, "\tDriver Version : %s%s\n",
2246 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2248 copy_info(&info, "\tDriver Build : %d\n",
2251 copy_info(&info, "\tMax Physical Devices : %d\n",
2252 ha->enq->ucMaxPhysicalDevices);
2253 copy_info(&info, "\tMax Active Commands : %d\n",
2255 copy_info(&info, "\tCurrent Queued Commands : %d\n",
2256 ha->scb_waitlist.count);
2257 copy_info(&info, "\tCurrent Active Commands : %d\n",
2258 ha->scb_activelist.count - ha->num_ioctl);
2259 copy_info(&info, "\tCurrent Queued PT Commands : %d\n",
2260 ha->copp_waitlist.count);
2261 copy_info(&info, "\tCurrent Active PT Commands : %d\n",
2264 copy_info(&info, "\n");
2266 return (info.localpos);
2269 /****************************************************************************/
2271 /* Routine Name: copy_mem_info */
2273 /* Routine Description: */
2275 /* Copy data into an IPS_INFOSTR structure */
2277 /****************************************************************************/
2279 copy_mem_info(IPS_INFOSTR * info, char *data, int len)
2281 METHOD_TRACE("copy_mem_info", 1);
2283 if (info->pos + len < info->offset) {
2288 if (info->pos < info->offset) {
2289 data += (info->offset - info->pos);
2290 len -= (info->offset - info->pos);
2291 info->pos += (info->offset - info->pos);
2294 if (info->localpos + len > info->length)
2295 len = info->length - info->localpos;
2298 memcpy(info->buffer + info->localpos, data, len);
2300 info->localpos += len;
2304 /****************************************************************************/
2306 /* Routine Name: copy_info */
2308 /* Routine Description: */
2310 /* printf style wrapper for an info structure */
2312 /****************************************************************************/
2314 copy_info(IPS_INFOSTR * info, char *fmt, ...)
2320 METHOD_TRACE("copy_info", 1);
2322 va_start(args, fmt);
2323 len = vsprintf(buf, fmt, args);
2326 copy_mem_info(info, buf, len);
2331 /****************************************************************************/
2333 /* Routine Name: ips_identify_controller */
2335 /* Routine Description: */
2337 /* Identify this controller */
2339 /****************************************************************************/
2341 ips_identify_controller(ips_ha_t * ha)
2343 METHOD_TRACE("ips_identify_controller", 1);
2345 switch (ha->device_id) {
2346 case IPS_DEVICEID_COPPERHEAD:
2347 if (ha->revision_id <= IPS_REVID_SERVERAID) {
2348 ha->ad_type = IPS_ADTYPE_SERVERAID;
2349 } else if (ha->revision_id == IPS_REVID_SERVERAID2) {
2350 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2351 } else if (ha->revision_id == IPS_REVID_NAVAJO) {
2352 ha->ad_type = IPS_ADTYPE_NAVAJO;
2353 } else if ((ha->revision_id == IPS_REVID_SERVERAID2)
2354 && (ha->slot_num == 0)) {
2355 ha->ad_type = IPS_ADTYPE_KIOWA;
2356 } else if ((ha->revision_id >= IPS_REVID_CLARINETP1) &&
2357 (ha->revision_id <= IPS_REVID_CLARINETP3)) {
2358 if (ha->enq->ucMaxPhysicalDevices == 15)
2359 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2361 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2362 } else if ((ha->revision_id >= IPS_REVID_TROMBONE32) &&
2363 (ha->revision_id <= IPS_REVID_TROMBONE64)) {
2364 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2368 case IPS_DEVICEID_MORPHEUS:
2369 switch (ha->subdevice_id) {
2370 case IPS_SUBDEVICEID_4L:
2371 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2374 case IPS_SUBDEVICEID_4M:
2375 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2378 case IPS_SUBDEVICEID_4MX:
2379 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2382 case IPS_SUBDEVICEID_4LX:
2383 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2386 case IPS_SUBDEVICEID_5I2:
2387 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2390 case IPS_SUBDEVICEID_5I1:
2391 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2397 case IPS_DEVICEID_MARCO:
2398 switch (ha->subdevice_id) {
2399 case IPS_SUBDEVICEID_6M:
2400 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2402 case IPS_SUBDEVICEID_6I:
2403 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2405 case IPS_SUBDEVICEID_7k:
2406 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2408 case IPS_SUBDEVICEID_7M:
2409 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2416 /****************************************************************************/
2418 /* Routine Name: ips_get_bios_version */
2420 /* Routine Description: */
2422 /* Get the BIOS revision number */
2424 /****************************************************************************/
2426 ips_get_bios_version(ips_ha_t * ha, int intr)
2435 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2438 METHOD_TRACE("ips_get_bios_version", 1);
2443 strncpy(ha->bios_version, " ?", 8);
2445 if (ha->device_id == IPS_DEVICEID_COPPERHEAD) {
2446 if (IPS_USE_MEMIO(ha)) {
2447 /* Memory Mapped I/O */
2450 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2451 if (ha->revision_id == IPS_REVID_TROMBONE64)
2452 udelay(25); /* 25 us */
2454 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2457 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2458 if (ha->revision_id == IPS_REVID_TROMBONE64)
2459 udelay(25); /* 25 us */
2461 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2464 /* Get Major version */
2465 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2466 if (ha->revision_id == IPS_REVID_TROMBONE64)
2467 udelay(25); /* 25 us */
2469 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2471 /* Get Minor version */
2472 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2473 if (ha->revision_id == IPS_REVID_TROMBONE64)
2474 udelay(25); /* 25 us */
2475 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2477 /* Get SubMinor version */
2478 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2479 if (ha->revision_id == IPS_REVID_TROMBONE64)
2480 udelay(25); /* 25 us */
2481 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2484 /* Programmed I/O */
2487 outl(0, ha->io_addr + IPS_REG_FLAP);
2488 if (ha->revision_id == IPS_REVID_TROMBONE64)
2489 udelay(25); /* 25 us */
2491 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2494 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
2495 if (ha->revision_id == IPS_REVID_TROMBONE64)
2496 udelay(25); /* 25 us */
2498 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2501 /* Get Major version */
2502 outl(cpu_to_le32(0x1FF), ha->io_addr + IPS_REG_FLAP);
2503 if (ha->revision_id == IPS_REVID_TROMBONE64)
2504 udelay(25); /* 25 us */
2506 major = inb(ha->io_addr + IPS_REG_FLDP);
2508 /* Get Minor version */
2509 outl(cpu_to_le32(0x1FE), ha->io_addr + IPS_REG_FLAP);
2510 if (ha->revision_id == IPS_REVID_TROMBONE64)
2511 udelay(25); /* 25 us */
2513 minor = inb(ha->io_addr + IPS_REG_FLDP);
2515 /* Get SubMinor version */
2516 outl(cpu_to_le32(0x1FD), ha->io_addr + IPS_REG_FLAP);
2517 if (ha->revision_id == IPS_REVID_TROMBONE64)
2518 udelay(25); /* 25 us */
2520 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2524 /* Morpheus Family - Send Command to the card */
2526 buffer = ha->ioctl_data;
2528 memset(buffer, 0, 0x1000);
2530 scb = &ha->scbs[ha->max_cmds - 1];
2532 ips_init_scb(ha, scb);
2534 scb->timeout = ips_cmd_timeout;
2535 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2537 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2538 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2539 scb->cmd.flashfw.type = 1;
2540 scb->cmd.flashfw.direction = 0;
2541 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2542 scb->cmd.flashfw.total_packets = 1;
2543 scb->cmd.flashfw.packet_num = 0;
2544 scb->data_len = 0x1000;
2545 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2547 /* issue the command */
2549 ips_send_wait(ha, scb, ips_cmd_timeout,
2550 intr)) == IPS_FAILURE)
2551 || (ret == IPS_SUCCESS_IMM)
2552 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2553 /* Error occurred */
2558 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2559 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2560 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2561 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2567 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2568 ha->bios_version[1] = '.';
2569 ha->bios_version[2] = hexDigits[major & 0x0F];
2570 ha->bios_version[3] = hexDigits[subminor];
2571 ha->bios_version[4] = '.';
2572 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2573 ha->bios_version[6] = hexDigits[minor & 0x0F];
2574 ha->bios_version[7] = 0;
2577 /****************************************************************************/
2579 /* Routine Name: ips_hainit */
2581 /* Routine Description: */
2583 /* Initialize the controller */
2585 /* NOTE: Assumes to be called from with a lock */
2587 /****************************************************************************/
2589 ips_hainit(ips_ha_t * ha)
2594 METHOD_TRACE("ips_hainit", 1);
2599 if (ha->func.statinit)
2600 (*ha->func.statinit) (ha);
2602 if (ha->func.enableint)
2603 (*ha->func.enableint) (ha);
2606 ha->reset_count = 1;
2607 do_gettimeofday(&tv);
2608 ha->last_ffdc = tv.tv_sec;
2609 ips_ffdc_reset(ha, IPS_INTR_IORL);
2611 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2612 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2613 "unable to read config from controller.\n");
2618 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2619 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2620 "unable to read controller status.\n");
2625 /* Identify this controller */
2626 ips_identify_controller(ha);
2628 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2629 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2630 "unable to read subsystem parameters.\n");
2635 /* write nvram user page 5 */
2636 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2637 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2638 "unable to write driver info to controller.\n");
2643 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2644 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2645 ips_clear_adapter(ha, IPS_INTR_IORL);
2647 /* set limits on SID, LUN, BUS */
2648 ha->ntargets = IPS_MAX_TARGETS + 1;
2650 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2652 switch (ha->conf->logical_drive[0].ucStripeSize) {
2654 ha->max_xfer = 0x10000;
2658 ha->max_xfer = 0x20000;
2662 ha->max_xfer = 0x40000;
2667 ha->max_xfer = 0x80000;
2671 /* setup max concurrent commands */
2672 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2673 /* Use the new method */
2674 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2676 /* use the old method */
2677 switch (ha->conf->logical_drive[0].ucStripeSize) {
2697 /* Limit the Active Commands on a Lite Adapter */
2698 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2699 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2700 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2701 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2702 ha->max_cmds = MaxLiteCmds;
2705 /* set controller IDs */
2706 ha->ha_id[0] = IPS_ADAPTER_ID;
2707 for (i = 1; i < ha->nbus; i++) {
2708 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2709 ha->dcdb_active[i - 1] = 0;
2715 /****************************************************************************/
2717 /* Routine Name: ips_next */
2719 /* Routine Description: */
2721 /* Take the next command off the queue and send it to the controller */
2723 /****************************************************************************/
2725 ips_next(ips_ha_t * ha, int intr)
2728 struct scsi_cmnd *SC;
2729 struct scsi_cmnd *p;
2730 struct scsi_cmnd *q;
2731 ips_copp_wait_item_t *item;
2733 unsigned long cpu_flags = 0;
2734 struct Scsi_Host *host;
2735 METHOD_TRACE("ips_next", 1);
2739 host = ips_sh[ha->host_num];
2741 * Block access to the queue function so
2742 * this command won't time out
2744 if (intr == IPS_INTR_ON)
2745 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2747 if ((ha->subsys->param[3] & 0x300000)
2748 && (ha->scb_activelist.count == 0)) {
2751 do_gettimeofday(&tv);
2753 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2754 ha->last_ffdc = tv.tv_sec;
2760 * Send passthru commands
2761 * These have priority over normal I/O
2762 * but shouldn't affect performance too much
2763 * since we limit the number that can be active
2764 * on the card at any one time
2766 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2767 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2769 item = ips_removeq_copp_head(&ha->copp_waitlist);
2771 if (intr == IPS_INTR_ON)
2772 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2773 scb->scsi_cmd = item->scsi_cmd;
2776 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2778 if (intr == IPS_INTR_ON)
2779 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2782 if (scb->scsi_cmd) {
2783 scb->scsi_cmd->result = DID_ERROR << 16;
2784 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2787 ips_freescb(ha, scb);
2789 case IPS_SUCCESS_IMM:
2790 if (scb->scsi_cmd) {
2791 scb->scsi_cmd->result = DID_OK << 16;
2792 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2795 ips_freescb(ha, scb);
2801 if (ret != IPS_SUCCESS) {
2806 ret = ips_send_cmd(ha, scb);
2808 if (ret == IPS_SUCCESS)
2809 ips_putq_scb_head(&ha->scb_activelist, scb);
2815 if (scb->scsi_cmd) {
2816 scb->scsi_cmd->result = DID_ERROR << 16;
2819 ips_freescb(ha, scb);
2821 case IPS_SUCCESS_IMM:
2822 ips_freescb(ha, scb);
2831 * Send "Normal" I/O commands
2834 p = ha->scb_waitlist.head;
2835 while ((p) && (scb = ips_getscb(ha))) {
2836 if ((scmd_channel(p) > 0)
2838 dcdb_active[scmd_channel(p) -
2839 1] & (1 << scmd_id(p)))) {
2840 ips_freescb(ha, scb);
2841 p = (struct scsi_cmnd *) p->host_scribble;
2846 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2848 if (intr == IPS_INTR_ON)
2849 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags); /* Unlock HA after command is taken off queue */
2851 SC->result = DID_OK;
2852 SC->host_scribble = NULL;
2854 memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
2856 scb->target_id = SC->device->id;
2857 scb->lun = SC->device->lun;
2858 scb->bus = SC->device->channel;
2862 scb->callback = ipsintr_done;
2863 scb->timeout = ips_cmd_timeout;
2864 memset(&scb->cmd, 0, 16);
2866 /* copy in the CDB */
2867 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2869 /* Now handle the data buffer */
2871 struct scatterlist *sg;
2874 sg = SC->request_buffer;
2875 scb->sg_count = pci_map_sg(ha->pcidev, sg, SC->use_sg,
2876 SC->sc_data_direction);
2877 scb->flags |= IPS_SCB_MAP_SG;
2878 for (i = 0; i < scb->sg_count; i++) {
2879 if (ips_fill_scb_sg_single
2880 (ha, sg_dma_address(&sg[i]), scb, i,
2881 sg_dma_len(&sg[i])) < 0)
2884 scb->dcdb.transfer_length = scb->data_len;
2886 if (SC->request_bufflen) {
2888 pci_map_single(ha->pcidev,
2890 SC->request_bufflen,
2891 SC->sc_data_direction);
2892 scb->flags |= IPS_SCB_MAP_SINGLE;
2893 ips_fill_scb_sg_single(ha, scb->data_busaddr,
2895 SC->request_bufflen);
2896 scb->dcdb.transfer_length = scb->data_len;
2898 scb->data_busaddr = 0L;
2901 scb->dcdb.transfer_length = 0;
2906 scb->dcdb.cmd_attribute =
2907 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2909 /* Allow a WRITE BUFFER Command to Have no Data */
2910 /* This is Used by Tape Flash Utilites */
2911 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0))
2912 scb->dcdb.cmd_attribute = 0;
2914 if (!(scb->dcdb.cmd_attribute & 0x3))
2915 scb->dcdb.transfer_length = 0;
2917 if (scb->data_len >= IPS_MAX_XFER) {
2918 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2919 scb->dcdb.transfer_length = 0;
2921 if (intr == IPS_INTR_ON)
2922 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2924 ret = ips_send_cmd(ha, scb);
2928 ips_putq_scb_head(&ha->scb_activelist, scb);
2931 if (scb->scsi_cmd) {
2932 scb->scsi_cmd->result = DID_ERROR << 16;
2933 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2937 ha->dcdb_active[scb->bus - 1] &=
2938 ~(1 << scb->target_id);
2940 ips_freescb(ha, scb);
2942 case IPS_SUCCESS_IMM:
2944 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2947 ha->dcdb_active[scb->bus - 1] &=
2948 ~(1 << scb->target_id);
2950 ips_freescb(ha, scb);
2956 p = (struct scsi_cmnd *) p->host_scribble;
2960 if (intr == IPS_INTR_ON)
2961 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2964 /****************************************************************************/
2966 /* Routine Name: ips_putq_scb_head */
2968 /* Routine Description: */
2970 /* Add an item to the head of the queue */
2972 /* ASSUMED to be called from within the HA lock */
2974 /****************************************************************************/
2976 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2978 METHOD_TRACE("ips_putq_scb_head", 1);
2983 item->q_next = queue->head;
2992 /****************************************************************************/
2994 /* Routine Name: ips_removeq_scb_head */
2996 /* Routine Description: */
2998 /* Remove the head of the queue */
3000 /* ASSUMED to be called from within the HA lock */
3002 /****************************************************************************/
3004 ips_removeq_scb_head(ips_scb_queue_t * queue)
3008 METHOD_TRACE("ips_removeq_scb_head", 1);
3016 queue->head = item->q_next;
3017 item->q_next = NULL;
3019 if (queue->tail == item)
3027 /****************************************************************************/
3029 /* Routine Name: ips_removeq_scb */
3031 /* Routine Description: */
3033 /* Remove an item from a queue */
3035 /* ASSUMED to be called from within the HA lock */
3037 /****************************************************************************/
3039 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
3043 METHOD_TRACE("ips_removeq_scb", 1);
3048 if (item == queue->head) {
3049 return (ips_removeq_scb_head(queue));
3054 while ((p) && (item != p->q_next))
3059 p->q_next = item->q_next;
3064 item->q_next = NULL;
3073 /****************************************************************************/
3075 /* Routine Name: ips_putq_wait_tail */
3077 /* Routine Description: */
3079 /* Add an item to the tail of the queue */
3081 /* ASSUMED to be called from within the HA lock */
3083 /****************************************************************************/
3084 static void ips_putq_wait_tail(ips_wait_queue_t *queue, struct scsi_cmnd *item)
3086 METHOD_TRACE("ips_putq_wait_tail", 1);
3091 item->host_scribble = NULL;
3094 queue->tail->host_scribble = (char *) item;
3104 /****************************************************************************/
3106 /* Routine Name: ips_removeq_wait_head */
3108 /* Routine Description: */
3110 /* Remove the head of the queue */
3112 /* ASSUMED to be called from within the HA lock */
3114 /****************************************************************************/
3115 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *queue)
3117 struct scsi_cmnd *item;
3119 METHOD_TRACE("ips_removeq_wait_head", 1);
3127 queue->head = (struct scsi_cmnd *) item->host_scribble;
3128 item->host_scribble = NULL;
3130 if (queue->tail == item)
3138 /****************************************************************************/
3140 /* Routine Name: ips_removeq_wait */
3142 /* Routine Description: */
3144 /* Remove an item from a queue */
3146 /* ASSUMED to be called from within the HA lock */
3148 /****************************************************************************/
3149 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *queue,
3150 struct scsi_cmnd *item)
3152 struct scsi_cmnd *p;
3154 METHOD_TRACE("ips_removeq_wait", 1);
3159 if (item == queue->head) {
3160 return (ips_removeq_wait_head(queue));
3165 while ((p) && (item != (struct scsi_cmnd *) p->host_scribble))
3166 p = (struct scsi_cmnd *) p->host_scribble;
3170 p->host_scribble = item->host_scribble;
3172 if (!item->host_scribble)
3175 item->host_scribble = NULL;
3184 /****************************************************************************/
3186 /* Routine Name: ips_putq_copp_tail */
3188 /* Routine Description: */
3190 /* Add an item to the tail of the queue */
3192 /* ASSUMED to be called from within the HA lock */
3194 /****************************************************************************/
3196 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3198 METHOD_TRACE("ips_putq_copp_tail", 1);
3206 queue->tail->next = item;
3216 /****************************************************************************/
3218 /* Routine Name: ips_removeq_copp_head */
3220 /* Routine Description: */
3222 /* Remove the head of the queue */
3224 /* ASSUMED to be called from within the HA lock */
3226 /****************************************************************************/
3227 static ips_copp_wait_item_t *
3228 ips_removeq_copp_head(ips_copp_queue_t * queue)
3230 ips_copp_wait_item_t *item;
3232 METHOD_TRACE("ips_removeq_copp_head", 1);
3240 queue->head = item->next;
3243 if (queue->tail == item)
3251 /****************************************************************************/
3253 /* Routine Name: ips_removeq_copp */
3255 /* Routine Description: */
3257 /* Remove an item from a queue */
3259 /* ASSUMED to be called from within the HA lock */
3261 /****************************************************************************/
3262 static ips_copp_wait_item_t *
3263 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3265 ips_copp_wait_item_t *p;
3267 METHOD_TRACE("ips_removeq_copp", 1);
3272 if (item == queue->head) {
3273 return (ips_removeq_copp_head(queue));
3278 while ((p) && (item != p->next))
3283 p->next = item->next;
3297 /****************************************************************************/
3299 /* Routine Name: ipsintr_blocking */
3301 /* Routine Description: */
3303 /* Finalize an interrupt for internal commands */
3305 /****************************************************************************/
3307 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3309 METHOD_TRACE("ipsintr_blocking", 2);
3311 ips_freescb(ha, scb);
3312 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3313 ha->waitflag = FALSE;
3319 /****************************************************************************/
3321 /* Routine Name: ipsintr_done */
3323 /* Routine Description: */
3325 /* Finalize an interrupt for non-internal commands */
3327 /****************************************************************************/
3329 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3331 METHOD_TRACE("ipsintr_done", 2);
3334 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3335 "Spurious interrupt; scb NULL.\n");
3340 if (scb->scsi_cmd == NULL) {
3341 /* unexpected interrupt */
3342 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3343 "Spurious interrupt; scsi_cmd not set.\n");
3351 /****************************************************************************/
3353 /* Routine Name: ips_done */
3355 /* Routine Description: */
3357 /* Do housekeeping on completed commands */
3358 /* ASSUMED to be called form within the request lock */
3359 /****************************************************************************/
3361 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3365 METHOD_TRACE("ips_done", 1);
3370 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3371 ips_cleanup_passthru(ha, scb);
3375 * Check to see if this command had too much
3376 * data and had to be broke up. If so, queue
3377 * the rest of the data and continue.
3379 if ((scb->breakup) || (scb->sg_break)) {
3380 /* we had a data breakup */
3383 if (scb->sg_count) {
3385 struct scatterlist *sg;
3386 int ips_sg_index = 0;
3389 sg = scb->scsi_cmd->request_buffer;
3391 /* Spin forward to last dma chunk */
3392 sg_dma_index = scb->breakup;
3394 /* Take care of possible partial on last chunk */
3395 ips_fill_scb_sg_single(ha,
3398 scb, ips_sg_index++,
3402 for (; sg_dma_index < scb->sg_count;
3404 if (ips_fill_scb_sg_single
3406 sg_dma_address(&sg[sg_dma_index]),
3407 scb, ips_sg_index++,
3408 sg_dma_len(&sg[sg_dma_index])) < 0)
3414 /* Non S/G Request */
3415 (void) ips_fill_scb_sg_single(ha,
3427 scb->dcdb.transfer_length = scb->data_len;
3428 scb->dcdb.cmd_attribute |=
3429 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3431 if (!(scb->dcdb.cmd_attribute & 0x3))
3432 scb->dcdb.transfer_length = 0;
3434 if (scb->data_len >= IPS_MAX_XFER) {
3435 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3436 scb->dcdb.transfer_length = 0;
3439 ret = ips_send_cmd(ha, scb);
3443 if (scb->scsi_cmd) {
3444 scb->scsi_cmd->result = DID_ERROR << 16;
3445 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3448 ips_freescb(ha, scb);
3450 case IPS_SUCCESS_IMM:
3451 if (scb->scsi_cmd) {
3452 scb->scsi_cmd->result = DID_ERROR << 16;
3453 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3456 ips_freescb(ha, scb);
3464 } /* end if passthru */
3467 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3470 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3472 ips_freescb(ha, scb);
3475 /****************************************************************************/
3477 /* Routine Name: ips_map_status */
3479 /* Routine Description: */
3481 /* Map Controller Error codes to Linux Error Codes */
3483 /****************************************************************************/
3485 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3489 uint32_t transfer_len;
3490 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3491 IPS_SCSI_INQ_DATA inquiryData;
3493 METHOD_TRACE("ips_map_status", 1);
3497 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3498 ips_name, ha->host_num,
3499 scb->scsi_cmd->device->channel,
3500 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3501 scb->basic_status, scb->extended_status,
3502 scb->extended_status ==
3503 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3504 scb->extended_status ==
3505 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3506 scb->extended_status ==
3507 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3510 /* default driver error */
3511 errcode = DID_ERROR;
3514 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3515 case IPS_CMD_TIMEOUT:
3516 errcode = DID_TIME_OUT;
3519 case IPS_INVAL_OPCO:
3520 case IPS_INVAL_CMD_BLK:
3521 case IPS_INVAL_PARM_BLK:
3523 case IPS_CMD_CMPLT_WERROR:
3526 case IPS_PHYS_DRV_ERROR:
3527 switch (scb->extended_status) {
3528 case IPS_ERR_SEL_TO:
3530 errcode = DID_NO_CONNECT;
3534 case IPS_ERR_OU_RUN:
3535 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3536 (scb->cmd.dcdb.op_code ==
3537 IPS_CMD_EXTENDED_DCDB_SG)) {
3538 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3539 transfer_len = tapeDCDB->transfer_length;
3542 (uint32_t) scb->dcdb.transfer_length;
3545 if ((scb->bus) && (transfer_len < scb->data_len)) {
3546 /* Underrun - set default to no error */
3549 /* Restrict access to physical DASD */
3550 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3551 ips_scmd_buf_read(scb->scsi_cmd,
3552 &inquiryData, sizeof (inquiryData));
3553 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK) {
3554 errcode = DID_TIME_OUT;
3559 errcode = DID_ERROR;
3563 case IPS_ERR_RECOVERY:
3564 /* don't fail recovered errors */
3570 case IPS_ERR_HOST_RESET:
3571 case IPS_ERR_DEV_RESET:
3572 errcode = DID_RESET;
3575 case IPS_ERR_CKCOND:
3577 if ((scb->cmd.dcdb.op_code ==
3578 IPS_CMD_EXTENDED_DCDB)
3579 || (scb->cmd.dcdb.op_code ==
3580 IPS_CMD_EXTENDED_DCDB_SG)) {
3582 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3583 memcpy(scb->scsi_cmd->sense_buffer,
3584 tapeDCDB->sense_info,
3585 sizeof (scb->scsi_cmd->
3588 memcpy(scb->scsi_cmd->sense_buffer,
3589 scb->dcdb.sense_info,
3590 sizeof (scb->scsi_cmd->
3593 device_error = 2; /* check condition */
3601 errcode = DID_ERROR;
3607 scb->scsi_cmd->result = device_error | (errcode << 16);
3612 /****************************************************************************/
3614 /* Routine Name: ips_send_wait */
3616 /* Routine Description: */
3618 /* Send a command to the controller and wait for it to return */
3620 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3621 /* actually need to wait. */
3622 /****************************************************************************/
3624 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3628 METHOD_TRACE("ips_send_wait", 1);
3630 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3631 ha->waitflag = TRUE;
3632 ha->cmd_in_progress = scb->cdb[0];
3634 scb->callback = ipsintr_blocking;
3635 ret = ips_send_cmd(ha, scb);
3637 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3640 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3641 ret = ips_wait(ha, timeout, intr);
3646 /****************************************************************************/
3648 /* Routine Name: ips_scmd_buf_write */
3650 /* Routine Description: */
3651 /* Write data to struct scsi_cmnd request_buffer at proper offsets */
3652 /****************************************************************************/
3654 ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
3658 unsigned int min_cnt, xfer_cnt;
3659 char *cdata = (char *) data;
3660 unsigned char *buffer;
3661 unsigned long flags;
3662 struct scatterlist *sg = scmd->request_buffer;
3663 for (i = 0, xfer_cnt = 0;
3664 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3665 min_cnt = min(count - xfer_cnt, sg[i].length);
3667 /* kmap_atomic() ensures addressability of the data buffer.*/
3668 /* local_irq_save() protects the KM_IRQ0 address slot. */
3669 local_irq_save(flags);
3670 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset;
3671 memcpy(buffer, &cdata[xfer_cnt], min_cnt);
3672 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3673 local_irq_restore(flags);
3675 xfer_cnt += min_cnt;
3679 unsigned int min_cnt = min(count, scmd->request_bufflen);
3680 memcpy(scmd->request_buffer, data, min_cnt);
3684 /****************************************************************************/
3686 /* Routine Name: ips_scmd_buf_read */
3688 /* Routine Description: */
3689 /* Copy data from a struct scsi_cmnd to a new, linear buffer */
3690 /****************************************************************************/
3692 ips_scmd_buf_read(struct scsi_cmnd *scmd, void *data, unsigned int count)
3696 unsigned int min_cnt, xfer_cnt;
3697 char *cdata = (char *) data;
3698 unsigned char *buffer;
3699 unsigned long flags;
3700 struct scatterlist *sg = scmd->request_buffer;
3701 for (i = 0, xfer_cnt = 0;
3702 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3703 min_cnt = min(count - xfer_cnt, sg[i].length);
3705 /* kmap_atomic() ensures addressability of the data buffer.*/
3706 /* local_irq_save() protects the KM_IRQ0 address slot. */
3707 local_irq_save(flags);
3708 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset;
3709 memcpy(&cdata[xfer_cnt], buffer, min_cnt);
3710 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3711 local_irq_restore(flags);
3713 xfer_cnt += min_cnt;
3717 unsigned int min_cnt = min(count, scmd->request_bufflen);
3718 memcpy(data, scmd->request_buffer, min_cnt);
3722 /****************************************************************************/
3724 /* Routine Name: ips_send_cmd */
3726 /* Routine Description: */
3728 /* Map SCSI commands to ServeRAID commands for logical drives */
3730 /****************************************************************************/
3732 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3737 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3740 METHOD_TRACE("ips_send_cmd", 1);
3744 if (!scb->scsi_cmd) {
3745 /* internal command */
3748 /* Controller commands can't be issued */
3749 /* to real devices -- fail them */
3750 if ((ha->waitflag == TRUE) &&
3751 (ha->cmd_in_progress == scb->cdb[0])) {
3752 ha->waitflag = FALSE;
3757 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3758 /* command to logical bus -- interpret */
3759 ret = IPS_SUCCESS_IMM;
3761 switch (scb->scsi_cmd->cmnd[0]) {
3762 case ALLOW_MEDIUM_REMOVAL:
3765 case WRITE_FILEMARKS:
3767 scb->scsi_cmd->result = DID_ERROR << 16;
3771 scb->scsi_cmd->result = DID_OK << 16;
3773 case TEST_UNIT_READY:
3775 if (scb->target_id == IPS_ADAPTER_ID) {
3777 * Either we have a TUR
3778 * or we have a SCSI inquiry
3780 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3781 scb->scsi_cmd->result = DID_OK << 16;
3783 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3784 IPS_SCSI_INQ_DATA inquiry;
3787 sizeof (IPS_SCSI_INQ_DATA));
3789 inquiry.DeviceType =
3790 IPS_SCSI_INQ_TYPE_PROCESSOR;
3791 inquiry.DeviceTypeQualifier =
3792 IPS_SCSI_INQ_LU_CONNECTED;
3793 inquiry.Version = IPS_SCSI_INQ_REV2;
3794 inquiry.ResponseDataFormat =
3795 IPS_SCSI_INQ_RD_REV2;
3796 inquiry.AdditionalLength = 31;
3798 IPS_SCSI_INQ_Address16;
3800 IPS_SCSI_INQ_WBus16 |
3802 strncpy(inquiry.VendorId, "IBM ",
3804 strncpy(inquiry.ProductId,
3806 strncpy(inquiry.ProductRevisionLevel,
3809 ips_scmd_buf_write(scb->scsi_cmd,
3813 scb->scsi_cmd->result = DID_OK << 16;
3816 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3817 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3818 scb->cmd.logical_info.reserved = 0;
3819 scb->cmd.logical_info.reserved2 = 0;
3820 scb->data_len = sizeof (IPS_LD_INFO);
3821 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3823 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3830 ips_reqsen(ha, scb);
3831 scb->scsi_cmd->result = DID_OK << 16;
3837 scb->cmd.basic_io.op_code =
3838 (scb->scsi_cmd->cmnd[0] ==
3839 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3840 scb->cmd.basic_io.enhanced_sg = 0;
3841 scb->cmd.basic_io.sg_addr =
3842 cpu_to_le32(scb->data_busaddr);
3844 scb->cmd.basic_io.op_code =
3845 (scb->scsi_cmd->cmnd[0] ==
3846 READ_6) ? IPS_CMD_READ_SG :
3848 scb->cmd.basic_io.enhanced_sg =
3849 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3850 scb->cmd.basic_io.sg_addr =
3851 cpu_to_le32(scb->sg_busaddr);
3854 scb->cmd.basic_io.segment_4G = 0;
3855 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3856 scb->cmd.basic_io.log_drv = scb->target_id;
3857 scb->cmd.basic_io.sg_count = scb->sg_len;
3859 if (scb->cmd.basic_io.lba)
3860 scb->cmd.basic_io.lba =
3861 cpu_to_le32(le32_to_cpu
3862 (scb->cmd.basic_io.lba) +
3863 le16_to_cpu(scb->cmd.basic_io.
3866 scb->cmd.basic_io.lba =
3868 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3870 (scb->scsi_cmd->cmnd[3]));
3872 scb->cmd.basic_io.sector_count =
3873 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3875 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3876 scb->cmd.basic_io.sector_count =
3885 scb->cmd.basic_io.op_code =
3886 (scb->scsi_cmd->cmnd[0] ==
3887 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3888 scb->cmd.basic_io.enhanced_sg = 0;
3889 scb->cmd.basic_io.sg_addr =
3890 cpu_to_le32(scb->data_busaddr);
3892 scb->cmd.basic_io.op_code =
3893 (scb->scsi_cmd->cmnd[0] ==
3894 READ_10) ? IPS_CMD_READ_SG :
3896 scb->cmd.basic_io.enhanced_sg =
3897 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3898 scb->cmd.basic_io.sg_addr =
3899 cpu_to_le32(scb->sg_busaddr);
3902 scb->cmd.basic_io.segment_4G = 0;
3903 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3904 scb->cmd.basic_io.log_drv = scb->target_id;
3905 scb->cmd.basic_io.sg_count = scb->sg_len;
3907 if (scb->cmd.basic_io.lba)
3908 scb->cmd.basic_io.lba =
3909 cpu_to_le32(le32_to_cpu
3910 (scb->cmd.basic_io.lba) +
3911 le16_to_cpu(scb->cmd.basic_io.
3914 scb->cmd.basic_io.lba =
3915 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3919 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3922 scb->cmd.basic_io.sector_count =
3923 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3925 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3927 * This is a null condition
3928 * we don't have to do anything
3931 scb->scsi_cmd->result = DID_OK << 16;
3939 scb->scsi_cmd->result = DID_OK << 16;
3943 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3944 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3945 scb->cmd.basic_io.segment_4G = 0;
3946 scb->cmd.basic_io.enhanced_sg = 0;
3947 scb->data_len = sizeof (*ha->enq);
3948 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3953 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3954 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3955 scb->cmd.logical_info.reserved = 0;
3956 scb->cmd.logical_info.reserved2 = 0;
3957 scb->cmd.logical_info.reserved3 = 0;
3958 scb->data_len = sizeof (IPS_LD_INFO);
3959 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3961 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3965 case SEND_DIAGNOSTIC:
3966 case REASSIGN_BLOCKS:
3970 case READ_DEFECT_DATA:
3973 scb->scsi_cmd->result = DID_OK << 16;
3977 /* Set the Return Info to appear like the Command was */
3978 /* attempted, a Check Condition occurred, and Sense */
3979 /* Data indicating an Invalid CDB OpCode is returned. */
3980 sp = (char *) scb->scsi_cmd->sense_buffer;
3981 memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
3983 sp[0] = 0x70; /* Error Code */
3984 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3985 sp[7] = 0x0A; /* Additional Sense Length */
3986 sp[12] = 0x20; /* ASC = Invalid OpCode */
3987 sp[13] = 0x00; /* ASCQ */
3989 device_error = 2; /* Indicate Check Condition */
3990 scb->scsi_cmd->result = device_error | (DID_OK << 16);
3995 if (ret == IPS_SUCCESS_IMM)
4001 /* If we already know the Device is Not there, no need to attempt a Command */
4002 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
4003 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
4004 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
4005 return (IPS_SUCCESS_IMM);
4008 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
4009 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
4010 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
4011 (unsigned long) &scb->
4013 (unsigned long) scb);
4014 scb->cmd.dcdb.reserved = 0;
4015 scb->cmd.dcdb.reserved2 = 0;
4016 scb->cmd.dcdb.reserved3 = 0;
4017 scb->cmd.dcdb.segment_4G = 0;
4018 scb->cmd.dcdb.enhanced_sg = 0;
4020 TimeOut = scb->scsi_cmd->timeout_per_command;
4022 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
4024 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
4026 scb->cmd.dcdb.op_code =
4027 IPS_CMD_EXTENDED_DCDB_SG;
4028 scb->cmd.dcdb.enhanced_sg =
4029 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4032 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
4033 tapeDCDB->device_address =
4034 ((scb->bus - 1) << 4) | scb->target_id;
4035 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4036 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
4039 if (TimeOut < (10 * HZ))
4040 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4041 else if (TimeOut < (60 * HZ))
4042 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4043 else if (TimeOut < (1200 * HZ))
4044 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4047 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
4048 tapeDCDB->reserved_for_LUN = 0;
4049 tapeDCDB->transfer_length = scb->data_len;
4050 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
4051 tapeDCDB->buffer_pointer =
4052 cpu_to_le32(scb->sg_busaddr);
4054 tapeDCDB->buffer_pointer =
4055 cpu_to_le32(scb->data_busaddr);
4056 tapeDCDB->sg_count = scb->sg_len;
4057 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
4058 tapeDCDB->scsi_status = 0;
4059 tapeDCDB->reserved = 0;
4060 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
4061 scb->scsi_cmd->cmd_len);
4064 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
4066 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
4067 scb->cmd.dcdb.enhanced_sg =
4068 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4071 scb->dcdb.device_address =
4072 ((scb->bus - 1) << 4) | scb->target_id;
4073 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4076 if (TimeOut < (10 * HZ))
4077 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4078 else if (TimeOut < (60 * HZ))
4079 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4080 else if (TimeOut < (1200 * HZ))
4081 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4084 scb->dcdb.transfer_length = scb->data_len;
4085 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
4086 scb->dcdb.transfer_length = 0;
4087 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
4088 scb->dcdb.buffer_pointer =
4089 cpu_to_le32(scb->sg_busaddr);
4091 scb->dcdb.buffer_pointer =
4092 cpu_to_le32(scb->data_busaddr);
4093 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
4094 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
4095 scb->dcdb.sg_count = scb->sg_len;
4096 scb->dcdb.reserved = 0;
4097 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
4098 scb->scsi_cmd->cmd_len);
4099 scb->dcdb.scsi_status = 0;
4100 scb->dcdb.reserved2[0] = 0;
4101 scb->dcdb.reserved2[1] = 0;
4102 scb->dcdb.reserved2[2] = 0;
4106 return ((*ha->func.issue) (ha, scb));
4109 /****************************************************************************/
4111 /* Routine Name: ips_chk_status */
4113 /* Routine Description: */
4115 /* Check the status of commands to logical drives */
4116 /* Assumed to be called with the HA lock */
4117 /****************************************************************************/
4119 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
4123 uint8_t basic_status;
4126 IPS_SCSI_INQ_DATA inquiryData;
4128 METHOD_TRACE("ips_chkstatus", 1);
4130 scb = &ha->scbs[pstatus->fields.command_id];
4131 scb->basic_status = basic_status =
4132 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
4133 scb->extended_status = ext_status = pstatus->fields.extended_status;
4136 sp->residue_len = 0;
4137 sp->scb_addr = (void *) scb;
4139 /* Remove the item from the active queue */
4140 ips_removeq_scb(&ha->scb_activelist, scb);
4143 /* internal commands are handled in do_ipsintr */
4146 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
4150 scb->cmd.basic_io.command_id,
4151 scb->bus, scb->target_id, scb->lun);
4153 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
4154 /* passthru - just returns the raw result */
4159 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
4160 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
4162 if (scb->bus == 0) {
4163 if ((basic_status & IPS_GSC_STATUS_MASK) ==
4164 IPS_CMD_RECOVERED_ERROR) {
4166 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4167 ips_name, ha->host_num,
4168 scb->cmd.basic_io.op_code,
4169 basic_status, ext_status);
4172 switch (scb->scsi_cmd->cmnd[0]) {
4173 case ALLOW_MEDIUM_REMOVAL:
4176 case WRITE_FILEMARKS:
4178 errcode = DID_ERROR;
4184 case TEST_UNIT_READY:
4185 if (!ips_online(ha, scb)) {
4186 errcode = DID_TIME_OUT;
4191 if (ips_online(ha, scb)) {
4192 ips_inquiry(ha, scb);
4194 errcode = DID_TIME_OUT;
4199 ips_reqsen(ha, scb);
4211 if (!ips_online(ha, scb)
4212 || !ips_msense(ha, scb)) {
4213 errcode = DID_ERROR;
4218 if (ips_online(ha, scb))
4221 errcode = DID_TIME_OUT;
4225 case SEND_DIAGNOSTIC:
4226 case REASSIGN_BLOCKS:
4230 errcode = DID_ERROR;
4235 case READ_DEFECT_DATA:
4241 errcode = DID_ERROR;
4244 scb->scsi_cmd->result = errcode << 16;
4245 } else { /* bus == 0 */
4246 /* restrict access to physical drives */
4247 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
4248 ips_scmd_buf_read(scb->scsi_cmd,
4249 &inquiryData, sizeof (inquiryData));
4250 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK)
4251 scb->scsi_cmd->result = DID_TIME_OUT << 16;
4254 } else { /* recovered error / success */
4255 if (scb->bus == 0) {
4257 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4258 ips_name, ha->host_num,
4259 scb->cmd.basic_io.op_code, basic_status,
4263 ips_map_status(ha, scb, sp);
4267 /****************************************************************************/
4269 /* Routine Name: ips_online */
4271 /* Routine Description: */
4273 /* Determine if a logical drive is online */
4275 /****************************************************************************/
4277 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4279 METHOD_TRACE("ips_online", 1);
4281 if (scb->target_id >= IPS_MAX_LD)
4284 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4285 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4289 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4291 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4293 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4295 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4302 /****************************************************************************/
4304 /* Routine Name: ips_inquiry */
4306 /* Routine Description: */
4308 /* Simulate an inquiry command to a logical drive */
4310 /****************************************************************************/
4312 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4314 IPS_SCSI_INQ_DATA inquiry;
4316 METHOD_TRACE("ips_inquiry", 1);
4318 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4320 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4321 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4322 inquiry.Version = IPS_SCSI_INQ_REV2;
4323 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4324 inquiry.AdditionalLength = 31;
4325 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4327 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4328 strncpy(inquiry.VendorId, "IBM ", 8);
4329 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4330 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4332 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4337 /****************************************************************************/
4339 /* Routine Name: ips_rdcap */
4341 /* Routine Description: */
4343 /* Simulate a read capacity command to a logical drive */
4345 /****************************************************************************/
4347 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4349 IPS_SCSI_CAPACITY cap;
4351 METHOD_TRACE("ips_rdcap", 1);
4353 if (scb->scsi_cmd->request_bufflen < 8)
4357 cpu_to_be32(le32_to_cpu
4358 (ha->logical_drive_info->
4359 drive_info[scb->target_id].sector_count) - 1);
4360 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4362 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4367 /****************************************************************************/
4369 /* Routine Name: ips_msense */
4371 /* Routine Description: */
4373 /* Simulate a mode sense command to a logical drive */
4375 /****************************************************************************/
4377 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4382 IPS_SCSI_MODE_PAGE_DATA mdata;
4384 METHOD_TRACE("ips_msense", 1);
4386 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4387 (ha->enq->ucMiscFlag & 0x8) == 0) {
4388 heads = IPS_NORM_HEADS;
4389 sectors = IPS_NORM_SECTORS;
4391 heads = IPS_COMP_HEADS;
4392 sectors = IPS_COMP_SECTORS;
4396 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4397 1) / (heads * sectors);
4399 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4401 mdata.hdr.BlockDescLength = 8;
4403 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4404 case 0x03: /* page 3 */
4405 mdata.pdata.pg3.PageCode = 3;
4406 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4407 mdata.hdr.DataLength =
4408 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4409 mdata.pdata.pg3.TracksPerZone = 0;
4410 mdata.pdata.pg3.AltSectorsPerZone = 0;
4411 mdata.pdata.pg3.AltTracksPerZone = 0;
4412 mdata.pdata.pg3.AltTracksPerVolume = 0;
4413 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4414 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4415 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4416 mdata.pdata.pg3.TrackSkew = 0;
4417 mdata.pdata.pg3.CylinderSkew = 0;
4418 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4422 mdata.pdata.pg4.PageCode = 4;
4423 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4424 mdata.hdr.DataLength =
4425 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4426 mdata.pdata.pg4.CylindersHigh =
4427 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4428 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4429 mdata.pdata.pg4.Heads = heads;
4430 mdata.pdata.pg4.WritePrecompHigh = 0;
4431 mdata.pdata.pg4.WritePrecompLow = 0;
4432 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4433 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4434 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4435 mdata.pdata.pg4.LandingZoneHigh = 0;
4436 mdata.pdata.pg4.LandingZoneLow = 0;
4437 mdata.pdata.pg4.flags = 0;
4438 mdata.pdata.pg4.RotationalOffset = 0;
4439 mdata.pdata.pg4.MediumRotationRate = 0;
4442 mdata.pdata.pg8.PageCode = 8;
4443 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4444 mdata.hdr.DataLength =
4445 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4446 /* everything else is left set to 0 */
4453 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4458 /****************************************************************************/
4460 /* Routine Name: ips_reqsen */
4462 /* Routine Description: */
4464 /* Simulate a request sense command to a logical drive */
4466 /****************************************************************************/
4468 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4470 IPS_SCSI_REQSEN reqsen;
4472 METHOD_TRACE("ips_reqsen", 1);
4474 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4476 reqsen.ResponseCode =
4477 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4478 reqsen.AdditionalLength = 10;
4479 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4480 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4482 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4487 /****************************************************************************/
4489 /* Routine Name: ips_free */
4491 /* Routine Description: */
4493 /* Free any allocated space for this controller */
4495 /****************************************************************************/
4497 ips_free(ips_ha_t * ha)
4500 METHOD_TRACE("ips_free", 1);
4504 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4505 ha->enq, ha->enq_busaddr);
4513 pci_free_consistent(ha->pcidev,
4514 sizeof (IPS_ADAPTER) +
4515 sizeof (IPS_IO_CMD), ha->adapt,
4516 ha->adapt->hw_status_start);
4520 if (ha->logical_drive_info) {
4521 pci_free_consistent(ha->pcidev,
4522 sizeof (IPS_LD_INFO),
4523 ha->logical_drive_info,
4524 ha->logical_drive_info_dma_addr);
4525 ha->logical_drive_info = NULL;
4534 if (ha->ioctl_data) {
4535 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4536 ha->ioctl_data, ha->ioctl_busaddr);
4537 ha->ioctl_data = NULL;
4538 ha->ioctl_datasize = 0;
4541 ips_deallocatescbs(ha, ha->max_cmds);
4543 /* free memory mapped (if applicable) */
4545 iounmap(ha->ioremap_ptr);
4546 ha->ioremap_ptr = NULL;
4551 release_mem_region(ha->mem_addr, ha->mem_len);
4557 /****************************************************************************/
4559 /* Routine Name: ips_deallocatescbs */
4561 /* Routine Description: */
4563 /* Free the command blocks */
4565 /****************************************************************************/
4567 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4570 pci_free_consistent(ha->pcidev,
4571 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4572 ha->scbs->sg_list.list,
4573 ha->scbs->sg_busaddr);
4574 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4575 ha->scbs, ha->scbs->scb_busaddr);
4581 /****************************************************************************/
4583 /* Routine Name: ips_allocatescbs */
4585 /* Routine Description: */
4587 /* Allocate the command blocks */
4589 /****************************************************************************/
4591 ips_allocatescbs(ips_ha_t * ha)
4596 dma_addr_t command_dma, sg_dma;
4598 METHOD_TRACE("ips_allocatescbs", 1);
4600 /* Allocate memory for the SCBs */
4602 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4604 if (ha->scbs == NULL)
4607 pci_alloc_consistent(ha->pcidev,
4608 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4609 ha->max_cmds, &sg_dma);
4610 if (ips_sg.list == NULL) {
4611 pci_free_consistent(ha->pcidev,
4612 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4617 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4619 for (i = 0; i < ha->max_cmds; i++) {
4620 scb_p = &ha->scbs[i];
4621 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4622 /* set up S/G list */
4623 if (IPS_USE_ENH_SGLIST(ha)) {
4624 scb_p->sg_list.enh_list =
4625 ips_sg.enh_list + i * IPS_MAX_SG;
4627 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4629 scb_p->sg_list.std_list =
4630 ips_sg.std_list + i * IPS_MAX_SG;
4632 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4635 /* add to the free list */
4636 if (i < ha->max_cmds - 1) {
4637 scb_p->q_next = ha->scb_freelist;
4638 ha->scb_freelist = scb_p;
4646 /****************************************************************************/
4648 /* Routine Name: ips_init_scb */
4650 /* Routine Description: */
4652 /* Initialize a CCB to default values */
4654 /****************************************************************************/
4656 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4658 IPS_SG_LIST sg_list;
4659 uint32_t cmd_busaddr, sg_busaddr;
4660 METHOD_TRACE("ips_init_scb", 1);
4665 sg_list.list = scb->sg_list.list;
4666 cmd_busaddr = scb->scb_busaddr;
4667 sg_busaddr = scb->sg_busaddr;
4669 memset(scb, 0, sizeof (ips_scb_t));
4670 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4672 /* Initialize dummy command bucket */
4673 ha->dummy->op_code = 0xFF;
4674 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4675 + sizeof (IPS_ADAPTER));
4676 ha->dummy->command_id = IPS_MAX_CMDS;
4678 /* set bus address of scb */
4679 scb->scb_busaddr = cmd_busaddr;
4680 scb->sg_busaddr = sg_busaddr;
4681 scb->sg_list.list = sg_list.list;
4684 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4685 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4686 + sizeof (IPS_ADAPTER));
4689 /****************************************************************************/
4691 /* Routine Name: ips_get_scb */
4693 /* Routine Description: */
4695 /* Initialize a CCB to default values */
4697 /* ASSUMED to be callled from within a lock */
4699 /****************************************************************************/
4701 ips_getscb(ips_ha_t * ha)
4705 METHOD_TRACE("ips_getscb", 1);
4707 if ((scb = ha->scb_freelist) == NULL) {
4712 ha->scb_freelist = scb->q_next;
4716 ips_init_scb(ha, scb);
4721 /****************************************************************************/
4723 /* Routine Name: ips_free_scb */
4725 /* Routine Description: */
4727 /* Return an unused CCB back to the free list */
4729 /* ASSUMED to be called from within a lock */
4731 /****************************************************************************/
4733 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4736 METHOD_TRACE("ips_freescb", 1);
4737 if (scb->flags & IPS_SCB_MAP_SG)
4738 pci_unmap_sg(ha->pcidev, scb->scsi_cmd->request_buffer,
4739 scb->scsi_cmd->use_sg, IPS_DMA_DIR(scb));
4740 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4741 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4744 /* check to make sure this is not our "special" scb */
4745 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4746 scb->q_next = ha->scb_freelist;
4747 ha->scb_freelist = scb;
4751 /****************************************************************************/
4753 /* Routine Name: ips_isinit_copperhead */
4755 /* Routine Description: */
4757 /* Is controller initialized ? */
4759 /****************************************************************************/
4761 ips_isinit_copperhead(ips_ha_t * ha)
4766 METHOD_TRACE("ips_isinit_copperhead", 1);
4768 isr = inb(ha->io_addr + IPS_REG_HISR);
4769 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4771 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4777 /****************************************************************************/
4779 /* Routine Name: ips_isinit_copperhead_memio */
4781 /* Routine Description: */
4783 /* Is controller initialized ? */
4785 /****************************************************************************/
4787 ips_isinit_copperhead_memio(ips_ha_t * ha)
4792 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4794 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4795 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4797 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4803 /****************************************************************************/
4805 /* Routine Name: ips_isinit_morpheus */
4807 /* Routine Description: */
4809 /* Is controller initialized ? */
4811 /****************************************************************************/
4813 ips_isinit_morpheus(ips_ha_t * ha)
4818 METHOD_TRACE("ips_is_init_morpheus", 1);
4820 if (ips_isintr_morpheus(ha))
4821 ips_flush_and_reset(ha);
4823 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4824 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4828 else if (bits & 0x3)
4834 /****************************************************************************/
4836 /* Routine Name: ips_flush_and_reset */
4838 /* Routine Description: */
4840 /* Perform cleanup ( FLUSH and RESET ) when the adapter is in an unknown */
4841 /* state ( was trying to INIT and an interrupt was already pending ) ... */
4843 /****************************************************************************/
4845 ips_flush_and_reset(ips_ha_t *ha)
4851 dma_addr_t command_dma;
4853 /* Create a usuable SCB */
4854 scb = pci_alloc_consistent(ha->pcidev, sizeof(ips_scb_t), &command_dma);
4856 memset(scb, 0, sizeof(ips_scb_t));
4857 ips_init_scb(ha, scb);
4858 scb->scb_busaddr = command_dma;
4860 scb->timeout = ips_cmd_timeout;
4861 scb->cdb[0] = IPS_CMD_FLUSH;
4863 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
4864 scb->cmd.flush_cache.command_id = IPS_MAX_CMDS; /* Use an ID that would otherwise not exist */
4865 scb->cmd.flush_cache.state = IPS_NORM_STATE;
4866 scb->cmd.flush_cache.reserved = 0;
4867 scb->cmd.flush_cache.reserved2 = 0;
4868 scb->cmd.flush_cache.reserved3 = 0;
4869 scb->cmd.flush_cache.reserved4 = 0;
4871 ret = ips_send_cmd(ha, scb); /* Send the Flush Command */
4873 if (ret == IPS_SUCCESS) {
4874 time = 60 * IPS_ONE_SEC; /* Max Wait time is 60 seconds */
4877 while ((time > 0) && (!done)) {
4878 done = ips_poll_for_flush_complete(ha);
4879 /* This may look evil, but it's only done during extremely rare start-up conditions ! */
4886 /* Now RESET and INIT the adapter */
4887 (*ha->func.reset) (ha);
4889 pci_free_consistent(ha->pcidev, sizeof(ips_scb_t), scb, command_dma);
4893 /****************************************************************************/
4895 /* Routine Name: ips_poll_for_flush_complete */
4897 /* Routine Description: */
4899 /* Poll for the Flush Command issued by ips_flush_and_reset() to complete */
4900 /* All other responses are just taken off the queue and ignored */
4902 /****************************************************************************/
4904 ips_poll_for_flush_complete(ips_ha_t * ha)
4909 cstatus.value = (*ha->func.statupd) (ha);
4911 if (cstatus.value == 0xffffffff) /* If No Interrupt to process */
4914 /* Success is when we see the Flush Command ID */
4915 if (cstatus.fields.command_id == IPS_MAX_CMDS )
4922 /****************************************************************************/
4924 /* Routine Name: ips_enable_int_copperhead */
4926 /* Routine Description: */
4927 /* Turn on interrupts */
4929 /****************************************************************************/
4931 ips_enable_int_copperhead(ips_ha_t * ha)
4933 METHOD_TRACE("ips_enable_int_copperhead", 1);
4935 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4936 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4939 /****************************************************************************/
4941 /* Routine Name: ips_enable_int_copperhead_memio */
4943 /* Routine Description: */
4944 /* Turn on interrupts */
4946 /****************************************************************************/
4948 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4950 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4952 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4953 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4956 /****************************************************************************/
4958 /* Routine Name: ips_enable_int_morpheus */
4960 /* Routine Description: */
4961 /* Turn on interrupts */
4963 /****************************************************************************/
4965 ips_enable_int_morpheus(ips_ha_t * ha)
4969 METHOD_TRACE("ips_enable_int_morpheus", 1);
4971 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4973 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4974 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4977 /****************************************************************************/
4979 /* Routine Name: ips_init_copperhead */
4981 /* Routine Description: */
4983 /* Initialize a copperhead controller */
4985 /****************************************************************************/
4987 ips_init_copperhead(ips_ha_t * ha)
4991 uint8_t PostByte[IPS_MAX_POST_BYTES];
4992 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4995 METHOD_TRACE("ips_init_copperhead", 1);
4997 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4998 for (j = 0; j < 45; j++) {
4999 Isr = inb(ha->io_addr + IPS_REG_HISR);
5000 if (Isr & IPS_BIT_GHI)
5003 /* Delay for 1 Second */
5004 msleep(IPS_ONE_SEC);
5008 /* error occurred */
5011 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
5012 outb(Isr, ha->io_addr + IPS_REG_HISR);
5015 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5016 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5017 "reset controller fails (post status %x %x).\n",
5018 PostByte[0], PostByte[1]);
5023 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5024 for (j = 0; j < 240; j++) {
5025 Isr = inb(ha->io_addr + IPS_REG_HISR);
5026 if (Isr & IPS_BIT_GHI)
5029 /* Delay for 1 Second */
5030 msleep(IPS_ONE_SEC);
5034 /* error occurred */
5037 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
5038 outb(Isr, ha->io_addr + IPS_REG_HISR);
5041 for (i = 0; i < 240; i++) {
5042 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
5044 if ((Cbsp & IPS_BIT_OP) == 0)
5047 /* Delay for 1 Second */
5048 msleep(IPS_ONE_SEC);
5056 outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
5058 /* Enable busmastering */
5059 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
5061 if (ha->revision_id == IPS_REVID_TROMBONE64)
5062 /* fix for anaconda64 */
5063 outl(0, ha->io_addr + IPS_REG_NDAE);
5065 /* Enable interrupts */
5066 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
5071 /****************************************************************************/
5073 /* Routine Name: ips_init_copperhead_memio */
5075 /* Routine Description: */
5077 /* Initialize a copperhead controller with memory mapped I/O */
5079 /****************************************************************************/
5081 ips_init_copperhead_memio(ips_ha_t * ha)
5085 uint8_t PostByte[IPS_MAX_POST_BYTES];
5086 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
5089 METHOD_TRACE("ips_init_copperhead_memio", 1);
5091 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
5092 for (j = 0; j < 45; j++) {
5093 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5094 if (Isr & IPS_BIT_GHI)
5097 /* Delay for 1 Second */
5098 msleep(IPS_ONE_SEC);
5102 /* error occurred */
5105 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5106 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5109 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5110 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5111 "reset controller fails (post status %x %x).\n",
5112 PostByte[0], PostByte[1]);
5117 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5118 for (j = 0; j < 240; j++) {
5119 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5120 if (Isr & IPS_BIT_GHI)
5123 /* Delay for 1 Second */
5124 msleep(IPS_ONE_SEC);
5128 /* error occurred */
5131 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5132 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5135 for (i = 0; i < 240; i++) {
5136 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
5138 if ((Cbsp & IPS_BIT_OP) == 0)
5141 /* Delay for 1 Second */
5142 msleep(IPS_ONE_SEC);
5146 /* error occurred */
5150 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
5152 /* Enable busmastering */
5153 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
5155 if (ha->revision_id == IPS_REVID_TROMBONE64)
5156 /* fix for anaconda64 */
5157 writel(0, ha->mem_ptr + IPS_REG_NDAE);
5159 /* Enable interrupts */
5160 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
5162 /* if we get here then everything went OK */
5166 /****************************************************************************/
5168 /* Routine Name: ips_init_morpheus */
5170 /* Routine Description: */
5172 /* Initialize a morpheus controller */
5174 /****************************************************************************/
5176 ips_init_morpheus(ips_ha_t * ha)
5184 METHOD_TRACE("ips_init_morpheus", 1);
5186 /* Wait up to 45 secs for Post */
5187 for (i = 0; i < 45; i++) {
5188 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5190 if (Isr & IPS_BIT_I960_MSG0I)
5193 /* Delay for 1 Second */
5194 msleep(IPS_ONE_SEC);
5198 /* error occurred */
5199 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5200 "timeout waiting for post.\n");
5205 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5207 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
5208 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5209 "Flashing Battery PIC, Please wait ...\n");
5211 /* Clear the interrupt bit */
5212 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5213 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5215 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
5216 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5219 /* Delay for 1 Second */
5220 msleep(IPS_ONE_SEC);
5224 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5225 "timeout waiting for Battery PIC Flash\n");
5231 /* Clear the interrupt bit */
5232 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5233 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5235 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
5236 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5237 "reset controller fails (post status %x).\n", Post);
5242 /* Wait up to 240 secs for config bytes */
5243 for (i = 0; i < 240; i++) {
5244 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5246 if (Isr & IPS_BIT_I960_MSG1I)
5249 /* Delay for 1 Second */
5250 msleep(IPS_ONE_SEC);
5254 /* error occurred */
5255 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5256 "timeout waiting for config.\n");
5261 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
5263 /* Clear interrupt bit */
5264 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
5265 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5267 /* Turn on the interrupts */
5268 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
5270 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
5272 /* if we get here then everything went OK */
5274 /* Since we did a RESET, an EraseStripeLock may be needed */
5275 if (Post == 0xEF10) {
5276 if ((Config == 0x000F) || (Config == 0x0009))
5277 ha->requires_esl = 1;
5283 /****************************************************************************/
5285 /* Routine Name: ips_reset_copperhead */
5287 /* Routine Description: */
5289 /* Reset the controller */
5291 /****************************************************************************/
5293 ips_reset_copperhead(ips_ha_t * ha)
5297 METHOD_TRACE("ips_reset_copperhead", 1);
5299 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5300 ips_name, ha->host_num, ha->io_addr, ha->irq);
5304 while (reset_counter < 2) {
5307 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5309 /* Delay for 1 Second */
5310 msleep(IPS_ONE_SEC);
5312 outb(0, ha->io_addr + IPS_REG_SCPR);
5314 /* Delay for 1 Second */
5315 msleep(IPS_ONE_SEC);
5317 if ((*ha->func.init) (ha))
5319 else if (reset_counter >= 2) {
5328 /****************************************************************************/
5330 /* Routine Name: ips_reset_copperhead_memio */
5332 /* Routine Description: */
5334 /* Reset the controller */
5336 /****************************************************************************/
5338 ips_reset_copperhead_memio(ips_ha_t * ha)
5342 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5344 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5345 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5349 while (reset_counter < 2) {
5352 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5354 /* Delay for 1 Second */
5355 msleep(IPS_ONE_SEC);
5357 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5359 /* Delay for 1 Second */
5360 msleep(IPS_ONE_SEC);
5362 if ((*ha->func.init) (ha))
5364 else if (reset_counter >= 2) {
5373 /****************************************************************************/
5375 /* Routine Name: ips_reset_morpheus */
5377 /* Routine Description: */
5379 /* Reset the controller */
5381 /****************************************************************************/
5383 ips_reset_morpheus(ips_ha_t * ha)
5388 METHOD_TRACE("ips_reset_morpheus", 1);
5390 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5391 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5395 while (reset_counter < 2) {
5398 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5400 /* Delay for 5 Seconds */
5401 msleep(5 * IPS_ONE_SEC);
5403 /* Do a PCI config read to wait for adapter */
5404 pci_read_config_byte(ha->pcidev, 4, &junk);
5406 if ((*ha->func.init) (ha))
5408 else if (reset_counter >= 2) {
5417 /****************************************************************************/
5419 /* Routine Name: ips_statinit */
5421 /* Routine Description: */
5423 /* Initialize the status queues on the controller */
5425 /****************************************************************************/
5427 ips_statinit(ips_ha_t * ha)
5429 uint32_t phys_status_start;
5431 METHOD_TRACE("ips_statinit", 1);
5433 ha->adapt->p_status_start = ha->adapt->status;
5434 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5435 ha->adapt->p_status_tail = ha->adapt->status;
5437 phys_status_start = ha->adapt->hw_status_start;
5438 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
5439 outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE),
5440 ha->io_addr + IPS_REG_SQER);
5441 outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE),
5442 ha->io_addr + IPS_REG_SQHR);
5443 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
5445 ha->adapt->hw_status_tail = phys_status_start;
5448 /****************************************************************************/
5450 /* Routine Name: ips_statinit_memio */
5452 /* Routine Description: */
5454 /* Initialize the status queues on the controller */
5456 /****************************************************************************/
5458 ips_statinit_memio(ips_ha_t * ha)
5460 uint32_t phys_status_start;
5462 METHOD_TRACE("ips_statinit_memio", 1);
5464 ha->adapt->p_status_start = ha->adapt->status;
5465 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5466 ha->adapt->p_status_tail = ha->adapt->status;
5468 phys_status_start = ha->adapt->hw_status_start;
5469 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5470 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5471 ha->mem_ptr + IPS_REG_SQER);
5472 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5473 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5475 ha->adapt->hw_status_tail = phys_status_start;
5478 /****************************************************************************/
5480 /* Routine Name: ips_statupd_copperhead */
5482 /* Routine Description: */
5484 /* Remove an element from the status queue */
5486 /****************************************************************************/
5488 ips_statupd_copperhead(ips_ha_t * ha)
5490 METHOD_TRACE("ips_statupd_copperhead", 1);
5492 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5493 ha->adapt->p_status_tail++;
5494 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5496 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5497 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5500 outl(cpu_to_le32(ha->adapt->hw_status_tail),
5501 ha->io_addr + IPS_REG_SQTR);
5503 return (ha->adapt->p_status_tail->value);
5506 /****************************************************************************/
5508 /* Routine Name: ips_statupd_copperhead_memio */
5510 /* Routine Description: */
5512 /* Remove an element from the status queue */
5514 /****************************************************************************/
5516 ips_statupd_copperhead_memio(ips_ha_t * ha)
5518 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5520 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5521 ha->adapt->p_status_tail++;
5522 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5524 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5525 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5528 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5530 return (ha->adapt->p_status_tail->value);
5533 /****************************************************************************/
5535 /* Routine Name: ips_statupd_morpheus */
5537 /* Routine Description: */
5539 /* Remove an element from the status queue */
5541 /****************************************************************************/
5543 ips_statupd_morpheus(ips_ha_t * ha)
5547 METHOD_TRACE("ips_statupd_morpheus", 1);
5549 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5554 /****************************************************************************/
5556 /* Routine Name: ips_issue_copperhead */
5558 /* Routine Description: */
5560 /* Send a command down to the controller */
5562 /****************************************************************************/
5564 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5569 METHOD_TRACE("ips_issue_copperhead", 1);
5571 if (scb->scsi_cmd) {
5572 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5576 scb->cmd.basic_io.command_id,
5577 scb->bus, scb->target_id, scb->lun);
5579 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5580 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5586 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5589 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5590 if (!(val & IPS_BIT_START_STOP))
5593 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5594 "ips_issue val [0x%x].\n", val);
5595 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5596 "ips_issue semaphore chk timeout.\n");
5598 return (IPS_FAILURE);
5602 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
5603 outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
5605 return (IPS_SUCCESS);
5608 /****************************************************************************/
5610 /* Routine Name: ips_issue_copperhead_memio */
5612 /* Routine Description: */
5614 /* Send a command down to the controller */
5616 /****************************************************************************/
5618 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5623 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5625 if (scb->scsi_cmd) {
5626 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5630 scb->cmd.basic_io.command_id,
5631 scb->bus, scb->target_id, scb->lun);
5633 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5634 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5639 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5642 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5643 if (!(val & IPS_BIT_START_STOP))
5646 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5647 "ips_issue val [0x%x].\n", val);
5648 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5649 "ips_issue semaphore chk timeout.\n");
5651 return (IPS_FAILURE);
5655 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5656 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5658 return (IPS_SUCCESS);
5661 /****************************************************************************/
5663 /* Routine Name: ips_issue_i2o */
5665 /* Routine Description: */
5667 /* Send a command down to the controller */
5669 /****************************************************************************/
5671 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5674 METHOD_TRACE("ips_issue_i2o", 1);
5676 if (scb->scsi_cmd) {
5677 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5681 scb->cmd.basic_io.command_id,
5682 scb->bus, scb->target_id, scb->lun);
5684 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5685 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5688 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
5690 return (IPS_SUCCESS);
5693 /****************************************************************************/
5695 /* Routine Name: ips_issue_i2o_memio */
5697 /* Routine Description: */
5699 /* Send a command down to the controller */
5701 /****************************************************************************/
5703 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5706 METHOD_TRACE("ips_issue_i2o_memio", 1);
5708 if (scb->scsi_cmd) {
5709 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5713 scb->cmd.basic_io.command_id,
5714 scb->bus, scb->target_id, scb->lun);
5716 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5717 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5720 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5722 return (IPS_SUCCESS);
5725 /****************************************************************************/
5727 /* Routine Name: ips_isintr_copperhead */
5729 /* Routine Description: */
5731 /* Test to see if an interrupt is for us */
5733 /****************************************************************************/
5735 ips_isintr_copperhead(ips_ha_t * ha)
5739 METHOD_TRACE("ips_isintr_copperhead", 2);
5741 Isr = inb(ha->io_addr + IPS_REG_HISR);
5744 /* ?!?! Nothing really there */
5747 if (Isr & IPS_BIT_SCE)
5749 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5750 /* status queue overflow or GHI */
5751 /* just clear the interrupt */
5752 outb(Isr, ha->io_addr + IPS_REG_HISR);
5758 /****************************************************************************/
5760 /* Routine Name: ips_isintr_copperhead_memio */
5762 /* Routine Description: */
5764 /* Test to see if an interrupt is for us */
5766 /****************************************************************************/
5768 ips_isintr_copperhead_memio(ips_ha_t * ha)
5772 METHOD_TRACE("ips_isintr_memio", 2);
5774 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5777 /* ?!?! Nothing really there */
5780 if (Isr & IPS_BIT_SCE)
5782 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5783 /* status queue overflow or GHI */
5784 /* just clear the interrupt */
5785 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5791 /****************************************************************************/
5793 /* Routine Name: ips_isintr_morpheus */
5795 /* Routine Description: */
5797 /* Test to see if an interrupt is for us */
5799 /****************************************************************************/
5801 ips_isintr_morpheus(ips_ha_t * ha)
5805 METHOD_TRACE("ips_isintr_morpheus", 2);
5807 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5809 if (Isr & IPS_BIT_I2O_OPQI)
5815 /****************************************************************************/
5817 /* Routine Name: ips_wait */
5819 /* Routine Description: */
5821 /* Wait for a command to complete */
5823 /****************************************************************************/
5825 ips_wait(ips_ha_t * ha, int time, int intr)
5830 METHOD_TRACE("ips_wait", 1);
5835 time *= IPS_ONE_SEC; /* convert seconds */
5837 while ((time > 0) && (!done)) {
5838 if (intr == IPS_INTR_ON) {
5839 if (ha->waitflag == FALSE) {
5844 } else if (intr == IPS_INTR_IORL) {
5845 if (ha->waitflag == FALSE) {
5847 * controller generated an interrupt to
5848 * acknowledge completion of the command
5849 * and ips_intr() has serviced the interrupt.
5857 * NOTE: we already have the io_request_lock so
5858 * even if we get an interrupt it won't get serviced
5859 * until after we finish.
5862 (*ha->func.intr) (ha);
5865 /* This looks like a very evil loop, but it only does this during start-up */
5873 /****************************************************************************/
5875 /* Routine Name: ips_write_driver_status */
5877 /* Routine Description: */
5879 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5881 /****************************************************************************/
5883 ips_write_driver_status(ips_ha_t * ha, int intr)
5885 METHOD_TRACE("ips_write_driver_status", 1);
5887 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5888 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5889 "unable to read NVRAM page 5.\n");
5894 /* check to make sure the page has a valid */
5896 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5898 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5899 ips_name, ha->host_num, ha->nvram->signature);
5900 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5904 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5905 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5906 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5907 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5908 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5909 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5910 ha->nvram->bios_low[3]);
5912 ips_get_bios_version(ha, intr);
5914 /* change values (as needed) */
5915 ha->nvram->operating_system = IPS_OS_LINUX;
5916 ha->nvram->adapter_type = ha->ad_type;
5917 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5918 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5919 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5920 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5922 ha->nvram->versioning = 0; /* Indicate the Driver Does Not Support Versioning */
5924 /* now update the page */
5925 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5926 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5927 "unable to write NVRAM page 5.\n");
5932 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5933 ha->slot_num = ha->nvram->adapter_slot;
5938 /****************************************************************************/
5940 /* Routine Name: ips_read_adapter_status */
5942 /* Routine Description: */
5944 /* Do an Inquiry command to the adapter */
5946 /****************************************************************************/
5948 ips_read_adapter_status(ips_ha_t * ha, int intr)
5953 METHOD_TRACE("ips_read_adapter_status", 1);
5955 scb = &ha->scbs[ha->max_cmds - 1];
5957 ips_init_scb(ha, scb);
5959 scb->timeout = ips_cmd_timeout;
5960 scb->cdb[0] = IPS_CMD_ENQUIRY;
5962 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5963 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5964 scb->cmd.basic_io.sg_count = 0;
5965 scb->cmd.basic_io.lba = 0;
5966 scb->cmd.basic_io.sector_count = 0;
5967 scb->cmd.basic_io.log_drv = 0;
5968 scb->data_len = sizeof (*ha->enq);
5969 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5973 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5974 || (ret == IPS_SUCCESS_IMM)
5975 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5981 /****************************************************************************/
5983 /* Routine Name: ips_read_subsystem_parameters */
5985 /* Routine Description: */
5987 /* Read subsystem parameters from the adapter */
5989 /****************************************************************************/
5991 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
5996 METHOD_TRACE("ips_read_subsystem_parameters", 1);
5998 scb = &ha->scbs[ha->max_cmds - 1];
6000 ips_init_scb(ha, scb);
6002 scb->timeout = ips_cmd_timeout;
6003 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
6005 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
6006 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
6007 scb->cmd.basic_io.sg_count = 0;
6008 scb->cmd.basic_io.lba = 0;
6009 scb->cmd.basic_io.sector_count = 0;
6010 scb->cmd.basic_io.log_drv = 0;
6011 scb->data_len = sizeof (*ha->subsys);
6012 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
6016 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6017 || (ret == IPS_SUCCESS_IMM)
6018 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6021 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
6025 /****************************************************************************/
6027 /* Routine Name: ips_read_config */
6029 /* Routine Description: */
6031 /* Read the configuration on the adapter */
6033 /****************************************************************************/
6035 ips_read_config(ips_ha_t * ha, int intr)
6041 METHOD_TRACE("ips_read_config", 1);
6043 /* set defaults for initiator IDs */
6044 for (i = 0; i < 4; i++)
6045 ha->conf->init_id[i] = 7;
6047 scb = &ha->scbs[ha->max_cmds - 1];
6049 ips_init_scb(ha, scb);
6051 scb->timeout = ips_cmd_timeout;
6052 scb->cdb[0] = IPS_CMD_READ_CONF;
6054 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
6055 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
6056 scb->data_len = sizeof (*ha->conf);
6057 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
6061 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6062 || (ret == IPS_SUCCESS_IMM)
6063 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6065 memset(ha->conf, 0, sizeof (IPS_CONF));
6067 /* reset initiator IDs */
6068 for (i = 0; i < 4; i++)
6069 ha->conf->init_id[i] = 7;
6071 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
6072 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
6073 IPS_CMD_CMPLT_WERROR)
6079 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
6083 /****************************************************************************/
6085 /* Routine Name: ips_readwrite_page5 */
6087 /* Routine Description: */
6089 /* Read nvram page 5 from the adapter */
6091 /****************************************************************************/
6093 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
6098 METHOD_TRACE("ips_readwrite_page5", 1);
6100 scb = &ha->scbs[ha->max_cmds - 1];
6102 ips_init_scb(ha, scb);
6104 scb->timeout = ips_cmd_timeout;
6105 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
6107 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
6108 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
6109 scb->cmd.nvram.page = 5;
6110 scb->cmd.nvram.write = write;
6111 scb->cmd.nvram.reserved = 0;
6112 scb->cmd.nvram.reserved2 = 0;
6113 scb->data_len = sizeof (*ha->nvram);
6114 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
6116 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
6118 /* issue the command */
6120 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6121 || (ret == IPS_SUCCESS_IMM)
6122 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6124 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
6129 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
6133 /****************************************************************************/
6135 /* Routine Name: ips_clear_adapter */
6137 /* Routine Description: */
6139 /* Clear the stripe lock tables */
6141 /****************************************************************************/
6143 ips_clear_adapter(ips_ha_t * ha, int intr)
6148 METHOD_TRACE("ips_clear_adapter", 1);
6150 scb = &ha->scbs[ha->max_cmds - 1];
6152 ips_init_scb(ha, scb);
6154 scb->timeout = ips_reset_timeout;
6155 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
6157 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
6158 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
6159 scb->cmd.config_sync.channel = 0;
6160 scb->cmd.config_sync.source_target = IPS_POCL;
6161 scb->cmd.config_sync.reserved = 0;
6162 scb->cmd.config_sync.reserved2 = 0;
6163 scb->cmd.config_sync.reserved3 = 0;
6167 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
6168 || (ret == IPS_SUCCESS_IMM)
6169 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6172 /* send unlock stripe command */
6173 ips_init_scb(ha, scb);
6175 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
6176 scb->timeout = ips_reset_timeout;
6178 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
6179 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
6180 scb->cmd.unlock_stripe.log_drv = 0;
6181 scb->cmd.unlock_stripe.control = IPS_CSL;
6182 scb->cmd.unlock_stripe.reserved = 0;
6183 scb->cmd.unlock_stripe.reserved2 = 0;
6184 scb->cmd.unlock_stripe.reserved3 = 0;
6188 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6189 || (ret == IPS_SUCCESS_IMM)
6190 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6196 /****************************************************************************/
6198 /* Routine Name: ips_ffdc_reset */
6200 /* Routine Description: */
6202 /* FFDC: write reset info */
6204 /****************************************************************************/
6206 ips_ffdc_reset(ips_ha_t * ha, int intr)
6210 METHOD_TRACE("ips_ffdc_reset", 1);
6212 scb = &ha->scbs[ha->max_cmds - 1];
6214 ips_init_scb(ha, scb);
6216 scb->timeout = ips_cmd_timeout;
6217 scb->cdb[0] = IPS_CMD_FFDC;
6218 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6219 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6220 scb->cmd.ffdc.reset_count = ha->reset_count;
6221 scb->cmd.ffdc.reset_type = 0x80;
6223 /* convert time to what the card wants */
6224 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6227 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6230 /****************************************************************************/
6232 /* Routine Name: ips_ffdc_time */
6234 /* Routine Description: */
6236 /* FFDC: write time info */
6238 /****************************************************************************/
6240 ips_ffdc_time(ips_ha_t * ha)
6244 METHOD_TRACE("ips_ffdc_time", 1);
6246 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
6248 scb = &ha->scbs[ha->max_cmds - 1];
6250 ips_init_scb(ha, scb);
6252 scb->timeout = ips_cmd_timeout;
6253 scb->cdb[0] = IPS_CMD_FFDC;
6254 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6255 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6256 scb->cmd.ffdc.reset_count = 0;
6257 scb->cmd.ffdc.reset_type = 0;
6259 /* convert time to what the card wants */
6260 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6263 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
6266 /****************************************************************************/
6268 /* Routine Name: ips_fix_ffdc_time */
6270 /* Routine Description: */
6271 /* Adjust time_t to what the card wants */
6273 /****************************************************************************/
6275 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6282 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6283 int month_lengths[12][2] = { {31, 31},
6297 METHOD_TRACE("ips_fix_ffdc_time", 1);
6299 days = current_time / IPS_SECS_DAY;
6300 rem = current_time % IPS_SECS_DAY;
6302 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6303 rem = rem % IPS_SECS_HOUR;
6304 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6305 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6307 year = IPS_EPOCH_YEAR;
6308 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6311 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6314 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6315 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6316 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6320 scb->cmd.ffdc.yearH = year / 100;
6321 scb->cmd.ffdc.yearL = year % 100;
6323 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6324 days -= month_lengths[i][yleap];
6326 scb->cmd.ffdc.month = i + 1;
6327 scb->cmd.ffdc.day = days + 1;
6330 /****************************************************************************
6331 * BIOS Flash Routines *
6332 ****************************************************************************/
6334 /****************************************************************************/
6336 /* Routine Name: ips_erase_bios */
6338 /* Routine Description: */
6339 /* Erase the BIOS on the adapter */
6341 /****************************************************************************/
6343 ips_erase_bios(ips_ha_t * ha)
6348 METHOD_TRACE("ips_erase_bios", 1);
6352 /* Clear the status register */
6353 outl(0, ha->io_addr + IPS_REG_FLAP);
6354 if (ha->revision_id == IPS_REVID_TROMBONE64)
6355 udelay(25); /* 25 us */
6357 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6358 if (ha->revision_id == IPS_REVID_TROMBONE64)
6359 udelay(25); /* 25 us */
6362 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6363 if (ha->revision_id == IPS_REVID_TROMBONE64)
6364 udelay(25); /* 25 us */
6367 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6368 if (ha->revision_id == IPS_REVID_TROMBONE64)
6369 udelay(25); /* 25 us */
6372 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6373 if (ha->revision_id == IPS_REVID_TROMBONE64)
6374 udelay(25); /* 25 us */
6376 timeout = 80000; /* 80 seconds */
6378 while (timeout > 0) {
6379 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6380 outl(0, ha->io_addr + IPS_REG_FLAP);
6381 udelay(25); /* 25 us */
6384 status = inb(ha->io_addr + IPS_REG_FLDP);
6393 /* check for timeout */
6397 /* try to suspend the erase */
6398 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6399 if (ha->revision_id == IPS_REVID_TROMBONE64)
6400 udelay(25); /* 25 us */
6402 /* wait for 10 seconds */
6404 while (timeout > 0) {
6405 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6406 outl(0, ha->io_addr + IPS_REG_FLAP);
6407 udelay(25); /* 25 us */
6410 status = inb(ha->io_addr + IPS_REG_FLDP);
6422 /* check for valid VPP */
6427 /* check for successful flash */
6429 /* sequence error */
6432 /* Otherwise, we were successful */
6434 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6435 if (ha->revision_id == IPS_REVID_TROMBONE64)
6436 udelay(25); /* 25 us */
6439 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6440 if (ha->revision_id == IPS_REVID_TROMBONE64)
6441 udelay(25); /* 25 us */
6446 /****************************************************************************/
6448 /* Routine Name: ips_erase_bios_memio */
6450 /* Routine Description: */
6451 /* Erase the BIOS on the adapter */
6453 /****************************************************************************/
6455 ips_erase_bios_memio(ips_ha_t * ha)
6460 METHOD_TRACE("ips_erase_bios_memio", 1);
6464 /* Clear the status register */
6465 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6466 if (ha->revision_id == IPS_REVID_TROMBONE64)
6467 udelay(25); /* 25 us */
6469 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6470 if (ha->revision_id == IPS_REVID_TROMBONE64)
6471 udelay(25); /* 25 us */
6474 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6475 if (ha->revision_id == IPS_REVID_TROMBONE64)
6476 udelay(25); /* 25 us */
6479 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6480 if (ha->revision_id == IPS_REVID_TROMBONE64)
6481 udelay(25); /* 25 us */
6484 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6485 if (ha->revision_id == IPS_REVID_TROMBONE64)
6486 udelay(25); /* 25 us */
6488 timeout = 80000; /* 80 seconds */
6490 while (timeout > 0) {
6491 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6492 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6493 udelay(25); /* 25 us */
6496 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6505 /* check for timeout */
6509 /* try to suspend the erase */
6510 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6511 if (ha->revision_id == IPS_REVID_TROMBONE64)
6512 udelay(25); /* 25 us */
6514 /* wait for 10 seconds */
6516 while (timeout > 0) {
6517 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6518 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6519 udelay(25); /* 25 us */
6522 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6534 /* check for valid VPP */
6539 /* check for successful flash */
6541 /* sequence error */
6544 /* Otherwise, we were successful */
6546 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6547 if (ha->revision_id == IPS_REVID_TROMBONE64)
6548 udelay(25); /* 25 us */
6551 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6552 if (ha->revision_id == IPS_REVID_TROMBONE64)
6553 udelay(25); /* 25 us */
6558 /****************************************************************************/
6560 /* Routine Name: ips_program_bios */
6562 /* Routine Description: */
6563 /* Program the BIOS on the adapter */
6565 /****************************************************************************/
6567 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6574 METHOD_TRACE("ips_program_bios", 1);
6578 for (i = 0; i < buffersize; i++) {
6580 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6581 if (ha->revision_id == IPS_REVID_TROMBONE64)
6582 udelay(25); /* 25 us */
6584 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6585 if (ha->revision_id == IPS_REVID_TROMBONE64)
6586 udelay(25); /* 25 us */
6588 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6589 if (ha->revision_id == IPS_REVID_TROMBONE64)
6590 udelay(25); /* 25 us */
6592 /* wait up to one second */
6594 while (timeout > 0) {
6595 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6596 outl(0, ha->io_addr + IPS_REG_FLAP);
6597 udelay(25); /* 25 us */
6600 status = inb(ha->io_addr + IPS_REG_FLDP);
6611 outl(0, ha->io_addr + IPS_REG_FLAP);
6612 if (ha->revision_id == IPS_REVID_TROMBONE64)
6613 udelay(25); /* 25 us */
6615 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6616 if (ha->revision_id == IPS_REVID_TROMBONE64)
6617 udelay(25); /* 25 us */
6622 /* check the status */
6623 if (status & 0x18) {
6624 /* programming error */
6625 outl(0, ha->io_addr + IPS_REG_FLAP);
6626 if (ha->revision_id == IPS_REVID_TROMBONE64)
6627 udelay(25); /* 25 us */
6629 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6630 if (ha->revision_id == IPS_REVID_TROMBONE64)
6631 udelay(25); /* 25 us */
6637 /* Enable reading */
6638 outl(0, ha->io_addr + IPS_REG_FLAP);
6639 if (ha->revision_id == IPS_REVID_TROMBONE64)
6640 udelay(25); /* 25 us */
6642 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6643 if (ha->revision_id == IPS_REVID_TROMBONE64)
6644 udelay(25); /* 25 us */
6649 /****************************************************************************/
6651 /* Routine Name: ips_program_bios_memio */
6653 /* Routine Description: */
6654 /* Program the BIOS on the adapter */
6656 /****************************************************************************/
6658 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6665 METHOD_TRACE("ips_program_bios_memio", 1);
6669 for (i = 0; i < buffersize; i++) {
6671 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6672 if (ha->revision_id == IPS_REVID_TROMBONE64)
6673 udelay(25); /* 25 us */
6675 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6676 if (ha->revision_id == IPS_REVID_TROMBONE64)
6677 udelay(25); /* 25 us */
6679 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6680 if (ha->revision_id == IPS_REVID_TROMBONE64)
6681 udelay(25); /* 25 us */
6683 /* wait up to one second */
6685 while (timeout > 0) {
6686 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6687 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6688 udelay(25); /* 25 us */
6691 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6702 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6703 if (ha->revision_id == IPS_REVID_TROMBONE64)
6704 udelay(25); /* 25 us */
6706 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6707 if (ha->revision_id == IPS_REVID_TROMBONE64)
6708 udelay(25); /* 25 us */
6713 /* check the status */
6714 if (status & 0x18) {
6715 /* programming error */
6716 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6717 if (ha->revision_id == IPS_REVID_TROMBONE64)
6718 udelay(25); /* 25 us */
6720 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6721 if (ha->revision_id == IPS_REVID_TROMBONE64)
6722 udelay(25); /* 25 us */
6728 /* Enable reading */
6729 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6730 if (ha->revision_id == IPS_REVID_TROMBONE64)
6731 udelay(25); /* 25 us */
6733 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6734 if (ha->revision_id == IPS_REVID_TROMBONE64)
6735 udelay(25); /* 25 us */
6740 /****************************************************************************/
6742 /* Routine Name: ips_verify_bios */
6744 /* Routine Description: */
6745 /* Verify the BIOS on the adapter */
6747 /****************************************************************************/
6749 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6755 METHOD_TRACE("ips_verify_bios", 1);
6758 outl(0, ha->io_addr + IPS_REG_FLAP);
6759 if (ha->revision_id == IPS_REVID_TROMBONE64)
6760 udelay(25); /* 25 us */
6762 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6765 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
6766 if (ha->revision_id == IPS_REVID_TROMBONE64)
6767 udelay(25); /* 25 us */
6768 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6772 for (i = 2; i < buffersize; i++) {
6774 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6775 if (ha->revision_id == IPS_REVID_TROMBONE64)
6776 udelay(25); /* 25 us */
6778 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6789 /****************************************************************************/
6791 /* Routine Name: ips_verify_bios_memio */
6793 /* Routine Description: */
6794 /* Verify the BIOS on the adapter */
6796 /****************************************************************************/
6798 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6804 METHOD_TRACE("ips_verify_bios_memio", 1);
6807 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6808 if (ha->revision_id == IPS_REVID_TROMBONE64)
6809 udelay(25); /* 25 us */
6811 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6814 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6815 if (ha->revision_id == IPS_REVID_TROMBONE64)
6816 udelay(25); /* 25 us */
6817 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6821 for (i = 2; i < buffersize; i++) {
6823 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6824 if (ha->revision_id == IPS_REVID_TROMBONE64)
6825 udelay(25); /* 25 us */
6828 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6839 /****************************************************************************/
6841 /* Routine Name: ips_abort_init */
6843 /* Routine Description: */
6844 /* cleanup routine for a failed adapter initialization */
6845 /****************************************************************************/
6847 ips_abort_init(ips_ha_t * ha, int index)
6851 ips_ha[index] = NULL;
6852 ips_sh[index] = NULL;
6856 /****************************************************************************/
6858 /* Routine Name: ips_shift_controllers */
6860 /* Routine Description: */
6861 /* helper function for ordering adapters */
6862 /****************************************************************************/
6864 ips_shift_controllers(int lowindex, int highindex)
6866 ips_ha_t *ha_sav = ips_ha[highindex];
6867 struct Scsi_Host *sh_sav = ips_sh[highindex];
6870 for (i = highindex; i > lowindex; i--) {
6871 ips_ha[i] = ips_ha[i - 1];
6872 ips_sh[i] = ips_sh[i - 1];
6873 ips_ha[i]->host_num = i;
6875 ha_sav->host_num = lowindex;
6876 ips_ha[lowindex] = ha_sav;
6877 ips_sh[lowindex] = sh_sav;
6880 /****************************************************************************/
6882 /* Routine Name: ips_order_controllers */
6884 /* Routine Description: */
6885 /* place controllers is the "proper" boot order */
6886 /****************************************************************************/
6888 ips_order_controllers(void)
6890 int i, j, tmp, position = 0;
6891 IPS_NVRAM_P5 *nvram;
6894 nvram = ips_ha[0]->nvram;
6896 if (nvram->adapter_order[0]) {
6897 for (i = 1; i <= nvram->adapter_order[0]; i++) {
6898 for (j = position; j < ips_num_controllers; j++) {
6899 switch (ips_ha[j]->ad_type) {
6900 case IPS_ADTYPE_SERVERAID6M:
6901 case IPS_ADTYPE_SERVERAID7M:
6902 if (nvram->adapter_order[i] == 'M') {
6903 ips_shift_controllers(position,
6908 case IPS_ADTYPE_SERVERAID4L:
6909 case IPS_ADTYPE_SERVERAID4M:
6910 case IPS_ADTYPE_SERVERAID4MX:
6911 case IPS_ADTYPE_SERVERAID4LX:
6912 if (nvram->adapter_order[i] == 'N') {
6913 ips_shift_controllers(position,
6918 case IPS_ADTYPE_SERVERAID6I:
6919 case IPS_ADTYPE_SERVERAID5I2:
6920 case IPS_ADTYPE_SERVERAID5I1:
6921 case IPS_ADTYPE_SERVERAID7k:
6922 if (nvram->adapter_order[i] == 'S') {
6923 ips_shift_controllers(position,
6928 case IPS_ADTYPE_SERVERAID:
6929 case IPS_ADTYPE_SERVERAID2:
6930 case IPS_ADTYPE_NAVAJO:
6931 case IPS_ADTYPE_KIOWA:
6932 case IPS_ADTYPE_SERVERAID3L:
6933 case IPS_ADTYPE_SERVERAID3:
6934 case IPS_ADTYPE_SERVERAID4H:
6935 if (nvram->adapter_order[i] == 'A') {
6936 ips_shift_controllers(position,
6946 /* if adapter_order[0], then ordering is complete */
6949 /* old bios, use older ordering */
6951 for (i = position; i < ips_num_controllers; i++) {
6952 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I2 ||
6953 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I1) {
6954 ips_shift_controllers(position, i);
6959 /* if there were no 5I cards, then don't do any extra ordering */
6962 for (i = position; i < ips_num_controllers; i++) {
6963 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4L ||
6964 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4M ||
6965 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4LX ||
6966 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4MX) {
6967 ips_shift_controllers(position, i);
6975 /****************************************************************************/
6977 /* Routine Name: ips_register_scsi */
6979 /* Routine Description: */
6980 /* perform any registration and setup with the scsi layer */
6981 /****************************************************************************/
6983 ips_register_scsi(int index)
6985 struct Scsi_Host *sh;
6986 ips_ha_t *ha, *oldha = ips_ha[index];
6987 sh = scsi_host_alloc(&ips_driver_template, sizeof (ips_ha_t));
6989 IPS_PRINTK(KERN_WARNING, oldha->pcidev,
6990 "Unable to register controller with SCSI subsystem\n");
6994 memcpy(ha, oldha, sizeof (ips_ha_t));
6995 free_irq(oldha->irq, oldha);
6996 /* Install the interrupt handler with the new ha */
6997 if (request_irq(ha->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
6998 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6999 "Unable to install interrupt handler\n");
7007 IPS_SCSI_SET_DEVICE(sh, ha);
7009 /* Store away needed values for later use */
7010 sh->io_port = ha->io_addr;
7011 sh->n_io_port = ha->io_addr ? 255 : 0;
7012 sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
7014 sh->sg_tablesize = sh->hostt->sg_tablesize;
7015 sh->can_queue = sh->hostt->can_queue;
7016 sh->cmd_per_lun = sh->hostt->cmd_per_lun;
7017 sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
7018 sh->use_clustering = sh->hostt->use_clustering;
7020 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
7021 sh->max_sectors = 128;
7024 sh->max_id = ha->ntargets;
7025 sh->max_lun = ha->nlun;
7026 sh->max_channel = ha->nbus - 1;
7027 sh->can_queue = ha->max_cmds - 1;
7029 IPS_ADD_HOST(sh, NULL);
7033 /*---------------------------------------------------------------------------*/
7034 /* Routine Name: ips_remove_device */
7036 /* Routine Description: */
7037 /* Remove one Adapter ( Hot Plugging ) */
7038 /*---------------------------------------------------------------------------*/
7039 static void __devexit
7040 ips_remove_device(struct pci_dev *pci_dev)
7043 struct Scsi_Host *sh;
7046 for (i = 0; i < IPS_MAX_ADAPTERS; i++) {
7049 if ((pci_dev->bus->number == ha->pcidev->bus->number) &&
7050 (pci_dev->devfn == ha->pcidev->devfn)) {
7058 /****************************************************************************/
7060 /* Routine Name: ips_module_init */
7062 /* Routine Description: */
7063 /* function called on module load */
7064 /****************************************************************************/
7066 ips_module_init(void)
7068 if (pci_register_driver(&ips_pci_driver) < 0)
7070 ips_driver_template.module = THIS_MODULE;
7071 ips_order_controllers();
7072 if (IPS_REGISTER_HOSTS(&ips_driver_template)) {
7073 pci_unregister_driver(&ips_pci_driver);
7076 register_reboot_notifier(&ips_notifier);
7080 /****************************************************************************/
7082 /* Routine Name: ips_module_exit */
7084 /* Routine Description: */
7085 /* function called on module unload */
7086 /****************************************************************************/
7088 ips_module_exit(void)
7090 IPS_UNREGISTER_HOSTS(&ips_driver_template);
7091 pci_unregister_driver(&ips_pci_driver);
7092 unregister_reboot_notifier(&ips_notifier);
7095 module_init(ips_module_init);
7096 module_exit(ips_module_exit);
7098 /*---------------------------------------------------------------------------*/
7099 /* Routine Name: ips_insert_device */
7101 /* Routine Description: */
7102 /* Add One Adapter ( Hot Plug ) */
7105 /* 0 if Successful, else non-zero */
7106 /*---------------------------------------------------------------------------*/
7107 static int __devinit
7108 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
7113 METHOD_TRACE("ips_insert_device", 1);
7114 if (pci_enable_device(pci_dev))
7117 rc = ips_init_phase1(pci_dev, &index);
7119 rc = ips_init_phase2(index);
7122 if (ips_register_scsi(index)) {
7123 ips_free(ips_ha[index]);
7128 ips_num_controllers++;
7130 ips_next_controller = ips_num_controllers;
7134 /*---------------------------------------------------------------------------*/
7135 /* Routine Name: ips_init_phase1 */
7137 /* Routine Description: */
7138 /* Adapter Initialization */
7141 /* 0 if Successful, else non-zero */
7142 /*---------------------------------------------------------------------------*/
7144 ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
7151 uint8_t revision_id;
7155 uint16_t subdevice_id;
7158 dma_addr_t dma_address;
7159 char __iomem *ioremap_ptr;
7160 char __iomem *mem_ptr;
7163 METHOD_TRACE("ips_init_phase1", 1);
7164 index = IPS_MAX_ADAPTERS;
7165 for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
7166 if (ips_ha[j] == 0) {
7172 if (index >= IPS_MAX_ADAPTERS)
7175 /* stuff that we get in dev */
7177 bus = pci_dev->bus->number;
7178 func = pci_dev->devfn;
7180 /* Init MEM/IO addresses to 0 */
7186 for (j = 0; j < 2; j++) {
7187 if (!pci_resource_start(pci_dev, j))
7190 if (pci_resource_flags(pci_dev, j) & IORESOURCE_IO) {
7191 io_addr = pci_resource_start(pci_dev, j);
7192 io_len = pci_resource_len(pci_dev, j);
7194 mem_addr = pci_resource_start(pci_dev, j);
7195 mem_len = pci_resource_len(pci_dev, j);
7199 /* setup memory mapped area (if applicable) */
7204 if (!request_mem_region(mem_addr, mem_len, "ips")) {
7205 IPS_PRINTK(KERN_WARNING, pci_dev,
7206 "Couldn't allocate IO Memory space %x len %d.\n",
7211 base = mem_addr & PAGE_MASK;
7212 offs = mem_addr - base;
7213 ioremap_ptr = ioremap(base, PAGE_SIZE);
7214 mem_ptr = ioremap_ptr + offs;
7220 /* setup I/O mapped area (if applicable) */
7222 if (!request_region(io_addr, io_len, "ips")) {
7223 IPS_PRINTK(KERN_WARNING, pci_dev,
7224 "Couldn't allocate IO space %x len %d.\n",
7230 /* get the revision ID */
7231 if (pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id)) {
7232 IPS_PRINTK(KERN_WARNING, pci_dev, "Can't get revision id.\n");
7236 subdevice_id = pci_dev->subsystem_device;
7238 /* found a controller */
7239 ha = kmalloc(sizeof (ips_ha_t), GFP_KERNEL);
7241 IPS_PRINTK(KERN_WARNING, pci_dev,
7242 "Unable to allocate temporary ha struct\n");
7246 memset(ha, 0, sizeof (ips_ha_t));
7248 ips_sh[index] = NULL;
7252 /* Store info in HA structure */
7254 ha->io_addr = io_addr;
7255 ha->io_len = io_len;
7256 ha->mem_addr = mem_addr;
7257 ha->mem_len = mem_len;
7258 ha->mem_ptr = mem_ptr;
7259 ha->ioremap_ptr = ioremap_ptr;
7260 ha->host_num = (uint32_t) index;
7261 ha->revision_id = revision_id;
7262 ha->slot_num = PCI_SLOT(pci_dev->devfn);
7263 ha->device_id = pci_dev->device;
7264 ha->subdevice_id = subdevice_id;
7265 ha->pcidev = pci_dev;
7268 * Set the pci_dev's dma_mask. Not all adapters support 64bit
7269 * addressing so don't enable it if the adapter can't support
7270 * it! Also, don't use 64bit addressing if dma addresses
7271 * are guaranteed to be < 4G.
7273 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
7274 !pci_set_dma_mask(ha->pcidev, DMA_64BIT_MASK)) {
7275 (ha)->flags |= IPS_HA_ENH_SG;
7277 if (pci_set_dma_mask(ha->pcidev, DMA_32BIT_MASK) != 0) {
7278 printk(KERN_WARNING "Unable to set DMA Mask\n");
7279 return ips_abort_init(ha, index);
7282 if(ips_cd_boot && !ips_FlashData){
7283 ips_FlashData = pci_alloc_consistent(pci_dev, PAGE_SIZE << 7,
7287 ha->enq = pci_alloc_consistent(pci_dev, sizeof (IPS_ENQ),
7290 IPS_PRINTK(KERN_WARNING, pci_dev,
7291 "Unable to allocate host inquiry structure\n");
7292 return ips_abort_init(ha, index);
7295 ha->adapt = pci_alloc_consistent(pci_dev, sizeof (IPS_ADAPTER) +
7296 sizeof (IPS_IO_CMD), &dma_address);
7298 IPS_PRINTK(KERN_WARNING, pci_dev,
7299 "Unable to allocate host adapt & dummy structures\n");
7300 return ips_abort_init(ha, index);
7302 ha->adapt->hw_status_start = dma_address;
7303 ha->dummy = (void *) (ha->adapt + 1);
7307 ha->logical_drive_info = pci_alloc_consistent(pci_dev, sizeof (IPS_LD_INFO), &dma_address);
7308 if (!ha->logical_drive_info) {
7309 IPS_PRINTK(KERN_WARNING, pci_dev,
7310 "Unable to allocate logical drive info structure\n");
7311 return ips_abort_init(ha, index);
7313 ha->logical_drive_info_dma_addr = dma_address;
7316 ha->conf = kmalloc(sizeof (IPS_CONF), GFP_KERNEL);
7319 IPS_PRINTK(KERN_WARNING, pci_dev,
7320 "Unable to allocate host conf structure\n");
7321 return ips_abort_init(ha, index);
7324 ha->nvram = kmalloc(sizeof (IPS_NVRAM_P5), GFP_KERNEL);
7327 IPS_PRINTK(KERN_WARNING, pci_dev,
7328 "Unable to allocate host NVRAM structure\n");
7329 return ips_abort_init(ha, index);
7332 ha->subsys = kmalloc(sizeof (IPS_SUBSYS), GFP_KERNEL);
7335 IPS_PRINTK(KERN_WARNING, pci_dev,
7336 "Unable to allocate host subsystem structure\n");
7337 return ips_abort_init(ha, index);
7340 /* the ioctl buffer is now used during adapter initialization, so its
7341 * successful allocation is now required */
7342 if (ips_ioctlsize < PAGE_SIZE)
7343 ips_ioctlsize = PAGE_SIZE;
7345 ha->ioctl_data = pci_alloc_consistent(pci_dev, ips_ioctlsize,
7346 &ha->ioctl_busaddr);
7347 ha->ioctl_len = ips_ioctlsize;
7348 if (!ha->ioctl_data) {
7349 IPS_PRINTK(KERN_WARNING, pci_dev,
7350 "Unable to allocate IOCTL data\n");
7351 return ips_abort_init(ha, index);
7357 ips_setup_funclist(ha);
7359 if ((IPS_IS_MORPHEUS(ha)) || (IPS_IS_MARCO(ha))) {
7360 /* If Morpheus appears dead, reset it */
7361 IsDead = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
7362 if (IsDead == 0xDEADBEEF) {
7363 ips_reset_morpheus(ha);
7368 * Initialize the card if it isn't already
7371 if (!(*ha->func.isinit) (ha)) {
7372 if (!(*ha->func.init) (ha)) {
7374 * Initialization failed
7376 IPS_PRINTK(KERN_WARNING, pci_dev,
7377 "Unable to initialize controller\n");
7378 return ips_abort_init(ha, index);
7386 /*---------------------------------------------------------------------------*/
7387 /* Routine Name: ips_init_phase2 */
7389 /* Routine Description: */
7390 /* Adapter Initialization Phase 2 */
7393 /* 0 if Successful, else non-zero */
7394 /*---------------------------------------------------------------------------*/
7396 ips_init_phase2(int index)
7402 METHOD_TRACE("ips_init_phase2", 1);
7404 ips_ha[index] = NULL;
7408 /* Install the interrupt handler */
7409 if (request_irq(ha->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
7410 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7411 "Unable to install interrupt handler\n");
7412 return ips_abort_init(ha, index);
7416 * Allocate a temporary SCB for initialization
7419 if (!ips_allocatescbs(ha)) {
7420 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7421 "Unable to allocate a CCB\n");
7422 free_irq(ha->irq, ha);
7423 return ips_abort_init(ha, index);
7426 if (!ips_hainit(ha)) {
7427 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7428 "Unable to initialize controller\n");
7429 free_irq(ha->irq, ha);
7430 return ips_abort_init(ha, index);
7432 /* Free the temporary SCB */
7433 ips_deallocatescbs(ha, 1);
7436 if (!ips_allocatescbs(ha)) {
7437 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7438 "Unable to allocate CCBs\n");
7439 free_irq(ha->irq, ha);
7440 return ips_abort_init(ha, index);
7446 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
7447 MODULE_LICENSE("GPL");
7450 MODULE_DESCRIPTION("IBM ServeRAID Adapter Driver " IPS_VER_STRING);
7452 #ifdef MODULE_VERSION
7453 MODULE_VERSION(IPS_VER_STRING);
7458 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7459 * Emacs will notice this stuff at the end of the file and automatically
7460 * adjust the settings for this buffer only. This must remain at the end
7462 * ---------------------------------------------------------------------------
7465 * c-brace-imaginary-offset: 0
7466 * c-brace-offset: -2
7467 * c-argdecl-indent: 2
7468 * c-label-offset: -2
7469 * c-continued-statement-offset: 2
7470 * c-continued-brace-offset: 0
7471 * indent-tabs-mode: nil