1 /* $FreeBSD: src/sys/dev/asr/asr.c,v 1.3.2.2 2001/08/23 05:21:29 scottl Exp $ */
3 * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
4 * Copyright (c) 2000-2001 Adaptec Corporation
7 * TERMS AND CONDITIONS OF USE
9 * Redistribution and use in source form, with or without modification, are
10 * permitted provided that redistributions of source code must retain the
11 * above copyright notice, this list of conditions and the following disclaimer.
13 * This software is provided `as is' by Adaptec and any express or implied
14 * warranties, including, but not limited to, the implied warranties of
15 * merchantability and fitness for a particular purpose, are disclaimed. In no
16 * event shall Adaptec be liable for any direct, indirect, incidental, special,
17 * exemplary or consequential damages (including, but not limited to,
18 * procurement of substitute goods or services; loss of use, data, or profits;
19 * or business interruptions) however caused and on any theory of liability,
20 * whether in contract, strict liability, or tort (including negligence or
21 * otherwise) arising in any way out of the use of this driver software, even
22 * if advised of the possibility of such damage.
24 * SCSI I2O host adapter driver
26 * V1.08 2001/08/21 Mark_Salyzyn@adaptec.com
27 * - The 2000S and 2005S do not initialize on some machines,
28 * increased timeout to 255ms from 50ms for the StatusGet
30 * V1.07 2001/05/22 Mark_Salyzyn@adaptec.com
31 * - I knew this one was too good to be true. The error return
32 * on ioctl commands needs to be compared to CAM_REQ_CMP, not
33 * to the bit masked status.
34 * V1.06 2001/05/08 Mark_Salyzyn@adaptec.com
35 * - The 2005S that was supported is affectionately called the
36 * Conjoined BAR Firmware. In order to support RAID-5 in a
37 * 16MB low-cost configuration, Firmware was forced to go
38 * to a Split BAR Firmware. This requires a separate IOP and
39 * Messaging base address.
40 * V1.05 2001/04/25 Mark_Salyzyn@adaptec.com
41 * - Handle support for 2005S Zero Channel RAID solution.
42 * - System locked up if the Adapter locked up. Do not try
43 * to send other commands if the resetIOP command fails. The
44 * fail outstanding command discovery loop was flawed as the
45 * removal of the command from the list prevented discovering
47 * - Comment changes to clarify driver.
48 * - SysInfo searched for an EATA SmartROM, not an I2O SmartROM.
49 * - We do not use the AC_FOUND_DEV event because of I2O.
51 * V1.04 2000/09/22 Mark_Salyzyn@adaptec.com, msmith@freebsd.org,
52 * lampa@fee.vutbr.cz and Scott_Long@adaptec.com.
53 * - Removed support for PM1554, PM2554 and PM2654 in Mode-0
54 * mode as this is confused with competitor adapters in run
56 * - critical locking needed in ASR_ccbAdd and ASR_ccbRemove
57 * to prevent operating system panic.
58 * - moved default major number to 154 from 97.
59 * V1.03 2000/07/12 Mark_Salyzyn@adaptec.com
60 * - The controller is not actually an ASR (Adaptec SCSI RAID)
61 * series that is visible, it's more of an internal code name.
62 * remove any visible references within reason for now.
63 * - bus_ptr->LUN was not correctly zeroed when initially
64 * allocated causing a possible panic of the operating system
66 * V1.02 2000/06/26 Mark_Salyzyn@adaptec.com
67 * - Code always fails for ASR_getTid affecting performance.
68 * - initiated a set of changes that resulted from a formal
69 * code inspection by Mark_Salyzyn@adaptec.com,
70 * George_Dake@adaptec.com, Jeff_Zeak@adaptec.com,
71 * Martin_Wilson@adaptec.com and Vincent_Trandoan@adaptec.com.
72 * Their findings were focussed on the LCT & TID handler, and
73 * all resulting changes were to improve code readability,
74 * consistency or have a positive effect on performance.
75 * V1.01 2000/06/14 Mark_Salyzyn@adaptec.com
76 * - Passthrough returned an incorrect error.
77 * - Passthrough did not migrate the intrinsic scsi layer wakeup
78 * on command completion.
79 * - generate control device nodes using make_dev and delete_dev.
80 * - Performance affected by TID caching reallocing.
81 * - Made suggested changes by Justin_Gibbs@adaptec.com
82 * - use splcam instead of splbio.
83 * - use cam_imask instead of bio_imask.
84 * - use u_int8_t instead of u_char.
85 * - use u_int16_t instead of u_short.
86 * - use u_int32_t instead of u_long where appropriate.
87 * - use 64 bit context handler instead of 32 bit.
88 * - create_ccb should only allocate the worst case
89 * requirements for the driver since CAM may evolve
90 * making union ccb much larger than needed here.
91 * renamed create_ccb to asr_alloc_ccb.
92 * - go nutz justifying all debug prints as macros
93 * defined at the top and remove unsightly ifdefs.
94 * - INLINE STATIC viewed as confusing. Historically
95 * utilized to affect code performance and debug
96 * issues in OS, Compiler or OEM specific situations.
97 * V1.00 2000/05/31 Mark_Salyzyn@adaptec.com
98 * - Ported from FreeBSD 2.2.X DPT I2O driver.
99 * changed struct scsi_xfer to union ccb/struct ccb_hdr
100 * changed variable name xs to ccb
101 * changed struct scsi_link to struct cam_path
102 * changed struct scsibus_data to struct cam_sim
103 * stopped using fordriver for holding on to the TID
104 * use proprietary packet creation instead of scsi_inquire
105 * CAM layer sends synchronize commands.
108 #define ASR_VERSION 1
109 #define ASR_REVISION '0'
110 #define ASR_SUBREVISION '8'
113 #define ASR_YEAR 2001 - 1980
116 * Debug macros to reduce the unsightly ifdefs
118 #if (defined(DEBUG_ASR) || defined(DEBUG_ASR_USR_CMD) || defined(DEBUG_ASR_CMD))
119 # define debug_asr_message(message) \
121 u_int32_t * pointer = (u_int32_t *)message; \
122 u_int32_t length = I2O_MESSAGE_FRAME_getMessageSize(message);\
123 u_int32_t counter = 0; \
126 printf ("%08lx%c", (u_long)*(pointer++), \
127 (((++counter & 7) == 0) || (length == 0)) \
132 #endif /* DEBUG_ASR || DEBUG_ASR_USR_CMD || DEBUG_ASR_CMD */
134 #if (defined(DEBUG_ASR))
135 /* Breaks on none STDC based compilers :-( */
136 # define debug_asr_printf(fmt,args...) printf(fmt, ##args)
137 # define debug_asr_dump_message(message) debug_asr_message(message)
138 # define debug_asr_print_path(ccb) xpt_print_path(ccb->ccb_h.path);
139 /* None fatal version of the ASSERT macro */
140 # if (defined(__STDC__))
141 # define ASSERT(phrase) if(!(phrase))printf(#phrase " at line %d file %s\n",__LINE__,__FILE__)
143 # define ASSERT(phrase) if(!(phrase))printf("phrase" " at line %d file %s\n",__LINE__,__FILE__)
145 #else /* DEBUG_ASR */
146 # define debug_asr_printf(fmt,args...)
147 # define debug_asr_dump_message(message)
148 # define debug_asr_print_path(ccb)
150 #endif /* DEBUG_ASR */
153 * If DEBUG_ASR_CMD is defined:
154 * 0 - Display incoming SCSI commands
155 * 1 - add in a quick character before queueing.
156 * 2 - add in outgoing message frames.
158 #if (defined(DEBUG_ASR_CMD))
159 # define debug_asr_cmd_printf(fmt,args...) printf(fmt,##args)
160 # define debug_asr_dump_ccb(ccb) \
162 u_int8_t * cp = (unsigned char *)&(ccb->csio.cdb_io); \
163 int len = ccb->csio.cdb_len; \
166 debug_asr_cmd_printf (" %02x", *(cp++)); \
170 # if (DEBUG_ASR_CMD > 0)
171 # define debug_asr_cmd1_printf debug_asr_cmd_printf
173 # define debug_asr_cmd1_printf(fmt,args...)
175 # if (DEBUG_ASR_CMD > 1)
176 # define debug_asr_cmd2_printf debug_asr_cmd_printf
177 # define debug_asr_cmd2_dump_message(message) debug_asr_message(message)
179 # define debug_asr_cmd2_printf(fmt,args...)
180 # define debug_asr_cmd2_dump_message(message)
182 #else /* DEBUG_ASR_CMD */
183 # define debug_asr_cmd_printf(fmt,args...)
184 # define debug_asr_cmd_dump_ccb(ccb)
185 # define debug_asr_cmd1_printf(fmt,args...)
186 # define debug_asr_cmd2_printf(fmt,args...)
187 # define debug_asr_cmd2_dump_message(message)
188 #endif /* DEBUG_ASR_CMD */
190 #if (defined(DEBUG_ASR_USR_CMD))
191 # define debug_usr_cmd_printf(fmt,args...) printf(fmt,##args)
192 # define debug_usr_cmd_dump_message(message) debug_usr_message(message)
193 #else /* DEBUG_ASR_USR_CMD */
194 # define debug_usr_cmd_printf(fmt,args...)
195 # define debug_usr_cmd_dump_message(message)
196 #endif /* DEBUG_ASR_USR_CMD */
198 #define dsDescription_size 46 /* Snug as a bug in a rug */
199 #include "dev/asr/dptsig.h"
201 static dpt_sig_S ASR_sig = {
202 { 'd', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, PROC_INTEL,
203 PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM, FT_HBADRVR, 0,
204 OEM_DPT, OS_FREE_BSD, CAP_ABOVE16MB, DEV_ALL,
206 0, 0, ASR_VERSION, ASR_REVISION, ASR_SUBREVISION,
207 ASR_MONTH, ASR_DAY, ASR_YEAR,
208 /* 01234567890123456789012345678901234567890123456789 < 50 chars */
209 "Adaptec FreeBSD 4.0.0 Unix SCSI I2O HBA Driver"
210 /* ^^^^^ asr_attach alters these to match OS */
213 #include <sys/param.h> /* TRUE=1 and FALSE=0 defined here */
214 #include <sys/kernel.h>
215 #include <sys/systm.h>
216 #include <sys/malloc.h>
217 #include <sys/proc.h>
218 #include <sys/conf.h>
219 #include <sys/disklabel.h>
221 #include <machine/resource.h>
222 #include <machine/bus.h>
223 #include <sys/rman.h>
224 #include <sys/stat.h>
227 #include <cam/cam_ccb.h>
228 #include <cam/cam_sim.h>
229 #include <cam/cam_xpt_sim.h>
230 #include <cam/cam_xpt_periph.h>
232 #include <cam/scsi/scsi_all.h>
233 #include <cam/scsi/scsi_message.h>
237 #include <machine/cputypes.h>
238 #include <machine/clock.h>
239 #include <i386/include/vmparam.h>
241 #include <pci/pcivar.h>
242 #include <pci/pcireg.h>
244 #define STATIC static
247 #if (defined(DEBUG_ASR) && (DEBUG_ASR > 0))
257 #define osdSwap4(x) ((u_long)ntohl((u_long)(x)))
258 #define KVTOPHYS(x) vtophys(x)
259 #include "dev/asr/dptalign.h"
260 #include "dev/asr/i2oexec.h"
261 #include "dev/asr/i2obscsi.h"
262 #include "dev/asr/i2odpt.h"
263 #include "dev/asr/i2oadptr.h"
266 #include "dev/asr/sys_info.h"
268 /* Configuration Definitions */
270 #define SG_SIZE 58 /* Scatter Gather list Size */
271 #define MAX_TARGET_ID 126 /* Maximum Target ID supported */
272 #define MAX_LUN 255 /* Maximum LUN Supported */
273 #define MAX_CHANNEL 7 /* Maximum Channel # Supported by driver */
274 #define MAX_INBOUND 2000 /* Max CCBs, Also Max Queue Size */
275 #define MAX_OUTBOUND 256 /* Maximum outbound frames/adapter */
276 #define MAX_INBOUND_SIZE 512 /* Maximum inbound frame size */
277 #define MAX_MAP 4194304L /* Maximum mapping size of IOP */
278 /* Also serves as the minimum map for */
279 /* the 2005S zero channel RAID product */
281 /**************************************************************************
282 ** ASR Host Adapter structure - One Structure For Each Host Adapter That **
283 ** Is Configured Into The System. The Structure Supplies Configuration **
284 ** Information, Status Info, Queue Info And An Active CCB List Pointer. **
285 ***************************************************************************/
287 /* I2O register set */
292 # define Mask_InterruptsDisabled 0x08
294 volatile U32 ToFIFO; /* In Bound FIFO */
295 volatile U32 FromFIFO; /* Out Bound FIFO */
299 * A MIX of performance and space considerations for TID lookups
301 typedef u_int16_t tid_t;
304 u_int32_t size; /* up to MAX_LUN */
309 u_int32_t size; /* up to MAX_TARGET */
314 * To ensure that we only allocate and use the worst case ccb here, lets
315 * make our own local ccb union. If asr_alloc_ccb is utilized for another
316 * ccb type, ensure that you add the additional structures into our local
317 * ccb union. To ensure strict type checking, we will utilize the local
318 * ccb definition wherever possible.
321 struct ccb_hdr ccb_h; /* For convenience */
322 struct ccb_scsiio csio;
323 struct ccb_setasync csa;
326 typedef struct Asr_softc {
328 void * ha_Base; /* base port for each board */
329 u_int8_t * volatile ha_blinkLED;
330 i2oRegs_t * ha_Virt; /* Base address of IOP */
331 U8 * ha_Fvirt; /* Base address of Frames */
332 I2O_IOP_ENTRY ha_SystemTable;
333 LIST_HEAD(,ccb_hdr) ha_ccb; /* ccbs in use */
334 struct cam_path * ha_path[MAX_CHANNEL+1];
335 struct cam_sim * ha_sim[MAX_CHANNEL+1];
336 #if __FreeBSD_version >= 400000
337 struct resource * ha_mem_res;
338 struct resource * ha_mes_res;
339 struct resource * ha_irq_res;
342 PI2O_LCT ha_LCT; /* Complete list of devices */
343 # define le_type IdentityTag[0]
344 # define I2O_BSA 0x20
345 # define I2O_FCA 0x40
346 # define I2O_SCSI 0x00
347 # define I2O_PORT 0x80
348 # define I2O_UNKNOWN 0x7F
349 # define le_bus IdentityTag[1]
350 # define le_target IdentityTag[2]
351 # define le_lun IdentityTag[3]
352 target2lun_t * ha_targets[MAX_CHANNEL+1];
353 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME ha_Msgs;
356 u_int8_t ha_in_reset;
357 # define HA_OPERATIONAL 0
358 # define HA_IN_RESET 1
359 # define HA_OFF_LINE 2
360 # define HA_OFF_LINE_RECOVERY 3
361 /* Configuration information */
362 /* The target id maximums we take */
363 u_int8_t ha_MaxBus; /* Maximum bus */
364 u_int8_t ha_MaxId; /* Maximum target ID */
365 u_int8_t ha_MaxLun; /* Maximum target LUN */
366 u_int8_t ha_SgSize; /* Max SG elements */
367 u_int8_t ha_pciBusNum;
368 u_int8_t ha_pciDeviceNum;
369 u_int8_t ha_adapter_target[MAX_CHANNEL+1];
370 u_int16_t ha_QueueSize; /* Max outstanding commands */
371 u_int16_t ha_Msgs_Count;
373 /* Links into other parents and HBAs */
374 struct Asr_softc * ha_next; /* HBA list */
376 #ifdef ASR_MEASURE_PERFORMANCE
377 #define MAX_TIMEQ_SIZE 256 // assumes MAX 256 scsi commands sent
378 asr_perf_t ha_performance;
379 u_int32_t ha_submitted_ccbs_count;
381 // Queueing macros for a circular queue
382 #define TIMEQ_FREE_LIST_EMPTY(head, tail) (-1 == (head) && -1 == (tail))
383 #define TIMEQ_FREE_LIST_FULL(head, tail) ((((tail) + 1) % MAX_TIMEQ_SIZE) == (head))
384 #define ENQ_TIMEQ_FREE_LIST(item, Q, head, tail) \
385 if (!TIMEQ_FREE_LIST_FULL((head), (tail))) { \
386 if TIMEQ_FREE_LIST_EMPTY((head),(tail)) { \
387 (head) = (tail) = 0; \
389 else (tail) = ((tail) + 1) % MAX_TIMEQ_SIZE; \
390 Q[(tail)] = (item); \
393 debug_asr_printf("asr: Enqueueing when TimeQ Free List is full... This should not happen!\n"); \
395 #define DEQ_TIMEQ_FREE_LIST(item, Q, head, tail) \
396 if (!TIMEQ_FREE_LIST_EMPTY((head), (tail))) { \
398 if ((head) == (tail)) { (head) = (tail) = -1; } \
399 else (head) = ((head) + 1) % MAX_TIMEQ_SIZE; \
403 debug_asr_printf("asr: Dequeueing when TimeQ Free List is empty... This should not happen!\n"); \
406 // Circular queue of time stamps
407 struct timeval ha_timeQ[MAX_TIMEQ_SIZE];
408 u_int32_t ha_timeQFreeList[MAX_TIMEQ_SIZE];
409 int ha_timeQFreeHead;
410 int ha_timeQFreeTail;
414 STATIC Asr_softc_t * Asr_softc;
417 * Prototypes of the routines we have in this object.
420 /* Externally callable routines */
421 #if __FreeBSD_version >= 400000
422 #define PROBE_ARGS IN device_t tag
423 #define PROBE_RET int
424 #define PROBE_SET() u_long id = (pci_get_device(tag)<<16)|pci_get_vendor(tag)
425 #define PROBE_RETURN(retval) if(retval){device_set_desc(tag,retval);return(0);}else{return(ENXIO);}
426 #define ATTACH_ARGS IN device_t tag
427 #define ATTACH_RET int
428 #define ATTACH_SET() int unit = device_get_unit(tag)
429 #define ATTACH_RETURN(retval) return(retval)
431 #define PROBE_ARGS IN pcici_t tag, IN pcidi_t id
432 #define PROBE_RET const char *
434 #define PROBE_RETURN(retval) return(retval)
435 #define ATTACH_ARGS IN pcici_t tag, IN int unit
436 #define ATTACH_RET void
438 #define ATTACH_RETURN(retval) return
440 /* I2O HDM interface */
441 STATIC PROBE_RET asr_probe __P((PROBE_ARGS));
442 STATIC ATTACH_RET asr_attach __P((ATTACH_ARGS));
443 /* DOMINO placeholder */
444 STATIC PROBE_RET domino_probe __P((PROBE_ARGS));
445 STATIC ATTACH_RET domino_attach __P((ATTACH_ARGS));
446 /* MODE0 adapter placeholder */
447 STATIC PROBE_RET mode0_probe __P((PROBE_ARGS));
448 STATIC ATTACH_RET mode0_attach __P((ATTACH_ARGS));
450 STATIC Asr_softc_t * ASR_get_sc __P((
452 STATIC int asr_ioctl __P((
457 struct proc * proc));
458 STATIC int asr_open __P((
462 IN struct proc * proc));
463 STATIC int asr_close __P((
467 struct proc * proc));
468 STATIC int asr_intr __P((
469 IN Asr_softc_t * sc));
470 STATIC void asr_timeout __P((
472 STATIC int ASR_init __P((
473 IN Asr_softc_t * sc));
474 STATIC INLINE int ASR_acquireLct __P((
475 INOUT Asr_softc_t * sc));
476 STATIC INLINE int ASR_acquireHrt __P((
477 INOUT Asr_softc_t * sc));
478 STATIC void asr_action __P((
479 IN struct cam_sim * sim,
480 IN union ccb * ccb));
481 STATIC void asr_poll __P((
482 IN struct cam_sim * sim));
485 * Here is the auto-probe structure used to nest our tests appropriately
486 * during the startup phase of the operating system.
488 #if __FreeBSD_version >= 400000
489 STATIC device_method_t asr_methods[] = {
490 DEVMETHOD(device_probe, asr_probe),
491 DEVMETHOD(device_attach, asr_attach),
495 STATIC driver_t asr_driver = {
501 STATIC devclass_t asr_devclass;
503 DRIVER_MODULE(asr, pci, asr_driver, asr_devclass, 0, 0);
505 STATIC device_method_t domino_methods[] = {
506 DEVMETHOD(device_probe, domino_probe),
507 DEVMETHOD(device_attach, domino_attach),
511 STATIC driver_t domino_driver = {
517 STATIC devclass_t domino_devclass;
519 DRIVER_MODULE(domino, pci, domino_driver, domino_devclass, 0, 0);
521 STATIC device_method_t mode0_methods[] = {
522 DEVMETHOD(device_probe, mode0_probe),
523 DEVMETHOD(device_attach, mode0_attach),
527 STATIC driver_t mode0_driver = {
533 STATIC devclass_t mode0_devclass;
535 DRIVER_MODULE(mode0, pci, mode0_driver, mode0_devclass, 0, 0);
537 STATIC u_long asr_pcicount = 0;
538 STATIC struct pci_device asr_pcidev = {
545 DATA_SET (asr_pciset, asr_pcidev);
547 STATIC u_long domino_pcicount = 0;
548 STATIC struct pci_device domino_pcidev = {
555 DATA_SET (domino_pciset, domino_pcidev);
557 STATIC u_long mode0_pcicount = 0;
558 STATIC struct pci_device mode0_pcidev = {
565 DATA_SET (mode0_pciset, mode0_pcidev);
569 * devsw for asr hba driver
571 * only ioctl is used. the sd driver provides all other access.
573 #define CDEV_MAJOR 154 /* prefered default character major */
574 STATIC struct cdevsw asr_cdevsw = {
576 asr_close, /* close */
579 asr_ioctl, /* ioctl */
582 nostrategy, /* strategy */
584 CDEV_MAJOR, /* maj */
591 #ifdef ASR_MEASURE_PERFORMANCE
592 STATIC u_int32_t asr_time_delta __P((IN struct timeval start,
593 IN struct timeval end));
597 * Initialize the dynamic cdevsw hooks.
603 static int asr_devsw_installed = 0;
605 if (asr_devsw_installed) {
608 asr_devsw_installed++;
610 * Find a free spot (the report during driver load used by
611 * osd layer in engine to generate the controlling nodes).
613 while ((asr_cdevsw.d_maj < NUMCDEVSW)
614 && (devsw(makedev(asr_cdevsw.d_maj,0)) != (struct cdevsw *)NULL)) {
617 if (asr_cdevsw.d_maj >= NUMCDEVSW) for (
618 asr_cdevsw.d_maj = 0;
619 (asr_cdevsw.d_maj < CDEV_MAJOR)
620 && (devsw(makedev(asr_cdevsw.d_maj,0)) != (struct cdevsw *)NULL);
625 cdevsw_add(&asr_cdevsw);
627 * delete any nodes that would attach to the primary adapter,
628 * let the adapter scans add them.
630 destroy_dev(makedev(asr_cdevsw.d_maj,0));
633 /* Must initialize before CAM layer picks up our HBA driver */
634 SYSINIT(asrdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,asr_drvinit,NULL)
636 /* I2O support routines */
637 #define defAlignLong(STRUCT,NAME) char NAME[sizeof(STRUCT)]
638 #define getAlignLong(STRUCT,NAME) ((STRUCT *)(NAME))
641 * Fill message with default.
643 STATIC PI2O_MESSAGE_FRAME
648 OUT PI2O_MESSAGE_FRAME Message_Ptr;
650 Message_Ptr = getAlignLong(I2O_MESSAGE_FRAME, Message);
651 bzero ((void *)Message_Ptr, size);
652 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11);
653 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
654 (size + sizeof(U32) - 1) >> 2);
655 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
656 return (Message_Ptr);
657 } /* ASR_fillMessage */
659 #define EMPTY_QUEUE ((U32)-1L)
665 OUT U32 MessageOffset;
667 if ((MessageOffset = virt->ToFIFO) == EMPTY_QUEUE) {
668 MessageOffset = virt->ToFIFO;
670 return (MessageOffset);
671 } /* ASR_getMessage */
673 /* Issue a polled command */
676 INOUT i2oRegs_t * virt,
678 IN PI2O_MESSAGE_FRAME Message)
685 * ASR_initiateCp is only used for synchronous commands and will
686 * be made more resiliant to adapter delays since commands like
687 * resetIOP can cause the adapter to be deaf for a little time.
689 while (((MessageOffset = ASR_getMessage(virt)) == EMPTY_QUEUE)
693 if (MessageOffset != EMPTY_QUEUE) {
694 bcopy (Message, fvirt + MessageOffset,
695 I2O_MESSAGE_FRAME_getMessageSize(Message) << 2);
697 * Disable the Interrupts
699 virt->Mask = (Mask = virt->Mask) | Mask_InterruptsDisabled;
700 virt->ToFIFO = MessageOffset;
703 } /* ASR_initiateCp */
710 INOUT i2oRegs_t * virt,
713 struct resetMessage {
714 I2O_EXEC_IOP_RESET_MESSAGE M;
717 defAlignLong(struct resetMessage,Message);
718 PI2O_EXEC_IOP_RESET_MESSAGE Message_Ptr;
719 OUT U32 * volatile Reply_Ptr;
723 * Build up our copy of the Message.
725 Message_Ptr = (PI2O_EXEC_IOP_RESET_MESSAGE)ASR_fillMessage(Message,
726 sizeof(I2O_EXEC_IOP_RESET_MESSAGE));
727 I2O_EXEC_IOP_RESET_MESSAGE_setFunction(Message_Ptr, I2O_EXEC_IOP_RESET);
729 * Reset the Reply Status
731 *(Reply_Ptr = (U32 *)((char *)Message_Ptr
732 + sizeof(I2O_EXEC_IOP_RESET_MESSAGE))) = 0;
733 I2O_EXEC_IOP_RESET_MESSAGE_setStatusWordLowAddress(Message_Ptr,
734 KVTOPHYS((void *)Reply_Ptr));
736 * Send the Message out
738 if ((Old = ASR_initiateCp (virt, fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
740 * Wait for a response (Poll), timeouts are dangerous if
741 * the card is truly responsive. We assume response in 2s.
743 u_int8_t Delay = 200;
745 while ((*Reply_Ptr == 0) && (--Delay != 0)) {
749 * Re-enable the interrupts.
755 ASSERT (Old != (U32)-1L);
760 * Get the curent state of the adapter
762 STATIC INLINE PI2O_EXEC_STATUS_GET_REPLY
764 INOUT i2oRegs_t * virt,
766 OUT PI2O_EXEC_STATUS_GET_REPLY buffer)
768 defAlignLong(I2O_EXEC_STATUS_GET_MESSAGE,Message);
769 PI2O_EXEC_STATUS_GET_MESSAGE Message_Ptr;
773 * Build up our copy of the Message.
775 Message_Ptr = (PI2O_EXEC_STATUS_GET_MESSAGE)ASR_fillMessage(Message,
776 sizeof(I2O_EXEC_STATUS_GET_MESSAGE));
777 I2O_EXEC_STATUS_GET_MESSAGE_setFunction(Message_Ptr,
778 I2O_EXEC_STATUS_GET);
779 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferAddressLow(Message_Ptr,
780 KVTOPHYS((void *)buffer));
781 /* This one is a Byte Count */
782 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferLength(Message_Ptr,
783 sizeof(I2O_EXEC_STATUS_GET_REPLY));
785 * Reset the Reply Status
787 bzero ((void *)buffer, sizeof(I2O_EXEC_STATUS_GET_REPLY));
789 * Send the Message out
791 if ((Old = ASR_initiateCp (virt, fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
793 * Wait for a response (Poll), timeouts are dangerous if
794 * the card is truly responsive. We assume response in 50ms.
796 u_int8_t Delay = 255;
798 while (*((U8 * volatile)&(buffer->SyncByte)) == 0) {
800 buffer = (PI2O_EXEC_STATUS_GET_REPLY)NULL;
806 * Re-enable the interrupts.
811 return ((PI2O_EXEC_STATUS_GET_REPLY)NULL);
812 } /* ASR_getStatus */
815 * Check if the device is a SCSI I2O HBA, and add it to the list.
819 * Probe for ASR controller. If we find it, we will use it.
823 asr_probe(PROBE_ARGS)
826 if ((id == 0xA5011044) || (id == 0xA5111044)) {
827 PROBE_RETURN ("Adaptec Caching SCSI RAID");
833 * Probe/Attach for DOMINO chipset.
836 domino_probe(PROBE_ARGS)
839 if (id == 0x10121044) {
840 PROBE_RETURN ("Adaptec Caching Memory Controller");
846 domino_attach (ATTACH_ARGS)
849 } /* domino_attach */
852 * Probe/Attach for MODE0 adapters.
855 mode0_probe(PROBE_ARGS)
860 * If/When we can get a business case to commit to a
861 * Mode0 driver here, we can make all these tests more
862 * specific and robust. Mode0 adapters have their processors
863 * turned off, this the chips are in a raw state.
866 /* This is a PLX9054 */
867 if (id == 0x905410B5) {
868 PROBE_RETURN ("Adaptec Mode0 PM3757");
870 /* This is a PLX9080 */
871 if (id == 0x908010B5) {
872 PROBE_RETURN ("Adaptec Mode0 PM3754/PM3755");
874 /* This is a ZION 80303 */
875 if (id == 0x53098086) {
876 PROBE_RETURN ("Adaptec Mode0 3010S");
878 /* This is an i960RS */
879 if (id == 0x39628086) {
880 PROBE_RETURN ("Adaptec Mode0 2100S");
882 /* This is an i960RN */
883 if (id == 0x19648086) {
884 PROBE_RETURN ("Adaptec Mode0 PM2865/2400A/3200S/3400S");
886 #if 0 /* this would match any generic i960 -- mjs */
887 /* This is an i960RP (typically also on Motherboards) */
888 if (id == 0x19608086) {
889 PROBE_RETURN ("Adaptec Mode0 PM2554/PM1554/PM2654");
896 mode0_attach (ATTACH_ARGS)
901 STATIC INLINE union asr_ccb *
905 OUT union asr_ccb * new_ccb;
907 if ((new_ccb = (union asr_ccb *)malloc(sizeof(*new_ccb),
908 M_DEVBUF, M_WAITOK)) != (union asr_ccb *)NULL) {
909 bzero (new_ccb, sizeof(*new_ccb));
910 new_ccb->ccb_h.pinfo.priority = 1;
911 new_ccb->ccb_h.pinfo.index = CAM_UNQUEUED_INDEX;
912 new_ccb->ccb_h.spriv_ptr0 = sc;
915 } /* asr_alloc_ccb */
919 IN union asr_ccb * free_ccb)
921 free(free_ccb, M_DEVBUF);
925 * Print inquiry data `carefully'
932 while ((--len >= 0) && (*s) && (*s != ' ') && (*s != '-')) {
933 printf ("%c", *(s++));
940 STATIC INLINE int ASR_queue __P((
942 IN PI2O_MESSAGE_FRAME Message));
944 * Send a message synchronously and without Interrupt to a ccb.
948 INOUT union asr_ccb * ccb,
949 IN PI2O_MESSAGE_FRAME Message)
953 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
956 * We do not need any (optional byteswapping) method access to
957 * the Initiator context field.
959 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
961 /* Prevent interrupt service */
963 sc->ha_Virt->Mask = (Mask = sc->ha_Virt->Mask)
964 | Mask_InterruptsDisabled;
966 if (ASR_queue (sc, Message) == EMPTY_QUEUE) {
967 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
968 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
972 * Wait for this board to report a finished instruction.
974 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
978 /* Re-enable Interrupts */
979 sc->ha_Virt->Mask = Mask;
982 return (ccb->ccb_h.status);
986 * Send a message synchronously to a Asr_softc_t
991 IN PI2O_MESSAGE_FRAME Message)
996 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
997 return (CAM_REQUEUE_REQ);
1000 status = ASR_queue_s (ccb, Message);
1008 * Add the specified ccb to the active queue
1012 IN Asr_softc_t * sc,
1013 INOUT union asr_ccb * ccb)
1018 LIST_INSERT_HEAD(&(sc->ha_ccb), &(ccb->ccb_h), sim_links.le);
1019 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
1020 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT) {
1022 * RAID systems can take considerable time to
1023 * complete some commands given the large cache
1024 * flashes switching from write back to write thru.
1026 ccb->ccb_h.timeout = 6 * 60 * 1000;
1028 ccb->ccb_h.timeout_ch = timeout(asr_timeout, (caddr_t)ccb,
1029 (ccb->ccb_h.timeout * hz) / 1000);
1035 * Remove the specified ccb from the active queue.
1039 IN Asr_softc_t * sc,
1040 INOUT union asr_ccb * ccb)
1045 untimeout(asr_timeout, (caddr_t)ccb, ccb->ccb_h.timeout_ch);
1046 LIST_REMOVE(&(ccb->ccb_h), sim_links.le);
1048 } /* ASR_ccbRemove */
1051 * Fail all the active commands, so they get re-issued by the operating
1055 ASR_failActiveCommands (
1056 IN Asr_softc_t * sc)
1058 struct ccb_hdr * ccb;
1061 #if 0 /* Currently handled by callers, unnecessary paranoia currently */
1062 /* Left in for historical perspective. */
1063 defAlignLong(I2O_EXEC_LCT_NOTIFY_MESSAGE,Message);
1064 PI2O_EXEC_LCT_NOTIFY_MESSAGE Message_Ptr;
1066 /* Send a blind LCT command to wait for the enableSys to complete */
1067 Message_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)ASR_fillMessage(Message,
1068 sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) - sizeof(I2O_SG_ELEMENT));
1069 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1070 I2O_EXEC_LCT_NOTIFY);
1071 I2O_EXEC_LCT_NOTIFY_MESSAGE_setClassIdentifier(Message_Ptr,
1072 I2O_CLASS_MATCH_ANYCLASS);
1073 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1078 * We do not need to inform the CAM layer that we had a bus
1079 * reset since we manage it on our own, this also prevents the
1080 * SCSI_DELAY settling that would be required on other systems.
1081 * The `SCSI_DELAY' has already been handled by the card via the
1082 * acquisition of the LCT table while we are at CAM priority level.
1083 * for (int bus = 0; bus <= sc->ha_MaxBus; ++bus) {
1084 * xpt_async (AC_BUS_RESET, sc->ha_path[bus], NULL);
1087 while ((ccb = LIST_FIRST(&(sc->ha_ccb))) != (struct ccb_hdr *)NULL) {
1088 ASR_ccbRemove (sc, (union asr_ccb *)ccb);
1090 ccb->status &= ~CAM_STATUS_MASK;
1091 ccb->status |= CAM_REQUEUE_REQ;
1092 /* Nothing Transfered */
1093 ((struct ccb_scsiio *)ccb)->resid
1094 = ((struct ccb_scsiio *)ccb)->dxfer_len;
1097 xpt_done ((union ccb *)ccb);
1099 wakeup ((caddr_t)ccb);
1103 } /* ASR_failActiveCommands */
1106 * The following command causes the HBA to reset the specific bus
1110 IN Asr_softc_t * sc,
1113 defAlignLong(I2O_HBA_BUS_RESET_MESSAGE,Message);
1114 I2O_HBA_BUS_RESET_MESSAGE * Message_Ptr;
1115 PI2O_LCT_ENTRY Device;
1117 Message_Ptr = (I2O_HBA_BUS_RESET_MESSAGE *)ASR_fillMessage(Message,
1118 sizeof(I2O_HBA_BUS_RESET_MESSAGE));
1119 I2O_MESSAGE_FRAME_setFunction(&Message_Ptr->StdMessageFrame,
1121 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
1122 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
1124 if (((Device->le_type & I2O_PORT) != 0)
1125 && (Device->le_bus == bus)) {
1126 I2O_MESSAGE_FRAME_setTargetAddress(
1127 &Message_Ptr->StdMessageFrame,
1128 I2O_LCT_ENTRY_getLocalTID(Device));
1129 /* Asynchronous command, with no expectations */
1130 (void)ASR_queue(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1134 } /* ASR_resetBus */
1137 ASR_getBlinkLedCode (
1138 IN Asr_softc_t * sc)
1140 if ((sc != (Asr_softc_t *)NULL)
1141 && (sc->ha_blinkLED != (u_int8_t *)NULL)
1142 && (sc->ha_blinkLED[1] == 0xBC)) {
1143 return (sc->ha_blinkLED[0]);
1146 } /* ASR_getBlinkCode */
1149 * Determine the address of an TID lookup. Must be done at high priority
1150 * since the address can be changed by other threads of execution.
1152 * Returns NULL pointer if not indexible (but will attempt to generate
1153 * an index if `new_entry' flag is set to TRUE).
1155 * All addressible entries are to be guaranteed zero if never initialized.
1157 STATIC INLINE tid_t *
1159 INOUT Asr_softc_t * sc,
1165 target2lun_t * bus_ptr;
1166 lun2tid_t * target_ptr;
1170 * Validity checking of incoming parameters. More of a bound
1171 * expansion limit than an issue with the code dealing with the
1174 * sc must be valid before it gets here, so that check could be
1175 * dropped if speed a critical issue.
1177 if ((sc == (Asr_softc_t *)NULL)
1178 || (bus > MAX_CHANNEL)
1179 || (target > sc->ha_MaxId)
1180 || (lun > sc->ha_MaxLun)) {
1181 debug_asr_printf("(%lx,%d,%d,%d) target out of range\n",
1182 (u_long)sc, bus, target, lun);
1183 return ((tid_t *)NULL);
1186 * See if there is an associated bus list.
1188 * for performance, allocate in size of BUS_CHUNK chunks.
1189 * BUS_CHUNK must be a power of two. This is to reduce
1190 * fragmentation effects on the allocations.
1192 # define BUS_CHUNK 8
1193 new_size = ((target + BUS_CHUNK - 1) & ~(BUS_CHUNK - 1));
1194 if ((bus_ptr = sc->ha_targets[bus]) == (target2lun_t *)NULL) {
1196 * Allocate a new structure?
1197 * Since one element in structure, the +1
1198 * needed for size has been abstracted.
1200 if ((new_entry == FALSE)
1201 || ((sc->ha_targets[bus] = bus_ptr = (target2lun_t *)malloc (
1202 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
1204 == (target2lun_t *)NULL)) {
1205 debug_asr_printf("failed to allocate bus list\n");
1206 return ((tid_t *)NULL);
1208 bzero (bus_ptr, sizeof(*bus_ptr)
1209 + (sizeof(bus_ptr->LUN) * new_size));
1210 bus_ptr->size = new_size + 1;
1211 } else if (bus_ptr->size <= new_size) {
1212 target2lun_t * new_bus_ptr;
1215 * Reallocate a new structure?
1216 * Since one element in structure, the +1
1217 * needed for size has been abstracted.
1219 if ((new_entry == FALSE)
1220 || ((new_bus_ptr = (target2lun_t *)malloc (
1221 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
1223 == (target2lun_t *)NULL)) {
1224 debug_asr_printf("failed to reallocate bus list\n");
1225 return ((tid_t *)NULL);
1228 * Zero and copy the whole thing, safer, simpler coding
1229 * and not really performance critical at this point.
1231 bzero (new_bus_ptr, sizeof(*bus_ptr)
1232 + (sizeof(bus_ptr->LUN) * new_size));
1233 bcopy (bus_ptr, new_bus_ptr, sizeof(*bus_ptr)
1234 + (sizeof(bus_ptr->LUN) * (bus_ptr->size - 1)));
1235 sc->ha_targets[bus] = new_bus_ptr;
1236 free (bus_ptr, M_TEMP);
1237 bus_ptr = new_bus_ptr;
1238 bus_ptr->size = new_size + 1;
1241 * We now have the bus list, lets get to the target list.
1242 * Since most systems have only *one* lun, we do not allocate
1243 * in chunks as above, here we allow one, then in chunk sizes.
1244 * TARGET_CHUNK must be a power of two. This is to reduce
1245 * fragmentation effects on the allocations.
1247 # define TARGET_CHUNK 8
1248 if ((new_size = lun) != 0) {
1249 new_size = ((lun + TARGET_CHUNK - 1) & ~(TARGET_CHUNK - 1));
1251 if ((target_ptr = bus_ptr->LUN[target]) == (lun2tid_t *)NULL) {
1253 * Allocate a new structure?
1254 * Since one element in structure, the +1
1255 * needed for size has been abstracted.
1257 if ((new_entry == FALSE)
1258 || ((bus_ptr->LUN[target] = target_ptr = (lun2tid_t *)malloc (
1259 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
1261 == (lun2tid_t *)NULL)) {
1262 debug_asr_printf("failed to allocate target list\n");
1263 return ((tid_t *)NULL);
1265 bzero (target_ptr, sizeof(*target_ptr)
1266 + (sizeof(target_ptr->TID) * new_size));
1267 target_ptr->size = new_size + 1;
1268 } else if (target_ptr->size <= new_size) {
1269 lun2tid_t * new_target_ptr;
1272 * Reallocate a new structure?
1273 * Since one element in structure, the +1
1274 * needed for size has been abstracted.
1276 if ((new_entry == FALSE)
1277 || ((new_target_ptr = (lun2tid_t *)malloc (
1278 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
1280 == (lun2tid_t *)NULL)) {
1281 debug_asr_printf("failed to reallocate target list\n");
1282 return ((tid_t *)NULL);
1285 * Zero and copy the whole thing, safer, simpler coding
1286 * and not really performance critical at this point.
1288 bzero (new_target_ptr, sizeof(*target_ptr)
1289 + (sizeof(target_ptr->TID) * new_size));
1290 bcopy (target_ptr, new_target_ptr,
1292 + (sizeof(target_ptr->TID) * (target_ptr->size - 1)));
1293 bus_ptr->LUN[target] = new_target_ptr;
1294 free (target_ptr, M_TEMP);
1295 target_ptr = new_target_ptr;
1296 target_ptr->size = new_size + 1;
1299 * Now, acquire the TID address from the LUN indexed list.
1301 return (&(target_ptr->TID[lun]));
1302 } /* ASR_getTidAddress */
1305 * Get a pre-existing TID relationship.
1307 * If the TID was never set, return (tid_t)-1.
1309 * should use mutex rather than spl.
1313 IN Asr_softc_t * sc,
1323 if (((tid_ptr = ASR_getTidAddress (sc, bus, target, lun, FALSE))
1325 /* (tid_t)0 or (tid_t)-1 indicate no TID */
1326 || (*tid_ptr == (tid_t)0)) {
1336 * Set a TID relationship.
1338 * If the TID was not set, return (tid_t)-1.
1340 * should use mutex rather than spl.
1344 INOUT Asr_softc_t * sc,
1353 if (TID != (tid_t)-1) {
1358 if ((tid_ptr = ASR_getTidAddress (sc, bus, target, lun, TRUE))
1369 /*-------------------------------------------------------------------------*/
1370 /* Function ASR_rescan */
1371 /*-------------------------------------------------------------------------*/
1372 /* The Parameters Passed To This Function Are : */
1373 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1375 /* This Function Will rescan the adapter and resynchronize any data */
1377 /* Return : 0 For OK, Error Code Otherwise */
1378 /*-------------------------------------------------------------------------*/
1382 IN Asr_softc_t * sc)
1388 * Re-acquire the LCT table and synchronize us to the adapter.
1390 if ((error = ASR_acquireLct(sc)) == 0) {
1391 error = ASR_acquireHrt(sc);
1398 bus = sc->ha_MaxBus;
1399 /* Reset all existing cached TID lookups */
1401 int target, event = 0;
1404 * Scan for all targets on this bus to see if they
1405 * got affected by the rescan.
1407 for (target = 0; target <= sc->ha_MaxId; ++target) {
1410 /* Stay away from the controller ID */
1411 if (target == sc->ha_adapter_target[bus]) {
1414 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
1415 PI2O_LCT_ENTRY Device;
1416 tid_t TID = (tid_t)-1;
1420 * See if the cached TID changed. Search for
1421 * the device in our new LCT.
1423 for (Device = sc->ha_LCT->LCTEntry;
1424 Device < (PI2O_LCT_ENTRY)(((U32 *)sc->ha_LCT)
1425 + I2O_LCT_getTableSize(sc->ha_LCT));
1427 if ((Device->le_type != I2O_UNKNOWN)
1428 && (Device->le_bus == bus)
1429 && (Device->le_target == target)
1430 && (Device->le_lun == lun)
1431 && (I2O_LCT_ENTRY_getUserTID(Device)
1433 TID = I2O_LCT_ENTRY_getLocalTID(
1439 * Indicate to the OS that the label needs
1440 * to be recalculated, or that the specific
1441 * open device is no longer valid (Merde)
1442 * because the cached TID changed.
1444 LastTID = ASR_getTid (sc, bus, target, lun);
1445 if (LastTID != TID) {
1446 struct cam_path * path;
1448 if (xpt_create_path(&path,
1450 cam_sim_path(sc->ha_sim[bus]),
1451 target, lun) != CAM_REQ_CMP) {
1452 if (TID == (tid_t)-1) {
1453 event |= AC_LOST_DEVICE;
1455 event |= AC_INQ_CHANGED
1456 | AC_GETDEV_CHANGED;
1459 if (TID == (tid_t)-1) {
1463 } else if (LastTID == (tid_t)-1) {
1464 struct ccb_getdev ccb;
1468 path, /*priority*/5);
1484 * We have the option of clearing the
1485 * cached TID for it to be rescanned, or to
1486 * set it now even if the device never got
1487 * accessed. We chose the later since we
1488 * currently do not use the condition that
1489 * the TID ever got cached.
1491 ASR_setTid (sc, bus, target, lun, TID);
1495 * The xpt layer can not handle multiple events at the
1498 if (event & AC_LOST_DEVICE) {
1499 xpt_async(AC_LOST_DEVICE, sc->ha_path[bus], NULL);
1501 if (event & AC_INQ_CHANGED) {
1502 xpt_async(AC_INQ_CHANGED, sc->ha_path[bus], NULL);
1504 if (event & AC_GETDEV_CHANGED) {
1505 xpt_async(AC_GETDEV_CHANGED, sc->ha_path[bus], NULL);
1507 } while (--bus >= 0);
1511 /*-------------------------------------------------------------------------*/
1512 /* Function ASR_reset */
1513 /*-------------------------------------------------------------------------*/
1514 /* The Parameters Passed To This Function Are : */
1515 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1517 /* This Function Will reset the adapter and resynchronize any data */
1520 /*-------------------------------------------------------------------------*/
1524 IN Asr_softc_t * sc)
1529 if ((sc->ha_in_reset == HA_IN_RESET)
1530 || (sc->ha_in_reset == HA_OFF_LINE_RECOVERY)) {
1535 * Promotes HA_OPERATIONAL to HA_IN_RESET,
1536 * or HA_OFF_LINE to HA_OFF_LINE_RECOVERY.
1538 ++(sc->ha_in_reset);
1539 if (ASR_resetIOP (sc->ha_Virt, sc->ha_Fvirt) == 0) {
1540 debug_asr_printf ("ASR_resetIOP failed\n");
1542 * We really need to take this card off-line, easier said
1543 * than make sense. Better to keep retrying for now since if a
1544 * UART cable is connected the blinkLEDs the adapter is now in
1545 * a hard state requiring action from the monitor commands to
1546 * the HBA to continue. For debugging waiting forever is a
1547 * good thing. In a production system, however, one may wish
1548 * to instead take the card off-line ...
1550 # if 0 && (defined(HA_OFF_LINE))
1552 * Take adapter off-line.
1554 printf ("asr%d: Taking adapter off-line\n",
1556 ? cam_sim_unit(xpt_path_sim(sc->ha_path[0]))
1558 sc->ha_in_reset = HA_OFF_LINE;
1563 while (ASR_resetIOP (sc->ha_Virt, sc->ha_Fvirt) == 0);
1566 retVal = ASR_init (sc);
1569 debug_asr_printf ("ASR_init failed\n");
1570 sc->ha_in_reset = HA_OFF_LINE;
1573 if (ASR_rescan (sc) != 0) {
1574 debug_asr_printf ("ASR_rescan failed\n");
1576 ASR_failActiveCommands (sc);
1577 if (sc->ha_in_reset == HA_OFF_LINE_RECOVERY) {
1578 printf ("asr%d: Brining adapter back on-line\n",
1580 ? cam_sim_unit(xpt_path_sim(sc->ha_path[0]))
1583 sc->ha_in_reset = HA_OPERATIONAL;
1588 * Device timeout handler.
1594 union asr_ccb * ccb = (union asr_ccb *)arg;
1595 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
1598 debug_asr_print_path(ccb);
1599 debug_asr_printf("timed out");
1602 * Check if the adapter has locked up?
1604 if ((s = ASR_getBlinkLedCode(sc)) != 0) {
1606 printf ("asr%d: Blink LED 0x%x resetting adapter\n",
1607 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)), s);
1608 if (ASR_reset (sc) == ENXIO) {
1609 /* Try again later */
1610 ccb->ccb_h.timeout_ch = timeout(asr_timeout,
1612 (ccb->ccb_h.timeout * hz) / 1000);
1617 * Abort does not function on the ASR card!!! Walking away from
1618 * the SCSI command is also *very* dangerous. A SCSI BUS reset is
1619 * our best bet, followed by a complete adapter reset if that fails.
1622 /* Check if we already timed out once to raise the issue */
1623 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_CMD_TIMEOUT) {
1624 debug_asr_printf (" AGAIN\nreinitializing adapter\n");
1625 if (ASR_reset (sc) == ENXIO) {
1626 ccb->ccb_h.timeout_ch = timeout(asr_timeout,
1628 (ccb->ccb_h.timeout * hz) / 1000);
1633 debug_asr_printf ("\nresetting bus\n");
1634 /* If the BUS reset does not take, then an adapter reset is next! */
1635 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1636 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1637 ccb->ccb_h.timeout_ch = timeout(asr_timeout, (caddr_t)ccb,
1638 (ccb->ccb_h.timeout * hz) / 1000);
1639 ASR_resetBus (sc, cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)));
1640 xpt_async (AC_BUS_RESET, ccb->ccb_h.path, NULL);
1645 * send a message asynchronously
1649 IN Asr_softc_t * sc,
1650 IN PI2O_MESSAGE_FRAME Message)
1652 OUT U32 MessageOffset;
1653 union asr_ccb * ccb;
1655 debug_asr_printf ("Host Command Dump:\n");
1656 debug_asr_dump_message (Message);
1658 ccb = (union asr_ccb *)(long)
1659 I2O_MESSAGE_FRAME_getInitiatorContext64(Message);
1661 if ((MessageOffset = ASR_getMessage(sc->ha_Virt)) != EMPTY_QUEUE) {
1662 #ifdef ASR_MEASURE_PERFORMANCE
1666 ++sc->ha_performance.command_count[
1667 (int) ccb->csio.cdb_io.cdb_bytes[0]];
1668 DEQ_TIMEQ_FREE_LIST(startTimeIndex,
1669 sc->ha_timeQFreeList,
1670 sc->ha_timeQFreeHead,
1671 sc->ha_timeQFreeTail);
1672 if (-1 != startTimeIndex) {
1673 microtime(&(sc->ha_timeQ[startTimeIndex]));
1675 /* Time stamp the command before we send it out */
1676 ((PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *) Message)->
1677 PrivateMessageFrame.TransactionContext
1678 = (I2O_TRANSACTION_CONTEXT) startTimeIndex;
1680 ++sc->ha_submitted_ccbs_count;
1681 if (sc->ha_performance.max_submit_count
1682 < sc->ha_submitted_ccbs_count) {
1683 sc->ha_performance.max_submit_count
1684 = sc->ha_submitted_ccbs_count;
1688 bcopy (Message, sc->ha_Fvirt + MessageOffset,
1689 I2O_MESSAGE_FRAME_getMessageSize(Message) << 2);
1691 ASR_ccbAdd (sc, ccb);
1693 /* Post the command */
1694 sc->ha_Virt->ToFIFO = MessageOffset;
1696 if (ASR_getBlinkLedCode(sc)) {
1698 * Unlikely we can do anything if we can't grab a
1699 * message frame :-(, but lets give it a try.
1701 (void)ASR_reset (sc);
1704 return (MessageOffset);
1708 /* Simple Scatter Gather elements */
1709 #define SG(SGL,Index,Flags,Buffer,Size) \
1710 I2O_FLAGS_COUNT_setCount( \
1711 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1713 I2O_FLAGS_COUNT_setFlags( \
1714 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1715 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | (Flags)); \
1716 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress( \
1717 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index]), \
1718 (Buffer == NULL) ? NULL : KVTOPHYS(Buffer))
1721 * Retrieve Parameter Group.
1722 * Buffer must be allocated using defAlignLong macro.
1726 IN Asr_softc_t * sc,
1730 IN unsigned BufferSize)
1732 struct paramGetMessage {
1733 I2O_UTIL_PARAMS_GET_MESSAGE M;
1735 sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT)];
1737 I2O_PARAM_OPERATIONS_LIST_HEADER Header;
1738 I2O_PARAM_OPERATION_ALL_TEMPLATE Template[1];
1741 defAlignLong(struct paramGetMessage, Message);
1742 struct Operations * Operations_Ptr;
1743 I2O_UTIL_PARAMS_GET_MESSAGE * Message_Ptr;
1744 struct ParamBuffer {
1745 I2O_PARAM_RESULTS_LIST_HEADER Header;
1746 I2O_PARAM_READ_OPERATION_RESULT Read;
1750 Message_Ptr = (I2O_UTIL_PARAMS_GET_MESSAGE *)ASR_fillMessage(Message,
1751 sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1752 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1753 Operations_Ptr = (struct Operations *)((char *)Message_Ptr
1754 + sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1755 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1756 bzero ((void *)Operations_Ptr, sizeof(struct Operations));
1757 I2O_PARAM_OPERATIONS_LIST_HEADER_setOperationCount(
1758 &(Operations_Ptr->Header), 1);
1759 I2O_PARAM_OPERATION_ALL_TEMPLATE_setOperation(
1760 &(Operations_Ptr->Template[0]), I2O_PARAMS_OPERATION_FIELD_GET);
1761 I2O_PARAM_OPERATION_ALL_TEMPLATE_setFieldCount(
1762 &(Operations_Ptr->Template[0]), 0xFFFF);
1763 I2O_PARAM_OPERATION_ALL_TEMPLATE_setGroupNumber(
1764 &(Operations_Ptr->Template[0]), Group);
1765 bzero ((void *)(Buffer_Ptr = getAlignLong(struct ParamBuffer, Buffer)),
1768 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1770 + (((sizeof(I2O_UTIL_PARAMS_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1771 / sizeof(U32)) << 4));
1772 I2O_MESSAGE_FRAME_setTargetAddress (&(Message_Ptr->StdMessageFrame),
1774 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
1775 I2O_UTIL_PARAMS_GET);
1777 * Set up the buffers as scatter gather elements.
1779 SG(&(Message_Ptr->SGL), 0,
1780 I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER,
1781 Operations_Ptr, sizeof(struct Operations));
1782 SG(&(Message_Ptr->SGL), 1,
1783 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
1784 Buffer_Ptr, BufferSize);
1786 if ((ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) == CAM_REQ_CMP)
1787 && (Buffer_Ptr->Header.ResultCount)) {
1788 return ((void *)(Buffer_Ptr->Info));
1790 return ((void *)NULL);
1791 } /* ASR_getParams */
1794 * Acquire the LCT information.
1798 INOUT Asr_softc_t * sc)
1800 PI2O_EXEC_LCT_NOTIFY_MESSAGE Message_Ptr;
1801 PI2O_SGE_SIMPLE_ELEMENT sg;
1802 int MessageSizeInBytes;
1806 PI2O_LCT_ENTRY Entry;
1809 * sc value assumed valid
1811 MessageSizeInBytes = sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE)
1812 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT);
1813 if ((Message_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)malloc (
1814 MessageSizeInBytes, M_TEMP, M_WAITOK))
1815 == (PI2O_EXEC_LCT_NOTIFY_MESSAGE)NULL) {
1818 (void)ASR_fillMessage((char *)Message_Ptr, MessageSizeInBytes);
1819 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1821 (((sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1822 / sizeof(U32)) << 4)));
1823 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1824 I2O_EXEC_LCT_NOTIFY);
1825 I2O_EXEC_LCT_NOTIFY_MESSAGE_setClassIdentifier(Message_Ptr,
1826 I2O_CLASS_MATCH_ANYCLASS);
1828 * Call the LCT table to determine the number of device entries
1829 * to reserve space for.
1831 SG(&(Message_Ptr->SGL), 0,
1832 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER, &Table,
1835 * since this code is reused in several systems, code efficiency
1836 * is greater by using a shift operation rather than a divide by
1837 * sizeof(u_int32_t).
1839 I2O_LCT_setTableSize(&Table,
1840 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1841 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1843 * Determine the size of the LCT table.
1846 free (sc->ha_LCT, M_TEMP);
1849 * malloc only generates contiguous memory when less than a
1850 * page is expected. We must break the request up into an SG list ...
1852 if (((len = (I2O_LCT_getTableSize(&Table) << 2)) <=
1853 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)))
1854 || (len > (128 * 1024))) { /* Arbitrary */
1855 free (Message_Ptr, M_TEMP);
1858 if ((sc->ha_LCT = (PI2O_LCT)malloc (len, M_TEMP, M_WAITOK))
1859 == (PI2O_LCT)NULL) {
1860 free (Message_Ptr, M_TEMP);
1864 * since this code is reused in several systems, code efficiency
1865 * is greater by using a shift operation rather than a divide by
1866 * sizeof(u_int32_t).
1868 I2O_LCT_setTableSize(sc->ha_LCT,
1869 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1871 * Convert the access to the LCT table into a SG list.
1873 sg = Message_Ptr->SGL.u.Simple;
1874 v = (caddr_t)(sc->ha_LCT);
1876 int next, base, span;
1879 next = base = KVTOPHYS(v);
1880 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
1882 /* How far can we go contiguously */
1883 while ((len > 0) && (base == next)) {
1886 next = trunc_page(base) + PAGE_SIZE;
1897 /* Construct the Flags */
1898 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
1900 int rw = I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT;
1902 rw = (I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT
1903 | I2O_SGL_FLAGS_LAST_ELEMENT
1904 | I2O_SGL_FLAGS_END_OF_BUFFER);
1906 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount), rw);
1914 * Incrementing requires resizing of the packet.
1917 MessageSizeInBytes += sizeof(*sg);
1918 I2O_MESSAGE_FRAME_setMessageSize(
1919 &(Message_Ptr->StdMessageFrame),
1920 I2O_MESSAGE_FRAME_getMessageSize(
1921 &(Message_Ptr->StdMessageFrame))
1922 + (sizeof(*sg) / sizeof(U32)));
1924 PI2O_EXEC_LCT_NOTIFY_MESSAGE NewMessage_Ptr;
1926 if ((NewMessage_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)
1927 malloc (MessageSizeInBytes, M_TEMP, M_WAITOK))
1928 == (PI2O_EXEC_LCT_NOTIFY_MESSAGE)NULL) {
1929 free (sc->ha_LCT, M_TEMP);
1930 sc->ha_LCT = (PI2O_LCT)NULL;
1931 free (Message_Ptr, M_TEMP);
1934 span = ((caddr_t)sg) - (caddr_t)Message_Ptr;
1935 bcopy ((caddr_t)Message_Ptr,
1936 (caddr_t)NewMessage_Ptr, span);
1937 free (Message_Ptr, M_TEMP);
1938 sg = (PI2O_SGE_SIMPLE_ELEMENT)
1939 (((caddr_t)NewMessage_Ptr) + span);
1940 Message_Ptr = NewMessage_Ptr;
1945 retval = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1946 free (Message_Ptr, M_TEMP);
1947 if (retval != CAM_REQ_CMP) {
1951 /* If the LCT table grew, lets truncate accesses */
1952 if (I2O_LCT_getTableSize(&Table) < I2O_LCT_getTableSize(sc->ha_LCT)) {
1953 I2O_LCT_setTableSize(sc->ha_LCT, I2O_LCT_getTableSize(&Table));
1955 for (Entry = sc->ha_LCT->LCTEntry; Entry < (PI2O_LCT_ENTRY)
1956 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
1958 Entry->le_type = I2O_UNKNOWN;
1959 switch (I2O_CLASS_ID_getClass(&(Entry->ClassID))) {
1961 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
1962 Entry->le_type = I2O_BSA;
1965 case I2O_CLASS_SCSI_PERIPHERAL:
1966 Entry->le_type = I2O_SCSI;
1969 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
1970 Entry->le_type = I2O_FCA;
1973 case I2O_CLASS_BUS_ADAPTER_PORT:
1974 Entry->le_type = I2O_PORT | I2O_SCSI;
1976 case I2O_CLASS_FIBRE_CHANNEL_PORT:
1977 if (I2O_CLASS_ID_getClass(&(Entry->ClassID)) ==
1978 I2O_CLASS_FIBRE_CHANNEL_PORT) {
1979 Entry->le_type = I2O_PORT | I2O_FCA;
1981 { struct ControllerInfo {
1982 I2O_PARAM_RESULTS_LIST_HEADER Header;
1983 I2O_PARAM_READ_OPERATION_RESULT Read;
1984 I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1986 defAlignLong(struct ControllerInfo, Buffer);
1987 PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1989 Entry->le_bus = 0xff;
1990 Entry->le_target = 0xff;
1991 Entry->le_lun = 0xff;
1993 if ((Info = (PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR)
1995 I2O_LCT_ENTRY_getLocalTID(Entry),
1996 I2O_HBA_SCSI_CONTROLLER_INFO_GROUP_NO,
1997 Buffer, sizeof(struct ControllerInfo)))
1998 == (PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR)NULL) {
2002 = I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR_getInitiatorID(
2009 { struct DeviceInfo {
2010 I2O_PARAM_RESULTS_LIST_HEADER Header;
2011 I2O_PARAM_READ_OPERATION_RESULT Read;
2012 I2O_DPT_DEVICE_INFO_SCALAR Info;
2014 defAlignLong (struct DeviceInfo, Buffer);
2015 PI2O_DPT_DEVICE_INFO_SCALAR Info;
2017 Entry->le_bus = 0xff;
2018 Entry->le_target = 0xff;
2019 Entry->le_lun = 0xff;
2021 if ((Info = (PI2O_DPT_DEVICE_INFO_SCALAR)
2023 I2O_LCT_ENTRY_getLocalTID(Entry),
2024 I2O_DPT_DEVICE_INFO_GROUP_NO,
2025 Buffer, sizeof(struct DeviceInfo)))
2026 == (PI2O_DPT_DEVICE_INFO_SCALAR)NULL) {
2030 |= I2O_DPT_DEVICE_INFO_SCALAR_getDeviceType(Info);
2032 = I2O_DPT_DEVICE_INFO_SCALAR_getBus(Info);
2033 if ((Entry->le_bus > sc->ha_MaxBus)
2034 && (Entry->le_bus <= MAX_CHANNEL)) {
2035 sc->ha_MaxBus = Entry->le_bus;
2038 = I2O_DPT_DEVICE_INFO_SCALAR_getIdentifier(Info);
2040 = I2O_DPT_DEVICE_INFO_SCALAR_getLunInfo(Info);
2044 * A zero return value indicates success.
2047 } /* ASR_acquireLct */
2050 * Initialize a message frame.
2051 * We assume that the CDB has already been set up, so all we do here is
2052 * generate the Scatter Gather list.
2054 STATIC INLINE PI2O_MESSAGE_FRAME
2056 IN union asr_ccb * ccb,
2057 OUT PI2O_MESSAGE_FRAME Message)
2059 int next, span, base, rw;
2060 OUT PI2O_MESSAGE_FRAME Message_Ptr;
2061 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
2062 PI2O_SGE_SIMPLE_ELEMENT sg;
2064 vm_size_t size, len;
2067 /* We only need to zero out the PRIVATE_SCSI_SCB_EXECUTE_MESSAGE */
2068 bzero (Message_Ptr = getAlignLong(I2O_MESSAGE_FRAME, Message),
2069 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT)));
2072 int target = ccb->ccb_h.target_id;
2073 int lun = ccb->ccb_h.target_lun;
2074 int bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
2077 if ((TID = ASR_getTid (sc, bus, target, lun)) == (tid_t)-1) {
2078 PI2O_LCT_ENTRY Device;
2081 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2082 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
2084 if ((Device->le_type != I2O_UNKNOWN)
2085 && (Device->le_bus == bus)
2086 && (Device->le_target == target)
2087 && (Device->le_lun == lun)
2088 && (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF)) {
2089 TID = I2O_LCT_ENTRY_getLocalTID(Device);
2090 ASR_setTid (sc, Device->le_bus,
2091 Device->le_target, Device->le_lun,
2097 if (TID == (tid_t)0) {
2098 return ((PI2O_MESSAGE_FRAME)NULL);
2100 I2O_MESSAGE_FRAME_setTargetAddress(Message_Ptr, TID);
2101 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(
2102 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, TID);
2104 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11 |
2105 (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2106 / sizeof(U32)) << 4));
2107 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
2108 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2109 - sizeof(I2O_SG_ELEMENT)) / sizeof(U32));
2110 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
2111 I2O_MESSAGE_FRAME_setFunction(Message_Ptr, I2O_PRIVATE_MESSAGE);
2112 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
2113 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, I2O_SCSI_SCB_EXEC);
2114 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
2115 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
2116 I2O_SCB_FLAG_ENABLE_DISCONNECT
2117 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2118 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2120 * We do not need any (optional byteswapping) method access to
2121 * the Initiator & Transaction context field.
2123 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
2125 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2126 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, DPT_ORGANIZATION_ID);
2130 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(
2131 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, ccb->csio.cdb_len);
2132 bcopy (&(ccb->csio.cdb_io),
2133 ((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->CDB, ccb->csio.cdb_len);
2136 * Given a buffer describing a transfer, set up a scatter/gather map
2137 * in a ccb to map that SCSI transfer.
2140 rw = (ccb->ccb_h.flags & CAM_DIR_IN) ? 0 : I2O_SGL_FLAGS_DIR;
2142 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
2143 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
2144 (ccb->csio.dxfer_len)
2145 ? ((rw) ? (I2O_SCB_FLAG_XFER_TO_DEVICE
2146 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2147 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2148 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER)
2149 : (I2O_SCB_FLAG_XFER_FROM_DEVICE
2150 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2151 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2152 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER))
2153 : (I2O_SCB_FLAG_ENABLE_DISCONNECT
2154 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2155 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2158 * Given a transfer described by a `data', fill in the SG list.
2160 sg = &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->SGL.u.Simple[0];
2162 len = ccb->csio.dxfer_len;
2163 v = ccb->csio.data_ptr;
2164 ASSERT (ccb->csio.dxfer_len >= 0);
2165 MessageSize = I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr);
2166 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
2167 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, len);
2168 while ((len > 0) && (sg < &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2169 Message_Ptr)->SGL.u.Simple[SG_SIZE])) {
2171 next = base = KVTOPHYS(v);
2172 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
2174 /* How far can we go contiguously */
2175 while ((len > 0) && (base == next)) {
2176 next = trunc_page(base) + PAGE_SIZE;
2187 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
2189 rw |= I2O_SGL_FLAGS_LAST_ELEMENT;
2191 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount),
2192 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | rw);
2194 MessageSize += sizeof(*sg) / sizeof(U32);
2196 /* We always do the request sense ... */
2197 if ((span = ccb->csio.sense_len) == 0) {
2198 span = sizeof(ccb->csio.sense_data);
2200 SG(sg, 0, I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2201 &(ccb->csio.sense_data), span);
2202 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
2203 MessageSize + (sizeof(*sg) / sizeof(U32)));
2204 return (Message_Ptr);
2205 } /* ASR_init_message */
2208 * Reset the adapter.
2212 INOUT Asr_softc_t * sc)
2214 struct initOutBoundMessage {
2215 I2O_EXEC_OUTBOUND_INIT_MESSAGE M;
2218 defAlignLong(struct initOutBoundMessage,Message);
2219 PI2O_EXEC_OUTBOUND_INIT_MESSAGE Message_Ptr;
2220 OUT U32 * volatile Reply_Ptr;
2224 * Build up our copy of the Message.
2226 Message_Ptr = (PI2O_EXEC_OUTBOUND_INIT_MESSAGE)ASR_fillMessage(Message,
2227 sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE));
2228 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2229 I2O_EXEC_OUTBOUND_INIT);
2230 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setHostPageFrameSize(Message_Ptr, PAGE_SIZE);
2231 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setOutboundMFrameSize(Message_Ptr,
2232 sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME));
2234 * Reset the Reply Status
2236 *(Reply_Ptr = (U32 *)((char *)Message_Ptr
2237 + sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE))) = 0;
2238 SG (&(Message_Ptr->SGL), 0, I2O_SGL_FLAGS_LAST_ELEMENT, Reply_Ptr,
2241 * Send the Message out
2243 if ((Old = ASR_initiateCp (sc->ha_Virt, sc->ha_Fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
2247 * Wait for a response (Poll).
2249 while (*Reply_Ptr < I2O_EXEC_OUTBOUND_INIT_REJECTED);
2251 * Re-enable the interrupts.
2253 sc->ha_Virt->Mask = Old;
2255 * Populate the outbound table.
2257 if (sc->ha_Msgs == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
2259 /* Allocate the reply frames */
2260 size = sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
2261 * sc->ha_Msgs_Count;
2264 * contigmalloc only works reliably at
2265 * initialization time.
2267 if ((sc->ha_Msgs = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
2268 contigmalloc (size, M_DEVBUF, M_WAITOK, 0ul,
2269 0xFFFFFFFFul, (u_long)sizeof(U32), 0ul))
2270 != (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
2271 (void)bzero ((char *)sc->ha_Msgs, size);
2272 sc->ha_Msgs_Phys = KVTOPHYS(sc->ha_Msgs);
2276 /* Initialize the outbound FIFO */
2277 if (sc->ha_Msgs != (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL)
2278 for (size = sc->ha_Msgs_Count, addr = sc->ha_Msgs_Phys;
2280 sc->ha_Virt->FromFIFO = addr;
2281 addr += sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME);
2283 return (*Reply_Ptr);
2286 } /* ASR_initOutBound */
2289 * Set the system table
2293 IN Asr_softc_t * sc)
2295 PI2O_EXEC_SYS_TAB_SET_MESSAGE Message_Ptr;
2296 PI2O_SET_SYSTAB_HEADER SystemTable;
2298 PI2O_SGE_SIMPLE_ELEMENT sg;
2301 if ((SystemTable = (PI2O_SET_SYSTAB_HEADER)malloc (
2302 sizeof(I2O_SET_SYSTAB_HEADER), M_TEMP, M_WAITOK))
2303 == (PI2O_SET_SYSTAB_HEADER)NULL) {
2306 bzero (SystemTable, sizeof(I2O_SET_SYSTAB_HEADER));
2307 for (ha = Asr_softc; ha; ha = ha->ha_next) {
2308 ++SystemTable->NumberEntries;
2310 if ((Message_Ptr = (PI2O_EXEC_SYS_TAB_SET_MESSAGE)malloc (
2311 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2312 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)),
2313 M_TEMP, M_WAITOK)) == (PI2O_EXEC_SYS_TAB_SET_MESSAGE)NULL) {
2314 free (SystemTable, M_TEMP);
2317 (void)ASR_fillMessage((char *)Message_Ptr,
2318 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2319 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)));
2320 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
2322 (((sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2323 / sizeof(U32)) << 4)));
2324 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2325 I2O_EXEC_SYS_TAB_SET);
2327 * Call the LCT table to determine the number of device entries
2328 * to reserve space for.
2329 * since this code is reused in several systems, code efficiency
2330 * is greater by using a shift operation rather than a divide by
2331 * sizeof(u_int32_t).
2333 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
2334 + ((I2O_MESSAGE_FRAME_getVersionOffset(
2335 &(Message_Ptr->StdMessageFrame)) & 0xF0) >> 2));
2336 SG(sg, 0, I2O_SGL_FLAGS_DIR, SystemTable, sizeof(I2O_SET_SYSTAB_HEADER));
2338 for (ha = Asr_softc; ha; ha = ha->ha_next) {
2341 ? (I2O_SGL_FLAGS_DIR)
2342 : (I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER)),
2343 &(ha->ha_SystemTable), sizeof(ha->ha_SystemTable));
2346 SG(sg, 0, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
2347 SG(sg, 1, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_LAST_ELEMENT
2348 | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
2349 retVal = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2350 free (Message_Ptr, M_TEMP);
2351 free (SystemTable, M_TEMP);
2353 } /* ASR_setSysTab */
2357 INOUT Asr_softc_t * sc)
2359 defAlignLong(I2O_EXEC_HRT_GET_MESSAGE,Message);
2360 I2O_EXEC_HRT_GET_MESSAGE * Message_Ptr;
2363 I2O_HRT_ENTRY Entry[MAX_CHANNEL];
2365 u_int8_t NumberOfEntries;
2366 PI2O_HRT_ENTRY Entry;
2368 bzero ((void *)&Hrt, sizeof (Hrt));
2369 Message_Ptr = (I2O_EXEC_HRT_GET_MESSAGE *)ASR_fillMessage(Message,
2370 sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2371 + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2372 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
2374 + (((sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2375 / sizeof(U32)) << 4)));
2376 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
2380 * Set up the buffers as scatter gather elements.
2382 SG(&(Message_Ptr->SGL), 0,
2383 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2385 if (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != CAM_REQ_CMP) {
2388 if ((NumberOfEntries = I2O_HRT_getNumberEntries(&Hrt.Header))
2389 > (MAX_CHANNEL + 1)) {
2390 NumberOfEntries = MAX_CHANNEL + 1;
2392 for (Entry = Hrt.Header.HRTEntry;
2393 NumberOfEntries != 0;
2394 ++Entry, --NumberOfEntries) {
2395 PI2O_LCT_ENTRY Device;
2397 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2398 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
2400 if (I2O_LCT_ENTRY_getLocalTID(Device)
2401 == (I2O_HRT_ENTRY_getAdapterID(Entry) & 0xFFF)) {
2402 Device->le_bus = I2O_HRT_ENTRY_getAdapterID(
2404 if ((Device->le_bus > sc->ha_MaxBus)
2405 && (Device->le_bus <= MAX_CHANNEL)) {
2406 sc->ha_MaxBus = Device->le_bus;
2412 } /* ASR_acquireHrt */
2415 * Enable the adapter.
2419 IN Asr_softc_t * sc)
2421 defAlignLong(I2O_EXEC_SYS_ENABLE_MESSAGE,Message);
2422 PI2O_EXEC_SYS_ENABLE_MESSAGE Message_Ptr;
2424 Message_Ptr = (PI2O_EXEC_SYS_ENABLE_MESSAGE)ASR_fillMessage(Message,
2425 sizeof(I2O_EXEC_SYS_ENABLE_MESSAGE));
2426 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2427 I2O_EXEC_SYS_ENABLE);
2428 return (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != 0);
2429 } /* ASR_enableSys */
2432 * Perform the stages necessary to initialize the adapter
2436 IN Asr_softc_t * sc)
2438 return ((ASR_initOutBound(sc) == 0)
2439 || (ASR_setSysTab(sc) != CAM_REQ_CMP)
2440 || (ASR_enableSys(sc) != CAM_REQ_CMP));
2444 * Send a Synchronize Cache command to the target device.
2448 IN Asr_softc_t * sc,
2456 * We will not synchronize the device when there are outstanding
2457 * commands issued by the OS (this is due to a locked up device,
2458 * as the OS normally would flush all outstanding commands before
2459 * issuing a shutdown or an adapter reset).
2461 if ((sc != (Asr_softc_t *)NULL)
2462 && (LIST_FIRST(&(sc->ha_ccb)) != (struct ccb_hdr *)NULL)
2463 && ((TID = ASR_getTid (sc, bus, target, lun)) != (tid_t)-1)
2464 && (TID != (tid_t)0)) {
2465 defAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE,Message);
2466 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
2469 = getAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE, Message),
2470 sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2471 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2473 I2O_MESSAGE_FRAME_setVersionOffset(
2474 (PI2O_MESSAGE_FRAME)Message_Ptr,
2476 | (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2477 - sizeof(I2O_SG_ELEMENT))
2478 / sizeof(U32)) << 4));
2479 I2O_MESSAGE_FRAME_setMessageSize(
2480 (PI2O_MESSAGE_FRAME)Message_Ptr,
2481 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2482 - sizeof(I2O_SG_ELEMENT))
2484 I2O_MESSAGE_FRAME_setInitiatorAddress (
2485 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
2486 I2O_MESSAGE_FRAME_setFunction(
2487 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
2488 I2O_MESSAGE_FRAME_setTargetAddress(
2489 (PI2O_MESSAGE_FRAME)Message_Ptr, TID);
2490 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
2491 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2493 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(Message_Ptr, TID);
2494 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2495 I2O_SCB_FLAG_ENABLE_DISCONNECT
2496 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2497 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2498 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2499 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2500 DPT_ORGANIZATION_ID);
2501 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
2502 Message_Ptr->CDB[0] = SYNCHRONIZE_CACHE;
2503 Message_Ptr->CDB[1] = (lun << 5);
2505 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2506 (I2O_SCB_FLAG_XFER_FROM_DEVICE
2507 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2508 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2509 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2511 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2518 IN Asr_softc_t * sc)
2520 int bus, target, lun;
2522 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
2523 for (target = 0; target <= sc->ha_MaxId; ++target) {
2524 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
2525 ASR_sync(sc,bus,target,lun);
2532 * Reset the HBA, targets and BUS.
2533 * Currently this resets *all* the SCSI busses.
2537 IN Asr_softc_t * sc)
2539 ASR_synchronize (sc);
2540 (void)ASR_reset (sc);
2541 } /* asr_hbareset */
2544 * A reduced copy of the real pci_map_mem, incorporating the MAX_MAP
2545 * limit and a reduction in error checking (in the pre 4.0 case).
2549 #if __FreeBSD_version >= 400000
2554 IN Asr_softc_t * sc)
2559 #if __FreeBSD_version >= 400000
2561 * I2O specification says we must find first *memory* mapped BAR
2563 for (rid = PCIR_MAPS;
2564 rid < (PCIR_MAPS + 4 * sizeof(u_int32_t));
2565 rid += sizeof(u_int32_t)) {
2566 p = pci_read_config(tag, rid, sizeof(p));
2574 if (rid >= (PCIR_MAPS + 4 * sizeof(u_int32_t))) {
2577 p = pci_read_config(tag, rid, sizeof(p));
2578 pci_write_config(tag, rid, -1, sizeof(p));
2579 l = 0 - (pci_read_config(tag, rid, sizeof(l)) & ~15);
2580 pci_write_config(tag, rid, p, sizeof(p));
2585 * The 2005S Zero Channel RAID solution is not a perfect PCI
2586 * citizen. It asks for 4MB on BAR0, and 0MB on BAR1, once
2587 * enabled it rewrites the size of BAR0 to 2MB, sets BAR1 to
2588 * BAR0+2MB and sets it's size to 2MB. The IOP registers are
2589 * accessible via BAR0, the messaging registers are accessible
2590 * via BAR1. If the subdevice code is 50 to 59 decimal.
2592 s = pci_read_config(tag, PCIR_DEVVENDOR, sizeof(s));
2593 if (s != 0xA5111044) {
2594 s = pci_read_config(tag, PCIR_SUBVEND_0, sizeof(s));
2595 if ((((ADPTDOMINATOR_SUB_ID_START ^ s) & 0xF000FFFF) == 0)
2596 && (ADPTDOMINATOR_SUB_ID_START <= s)
2597 && (s <= ADPTDOMINATOR_SUB_ID_END)) {
2598 l = MAX_MAP; /* Conjoined BAR Raptor Daptor */
2602 sc->ha_mem_res = bus_alloc_resource(tag, SYS_RES_MEMORY, &rid,
2603 p, p + l, l, RF_ACTIVE);
2604 if (sc->ha_mem_res == (struct resource *)NULL) {
2607 sc->ha_Base = (void *)rman_get_start(sc->ha_mem_res);
2608 if (sc->ha_Base == (void *)NULL) {
2611 sc->ha_Virt = (i2oRegs_t *) rman_get_virtual(sc->ha_mem_res);
2612 if (s == 0xA5111044) { /* Split BAR Raptor Daptor */
2613 if ((rid += sizeof(u_int32_t))
2614 >= (PCIR_MAPS + 4 * sizeof(u_int32_t))) {
2617 p = pci_read_config(tag, rid, sizeof(p));
2618 pci_write_config(tag, rid, -1, sizeof(p));
2619 l = 0 - (pci_read_config(tag, rid, sizeof(l)) & ~15);
2620 pci_write_config(tag, rid, p, sizeof(p));
2625 sc->ha_mes_res = bus_alloc_resource(tag, SYS_RES_MEMORY, &rid,
2626 p, p + l, l, RF_ACTIVE);
2627 if (sc->ha_mes_res == (struct resource *)NULL) {
2630 if ((void *)rman_get_start(sc->ha_mes_res) == (void *)NULL) {
2633 sc->ha_Fvirt = (U8 *) rman_get_virtual(sc->ha_mes_res);
2635 sc->ha_Fvirt = (U8 *)(sc->ha_Virt);
2638 vm_size_t psize, poffs;
2641 * I2O specification says we must find first *memory* mapped BAR
2643 for (rid = PCI_MAP_REG_START;
2644 rid < (PCI_MAP_REG_START + 4 * sizeof(u_int32_t));
2645 rid += sizeof(u_int32_t)) {
2646 p = pci_conf_read (tag, rid);
2651 if (rid >= (PCI_MAP_REG_START + 4 * sizeof(u_int32_t))) {
2652 rid = PCI_MAP_REG_START;
2655 ** save old mapping, get size and type of memory
2657 ** type is in the lowest four bits.
2658 ** If device requires 2^n bytes, the next
2659 ** n-4 bits are read as 0.
2662 sc->ha_Base = (void *)((p = pci_conf_read (tag, rid))
2663 & PCI_MAP_MEMORY_ADDRESS_MASK);
2664 pci_conf_write (tag, rid, 0xfffffffful);
2665 l = pci_conf_read (tag, rid);
2666 pci_conf_write (tag, rid, p);
2672 if (!((l & PCI_MAP_MEMORY_TYPE_MASK) == PCI_MAP_MEMORY_TYPE_32BIT_1M
2673 && ((u_long)sc->ha_Base & ~0xfffff) == 0)
2674 && ((l & PCI_MAP_MEMORY_TYPE_MASK) != PCI_MAP_MEMORY_TYPE_32BIT)) {
2676 "asr_pci_map_mem failed: bad memory type=0x%x\n",
2685 psize = -(l & PCI_MAP_MEMORY_ADDRESS_MASK);
2686 if (psize > MAX_MAP) {
2690 * The 2005S Zero Channel RAID solution is not a perfect PCI
2691 * citizen. It asks for 4MB on BAR0, and 0MB on BAR1, once
2692 * enabled it rewrites the size of BAR0 to 2MB, sets BAR1 to
2693 * BAR0+2MB and sets it's size to 2MB. The IOP registers are
2694 * accessible via BAR0, the messaging registers are accessible
2695 * via BAR1. If the subdevice code is 50 to 59 decimal.
2697 s = pci_read_config(tag, PCIR_DEVVENDOR, sizeof(s));
2698 if (s != 0xA5111044) {
2699 s = pci_conf_read (tag, PCIR_SUBVEND_0)
2700 if ((((ADPTDOMINATOR_SUB_ID_START ^ s) & 0xF000FFFF) == 0)
2701 && (ADPTDOMINATOR_SUB_ID_START <= s)
2702 && (s <= ADPTDOMINATOR_SUB_ID_END)) {
2707 if ((sc->ha_Base == (void *)NULL)
2708 || (sc->ha_Base == (void *)PCI_MAP_MEMORY_ADDRESS_MASK)) {
2709 debug_asr_printf ("asr_pci_map_mem: not configured by bios.\n");
2714 ** Truncate sc->ha_Base to page boundary.
2715 ** (Or does pmap_mapdev the job?)
2718 poffs = (u_long)sc->ha_Base - trunc_page ((u_long)sc->ha_Base);
2719 sc->ha_Virt = (i2oRegs_t *)pmap_mapdev ((u_long)sc->ha_Base - poffs,
2722 if (sc->ha_Virt == (i2oRegs_t *)NULL) {
2726 sc->ha_Virt = (i2oRegs_t *)((u_long)sc->ha_Virt + poffs);
2727 if (s == 0xA5111044) {
2728 if ((rid += sizeof(u_int32_t))
2729 >= (PCI_MAP_REG_START + 4 * sizeof(u_int32_t))) {
2734 ** save old mapping, get size and type of memory
2736 ** type is in the lowest four bits.
2737 ** If device requires 2^n bytes, the next
2738 ** n-4 bits are read as 0.
2741 if ((((p = pci_conf_read (tag, rid))
2742 & PCI_MAP_MEMORY_ADDRESS_MASK) == 0L)
2743 || ((p & PCI_MAP_MEMORY_ADDRESS_MASK)
2744 == PCI_MAP_MEMORY_ADDRESS_MASK)) {
2745 debug_asr_printf ("asr_pci_map_mem: not configured by bios.\n");
2747 pci_conf_write (tag, rid, 0xfffffffful);
2748 l = pci_conf_read (tag, rid);
2749 pci_conf_write (tag, rid, p);
2750 p &= PCI_MAP_MEMORY_TYPE_MASK;
2756 if (!((l & PCI_MAP_MEMORY_TYPE_MASK)
2757 == PCI_MAP_MEMORY_TYPE_32BIT_1M
2758 && (p & ~0xfffff) == 0)
2759 && ((l & PCI_MAP_MEMORY_TYPE_MASK)
2760 != PCI_MAP_MEMORY_TYPE_32BIT)) {
2762 "asr_pci_map_mem failed: bad memory type=0x%x\n",
2771 psize = -(l & PCI_MAP_MEMORY_ADDRESS_MASK);
2772 if (psize > MAX_MAP) {
2777 ** Truncate p to page boundary.
2778 ** (Or does pmap_mapdev the job?)
2781 poffs = p - trunc_page (p);
2782 sc->ha_Fvirt = (U8 *)pmap_mapdev (p - poffs, psize + poffs);
2784 if (sc->ha_Fvirt == (U8 *)NULL) {
2788 sc->ha_Fvirt = (U8 *)((u_long)sc->ha_Fvirt + poffs);
2790 sc->ha_Fvirt = (U8 *)(sc->ha_Virt);
2794 } /* asr_pci_map_mem */
2797 * A simplified copy of the real pci_map_int with additional
2798 * registration requirements.
2802 #if __FreeBSD_version >= 400000
2807 IN Asr_softc_t * sc)
2809 #if __FreeBSD_version >= 400000
2812 sc->ha_irq_res = bus_alloc_resource(tag, SYS_RES_IRQ, &rid,
2813 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
2814 if (sc->ha_irq_res == (struct resource *)NULL) {
2817 if (bus_setup_intr(tag, sc->ha_irq_res, INTR_TYPE_CAM,
2818 (driver_intr_t *)asr_intr, (void *)sc, &(sc->ha_intr))) {
2821 sc->ha_irq = pci_read_config(tag, PCIR_INTLINE, sizeof(char));
2823 if (!pci_map_int(tag, (pci_inthand_t *)asr_intr,
2824 (void *)sc, &cam_imask)) {
2827 sc->ha_irq = pci_conf_read(tag, PCIR_INTLINE);
2830 } /* asr_pci_map_int */
2833 * Attach the devices, and virtual devices to the driver list.
2836 asr_attach (ATTACH_ARGS)
2839 struct scsi_inquiry_data * iq;
2842 if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT)) == (Asr_softc_t *)NULL) {
2843 ATTACH_RETURN(ENOMEM);
2845 if (Asr_softc == (Asr_softc_t *)NULL) {
2847 * Fixup the OS revision as saved in the dptsig for the
2848 * engine (dptioctl.h) to pick up.
2850 bcopy (osrelease, &ASR_sig.dsDescription[16], 5);
2851 printf ("asr%d: major=%d\n", unit, asr_cdevsw.d_maj);
2854 * Initialize the software structure
2856 bzero (sc, sizeof(*sc));
2857 LIST_INIT(&(sc->ha_ccb));
2858 # ifdef ASR_MEASURE_PERFORMANCE
2862 // initialize free list for timeQ
2863 sc->ha_timeQFreeHead = 0;
2864 sc->ha_timeQFreeTail = MAX_TIMEQ_SIZE - 1;
2865 for (i = 0; i < MAX_TIMEQ_SIZE; i++) {
2866 sc->ha_timeQFreeList[i] = i;
2870 /* Link us into the HA list */
2874 for (ha = &Asr_softc; *ha; ha = &((*ha)->ha_next));
2878 PI2O_EXEC_STATUS_GET_REPLY status;
2882 * This is the real McCoy!
2884 if (!asr_pci_map_mem(tag, sc)) {
2885 printf ("asr%d: could not map memory\n", unit);
2886 ATTACH_RETURN(ENXIO);
2888 /* Enable if not formerly enabled */
2889 #if __FreeBSD_version >= 400000
2890 pci_write_config (tag, PCIR_COMMAND,
2891 pci_read_config (tag, PCIR_COMMAND, sizeof(char))
2892 | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN, sizeof(char));
2893 /* Knowledge is power, responsibility is direct */
2895 struct pci_devinfo {
2896 STAILQ_ENTRY(pci_devinfo) pci_links;
2897 struct resource_list resources;
2899 } * dinfo = device_get_ivars(tag);
2900 sc->ha_pciBusNum = dinfo->cfg.bus;
2901 sc->ha_pciDeviceNum = (dinfo->cfg.slot << 3)
2905 pci_conf_write (tag, PCIR_COMMAND,
2906 pci_conf_read (tag, PCIR_COMMAND)
2907 | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
2908 /* Knowledge is power, responsibility is direct */
2909 switch (pci_mechanism) {
2912 sc->ha_pciBusNum = tag.cfg1 >> 16;
2913 sc->ha_pciDeviceNum = tag.cfg1 >> 8;
2916 sc->ha_pciBusNum = tag.cfg2.forward;
2917 sc->ha_pciDeviceNum = ((tag.cfg2.enable >> 1) & 7)
2918 | (tag.cfg2.port >> 5);
2921 /* Check if the device is there? */
2922 if ((ASR_resetIOP(sc->ha_Virt, sc->ha_Fvirt) == 0)
2923 || ((status = (PI2O_EXEC_STATUS_GET_REPLY)malloc (
2924 sizeof(I2O_EXEC_STATUS_GET_REPLY), M_TEMP, M_WAITOK))
2925 == (PI2O_EXEC_STATUS_GET_REPLY)NULL)
2926 || (ASR_getStatus(sc->ha_Virt, sc->ha_Fvirt, status) == NULL)) {
2927 printf ("asr%d: could not initialize hardware\n", unit);
2928 ATTACH_RETURN(ENODEV); /* Get next, maybe better luck */
2930 sc->ha_SystemTable.OrganizationID = status->OrganizationID;
2931 sc->ha_SystemTable.IOP_ID = status->IOP_ID;
2932 sc->ha_SystemTable.I2oVersion = status->I2oVersion;
2933 sc->ha_SystemTable.IopState = status->IopState;
2934 sc->ha_SystemTable.MessengerType = status->MessengerType;
2935 sc->ha_SystemTable.InboundMessageFrameSize
2936 = status->InboundMFrameSize;
2937 sc->ha_SystemTable.MessengerInfo.InboundMessagePortAddressLow
2938 = (U32)(sc->ha_Base) + (U32)(&(((i2oRegs_t *)NULL)->ToFIFO));
2940 if (!asr_pci_map_int(tag, (void *)sc)) {
2941 printf ("asr%d: could not map interrupt\n", unit);
2942 ATTACH_RETURN(ENXIO);
2945 /* Adjust the maximim inbound count */
2946 if (((sc->ha_QueueSize
2947 = I2O_EXEC_STATUS_GET_REPLY_getMaxInboundMFrames(status))
2949 || (sc->ha_QueueSize == 0)) {
2950 sc->ha_QueueSize = MAX_INBOUND;
2953 /* Adjust the maximum outbound count */
2954 if (((sc->ha_Msgs_Count
2955 = I2O_EXEC_STATUS_GET_REPLY_getMaxOutboundMFrames(status))
2957 || (sc->ha_Msgs_Count == 0)) {
2958 sc->ha_Msgs_Count = MAX_OUTBOUND;
2960 if (sc->ha_Msgs_Count > sc->ha_QueueSize) {
2961 sc->ha_Msgs_Count = sc->ha_QueueSize;
2964 /* Adjust the maximum SG size to adapter */
2965 if ((size = (I2O_EXEC_STATUS_GET_REPLY_getInboundMFrameSize(
2966 status) << 2)) > MAX_INBOUND_SIZE) {
2967 size = MAX_INBOUND_SIZE;
2969 free (status, M_TEMP);
2970 sc->ha_SgSize = (size - sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2971 + sizeof(I2O_SG_ELEMENT)) / sizeof(I2O_SGE_SIMPLE_ELEMENT);
2975 * Only do a bus/HBA reset on the first time through. On this
2976 * first time through, we do not send a flush to the devices.
2978 if (ASR_init(sc) == 0) {
2980 I2O_PARAM_RESULTS_LIST_HEADER Header;
2981 I2O_PARAM_READ_OPERATION_RESULT Read;
2982 I2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2984 defAlignLong (struct BufferInfo, Buffer);
2985 PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2986 # define FW_DEBUG_BLED_OFFSET 8
2988 if ((Info = (PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR)
2989 ASR_getParams(sc, 0,
2990 I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO,
2991 Buffer, sizeof(struct BufferInfo)))
2992 != (PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR)NULL) {
2993 sc->ha_blinkLED = sc->ha_Fvirt
2994 + I2O_DPT_EXEC_IOP_BUFFERS_SCALAR_getSerialOutputOffset(Info)
2995 + FW_DEBUG_BLED_OFFSET;
2997 if (ASR_acquireLct(sc) == 0) {
2998 (void)ASR_acquireHrt(sc);
3001 printf ("asr%d: failed to initialize\n", unit);
3002 ATTACH_RETURN(ENXIO);
3005 * Add in additional probe responses for more channels. We
3006 * are reusing the variable `target' for a channel loop counter.
3007 * Done here because of we need both the acquireLct and
3010 { PI2O_LCT_ENTRY Device;
3012 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
3013 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
3015 if (Device->le_type == I2O_UNKNOWN) {
3018 if (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF) {
3019 if (Device->le_target > sc->ha_MaxId) {
3020 sc->ha_MaxId = Device->le_target;
3022 if (Device->le_lun > sc->ha_MaxLun) {
3023 sc->ha_MaxLun = Device->le_lun;
3026 if (((Device->le_type & I2O_PORT) != 0)
3027 && (Device->le_bus <= MAX_CHANNEL)) {
3028 /* Do not increase MaxId for efficiency */
3029 sc->ha_adapter_target[Device->le_bus]
3030 = Device->le_target;
3037 * Print the HBA model number as inquired from the card.
3040 printf ("asr%d:", unit);
3042 if ((iq = (struct scsi_inquiry_data *)malloc (
3043 sizeof(struct scsi_inquiry_data), M_TEMP, M_WAITOK))
3044 != (struct scsi_inquiry_data *)NULL) {
3045 defAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE,Message);
3046 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
3049 bzero (iq, sizeof(struct scsi_inquiry_data));
3051 = getAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE, Message),
3052 sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3053 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
3055 I2O_MESSAGE_FRAME_setVersionOffset(
3056 (PI2O_MESSAGE_FRAME)Message_Ptr,
3058 | (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3059 - sizeof(I2O_SG_ELEMENT))
3060 / sizeof(U32)) << 4));
3061 I2O_MESSAGE_FRAME_setMessageSize(
3062 (PI2O_MESSAGE_FRAME)Message_Ptr,
3063 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3064 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT))
3066 I2O_MESSAGE_FRAME_setInitiatorAddress (
3067 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
3068 I2O_MESSAGE_FRAME_setFunction(
3069 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
3070 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
3071 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
3073 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
3074 I2O_SCB_FLAG_ENABLE_DISCONNECT
3075 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
3076 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
3077 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setInterpret(Message_Ptr, 1);
3078 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
3079 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
3080 DPT_ORGANIZATION_ID);
3081 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
3082 Message_Ptr->CDB[0] = INQUIRY;
3083 Message_Ptr->CDB[4] = (unsigned char)sizeof(struct scsi_inquiry_data);
3084 if (Message_Ptr->CDB[4] == 0) {
3085 Message_Ptr->CDB[4] = 255;
3088 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
3089 (I2O_SCB_FLAG_XFER_FROM_DEVICE
3090 | I2O_SCB_FLAG_ENABLE_DISCONNECT
3091 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
3092 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
3094 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
3095 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
3096 sizeof(struct scsi_inquiry_data));
3097 SG(&(Message_Ptr->SGL), 0,
3098 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
3099 iq, sizeof(struct scsi_inquiry_data));
3100 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
3102 if (iq->vendor[0] && (iq->vendor[0] != ' ')) {
3104 ASR_prstring (iq->vendor, 8);
3107 if (iq->product[0] && (iq->product[0] != ' ')) {
3109 ASR_prstring (iq->product, 16);
3112 if (iq->revision[0] && (iq->revision[0] != ' ')) {
3113 printf (" FW Rev. ");
3114 ASR_prstring (iq->revision, 4);
3117 free ((caddr_t)iq, M_TEMP);
3122 printf (" %d channel, %d CCBs, Protocol I2O\n", sc->ha_MaxBus + 1,
3123 (sc->ha_QueueSize > MAX_INBOUND) ? MAX_INBOUND : sc->ha_QueueSize);
3126 * fill in the prototype cam_path.
3130 union asr_ccb * ccb;
3132 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
3133 printf ("asr%d: CAM could not be notified of asynchronous callback parameters\n", unit);
3134 ATTACH_RETURN(ENOMEM);
3136 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
3137 struct cam_devq * devq;
3138 int QueueSize = sc->ha_QueueSize;
3140 if (QueueSize > MAX_INBOUND) {
3141 QueueSize = MAX_INBOUND;
3145 * Create the device queue for our SIM(s).
3147 if ((devq = cam_simq_alloc(QueueSize)) == NULL) {
3152 * Construct our first channel SIM entry
3154 sc->ha_sim[bus] = cam_sim_alloc(
3155 asr_action, asr_poll, "asr", sc,
3156 unit, 1, QueueSize, devq);
3157 if (sc->ha_sim[bus] == NULL) {
3161 if (xpt_bus_register(sc->ha_sim[bus], bus)
3163 cam_sim_free(sc->ha_sim[bus],
3165 sc->ha_sim[bus] = NULL;
3169 if (xpt_create_path(&(sc->ha_path[bus]), /*periph*/NULL,
3170 cam_sim_path(sc->ha_sim[bus]), CAM_TARGET_WILDCARD,
3171 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
3173 cam_sim_path(sc->ha_sim[bus]));
3174 cam_sim_free(sc->ha_sim[bus],
3176 sc->ha_sim[bus] = NULL;
3183 * Generate the device node information
3185 (void)make_dev(&asr_cdevsw, unit, 0, 0, S_IRWXU, "rasr%d", unit);
3186 destroy_dev(makedev(asr_cdevsw.d_maj,unit+1));
3192 IN struct cam_sim *sim)
3194 asr_intr(cam_sim_softc(sim));
3199 IN struct cam_sim * sim,
3202 struct Asr_softc * sc;
3204 debug_asr_printf ("asr_action(%lx,%lx{%x})\n",
3205 (u_long)sim, (u_long)ccb, ccb->ccb_h.func_code);
3207 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("asr_action\n"));
3209 ccb->ccb_h.spriv_ptr0 = sc = (struct Asr_softc *)cam_sim_softc(sim);
3211 switch (ccb->ccb_h.func_code) {
3213 /* Common cases first */
3214 case XPT_SCSI_IO: /* Execute the requested I/O operation */
3217 char M[MAX_INBOUND_SIZE];
3219 defAlignLong(struct Message,Message);
3220 PI2O_MESSAGE_FRAME Message_Ptr;
3222 /* Reject incoming commands while we are resetting the card */
3223 if (sc->ha_in_reset != HA_OPERATIONAL) {
3224 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3225 if (sc->ha_in_reset >= HA_OFF_LINE) {
3226 /* HBA is now off-line */
3227 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
3229 /* HBA currently resetting, try again later. */
3230 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3232 debug_asr_cmd_printf (" e\n");
3234 debug_asr_cmd_printf (" q\n");
3237 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
3239 "asr%d WARNING: scsi_cmd(%x) already done on b%dt%du%d\n",
3240 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
3241 ccb->csio.cdb_io.cdb_bytes[0],
3243 ccb->ccb_h.target_id,
3244 ccb->ccb_h.target_lun);
3246 debug_asr_cmd_printf ("(%d,%d,%d,%d)",
3249 ccb->ccb_h.target_id,
3250 ccb->ccb_h.target_lun);
3251 debug_asr_cmd_dump_ccb(ccb);
3253 if ((Message_Ptr = ASR_init_message ((union asr_ccb *)ccb,
3254 (PI2O_MESSAGE_FRAME)Message)) != (PI2O_MESSAGE_FRAME)NULL) {
3255 debug_asr_cmd2_printf ("TID=%x:\n",
3256 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getTID(
3257 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr));
3258 debug_asr_cmd2_dump_message(Message_Ptr);
3259 debug_asr_cmd1_printf (" q");
3261 if (ASR_queue (sc, Message_Ptr) == EMPTY_QUEUE) {
3262 #ifdef ASR_MEASURE_PERFORMANCE
3263 ++sc->ha_performance.command_too_busy;
3265 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3266 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3267 debug_asr_cmd_printf (" E\n");
3270 debug_asr_cmd_printf (" Q\n");
3274 * We will get here if there is no valid TID for the device
3275 * referenced in the scsi command packet.
3277 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3278 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
3279 debug_asr_cmd_printf (" B\n");
3284 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
3285 /* Rese HBA device ... */
3287 ccb->ccb_h.status = CAM_REQ_CMP;
3291 # if (defined(REPORT_LUNS))
3294 case XPT_ABORT: /* Abort the specified CCB */
3296 ccb->ccb_h.status = CAM_REQ_INVALID;
3300 case XPT_SET_TRAN_SETTINGS:
3302 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3306 case XPT_GET_TRAN_SETTINGS:
3307 /* Get default/user set transfer settings for the target */
3309 struct ccb_trans_settings *cts;
3313 target_mask = 0x01 << ccb->ccb_h.target_id;
3314 if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) {
3315 cts->flags = CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB;
3316 cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
3317 cts->sync_period = 6; /* 40MHz */
3318 cts->sync_offset = 15;
3320 cts->valid = CCB_TRANS_SYNC_RATE_VALID
3321 | CCB_TRANS_SYNC_OFFSET_VALID
3322 | CCB_TRANS_BUS_WIDTH_VALID
3323 | CCB_TRANS_DISC_VALID
3324 | CCB_TRANS_TQ_VALID;
3325 ccb->ccb_h.status = CAM_REQ_CMP;
3327 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3333 case XPT_CALC_GEOMETRY:
3335 struct ccb_calc_geometry *ccg;
3337 u_int32_t secs_per_cylinder;
3340 size_mb = ccg->volume_size
3341 / ((1024L * 1024L) / ccg->block_size);
3343 if (size_mb > 4096) {
3345 ccg->secs_per_track = 63;
3346 } else if (size_mb > 2048) {
3348 ccg->secs_per_track = 63;
3349 } else if (size_mb > 1024) {
3351 ccg->secs_per_track = 63;
3354 ccg->secs_per_track = 32;
3356 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
3357 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
3358 ccb->ccb_h.status = CAM_REQ_CMP;
3363 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
3364 ASR_resetBus (sc, cam_sim_bus(sim));
3365 ccb->ccb_h.status = CAM_REQ_CMP;
3369 case XPT_TERM_IO: /* Terminate the I/O process */
3371 ccb->ccb_h.status = CAM_REQ_INVALID;
3375 case XPT_PATH_INQ: /* Path routing inquiry */
3377 struct ccb_pathinq *cpi = &(ccb->cpi);
3379 cpi->version_num = 1; /* XXX??? */
3380 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
3381 cpi->target_sprt = 0;
3382 /* Not necessary to reset bus, done by HDM initialization */
3383 cpi->hba_misc = PIM_NOBUSRESET;
3384 cpi->hba_eng_cnt = 0;
3385 cpi->max_target = sc->ha_MaxId;
3386 cpi->max_lun = sc->ha_MaxLun;
3387 cpi->initiator_id = sc->ha_adapter_target[cam_sim_bus(sim)];
3388 cpi->bus_id = cam_sim_bus(sim);
3389 cpi->base_transfer_speed = 3300;
3390 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
3391 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
3392 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
3393 cpi->unit_number = cam_sim_unit(sim);
3394 cpi->ccb_h.status = CAM_REQ_CMP;
3399 ccb->ccb_h.status = CAM_REQ_INVALID;
3405 #ifdef ASR_MEASURE_PERFORMANCE
3408 #define min_submitR sc->ha_performance.read_by_size_min_time[index]
3409 #define max_submitR sc->ha_performance.read_by_size_max_time[index]
3410 #define min_submitW sc->ha_performance.write_by_size_min_time[index]
3411 #define max_submitW sc->ha_performance.write_by_size_max_time[index]
3415 IN Asr_softc_t * sc,
3416 IN u_int32_t submitted_time,
3420 struct timeval submitted_timeval;
3422 submitted_timeval.tv_sec = 0;
3423 submitted_timeval.tv_usec = submitted_time;
3425 if ( op == READ_OP ) {
3426 ++sc->ha_performance.read_by_size_count[index];
3428 if ( submitted_time != 0xffffffff ) {
3430 &(sc->ha_performance.read_by_size_total_time[index]),
3431 &submitted_timeval);
3432 if ( (min_submitR == 0)
3433 || (submitted_time < min_submitR) ) {
3434 min_submitR = submitted_time;
3437 if ( submitted_time > max_submitR ) {
3438 max_submitR = submitted_time;
3442 ++sc->ha_performance.write_by_size_count[index];
3443 if ( submitted_time != 0xffffffff ) {
3445 &(sc->ha_performance.write_by_size_total_time[index]),
3446 &submitted_timeval);
3447 if ( (submitted_time < min_submitW)
3448 || (min_submitW == 0) ) {
3449 min_submitW = submitted_time;
3452 if ( submitted_time > max_submitW ) {
3453 max_submitW = submitted_time;
3457 } /* asr_IObySize */
3461 * Handle processing of current CCB as pointed to by the Status.
3465 IN Asr_softc_t * sc)
3469 #ifdef ASR_MEASURE_PERFORMANCE
3470 struct timeval junk;
3473 sc->ha_performance.intr_started = junk;
3477 sc->ha_Virt->Status & Mask_InterruptsDisabled;
3479 union asr_ccb * ccb;
3481 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
3483 if (((ReplyOffset = sc->ha_Virt->FromFIFO) == EMPTY_QUEUE)
3484 && ((ReplyOffset = sc->ha_Virt->FromFIFO) == EMPTY_QUEUE)) {
3487 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)(ReplyOffset
3488 - sc->ha_Msgs_Phys + (char *)(sc->ha_Msgs));
3490 * We do not need any (optional byteswapping) method access to
3491 * the Initiator context field.
3493 ccb = (union asr_ccb *)(long)
3494 I2O_MESSAGE_FRAME_getInitiatorContext64(
3495 &(Reply->StdReplyFrame.StdMessageFrame));
3496 if (I2O_MESSAGE_FRAME_getMsgFlags(
3497 &(Reply->StdReplyFrame.StdMessageFrame))
3498 & I2O_MESSAGE_FLAGS_FAIL) {
3499 defAlignLong(I2O_UTIL_NOP_MESSAGE,Message);
3500 PI2O_UTIL_NOP_MESSAGE Message_Ptr;
3503 MessageOffset = (u_long)
3504 I2O_FAILURE_REPLY_MESSAGE_FRAME_getPreservedMFA(
3505 (PI2O_FAILURE_REPLY_MESSAGE_FRAME)Reply);
3507 * Get the Original Message Frame's address, and get
3508 * it's Transaction Context into our space. (Currently
3509 * unused at original authorship, but better to be
3510 * safe than sorry). Straight copy means that we
3511 * need not concern ourselves with the (optional
3512 * byteswapping) method access.
3514 Reply->StdReplyFrame.TransactionContext
3515 = ((PI2O_SINGLE_REPLY_MESSAGE_FRAME)
3516 (sc->ha_Fvirt + MessageOffset))->TransactionContext;
3518 * For 64 bit machines, we need to reconstruct the
3521 ccb = (union asr_ccb *)(long)
3522 I2O_MESSAGE_FRAME_getInitiatorContext64(
3523 &(Reply->StdReplyFrame.StdMessageFrame));
3525 * Unique error code for command failure.
3527 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
3528 &(Reply->StdReplyFrame), (u_int16_t)-2);
3530 * Modify the message frame to contain a NOP and
3531 * re-issue it to the controller.
3533 Message_Ptr = (PI2O_UTIL_NOP_MESSAGE)ASR_fillMessage(
3534 Message, sizeof(I2O_UTIL_NOP_MESSAGE));
3535 # if (I2O_UTIL_NOP != 0)
3536 I2O_MESSAGE_FRAME_setFunction (
3537 &(Message_Ptr->StdMessageFrame),
3541 * Copy the packet out to the Original Message
3543 bcopy ((caddr_t)Message_Ptr,
3544 sc->ha_Fvirt + MessageOffset,
3545 sizeof(I2O_UTIL_NOP_MESSAGE));
3549 sc->ha_Virt->ToFIFO = MessageOffset;
3553 * Asynchronous command with no return requirements,
3554 * and a generic handler for immunity against odd error
3555 * returns from the adapter.
3557 if (ccb == (union asr_ccb *)NULL) {
3559 * Return Reply so that it can be used for the
3562 sc->ha_Virt->FromFIFO = ReplyOffset;
3566 /* Welease Wadjah! (and stop timeouts) */
3567 ASR_ccbRemove (sc, ccb);
3570 I2O_SINGLE_REPLY_MESSAGE_FRAME_getDetailedStatusCode(
3571 &(Reply->StdReplyFrame))) {
3573 case I2O_SCSI_DSC_SUCCESS:
3574 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3575 ccb->ccb_h.status |= CAM_REQ_CMP;
3578 case I2O_SCSI_DSC_CHECK_CONDITION:
3579 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3580 ccb->ccb_h.status |= CAM_REQ_CMP|CAM_AUTOSNS_VALID;
3583 case I2O_SCSI_DSC_BUSY:
3585 case I2O_SCSI_HBA_DSC_ADAPTER_BUSY:
3587 case I2O_SCSI_HBA_DSC_SCSI_BUS_RESET:
3589 case I2O_SCSI_HBA_DSC_BUS_BUSY:
3590 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3591 ccb->ccb_h.status |= CAM_SCSI_BUSY;
3594 case I2O_SCSI_HBA_DSC_SELECTION_TIMEOUT:
3595 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3596 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
3599 case I2O_SCSI_HBA_DSC_COMMAND_TIMEOUT:
3601 case I2O_SCSI_HBA_DSC_DEVICE_NOT_PRESENT:
3603 case I2O_SCSI_HBA_DSC_LUN_INVALID:
3605 case I2O_SCSI_HBA_DSC_SCSI_TID_INVALID:
3606 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3607 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
3610 case I2O_SCSI_HBA_DSC_DATA_OVERRUN:
3612 case I2O_SCSI_HBA_DSC_REQUEST_LENGTH_ERROR:
3613 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3614 ccb->ccb_h.status |= CAM_DATA_RUN_ERR;
3618 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3619 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3622 if ((ccb->csio.resid = ccb->csio.dxfer_len) != 0) {
3624 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getTransferCount(
3628 #ifdef ASR_MEASURE_PERFORMANCE
3630 struct timeval endTime;
3631 u_int32_t submitted_time;
3636 --sc->ha_submitted_ccbs_count;
3638 = (int)Reply->StdReplyFrame.TransactionContext;
3639 if (-1 != startTimeIndex) {
3640 /* Compute the time spent in device/adapter */
3641 microtime(&endTime);
3642 submitted_time = asr_time_delta(sc->ha_timeQ[
3643 startTimeIndex], endTime);
3644 /* put the startTimeIndex back on free list */
3645 ENQ_TIMEQ_FREE_LIST(startTimeIndex,
3646 sc->ha_timeQFreeList,
3647 sc->ha_timeQFreeHead,
3648 sc->ha_timeQFreeTail);
3650 submitted_time = 0xffffffff;
3653 #define maxctime sc->ha_performance.max_command_time[ccb->csio.cdb_io.cdb_bytes[0]]
3654 #define minctime sc->ha_performance.min_command_time[ccb->csio.cdb_io.cdb_bytes[0]]
3655 if (submitted_time != 0xffffffff) {
3656 if ( maxctime < submitted_time ) {
3657 maxctime = submitted_time;
3659 if ( (minctime == 0)
3660 || (minctime > submitted_time) ) {
3661 minctime = submitted_time;
3664 if ( sc->ha_performance.max_submit_time
3665 < submitted_time ) {
3666 sc->ha_performance.max_submit_time
3669 if ( sc->ha_performance.min_submit_time == 0
3670 || sc->ha_performance.min_submit_time
3672 sc->ha_performance.min_submit_time
3676 switch ( ccb->csio.cdb_io.cdb_bytes[0] ) {
3678 case 0xa8: /* 12-byte READ */
3680 case 0x08: /* 6-byte READ */
3682 case 0x28: /* 10-byte READ */
3686 case 0x0a: /* 6-byte WRITE */
3688 case 0xaa: /* 12-byte WRITE */
3690 case 0x2a: /* 10-byte WRITE */
3699 if ( op_type != 0 ) {
3700 struct scsi_rw_big * cmd;
3702 cmd = (struct scsi_rw_big *)
3703 &(ccb->csio.cdb_io);
3705 size = (((u_int32_t) cmd->length2 << 8)
3706 | ((u_int32_t) cmd->length1)) << 9;
3712 submitted_time, op_type,
3718 submitted_time, op_type,
3724 submitted_time, op_type,
3730 submitted_time, op_type,
3736 submitted_time, op_type,
3742 submitted_time, op_type,
3748 submitted_time, op_type,
3754 submitted_time, op_type,
3759 if ( size > (1 << 16) ) {
3776 /* Sense data in reply packet */
3777 if (ccb->ccb_h.status & CAM_AUTOSNS_VALID) {
3778 u_int16_t size = I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getAutoSenseTransferCount(Reply);
3781 if (size > sizeof(ccb->csio.sense_data)) {
3782 size = sizeof(ccb->csio.sense_data);
3784 if (size > I2O_SCSI_SENSE_DATA_SZ) {
3785 size = I2O_SCSI_SENSE_DATA_SZ;
3787 if ((ccb->csio.sense_len)
3788 && (size > ccb->csio.sense_len)) {
3789 size = ccb->csio.sense_len;
3791 bcopy ((caddr_t)Reply->SenseData,
3792 (caddr_t)&(ccb->csio.sense_data), size);
3797 * Return Reply so that it can be used for the next command
3798 * since we have no more need for it now
3800 sc->ha_Virt->FromFIFO = ReplyOffset;
3802 if (ccb->ccb_h.path) {
3803 xpt_done ((union ccb *)ccb);
3805 wakeup ((caddr_t)ccb);
3808 #ifdef ASR_MEASURE_PERFORMANCE
3813 result = asr_time_delta(sc->ha_performance.intr_started, junk);
3815 if (result != 0xffffffff) {
3816 if ( sc->ha_performance.max_intr_time < result ) {
3817 sc->ha_performance.max_intr_time = result;
3820 if ( (sc->ha_performance.min_intr_time == 0)
3821 || (sc->ha_performance.min_intr_time > result) ) {
3822 sc->ha_performance.min_intr_time = result;
3830 #undef QueueSize /* Grrrr */
3831 #undef SG_Size /* Grrrr */
3834 * Meant to be included at the bottom of asr.c !!!
3838 * Included here as hard coded. Done because other necessary include
3839 * files utilize C++ comment structures which make them a nuisance to
3840 * included here just to pick up these three typedefs.
3842 typedef U32 DPT_TAG_T;
3843 typedef U32 DPT_MSG_T;
3844 typedef U32 DPT_RTN_T;
3846 #undef SCSI_RESET /* Conflicts with "scsi/scsiconf.h" defintion */
3847 #include "dev/asr/osd_unix.h"
3849 #define asr_unit(dev) minor(dev)
3851 STATIC INLINE Asr_softc_t *
3855 int unit = asr_unit(dev);
3856 OUT Asr_softc_t * sc = Asr_softc;
3858 while (sc && sc->ha_sim[0] && (cam_sim_unit(sc->ha_sim[0]) != unit)) {
3864 STATIC u_int8_t ASR_ctlr_held;
3865 #if (!defined(UNREFERENCED_PARAMETER))
3866 # define UNREFERENCED_PARAMETER(x) (void)(x)
3874 IN struct proc * proc)
3878 UNREFERENCED_PARAMETER(flags);
3879 UNREFERENCED_PARAMETER(ifmt);
3881 if (ASR_get_sc (dev) == (Asr_softc_t *)NULL) {
3885 if (ASR_ctlr_held) {
3887 } else if ((error = suser(proc)) == 0) {
3901 UNREFERENCED_PARAMETER(dev);
3902 UNREFERENCED_PARAMETER(flags);
3903 UNREFERENCED_PARAMETER(ifmt);
3904 UNREFERENCED_PARAMETER(proc);
3911 /*-------------------------------------------------------------------------*/
3912 /* Function ASR_queue_i */
3913 /*-------------------------------------------------------------------------*/
3914 /* The Parameters Passed To This Function Are : */
3915 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
3916 /* PI2O_MESSAGE_FRAME : Msg Structure Pointer For This Command */
3917 /* I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME following the Msg Structure */
3919 /* This Function Will Take The User Request Packet And Convert It To An */
3920 /* I2O MSG And Send It Off To The Adapter. */
3922 /* Return : 0 For OK, Error Code Otherwise */
3923 /*-------------------------------------------------------------------------*/
3926 IN Asr_softc_t * sc,
3927 INOUT PI2O_MESSAGE_FRAME Packet)
3929 union asr_ccb * ccb;
3930 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
3931 PI2O_MESSAGE_FRAME Message_Ptr;
3932 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply_Ptr;
3933 int MessageSizeInBytes;
3934 int ReplySizeInBytes;
3937 /* Scatter Gather buffer list */
3938 struct ioctlSgList_S {
3939 SLIST_ENTRY(ioctlSgList_S) link;
3941 I2O_FLAGS_COUNT FlagsCount;
3942 char KernelSpace[sizeof(long)];
3944 /* Generates a `first' entry */
3945 SLIST_HEAD(ioctlSgListHead_S, ioctlSgList_S) sgList;
3947 if (ASR_getBlinkLedCode(sc)) {
3948 debug_usr_cmd_printf ("Adapter currently in BlinkLed %x\n",
3949 ASR_getBlinkLedCode(sc));
3952 /* Copy in the message into a local allocation */
3953 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)malloc (
3954 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK))
3955 == (PI2O_MESSAGE_FRAME)NULL) {
3956 debug_usr_cmd_printf (
3957 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
3960 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
3961 sizeof(I2O_MESSAGE_FRAME))) != 0) {
3962 free (Message_Ptr, M_TEMP);
3963 debug_usr_cmd_printf ("Can't copy in packet errno=%d\n", error);
3966 /* Acquire information to determine type of packet */
3967 MessageSizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)<<2);
3968 /* The offset of the reply information within the user packet */
3969 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)((char *)Packet
3970 + MessageSizeInBytes);
3972 /* Check if the message is a synchronous initialization command */
3973 s = I2O_MESSAGE_FRAME_getFunction(Message_Ptr);
3974 free (Message_Ptr, M_TEMP);
3977 case I2O_EXEC_IOP_RESET:
3980 status = ASR_resetIOP(sc->ha_Virt, sc->ha_Fvirt);
3981 ReplySizeInBytes = sizeof(status);
3982 debug_usr_cmd_printf ("resetIOP done\n");
3983 return (copyout ((caddr_t)&status, (caddr_t)Reply,
3987 case I2O_EXEC_STATUS_GET:
3988 { I2O_EXEC_STATUS_GET_REPLY status;
3990 if (ASR_getStatus (sc->ha_Virt, sc->ha_Fvirt, &status)
3991 == (PI2O_EXEC_STATUS_GET_REPLY)NULL) {
3992 debug_usr_cmd_printf ("getStatus failed\n");
3995 ReplySizeInBytes = sizeof(status);
3996 debug_usr_cmd_printf ("getStatus done\n");
3997 return (copyout ((caddr_t)&status, (caddr_t)Reply,
4001 case I2O_EXEC_OUTBOUND_INIT:
4004 status = ASR_initOutBound(sc);
4005 ReplySizeInBytes = sizeof(status);
4006 debug_usr_cmd_printf ("intOutBound done\n");
4007 return (copyout ((caddr_t)&status, (caddr_t)Reply,
4012 /* Determine if the message size is valid */
4013 if ((MessageSizeInBytes < sizeof(I2O_MESSAGE_FRAME))
4014 || (MAX_INBOUND_SIZE < MessageSizeInBytes)) {
4015 debug_usr_cmd_printf ("Packet size %d incorrect\n",
4016 MessageSizeInBytes);
4020 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)malloc (MessageSizeInBytes,
4021 M_TEMP, M_WAITOK)) == (PI2O_MESSAGE_FRAME)NULL) {
4022 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
4023 MessageSizeInBytes);
4026 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
4027 MessageSizeInBytes)) != 0) {
4028 free (Message_Ptr, M_TEMP);
4029 debug_usr_cmd_printf ("Can't copy in packet[%d] errno=%d\n",
4030 MessageSizeInBytes, error);
4034 /* Check the size of the reply frame, and start constructing */
4036 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)malloc (
4037 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK))
4038 == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
4039 free (Message_Ptr, M_TEMP);
4040 debug_usr_cmd_printf (
4041 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
4044 if ((error = copyin ((caddr_t)Reply, (caddr_t)Reply_Ptr,
4045 sizeof(I2O_MESSAGE_FRAME))) != 0) {
4046 free (Reply_Ptr, M_TEMP);
4047 free (Message_Ptr, M_TEMP);
4048 debug_usr_cmd_printf (
4049 "Failed to copy in reply frame, errno=%d\n",
4053 ReplySizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(
4054 &(Reply_Ptr->StdReplyFrame.StdMessageFrame)) << 2);
4055 free (Reply_Ptr, M_TEMP);
4056 if (ReplySizeInBytes < sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME)) {
4057 free (Message_Ptr, M_TEMP);
4058 debug_usr_cmd_printf (
4059 "Failed to copy in reply frame[%d], errno=%d\n",
4060 ReplySizeInBytes, error);
4064 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)malloc (
4065 ((ReplySizeInBytes > sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME))
4067 : sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)),
4068 M_TEMP, M_WAITOK)) == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
4069 free (Message_Ptr, M_TEMP);
4070 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
4074 (void)ASR_fillMessage ((char *)Reply_Ptr, ReplySizeInBytes);
4075 Reply_Ptr->StdReplyFrame.StdMessageFrame.InitiatorContext
4076 = Message_Ptr->InitiatorContext;
4077 Reply_Ptr->StdReplyFrame.TransactionContext
4078 = ((PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr)->TransactionContext;
4079 I2O_MESSAGE_FRAME_setMsgFlags(
4080 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
4081 I2O_MESSAGE_FRAME_getMsgFlags(
4082 &(Reply_Ptr->StdReplyFrame.StdMessageFrame))
4083 | I2O_MESSAGE_FLAGS_REPLY);
4085 /* Check if the message is a special case command */
4086 switch (I2O_MESSAGE_FRAME_getFunction(Message_Ptr)) {
4087 case I2O_EXEC_SYS_TAB_SET: /* Special Case of empty Scatter Gather */
4088 if (MessageSizeInBytes == ((I2O_MESSAGE_FRAME_getVersionOffset(
4089 Message_Ptr) & 0xF0) >> 2)) {
4090 free (Message_Ptr, M_TEMP);
4091 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
4092 &(Reply_Ptr->StdReplyFrame),
4093 (ASR_setSysTab(sc) != CAM_REQ_CMP));
4094 I2O_MESSAGE_FRAME_setMessageSize(
4095 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
4096 sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME));
4097 error = copyout ((caddr_t)Reply_Ptr, (caddr_t)Reply,
4099 free (Reply_Ptr, M_TEMP);
4104 /* Deal in the general case */
4105 /* First allocate and optionally copy in each scatter gather element */
4106 SLIST_INIT(&sgList);
4107 if ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0) != 0) {
4108 PI2O_SGE_SIMPLE_ELEMENT sg;
4111 * since this code is reused in several systems, code
4112 * efficiency is greater by using a shift operation rather
4113 * than a divide by sizeof(u_int32_t).
4115 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
4116 + ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0)
4118 while (sg < (PI2O_SGE_SIMPLE_ELEMENT)(((caddr_t)Message_Ptr)
4119 + MessageSizeInBytes)) {
4123 if ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
4124 & I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT) == 0) {
4128 len = I2O_FLAGS_COUNT_getCount(&(sg->FlagsCount));
4129 debug_usr_cmd_printf ("SG[%d] = %x[%d]\n",
4130 sg - (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
4131 + ((I2O_MESSAGE_FRAME_getVersionOffset(
4132 Message_Ptr) & 0xF0) >> 2)),
4133 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg), len);
4135 if ((elm = (struct ioctlSgList_S *)malloc (
4136 sizeof(*elm) - sizeof(elm->KernelSpace) + len,
4138 == (struct ioctlSgList_S *)NULL) {
4139 debug_usr_cmd_printf (
4140 "Failed to allocate SG[%d]\n", len);
4144 SLIST_INSERT_HEAD(&sgList, elm, link);
4145 elm->FlagsCount = sg->FlagsCount;
4146 elm->UserSpace = (caddr_t)
4147 (I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg));
4148 v = elm->KernelSpace;
4149 /* Copy in outgoing data (DIR bit could be invalid) */
4150 if ((error = copyin (elm->UserSpace, (caddr_t)v, len))
4155 * If the buffer is not contiguous, lets
4156 * break up the scatter/gather entries.
4159 && (sg < (PI2O_SGE_SIMPLE_ELEMENT)
4160 (((caddr_t)Message_Ptr) + MAX_INBOUND_SIZE))) {
4161 int next, base, span;
4164 next = base = KVTOPHYS(v);
4165 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg,
4168 /* How far can we go physically contiguously */
4169 while ((len > 0) && (base == next)) {
4172 next = trunc_page(base) + PAGE_SIZE;
4183 /* Construct the Flags */
4184 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount),
4187 int flags = I2O_FLAGS_COUNT_getFlags(
4188 &(elm->FlagsCount));
4189 /* Any remaining length? */
4192 ~(I2O_SGL_FLAGS_END_OF_BUFFER
4193 | I2O_SGL_FLAGS_LAST_ELEMENT);
4195 I2O_FLAGS_COUNT_setFlags(
4196 &(sg->FlagsCount), flags);
4199 debug_usr_cmd_printf ("sg[%d] = %x[%d]\n",
4200 sg - (PI2O_SGE_SIMPLE_ELEMENT)
4201 ((char *)Message_Ptr
4202 + ((I2O_MESSAGE_FRAME_getVersionOffset(
4203 Message_Ptr) & 0xF0) >> 2)),
4204 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg),
4211 * Incrementing requires resizing of the
4212 * packet, and moving up the existing SG
4216 MessageSizeInBytes += sizeof(*sg);
4217 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
4218 I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)
4219 + (sizeof(*sg) / sizeof(U32)));
4221 PI2O_MESSAGE_FRAME NewMessage_Ptr;
4224 = (PI2O_MESSAGE_FRAME)
4225 malloc (MessageSizeInBytes,
4227 == (PI2O_MESSAGE_FRAME)NULL) {
4228 debug_usr_cmd_printf (
4229 "Failed to acquire frame[%d] memory\n",
4230 MessageSizeInBytes);
4234 span = ((caddr_t)sg)
4235 - (caddr_t)Message_Ptr;
4236 bcopy ((caddr_t)Message_Ptr,
4237 (caddr_t)NewMessage_Ptr, span);
4238 bcopy ((caddr_t)(sg-1),
4239 ((caddr_t)NewMessage_Ptr) + span,
4240 MessageSizeInBytes - span);
4241 free (Message_Ptr, M_TEMP);
4242 sg = (PI2O_SGE_SIMPLE_ELEMENT)
4243 (((caddr_t)NewMessage_Ptr) + span);
4244 Message_Ptr = NewMessage_Ptr;
4248 || ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
4249 & I2O_SGL_FLAGS_LAST_ELEMENT) != 0)) {
4255 while ((elm = SLIST_FIRST(&sgList))
4256 != (struct ioctlSgList_S *)NULL) {
4257 SLIST_REMOVE_HEAD(&sgList, link);
4260 free (Reply_Ptr, M_TEMP);
4261 free (Message_Ptr, M_TEMP);
4266 debug_usr_cmd_printf ("Inbound: ");
4267 debug_usr_cmd_dump_message(Message_Ptr);
4269 /* Send the command */
4270 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
4271 /* Free up in-kernel buffers */
4272 while ((elm = SLIST_FIRST(&sgList))
4273 != (struct ioctlSgList_S *)NULL) {
4274 SLIST_REMOVE_HEAD(&sgList, link);
4277 free (Reply_Ptr, M_TEMP);
4278 free (Message_Ptr, M_TEMP);
4283 * We do not need any (optional byteswapping) method access to
4284 * the Initiator context field.
4286 I2O_MESSAGE_FRAME_setInitiatorContext64(
4287 (PI2O_MESSAGE_FRAME)Message_Ptr, (long)ccb);
4289 (void)ASR_queue (sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
4291 free (Message_Ptr, M_TEMP);
4294 * Wait for the board to report a finished instruction.
4297 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
4298 if (ASR_getBlinkLedCode(sc)) {
4300 printf ("asr%d: Blink LED 0x%x resetting adapter\n",
4301 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
4302 ASR_getBlinkLedCode(sc));
4303 if (ASR_reset (sc) == ENXIO) {
4304 /* Command Cleanup */
4305 ASR_ccbRemove(sc, ccb);
4308 /* Free up in-kernel buffers */
4309 while ((elm = SLIST_FIRST(&sgList))
4310 != (struct ioctlSgList_S *)NULL) {
4311 SLIST_REMOVE_HEAD(&sgList, link);
4314 free (Reply_Ptr, M_TEMP);
4318 /* Check every second for BlinkLed */
4319 /* There is no PRICAM, but outwardly PRIBIO is functional */
4320 tsleep((caddr_t)ccb, PRIBIO, "asr", hz);
4324 debug_usr_cmd_printf ("Outbound: ");
4325 debug_usr_cmd_dump_message(Reply_Ptr);
4327 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
4328 &(Reply_Ptr->StdReplyFrame),
4329 (ccb->ccb_h.status != CAM_REQ_CMP));
4331 if (ReplySizeInBytes >= (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4332 - I2O_SCSI_SENSE_DATA_SZ - sizeof(U32))) {
4333 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setTransferCount(Reply_Ptr,
4334 ccb->csio.dxfer_len - ccb->csio.resid);
4336 if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) && (ReplySizeInBytes
4337 > (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4338 - I2O_SCSI_SENSE_DATA_SZ))) {
4339 int size = ReplySizeInBytes
4340 - sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4341 - I2O_SCSI_SENSE_DATA_SZ;
4343 if (size > sizeof(ccb->csio.sense_data)) {
4344 size = sizeof(ccb->csio.sense_data);
4346 bcopy ((caddr_t)&(ccb->csio.sense_data), (caddr_t)Reply_Ptr->SenseData,
4348 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setAutoSenseTransferCount(
4352 /* Free up in-kernel buffers */
4353 while ((elm = SLIST_FIRST(&sgList)) != (struct ioctlSgList_S *)NULL) {
4354 /* Copy out as necessary */
4356 /* DIR bit considered `valid', error due to ignorance works */
4357 && ((I2O_FLAGS_COUNT_getFlags(&(elm->FlagsCount))
4358 & I2O_SGL_FLAGS_DIR) == 0)) {
4359 error = copyout ((caddr_t)(elm->KernelSpace),
4361 I2O_FLAGS_COUNT_getCount(&(elm->FlagsCount)));
4363 SLIST_REMOVE_HEAD(&sgList, link);
4367 /* Copy reply frame to user space */
4368 error = copyout ((caddr_t)Reply_Ptr, (caddr_t)Reply,
4371 free (Reply_Ptr, M_TEMP);
4377 /*----------------------------------------------------------------------*/
4378 /* Function asr_ioctl */
4379 /*----------------------------------------------------------------------*/
4380 /* The parameters passed to this function are : */
4381 /* dev : Device number. */
4382 /* cmd : Ioctl Command */
4383 /* data : User Argument Passed In. */
4384 /* flag : Mode Parameter */
4385 /* proc : Process Parameter */
4387 /* This function is the user interface into this adapter driver */
4389 /* Return : zero if OK, error code if not */
4390 /*----------------------------------------------------------------------*/
4402 Asr_softc_t * sc = ASR_get_sc (dev);
4403 UNREFERENCED_PARAMETER(flag);
4404 UNREFERENCED_PARAMETER(proc);
4406 if (sc != (Asr_softc_t *)NULL)
4410 # if (dsDescription_size != 50)
4411 case DPT_SIGNATURE + ((50 - dsDescription_size) << 16):
4413 if (cmd & 0xFFFF0000) {
4414 (void)bcopy ((caddr_t)(&ASR_sig), data,
4418 /* Traditional version of the ioctl interface */
4419 case DPT_SIGNATURE & 0x0000FFFF:
4420 return (copyout ((caddr_t)(&ASR_sig), *((caddr_t *)data),
4421 sizeof(dpt_sig_S)));
4423 /* Traditional version of the ioctl interface */
4424 case DPT_CTRLINFO & 0x0000FFFF:
4425 case DPT_CTRLINFO: {
4428 u_int16_t drvrHBAnum;
4430 u_int16_t blinkState;
4432 u_int8_t pciDeviceNum;
4434 u_int16_t Interrupt;
4435 u_int32_t reserved1;
4436 u_int32_t reserved2;
4437 u_int32_t reserved3;
4440 bzero (&CtlrInfo, sizeof(CtlrInfo));
4441 CtlrInfo.length = sizeof(CtlrInfo) - sizeof(u_int16_t);
4442 CtlrInfo.drvrHBAnum = asr_unit(dev);
4443 CtlrInfo.baseAddr = (u_long)sc->ha_Base;
4444 i = ASR_getBlinkLedCode (sc);
4448 CtlrInfo.blinkState = i;
4449 CtlrInfo.pciBusNum = sc->ha_pciBusNum;
4450 CtlrInfo.pciDeviceNum = sc->ha_pciDeviceNum;
4451 #define FLG_OSD_PCI_VALID 0x0001
4452 #define FLG_OSD_DMA 0x0002
4453 #define FLG_OSD_I2O 0x0004
4454 CtlrInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
4455 CtlrInfo.Interrupt = sc->ha_irq;
4456 if (cmd & 0xFFFF0000) {
4457 bcopy (&CtlrInfo, data, sizeof(CtlrInfo));
4459 error = copyout (&CtlrInfo, *(caddr_t *)data, sizeof(CtlrInfo));
4463 /* Traditional version of the ioctl interface */
4464 case DPT_SYSINFO & 0x0000FFFF:
4468 /* Kernel Specific ptok `hack' */
4469 # define ptok(a) ((char *)(a) + KERNBASE)
4471 bzero (&Info, sizeof(Info));
4473 /* Appears I am the only person in the Kernel doing this */
4481 Info.drive0CMOS = j;
4488 Info.drive1CMOS = j;
4490 Info.numDrives = *((char *)ptok(0x475));
4492 Info.processorFamily = ASR_sig.dsProcessorFamily;
4494 case CPU_386SX: case CPU_386:
4495 Info.processorType = PROC_386; break;
4496 case CPU_486SX: case CPU_486:
4497 Info.processorType = PROC_486; break;
4499 Info.processorType = PROC_PENTIUM; break;
4501 Info.processorType = PROC_SEXIUM; break;
4503 Info.osType = OS_BSDI_UNIX;
4504 Info.osMajorVersion = osrelease[0] - '0';
4505 Info.osMinorVersion = osrelease[2] - '0';
4506 /* Info.osRevision = 0; */
4507 /* Info.osSubRevision = 0; */
4508 Info.busType = SI_PCI_BUS;
4509 Info.flags = SI_CMOS_Valid | SI_NumDrivesValid
4510 | SI_OSversionValid | SI_BusTypeValid | SI_NO_SmartROM;
4512 /* Go Out And Look For I2O SmartROM */
4513 for(j = 0xC8000; j < 0xE0000; j += 2048) {
4517 if (*((unsigned short *)cp) != 0xAA55) {
4520 j += (cp[2] * 512) - 2048;
4521 if ((*((u_long *)(cp + 6))
4522 != ('S' + (' ' * 256) + (' ' * 65536L)))
4523 || (*((u_long *)(cp + 10))
4524 != ('I' + ('2' * 256) + ('0' * 65536L)))) {
4528 for (k = 0; k < 64; ++k) {
4529 if (*((unsigned short *)cp)
4530 == (' ' + ('v' * 256))) {
4535 Info.smartROMMajorVersion
4536 = *((unsigned char *)(cp += 4)) - '0';
4537 Info.smartROMMinorVersion
4538 = *((unsigned char *)(cp += 2));
4539 Info.smartROMRevision
4540 = *((unsigned char *)(++cp));
4541 Info.flags |= SI_SmartROMverValid;
4542 Info.flags &= ~SI_NO_SmartROM;
4546 /* Get The Conventional Memory Size From CMOS */
4552 Info.conventionalMemSize = j;
4554 /* Get The Extended Memory Found At Power On From CMOS */
4560 Info.extendedMemSize = j;
4561 Info.flags |= SI_MemorySizeValid;
4563 # if (defined(THIS_IS_BROKEN))
4564 /* If There Is 1 or 2 Drives Found, Set Up Drive Parameters */
4565 if (Info.numDrives > 0) {
4567 * Get The Pointer From Int 41 For The First
4570 j = ((unsigned)(*((unsigned short *)ptok(0x104+2))) << 4)
4571 + (unsigned)(*((unsigned short *)ptok(0x104+0)));
4573 * It appears that SmartROM's Int41/Int46 pointers
4574 * use memory that gets stepped on by the kernel
4575 * loading. We no longer have access to this
4576 * geometry information but try anyways (!?)
4578 Info.drives[0].cylinders = *((unsigned char *)ptok(j));
4580 Info.drives[0].cylinders += ((int)*((unsigned char *)
4583 Info.drives[0].heads = *((unsigned char *)ptok(j));
4585 Info.drives[0].sectors = *((unsigned char *)ptok(j));
4586 Info.flags |= SI_DriveParamsValid;
4587 if ((Info.drives[0].cylinders == 0)
4588 || (Info.drives[0].heads == 0)
4589 || (Info.drives[0].sectors == 0)) {
4590 Info.flags &= ~SI_DriveParamsValid;
4592 if (Info.numDrives > 1) {
4594 * Get The Pointer From Int 46 For The
4595 * Second Drive Parameters
4597 j = ((unsigned)(*((unsigned short *)ptok(0x118+2))) << 4)
4598 + (unsigned)(*((unsigned short *)ptok(0x118+0)));
4599 Info.drives[1].cylinders = *((unsigned char *)
4602 Info.drives[1].cylinders += ((int)
4603 *((unsigned char *)ptok(j))) << 8;
4605 Info.drives[1].heads = *((unsigned char *)
4608 Info.drives[1].sectors = *((unsigned char *)
4610 if ((Info.drives[1].cylinders == 0)
4611 || (Info.drives[1].heads == 0)
4612 || (Info.drives[1].sectors == 0)) {
4613 Info.flags &= ~SI_DriveParamsValid;
4618 /* Copy Out The Info Structure To The User */
4619 if (cmd & 0xFFFF0000) {
4620 bcopy (&Info, data, sizeof(Info));
4622 error = copyout (&Info, *(caddr_t *)data, sizeof(Info));
4626 /* Get The BlinkLED State */
4628 i = ASR_getBlinkLedCode (sc);
4632 if (cmd & 0xFFFF0000) {
4633 bcopy ((caddr_t)(&i), data, sizeof(i));
4635 error = copyout (&i, *(caddr_t *)data, sizeof(i));
4639 /* Get performance metrics */
4640 #ifdef ASR_MEASURE_PERFORMANCE
4642 bcopy((caddr_t) &(sc->ha_performance), data,
4643 sizeof(sc->ha_performance));
4647 /* Send an I2O command */
4649 return (ASR_queue_i (sc, *((PI2O_MESSAGE_FRAME *)data)));
4651 /* Reset and re-initialize the adapter */
4653 return (ASR_reset (sc));
4655 /* Rescan the LCT table and resynchronize the information */
4657 return (ASR_rescan (sc));
4662 #ifdef ASR_MEASURE_PERFORMANCE
4664 * This function subtracts one timeval structure from another,
4665 * Returning the result in usec.
4666 * It assumes that less than 4 billion usecs passed form start to end.
4667 * If times are sensless, 0xffffffff is returned.
4672 IN struct timeval start,
4673 IN struct timeval end)
4675 OUT u_int32_t result;
4677 if (start.tv_sec > end.tv_sec) {
4678 result = 0xffffffff;
4681 if (start.tv_sec == end.tv_sec) {
4682 if (start.tv_usec > end.tv_usec) {
4683 result = 0xffffffff;
4685 return (end.tv_usec - start.tv_usec);
4688 return (end.tv_sec - start.tv_sec) * 1000000 +
4689 end.tv_usec + (1000000 - start.tv_usec);
4693 } /* asr_time_delta */