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 /*****************************************************************************/
139 * Conditional Compilation directives for this driver:
141 * IPS_DEBUG - Turn on debugging info
145 * debug:<number> - Set debug level to <number>
146 * NOTE: only works when IPS_DEBUG compile directive is used.
147 * 1 - Normal debug messages
148 * 2 - Verbose debug messages
149 * 11 - Method trace (non interrupt)
150 * 12 - Method trace (includes interrupt)
152 * noi2o - Don't use I2O Queues (ServeRAID 4 only)
153 * nommap - Don't use memory mapped I/O
154 * ioctlsize - Initial size of the IOCTL buffer
158 #include <asm/byteorder.h>
159 #include <asm/page.h>
160 #include <linux/stddef.h>
161 #include <linux/version.h>
162 #include <linux/string.h>
163 #include <linux/errno.h>
164 #include <linux/kernel.h>
165 #include <linux/ioport.h>
166 #include <linux/slab.h>
167 #include <linux/delay.h>
168 #include <linux/pci.h>
169 #include <linux/proc_fs.h>
170 #include <linux/reboot.h>
171 #include <linux/interrupt.h>
173 #include <linux/blkdev.h>
174 #include <linux/types.h>
179 #include <scsi/scsi_host.h>
182 #include <linux/module.h>
184 #include <linux/stat.h>
185 #include <linux/config.h>
187 #include <linux/spinlock.h>
188 #include <linux/init.h>
190 #include <linux/smp.h>
193 static char *ips = NULL;
194 MODULE_PARM(ips, "s");
200 #define IPS_VERSION_HIGH "7.00"
201 #define IPS_VERSION_LOW ".15 "
203 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
204 #warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
207 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
208 #include <linux/blk.h>
210 #define IPS_SG_ADDRESS(sg) ((sg)->address)
211 #define IPS_LOCK_SAVE(lock,flags) spin_lock_irqsave(&io_request_lock,flags)
212 #define IPS_UNLOCK_RESTORE(lock,flags) spin_unlock_irqrestore(&io_request_lock,flags)
214 #define __devexit_p(x) x
217 #define IPS_SG_ADDRESS(sg) (page_address((sg)->page) ? \
218 page_address((sg)->page)+(sg)->offset : NULL)
219 #define IPS_LOCK_SAVE(lock,flags) do{spin_lock(lock);(void)flags;}while(0)
220 #define IPS_UNLOCK_RESTORE(lock,flags) do{spin_unlock(lock);(void)flags;}while(0)
223 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
224 SCSI_DATA_NONE == scb->scsi_cmd->sc_data_direction) ? \
225 PCI_DMA_BIDIRECTIONAL : \
226 scsi_to_pci_dma_dir(scb->scsi_cmd->sc_data_direction))
229 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
230 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
231 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
233 #define METHOD_TRACE(s, i)
235 #define DEBUG_VAR(i, s, v...)
241 static const char ips_name[] = "ips";
242 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
243 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
244 static unsigned int ips_next_controller;
245 static unsigned int ips_num_controllers;
246 static unsigned int ips_released_controllers;
247 static int ips_hotplug;
248 static int ips_cmd_timeout = 60;
249 static int ips_reset_timeout = 60 * 5;
250 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
251 static int ips_force_i2o = 1; /* Always use I2O command delivery */
252 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
253 static int ips_cd_boot; /* Booting from Manager CD */
254 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
255 static dma_addr_t ips_flashbusaddr;
256 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
257 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
258 static Scsi_Host_Template ips_driver_template = {
259 .detect = ips_detect,
260 .release = ips_release,
262 .queuecommand = ips_queue,
263 .eh_abort_handler = ips_eh_abort,
264 .eh_host_reset_handler = ips_eh_reset,
266 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
267 .proc_info = ips_proc_info,
268 .slave_configure = ips_slave_configure,
270 .proc_info = ips_proc24_info,
271 .select_queue_depths = ips_select_queue_depth,
273 .bios_param = ips_biosparam,
275 .sg_tablesize = IPS_MAX_SG,
277 .use_clustering = ENABLE_CLUSTERING,
278 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
279 .use_new_eh_code = 1,
283 IPS_DEFINE_COMPAT_TABLE( Compatable ); /* Version Compatability Table */
286 /* This table describes all ServeRAID Adapters */
287 static struct pci_device_id ips_pci_table[] = {
288 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
289 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
290 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
294 MODULE_DEVICE_TABLE( pci, ips_pci_table );
296 static char ips_hot_plug_name[] = "ips";
298 static int __devinit ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
299 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
301 struct pci_driver ips_pci_driver = {
302 .name = ips_hot_plug_name,
303 .id_table = ips_pci_table,
304 .probe = ips_insert_device,
305 .remove = __devexit_p(ips_remove_device),
310 * Necessary forward function protoypes
312 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
314 #define MAX_ADAPTER_NAME 15
316 static char ips_adapter_name[][30] = {
319 "ServeRAID on motherboard",
320 "ServeRAID on motherboard",
337 static struct notifier_block ips_notifier = {
344 static char ips_command_direction[] = {
345 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
346 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
347 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
348 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
349 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
350 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
351 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
352 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
353 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
354 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
355 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
356 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
357 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
358 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
359 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
360 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
361 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
362 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
363 IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
364 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
365 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
366 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
367 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
368 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
369 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
370 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
371 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
372 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
373 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
374 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
375 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
376 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
377 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
378 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
379 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
380 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
381 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
382 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
383 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
384 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
385 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
386 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
387 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
388 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
389 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
390 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
391 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
392 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
393 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
394 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
395 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
399 * Function prototypes
401 int ips_detect(Scsi_Host_Template *);
402 int ips_release(struct Scsi_Host *);
403 int ips_eh_abort(Scsi_Cmnd *);
404 int ips_eh_reset(Scsi_Cmnd *);
405 int ips_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
406 const char *ips_info(struct Scsi_Host *);
407 irqreturn_t do_ipsintr(int, void *, struct pt_regs *);
408 static int ips_hainit(ips_ha_t *);
409 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
410 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
411 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
412 static int ips_online(ips_ha_t *, ips_scb_t *);
413 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
414 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
415 static int ips_msense(ips_ha_t *, ips_scb_t *);
416 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
417 static int ips_deallocatescbs(ips_ha_t *, int);
418 static int ips_allocatescbs(ips_ha_t *);
419 static int ips_reset_copperhead(ips_ha_t *);
420 static int ips_reset_copperhead_memio(ips_ha_t *);
421 static int ips_reset_morpheus(ips_ha_t *);
422 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
423 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
424 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
425 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
426 static int ips_isintr_copperhead(ips_ha_t *);
427 static int ips_isintr_copperhead_memio(ips_ha_t *);
428 static int ips_isintr_morpheus(ips_ha_t *);
429 static int ips_wait(ips_ha_t *, int, int);
430 static int ips_write_driver_status(ips_ha_t *, int);
431 static int ips_read_adapter_status(ips_ha_t *, int);
432 static int ips_read_subsystem_parameters(ips_ha_t *, int);
433 static int ips_read_config(ips_ha_t *, int);
434 static int ips_clear_adapter(ips_ha_t *, int);
435 static int ips_readwrite_page5(ips_ha_t *, int, int);
436 static int ips_init_copperhead(ips_ha_t *);
437 static int ips_init_copperhead_memio(ips_ha_t *);
438 static int ips_init_morpheus(ips_ha_t *);
439 static int ips_isinit_copperhead(ips_ha_t *);
440 static int ips_isinit_copperhead_memio(ips_ha_t *);
441 static int ips_isinit_morpheus(ips_ha_t *);
442 static int ips_erase_bios(ips_ha_t *);
443 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
444 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
445 static int ips_erase_bios_memio(ips_ha_t *);
446 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
447 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
448 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
449 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
450 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
451 static void ips_free_flash_copperhead(ips_ha_t * ha);
452 static void ips_get_bios_version(ips_ha_t *, int);
453 static void ips_identify_controller(ips_ha_t *);
454 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
455 static void ips_enable_int_copperhead(ips_ha_t *);
456 static void ips_enable_int_copperhead_memio(ips_ha_t *);
457 static void ips_enable_int_morpheus(ips_ha_t *);
458 static int ips_intr_copperhead(ips_ha_t *);
459 static int ips_intr_morpheus(ips_ha_t *);
460 static void ips_next(ips_ha_t *, int);
461 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
462 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
463 static void ips_done(ips_ha_t *, ips_scb_t *);
464 static void ips_free(ips_ha_t *);
465 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
466 static void ips_freescb(ips_ha_t *, ips_scb_t *);
467 static void ips_setup_funclist(ips_ha_t *);
468 static void ips_statinit(ips_ha_t *);
469 static void ips_statinit_memio(ips_ha_t *);
470 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
471 static void ips_ffdc_reset(ips_ha_t *, int);
472 static void ips_ffdc_time(ips_ha_t *);
473 static uint32_t ips_statupd_copperhead(ips_ha_t *);
474 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
475 static uint32_t ips_statupd_morpheus(ips_ha_t *);
476 static ips_scb_t *ips_getscb(ips_ha_t *);
477 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
478 static void ips_putq_wait_tail(ips_wait_queue_t *, Scsi_Cmnd *);
479 static void ips_putq_copp_tail(ips_copp_queue_t *,
480 ips_copp_wait_item_t *);
481 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
482 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
483 static Scsi_Cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
484 static Scsi_Cmnd *ips_removeq_wait(ips_wait_queue_t *, Scsi_Cmnd *);
485 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
486 ips_copp_wait_item_t *);
487 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
489 static int ips_is_passthru(Scsi_Cmnd *);
490 static int ips_make_passthru(ips_ha_t *, Scsi_Cmnd *, ips_scb_t *, int);
491 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
492 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
493 static void ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data,
495 static void ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned int count);
497 int ips_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
498 static int ips_host_info(ips_ha_t *, char *, off_t, int);
499 static void copy_mem_info(IPS_INFOSTR *, char *, int);
500 static int copy_info(IPS_INFOSTR *, char *, ...);
501 static int ips_get_version_info(ips_ha_t * ha, dma_addr_t, int intr);
502 static void ips_version_check(ips_ha_t * ha, int intr);
503 static int ips_abort_init(ips_ha_t * ha, int index);
504 static int ips_init_phase2(int index);
506 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
507 static int ips_register_scsi(int index);
508 /*--------------------------------------------------------------------------*/
509 /* Exported Functions */
510 /*--------------------------------------------------------------------------*/
512 /****************************************************************************/
514 /* Routine Name: ips_setup */
516 /* Routine Description: */
518 /* setup parameters to the driver */
520 /****************************************************************************/
522 ips_setup(char *ips_str)
528 IPS_OPTION options[] = {
529 {"noi2o", &ips_force_i2o, 0},
530 {"nommap", &ips_force_memio, 0},
531 {"ioctlsize", &ips_ioctlsize, IPS_IOCTL_SIZE},
532 {"cdboot", &ips_cd_boot, 0},
533 {"maxcmds", &MaxLiteCmds, 32},
536 /* Don't use strtok() anymore ( if 2.4 Kernel or beyond ) */
537 /* Search for value */
538 while ((key = strsep(&ips_str, ",."))) {
541 value = strchr(key, ':');
545 * We now have key/value pairs.
546 * Update the variables
548 for (i = 0; i < (sizeof (options) / sizeof (options[0])); i++) {
550 (key, options[i].option_name,
551 strlen(options[i].option_name)) == 0) {
553 *options[i].option_flag =
554 simple_strtoul(value, NULL, 0);
556 *options[i].option_flag =
557 options[i].option_value;
566 __setup("ips=", ips_setup);
568 /****************************************************************************/
570 /* Routine Name: ips_detect */
572 /* Routine Description: */
574 /* Detect and initialize the driver */
576 /* NOTE: this routine is called under the io_request_lock spinlock */
578 /****************************************************************************/
580 ips_detect(Scsi_Host_Template * SHT)
584 METHOD_TRACE("ips_detect", 1);
591 for (i = 0; i < ips_num_controllers; i++) {
592 if (ips_register_scsi(i))
594 ips_released_controllers++;
597 return (ips_num_controllers);
600 /****************************************************************************/
601 /* configure the function pointers to use the functions that will work */
602 /* with the found version of the adapter */
603 /****************************************************************************/
605 ips_setup_funclist(ips_ha_t * ha)
611 if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
612 /* morpheus / marco / sebring */
613 ha->func.isintr = ips_isintr_morpheus;
614 ha->func.isinit = ips_isinit_morpheus;
615 ha->func.issue = ips_issue_i2o_memio;
616 ha->func.init = ips_init_morpheus;
617 ha->func.statupd = ips_statupd_morpheus;
618 ha->func.reset = ips_reset_morpheus;
619 ha->func.intr = ips_intr_morpheus;
620 ha->func.enableint = ips_enable_int_morpheus;
621 } else if (IPS_USE_MEMIO(ha)) {
622 /* copperhead w/MEMIO */
623 ha->func.isintr = ips_isintr_copperhead_memio;
624 ha->func.isinit = ips_isinit_copperhead_memio;
625 ha->func.init = ips_init_copperhead_memio;
626 ha->func.statupd = ips_statupd_copperhead_memio;
627 ha->func.statinit = ips_statinit_memio;
628 ha->func.reset = ips_reset_copperhead_memio;
629 ha->func.intr = ips_intr_copperhead;
630 ha->func.erasebios = ips_erase_bios_memio;
631 ha->func.programbios = ips_program_bios_memio;
632 ha->func.verifybios = ips_verify_bios_memio;
633 ha->func.enableint = ips_enable_int_copperhead_memio;
634 if (IPS_USE_I2O_DELIVER(ha))
635 ha->func.issue = ips_issue_i2o_memio;
637 ha->func.issue = ips_issue_copperhead_memio;
640 ha->func.isintr = ips_isintr_copperhead;
641 ha->func.isinit = ips_isinit_copperhead;
642 ha->func.init = ips_init_copperhead;
643 ha->func.statupd = ips_statupd_copperhead;
644 ha->func.statinit = ips_statinit;
645 ha->func.reset = ips_reset_copperhead;
646 ha->func.intr = ips_intr_copperhead;
647 ha->func.erasebios = ips_erase_bios;
648 ha->func.programbios = ips_program_bios;
649 ha->func.verifybios = ips_verify_bios;
650 ha->func.enableint = ips_enable_int_copperhead;
652 if (IPS_USE_I2O_DELIVER(ha))
653 ha->func.issue = ips_issue_i2o;
655 ha->func.issue = ips_issue_copperhead;
659 /****************************************************************************/
661 /* Routine Name: ips_release */
663 /* Routine Description: */
665 /* Remove a driver */
667 /****************************************************************************/
669 ips_release(struct Scsi_Host *sh)
675 METHOD_TRACE("ips_release", 1);
677 for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++) ;
679 if (i == IPS_MAX_ADAPTERS) {
681 "(%s) release, invalid Scsi_Host pointer.\n", ips_name);
691 /* flush the cache on the controller */
692 scb = &ha->scbs[ha->max_cmds - 1];
694 ips_init_scb(ha, scb);
696 scb->timeout = ips_cmd_timeout;
697 scb->cdb[0] = IPS_CMD_FLUSH;
699 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
700 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
701 scb->cmd.flush_cache.state = IPS_NORM_STATE;
702 scb->cmd.flush_cache.reserved = 0;
703 scb->cmd.flush_cache.reserved2 = 0;
704 scb->cmd.flush_cache.reserved3 = 0;
705 scb->cmd.flush_cache.reserved4 = 0;
707 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
710 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) == IPS_FAILURE)
711 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Incomplete Flush.\n");
713 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Complete.\n");
718 /* free extra memory */
721 /* Free I/O Region */
723 release_region(ha->io_addr, ha->io_len);
726 free_irq(ha->irq, ha);
731 ips_released_controllers++;
736 /****************************************************************************/
738 /* Routine Name: ips_halt */
740 /* Routine Description: */
742 /* Perform cleanup when the system reboots */
744 /****************************************************************************/
746 ips_halt(struct notifier_block *nb, ulong event, void *buf)
752 if ((event != SYS_RESTART) && (event != SYS_HALT) &&
753 (event != SYS_POWER_OFF))
754 return (NOTIFY_DONE);
756 for (i = 0; i < ips_next_controller; i++) {
757 ha = (ips_ha_t *) ips_ha[i];
765 /* flush the cache on the controller */
766 scb = &ha->scbs[ha->max_cmds - 1];
768 ips_init_scb(ha, scb);
770 scb->timeout = ips_cmd_timeout;
771 scb->cdb[0] = IPS_CMD_FLUSH;
773 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
774 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
775 scb->cmd.flush_cache.state = IPS_NORM_STATE;
776 scb->cmd.flush_cache.reserved = 0;
777 scb->cmd.flush_cache.reserved2 = 0;
778 scb->cmd.flush_cache.reserved3 = 0;
779 scb->cmd.flush_cache.reserved4 = 0;
781 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
784 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) ==
786 IPS_PRINTK(KERN_WARNING, ha->pcidev,
787 "Incomplete Flush.\n");
789 IPS_PRINTK(KERN_WARNING, ha->pcidev,
790 "Flushing Complete.\n");
796 /****************************************************************************/
798 /* Routine Name: ips_eh_abort */
800 /* Routine Description: */
802 /* Abort a command (using the new error code stuff) */
803 /* Note: this routine is called under the io_request_lock */
804 /****************************************************************************/
806 ips_eh_abort(Scsi_Cmnd * SC)
809 ips_copp_wait_item_t *item;
812 METHOD_TRACE("ips_eh_abort", 1);
817 ha = (ips_ha_t *) SC->device->host->hostdata;
825 if (SC->serial_number != SC->serial_number_at_timeout) {
826 /* HMM, looks like a bogus command */
827 DEBUG(1, "Abort called with bogus scsi command");
832 /* See if the command is on the copp queue */
833 item = ha->copp_waitlist.head;
834 while ((item) && (item->scsi_cmd != SC))
839 ips_removeq_copp(&ha->copp_waitlist, item);
842 /* See if the command is on the wait queue */
843 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
844 /* command not sent yet */
847 /* command must have already been sent */
853 /****************************************************************************/
855 /* Routine Name: ips_eh_reset */
857 /* Routine Description: */
859 /* Reset the controller (with new eh error code) */
861 /* NOTE: this routine is called under the io_request_lock spinlock */
863 /****************************************************************************/
865 ips_eh_reset(Scsi_Cmnd * SC)
871 ips_copp_wait_item_t *item;
873 METHOD_TRACE("ips_eh_reset", 1);
880 DEBUG(1, "Reset called with NULL scsi command");
885 ha = (ips_ha_t *) SC->device->host->hostdata;
888 DEBUG(1, "Reset called with NULL ha struct");
896 /* See if the command is on the copp queue */
897 item = ha->copp_waitlist.head;
898 while ((item) && (item->scsi_cmd != SC))
903 ips_removeq_copp(&ha->copp_waitlist, item);
907 /* See if the command is on the wait queue */
908 if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
909 /* command not sent yet */
913 /* An explanation for the casual observer: */
914 /* Part of the function of a RAID controller is automatic error */
915 /* detection and recovery. As such, the only problem that physically */
916 /* resetting an adapter will ever fix is when, for some reason, */
917 /* the driver is not successfully communicating with the adapter. */
918 /* Therefore, we will attempt to flush this adapter. If that succeeds, */
919 /* then there's no real purpose in a physical reset. This will complete */
920 /* much faster and avoids any problems that might be caused by a */
921 /* physical reset ( such as having to fail all the outstanding I/O's ). */
923 if (ha->ioctl_reset == 0) { /* IF Not an IOCTL Requested Reset */
924 scb = &ha->scbs[ha->max_cmds - 1];
926 ips_init_scb(ha, scb);
928 scb->timeout = ips_cmd_timeout;
929 scb->cdb[0] = IPS_CMD_FLUSH;
931 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
932 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
933 scb->cmd.flush_cache.state = IPS_NORM_STATE;
934 scb->cmd.flush_cache.reserved = 0;
935 scb->cmd.flush_cache.reserved2 = 0;
936 scb->cmd.flush_cache.reserved3 = 0;
937 scb->cmd.flush_cache.reserved4 = 0;
939 /* Attempt the flush command */
940 ret = ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_IORL);
941 if (ret == IPS_SUCCESS) {
942 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
943 "Reset Request - Flushed Cache\n");
948 /* Either we can't communicate with the adapter or it's an IOCTL request */
949 /* from a utility. A physical reset is needed at this point. */
951 ha->ioctl_reset = 0; /* Reset the IOCTL Requested Reset Flag */
954 * command must have already been sent
955 * reset the controller
957 IPS_PRINTK(KERN_NOTICE, ha->pcidev, "Resetting controller.\n");
958 ret = (*ha->func.reset) (ha);
963 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
964 "Controller reset failed - controller now offline.\n");
966 /* Now fail all of the active commands */
967 DEBUG_VAR(1, "(%s%d) Failing active commands",
968 ips_name, ha->host_num);
970 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
971 scb->scsi_cmd->result = DID_ERROR << 16;
972 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
973 ips_freescb(ha, scb);
976 /* Now fail all of the pending commands */
977 DEBUG_VAR(1, "(%s%d) Failing pending commands",
978 ips_name, ha->host_num);
980 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
981 scsi_cmd->result = DID_ERROR;
982 scsi_cmd->scsi_done(scsi_cmd);
989 if (!ips_clear_adapter(ha, IPS_INTR_IORL)) {
992 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
993 "Controller reset failed - controller now offline.\n");
995 /* Now fail all of the active commands */
996 DEBUG_VAR(1, "(%s%d) Failing active commands",
997 ips_name, ha->host_num);
999 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1000 scb->scsi_cmd->result = DID_ERROR << 16;
1001 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1002 ips_freescb(ha, scb);
1005 /* Now fail all of the pending commands */
1006 DEBUG_VAR(1, "(%s%d) Failing pending commands",
1007 ips_name, ha->host_num);
1009 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
1010 scsi_cmd->result = DID_ERROR << 16;
1011 scsi_cmd->scsi_done(scsi_cmd);
1019 if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
1022 do_gettimeofday(&tv);
1023 ha->last_ffdc = tv.tv_sec;
1025 ips_ffdc_reset(ha, IPS_INTR_IORL);
1028 /* Now fail all of the active commands */
1029 DEBUG_VAR(1, "(%s%d) Failing active commands", ips_name, ha->host_num);
1031 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1032 scb->scsi_cmd->result =
1033 (DID_RESET << 16) | (SUGGEST_RETRY << 24);
1034 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1035 ips_freescb(ha, scb);
1038 /* Reset DCDB active command bits */
1039 for (i = 1; i < ha->nbus; i++)
1040 ha->dcdb_active[i - 1] = 0;
1042 /* Reset the number of active IOCTLs */
1045 ips_next(ha, IPS_INTR_IORL);
1048 #endif /* NO_IPS_RESET */
1052 /****************************************************************************/
1054 /* Routine Name: ips_queue */
1056 /* Routine Description: */
1058 /* Send a command to the controller */
1061 /* Linux obtains io_request_lock before calling this function */
1063 /****************************************************************************/
1065 ips_queue(Scsi_Cmnd * SC, void (*done) (Scsi_Cmnd *))
1070 METHOD_TRACE("ips_queue", 1);
1072 ha = (ips_ha_t *) SC->device->host->hostdata;
1080 if (ips_is_passthru(SC)) {
1081 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1082 SC->result = DID_BUS_BUSY << 16;
1087 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1088 SC->result = DID_BUS_BUSY << 16;
1094 SC->scsi_done = done;
1096 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1100 SC->device->channel, SC->device->id, SC->device->lun);
1102 /* Check for command to initiator IDs */
1103 if ((SC->device->channel > 0)
1104 && (SC->device->id == ha->ha_id[SC->device->channel])) {
1105 SC->result = DID_NO_CONNECT << 16;
1111 if (ips_is_passthru(SC)) {
1113 ips_copp_wait_item_t *scratch;
1115 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1116 /* There can never be any system activity ( network or disk ), but check */
1117 /* anyway just as a good practice. */
1118 pt = (ips_passthru_t *) SC->request_buffer;
1119 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1120 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1121 if (ha->scb_activelist.count != 0) {
1122 SC->result = DID_BUS_BUSY << 16;
1126 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1128 SC->result = DID_OK << 16;
1133 /* allocate space for the scribble */
1134 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1137 SC->result = DID_ERROR << 16;
1143 scratch->scsi_cmd = SC;
1144 scratch->next = NULL;
1146 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1148 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1151 ips_next(ha, IPS_INTR_IORL);
1156 /****************************************************************************/
1158 /* Routine Name: ips_biosparam */
1160 /* Routine Description: */
1162 /* Set bios geometry for the controller */
1164 /****************************************************************************/
1166 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1167 ips_biosparam(Disk * disk, kdev_t dev, int geom[])
1169 ips_ha_t *ha = (ips_ha_t *) disk->device->host->hostdata;
1170 unsigned long capacity = disk->capacity;
1172 ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1173 sector_t capacity, int geom[])
1175 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1181 METHOD_TRACE("ips_biosparam", 1);
1184 /* ?!?! host adater info invalid */
1190 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1191 /* ?!?! Enquiry command failed */
1194 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1195 heads = IPS_NORM_HEADS;
1196 sectors = IPS_NORM_SECTORS;
1198 heads = IPS_COMP_HEADS;
1199 sectors = IPS_COMP_SECTORS;
1202 cylinders = (unsigned long) capacity / (heads * sectors);
1204 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1205 heads, sectors, cylinders);
1209 geom[2] = cylinders;
1214 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1216 /* ips_proc24_info is a wrapper around ips_proc_info *
1217 * for compatibility with the 2.4 scsi parameters */
1219 ips_proc24_info(char *buffer, char **start, off_t offset, int length,
1220 int hostno, int func)
1224 for (i = 0; i < ips_next_controller; i++) {
1225 if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
1226 return ips_proc_info(ips_sh[i], buffer, start,
1227 offset, length, func);
1233 /****************************************************************************/
1235 /* Routine Name: ips_select_queue_depth */
1237 /* Routine Description: */
1239 /* Select queue depths for the devices on the contoller */
1241 /****************************************************************************/
1243 ips_select_queue_depth(struct Scsi_Host *host, Scsi_Device * scsi_devs)
1245 Scsi_Device *device;
1251 min = ha->max_cmds / 4;
1253 for (device = scsi_devs; device; device = device->next) {
1254 if (device->host == host) {
1255 if ((device->channel == 0) && (device->type == 0))
1260 for (device = scsi_devs; device; device = device->next) {
1261 if (device->host == host) {
1262 if ((device->channel == 0) && (device->type == 0)) {
1263 device->queue_depth =
1264 (ha->max_cmds - 1) / count;
1265 if (device->queue_depth < min)
1266 device->queue_depth = min;
1268 device->queue_depth = 2;
1271 if (device->queue_depth < 2)
1272 device->queue_depth = 2;
1278 /****************************************************************************/
1280 /* Routine Name: ips_slave_configure */
1282 /* Routine Description: */
1284 /* Set queue depths on devices once scan is complete */
1286 /****************************************************************************/
1288 ips_slave_configure(Scsi_Device * SDptr)
1293 ha = IPS_HA(SDptr->host);
1294 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1295 min = ha->max_cmds / 2;
1296 if (ha->enq->ucLogDriveCount <= 2)
1297 min = ha->max_cmds - 1;
1298 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min);
1304 /****************************************************************************/
1306 /* Routine Name: do_ipsintr */
1308 /* Routine Description: */
1310 /* Wrapper for the interrupt handler */
1312 /****************************************************************************/
1314 do_ipsintr(int irq, void *dev_id, struct pt_regs * regs)
1317 unsigned long cpu_flags;
1318 struct Scsi_Host *host;
1321 METHOD_TRACE("do_ipsintr", 2);
1323 ha = (ips_ha_t *) dev_id;
1326 host = ips_sh[ha->host_num];
1327 /* interrupt during initialization */
1329 (*ha->func.intr) (ha);
1333 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
1336 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1340 irqstatus = (*ha->func.intr) (ha);
1342 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1344 /* start the next command */
1345 ips_next(ha, IPS_INTR_ON);
1346 return IRQ_RETVAL(irqstatus);
1349 /****************************************************************************/
1351 /* Routine Name: ips_intr_copperhead */
1353 /* Routine Description: */
1355 /* Polling interrupt handler */
1357 /* ASSUMES interrupts are disabled */
1359 /****************************************************************************/
1361 ips_intr_copperhead(ips_ha_t * ha)
1368 METHOD_TRACE("ips_intr", 2);
1376 intrstatus = (*ha->func.isintr) (ha);
1380 * Unexpected/Shared interrupt
1389 intrstatus = (*ha->func.isintr) (ha);
1394 cstatus.value = (*ha->func.statupd) (ha);
1396 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1397 /* Spurious Interupt ? */
1401 ips_chkstatus(ha, &cstatus);
1402 scb = (ips_scb_t *) sp->scb_addr;
1405 * use the callback function to finish things up
1406 * NOTE: interrupts are OFF for this
1408 (*scb->callback) (ha, scb);
1413 /****************************************************************************/
1415 /* Routine Name: ips_intr_morpheus */
1417 /* Routine Description: */
1419 /* Polling interrupt handler */
1421 /* ASSUMES interrupts are disabled */
1423 /****************************************************************************/
1425 ips_intr_morpheus(ips_ha_t * ha)
1432 METHOD_TRACE("ips_intr_morpheus", 2);
1440 intrstatus = (*ha->func.isintr) (ha);
1444 * Unexpected/Shared interrupt
1453 intrstatus = (*ha->func.isintr) (ha);
1458 cstatus.value = (*ha->func.statupd) (ha);
1460 if (cstatus.value == 0xffffffff)
1461 /* No more to process */
1464 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1465 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1466 "Spurious interrupt; no ccb.\n");
1471 ips_chkstatus(ha, &cstatus);
1472 scb = (ips_scb_t *) sp->scb_addr;
1475 * use the callback function to finish things up
1476 * NOTE: interrupts are OFF for this
1478 (*scb->callback) (ha, scb);
1483 /****************************************************************************/
1485 /* Routine Name: ips_info */
1487 /* Routine Description: */
1489 /* Return info about the driver */
1491 /****************************************************************************/
1493 ips_info(struct Scsi_Host *SH)
1495 static char buffer[256];
1499 METHOD_TRACE("ips_info", 1);
1507 memset(bp, 0, sizeof (buffer));
1509 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1510 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1512 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1514 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1521 /****************************************************************************/
1523 /* Routine Name: ips_proc_info */
1525 /* Routine Description: */
1527 /* The passthru interface for the driver */
1529 /****************************************************************************/
1531 ips_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1532 int length, int func)
1536 ips_ha_t *ha = NULL;
1538 METHOD_TRACE("ips_proc_info", 1);
1540 /* Find our host structure */
1541 for (i = 0; i < ips_next_controller; i++) {
1543 if (ips_sh[i] == host) {
1544 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1561 ret = ips_host_info(ha, buffer, offset, length);
1567 /*--------------------------------------------------------------------------*/
1568 /* Helper Functions */
1569 /*--------------------------------------------------------------------------*/
1571 /****************************************************************************/
1573 /* Routine Name: ips_is_passthru */
1575 /* Routine Description: */
1577 /* Determine if the specified SCSI command is really a passthru command */
1579 /****************************************************************************/
1581 ips_is_passthru(Scsi_Cmnd * SC)
1583 METHOD_TRACE("ips_is_passthru", 1);
1588 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1589 (SC->device->channel == 0) &&
1590 (SC->device->id == IPS_ADAPTER_ID) &&
1591 (SC->device->lun == 0) && SC->request_buffer) {
1592 if ((!SC->use_sg) && SC->request_bufflen &&
1593 (((char *) SC->request_buffer)[0] == 'C') &&
1594 (((char *) SC->request_buffer)[1] == 'O') &&
1595 (((char *) SC->request_buffer)[2] == 'P') &&
1596 (((char *) SC->request_buffer)[3] == 'P'))
1598 else if (SC->use_sg) {
1599 struct scatterlist *sg = SC->request_buffer;
1600 char *buffer = IPS_SG_ADDRESS(sg);
1601 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1602 buffer[2] == 'P' && buffer[3] == 'P')
1609 /****************************************************************************/
1611 /* Routine Name: ips_alloc_passthru_buffer */
1613 /* Routine Description: */
1614 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1615 /* is too small or doesn't exist */
1616 /****************************************************************************/
1618 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1621 dma_addr_t dma_busaddr;
1623 if (ha->ioctl_data && length <= ha->ioctl_len)
1625 /* there is no buffer or it's not big enough, allocate a new one */
1626 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1628 /* free the old memory */
1629 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1631 /* use the new memory */
1632 ha->ioctl_data = (char *) bigger_buf;
1633 ha->ioctl_len = length;
1634 ha->ioctl_busaddr = dma_busaddr;
1641 /****************************************************************************/
1643 /* Routine Name: ips_make_passthru */
1645 /* Routine Description: */
1647 /* Make a passthru command out of the info in the Scsi block */
1649 /****************************************************************************/
1651 ips_make_passthru(ips_ha_t * ha, Scsi_Cmnd * SC, ips_scb_t * scb, int intr)
1657 METHOD_TRACE("ips_make_passthru", 1);
1660 length = SC->request_bufflen;
1662 struct scatterlist *sg = SC->request_buffer;
1664 for (i = 0; i < SC->use_sg; i++)
1665 length += sg[i].length;
1667 if (length < sizeof (ips_passthru_t)) {
1669 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1670 ips_name, ha->host_num);
1671 return (IPS_FAILURE);
1673 if (ips_alloc_passthru_buffer(ha, length)) {
1674 /* allocation failure! If ha->ioctl_data exists, use it to return
1675 some error codes. Return a failed command to the scsi layer. */
1676 if (ha->ioctl_data) {
1677 pt = (ips_passthru_t *) ha->ioctl_data;
1678 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1679 pt->BasicStatus = 0x0B;
1680 pt->ExtendedStatus = 0x00;
1681 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1685 ha->ioctl_datasize = length;
1687 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1688 pt = (ips_passthru_t *) ha->ioctl_data;
1691 * Some notes about the passthru interface used
1693 * IF the scsi op_code == 0x0d then we assume
1694 * that the data came along with/goes with the
1695 * packet we received from the sg driver. In this
1696 * case the CmdBSize field of the pt structure is
1697 * used for the size of the buffer.
1700 switch (pt->CoppCmd) {
1702 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1703 &ips_num_controllers, sizeof (int));
1704 ips_scmd_buf_write(SC, ha->ioctl_data,
1705 sizeof (ips_passthru_t) + sizeof (int));
1706 SC->result = DID_OK << 16;
1708 return (IPS_SUCCESS_IMM);
1710 case IPS_COPPUSRCMD:
1711 case IPS_COPPIOCCMD:
1712 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1713 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1716 "(%s%d) Passthru structure wrong size",
1717 ips_name, ha->host_num);
1719 return (IPS_FAILURE);
1722 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
1723 pt->CoppCP.cmd.flashfw.op_code ==
1724 IPS_CMD_RW_BIOSFW) {
1725 ret = ips_flash_copperhead(ha, pt, scb);
1726 ips_scmd_buf_write(SC, ha->ioctl_data,
1727 sizeof (ips_passthru_t));
1730 if (ips_usrcmd(ha, pt, scb))
1731 return (IPS_SUCCESS);
1733 return (IPS_FAILURE);
1740 return (IPS_FAILURE);
1743 /****************************************************************************/
1744 /* Routine Name: ips_flash_copperhead */
1745 /* Routine Description: */
1746 /* Flash the BIOS/FW on a Copperhead style controller */
1747 /****************************************************************************/
1749 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1753 /* Trombone is the only copperhead that can do packet flash, but only
1754 * for firmware. No one said it had to make sence. */
1755 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1756 if (ips_usrcmd(ha, pt, scb))
1761 pt->BasicStatus = 0x0B;
1762 pt->ExtendedStatus = 0;
1763 scb->scsi_cmd->result = DID_OK << 16;
1764 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1765 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1766 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1767 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1768 pt->BasicStatus = 0;
1769 return ips_flash_bios(ha, pt, scb);
1770 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1771 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1772 ha->flash_data = ips_FlashData;
1773 ha->flash_busaddr = ips_flashbusaddr;
1774 ha->flash_len = PAGE_SIZE << 7;
1775 ha->flash_datasize = 0;
1776 } else if (!ha->flash_data) {
1777 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1778 pt->CoppCP.cmd.flashfw.count;
1779 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1781 &ha->flash_busaddr);
1782 if (!ha->flash_data){
1783 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1786 ha->flash_datasize = 0;
1787 ha->flash_len = datasize;
1791 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1793 ips_free_flash_copperhead(ha);
1794 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1795 "failed size sanity check\n");
1799 if (!ha->flash_data)
1801 pt->BasicStatus = 0;
1802 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1803 pt->CoppCP.cmd.flashfw.count);
1804 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1805 if (pt->CoppCP.cmd.flashfw.packet_num ==
1806 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1807 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1808 return ips_flash_bios(ha, pt, scb);
1809 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1810 return ips_flash_firmware(ha, pt, scb);
1812 return IPS_SUCCESS_IMM;
1815 /****************************************************************************/
1816 /* Routine Name: ips_flash_bios */
1817 /* Routine Description: */
1818 /* flashes the bios of a copperhead adapter */
1819 /****************************************************************************/
1821 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1824 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1825 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1826 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1827 (!ha->func.verifybios))
1829 if ((*ha->func.erasebios) (ha)) {
1831 "(%s%d) flash bios failed - unable to erase flash",
1832 ips_name, ha->host_num);
1835 if ((*ha->func.programbios) (ha,
1838 ha->flash_datasize -
1839 IPS_BIOS_HEADER, 0)) {
1841 "(%s%d) flash bios failed - unable to flash",
1842 ips_name, ha->host_num);
1845 if ((*ha->func.verifybios) (ha,
1848 ha->flash_datasize -
1849 IPS_BIOS_HEADER, 0)) {
1851 "(%s%d) flash bios failed - unable to verify flash",
1852 ips_name, ha->host_num);
1855 ips_free_flash_copperhead(ha);
1856 return IPS_SUCCESS_IMM;
1857 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1858 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1859 if (!ha->func.erasebios)
1861 if ((*ha->func.erasebios) (ha)) {
1863 "(%s%d) flash bios failed - unable to erase flash",
1864 ips_name, ha->host_num);
1867 return IPS_SUCCESS_IMM;
1870 pt->BasicStatus = 0x0B;
1871 pt->ExtendedStatus = 0x00;
1872 ips_free_flash_copperhead(ha);
1876 /****************************************************************************/
1878 /* Routine Name: ips_fill_scb_sg_single */
1880 /* Routine Description: */
1881 /* Fill in a single scb sg_list element from an address */
1882 /* return a -1 if a breakup occurred */
1883 /****************************************************************************/
1885 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1886 ips_scb_t * scb, int indx, unsigned int e_len)
1891 if ((scb->data_len + e_len) > ha->max_xfer) {
1892 e_len = ha->max_xfer - scb->data_len;
1893 scb->breakup = indx;
1900 if (IPS_USE_ENH_SGLIST(ha)) {
1901 scb->sg_list.enh_list[indx].address_lo =
1902 cpu_to_le32(pci_dma_lo32(busaddr));
1903 scb->sg_list.enh_list[indx].address_hi =
1904 cpu_to_le32(pci_dma_hi32(busaddr));
1905 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1907 scb->sg_list.std_list[indx].address =
1908 cpu_to_le32(pci_dma_lo32(busaddr));
1909 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1913 scb->data_len += e_len;
1917 /****************************************************************************/
1918 /* Routine Name: ips_flash_firmware */
1919 /* Routine Description: */
1920 /* flashes the firmware of a copperhead adapter */
1921 /****************************************************************************/
1923 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1925 IPS_SG_LIST sg_list;
1926 uint32_t cmd_busaddr;
1928 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1929 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1930 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1931 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1932 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1934 pt->BasicStatus = 0x0B;
1935 pt->ExtendedStatus = 0x00;
1936 ips_free_flash_copperhead(ha);
1939 /* Save the S/G list pointer so it doesn't get clobbered */
1940 sg_list.list = scb->sg_list.list;
1941 cmd_busaddr = scb->scb_busaddr;
1942 /* copy in the CP */
1943 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1944 /* FIX stuff that might be wrong */
1945 scb->sg_list.list = sg_list.list;
1946 scb->scb_busaddr = cmd_busaddr;
1947 scb->bus = scb->scsi_cmd->device->channel;
1948 scb->target_id = scb->scsi_cmd->device->id;
1949 scb->lun = scb->scsi_cmd->device->lun;
1954 scb->callback = ipsintr_done;
1955 scb->timeout = ips_cmd_timeout;
1957 scb->data_len = ha->flash_datasize;
1959 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1961 scb->flags |= IPS_SCB_MAP_SINGLE;
1962 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1963 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1965 scb->timeout = pt->TimeOut;
1966 scb->scsi_cmd->result = DID_OK << 16;
1970 /****************************************************************************/
1971 /* Routine Name: ips_free_flash_copperhead */
1972 /* Routine Description: */
1973 /* release the memory resources used to hold the flash image */
1974 /****************************************************************************/
1976 ips_free_flash_copperhead(ips_ha_t * ha)
1978 if (ha->flash_data == ips_FlashData)
1979 test_and_clear_bit(0, &ips_FlashDataInUse);
1980 else if (ha->flash_data)
1981 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
1983 ha->flash_data = NULL;
1986 /****************************************************************************/
1988 /* Routine Name: ips_usrcmd */
1990 /* Routine Description: */
1992 /* Process a user command and make it ready to send */
1994 /****************************************************************************/
1996 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1998 IPS_SG_LIST sg_list;
1999 uint32_t cmd_busaddr;
2001 METHOD_TRACE("ips_usrcmd", 1);
2003 if ((!scb) || (!pt) || (!ha))
2006 /* Save the S/G list pointer so it doesn't get clobbered */
2007 sg_list.list = scb->sg_list.list;
2008 cmd_busaddr = scb->scb_busaddr;
2009 /* copy in the CP */
2010 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
2011 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
2013 /* FIX stuff that might be wrong */
2014 scb->sg_list.list = sg_list.list;
2015 scb->scb_busaddr = cmd_busaddr;
2016 scb->bus = scb->scsi_cmd->device->channel;
2017 scb->target_id = scb->scsi_cmd->device->id;
2018 scb->lun = scb->scsi_cmd->device->lun;
2023 scb->callback = ipsintr_done;
2024 scb->timeout = ips_cmd_timeout;
2025 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
2027 /* we don't support DCDB/READ/WRITE Scatter Gather */
2028 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
2029 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
2030 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
2034 scb->data_len = pt->CmdBSize;
2035 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
2037 scb->data_busaddr = 0L;
2040 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2041 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
2042 (unsigned long) &scb->
2044 (unsigned long) scb);
2047 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2048 scb->dcdb.buffer_pointer =
2049 cpu_to_le32(scb->data_busaddr);
2051 scb->cmd.basic_io.sg_addr =
2052 cpu_to_le32(scb->data_busaddr);
2057 scb->timeout = pt->TimeOut;
2059 if (pt->TimeOut <= 10)
2060 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
2061 else if (pt->TimeOut <= 60)
2062 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
2064 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
2067 /* assume success */
2068 scb->scsi_cmd->result = DID_OK << 16;
2074 /****************************************************************************/
2076 /* Routine Name: ips_cleanup_passthru */
2078 /* Routine Description: */
2080 /* Cleanup after a passthru command */
2082 /****************************************************************************/
2084 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
2088 METHOD_TRACE("ips_cleanup_passthru", 1);
2090 if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
2091 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2092 ips_name, ha->host_num);
2096 pt = (ips_passthru_t *) ha->ioctl_data;
2098 /* Copy data back to the user */
2099 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2100 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2102 pt->BasicStatus = scb->basic_status;
2103 pt->ExtendedStatus = scb->extended_status;
2104 pt->AdapterType = ha->ad_type;
2106 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
2107 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2108 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2109 ips_free_flash_copperhead(ha);
2111 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2114 /****************************************************************************/
2116 /* Routine Name: ips_host_info */
2118 /* Routine Description: */
2120 /* The passthru interface for the driver */
2122 /****************************************************************************/
2124 ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
2128 METHOD_TRACE("ips_host_info", 1);
2132 info.offset = offset;
2136 copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
2138 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2139 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2140 copy_info(&info, "\tController Type : %s\n",
2141 ips_adapter_name[ha->ad_type - 1]);
2144 "\tController Type : Unknown\n");
2148 "\tIO region : 0x%lx (%d bytes)\n",
2149 ha->io_addr, ha->io_len);
2153 "\tMemory region : 0x%lx (%d bytes)\n",
2154 ha->mem_addr, ha->mem_len);
2156 "\tShared memory address : 0x%lx\n",
2160 copy_info(&info, "\tIRQ number : %d\n", ha->irq);
2162 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2163 /* That keeps everything happy for "text" operations on the proc file. */
2165 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2166 if (ha->nvram->bios_low[3] == 0) {
2168 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2169 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2170 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2171 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2172 ha->nvram->bios_low[2]);
2176 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2177 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2178 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2179 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2180 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2185 if (ha->enq->CodeBlkVersion[7] == 0) {
2187 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2188 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2189 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2190 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2191 ha->enq->CodeBlkVersion[6]);
2194 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2195 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2196 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2197 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2198 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2201 if (ha->enq->BootBlkVersion[7] == 0) {
2203 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2204 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2205 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2206 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2207 ha->enq->BootBlkVersion[6]);
2210 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2211 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2212 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2213 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2214 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2217 copy_info(&info, "\tDriver Version : %s%s\n",
2218 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2220 copy_info(&info, "\tDriver Build : %d\n",
2223 copy_info(&info, "\tMax Physical Devices : %d\n",
2224 ha->enq->ucMaxPhysicalDevices);
2225 copy_info(&info, "\tMax Active Commands : %d\n",
2227 copy_info(&info, "\tCurrent Queued Commands : %d\n",
2228 ha->scb_waitlist.count);
2229 copy_info(&info, "\tCurrent Active Commands : %d\n",
2230 ha->scb_activelist.count - ha->num_ioctl);
2231 copy_info(&info, "\tCurrent Queued PT Commands : %d\n",
2232 ha->copp_waitlist.count);
2233 copy_info(&info, "\tCurrent Active PT Commands : %d\n",
2236 copy_info(&info, "\n");
2238 return (info.localpos);
2241 /****************************************************************************/
2243 /* Routine Name: copy_mem_info */
2245 /* Routine Description: */
2247 /* Copy data into an IPS_INFOSTR structure */
2249 /****************************************************************************/
2251 copy_mem_info(IPS_INFOSTR * info, char *data, int len)
2253 METHOD_TRACE("copy_mem_info", 1);
2255 if (info->pos + len < info->offset) {
2260 if (info->pos < info->offset) {
2261 data += (info->offset - info->pos);
2262 len -= (info->offset - info->pos);
2263 info->pos += (info->offset - info->pos);
2266 if (info->localpos + len > info->length)
2267 len = info->length - info->localpos;
2270 memcpy(info->buffer + info->localpos, data, len);
2272 info->localpos += len;
2276 /****************************************************************************/
2278 /* Routine Name: copy_info */
2280 /* Routine Description: */
2282 /* printf style wrapper for an info structure */
2284 /****************************************************************************/
2286 copy_info(IPS_INFOSTR * info, char *fmt, ...)
2292 METHOD_TRACE("copy_info", 1);
2294 va_start(args, fmt);
2295 len = vsprintf(buf, fmt, args);
2298 copy_mem_info(info, buf, len);
2303 /****************************************************************************/
2305 /* Routine Name: ips_identify_controller */
2307 /* Routine Description: */
2309 /* Identify this controller */
2311 /****************************************************************************/
2313 ips_identify_controller(ips_ha_t * ha)
2315 METHOD_TRACE("ips_identify_controller", 1);
2317 switch (ha->device_id) {
2318 case IPS_DEVICEID_COPPERHEAD:
2319 if (ha->revision_id <= IPS_REVID_SERVERAID) {
2320 ha->ad_type = IPS_ADTYPE_SERVERAID;
2321 } else if (ha->revision_id == IPS_REVID_SERVERAID2) {
2322 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2323 } else if (ha->revision_id == IPS_REVID_NAVAJO) {
2324 ha->ad_type = IPS_ADTYPE_NAVAJO;
2325 } else if ((ha->revision_id == IPS_REVID_SERVERAID2)
2326 && (ha->slot_num == 0)) {
2327 ha->ad_type = IPS_ADTYPE_KIOWA;
2328 } else if ((ha->revision_id >= IPS_REVID_CLARINETP1) &&
2329 (ha->revision_id <= IPS_REVID_CLARINETP3)) {
2330 if (ha->enq->ucMaxPhysicalDevices == 15)
2331 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2333 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2334 } else if ((ha->revision_id >= IPS_REVID_TROMBONE32) &&
2335 (ha->revision_id <= IPS_REVID_TROMBONE64)) {
2336 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2340 case IPS_DEVICEID_MORPHEUS:
2341 switch (ha->subdevice_id) {
2342 case IPS_SUBDEVICEID_4L:
2343 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2346 case IPS_SUBDEVICEID_4M:
2347 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2350 case IPS_SUBDEVICEID_4MX:
2351 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2354 case IPS_SUBDEVICEID_4LX:
2355 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2358 case IPS_SUBDEVICEID_5I2:
2359 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2362 case IPS_SUBDEVICEID_5I1:
2363 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2369 case IPS_DEVICEID_MARCO:
2370 switch (ha->subdevice_id) {
2371 case IPS_SUBDEVICEID_6M:
2372 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2374 case IPS_SUBDEVICEID_6I:
2375 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2377 case IPS_SUBDEVICEID_7k:
2378 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2380 case IPS_SUBDEVICEID_7M:
2381 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2388 /****************************************************************************/
2390 /* Routine Name: ips_get_bios_version */
2392 /* Routine Description: */
2394 /* Get the BIOS revision number */
2396 /****************************************************************************/
2398 ips_get_bios_version(ips_ha_t * ha, int intr)
2407 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2410 METHOD_TRACE("ips_get_bios_version", 1);
2415 strncpy(ha->bios_version, " ?", 8);
2417 if (ha->device_id == IPS_DEVICEID_COPPERHEAD) {
2418 if (IPS_USE_MEMIO(ha)) {
2419 /* Memory Mapped I/O */
2422 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2423 if (ha->revision_id == IPS_REVID_TROMBONE64)
2424 udelay(25); /* 25 us */
2426 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2429 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2430 if (ha->revision_id == IPS_REVID_TROMBONE64)
2431 udelay(25); /* 25 us */
2433 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2436 /* Get Major version */
2437 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2438 if (ha->revision_id == IPS_REVID_TROMBONE64)
2439 udelay(25); /* 25 us */
2441 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2443 /* Get Minor version */
2444 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2445 if (ha->revision_id == IPS_REVID_TROMBONE64)
2446 udelay(25); /* 25 us */
2447 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2449 /* Get SubMinor version */
2450 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2451 if (ha->revision_id == IPS_REVID_TROMBONE64)
2452 udelay(25); /* 25 us */
2453 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2456 /* Programmed I/O */
2459 outl(0, ha->io_addr + IPS_REG_FLAP);
2460 if (ha->revision_id == IPS_REVID_TROMBONE64)
2461 udelay(25); /* 25 us */
2463 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2466 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
2467 if (ha->revision_id == IPS_REVID_TROMBONE64)
2468 udelay(25); /* 25 us */
2470 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2473 /* Get Major version */
2474 outl(cpu_to_le32(0x1FF), ha->io_addr + IPS_REG_FLAP);
2475 if (ha->revision_id == IPS_REVID_TROMBONE64)
2476 udelay(25); /* 25 us */
2478 major = inb(ha->io_addr + IPS_REG_FLDP);
2480 /* Get Minor version */
2481 outl(cpu_to_le32(0x1FE), ha->io_addr + IPS_REG_FLAP);
2482 if (ha->revision_id == IPS_REVID_TROMBONE64)
2483 udelay(25); /* 25 us */
2485 minor = inb(ha->io_addr + IPS_REG_FLDP);
2487 /* Get SubMinor version */
2488 outl(cpu_to_le32(0x1FD), ha->io_addr + IPS_REG_FLAP);
2489 if (ha->revision_id == IPS_REVID_TROMBONE64)
2490 udelay(25); /* 25 us */
2492 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2496 /* Morpheus Family - Send Command to the card */
2498 buffer = ha->ioctl_data;
2500 memset(buffer, 0, 0x1000);
2502 scb = &ha->scbs[ha->max_cmds - 1];
2504 ips_init_scb(ha, scb);
2506 scb->timeout = ips_cmd_timeout;
2507 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2509 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2510 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2511 scb->cmd.flashfw.type = 1;
2512 scb->cmd.flashfw.direction = 0;
2513 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2514 scb->cmd.flashfw.total_packets = 1;
2515 scb->cmd.flashfw.packet_num = 0;
2516 scb->data_len = 0x1000;
2517 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2519 /* issue the command */
2521 ips_send_wait(ha, scb, ips_cmd_timeout,
2522 intr)) == IPS_FAILURE)
2523 || (ret == IPS_SUCCESS_IMM)
2524 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2525 /* Error occurred */
2530 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2531 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2532 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2533 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2539 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2540 ha->bios_version[1] = '.';
2541 ha->bios_version[2] = hexDigits[major & 0x0F];
2542 ha->bios_version[3] = hexDigits[subminor];
2543 ha->bios_version[4] = '.';
2544 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2545 ha->bios_version[6] = hexDigits[minor & 0x0F];
2546 ha->bios_version[7] = 0;
2549 /****************************************************************************/
2551 /* Routine Name: ips_hainit */
2553 /* Routine Description: */
2555 /* Initialize the controller */
2557 /* NOTE: Assumes to be called from with a lock */
2559 /****************************************************************************/
2561 ips_hainit(ips_ha_t * ha)
2566 METHOD_TRACE("ips_hainit", 1);
2571 if (ha->func.statinit)
2572 (*ha->func.statinit) (ha);
2574 if (ha->func.enableint)
2575 (*ha->func.enableint) (ha);
2578 ha->reset_count = 1;
2579 do_gettimeofday(&tv);
2580 ha->last_ffdc = tv.tv_sec;
2581 ips_ffdc_reset(ha, IPS_INTR_IORL);
2583 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2584 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2585 "unable to read config from controller.\n");
2590 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2591 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2592 "unable to read controller status.\n");
2597 /* Identify this controller */
2598 ips_identify_controller(ha);
2600 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2601 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2602 "unable to read subsystem parameters.\n");
2607 /* write nvram user page 5 */
2608 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2609 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2610 "unable to write driver info to controller.\n");
2615 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2616 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2617 ips_clear_adapter(ha, IPS_INTR_IORL);
2619 /* set limits on SID, LUN, BUS */
2620 ha->ntargets = IPS_MAX_TARGETS + 1;
2622 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2624 switch (ha->conf->logical_drive[0].ucStripeSize) {
2626 ha->max_xfer = 0x10000;
2630 ha->max_xfer = 0x20000;
2634 ha->max_xfer = 0x40000;
2639 ha->max_xfer = 0x80000;
2643 /* setup max concurrent commands */
2644 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2645 /* Use the new method */
2646 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2648 /* use the old method */
2649 switch (ha->conf->logical_drive[0].ucStripeSize) {
2669 /* Limit the Active Commands on a Lite Adapter */
2670 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2671 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2672 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2673 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2674 ha->max_cmds = MaxLiteCmds;
2677 /* set controller IDs */
2678 ha->ha_id[0] = IPS_ADAPTER_ID;
2679 for (i = 1; i < ha->nbus; i++) {
2680 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2681 ha->dcdb_active[i - 1] = 0;
2687 /****************************************************************************/
2689 /* Routine Name: ips_next */
2691 /* Routine Description: */
2693 /* Take the next command off the queue and send it to the controller */
2695 /****************************************************************************/
2697 ips_next(ips_ha_t * ha, int intr)
2703 ips_copp_wait_item_t *item;
2705 unsigned long cpu_flags = 0;
2706 struct Scsi_Host *host;
2707 METHOD_TRACE("ips_next", 1);
2711 host = ips_sh[ha->host_num];
2713 * Block access to the queue function so
2714 * this command won't time out
2716 if (intr == IPS_INTR_ON)
2717 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2719 if ((ha->subsys->param[3] & 0x300000)
2720 && (ha->scb_activelist.count == 0)) {
2723 do_gettimeofday(&tv);
2725 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2726 ha->last_ffdc = tv.tv_sec;
2732 * Send passthru commands
2733 * These have priority over normal I/O
2734 * but shouldn't affect performance too much
2735 * since we limit the number that can be active
2736 * on the card at any one time
2738 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2739 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2741 item = ips_removeq_copp_head(&ha->copp_waitlist);
2743 if (intr == IPS_INTR_ON)
2744 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2745 scb->scsi_cmd = item->scsi_cmd;
2748 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2750 if (intr == IPS_INTR_ON)
2751 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2754 if (scb->scsi_cmd) {
2755 scb->scsi_cmd->result = DID_ERROR << 16;
2756 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2759 ips_freescb(ha, scb);
2761 case IPS_SUCCESS_IMM:
2762 if (scb->scsi_cmd) {
2763 scb->scsi_cmd->result = DID_OK << 16;
2764 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2767 ips_freescb(ha, scb);
2773 if (ret != IPS_SUCCESS) {
2778 ret = ips_send_cmd(ha, scb);
2780 if (ret == IPS_SUCCESS)
2781 ips_putq_scb_head(&ha->scb_activelist, scb);
2787 if (scb->scsi_cmd) {
2788 scb->scsi_cmd->result = DID_ERROR << 16;
2791 ips_freescb(ha, scb);
2793 case IPS_SUCCESS_IMM:
2794 ips_freescb(ha, scb);
2803 * Send "Normal" I/O commands
2806 p = ha->scb_waitlist.head;
2807 while ((p) && (scb = ips_getscb(ha))) {
2808 if ((p->device->channel > 0)
2810 dcdb_active[p->device->channel -
2811 1] & (1 << p->device->id))) {
2812 ips_freescb(ha, scb);
2813 p = (Scsi_Cmnd *) p->host_scribble;
2818 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2820 if (intr == IPS_INTR_ON)
2821 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags); /* Unlock HA after command is taken off queue */
2823 SC->result = DID_OK;
2824 SC->host_scribble = NULL;
2826 memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
2828 scb->target_id = SC->device->id;
2829 scb->lun = SC->device->lun;
2830 scb->bus = SC->device->channel;
2834 scb->callback = ipsintr_done;
2835 scb->timeout = ips_cmd_timeout;
2836 memset(&scb->cmd, 0, 16);
2838 /* copy in the CDB */
2839 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2841 /* Now handle the data buffer */
2843 struct scatterlist *sg;
2846 sg = SC->request_buffer;
2847 scb->sg_count = pci_map_sg(ha->pcidev, sg, SC->use_sg,
2848 scsi_to_pci_dma_dir(SC->
2849 sc_data_direction));
2850 scb->flags |= IPS_SCB_MAP_SG;
2851 for (i = 0; i < scb->sg_count; i++) {
2852 if (ips_fill_scb_sg_single
2853 (ha, sg_dma_address(&sg[i]), scb, i,
2854 sg_dma_len(&sg[i])) < 0)
2857 scb->dcdb.transfer_length = scb->data_len;
2859 if (SC->request_bufflen) {
2861 pci_map_single(ha->pcidev,
2863 SC->request_bufflen,
2864 scsi_to_pci_dma_dir(SC->
2865 sc_data_direction));
2866 scb->flags |= IPS_SCB_MAP_SINGLE;
2867 ips_fill_scb_sg_single(ha, scb->data_busaddr,
2869 SC->request_bufflen);
2870 scb->dcdb.transfer_length = scb->data_len;
2872 scb->data_busaddr = 0L;
2875 scb->dcdb.transfer_length = 0;
2880 scb->dcdb.cmd_attribute =
2881 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2883 /* Allow a WRITE BUFFER Command to Have no Data */
2884 /* This is Used by Tape Flash Utilites */
2885 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0))
2886 scb->dcdb.cmd_attribute = 0;
2888 if (!(scb->dcdb.cmd_attribute & 0x3))
2889 scb->dcdb.transfer_length = 0;
2891 if (scb->data_len >= IPS_MAX_XFER) {
2892 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2893 scb->dcdb.transfer_length = 0;
2895 if (intr == IPS_INTR_ON)
2896 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2898 ret = ips_send_cmd(ha, scb);
2902 ips_putq_scb_head(&ha->scb_activelist, scb);
2905 if (scb->scsi_cmd) {
2906 scb->scsi_cmd->result = DID_ERROR << 16;
2907 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2911 ha->dcdb_active[scb->bus - 1] &=
2912 ~(1 << scb->target_id);
2914 ips_freescb(ha, scb);
2916 case IPS_SUCCESS_IMM:
2918 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2921 ha->dcdb_active[scb->bus - 1] &=
2922 ~(1 << scb->target_id);
2924 ips_freescb(ha, scb);
2930 p = (Scsi_Cmnd *) p->host_scribble;
2934 if (intr == IPS_INTR_ON)
2935 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2938 /****************************************************************************/
2940 /* Routine Name: ips_putq_scb_head */
2942 /* Routine Description: */
2944 /* Add an item to the head of the queue */
2946 /* ASSUMED to be called from within the HA lock */
2948 /****************************************************************************/
2950 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2952 METHOD_TRACE("ips_putq_scb_head", 1);
2957 item->q_next = queue->head;
2966 /****************************************************************************/
2968 /* Routine Name: ips_removeq_scb_head */
2970 /* Routine Description: */
2972 /* Remove the head of the queue */
2974 /* ASSUMED to be called from within the HA lock */
2976 /****************************************************************************/
2978 ips_removeq_scb_head(ips_scb_queue_t * queue)
2982 METHOD_TRACE("ips_removeq_scb_head", 1);
2990 queue->head = item->q_next;
2991 item->q_next = NULL;
2993 if (queue->tail == item)
3001 /****************************************************************************/
3003 /* Routine Name: ips_removeq_scb */
3005 /* Routine Description: */
3007 /* Remove an item from a queue */
3009 /* ASSUMED to be called from within the HA lock */
3011 /****************************************************************************/
3013 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
3017 METHOD_TRACE("ips_removeq_scb", 1);
3022 if (item == queue->head) {
3023 return (ips_removeq_scb_head(queue));
3028 while ((p) && (item != p->q_next))
3033 p->q_next = item->q_next;
3038 item->q_next = NULL;
3047 /****************************************************************************/
3049 /* Routine Name: ips_putq_wait_tail */
3051 /* Routine Description: */
3053 /* Add an item to the tail of the queue */
3055 /* ASSUMED to be called from within the HA lock */
3057 /****************************************************************************/
3059 ips_putq_wait_tail(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3061 METHOD_TRACE("ips_putq_wait_tail", 1);
3066 item->host_scribble = NULL;
3069 queue->tail->host_scribble = (char *) item;
3079 /****************************************************************************/
3081 /* Routine Name: ips_removeq_wait_head */
3083 /* Routine Description: */
3085 /* Remove the head of the queue */
3087 /* ASSUMED to be called from within the HA lock */
3089 /****************************************************************************/
3091 ips_removeq_wait_head(ips_wait_queue_t * queue)
3095 METHOD_TRACE("ips_removeq_wait_head", 1);
3103 queue->head = (Scsi_Cmnd *) item->host_scribble;
3104 item->host_scribble = NULL;
3106 if (queue->tail == item)
3114 /****************************************************************************/
3116 /* Routine Name: ips_removeq_wait */
3118 /* Routine Description: */
3120 /* Remove an item from a queue */
3122 /* ASSUMED to be called from within the HA lock */
3124 /****************************************************************************/
3126 ips_removeq_wait(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3130 METHOD_TRACE("ips_removeq_wait", 1);
3135 if (item == queue->head) {
3136 return (ips_removeq_wait_head(queue));
3141 while ((p) && (item != (Scsi_Cmnd *) p->host_scribble))
3142 p = (Scsi_Cmnd *) p->host_scribble;
3146 p->host_scribble = item->host_scribble;
3148 if (!item->host_scribble)
3151 item->host_scribble = NULL;
3160 /****************************************************************************/
3162 /* Routine Name: ips_putq_copp_tail */
3164 /* Routine Description: */
3166 /* Add an item to the tail of the queue */
3168 /* ASSUMED to be called from within the HA lock */
3170 /****************************************************************************/
3172 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3174 METHOD_TRACE("ips_putq_copp_tail", 1);
3182 queue->tail->next = item;
3192 /****************************************************************************/
3194 /* Routine Name: ips_removeq_copp_head */
3196 /* Routine Description: */
3198 /* Remove the head of the queue */
3200 /* ASSUMED to be called from within the HA lock */
3202 /****************************************************************************/
3203 static ips_copp_wait_item_t *
3204 ips_removeq_copp_head(ips_copp_queue_t * queue)
3206 ips_copp_wait_item_t *item;
3208 METHOD_TRACE("ips_removeq_copp_head", 1);
3216 queue->head = item->next;
3219 if (queue->tail == item)
3227 /****************************************************************************/
3229 /* Routine Name: ips_removeq_copp */
3231 /* Routine Description: */
3233 /* Remove an item from a queue */
3235 /* ASSUMED to be called from within the HA lock */
3237 /****************************************************************************/
3238 static ips_copp_wait_item_t *
3239 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3241 ips_copp_wait_item_t *p;
3243 METHOD_TRACE("ips_removeq_copp", 1);
3248 if (item == queue->head) {
3249 return (ips_removeq_copp_head(queue));
3254 while ((p) && (item != p->next))
3259 p->next = item->next;
3273 /****************************************************************************/
3275 /* Routine Name: ipsintr_blocking */
3277 /* Routine Description: */
3279 /* Finalize an interrupt for internal commands */
3281 /****************************************************************************/
3283 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3285 METHOD_TRACE("ipsintr_blocking", 2);
3287 ips_freescb(ha, scb);
3288 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3289 ha->waitflag = FALSE;
3295 /****************************************************************************/
3297 /* Routine Name: ipsintr_done */
3299 /* Routine Description: */
3301 /* Finalize an interrupt for non-internal commands */
3303 /****************************************************************************/
3305 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3307 METHOD_TRACE("ipsintr_done", 2);
3310 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3311 "Spurious interrupt; scb NULL.\n");
3316 if (scb->scsi_cmd == NULL) {
3317 /* unexpected interrupt */
3318 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3319 "Spurious interrupt; scsi_cmd not set.\n");
3327 /****************************************************************************/
3329 /* Routine Name: ips_done */
3331 /* Routine Description: */
3333 /* Do housekeeping on completed commands */
3334 /* ASSUMED to be called form within the request lock */
3335 /****************************************************************************/
3337 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3341 METHOD_TRACE("ips_done", 1);
3346 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3347 ips_cleanup_passthru(ha, scb);
3351 * Check to see if this command had too much
3352 * data and had to be broke up. If so, queue
3353 * the rest of the data and continue.
3355 if ((scb->breakup) || (scb->sg_break)) {
3356 /* we had a data breakup */
3359 if (scb->sg_count) {
3361 struct scatterlist *sg;
3362 int ips_sg_index = 0;
3365 sg = scb->scsi_cmd->request_buffer;
3367 /* Spin forward to last dma chunk */
3368 sg_dma_index = scb->breakup;
3370 /* Take care of possible partial on last chunk */
3371 ips_fill_scb_sg_single(ha,
3374 scb, ips_sg_index++,
3378 for (; sg_dma_index < scb->sg_count;
3380 if (ips_fill_scb_sg_single
3382 sg_dma_address(&sg[sg_dma_index]),
3383 scb, ips_sg_index++,
3384 sg_dma_len(&sg[sg_dma_index])) < 0)
3390 /* Non S/G Request */
3391 (void) ips_fill_scb_sg_single(ha,
3403 scb->dcdb.transfer_length = scb->data_len;
3404 scb->dcdb.cmd_attribute |=
3405 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3407 if (!(scb->dcdb.cmd_attribute & 0x3))
3408 scb->dcdb.transfer_length = 0;
3410 if (scb->data_len >= IPS_MAX_XFER) {
3411 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3412 scb->dcdb.transfer_length = 0;
3415 ret = ips_send_cmd(ha, scb);
3419 if (scb->scsi_cmd) {
3420 scb->scsi_cmd->result = DID_ERROR << 16;
3421 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3424 ips_freescb(ha, scb);
3426 case IPS_SUCCESS_IMM:
3427 if (scb->scsi_cmd) {
3428 scb->scsi_cmd->result = DID_ERROR << 16;
3429 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3432 ips_freescb(ha, scb);
3440 } /* end if passthru */
3443 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3446 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3448 ips_freescb(ha, scb);
3451 /****************************************************************************/
3453 /* Routine Name: ips_map_status */
3455 /* Routine Description: */
3457 /* Map Controller Error codes to Linux Error Codes */
3459 /****************************************************************************/
3461 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3465 uint32_t transfer_len;
3466 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3468 METHOD_TRACE("ips_map_status", 1);
3472 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3473 ips_name, ha->host_num,
3474 scb->scsi_cmd->device->channel,
3475 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3476 scb->basic_status, scb->extended_status,
3477 scb->extended_status ==
3478 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3479 scb->extended_status ==
3480 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3481 scb->extended_status ==
3482 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3485 /* default driver error */
3486 errcode = DID_ERROR;
3489 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3490 case IPS_CMD_TIMEOUT:
3491 errcode = DID_TIME_OUT;
3494 case IPS_INVAL_OPCO:
3495 case IPS_INVAL_CMD_BLK:
3496 case IPS_INVAL_PARM_BLK:
3498 case IPS_CMD_CMPLT_WERROR:
3501 case IPS_PHYS_DRV_ERROR:
3502 switch (scb->extended_status) {
3503 case IPS_ERR_SEL_TO:
3505 errcode = DID_NO_CONNECT;
3509 case IPS_ERR_OU_RUN:
3510 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3511 (scb->cmd.dcdb.op_code ==
3512 IPS_CMD_EXTENDED_DCDB_SG)) {
3513 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3514 transfer_len = tapeDCDB->transfer_length;
3517 (uint32_t) scb->dcdb.transfer_length;
3520 if ((scb->bus) && (transfer_len < scb->data_len)) {
3521 /* Underrun - set default to no error */
3524 /* Restrict access to physical DASD */
3525 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
3526 ((((char *) scb->scsi_cmd->
3527 buffer)[0] & 0x1f) == TYPE_DISK)) {
3528 /* underflow -- no error */
3529 /* restrict access to physical DASD */
3530 errcode = DID_TIME_OUT;
3534 errcode = DID_ERROR;
3538 case IPS_ERR_RECOVERY:
3539 /* don't fail recovered errors */
3545 case IPS_ERR_HOST_RESET:
3546 case IPS_ERR_DEV_RESET:
3547 errcode = DID_RESET;
3550 case IPS_ERR_CKCOND:
3552 if ((scb->cmd.dcdb.op_code ==
3553 IPS_CMD_EXTENDED_DCDB)
3554 || (scb->cmd.dcdb.op_code ==
3555 IPS_CMD_EXTENDED_DCDB_SG)) {
3557 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3558 memcpy(scb->scsi_cmd->sense_buffer,
3559 tapeDCDB->sense_info,
3560 sizeof (scb->scsi_cmd->
3563 memcpy(scb->scsi_cmd->sense_buffer,
3564 scb->dcdb.sense_info,
3565 sizeof (scb->scsi_cmd->
3568 device_error = 2; /* check condition */
3576 errcode = DID_ERROR;
3582 scb->scsi_cmd->result = device_error | (errcode << 16);
3587 /****************************************************************************/
3589 /* Routine Name: ips_send_wait */
3591 /* Routine Description: */
3593 /* Send a command to the controller and wait for it to return */
3595 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3596 /* actually need to wait. */
3597 /****************************************************************************/
3599 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3603 METHOD_TRACE("ips_send_wait", 1);
3605 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3606 ha->waitflag = TRUE;
3607 ha->cmd_in_progress = scb->cdb[0];
3609 scb->callback = ipsintr_blocking;
3610 ret = ips_send_cmd(ha, scb);
3612 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3615 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3616 ret = ips_wait(ha, timeout, intr);
3621 /****************************************************************************/
3623 /* Routine Name: ips_scmd_buf_write */
3625 /* Routine Description: */
3626 /* Write data to Scsi_Cmnd request_buffer at proper offsets */
3627 /****************************************************************************/
3629 ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data, unsigned
3634 unsigned int min_cnt, xfer_cnt;
3635 char *cdata = (char *) data;
3636 struct scatterlist *sg = scmd->request_buffer;
3637 for (i = 0, xfer_cnt = 0;
3638 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3639 if (!IPS_SG_ADDRESS(&sg[i]))
3641 min_cnt = min(count - xfer_cnt, sg[i].length);
3642 memcpy(IPS_SG_ADDRESS(&sg[i]), &cdata[xfer_cnt],
3644 xfer_cnt += min_cnt;
3648 unsigned int min_cnt = min(count, scmd->request_bufflen);
3649 memcpy(scmd->request_buffer, data, min_cnt);
3653 /****************************************************************************/
3655 /* Routine Name: ips_scmd_buf_read */
3657 /* Routine Description: */
3658 /* Copy data from a Scsi_Cmnd to a new, linear buffer */
3659 /****************************************************************************/
3661 ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned
3666 unsigned int min_cnt, xfer_cnt;
3667 char *cdata = (char *) data;
3668 struct scatterlist *sg = scmd->request_buffer;
3669 for (i = 0, xfer_cnt = 0;
3670 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3671 if (!IPS_SG_ADDRESS(&sg[i]))
3673 min_cnt = min(count - xfer_cnt, sg[i].length);
3674 memcpy(&cdata[xfer_cnt], IPS_SG_ADDRESS(&sg[i]),
3676 xfer_cnt += min_cnt;
3680 unsigned int min_cnt = min(count, scmd->request_bufflen);
3681 memcpy(data, scmd->request_buffer, min_cnt);
3685 /****************************************************************************/
3687 /* Routine Name: ips_send_cmd */
3689 /* Routine Description: */
3691 /* Map SCSI commands to ServeRAID commands for logical drives */
3693 /****************************************************************************/
3695 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3700 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3703 METHOD_TRACE("ips_send_cmd", 1);
3707 if (!scb->scsi_cmd) {
3708 /* internal command */
3711 /* Controller commands can't be issued */
3712 /* to real devices -- fail them */
3713 if ((ha->waitflag == TRUE) &&
3714 (ha->cmd_in_progress == scb->cdb[0])) {
3715 ha->waitflag = FALSE;
3720 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3721 /* command to logical bus -- interpret */
3722 ret = IPS_SUCCESS_IMM;
3724 switch (scb->scsi_cmd->cmnd[0]) {
3725 case ALLOW_MEDIUM_REMOVAL:
3728 case WRITE_FILEMARKS:
3730 scb->scsi_cmd->result = DID_ERROR << 16;
3734 scb->scsi_cmd->result = DID_OK << 16;
3736 case TEST_UNIT_READY:
3738 if (scb->target_id == IPS_ADAPTER_ID) {
3740 * Either we have a TUR
3741 * or we have a SCSI inquiry
3743 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3744 scb->scsi_cmd->result = DID_OK << 16;
3746 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3747 IPS_SCSI_INQ_DATA inquiry;
3750 sizeof (IPS_SCSI_INQ_DATA));
3752 inquiry.DeviceType =
3753 IPS_SCSI_INQ_TYPE_PROCESSOR;
3754 inquiry.DeviceTypeQualifier =
3755 IPS_SCSI_INQ_LU_CONNECTED;
3756 inquiry.Version = IPS_SCSI_INQ_REV2;
3757 inquiry.ResponseDataFormat =
3758 IPS_SCSI_INQ_RD_REV2;
3759 inquiry.AdditionalLength = 31;
3761 IPS_SCSI_INQ_Address16;
3763 IPS_SCSI_INQ_WBus16 |
3765 strncpy(inquiry.VendorId, "IBM ",
3767 strncpy(inquiry.ProductId,
3769 strncpy(inquiry.ProductRevisionLevel,
3772 ips_scmd_buf_write(scb->scsi_cmd,
3776 scb->scsi_cmd->result = DID_OK << 16;
3779 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3780 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3781 scb->cmd.logical_info.reserved = 0;
3782 scb->cmd.logical_info.reserved2 = 0;
3783 scb->data_len = sizeof (IPS_LD_INFO);
3784 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3786 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3793 ips_reqsen(ha, scb);
3794 scb->scsi_cmd->result = DID_OK << 16;
3800 scb->cmd.basic_io.op_code =
3801 (scb->scsi_cmd->cmnd[0] ==
3802 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3803 scb->cmd.basic_io.enhanced_sg = 0;
3804 scb->cmd.basic_io.sg_addr =
3805 cpu_to_le32(scb->data_busaddr);
3807 scb->cmd.basic_io.op_code =
3808 (scb->scsi_cmd->cmnd[0] ==
3809 READ_6) ? IPS_CMD_READ_SG :
3811 scb->cmd.basic_io.enhanced_sg =
3812 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3813 scb->cmd.basic_io.sg_addr =
3814 cpu_to_le32(scb->sg_busaddr);
3817 scb->cmd.basic_io.segment_4G = 0;
3818 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3819 scb->cmd.basic_io.log_drv = scb->target_id;
3820 scb->cmd.basic_io.sg_count = scb->sg_len;
3822 if (scb->cmd.basic_io.lba)
3823 scb->cmd.basic_io.lba =
3824 cpu_to_le32(le32_to_cpu
3825 (scb->cmd.basic_io.lba) +
3826 le16_to_cpu(scb->cmd.basic_io.
3829 scb->cmd.basic_io.lba =
3831 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3833 (scb->scsi_cmd->cmnd[3]));
3835 scb->cmd.basic_io.sector_count =
3836 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3838 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3839 scb->cmd.basic_io.sector_count =
3848 scb->cmd.basic_io.op_code =
3849 (scb->scsi_cmd->cmnd[0] ==
3850 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3851 scb->cmd.basic_io.enhanced_sg = 0;
3852 scb->cmd.basic_io.sg_addr =
3853 cpu_to_le32(scb->data_busaddr);
3855 scb->cmd.basic_io.op_code =
3856 (scb->scsi_cmd->cmnd[0] ==
3857 READ_10) ? IPS_CMD_READ_SG :
3859 scb->cmd.basic_io.enhanced_sg =
3860 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3861 scb->cmd.basic_io.sg_addr =
3862 cpu_to_le32(scb->sg_busaddr);
3865 scb->cmd.basic_io.segment_4G = 0;
3866 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3867 scb->cmd.basic_io.log_drv = scb->target_id;
3868 scb->cmd.basic_io.sg_count = scb->sg_len;
3870 if (scb->cmd.basic_io.lba)
3871 scb->cmd.basic_io.lba =
3872 cpu_to_le32(le32_to_cpu
3873 (scb->cmd.basic_io.lba) +
3874 le16_to_cpu(scb->cmd.basic_io.
3877 scb->cmd.basic_io.lba =
3878 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3882 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3885 scb->cmd.basic_io.sector_count =
3886 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3888 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3890 * This is a null condition
3891 * we don't have to do anything
3894 scb->scsi_cmd->result = DID_OK << 16;
3902 scb->scsi_cmd->result = DID_OK << 16;
3906 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3907 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3908 scb->cmd.basic_io.segment_4G = 0;
3909 scb->cmd.basic_io.enhanced_sg = 0;
3910 scb->data_len = sizeof (*ha->enq);
3911 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3916 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3917 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3918 scb->cmd.logical_info.reserved = 0;
3919 scb->cmd.logical_info.reserved2 = 0;
3920 scb->cmd.logical_info.reserved3 = 0;
3921 scb->data_len = sizeof (IPS_LD_INFO);
3922 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3924 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3928 case SEND_DIAGNOSTIC:
3929 case REASSIGN_BLOCKS:
3933 case READ_DEFECT_DATA:
3936 scb->scsi_cmd->result = DID_OK << 16;
3940 /* Set the Return Info to appear like the Command was */
3941 /* attempted, a Check Condition occurred, and Sense */
3942 /* Data indicating an Invalid CDB OpCode is returned. */
3943 sp = (char *) scb->scsi_cmd->sense_buffer;
3944 memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
3946 sp[0] = 0x70; /* Error Code */
3947 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3948 sp[7] = 0x0A; /* Additional Sense Length */
3949 sp[12] = 0x20; /* ASC = Invalid OpCode */
3950 sp[13] = 0x00; /* ASCQ */
3952 device_error = 2; /* Indicate Check Condition */
3953 scb->scsi_cmd->result = device_error | (DID_OK << 16);
3958 if (ret == IPS_SUCCESS_IMM)
3964 /* If we already know the Device is Not there, no need to attempt a Command */
3965 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
3966 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
3967 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
3968 return (IPS_SUCCESS_IMM);
3971 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
3972 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
3973 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
3974 (unsigned long) &scb->
3976 (unsigned long) scb);
3977 scb->cmd.dcdb.reserved = 0;
3978 scb->cmd.dcdb.reserved2 = 0;
3979 scb->cmd.dcdb.reserved3 = 0;
3980 scb->cmd.dcdb.segment_4G = 0;
3981 scb->cmd.dcdb.enhanced_sg = 0;
3983 TimeOut = scb->scsi_cmd->timeout_per_command;
3985 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
3987 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
3989 scb->cmd.dcdb.op_code =
3990 IPS_CMD_EXTENDED_DCDB_SG;
3991 scb->cmd.dcdb.enhanced_sg =
3992 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3995 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
3996 tapeDCDB->device_address =
3997 ((scb->bus - 1) << 4) | scb->target_id;
3998 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
3999 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
4002 if (TimeOut < (10 * HZ))
4003 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4004 else if (TimeOut < (60 * HZ))
4005 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4006 else if (TimeOut < (1200 * HZ))
4007 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4010 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
4011 tapeDCDB->reserved_for_LUN = 0;
4012 tapeDCDB->transfer_length = scb->data_len;
4013 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
4014 tapeDCDB->buffer_pointer =
4015 cpu_to_le32(scb->sg_busaddr);
4017 tapeDCDB->buffer_pointer =
4018 cpu_to_le32(scb->data_busaddr);
4019 tapeDCDB->sg_count = scb->sg_len;
4020 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
4021 tapeDCDB->scsi_status = 0;
4022 tapeDCDB->reserved = 0;
4023 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
4024 scb->scsi_cmd->cmd_len);
4027 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
4029 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
4030 scb->cmd.dcdb.enhanced_sg =
4031 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4034 scb->dcdb.device_address =
4035 ((scb->bus - 1) << 4) | scb->target_id;
4036 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4039 if (TimeOut < (10 * HZ))
4040 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4041 else if (TimeOut < (60 * HZ))
4042 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4043 else if (TimeOut < (1200 * HZ))
4044 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4047 scb->dcdb.transfer_length = scb->data_len;
4048 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
4049 scb->dcdb.transfer_length = 0;
4050 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
4051 scb->dcdb.buffer_pointer =
4052 cpu_to_le32(scb->sg_busaddr);
4054 scb->dcdb.buffer_pointer =
4055 cpu_to_le32(scb->data_busaddr);
4056 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
4057 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
4058 scb->dcdb.sg_count = scb->sg_len;
4059 scb->dcdb.reserved = 0;
4060 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
4061 scb->scsi_cmd->cmd_len);
4062 scb->dcdb.scsi_status = 0;
4063 scb->dcdb.reserved2[0] = 0;
4064 scb->dcdb.reserved2[1] = 0;
4065 scb->dcdb.reserved2[2] = 0;
4069 return ((*ha->func.issue) (ha, scb));
4072 /****************************************************************************/
4074 /* Routine Name: ips_chk_status */
4076 /* Routine Description: */
4078 /* Check the status of commands to logical drives */
4079 /* Assumed to be called with the HA lock */
4080 /****************************************************************************/
4082 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
4086 uint8_t basic_status;
4090 METHOD_TRACE("ips_chkstatus", 1);
4092 scb = &ha->scbs[pstatus->fields.command_id];
4093 scb->basic_status = basic_status =
4094 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
4095 scb->extended_status = ext_status = pstatus->fields.extended_status;
4098 sp->residue_len = 0;
4099 sp->scb_addr = (void *) scb;
4101 /* Remove the item from the active queue */
4102 ips_removeq_scb(&ha->scb_activelist, scb);
4105 /* internal commands are handled in do_ipsintr */
4108 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
4112 scb->cmd.basic_io.command_id,
4113 scb->bus, scb->target_id, scb->lun);
4115 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
4116 /* passthru - just returns the raw result */
4121 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
4122 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
4124 if (scb->bus == 0) {
4125 if ((basic_status & IPS_GSC_STATUS_MASK) ==
4126 IPS_CMD_RECOVERED_ERROR) {
4128 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4129 ips_name, ha->host_num,
4130 scb->cmd.basic_io.op_code,
4131 basic_status, ext_status);
4134 switch (scb->scsi_cmd->cmnd[0]) {
4135 case ALLOW_MEDIUM_REMOVAL:
4138 case WRITE_FILEMARKS:
4140 errcode = DID_ERROR;
4146 case TEST_UNIT_READY:
4147 if (!ips_online(ha, scb)) {
4148 errcode = DID_TIME_OUT;
4153 if (ips_online(ha, scb)) {
4154 ips_inquiry(ha, scb);
4156 errcode = DID_TIME_OUT;
4161 ips_reqsen(ha, scb);
4173 if (!ips_online(ha, scb)
4174 || !ips_msense(ha, scb)) {
4175 errcode = DID_ERROR;
4180 if (ips_online(ha, scb))
4183 errcode = DID_TIME_OUT;
4187 case SEND_DIAGNOSTIC:
4188 case REASSIGN_BLOCKS:
4192 errcode = DID_ERROR;
4197 case READ_DEFECT_DATA:
4203 errcode = DID_ERROR;
4206 scb->scsi_cmd->result = errcode << 16;
4207 } else { /* bus == 0 */
4208 /* restrict access to physical drives */
4209 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
4210 ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) ==
4213 scb->scsi_cmd->result = DID_TIME_OUT << 16;
4216 } else { /* recovered error / success */
4217 if (scb->bus == 0) {
4219 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4220 ips_name, ha->host_num,
4221 scb->cmd.basic_io.op_code, basic_status,
4225 ips_map_status(ha, scb, sp);
4229 /****************************************************************************/
4231 /* Routine Name: ips_online */
4233 /* Routine Description: */
4235 /* Determine if a logical drive is online */
4237 /****************************************************************************/
4239 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4241 METHOD_TRACE("ips_online", 1);
4243 if (scb->target_id >= IPS_MAX_LD)
4246 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4247 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4251 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4253 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4255 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4257 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4264 /****************************************************************************/
4266 /* Routine Name: ips_inquiry */
4268 /* Routine Description: */
4270 /* Simulate an inquiry command to a logical drive */
4272 /****************************************************************************/
4274 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4276 IPS_SCSI_INQ_DATA inquiry;
4278 METHOD_TRACE("ips_inquiry", 1);
4280 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4282 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4283 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4284 inquiry.Version = IPS_SCSI_INQ_REV2;
4285 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4286 inquiry.AdditionalLength = 31;
4287 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4289 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4290 strncpy(inquiry.VendorId, "IBM ", 8);
4291 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4292 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4294 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4299 /****************************************************************************/
4301 /* Routine Name: ips_rdcap */
4303 /* Routine Description: */
4305 /* Simulate a read capacity command to a logical drive */
4307 /****************************************************************************/
4309 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4311 IPS_SCSI_CAPACITY cap;
4313 METHOD_TRACE("ips_rdcap", 1);
4315 if (scb->scsi_cmd->bufflen < 8)
4319 cpu_to_be32(le32_to_cpu
4320 (ha->logical_drive_info->
4321 drive_info[scb->target_id].sector_count) - 1);
4322 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4324 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4329 /****************************************************************************/
4331 /* Routine Name: ips_msense */
4333 /* Routine Description: */
4335 /* Simulate a mode sense command to a logical drive */
4337 /****************************************************************************/
4339 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4344 IPS_SCSI_MODE_PAGE_DATA mdata;
4346 METHOD_TRACE("ips_msense", 1);
4348 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4349 (ha->enq->ucMiscFlag & 0x8) == 0) {
4350 heads = IPS_NORM_HEADS;
4351 sectors = IPS_NORM_SECTORS;
4353 heads = IPS_COMP_HEADS;
4354 sectors = IPS_COMP_SECTORS;
4358 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4359 1) / (heads * sectors);
4361 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4363 mdata.hdr.BlockDescLength = 8;
4365 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4366 case 0x03: /* page 3 */
4367 mdata.pdata.pg3.PageCode = 3;
4368 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4369 mdata.hdr.DataLength =
4370 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4371 mdata.pdata.pg3.TracksPerZone = 0;
4372 mdata.pdata.pg3.AltSectorsPerZone = 0;
4373 mdata.pdata.pg3.AltTracksPerZone = 0;
4374 mdata.pdata.pg3.AltTracksPerVolume = 0;
4375 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4376 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4377 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4378 mdata.pdata.pg3.TrackSkew = 0;
4379 mdata.pdata.pg3.CylinderSkew = 0;
4380 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4384 mdata.pdata.pg4.PageCode = 4;
4385 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4386 mdata.hdr.DataLength =
4387 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4388 mdata.pdata.pg4.CylindersHigh =
4389 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4390 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4391 mdata.pdata.pg4.Heads = heads;
4392 mdata.pdata.pg4.WritePrecompHigh = 0;
4393 mdata.pdata.pg4.WritePrecompLow = 0;
4394 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4395 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4396 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4397 mdata.pdata.pg4.LandingZoneHigh = 0;
4398 mdata.pdata.pg4.LandingZoneLow = 0;
4399 mdata.pdata.pg4.flags = 0;
4400 mdata.pdata.pg4.RotationalOffset = 0;
4401 mdata.pdata.pg4.MediumRotationRate = 0;
4404 mdata.pdata.pg8.PageCode = 8;
4405 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4406 mdata.hdr.DataLength =
4407 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4408 /* everything else is left set to 0 */
4415 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4420 /****************************************************************************/
4422 /* Routine Name: ips_reqsen */
4424 /* Routine Description: */
4426 /* Simulate a request sense command to a logical drive */
4428 /****************************************************************************/
4430 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4432 IPS_SCSI_REQSEN reqsen;
4434 METHOD_TRACE("ips_reqsen", 1);
4436 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4438 reqsen.ResponseCode =
4439 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4440 reqsen.AdditionalLength = 10;
4441 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4442 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4444 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4449 /****************************************************************************/
4451 /* Routine Name: ips_free */
4453 /* Routine Description: */
4455 /* Free any allocated space for this controller */
4457 /****************************************************************************/
4459 ips_free(ips_ha_t * ha)
4462 METHOD_TRACE("ips_free", 1);
4466 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4467 ha->enq, ha->enq_busaddr);
4477 pci_free_consistent(ha->pcidev,
4478 sizeof (IPS_ADAPTER) +
4479 sizeof (IPS_IO_CMD), ha->adapt,
4480 ha->adapt->hw_status_start);
4484 if (ha->logical_drive_info) {
4485 pci_free_consistent(ha->pcidev,
4486 sizeof (IPS_LD_INFO),
4487 ha->logical_drive_info,
4488 ha->logical_drive_info_dma_addr);
4489 ha->logical_drive_info = NULL;
4502 if (ha->ioctl_data) {
4503 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4504 ha->ioctl_data, ha->ioctl_busaddr);
4505 ha->ioctl_data = NULL;
4506 ha->ioctl_datasize = 0;
4509 ips_deallocatescbs(ha, ha->max_cmds);
4511 /* free memory mapped (if applicable) */
4513 iounmap(ha->ioremap_ptr);
4514 ha->ioremap_ptr = NULL;
4519 release_mem_region(ha->mem_addr, ha->mem_len);
4525 /****************************************************************************/
4527 /* Routine Name: ips_deallocatescbs */
4529 /* Routine Description: */
4531 /* Free the command blocks */
4533 /****************************************************************************/
4535 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4538 pci_free_consistent(ha->pcidev,
4539 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4540 ha->scbs->sg_list.list,
4541 ha->scbs->sg_busaddr);
4542 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4543 ha->scbs, ha->scbs->scb_busaddr);
4549 /****************************************************************************/
4551 /* Routine Name: ips_allocatescbs */
4553 /* Routine Description: */
4555 /* Allocate the command blocks */
4557 /****************************************************************************/
4559 ips_allocatescbs(ips_ha_t * ha)
4564 dma_addr_t command_dma, sg_dma;
4566 METHOD_TRACE("ips_allocatescbs", 1);
4568 /* Allocate memory for the SCBs */
4570 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4572 if (ha->scbs == NULL)
4575 pci_alloc_consistent(ha->pcidev,
4576 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4577 ha->max_cmds, &sg_dma);
4578 if (ips_sg.list == NULL) {
4579 pci_free_consistent(ha->pcidev,
4580 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4585 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4587 for (i = 0; i < ha->max_cmds; i++) {
4588 scb_p = &ha->scbs[i];
4589 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4590 /* set up S/G list */
4591 if (IPS_USE_ENH_SGLIST(ha)) {
4592 scb_p->sg_list.enh_list =
4593 ips_sg.enh_list + i * IPS_MAX_SG;
4595 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4597 scb_p->sg_list.std_list =
4598 ips_sg.std_list + i * IPS_MAX_SG;
4600 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4603 /* add to the free list */
4604 if (i < ha->max_cmds - 1) {
4605 scb_p->q_next = ha->scb_freelist;
4606 ha->scb_freelist = scb_p;
4614 /****************************************************************************/
4616 /* Routine Name: ips_init_scb */
4618 /* Routine Description: */
4620 /* Initialize a CCB to default values */
4622 /****************************************************************************/
4624 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4626 IPS_SG_LIST sg_list;
4627 uint32_t cmd_busaddr, sg_busaddr;
4628 METHOD_TRACE("ips_init_scb", 1);
4633 sg_list.list = scb->sg_list.list;
4634 cmd_busaddr = scb->scb_busaddr;
4635 sg_busaddr = scb->sg_busaddr;
4637 memset(scb, 0, sizeof (ips_scb_t));
4638 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4640 /* Initialize dummy command bucket */
4641 ha->dummy->op_code = 0xFF;
4642 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4643 + sizeof (IPS_ADAPTER));
4644 ha->dummy->command_id = IPS_MAX_CMDS;
4646 /* set bus address of scb */
4647 scb->scb_busaddr = cmd_busaddr;
4648 scb->sg_busaddr = sg_busaddr;
4649 scb->sg_list.list = sg_list.list;
4652 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4653 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4654 + sizeof (IPS_ADAPTER));
4657 /****************************************************************************/
4659 /* Routine Name: ips_get_scb */
4661 /* Routine Description: */
4663 /* Initialize a CCB to default values */
4665 /* ASSUMED to be callled from within a lock */
4667 /****************************************************************************/
4669 ips_getscb(ips_ha_t * ha)
4673 METHOD_TRACE("ips_getscb", 1);
4675 if ((scb = ha->scb_freelist) == NULL) {
4680 ha->scb_freelist = scb->q_next;
4684 ips_init_scb(ha, scb);
4689 /****************************************************************************/
4691 /* Routine Name: ips_free_scb */
4693 /* Routine Description: */
4695 /* Return an unused CCB back to the free list */
4697 /* ASSUMED to be called from within a lock */
4699 /****************************************************************************/
4701 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4704 METHOD_TRACE("ips_freescb", 1);
4705 if (scb->flags & IPS_SCB_MAP_SG)
4706 pci_unmap_sg(ha->pcidev, scb->scsi_cmd->request_buffer,
4707 scb->scsi_cmd->use_sg, IPS_DMA_DIR(scb));
4708 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4709 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4712 /* check to make sure this is not our "special" scb */
4713 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4714 scb->q_next = ha->scb_freelist;
4715 ha->scb_freelist = scb;
4719 /****************************************************************************/
4721 /* Routine Name: ips_isinit_copperhead */
4723 /* Routine Description: */
4725 /* Is controller initialized ? */
4727 /****************************************************************************/
4729 ips_isinit_copperhead(ips_ha_t * ha)
4734 METHOD_TRACE("ips_isinit_copperhead", 1);
4736 isr = inb(ha->io_addr + IPS_REG_HISR);
4737 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4739 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4745 /****************************************************************************/
4747 /* Routine Name: ips_isinit_copperhead_memio */
4749 /* Routine Description: */
4751 /* Is controller initialized ? */
4753 /****************************************************************************/
4755 ips_isinit_copperhead_memio(ips_ha_t * ha)
4760 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4762 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4763 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4765 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4771 /****************************************************************************/
4773 /* Routine Name: ips_isinit_morpheus */
4775 /* Routine Description: */
4777 /* Is controller initialized ? */
4779 /****************************************************************************/
4781 ips_isinit_morpheus(ips_ha_t * ha)
4786 METHOD_TRACE("ips_is_init_morpheus", 1);
4788 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4789 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4793 else if (bits & 0x3)
4799 /****************************************************************************/
4801 /* Routine Name: ips_enable_int_copperhead */
4803 /* Routine Description: */
4804 /* Turn on interrupts */
4806 /****************************************************************************/
4808 ips_enable_int_copperhead(ips_ha_t * ha)
4810 METHOD_TRACE("ips_enable_int_copperhead", 1);
4812 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4813 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4816 /****************************************************************************/
4818 /* Routine Name: ips_enable_int_copperhead_memio */
4820 /* Routine Description: */
4821 /* Turn on interrupts */
4823 /****************************************************************************/
4825 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4827 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4829 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4830 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4833 /****************************************************************************/
4835 /* Routine Name: ips_enable_int_morpheus */
4837 /* Routine Description: */
4838 /* Turn on interrupts */
4840 /****************************************************************************/
4842 ips_enable_int_morpheus(ips_ha_t * ha)
4846 METHOD_TRACE("ips_enable_int_morpheus", 1);
4848 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4850 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4851 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4854 /****************************************************************************/
4856 /* Routine Name: ips_init_copperhead */
4858 /* Routine Description: */
4860 /* Initialize a copperhead controller */
4862 /****************************************************************************/
4864 ips_init_copperhead(ips_ha_t * ha)
4868 uint8_t PostByte[IPS_MAX_POST_BYTES];
4869 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4872 METHOD_TRACE("ips_init_copperhead", 1);
4874 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4875 for (j = 0; j < 45; j++) {
4876 Isr = inb(ha->io_addr + IPS_REG_HISR);
4877 if (Isr & IPS_BIT_GHI)
4880 /* Delay for 1 Second */
4881 MDELAY(IPS_ONE_SEC);
4885 /* error occurred */
4888 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4889 outb(Isr, ha->io_addr + IPS_REG_HISR);
4892 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4893 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4894 "reset controller fails (post status %x %x).\n",
4895 PostByte[0], PostByte[1]);
4900 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4901 for (j = 0; j < 240; j++) {
4902 Isr = inb(ha->io_addr + IPS_REG_HISR);
4903 if (Isr & IPS_BIT_GHI)
4906 /* Delay for 1 Second */
4907 MDELAY(IPS_ONE_SEC);
4911 /* error occurred */
4914 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4915 outb(Isr, ha->io_addr + IPS_REG_HISR);
4918 for (i = 0; i < 240; i++) {
4919 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
4921 if ((Cbsp & IPS_BIT_OP) == 0)
4924 /* Delay for 1 Second */
4925 MDELAY(IPS_ONE_SEC);
4933 outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
4935 /* Enable busmastering */
4936 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
4938 if (ha->revision_id == IPS_REVID_TROMBONE64)
4939 /* fix for anaconda64 */
4940 outl(0, ha->io_addr + IPS_REG_NDAE);
4942 /* Enable interrupts */
4943 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
4948 /****************************************************************************/
4950 /* Routine Name: ips_init_copperhead_memio */
4952 /* Routine Description: */
4954 /* Initialize a copperhead controller with memory mapped I/O */
4956 /****************************************************************************/
4958 ips_init_copperhead_memio(ips_ha_t * ha)
4962 uint8_t PostByte[IPS_MAX_POST_BYTES];
4963 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4966 METHOD_TRACE("ips_init_copperhead_memio", 1);
4968 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4969 for (j = 0; j < 45; j++) {
4970 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4971 if (Isr & IPS_BIT_GHI)
4974 /* Delay for 1 Second */
4975 MDELAY(IPS_ONE_SEC);
4979 /* error occurred */
4982 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
4983 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
4986 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4987 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4988 "reset controller fails (post status %x %x).\n",
4989 PostByte[0], PostByte[1]);
4994 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4995 for (j = 0; j < 240; j++) {
4996 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4997 if (Isr & IPS_BIT_GHI)
5000 /* Delay for 1 Second */
5001 MDELAY(IPS_ONE_SEC);
5005 /* error occurred */
5008 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5009 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5012 for (i = 0; i < 240; i++) {
5013 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
5015 if ((Cbsp & IPS_BIT_OP) == 0)
5018 /* Delay for 1 Second */
5019 MDELAY(IPS_ONE_SEC);
5023 /* error occurred */
5027 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
5029 /* Enable busmastering */
5030 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
5032 if (ha->revision_id == IPS_REVID_TROMBONE64)
5033 /* fix for anaconda64 */
5034 writel(0, ha->mem_ptr + IPS_REG_NDAE);
5036 /* Enable interrupts */
5037 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
5039 /* if we get here then everything went OK */
5043 /****************************************************************************/
5045 /* Routine Name: ips_init_morpheus */
5047 /* Routine Description: */
5049 /* Initialize a morpheus controller */
5051 /****************************************************************************/
5053 ips_init_morpheus(ips_ha_t * ha)
5061 METHOD_TRACE("ips_init_morpheus", 1);
5063 /* Wait up to 45 secs for Post */
5064 for (i = 0; i < 45; i++) {
5065 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5067 if (Isr & IPS_BIT_I960_MSG0I)
5070 /* Delay for 1 Second */
5071 MDELAY(IPS_ONE_SEC);
5075 /* error occurred */
5076 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5077 "timeout waiting for post.\n");
5082 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5084 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
5085 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5086 "Flashing Battery PIC, Please wait ...\n");
5088 /* Clear the interrupt bit */
5089 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5090 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5092 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
5093 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5096 /* Delay for 1 Second */
5097 MDELAY(IPS_ONE_SEC);
5101 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5102 "timeout waiting for Battery PIC Flash\n");
5108 /* Clear the interrupt bit */
5109 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5110 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5112 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
5113 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5114 "reset controller fails (post status %x).\n", Post);
5119 /* Wait up to 240 secs for config bytes */
5120 for (i = 0; i < 240; i++) {
5121 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5123 if (Isr & IPS_BIT_I960_MSG1I)
5126 /* Delay for 1 Second */
5127 MDELAY(IPS_ONE_SEC);
5131 /* error occurred */
5132 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5133 "timeout waiting for config.\n");
5138 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
5140 /* Clear interrupt bit */
5141 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
5142 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5144 /* Turn on the interrupts */
5145 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
5147 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
5149 /* if we get here then everything went OK */
5151 /* Since we did a RESET, an EraseStripeLock may be needed */
5152 if (Post == 0xEF10) {
5153 if ((Config == 0x000F) || (Config == 0x0009))
5154 ha->requires_esl = 1;
5160 /****************************************************************************/
5162 /* Routine Name: ips_reset_copperhead */
5164 /* Routine Description: */
5166 /* Reset the controller */
5168 /****************************************************************************/
5170 ips_reset_copperhead(ips_ha_t * ha)
5174 METHOD_TRACE("ips_reset_copperhead", 1);
5176 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5177 ips_name, ha->host_num, ha->io_addr, ha->irq);
5181 while (reset_counter < 2) {
5184 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5186 /* Delay for 1 Second */
5187 MDELAY(IPS_ONE_SEC);
5189 outb(0, ha->io_addr + IPS_REG_SCPR);
5191 /* Delay for 1 Second */
5192 MDELAY(IPS_ONE_SEC);
5194 if ((*ha->func.init) (ha))
5196 else if (reset_counter >= 2) {
5205 /****************************************************************************/
5207 /* Routine Name: ips_reset_copperhead_memio */
5209 /* Routine Description: */
5211 /* Reset the controller */
5213 /****************************************************************************/
5215 ips_reset_copperhead_memio(ips_ha_t * ha)
5219 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5221 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5222 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5226 while (reset_counter < 2) {
5229 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5231 /* Delay for 1 Second */
5232 MDELAY(IPS_ONE_SEC);
5234 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5236 /* Delay for 1 Second */
5237 MDELAY(IPS_ONE_SEC);
5239 if ((*ha->func.init) (ha))
5241 else if (reset_counter >= 2) {
5250 /****************************************************************************/
5252 /* Routine Name: ips_reset_morpheus */
5254 /* Routine Description: */
5256 /* Reset the controller */
5258 /****************************************************************************/
5260 ips_reset_morpheus(ips_ha_t * ha)
5265 METHOD_TRACE("ips_reset_morpheus", 1);
5267 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5268 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5272 while (reset_counter < 2) {
5275 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5277 /* Delay for 5 Seconds */
5278 MDELAY(5 * IPS_ONE_SEC);
5280 /* Do a PCI config read to wait for adapter */
5281 pci_read_config_byte(ha->pcidev, 4, &junk);
5283 if ((*ha->func.init) (ha))
5285 else if (reset_counter >= 2) {
5294 /****************************************************************************/
5296 /* Routine Name: ips_statinit */
5298 /* Routine Description: */
5300 /* Initialize the status queues on the controller */
5302 /****************************************************************************/
5304 ips_statinit(ips_ha_t * ha)
5306 uint32_t phys_status_start;
5308 METHOD_TRACE("ips_statinit", 1);
5310 ha->adapt->p_status_start = ha->adapt->status;
5311 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5312 ha->adapt->p_status_tail = ha->adapt->status;
5314 phys_status_start = ha->adapt->hw_status_start;
5315 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
5316 outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE),
5317 ha->io_addr + IPS_REG_SQER);
5318 outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE),
5319 ha->io_addr + IPS_REG_SQHR);
5320 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
5322 ha->adapt->hw_status_tail = phys_status_start;
5325 /****************************************************************************/
5327 /* Routine Name: ips_statinit_memio */
5329 /* Routine Description: */
5331 /* Initialize the status queues on the controller */
5333 /****************************************************************************/
5335 ips_statinit_memio(ips_ha_t * ha)
5337 uint32_t phys_status_start;
5339 METHOD_TRACE("ips_statinit_memio", 1);
5341 ha->adapt->p_status_start = ha->adapt->status;
5342 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5343 ha->adapt->p_status_tail = ha->adapt->status;
5345 phys_status_start = ha->adapt->hw_status_start;
5346 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5347 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5348 ha->mem_ptr + IPS_REG_SQER);
5349 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5350 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5352 ha->adapt->hw_status_tail = phys_status_start;
5355 /****************************************************************************/
5357 /* Routine Name: ips_statupd_copperhead */
5359 /* Routine Description: */
5361 /* Remove an element from the status queue */
5363 /****************************************************************************/
5365 ips_statupd_copperhead(ips_ha_t * ha)
5367 METHOD_TRACE("ips_statupd_copperhead", 1);
5369 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5370 ha->adapt->p_status_tail++;
5371 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5373 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5374 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5377 outl(cpu_to_le32(ha->adapt->hw_status_tail),
5378 ha->io_addr + IPS_REG_SQTR);
5380 return (ha->adapt->p_status_tail->value);
5383 /****************************************************************************/
5385 /* Routine Name: ips_statupd_copperhead_memio */
5387 /* Routine Description: */
5389 /* Remove an element from the status queue */
5391 /****************************************************************************/
5393 ips_statupd_copperhead_memio(ips_ha_t * ha)
5395 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5397 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5398 ha->adapt->p_status_tail++;
5399 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5401 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5402 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5405 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5407 return (ha->adapt->p_status_tail->value);
5410 /****************************************************************************/
5412 /* Routine Name: ips_statupd_morpheus */
5414 /* Routine Description: */
5416 /* Remove an element from the status queue */
5418 /****************************************************************************/
5420 ips_statupd_morpheus(ips_ha_t * ha)
5424 METHOD_TRACE("ips_statupd_morpheus", 1);
5426 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5431 /****************************************************************************/
5433 /* Routine Name: ips_issue_copperhead */
5435 /* Routine Description: */
5437 /* Send a command down to the controller */
5439 /****************************************************************************/
5441 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5446 METHOD_TRACE("ips_issue_copperhead", 1);
5448 if (scb->scsi_cmd) {
5449 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5453 scb->cmd.basic_io.command_id,
5454 scb->bus, scb->target_id, scb->lun);
5456 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5457 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5463 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5466 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5467 if (!(val & IPS_BIT_START_STOP))
5470 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5471 "ips_issue val [0x%x].\n", val);
5472 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5473 "ips_issue semaphore chk timeout.\n");
5475 return (IPS_FAILURE);
5479 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
5480 outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
5482 return (IPS_SUCCESS);
5485 /****************************************************************************/
5487 /* Routine Name: ips_issue_copperhead_memio */
5489 /* Routine Description: */
5491 /* Send a command down to the controller */
5493 /****************************************************************************/
5495 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5500 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5502 if (scb->scsi_cmd) {
5503 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5507 scb->cmd.basic_io.command_id,
5508 scb->bus, scb->target_id, scb->lun);
5510 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5511 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5516 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5519 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5520 if (!(val & IPS_BIT_START_STOP))
5523 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5524 "ips_issue val [0x%x].\n", val);
5525 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5526 "ips_issue semaphore chk timeout.\n");
5528 return (IPS_FAILURE);
5532 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5533 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5535 return (IPS_SUCCESS);
5538 /****************************************************************************/
5540 /* Routine Name: ips_issue_i2o */
5542 /* Routine Description: */
5544 /* Send a command down to the controller */
5546 /****************************************************************************/
5548 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5551 METHOD_TRACE("ips_issue_i2o", 1);
5553 if (scb->scsi_cmd) {
5554 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5558 scb->cmd.basic_io.command_id,
5559 scb->bus, scb->target_id, scb->lun);
5561 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5562 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5565 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
5567 return (IPS_SUCCESS);
5570 /****************************************************************************/
5572 /* Routine Name: ips_issue_i2o_memio */
5574 /* Routine Description: */
5576 /* Send a command down to the controller */
5578 /****************************************************************************/
5580 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5583 METHOD_TRACE("ips_issue_i2o_memio", 1);
5585 if (scb->scsi_cmd) {
5586 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5590 scb->cmd.basic_io.command_id,
5591 scb->bus, scb->target_id, scb->lun);
5593 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5594 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5597 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5599 return (IPS_SUCCESS);
5602 /****************************************************************************/
5604 /* Routine Name: ips_isintr_copperhead */
5606 /* Routine Description: */
5608 /* Test to see if an interrupt is for us */
5610 /****************************************************************************/
5612 ips_isintr_copperhead(ips_ha_t * ha)
5616 METHOD_TRACE("ips_isintr_copperhead", 2);
5618 Isr = inb(ha->io_addr + IPS_REG_HISR);
5621 /* ?!?! Nothing really there */
5624 if (Isr & IPS_BIT_SCE)
5626 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5627 /* status queue overflow or GHI */
5628 /* just clear the interrupt */
5629 outb(Isr, ha->io_addr + IPS_REG_HISR);
5635 /****************************************************************************/
5637 /* Routine Name: ips_isintr_copperhead_memio */
5639 /* Routine Description: */
5641 /* Test to see if an interrupt is for us */
5643 /****************************************************************************/
5645 ips_isintr_copperhead_memio(ips_ha_t * ha)
5649 METHOD_TRACE("ips_isintr_memio", 2);
5651 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5654 /* ?!?! Nothing really there */
5657 if (Isr & IPS_BIT_SCE)
5659 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5660 /* status queue overflow or GHI */
5661 /* just clear the interrupt */
5662 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5668 /****************************************************************************/
5670 /* Routine Name: ips_isintr_morpheus */
5672 /* Routine Description: */
5674 /* Test to see if an interrupt is for us */
5676 /****************************************************************************/
5678 ips_isintr_morpheus(ips_ha_t * ha)
5682 METHOD_TRACE("ips_isintr_morpheus", 2);
5684 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5686 if (Isr & IPS_BIT_I2O_OPQI)
5692 /****************************************************************************/
5694 /* Routine Name: ips_wait */
5696 /* Routine Description: */
5698 /* Wait for a command to complete */
5700 /****************************************************************************/
5702 ips_wait(ips_ha_t * ha, int time, int intr)
5707 METHOD_TRACE("ips_wait", 1);
5712 time *= IPS_ONE_SEC; /* convert seconds */
5714 while ((time > 0) && (!done)) {
5715 if (intr == IPS_INTR_ON) {
5716 if (ha->waitflag == FALSE) {
5721 } else if (intr == IPS_INTR_IORL) {
5722 if (ha->waitflag == FALSE) {
5724 * controller generated an interrupt to
5725 * acknowledge completion of the command
5726 * and ips_intr() has serviced the interrupt.
5734 * NOTE: we already have the io_request_lock so
5735 * even if we get an interrupt it won't get serviced
5736 * until after we finish.
5739 (*ha->func.intr) (ha);
5742 /* This looks like a very evil loop, but it only does this during start-up */
5750 /****************************************************************************/
5752 /* Routine Name: ips_write_driver_status */
5754 /* Routine Description: */
5756 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5758 /****************************************************************************/
5760 ips_write_driver_status(ips_ha_t * ha, int intr)
5762 METHOD_TRACE("ips_write_driver_status", 1);
5764 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5765 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5766 "unable to read NVRAM page 5.\n");
5771 /* check to make sure the page has a valid */
5773 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5775 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5776 ips_name, ha->host_num, ha->nvram->signature);
5777 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5781 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5782 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5783 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5784 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5785 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5786 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5787 ha->nvram->bios_low[3]);
5789 ips_get_bios_version(ha, intr);
5791 /* change values (as needed) */
5792 ha->nvram->operating_system = IPS_OS_LINUX;
5793 ha->nvram->adapter_type = ha->ad_type;
5794 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5795 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5796 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5797 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5799 ips_version_check(ha, intr); /* Check BIOS/FW/Driver Versions */
5801 /* now update the page */
5802 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5803 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5804 "unable to write NVRAM page 5.\n");
5809 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5810 ha->slot_num = ha->nvram->adapter_slot;
5815 /****************************************************************************/
5817 /* Routine Name: ips_read_adapter_status */
5819 /* Routine Description: */
5821 /* Do an Inquiry command to the adapter */
5823 /****************************************************************************/
5825 ips_read_adapter_status(ips_ha_t * ha, int intr)
5830 METHOD_TRACE("ips_read_adapter_status", 1);
5832 scb = &ha->scbs[ha->max_cmds - 1];
5834 ips_init_scb(ha, scb);
5836 scb->timeout = ips_cmd_timeout;
5837 scb->cdb[0] = IPS_CMD_ENQUIRY;
5839 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5840 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5841 scb->cmd.basic_io.sg_count = 0;
5842 scb->cmd.basic_io.lba = 0;
5843 scb->cmd.basic_io.sector_count = 0;
5844 scb->cmd.basic_io.log_drv = 0;
5845 scb->data_len = sizeof (*ha->enq);
5846 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5850 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5851 || (ret == IPS_SUCCESS_IMM)
5852 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5858 /****************************************************************************/
5860 /* Routine Name: ips_read_subsystem_parameters */
5862 /* Routine Description: */
5864 /* Read subsystem parameters from the adapter */
5866 /****************************************************************************/
5868 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
5873 METHOD_TRACE("ips_read_subsystem_parameters", 1);
5875 scb = &ha->scbs[ha->max_cmds - 1];
5877 ips_init_scb(ha, scb);
5879 scb->timeout = ips_cmd_timeout;
5880 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
5882 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
5883 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5884 scb->cmd.basic_io.sg_count = 0;
5885 scb->cmd.basic_io.lba = 0;
5886 scb->cmd.basic_io.sector_count = 0;
5887 scb->cmd.basic_io.log_drv = 0;
5888 scb->data_len = sizeof (*ha->subsys);
5889 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5893 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5894 || (ret == IPS_SUCCESS_IMM)
5895 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5898 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
5902 /****************************************************************************/
5904 /* Routine Name: ips_read_config */
5906 /* Routine Description: */
5908 /* Read the configuration on the adapter */
5910 /****************************************************************************/
5912 ips_read_config(ips_ha_t * ha, int intr)
5918 METHOD_TRACE("ips_read_config", 1);
5920 /* set defaults for initiator IDs */
5921 for (i = 0; i < 4; i++)
5922 ha->conf->init_id[i] = 7;
5924 scb = &ha->scbs[ha->max_cmds - 1];
5926 ips_init_scb(ha, scb);
5928 scb->timeout = ips_cmd_timeout;
5929 scb->cdb[0] = IPS_CMD_READ_CONF;
5931 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
5932 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5933 scb->data_len = sizeof (*ha->conf);
5934 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5938 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5939 || (ret == IPS_SUCCESS_IMM)
5940 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
5942 memset(ha->conf, 0, sizeof (IPS_CONF));
5944 /* reset initiator IDs */
5945 for (i = 0; i < 4; i++)
5946 ha->conf->init_id[i] = 7;
5948 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
5949 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
5950 IPS_CMD_CMPLT_WERROR)
5956 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
5960 /****************************************************************************/
5962 /* Routine Name: ips_readwrite_page5 */
5964 /* Routine Description: */
5966 /* Read nvram page 5 from the adapter */
5968 /****************************************************************************/
5970 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
5975 METHOD_TRACE("ips_readwrite_page5", 1);
5977 scb = &ha->scbs[ha->max_cmds - 1];
5979 ips_init_scb(ha, scb);
5981 scb->timeout = ips_cmd_timeout;
5982 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
5984 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
5985 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
5986 scb->cmd.nvram.page = 5;
5987 scb->cmd.nvram.write = write;
5988 scb->cmd.nvram.reserved = 0;
5989 scb->cmd.nvram.reserved2 = 0;
5990 scb->data_len = sizeof (*ha->nvram);
5991 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
5993 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
5995 /* issue the command */
5997 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5998 || (ret == IPS_SUCCESS_IMM)
5999 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6001 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
6006 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
6010 /****************************************************************************/
6012 /* Routine Name: ips_clear_adapter */
6014 /* Routine Description: */
6016 /* Clear the stripe lock tables */
6018 /****************************************************************************/
6020 ips_clear_adapter(ips_ha_t * ha, int intr)
6025 METHOD_TRACE("ips_clear_adapter", 1);
6027 scb = &ha->scbs[ha->max_cmds - 1];
6029 ips_init_scb(ha, scb);
6031 scb->timeout = ips_reset_timeout;
6032 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
6034 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
6035 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
6036 scb->cmd.config_sync.channel = 0;
6037 scb->cmd.config_sync.source_target = IPS_POCL;
6038 scb->cmd.config_sync.reserved = 0;
6039 scb->cmd.config_sync.reserved2 = 0;
6040 scb->cmd.config_sync.reserved3 = 0;
6044 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
6045 || (ret == IPS_SUCCESS_IMM)
6046 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6049 /* send unlock stripe command */
6050 ips_init_scb(ha, scb);
6052 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
6053 scb->timeout = ips_reset_timeout;
6055 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
6056 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
6057 scb->cmd.unlock_stripe.log_drv = 0;
6058 scb->cmd.unlock_stripe.control = IPS_CSL;
6059 scb->cmd.unlock_stripe.reserved = 0;
6060 scb->cmd.unlock_stripe.reserved2 = 0;
6061 scb->cmd.unlock_stripe.reserved3 = 0;
6065 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6066 || (ret == IPS_SUCCESS_IMM)
6067 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6073 /****************************************************************************/
6075 /* Routine Name: ips_ffdc_reset */
6077 /* Routine Description: */
6079 /* FFDC: write reset info */
6081 /****************************************************************************/
6083 ips_ffdc_reset(ips_ha_t * ha, int intr)
6087 METHOD_TRACE("ips_ffdc_reset", 1);
6089 scb = &ha->scbs[ha->max_cmds - 1];
6091 ips_init_scb(ha, scb);
6093 scb->timeout = ips_cmd_timeout;
6094 scb->cdb[0] = IPS_CMD_FFDC;
6095 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6096 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6097 scb->cmd.ffdc.reset_count = ha->reset_count;
6098 scb->cmd.ffdc.reset_type = 0x80;
6100 /* convert time to what the card wants */
6101 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6104 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6107 /****************************************************************************/
6109 /* Routine Name: ips_ffdc_time */
6111 /* Routine Description: */
6113 /* FFDC: write time info */
6115 /****************************************************************************/
6117 ips_ffdc_time(ips_ha_t * ha)
6121 METHOD_TRACE("ips_ffdc_time", 1);
6123 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
6125 scb = &ha->scbs[ha->max_cmds - 1];
6127 ips_init_scb(ha, scb);
6129 scb->timeout = ips_cmd_timeout;
6130 scb->cdb[0] = IPS_CMD_FFDC;
6131 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6132 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6133 scb->cmd.ffdc.reset_count = 0;
6134 scb->cmd.ffdc.reset_type = 0;
6136 /* convert time to what the card wants */
6137 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6140 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
6143 /****************************************************************************/
6145 /* Routine Name: ips_fix_ffdc_time */
6147 /* Routine Description: */
6148 /* Adjust time_t to what the card wants */
6150 /****************************************************************************/
6152 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6159 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6160 int month_lengths[12][2] = { {31, 31},
6174 METHOD_TRACE("ips_fix_ffdc_time", 1);
6176 days = current_time / IPS_SECS_DAY;
6177 rem = current_time % IPS_SECS_DAY;
6179 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6180 rem = rem % IPS_SECS_HOUR;
6181 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6182 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6184 year = IPS_EPOCH_YEAR;
6185 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6188 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6191 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6192 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6193 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6197 scb->cmd.ffdc.yearH = year / 100;
6198 scb->cmd.ffdc.yearL = year % 100;
6200 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6201 days -= month_lengths[i][yleap];
6203 scb->cmd.ffdc.month = i + 1;
6204 scb->cmd.ffdc.day = days + 1;
6207 /****************************************************************************
6208 * BIOS Flash Routines *
6209 ****************************************************************************/
6211 /****************************************************************************/
6213 /* Routine Name: ips_erase_bios */
6215 /* Routine Description: */
6216 /* Erase the BIOS on the adapter */
6218 /****************************************************************************/
6220 ips_erase_bios(ips_ha_t * ha)
6225 METHOD_TRACE("ips_erase_bios", 1);
6229 /* Clear the status register */
6230 outl(0, ha->io_addr + IPS_REG_FLAP);
6231 if (ha->revision_id == IPS_REVID_TROMBONE64)
6232 udelay(25); /* 25 us */
6234 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6235 if (ha->revision_id == IPS_REVID_TROMBONE64)
6236 udelay(25); /* 25 us */
6239 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6240 if (ha->revision_id == IPS_REVID_TROMBONE64)
6241 udelay(25); /* 25 us */
6244 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6245 if (ha->revision_id == IPS_REVID_TROMBONE64)
6246 udelay(25); /* 25 us */
6249 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6250 if (ha->revision_id == IPS_REVID_TROMBONE64)
6251 udelay(25); /* 25 us */
6253 timeout = 80000; /* 80 seconds */
6255 while (timeout > 0) {
6256 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6257 outl(0, ha->io_addr + IPS_REG_FLAP);
6258 udelay(25); /* 25 us */
6261 status = inb(ha->io_addr + IPS_REG_FLDP);
6270 /* check for timeout */
6274 /* try to suspend the erase */
6275 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6276 if (ha->revision_id == IPS_REVID_TROMBONE64)
6277 udelay(25); /* 25 us */
6279 /* wait for 10 seconds */
6281 while (timeout > 0) {
6282 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6283 outl(0, ha->io_addr + IPS_REG_FLAP);
6284 udelay(25); /* 25 us */
6287 status = inb(ha->io_addr + IPS_REG_FLDP);
6299 /* check for valid VPP */
6304 /* check for succesful flash */
6306 /* sequence error */
6309 /* Otherwise, we were successful */
6311 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6312 if (ha->revision_id == IPS_REVID_TROMBONE64)
6313 udelay(25); /* 25 us */
6316 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6317 if (ha->revision_id == IPS_REVID_TROMBONE64)
6318 udelay(25); /* 25 us */
6323 /****************************************************************************/
6325 /* Routine Name: ips_erase_bios_memio */
6327 /* Routine Description: */
6328 /* Erase the BIOS on the adapter */
6330 /****************************************************************************/
6332 ips_erase_bios_memio(ips_ha_t * ha)
6337 METHOD_TRACE("ips_erase_bios_memio", 1);
6341 /* Clear the status register */
6342 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6343 if (ha->revision_id == IPS_REVID_TROMBONE64)
6344 udelay(25); /* 25 us */
6346 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6347 if (ha->revision_id == IPS_REVID_TROMBONE64)
6348 udelay(25); /* 25 us */
6351 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6352 if (ha->revision_id == IPS_REVID_TROMBONE64)
6353 udelay(25); /* 25 us */
6356 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6357 if (ha->revision_id == IPS_REVID_TROMBONE64)
6358 udelay(25); /* 25 us */
6361 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6362 if (ha->revision_id == IPS_REVID_TROMBONE64)
6363 udelay(25); /* 25 us */
6365 timeout = 80000; /* 80 seconds */
6367 while (timeout > 0) {
6368 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6369 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6370 udelay(25); /* 25 us */
6373 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6382 /* check for timeout */
6386 /* try to suspend the erase */
6387 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6388 if (ha->revision_id == IPS_REVID_TROMBONE64)
6389 udelay(25); /* 25 us */
6391 /* wait for 10 seconds */
6393 while (timeout > 0) {
6394 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6395 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6396 udelay(25); /* 25 us */
6399 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6411 /* check for valid VPP */
6416 /* check for succesful flash */
6418 /* sequence error */
6421 /* Otherwise, we were successful */
6423 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6424 if (ha->revision_id == IPS_REVID_TROMBONE64)
6425 udelay(25); /* 25 us */
6428 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6429 if (ha->revision_id == IPS_REVID_TROMBONE64)
6430 udelay(25); /* 25 us */
6435 /****************************************************************************/
6437 /* Routine Name: ips_program_bios */
6439 /* Routine Description: */
6440 /* Program the BIOS on the adapter */
6442 /****************************************************************************/
6444 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6451 METHOD_TRACE("ips_program_bios", 1);
6455 for (i = 0; i < buffersize; i++) {
6457 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6458 if (ha->revision_id == IPS_REVID_TROMBONE64)
6459 udelay(25); /* 25 us */
6461 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6462 if (ha->revision_id == IPS_REVID_TROMBONE64)
6463 udelay(25); /* 25 us */
6465 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6466 if (ha->revision_id == IPS_REVID_TROMBONE64)
6467 udelay(25); /* 25 us */
6469 /* wait up to one second */
6471 while (timeout > 0) {
6472 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6473 outl(0, ha->io_addr + IPS_REG_FLAP);
6474 udelay(25); /* 25 us */
6477 status = inb(ha->io_addr + IPS_REG_FLDP);
6488 outl(0, ha->io_addr + IPS_REG_FLAP);
6489 if (ha->revision_id == IPS_REVID_TROMBONE64)
6490 udelay(25); /* 25 us */
6492 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6493 if (ha->revision_id == IPS_REVID_TROMBONE64)
6494 udelay(25); /* 25 us */
6499 /* check the status */
6500 if (status & 0x18) {
6501 /* programming error */
6502 outl(0, ha->io_addr + IPS_REG_FLAP);
6503 if (ha->revision_id == IPS_REVID_TROMBONE64)
6504 udelay(25); /* 25 us */
6506 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6507 if (ha->revision_id == IPS_REVID_TROMBONE64)
6508 udelay(25); /* 25 us */
6514 /* Enable reading */
6515 outl(0, ha->io_addr + IPS_REG_FLAP);
6516 if (ha->revision_id == IPS_REVID_TROMBONE64)
6517 udelay(25); /* 25 us */
6519 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6520 if (ha->revision_id == IPS_REVID_TROMBONE64)
6521 udelay(25); /* 25 us */
6526 /****************************************************************************/
6528 /* Routine Name: ips_program_bios_memio */
6530 /* Routine Description: */
6531 /* Program the BIOS on the adapter */
6533 /****************************************************************************/
6535 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6542 METHOD_TRACE("ips_program_bios_memio", 1);
6546 for (i = 0; i < buffersize; i++) {
6548 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6549 if (ha->revision_id == IPS_REVID_TROMBONE64)
6550 udelay(25); /* 25 us */
6552 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6553 if (ha->revision_id == IPS_REVID_TROMBONE64)
6554 udelay(25); /* 25 us */
6556 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6557 if (ha->revision_id == IPS_REVID_TROMBONE64)
6558 udelay(25); /* 25 us */
6560 /* wait up to one second */
6562 while (timeout > 0) {
6563 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6564 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6565 udelay(25); /* 25 us */
6568 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6579 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6580 if (ha->revision_id == IPS_REVID_TROMBONE64)
6581 udelay(25); /* 25 us */
6583 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6584 if (ha->revision_id == IPS_REVID_TROMBONE64)
6585 udelay(25); /* 25 us */
6590 /* check the status */
6591 if (status & 0x18) {
6592 /* programming error */
6593 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6594 if (ha->revision_id == IPS_REVID_TROMBONE64)
6595 udelay(25); /* 25 us */
6597 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6598 if (ha->revision_id == IPS_REVID_TROMBONE64)
6599 udelay(25); /* 25 us */
6605 /* Enable reading */
6606 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6607 if (ha->revision_id == IPS_REVID_TROMBONE64)
6608 udelay(25); /* 25 us */
6610 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6611 if (ha->revision_id == IPS_REVID_TROMBONE64)
6612 udelay(25); /* 25 us */
6617 /****************************************************************************/
6619 /* Routine Name: ips_verify_bios */
6621 /* Routine Description: */
6622 /* Verify the BIOS on the adapter */
6624 /****************************************************************************/
6626 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6632 METHOD_TRACE("ips_verify_bios", 1);
6635 outl(0, ha->io_addr + IPS_REG_FLAP);
6636 if (ha->revision_id == IPS_REVID_TROMBONE64)
6637 udelay(25); /* 25 us */
6639 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6642 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
6643 if (ha->revision_id == IPS_REVID_TROMBONE64)
6644 udelay(25); /* 25 us */
6645 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6649 for (i = 2; i < buffersize; i++) {
6651 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6652 if (ha->revision_id == IPS_REVID_TROMBONE64)
6653 udelay(25); /* 25 us */
6655 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6666 /****************************************************************************/
6668 /* Routine Name: ips_verify_bios_memio */
6670 /* Routine Description: */
6671 /* Verify the BIOS on the adapter */
6673 /****************************************************************************/
6675 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6681 METHOD_TRACE("ips_verify_bios_memio", 1);
6684 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6685 if (ha->revision_id == IPS_REVID_TROMBONE64)
6686 udelay(25); /* 25 us */
6688 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6691 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6692 if (ha->revision_id == IPS_REVID_TROMBONE64)
6693 udelay(25); /* 25 us */
6694 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6698 for (i = 2; i < buffersize; i++) {
6700 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6701 if (ha->revision_id == IPS_REVID_TROMBONE64)
6702 udelay(25); /* 25 us */
6705 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6716 /*---------------------------------------------------------------------------*/
6717 /* Routine Name: ips_version_check */
6720 /* Assumes that ips_read_adapter_status() is called first filling in */
6721 /* the data for SubSystem Parameters. */
6722 /* Called from ips_write_driver_status() so it also assumes NVRAM Page 5 */
6723 /* Data is available. */
6725 /*---------------------------------------------------------------------------*/
6727 ips_version_check(ips_ha_t * ha, int intr)
6729 IPS_VERSION_DATA *VersionInfo;
6730 uint8_t FirmwareVersion[IPS_COMPAT_ID_LENGTH + 1];
6731 uint8_t BiosVersion[IPS_COMPAT_ID_LENGTH + 1];
6734 char BiosString[10];
6735 char FirmwareString[10];
6737 METHOD_TRACE("ips_version_check", 1);
6739 VersionInfo = ( IPS_VERSION_DATA * ) ha->ioctl_data;
6741 memset(FirmwareVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6742 memset(BiosVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6744 /* Get the Compatible BIOS Version from NVRAM Page 5 */
6745 memcpy(BiosVersion, ha->nvram->BiosCompatibilityID,
6746 IPS_COMPAT_ID_LENGTH);
6749 if (ha->subsys->param[4] & IPS_GET_VERSION_SUPPORT) { /* If Versioning is Supported */
6750 /* Get the Version Info with a Get Version Command */
6751 memset( VersionInfo, 0, sizeof (IPS_VERSION_DATA));
6752 rc = ips_get_version_info(ha, ha->ioctl_busaddr, intr);
6753 if (rc == IPS_SUCCESS)
6754 memcpy(FirmwareVersion, VersionInfo->compatibilityId,
6755 IPS_COMPAT_ID_LENGTH);
6758 if (rc != IPS_SUCCESS) { /* If Data Not Obtainable from a GetVersion Command */
6759 /* Get the Firmware Version from Enquiry Data */
6760 memcpy(FirmwareVersion, ha->enq->CodeBlkVersion,
6761 IPS_COMPAT_ID_LENGTH);
6764 /* printk(KERN_WARNING "Adapter's BIOS Version = %s\n", BiosVersion); */
6765 /* printk(KERN_WARNING "BIOS Compatible Version = %s\n", IPS_COMPAT_BIOS); */
6766 /* printk(KERN_WARNING "Adapter's Firmware Version = %s\n", FirmwareVersion); */
6767 /* printk(KERN_WARNING "Firmware Compatible Version = %s \n", Compatable[ ha->nvram->adapter_type ]); */
6772 (FirmwareVersion, Compatable[ha->nvram->adapter_type],
6773 IPS_COMPAT_ID_LENGTH) != 0)
6776 if (strncmp(BiosVersion, IPS_COMPAT_BIOS, IPS_COMPAT_ID_LENGTH) != 0)
6779 ha->nvram->versioning = 1; /* Indicate the Driver Supports Versioning */
6782 ha->nvram->version_mismatch = 1;
6783 if (ips_cd_boot == 0) {
6784 strncpy(&BiosString[0], ha->nvram->bios_high, 4);
6785 strncpy(&BiosString[4], ha->nvram->bios_low, 4);
6788 strncpy(&FirmwareString[0], ha->enq->CodeBlkVersion, 8);
6789 FirmwareString[8] = 0;
6791 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6792 "Warning ! ! ! ServeRAID Version Mismatch\n");
6793 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6794 "Bios = %s, Firmware = %s, Device Driver = %s%s\n",
6795 BiosString, FirmwareString, IPS_VERSION_HIGH,
6797 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6798 "These levels should match to avoid possible compatibility problems.\n");
6801 ha->nvram->version_mismatch = 0;
6807 /*---------------------------------------------------------------------------*/
6808 /* Routine Name: ips_get_version_info */
6810 /* Routine Description: */
6811 /* Issue an internal GETVERSION Command */
6814 /* 0 if Successful, else non-zero */
6815 /*---------------------------------------------------------------------------*/
6817 ips_get_version_info(ips_ha_t * ha, dma_addr_t Buffer, int intr)
6822 METHOD_TRACE("ips_get_version_info", 1);
6824 scb = &ha->scbs[ha->max_cmds - 1];
6826 ips_init_scb(ha, scb);
6828 scb->timeout = ips_cmd_timeout;
6829 scb->cdb[0] = IPS_CMD_GET_VERSION_INFO;
6830 scb->cmd.version_info.op_code = IPS_CMD_GET_VERSION_INFO;
6831 scb->cmd.version_info.command_id = IPS_COMMAND_ID(ha, scb);
6832 scb->cmd.version_info.reserved = 0;
6833 scb->cmd.version_info.count = sizeof (IPS_VERSION_DATA);
6834 scb->cmd.version_info.reserved2 = 0;
6835 scb->data_len = sizeof (IPS_VERSION_DATA);
6836 scb->data_busaddr = Buffer;
6837 scb->cmd.version_info.buffer_addr = Buffer;
6841 rc = ips_send_wait(ha, scb, ips_cmd_timeout, intr);
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_SERVERAID7k:
6908 case IPS_ADTYPE_SERVERAID7M:
6909 if (nvram->adapter_order[i] == 'M') {
6910 ips_shift_controllers(position,
6915 case IPS_ADTYPE_SERVERAID4L:
6916 case IPS_ADTYPE_SERVERAID4M:
6917 case IPS_ADTYPE_SERVERAID4MX:
6918 case IPS_ADTYPE_SERVERAID4LX:
6919 if (nvram->adapter_order[i] == 'N') {
6920 ips_shift_controllers(position,
6925 case IPS_ADTYPE_SERVERAID6I:
6926 case IPS_ADTYPE_SERVERAID5I2:
6927 case IPS_ADTYPE_SERVERAID5I1:
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, SA_SHIRQ, 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_module_init(&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;
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, 0xffffffffffffffffULL)) {
7281 (ha)->flags |= IPS_HA_ENH_SG;
7283 if (pci_set_dma_mask(ha->pcidev, 0xffffffffULL) != 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, SA_SHIRQ, 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");
7457 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7458 * Emacs will notice this stuff at the end of the file and automatically
7459 * adjust the settings for this buffer only. This must remain at the end
7461 * ---------------------------------------------------------------------------
7464 * c-brace-imaginary-offset: 0
7465 * c-brace-offset: -2
7466 * c-argdecl-indent: 2
7467 * c-label-offset: -2
7468 * c-continued-statement-offset: 2
7469 * c-continued-brace-offset: 0
7470 * indent-tabs-mode: nil