1 /* $FreeBSD: src/sys/dev/asr/asr.c,v 1.3.2.2 2001/08/23 05:21:29 scottl Exp $ */
2 /* $DragonFly: src/sys/dev/raid/asr/asr.c,v 1.8 2003/07/23 02:30:15 dillon Exp $ */
4 * Copyright (c) 1996-2000 Distributed Processing Technology Corporation
5 * Copyright (c) 2000-2001 Adaptec Corporation
8 * TERMS AND CONDITIONS OF USE
10 * Redistribution and use in source form, with or without modification, are
11 * permitted provided that redistributions of source code must retain the
12 * above copyright notice, this list of conditions and the following disclaimer.
14 * This software is provided `as is' by Adaptec and any express or implied
15 * warranties, including, but not limited to, the implied warranties of
16 * merchantability and fitness for a particular purpose, are disclaimed. In no
17 * event shall Adaptec be liable for any direct, indirect, incidental, special,
18 * exemplary or consequential damages (including, but not limited to,
19 * procurement of substitute goods or services; loss of use, data, or profits;
20 * or business interruptions) however caused and on any theory of liability,
21 * whether in contract, strict liability, or tort (including negligence or
22 * otherwise) arising in any way out of the use of this driver software, even
23 * if advised of the possibility of such damage.
25 * SCSI I2O host adapter driver
27 * V1.08 2001/08/21 Mark_Salyzyn@adaptec.com
28 * - The 2000S and 2005S do not initialize on some machines,
29 * increased timeout to 255ms from 50ms for the StatusGet
31 * V1.07 2001/05/22 Mark_Salyzyn@adaptec.com
32 * - I knew this one was too good to be true. The error return
33 * on ioctl commands needs to be compared to CAM_REQ_CMP, not
34 * to the bit masked status.
35 * V1.06 2001/05/08 Mark_Salyzyn@adaptec.com
36 * - The 2005S that was supported is affectionately called the
37 * Conjoined BAR Firmware. In order to support RAID-5 in a
38 * 16MB low-cost configuration, Firmware was forced to go
39 * to a Split BAR Firmware. This requires a separate IOP and
40 * Messaging base address.
41 * V1.05 2001/04/25 Mark_Salyzyn@adaptec.com
42 * - Handle support for 2005S Zero Channel RAID solution.
43 * - System locked up if the Adapter locked up. Do not try
44 * to send other commands if the resetIOP command fails. The
45 * fail outstanding command discovery loop was flawed as the
46 * removal of the command from the list prevented discovering
48 * - Comment changes to clarify driver.
49 * - SysInfo searched for an EATA SmartROM, not an I2O SmartROM.
50 * - We do not use the AC_FOUND_DEV event because of I2O.
52 * V1.04 2000/09/22 Mark_Salyzyn@adaptec.com, msmith@freebsd.org,
53 * lampa@fee.vutbr.cz and Scott_Long@adaptec.com.
54 * - Removed support for PM1554, PM2554 and PM2654 in Mode-0
55 * mode as this is confused with competitor adapters in run
57 * - critical locking needed in ASR_ccbAdd and ASR_ccbRemove
58 * to prevent operating system panic.
59 * - moved default major number to 154 from 97.
60 * V1.03 2000/07/12 Mark_Salyzyn@adaptec.com
61 * - The controller is not actually an ASR (Adaptec SCSI RAID)
62 * series that is visible, it's more of an internal code name.
63 * remove any visible references within reason for now.
64 * - bus_ptr->LUN was not correctly zeroed when initially
65 * allocated causing a possible panic of the operating system
67 * V1.02 2000/06/26 Mark_Salyzyn@adaptec.com
68 * - Code always fails for ASR_getTid affecting performance.
69 * - initiated a set of changes that resulted from a formal
70 * code inspection by Mark_Salyzyn@adaptec.com,
71 * George_Dake@adaptec.com, Jeff_Zeak@adaptec.com,
72 * Martin_Wilson@adaptec.com and Vincent_Trandoan@adaptec.com.
73 * Their findings were focussed on the LCT & TID handler, and
74 * all resulting changes were to improve code readability,
75 * consistency or have a positive effect on performance.
76 * V1.01 2000/06/14 Mark_Salyzyn@adaptec.com
77 * - Passthrough returned an incorrect error.
78 * - Passthrough did not migrate the intrinsic scsi layer wakeup
79 * on command completion.
80 * - generate control device nodes using make_dev and delete_dev.
81 * - Performance affected by TID caching reallocing.
82 * - Made suggested changes by Justin_Gibbs@adaptec.com
83 * - use splcam instead of splbio.
84 * - use cam_imask instead of bio_imask.
85 * - use u_int8_t instead of u_char.
86 * - use u_int16_t instead of u_short.
87 * - use u_int32_t instead of u_long where appropriate.
88 * - use 64 bit context handler instead of 32 bit.
89 * - create_ccb should only allocate the worst case
90 * requirements for the driver since CAM may evolve
91 * making union ccb much larger than needed here.
92 * renamed create_ccb to asr_alloc_ccb.
93 * - go nutz justifying all debug prints as macros
94 * defined at the top and remove unsightly ifdefs.
95 * - INLINE STATIC viewed as confusing. Historically
96 * utilized to affect code performance and debug
97 * issues in OS, Compiler or OEM specific situations.
98 * V1.00 2000/05/31 Mark_Salyzyn@adaptec.com
99 * - Ported from FreeBSD 2.2.X DPT I2O driver.
100 * changed struct scsi_xfer to union ccb/struct ccb_hdr
101 * changed variable name xs to ccb
102 * changed struct scsi_link to struct cam_path
103 * changed struct scsibus_data to struct cam_sim
104 * stopped using fordriver for holding on to the TID
105 * use proprietary packet creation instead of scsi_inquire
106 * CAM layer sends synchronize commands.
109 #define ASR_VERSION 1
110 #define ASR_REVISION '0'
111 #define ASR_SUBREVISION '8'
114 #define ASR_YEAR 2001 - 1980
117 * Debug macros to reduce the unsightly ifdefs
119 #if (defined(DEBUG_ASR) || defined(DEBUG_ASR_USR_CMD) || defined(DEBUG_ASR_CMD))
120 # define debug_asr_message(message) \
122 u_int32_t * pointer = (u_int32_t *)message; \
123 u_int32_t length = I2O_MESSAGE_FRAME_getMessageSize(message);\
124 u_int32_t counter = 0; \
127 printf ("%08lx%c", (u_long)*(pointer++), \
128 (((++counter & 7) == 0) || (length == 0)) \
133 #endif /* DEBUG_ASR || DEBUG_ASR_USR_CMD || DEBUG_ASR_CMD */
135 #if (defined(DEBUG_ASR))
136 /* Breaks on none STDC based compilers :-( */
137 # define debug_asr_printf(fmt,args...) printf(fmt, ##args)
138 # define debug_asr_dump_message(message) debug_asr_message(message)
139 # define debug_asr_print_path(ccb) xpt_print_path(ccb->ccb_h.path);
140 /* None fatal version of the ASSERT macro */
141 # if (defined(__STDC__))
142 # define ASSERT(phrase) if(!(phrase))printf(#phrase " at line %d file %s\n",__LINE__,__FILE__)
144 # define ASSERT(phrase) if(!(phrase))printf("phrase" " at line %d file %s\n",__LINE__,__FILE__)
146 #else /* DEBUG_ASR */
147 # define debug_asr_printf(fmt,args...)
148 # define debug_asr_dump_message(message)
149 # define debug_asr_print_path(ccb)
151 #endif /* DEBUG_ASR */
154 * If DEBUG_ASR_CMD is defined:
155 * 0 - Display incoming SCSI commands
156 * 1 - add in a quick character before queueing.
157 * 2 - add in outgoing message frames.
159 #if (defined(DEBUG_ASR_CMD))
160 # define debug_asr_cmd_printf(fmt,args...) printf(fmt,##args)
161 # define debug_asr_dump_ccb(ccb) \
163 u_int8_t * cp = (unsigned char *)&(ccb->csio.cdb_io); \
164 int len = ccb->csio.cdb_len; \
167 debug_asr_cmd_printf (" %02x", *(cp++)); \
171 # if (DEBUG_ASR_CMD > 0)
172 # define debug_asr_cmd1_printf debug_asr_cmd_printf
174 # define debug_asr_cmd1_printf(fmt,args...)
176 # if (DEBUG_ASR_CMD > 1)
177 # define debug_asr_cmd2_printf debug_asr_cmd_printf
178 # define debug_asr_cmd2_dump_message(message) debug_asr_message(message)
180 # define debug_asr_cmd2_printf(fmt,args...)
181 # define debug_asr_cmd2_dump_message(message)
183 #else /* DEBUG_ASR_CMD */
184 # define debug_asr_cmd_printf(fmt,args...)
185 # define debug_asr_cmd_dump_ccb(ccb)
186 # define debug_asr_cmd1_printf(fmt,args...)
187 # define debug_asr_cmd2_printf(fmt,args...)
188 # define debug_asr_cmd2_dump_message(message)
189 #endif /* DEBUG_ASR_CMD */
191 #if (defined(DEBUG_ASR_USR_CMD))
192 # define debug_usr_cmd_printf(fmt,args...) printf(fmt,##args)
193 # define debug_usr_cmd_dump_message(message) debug_usr_message(message)
194 #else /* DEBUG_ASR_USR_CMD */
195 # define debug_usr_cmd_printf(fmt,args...)
196 # define debug_usr_cmd_dump_message(message)
197 #endif /* DEBUG_ASR_USR_CMD */
199 #define dsDescription_size 46 /* Snug as a bug in a rug */
200 #include "dev/asr/dptsig.h"
202 static dpt_sig_S ASR_sig = {
203 { 'd', 'P', 't', 'S', 'i', 'G'}, SIG_VERSION, PROC_INTEL,
204 PROC_386 | PROC_486 | PROC_PENTIUM | PROC_SEXIUM, FT_HBADRVR, 0,
205 OEM_DPT, OS_FREE_BSD, CAP_ABOVE16MB, DEV_ALL,
207 0, 0, ASR_VERSION, ASR_REVISION, ASR_SUBREVISION,
208 ASR_MONTH, ASR_DAY, ASR_YEAR,
209 /* 01234567890123456789012345678901234567890123456789 < 50 chars */
210 "Adaptec FreeBSD 4.0.0 Unix SCSI I2O HBA Driver"
211 /* ^^^^^ asr_attach alters these to match OS */
214 #include <sys/param.h> /* TRUE=1 and FALSE=0 defined here */
215 #include <sys/kernel.h>
216 #include <sys/systm.h>
217 #include <sys/malloc.h>
218 #include <sys/proc.h>
219 #include <sys/conf.h>
220 #include <sys/disklabel.h>
222 #include <machine/resource.h>
223 #include <machine/bus.h>
224 #include <sys/rman.h>
225 #include <sys/stat.h>
226 #include <sys/device.h>
229 #include <cam/cam_ccb.h>
230 #include <cam/cam_sim.h>
231 #include <cam/cam_xpt_sim.h>
232 #include <cam/cam_xpt_periph.h>
234 #include <cam/scsi/scsi_all.h>
235 #include <cam/scsi/scsi_message.h>
239 #include <machine/cputypes.h>
240 #include <machine/clock.h>
241 #include <i386/include/vmparam.h>
243 #include <pci/pcivar.h>
244 #include <pci/pcireg.h>
246 #define STATIC static
249 #if (defined(DEBUG_ASR) && (DEBUG_ASR > 0))
259 #define osdSwap4(x) ((u_long)ntohl((u_long)(x)))
260 #define KVTOPHYS(x) vtophys(x)
261 #include "dev/asr/dptalign.h"
262 #include "dev/asr/i2oexec.h"
263 #include "dev/asr/i2obscsi.h"
264 #include "dev/asr/i2odpt.h"
265 #include "dev/asr/i2oadptr.h"
268 #include "dev/asr/sys_info.h"
270 /* Configuration Definitions */
272 #define SG_SIZE 58 /* Scatter Gather list Size */
273 #define MAX_TARGET_ID 126 /* Maximum Target ID supported */
274 #define MAX_LUN 255 /* Maximum LUN Supported */
275 #define MAX_CHANNEL 7 /* Maximum Channel # Supported by driver */
276 #define MAX_INBOUND 2000 /* Max CCBs, Also Max Queue Size */
277 #define MAX_OUTBOUND 256 /* Maximum outbound frames/adapter */
278 #define MAX_INBOUND_SIZE 512 /* Maximum inbound frame size */
279 #define MAX_MAP 4194304L /* Maximum mapping size of IOP */
280 /* Also serves as the minimum map for */
281 /* the 2005S zero channel RAID product */
283 /**************************************************************************
284 ** ASR Host Adapter structure - One Structure For Each Host Adapter That **
285 ** Is Configured Into The System. The Structure Supplies Configuration **
286 ** Information, Status Info, Queue Info And An Active CCB List Pointer. **
287 ***************************************************************************/
289 /* I2O register set */
294 # define Mask_InterruptsDisabled 0x08
296 volatile U32 ToFIFO; /* In Bound FIFO */
297 volatile U32 FromFIFO; /* Out Bound FIFO */
301 * A MIX of performance and space considerations for TID lookups
303 typedef u_int16_t tid_t;
306 u_int32_t size; /* up to MAX_LUN */
311 u_int32_t size; /* up to MAX_TARGET */
316 * To ensure that we only allocate and use the worst case ccb here, lets
317 * make our own local ccb union. If asr_alloc_ccb is utilized for another
318 * ccb type, ensure that you add the additional structures into our local
319 * ccb union. To ensure strict type checking, we will utilize the local
320 * ccb definition wherever possible.
323 struct ccb_hdr ccb_h; /* For convenience */
324 struct ccb_scsiio csio;
325 struct ccb_setasync csa;
328 typedef struct Asr_softc {
330 void * ha_Base; /* base port for each board */
331 u_int8_t * volatile ha_blinkLED;
332 i2oRegs_t * ha_Virt; /* Base address of IOP */
333 U8 * ha_Fvirt; /* Base address of Frames */
334 I2O_IOP_ENTRY ha_SystemTable;
335 LIST_HEAD(,ccb_hdr) ha_ccb; /* ccbs in use */
336 struct cam_path * ha_path[MAX_CHANNEL+1];
337 struct cam_sim * ha_sim[MAX_CHANNEL+1];
338 #if __FreeBSD_version >= 400000
339 struct resource * ha_mem_res;
340 struct resource * ha_mes_res;
341 struct resource * ha_irq_res;
344 PI2O_LCT ha_LCT; /* Complete list of devices */
345 # define le_type IdentityTag[0]
346 # define I2O_BSA 0x20
347 # define I2O_FCA 0x40
348 # define I2O_SCSI 0x00
349 # define I2O_PORT 0x80
350 # define I2O_UNKNOWN 0x7F
351 # define le_bus IdentityTag[1]
352 # define le_target IdentityTag[2]
353 # define le_lun IdentityTag[3]
354 target2lun_t * ha_targets[MAX_CHANNEL+1];
355 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME ha_Msgs;
358 u_int8_t ha_in_reset;
359 # define HA_OPERATIONAL 0
360 # define HA_IN_RESET 1
361 # define HA_OFF_LINE 2
362 # define HA_OFF_LINE_RECOVERY 3
363 /* Configuration information */
364 /* The target id maximums we take */
365 u_int8_t ha_MaxBus; /* Maximum bus */
366 u_int8_t ha_MaxId; /* Maximum target ID */
367 u_int8_t ha_MaxLun; /* Maximum target LUN */
368 u_int8_t ha_SgSize; /* Max SG elements */
369 u_int8_t ha_pciBusNum;
370 u_int8_t ha_pciDeviceNum;
371 u_int8_t ha_adapter_target[MAX_CHANNEL+1];
372 u_int16_t ha_QueueSize; /* Max outstanding commands */
373 u_int16_t ha_Msgs_Count;
375 /* Links into other parents and HBAs */
376 struct Asr_softc * ha_next; /* HBA list */
378 #ifdef ASR_MEASURE_PERFORMANCE
379 #define MAX_TIMEQ_SIZE 256 // assumes MAX 256 scsi commands sent
380 asr_perf_t ha_performance;
381 u_int32_t ha_submitted_ccbs_count;
383 // Queueing macros for a circular queue
384 #define TIMEQ_FREE_LIST_EMPTY(head, tail) (-1 == (head) && -1 == (tail))
385 #define TIMEQ_FREE_LIST_FULL(head, tail) ((((tail) + 1) % MAX_TIMEQ_SIZE) == (head))
386 #define ENQ_TIMEQ_FREE_LIST(item, Q, head, tail) \
387 if (!TIMEQ_FREE_LIST_FULL((head), (tail))) { \
388 if TIMEQ_FREE_LIST_EMPTY((head),(tail)) { \
389 (head) = (tail) = 0; \
391 else (tail) = ((tail) + 1) % MAX_TIMEQ_SIZE; \
392 Q[(tail)] = (item); \
395 debug_asr_printf("asr: Enqueueing when TimeQ Free List is full... This should not happen!\n"); \
397 #define DEQ_TIMEQ_FREE_LIST(item, Q, head, tail) \
398 if (!TIMEQ_FREE_LIST_EMPTY((head), (tail))) { \
400 if ((head) == (tail)) { (head) = (tail) = -1; } \
401 else (head) = ((head) + 1) % MAX_TIMEQ_SIZE; \
405 debug_asr_printf("asr: Dequeueing when TimeQ Free List is empty... This should not happen!\n"); \
408 // Circular queue of time stamps
409 struct timeval ha_timeQ[MAX_TIMEQ_SIZE];
410 u_int32_t ha_timeQFreeList[MAX_TIMEQ_SIZE];
411 int ha_timeQFreeHead;
412 int ha_timeQFreeTail;
416 STATIC Asr_softc_t * Asr_softc;
419 * Prototypes of the routines we have in this object.
422 /* Externally callable routines */
423 #if __FreeBSD_version >= 400000
424 #define PROBE_ARGS IN device_t tag
425 #define PROBE_RET int
426 #define PROBE_SET() u_long id = (pci_get_device(tag)<<16)|pci_get_vendor(tag)
427 #define PROBE_RETURN(retval) if(retval){device_set_desc(tag,retval);return(0);}else{return(ENXIO);}
428 #define ATTACH_ARGS IN device_t tag
429 #define ATTACH_RET int
430 #define ATTACH_SET() int unit = device_get_unit(tag)
431 #define ATTACH_RETURN(retval) return(retval)
433 #define PROBE_ARGS IN pcici_t tag, IN pcidi_t id
434 #define PROBE_RET const char *
436 #define PROBE_RETURN(retval) return(retval)
437 #define ATTACH_ARGS IN pcici_t tag, IN int unit
438 #define ATTACH_RET void
440 #define ATTACH_RETURN(retval) return
442 /* I2O HDM interface */
443 STATIC PROBE_RET asr_probe __P((PROBE_ARGS));
444 STATIC ATTACH_RET asr_attach __P((ATTACH_ARGS));
445 /* DOMINO placeholder */
446 STATIC PROBE_RET domino_probe __P((PROBE_ARGS));
447 STATIC ATTACH_RET domino_attach __P((ATTACH_ARGS));
448 /* MODE0 adapter placeholder */
449 STATIC PROBE_RET mode0_probe __P((PROBE_ARGS));
450 STATIC ATTACH_RET mode0_attach __P((ATTACH_ARGS));
452 STATIC Asr_softc_t * ASR_get_sc __P((
454 STATIC int asr_ioctl __P((
460 STATIC int asr_open __P((
465 STATIC int asr_close __P((
470 STATIC int asr_intr __P((
471 IN Asr_softc_t * sc));
472 STATIC void asr_timeout __P((
474 STATIC int ASR_init __P((
475 IN Asr_softc_t * sc));
476 STATIC INLINE int ASR_acquireLct __P((
477 INOUT Asr_softc_t * sc));
478 STATIC INLINE int ASR_acquireHrt __P((
479 INOUT Asr_softc_t * sc));
480 STATIC void asr_action __P((
481 IN struct cam_sim * sim,
482 IN union ccb * ccb));
483 STATIC void asr_poll __P((
484 IN struct cam_sim * sim));
487 * Here is the auto-probe structure used to nest our tests appropriately
488 * during the startup phase of the operating system.
490 #if __FreeBSD_version >= 400000
491 STATIC device_method_t asr_methods[] = {
492 DEVMETHOD(device_probe, asr_probe),
493 DEVMETHOD(device_attach, asr_attach),
497 STATIC driver_t asr_driver = {
503 STATIC devclass_t asr_devclass;
505 DRIVER_MODULE(asr, pci, asr_driver, asr_devclass, 0, 0);
507 STATIC device_method_t domino_methods[] = {
508 DEVMETHOD(device_probe, domino_probe),
509 DEVMETHOD(device_attach, domino_attach),
513 STATIC driver_t domino_driver = {
519 STATIC devclass_t domino_devclass;
521 DRIVER_MODULE(domino, pci, domino_driver, domino_devclass, 0, 0);
523 STATIC device_method_t mode0_methods[] = {
524 DEVMETHOD(device_probe, mode0_probe),
525 DEVMETHOD(device_attach, mode0_attach),
529 STATIC driver_t mode0_driver = {
535 STATIC devclass_t mode0_devclass;
537 DRIVER_MODULE(mode0, pci, mode0_driver, mode0_devclass, 0, 0);
539 STATIC u_long asr_pcicount = 0;
540 STATIC struct pci_device asr_pcidev = {
547 DATA_SET (asr_pciset, asr_pcidev);
549 STATIC u_long domino_pcicount = 0;
550 STATIC struct pci_device domino_pcidev = {
557 DATA_SET (domino_pciset, domino_pcidev);
559 STATIC u_long mode0_pcicount = 0;
560 STATIC struct pci_device mode0_pcidev = {
567 DATA_SET (mode0_pciset, mode0_pcidev);
571 * devsw for asr hba driver
573 * only ioctl is used. the sd driver provides all other access.
575 #define CDEV_MAJOR 154 /* prefered default character major */
576 STATIC struct cdevsw asr_cdevsw = {
578 CDEV_MAJOR, /* maj */
584 asr_close, /* close */
587 asr_ioctl, /* ioctl */
590 nostrategy, /* strategy */
595 #ifdef ASR_MEASURE_PERFORMANCE
596 STATIC u_int32_t asr_time_delta __P((IN struct timeval start,
597 IN struct timeval end));
601 * Initialize the dynamic cdevsw hooks.
607 static int asr_devsw_installed = 0;
609 if (asr_devsw_installed) {
612 asr_devsw_installed++;
614 * Find a free spot (the report during driver load used by
615 * osd layer in engine to generate the controlling nodes).
617 while ((asr_cdevsw.d_maj < NUMCDEVSW)
618 && (dev_dport(makedev(asr_cdevsw.d_maj,0)) != NULL)) {
621 if (asr_cdevsw.d_maj >= NUMCDEVSW) for (
622 asr_cdevsw.d_maj = 0;
623 (asr_cdevsw.d_maj < CDEV_MAJOR)
624 && (dev_dport(makedev(asr_cdevsw.d_maj,0)) != NULL);
629 cdevsw_add(&asr_cdevsw);
631 * delete any nodes that would attach to the primary adapter,
632 * let the adapter scans add them.
634 destroy_dev(makedev(asr_cdevsw.d_maj,0));
637 /* Must initialize before CAM layer picks up our HBA driver */
638 SYSINIT(asrdev,SI_SUB_DRIVERS,SI_ORDER_MIDDLE+CDEV_MAJOR,asr_drvinit,NULL)
640 /* I2O support routines */
641 #define defAlignLong(STRUCT,NAME) char NAME[sizeof(STRUCT)]
642 #define getAlignLong(STRUCT,NAME) ((STRUCT *)(NAME))
645 * Fill message with default.
647 STATIC PI2O_MESSAGE_FRAME
652 OUT PI2O_MESSAGE_FRAME Message_Ptr;
654 Message_Ptr = getAlignLong(I2O_MESSAGE_FRAME, Message);
655 bzero ((void *)Message_Ptr, size);
656 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11);
657 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
658 (size + sizeof(U32) - 1) >> 2);
659 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
660 return (Message_Ptr);
661 } /* ASR_fillMessage */
663 #define EMPTY_QUEUE ((U32)-1L)
669 OUT U32 MessageOffset;
671 if ((MessageOffset = virt->ToFIFO) == EMPTY_QUEUE) {
672 MessageOffset = virt->ToFIFO;
674 return (MessageOffset);
675 } /* ASR_getMessage */
677 /* Issue a polled command */
680 INOUT i2oRegs_t * virt,
682 IN PI2O_MESSAGE_FRAME Message)
689 * ASR_initiateCp is only used for synchronous commands and will
690 * be made more resiliant to adapter delays since commands like
691 * resetIOP can cause the adapter to be deaf for a little time.
693 while (((MessageOffset = ASR_getMessage(virt)) == EMPTY_QUEUE)
697 if (MessageOffset != EMPTY_QUEUE) {
698 bcopy (Message, fvirt + MessageOffset,
699 I2O_MESSAGE_FRAME_getMessageSize(Message) << 2);
701 * Disable the Interrupts
703 virt->Mask = (Mask = virt->Mask) | Mask_InterruptsDisabled;
704 virt->ToFIFO = MessageOffset;
707 } /* ASR_initiateCp */
714 INOUT i2oRegs_t * virt,
717 struct resetMessage {
718 I2O_EXEC_IOP_RESET_MESSAGE M;
721 defAlignLong(struct resetMessage,Message);
722 PI2O_EXEC_IOP_RESET_MESSAGE Message_Ptr;
723 OUT U32 * volatile Reply_Ptr;
727 * Build up our copy of the Message.
729 Message_Ptr = (PI2O_EXEC_IOP_RESET_MESSAGE)ASR_fillMessage(Message,
730 sizeof(I2O_EXEC_IOP_RESET_MESSAGE));
731 I2O_EXEC_IOP_RESET_MESSAGE_setFunction(Message_Ptr, I2O_EXEC_IOP_RESET);
733 * Reset the Reply Status
735 *(Reply_Ptr = (U32 *)((char *)Message_Ptr
736 + sizeof(I2O_EXEC_IOP_RESET_MESSAGE))) = 0;
737 I2O_EXEC_IOP_RESET_MESSAGE_setStatusWordLowAddress(Message_Ptr,
738 KVTOPHYS((void *)Reply_Ptr));
740 * Send the Message out
742 if ((Old = ASR_initiateCp (virt, fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
744 * Wait for a response (Poll), timeouts are dangerous if
745 * the card is truly responsive. We assume response in 2s.
747 u_int8_t Delay = 200;
749 while ((*Reply_Ptr == 0) && (--Delay != 0)) {
753 * Re-enable the interrupts.
759 ASSERT (Old != (U32)-1L);
764 * Get the curent state of the adapter
766 STATIC INLINE PI2O_EXEC_STATUS_GET_REPLY
768 INOUT i2oRegs_t * virt,
770 OUT PI2O_EXEC_STATUS_GET_REPLY buffer)
772 defAlignLong(I2O_EXEC_STATUS_GET_MESSAGE,Message);
773 PI2O_EXEC_STATUS_GET_MESSAGE Message_Ptr;
777 * Build up our copy of the Message.
779 Message_Ptr = (PI2O_EXEC_STATUS_GET_MESSAGE)ASR_fillMessage(Message,
780 sizeof(I2O_EXEC_STATUS_GET_MESSAGE));
781 I2O_EXEC_STATUS_GET_MESSAGE_setFunction(Message_Ptr,
782 I2O_EXEC_STATUS_GET);
783 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferAddressLow(Message_Ptr,
784 KVTOPHYS((void *)buffer));
785 /* This one is a Byte Count */
786 I2O_EXEC_STATUS_GET_MESSAGE_setReplyBufferLength(Message_Ptr,
787 sizeof(I2O_EXEC_STATUS_GET_REPLY));
789 * Reset the Reply Status
791 bzero ((void *)buffer, sizeof(I2O_EXEC_STATUS_GET_REPLY));
793 * Send the Message out
795 if ((Old = ASR_initiateCp (virt, fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
797 * Wait for a response (Poll), timeouts are dangerous if
798 * the card is truly responsive. We assume response in 50ms.
800 u_int8_t Delay = 255;
802 while (*((U8 * volatile)&(buffer->SyncByte)) == 0) {
804 buffer = (PI2O_EXEC_STATUS_GET_REPLY)NULL;
810 * Re-enable the interrupts.
815 return ((PI2O_EXEC_STATUS_GET_REPLY)NULL);
816 } /* ASR_getStatus */
819 * Check if the device is a SCSI I2O HBA, and add it to the list.
823 * Probe for ASR controller. If we find it, we will use it.
827 asr_probe(PROBE_ARGS)
830 if ((id == 0xA5011044) || (id == 0xA5111044)) {
831 PROBE_RETURN ("Adaptec Caching SCSI RAID");
837 * Probe/Attach for DOMINO chipset.
840 domino_probe(PROBE_ARGS)
843 if (id == 0x10121044) {
844 PROBE_RETURN ("Adaptec Caching Memory Controller");
850 domino_attach (ATTACH_ARGS)
853 } /* domino_attach */
856 * Probe/Attach for MODE0 adapters.
859 mode0_probe(PROBE_ARGS)
864 * If/When we can get a business case to commit to a
865 * Mode0 driver here, we can make all these tests more
866 * specific and robust. Mode0 adapters have their processors
867 * turned off, this the chips are in a raw state.
870 /* This is a PLX9054 */
871 if (id == 0x905410B5) {
872 PROBE_RETURN ("Adaptec Mode0 PM3757");
874 /* This is a PLX9080 */
875 if (id == 0x908010B5) {
876 PROBE_RETURN ("Adaptec Mode0 PM3754/PM3755");
878 /* This is a ZION 80303 */
879 if (id == 0x53098086) {
880 PROBE_RETURN ("Adaptec Mode0 3010S");
882 /* This is an i960RS */
883 if (id == 0x39628086) {
884 PROBE_RETURN ("Adaptec Mode0 2100S");
886 /* This is an i960RN */
887 if (id == 0x19648086) {
888 PROBE_RETURN ("Adaptec Mode0 PM2865/2400A/3200S/3400S");
890 #if 0 /* this would match any generic i960 -- mjs */
891 /* This is an i960RP (typically also on Motherboards) */
892 if (id == 0x19608086) {
893 PROBE_RETURN ("Adaptec Mode0 PM2554/PM1554/PM2654");
900 mode0_attach (ATTACH_ARGS)
905 STATIC INLINE union asr_ccb *
909 OUT union asr_ccb * new_ccb;
911 if ((new_ccb = (union asr_ccb *)malloc(sizeof(*new_ccb),
912 M_DEVBUF, M_WAITOK)) != (union asr_ccb *)NULL) {
913 bzero (new_ccb, sizeof(*new_ccb));
914 new_ccb->ccb_h.pinfo.priority = 1;
915 new_ccb->ccb_h.pinfo.index = CAM_UNQUEUED_INDEX;
916 new_ccb->ccb_h.spriv_ptr0 = sc;
919 } /* asr_alloc_ccb */
923 IN union asr_ccb * free_ccb)
925 free(free_ccb, M_DEVBUF);
929 * Print inquiry data `carefully'
936 while ((--len >= 0) && (*s) && (*s != ' ') && (*s != '-')) {
937 printf ("%c", *(s++));
944 STATIC INLINE int ASR_queue __P((
946 IN PI2O_MESSAGE_FRAME Message));
948 * Send a message synchronously and without Interrupt to a ccb.
952 INOUT union asr_ccb * ccb,
953 IN PI2O_MESSAGE_FRAME Message)
957 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
960 * We do not need any (optional byteswapping) method access to
961 * the Initiator context field.
963 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
965 /* Prevent interrupt service */
967 sc->ha_Virt->Mask = (Mask = sc->ha_Virt->Mask)
968 | Mask_InterruptsDisabled;
970 if (ASR_queue (sc, Message) == EMPTY_QUEUE) {
971 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
972 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
976 * Wait for this board to report a finished instruction.
978 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
982 /* Re-enable Interrupts */
983 sc->ha_Virt->Mask = Mask;
986 return (ccb->ccb_h.status);
990 * Send a message synchronously to a Asr_softc_t
995 IN PI2O_MESSAGE_FRAME Message)
1000 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
1001 return (CAM_REQUEUE_REQ);
1004 status = ASR_queue_s (ccb, Message);
1012 * Add the specified ccb to the active queue
1016 IN Asr_softc_t * sc,
1017 INOUT union asr_ccb * ccb)
1022 LIST_INSERT_HEAD(&(sc->ha_ccb), &(ccb->ccb_h), sim_links.le);
1023 if (ccb->ccb_h.timeout != CAM_TIME_INFINITY) {
1024 if (ccb->ccb_h.timeout == CAM_TIME_DEFAULT) {
1026 * RAID systems can take considerable time to
1027 * complete some commands given the large cache
1028 * flashes switching from write back to write thru.
1030 ccb->ccb_h.timeout = 6 * 60 * 1000;
1032 ccb->ccb_h.timeout_ch = timeout(asr_timeout, (caddr_t)ccb,
1033 (ccb->ccb_h.timeout * hz) / 1000);
1039 * Remove the specified ccb from the active queue.
1043 IN Asr_softc_t * sc,
1044 INOUT union asr_ccb * ccb)
1049 untimeout(asr_timeout, (caddr_t)ccb, ccb->ccb_h.timeout_ch);
1050 LIST_REMOVE(&(ccb->ccb_h), sim_links.le);
1052 } /* ASR_ccbRemove */
1055 * Fail all the active commands, so they get re-issued by the operating
1059 ASR_failActiveCommands (
1060 IN Asr_softc_t * sc)
1062 struct ccb_hdr * ccb;
1065 #if 0 /* Currently handled by callers, unnecessary paranoia currently */
1066 /* Left in for historical perspective. */
1067 defAlignLong(I2O_EXEC_LCT_NOTIFY_MESSAGE,Message);
1068 PI2O_EXEC_LCT_NOTIFY_MESSAGE Message_Ptr;
1070 /* Send a blind LCT command to wait for the enableSys to complete */
1071 Message_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)ASR_fillMessage(Message,
1072 sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) - sizeof(I2O_SG_ELEMENT));
1073 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1074 I2O_EXEC_LCT_NOTIFY);
1075 I2O_EXEC_LCT_NOTIFY_MESSAGE_setClassIdentifier(Message_Ptr,
1076 I2O_CLASS_MATCH_ANYCLASS);
1077 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1082 * We do not need to inform the CAM layer that we had a bus
1083 * reset since we manage it on our own, this also prevents the
1084 * SCSI_DELAY settling that would be required on other systems.
1085 * The `SCSI_DELAY' has already been handled by the card via the
1086 * acquisition of the LCT table while we are at CAM priority level.
1087 * for (int bus = 0; bus <= sc->ha_MaxBus; ++bus) {
1088 * xpt_async (AC_BUS_RESET, sc->ha_path[bus], NULL);
1091 while ((ccb = LIST_FIRST(&(sc->ha_ccb))) != (struct ccb_hdr *)NULL) {
1092 ASR_ccbRemove (sc, (union asr_ccb *)ccb);
1094 ccb->status &= ~CAM_STATUS_MASK;
1095 ccb->status |= CAM_REQUEUE_REQ;
1096 /* Nothing Transfered */
1097 ((struct ccb_scsiio *)ccb)->resid
1098 = ((struct ccb_scsiio *)ccb)->dxfer_len;
1101 xpt_done ((union ccb *)ccb);
1103 wakeup ((caddr_t)ccb);
1107 } /* ASR_failActiveCommands */
1110 * The following command causes the HBA to reset the specific bus
1114 IN Asr_softc_t * sc,
1117 defAlignLong(I2O_HBA_BUS_RESET_MESSAGE,Message);
1118 I2O_HBA_BUS_RESET_MESSAGE * Message_Ptr;
1119 PI2O_LCT_ENTRY Device;
1121 Message_Ptr = (I2O_HBA_BUS_RESET_MESSAGE *)ASR_fillMessage(Message,
1122 sizeof(I2O_HBA_BUS_RESET_MESSAGE));
1123 I2O_MESSAGE_FRAME_setFunction(&Message_Ptr->StdMessageFrame,
1125 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
1126 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
1128 if (((Device->le_type & I2O_PORT) != 0)
1129 && (Device->le_bus == bus)) {
1130 I2O_MESSAGE_FRAME_setTargetAddress(
1131 &Message_Ptr->StdMessageFrame,
1132 I2O_LCT_ENTRY_getLocalTID(Device));
1133 /* Asynchronous command, with no expectations */
1134 (void)ASR_queue(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1138 } /* ASR_resetBus */
1141 ASR_getBlinkLedCode (
1142 IN Asr_softc_t * sc)
1144 if ((sc != (Asr_softc_t *)NULL)
1145 && (sc->ha_blinkLED != (u_int8_t *)NULL)
1146 && (sc->ha_blinkLED[1] == 0xBC)) {
1147 return (sc->ha_blinkLED[0]);
1150 } /* ASR_getBlinkCode */
1153 * Determine the address of an TID lookup. Must be done at high priority
1154 * since the address can be changed by other threads of execution.
1156 * Returns NULL pointer if not indexible (but will attempt to generate
1157 * an index if `new_entry' flag is set to TRUE).
1159 * All addressible entries are to be guaranteed zero if never initialized.
1161 STATIC INLINE tid_t *
1163 INOUT Asr_softc_t * sc,
1169 target2lun_t * bus_ptr;
1170 lun2tid_t * target_ptr;
1174 * Validity checking of incoming parameters. More of a bound
1175 * expansion limit than an issue with the code dealing with the
1178 * sc must be valid before it gets here, so that check could be
1179 * dropped if speed a critical issue.
1181 if ((sc == (Asr_softc_t *)NULL)
1182 || (bus > MAX_CHANNEL)
1183 || (target > sc->ha_MaxId)
1184 || (lun > sc->ha_MaxLun)) {
1185 debug_asr_printf("(%lx,%d,%d,%d) target out of range\n",
1186 (u_long)sc, bus, target, lun);
1187 return ((tid_t *)NULL);
1190 * See if there is an associated bus list.
1192 * for performance, allocate in size of BUS_CHUNK chunks.
1193 * BUS_CHUNK must be a power of two. This is to reduce
1194 * fragmentation effects on the allocations.
1196 # define BUS_CHUNK 8
1197 new_size = ((target + BUS_CHUNK - 1) & ~(BUS_CHUNK - 1));
1198 if ((bus_ptr = sc->ha_targets[bus]) == (target2lun_t *)NULL) {
1200 * Allocate a new structure?
1201 * Since one element in structure, the +1
1202 * needed for size has been abstracted.
1204 if ((new_entry == FALSE)
1205 || ((sc->ha_targets[bus] = bus_ptr = (target2lun_t *)malloc (
1206 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
1208 == (target2lun_t *)NULL)) {
1209 debug_asr_printf("failed to allocate bus list\n");
1210 return ((tid_t *)NULL);
1212 bzero (bus_ptr, sizeof(*bus_ptr)
1213 + (sizeof(bus_ptr->LUN) * new_size));
1214 bus_ptr->size = new_size + 1;
1215 } else if (bus_ptr->size <= new_size) {
1216 target2lun_t * new_bus_ptr;
1219 * Reallocate a new structure?
1220 * Since one element in structure, the +1
1221 * needed for size has been abstracted.
1223 if ((new_entry == FALSE)
1224 || ((new_bus_ptr = (target2lun_t *)malloc (
1225 sizeof(*bus_ptr) + (sizeof(bus_ptr->LUN) * new_size),
1227 == (target2lun_t *)NULL)) {
1228 debug_asr_printf("failed to reallocate bus list\n");
1229 return ((tid_t *)NULL);
1232 * Zero and copy the whole thing, safer, simpler coding
1233 * and not really performance critical at this point.
1235 bzero (new_bus_ptr, sizeof(*bus_ptr)
1236 + (sizeof(bus_ptr->LUN) * new_size));
1237 bcopy (bus_ptr, new_bus_ptr, sizeof(*bus_ptr)
1238 + (sizeof(bus_ptr->LUN) * (bus_ptr->size - 1)));
1239 sc->ha_targets[bus] = new_bus_ptr;
1240 free (bus_ptr, M_TEMP);
1241 bus_ptr = new_bus_ptr;
1242 bus_ptr->size = new_size + 1;
1245 * We now have the bus list, lets get to the target list.
1246 * Since most systems have only *one* lun, we do not allocate
1247 * in chunks as above, here we allow one, then in chunk sizes.
1248 * TARGET_CHUNK must be a power of two. This is to reduce
1249 * fragmentation effects on the allocations.
1251 # define TARGET_CHUNK 8
1252 if ((new_size = lun) != 0) {
1253 new_size = ((lun + TARGET_CHUNK - 1) & ~(TARGET_CHUNK - 1));
1255 if ((target_ptr = bus_ptr->LUN[target]) == (lun2tid_t *)NULL) {
1257 * Allocate a new structure?
1258 * Since one element in structure, the +1
1259 * needed for size has been abstracted.
1261 if ((new_entry == FALSE)
1262 || ((bus_ptr->LUN[target] = target_ptr = (lun2tid_t *)malloc (
1263 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
1265 == (lun2tid_t *)NULL)) {
1266 debug_asr_printf("failed to allocate target list\n");
1267 return ((tid_t *)NULL);
1269 bzero (target_ptr, sizeof(*target_ptr)
1270 + (sizeof(target_ptr->TID) * new_size));
1271 target_ptr->size = new_size + 1;
1272 } else if (target_ptr->size <= new_size) {
1273 lun2tid_t * new_target_ptr;
1276 * Reallocate a new structure?
1277 * Since one element in structure, the +1
1278 * needed for size has been abstracted.
1280 if ((new_entry == FALSE)
1281 || ((new_target_ptr = (lun2tid_t *)malloc (
1282 sizeof(*target_ptr) + (sizeof(target_ptr->TID) * new_size),
1284 == (lun2tid_t *)NULL)) {
1285 debug_asr_printf("failed to reallocate target list\n");
1286 return ((tid_t *)NULL);
1289 * Zero and copy the whole thing, safer, simpler coding
1290 * and not really performance critical at this point.
1292 bzero (new_target_ptr, sizeof(*target_ptr)
1293 + (sizeof(target_ptr->TID) * new_size));
1294 bcopy (target_ptr, new_target_ptr,
1296 + (sizeof(target_ptr->TID) * (target_ptr->size - 1)));
1297 bus_ptr->LUN[target] = new_target_ptr;
1298 free (target_ptr, M_TEMP);
1299 target_ptr = new_target_ptr;
1300 target_ptr->size = new_size + 1;
1303 * Now, acquire the TID address from the LUN indexed list.
1305 return (&(target_ptr->TID[lun]));
1306 } /* ASR_getTidAddress */
1309 * Get a pre-existing TID relationship.
1311 * If the TID was never set, return (tid_t)-1.
1313 * should use mutex rather than spl.
1317 IN Asr_softc_t * sc,
1327 if (((tid_ptr = ASR_getTidAddress (sc, bus, target, lun, FALSE))
1329 /* (tid_t)0 or (tid_t)-1 indicate no TID */
1330 || (*tid_ptr == (tid_t)0)) {
1340 * Set a TID relationship.
1342 * If the TID was not set, return (tid_t)-1.
1344 * should use mutex rather than spl.
1348 INOUT Asr_softc_t * sc,
1357 if (TID != (tid_t)-1) {
1362 if ((tid_ptr = ASR_getTidAddress (sc, bus, target, lun, TRUE))
1373 /*-------------------------------------------------------------------------*/
1374 /* Function ASR_rescan */
1375 /*-------------------------------------------------------------------------*/
1376 /* The Parameters Passed To This Function Are : */
1377 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1379 /* This Function Will rescan the adapter and resynchronize any data */
1381 /* Return : 0 For OK, Error Code Otherwise */
1382 /*-------------------------------------------------------------------------*/
1386 IN Asr_softc_t * sc)
1392 * Re-acquire the LCT table and synchronize us to the adapter.
1394 if ((error = ASR_acquireLct(sc)) == 0) {
1395 error = ASR_acquireHrt(sc);
1402 bus = sc->ha_MaxBus;
1403 /* Reset all existing cached TID lookups */
1405 int target, event = 0;
1408 * Scan for all targets on this bus to see if they
1409 * got affected by the rescan.
1411 for (target = 0; target <= sc->ha_MaxId; ++target) {
1414 /* Stay away from the controller ID */
1415 if (target == sc->ha_adapter_target[bus]) {
1418 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
1419 PI2O_LCT_ENTRY Device;
1420 tid_t TID = (tid_t)-1;
1424 * See if the cached TID changed. Search for
1425 * the device in our new LCT.
1427 for (Device = sc->ha_LCT->LCTEntry;
1428 Device < (PI2O_LCT_ENTRY)(((U32 *)sc->ha_LCT)
1429 + I2O_LCT_getTableSize(sc->ha_LCT));
1431 if ((Device->le_type != I2O_UNKNOWN)
1432 && (Device->le_bus == bus)
1433 && (Device->le_target == target)
1434 && (Device->le_lun == lun)
1435 && (I2O_LCT_ENTRY_getUserTID(Device)
1437 TID = I2O_LCT_ENTRY_getLocalTID(
1443 * Indicate to the OS that the label needs
1444 * to be recalculated, or that the specific
1445 * open device is no longer valid (Merde)
1446 * because the cached TID changed.
1448 LastTID = ASR_getTid (sc, bus, target, lun);
1449 if (LastTID != TID) {
1450 struct cam_path * path;
1452 if (xpt_create_path(&path,
1454 cam_sim_path(sc->ha_sim[bus]),
1455 target, lun) != CAM_REQ_CMP) {
1456 if (TID == (tid_t)-1) {
1457 event |= AC_LOST_DEVICE;
1459 event |= AC_INQ_CHANGED
1460 | AC_GETDEV_CHANGED;
1463 if (TID == (tid_t)-1) {
1467 } else if (LastTID == (tid_t)-1) {
1468 struct ccb_getdev ccb;
1472 path, /*priority*/5);
1488 * We have the option of clearing the
1489 * cached TID for it to be rescanned, or to
1490 * set it now even if the device never got
1491 * accessed. We chose the later since we
1492 * currently do not use the condition that
1493 * the TID ever got cached.
1495 ASR_setTid (sc, bus, target, lun, TID);
1499 * The xpt layer can not handle multiple events at the
1502 if (event & AC_LOST_DEVICE) {
1503 xpt_async(AC_LOST_DEVICE, sc->ha_path[bus], NULL);
1505 if (event & AC_INQ_CHANGED) {
1506 xpt_async(AC_INQ_CHANGED, sc->ha_path[bus], NULL);
1508 if (event & AC_GETDEV_CHANGED) {
1509 xpt_async(AC_GETDEV_CHANGED, sc->ha_path[bus], NULL);
1511 } while (--bus >= 0);
1515 /*-------------------------------------------------------------------------*/
1516 /* Function ASR_reset */
1517 /*-------------------------------------------------------------------------*/
1518 /* The Parameters Passed To This Function Are : */
1519 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
1521 /* This Function Will reset the adapter and resynchronize any data */
1524 /*-------------------------------------------------------------------------*/
1528 IN Asr_softc_t * sc)
1533 if ((sc->ha_in_reset == HA_IN_RESET)
1534 || (sc->ha_in_reset == HA_OFF_LINE_RECOVERY)) {
1539 * Promotes HA_OPERATIONAL to HA_IN_RESET,
1540 * or HA_OFF_LINE to HA_OFF_LINE_RECOVERY.
1542 ++(sc->ha_in_reset);
1543 if (ASR_resetIOP (sc->ha_Virt, sc->ha_Fvirt) == 0) {
1544 debug_asr_printf ("ASR_resetIOP failed\n");
1546 * We really need to take this card off-line, easier said
1547 * than make sense. Better to keep retrying for now since if a
1548 * UART cable is connected the blinkLEDs the adapter is now in
1549 * a hard state requiring action from the monitor commands to
1550 * the HBA to continue. For debugging waiting forever is a
1551 * good thing. In a production system, however, one may wish
1552 * to instead take the card off-line ...
1554 # if 0 && (defined(HA_OFF_LINE))
1556 * Take adapter off-line.
1558 printf ("asr%d: Taking adapter off-line\n",
1560 ? cam_sim_unit(xpt_path_sim(sc->ha_path[0]))
1562 sc->ha_in_reset = HA_OFF_LINE;
1567 while (ASR_resetIOP (sc->ha_Virt, sc->ha_Fvirt) == 0);
1570 retVal = ASR_init (sc);
1573 debug_asr_printf ("ASR_init failed\n");
1574 sc->ha_in_reset = HA_OFF_LINE;
1577 if (ASR_rescan (sc) != 0) {
1578 debug_asr_printf ("ASR_rescan failed\n");
1580 ASR_failActiveCommands (sc);
1581 if (sc->ha_in_reset == HA_OFF_LINE_RECOVERY) {
1582 printf ("asr%d: Brining adapter back on-line\n",
1584 ? cam_sim_unit(xpt_path_sim(sc->ha_path[0]))
1587 sc->ha_in_reset = HA_OPERATIONAL;
1592 * Device timeout handler.
1598 union asr_ccb * ccb = (union asr_ccb *)arg;
1599 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
1602 debug_asr_print_path(ccb);
1603 debug_asr_printf("timed out");
1606 * Check if the adapter has locked up?
1608 if ((s = ASR_getBlinkLedCode(sc)) != 0) {
1610 printf ("asr%d: Blink LED 0x%x resetting adapter\n",
1611 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)), s);
1612 if (ASR_reset (sc) == ENXIO) {
1613 /* Try again later */
1614 ccb->ccb_h.timeout_ch = timeout(asr_timeout,
1616 (ccb->ccb_h.timeout * hz) / 1000);
1621 * Abort does not function on the ASR card!!! Walking away from
1622 * the SCSI command is also *very* dangerous. A SCSI BUS reset is
1623 * our best bet, followed by a complete adapter reset if that fails.
1626 /* Check if we already timed out once to raise the issue */
1627 if ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_CMD_TIMEOUT) {
1628 debug_asr_printf (" AGAIN\nreinitializing adapter\n");
1629 if (ASR_reset (sc) == ENXIO) {
1630 ccb->ccb_h.timeout_ch = timeout(asr_timeout,
1632 (ccb->ccb_h.timeout * hz) / 1000);
1637 debug_asr_printf ("\nresetting bus\n");
1638 /* If the BUS reset does not take, then an adapter reset is next! */
1639 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
1640 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
1641 ccb->ccb_h.timeout_ch = timeout(asr_timeout, (caddr_t)ccb,
1642 (ccb->ccb_h.timeout * hz) / 1000);
1643 ASR_resetBus (sc, cam_sim_bus(xpt_path_sim(ccb->ccb_h.path)));
1644 xpt_async (AC_BUS_RESET, ccb->ccb_h.path, NULL);
1649 * send a message asynchronously
1653 IN Asr_softc_t * sc,
1654 IN PI2O_MESSAGE_FRAME Message)
1656 OUT U32 MessageOffset;
1657 union asr_ccb * ccb;
1659 debug_asr_printf ("Host Command Dump:\n");
1660 debug_asr_dump_message (Message);
1662 ccb = (union asr_ccb *)(long)
1663 I2O_MESSAGE_FRAME_getInitiatorContext64(Message);
1665 if ((MessageOffset = ASR_getMessage(sc->ha_Virt)) != EMPTY_QUEUE) {
1666 #ifdef ASR_MEASURE_PERFORMANCE
1670 ++sc->ha_performance.command_count[
1671 (int) ccb->csio.cdb_io.cdb_bytes[0]];
1672 DEQ_TIMEQ_FREE_LIST(startTimeIndex,
1673 sc->ha_timeQFreeList,
1674 sc->ha_timeQFreeHead,
1675 sc->ha_timeQFreeTail);
1676 if (-1 != startTimeIndex) {
1677 microtime(&(sc->ha_timeQ[startTimeIndex]));
1679 /* Time stamp the command before we send it out */
1680 ((PRIVATE_SCSI_SCB_EXECUTE_MESSAGE *) Message)->
1681 PrivateMessageFrame.TransactionContext
1682 = (I2O_TRANSACTION_CONTEXT) startTimeIndex;
1684 ++sc->ha_submitted_ccbs_count;
1685 if (sc->ha_performance.max_submit_count
1686 < sc->ha_submitted_ccbs_count) {
1687 sc->ha_performance.max_submit_count
1688 = sc->ha_submitted_ccbs_count;
1692 bcopy (Message, sc->ha_Fvirt + MessageOffset,
1693 I2O_MESSAGE_FRAME_getMessageSize(Message) << 2);
1695 ASR_ccbAdd (sc, ccb);
1697 /* Post the command */
1698 sc->ha_Virt->ToFIFO = MessageOffset;
1700 if (ASR_getBlinkLedCode(sc)) {
1702 * Unlikely we can do anything if we can't grab a
1703 * message frame :-(, but lets give it a try.
1705 (void)ASR_reset (sc);
1708 return (MessageOffset);
1712 /* Simple Scatter Gather elements */
1713 #define SG(SGL,Index,Flags,Buffer,Size) \
1714 I2O_FLAGS_COUNT_setCount( \
1715 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1717 I2O_FLAGS_COUNT_setFlags( \
1718 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index].FlagsCount), \
1719 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | (Flags)); \
1720 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress( \
1721 &(((PI2O_SG_ELEMENT)(SGL))->u.Simple[Index]), \
1722 (Buffer == NULL) ? NULL : KVTOPHYS(Buffer))
1725 * Retrieve Parameter Group.
1726 * Buffer must be allocated using defAlignLong macro.
1730 IN Asr_softc_t * sc,
1734 IN unsigned BufferSize)
1736 struct paramGetMessage {
1737 I2O_UTIL_PARAMS_GET_MESSAGE M;
1739 sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT)];
1741 I2O_PARAM_OPERATIONS_LIST_HEADER Header;
1742 I2O_PARAM_OPERATION_ALL_TEMPLATE Template[1];
1745 defAlignLong(struct paramGetMessage, Message);
1746 struct Operations * Operations_Ptr;
1747 I2O_UTIL_PARAMS_GET_MESSAGE * Message_Ptr;
1748 struct ParamBuffer {
1749 I2O_PARAM_RESULTS_LIST_HEADER Header;
1750 I2O_PARAM_READ_OPERATION_RESULT Read;
1754 Message_Ptr = (I2O_UTIL_PARAMS_GET_MESSAGE *)ASR_fillMessage(Message,
1755 sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1756 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1757 Operations_Ptr = (struct Operations *)((char *)Message_Ptr
1758 + sizeof(I2O_UTIL_PARAMS_GET_MESSAGE)
1759 + sizeof(I2O_SGE_SIMPLE_ELEMENT)*2 - sizeof(I2O_SG_ELEMENT));
1760 bzero ((void *)Operations_Ptr, sizeof(struct Operations));
1761 I2O_PARAM_OPERATIONS_LIST_HEADER_setOperationCount(
1762 &(Operations_Ptr->Header), 1);
1763 I2O_PARAM_OPERATION_ALL_TEMPLATE_setOperation(
1764 &(Operations_Ptr->Template[0]), I2O_PARAMS_OPERATION_FIELD_GET);
1765 I2O_PARAM_OPERATION_ALL_TEMPLATE_setFieldCount(
1766 &(Operations_Ptr->Template[0]), 0xFFFF);
1767 I2O_PARAM_OPERATION_ALL_TEMPLATE_setGroupNumber(
1768 &(Operations_Ptr->Template[0]), Group);
1769 bzero ((void *)(Buffer_Ptr = getAlignLong(struct ParamBuffer, Buffer)),
1772 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1774 + (((sizeof(I2O_UTIL_PARAMS_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1775 / sizeof(U32)) << 4));
1776 I2O_MESSAGE_FRAME_setTargetAddress (&(Message_Ptr->StdMessageFrame),
1778 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
1779 I2O_UTIL_PARAMS_GET);
1781 * Set up the buffers as scatter gather elements.
1783 SG(&(Message_Ptr->SGL), 0,
1784 I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER,
1785 Operations_Ptr, sizeof(struct Operations));
1786 SG(&(Message_Ptr->SGL), 1,
1787 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
1788 Buffer_Ptr, BufferSize);
1790 if ((ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) == CAM_REQ_CMP)
1791 && (Buffer_Ptr->Header.ResultCount)) {
1792 return ((void *)(Buffer_Ptr->Info));
1794 return ((void *)NULL);
1795 } /* ASR_getParams */
1798 * Acquire the LCT information.
1802 INOUT Asr_softc_t * sc)
1804 PI2O_EXEC_LCT_NOTIFY_MESSAGE Message_Ptr;
1805 PI2O_SGE_SIMPLE_ELEMENT sg;
1806 int MessageSizeInBytes;
1810 PI2O_LCT_ENTRY Entry;
1813 * sc value assumed valid
1815 MessageSizeInBytes = sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE)
1816 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT);
1817 if ((Message_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)malloc (
1818 MessageSizeInBytes, M_TEMP, M_WAITOK))
1819 == (PI2O_EXEC_LCT_NOTIFY_MESSAGE)NULL) {
1822 (void)ASR_fillMessage((char *)Message_Ptr, MessageSizeInBytes);
1823 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
1825 (((sizeof(I2O_EXEC_LCT_NOTIFY_MESSAGE) - sizeof(I2O_SG_ELEMENT))
1826 / sizeof(U32)) << 4)));
1827 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
1828 I2O_EXEC_LCT_NOTIFY);
1829 I2O_EXEC_LCT_NOTIFY_MESSAGE_setClassIdentifier(Message_Ptr,
1830 I2O_CLASS_MATCH_ANYCLASS);
1832 * Call the LCT table to determine the number of device entries
1833 * to reserve space for.
1835 SG(&(Message_Ptr->SGL), 0,
1836 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER, &Table,
1839 * since this code is reused in several systems, code efficiency
1840 * is greater by using a shift operation rather than a divide by
1841 * sizeof(u_int32_t).
1843 I2O_LCT_setTableSize(&Table,
1844 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1845 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1847 * Determine the size of the LCT table.
1850 free (sc->ha_LCT, M_TEMP);
1853 * malloc only generates contiguous memory when less than a
1854 * page is expected. We must break the request up into an SG list ...
1856 if (((len = (I2O_LCT_getTableSize(&Table) << 2)) <=
1857 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)))
1858 || (len > (128 * 1024))) { /* Arbitrary */
1859 free (Message_Ptr, M_TEMP);
1862 if ((sc->ha_LCT = (PI2O_LCT)malloc (len, M_TEMP, M_WAITOK))
1863 == (PI2O_LCT)NULL) {
1864 free (Message_Ptr, M_TEMP);
1868 * since this code is reused in several systems, code efficiency
1869 * is greater by using a shift operation rather than a divide by
1870 * sizeof(u_int32_t).
1872 I2O_LCT_setTableSize(sc->ha_LCT,
1873 (sizeof(I2O_LCT) - sizeof(I2O_LCT_ENTRY)) >> 2);
1875 * Convert the access to the LCT table into a SG list.
1877 sg = Message_Ptr->SGL.u.Simple;
1878 v = (caddr_t)(sc->ha_LCT);
1880 int next, base, span;
1883 next = base = KVTOPHYS(v);
1884 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
1886 /* How far can we go contiguously */
1887 while ((len > 0) && (base == next)) {
1890 next = trunc_page(base) + PAGE_SIZE;
1901 /* Construct the Flags */
1902 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
1904 int rw = I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT;
1906 rw = (I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT
1907 | I2O_SGL_FLAGS_LAST_ELEMENT
1908 | I2O_SGL_FLAGS_END_OF_BUFFER);
1910 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount), rw);
1918 * Incrementing requires resizing of the packet.
1921 MessageSizeInBytes += sizeof(*sg);
1922 I2O_MESSAGE_FRAME_setMessageSize(
1923 &(Message_Ptr->StdMessageFrame),
1924 I2O_MESSAGE_FRAME_getMessageSize(
1925 &(Message_Ptr->StdMessageFrame))
1926 + (sizeof(*sg) / sizeof(U32)));
1928 PI2O_EXEC_LCT_NOTIFY_MESSAGE NewMessage_Ptr;
1930 if ((NewMessage_Ptr = (PI2O_EXEC_LCT_NOTIFY_MESSAGE)
1931 malloc (MessageSizeInBytes, M_TEMP, M_WAITOK))
1932 == (PI2O_EXEC_LCT_NOTIFY_MESSAGE)NULL) {
1933 free (sc->ha_LCT, M_TEMP);
1934 sc->ha_LCT = (PI2O_LCT)NULL;
1935 free (Message_Ptr, M_TEMP);
1938 span = ((caddr_t)sg) - (caddr_t)Message_Ptr;
1939 bcopy ((caddr_t)Message_Ptr,
1940 (caddr_t)NewMessage_Ptr, span);
1941 free (Message_Ptr, M_TEMP);
1942 sg = (PI2O_SGE_SIMPLE_ELEMENT)
1943 (((caddr_t)NewMessage_Ptr) + span);
1944 Message_Ptr = NewMessage_Ptr;
1949 retval = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
1950 free (Message_Ptr, M_TEMP);
1951 if (retval != CAM_REQ_CMP) {
1955 /* If the LCT table grew, lets truncate accesses */
1956 if (I2O_LCT_getTableSize(&Table) < I2O_LCT_getTableSize(sc->ha_LCT)) {
1957 I2O_LCT_setTableSize(sc->ha_LCT, I2O_LCT_getTableSize(&Table));
1959 for (Entry = sc->ha_LCT->LCTEntry; Entry < (PI2O_LCT_ENTRY)
1960 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
1962 Entry->le_type = I2O_UNKNOWN;
1963 switch (I2O_CLASS_ID_getClass(&(Entry->ClassID))) {
1965 case I2O_CLASS_RANDOM_BLOCK_STORAGE:
1966 Entry->le_type = I2O_BSA;
1969 case I2O_CLASS_SCSI_PERIPHERAL:
1970 Entry->le_type = I2O_SCSI;
1973 case I2O_CLASS_FIBRE_CHANNEL_PERIPHERAL:
1974 Entry->le_type = I2O_FCA;
1977 case I2O_CLASS_BUS_ADAPTER_PORT:
1978 Entry->le_type = I2O_PORT | I2O_SCSI;
1980 case I2O_CLASS_FIBRE_CHANNEL_PORT:
1981 if (I2O_CLASS_ID_getClass(&(Entry->ClassID)) ==
1982 I2O_CLASS_FIBRE_CHANNEL_PORT) {
1983 Entry->le_type = I2O_PORT | I2O_FCA;
1985 { struct ControllerInfo {
1986 I2O_PARAM_RESULTS_LIST_HEADER Header;
1987 I2O_PARAM_READ_OPERATION_RESULT Read;
1988 I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1990 defAlignLong(struct ControllerInfo, Buffer);
1991 PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR Info;
1993 Entry->le_bus = 0xff;
1994 Entry->le_target = 0xff;
1995 Entry->le_lun = 0xff;
1997 if ((Info = (PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR)
1999 I2O_LCT_ENTRY_getLocalTID(Entry),
2000 I2O_HBA_SCSI_CONTROLLER_INFO_GROUP_NO,
2001 Buffer, sizeof(struct ControllerInfo)))
2002 == (PI2O_HBA_SCSI_CONTROLLER_INFO_SCALAR)NULL) {
2006 = I2O_HBA_SCSI_CONTROLLER_INFO_SCALAR_getInitiatorID(
2013 { struct DeviceInfo {
2014 I2O_PARAM_RESULTS_LIST_HEADER Header;
2015 I2O_PARAM_READ_OPERATION_RESULT Read;
2016 I2O_DPT_DEVICE_INFO_SCALAR Info;
2018 defAlignLong (struct DeviceInfo, Buffer);
2019 PI2O_DPT_DEVICE_INFO_SCALAR Info;
2021 Entry->le_bus = 0xff;
2022 Entry->le_target = 0xff;
2023 Entry->le_lun = 0xff;
2025 if ((Info = (PI2O_DPT_DEVICE_INFO_SCALAR)
2027 I2O_LCT_ENTRY_getLocalTID(Entry),
2028 I2O_DPT_DEVICE_INFO_GROUP_NO,
2029 Buffer, sizeof(struct DeviceInfo)))
2030 == (PI2O_DPT_DEVICE_INFO_SCALAR)NULL) {
2034 |= I2O_DPT_DEVICE_INFO_SCALAR_getDeviceType(Info);
2036 = I2O_DPT_DEVICE_INFO_SCALAR_getBus(Info);
2037 if ((Entry->le_bus > sc->ha_MaxBus)
2038 && (Entry->le_bus <= MAX_CHANNEL)) {
2039 sc->ha_MaxBus = Entry->le_bus;
2042 = I2O_DPT_DEVICE_INFO_SCALAR_getIdentifier(Info);
2044 = I2O_DPT_DEVICE_INFO_SCALAR_getLunInfo(Info);
2048 * A zero return value indicates success.
2051 } /* ASR_acquireLct */
2054 * Initialize a message frame.
2055 * We assume that the CDB has already been set up, so all we do here is
2056 * generate the Scatter Gather list.
2058 STATIC INLINE PI2O_MESSAGE_FRAME
2060 IN union asr_ccb * ccb,
2061 OUT PI2O_MESSAGE_FRAME Message)
2063 int next, span, base, rw;
2064 OUT PI2O_MESSAGE_FRAME Message_Ptr;
2065 Asr_softc_t * sc = (Asr_softc_t *)(ccb->ccb_h.spriv_ptr0);
2066 PI2O_SGE_SIMPLE_ELEMENT sg;
2068 vm_size_t size, len;
2071 /* We only need to zero out the PRIVATE_SCSI_SCB_EXECUTE_MESSAGE */
2072 bzero (Message_Ptr = getAlignLong(I2O_MESSAGE_FRAME, Message),
2073 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT)));
2076 int target = ccb->ccb_h.target_id;
2077 int lun = ccb->ccb_h.target_lun;
2078 int bus = cam_sim_bus(xpt_path_sim(ccb->ccb_h.path));
2081 if ((TID = ASR_getTid (sc, bus, target, lun)) == (tid_t)-1) {
2082 PI2O_LCT_ENTRY Device;
2085 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2086 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
2088 if ((Device->le_type != I2O_UNKNOWN)
2089 && (Device->le_bus == bus)
2090 && (Device->le_target == target)
2091 && (Device->le_lun == lun)
2092 && (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF)) {
2093 TID = I2O_LCT_ENTRY_getLocalTID(Device);
2094 ASR_setTid (sc, Device->le_bus,
2095 Device->le_target, Device->le_lun,
2101 if (TID == (tid_t)0) {
2102 return ((PI2O_MESSAGE_FRAME)NULL);
2104 I2O_MESSAGE_FRAME_setTargetAddress(Message_Ptr, TID);
2105 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(
2106 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, TID);
2108 I2O_MESSAGE_FRAME_setVersionOffset(Message_Ptr, I2O_VERSION_11 |
2109 (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2110 / sizeof(U32)) << 4));
2111 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
2112 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2113 - sizeof(I2O_SG_ELEMENT)) / sizeof(U32));
2114 I2O_MESSAGE_FRAME_setInitiatorAddress (Message_Ptr, 1);
2115 I2O_MESSAGE_FRAME_setFunction(Message_Ptr, I2O_PRIVATE_MESSAGE);
2116 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
2117 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, I2O_SCSI_SCB_EXEC);
2118 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
2119 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
2120 I2O_SCB_FLAG_ENABLE_DISCONNECT
2121 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2122 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2124 * We do not need any (optional byteswapping) method access to
2125 * the Initiator & Transaction context field.
2127 I2O_MESSAGE_FRAME_setInitiatorContext64(Message, (long)ccb);
2129 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2130 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr, DPT_ORGANIZATION_ID);
2134 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(
2135 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, ccb->csio.cdb_len);
2136 bcopy (&(ccb->csio.cdb_io),
2137 ((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->CDB, ccb->csio.cdb_len);
2140 * Given a buffer describing a transfer, set up a scatter/gather map
2141 * in a ccb to map that SCSI transfer.
2144 rw = (ccb->ccb_h.flags & CAM_DIR_IN) ? 0 : I2O_SGL_FLAGS_DIR;
2146 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (
2147 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
2148 (ccb->csio.dxfer_len)
2149 ? ((rw) ? (I2O_SCB_FLAG_XFER_TO_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_XFER_FROM_DEVICE
2154 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2155 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2156 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER))
2157 : (I2O_SCB_FLAG_ENABLE_DISCONNECT
2158 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2159 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2162 * Given a transfer described by a `data', fill in the SG list.
2164 sg = &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr)->SGL.u.Simple[0];
2166 len = ccb->csio.dxfer_len;
2167 v = ccb->csio.data_ptr;
2168 ASSERT (ccb->csio.dxfer_len >= 0);
2169 MessageSize = I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr);
2170 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
2171 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr, len);
2172 while ((len > 0) && (sg < &((PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2173 Message_Ptr)->SGL.u.Simple[SG_SIZE])) {
2175 next = base = KVTOPHYS(v);
2176 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg, base);
2178 /* How far can we go contiguously */
2179 while ((len > 0) && (base == next)) {
2180 next = trunc_page(base) + PAGE_SIZE;
2191 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount), span);
2193 rw |= I2O_SGL_FLAGS_LAST_ELEMENT;
2195 I2O_FLAGS_COUNT_setFlags(&(sg->FlagsCount),
2196 I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT | rw);
2198 MessageSize += sizeof(*sg) / sizeof(U32);
2200 /* We always do the request sense ... */
2201 if ((span = ccb->csio.sense_len) == 0) {
2202 span = sizeof(ccb->csio.sense_data);
2204 SG(sg, 0, I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2205 &(ccb->csio.sense_data), span);
2206 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
2207 MessageSize + (sizeof(*sg) / sizeof(U32)));
2208 return (Message_Ptr);
2209 } /* ASR_init_message */
2212 * Reset the adapter.
2216 INOUT Asr_softc_t * sc)
2218 struct initOutBoundMessage {
2219 I2O_EXEC_OUTBOUND_INIT_MESSAGE M;
2222 defAlignLong(struct initOutBoundMessage,Message);
2223 PI2O_EXEC_OUTBOUND_INIT_MESSAGE Message_Ptr;
2224 OUT U32 * volatile Reply_Ptr;
2228 * Build up our copy of the Message.
2230 Message_Ptr = (PI2O_EXEC_OUTBOUND_INIT_MESSAGE)ASR_fillMessage(Message,
2231 sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE));
2232 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2233 I2O_EXEC_OUTBOUND_INIT);
2234 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setHostPageFrameSize(Message_Ptr, PAGE_SIZE);
2235 I2O_EXEC_OUTBOUND_INIT_MESSAGE_setOutboundMFrameSize(Message_Ptr,
2236 sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME));
2238 * Reset the Reply Status
2240 *(Reply_Ptr = (U32 *)((char *)Message_Ptr
2241 + sizeof(I2O_EXEC_OUTBOUND_INIT_MESSAGE))) = 0;
2242 SG (&(Message_Ptr->SGL), 0, I2O_SGL_FLAGS_LAST_ELEMENT, Reply_Ptr,
2245 * Send the Message out
2247 if ((Old = ASR_initiateCp (sc->ha_Virt, sc->ha_Fvirt, (PI2O_MESSAGE_FRAME)Message_Ptr)) != (U32)-1L) {
2251 * Wait for a response (Poll).
2253 while (*Reply_Ptr < I2O_EXEC_OUTBOUND_INIT_REJECTED);
2255 * Re-enable the interrupts.
2257 sc->ha_Virt->Mask = Old;
2259 * Populate the outbound table.
2261 if (sc->ha_Msgs == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
2263 /* Allocate the reply frames */
2264 size = sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
2265 * sc->ha_Msgs_Count;
2268 * contigmalloc only works reliably at
2269 * initialization time.
2271 if ((sc->ha_Msgs = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
2272 contigmalloc (size, M_DEVBUF, M_WAITOK, 0ul,
2273 0xFFFFFFFFul, (u_long)sizeof(U32), 0ul))
2274 != (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
2275 (void)bzero ((char *)sc->ha_Msgs, size);
2276 sc->ha_Msgs_Phys = KVTOPHYS(sc->ha_Msgs);
2280 /* Initialize the outbound FIFO */
2281 if (sc->ha_Msgs != (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL)
2282 for (size = sc->ha_Msgs_Count, addr = sc->ha_Msgs_Phys;
2284 sc->ha_Virt->FromFIFO = addr;
2285 addr += sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME);
2287 return (*Reply_Ptr);
2290 } /* ASR_initOutBound */
2293 * Set the system table
2297 IN Asr_softc_t * sc)
2299 PI2O_EXEC_SYS_TAB_SET_MESSAGE Message_Ptr;
2300 PI2O_SET_SYSTAB_HEADER SystemTable;
2302 PI2O_SGE_SIMPLE_ELEMENT sg;
2305 if ((SystemTable = (PI2O_SET_SYSTAB_HEADER)malloc (
2306 sizeof(I2O_SET_SYSTAB_HEADER), M_TEMP, M_WAITOK))
2307 == (PI2O_SET_SYSTAB_HEADER)NULL) {
2310 bzero (SystemTable, sizeof(I2O_SET_SYSTAB_HEADER));
2311 for (ha = Asr_softc; ha; ha = ha->ha_next) {
2312 ++SystemTable->NumberEntries;
2314 if ((Message_Ptr = (PI2O_EXEC_SYS_TAB_SET_MESSAGE)malloc (
2315 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2316 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)),
2317 M_TEMP, M_WAITOK)) == (PI2O_EXEC_SYS_TAB_SET_MESSAGE)NULL) {
2318 free (SystemTable, M_TEMP);
2321 (void)ASR_fillMessage((char *)Message_Ptr,
2322 sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2323 + ((3+SystemTable->NumberEntries) * sizeof(I2O_SGE_SIMPLE_ELEMENT)));
2324 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
2326 (((sizeof(I2O_EXEC_SYS_TAB_SET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2327 / sizeof(U32)) << 4)));
2328 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2329 I2O_EXEC_SYS_TAB_SET);
2331 * Call the LCT table to determine the number of device entries
2332 * to reserve space for.
2333 * since this code is reused in several systems, code efficiency
2334 * is greater by using a shift operation rather than a divide by
2335 * sizeof(u_int32_t).
2337 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
2338 + ((I2O_MESSAGE_FRAME_getVersionOffset(
2339 &(Message_Ptr->StdMessageFrame)) & 0xF0) >> 2));
2340 SG(sg, 0, I2O_SGL_FLAGS_DIR, SystemTable, sizeof(I2O_SET_SYSTAB_HEADER));
2342 for (ha = Asr_softc; ha; ha = ha->ha_next) {
2345 ? (I2O_SGL_FLAGS_DIR)
2346 : (I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER)),
2347 &(ha->ha_SystemTable), sizeof(ha->ha_SystemTable));
2350 SG(sg, 0, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
2351 SG(sg, 1, I2O_SGL_FLAGS_DIR | I2O_SGL_FLAGS_LAST_ELEMENT
2352 | I2O_SGL_FLAGS_END_OF_BUFFER, NULL, 0);
2353 retVal = ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2354 free (Message_Ptr, M_TEMP);
2355 free (SystemTable, M_TEMP);
2357 } /* ASR_setSysTab */
2361 INOUT Asr_softc_t * sc)
2363 defAlignLong(I2O_EXEC_HRT_GET_MESSAGE,Message);
2364 I2O_EXEC_HRT_GET_MESSAGE * Message_Ptr;
2367 I2O_HRT_ENTRY Entry[MAX_CHANNEL];
2369 u_int8_t NumberOfEntries;
2370 PI2O_HRT_ENTRY Entry;
2372 bzero ((void *)&Hrt, sizeof (Hrt));
2373 Message_Ptr = (I2O_EXEC_HRT_GET_MESSAGE *)ASR_fillMessage(Message,
2374 sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT)
2375 + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2376 I2O_MESSAGE_FRAME_setVersionOffset(&(Message_Ptr->StdMessageFrame),
2378 + (((sizeof(I2O_EXEC_HRT_GET_MESSAGE) - sizeof(I2O_SG_ELEMENT))
2379 / sizeof(U32)) << 4)));
2380 I2O_MESSAGE_FRAME_setFunction (&(Message_Ptr->StdMessageFrame),
2384 * Set up the buffers as scatter gather elements.
2386 SG(&(Message_Ptr->SGL), 0,
2387 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
2389 if (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != CAM_REQ_CMP) {
2392 if ((NumberOfEntries = I2O_HRT_getNumberEntries(&Hrt.Header))
2393 > (MAX_CHANNEL + 1)) {
2394 NumberOfEntries = MAX_CHANNEL + 1;
2396 for (Entry = Hrt.Header.HRTEntry;
2397 NumberOfEntries != 0;
2398 ++Entry, --NumberOfEntries) {
2399 PI2O_LCT_ENTRY Device;
2401 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
2402 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
2404 if (I2O_LCT_ENTRY_getLocalTID(Device)
2405 == (I2O_HRT_ENTRY_getAdapterID(Entry) & 0xFFF)) {
2406 Device->le_bus = I2O_HRT_ENTRY_getAdapterID(
2408 if ((Device->le_bus > sc->ha_MaxBus)
2409 && (Device->le_bus <= MAX_CHANNEL)) {
2410 sc->ha_MaxBus = Device->le_bus;
2416 } /* ASR_acquireHrt */
2419 * Enable the adapter.
2423 IN Asr_softc_t * sc)
2425 defAlignLong(I2O_EXEC_SYS_ENABLE_MESSAGE,Message);
2426 PI2O_EXEC_SYS_ENABLE_MESSAGE Message_Ptr;
2428 Message_Ptr = (PI2O_EXEC_SYS_ENABLE_MESSAGE)ASR_fillMessage(Message,
2429 sizeof(I2O_EXEC_SYS_ENABLE_MESSAGE));
2430 I2O_MESSAGE_FRAME_setFunction(&(Message_Ptr->StdMessageFrame),
2431 I2O_EXEC_SYS_ENABLE);
2432 return (ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr) != 0);
2433 } /* ASR_enableSys */
2436 * Perform the stages necessary to initialize the adapter
2440 IN Asr_softc_t * sc)
2442 return ((ASR_initOutBound(sc) == 0)
2443 || (ASR_setSysTab(sc) != CAM_REQ_CMP)
2444 || (ASR_enableSys(sc) != CAM_REQ_CMP));
2448 * Send a Synchronize Cache command to the target device.
2452 IN Asr_softc_t * sc,
2460 * We will not synchronize the device when there are outstanding
2461 * commands issued by the OS (this is due to a locked up device,
2462 * as the OS normally would flush all outstanding commands before
2463 * issuing a shutdown or an adapter reset).
2465 if ((sc != (Asr_softc_t *)NULL)
2466 && (LIST_FIRST(&(sc->ha_ccb)) != (struct ccb_hdr *)NULL)
2467 && ((TID = ASR_getTid (sc, bus, target, lun)) != (tid_t)-1)
2468 && (TID != (tid_t)0)) {
2469 defAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE,Message);
2470 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
2473 = getAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE, Message),
2474 sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2475 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
2477 I2O_MESSAGE_FRAME_setVersionOffset(
2478 (PI2O_MESSAGE_FRAME)Message_Ptr,
2480 | (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2481 - sizeof(I2O_SG_ELEMENT))
2482 / sizeof(U32)) << 4));
2483 I2O_MESSAGE_FRAME_setMessageSize(
2484 (PI2O_MESSAGE_FRAME)Message_Ptr,
2485 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2486 - sizeof(I2O_SG_ELEMENT))
2488 I2O_MESSAGE_FRAME_setInitiatorAddress (
2489 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
2490 I2O_MESSAGE_FRAME_setFunction(
2491 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
2492 I2O_MESSAGE_FRAME_setTargetAddress(
2493 (PI2O_MESSAGE_FRAME)Message_Ptr, TID);
2494 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
2495 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2497 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setTID(Message_Ptr, TID);
2498 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2499 I2O_SCB_FLAG_ENABLE_DISCONNECT
2500 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2501 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
2502 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
2503 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
2504 DPT_ORGANIZATION_ID);
2505 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
2506 Message_Ptr->CDB[0] = SYNCHRONIZE_CACHE;
2507 Message_Ptr->CDB[1] = (lun << 5);
2509 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
2510 (I2O_SCB_FLAG_XFER_FROM_DEVICE
2511 | I2O_SCB_FLAG_ENABLE_DISCONNECT
2512 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
2513 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
2515 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
2522 IN Asr_softc_t * sc)
2524 int bus, target, lun;
2526 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
2527 for (target = 0; target <= sc->ha_MaxId; ++target) {
2528 for (lun = 0; lun <= sc->ha_MaxLun; ++lun) {
2529 ASR_sync(sc,bus,target,lun);
2536 * Reset the HBA, targets and BUS.
2537 * Currently this resets *all* the SCSI busses.
2541 IN Asr_softc_t * sc)
2543 ASR_synchronize (sc);
2544 (void)ASR_reset (sc);
2545 } /* asr_hbareset */
2548 * A reduced copy of the real pci_map_mem, incorporating the MAX_MAP
2549 * limit and a reduction in error checking (in the pre 4.0 case).
2553 #if __FreeBSD_version >= 400000
2558 IN Asr_softc_t * sc)
2563 #if __FreeBSD_version >= 400000
2565 * I2O specification says we must find first *memory* mapped BAR
2567 for (rid = PCIR_MAPS;
2568 rid < (PCIR_MAPS + 4 * sizeof(u_int32_t));
2569 rid += sizeof(u_int32_t)) {
2570 p = pci_read_config(tag, rid, sizeof(p));
2578 if (rid >= (PCIR_MAPS + 4 * sizeof(u_int32_t))) {
2581 p = pci_read_config(tag, rid, sizeof(p));
2582 pci_write_config(tag, rid, -1, sizeof(p));
2583 l = 0 - (pci_read_config(tag, rid, sizeof(l)) & ~15);
2584 pci_write_config(tag, rid, p, sizeof(p));
2589 * The 2005S Zero Channel RAID solution is not a perfect PCI
2590 * citizen. It asks for 4MB on BAR0, and 0MB on BAR1, once
2591 * enabled it rewrites the size of BAR0 to 2MB, sets BAR1 to
2592 * BAR0+2MB and sets it's size to 2MB. The IOP registers are
2593 * accessible via BAR0, the messaging registers are accessible
2594 * via BAR1. If the subdevice code is 50 to 59 decimal.
2596 s = pci_read_config(tag, PCIR_DEVVENDOR, sizeof(s));
2597 if (s != 0xA5111044) {
2598 s = pci_read_config(tag, PCIR_SUBVEND_0, sizeof(s));
2599 if ((((ADPTDOMINATOR_SUB_ID_START ^ s) & 0xF000FFFF) == 0)
2600 && (ADPTDOMINATOR_SUB_ID_START <= s)
2601 && (s <= ADPTDOMINATOR_SUB_ID_END)) {
2602 l = MAX_MAP; /* Conjoined BAR Raptor Daptor */
2606 sc->ha_mem_res = bus_alloc_resource(tag, SYS_RES_MEMORY, &rid,
2607 p, p + l, l, RF_ACTIVE);
2608 if (sc->ha_mem_res == (struct resource *)NULL) {
2611 sc->ha_Base = (void *)rman_get_start(sc->ha_mem_res);
2612 if (sc->ha_Base == (void *)NULL) {
2615 sc->ha_Virt = (i2oRegs_t *) rman_get_virtual(sc->ha_mem_res);
2616 if (s == 0xA5111044) { /* Split BAR Raptor Daptor */
2617 if ((rid += sizeof(u_int32_t))
2618 >= (PCIR_MAPS + 4 * sizeof(u_int32_t))) {
2621 p = pci_read_config(tag, rid, sizeof(p));
2622 pci_write_config(tag, rid, -1, sizeof(p));
2623 l = 0 - (pci_read_config(tag, rid, sizeof(l)) & ~15);
2624 pci_write_config(tag, rid, p, sizeof(p));
2629 sc->ha_mes_res = bus_alloc_resource(tag, SYS_RES_MEMORY, &rid,
2630 p, p + l, l, RF_ACTIVE);
2631 if (sc->ha_mes_res == (struct resource *)NULL) {
2634 if ((void *)rman_get_start(sc->ha_mes_res) == (void *)NULL) {
2637 sc->ha_Fvirt = (U8 *) rman_get_virtual(sc->ha_mes_res);
2639 sc->ha_Fvirt = (U8 *)(sc->ha_Virt);
2642 vm_size_t psize, poffs;
2645 * I2O specification says we must find first *memory* mapped BAR
2647 for (rid = PCI_MAP_REG_START;
2648 rid < (PCI_MAP_REG_START + 4 * sizeof(u_int32_t));
2649 rid += sizeof(u_int32_t)) {
2650 p = pci_conf_read (tag, rid);
2655 if (rid >= (PCI_MAP_REG_START + 4 * sizeof(u_int32_t))) {
2656 rid = PCI_MAP_REG_START;
2659 ** save old mapping, get size and type of memory
2661 ** type is in the lowest four bits.
2662 ** If device requires 2^n bytes, the next
2663 ** n-4 bits are read as 0.
2666 sc->ha_Base = (void *)((p = pci_conf_read (tag, rid))
2667 & PCI_MAP_MEMORY_ADDRESS_MASK);
2668 pci_conf_write (tag, rid, 0xfffffffful);
2669 l = pci_conf_read (tag, rid);
2670 pci_conf_write (tag, rid, p);
2676 if (!((l & PCI_MAP_MEMORY_TYPE_MASK) == PCI_MAP_MEMORY_TYPE_32BIT_1M
2677 && ((u_long)sc->ha_Base & ~0xfffff) == 0)
2678 && ((l & PCI_MAP_MEMORY_TYPE_MASK) != PCI_MAP_MEMORY_TYPE_32BIT)) {
2680 "asr_pci_map_mem failed: bad memory type=0x%x\n",
2689 psize = -(l & PCI_MAP_MEMORY_ADDRESS_MASK);
2690 if (psize > MAX_MAP) {
2694 * The 2005S Zero Channel RAID solution is not a perfect PCI
2695 * citizen. It asks for 4MB on BAR0, and 0MB on BAR1, once
2696 * enabled it rewrites the size of BAR0 to 2MB, sets BAR1 to
2697 * BAR0+2MB and sets it's size to 2MB. The IOP registers are
2698 * accessible via BAR0, the messaging registers are accessible
2699 * via BAR1. If the subdevice code is 50 to 59 decimal.
2701 s = pci_read_config(tag, PCIR_DEVVENDOR, sizeof(s));
2702 if (s != 0xA5111044) {
2703 s = pci_conf_read (tag, PCIR_SUBVEND_0)
2704 if ((((ADPTDOMINATOR_SUB_ID_START ^ s) & 0xF000FFFF) == 0)
2705 && (ADPTDOMINATOR_SUB_ID_START <= s)
2706 && (s <= ADPTDOMINATOR_SUB_ID_END)) {
2711 if ((sc->ha_Base == (void *)NULL)
2712 || (sc->ha_Base == (void *)PCI_MAP_MEMORY_ADDRESS_MASK)) {
2713 debug_asr_printf ("asr_pci_map_mem: not configured by bios.\n");
2718 ** Truncate sc->ha_Base to page boundary.
2719 ** (Or does pmap_mapdev the job?)
2722 poffs = (u_long)sc->ha_Base - trunc_page ((u_long)sc->ha_Base);
2723 sc->ha_Virt = (i2oRegs_t *)pmap_mapdev ((u_long)sc->ha_Base - poffs,
2726 if (sc->ha_Virt == (i2oRegs_t *)NULL) {
2730 sc->ha_Virt = (i2oRegs_t *)((u_long)sc->ha_Virt + poffs);
2731 if (s == 0xA5111044) {
2732 if ((rid += sizeof(u_int32_t))
2733 >= (PCI_MAP_REG_START + 4 * sizeof(u_int32_t))) {
2738 ** save old mapping, get size and type of memory
2740 ** type is in the lowest four bits.
2741 ** If device requires 2^n bytes, the next
2742 ** n-4 bits are read as 0.
2745 if ((((p = pci_conf_read (tag, rid))
2746 & PCI_MAP_MEMORY_ADDRESS_MASK) == 0L)
2747 || ((p & PCI_MAP_MEMORY_ADDRESS_MASK)
2748 == PCI_MAP_MEMORY_ADDRESS_MASK)) {
2749 debug_asr_printf ("asr_pci_map_mem: not configured by bios.\n");
2751 pci_conf_write (tag, rid, 0xfffffffful);
2752 l = pci_conf_read (tag, rid);
2753 pci_conf_write (tag, rid, p);
2754 p &= PCI_MAP_MEMORY_TYPE_MASK;
2760 if (!((l & PCI_MAP_MEMORY_TYPE_MASK)
2761 == PCI_MAP_MEMORY_TYPE_32BIT_1M
2762 && (p & ~0xfffff) == 0)
2763 && ((l & PCI_MAP_MEMORY_TYPE_MASK)
2764 != PCI_MAP_MEMORY_TYPE_32BIT)) {
2766 "asr_pci_map_mem failed: bad memory type=0x%x\n",
2775 psize = -(l & PCI_MAP_MEMORY_ADDRESS_MASK);
2776 if (psize > MAX_MAP) {
2781 ** Truncate p to page boundary.
2782 ** (Or does pmap_mapdev the job?)
2785 poffs = p - trunc_page (p);
2786 sc->ha_Fvirt = (U8 *)pmap_mapdev (p - poffs, psize + poffs);
2788 if (sc->ha_Fvirt == (U8 *)NULL) {
2792 sc->ha_Fvirt = (U8 *)((u_long)sc->ha_Fvirt + poffs);
2794 sc->ha_Fvirt = (U8 *)(sc->ha_Virt);
2798 } /* asr_pci_map_mem */
2801 * A simplified copy of the real pci_map_int with additional
2802 * registration requirements.
2806 #if __FreeBSD_version >= 400000
2811 IN Asr_softc_t * sc)
2813 #if __FreeBSD_version >= 400000
2816 sc->ha_irq_res = bus_alloc_resource(tag, SYS_RES_IRQ, &rid,
2817 0, ~0, 1, RF_ACTIVE | RF_SHAREABLE);
2818 if (sc->ha_irq_res == (struct resource *)NULL) {
2821 if (bus_setup_intr(tag, sc->ha_irq_res, INTR_TYPE_CAM,
2822 (driver_intr_t *)asr_intr, (void *)sc, &(sc->ha_intr))) {
2825 sc->ha_irq = pci_read_config(tag, PCIR_INTLINE, sizeof(char));
2827 if (!pci_map_int(tag, (pci_inthand_t *)asr_intr,
2828 (void *)sc, &cam_imask)) {
2831 sc->ha_irq = pci_conf_read(tag, PCIR_INTLINE);
2834 } /* asr_pci_map_int */
2837 * Attach the devices, and virtual devices to the driver list.
2840 asr_attach (ATTACH_ARGS)
2843 struct scsi_inquiry_data * iq;
2846 if ((sc = malloc(sizeof(*sc), M_DEVBUF, M_NOWAIT)) == (Asr_softc_t *)NULL) {
2847 ATTACH_RETURN(ENOMEM);
2849 if (Asr_softc == (Asr_softc_t *)NULL) {
2851 * Fixup the OS revision as saved in the dptsig for the
2852 * engine (dptioctl.h) to pick up.
2854 bcopy (osrelease, &ASR_sig.dsDescription[16], 5);
2855 printf ("asr%d: major=%d\n", unit, asr_cdevsw.d_maj);
2858 * Initialize the software structure
2860 bzero (sc, sizeof(*sc));
2861 LIST_INIT(&(sc->ha_ccb));
2862 # ifdef ASR_MEASURE_PERFORMANCE
2866 // initialize free list for timeQ
2867 sc->ha_timeQFreeHead = 0;
2868 sc->ha_timeQFreeTail = MAX_TIMEQ_SIZE - 1;
2869 for (i = 0; i < MAX_TIMEQ_SIZE; i++) {
2870 sc->ha_timeQFreeList[i] = i;
2874 /* Link us into the HA list */
2878 for (ha = &Asr_softc; *ha; ha = &((*ha)->ha_next));
2882 PI2O_EXEC_STATUS_GET_REPLY status;
2886 * This is the real McCoy!
2888 if (!asr_pci_map_mem(tag, sc)) {
2889 printf ("asr%d: could not map memory\n", unit);
2890 ATTACH_RETURN(ENXIO);
2892 /* Enable if not formerly enabled */
2893 #if __FreeBSD_version >= 400000
2894 pci_write_config (tag, PCIR_COMMAND,
2895 pci_read_config (tag, PCIR_COMMAND, sizeof(char))
2896 | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN, sizeof(char));
2897 /* Knowledge is power, responsibility is direct */
2899 struct pci_devinfo {
2900 STAILQ_ENTRY(pci_devinfo) pci_links;
2901 struct resource_list resources;
2903 } * dinfo = device_get_ivars(tag);
2904 sc->ha_pciBusNum = dinfo->cfg.bus;
2905 sc->ha_pciDeviceNum = (dinfo->cfg.slot << 3)
2909 pci_conf_write (tag, PCIR_COMMAND,
2910 pci_conf_read (tag, PCIR_COMMAND)
2911 | PCIM_CMD_MEMEN | PCIM_CMD_BUSMASTEREN);
2912 /* Knowledge is power, responsibility is direct */
2913 switch (pci_mechanism) {
2916 sc->ha_pciBusNum = tag.cfg1 >> 16;
2917 sc->ha_pciDeviceNum = tag.cfg1 >> 8;
2920 sc->ha_pciBusNum = tag.cfg2.forward;
2921 sc->ha_pciDeviceNum = ((tag.cfg2.enable >> 1) & 7)
2922 | (tag.cfg2.port >> 5);
2925 /* Check if the device is there? */
2926 if ((ASR_resetIOP(sc->ha_Virt, sc->ha_Fvirt) == 0)
2927 || ((status = (PI2O_EXEC_STATUS_GET_REPLY)malloc (
2928 sizeof(I2O_EXEC_STATUS_GET_REPLY), M_TEMP, M_WAITOK))
2929 == (PI2O_EXEC_STATUS_GET_REPLY)NULL)
2930 || (ASR_getStatus(sc->ha_Virt, sc->ha_Fvirt, status) == NULL)) {
2931 printf ("asr%d: could not initialize hardware\n", unit);
2932 ATTACH_RETURN(ENODEV); /* Get next, maybe better luck */
2934 sc->ha_SystemTable.OrganizationID = status->OrganizationID;
2935 sc->ha_SystemTable.IOP_ID = status->IOP_ID;
2936 sc->ha_SystemTable.I2oVersion = status->I2oVersion;
2937 sc->ha_SystemTable.IopState = status->IopState;
2938 sc->ha_SystemTable.MessengerType = status->MessengerType;
2939 sc->ha_SystemTable.InboundMessageFrameSize
2940 = status->InboundMFrameSize;
2941 sc->ha_SystemTable.MessengerInfo.InboundMessagePortAddressLow
2942 = (U32)(sc->ha_Base) + (U32)(&(((i2oRegs_t *)NULL)->ToFIFO));
2944 if (!asr_pci_map_int(tag, (void *)sc)) {
2945 printf ("asr%d: could not map interrupt\n", unit);
2946 ATTACH_RETURN(ENXIO);
2949 /* Adjust the maximim inbound count */
2950 if (((sc->ha_QueueSize
2951 = I2O_EXEC_STATUS_GET_REPLY_getMaxInboundMFrames(status))
2953 || (sc->ha_QueueSize == 0)) {
2954 sc->ha_QueueSize = MAX_INBOUND;
2957 /* Adjust the maximum outbound count */
2958 if (((sc->ha_Msgs_Count
2959 = I2O_EXEC_STATUS_GET_REPLY_getMaxOutboundMFrames(status))
2961 || (sc->ha_Msgs_Count == 0)) {
2962 sc->ha_Msgs_Count = MAX_OUTBOUND;
2964 if (sc->ha_Msgs_Count > sc->ha_QueueSize) {
2965 sc->ha_Msgs_Count = sc->ha_QueueSize;
2968 /* Adjust the maximum SG size to adapter */
2969 if ((size = (I2O_EXEC_STATUS_GET_REPLY_getInboundMFrameSize(
2970 status) << 2)) > MAX_INBOUND_SIZE) {
2971 size = MAX_INBOUND_SIZE;
2973 free (status, M_TEMP);
2974 sc->ha_SgSize = (size - sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
2975 + sizeof(I2O_SG_ELEMENT)) / sizeof(I2O_SGE_SIMPLE_ELEMENT);
2979 * Only do a bus/HBA reset on the first time through. On this
2980 * first time through, we do not send a flush to the devices.
2982 if (ASR_init(sc) == 0) {
2984 I2O_PARAM_RESULTS_LIST_HEADER Header;
2985 I2O_PARAM_READ_OPERATION_RESULT Read;
2986 I2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2988 defAlignLong (struct BufferInfo, Buffer);
2989 PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR Info;
2990 # define FW_DEBUG_BLED_OFFSET 8
2992 if ((Info = (PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR)
2993 ASR_getParams(sc, 0,
2994 I2O_DPT_EXEC_IOP_BUFFERS_GROUP_NO,
2995 Buffer, sizeof(struct BufferInfo)))
2996 != (PI2O_DPT_EXEC_IOP_BUFFERS_SCALAR)NULL) {
2997 sc->ha_blinkLED = sc->ha_Fvirt
2998 + I2O_DPT_EXEC_IOP_BUFFERS_SCALAR_getSerialOutputOffset(Info)
2999 + FW_DEBUG_BLED_OFFSET;
3001 if (ASR_acquireLct(sc) == 0) {
3002 (void)ASR_acquireHrt(sc);
3005 printf ("asr%d: failed to initialize\n", unit);
3006 ATTACH_RETURN(ENXIO);
3009 * Add in additional probe responses for more channels. We
3010 * are reusing the variable `target' for a channel loop counter.
3011 * Done here because of we need both the acquireLct and
3014 { PI2O_LCT_ENTRY Device;
3016 for (Device = sc->ha_LCT->LCTEntry; Device < (PI2O_LCT_ENTRY)
3017 (((U32 *)sc->ha_LCT)+I2O_LCT_getTableSize(sc->ha_LCT));
3019 if (Device->le_type == I2O_UNKNOWN) {
3022 if (I2O_LCT_ENTRY_getUserTID(Device) == 0xFFF) {
3023 if (Device->le_target > sc->ha_MaxId) {
3024 sc->ha_MaxId = Device->le_target;
3026 if (Device->le_lun > sc->ha_MaxLun) {
3027 sc->ha_MaxLun = Device->le_lun;
3030 if (((Device->le_type & I2O_PORT) != 0)
3031 && (Device->le_bus <= MAX_CHANNEL)) {
3032 /* Do not increase MaxId for efficiency */
3033 sc->ha_adapter_target[Device->le_bus]
3034 = Device->le_target;
3041 * Print the HBA model number as inquired from the card.
3044 printf ("asr%d:", unit);
3046 if ((iq = (struct scsi_inquiry_data *)malloc (
3047 sizeof(struct scsi_inquiry_data), M_TEMP, M_WAITOK))
3048 != (struct scsi_inquiry_data *)NULL) {
3049 defAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE,Message);
3050 PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE Message_Ptr;
3053 bzero (iq, sizeof(struct scsi_inquiry_data));
3055 = getAlignLong(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE, Message),
3056 sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3057 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT));
3059 I2O_MESSAGE_FRAME_setVersionOffset(
3060 (PI2O_MESSAGE_FRAME)Message_Ptr,
3062 | (((sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3063 - sizeof(I2O_SG_ELEMENT))
3064 / sizeof(U32)) << 4));
3065 I2O_MESSAGE_FRAME_setMessageSize(
3066 (PI2O_MESSAGE_FRAME)Message_Ptr,
3067 (sizeof(PRIVATE_SCSI_SCB_EXECUTE_MESSAGE)
3068 - sizeof(I2O_SG_ELEMENT) + sizeof(I2O_SGE_SIMPLE_ELEMENT))
3070 I2O_MESSAGE_FRAME_setInitiatorAddress (
3071 (PI2O_MESSAGE_FRAME)Message_Ptr, 1);
3072 I2O_MESSAGE_FRAME_setFunction(
3073 (PI2O_MESSAGE_FRAME)Message_Ptr, I2O_PRIVATE_MESSAGE);
3074 I2O_PRIVATE_MESSAGE_FRAME_setXFunctionCode (
3075 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
3077 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
3078 I2O_SCB_FLAG_ENABLE_DISCONNECT
3079 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
3080 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER);
3081 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setInterpret(Message_Ptr, 1);
3082 I2O_PRIVATE_MESSAGE_FRAME_setOrganizationID(
3083 (PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr,
3084 DPT_ORGANIZATION_ID);
3085 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setCDBLength(Message_Ptr, 6);
3086 Message_Ptr->CDB[0] = INQUIRY;
3087 Message_Ptr->CDB[4] = (unsigned char)sizeof(struct scsi_inquiry_data);
3088 if (Message_Ptr->CDB[4] == 0) {
3089 Message_Ptr->CDB[4] = 255;
3092 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setSCBFlags (Message_Ptr,
3093 (I2O_SCB_FLAG_XFER_FROM_DEVICE
3094 | I2O_SCB_FLAG_ENABLE_DISCONNECT
3095 | I2O_SCB_FLAG_SIMPLE_QUEUE_TAG
3096 | I2O_SCB_FLAG_SENSE_DATA_IN_BUFFER));
3098 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_setByteCount(
3099 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr,
3100 sizeof(struct scsi_inquiry_data));
3101 SG(&(Message_Ptr->SGL), 0,
3102 I2O_SGL_FLAGS_LAST_ELEMENT | I2O_SGL_FLAGS_END_OF_BUFFER,
3103 iq, sizeof(struct scsi_inquiry_data));
3104 (void)ASR_queue_c(sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
3106 if (iq->vendor[0] && (iq->vendor[0] != ' ')) {
3108 ASR_prstring (iq->vendor, 8);
3111 if (iq->product[0] && (iq->product[0] != ' ')) {
3113 ASR_prstring (iq->product, 16);
3116 if (iq->revision[0] && (iq->revision[0] != ' ')) {
3117 printf (" FW Rev. ");
3118 ASR_prstring (iq->revision, 4);
3121 free ((caddr_t)iq, M_TEMP);
3126 printf (" %d channel, %d CCBs, Protocol I2O\n", sc->ha_MaxBus + 1,
3127 (sc->ha_QueueSize > MAX_INBOUND) ? MAX_INBOUND : sc->ha_QueueSize);
3130 * fill in the prototype cam_path.
3134 union asr_ccb * ccb;
3136 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
3137 printf ("asr%d: CAM could not be notified of asynchronous callback parameters\n", unit);
3138 ATTACH_RETURN(ENOMEM);
3140 for (bus = 0; bus <= sc->ha_MaxBus; ++bus) {
3141 struct cam_devq * devq;
3142 int QueueSize = sc->ha_QueueSize;
3144 if (QueueSize > MAX_INBOUND) {
3145 QueueSize = MAX_INBOUND;
3149 * Create the device queue for our SIM(s).
3151 if ((devq = cam_simq_alloc(QueueSize)) == NULL) {
3156 * Construct our first channel SIM entry
3158 sc->ha_sim[bus] = cam_sim_alloc(
3159 asr_action, asr_poll, "asr", sc,
3160 unit, 1, QueueSize, devq);
3161 if (sc->ha_sim[bus] == NULL) {
3165 if (xpt_bus_register(sc->ha_sim[bus], bus)
3167 cam_sim_free(sc->ha_sim[bus],
3169 sc->ha_sim[bus] = NULL;
3173 if (xpt_create_path(&(sc->ha_path[bus]), /*periph*/NULL,
3174 cam_sim_path(sc->ha_sim[bus]), CAM_TARGET_WILDCARD,
3175 CAM_LUN_WILDCARD) != CAM_REQ_CMP) {
3177 cam_sim_path(sc->ha_sim[bus]));
3178 cam_sim_free(sc->ha_sim[bus],
3180 sc->ha_sim[bus] = NULL;
3187 * Generate the device node information
3189 (void)make_dev(&asr_cdevsw, unit, 0, 0, S_IRWXU, "rasr%d", unit);
3190 destroy_dev(makedev(asr_cdevsw.d_maj,unit+1));
3196 IN struct cam_sim *sim)
3198 asr_intr(cam_sim_softc(sim));
3203 IN struct cam_sim * sim,
3206 struct Asr_softc * sc;
3208 debug_asr_printf ("asr_action(%lx,%lx{%x})\n",
3209 (u_long)sim, (u_long)ccb, ccb->ccb_h.func_code);
3211 CAM_DEBUG(ccb->ccb_h.path, CAM_DEBUG_TRACE, ("asr_action\n"));
3213 ccb->ccb_h.spriv_ptr0 = sc = (struct Asr_softc *)cam_sim_softc(sim);
3215 switch (ccb->ccb_h.func_code) {
3217 /* Common cases first */
3218 case XPT_SCSI_IO: /* Execute the requested I/O operation */
3221 char M[MAX_INBOUND_SIZE];
3223 defAlignLong(struct Message,Message);
3224 PI2O_MESSAGE_FRAME Message_Ptr;
3226 /* Reject incoming commands while we are resetting the card */
3227 if (sc->ha_in_reset != HA_OPERATIONAL) {
3228 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3229 if (sc->ha_in_reset >= HA_OFF_LINE) {
3230 /* HBA is now off-line */
3231 ccb->ccb_h.status |= CAM_UNREC_HBA_ERROR;
3233 /* HBA currently resetting, try again later. */
3234 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3236 debug_asr_cmd_printf (" e\n");
3238 debug_asr_cmd_printf (" q\n");
3241 if ((ccb->ccb_h.status & CAM_STATUS_MASK) != CAM_REQ_INPROG) {
3243 "asr%d WARNING: scsi_cmd(%x) already done on b%dt%du%d\n",
3244 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
3245 ccb->csio.cdb_io.cdb_bytes[0],
3247 ccb->ccb_h.target_id,
3248 ccb->ccb_h.target_lun);
3250 debug_asr_cmd_printf ("(%d,%d,%d,%d)",
3253 ccb->ccb_h.target_id,
3254 ccb->ccb_h.target_lun);
3255 debug_asr_cmd_dump_ccb(ccb);
3257 if ((Message_Ptr = ASR_init_message ((union asr_ccb *)ccb,
3258 (PI2O_MESSAGE_FRAME)Message)) != (PI2O_MESSAGE_FRAME)NULL) {
3259 debug_asr_cmd2_printf ("TID=%x:\n",
3260 PRIVATE_SCSI_SCB_EXECUTE_MESSAGE_getTID(
3261 (PPRIVATE_SCSI_SCB_EXECUTE_MESSAGE)Message_Ptr));
3262 debug_asr_cmd2_dump_message(Message_Ptr);
3263 debug_asr_cmd1_printf (" q");
3265 if (ASR_queue (sc, Message_Ptr) == EMPTY_QUEUE) {
3266 #ifdef ASR_MEASURE_PERFORMANCE
3267 ++sc->ha_performance.command_too_busy;
3269 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3270 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3271 debug_asr_cmd_printf (" E\n");
3274 debug_asr_cmd_printf (" Q\n");
3278 * We will get here if there is no valid TID for the device
3279 * referenced in the scsi command packet.
3281 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3282 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
3283 debug_asr_cmd_printf (" B\n");
3288 case XPT_RESET_DEV: /* Bus Device Reset the specified SCSI device */
3289 /* Rese HBA device ... */
3291 ccb->ccb_h.status = CAM_REQ_CMP;
3295 # if (defined(REPORT_LUNS))
3298 case XPT_ABORT: /* Abort the specified CCB */
3300 ccb->ccb_h.status = CAM_REQ_INVALID;
3304 case XPT_SET_TRAN_SETTINGS:
3306 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3310 case XPT_GET_TRAN_SETTINGS:
3311 /* Get default/user set transfer settings for the target */
3313 struct ccb_trans_settings *cts;
3317 target_mask = 0x01 << ccb->ccb_h.target_id;
3318 if ((cts->flags & CCB_TRANS_USER_SETTINGS) != 0) {
3319 cts->flags = CCB_TRANS_DISC_ENB|CCB_TRANS_TAG_ENB;
3320 cts->bus_width = MSG_EXT_WDTR_BUS_16_BIT;
3321 cts->sync_period = 6; /* 40MHz */
3322 cts->sync_offset = 15;
3324 cts->valid = CCB_TRANS_SYNC_RATE_VALID
3325 | CCB_TRANS_SYNC_OFFSET_VALID
3326 | CCB_TRANS_BUS_WIDTH_VALID
3327 | CCB_TRANS_DISC_VALID
3328 | CCB_TRANS_TQ_VALID;
3329 ccb->ccb_h.status = CAM_REQ_CMP;
3331 ccb->ccb_h.status = CAM_FUNC_NOTAVAIL;
3337 case XPT_CALC_GEOMETRY:
3339 struct ccb_calc_geometry *ccg;
3341 u_int32_t secs_per_cylinder;
3344 size_mb = ccg->volume_size
3345 / ((1024L * 1024L) / ccg->block_size);
3347 if (size_mb > 4096) {
3349 ccg->secs_per_track = 63;
3350 } else if (size_mb > 2048) {
3352 ccg->secs_per_track = 63;
3353 } else if (size_mb > 1024) {
3355 ccg->secs_per_track = 63;
3358 ccg->secs_per_track = 32;
3360 secs_per_cylinder = ccg->heads * ccg->secs_per_track;
3361 ccg->cylinders = ccg->volume_size / secs_per_cylinder;
3362 ccb->ccb_h.status = CAM_REQ_CMP;
3367 case XPT_RESET_BUS: /* Reset the specified SCSI bus */
3368 ASR_resetBus (sc, cam_sim_bus(sim));
3369 ccb->ccb_h.status = CAM_REQ_CMP;
3373 case XPT_TERM_IO: /* Terminate the I/O process */
3375 ccb->ccb_h.status = CAM_REQ_INVALID;
3379 case XPT_PATH_INQ: /* Path routing inquiry */
3381 struct ccb_pathinq *cpi = &(ccb->cpi);
3383 cpi->version_num = 1; /* XXX??? */
3384 cpi->hba_inquiry = PI_SDTR_ABLE|PI_TAG_ABLE|PI_WIDE_16;
3385 cpi->target_sprt = 0;
3386 /* Not necessary to reset bus, done by HDM initialization */
3387 cpi->hba_misc = PIM_NOBUSRESET;
3388 cpi->hba_eng_cnt = 0;
3389 cpi->max_target = sc->ha_MaxId;
3390 cpi->max_lun = sc->ha_MaxLun;
3391 cpi->initiator_id = sc->ha_adapter_target[cam_sim_bus(sim)];
3392 cpi->bus_id = cam_sim_bus(sim);
3393 cpi->base_transfer_speed = 3300;
3394 strncpy(cpi->sim_vid, "FreeBSD", SIM_IDLEN);
3395 strncpy(cpi->hba_vid, "Adaptec", HBA_IDLEN);
3396 strncpy(cpi->dev_name, cam_sim_name(sim), DEV_IDLEN);
3397 cpi->unit_number = cam_sim_unit(sim);
3398 cpi->ccb_h.status = CAM_REQ_CMP;
3403 ccb->ccb_h.status = CAM_REQ_INVALID;
3409 #ifdef ASR_MEASURE_PERFORMANCE
3412 #define min_submitR sc->ha_performance.read_by_size_min_time[index]
3413 #define max_submitR sc->ha_performance.read_by_size_max_time[index]
3414 #define min_submitW sc->ha_performance.write_by_size_min_time[index]
3415 #define max_submitW sc->ha_performance.write_by_size_max_time[index]
3419 IN Asr_softc_t * sc,
3420 IN u_int32_t submitted_time,
3424 struct timeval submitted_timeval;
3426 submitted_timeval.tv_sec = 0;
3427 submitted_timeval.tv_usec = submitted_time;
3429 if ( op == READ_OP ) {
3430 ++sc->ha_performance.read_by_size_count[index];
3432 if ( submitted_time != 0xffffffff ) {
3434 &(sc->ha_performance.read_by_size_total_time[index]),
3435 &submitted_timeval);
3436 if ( (min_submitR == 0)
3437 || (submitted_time < min_submitR) ) {
3438 min_submitR = submitted_time;
3441 if ( submitted_time > max_submitR ) {
3442 max_submitR = submitted_time;
3446 ++sc->ha_performance.write_by_size_count[index];
3447 if ( submitted_time != 0xffffffff ) {
3449 &(sc->ha_performance.write_by_size_total_time[index]),
3450 &submitted_timeval);
3451 if ( (submitted_time < min_submitW)
3452 || (min_submitW == 0) ) {
3453 min_submitW = submitted_time;
3456 if ( submitted_time > max_submitW ) {
3457 max_submitW = submitted_time;
3461 } /* asr_IObySize */
3465 * Handle processing of current CCB as pointed to by the Status.
3469 IN Asr_softc_t * sc)
3473 #ifdef ASR_MEASURE_PERFORMANCE
3474 struct timeval junk;
3477 sc->ha_performance.intr_started = junk;
3481 sc->ha_Virt->Status & Mask_InterruptsDisabled;
3483 union asr_ccb * ccb;
3485 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
3487 if (((ReplyOffset = sc->ha_Virt->FromFIFO) == EMPTY_QUEUE)
3488 && ((ReplyOffset = sc->ha_Virt->FromFIFO) == EMPTY_QUEUE)) {
3491 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)(ReplyOffset
3492 - sc->ha_Msgs_Phys + (char *)(sc->ha_Msgs));
3494 * We do not need any (optional byteswapping) method access to
3495 * the Initiator context field.
3497 ccb = (union asr_ccb *)(long)
3498 I2O_MESSAGE_FRAME_getInitiatorContext64(
3499 &(Reply->StdReplyFrame.StdMessageFrame));
3500 if (I2O_MESSAGE_FRAME_getMsgFlags(
3501 &(Reply->StdReplyFrame.StdMessageFrame))
3502 & I2O_MESSAGE_FLAGS_FAIL) {
3503 defAlignLong(I2O_UTIL_NOP_MESSAGE,Message);
3504 PI2O_UTIL_NOP_MESSAGE Message_Ptr;
3507 MessageOffset = (u_long)
3508 I2O_FAILURE_REPLY_MESSAGE_FRAME_getPreservedMFA(
3509 (PI2O_FAILURE_REPLY_MESSAGE_FRAME)Reply);
3511 * Get the Original Message Frame's address, and get
3512 * it's Transaction Context into our space. (Currently
3513 * unused at original authorship, but better to be
3514 * safe than sorry). Straight copy means that we
3515 * need not concern ourselves with the (optional
3516 * byteswapping) method access.
3518 Reply->StdReplyFrame.TransactionContext
3519 = ((PI2O_SINGLE_REPLY_MESSAGE_FRAME)
3520 (sc->ha_Fvirt + MessageOffset))->TransactionContext;
3522 * For 64 bit machines, we need to reconstruct the
3525 ccb = (union asr_ccb *)(long)
3526 I2O_MESSAGE_FRAME_getInitiatorContext64(
3527 &(Reply->StdReplyFrame.StdMessageFrame));
3529 * Unique error code for command failure.
3531 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
3532 &(Reply->StdReplyFrame), (u_int16_t)-2);
3534 * Modify the message frame to contain a NOP and
3535 * re-issue it to the controller.
3537 Message_Ptr = (PI2O_UTIL_NOP_MESSAGE)ASR_fillMessage(
3538 Message, sizeof(I2O_UTIL_NOP_MESSAGE));
3539 # if (I2O_UTIL_NOP != 0)
3540 I2O_MESSAGE_FRAME_setFunction (
3541 &(Message_Ptr->StdMessageFrame),
3545 * Copy the packet out to the Original Message
3547 bcopy ((caddr_t)Message_Ptr,
3548 sc->ha_Fvirt + MessageOffset,
3549 sizeof(I2O_UTIL_NOP_MESSAGE));
3553 sc->ha_Virt->ToFIFO = MessageOffset;
3557 * Asynchronous command with no return requirements,
3558 * and a generic handler for immunity against odd error
3559 * returns from the adapter.
3561 if (ccb == (union asr_ccb *)NULL) {
3563 * Return Reply so that it can be used for the
3566 sc->ha_Virt->FromFIFO = ReplyOffset;
3570 /* Welease Wadjah! (and stop timeouts) */
3571 ASR_ccbRemove (sc, ccb);
3574 I2O_SINGLE_REPLY_MESSAGE_FRAME_getDetailedStatusCode(
3575 &(Reply->StdReplyFrame))) {
3577 case I2O_SCSI_DSC_SUCCESS:
3578 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3579 ccb->ccb_h.status |= CAM_REQ_CMP;
3582 case I2O_SCSI_DSC_CHECK_CONDITION:
3583 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3584 ccb->ccb_h.status |= CAM_REQ_CMP|CAM_AUTOSNS_VALID;
3587 case I2O_SCSI_DSC_BUSY:
3589 case I2O_SCSI_HBA_DSC_ADAPTER_BUSY:
3591 case I2O_SCSI_HBA_DSC_SCSI_BUS_RESET:
3593 case I2O_SCSI_HBA_DSC_BUS_BUSY:
3594 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3595 ccb->ccb_h.status |= CAM_SCSI_BUSY;
3598 case I2O_SCSI_HBA_DSC_SELECTION_TIMEOUT:
3599 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3600 ccb->ccb_h.status |= CAM_SEL_TIMEOUT;
3603 case I2O_SCSI_HBA_DSC_COMMAND_TIMEOUT:
3605 case I2O_SCSI_HBA_DSC_DEVICE_NOT_PRESENT:
3607 case I2O_SCSI_HBA_DSC_LUN_INVALID:
3609 case I2O_SCSI_HBA_DSC_SCSI_TID_INVALID:
3610 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3611 ccb->ccb_h.status |= CAM_CMD_TIMEOUT;
3614 case I2O_SCSI_HBA_DSC_DATA_OVERRUN:
3616 case I2O_SCSI_HBA_DSC_REQUEST_LENGTH_ERROR:
3617 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3618 ccb->ccb_h.status |= CAM_DATA_RUN_ERR;
3622 ccb->ccb_h.status &= ~CAM_STATUS_MASK;
3623 ccb->ccb_h.status |= CAM_REQUEUE_REQ;
3626 if ((ccb->csio.resid = ccb->csio.dxfer_len) != 0) {
3628 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getTransferCount(
3632 #ifdef ASR_MEASURE_PERFORMANCE
3634 struct timeval endTime;
3635 u_int32_t submitted_time;
3640 --sc->ha_submitted_ccbs_count;
3642 = (int)Reply->StdReplyFrame.TransactionContext;
3643 if (-1 != startTimeIndex) {
3644 /* Compute the time spent in device/adapter */
3645 microtime(&endTime);
3646 submitted_time = asr_time_delta(sc->ha_timeQ[
3647 startTimeIndex], endTime);
3648 /* put the startTimeIndex back on free list */
3649 ENQ_TIMEQ_FREE_LIST(startTimeIndex,
3650 sc->ha_timeQFreeList,
3651 sc->ha_timeQFreeHead,
3652 sc->ha_timeQFreeTail);
3654 submitted_time = 0xffffffff;
3657 #define maxctime sc->ha_performance.max_command_time[ccb->csio.cdb_io.cdb_bytes[0]]
3658 #define minctime sc->ha_performance.min_command_time[ccb->csio.cdb_io.cdb_bytes[0]]
3659 if (submitted_time != 0xffffffff) {
3660 if ( maxctime < submitted_time ) {
3661 maxctime = submitted_time;
3663 if ( (minctime == 0)
3664 || (minctime > submitted_time) ) {
3665 minctime = submitted_time;
3668 if ( sc->ha_performance.max_submit_time
3669 < submitted_time ) {
3670 sc->ha_performance.max_submit_time
3673 if ( sc->ha_performance.min_submit_time == 0
3674 || sc->ha_performance.min_submit_time
3676 sc->ha_performance.min_submit_time
3680 switch ( ccb->csio.cdb_io.cdb_bytes[0] ) {
3682 case 0xa8: /* 12-byte READ */
3684 case 0x08: /* 6-byte READ */
3686 case 0x28: /* 10-byte READ */
3690 case 0x0a: /* 6-byte WRITE */
3692 case 0xaa: /* 12-byte WRITE */
3694 case 0x2a: /* 10-byte WRITE */
3703 if ( op_type != 0 ) {
3704 struct scsi_rw_big * cmd;
3706 cmd = (struct scsi_rw_big *)
3707 &(ccb->csio.cdb_io);
3709 size = (((u_int32_t) cmd->length2 << 8)
3710 | ((u_int32_t) cmd->length1)) << 9;
3716 submitted_time, op_type,
3722 submitted_time, op_type,
3728 submitted_time, op_type,
3734 submitted_time, op_type,
3740 submitted_time, op_type,
3746 submitted_time, op_type,
3752 submitted_time, op_type,
3758 submitted_time, op_type,
3763 if ( size > (1 << 16) ) {
3780 /* Sense data in reply packet */
3781 if (ccb->ccb_h.status & CAM_AUTOSNS_VALID) {
3782 u_int16_t size = I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_getAutoSenseTransferCount(Reply);
3785 if (size > sizeof(ccb->csio.sense_data)) {
3786 size = sizeof(ccb->csio.sense_data);
3788 if (size > I2O_SCSI_SENSE_DATA_SZ) {
3789 size = I2O_SCSI_SENSE_DATA_SZ;
3791 if ((ccb->csio.sense_len)
3792 && (size > ccb->csio.sense_len)) {
3793 size = ccb->csio.sense_len;
3795 bcopy ((caddr_t)Reply->SenseData,
3796 (caddr_t)&(ccb->csio.sense_data), size);
3801 * Return Reply so that it can be used for the next command
3802 * since we have no more need for it now
3804 sc->ha_Virt->FromFIFO = ReplyOffset;
3806 if (ccb->ccb_h.path) {
3807 xpt_done ((union ccb *)ccb);
3809 wakeup ((caddr_t)ccb);
3812 #ifdef ASR_MEASURE_PERFORMANCE
3817 result = asr_time_delta(sc->ha_performance.intr_started, junk);
3819 if (result != 0xffffffff) {
3820 if ( sc->ha_performance.max_intr_time < result ) {
3821 sc->ha_performance.max_intr_time = result;
3824 if ( (sc->ha_performance.min_intr_time == 0)
3825 || (sc->ha_performance.min_intr_time > result) ) {
3826 sc->ha_performance.min_intr_time = result;
3834 #undef QueueSize /* Grrrr */
3835 #undef SG_Size /* Grrrr */
3838 * Meant to be included at the bottom of asr.c !!!
3842 * Included here as hard coded. Done because other necessary include
3843 * files utilize C++ comment structures which make them a nuisance to
3844 * included here just to pick up these three typedefs.
3846 typedef U32 DPT_TAG_T;
3847 typedef U32 DPT_MSG_T;
3848 typedef U32 DPT_RTN_T;
3850 #undef SCSI_RESET /* Conflicts with "scsi/scsiconf.h" defintion */
3851 #include "dev/asr/osd_unix.h"
3853 #define asr_unit(dev) minor(dev)
3855 STATIC INLINE Asr_softc_t *
3859 int unit = asr_unit(dev);
3860 OUT Asr_softc_t * sc = Asr_softc;
3862 while (sc && sc->ha_sim[0] && (cam_sim_unit(sc->ha_sim[0]) != unit)) {
3868 STATIC u_int8_t ASR_ctlr_held;
3869 #if (!defined(UNREFERENCED_PARAMETER))
3870 # define UNREFERENCED_PARAMETER(x) (void)(x)
3882 UNREFERENCED_PARAMETER(flags);
3883 UNREFERENCED_PARAMETER(ifmt);
3885 if (ASR_get_sc (dev) == (Asr_softc_t *)NULL) {
3888 KKASSERT(td->td_proc);
3890 if (ASR_ctlr_held) {
3892 } else if ((error = suser_cred(td->td_proc->p_ucred, 0)) == 0) {
3906 UNREFERENCED_PARAMETER(dev);
3907 UNREFERENCED_PARAMETER(flags);
3908 UNREFERENCED_PARAMETER(ifmt);
3909 UNREFERENCED_PARAMETER(td);
3916 /*-------------------------------------------------------------------------*/
3917 /* Function ASR_queue_i */
3918 /*-------------------------------------------------------------------------*/
3919 /* The Parameters Passed To This Function Are : */
3920 /* Asr_softc_t * : HBA miniport driver's adapter data storage. */
3921 /* PI2O_MESSAGE_FRAME : Msg Structure Pointer For This Command */
3922 /* I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME following the Msg Structure */
3924 /* This Function Will Take The User Request Packet And Convert It To An */
3925 /* I2O MSG And Send It Off To The Adapter. */
3927 /* Return : 0 For OK, Error Code Otherwise */
3928 /*-------------------------------------------------------------------------*/
3931 IN Asr_softc_t * sc,
3932 INOUT PI2O_MESSAGE_FRAME Packet)
3934 union asr_ccb * ccb;
3935 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply;
3936 PI2O_MESSAGE_FRAME Message_Ptr;
3937 PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME Reply_Ptr;
3938 int MessageSizeInBytes;
3939 int ReplySizeInBytes;
3942 /* Scatter Gather buffer list */
3943 struct ioctlSgList_S {
3944 SLIST_ENTRY(ioctlSgList_S) link;
3946 I2O_FLAGS_COUNT FlagsCount;
3947 char KernelSpace[sizeof(long)];
3949 /* Generates a `first' entry */
3950 SLIST_HEAD(ioctlSgListHead_S, ioctlSgList_S) sgList;
3952 if (ASR_getBlinkLedCode(sc)) {
3953 debug_usr_cmd_printf ("Adapter currently in BlinkLed %x\n",
3954 ASR_getBlinkLedCode(sc));
3957 /* Copy in the message into a local allocation */
3958 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)malloc (
3959 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK))
3960 == (PI2O_MESSAGE_FRAME)NULL) {
3961 debug_usr_cmd_printf (
3962 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
3965 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
3966 sizeof(I2O_MESSAGE_FRAME))) != 0) {
3967 free (Message_Ptr, M_TEMP);
3968 debug_usr_cmd_printf ("Can't copy in packet errno=%d\n", error);
3971 /* Acquire information to determine type of packet */
3972 MessageSizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)<<2);
3973 /* The offset of the reply information within the user packet */
3974 Reply = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)((char *)Packet
3975 + MessageSizeInBytes);
3977 /* Check if the message is a synchronous initialization command */
3978 s = I2O_MESSAGE_FRAME_getFunction(Message_Ptr);
3979 free (Message_Ptr, M_TEMP);
3982 case I2O_EXEC_IOP_RESET:
3985 status = ASR_resetIOP(sc->ha_Virt, sc->ha_Fvirt);
3986 ReplySizeInBytes = sizeof(status);
3987 debug_usr_cmd_printf ("resetIOP done\n");
3988 return (copyout ((caddr_t)&status, (caddr_t)Reply,
3992 case I2O_EXEC_STATUS_GET:
3993 { I2O_EXEC_STATUS_GET_REPLY status;
3995 if (ASR_getStatus (sc->ha_Virt, sc->ha_Fvirt, &status)
3996 == (PI2O_EXEC_STATUS_GET_REPLY)NULL) {
3997 debug_usr_cmd_printf ("getStatus failed\n");
4000 ReplySizeInBytes = sizeof(status);
4001 debug_usr_cmd_printf ("getStatus done\n");
4002 return (copyout ((caddr_t)&status, (caddr_t)Reply,
4006 case I2O_EXEC_OUTBOUND_INIT:
4009 status = ASR_initOutBound(sc);
4010 ReplySizeInBytes = sizeof(status);
4011 debug_usr_cmd_printf ("intOutBound done\n");
4012 return (copyout ((caddr_t)&status, (caddr_t)Reply,
4017 /* Determine if the message size is valid */
4018 if ((MessageSizeInBytes < sizeof(I2O_MESSAGE_FRAME))
4019 || (MAX_INBOUND_SIZE < MessageSizeInBytes)) {
4020 debug_usr_cmd_printf ("Packet size %d incorrect\n",
4021 MessageSizeInBytes);
4025 if ((Message_Ptr = (PI2O_MESSAGE_FRAME)malloc (MessageSizeInBytes,
4026 M_TEMP, M_WAITOK)) == (PI2O_MESSAGE_FRAME)NULL) {
4027 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
4028 MessageSizeInBytes);
4031 if ((error = copyin ((caddr_t)Packet, (caddr_t)Message_Ptr,
4032 MessageSizeInBytes)) != 0) {
4033 free (Message_Ptr, M_TEMP);
4034 debug_usr_cmd_printf ("Can't copy in packet[%d] errno=%d\n",
4035 MessageSizeInBytes, error);
4039 /* Check the size of the reply frame, and start constructing */
4041 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)malloc (
4042 sizeof(I2O_MESSAGE_FRAME), M_TEMP, M_WAITOK))
4043 == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
4044 free (Message_Ptr, M_TEMP);
4045 debug_usr_cmd_printf (
4046 "Failed to acquire I2O_MESSAGE_FRAME memory\n");
4049 if ((error = copyin ((caddr_t)Reply, (caddr_t)Reply_Ptr,
4050 sizeof(I2O_MESSAGE_FRAME))) != 0) {
4051 free (Reply_Ptr, M_TEMP);
4052 free (Message_Ptr, M_TEMP);
4053 debug_usr_cmd_printf (
4054 "Failed to copy in reply frame, errno=%d\n",
4058 ReplySizeInBytes = (I2O_MESSAGE_FRAME_getMessageSize(
4059 &(Reply_Ptr->StdReplyFrame.StdMessageFrame)) << 2);
4060 free (Reply_Ptr, M_TEMP);
4061 if (ReplySizeInBytes < sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME)) {
4062 free (Message_Ptr, M_TEMP);
4063 debug_usr_cmd_printf (
4064 "Failed to copy in reply frame[%d], errno=%d\n",
4065 ReplySizeInBytes, error);
4069 if ((Reply_Ptr = (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)malloc (
4070 ((ReplySizeInBytes > sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME))
4072 : sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)),
4073 M_TEMP, M_WAITOK)) == (PI2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)NULL) {
4074 free (Message_Ptr, M_TEMP);
4075 debug_usr_cmd_printf ("Failed to acquire frame[%d] memory\n",
4079 (void)ASR_fillMessage ((char *)Reply_Ptr, ReplySizeInBytes);
4080 Reply_Ptr->StdReplyFrame.StdMessageFrame.InitiatorContext
4081 = Message_Ptr->InitiatorContext;
4082 Reply_Ptr->StdReplyFrame.TransactionContext
4083 = ((PI2O_PRIVATE_MESSAGE_FRAME)Message_Ptr)->TransactionContext;
4084 I2O_MESSAGE_FRAME_setMsgFlags(
4085 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
4086 I2O_MESSAGE_FRAME_getMsgFlags(
4087 &(Reply_Ptr->StdReplyFrame.StdMessageFrame))
4088 | I2O_MESSAGE_FLAGS_REPLY);
4090 /* Check if the message is a special case command */
4091 switch (I2O_MESSAGE_FRAME_getFunction(Message_Ptr)) {
4092 case I2O_EXEC_SYS_TAB_SET: /* Special Case of empty Scatter Gather */
4093 if (MessageSizeInBytes == ((I2O_MESSAGE_FRAME_getVersionOffset(
4094 Message_Ptr) & 0xF0) >> 2)) {
4095 free (Message_Ptr, M_TEMP);
4096 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
4097 &(Reply_Ptr->StdReplyFrame),
4098 (ASR_setSysTab(sc) != CAM_REQ_CMP));
4099 I2O_MESSAGE_FRAME_setMessageSize(
4100 &(Reply_Ptr->StdReplyFrame.StdMessageFrame),
4101 sizeof(I2O_SINGLE_REPLY_MESSAGE_FRAME));
4102 error = copyout ((caddr_t)Reply_Ptr, (caddr_t)Reply,
4104 free (Reply_Ptr, M_TEMP);
4109 /* Deal in the general case */
4110 /* First allocate and optionally copy in each scatter gather element */
4111 SLIST_INIT(&sgList);
4112 if ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0) != 0) {
4113 PI2O_SGE_SIMPLE_ELEMENT sg;
4116 * since this code is reused in several systems, code
4117 * efficiency is greater by using a shift operation rather
4118 * than a divide by sizeof(u_int32_t).
4120 sg = (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
4121 + ((I2O_MESSAGE_FRAME_getVersionOffset(Message_Ptr) & 0xF0)
4123 while (sg < (PI2O_SGE_SIMPLE_ELEMENT)(((caddr_t)Message_Ptr)
4124 + MessageSizeInBytes)) {
4128 if ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
4129 & I2O_SGL_FLAGS_SIMPLE_ADDRESS_ELEMENT) == 0) {
4133 len = I2O_FLAGS_COUNT_getCount(&(sg->FlagsCount));
4134 debug_usr_cmd_printf ("SG[%d] = %x[%d]\n",
4135 sg - (PI2O_SGE_SIMPLE_ELEMENT)((char *)Message_Ptr
4136 + ((I2O_MESSAGE_FRAME_getVersionOffset(
4137 Message_Ptr) & 0xF0) >> 2)),
4138 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg), len);
4140 if ((elm = (struct ioctlSgList_S *)malloc (
4141 sizeof(*elm) - sizeof(elm->KernelSpace) + len,
4143 == (struct ioctlSgList_S *)NULL) {
4144 debug_usr_cmd_printf (
4145 "Failed to allocate SG[%d]\n", len);
4149 SLIST_INSERT_HEAD(&sgList, elm, link);
4150 elm->FlagsCount = sg->FlagsCount;
4151 elm->UserSpace = (caddr_t)
4152 (I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg));
4153 v = elm->KernelSpace;
4154 /* Copy in outgoing data (DIR bit could be invalid) */
4155 if ((error = copyin (elm->UserSpace, (caddr_t)v, len))
4160 * If the buffer is not contiguous, lets
4161 * break up the scatter/gather entries.
4164 && (sg < (PI2O_SGE_SIMPLE_ELEMENT)
4165 (((caddr_t)Message_Ptr) + MAX_INBOUND_SIZE))) {
4166 int next, base, span;
4169 next = base = KVTOPHYS(v);
4170 I2O_SGE_SIMPLE_ELEMENT_setPhysicalAddress(sg,
4173 /* How far can we go physically contiguously */
4174 while ((len > 0) && (base == next)) {
4177 next = trunc_page(base) + PAGE_SIZE;
4188 /* Construct the Flags */
4189 I2O_FLAGS_COUNT_setCount(&(sg->FlagsCount),
4192 int flags = I2O_FLAGS_COUNT_getFlags(
4193 &(elm->FlagsCount));
4194 /* Any remaining length? */
4197 ~(I2O_SGL_FLAGS_END_OF_BUFFER
4198 | I2O_SGL_FLAGS_LAST_ELEMENT);
4200 I2O_FLAGS_COUNT_setFlags(
4201 &(sg->FlagsCount), flags);
4204 debug_usr_cmd_printf ("sg[%d] = %x[%d]\n",
4205 sg - (PI2O_SGE_SIMPLE_ELEMENT)
4206 ((char *)Message_Ptr
4207 + ((I2O_MESSAGE_FRAME_getVersionOffset(
4208 Message_Ptr) & 0xF0) >> 2)),
4209 I2O_SGE_SIMPLE_ELEMENT_getPhysicalAddress(sg),
4216 * Incrementing requires resizing of the
4217 * packet, and moving up the existing SG
4221 MessageSizeInBytes += sizeof(*sg);
4222 I2O_MESSAGE_FRAME_setMessageSize(Message_Ptr,
4223 I2O_MESSAGE_FRAME_getMessageSize(Message_Ptr)
4224 + (sizeof(*sg) / sizeof(U32)));
4226 PI2O_MESSAGE_FRAME NewMessage_Ptr;
4229 = (PI2O_MESSAGE_FRAME)
4230 malloc (MessageSizeInBytes,
4232 == (PI2O_MESSAGE_FRAME)NULL) {
4233 debug_usr_cmd_printf (
4234 "Failed to acquire frame[%d] memory\n",
4235 MessageSizeInBytes);
4239 span = ((caddr_t)sg)
4240 - (caddr_t)Message_Ptr;
4241 bcopy ((caddr_t)Message_Ptr,
4242 (caddr_t)NewMessage_Ptr, span);
4243 bcopy ((caddr_t)(sg-1),
4244 ((caddr_t)NewMessage_Ptr) + span,
4245 MessageSizeInBytes - span);
4246 free (Message_Ptr, M_TEMP);
4247 sg = (PI2O_SGE_SIMPLE_ELEMENT)
4248 (((caddr_t)NewMessage_Ptr) + span);
4249 Message_Ptr = NewMessage_Ptr;
4253 || ((I2O_FLAGS_COUNT_getFlags(&(sg->FlagsCount))
4254 & I2O_SGL_FLAGS_LAST_ELEMENT) != 0)) {
4260 while ((elm = SLIST_FIRST(&sgList))
4261 != (struct ioctlSgList_S *)NULL) {
4262 SLIST_REMOVE_HEAD(&sgList, link);
4265 free (Reply_Ptr, M_TEMP);
4266 free (Message_Ptr, M_TEMP);
4271 debug_usr_cmd_printf ("Inbound: ");
4272 debug_usr_cmd_dump_message(Message_Ptr);
4274 /* Send the command */
4275 if ((ccb = asr_alloc_ccb (sc)) == (union asr_ccb *)NULL) {
4276 /* Free up in-kernel buffers */
4277 while ((elm = SLIST_FIRST(&sgList))
4278 != (struct ioctlSgList_S *)NULL) {
4279 SLIST_REMOVE_HEAD(&sgList, link);
4282 free (Reply_Ptr, M_TEMP);
4283 free (Message_Ptr, M_TEMP);
4288 * We do not need any (optional byteswapping) method access to
4289 * the Initiator context field.
4291 I2O_MESSAGE_FRAME_setInitiatorContext64(
4292 (PI2O_MESSAGE_FRAME)Message_Ptr, (long)ccb);
4294 (void)ASR_queue (sc, (PI2O_MESSAGE_FRAME)Message_Ptr);
4296 free (Message_Ptr, M_TEMP);
4299 * Wait for the board to report a finished instruction.
4302 while ((ccb->ccb_h.status & CAM_STATUS_MASK) == CAM_REQ_INPROG) {
4303 if (ASR_getBlinkLedCode(sc)) {
4305 printf ("asr%d: Blink LED 0x%x resetting adapter\n",
4306 cam_sim_unit(xpt_path_sim(ccb->ccb_h.path)),
4307 ASR_getBlinkLedCode(sc));
4308 if (ASR_reset (sc) == ENXIO) {
4309 /* Command Cleanup */
4310 ASR_ccbRemove(sc, ccb);
4313 /* Free up in-kernel buffers */
4314 while ((elm = SLIST_FIRST(&sgList))
4315 != (struct ioctlSgList_S *)NULL) {
4316 SLIST_REMOVE_HEAD(&sgList, link);
4319 free (Reply_Ptr, M_TEMP);
4323 /* Check every second for BlinkLed */
4324 tsleep((caddr_t)ccb, 0, "asr", hz);
4328 debug_usr_cmd_printf ("Outbound: ");
4329 debug_usr_cmd_dump_message(Reply_Ptr);
4331 I2O_SINGLE_REPLY_MESSAGE_FRAME_setDetailedStatusCode(
4332 &(Reply_Ptr->StdReplyFrame),
4333 (ccb->ccb_h.status != CAM_REQ_CMP));
4335 if (ReplySizeInBytes >= (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4336 - I2O_SCSI_SENSE_DATA_SZ - sizeof(U32))) {
4337 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setTransferCount(Reply_Ptr,
4338 ccb->csio.dxfer_len - ccb->csio.resid);
4340 if ((ccb->ccb_h.status & CAM_AUTOSNS_VALID) && (ReplySizeInBytes
4341 > (sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4342 - I2O_SCSI_SENSE_DATA_SZ))) {
4343 int size = ReplySizeInBytes
4344 - sizeof(I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME)
4345 - I2O_SCSI_SENSE_DATA_SZ;
4347 if (size > sizeof(ccb->csio.sense_data)) {
4348 size = sizeof(ccb->csio.sense_data);
4350 bcopy ((caddr_t)&(ccb->csio.sense_data), (caddr_t)Reply_Ptr->SenseData,
4352 I2O_SCSI_ERROR_REPLY_MESSAGE_FRAME_setAutoSenseTransferCount(
4356 /* Free up in-kernel buffers */
4357 while ((elm = SLIST_FIRST(&sgList)) != (struct ioctlSgList_S *)NULL) {
4358 /* Copy out as necessary */
4360 /* DIR bit considered `valid', error due to ignorance works */
4361 && ((I2O_FLAGS_COUNT_getFlags(&(elm->FlagsCount))
4362 & I2O_SGL_FLAGS_DIR) == 0)) {
4363 error = copyout ((caddr_t)(elm->KernelSpace),
4365 I2O_FLAGS_COUNT_getCount(&(elm->FlagsCount)));
4367 SLIST_REMOVE_HEAD(&sgList, link);
4371 /* Copy reply frame to user space */
4372 error = copyout ((caddr_t)Reply_Ptr, (caddr_t)Reply,
4375 free (Reply_Ptr, M_TEMP);
4381 /*----------------------------------------------------------------------*/
4382 /* Function asr_ioctl */
4383 /*----------------------------------------------------------------------*/
4384 /* The parameters passed to this function are : */
4385 /* dev : Device number. */
4386 /* cmd : Ioctl Command */
4387 /* data : User Argument Passed In. */
4388 /* flag : Mode Parameter */
4389 /* proc : Process Parameter */
4391 /* This function is the user interface into this adapter driver */
4393 /* Return : zero if OK, error code if not */
4394 /*----------------------------------------------------------------------*/
4406 Asr_softc_t * sc = ASR_get_sc (dev);
4407 UNREFERENCED_PARAMETER(flag);
4408 UNREFERENCED_PARAMETER(td);
4410 if (sc != (Asr_softc_t *)NULL)
4414 # if (dsDescription_size != 50)
4415 case DPT_SIGNATURE + ((50 - dsDescription_size) << 16):
4417 if (cmd & 0xFFFF0000) {
4418 (void)bcopy ((caddr_t)(&ASR_sig), data,
4422 /* Traditional version of the ioctl interface */
4423 case DPT_SIGNATURE & 0x0000FFFF:
4424 return (copyout ((caddr_t)(&ASR_sig), *((caddr_t *)data),
4425 sizeof(dpt_sig_S)));
4427 /* Traditional version of the ioctl interface */
4428 case DPT_CTRLINFO & 0x0000FFFF:
4429 case DPT_CTRLINFO: {
4432 u_int16_t drvrHBAnum;
4434 u_int16_t blinkState;
4436 u_int8_t pciDeviceNum;
4438 u_int16_t Interrupt;
4439 u_int32_t reserved1;
4440 u_int32_t reserved2;
4441 u_int32_t reserved3;
4444 bzero (&CtlrInfo, sizeof(CtlrInfo));
4445 CtlrInfo.length = sizeof(CtlrInfo) - sizeof(u_int16_t);
4446 CtlrInfo.drvrHBAnum = asr_unit(dev);
4447 CtlrInfo.baseAddr = (u_long)sc->ha_Base;
4448 i = ASR_getBlinkLedCode (sc);
4452 CtlrInfo.blinkState = i;
4453 CtlrInfo.pciBusNum = sc->ha_pciBusNum;
4454 CtlrInfo.pciDeviceNum = sc->ha_pciDeviceNum;
4455 #define FLG_OSD_PCI_VALID 0x0001
4456 #define FLG_OSD_DMA 0x0002
4457 #define FLG_OSD_I2O 0x0004
4458 CtlrInfo.hbaFlags = FLG_OSD_PCI_VALID | FLG_OSD_DMA | FLG_OSD_I2O;
4459 CtlrInfo.Interrupt = sc->ha_irq;
4460 if (cmd & 0xFFFF0000) {
4461 bcopy (&CtlrInfo, data, sizeof(CtlrInfo));
4463 error = copyout (&CtlrInfo, *(caddr_t *)data, sizeof(CtlrInfo));
4467 /* Traditional version of the ioctl interface */
4468 case DPT_SYSINFO & 0x0000FFFF:
4472 /* Kernel Specific ptok `hack' */
4473 # define ptok(a) ((char *)(a) + KERNBASE)
4475 bzero (&Info, sizeof(Info));
4477 /* Appears I am the only person in the Kernel doing this */
4485 Info.drive0CMOS = j;
4492 Info.drive1CMOS = j;
4494 Info.numDrives = *((char *)ptok(0x475));
4496 Info.processorFamily = ASR_sig.dsProcessorFamily;
4498 case CPU_386SX: case CPU_386:
4499 Info.processorType = PROC_386; break;
4500 case CPU_486SX: case CPU_486:
4501 Info.processorType = PROC_486; break;
4503 Info.processorType = PROC_PENTIUM; break;
4505 Info.processorType = PROC_SEXIUM; break;
4507 Info.osType = OS_BSDI_UNIX;
4508 Info.osMajorVersion = osrelease[0] - '0';
4509 Info.osMinorVersion = osrelease[2] - '0';
4510 /* Info.osRevision = 0; */
4511 /* Info.osSubRevision = 0; */
4512 Info.busType = SI_PCI_BUS;
4513 Info.flags = SI_CMOS_Valid | SI_NumDrivesValid
4514 | SI_OSversionValid | SI_BusTypeValid | SI_NO_SmartROM;
4516 /* Go Out And Look For I2O SmartROM */
4517 for(j = 0xC8000; j < 0xE0000; j += 2048) {
4521 if (*((unsigned short *)cp) != 0xAA55) {
4524 j += (cp[2] * 512) - 2048;
4525 if ((*((u_long *)(cp + 6))
4526 != ('S' + (' ' * 256) + (' ' * 65536L)))
4527 || (*((u_long *)(cp + 10))
4528 != ('I' + ('2' * 256) + ('0' * 65536L)))) {
4532 for (k = 0; k < 64; ++k) {
4533 if (*((unsigned short *)cp)
4534 == (' ' + ('v' * 256))) {
4539 Info.smartROMMajorVersion
4540 = *((unsigned char *)(cp += 4)) - '0';
4541 Info.smartROMMinorVersion
4542 = *((unsigned char *)(cp += 2));
4543 Info.smartROMRevision
4544 = *((unsigned char *)(++cp));
4545 Info.flags |= SI_SmartROMverValid;
4546 Info.flags &= ~SI_NO_SmartROM;
4550 /* Get The Conventional Memory Size From CMOS */
4556 Info.conventionalMemSize = j;
4558 /* Get The Extended Memory Found At Power On From CMOS */
4564 Info.extendedMemSize = j;
4565 Info.flags |= SI_MemorySizeValid;
4567 # if (defined(THIS_IS_BROKEN))
4568 /* If There Is 1 or 2 Drives Found, Set Up Drive Parameters */
4569 if (Info.numDrives > 0) {
4571 * Get The Pointer From Int 41 For The First
4574 j = ((unsigned)(*((unsigned short *)ptok(0x104+2))) << 4)
4575 + (unsigned)(*((unsigned short *)ptok(0x104+0)));
4577 * It appears that SmartROM's Int41/Int46 pointers
4578 * use memory that gets stepped on by the kernel
4579 * loading. We no longer have access to this
4580 * geometry information but try anyways (!?)
4582 Info.drives[0].cylinders = *((unsigned char *)ptok(j));
4584 Info.drives[0].cylinders += ((int)*((unsigned char *)
4587 Info.drives[0].heads = *((unsigned char *)ptok(j));
4589 Info.drives[0].sectors = *((unsigned char *)ptok(j));
4590 Info.flags |= SI_DriveParamsValid;
4591 if ((Info.drives[0].cylinders == 0)
4592 || (Info.drives[0].heads == 0)
4593 || (Info.drives[0].sectors == 0)) {
4594 Info.flags &= ~SI_DriveParamsValid;
4596 if (Info.numDrives > 1) {
4598 * Get The Pointer From Int 46 For The
4599 * Second Drive Parameters
4601 j = ((unsigned)(*((unsigned short *)ptok(0x118+2))) << 4)
4602 + (unsigned)(*((unsigned short *)ptok(0x118+0)));
4603 Info.drives[1].cylinders = *((unsigned char *)
4606 Info.drives[1].cylinders += ((int)
4607 *((unsigned char *)ptok(j))) << 8;
4609 Info.drives[1].heads = *((unsigned char *)
4612 Info.drives[1].sectors = *((unsigned char *)
4614 if ((Info.drives[1].cylinders == 0)
4615 || (Info.drives[1].heads == 0)
4616 || (Info.drives[1].sectors == 0)) {
4617 Info.flags &= ~SI_DriveParamsValid;
4622 /* Copy Out The Info Structure To The User */
4623 if (cmd & 0xFFFF0000) {
4624 bcopy (&Info, data, sizeof(Info));
4626 error = copyout (&Info, *(caddr_t *)data, sizeof(Info));
4630 /* Get The BlinkLED State */
4632 i = ASR_getBlinkLedCode (sc);
4636 if (cmd & 0xFFFF0000) {
4637 bcopy ((caddr_t)(&i), data, sizeof(i));
4639 error = copyout (&i, *(caddr_t *)data, sizeof(i));
4643 /* Get performance metrics */
4644 #ifdef ASR_MEASURE_PERFORMANCE
4646 bcopy((caddr_t) &(sc->ha_performance), data,
4647 sizeof(sc->ha_performance));
4651 /* Send an I2O command */
4653 return (ASR_queue_i (sc, *((PI2O_MESSAGE_FRAME *)data)));
4655 /* Reset and re-initialize the adapter */
4657 return (ASR_reset (sc));
4659 /* Rescan the LCT table and resynchronize the information */
4661 return (ASR_rescan (sc));
4666 #ifdef ASR_MEASURE_PERFORMANCE
4668 * This function subtracts one timeval structure from another,
4669 * Returning the result in usec.
4670 * It assumes that less than 4 billion usecs passed form start to end.
4671 * If times are sensless, 0xffffffff is returned.
4676 IN struct timeval start,
4677 IN struct timeval end)
4679 OUT u_int32_t result;
4681 if (start.tv_sec > end.tv_sec) {
4682 result = 0xffffffff;
4685 if (start.tv_sec == end.tv_sec) {
4686 if (start.tv_usec > end.tv_usec) {
4687 result = 0xffffffff;
4689 return (end.tv_usec - start.tv_usec);
4692 return (end.tv_sec - start.tv_sec) * 1000000 +
4693 end.tv_usec + (1000000 - start.tv_usec);
4697 } /* asr_time_delta */