1 /*****************************************************************************/
2 /* ips.c -- driver for the Adaptec / IBM ServeRAID controller */
4 /* Written By: Keith Mitchell, IBM Corporation */
5 /* Jack Hammer, Adaptec, Inc. */
6 /* David Jeffery, Adaptec, Inc. */
8 /* Copyright (C) 2000 IBM Corporation */
9 /* Copyright (C) 2002,2003 Adaptec, Inc. */
11 /* This program is free software; you can redistribute it and/or modify */
12 /* it under the terms of the GNU General Public License as published by */
13 /* the Free Software Foundation; either version 2 of the License, or */
14 /* (at your option) any later version. */
16 /* This program is distributed in the hope that it will be useful, */
17 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
18 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
19 /* GNU General Public License for more details. */
22 /* THE PROGRAM IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OR */
23 /* CONDITIONS OF ANY KIND, EITHER EXPRESS OR IMPLIED INCLUDING, WITHOUT */
24 /* LIMITATION, ANY WARRANTIES OR CONDITIONS OF TITLE, NON-INFRINGEMENT, */
25 /* MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE. Each Recipient is */
26 /* solely responsible for determining the appropriateness of using and */
27 /* distributing the Program and assumes all risks associated with its */
28 /* exercise of rights under this Agreement, including but not limited to */
29 /* the risks and costs of program errors, damage to or loss of data, */
30 /* programs or equipment, and unavailability or interruption of operations. */
32 /* DISCLAIMER OF LIABILITY */
33 /* NEITHER RECIPIENT NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY */
34 /* DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL */
35 /* DAMAGES (INCLUDING WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND */
36 /* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR */
37 /* TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE */
38 /* USE OR DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED */
39 /* HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES */
41 /* You should have received a copy of the GNU General Public License */
42 /* along with this program; if not, write to the Free Software */
43 /* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
45 /* Bugs/Comments/Suggestions about this driver should be mailed to: */
46 /* ipslinux@adaptec.com */
48 /* For system support issues, contact your local IBM Customer support. */
49 /* Directions to find IBM Customer Support for each country can be found at: */
50 /* http://www.ibm.com/planetwide/ */
52 /*****************************************************************************/
54 /*****************************************************************************/
57 /* 0.99.02 - Breakup commands that are bigger than 8 * the stripe size */
58 /* 0.99.03 - Make interrupt routine handle all completed request on the */
59 /* adapter not just the first one */
60 /* - Make sure passthru commands get woken up if we run out of */
62 /* - Send all of the commands on the queue at once rather than */
63 /* one at a time since the card will support it. */
64 /* 0.99.04 - Fix race condition in the passthru mechanism -- this required */
65 /* the interface to the utilities to change */
66 /* - Fix error recovery code */
67 /* 0.99.05 - Fix an oops when we get certain passthru commands */
68 /* 1.00.00 - Initial Public Release */
69 /* Functionally equivalent to 0.99.05 */
70 /* 3.60.00 - Bump max commands to 128 for use with firmware 3.60 */
71 /* - Change version to 3.60 to coincide with release numbering. */
72 /* 3.60.01 - Remove bogus error check in passthru routine */
73 /* 3.60.02 - Make DCDB direction based on lookup table */
74 /* - Only allow one DCDB command to a SCSI ID at a time */
75 /* 4.00.00 - Add support for ServeRAID 4 */
76 /* 4.00.01 - Add support for First Failure Data Capture */
77 /* 4.00.02 - Fix problem with PT DCDB with no buffer */
78 /* 4.00.03 - Add alternative passthru interface */
79 /* - Add ability to flash BIOS */
80 /* 4.00.04 - Rename structures/constants to be prefixed with IPS_ */
81 /* 4.00.05 - Remove wish_block from init routine */
82 /* - Use linux/spinlock.h instead of asm/spinlock.h for kernels */
83 /* 2.3.18 and later */
84 /* - Sync with other changes from the 2.3 kernels */
85 /* 4.00.06 - Fix timeout with initial FFDC command */
86 /* 4.00.06a - Port to 2.4 (trivial) -- Christoph Hellwig <hch@infradead.org> */
87 /* 4.10.00 - Add support for ServeRAID 4M/4L */
88 /* 4.10.13 - Fix for dynamic unload and proc file system */
89 /* 4.20.03 - Rename version to coincide with new release schedules */
90 /* Performance fixes */
91 /* Fix truncation of /proc files with cat */
92 /* Merge in changes through kernel 2.4.0test1ac21 */
93 /* 4.20.13 - Fix some failure cases / reset code */
94 /* - Hook into the reboot_notifier to flush the controller cache */
95 /* 4.50.01 - Fix problem when there is a hole in logical drive numbering */
96 /* 4.70.09 - Use a Common ( Large Buffer ) for Flashing from the JCRM CD */
97 /* - Add IPSSEND Flash Support */
98 /* - Set Sense Data for Unknown SCSI Command */
99 /* - Use Slot Number from NVRAM Page 5 */
100 /* - Restore caller's DCDB Structure */
101 /* 4.70.12 - Corrective actions for bad controller ( during initialization )*/
102 /* 4.70.13 - Don't Send CDB's if we already know the device is not present */
103 /* - Don't release HA Lock in ips_next() until SC taken off queue */
104 /* - Unregister SCSI device in ips_release() */
105 /* 4.70.15 - Fix Breakup for very large ( non-SG ) requests in ips_done() */
106 /* 4.71.00 - Change all memory allocations to not use GFP_DMA flag */
107 /* Code Clean-Up for 2.4.x kernel */
108 /* 4.72.00 - Allow for a Scatter-Gather Element to exceed MAX_XFER Size */
109 /* 4.72.01 - I/O Mapped Memory release ( so "insmod ips" does not Fail ) */
110 /* - Don't Issue Internal FFDC Command if there are Active Commands */
111 /* - Close Window for getting too many IOCTL's active */
112 /* 4.80.00 - Make ia64 Safe */
113 /* 4.80.04 - Eliminate calls to strtok() if 2.4.x or greater */
114 /* - Adjustments to Device Queue Depth */
115 /* 4.80.14 - Take all semaphores off stack */
116 /* - Clean Up New_IOCTL path */
117 /* 4.80.20 - Set max_sectors in Scsi_Host structure ( if >= 2.4.7 kernel ) */
118 /* - 5 second delay needed after resetting an i960 adapter */
119 /* 4.80.26 - Clean up potential code problems ( Arjan's recommendations ) */
120 /* 4.90.01 - Version Matching for FirmWare, BIOS, and Driver */
121 /* 4.90.05 - Use New PCI Architecture to facilitate Hot Plug Development */
122 /* 4.90.08 - Increase Delays in Flashing ( Trombone Only - 4H ) */
123 /* 4.90.08 - Data Corruption if First Scatter Gather Element is > 64K */
124 /* 4.90.11 - Don't actually RESET unless it's physically required */
125 /* - Remove unused compile options */
126 /* 5.00.01 - Sarasota ( 5i ) adapters must always be scanned first */
127 /* - Get rid on IOCTL_NEW_COMMAND code */
128 /* - Add Extended DCDB Commands for Tape Support in 5I */
129 /* 5.10.12 - use pci_dma interfaces, update for 2.5 kernel changes */
130 /* 5.10.15 - remove unused code (sem, macros, etc.) */
131 /* 5.30.00 - use __devexit_p() */
132 /* 6.00.00 - Add 6x Adapters and Battery Flash */
133 /* 6.10.00 - Remove 1G Addressing Limitations */
134 /* 6.11.xx - Get VersionInfo buffer off the stack ! DDTS 60401 */
135 /* 6.11.xx - Make Logical Drive Info structure safe for DMA DDTS 60639 */
136 /* 7.10.18 - Add highmem_io flag in SCSI Templete for 2.4 kernels */
137 /* - Fix path/name for scsi_hosts.h include for 2.6 kernels */
138 /* - Fix sort order of 7k */
139 /* - Remove 3 unused "inline" functions */
140 /* 7.12.xx - Use STATIC functions whereever possible */
141 /* - Clean up deprecated MODULE_PARM calls */
142 /*****************************************************************************/
145 * Conditional Compilation directives for this driver:
147 * IPS_DEBUG - Turn on debugging info
151 * debug:<number> - Set debug level to <number>
152 * NOTE: only works when IPS_DEBUG compile directive is used.
153 * 1 - Normal debug messages
154 * 2 - Verbose debug messages
155 * 11 - Method trace (non interrupt)
156 * 12 - Method trace (includes interrupt)
158 * noi2o - Don't use I2O Queues (ServeRAID 4 only)
159 * nommap - Don't use memory mapped I/O
160 * ioctlsize - Initial size of the IOCTL buffer
164 #include <asm/byteorder.h>
165 #include <asm/page.h>
166 #include <linux/stddef.h>
167 #include <linux/version.h>
168 #include <linux/string.h>
169 #include <linux/errno.h>
170 #include <linux/kernel.h>
171 #include <linux/ioport.h>
172 #include <linux/slab.h>
173 #include <linux/delay.h>
174 #include <linux/pci.h>
175 #include <linux/proc_fs.h>
176 #include <linux/reboot.h>
177 #include <linux/interrupt.h>
179 #include <linux/blkdev.h>
180 #include <linux/types.h>
186 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
189 #include <scsi/scsi_host.h>
194 #include <linux/module.h>
196 #include <linux/stat.h>
197 #include <linux/config.h>
199 #include <linux/spinlock.h>
200 #include <linux/init.h>
202 #include <linux/smp.h>
205 static char *ips = NULL;
206 module_param(ips, charp, 0);
212 #define IPS_VERSION_HIGH "7.12"
213 #define IPS_VERSION_LOW ".02 "
215 #if !defined(__i386__) && !defined(__ia64__) && !defined(__x86_64__)
216 #warning "This driver has only been tested on the x86/ia64/x86_64 platforms"
219 #if LINUX_VERSION_CODE <= KERNEL_VERSION(2,5,0)
220 #include <linux/blk.h>
222 #define IPS_SG_ADDRESS(sg) ((sg)->address)
223 #define IPS_LOCK_SAVE(lock,flags) spin_lock_irqsave(&io_request_lock,flags)
224 #define IPS_UNLOCK_RESTORE(lock,flags) spin_unlock_irqrestore(&io_request_lock,flags)
226 #define __devexit_p(x) x
229 #define IPS_SG_ADDRESS(sg) (page_address((sg)->page) ? \
230 page_address((sg)->page)+(sg)->offset : NULL)
231 #define IPS_LOCK_SAVE(lock,flags) do{spin_lock(lock);(void)flags;}while(0)
232 #define IPS_UNLOCK_RESTORE(lock,flags) do{spin_unlock(lock);(void)flags;}while(0)
235 #define IPS_DMA_DIR(scb) ((!scb->scsi_cmd || ips_is_passthru(scb->scsi_cmd) || \
236 DMA_NONE == scb->scsi_cmd->sc_data_direction) ? \
237 PCI_DMA_BIDIRECTIONAL : \
238 scb->scsi_cmd->sc_data_direction)
241 #define METHOD_TRACE(s, i) if (ips_debug >= (i+10)) printk(KERN_NOTICE s "\n");
242 #define DEBUG(i, s) if (ips_debug >= i) printk(KERN_NOTICE s "\n");
243 #define DEBUG_VAR(i, s, v...) if (ips_debug >= i) printk(KERN_NOTICE s "\n", v);
245 #define METHOD_TRACE(s, i)
247 #define DEBUG_VAR(i, s, v...)
251 * Function prototypes
253 static int ips_detect(Scsi_Host_Template *);
254 static int ips_release(struct Scsi_Host *);
255 static int ips_eh_abort(Scsi_Cmnd *);
256 static int ips_eh_reset(Scsi_Cmnd *);
257 static int ips_queue(Scsi_Cmnd *, void (*)(Scsi_Cmnd *));
258 static const char *ips_info(struct Scsi_Host *);
259 static irqreturn_t do_ipsintr(int, void *, struct pt_regs *);
260 static int ips_hainit(ips_ha_t *);
261 static int ips_map_status(ips_ha_t *, ips_scb_t *, ips_stat_t *);
262 static int ips_send_wait(ips_ha_t *, ips_scb_t *, int, int);
263 static int ips_send_cmd(ips_ha_t *, ips_scb_t *);
264 static int ips_online(ips_ha_t *, ips_scb_t *);
265 static int ips_inquiry(ips_ha_t *, ips_scb_t *);
266 static int ips_rdcap(ips_ha_t *, ips_scb_t *);
267 static int ips_msense(ips_ha_t *, ips_scb_t *);
268 static int ips_reqsen(ips_ha_t *, ips_scb_t *);
269 static int ips_deallocatescbs(ips_ha_t *, int);
270 static int ips_allocatescbs(ips_ha_t *);
271 static int ips_reset_copperhead(ips_ha_t *);
272 static int ips_reset_copperhead_memio(ips_ha_t *);
273 static int ips_reset_morpheus(ips_ha_t *);
274 static int ips_issue_copperhead(ips_ha_t *, ips_scb_t *);
275 static int ips_issue_copperhead_memio(ips_ha_t *, ips_scb_t *);
276 static int ips_issue_i2o(ips_ha_t *, ips_scb_t *);
277 static int ips_issue_i2o_memio(ips_ha_t *, ips_scb_t *);
278 static int ips_isintr_copperhead(ips_ha_t *);
279 static int ips_isintr_copperhead_memio(ips_ha_t *);
280 static int ips_isintr_morpheus(ips_ha_t *);
281 static int ips_wait(ips_ha_t *, int, int);
282 static int ips_write_driver_status(ips_ha_t *, int);
283 static int ips_read_adapter_status(ips_ha_t *, int);
284 static int ips_read_subsystem_parameters(ips_ha_t *, int);
285 static int ips_read_config(ips_ha_t *, int);
286 static int ips_clear_adapter(ips_ha_t *, int);
287 static int ips_readwrite_page5(ips_ha_t *, int, int);
288 static int ips_init_copperhead(ips_ha_t *);
289 static int ips_init_copperhead_memio(ips_ha_t *);
290 static int ips_init_morpheus(ips_ha_t *);
291 static int ips_isinit_copperhead(ips_ha_t *);
292 static int ips_isinit_copperhead_memio(ips_ha_t *);
293 static int ips_isinit_morpheus(ips_ha_t *);
294 static int ips_erase_bios(ips_ha_t *);
295 static int ips_program_bios(ips_ha_t *, char *, uint32_t, uint32_t);
296 static int ips_verify_bios(ips_ha_t *, char *, uint32_t, uint32_t);
297 static int ips_erase_bios_memio(ips_ha_t *);
298 static int ips_program_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
299 static int ips_verify_bios_memio(ips_ha_t *, char *, uint32_t, uint32_t);
300 static int ips_flash_copperhead(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
301 static int ips_flash_bios(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
302 static int ips_flash_firmware(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
303 static void ips_free_flash_copperhead(ips_ha_t * ha);
304 static void ips_get_bios_version(ips_ha_t *, int);
305 static void ips_identify_controller(ips_ha_t *);
306 static void ips_chkstatus(ips_ha_t *, IPS_STATUS *);
307 static void ips_enable_int_copperhead(ips_ha_t *);
308 static void ips_enable_int_copperhead_memio(ips_ha_t *);
309 static void ips_enable_int_morpheus(ips_ha_t *);
310 static int ips_intr_copperhead(ips_ha_t *);
311 static int ips_intr_morpheus(ips_ha_t *);
312 static void ips_next(ips_ha_t *, int);
313 static void ipsintr_blocking(ips_ha_t *, struct ips_scb *);
314 static void ipsintr_done(ips_ha_t *, struct ips_scb *);
315 static void ips_done(ips_ha_t *, ips_scb_t *);
316 static void ips_free(ips_ha_t *);
317 static void ips_init_scb(ips_ha_t *, ips_scb_t *);
318 static void ips_freescb(ips_ha_t *, ips_scb_t *);
319 static void ips_setup_funclist(ips_ha_t *);
320 static void ips_statinit(ips_ha_t *);
321 static void ips_statinit_memio(ips_ha_t *);
322 static void ips_fix_ffdc_time(ips_ha_t *, ips_scb_t *, time_t);
323 static void ips_ffdc_reset(ips_ha_t *, int);
324 static void ips_ffdc_time(ips_ha_t *);
325 static uint32_t ips_statupd_copperhead(ips_ha_t *);
326 static uint32_t ips_statupd_copperhead_memio(ips_ha_t *);
327 static uint32_t ips_statupd_morpheus(ips_ha_t *);
328 static ips_scb_t *ips_getscb(ips_ha_t *);
329 static void ips_putq_scb_head(ips_scb_queue_t *, ips_scb_t *);
330 static void ips_putq_wait_tail(ips_wait_queue_t *, Scsi_Cmnd *);
331 static void ips_putq_copp_tail(ips_copp_queue_t *,
332 ips_copp_wait_item_t *);
333 static ips_scb_t *ips_removeq_scb_head(ips_scb_queue_t *);
334 static ips_scb_t *ips_removeq_scb(ips_scb_queue_t *, ips_scb_t *);
335 static Scsi_Cmnd *ips_removeq_wait_head(ips_wait_queue_t *);
336 static Scsi_Cmnd *ips_removeq_wait(ips_wait_queue_t *, Scsi_Cmnd *);
337 static ips_copp_wait_item_t *ips_removeq_copp(ips_copp_queue_t *,
338 ips_copp_wait_item_t *);
339 static ips_copp_wait_item_t *ips_removeq_copp_head(ips_copp_queue_t *);
341 static int ips_is_passthru(Scsi_Cmnd *);
342 static int ips_make_passthru(ips_ha_t *, Scsi_Cmnd *, ips_scb_t *, int);
343 static int ips_usrcmd(ips_ha_t *, ips_passthru_t *, ips_scb_t *);
344 static void ips_cleanup_passthru(ips_ha_t *, ips_scb_t *);
345 static void ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data,
347 static void ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned int count);
349 static int ips_proc_info(struct Scsi_Host *, char *, char **, off_t, int, int);
350 static int ips_host_info(ips_ha_t *, char *, off_t, int);
351 static void copy_mem_info(IPS_INFOSTR *, char *, int);
352 static int copy_info(IPS_INFOSTR *, char *, ...);
353 static int ips_get_version_info(ips_ha_t * ha, dma_addr_t, int intr);
354 static void ips_version_check(ips_ha_t * ha, int intr);
355 static int ips_abort_init(ips_ha_t * ha, int index);
356 static int ips_init_phase2(int index);
358 static int ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr);
359 static int ips_register_scsi(int index);
364 static const char ips_name[] = "ips";
365 static struct Scsi_Host *ips_sh[IPS_MAX_ADAPTERS]; /* Array of host controller structures */
366 static ips_ha_t *ips_ha[IPS_MAX_ADAPTERS]; /* Array of HA structures */
367 static unsigned int ips_next_controller;
368 static unsigned int ips_num_controllers;
369 static unsigned int ips_released_controllers;
370 static int ips_hotplug;
371 static int ips_cmd_timeout = 60;
372 static int ips_reset_timeout = 60 * 5;
373 static int ips_force_memio = 1; /* Always use Memory Mapped I/O */
374 static int ips_force_i2o = 1; /* Always use I2O command delivery */
375 static int ips_ioctlsize = IPS_IOCTL_SIZE; /* Size of the ioctl buffer */
376 static int ips_cd_boot; /* Booting from Manager CD */
377 static char *ips_FlashData = NULL; /* CD Boot - Flash Data Buffer */
378 static dma_addr_t ips_flashbusaddr;
379 static long ips_FlashDataInUse; /* CD Boot - Flash Data In Use Flag */
380 static uint32_t MaxLiteCmds = 32; /* Max Active Cmds for a Lite Adapter */
381 static Scsi_Host_Template ips_driver_template = {
382 .detect = ips_detect,
383 .release = ips_release,
385 .queuecommand = ips_queue,
386 .eh_abort_handler = ips_eh_abort,
387 .eh_host_reset_handler = ips_eh_reset,
389 #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,0)
390 .proc_info = ips_proc_info,
391 .slave_configure = ips_slave_configure,
393 .proc_info = ips_proc24_info,
394 .select_queue_depths = ips_select_queue_depth,
396 .bios_param = ips_biosparam,
398 .sg_tablesize = IPS_MAX_SG,
400 .use_clustering = ENABLE_CLUSTERING,
401 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
402 .use_new_eh_code = 1,
404 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,20) && LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
409 static IPS_DEFINE_COMPAT_TABLE( Compatable ); /* Version Compatability Table */
412 /* This table describes all ServeRAID Adapters */
413 static struct pci_device_id ips_pci_table[] = {
414 { 0x1014, 0x002E, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
415 { 0x1014, 0x01BD, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
416 { 0x9005, 0x0250, PCI_ANY_ID, PCI_ANY_ID, 0, 0 },
420 MODULE_DEVICE_TABLE( pci, ips_pci_table );
422 static char ips_hot_plug_name[] = "ips";
424 static int __devinit ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent);
425 static void __devexit ips_remove_device(struct pci_dev *pci_dev);
427 static struct pci_driver ips_pci_driver = {
428 .name = ips_hot_plug_name,
429 .id_table = ips_pci_table,
430 .probe = ips_insert_device,
431 .remove = __devexit_p(ips_remove_device),
436 * Necessary forward function protoypes
438 static int ips_halt(struct notifier_block *nb, ulong event, void *buf);
440 #define MAX_ADAPTER_NAME 15
442 static char ips_adapter_name[][30] = {
445 "ServeRAID on motherboard",
446 "ServeRAID on motherboard",
463 static struct notifier_block ips_notifier = {
470 static char ips_command_direction[] = {
471 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT,
472 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK,
473 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
474 IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
475 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_OUT,
476 IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_OUT,
477 IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_IN,
478 IPS_DATA_UNK, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
479 IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_UNK,
480 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
481 IPS_DATA_OUT, IPS_DATA_NONE, IPS_DATA_IN, IPS_DATA_NONE, IPS_DATA_NONE,
482 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT,
483 IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_OUT,
484 IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_IN, IPS_DATA_NONE,
485 IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK,
486 IPS_DATA_NONE, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK,
487 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
488 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
489 IPS_DATA_IN, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
490 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
491 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
492 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
493 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
494 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
495 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
496 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
497 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
498 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
499 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
500 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
501 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
502 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
503 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
504 IPS_DATA_NONE, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_NONE,
505 IPS_DATA_OUT, IPS_DATA_UNK, IPS_DATA_NONE, IPS_DATA_UNK, IPS_DATA_OUT,
506 IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_OUT, IPS_DATA_NONE,
507 IPS_DATA_UNK, IPS_DATA_IN, IPS_DATA_OUT, IPS_DATA_IN, IPS_DATA_IN,
508 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
509 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
510 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
511 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
512 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
513 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
514 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
515 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
516 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
517 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_OUT,
518 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
519 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
520 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK,
521 IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK, IPS_DATA_UNK
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;
824 unsigned long cpu_flags;
825 struct Scsi_Host *host;
827 METHOD_TRACE("ips_eh_abort", 1);
832 host = SC->device->host;
833 ha = (ips_ha_t *) SC->device->host->hostdata;
841 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
843 /* See if the command is on the copp queue */
844 item = ha->copp_waitlist.head;
845 while ((item) && (item->scsi_cmd != SC))
850 ips_removeq_copp(&ha->copp_waitlist, item);
853 /* See if the command is on the wait queue */
854 } else if (ips_removeq_wait(&ha->scb_waitlist, SC)) {
855 /* command not sent yet */
858 /* command must have already been sent */
862 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
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 */
1066 ips_eh_reset(Scsi_Cmnd * SC)
1070 spin_lock_irq(SC->device->host->host_lock);
1071 rc = __ips_eh_reset(SC);
1072 spin_unlock_irq(SC->device->host->host_lock);
1077 /****************************************************************************/
1079 /* Routine Name: ips_queue */
1081 /* Routine Description: */
1083 /* Send a command to the controller */
1086 /* Linux obtains io_request_lock before calling this function */
1088 /****************************************************************************/
1090 ips_queue(Scsi_Cmnd * SC, void (*done) (Scsi_Cmnd *))
1095 METHOD_TRACE("ips_queue", 1);
1097 ha = (ips_ha_t *) SC->device->host->hostdata;
1105 if (ips_is_passthru(SC)) {
1106 if (ha->copp_waitlist.count == IPS_MAX_IOCTL_QUEUE) {
1107 SC->result = DID_BUS_BUSY << 16;
1112 } else if (ha->scb_waitlist.count == IPS_MAX_QUEUE) {
1113 SC->result = DID_BUS_BUSY << 16;
1119 SC->scsi_done = done;
1121 DEBUG_VAR(2, "(%s%d): ips_queue: cmd 0x%X (%d %d %d)",
1125 SC->device->channel, SC->device->id, SC->device->lun);
1127 /* Check for command to initiator IDs */
1128 if ((SC->device->channel > 0)
1129 && (SC->device->id == ha->ha_id[SC->device->channel])) {
1130 SC->result = DID_NO_CONNECT << 16;
1136 if (ips_is_passthru(SC)) {
1138 ips_copp_wait_item_t *scratch;
1140 /* A Reset IOCTL is only sent by the boot CD in extreme cases. */
1141 /* There can never be any system activity ( network or disk ), but check */
1142 /* anyway just as a good practice. */
1143 pt = (ips_passthru_t *) SC->request_buffer;
1144 if ((pt->CoppCP.cmd.reset.op_code == IPS_CMD_RESET_CHANNEL) &&
1145 (pt->CoppCP.cmd.reset.adapter_flag == 1)) {
1146 if (ha->scb_activelist.count != 0) {
1147 SC->result = DID_BUS_BUSY << 16;
1151 ha->ioctl_reset = 1; /* This reset request is from an IOCTL */
1153 SC->result = DID_OK << 16;
1158 /* allocate space for the scribble */
1159 scratch = kmalloc(sizeof (ips_copp_wait_item_t), GFP_ATOMIC);
1162 SC->result = DID_ERROR << 16;
1168 scratch->scsi_cmd = SC;
1169 scratch->next = NULL;
1171 ips_putq_copp_tail(&ha->copp_waitlist, scratch);
1173 ips_putq_wait_tail(&ha->scb_waitlist, SC);
1176 ips_next(ha, IPS_INTR_IORL);
1181 /****************************************************************************/
1183 /* Routine Name: ips_biosparam */
1185 /* Routine Description: */
1187 /* Set bios geometry for the controller */
1189 /****************************************************************************/
1191 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1192 ips_biosparam(Disk * disk, kdev_t dev, int geom[])
1194 ips_ha_t *ha = (ips_ha_t *) disk->device->host->hostdata;
1195 unsigned long capacity = disk->capacity;
1197 ips_biosparam(struct scsi_device *sdev, struct block_device *bdev,
1198 sector_t capacity, int geom[])
1200 ips_ha_t *ha = (ips_ha_t *) sdev->host->hostdata;
1206 METHOD_TRACE("ips_biosparam", 1);
1209 /* ?!?! host adater info invalid */
1215 if (!ips_read_adapter_status(ha, IPS_INTR_ON))
1216 /* ?!?! Enquiry command failed */
1219 if ((capacity > 0x400000) && ((ha->enq->ucMiscFlag & 0x8) == 0)) {
1220 heads = IPS_NORM_HEADS;
1221 sectors = IPS_NORM_SECTORS;
1223 heads = IPS_COMP_HEADS;
1224 sectors = IPS_COMP_SECTORS;
1227 cylinders = (unsigned long) capacity / (heads * sectors);
1229 DEBUG_VAR(2, "Geometry: heads: %d, sectors: %d, cylinders: %d",
1230 heads, sectors, cylinders);
1234 geom[2] = cylinders;
1239 #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,0)
1241 /* ips_proc24_info is a wrapper around ips_proc_info *
1242 * for compatibility with the 2.4 scsi parameters */
1244 ips_proc24_info(char *buffer, char **start, off_t offset, int length,
1245 int hostno, int func)
1249 for (i = 0; i < ips_next_controller; i++) {
1250 if (ips_sh[i] && ips_sh[i]->host_no == hostno) {
1251 return ips_proc_info(ips_sh[i], buffer, start,
1252 offset, length, func);
1258 /****************************************************************************/
1260 /* Routine Name: ips_select_queue_depth */
1262 /* Routine Description: */
1264 /* Select queue depths for the devices on the contoller */
1266 /****************************************************************************/
1268 ips_select_queue_depth(struct Scsi_Host *host, Scsi_Device * scsi_devs)
1270 Scsi_Device *device;
1276 min = ha->max_cmds / 4;
1278 for (device = scsi_devs; device; device = device->next) {
1279 if (device->host == host) {
1280 if ((device->channel == 0) && (device->type == 0))
1285 for (device = scsi_devs; device; device = device->next) {
1286 if (device->host == host) {
1287 if ((device->channel == 0) && (device->type == 0)) {
1288 device->queue_depth =
1289 (ha->max_cmds - 1) / count;
1290 if (device->queue_depth < min)
1291 device->queue_depth = min;
1293 device->queue_depth = 2;
1296 if (device->queue_depth < 2)
1297 device->queue_depth = 2;
1303 /****************************************************************************/
1305 /* Routine Name: ips_slave_configure */
1307 /* Routine Description: */
1309 /* Set queue depths on devices once scan is complete */
1311 /****************************************************************************/
1313 ips_slave_configure(Scsi_Device * SDptr)
1318 ha = IPS_HA(SDptr->host);
1319 if (SDptr->tagged_supported && SDptr->type == TYPE_DISK) {
1320 min = ha->max_cmds / 2;
1321 if (ha->enq->ucLogDriveCount <= 2)
1322 min = ha->max_cmds - 1;
1323 scsi_adjust_queue_depth(SDptr, MSG_ORDERED_TAG, min);
1329 /****************************************************************************/
1331 /* Routine Name: do_ipsintr */
1333 /* Routine Description: */
1335 /* Wrapper for the interrupt handler */
1337 /****************************************************************************/
1339 do_ipsintr(int irq, void *dev_id, struct pt_regs * regs)
1342 unsigned long cpu_flags;
1343 struct Scsi_Host *host;
1346 METHOD_TRACE("do_ipsintr", 2);
1348 ha = (ips_ha_t *) dev_id;
1351 host = ips_sh[ha->host_num];
1352 /* interrupt during initialization */
1354 (*ha->func.intr) (ha);
1358 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
1361 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1365 irqstatus = (*ha->func.intr) (ha);
1367 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
1369 /* start the next command */
1370 ips_next(ha, IPS_INTR_ON);
1371 return IRQ_RETVAL(irqstatus);
1374 /****************************************************************************/
1376 /* Routine Name: ips_intr_copperhead */
1378 /* Routine Description: */
1380 /* Polling interrupt handler */
1382 /* ASSUMES interrupts are disabled */
1384 /****************************************************************************/
1386 ips_intr_copperhead(ips_ha_t * ha)
1393 METHOD_TRACE("ips_intr", 2);
1401 intrstatus = (*ha->func.isintr) (ha);
1405 * Unexpected/Shared interrupt
1414 intrstatus = (*ha->func.isintr) (ha);
1419 cstatus.value = (*ha->func.statupd) (ha);
1421 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1422 /* Spurious Interupt ? */
1426 ips_chkstatus(ha, &cstatus);
1427 scb = (ips_scb_t *) sp->scb_addr;
1430 * use the callback function to finish things up
1431 * NOTE: interrupts are OFF for this
1433 (*scb->callback) (ha, scb);
1438 /****************************************************************************/
1440 /* Routine Name: ips_intr_morpheus */
1442 /* Routine Description: */
1444 /* Polling interrupt handler */
1446 /* ASSUMES interrupts are disabled */
1448 /****************************************************************************/
1450 ips_intr_morpheus(ips_ha_t * ha)
1457 METHOD_TRACE("ips_intr_morpheus", 2);
1465 intrstatus = (*ha->func.isintr) (ha);
1469 * Unexpected/Shared interrupt
1478 intrstatus = (*ha->func.isintr) (ha);
1483 cstatus.value = (*ha->func.statupd) (ha);
1485 if (cstatus.value == 0xffffffff)
1486 /* No more to process */
1489 if (cstatus.fields.command_id > (IPS_MAX_CMDS - 1)) {
1490 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1491 "Spurious interrupt; no ccb.\n");
1496 ips_chkstatus(ha, &cstatus);
1497 scb = (ips_scb_t *) sp->scb_addr;
1500 * use the callback function to finish things up
1501 * NOTE: interrupts are OFF for this
1503 (*scb->callback) (ha, scb);
1508 /****************************************************************************/
1510 /* Routine Name: ips_info */
1512 /* Routine Description: */
1514 /* Return info about the driver */
1516 /****************************************************************************/
1518 ips_info(struct Scsi_Host *SH)
1520 static char buffer[256];
1524 METHOD_TRACE("ips_info", 1);
1532 memset(bp, 0, sizeof (buffer));
1534 sprintf(bp, "%s%s%s Build %d", "IBM PCI ServeRAID ",
1535 IPS_VERSION_HIGH, IPS_VERSION_LOW, IPS_BUILD_IDENT);
1537 if (ha->ad_type > 0 && ha->ad_type <= MAX_ADAPTER_NAME) {
1539 strcat(bp, ips_adapter_name[ha->ad_type - 1]);
1546 /****************************************************************************/
1548 /* Routine Name: ips_proc_info */
1550 /* Routine Description: */
1552 /* The passthru interface for the driver */
1554 /****************************************************************************/
1556 ips_proc_info(struct Scsi_Host *host, char *buffer, char **start, off_t offset,
1557 int length, int func)
1561 ips_ha_t *ha = NULL;
1563 METHOD_TRACE("ips_proc_info", 1);
1565 /* Find our host structure */
1566 for (i = 0; i < ips_next_controller; i++) {
1568 if (ips_sh[i] == host) {
1569 ha = (ips_ha_t *) ips_sh[i]->hostdata;
1586 ret = ips_host_info(ha, buffer, offset, length);
1592 /*--------------------------------------------------------------------------*/
1593 /* Helper Functions */
1594 /*--------------------------------------------------------------------------*/
1596 /****************************************************************************/
1598 /* Routine Name: ips_is_passthru */
1600 /* Routine Description: */
1602 /* Determine if the specified SCSI command is really a passthru command */
1604 /****************************************************************************/
1606 ips_is_passthru(Scsi_Cmnd * SC)
1608 METHOD_TRACE("ips_is_passthru", 1);
1613 if ((SC->cmnd[0] == IPS_IOCTL_COMMAND) &&
1614 (SC->device->channel == 0) &&
1615 (SC->device->id == IPS_ADAPTER_ID) &&
1616 (SC->device->lun == 0) && SC->request_buffer) {
1617 if ((!SC->use_sg) && SC->request_bufflen &&
1618 (((char *) SC->request_buffer)[0] == 'C') &&
1619 (((char *) SC->request_buffer)[1] == 'O') &&
1620 (((char *) SC->request_buffer)[2] == 'P') &&
1621 (((char *) SC->request_buffer)[3] == 'P'))
1623 else if (SC->use_sg) {
1624 struct scatterlist *sg = SC->request_buffer;
1625 char *buffer = IPS_SG_ADDRESS(sg);
1626 if (buffer && buffer[0] == 'C' && buffer[1] == 'O' &&
1627 buffer[2] == 'P' && buffer[3] == 'P')
1634 /****************************************************************************/
1636 /* Routine Name: ips_alloc_passthru_buffer */
1638 /* Routine Description: */
1639 /* allocate a buffer large enough for the ioctl data if the ioctl buffer */
1640 /* is too small or doesn't exist */
1641 /****************************************************************************/
1643 ips_alloc_passthru_buffer(ips_ha_t * ha, int length)
1646 dma_addr_t dma_busaddr;
1648 if (ha->ioctl_data && length <= ha->ioctl_len)
1650 /* there is no buffer or it's not big enough, allocate a new one */
1651 bigger_buf = pci_alloc_consistent(ha->pcidev, length, &dma_busaddr);
1653 /* free the old memory */
1654 pci_free_consistent(ha->pcidev, ha->ioctl_len, ha->ioctl_data,
1656 /* use the new memory */
1657 ha->ioctl_data = (char *) bigger_buf;
1658 ha->ioctl_len = length;
1659 ha->ioctl_busaddr = dma_busaddr;
1666 /****************************************************************************/
1668 /* Routine Name: ips_make_passthru */
1670 /* Routine Description: */
1672 /* Make a passthru command out of the info in the Scsi block */
1674 /****************************************************************************/
1676 ips_make_passthru(ips_ha_t * ha, Scsi_Cmnd * SC, ips_scb_t * scb, int intr)
1682 METHOD_TRACE("ips_make_passthru", 1);
1685 length = SC->request_bufflen;
1687 struct scatterlist *sg = SC->request_buffer;
1689 for (i = 0; i < SC->use_sg; i++)
1690 length += sg[i].length;
1692 if (length < sizeof (ips_passthru_t)) {
1694 DEBUG_VAR(1, "(%s%d) Passthru structure wrong size",
1695 ips_name, ha->host_num);
1696 return (IPS_FAILURE);
1698 if (ips_alloc_passthru_buffer(ha, length)) {
1699 /* allocation failure! If ha->ioctl_data exists, use it to return
1700 some error codes. Return a failed command to the scsi layer. */
1701 if (ha->ioctl_data) {
1702 pt = (ips_passthru_t *) ha->ioctl_data;
1703 ips_scmd_buf_read(SC, pt, sizeof (ips_passthru_t));
1704 pt->BasicStatus = 0x0B;
1705 pt->ExtendedStatus = 0x00;
1706 ips_scmd_buf_write(SC, pt, sizeof (ips_passthru_t));
1710 ha->ioctl_datasize = length;
1712 ips_scmd_buf_read(SC, ha->ioctl_data, ha->ioctl_datasize);
1713 pt = (ips_passthru_t *) ha->ioctl_data;
1716 * Some notes about the passthru interface used
1718 * IF the scsi op_code == 0x0d then we assume
1719 * that the data came along with/goes with the
1720 * packet we received from the sg driver. In this
1721 * case the CmdBSize field of the pt structure is
1722 * used for the size of the buffer.
1725 switch (pt->CoppCmd) {
1727 memcpy(ha->ioctl_data + sizeof (ips_passthru_t),
1728 &ips_num_controllers, sizeof (int));
1729 ips_scmd_buf_write(SC, ha->ioctl_data,
1730 sizeof (ips_passthru_t) + sizeof (int));
1731 SC->result = DID_OK << 16;
1733 return (IPS_SUCCESS_IMM);
1735 case IPS_COPPUSRCMD:
1736 case IPS_COPPIOCCMD:
1737 if (SC->cmnd[0] == IPS_IOCTL_COMMAND) {
1738 if (length < (sizeof (ips_passthru_t) + pt->CmdBSize)) {
1741 "(%s%d) Passthru structure wrong size",
1742 ips_name, ha->host_num);
1744 return (IPS_FAILURE);
1747 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
1748 pt->CoppCP.cmd.flashfw.op_code ==
1749 IPS_CMD_RW_BIOSFW) {
1750 ret = ips_flash_copperhead(ha, pt, scb);
1751 ips_scmd_buf_write(SC, ha->ioctl_data,
1752 sizeof (ips_passthru_t));
1755 if (ips_usrcmd(ha, pt, scb))
1756 return (IPS_SUCCESS);
1758 return (IPS_FAILURE);
1765 return (IPS_FAILURE);
1768 /****************************************************************************/
1769 /* Routine Name: ips_flash_copperhead */
1770 /* Routine Description: */
1771 /* Flash the BIOS/FW on a Copperhead style controller */
1772 /****************************************************************************/
1774 ips_flash_copperhead(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1778 /* Trombone is the only copperhead that can do packet flash, but only
1779 * for firmware. No one said it had to make sence. */
1780 if (IPS_IS_TROMBONE(ha) && pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE) {
1781 if (ips_usrcmd(ha, pt, scb))
1786 pt->BasicStatus = 0x0B;
1787 pt->ExtendedStatus = 0;
1788 scb->scsi_cmd->result = DID_OK << 16;
1789 /* IF it's OK to Use the "CD BOOT" Flash Buffer, then you can */
1790 /* avoid allocating a huge buffer per adapter ( which can fail ). */
1791 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1792 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1793 pt->BasicStatus = 0;
1794 return ips_flash_bios(ha, pt, scb);
1795 } else if (pt->CoppCP.cmd.flashfw.packet_num == 0) {
1796 if (ips_FlashData && !test_and_set_bit(0, &ips_FlashDataInUse)){
1797 ha->flash_data = ips_FlashData;
1798 ha->flash_busaddr = ips_flashbusaddr;
1799 ha->flash_len = PAGE_SIZE << 7;
1800 ha->flash_datasize = 0;
1801 } else if (!ha->flash_data) {
1802 datasize = pt->CoppCP.cmd.flashfw.total_packets *
1803 pt->CoppCP.cmd.flashfw.count;
1804 ha->flash_data = pci_alloc_consistent(ha->pcidev,
1806 &ha->flash_busaddr);
1807 if (!ha->flash_data){
1808 printk(KERN_WARNING "Unable to allocate a flash buffer\n");
1811 ha->flash_datasize = 0;
1812 ha->flash_len = datasize;
1816 if (pt->CoppCP.cmd.flashfw.count + ha->flash_datasize >
1818 ips_free_flash_copperhead(ha);
1819 IPS_PRINTK(KERN_WARNING, ha->pcidev,
1820 "failed size sanity check\n");
1824 if (!ha->flash_data)
1826 pt->BasicStatus = 0;
1827 memcpy(&ha->flash_data[ha->flash_datasize], pt + 1,
1828 pt->CoppCP.cmd.flashfw.count);
1829 ha->flash_datasize += pt->CoppCP.cmd.flashfw.count;
1830 if (pt->CoppCP.cmd.flashfw.packet_num ==
1831 pt->CoppCP.cmd.flashfw.total_packets - 1) {
1832 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE)
1833 return ips_flash_bios(ha, pt, scb);
1834 else if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE)
1835 return ips_flash_firmware(ha, pt, scb);
1837 return IPS_SUCCESS_IMM;
1840 /****************************************************************************/
1841 /* Routine Name: ips_flash_bios */
1842 /* Routine Description: */
1843 /* flashes the bios of a copperhead adapter */
1844 /****************************************************************************/
1846 ips_flash_bios(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1849 if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1850 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_BIOS) {
1851 if ((!ha->func.programbios) || (!ha->func.erasebios) ||
1852 (!ha->func.verifybios))
1854 if ((*ha->func.erasebios) (ha)) {
1856 "(%s%d) flash bios failed - unable to erase flash",
1857 ips_name, ha->host_num);
1860 if ((*ha->func.programbios) (ha,
1863 ha->flash_datasize -
1864 IPS_BIOS_HEADER, 0)) {
1866 "(%s%d) flash bios failed - unable to flash",
1867 ips_name, ha->host_num);
1870 if ((*ha->func.verifybios) (ha,
1873 ha->flash_datasize -
1874 IPS_BIOS_HEADER, 0)) {
1876 "(%s%d) flash bios failed - unable to verify flash",
1877 ips_name, ha->host_num);
1880 ips_free_flash_copperhead(ha);
1881 return IPS_SUCCESS_IMM;
1882 } else if (pt->CoppCP.cmd.flashfw.type == IPS_BIOS_IMAGE &&
1883 pt->CoppCP.cmd.flashfw.direction == IPS_ERASE_BIOS) {
1884 if (!ha->func.erasebios)
1886 if ((*ha->func.erasebios) (ha)) {
1888 "(%s%d) flash bios failed - unable to erase flash",
1889 ips_name, ha->host_num);
1892 return IPS_SUCCESS_IMM;
1895 pt->BasicStatus = 0x0B;
1896 pt->ExtendedStatus = 0x00;
1897 ips_free_flash_copperhead(ha);
1901 /****************************************************************************/
1903 /* Routine Name: ips_fill_scb_sg_single */
1905 /* Routine Description: */
1906 /* Fill in a single scb sg_list element from an address */
1907 /* return a -1 if a breakup occurred */
1908 /****************************************************************************/
1910 ips_fill_scb_sg_single(ips_ha_t * ha, dma_addr_t busaddr,
1911 ips_scb_t * scb, int indx, unsigned int e_len)
1916 if ((scb->data_len + e_len) > ha->max_xfer) {
1917 e_len = ha->max_xfer - scb->data_len;
1918 scb->breakup = indx;
1925 if (IPS_USE_ENH_SGLIST(ha)) {
1926 scb->sg_list.enh_list[indx].address_lo =
1927 cpu_to_le32(pci_dma_lo32(busaddr));
1928 scb->sg_list.enh_list[indx].address_hi =
1929 cpu_to_le32(pci_dma_hi32(busaddr));
1930 scb->sg_list.enh_list[indx].length = cpu_to_le32(e_len);
1932 scb->sg_list.std_list[indx].address =
1933 cpu_to_le32(pci_dma_lo32(busaddr));
1934 scb->sg_list.std_list[indx].length = cpu_to_le32(e_len);
1938 scb->data_len += e_len;
1942 /****************************************************************************/
1943 /* Routine Name: ips_flash_firmware */
1944 /* Routine Description: */
1945 /* flashes the firmware of a copperhead adapter */
1946 /****************************************************************************/
1948 ips_flash_firmware(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
1950 IPS_SG_LIST sg_list;
1951 uint32_t cmd_busaddr;
1953 if (pt->CoppCP.cmd.flashfw.type == IPS_FW_IMAGE &&
1954 pt->CoppCP.cmd.flashfw.direction == IPS_WRITE_FW) {
1955 memset(&pt->CoppCP.cmd, 0, sizeof (IPS_HOST_COMMAND));
1956 pt->CoppCP.cmd.flashfw.op_code = IPS_CMD_DOWNLOAD;
1957 pt->CoppCP.cmd.flashfw.count = cpu_to_le32(ha->flash_datasize);
1959 pt->BasicStatus = 0x0B;
1960 pt->ExtendedStatus = 0x00;
1961 ips_free_flash_copperhead(ha);
1964 /* Save the S/G list pointer so it doesn't get clobbered */
1965 sg_list.list = scb->sg_list.list;
1966 cmd_busaddr = scb->scb_busaddr;
1967 /* copy in the CP */
1968 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
1969 /* FIX stuff that might be wrong */
1970 scb->sg_list.list = sg_list.list;
1971 scb->scb_busaddr = cmd_busaddr;
1972 scb->bus = scb->scsi_cmd->device->channel;
1973 scb->target_id = scb->scsi_cmd->device->id;
1974 scb->lun = scb->scsi_cmd->device->lun;
1979 scb->callback = ipsintr_done;
1980 scb->timeout = ips_cmd_timeout;
1982 scb->data_len = ha->flash_datasize;
1984 pci_map_single(ha->pcidev, ha->flash_data, scb->data_len,
1986 scb->flags |= IPS_SCB_MAP_SINGLE;
1987 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
1988 scb->cmd.flashfw.buffer_addr = cpu_to_le32(scb->data_busaddr);
1990 scb->timeout = pt->TimeOut;
1991 scb->scsi_cmd->result = DID_OK << 16;
1995 /****************************************************************************/
1996 /* Routine Name: ips_free_flash_copperhead */
1997 /* Routine Description: */
1998 /* release the memory resources used to hold the flash image */
1999 /****************************************************************************/
2001 ips_free_flash_copperhead(ips_ha_t * ha)
2003 if (ha->flash_data == ips_FlashData)
2004 test_and_clear_bit(0, &ips_FlashDataInUse);
2005 else if (ha->flash_data)
2006 pci_free_consistent(ha->pcidev, ha->flash_len, ha->flash_data,
2008 ha->flash_data = NULL;
2011 /****************************************************************************/
2013 /* Routine Name: ips_usrcmd */
2015 /* Routine Description: */
2017 /* Process a user command and make it ready to send */
2019 /****************************************************************************/
2021 ips_usrcmd(ips_ha_t * ha, ips_passthru_t * pt, ips_scb_t * scb)
2023 IPS_SG_LIST sg_list;
2024 uint32_t cmd_busaddr;
2026 METHOD_TRACE("ips_usrcmd", 1);
2028 if ((!scb) || (!pt) || (!ha))
2031 /* Save the S/G list pointer so it doesn't get clobbered */
2032 sg_list.list = scb->sg_list.list;
2033 cmd_busaddr = scb->scb_busaddr;
2034 /* copy in the CP */
2035 memcpy(&scb->cmd, &pt->CoppCP.cmd, sizeof (IPS_IOCTL_CMD));
2036 memcpy(&scb->dcdb, &pt->CoppCP.dcdb, sizeof (IPS_DCDB_TABLE));
2038 /* FIX stuff that might be wrong */
2039 scb->sg_list.list = sg_list.list;
2040 scb->scb_busaddr = cmd_busaddr;
2041 scb->bus = scb->scsi_cmd->device->channel;
2042 scb->target_id = scb->scsi_cmd->device->id;
2043 scb->lun = scb->scsi_cmd->device->lun;
2048 scb->callback = ipsintr_done;
2049 scb->timeout = ips_cmd_timeout;
2050 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
2052 /* we don't support DCDB/READ/WRITE Scatter Gather */
2053 if ((scb->cmd.basic_io.op_code == IPS_CMD_READ_SG) ||
2054 (scb->cmd.basic_io.op_code == IPS_CMD_WRITE_SG) ||
2055 (scb->cmd.basic_io.op_code == IPS_CMD_DCDB_SG))
2059 scb->data_len = pt->CmdBSize;
2060 scb->data_busaddr = ha->ioctl_busaddr + sizeof (ips_passthru_t);
2062 scb->data_busaddr = 0L;
2065 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2066 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
2067 (unsigned long) &scb->
2069 (unsigned long) scb);
2072 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB)
2073 scb->dcdb.buffer_pointer =
2074 cpu_to_le32(scb->data_busaddr);
2076 scb->cmd.basic_io.sg_addr =
2077 cpu_to_le32(scb->data_busaddr);
2082 scb->timeout = pt->TimeOut;
2084 if (pt->TimeOut <= 10)
2085 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10;
2086 else if (pt->TimeOut <= 60)
2087 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60;
2089 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M;
2092 /* assume success */
2093 scb->scsi_cmd->result = DID_OK << 16;
2099 /****************************************************************************/
2101 /* Routine Name: ips_cleanup_passthru */
2103 /* Routine Description: */
2105 /* Cleanup after a passthru command */
2107 /****************************************************************************/
2109 ips_cleanup_passthru(ips_ha_t * ha, ips_scb_t * scb)
2113 METHOD_TRACE("ips_cleanup_passthru", 1);
2115 if ((!scb) || (!scb->scsi_cmd) || (!scb->scsi_cmd->request_buffer)) {
2116 DEBUG_VAR(1, "(%s%d) couldn't cleanup after passthru",
2117 ips_name, ha->host_num);
2121 pt = (ips_passthru_t *) ha->ioctl_data;
2123 /* Copy data back to the user */
2124 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB) /* Copy DCDB Back to Caller's Area */
2125 memcpy(&pt->CoppCP.dcdb, &scb->dcdb, sizeof (IPS_DCDB_TABLE));
2127 pt->BasicStatus = scb->basic_status;
2128 pt->ExtendedStatus = scb->extended_status;
2129 pt->AdapterType = ha->ad_type;
2131 if (ha->device_id == IPS_DEVICEID_COPPERHEAD &&
2132 (scb->cmd.flashfw.op_code == IPS_CMD_DOWNLOAD ||
2133 scb->cmd.flashfw.op_code == IPS_CMD_RW_BIOSFW))
2134 ips_free_flash_copperhead(ha);
2136 ips_scmd_buf_write(scb->scsi_cmd, ha->ioctl_data, ha->ioctl_datasize);
2139 /****************************************************************************/
2141 /* Routine Name: ips_host_info */
2143 /* Routine Description: */
2145 /* The passthru interface for the driver */
2147 /****************************************************************************/
2149 ips_host_info(ips_ha_t * ha, char *ptr, off_t offset, int len)
2153 METHOD_TRACE("ips_host_info", 1);
2157 info.offset = offset;
2161 copy_info(&info, "\nIBM ServeRAID General Information:\n\n");
2163 if ((le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) &&
2164 (le16_to_cpu(ha->nvram->adapter_type) != 0))
2165 copy_info(&info, "\tController Type : %s\n",
2166 ips_adapter_name[ha->ad_type - 1]);
2169 "\tController Type : Unknown\n");
2173 "\tIO region : 0x%lx (%d bytes)\n",
2174 ha->io_addr, ha->io_len);
2178 "\tMemory region : 0x%lx (%d bytes)\n",
2179 ha->mem_addr, ha->mem_len);
2181 "\tShared memory address : 0x%lx\n",
2185 copy_info(&info, "\tIRQ number : %d\n", ha->irq);
2187 /* For the Next 3 lines Check for Binary 0 at the end and don't include it if it's there. */
2188 /* That keeps everything happy for "text" operations on the proc file. */
2190 if (le32_to_cpu(ha->nvram->signature) == IPS_NVRAM_P5_SIG) {
2191 if (ha->nvram->bios_low[3] == 0) {
2193 "\tBIOS Version : %c%c%c%c%c%c%c\n",
2194 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2195 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2196 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2197 ha->nvram->bios_low[2]);
2201 "\tBIOS Version : %c%c%c%c%c%c%c%c\n",
2202 ha->nvram->bios_high[0], ha->nvram->bios_high[1],
2203 ha->nvram->bios_high[2], ha->nvram->bios_high[3],
2204 ha->nvram->bios_low[0], ha->nvram->bios_low[1],
2205 ha->nvram->bios_low[2], ha->nvram->bios_low[3]);
2210 if (ha->enq->CodeBlkVersion[7] == 0) {
2212 "\tFirmware Version : %c%c%c%c%c%c%c\n",
2213 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2214 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2215 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2216 ha->enq->CodeBlkVersion[6]);
2219 "\tFirmware Version : %c%c%c%c%c%c%c%c\n",
2220 ha->enq->CodeBlkVersion[0], ha->enq->CodeBlkVersion[1],
2221 ha->enq->CodeBlkVersion[2], ha->enq->CodeBlkVersion[3],
2222 ha->enq->CodeBlkVersion[4], ha->enq->CodeBlkVersion[5],
2223 ha->enq->CodeBlkVersion[6], ha->enq->CodeBlkVersion[7]);
2226 if (ha->enq->BootBlkVersion[7] == 0) {
2228 "\tBoot Block Version : %c%c%c%c%c%c%c\n",
2229 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2230 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2231 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2232 ha->enq->BootBlkVersion[6]);
2235 "\tBoot Block Version : %c%c%c%c%c%c%c%c\n",
2236 ha->enq->BootBlkVersion[0], ha->enq->BootBlkVersion[1],
2237 ha->enq->BootBlkVersion[2], ha->enq->BootBlkVersion[3],
2238 ha->enq->BootBlkVersion[4], ha->enq->BootBlkVersion[5],
2239 ha->enq->BootBlkVersion[6], ha->enq->BootBlkVersion[7]);
2242 copy_info(&info, "\tDriver Version : %s%s\n",
2243 IPS_VERSION_HIGH, IPS_VERSION_LOW);
2245 copy_info(&info, "\tDriver Build : %d\n",
2248 copy_info(&info, "\tMax Physical Devices : %d\n",
2249 ha->enq->ucMaxPhysicalDevices);
2250 copy_info(&info, "\tMax Active Commands : %d\n",
2252 copy_info(&info, "\tCurrent Queued Commands : %d\n",
2253 ha->scb_waitlist.count);
2254 copy_info(&info, "\tCurrent Active Commands : %d\n",
2255 ha->scb_activelist.count - ha->num_ioctl);
2256 copy_info(&info, "\tCurrent Queued PT Commands : %d\n",
2257 ha->copp_waitlist.count);
2258 copy_info(&info, "\tCurrent Active PT Commands : %d\n",
2261 copy_info(&info, "\n");
2263 return (info.localpos);
2266 /****************************************************************************/
2268 /* Routine Name: copy_mem_info */
2270 /* Routine Description: */
2272 /* Copy data into an IPS_INFOSTR structure */
2274 /****************************************************************************/
2276 copy_mem_info(IPS_INFOSTR * info, char *data, int len)
2278 METHOD_TRACE("copy_mem_info", 1);
2280 if (info->pos + len < info->offset) {
2285 if (info->pos < info->offset) {
2286 data += (info->offset - info->pos);
2287 len -= (info->offset - info->pos);
2288 info->pos += (info->offset - info->pos);
2291 if (info->localpos + len > info->length)
2292 len = info->length - info->localpos;
2295 memcpy(info->buffer + info->localpos, data, len);
2297 info->localpos += len;
2301 /****************************************************************************/
2303 /* Routine Name: copy_info */
2305 /* Routine Description: */
2307 /* printf style wrapper for an info structure */
2309 /****************************************************************************/
2311 copy_info(IPS_INFOSTR * info, char *fmt, ...)
2317 METHOD_TRACE("copy_info", 1);
2319 va_start(args, fmt);
2320 len = vsprintf(buf, fmt, args);
2323 copy_mem_info(info, buf, len);
2328 /****************************************************************************/
2330 /* Routine Name: ips_identify_controller */
2332 /* Routine Description: */
2334 /* Identify this controller */
2336 /****************************************************************************/
2338 ips_identify_controller(ips_ha_t * ha)
2340 METHOD_TRACE("ips_identify_controller", 1);
2342 switch (ha->device_id) {
2343 case IPS_DEVICEID_COPPERHEAD:
2344 if (ha->revision_id <= IPS_REVID_SERVERAID) {
2345 ha->ad_type = IPS_ADTYPE_SERVERAID;
2346 } else if (ha->revision_id == IPS_REVID_SERVERAID2) {
2347 ha->ad_type = IPS_ADTYPE_SERVERAID2;
2348 } else if (ha->revision_id == IPS_REVID_NAVAJO) {
2349 ha->ad_type = IPS_ADTYPE_NAVAJO;
2350 } else if ((ha->revision_id == IPS_REVID_SERVERAID2)
2351 && (ha->slot_num == 0)) {
2352 ha->ad_type = IPS_ADTYPE_KIOWA;
2353 } else if ((ha->revision_id >= IPS_REVID_CLARINETP1) &&
2354 (ha->revision_id <= IPS_REVID_CLARINETP3)) {
2355 if (ha->enq->ucMaxPhysicalDevices == 15)
2356 ha->ad_type = IPS_ADTYPE_SERVERAID3L;
2358 ha->ad_type = IPS_ADTYPE_SERVERAID3;
2359 } else if ((ha->revision_id >= IPS_REVID_TROMBONE32) &&
2360 (ha->revision_id <= IPS_REVID_TROMBONE64)) {
2361 ha->ad_type = IPS_ADTYPE_SERVERAID4H;
2365 case IPS_DEVICEID_MORPHEUS:
2366 switch (ha->subdevice_id) {
2367 case IPS_SUBDEVICEID_4L:
2368 ha->ad_type = IPS_ADTYPE_SERVERAID4L;
2371 case IPS_SUBDEVICEID_4M:
2372 ha->ad_type = IPS_ADTYPE_SERVERAID4M;
2375 case IPS_SUBDEVICEID_4MX:
2376 ha->ad_type = IPS_ADTYPE_SERVERAID4MX;
2379 case IPS_SUBDEVICEID_4LX:
2380 ha->ad_type = IPS_ADTYPE_SERVERAID4LX;
2383 case IPS_SUBDEVICEID_5I2:
2384 ha->ad_type = IPS_ADTYPE_SERVERAID5I2;
2387 case IPS_SUBDEVICEID_5I1:
2388 ha->ad_type = IPS_ADTYPE_SERVERAID5I1;
2394 case IPS_DEVICEID_MARCO:
2395 switch (ha->subdevice_id) {
2396 case IPS_SUBDEVICEID_6M:
2397 ha->ad_type = IPS_ADTYPE_SERVERAID6M;
2399 case IPS_SUBDEVICEID_6I:
2400 ha->ad_type = IPS_ADTYPE_SERVERAID6I;
2402 case IPS_SUBDEVICEID_7k:
2403 ha->ad_type = IPS_ADTYPE_SERVERAID7k;
2405 case IPS_SUBDEVICEID_7M:
2406 ha->ad_type = IPS_ADTYPE_SERVERAID7M;
2413 /****************************************************************************/
2415 /* Routine Name: ips_get_bios_version */
2417 /* Routine Description: */
2419 /* Get the BIOS revision number */
2421 /****************************************************************************/
2423 ips_get_bios_version(ips_ha_t * ha, int intr)
2432 { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C',
2435 METHOD_TRACE("ips_get_bios_version", 1);
2440 strncpy(ha->bios_version, " ?", 8);
2442 if (ha->device_id == IPS_DEVICEID_COPPERHEAD) {
2443 if (IPS_USE_MEMIO(ha)) {
2444 /* Memory Mapped I/O */
2447 writel(0, ha->mem_ptr + IPS_REG_FLAP);
2448 if (ha->revision_id == IPS_REVID_TROMBONE64)
2449 udelay(25); /* 25 us */
2451 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
2454 writel(1, ha->mem_ptr + IPS_REG_FLAP);
2455 if (ha->revision_id == IPS_REVID_TROMBONE64)
2456 udelay(25); /* 25 us */
2458 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
2461 /* Get Major version */
2462 writel(0x1FF, ha->mem_ptr + IPS_REG_FLAP);
2463 if (ha->revision_id == IPS_REVID_TROMBONE64)
2464 udelay(25); /* 25 us */
2466 major = readb(ha->mem_ptr + IPS_REG_FLDP);
2468 /* Get Minor version */
2469 writel(0x1FE, ha->mem_ptr + IPS_REG_FLAP);
2470 if (ha->revision_id == IPS_REVID_TROMBONE64)
2471 udelay(25); /* 25 us */
2472 minor = readb(ha->mem_ptr + IPS_REG_FLDP);
2474 /* Get SubMinor version */
2475 writel(0x1FD, ha->mem_ptr + IPS_REG_FLAP);
2476 if (ha->revision_id == IPS_REVID_TROMBONE64)
2477 udelay(25); /* 25 us */
2478 subminor = readb(ha->mem_ptr + IPS_REG_FLDP);
2481 /* Programmed I/O */
2484 outl(0, ha->io_addr + IPS_REG_FLAP);
2485 if (ha->revision_id == IPS_REVID_TROMBONE64)
2486 udelay(25); /* 25 us */
2488 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
2491 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
2492 if (ha->revision_id == IPS_REVID_TROMBONE64)
2493 udelay(25); /* 25 us */
2495 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
2498 /* Get Major version */
2499 outl(cpu_to_le32(0x1FF), ha->io_addr + IPS_REG_FLAP);
2500 if (ha->revision_id == IPS_REVID_TROMBONE64)
2501 udelay(25); /* 25 us */
2503 major = inb(ha->io_addr + IPS_REG_FLDP);
2505 /* Get Minor version */
2506 outl(cpu_to_le32(0x1FE), ha->io_addr + IPS_REG_FLAP);
2507 if (ha->revision_id == IPS_REVID_TROMBONE64)
2508 udelay(25); /* 25 us */
2510 minor = inb(ha->io_addr + IPS_REG_FLDP);
2512 /* Get SubMinor version */
2513 outl(cpu_to_le32(0x1FD), ha->io_addr + IPS_REG_FLAP);
2514 if (ha->revision_id == IPS_REVID_TROMBONE64)
2515 udelay(25); /* 25 us */
2517 subminor = inb(ha->io_addr + IPS_REG_FLDP);
2521 /* Morpheus Family - Send Command to the card */
2523 buffer = ha->ioctl_data;
2525 memset(buffer, 0, 0x1000);
2527 scb = &ha->scbs[ha->max_cmds - 1];
2529 ips_init_scb(ha, scb);
2531 scb->timeout = ips_cmd_timeout;
2532 scb->cdb[0] = IPS_CMD_RW_BIOSFW;
2534 scb->cmd.flashfw.op_code = IPS_CMD_RW_BIOSFW;
2535 scb->cmd.flashfw.command_id = IPS_COMMAND_ID(ha, scb);
2536 scb->cmd.flashfw.type = 1;
2537 scb->cmd.flashfw.direction = 0;
2538 scb->cmd.flashfw.count = cpu_to_le32(0x800);
2539 scb->cmd.flashfw.total_packets = 1;
2540 scb->cmd.flashfw.packet_num = 0;
2541 scb->data_len = 0x1000;
2542 scb->cmd.flashfw.buffer_addr = ha->ioctl_busaddr;
2544 /* issue the command */
2546 ips_send_wait(ha, scb, ips_cmd_timeout,
2547 intr)) == IPS_FAILURE)
2548 || (ret == IPS_SUCCESS_IMM)
2549 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
2550 /* Error occurred */
2555 if ((buffer[0xC0] == 0x55) && (buffer[0xC1] == 0xAA)) {
2556 major = buffer[0x1ff + 0xC0]; /* Offset 0x1ff after the header (0xc0) */
2557 minor = buffer[0x1fe + 0xC0]; /* Offset 0x1fe after the header (0xc0) */
2558 subminor = buffer[0x1fd + 0xC0]; /* Offset 0x1fd after the header (0xc0) */
2564 ha->bios_version[0] = hexDigits[(major & 0xF0) >> 4];
2565 ha->bios_version[1] = '.';
2566 ha->bios_version[2] = hexDigits[major & 0x0F];
2567 ha->bios_version[3] = hexDigits[subminor];
2568 ha->bios_version[4] = '.';
2569 ha->bios_version[5] = hexDigits[(minor & 0xF0) >> 4];
2570 ha->bios_version[6] = hexDigits[minor & 0x0F];
2571 ha->bios_version[7] = 0;
2574 /****************************************************************************/
2576 /* Routine Name: ips_hainit */
2578 /* Routine Description: */
2580 /* Initialize the controller */
2582 /* NOTE: Assumes to be called from with a lock */
2584 /****************************************************************************/
2586 ips_hainit(ips_ha_t * ha)
2591 METHOD_TRACE("ips_hainit", 1);
2596 if (ha->func.statinit)
2597 (*ha->func.statinit) (ha);
2599 if (ha->func.enableint)
2600 (*ha->func.enableint) (ha);
2603 ha->reset_count = 1;
2604 do_gettimeofday(&tv);
2605 ha->last_ffdc = tv.tv_sec;
2606 ips_ffdc_reset(ha, IPS_INTR_IORL);
2608 if (!ips_read_config(ha, IPS_INTR_IORL)) {
2609 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2610 "unable to read config from controller.\n");
2615 if (!ips_read_adapter_status(ha, IPS_INTR_IORL)) {
2616 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2617 "unable to read controller status.\n");
2622 /* Identify this controller */
2623 ips_identify_controller(ha);
2625 if (!ips_read_subsystem_parameters(ha, IPS_INTR_IORL)) {
2626 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2627 "unable to read subsystem parameters.\n");
2632 /* write nvram user page 5 */
2633 if (!ips_write_driver_status(ha, IPS_INTR_IORL)) {
2634 IPS_PRINTK(KERN_WARNING, ha->pcidev,
2635 "unable to write driver info to controller.\n");
2640 /* If there are Logical Drives and a Reset Occurred, then an EraseStripeLock is Needed */
2641 if ((ha->conf->ucLogDriveCount > 0) && (ha->requires_esl == 1))
2642 ips_clear_adapter(ha, IPS_INTR_IORL);
2644 /* set limits on SID, LUN, BUS */
2645 ha->ntargets = IPS_MAX_TARGETS + 1;
2647 ha->nbus = (ha->enq->ucMaxPhysicalDevices / IPS_MAX_TARGETS) + 1;
2649 switch (ha->conf->logical_drive[0].ucStripeSize) {
2651 ha->max_xfer = 0x10000;
2655 ha->max_xfer = 0x20000;
2659 ha->max_xfer = 0x40000;
2664 ha->max_xfer = 0x80000;
2668 /* setup max concurrent commands */
2669 if (le32_to_cpu(ha->subsys->param[4]) & 0x1) {
2670 /* Use the new method */
2671 ha->max_cmds = ha->enq->ucConcurrentCmdCount;
2673 /* use the old method */
2674 switch (ha->conf->logical_drive[0].ucStripeSize) {
2694 /* Limit the Active Commands on a Lite Adapter */
2695 if ((ha->ad_type == IPS_ADTYPE_SERVERAID3L) ||
2696 (ha->ad_type == IPS_ADTYPE_SERVERAID4L) ||
2697 (ha->ad_type == IPS_ADTYPE_SERVERAID4LX)) {
2698 if ((ha->max_cmds > MaxLiteCmds) && (MaxLiteCmds))
2699 ha->max_cmds = MaxLiteCmds;
2702 /* set controller IDs */
2703 ha->ha_id[0] = IPS_ADAPTER_ID;
2704 for (i = 1; i < ha->nbus; i++) {
2705 ha->ha_id[i] = ha->conf->init_id[i - 1] & 0x1f;
2706 ha->dcdb_active[i - 1] = 0;
2712 /****************************************************************************/
2714 /* Routine Name: ips_next */
2716 /* Routine Description: */
2718 /* Take the next command off the queue and send it to the controller */
2720 /****************************************************************************/
2722 ips_next(ips_ha_t * ha, int intr)
2728 ips_copp_wait_item_t *item;
2730 unsigned long cpu_flags = 0;
2731 struct Scsi_Host *host;
2732 METHOD_TRACE("ips_next", 1);
2736 host = ips_sh[ha->host_num];
2738 * Block access to the queue function so
2739 * this command won't time out
2741 if (intr == IPS_INTR_ON)
2742 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2744 if ((ha->subsys->param[3] & 0x300000)
2745 && (ha->scb_activelist.count == 0)) {
2748 do_gettimeofday(&tv);
2750 if (tv.tv_sec - ha->last_ffdc > IPS_SECS_8HOURS) {
2751 ha->last_ffdc = tv.tv_sec;
2757 * Send passthru commands
2758 * These have priority over normal I/O
2759 * but shouldn't affect performance too much
2760 * since we limit the number that can be active
2761 * on the card at any one time
2763 while ((ha->num_ioctl < IPS_MAX_IOCTL) &&
2764 (ha->copp_waitlist.head) && (scb = ips_getscb(ha))) {
2766 item = ips_removeq_copp_head(&ha->copp_waitlist);
2768 if (intr == IPS_INTR_ON)
2769 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2770 scb->scsi_cmd = item->scsi_cmd;
2773 ret = ips_make_passthru(ha, scb->scsi_cmd, scb, intr);
2775 if (intr == IPS_INTR_ON)
2776 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2779 if (scb->scsi_cmd) {
2780 scb->scsi_cmd->result = DID_ERROR << 16;
2781 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2784 ips_freescb(ha, scb);
2786 case IPS_SUCCESS_IMM:
2787 if (scb->scsi_cmd) {
2788 scb->scsi_cmd->result = DID_OK << 16;
2789 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2792 ips_freescb(ha, scb);
2798 if (ret != IPS_SUCCESS) {
2803 ret = ips_send_cmd(ha, scb);
2805 if (ret == IPS_SUCCESS)
2806 ips_putq_scb_head(&ha->scb_activelist, scb);
2812 if (scb->scsi_cmd) {
2813 scb->scsi_cmd->result = DID_ERROR << 16;
2816 ips_freescb(ha, scb);
2818 case IPS_SUCCESS_IMM:
2819 ips_freescb(ha, scb);
2828 * Send "Normal" I/O commands
2831 p = ha->scb_waitlist.head;
2832 while ((p) && (scb = ips_getscb(ha))) {
2833 if ((p->device->channel > 0)
2835 dcdb_active[p->device->channel -
2836 1] & (1 << p->device->id))) {
2837 ips_freescb(ha, scb);
2838 p = (Scsi_Cmnd *) p->host_scribble;
2843 SC = ips_removeq_wait(&ha->scb_waitlist, q);
2845 if (intr == IPS_INTR_ON)
2846 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags); /* Unlock HA after command is taken off queue */
2848 SC->result = DID_OK;
2849 SC->host_scribble = NULL;
2851 memset(SC->sense_buffer, 0, sizeof (SC->sense_buffer));
2853 scb->target_id = SC->device->id;
2854 scb->lun = SC->device->lun;
2855 scb->bus = SC->device->channel;
2859 scb->callback = ipsintr_done;
2860 scb->timeout = ips_cmd_timeout;
2861 memset(&scb->cmd, 0, 16);
2863 /* copy in the CDB */
2864 memcpy(scb->cdb, SC->cmnd, SC->cmd_len);
2866 /* Now handle the data buffer */
2868 struct scatterlist *sg;
2871 sg = SC->request_buffer;
2872 scb->sg_count = pci_map_sg(ha->pcidev, sg, SC->use_sg,
2873 SC->sc_data_direction);
2874 scb->flags |= IPS_SCB_MAP_SG;
2875 for (i = 0; i < scb->sg_count; i++) {
2876 if (ips_fill_scb_sg_single
2877 (ha, sg_dma_address(&sg[i]), scb, i,
2878 sg_dma_len(&sg[i])) < 0)
2881 scb->dcdb.transfer_length = scb->data_len;
2883 if (SC->request_bufflen) {
2885 pci_map_single(ha->pcidev,
2887 SC->request_bufflen,
2888 SC->sc_data_direction);
2889 scb->flags |= IPS_SCB_MAP_SINGLE;
2890 ips_fill_scb_sg_single(ha, scb->data_busaddr,
2892 SC->request_bufflen);
2893 scb->dcdb.transfer_length = scb->data_len;
2895 scb->data_busaddr = 0L;
2898 scb->dcdb.transfer_length = 0;
2903 scb->dcdb.cmd_attribute =
2904 ips_command_direction[scb->scsi_cmd->cmnd[0]];
2906 /* Allow a WRITE BUFFER Command to Have no Data */
2907 /* This is Used by Tape Flash Utilites */
2908 if ((scb->scsi_cmd->cmnd[0] == WRITE_BUFFER) && (scb->data_len == 0))
2909 scb->dcdb.cmd_attribute = 0;
2911 if (!(scb->dcdb.cmd_attribute & 0x3))
2912 scb->dcdb.transfer_length = 0;
2914 if (scb->data_len >= IPS_MAX_XFER) {
2915 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
2916 scb->dcdb.transfer_length = 0;
2918 if (intr == IPS_INTR_ON)
2919 IPS_LOCK_SAVE(host->host_lock, cpu_flags);
2921 ret = ips_send_cmd(ha, scb);
2925 ips_putq_scb_head(&ha->scb_activelist, scb);
2928 if (scb->scsi_cmd) {
2929 scb->scsi_cmd->result = DID_ERROR << 16;
2930 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);
2939 case IPS_SUCCESS_IMM:
2941 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
2944 ha->dcdb_active[scb->bus - 1] &=
2945 ~(1 << scb->target_id);
2947 ips_freescb(ha, scb);
2953 p = (Scsi_Cmnd *) p->host_scribble;
2957 if (intr == IPS_INTR_ON)
2958 IPS_UNLOCK_RESTORE(host->host_lock, cpu_flags);
2961 /****************************************************************************/
2963 /* Routine Name: ips_putq_scb_head */
2965 /* Routine Description: */
2967 /* Add an item to the head of the queue */
2969 /* ASSUMED to be called from within the HA lock */
2971 /****************************************************************************/
2973 ips_putq_scb_head(ips_scb_queue_t * queue, ips_scb_t * item)
2975 METHOD_TRACE("ips_putq_scb_head", 1);
2980 item->q_next = queue->head;
2989 /****************************************************************************/
2991 /* Routine Name: ips_removeq_scb_head */
2993 /* Routine Description: */
2995 /* Remove the head of the queue */
2997 /* ASSUMED to be called from within the HA lock */
2999 /****************************************************************************/
3001 ips_removeq_scb_head(ips_scb_queue_t * queue)
3005 METHOD_TRACE("ips_removeq_scb_head", 1);
3013 queue->head = item->q_next;
3014 item->q_next = NULL;
3016 if (queue->tail == item)
3024 /****************************************************************************/
3026 /* Routine Name: ips_removeq_scb */
3028 /* Routine Description: */
3030 /* Remove an item from a queue */
3032 /* ASSUMED to be called from within the HA lock */
3034 /****************************************************************************/
3036 ips_removeq_scb(ips_scb_queue_t * queue, ips_scb_t * item)
3040 METHOD_TRACE("ips_removeq_scb", 1);
3045 if (item == queue->head) {
3046 return (ips_removeq_scb_head(queue));
3051 while ((p) && (item != p->q_next))
3056 p->q_next = item->q_next;
3061 item->q_next = NULL;
3070 /****************************************************************************/
3072 /* Routine Name: ips_putq_wait_tail */
3074 /* Routine Description: */
3076 /* Add an item to the tail of the queue */
3078 /* ASSUMED to be called from within the HA lock */
3080 /****************************************************************************/
3082 ips_putq_wait_tail(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3084 METHOD_TRACE("ips_putq_wait_tail", 1);
3089 item->host_scribble = NULL;
3092 queue->tail->host_scribble = (char *) item;
3102 /****************************************************************************/
3104 /* Routine Name: ips_removeq_wait_head */
3106 /* Routine Description: */
3108 /* Remove the head of the queue */
3110 /* ASSUMED to be called from within the HA lock */
3112 /****************************************************************************/
3114 ips_removeq_wait_head(ips_wait_queue_t * queue)
3118 METHOD_TRACE("ips_removeq_wait_head", 1);
3126 queue->head = (Scsi_Cmnd *) item->host_scribble;
3127 item->host_scribble = NULL;
3129 if (queue->tail == item)
3137 /****************************************************************************/
3139 /* Routine Name: ips_removeq_wait */
3141 /* Routine Description: */
3143 /* Remove an item from a queue */
3145 /* ASSUMED to be called from within the HA lock */
3147 /****************************************************************************/
3149 ips_removeq_wait(ips_wait_queue_t * queue, Scsi_Cmnd * item)
3153 METHOD_TRACE("ips_removeq_wait", 1);
3158 if (item == queue->head) {
3159 return (ips_removeq_wait_head(queue));
3164 while ((p) && (item != (Scsi_Cmnd *) p->host_scribble))
3165 p = (Scsi_Cmnd *) p->host_scribble;
3169 p->host_scribble = item->host_scribble;
3171 if (!item->host_scribble)
3174 item->host_scribble = NULL;
3183 /****************************************************************************/
3185 /* Routine Name: ips_putq_copp_tail */
3187 /* Routine Description: */
3189 /* Add an item to the tail of the queue */
3191 /* ASSUMED to be called from within the HA lock */
3193 /****************************************************************************/
3195 ips_putq_copp_tail(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3197 METHOD_TRACE("ips_putq_copp_tail", 1);
3205 queue->tail->next = item;
3215 /****************************************************************************/
3217 /* Routine Name: ips_removeq_copp_head */
3219 /* Routine Description: */
3221 /* Remove the head of the queue */
3223 /* ASSUMED to be called from within the HA lock */
3225 /****************************************************************************/
3226 static ips_copp_wait_item_t *
3227 ips_removeq_copp_head(ips_copp_queue_t * queue)
3229 ips_copp_wait_item_t *item;
3231 METHOD_TRACE("ips_removeq_copp_head", 1);
3239 queue->head = item->next;
3242 if (queue->tail == item)
3250 /****************************************************************************/
3252 /* Routine Name: ips_removeq_copp */
3254 /* Routine Description: */
3256 /* Remove an item from a queue */
3258 /* ASSUMED to be called from within the HA lock */
3260 /****************************************************************************/
3261 static ips_copp_wait_item_t *
3262 ips_removeq_copp(ips_copp_queue_t * queue, ips_copp_wait_item_t * item)
3264 ips_copp_wait_item_t *p;
3266 METHOD_TRACE("ips_removeq_copp", 1);
3271 if (item == queue->head) {
3272 return (ips_removeq_copp_head(queue));
3277 while ((p) && (item != p->next))
3282 p->next = item->next;
3296 /****************************************************************************/
3298 /* Routine Name: ipsintr_blocking */
3300 /* Routine Description: */
3302 /* Finalize an interrupt for internal commands */
3304 /****************************************************************************/
3306 ipsintr_blocking(ips_ha_t * ha, ips_scb_t * scb)
3308 METHOD_TRACE("ipsintr_blocking", 2);
3310 ips_freescb(ha, scb);
3311 if ((ha->waitflag == TRUE) && (ha->cmd_in_progress == scb->cdb[0])) {
3312 ha->waitflag = FALSE;
3318 /****************************************************************************/
3320 /* Routine Name: ipsintr_done */
3322 /* Routine Description: */
3324 /* Finalize an interrupt for non-internal commands */
3326 /****************************************************************************/
3328 ipsintr_done(ips_ha_t * ha, ips_scb_t * scb)
3330 METHOD_TRACE("ipsintr_done", 2);
3333 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3334 "Spurious interrupt; scb NULL.\n");
3339 if (scb->scsi_cmd == NULL) {
3340 /* unexpected interrupt */
3341 IPS_PRINTK(KERN_WARNING, ha->pcidev,
3342 "Spurious interrupt; scsi_cmd not set.\n");
3350 /****************************************************************************/
3352 /* Routine Name: ips_done */
3354 /* Routine Description: */
3356 /* Do housekeeping on completed commands */
3357 /* ASSUMED to be called form within the request lock */
3358 /****************************************************************************/
3360 ips_done(ips_ha_t * ha, ips_scb_t * scb)
3364 METHOD_TRACE("ips_done", 1);
3369 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd))) {
3370 ips_cleanup_passthru(ha, scb);
3374 * Check to see if this command had too much
3375 * data and had to be broke up. If so, queue
3376 * the rest of the data and continue.
3378 if ((scb->breakup) || (scb->sg_break)) {
3379 /* we had a data breakup */
3382 if (scb->sg_count) {
3384 struct scatterlist *sg;
3385 int ips_sg_index = 0;
3388 sg = scb->scsi_cmd->request_buffer;
3390 /* Spin forward to last dma chunk */
3391 sg_dma_index = scb->breakup;
3393 /* Take care of possible partial on last chunk */
3394 ips_fill_scb_sg_single(ha,
3397 scb, ips_sg_index++,
3401 for (; sg_dma_index < scb->sg_count;
3403 if (ips_fill_scb_sg_single
3405 sg_dma_address(&sg[sg_dma_index]),
3406 scb, ips_sg_index++,
3407 sg_dma_len(&sg[sg_dma_index])) < 0)
3413 /* Non S/G Request */
3414 (void) ips_fill_scb_sg_single(ha,
3426 scb->dcdb.transfer_length = scb->data_len;
3427 scb->dcdb.cmd_attribute |=
3428 ips_command_direction[scb->scsi_cmd->cmnd[0]];
3430 if (!(scb->dcdb.cmd_attribute & 0x3))
3431 scb->dcdb.transfer_length = 0;
3433 if (scb->data_len >= IPS_MAX_XFER) {
3434 scb->dcdb.cmd_attribute |= IPS_TRANSFER64K;
3435 scb->dcdb.transfer_length = 0;
3438 ret = ips_send_cmd(ha, scb);
3442 if (scb->scsi_cmd) {
3443 scb->scsi_cmd->result = DID_ERROR << 16;
3444 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3447 ips_freescb(ha, scb);
3449 case IPS_SUCCESS_IMM:
3450 if (scb->scsi_cmd) {
3451 scb->scsi_cmd->result = DID_ERROR << 16;
3452 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3455 ips_freescb(ha, scb);
3463 } /* end if passthru */
3466 ha->dcdb_active[scb->bus - 1] &= ~(1 << scb->target_id);
3469 scb->scsi_cmd->scsi_done(scb->scsi_cmd);
3471 ips_freescb(ha, scb);
3474 /****************************************************************************/
3476 /* Routine Name: ips_map_status */
3478 /* Routine Description: */
3480 /* Map Controller Error codes to Linux Error Codes */
3482 /****************************************************************************/
3484 ips_map_status(ips_ha_t * ha, ips_scb_t * scb, ips_stat_t * sp)
3488 uint32_t transfer_len;
3489 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3491 METHOD_TRACE("ips_map_status", 1);
3495 "(%s%d) Physical device error (%d %d %d): %x %x, Sense Key: %x, ASC: %x, ASCQ: %x",
3496 ips_name, ha->host_num,
3497 scb->scsi_cmd->device->channel,
3498 scb->scsi_cmd->device->id, scb->scsi_cmd->device->lun,
3499 scb->basic_status, scb->extended_status,
3500 scb->extended_status ==
3501 IPS_ERR_CKCOND ? scb->dcdb.sense_info[2] & 0xf : 0,
3502 scb->extended_status ==
3503 IPS_ERR_CKCOND ? scb->dcdb.sense_info[12] : 0,
3504 scb->extended_status ==
3505 IPS_ERR_CKCOND ? scb->dcdb.sense_info[13] : 0);
3508 /* default driver error */
3509 errcode = DID_ERROR;
3512 switch (scb->basic_status & IPS_GSC_STATUS_MASK) {
3513 case IPS_CMD_TIMEOUT:
3514 errcode = DID_TIME_OUT;
3517 case IPS_INVAL_OPCO:
3518 case IPS_INVAL_CMD_BLK:
3519 case IPS_INVAL_PARM_BLK:
3521 case IPS_CMD_CMPLT_WERROR:
3524 case IPS_PHYS_DRV_ERROR:
3525 switch (scb->extended_status) {
3526 case IPS_ERR_SEL_TO:
3528 errcode = DID_NO_CONNECT;
3532 case IPS_ERR_OU_RUN:
3533 if ((scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB) ||
3534 (scb->cmd.dcdb.op_code ==
3535 IPS_CMD_EXTENDED_DCDB_SG)) {
3536 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3537 transfer_len = tapeDCDB->transfer_length;
3540 (uint32_t) scb->dcdb.transfer_length;
3543 if ((scb->bus) && (transfer_len < scb->data_len)) {
3544 /* Underrun - set default to no error */
3547 /* Restrict access to physical DASD */
3548 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
3549 ((((char *) scb->scsi_cmd->
3550 buffer)[0] & 0x1f) == TYPE_DISK)) {
3551 /* underflow -- no error */
3552 /* restrict access to physical DASD */
3553 errcode = DID_TIME_OUT;
3557 errcode = DID_ERROR;
3561 case IPS_ERR_RECOVERY:
3562 /* don't fail recovered errors */
3568 case IPS_ERR_HOST_RESET:
3569 case IPS_ERR_DEV_RESET:
3570 errcode = DID_RESET;
3573 case IPS_ERR_CKCOND:
3575 if ((scb->cmd.dcdb.op_code ==
3576 IPS_CMD_EXTENDED_DCDB)
3577 || (scb->cmd.dcdb.op_code ==
3578 IPS_CMD_EXTENDED_DCDB_SG)) {
3580 (IPS_DCDB_TABLE_TAPE *) & scb->dcdb;
3581 memcpy(scb->scsi_cmd->sense_buffer,
3582 tapeDCDB->sense_info,
3583 sizeof (scb->scsi_cmd->
3586 memcpy(scb->scsi_cmd->sense_buffer,
3587 scb->dcdb.sense_info,
3588 sizeof (scb->scsi_cmd->
3591 device_error = 2; /* check condition */
3599 errcode = DID_ERROR;
3605 scb->scsi_cmd->result = device_error | (errcode << 16);
3610 /****************************************************************************/
3612 /* Routine Name: ips_send_wait */
3614 /* Routine Description: */
3616 /* Send a command to the controller and wait for it to return */
3618 /* The FFDC Time Stamp use this function for the callback, but doesn't */
3619 /* actually need to wait. */
3620 /****************************************************************************/
3622 ips_send_wait(ips_ha_t * ha, ips_scb_t * scb, int timeout, int intr)
3626 METHOD_TRACE("ips_send_wait", 1);
3628 if (intr != IPS_FFDC) { /* Won't be Waiting if this is a Time Stamp */
3629 ha->waitflag = TRUE;
3630 ha->cmd_in_progress = scb->cdb[0];
3632 scb->callback = ipsintr_blocking;
3633 ret = ips_send_cmd(ha, scb);
3635 if ((ret == IPS_FAILURE) || (ret == IPS_SUCCESS_IMM))
3638 if (intr != IPS_FFDC) /* Don't Wait around if this is a Time Stamp */
3639 ret = ips_wait(ha, timeout, intr);
3644 /****************************************************************************/
3646 /* Routine Name: ips_scmd_buf_write */
3648 /* Routine Description: */
3649 /* Write data to Scsi_Cmnd request_buffer at proper offsets */
3650 /****************************************************************************/
3652 ips_scmd_buf_write(Scsi_Cmnd * scmd, void *data, unsigned
3657 unsigned int min_cnt, xfer_cnt;
3658 char *cdata = (char *) data;
3659 struct scatterlist *sg = scmd->request_buffer;
3660 for (i = 0, xfer_cnt = 0;
3661 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3662 if (!IPS_SG_ADDRESS(&sg[i]))
3664 min_cnt = min(count - xfer_cnt, sg[i].length);
3665 memcpy(IPS_SG_ADDRESS(&sg[i]), &cdata[xfer_cnt],
3667 xfer_cnt += min_cnt;
3671 unsigned int min_cnt = min(count, scmd->request_bufflen);
3672 memcpy(scmd->request_buffer, data, min_cnt);
3676 /****************************************************************************/
3678 /* Routine Name: ips_scmd_buf_read */
3680 /* Routine Description: */
3681 /* Copy data from a Scsi_Cmnd to a new, linear buffer */
3682 /****************************************************************************/
3684 ips_scmd_buf_read(Scsi_Cmnd * scmd, void *data, unsigned
3689 unsigned int min_cnt, xfer_cnt;
3690 char *cdata = (char *) data;
3691 struct scatterlist *sg = scmd->request_buffer;
3692 for (i = 0, xfer_cnt = 0;
3693 (i < scmd->use_sg) && (xfer_cnt < count); i++) {
3694 if (!IPS_SG_ADDRESS(&sg[i]))
3696 min_cnt = min(count - xfer_cnt, sg[i].length);
3697 memcpy(&cdata[xfer_cnt], IPS_SG_ADDRESS(&sg[i]),
3699 xfer_cnt += min_cnt;
3703 unsigned int min_cnt = min(count, scmd->request_bufflen);
3704 memcpy(data, scmd->request_buffer, min_cnt);
3708 /****************************************************************************/
3710 /* Routine Name: ips_send_cmd */
3712 /* Routine Description: */
3714 /* Map SCSI commands to ServeRAID commands for logical drives */
3716 /****************************************************************************/
3718 ips_send_cmd(ips_ha_t * ha, ips_scb_t * scb)
3723 IPS_DCDB_TABLE_TAPE *tapeDCDB;
3726 METHOD_TRACE("ips_send_cmd", 1);
3730 if (!scb->scsi_cmd) {
3731 /* internal command */
3734 /* Controller commands can't be issued */
3735 /* to real devices -- fail them */
3736 if ((ha->waitflag == TRUE) &&
3737 (ha->cmd_in_progress == scb->cdb[0])) {
3738 ha->waitflag = FALSE;
3743 } else if ((scb->bus == 0) && (!ips_is_passthru(scb->scsi_cmd))) {
3744 /* command to logical bus -- interpret */
3745 ret = IPS_SUCCESS_IMM;
3747 switch (scb->scsi_cmd->cmnd[0]) {
3748 case ALLOW_MEDIUM_REMOVAL:
3751 case WRITE_FILEMARKS:
3753 scb->scsi_cmd->result = DID_ERROR << 16;
3757 scb->scsi_cmd->result = DID_OK << 16;
3759 case TEST_UNIT_READY:
3761 if (scb->target_id == IPS_ADAPTER_ID) {
3763 * Either we have a TUR
3764 * or we have a SCSI inquiry
3766 if (scb->scsi_cmd->cmnd[0] == TEST_UNIT_READY)
3767 scb->scsi_cmd->result = DID_OK << 16;
3769 if (scb->scsi_cmd->cmnd[0] == INQUIRY) {
3770 IPS_SCSI_INQ_DATA inquiry;
3773 sizeof (IPS_SCSI_INQ_DATA));
3775 inquiry.DeviceType =
3776 IPS_SCSI_INQ_TYPE_PROCESSOR;
3777 inquiry.DeviceTypeQualifier =
3778 IPS_SCSI_INQ_LU_CONNECTED;
3779 inquiry.Version = IPS_SCSI_INQ_REV2;
3780 inquiry.ResponseDataFormat =
3781 IPS_SCSI_INQ_RD_REV2;
3782 inquiry.AdditionalLength = 31;
3784 IPS_SCSI_INQ_Address16;
3786 IPS_SCSI_INQ_WBus16 |
3788 strncpy(inquiry.VendorId, "IBM ",
3790 strncpy(inquiry.ProductId,
3792 strncpy(inquiry.ProductRevisionLevel,
3795 ips_scmd_buf_write(scb->scsi_cmd,
3799 scb->scsi_cmd->result = DID_OK << 16;
3802 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3803 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3804 scb->cmd.logical_info.reserved = 0;
3805 scb->cmd.logical_info.reserved2 = 0;
3806 scb->data_len = sizeof (IPS_LD_INFO);
3807 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3809 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3816 ips_reqsen(ha, scb);
3817 scb->scsi_cmd->result = DID_OK << 16;
3823 scb->cmd.basic_io.op_code =
3824 (scb->scsi_cmd->cmnd[0] ==
3825 READ_6) ? IPS_CMD_READ : IPS_CMD_WRITE;
3826 scb->cmd.basic_io.enhanced_sg = 0;
3827 scb->cmd.basic_io.sg_addr =
3828 cpu_to_le32(scb->data_busaddr);
3830 scb->cmd.basic_io.op_code =
3831 (scb->scsi_cmd->cmnd[0] ==
3832 READ_6) ? IPS_CMD_READ_SG :
3834 scb->cmd.basic_io.enhanced_sg =
3835 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3836 scb->cmd.basic_io.sg_addr =
3837 cpu_to_le32(scb->sg_busaddr);
3840 scb->cmd.basic_io.segment_4G = 0;
3841 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3842 scb->cmd.basic_io.log_drv = scb->target_id;
3843 scb->cmd.basic_io.sg_count = scb->sg_len;
3845 if (scb->cmd.basic_io.lba)
3846 scb->cmd.basic_io.lba =
3847 cpu_to_le32(le32_to_cpu
3848 (scb->cmd.basic_io.lba) +
3849 le16_to_cpu(scb->cmd.basic_io.
3852 scb->cmd.basic_io.lba =
3854 cmnd[1] & 0x1f) << 16) | (scb->scsi_cmd->
3856 (scb->scsi_cmd->cmnd[3]));
3858 scb->cmd.basic_io.sector_count =
3859 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3861 if (le16_to_cpu(scb->cmd.basic_io.sector_count) == 0)
3862 scb->cmd.basic_io.sector_count =
3871 scb->cmd.basic_io.op_code =
3872 (scb->scsi_cmd->cmnd[0] ==
3873 READ_10) ? IPS_CMD_READ : IPS_CMD_WRITE;
3874 scb->cmd.basic_io.enhanced_sg = 0;
3875 scb->cmd.basic_io.sg_addr =
3876 cpu_to_le32(scb->data_busaddr);
3878 scb->cmd.basic_io.op_code =
3879 (scb->scsi_cmd->cmnd[0] ==
3880 READ_10) ? IPS_CMD_READ_SG :
3882 scb->cmd.basic_io.enhanced_sg =
3883 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
3884 scb->cmd.basic_io.sg_addr =
3885 cpu_to_le32(scb->sg_busaddr);
3888 scb->cmd.basic_io.segment_4G = 0;
3889 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3890 scb->cmd.basic_io.log_drv = scb->target_id;
3891 scb->cmd.basic_io.sg_count = scb->sg_len;
3893 if (scb->cmd.basic_io.lba)
3894 scb->cmd.basic_io.lba =
3895 cpu_to_le32(le32_to_cpu
3896 (scb->cmd.basic_io.lba) +
3897 le16_to_cpu(scb->cmd.basic_io.
3900 scb->cmd.basic_io.lba =
3901 ((scb->scsi_cmd->cmnd[2] << 24) | (scb->
3905 (scb->scsi_cmd->cmnd[4] << 8) | scb->
3908 scb->cmd.basic_io.sector_count =
3909 cpu_to_le16(scb->data_len / IPS_BLKSIZE);
3911 if (cpu_to_le16(scb->cmd.basic_io.sector_count) == 0) {
3913 * This is a null condition
3914 * we don't have to do anything
3917 scb->scsi_cmd->result = DID_OK << 16;
3925 scb->scsi_cmd->result = DID_OK << 16;
3929 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
3930 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
3931 scb->cmd.basic_io.segment_4G = 0;
3932 scb->cmd.basic_io.enhanced_sg = 0;
3933 scb->data_len = sizeof (*ha->enq);
3934 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
3939 scb->cmd.logical_info.op_code = IPS_CMD_GET_LD_INFO;
3940 scb->cmd.logical_info.command_id = IPS_COMMAND_ID(ha, scb);
3941 scb->cmd.logical_info.reserved = 0;
3942 scb->cmd.logical_info.reserved2 = 0;
3943 scb->cmd.logical_info.reserved3 = 0;
3944 scb->data_len = sizeof (IPS_LD_INFO);
3945 scb->data_busaddr = ha->logical_drive_info_dma_addr;
3947 scb->cmd.logical_info.buffer_addr = scb->data_busaddr;
3951 case SEND_DIAGNOSTIC:
3952 case REASSIGN_BLOCKS:
3956 case READ_DEFECT_DATA:
3959 scb->scsi_cmd->result = DID_OK << 16;
3963 /* Set the Return Info to appear like the Command was */
3964 /* attempted, a Check Condition occurred, and Sense */
3965 /* Data indicating an Invalid CDB OpCode is returned. */
3966 sp = (char *) scb->scsi_cmd->sense_buffer;
3967 memset(sp, 0, sizeof (scb->scsi_cmd->sense_buffer));
3969 sp[0] = 0x70; /* Error Code */
3970 sp[2] = ILLEGAL_REQUEST; /* Sense Key 5 Illegal Req. */
3971 sp[7] = 0x0A; /* Additional Sense Length */
3972 sp[12] = 0x20; /* ASC = Invalid OpCode */
3973 sp[13] = 0x00; /* ASCQ */
3975 device_error = 2; /* Indicate Check Condition */
3976 scb->scsi_cmd->result = device_error | (DID_OK << 16);
3981 if (ret == IPS_SUCCESS_IMM)
3987 /* If we already know the Device is Not there, no need to attempt a Command */
3988 /* This also protects an NT FailOver Controller from getting CDB's sent to it */
3989 if (ha->conf->dev[scb->bus - 1][scb->target_id].ucState == 0) {
3990 scb->scsi_cmd->result = DID_NO_CONNECT << 16;
3991 return (IPS_SUCCESS_IMM);
3994 ha->dcdb_active[scb->bus - 1] |= (1 << scb->target_id);
3995 scb->cmd.dcdb.command_id = IPS_COMMAND_ID(ha, scb);
3996 scb->cmd.dcdb.dcdb_address = cpu_to_le32(scb->scb_busaddr +
3997 (unsigned long) &scb->
3999 (unsigned long) scb);
4000 scb->cmd.dcdb.reserved = 0;
4001 scb->cmd.dcdb.reserved2 = 0;
4002 scb->cmd.dcdb.reserved3 = 0;
4003 scb->cmd.dcdb.segment_4G = 0;
4004 scb->cmd.dcdb.enhanced_sg = 0;
4006 TimeOut = scb->scsi_cmd->timeout_per_command;
4008 if (ha->subsys->param[4] & 0x00100000) { /* If NEW Tape DCDB is Supported */
4010 scb->cmd.dcdb.op_code = IPS_CMD_EXTENDED_DCDB;
4012 scb->cmd.dcdb.op_code =
4013 IPS_CMD_EXTENDED_DCDB_SG;
4014 scb->cmd.dcdb.enhanced_sg =
4015 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4018 tapeDCDB = (IPS_DCDB_TABLE_TAPE *) & scb->dcdb; /* Use Same Data Area as Old DCDB Struct */
4019 tapeDCDB->device_address =
4020 ((scb->bus - 1) << 4) | scb->target_id;
4021 tapeDCDB->cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4022 tapeDCDB->cmd_attribute &= ~IPS_TRANSFER64K; /* Always Turn OFF 64K Size Flag */
4025 if (TimeOut < (10 * HZ))
4026 tapeDCDB->cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4027 else if (TimeOut < (60 * HZ))
4028 tapeDCDB->cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4029 else if (TimeOut < (1200 * HZ))
4030 tapeDCDB->cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4033 tapeDCDB->cdb_length = scb->scsi_cmd->cmd_len;
4034 tapeDCDB->reserved_for_LUN = 0;
4035 tapeDCDB->transfer_length = scb->data_len;
4036 if (scb->cmd.dcdb.op_code == IPS_CMD_EXTENDED_DCDB_SG)
4037 tapeDCDB->buffer_pointer =
4038 cpu_to_le32(scb->sg_busaddr);
4040 tapeDCDB->buffer_pointer =
4041 cpu_to_le32(scb->data_busaddr);
4042 tapeDCDB->sg_count = scb->sg_len;
4043 tapeDCDB->sense_length = sizeof (tapeDCDB->sense_info);
4044 tapeDCDB->scsi_status = 0;
4045 tapeDCDB->reserved = 0;
4046 memcpy(tapeDCDB->scsi_cdb, scb->scsi_cmd->cmnd,
4047 scb->scsi_cmd->cmd_len);
4050 scb->cmd.dcdb.op_code = IPS_CMD_DCDB;
4052 scb->cmd.dcdb.op_code = IPS_CMD_DCDB_SG;
4053 scb->cmd.dcdb.enhanced_sg =
4054 IPS_USE_ENH_SGLIST(ha) ? 0xFF : 0;
4057 scb->dcdb.device_address =
4058 ((scb->bus - 1) << 4) | scb->target_id;
4059 scb->dcdb.cmd_attribute |= IPS_DISCONNECT_ALLOWED;
4062 if (TimeOut < (10 * HZ))
4063 scb->dcdb.cmd_attribute |= IPS_TIMEOUT10; /* TimeOut is 10 Seconds */
4064 else if (TimeOut < (60 * HZ))
4065 scb->dcdb.cmd_attribute |= IPS_TIMEOUT60; /* TimeOut is 60 Seconds */
4066 else if (TimeOut < (1200 * HZ))
4067 scb->dcdb.cmd_attribute |= IPS_TIMEOUT20M; /* TimeOut is 20 Minutes */
4070 scb->dcdb.transfer_length = scb->data_len;
4071 if (scb->dcdb.cmd_attribute & IPS_TRANSFER64K)
4072 scb->dcdb.transfer_length = 0;
4073 if (scb->cmd.dcdb.op_code == IPS_CMD_DCDB_SG)
4074 scb->dcdb.buffer_pointer =
4075 cpu_to_le32(scb->sg_busaddr);
4077 scb->dcdb.buffer_pointer =
4078 cpu_to_le32(scb->data_busaddr);
4079 scb->dcdb.cdb_length = scb->scsi_cmd->cmd_len;
4080 scb->dcdb.sense_length = sizeof (scb->dcdb.sense_info);
4081 scb->dcdb.sg_count = scb->sg_len;
4082 scb->dcdb.reserved = 0;
4083 memcpy(scb->dcdb.scsi_cdb, scb->scsi_cmd->cmnd,
4084 scb->scsi_cmd->cmd_len);
4085 scb->dcdb.scsi_status = 0;
4086 scb->dcdb.reserved2[0] = 0;
4087 scb->dcdb.reserved2[1] = 0;
4088 scb->dcdb.reserved2[2] = 0;
4092 return ((*ha->func.issue) (ha, scb));
4095 /****************************************************************************/
4097 /* Routine Name: ips_chk_status */
4099 /* Routine Description: */
4101 /* Check the status of commands to logical drives */
4102 /* Assumed to be called with the HA lock */
4103 /****************************************************************************/
4105 ips_chkstatus(ips_ha_t * ha, IPS_STATUS * pstatus)
4109 uint8_t basic_status;
4113 METHOD_TRACE("ips_chkstatus", 1);
4115 scb = &ha->scbs[pstatus->fields.command_id];
4116 scb->basic_status = basic_status =
4117 pstatus->fields.basic_status & IPS_BASIC_STATUS_MASK;
4118 scb->extended_status = ext_status = pstatus->fields.extended_status;
4121 sp->residue_len = 0;
4122 sp->scb_addr = (void *) scb;
4124 /* Remove the item from the active queue */
4125 ips_removeq_scb(&ha->scb_activelist, scb);
4128 /* internal commands are handled in do_ipsintr */
4131 DEBUG_VAR(2, "(%s%d) ips_chkstatus: cmd 0x%X id %d (%d %d %d)",
4135 scb->cmd.basic_io.command_id,
4136 scb->bus, scb->target_id, scb->lun);
4138 if ((scb->scsi_cmd) && (ips_is_passthru(scb->scsi_cmd)))
4139 /* passthru - just returns the raw result */
4144 if (((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_SUCCESS) ||
4145 ((basic_status & IPS_GSC_STATUS_MASK) == IPS_CMD_RECOVERED_ERROR)) {
4147 if (scb->bus == 0) {
4148 if ((basic_status & IPS_GSC_STATUS_MASK) ==
4149 IPS_CMD_RECOVERED_ERROR) {
4151 "(%s%d) Recovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4152 ips_name, ha->host_num,
4153 scb->cmd.basic_io.op_code,
4154 basic_status, ext_status);
4157 switch (scb->scsi_cmd->cmnd[0]) {
4158 case ALLOW_MEDIUM_REMOVAL:
4161 case WRITE_FILEMARKS:
4163 errcode = DID_ERROR;
4169 case TEST_UNIT_READY:
4170 if (!ips_online(ha, scb)) {
4171 errcode = DID_TIME_OUT;
4176 if (ips_online(ha, scb)) {
4177 ips_inquiry(ha, scb);
4179 errcode = DID_TIME_OUT;
4184 ips_reqsen(ha, scb);
4196 if (!ips_online(ha, scb)
4197 || !ips_msense(ha, scb)) {
4198 errcode = DID_ERROR;
4203 if (ips_online(ha, scb))
4206 errcode = DID_TIME_OUT;
4210 case SEND_DIAGNOSTIC:
4211 case REASSIGN_BLOCKS:
4215 errcode = DID_ERROR;
4220 case READ_DEFECT_DATA:
4226 errcode = DID_ERROR;
4229 scb->scsi_cmd->result = errcode << 16;
4230 } else { /* bus == 0 */
4231 /* restrict access to physical drives */
4232 if ((scb->scsi_cmd->cmnd[0] == INQUIRY) &&
4233 ((((char *) scb->scsi_cmd->buffer)[0] & 0x1f) ==
4236 scb->scsi_cmd->result = DID_TIME_OUT << 16;
4239 } else { /* recovered error / success */
4240 if (scb->bus == 0) {
4242 "(%s%d) Unrecovered Logical Drive Error OpCode: %x, BSB: %x, ESB: %x",
4243 ips_name, ha->host_num,
4244 scb->cmd.basic_io.op_code, basic_status,
4248 ips_map_status(ha, scb, sp);
4252 /****************************************************************************/
4254 /* Routine Name: ips_online */
4256 /* Routine Description: */
4258 /* Determine if a logical drive is online */
4260 /****************************************************************************/
4262 ips_online(ips_ha_t * ha, ips_scb_t * scb)
4264 METHOD_TRACE("ips_online", 1);
4266 if (scb->target_id >= IPS_MAX_LD)
4269 if ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1) {
4270 memset(ha->logical_drive_info, 0, sizeof (IPS_LD_INFO));
4274 if (ha->logical_drive_info->drive_info[scb->target_id].state !=
4276 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4278 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4280 && ha->logical_drive_info->drive_info[scb->target_id].state !=
4287 /****************************************************************************/
4289 /* Routine Name: ips_inquiry */
4291 /* Routine Description: */
4293 /* Simulate an inquiry command to a logical drive */
4295 /****************************************************************************/
4297 ips_inquiry(ips_ha_t * ha, ips_scb_t * scb)
4299 IPS_SCSI_INQ_DATA inquiry;
4301 METHOD_TRACE("ips_inquiry", 1);
4303 memset(&inquiry, 0, sizeof (IPS_SCSI_INQ_DATA));
4305 inquiry.DeviceType = IPS_SCSI_INQ_TYPE_DASD;
4306 inquiry.DeviceTypeQualifier = IPS_SCSI_INQ_LU_CONNECTED;
4307 inquiry.Version = IPS_SCSI_INQ_REV2;
4308 inquiry.ResponseDataFormat = IPS_SCSI_INQ_RD_REV2;
4309 inquiry.AdditionalLength = 31;
4310 inquiry.Flags[0] = IPS_SCSI_INQ_Address16;
4312 IPS_SCSI_INQ_WBus16 | IPS_SCSI_INQ_Sync | IPS_SCSI_INQ_CmdQue;
4313 strncpy(inquiry.VendorId, "IBM ", 8);
4314 strncpy(inquiry.ProductId, "SERVERAID ", 16);
4315 strncpy(inquiry.ProductRevisionLevel, "1.00", 4);
4317 ips_scmd_buf_write(scb->scsi_cmd, &inquiry, sizeof (inquiry));
4322 /****************************************************************************/
4324 /* Routine Name: ips_rdcap */
4326 /* Routine Description: */
4328 /* Simulate a read capacity command to a logical drive */
4330 /****************************************************************************/
4332 ips_rdcap(ips_ha_t * ha, ips_scb_t * scb)
4334 IPS_SCSI_CAPACITY cap;
4336 METHOD_TRACE("ips_rdcap", 1);
4338 if (scb->scsi_cmd->bufflen < 8)
4342 cpu_to_be32(le32_to_cpu
4343 (ha->logical_drive_info->
4344 drive_info[scb->target_id].sector_count) - 1);
4345 cap.len = cpu_to_be32((uint32_t) IPS_BLKSIZE);
4347 ips_scmd_buf_write(scb->scsi_cmd, &cap, sizeof (cap));
4352 /****************************************************************************/
4354 /* Routine Name: ips_msense */
4356 /* Routine Description: */
4358 /* Simulate a mode sense command to a logical drive */
4360 /****************************************************************************/
4362 ips_msense(ips_ha_t * ha, ips_scb_t * scb)
4367 IPS_SCSI_MODE_PAGE_DATA mdata;
4369 METHOD_TRACE("ips_msense", 1);
4371 if (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) > 0x400000 &&
4372 (ha->enq->ucMiscFlag & 0x8) == 0) {
4373 heads = IPS_NORM_HEADS;
4374 sectors = IPS_NORM_SECTORS;
4376 heads = IPS_COMP_HEADS;
4377 sectors = IPS_COMP_SECTORS;
4381 (le32_to_cpu(ha->enq->ulDriveSize[scb->target_id]) -
4382 1) / (heads * sectors);
4384 memset(&mdata, 0, sizeof (IPS_SCSI_MODE_PAGE_DATA));
4386 mdata.hdr.BlockDescLength = 8;
4388 switch (scb->scsi_cmd->cmnd[2] & 0x3f) {
4389 case 0x03: /* page 3 */
4390 mdata.pdata.pg3.PageCode = 3;
4391 mdata.pdata.pg3.PageLength = sizeof (IPS_SCSI_MODE_PAGE3);
4392 mdata.hdr.DataLength =
4393 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg3.PageLength;
4394 mdata.pdata.pg3.TracksPerZone = 0;
4395 mdata.pdata.pg3.AltSectorsPerZone = 0;
4396 mdata.pdata.pg3.AltTracksPerZone = 0;
4397 mdata.pdata.pg3.AltTracksPerVolume = 0;
4398 mdata.pdata.pg3.SectorsPerTrack = cpu_to_be16(sectors);
4399 mdata.pdata.pg3.BytesPerSector = cpu_to_be16(IPS_BLKSIZE);
4400 mdata.pdata.pg3.Interleave = cpu_to_be16(1);
4401 mdata.pdata.pg3.TrackSkew = 0;
4402 mdata.pdata.pg3.CylinderSkew = 0;
4403 mdata.pdata.pg3.flags = IPS_SCSI_MP3_SoftSector;
4407 mdata.pdata.pg4.PageCode = 4;
4408 mdata.pdata.pg4.PageLength = sizeof (IPS_SCSI_MODE_PAGE4);
4409 mdata.hdr.DataLength =
4410 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg4.PageLength;
4411 mdata.pdata.pg4.CylindersHigh =
4412 cpu_to_be16((cylinders >> 8) & 0xFFFF);
4413 mdata.pdata.pg4.CylindersLow = (cylinders & 0xFF);
4414 mdata.pdata.pg4.Heads = heads;
4415 mdata.pdata.pg4.WritePrecompHigh = 0;
4416 mdata.pdata.pg4.WritePrecompLow = 0;
4417 mdata.pdata.pg4.ReducedWriteCurrentHigh = 0;
4418 mdata.pdata.pg4.ReducedWriteCurrentLow = 0;
4419 mdata.pdata.pg4.StepRate = cpu_to_be16(1);
4420 mdata.pdata.pg4.LandingZoneHigh = 0;
4421 mdata.pdata.pg4.LandingZoneLow = 0;
4422 mdata.pdata.pg4.flags = 0;
4423 mdata.pdata.pg4.RotationalOffset = 0;
4424 mdata.pdata.pg4.MediumRotationRate = 0;
4427 mdata.pdata.pg8.PageCode = 8;
4428 mdata.pdata.pg8.PageLength = sizeof (IPS_SCSI_MODE_PAGE8);
4429 mdata.hdr.DataLength =
4430 3 + mdata.hdr.BlockDescLength + mdata.pdata.pg8.PageLength;
4431 /* everything else is left set to 0 */
4438 ips_scmd_buf_write(scb->scsi_cmd, &mdata, sizeof (mdata));
4443 /****************************************************************************/
4445 /* Routine Name: ips_reqsen */
4447 /* Routine Description: */
4449 /* Simulate a request sense command to a logical drive */
4451 /****************************************************************************/
4453 ips_reqsen(ips_ha_t * ha, ips_scb_t * scb)
4455 IPS_SCSI_REQSEN reqsen;
4457 METHOD_TRACE("ips_reqsen", 1);
4459 memset(&reqsen, 0, sizeof (IPS_SCSI_REQSEN));
4461 reqsen.ResponseCode =
4462 IPS_SCSI_REQSEN_VALID | IPS_SCSI_REQSEN_CURRENT_ERR;
4463 reqsen.AdditionalLength = 10;
4464 reqsen.AdditionalSenseCode = IPS_SCSI_REQSEN_NO_SENSE;
4465 reqsen.AdditionalSenseCodeQual = IPS_SCSI_REQSEN_NO_SENSE;
4467 ips_scmd_buf_write(scb->scsi_cmd, &reqsen, sizeof (reqsen));
4472 /****************************************************************************/
4474 /* Routine Name: ips_free */
4476 /* Routine Description: */
4478 /* Free any allocated space for this controller */
4480 /****************************************************************************/
4482 ips_free(ips_ha_t * ha)
4485 METHOD_TRACE("ips_free", 1);
4489 pci_free_consistent(ha->pcidev, sizeof(IPS_ENQ),
4490 ha->enq, ha->enq_busaddr);
4500 pci_free_consistent(ha->pcidev,
4501 sizeof (IPS_ADAPTER) +
4502 sizeof (IPS_IO_CMD), ha->adapt,
4503 ha->adapt->hw_status_start);
4507 if (ha->logical_drive_info) {
4508 pci_free_consistent(ha->pcidev,
4509 sizeof (IPS_LD_INFO),
4510 ha->logical_drive_info,
4511 ha->logical_drive_info_dma_addr);
4512 ha->logical_drive_info = NULL;
4525 if (ha->ioctl_data) {
4526 pci_free_consistent(ha->pcidev, ha->ioctl_len,
4527 ha->ioctl_data, ha->ioctl_busaddr);
4528 ha->ioctl_data = NULL;
4529 ha->ioctl_datasize = 0;
4532 ips_deallocatescbs(ha, ha->max_cmds);
4534 /* free memory mapped (if applicable) */
4536 iounmap(ha->ioremap_ptr);
4537 ha->ioremap_ptr = NULL;
4542 release_mem_region(ha->mem_addr, ha->mem_len);
4548 /****************************************************************************/
4550 /* Routine Name: ips_deallocatescbs */
4552 /* Routine Description: */
4554 /* Free the command blocks */
4556 /****************************************************************************/
4558 ips_deallocatescbs(ips_ha_t * ha, int cmds)
4561 pci_free_consistent(ha->pcidev,
4562 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * cmds,
4563 ha->scbs->sg_list.list,
4564 ha->scbs->sg_busaddr);
4565 pci_free_consistent(ha->pcidev, sizeof (ips_scb_t) * cmds,
4566 ha->scbs, ha->scbs->scb_busaddr);
4572 /****************************************************************************/
4574 /* Routine Name: ips_allocatescbs */
4576 /* Routine Description: */
4578 /* Allocate the command blocks */
4580 /****************************************************************************/
4582 ips_allocatescbs(ips_ha_t * ha)
4587 dma_addr_t command_dma, sg_dma;
4589 METHOD_TRACE("ips_allocatescbs", 1);
4591 /* Allocate memory for the SCBs */
4593 pci_alloc_consistent(ha->pcidev, ha->max_cmds * sizeof (ips_scb_t),
4595 if (ha->scbs == NULL)
4598 pci_alloc_consistent(ha->pcidev,
4599 IPS_SGLIST_SIZE(ha) * IPS_MAX_SG *
4600 ha->max_cmds, &sg_dma);
4601 if (ips_sg.list == NULL) {
4602 pci_free_consistent(ha->pcidev,
4603 ha->max_cmds * sizeof (ips_scb_t), ha->scbs,
4608 memset(ha->scbs, 0, ha->max_cmds * sizeof (ips_scb_t));
4610 for (i = 0; i < ha->max_cmds; i++) {
4611 scb_p = &ha->scbs[i];
4612 scb_p->scb_busaddr = command_dma + sizeof (ips_scb_t) * i;
4613 /* set up S/G list */
4614 if (IPS_USE_ENH_SGLIST(ha)) {
4615 scb_p->sg_list.enh_list =
4616 ips_sg.enh_list + i * IPS_MAX_SG;
4618 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4620 scb_p->sg_list.std_list =
4621 ips_sg.std_list + i * IPS_MAX_SG;
4623 sg_dma + IPS_SGLIST_SIZE(ha) * IPS_MAX_SG * i;
4626 /* add to the free list */
4627 if (i < ha->max_cmds - 1) {
4628 scb_p->q_next = ha->scb_freelist;
4629 ha->scb_freelist = scb_p;
4637 /****************************************************************************/
4639 /* Routine Name: ips_init_scb */
4641 /* Routine Description: */
4643 /* Initialize a CCB to default values */
4645 /****************************************************************************/
4647 ips_init_scb(ips_ha_t * ha, ips_scb_t * scb)
4649 IPS_SG_LIST sg_list;
4650 uint32_t cmd_busaddr, sg_busaddr;
4651 METHOD_TRACE("ips_init_scb", 1);
4656 sg_list.list = scb->sg_list.list;
4657 cmd_busaddr = scb->scb_busaddr;
4658 sg_busaddr = scb->sg_busaddr;
4660 memset(scb, 0, sizeof (ips_scb_t));
4661 memset(ha->dummy, 0, sizeof (IPS_IO_CMD));
4663 /* Initialize dummy command bucket */
4664 ha->dummy->op_code = 0xFF;
4665 ha->dummy->ccsar = cpu_to_le32(ha->adapt->hw_status_start
4666 + sizeof (IPS_ADAPTER));
4667 ha->dummy->command_id = IPS_MAX_CMDS;
4669 /* set bus address of scb */
4670 scb->scb_busaddr = cmd_busaddr;
4671 scb->sg_busaddr = sg_busaddr;
4672 scb->sg_list.list = sg_list.list;
4675 scb->cmd.basic_io.cccr = cpu_to_le32((uint32_t) IPS_BIT_ILE);
4676 scb->cmd.basic_io.ccsar = cpu_to_le32(ha->adapt->hw_status_start
4677 + sizeof (IPS_ADAPTER));
4680 /****************************************************************************/
4682 /* Routine Name: ips_get_scb */
4684 /* Routine Description: */
4686 /* Initialize a CCB to default values */
4688 /* ASSUMED to be callled from within a lock */
4690 /****************************************************************************/
4692 ips_getscb(ips_ha_t * ha)
4696 METHOD_TRACE("ips_getscb", 1);
4698 if ((scb = ha->scb_freelist) == NULL) {
4703 ha->scb_freelist = scb->q_next;
4707 ips_init_scb(ha, scb);
4712 /****************************************************************************/
4714 /* Routine Name: ips_free_scb */
4716 /* Routine Description: */
4718 /* Return an unused CCB back to the free list */
4720 /* ASSUMED to be called from within a lock */
4722 /****************************************************************************/
4724 ips_freescb(ips_ha_t * ha, ips_scb_t * scb)
4727 METHOD_TRACE("ips_freescb", 1);
4728 if (scb->flags & IPS_SCB_MAP_SG)
4729 pci_unmap_sg(ha->pcidev, scb->scsi_cmd->request_buffer,
4730 scb->scsi_cmd->use_sg, IPS_DMA_DIR(scb));
4731 else if (scb->flags & IPS_SCB_MAP_SINGLE)
4732 pci_unmap_single(ha->pcidev, scb->data_busaddr, scb->data_len,
4735 /* check to make sure this is not our "special" scb */
4736 if (IPS_COMMAND_ID(ha, scb) < (ha->max_cmds - 1)) {
4737 scb->q_next = ha->scb_freelist;
4738 ha->scb_freelist = scb;
4742 /****************************************************************************/
4744 /* Routine Name: ips_isinit_copperhead */
4746 /* Routine Description: */
4748 /* Is controller initialized ? */
4750 /****************************************************************************/
4752 ips_isinit_copperhead(ips_ha_t * ha)
4757 METHOD_TRACE("ips_isinit_copperhead", 1);
4759 isr = inb(ha->io_addr + IPS_REG_HISR);
4760 scpr = inb(ha->io_addr + IPS_REG_SCPR);
4762 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4768 /****************************************************************************/
4770 /* Routine Name: ips_isinit_copperhead_memio */
4772 /* Routine Description: */
4774 /* Is controller initialized ? */
4776 /****************************************************************************/
4778 ips_isinit_copperhead_memio(ips_ha_t * ha)
4783 METHOD_TRACE("ips_is_init_copperhead_memio", 1);
4785 isr = readb(ha->mem_ptr + IPS_REG_HISR);
4786 scpr = readb(ha->mem_ptr + IPS_REG_SCPR);
4788 if (((isr & IPS_BIT_EI) == 0) && ((scpr & IPS_BIT_EBM) == 0))
4794 /****************************************************************************/
4796 /* Routine Name: ips_isinit_morpheus */
4798 /* Routine Description: */
4800 /* Is controller initialized ? */
4802 /****************************************************************************/
4804 ips_isinit_morpheus(ips_ha_t * ha)
4809 METHOD_TRACE("ips_is_init_morpheus", 1);
4811 post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
4812 bits = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
4816 else if (bits & 0x3)
4822 /****************************************************************************/
4824 /* Routine Name: ips_enable_int_copperhead */
4826 /* Routine Description: */
4827 /* Turn on interrupts */
4829 /****************************************************************************/
4831 ips_enable_int_copperhead(ips_ha_t * ha)
4833 METHOD_TRACE("ips_enable_int_copperhead", 1);
4835 outb(ha->io_addr + IPS_REG_HISR, IPS_BIT_EI);
4836 inb(ha->io_addr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4839 /****************************************************************************/
4841 /* Routine Name: ips_enable_int_copperhead_memio */
4843 /* Routine Description: */
4844 /* Turn on interrupts */
4846 /****************************************************************************/
4848 ips_enable_int_copperhead_memio(ips_ha_t * ha)
4850 METHOD_TRACE("ips_enable_int_copperhead_memio", 1);
4852 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
4853 readb(ha->mem_ptr + IPS_REG_HISR); /*Ensure PCI Posting Completes*/
4856 /****************************************************************************/
4858 /* Routine Name: ips_enable_int_morpheus */
4860 /* Routine Description: */
4861 /* Turn on interrupts */
4863 /****************************************************************************/
4865 ips_enable_int_morpheus(ips_ha_t * ha)
4869 METHOD_TRACE("ips_enable_int_morpheus", 1);
4871 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
4873 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
4874 readl(ha->mem_ptr + IPS_REG_I960_OIMR); /*Ensure PCI Posting Completes*/
4877 /****************************************************************************/
4879 /* Routine Name: ips_init_copperhead */
4881 /* Routine Description: */
4883 /* Initialize a copperhead controller */
4885 /****************************************************************************/
4887 ips_init_copperhead(ips_ha_t * ha)
4891 uint8_t PostByte[IPS_MAX_POST_BYTES];
4892 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4895 METHOD_TRACE("ips_init_copperhead", 1);
4897 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4898 for (j = 0; j < 45; j++) {
4899 Isr = inb(ha->io_addr + IPS_REG_HISR);
4900 if (Isr & IPS_BIT_GHI)
4903 /* Delay for 1 Second */
4904 MDELAY(IPS_ONE_SEC);
4908 /* error occurred */
4911 PostByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4912 outb(Isr, ha->io_addr + IPS_REG_HISR);
4915 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
4916 IPS_PRINTK(KERN_WARNING, ha->pcidev,
4917 "reset controller fails (post status %x %x).\n",
4918 PostByte[0], PostByte[1]);
4923 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
4924 for (j = 0; j < 240; j++) {
4925 Isr = inb(ha->io_addr + IPS_REG_HISR);
4926 if (Isr & IPS_BIT_GHI)
4929 /* Delay for 1 Second */
4930 MDELAY(IPS_ONE_SEC);
4934 /* error occurred */
4937 ConfigByte[i] = inb(ha->io_addr + IPS_REG_ISPR);
4938 outb(Isr, ha->io_addr + IPS_REG_HISR);
4941 for (i = 0; i < 240; i++) {
4942 Cbsp = inb(ha->io_addr + IPS_REG_CBSP);
4944 if ((Cbsp & IPS_BIT_OP) == 0)
4947 /* Delay for 1 Second */
4948 MDELAY(IPS_ONE_SEC);
4956 outl(cpu_to_le32(0x1010), ha->io_addr + IPS_REG_CCCR);
4958 /* Enable busmastering */
4959 outb(IPS_BIT_EBM, ha->io_addr + IPS_REG_SCPR);
4961 if (ha->revision_id == IPS_REVID_TROMBONE64)
4962 /* fix for anaconda64 */
4963 outl(0, ha->io_addr + IPS_REG_NDAE);
4965 /* Enable interrupts */
4966 outb(IPS_BIT_EI, ha->io_addr + IPS_REG_HISR);
4971 /****************************************************************************/
4973 /* Routine Name: ips_init_copperhead_memio */
4975 /* Routine Description: */
4977 /* Initialize a copperhead controller with memory mapped I/O */
4979 /****************************************************************************/
4981 ips_init_copperhead_memio(ips_ha_t * ha)
4985 uint8_t PostByte[IPS_MAX_POST_BYTES];
4986 uint8_t ConfigByte[IPS_MAX_CONFIG_BYTES];
4989 METHOD_TRACE("ips_init_copperhead_memio", 1);
4991 for (i = 0; i < IPS_MAX_POST_BYTES; i++) {
4992 for (j = 0; j < 45; j++) {
4993 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
4994 if (Isr & IPS_BIT_GHI)
4997 /* Delay for 1 Second */
4998 MDELAY(IPS_ONE_SEC);
5002 /* error occurred */
5005 PostByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5006 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5009 if (PostByte[0] < IPS_GOOD_POST_STATUS) {
5010 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5011 "reset controller fails (post status %x %x).\n",
5012 PostByte[0], PostByte[1]);
5017 for (i = 0; i < IPS_MAX_CONFIG_BYTES; i++) {
5018 for (j = 0; j < 240; j++) {
5019 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5020 if (Isr & IPS_BIT_GHI)
5023 /* Delay for 1 Second */
5024 MDELAY(IPS_ONE_SEC);
5028 /* error occurred */
5031 ConfigByte[i] = readb(ha->mem_ptr + IPS_REG_ISPR);
5032 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5035 for (i = 0; i < 240; i++) {
5036 Cbsp = readb(ha->mem_ptr + IPS_REG_CBSP);
5038 if ((Cbsp & IPS_BIT_OP) == 0)
5041 /* Delay for 1 Second */
5042 MDELAY(IPS_ONE_SEC);
5046 /* error occurred */
5050 writel(0x1010, ha->mem_ptr + IPS_REG_CCCR);
5052 /* Enable busmastering */
5053 writeb(IPS_BIT_EBM, ha->mem_ptr + IPS_REG_SCPR);
5055 if (ha->revision_id == IPS_REVID_TROMBONE64)
5056 /* fix for anaconda64 */
5057 writel(0, ha->mem_ptr + IPS_REG_NDAE);
5059 /* Enable interrupts */
5060 writeb(IPS_BIT_EI, ha->mem_ptr + IPS_REG_HISR);
5062 /* if we get here then everything went OK */
5066 /****************************************************************************/
5068 /* Routine Name: ips_init_morpheus */
5070 /* Routine Description: */
5072 /* Initialize a morpheus controller */
5074 /****************************************************************************/
5076 ips_init_morpheus(ips_ha_t * ha)
5084 METHOD_TRACE("ips_init_morpheus", 1);
5086 /* Wait up to 45 secs for Post */
5087 for (i = 0; i < 45; i++) {
5088 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5090 if (Isr & IPS_BIT_I960_MSG0I)
5093 /* Delay for 1 Second */
5094 MDELAY(IPS_ONE_SEC);
5098 /* error occurred */
5099 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5100 "timeout waiting for post.\n");
5105 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5107 if (Post == 0x4F00) { /* If Flashing the Battery PIC */
5108 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5109 "Flashing Battery PIC, Please wait ...\n");
5111 /* Clear the interrupt bit */
5112 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5113 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5115 for (i = 0; i < 120; i++) { /* Wait Up to 2 Min. for Completion */
5116 Post = readl(ha->mem_ptr + IPS_REG_I960_MSG0);
5119 /* Delay for 1 Second */
5120 MDELAY(IPS_ONE_SEC);
5124 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5125 "timeout waiting for Battery PIC Flash\n");
5131 /* Clear the interrupt bit */
5132 Isr = (uint32_t) IPS_BIT_I960_MSG0I;
5133 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5135 if (Post < (IPS_GOOD_POST_STATUS << 8)) {
5136 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5137 "reset controller fails (post status %x).\n", Post);
5142 /* Wait up to 240 secs for config bytes */
5143 for (i = 0; i < 240; i++) {
5144 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5146 if (Isr & IPS_BIT_I960_MSG1I)
5149 /* Delay for 1 Second */
5150 MDELAY(IPS_ONE_SEC);
5154 /* error occurred */
5155 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5156 "timeout waiting for config.\n");
5161 Config = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
5163 /* Clear interrupt bit */
5164 Isr = (uint32_t) IPS_BIT_I960_MSG1I;
5165 writel(Isr, ha->mem_ptr + IPS_REG_I2O_HIR);
5167 /* Turn on the interrupts */
5168 Oimr = readl(ha->mem_ptr + IPS_REG_I960_OIMR);
5170 writel(Oimr, ha->mem_ptr + IPS_REG_I960_OIMR);
5172 /* if we get here then everything went OK */
5174 /* Since we did a RESET, an EraseStripeLock may be needed */
5175 if (Post == 0xEF10) {
5176 if ((Config == 0x000F) || (Config == 0x0009))
5177 ha->requires_esl = 1;
5183 /****************************************************************************/
5185 /* Routine Name: ips_reset_copperhead */
5187 /* Routine Description: */
5189 /* Reset the controller */
5191 /****************************************************************************/
5193 ips_reset_copperhead(ips_ha_t * ha)
5197 METHOD_TRACE("ips_reset_copperhead", 1);
5199 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead: io addr: %x, irq: %d",
5200 ips_name, ha->host_num, ha->io_addr, ha->irq);
5204 while (reset_counter < 2) {
5207 outb(IPS_BIT_RST, ha->io_addr + IPS_REG_SCPR);
5209 /* Delay for 1 Second */
5210 MDELAY(IPS_ONE_SEC);
5212 outb(0, ha->io_addr + IPS_REG_SCPR);
5214 /* Delay for 1 Second */
5215 MDELAY(IPS_ONE_SEC);
5217 if ((*ha->func.init) (ha))
5219 else if (reset_counter >= 2) {
5228 /****************************************************************************/
5230 /* Routine Name: ips_reset_copperhead_memio */
5232 /* Routine Description: */
5234 /* Reset the controller */
5236 /****************************************************************************/
5238 ips_reset_copperhead_memio(ips_ha_t * ha)
5242 METHOD_TRACE("ips_reset_copperhead_memio", 1);
5244 DEBUG_VAR(1, "(%s%d) ips_reset_copperhead_memio: mem addr: %x, irq: %d",
5245 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5249 while (reset_counter < 2) {
5252 writeb(IPS_BIT_RST, ha->mem_ptr + IPS_REG_SCPR);
5254 /* Delay for 1 Second */
5255 MDELAY(IPS_ONE_SEC);
5257 writeb(0, ha->mem_ptr + IPS_REG_SCPR);
5259 /* Delay for 1 Second */
5260 MDELAY(IPS_ONE_SEC);
5262 if ((*ha->func.init) (ha))
5264 else if (reset_counter >= 2) {
5273 /****************************************************************************/
5275 /* Routine Name: ips_reset_morpheus */
5277 /* Routine Description: */
5279 /* Reset the controller */
5281 /****************************************************************************/
5283 ips_reset_morpheus(ips_ha_t * ha)
5288 METHOD_TRACE("ips_reset_morpheus", 1);
5290 DEBUG_VAR(1, "(%s%d) ips_reset_morpheus: mem addr: %x, irq: %d",
5291 ips_name, ha->host_num, ha->mem_addr, ha->irq);
5295 while (reset_counter < 2) {
5298 writel(0x80000000, ha->mem_ptr + IPS_REG_I960_IDR);
5300 /* Delay for 5 Seconds */
5301 MDELAY(5 * IPS_ONE_SEC);
5303 /* Do a PCI config read to wait for adapter */
5304 pci_read_config_byte(ha->pcidev, 4, &junk);
5306 if ((*ha->func.init) (ha))
5308 else if (reset_counter >= 2) {
5317 /****************************************************************************/
5319 /* Routine Name: ips_statinit */
5321 /* Routine Description: */
5323 /* Initialize the status queues on the controller */
5325 /****************************************************************************/
5327 ips_statinit(ips_ha_t * ha)
5329 uint32_t phys_status_start;
5331 METHOD_TRACE("ips_statinit", 1);
5333 ha->adapt->p_status_start = ha->adapt->status;
5334 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5335 ha->adapt->p_status_tail = ha->adapt->status;
5337 phys_status_start = ha->adapt->hw_status_start;
5338 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQSR);
5339 outl(cpu_to_le32(phys_status_start + IPS_STATUS_Q_SIZE),
5340 ha->io_addr + IPS_REG_SQER);
5341 outl(cpu_to_le32(phys_status_start + IPS_STATUS_SIZE),
5342 ha->io_addr + IPS_REG_SQHR);
5343 outl(cpu_to_le32(phys_status_start), ha->io_addr + IPS_REG_SQTR);
5345 ha->adapt->hw_status_tail = phys_status_start;
5348 /****************************************************************************/
5350 /* Routine Name: ips_statinit_memio */
5352 /* Routine Description: */
5354 /* Initialize the status queues on the controller */
5356 /****************************************************************************/
5358 ips_statinit_memio(ips_ha_t * ha)
5360 uint32_t phys_status_start;
5362 METHOD_TRACE("ips_statinit_memio", 1);
5364 ha->adapt->p_status_start = ha->adapt->status;
5365 ha->adapt->p_status_end = ha->adapt->status + IPS_MAX_CMDS;
5366 ha->adapt->p_status_tail = ha->adapt->status;
5368 phys_status_start = ha->adapt->hw_status_start;
5369 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQSR);
5370 writel(phys_status_start + IPS_STATUS_Q_SIZE,
5371 ha->mem_ptr + IPS_REG_SQER);
5372 writel(phys_status_start + IPS_STATUS_SIZE, ha->mem_ptr + IPS_REG_SQHR);
5373 writel(phys_status_start, ha->mem_ptr + IPS_REG_SQTR);
5375 ha->adapt->hw_status_tail = phys_status_start;
5378 /****************************************************************************/
5380 /* Routine Name: ips_statupd_copperhead */
5382 /* Routine Description: */
5384 /* Remove an element from the status queue */
5386 /****************************************************************************/
5388 ips_statupd_copperhead(ips_ha_t * ha)
5390 METHOD_TRACE("ips_statupd_copperhead", 1);
5392 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5393 ha->adapt->p_status_tail++;
5394 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5396 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5397 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5400 outl(cpu_to_le32(ha->adapt->hw_status_tail),
5401 ha->io_addr + IPS_REG_SQTR);
5403 return (ha->adapt->p_status_tail->value);
5406 /****************************************************************************/
5408 /* Routine Name: ips_statupd_copperhead_memio */
5410 /* Routine Description: */
5412 /* Remove an element from the status queue */
5414 /****************************************************************************/
5416 ips_statupd_copperhead_memio(ips_ha_t * ha)
5418 METHOD_TRACE("ips_statupd_copperhead_memio", 1);
5420 if (ha->adapt->p_status_tail != ha->adapt->p_status_end) {
5421 ha->adapt->p_status_tail++;
5422 ha->adapt->hw_status_tail += sizeof (IPS_STATUS);
5424 ha->adapt->p_status_tail = ha->adapt->p_status_start;
5425 ha->adapt->hw_status_tail = ha->adapt->hw_status_start;
5428 writel(ha->adapt->hw_status_tail, ha->mem_ptr + IPS_REG_SQTR);
5430 return (ha->adapt->p_status_tail->value);
5433 /****************************************************************************/
5435 /* Routine Name: ips_statupd_morpheus */
5437 /* Routine Description: */
5439 /* Remove an element from the status queue */
5441 /****************************************************************************/
5443 ips_statupd_morpheus(ips_ha_t * ha)
5447 METHOD_TRACE("ips_statupd_morpheus", 1);
5449 val = readl(ha->mem_ptr + IPS_REG_I2O_OUTMSGQ);
5454 /****************************************************************************/
5456 /* Routine Name: ips_issue_copperhead */
5458 /* Routine Description: */
5460 /* Send a command down to the controller */
5462 /****************************************************************************/
5464 ips_issue_copperhead(ips_ha_t * ha, ips_scb_t * scb)
5469 METHOD_TRACE("ips_issue_copperhead", 1);
5471 if (scb->scsi_cmd) {
5472 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5476 scb->cmd.basic_io.command_id,
5477 scb->bus, scb->target_id, scb->lun);
5479 DEBUG_VAR(2, KERN_NOTICE "(%s%d) ips_issue: logical cmd id %d",
5480 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5486 le32_to_cpu(inl(ha->io_addr + IPS_REG_CCCR))) & IPS_BIT_SEM) {
5489 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5490 if (!(val & IPS_BIT_START_STOP))
5493 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5494 "ips_issue val [0x%x].\n", val);
5495 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5496 "ips_issue semaphore chk timeout.\n");
5498 return (IPS_FAILURE);
5502 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_CCSAR);
5503 outw(cpu_to_le32(IPS_BIT_START_CMD), ha->io_addr + IPS_REG_CCCR);
5505 return (IPS_SUCCESS);
5508 /****************************************************************************/
5510 /* Routine Name: ips_issue_copperhead_memio */
5512 /* Routine Description: */
5514 /* Send a command down to the controller */
5516 /****************************************************************************/
5518 ips_issue_copperhead_memio(ips_ha_t * ha, ips_scb_t * scb)
5523 METHOD_TRACE("ips_issue_copperhead_memio", 1);
5525 if (scb->scsi_cmd) {
5526 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5530 scb->cmd.basic_io.command_id,
5531 scb->bus, scb->target_id, scb->lun);
5533 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5534 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5539 while ((val = readl(ha->mem_ptr + IPS_REG_CCCR)) & IPS_BIT_SEM) {
5542 if (++TimeOut >= IPS_SEM_TIMEOUT) {
5543 if (!(val & IPS_BIT_START_STOP))
5546 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5547 "ips_issue val [0x%x].\n", val);
5548 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5549 "ips_issue semaphore chk timeout.\n");
5551 return (IPS_FAILURE);
5555 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_CCSAR);
5556 writel(IPS_BIT_START_CMD, ha->mem_ptr + IPS_REG_CCCR);
5558 return (IPS_SUCCESS);
5561 /****************************************************************************/
5563 /* Routine Name: ips_issue_i2o */
5565 /* Routine Description: */
5567 /* Send a command down to the controller */
5569 /****************************************************************************/
5571 ips_issue_i2o(ips_ha_t * ha, ips_scb_t * scb)
5574 METHOD_TRACE("ips_issue_i2o", 1);
5576 if (scb->scsi_cmd) {
5577 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5581 scb->cmd.basic_io.command_id,
5582 scb->bus, scb->target_id, scb->lun);
5584 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5585 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5588 outl(cpu_to_le32(scb->scb_busaddr), ha->io_addr + IPS_REG_I2O_INMSGQ);
5590 return (IPS_SUCCESS);
5593 /****************************************************************************/
5595 /* Routine Name: ips_issue_i2o_memio */
5597 /* Routine Description: */
5599 /* Send a command down to the controller */
5601 /****************************************************************************/
5603 ips_issue_i2o_memio(ips_ha_t * ha, ips_scb_t * scb)
5606 METHOD_TRACE("ips_issue_i2o_memio", 1);
5608 if (scb->scsi_cmd) {
5609 DEBUG_VAR(2, "(%s%d) ips_issue: cmd 0x%X id %d (%d %d %d)",
5613 scb->cmd.basic_io.command_id,
5614 scb->bus, scb->target_id, scb->lun);
5616 DEBUG_VAR(2, "(%s%d) ips_issue: logical cmd id %d",
5617 ips_name, ha->host_num, scb->cmd.basic_io.command_id);
5620 writel(scb->scb_busaddr, ha->mem_ptr + IPS_REG_I2O_INMSGQ);
5622 return (IPS_SUCCESS);
5625 /****************************************************************************/
5627 /* Routine Name: ips_isintr_copperhead */
5629 /* Routine Description: */
5631 /* Test to see if an interrupt is for us */
5633 /****************************************************************************/
5635 ips_isintr_copperhead(ips_ha_t * ha)
5639 METHOD_TRACE("ips_isintr_copperhead", 2);
5641 Isr = inb(ha->io_addr + IPS_REG_HISR);
5644 /* ?!?! Nothing really there */
5647 if (Isr & IPS_BIT_SCE)
5649 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5650 /* status queue overflow or GHI */
5651 /* just clear the interrupt */
5652 outb(Isr, ha->io_addr + IPS_REG_HISR);
5658 /****************************************************************************/
5660 /* Routine Name: ips_isintr_copperhead_memio */
5662 /* Routine Description: */
5664 /* Test to see if an interrupt is for us */
5666 /****************************************************************************/
5668 ips_isintr_copperhead_memio(ips_ha_t * ha)
5672 METHOD_TRACE("ips_isintr_memio", 2);
5674 Isr = readb(ha->mem_ptr + IPS_REG_HISR);
5677 /* ?!?! Nothing really there */
5680 if (Isr & IPS_BIT_SCE)
5682 else if (Isr & (IPS_BIT_SQO | IPS_BIT_GHI)) {
5683 /* status queue overflow or GHI */
5684 /* just clear the interrupt */
5685 writeb(Isr, ha->mem_ptr + IPS_REG_HISR);
5691 /****************************************************************************/
5693 /* Routine Name: ips_isintr_morpheus */
5695 /* Routine Description: */
5697 /* Test to see if an interrupt is for us */
5699 /****************************************************************************/
5701 ips_isintr_morpheus(ips_ha_t * ha)
5705 METHOD_TRACE("ips_isintr_morpheus", 2);
5707 Isr = readl(ha->mem_ptr + IPS_REG_I2O_HIR);
5709 if (Isr & IPS_BIT_I2O_OPQI)
5715 /****************************************************************************/
5717 /* Routine Name: ips_wait */
5719 /* Routine Description: */
5721 /* Wait for a command to complete */
5723 /****************************************************************************/
5725 ips_wait(ips_ha_t * ha, int time, int intr)
5730 METHOD_TRACE("ips_wait", 1);
5735 time *= IPS_ONE_SEC; /* convert seconds */
5737 while ((time > 0) && (!done)) {
5738 if (intr == IPS_INTR_ON) {
5739 if (ha->waitflag == FALSE) {
5744 } else if (intr == IPS_INTR_IORL) {
5745 if (ha->waitflag == FALSE) {
5747 * controller generated an interrupt to
5748 * acknowledge completion of the command
5749 * and ips_intr() has serviced the interrupt.
5757 * NOTE: we already have the io_request_lock so
5758 * even if we get an interrupt it won't get serviced
5759 * until after we finish.
5762 (*ha->func.intr) (ha);
5765 /* This looks like a very evil loop, but it only does this during start-up */
5773 /****************************************************************************/
5775 /* Routine Name: ips_write_driver_status */
5777 /* Routine Description: */
5779 /* Write OS/Driver version to Page 5 of the nvram on the controller */
5781 /****************************************************************************/
5783 ips_write_driver_status(ips_ha_t * ha, int intr)
5785 METHOD_TRACE("ips_write_driver_status", 1);
5787 if (!ips_readwrite_page5(ha, FALSE, intr)) {
5788 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5789 "unable to read NVRAM page 5.\n");
5794 /* check to make sure the page has a valid */
5796 if (le32_to_cpu(ha->nvram->signature) != IPS_NVRAM_P5_SIG) {
5798 "(%s%d) NVRAM page 5 has an invalid signature: %X.",
5799 ips_name, ha->host_num, ha->nvram->signature);
5800 ha->nvram->signature = IPS_NVRAM_P5_SIG;
5804 "(%s%d) Ad Type: %d, Ad Slot: %d, BIOS: %c%c%c%c %c%c%c%c.",
5805 ips_name, ha->host_num, le16_to_cpu(ha->nvram->adapter_type),
5806 ha->nvram->adapter_slot, ha->nvram->bios_high[0],
5807 ha->nvram->bios_high[1], ha->nvram->bios_high[2],
5808 ha->nvram->bios_high[3], ha->nvram->bios_low[0],
5809 ha->nvram->bios_low[1], ha->nvram->bios_low[2],
5810 ha->nvram->bios_low[3]);
5812 ips_get_bios_version(ha, intr);
5814 /* change values (as needed) */
5815 ha->nvram->operating_system = IPS_OS_LINUX;
5816 ha->nvram->adapter_type = ha->ad_type;
5817 strncpy((char *) ha->nvram->driver_high, IPS_VERSION_HIGH, 4);
5818 strncpy((char *) ha->nvram->driver_low, IPS_VERSION_LOW, 4);
5819 strncpy((char *) ha->nvram->bios_high, ha->bios_version, 4);
5820 strncpy((char *) ha->nvram->bios_low, ha->bios_version + 4, 4);
5822 ips_version_check(ha, intr); /* Check BIOS/FW/Driver Versions */
5824 /* now update the page */
5825 if (!ips_readwrite_page5(ha, TRUE, intr)) {
5826 IPS_PRINTK(KERN_WARNING, ha->pcidev,
5827 "unable to write NVRAM page 5.\n");
5832 /* IF NVRAM Page 5 is OK, Use it for Slot Number Info Because Linux Doesn't Do Slots */
5833 ha->slot_num = ha->nvram->adapter_slot;
5838 /****************************************************************************/
5840 /* Routine Name: ips_read_adapter_status */
5842 /* Routine Description: */
5844 /* Do an Inquiry command to the adapter */
5846 /****************************************************************************/
5848 ips_read_adapter_status(ips_ha_t * ha, int intr)
5853 METHOD_TRACE("ips_read_adapter_status", 1);
5855 scb = &ha->scbs[ha->max_cmds - 1];
5857 ips_init_scb(ha, scb);
5859 scb->timeout = ips_cmd_timeout;
5860 scb->cdb[0] = IPS_CMD_ENQUIRY;
5862 scb->cmd.basic_io.op_code = IPS_CMD_ENQUIRY;
5863 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5864 scb->cmd.basic_io.sg_count = 0;
5865 scb->cmd.basic_io.lba = 0;
5866 scb->cmd.basic_io.sector_count = 0;
5867 scb->cmd.basic_io.log_drv = 0;
5868 scb->data_len = sizeof (*ha->enq);
5869 scb->cmd.basic_io.sg_addr = ha->enq_busaddr;
5873 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5874 || (ret == IPS_SUCCESS_IMM)
5875 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5881 /****************************************************************************/
5883 /* Routine Name: ips_read_subsystem_parameters */
5885 /* Routine Description: */
5887 /* Read subsystem parameters from the adapter */
5889 /****************************************************************************/
5891 ips_read_subsystem_parameters(ips_ha_t * ha, int intr)
5896 METHOD_TRACE("ips_read_subsystem_parameters", 1);
5898 scb = &ha->scbs[ha->max_cmds - 1];
5900 ips_init_scb(ha, scb);
5902 scb->timeout = ips_cmd_timeout;
5903 scb->cdb[0] = IPS_CMD_GET_SUBSYS;
5905 scb->cmd.basic_io.op_code = IPS_CMD_GET_SUBSYS;
5906 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5907 scb->cmd.basic_io.sg_count = 0;
5908 scb->cmd.basic_io.lba = 0;
5909 scb->cmd.basic_io.sector_count = 0;
5910 scb->cmd.basic_io.log_drv = 0;
5911 scb->data_len = sizeof (*ha->subsys);
5912 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5916 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5917 || (ret == IPS_SUCCESS_IMM)
5918 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
5921 memcpy(ha->subsys, ha->ioctl_data, sizeof(*ha->subsys));
5925 /****************************************************************************/
5927 /* Routine Name: ips_read_config */
5929 /* Routine Description: */
5931 /* Read the configuration on the adapter */
5933 /****************************************************************************/
5935 ips_read_config(ips_ha_t * ha, int intr)
5941 METHOD_TRACE("ips_read_config", 1);
5943 /* set defaults for initiator IDs */
5944 for (i = 0; i < 4; i++)
5945 ha->conf->init_id[i] = 7;
5947 scb = &ha->scbs[ha->max_cmds - 1];
5949 ips_init_scb(ha, scb);
5951 scb->timeout = ips_cmd_timeout;
5952 scb->cdb[0] = IPS_CMD_READ_CONF;
5954 scb->cmd.basic_io.op_code = IPS_CMD_READ_CONF;
5955 scb->cmd.basic_io.command_id = IPS_COMMAND_ID(ha, scb);
5956 scb->data_len = sizeof (*ha->conf);
5957 scb->cmd.basic_io.sg_addr = ha->ioctl_busaddr;
5961 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
5962 || (ret == IPS_SUCCESS_IMM)
5963 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
5965 memset(ha->conf, 0, sizeof (IPS_CONF));
5967 /* reset initiator IDs */
5968 for (i = 0; i < 4; i++)
5969 ha->conf->init_id[i] = 7;
5971 /* Allow Completed with Errors, so JCRM can access the Adapter to fix the problems */
5972 if ((scb->basic_status & IPS_GSC_STATUS_MASK) ==
5973 IPS_CMD_CMPLT_WERROR)
5979 memcpy(ha->conf, ha->ioctl_data, sizeof(*ha->conf));
5983 /****************************************************************************/
5985 /* Routine Name: ips_readwrite_page5 */
5987 /* Routine Description: */
5989 /* Read nvram page 5 from the adapter */
5991 /****************************************************************************/
5993 ips_readwrite_page5(ips_ha_t * ha, int write, int intr)
5998 METHOD_TRACE("ips_readwrite_page5", 1);
6000 scb = &ha->scbs[ha->max_cmds - 1];
6002 ips_init_scb(ha, scb);
6004 scb->timeout = ips_cmd_timeout;
6005 scb->cdb[0] = IPS_CMD_RW_NVRAM_PAGE;
6007 scb->cmd.nvram.op_code = IPS_CMD_RW_NVRAM_PAGE;
6008 scb->cmd.nvram.command_id = IPS_COMMAND_ID(ha, scb);
6009 scb->cmd.nvram.page = 5;
6010 scb->cmd.nvram.write = write;
6011 scb->cmd.nvram.reserved = 0;
6012 scb->cmd.nvram.reserved2 = 0;
6013 scb->data_len = sizeof (*ha->nvram);
6014 scb->cmd.nvram.buffer_addr = ha->ioctl_busaddr;
6016 memcpy(ha->ioctl_data, ha->nvram, sizeof(*ha->nvram));
6018 /* issue the command */
6020 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6021 || (ret == IPS_SUCCESS_IMM)
6022 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1)) {
6024 memset(ha->nvram, 0, sizeof (IPS_NVRAM_P5));
6029 memcpy(ha->nvram, ha->ioctl_data, sizeof(*ha->nvram));
6033 /****************************************************************************/
6035 /* Routine Name: ips_clear_adapter */
6037 /* Routine Description: */
6039 /* Clear the stripe lock tables */
6041 /****************************************************************************/
6043 ips_clear_adapter(ips_ha_t * ha, int intr)
6048 METHOD_TRACE("ips_clear_adapter", 1);
6050 scb = &ha->scbs[ha->max_cmds - 1];
6052 ips_init_scb(ha, scb);
6054 scb->timeout = ips_reset_timeout;
6055 scb->cdb[0] = IPS_CMD_CONFIG_SYNC;
6057 scb->cmd.config_sync.op_code = IPS_CMD_CONFIG_SYNC;
6058 scb->cmd.config_sync.command_id = IPS_COMMAND_ID(ha, scb);
6059 scb->cmd.config_sync.channel = 0;
6060 scb->cmd.config_sync.source_target = IPS_POCL;
6061 scb->cmd.config_sync.reserved = 0;
6062 scb->cmd.config_sync.reserved2 = 0;
6063 scb->cmd.config_sync.reserved3 = 0;
6067 ips_send_wait(ha, scb, ips_reset_timeout, intr)) == IPS_FAILURE)
6068 || (ret == IPS_SUCCESS_IMM)
6069 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6072 /* send unlock stripe command */
6073 ips_init_scb(ha, scb);
6075 scb->cdb[0] = IPS_CMD_ERROR_TABLE;
6076 scb->timeout = ips_reset_timeout;
6078 scb->cmd.unlock_stripe.op_code = IPS_CMD_ERROR_TABLE;
6079 scb->cmd.unlock_stripe.command_id = IPS_COMMAND_ID(ha, scb);
6080 scb->cmd.unlock_stripe.log_drv = 0;
6081 scb->cmd.unlock_stripe.control = IPS_CSL;
6082 scb->cmd.unlock_stripe.reserved = 0;
6083 scb->cmd.unlock_stripe.reserved2 = 0;
6084 scb->cmd.unlock_stripe.reserved3 = 0;
6088 ips_send_wait(ha, scb, ips_cmd_timeout, intr)) == IPS_FAILURE)
6089 || (ret == IPS_SUCCESS_IMM)
6090 || ((scb->basic_status & IPS_GSC_STATUS_MASK) > 1))
6096 /****************************************************************************/
6098 /* Routine Name: ips_ffdc_reset */
6100 /* Routine Description: */
6102 /* FFDC: write reset info */
6104 /****************************************************************************/
6106 ips_ffdc_reset(ips_ha_t * ha, int intr)
6110 METHOD_TRACE("ips_ffdc_reset", 1);
6112 scb = &ha->scbs[ha->max_cmds - 1];
6114 ips_init_scb(ha, scb);
6116 scb->timeout = ips_cmd_timeout;
6117 scb->cdb[0] = IPS_CMD_FFDC;
6118 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6119 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6120 scb->cmd.ffdc.reset_count = ha->reset_count;
6121 scb->cmd.ffdc.reset_type = 0x80;
6123 /* convert time to what the card wants */
6124 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6127 ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6130 /****************************************************************************/
6132 /* Routine Name: ips_ffdc_time */
6134 /* Routine Description: */
6136 /* FFDC: write time info */
6138 /****************************************************************************/
6140 ips_ffdc_time(ips_ha_t * ha)
6144 METHOD_TRACE("ips_ffdc_time", 1);
6146 DEBUG_VAR(1, "(%s%d) Sending time update.", ips_name, ha->host_num);
6148 scb = &ha->scbs[ha->max_cmds - 1];
6150 ips_init_scb(ha, scb);
6152 scb->timeout = ips_cmd_timeout;
6153 scb->cdb[0] = IPS_CMD_FFDC;
6154 scb->cmd.ffdc.op_code = IPS_CMD_FFDC;
6155 scb->cmd.ffdc.command_id = IPS_COMMAND_ID(ha, scb);
6156 scb->cmd.ffdc.reset_count = 0;
6157 scb->cmd.ffdc.reset_type = 0;
6159 /* convert time to what the card wants */
6160 ips_fix_ffdc_time(ha, scb, ha->last_ffdc);
6163 ips_send_wait(ha, scb, ips_cmd_timeout, IPS_FFDC);
6166 /****************************************************************************/
6168 /* Routine Name: ips_fix_ffdc_time */
6170 /* Routine Description: */
6171 /* Adjust time_t to what the card wants */
6173 /****************************************************************************/
6175 ips_fix_ffdc_time(ips_ha_t * ha, ips_scb_t * scb, time_t current_time)
6182 int year_lengths[2] = { IPS_DAYS_NORMAL_YEAR, IPS_DAYS_LEAP_YEAR };
6183 int month_lengths[12][2] = { {31, 31},
6197 METHOD_TRACE("ips_fix_ffdc_time", 1);
6199 days = current_time / IPS_SECS_DAY;
6200 rem = current_time % IPS_SECS_DAY;
6202 scb->cmd.ffdc.hour = (rem / IPS_SECS_HOUR);
6203 rem = rem % IPS_SECS_HOUR;
6204 scb->cmd.ffdc.minute = (rem / IPS_SECS_MIN);
6205 scb->cmd.ffdc.second = (rem % IPS_SECS_MIN);
6207 year = IPS_EPOCH_YEAR;
6208 while (days < 0 || days >= year_lengths[yleap = IPS_IS_LEAP_YEAR(year)]) {
6211 newy = year + (days / IPS_DAYS_NORMAL_YEAR);
6214 days -= (newy - year) * IPS_DAYS_NORMAL_YEAR +
6215 IPS_NUM_LEAP_YEARS_THROUGH(newy - 1) -
6216 IPS_NUM_LEAP_YEARS_THROUGH(year - 1);
6220 scb->cmd.ffdc.yearH = year / 100;
6221 scb->cmd.ffdc.yearL = year % 100;
6223 for (i = 0; days >= month_lengths[i][yleap]; ++i)
6224 days -= month_lengths[i][yleap];
6226 scb->cmd.ffdc.month = i + 1;
6227 scb->cmd.ffdc.day = days + 1;
6230 /****************************************************************************
6231 * BIOS Flash Routines *
6232 ****************************************************************************/
6234 /****************************************************************************/
6236 /* Routine Name: ips_erase_bios */
6238 /* Routine Description: */
6239 /* Erase the BIOS on the adapter */
6241 /****************************************************************************/
6243 ips_erase_bios(ips_ha_t * ha)
6248 METHOD_TRACE("ips_erase_bios", 1);
6252 /* Clear the status register */
6253 outl(0, ha->io_addr + IPS_REG_FLAP);
6254 if (ha->revision_id == IPS_REVID_TROMBONE64)
6255 udelay(25); /* 25 us */
6257 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6258 if (ha->revision_id == IPS_REVID_TROMBONE64)
6259 udelay(25); /* 25 us */
6262 outb(0x20, ha->io_addr + IPS_REG_FLDP);
6263 if (ha->revision_id == IPS_REVID_TROMBONE64)
6264 udelay(25); /* 25 us */
6267 outb(0xD0, ha->io_addr + IPS_REG_FLDP);
6268 if (ha->revision_id == IPS_REVID_TROMBONE64)
6269 udelay(25); /* 25 us */
6272 outb(0x70, ha->io_addr + IPS_REG_FLDP);
6273 if (ha->revision_id == IPS_REVID_TROMBONE64)
6274 udelay(25); /* 25 us */
6276 timeout = 80000; /* 80 seconds */
6278 while (timeout > 0) {
6279 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6280 outl(0, ha->io_addr + IPS_REG_FLAP);
6281 udelay(25); /* 25 us */
6284 status = inb(ha->io_addr + IPS_REG_FLDP);
6293 /* check for timeout */
6297 /* try to suspend the erase */
6298 outb(0xB0, ha->io_addr + IPS_REG_FLDP);
6299 if (ha->revision_id == IPS_REVID_TROMBONE64)
6300 udelay(25); /* 25 us */
6302 /* wait for 10 seconds */
6304 while (timeout > 0) {
6305 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6306 outl(0, ha->io_addr + IPS_REG_FLAP);
6307 udelay(25); /* 25 us */
6310 status = inb(ha->io_addr + IPS_REG_FLDP);
6322 /* check for valid VPP */
6327 /* check for succesful flash */
6329 /* sequence error */
6332 /* Otherwise, we were successful */
6334 outb(0x50, ha->io_addr + IPS_REG_FLDP);
6335 if (ha->revision_id == IPS_REVID_TROMBONE64)
6336 udelay(25); /* 25 us */
6339 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6340 if (ha->revision_id == IPS_REVID_TROMBONE64)
6341 udelay(25); /* 25 us */
6346 /****************************************************************************/
6348 /* Routine Name: ips_erase_bios_memio */
6350 /* Routine Description: */
6351 /* Erase the BIOS on the adapter */
6353 /****************************************************************************/
6355 ips_erase_bios_memio(ips_ha_t * ha)
6360 METHOD_TRACE("ips_erase_bios_memio", 1);
6364 /* Clear the status register */
6365 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6366 if (ha->revision_id == IPS_REVID_TROMBONE64)
6367 udelay(25); /* 25 us */
6369 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6370 if (ha->revision_id == IPS_REVID_TROMBONE64)
6371 udelay(25); /* 25 us */
6374 writeb(0x20, ha->mem_ptr + IPS_REG_FLDP);
6375 if (ha->revision_id == IPS_REVID_TROMBONE64)
6376 udelay(25); /* 25 us */
6379 writeb(0xD0, ha->mem_ptr + IPS_REG_FLDP);
6380 if (ha->revision_id == IPS_REVID_TROMBONE64)
6381 udelay(25); /* 25 us */
6384 writeb(0x70, ha->mem_ptr + IPS_REG_FLDP);
6385 if (ha->revision_id == IPS_REVID_TROMBONE64)
6386 udelay(25); /* 25 us */
6388 timeout = 80000; /* 80 seconds */
6390 while (timeout > 0) {
6391 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6392 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6393 udelay(25); /* 25 us */
6396 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6405 /* check for timeout */
6409 /* try to suspend the erase */
6410 writeb(0xB0, ha->mem_ptr + IPS_REG_FLDP);
6411 if (ha->revision_id == IPS_REVID_TROMBONE64)
6412 udelay(25); /* 25 us */
6414 /* wait for 10 seconds */
6416 while (timeout > 0) {
6417 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6418 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6419 udelay(25); /* 25 us */
6422 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6434 /* check for valid VPP */
6439 /* check for succesful flash */
6441 /* sequence error */
6444 /* Otherwise, we were successful */
6446 writeb(0x50, ha->mem_ptr + IPS_REG_FLDP);
6447 if (ha->revision_id == IPS_REVID_TROMBONE64)
6448 udelay(25); /* 25 us */
6451 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6452 if (ha->revision_id == IPS_REVID_TROMBONE64)
6453 udelay(25); /* 25 us */
6458 /****************************************************************************/
6460 /* Routine Name: ips_program_bios */
6462 /* Routine Description: */
6463 /* Program the BIOS on the adapter */
6465 /****************************************************************************/
6467 ips_program_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6474 METHOD_TRACE("ips_program_bios", 1);
6478 for (i = 0; i < buffersize; i++) {
6480 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6481 if (ha->revision_id == IPS_REVID_TROMBONE64)
6482 udelay(25); /* 25 us */
6484 outb(0x40, ha->io_addr + IPS_REG_FLDP);
6485 if (ha->revision_id == IPS_REVID_TROMBONE64)
6486 udelay(25); /* 25 us */
6488 outb(buffer[i], ha->io_addr + IPS_REG_FLDP);
6489 if (ha->revision_id == IPS_REVID_TROMBONE64)
6490 udelay(25); /* 25 us */
6492 /* wait up to one second */
6494 while (timeout > 0) {
6495 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6496 outl(0, ha->io_addr + IPS_REG_FLAP);
6497 udelay(25); /* 25 us */
6500 status = inb(ha->io_addr + IPS_REG_FLDP);
6511 outl(0, ha->io_addr + IPS_REG_FLAP);
6512 if (ha->revision_id == IPS_REVID_TROMBONE64)
6513 udelay(25); /* 25 us */
6515 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6516 if (ha->revision_id == IPS_REVID_TROMBONE64)
6517 udelay(25); /* 25 us */
6522 /* check the status */
6523 if (status & 0x18) {
6524 /* programming error */
6525 outl(0, ha->io_addr + IPS_REG_FLAP);
6526 if (ha->revision_id == IPS_REVID_TROMBONE64)
6527 udelay(25); /* 25 us */
6529 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6530 if (ha->revision_id == IPS_REVID_TROMBONE64)
6531 udelay(25); /* 25 us */
6537 /* Enable reading */
6538 outl(0, ha->io_addr + IPS_REG_FLAP);
6539 if (ha->revision_id == IPS_REVID_TROMBONE64)
6540 udelay(25); /* 25 us */
6542 outb(0xFF, ha->io_addr + IPS_REG_FLDP);
6543 if (ha->revision_id == IPS_REVID_TROMBONE64)
6544 udelay(25); /* 25 us */
6549 /****************************************************************************/
6551 /* Routine Name: ips_program_bios_memio */
6553 /* Routine Description: */
6554 /* Program the BIOS on the adapter */
6556 /****************************************************************************/
6558 ips_program_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6565 METHOD_TRACE("ips_program_bios_memio", 1);
6569 for (i = 0; i < buffersize; i++) {
6571 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6572 if (ha->revision_id == IPS_REVID_TROMBONE64)
6573 udelay(25); /* 25 us */
6575 writeb(0x40, ha->mem_ptr + IPS_REG_FLDP);
6576 if (ha->revision_id == IPS_REVID_TROMBONE64)
6577 udelay(25); /* 25 us */
6579 writeb(buffer[i], ha->mem_ptr + IPS_REG_FLDP);
6580 if (ha->revision_id == IPS_REVID_TROMBONE64)
6581 udelay(25); /* 25 us */
6583 /* wait up to one second */
6585 while (timeout > 0) {
6586 if (ha->revision_id == IPS_REVID_TROMBONE64) {
6587 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6588 udelay(25); /* 25 us */
6591 status = readb(ha->mem_ptr + IPS_REG_FLDP);
6602 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6603 if (ha->revision_id == IPS_REVID_TROMBONE64)
6604 udelay(25); /* 25 us */
6606 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6607 if (ha->revision_id == IPS_REVID_TROMBONE64)
6608 udelay(25); /* 25 us */
6613 /* check the status */
6614 if (status & 0x18) {
6615 /* programming error */
6616 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6617 if (ha->revision_id == IPS_REVID_TROMBONE64)
6618 udelay(25); /* 25 us */
6620 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6621 if (ha->revision_id == IPS_REVID_TROMBONE64)
6622 udelay(25); /* 25 us */
6628 /* Enable reading */
6629 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6630 if (ha->revision_id == IPS_REVID_TROMBONE64)
6631 udelay(25); /* 25 us */
6633 writeb(0xFF, ha->mem_ptr + IPS_REG_FLDP);
6634 if (ha->revision_id == IPS_REVID_TROMBONE64)
6635 udelay(25); /* 25 us */
6640 /****************************************************************************/
6642 /* Routine Name: ips_verify_bios */
6644 /* Routine Description: */
6645 /* Verify the BIOS on the adapter */
6647 /****************************************************************************/
6649 ips_verify_bios(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6655 METHOD_TRACE("ips_verify_bios", 1);
6658 outl(0, ha->io_addr + IPS_REG_FLAP);
6659 if (ha->revision_id == IPS_REVID_TROMBONE64)
6660 udelay(25); /* 25 us */
6662 if (inb(ha->io_addr + IPS_REG_FLDP) != 0x55)
6665 outl(cpu_to_le32(1), ha->io_addr + IPS_REG_FLAP);
6666 if (ha->revision_id == IPS_REVID_TROMBONE64)
6667 udelay(25); /* 25 us */
6668 if (inb(ha->io_addr + IPS_REG_FLDP) != 0xAA)
6672 for (i = 2; i < buffersize; i++) {
6674 outl(cpu_to_le32(i + offset), ha->io_addr + IPS_REG_FLAP);
6675 if (ha->revision_id == IPS_REVID_TROMBONE64)
6676 udelay(25); /* 25 us */
6678 checksum = (uint8_t) checksum + inb(ha->io_addr + IPS_REG_FLDP);
6689 /****************************************************************************/
6691 /* Routine Name: ips_verify_bios_memio */
6693 /* Routine Description: */
6694 /* Verify the BIOS on the adapter */
6696 /****************************************************************************/
6698 ips_verify_bios_memio(ips_ha_t * ha, char *buffer, uint32_t buffersize,
6704 METHOD_TRACE("ips_verify_bios_memio", 1);
6707 writel(0, ha->mem_ptr + IPS_REG_FLAP);
6708 if (ha->revision_id == IPS_REVID_TROMBONE64)
6709 udelay(25); /* 25 us */
6711 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0x55)
6714 writel(1, ha->mem_ptr + IPS_REG_FLAP);
6715 if (ha->revision_id == IPS_REVID_TROMBONE64)
6716 udelay(25); /* 25 us */
6717 if (readb(ha->mem_ptr + IPS_REG_FLDP) != 0xAA)
6721 for (i = 2; i < buffersize; i++) {
6723 writel(i + offset, ha->mem_ptr + IPS_REG_FLAP);
6724 if (ha->revision_id == IPS_REVID_TROMBONE64)
6725 udelay(25); /* 25 us */
6728 (uint8_t) checksum + readb(ha->mem_ptr + IPS_REG_FLDP);
6739 /*---------------------------------------------------------------------------*/
6740 /* Routine Name: ips_version_check */
6743 /* Assumes that ips_read_adapter_status() is called first filling in */
6744 /* the data for SubSystem Parameters. */
6745 /* Called from ips_write_driver_status() so it also assumes NVRAM Page 5 */
6746 /* Data is available. */
6748 /*---------------------------------------------------------------------------*/
6750 ips_version_check(ips_ha_t * ha, int intr)
6752 IPS_VERSION_DATA *VersionInfo;
6753 uint8_t FirmwareVersion[IPS_COMPAT_ID_LENGTH + 1];
6754 uint8_t BiosVersion[IPS_COMPAT_ID_LENGTH + 1];
6757 char BiosString[10];
6758 char FirmwareString[10];
6760 METHOD_TRACE("ips_version_check", 1);
6762 VersionInfo = ( IPS_VERSION_DATA * ) ha->ioctl_data;
6764 memset(FirmwareVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6765 memset(BiosVersion, 0, IPS_COMPAT_ID_LENGTH + 1);
6767 /* Get the Compatible BIOS Version from NVRAM Page 5 */
6768 memcpy(BiosVersion, ha->nvram->BiosCompatibilityID,
6769 IPS_COMPAT_ID_LENGTH);
6772 if (ha->subsys->param[4] & IPS_GET_VERSION_SUPPORT) { /* If Versioning is Supported */
6773 /* Get the Version Info with a Get Version Command */
6774 memset( VersionInfo, 0, sizeof (IPS_VERSION_DATA));
6775 rc = ips_get_version_info(ha, ha->ioctl_busaddr, intr);
6776 if (rc == IPS_SUCCESS)
6777 memcpy(FirmwareVersion, VersionInfo->compatibilityId,
6778 IPS_COMPAT_ID_LENGTH);
6781 if (rc != IPS_SUCCESS) { /* If Data Not Obtainable from a GetVersion Command */
6782 /* Get the Firmware Version from Enquiry Data */
6783 memcpy(FirmwareVersion, ha->enq->CodeBlkVersion,
6784 IPS_COMPAT_ID_LENGTH);
6787 /* printk(KERN_WARNING "Adapter's BIOS Version = %s\n", BiosVersion); */
6788 /* printk(KERN_WARNING "BIOS Compatible Version = %s\n", IPS_COMPAT_BIOS); */
6789 /* printk(KERN_WARNING "Adapter's Firmware Version = %s\n", FirmwareVersion); */
6790 /* printk(KERN_WARNING "Firmware Compatible Version = %s \n", Compatable[ ha->nvram->adapter_type ]); */
6795 (FirmwareVersion, Compatable[ha->nvram->adapter_type],
6796 IPS_COMPAT_ID_LENGTH) != 0)
6799 if (strncmp(BiosVersion, IPS_COMPAT_BIOS, IPS_COMPAT_ID_LENGTH) != 0)
6802 ha->nvram->versioning = 1; /* Indicate the Driver Supports Versioning */
6805 ha->nvram->version_mismatch = 1;
6806 if (ips_cd_boot == 0) {
6807 strncpy(&BiosString[0], ha->nvram->bios_high, 4);
6808 strncpy(&BiosString[4], ha->nvram->bios_low, 4);
6811 strncpy(&FirmwareString[0], ha->enq->CodeBlkVersion, 8);
6812 FirmwareString[8] = 0;
6814 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6815 "Warning ! ! ! ServeRAID Version Mismatch\n");
6816 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6817 "Bios = %s, Firmware = %s, Device Driver = %s%s\n",
6818 BiosString, FirmwareString, IPS_VERSION_HIGH,
6820 IPS_PRINTK(KERN_WARNING, ha->pcidev,
6821 "These levels should match to avoid possible compatibility problems.\n");
6824 ha->nvram->version_mismatch = 0;
6830 /*---------------------------------------------------------------------------*/
6831 /* Routine Name: ips_get_version_info */
6833 /* Routine Description: */
6834 /* Issue an internal GETVERSION Command */
6837 /* 0 if Successful, else non-zero */
6838 /*---------------------------------------------------------------------------*/
6840 ips_get_version_info(ips_ha_t * ha, dma_addr_t Buffer, int intr)
6845 METHOD_TRACE("ips_get_version_info", 1);
6847 scb = &ha->scbs[ha->max_cmds - 1];
6849 ips_init_scb(ha, scb);
6851 scb->timeout = ips_cmd_timeout;
6852 scb->cdb[0] = IPS_CMD_GET_VERSION_INFO;
6853 scb->cmd.version_info.op_code = IPS_CMD_GET_VERSION_INFO;
6854 scb->cmd.version_info.command_id = IPS_COMMAND_ID(ha, scb);
6855 scb->cmd.version_info.reserved = 0;
6856 scb->cmd.version_info.count = sizeof (IPS_VERSION_DATA);
6857 scb->cmd.version_info.reserved2 = 0;
6858 scb->data_len = sizeof (IPS_VERSION_DATA);
6859 scb->data_busaddr = Buffer;
6860 scb->cmd.version_info.buffer_addr = Buffer;
6864 rc = ips_send_wait(ha, scb, ips_cmd_timeout, intr);
6868 /****************************************************************************/
6870 /* Routine Name: ips_abort_init */
6872 /* Routine Description: */
6873 /* cleanup routine for a failed adapter initialization */
6874 /****************************************************************************/
6876 ips_abort_init(ips_ha_t * ha, int index)
6880 ips_ha[index] = NULL;
6881 ips_sh[index] = NULL;
6885 /****************************************************************************/
6887 /* Routine Name: ips_shift_controllers */
6889 /* Routine Description: */
6890 /* helper function for ordering adapters */
6891 /****************************************************************************/
6893 ips_shift_controllers(int lowindex, int highindex)
6895 ips_ha_t *ha_sav = ips_ha[highindex];
6896 struct Scsi_Host *sh_sav = ips_sh[highindex];
6899 for (i = highindex; i > lowindex; i--) {
6900 ips_ha[i] = ips_ha[i - 1];
6901 ips_sh[i] = ips_sh[i - 1];
6902 ips_ha[i]->host_num = i;
6904 ha_sav->host_num = lowindex;
6905 ips_ha[lowindex] = ha_sav;
6906 ips_sh[lowindex] = sh_sav;
6909 /****************************************************************************/
6911 /* Routine Name: ips_order_controllers */
6913 /* Routine Description: */
6914 /* place controllers is the "proper" boot order */
6915 /****************************************************************************/
6917 ips_order_controllers(void)
6919 int i, j, tmp, position = 0;
6920 IPS_NVRAM_P5 *nvram;
6923 nvram = ips_ha[0]->nvram;
6925 if (nvram->adapter_order[0]) {
6926 for (i = 1; i <= nvram->adapter_order[0]; i++) {
6927 for (j = position; j < ips_num_controllers; j++) {
6928 switch (ips_ha[j]->ad_type) {
6929 case IPS_ADTYPE_SERVERAID6M:
6930 case IPS_ADTYPE_SERVERAID7M:
6931 if (nvram->adapter_order[i] == 'M') {
6932 ips_shift_controllers(position,
6937 case IPS_ADTYPE_SERVERAID4L:
6938 case IPS_ADTYPE_SERVERAID4M:
6939 case IPS_ADTYPE_SERVERAID4MX:
6940 case IPS_ADTYPE_SERVERAID4LX:
6941 if (nvram->adapter_order[i] == 'N') {
6942 ips_shift_controllers(position,
6947 case IPS_ADTYPE_SERVERAID6I:
6948 case IPS_ADTYPE_SERVERAID5I2:
6949 case IPS_ADTYPE_SERVERAID5I1:
6950 case IPS_ADTYPE_SERVERAID7k:
6951 if (nvram->adapter_order[i] == 'S') {
6952 ips_shift_controllers(position,
6957 case IPS_ADTYPE_SERVERAID:
6958 case IPS_ADTYPE_SERVERAID2:
6959 case IPS_ADTYPE_NAVAJO:
6960 case IPS_ADTYPE_KIOWA:
6961 case IPS_ADTYPE_SERVERAID3L:
6962 case IPS_ADTYPE_SERVERAID3:
6963 case IPS_ADTYPE_SERVERAID4H:
6964 if (nvram->adapter_order[i] == 'A') {
6965 ips_shift_controllers(position,
6975 /* if adapter_order[0], then ordering is complete */
6978 /* old bios, use older ordering */
6980 for (i = position; i < ips_num_controllers; i++) {
6981 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I2 ||
6982 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID5I1) {
6983 ips_shift_controllers(position, i);
6988 /* if there were no 5I cards, then don't do any extra ordering */
6991 for (i = position; i < ips_num_controllers; i++) {
6992 if (ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4L ||
6993 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4M ||
6994 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4LX ||
6995 ips_ha[i]->ad_type == IPS_ADTYPE_SERVERAID4MX) {
6996 ips_shift_controllers(position, i);
7004 /****************************************************************************/
7006 /* Routine Name: ips_register_scsi */
7008 /* Routine Description: */
7009 /* perform any registration and setup with the scsi layer */
7010 /****************************************************************************/
7012 ips_register_scsi(int index)
7014 struct Scsi_Host *sh;
7015 ips_ha_t *ha, *oldha = ips_ha[index];
7016 sh = scsi_host_alloc(&ips_driver_template, sizeof (ips_ha_t));
7018 IPS_PRINTK(KERN_WARNING, oldha->pcidev,
7019 "Unable to register controller with SCSI subsystem\n");
7023 memcpy(ha, oldha, sizeof (ips_ha_t));
7024 free_irq(oldha->irq, oldha);
7025 /* Install the interrupt handler with the new ha */
7026 if (request_irq(ha->irq, do_ipsintr, SA_SHIRQ, ips_name, ha)) {
7027 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7028 "Unable to install interrupt handler\n");
7036 IPS_SCSI_SET_DEVICE(sh, ha);
7038 /* Store away needed values for later use */
7039 sh->io_port = ha->io_addr;
7040 sh->n_io_port = ha->io_addr ? 255 : 0;
7041 sh->unique_id = (ha->io_addr) ? ha->io_addr : ha->mem_addr;
7043 sh->sg_tablesize = sh->hostt->sg_tablesize;
7044 sh->can_queue = sh->hostt->can_queue;
7045 sh->cmd_per_lun = sh->hostt->cmd_per_lun;
7046 sh->unchecked_isa_dma = sh->hostt->unchecked_isa_dma;
7047 sh->use_clustering = sh->hostt->use_clustering;
7049 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,7)
7050 sh->max_sectors = 128;
7053 sh->max_id = ha->ntargets;
7054 sh->max_lun = ha->nlun;
7055 sh->max_channel = ha->nbus - 1;
7056 sh->can_queue = ha->max_cmds - 1;
7058 IPS_ADD_HOST(sh, NULL);
7062 /*---------------------------------------------------------------------------*/
7063 /* Routine Name: ips_remove_device */
7065 /* Routine Description: */
7066 /* Remove one Adapter ( Hot Plugging ) */
7067 /*---------------------------------------------------------------------------*/
7068 static void __devexit
7069 ips_remove_device(struct pci_dev *pci_dev)
7072 struct Scsi_Host *sh;
7075 for (i = 0; i < IPS_MAX_ADAPTERS; i++) {
7078 if ((pci_dev->bus->number == ha->pcidev->bus->number) &&
7079 (pci_dev->devfn == ha->pcidev->devfn)) {
7087 /****************************************************************************/
7089 /* Routine Name: ips_module_init */
7091 /* Routine Description: */
7092 /* function called on module load */
7093 /****************************************************************************/
7095 ips_module_init(void)
7097 if (pci_module_init(&ips_pci_driver) < 0)
7099 ips_driver_template.module = THIS_MODULE;
7100 ips_order_controllers();
7101 if (IPS_REGISTER_HOSTS(&ips_driver_template)) {
7102 pci_unregister_driver(&ips_pci_driver);
7105 register_reboot_notifier(&ips_notifier);
7109 /****************************************************************************/
7111 /* Routine Name: ips_module_exit */
7113 /* Routine Description: */
7114 /* function called on module unload */
7115 /****************************************************************************/
7117 ips_module_exit(void)
7119 IPS_UNREGISTER_HOSTS(&ips_driver_template);
7120 pci_unregister_driver(&ips_pci_driver);
7121 unregister_reboot_notifier(&ips_notifier);
7124 module_init(ips_module_init);
7125 module_exit(ips_module_exit);
7127 /*---------------------------------------------------------------------------*/
7128 /* Routine Name: ips_insert_device */
7130 /* Routine Description: */
7131 /* Add One Adapter ( Hot Plug ) */
7134 /* 0 if Successful, else non-zero */
7135 /*---------------------------------------------------------------------------*/
7136 static int __devinit
7137 ips_insert_device(struct pci_dev *pci_dev, const struct pci_device_id *ent)
7142 METHOD_TRACE("ips_insert_device", 1);
7143 if (pci_enable_device(pci_dev))
7146 rc = ips_init_phase1(pci_dev, &index);
7148 rc = ips_init_phase2(index);
7151 if (ips_register_scsi(index)) {
7152 ips_free(ips_ha[index]);
7157 ips_num_controllers++;
7159 ips_next_controller = ips_num_controllers;
7163 /*---------------------------------------------------------------------------*/
7164 /* Routine Name: ips_init_phase1 */
7166 /* Routine Description: */
7167 /* Adapter Initialization */
7170 /* 0 if Successful, else non-zero */
7171 /*---------------------------------------------------------------------------*/
7173 ips_init_phase1(struct pci_dev *pci_dev, int *indexPtr)
7180 uint8_t revision_id;
7184 uint16_t subdevice_id;
7187 dma_addr_t dma_address;
7188 char __iomem *ioremap_ptr;
7189 char __iomem *mem_ptr;
7192 METHOD_TRACE("ips_init_phase1", 1);
7193 index = IPS_MAX_ADAPTERS;
7194 for (j = 0; j < IPS_MAX_ADAPTERS; j++) {
7195 if (ips_ha[j] == 0) {
7201 if (index >= IPS_MAX_ADAPTERS)
7204 /* stuff that we get in dev */
7206 bus = pci_dev->bus->number;
7207 func = pci_dev->devfn;
7209 /* Init MEM/IO addresses to 0 */
7215 for (j = 0; j < 2; j++) {
7216 if (!pci_resource_start(pci_dev, j))
7219 if (pci_resource_flags(pci_dev, j) & IORESOURCE_IO) {
7220 io_addr = pci_resource_start(pci_dev, j);
7221 io_len = pci_resource_len(pci_dev, j);
7223 mem_addr = pci_resource_start(pci_dev, j);
7224 mem_len = pci_resource_len(pci_dev, j);
7228 /* setup memory mapped area (if applicable) */
7233 if (!request_mem_region(mem_addr, mem_len, "ips")) {
7234 IPS_PRINTK(KERN_WARNING, pci_dev,
7235 "Couldn't allocate IO Memory space %x len %d.\n",
7240 base = mem_addr & PAGE_MASK;
7241 offs = mem_addr - base;
7242 ioremap_ptr = ioremap(base, PAGE_SIZE);
7243 mem_ptr = ioremap_ptr + offs;
7249 /* setup I/O mapped area (if applicable) */
7251 if (!request_region(io_addr, io_len, "ips")) {
7252 IPS_PRINTK(KERN_WARNING, pci_dev,
7253 "Couldn't allocate IO space %x len %d.\n",
7259 /* get the revision ID */
7260 if (pci_read_config_byte(pci_dev, PCI_REVISION_ID, &revision_id)) {
7261 IPS_PRINTK(KERN_WARNING, pci_dev, "Can't get revision id.\n");
7265 subdevice_id = pci_dev->subsystem_device;
7267 /* found a controller */
7268 ha = kmalloc(sizeof (ips_ha_t), GFP_KERNEL);
7270 IPS_PRINTK(KERN_WARNING, pci_dev,
7271 "Unable to allocate temporary ha struct\n");
7275 memset(ha, 0, sizeof (ips_ha_t));
7277 ips_sh[index] = NULL;
7281 /* Store info in HA structure */
7283 ha->io_addr = io_addr;
7284 ha->io_len = io_len;
7285 ha->mem_addr = mem_addr;
7286 ha->mem_len = mem_len;
7287 ha->mem_ptr = mem_ptr;
7288 ha->ioremap_ptr = ioremap_ptr;
7289 ha->host_num = (uint32_t) index;
7290 ha->revision_id = revision_id;
7291 ha->slot_num = PCI_SLOT(pci_dev->devfn);
7292 ha->device_id = pci_dev->device;
7293 ha->subdevice_id = subdevice_id;
7294 ha->pcidev = pci_dev;
7297 * Set the pci_dev's dma_mask. Not all adapters support 64bit
7298 * addressing so don't enable it if the adapter can't support
7299 * it! Also, don't use 64bit addressing if dma addresses
7300 * are guaranteed to be < 4G.
7302 if (IPS_ENABLE_DMA64 && IPS_HAS_ENH_SGLIST(ha) &&
7303 !pci_set_dma_mask(ha->pcidev, 0xffffffffffffffffULL)) {
7304 (ha)->flags |= IPS_HA_ENH_SG;
7306 if (pci_set_dma_mask(ha->pcidev, 0xffffffffULL) != 0) {
7307 printk(KERN_WARNING "Unable to set DMA Mask\n");
7308 return ips_abort_init(ha, index);
7311 if(ips_cd_boot && !ips_FlashData){
7312 ips_FlashData = pci_alloc_consistent(pci_dev, PAGE_SIZE << 7,
7316 ha->enq = pci_alloc_consistent(pci_dev, sizeof (IPS_ENQ),
7319 IPS_PRINTK(KERN_WARNING, pci_dev,
7320 "Unable to allocate host inquiry structure\n");
7321 return ips_abort_init(ha, index);
7324 ha->adapt = pci_alloc_consistent(pci_dev, sizeof (IPS_ADAPTER) +
7325 sizeof (IPS_IO_CMD), &dma_address);
7327 IPS_PRINTK(KERN_WARNING, pci_dev,
7328 "Unable to allocate host adapt & dummy structures\n");
7329 return ips_abort_init(ha, index);
7331 ha->adapt->hw_status_start = dma_address;
7332 ha->dummy = (void *) (ha->adapt + 1);
7336 ha->logical_drive_info = pci_alloc_consistent(pci_dev, sizeof (IPS_LD_INFO), &dma_address);
7337 if (!ha->logical_drive_info) {
7338 IPS_PRINTK(KERN_WARNING, pci_dev,
7339 "Unable to allocate logical drive info structure\n");
7340 return ips_abort_init(ha, index);
7342 ha->logical_drive_info_dma_addr = dma_address;
7345 ha->conf = kmalloc(sizeof (IPS_CONF), GFP_KERNEL);
7348 IPS_PRINTK(KERN_WARNING, pci_dev,
7349 "Unable to allocate host conf structure\n");
7350 return ips_abort_init(ha, index);
7353 ha->nvram = kmalloc(sizeof (IPS_NVRAM_P5), GFP_KERNEL);
7356 IPS_PRINTK(KERN_WARNING, pci_dev,
7357 "Unable to allocate host NVRAM structure\n");
7358 return ips_abort_init(ha, index);
7361 ha->subsys = kmalloc(sizeof (IPS_SUBSYS), GFP_KERNEL);
7364 IPS_PRINTK(KERN_WARNING, pci_dev,
7365 "Unable to allocate host subsystem structure\n");
7366 return ips_abort_init(ha, index);
7369 /* the ioctl buffer is now used during adapter initialization, so its
7370 * successful allocation is now required */
7371 if (ips_ioctlsize < PAGE_SIZE)
7372 ips_ioctlsize = PAGE_SIZE;
7374 ha->ioctl_data = pci_alloc_consistent(pci_dev, ips_ioctlsize,
7375 &ha->ioctl_busaddr);
7376 ha->ioctl_len = ips_ioctlsize;
7377 if (!ha->ioctl_data) {
7378 IPS_PRINTK(KERN_WARNING, pci_dev,
7379 "Unable to allocate IOCTL data\n");
7380 return ips_abort_init(ha, index);
7386 ips_setup_funclist(ha);
7388 if ((IPS_IS_MORPHEUS(ha)) || (IPS_IS_MARCO(ha))) {
7389 /* If Morpheus appears dead, reset it */
7390 IsDead = readl(ha->mem_ptr + IPS_REG_I960_MSG1);
7391 if (IsDead == 0xDEADBEEF) {
7392 ips_reset_morpheus(ha);
7397 * Initialize the card if it isn't already
7400 if (!(*ha->func.isinit) (ha)) {
7401 if (!(*ha->func.init) (ha)) {
7403 * Initialization failed
7405 IPS_PRINTK(KERN_WARNING, pci_dev,
7406 "Unable to initialize controller\n");
7407 return ips_abort_init(ha, index);
7415 /*---------------------------------------------------------------------------*/
7416 /* Routine Name: ips_init_phase2 */
7418 /* Routine Description: */
7419 /* Adapter Initialization Phase 2 */
7422 /* 0 if Successful, else non-zero */
7423 /*---------------------------------------------------------------------------*/
7425 ips_init_phase2(int index)
7431 METHOD_TRACE("ips_init_phase2", 1);
7433 ips_ha[index] = NULL;
7437 /* Install the interrupt handler */
7438 if (request_irq(ha->irq, do_ipsintr, SA_SHIRQ, ips_name, ha)) {
7439 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7440 "Unable to install interrupt handler\n");
7441 return ips_abort_init(ha, index);
7445 * Allocate a temporary SCB for initialization
7448 if (!ips_allocatescbs(ha)) {
7449 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7450 "Unable to allocate a CCB\n");
7451 free_irq(ha->irq, ha);
7452 return ips_abort_init(ha, index);
7455 if (!ips_hainit(ha)) {
7456 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7457 "Unable to initialize controller\n");
7458 free_irq(ha->irq, ha);
7459 return ips_abort_init(ha, index);
7461 /* Free the temporary SCB */
7462 ips_deallocatescbs(ha, 1);
7465 if (!ips_allocatescbs(ha)) {
7466 IPS_PRINTK(KERN_WARNING, ha->pcidev,
7467 "Unable to allocate CCBs\n");
7468 free_irq(ha->irq, ha);
7469 return ips_abort_init(ha, index);
7475 #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,9)
7476 MODULE_LICENSE("GPL");
7479 MODULE_DESCRIPTION("IBM ServeRAID Adapter Driver " IPS_VER_STRING);
7481 #ifdef MODULE_VERSION
7482 MODULE_VERSION(IPS_VER_STRING);
7487 * Overrides for Emacs so that we almost follow Linus's tabbing style.
7488 * Emacs will notice this stuff at the end of the file and automatically
7489 * adjust the settings for this buffer only. This must remain at the end
7491 * ---------------------------------------------------------------------------
7494 * c-brace-imaginary-offset: 0
7495 * c-brace-offset: -2
7496 * c-argdecl-indent: 2
7497 * c-label-offset: -2
7498 * c-continued-statement-offset: 2
7499 * c-continued-brace-offset: 0
7500 * indent-tabs-mode: nil