1 /*****************************************************************************/
2 /* ips.c -- driver for the Adaptec / IBM ServeRAID controller */
4 /* Written By: Keith Mitchell, IBM Corporation */
5 /* Jack Hammer, Adaptec, Inc. */
6 /* David Jeffery, Adaptec, Inc. */
8 /* Copyright (C) 2000 IBM Corporation */
9 /* Copyright (C) 2002,2003 Adaptec, Inc. */
11 /* This program is free software; you can redistribute it and/or modify */
12 /* it under the terms of the GNU General Public License as published by */
13 /* the Free Software Foundation; either version 2 of the License, or */
14 /* (at your option) any later version. */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU General Public License for more details. */
22 /* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR */
23 /* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT */
24 /* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, */
25 /* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is */
26 /* solely responsible for determining the appropriateness of using and */
27 /* distributing the Program and assumes all risks associated with its */
28 /* exercise of rights under this Agreement, including but not limited to */
29 /* the risks and costs of program errors, damage to or loss of data, */
30 /* programs or equipment, and unavailability or interruption of operations. */
32 /* DISCLAIMER OF LIABILITY */
33 /* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY */
34 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */
35 /* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND */
36 /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR */
37 /* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE */
38 /* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED */
39 /* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES */
41 /* You should have received a copy of the GNU General Public License */
42 /* along with this program; if not, write to the Free Software */
43 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
45 /* Bugs/Comments/Suggestions about this driver should be mailed to: */
46 /* ipslinux@adaptec.com */
48 /* For system support issues, contact your local IBM Customer support. */
49 /* Directions to find IBM Customer Support for each country can be found at: */
50 /* http://www.ibm.com/planetwide/ */
52 /*****************************************************************************/
54 /*****************************************************************************/
57 /* 0.99.02 - Breakup commands that are bigger than 8 * the stripe size */
58 /* 0.99.03 - Make interrupt routine handle all completed request on the */
59 /* adapter not just the first one */
60 /* - Make sure passthru commands get woken up if we run out of */
62 /* - Send all of the commands on the queue at once rather than */
63 /* one at a time since the card will support it. */
64 /* 0.99.04 - Fix race condition in the passthru mechanism -- this required */
65 /* the interface to the utilities to change */
66 /* - Fix error recovery code */
67 /* 0.99.05 - Fix an oops when we get certain passthru commands */
68 /* 1.00.00 - Initial Public Release */
69 /* Functionally equivalent to 0.99.05 */
70 /* 3.60.00 - Bump max commands to 128 for use with firmware 3.60 */
71 /* - Change version to 3.60 to coincide with release numbering. */
72 /* 3.60.01 - Remove bogus error check in passthru routine */
73 /* 3.60.02 - Make DCDB direction based on lookup table */
74 /* - Only allow one DCDB command to a SCSI ID at a time */
75 /* 4.00.00 - Add support for ServeRAID 4 */
76 /* 4.00.01 - Add support for First Failure Data Capture */
77 /* 4.00.02 - Fix problem with PT DCDB with no buffer */
78 /* 4.00.03 - Add alternative passthru interface */
79 /* - Add ability to flash BIOS */
80 /* 4.00.04 - Rename structures/constants to be prefixed with IPS_ */
81 /* 4.00.05 - Remove wish_block from init routine */
82 /* - Use linux/spinlock.h instead of asm/spinlock.h for kernels */
83 /* 2.3.18 and later */
84 /* - Sync with other changes from the 2.3 kernels */
85 /* 4.00.06 - Fix timeout with initial FFDC command */
86 /* 4.00.06a - Port to 2.4 (trivial) -- Christoph Hellwig <hch@infradead.org> */
87 /* 4.10.00 - Add support for ServeRAID 4M/4L */
88 /* 4.10.13 - Fix for dynamic unload and proc file system */
89 /* 4.20.03 - Rename version to coincide with new release schedules */
90 /* Performance fixes */
91 /* Fix truncation of /proc files with cat */
92 /* Merge in changes through kernel 2.4.0test1ac21 */
93 /* 4.20.13 - Fix some failure cases / reset code */
94 /* - Hook into the reboot_notifier to flush the controller cache */
95 /* 4.50.01 - Fix problem when there is a hole in logical drive numbering */
96 /* 4.70.09 - Use a Common ( Large Buffer ) for Flashing from the JCRM CD */
97 /* - Add IPSSEND Flash Support */
98 /* - Set Sense Data for Unknown SCSI Command */
99 /* - Use Slot Number from NVRAM Page 5 */
100 /* - Restore caller's DCDB Structure */
101 /* 4.70.12 - Corrective actions for bad controller ( during initialization )*/
102 /* 4.70.13 - Don't Send CDB's if we already know the device is not present */
103 /* - Don't release HA Lock in ips_next() until SC taken off queue */
104 /* - Unregister SCSI device in ips_release() */
105 /* 4.70.15 - Fix Breakup for very large ( non-SG ) requests in ips_done() */
106 /* 4.71.00 - Change all memory allocations to not use GFP_DMA flag */
107 /* Code Clean-Up for 2.4.x kernel */
108 /* 4.72.00 - Allow for a Scatter-Gather Element to exceed MAX_XFER Size */
109 /* 4.72.01 - I/O Mapped Memory release ( so "insmod ips" does not Fail ) */
110 /* - Don't Issue Internal FFDC Command if there are Active Commands */
111 /* - Close Window for getting too many IOCTL's active */
112 /* 4.80.00 - Make ia64 Safe */
113 /* 4.80.04 - Eliminate calls to strtok() if 2.4.x or greater */
114 /* - Adjustments to Device Queue Depth */
115 /* 4.80.14 - Take all semaphores off stack */
116 /* - Clean Up New_IOCTL path */
117 /* 4.80.20 - Set max_sectors in Scsi_Host structure ( if >= 2.4.7 kernel ) */
118 /* - 5 second delay needed after resetting an i960 adapter */
119 /* 4.80.26 - Clean up potential code problems ( Arjan's recommendations ) */
120 /* 4.90.01 - Version Matching for FirmWare, BIOS, and Driver */
121 /* 4.90.05 - Use New PCI Architecture to facilitate Hot Plug Development */
122 /* 4.90.08 - Increase Delays in Flashing ( Trombone Only - 4H ) */
123 /* 4.90.08 - Data Corruption if First Scatter Gather Element is > 64K */
124 /* 4.90.11 - Don't actually RESET unless it's physically required */
125 /* - Remove unused compile options */
126 /* 5.00.01 - Sarasota ( 5i ) adapters must always be scanned first */
127 /* - Get rid on IOCTL_NEW_COMMAND code */
128 /* - Add Extended DCDB Commands for Tape Support in 5I */
129 /* 5.10.12 - use pci_dma interfaces, update for 2.5 kernel changes */
130 /* 5.10.15 - remove unused code (sem, macros, etc.) */
131 /* 5.30.00 - use __devexit_p() */
132 /* 6.00.00 - Add 6x Adapters and Battery Flash */
133 /* 6.10.00 - Remove 1G Addressing Limitations */
134 /* 6.11.xx - Get VersionInfo buffer off the stack ! DDTS 60401 */
135 /* 6.11.xx - Make Logical Drive Info structure safe for DMA DDTS 60639 */
136 /* 7.10.xx - Add highmem_io flag in SCSI Templete for 2.4 kernels */
137 /* - Fix path/name for scsi_hosts.h include for 2.6 kernels */
138 /* - Fix sort order of 7k */
139 /* - Remove 3 unused "inline" functions */
140 /*****************************************************************************/
143 * Conditional Compilation directives for this driver:
145 * IPS_DEBUG - Turn on debugging info
149 * debug:<number> - Set debug level to <number>
150 * NOTE: only works when IPS_DEBUG compile directive is used.
151 * 1 - Normal debug messages
152 * 2 - Verbose debug messages
153 * 11 - Method trace (non interrupt)
154 * 12 - Method trace (includes interrupt)
156 * noi2o - Don't use I2O Queues (ServeRAID 4 only)
157 * nommap - Don't use memory mapped I/O
158 * ioctlsize - Initial size of the IOCTL buffer
162 #include <asm/byteorder.h>
163 #include <asm/page.h>
164 #include <linux/stddef.h>
165 #include <linux/version.h>
166 #include <linux/string.h>
167 #include <linux/errno.h>
168 #include <linux/kernel.h>
169 #include <linux/ioport.h>
170 #include <linux/slab.h>
171 #include <linux/delay.h>
172 #include <linux/pci.h>
173 #include <linux/proc_fs.h>
174 #include <linux/reboot.h>
175 #include <linux/interrupt.h>
177 #include <linux/blkdev.h>
178 #include <linux/types.h>
184 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
187 #include <scsi/scsi_host.h>
192 #include <linux/module.h>
194 #include <linux/stat.h>
195 #include <linux/config.h>
197 #include <linux/spinlock.h>
198 #include <linux/init.h>
200 #include <linux/smp.h>
203 static char *ips = NULL;
204 module_param(ips, charp, 0);
210 #define IPS_VERSION_HIGH "7.10"
211 #define IPS_VERSION_LOW ".18 "
213 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
214 #warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
217 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
218 #include <linux/blk.h>
220 #define IPS_SG_ADDRESS(sg) ((sg)->address)
221 #define IPS_LOCK_SAVE(lock,flags) spin_lock_irqsave(&io_request_lock,flags)
222 #define IPS_UNLOCK_RESTORE(lock,flags) spin_unlock_irqrestore(&io_request_lock,flags)
224 #define __devexit_p(x) x
227 #define IPS_SG_ADDRESS(sg) (page_address((sg)->page) ? \
228 page_address((sg)->page)+(sg)->offset : NULL)
229 #define IPS_LOCK_SAVE(lock,flags) do{spin_lock(lock);(void)flags;}while(0)
230 #define IPS_UNLOCK_RESTORE(lock,flags) do{spin_unlock(lock);(void)flags;}while(0)
233 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
234 SCSI_DATA_NONE == scb->scsi_cmd->sc_data_direction) ? \
235 PCI_DMA_BIDIRECTIONAL : \
236 scsi_to_pci_dma_dir(scb->scsi_cmd->sc_data_direction))
239 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
240 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
241 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
243 #define METHOD_TRACE(s, i)
245 #define DEBUG_VAR(i, s, v...)
251 static const char ips_name[] = "ips";
252 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
253 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
254 static unsigned int ips_next_controller;
255 static unsigned int ips_num_controllers;
256 static unsigned int ips_released_controllers;
257 static int ips_hotplug;
258 static int ips_cmd_timeout = 60;
259 static int ips_reset_timeout = 60 * 5;
260 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
261 static int ips_force_i2o = 1; /* Always use I2O command delivery */
262 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
263 static int ips_cd_boot; /* Booting from Manager CD */
264 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
265 static dma_addr_t ips_flashbusaddr;
266 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
267 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
268 static Scsi_Host_Template ips_driver_template = {
269 .detect = ips_detect,
270 .release = ips_release,
272 .queuecommand = ips_queue,
273 .eh_abort_handler = ips_eh_abort,
274 .eh_host_reset_handler = ips_eh_reset,
276 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
277 .proc_info = ips_proc_info,
278 .slave_configure = ips_slave_configure,
280 .proc_info = ips_proc24_info,
281 .select_queue_depths = ips_select_queue_depth,
283 .bios_param = ips_biosparam,
285 .sg_tablesize = IPS_MAX_SG,
287 .use_clustering = ENABLE_CLUSTERING,
288 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
289 .use_new_eh_code = 1,
291 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
296 IPS_DEFINE_COMPAT_TABLE( Compatable ); /* Version Compatability Table */
299 /* This table describes all ServeRAID Adapters */
300 static struct pci_device_id ips_pci_table[] = {
301 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
302 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
303 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
307 MODULE_DEVICE_TABLE( pci, ips_pci_table );
309 static char ips_hot_plug_name[] = "ips";
311 static int __devinit ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
312 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
314 struct pci_driver ips_pci_driver = {
315 .name = ips_hot_plug_name,
316 .id_table = ips_pci_table,
317 .probe = ips_insert_device,
318 .remove = __devexit_p(ips_remove_device),
323 * Necessary forward function protoypes
325 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
327 #define MAX_ADAPTER_NAME 15
329 static char ips_adapter_name[][30] = {
332 "ServeRAID on motherboard",
333 "ServeRAID on motherboard",
350 static struct notifier_block ips_notifier = {
357 static char ips_command_direction[] = {
358 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
359 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
360 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
361 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
362 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
363 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
364 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
365 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
366 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
367 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
368 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
369 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
370 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
371 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
372 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
373 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, 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_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
376 IPS_DATA_IN, 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_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
379 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
380 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
381 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
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_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
392 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
393 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
394 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
395 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
396 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
397 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
398 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
399 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
400 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
401 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
402 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
403 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
404 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
405 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
406 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
407 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
408 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
412 * Function prototypes
414 int ips_detect(Scsi_Host_Template *);
415 int ips_release(struct Scsi_Host *);
416 int ips_eh_abort(Scsi_Cmnd *);
417 int ips_eh_reset(Scsi_Cmnd *);
418 int ips_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
419 const char *ips_info(struct Scsi_Host *);
420 irqreturn_t do_ipsintr(int, void *, struct pt_regs *);
421 static int ips_hainit(ips_ha_t *);
422 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
423 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
424 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
425 static int ips_online(ips_ha_t *, ips_scb_t *);
426 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
427 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
428 static int ips_msense(ips_ha_t *, ips_scb_t *);
429 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
430 static int ips_deallocatescbs(ips_ha_t *, int);
431 static int ips_allocatescbs(ips_ha_t *);
432 static int ips_reset_copperhead(ips_ha_t *);
433 static int ips_reset_copperhead_memio(ips_ha_t *);
434 static int ips_reset_morpheus(ips_ha_t *);
435 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
436 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
437 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
438 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
439 static int ips_isintr_copperhead(ips_ha_t *);
440 static int ips_isintr_copperhead_memio(ips_ha_t *);
441 static int ips_isintr_morpheus(ips_ha_t *);
442 static int ips_wait(ips_ha_t *, int, int);
443 static int ips_write_driver_status(ips_ha_t *, int);
444 static int ips_read_adapter_status(ips_ha_t *, int);
445 static int ips_read_subsystem_parameters(ips_ha_t *, int);
446 static int ips_read_config(ips_ha_t *, int);
447 static int ips_clear_adapter(ips_ha_t *, int);
448 static int ips_readwrite_page5(ips_ha_t *, int, int);
449 static int ips_init_copperhead(ips_ha_t *);
450 static int ips_init_copperhead_memio(ips_ha_t *);
451 static int ips_init_morpheus(ips_ha_t *);
452 static int ips_isinit_copperhead(ips_ha_t *);
453 static int ips_isinit_copperhead_memio(ips_ha_t *);
454 static int ips_isinit_morpheus(ips_ha_t *);
455 static int ips_erase_bios(ips_ha_t *);
456 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
457 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
458 static int ips_erase_bios_memio(ips_ha_t *);
459 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
460 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
461 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
462 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
463 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
464 static void ips_free_flash_copperhead(ips_ha_t * ha);
465 static void ips_get_bios_version(ips_ha_t *, int);
466 static void ips_identify_controller(ips_ha_t *);
467 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
468 static void ips_enable_int_copperhead(ips_ha_t *);
469 static void ips_enable_int_copperhead_memio(ips_ha_t *);
470 static void ips_enable_int_morpheus(ips_ha_t *);
471 static int ips_intr_copperhead(ips_ha_t *);
472 static int ips_intr_morpheus(ips_ha_t *);
473 static void ips_next(ips_ha_t *, int);
474 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
475 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
476 static void ips_done(ips_ha_t *, ips_scb_t *);
477 static void ips_free(ips_ha_t *);
478 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
479 static void ips_freescb(ips_ha_t *, ips_scb_t *);
480 static void ips_setup_funclist(ips_ha_t *);
481 static void ips_statinit(ips_ha_t *);
482 static void ips_statinit_memio(ips_ha_t *);
483 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
484 static void ips_ffdc_reset(ips_ha_t *, int);
485 static void ips_ffdc_time(ips_ha_t *);
486 static uint32_t ips_statupd_copperhead(ips_ha_t *);
487 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
488 static uint32_t ips_statupd_morpheus(ips_ha_t *);
489 static ips_scb_t *ips_getscb(ips_ha_t *);
490 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
491 static void ips_putq_wait_tail(ips_wait_queue_t *, Scsi_Cmnd *);
492 static void ips_putq_copp_tail(ips_copp_queue_t *,
493 ips_copp_wait_item_t *);
494 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
495 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
496 static Scsi_Cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
497 static Scsi_Cmnd *ips_removeq_wait(ips_wait_queue_t *, Scsi_Cmnd *);
498 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
499 ips_copp_wait_item_t *);
500 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
502 static int ips_is_passthru(Scsi_Cmnd *);
503 static int ips_make_passthru(ips_ha_t *, Scsi_Cmnd *, ips_scb_t *, int);
504 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
505 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
506 static void ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data,
508 static void ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned int count);
510 int ips_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
511 static int ips_host_info(ips_ha_t *, char *, off_t, int);
512 static void copy_mem_info(IPS_INFOSTR *, char *, int);
513 static int copy_info(IPS_INFOSTR *, char *, ...);
514 static int ips_get_version_info(ips_ha_t * ha, dma_addr_t, int intr);
515 static void ips_version_check(ips_ha_t * ha, int intr);
516 static int ips_abort_init(ips_ha_t * ha, int index);
517 static int ips_init_phase2(int index);
519 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
520 static int ips_register_scsi(int index);
521 /*--------------------------------------------------------------------------*/
522 /* Exported Functions */
523 /*--------------------------------------------------------------------------*/
525 /****************************************************************************/
527 /* Routine Name: ips_setup */
529 /* Routine Description: */
531 /* setup parameters to the driver */
533 /****************************************************************************/
535 ips_setup(char *ips_str)
541 IPS_OPTION options[] = {
542 {"noi2o", &ips_force_i2o, 0},
543 {"nommap", &ips_force_memio, 0},
544 {"ioctlsize", &ips_ioctlsize, IPS_IOCTL_SIZE},
545 {"cdboot", &ips_cd_boot, 0},
546 {"maxcmds", &MaxLiteCmds, 32},
549 /* Don't use strtok() anymore ( if 2.4 Kernel or beyond ) */
550 /* Search for value */
551 while ((key = strsep(&ips_str, ",."))) {
554 value = strchr(key, ':');
558 * We now have key/value pairs.
559 * Update the variables
561 for (i = 0; i < (sizeof (options) / sizeof (options[0])); i++) {
563 (key, options[i].option_name,
564 strlen(options[i].option_name)) == 0) {
566 *options[i].option_flag =
567 simple_strtoul(value, NULL, 0);
569 *options[i].option_flag =
570 options[i].option_value;
579 __setup("ips=", ips_setup);
581 /****************************************************************************/
583 /* Routine Name: ips_detect */
585 /* Routine Description: */
587 /* Detect and initialize the driver */
589 /* NOTE: this routine is called under the io_request_lock spinlock */
591 /****************************************************************************/
593 ips_detect(Scsi_Host_Template * SHT)
597 METHOD_TRACE("ips_detect", 1);
604 for (i = 0; i < ips_num_controllers; i++) {
605 if (ips_register_scsi(i))
607 ips_released_controllers++;
610 return (ips_num_controllers);
613 /****************************************************************************/
614 /* configure the function pointers to use the functions that will work */
615 /* with the found version of the adapter */
616 /****************************************************************************/
618 ips_setup_funclist(ips_ha_t * ha)
624 if (IPS_IS_MORPHEUS(ha) || IPS_IS_MARCO(ha)) {
625 /* morpheus / marco / sebring */
626 ha->func.isintr = ips_isintr_morpheus;
627 ha->func.isinit = ips_isinit_morpheus;
628 ha->func.issue = ips_issue_i2o_memio;
629 ha->func.init = ips_init_morpheus;
630 ha->func.statupd = ips_statupd_morpheus;
631 ha->func.reset = ips_reset_morpheus;
632 ha->func.intr = ips_intr_morpheus;
633 ha->func.enableint = ips_enable_int_morpheus;
634 } else if (IPS_USE_MEMIO(ha)) {
635 /* copperhead w/MEMIO */
636 ha->func.isintr = ips_isintr_copperhead_memio;
637 ha->func.isinit = ips_isinit_copperhead_memio;
638 ha->func.init = ips_init_copperhead_memio;
639 ha->func.statupd = ips_statupd_copperhead_memio;
640 ha->func.statinit = ips_statinit_memio;
641 ha->func.reset = ips_reset_copperhead_memio;
642 ha->func.intr = ips_intr_copperhead;
643 ha->func.erasebios = ips_erase_bios_memio;
644 ha->func.programbios = ips_program_bios_memio;
645 ha->func.verifybios = ips_verify_bios_memio;
646 ha->func.enableint = ips_enable_int_copperhead_memio;
647 if (IPS_USE_I2O_DELIVER(ha))
648 ha->func.issue = ips_issue_i2o_memio;
650 ha->func.issue = ips_issue_copperhead_memio;
653 ha->func.isintr = ips_isintr_copperhead;
654 ha->func.isinit = ips_isinit_copperhead;
655 ha->func.init = ips_init_copperhead;
656 ha->func.statupd = ips_statupd_copperhead;
657 ha->func.statinit = ips_statinit;
658 ha->func.reset = ips_reset_copperhead;
659 ha->func.intr = ips_intr_copperhead;
660 ha->func.erasebios = ips_erase_bios;
661 ha->func.programbios = ips_program_bios;
662 ha->func.verifybios = ips_verify_bios;
663 ha->func.enableint = ips_enable_int_copperhead;
665 if (IPS_USE_I2O_DELIVER(ha))
666 ha->func.issue = ips_issue_i2o;
668 ha->func.issue = ips_issue_copperhead;
672 /****************************************************************************/
674 /* Routine Name: ips_release */
676 /* Routine Description: */
678 /* Remove a driver */
680 /****************************************************************************/
682 ips_release(struct Scsi_Host *sh)
688 METHOD_TRACE("ips_release", 1);
690 for (i = 0; i < IPS_MAX_ADAPTERS && ips_sh[i] != sh; i++) ;
692 if (i == IPS_MAX_ADAPTERS) {
694 "(%s) release, invalid Scsi_Host pointer.\n", ips_name);
704 /* flush the cache on the controller */
705 scb = &ha->scbs[ha->max_cmds - 1];
707 ips_init_scb(ha, scb);
709 scb->timeout = ips_cmd_timeout;
710 scb->cdb[0] = IPS_CMD_FLUSH;
712 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
713 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
714 scb->cmd.flush_cache.state = IPS_NORM_STATE;
715 scb->cmd.flush_cache.reserved = 0;
716 scb->cmd.flush_cache.reserved2 = 0;
717 scb->cmd.flush_cache.reserved3 = 0;
718 scb->cmd.flush_cache.reserved4 = 0;
720 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
723 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) == IPS_FAILURE)
724 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Incomplete Flush.\n");
726 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Complete.\n");
731 /* free extra memory */
734 /* Free I/O Region */
736 release_region(ha->io_addr, ha->io_len);
739 free_irq(ha->irq, ha);
744 ips_released_controllers++;
749 /****************************************************************************/
751 /* Routine Name: ips_halt */
753 /* Routine Description: */
755 /* Perform cleanup when the system reboots */
757 /****************************************************************************/
759 ips_halt(struct notifier_block *nb, ulong event, void *buf)
765 if ((event != SYS_RESTART) && (event != SYS_HALT) &&
766 (event != SYS_POWER_OFF))
767 return (NOTIFY_DONE);
769 for (i = 0; i < ips_next_controller; i++) {
770 ha = (ips_ha_t *) ips_ha[i];
778 /* flush the cache on the controller */
779 scb = &ha->scbs[ha->max_cmds - 1];
781 ips_init_scb(ha, scb);
783 scb->timeout = ips_cmd_timeout;
784 scb->cdb[0] = IPS_CMD_FLUSH;
786 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
787 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
788 scb->cmd.flush_cache.state = IPS_NORM_STATE;
789 scb->cmd.flush_cache.reserved = 0;
790 scb->cmd.flush_cache.reserved2 = 0;
791 scb->cmd.flush_cache.reserved3 = 0;
792 scb->cmd.flush_cache.reserved4 = 0;
794 IPS_PRINTK(KERN_WARNING, ha->pcidev, "Flushing Cache.\n");
797 if (ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_ON) ==
799 IPS_PRINTK(KERN_WARNING, ha->pcidev,
800 "Incomplete Flush.\n");
802 IPS_PRINTK(KERN_WARNING, ha->pcidev,
803 "Flushing Complete.\n");
809 /****************************************************************************/
811 /* Routine Name: ips_eh_abort */
813 /* Routine Description: */
815 /* Abort a command (using the new error code stuff) */
816 /* Note: this routine is called under the io_request_lock */
817 /****************************************************************************/
819 ips_eh_abort(Scsi_Cmnd * SC)
822 ips_copp_wait_item_t *item;
825 METHOD_TRACE("ips_eh_abort", 1);
830 ha = (ips_ha_t *) SC->device->host->hostdata;
838 if (SC->serial_number != SC->serial_number_at_timeout) {
839 /* HMM, looks like a bogus command */
840 DEBUG(1, "Abort called with bogus scsi command");
845 /* See if the command is on the copp queue */
846 item = ha->copp_waitlist.head;
847 while ((item) && (item->scsi_cmd != SC))
852 ips_removeq_copp(&ha->copp_waitlist, item);
855 /* See if the command is on the wait queue */
856 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
857 /* command not sent yet */
860 /* command must have already been sent */
866 /****************************************************************************/
868 /* Routine Name: ips_eh_reset */
870 /* Routine Description: */
872 /* Reset the controller (with new eh error code) */
874 /* NOTE: this routine is called under the io_request_lock spinlock */
876 /****************************************************************************/
878 ips_eh_reset(Scsi_Cmnd * SC)
884 ips_copp_wait_item_t *item;
886 METHOD_TRACE("ips_eh_reset", 1);
893 DEBUG(1, "Reset called with NULL scsi command");
898 ha = (ips_ha_t *) SC->device->host->hostdata;
901 DEBUG(1, "Reset called with NULL ha struct");
909 /* See if the command is on the copp queue */
910 item = ha->copp_waitlist.head;
911 while ((item) && (item->scsi_cmd != SC))
916 ips_removeq_copp(&ha->copp_waitlist, item);
920 /* See if the command is on the wait queue */
921 if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
922 /* command not sent yet */
926 /* An explanation for the casual observer: */
927 /* Part of the function of a RAID controller is automatic error */
928 /* detection and recovery. As such, the only problem that physically */
929 /* resetting an adapter will ever fix is when, for some reason, */
930 /* the driver is not successfully communicating with the adapter. */
931 /* Therefore, we will attempt to flush this adapter. If that succeeds, */
932 /* then there's no real purpose in a physical reset. This will complete */
933 /* much faster and avoids any problems that might be caused by a */
934 /* physical reset ( such as having to fail all the outstanding I/O's ). */
936 if (ha->ioctl_reset == 0) { /* IF Not an IOCTL Requested Reset */
937 scb = &ha->scbs[ha->max_cmds - 1];
939 ips_init_scb(ha, scb);
941 scb->timeout = ips_cmd_timeout;
942 scb->cdb[0] = IPS_CMD_FLUSH;
944 scb->cmd.flush_cache.op_code = IPS_CMD_FLUSH;
945 scb->cmd.flush_cache.command_id = IPS_COMMAND_ID(ha, scb);
946 scb->cmd.flush_cache.state = IPS_NORM_STATE;
947 scb->cmd.flush_cache.reserved = 0;
948 scb->cmd.flush_cache.reserved2 = 0;
949 scb->cmd.flush_cache.reserved3 = 0;
950 scb->cmd.flush_cache.reserved4 = 0;
952 /* Attempt the flush command */
953 ret = ips_send_wait(ha, scb, ips_cmd_timeout, IPS_INTR_IORL);
954 if (ret == IPS_SUCCESS) {
955 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
956 "Reset Request - Flushed Cache\n");
961 /* Either we can't communicate with the adapter or it's an IOCTL request */
962 /* from a utility. A physical reset is needed at this point. */
964 ha->ioctl_reset = 0; /* Reset the IOCTL Requested Reset Flag */
967 * command must have already been sent
968 * reset the controller
970 IPS_PRINTK(KERN_NOTICE, ha->pcidev, "Resetting controller.\n");
971 ret = (*ha->func.reset) (ha);
976 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
977 "Controller reset failed - controller now offline.\n");
979 /* Now fail all of the active commands */
980 DEBUG_VAR(1, "(%s%d) Failing active commands",
981 ips_name, ha->host_num);
983 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
984 scb->scsi_cmd->result = DID_ERROR << 16;
985 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
986 ips_freescb(ha, scb);
989 /* Now fail all of the pending commands */
990 DEBUG_VAR(1, "(%s%d) Failing pending commands",
991 ips_name, ha->host_num);
993 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
994 scsi_cmd->result = DID_ERROR;
995 scsi_cmd->scsi_done(scsi_cmd);
1002 if (!ips_clear_adapter(ha, IPS_INTR_IORL)) {
1003 Scsi_Cmnd *scsi_cmd;
1005 IPS_PRINTK(KERN_NOTICE, ha->pcidev,
1006 "Controller reset failed - controller now offline.\n");
1008 /* Now fail all of the active commands */
1009 DEBUG_VAR(1, "(%s%d) Failing active commands",
1010 ips_name, ha->host_num);
1012 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1013 scb->scsi_cmd->result = DID_ERROR << 16;
1014 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1015 ips_freescb(ha, scb);
1018 /* Now fail all of the pending commands */
1019 DEBUG_VAR(1, "(%s%d) Failing pending commands",
1020 ips_name, ha->host_num);
1022 while ((scsi_cmd = ips_removeq_wait_head(&ha->scb_waitlist))) {
1023 scsi_cmd->result = DID_ERROR << 16;
1024 scsi_cmd->scsi_done(scsi_cmd);
1032 if (le32_to_cpu(ha->subsys->param[3]) & 0x300000) {
1035 do_gettimeofday(&tv);
1036 ha->last_ffdc = tv.tv_sec;
1038 ips_ffdc_reset(ha, IPS_INTR_IORL);
1041 /* Now fail all of the active commands */
1042 DEBUG_VAR(1, "(%s%d) Failing active commands", ips_name, ha->host_num);
1044 while ((scb = ips_removeq_scb_head(&ha->scb_activelist))) {
1045 scb->scsi_cmd->result =
1046 (DID_RESET << 16) | (SUGGEST_RETRY << 24);
1047 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
1048 ips_freescb(ha, scb);
1051 /* Reset DCDB active command bits */
1052 for (i = 1; i < ha->nbus; i++)
1053 ha->dcdb_active[i - 1] = 0;
1055 /* Reset the number of active IOCTLs */
1058 ips_next(ha, IPS_INTR_IORL);
1061 #endif /* NO_IPS_RESET */
1065 /****************************************************************************/
1067 /* Routine Name: ips_queue */
1069 /* Routine Description: */
1071 /* Send a command to the controller */
1074 /* Linux obtains io_request_lock before calling this function */
1076 /****************************************************************************/
1078 ips_queue(Scsi_Cmnd * SC, void (*done) (Scsi_Cmnd *))
1083 METHOD_TRACE("ips_queue", 1);
1085 ha = (ips_ha_t *) SC->device->host->hostdata;
1093 if (ips_is_passthru(SC)) {
1094 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1095 SC->result = DID_BUS_BUSY << 16;
1100 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1101 SC->result = DID_BUS_BUSY << 16;
1107 SC->scsi_done = done;
1109 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1113 SC->device->channel, SC->device->id, SC->device->lun);
1115 /* Check for command to initiator IDs */
1116 if ((SC->device->channel > 0)
1117 && (SC->device->id == ha->ha_id[SC->device->channel])) {
1118 SC->result = DID_NO_CONNECT << 16;
1124 if (ips_is_passthru(SC)) {
1126 ips_copp_wait_item_t *scratch;
1128 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1129 /* There can never be any system activity ( network or disk ), but check */
1130 /* anyway just as a good practice. */
1131 pt = (ips_passthru_t *) SC->request_buffer;
1132 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1133 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1134 if (ha->scb_activelist.count != 0) {
1135 SC->result = DID_BUS_BUSY << 16;
1139 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1141 SC->result = DID_OK << 16;
1146 /* allocate space for the scribble */
1147 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1150 SC->result = DID_ERROR << 16;
1156 scratch->scsi_cmd = SC;
1157 scratch->next = NULL;
1159 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1161 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1164 ips_next(ha, IPS_INTR_IORL);
1169 /****************************************************************************/
1171 /* Routine Name: ips_biosparam */
1173 /* Routine Description: */
1175 /* Set bios geometry for the controller */
1177 /****************************************************************************/
1179 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1180 ips_biosparam(Disk * disk, kdev_t dev, int geom[])
1182 ips_ha_t *ha = (ips_ha_t *) disk->device->host->hostdata;
1183 unsigned long capacity = disk->capacity;
1185 ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1186 sector_t capacity, int geom[])
1188 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1194 METHOD_TRACE("ips_biosparam", 1);
1197 /* ?!?! host adater info invalid */
1203 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1204 /* ?!?! Enquiry command failed */
1207 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1208 heads = IPS_NORM_HEADS;
1209 sectors = IPS_NORM_SECTORS;
1211 heads = IPS_COMP_HEADS;
1212 sectors = IPS_COMP_SECTORS;
1215 cylinders = (unsigned long) capacity / (heads * sectors);
1217 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1218 heads, sectors, cylinders);
1222 geom[2] = cylinders;
1227 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1229 /* ips_proc24_info is a wrapper around ips_proc_info *
1230 * for compatibility with the 2.4 scsi parameters */
1232 ips_proc24_info(char *buffer, char **start, off_t offset, int length,
1233 int hostno, int func)
1237 for (i = 0; i < ips_next_controller; i++) {
1238 if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
1239 return ips_proc_info(ips_sh[i], buffer, start,
1240 offset, length, func);
1246 /****************************************************************************/
1248 /* Routine Name: ips_select_queue_depth */
1250 /* Routine Description: */
1252 /* Select queue depths for the devices on the contoller */
1254 /****************************************************************************/
1256 ips_select_queue_depth(struct Scsi_Host *host, Scsi_Device * scsi_devs)
1258 Scsi_Device *device;
1264 min = ha->max_cmds / 4;
1266 for (device = scsi_devs; device; device = device->next) {
1267 if (device->host == host) {
1268 if ((device->channel == 0) && (device->type == 0))
1273 for (device = scsi_devs; device; device = device->next) {
1274 if (device->host == host) {
1275 if ((device->channel == 0) && (device->type == 0)) {
1276 device->queue_depth =
1277 (ha->max_cmds - 1) / count;
1278 if (device->queue_depth < min)
1279 device->queue_depth = min;
1281 device->queue_depth = 2;
1284 if (device->queue_depth < 2)
1285 device->queue_depth = 2;
1291 /****************************************************************************/
1293 /* Routine Name: ips_slave_configure */
1295 /* Routine Description: */
1297 /* Set queue depths on devices once scan is complete */
1299 /****************************************************************************/
1301 ips_slave_configure(Scsi_Device * SDptr)
1306 ha = IPS_HA(SDptr->host);
1307 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1308 min = ha->max_cmds / 2;
1309 if (ha->enq->ucLogDriveCount <= 2)
1310 min = ha->max_cmds - 1;
1311 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min);
1317 /****************************************************************************/
1319 /* Routine Name: do_ipsintr */
1321 /* Routine Description: */
1323 /* Wrapper for the interrupt handler */
1325 /****************************************************************************/
1327 do_ipsintr(int irq, void *dev_id, struct pt_regs * regs)
1330 unsigned long cpu_flags;
1331 struct Scsi_Host *host;
1334 METHOD_TRACE("do_ipsintr", 2);
1336 ha = (ips_ha_t *) dev_id;
1339 host = ips_sh[ha->host_num];
1340 /* interrupt during initialization */
1342 (*ha->func.intr) (ha);
1346 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
1349 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1353 irqstatus = (*ha->func.intr) (ha);
1355 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1357 /* start the next command */
1358 ips_next(ha, IPS_INTR_ON);
1359 return IRQ_RETVAL(irqstatus);
1362 /****************************************************************************/
1364 /* Routine Name: ips_intr_copperhead */
1366 /* Routine Description: */
1368 /* Polling interrupt handler */
1370 /* ASSUMES interrupts are disabled */
1372 /****************************************************************************/
1374 ips_intr_copperhead(ips_ha_t * ha)
1381 METHOD_TRACE("ips_intr", 2);
1389 intrstatus = (*ha->func.isintr) (ha);
1393 * Unexpected/Shared interrupt
1402 intrstatus = (*ha->func.isintr) (ha);
1407 cstatus.value = (*ha->func.statupd) (ha);
1409 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1410 /* Spurious Interupt ? */
1414 ips_chkstatus(ha, &cstatus);
1415 scb = (ips_scb_t *) sp->scb_addr;
1418 * use the callback function to finish things up
1419 * NOTE: interrupts are OFF for this
1421 (*scb->callback) (ha, scb);
1426 /****************************************************************************/
1428 /* Routine Name: ips_intr_morpheus */
1430 /* Routine Description: */
1432 /* Polling interrupt handler */
1434 /* ASSUMES interrupts are disabled */
1436 /****************************************************************************/
1438 ips_intr_morpheus(ips_ha_t * ha)
1445 METHOD_TRACE("ips_intr_morpheus", 2);
1453 intrstatus = (*ha->func.isintr) (ha);
1457 * Unexpected/Shared interrupt
1466 intrstatus = (*ha->func.isintr) (ha);
1471 cstatus.value = (*ha->func.statupd) (ha);
1473 if (cstatus.value == 0xffffffff)
1474 /* No more to process */
1477 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1478 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1479 "Spurious interrupt; no ccb.\n");
1484 ips_chkstatus(ha, &cstatus);
1485 scb = (ips_scb_t *) sp->scb_addr;
1488 * use the callback function to finish things up
1489 * NOTE: interrupts are OFF for this
1491 (*scb->callback) (ha, scb);
1496 /****************************************************************************/
1498 /* Routine Name: ips_info */
1500 /* Routine Description: */
1502 /* Return info about the driver */
1504 /****************************************************************************/
1506 ips_info(struct Scsi_Host *SH)
1508 static char buffer[256];
1512 METHOD_TRACE("ips_info", 1);
1520 memset(bp, 0, sizeof (buffer));
1522 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1523 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1525 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1527 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1534 /****************************************************************************/
1536 /* Routine Name: ips_proc_info */
1538 /* Routine Description: */
1540 /* The passthru interface for the driver */
1542 /****************************************************************************/
1544 ips_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1545 int length, int func)
1549 ips_ha_t *ha = NULL;
1551 METHOD_TRACE("ips_proc_info", 1);
1553 /* Find our host structure */
1554 for (i = 0; i < ips_next_controller; i++) {
1556 if (ips_sh[i] == host) {
1557 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1574 ret = ips_host_info(ha, buffer, offset, length);
1580 /*--------------------------------------------------------------------------*/
1581 /* Helper Functions */
1582 /*--------------------------------------------------------------------------*/
1584 /****************************************************************************/
1586 /* Routine Name: ips_is_passthru */
1588 /* Routine Description: */
1590 /* Determine if the specified SCSI command is really a passthru command */
1592 /****************************************************************************/
1594 ips_is_passthru(Scsi_Cmnd * SC)
1596 METHOD_TRACE("ips_is_passthru", 1);
1601 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1602 (SC->device->channel == 0) &&
1603 (SC->device->id == IPS_ADAPTER_ID) &&
1604 (SC->device->lun == 0) && SC->request_buffer) {
1605 if ((!SC->use_sg) && SC->request_bufflen &&
1606 (((char *) SC->request_buffer)[0] == 'C') &&
1607 (((char *) SC->request_buffer)[1] == 'O') &&
1608 (((char *) SC->request_buffer)[2] == 'P') &&
1609 (((char *) SC->request_buffer)[3] == 'P'))
1611 else if (SC->use_sg) {
1612 struct scatterlist *sg = SC->request_buffer;
1613 char *buffer = IPS_SG_ADDRESS(sg);
1614 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1615 buffer[2] == 'P' && buffer[3] == 'P')
1622 /****************************************************************************/
1624 /* Routine Name: ips_alloc_passthru_buffer */
1626 /* Routine Description: */
1627 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1628 /* is too small or doesn't exist */
1629 /****************************************************************************/
1631 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1634 dma_addr_t dma_busaddr;
1636 if (ha->ioctl_data && length <= ha->ioctl_len)
1638 /* there is no buffer or it's not big enough, allocate a new one */
1639 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1641 /* free the old memory */
1642 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1644 /* use the new memory */
1645 ha->ioctl_data = (char *) bigger_buf;
1646 ha->ioctl_len = length;
1647 ha->ioctl_busaddr = dma_busaddr;
1654 /****************************************************************************/
1656 /* Routine Name: ips_make_passthru */
1658 /* Routine Description: */
1660 /* Make a passthru command out of the info in the Scsi block */
1662 /****************************************************************************/
1664 ips_make_passthru(ips_ha_t * ha, Scsi_Cmnd * SC, ips_scb_t * scb, int intr)
1670 METHOD_TRACE("ips_make_passthru", 1);
1673 length = SC->request_bufflen;
1675 struct scatterlist *sg = SC->request_buffer;
1677 for (i = 0; i < SC->use_sg; i++)
1678 length += sg[i].length;
1680 if (length < sizeof (ips_passthru_t)) {
1682 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1683 ips_name, ha->host_num);
1684 return (IPS_FAILURE);
1686 if (ips_alloc_passthru_buffer(ha, length)) {
1687 /* allocation failure! If ha->ioctl_data exists, use it to return
1688 some error codes. Return a failed command to the scsi layer. */
1689 if (ha->ioctl_data) {
1690 pt = (ips_passthru_t *) ha->ioctl_data;
1691 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1692 pt->BasicStatus = 0x0B;
1693 pt->ExtendedStatus = 0x00;
1694 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1698 ha->ioctl_datasize = length;
1700 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1701 pt = (ips_passthru_t *) ha->ioctl_data;
1704 * Some notes about the passthru interface used
1706 * IF the scsi op_code == 0x0d then we assume
1707 * that the data came along with/goes with the
1708 * packet we received from the sg driver. In this
1709 * case the CmdBSize field of the pt structure is
1710 * used for the size of the buffer.
1713 switch (pt->CoppCmd) {
1715 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1716 &ips_num_controllers, sizeof (int));
1717 ips_scmd_buf_write(SC, ha->ioctl_data,
1718 sizeof (ips_passthru_t) + sizeof (int));
1719 SC->result = DID_OK << 16;
1721 return (IPS_SUCCESS_IMM);
1723 case IPS_COPPUSRCMD:
1724 case IPS_COPPIOCCMD:
1725 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1726 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1729 "(%s%d) Passthru structure wrong size",
1730 ips_name, ha->host_num);
1732 return (IPS_FAILURE);
1735 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
1736 pt->CoppCP.cmd.flashfw.op_code ==
1737 IPS_CMD_RW_BIOSFW) {
1738 ret = ips_flash_copperhead(ha, pt, scb);
1739 ips_scmd_buf_write(SC, ha->ioctl_data,
1740 sizeof (ips_passthru_t));
1743 if (ips_usrcmd(ha, pt, scb))
1744 return (IPS_SUCCESS);
1746 return (IPS_FAILURE);
1753 return (IPS_FAILURE);
1756 /****************************************************************************/
1757 /* Routine Name: ips_flash_copperhead */
1758 /* Routine Description: */
1759 /* Flash the BIOS/FW on a Copperhead style controller */
1760 /****************************************************************************/
1762 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1766 /* Trombone is the only copperhead that can do packet flash, but only
1767 * for firmware. No one said it had to make sence. */
1768 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1769 if (ips_usrcmd(ha, pt, scb))
1774 pt->BasicStatus = 0x0B;
1775 pt->ExtendedStatus = 0;
1776 scb->scsi_cmd->result = DID_OK << 16;
1777 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1778 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1779 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1780 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1781 pt->BasicStatus = 0;
1782 return ips_flash_bios(ha, pt, scb);
1783 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1784 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1785 ha->flash_data = ips_FlashData;
1786 ha->flash_busaddr = ips_flashbusaddr;
1787 ha->flash_len = PAGE_SIZE << 7;
1788 ha->flash_datasize = 0;
1789 } else if (!ha->flash_data) {
1790 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1791 pt->CoppCP.cmd.flashfw.count;
1792 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1794 &ha->flash_busaddr);
1795 if (!ha->flash_data){
1796 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1799 ha->flash_datasize = 0;
1800 ha->flash_len = datasize;
1804 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1806 ips_free_flash_copperhead(ha);
1807 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1808 "failed size sanity check\n");
1812 if (!ha->flash_data)
1814 pt->BasicStatus = 0;
1815 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1816 pt->CoppCP.cmd.flashfw.count);
1817 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1818 if (pt->CoppCP.cmd.flashfw.packet_num ==
1819 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1820 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1821 return ips_flash_bios(ha, pt, scb);
1822 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1823 return ips_flash_firmware(ha, pt, scb);
1825 return IPS_SUCCESS_IMM;
1828 /****************************************************************************/
1829 /* Routine Name: ips_flash_bios */
1830 /* Routine Description: */
1831 /* flashes the bios of a copperhead adapter */
1832 /****************************************************************************/
1834 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1837 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1838 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1839 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1840 (!ha->func.verifybios))
1842 if ((*ha->func.erasebios) (ha)) {
1844 "(%s%d) flash bios failed - unable to erase flash",
1845 ips_name, ha->host_num);
1848 if ((*ha->func.programbios) (ha,
1851 ha->flash_datasize -
1852 IPS_BIOS_HEADER, 0)) {
1854 "(%s%d) flash bios failed - unable to flash",
1855 ips_name, ha->host_num);
1858 if ((*ha->func.verifybios) (ha,
1861 ha->flash_datasize -
1862 IPS_BIOS_HEADER, 0)) {
1864 "(%s%d) flash bios failed - unable to verify flash",
1865 ips_name, ha->host_num);
1868 ips_free_flash_copperhead(ha);
1869 return IPS_SUCCESS_IMM;
1870 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1871 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1872 if (!ha->func.erasebios)
1874 if ((*ha->func.erasebios) (ha)) {
1876 "(%s%d) flash bios failed - unable to erase flash",
1877 ips_name, ha->host_num);
1880 return IPS_SUCCESS_IMM;
1883 pt->BasicStatus = 0x0B;
1884 pt->ExtendedStatus = 0x00;
1885 ips_free_flash_copperhead(ha);
1889 /****************************************************************************/
1891 /* Routine Name: ips_fill_scb_sg_single */
1893 /* Routine Description: */
1894 /* Fill in a single scb sg_list element from an address */
1895 /* return a -1 if a breakup occurred */
1896 /****************************************************************************/
1898 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1899 ips_scb_t * scb, int indx, unsigned int e_len)
1904 if ((scb->data_len + e_len) > ha->max_xfer) {
1905 e_len = ha->max_xfer - scb->data_len;
1906 scb->breakup = indx;
1913 if (IPS_USE_ENH_SGLIST(ha)) {
1914 scb->sg_list.enh_list[indx].address_lo =
1915 cpu_to_le32(pci_dma_lo32(busaddr));
1916 scb->sg_list.enh_list[indx].address_hi =
1917 cpu_to_le32(pci_dma_hi32(busaddr));
1918 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1920 scb->sg_list.std_list[indx].address =
1921 cpu_to_le32(pci_dma_lo32(busaddr));
1922 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1926 scb->data_len += e_len;
1930 /****************************************************************************/
1931 /* Routine Name: ips_flash_firmware */
1932 /* Routine Description: */
1933 /* flashes the firmware of a copperhead adapter */
1934 /****************************************************************************/
1936 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1938 IPS_SG_LIST sg_list;
1939 uint32_t cmd_busaddr;
1941 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1942 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1943 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1944 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1945 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1947 pt->BasicStatus = 0x0B;
1948 pt->ExtendedStatus = 0x00;
1949 ips_free_flash_copperhead(ha);
1952 /* Save the S/G list pointer so it doesn't get clobbered */
1953 sg_list.list = scb->sg_list.list;
1954 cmd_busaddr = scb->scb_busaddr;
1955 /* copy in the CP */
1956 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1957 /* FIX stuff that might be wrong */
1958 scb->sg_list.list = sg_list.list;
1959 scb->scb_busaddr = cmd_busaddr;
1960 scb->bus = scb->scsi_cmd->device->channel;
1961 scb->target_id = scb->scsi_cmd->device->id;
1962 scb->lun = scb->scsi_cmd->device->lun;
1967 scb->callback = ipsintr_done;
1968 scb->timeout = ips_cmd_timeout;
1970 scb->data_len = ha->flash_datasize;
1972 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1974 scb->flags |= IPS_SCB_MAP_SINGLE;
1975 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1976 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1978 scb->timeout = pt->TimeOut;
1979 scb->scsi_cmd->result = DID_OK << 16;
1983 /****************************************************************************/
1984 /* Routine Name: ips_free_flash_copperhead */
1985 /* Routine Description: */
1986 /* release the memory resources used to hold the flash image */
1987 /****************************************************************************/
1989 ips_free_flash_copperhead(ips_ha_t * ha)
1991 if (ha->flash_data == ips_FlashData)
1992 test_and_clear_bit(0, &ips_FlashDataInUse);
1993 else if (ha->flash_data)
1994 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
1996 ha->flash_data = NULL;
1999 /****************************************************************************/
2001 /* Routine Name: ips_usrcmd */
2003 /* Routine Description: */
2005 /* Process a user command and make it ready to send */
2007 /****************************************************************************/
2009 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
2011 IPS_SG_LIST sg_list;
2012 uint32_t cmd_busaddr;
2014 METHOD_TRACE("ips_usrcmd", 1);
2016 if ((!scb) || (!pt) || (!ha))
2019 /* Save the S/G list pointer so it doesn't get clobbered */
2020 sg_list.list = scb->sg_list.list;
2021 cmd_busaddr = scb->scb_busaddr;
2022 /* copy in the CP */
2023 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
2024 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
2026 /* FIX stuff that might be wrong */
2027 scb->sg_list.list = sg_list.list;
2028 scb->scb_busaddr = cmd_busaddr;
2029 scb->bus = scb->scsi_cmd->device->channel;
2030 scb->target_id = scb->scsi_cmd->device->id;
2031 scb->lun = scb->scsi_cmd->device->lun;
2036 scb->callback = ipsintr_done;
2037 scb->timeout = ips_cmd_timeout;
2038 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
2040 /* we don't support DCDB/READ/WRITE Scatter Gather */
2041 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
2042 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
2043 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
2047 scb->data_len = pt->CmdBSize;
2048 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
2050 scb->data_busaddr = 0L;
2053 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2054 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
2055 (unsigned long) &scb->
2057 (unsigned long) scb);
2060 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2061 scb->dcdb.buffer_pointer =
2062 cpu_to_le32(scb->data_busaddr);
2064 scb->cmd.basic_io.sg_addr =
2065 cpu_to_le32(scb->data_busaddr);
2070 scb->timeout = pt->TimeOut;
2072 if (pt->TimeOut <= 10)
2073 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
2074 else if (pt->TimeOut <= 60)
2075 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
2077 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
2080 /* assume success */
2081 scb->scsi_cmd->result = DID_OK << 16;
2087 /****************************************************************************/
2089 /* Routine Name: ips_cleanup_passthru */
2091 /* Routine Description: */
2093 /* Cleanup after a passthru command */
2095 /****************************************************************************/
2097 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
2101 METHOD_TRACE("ips_cleanup_passthru", 1);
2103 if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
2104 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2105 ips_name, ha->host_num);
2109 pt = (ips_passthru_t *) ha->ioctl_data;
2111 /* Copy data back to the user */
2112 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2113 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2115 pt->BasicStatus = scb->basic_status;
2116 pt->ExtendedStatus = scb->extended_status;
2117 pt->AdapterType = ha->ad_type;
2119 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
2120 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2121 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2122 ips_free_flash_copperhead(ha);
2124 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2127 /****************************************************************************/
2129 /* Routine Name: ips_host_info */
2131 /* Routine Description: */
2133 /* The passthru interface for the driver */
2135 /****************************************************************************/
2137 ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
2141 METHOD_TRACE("ips_host_info", 1);
2145 info.offset = offset;
2149 copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
2151 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2152 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2153 copy_info(&info, "\tController Type : %s\n",
2154 ips_adapter_name[ha->ad_type - 1]);
2157 "\tController Type : Unknown\n");
2161 "\tIO region : 0x%lx (%d bytes)\n",
2162 ha->io_addr, ha->io_len);
2166 "\tMemory region : 0x%lx (%d bytes)\n",
2167 ha->mem_addr, ha->mem_len);
2169 "\tShared memory address : 0x%lx\n",
2173 copy_info(&info, "\tIRQ number : %d\n", ha->irq);
2175 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2176 /* That keeps everything happy for "text" operations on the proc file. */
2178 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2179 if (ha->nvram->bios_low[3] == 0) {
2181 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2182 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2183 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2184 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2185 ha->nvram->bios_low[2]);
2189 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2190 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2191 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2192 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2193 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2198 if (ha->enq->CodeBlkVersion[7] == 0) {
2200 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2201 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2202 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2203 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2204 ha->enq->CodeBlkVersion[6]);
2207 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2208 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2209 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2210 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2211 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2214 if (ha->enq->BootBlkVersion[7] == 0) {
2216 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2217 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2218 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2219 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2220 ha->enq->BootBlkVersion[6]);
2223 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2224 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2225 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2226 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2227 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2230 copy_info(&info, "\tDriver Version : %s%s\n",
2231 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2233 copy_info(&info, "\tDriver Build : %d\n",
2236 copy_info(&info, "\tMax Physical Devices : %d\n",
2237 ha->enq->ucMaxPhysicalDevices);
2238 copy_info(&info, "\tMax Active Commands : %d\n",
2240 copy_info(&info, "\tCurrent Queued Commands : %d\n",
2241 ha->scb_waitlist.count);
2242 copy_info(&info, "\tCurrent Active Commands : %d\n",
2243 ha->scb_activelist.count - ha->num_ioctl);
2244 copy_info(&info, "\tCurrent Queued PT Commands : %d\n",
2245 ha->copp_waitlist.count);
2246 copy_info(&info, "\tCurrent Active PT Commands : %d\n",
2249 copy_info(&info, "\n");
2251 return (info.localpos);
2254 /****************************************************************************/
2256 /* Routine Name: copy_mem_info */
2258 /* Routine Description: */
2260 /* Copy data into an IPS_INFOSTR structure */
2262 /****************************************************************************/
2264 copy_mem_info(IPS_INFOSTR * info, char *data, int len)
2266 METHOD_TRACE("copy_mem_info", 1);
2268 if (info->pos + len < info->offset) {
2273 if (info->pos < info->offset) {
2274 data += (info->offset - info->pos);
2275 len -= (info->offset - info->pos);
2276 info->pos += (info->offset - info->pos);
2279 if (info->localpos + len > info->length)
2280 len = info->length - info->localpos;
2283 memcpy(info->buffer + info->localpos, data, len);
2285 info->localpos += len;
2289 /****************************************************************************/
2291 /* Routine Name: copy_info */
2293 /* Routine Description: */
2295 /* printf style wrapper for an info structure */
2297 /****************************************************************************/
2299 copy_info(IPS_INFOSTR * info, char *fmt, ...)
2305 METHOD_TRACE("copy_info", 1);
2307 va_start(args, fmt);
2308 len = vsprintf(buf, fmt, args);
2311 copy_mem_info(info, buf, len);
2316 /****************************************************************************/
2318 /* Routine Name: ips_identify_controller */
2320 /* Routine Description: */
2322 /* Identify this controller */
2324 /****************************************************************************/
2326 ips_identify_controller(ips_ha_t * ha)
2328 METHOD_TRACE("ips_identify_controller", 1);
2330 switch (ha->device_id) {
2331 case IPS_DEVICEID_COPPERHEAD:
2332 if (ha->revision_id <= IPS_REVID_SERVERAID) {
2333 ha->ad_type = IPS_ADTYPE_SERVERAID;
2334 } else if (ha->revision_id == IPS_REVID_SERVERAID2) {
2335 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2336 } else if (ha->revision_id == IPS_REVID_NAVAJO) {
2337 ha->ad_type = IPS_ADTYPE_NAVAJO;
2338 } else if ((ha->revision_id == IPS_REVID_SERVERAID2)
2339 && (ha->slot_num == 0)) {
2340 ha->ad_type = IPS_ADTYPE_KIOWA;
2341 } else if ((ha->revision_id >= IPS_REVID_CLARINETP1) &&
2342 (ha->revision_id <= IPS_REVID_CLARINETP3)) {
2343 if (ha->enq->ucMaxPhysicalDevices == 15)
2344 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2346 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2347 } else if ((ha->revision_id >= IPS_REVID_TROMBONE32) &&
2348 (ha->revision_id <= IPS_REVID_TROMBONE64)) {
2349 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2353 case IPS_DEVICEID_MORPHEUS:
2354 switch (ha->subdevice_id) {
2355 case IPS_SUBDEVICEID_4L:
2356 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2359 case IPS_SUBDEVICEID_4M:
2360 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2363 case IPS_SUBDEVICEID_4MX:
2364 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2367 case IPS_SUBDEVICEID_4LX:
2368 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2371 case IPS_SUBDEVICEID_5I2:
2372 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2375 case IPS_SUBDEVICEID_5I1:
2376 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2382 case IPS_DEVICEID_MARCO:
2383 switch (ha->subdevice_id) {
2384 case IPS_SUBDEVICEID_6M:
2385 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2387 case IPS_SUBDEVICEID_6I:
2388 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2390 case IPS_SUBDEVICEID_7k:
2391 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2393 case IPS_SUBDEVICEID_7M:
2394 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2401 /****************************************************************************/
2403 /* Routine Name: ips_get_bios_version */
2405 /* Routine Description: */
2407 /* Get the BIOS revision number */
2409 /****************************************************************************/
2411 ips_get_bios_version(ips_ha_t * ha, int intr)
2420 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2423 METHOD_TRACE("ips_get_bios_version", 1);
2428 strncpy(ha->bios_version, " ?", 8);
2430 if (ha->device_id == IPS_DEVICEID_COPPERHEAD) {
2431 if (IPS_USE_MEMIO(ha)) {
2432 /* Memory Mapped I/O */
2435 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2436 if (ha->revision_id == IPS_REVID_TROMBONE64)
2437 udelay(25); /* 25 us */
2439 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2442 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2443 if (ha->revision_id == IPS_REVID_TROMBONE64)
2444 udelay(25); /* 25 us */
2446 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2449 /* Get Major version */
2450 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2451 if (ha->revision_id == IPS_REVID_TROMBONE64)
2452 udelay(25); /* 25 us */
2454 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2456 /* Get Minor version */
2457 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2458 if (ha->revision_id == IPS_REVID_TROMBONE64)
2459 udelay(25); /* 25 us */
2460 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2462 /* Get SubMinor version */
2463 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2464 if (ha->revision_id == IPS_REVID_TROMBONE64)
2465 udelay(25); /* 25 us */
2466 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2469 /* Programmed I/O */
2472 outl(0, ha->io_addr + IPS_REG_FLAP);
2473 if (ha->revision_id == IPS_REVID_TROMBONE64)
2474 udelay(25); /* 25 us */
2476 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2479 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
2480 if (ha->revision_id == IPS_REVID_TROMBONE64)
2481 udelay(25); /* 25 us */
2483 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2486 /* Get Major version */
2487 outl(cpu_to_le32(0x1FF), ha->io_addr + IPS_REG_FLAP);
2488 if (ha->revision_id == IPS_REVID_TROMBONE64)
2489 udelay(25); /* 25 us */
2491 major = inb(ha->io_addr + IPS_REG_FLDP);
2493 /* Get Minor version */
2494 outl(cpu_to_le32(0x1FE), ha->io_addr + IPS_REG_FLAP);
2495 if (ha->revision_id == IPS_REVID_TROMBONE64)
2496 udelay(25); /* 25 us */
2498 minor = inb(ha->io_addr + IPS_REG_FLDP);
2500 /* Get SubMinor version */
2501 outl(cpu_to_le32(0x1FD), ha->io_addr + IPS_REG_FLAP);
2502 if (ha->revision_id == IPS_REVID_TROMBONE64)
2503 udelay(25); /* 25 us */
2505 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2509 /* Morpheus Family - Send Command to the card */
2511 buffer = ha->ioctl_data;
2513 memset(buffer, 0, 0x1000);
2515 scb = &ha->scbs[ha->max_cmds - 1];
2517 ips_init_scb(ha, scb);
2519 scb->timeout = ips_cmd_timeout;
2520 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2522 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2523 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2524 scb->cmd.flashfw.type = 1;
2525 scb->cmd.flashfw.direction = 0;
2526 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2527 scb->cmd.flashfw.total_packets = 1;
2528 scb->cmd.flashfw.packet_num = 0;
2529 scb->data_len = 0x1000;
2530 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2532 /* issue the command */
2534 ips_send_wait(ha, scb, ips_cmd_timeout,
2535 intr)) == IPS_FAILURE)
2536 || (ret == IPS_SUCCESS_IMM)
2537 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2538 /* Error occurred */
2543 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2544 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2545 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2546 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2552 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2553 ha->bios_version[1] = '.';
2554 ha->bios_version[2] = hexDigits[major & 0x0F];
2555 ha->bios_version[3] = hexDigits[subminor];
2556 ha->bios_version[4] = '.';
2557 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2558 ha->bios_version[6] = hexDigits[minor & 0x0F];
2559 ha->bios_version[7] = 0;
2562 /****************************************************************************/
2564 /* Routine Name: ips_hainit */
2566 /* Routine Description: */
2568 /* Initialize the controller */
2570 /* NOTE: Assumes to be called from with a lock */
2572 /****************************************************************************/
2574 ips_hainit(ips_ha_t * ha)
2579 METHOD_TRACE("ips_hainit", 1);
2584 if (ha->func.statinit)
2585 (*ha->func.statinit) (ha);
2587 if (ha->func.enableint)
2588 (*ha->func.enableint) (ha);
2591 ha->reset_count = 1;
2592 do_gettimeofday(&tv);
2593 ha->last_ffdc = tv.tv_sec;
2594 ips_ffdc_reset(ha, IPS_INTR_IORL);
2596 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2597 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2598 "unable to read config from controller.\n");
2603 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2604 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2605 "unable to read controller status.\n");
2610 /* Identify this controller */
2611 ips_identify_controller(ha);
2613 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2614 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2615 "unable to read subsystem parameters.\n");
2620 /* write nvram user page 5 */
2621 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2622 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2623 "unable to write driver info to controller.\n");
2628 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2629 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2630 ips_clear_adapter(ha, IPS_INTR_IORL);
2632 /* set limits on SID, LUN, BUS */
2633 ha->ntargets = IPS_MAX_TARGETS + 1;
2635 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2637 switch (ha->conf->logical_drive[0].ucStripeSize) {
2639 ha->max_xfer = 0x10000;
2643 ha->max_xfer = 0x20000;
2647 ha->max_xfer = 0x40000;
2652 ha->max_xfer = 0x80000;
2656 /* setup max concurrent commands */
2657 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2658 /* Use the new method */
2659 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2661 /* use the old method */
2662 switch (ha->conf->logical_drive[0].ucStripeSize) {
2682 /* Limit the Active Commands on a Lite Adapter */
2683 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2684 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2685 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2686 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2687 ha->max_cmds = MaxLiteCmds;
2690 /* set controller IDs */
2691 ha->ha_id[0] = IPS_ADAPTER_ID;
2692 for (i = 1; i < ha->nbus; i++) {
2693 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2694 ha->dcdb_active[i - 1] = 0;
2700 /****************************************************************************/
2702 /* Routine Name: ips_next */
2704 /* Routine Description: */
2706 /* Take the next command off the queue and send it to the controller */
2708 /****************************************************************************/
2710 ips_next(ips_ha_t * ha, int intr)
2716 ips_copp_wait_item_t *item;
2718 unsigned long cpu_flags = 0;
2719 struct Scsi_Host *host;
2720 METHOD_TRACE("ips_next", 1);
2724 host = ips_sh[ha->host_num];
2726 * Block access to the queue function so
2727 * this command won't time out
2729 if (intr == IPS_INTR_ON)
2730 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2732 if ((ha->subsys->param[3] & 0x300000)
2733 && (ha->scb_activelist.count == 0)) {
2736 do_gettimeofday(&tv);
2738 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2739 ha->last_ffdc = tv.tv_sec;
2745 * Send passthru commands
2746 * These have priority over normal I/O
2747 * but shouldn't affect performance too much
2748 * since we limit the number that can be active
2749 * on the card at any one time
2751 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2752 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2754 item = ips_removeq_copp_head(&ha->copp_waitlist);
2756 if (intr == IPS_INTR_ON)
2757 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2758 scb->scsi_cmd = item->scsi_cmd;
2761 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2763 if (intr == IPS_INTR_ON)
2764 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2767 if (scb->scsi_cmd) {
2768 scb->scsi_cmd->result = DID_ERROR << 16;
2769 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2772 ips_freescb(ha, scb);
2774 case IPS_SUCCESS_IMM:
2775 if (scb->scsi_cmd) {
2776 scb->scsi_cmd->result = DID_OK << 16;
2777 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2780 ips_freescb(ha, scb);
2786 if (ret != IPS_SUCCESS) {
2791 ret = ips_send_cmd(ha, scb);
2793 if (ret == IPS_SUCCESS)
2794 ips_putq_scb_head(&ha->scb_activelist, scb);
2800 if (scb->scsi_cmd) {
2801 scb->scsi_cmd->result = DID_ERROR << 16;
2804 ips_freescb(ha, scb);
2806 case IPS_SUCCESS_IMM:
2807 ips_freescb(ha, scb);
2816 * Send "Normal" I/O commands
2819 p = ha->scb_waitlist.head;
2820 while ((p) && (scb = ips_getscb(ha))) {
2821 if ((p->device->channel > 0)
2823 dcdb_active[p->device->channel -
2824 1] & (1 << p->device->id))) {
2825 ips_freescb(ha, scb);
2826 p = (Scsi_Cmnd *) p->host_scribble;
2831 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2833 if (intr == IPS_INTR_ON)
2834 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags); /* Unlock HA after command is taken off queue */
2836 SC->result = DID_OK;
2837 SC->host_scribble = NULL;
2839 memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
2841 scb->target_id = SC->device->id;
2842 scb->lun = SC->device->lun;
2843 scb->bus = SC->device->channel;
2847 scb->callback = ipsintr_done;
2848 scb->timeout = ips_cmd_timeout;
2849 memset(&scb->cmd, 0, 16);
2851 /* copy in the CDB */
2852 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2854 /* Now handle the data buffer */
2856 struct scatterlist *sg;
2859 sg = SC->request_buffer;
2860 scb->sg_count = pci_map_sg(ha->pcidev, sg, SC->use_sg,
2861 scsi_to_pci_dma_dir(SC->
2862 sc_data_direction));
2863 scb->flags |= IPS_SCB_MAP_SG;
2864 for (i = 0; i < scb->sg_count; i++) {
2865 if (ips_fill_scb_sg_single
2866 (ha, sg_dma_address(&sg[i]), scb, i,
2867 sg_dma_len(&sg[i])) < 0)
2870 scb->dcdb.transfer_length = scb->data_len;
2872 if (SC->request_bufflen) {
2874 pci_map_single(ha->pcidev,
2876 SC->request_bufflen,
2877 scsi_to_pci_dma_dir(SC->
2878 sc_data_direction));
2879 scb->flags |= IPS_SCB_MAP_SINGLE;
2880 ips_fill_scb_sg_single(ha, scb->data_busaddr,
2882 SC->request_bufflen);
2883 scb->dcdb.transfer_length = scb->data_len;
2885 scb->data_busaddr = 0L;
2888 scb->dcdb.transfer_length = 0;
2893 scb->dcdb.cmd_attribute =
2894 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2896 /* Allow a WRITE BUFFER Command to Have no Data */
2897 /* This is Used by Tape Flash Utilites */
2898 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0))
2899 scb->dcdb.cmd_attribute = 0;
2901 if (!(scb->dcdb.cmd_attribute & 0x3))
2902 scb->dcdb.transfer_length = 0;
2904 if (scb->data_len >= IPS_MAX_XFER) {
2905 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2906 scb->dcdb.transfer_length = 0;
2908 if (intr == IPS_INTR_ON)
2909 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2911 ret = ips_send_cmd(ha, scb);
2915 ips_putq_scb_head(&ha->scb_activelist, scb);
2918 if (scb->scsi_cmd) {
2919 scb->scsi_cmd->result = DID_ERROR << 16;
2920 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2924 ha->dcdb_active[scb->bus - 1] &=
2925 ~(1 << scb->target_id);
2927 ips_freescb(ha, scb);
2929 case IPS_SUCCESS_IMM:
2931 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2934 ha->dcdb_active[scb->bus - 1] &=
2935 ~(1 << scb->target_id);
2937 ips_freescb(ha, scb);
2943 p = (Scsi_Cmnd *) p->host_scribble;
2947 if (intr == IPS_INTR_ON)
2948 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2951 /****************************************************************************/
2953 /* Routine Name: ips_putq_scb_head */
2955 /* Routine Description: */
2957 /* Add an item to the head of the queue */
2959 /* ASSUMED to be called from within the HA lock */
2961 /****************************************************************************/
2963 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2965 METHOD_TRACE("ips_putq_scb_head", 1);
2970 item->q_next = queue->head;
2979 /****************************************************************************/
2981 /* Routine Name: ips_removeq_scb_head */
2983 /* Routine Description: */
2985 /* Remove the head of the queue */
2987 /* ASSUMED to be called from within the HA lock */
2989 /****************************************************************************/
2991 ips_removeq_scb_head(ips_scb_queue_t * queue)
2995 METHOD_TRACE("ips_removeq_scb_head", 1);
3003 queue->head = item->q_next;
3004 item->q_next = NULL;
3006 if (queue->tail == item)
3014 /****************************************************************************/
3016 /* Routine Name: ips_removeq_scb */
3018 /* Routine Description: */
3020 /* Remove an item from a queue */
3022 /* ASSUMED to be called from within the HA lock */
3024 /****************************************************************************/
3026 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
3030 METHOD_TRACE("ips_removeq_scb", 1);
3035 if (item == queue->head) {
3036 return (ips_removeq_scb_head(queue));
3041 while ((p) && (item != p->q_next))
3046 p->q_next = item->q_next;
3051 item->q_next = NULL;
3060 /****************************************************************************/
3062 /* Routine Name: ips_putq_wait_tail */
3064 /* Routine Description: */
3066 /* Add an item to the tail of the queue */
3068 /* ASSUMED to be called from within the HA lock */
3070 /****************************************************************************/
3072 ips_putq_wait_tail(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3074 METHOD_TRACE("ips_putq_wait_tail", 1);
3079 item->host_scribble = NULL;
3082 queue->tail->host_scribble = (char *) item;
3092 /****************************************************************************/
3094 /* Routine Name: ips_removeq_wait_head */
3096 /* Routine Description: */
3098 /* Remove the head of the queue */
3100 /* ASSUMED to be called from within the HA lock */
3102 /****************************************************************************/
3104 ips_removeq_wait_head(ips_wait_queue_t * queue)
3108 METHOD_TRACE("ips_removeq_wait_head", 1);
3116 queue->head = (Scsi_Cmnd *) item->host_scribble;
3117 item->host_scribble = NULL;
3119 if (queue->tail == item)
3127 /****************************************************************************/
3129 /* Routine Name: ips_removeq_wait */
3131 /* Routine Description: */
3133 /* Remove an item from a queue */
3135 /* ASSUMED to be called from within the HA lock */
3137 /****************************************************************************/
3139 ips_removeq_wait(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3143 METHOD_TRACE("ips_removeq_wait", 1);
3148 if (item == queue->head) {
3149 return (ips_removeq_wait_head(queue));
3154 while ((p) && (item != (Scsi_Cmnd *) p->host_scribble))
3155 p = (Scsi_Cmnd *) p->host_scribble;
3159 p->host_scribble = item->host_scribble;
3161 if (!item->host_scribble)
3164 item->host_scribble = NULL;
3173 /****************************************************************************/
3175 /* Routine Name: ips_putq_copp_tail */
3177 /* Routine Description: */
3179 /* Add an item to the tail of the queue */
3181 /* ASSUMED to be called from within the HA lock */
3183 /****************************************************************************/
3185 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3187 METHOD_TRACE("ips_putq_copp_tail", 1);
3195 queue->tail->next = item;
3205 /****************************************************************************/
3207 /* Routine Name: ips_removeq_copp_head */
3209 /* Routine Description: */
3211 /* Remove the head of the queue */
3213 /* ASSUMED to be called from within the HA lock */
3215 /****************************************************************************/
3216 static ips_copp_wait_item_t *
3217 ips_removeq_copp_head(ips_copp_queue_t * queue)
3219 ips_copp_wait_item_t *item;
3221 METHOD_TRACE("ips_removeq_copp_head", 1);
3229 queue->head = item->next;
3232 if (queue->tail == item)
3240 /****************************************************************************/
3242 /* Routine Name: ips_removeq_copp */
3244 /* Routine Description: */
3246 /* Remove an item from a queue */
3248 /* ASSUMED to be called from within the HA lock */
3250 /****************************************************************************/
3251 static ips_copp_wait_item_t *
3252 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3254 ips_copp_wait_item_t *p;
3256 METHOD_TRACE("ips_removeq_copp", 1);
3261 if (item == queue->head) {
3262 return (ips_removeq_copp_head(queue));
3267 while ((p) && (item != p->next))
3272 p->next = item->next;
3286 /****************************************************************************/
3288 /* Routine Name: ipsintr_blocking */
3290 /* Routine Description: */
3292 /* Finalize an interrupt for internal commands */
3294 /****************************************************************************/
3296 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3298 METHOD_TRACE("ipsintr_blocking", 2);
3300 ips_freescb(ha, scb);
3301 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3302 ha->waitflag = FALSE;
3308 /****************************************************************************/
3310 /* Routine Name: ipsintr_done */
3312 /* Routine Description: */
3314 /* Finalize an interrupt for non-internal commands */
3316 /****************************************************************************/
3318 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3320 METHOD_TRACE("ipsintr_done", 2);
3323 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3324 "Spurious interrupt; scb NULL.\n");
3329 if (scb->scsi_cmd == NULL) {
3330 /* unexpected interrupt */
3331 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3332 "Spurious interrupt; scsi_cmd not set.\n");
3340 /****************************************************************************/
3342 /* Routine Name: ips_done */
3344 /* Routine Description: */
3346 /* Do housekeeping on completed commands */
3347 /* ASSUMED to be called form within the request lock */
3348 /****************************************************************************/
3350 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3354 METHOD_TRACE("ips_done", 1);
3359 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3360 ips_cleanup_passthru(ha, scb);
3364 * Check to see if this command had too much
3365 * data and had to be broke up. If so, queue
3366 * the rest of the data and continue.
3368 if ((scb->breakup) || (scb->sg_break)) {
3369 /* we had a data breakup */
3372 if (scb->sg_count) {
3374 struct scatterlist *sg;
3375 int ips_sg_index = 0;
3378 sg = scb->scsi_cmd->request_buffer;
3380 /* Spin forward to last dma chunk */
3381 sg_dma_index = scb->breakup;
3383 /* Take care of possible partial on last chunk */
3384 ips_fill_scb_sg_single(ha,
3387 scb, ips_sg_index++,
3391 for (; sg_dma_index < scb->sg_count;
3393 if (ips_fill_scb_sg_single
3395 sg_dma_address(&sg[sg_dma_index]),
3396 scb, ips_sg_index++,
3397 sg_dma_len(&sg[sg_dma_index])) < 0)
3403 /* Non S/G Request */
3404 (void) ips_fill_scb_sg_single(ha,
3416 scb->dcdb.transfer_length = scb->data_len;
3417 scb->dcdb.cmd_attribute |=
3418 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3420 if (!(scb->dcdb.cmd_attribute & 0x3))
3421 scb->dcdb.transfer_length = 0;
3423 if (scb->data_len >= IPS_MAX_XFER) {
3424 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3425 scb->dcdb.transfer_length = 0;
3428 ret = ips_send_cmd(ha, scb);
3432 if (scb->scsi_cmd) {
3433 scb->scsi_cmd->result = DID_ERROR << 16;
3434 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3437 ips_freescb(ha, scb);
3439 case IPS_SUCCESS_IMM:
3440 if (scb->scsi_cmd) {
3441 scb->scsi_cmd->result = DID_ERROR << 16;
3442 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3445 ips_freescb(ha, scb);
3453 } /* end if passthru */
3456 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3459 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3461 ips_freescb(ha, scb);
3464 /****************************************************************************/
3466 /* Routine Name: ips_map_status */
3468 /* Routine Description: */
3470 /* Map Controller Error codes to Linux Error Codes */
3472 /****************************************************************************/
3474 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3478 uint32_t transfer_len;
3479 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3481 METHOD_TRACE("ips_map_status", 1);
3485 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3486 ips_name, ha->host_num,
3487 scb->scsi_cmd->device->channel,
3488 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3489 scb->basic_status, scb->extended_status,
3490 scb->extended_status ==
3491 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3492 scb->extended_status ==
3493 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3494 scb->extended_status ==
3495 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3498 /* default driver error */
3499 errcode = DID_ERROR;
3502 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3503 case IPS_CMD_TIMEOUT:
3504 errcode = DID_TIME_OUT;
3507 case IPS_INVAL_OPCO:
3508 case IPS_INVAL_CMD_BLK:
3509 case IPS_INVAL_PARM_BLK:
3511 case IPS_CMD_CMPLT_WERROR:
3514 case IPS_PHYS_DRV_ERROR:
3515 switch (scb->extended_status) {
3516 case IPS_ERR_SEL_TO:
3518 errcode = DID_NO_CONNECT;
3522 case IPS_ERR_OU_RUN:
3523 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3524 (scb->cmd.dcdb.op_code ==
3525 IPS_CMD_EXTENDED_DCDB_SG)) {
3526 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3527 transfer_len = tapeDCDB->transfer_length;
3530 (uint32_t) scb->dcdb.transfer_length;
3533 if ((scb->bus) && (transfer_len < scb->data_len)) {
3534 /* Underrun - set default to no error */
3537 /* Restrict access to physical DASD */
3538 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
3539 ((((char *) scb->scsi_cmd->
3540 buffer)[0] & 0x1f) == TYPE_DISK)) {
3541 /* underflow -- no error */
3542 /* restrict access to physical DASD */
3543 errcode = DID_TIME_OUT;
3547 errcode = DID_ERROR;
3551 case IPS_ERR_RECOVERY:
3552 /* don't fail recovered errors */
3558 case IPS_ERR_HOST_RESET:
3559 case IPS_ERR_DEV_RESET:
3560 errcode = DID_RESET;
3563 case IPS_ERR_CKCOND:
3565 if ((scb->cmd.dcdb.op_code ==
3566 IPS_CMD_EXTENDED_DCDB)
3567 || (scb->cmd.dcdb.op_code ==
3568 IPS_CMD_EXTENDED_DCDB_SG)) {
3570 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3571 memcpy(scb->scsi_cmd->sense_buffer,
3572 tapeDCDB->sense_info,
3573 sizeof (scb->scsi_cmd->
3576 memcpy(scb->scsi_cmd->sense_buffer,
3577 scb->dcdb.sense_info,
3578 sizeof (scb->scsi_cmd->
3581 device_error = 2; /* check condition */
3589 errcode = DID_ERROR;
3595 scb->scsi_cmd->result = device_error | (errcode << 16);
3600 /****************************************************************************/
3602 /* Routine Name: ips_send_wait */
3604 /* Routine Description: */
3606 /* Send a command to the controller and wait for it to return */
3608 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3609 /* actually need to wait. */
3610 /****************************************************************************/
3612 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3616 METHOD_TRACE("ips_send_wait", 1);
3618 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3619 ha->waitflag = TRUE;
3620 ha->cmd_in_progress = scb->cdb[0];
3622 scb->callback = ipsintr_blocking;
3623 ret = ips_send_cmd(ha, scb);
3625 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3628 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3629 ret = ips_wait(ha, timeout, intr);
3634 /****************************************************************************/
3636 /* Routine Name: ips_scmd_buf_write */
3638 /* Routine Description: */
3639 /* Write data to Scsi_Cmnd request_buffer at proper offsets */
3640 /****************************************************************************/
3642 ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data, unsigned
3647 unsigned int min_cnt, xfer_cnt;
3648 char *cdata = (char *) data;
3649 struct scatterlist *sg = scmd->request_buffer;
3650 for (i = 0, xfer_cnt = 0;
3651 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3652 if (!IPS_SG_ADDRESS(&sg[i]))
3654 min_cnt = min(count - xfer_cnt, sg[i].length);
3655 memcpy(IPS_SG_ADDRESS(&sg[i]), &cdata[xfer_cnt],
3657 xfer_cnt += min_cnt;
3661 unsigned int min_cnt = min(count, scmd->request_bufflen);
3662 memcpy(scmd->request_buffer, data, min_cnt);
3666 /****************************************************************************/
3668 /* Routine Name: ips_scmd_buf_read */
3670 /* Routine Description: */
3671 /* Copy data from a Scsi_Cmnd to a new, linear buffer */
3672 /****************************************************************************/
3674 ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned
3679 unsigned int min_cnt, xfer_cnt;
3680 char *cdata = (char *) data;
3681 struct scatterlist *sg = scmd->request_buffer;
3682 for (i = 0, xfer_cnt = 0;
3683 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3684 if (!IPS_SG_ADDRESS(&sg[i]))
3686 min_cnt = min(count - xfer_cnt, sg[i].length);
3687 memcpy(&cdata[xfer_cnt], IPS_SG_ADDRESS(&sg[i]),
3689 xfer_cnt += min_cnt;
3693 unsigned int min_cnt = min(count, scmd->request_bufflen);
3694 memcpy(data, scmd->request_buffer, min_cnt);
3698 /****************************************************************************/
3700 /* Routine Name: ips_send_cmd */
3702 /* Routine Description: */
3704 /* Map SCSI commands to ServeRAID commands for logical drives */
3706 /****************************************************************************/
3708 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3713 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3716 METHOD_TRACE("ips_send_cmd", 1);
3720 if (!scb->scsi_cmd) {
3721 /* internal command */
3724 /* Controller commands can't be issued */
3725 /* to real devices -- fail them */
3726 if ((ha->waitflag == TRUE) &&
3727 (ha->cmd_in_progress == scb->cdb[0])) {
3728 ha->waitflag = FALSE;
3733 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3734 /* command to logical bus -- interpret */
3735 ret = IPS_SUCCESS_IMM;
3737 switch (scb->scsi_cmd->cmnd[0]) {
3738 case ALLOW_MEDIUM_REMOVAL:
3741 case WRITE_FILEMARKS:
3743 scb->scsi_cmd->result = DID_ERROR << 16;
3747 scb->scsi_cmd->result = DID_OK << 16;
3749 case TEST_UNIT_READY:
3751 if (scb->target_id == IPS_ADAPTER_ID) {
3753 * Either we have a TUR
3754 * or we have a SCSI inquiry
3756 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3757 scb->scsi_cmd->result = DID_OK << 16;
3759 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3760 IPS_SCSI_INQ_DATA inquiry;
3763 sizeof (IPS_SCSI_INQ_DATA));
3765 inquiry.DeviceType =
3766 IPS_SCSI_INQ_TYPE_PROCESSOR;
3767 inquiry.DeviceTypeQualifier =
3768 IPS_SCSI_INQ_LU_CONNECTED;
3769 inquiry.Version = IPS_SCSI_INQ_REV2;
3770 inquiry.ResponseDataFormat =
3771 IPS_SCSI_INQ_RD_REV2;
3772 inquiry.AdditionalLength = 31;
3774 IPS_SCSI_INQ_Address16;
3776 IPS_SCSI_INQ_WBus16 |
3778 strncpy(inquiry.VendorId, "IBM ",
3780 strncpy(inquiry.ProductId,
3782 strncpy(inquiry.ProductRevisionLevel,
3785 ips_scmd_buf_write(scb->scsi_cmd,
3789 scb->scsi_cmd->result = DID_OK << 16;
3792 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3793 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3794 scb->cmd.logical_info.reserved = 0;
3795 scb->cmd.logical_info.reserved2 = 0;
3796 scb->data_len = sizeof (IPS_LD_INFO);
3797 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3799 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3806 ips_reqsen(ha, scb);
3807 scb->scsi_cmd->result = DID_OK << 16;
3813 scb->cmd.basic_io.op_code =
3814 (scb->scsi_cmd->cmnd[0] ==
3815 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3816 scb->cmd.basic_io.enhanced_sg = 0;
3817 scb->cmd.basic_io.sg_addr =
3818 cpu_to_le32(scb->data_busaddr);
3820 scb->cmd.basic_io.op_code =
3821 (scb->scsi_cmd->cmnd[0] ==
3822 READ_6) ? IPS_CMD_READ_SG :
3824 scb->cmd.basic_io.enhanced_sg =
3825 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3826 scb->cmd.basic_io.sg_addr =
3827 cpu_to_le32(scb->sg_busaddr);
3830 scb->cmd.basic_io.segment_4G = 0;
3831 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3832 scb->cmd.basic_io.log_drv = scb->target_id;
3833 scb->cmd.basic_io.sg_count = scb->sg_len;
3835 if (scb->cmd.basic_io.lba)
3836 scb->cmd.basic_io.lba =
3837 cpu_to_le32(le32_to_cpu
3838 (scb->cmd.basic_io.lba) +
3839 le16_to_cpu(scb->cmd.basic_io.
3842 scb->cmd.basic_io.lba =
3844 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3846 (scb->scsi_cmd->cmnd[3]));
3848 scb->cmd.basic_io.sector_count =
3849 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3851 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3852 scb->cmd.basic_io.sector_count =
3861 scb->cmd.basic_io.op_code =
3862 (scb->scsi_cmd->cmnd[0] ==
3863 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3864 scb->cmd.basic_io.enhanced_sg = 0;
3865 scb->cmd.basic_io.sg_addr =
3866 cpu_to_le32(scb->data_busaddr);
3868 scb->cmd.basic_io.op_code =
3869 (scb->scsi_cmd->cmnd[0] ==
3870 READ_10) ? IPS_CMD_READ_SG :
3872 scb->cmd.basic_io.enhanced_sg =
3873 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3874 scb->cmd.basic_io.sg_addr =
3875 cpu_to_le32(scb->sg_busaddr);
3878 scb->cmd.basic_io.segment_4G = 0;
3879 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3880 scb->cmd.basic_io.log_drv = scb->target_id;
3881 scb->cmd.basic_io.sg_count = scb->sg_len;
3883 if (scb->cmd.basic_io.lba)
3884 scb->cmd.basic_io.lba =
3885 cpu_to_le32(le32_to_cpu
3886 (scb->cmd.basic_io.lba) +
3887 le16_to_cpu(scb->cmd.basic_io.
3890 scb->cmd.basic_io.lba =
3891 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3895 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3898 scb->cmd.basic_io.sector_count =
3899 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3901 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3903 * This is a null condition
3904 * we don't have to do anything
3907 scb->scsi_cmd->result = DID_OK << 16;
3915 scb->scsi_cmd->result = DID_OK << 16;
3919 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3920 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3921 scb->cmd.basic_io.segment_4G = 0;
3922 scb->cmd.basic_io.enhanced_sg = 0;
3923 scb->data_len = sizeof (*ha->enq);
3924 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3929 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3930 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3931 scb->cmd.logical_info.reserved = 0;
3932 scb->cmd.logical_info.reserved2 = 0;
3933 scb->cmd.logical_info.reserved3 = 0;
3934 scb->data_len = sizeof (IPS_LD_INFO);
3935 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3937 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3941 case SEND_DIAGNOSTIC:
3942 case REASSIGN_BLOCKS:
3946 case READ_DEFECT_DATA:
3949 scb->scsi_cmd->result = DID_OK << 16;
3953 /* Set the Return Info to appear like the Command was */
3954 /* attempted, a Check Condition occurred, and Sense */
3955 /* Data indicating an Invalid CDB OpCode is returned. */
3956 sp = (char *) scb->scsi_cmd->sense_buffer;
3957 memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
3959 sp[0] = 0x70; /* Error Code */
3960 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3961 sp[7] = 0x0A; /* Additional Sense Length */
3962 sp[12] = 0x20; /* ASC = Invalid OpCode */
3963 sp[13] = 0x00; /* ASCQ */
3965 device_error = 2; /* Indicate Check Condition */
3966 scb->scsi_cmd->result = device_error | (DID_OK << 16);
3971 if (ret == IPS_SUCCESS_IMM)
3977 /* If we already know the Device is Not there, no need to attempt a Command */
3978 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
3979 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
3980 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
3981 return (IPS_SUCCESS_IMM);
3984 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
3985 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
3986 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
3987 (unsigned long) &scb->
3989 (unsigned long) scb);
3990 scb->cmd.dcdb.reserved = 0;
3991 scb->cmd.dcdb.reserved2 = 0;
3992 scb->cmd.dcdb.reserved3 = 0;
3993 scb->cmd.dcdb.segment_4G = 0;
3994 scb->cmd.dcdb.enhanced_sg = 0;
3996 TimeOut = scb->scsi_cmd->timeout_per_command;
3998 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
4000 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
4002 scb->cmd.dcdb.op_code =
4003 IPS_CMD_EXTENDED_DCDB_SG;
4004 scb->cmd.dcdb.enhanced_sg =
4005 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4008 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
4009 tapeDCDB->device_address =
4010 ((scb->bus - 1) << 4) | scb->target_id;
4011 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4012 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
4015 if (TimeOut < (10 * HZ))
4016 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4017 else if (TimeOut < (60 * HZ))
4018 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4019 else if (TimeOut < (1200 * HZ))
4020 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4023 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
4024 tapeDCDB->reserved_for_LUN = 0;
4025 tapeDCDB->transfer_length = scb->data_len;
4026 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
4027 tapeDCDB->buffer_pointer =
4028 cpu_to_le32(scb->sg_busaddr);
4030 tapeDCDB->buffer_pointer =
4031 cpu_to_le32(scb->data_busaddr);
4032 tapeDCDB->sg_count = scb->sg_len;
4033 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
4034 tapeDCDB->scsi_status = 0;
4035 tapeDCDB->reserved = 0;
4036 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
4037 scb->scsi_cmd->cmd_len);
4040 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
4042 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
4043 scb->cmd.dcdb.enhanced_sg =
4044 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4047 scb->dcdb.device_address =
4048 ((scb->bus - 1) << 4) | scb->target_id;
4049 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4052 if (TimeOut < (10 * HZ))
4053 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4054 else if (TimeOut < (60 * HZ))
4055 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4056 else if (TimeOut < (1200 * HZ))
4057 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4060 scb->dcdb.transfer_length = scb->data_len;
4061 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
4062 scb->dcdb.transfer_length = 0;
4063 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
4064 scb->dcdb.buffer_pointer =
4065 cpu_to_le32(scb->sg_busaddr);
4067 scb->dcdb.buffer_pointer =
4068 cpu_to_le32(scb->data_busaddr);
4069 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
4070 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
4071 scb->dcdb.sg_count = scb->sg_len;
4072 scb->dcdb.reserved = 0;
4073 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
4074 scb->scsi_cmd->cmd_len);
4075 scb->dcdb.scsi_status = 0;
4076 scb->dcdb.reserved2[0] = 0;
4077 scb->dcdb.reserved2[1] = 0;
4078 scb->dcdb.reserved2[2] = 0;
4082 return ((*ha->func.issue) (ha, scb));
4085 /****************************************************************************/
4087 /* Routine Name: ips_chk_status */
4089 /* Routine Description: */
4091 /* Check the status of commands to logical drives */
4092 /* Assumed to be called with the HA lock */
4093 /****************************************************************************/
4095 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
4099 uint8_t basic_status;
4103 METHOD_TRACE("ips_chkstatus", 1);
4105 scb = &ha->scbs[pstatus->fields.command_id];
4106 scb->basic_status = basic_status =
4107 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
4108 scb->extended_status = ext_status = pstatus->fields.extended_status;
4111 sp->residue_len = 0;
4112 sp->scb_addr = (void *) scb;
4114 /* Remove the item from the active queue */
4115 ips_removeq_scb(&ha->scb_activelist, scb);
4118 /* internal commands are handled in do_ipsintr */
4121 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
4125 scb->cmd.basic_io.command_id,
4126 scb->bus, scb->target_id, scb->lun);
4128 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
4129 /* passthru - just returns the raw result */
4134 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
4135 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
4137 if (scb->bus == 0) {
4138 if ((basic_status & IPS_GSC_STATUS_MASK) ==
4139 IPS_CMD_RECOVERED_ERROR) {
4141 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4142 ips_name, ha->host_num,
4143 scb->cmd.basic_io.op_code,
4144 basic_status, ext_status);
4147 switch (scb->scsi_cmd->cmnd[0]) {
4148 case ALLOW_MEDIUM_REMOVAL:
4151 case WRITE_FILEMARKS:
4153 errcode = DID_ERROR;
4159 case TEST_UNIT_READY:
4160 if (!ips_online(ha, scb)) {
4161 errcode = DID_TIME_OUT;
4166 if (ips_online(ha, scb)) {
4167 ips_inquiry(ha, scb);
4169 errcode = DID_TIME_OUT;
4174 ips_reqsen(ha, scb);
4186 if (!ips_online(ha, scb)
4187 || !ips_msense(ha, scb)) {
4188 errcode = DID_ERROR;
4193 if (ips_online(ha, scb))
4196 errcode = DID_TIME_OUT;
4200 case SEND_DIAGNOSTIC:
4201 case REASSIGN_BLOCKS:
4205 errcode = DID_ERROR;
4210 case READ_DEFECT_DATA:
4216 errcode = DID_ERROR;
4219 scb->scsi_cmd->result = errcode << 16;
4220 } else { /* bus == 0 */
4221 /* restrict access to physical drives */
4222 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
4223 ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) ==
4226 scb->scsi_cmd->result = DID_TIME_OUT << 16;
4229 } else { /* recovered error / success */
4230 if (scb->bus == 0) {
4232 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4233 ips_name, ha->host_num,
4234 scb->cmd.basic_io.op_code, basic_status,
4238 ips_map_status(ha, scb, sp);
4242 /****************************************************************************/
4244 /* Routine Name: ips_online */
4246 /* Routine Description: */
4248 /* Determine if a logical drive is online */
4250 /****************************************************************************/
4252 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4254 METHOD_TRACE("ips_online", 1);
4256 if (scb->target_id >= IPS_MAX_LD)
4259 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4260 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4264 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4266 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4268 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4270 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4277 /****************************************************************************/
4279 /* Routine Name: ips_inquiry */
4281 /* Routine Description: */
4283 /* Simulate an inquiry command to a logical drive */
4285 /****************************************************************************/
4287 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4289 IPS_SCSI_INQ_DATA inquiry;
4291 METHOD_TRACE("ips_inquiry", 1);
4293 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4295 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4296 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4297 inquiry.Version = IPS_SCSI_INQ_REV2;
4298 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4299 inquiry.AdditionalLength = 31;
4300 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4302 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4303 strncpy(inquiry.VendorId, "IBM ", 8);
4304 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4305 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4307 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4312 /****************************************************************************/
4314 /* Routine Name: ips_rdcap */
4316 /* Routine Description: */
4318 /* Simulate a read capacity command to a logical drive */
4320 /****************************************************************************/
4322 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4324 IPS_SCSI_CAPACITY cap;
4326 METHOD_TRACE("ips_rdcap", 1);
4328 if (scb->scsi_cmd->bufflen < 8)
4332 cpu_to_be32(le32_to_cpu
4333 (ha->logical_drive_info->
4334 drive_info[scb->target_id].sector_count) - 1);
4335 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4337 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4342 /****************************************************************************/
4344 /* Routine Name: ips_msense */
4346 /* Routine Description: */
4348 /* Simulate a mode sense command to a logical drive */
4350 /****************************************************************************/
4352 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4357 IPS_SCSI_MODE_PAGE_DATA mdata;
4359 METHOD_TRACE("ips_msense", 1);
4361 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4362 (ha->enq->ucMiscFlag & 0x8) == 0) {
4363 heads = IPS_NORM_HEADS;
4364 sectors = IPS_NORM_SECTORS;
4366 heads = IPS_COMP_HEADS;
4367 sectors = IPS_COMP_SECTORS;
4371 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4372 1) / (heads * sectors);
4374 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4376 mdata.hdr.BlockDescLength = 8;
4378 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4379 case 0x03: /* page 3 */
4380 mdata.pdata.pg3.PageCode = 3;
4381 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4382 mdata.hdr.DataLength =
4383 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4384 mdata.pdata.pg3.TracksPerZone = 0;
4385 mdata.pdata.pg3.AltSectorsPerZone = 0;
4386 mdata.pdata.pg3.AltTracksPerZone = 0;
4387 mdata.pdata.pg3.AltTracksPerVolume = 0;
4388 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4389 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4390 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4391 mdata.pdata.pg3.TrackSkew = 0;
4392 mdata.pdata.pg3.CylinderSkew = 0;
4393 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4397 mdata.pdata.pg4.PageCode = 4;
4398 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4399 mdata.hdr.DataLength =
4400 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4401 mdata.pdata.pg4.CylindersHigh =
4402 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4403 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4404 mdata.pdata.pg4.Heads = heads;
4405 mdata.pdata.pg4.WritePrecompHigh = 0;
4406 mdata.pdata.pg4.WritePrecompLow = 0;
4407 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4408 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4409 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4410 mdata.pdata.pg4.LandingZoneHigh = 0;
4411 mdata.pdata.pg4.LandingZoneLow = 0;
4412 mdata.pdata.pg4.flags = 0;
4413 mdata.pdata.pg4.RotationalOffset = 0;
4414 mdata.pdata.pg4.MediumRotationRate = 0;
4417 mdata.pdata.pg8.PageCode = 8;
4418 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4419 mdata.hdr.DataLength =
4420 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4421 /* everything else is left set to 0 */
4428 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4433 /****************************************************************************/
4435 /* Routine Name: ips_reqsen */
4437 /* Routine Description: */
4439 /* Simulate a request sense command to a logical drive */
4441 /****************************************************************************/
4443 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4445 IPS_SCSI_REQSEN reqsen;
4447 METHOD_TRACE("ips_reqsen", 1);
4449 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4451 reqsen.ResponseCode =
4452 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4453 reqsen.AdditionalLength = 10;
4454 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4455 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4457 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4462 /****************************************************************************/
4464 /* Routine Name: ips_free */
4466 /* Routine Description: */
4468 /* Free any allocated space for this controller */
4470 /****************************************************************************/
4472 ips_free(ips_ha_t * ha)
4475 METHOD_TRACE("ips_free", 1);
4479 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4480 ha->enq, ha->enq_busaddr);
4490 pci_free_consistent(ha->pcidev,
4491 sizeof (IPS_ADAPTER) +
4492 sizeof (IPS_IO_CMD), ha->adapt,
4493 ha->adapt->hw_status_start);
4497 if (ha->logical_drive_info) {
4498 pci_free_consistent(ha->pcidev,
4499 sizeof (IPS_LD_INFO),
4500 ha->logical_drive_info,
4501 ha->logical_drive_info_dma_addr);
4502 ha->logical_drive_info = NULL;
4515 if (ha->ioctl_data) {
4516 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4517 ha->ioctl_data, ha->ioctl_busaddr);
4518 ha->ioctl_data = NULL;
4519 ha->ioctl_datasize = 0;
4522 ips_deallocatescbs(ha, ha->max_cmds);
4524 /* free memory mapped (if applicable) */
4526 iounmap(ha->ioremap_ptr);
4527 ha->ioremap_ptr = NULL;
4532 release_mem_region(ha->mem_addr, ha->mem_len);
4538 /****************************************************************************/
4540 /* Routine Name: ips_deallocatescbs */
4542 /* Routine Description: */
4544 /* Free the command blocks */
4546 /****************************************************************************/
4548 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4551 pci_free_consistent(ha->pcidev,
4552 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4553 ha->scbs->sg_list.list,
4554 ha->scbs->sg_busaddr);
4555 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4556 ha->scbs, ha->scbs->scb_busaddr);
4562 /****************************************************************************/
4564 /* Routine Name: ips_allocatescbs */
4566 /* Routine Description: */
4568 /* Allocate the command blocks */
4570 /****************************************************************************/
4572 ips_allocatescbs(ips_ha_t * ha)
4577 dma_addr_t command_dma, sg_dma;
4579 METHOD_TRACE("ips_allocatescbs", 1);
4581 /* Allocate memory for the SCBs */
4583 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4585 if (ha->scbs == NULL)
4588 pci_alloc_consistent(ha->pcidev,
4589 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4590 ha->max_cmds, &sg_dma);
4591 if (ips_sg.list == NULL) {
4592 pci_free_consistent(ha->pcidev,
4593 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4598 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4600 for (i = 0; i < ha->max_cmds; i++) {
4601 scb_p = &ha->scbs[i];
4602 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4603 /* set up S/G list */
4604 if (IPS_USE_ENH_SGLIST(ha)) {
4605 scb_p->sg_list.enh_list =
4606 ips_sg.enh_list + i * IPS_MAX_SG;
4608 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4610 scb_p->sg_list.std_list =
4611 ips_sg.std_list + i * IPS_MAX_SG;
4613 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4616 /* add to the free list */
4617 if (i < ha->max_cmds - 1) {
4618 scb_p->q_next = ha->scb_freelist;
4619 ha->scb_freelist = scb_p;
4627 /****************************************************************************/
4629 /* Routine Name: ips_init_scb */
4631 /* Routine Description: */
4633 /* Initialize a CCB to default values */
4635 /****************************************************************************/
4637 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4639 IPS_SG_LIST sg_list;
4640 uint32_t cmd_busaddr, sg_busaddr;
4641 METHOD_TRACE("ips_init_scb", 1);
4646 sg_list.list = scb->sg_list.list;
4647 cmd_busaddr = scb->scb_busaddr;
4648 sg_busaddr = scb->sg_busaddr;
4650 memset(scb, 0, sizeof (ips_scb_t));
4651 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4653 /* Initialize dummy command bucket */
4654 ha->dummy->op_code = 0xFF;
4655 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4656 + sizeof (IPS_ADAPTER));
4657 ha->dummy->command_id = IPS_MAX_CMDS;
4659 /* set bus address of scb */
4660 scb->scb_busaddr = cmd_busaddr;
4661 scb->sg_busaddr = sg_busaddr;
4662 scb->sg_list.list = sg_list.list;
4665 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4666 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4667 + sizeof (IPS_ADAPTER));
4670 /****************************************************************************/
4672 /* Routine Name: ips_get_scb */
4674 /* Routine Description: */
4676 /* Initialize a CCB to default values */
4678 /* ASSUMED to be callled from within a lock */
4680 /****************************************************************************/
4682 ips_getscb(ips_ha_t * ha)
4686 METHOD_TRACE("ips_getscb", 1);
4688 if ((scb = ha->scb_freelist) == NULL) {
4693 ha->scb_freelist = scb->q_next;
4697 ips_init_scb(ha, scb);
4702 /****************************************************************************/
4704 /* Routine Name: ips_free_scb */
4706 /* Routine Description: */
4708 /* Return an unused CCB back to the free list */
4710 /* ASSUMED to be called from within a lock */
4712 /****************************************************************************/
4714 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4717 METHOD_TRACE("ips_freescb", 1);
4718 if (scb->flags & IPS_SCB_MAP_SG)
4719 pci_unmap_sg(ha->pcidev, scb->scsi_cmd->request_buffer,
4720 scb->scsi_cmd->use_sg, IPS_DMA_DIR(scb));
4721 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4722 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4725 /* check to make sure this is not our "special" scb */
4726 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4727 scb->q_next = ha->scb_freelist;
4728 ha->scb_freelist = scb;
4732 /****************************************************************************/
4734 /* Routine Name: ips_isinit_copperhead */
4736 /* Routine Description: */
4738 /* Is controller initialized ? */
4740 /****************************************************************************/
4742 ips_isinit_copperhead(ips_ha_t * ha)
4747 METHOD_TRACE("ips_isinit_copperhead", 1);
4749 isr = inb(ha->io_addr + IPS_REG_HISR);
4750 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4752 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4758 /****************************************************************************/
4760 /* Routine Name: ips_isinit_copperhead_memio */
4762 /* Routine Description: */
4764 /* Is controller initialized ? */
4766 /****************************************************************************/
4768 ips_isinit_copperhead_memio(ips_ha_t * ha)
4773 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4775 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4776 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4778 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4784 /****************************************************************************/
4786 /* Routine Name: ips_isinit_morpheus */
4788 /* Routine Description: */
4790 /* Is controller initialized ? */
4792 /****************************************************************************/
4794 ips_isinit_morpheus(ips_ha_t * ha)
4799 METHOD_TRACE("ips_is_init_morpheus", 1);
4801 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4802 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4806 else if (bits & 0x3)
4812 /****************************************************************************/
4814 /* Routine Name: ips_enable_int_copperhead */
4816 /* Routine Description: */
4817 /* Turn on interrupts */
4819 /****************************************************************************/
4821 ips_enable_int_copperhead(ips_ha_t * ha)
4823 METHOD_TRACE("ips_enable_int_copperhead", 1);
4825 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4826 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4829 /****************************************************************************/
4831 /* Routine Name: ips_enable_int_copperhead_memio */
4833 /* Routine Description: */
4834 /* Turn on interrupts */
4836 /****************************************************************************/
4838 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4840 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4842 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4843 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4846 /****************************************************************************/
4848 /* Routine Name: ips_enable_int_morpheus */
4850 /* Routine Description: */
4851 /* Turn on interrupts */
4853 /****************************************************************************/
4855 ips_enable_int_morpheus(ips_ha_t * ha)
4859 METHOD_TRACE("ips_enable_int_morpheus", 1);
4861 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4863 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4864 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4867 /****************************************************************************/
4869 /* Routine Name: ips_init_copperhead */
4871 /* Routine Description: */
4873 /* Initialize a copperhead controller */
4875 /****************************************************************************/
4877 ips_init_copperhead(ips_ha_t * ha)
4881 uint8_t PostByte[IPS_MAX_POST_BYTES];
4882 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4885 METHOD_TRACE("ips_init_copperhead", 1);
4887 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4888 for (j = 0; j < 45; j++) {
4889 Isr = inb(ha->io_addr + IPS_REG_HISR);
4890 if (Isr & IPS_BIT_GHI)
4893 /* Delay for 1 Second */
4894 MDELAY(IPS_ONE_SEC);
4898 /* error occurred */
4901 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4902 outb(Isr, ha->io_addr + IPS_REG_HISR);
4905 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4906 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4907 "reset controller fails (post status %x %x).\n",
4908 PostByte[0], PostByte[1]);
4913 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4914 for (j = 0; j < 240; j++) {
4915 Isr = inb(ha->io_addr + IPS_REG_HISR);
4916 if (Isr & IPS_BIT_GHI)
4919 /* Delay for 1 Second */
4920 MDELAY(IPS_ONE_SEC);
4924 /* error occurred */
4927 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4928 outb(Isr, ha->io_addr + IPS_REG_HISR);
4931 for (i = 0; i < 240; i++) {
4932 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
4934 if ((Cbsp & IPS_BIT_OP) == 0)
4937 /* Delay for 1 Second */
4938 MDELAY(IPS_ONE_SEC);
4946 outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
4948 /* Enable busmastering */
4949 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
4951 if (ha->revision_id == IPS_REVID_TROMBONE64)
4952 /* fix for anaconda64 */
4953 outl(0, ha->io_addr + IPS_REG_NDAE);
4955 /* Enable interrupts */
4956 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
4961 /****************************************************************************/
4963 /* Routine Name: ips_init_copperhead_memio */
4965 /* Routine Description: */
4967 /* Initialize a copperhead controller with memory mapped I/O */
4969 /****************************************************************************/
4971 ips_init_copperhead_memio(ips_ha_t * ha)
4975 uint8_t PostByte[IPS_MAX_POST_BYTES];
4976 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4979 METHOD_TRACE("ips_init_copperhead_memio", 1);
4981 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4982 for (j = 0; j < 45; j++) {
4983 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4984 if (Isr & IPS_BIT_GHI)
4987 /* Delay for 1 Second */
4988 MDELAY(IPS_ONE_SEC);
4992 /* error occurred */
4995 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
4996 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
4999 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5000 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5001 "reset controller fails (post status %x %x).\n",
5002 PostByte[0], PostByte[1]);
5007 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5008 for (j = 0; j < 240; j++) {
5009 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5010 if (Isr & IPS_BIT_GHI)
5013 /* Delay for 1 Second */
5014 MDELAY(IPS_ONE_SEC);
5018 /* error occurred */
5021 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5022 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5025 for (i = 0; i < 240; i++) {
5026 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
5028 if ((Cbsp & IPS_BIT_OP) == 0)
5031 /* Delay for 1 Second */
5032 MDELAY(IPS_ONE_SEC);
5036 /* error occurred */
5040 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
5042 /* Enable busmastering */
5043 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
5045 if (ha->revision_id == IPS_REVID_TROMBONE64)
5046 /* fix for anaconda64 */
5047 writel(0, ha->mem_ptr + IPS_REG_NDAE);
5049 /* Enable interrupts */
5050 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
5052 /* if we get here then everything went OK */
5056 /****************************************************************************/
5058 /* Routine Name: ips_init_morpheus */
5060 /* Routine Description: */
5062 /* Initialize a morpheus controller */
5064 /****************************************************************************/
5066 ips_init_morpheus(ips_ha_t * ha)
5074 METHOD_TRACE("ips_init_morpheus", 1);
5076 /* Wait up to 45 secs for Post */
5077 for (i = 0; i < 45; i++) {
5078 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5080 if (Isr & IPS_BIT_I960_MSG0I)
5083 /* Delay for 1 Second */
5084 MDELAY(IPS_ONE_SEC);
5088 /* error occurred */
5089 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5090 "timeout waiting for post.\n");
5095 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5097 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
5098 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5099 "Flashing Battery PIC, Please wait ...\n");
5101 /* Clear the interrupt bit */
5102 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5103 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5105 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
5106 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5109 /* Delay for 1 Second */
5110 MDELAY(IPS_ONE_SEC);
5114 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5115 "timeout waiting for Battery PIC Flash\n");
5121 /* Clear the interrupt bit */
5122 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5123 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5125 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
5126 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5127 "reset controller fails (post status %x).\n", Post);
5132 /* Wait up to 240 secs for config bytes */
5133 for (i = 0; i < 240; i++) {
5134 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5136 if (Isr & IPS_BIT_I960_MSG1I)
5139 /* Delay for 1 Second */
5140 MDELAY(IPS_ONE_SEC);
5144 /* error occurred */
5145 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5146 "timeout waiting for config.\n");
5151 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
5153 /* Clear interrupt bit */
5154 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
5155 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5157 /* Turn on the interrupts */
5158 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
5160 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
5162 /* if we get here then everything went OK */
5164 /* Since we did a RESET, an EraseStripeLock may be needed */
5165 if (Post == 0xEF10) {
5166 if ((Config == 0x000F) || (Config == 0x0009))
5167 ha->requires_esl = 1;
5173 /****************************************************************************/
5175 /* Routine Name: ips_reset_copperhead */
5177 /* Routine Description: */
5179 /* Reset the controller */
5181 /****************************************************************************/
5183 ips_reset_copperhead(ips_ha_t * ha)
5187 METHOD_TRACE("ips_reset_copperhead", 1);
5189 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5190 ips_name, ha->host_num, ha->io_addr, ha->irq);
5194 while (reset_counter < 2) {
5197 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5199 /* Delay for 1 Second */
5200 MDELAY(IPS_ONE_SEC);
5202 outb(0, ha->io_addr + IPS_REG_SCPR);
5204 /* Delay for 1 Second */
5205 MDELAY(IPS_ONE_SEC);
5207 if ((*ha->func.init) (ha))
5209 else if (reset_counter >= 2) {
5218 /****************************************************************************/
5220 /* Routine Name: ips_reset_copperhead_memio */
5222 /* Routine Description: */
5224 /* Reset the controller */
5226 /****************************************************************************/
5228 ips_reset_copperhead_memio(ips_ha_t * ha)
5232 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5234 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5235 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5239 while (reset_counter < 2) {
5242 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5244 /* Delay for 1 Second */
5245 MDELAY(IPS_ONE_SEC);
5247 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5249 /* Delay for 1 Second */
5250 MDELAY(IPS_ONE_SEC);
5252 if ((*ha->func.init) (ha))
5254 else if (reset_counter >= 2) {
5263 /****************************************************************************/
5265 /* Routine Name: ips_reset_morpheus */
5267 /* Routine Description: */
5269 /* Reset the controller */
5271 /****************************************************************************/
5273 ips_reset_morpheus(ips_ha_t * ha)
5278 METHOD_TRACE("ips_reset_morpheus", 1);
5280 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5281 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5285 while (reset_counter < 2) {
5288 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5290 /* Delay for 5 Seconds */
5291 MDELAY(5 * IPS_ONE_SEC);
5293 /* Do a PCI config read to wait for adapter */
5294 pci_read_config_byte(ha->pcidev, 4, &junk);
5296 if ((*ha->func.init) (ha))
5298 else if (reset_counter >= 2) {
5307 /****************************************************************************/
5309 /* Routine Name: ips_statinit */
5311 /* Routine Description: */
5313 /* Initialize the status queues on the controller */
5315 /****************************************************************************/
5317 ips_statinit(ips_ha_t * ha)
5319 uint32_t phys_status_start;
5321 METHOD_TRACE("ips_statinit", 1);
5323 ha->adapt->p_status_start = ha->adapt->status;
5324 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5325 ha->adapt->p_status_tail = ha->adapt->status;
5327 phys_status_start = ha->adapt->hw_status_start;
5328 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
5329 outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE),
5330 ha->io_addr + IPS_REG_SQER);
5331 outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE),
5332 ha->io_addr + IPS_REG_SQHR);
5333 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
5335 ha->adapt->hw_status_tail = phys_status_start;
5338 /****************************************************************************/
5340 /* Routine Name: ips_statinit_memio */
5342 /* Routine Description: */
5344 /* Initialize the status queues on the controller */
5346 /****************************************************************************/
5348 ips_statinit_memio(ips_ha_t * ha)
5350 uint32_t phys_status_start;
5352 METHOD_TRACE("ips_statinit_memio", 1);
5354 ha->adapt->p_status_start = ha->adapt->status;
5355 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5356 ha->adapt->p_status_tail = ha->adapt->status;
5358 phys_status_start = ha->adapt->hw_status_start;
5359 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5360 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5361 ha->mem_ptr + IPS_REG_SQER);
5362 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5363 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5365 ha->adapt->hw_status_tail = phys_status_start;
5368 /****************************************************************************/
5370 /* Routine Name: ips_statupd_copperhead */
5372 /* Routine Description: */
5374 /* Remove an element from the status queue */
5376 /****************************************************************************/
5378 ips_statupd_copperhead(ips_ha_t * ha)
5380 METHOD_TRACE("ips_statupd_copperhead", 1);
5382 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5383 ha->adapt->p_status_tail++;
5384 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5386 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5387 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5390 outl(cpu_to_le32(ha->adapt->hw_status_tail),
5391 ha->io_addr + IPS_REG_SQTR);
5393 return (ha->adapt->p_status_tail->value);
5396 /****************************************************************************/
5398 /* Routine Name: ips_statupd_copperhead_memio */
5400 /* Routine Description: */
5402 /* Remove an element from the status queue */
5404 /****************************************************************************/
5406 ips_statupd_copperhead_memio(ips_ha_t * ha)
5408 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5410 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5411 ha->adapt->p_status_tail++;
5412 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5414 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5415 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5418 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5420 return (ha->adapt->p_status_tail->value);
5423 /****************************************************************************/
5425 /* Routine Name: ips_statupd_morpheus */
5427 /* Routine Description: */
5429 /* Remove an element from the status queue */
5431 /****************************************************************************/
5433 ips_statupd_morpheus(ips_ha_t * ha)
5437 METHOD_TRACE("ips_statupd_morpheus", 1);
5439 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5444 /****************************************************************************/
5446 /* Routine Name: ips_issue_copperhead */
5448 /* Routine Description: */
5450 /* Send a command down to the controller */
5452 /****************************************************************************/
5454 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5459 METHOD_TRACE("ips_issue_copperhead", 1);
5461 if (scb->scsi_cmd) {
5462 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5466 scb->cmd.basic_io.command_id,
5467 scb->bus, scb->target_id, scb->lun);
5469 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5470 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5476 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5479 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5480 if (!(val & IPS_BIT_START_STOP))
5483 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5484 "ips_issue val [0x%x].\n", val);
5485 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5486 "ips_issue semaphore chk timeout.\n");
5488 return (IPS_FAILURE);
5492 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
5493 outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
5495 return (IPS_SUCCESS);
5498 /****************************************************************************/
5500 /* Routine Name: ips_issue_copperhead_memio */
5502 /* Routine Description: */
5504 /* Send a command down to the controller */
5506 /****************************************************************************/
5508 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5513 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5515 if (scb->scsi_cmd) {
5516 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5520 scb->cmd.basic_io.command_id,
5521 scb->bus, scb->target_id, scb->lun);
5523 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5524 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5529 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5532 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5533 if (!(val & IPS_BIT_START_STOP))
5536 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5537 "ips_issue val [0x%x].\n", val);
5538 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5539 "ips_issue semaphore chk timeout.\n");
5541 return (IPS_FAILURE);
5545 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5546 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5548 return (IPS_SUCCESS);
5551 /****************************************************************************/
5553 /* Routine Name: ips_issue_i2o */
5555 /* Routine Description: */
5557 /* Send a command down to the controller */
5559 /****************************************************************************/
5561 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5564 METHOD_TRACE("ips_issue_i2o", 1);
5566 if (scb->scsi_cmd) {
5567 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5571 scb->cmd.basic_io.command_id,
5572 scb->bus, scb->target_id, scb->lun);
5574 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5575 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5578 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
5580 return (IPS_SUCCESS);
5583 /****************************************************************************/
5585 /* Routine Name: ips_issue_i2o_memio */
5587 /* Routine Description: */
5589 /* Send a command down to the controller */
5591 /****************************************************************************/
5593 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5596 METHOD_TRACE("ips_issue_i2o_memio", 1);
5598 if (scb->scsi_cmd) {
5599 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5603 scb->cmd.basic_io.command_id,
5604 scb->bus, scb->target_id, scb->lun);
5606 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5607 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5610 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5612 return (IPS_SUCCESS);
5615 /****************************************************************************/
5617 /* Routine Name: ips_isintr_copperhead */
5619 /* Routine Description: */
5621 /* Test to see if an interrupt is for us */
5623 /****************************************************************************/
5625 ips_isintr_copperhead(ips_ha_t * ha)
5629 METHOD_TRACE("ips_isintr_copperhead", 2);
5631 Isr = inb(ha->io_addr + IPS_REG_HISR);
5634 /* ?!?! Nothing really there */
5637 if (Isr & IPS_BIT_SCE)
5639 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5640 /* status queue overflow or GHI */
5641 /* just clear the interrupt */
5642 outb(Isr, ha->io_addr + IPS_REG_HISR);
5648 /****************************************************************************/
5650 /* Routine Name: ips_isintr_copperhead_memio */
5652 /* Routine Description: */
5654 /* Test to see if an interrupt is for us */
5656 /****************************************************************************/
5658 ips_isintr_copperhead_memio(ips_ha_t * ha)
5662 METHOD_TRACE("ips_isintr_memio", 2);
5664 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5667 /* ?!?! Nothing really there */
5670 if (Isr & IPS_BIT_SCE)
5672 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5673 /* status queue overflow or GHI */
5674 /* just clear the interrupt */
5675 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5681 /****************************************************************************/
5683 /* Routine Name: ips_isintr_morpheus */
5685 /* Routine Description: */
5687 /* Test to see if an interrupt is for us */
5689 /****************************************************************************/
5691 ips_isintr_morpheus(ips_ha_t * ha)
5695 METHOD_TRACE("ips_isintr_morpheus", 2);
5697 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5699 if (Isr & IPS_BIT_I2O_OPQI)
5705 /****************************************************************************/
5707 /* Routine Name: ips_wait */
5709 /* Routine Description: */
5711 /* Wait for a command to complete */
5713 /****************************************************************************/
5715 ips_wait(ips_ha_t * ha, int time, int intr)
5720 METHOD_TRACE("ips_wait", 1);
5725 time *= IPS_ONE_SEC; /* convert seconds */
5727 while ((time > 0) && (!done)) {
5728 if (intr == IPS_INTR_ON) {
5729 if (ha->waitflag == FALSE) {
5734 } else if (intr == IPS_INTR_IORL) {
5735 if (ha->waitflag == FALSE) {
5737 * controller generated an interrupt to
5738 * acknowledge completion of the command
5739 * and ips_intr() has serviced the interrupt.
5747 * NOTE: we already have the io_request_lock so
5748 * even if we get an interrupt it won't get serviced
5749 * until after we finish.
5752 (*ha->func.intr) (ha);
5755 /* This looks like a very evil loop, but it only does this during start-up */
5763 /****************************************************************************/
5765 /* Routine Name: ips_write_driver_status */
5767 /* Routine Description: */
5769 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5771 /****************************************************************************/
5773 ips_write_driver_status(ips_ha_t * ha, int intr)
5775 METHOD_TRACE("ips_write_driver_status", 1);
5777 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5778 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5779 "unable to read NVRAM page 5.\n");
5784 /* check to make sure the page has a valid */
5786 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5788 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5789 ips_name, ha->host_num, ha->nvram->signature);
5790 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5794 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5795 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5796 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5797 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5798 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5799 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5800 ha->nvram->bios_low[3]);
5802 ips_get_bios_version(ha, intr);
5804 /* change values (as needed) */
5805 ha->nvram->operating_system = IPS_OS_LINUX;
5806 ha->nvram->adapter_type = ha->ad_type;
5807 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5808 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5809 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5810 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5812 ips_version_check(ha, intr); /* Check BIOS/FW/Driver Versions */
5814 /* now update the page */
5815 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5816 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5817 "unable to write NVRAM page 5.\n");
5822 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5823 ha->slot_num = ha->nvram->adapter_slot;
5828 /****************************************************************************/
5830 /* Routine Name: ips_read_adapter_status */
5832 /* Routine Description: */
5834 /* Do an Inquiry command to the adapter */
5836 /****************************************************************************/
5838 ips_read_adapter_status(ips_ha_t * ha, int intr)
5843 METHOD_TRACE("ips_read_adapter_status", 1);
5845 scb = &ha->scbs[ha->max_cmds - 1];
5847 ips_init_scb(ha, scb);
5849 scb->timeout = ips_cmd_timeout;
5850 scb->cdb[0] = IPS_CMD_ENQUIRY;
5852 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5853 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5854 scb->cmd.basic_io.sg_count = 0;
5855 scb->cmd.basic_io.lba = 0;
5856 scb->cmd.basic_io.sector_count = 0;
5857 scb->cmd.basic_io.log_drv = 0;
5858 scb->data_len = sizeof (*ha->enq);
5859 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5863 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5864 || (ret == IPS_SUCCESS_IMM)
5865 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5871 /****************************************************************************/
5873 /* Routine Name: ips_read_subsystem_parameters */
5875 /* Routine Description: */
5877 /* Read subsystem parameters from the adapter */
5879 /****************************************************************************/
5881 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
5886 METHOD_TRACE("ips_read_subsystem_parameters", 1);
5888 scb = &ha->scbs[ha->max_cmds - 1];
5890 ips_init_scb(ha, scb);
5892 scb->timeout = ips_cmd_timeout;
5893 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
5895 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
5896 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5897 scb->cmd.basic_io.sg_count = 0;
5898 scb->cmd.basic_io.lba = 0;
5899 scb->cmd.basic_io.sector_count = 0;
5900 scb->cmd.basic_io.log_drv = 0;
5901 scb->data_len = sizeof (*ha->subsys);
5902 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5906 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5907 || (ret == IPS_SUCCESS_IMM)
5908 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5911 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
5915 /****************************************************************************/
5917 /* Routine Name: ips_read_config */
5919 /* Routine Description: */
5921 /* Read the configuration on the adapter */
5923 /****************************************************************************/
5925 ips_read_config(ips_ha_t * ha, int intr)
5931 METHOD_TRACE("ips_read_config", 1);
5933 /* set defaults for initiator IDs */
5934 for (i = 0; i < 4; i++)
5935 ha->conf->init_id[i] = 7;
5937 scb = &ha->scbs[ha->max_cmds - 1];
5939 ips_init_scb(ha, scb);
5941 scb->timeout = ips_cmd_timeout;
5942 scb->cdb[0] = IPS_CMD_READ_CONF;
5944 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
5945 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5946 scb->data_len = sizeof (*ha->conf);
5947 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5951 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5952 || (ret == IPS_SUCCESS_IMM)
5953 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
5955 memset(ha->conf, 0, sizeof (IPS_CONF));
5957 /* reset initiator IDs */
5958 for (i = 0; i < 4; i++)
5959 ha->conf->init_id[i] = 7;
5961 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
5962 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
5963 IPS_CMD_CMPLT_WERROR)
5969 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
5973 /****************************************************************************/
5975 /* Routine Name: ips_readwrite_page5 */
5977 /* Routine Description: */
5979 /* Read nvram page 5 from the adapter */
5981 /****************************************************************************/
5983 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
5988 METHOD_TRACE("ips_readwrite_page5", 1);
5990 scb = &ha->scbs[ha->max_cmds - 1];
5992 ips_init_scb(ha, scb);
5994 scb->timeout = ips_cmd_timeout;
5995 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
5997 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
5998 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
5999 scb->cmd.nvram.page = 5;
6000 scb->cmd.nvram.write = write;
6001 scb->cmd.nvram.reserved = 0;
6002 scb->cmd.nvram.reserved2 = 0;
6003 scb->data_len = sizeof (*ha->nvram);
6004 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
6006 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
6008 /* issue the command */
6010 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6011 || (ret == IPS_SUCCESS_IMM)
6012 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6014 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
6019 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
6023 /****************************************************************************/
6025 /* Routine Name: ips_clear_adapter */
6027 /* Routine Description: */
6029 /* Clear the stripe lock tables */
6031 /****************************************************************************/
6033 ips_clear_adapter(ips_ha_t * ha, int intr)
6038 METHOD_TRACE("ips_clear_adapter", 1);
6040 scb = &ha->scbs[ha->max_cmds - 1];
6042 ips_init_scb(ha, scb);
6044 scb->timeout = ips_reset_timeout;
6045 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
6047 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
6048 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
6049 scb->cmd.config_sync.channel = 0;
6050 scb->cmd.config_sync.source_target = IPS_POCL;
6051 scb->cmd.config_sync.reserved = 0;
6052 scb->cmd.config_sync.reserved2 = 0;
6053 scb->cmd.config_sync.reserved3 = 0;
6057 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
6058 || (ret == IPS_SUCCESS_IMM)
6059 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6062 /* send unlock stripe command */
6063 ips_init_scb(ha, scb);
6065 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
6066 scb->timeout = ips_reset_timeout;
6068 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
6069 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
6070 scb->cmd.unlock_stripe.log_drv = 0;
6071 scb->cmd.unlock_stripe.control = IPS_CSL;
6072 scb->cmd.unlock_stripe.reserved = 0;
6073 scb->cmd.unlock_stripe.reserved2 = 0;
6074 scb->cmd.unlock_stripe.reserved3 = 0;
6078 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6079 || (ret == IPS_SUCCESS_IMM)
6080 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6086 /****************************************************************************/
6088 /* Routine Name: ips_ffdc_reset */
6090 /* Routine Description: */
6092 /* FFDC: write reset info */
6094 /****************************************************************************/
6096 ips_ffdc_reset(ips_ha_t * ha, int intr)
6100 METHOD_TRACE("ips_ffdc_reset", 1);
6102 scb = &ha->scbs[ha->max_cmds - 1];
6104 ips_init_scb(ha, scb);
6106 scb->timeout = ips_cmd_timeout;
6107 scb->cdb[0] = IPS_CMD_FFDC;
6108 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6109 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6110 scb->cmd.ffdc.reset_count = ha->reset_count;
6111 scb->cmd.ffdc.reset_type = 0x80;
6113 /* convert time to what the card wants */
6114 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6117 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6120 /****************************************************************************/
6122 /* Routine Name: ips_ffdc_time */
6124 /* Routine Description: */
6126 /* FFDC: write time info */
6128 /****************************************************************************/
6130 ips_ffdc_time(ips_ha_t * ha)
6134 METHOD_TRACE("ips_ffdc_time", 1);
6136 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
6138 scb = &ha->scbs[ha->max_cmds - 1];
6140 ips_init_scb(ha, scb);
6142 scb->timeout = ips_cmd_timeout;
6143 scb->cdb[0] = IPS_CMD_FFDC;
6144 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6145 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6146 scb->cmd.ffdc.reset_count = 0;
6147 scb->cmd.ffdc.reset_type = 0;
6149 /* convert time to what the card wants */
6150 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6153 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
6156 /****************************************************************************/
6158 /* Routine Name: ips_fix_ffdc_time */
6160 /* Routine Description: */
6161 /* Adjust time_t to what the card wants */
6163 /****************************************************************************/
6165 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6172 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6173 int month_lengths[12][2] = { {31, 31},
6187 METHOD_TRACE("ips_fix_ffdc_time", 1);
6189 days = current_time / IPS_SECS_DAY;
6190 rem = current_time % IPS_SECS_DAY;
6192 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6193 rem = rem % IPS_SECS_HOUR;
6194 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6195 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6197 year = IPS_EPOCH_YEAR;
6198 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6201 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6204 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6205 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6206 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6210 scb->cmd.ffdc.yearH = year / 100;
6211 scb->cmd.ffdc.yearL = year % 100;
6213 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6214 days -= month_lengths[i][yleap];
6216 scb->cmd.ffdc.month = i + 1;
6217 scb->cmd.ffdc.day = days + 1;
6220 /****************************************************************************
6221 * BIOS Flash Routines *
6222 ****************************************************************************/
6224 /****************************************************************************/
6226 /* Routine Name: ips_erase_bios */
6228 /* Routine Description: */
6229 /* Erase the BIOS on the adapter */
6231 /****************************************************************************/
6233 ips_erase_bios(ips_ha_t * ha)
6238 METHOD_TRACE("ips_erase_bios", 1);
6242 /* Clear the status register */
6243 outl(0, ha->io_addr + IPS_REG_FLAP);
6244 if (ha->revision_id == IPS_REVID_TROMBONE64)
6245 udelay(25); /* 25 us */
6247 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6248 if (ha->revision_id == IPS_REVID_TROMBONE64)
6249 udelay(25); /* 25 us */
6252 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6253 if (ha->revision_id == IPS_REVID_TROMBONE64)
6254 udelay(25); /* 25 us */
6257 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6258 if (ha->revision_id == IPS_REVID_TROMBONE64)
6259 udelay(25); /* 25 us */
6262 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6263 if (ha->revision_id == IPS_REVID_TROMBONE64)
6264 udelay(25); /* 25 us */
6266 timeout = 80000; /* 80 seconds */
6268 while (timeout > 0) {
6269 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6270 outl(0, ha->io_addr + IPS_REG_FLAP);
6271 udelay(25); /* 25 us */
6274 status = inb(ha->io_addr + IPS_REG_FLDP);
6283 /* check for timeout */
6287 /* try to suspend the erase */
6288 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6289 if (ha->revision_id == IPS_REVID_TROMBONE64)
6290 udelay(25); /* 25 us */
6292 /* wait for 10 seconds */
6294 while (timeout > 0) {
6295 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6296 outl(0, ha->io_addr + IPS_REG_FLAP);
6297 udelay(25); /* 25 us */
6300 status = inb(ha->io_addr + IPS_REG_FLDP);
6312 /* check for valid VPP */
6317 /* check for succesful flash */
6319 /* sequence error */
6322 /* Otherwise, we were successful */
6324 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6325 if (ha->revision_id == IPS_REVID_TROMBONE64)
6326 udelay(25); /* 25 us */
6329 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6330 if (ha->revision_id == IPS_REVID_TROMBONE64)
6331 udelay(25); /* 25 us */
6336 /****************************************************************************/
6338 /* Routine Name: ips_erase_bios_memio */
6340 /* Routine Description: */
6341 /* Erase the BIOS on the adapter */
6343 /****************************************************************************/
6345 ips_erase_bios_memio(ips_ha_t * ha)
6350 METHOD_TRACE("ips_erase_bios_memio", 1);
6354 /* Clear the status register */
6355 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6356 if (ha->revision_id == IPS_REVID_TROMBONE64)
6357 udelay(25); /* 25 us */
6359 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6360 if (ha->revision_id == IPS_REVID_TROMBONE64)
6361 udelay(25); /* 25 us */
6364 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6365 if (ha->revision_id == IPS_REVID_TROMBONE64)
6366 udelay(25); /* 25 us */
6369 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6370 if (ha->revision_id == IPS_REVID_TROMBONE64)
6371 udelay(25); /* 25 us */
6374 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6375 if (ha->revision_id == IPS_REVID_TROMBONE64)
6376 udelay(25); /* 25 us */
6378 timeout = 80000; /* 80 seconds */
6380 while (timeout > 0) {
6381 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6382 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6383 udelay(25); /* 25 us */
6386 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6395 /* check for timeout */
6399 /* try to suspend the erase */
6400 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6401 if (ha->revision_id == IPS_REVID_TROMBONE64)
6402 udelay(25); /* 25 us */
6404 /* wait for 10 seconds */
6406 while (timeout > 0) {
6407 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6408 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6409 udelay(25); /* 25 us */
6412 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6424 /* check for valid VPP */
6429 /* check for succesful flash */
6431 /* sequence error */
6434 /* Otherwise, we were successful */
6436 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6437 if (ha->revision_id == IPS_REVID_TROMBONE64)
6438 udelay(25); /* 25 us */
6441 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6442 if (ha->revision_id == IPS_REVID_TROMBONE64)
6443 udelay(25); /* 25 us */
6448 /****************************************************************************/
6450 /* Routine Name: ips_program_bios */
6452 /* Routine Description: */
6453 /* Program the BIOS on the adapter */
6455 /****************************************************************************/
6457 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6464 METHOD_TRACE("ips_program_bios", 1);
6468 for (i = 0; i < buffersize; i++) {
6470 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6471 if (ha->revision_id == IPS_REVID_TROMBONE64)
6472 udelay(25); /* 25 us */
6474 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6475 if (ha->revision_id == IPS_REVID_TROMBONE64)
6476 udelay(25); /* 25 us */
6478 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6479 if (ha->revision_id == IPS_REVID_TROMBONE64)
6480 udelay(25); /* 25 us */
6482 /* wait up to one second */
6484 while (timeout > 0) {
6485 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6486 outl(0, ha->io_addr + IPS_REG_FLAP);
6487 udelay(25); /* 25 us */
6490 status = inb(ha->io_addr + IPS_REG_FLDP);
6501 outl(0, ha->io_addr + IPS_REG_FLAP);
6502 if (ha->revision_id == IPS_REVID_TROMBONE64)
6503 udelay(25); /* 25 us */
6505 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6506 if (ha->revision_id == IPS_REVID_TROMBONE64)
6507 udelay(25); /* 25 us */
6512 /* check the status */
6513 if (status & 0x18) {
6514 /* programming error */
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 */
6527 /* Enable reading */
6528 outl(0, ha->io_addr + IPS_REG_FLAP);
6529 if (ha->revision_id == IPS_REVID_TROMBONE64)
6530 udelay(25); /* 25 us */
6532 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6533 if (ha->revision_id == IPS_REVID_TROMBONE64)
6534 udelay(25); /* 25 us */
6539 /****************************************************************************/
6541 /* Routine Name: ips_program_bios_memio */
6543 /* Routine Description: */
6544 /* Program the BIOS on the adapter */
6546 /****************************************************************************/
6548 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6555 METHOD_TRACE("ips_program_bios_memio", 1);
6559 for (i = 0; i < buffersize; i++) {
6561 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6562 if (ha->revision_id == IPS_REVID_TROMBONE64)
6563 udelay(25); /* 25 us */
6565 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6566 if (ha->revision_id == IPS_REVID_TROMBONE64)
6567 udelay(25); /* 25 us */
6569 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6570 if (ha->revision_id == IPS_REVID_TROMBONE64)
6571 udelay(25); /* 25 us */
6573 /* wait up to one second */
6575 while (timeout > 0) {
6576 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6577 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6578 udelay(25); /* 25 us */
6581 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6592 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6593 if (ha->revision_id == IPS_REVID_TROMBONE64)
6594 udelay(25); /* 25 us */
6596 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6597 if (ha->revision_id == IPS_REVID_TROMBONE64)
6598 udelay(25); /* 25 us */
6603 /* check the status */
6604 if (status & 0x18) {
6605 /* programming error */
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 */
6618 /* Enable reading */
6619 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6620 if (ha->revision_id == IPS_REVID_TROMBONE64)
6621 udelay(25); /* 25 us */
6623 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6624 if (ha->revision_id == IPS_REVID_TROMBONE64)
6625 udelay(25); /* 25 us */
6630 /****************************************************************************/
6632 /* Routine Name: ips_verify_bios */
6634 /* Routine Description: */
6635 /* Verify the BIOS on the adapter */
6637 /****************************************************************************/
6639 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6645 METHOD_TRACE("ips_verify_bios", 1);
6648 outl(0, ha->io_addr + IPS_REG_FLAP);
6649 if (ha->revision_id == IPS_REVID_TROMBONE64)
6650 udelay(25); /* 25 us */
6652 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6655 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
6656 if (ha->revision_id == IPS_REVID_TROMBONE64)
6657 udelay(25); /* 25 us */
6658 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6662 for (i = 2; i < buffersize; i++) {
6664 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6665 if (ha->revision_id == IPS_REVID_TROMBONE64)
6666 udelay(25); /* 25 us */
6668 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6679 /****************************************************************************/
6681 /* Routine Name: ips_verify_bios_memio */
6683 /* Routine Description: */
6684 /* Verify the BIOS on the adapter */
6686 /****************************************************************************/
6688 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6694 METHOD_TRACE("ips_verify_bios_memio", 1);
6697 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6698 if (ha->revision_id == IPS_REVID_TROMBONE64)
6699 udelay(25); /* 25 us */
6701 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6704 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6705 if (ha->revision_id == IPS_REVID_TROMBONE64)
6706 udelay(25); /* 25 us */
6707 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6711 for (i = 2; i < buffersize; i++) {
6713 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6714 if (ha->revision_id == IPS_REVID_TROMBONE64)
6715 udelay(25); /* 25 us */
6718 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6729 /*---------------------------------------------------------------------------*/
6730 /* Routine Name: ips_version_check */
6733 /* Assumes that ips_read_adapter_status() is called first filling in */
6734 /* the data for SubSystem Parameters. */
6735 /* Called from ips_write_driver_status() so it also assumes NVRAM Page 5 */
6736 /* Data is available. */
6738 /*---------------------------------------------------------------------------*/
6740 ips_version_check(ips_ha_t * ha, int intr)
6742 IPS_VERSION_DATA *VersionInfo;
6743 uint8_t FirmwareVersion[IPS_COMPAT_ID_LENGTH + 1];
6744 uint8_t BiosVersion[IPS_COMPAT_ID_LENGTH + 1];
6747 char BiosString[10];
6748 char FirmwareString[10];
6750 METHOD_TRACE("ips_version_check", 1);
6752 VersionInfo = ( IPS_VERSION_DATA * ) ha->ioctl_data;
6754 memset(FirmwareVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6755 memset(BiosVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6757 /* Get the Compatible BIOS Version from NVRAM Page 5 */
6758 memcpy(BiosVersion, ha->nvram->BiosCompatibilityID,
6759 IPS_COMPAT_ID_LENGTH);
6762 if (ha->subsys->param[4] & IPS_GET_VERSION_SUPPORT) { /* If Versioning is Supported */
6763 /* Get the Version Info with a Get Version Command */
6764 memset( VersionInfo, 0, sizeof (IPS_VERSION_DATA));
6765 rc = ips_get_version_info(ha, ha->ioctl_busaddr, intr);
6766 if (rc == IPS_SUCCESS)
6767 memcpy(FirmwareVersion, VersionInfo->compatibilityId,
6768 IPS_COMPAT_ID_LENGTH);
6771 if (rc != IPS_SUCCESS) { /* If Data Not Obtainable from a GetVersion Command */
6772 /* Get the Firmware Version from Enquiry Data */
6773 memcpy(FirmwareVersion, ha->enq->CodeBlkVersion,
6774 IPS_COMPAT_ID_LENGTH);
6777 /* printk(KERN_WARNING "Adapter's BIOS Version = %s\n", BiosVersion); */
6778 /* printk(KERN_WARNING "BIOS Compatible Version = %s\n", IPS_COMPAT_BIOS); */
6779 /* printk(KERN_WARNING "Adapter's Firmware Version = %s\n", FirmwareVersion); */
6780 /* printk(KERN_WARNING "Firmware Compatible Version = %s \n", Compatable[ ha->nvram->adapter_type ]); */
6785 (FirmwareVersion, Compatable[ha->nvram->adapter_type],
6786 IPS_COMPAT_ID_LENGTH) != 0)
6789 if (strncmp(BiosVersion, IPS_COMPAT_BIOS, IPS_COMPAT_ID_LENGTH) != 0)
6792 ha->nvram->versioning = 1; /* Indicate the Driver Supports Versioning */
6795 ha->nvram->version_mismatch = 1;
6796 if (ips_cd_boot == 0) {
6797 strncpy(&BiosString[0], ha->nvram->bios_high, 4);
6798 strncpy(&BiosString[4], ha->nvram->bios_low, 4);
6801 strncpy(&FirmwareString[0], ha->enq->CodeBlkVersion, 8);
6802 FirmwareString[8] = 0;
6804 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6805 "Warning ! ! ! ServeRAID Version Mismatch\n");
6806 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6807 "Bios = %s, Firmware = %s, Device Driver = %s%s\n",
6808 BiosString, FirmwareString, IPS_VERSION_HIGH,
6810 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6811 "These levels should match to avoid possible compatibility problems.\n");
6814 ha->nvram->version_mismatch = 0;
6820 /*---------------------------------------------------------------------------*/
6821 /* Routine Name: ips_get_version_info */
6823 /* Routine Description: */
6824 /* Issue an internal GETVERSION Command */
6827 /* 0 if Successful, else non-zero */
6828 /*---------------------------------------------------------------------------*/
6830 ips_get_version_info(ips_ha_t * ha, dma_addr_t Buffer, int intr)
6835 METHOD_TRACE("ips_get_version_info", 1);
6837 scb = &ha->scbs[ha->max_cmds - 1];
6839 ips_init_scb(ha, scb);
6841 scb->timeout = ips_cmd_timeout;
6842 scb->cdb[0] = IPS_CMD_GET_VERSION_INFO;
6843 scb->cmd.version_info.op_code = IPS_CMD_GET_VERSION_INFO;
6844 scb->cmd.version_info.command_id = IPS_COMMAND_ID(ha, scb);
6845 scb->cmd.version_info.reserved = 0;
6846 scb->cmd.version_info.count = sizeof (IPS_VERSION_DATA);
6847 scb->cmd.version_info.reserved2 = 0;
6848 scb->data_len = sizeof (IPS_VERSION_DATA);
6849 scb->data_busaddr = Buffer;
6850 scb->cmd.version_info.buffer_addr = Buffer;
6854 rc = ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6858 /****************************************************************************/
6860 /* Routine Name: ips_abort_init */
6862 /* Routine Description: */
6863 /* cleanup routine for a failed adapter initialization */
6864 /****************************************************************************/
6866 ips_abort_init(ips_ha_t * ha, int index)
6870 ips_ha[index] = NULL;
6871 ips_sh[index] = NULL;
6875 /****************************************************************************/
6877 /* Routine Name: ips_shift_controllers */
6879 /* Routine Description: */
6880 /* helper function for ordering adapters */
6881 /****************************************************************************/
6883 ips_shift_controllers(int lowindex, int highindex)
6885 ips_ha_t *ha_sav = ips_ha[highindex];
6886 struct Scsi_Host *sh_sav = ips_sh[highindex];
6889 for (i = highindex; i > lowindex; i--) {
6890 ips_ha[i] = ips_ha[i - 1];
6891 ips_sh[i] = ips_sh[i - 1];
6892 ips_ha[i]->host_num = i;
6894 ha_sav->host_num = lowindex;
6895 ips_ha[lowindex] = ha_sav;
6896 ips_sh[lowindex] = sh_sav;
6899 /****************************************************************************/
6901 /* Routine Name: ips_order_controllers */
6903 /* Routine Description: */
6904 /* place controllers is the "proper" boot order */
6905 /****************************************************************************/
6907 ips_order_controllers(void)
6909 int i, j, tmp, position = 0;
6910 IPS_NVRAM_P5 *nvram;
6913 nvram = ips_ha[0]->nvram;
6915 if (nvram->adapter_order[0]) {
6916 for (i = 1; i <= nvram->adapter_order[0]; i++) {
6917 for (j = position; j < ips_num_controllers; j++) {
6918 switch (ips_ha[j]->ad_type) {
6919 case IPS_ADTYPE_SERVERAID6M:
6920 case IPS_ADTYPE_SERVERAID7M:
6921 if (nvram->adapter_order[i] == 'M') {
6922 ips_shift_controllers(position,
6927 case IPS_ADTYPE_SERVERAID4L:
6928 case IPS_ADTYPE_SERVERAID4M:
6929 case IPS_ADTYPE_SERVERAID4MX:
6930 case IPS_ADTYPE_SERVERAID4LX:
6931 if (nvram->adapter_order[i] == 'N') {
6932 ips_shift_controllers(position,
6937 case IPS_ADTYPE_SERVERAID6I:
6938 case IPS_ADTYPE_SERVERAID5I2:
6939 case IPS_ADTYPE_SERVERAID5I1:
6940 case IPS_ADTYPE_SERVERAID7k:
6941 if (nvram->adapter_order[i] == 'S') {
6942 ips_shift_controllers(position,
6947 case IPS_ADTYPE_SERVERAID:
6948 case IPS_ADTYPE_SERVERAID2:
6949 case IPS_ADTYPE_NAVAJO:
6950 case IPS_ADTYPE_KIOWA:
6951 case IPS_ADTYPE_SERVERAID3L:
6952 case IPS_ADTYPE_SERVERAID3:
6953 case IPS_ADTYPE_SERVERAID4H:
6954 if (nvram->adapter_order[i] == 'A') {
6955 ips_shift_controllers(position,
6965 /* if adapter_order[0], then ordering is complete */
6968 /* old bios, use older ordering */
6970 for (i = position; i < ips_num_controllers; i++) {
6971 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I2 ||
6972 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I1) {
6973 ips_shift_controllers(position, i);
6978 /* if there were no 5I cards, then don't do any extra ordering */
6981 for (i = position; i < ips_num_controllers; i++) {
6982 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4L ||
6983 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4M ||
6984 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4LX ||
6985 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4MX) {
6986 ips_shift_controllers(position, i);
6994 /****************************************************************************/
6996 /* Routine Name: ips_register_scsi */
6998 /* Routine Description: */
6999 /* perform any registration and setup with the scsi layer */
7000 /****************************************************************************/
7002 ips_register_scsi(int index)
7004 struct Scsi_Host *sh;
7005 ips_ha_t *ha, *oldha = ips_ha[index];
7006 sh = scsi_host_alloc(&ips_driver_template, sizeof (ips_ha_t));
7008 IPS_PRINTK(KERN_WARNING, oldha->pcidev,
7009 "Unable to register controller with SCSI subsystem\n");
7013 memcpy(ha, oldha, sizeof (ips_ha_t));
7014 free_irq(oldha->irq, oldha);
7015 /* Install the interrupt handler with the new ha */
7016 if (request_irq(ha->irq, do_ipsintr, SA_SHIRQ, ips_name, ha)) {
7017 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7018 "Unable to install interrupt handler\n");
7026 IPS_SCSI_SET_DEVICE(sh, ha);
7028 /* Store away needed values for later use */
7029 sh->io_port = ha->io_addr;
7030 sh->n_io_port = ha->io_addr ? 255 : 0;
7031 sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
7033 sh->sg_tablesize = sh->hostt->sg_tablesize;
7034 sh->can_queue = sh->hostt->can_queue;
7035 sh->cmd_per_lun = sh->hostt->cmd_per_lun;
7036 sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
7037 sh->use_clustering = sh->hostt->use_clustering;
7039 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
7040 sh->max_sectors = 128;
7043 sh->max_id = ha->ntargets;
7044 sh->max_lun = ha->nlun;
7045 sh->max_channel = ha->nbus - 1;
7046 sh->can_queue = ha->max_cmds - 1;
7048 IPS_ADD_HOST(sh, NULL);
7052 /*---------------------------------------------------------------------------*/
7053 /* Routine Name: ips_remove_device */
7055 /* Routine Description: */
7056 /* Remove one Adapter ( Hot Plugging ) */
7057 /*---------------------------------------------------------------------------*/
7058 static void __devexit
7059 ips_remove_device(struct pci_dev *pci_dev)
7062 struct Scsi_Host *sh;
7065 for (i = 0; i < IPS_MAX_ADAPTERS; i++) {
7068 if ((pci_dev->bus->number == ha->pcidev->bus->number) &&
7069 (pci_dev->devfn == ha->pcidev->devfn)) {
7077 /****************************************************************************/
7079 /* Routine Name: ips_module_init */
7081 /* Routine Description: */
7082 /* function called on module load */
7083 /****************************************************************************/
7085 ips_module_init(void)
7087 if (pci_module_init(&ips_pci_driver) < 0)
7089 ips_driver_template.module = THIS_MODULE;
7090 ips_order_controllers();
7091 if (IPS_REGISTER_HOSTS(&ips_driver_template)) {
7092 pci_unregister_driver(&ips_pci_driver);
7095 register_reboot_notifier(&ips_notifier);
7099 /****************************************************************************/
7101 /* Routine Name: ips_module_exit */
7103 /* Routine Description: */
7104 /* function called on module unload */
7105 /****************************************************************************/
7107 ips_module_exit(void)
7109 IPS_UNREGISTER_HOSTS(&ips_driver_template);
7110 pci_unregister_driver(&ips_pci_driver);
7111 unregister_reboot_notifier(&ips_notifier);
7114 module_init(ips_module_init);
7115 module_exit(ips_module_exit);
7117 /*---------------------------------------------------------------------------*/
7118 /* Routine Name: ips_insert_device */
7120 /* Routine Description: */
7121 /* Add One Adapter ( Hot Plug ) */
7124 /* 0 if Successful, else non-zero */
7125 /*---------------------------------------------------------------------------*/
7126 static int __devinit
7127 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
7132 METHOD_TRACE("ips_insert_device", 1);
7133 if (pci_enable_device(pci_dev))
7136 rc = ips_init_phase1(pci_dev, &index);
7138 rc = ips_init_phase2(index);
7141 if (ips_register_scsi(index)) {
7142 ips_free(ips_ha[index]);
7147 ips_num_controllers++;
7149 ips_next_controller = ips_num_controllers;
7153 /*---------------------------------------------------------------------------*/
7154 /* Routine Name: ips_init_phase1 */
7156 /* Routine Description: */
7157 /* Adapter Initialization */
7160 /* 0 if Successful, else non-zero */
7161 /*---------------------------------------------------------------------------*/
7163 ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
7170 uint8_t revision_id;
7174 uint16_t subdevice_id;
7177 dma_addr_t dma_address;
7178 char __iomem *ioremap_ptr;
7179 char __iomem *mem_ptr;
7182 METHOD_TRACE("ips_init_phase1", 1);
7183 index = IPS_MAX_ADAPTERS;
7184 for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
7185 if (ips_ha[j] == 0) {
7191 if (index >= IPS_MAX_ADAPTERS)
7194 /* stuff that we get in dev */
7196 bus = pci_dev->bus->number;
7197 func = pci_dev->devfn;
7199 /* Init MEM/IO addresses to 0 */
7205 for (j = 0; j < 2; j++) {
7206 if (!pci_resource_start(pci_dev, j))
7209 if (pci_resource_flags(pci_dev, j) & IORESOURCE_IO) {
7210 io_addr = pci_resource_start(pci_dev, j);
7211 io_len = pci_resource_len(pci_dev, j);
7213 mem_addr = pci_resource_start(pci_dev, j);
7214 mem_len = pci_resource_len(pci_dev, j);
7218 /* setup memory mapped area (if applicable) */
7223 if (!request_mem_region(mem_addr, mem_len, "ips")) {
7224 IPS_PRINTK(KERN_WARNING, pci_dev,
7225 "Couldn't allocate IO Memory space %x len %d.\n",
7230 base = mem_addr & PAGE_MASK;
7231 offs = mem_addr - base;
7232 ioremap_ptr = ioremap(base, PAGE_SIZE);
7233 mem_ptr = ioremap_ptr + offs;
7239 /* setup I/O mapped area (if applicable) */
7241 if (!request_region(io_addr, io_len, "ips")) {
7242 IPS_PRINTK(KERN_WARNING, pci_dev,
7243 "Couldn't allocate IO space %x len %d.\n",
7249 /* get the revision ID */
7250 if (pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id)) {
7251 IPS_PRINTK(KERN_WARNING, pci_dev, "Can't get revision id.\n");
7255 subdevice_id = pci_dev->subsystem_device;
7257 /* found a controller */
7258 ha = kmalloc(sizeof (ips_ha_t), GFP_KERNEL);
7260 IPS_PRINTK(KERN_WARNING, pci_dev,
7261 "Unable to allocate temporary ha struct\n");
7265 memset(ha, 0, sizeof (ips_ha_t));
7267 ips_sh[index] = NULL;
7271 /* Store info in HA structure */
7273 ha->io_addr = io_addr;
7274 ha->io_len = io_len;
7275 ha->mem_addr = mem_addr;
7276 ha->mem_len = mem_len;
7277 ha->mem_ptr = mem_ptr;
7278 ha->ioremap_ptr = ioremap_ptr;
7279 ha->host_num = (uint32_t) index;
7280 ha->revision_id = revision_id;
7281 ha->slot_num = PCI_SLOT(pci_dev->devfn);
7282 ha->device_id = pci_dev->device;
7283 ha->subdevice_id = subdevice_id;
7284 ha->pcidev = pci_dev;
7287 * Set the pci_dev's dma_mask. Not all adapters support 64bit
7288 * addressing so don't enable it if the adapter can't support
7289 * it! Also, don't use 64bit addressing if dma addresses
7290 * are guaranteed to be < 4G.
7292 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
7293 !pci_set_dma_mask(ha->pcidev, 0xffffffffffffffffULL)) {
7294 (ha)->flags |= IPS_HA_ENH_SG;
7296 if (pci_set_dma_mask(ha->pcidev, 0xffffffffULL) != 0) {
7297 printk(KERN_WARNING "Unable to set DMA Mask\n");
7298 return ips_abort_init(ha, index);
7301 if(ips_cd_boot && !ips_FlashData){
7302 ips_FlashData = pci_alloc_consistent(pci_dev, PAGE_SIZE << 7,
7306 ha->enq = pci_alloc_consistent(pci_dev, sizeof (IPS_ENQ),
7309 IPS_PRINTK(KERN_WARNING, pci_dev,
7310 "Unable to allocate host inquiry structure\n");
7311 return ips_abort_init(ha, index);
7314 ha->adapt = pci_alloc_consistent(pci_dev, sizeof (IPS_ADAPTER) +
7315 sizeof (IPS_IO_CMD), &dma_address);
7317 IPS_PRINTK(KERN_WARNING, pci_dev,
7318 "Unable to allocate host adapt & dummy structures\n");
7319 return ips_abort_init(ha, index);
7321 ha->adapt->hw_status_start = dma_address;
7322 ha->dummy = (void *) (ha->adapt + 1);
7326 ha->logical_drive_info = pci_alloc_consistent(pci_dev, sizeof (IPS_LD_INFO), &dma_address);
7327 if (!ha->logical_drive_info) {
7328 IPS_PRINTK(KERN_WARNING, pci_dev,
7329 "Unable to allocate logical drive info structure\n");
7330 return ips_abort_init(ha, index);
7332 ha->logical_drive_info_dma_addr = dma_address;
7335 ha->conf = kmalloc(sizeof (IPS_CONF), GFP_KERNEL);
7338 IPS_PRINTK(KERN_WARNING, pci_dev,
7339 "Unable to allocate host conf structure\n");
7340 return ips_abort_init(ha, index);
7343 ha->nvram = kmalloc(sizeof (IPS_NVRAM_P5), GFP_KERNEL);
7346 IPS_PRINTK(KERN_WARNING, pci_dev,
7347 "Unable to allocate host NVRAM structure\n");
7348 return ips_abort_init(ha, index);
7351 ha->subsys = kmalloc(sizeof (IPS_SUBSYS), GFP_KERNEL);
7354 IPS_PRINTK(KERN_WARNING, pci_dev,
7355 "Unable to allocate host subsystem structure\n");
7356 return ips_abort_init(ha, index);
7359 /* the ioctl buffer is now used during adapter initialization, so its
7360 * successful allocation is now required */
7361 if (ips_ioctlsize < PAGE_SIZE)
7362 ips_ioctlsize = PAGE_SIZE;
7364 ha->ioctl_data = pci_alloc_consistent(pci_dev, ips_ioctlsize,
7365 &ha->ioctl_busaddr);
7366 ha->ioctl_len = ips_ioctlsize;
7367 if (!ha->ioctl_data) {
7368 IPS_PRINTK(KERN_WARNING, pci_dev,
7369 "Unable to allocate IOCTL data\n");
7370 return ips_abort_init(ha, index);
7376 ips_setup_funclist(ha);
7378 if ((IPS_IS_MORPHEUS(ha)) || (IPS_IS_MARCO(ha))) {
7379 /* If Morpheus appears dead, reset it */
7380 IsDead = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
7381 if (IsDead == 0xDEADBEEF) {
7382 ips_reset_morpheus(ha);
7387 * Initialize the card if it isn't already
7390 if (!(*ha->func.isinit) (ha)) {
7391 if (!(*ha->func.init) (ha)) {
7393 * Initialization failed
7395 IPS_PRINTK(KERN_WARNING, pci_dev,
7396 "Unable to initialize controller\n");
7397 return ips_abort_init(ha, index);
7405 /*---------------------------------------------------------------------------*/
7406 /* Routine Name: ips_init_phase2 */
7408 /* Routine Description: */
7409 /* Adapter Initialization Phase 2 */
7412 /* 0 if Successful, else non-zero */
7413 /*---------------------------------------------------------------------------*/
7415 ips_init_phase2(int index)
7421 METHOD_TRACE("ips_init_phase2", 1);
7423 ips_ha[index] = NULL;
7427 /* Install the interrupt handler */
7428 if (request_irq(ha->irq, do_ipsintr, SA_SHIRQ, ips_name, ha)) {
7429 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7430 "Unable to install interrupt handler\n");
7431 return ips_abort_init(ha, index);
7435 * Allocate a temporary SCB for initialization
7438 if (!ips_allocatescbs(ha)) {
7439 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7440 "Unable to allocate a CCB\n");
7441 free_irq(ha->irq, ha);
7442 return ips_abort_init(ha, index);
7445 if (!ips_hainit(ha)) {
7446 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7447 "Unable to initialize controller\n");
7448 free_irq(ha->irq, ha);
7449 return ips_abort_init(ha, index);
7451 /* Free the temporary SCB */
7452 ips_deallocatescbs(ha, 1);
7455 if (!ips_allocatescbs(ha)) {
7456 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7457 "Unable to allocate CCBs\n");
7458 free_irq(ha->irq, ha);
7459 return ips_abort_init(ha, index);
7465 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
7466 MODULE_LICENSE("GPL");
7469 MODULE_DESCRIPTION("IBM ServeRAID Adapter Driver " IPS_VER_STRING);
7471 #ifdef MODULE_VERSION
7472 MODULE_VERSION(IPS_VER_STRING);
7477 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7478 * Emacs will notice this stuff at the end of the file and automatically
7479 * adjust the settings for this buffer only. This must remain at the end
7481 * ---------------------------------------------------------------------------
7484 * c-brace-imaginary-offset: 0
7485 * c-brace-offset: -2
7486 * c-argdecl-indent: 2
7487 * c-label-offset: -2
7488 * c-continued-statement-offset: 2
7489 * c-continued-brace-offset: 0
7490 * indent-tabs-mode: nil