2 * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
3 * Copyright (c) 2000-2001 Adaptec Corporation
6 * TERMS AND CONDITIONS OF USE
8 * Redistribution and use in source form, with or without modification, are
9 * permitted provided that redistributions of source code must retain the
10 * above copyright notice, this list of conditions and the following disclaimer.
12 * This software is provided `as is' by Adaptec and any express or implied
13 * warranties, including, but not limited to, the implied warranties of
14 * merchantability and fitness for a particular purpose, are disclaimed. In no
15 * event shall Adaptec be liable for any direct, indirect, incidental, special,
16 * exemplary or consequential damages (including, but not limited to,
17 * procurement of substitute goods or services; loss of use, data, or profits;
18 * or business interruptions) however caused and on any theory of liability,
19 * whether in contract, strict liability, or tort (including negligence or
20 * otherwise) arising in any way out of the use of this driver software, even
21 * if advised of the possibility of such damage.
23 * SCSI I2O host adapter driver
25 * V1.10 2004/05/05 scottl@freebsd.org
26 * - Massive cleanup of the driver to remove dead code and
27 * non-conformant style.
28 * - Removed most i386-specific code to make it more portable.
29 * - Converted to the bus_space API.
30 * V1.08 2001/08/21 Mark_Salyzyn@adaptec.com
31 * - The 2000S and 2005S do not initialize on some machines,
32 * increased timeout to 255ms from 50ms for the StatusGet
34 * V1.07 2001/05/22 Mark_Salyzyn@adaptec.com
35 * - I knew this one was too good to be true. The error return
36 * on ioctl commands needs to be compared to CAM_REQ_CMP, not
37 * to the bit masked status.
38 * V1.06 2001/05/08 Mark_Salyzyn@adaptec.com
39 * - The 2005S that was supported is affectionately called the
40 * Conjoined BAR Firmware. In order to support RAID-5 in a
41 * 16MB low-cost configuration, Firmware was forced to go
42 * to a Split BAR Firmware. This requires a separate IOP and
43 * Messaging base address.
44 * V1.05 2001/04/25 Mark_Salyzyn@adaptec.com
45 * - Handle support for 2005S Zero Channel RAID solution.
46 * - System locked up if the Adapter locked up. Do not try
47 * to send other commands if the resetIOP command fails. The
48 * fail outstanding command discovery loop was flawed as the
49 * removal of the command from the list prevented discovering
51 * - Comment changes to clarify driver.
52 * - SysInfo searched for an EATA SmartROM, not an I2O SmartROM.
53 * - We do not use the AC_FOUND_DEV event because of I2O.
55 * V1.04 2000/09/22 Mark_Salyzyn@adaptec.com, msmith@freebsd.org,
56 * lampa@fee.vutbr.cz and Scott_Long@adaptec.com.
57 * - Removed support for PM1554, PM2554 and PM2654 in Mode-0
58 * mode as this is confused with competitor adapters in run
60 * - critical locking needed in ASR_ccbAdd and ASR_ccbRemove
61 * to prevent operating system panic.
62 * - moved default major number to 154 from 97.
63 * V1.03 2000/07/12 Mark_Salyzyn@adaptec.com
64 * - The controller is not actually an ASR (Adaptec SCSI RAID)
65 * series that is visible, it's more of an internal code name.
66 * remove any visible references within reason for now.
67 * - bus_ptr->LUN was not correctly zeroed when initially
68 * allocated causing a possible panic of the operating system
70 * V1.02 2000/06/26 Mark_Salyzyn@adaptec.com
71 * - Code always fails for ASR_getTid affecting performance.
72 * - initiated a set of changes that resulted from a formal
73 * code inspection by Mark_Salyzyn@adaptec.com,
74 * George_Dake@adaptec.com, Jeff_Zeak@adaptec.com,
75 * Martin_Wilson@adaptec.com and Vincent_Trandoan@adaptec.com.
76 * Their findings were focussed on the LCT & TID handler, and
77 * all resulting changes were to improve code readability,
78 * consistency or have a positive effect on performance.
79 * V1.01 2000/06/14 Mark_Salyzyn@adaptec.com
80 * - Passthrough returned an incorrect error.
81 * - Passthrough did not migrate the intrinsic scsi layer wakeup
82 * on command completion.
83 * - generate control device nodes using make_dev and delete_dev.
84 * - Performance affected by TID caching reallocing.
85 * - Made suggested changes by Justin_Gibbs@adaptec.com
86 * - use splcam instead of splbio.
87 * - use cam_imask instead of bio_imask.
88 * - use u_int8_t instead of u_char.
89 * - use u_int16_t instead of u_short.
90 * - use u_int32_t instead of u_long where appropriate.
91 * - use 64 bit context handler instead of 32 bit.
92 * - create_ccb should only allocate the worst case
93 * requirements for the driver since CAM may evolve
94 * making union ccb much larger than needed here.
95 * renamed create_ccb to asr_alloc_ccb.
96 * - go nutz justifying all debug prints as macros
97 * defined at the top and remove unsightly ifdefs.
98 * - INLINE STATIC viewed as confusing. Historically
99 * utilized to affect code performance and debug
100 * issues in OS, Compiler or OEM specific situations.
101 * V1.00 2000/05/31 Mark_Salyzyn@adaptec.com
102 * - Ported from FreeBSD 2.2.X DPT I2O driver.
103 * changed struct scsi_xfer to union ccb/struct ccb_hdr
104 * changed variable name xs to ccb
105 * changed struct scsi_link to struct cam_path
106 * changed struct scsibus_data to struct cam_sim
107 * stopped using fordriver for holding on to the TID
108 * use proprietary packet creation instead of scsi_inquire
109 * CAM layer sends synchronize commands.
111 * $FreeBSD: src/sys/dev/asr/asr.c,v 1.90 2011/10/13 20:06:19 marius Exp $
114 #include <sys/param.h> /* TRUE=1 and FALSE=0 defined here */
115 #include <sys/kernel.h>
116 #include <sys/module.h>
117 #include <sys/systm.h>
118 #include <sys/malloc.h>
119 #include <sys/conf.h>
120 #include <sys/priv.h>
121 #include <sys/proc.h>
123 #include <sys/rman.h>
124 #include <sys/stat.h>
125 #include <sys/device.h>
126 #include <sys/thread2.h>
127 #include <sys/bus_dma.h>
129 #include <bus/cam/cam.h>
130 #include <bus/cam/cam_ccb.h>
131 #include <bus/cam/cam_sim.h>
132 #include <bus/cam/cam_xpt_sim.h>
133 #include <bus/cam/cam_xpt_periph.h>
135 #include <bus/cam/scsi/scsi_all.h>
136 #include <bus/cam/scsi/scsi_message.h>
141 #include <machine/vmparam.h>
143 #include <bus/pci/pcivar.h>
144 #include <bus/pci/pcireg.h>
146 #define osdSwap4(x) ((u_long)ntohl((u_long)(x)))
147 #define KVTOPHYS(x) vtophys(x)
148 #include <dev/raid/asr/dptalign.h>
149 #include <dev/raid/asr/i2oexec.h>
150 #include <dev/raid/asr/i2obscsi.h>
151 #include <dev/raid/asr/i2odpt.h>
152 #include <dev/raid/asr/i2oadptr.h>
154 #include <dev/raid/asr/sys_info.h>
156 #define ASR_VERSION 1
157 #define ASR_REVISION '1'
158 #define ASR_SUBREVISION '0'
161 #define ASR_YEAR (2004 - 1980)
164 * Debug macros to reduce the unsightly ifdefs
166 #if (defined(DEBUG_ASR) || defined(DEBUG_ASR_USR_CMD) || defined(DEBUG_ASR_CMD))
168 debug_asr_message(PI2O_MESSAGE_FRAME message)
170 u_int32_t * pointer = (u_int32_t *)message;
171 u_int32_t length = I2O_MESSAGE_FRAME_getMessageSize(message);
172 u_int32_t counter = 0;
175 kprintf("%08lx%c", (u_long)*(pointer++),
176 (((++counter & 7) == 0) || (length == 0)) ? '\n' : ' ');
179 #endif /* DEBUG_ASR || DEBUG_ASR_USR_CMD || DEBUG_ASR_CMD */
182 /* Breaks on none STDC based compilers :-( */
183 #define debug_asr_printf(fmt,args...) kprintf(fmt, ##args)
184 #define debug_asr_dump_message(message) debug_asr_message(message)
185 #define debug_asr_print_path(ccb) xpt_print_path(ccb->ccb_h.path);
186 #else /* DEBUG_ASR */
187 #define debug_asr_printf(fmt,args...)
188 #define debug_asr_dump_message(message)
189 #define debug_asr_print_path(ccb)
190 #endif /* DEBUG_ASR */
193 * If DEBUG_ASR_CMD is defined:
194 * 0 - Display incoming SCSI commands
195 * 1 - add in a quick character before queueing.
196 * 2 - add in outgoing message frames.
198 #if (defined(DEBUG_ASR_CMD))
199 #define debug_asr_cmd_printf(fmt,args...) kprintf(fmt,##args)
201 debug_asr_dump_ccb(union ccb *ccb)
203 u_int8_t *cp = (unsigned char *)&(ccb->csio.cdb_io);
204 int len = ccb->csio.cdb_len;
207 debug_asr_cmd_printf (" %02x", *(cp++));
211 #if (DEBUG_ASR_CMD > 0)
212 #define debug_asr_cmd1_printf debug_asr_cmd_printf
214 #define debug_asr_cmd1_printf(fmt,args...)
216 #if (DEBUG_ASR_CMD > 1)
217 #define debug_asr_cmd2_printf debug_asr_cmd_printf
218 #define debug_asr_cmd2_dump_message(message) debug_asr_message(message)
220 #define debug_asr_cmd2_printf(fmt,args...)
221 #define debug_asr_cmd2_dump_message(message)
223 #else /* DEBUG_ASR_CMD */
224 #define debug_asr_cmd_printf(fmt,args...)
225 #define debug_asr_dump_ccb(ccb)
226 #define debug_asr_cmd1_printf(fmt,args...)
227 #define debug_asr_cmd2_printf(fmt,args...)
228 #define debug_asr_cmd2_dump_message(message)
229 #endif /* DEBUG_ASR_CMD */
231 #if (defined(DEBUG_ASR_USR_CMD))
232 #define debug_usr_cmd_printf(fmt,args...) kprintf(fmt,##args)
233 #define debug_usr_cmd_dump_message(message) debug_usr_message(message)
234 #else /* DEBUG_ASR_USR_CMD */
235 #define debug_usr_cmd_printf(fmt,args...)
236 #define debug_usr_cmd_dump_message(message)
237 #endif /* DEBUG_ASR_USR_CMD */
239 #ifdef ASR_IOCTL_COMPAT
240 #define dsDescription_size 46 /* Snug as a bug in a rug */
241 #endif /* ASR_IOCTL_COMPAT */
243 #include "dev/raid/asr/dptsig.h"
245 static dpt_sig_S ASR_sig = {
246 { 'd', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, PROC_INTEL,
247 PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM, FT_HBADRVR, 0,
248 OEM_DPT, OS_FREE_BSD, CAP_ABOVE16MB, DEV_ALL, ADF_ALL_SC5,
249 0, 0, ASR_VERSION, ASR_REVISION, ASR_SUBREVISION,
250 ASR_MONTH, ASR_DAY, ASR_YEAR,
251 /* 01234567890123456789012345678901234567890123456789 < 50 chars */
252 "Adaptec FreeBSD 4.0.0 Unix SCSI I2O HBA Driver"
253 /* ^^^^^ asr_attach alters these to match OS */
256 /* Configuration Definitions */
258 #define SG_SIZE 58 /* Scatter Gather list Size */
259 #define MAX_TARGET_ID 126 /* Maximum Target ID supported */
260 #define MAX_LUN 255 /* Maximum LUN Supported */
261 #define MAX_CHANNEL 7 /* Maximum Channel # Supported by driver */
262 #define MAX_INBOUND 2000 /* Max CCBs, Also Max Queue Size */
263 #define MAX_OUTBOUND 256 /* Maximum outbound frames/adapter */
264 #define MAX_INBOUND_SIZE 512 /* Maximum inbound frame size */
265 #define MAX_MAP 4194304L /* Maximum mapping size of IOP */
266 /* Also serves as the minimum map for */
267 /* the 2005S zero channel RAID product */
269 /* I2O register set */
270 #define I2O_REG_STATUS 0x30
271 #define I2O_REG_MASK 0x34
272 #define I2O_REG_TOFIFO 0x40
273 #define I2O_REG_FROMFIFO 0x44
275 #define Mask_InterruptsDisabled 0x08
278 * A MIX of performance and space considerations for TID lookups
280 typedef u_int16_t tid_t;
283 u_int32_t size; /* up to MAX_LUN */
288 u_int32_t size; /* up to MAX_TARGET */
293 * Don't play games with the ccb any more, use the CAM ccb
297 struct Asr_status_mem {
298 I2O_EXEC_STATUS_GET_REPLY status;
302 /**************************************************************************
303 ** ASR Host Adapter structure - One Structure For Each Host Adapter That **
304 ** Is Configured Into The System. The Structure Supplies Configuration **
305 ** Information, Status Info, Queue Info And An Active CCB List Pointer. **
306 ***************************************************************************/
308 typedef struct Asr_softc {
311 u_long ha_Base; /* base port for each board */
312 bus_size_t ha_blinkLED;
313 bus_space_handle_t ha_i2o_bhandle;
314 bus_space_tag_t ha_i2o_btag;
315 bus_space_handle_t ha_frame_bhandle;
316 bus_space_tag_t ha_frame_btag;
317 I2O_IOP_ENTRY ha_SystemTable;
318 LIST_HEAD(,ccb_hdr) ha_ccb; /* ccbs in use */
320 bus_dma_tag_t ha_parent_dmat;
321 bus_dma_tag_t ha_statusmem_dmat;
322 bus_dmamap_t ha_statusmem_dmamap;
323 struct Asr_status_mem * ha_statusmem;
324 u_int32_t ha_rstatus_phys;
325 u_int32_t ha_status_phys;
326 struct cam_path * ha_path[MAX_CHANNEL+1];
327 struct cam_sim * ha_sim[MAX_CHANNEL+1];
328 struct resource * ha_mem_res;
329 struct resource * ha_mes_res;
330 struct resource * ha_irq_res;
332 PI2O_LCT ha_LCT; /* Complete list of devices */
333 #define le_type IdentityTag[0]
336 #define I2O_SCSI 0x00
337 #define I2O_PORT 0x80
338 #define I2O_UNKNOWN 0x7F
339 #define le_bus IdentityTag[1]
340 #define le_target IdentityTag[2]
341 #define le_lun IdentityTag[3]
342 target2lun_t * ha_targets[MAX_CHANNEL+1];
343 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME ha_Msgs;
346 u_int8_t ha_in_reset;
347 #define HA_OPERATIONAL 0
348 #define HA_IN_RESET 1
349 #define HA_OFF_LINE 2
350 #define HA_OFF_LINE_RECOVERY 3
351 /* Configuration information */
352 /* The target id maximums we take */
353 u_int8_t ha_MaxBus; /* Maximum bus */
354 u_int8_t ha_MaxId; /* Maximum target ID */
355 u_int8_t ha_MaxLun; /* Maximum target LUN */
356 u_int8_t ha_SgSize; /* Max SG elements */
357 u_int8_t ha_pciBusNum;
358 u_int8_t ha_pciDeviceNum;
359 u_int8_t ha_adapter_target[MAX_CHANNEL+1];
360 u_int16_t ha_QueueSize; /* Max outstanding commands */
361 u_int16_t ha_Msgs_Count;
363 /* Links into other parents and HBAs */
364 struct Asr_softc * ha_next; /* HBA list */
365 struct cdev *ha_devt;
368 static Asr_softc_t *Asr_softc_list;
371 * Prototypes of the routines we have in this object.
374 /* I2O HDM interface */
375 static int asr_probe(device_t dev);
376 static int asr_attach(device_t dev);
378 static d_ioctl_t asr_ioctl;
379 static d_open_t asr_open;
380 static d_close_t asr_close;
381 static int asr_intr(Asr_softc_t *sc);
382 static void asr_timeout(void *arg);
383 static int ASR_init(Asr_softc_t *sc);
384 static int ASR_acquireLct(Asr_softc_t *sc);
385 static int ASR_acquireHrt(Asr_softc_t *sc);
386 static void asr_action(struct cam_sim *sim, union ccb *ccb);
387 static void asr_poll(struct cam_sim *sim);
388 static int ASR_queue(Asr_softc_t *sc, PI2O_MESSAGE_FRAME Message);
391 * Here is the auto-probe structure used to nest our tests appropriately
392 * during the startup phase of the operating system.
394 static device_method_t asr_methods[] = {
395 DEVMETHOD(device_probe, asr_probe),
396 DEVMETHOD(device_attach, asr_attach),
400 static driver_t asr_driver = {
406 static devclass_t asr_devclass;
407 DRIVER_MODULE(asr, pci, asr_driver, asr_devclass, NULL, NULL);
408 MODULE_VERSION(asr, 1);
409 MODULE_DEPEND(asr, pci, 1, 1, 1);
410 MODULE_DEPEND(asr, cam, 1, 1, 1);
413 * devsw for asr hba driver
415 * only ioctl is used. the sd driver provides all other access.
417 static struct dev_ops asr_ops = {
420 .d_close = asr_close,
421 .d_ioctl = asr_ioctl,
424 /* I2O support routines */
426 static __inline u_int32_t
427 asr_get_FromFIFO(Asr_softc_t *sc)
429 return (bus_space_read_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle,
433 static __inline u_int32_t
434 asr_get_ToFIFO(Asr_softc_t *sc)
436 return (bus_space_read_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle,
440 static __inline u_int32_t
441 asr_get_intr(Asr_softc_t *sc)
443 return (bus_space_read_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle,
447 static __inline u_int32_t
448 asr_get_status(Asr_softc_t *sc)
450 return (bus_space_read_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle,
455 asr_set_FromFIFO(Asr_softc_t *sc, u_int32_t val)
457 bus_space_write_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle, I2O_REG_FROMFIFO,
462 asr_set_ToFIFO(Asr_softc_t *sc, u_int32_t val)
464 bus_space_write_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle, I2O_REG_TOFIFO,
469 asr_set_intr(Asr_softc_t *sc, u_int32_t val)
471 bus_space_write_4(sc->ha_i2o_btag, sc->ha_i2o_bhandle, I2O_REG_MASK,
476 asr_set_frame(Asr_softc_t *sc, void *frame, u_int32_t offset, int len)
478 bus_space_write_region_4(sc->ha_frame_btag, sc->ha_frame_bhandle,
479 offset, (u_int32_t *)frame, len);
483 * Fill message with default.
485 static PI2O_MESSAGE_FRAME
486 ASR_fillMessage(void *Message, u_int16_t size)
488 PI2O_MESSAGE_FRAME Message_Ptr;
490 Message_Ptr = (I2O_MESSAGE_FRAME *)Message;
491 bzero(Message_Ptr, size);
492 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11);
493 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
494 (size + sizeof(U32) - 1) >> 2);
495 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
496 KASSERT(Message_Ptr != NULL, ("Message_Ptr == NULL"));
497 return (Message_Ptr);
498 } /* ASR_fillMessage */
500 #define EMPTY_QUEUE (0xffffffff)
503 ASR_getMessage(Asr_softc_t *sc)
507 MessageOffset = asr_get_ToFIFO(sc);
508 if (MessageOffset == EMPTY_QUEUE)
509 MessageOffset = asr_get_ToFIFO(sc);
511 return (MessageOffset);
512 } /* ASR_getMessage */
514 /* Issue a polled command */
516 ASR_initiateCp(Asr_softc_t *sc, PI2O_MESSAGE_FRAME Message)
518 U32 Mask = 0xffffffff;
523 * ASR_initiateCp is only used for synchronous commands and will
524 * be made more resiliant to adapter delays since commands like
525 * resetIOP can cause the adapter to be deaf for a little time.
527 while (((MessageOffset = ASR_getMessage(sc)) == EMPTY_QUEUE)
531 if (MessageOffset != EMPTY_QUEUE) {
532 asr_set_frame(sc, Message, MessageOffset,
533 I2O_MESSAGE_FRAME_getMessageSize(Message));
535 * Disable the Interrupts
537 Mask = asr_get_intr(sc);
538 asr_set_intr(sc, Mask | Mask_InterruptsDisabled);
539 asr_set_ToFIFO(sc, MessageOffset);
542 } /* ASR_initiateCp */
548 ASR_resetIOP(Asr_softc_t *sc)
550 I2O_EXEC_IOP_RESET_MESSAGE Message;
551 PI2O_EXEC_IOP_RESET_MESSAGE Message_Ptr;
556 * Build up our copy of the Message.
558 Message_Ptr = (PI2O_EXEC_IOP_RESET_MESSAGE)ASR_fillMessage(&Message,
559 sizeof(I2O_EXEC_IOP_RESET_MESSAGE));
560 I2O_EXEC_IOP_RESET_MESSAGE_setFunction(Message_Ptr, I2O_EXEC_IOP_RESET);
562 * Reset the Reply Status
564 Reply_Ptr = &sc->ha_statusmem->rstatus;
566 I2O_EXEC_IOP_RESET_MESSAGE_setStatusWordLowAddress(Message_Ptr,
567 sc->ha_rstatus_phys);
569 * Send the Message out
571 if ((Old = ASR_initiateCp(sc, (PI2O_MESSAGE_FRAME)Message_Ptr)) !=
574 * Wait for a response (Poll), timeouts are dangerous if
575 * the card is truly responsive. We assume response in 2s.
577 u_int8_t Delay = 200;
579 while ((*Reply_Ptr == 0) && (--Delay != 0)) {
583 * Re-enable the interrupts.
585 asr_set_intr(sc, Old);
586 KASSERT(*Reply_Ptr != 0, ("*Reply_Ptr == 0"));
589 KASSERT(Old != 0xffffffff, ("Old == -1"));
594 * Get the curent state of the adapter
596 static PI2O_EXEC_STATUS_GET_REPLY
597 ASR_getStatus(Asr_softc_t *sc)
599 I2O_EXEC_STATUS_GET_MESSAGE Message;
600 PI2O_EXEC_STATUS_GET_MESSAGE Message_Ptr;
601 PI2O_EXEC_STATUS_GET_REPLY buffer;
605 * Build up our copy of the Message.
607 Message_Ptr = (PI2O_EXEC_STATUS_GET_MESSAGE)ASR_fillMessage(&Message,
608 sizeof(I2O_EXEC_STATUS_GET_MESSAGE));
609 I2O_EXEC_STATUS_GET_MESSAGE_setFunction(Message_Ptr,
610 I2O_EXEC_STATUS_GET);
611 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferAddressLow(Message_Ptr,
613 /* This one is a Byte Count */
614 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferLength(Message_Ptr,
615 sizeof(I2O_EXEC_STATUS_GET_REPLY));
617 * Reset the Reply Status
619 buffer = &sc->ha_statusmem->status;
620 bzero(buffer, sizeof(I2O_EXEC_STATUS_GET_REPLY));
622 * Send the Message out
624 if ((Old = ASR_initiateCp(sc, (PI2O_MESSAGE_FRAME)Message_Ptr)) !=
627 * Wait for a response (Poll), timeouts are dangerous if
628 * the card is truly responsive. We assume response in 50ms.
630 u_int8_t Delay = 255;
632 while (*((U8 * volatile)&(buffer->SyncByte)) == 0) {
640 * Re-enable the interrupts.
642 asr_set_intr(sc, Old);
646 } /* ASR_getStatus */
649 * Check if the device is a SCSI I2O HBA, and add it to the list.
653 * Probe for ASR controller. If we find it, we will use it.
657 asr_probe(device_t dev)
661 id = (pci_get_device(dev) << 16) | pci_get_vendor(dev);
662 if ((id == 0xA5011044) || (id == 0xA5111044)) {
663 device_set_desc(dev, "Adaptec Caching SCSI RAID");
664 return (BUS_PROBE_DEFAULT);
669 static __inline union asr_ccb *
670 asr_alloc_ccb(Asr_softc_t *sc)
672 union asr_ccb *new_ccb;
674 new_ccb = xpt_alloc_ccb();
675 new_ccb->ccb_h.pinfo.priority = 1;
676 new_ccb->ccb_h.pinfo.index = CAM_UNQUEUED_INDEX;
677 new_ccb->ccb_h.spriv_ptr0 = sc;
680 } /* asr_alloc_ccb */
683 asr_free_ccb(union asr_ccb *free_ccb)
685 xpt_free_ccb(&free_ccb->ccb_h);
689 * Print inquiry data `carefully'
692 ASR_prstring(u_int8_t *s, int len)
694 while ((--len >= 0) && (*s) && (*s != ' ') && (*s != '-')) {
695 kprintf ("%c", *(s++));
700 * Send a message synchronously and without Interrupt to a ccb.
703 ASR_queue_s(union asr_ccb *ccb, PI2O_MESSAGE_FRAME Message)
706 Asr_softc_t *sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
709 * We do not need any (optional byteswapping) method access to
710 * the Initiator context field.
712 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
714 /* Prevent interrupt service */
716 Mask = asr_get_intr(sc);
717 asr_set_intr(sc, Mask | Mask_InterruptsDisabled);
719 if (ASR_queue(sc, Message) == EMPTY_QUEUE) {
720 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
721 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
725 * Wait for this board to report a finished instruction.
727 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
731 /* Re-enable Interrupts */
732 asr_set_intr(sc, Mask);
735 return (ccb->ccb_h.status);
739 * Send a message synchronously to an Asr_softc_t.
742 ASR_queue_c(Asr_softc_t *sc, PI2O_MESSAGE_FRAME Message)
747 if ((ccb = asr_alloc_ccb (sc)) == NULL) {
748 return (CAM_REQUEUE_REQ);
751 status = ASR_queue_s (ccb, Message);
759 * Add the specified ccb to the active queue
762 ASR_ccbAdd(Asr_softc_t *sc, union asr_ccb *ccb)
765 LIST_INSERT_HEAD(&(sc->ha_ccb), &(ccb->ccb_h), sim_links.le);
766 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
767 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT) {
769 * RAID systems can take considerable time to
770 * complete some commands given the large cache
771 * flashes switching from write back to write thru.
773 ccb->ccb_h.timeout = 6 * 60 * 1000;
775 callout_reset(ccb->ccb_h.timeout_ch,
776 (ccb->ccb_h.timeout * hz) / 1000,
783 * Remove the specified ccb from the active queue.
786 ASR_ccbRemove(Asr_softc_t *sc, union asr_ccb *ccb)
789 callout_stop(ccb->ccb_h.timeout_ch);
790 LIST_REMOVE(&(ccb->ccb_h), sim_links.le);
792 } /* ASR_ccbRemove */
795 * Fail all the active commands, so they get re-issued by the operating
799 ASR_failActiveCommands(Asr_softc_t *sc)
805 * We do not need to inform the CAM layer that we had a bus
806 * reset since we manage it on our own, this also prevents the
807 * SCSI_DELAY settling that would be required on other systems.
808 * The `SCSI_DELAY' has already been handled by the card via the
809 * acquisition of the LCT table while we are at CAM priority level.
810 * for (int bus = 0; bus <= sc->ha_MaxBus; ++bus) {
811 * xpt_async (AC_BUS_RESET, sc->ha_path[bus], NULL);
814 while ((ccb = LIST_FIRST(&(sc->ha_ccb))) != NULL) {
815 ASR_ccbRemove (sc, (union asr_ccb *)ccb);
817 ccb->status &= ~CAM_STATUS_MASK;
818 ccb->status |= CAM_REQUEUE_REQ;
819 /* Nothing Transfered */
820 ((struct ccb_scsiio *)ccb)->resid
821 = ((struct ccb_scsiio *)ccb)->dxfer_len;
824 xpt_done ((union ccb *)ccb);
830 } /* ASR_failActiveCommands */
833 * The following command causes the HBA to reset the specific bus
836 ASR_resetBus(Asr_softc_t *sc, int bus)
838 I2O_HBA_BUS_RESET_MESSAGE Message;
839 I2O_HBA_BUS_RESET_MESSAGE *Message_Ptr;
840 PI2O_LCT_ENTRY Device;
842 Message_Ptr = (I2O_HBA_BUS_RESET_MESSAGE *)ASR_fillMessage(&Message,
843 sizeof(I2O_HBA_BUS_RESET_MESSAGE));
844 I2O_MESSAGE_FRAME_setFunction(&Message_Ptr->StdMessageFrame,
846 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
847 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
849 if (((Device->le_type & I2O_PORT) != 0)
850 && (Device->le_bus == bus)) {
851 I2O_MESSAGE_FRAME_setTargetAddress(
852 &Message_Ptr->StdMessageFrame,
853 I2O_LCT_ENTRY_getLocalTID(Device));
854 /* Asynchronous command, with no expectations */
855 (void)ASR_queue(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
862 ASR_getBlinkLedCode(Asr_softc_t *sc)
869 blink = bus_space_read_1(sc->ha_frame_btag,
870 sc->ha_frame_bhandle, sc->ha_blinkLED + 1);
874 blink = bus_space_read_1(sc->ha_frame_btag,
875 sc->ha_frame_bhandle, sc->ha_blinkLED);
877 } /* ASR_getBlinkCode */
880 * Determine the address of an TID lookup. Must be done at high priority
881 * since the address can be changed by other threads of execution.
883 * Returns NULL pointer if not indexible (but will attempt to generate
884 * an index if `new_entry' flag is set to TRUE).
886 * All addressible entries are to be guaranteed zero if never initialized.
889 ASR_getTidAddress(Asr_softc_t *sc, int bus, int target, int lun, int new_entry)
891 target2lun_t *bus_ptr;
892 lun2tid_t *target_ptr;
896 * Validity checking of incoming parameters. More of a bound
897 * expansion limit than an issue with the code dealing with the
900 * sc must be valid before it gets here, so that check could be
901 * dropped if speed a critical issue.
904 || (bus > MAX_CHANNEL)
905 || (target > sc->ha_MaxId)
906 || (lun > sc->ha_MaxLun)) {
907 debug_asr_printf("(%lx,%d,%d,%d) target out of range\n",
908 (u_long)sc, bus, target, lun);
912 * See if there is an associated bus list.
914 * for performance, allocate in size of BUS_CHUNK chunks.
915 * BUS_CHUNK must be a power of two. This is to reduce
916 * fragmentation effects on the allocations.
919 new_size = roundup2(target, BUS_CHUNK);
920 if ((bus_ptr = sc->ha_targets[bus]) == NULL) {
922 * Allocate a new structure?
923 * Since one element in structure, the +1
924 * needed for size has been abstracted.
926 if ((new_entry == FALSE)
927 || ((sc->ha_targets[bus] = bus_ptr = (target2lun_t *)kmalloc (
928 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
929 M_TEMP, M_WAITOK | M_ZERO))
931 debug_asr_printf("failed to allocate bus list\n");
934 bus_ptr->size = new_size + 1;
935 } else if (bus_ptr->size <= new_size) {
936 target2lun_t * new_bus_ptr;
939 * Reallocate a new structure?
940 * Since one element in structure, the +1
941 * needed for size has been abstracted.
943 if ((new_entry == FALSE)
944 || ((new_bus_ptr = (target2lun_t *)kmalloc (
945 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
946 M_TEMP, M_WAITOK | M_ZERO)) == NULL)) {
947 debug_asr_printf("failed to reallocate bus list\n");
951 * Copy the whole thing, safer, simpler coding
952 * and not really performance critical at this point.
954 bcopy(bus_ptr, new_bus_ptr, sizeof(*bus_ptr)
955 + (sizeof(bus_ptr->LUN) * (bus_ptr->size - 1)));
956 sc->ha_targets[bus] = new_bus_ptr;
957 kfree(bus_ptr, M_TEMP);
958 bus_ptr = new_bus_ptr;
959 bus_ptr->size = new_size + 1;
962 * We now have the bus list, lets get to the target list.
963 * Since most systems have only *one* lun, we do not allocate
964 * in chunks as above, here we allow one, then in chunk sizes.
965 * TARGET_CHUNK must be a power of two. This is to reduce
966 * fragmentation effects on the allocations.
968 #define TARGET_CHUNK 8
969 if ((new_size = lun) != 0) {
970 new_size = roundup2(lun, TARGET_CHUNK);
972 if ((target_ptr = bus_ptr->LUN[target]) == NULL) {
974 * Allocate a new structure?
975 * Since one element in structure, the +1
976 * needed for size has been abstracted.
978 if ((new_entry == FALSE)
979 || ((bus_ptr->LUN[target] = target_ptr = (lun2tid_t *)kmalloc (
980 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
981 M_TEMP, M_WAITOK | M_ZERO)) == NULL)) {
982 debug_asr_printf("failed to allocate target list\n");
985 target_ptr->size = new_size + 1;
986 } else if (target_ptr->size <= new_size) {
987 lun2tid_t * new_target_ptr;
990 * Reallocate a new structure?
991 * Since one element in structure, the +1
992 * needed for size has been abstracted.
994 if ((new_entry == FALSE)
995 || ((new_target_ptr = (lun2tid_t *)kmalloc (
996 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
997 M_TEMP, M_WAITOK | M_ZERO)) == NULL)) {
998 debug_asr_printf("failed to reallocate target list\n");
1002 * Copy the whole thing, safer, simpler coding
1003 * and not really performance critical at this point.
1005 bcopy(target_ptr, new_target_ptr, sizeof(*target_ptr)
1006 + (sizeof(target_ptr->TID) * (target_ptr->size - 1)));
1007 bus_ptr->LUN[target] = new_target_ptr;
1008 kfree(target_ptr, M_TEMP);
1009 target_ptr = new_target_ptr;
1010 target_ptr->size = new_size + 1;
1013 * Now, acquire the TID address from the LUN indexed list.
1015 return (&(target_ptr->TID[lun]));
1016 } /* ASR_getTidAddress */
1019 * Get a pre-existing TID relationship.
1021 * If the TID was never set, return (tid_t)-1.
1023 * should use mutex rather than spl.
1025 static __inline tid_t
1026 ASR_getTid(Asr_softc_t *sc, int bus, int target, int lun)
1032 if (((tid_ptr = ASR_getTidAddress(sc, bus, target, lun, FALSE)) == NULL)
1033 /* (tid_t)0 or (tid_t)-1 indicate no TID */
1034 || (*tid_ptr == (tid_t)0)) {
1044 * Set a TID relationship.
1046 * If the TID was not set, return (tid_t)-1.
1048 * should use mutex rather than spl.
1050 static __inline tid_t
1051 ASR_setTid(Asr_softc_t *sc, int bus, int target, int lun, tid_t TID)
1055 if (TID != (tid_t)-1) {
1060 if ((tid_ptr = ASR_getTidAddress(sc, bus, target, lun, TRUE))
1071 /*-------------------------------------------------------------------------*/
1072 /* Function ASR_rescan */
1073 /*-------------------------------------------------------------------------*/
1074 /* The Parameters Passed To This Function Are : */
1075 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1077 /* This Function Will rescan the adapter and resynchronize any data */
1079 /* Return : 0 For OK, Error Code Otherwise */
1080 /*-------------------------------------------------------------------------*/
1083 ASR_rescan(Asr_softc_t *sc)
1089 * Re-acquire the LCT table and synchronize us to the adapter.
1091 if ((error = ASR_acquireLct(sc)) == 0) {
1092 error = ASR_acquireHrt(sc);
1099 bus = sc->ha_MaxBus;
1100 /* Reset all existing cached TID lookups */
1102 int target, event = 0;
1105 * Scan for all targets on this bus to see if they
1106 * got affected by the rescan.
1108 for (target = 0; target <= sc->ha_MaxId; ++target) {
1111 /* Stay away from the controller ID */
1112 if (target == sc->ha_adapter_target[bus]) {
1115 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
1116 PI2O_LCT_ENTRY Device;
1117 tid_t TID = (tid_t)-1;
1121 * See if the cached TID changed. Search for
1122 * the device in our new LCT.
1124 for (Device = sc->ha_LCT->LCTEntry;
1125 Device < (PI2O_LCT_ENTRY)(((U32 *)sc->ha_LCT)
1126 + I2O_LCT_getTableSize(sc->ha_LCT));
1128 if ((Device->le_type != I2O_UNKNOWN)
1129 && (Device->le_bus == bus)
1130 && (Device->le_target == target)
1131 && (Device->le_lun == lun)
1132 && (I2O_LCT_ENTRY_getUserTID(Device)
1134 TID = I2O_LCT_ENTRY_getLocalTID(
1140 * Indicate to the OS that the label needs
1141 * to be recalculated, or that the specific
1142 * open device is no longer valid (Merde)
1143 * because the cached TID changed.
1145 LastTID = ASR_getTid (sc, bus, target, lun);
1146 if (LastTID != TID) {
1147 struct cam_path * path;
1149 if (xpt_create_path(&path,
1151 cam_sim_path(sc->ha_sim[bus]),
1152 target, lun) != CAM_REQ_CMP) {
1153 if (TID == (tid_t)-1) {
1154 event |= AC_LOST_DEVICE;
1156 event |= AC_INQ_CHANGED
1157 | AC_GETDEV_CHANGED;
1160 if (TID == (tid_t)-1) {
1164 } else if (LastTID == (tid_t)-1) {
1165 struct ccb_getdev *ccb;
1167 ccb = &xpt_alloc_ccb()->cgd;
1171 path, /*priority*/5);
1176 xpt_free_ccb(&ccb->ccb_h);
1188 * We have the option of clearing the
1189 * cached TID for it to be rescanned, or to
1190 * set it now even if the device never got
1191 * accessed. We chose the later since we
1192 * currently do not use the condition that
1193 * the TID ever got cached.
1195 ASR_setTid (sc, bus, target, lun, TID);
1199 * The xpt layer can not handle multiple events at the
1202 if (event & AC_LOST_DEVICE) {
1203 xpt_async(AC_LOST_DEVICE, sc->ha_path[bus], NULL);
1205 if (event & AC_INQ_CHANGED) {
1206 xpt_async(AC_INQ_CHANGED, sc->ha_path[bus], NULL);
1208 if (event & AC_GETDEV_CHANGED) {
1209 xpt_async(AC_GETDEV_CHANGED, sc->ha_path[bus], NULL);
1211 } while (--bus >= 0);
1215 /*-------------------------------------------------------------------------*/
1216 /* Function ASR_reset */
1217 /*-------------------------------------------------------------------------*/
1218 /* The Parameters Passed To This Function Are : */
1219 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1221 /* This Function Will reset the adapter and resynchronize any data */
1224 /*-------------------------------------------------------------------------*/
1227 ASR_reset(Asr_softc_t *sc)
1232 if ((sc->ha_in_reset == HA_IN_RESET)
1233 || (sc->ha_in_reset == HA_OFF_LINE_RECOVERY)) {
1238 * Promotes HA_OPERATIONAL to HA_IN_RESET,
1239 * or HA_OFF_LINE to HA_OFF_LINE_RECOVERY.
1241 ++(sc->ha_in_reset);
1242 if (ASR_resetIOP(sc) == 0) {
1243 debug_asr_printf ("ASR_resetIOP failed\n");
1245 * We really need to take this card off-line, easier said
1246 * than make sense. Better to keep retrying for now since if a
1247 * UART cable is connected the blinkLEDs the adapter is now in
1248 * a hard state requiring action from the monitor commands to
1249 * the HBA to continue. For debugging waiting forever is a
1250 * good thing. In a production system, however, one may wish
1251 * to instead take the card off-line ...
1254 while (ASR_resetIOP(sc) == 0);
1256 retVal = ASR_init (sc);
1259 debug_asr_printf ("ASR_init failed\n");
1260 sc->ha_in_reset = HA_OFF_LINE;
1263 if (ASR_rescan (sc) != 0) {
1264 debug_asr_printf ("ASR_rescan failed\n");
1266 ASR_failActiveCommands (sc);
1267 if (sc->ha_in_reset == HA_OFF_LINE_RECOVERY) {
1268 kprintf ("asr%d: Brining adapter back on-line\n",
1270 ? cam_sim_unit(xpt_path_sim(sc->ha_path[0]))
1273 sc->ha_in_reset = HA_OPERATIONAL;
1278 * Device timeout handler.
1281 asr_timeout(void *arg)
1283 union asr_ccb *ccb = (union asr_ccb *)arg;
1284 Asr_softc_t *sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
1287 debug_asr_print_path(ccb);
1288 debug_asr_printf("timed out");
1291 * Check if the adapter has locked up?
1293 if ((s = ASR_getBlinkLedCode(sc)) != 0) {
1295 kprintf ("asr%d: Blink LED 0x%x resetting adapter\n",
1296 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)), s);
1297 if (ASR_reset (sc) == ENXIO) {
1298 /* Try again later */
1299 callout_reset(ccb->ccb_h.timeout_ch,
1300 (ccb->ccb_h.timeout * hz) / 1000,
1306 * Abort does not function on the ASR card!!! Walking away from
1307 * the SCSI command is also *very* dangerous. A SCSI BUS reset is
1308 * our best bet, followed by a complete adapter reset if that fails.
1311 /* Check if we already timed out once to raise the issue */
1312 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_CMD_TIMEOUT) {
1313 debug_asr_printf (" AGAIN\nreinitializing adapter\n");
1314 if (ASR_reset (sc) == ENXIO) {
1315 callout_reset(ccb->ccb_h.timeout_ch,
1316 (ccb->ccb_h.timeout * hz) / 1000,
1322 debug_asr_printf ("\nresetting bus\n");
1323 /* If the BUS reset does not take, then an adapter reset is next! */
1324 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1325 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1326 callout_reset(ccb->ccb_h.timeout_ch,
1327 (ccb->ccb_h.timeout * hz) / 1000,
1329 ASR_resetBus (sc, cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)));
1330 xpt_async (AC_BUS_RESET, ccb->ccb_h.path, NULL);
1335 * send a message asynchronously
1338 ASR_queue(Asr_softc_t *sc, PI2O_MESSAGE_FRAME Message)
1343 debug_asr_printf("Host Command Dump:\n");
1344 debug_asr_dump_message(Message);
1346 ccb = (union asr_ccb *)(long)
1347 I2O_MESSAGE_FRAME_getInitiatorContext64(Message);
1349 if ((MessageOffset = ASR_getMessage(sc)) != EMPTY_QUEUE) {
1350 asr_set_frame(sc, Message, MessageOffset,
1351 I2O_MESSAGE_FRAME_getMessageSize(Message));
1353 ASR_ccbAdd (sc, ccb);
1355 /* Post the command */
1356 asr_set_ToFIFO(sc, MessageOffset);
1358 if (ASR_getBlinkLedCode(sc)) {
1360 * Unlikely we can do anything if we can't grab a
1361 * message frame :-(, but lets give it a try.
1363 (void)ASR_reset(sc);
1366 return (MessageOffset);
1370 /* Simple Scatter Gather elements */
1371 #define SG(SGL,Index,Flags,Buffer,Size) \
1372 I2O_FLAGS_COUNT_setCount( \
1373 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1375 I2O_FLAGS_COUNT_setFlags( \
1376 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1377 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | (Flags)); \
1378 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress( \
1379 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index]), \
1380 (Buffer == NULL) ? 0 : KVTOPHYS(Buffer))
1383 * Retrieve Parameter Group.
1386 ASR_getParams(Asr_softc_t *sc, tid_t TID, int Group, void *Buffer,
1387 unsigned BufferSize)
1389 struct paramGetMessage {
1390 I2O_UTIL_PARAMS_GET_MESSAGE M;
1392 F[sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT)];
1394 I2O_PARAM_OPERATIONS_LIST_HEADER Header;
1395 I2O_PARAM_OPERATION_ALL_TEMPLATE Template[1];
1398 struct Operations *Operations_Ptr;
1399 I2O_UTIL_PARAMS_GET_MESSAGE *Message_Ptr;
1400 struct ParamBuffer {
1401 I2O_PARAM_RESULTS_LIST_HEADER Header;
1402 I2O_PARAM_READ_OPERATION_RESULT Read;
1406 Message_Ptr = (I2O_UTIL_PARAMS_GET_MESSAGE *)ASR_fillMessage(&Message,
1407 sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1408 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1409 Operations_Ptr = (struct Operations *)((char *)Message_Ptr
1410 + sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1411 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1412 bzero(Operations_Ptr, sizeof(struct Operations));
1413 I2O_PARAM_OPERATIONS_LIST_HEADER_setOperationCount(
1414 &(Operations_Ptr->Header), 1);
1415 I2O_PARAM_OPERATION_ALL_TEMPLATE_setOperation(
1416 &(Operations_Ptr->Template[0]), I2O_PARAMS_OPERATION_FIELD_GET);
1417 I2O_PARAM_OPERATION_ALL_TEMPLATE_setFieldCount(
1418 &(Operations_Ptr->Template[0]), 0xFFFF);
1419 I2O_PARAM_OPERATION_ALL_TEMPLATE_setGroupNumber(
1420 &(Operations_Ptr->Template[0]), Group);
1421 Buffer_Ptr = (struct ParamBuffer *)Buffer;
1422 bzero(Buffer_Ptr, BufferSize);
1424 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1426 + (((sizeof(I2O_UTIL_PARAMS_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1427 / sizeof(U32)) << 4));
1428 I2O_MESSAGE_FRAME_setTargetAddress (&(Message_Ptr->StdMessageFrame),
1430 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
1431 I2O_UTIL_PARAMS_GET);
1433 * Set up the buffers as scatter gather elements.
1435 SG(&(Message_Ptr->SGL), 0,
1436 I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER,
1437 Operations_Ptr, sizeof(struct Operations));
1438 SG(&(Message_Ptr->SGL), 1,
1439 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
1440 Buffer_Ptr, BufferSize);
1442 if ((ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) == CAM_REQ_CMP)
1443 && (Buffer_Ptr->Header.ResultCount)) {
1444 return ((void *)(Buffer_Ptr->Info));
1447 } /* ASR_getParams */
1450 * Acquire the LCT information.
1453 ASR_acquireLct(Asr_softc_t *sc)
1455 PI2O_EXEC_LCT_NOTIFY_MESSAGE Message_Ptr;
1456 PI2O_SGE_SIMPLE_ELEMENT sg;
1457 int MessageSizeInBytes;
1460 I2O_LCT Table, *TableP = &Table;
1461 PI2O_LCT_ENTRY Entry;
1464 * sc value assumed valid
1466 MessageSizeInBytes = sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) -
1467 sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT);
1468 if ((Message_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)kmalloc(
1469 MessageSizeInBytes, M_TEMP, M_WAITOK)) == NULL) {
1472 (void)ASR_fillMessage((void *)Message_Ptr, MessageSizeInBytes);
1473 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1474 (I2O_VERSION_11 + (((sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) -
1475 sizeof(I2O_SG_ELEMENT)) / sizeof(U32)) << 4)));
1476 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1477 I2O_EXEC_LCT_NOTIFY);
1478 I2O_EXEC_LCT_NOTIFY_MESSAGE_setClassIdentifier(Message_Ptr,
1479 I2O_CLASS_MATCH_ANYCLASS);
1481 * Call the LCT table to determine the number of device entries
1482 * to reserve space for.
1484 SG(&(Message_Ptr->SGL), 0,
1485 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER, TableP,
1488 * since this code is reused in several systems, code efficiency
1489 * is greater by using a shift operation rather than a divide by
1490 * sizeof(u_int32_t).
1492 I2O_LCT_setTableSize(&Table,
1493 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1494 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1496 * Determine the size of the LCT table.
1499 kfree(sc->ha_LCT, M_TEMP);
1502 * malloc only generates contiguous memory when less than a
1503 * page is expected. We must break the request up into an SG list ...
1505 if (((len = (I2O_LCT_getTableSize(&Table) << 2)) <=
1506 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)))
1507 || (len > (128 * 1024))) { /* Arbitrary */
1508 kfree(Message_Ptr, M_TEMP);
1511 if ((sc->ha_LCT = (PI2O_LCT)kmalloc (len, M_TEMP, M_WAITOK)) == NULL) {
1512 kfree(Message_Ptr, M_TEMP);
1516 * since this code is reused in several systems, code efficiency
1517 * is greater by using a shift operation rather than a divide by
1518 * sizeof(u_int32_t).
1520 I2O_LCT_setTableSize(sc->ha_LCT,
1521 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1523 * Convert the access to the LCT table into a SG list.
1525 sg = Message_Ptr->SGL.u.Simple;
1526 v = (caddr_t)(sc->ha_LCT);
1528 int next, base, span;
1531 next = base = KVTOPHYS(v);
1532 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
1534 /* How far can we go contiguously */
1535 while ((len > 0) && (base == next)) {
1538 next = trunc_page(base) + PAGE_SIZE;
1549 /* Construct the Flags */
1550 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
1552 int rw = I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT;
1554 rw = (I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT
1555 | I2O_SGL_FLAGS_LAST_ELEMENT
1556 | I2O_SGL_FLAGS_END_OF_BUFFER);
1558 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount), rw);
1566 * Incrementing requires resizing of the packet.
1569 MessageSizeInBytes += sizeof(*sg);
1570 I2O_MESSAGE_FRAME_setMessageSize(
1571 &(Message_Ptr->StdMessageFrame),
1572 I2O_MESSAGE_FRAME_getMessageSize(
1573 &(Message_Ptr->StdMessageFrame))
1574 + (sizeof(*sg) / sizeof(U32)));
1576 PI2O_EXEC_LCT_NOTIFY_MESSAGE NewMessage_Ptr;
1578 if ((NewMessage_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)
1579 kmalloc(MessageSizeInBytes, M_TEMP, M_WAITOK))
1581 kfree(sc->ha_LCT, M_TEMP);
1583 kfree(Message_Ptr, M_TEMP);
1586 span = ((caddr_t)sg) - (caddr_t)Message_Ptr;
1587 bcopy(Message_Ptr, NewMessage_Ptr, span);
1588 kfree(Message_Ptr, M_TEMP);
1589 sg = (PI2O_SGE_SIMPLE_ELEMENT)
1590 (((caddr_t)NewMessage_Ptr) + span);
1591 Message_Ptr = NewMessage_Ptr;
1596 retval = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1597 kfree(Message_Ptr, M_TEMP);
1598 if (retval != CAM_REQ_CMP) {
1602 /* If the LCT table grew, lets truncate accesses */
1603 if (I2O_LCT_getTableSize(&Table) < I2O_LCT_getTableSize(sc->ha_LCT)) {
1604 I2O_LCT_setTableSize(sc->ha_LCT, I2O_LCT_getTableSize(&Table));
1606 for (Entry = sc->ha_LCT->LCTEntry; Entry < (PI2O_LCT_ENTRY)
1607 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
1609 Entry->le_type = I2O_UNKNOWN;
1610 switch (I2O_CLASS_ID_getClass(&(Entry->ClassID))) {
1612 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
1613 Entry->le_type = I2O_BSA;
1616 case I2O_CLASS_SCSI_PERIPHERAL:
1617 Entry->le_type = I2O_SCSI;
1620 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
1621 Entry->le_type = I2O_FCA;
1624 case I2O_CLASS_BUS_ADAPTER_PORT:
1625 Entry->le_type = I2O_PORT | I2O_SCSI;
1627 case I2O_CLASS_FIBRE_CHANNEL_PORT:
1628 if (I2O_CLASS_ID_getClass(&(Entry->ClassID)) ==
1629 I2O_CLASS_FIBRE_CHANNEL_PORT) {
1630 Entry->le_type = I2O_PORT | I2O_FCA;
1632 { struct ControllerInfo {
1633 I2O_PARAM_RESULTS_LIST_HEADER Header;
1634 I2O_PARAM_READ_OPERATION_RESULT Read;
1635 I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1637 PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1639 Entry->le_bus = 0xff;
1640 Entry->le_target = 0xff;
1641 Entry->le_lun = 0xff;
1643 if ((Info = (PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR)
1645 I2O_LCT_ENTRY_getLocalTID(Entry),
1646 I2O_HBA_SCSI_CONTROLLER_INFO_GROUP_NO,
1647 &Buffer, sizeof(struct ControllerInfo))) == NULL) {
1651 = I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR_getInitiatorID(
1658 { struct DeviceInfo {
1659 I2O_PARAM_RESULTS_LIST_HEADER Header;
1660 I2O_PARAM_READ_OPERATION_RESULT Read;
1661 I2O_DPT_DEVICE_INFO_SCALAR Info;
1663 PI2O_DPT_DEVICE_INFO_SCALAR Info;
1665 Entry->le_bus = 0xff;
1666 Entry->le_target = 0xff;
1667 Entry->le_lun = 0xff;
1669 if ((Info = (PI2O_DPT_DEVICE_INFO_SCALAR)
1671 I2O_LCT_ENTRY_getLocalTID(Entry),
1672 I2O_DPT_DEVICE_INFO_GROUP_NO,
1673 &Buffer, sizeof(struct DeviceInfo))) == NULL) {
1677 |= I2O_DPT_DEVICE_INFO_SCALAR_getDeviceType(Info);
1679 = I2O_DPT_DEVICE_INFO_SCALAR_getBus(Info);
1680 if ((Entry->le_bus > sc->ha_MaxBus)
1681 && (Entry->le_bus <= MAX_CHANNEL)) {
1682 sc->ha_MaxBus = Entry->le_bus;
1685 = I2O_DPT_DEVICE_INFO_SCALAR_getIdentifier(Info);
1687 = I2O_DPT_DEVICE_INFO_SCALAR_getLunInfo(Info);
1691 * A zero return value indicates success.
1694 } /* ASR_acquireLct */
1697 * Initialize a message frame.
1698 * We assume that the CDB has already been set up, so all we do here is
1699 * generate the Scatter Gather list.
1701 static PI2O_MESSAGE_FRAME
1702 ASR_init_message(union asr_ccb *ccb, PI2O_MESSAGE_FRAME Message)
1704 PI2O_MESSAGE_FRAME Message_Ptr;
1705 PI2O_SGE_SIMPLE_ELEMENT sg;
1706 Asr_softc_t *sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
1707 vm_size_t size, len;
1710 int next, span, base, rw;
1711 int target = ccb->ccb_h.target_id;
1712 int lun = ccb->ccb_h.target_lun;
1713 int bus =cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
1716 /* We only need to zero out the PRIVATE_SCSI_SCB_EXECUTE_MESSAGE */
1717 Message_Ptr = (I2O_MESSAGE_FRAME *)Message;
1718 bzero(Message_Ptr, (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) -
1719 sizeof(I2O_SG_ELEMENT)));
1721 if ((TID = ASR_getTid (sc, bus, target, lun)) == (tid_t)-1) {
1722 PI2O_LCT_ENTRY Device;
1725 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
1726 (((U32 *)sc->ha_LCT) + I2O_LCT_getTableSize(sc->ha_LCT));
1728 if ((Device->le_type != I2O_UNKNOWN)
1729 && (Device->le_bus == bus)
1730 && (Device->le_target == target)
1731 && (Device->le_lun == lun)
1732 && (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF)) {
1733 TID = I2O_LCT_ENTRY_getLocalTID(Device);
1734 ASR_setTid(sc, Device->le_bus,
1735 Device->le_target, Device->le_lun,
1741 if (TID == (tid_t)0) {
1744 I2O_MESSAGE_FRAME_setTargetAddress(Message_Ptr, TID);
1745 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(
1746 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, TID);
1747 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11 |
1748 (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1749 / sizeof(U32)) << 4));
1750 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
1751 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
1752 - sizeof(I2O_SG_ELEMENT)) / sizeof(U32));
1753 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
1754 I2O_MESSAGE_FRAME_setFunction(Message_Ptr, I2O_PRIVATE_MESSAGE);
1755 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
1756 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, I2O_SCSI_SCB_EXEC);
1757 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
1758 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
1759 I2O_SCB_FLAG_ENABLE_DISCONNECT
1760 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
1761 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
1763 * We do not need any (optional byteswapping) method access to
1764 * the Initiator & Transaction context field.
1766 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
1768 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
1769 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, DPT_ORGANIZATION_ID);
1773 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(
1774 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, ccb->csio.cdb_len);
1775 bcopy(&(ccb->csio.cdb_io),
1776 ((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->CDB,
1780 * Given a buffer describing a transfer, set up a scatter/gather map
1781 * in a ccb to map that SCSI transfer.
1784 rw = (ccb->ccb_h.flags & CAM_DIR_IN) ? 0 : I2O_SGL_FLAGS_DIR;
1786 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
1787 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
1788 (ccb->csio.dxfer_len)
1789 ? ((rw) ? (I2O_SCB_FLAG_XFER_TO_DEVICE
1790 | I2O_SCB_FLAG_ENABLE_DISCONNECT
1791 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
1792 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER)
1793 : (I2O_SCB_FLAG_XFER_FROM_DEVICE
1794 | I2O_SCB_FLAG_ENABLE_DISCONNECT
1795 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
1796 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER))
1797 : (I2O_SCB_FLAG_ENABLE_DISCONNECT
1798 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
1799 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
1802 * Given a transfer described by a `data', fill in the SG list.
1804 sg = &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->SGL.u.Simple[0];
1806 len = ccb->csio.dxfer_len;
1807 v = ccb->csio.data_ptr;
1808 KASSERT(ccb->csio.dxfer_len >= 0, ("csio.dxfer_len < 0"));
1809 MessageSize = I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr);
1810 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
1811 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, len);
1812 while ((len > 0) && (sg < &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
1813 Message_Ptr)->SGL.u.Simple[SG_SIZE])) {
1815 next = base = KVTOPHYS(v);
1816 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
1818 /* How far can we go contiguously */
1819 while ((len > 0) && (base == next)) {
1820 next = trunc_page(base) + PAGE_SIZE;
1831 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
1833 rw |= I2O_SGL_FLAGS_LAST_ELEMENT;
1835 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount),
1836 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | rw);
1838 MessageSize += sizeof(*sg) / sizeof(U32);
1840 /* We always do the request sense ... */
1841 if ((span = ccb->csio.sense_len) == 0) {
1842 span = sizeof(ccb->csio.sense_data);
1844 SG(sg, 0, I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
1845 &(ccb->csio.sense_data), span);
1846 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
1847 MessageSize + (sizeof(*sg) / sizeof(U32)));
1848 return (Message_Ptr);
1849 } /* ASR_init_message */
1852 * Reset the adapter.
1855 ASR_initOutBound(Asr_softc_t *sc)
1857 struct initOutBoundMessage {
1858 I2O_EXEC_OUTBOUND_INIT_MESSAGE M;
1861 PI2O_EXEC_OUTBOUND_INIT_MESSAGE Message_Ptr;
1862 U32 *volatile Reply_Ptr;
1866 * Build up our copy of the Message.
1868 Message_Ptr = (PI2O_EXEC_OUTBOUND_INIT_MESSAGE)ASR_fillMessage(&Message,
1869 sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE));
1870 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1871 I2O_EXEC_OUTBOUND_INIT);
1872 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setHostPageFrameSize(Message_Ptr, PAGE_SIZE);
1873 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setOutboundMFrameSize(Message_Ptr,
1874 sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME));
1876 * Reset the Reply Status
1878 *(Reply_Ptr = (U32 *)((char *)Message_Ptr
1879 + sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE))) = 0;
1880 SG (&(Message_Ptr->SGL), 0, I2O_SGL_FLAGS_LAST_ELEMENT, Reply_Ptr,
1883 * Send the Message out
1885 if ((Old = ASR_initiateCp(sc, (PI2O_MESSAGE_FRAME)Message_Ptr)) !=
1890 * Wait for a response (Poll).
1892 while (*Reply_Ptr < I2O_EXEC_OUTBOUND_INIT_REJECTED);
1894 * Re-enable the interrupts.
1896 asr_set_intr(sc, Old);
1898 * Populate the outbound table.
1900 if (sc->ha_Msgs == NULL) {
1902 /* Allocate the reply frames */
1903 size = sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
1904 * sc->ha_Msgs_Count;
1907 * contigmalloc only works reliably at
1908 * initialization time.
1910 if ((sc->ha_Msgs = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
1911 contigmalloc (size, M_DEVBUF, M_WAITOK, 0ul,
1912 0xFFFFFFFFul, (u_long)sizeof(U32), 0ul)) != NULL) {
1913 bzero(sc->ha_Msgs, size);
1914 sc->ha_Msgs_Phys = KVTOPHYS(sc->ha_Msgs);
1918 /* Initialize the outbound FIFO */
1919 if (sc->ha_Msgs != NULL)
1920 for(size = sc->ha_Msgs_Count, addr = sc->ha_Msgs_Phys;
1922 asr_set_FromFIFO(sc, addr);
1924 sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME);
1926 return (*Reply_Ptr);
1929 } /* ASR_initOutBound */
1932 * Set the system table
1935 ASR_setSysTab(Asr_softc_t *sc)
1937 PI2O_EXEC_SYS_TAB_SET_MESSAGE Message_Ptr;
1938 PI2O_SET_SYSTAB_HEADER SystemTable;
1940 PI2O_SGE_SIMPLE_ELEMENT sg;
1943 if ((SystemTable = (PI2O_SET_SYSTAB_HEADER)kmalloc (
1944 sizeof(I2O_SET_SYSTAB_HEADER), M_TEMP, M_WAITOK | M_ZERO)) == NULL) {
1947 for (ha = Asr_softc_list; ha; ha = ha->ha_next) {
1948 ++SystemTable->NumberEntries;
1950 if ((Message_Ptr = (PI2O_EXEC_SYS_TAB_SET_MESSAGE)kmalloc (
1951 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
1952 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)),
1953 M_TEMP, M_WAITOK)) == NULL) {
1954 kfree(SystemTable, M_TEMP);
1957 (void)ASR_fillMessage((void *)Message_Ptr,
1958 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
1959 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)));
1960 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1962 (((sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1963 / sizeof(U32)) << 4)));
1964 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1965 I2O_EXEC_SYS_TAB_SET);
1967 * Call the LCT table to determine the number of device entries
1968 * to reserve space for.
1969 * since this code is reused in several systems, code efficiency
1970 * is greater by using a shift operation rather than a divide by
1971 * sizeof(u_int32_t).
1973 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
1974 + ((I2O_MESSAGE_FRAME_getVersionOffset(
1975 &(Message_Ptr->StdMessageFrame)) & 0xF0) >> 2));
1976 SG(sg, 0, I2O_SGL_FLAGS_DIR, SystemTable, sizeof(I2O_SET_SYSTAB_HEADER));
1978 for (ha = Asr_softc_list; ha; ha = ha->ha_next) {
1981 ? (I2O_SGL_FLAGS_DIR)
1982 : (I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER)),
1983 &(ha->ha_SystemTable), sizeof(ha->ha_SystemTable));
1986 SG(sg, 0, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
1987 SG(sg, 1, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_LAST_ELEMENT
1988 | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
1989 retVal = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1990 kfree(Message_Ptr, M_TEMP);
1991 kfree(SystemTable, M_TEMP);
1993 } /* ASR_setSysTab */
1996 ASR_acquireHrt(Asr_softc_t *sc)
1998 I2O_EXEC_HRT_GET_MESSAGE Message;
1999 I2O_EXEC_HRT_GET_MESSAGE *Message_Ptr;
2002 I2O_HRT_ENTRY Entry[MAX_CHANNEL];
2003 } Hrt, *HrtP = &Hrt;
2004 u_int8_t NumberOfEntries;
2005 PI2O_HRT_ENTRY Entry;
2007 bzero(&Hrt, sizeof (Hrt));
2008 Message_Ptr = (I2O_EXEC_HRT_GET_MESSAGE *)ASR_fillMessage(&Message,
2009 sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2010 + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2011 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
2013 + (((sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2014 / sizeof(U32)) << 4)));
2015 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
2019 * Set up the buffers as scatter gather elements.
2021 SG(&(Message_Ptr->SGL), 0,
2022 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2024 if (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != CAM_REQ_CMP) {
2027 if ((NumberOfEntries = I2O_HRT_getNumberEntries(&Hrt.Header))
2028 > (MAX_CHANNEL + 1)) {
2029 NumberOfEntries = MAX_CHANNEL + 1;
2031 for (Entry = Hrt.Header.HRTEntry;
2032 NumberOfEntries != 0;
2033 ++Entry, --NumberOfEntries) {
2034 PI2O_LCT_ENTRY Device;
2036 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2037 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
2039 if (I2O_LCT_ENTRY_getLocalTID(Device)
2040 == (I2O_HRT_ENTRY_getAdapterID(Entry) & 0xFFF)) {
2041 Device->le_bus = I2O_HRT_ENTRY_getAdapterID(
2043 if ((Device->le_bus > sc->ha_MaxBus)
2044 && (Device->le_bus <= MAX_CHANNEL)) {
2045 sc->ha_MaxBus = Device->le_bus;
2051 } /* ASR_acquireHrt */
2054 * Enable the adapter.
2057 ASR_enableSys(Asr_softc_t *sc)
2059 I2O_EXEC_SYS_ENABLE_MESSAGE Message;
2060 PI2O_EXEC_SYS_ENABLE_MESSAGE Message_Ptr;
2062 Message_Ptr = (PI2O_EXEC_SYS_ENABLE_MESSAGE)ASR_fillMessage(&Message,
2063 sizeof(I2O_EXEC_SYS_ENABLE_MESSAGE));
2064 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2065 I2O_EXEC_SYS_ENABLE);
2066 return (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != 0);
2067 } /* ASR_enableSys */
2070 * Perform the stages necessary to initialize the adapter
2073 ASR_init(Asr_softc_t *sc)
2075 return ((ASR_initOutBound(sc) == 0)
2076 || (ASR_setSysTab(sc) != CAM_REQ_CMP)
2077 || (ASR_enableSys(sc) != CAM_REQ_CMP));
2081 * Send a Synchronize Cache command to the target device.
2084 ASR_sync(Asr_softc_t *sc, int bus, int target, int lun)
2089 * We will not synchronize the device when there are outstanding
2090 * commands issued by the OS (this is due to a locked up device,
2091 * as the OS normally would flush all outstanding commands before
2092 * issuing a shutdown or an adapter reset).
2095 && (LIST_FIRST(&(sc->ha_ccb)) != NULL)
2096 && ((TID = ASR_getTid (sc, bus, target, lun)) != (tid_t)-1)
2097 && (TID != (tid_t)0)) {
2098 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message;
2099 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
2101 Message_Ptr = &Message;
2102 bzero(Message_Ptr, sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2103 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2105 I2O_MESSAGE_FRAME_setVersionOffset(
2106 (PI2O_MESSAGE_FRAME)Message_Ptr,
2108 | (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2109 - sizeof(I2O_SG_ELEMENT))
2110 / sizeof(U32)) << 4));
2111 I2O_MESSAGE_FRAME_setMessageSize(
2112 (PI2O_MESSAGE_FRAME)Message_Ptr,
2113 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2114 - sizeof(I2O_SG_ELEMENT))
2116 I2O_MESSAGE_FRAME_setInitiatorAddress (
2117 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
2118 I2O_MESSAGE_FRAME_setFunction(
2119 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
2120 I2O_MESSAGE_FRAME_setTargetAddress(
2121 (PI2O_MESSAGE_FRAME)Message_Ptr, TID);
2122 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
2123 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2125 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(Message_Ptr, TID);
2126 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2127 I2O_SCB_FLAG_ENABLE_DISCONNECT
2128 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2129 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2130 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2131 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2132 DPT_ORGANIZATION_ID);
2133 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
2134 Message_Ptr->CDB[0] = SYNCHRONIZE_CACHE;
2135 Message_Ptr->CDB[1] = (lun << 5);
2137 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2138 (I2O_SCB_FLAG_XFER_FROM_DEVICE
2139 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2140 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2141 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2143 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2149 ASR_synchronize(Asr_softc_t *sc)
2151 int bus, target, lun;
2153 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
2154 for (target = 0; target <= sc->ha_MaxId; ++target) {
2155 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
2156 ASR_sync(sc,bus,target,lun);
2163 * Reset the HBA, targets and BUS.
2164 * Currently this resets *all* the SCSI busses.
2166 static __inline void
2167 asr_hbareset(Asr_softc_t *sc)
2169 ASR_synchronize(sc);
2170 (void)ASR_reset(sc);
2171 } /* asr_hbareset */
2174 * A reduced copy of the real pci_map_mem, incorporating the MAX_MAP
2175 * limit and a reduction in error checking (in the pre 4.0 case).
2178 asr_pci_map_mem(device_t dev, Asr_softc_t *sc)
2184 * I2O specification says we must find first *memory* mapped BAR
2186 for (rid = 0; rid < 4; rid++) {
2187 p = pci_read_config(dev, PCIR_BAR(rid), sizeof(p));
2198 rid = PCIR_BAR(rid);
2199 p = pci_read_config(dev, rid, sizeof(p));
2200 pci_write_config(dev, rid, -1, sizeof(p));
2201 l = 0 - (pci_read_config(dev, rid, sizeof(l)) & ~15);
2202 pci_write_config(dev, rid, p, sizeof(p));
2207 * The 2005S Zero Channel RAID solution is not a perfect PCI
2208 * citizen. It asks for 4MB on BAR0, and 0MB on BAR1, once
2209 * enabled it rewrites the size of BAR0 to 2MB, sets BAR1 to
2210 * BAR0+2MB and sets it's size to 2MB. The IOP registers are
2211 * accessible via BAR0, the messaging registers are accessible
2212 * via BAR1. If the subdevice code is 50 to 59 decimal.
2214 s = pci_read_config(dev, PCIR_DEVVENDOR, sizeof(s));
2215 if (s != 0xA5111044) {
2216 s = pci_read_config(dev, PCIR_SUBVEND_0, sizeof(s));
2217 if ((((ADPTDOMINATOR_SUB_ID_START ^ s) & 0xF000FFFF) == 0)
2218 && (ADPTDOMINATOR_SUB_ID_START <= s)
2219 && (s <= ADPTDOMINATOR_SUB_ID_END)) {
2220 l = MAX_MAP; /* Conjoined BAR Raptor Daptor */
2224 sc->ha_mem_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
2225 p, p + l, l, RF_ACTIVE);
2226 if (sc->ha_mem_res == NULL) {
2229 sc->ha_Base = rman_get_start(sc->ha_mem_res);
2230 sc->ha_i2o_bhandle = rman_get_bushandle(sc->ha_mem_res);
2231 sc->ha_i2o_btag = rman_get_bustag(sc->ha_mem_res);
2233 if (s == 0xA5111044) { /* Split BAR Raptor Daptor */
2234 if ((rid += sizeof(u_int32_t)) >= PCIR_BAR(4)) {
2237 p = pci_read_config(dev, rid, sizeof(p));
2238 pci_write_config(dev, rid, -1, sizeof(p));
2239 l = 0 - (pci_read_config(dev, rid, sizeof(l)) & ~15);
2240 pci_write_config(dev, rid, p, sizeof(p));
2245 sc->ha_mes_res = bus_alloc_resource(dev, SYS_RES_MEMORY, &rid,
2246 p, p + l, l, RF_ACTIVE);
2247 if (sc->ha_mes_res == NULL) {
2250 sc->ha_frame_bhandle = rman_get_bushandle(sc->ha_mes_res);
2251 sc->ha_frame_btag = rman_get_bustag(sc->ha_mes_res);
2253 sc->ha_frame_bhandle = sc->ha_i2o_bhandle;
2254 sc->ha_frame_btag = sc->ha_i2o_btag;
2257 } /* asr_pci_map_mem */
2260 * A simplified copy of the real pci_map_int with additional
2261 * registration requirements.
2264 asr_pci_map_int(device_t dev, Asr_softc_t *sc)
2268 sc->ha_irq_res = bus_alloc_resource_any(dev, SYS_RES_IRQ, &rid,
2269 RF_ACTIVE | RF_SHAREABLE);
2270 if (sc->ha_irq_res == NULL) {
2273 if (bus_setup_intr(dev, sc->ha_irq_res, 0,
2274 (driver_intr_t *)asr_intr, (void *)sc, &(sc->ha_intr), NULL)) {
2277 sc->ha_irq = pci_read_config(dev, PCIR_INTLINE, sizeof(char));
2279 } /* asr_pci_map_int */
2282 asr_status_cb(void *arg, bus_dma_segment_t *segs, int nseg, int error)
2289 sc = (Asr_softc_t *)arg;
2292 * The status word can be at a 64-bit address, but the existing
2293 * accessor macros simply cannot manipulate 64-bit addresses.
2295 sc->ha_status_phys = (u_int32_t)segs[0].ds_addr +
2296 offsetof(struct Asr_status_mem, status);
2297 sc->ha_rstatus_phys = (u_int32_t)segs[0].ds_addr +
2298 offsetof(struct Asr_status_mem, rstatus);
2302 asr_alloc_dma(Asr_softc_t *sc)
2308 if (bus_dma_tag_create(NULL, /* parent */
2309 1, 0, /* algnmnt, boundary */
2310 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
2311 BUS_SPACE_MAXADDR, /* highaddr */
2312 NULL, NULL, /* filter, filterarg */
2313 BUS_SPACE_MAXSIZE_32BIT, /* maxsize */
2314 BUS_SPACE_UNRESTRICTED, /* nsegments */
2315 BUS_SPACE_MAXSIZE_32BIT, /* maxsegsize */
2317 &sc->ha_parent_dmat)) {
2318 device_printf(dev, "Cannot allocate parent DMA tag\n");
2322 if (bus_dma_tag_create(sc->ha_parent_dmat, /* parent */
2323 1, 0, /* algnmnt, boundary */
2324 BUS_SPACE_MAXADDR_32BIT, /* lowaddr */
2325 BUS_SPACE_MAXADDR, /* highaddr */
2326 NULL, NULL, /* filter, filterarg */
2327 sizeof(sc->ha_statusmem),/* maxsize */
2329 sizeof(sc->ha_statusmem),/* maxsegsize */
2331 &sc->ha_statusmem_dmat)) {
2332 device_printf(dev, "Cannot allocate status DMA tag\n");
2333 bus_dma_tag_destroy(sc->ha_parent_dmat);
2337 if (bus_dmamem_alloc(sc->ha_statusmem_dmat, (void **)&sc->ha_statusmem,
2338 BUS_DMA_NOWAIT, &sc->ha_statusmem_dmamap)) {
2339 device_printf(dev, "Cannot allocate status memory\n");
2340 bus_dma_tag_destroy(sc->ha_statusmem_dmat);
2341 bus_dma_tag_destroy(sc->ha_parent_dmat);
2344 (void)bus_dmamap_load(sc->ha_statusmem_dmat, sc->ha_statusmem_dmamap,
2345 sc->ha_statusmem, sizeof(sc->ha_statusmem), asr_status_cb, sc, 0);
2351 asr_release_dma(Asr_softc_t *sc)
2354 if (sc->ha_rstatus_phys != 0)
2355 bus_dmamap_unload(sc->ha_statusmem_dmat,
2356 sc->ha_statusmem_dmamap);
2357 if (sc->ha_statusmem != NULL)
2358 bus_dmamem_free(sc->ha_statusmem_dmat, sc->ha_statusmem,
2359 sc->ha_statusmem_dmamap);
2360 if (sc->ha_statusmem_dmat != NULL)
2361 bus_dma_tag_destroy(sc->ha_statusmem_dmat);
2362 if (sc->ha_parent_dmat != NULL)
2363 bus_dma_tag_destroy(sc->ha_parent_dmat);
2367 * Attach the devices, and virtual devices to the driver list.
2370 asr_attach(device_t dev)
2372 PI2O_EXEC_STATUS_GET_REPLY status;
2373 PI2O_LCT_ENTRY Device;
2374 Asr_softc_t *sc, **ha;
2375 struct scsi_inquiry_data *iq;
2376 int bus, size, unit;
2379 sc = device_get_softc(dev);
2380 unit = device_get_unit(dev);
2383 if (Asr_softc_list == NULL) {
2385 * Fixup the OS revision as saved in the dptsig for the
2386 * engine (dptioctl.h) to pick up.
2388 bcopy(osrelease, &ASR_sig.dsDescription[16], 5);
2391 * Initialize the software structure
2393 LIST_INIT(&(sc->ha_ccb));
2394 /* Link us into the HA list */
2395 for (ha = &Asr_softc_list; *ha; ha = &((*ha)->ha_next))
2400 * This is the real McCoy!
2402 if (!asr_pci_map_mem(dev, sc)) {
2403 device_printf(dev, "could not map memory\n");
2406 /* Enable if not formerly enabled */
2407 pci_write_config(dev, PCIR_COMMAND,
2408 pci_read_config(dev, PCIR_COMMAND, sizeof(char)) |
2409 PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN, sizeof(char));
2411 sc->ha_pciBusNum = pci_get_bus(dev);
2412 sc->ha_pciDeviceNum = (pci_get_slot(dev) << 3) | pci_get_function(dev);
2414 if ((error = asr_alloc_dma(sc)) != 0)
2417 /* Check if the device is there? */
2418 if (ASR_resetIOP(sc) == 0) {
2419 device_printf(dev, "Cannot reset adapter\n");
2420 asr_release_dma(sc);
2423 status = &sc->ha_statusmem->status;
2424 if (ASR_getStatus(sc) == NULL) {
2425 device_printf(dev, "could not initialize hardware\n");
2426 asr_release_dma(sc);
2429 sc->ha_SystemTable.OrganizationID = status->OrganizationID;
2430 sc->ha_SystemTable.IOP_ID = status->IOP_ID;
2431 sc->ha_SystemTable.I2oVersion = status->I2oVersion;
2432 sc->ha_SystemTable.IopState = status->IopState;
2433 sc->ha_SystemTable.MessengerType = status->MessengerType;
2434 sc->ha_SystemTable.InboundMessageFrameSize = status->InboundMFrameSize;
2435 sc->ha_SystemTable.MessengerInfo.InboundMessagePortAddressLow =
2436 (U32)(sc->ha_Base + I2O_REG_TOFIFO); /* XXX 64-bit */
2438 if (!asr_pci_map_int(dev, (void *)sc)) {
2439 device_printf(dev, "could not map interrupt\n");
2440 asr_release_dma(sc);
2444 /* Adjust the maximim inbound count */
2445 if (((sc->ha_QueueSize =
2446 I2O_EXEC_STATUS_GET_REPLY_getMaxInboundMFrames(status)) >
2447 MAX_INBOUND) || (sc->ha_QueueSize == 0)) {
2448 sc->ha_QueueSize = MAX_INBOUND;
2451 /* Adjust the maximum outbound count */
2452 if (((sc->ha_Msgs_Count =
2453 I2O_EXEC_STATUS_GET_REPLY_getMaxOutboundMFrames(status)) >
2454 MAX_OUTBOUND) || (sc->ha_Msgs_Count == 0)) {
2455 sc->ha_Msgs_Count = MAX_OUTBOUND;
2457 if (sc->ha_Msgs_Count > sc->ha_QueueSize) {
2458 sc->ha_Msgs_Count = sc->ha_QueueSize;
2461 /* Adjust the maximum SG size to adapter */
2462 if ((size = (I2O_EXEC_STATUS_GET_REPLY_getInboundMFrameSize(status) <<
2463 2)) > MAX_INBOUND_SIZE) {
2464 size = MAX_INBOUND_SIZE;
2466 sc->ha_SgSize = (size - sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2467 + sizeof(I2O_SG_ELEMENT)) / sizeof(I2O_SGE_SIMPLE_ELEMENT);
2470 * Only do a bus/HBA reset on the first time through. On this
2471 * first time through, we do not send a flush to the devices.
2473 if (ASR_init(sc) == 0) {
2475 I2O_PARAM_RESULTS_LIST_HEADER Header;
2476 I2O_PARAM_READ_OPERATION_RESULT Read;
2477 I2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2479 PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2480 #define FW_DEBUG_BLED_OFFSET 8
2482 if ((Info = (PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR)
2483 ASR_getParams(sc, 0, I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO,
2484 &Buffer, sizeof(struct BufferInfo))) != NULL) {
2485 sc->ha_blinkLED = FW_DEBUG_BLED_OFFSET +
2486 I2O_DPT_EXEC_IOP_BUFFERS_SCALAR_getSerialOutputOffset(Info);
2488 if (ASR_acquireLct(sc) == 0) {
2489 (void)ASR_acquireHrt(sc);
2492 device_printf(dev, "failed to initialize\n");
2493 asr_release_dma(sc);
2497 * Add in additional probe responses for more channels. We
2498 * are reusing the variable `target' for a channel loop counter.
2499 * Done here because of we need both the acquireLct and
2502 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2503 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT)); ++Device) {
2504 if (Device->le_type == I2O_UNKNOWN) {
2507 if (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF) {
2508 if (Device->le_target > sc->ha_MaxId) {
2509 sc->ha_MaxId = Device->le_target;
2511 if (Device->le_lun > sc->ha_MaxLun) {
2512 sc->ha_MaxLun = Device->le_lun;
2515 if (((Device->le_type & I2O_PORT) != 0)
2516 && (Device->le_bus <= MAX_CHANNEL)) {
2517 /* Do not increase MaxId for efficiency */
2518 sc->ha_adapter_target[Device->le_bus] =
2524 * Print the HBA model number as inquired from the card.
2527 device_printf(dev, " ");
2529 if ((iq = (struct scsi_inquiry_data *)kmalloc(
2530 sizeof(struct scsi_inquiry_data), M_TEMP, M_WAITOK | M_ZERO)) !=
2532 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message;
2533 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
2536 Message_Ptr = &Message;
2537 bzero(Message_Ptr, sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) -
2538 sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2540 I2O_MESSAGE_FRAME_setVersionOffset(
2541 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_VERSION_11 |
2542 (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2543 - sizeof(I2O_SG_ELEMENT)) / sizeof(U32)) << 4));
2544 I2O_MESSAGE_FRAME_setMessageSize(
2545 (PI2O_MESSAGE_FRAME)Message_Ptr,
2546 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) -
2547 sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT)) /
2549 I2O_MESSAGE_FRAME_setInitiatorAddress(
2550 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
2551 I2O_MESSAGE_FRAME_setFunction(
2552 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
2553 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode(
2554 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, I2O_SCSI_SCB_EXEC);
2555 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2556 I2O_SCB_FLAG_ENABLE_DISCONNECT
2557 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2558 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2559 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setInterpret(Message_Ptr, 1);
2560 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2561 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2562 DPT_ORGANIZATION_ID);
2563 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
2564 Message_Ptr->CDB[0] = INQUIRY;
2565 Message_Ptr->CDB[4] =
2566 (unsigned char)sizeof(struct scsi_inquiry_data);
2567 if (Message_Ptr->CDB[4] == 0) {
2568 Message_Ptr->CDB[4] = 255;
2571 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2572 (I2O_SCB_FLAG_XFER_FROM_DEVICE
2573 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2574 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2575 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2577 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
2578 Message_Ptr, sizeof(struct scsi_inquiry_data));
2579 SG(&(Message_Ptr->SGL), 0,
2580 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2581 iq, sizeof(struct scsi_inquiry_data));
2582 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2584 if (iq->vendor[0] && (iq->vendor[0] != ' ')) {
2586 ASR_prstring (iq->vendor, 8);
2589 if (iq->product[0] && (iq->product[0] != ' ')) {
2591 ASR_prstring (iq->product, 16);
2594 if (iq->revision[0] && (iq->revision[0] != ' ')) {
2595 kprintf (" FW Rev. ");
2596 ASR_prstring (iq->revision, 4);
2604 kprintf (" %d channel, %d CCBs, Protocol I2O\n", sc->ha_MaxBus + 1,
2605 (sc->ha_QueueSize > MAX_INBOUND) ? MAX_INBOUND : sc->ha_QueueSize);
2607 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
2608 struct cam_devq * devq;
2609 int QueueSize = sc->ha_QueueSize;
2611 if (QueueSize > MAX_INBOUND) {
2612 QueueSize = MAX_INBOUND;
2616 * Create the device queue for our SIM(s).
2618 if ((devq = cam_simq_alloc(QueueSize)) == NULL) {
2623 * Construct our first channel SIM entry
2625 sc->ha_sim[bus] = cam_sim_alloc(asr_action, asr_poll, "asr", sc,
2627 1, QueueSize, devq);
2628 if (sc->ha_sim[bus] == NULL) {
2632 if (xpt_bus_register(sc->ha_sim[bus], bus) != CAM_SUCCESS){
2633 cam_sim_free(sc->ha_sim[bus]);
2634 sc->ha_sim[bus] = NULL;
2638 if (xpt_create_path(&(sc->ha_path[bus]), /*periph*/NULL,
2639 cam_sim_path(sc->ha_sim[bus]), CAM_TARGET_WILDCARD,
2640 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
2641 xpt_bus_deregister( cam_sim_path(sc->ha_sim[bus]));
2642 cam_sim_free(sc->ha_sim[bus]);
2643 sc->ha_sim[bus] = NULL;
2649 * Generate the device node information
2651 sc->ha_devt = make_dev(&asr_ops, unit, UID_ROOT, GID_OPERATOR, 0640,
2653 if (sc->ha_devt != NULL)
2654 (void)make_dev_alias(sc->ha_devt, "rdpti%d", unit);
2655 sc->ha_devt->si_drv1 = sc;
2660 asr_poll(struct cam_sim *sim)
2662 asr_intr(cam_sim_softc(sim));
2666 asr_action(struct cam_sim *sim, union ccb *ccb)
2668 struct Asr_softc *sc;
2670 debug_asr_printf("asr_action(%lx,%lx{%x})\n", (u_long)sim, (u_long)ccb,
2671 ccb->ccb_h.func_code);
2673 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("asr_action\n"));
2675 ccb->ccb_h.spriv_ptr0 = sc = (struct Asr_softc *)cam_sim_softc(sim);
2677 switch (ccb->ccb_h.func_code) {
2679 /* Common cases first */
2680 case XPT_SCSI_IO: /* Execute the requested I/O operation */
2683 char M[MAX_INBOUND_SIZE];
2685 PI2O_MESSAGE_FRAME Message_Ptr;
2687 /* Reject incoming commands while we are resetting the card */
2688 if (sc->ha_in_reset != HA_OPERATIONAL) {
2689 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2690 if (sc->ha_in_reset >= HA_OFF_LINE) {
2691 /* HBA is now off-line */
2692 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
2694 /* HBA currently resetting, try again later. */
2695 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
2697 debug_asr_cmd_printf (" e\n");
2699 debug_asr_cmd_printf (" q\n");
2702 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
2704 "asr%d WARNING: scsi_cmd(%x) already done on b%dt%du%d\n",
2705 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
2706 ccb->csio.cdb_io.cdb_bytes[0],
2708 ccb->ccb_h.target_id,
2709 ccb->ccb_h.target_lun);
2711 debug_asr_cmd_printf("(%d,%d,%d,%d)", cam_sim_unit(sim),
2712 cam_sim_bus(sim), ccb->ccb_h.target_id,
2713 ccb->ccb_h.target_lun);
2714 debug_asr_dump_ccb(ccb);
2716 if ((Message_Ptr = ASR_init_message((union asr_ccb *)ccb,
2717 (PI2O_MESSAGE_FRAME)&Message)) != NULL) {
2718 debug_asr_cmd2_printf ("TID=%x:\n",
2719 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getTID(
2720 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr));
2721 debug_asr_cmd2_dump_message(Message_Ptr);
2722 debug_asr_cmd1_printf (" q");
2724 if (ASR_queue (sc, Message_Ptr) == EMPTY_QUEUE) {
2725 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2726 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
2727 debug_asr_cmd_printf (" E\n");
2730 debug_asr_cmd_printf(" Q\n");
2734 * We will get here if there is no valid TID for the device
2735 * referenced in the scsi command packet.
2737 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2738 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
2739 debug_asr_cmd_printf (" B\n");
2744 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
2745 /* Reset HBA device ... */
2747 ccb->ccb_h.status = CAM_REQ_CMP;
2751 case XPT_ABORT: /* Abort the specified CCB */
2753 ccb->ccb_h.status = CAM_REQ_INVALID;
2757 case XPT_SET_TRAN_SETTINGS:
2759 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
2763 case XPT_GET_TRAN_SETTINGS:
2764 /* Get default/user set transfer settings for the target */
2766 struct ccb_trans_settings *cts = &(ccb->cts);
2767 struct ccb_trans_settings_scsi *scsi =
2768 &cts->proto_specific.scsi;
2769 struct ccb_trans_settings_spi *spi =
2770 &cts->xport_specific.spi;
2772 if (cts->type == CTS_TYPE_USER_SETTINGS) {
2773 cts->protocol = PROTO_SCSI;
2774 cts->protocol_version = SCSI_REV_2;
2775 cts->transport = XPORT_SPI;
2776 cts->transport_version = 2;
2778 scsi->flags = CTS_SCSI_FLAGS_TAG_ENB;
2779 spi->flags = CTS_SPI_FLAGS_DISC_ENB;
2780 spi->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
2781 spi->sync_period = 6; /* 40MHz */
2782 spi->sync_offset = 15;
2783 spi->valid = CTS_SPI_VALID_SYNC_RATE
2784 | CTS_SPI_VALID_SYNC_OFFSET
2785 | CTS_SPI_VALID_BUS_WIDTH
2786 | CTS_SPI_VALID_DISC;
2787 scsi->valid = CTS_SCSI_VALID_TQ;
2789 ccb->ccb_h.status = CAM_REQ_CMP;
2791 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
2797 case XPT_CALC_GEOMETRY:
2799 struct ccb_calc_geometry *ccg;
2801 u_int32_t secs_per_cylinder;
2804 size_mb = ccg->volume_size
2805 / ((1024L * 1024L) / ccg->block_size);
2807 if (size_mb > 4096) {
2809 ccg->secs_per_track = 63;
2810 } else if (size_mb > 2048) {
2812 ccg->secs_per_track = 63;
2813 } else if (size_mb > 1024) {
2815 ccg->secs_per_track = 63;
2818 ccg->secs_per_track = 32;
2820 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
2821 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
2822 ccb->ccb_h.status = CAM_REQ_CMP;
2827 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
2828 ASR_resetBus (sc, cam_sim_bus(sim));
2829 ccb->ccb_h.status = CAM_REQ_CMP;
2833 case XPT_TERM_IO: /* Terminate the I/O process */
2835 ccb->ccb_h.status = CAM_REQ_INVALID;
2839 case XPT_PATH_INQ: /* Path routing inquiry */
2841 struct ccb_pathinq *cpi = &(ccb->cpi);
2843 cpi->version_num = 1; /* XXX??? */
2844 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
2845 cpi->target_sprt = 0;
2846 /* Not necessary to reset bus, done by HDM initialization */
2847 cpi->hba_misc = PIM_NOBUSRESET;
2848 cpi->hba_eng_cnt = 0;
2849 cpi->max_target = sc->ha_MaxId;
2850 cpi->max_lun = sc->ha_MaxLun;
2851 cpi->initiator_id = sc->ha_adapter_target[cam_sim_bus(sim)];
2852 cpi->bus_id = cam_sim_bus(sim);
2853 cpi->base_transfer_speed = 3300;
2854 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
2855 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
2856 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
2857 cpi->unit_number = cam_sim_unit(sim);
2858 cpi->ccb_h.status = CAM_REQ_CMP;
2859 cpi->transport = XPORT_SPI;
2860 cpi->transport_version = 2;
2861 cpi->protocol = PROTO_SCSI;
2862 cpi->protocol_version = SCSI_REV_2;
2867 ccb->ccb_h.status = CAM_REQ_INVALID;
2874 * Handle processing of current CCB as pointed to by the Status.
2877 asr_intr(Asr_softc_t *sc)
2881 for(processed = 0; asr_get_status(sc) & Mask_InterruptsDisabled;
2886 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
2888 if (((ReplyOffset = asr_get_FromFIFO(sc)) == EMPTY_QUEUE)
2889 && ((ReplyOffset = asr_get_FromFIFO(sc)) == EMPTY_QUEUE)) {
2892 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)(ReplyOffset
2893 - sc->ha_Msgs_Phys + (char *)(sc->ha_Msgs));
2895 * We do not need any (optional byteswapping) method access to
2896 * the Initiator context field.
2898 ccb = (union asr_ccb *)(long)
2899 I2O_MESSAGE_FRAME_getInitiatorContext64(
2900 &(Reply->StdReplyFrame.StdMessageFrame));
2901 if (I2O_MESSAGE_FRAME_getMsgFlags(
2902 &(Reply->StdReplyFrame.StdMessageFrame))
2903 & I2O_MESSAGE_FLAGS_FAIL) {
2904 I2O_UTIL_NOP_MESSAGE Message;
2905 PI2O_UTIL_NOP_MESSAGE Message_Ptr;
2908 MessageOffset = (u_long)
2909 I2O_FAILURE_REPLY_MESSAGE_FRAME_getPreservedMFA(
2910 (PI2O_FAILURE_REPLY_MESSAGE_FRAME)Reply);
2912 * Get the Original Message Frame's address, and get
2913 * it's Transaction Context into our space. (Currently
2914 * unused at original authorship, but better to be
2915 * safe than sorry). Straight copy means that we
2916 * need not concern ourselves with the (optional
2917 * byteswapping) method access.
2919 Reply->StdReplyFrame.TransactionContext =
2920 bus_space_read_4(sc->ha_frame_btag,
2921 sc->ha_frame_bhandle, MessageOffset +
2922 offsetof(I2O_SINGLE_REPLY_MESSAGE_FRAME,
2923 TransactionContext));
2925 * For 64 bit machines, we need to reconstruct the
2928 ccb = (union asr_ccb *)(long)
2929 I2O_MESSAGE_FRAME_getInitiatorContext64(
2930 &(Reply->StdReplyFrame.StdMessageFrame));
2932 * Unique error code for command failure.
2934 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
2935 &(Reply->StdReplyFrame), (u_int16_t)-2);
2937 * Modify the message frame to contain a NOP and
2938 * re-issue it to the controller.
2940 Message_Ptr = (PI2O_UTIL_NOP_MESSAGE)ASR_fillMessage(
2941 &Message, sizeof(I2O_UTIL_NOP_MESSAGE));
2942 #if (I2O_UTIL_NOP != 0)
2943 I2O_MESSAGE_FRAME_setFunction (
2944 &(Message_Ptr->StdMessageFrame),
2948 * Copy the packet out to the Original Message
2950 asr_set_frame(sc, Message_Ptr, MessageOffset,
2951 sizeof(I2O_UTIL_NOP_MESSAGE));
2955 asr_set_ToFIFO(sc, MessageOffset);
2959 * Asynchronous command with no return requirements,
2960 * and a generic handler for immunity against odd error
2961 * returns from the adapter.
2965 * Return Reply so that it can be used for the
2968 asr_set_FromFIFO(sc, ReplyOffset);
2972 /* Welease Wadjah! (and stop timeouts) */
2973 ASR_ccbRemove (sc, ccb);
2975 dsc = I2O_SINGLE_REPLY_MESSAGE_FRAME_getDetailedStatusCode(
2976 &(Reply->StdReplyFrame));
2977 ccb->csio.scsi_status = dsc & I2O_SCSI_DEVICE_DSC_MASK;
2978 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
2981 case I2O_SCSI_DSC_SUCCESS:
2982 ccb->ccb_h.status |= CAM_REQ_CMP;
2985 case I2O_SCSI_DSC_CHECK_CONDITION:
2986 ccb->ccb_h.status |= CAM_SCSI_STATUS_ERROR |
2990 case I2O_SCSI_DSC_BUSY:
2992 case I2O_SCSI_HBA_DSC_ADAPTER_BUSY:
2994 case I2O_SCSI_HBA_DSC_SCSI_BUS_RESET:
2996 case I2O_SCSI_HBA_DSC_BUS_BUSY:
2997 ccb->ccb_h.status |= CAM_SCSI_BUSY;
3000 case I2O_SCSI_HBA_DSC_SELECTION_TIMEOUT:
3001 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
3004 case I2O_SCSI_HBA_DSC_COMMAND_TIMEOUT:
3006 case I2O_SCSI_HBA_DSC_DEVICE_NOT_PRESENT:
3008 case I2O_SCSI_HBA_DSC_LUN_INVALID:
3010 case I2O_SCSI_HBA_DSC_SCSI_TID_INVALID:
3011 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
3014 case I2O_SCSI_HBA_DSC_DATA_OVERRUN:
3016 case I2O_SCSI_HBA_DSC_REQUEST_LENGTH_ERROR:
3017 ccb->ccb_h.status |= CAM_DATA_RUN_ERR;
3021 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3024 if ((ccb->csio.resid = ccb->csio.dxfer_len) != 0) {
3026 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getTransferCount(
3030 /* Sense data in reply packet */
3031 if (ccb->ccb_h.status & CAM_AUTOSNS_VALID) {
3032 u_int16_t size = I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getAutoSenseTransferCount(Reply);
3035 if (size > sizeof(ccb->csio.sense_data)) {
3036 size = sizeof(ccb->csio.sense_data);
3038 if (size > I2O_SCSI_SENSE_DATA_SZ) {
3039 size = I2O_SCSI_SENSE_DATA_SZ;
3041 if ((ccb->csio.sense_len)
3042 && (size > ccb->csio.sense_len)) {
3043 size = ccb->csio.sense_len;
3045 if (size < ccb->csio.sense_len) {
3046 ccb->csio.sense_resid =
3047 ccb->csio.sense_len - size;
3049 ccb->csio.sense_resid = 0;
3051 bzero(&(ccb->csio.sense_data),
3052 sizeof(ccb->csio.sense_data));
3053 bcopy(Reply->SenseData,
3054 &(ccb->csio.sense_data), size);
3059 * Return Reply so that it can be used for the next command
3060 * since we have no more need for it now
3062 asr_set_FromFIFO(sc, ReplyOffset);
3064 if (ccb->ccb_h.path) {
3065 xpt_done ((union ccb *)ccb);
3073 #undef QueueSize /* Grrrr */
3074 #undef SG_Size /* Grrrr */
3077 * Meant to be included at the bottom of asr.c !!!
3081 * Included here as hard coded. Done because other necessary include
3082 * files utilize C++ comment structures which make them a nuisance to
3083 * included here just to pick up these three typedefs.
3085 typedef U32 DPT_TAG_T;
3086 typedef U32 DPT_MSG_T;
3087 typedef U32 DPT_RTN_T;
3089 #undef SCSI_RESET /* Conflicts with "scsi/scsiconf.h" defintion */
3090 #include "dev/raid/asr/osd_unix.h"
3092 #define asr_unit(dev) minor(dev)
3094 static u_int8_t ASR_ctlr_held;
3097 asr_open(struct dev_open_args *ap)
3099 cdev_t dev = ap->a_head.a_dev;
3102 if (dev->si_drv1 == NULL) {
3106 if (ASR_ctlr_held) {
3108 } else if ((error = priv_check_cred(ap->a_cred, PRIV_ROOT, 0)) == 0) {
3116 asr_close(struct dev_close_args *ap)
3124 /*-------------------------------------------------------------------------*/
3125 /* Function ASR_queue_i */
3126 /*-------------------------------------------------------------------------*/
3127 /* The Parameters Passed To This Function Are : */
3128 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
3129 /* PI2O_MESSAGE_FRAME : Msg Structure Pointer For This Command */
3130 /* I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME following the Msg Structure */
3132 /* This Function Will Take The User Request Packet And Convert It To An */
3133 /* I2O MSG And Send It Off To The Adapter. */
3135 /* Return : 0 For OK, Error Code Otherwise */
3136 /*-------------------------------------------------------------------------*/
3138 ASR_queue_i(Asr_softc_t *sc, PI2O_MESSAGE_FRAME Packet)
3140 union asr_ccb * ccb;
3141 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
3142 PI2O_MESSAGE_FRAME Message_Ptr;
3143 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply_Ptr;
3144 int MessageSizeInBytes;
3145 int ReplySizeInBytes;
3148 /* Scatter Gather buffer list */
3149 struct ioctlSgList_S {
3150 SLIST_ENTRY(ioctlSgList_S) link;
3152 I2O_FLAGS_COUNT FlagsCount;
3153 char KernelSpace[sizeof(long)];
3155 /* Generates a `first' entry */
3156 SLIST_HEAD(ioctlSgListHead_S, ioctlSgList_S) sgList;
3158 if (ASR_getBlinkLedCode(sc)) {
3159 debug_usr_cmd_printf ("Adapter currently in BlinkLed %x\n",
3160 ASR_getBlinkLedCode(sc));
3163 /* Copy in the message into a local allocation */
3164 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)kmalloc (
3165 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK)) == NULL) {
3166 debug_usr_cmd_printf (
3167 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
3170 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
3171 sizeof(I2O_MESSAGE_FRAME))) != 0) {
3172 kfree(Message_Ptr, M_TEMP);
3173 debug_usr_cmd_printf ("Can't copy in packet errno=%d\n", error);
3176 /* Acquire information to determine type of packet */
3177 MessageSizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)<<2);
3178 /* The offset of the reply information within the user packet */
3179 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)((char *)Packet
3180 + MessageSizeInBytes);
3182 /* Check if the message is a synchronous initialization command */
3183 s = I2O_MESSAGE_FRAME_getFunction(Message_Ptr);
3184 kfree(Message_Ptr, M_TEMP);
3187 case I2O_EXEC_IOP_RESET:
3190 status = ASR_resetIOP(sc);
3191 ReplySizeInBytes = sizeof(status);
3192 debug_usr_cmd_printf ("resetIOP done\n");
3193 return (copyout ((caddr_t)&status, (caddr_t)Reply,
3197 case I2O_EXEC_STATUS_GET:
3198 { PI2O_EXEC_STATUS_GET_REPLY status;
3200 status = &sc->ha_statusmem->status;
3201 if (ASR_getStatus(sc) == NULL) {
3202 debug_usr_cmd_printf ("getStatus failed\n");
3205 ReplySizeInBytes = sizeof(status);
3206 debug_usr_cmd_printf ("getStatus done\n");
3207 return (copyout ((caddr_t)status, (caddr_t)Reply,
3211 case I2O_EXEC_OUTBOUND_INIT:
3214 status = ASR_initOutBound(sc);
3215 ReplySizeInBytes = sizeof(status);
3216 debug_usr_cmd_printf ("intOutBound done\n");
3217 return (copyout ((caddr_t)&status, (caddr_t)Reply,
3222 /* Determine if the message size is valid */
3223 if ((MessageSizeInBytes < sizeof(I2O_MESSAGE_FRAME))
3224 || (MAX_INBOUND_SIZE < MessageSizeInBytes)) {
3225 debug_usr_cmd_printf ("Packet size %d incorrect\n",
3226 MessageSizeInBytes);
3230 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)kmalloc (MessageSizeInBytes,
3231 M_TEMP, M_WAITOK)) == NULL) {
3232 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
3233 MessageSizeInBytes);
3236 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
3237 MessageSizeInBytes)) != 0) {
3238 kfree(Message_Ptr, M_TEMP);
3239 debug_usr_cmd_printf ("Can't copy in packet[%d] errno=%d\n",
3240 MessageSizeInBytes, error);
3244 /* Check the size of the reply frame, and start constructing */
3246 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)kmalloc (
3247 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK)) == NULL) {
3248 kfree(Message_Ptr, M_TEMP);
3249 debug_usr_cmd_printf (
3250 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
3253 if ((error = copyin ((caddr_t)Reply, (caddr_t)Reply_Ptr,
3254 sizeof(I2O_MESSAGE_FRAME))) != 0) {
3255 kfree(Reply_Ptr, M_TEMP);
3256 kfree(Message_Ptr, M_TEMP);
3257 debug_usr_cmd_printf (
3258 "Failed to copy in reply frame, errno=%d\n",
3262 ReplySizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(
3263 &(Reply_Ptr->StdReplyFrame.StdMessageFrame)) << 2);
3264 kfree(Reply_Ptr, M_TEMP);
3265 if (ReplySizeInBytes < sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME)) {
3266 kfree(Message_Ptr, M_TEMP);
3267 debug_usr_cmd_printf (
3268 "Failed to copy in reply frame[%d], errno=%d\n",
3269 ReplySizeInBytes, error);
3273 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)kmalloc (
3274 ((ReplySizeInBytes > sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME))
3275 ? ReplySizeInBytes : sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)),
3276 M_TEMP, M_WAITOK)) == NULL) {
3277 kfree(Message_Ptr, M_TEMP);
3278 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
3282 (void)ASR_fillMessage((void *)Reply_Ptr, ReplySizeInBytes);
3283 Reply_Ptr->StdReplyFrame.StdMessageFrame.InitiatorContext
3284 = Message_Ptr->InitiatorContext;
3285 Reply_Ptr->StdReplyFrame.TransactionContext
3286 = ((PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr)->TransactionContext;
3287 I2O_MESSAGE_FRAME_setMsgFlags(
3288 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
3289 I2O_MESSAGE_FRAME_getMsgFlags(
3290 &(Reply_Ptr->StdReplyFrame.StdMessageFrame))
3291 | I2O_MESSAGE_FLAGS_REPLY);
3293 /* Check if the message is a special case command */
3294 switch (I2O_MESSAGE_FRAME_getFunction(Message_Ptr)) {
3295 case I2O_EXEC_SYS_TAB_SET: /* Special Case of empty Scatter Gather */
3296 if (MessageSizeInBytes == ((I2O_MESSAGE_FRAME_getVersionOffset(
3297 Message_Ptr) & 0xF0) >> 2)) {
3298 kfree(Message_Ptr, M_TEMP);
3299 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
3300 &(Reply_Ptr->StdReplyFrame),
3301 (ASR_setSysTab(sc) != CAM_REQ_CMP));
3302 I2O_MESSAGE_FRAME_setMessageSize(
3303 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
3304 sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME));
3305 error = copyout ((caddr_t)Reply_Ptr, (caddr_t)Reply,
3307 kfree(Reply_Ptr, M_TEMP);
3312 /* Deal in the general case */
3313 /* First allocate and optionally copy in each scatter gather element */
3314 SLIST_INIT(&sgList);
3315 if ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0) != 0) {
3316 PI2O_SGE_SIMPLE_ELEMENT sg;
3319 * since this code is reused in several systems, code
3320 * efficiency is greater by using a shift operation rather
3321 * than a divide by sizeof(u_int32_t).
3323 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
3324 + ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0)
3326 while (sg < (PI2O_SGE_SIMPLE_ELEMENT)(((caddr_t)Message_Ptr)
3327 + MessageSizeInBytes)) {
3331 if ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
3332 & I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT) == 0) {
3336 len = I2O_FLAGS_COUNT_getCount(&(sg->FlagsCount));
3337 debug_usr_cmd_printf ("SG[%d] = %x[%d]\n",
3338 sg - (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
3339 + ((I2O_MESSAGE_FRAME_getVersionOffset(
3340 Message_Ptr) & 0xF0) >> 2)),
3341 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg), len);
3343 if ((elm = (struct ioctlSgList_S *)kmalloc (
3344 sizeof(*elm) - sizeof(elm->KernelSpace) + len,
3345 M_TEMP, M_WAITOK)) == NULL) {
3346 debug_usr_cmd_printf (
3347 "Failed to allocate SG[%d]\n", len);
3351 SLIST_INSERT_HEAD(&sgList, elm, link);
3352 elm->FlagsCount = sg->FlagsCount;
3353 elm->UserSpace = (caddr_t)
3354 (I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg));
3355 v = elm->KernelSpace;
3356 /* Copy in outgoing data (DIR bit could be invalid) */
3357 if ((error = copyin (elm->UserSpace, (caddr_t)v, len))
3362 * If the buffer is not contiguous, lets
3363 * break up the scatter/gather entries.
3366 && (sg < (PI2O_SGE_SIMPLE_ELEMENT)
3367 (((caddr_t)Message_Ptr) + MAX_INBOUND_SIZE))) {
3368 int next, base, span;
3371 next = base = KVTOPHYS(v);
3372 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg,
3375 /* How far can we go physically contiguously */
3376 while ((len > 0) && (base == next)) {
3379 next = trunc_page(base) + PAGE_SIZE;
3390 /* Construct the Flags */
3391 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount),
3394 int flags = I2O_FLAGS_COUNT_getFlags(
3395 &(elm->FlagsCount));
3396 /* Any remaining length? */
3399 ~(I2O_SGL_FLAGS_END_OF_BUFFER
3400 | I2O_SGL_FLAGS_LAST_ELEMENT);
3402 I2O_FLAGS_COUNT_setFlags(
3403 &(sg->FlagsCount), flags);
3406 debug_usr_cmd_printf ("sg[%d] = %x[%d]\n",
3407 sg - (PI2O_SGE_SIMPLE_ELEMENT)
3408 ((char *)Message_Ptr
3409 + ((I2O_MESSAGE_FRAME_getVersionOffset(
3410 Message_Ptr) & 0xF0) >> 2)),
3411 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg),
3418 * Incrementing requires resizing of the
3419 * packet, and moving up the existing SG
3423 MessageSizeInBytes += sizeof(*sg);
3424 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
3425 I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)
3426 + (sizeof(*sg) / sizeof(U32)));
3428 PI2O_MESSAGE_FRAME NewMessage_Ptr;
3431 = (PI2O_MESSAGE_FRAME)
3432 kmalloc (MessageSizeInBytes,
3433 M_TEMP, M_WAITOK)) == NULL) {
3434 debug_usr_cmd_printf (
3435 "Failed to acquire frame[%d] memory\n",
3436 MessageSizeInBytes);
3440 span = ((caddr_t)sg)
3441 - (caddr_t)Message_Ptr;
3442 bcopy(Message_Ptr,NewMessage_Ptr, span);
3443 bcopy((caddr_t)(sg-1),
3444 ((caddr_t)NewMessage_Ptr) + span,
3445 MessageSizeInBytes - span);
3446 kfree(Message_Ptr, M_TEMP);
3447 sg = (PI2O_SGE_SIMPLE_ELEMENT)
3448 (((caddr_t)NewMessage_Ptr) + span);
3449 Message_Ptr = NewMessage_Ptr;
3453 || ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
3454 & I2O_SGL_FLAGS_LAST_ELEMENT) != 0)) {
3460 while ((elm = SLIST_FIRST(&sgList)) != NULL) {
3461 SLIST_REMOVE_HEAD(&sgList, link);
3464 kfree(Reply_Ptr, M_TEMP);
3465 kfree(Message_Ptr, M_TEMP);
3470 debug_usr_cmd_printf ("Inbound: ");
3471 debug_usr_cmd_dump_message(Message_Ptr);
3473 /* Send the command */
3474 if ((ccb = asr_alloc_ccb (sc)) == NULL) {
3475 /* Free up in-kernel buffers */
3476 while ((elm = SLIST_FIRST(&sgList)) != NULL) {
3477 SLIST_REMOVE_HEAD(&sgList, link);
3480 kfree(Reply_Ptr, M_TEMP);
3481 kfree(Message_Ptr, M_TEMP);
3486 * We do not need any (optional byteswapping) method access to
3487 * the Initiator context field.
3489 I2O_MESSAGE_FRAME_setInitiatorContext64(
3490 (PI2O_MESSAGE_FRAME)Message_Ptr, (long)ccb);
3492 (void)ASR_queue (sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
3494 kfree(Message_Ptr, M_TEMP);
3497 * Wait for the board to report a finished instruction.
3500 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
3501 if (ASR_getBlinkLedCode(sc)) {
3503 kprintf ("asr%d: Blink LED 0x%x resetting adapter\n",
3504 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
3505 ASR_getBlinkLedCode(sc));
3506 if (ASR_reset (sc) == ENXIO) {
3507 /* Command Cleanup */
3508 ASR_ccbRemove(sc, ccb);
3511 /* Free up in-kernel buffers */
3512 while ((elm = SLIST_FIRST(&sgList)) != NULL) {
3513 SLIST_REMOVE_HEAD(&sgList, link);
3516 kfree(Reply_Ptr, M_TEMP);
3520 /* Check every second for BlinkLed */
3521 /* There is no PRICAM, but outwardly PRIBIO is functional */
3522 tsleep(ccb, 0, "asr", hz);
3526 debug_usr_cmd_printf ("Outbound: ");
3527 debug_usr_cmd_dump_message(Reply_Ptr);
3529 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
3530 &(Reply_Ptr->StdReplyFrame),
3531 (ccb->ccb_h.status != CAM_REQ_CMP));
3533 if (ReplySizeInBytes >= (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
3534 - I2O_SCSI_SENSE_DATA_SZ - sizeof(U32))) {
3535 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setTransferCount(Reply_Ptr,
3536 ccb->csio.dxfer_len - ccb->csio.resid);
3538 if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) && (ReplySizeInBytes
3539 > (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
3540 - I2O_SCSI_SENSE_DATA_SZ))) {
3541 int size = ReplySizeInBytes
3542 - sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
3543 - I2O_SCSI_SENSE_DATA_SZ;
3545 if (size > sizeof(ccb->csio.sense_data)) {
3546 size = sizeof(ccb->csio.sense_data);
3548 if (size < ccb->csio.sense_len) {
3549 ccb->csio.sense_resid = ccb->csio.sense_len - size;
3551 ccb->csio.sense_resid = 0;
3553 bzero(&(ccb->csio.sense_data), sizeof(ccb->csio.sense_data));
3554 bcopy(&(ccb->csio.sense_data), Reply_Ptr->SenseData, size);
3555 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setAutoSenseTransferCount(
3559 /* Free up in-kernel buffers */
3560 while ((elm = SLIST_FIRST(&sgList)) != NULL) {
3561 /* Copy out as necessary */
3563 /* DIR bit considered `valid', error due to ignorance works */
3564 && ((I2O_FLAGS_COUNT_getFlags(&(elm->FlagsCount))
3565 & I2O_SGL_FLAGS_DIR) == 0)) {
3566 error = copyout((caddr_t)(elm->KernelSpace),
3568 I2O_FLAGS_COUNT_getCount(&(elm->FlagsCount)));
3570 SLIST_REMOVE_HEAD(&sgList, link);
3574 /* Copy reply frame to user space */
3575 error = copyout((caddr_t)Reply_Ptr, (caddr_t)Reply,
3578 kfree(Reply_Ptr, M_TEMP);
3584 /*----------------------------------------------------------------------*/
3585 /* Function asr_ioctl */
3586 /*----------------------------------------------------------------------*/
3587 /* The parameters passed to this function are : */
3588 /* dev : Device number. */
3589 /* cmd : Ioctl Command */
3590 /* data : User Argument Passed In. */
3591 /* flag : Mode Parameter */
3592 /* proc : Process Parameter */
3594 /* This function is the user interface into this adapter driver */
3596 /* Return : zero if OK, error code if not */
3597 /*----------------------------------------------------------------------*/
3600 asr_ioctl(struct dev_ioctl_args *ap)
3602 cdev_t dev = ap->a_head.a_dev;
3603 u_long cmd = ap->a_cmd;
3604 caddr_t data = ap->a_data;
3605 Asr_softc_t *sc = dev->si_drv1;
3607 #ifdef ASR_IOCTL_COMPAT
3609 #endif /* ASR_IOCTL_COMPAT */
3616 #ifdef ASR_IOCTL_COMPAT
3617 #if (dsDescription_size != 50)
3618 case DPT_SIGNATURE + ((50 - dsDescription_size) << 16):
3620 if (cmd & 0xFFFF0000) {
3621 bcopy(&ASR_sig, data, sizeof(dpt_sig_S));
3624 /* Traditional version of the ioctl interface */
3625 case DPT_SIGNATURE & 0x0000FFFF:
3627 return (copyout((caddr_t)(&ASR_sig), *((caddr_t *)data),
3628 sizeof(dpt_sig_S)));
3630 /* Traditional version of the ioctl interface */
3631 case DPT_CTRLINFO & 0x0000FFFF:
3632 case DPT_CTRLINFO: {
3635 u_int16_t drvrHBAnum;
3637 u_int16_t blinkState;
3639 u_int8_t pciDeviceNum;
3641 u_int16_t Interrupt;
3642 u_int32_t reserved1;
3643 u_int32_t reserved2;
3644 u_int32_t reserved3;
3647 bzero(&CtlrInfo, sizeof(CtlrInfo));
3648 CtlrInfo.length = sizeof(CtlrInfo) - sizeof(u_int16_t);
3649 CtlrInfo.drvrHBAnum = asr_unit(dev);
3650 CtlrInfo.baseAddr = sc->ha_Base;
3651 i = ASR_getBlinkLedCode (sc);
3655 CtlrInfo.blinkState = i;
3656 CtlrInfo.pciBusNum = sc->ha_pciBusNum;
3657 CtlrInfo.pciDeviceNum = sc->ha_pciDeviceNum;
3658 #define FLG_OSD_PCI_VALID 0x0001
3659 #define FLG_OSD_DMA 0x0002
3660 #define FLG_OSD_I2O 0x0004
3661 CtlrInfo.hbaFlags = FLG_OSD_PCI_VALID|FLG_OSD_DMA|FLG_OSD_I2O;
3662 CtlrInfo.Interrupt = sc->ha_irq;
3663 #ifdef ASR_IOCTL_COMPAT
3664 if (cmd & 0xffff0000)
3665 bcopy(&CtlrInfo, data, sizeof(CtlrInfo));
3667 #endif /* ASR_IOCTL_COMPAT */
3668 error = copyout(&CtlrInfo, *(caddr_t *)data, sizeof(CtlrInfo));
3671 /* Traditional version of the ioctl interface */
3672 case DPT_SYSINFO & 0x0000FFFF:
3675 #ifdef ASR_IOCTL_COMPAT
3677 /* Kernel Specific ptok `hack' */
3678 #define ptok(a) ((char *)(uintptr_t)(a) + KERNBASE)
3680 bzero(&Info, sizeof(Info));
3682 /* Appears I am the only person in the Kernel doing this */
3690 Info.drive0CMOS = j;
3697 Info.drive1CMOS = j;
3699 Info.numDrives = *((char *)ptok(0x475));
3700 #else /* ASR_IOCTL_COMPAT */
3701 bzero(&Info, sizeof(Info));
3702 #endif /* ASR_IOCTL_COMPAT */
3704 Info.processorFamily = ASR_sig.dsProcessorFamily;
3705 Info.osType = OS_BSDI_UNIX;
3706 Info.osMajorVersion = osrelease[0] - '0';
3707 Info.osMinorVersion = osrelease[2] - '0';
3708 /* Info.osRevision = 0; */
3709 /* Info.osSubRevision = 0; */
3710 Info.busType = SI_PCI_BUS;
3711 Info.flags = SI_OSversionValid|SI_BusTypeValid|SI_NO_SmartROM;
3713 #ifdef ASR_IOCTL_COMPAT
3714 Info.flags |= SI_CMOS_Valid | SI_NumDrivesValid;
3715 /* Go Out And Look For I2O SmartROM */
3716 for(j = 0xC8000; j < 0xE0000; j += 2048) {
3720 if (*((unsigned short *)cp) != 0xAA55) {
3723 j += (cp[2] * 512) - 2048;
3724 if ((*((u_long *)(cp + 6))
3725 != ('S' + (' ' * 256) + (' ' * 65536L)))
3726 || (*((u_long *)(cp + 10))
3727 != ('I' + ('2' * 256) + ('0' * 65536L)))) {
3731 for (k = 0; k < 64; ++k) {
3732 if (*((unsigned short *)cp)
3733 == (' ' + ('v' * 256))) {
3738 Info.smartROMMajorVersion
3739 = *((unsigned char *)(cp += 4)) - '0';
3740 Info.smartROMMinorVersion
3741 = *((unsigned char *)(cp += 2));
3742 Info.smartROMRevision
3743 = *((unsigned char *)(++cp));
3744 Info.flags |= SI_SmartROMverValid;
3745 Info.flags &= ~SI_NO_SmartROM;
3749 /* Get The Conventional Memory Size From CMOS */
3755 Info.conventionalMemSize = j;
3757 /* Get The Extended Memory Found At Power On From CMOS */
3763 Info.extendedMemSize = j;
3764 Info.flags |= SI_MemorySizeValid;
3766 /* Copy Out The Info Structure To The User */
3767 if (cmd & 0xFFFF0000)
3768 bcopy(&Info, data, sizeof(Info));
3770 #endif /* ASR_IOCTL_COMPAT */
3771 error = copyout(&Info, *(caddr_t *)data, sizeof(Info));
3774 /* Get The BlinkLED State */
3776 i = ASR_getBlinkLedCode (sc);
3779 #ifdef ASR_IOCTL_COMPAT
3780 if (cmd & 0xffff0000)
3781 bcopy(&i, data, sizeof(i));
3783 #endif /* ASR_IOCTL_COMPAT */
3784 error = copyout(&i, *(caddr_t *)data, sizeof(i));
3787 /* Send an I2O command */
3789 return (ASR_queue_i(sc, *((PI2O_MESSAGE_FRAME *)data)));
3791 /* Reset and re-initialize the adapter */
3793 return (ASR_reset(sc));
3795 /* Rescan the LCT table and resynchronize the information */
3797 return (ASR_rescan(sc));