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>
188 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
191 #include <scsi/scsi_host.h>
196 #include <linux/module.h>
198 #include <linux/stat.h>
200 #include <linux/spinlock.h>
201 #include <linux/init.h>
203 #include <linux/smp.h>
206 static char *ips = NULL;
207 module_param(ips, charp, 0);
213 #define IPS_VERSION_HIGH "7.12"
214 #define IPS_VERSION_LOW ".05 "
216 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
217 #warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
220 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
221 #include <linux/blk.h>
223 #define IPS_LOCK_SAVE(lock,flags) spin_lock_irqsave(&io_request_lock,flags)
224 #define IPS_UNLOCK_RESTORE(lock,flags) spin_unlock_irqrestore(&io_request_lock,flags)
226 #define __devexit_p(x) x
229 #define IPS_LOCK_SAVE(lock,flags) do{spin_lock(lock);(void)flags;}while(0)
230 #define IPS_UNLOCK_RESTORE(lock,flags) do{spin_unlock(lock);(void)flags;}while(0)
233 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
234 DMA_NONE == scb->scsi_cmd->sc_data_direction) ? \
235 PCI_DMA_BIDIRECTIONAL : \
236 scb->scsi_cmd->sc_data_direction)
239 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
240 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
241 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
243 #define METHOD_TRACE(s, i)
245 #define DEBUG_VAR(i, s, v...)
249 * Function prototypes
251 static int ips_detect(struct scsi_host_template *);
252 static int ips_release(struct Scsi_Host *);
253 static int ips_eh_abort(struct scsi_cmnd *);
254 static int ips_eh_reset(struct scsi_cmnd *);
255 static int ips_queue(struct scsi_cmnd *, void (*)(struct scsi_cmnd *));
256 static const char *ips_info(struct Scsi_Host *);
257 static irqreturn_t do_ipsintr(int, void *, struct pt_regs *);
258 static int ips_hainit(ips_ha_t *);
259 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
260 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
261 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
262 static int ips_online(ips_ha_t *, ips_scb_t *);
263 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
264 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
265 static int ips_msense(ips_ha_t *, ips_scb_t *);
266 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
267 static int ips_deallocatescbs(ips_ha_t *, int);
268 static int ips_allocatescbs(ips_ha_t *);
269 static int ips_reset_copperhead(ips_ha_t *);
270 static int ips_reset_copperhead_memio(ips_ha_t *);
271 static int ips_reset_morpheus(ips_ha_t *);
272 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
273 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
274 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
275 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
276 static int ips_isintr_copperhead(ips_ha_t *);
277 static int ips_isintr_copperhead_memio(ips_ha_t *);
278 static int ips_isintr_morpheus(ips_ha_t *);
279 static int ips_wait(ips_ha_t *, int, int);
280 static int ips_write_driver_status(ips_ha_t *, int);
281 static int ips_read_adapter_status(ips_ha_t *, int);
282 static int ips_read_subsystem_parameters(ips_ha_t *, int);
283 static int ips_read_config(ips_ha_t *, int);
284 static int ips_clear_adapter(ips_ha_t *, int);
285 static int ips_readwrite_page5(ips_ha_t *, int, int);
286 static int ips_init_copperhead(ips_ha_t *);
287 static int ips_init_copperhead_memio(ips_ha_t *);
288 static int ips_init_morpheus(ips_ha_t *);
289 static int ips_isinit_copperhead(ips_ha_t *);
290 static int ips_isinit_copperhead_memio(ips_ha_t *);
291 static int ips_isinit_morpheus(ips_ha_t *);
292 static int ips_erase_bios(ips_ha_t *);
293 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
294 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
295 static int ips_erase_bios_memio(ips_ha_t *);
296 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
297 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
298 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
299 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
300 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
301 static void ips_free_flash_copperhead(ips_ha_t * ha);
302 static void ips_get_bios_version(ips_ha_t *, int);
303 static void ips_identify_controller(ips_ha_t *);
304 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
305 static void ips_enable_int_copperhead(ips_ha_t *);
306 static void ips_enable_int_copperhead_memio(ips_ha_t *);
307 static void ips_enable_int_morpheus(ips_ha_t *);
308 static int ips_intr_copperhead(ips_ha_t *);
309 static int ips_intr_morpheus(ips_ha_t *);
310 static void ips_next(ips_ha_t *, int);
311 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
312 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
313 static void ips_done(ips_ha_t *, ips_scb_t *);
314 static void ips_free(ips_ha_t *);
315 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
316 static void ips_freescb(ips_ha_t *, ips_scb_t *);
317 static void ips_setup_funclist(ips_ha_t *);
318 static void ips_statinit(ips_ha_t *);
319 static void ips_statinit_memio(ips_ha_t *);
320 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
321 static void ips_ffdc_reset(ips_ha_t *, int);
322 static void ips_ffdc_time(ips_ha_t *);
323 static uint32_t ips_statupd_copperhead(ips_ha_t *);
324 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
325 static uint32_t ips_statupd_morpheus(ips_ha_t *);
326 static ips_scb_t *ips_getscb(ips_ha_t *);
327 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
328 static void ips_putq_wait_tail(ips_wait_queue_t *, struct scsi_cmnd *);
329 static void ips_putq_copp_tail(ips_copp_queue_t *,
330 ips_copp_wait_item_t *);
331 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
332 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
333 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
334 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *,
336 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
337 ips_copp_wait_item_t *);
338 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
340 static int ips_is_passthru(struct scsi_cmnd *);
341 static int ips_make_passthru(ips_ha_t *, struct scsi_cmnd *, ips_scb_t *, int);
342 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
343 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
344 static void ips_scmd_buf_write(struct scsi_cmnd * scmd, void *data,
346 static void ips_scmd_buf_read(struct scsi_cmnd * scmd, void *data,
349 static int ips_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
350 static int ips_host_info(ips_ha_t *, char *, off_t, int);
351 static void copy_mem_info(IPS_INFOSTR *, char *, int);
352 static int copy_info(IPS_INFOSTR *, char *, ...);
353 static int ips_abort_init(ips_ha_t * ha, int index);
354 static int ips_init_phase2(int index);
356 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
357 static int ips_register_scsi(int index);
359 static int ips_poll_for_flush_complete(ips_ha_t * ha);
360 static void ips_flush_and_reset(ips_ha_t *ha);
365 static const char ips_name[] = "ips";
366 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
367 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
368 static unsigned int ips_next_controller;
369 static unsigned int ips_num_controllers;
370 static unsigned int ips_released_controllers;
371 static int ips_hotplug;
372 static int ips_cmd_timeout = 60;
373 static int ips_reset_timeout = 60 * 5;
374 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
375 static int ips_force_i2o = 1; /* Always use I2O command delivery */
376 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
377 static int ips_cd_boot; /* Booting from Manager CD */
378 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
379 static dma_addr_t ips_flashbusaddr;
380 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
381 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
382 static struct scsi_host_template ips_driver_template = {
383 .detect = ips_detect,
384 .release = ips_release,
386 .queuecommand = ips_queue,
387 .eh_abort_handler = ips_eh_abort,
388 .eh_host_reset_handler = ips_eh_reset,
390 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
391 .proc_info = ips_proc_info,
392 .slave_configure = ips_slave_configure,
394 .proc_info = ips_proc24_info,
395 .select_queue_depths = ips_select_queue_depth,
397 .bios_param = ips_biosparam,
399 .sg_tablesize = IPS_MAX_SG,
401 .use_clustering = ENABLE_CLUSTERING,
402 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
403 .use_new_eh_code = 1,
405 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
411 /* This table describes all ServeRAID Adapters */
412 static struct pci_device_id ips_pci_table[] = {
413 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
414 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
415 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
419 MODULE_DEVICE_TABLE( pci, ips_pci_table );
421 static char ips_hot_plug_name[] = "ips";
423 static int __devinit ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
424 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
426 static struct pci_driver ips_pci_driver = {
427 .name = ips_hot_plug_name,
428 .id_table = ips_pci_table,
429 .probe = ips_insert_device,
430 .remove = __devexit_p(ips_remove_device),
435 * Necessary forward function protoypes
437 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
439 #define MAX_ADAPTER_NAME 15
441 static char ips_adapter_name[][30] = {
444 "ServeRAID on motherboard",
445 "ServeRAID on motherboard",
462 static struct notifier_block ips_notifier = {
469 static char ips_command_direction[] = {
470 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
471 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
472 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
473 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
474 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
475 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
476 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
477 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
478 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
479 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
480 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
481 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
482 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
483 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
484 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
485 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, 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_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
488 IPS_DATA_IN, 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_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
498 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
499 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
500 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
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_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
504 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
505 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
506 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
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_UNK,
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,
515 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
516 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
517 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
518 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
519 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
520 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
524 /****************************************************************************/
526 /* Routine Name: ips_setup */
528 /* Routine Description: */
530 /* setup parameters to the driver */
532 /****************************************************************************/
534 ips_setup(char *ips_str)
540 IPS_OPTION options[] = {
541 {"noi2o", &ips_force_i2o, 0},
542 {"nommap", &ips_force_memio, 0},
543 {"ioctlsize", &ips_ioctlsize, IPS_IOCTL_SIZE},
544 {"cdboot", &ips_cd_boot, 0},
545 {"maxcmds", &MaxLiteCmds, 32},
548 /* Don't use strtok() anymore ( if 2.4 Kernel or beyond ) */
549 /* Search for value */
550 while ((key = strsep(&ips_str, ",."))) {
553 value = strchr(key, ':');
557 * We now have key/value pairs.
558 * Update the variables
560 for (i = 0; i < ARRAY_SIZE(options); i++) {
562 (key, options[i].option_name,
563 strlen(options[i].option_name)) == 0) {
565 *options[i].option_flag =
566 simple_strtoul(value, NULL, 0);
568 *options[i].option_flag =
569 options[i].option_value;
578 __setup("ips=", ips_setup);
580 /****************************************************************************/
582 /* Routine Name: ips_detect */
584 /* Routine Description: */
586 /* Detect and initialize the driver */
588 /* NOTE: this routine is called under the io_request_lock spinlock */
590 /****************************************************************************/
592 ips_detect(struct scsi_host_template * SHT)
596 METHOD_TRACE("ips_detect", 1);
603 for (i = 0; i < ips_num_controllers; i++) {
604 if (ips_register_scsi(i))
606 ips_released_controllers++;
609 return (ips_num_controllers);
612 /****************************************************************************/
613 /* configure the function pointers to use the functions that will work */
614 /* with the found version of the adapter */
615 /****************************************************************************/
617 ips_setup_funclist(ips_ha_t * ha)
623 if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
624 /* morpheus / marco / sebring */
625 ha->func.isintr = ips_isintr_morpheus;
626 ha->func.isinit = ips_isinit_morpheus;
627 ha->func.issue = ips_issue_i2o_memio;
628 ha->func.init = ips_init_morpheus;
629 ha->func.statupd = ips_statupd_morpheus;
630 ha->func.reset = ips_reset_morpheus;
631 ha->func.intr = ips_intr_morpheus;
632 ha->func.enableint = ips_enable_int_morpheus;
633 } else if (IPS_USE_MEMIO(ha)) {
634 /* copperhead w/MEMIO */
635 ha->func.isintr = ips_isintr_copperhead_memio;
636 ha->func.isinit = ips_isinit_copperhead_memio;
637 ha->func.init = ips_init_copperhead_memio;
638 ha->func.statupd = ips_statupd_copperhead_memio;
639 ha->func.statinit = ips_statinit_memio;
640 ha->func.reset = ips_reset_copperhead_memio;
641 ha->func.intr = ips_intr_copperhead;
642 ha->func.erasebios = ips_erase_bios_memio;
643 ha->func.programbios = ips_program_bios_memio;
644 ha->func.verifybios = ips_verify_bios_memio;
645 ha->func.enableint = ips_enable_int_copperhead_memio;
646 if (IPS_USE_I2O_DELIVER(ha))
647 ha->func.issue = ips_issue_i2o_memio;
649 ha->func.issue = ips_issue_copperhead_memio;
652 ha->func.isintr = ips_isintr_copperhead;
653 ha->func.isinit = ips_isinit_copperhead;
654 ha->func.init = ips_init_copperhead;
655 ha->func.statupd = ips_statupd_copperhead;
656 ha->func.statinit = ips_statinit;
657 ha->func.reset = ips_reset_copperhead;
658 ha->func.intr = ips_intr_copperhead;
659 ha->func.erasebios = ips_erase_bios;
660 ha->func.programbios = ips_program_bios;
661 ha->func.verifybios = ips_verify_bios;
662 ha->func.enableint = ips_enable_int_copperhead;
664 if (IPS_USE_I2O_DELIVER(ha))
665 ha->func.issue = ips_issue_i2o;
667 ha->func.issue = ips_issue_copperhead;
671 /****************************************************************************/
673 /* Routine Name: ips_release */
675 /* Routine Description: */
677 /* Remove a driver */
679 /****************************************************************************/
681 ips_release(struct Scsi_Host *sh)
687 METHOD_TRACE("ips_release", 1);
689 for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++) ;
691 if (i == IPS_MAX_ADAPTERS) {
693 "(%s) release, invalid Scsi_Host pointer.\n", ips_name);
703 /* flush the cache on the controller */
704 scb = &ha->scbs[ha->max_cmds - 1];
706 ips_init_scb(ha, scb);
708 scb->timeout = ips_cmd_timeout;
709 scb->cdb[0] = IPS_CMD_FLUSH;
711 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
712 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
713 scb->cmd.flush_cache.state = IPS_NORM_STATE;
714 scb->cmd.flush_cache.reserved = 0;
715 scb->cmd.flush_cache.reserved2 = 0;
716 scb->cmd.flush_cache.reserved3 = 0;
717 scb->cmd.flush_cache.reserved4 = 0;
719 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
722 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) == IPS_FAILURE)
723 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Incomplete Flush.\n");
725 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Complete.\n");
730 /* free extra memory */
733 /* Free I/O Region */
735 release_region(ha->io_addr, ha->io_len);
738 free_irq(ha->irq, ha);
743 ips_released_controllers++;
748 /****************************************************************************/
750 /* Routine Name: ips_halt */
752 /* Routine Description: */
754 /* Perform cleanup when the system reboots */
756 /****************************************************************************/
758 ips_halt(struct notifier_block *nb, ulong event, void *buf)
764 if ((event != SYS_RESTART) && (event != SYS_HALT) &&
765 (event != SYS_POWER_OFF))
766 return (NOTIFY_DONE);
768 for (i = 0; i < ips_next_controller; i++) {
769 ha = (ips_ha_t *) ips_ha[i];
777 /* flush the cache on the controller */
778 scb = &ha->scbs[ha->max_cmds - 1];
780 ips_init_scb(ha, scb);
782 scb->timeout = ips_cmd_timeout;
783 scb->cdb[0] = IPS_CMD_FLUSH;
785 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
786 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
787 scb->cmd.flush_cache.state = IPS_NORM_STATE;
788 scb->cmd.flush_cache.reserved = 0;
789 scb->cmd.flush_cache.reserved2 = 0;
790 scb->cmd.flush_cache.reserved3 = 0;
791 scb->cmd.flush_cache.reserved4 = 0;
793 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
796 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) ==
798 IPS_PRINTK(KERN_WARNING, ha->pcidev,
799 "Incomplete Flush.\n");
801 IPS_PRINTK(KERN_WARNING, ha->pcidev,
802 "Flushing Complete.\n");
808 /****************************************************************************/
810 /* Routine Name: ips_eh_abort */
812 /* Routine Description: */
814 /* Abort a command (using the new error code stuff) */
815 /* Note: this routine is called under the io_request_lock */
816 /****************************************************************************/
817 int ips_eh_abort(struct scsi_cmnd *SC)
820 ips_copp_wait_item_t *item;
822 unsigned long cpu_flags;
823 struct Scsi_Host *host;
825 METHOD_TRACE("ips_eh_abort", 1);
830 host = SC->device->host;
831 ha = (ips_ha_t *) SC->device->host->hostdata;
839 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
841 /* See if the command is on the copp queue */
842 item = ha->copp_waitlist.head;
843 while ((item) && (item->scsi_cmd != SC))
848 ips_removeq_copp(&ha->copp_waitlist, item);
851 /* See if the command is on the wait queue */
852 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
853 /* command not sent yet */
856 /* command must have already been sent */
860 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
864 /****************************************************************************/
866 /* Routine Name: ips_eh_reset */
868 /* Routine Description: */
870 /* Reset the controller (with new eh error code) */
872 /* NOTE: this routine is called under the io_request_lock spinlock */
874 /****************************************************************************/
875 static int __ips_eh_reset(struct scsi_cmnd *SC)
881 ips_copp_wait_item_t *item;
883 METHOD_TRACE("ips_eh_reset", 1);
890 DEBUG(1, "Reset called with NULL scsi command");
895 ha = (ips_ha_t *) SC->device->host->hostdata;
898 DEBUG(1, "Reset called with NULL ha struct");
906 /* See if the command is on the copp queue */
907 item = ha->copp_waitlist.head;
908 while ((item) && (item->scsi_cmd != SC))
913 ips_removeq_copp(&ha->copp_waitlist, item);
917 /* See if the command is on the wait queue */
918 if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
919 /* command not sent yet */
923 /* An explanation for the casual observer: */
924 /* Part of the function of a RAID controller is automatic error */
925 /* detection and recovery. As such, the only problem that physically */
926 /* resetting an adapter will ever fix is when, for some reason, */
927 /* the driver is not successfully communicating with the adapter. */
928 /* Therefore, we will attempt to flush this adapter. If that succeeds, */
929 /* then there's no real purpose in a physical reset. This will complete */
930 /* much faster and avoids any problems that might be caused by a */
931 /* physical reset ( such as having to fail all the outstanding I/O's ). */
933 if (ha->ioctl_reset == 0) { /* IF Not an IOCTL Requested Reset */
934 scb = &ha->scbs[ha->max_cmds - 1];
936 ips_init_scb(ha, scb);
938 scb->timeout = ips_cmd_timeout;
939 scb->cdb[0] = IPS_CMD_FLUSH;
941 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
942 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
943 scb->cmd.flush_cache.state = IPS_NORM_STATE;
944 scb->cmd.flush_cache.reserved = 0;
945 scb->cmd.flush_cache.reserved2 = 0;
946 scb->cmd.flush_cache.reserved3 = 0;
947 scb->cmd.flush_cache.reserved4 = 0;
949 /* Attempt the flush command */
950 ret = ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_IORL);
951 if (ret == IPS_SUCCESS) {
952 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
953 "Reset Request - Flushed Cache\n");
958 /* Either we can't communicate with the adapter or it's an IOCTL request */
959 /* from a utility. A physical reset is needed at this point. */
961 ha->ioctl_reset = 0; /* Reset the IOCTL Requested Reset Flag */
964 * command must have already been sent
965 * reset the controller
967 IPS_PRINTK(KERN_NOTICE, ha->pcidev, "Resetting controller.\n");
968 ret = (*ha->func.reset) (ha);
971 struct scsi_cmnd *scsi_cmd;
973 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
974 "Controller reset failed - controller now offline.\n");
976 /* Now fail all of the active commands */
977 DEBUG_VAR(1, "(%s%d) Failing active commands",
978 ips_name, ha->host_num);
980 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
981 scb->scsi_cmd->result = DID_ERROR << 16;
982 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
983 ips_freescb(ha, scb);
986 /* Now fail all of the pending commands */
987 DEBUG_VAR(1, "(%s%d) Failing pending commands",
988 ips_name, ha->host_num);
990 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
991 scsi_cmd->result = DID_ERROR;
992 scsi_cmd->scsi_done(scsi_cmd);
999 if (!ips_clear_adapter(ha, IPS_INTR_IORL)) {
1000 struct scsi_cmnd *scsi_cmd;
1002 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
1003 "Controller reset failed - controller now offline.\n");
1005 /* Now fail all of the active commands */
1006 DEBUG_VAR(1, "(%s%d) Failing active commands",
1007 ips_name, ha->host_num);
1009 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1010 scb->scsi_cmd->result = DID_ERROR << 16;
1011 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1012 ips_freescb(ha, scb);
1015 /* Now fail all of the pending commands */
1016 DEBUG_VAR(1, "(%s%d) Failing pending commands",
1017 ips_name, ha->host_num);
1019 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
1020 scsi_cmd->result = DID_ERROR << 16;
1021 scsi_cmd->scsi_done(scsi_cmd);
1029 if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
1032 do_gettimeofday(&tv);
1033 ha->last_ffdc = tv.tv_sec;
1035 ips_ffdc_reset(ha, IPS_INTR_IORL);
1038 /* Now fail all of the active commands */
1039 DEBUG_VAR(1, "(%s%d) Failing active commands", ips_name, ha->host_num);
1041 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1042 scb->scsi_cmd->result =
1043 (DID_RESET << 16) | (SUGGEST_RETRY << 24);
1044 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1045 ips_freescb(ha, scb);
1048 /* Reset DCDB active command bits */
1049 for (i = 1; i < ha->nbus; i++)
1050 ha->dcdb_active[i - 1] = 0;
1052 /* Reset the number of active IOCTLs */
1055 ips_next(ha, IPS_INTR_IORL);
1058 #endif /* NO_IPS_RESET */
1062 static int ips_eh_reset(struct scsi_cmnd *SC)
1066 spin_lock_irq(SC->device->host->host_lock);
1067 rc = __ips_eh_reset(SC);
1068 spin_unlock_irq(SC->device->host->host_lock);
1073 /****************************************************************************/
1075 /* Routine Name: ips_queue */
1077 /* Routine Description: */
1079 /* Send a command to the controller */
1082 /* Linux obtains io_request_lock before calling this function */
1084 /****************************************************************************/
1085 static int ips_queue(struct scsi_cmnd *SC, void (*done) (struct scsi_cmnd *))
1090 METHOD_TRACE("ips_queue", 1);
1092 ha = (ips_ha_t *) SC->device->host->hostdata;
1100 if (ips_is_passthru(SC)) {
1101 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1102 SC->result = DID_BUS_BUSY << 16;
1107 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1108 SC->result = DID_BUS_BUSY << 16;
1114 SC->scsi_done = done;
1116 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1120 SC->device->channel, SC->device->id, SC->device->lun);
1122 /* Check for command to initiator IDs */
1123 if ((scmd_channel(SC) > 0)
1124 && (scmd_id(SC) == ha->ha_id[scmd_channel(SC)])) {
1125 SC->result = DID_NO_CONNECT << 16;
1131 if (ips_is_passthru(SC)) {
1133 ips_copp_wait_item_t *scratch;
1135 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1136 /* There can never be any system activity ( network or disk ), but check */
1137 /* anyway just as a good practice. */
1138 pt = (ips_passthru_t *) SC->request_buffer;
1139 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1140 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1141 if (ha->scb_activelist.count != 0) {
1142 SC->result = DID_BUS_BUSY << 16;
1146 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1148 SC->result = DID_OK << 16;
1153 /* allocate space for the scribble */
1154 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1157 SC->result = DID_ERROR << 16;
1163 scratch->scsi_cmd = SC;
1164 scratch->next = NULL;
1166 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1168 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1171 ips_next(ha, IPS_INTR_IORL);
1176 /****************************************************************************/
1178 /* Routine Name: ips_biosparam */
1180 /* Routine Description: */
1182 /* Set bios geometry for the controller */
1184 /****************************************************************************/
1186 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1187 ips_biosparam(Disk * disk, kdev_t dev, int geom[])
1189 ips_ha_t *ha = (ips_ha_t *) disk->device->host->hostdata;
1190 unsigned long capacity = disk->capacity;
1192 ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1193 sector_t capacity, int geom[])
1195 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1201 METHOD_TRACE("ips_biosparam", 1);
1204 /* ?!?! host adater info invalid */
1210 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1211 /* ?!?! Enquiry command failed */
1214 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1215 heads = IPS_NORM_HEADS;
1216 sectors = IPS_NORM_SECTORS;
1218 heads = IPS_COMP_HEADS;
1219 sectors = IPS_COMP_SECTORS;
1222 cylinders = (unsigned long) capacity / (heads * sectors);
1224 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1225 heads, sectors, cylinders);
1229 geom[2] = cylinders;
1234 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1236 /* ips_proc24_info is a wrapper around ips_proc_info *
1237 * for compatibility with the 2.4 scsi parameters */
1239 ips_proc24_info(char *buffer, char **start, off_t offset, int length,
1240 int hostno, int func)
1244 for (i = 0; i < ips_next_controller; i++) {
1245 if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
1246 return ips_proc_info(ips_sh[i], buffer, start,
1247 offset, length, func);
1253 /****************************************************************************/
1255 /* Routine Name: ips_select_queue_depth */
1257 /* Routine Description: */
1259 /* Select queue depths for the devices on the contoller */
1261 /****************************************************************************/
1263 ips_select_queue_depth(struct Scsi_Host *host, struct scsi_device * scsi_devs)
1265 struct scsi_device *device;
1271 min = ha->max_cmds / 4;
1273 for (device = scsi_devs; device; device = device->next) {
1274 if (device->host == host) {
1275 if ((device->channel == 0) && (device->type == 0))
1280 for (device = scsi_devs; device; device = device->next) {
1281 if (device->host == host) {
1282 if ((device->channel == 0) && (device->type == 0)) {
1283 device->queue_depth =
1284 (ha->max_cmds - 1) / count;
1285 if (device->queue_depth < min)
1286 device->queue_depth = min;
1288 device->queue_depth = 2;
1291 if (device->queue_depth < 2)
1292 device->queue_depth = 2;
1298 /****************************************************************************/
1300 /* Routine Name: ips_slave_configure */
1302 /* Routine Description: */
1304 /* Set queue depths on devices once scan is complete */
1306 /****************************************************************************/
1308 ips_slave_configure(struct scsi_device * SDptr)
1313 ha = IPS_HA(SDptr->host);
1314 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1315 min = ha->max_cmds / 2;
1316 if (ha->enq->ucLogDriveCount <= 2)
1317 min = ha->max_cmds - 1;
1318 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min);
1321 SDptr->skip_ms_page_8 = 1;
1322 SDptr->skip_ms_page_3f = 1;
1327 /****************************************************************************/
1329 /* Routine Name: do_ipsintr */
1331 /* Routine Description: */
1333 /* Wrapper for the interrupt handler */
1335 /****************************************************************************/
1337 do_ipsintr(int irq, void *dev_id, struct pt_regs * regs)
1340 unsigned long cpu_flags;
1341 struct Scsi_Host *host;
1344 METHOD_TRACE("do_ipsintr", 2);
1346 ha = (ips_ha_t *) dev_id;
1349 host = ips_sh[ha->host_num];
1350 /* interrupt during initialization */
1352 (*ha->func.intr) (ha);
1356 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
1359 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1363 irqstatus = (*ha->func.intr) (ha);
1365 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1367 /* start the next command */
1368 ips_next(ha, IPS_INTR_ON);
1369 return IRQ_RETVAL(irqstatus);
1372 /****************************************************************************/
1374 /* Routine Name: ips_intr_copperhead */
1376 /* Routine Description: */
1378 /* Polling interrupt handler */
1380 /* ASSUMES interrupts are disabled */
1382 /****************************************************************************/
1384 ips_intr_copperhead(ips_ha_t * ha)
1391 METHOD_TRACE("ips_intr", 2);
1399 intrstatus = (*ha->func.isintr) (ha);
1403 * Unexpected/Shared interrupt
1412 intrstatus = (*ha->func.isintr) (ha);
1417 cstatus.value = (*ha->func.statupd) (ha);
1419 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1420 /* Spurious Interupt ? */
1424 ips_chkstatus(ha, &cstatus);
1425 scb = (ips_scb_t *) sp->scb_addr;
1428 * use the callback function to finish things up
1429 * NOTE: interrupts are OFF for this
1431 (*scb->callback) (ha, scb);
1436 /****************************************************************************/
1438 /* Routine Name: ips_intr_morpheus */
1440 /* Routine Description: */
1442 /* Polling interrupt handler */
1444 /* ASSUMES interrupts are disabled */
1446 /****************************************************************************/
1448 ips_intr_morpheus(ips_ha_t * ha)
1455 METHOD_TRACE("ips_intr_morpheus", 2);
1463 intrstatus = (*ha->func.isintr) (ha);
1467 * Unexpected/Shared interrupt
1476 intrstatus = (*ha->func.isintr) (ha);
1481 cstatus.value = (*ha->func.statupd) (ha);
1483 if (cstatus.value == 0xffffffff)
1484 /* No more to process */
1487 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1488 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1489 "Spurious interrupt; no ccb.\n");
1494 ips_chkstatus(ha, &cstatus);
1495 scb = (ips_scb_t *) sp->scb_addr;
1498 * use the callback function to finish things up
1499 * NOTE: interrupts are OFF for this
1501 (*scb->callback) (ha, scb);
1506 /****************************************************************************/
1508 /* Routine Name: ips_info */
1510 /* Routine Description: */
1512 /* Return info about the driver */
1514 /****************************************************************************/
1516 ips_info(struct Scsi_Host *SH)
1518 static char buffer[256];
1522 METHOD_TRACE("ips_info", 1);
1530 memset(bp, 0, sizeof (buffer));
1532 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1533 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1535 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1537 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1544 /****************************************************************************/
1546 /* Routine Name: ips_proc_info */
1548 /* Routine Description: */
1550 /* The passthru interface for the driver */
1552 /****************************************************************************/
1554 ips_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1555 int length, int func)
1559 ips_ha_t *ha = NULL;
1561 METHOD_TRACE("ips_proc_info", 1);
1563 /* Find our host structure */
1564 for (i = 0; i < ips_next_controller; i++) {
1566 if (ips_sh[i] == host) {
1567 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1584 ret = ips_host_info(ha, buffer, offset, length);
1590 /*--------------------------------------------------------------------------*/
1591 /* Helper Functions */
1592 /*--------------------------------------------------------------------------*/
1594 /****************************************************************************/
1596 /* Routine Name: ips_is_passthru */
1598 /* Routine Description: */
1600 /* Determine if the specified SCSI command is really a passthru command */
1602 /****************************************************************************/
1603 static int ips_is_passthru(struct scsi_cmnd *SC)
1605 unsigned long flags;
1607 METHOD_TRACE("ips_is_passthru", 1);
1612 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1613 (SC->device->channel == 0) &&
1614 (SC->device->id == IPS_ADAPTER_ID) &&
1615 (SC->device->lun == 0) && SC->request_buffer) {
1616 if ((!SC->use_sg) && SC->request_bufflen &&
1617 (((char *) SC->request_buffer)[0] == 'C') &&
1618 (((char *) SC->request_buffer)[1] == 'O') &&
1619 (((char *) SC->request_buffer)[2] == 'P') &&
1620 (((char *) SC->request_buffer)[3] == 'P'))
1622 else if (SC->use_sg) {
1623 struct scatterlist *sg = SC->request_buffer;
1626 /* kmap_atomic() ensures addressability of the user buffer.*/
1627 /* local_irq_save() protects the KM_IRQ0 address slot. */
1628 local_irq_save(flags);
1629 buffer = kmap_atomic(sg->page, KM_IRQ0) + sg->offset;
1630 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1631 buffer[2] == 'P' && buffer[3] == 'P') {
1632 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
1633 local_irq_restore(flags);
1636 kunmap_atomic(buffer - sg->offset, KM_IRQ0);
1637 local_irq_restore(flags);
1643 /****************************************************************************/
1645 /* Routine Name: ips_alloc_passthru_buffer */
1647 /* Routine Description: */
1648 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1649 /* is too small or doesn't exist */
1650 /****************************************************************************/
1652 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1655 dma_addr_t dma_busaddr;
1657 if (ha->ioctl_data && length <= ha->ioctl_len)
1659 /* there is no buffer or it's not big enough, allocate a new one */
1660 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1662 /* free the old memory */
1663 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1665 /* use the new memory */
1666 ha->ioctl_data = (char *) bigger_buf;
1667 ha->ioctl_len = length;
1668 ha->ioctl_busaddr = dma_busaddr;
1675 /****************************************************************************/
1677 /* Routine Name: ips_make_passthru */
1679 /* Routine Description: */
1681 /* Make a passthru command out of the info in the Scsi block */
1683 /****************************************************************************/
1685 ips_make_passthru(ips_ha_t *ha, struct scsi_cmnd *SC, ips_scb_t *scb, int intr)
1691 METHOD_TRACE("ips_make_passthru", 1);
1694 length = SC->request_bufflen;
1696 struct scatterlist *sg = SC->request_buffer;
1698 for (i = 0; i < SC->use_sg; i++)
1699 length += sg[i].length;
1701 if (length < sizeof (ips_passthru_t)) {
1703 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1704 ips_name, ha->host_num);
1705 return (IPS_FAILURE);
1707 if (ips_alloc_passthru_buffer(ha, length)) {
1708 /* allocation failure! If ha->ioctl_data exists, use it to return
1709 some error codes. Return a failed command to the scsi layer. */
1710 if (ha->ioctl_data) {
1711 pt = (ips_passthru_t *) ha->ioctl_data;
1712 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1713 pt->BasicStatus = 0x0B;
1714 pt->ExtendedStatus = 0x00;
1715 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1719 ha->ioctl_datasize = length;
1721 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1722 pt = (ips_passthru_t *) ha->ioctl_data;
1725 * Some notes about the passthru interface used
1727 * IF the scsi op_code == 0x0d then we assume
1728 * that the data came along with/goes with the
1729 * packet we received from the sg driver. In this
1730 * case the CmdBSize field of the pt structure is
1731 * used for the size of the buffer.
1734 switch (pt->CoppCmd) {
1736 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1737 &ips_num_controllers, sizeof (int));
1738 ips_scmd_buf_write(SC, ha->ioctl_data,
1739 sizeof (ips_passthru_t) + sizeof (int));
1740 SC->result = DID_OK << 16;
1742 return (IPS_SUCCESS_IMM);
1744 case IPS_COPPUSRCMD:
1745 case IPS_COPPIOCCMD:
1746 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1747 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1750 "(%s%d) Passthru structure wrong size",
1751 ips_name, ha->host_num);
1753 return (IPS_FAILURE);
1756 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
1757 pt->CoppCP.cmd.flashfw.op_code ==
1758 IPS_CMD_RW_BIOSFW) {
1759 ret = ips_flash_copperhead(ha, pt, scb);
1760 ips_scmd_buf_write(SC, ha->ioctl_data,
1761 sizeof (ips_passthru_t));
1764 if (ips_usrcmd(ha, pt, scb))
1765 return (IPS_SUCCESS);
1767 return (IPS_FAILURE);
1774 return (IPS_FAILURE);
1777 /****************************************************************************/
1778 /* Routine Name: ips_flash_copperhead */
1779 /* Routine Description: */
1780 /* Flash the BIOS/FW on a Copperhead style controller */
1781 /****************************************************************************/
1783 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1787 /* Trombone is the only copperhead that can do packet flash, but only
1788 * for firmware. No one said it had to make sence. */
1789 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1790 if (ips_usrcmd(ha, pt, scb))
1795 pt->BasicStatus = 0x0B;
1796 pt->ExtendedStatus = 0;
1797 scb->scsi_cmd->result = DID_OK << 16;
1798 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1799 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1800 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1801 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1802 pt->BasicStatus = 0;
1803 return ips_flash_bios(ha, pt, scb);
1804 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1805 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1806 ha->flash_data = ips_FlashData;
1807 ha->flash_busaddr = ips_flashbusaddr;
1808 ha->flash_len = PAGE_SIZE << 7;
1809 ha->flash_datasize = 0;
1810 } else if (!ha->flash_data) {
1811 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1812 pt->CoppCP.cmd.flashfw.count;
1813 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1815 &ha->flash_busaddr);
1816 if (!ha->flash_data){
1817 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1820 ha->flash_datasize = 0;
1821 ha->flash_len = datasize;
1825 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1827 ips_free_flash_copperhead(ha);
1828 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1829 "failed size sanity check\n");
1833 if (!ha->flash_data)
1835 pt->BasicStatus = 0;
1836 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1837 pt->CoppCP.cmd.flashfw.count);
1838 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1839 if (pt->CoppCP.cmd.flashfw.packet_num ==
1840 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1841 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1842 return ips_flash_bios(ha, pt, scb);
1843 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1844 return ips_flash_firmware(ha, pt, scb);
1846 return IPS_SUCCESS_IMM;
1849 /****************************************************************************/
1850 /* Routine Name: ips_flash_bios */
1851 /* Routine Description: */
1852 /* flashes the bios of a copperhead adapter */
1853 /****************************************************************************/
1855 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1858 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1859 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1860 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1861 (!ha->func.verifybios))
1863 if ((*ha->func.erasebios) (ha)) {
1865 "(%s%d) flash bios failed - unable to erase flash",
1866 ips_name, ha->host_num);
1869 if ((*ha->func.programbios) (ha,
1872 ha->flash_datasize -
1873 IPS_BIOS_HEADER, 0)) {
1875 "(%s%d) flash bios failed - unable to flash",
1876 ips_name, ha->host_num);
1879 if ((*ha->func.verifybios) (ha,
1882 ha->flash_datasize -
1883 IPS_BIOS_HEADER, 0)) {
1885 "(%s%d) flash bios failed - unable to verify flash",
1886 ips_name, ha->host_num);
1889 ips_free_flash_copperhead(ha);
1890 return IPS_SUCCESS_IMM;
1891 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1892 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1893 if (!ha->func.erasebios)
1895 if ((*ha->func.erasebios) (ha)) {
1897 "(%s%d) flash bios failed - unable to erase flash",
1898 ips_name, ha->host_num);
1901 return IPS_SUCCESS_IMM;
1904 pt->BasicStatus = 0x0B;
1905 pt->ExtendedStatus = 0x00;
1906 ips_free_flash_copperhead(ha);
1910 /****************************************************************************/
1912 /* Routine Name: ips_fill_scb_sg_single */
1914 /* Routine Description: */
1915 /* Fill in a single scb sg_list element from an address */
1916 /* return a -1 if a breakup occurred */
1917 /****************************************************************************/
1919 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1920 ips_scb_t * scb, int indx, unsigned int e_len)
1925 if ((scb->data_len + e_len) > ha->max_xfer) {
1926 e_len = ha->max_xfer - scb->data_len;
1927 scb->breakup = indx;
1934 if (IPS_USE_ENH_SGLIST(ha)) {
1935 scb->sg_list.enh_list[indx].address_lo =
1936 cpu_to_le32(pci_dma_lo32(busaddr));
1937 scb->sg_list.enh_list[indx].address_hi =
1938 cpu_to_le32(pci_dma_hi32(busaddr));
1939 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1941 scb->sg_list.std_list[indx].address =
1942 cpu_to_le32(pci_dma_lo32(busaddr));
1943 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1947 scb->data_len += e_len;
1951 /****************************************************************************/
1952 /* Routine Name: ips_flash_firmware */
1953 /* Routine Description: */
1954 /* flashes the firmware of a copperhead adapter */
1955 /****************************************************************************/
1957 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1959 IPS_SG_LIST sg_list;
1960 uint32_t cmd_busaddr;
1962 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1963 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1964 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1965 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1966 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1968 pt->BasicStatus = 0x0B;
1969 pt->ExtendedStatus = 0x00;
1970 ips_free_flash_copperhead(ha);
1973 /* Save the S/G list pointer so it doesn't get clobbered */
1974 sg_list.list = scb->sg_list.list;
1975 cmd_busaddr = scb->scb_busaddr;
1976 /* copy in the CP */
1977 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1978 /* FIX stuff that might be wrong */
1979 scb->sg_list.list = sg_list.list;
1980 scb->scb_busaddr = cmd_busaddr;
1981 scb->bus = scb->scsi_cmd->device->channel;
1982 scb->target_id = scb->scsi_cmd->device->id;
1983 scb->lun = scb->scsi_cmd->device->lun;
1988 scb->callback = ipsintr_done;
1989 scb->timeout = ips_cmd_timeout;
1991 scb->data_len = ha->flash_datasize;
1993 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1995 scb->flags |= IPS_SCB_MAP_SINGLE;
1996 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1997 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1999 scb->timeout = pt->TimeOut;
2000 scb->scsi_cmd->result = DID_OK << 16;
2004 /****************************************************************************/
2005 /* Routine Name: ips_free_flash_copperhead */
2006 /* Routine Description: */
2007 /* release the memory resources used to hold the flash image */
2008 /****************************************************************************/
2010 ips_free_flash_copperhead(ips_ha_t * ha)
2012 if (ha->flash_data == ips_FlashData)
2013 test_and_clear_bit(0, &ips_FlashDataInUse);
2014 else if (ha->flash_data)
2015 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
2017 ha->flash_data = NULL;
2020 /****************************************************************************/
2022 /* Routine Name: ips_usrcmd */
2024 /* Routine Description: */
2026 /* Process a user command and make it ready to send */
2028 /****************************************************************************/
2030 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
2032 IPS_SG_LIST sg_list;
2033 uint32_t cmd_busaddr;
2035 METHOD_TRACE("ips_usrcmd", 1);
2037 if ((!scb) || (!pt) || (!ha))
2040 /* Save the S/G list pointer so it doesn't get clobbered */
2041 sg_list.list = scb->sg_list.list;
2042 cmd_busaddr = scb->scb_busaddr;
2043 /* copy in the CP */
2044 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
2045 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
2047 /* FIX stuff that might be wrong */
2048 scb->sg_list.list = sg_list.list;
2049 scb->scb_busaddr = cmd_busaddr;
2050 scb->bus = scb->scsi_cmd->device->channel;
2051 scb->target_id = scb->scsi_cmd->device->id;
2052 scb->lun = scb->scsi_cmd->device->lun;
2057 scb->callback = ipsintr_done;
2058 scb->timeout = ips_cmd_timeout;
2059 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
2061 /* we don't support DCDB/READ/WRITE Scatter Gather */
2062 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
2063 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
2064 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
2068 scb->data_len = pt->CmdBSize;
2069 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
2071 scb->data_busaddr = 0L;
2074 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2075 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
2076 (unsigned long) &scb->
2078 (unsigned long) scb);
2081 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2082 scb->dcdb.buffer_pointer =
2083 cpu_to_le32(scb->data_busaddr);
2085 scb->cmd.basic_io.sg_addr =
2086 cpu_to_le32(scb->data_busaddr);
2091 scb->timeout = pt->TimeOut;
2093 if (pt->TimeOut <= 10)
2094 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
2095 else if (pt->TimeOut <= 60)
2096 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
2098 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
2101 /* assume success */
2102 scb->scsi_cmd->result = DID_OK << 16;
2108 /****************************************************************************/
2110 /* Routine Name: ips_cleanup_passthru */
2112 /* Routine Description: */
2114 /* Cleanup after a passthru command */
2116 /****************************************************************************/
2118 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
2122 METHOD_TRACE("ips_cleanup_passthru", 1);
2124 if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
2125 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2126 ips_name, ha->host_num);
2130 pt = (ips_passthru_t *) ha->ioctl_data;
2132 /* Copy data back to the user */
2133 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2134 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2136 pt->BasicStatus = scb->basic_status;
2137 pt->ExtendedStatus = scb->extended_status;
2138 pt->AdapterType = ha->ad_type;
2140 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
2141 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2142 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2143 ips_free_flash_copperhead(ha);
2145 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2148 /****************************************************************************/
2150 /* Routine Name: ips_host_info */
2152 /* Routine Description: */
2154 /* The passthru interface for the driver */
2156 /****************************************************************************/
2158 ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
2162 METHOD_TRACE("ips_host_info", 1);
2166 info.offset = offset;
2170 copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
2172 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2173 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2174 copy_info(&info, "\tController Type : %s\n",
2175 ips_adapter_name[ha->ad_type - 1]);
2178 "\tController Type : Unknown\n");
2182 "\tIO region : 0x%lx (%d bytes)\n",
2183 ha->io_addr, ha->io_len);
2187 "\tMemory region : 0x%lx (%d bytes)\n",
2188 ha->mem_addr, ha->mem_len);
2190 "\tShared memory address : 0x%lx\n",
2194 copy_info(&info, "\tIRQ number : %d\n", ha->irq);
2196 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2197 /* That keeps everything happy for "text" operations on the proc file. */
2199 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2200 if (ha->nvram->bios_low[3] == 0) {
2202 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2203 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2204 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2205 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2206 ha->nvram->bios_low[2]);
2210 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2211 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2212 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2213 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2214 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2219 if (ha->enq->CodeBlkVersion[7] == 0) {
2221 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2222 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2223 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2224 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2225 ha->enq->CodeBlkVersion[6]);
2228 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2229 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2230 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2231 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2232 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2235 if (ha->enq->BootBlkVersion[7] == 0) {
2237 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2238 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2239 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2240 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2241 ha->enq->BootBlkVersion[6]);
2244 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2245 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2246 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2247 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2248 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2251 copy_info(&info, "\tDriver Version : %s%s\n",
2252 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2254 copy_info(&info, "\tDriver Build : %d\n",
2257 copy_info(&info, "\tMax Physical Devices : %d\n",
2258 ha->enq->ucMaxPhysicalDevices);
2259 copy_info(&info, "\tMax Active Commands : %d\n",
2261 copy_info(&info, "\tCurrent Queued Commands : %d\n",
2262 ha->scb_waitlist.count);
2263 copy_info(&info, "\tCurrent Active Commands : %d\n",
2264 ha->scb_activelist.count - ha->num_ioctl);
2265 copy_info(&info, "\tCurrent Queued PT Commands : %d\n",
2266 ha->copp_waitlist.count);
2267 copy_info(&info, "\tCurrent Active PT Commands : %d\n",
2270 copy_info(&info, "\n");
2272 return (info.localpos);
2275 /****************************************************************************/
2277 /* Routine Name: copy_mem_info */
2279 /* Routine Description: */
2281 /* Copy data into an IPS_INFOSTR structure */
2283 /****************************************************************************/
2285 copy_mem_info(IPS_INFOSTR * info, char *data, int len)
2287 METHOD_TRACE("copy_mem_info", 1);
2289 if (info->pos + len < info->offset) {
2294 if (info->pos < info->offset) {
2295 data += (info->offset - info->pos);
2296 len -= (info->offset - info->pos);
2297 info->pos += (info->offset - info->pos);
2300 if (info->localpos + len > info->length)
2301 len = info->length - info->localpos;
2304 memcpy(info->buffer + info->localpos, data, len);
2306 info->localpos += len;
2310 /****************************************************************************/
2312 /* Routine Name: copy_info */
2314 /* Routine Description: */
2316 /* printf style wrapper for an info structure */
2318 /****************************************************************************/
2320 copy_info(IPS_INFOSTR * info, char *fmt, ...)
2326 METHOD_TRACE("copy_info", 1);
2328 va_start(args, fmt);
2329 len = vsprintf(buf, fmt, args);
2332 copy_mem_info(info, buf, len);
2337 /****************************************************************************/
2339 /* Routine Name: ips_identify_controller */
2341 /* Routine Description: */
2343 /* Identify this controller */
2345 /****************************************************************************/
2347 ips_identify_controller(ips_ha_t * ha)
2349 METHOD_TRACE("ips_identify_controller", 1);
2351 switch (ha->device_id) {
2352 case IPS_DEVICEID_COPPERHEAD:
2353 if (ha->revision_id <= IPS_REVID_SERVERAID) {
2354 ha->ad_type = IPS_ADTYPE_SERVERAID;
2355 } else if (ha->revision_id == IPS_REVID_SERVERAID2) {
2356 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2357 } else if (ha->revision_id == IPS_REVID_NAVAJO) {
2358 ha->ad_type = IPS_ADTYPE_NAVAJO;
2359 } else if ((ha->revision_id == IPS_REVID_SERVERAID2)
2360 && (ha->slot_num == 0)) {
2361 ha->ad_type = IPS_ADTYPE_KIOWA;
2362 } else if ((ha->revision_id >= IPS_REVID_CLARINETP1) &&
2363 (ha->revision_id <= IPS_REVID_CLARINETP3)) {
2364 if (ha->enq->ucMaxPhysicalDevices == 15)
2365 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2367 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2368 } else if ((ha->revision_id >= IPS_REVID_TROMBONE32) &&
2369 (ha->revision_id <= IPS_REVID_TROMBONE64)) {
2370 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2374 case IPS_DEVICEID_MORPHEUS:
2375 switch (ha->subdevice_id) {
2376 case IPS_SUBDEVICEID_4L:
2377 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2380 case IPS_SUBDEVICEID_4M:
2381 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2384 case IPS_SUBDEVICEID_4MX:
2385 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2388 case IPS_SUBDEVICEID_4LX:
2389 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2392 case IPS_SUBDEVICEID_5I2:
2393 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2396 case IPS_SUBDEVICEID_5I1:
2397 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2403 case IPS_DEVICEID_MARCO:
2404 switch (ha->subdevice_id) {
2405 case IPS_SUBDEVICEID_6M:
2406 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2408 case IPS_SUBDEVICEID_6I:
2409 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2411 case IPS_SUBDEVICEID_7k:
2412 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2414 case IPS_SUBDEVICEID_7M:
2415 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2422 /****************************************************************************/
2424 /* Routine Name: ips_get_bios_version */
2426 /* Routine Description: */
2428 /* Get the BIOS revision number */
2430 /****************************************************************************/
2432 ips_get_bios_version(ips_ha_t * ha, int intr)
2441 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2444 METHOD_TRACE("ips_get_bios_version", 1);
2449 strncpy(ha->bios_version, " ?", 8);
2451 if (ha->device_id == IPS_DEVICEID_COPPERHEAD) {
2452 if (IPS_USE_MEMIO(ha)) {
2453 /* Memory Mapped I/O */
2456 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2457 if (ha->revision_id == IPS_REVID_TROMBONE64)
2458 udelay(25); /* 25 us */
2460 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2463 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2464 if (ha->revision_id == IPS_REVID_TROMBONE64)
2465 udelay(25); /* 25 us */
2467 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2470 /* Get Major version */
2471 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2472 if (ha->revision_id == IPS_REVID_TROMBONE64)
2473 udelay(25); /* 25 us */
2475 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2477 /* Get Minor version */
2478 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2479 if (ha->revision_id == IPS_REVID_TROMBONE64)
2480 udelay(25); /* 25 us */
2481 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2483 /* Get SubMinor version */
2484 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2485 if (ha->revision_id == IPS_REVID_TROMBONE64)
2486 udelay(25); /* 25 us */
2487 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2490 /* Programmed I/O */
2493 outl(0, ha->io_addr + IPS_REG_FLAP);
2494 if (ha->revision_id == IPS_REVID_TROMBONE64)
2495 udelay(25); /* 25 us */
2497 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2500 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
2501 if (ha->revision_id == IPS_REVID_TROMBONE64)
2502 udelay(25); /* 25 us */
2504 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2507 /* Get Major version */
2508 outl(cpu_to_le32(0x1FF), ha->io_addr + IPS_REG_FLAP);
2509 if (ha->revision_id == IPS_REVID_TROMBONE64)
2510 udelay(25); /* 25 us */
2512 major = inb(ha->io_addr + IPS_REG_FLDP);
2514 /* Get Minor version */
2515 outl(cpu_to_le32(0x1FE), ha->io_addr + IPS_REG_FLAP);
2516 if (ha->revision_id == IPS_REVID_TROMBONE64)
2517 udelay(25); /* 25 us */
2519 minor = inb(ha->io_addr + IPS_REG_FLDP);
2521 /* Get SubMinor version */
2522 outl(cpu_to_le32(0x1FD), ha->io_addr + IPS_REG_FLAP);
2523 if (ha->revision_id == IPS_REVID_TROMBONE64)
2524 udelay(25); /* 25 us */
2526 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2530 /* Morpheus Family - Send Command to the card */
2532 buffer = ha->ioctl_data;
2534 memset(buffer, 0, 0x1000);
2536 scb = &ha->scbs[ha->max_cmds - 1];
2538 ips_init_scb(ha, scb);
2540 scb->timeout = ips_cmd_timeout;
2541 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2543 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2544 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2545 scb->cmd.flashfw.type = 1;
2546 scb->cmd.flashfw.direction = 0;
2547 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2548 scb->cmd.flashfw.total_packets = 1;
2549 scb->cmd.flashfw.packet_num = 0;
2550 scb->data_len = 0x1000;
2551 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2553 /* issue the command */
2555 ips_send_wait(ha, scb, ips_cmd_timeout,
2556 intr)) == IPS_FAILURE)
2557 || (ret == IPS_SUCCESS_IMM)
2558 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2559 /* Error occurred */
2564 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2565 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2566 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2567 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2573 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2574 ha->bios_version[1] = '.';
2575 ha->bios_version[2] = hexDigits[major & 0x0F];
2576 ha->bios_version[3] = hexDigits[subminor];
2577 ha->bios_version[4] = '.';
2578 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2579 ha->bios_version[6] = hexDigits[minor & 0x0F];
2580 ha->bios_version[7] = 0;
2583 /****************************************************************************/
2585 /* Routine Name: ips_hainit */
2587 /* Routine Description: */
2589 /* Initialize the controller */
2591 /* NOTE: Assumes to be called from with a lock */
2593 /****************************************************************************/
2595 ips_hainit(ips_ha_t * ha)
2600 METHOD_TRACE("ips_hainit", 1);
2605 if (ha->func.statinit)
2606 (*ha->func.statinit) (ha);
2608 if (ha->func.enableint)
2609 (*ha->func.enableint) (ha);
2612 ha->reset_count = 1;
2613 do_gettimeofday(&tv);
2614 ha->last_ffdc = tv.tv_sec;
2615 ips_ffdc_reset(ha, IPS_INTR_IORL);
2617 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2618 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2619 "unable to read config from controller.\n");
2624 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2625 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2626 "unable to read controller status.\n");
2631 /* Identify this controller */
2632 ips_identify_controller(ha);
2634 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2635 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2636 "unable to read subsystem parameters.\n");
2641 /* write nvram user page 5 */
2642 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2643 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2644 "unable to write driver info to controller.\n");
2649 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2650 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2651 ips_clear_adapter(ha, IPS_INTR_IORL);
2653 /* set limits on SID, LUN, BUS */
2654 ha->ntargets = IPS_MAX_TARGETS + 1;
2656 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2658 switch (ha->conf->logical_drive[0].ucStripeSize) {
2660 ha->max_xfer = 0x10000;
2664 ha->max_xfer = 0x20000;
2668 ha->max_xfer = 0x40000;
2673 ha->max_xfer = 0x80000;
2677 /* setup max concurrent commands */
2678 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2679 /* Use the new method */
2680 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2682 /* use the old method */
2683 switch (ha->conf->logical_drive[0].ucStripeSize) {
2703 /* Limit the Active Commands on a Lite Adapter */
2704 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2705 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2706 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2707 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2708 ha->max_cmds = MaxLiteCmds;
2711 /* set controller IDs */
2712 ha->ha_id[0] = IPS_ADAPTER_ID;
2713 for (i = 1; i < ha->nbus; i++) {
2714 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2715 ha->dcdb_active[i - 1] = 0;
2721 /****************************************************************************/
2723 /* Routine Name: ips_next */
2725 /* Routine Description: */
2727 /* Take the next command off the queue and send it to the controller */
2729 /****************************************************************************/
2731 ips_next(ips_ha_t * ha, int intr)
2734 struct scsi_cmnd *SC;
2735 struct scsi_cmnd *p;
2736 struct scsi_cmnd *q;
2737 ips_copp_wait_item_t *item;
2739 unsigned long cpu_flags = 0;
2740 struct Scsi_Host *host;
2741 METHOD_TRACE("ips_next", 1);
2745 host = ips_sh[ha->host_num];
2747 * Block access to the queue function so
2748 * this command won't time out
2750 if (intr == IPS_INTR_ON)
2751 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2753 if ((ha->subsys->param[3] & 0x300000)
2754 && (ha->scb_activelist.count == 0)) {
2757 do_gettimeofday(&tv);
2759 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2760 ha->last_ffdc = tv.tv_sec;
2766 * Send passthru commands
2767 * These have priority over normal I/O
2768 * but shouldn't affect performance too much
2769 * since we limit the number that can be active
2770 * on the card at any one time
2772 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2773 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2775 item = ips_removeq_copp_head(&ha->copp_waitlist);
2777 if (intr == IPS_INTR_ON)
2778 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2779 scb->scsi_cmd = item->scsi_cmd;
2782 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2784 if (intr == IPS_INTR_ON)
2785 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2788 if (scb->scsi_cmd) {
2789 scb->scsi_cmd->result = DID_ERROR << 16;
2790 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2793 ips_freescb(ha, scb);
2795 case IPS_SUCCESS_IMM:
2796 if (scb->scsi_cmd) {
2797 scb->scsi_cmd->result = DID_OK << 16;
2798 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2801 ips_freescb(ha, scb);
2807 if (ret != IPS_SUCCESS) {
2812 ret = ips_send_cmd(ha, scb);
2814 if (ret == IPS_SUCCESS)
2815 ips_putq_scb_head(&ha->scb_activelist, scb);
2821 if (scb->scsi_cmd) {
2822 scb->scsi_cmd->result = DID_ERROR << 16;
2825 ips_freescb(ha, scb);
2827 case IPS_SUCCESS_IMM:
2828 ips_freescb(ha, scb);
2837 * Send "Normal" I/O commands
2840 p = ha->scb_waitlist.head;
2841 while ((p) && (scb = ips_getscb(ha))) {
2842 if ((scmd_channel(p) > 0)
2844 dcdb_active[scmd_channel(p) -
2845 1] & (1 << scmd_id(p)))) {
2846 ips_freescb(ha, scb);
2847 p = (struct scsi_cmnd *) p->host_scribble;
2852 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2854 if (intr == IPS_INTR_ON)
2855 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags); /* Unlock HA after command is taken off queue */
2857 SC->result = DID_OK;
2858 SC->host_scribble = NULL;
2860 memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
2862 scb->target_id = SC->device->id;
2863 scb->lun = SC->device->lun;
2864 scb->bus = SC->device->channel;
2868 scb->callback = ipsintr_done;
2869 scb->timeout = ips_cmd_timeout;
2870 memset(&scb->cmd, 0, 16);
2872 /* copy in the CDB */
2873 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2875 /* Now handle the data buffer */
2877 struct scatterlist *sg;
2880 sg = SC->request_buffer;
2881 scb->sg_count = pci_map_sg(ha->pcidev, sg, SC->use_sg,
2882 SC->sc_data_direction);
2883 scb->flags |= IPS_SCB_MAP_SG;
2884 for (i = 0; i < scb->sg_count; i++) {
2885 if (ips_fill_scb_sg_single
2886 (ha, sg_dma_address(&sg[i]), scb, i,
2887 sg_dma_len(&sg[i])) < 0)
2890 scb->dcdb.transfer_length = scb->data_len;
2892 if (SC->request_bufflen) {
2894 pci_map_single(ha->pcidev,
2896 SC->request_bufflen,
2897 SC->sc_data_direction);
2898 scb->flags |= IPS_SCB_MAP_SINGLE;
2899 ips_fill_scb_sg_single(ha, scb->data_busaddr,
2901 SC->request_bufflen);
2902 scb->dcdb.transfer_length = scb->data_len;
2904 scb->data_busaddr = 0L;
2907 scb->dcdb.transfer_length = 0;
2912 scb->dcdb.cmd_attribute =
2913 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2915 /* Allow a WRITE BUFFER Command to Have no Data */
2916 /* This is Used by Tape Flash Utilites */
2917 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0))
2918 scb->dcdb.cmd_attribute = 0;
2920 if (!(scb->dcdb.cmd_attribute & 0x3))
2921 scb->dcdb.transfer_length = 0;
2923 if (scb->data_len >= IPS_MAX_XFER) {
2924 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2925 scb->dcdb.transfer_length = 0;
2927 if (intr == IPS_INTR_ON)
2928 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2930 ret = ips_send_cmd(ha, scb);
2934 ips_putq_scb_head(&ha->scb_activelist, scb);
2937 if (scb->scsi_cmd) {
2938 scb->scsi_cmd->result = DID_ERROR << 16;
2939 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2943 ha->dcdb_active[scb->bus - 1] &=
2944 ~(1 << scb->target_id);
2946 ips_freescb(ha, scb);
2948 case IPS_SUCCESS_IMM:
2950 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2953 ha->dcdb_active[scb->bus - 1] &=
2954 ~(1 << scb->target_id);
2956 ips_freescb(ha, scb);
2962 p = (struct scsi_cmnd *) p->host_scribble;
2966 if (intr == IPS_INTR_ON)
2967 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2970 /****************************************************************************/
2972 /* Routine Name: ips_putq_scb_head */
2974 /* Routine Description: */
2976 /* Add an item to the head of the queue */
2978 /* ASSUMED to be called from within the HA lock */
2980 /****************************************************************************/
2982 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2984 METHOD_TRACE("ips_putq_scb_head", 1);
2989 item->q_next = queue->head;
2998 /****************************************************************************/
3000 /* Routine Name: ips_removeq_scb_head */
3002 /* Routine Description: */
3004 /* Remove the head of the queue */
3006 /* ASSUMED to be called from within the HA lock */
3008 /****************************************************************************/
3010 ips_removeq_scb_head(ips_scb_queue_t * queue)
3014 METHOD_TRACE("ips_removeq_scb_head", 1);
3022 queue->head = item->q_next;
3023 item->q_next = NULL;
3025 if (queue->tail == item)
3033 /****************************************************************************/
3035 /* Routine Name: ips_removeq_scb */
3037 /* Routine Description: */
3039 /* Remove an item from a queue */
3041 /* ASSUMED to be called from within the HA lock */
3043 /****************************************************************************/
3045 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
3049 METHOD_TRACE("ips_removeq_scb", 1);
3054 if (item == queue->head) {
3055 return (ips_removeq_scb_head(queue));
3060 while ((p) && (item != p->q_next))
3065 p->q_next = item->q_next;
3070 item->q_next = NULL;
3079 /****************************************************************************/
3081 /* Routine Name: ips_putq_wait_tail */
3083 /* Routine Description: */
3085 /* Add an item to the tail of the queue */
3087 /* ASSUMED to be called from within the HA lock */
3089 /****************************************************************************/
3090 static void ips_putq_wait_tail(ips_wait_queue_t *queue, struct scsi_cmnd *item)
3092 METHOD_TRACE("ips_putq_wait_tail", 1);
3097 item->host_scribble = NULL;
3100 queue->tail->host_scribble = (char *) item;
3110 /****************************************************************************/
3112 /* Routine Name: ips_removeq_wait_head */
3114 /* Routine Description: */
3116 /* Remove the head of the queue */
3118 /* ASSUMED to be called from within the HA lock */
3120 /****************************************************************************/
3121 static struct scsi_cmnd *ips_removeq_wait_head(ips_wait_queue_t *queue)
3123 struct scsi_cmnd *item;
3125 METHOD_TRACE("ips_removeq_wait_head", 1);
3133 queue->head = (struct scsi_cmnd *) item->host_scribble;
3134 item->host_scribble = NULL;
3136 if (queue->tail == item)
3144 /****************************************************************************/
3146 /* Routine Name: ips_removeq_wait */
3148 /* Routine Description: */
3150 /* Remove an item from a queue */
3152 /* ASSUMED to be called from within the HA lock */
3154 /****************************************************************************/
3155 static struct scsi_cmnd *ips_removeq_wait(ips_wait_queue_t *queue,
3156 struct scsi_cmnd *item)
3158 struct scsi_cmnd *p;
3160 METHOD_TRACE("ips_removeq_wait", 1);
3165 if (item == queue->head) {
3166 return (ips_removeq_wait_head(queue));
3171 while ((p) && (item != (struct scsi_cmnd *) p->host_scribble))
3172 p = (struct scsi_cmnd *) p->host_scribble;
3176 p->host_scribble = item->host_scribble;
3178 if (!item->host_scribble)
3181 item->host_scribble = NULL;
3190 /****************************************************************************/
3192 /* Routine Name: ips_putq_copp_tail */
3194 /* Routine Description: */
3196 /* Add an item to the tail of the queue */
3198 /* ASSUMED to be called from within the HA lock */
3200 /****************************************************************************/
3202 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3204 METHOD_TRACE("ips_putq_copp_tail", 1);
3212 queue->tail->next = item;
3222 /****************************************************************************/
3224 /* Routine Name: ips_removeq_copp_head */
3226 /* Routine Description: */
3228 /* Remove the head of the queue */
3230 /* ASSUMED to be called from within the HA lock */
3232 /****************************************************************************/
3233 static ips_copp_wait_item_t *
3234 ips_removeq_copp_head(ips_copp_queue_t * queue)
3236 ips_copp_wait_item_t *item;
3238 METHOD_TRACE("ips_removeq_copp_head", 1);
3246 queue->head = item->next;
3249 if (queue->tail == item)
3257 /****************************************************************************/
3259 /* Routine Name: ips_removeq_copp */
3261 /* Routine Description: */
3263 /* Remove an item from a queue */
3265 /* ASSUMED to be called from within the HA lock */
3267 /****************************************************************************/
3268 static ips_copp_wait_item_t *
3269 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3271 ips_copp_wait_item_t *p;
3273 METHOD_TRACE("ips_removeq_copp", 1);
3278 if (item == queue->head) {
3279 return (ips_removeq_copp_head(queue));
3284 while ((p) && (item != p->next))
3289 p->next = item->next;
3303 /****************************************************************************/
3305 /* Routine Name: ipsintr_blocking */
3307 /* Routine Description: */
3309 /* Finalize an interrupt for internal commands */
3311 /****************************************************************************/
3313 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3315 METHOD_TRACE("ipsintr_blocking", 2);
3317 ips_freescb(ha, scb);
3318 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3319 ha->waitflag = FALSE;
3325 /****************************************************************************/
3327 /* Routine Name: ipsintr_done */
3329 /* Routine Description: */
3331 /* Finalize an interrupt for non-internal commands */
3333 /****************************************************************************/
3335 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3337 METHOD_TRACE("ipsintr_done", 2);
3340 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3341 "Spurious interrupt; scb NULL.\n");
3346 if (scb->scsi_cmd == NULL) {
3347 /* unexpected interrupt */
3348 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3349 "Spurious interrupt; scsi_cmd not set.\n");
3357 /****************************************************************************/
3359 /* Routine Name: ips_done */
3361 /* Routine Description: */
3363 /* Do housekeeping on completed commands */
3364 /* ASSUMED to be called form within the request lock */
3365 /****************************************************************************/
3367 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3371 METHOD_TRACE("ips_done", 1);
3376 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3377 ips_cleanup_passthru(ha, scb);
3381 * Check to see if this command had too much
3382 * data and had to be broke up. If so, queue
3383 * the rest of the data and continue.
3385 if ((scb->breakup) || (scb->sg_break)) {
3386 /* we had a data breakup */
3389 if (scb->sg_count) {
3391 struct scatterlist *sg;
3392 int ips_sg_index = 0;
3395 sg = scb->scsi_cmd->request_buffer;
3397 /* Spin forward to last dma chunk */
3398 sg_dma_index = scb->breakup;
3400 /* Take care of possible partial on last chunk */
3401 ips_fill_scb_sg_single(ha,
3404 scb, ips_sg_index++,
3408 for (; sg_dma_index < scb->sg_count;
3410 if (ips_fill_scb_sg_single
3412 sg_dma_address(&sg[sg_dma_index]),
3413 scb, ips_sg_index++,
3414 sg_dma_len(&sg[sg_dma_index])) < 0)
3420 /* Non S/G Request */
3421 (void) ips_fill_scb_sg_single(ha,
3433 scb->dcdb.transfer_length = scb->data_len;
3434 scb->dcdb.cmd_attribute |=
3435 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3437 if (!(scb->dcdb.cmd_attribute & 0x3))
3438 scb->dcdb.transfer_length = 0;
3440 if (scb->data_len >= IPS_MAX_XFER) {
3441 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3442 scb->dcdb.transfer_length = 0;
3445 ret = ips_send_cmd(ha, scb);
3449 if (scb->scsi_cmd) {
3450 scb->scsi_cmd->result = DID_ERROR << 16;
3451 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3454 ips_freescb(ha, scb);
3456 case IPS_SUCCESS_IMM:
3457 if (scb->scsi_cmd) {
3458 scb->scsi_cmd->result = DID_ERROR << 16;
3459 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3462 ips_freescb(ha, scb);
3470 } /* end if passthru */
3473 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3476 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3478 ips_freescb(ha, scb);
3481 /****************************************************************************/
3483 /* Routine Name: ips_map_status */
3485 /* Routine Description: */
3487 /* Map Controller Error codes to Linux Error Codes */
3489 /****************************************************************************/
3491 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3495 uint32_t transfer_len;
3496 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3497 IPS_SCSI_INQ_DATA inquiryData;
3499 METHOD_TRACE("ips_map_status", 1);
3503 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3504 ips_name, ha->host_num,
3505 scb->scsi_cmd->device->channel,
3506 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3507 scb->basic_status, scb->extended_status,
3508 scb->extended_status ==
3509 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3510 scb->extended_status ==
3511 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3512 scb->extended_status ==
3513 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3516 /* default driver error */
3517 errcode = DID_ERROR;
3520 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3521 case IPS_CMD_TIMEOUT:
3522 errcode = DID_TIME_OUT;
3525 case IPS_INVAL_OPCO:
3526 case IPS_INVAL_CMD_BLK:
3527 case IPS_INVAL_PARM_BLK:
3529 case IPS_CMD_CMPLT_WERROR:
3532 case IPS_PHYS_DRV_ERROR:
3533 switch (scb->extended_status) {
3534 case IPS_ERR_SEL_TO:
3536 errcode = DID_NO_CONNECT;
3540 case IPS_ERR_OU_RUN:
3541 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3542 (scb->cmd.dcdb.op_code ==
3543 IPS_CMD_EXTENDED_DCDB_SG)) {
3544 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3545 transfer_len = tapeDCDB->transfer_length;
3548 (uint32_t) scb->dcdb.transfer_length;
3551 if ((scb->bus) && (transfer_len < scb->data_len)) {
3552 /* Underrun - set default to no error */
3555 /* Restrict access to physical DASD */
3556 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3557 ips_scmd_buf_read(scb->scsi_cmd,
3558 &inquiryData, sizeof (inquiryData));
3559 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK) {
3560 errcode = DID_TIME_OUT;
3565 errcode = DID_ERROR;
3569 case IPS_ERR_RECOVERY:
3570 /* don't fail recovered errors */
3576 case IPS_ERR_HOST_RESET:
3577 case IPS_ERR_DEV_RESET:
3578 errcode = DID_RESET;
3581 case IPS_ERR_CKCOND:
3583 if ((scb->cmd.dcdb.op_code ==
3584 IPS_CMD_EXTENDED_DCDB)
3585 || (scb->cmd.dcdb.op_code ==
3586 IPS_CMD_EXTENDED_DCDB_SG)) {
3588 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3589 memcpy(scb->scsi_cmd->sense_buffer,
3590 tapeDCDB->sense_info,
3591 sizeof (scb->scsi_cmd->
3594 memcpy(scb->scsi_cmd->sense_buffer,
3595 scb->dcdb.sense_info,
3596 sizeof (scb->scsi_cmd->
3599 device_error = 2; /* check condition */
3607 errcode = DID_ERROR;
3613 scb->scsi_cmd->result = device_error | (errcode << 16);
3618 /****************************************************************************/
3620 /* Routine Name: ips_send_wait */
3622 /* Routine Description: */
3624 /* Send a command to the controller and wait for it to return */
3626 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3627 /* actually need to wait. */
3628 /****************************************************************************/
3630 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3634 METHOD_TRACE("ips_send_wait", 1);
3636 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3637 ha->waitflag = TRUE;
3638 ha->cmd_in_progress = scb->cdb[0];
3640 scb->callback = ipsintr_blocking;
3641 ret = ips_send_cmd(ha, scb);
3643 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3646 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3647 ret = ips_wait(ha, timeout, intr);
3652 /****************************************************************************/
3654 /* Routine Name: ips_scmd_buf_write */
3656 /* Routine Description: */
3657 /* Write data to struct scsi_cmnd request_buffer at proper offsets */
3658 /****************************************************************************/
3660 ips_scmd_buf_write(struct scsi_cmnd *scmd, void *data, unsigned int count)
3664 unsigned int min_cnt, xfer_cnt;
3665 char *cdata = (char *) data;
3666 unsigned char *buffer;
3667 unsigned long flags;
3668 struct scatterlist *sg = scmd->request_buffer;
3669 for (i = 0, xfer_cnt = 0;
3670 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3671 min_cnt = min(count - xfer_cnt, sg[i].length);
3673 /* kmap_atomic() ensures addressability of the data buffer.*/
3674 /* local_irq_save() protects the KM_IRQ0 address slot. */
3675 local_irq_save(flags);
3676 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset;
3677 memcpy(buffer, &cdata[xfer_cnt], min_cnt);
3678 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3679 local_irq_restore(flags);
3681 xfer_cnt += min_cnt;
3685 unsigned int min_cnt = min(count, scmd->request_bufflen);
3686 memcpy(scmd->request_buffer, data, min_cnt);
3690 /****************************************************************************/
3692 /* Routine Name: ips_scmd_buf_read */
3694 /* Routine Description: */
3695 /* Copy data from a struct scsi_cmnd to a new, linear buffer */
3696 /****************************************************************************/
3698 ips_scmd_buf_read(struct scsi_cmnd *scmd, void *data, unsigned int count)
3702 unsigned int min_cnt, xfer_cnt;
3703 char *cdata = (char *) data;
3704 unsigned char *buffer;
3705 unsigned long flags;
3706 struct scatterlist *sg = scmd->request_buffer;
3707 for (i = 0, xfer_cnt = 0;
3708 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3709 min_cnt = min(count - xfer_cnt, sg[i].length);
3711 /* kmap_atomic() ensures addressability of the data buffer.*/
3712 /* local_irq_save() protects the KM_IRQ0 address slot. */
3713 local_irq_save(flags);
3714 buffer = kmap_atomic(sg[i].page, KM_IRQ0) + sg[i].offset;
3715 memcpy(&cdata[xfer_cnt], buffer, min_cnt);
3716 kunmap_atomic(buffer - sg[i].offset, KM_IRQ0);
3717 local_irq_restore(flags);
3719 xfer_cnt += min_cnt;
3723 unsigned int min_cnt = min(count, scmd->request_bufflen);
3724 memcpy(data, scmd->request_buffer, min_cnt);
3728 /****************************************************************************/
3730 /* Routine Name: ips_send_cmd */
3732 /* Routine Description: */
3734 /* Map SCSI commands to ServeRAID commands for logical drives */
3736 /****************************************************************************/
3738 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3743 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3746 METHOD_TRACE("ips_send_cmd", 1);
3750 if (!scb->scsi_cmd) {
3751 /* internal command */
3754 /* Controller commands can't be issued */
3755 /* to real devices -- fail them */
3756 if ((ha->waitflag == TRUE) &&
3757 (ha->cmd_in_progress == scb->cdb[0])) {
3758 ha->waitflag = FALSE;
3763 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3764 /* command to logical bus -- interpret */
3765 ret = IPS_SUCCESS_IMM;
3767 switch (scb->scsi_cmd->cmnd[0]) {
3768 case ALLOW_MEDIUM_REMOVAL:
3771 case WRITE_FILEMARKS:
3773 scb->scsi_cmd->result = DID_ERROR << 16;
3777 scb->scsi_cmd->result = DID_OK << 16;
3779 case TEST_UNIT_READY:
3781 if (scb->target_id == IPS_ADAPTER_ID) {
3783 * Either we have a TUR
3784 * or we have a SCSI inquiry
3786 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3787 scb->scsi_cmd->result = DID_OK << 16;
3789 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3790 IPS_SCSI_INQ_DATA inquiry;
3793 sizeof (IPS_SCSI_INQ_DATA));
3795 inquiry.DeviceType =
3796 IPS_SCSI_INQ_TYPE_PROCESSOR;
3797 inquiry.DeviceTypeQualifier =
3798 IPS_SCSI_INQ_LU_CONNECTED;
3799 inquiry.Version = IPS_SCSI_INQ_REV2;
3800 inquiry.ResponseDataFormat =
3801 IPS_SCSI_INQ_RD_REV2;
3802 inquiry.AdditionalLength = 31;
3804 IPS_SCSI_INQ_Address16;
3806 IPS_SCSI_INQ_WBus16 |
3808 strncpy(inquiry.VendorId, "IBM ",
3810 strncpy(inquiry.ProductId,
3812 strncpy(inquiry.ProductRevisionLevel,
3815 ips_scmd_buf_write(scb->scsi_cmd,
3819 scb->scsi_cmd->result = DID_OK << 16;
3822 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3823 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3824 scb->cmd.logical_info.reserved = 0;
3825 scb->cmd.logical_info.reserved2 = 0;
3826 scb->data_len = sizeof (IPS_LD_INFO);
3827 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3829 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3836 ips_reqsen(ha, scb);
3837 scb->scsi_cmd->result = DID_OK << 16;
3843 scb->cmd.basic_io.op_code =
3844 (scb->scsi_cmd->cmnd[0] ==
3845 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3846 scb->cmd.basic_io.enhanced_sg = 0;
3847 scb->cmd.basic_io.sg_addr =
3848 cpu_to_le32(scb->data_busaddr);
3850 scb->cmd.basic_io.op_code =
3851 (scb->scsi_cmd->cmnd[0] ==
3852 READ_6) ? IPS_CMD_READ_SG :
3854 scb->cmd.basic_io.enhanced_sg =
3855 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3856 scb->cmd.basic_io.sg_addr =
3857 cpu_to_le32(scb->sg_busaddr);
3860 scb->cmd.basic_io.segment_4G = 0;
3861 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3862 scb->cmd.basic_io.log_drv = scb->target_id;
3863 scb->cmd.basic_io.sg_count = scb->sg_len;
3865 if (scb->cmd.basic_io.lba)
3866 scb->cmd.basic_io.lba =
3867 cpu_to_le32(le32_to_cpu
3868 (scb->cmd.basic_io.lba) +
3869 le16_to_cpu(scb->cmd.basic_io.
3872 scb->cmd.basic_io.lba =
3874 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3876 (scb->scsi_cmd->cmnd[3]));
3878 scb->cmd.basic_io.sector_count =
3879 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3881 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3882 scb->cmd.basic_io.sector_count =
3891 scb->cmd.basic_io.op_code =
3892 (scb->scsi_cmd->cmnd[0] ==
3893 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3894 scb->cmd.basic_io.enhanced_sg = 0;
3895 scb->cmd.basic_io.sg_addr =
3896 cpu_to_le32(scb->data_busaddr);
3898 scb->cmd.basic_io.op_code =
3899 (scb->scsi_cmd->cmnd[0] ==
3900 READ_10) ? IPS_CMD_READ_SG :
3902 scb->cmd.basic_io.enhanced_sg =
3903 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3904 scb->cmd.basic_io.sg_addr =
3905 cpu_to_le32(scb->sg_busaddr);
3908 scb->cmd.basic_io.segment_4G = 0;
3909 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3910 scb->cmd.basic_io.log_drv = scb->target_id;
3911 scb->cmd.basic_io.sg_count = scb->sg_len;
3913 if (scb->cmd.basic_io.lba)
3914 scb->cmd.basic_io.lba =
3915 cpu_to_le32(le32_to_cpu
3916 (scb->cmd.basic_io.lba) +
3917 le16_to_cpu(scb->cmd.basic_io.
3920 scb->cmd.basic_io.lba =
3921 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3925 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3928 scb->cmd.basic_io.sector_count =
3929 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3931 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3933 * This is a null condition
3934 * we don't have to do anything
3937 scb->scsi_cmd->result = DID_OK << 16;
3945 scb->scsi_cmd->result = DID_OK << 16;
3949 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3950 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3951 scb->cmd.basic_io.segment_4G = 0;
3952 scb->cmd.basic_io.enhanced_sg = 0;
3953 scb->data_len = sizeof (*ha->enq);
3954 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3959 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3960 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3961 scb->cmd.logical_info.reserved = 0;
3962 scb->cmd.logical_info.reserved2 = 0;
3963 scb->cmd.logical_info.reserved3 = 0;
3964 scb->data_len = sizeof (IPS_LD_INFO);
3965 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3967 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3971 case SEND_DIAGNOSTIC:
3972 case REASSIGN_BLOCKS:
3976 case READ_DEFECT_DATA:
3979 scb->scsi_cmd->result = DID_OK << 16;
3983 /* Set the Return Info to appear like the Command was */
3984 /* attempted, a Check Condition occurred, and Sense */
3985 /* Data indicating an Invalid CDB OpCode is returned. */
3986 sp = (char *) scb->scsi_cmd->sense_buffer;
3987 memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
3989 sp[0] = 0x70; /* Error Code */
3990 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3991 sp[7] = 0x0A; /* Additional Sense Length */
3992 sp[12] = 0x20; /* ASC = Invalid OpCode */
3993 sp[13] = 0x00; /* ASCQ */
3995 device_error = 2; /* Indicate Check Condition */
3996 scb->scsi_cmd->result = device_error | (DID_OK << 16);
4001 if (ret == IPS_SUCCESS_IMM)
4007 /* If we already know the Device is Not there, no need to attempt a Command */
4008 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
4009 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
4010 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
4011 return (IPS_SUCCESS_IMM);
4014 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
4015 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
4016 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
4017 (unsigned long) &scb->
4019 (unsigned long) scb);
4020 scb->cmd.dcdb.reserved = 0;
4021 scb->cmd.dcdb.reserved2 = 0;
4022 scb->cmd.dcdb.reserved3 = 0;
4023 scb->cmd.dcdb.segment_4G = 0;
4024 scb->cmd.dcdb.enhanced_sg = 0;
4026 TimeOut = scb->scsi_cmd->timeout_per_command;
4028 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
4030 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
4032 scb->cmd.dcdb.op_code =
4033 IPS_CMD_EXTENDED_DCDB_SG;
4034 scb->cmd.dcdb.enhanced_sg =
4035 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4038 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
4039 tapeDCDB->device_address =
4040 ((scb->bus - 1) << 4) | scb->target_id;
4041 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4042 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
4045 if (TimeOut < (10 * HZ))
4046 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4047 else if (TimeOut < (60 * HZ))
4048 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4049 else if (TimeOut < (1200 * HZ))
4050 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4053 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
4054 tapeDCDB->reserved_for_LUN = 0;
4055 tapeDCDB->transfer_length = scb->data_len;
4056 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
4057 tapeDCDB->buffer_pointer =
4058 cpu_to_le32(scb->sg_busaddr);
4060 tapeDCDB->buffer_pointer =
4061 cpu_to_le32(scb->data_busaddr);
4062 tapeDCDB->sg_count = scb->sg_len;
4063 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
4064 tapeDCDB->scsi_status = 0;
4065 tapeDCDB->reserved = 0;
4066 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
4067 scb->scsi_cmd->cmd_len);
4070 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
4072 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
4073 scb->cmd.dcdb.enhanced_sg =
4074 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4077 scb->dcdb.device_address =
4078 ((scb->bus - 1) << 4) | scb->target_id;
4079 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4082 if (TimeOut < (10 * HZ))
4083 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4084 else if (TimeOut < (60 * HZ))
4085 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4086 else if (TimeOut < (1200 * HZ))
4087 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4090 scb->dcdb.transfer_length = scb->data_len;
4091 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
4092 scb->dcdb.transfer_length = 0;
4093 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
4094 scb->dcdb.buffer_pointer =
4095 cpu_to_le32(scb->sg_busaddr);
4097 scb->dcdb.buffer_pointer =
4098 cpu_to_le32(scb->data_busaddr);
4099 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
4100 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
4101 scb->dcdb.sg_count = scb->sg_len;
4102 scb->dcdb.reserved = 0;
4103 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
4104 scb->scsi_cmd->cmd_len);
4105 scb->dcdb.scsi_status = 0;
4106 scb->dcdb.reserved2[0] = 0;
4107 scb->dcdb.reserved2[1] = 0;
4108 scb->dcdb.reserved2[2] = 0;
4112 return ((*ha->func.issue) (ha, scb));
4115 /****************************************************************************/
4117 /* Routine Name: ips_chk_status */
4119 /* Routine Description: */
4121 /* Check the status of commands to logical drives */
4122 /* Assumed to be called with the HA lock */
4123 /****************************************************************************/
4125 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
4129 uint8_t basic_status;
4132 IPS_SCSI_INQ_DATA inquiryData;
4134 METHOD_TRACE("ips_chkstatus", 1);
4136 scb = &ha->scbs[pstatus->fields.command_id];
4137 scb->basic_status = basic_status =
4138 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
4139 scb->extended_status = ext_status = pstatus->fields.extended_status;
4142 sp->residue_len = 0;
4143 sp->scb_addr = (void *) scb;
4145 /* Remove the item from the active queue */
4146 ips_removeq_scb(&ha->scb_activelist, scb);
4149 /* internal commands are handled in do_ipsintr */
4152 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
4156 scb->cmd.basic_io.command_id,
4157 scb->bus, scb->target_id, scb->lun);
4159 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
4160 /* passthru - just returns the raw result */
4165 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
4166 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
4168 if (scb->bus == 0) {
4169 if ((basic_status & IPS_GSC_STATUS_MASK) ==
4170 IPS_CMD_RECOVERED_ERROR) {
4172 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4173 ips_name, ha->host_num,
4174 scb->cmd.basic_io.op_code,
4175 basic_status, ext_status);
4178 switch (scb->scsi_cmd->cmnd[0]) {
4179 case ALLOW_MEDIUM_REMOVAL:
4182 case WRITE_FILEMARKS:
4184 errcode = DID_ERROR;
4190 case TEST_UNIT_READY:
4191 if (!ips_online(ha, scb)) {
4192 errcode = DID_TIME_OUT;
4197 if (ips_online(ha, scb)) {
4198 ips_inquiry(ha, scb);
4200 errcode = DID_TIME_OUT;
4205 ips_reqsen(ha, scb);
4217 if (!ips_online(ha, scb)
4218 || !ips_msense(ha, scb)) {
4219 errcode = DID_ERROR;
4224 if (ips_online(ha, scb))
4227 errcode = DID_TIME_OUT;
4231 case SEND_DIAGNOSTIC:
4232 case REASSIGN_BLOCKS:
4236 errcode = DID_ERROR;
4241 case READ_DEFECT_DATA:
4247 errcode = DID_ERROR;
4250 scb->scsi_cmd->result = errcode << 16;
4251 } else { /* bus == 0 */
4252 /* restrict access to physical drives */
4253 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
4254 ips_scmd_buf_read(scb->scsi_cmd,
4255 &inquiryData, sizeof (inquiryData));
4256 if ((inquiryData.DeviceType & 0x1f) == TYPE_DISK)
4257 scb->scsi_cmd->result = DID_TIME_OUT << 16;
4260 } else { /* recovered error / success */
4261 if (scb->bus == 0) {
4263 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4264 ips_name, ha->host_num,
4265 scb->cmd.basic_io.op_code, basic_status,
4269 ips_map_status(ha, scb, sp);
4273 /****************************************************************************/
4275 /* Routine Name: ips_online */
4277 /* Routine Description: */
4279 /* Determine if a logical drive is online */
4281 /****************************************************************************/
4283 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4285 METHOD_TRACE("ips_online", 1);
4287 if (scb->target_id >= IPS_MAX_LD)
4290 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4291 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4295 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4297 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4299 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4301 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4308 /****************************************************************************/
4310 /* Routine Name: ips_inquiry */
4312 /* Routine Description: */
4314 /* Simulate an inquiry command to a logical drive */
4316 /****************************************************************************/
4318 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4320 IPS_SCSI_INQ_DATA inquiry;
4322 METHOD_TRACE("ips_inquiry", 1);
4324 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4326 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4327 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4328 inquiry.Version = IPS_SCSI_INQ_REV2;
4329 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4330 inquiry.AdditionalLength = 31;
4331 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4333 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4334 strncpy(inquiry.VendorId, "IBM ", 8);
4335 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4336 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4338 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4343 /****************************************************************************/
4345 /* Routine Name: ips_rdcap */
4347 /* Routine Description: */
4349 /* Simulate a read capacity command to a logical drive */
4351 /****************************************************************************/
4353 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4355 IPS_SCSI_CAPACITY cap;
4357 METHOD_TRACE("ips_rdcap", 1);
4359 if (scb->scsi_cmd->request_bufflen < 8)
4363 cpu_to_be32(le32_to_cpu
4364 (ha->logical_drive_info->
4365 drive_info[scb->target_id].sector_count) - 1);
4366 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4368 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4373 /****************************************************************************/
4375 /* Routine Name: ips_msense */
4377 /* Routine Description: */
4379 /* Simulate a mode sense command to a logical drive */
4381 /****************************************************************************/
4383 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4388 IPS_SCSI_MODE_PAGE_DATA mdata;
4390 METHOD_TRACE("ips_msense", 1);
4392 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4393 (ha->enq->ucMiscFlag & 0x8) == 0) {
4394 heads = IPS_NORM_HEADS;
4395 sectors = IPS_NORM_SECTORS;
4397 heads = IPS_COMP_HEADS;
4398 sectors = IPS_COMP_SECTORS;
4402 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4403 1) / (heads * sectors);
4405 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4407 mdata.hdr.BlockDescLength = 8;
4409 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4410 case 0x03: /* page 3 */
4411 mdata.pdata.pg3.PageCode = 3;
4412 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4413 mdata.hdr.DataLength =
4414 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4415 mdata.pdata.pg3.TracksPerZone = 0;
4416 mdata.pdata.pg3.AltSectorsPerZone = 0;
4417 mdata.pdata.pg3.AltTracksPerZone = 0;
4418 mdata.pdata.pg3.AltTracksPerVolume = 0;
4419 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4420 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4421 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4422 mdata.pdata.pg3.TrackSkew = 0;
4423 mdata.pdata.pg3.CylinderSkew = 0;
4424 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4428 mdata.pdata.pg4.PageCode = 4;
4429 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4430 mdata.hdr.DataLength =
4431 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4432 mdata.pdata.pg4.CylindersHigh =
4433 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4434 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4435 mdata.pdata.pg4.Heads = heads;
4436 mdata.pdata.pg4.WritePrecompHigh = 0;
4437 mdata.pdata.pg4.WritePrecompLow = 0;
4438 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4439 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4440 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4441 mdata.pdata.pg4.LandingZoneHigh = 0;
4442 mdata.pdata.pg4.LandingZoneLow = 0;
4443 mdata.pdata.pg4.flags = 0;
4444 mdata.pdata.pg4.RotationalOffset = 0;
4445 mdata.pdata.pg4.MediumRotationRate = 0;
4448 mdata.pdata.pg8.PageCode = 8;
4449 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4450 mdata.hdr.DataLength =
4451 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4452 /* everything else is left set to 0 */
4459 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4464 /****************************************************************************/
4466 /* Routine Name: ips_reqsen */
4468 /* Routine Description: */
4470 /* Simulate a request sense command to a logical drive */
4472 /****************************************************************************/
4474 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4476 IPS_SCSI_REQSEN reqsen;
4478 METHOD_TRACE("ips_reqsen", 1);
4480 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4482 reqsen.ResponseCode =
4483 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4484 reqsen.AdditionalLength = 10;
4485 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4486 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4488 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4493 /****************************************************************************/
4495 /* Routine Name: ips_free */
4497 /* Routine Description: */
4499 /* Free any allocated space for this controller */
4501 /****************************************************************************/
4503 ips_free(ips_ha_t * ha)
4506 METHOD_TRACE("ips_free", 1);
4510 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4511 ha->enq, ha->enq_busaddr);
4519 pci_free_consistent(ha->pcidev,
4520 sizeof (IPS_ADAPTER) +
4521 sizeof (IPS_IO_CMD), ha->adapt,
4522 ha->adapt->hw_status_start);
4526 if (ha->logical_drive_info) {
4527 pci_free_consistent(ha->pcidev,
4528 sizeof (IPS_LD_INFO),
4529 ha->logical_drive_info,
4530 ha->logical_drive_info_dma_addr);
4531 ha->logical_drive_info = NULL;
4540 if (ha->ioctl_data) {
4541 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4542 ha->ioctl_data, ha->ioctl_busaddr);
4543 ha->ioctl_data = NULL;
4544 ha->ioctl_datasize = 0;
4547 ips_deallocatescbs(ha, ha->max_cmds);
4549 /* free memory mapped (if applicable) */
4551 iounmap(ha->ioremap_ptr);
4552 ha->ioremap_ptr = NULL;
4557 release_mem_region(ha->mem_addr, ha->mem_len);
4563 /****************************************************************************/
4565 /* Routine Name: ips_deallocatescbs */
4567 /* Routine Description: */
4569 /* Free the command blocks */
4571 /****************************************************************************/
4573 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4576 pci_free_consistent(ha->pcidev,
4577 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4578 ha->scbs->sg_list.list,
4579 ha->scbs->sg_busaddr);
4580 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4581 ha->scbs, ha->scbs->scb_busaddr);
4587 /****************************************************************************/
4589 /* Routine Name: ips_allocatescbs */
4591 /* Routine Description: */
4593 /* Allocate the command blocks */
4595 /****************************************************************************/
4597 ips_allocatescbs(ips_ha_t * ha)
4602 dma_addr_t command_dma, sg_dma;
4604 METHOD_TRACE("ips_allocatescbs", 1);
4606 /* Allocate memory for the SCBs */
4608 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4610 if (ha->scbs == NULL)
4613 pci_alloc_consistent(ha->pcidev,
4614 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4615 ha->max_cmds, &sg_dma);
4616 if (ips_sg.list == NULL) {
4617 pci_free_consistent(ha->pcidev,
4618 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4623 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4625 for (i = 0; i < ha->max_cmds; i++) {
4626 scb_p = &ha->scbs[i];
4627 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4628 /* set up S/G list */
4629 if (IPS_USE_ENH_SGLIST(ha)) {
4630 scb_p->sg_list.enh_list =
4631 ips_sg.enh_list + i * IPS_MAX_SG;
4633 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4635 scb_p->sg_list.std_list =
4636 ips_sg.std_list + i * IPS_MAX_SG;
4638 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4641 /* add to the free list */
4642 if (i < ha->max_cmds - 1) {
4643 scb_p->q_next = ha->scb_freelist;
4644 ha->scb_freelist = scb_p;
4652 /****************************************************************************/
4654 /* Routine Name: ips_init_scb */
4656 /* Routine Description: */
4658 /* Initialize a CCB to default values */
4660 /****************************************************************************/
4662 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4664 IPS_SG_LIST sg_list;
4665 uint32_t cmd_busaddr, sg_busaddr;
4666 METHOD_TRACE("ips_init_scb", 1);
4671 sg_list.list = scb->sg_list.list;
4672 cmd_busaddr = scb->scb_busaddr;
4673 sg_busaddr = scb->sg_busaddr;
4675 memset(scb, 0, sizeof (ips_scb_t));
4676 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4678 /* Initialize dummy command bucket */
4679 ha->dummy->op_code = 0xFF;
4680 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4681 + sizeof (IPS_ADAPTER));
4682 ha->dummy->command_id = IPS_MAX_CMDS;
4684 /* set bus address of scb */
4685 scb->scb_busaddr = cmd_busaddr;
4686 scb->sg_busaddr = sg_busaddr;
4687 scb->sg_list.list = sg_list.list;
4690 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4691 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4692 + sizeof (IPS_ADAPTER));
4695 /****************************************************************************/
4697 /* Routine Name: ips_get_scb */
4699 /* Routine Description: */
4701 /* Initialize a CCB to default values */
4703 /* ASSUMED to be callled from within a lock */
4705 /****************************************************************************/
4707 ips_getscb(ips_ha_t * ha)
4711 METHOD_TRACE("ips_getscb", 1);
4713 if ((scb = ha->scb_freelist) == NULL) {
4718 ha->scb_freelist = scb->q_next;
4722 ips_init_scb(ha, scb);
4727 /****************************************************************************/
4729 /* Routine Name: ips_free_scb */
4731 /* Routine Description: */
4733 /* Return an unused CCB back to the free list */
4735 /* ASSUMED to be called from within a lock */
4737 /****************************************************************************/
4739 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4742 METHOD_TRACE("ips_freescb", 1);
4743 if (scb->flags & IPS_SCB_MAP_SG)
4744 pci_unmap_sg(ha->pcidev, scb->scsi_cmd->request_buffer,
4745 scb->scsi_cmd->use_sg, IPS_DMA_DIR(scb));
4746 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4747 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4750 /* check to make sure this is not our "special" scb */
4751 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4752 scb->q_next = ha->scb_freelist;
4753 ha->scb_freelist = scb;
4757 /****************************************************************************/
4759 /* Routine Name: ips_isinit_copperhead */
4761 /* Routine Description: */
4763 /* Is controller initialized ? */
4765 /****************************************************************************/
4767 ips_isinit_copperhead(ips_ha_t * ha)
4772 METHOD_TRACE("ips_isinit_copperhead", 1);
4774 isr = inb(ha->io_addr + IPS_REG_HISR);
4775 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4777 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4783 /****************************************************************************/
4785 /* Routine Name: ips_isinit_copperhead_memio */
4787 /* Routine Description: */
4789 /* Is controller initialized ? */
4791 /****************************************************************************/
4793 ips_isinit_copperhead_memio(ips_ha_t * ha)
4798 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4800 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4801 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4803 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4809 /****************************************************************************/
4811 /* Routine Name: ips_isinit_morpheus */
4813 /* Routine Description: */
4815 /* Is controller initialized ? */
4817 /****************************************************************************/
4819 ips_isinit_morpheus(ips_ha_t * ha)
4824 METHOD_TRACE("ips_is_init_morpheus", 1);
4826 if (ips_isintr_morpheus(ha))
4827 ips_flush_and_reset(ha);
4829 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4830 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4834 else if (bits & 0x3)
4840 /****************************************************************************/
4842 /* Routine Name: ips_flush_and_reset */
4844 /* Routine Description: */
4846 /* Perform cleanup ( FLUSH and RESET ) when the adapter is in an unknown */
4847 /* state ( was trying to INIT and an interrupt was already pending ) ... */
4849 /****************************************************************************/
4851 ips_flush_and_reset(ips_ha_t *ha)
4857 dma_addr_t command_dma;
4859 /* Create a usuable SCB */
4860 scb = pci_alloc_consistent(ha->pcidev, sizeof(ips_scb_t), &command_dma);
4862 memset(scb, 0, sizeof(ips_scb_t));
4863 ips_init_scb(ha, scb);
4864 scb->scb_busaddr = command_dma;
4866 scb->timeout = ips_cmd_timeout;
4867 scb->cdb[0] = IPS_CMD_FLUSH;
4869 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
4870 scb->cmd.flush_cache.command_id = IPS_MAX_CMDS; /* Use an ID that would otherwise not exist */
4871 scb->cmd.flush_cache.state = IPS_NORM_STATE;
4872 scb->cmd.flush_cache.reserved = 0;
4873 scb->cmd.flush_cache.reserved2 = 0;
4874 scb->cmd.flush_cache.reserved3 = 0;
4875 scb->cmd.flush_cache.reserved4 = 0;
4877 ret = ips_send_cmd(ha, scb); /* Send the Flush Command */
4879 if (ret == IPS_SUCCESS) {
4880 time = 60 * IPS_ONE_SEC; /* Max Wait time is 60 seconds */
4883 while ((time > 0) && (!done)) {
4884 done = ips_poll_for_flush_complete(ha);
4885 /* This may look evil, but it's only done during extremely rare start-up conditions ! */
4892 /* Now RESET and INIT the adapter */
4893 (*ha->func.reset) (ha);
4895 pci_free_consistent(ha->pcidev, sizeof(ips_scb_t), scb, command_dma);
4899 /****************************************************************************/
4901 /* Routine Name: ips_poll_for_flush_complete */
4903 /* Routine Description: */
4905 /* Poll for the Flush Command issued by ips_flush_and_reset() to complete */
4906 /* All other responses are just taken off the queue and ignored */
4908 /****************************************************************************/
4910 ips_poll_for_flush_complete(ips_ha_t * ha)
4915 cstatus.value = (*ha->func.statupd) (ha);
4917 if (cstatus.value == 0xffffffff) /* If No Interrupt to process */
4920 /* Success is when we see the Flush Command ID */
4921 if (cstatus.fields.command_id == IPS_MAX_CMDS )
4928 /****************************************************************************/
4930 /* Routine Name: ips_enable_int_copperhead */
4932 /* Routine Description: */
4933 /* Turn on interrupts */
4935 /****************************************************************************/
4937 ips_enable_int_copperhead(ips_ha_t * ha)
4939 METHOD_TRACE("ips_enable_int_copperhead", 1);
4941 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4942 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4945 /****************************************************************************/
4947 /* Routine Name: ips_enable_int_copperhead_memio */
4949 /* Routine Description: */
4950 /* Turn on interrupts */
4952 /****************************************************************************/
4954 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4956 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4958 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4959 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4962 /****************************************************************************/
4964 /* Routine Name: ips_enable_int_morpheus */
4966 /* Routine Description: */
4967 /* Turn on interrupts */
4969 /****************************************************************************/
4971 ips_enable_int_morpheus(ips_ha_t * ha)
4975 METHOD_TRACE("ips_enable_int_morpheus", 1);
4977 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4979 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4980 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4983 /****************************************************************************/
4985 /* Routine Name: ips_init_copperhead */
4987 /* Routine Description: */
4989 /* Initialize a copperhead controller */
4991 /****************************************************************************/
4993 ips_init_copperhead(ips_ha_t * ha)
4997 uint8_t PostByte[IPS_MAX_POST_BYTES];
4998 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
5001 METHOD_TRACE("ips_init_copperhead", 1);
5003 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
5004 for (j = 0; j < 45; j++) {
5005 Isr = inb(ha->io_addr + IPS_REG_HISR);
5006 if (Isr & IPS_BIT_GHI)
5009 /* Delay for 1 Second */
5010 msleep(IPS_ONE_SEC);
5014 /* error occurred */
5017 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
5018 outb(Isr, ha->io_addr + IPS_REG_HISR);
5021 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5022 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5023 "reset controller fails (post status %x %x).\n",
5024 PostByte[0], PostByte[1]);
5029 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5030 for (j = 0; j < 240; j++) {
5031 Isr = inb(ha->io_addr + IPS_REG_HISR);
5032 if (Isr & IPS_BIT_GHI)
5035 /* Delay for 1 Second */
5036 msleep(IPS_ONE_SEC);
5040 /* error occurred */
5043 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
5044 outb(Isr, ha->io_addr + IPS_REG_HISR);
5047 for (i = 0; i < 240; i++) {
5048 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
5050 if ((Cbsp & IPS_BIT_OP) == 0)
5053 /* Delay for 1 Second */
5054 msleep(IPS_ONE_SEC);
5062 outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
5064 /* Enable busmastering */
5065 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
5067 if (ha->revision_id == IPS_REVID_TROMBONE64)
5068 /* fix for anaconda64 */
5069 outl(0, ha->io_addr + IPS_REG_NDAE);
5071 /* Enable interrupts */
5072 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
5077 /****************************************************************************/
5079 /* Routine Name: ips_init_copperhead_memio */
5081 /* Routine Description: */
5083 /* Initialize a copperhead controller with memory mapped I/O */
5085 /****************************************************************************/
5087 ips_init_copperhead_memio(ips_ha_t * ha)
5091 uint8_t PostByte[IPS_MAX_POST_BYTES];
5092 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
5095 METHOD_TRACE("ips_init_copperhead_memio", 1);
5097 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
5098 for (j = 0; j < 45; j++) {
5099 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5100 if (Isr & IPS_BIT_GHI)
5103 /* Delay for 1 Second */
5104 msleep(IPS_ONE_SEC);
5108 /* error occurred */
5111 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5112 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5115 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5116 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5117 "reset controller fails (post status %x %x).\n",
5118 PostByte[0], PostByte[1]);
5123 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5124 for (j = 0; j < 240; j++) {
5125 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5126 if (Isr & IPS_BIT_GHI)
5129 /* Delay for 1 Second */
5130 msleep(IPS_ONE_SEC);
5134 /* error occurred */
5137 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5138 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5141 for (i = 0; i < 240; i++) {
5142 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
5144 if ((Cbsp & IPS_BIT_OP) == 0)
5147 /* Delay for 1 Second */
5148 msleep(IPS_ONE_SEC);
5152 /* error occurred */
5156 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
5158 /* Enable busmastering */
5159 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
5161 if (ha->revision_id == IPS_REVID_TROMBONE64)
5162 /* fix for anaconda64 */
5163 writel(0, ha->mem_ptr + IPS_REG_NDAE);
5165 /* Enable interrupts */
5166 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
5168 /* if we get here then everything went OK */
5172 /****************************************************************************/
5174 /* Routine Name: ips_init_morpheus */
5176 /* Routine Description: */
5178 /* Initialize a morpheus controller */
5180 /****************************************************************************/
5182 ips_init_morpheus(ips_ha_t * ha)
5190 METHOD_TRACE("ips_init_morpheus", 1);
5192 /* Wait up to 45 secs for Post */
5193 for (i = 0; i < 45; i++) {
5194 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5196 if (Isr & IPS_BIT_I960_MSG0I)
5199 /* Delay for 1 Second */
5200 msleep(IPS_ONE_SEC);
5204 /* error occurred */
5205 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5206 "timeout waiting for post.\n");
5211 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5213 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
5214 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5215 "Flashing Battery PIC, Please wait ...\n");
5217 /* Clear the interrupt bit */
5218 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5219 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5221 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
5222 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5225 /* Delay for 1 Second */
5226 msleep(IPS_ONE_SEC);
5230 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5231 "timeout waiting for Battery PIC Flash\n");
5237 /* Clear the interrupt bit */
5238 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5239 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5241 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
5242 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5243 "reset controller fails (post status %x).\n", Post);
5248 /* Wait up to 240 secs for config bytes */
5249 for (i = 0; i < 240; i++) {
5250 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5252 if (Isr & IPS_BIT_I960_MSG1I)
5255 /* Delay for 1 Second */
5256 msleep(IPS_ONE_SEC);
5260 /* error occurred */
5261 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5262 "timeout waiting for config.\n");
5267 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
5269 /* Clear interrupt bit */
5270 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
5271 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5273 /* Turn on the interrupts */
5274 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
5276 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
5278 /* if we get here then everything went OK */
5280 /* Since we did a RESET, an EraseStripeLock may be needed */
5281 if (Post == 0xEF10) {
5282 if ((Config == 0x000F) || (Config == 0x0009))
5283 ha->requires_esl = 1;
5289 /****************************************************************************/
5291 /* Routine Name: ips_reset_copperhead */
5293 /* Routine Description: */
5295 /* Reset the controller */
5297 /****************************************************************************/
5299 ips_reset_copperhead(ips_ha_t * ha)
5303 METHOD_TRACE("ips_reset_copperhead", 1);
5305 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5306 ips_name, ha->host_num, ha->io_addr, ha->irq);
5310 while (reset_counter < 2) {
5313 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5315 /* Delay for 1 Second */
5316 msleep(IPS_ONE_SEC);
5318 outb(0, ha->io_addr + IPS_REG_SCPR);
5320 /* Delay for 1 Second */
5321 msleep(IPS_ONE_SEC);
5323 if ((*ha->func.init) (ha))
5325 else if (reset_counter >= 2) {
5334 /****************************************************************************/
5336 /* Routine Name: ips_reset_copperhead_memio */
5338 /* Routine Description: */
5340 /* Reset the controller */
5342 /****************************************************************************/
5344 ips_reset_copperhead_memio(ips_ha_t * ha)
5348 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5350 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5351 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5355 while (reset_counter < 2) {
5358 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5360 /* Delay for 1 Second */
5361 msleep(IPS_ONE_SEC);
5363 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5365 /* Delay for 1 Second */
5366 msleep(IPS_ONE_SEC);
5368 if ((*ha->func.init) (ha))
5370 else if (reset_counter >= 2) {
5379 /****************************************************************************/
5381 /* Routine Name: ips_reset_morpheus */
5383 /* Routine Description: */
5385 /* Reset the controller */
5387 /****************************************************************************/
5389 ips_reset_morpheus(ips_ha_t * ha)
5394 METHOD_TRACE("ips_reset_morpheus", 1);
5396 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5397 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5401 while (reset_counter < 2) {
5404 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5406 /* Delay for 5 Seconds */
5407 msleep(5 * IPS_ONE_SEC);
5409 /* Do a PCI config read to wait for adapter */
5410 pci_read_config_byte(ha->pcidev, 4, &junk);
5412 if ((*ha->func.init) (ha))
5414 else if (reset_counter >= 2) {
5423 /****************************************************************************/
5425 /* Routine Name: ips_statinit */
5427 /* Routine Description: */
5429 /* Initialize the status queues on the controller */
5431 /****************************************************************************/
5433 ips_statinit(ips_ha_t * ha)
5435 uint32_t phys_status_start;
5437 METHOD_TRACE("ips_statinit", 1);
5439 ha->adapt->p_status_start = ha->adapt->status;
5440 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5441 ha->adapt->p_status_tail = ha->adapt->status;
5443 phys_status_start = ha->adapt->hw_status_start;
5444 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
5445 outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE),
5446 ha->io_addr + IPS_REG_SQER);
5447 outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE),
5448 ha->io_addr + IPS_REG_SQHR);
5449 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
5451 ha->adapt->hw_status_tail = phys_status_start;
5454 /****************************************************************************/
5456 /* Routine Name: ips_statinit_memio */
5458 /* Routine Description: */
5460 /* Initialize the status queues on the controller */
5462 /****************************************************************************/
5464 ips_statinit_memio(ips_ha_t * ha)
5466 uint32_t phys_status_start;
5468 METHOD_TRACE("ips_statinit_memio", 1);
5470 ha->adapt->p_status_start = ha->adapt->status;
5471 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5472 ha->adapt->p_status_tail = ha->adapt->status;
5474 phys_status_start = ha->adapt->hw_status_start;
5475 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5476 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5477 ha->mem_ptr + IPS_REG_SQER);
5478 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5479 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5481 ha->adapt->hw_status_tail = phys_status_start;
5484 /****************************************************************************/
5486 /* Routine Name: ips_statupd_copperhead */
5488 /* Routine Description: */
5490 /* Remove an element from the status queue */
5492 /****************************************************************************/
5494 ips_statupd_copperhead(ips_ha_t * ha)
5496 METHOD_TRACE("ips_statupd_copperhead", 1);
5498 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5499 ha->adapt->p_status_tail++;
5500 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5502 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5503 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5506 outl(cpu_to_le32(ha->adapt->hw_status_tail),
5507 ha->io_addr + IPS_REG_SQTR);
5509 return (ha->adapt->p_status_tail->value);
5512 /****************************************************************************/
5514 /* Routine Name: ips_statupd_copperhead_memio */
5516 /* Routine Description: */
5518 /* Remove an element from the status queue */
5520 /****************************************************************************/
5522 ips_statupd_copperhead_memio(ips_ha_t * ha)
5524 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5526 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5527 ha->adapt->p_status_tail++;
5528 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5530 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5531 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5534 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5536 return (ha->adapt->p_status_tail->value);
5539 /****************************************************************************/
5541 /* Routine Name: ips_statupd_morpheus */
5543 /* Routine Description: */
5545 /* Remove an element from the status queue */
5547 /****************************************************************************/
5549 ips_statupd_morpheus(ips_ha_t * ha)
5553 METHOD_TRACE("ips_statupd_morpheus", 1);
5555 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5560 /****************************************************************************/
5562 /* Routine Name: ips_issue_copperhead */
5564 /* Routine Description: */
5566 /* Send a command down to the controller */
5568 /****************************************************************************/
5570 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5575 METHOD_TRACE("ips_issue_copperhead", 1);
5577 if (scb->scsi_cmd) {
5578 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5582 scb->cmd.basic_io.command_id,
5583 scb->bus, scb->target_id, scb->lun);
5585 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5586 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5592 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5595 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5596 if (!(val & IPS_BIT_START_STOP))
5599 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5600 "ips_issue val [0x%x].\n", val);
5601 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5602 "ips_issue semaphore chk timeout.\n");
5604 return (IPS_FAILURE);
5608 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
5609 outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
5611 return (IPS_SUCCESS);
5614 /****************************************************************************/
5616 /* Routine Name: ips_issue_copperhead_memio */
5618 /* Routine Description: */
5620 /* Send a command down to the controller */
5622 /****************************************************************************/
5624 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5629 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5631 if (scb->scsi_cmd) {
5632 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5636 scb->cmd.basic_io.command_id,
5637 scb->bus, scb->target_id, scb->lun);
5639 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5640 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5645 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5648 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5649 if (!(val & IPS_BIT_START_STOP))
5652 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5653 "ips_issue val [0x%x].\n", val);
5654 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5655 "ips_issue semaphore chk timeout.\n");
5657 return (IPS_FAILURE);
5661 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5662 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5664 return (IPS_SUCCESS);
5667 /****************************************************************************/
5669 /* Routine Name: ips_issue_i2o */
5671 /* Routine Description: */
5673 /* Send a command down to the controller */
5675 /****************************************************************************/
5677 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5680 METHOD_TRACE("ips_issue_i2o", 1);
5682 if (scb->scsi_cmd) {
5683 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5687 scb->cmd.basic_io.command_id,
5688 scb->bus, scb->target_id, scb->lun);
5690 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5691 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5694 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
5696 return (IPS_SUCCESS);
5699 /****************************************************************************/
5701 /* Routine Name: ips_issue_i2o_memio */
5703 /* Routine Description: */
5705 /* Send a command down to the controller */
5707 /****************************************************************************/
5709 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5712 METHOD_TRACE("ips_issue_i2o_memio", 1);
5714 if (scb->scsi_cmd) {
5715 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5719 scb->cmd.basic_io.command_id,
5720 scb->bus, scb->target_id, scb->lun);
5722 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5723 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5726 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5728 return (IPS_SUCCESS);
5731 /****************************************************************************/
5733 /* Routine Name: ips_isintr_copperhead */
5735 /* Routine Description: */
5737 /* Test to see if an interrupt is for us */
5739 /****************************************************************************/
5741 ips_isintr_copperhead(ips_ha_t * ha)
5745 METHOD_TRACE("ips_isintr_copperhead", 2);
5747 Isr = inb(ha->io_addr + IPS_REG_HISR);
5750 /* ?!?! Nothing really there */
5753 if (Isr & IPS_BIT_SCE)
5755 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5756 /* status queue overflow or GHI */
5757 /* just clear the interrupt */
5758 outb(Isr, ha->io_addr + IPS_REG_HISR);
5764 /****************************************************************************/
5766 /* Routine Name: ips_isintr_copperhead_memio */
5768 /* Routine Description: */
5770 /* Test to see if an interrupt is for us */
5772 /****************************************************************************/
5774 ips_isintr_copperhead_memio(ips_ha_t * ha)
5778 METHOD_TRACE("ips_isintr_memio", 2);
5780 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5783 /* ?!?! Nothing really there */
5786 if (Isr & IPS_BIT_SCE)
5788 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5789 /* status queue overflow or GHI */
5790 /* just clear the interrupt */
5791 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5797 /****************************************************************************/
5799 /* Routine Name: ips_isintr_morpheus */
5801 /* Routine Description: */
5803 /* Test to see if an interrupt is for us */
5805 /****************************************************************************/
5807 ips_isintr_morpheus(ips_ha_t * ha)
5811 METHOD_TRACE("ips_isintr_morpheus", 2);
5813 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5815 if (Isr & IPS_BIT_I2O_OPQI)
5821 /****************************************************************************/
5823 /* Routine Name: ips_wait */
5825 /* Routine Description: */
5827 /* Wait for a command to complete */
5829 /****************************************************************************/
5831 ips_wait(ips_ha_t * ha, int time, int intr)
5836 METHOD_TRACE("ips_wait", 1);
5841 time *= IPS_ONE_SEC; /* convert seconds */
5843 while ((time > 0) && (!done)) {
5844 if (intr == IPS_INTR_ON) {
5845 if (ha->waitflag == FALSE) {
5850 } else if (intr == IPS_INTR_IORL) {
5851 if (ha->waitflag == FALSE) {
5853 * controller generated an interrupt to
5854 * acknowledge completion of the command
5855 * and ips_intr() has serviced the interrupt.
5863 * NOTE: we already have the io_request_lock so
5864 * even if we get an interrupt it won't get serviced
5865 * until after we finish.
5868 (*ha->func.intr) (ha);
5871 /* This looks like a very evil loop, but it only does this during start-up */
5879 /****************************************************************************/
5881 /* Routine Name: ips_write_driver_status */
5883 /* Routine Description: */
5885 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5887 /****************************************************************************/
5889 ips_write_driver_status(ips_ha_t * ha, int intr)
5891 METHOD_TRACE("ips_write_driver_status", 1);
5893 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5894 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5895 "unable to read NVRAM page 5.\n");
5900 /* check to make sure the page has a valid */
5902 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5904 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5905 ips_name, ha->host_num, ha->nvram->signature);
5906 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5910 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5911 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5912 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5913 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5914 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5915 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5916 ha->nvram->bios_low[3]);
5918 ips_get_bios_version(ha, intr);
5920 /* change values (as needed) */
5921 ha->nvram->operating_system = IPS_OS_LINUX;
5922 ha->nvram->adapter_type = ha->ad_type;
5923 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5924 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5925 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5926 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5928 ha->nvram->versioning = 0; /* Indicate the Driver Does Not Support Versioning */
5930 /* now update the page */
5931 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5932 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5933 "unable to write NVRAM page 5.\n");
5938 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5939 ha->slot_num = ha->nvram->adapter_slot;
5944 /****************************************************************************/
5946 /* Routine Name: ips_read_adapter_status */
5948 /* Routine Description: */
5950 /* Do an Inquiry command to the adapter */
5952 /****************************************************************************/
5954 ips_read_adapter_status(ips_ha_t * ha, int intr)
5959 METHOD_TRACE("ips_read_adapter_status", 1);
5961 scb = &ha->scbs[ha->max_cmds - 1];
5963 ips_init_scb(ha, scb);
5965 scb->timeout = ips_cmd_timeout;
5966 scb->cdb[0] = IPS_CMD_ENQUIRY;
5968 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5969 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5970 scb->cmd.basic_io.sg_count = 0;
5971 scb->cmd.basic_io.lba = 0;
5972 scb->cmd.basic_io.sector_count = 0;
5973 scb->cmd.basic_io.log_drv = 0;
5974 scb->data_len = sizeof (*ha->enq);
5975 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5979 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5980 || (ret == IPS_SUCCESS_IMM)
5981 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5987 /****************************************************************************/
5989 /* Routine Name: ips_read_subsystem_parameters */
5991 /* Routine Description: */
5993 /* Read subsystem parameters from the adapter */
5995 /****************************************************************************/
5997 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
6002 METHOD_TRACE("ips_read_subsystem_parameters", 1);
6004 scb = &ha->scbs[ha->max_cmds - 1];
6006 ips_init_scb(ha, scb);
6008 scb->timeout = ips_cmd_timeout;
6009 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
6011 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
6012 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
6013 scb->cmd.basic_io.sg_count = 0;
6014 scb->cmd.basic_io.lba = 0;
6015 scb->cmd.basic_io.sector_count = 0;
6016 scb->cmd.basic_io.log_drv = 0;
6017 scb->data_len = sizeof (*ha->subsys);
6018 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
6022 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6023 || (ret == IPS_SUCCESS_IMM)
6024 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6027 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
6031 /****************************************************************************/
6033 /* Routine Name: ips_read_config */
6035 /* Routine Description: */
6037 /* Read the configuration on the adapter */
6039 /****************************************************************************/
6041 ips_read_config(ips_ha_t * ha, int intr)
6047 METHOD_TRACE("ips_read_config", 1);
6049 /* set defaults for initiator IDs */
6050 for (i = 0; i < 4; i++)
6051 ha->conf->init_id[i] = 7;
6053 scb = &ha->scbs[ha->max_cmds - 1];
6055 ips_init_scb(ha, scb);
6057 scb->timeout = ips_cmd_timeout;
6058 scb->cdb[0] = IPS_CMD_READ_CONF;
6060 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
6061 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
6062 scb->data_len = sizeof (*ha->conf);
6063 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
6067 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6068 || (ret == IPS_SUCCESS_IMM)
6069 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6071 memset(ha->conf, 0, sizeof (IPS_CONF));
6073 /* reset initiator IDs */
6074 for (i = 0; i < 4; i++)
6075 ha->conf->init_id[i] = 7;
6077 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
6078 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
6079 IPS_CMD_CMPLT_WERROR)
6085 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
6089 /****************************************************************************/
6091 /* Routine Name: ips_readwrite_page5 */
6093 /* Routine Description: */
6095 /* Read nvram page 5 from the adapter */
6097 /****************************************************************************/
6099 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
6104 METHOD_TRACE("ips_readwrite_page5", 1);
6106 scb = &ha->scbs[ha->max_cmds - 1];
6108 ips_init_scb(ha, scb);
6110 scb->timeout = ips_cmd_timeout;
6111 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
6113 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
6114 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
6115 scb->cmd.nvram.page = 5;
6116 scb->cmd.nvram.write = write;
6117 scb->cmd.nvram.reserved = 0;
6118 scb->cmd.nvram.reserved2 = 0;
6119 scb->data_len = sizeof (*ha->nvram);
6120 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
6122 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
6124 /* issue the command */
6126 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6127 || (ret == IPS_SUCCESS_IMM)
6128 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6130 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
6135 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
6139 /****************************************************************************/
6141 /* Routine Name: ips_clear_adapter */
6143 /* Routine Description: */
6145 /* Clear the stripe lock tables */
6147 /****************************************************************************/
6149 ips_clear_adapter(ips_ha_t * ha, int intr)
6154 METHOD_TRACE("ips_clear_adapter", 1);
6156 scb = &ha->scbs[ha->max_cmds - 1];
6158 ips_init_scb(ha, scb);
6160 scb->timeout = ips_reset_timeout;
6161 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
6163 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
6164 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
6165 scb->cmd.config_sync.channel = 0;
6166 scb->cmd.config_sync.source_target = IPS_POCL;
6167 scb->cmd.config_sync.reserved = 0;
6168 scb->cmd.config_sync.reserved2 = 0;
6169 scb->cmd.config_sync.reserved3 = 0;
6173 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
6174 || (ret == IPS_SUCCESS_IMM)
6175 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6178 /* send unlock stripe command */
6179 ips_init_scb(ha, scb);
6181 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
6182 scb->timeout = ips_reset_timeout;
6184 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
6185 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
6186 scb->cmd.unlock_stripe.log_drv = 0;
6187 scb->cmd.unlock_stripe.control = IPS_CSL;
6188 scb->cmd.unlock_stripe.reserved = 0;
6189 scb->cmd.unlock_stripe.reserved2 = 0;
6190 scb->cmd.unlock_stripe.reserved3 = 0;
6194 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6195 || (ret == IPS_SUCCESS_IMM)
6196 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6202 /****************************************************************************/
6204 /* Routine Name: ips_ffdc_reset */
6206 /* Routine Description: */
6208 /* FFDC: write reset info */
6210 /****************************************************************************/
6212 ips_ffdc_reset(ips_ha_t * ha, int intr)
6216 METHOD_TRACE("ips_ffdc_reset", 1);
6218 scb = &ha->scbs[ha->max_cmds - 1];
6220 ips_init_scb(ha, scb);
6222 scb->timeout = ips_cmd_timeout;
6223 scb->cdb[0] = IPS_CMD_FFDC;
6224 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6225 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6226 scb->cmd.ffdc.reset_count = ha->reset_count;
6227 scb->cmd.ffdc.reset_type = 0x80;
6229 /* convert time to what the card wants */
6230 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6233 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6236 /****************************************************************************/
6238 /* Routine Name: ips_ffdc_time */
6240 /* Routine Description: */
6242 /* FFDC: write time info */
6244 /****************************************************************************/
6246 ips_ffdc_time(ips_ha_t * ha)
6250 METHOD_TRACE("ips_ffdc_time", 1);
6252 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
6254 scb = &ha->scbs[ha->max_cmds - 1];
6256 ips_init_scb(ha, scb);
6258 scb->timeout = ips_cmd_timeout;
6259 scb->cdb[0] = IPS_CMD_FFDC;
6260 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6261 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6262 scb->cmd.ffdc.reset_count = 0;
6263 scb->cmd.ffdc.reset_type = 0;
6265 /* convert time to what the card wants */
6266 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6269 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
6272 /****************************************************************************/
6274 /* Routine Name: ips_fix_ffdc_time */
6276 /* Routine Description: */
6277 /* Adjust time_t to what the card wants */
6279 /****************************************************************************/
6281 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6288 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6289 int month_lengths[12][2] = { {31, 31},
6303 METHOD_TRACE("ips_fix_ffdc_time", 1);
6305 days = current_time / IPS_SECS_DAY;
6306 rem = current_time % IPS_SECS_DAY;
6308 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6309 rem = rem % IPS_SECS_HOUR;
6310 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6311 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6313 year = IPS_EPOCH_YEAR;
6314 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6317 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6320 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6321 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6322 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6326 scb->cmd.ffdc.yearH = year / 100;
6327 scb->cmd.ffdc.yearL = year % 100;
6329 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6330 days -= month_lengths[i][yleap];
6332 scb->cmd.ffdc.month = i + 1;
6333 scb->cmd.ffdc.day = days + 1;
6336 /****************************************************************************
6337 * BIOS Flash Routines *
6338 ****************************************************************************/
6340 /****************************************************************************/
6342 /* Routine Name: ips_erase_bios */
6344 /* Routine Description: */
6345 /* Erase the BIOS on the adapter */
6347 /****************************************************************************/
6349 ips_erase_bios(ips_ha_t * ha)
6354 METHOD_TRACE("ips_erase_bios", 1);
6358 /* Clear the status register */
6359 outl(0, ha->io_addr + IPS_REG_FLAP);
6360 if (ha->revision_id == IPS_REVID_TROMBONE64)
6361 udelay(25); /* 25 us */
6363 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6364 if (ha->revision_id == IPS_REVID_TROMBONE64)
6365 udelay(25); /* 25 us */
6368 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6369 if (ha->revision_id == IPS_REVID_TROMBONE64)
6370 udelay(25); /* 25 us */
6373 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6374 if (ha->revision_id == IPS_REVID_TROMBONE64)
6375 udelay(25); /* 25 us */
6378 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6379 if (ha->revision_id == IPS_REVID_TROMBONE64)
6380 udelay(25); /* 25 us */
6382 timeout = 80000; /* 80 seconds */
6384 while (timeout > 0) {
6385 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6386 outl(0, ha->io_addr + IPS_REG_FLAP);
6387 udelay(25); /* 25 us */
6390 status = inb(ha->io_addr + IPS_REG_FLDP);
6399 /* check for timeout */
6403 /* try to suspend the erase */
6404 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6405 if (ha->revision_id == IPS_REVID_TROMBONE64)
6406 udelay(25); /* 25 us */
6408 /* wait for 10 seconds */
6410 while (timeout > 0) {
6411 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6412 outl(0, ha->io_addr + IPS_REG_FLAP);
6413 udelay(25); /* 25 us */
6416 status = inb(ha->io_addr + IPS_REG_FLDP);
6428 /* check for valid VPP */
6433 /* check for successful flash */
6435 /* sequence error */
6438 /* Otherwise, we were successful */
6440 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6441 if (ha->revision_id == IPS_REVID_TROMBONE64)
6442 udelay(25); /* 25 us */
6445 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6446 if (ha->revision_id == IPS_REVID_TROMBONE64)
6447 udelay(25); /* 25 us */
6452 /****************************************************************************/
6454 /* Routine Name: ips_erase_bios_memio */
6456 /* Routine Description: */
6457 /* Erase the BIOS on the adapter */
6459 /****************************************************************************/
6461 ips_erase_bios_memio(ips_ha_t * ha)
6466 METHOD_TRACE("ips_erase_bios_memio", 1);
6470 /* Clear the status register */
6471 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6472 if (ha->revision_id == IPS_REVID_TROMBONE64)
6473 udelay(25); /* 25 us */
6475 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6476 if (ha->revision_id == IPS_REVID_TROMBONE64)
6477 udelay(25); /* 25 us */
6480 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6481 if (ha->revision_id == IPS_REVID_TROMBONE64)
6482 udelay(25); /* 25 us */
6485 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6486 if (ha->revision_id == IPS_REVID_TROMBONE64)
6487 udelay(25); /* 25 us */
6490 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6491 if (ha->revision_id == IPS_REVID_TROMBONE64)
6492 udelay(25); /* 25 us */
6494 timeout = 80000; /* 80 seconds */
6496 while (timeout > 0) {
6497 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6498 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6499 udelay(25); /* 25 us */
6502 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6511 /* check for timeout */
6515 /* try to suspend the erase */
6516 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6517 if (ha->revision_id == IPS_REVID_TROMBONE64)
6518 udelay(25); /* 25 us */
6520 /* wait for 10 seconds */
6522 while (timeout > 0) {
6523 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6524 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6525 udelay(25); /* 25 us */
6528 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6540 /* check for valid VPP */
6545 /* check for successful flash */
6547 /* sequence error */
6550 /* Otherwise, we were successful */
6552 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6553 if (ha->revision_id == IPS_REVID_TROMBONE64)
6554 udelay(25); /* 25 us */
6557 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6558 if (ha->revision_id == IPS_REVID_TROMBONE64)
6559 udelay(25); /* 25 us */
6564 /****************************************************************************/
6566 /* Routine Name: ips_program_bios */
6568 /* Routine Description: */
6569 /* Program the BIOS on the adapter */
6571 /****************************************************************************/
6573 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6580 METHOD_TRACE("ips_program_bios", 1);
6584 for (i = 0; i < buffersize; i++) {
6586 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6587 if (ha->revision_id == IPS_REVID_TROMBONE64)
6588 udelay(25); /* 25 us */
6590 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6591 if (ha->revision_id == IPS_REVID_TROMBONE64)
6592 udelay(25); /* 25 us */
6594 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6595 if (ha->revision_id == IPS_REVID_TROMBONE64)
6596 udelay(25); /* 25 us */
6598 /* wait up to one second */
6600 while (timeout > 0) {
6601 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6602 outl(0, ha->io_addr + IPS_REG_FLAP);
6603 udelay(25); /* 25 us */
6606 status = inb(ha->io_addr + IPS_REG_FLDP);
6617 outl(0, ha->io_addr + IPS_REG_FLAP);
6618 if (ha->revision_id == IPS_REVID_TROMBONE64)
6619 udelay(25); /* 25 us */
6621 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6622 if (ha->revision_id == IPS_REVID_TROMBONE64)
6623 udelay(25); /* 25 us */
6628 /* check the status */
6629 if (status & 0x18) {
6630 /* programming error */
6631 outl(0, ha->io_addr + IPS_REG_FLAP);
6632 if (ha->revision_id == IPS_REVID_TROMBONE64)
6633 udelay(25); /* 25 us */
6635 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6636 if (ha->revision_id == IPS_REVID_TROMBONE64)
6637 udelay(25); /* 25 us */
6643 /* Enable reading */
6644 outl(0, ha->io_addr + IPS_REG_FLAP);
6645 if (ha->revision_id == IPS_REVID_TROMBONE64)
6646 udelay(25); /* 25 us */
6648 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6649 if (ha->revision_id == IPS_REVID_TROMBONE64)
6650 udelay(25); /* 25 us */
6655 /****************************************************************************/
6657 /* Routine Name: ips_program_bios_memio */
6659 /* Routine Description: */
6660 /* Program the BIOS on the adapter */
6662 /****************************************************************************/
6664 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6671 METHOD_TRACE("ips_program_bios_memio", 1);
6675 for (i = 0; i < buffersize; i++) {
6677 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6678 if (ha->revision_id == IPS_REVID_TROMBONE64)
6679 udelay(25); /* 25 us */
6681 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6682 if (ha->revision_id == IPS_REVID_TROMBONE64)
6683 udelay(25); /* 25 us */
6685 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6686 if (ha->revision_id == IPS_REVID_TROMBONE64)
6687 udelay(25); /* 25 us */
6689 /* wait up to one second */
6691 while (timeout > 0) {
6692 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6693 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6694 udelay(25); /* 25 us */
6697 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6708 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6709 if (ha->revision_id == IPS_REVID_TROMBONE64)
6710 udelay(25); /* 25 us */
6712 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6713 if (ha->revision_id == IPS_REVID_TROMBONE64)
6714 udelay(25); /* 25 us */
6719 /* check the status */
6720 if (status & 0x18) {
6721 /* programming error */
6722 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6723 if (ha->revision_id == IPS_REVID_TROMBONE64)
6724 udelay(25); /* 25 us */
6726 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6727 if (ha->revision_id == IPS_REVID_TROMBONE64)
6728 udelay(25); /* 25 us */
6734 /* Enable reading */
6735 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6736 if (ha->revision_id == IPS_REVID_TROMBONE64)
6737 udelay(25); /* 25 us */
6739 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6740 if (ha->revision_id == IPS_REVID_TROMBONE64)
6741 udelay(25); /* 25 us */
6746 /****************************************************************************/
6748 /* Routine Name: ips_verify_bios */
6750 /* Routine Description: */
6751 /* Verify the BIOS on the adapter */
6753 /****************************************************************************/
6755 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6761 METHOD_TRACE("ips_verify_bios", 1);
6764 outl(0, ha->io_addr + IPS_REG_FLAP);
6765 if (ha->revision_id == IPS_REVID_TROMBONE64)
6766 udelay(25); /* 25 us */
6768 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6771 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
6772 if (ha->revision_id == IPS_REVID_TROMBONE64)
6773 udelay(25); /* 25 us */
6774 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6778 for (i = 2; i < buffersize; i++) {
6780 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6781 if (ha->revision_id == IPS_REVID_TROMBONE64)
6782 udelay(25); /* 25 us */
6784 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6795 /****************************************************************************/
6797 /* Routine Name: ips_verify_bios_memio */
6799 /* Routine Description: */
6800 /* Verify the BIOS on the adapter */
6802 /****************************************************************************/
6804 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6810 METHOD_TRACE("ips_verify_bios_memio", 1);
6813 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6814 if (ha->revision_id == IPS_REVID_TROMBONE64)
6815 udelay(25); /* 25 us */
6817 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6820 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6821 if (ha->revision_id == IPS_REVID_TROMBONE64)
6822 udelay(25); /* 25 us */
6823 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6827 for (i = 2; i < buffersize; i++) {
6829 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6830 if (ha->revision_id == IPS_REVID_TROMBONE64)
6831 udelay(25); /* 25 us */
6834 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6845 /****************************************************************************/
6847 /* Routine Name: ips_abort_init */
6849 /* Routine Description: */
6850 /* cleanup routine for a failed adapter initialization */
6851 /****************************************************************************/
6853 ips_abort_init(ips_ha_t * ha, int index)
6857 ips_ha[index] = NULL;
6858 ips_sh[index] = NULL;
6862 /****************************************************************************/
6864 /* Routine Name: ips_shift_controllers */
6866 /* Routine Description: */
6867 /* helper function for ordering adapters */
6868 /****************************************************************************/
6870 ips_shift_controllers(int lowindex, int highindex)
6872 ips_ha_t *ha_sav = ips_ha[highindex];
6873 struct Scsi_Host *sh_sav = ips_sh[highindex];
6876 for (i = highindex; i > lowindex; i--) {
6877 ips_ha[i] = ips_ha[i - 1];
6878 ips_sh[i] = ips_sh[i - 1];
6879 ips_ha[i]->host_num = i;
6881 ha_sav->host_num = lowindex;
6882 ips_ha[lowindex] = ha_sav;
6883 ips_sh[lowindex] = sh_sav;
6886 /****************************************************************************/
6888 /* Routine Name: ips_order_controllers */
6890 /* Routine Description: */
6891 /* place controllers is the "proper" boot order */
6892 /****************************************************************************/
6894 ips_order_controllers(void)
6896 int i, j, tmp, position = 0;
6897 IPS_NVRAM_P5 *nvram;
6900 nvram = ips_ha[0]->nvram;
6902 if (nvram->adapter_order[0]) {
6903 for (i = 1; i <= nvram->adapter_order[0]; i++) {
6904 for (j = position; j < ips_num_controllers; j++) {
6905 switch (ips_ha[j]->ad_type) {
6906 case IPS_ADTYPE_SERVERAID6M:
6907 case IPS_ADTYPE_SERVERAID7M:
6908 if (nvram->adapter_order[i] == 'M') {
6909 ips_shift_controllers(position,
6914 case IPS_ADTYPE_SERVERAID4L:
6915 case IPS_ADTYPE_SERVERAID4M:
6916 case IPS_ADTYPE_SERVERAID4MX:
6917 case IPS_ADTYPE_SERVERAID4LX:
6918 if (nvram->adapter_order[i] == 'N') {
6919 ips_shift_controllers(position,
6924 case IPS_ADTYPE_SERVERAID6I:
6925 case IPS_ADTYPE_SERVERAID5I2:
6926 case IPS_ADTYPE_SERVERAID5I1:
6927 case IPS_ADTYPE_SERVERAID7k:
6928 if (nvram->adapter_order[i] == 'S') {
6929 ips_shift_controllers(position,
6934 case IPS_ADTYPE_SERVERAID:
6935 case IPS_ADTYPE_SERVERAID2:
6936 case IPS_ADTYPE_NAVAJO:
6937 case IPS_ADTYPE_KIOWA:
6938 case IPS_ADTYPE_SERVERAID3L:
6939 case IPS_ADTYPE_SERVERAID3:
6940 case IPS_ADTYPE_SERVERAID4H:
6941 if (nvram->adapter_order[i] == 'A') {
6942 ips_shift_controllers(position,
6952 /* if adapter_order[0], then ordering is complete */
6955 /* old bios, use older ordering */
6957 for (i = position; i < ips_num_controllers; i++) {
6958 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I2 ||
6959 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I1) {
6960 ips_shift_controllers(position, i);
6965 /* if there were no 5I cards, then don't do any extra ordering */
6968 for (i = position; i < ips_num_controllers; i++) {
6969 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4L ||
6970 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4M ||
6971 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4LX ||
6972 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4MX) {
6973 ips_shift_controllers(position, i);
6981 /****************************************************************************/
6983 /* Routine Name: ips_register_scsi */
6985 /* Routine Description: */
6986 /* perform any registration and setup with the scsi layer */
6987 /****************************************************************************/
6989 ips_register_scsi(int index)
6991 struct Scsi_Host *sh;
6992 ips_ha_t *ha, *oldha = ips_ha[index];
6993 sh = scsi_host_alloc(&ips_driver_template, sizeof (ips_ha_t));
6995 IPS_PRINTK(KERN_WARNING, oldha->pcidev,
6996 "Unable to register controller with SCSI subsystem\n");
7000 memcpy(ha, oldha, sizeof (ips_ha_t));
7001 free_irq(oldha->irq, oldha);
7002 /* Install the interrupt handler with the new ha */
7003 if (request_irq(ha->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
7004 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7005 "Unable to install interrupt handler\n");
7013 IPS_SCSI_SET_DEVICE(sh, ha);
7015 /* Store away needed values for later use */
7016 sh->io_port = ha->io_addr;
7017 sh->n_io_port = ha->io_addr ? 255 : 0;
7018 sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
7020 sh->sg_tablesize = sh->hostt->sg_tablesize;
7021 sh->can_queue = sh->hostt->can_queue;
7022 sh->cmd_per_lun = sh->hostt->cmd_per_lun;
7023 sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
7024 sh->use_clustering = sh->hostt->use_clustering;
7026 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
7027 sh->max_sectors = 128;
7030 sh->max_id = ha->ntargets;
7031 sh->max_lun = ha->nlun;
7032 sh->max_channel = ha->nbus - 1;
7033 sh->can_queue = ha->max_cmds - 1;
7035 IPS_ADD_HOST(sh, NULL);
7039 /*---------------------------------------------------------------------------*/
7040 /* Routine Name: ips_remove_device */
7042 /* Routine Description: */
7043 /* Remove one Adapter ( Hot Plugging ) */
7044 /*---------------------------------------------------------------------------*/
7045 static void __devexit
7046 ips_remove_device(struct pci_dev *pci_dev)
7049 struct Scsi_Host *sh;
7052 for (i = 0; i < IPS_MAX_ADAPTERS; i++) {
7055 if ((pci_dev->bus->number == ha->pcidev->bus->number) &&
7056 (pci_dev->devfn == ha->pcidev->devfn)) {
7064 /****************************************************************************/
7066 /* Routine Name: ips_module_init */
7068 /* Routine Description: */
7069 /* function called on module load */
7070 /****************************************************************************/
7072 ips_module_init(void)
7074 if (pci_register_driver(&ips_pci_driver) < 0)
7076 ips_driver_template.module = THIS_MODULE;
7077 ips_order_controllers();
7078 if (IPS_REGISTER_HOSTS(&ips_driver_template)) {
7079 pci_unregister_driver(&ips_pci_driver);
7082 register_reboot_notifier(&ips_notifier);
7086 /****************************************************************************/
7088 /* Routine Name: ips_module_exit */
7090 /* Routine Description: */
7091 /* function called on module unload */
7092 /****************************************************************************/
7094 ips_module_exit(void)
7096 IPS_UNREGISTER_HOSTS(&ips_driver_template);
7097 pci_unregister_driver(&ips_pci_driver);
7098 unregister_reboot_notifier(&ips_notifier);
7101 module_init(ips_module_init);
7102 module_exit(ips_module_exit);
7104 /*---------------------------------------------------------------------------*/
7105 /* Routine Name: ips_insert_device */
7107 /* Routine Description: */
7108 /* Add One Adapter ( Hot Plug ) */
7111 /* 0 if Successful, else non-zero */
7112 /*---------------------------------------------------------------------------*/
7113 static int __devinit
7114 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
7119 METHOD_TRACE("ips_insert_device", 1);
7120 if (pci_enable_device(pci_dev))
7123 rc = ips_init_phase1(pci_dev, &index);
7125 rc = ips_init_phase2(index);
7128 if (ips_register_scsi(index)) {
7129 ips_free(ips_ha[index]);
7134 ips_num_controllers++;
7136 ips_next_controller = ips_num_controllers;
7140 /*---------------------------------------------------------------------------*/
7141 /* Routine Name: ips_init_phase1 */
7143 /* Routine Description: */
7144 /* Adapter Initialization */
7147 /* 0 if Successful, else non-zero */
7148 /*---------------------------------------------------------------------------*/
7150 ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
7157 uint8_t revision_id;
7161 uint16_t subdevice_id;
7164 dma_addr_t dma_address;
7165 char __iomem *ioremap_ptr;
7166 char __iomem *mem_ptr;
7169 METHOD_TRACE("ips_init_phase1", 1);
7170 index = IPS_MAX_ADAPTERS;
7171 for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
7172 if (ips_ha[j] == 0) {
7178 if (index >= IPS_MAX_ADAPTERS)
7181 /* stuff that we get in dev */
7183 bus = pci_dev->bus->number;
7184 func = pci_dev->devfn;
7186 /* Init MEM/IO addresses to 0 */
7192 for (j = 0; j < 2; j++) {
7193 if (!pci_resource_start(pci_dev, j))
7196 if (pci_resource_flags(pci_dev, j) & IORESOURCE_IO) {
7197 io_addr = pci_resource_start(pci_dev, j);
7198 io_len = pci_resource_len(pci_dev, j);
7200 mem_addr = pci_resource_start(pci_dev, j);
7201 mem_len = pci_resource_len(pci_dev, j);
7205 /* setup memory mapped area (if applicable) */
7210 if (!request_mem_region(mem_addr, mem_len, "ips")) {
7211 IPS_PRINTK(KERN_WARNING, pci_dev,
7212 "Couldn't allocate IO Memory space %x len %d.\n",
7217 base = mem_addr & PAGE_MASK;
7218 offs = mem_addr - base;
7219 ioremap_ptr = ioremap(base, PAGE_SIZE);
7220 mem_ptr = ioremap_ptr + offs;
7226 /* setup I/O mapped area (if applicable) */
7228 if (!request_region(io_addr, io_len, "ips")) {
7229 IPS_PRINTK(KERN_WARNING, pci_dev,
7230 "Couldn't allocate IO space %x len %d.\n",
7236 /* get the revision ID */
7237 if (pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id)) {
7238 IPS_PRINTK(KERN_WARNING, pci_dev, "Can't get revision id.\n");
7242 subdevice_id = pci_dev->subsystem_device;
7244 /* found a controller */
7245 ha = kmalloc(sizeof (ips_ha_t), GFP_KERNEL);
7247 IPS_PRINTK(KERN_WARNING, pci_dev,
7248 "Unable to allocate temporary ha struct\n");
7252 memset(ha, 0, sizeof (ips_ha_t));
7254 ips_sh[index] = NULL;
7258 /* Store info in HA structure */
7260 ha->io_addr = io_addr;
7261 ha->io_len = io_len;
7262 ha->mem_addr = mem_addr;
7263 ha->mem_len = mem_len;
7264 ha->mem_ptr = mem_ptr;
7265 ha->ioremap_ptr = ioremap_ptr;
7266 ha->host_num = (uint32_t) index;
7267 ha->revision_id = revision_id;
7268 ha->slot_num = PCI_SLOT(pci_dev->devfn);
7269 ha->device_id = pci_dev->device;
7270 ha->subdevice_id = subdevice_id;
7271 ha->pcidev = pci_dev;
7274 * Set the pci_dev's dma_mask. Not all adapters support 64bit
7275 * addressing so don't enable it if the adapter can't support
7276 * it! Also, don't use 64bit addressing if dma addresses
7277 * are guaranteed to be < 4G.
7279 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
7280 !pci_set_dma_mask(ha->pcidev, DMA_64BIT_MASK)) {
7281 (ha)->flags |= IPS_HA_ENH_SG;
7283 if (pci_set_dma_mask(ha->pcidev, DMA_32BIT_MASK) != 0) {
7284 printk(KERN_WARNING "Unable to set DMA Mask\n");
7285 return ips_abort_init(ha, index);
7288 if(ips_cd_boot && !ips_FlashData){
7289 ips_FlashData = pci_alloc_consistent(pci_dev, PAGE_SIZE << 7,
7293 ha->enq = pci_alloc_consistent(pci_dev, sizeof (IPS_ENQ),
7296 IPS_PRINTK(KERN_WARNING, pci_dev,
7297 "Unable to allocate host inquiry structure\n");
7298 return ips_abort_init(ha, index);
7301 ha->adapt = pci_alloc_consistent(pci_dev, sizeof (IPS_ADAPTER) +
7302 sizeof (IPS_IO_CMD), &dma_address);
7304 IPS_PRINTK(KERN_WARNING, pci_dev,
7305 "Unable to allocate host adapt & dummy structures\n");
7306 return ips_abort_init(ha, index);
7308 ha->adapt->hw_status_start = dma_address;
7309 ha->dummy = (void *) (ha->adapt + 1);
7313 ha->logical_drive_info = pci_alloc_consistent(pci_dev, sizeof (IPS_LD_INFO), &dma_address);
7314 if (!ha->logical_drive_info) {
7315 IPS_PRINTK(KERN_WARNING, pci_dev,
7316 "Unable to allocate logical drive info structure\n");
7317 return ips_abort_init(ha, index);
7319 ha->logical_drive_info_dma_addr = dma_address;
7322 ha->conf = kmalloc(sizeof (IPS_CONF), GFP_KERNEL);
7325 IPS_PRINTK(KERN_WARNING, pci_dev,
7326 "Unable to allocate host conf structure\n");
7327 return ips_abort_init(ha, index);
7330 ha->nvram = kmalloc(sizeof (IPS_NVRAM_P5), GFP_KERNEL);
7333 IPS_PRINTK(KERN_WARNING, pci_dev,
7334 "Unable to allocate host NVRAM structure\n");
7335 return ips_abort_init(ha, index);
7338 ha->subsys = kmalloc(sizeof (IPS_SUBSYS), GFP_KERNEL);
7341 IPS_PRINTK(KERN_WARNING, pci_dev,
7342 "Unable to allocate host subsystem structure\n");
7343 return ips_abort_init(ha, index);
7346 /* the ioctl buffer is now used during adapter initialization, so its
7347 * successful allocation is now required */
7348 if (ips_ioctlsize < PAGE_SIZE)
7349 ips_ioctlsize = PAGE_SIZE;
7351 ha->ioctl_data = pci_alloc_consistent(pci_dev, ips_ioctlsize,
7352 &ha->ioctl_busaddr);
7353 ha->ioctl_len = ips_ioctlsize;
7354 if (!ha->ioctl_data) {
7355 IPS_PRINTK(KERN_WARNING, pci_dev,
7356 "Unable to allocate IOCTL data\n");
7357 return ips_abort_init(ha, index);
7363 ips_setup_funclist(ha);
7365 if ((IPS_IS_MORPHEUS(ha)) || (IPS_IS_MARCO(ha))) {
7366 /* If Morpheus appears dead, reset it */
7367 IsDead = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
7368 if (IsDead == 0xDEADBEEF) {
7369 ips_reset_morpheus(ha);
7374 * Initialize the card if it isn't already
7377 if (!(*ha->func.isinit) (ha)) {
7378 if (!(*ha->func.init) (ha)) {
7380 * Initialization failed
7382 IPS_PRINTK(KERN_WARNING, pci_dev,
7383 "Unable to initialize controller\n");
7384 return ips_abort_init(ha, index);
7392 /*---------------------------------------------------------------------------*/
7393 /* Routine Name: ips_init_phase2 */
7395 /* Routine Description: */
7396 /* Adapter Initialization Phase 2 */
7399 /* 0 if Successful, else non-zero */
7400 /*---------------------------------------------------------------------------*/
7402 ips_init_phase2(int index)
7408 METHOD_TRACE("ips_init_phase2", 1);
7410 ips_ha[index] = NULL;
7414 /* Install the interrupt handler */
7415 if (request_irq(ha->irq, do_ipsintr, IRQF_SHARED, ips_name, ha)) {
7416 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7417 "Unable to install interrupt handler\n");
7418 return ips_abort_init(ha, index);
7422 * Allocate a temporary SCB for initialization
7425 if (!ips_allocatescbs(ha)) {
7426 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7427 "Unable to allocate a CCB\n");
7428 free_irq(ha->irq, ha);
7429 return ips_abort_init(ha, index);
7432 if (!ips_hainit(ha)) {
7433 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7434 "Unable to initialize controller\n");
7435 free_irq(ha->irq, ha);
7436 return ips_abort_init(ha, index);
7438 /* Free the temporary SCB */
7439 ips_deallocatescbs(ha, 1);
7442 if (!ips_allocatescbs(ha)) {
7443 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7444 "Unable to allocate CCBs\n");
7445 free_irq(ha->irq, ha);
7446 return ips_abort_init(ha, index);
7452 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
7453 MODULE_LICENSE("GPL");
7456 MODULE_DESCRIPTION("IBM ServeRAID Adapter Driver " IPS_VER_STRING);
7458 #ifdef MODULE_VERSION
7459 MODULE_VERSION(IPS_VER_STRING);
7464 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7465 * Emacs will notice this stuff at the end of the file and automatically
7466 * adjust the settings for this buffer only. This must remain at the end
7468 * ---------------------------------------------------------------------------
7471 * c-brace-imaginary-offset: 0
7472 * c-brace-offset: -2
7473 * c-argdecl-indent: 2
7474 * c-label-offset: -2
7475 * c-continued-statement-offset: 2
7476 * c-continued-brace-offset: 0
7477 * indent-tabs-mode: nil