[PATCH] ppc32: add watchdog & RTC support for Marvell EV64360BP board
[linux/fpc-iii.git] / drivers / scsi / FlashPoint.c
blob5beed4f6d985a7b2bd2c9f007b2e49158989ec31
1 /*
3 FlashPoint.c -- FlashPoint SCCB Manager for Linux
5 This file contains the FlashPoint SCCB Manager from BusLogic's FlashPoint
6 Driver Developer's Kit, with minor modifications by Leonard N. Zubkoff for
7 Linux compatibility. It was provided by BusLogic in the form of 16 separate
8 source files, which would have unnecessarily cluttered the scsi directory, so
9 the individual files have been combined into this single file.
11 Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
13 This file is available under both the GNU General Public License
14 and a BSD-style copyright; see LICENSE.FlashPoint for details.
19 #include <linux/config.h>
22 #ifndef CONFIG_SCSI_OMIT_FLASHPOINT
25 #define MAX_CARDS 8
26 #undef BUSTYPE_PCI
29 #define OS_InPortByte(port) inb(port)
30 #define OS_InPortWord(port) inw(port)
31 #define OS_InPortLong(port) inl(port)
32 #define OS_OutPortByte(port, value) outb(value, port)
33 #define OS_OutPortWord(port, value) outw(value, port)
34 #define OS_OutPortLong(port, value) outl(value, port)
38 Define name replacements for compatibility with the Linux BusLogic Driver.
41 #define SccbMgr_sense_adapter FlashPoint_ProbeHostAdapter
42 #define SccbMgr_config_adapter FlashPoint_HardwareResetHostAdapter
43 #define SccbMgr_unload_card FlashPoint_ReleaseHostAdapter
44 #define SccbMgr_start_sccb FlashPoint_StartCCB
45 #define SccbMgr_abort_sccb FlashPoint_AbortCCB
46 #define SccbMgr_my_int FlashPoint_InterruptPending
47 #define SccbMgr_isr FlashPoint_HandleInterrupt
50 #define MAX_CDBLEN 12
52 #define SCAM_LEV_2 1
54 #define CRCMASK 0xA001
56 #define BL_VENDOR_ID 0x104B
57 #define FP_DEVICE_ID 0x8130
58 #define MM_DEVICE_ID 0x1040
61 #define FAILURE 0xFFFFFFFFL
64 typedef unsigned char UCHAR;
65 typedef unsigned short USHORT;
66 typedef unsigned int UINT;
67 typedef unsigned long ULONG;
68 typedef unsigned char * PUCHAR;
69 typedef unsigned short* PUSHORT;
70 typedef unsigned long * PULONG;
71 typedef void * PVOID;
74 typedef unsigned char * uchar_ptr;
75 typedef unsigned short * ushort_ptr;
76 typedef unsigned long * ulong_ptr;
79 #define s08bits char
80 #define s16bits short
81 #define s32bits long
83 #define u08bits unsigned s08bits
84 #define u16bits unsigned s16bits
85 #define u32bits unsigned s32bits
87 typedef u08bits * pu08bits;
88 typedef u16bits * pu16bits;
89 typedef u32bits * pu32bits;
92 #define BIT(x) ((UCHAR)(1<<(x))) /* single-bit mask in bit position x */
93 #define BITW(x) ((USHORT)(1<<(x))) /* single-bit mask in bit position x */
98 typedef struct _SCCB *PSCCB;
99 typedef void (*CALL_BK_FN)(PSCCB);
102 typedef struct SCCBMgr_info {
103 ULONG si_baseaddr;
104 UCHAR si_present;
105 UCHAR si_intvect;
106 UCHAR si_id;
107 UCHAR si_lun;
108 USHORT si_fw_revision;
109 USHORT si_per_targ_init_sync;
110 USHORT si_per_targ_fast_nego;
111 USHORT si_per_targ_ultra_nego;
112 USHORT si_per_targ_no_disc;
113 USHORT si_per_targ_wide_nego;
114 USHORT si_flags;
115 UCHAR si_card_family;
116 UCHAR si_bustype;
117 UCHAR si_card_model[3];
118 UCHAR si_relative_cardnum;
119 UCHAR si_reserved[4];
120 ULONG si_OS_reserved;
121 UCHAR si_XlatInfo[4];
122 ULONG si_reserved2[5];
123 ULONG si_secondary_range;
124 } SCCBMGR_INFO;
126 typedef SCCBMGR_INFO * PSCCBMGR_INFO;
129 #define SCSI_PARITY_ENA 0x0001
130 #define LOW_BYTE_TERM 0x0010
131 #define HIGH_BYTE_TERM 0x0020
132 #define BUSTYPE_PCI 0x3
134 #define SUPPORT_16TAR_32LUN 0x0002
135 #define SOFT_RESET 0x0004
136 #define EXTENDED_TRANSLATION 0x0008
137 #define POST_ALL_UNDERRRUNS 0x0040
138 #define FLAG_SCAM_ENABLED 0x0080
139 #define FLAG_SCAM_LEVEL2 0x0100
144 #define HARPOON_FAMILY 0x02
147 #define ISA_BUS_CARD 0x01
148 #define EISA_BUS_CARD 0x02
149 #define PCI_BUS_CARD 0x03
150 #define VESA_BUS_CARD 0x04
152 /* SCCB struc used for both SCCB and UCB manager compiles!
153 * The UCB Manager treats the SCCB as it's 'native hardware structure'
157 #pragma pack(1)
158 typedef struct _SCCB {
159 UCHAR OperationCode;
160 UCHAR ControlByte;
161 UCHAR CdbLength;
162 UCHAR RequestSenseLength;
163 ULONG DataLength;
164 ULONG DataPointer;
165 UCHAR CcbRes[2];
166 UCHAR HostStatus;
167 UCHAR TargetStatus;
168 UCHAR TargID;
169 UCHAR Lun;
170 UCHAR Cdb[12];
171 UCHAR CcbRes1;
172 UCHAR Reserved1;
173 ULONG Reserved2;
174 ULONG SensePointer;
177 CALL_BK_FN SccbCallback; /* VOID (*SccbCallback)(); */
178 ULONG SccbIOPort; /* Identifies board base port */
179 UCHAR SccbStatus;
180 UCHAR SCCBRes2;
181 USHORT SccbOSFlags;
184 ULONG Sccb_XferCnt; /* actual transfer count */
185 ULONG Sccb_ATC;
186 ULONG SccbVirtDataPtr; /* virtual addr for OS/2 */
187 ULONG Sccb_res1;
188 USHORT Sccb_MGRFlags;
189 USHORT Sccb_sgseg;
190 UCHAR Sccb_scsimsg; /* identify msg for selection */
191 UCHAR Sccb_tag;
192 UCHAR Sccb_scsistat;
193 UCHAR Sccb_idmsg; /* image of last msg in */
194 PSCCB Sccb_forwardlink;
195 PSCCB Sccb_backlink;
196 ULONG Sccb_savedATC;
197 UCHAR Save_Cdb[6];
198 UCHAR Save_CdbLen;
199 UCHAR Sccb_XferState;
200 ULONG Sccb_SGoffset;
201 } SCCB;
203 #define SCCB_SIZE sizeof(SCCB)
205 #pragma pack()
209 #define SCSI_INITIATOR_COMMAND 0x00
210 #define TARGET_MODE_COMMAND 0x01
211 #define SCATTER_GATHER_COMMAND 0x02
212 #define RESIDUAL_COMMAND 0x03
213 #define RESIDUAL_SG_COMMAND 0x04
214 #define RESET_COMMAND 0x81
217 #define F_USE_CMD_Q 0x20 /*Inidcates TAGGED command. */
218 #define TAG_TYPE_MASK 0xC0 /*Type of tag msg to send. */
219 #define TAG_Q_MASK 0xE0
220 #define SCCB_DATA_XFER_OUT 0x10 /* Write */
221 #define SCCB_DATA_XFER_IN 0x08 /* Read */
224 #define FOURTEEN_BYTES 0x00 /* Request Sense Buffer size */
225 #define NO_AUTO_REQUEST_SENSE 0x01 /* No Request Sense Buffer */
228 #define BUS_FREE_ST 0
229 #define SELECT_ST 1
230 #define SELECT_BDR_ST 2 /* Select w\ Bus Device Reset */
231 #define SELECT_SN_ST 3 /* Select w\ Sync Nego */
232 #define SELECT_WN_ST 4 /* Select w\ Wide Data Nego */
233 #define SELECT_Q_ST 5 /* Select w\ Tagged Q'ing */
234 #define COMMAND_ST 6
235 #define DATA_OUT_ST 7
236 #define DATA_IN_ST 8
237 #define DISCONNECT_ST 9
238 #define STATUS_ST 10
239 #define ABORT_ST 11
240 #define MESSAGE_ST 12
243 #define F_HOST_XFER_DIR 0x01
244 #define F_ALL_XFERRED 0x02
245 #define F_SG_XFER 0x04
246 #define F_AUTO_SENSE 0x08
247 #define F_ODD_BALL_CNT 0x10
248 #define F_NO_DATA_YET 0x80
251 #define F_STATUSLOADED 0x01
252 #define F_MSGLOADED 0x02
253 #define F_DEV_SELECTED 0x04
256 #define SCCB_COMPLETE 0x00 /* SCCB completed without error */
257 #define SCCB_DATA_UNDER_RUN 0x0C
258 #define SCCB_SELECTION_TIMEOUT 0x11 /* Set SCSI selection timed out */
259 #define SCCB_DATA_OVER_RUN 0x12
260 #define SCCB_UNEXPECTED_BUS_FREE 0x13 /* Target dropped SCSI BSY */
261 #define SCCB_PHASE_SEQUENCE_FAIL 0x14 /* Target bus phase sequence failure */
263 #define SCCB_INVALID_OP_CODE 0x16 /* SCCB invalid operation code */
264 #define SCCB_INVALID_SCCB 0x1A /* Invalid SCCB - bad parameter */
265 #define SCCB_GROSS_FW_ERR 0x27 /* Major problem! */
266 #define SCCB_BM_ERR 0x30 /* BusMaster error. */
267 #define SCCB_PARITY_ERR 0x34 /* SCSI parity error */
271 #define SCCB_INVALID_DIRECTION 0x18 /* Invalid target direction */
272 #define SCCB_DUPLICATE_SCCB 0x19 /* Duplicate SCCB */
273 #define SCCB_SCSI_RST 0x35 /* SCSI RESET detected. */
276 #define SCCB_IN_PROCESS 0x00
277 #define SCCB_SUCCESS 0x01
278 #define SCCB_ABORT 0x02
279 #define SCCB_NOT_FOUND 0x03
280 #define SCCB_ERROR 0x04
281 #define SCCB_INVALID 0x05
283 #define SCCB_SIZE sizeof(SCCB)
286 #define ORION_FW_REV 3110
288 #define HARP_REVD 1
291 #define QUEUE_DEPTH 254+1 /*1 for Normal disconnect 32 for Q'ing. */
293 #define MAX_MB_CARDS 4 /* Max. no of cards suppoerted on Mother Board */
295 #define WIDE_SCSI 1
297 #define MAX_SCSI_TAR 16
298 #define MAX_LUN 32
299 #define LUN_MASK 0x1f
301 #if defined(HARP_REVA)
302 #define SG_BUF_CNT 15 /*Number of prefetched elements. */
303 #else
304 #define SG_BUF_CNT 16 /*Number of prefetched elements. */
305 #endif
307 #define SG_ELEMENT_SIZE 8 /*Eight byte per element. */
308 #define SG_LOCAL_MASK 0x00000000L
309 #define SG_ELEMENT_MASK 0xFFFFFFFFL
312 #define RD_HARPOON(ioport) OS_InPortByte((u32bits)ioport)
313 #define RDW_HARPOON(ioport) OS_InPortWord((u32bits)ioport)
314 #define RD_HARP32(ioport,offset,data) (data = OS_InPortLong((u32bits)(ioport + offset)))
315 #define WR_HARPOON(ioport,val) OS_OutPortByte((u32bits)ioport,(u08bits) val)
316 #define WRW_HARPOON(ioport,val) OS_OutPortWord((u32bits)ioport,(u16bits)val)
317 #define WR_HARP32(ioport,offset,data) OS_OutPortLong((u32bits)(ioport + offset), data)
320 #define TAR_SYNC_MASK (BIT(7)+BIT(6))
321 #define SYNC_UNKNOWN 0x00
322 #define SYNC_TRYING BIT(6)
323 #define SYNC_SUPPORTED (BIT(7)+BIT(6))
325 #define TAR_WIDE_MASK (BIT(5)+BIT(4))
326 #define WIDE_DISABLED 0x00
327 #define WIDE_ENABLED BIT(4)
328 #define WIDE_NEGOCIATED BIT(5)
330 #define TAR_TAG_Q_MASK (BIT(3)+BIT(2))
331 #define TAG_Q_UNKNOWN 0x00
332 #define TAG_Q_TRYING BIT(2)
333 #define TAG_Q_REJECT BIT(3)
334 #define TAG_Q_SUPPORTED (BIT(3)+BIT(2))
336 #define TAR_ALLOW_DISC BIT(0)
339 #define EE_SYNC_MASK (BIT(0)+BIT(1))
340 #define EE_SYNC_ASYNC 0x00
341 #define EE_SYNC_5MB BIT(0)
342 #define EE_SYNC_10MB BIT(1)
343 #define EE_SYNC_20MB (BIT(0)+BIT(1))
345 #define EE_ALLOW_DISC BIT(6)
346 #define EE_WIDE_SCSI BIT(7)
349 typedef struct SCCBMgr_tar_info *PSCCBMgr_tar_info;
352 typedef struct SCCBMgr_tar_info {
354 PSCCB TarSelQ_Head;
355 PSCCB TarSelQ_Tail;
356 UCHAR TarLUN_CA; /*Contingent Allgiance */
357 UCHAR TarTagQ_Cnt;
358 UCHAR TarSelQ_Cnt;
359 UCHAR TarStatus;
360 UCHAR TarEEValue;
361 UCHAR TarSyncCtrl;
362 UCHAR TarReserved[2]; /* for alignment */
363 UCHAR LunDiscQ_Idx[MAX_LUN];
364 UCHAR TarLUNBusy[MAX_LUN];
365 } SCCBMGR_TAR_INFO;
367 typedef struct NVRAMInfo {
368 UCHAR niModel; /* Model No. of card */
369 UCHAR niCardNo; /* Card no. */
370 ULONG niBaseAddr; /* Port Address of card */
371 UCHAR niSysConf; /* Adapter Configuration byte - Byte 16 of eeprom map */
372 UCHAR niScsiConf; /* SCSI Configuration byte - Byte 17 of eeprom map */
373 UCHAR niScamConf; /* SCAM Configuration byte - Byte 20 of eeprom map */
374 UCHAR niAdapId; /* Host Adapter ID - Byte 24 of eerpom map */
375 UCHAR niSyncTbl[MAX_SCSI_TAR / 2]; /* Sync/Wide byte of targets */
376 UCHAR niScamTbl[MAX_SCSI_TAR][4]; /* Compressed Scam name string of Targets */
377 }NVRAMINFO;
379 typedef NVRAMINFO *PNVRamInfo;
381 #define MODEL_LT 1
382 #define MODEL_DL 2
383 #define MODEL_LW 3
384 #define MODEL_DW 4
387 typedef struct SCCBcard {
388 PSCCB currentSCCB;
389 PSCCBMGR_INFO cardInfo;
391 ULONG ioPort;
393 USHORT cmdCounter;
394 UCHAR discQCount;
395 UCHAR tagQ_Lst;
396 UCHAR cardIndex;
397 UCHAR scanIndex;
398 UCHAR globalFlags;
399 UCHAR ourId;
400 PNVRamInfo pNvRamInfo;
401 PSCCB discQ_Tbl[QUEUE_DEPTH];
403 }SCCBCARD;
405 typedef struct SCCBcard *PSCCBcard;
408 #define F_TAG_STARTED 0x01
409 #define F_CONLUN_IO 0x02
410 #define F_DO_RENEGO 0x04
411 #define F_NO_FILTER 0x08
412 #define F_GREEN_PC 0x10
413 #define F_HOST_XFER_ACT 0x20
414 #define F_NEW_SCCB_CMD 0x40
415 #define F_UPDATE_EEPROM 0x80
418 #define ID_STRING_LENGTH 32
419 #define TYPE_CODE0 0x63 /*Level2 Mstr (bits 7-6), */
421 #define TYPE_CODE1 00 /*No ID yet */
423 #define SLV_TYPE_CODE0 0xA3 /*Priority Bit set (bits 7-6), */
425 #define ASSIGN_ID 0x00
426 #define SET_P_FLAG 0x01
427 #define CFG_CMPLT 0x03
428 #define DOM_MSTR 0x0F
429 #define SYNC_PTRN 0x1F
431 #define ID_0_7 0x18
432 #define ID_8_F 0x11
433 #define ID_10_17 0x12
434 #define ID_18_1F 0x0B
435 #define MISC_CODE 0x14
436 #define CLR_P_FLAG 0x18
437 #define LOCATE_ON 0x12
438 #define LOCATE_OFF 0x0B
440 #define LVL_1_MST 0x00
441 #define LVL_2_MST 0x40
442 #define DOM_LVL_2 0xC0
445 #define INIT_SELTD 0x01
446 #define LEVEL2_TAR 0x02
449 enum scam_id_st { ID0,ID1,ID2,ID3,ID4,ID5,ID6,ID7,ID8,ID9,ID10,ID11,ID12,
450 ID13,ID14,ID15,ID_UNUSED,ID_UNASSIGNED,ID_ASSIGNED,LEGACY,
451 CLR_PRIORITY,NO_ID_AVAIL };
453 typedef struct SCCBscam_info {
455 UCHAR id_string[ID_STRING_LENGTH];
456 enum scam_id_st state;
458 } SCCBSCAM_INFO, *PSCCBSCAM_INFO;
461 #define SCSI_TEST_UNIT_READY 0x00
462 #define SCSI_REZERO_UNIT 0x01
463 #define SCSI_REQUEST_SENSE 0x03
464 #define SCSI_FORMAT_UNIT 0x04
465 #define SCSI_REASSIGN 0x07
466 #define SCSI_READ 0x08
467 #define SCSI_WRITE 0x0A
468 #define SCSI_SEEK 0x0B
469 #define SCSI_INQUIRY 0x12
470 #define SCSI_MODE_SELECT 0x15
471 #define SCSI_RESERVE_UNIT 0x16
472 #define SCSI_RELEASE_UNIT 0x17
473 #define SCSI_MODE_SENSE 0x1A
474 #define SCSI_START_STOP_UNIT 0x1B
475 #define SCSI_SEND_DIAGNOSTIC 0x1D
476 #define SCSI_READ_CAPACITY 0x25
477 #define SCSI_READ_EXTENDED 0x28
478 #define SCSI_WRITE_EXTENDED 0x2A
479 #define SCSI_SEEK_EXTENDED 0x2B
480 #define SCSI_WRITE_AND_VERIFY 0x2E
481 #define SCSI_VERIFY 0x2F
482 #define SCSI_READ_DEFECT_DATA 0x37
483 #define SCSI_WRITE_BUFFER 0x3B
484 #define SCSI_READ_BUFFER 0x3C
485 #define SCSI_RECV_DIAGNOSTIC 0x1C
486 #define SCSI_READ_LONG 0x3E
487 #define SCSI_WRITE_LONG 0x3F
488 #define SCSI_LAST_SCSI_CMND SCSI_WRITE_LONG
489 #define SCSI_INVALID_CMND 0xFF
493 #define SSGOOD 0x00
494 #define SSCHECK 0x02
495 #define SSCOND_MET 0x04
496 #define SSBUSY 0x08
497 #define SSRESERVATION_CONFLICT 0x18
498 #define SSCMD_TERM 0x22
499 #define SSQ_FULL 0x28
502 #define SKNO_SEN 0x00
503 #define SKRECOV_ERR 0x01
504 #define SKNOT_RDY 0x02
505 #define SKMED_ERR 0x03
506 #define SKHW_ERR 0x04
507 #define SKILL_REQ 0x05
508 #define SKUNIT_ATTN 0x06
509 #define SKDATA_PROTECT 0x07
510 #define SKBLNK_CHK 0x08
511 #define SKCPY_ABORT 0x0A
512 #define SKABORT_CMD 0x0B
513 #define SKEQUAL 0x0C
514 #define SKVOL_OVF 0x0D
515 #define SKMIS_CMP 0x0E
518 #define SMCMD_COMP 0x00
519 #define SMEXT 0x01
520 #define SMSAVE_DATA_PTR 0x02
521 #define SMREST_DATA_PTR 0x03
522 #define SMDISC 0x04
523 #define SMINIT_DETEC_ERR 0x05
524 #define SMABORT 0x06
525 #define SMREJECT 0x07
526 #define SMNO_OP 0x08
527 #define SMPARITY 0x09
528 #define SMDEV_RESET 0x0C
529 #define SMABORT_TAG 0x0D
530 #define SMINIT_RECOVERY 0x0F
531 #define SMREL_RECOVERY 0x10
533 #define SMIDENT 0x80
534 #define DISC_PRIV 0x40
537 #define SMSYNC 0x01
538 #define SM10MBS 0x19 /* 100ns */
539 #define SM5MBS 0x32 /* 200ns */
540 #define SMOFFSET 0x0F /* Maxoffset value */
541 #define SMWDTR 0x03
542 #define SM8BIT 0x00
543 #define SM16BIT 0x01
544 #define SM32BIT 0x02
545 #define SMIGNORWR 0x23 /* Ignore Wide Residue */
548 #define ARBITRATION_DELAY 0x01 /* 2.4us using a 40Mhz clock */
549 #define BUS_SETTLE_DELAY 0x01 /* 400ns */
550 #define BUS_CLEAR_DELAY 0x01 /* 800ns */
554 #define SPHASE_TO 0x0A /* 10 second timeout waiting for */
555 #define SCMD_TO 0x0F /* Overall command timeout */
559 #define SIX_BYTE_CMD 0x06
560 #define TEN_BYTE_CMD 0x0A
561 #define TWELVE_BYTE_CMD 0x0C
563 #define ASYNC 0x00
564 #define PERI25NS 0x06 /* 25/4ns to next clock for xbow. */
565 #define SYNC10MBS 0x19
566 #define SYNC5MBS 0x32
567 #define MAX_OFFSET 0x0F /* Maxbyteoffset for Sync Xfers */
570 #define EEPROM_WD_CNT 256
572 #define EEPROM_CHECK_SUM 0
573 #define FW_SIGNATURE 2
574 #define MODEL_NUMB_0 4
575 #define MODEL_NUMB_1 5
576 #define MODEL_NUMB_2 6
577 #define MODEL_NUMB_3 7
578 #define MODEL_NUMB_4 8
579 #define MODEL_NUMB_5 9
580 #define IO_BASE_ADDR 10
581 #define IRQ_NUMBER 12
582 #define PCI_INT_PIN 13
583 #define BUS_DELAY 14 /*On time in byte 14 off delay in 15 */
584 #define SYSTEM_CONFIG 16
585 #define SCSI_CONFIG 17
586 #define BIOS_CONFIG 18
587 #define SPIN_UP_DELAY 19
588 #define SCAM_CONFIG 20
589 #define ADAPTER_SCSI_ID 24
592 #define IGNORE_B_SCAN 32
593 #define SEND_START_ENA 34
594 #define DEVICE_ENABLE 36
596 #define SYNC_RATE_TBL 38
597 #define SYNC_RATE_TBL01 38
598 #define SYNC_RATE_TBL23 40
599 #define SYNC_RATE_TBL45 42
600 #define SYNC_RATE_TBL67 44
601 #define SYNC_RATE_TBL89 46
602 #define SYNC_RATE_TBLab 48
603 #define SYNC_RATE_TBLcd 50
604 #define SYNC_RATE_TBLef 52
608 #define EE_SCAMBASE 256
612 #define DOM_MASTER (BIT(0) + BIT(1))
613 #define SCAM_ENABLED BIT(2)
614 #define SCAM_LEVEL2 BIT(3)
617 #define RENEGO_ENA BITW(10)
618 #define CONNIO_ENA BITW(11)
619 #define GREEN_PC_ENA BITW(12)
622 #define AUTO_RATE_00 00
623 #define AUTO_RATE_05 01
624 #define AUTO_RATE_10 02
625 #define AUTO_RATE_20 03
627 #define WIDE_NEGO_BIT BIT(7)
628 #define DISC_ENABLE_BIT BIT(6)
632 #define hp_vendor_id_0 0x00 /* LSB */
633 #define ORION_VEND_0 0x4B
635 #define hp_vendor_id_1 0x01 /* MSB */
636 #define ORION_VEND_1 0x10
638 #define hp_device_id_0 0x02 /* LSB */
639 #define ORION_DEV_0 0x30
641 #define hp_device_id_1 0x03 /* MSB */
642 #define ORION_DEV_1 0x81
644 /* Sub Vendor ID and Sub Device ID only available in
645 Harpoon Version 2 and higher */
647 #define hp_sub_vendor_id_0 0x04 /* LSB */
648 #define hp_sub_vendor_id_1 0x05 /* MSB */
649 #define hp_sub_device_id_0 0x06 /* LSB */
650 #define hp_sub_device_id_1 0x07 /* MSB */
653 #define hp_dual_addr_lo 0x08
654 #define hp_dual_addr_lmi 0x09
655 #define hp_dual_addr_hmi 0x0A
656 #define hp_dual_addr_hi 0x0B
658 #define hp_semaphore 0x0C
659 #define SCCB_MGR_ACTIVE BIT(0)
660 #define TICKLE_ME BIT(1)
661 #define SCCB_MGR_PRESENT BIT(3)
662 #define BIOS_IN_USE BIT(4)
664 #define hp_user_defined_D 0x0D
666 #define hp_reserved_E 0x0E
668 #define hp_sys_ctrl 0x0F
670 #define STOP_CLK BIT(0) /*Turn off BusMaster Clock */
671 #define DRVR_RST BIT(1) /*Firmware Reset to 80C15 chip */
672 #define HALT_MACH BIT(3) /*Halt State Machine */
673 #define HARD_ABORT BIT(4) /*Hard Abort */
674 #define DIAG_MODE BIT(5) /*Diagnostic Mode */
676 #define BM_ABORT_TMOUT 0x50 /*Halt State machine time out */
678 #define hp_sys_cfg 0x10
680 #define DONT_RST_FIFO BIT(7) /*Don't reset FIFO */
683 #define hp_host_ctrl0 0x11
685 #define DUAL_ADDR_MODE BIT(0) /*Enable 64-bit addresses */
686 #define IO_MEM_SPACE BIT(1) /*I/O Memory Space */
687 #define RESOURCE_LOCK BIT(2) /*Enable Resource Lock */
688 #define IGNOR_ACCESS_ERR BIT(3) /*Ignore Access Error */
689 #define HOST_INT_EDGE BIT(4) /*Host interrupt level/edge mode sel */
690 #define SIX_CLOCKS BIT(5) /*6 Clocks between Strobe */
691 #define DMA_EVEN_PARITY BIT(6) /*Enable DMA Enen Parity */
694 #define BURST_MODE BIT(0)
697 #define hp_reserved_12 0x12
699 #define hp_host_blk_cnt 0x13
701 #define XFER_BLK1 0x00 /* 0 0 0 1 byte per block*/
702 #define XFER_BLK2 0x01 /* 0 0 1 2 byte per block*/
703 #define XFER_BLK4 0x02 /* 0 1 0 4 byte per block*/
704 #define XFER_BLK8 0x03 /* 0 1 1 8 byte per block*/
705 #define XFER_BLK16 0x04 /* 1 0 0 16 byte per block*/
706 #define XFER_BLK32 0x05 /* 1 0 1 32 byte per block*/
707 #define XFER_BLK64 0x06 /* 1 1 0 64 byte per block*/
709 #define BM_THRESHOLD 0x40 /* PCI mode can only xfer 16 bytes*/
712 #define hp_reserved_14 0x14
713 #define hp_reserved_15 0x15
714 #define hp_reserved_16 0x16
716 #define hp_int_mask 0x17
718 #define INT_CMD_COMPL BIT(0) /* DMA command complete */
719 #define INT_EXT_STATUS BIT(1) /* Extended Status Set */
720 #define INT_SCSI BIT(2) /* Scsi block interrupt */
721 #define INT_FIFO_RDY BIT(4) /* FIFO data ready */
724 #define hp_xfer_cnt_lo 0x18
725 #define hp_xfer_cnt_mi 0x19
726 #define hp_xfer_cnt_hi 0x1A
727 #define hp_xfer_cmd 0x1B
729 #define XFER_HOST_DMA 0x00 /* 0 0 0 Transfer Host -> DMA */
730 #define XFER_DMA_HOST 0x01 /* 0 0 1 Transfer DMA -> Host */
731 #define XFER_HOST_MPU 0x02 /* 0 1 0 Transfer Host -> MPU */
732 #define XFER_MPU_HOST 0x03 /* 0 1 1 Transfer MPU -> Host */
733 #define XFER_DMA_MPU 0x04 /* 1 0 0 Transfer DMA -> MPU */
734 #define XFER_MPU_DMA 0x05 /* 1 0 1 Transfer MPU -> DMA */
735 #define SET_SEMAPHORE 0x06 /* 1 1 0 Set Semaphore */
736 #define XFER_NOP 0x07 /* 1 1 1 Transfer NOP */
737 #define XFER_MB_MPU 0x06 /* 1 1 0 Transfer MB -> MPU */
738 #define XFER_MB_DMA 0x07 /* 1 1 1 Transfer MB -> DMA */
741 #define XFER_HOST_AUTO 0x00 /* 0 0 Auto Transfer Size */
742 #define XFER_HOST_8BIT 0x08 /* 0 1 8 BIT Transfer Size */
743 #define XFER_HOST_16BIT 0x10 /* 1 0 16 BIT Transfer Size */
744 #define XFER_HOST_32BIT 0x18 /* 1 1 32 BIT Transfer Size */
746 #define XFER_DMA_8BIT 0x20 /* 0 1 8 BIT Transfer Size */
747 #define XFER_DMA_16BIT 0x40 /* 1 0 16 BIT Transfer Size */
749 #define DISABLE_INT BIT(7) /*Do not interrupt at end of cmd. */
751 #define HOST_WRT_CMD ((DISABLE_INT + XFER_HOST_DMA + XFER_HOST_AUTO + XFER_DMA_8BIT))
752 #define HOST_RD_CMD ((DISABLE_INT + XFER_DMA_HOST + XFER_HOST_AUTO + XFER_DMA_8BIT))
753 #define WIDE_HOST_WRT_CMD ((DISABLE_INT + XFER_HOST_DMA + XFER_HOST_AUTO + XFER_DMA_16BIT))
754 #define WIDE_HOST_RD_CMD ((DISABLE_INT + XFER_DMA_HOST + XFER_HOST_AUTO + XFER_DMA_16BIT))
756 #define hp_host_addr_lo 0x1C
757 #define hp_host_addr_lmi 0x1D
758 #define hp_host_addr_hmi 0x1E
759 #define hp_host_addr_hi 0x1F
761 #define hp_pio_data 0x20
762 #define hp_reserved_21 0x21
763 #define hp_ee_ctrl 0x22
765 #define EXT_ARB_ACK BIT(7)
766 #define SCSI_TERM_ENA_H BIT(6) /* SCSI high byte terminator */
767 #define SEE_MS BIT(5)
768 #define SEE_CS BIT(3)
769 #define SEE_CLK BIT(2)
770 #define SEE_DO BIT(1)
771 #define SEE_DI BIT(0)
773 #define EE_READ 0x06
774 #define EE_WRITE 0x05
775 #define EWEN 0x04
776 #define EWEN_ADDR 0x03C0
777 #define EWDS 0x04
778 #define EWDS_ADDR 0x0000
780 #define hp_brdctl 0x23
782 #define DAT_7 BIT(7)
783 #define DAT_6 BIT(6)
784 #define DAT_5 BIT(5)
785 #define BRD_STB BIT(4)
786 #define BRD_CS BIT(3)
787 #define BRD_WR BIT(2)
789 #define hp_reserved_24 0x24
790 #define hp_reserved_25 0x25
795 #define hp_bm_ctrl 0x26
797 #define SCSI_TERM_ENA_L BIT(0) /*Enable/Disable external terminators */
798 #define FLUSH_XFER_CNTR BIT(1) /*Flush transfer counter */
799 #define BM_XFER_MIN_8 BIT(2) /*Enable bus master transfer of 9 */
800 #define BIOS_ENA BIT(3) /*Enable BIOS/FLASH Enable */
801 #define FORCE1_XFER BIT(5) /*Always xfer one byte in byte mode */
802 #define FAST_SINGLE BIT(6) /*?? */
804 #define BMCTRL_DEFAULT (FORCE1_XFER|FAST_SINGLE|SCSI_TERM_ENA_L)
806 #define hp_reserved_27 0x27
808 #define hp_sg_addr 0x28
809 #define hp_page_ctrl 0x29
811 #define SCATTER_EN BIT(0)
812 #define SGRAM_ARAM BIT(1)
813 #define BIOS_SHADOW BIT(2)
814 #define G_INT_DISABLE BIT(3) /* Enable/Disable all Interrupts */
815 #define NARROW_SCSI_CARD BIT(4) /* NARROW/WIDE SCSI config pin */
817 #define hp_reserved_2A 0x2A
818 #define hp_pci_cmd_cfg 0x2B
820 #define IO_SPACE_ENA BIT(0) /*enable I/O space */
821 #define MEM_SPACE_ENA BIT(1) /*enable memory space */
822 #define BUS_MSTR_ENA BIT(2) /*enable bus master operation */
823 #define MEM_WI_ENA BIT(4) /*enable Write and Invalidate */
824 #define PAR_ERR_RESP BIT(6) /*enable parity error responce. */
826 #define hp_reserved_2C 0x2C
828 #define hp_pci_stat_cfg 0x2D
830 #define DATA_PARITY_ERR BIT(0)
831 #define REC_TARGET_ABORT BIT(4) /*received Target abort */
832 #define REC_MASTER_ABORT BIT(5) /*received Master abort */
833 #define SIG_SYSTEM_ERR BIT(6)
834 #define DETECTED_PAR_ERR BIT(7)
836 #define hp_reserved_2E 0x2E
838 #define hp_sys_status 0x2F
840 #define SLV_DATA_RDY BIT(0) /*Slave data ready */
841 #define XFER_CNT_ZERO BIT(1) /*Transfer counter = 0 */
842 #define BM_FIFO_EMPTY BIT(2) /*FIFO empty */
843 #define BM_FIFO_FULL BIT(3) /*FIFO full */
844 #define HOST_OP_DONE BIT(4) /*host operation done */
845 #define DMA_OP_DONE BIT(5) /*DMA operation done */
846 #define SLV_OP_DONE BIT(6) /*Slave operation done */
847 #define PWR_ON_FLAG BIT(7) /*Power on flag */
849 #define hp_reserved_30 0x30
851 #define hp_host_status0 0x31
853 #define HOST_TERM BIT(5) /*Host Terminal Count */
854 #define HOST_TRSHLD BIT(6) /*Host Threshold */
855 #define CONNECTED_2_HOST BIT(7) /*Connected to Host */
857 #define hp_reserved_32 0x32
859 #define hp_rev_num 0x33
861 #define REV_A_CONST 0x0E
862 #define REV_B_CONST 0x0E
864 #define hp_stack_data 0x34
865 #define hp_stack_addr 0x35
867 #define hp_ext_status 0x36
869 #define BM_FORCE_OFF BIT(0) /*Bus Master is forced to get off */
870 #define PCI_TGT_ABORT BIT(0) /*PCI bus master transaction aborted */
871 #define PCI_DEV_TMOUT BIT(1) /*PCI Device Time out */
872 #define FIFO_TC_NOT_ZERO BIT(2) /*FIFO or transfer counter not zero */
873 #define CHIP_RST_OCCUR BIT(3) /*Chip reset occurs */
874 #define CMD_ABORTED BIT(4) /*Command aborted */
875 #define BM_PARITY_ERR BIT(5) /*parity error on data received */
876 #define PIO_OVERRUN BIT(6) /*Slave data overrun */
877 #define BM_CMD_BUSY BIT(7) /*Bus master transfer command busy */
878 #define BAD_EXT_STATUS (BM_FORCE_OFF | PCI_DEV_TMOUT | CMD_ABORTED | \
879 BM_PARITY_ERR | PIO_OVERRUN)
881 #define hp_int_status 0x37
883 #define BM_CMD_CMPL BIT(0) /*Bus Master command complete */
884 #define EXT_STATUS_ON BIT(1) /*Extended status is valid */
885 #define SCSI_INTERRUPT BIT(2) /*Global indication of a SCSI int. */
886 #define BM_FIFO_RDY BIT(4)
887 #define INT_ASSERTED BIT(5) /* */
888 #define SRAM_BUSY BIT(6) /*Scatter/Gather RAM busy */
889 #define CMD_REG_BUSY BIT(7)
892 #define hp_fifo_cnt 0x38
893 #define hp_curr_host_cnt 0x39
894 #define hp_reserved_3A 0x3A
895 #define hp_fifo_in_addr 0x3B
897 #define hp_fifo_out_addr 0x3C
898 #define hp_reserved_3D 0x3D
899 #define hp_reserved_3E 0x3E
900 #define hp_reserved_3F 0x3F
904 #define hp_intena 0x40
906 #define RESET BITW(7)
907 #define PROG_HLT BITW(6)
908 #define PARITY BITW(5)
909 #define FIFO BITW(4)
910 #define SEL BITW(3)
911 #define SCAM_SEL BITW(2)
912 #define RSEL BITW(1)
913 #define TIMEOUT BITW(0)
914 #define BUS_FREE BITW(15)
915 #define XFER_CNT_0 BITW(14)
916 #define PHASE BITW(13)
917 #define IUNKWN BITW(12)
918 #define ICMD_COMP BITW(11)
919 #define ITICKLE BITW(10)
920 #define IDO_STRT BITW(9)
921 #define ITAR_DISC BITW(8)
922 #define AUTO_INT (BITW(12)+BITW(11)+BITW(10)+BITW(9)+BITW(8))
923 #define CLR_ALL_INT 0xFFFF
924 #define CLR_ALL_INT_1 0xFF00
926 #define hp_intstat 0x42
928 #define hp_scsisig 0x44
930 #define SCSI_SEL BIT(7)
931 #define SCSI_BSY BIT(6)
932 #define SCSI_REQ BIT(5)
933 #define SCSI_ACK BIT(4)
934 #define SCSI_ATN BIT(3)
935 #define SCSI_CD BIT(2)
936 #define SCSI_MSG BIT(1)
937 #define SCSI_IOBIT BIT(0)
939 #define S_SCSI_PHZ (BIT(2)+BIT(1)+BIT(0))
940 #define S_CMD_PH (BIT(2) )
941 #define S_MSGO_PH (BIT(2)+BIT(1) )
942 #define S_STAT_PH (BIT(2) +BIT(0))
943 #define S_MSGI_PH (BIT(2)+BIT(1)+BIT(0))
944 #define S_DATAI_PH ( BIT(0))
945 #define S_DATAO_PH 0x00
946 #define S_ILL_PH ( BIT(1) )
948 #define hp_scsictrl_0 0x45
950 #define NO_ARB BIT(7)
951 #define SEL_TAR BIT(6)
952 #define ENA_ATN BIT(4)
953 #define ENA_RESEL BIT(2)
954 #define SCSI_RST BIT(1)
955 #define ENA_SCAM_SEL BIT(0)
959 #define hp_portctrl_0 0x46
961 #define SCSI_PORT BIT(7)
962 #define SCSI_INBIT BIT(6)
963 #define DMA_PORT BIT(5)
964 #define DMA_RD BIT(4)
965 #define HOST_PORT BIT(3)
966 #define HOST_WRT BIT(2)
967 #define SCSI_BUS_EN BIT(1)
968 #define START_TO BIT(0)
970 #define hp_scsireset 0x47
972 #define SCSI_TAR BIT(7)
973 #define SCSI_INI BIT(6)
974 #define SCAM_EN BIT(5)
975 #define ACK_HOLD BIT(4)
976 #define DMA_RESET BIT(3)
977 #define HPSCSI_RESET BIT(2)
978 #define PROG_RESET BIT(1)
979 #define FIFO_CLR BIT(0)
981 #define hp_xfercnt_0 0x48
982 #define hp_xfercnt_1 0x49
983 #define hp_xfercnt_2 0x4A
984 #define hp_xfercnt_3 0x4B
986 #define hp_fifodata_0 0x4C
987 #define hp_fifodata_1 0x4D
988 #define hp_addstat 0x4E
990 #define SCAM_TIMER BIT(7)
991 #define AUTO_RUNNING BIT(6)
992 #define FAST_SYNC BIT(5)
993 #define SCSI_MODE8 BIT(3)
994 #define SCSI_PAR_ERR BIT(0)
996 #define hp_prgmcnt_0 0x4F
998 #define AUTO_PC_MASK 0x3F
1000 #define hp_selfid_0 0x50
1001 #define hp_selfid_1 0x51
1002 #define hp_arb_id 0x52
1004 #define ARB_ID (BIT(3) + BIT(2) + BIT(1) + BIT(0))
1006 #define hp_select_id 0x53
1008 #define RESEL_ID (BIT(7) + BIT(6) + BIT(5) + BIT(4))
1009 #define SELECT_ID (BIT(3) + BIT(2) + BIT(1) + BIT(0))
1011 #define hp_synctarg_base 0x54
1012 #define hp_synctarg_12 0x54
1013 #define hp_synctarg_13 0x55
1014 #define hp_synctarg_14 0x56
1015 #define hp_synctarg_15 0x57
1017 #define hp_synctarg_8 0x58
1018 #define hp_synctarg_9 0x59
1019 #define hp_synctarg_10 0x5A
1020 #define hp_synctarg_11 0x5B
1022 #define hp_synctarg_4 0x5C
1023 #define hp_synctarg_5 0x5D
1024 #define hp_synctarg_6 0x5E
1025 #define hp_synctarg_7 0x5F
1027 #define hp_synctarg_0 0x60
1028 #define hp_synctarg_1 0x61
1029 #define hp_synctarg_2 0x62
1030 #define hp_synctarg_3 0x63
1032 #define RATE_20MB 0x00
1033 #define RATE_10MB ( BIT(5))
1034 #define RATE_6_6MB ( BIT(6) )
1035 #define RATE_5MB ( BIT(6)+BIT(5))
1036 #define RATE_4MB (BIT(7) )
1037 #define RATE_3_33MB (BIT(7) +BIT(5))
1038 #define RATE_2_85MB (BIT(7)+BIT(6) )
1039 #define RATE_2_5MB (BIT(7)+BIT(5)+BIT(6))
1040 #define NEXT_CLK BIT(5)
1041 #define SLOWEST_SYNC (BIT(7)+BIT(6)+BIT(5))
1042 #define NARROW_SCSI BIT(4)
1043 #define SYNC_OFFSET (BIT(3) + BIT(2) + BIT(1) + BIT(0))
1044 #define DEFAULT_ASYNC 0x00
1045 #define DEFAULT_OFFSET 0x0F
1047 #define hp_autostart_0 0x64
1048 #define hp_autostart_1 0x65
1049 #define hp_autostart_2 0x66
1050 #define hp_autostart_3 0x67
1054 #define DISABLE 0x00
1055 #define AUTO_IMMED BIT(5)
1056 #define SELECT BIT(6)
1057 #define RESELECT (BIT(6)+BIT(5))
1058 #define BUSFREE BIT(7)
1059 #define XFER_0 (BIT(7)+BIT(5))
1060 #define END_DATA (BIT(7)+BIT(6))
1061 #define MSG_PHZ (BIT(7)+BIT(6)+BIT(5))
1063 #define hp_gp_reg_0 0x68
1064 #define hp_gp_reg_1 0x69
1065 #define hp_gp_reg_2 0x6A
1066 #define hp_gp_reg_3 0x6B
1068 #define hp_seltimeout 0x6C
1071 #define TO_2ms 0x54 /* 2.0503ms */
1072 #define TO_4ms 0x67 /* 3.9959ms */
1074 #define TO_5ms 0x03 /* 4.9152ms */
1075 #define TO_10ms 0x07 /* 11.xxxms */
1076 #define TO_250ms 0x99 /* 250.68ms */
1077 #define TO_290ms 0xB1 /* 289.99ms */
1078 #define TO_350ms 0xD6 /* 350.62ms */
1079 #define TO_417ms 0xFF /* 417.79ms */
1081 #define hp_clkctrl_0 0x6D
1083 #define PWR_DWN BIT(6)
1084 #define ACTdeassert BIT(4)
1085 #define ATNonErr BIT(3)
1086 #define CLK_30MHZ BIT(1)
1087 #define CLK_40MHZ (BIT(1) + BIT(0))
1088 #define CLK_50MHZ BIT(2)
1090 #define CLKCTRL_DEFAULT (ACTdeassert | CLK_40MHZ)
1092 #define hp_fiforead 0x6E
1093 #define hp_fifowrite 0x6F
1095 #define hp_offsetctr 0x70
1096 #define hp_xferstat 0x71
1098 #define FIFO_FULL BIT(7)
1099 #define FIFO_EMPTY BIT(6)
1100 #define FIFO_MASK 0x3F /* Mask for the FIFO count value. */
1101 #define FIFO_LEN 0x20
1103 #define hp_portctrl_1 0x72
1105 #define EVEN_HOST_P BIT(5)
1106 #define INVT_SCSI BIT(4)
1107 #define CHK_SCSI_P BIT(3)
1108 #define HOST_MODE8 BIT(0)
1109 #define HOST_MODE16 0x00
1111 #define hp_xfer_pad 0x73
1113 #define ID_UNLOCK BIT(3)
1114 #define XFER_PAD BIT(2)
1116 #define hp_scsidata_0 0x74
1117 #define hp_scsidata_1 0x75
1118 #define hp_timer_0 0x76
1119 #define hp_timer_1 0x77
1121 #define hp_reserved_78 0x78
1122 #define hp_reserved_79 0x79
1123 #define hp_reserved_7A 0x7A
1124 #define hp_reserved_7B 0x7B
1126 #define hp_reserved_7C 0x7C
1127 #define hp_reserved_7D 0x7D
1128 #define hp_reserved_7E 0x7E
1129 #define hp_reserved_7F 0x7F
1131 #define hp_aramBase 0x80
1132 #define BIOS_DATA_OFFSET 0x60
1133 #define BIOS_RELATIVE_CARD 0x64
1138 #define AUTO_LEN 0x80
1139 #define AR0 0x00
1140 #define AR1 BITW(8)
1141 #define AR2 BITW(9)
1142 #define AR3 (BITW(9) + BITW(8))
1143 #define SDATA BITW(10)
1145 #define NOP_OP 0x00 /* Nop command */
1147 #define CRD_OP BITW(11) /* Cmp Reg. w/ Data */
1149 #define CRR_OP BITW(12) /* Cmp Reg. w. Reg. */
1151 #define CBE_OP (BITW(14)+BITW(12)+BITW(11)) /* Cmp SCSI cmd class & Branch EQ */
1153 #define CBN_OP (BITW(14)+BITW(13)) /* Cmp SCSI cmd class & Branch NOT EQ */
1155 #define CPE_OP (BITW(14)+BITW(11)) /* Cmp SCSI phs & Branch EQ */
1157 #define CPN_OP (BITW(14)+BITW(12)) /* Cmp SCSI phs & Branch NOT EQ */
1160 #define ADATA_OUT 0x00
1161 #define ADATA_IN BITW(8)
1162 #define ACOMMAND BITW(10)
1163 #define ASTATUS (BITW(10)+BITW(8))
1164 #define AMSG_OUT (BITW(10)+BITW(9))
1165 #define AMSG_IN (BITW(10)+BITW(9)+BITW(8))
1166 #define AILLEGAL (BITW(9)+BITW(8))
1169 #define BRH_OP BITW(13) /* Branch */
1172 #define ALWAYS 0x00
1173 #define EQUAL BITW(8)
1174 #define NOT_EQ BITW(9)
1176 #define TCB_OP (BITW(13)+BITW(11)) /* Test condition & branch */
1179 #define ATN_SET BITW(8)
1180 #define ATN_RESET BITW(9)
1181 #define XFER_CNT (BITW(9)+BITW(8))
1182 #define FIFO_0 BITW(10)
1183 #define FIFO_NOT0 (BITW(10)+BITW(8))
1184 #define T_USE_SYNC0 (BITW(10)+BITW(9))
1187 #define MPM_OP BITW(15) /* Match phase and move data */
1189 #define MDR_OP (BITW(12)+BITW(11)) /* Move data to Reg. */
1191 #define MRR_OP BITW(14) /* Move DReg. to Reg. */
1194 #define S_IDREG (BIT(2)+BIT(1)+BIT(0))
1197 #define D_AR0 0x00
1198 #define D_AR1 BIT(0)
1199 #define D_AR2 BIT(1)
1200 #define D_AR3 (BIT(1) + BIT(0))
1201 #define D_SDATA BIT(2)
1202 #define D_BUCKET (BIT(2) + BIT(1) + BIT(0))
1205 #define ADR_OP (BITW(13)+BITW(12)) /* Logical AND Reg. w. Data */
1207 #define ADS_OP (BITW(14)+BITW(13)+BITW(12))
1209 #define ODR_OP (BITW(13)+BITW(12)+BITW(11))
1211 #define ODS_OP (BITW(14)+BITW(13)+BITW(12)+BITW(11))
1213 #define STR_OP (BITW(15)+BITW(14)) /* Store to A_Reg. */
1215 #define AINT_ENA1 0x00
1216 #define AINT_STAT1 BITW(8)
1217 #define ASCSI_SIG BITW(9)
1218 #define ASCSI_CNTL (BITW(9)+BITW(8))
1219 #define APORT_CNTL BITW(10)
1220 #define ARST_CNTL (BITW(10)+BITW(8))
1221 #define AXFERCNT0 (BITW(10)+BITW(9))
1222 #define AXFERCNT1 (BITW(10)+BITW(9)+BITW(8))
1223 #define AXFERCNT2 BITW(11)
1224 #define AFIFO_DATA (BITW(11)+BITW(8))
1225 #define ASCSISELID (BITW(11)+BITW(9))
1226 #define ASCSISYNC0 (BITW(11)+BITW(9)+BITW(8))
1229 #define RAT_OP (BITW(14)+BITW(13)+BITW(11))
1231 #define SSI_OP (BITW(15)+BITW(11))
1234 #define SSI_ITAR_DISC (ITAR_DISC >> 8)
1235 #define SSI_IDO_STRT (IDO_STRT >> 8)
1236 #define SSI_IDI_STRT (IDO_STRT >> 8)
1238 #define SSI_ICMD_COMP (ICMD_COMP >> 8)
1239 #define SSI_ITICKLE (ITICKLE >> 8)
1241 #define SSI_IUNKWN (IUNKWN >> 8)
1242 #define SSI_INO_CC (IUNKWN >> 8)
1243 #define SSI_IRFAIL (IUNKWN >> 8)
1246 #define NP 0x10 /*Next Phase */
1247 #define NTCMD 0x02 /*Non- Tagged Command start */
1248 #define CMDPZ 0x04 /*Command phase */
1249 #define DINT 0x12 /*Data Out/In interrupt */
1250 #define DI 0x13 /*Data Out */
1251 #define MI 0x14 /*Message In */
1252 #define DC 0x19 /*Disconnect Message */
1253 #define ST 0x1D /*Status Phase */
1254 #define UNKNWN 0x24 /*Unknown bus action */
1255 #define CC 0x25 /*Command Completion failure */
1256 #define TICK 0x26 /*New target reselected us. */
1257 #define RFAIL 0x27 /*Reselection failed */
1258 #define SELCHK 0x28 /*Select & Check SCSI ID latch reg */
1261 #define ID_MSG_STRT hp_aramBase + 0x00
1262 #define NON_TAG_ID_MSG hp_aramBase + 0x06
1263 #define CMD_STRT hp_aramBase + 0x08
1264 #define SYNC_MSGS hp_aramBase + 0x08
1270 #define TAG_STRT 0x00
1271 #define SELECTION_START 0x00
1272 #define DISCONNECT_START 0x10/2
1273 #define END_DATA_START 0x14/2
1274 #define NONTAG_STRT 0x02/2
1275 #define CMD_ONLY_STRT CMDPZ/2
1276 #define TICKLE_STRT TICK/2
1277 #define SELCHK_STRT SELCHK/2
1282 #define mEEPROM_CLK_DELAY(port) (RD_HARPOON(port+hp_intstat_1))
1284 #define mWAIT_10MS(port) (RD_HARPOON(port+hp_intstat_1))
1287 #define CLR_XFER_CNT(port) (WR_HARPOON(port+hp_xfercnt_0, 0x00))
1289 #define SET_XFER_CNT(port, data) (WR_HARP32(port,hp_xfercnt_0,data))
1291 #define GET_XFER_CNT(port, xfercnt) {RD_HARP32(port,hp_xfercnt_0,xfercnt); xfercnt &= 0xFFFFFF;}
1292 /* #define GET_XFER_CNT(port, xfercnt) (xfercnt = RD_HARPOON(port+hp_xfercnt_2), \
1293 xfercnt <<= 16,\
1294 xfercnt |= RDW_HARPOON((USHORT)(port+hp_xfercnt_0)))
1296 #define HP_SETUP_ADDR_CNT(port,addr,count) (WRW_HARPOON((port+hp_host_addr_lo), (USHORT)(addr & 0x0000FFFFL)),\
1297 addr >>= 16,\
1298 WRW_HARPOON((port+hp_host_addr_hmi), (USHORT)(addr & 0x0000FFFFL)),\
1299 WR_HARP32(port,hp_xfercnt_0,count),\
1300 WRW_HARPOON((port+hp_xfer_cnt_lo), (USHORT)(count & 0x0000FFFFL)),\
1301 count >>= 16,\
1302 WR_HARPOON(port+hp_xfer_cnt_hi, (count & 0xFF)))
1304 #define ACCEPT_MSG(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
1305 WR_HARPOON(port+hp_scsisig, S_ILL_PH);}
1308 #define ACCEPT_MSG_ATN(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
1309 WR_HARPOON(port+hp_scsisig, (S_ILL_PH|SCSI_ATN));}
1311 #define ACCEPT_STAT(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
1312 WR_HARPOON(port+hp_scsisig, S_ILL_PH);}
1314 #define ACCEPT_STAT_ATN(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
1315 WR_HARPOON(port+hp_scsisig, (S_ILL_PH|SCSI_ATN));}
1317 #define DISABLE_AUTO(port) (WR_HARPOON(port+hp_scsireset, PROG_RESET),\
1318 WR_HARPOON(port+hp_scsireset, 0x00))
1320 #define ARAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
1321 (RD_HARPOON(p_port+hp_page_ctrl) | SGRAM_ARAM)))
1323 #define SGRAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
1324 (RD_HARPOON(p_port+hp_page_ctrl) & ~SGRAM_ARAM)))
1326 #define MDISABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
1327 (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE)))
1329 #define MENABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
1330 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE)))
1335 void scsiStartAuto(ULONG port);
1336 static UCHAR FPT_sisyncn(ULONG port, UCHAR p_card, UCHAR syncFlag);
1337 static void FPT_ssel(ULONG port, UCHAR p_card);
1338 static void FPT_sres(ULONG port, UCHAR p_card, PSCCBcard pCurrCard);
1339 static void FPT_shandem(ULONG port, UCHAR p_card,PSCCB pCurrSCCB);
1340 static void FPT_stsyncn(ULONG port, UCHAR p_card);
1341 static void FPT_sisyncr(ULONG port,UCHAR sync_pulse, UCHAR offset);
1342 static void FPT_sssyncv(ULONG p_port, UCHAR p_id, UCHAR p_sync_value,
1343 PSCCBMgr_tar_info currTar_Info);
1344 static void FPT_sresb(ULONG port, UCHAR p_card);
1345 static void FPT_sxfrp(ULONG p_port, UCHAR p_card);
1346 static void FPT_schkdd(ULONG port, UCHAR p_card);
1347 static UCHAR FPT_RdStack(ULONG port, UCHAR index);
1348 static void FPT_WrStack(ULONG portBase, UCHAR index, UCHAR data);
1349 static UCHAR FPT_ChkIfChipInitialized(ULONG ioPort);
1351 static void FPT_SendMsg(ULONG port, UCHAR message);
1352 static void FPT_queueFlushTargSccb(UCHAR p_card, UCHAR thisTarg,
1353 UCHAR error_code);
1355 static void FPT_sinits(PSCCB p_sccb, UCHAR p_card);
1356 static void FPT_RNVRamData(PNVRamInfo pNvRamInfo);
1358 static UCHAR FPT_siwidn(ULONG port, UCHAR p_card);
1359 static void FPT_stwidn(ULONG port, UCHAR p_card);
1360 static void FPT_siwidr(ULONG port, UCHAR width);
1363 static void FPT_queueSelectFail(PSCCBcard pCurrCard, UCHAR p_card);
1364 static void FPT_queueDisconnect(PSCCB p_SCCB, UCHAR p_card);
1365 static void FPT_queueCmdComplete(PSCCBcard pCurrCard, PSCCB p_SCCB,
1366 UCHAR p_card);
1367 static void FPT_queueSearchSelect(PSCCBcard pCurrCard, UCHAR p_card);
1368 static void FPT_queueFlushSccb(UCHAR p_card, UCHAR error_code);
1369 static void FPT_queueAddSccb(PSCCB p_SCCB, UCHAR card);
1370 static UCHAR FPT_queueFindSccb(PSCCB p_SCCB, UCHAR p_card);
1371 static void FPT_utilUpdateResidual(PSCCB p_SCCB);
1372 static USHORT FPT_CalcCrc16(UCHAR buffer[]);
1373 static UCHAR FPT_CalcLrc(UCHAR buffer[]);
1376 static void FPT_Wait1Second(ULONG p_port);
1377 static void FPT_Wait(ULONG p_port, UCHAR p_delay);
1378 static void FPT_utilEEWriteOnOff(ULONG p_port,UCHAR p_mode);
1379 static void FPT_utilEEWrite(ULONG p_port, USHORT ee_data, USHORT ee_addr);
1380 static USHORT FPT_utilEERead(ULONG p_port, USHORT ee_addr);
1381 static USHORT FPT_utilEEReadOrg(ULONG p_port, USHORT ee_addr);
1382 static void FPT_utilEESendCmdAddr(ULONG p_port, UCHAR ee_cmd, USHORT ee_addr);
1386 static void FPT_phaseDataOut(ULONG port, UCHAR p_card);
1387 static void FPT_phaseDataIn(ULONG port, UCHAR p_card);
1388 static void FPT_phaseCommand(ULONG port, UCHAR p_card);
1389 static void FPT_phaseStatus(ULONG port, UCHAR p_card);
1390 static void FPT_phaseMsgOut(ULONG port, UCHAR p_card);
1391 static void FPT_phaseMsgIn(ULONG port, UCHAR p_card);
1392 static void FPT_phaseIllegal(ULONG port, UCHAR p_card);
1394 static void FPT_phaseDecode(ULONG port, UCHAR p_card);
1395 static void FPT_phaseChkFifo(ULONG port, UCHAR p_card);
1396 static void FPT_phaseBusFree(ULONG p_port, UCHAR p_card);
1401 static void FPT_XbowInit(ULONG port, UCHAR scamFlg);
1402 static void FPT_BusMasterInit(ULONG p_port);
1403 static void FPT_DiagEEPROM(ULONG p_port);
1408 void busMstrAbort(ULONG port);
1409 static void FPT_dataXferProcessor(ULONG port, PSCCBcard pCurrCard);
1410 static void FPT_busMstrSGDataXferStart(ULONG port, PSCCB pCurrSCCB);
1411 static void FPT_busMstrDataXferStart(ULONG port, PSCCB pCurrSCCB);
1412 static void FPT_hostDataXferAbort(ULONG port, UCHAR p_card, PSCCB pCurrSCCB);
1413 static void FPT_hostDataXferRestart(PSCCB currSCCB);
1416 static UCHAR FPT_SccbMgr_bad_isr(ULONG p_port, UCHAR p_card,
1417 PSCCBcard pCurrCard, USHORT p_int);
1419 static void FPT_SccbMgrTableInitAll(void);
1420 static void FPT_SccbMgrTableInitCard(PSCCBcard pCurrCard, UCHAR p_card);
1421 static void FPT_SccbMgrTableInitTarget(UCHAR p_card, UCHAR target);
1425 static void FPT_scini(UCHAR p_card, UCHAR p_our_id, UCHAR p_power_up);
1427 static int FPT_scarb(ULONG p_port, UCHAR p_sel_type);
1428 static void FPT_scbusf(ULONG p_port);
1429 static void FPT_scsel(ULONG p_port);
1430 static void FPT_scasid(UCHAR p_card, ULONG p_port);
1431 static UCHAR FPT_scxferc(ULONG p_port, UCHAR p_data);
1432 static UCHAR FPT_scsendi(ULONG p_port, UCHAR p_id_string[]);
1433 static UCHAR FPT_sciso(ULONG p_port, UCHAR p_id_string[]);
1434 static void FPT_scwirod(ULONG p_port, UCHAR p_data_bit);
1435 static void FPT_scwiros(ULONG p_port, UCHAR p_data_bit);
1436 static UCHAR FPT_scvalq(UCHAR p_quintet);
1437 static UCHAR FPT_scsell(ULONG p_port, UCHAR targ_id);
1438 static void FPT_scwtsel(ULONG p_port);
1439 static void FPT_inisci(UCHAR p_card, ULONG p_port, UCHAR p_our_id);
1440 static void FPT_scsavdi(UCHAR p_card, ULONG p_port);
1441 static UCHAR FPT_scmachid(UCHAR p_card, UCHAR p_id_string[]);
1444 static void FPT_autoCmdCmplt(ULONG p_port, UCHAR p_card);
1445 static void FPT_autoLoadDefaultMap(ULONG p_port);
1449 void OS_start_timer(unsigned long ioport, unsigned long timeout);
1450 void OS_stop_timer(unsigned long ioport, unsigned long timeout);
1451 void OS_disable_int(unsigned char intvec);
1452 void OS_enable_int(unsigned char intvec);
1453 void OS_delay(unsigned long count);
1454 int OS_VirtToPhys(u32bits CardHandle, u32bits *physaddr, u32bits *virtaddr);
1456 static SCCBMGR_TAR_INFO FPT_sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR] = { { { 0 } } };
1457 static SCCBCARD FPT_BL_Card[MAX_CARDS] = { { 0 } };
1458 static SCCBSCAM_INFO FPT_scamInfo[MAX_SCSI_TAR] = { { { 0 } } };
1459 static NVRAMINFO FPT_nvRamInfo[MAX_MB_CARDS] = { { 0 } };
1462 static UCHAR FPT_mbCards = 0;
1463 static UCHAR FPT_scamHAString[] = {0x63, 0x07, 'B', 'U', 'S', 'L', 'O', 'G', 'I', 'C', \
1464 ' ', 'B', 'T', '-', '9', '3', '0', \
1465 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, \
1466 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20};
1468 static USHORT FPT_default_intena = 0;
1471 static void (*FPT_s_PhaseTbl[8]) (ULONG, UCHAR)= { 0 };
1474 /*---------------------------------------------------------------------
1476 * Function: SccbMgr_sense_adapter
1478 * Description: Setup and/or Search for cards and return info to caller.
1480 *---------------------------------------------------------------------*/
1482 static int SccbMgr_sense_adapter(PSCCBMGR_INFO pCardInfo)
1484 static UCHAR first_time = 1;
1486 UCHAR i,j,id,ScamFlg;
1487 USHORT temp,temp2,temp3,temp4,temp5,temp6;
1488 ULONG ioport;
1489 PNVRamInfo pCurrNvRam;
1491 ioport = pCardInfo->si_baseaddr;
1494 if (RD_HARPOON(ioport+hp_vendor_id_0) != ORION_VEND_0)
1495 return((int)FAILURE);
1497 if ((RD_HARPOON(ioport+hp_vendor_id_1) != ORION_VEND_1))
1498 return((int)FAILURE);
1500 if ((RD_HARPOON(ioport+hp_device_id_0) != ORION_DEV_0))
1501 return((int)FAILURE);
1503 if ((RD_HARPOON(ioport+hp_device_id_1) != ORION_DEV_1))
1504 return((int)FAILURE);
1507 if (RD_HARPOON(ioport+hp_rev_num) != 0x0f){
1509 /* For new Harpoon then check for sub_device ID LSB
1510 the bits(0-3) must be all ZERO for compatible with
1511 current version of SCCBMgr, else skip this Harpoon
1512 device. */
1514 if (RD_HARPOON(ioport+hp_sub_device_id_0) & 0x0f)
1515 return((int)FAILURE);
1518 if (first_time)
1520 FPT_SccbMgrTableInitAll();
1521 first_time = 0;
1522 FPT_mbCards = 0;
1525 if(FPT_RdStack(ioport, 0) != 0x00) {
1526 if(FPT_ChkIfChipInitialized(ioport) == 0)
1528 pCurrNvRam = NULL;
1529 WR_HARPOON(ioport+hp_semaphore, 0x00);
1530 FPT_XbowInit(ioport, 0); /*Must Init the SCSI before attempting */
1531 FPT_DiagEEPROM(ioport);
1533 else
1535 if(FPT_mbCards < MAX_MB_CARDS) {
1536 pCurrNvRam = &FPT_nvRamInfo[FPT_mbCards];
1537 FPT_mbCards++;
1538 pCurrNvRam->niBaseAddr = ioport;
1539 FPT_RNVRamData(pCurrNvRam);
1540 }else
1541 return((int) FAILURE);
1543 }else
1544 pCurrNvRam = NULL;
1546 WR_HARPOON(ioport+hp_clkctrl_0, CLKCTRL_DEFAULT);
1547 WR_HARPOON(ioport+hp_sys_ctrl, 0x00);
1549 if(pCurrNvRam)
1550 pCardInfo->si_id = pCurrNvRam->niAdapId;
1551 else
1552 pCardInfo->si_id = (UCHAR)(FPT_utilEERead(ioport, (ADAPTER_SCSI_ID/2)) &
1553 (UCHAR)0x0FF);
1555 pCardInfo->si_lun = 0x00;
1556 pCardInfo->si_fw_revision = ORION_FW_REV;
1557 temp2 = 0x0000;
1558 temp3 = 0x0000;
1559 temp4 = 0x0000;
1560 temp5 = 0x0000;
1561 temp6 = 0x0000;
1563 for (id = 0; id < (16/2); id++) {
1565 if(pCurrNvRam){
1566 temp = (USHORT) pCurrNvRam->niSyncTbl[id];
1567 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1568 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1569 }else
1570 temp = FPT_utilEERead(ioport, (USHORT)((SYNC_RATE_TBL/2)+id));
1572 for (i = 0; i < 2; temp >>=8,i++) {
1574 temp2 >>= 1;
1575 temp3 >>= 1;
1576 temp4 >>= 1;
1577 temp5 >>= 1;
1578 temp6 >>= 1;
1579 switch (temp & 0x3)
1581 case AUTO_RATE_20: /* Synchronous, 20 mega-transfers/second */
1582 temp6 |= 0x8000; /* Fall through */
1583 case AUTO_RATE_10: /* Synchronous, 10 mega-transfers/second */
1584 temp5 |= 0x8000; /* Fall through */
1585 case AUTO_RATE_05: /* Synchronous, 5 mega-transfers/second */
1586 temp2 |= 0x8000; /* Fall through */
1587 case AUTO_RATE_00: /* Asynchronous */
1588 break;
1591 if (temp & DISC_ENABLE_BIT)
1592 temp3 |= 0x8000;
1594 if (temp & WIDE_NEGO_BIT)
1595 temp4 |= 0x8000;
1600 pCardInfo->si_per_targ_init_sync = temp2;
1601 pCardInfo->si_per_targ_no_disc = temp3;
1602 pCardInfo->si_per_targ_wide_nego = temp4;
1603 pCardInfo->si_per_targ_fast_nego = temp5;
1604 pCardInfo->si_per_targ_ultra_nego = temp6;
1606 if(pCurrNvRam)
1607 i = pCurrNvRam->niSysConf;
1608 else
1609 i = (UCHAR)(FPT_utilEERead(ioport, (SYSTEM_CONFIG/2)));
1611 if(pCurrNvRam)
1612 ScamFlg = pCurrNvRam->niScamConf;
1613 else
1614 ScamFlg = (UCHAR) FPT_utilEERead(ioport, SCAM_CONFIG/2);
1616 pCardInfo->si_flags = 0x0000;
1618 if (i & 0x01)
1619 pCardInfo->si_flags |= SCSI_PARITY_ENA;
1621 if (!(i & 0x02))
1622 pCardInfo->si_flags |= SOFT_RESET;
1624 if (i & 0x10)
1625 pCardInfo->si_flags |= EXTENDED_TRANSLATION;
1627 if (ScamFlg & SCAM_ENABLED)
1628 pCardInfo->si_flags |= FLAG_SCAM_ENABLED;
1630 if (ScamFlg & SCAM_LEVEL2)
1631 pCardInfo->si_flags |= FLAG_SCAM_LEVEL2;
1633 j = (RD_HARPOON(ioport+hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1634 if (i & 0x04) {
1635 j |= SCSI_TERM_ENA_L;
1637 WR_HARPOON(ioport+hp_bm_ctrl, j );
1639 j = (RD_HARPOON(ioport+hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1640 if (i & 0x08) {
1641 j |= SCSI_TERM_ENA_H;
1643 WR_HARPOON(ioport+hp_ee_ctrl, j );
1645 if (!(RD_HARPOON(ioport+hp_page_ctrl) & NARROW_SCSI_CARD))
1647 pCardInfo->si_flags |= SUPPORT_16TAR_32LUN;
1649 pCardInfo->si_card_family = HARPOON_FAMILY;
1650 pCardInfo->si_bustype = BUSTYPE_PCI;
1652 if(pCurrNvRam){
1653 pCardInfo->si_card_model[0] = '9';
1654 switch(pCurrNvRam->niModel & 0x0f){
1655 case MODEL_LT:
1656 pCardInfo->si_card_model[1] = '3';
1657 pCardInfo->si_card_model[2] = '0';
1658 break;
1659 case MODEL_LW:
1660 pCardInfo->si_card_model[1] = '5';
1661 pCardInfo->si_card_model[2] = '0';
1662 break;
1663 case MODEL_DL:
1664 pCardInfo->si_card_model[1] = '3';
1665 pCardInfo->si_card_model[2] = '2';
1666 break;
1667 case MODEL_DW:
1668 pCardInfo->si_card_model[1] = '5';
1669 pCardInfo->si_card_model[2] = '2';
1670 break;
1672 }else{
1673 temp = FPT_utilEERead(ioport, (MODEL_NUMB_0/2));
1674 pCardInfo->si_card_model[0] = (UCHAR)(temp >> 8);
1675 temp = FPT_utilEERead(ioport, (MODEL_NUMB_2/2));
1677 pCardInfo->si_card_model[1] = (UCHAR)(temp & 0x00FF);
1678 pCardInfo->si_card_model[2] = (UCHAR)(temp >> 8);
1681 if (pCardInfo->si_card_model[1] == '3')
1683 if (RD_HARPOON(ioport+hp_ee_ctrl) & BIT(7))
1684 pCardInfo->si_flags |= LOW_BYTE_TERM;
1686 else if (pCardInfo->si_card_model[2] == '0')
1688 temp = RD_HARPOON(ioport+hp_xfer_pad);
1689 WR_HARPOON(ioport+hp_xfer_pad, (temp & ~BIT(4)));
1690 if (RD_HARPOON(ioport+hp_ee_ctrl) & BIT(7))
1691 pCardInfo->si_flags |= LOW_BYTE_TERM;
1692 WR_HARPOON(ioport+hp_xfer_pad, (temp | BIT(4)));
1693 if (RD_HARPOON(ioport+hp_ee_ctrl) & BIT(7))
1694 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1695 WR_HARPOON(ioport+hp_xfer_pad, temp);
1697 else
1699 temp = RD_HARPOON(ioport+hp_ee_ctrl);
1700 temp2 = RD_HARPOON(ioport+hp_xfer_pad);
1701 WR_HARPOON(ioport+hp_ee_ctrl, (temp | SEE_CS));
1702 WR_HARPOON(ioport+hp_xfer_pad, (temp2 | BIT(4)));
1703 temp3 = 0;
1704 for (i = 0; i < 8; i++)
1706 temp3 <<= 1;
1707 if (!(RD_HARPOON(ioport+hp_ee_ctrl) & BIT(7)))
1708 temp3 |= 1;
1709 WR_HARPOON(ioport+hp_xfer_pad, (temp2 & ~BIT(4)));
1710 WR_HARPOON(ioport+hp_xfer_pad, (temp2 | BIT(4)));
1712 WR_HARPOON(ioport+hp_ee_ctrl, temp);
1713 WR_HARPOON(ioport+hp_xfer_pad, temp2);
1714 if (!(temp3 & BIT(7)))
1715 pCardInfo->si_flags |= LOW_BYTE_TERM;
1716 if (!(temp3 & BIT(6)))
1717 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1721 ARAM_ACCESS(ioport);
1723 for ( i = 0; i < 4; i++ ) {
1725 pCardInfo->si_XlatInfo[i] =
1726 RD_HARPOON(ioport+hp_aramBase+BIOS_DATA_OFFSET+i);
1729 /* return with -1 if no sort, else return with
1730 logical card number sorted by BIOS (zero-based) */
1732 pCardInfo->si_relative_cardnum =
1733 (UCHAR)(RD_HARPOON(ioport+hp_aramBase+BIOS_RELATIVE_CARD)-1);
1735 SGRAM_ACCESS(ioport);
1737 FPT_s_PhaseTbl[0] = FPT_phaseDataOut;
1738 FPT_s_PhaseTbl[1] = FPT_phaseDataIn;
1739 FPT_s_PhaseTbl[2] = FPT_phaseIllegal;
1740 FPT_s_PhaseTbl[3] = FPT_phaseIllegal;
1741 FPT_s_PhaseTbl[4] = FPT_phaseCommand;
1742 FPT_s_PhaseTbl[5] = FPT_phaseStatus;
1743 FPT_s_PhaseTbl[6] = FPT_phaseMsgOut;
1744 FPT_s_PhaseTbl[7] = FPT_phaseMsgIn;
1746 pCardInfo->si_present = 0x01;
1748 return(0);
1752 /*---------------------------------------------------------------------
1754 * Function: SccbMgr_config_adapter
1756 * Description: Setup adapter for normal operation (hard reset).
1758 *---------------------------------------------------------------------*/
1760 static ULONG SccbMgr_config_adapter(PSCCBMGR_INFO pCardInfo)
1762 PSCCBcard CurrCard = NULL;
1763 PNVRamInfo pCurrNvRam;
1764 UCHAR i,j,thisCard, ScamFlg;
1765 USHORT temp,sync_bit_map,id;
1766 ULONG ioport;
1768 ioport = pCardInfo->si_baseaddr;
1770 for(thisCard =0; thisCard <= MAX_CARDS; thisCard++) {
1772 if (thisCard == MAX_CARDS) {
1774 return(FAILURE);
1777 if (FPT_BL_Card[thisCard].ioPort == ioport) {
1779 CurrCard = &FPT_BL_Card[thisCard];
1780 FPT_SccbMgrTableInitCard(CurrCard,thisCard);
1781 break;
1784 else if (FPT_BL_Card[thisCard].ioPort == 0x00) {
1786 FPT_BL_Card[thisCard].ioPort = ioport;
1787 CurrCard = &FPT_BL_Card[thisCard];
1789 if(FPT_mbCards)
1790 for(i = 0; i < FPT_mbCards; i++){
1791 if(CurrCard->ioPort == FPT_nvRamInfo[i].niBaseAddr)
1792 CurrCard->pNvRamInfo = &FPT_nvRamInfo[i];
1794 FPT_SccbMgrTableInitCard(CurrCard,thisCard);
1795 CurrCard->cardIndex = thisCard;
1796 CurrCard->cardInfo = pCardInfo;
1798 break;
1802 pCurrNvRam = CurrCard->pNvRamInfo;
1804 if(pCurrNvRam){
1805 ScamFlg = pCurrNvRam->niScamConf;
1807 else{
1808 ScamFlg = (UCHAR) FPT_utilEERead(ioport, SCAM_CONFIG/2);
1812 FPT_BusMasterInit(ioport);
1813 FPT_XbowInit(ioport, ScamFlg);
1815 FPT_autoLoadDefaultMap(ioport);
1818 for (i = 0,id = 0x01; i != pCardInfo->si_id; i++,id <<= 1){}
1820 WR_HARPOON(ioport+hp_selfid_0, id);
1821 WR_HARPOON(ioport+hp_selfid_1, 0x00);
1822 WR_HARPOON(ioport+hp_arb_id, pCardInfo->si_id);
1823 CurrCard->ourId = pCardInfo->si_id;
1825 i = (UCHAR) pCardInfo->si_flags;
1826 if (i & SCSI_PARITY_ENA)
1827 WR_HARPOON(ioport+hp_portctrl_1,(HOST_MODE8 | CHK_SCSI_P));
1829 j = (RD_HARPOON(ioport+hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1830 if (i & LOW_BYTE_TERM)
1831 j |= SCSI_TERM_ENA_L;
1832 WR_HARPOON(ioport+hp_bm_ctrl, j);
1834 j = (RD_HARPOON(ioport+hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1835 if (i & HIGH_BYTE_TERM)
1836 j |= SCSI_TERM_ENA_H;
1837 WR_HARPOON(ioport+hp_ee_ctrl, j );
1840 if (!(pCardInfo->si_flags & SOFT_RESET)) {
1842 FPT_sresb(ioport,thisCard);
1844 FPT_scini(thisCard, pCardInfo->si_id, 0);
1849 if (pCardInfo->si_flags & POST_ALL_UNDERRRUNS)
1850 CurrCard->globalFlags |= F_NO_FILTER;
1852 if(pCurrNvRam){
1853 if(pCurrNvRam->niSysConf & 0x10)
1854 CurrCard->globalFlags |= F_GREEN_PC;
1856 else{
1857 if (FPT_utilEERead(ioport, (SYSTEM_CONFIG/2)) & GREEN_PC_ENA)
1858 CurrCard->globalFlags |= F_GREEN_PC;
1861 /* Set global flag to indicate Re-Negotiation to be done on all
1862 ckeck condition */
1863 if(pCurrNvRam){
1864 if(pCurrNvRam->niScsiConf & 0x04)
1865 CurrCard->globalFlags |= F_DO_RENEGO;
1867 else{
1868 if (FPT_utilEERead(ioport, (SCSI_CONFIG/2)) & RENEGO_ENA)
1869 CurrCard->globalFlags |= F_DO_RENEGO;
1872 if(pCurrNvRam){
1873 if(pCurrNvRam->niScsiConf & 0x08)
1874 CurrCard->globalFlags |= F_CONLUN_IO;
1876 else{
1877 if (FPT_utilEERead(ioport, (SCSI_CONFIG/2)) & CONNIO_ENA)
1878 CurrCard->globalFlags |= F_CONLUN_IO;
1882 temp = pCardInfo->si_per_targ_no_disc;
1884 for (i = 0,id = 1; i < MAX_SCSI_TAR; i++, id <<= 1) {
1886 if (temp & id)
1887 FPT_sccbMgrTbl[thisCard][i].TarStatus |= TAR_ALLOW_DISC;
1890 sync_bit_map = 0x0001;
1892 for (id = 0; id < (MAX_SCSI_TAR/2); id++) {
1894 if(pCurrNvRam){
1895 temp = (USHORT) pCurrNvRam->niSyncTbl[id];
1896 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1897 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1898 }else
1899 temp = FPT_utilEERead(ioport, (USHORT)((SYNC_RATE_TBL/2)+id));
1901 for (i = 0; i < 2; temp >>=8,i++) {
1903 if (pCardInfo->si_per_targ_init_sync & sync_bit_map) {
1905 FPT_sccbMgrTbl[thisCard][id*2+i].TarEEValue = (UCHAR)temp;
1908 else {
1909 FPT_sccbMgrTbl[thisCard][id*2+i].TarStatus |= SYNC_SUPPORTED;
1910 FPT_sccbMgrTbl[thisCard][id*2+i].TarEEValue =
1911 (UCHAR)(temp & ~EE_SYNC_MASK);
1914 /* if ((pCardInfo->si_per_targ_wide_nego & sync_bit_map) ||
1915 (id*2+i >= 8)){
1917 if (pCardInfo->si_per_targ_wide_nego & sync_bit_map){
1919 FPT_sccbMgrTbl[thisCard][id*2+i].TarEEValue |= EE_WIDE_SCSI;
1923 else { /* NARROW SCSI */
1924 FPT_sccbMgrTbl[thisCard][id*2+i].TarStatus |= WIDE_NEGOCIATED;
1928 sync_bit_map <<= 1;
1935 WR_HARPOON((ioport+hp_semaphore),
1936 (UCHAR)(RD_HARPOON((ioport+hp_semaphore)) | SCCB_MGR_PRESENT));
1938 return((ULONG)CurrCard);
1941 static void SccbMgr_unload_card(ULONG pCurrCard)
1943 UCHAR i;
1944 ULONG portBase;
1945 ULONG regOffset;
1946 ULONG scamData;
1947 ULONG *pScamTbl;
1948 PNVRamInfo pCurrNvRam;
1950 pCurrNvRam = ((PSCCBcard)pCurrCard)->pNvRamInfo;
1952 if(pCurrNvRam){
1953 FPT_WrStack(pCurrNvRam->niBaseAddr, 0, pCurrNvRam->niModel);
1954 FPT_WrStack(pCurrNvRam->niBaseAddr, 1, pCurrNvRam->niSysConf);
1955 FPT_WrStack(pCurrNvRam->niBaseAddr, 2, pCurrNvRam->niScsiConf);
1956 FPT_WrStack(pCurrNvRam->niBaseAddr, 3, pCurrNvRam->niScamConf);
1957 FPT_WrStack(pCurrNvRam->niBaseAddr, 4, pCurrNvRam->niAdapId);
1959 for(i = 0; i < MAX_SCSI_TAR / 2; i++)
1960 FPT_WrStack(pCurrNvRam->niBaseAddr, (UCHAR)(i+5), pCurrNvRam->niSyncTbl[i]);
1962 portBase = pCurrNvRam->niBaseAddr;
1964 for(i = 0; i < MAX_SCSI_TAR; i++){
1965 regOffset = hp_aramBase + 64 + i*4;
1966 pScamTbl = (ULONG *) &pCurrNvRam->niScamTbl[i];
1967 scamData = *pScamTbl;
1968 WR_HARP32(portBase, regOffset, scamData);
1971 }else{
1972 FPT_WrStack(((PSCCBcard)pCurrCard)->ioPort, 0, 0);
1977 static void FPT_RNVRamData(PNVRamInfo pNvRamInfo)
1979 UCHAR i;
1980 ULONG portBase;
1981 ULONG regOffset;
1982 ULONG scamData;
1983 ULONG *pScamTbl;
1985 pNvRamInfo->niModel = FPT_RdStack(pNvRamInfo->niBaseAddr, 0);
1986 pNvRamInfo->niSysConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 1);
1987 pNvRamInfo->niScsiConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 2);
1988 pNvRamInfo->niScamConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 3);
1989 pNvRamInfo->niAdapId = FPT_RdStack(pNvRamInfo->niBaseAddr, 4);
1991 for(i = 0; i < MAX_SCSI_TAR / 2; i++)
1992 pNvRamInfo->niSyncTbl[i] = FPT_RdStack(pNvRamInfo->niBaseAddr, (UCHAR)(i+5));
1994 portBase = pNvRamInfo->niBaseAddr;
1996 for(i = 0; i < MAX_SCSI_TAR; i++){
1997 regOffset = hp_aramBase + 64 + i*4;
1998 RD_HARP32(portBase, regOffset, scamData);
1999 pScamTbl = (ULONG *) &pNvRamInfo->niScamTbl[i];
2000 *pScamTbl = scamData;
2005 static UCHAR FPT_RdStack(ULONG portBase, UCHAR index)
2007 WR_HARPOON(portBase + hp_stack_addr, index);
2008 return(RD_HARPOON(portBase + hp_stack_data));
2011 static void FPT_WrStack(ULONG portBase, UCHAR index, UCHAR data)
2013 WR_HARPOON(portBase + hp_stack_addr, index);
2014 WR_HARPOON(portBase + hp_stack_data, data);
2018 static UCHAR FPT_ChkIfChipInitialized(ULONG ioPort)
2020 if((RD_HARPOON(ioPort + hp_arb_id) & 0x0f) != FPT_RdStack(ioPort, 4))
2021 return(0);
2022 if((RD_HARPOON(ioPort + hp_clkctrl_0) & CLKCTRL_DEFAULT)
2023 != CLKCTRL_DEFAULT)
2024 return(0);
2025 if((RD_HARPOON(ioPort + hp_seltimeout) == TO_250ms) ||
2026 (RD_HARPOON(ioPort + hp_seltimeout) == TO_290ms))
2027 return(1);
2028 return(0);
2031 /*---------------------------------------------------------------------
2033 * Function: SccbMgr_start_sccb
2035 * Description: Start a command pointed to by p_Sccb. When the
2036 * command is completed it will be returned via the
2037 * callback function.
2039 *---------------------------------------------------------------------*/
2040 static void SccbMgr_start_sccb(ULONG pCurrCard, PSCCB p_Sccb)
2042 ULONG ioport;
2043 UCHAR thisCard, lun;
2044 PSCCB pSaveSccb;
2045 CALL_BK_FN callback;
2047 thisCard = ((PSCCBcard) pCurrCard)->cardIndex;
2048 ioport = ((PSCCBcard) pCurrCard)->ioPort;
2050 if((p_Sccb->TargID > MAX_SCSI_TAR) || (p_Sccb->Lun > MAX_LUN))
2053 p_Sccb->HostStatus = SCCB_COMPLETE;
2054 p_Sccb->SccbStatus = SCCB_ERROR;
2055 callback = (CALL_BK_FN)p_Sccb->SccbCallback;
2056 if (callback)
2057 callback(p_Sccb);
2059 return;
2062 FPT_sinits(p_Sccb,thisCard);
2065 if (!((PSCCBcard) pCurrCard)->cmdCounter)
2067 WR_HARPOON(ioport+hp_semaphore, (RD_HARPOON(ioport+hp_semaphore)
2068 | SCCB_MGR_ACTIVE));
2070 if (((PSCCBcard) pCurrCard)->globalFlags & F_GREEN_PC)
2072 WR_HARPOON(ioport+hp_clkctrl_0, CLKCTRL_DEFAULT);
2073 WR_HARPOON(ioport+hp_sys_ctrl, 0x00);
2077 ((PSCCBcard)pCurrCard)->cmdCounter++;
2079 if (RD_HARPOON(ioport+hp_semaphore) & BIOS_IN_USE) {
2081 WR_HARPOON(ioport+hp_semaphore, (RD_HARPOON(ioport+hp_semaphore)
2082 | TICKLE_ME));
2083 if(p_Sccb->OperationCode == RESET_COMMAND)
2085 pSaveSccb = ((PSCCBcard) pCurrCard)->currentSCCB;
2086 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2087 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
2088 ((PSCCBcard) pCurrCard)->currentSCCB = pSaveSccb;
2090 else
2092 FPT_queueAddSccb(p_Sccb,thisCard);
2096 else if ((RD_HARPOON(ioport+hp_page_ctrl) & G_INT_DISABLE)) {
2098 if(p_Sccb->OperationCode == RESET_COMMAND)
2100 pSaveSccb = ((PSCCBcard) pCurrCard)->currentSCCB;
2101 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2102 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
2103 ((PSCCBcard) pCurrCard)->currentSCCB = pSaveSccb;
2105 else
2107 FPT_queueAddSccb(p_Sccb,thisCard);
2111 else {
2113 MDISABLE_INT(ioport);
2115 if((((PSCCBcard) pCurrCard)->globalFlags & F_CONLUN_IO) &&
2116 ((FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
2117 lun = p_Sccb->Lun;
2118 else
2119 lun = 0;
2120 if ((((PSCCBcard) pCurrCard)->currentSCCB == NULL) &&
2121 (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarSelQ_Cnt == 0) &&
2122 (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarLUNBusy[lun]
2123 == 0)) {
2125 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2126 FPT_ssel(p_Sccb->SccbIOPort,thisCard);
2129 else {
2131 if(p_Sccb->OperationCode == RESET_COMMAND)
2133 pSaveSccb = ((PSCCBcard) pCurrCard)->currentSCCB;
2134 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2135 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
2136 ((PSCCBcard) pCurrCard)->currentSCCB = pSaveSccb;
2138 else
2140 FPT_queueAddSccb(p_Sccb,thisCard);
2145 MENABLE_INT(ioport);
2151 /*---------------------------------------------------------------------
2153 * Function: SccbMgr_abort_sccb
2155 * Description: Abort the command pointed to by p_Sccb. When the
2156 * command is completed it will be returned via the
2157 * callback function.
2159 *---------------------------------------------------------------------*/
2160 static int SccbMgr_abort_sccb(ULONG pCurrCard, PSCCB p_Sccb)
2162 ULONG ioport;
2164 UCHAR thisCard;
2165 CALL_BK_FN callback;
2166 UCHAR TID;
2167 PSCCB pSaveSCCB;
2168 PSCCBMgr_tar_info currTar_Info;
2171 ioport = ((PSCCBcard) pCurrCard)->ioPort;
2173 thisCard = ((PSCCBcard)pCurrCard)->cardIndex;
2175 if (!(RD_HARPOON(ioport+hp_page_ctrl) & G_INT_DISABLE))
2178 if (FPT_queueFindSccb(p_Sccb,thisCard))
2181 ((PSCCBcard)pCurrCard)->cmdCounter--;
2183 if (!((PSCCBcard)pCurrCard)->cmdCounter)
2184 WR_HARPOON(ioport+hp_semaphore,(RD_HARPOON(ioport+hp_semaphore)
2185 & (UCHAR)(~(SCCB_MGR_ACTIVE | TICKLE_ME)) ));
2187 p_Sccb->SccbStatus = SCCB_ABORT;
2188 callback = p_Sccb->SccbCallback;
2189 callback(p_Sccb);
2191 return(0);
2194 else
2196 if (((PSCCBcard)pCurrCard)->currentSCCB == p_Sccb)
2198 p_Sccb->SccbStatus = SCCB_ABORT;
2199 return(0);
2203 else
2206 TID = p_Sccb->TargID;
2209 if(p_Sccb->Sccb_tag)
2211 MDISABLE_INT(ioport);
2212 if (((PSCCBcard) pCurrCard)->discQ_Tbl[p_Sccb->Sccb_tag]==p_Sccb)
2214 p_Sccb->SccbStatus = SCCB_ABORT;
2215 p_Sccb->Sccb_scsistat = ABORT_ST;
2216 p_Sccb->Sccb_scsimsg = SMABORT_TAG;
2218 if(((PSCCBcard) pCurrCard)->currentSCCB == NULL)
2220 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2221 FPT_ssel(ioport, thisCard);
2223 else
2225 pSaveSCCB = ((PSCCBcard) pCurrCard)->currentSCCB;
2226 ((PSCCBcard) pCurrCard)->currentSCCB = p_Sccb;
2227 FPT_queueSelectFail((PSCCBcard) pCurrCard, thisCard);
2228 ((PSCCBcard) pCurrCard)->currentSCCB = pSaveSCCB;
2231 MENABLE_INT(ioport);
2232 return(0);
2234 else
2236 currTar_Info = &FPT_sccbMgrTbl[thisCard][p_Sccb->TargID];
2238 if(FPT_BL_Card[thisCard].discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_Sccb->Lun]]
2239 == p_Sccb)
2241 p_Sccb->SccbStatus = SCCB_ABORT;
2242 return(0);
2248 return(-1);
2252 /*---------------------------------------------------------------------
2254 * Function: SccbMgr_my_int
2256 * Description: Do a quick check to determine if there is a pending
2257 * interrupt for this card and disable the IRQ Pin if so.
2259 *---------------------------------------------------------------------*/
2260 static UCHAR SccbMgr_my_int(ULONG pCurrCard)
2262 ULONG ioport;
2264 ioport = ((PSCCBcard)pCurrCard)->ioPort;
2266 if (RD_HARPOON(ioport+hp_int_status) & INT_ASSERTED)
2268 return(1);
2271 else
2273 return(0);
2278 /*---------------------------------------------------------------------
2280 * Function: SccbMgr_isr
2282 * Description: This is our entry point when an interrupt is generated
2283 * by the card and the upper level driver passes it on to
2284 * us.
2286 *---------------------------------------------------------------------*/
2287 static int SccbMgr_isr(ULONG pCurrCard)
2289 PSCCB currSCCB;
2290 UCHAR thisCard,result,bm_status, bm_int_st;
2291 USHORT hp_int;
2292 UCHAR i, target;
2293 ULONG ioport;
2295 thisCard = ((PSCCBcard)pCurrCard)->cardIndex;
2296 ioport = ((PSCCBcard)pCurrCard)->ioPort;
2298 MDISABLE_INT(ioport);
2300 if ((bm_int_st=RD_HARPOON(ioport+hp_int_status)) & EXT_STATUS_ON)
2301 bm_status = RD_HARPOON(ioport+hp_ext_status) & (UCHAR)BAD_EXT_STATUS;
2302 else
2303 bm_status = 0;
2305 WR_HARPOON(ioport+hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
2307 while ((hp_int = RDW_HARPOON((ioport+hp_intstat)) & FPT_default_intena) |
2308 bm_status)
2311 currSCCB = ((PSCCBcard)pCurrCard)->currentSCCB;
2313 if (hp_int & (FIFO | TIMEOUT | RESET | SCAM_SEL) || bm_status) {
2314 result = FPT_SccbMgr_bad_isr(ioport,thisCard,((PSCCBcard)pCurrCard),hp_int);
2315 WRW_HARPOON((ioport+hp_intstat), (FIFO | TIMEOUT | RESET | SCAM_SEL));
2316 bm_status = 0;
2318 if (result) {
2320 MENABLE_INT(ioport);
2321 return(result);
2326 else if (hp_int & ICMD_COMP) {
2328 if ( !(hp_int & BUS_FREE) ) {
2329 /* Wait for the BusFree before starting a new command. We
2330 must also check for being reselected since the BusFree
2331 may not show up if another device reselects us in 1.5us or
2332 less. SRR Wednesday, 3/8/1995.
2334 while (!(RDW_HARPOON((ioport+hp_intstat)) & (BUS_FREE | RSEL))) ;
2337 if (((PSCCBcard)pCurrCard)->globalFlags & F_HOST_XFER_ACT)
2339 FPT_phaseChkFifo(ioport, thisCard);
2341 /* WRW_HARPOON((ioport+hp_intstat),
2342 (BUS_FREE | ICMD_COMP | ITAR_DISC | XFER_CNT_0));
2345 WRW_HARPOON((ioport+hp_intstat), CLR_ALL_INT_1);
2347 FPT_autoCmdCmplt(ioport,thisCard);
2352 else if (hp_int & ITAR_DISC)
2355 if (((PSCCBcard)pCurrCard)->globalFlags & F_HOST_XFER_ACT) {
2357 FPT_phaseChkFifo(ioport, thisCard);
2361 if (RD_HARPOON(ioport+hp_gp_reg_1) == SMSAVE_DATA_PTR) {
2363 WR_HARPOON(ioport+hp_gp_reg_1, 0x00);
2364 currSCCB->Sccb_XferState |= F_NO_DATA_YET;
2366 currSCCB->Sccb_savedATC = currSCCB->Sccb_ATC;
2369 currSCCB->Sccb_scsistat = DISCONNECT_ST;
2370 FPT_queueDisconnect(currSCCB,thisCard);
2372 /* Wait for the BusFree before starting a new command. We
2373 must also check for being reselected since the BusFree
2374 may not show up if another device reselects us in 1.5us or
2375 less. SRR Wednesday, 3/8/1995.
2377 while (!(RDW_HARPOON((ioport+hp_intstat)) & (BUS_FREE | RSEL)) &&
2378 !((RDW_HARPOON((ioport+hp_intstat)) & PHASE) &&
2379 RD_HARPOON((ioport+hp_scsisig)) ==
2380 (SCSI_BSY | SCSI_REQ | SCSI_CD | SCSI_MSG | SCSI_IOBIT))) ;
2383 The additional loop exit condition above detects a timing problem
2384 with the revision D/E harpoon chips. The caller should reset the
2385 host adapter to recover when 0xFE is returned.
2387 if (!(RDW_HARPOON((ioport+hp_intstat)) & (BUS_FREE | RSEL)))
2389 MENABLE_INT(ioport);
2390 return 0xFE;
2393 WRW_HARPOON((ioport+hp_intstat), (BUS_FREE | ITAR_DISC));
2396 ((PSCCBcard)pCurrCard)->globalFlags |= F_NEW_SCCB_CMD;
2401 else if (hp_int & RSEL) {
2403 WRW_HARPOON((ioport+hp_intstat), (PROG_HLT | RSEL | PHASE | BUS_FREE));
2405 if (RDW_HARPOON((ioport+hp_intstat)) & ITAR_DISC)
2407 if (((PSCCBcard)pCurrCard)->globalFlags & F_HOST_XFER_ACT)
2409 FPT_phaseChkFifo(ioport, thisCard);
2412 if (RD_HARPOON(ioport+hp_gp_reg_1) == SMSAVE_DATA_PTR)
2414 WR_HARPOON(ioport+hp_gp_reg_1, 0x00);
2415 currSCCB->Sccb_XferState |= F_NO_DATA_YET;
2416 currSCCB->Sccb_savedATC = currSCCB->Sccb_ATC;
2419 WRW_HARPOON((ioport+hp_intstat), (BUS_FREE | ITAR_DISC));
2420 currSCCB->Sccb_scsistat = DISCONNECT_ST;
2421 FPT_queueDisconnect(currSCCB,thisCard);
2424 FPT_sres(ioport,thisCard,((PSCCBcard)pCurrCard));
2425 FPT_phaseDecode(ioport,thisCard);
2430 else if ((hp_int & IDO_STRT) && (!(hp_int & BUS_FREE)))
2433 WRW_HARPOON((ioport+hp_intstat), (IDO_STRT | XFER_CNT_0));
2434 FPT_phaseDecode(ioport,thisCard);
2439 else if ( (hp_int & IUNKWN) || (hp_int & PROG_HLT) )
2441 WRW_HARPOON((ioport+hp_intstat), (PHASE | IUNKWN | PROG_HLT));
2442 if ((RD_HARPOON(ioport+hp_prgmcnt_0) & (UCHAR)0x3f)< (UCHAR)SELCHK)
2444 FPT_phaseDecode(ioport,thisCard);
2446 else
2448 /* Harpoon problem some SCSI target device respond to selection
2449 with short BUSY pulse (<400ns) this will make the Harpoon is not able
2450 to latch the correct Target ID into reg. x53.
2451 The work around require to correct this reg. But when write to this
2452 reg. (0x53) also increment the FIFO write addr reg (0x6f), thus we
2453 need to read this reg first then restore it later. After update to 0x53 */
2455 i = (UCHAR)(RD_HARPOON(ioport+hp_fifowrite));
2456 target = (UCHAR)(RD_HARPOON(ioport+hp_gp_reg_3));
2457 WR_HARPOON(ioport+hp_xfer_pad, (UCHAR) ID_UNLOCK);
2458 WR_HARPOON(ioport+hp_select_id, (UCHAR)(target | target<<4));
2459 WR_HARPOON(ioport+hp_xfer_pad, (UCHAR) 0x00);
2460 WR_HARPOON(ioport+hp_fifowrite, i);
2461 WR_HARPOON(ioport+hp_autostart_3, (AUTO_IMMED+TAG_STRT));
2465 else if (hp_int & XFER_CNT_0) {
2467 WRW_HARPOON((ioport+hp_intstat), XFER_CNT_0);
2469 FPT_schkdd(ioport,thisCard);
2474 else if (hp_int & BUS_FREE) {
2476 WRW_HARPOON((ioport+hp_intstat), BUS_FREE);
2478 if (((PSCCBcard)pCurrCard)->globalFlags & F_HOST_XFER_ACT) {
2480 FPT_hostDataXferAbort(ioport,thisCard,currSCCB);
2483 FPT_phaseBusFree(ioport,thisCard);
2487 else if (hp_int & ITICKLE) {
2489 WRW_HARPOON((ioport+hp_intstat), ITICKLE);
2490 ((PSCCBcard)pCurrCard)->globalFlags |= F_NEW_SCCB_CMD;
2495 if (((PSCCBcard)pCurrCard)->globalFlags & F_NEW_SCCB_CMD) {
2498 ((PSCCBcard)pCurrCard)->globalFlags &= ~F_NEW_SCCB_CMD;
2501 if (((PSCCBcard)pCurrCard)->currentSCCB == NULL) {
2503 FPT_queueSearchSelect(((PSCCBcard)pCurrCard),thisCard);
2506 if (((PSCCBcard)pCurrCard)->currentSCCB != NULL) {
2507 ((PSCCBcard)pCurrCard)->globalFlags &= ~F_NEW_SCCB_CMD;
2508 FPT_ssel(ioport,thisCard);
2511 break;
2515 } /*end while */
2517 MENABLE_INT(ioport);
2519 return(0);
2522 /*---------------------------------------------------------------------
2524 * Function: Sccb_bad_isr
2526 * Description: Some type of interrupt has occurred which is slightly
2527 * out of the ordinary. We will now decode it fully, in
2528 * this routine. This is broken up in an attempt to save
2529 * processing time.
2531 *---------------------------------------------------------------------*/
2532 static UCHAR FPT_SccbMgr_bad_isr(ULONG p_port, UCHAR p_card,
2533 PSCCBcard pCurrCard, USHORT p_int)
2535 UCHAR temp, ScamFlg;
2536 PSCCBMgr_tar_info currTar_Info;
2537 PNVRamInfo pCurrNvRam;
2540 if (RD_HARPOON(p_port+hp_ext_status) &
2541 (BM_FORCE_OFF | PCI_DEV_TMOUT | BM_PARITY_ERR | PIO_OVERRUN) )
2544 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
2547 FPT_hostDataXferAbort(p_port,p_card, pCurrCard->currentSCCB);
2550 if (RD_HARPOON(p_port+hp_pci_stat_cfg) & REC_MASTER_ABORT)
2553 WR_HARPOON(p_port+hp_pci_stat_cfg,
2554 (RD_HARPOON(p_port+hp_pci_stat_cfg) & ~REC_MASTER_ABORT));
2556 WR_HARPOON(p_port+hp_host_blk_cnt, 0x00);
2560 if (pCurrCard->currentSCCB != NULL)
2563 if (!pCurrCard->currentSCCB->HostStatus)
2564 pCurrCard->currentSCCB->HostStatus = SCCB_BM_ERR;
2566 FPT_sxfrp(p_port,p_card);
2568 temp = (UCHAR)(RD_HARPOON(p_port+hp_ee_ctrl) &
2569 (EXT_ARB_ACK | SCSI_TERM_ENA_H));
2570 WR_HARPOON(p_port+hp_ee_ctrl, ((UCHAR)temp | SEE_MS | SEE_CS));
2571 WR_HARPOON(p_port+hp_ee_ctrl, temp);
2573 if (!(RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | RESET)))
2575 FPT_phaseDecode(p_port,p_card);
2581 else if (p_int & RESET)
2584 WR_HARPOON(p_port+hp_clkctrl_0, CLKCTRL_DEFAULT);
2585 WR_HARPOON(p_port+hp_sys_ctrl, 0x00);
2586 if (pCurrCard->currentSCCB != NULL) {
2588 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
2590 FPT_hostDataXferAbort(p_port,p_card, pCurrCard->currentSCCB);
2594 DISABLE_AUTO(p_port);
2596 FPT_sresb(p_port,p_card);
2598 while(RD_HARPOON(p_port+hp_scsictrl_0) & SCSI_RST) {}
2600 pCurrNvRam = pCurrCard->pNvRamInfo;
2601 if(pCurrNvRam){
2602 ScamFlg = pCurrNvRam->niScamConf;
2604 else{
2605 ScamFlg = (UCHAR) FPT_utilEERead(p_port, SCAM_CONFIG/2);
2608 FPT_XbowInit(p_port, ScamFlg);
2610 FPT_scini(p_card, pCurrCard->ourId, 0);
2612 return(0xFF);
2616 else if (p_int & FIFO) {
2618 WRW_HARPOON((p_port+hp_intstat), FIFO);
2620 if (pCurrCard->currentSCCB != NULL)
2621 FPT_sxfrp(p_port,p_card);
2624 else if (p_int & TIMEOUT)
2627 DISABLE_AUTO(p_port);
2629 WRW_HARPOON((p_port+hp_intstat),
2630 (PROG_HLT | TIMEOUT | SEL |BUS_FREE | PHASE | IUNKWN));
2632 pCurrCard->currentSCCB->HostStatus = SCCB_SELECTION_TIMEOUT;
2635 currTar_Info = &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
2636 if((pCurrCard->globalFlags & F_CONLUN_IO) &&
2637 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
2638 currTar_Info->TarLUNBusy[pCurrCard->currentSCCB->Lun] = 0;
2639 else
2640 currTar_Info->TarLUNBusy[0] = 0;
2643 if (currTar_Info->TarEEValue & EE_SYNC_MASK)
2645 currTar_Info->TarSyncCtrl = 0;
2646 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2649 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
2651 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2654 FPT_sssyncv(p_port, pCurrCard->currentSCCB->TargID, NARROW_SCSI,currTar_Info);
2656 FPT_queueCmdComplete(pCurrCard, pCurrCard->currentSCCB, p_card);
2660 else if (p_int & SCAM_SEL)
2663 FPT_scarb(p_port,LEVEL2_TAR);
2664 FPT_scsel(p_port);
2665 FPT_scasid(p_card, p_port);
2667 FPT_scbusf(p_port);
2669 WRW_HARPOON((p_port+hp_intstat), SCAM_SEL);
2672 return(0x00);
2676 /*---------------------------------------------------------------------
2678 * Function: SccbMgrTableInit
2680 * Description: Initialize all Sccb manager data structures.
2682 *---------------------------------------------------------------------*/
2684 static void FPT_SccbMgrTableInitAll()
2686 UCHAR thisCard;
2688 for (thisCard = 0; thisCard < MAX_CARDS; thisCard++)
2690 FPT_SccbMgrTableInitCard(&FPT_BL_Card[thisCard],thisCard);
2692 FPT_BL_Card[thisCard].ioPort = 0x00;
2693 FPT_BL_Card[thisCard].cardInfo = NULL;
2694 FPT_BL_Card[thisCard].cardIndex = 0xFF;
2695 FPT_BL_Card[thisCard].ourId = 0x00;
2696 FPT_BL_Card[thisCard].pNvRamInfo = NULL;
2701 /*---------------------------------------------------------------------
2703 * Function: SccbMgrTableInit
2705 * Description: Initialize all Sccb manager data structures.
2707 *---------------------------------------------------------------------*/
2709 static void FPT_SccbMgrTableInitCard(PSCCBcard pCurrCard, UCHAR p_card)
2711 UCHAR scsiID, qtag;
2713 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++)
2715 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2718 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++)
2720 FPT_sccbMgrTbl[p_card][scsiID].TarStatus = 0;
2721 FPT_sccbMgrTbl[p_card][scsiID].TarEEValue = 0;
2722 FPT_SccbMgrTableInitTarget(p_card, scsiID);
2725 pCurrCard->scanIndex = 0x00;
2726 pCurrCard->currentSCCB = NULL;
2727 pCurrCard->globalFlags = 0x00;
2728 pCurrCard->cmdCounter = 0x00;
2729 pCurrCard->tagQ_Lst = 0x01;
2730 pCurrCard->discQCount = 0;
2736 /*---------------------------------------------------------------------
2738 * Function: SccbMgrTableInit
2740 * Description: Initialize all Sccb manager data structures.
2742 *---------------------------------------------------------------------*/
2744 static void FPT_SccbMgrTableInitTarget(UCHAR p_card, UCHAR target)
2747 UCHAR lun, qtag;
2748 PSCCBMgr_tar_info currTar_Info;
2750 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2752 currTar_Info->TarSelQ_Cnt = 0;
2753 currTar_Info->TarSyncCtrl = 0;
2755 currTar_Info->TarSelQ_Head = NULL;
2756 currTar_Info->TarSelQ_Tail = NULL;
2757 currTar_Info->TarTagQ_Cnt = 0;
2758 currTar_Info->TarLUN_CA = 0;
2761 for (lun = 0; lun < MAX_LUN; lun++)
2763 currTar_Info->TarLUNBusy[lun] = 0;
2764 currTar_Info->LunDiscQ_Idx[lun] = 0;
2767 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++)
2769 if(FPT_BL_Card[p_card].discQ_Tbl[qtag] != NULL)
2771 if(FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == target)
2773 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2774 FPT_BL_Card[p_card].discQCount--;
2781 /*---------------------------------------------------------------------
2783 * Function: sfetm
2785 * Description: Read in a message byte from the SCSI bus, and check
2786 * for a parity error.
2788 *---------------------------------------------------------------------*/
2790 static UCHAR FPT_sfm(ULONG port, PSCCB pCurrSCCB)
2792 UCHAR message;
2793 USHORT TimeOutLoop;
2795 TimeOutLoop = 0;
2796 while( (!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ)) &&
2797 (TimeOutLoop++ < 20000) ){}
2800 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
2802 message = RD_HARPOON(port+hp_scsidata_0);
2804 WR_HARPOON(port+hp_scsisig, SCSI_ACK + S_MSGI_PH);
2807 if (TimeOutLoop > 20000)
2808 message = 0x00; /* force message byte = 0 if Time Out on Req */
2810 if ((RDW_HARPOON((port+hp_intstat)) & PARITY) &&
2811 (RD_HARPOON(port+hp_addstat) & SCSI_PAR_ERR))
2813 WR_HARPOON(port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
2814 WR_HARPOON(port+hp_xferstat, 0);
2815 WR_HARPOON(port+hp_fiforead, 0);
2816 WR_HARPOON(port+hp_fifowrite, 0);
2817 if (pCurrSCCB != NULL)
2819 pCurrSCCB->Sccb_scsimsg = SMPARITY;
2821 message = 0x00;
2824 ACCEPT_MSG_ATN(port);
2825 TimeOutLoop = 0;
2826 while( (!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ)) &&
2827 (TimeOutLoop++ < 20000) ){}
2828 if (TimeOutLoop > 20000)
2830 WRW_HARPOON((port+hp_intstat), PARITY);
2831 return(message);
2833 if ((RD_HARPOON(port+hp_scsisig) & S_SCSI_PHZ) != S_MSGI_PH)
2835 WRW_HARPOON((port+hp_intstat), PARITY);
2836 return(message);
2838 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
2840 RD_HARPOON(port+hp_scsidata_0);
2842 WR_HARPOON(port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
2844 }while(1);
2847 WR_HARPOON(port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
2848 WR_HARPOON(port+hp_xferstat, 0);
2849 WR_HARPOON(port+hp_fiforead, 0);
2850 WR_HARPOON(port+hp_fifowrite, 0);
2851 return(message);
2855 /*---------------------------------------------------------------------
2857 * Function: FPT_ssel
2859 * Description: Load up automation and select target device.
2861 *---------------------------------------------------------------------*/
2863 static void FPT_ssel(ULONG port, UCHAR p_card)
2866 UCHAR auto_loaded, i, target, *theCCB;
2868 ULONG cdb_reg;
2869 PSCCBcard CurrCard;
2870 PSCCB currSCCB;
2871 PSCCBMgr_tar_info currTar_Info;
2872 UCHAR lastTag, lun;
2874 CurrCard = &FPT_BL_Card[p_card];
2875 currSCCB = CurrCard->currentSCCB;
2876 target = currSCCB->TargID;
2877 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2878 lastTag = CurrCard->tagQ_Lst;
2880 ARAM_ACCESS(port);
2883 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
2884 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2886 if(((CurrCard->globalFlags & F_CONLUN_IO) &&
2887 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
2889 lun = currSCCB->Lun;
2890 else
2891 lun = 0;
2894 if (CurrCard->globalFlags & F_TAG_STARTED)
2896 if (!(currSCCB->ControlByte & F_USE_CMD_Q))
2898 if ((currTar_Info->TarLUN_CA == 0)
2899 && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
2900 == TAG_Q_TRYING))
2903 if (currTar_Info->TarTagQ_Cnt !=0)
2905 currTar_Info->TarLUNBusy[lun] = 1;
2906 FPT_queueSelectFail(CurrCard,p_card);
2907 SGRAM_ACCESS(port);
2908 return;
2911 else {
2912 currTar_Info->TarLUNBusy[lun] = 1;
2915 } /*End non-tagged */
2917 else {
2918 currTar_Info->TarLUNBusy[lun] = 1;
2921 } /*!Use cmd Q Tagged */
2923 else {
2924 if (currTar_Info->TarLUN_CA == 1)
2926 FPT_queueSelectFail(CurrCard,p_card);
2927 SGRAM_ACCESS(port);
2928 return;
2931 currTar_Info->TarLUNBusy[lun] = 1;
2933 } /*else use cmd Q tagged */
2935 } /*if glob tagged started */
2937 else {
2938 currTar_Info->TarLUNBusy[lun] = 1;
2943 if((((CurrCard->globalFlags & F_CONLUN_IO) &&
2944 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
2945 || (!(currSCCB->ControlByte & F_USE_CMD_Q))))
2947 if(CurrCard->discQCount >= QUEUE_DEPTH)
2949 currTar_Info->TarLUNBusy[lun] = 1;
2950 FPT_queueSelectFail(CurrCard,p_card);
2951 SGRAM_ACCESS(port);
2952 return;
2954 for (i = 1; i < QUEUE_DEPTH; i++)
2956 if (++lastTag >= QUEUE_DEPTH) lastTag = 1;
2957 if (CurrCard->discQ_Tbl[lastTag] == NULL)
2959 CurrCard->tagQ_Lst = lastTag;
2960 currTar_Info->LunDiscQ_Idx[lun] = lastTag;
2961 CurrCard->discQ_Tbl[lastTag] = currSCCB;
2962 CurrCard->discQCount++;
2963 break;
2966 if(i == QUEUE_DEPTH)
2968 currTar_Info->TarLUNBusy[lun] = 1;
2969 FPT_queueSelectFail(CurrCard,p_card);
2970 SGRAM_ACCESS(port);
2971 return;
2977 auto_loaded = 0;
2979 WR_HARPOON(port+hp_select_id, target);
2980 WR_HARPOON(port+hp_gp_reg_3, target); /* Use by new automation logic */
2982 if (currSCCB->OperationCode == RESET_COMMAND) {
2983 WRW_HARPOON((port+ID_MSG_STRT), (MPM_OP+AMSG_OUT+
2984 (currSCCB->Sccb_idmsg & ~DISC_PRIV)));
2986 WRW_HARPOON((port+ID_MSG_STRT+2),BRH_OP+ALWAYS+NP);
2988 currSCCB->Sccb_scsimsg = SMDEV_RESET;
2990 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
2991 auto_loaded = 1;
2992 currSCCB->Sccb_scsistat = SELECT_BDR_ST;
2994 if (currTar_Info->TarEEValue & EE_SYNC_MASK)
2996 currTar_Info->TarSyncCtrl = 0;
2997 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
3000 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
3002 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
3005 FPT_sssyncv(port, target, NARROW_SCSI,currTar_Info);
3006 FPT_SccbMgrTableInitTarget(p_card, target);
3010 else if(currSCCB->Sccb_scsistat == ABORT_ST)
3012 WRW_HARPOON((port+ID_MSG_STRT), (MPM_OP+AMSG_OUT+
3013 (currSCCB->Sccb_idmsg & ~DISC_PRIV)));
3015 WRW_HARPOON((port+ID_MSG_STRT+2),BRH_OP+ALWAYS+CMDPZ);
3017 WRW_HARPOON((port+SYNC_MSGS+0), (MPM_OP+AMSG_OUT+
3018 (((UCHAR)(currSCCB->ControlByte & TAG_TYPE_MASK)
3019 >> 6) | (UCHAR)0x20)));
3020 WRW_HARPOON((port+SYNC_MSGS+2),
3021 (MPM_OP+AMSG_OUT+currSCCB->Sccb_tag));
3022 WRW_HARPOON((port+SYNC_MSGS+4), (BRH_OP+ALWAYS+NP ));
3024 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
3025 auto_loaded = 1;
3029 else if (!(currTar_Info->TarStatus & WIDE_NEGOCIATED)) {
3030 auto_loaded = FPT_siwidn(port,p_card);
3031 currSCCB->Sccb_scsistat = SELECT_WN_ST;
3034 else if (!((currTar_Info->TarStatus & TAR_SYNC_MASK)
3035 == SYNC_SUPPORTED)) {
3036 auto_loaded = FPT_sisyncn(port,p_card, 0);
3037 currSCCB->Sccb_scsistat = SELECT_SN_ST;
3041 if (!auto_loaded)
3044 if (currSCCB->ControlByte & F_USE_CMD_Q)
3047 CurrCard->globalFlags |= F_TAG_STARTED;
3049 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
3050 == TAG_Q_REJECT)
3052 currSCCB->ControlByte &= ~F_USE_CMD_Q;
3054 /* Fix up the start instruction with a jump to
3055 Non-Tag-CMD handling */
3056 WRW_HARPOON((port+ID_MSG_STRT),BRH_OP+ALWAYS+NTCMD);
3058 WRW_HARPOON((port+NON_TAG_ID_MSG),
3059 (MPM_OP+AMSG_OUT+currSCCB->Sccb_idmsg));
3061 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
3063 /* Setup our STATE so we know what happend when
3064 the wheels fall off. */
3065 currSCCB->Sccb_scsistat = SELECT_ST;
3067 currTar_Info->TarLUNBusy[lun] = 1;
3070 else
3072 WRW_HARPOON((port+ID_MSG_STRT), (MPM_OP+AMSG_OUT+currSCCB->Sccb_idmsg));
3074 WRW_HARPOON((port+ID_MSG_STRT+2), (MPM_OP+AMSG_OUT+
3075 (((UCHAR)(currSCCB->ControlByte & TAG_TYPE_MASK)
3076 >> 6) | (UCHAR)0x20)));
3078 for (i = 1; i < QUEUE_DEPTH; i++)
3080 if (++lastTag >= QUEUE_DEPTH) lastTag = 1;
3081 if (CurrCard->discQ_Tbl[lastTag] == NULL)
3083 WRW_HARPOON((port+ID_MSG_STRT+6),
3084 (MPM_OP+AMSG_OUT+lastTag));
3085 CurrCard->tagQ_Lst = lastTag;
3086 currSCCB->Sccb_tag = lastTag;
3087 CurrCard->discQ_Tbl[lastTag] = currSCCB;
3088 CurrCard->discQCount++;
3089 break;
3094 if ( i == QUEUE_DEPTH )
3096 currTar_Info->TarLUNBusy[lun] = 1;
3097 FPT_queueSelectFail(CurrCard,p_card);
3098 SGRAM_ACCESS(port);
3099 return;
3102 currSCCB->Sccb_scsistat = SELECT_Q_ST;
3104 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
3108 else
3111 WRW_HARPOON((port+ID_MSG_STRT),BRH_OP+ALWAYS+NTCMD);
3113 WRW_HARPOON((port+NON_TAG_ID_MSG),
3114 (MPM_OP+AMSG_OUT+currSCCB->Sccb_idmsg));
3116 currSCCB->Sccb_scsistat = SELECT_ST;
3118 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
3122 theCCB = (UCHAR *)&currSCCB->Cdb[0];
3124 cdb_reg = port + CMD_STRT;
3126 for (i=0; i < currSCCB->CdbLength; i++)
3128 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + *theCCB));
3129 cdb_reg +=2;
3130 theCCB++;
3133 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
3134 WRW_HARPOON(cdb_reg, (BRH_OP+ALWAYS+ NP));
3136 } /* auto_loaded */
3138 WRW_HARPOON((port+hp_fiforead), (USHORT) 0x00);
3139 WR_HARPOON(port+hp_xferstat, 0x00);
3141 WRW_HARPOON((port+hp_intstat), (PROG_HLT | TIMEOUT | SEL | BUS_FREE));
3143 WR_HARPOON(port+hp_portctrl_0,(SCSI_PORT));
3146 if (!(currSCCB->Sccb_MGRFlags & F_DEV_SELECTED))
3148 WR_HARPOON(port+hp_scsictrl_0, (SEL_TAR | ENA_ATN | ENA_RESEL | ENA_SCAM_SEL));
3150 else
3153 /* auto_loaded = (RD_HARPOON(port+hp_autostart_3) & (UCHAR)0x1F);
3154 auto_loaded |= AUTO_IMMED; */
3155 auto_loaded = AUTO_IMMED;
3157 DISABLE_AUTO(port);
3159 WR_HARPOON(port+hp_autostart_3, auto_loaded);
3162 SGRAM_ACCESS(port);
3166 /*---------------------------------------------------------------------
3168 * Function: FPT_sres
3170 * Description: Hookup the correct CCB and handle the incoming messages.
3172 *---------------------------------------------------------------------*/
3174 static void FPT_sres(ULONG port, UCHAR p_card, PSCCBcard pCurrCard)
3177 UCHAR our_target, message, lun = 0, tag, msgRetryCount;
3180 PSCCBMgr_tar_info currTar_Info;
3181 PSCCB currSCCB;
3186 if(pCurrCard->currentSCCB != NULL)
3188 currTar_Info = &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
3189 DISABLE_AUTO(port);
3192 WR_HARPOON((port+hp_scsictrl_0),(ENA_RESEL | ENA_SCAM_SEL));
3195 currSCCB = pCurrCard->currentSCCB;
3196 if(currSCCB->Sccb_scsistat == SELECT_WN_ST)
3198 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
3199 currSCCB->Sccb_scsistat = BUS_FREE_ST;
3201 if(currSCCB->Sccb_scsistat == SELECT_SN_ST)
3203 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
3204 currSCCB->Sccb_scsistat = BUS_FREE_ST;
3206 if(((pCurrCard->globalFlags & F_CONLUN_IO) &&
3207 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
3209 currTar_Info->TarLUNBusy[currSCCB->Lun] = 0;
3210 if(currSCCB->Sccb_scsistat != ABORT_ST)
3212 pCurrCard->discQCount--;
3213 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[currSCCB->Lun]]
3214 = NULL;
3217 else
3219 currTar_Info->TarLUNBusy[0] = 0;
3220 if(currSCCB->Sccb_tag)
3222 if(currSCCB->Sccb_scsistat != ABORT_ST)
3224 pCurrCard->discQCount--;
3225 pCurrCard->discQ_Tbl[currSCCB->Sccb_tag] = NULL;
3227 }else
3229 if(currSCCB->Sccb_scsistat != ABORT_ST)
3231 pCurrCard->discQCount--;
3232 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = NULL;
3237 FPT_queueSelectFail(&FPT_BL_Card[p_card],p_card);
3240 WRW_HARPOON((port+hp_fiforead), (USHORT) 0x00);
3243 our_target = (UCHAR)(RD_HARPOON(port+hp_select_id) >> 4);
3244 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
3247 msgRetryCount = 0;
3251 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
3252 tag = 0;
3255 while(!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ))
3257 if (! (RD_HARPOON(port+hp_scsisig) & SCSI_BSY))
3260 WRW_HARPOON((port+hp_intstat), PHASE);
3261 return;
3265 WRW_HARPOON((port+hp_intstat), PHASE);
3266 if ((RD_HARPOON(port+hp_scsisig) & S_SCSI_PHZ) == S_MSGI_PH)
3269 message = FPT_sfm(port,pCurrCard->currentSCCB);
3270 if (message)
3273 if (message <= (0x80 | LUN_MASK))
3275 lun = message & (UCHAR)LUN_MASK;
3277 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_TRYING)
3279 if (currTar_Info->TarTagQ_Cnt != 0)
3282 if (!(currTar_Info->TarLUN_CA))
3284 ACCEPT_MSG(port); /*Release the ACK for ID msg. */
3287 message = FPT_sfm(port,pCurrCard->currentSCCB);
3288 if (message)
3290 ACCEPT_MSG(port);
3293 else
3294 message = 0;
3296 if(message != 0)
3298 tag = FPT_sfm(port,pCurrCard->currentSCCB);
3300 if (!(tag))
3301 message = 0;
3304 } /*C.A. exists! */
3306 } /*End Q cnt != 0 */
3308 } /*End Tag cmds supported! */
3310 } /*End valid ID message. */
3312 else
3315 ACCEPT_MSG_ATN(port);
3318 } /* End good id message. */
3320 else
3323 message = 0;
3326 else
3328 ACCEPT_MSG_ATN(port);
3330 while (!(RDW_HARPOON((port+hp_intstat)) & (PHASE | RESET)) &&
3331 !(RD_HARPOON(port+hp_scsisig) & SCSI_REQ) &&
3332 (RD_HARPOON(port+hp_scsisig) & SCSI_BSY)) ;
3334 return;
3337 if(message == 0)
3339 msgRetryCount++;
3340 if(msgRetryCount == 1)
3342 FPT_SendMsg(port, SMPARITY);
3344 else
3346 FPT_SendMsg(port, SMDEV_RESET);
3348 FPT_sssyncv(port, our_target, NARROW_SCSI,currTar_Info);
3350 if (FPT_sccbMgrTbl[p_card][our_target].TarEEValue & EE_SYNC_MASK)
3353 FPT_sccbMgrTbl[p_card][our_target].TarStatus &= ~TAR_SYNC_MASK;
3357 if (FPT_sccbMgrTbl[p_card][our_target].TarEEValue & EE_WIDE_SCSI)
3360 FPT_sccbMgrTbl[p_card][our_target].TarStatus &= ~TAR_WIDE_MASK;
3364 FPT_queueFlushTargSccb(p_card, our_target, SCCB_COMPLETE);
3365 FPT_SccbMgrTableInitTarget(p_card,our_target);
3366 return;
3369 }while(message == 0);
3373 if(((pCurrCard->globalFlags & F_CONLUN_IO) &&
3374 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
3376 currTar_Info->TarLUNBusy[lun] = 1;
3377 pCurrCard->currentSCCB = pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[lun]];
3378 if(pCurrCard->currentSCCB != NULL)
3380 ACCEPT_MSG(port);
3382 else
3384 ACCEPT_MSG_ATN(port);
3387 else
3389 currTar_Info->TarLUNBusy[0] = 1;
3392 if (tag)
3394 if (pCurrCard->discQ_Tbl[tag] != NULL)
3396 pCurrCard->currentSCCB = pCurrCard->discQ_Tbl[tag];
3397 currTar_Info->TarTagQ_Cnt--;
3398 ACCEPT_MSG(port);
3400 else
3402 ACCEPT_MSG_ATN(port);
3404 }else
3406 pCurrCard->currentSCCB = pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]];
3407 if(pCurrCard->currentSCCB != NULL)
3409 ACCEPT_MSG(port);
3411 else
3413 ACCEPT_MSG_ATN(port);
3418 if(pCurrCard->currentSCCB != NULL)
3420 if(pCurrCard->currentSCCB->Sccb_scsistat == ABORT_ST)
3422 /* During Abort Tag command, the target could have got re-selected
3423 and completed the command. Check the select Q and remove the CCB
3424 if it is in the Select Q */
3425 FPT_queueFindSccb(pCurrCard->currentSCCB, p_card);
3430 while (!(RDW_HARPOON((port+hp_intstat)) & (PHASE | RESET)) &&
3431 !(RD_HARPOON(port+hp_scsisig) & SCSI_REQ) &&
3432 (RD_HARPOON(port+hp_scsisig) & SCSI_BSY)) ;
3435 static void FPT_SendMsg(ULONG port, UCHAR message)
3437 while(!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ))
3439 if (! (RD_HARPOON(port+hp_scsisig) & SCSI_BSY))
3442 WRW_HARPOON((port+hp_intstat), PHASE);
3443 return;
3447 WRW_HARPOON((port+hp_intstat), PHASE);
3448 if ((RD_HARPOON(port+hp_scsisig) & S_SCSI_PHZ) == S_MSGO_PH)
3450 WRW_HARPOON((port+hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0));
3453 WR_HARPOON(port+hp_portctrl_0, SCSI_BUS_EN);
3455 WR_HARPOON(port+hp_scsidata_0,message);
3457 WR_HARPOON(port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
3459 ACCEPT_MSG(port);
3461 WR_HARPOON(port+hp_portctrl_0, 0x00);
3463 if ((message == SMABORT) || (message == SMDEV_RESET) ||
3464 (message == SMABORT_TAG) )
3466 while(!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | PHASE))) {}
3468 if (RDW_HARPOON((port+hp_intstat)) & BUS_FREE)
3470 WRW_HARPOON((port+hp_intstat), BUS_FREE);
3476 /*---------------------------------------------------------------------
3478 * Function: FPT_sdecm
3480 * Description: Determine the proper responce to the message from the
3481 * target device.
3483 *---------------------------------------------------------------------*/
3484 static void FPT_sdecm(UCHAR message, ULONG port, UCHAR p_card)
3486 PSCCB currSCCB;
3487 PSCCBcard CurrCard;
3488 PSCCBMgr_tar_info currTar_Info;
3490 CurrCard = &FPT_BL_Card[p_card];
3491 currSCCB = CurrCard->currentSCCB;
3493 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3495 if (message == SMREST_DATA_PTR)
3497 if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET))
3499 currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC;
3501 FPT_hostDataXferRestart(currSCCB);
3504 ACCEPT_MSG(port);
3505 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3508 else if (message == SMCMD_COMP)
3512 if (currSCCB->Sccb_scsistat == SELECT_Q_ST)
3514 currTar_Info->TarStatus &= ~(UCHAR)TAR_TAG_Q_MASK;
3515 currTar_Info->TarStatus |= (UCHAR)TAG_Q_REJECT;
3518 ACCEPT_MSG(port);
3522 else if ((message == SMNO_OP) || (message >= SMIDENT)
3523 || (message == SMINIT_RECOVERY) || (message == SMREL_RECOVERY))
3526 ACCEPT_MSG(port);
3527 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3530 else if (message == SMREJECT)
3533 if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) ||
3534 (currSCCB->Sccb_scsistat == SELECT_WN_ST) ||
3535 ((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING ) ||
3536 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_TRYING ) )
3539 WRW_HARPOON((port+hp_intstat), BUS_FREE);
3541 ACCEPT_MSG(port);
3544 while ((!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ)) &&
3545 (!(RDW_HARPOON((port+hp_intstat)) & BUS_FREE))) {}
3547 if(currSCCB->Lun == 0x00)
3549 if ((currSCCB->Sccb_scsistat == SELECT_SN_ST))
3552 currTar_Info->TarStatus |= (UCHAR)SYNC_SUPPORTED;
3554 currTar_Info->TarEEValue &= ~EE_SYNC_MASK;
3557 else if ((currSCCB->Sccb_scsistat == SELECT_WN_ST))
3561 currTar_Info->TarStatus = (currTar_Info->TarStatus &
3562 ~WIDE_ENABLED) | WIDE_NEGOCIATED;
3564 currTar_Info->TarEEValue &= ~EE_WIDE_SCSI;
3568 else if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_TRYING )
3570 currTar_Info->TarStatus = (currTar_Info->TarStatus &
3571 ~(UCHAR)TAR_TAG_Q_MASK) | TAG_Q_REJECT;
3574 currSCCB->ControlByte &= ~F_USE_CMD_Q;
3575 CurrCard->discQCount--;
3576 CurrCard->discQ_Tbl[currSCCB->Sccb_tag] = NULL;
3577 currSCCB->Sccb_tag = 0x00;
3582 if (RDW_HARPOON((port+hp_intstat)) & BUS_FREE)
3586 if(currSCCB->Lun == 0x00)
3588 WRW_HARPOON((port+hp_intstat), BUS_FREE);
3589 CurrCard->globalFlags |= F_NEW_SCCB_CMD;
3593 else
3596 if((CurrCard->globalFlags & F_CONLUN_IO) &&
3597 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
3598 currTar_Info->TarLUNBusy[currSCCB->Lun] = 1;
3599 else
3600 currTar_Info->TarLUNBusy[0] = 1;
3603 currSCCB->ControlByte &= ~(UCHAR)F_USE_CMD_Q;
3605 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3610 else
3612 ACCEPT_MSG(port);
3614 while ((!(RD_HARPOON(port+hp_scsisig) & SCSI_REQ)) &&
3615 (!(RDW_HARPOON((port+hp_intstat)) & BUS_FREE))) {}
3617 if (!(RDW_HARPOON((port+hp_intstat)) & BUS_FREE))
3619 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3624 else if (message == SMEXT)
3627 ACCEPT_MSG(port);
3628 FPT_shandem(port,p_card,currSCCB);
3631 else if (message == SMIGNORWR)
3634 ACCEPT_MSG(port); /* ACK the RESIDUE MSG */
3636 message = FPT_sfm(port,currSCCB);
3638 if(currSCCB->Sccb_scsimsg != SMPARITY)
3639 ACCEPT_MSG(port);
3640 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3644 else
3647 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
3648 currSCCB->Sccb_scsimsg = SMREJECT;
3650 ACCEPT_MSG_ATN(port);
3651 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3656 /*---------------------------------------------------------------------
3658 * Function: FPT_shandem
3660 * Description: Decide what to do with the extended message.
3662 *---------------------------------------------------------------------*/
3663 static void FPT_shandem(ULONG port, UCHAR p_card, PSCCB pCurrSCCB)
3665 UCHAR length,message;
3667 length = FPT_sfm(port,pCurrSCCB);
3668 if (length)
3671 ACCEPT_MSG(port);
3672 message = FPT_sfm(port,pCurrSCCB);
3673 if (message)
3676 if (message == SMSYNC)
3679 if (length == 0x03)
3682 ACCEPT_MSG(port);
3683 FPT_stsyncn(port,p_card);
3685 else
3688 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3689 ACCEPT_MSG_ATN(port);
3692 else if (message == SMWDTR)
3695 if (length == 0x02)
3698 ACCEPT_MSG(port);
3699 FPT_stwidn(port,p_card);
3701 else
3704 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3705 ACCEPT_MSG_ATN(port);
3707 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3710 else
3713 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3714 ACCEPT_MSG_ATN(port);
3716 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3719 else
3721 if(pCurrSCCB->Sccb_scsimsg != SMPARITY)
3722 ACCEPT_MSG(port);
3723 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3725 }else
3727 if(pCurrSCCB->Sccb_scsimsg == SMPARITY)
3728 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3733 /*---------------------------------------------------------------------
3735 * Function: FPT_sisyncn
3737 * Description: Read in a message byte from the SCSI bus, and check
3738 * for a parity error.
3740 *---------------------------------------------------------------------*/
3742 static UCHAR FPT_sisyncn(ULONG port, UCHAR p_card, UCHAR syncFlag)
3744 PSCCB currSCCB;
3745 PSCCBMgr_tar_info currTar_Info;
3747 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3748 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3750 if (!((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)) {
3753 WRW_HARPOON((port+ID_MSG_STRT),
3754 (MPM_OP+AMSG_OUT+(currSCCB->Sccb_idmsg & ~(UCHAR)DISC_PRIV)));
3756 WRW_HARPOON((port+ID_MSG_STRT+2),BRH_OP+ALWAYS+CMDPZ);
3758 WRW_HARPOON((port+SYNC_MSGS+0), (MPM_OP+AMSG_OUT+SMEXT ));
3759 WRW_HARPOON((port+SYNC_MSGS+2), (MPM_OP+AMSG_OUT+0x03 ));
3760 WRW_HARPOON((port+SYNC_MSGS+4), (MPM_OP+AMSG_OUT+SMSYNC));
3763 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3765 WRW_HARPOON((port+SYNC_MSGS+6), (MPM_OP+AMSG_OUT+ 12));
3767 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_10MB)
3769 WRW_HARPOON((port+SYNC_MSGS+6), (MPM_OP+AMSG_OUT+ 25));
3771 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_5MB)
3773 WRW_HARPOON((port+SYNC_MSGS+6), (MPM_OP+AMSG_OUT+ 50));
3775 else
3776 WRW_HARPOON((port+SYNC_MSGS+6), (MPM_OP+AMSG_OUT+ 00));
3779 WRW_HARPOON((port+SYNC_MSGS+8), (RAT_OP ));
3780 WRW_HARPOON((port+SYNC_MSGS+10),(MPM_OP+AMSG_OUT+DEFAULT_OFFSET));
3781 WRW_HARPOON((port+SYNC_MSGS+12),(BRH_OP+ALWAYS+NP ));
3784 if(syncFlag == 0)
3786 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
3787 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3788 ~(UCHAR)TAR_SYNC_MASK) | (UCHAR)SYNC_TRYING);
3790 else
3792 WR_HARPOON(port+hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
3796 return(1);
3799 else {
3801 currTar_Info->TarStatus |= (UCHAR)SYNC_SUPPORTED;
3802 currTar_Info->TarEEValue &= ~EE_SYNC_MASK;
3803 return(0);
3809 /*---------------------------------------------------------------------
3811 * Function: FPT_stsyncn
3813 * Description: The has sent us a Sync Nego message so handle it as
3814 * necessary.
3816 *---------------------------------------------------------------------*/
3817 static void FPT_stsyncn(ULONG port, UCHAR p_card)
3819 UCHAR sync_msg,offset,sync_reg,our_sync_msg;
3820 PSCCB currSCCB;
3821 PSCCBMgr_tar_info currTar_Info;
3823 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3824 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3826 sync_msg = FPT_sfm(port,currSCCB);
3828 if((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY))
3830 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3831 return;
3834 ACCEPT_MSG(port);
3837 offset = FPT_sfm(port,currSCCB);
3839 if((offset == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY))
3841 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3842 return;
3845 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3847 our_sync_msg = 12; /* Setup our Message to 20mb/s */
3849 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_10MB)
3851 our_sync_msg = 25; /* Setup our Message to 10mb/s */
3853 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_5MB)
3855 our_sync_msg = 50; /* Setup our Message to 5mb/s */
3856 else
3858 our_sync_msg = 0; /* Message = Async */
3860 if (sync_msg < our_sync_msg) {
3861 sync_msg = our_sync_msg; /*if faster, then set to max. */
3864 if (offset == ASYNC)
3865 sync_msg = ASYNC;
3867 if (offset > MAX_OFFSET)
3868 offset = MAX_OFFSET;
3870 sync_reg = 0x00;
3872 if (sync_msg > 12)
3874 sync_reg = 0x20; /* Use 10MB/s */
3876 if (sync_msg > 25)
3878 sync_reg = 0x40; /* Use 6.6MB/s */
3880 if (sync_msg > 38)
3882 sync_reg = 0x60; /* Use 5MB/s */
3884 if (sync_msg > 50)
3886 sync_reg = 0x80; /* Use 4MB/s */
3888 if (sync_msg > 62)
3890 sync_reg = 0xA0; /* Use 3.33MB/s */
3892 if (sync_msg > 75)
3894 sync_reg = 0xC0; /* Use 2.85MB/s */
3896 if (sync_msg > 87)
3898 sync_reg = 0xE0; /* Use 2.5MB/s */
3900 if (sync_msg > 100) {
3902 sync_reg = 0x00; /* Use ASYNC */
3903 offset = 0x00;
3907 if (currTar_Info->TarStatus & WIDE_ENABLED)
3909 sync_reg |= offset;
3911 else
3913 sync_reg |= (offset | NARROW_SCSI);
3915 FPT_sssyncv(port,currSCCB->TargID,sync_reg,currTar_Info);
3918 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
3921 ACCEPT_MSG(port);
3923 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3924 ~(UCHAR)TAR_SYNC_MASK) | (UCHAR)SYNC_SUPPORTED);
3926 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
3929 else {
3932 ACCEPT_MSG_ATN(port);
3934 FPT_sisyncr(port,sync_msg,offset);
3936 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3937 ~(UCHAR)TAR_SYNC_MASK) | (UCHAR)SYNC_SUPPORTED);
3942 /*---------------------------------------------------------------------
3944 * Function: FPT_sisyncr
3946 * Description: Answer the targets sync message.
3948 *---------------------------------------------------------------------*/
3949 static void FPT_sisyncr(ULONG port,UCHAR sync_pulse, UCHAR offset)
3951 ARAM_ACCESS(port);
3952 WRW_HARPOON((port+SYNC_MSGS+0), (MPM_OP+AMSG_OUT+SMEXT ));
3953 WRW_HARPOON((port+SYNC_MSGS+2), (MPM_OP+AMSG_OUT+0x03 ));
3954 WRW_HARPOON((port+SYNC_MSGS+4), (MPM_OP+AMSG_OUT+SMSYNC));
3955 WRW_HARPOON((port+SYNC_MSGS+6), (MPM_OP+AMSG_OUT+sync_pulse));
3956 WRW_HARPOON((port+SYNC_MSGS+8), (RAT_OP ));
3957 WRW_HARPOON((port+SYNC_MSGS+10),(MPM_OP+AMSG_OUT+offset));
3958 WRW_HARPOON((port+SYNC_MSGS+12),(BRH_OP+ALWAYS+NP ));
3959 SGRAM_ACCESS(port);
3961 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
3962 WRW_HARPOON((port+hp_intstat), CLR_ALL_INT_1);
3964 WR_HARPOON(port+hp_autostart_3, (AUTO_IMMED+CMD_ONLY_STRT));
3966 while (!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | AUTO_INT))) {}
3971 /*---------------------------------------------------------------------
3973 * Function: FPT_siwidn
3975 * Description: Read in a message byte from the SCSI bus, and check
3976 * for a parity error.
3978 *---------------------------------------------------------------------*/
3980 static UCHAR FPT_siwidn(ULONG port, UCHAR p_card)
3982 PSCCB currSCCB;
3983 PSCCBMgr_tar_info currTar_Info;
3985 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3986 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3988 if (!((currTar_Info->TarStatus & TAR_WIDE_MASK) == WIDE_NEGOCIATED)) {
3991 WRW_HARPOON((port+ID_MSG_STRT),
3992 (MPM_OP+AMSG_OUT+(currSCCB->Sccb_idmsg & ~(UCHAR)DISC_PRIV)));
3994 WRW_HARPOON((port+ID_MSG_STRT+2),BRH_OP+ALWAYS+CMDPZ);
3996 WRW_HARPOON((port+SYNC_MSGS+0), (MPM_OP+AMSG_OUT+SMEXT ));
3997 WRW_HARPOON((port+SYNC_MSGS+2), (MPM_OP+AMSG_OUT+0x02 ));
3998 WRW_HARPOON((port+SYNC_MSGS+4), (MPM_OP+AMSG_OUT+SMWDTR));
3999 WRW_HARPOON((port+SYNC_MSGS+6), (RAT_OP ));
4000 WRW_HARPOON((port+SYNC_MSGS+8), (MPM_OP+AMSG_OUT+ SM16BIT));
4001 WRW_HARPOON((port+SYNC_MSGS+10),(BRH_OP+ALWAYS+NP ));
4003 WR_HARPOON(port+hp_autostart_3, (SELECT+SELCHK_STRT));
4006 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
4007 ~(UCHAR)TAR_WIDE_MASK) | (UCHAR)WIDE_ENABLED);
4009 return(1);
4012 else {
4014 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
4015 ~(UCHAR)TAR_WIDE_MASK) | WIDE_NEGOCIATED);
4017 currTar_Info->TarEEValue &= ~EE_WIDE_SCSI;
4018 return(0);
4024 /*---------------------------------------------------------------------
4026 * Function: FPT_stwidn
4028 * Description: The has sent us a Wide Nego message so handle it as
4029 * necessary.
4031 *---------------------------------------------------------------------*/
4032 static void FPT_stwidn(ULONG port, UCHAR p_card)
4034 UCHAR width;
4035 PSCCB currSCCB;
4036 PSCCBMgr_tar_info currTar_Info;
4038 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4039 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
4041 width = FPT_sfm(port,currSCCB);
4043 if((width == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY))
4045 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
4046 return;
4050 if (!(currTar_Info->TarEEValue & EE_WIDE_SCSI))
4051 width = 0;
4053 if (width) {
4054 currTar_Info->TarStatus |= WIDE_ENABLED;
4055 width = 0;
4057 else {
4058 width = NARROW_SCSI;
4059 currTar_Info->TarStatus &= ~WIDE_ENABLED;
4063 FPT_sssyncv(port,currSCCB->TargID,width,currTar_Info);
4066 if (currSCCB->Sccb_scsistat == SELECT_WN_ST)
4071 currTar_Info->TarStatus |= WIDE_NEGOCIATED;
4073 if (!((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_SUPPORTED))
4075 ACCEPT_MSG_ATN(port);
4076 ARAM_ACCESS(port);
4077 FPT_sisyncn(port,p_card, 1);
4078 currSCCB->Sccb_scsistat = SELECT_SN_ST;
4079 SGRAM_ACCESS(port);
4081 else
4083 ACCEPT_MSG(port);
4084 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
4088 else {
4091 ACCEPT_MSG_ATN(port);
4093 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
4094 width = SM16BIT;
4095 else
4096 width = SM8BIT;
4098 FPT_siwidr(port,width);
4100 currTar_Info->TarStatus |= (WIDE_NEGOCIATED | WIDE_ENABLED);
4105 /*---------------------------------------------------------------------
4107 * Function: FPT_siwidr
4109 * Description: Answer the targets Wide nego message.
4111 *---------------------------------------------------------------------*/
4112 static void FPT_siwidr(ULONG port, UCHAR width)
4114 ARAM_ACCESS(port);
4115 WRW_HARPOON((port+SYNC_MSGS+0), (MPM_OP+AMSG_OUT+SMEXT ));
4116 WRW_HARPOON((port+SYNC_MSGS+2), (MPM_OP+AMSG_OUT+0x02 ));
4117 WRW_HARPOON((port+SYNC_MSGS+4), (MPM_OP+AMSG_OUT+SMWDTR));
4118 WRW_HARPOON((port+SYNC_MSGS+6), (RAT_OP ));
4119 WRW_HARPOON((port+SYNC_MSGS+8),(MPM_OP+AMSG_OUT+width));
4120 WRW_HARPOON((port+SYNC_MSGS+10),(BRH_OP+ALWAYS+NP ));
4121 SGRAM_ACCESS(port);
4123 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
4124 WRW_HARPOON((port+hp_intstat), CLR_ALL_INT_1);
4126 WR_HARPOON(port+hp_autostart_3, (AUTO_IMMED+CMD_ONLY_STRT));
4128 while (!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | AUTO_INT))) {}
4133 /*---------------------------------------------------------------------
4135 * Function: FPT_sssyncv
4137 * Description: Write the desired value to the Sync Register for the
4138 * ID specified.
4140 *---------------------------------------------------------------------*/
4141 static void FPT_sssyncv(ULONG p_port, UCHAR p_id, UCHAR p_sync_value,
4142 PSCCBMgr_tar_info currTar_Info)
4144 UCHAR index;
4146 index = p_id;
4148 switch (index) {
4150 case 0:
4151 index = 12; /* hp_synctarg_0 */
4152 break;
4153 case 1:
4154 index = 13; /* hp_synctarg_1 */
4155 break;
4156 case 2:
4157 index = 14; /* hp_synctarg_2 */
4158 break;
4159 case 3:
4160 index = 15; /* hp_synctarg_3 */
4161 break;
4162 case 4:
4163 index = 8; /* hp_synctarg_4 */
4164 break;
4165 case 5:
4166 index = 9; /* hp_synctarg_5 */
4167 break;
4168 case 6:
4169 index = 10; /* hp_synctarg_6 */
4170 break;
4171 case 7:
4172 index = 11; /* hp_synctarg_7 */
4173 break;
4174 case 8:
4175 index = 4; /* hp_synctarg_8 */
4176 break;
4177 case 9:
4178 index = 5; /* hp_synctarg_9 */
4179 break;
4180 case 10:
4181 index = 6; /* hp_synctarg_10 */
4182 break;
4183 case 11:
4184 index = 7; /* hp_synctarg_11 */
4185 break;
4186 case 12:
4187 index = 0; /* hp_synctarg_12 */
4188 break;
4189 case 13:
4190 index = 1; /* hp_synctarg_13 */
4191 break;
4192 case 14:
4193 index = 2; /* hp_synctarg_14 */
4194 break;
4195 case 15:
4196 index = 3; /* hp_synctarg_15 */
4200 WR_HARPOON(p_port+hp_synctarg_base+index, p_sync_value);
4202 currTar_Info->TarSyncCtrl = p_sync_value;
4206 /*---------------------------------------------------------------------
4208 * Function: FPT_sresb
4210 * Description: Reset the desired card's SCSI bus.
4212 *---------------------------------------------------------------------*/
4213 static void FPT_sresb(ULONG port, UCHAR p_card)
4215 UCHAR scsiID, i;
4217 PSCCBMgr_tar_info currTar_Info;
4219 WR_HARPOON(port+hp_page_ctrl,
4220 (RD_HARPOON(port+hp_page_ctrl) | G_INT_DISABLE));
4221 WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
4223 WR_HARPOON(port+hp_scsictrl_0, SCSI_RST);
4225 scsiID = RD_HARPOON(port+hp_seltimeout);
4226 WR_HARPOON(port+hp_seltimeout,TO_5ms);
4227 WRW_HARPOON((port+hp_intstat), TIMEOUT);
4229 WR_HARPOON(port+hp_portctrl_0,(SCSI_PORT | START_TO));
4231 while (!(RDW_HARPOON((port+hp_intstat)) & TIMEOUT)) {}
4233 WR_HARPOON(port+hp_seltimeout,scsiID);
4235 WR_HARPOON(port+hp_scsictrl_0, ENA_SCAM_SEL);
4237 FPT_Wait(port, TO_5ms);
4239 WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
4241 WR_HARPOON(port+hp_int_mask, (RD_HARPOON(port+hp_int_mask) | 0x00));
4243 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++)
4245 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
4247 if (currTar_Info->TarEEValue & EE_SYNC_MASK)
4249 currTar_Info->TarSyncCtrl = 0;
4250 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
4253 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
4255 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
4258 FPT_sssyncv(port, scsiID, NARROW_SCSI,currTar_Info);
4260 FPT_SccbMgrTableInitTarget(p_card, scsiID);
4263 FPT_BL_Card[p_card].scanIndex = 0x00;
4264 FPT_BL_Card[p_card].currentSCCB = NULL;
4265 FPT_BL_Card[p_card].globalFlags &= ~(F_TAG_STARTED | F_HOST_XFER_ACT
4266 | F_NEW_SCCB_CMD);
4267 FPT_BL_Card[p_card].cmdCounter = 0x00;
4268 FPT_BL_Card[p_card].discQCount = 0x00;
4269 FPT_BL_Card[p_card].tagQ_Lst = 0x01;
4271 for(i = 0; i < QUEUE_DEPTH; i++)
4272 FPT_BL_Card[p_card].discQ_Tbl[i] = NULL;
4274 WR_HARPOON(port+hp_page_ctrl,
4275 (RD_HARPOON(port+hp_page_ctrl) & ~G_INT_DISABLE));
4279 /*---------------------------------------------------------------------
4281 * Function: FPT_ssenss
4283 * Description: Setup for the Auto Sense command.
4285 *---------------------------------------------------------------------*/
4286 static void FPT_ssenss(PSCCBcard pCurrCard)
4288 UCHAR i;
4289 PSCCB currSCCB;
4291 currSCCB = pCurrCard->currentSCCB;
4294 currSCCB->Save_CdbLen = currSCCB->CdbLength;
4296 for (i = 0; i < 6; i++) {
4298 currSCCB->Save_Cdb[i] = currSCCB->Cdb[i];
4301 currSCCB->CdbLength = SIX_BYTE_CMD;
4302 currSCCB->Cdb[0] = SCSI_REQUEST_SENSE;
4303 currSCCB->Cdb[1] = currSCCB->Cdb[1] & (UCHAR)0xE0; /*Keep LUN. */
4304 currSCCB->Cdb[2] = 0x00;
4305 currSCCB->Cdb[3] = 0x00;
4306 currSCCB->Cdb[4] = currSCCB->RequestSenseLength;
4307 currSCCB->Cdb[5] = 0x00;
4309 currSCCB->Sccb_XferCnt = (unsigned long)currSCCB->RequestSenseLength;
4311 currSCCB->Sccb_ATC = 0x00;
4313 currSCCB->Sccb_XferState |= F_AUTO_SENSE;
4315 currSCCB->Sccb_XferState &= ~F_SG_XFER;
4317 currSCCB->Sccb_idmsg = currSCCB->Sccb_idmsg & ~(UCHAR)DISC_PRIV;
4319 currSCCB->ControlByte = 0x00;
4321 currSCCB->Sccb_MGRFlags &= F_STATUSLOADED;
4326 /*---------------------------------------------------------------------
4328 * Function: FPT_sxfrp
4330 * Description: Transfer data into the bit bucket until the device
4331 * decides to switch phase.
4333 *---------------------------------------------------------------------*/
4335 static void FPT_sxfrp(ULONG p_port, UCHAR p_card)
4337 UCHAR curr_phz;
4340 DISABLE_AUTO(p_port);
4342 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
4344 FPT_hostDataXferAbort(p_port,p_card,FPT_BL_Card[p_card].currentSCCB);
4348 /* If the Automation handled the end of the transfer then do not
4349 match the phase or we will get out of sync with the ISR. */
4351 if (RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | XFER_CNT_0 | AUTO_INT))
4352 return;
4354 WR_HARPOON(p_port+hp_xfercnt_0, 0x00);
4356 curr_phz = RD_HARPOON(p_port+hp_scsisig) & (UCHAR)S_SCSI_PHZ;
4358 WRW_HARPOON((p_port+hp_intstat), XFER_CNT_0);
4361 WR_HARPOON(p_port+hp_scsisig, curr_phz);
4363 while ( !(RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | RESET)) &&
4364 (curr_phz == (RD_HARPOON(p_port+hp_scsisig) & (UCHAR)S_SCSI_PHZ)) )
4366 if (curr_phz & (UCHAR)SCSI_IOBIT)
4368 WR_HARPOON(p_port+hp_portctrl_0, (SCSI_PORT | HOST_PORT | SCSI_INBIT));
4370 if (!(RD_HARPOON(p_port+hp_xferstat) & FIFO_EMPTY))
4372 RD_HARPOON(p_port+hp_fifodata_0);
4375 else
4377 WR_HARPOON(p_port+hp_portctrl_0, (SCSI_PORT | HOST_PORT | HOST_WRT));
4378 if (RD_HARPOON(p_port+hp_xferstat) & FIFO_EMPTY)
4380 WR_HARPOON(p_port+hp_fifodata_0,0xFA);
4383 } /* End of While loop for padding data I/O phase */
4385 while ( !(RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | RESET)))
4387 if (RD_HARPOON(p_port+hp_scsisig) & SCSI_REQ)
4388 break;
4391 WR_HARPOON(p_port+hp_portctrl_0, (SCSI_PORT | HOST_PORT | SCSI_INBIT));
4392 while (!(RD_HARPOON(p_port+hp_xferstat) & FIFO_EMPTY))
4394 RD_HARPOON(p_port+hp_fifodata_0);
4397 if ( !(RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | RESET)))
4399 WR_HARPOON(p_port+hp_autostart_0, (AUTO_IMMED+DISCONNECT_START));
4400 while (!(RDW_HARPOON((p_port+hp_intstat)) & AUTO_INT)) {}
4402 if (RDW_HARPOON((p_port+hp_intstat)) & (ICMD_COMP | ITAR_DISC))
4403 while (!(RDW_HARPOON((p_port+hp_intstat)) & (BUS_FREE | RSEL))) ;
4408 /*---------------------------------------------------------------------
4410 * Function: FPT_schkdd
4412 * Description: Make sure data has been flushed from both FIFOs and abort
4413 * the operations if necessary.
4415 *---------------------------------------------------------------------*/
4417 static void FPT_schkdd(ULONG port, UCHAR p_card)
4419 USHORT TimeOutLoop;
4420 UCHAR sPhase;
4422 PSCCB currSCCB;
4424 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4427 if ((currSCCB->Sccb_scsistat != DATA_OUT_ST) &&
4428 (currSCCB->Sccb_scsistat != DATA_IN_ST)) {
4429 return;
4434 if (currSCCB->Sccb_XferState & F_ODD_BALL_CNT)
4437 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt-1);
4439 currSCCB->Sccb_XferCnt = 1;
4441 currSCCB->Sccb_XferState &= ~F_ODD_BALL_CNT;
4442 WRW_HARPOON((port+hp_fiforead), (USHORT) 0x00);
4443 WR_HARPOON(port+hp_xferstat, 0x00);
4446 else
4449 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
4451 currSCCB->Sccb_XferCnt = 0;
4454 if ((RDW_HARPOON((port+hp_intstat)) & PARITY) &&
4455 (currSCCB->HostStatus == SCCB_COMPLETE)) {
4457 currSCCB->HostStatus = SCCB_PARITY_ERR;
4458 WRW_HARPOON((port+hp_intstat), PARITY);
4462 FPT_hostDataXferAbort(port,p_card,currSCCB);
4465 while (RD_HARPOON(port+hp_scsisig) & SCSI_ACK) {}
4467 TimeOutLoop = 0;
4469 while(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY)
4471 if (RDW_HARPOON((port+hp_intstat)) & BUS_FREE) {
4472 return;
4474 if (RD_HARPOON(port+hp_offsetctr) & (UCHAR)0x1F) {
4475 break;
4477 if (RDW_HARPOON((port+hp_intstat)) & RESET) {
4478 return;
4480 if ((RD_HARPOON(port+hp_scsisig) & SCSI_REQ) || (TimeOutLoop++>0x3000) )
4481 break;
4484 sPhase = RD_HARPOON(port+hp_scsisig) & (SCSI_BSY | S_SCSI_PHZ);
4485 if ((!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY)) ||
4486 (RD_HARPOON(port+hp_offsetctr) & (UCHAR)0x1F) ||
4487 (sPhase == (SCSI_BSY | S_DATAO_PH)) ||
4488 (sPhase == (SCSI_BSY | S_DATAI_PH)))
4491 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
4493 if (!(currSCCB->Sccb_XferState & F_ALL_XFERRED))
4495 if (currSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
4496 FPT_phaseDataIn(port,p_card);
4499 else {
4500 FPT_phaseDataOut(port,p_card);
4503 else
4505 FPT_sxfrp(port,p_card);
4506 if (!(RDW_HARPOON((port+hp_intstat)) &
4507 (BUS_FREE | ICMD_COMP | ITAR_DISC | RESET)))
4509 WRW_HARPOON((port+hp_intstat), AUTO_INT);
4510 FPT_phaseDecode(port,p_card);
4516 else {
4517 WR_HARPOON(port+hp_portctrl_0, 0x00);
4522 /*---------------------------------------------------------------------
4524 * Function: FPT_sinits
4526 * Description: Setup SCCB manager fields in this SCCB.
4528 *---------------------------------------------------------------------*/
4530 static void FPT_sinits(PSCCB p_sccb, UCHAR p_card)
4532 PSCCBMgr_tar_info currTar_Info;
4534 if((p_sccb->TargID > MAX_SCSI_TAR) || (p_sccb->Lun > MAX_LUN))
4536 return;
4538 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
4540 p_sccb->Sccb_XferState = 0x00;
4541 p_sccb->Sccb_XferCnt = p_sccb->DataLength;
4543 if ((p_sccb->OperationCode == SCATTER_GATHER_COMMAND) ||
4544 (p_sccb->OperationCode == RESIDUAL_SG_COMMAND)) {
4546 p_sccb->Sccb_SGoffset = 0;
4547 p_sccb->Sccb_XferState = F_SG_XFER;
4548 p_sccb->Sccb_XferCnt = 0x00;
4551 if (p_sccb->DataLength == 0x00)
4553 p_sccb->Sccb_XferState |= F_ALL_XFERRED;
4555 if (p_sccb->ControlByte & F_USE_CMD_Q)
4557 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
4558 p_sccb->ControlByte &= ~F_USE_CMD_Q;
4560 else
4561 currTar_Info->TarStatus |= TAG_Q_TRYING;
4564 /* For !single SCSI device in system & device allow Disconnect
4565 or command is tag_q type then send Cmd with Disconnect Enable
4566 else send Cmd with Disconnect Disable */
4569 if (((!(FPT_BL_Card[p_card].globalFlags & F_SINGLE_DEVICE)) &&
4570 (currTar_Info->TarStatus & TAR_ALLOW_DISC)) ||
4571 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
4573 if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) ||
4574 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
4575 p_sccb->Sccb_idmsg = (UCHAR)(SMIDENT | DISC_PRIV) | p_sccb->Lun;
4578 else {
4580 p_sccb->Sccb_idmsg = (UCHAR)SMIDENT | p_sccb->Lun;
4583 p_sccb->HostStatus = 0x00;
4584 p_sccb->TargetStatus = 0x00;
4585 p_sccb->Sccb_tag = 0x00;
4586 p_sccb->Sccb_MGRFlags = 0x00;
4587 p_sccb->Sccb_sgseg = 0x00;
4588 p_sccb->Sccb_ATC = 0x00;
4589 p_sccb->Sccb_savedATC = 0x00;
4591 p_sccb->SccbVirtDataPtr = 0x00;
4592 p_sccb->Sccb_forwardlink = NULL;
4593 p_sccb->Sccb_backlink = NULL;
4595 p_sccb->Sccb_scsistat = BUS_FREE_ST;
4596 p_sccb->SccbStatus = SCCB_IN_PROCESS;
4597 p_sccb->Sccb_scsimsg = SMNO_OP;
4602 /*---------------------------------------------------------------------
4604 * Function: Phase Decode
4606 * Description: Determine the phase and call the appropriate function.
4608 *---------------------------------------------------------------------*/
4610 static void FPT_phaseDecode(ULONG p_port, UCHAR p_card)
4612 unsigned char phase_ref;
4613 void (*phase) (ULONG, UCHAR);
4616 DISABLE_AUTO(p_port);
4618 phase_ref = (UCHAR) (RD_HARPOON(p_port+hp_scsisig) & S_SCSI_PHZ);
4620 phase = FPT_s_PhaseTbl[phase_ref];
4622 (*phase)(p_port, p_card); /* Call the correct phase func */
4627 /*---------------------------------------------------------------------
4629 * Function: Data Out Phase
4631 * Description: Start up both the BusMaster and Xbow.
4633 *---------------------------------------------------------------------*/
4635 static void FPT_phaseDataOut(ULONG port, UCHAR p_card)
4638 PSCCB currSCCB;
4640 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4641 if (currSCCB == NULL)
4643 return; /* Exit if No SCCB record */
4646 currSCCB->Sccb_scsistat = DATA_OUT_ST;
4647 currSCCB->Sccb_XferState &= ~(F_HOST_XFER_DIR | F_NO_DATA_YET);
4649 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
4651 WRW_HARPOON((port+hp_intstat), XFER_CNT_0);
4653 WR_HARPOON(port+hp_autostart_0, (END_DATA+END_DATA_START));
4655 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4657 if (currSCCB->Sccb_XferCnt == 0) {
4660 if ((currSCCB->ControlByte & SCCB_DATA_XFER_OUT) &&
4661 (currSCCB->HostStatus == SCCB_COMPLETE))
4662 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4664 FPT_sxfrp(port,p_card);
4665 if (!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | RESET)))
4666 FPT_phaseDecode(port,p_card);
4671 /*---------------------------------------------------------------------
4673 * Function: Data In Phase
4675 * Description: Startup the BusMaster and the XBOW.
4677 *---------------------------------------------------------------------*/
4679 static void FPT_phaseDataIn(ULONG port, UCHAR p_card)
4682 PSCCB currSCCB;
4684 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4686 if (currSCCB == NULL)
4688 return; /* Exit if No SCCB record */
4692 currSCCB->Sccb_scsistat = DATA_IN_ST;
4693 currSCCB->Sccb_XferState |= F_HOST_XFER_DIR;
4694 currSCCB->Sccb_XferState &= ~F_NO_DATA_YET;
4696 WR_HARPOON(port+hp_portctrl_0, SCSI_PORT);
4698 WRW_HARPOON((port+hp_intstat), XFER_CNT_0);
4700 WR_HARPOON(port+hp_autostart_0, (END_DATA+END_DATA_START));
4702 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4704 if (currSCCB->Sccb_XferCnt == 0) {
4707 if ((currSCCB->ControlByte & SCCB_DATA_XFER_IN) &&
4708 (currSCCB->HostStatus == SCCB_COMPLETE))
4709 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4711 FPT_sxfrp(port,p_card);
4712 if (!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | RESET)))
4713 FPT_phaseDecode(port,p_card);
4718 /*---------------------------------------------------------------------
4720 * Function: Command Phase
4722 * Description: Load the CDB into the automation and start it up.
4724 *---------------------------------------------------------------------*/
4726 static void FPT_phaseCommand(ULONG p_port, UCHAR p_card)
4728 PSCCB currSCCB;
4729 ULONG cdb_reg;
4730 UCHAR i;
4732 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4734 if (currSCCB->OperationCode == RESET_COMMAND) {
4736 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4737 currSCCB->CdbLength = SIX_BYTE_CMD;
4740 WR_HARPOON(p_port+hp_scsisig, 0x00);
4742 ARAM_ACCESS(p_port);
4745 cdb_reg = p_port + CMD_STRT;
4747 for (i=0; i < currSCCB->CdbLength; i++) {
4749 if (currSCCB->OperationCode == RESET_COMMAND)
4751 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + 0x00));
4753 else
4754 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + currSCCB->Cdb[i]));
4755 cdb_reg +=2;
4758 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
4759 WRW_HARPOON(cdb_reg, (BRH_OP+ALWAYS+ NP));
4761 WR_HARPOON(p_port+hp_portctrl_0,(SCSI_PORT));
4763 currSCCB->Sccb_scsistat = COMMAND_ST;
4765 WR_HARPOON(p_port+hp_autostart_3, (AUTO_IMMED | CMD_ONLY_STRT));
4766 SGRAM_ACCESS(p_port);
4770 /*---------------------------------------------------------------------
4772 * Function: Status phase
4774 * Description: Bring in the status and command complete message bytes
4776 *---------------------------------------------------------------------*/
4778 static void FPT_phaseStatus(ULONG port, UCHAR p_card)
4780 /* Start-up the automation to finish off this command and let the
4781 isr handle the interrupt for command complete when it comes in.
4782 We could wait here for the interrupt to be generated?
4785 WR_HARPOON(port+hp_scsisig, 0x00);
4787 WR_HARPOON(port+hp_autostart_0, (AUTO_IMMED+END_DATA_START));
4791 /*---------------------------------------------------------------------
4793 * Function: Phase Message Out
4795 * Description: Send out our message (if we have one) and handle whatever
4796 * else is involed.
4798 *---------------------------------------------------------------------*/
4800 static void FPT_phaseMsgOut(ULONG port, UCHAR p_card)
4802 UCHAR message,scsiID;
4803 PSCCB currSCCB;
4804 PSCCBMgr_tar_info currTar_Info;
4806 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4808 if (currSCCB != NULL) {
4810 message = currSCCB->Sccb_scsimsg;
4811 scsiID = currSCCB->TargID;
4813 if (message == SMDEV_RESET)
4817 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
4818 currTar_Info->TarSyncCtrl = 0;
4819 FPT_sssyncv(port, scsiID, NARROW_SCSI,currTar_Info);
4821 if (FPT_sccbMgrTbl[p_card][scsiID].TarEEValue & EE_SYNC_MASK)
4824 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &= ~TAR_SYNC_MASK;
4828 if (FPT_sccbMgrTbl[p_card][scsiID].TarEEValue & EE_WIDE_SCSI)
4831 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &= ~TAR_WIDE_MASK;
4835 FPT_queueFlushSccb(p_card,SCCB_COMPLETE);
4836 FPT_SccbMgrTableInitTarget(p_card,scsiID);
4838 else if (currSCCB->Sccb_scsistat == ABORT_ST)
4840 currSCCB->HostStatus = SCCB_COMPLETE;
4841 if(FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] != NULL)
4843 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
4844 FPT_sccbMgrTbl[p_card][scsiID].TarTagQ_Cnt--;
4849 else if (currSCCB->Sccb_scsistat < COMMAND_ST)
4853 if(message == SMNO_OP)
4855 currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED;
4857 FPT_ssel(port,p_card);
4858 return;
4861 else
4865 if (message == SMABORT)
4867 FPT_queueFlushSccb(p_card,SCCB_COMPLETE);
4871 else
4873 message = SMABORT;
4876 WRW_HARPOON((port+hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0));
4879 WR_HARPOON(port+hp_portctrl_0, SCSI_BUS_EN);
4881 WR_HARPOON(port+hp_scsidata_0,message);
4883 WR_HARPOON(port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
4885 ACCEPT_MSG(port);
4887 WR_HARPOON(port+hp_portctrl_0, 0x00);
4889 if ((message == SMABORT) || (message == SMDEV_RESET) ||
4890 (message == SMABORT_TAG) )
4893 while(!(RDW_HARPOON((port+hp_intstat)) & (BUS_FREE | PHASE))) {}
4895 if (RDW_HARPOON((port+hp_intstat)) & BUS_FREE)
4897 WRW_HARPOON((port+hp_intstat), BUS_FREE);
4899 if (currSCCB != NULL)
4902 if((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4903 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4904 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 0;
4905 else
4906 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
4908 FPT_queueCmdComplete(&FPT_BL_Card[p_card],currSCCB, p_card);
4911 else
4913 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4917 else
4920 FPT_sxfrp(port,p_card);
4924 else
4927 if(message == SMPARITY)
4929 currSCCB->Sccb_scsimsg = SMNO_OP;
4930 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
4932 else
4934 FPT_sxfrp(port,p_card);
4940 /*---------------------------------------------------------------------
4942 * Function: Message In phase
4944 * Description: Bring in the message and determine what to do with it.
4946 *---------------------------------------------------------------------*/
4948 static void FPT_phaseMsgIn(ULONG port, UCHAR p_card)
4950 UCHAR message;
4951 PSCCB currSCCB;
4953 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4955 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT)
4958 FPT_phaseChkFifo(port, p_card);
4961 message = RD_HARPOON(port+hp_scsidata_0);
4962 if ((message == SMDISC) || (message == SMSAVE_DATA_PTR))
4965 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+END_DATA_START));
4969 else
4972 message = FPT_sfm(port,currSCCB);
4973 if (message)
4977 FPT_sdecm(message,port,p_card);
4980 else
4982 if(currSCCB->Sccb_scsimsg != SMPARITY)
4983 ACCEPT_MSG(port);
4984 WR_HARPOON(port+hp_autostart_1, (AUTO_IMMED+DISCONNECT_START));
4991 /*---------------------------------------------------------------------
4993 * Function: Illegal phase
4995 * Description: Target switched to some illegal phase, so all we can do
4996 * is report an error back to the host (if that is possible)
4997 * and send an ABORT message to the misbehaving target.
4999 *---------------------------------------------------------------------*/
5001 static void FPT_phaseIllegal(ULONG port, UCHAR p_card)
5003 PSCCB currSCCB;
5005 currSCCB = FPT_BL_Card[p_card].currentSCCB;
5007 WR_HARPOON(port+hp_scsisig, RD_HARPOON(port+hp_scsisig));
5008 if (currSCCB != NULL) {
5010 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
5011 currSCCB->Sccb_scsistat = ABORT_ST;
5012 currSCCB->Sccb_scsimsg = SMABORT;
5015 ACCEPT_MSG_ATN(port);
5020 /*---------------------------------------------------------------------
5022 * Function: Phase Check FIFO
5024 * Description: Make sure data has been flushed from both FIFOs and abort
5025 * the operations if necessary.
5027 *---------------------------------------------------------------------*/
5029 static void FPT_phaseChkFifo(ULONG port, UCHAR p_card)
5031 ULONG xfercnt;
5032 PSCCB currSCCB;
5034 currSCCB = FPT_BL_Card[p_card].currentSCCB;
5036 if (currSCCB->Sccb_scsistat == DATA_IN_ST)
5039 while((!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY)) &&
5040 (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY)) {}
5043 if (!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY))
5045 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
5047 currSCCB->Sccb_XferCnt = 0;
5049 if ((RDW_HARPOON((port+hp_intstat)) & PARITY) &&
5050 (currSCCB->HostStatus == SCCB_COMPLETE))
5052 currSCCB->HostStatus = SCCB_PARITY_ERR;
5053 WRW_HARPOON((port+hp_intstat), PARITY);
5056 FPT_hostDataXferAbort(port,p_card,currSCCB);
5058 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
5060 while((!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY)) &&
5061 (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY)) {}
5064 } /*End Data In specific code. */
5068 GET_XFER_CNT(port,xfercnt);
5071 WR_HARPOON(port+hp_xfercnt_0, 0x00);
5074 WR_HARPOON(port+hp_portctrl_0, 0x00);
5076 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - xfercnt);
5078 currSCCB->Sccb_XferCnt = xfercnt;
5080 if ((RDW_HARPOON((port+hp_intstat)) & PARITY) &&
5081 (currSCCB->HostStatus == SCCB_COMPLETE)) {
5083 currSCCB->HostStatus = SCCB_PARITY_ERR;
5084 WRW_HARPOON((port+hp_intstat), PARITY);
5088 FPT_hostDataXferAbort(port,p_card,currSCCB);
5091 WR_HARPOON(port+hp_fifowrite, 0x00);
5092 WR_HARPOON(port+hp_fiforead, 0x00);
5093 WR_HARPOON(port+hp_xferstat, 0x00);
5095 WRW_HARPOON((port+hp_intstat), XFER_CNT_0);
5099 /*---------------------------------------------------------------------
5101 * Function: Phase Bus Free
5103 * Description: We just went bus free so figure out if it was
5104 * because of command complete or from a disconnect.
5106 *---------------------------------------------------------------------*/
5107 static void FPT_phaseBusFree(ULONG port, UCHAR p_card)
5109 PSCCB currSCCB;
5111 currSCCB = FPT_BL_Card[p_card].currentSCCB;
5113 if (currSCCB != NULL)
5116 DISABLE_AUTO(port);
5119 if (currSCCB->OperationCode == RESET_COMMAND)
5122 if((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5123 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
5124 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 0;
5125 else
5126 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
5128 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
5130 FPT_queueSearchSelect(&FPT_BL_Card[p_card],p_card);
5134 else if(currSCCB->Sccb_scsistat == SELECT_SN_ST)
5136 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
5137 (UCHAR)SYNC_SUPPORTED;
5138 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_SYNC_MASK;
5141 else if(currSCCB->Sccb_scsistat == SELECT_WN_ST)
5143 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
5144 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
5145 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
5147 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_WIDE_SCSI;
5150 else if(currSCCB->Sccb_scsistat == SELECT_Q_ST)
5152 /* Make sure this is not a phony BUS_FREE. If we were
5153 reselected or if BUSY is NOT on then this is a
5154 valid BUS FREE. SRR Wednesday, 5/10/1995. */
5156 if ((!(RD_HARPOON(port+hp_scsisig) & SCSI_BSY)) ||
5157 (RDW_HARPOON((port+hp_intstat)) & RSEL))
5159 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_TAG_Q_MASK;
5160 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |= TAG_Q_REJECT;
5163 else
5165 return;
5169 else
5172 currSCCB->Sccb_scsistat = BUS_FREE_ST;
5174 if (!currSCCB->HostStatus)
5176 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
5179 if((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5180 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
5181 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 0;
5182 else
5183 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
5185 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
5186 return;
5190 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
5192 } /*end if !=null */
5198 /*---------------------------------------------------------------------
5200 * Function: Auto Load Default Map
5202 * Description: Load the Automation RAM with the defualt map values.
5204 *---------------------------------------------------------------------*/
5205 static void FPT_autoLoadDefaultMap(ULONG p_port)
5207 ULONG map_addr;
5209 ARAM_ACCESS(p_port);
5210 map_addr = p_port + hp_aramBase;
5212 WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0xC0)); /*ID MESSAGE */
5213 map_addr +=2;
5214 WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0x20)); /*SIMPLE TAG QUEUEING MSG */
5215 map_addr +=2;
5216 WRW_HARPOON(map_addr, RAT_OP); /*RESET ATTENTION */
5217 map_addr +=2;
5218 WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0x00)); /*TAG ID MSG */
5219 map_addr +=2;
5220 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 0 */
5221 map_addr +=2;
5222 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 1 */
5223 map_addr +=2;
5224 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 2 */
5225 map_addr +=2;
5226 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 3 */
5227 map_addr +=2;
5228 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 4 */
5229 map_addr +=2;
5230 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 5 */
5231 map_addr +=2;
5232 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 6 */
5233 map_addr +=2;
5234 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 7 */
5235 map_addr +=2;
5236 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 8 */
5237 map_addr +=2;
5238 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 9 */
5239 map_addr +=2;
5240 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 10 */
5241 map_addr +=2;
5242 WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 11 */
5243 map_addr +=2;
5244 WRW_HARPOON(map_addr, (CPE_OP+ADATA_OUT+ DINT)); /*JUMP IF DATA OUT */
5245 map_addr +=2;
5246 WRW_HARPOON(map_addr, (TCB_OP+FIFO_0+ DI)); /*JUMP IF NO DATA IN FIFO */
5247 map_addr +=2; /*This means AYNC DATA IN */
5248 WRW_HARPOON(map_addr, (SSI_OP+ SSI_IDO_STRT)); /*STOP AND INTERRUPT */
5249 map_addr +=2;
5250 WRW_HARPOON(map_addr, (CPE_OP+ADATA_IN+DINT)); /*JUMP IF NOT DATA IN PHZ */
5251 map_addr +=2;
5252 WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ ST)); /*IF NOT MSG IN CHECK 4 DATA IN */
5253 map_addr +=2;
5254 WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x02)); /*SAVE DATA PTR MSG? */
5255 map_addr +=2;
5256 WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ DC)); /*GO CHECK FOR DISCONNECT MSG */
5257 map_addr +=2;
5258 WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_AR1)); /*SAVE DATA PTRS MSG */
5259 map_addr +=2;
5260 WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ ST)); /*IF NOT MSG IN CHECK DATA IN */
5261 map_addr +=2;
5262 WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x04)); /*DISCONNECT MSG? */
5263 map_addr +=2;
5264 WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ UNKNWN));/*UKNKNOWN MSG */
5265 map_addr +=2;
5266 WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_BUCKET));/*XFER DISCONNECT MSG */
5267 map_addr +=2;
5268 WRW_HARPOON(map_addr, (SSI_OP+ SSI_ITAR_DISC));/*STOP AND INTERRUPT */
5269 map_addr +=2;
5270 WRW_HARPOON(map_addr, (CPN_OP+ASTATUS+ UNKNWN));/*JUMP IF NOT STATUS PHZ. */
5271 map_addr +=2;
5272 WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_AR0)); /*GET STATUS BYTE */
5273 map_addr +=2;
5274 WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ CC)); /*ERROR IF NOT MSG IN PHZ */
5275 map_addr +=2;
5276 WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x00)); /*CHECK FOR CMD COMPLETE MSG. */
5277 map_addr +=2;
5278 WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ CC)); /*ERROR IF NOT CMD COMPLETE MSG. */
5279 map_addr +=2;
5280 WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_BUCKET));/*GET CMD COMPLETE MSG */
5281 map_addr +=2;
5282 WRW_HARPOON(map_addr, (SSI_OP+ SSI_ICMD_COMP));/*END OF COMMAND */
5283 map_addr +=2;
5285 WRW_HARPOON(map_addr, (SSI_OP+ SSI_IUNKWN)); /*RECEIVED UNKNOWN MSG BYTE */
5286 map_addr +=2;
5287 WRW_HARPOON(map_addr, (SSI_OP+ SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
5288 map_addr +=2;
5289 WRW_HARPOON(map_addr, (SSI_OP+ SSI_ITICKLE)); /*BIOS Tickled the Mgr */
5290 map_addr +=2;
5291 WRW_HARPOON(map_addr, (SSI_OP+ SSI_IRFAIL)); /*EXPECTED ID/TAG MESSAGES AND */
5292 map_addr +=2; /* DIDN'T GET ONE */
5293 WRW_HARPOON(map_addr, (CRR_OP+AR3+ S_IDREG)); /* comp SCSI SEL ID & AR3*/
5294 map_addr +=2;
5295 WRW_HARPOON(map_addr, (BRH_OP+EQUAL+ 0x00)); /*SEL ID OK then Conti. */
5296 map_addr +=2;
5297 WRW_HARPOON(map_addr, (SSI_OP+ SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
5301 SGRAM_ACCESS(p_port);
5304 /*---------------------------------------------------------------------
5306 * Function: Auto Command Complete
5308 * Description: Post command back to host and find another command
5309 * to execute.
5311 *---------------------------------------------------------------------*/
5313 static void FPT_autoCmdCmplt(ULONG p_port, UCHAR p_card)
5315 PSCCB currSCCB;
5316 UCHAR status_byte;
5318 currSCCB = FPT_BL_Card[p_card].currentSCCB;
5320 status_byte = RD_HARPOON(p_port+hp_gp_reg_0);
5322 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0;
5324 if (status_byte != SSGOOD) {
5326 if (status_byte == SSQ_FULL) {
5329 if(((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5330 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
5332 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 1;
5333 if(FPT_BL_Card[p_card].discQCount != 0)
5334 FPT_BL_Card[p_card].discQCount--;
5335 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
5337 else
5339 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 1;
5340 if(currSCCB->Sccb_tag)
5342 if(FPT_BL_Card[p_card].discQCount != 0)
5343 FPT_BL_Card[p_card].discQCount--;
5344 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
5345 }else
5347 if(FPT_BL_Card[p_card].discQCount != 0)
5348 FPT_BL_Card[p_card].discQCount--;
5349 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
5353 currSCCB->Sccb_MGRFlags |= F_STATUSLOADED;
5355 FPT_queueSelectFail(&FPT_BL_Card[p_card],p_card);
5357 return;
5360 if(currSCCB->Sccb_scsistat == SELECT_SN_ST)
5362 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
5363 (UCHAR)SYNC_SUPPORTED;
5365 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_SYNC_MASK;
5366 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
5368 if(((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5369 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
5371 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 1;
5372 if(FPT_BL_Card[p_card].discQCount != 0)
5373 FPT_BL_Card[p_card].discQCount--;
5374 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
5376 else
5378 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 1;
5379 if(currSCCB->Sccb_tag)
5381 if(FPT_BL_Card[p_card].discQCount != 0)
5382 FPT_BL_Card[p_card].discQCount--;
5383 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
5384 }else
5386 if(FPT_BL_Card[p_card].discQCount != 0)
5387 FPT_BL_Card[p_card].discQCount--;
5388 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
5391 return;
5395 if(currSCCB->Sccb_scsistat == SELECT_WN_ST)
5398 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
5399 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
5400 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
5402 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_WIDE_SCSI;
5403 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
5405 if(((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5406 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
5408 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 1;
5409 if(FPT_BL_Card[p_card].discQCount != 0)
5410 FPT_BL_Card[p_card].discQCount--;
5411 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
5413 else
5415 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 1;
5416 if(currSCCB->Sccb_tag)
5418 if(FPT_BL_Card[p_card].discQCount != 0)
5419 FPT_BL_Card[p_card].discQCount--;
5420 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
5421 }else
5423 if(FPT_BL_Card[p_card].discQCount != 0)
5424 FPT_BL_Card[p_card].discQCount--;
5425 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
5428 return;
5432 if (status_byte == SSCHECK)
5434 if(FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO)
5436 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue & EE_SYNC_MASK)
5438 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_SYNC_MASK;
5440 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue & EE_WIDE_SCSI)
5442 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_WIDE_MASK;
5447 if (!(currSCCB->Sccb_XferState & F_AUTO_SENSE)) {
5449 currSCCB->SccbStatus = SCCB_ERROR;
5450 currSCCB->TargetStatus = status_byte;
5452 if (status_byte == SSCHECK) {
5454 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA
5455 = 1;
5458 if (currSCCB->RequestSenseLength != NO_AUTO_REQUEST_SENSE) {
5460 if (currSCCB->RequestSenseLength == 0)
5461 currSCCB->RequestSenseLength = 14;
5463 FPT_ssenss(&FPT_BL_Card[p_card]);
5464 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
5466 if(((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5467 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
5469 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 1;
5470 if(FPT_BL_Card[p_card].discQCount != 0)
5471 FPT_BL_Card[p_card].discQCount--;
5472 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
5474 else
5476 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 1;
5477 if(currSCCB->Sccb_tag)
5479 if(FPT_BL_Card[p_card].discQCount != 0)
5480 FPT_BL_Card[p_card].discQCount--;
5481 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
5482 }else
5484 if(FPT_BL_Card[p_card].discQCount != 0)
5485 FPT_BL_Card[p_card].discQCount--;
5486 FPT_BL_Card[p_card].discQ_Tbl[FPT_sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
5489 return;
5496 if((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
5497 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
5498 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = 0;
5499 else
5500 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
5503 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
5506 #define SHORT_WAIT 0x0000000F
5507 #define LONG_WAIT 0x0000FFFFL
5510 /*---------------------------------------------------------------------
5512 * Function: Data Transfer Processor
5514 * Description: This routine performs two tasks.
5515 * (1) Start data transfer by calling HOST_DATA_XFER_START
5516 * function. Once data transfer is started, (2) Depends
5517 * on the type of data transfer mode Scatter/Gather mode
5518 * or NON Scatter/Gather mode. In NON Scatter/Gather mode,
5519 * this routine checks Sccb_MGRFlag (F_HOST_XFER_ACT bit) for
5520 * data transfer done. In Scatter/Gather mode, this routine
5521 * checks bus master command complete and dual rank busy
5522 * bit to keep chaining SC transfer command. Similarly,
5523 * in Scatter/Gather mode, it checks Sccb_MGRFlag
5524 * (F_HOST_XFER_ACT bit) for data transfer done.
5526 *---------------------------------------------------------------------*/
5528 static void FPT_dataXferProcessor(ULONG port, PSCCBcard pCurrCard)
5530 PSCCB currSCCB;
5532 currSCCB = pCurrCard->currentSCCB;
5534 if (currSCCB->Sccb_XferState & F_SG_XFER)
5536 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
5539 currSCCB->Sccb_sgseg += (UCHAR)SG_BUF_CNT;
5540 currSCCB->Sccb_SGoffset = 0x00;
5542 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
5544 FPT_busMstrSGDataXferStart(port, currSCCB);
5547 else
5549 if (!(pCurrCard->globalFlags & F_HOST_XFER_ACT))
5551 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
5553 FPT_busMstrDataXferStart(port, currSCCB);
5559 /*---------------------------------------------------------------------
5561 * Function: BusMaster Scatter Gather Data Transfer Start
5563 * Description:
5565 *---------------------------------------------------------------------*/
5566 static void FPT_busMstrSGDataXferStart(ULONG p_port, PSCCB pcurrSCCB)
5568 ULONG count,addr,tmpSGCnt;
5569 UINT sg_index;
5570 UCHAR sg_count, i;
5571 ULONG reg_offset;
5574 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5576 count = ((ULONG) HOST_RD_CMD)<<24;
5579 else {
5580 count = ((ULONG) HOST_WRT_CMD)<<24;
5583 sg_count = 0;
5584 tmpSGCnt = 0;
5585 sg_index = pcurrSCCB->Sccb_sgseg;
5586 reg_offset = hp_aramBase;
5589 i = (UCHAR) (RD_HARPOON(p_port+hp_page_ctrl) & ~(SGRAM_ARAM|SCATTER_EN));
5592 WR_HARPOON(p_port+hp_page_ctrl, i);
5594 while ((sg_count < (UCHAR)SG_BUF_CNT) &&
5595 ((ULONG)(sg_index * (UINT)SG_ELEMENT_SIZE) < pcurrSCCB->DataLength) ) {
5597 tmpSGCnt += *(((ULONG *)pcurrSCCB->DataPointer)+
5598 (sg_index * 2));
5600 count |= *(((ULONG *)pcurrSCCB->DataPointer)+
5601 (sg_index * 2));
5603 addr = *(((ULONG *)pcurrSCCB->DataPointer)+
5604 ((sg_index * 2) + 1));
5607 if ((!sg_count) && (pcurrSCCB->Sccb_SGoffset)) {
5609 addr += ((count & 0x00FFFFFFL) - pcurrSCCB->Sccb_SGoffset);
5610 count = (count & 0xFF000000L) | pcurrSCCB->Sccb_SGoffset;
5612 tmpSGCnt = count & 0x00FFFFFFL;
5615 WR_HARP32(p_port,reg_offset,addr);
5616 reg_offset +=4;
5618 WR_HARP32(p_port,reg_offset,count);
5619 reg_offset +=4;
5621 count &= 0xFF000000L;
5622 sg_index++;
5623 sg_count++;
5625 } /*End While */
5627 pcurrSCCB->Sccb_XferCnt = tmpSGCnt;
5629 WR_HARPOON(p_port+hp_sg_addr,(sg_count<<4));
5631 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5633 WR_HARP32(p_port,hp_xfercnt_0,tmpSGCnt);
5636 WR_HARPOON(p_port+hp_portctrl_0,(DMA_PORT | SCSI_PORT | SCSI_INBIT));
5637 WR_HARPOON(p_port+hp_scsisig, S_DATAI_PH);
5640 else {
5643 if ((!(RD_HARPOON(p_port+hp_synctarg_0) & NARROW_SCSI)) &&
5644 (tmpSGCnt & 0x000000001))
5647 pcurrSCCB->Sccb_XferState |= F_ODD_BALL_CNT;
5648 tmpSGCnt--;
5652 WR_HARP32(p_port,hp_xfercnt_0,tmpSGCnt);
5654 WR_HARPOON(p_port+hp_portctrl_0,(SCSI_PORT | DMA_PORT | DMA_RD));
5655 WR_HARPOON(p_port+hp_scsisig, S_DATAO_PH);
5659 WR_HARPOON(p_port+hp_page_ctrl, (UCHAR) (i | SCATTER_EN));
5664 /*---------------------------------------------------------------------
5666 * Function: BusMaster Data Transfer Start
5668 * Description:
5670 *---------------------------------------------------------------------*/
5671 static void FPT_busMstrDataXferStart(ULONG p_port, PSCCB pcurrSCCB)
5673 ULONG addr,count;
5675 if (!(pcurrSCCB->Sccb_XferState & F_AUTO_SENSE)) {
5677 count = pcurrSCCB->Sccb_XferCnt;
5679 addr = (ULONG) pcurrSCCB->DataPointer + pcurrSCCB->Sccb_ATC;
5682 else {
5683 addr = pcurrSCCB->SensePointer;
5684 count = pcurrSCCB->RequestSenseLength;
5688 HP_SETUP_ADDR_CNT(p_port,addr,count);
5691 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5693 WR_HARPOON(p_port+hp_portctrl_0,(DMA_PORT | SCSI_PORT | SCSI_INBIT));
5694 WR_HARPOON(p_port+hp_scsisig, S_DATAI_PH);
5696 WR_HARPOON(p_port+hp_xfer_cmd,
5697 (XFER_DMA_HOST | XFER_HOST_AUTO | XFER_DMA_8BIT));
5700 else {
5702 WR_HARPOON(p_port+hp_portctrl_0,(SCSI_PORT | DMA_PORT | DMA_RD));
5703 WR_HARPOON(p_port+hp_scsisig, S_DATAO_PH);
5705 WR_HARPOON(p_port+hp_xfer_cmd,
5706 (XFER_HOST_DMA | XFER_HOST_AUTO | XFER_DMA_8BIT));
5712 /*---------------------------------------------------------------------
5714 * Function: BusMaster Timeout Handler
5716 * Description: This function is called after a bus master command busy time
5717 * out is detected. This routines issue halt state machine
5718 * with a software time out for command busy. If command busy
5719 * is still asserted at the end of the time out, it issues
5720 * hard abort with another software time out. It hard abort
5721 * command busy is also time out, it'll just give up.
5723 *---------------------------------------------------------------------*/
5724 static UCHAR FPT_busMstrTimeOut(ULONG p_port)
5726 ULONG timeout;
5728 timeout = LONG_WAIT;
5730 WR_HARPOON(p_port+hp_sys_ctrl, HALT_MACH);
5732 while ((!(RD_HARPOON(p_port+hp_ext_status) & CMD_ABORTED)) && timeout--) {}
5736 if (RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) {
5737 WR_HARPOON(p_port+hp_sys_ctrl, HARD_ABORT);
5739 timeout = LONG_WAIT;
5740 while ((RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
5743 RD_HARPOON(p_port+hp_int_status); /*Clear command complete */
5745 if (RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) {
5746 return(1);
5749 else {
5750 return(0);
5755 /*---------------------------------------------------------------------
5757 * Function: Host Data Transfer Abort
5759 * Description: Abort any in progress transfer.
5761 *---------------------------------------------------------------------*/
5762 static void FPT_hostDataXferAbort(ULONG port, UCHAR p_card, PSCCB pCurrSCCB)
5765 ULONG timeout;
5766 ULONG remain_cnt;
5767 UINT sg_ptr;
5769 FPT_BL_Card[p_card].globalFlags &= ~F_HOST_XFER_ACT;
5771 if (pCurrSCCB->Sccb_XferState & F_AUTO_SENSE) {
5774 if (!(RD_HARPOON(port+hp_int_status) & INT_CMD_COMPL)) {
5776 WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) | FLUSH_XFER_CNTR));
5777 timeout = LONG_WAIT;
5779 while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
5781 WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) & ~FLUSH_XFER_CNTR));
5783 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5785 if (FPT_busMstrTimeOut(port)) {
5787 if (pCurrSCCB->HostStatus == 0x00)
5789 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5793 if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS)
5795 if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS)
5797 if (pCurrSCCB->HostStatus == 0x00)
5800 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5806 else if (pCurrSCCB->Sccb_XferCnt) {
5808 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5811 WR_HARPOON(port+hp_page_ctrl, (RD_HARPOON(port+hp_page_ctrl) &
5812 ~SCATTER_EN));
5814 WR_HARPOON(port+hp_sg_addr,0x00);
5816 sg_ptr = pCurrSCCB->Sccb_sgseg + SG_BUF_CNT;
5818 if (sg_ptr > (UINT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE)) {
5820 sg_ptr = (UINT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE);
5823 remain_cnt = pCurrSCCB->Sccb_XferCnt;
5825 while (remain_cnt < 0x01000000L) {
5827 sg_ptr--;
5829 if (remain_cnt > (ULONG)(*(((ULONG *)pCurrSCCB->
5830 DataPointer) + (sg_ptr * 2)))) {
5832 remain_cnt -= (ULONG)(*(((ULONG *)pCurrSCCB->
5833 DataPointer) + (sg_ptr * 2)));
5836 else {
5838 break;
5844 if (remain_cnt < 0x01000000L) {
5847 pCurrSCCB->Sccb_SGoffset = remain_cnt;
5849 pCurrSCCB->Sccb_sgseg = (USHORT)sg_ptr;
5852 if ((ULONG)(sg_ptr * SG_ELEMENT_SIZE) == pCurrSCCB->DataLength
5853 && (remain_cnt == 0))
5855 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5858 else {
5861 if (pCurrSCCB->HostStatus == 0x00) {
5863 pCurrSCCB->HostStatus = SCCB_GROSS_FW_ERR;
5869 if (!(pCurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)) {
5872 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5874 FPT_busMstrTimeOut(port);
5877 else {
5879 if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
5881 if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
5883 if (pCurrSCCB->HostStatus == 0x00) {
5885 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5893 else {
5896 if ((RD_HARPOON(port+hp_fifo_cnt)) >= BM_THRESHOLD) {
5898 timeout = SHORT_WAIT;
5900 while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) &&
5901 ((RD_HARPOON(port+hp_fifo_cnt)) >= BM_THRESHOLD) &&
5902 timeout--) {}
5905 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5907 WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) |
5908 FLUSH_XFER_CNTR));
5910 timeout = LONG_WAIT;
5912 while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) &&
5913 timeout--) {}
5915 WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) &
5916 ~FLUSH_XFER_CNTR));
5919 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5921 if (pCurrSCCB->HostStatus == 0x00) {
5923 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5926 FPT_busMstrTimeOut(port);
5930 if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
5932 if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
5934 if (pCurrSCCB->HostStatus == 0x00) {
5936 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5944 else {
5947 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5949 timeout = LONG_WAIT;
5951 while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
5953 if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
5955 if (pCurrSCCB->HostStatus == 0x00) {
5957 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5960 FPT_busMstrTimeOut(port);
5965 if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
5967 if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
5969 if (pCurrSCCB->HostStatus == 0x00) {
5971 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5977 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5979 WR_HARPOON(port+hp_page_ctrl, (RD_HARPOON(port+hp_page_ctrl) &
5980 ~SCATTER_EN));
5982 WR_HARPOON(port+hp_sg_addr,0x00);
5984 pCurrSCCB->Sccb_sgseg += SG_BUF_CNT;
5986 pCurrSCCB->Sccb_SGoffset = 0x00;
5989 if ((ULONG)(pCurrSCCB->Sccb_sgseg * SG_ELEMENT_SIZE) >=
5990 pCurrSCCB->DataLength) {
5992 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5994 pCurrSCCB->Sccb_sgseg = (USHORT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE);
5999 else {
6001 if (!(pCurrSCCB->Sccb_XferState & F_AUTO_SENSE))
6003 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
6007 WR_HARPOON(port+hp_int_mask,(INT_CMD_COMPL | SCSI_INTERRUPT));
6012 /*---------------------------------------------------------------------
6014 * Function: Host Data Transfer Restart
6016 * Description: Reset the available count due to a restore data
6017 * pointers message.
6019 *---------------------------------------------------------------------*/
6020 static void FPT_hostDataXferRestart(PSCCB currSCCB)
6022 ULONG data_count;
6023 UINT sg_index;
6024 ULONG *sg_ptr;
6026 if (currSCCB->Sccb_XferState & F_SG_XFER) {
6028 currSCCB->Sccb_XferCnt = 0;
6030 sg_index = 0xffff; /*Index by long words into sg list. */
6031 data_count = 0; /*Running count of SG xfer counts. */
6033 sg_ptr = (ULONG *)currSCCB->DataPointer;
6035 while (data_count < currSCCB->Sccb_ATC) {
6037 sg_index++;
6038 data_count += *(sg_ptr+(sg_index * 2));
6041 if (data_count == currSCCB->Sccb_ATC) {
6043 currSCCB->Sccb_SGoffset = 0;
6044 sg_index++;
6047 else {
6048 currSCCB->Sccb_SGoffset = data_count - currSCCB->Sccb_ATC;
6051 currSCCB->Sccb_sgseg = (USHORT)sg_index;
6054 else {
6055 currSCCB->Sccb_XferCnt = currSCCB->DataLength - currSCCB->Sccb_ATC;
6061 /*---------------------------------------------------------------------
6063 * Function: FPT_scini
6065 * Description: Setup all data structures necessary for SCAM selection.
6067 *---------------------------------------------------------------------*/
6069 static void FPT_scini(UCHAR p_card, UCHAR p_our_id, UCHAR p_power_up)
6072 UCHAR loser,assigned_id;
6073 ULONG p_port;
6075 UCHAR i,k,ScamFlg ;
6076 PSCCBcard currCard;
6077 PNVRamInfo pCurrNvRam;
6079 currCard = &FPT_BL_Card[p_card];
6080 p_port = currCard->ioPort;
6081 pCurrNvRam = currCard->pNvRamInfo;
6084 if(pCurrNvRam){
6085 ScamFlg = pCurrNvRam->niScamConf;
6086 i = pCurrNvRam->niSysConf;
6088 else{
6089 ScamFlg = (UCHAR) FPT_utilEERead(p_port, SCAM_CONFIG/2);
6090 i = (UCHAR)(FPT_utilEERead(p_port, (SYSTEM_CONFIG/2)));
6092 if(!(i & 0x02)) /* check if reset bus in AutoSCSI parameter set */
6093 return;
6095 FPT_inisci(p_card,p_port, p_our_id);
6097 /* Force to wait 1 sec after SCSI bus reset. Some SCAM device FW
6098 too slow to return to SCAM selection */
6100 /* if (p_power_up)
6101 FPT_Wait1Second(p_port);
6102 else
6103 FPT_Wait(p_port, TO_250ms); */
6105 FPT_Wait1Second(p_port);
6107 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
6109 while (!(FPT_scarb(p_port,INIT_SELTD))) {}
6111 FPT_scsel(p_port);
6113 do {
6114 FPT_scxferc(p_port,SYNC_PTRN);
6115 FPT_scxferc(p_port,DOM_MSTR);
6116 loser = FPT_scsendi(p_port,&FPT_scamInfo[p_our_id].id_string[0]);
6117 } while ( loser == 0xFF );
6119 FPT_scbusf(p_port);
6121 if ((p_power_up) && (!loser))
6123 FPT_sresb(p_port,p_card);
6124 FPT_Wait(p_port, TO_250ms);
6126 while (!(FPT_scarb(p_port,INIT_SELTD))) {}
6128 FPT_scsel(p_port);
6130 do {
6131 FPT_scxferc(p_port, SYNC_PTRN);
6132 FPT_scxferc(p_port, DOM_MSTR);
6133 loser = FPT_scsendi(p_port,&FPT_scamInfo[p_our_id].
6134 id_string[0]);
6135 } while ( loser == 0xFF );
6137 FPT_scbusf(p_port);
6141 else
6143 loser = 0;
6147 if (!loser)
6150 FPT_scamInfo[p_our_id].state = ID_ASSIGNED;
6153 if (ScamFlg & SCAM_ENABLED)
6156 for (i=0; i < MAX_SCSI_TAR; i++)
6158 if ((FPT_scamInfo[i].state == ID_UNASSIGNED) ||
6159 (FPT_scamInfo[i].state == ID_UNUSED))
6161 if (FPT_scsell(p_port,i))
6163 FPT_scamInfo[i].state = LEGACY;
6164 if ((FPT_scamInfo[i].id_string[0] != 0xFF) ||
6165 (FPT_scamInfo[i].id_string[1] != 0xFA))
6168 FPT_scamInfo[i].id_string[0] = 0xFF;
6169 FPT_scamInfo[i].id_string[1] = 0xFA;
6170 if(pCurrNvRam == NULL)
6171 currCard->globalFlags |= F_UPDATE_EEPROM;
6177 FPT_sresb(p_port,p_card);
6178 FPT_Wait1Second(p_port);
6179 while (!(FPT_scarb(p_port,INIT_SELTD))) {}
6180 FPT_scsel(p_port);
6181 FPT_scasid(p_card, p_port);
6186 else if ((loser) && (ScamFlg & SCAM_ENABLED))
6188 FPT_scamInfo[p_our_id].id_string[0] = SLV_TYPE_CODE0;
6189 assigned_id = 0;
6190 FPT_scwtsel(p_port);
6192 do {
6193 while (FPT_scxferc(p_port,0x00) != SYNC_PTRN) {}
6195 i = FPT_scxferc(p_port,0x00);
6196 if (i == ASSIGN_ID)
6198 if (!(FPT_scsendi(p_port,&FPT_scamInfo[p_our_id].id_string[0])))
6200 i = FPT_scxferc(p_port,0x00);
6201 if (FPT_scvalq(i))
6203 k = FPT_scxferc(p_port,0x00);
6205 if (FPT_scvalq(k))
6207 currCard->ourId =
6208 ((UCHAR)(i<<3)+(k & (UCHAR)7)) & (UCHAR) 0x3F;
6209 FPT_inisci(p_card, p_port, p_our_id);
6210 FPT_scamInfo[currCard->ourId].state = ID_ASSIGNED;
6211 FPT_scamInfo[currCard->ourId].id_string[0]
6212 = SLV_TYPE_CODE0;
6213 assigned_id = 1;
6219 else if (i == SET_P_FLAG)
6221 if (!(FPT_scsendi(p_port,
6222 &FPT_scamInfo[p_our_id].id_string[0])))
6223 FPT_scamInfo[p_our_id].id_string[0] |= 0x80;
6225 }while (!assigned_id);
6227 while (FPT_scxferc(p_port,0x00) != CFG_CMPLT) {}
6230 if (ScamFlg & SCAM_ENABLED)
6232 FPT_scbusf(p_port);
6233 if (currCard->globalFlags & F_UPDATE_EEPROM)
6235 FPT_scsavdi(p_card, p_port);
6236 currCard->globalFlags &= ~F_UPDATE_EEPROM;
6242 for (i=0,k=0; i < MAX_SCSI_TAR; i++)
6244 if ((FPT_scamInfo[i].state == ID_ASSIGNED) ||
6245 (FPT_scamInfo[i].state == LEGACY))
6246 k++;
6249 if (k==2)
6250 currCard->globalFlags |= F_SINGLE_DEVICE;
6251 else
6252 currCard->globalFlags &= ~F_SINGLE_DEVICE;
6257 /*---------------------------------------------------------------------
6259 * Function: FPT_scarb
6261 * Description: Gain control of the bus and wait SCAM select time (250ms)
6263 *---------------------------------------------------------------------*/
6265 static int FPT_scarb(ULONG p_port, UCHAR p_sel_type)
6267 if (p_sel_type == INIT_SELTD)
6270 while (RD_HARPOON(p_port+hp_scsisig) & (SCSI_SEL | SCSI_BSY)) {}
6273 if (RD_HARPOON(p_port+hp_scsisig) & SCSI_SEL)
6274 return(0);
6276 if (RD_HARPOON(p_port+hp_scsidata_0) != 00)
6277 return(0);
6279 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_BSY));
6281 if (RD_HARPOON(p_port+hp_scsisig) & SCSI_SEL) {
6283 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) &
6284 ~SCSI_BSY));
6285 return(0);
6289 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_SEL));
6291 if (RD_HARPOON(p_port+hp_scsidata_0) != 00) {
6293 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) &
6294 ~(SCSI_BSY | SCSI_SEL)));
6295 return(0);
6300 WR_HARPOON(p_port+hp_clkctrl_0, (RD_HARPOON(p_port+hp_clkctrl_0)
6301 & ~ACTdeassert));
6302 WR_HARPOON(p_port+hp_scsireset, SCAM_EN);
6303 WR_HARPOON(p_port+hp_scsidata_0, 0x00);
6304 WR_HARPOON(p_port+hp_scsidata_1, 0x00);
6305 WR_HARPOON(p_port+hp_portctrl_0, SCSI_BUS_EN);
6307 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_MSG));
6309 WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig)
6310 & ~SCSI_BSY));
6312 FPT_Wait(p_port,TO_250ms);
6314 return(1);
6318 /*---------------------------------------------------------------------
6320 * Function: FPT_scbusf
6322 * Description: Release the SCSI bus and disable SCAM selection.
6324 *---------------------------------------------------------------------*/
6326 static void FPT_scbusf(ULONG p_port)
6328 WR_HARPOON(p_port+hp_page_ctrl,
6329 (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE));
6332 WR_HARPOON(p_port+hp_scsidata_0, 0x00);
6334 WR_HARPOON(p_port+hp_portctrl_0, (RD_HARPOON(p_port+hp_portctrl_0)
6335 & ~SCSI_BUS_EN));
6337 WR_HARPOON(p_port+hp_scsisig, 0x00);
6340 WR_HARPOON(p_port+hp_scsireset, (RD_HARPOON(p_port+hp_scsireset)
6341 & ~SCAM_EN));
6343 WR_HARPOON(p_port+hp_clkctrl_0, (RD_HARPOON(p_port+hp_clkctrl_0)
6344 | ACTdeassert));
6346 WRW_HARPOON((p_port+hp_intstat), (BUS_FREE | AUTO_INT | SCAM_SEL));
6348 WR_HARPOON(p_port+hp_page_ctrl,
6349 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
6354 /*---------------------------------------------------------------------
6356 * Function: FPT_scasid
6358 * Description: Assign an ID to all the SCAM devices.
6360 *---------------------------------------------------------------------*/
6362 static void FPT_scasid(UCHAR p_card, ULONG p_port)
6364 UCHAR temp_id_string[ID_STRING_LENGTH];
6366 UCHAR i,k,scam_id;
6367 UCHAR crcBytes[3];
6368 PNVRamInfo pCurrNvRam;
6369 ushort_ptr pCrcBytes;
6371 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
6373 i=0;
6375 while (!i)
6378 for (k=0; k < ID_STRING_LENGTH; k++)
6380 temp_id_string[k] = (UCHAR) 0x00;
6383 FPT_scxferc(p_port,SYNC_PTRN);
6384 FPT_scxferc(p_port,ASSIGN_ID);
6386 if (!(FPT_sciso(p_port,&temp_id_string[0])))
6388 if(pCurrNvRam){
6389 pCrcBytes = (ushort_ptr)&crcBytes[0];
6390 *pCrcBytes = FPT_CalcCrc16(&temp_id_string[0]);
6391 crcBytes[2] = FPT_CalcLrc(&temp_id_string[0]);
6392 temp_id_string[1] = crcBytes[2];
6393 temp_id_string[2] = crcBytes[0];
6394 temp_id_string[3] = crcBytes[1];
6395 for(k = 4; k < ID_STRING_LENGTH; k++)
6396 temp_id_string[k] = (UCHAR) 0x00;
6398 i = FPT_scmachid(p_card,temp_id_string);
6400 if (i == CLR_PRIORITY)
6402 FPT_scxferc(p_port,MISC_CODE);
6403 FPT_scxferc(p_port,CLR_P_FLAG);
6404 i = 0; /*Not the last ID yet. */
6407 else if (i != NO_ID_AVAIL)
6409 if (i < 8 )
6410 FPT_scxferc(p_port,ID_0_7);
6411 else
6412 FPT_scxferc(p_port,ID_8_F);
6414 scam_id = (i & (UCHAR) 0x07);
6417 for (k=1; k < 0x08; k <<= 1)
6418 if (!( k & i ))
6419 scam_id += 0x08; /*Count number of zeros in DB0-3. */
6421 FPT_scxferc(p_port,scam_id);
6423 i = 0; /*Not the last ID yet. */
6427 else
6429 i = 1;
6432 } /*End while */
6434 FPT_scxferc(p_port,SYNC_PTRN);
6435 FPT_scxferc(p_port,CFG_CMPLT);
6442 /*---------------------------------------------------------------------
6444 * Function: FPT_scsel
6446 * Description: Select all the SCAM devices.
6448 *---------------------------------------------------------------------*/
6450 static void FPT_scsel(ULONG p_port)
6453 WR_HARPOON(p_port+hp_scsisig, SCSI_SEL);
6454 FPT_scwiros(p_port, SCSI_MSG);
6456 WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY));
6459 WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
6460 WR_HARPOON(p_port+hp_scsidata_0, (UCHAR)(RD_HARPOON(p_port+hp_scsidata_0) |
6461 (UCHAR)(BIT(7)+BIT(6))));
6464 WR_HARPOON(p_port+hp_scsisig, (SCSI_BSY | SCSI_IOBIT | SCSI_CD));
6465 FPT_scwiros(p_port, SCSI_SEL);
6467 WR_HARPOON(p_port+hp_scsidata_0, (UCHAR)(RD_HARPOON(p_port+hp_scsidata_0) &
6468 ~(UCHAR)BIT(6)));
6469 FPT_scwirod(p_port, BIT(6));
6471 WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
6476 /*---------------------------------------------------------------------
6478 * Function: FPT_scxferc
6480 * Description: Handshake the p_data (DB4-0) across the bus.
6482 *---------------------------------------------------------------------*/
6484 static UCHAR FPT_scxferc(ULONG p_port, UCHAR p_data)
6486 UCHAR curr_data, ret_data;
6488 curr_data = p_data | BIT(7) | BIT(5); /*Start with DB7 & DB5 asserted. */
6490 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6492 curr_data &= ~BIT(7);
6494 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6496 FPT_scwirod(p_port,BIT(7)); /*Wait for DB7 to be released. */
6497 while (!(RD_HARPOON(p_port+hp_scsidata_0) & BIT(5)));
6499 ret_data = (RD_HARPOON(p_port+hp_scsidata_0) & (UCHAR) 0x1F);
6501 curr_data |= BIT(6);
6503 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6505 curr_data &= ~BIT(5);
6507 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6509 FPT_scwirod(p_port,BIT(5)); /*Wait for DB5 to be released. */
6511 curr_data &= ~(BIT(4)|BIT(3)|BIT(2)|BIT(1)|BIT(0)); /*Release data bits */
6512 curr_data |= BIT(7);
6514 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6516 curr_data &= ~BIT(6);
6518 WR_HARPOON(p_port+hp_scsidata_0, curr_data);
6520 FPT_scwirod(p_port,BIT(6)); /*Wait for DB6 to be released. */
6522 return(ret_data);
6526 /*---------------------------------------------------------------------
6528 * Function: FPT_scsendi
6530 * Description: Transfer our Identification string to determine if we
6531 * will be the dominant master.
6533 *---------------------------------------------------------------------*/
6535 static UCHAR FPT_scsendi(ULONG p_port, UCHAR p_id_string[])
6537 UCHAR ret_data,byte_cnt,bit_cnt,defer;
6539 defer = 0;
6541 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
6543 for (bit_cnt = 0x80; bit_cnt != 0 ; bit_cnt >>= 1) {
6545 if (defer)
6546 ret_data = FPT_scxferc(p_port,00);
6548 else if (p_id_string[byte_cnt] & bit_cnt)
6550 ret_data = FPT_scxferc(p_port,02);
6552 else {
6554 ret_data = FPT_scxferc(p_port,01);
6555 if (ret_data & 02)
6556 defer = 1;
6559 if ((ret_data & 0x1C) == 0x10)
6560 return(0x00); /*End of isolation stage, we won! */
6562 if (ret_data & 0x1C)
6563 return(0xFF);
6565 if ((defer) && (!(ret_data & 0x1F)))
6566 return(0x01); /*End of isolation stage, we lost. */
6568 } /*bit loop */
6570 } /*byte loop */
6572 if (defer)
6573 return(0x01); /*We lost */
6574 else
6575 return(0); /*We WON! Yeeessss! */
6580 /*---------------------------------------------------------------------
6582 * Function: FPT_sciso
6584 * Description: Transfer the Identification string.
6586 *---------------------------------------------------------------------*/
6588 static UCHAR FPT_sciso(ULONG p_port, UCHAR p_id_string[])
6590 UCHAR ret_data,the_data,byte_cnt,bit_cnt;
6592 the_data = 0;
6594 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
6596 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
6598 ret_data = FPT_scxferc(p_port,0);
6600 if (ret_data & 0xFC)
6601 return(0xFF);
6603 else {
6605 the_data <<= 1;
6606 if (ret_data & BIT(1)) {
6607 the_data |= 1;
6611 if ((ret_data & 0x1F) == 0)
6614 if(bit_cnt != 0 || bit_cnt != 8)
6616 byte_cnt = 0;
6617 bit_cnt = 0;
6618 FPT_scxferc(p_port, SYNC_PTRN);
6619 FPT_scxferc(p_port, ASSIGN_ID);
6620 continue;
6623 if (byte_cnt)
6624 return(0x00);
6625 else
6626 return(0xFF);
6629 } /*bit loop */
6631 p_id_string[byte_cnt] = the_data;
6633 } /*byte loop */
6635 return(0);
6640 /*---------------------------------------------------------------------
6642 * Function: FPT_scwirod
6644 * Description: Sample the SCSI data bus making sure the signal has been
6645 * deasserted for the correct number of consecutive samples.
6647 *---------------------------------------------------------------------*/
6649 static void FPT_scwirod(ULONG p_port, UCHAR p_data_bit)
6651 UCHAR i;
6653 i = 0;
6654 while ( i < MAX_SCSI_TAR ) {
6656 if (RD_HARPOON(p_port+hp_scsidata_0) & p_data_bit)
6658 i = 0;
6660 else
6662 i++;
6669 /*---------------------------------------------------------------------
6671 * Function: FPT_scwiros
6673 * Description: Sample the SCSI Signal lines making sure the signal has been
6674 * deasserted for the correct number of consecutive samples.
6676 *---------------------------------------------------------------------*/
6678 static void FPT_scwiros(ULONG p_port, UCHAR p_data_bit)
6680 UCHAR i;
6682 i = 0;
6683 while ( i < MAX_SCSI_TAR ) {
6685 if (RD_HARPOON(p_port+hp_scsisig) & p_data_bit)
6687 i = 0;
6689 else
6691 i++;
6697 /*---------------------------------------------------------------------
6699 * Function: FPT_scvalq
6701 * Description: Make sure we received a valid data byte.
6703 *---------------------------------------------------------------------*/
6705 static UCHAR FPT_scvalq(UCHAR p_quintet)
6707 UCHAR count;
6709 for (count=1; count < 0x08; count<<=1) {
6710 if (!(p_quintet & count))
6711 p_quintet -= 0x80;
6714 if (p_quintet & 0x18)
6715 return(0);
6717 else
6718 return(1);
6722 /*---------------------------------------------------------------------
6724 * Function: FPT_scsell
6726 * Description: Select the specified device ID using a selection timeout
6727 * less than 4ms. If somebody responds then it is a legacy
6728 * drive and this ID must be marked as such.
6730 *---------------------------------------------------------------------*/
6732 static UCHAR FPT_scsell(ULONG p_port, UCHAR targ_id)
6734 ULONG i;
6736 WR_HARPOON(p_port+hp_page_ctrl,
6737 (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE));
6739 ARAM_ACCESS(p_port);
6741 WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) | SCAM_TIMER));
6742 WR_HARPOON(p_port+hp_seltimeout,TO_4ms);
6745 for (i = p_port+CMD_STRT; i < p_port+CMD_STRT+12; i+=2) {
6746 WRW_HARPOON(i, (MPM_OP+ACOMMAND));
6748 WRW_HARPOON(i, (BRH_OP+ALWAYS+ NP));
6750 WRW_HARPOON((p_port+hp_intstat),
6751 (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
6753 WR_HARPOON(p_port+hp_select_id, targ_id);
6755 WR_HARPOON(p_port+hp_portctrl_0, SCSI_PORT);
6756 WR_HARPOON(p_port+hp_autostart_3, (SELECT | CMD_ONLY_STRT));
6757 WR_HARPOON(p_port+hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
6760 while (!(RDW_HARPOON((p_port+hp_intstat)) &
6761 (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {}
6763 if (RDW_HARPOON((p_port+hp_intstat)) & RESET)
6764 FPT_Wait(p_port, TO_250ms);
6766 DISABLE_AUTO(p_port);
6768 WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) & ~SCAM_TIMER));
6769 WR_HARPOON(p_port+hp_seltimeout,TO_290ms);
6771 SGRAM_ACCESS(p_port);
6773 if (RDW_HARPOON((p_port+hp_intstat)) & (RESET | TIMEOUT) ) {
6775 WRW_HARPOON((p_port+hp_intstat),
6776 (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
6778 WR_HARPOON(p_port+hp_page_ctrl,
6779 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
6781 return(0); /*No legacy device */
6784 else {
6786 while(!(RDW_HARPOON((p_port+hp_intstat)) & BUS_FREE)) {
6787 if (RD_HARPOON(p_port+hp_scsisig) & SCSI_REQ)
6789 WR_HARPOON(p_port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
6790 ACCEPT_MSG(p_port);
6794 WRW_HARPOON((p_port+hp_intstat), CLR_ALL_INT_1);
6796 WR_HARPOON(p_port+hp_page_ctrl,
6797 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
6799 return(1); /*Found one of them oldies! */
6803 /*---------------------------------------------------------------------
6805 * Function: FPT_scwtsel
6807 * Description: Wait to be selected by another SCAM initiator.
6809 *---------------------------------------------------------------------*/
6811 static void FPT_scwtsel(ULONG p_port)
6813 while(!(RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL)) {}
6817 /*---------------------------------------------------------------------
6819 * Function: FPT_inisci
6821 * Description: Setup the data Structure with the info from the EEPROM.
6823 *---------------------------------------------------------------------*/
6825 static void FPT_inisci(UCHAR p_card, ULONG p_port, UCHAR p_our_id)
6827 UCHAR i,k,max_id;
6828 USHORT ee_data;
6829 PNVRamInfo pCurrNvRam;
6831 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
6833 if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
6834 max_id = 0x08;
6836 else
6837 max_id = 0x10;
6839 if(pCurrNvRam){
6840 for(i = 0; i < max_id; i++){
6842 for(k = 0; k < 4; k++)
6843 FPT_scamInfo[i].id_string[k] = pCurrNvRam->niScamTbl[i][k];
6844 for(k = 4; k < ID_STRING_LENGTH; k++)
6845 FPT_scamInfo[i].id_string[k] = (UCHAR) 0x00;
6847 if(FPT_scamInfo[i].id_string[0] == 0x00)
6848 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6849 else
6850 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6853 }else {
6854 for (i=0; i < max_id; i++)
6856 for (k=0; k < ID_STRING_LENGTH; k+=2)
6858 ee_data = FPT_utilEERead(p_port, (USHORT)((EE_SCAMBASE/2) +
6859 (USHORT) (i*((USHORT)ID_STRING_LENGTH/2)) + (USHORT)(k/2)));
6860 FPT_scamInfo[i].id_string[k] = (UCHAR) ee_data;
6861 ee_data >>= 8;
6862 FPT_scamInfo[i].id_string[k+1] = (UCHAR) ee_data;
6865 if ((FPT_scamInfo[i].id_string[0] == 0x00) ||
6866 (FPT_scamInfo[i].id_string[0] == 0xFF))
6868 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6870 else
6871 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6875 for(k = 0; k < ID_STRING_LENGTH; k++)
6876 FPT_scamInfo[p_our_id].id_string[k] = FPT_scamHAString[k];
6880 /*---------------------------------------------------------------------
6882 * Function: FPT_scmachid
6884 * Description: Match the Device ID string with our values stored in
6885 * the EEPROM.
6887 *---------------------------------------------------------------------*/
6889 static UCHAR FPT_scmachid(UCHAR p_card, UCHAR p_id_string[])
6892 UCHAR i,k,match;
6895 for (i=0; i < MAX_SCSI_TAR; i++) {
6897 match = 1;
6899 for (k=0; k < ID_STRING_LENGTH; k++)
6901 if (p_id_string[k] != FPT_scamInfo[i].id_string[k])
6902 match = 0;
6905 if (match)
6907 FPT_scamInfo[i].state = ID_ASSIGNED;
6908 return(i);
6915 if (p_id_string[0] & BIT(5))
6916 i = 8;
6917 else
6918 i = MAX_SCSI_TAR;
6920 if (((p_id_string[0] & 0x06) == 0x02) || ((p_id_string[0] & 0x06) == 0x04))
6921 match = p_id_string[1] & (UCHAR) 0x1F;
6922 else
6923 match = 7;
6925 while (i > 0)
6927 i--;
6929 if (FPT_scamInfo[match].state == ID_UNUSED)
6931 for (k=0; k < ID_STRING_LENGTH; k++)
6933 FPT_scamInfo[match].id_string[k] = p_id_string[k];
6936 FPT_scamInfo[match].state = ID_ASSIGNED;
6938 if(FPT_BL_Card[p_card].pNvRamInfo == NULL)
6939 FPT_BL_Card[p_card].globalFlags |= F_UPDATE_EEPROM;
6940 return(match);
6945 match--;
6947 if (match == 0xFF)
6949 if (p_id_string[0] & BIT(5))
6950 match = 7;
6951 else
6952 match = MAX_SCSI_TAR-1;
6958 if (p_id_string[0] & BIT(7))
6960 return(CLR_PRIORITY);
6964 if (p_id_string[0] & BIT(5))
6965 i = 8;
6966 else
6967 i = MAX_SCSI_TAR;
6969 if (((p_id_string[0] & 0x06) == 0x02) || ((p_id_string[0] & 0x06) == 0x04))
6970 match = p_id_string[1] & (UCHAR) 0x1F;
6971 else
6972 match = 7;
6974 while (i > 0)
6977 i--;
6979 if (FPT_scamInfo[match].state == ID_UNASSIGNED)
6981 for (k=0; k < ID_STRING_LENGTH; k++)
6983 FPT_scamInfo[match].id_string[k] = p_id_string[k];
6986 FPT_scamInfo[match].id_string[0] |= BIT(7);
6987 FPT_scamInfo[match].state = ID_ASSIGNED;
6988 if(FPT_BL_Card[p_card].pNvRamInfo == NULL)
6989 FPT_BL_Card[p_card].globalFlags |= F_UPDATE_EEPROM;
6990 return(match);
6995 match--;
6997 if (match == 0xFF)
6999 if (p_id_string[0] & BIT(5))
7000 match = 7;
7001 else
7002 match = MAX_SCSI_TAR-1;
7006 return(NO_ID_AVAIL);
7010 /*---------------------------------------------------------------------
7012 * Function: FPT_scsavdi
7014 * Description: Save off the device SCAM ID strings.
7016 *---------------------------------------------------------------------*/
7018 static void FPT_scsavdi(UCHAR p_card, ULONG p_port)
7020 UCHAR i,k,max_id;
7021 USHORT ee_data,sum_data;
7024 sum_data = 0x0000;
7026 for (i = 1; i < EE_SCAMBASE/2; i++)
7028 sum_data += FPT_utilEERead(p_port, i);
7032 FPT_utilEEWriteOnOff(p_port,1); /* Enable write access to the EEPROM */
7034 if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
7035 max_id = 0x08;
7037 else
7038 max_id = 0x10;
7040 for (i=0; i < max_id; i++)
7043 for (k=0; k < ID_STRING_LENGTH; k+=2)
7045 ee_data = FPT_scamInfo[i].id_string[k+1];
7046 ee_data <<= 8;
7047 ee_data |= FPT_scamInfo[i].id_string[k];
7048 sum_data += ee_data;
7049 FPT_utilEEWrite(p_port, ee_data, (USHORT)((EE_SCAMBASE/2) +
7050 (USHORT)(i*((USHORT)ID_STRING_LENGTH/2)) + (USHORT)(k/2)));
7055 FPT_utilEEWrite(p_port, sum_data, EEPROM_CHECK_SUM/2);
7056 FPT_utilEEWriteOnOff(p_port,0); /* Turn off write access */
7059 /*---------------------------------------------------------------------
7061 * Function: FPT_XbowInit
7063 * Description: Setup the Xbow for normal operation.
7065 *---------------------------------------------------------------------*/
7067 static void FPT_XbowInit(ULONG port, UCHAR ScamFlg)
7069 UCHAR i;
7071 i = RD_HARPOON(port+hp_page_ctrl);
7072 WR_HARPOON(port+hp_page_ctrl, (UCHAR) (i | G_INT_DISABLE));
7074 WR_HARPOON(port+hp_scsireset,0x00);
7075 WR_HARPOON(port+hp_portctrl_1,HOST_MODE8);
7077 WR_HARPOON(port+hp_scsireset,(DMA_RESET | HPSCSI_RESET | PROG_RESET | \
7078 FIFO_CLR));
7080 WR_HARPOON(port+hp_scsireset,SCSI_INI);
7082 WR_HARPOON(port+hp_clkctrl_0,CLKCTRL_DEFAULT);
7084 WR_HARPOON(port+hp_scsisig,0x00); /* Clear any signals we might */
7085 WR_HARPOON(port+hp_scsictrl_0,ENA_SCAM_SEL);
7087 WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
7089 FPT_default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
7090 BUS_FREE | XFER_CNT_0 | AUTO_INT;
7092 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
7093 FPT_default_intena |= SCAM_SEL;
7095 WRW_HARPOON((port+hp_intena), FPT_default_intena);
7097 WR_HARPOON(port+hp_seltimeout,TO_290ms);
7099 /* Turn on SCSI_MODE8 for narrow cards to fix the
7100 strapping issue with the DUAL CHANNEL card */
7101 if (RD_HARPOON(port+hp_page_ctrl) & NARROW_SCSI_CARD)
7102 WR_HARPOON(port+hp_addstat,SCSI_MODE8);
7104 WR_HARPOON(port+hp_page_ctrl, i);
7109 /*---------------------------------------------------------------------
7111 * Function: FPT_BusMasterInit
7113 * Description: Initialize the BusMaster for normal operations.
7115 *---------------------------------------------------------------------*/
7117 static void FPT_BusMasterInit(ULONG p_port)
7121 WR_HARPOON(p_port+hp_sys_ctrl, DRVR_RST);
7122 WR_HARPOON(p_port+hp_sys_ctrl, 0x00);
7124 WR_HARPOON(p_port+hp_host_blk_cnt, XFER_BLK64);
7127 WR_HARPOON(p_port+hp_bm_ctrl, (BMCTRL_DEFAULT));
7129 WR_HARPOON(p_port+hp_ee_ctrl, (SCSI_TERM_ENA_H));
7132 RD_HARPOON(p_port+hp_int_status); /*Clear interrupts. */
7133 WR_HARPOON(p_port+hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
7134 WR_HARPOON(p_port+hp_page_ctrl, (RD_HARPOON(p_port+hp_page_ctrl) &
7135 ~SCATTER_EN));
7139 /*---------------------------------------------------------------------
7141 * Function: FPT_DiagEEPROM
7143 * Description: Verfiy checksum and 'Key' and initialize the EEPROM if
7144 * necessary.
7146 *---------------------------------------------------------------------*/
7148 static void FPT_DiagEEPROM(ULONG p_port)
7150 USHORT index,temp,max_wd_cnt;
7152 if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
7153 max_wd_cnt = EEPROM_WD_CNT;
7154 else
7155 max_wd_cnt = EEPROM_WD_CNT * 2;
7157 temp = FPT_utilEERead(p_port, FW_SIGNATURE/2);
7159 if (temp == 0x4641) {
7161 for (index = 2; index < max_wd_cnt; index++) {
7163 temp += FPT_utilEERead(p_port, index);
7167 if (temp == FPT_utilEERead(p_port, EEPROM_CHECK_SUM/2)) {
7169 return; /*EEPROM is Okay so return now! */
7174 FPT_utilEEWriteOnOff(p_port,(UCHAR)1);
7176 for (index = 0; index < max_wd_cnt; index++) {
7178 FPT_utilEEWrite(p_port, 0x0000, index);
7181 temp = 0;
7183 FPT_utilEEWrite(p_port, 0x4641, FW_SIGNATURE/2);
7184 temp += 0x4641;
7185 FPT_utilEEWrite(p_port, 0x3920, MODEL_NUMB_0/2);
7186 temp += 0x3920;
7187 FPT_utilEEWrite(p_port, 0x3033, MODEL_NUMB_2/2);
7188 temp += 0x3033;
7189 FPT_utilEEWrite(p_port, 0x2020, MODEL_NUMB_4/2);
7190 temp += 0x2020;
7191 FPT_utilEEWrite(p_port, 0x70D3, SYSTEM_CONFIG/2);
7192 temp += 0x70D3;
7193 FPT_utilEEWrite(p_port, 0x0010, BIOS_CONFIG/2);
7194 temp += 0x0010;
7195 FPT_utilEEWrite(p_port, 0x0003, SCAM_CONFIG/2);
7196 temp += 0x0003;
7197 FPT_utilEEWrite(p_port, 0x0007, ADAPTER_SCSI_ID/2);
7198 temp += 0x0007;
7200 FPT_utilEEWrite(p_port, 0x0000, IGNORE_B_SCAN/2);
7201 temp += 0x0000;
7202 FPT_utilEEWrite(p_port, 0x0000, SEND_START_ENA/2);
7203 temp += 0x0000;
7204 FPT_utilEEWrite(p_port, 0x0000, DEVICE_ENABLE/2);
7205 temp += 0x0000;
7207 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL01/2);
7208 temp += 0x4242;
7209 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL23/2);
7210 temp += 0x4242;
7211 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL45/2);
7212 temp += 0x4242;
7213 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL67/2);
7214 temp += 0x4242;
7215 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL89/2);
7216 temp += 0x4242;
7217 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLab/2);
7218 temp += 0x4242;
7219 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLcd/2);
7220 temp += 0x4242;
7221 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLef/2);
7222 temp += 0x4242;
7225 FPT_utilEEWrite(p_port, 0x6C46, 64/2); /*PRODUCT ID */
7226 temp += 0x6C46;
7227 FPT_utilEEWrite(p_port, 0x7361, 66/2); /* FlashPoint LT */
7228 temp += 0x7361;
7229 FPT_utilEEWrite(p_port, 0x5068, 68/2);
7230 temp += 0x5068;
7231 FPT_utilEEWrite(p_port, 0x696F, 70/2);
7232 temp += 0x696F;
7233 FPT_utilEEWrite(p_port, 0x746E, 72/2);
7234 temp += 0x746E;
7235 FPT_utilEEWrite(p_port, 0x4C20, 74/2);
7236 temp += 0x4C20;
7237 FPT_utilEEWrite(p_port, 0x2054, 76/2);
7238 temp += 0x2054;
7239 FPT_utilEEWrite(p_port, 0x2020, 78/2);
7240 temp += 0x2020;
7242 index = ((EE_SCAMBASE/2)+(7*16));
7243 FPT_utilEEWrite(p_port, (0x0700+TYPE_CODE0), index);
7244 temp += (0x0700+TYPE_CODE0);
7245 index++;
7246 FPT_utilEEWrite(p_port, 0x5542, index); /*Vendor ID code */
7247 temp += 0x5542; /* BUSLOGIC */
7248 index++;
7249 FPT_utilEEWrite(p_port, 0x4C53, index);
7250 temp += 0x4C53;
7251 index++;
7252 FPT_utilEEWrite(p_port, 0x474F, index);
7253 temp += 0x474F;
7254 index++;
7255 FPT_utilEEWrite(p_port, 0x4349, index);
7256 temp += 0x4349;
7257 index++;
7258 FPT_utilEEWrite(p_port, 0x5442, index); /*Vendor unique code */
7259 temp += 0x5442; /* BT- 930 */
7260 index++;
7261 FPT_utilEEWrite(p_port, 0x202D, index);
7262 temp += 0x202D;
7263 index++;
7264 FPT_utilEEWrite(p_port, 0x3339, index);
7265 temp += 0x3339;
7266 index++; /*Serial # */
7267 FPT_utilEEWrite(p_port, 0x2030, index); /* 01234567 */
7268 temp += 0x2030;
7269 index++;
7270 FPT_utilEEWrite(p_port, 0x5453, index);
7271 temp += 0x5453;
7272 index++;
7273 FPT_utilEEWrite(p_port, 0x5645, index);
7274 temp += 0x5645;
7275 index++;
7276 FPT_utilEEWrite(p_port, 0x2045, index);
7277 temp += 0x2045;
7278 index++;
7279 FPT_utilEEWrite(p_port, 0x202F, index);
7280 temp += 0x202F;
7281 index++;
7282 FPT_utilEEWrite(p_port, 0x4F4A, index);
7283 temp += 0x4F4A;
7284 index++;
7285 FPT_utilEEWrite(p_port, 0x204E, index);
7286 temp += 0x204E;
7287 index++;
7288 FPT_utilEEWrite(p_port, 0x3539, index);
7289 temp += 0x3539;
7293 FPT_utilEEWrite(p_port, temp, EEPROM_CHECK_SUM/2);
7295 FPT_utilEEWriteOnOff(p_port,(UCHAR)0);
7300 /*---------------------------------------------------------------------
7302 * Function: Queue Search Select
7304 * Description: Try to find a new command to execute.
7306 *---------------------------------------------------------------------*/
7308 static void FPT_queueSearchSelect(PSCCBcard pCurrCard, UCHAR p_card)
7310 UCHAR scan_ptr, lun;
7311 PSCCBMgr_tar_info currTar_Info;
7312 PSCCB pOldSccb;
7314 scan_ptr = pCurrCard->scanIndex;
7317 currTar_Info = &FPT_sccbMgrTbl[p_card][scan_ptr];
7318 if((pCurrCard->globalFlags & F_CONLUN_IO) &&
7319 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
7321 if (currTar_Info->TarSelQ_Cnt != 0)
7324 scan_ptr++;
7325 if (scan_ptr == MAX_SCSI_TAR)
7326 scan_ptr = 0;
7328 for(lun=0; lun < MAX_LUN; lun++)
7330 if(currTar_Info->TarLUNBusy[lun] == 0)
7333 pCurrCard->currentSCCB = currTar_Info->TarSelQ_Head;
7334 pOldSccb = NULL;
7336 while((pCurrCard->currentSCCB != NULL) &&
7337 (lun != pCurrCard->currentSCCB->Lun))
7339 pOldSccb = pCurrCard->currentSCCB;
7340 pCurrCard->currentSCCB = (PSCCB)(pCurrCard->currentSCCB)->
7341 Sccb_forwardlink;
7343 if(pCurrCard->currentSCCB == NULL)
7344 continue;
7345 if(pOldSccb != NULL)
7347 pOldSccb->Sccb_forwardlink = (PSCCB)(pCurrCard->currentSCCB)->
7348 Sccb_forwardlink;
7349 pOldSccb->Sccb_backlink = (PSCCB)(pCurrCard->currentSCCB)->
7350 Sccb_backlink;
7351 currTar_Info->TarSelQ_Cnt--;
7353 else
7355 currTar_Info->TarSelQ_Head = (PSCCB)(pCurrCard->currentSCCB)->Sccb_forwardlink;
7357 if (currTar_Info->TarSelQ_Head == NULL)
7359 currTar_Info->TarSelQ_Tail = NULL;
7360 currTar_Info->TarSelQ_Cnt = 0;
7362 else
7364 currTar_Info->TarSelQ_Cnt--;
7365 currTar_Info->TarSelQ_Head->Sccb_backlink = (PSCCB)NULL;
7368 pCurrCard->scanIndex = scan_ptr;
7370 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
7372 break;
7377 else
7379 scan_ptr++;
7380 if (scan_ptr == MAX_SCSI_TAR) {
7381 scan_ptr = 0;
7386 else
7388 if ((currTar_Info->TarSelQ_Cnt != 0) &&
7389 (currTar_Info->TarLUNBusy[0] == 0))
7392 pCurrCard->currentSCCB = currTar_Info->TarSelQ_Head;
7394 currTar_Info->TarSelQ_Head = (PSCCB)(pCurrCard->currentSCCB)->Sccb_forwardlink;
7396 if (currTar_Info->TarSelQ_Head == NULL)
7398 currTar_Info->TarSelQ_Tail = NULL;
7399 currTar_Info->TarSelQ_Cnt = 0;
7401 else
7403 currTar_Info->TarSelQ_Cnt--;
7404 currTar_Info->TarSelQ_Head->Sccb_backlink = (PSCCB)NULL;
7407 scan_ptr++;
7408 if (scan_ptr == MAX_SCSI_TAR)
7409 scan_ptr = 0;
7411 pCurrCard->scanIndex = scan_ptr;
7413 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
7415 break;
7418 else
7420 scan_ptr++;
7421 if (scan_ptr == MAX_SCSI_TAR)
7423 scan_ptr = 0;
7427 } while (scan_ptr != pCurrCard->scanIndex);
7431 /*---------------------------------------------------------------------
7433 * Function: Queue Select Fail
7435 * Description: Add the current SCCB to the head of the Queue.
7437 *---------------------------------------------------------------------*/
7439 static void FPT_queueSelectFail(PSCCBcard pCurrCard, UCHAR p_card)
7441 UCHAR thisTarg;
7442 PSCCBMgr_tar_info currTar_Info;
7444 if (pCurrCard->currentSCCB != NULL)
7446 thisTarg = (UCHAR)(((PSCCB)(pCurrCard->currentSCCB))->TargID);
7447 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7449 pCurrCard->currentSCCB->Sccb_backlink = (PSCCB)NULL;
7451 pCurrCard->currentSCCB->Sccb_forwardlink = currTar_Info->TarSelQ_Head;
7453 if (currTar_Info->TarSelQ_Cnt == 0)
7455 currTar_Info->TarSelQ_Tail = pCurrCard->currentSCCB;
7458 else
7460 currTar_Info->TarSelQ_Head->Sccb_backlink = pCurrCard->currentSCCB;
7464 currTar_Info->TarSelQ_Head = pCurrCard->currentSCCB;
7466 pCurrCard->currentSCCB = NULL;
7467 currTar_Info->TarSelQ_Cnt++;
7470 /*---------------------------------------------------------------------
7472 * Function: Queue Command Complete
7474 * Description: Call the callback function with the current SCCB.
7476 *---------------------------------------------------------------------*/
7478 static void FPT_queueCmdComplete(PSCCBcard pCurrCard, PSCCB p_sccb,
7479 UCHAR p_card)
7482 UCHAR i, SCSIcmd;
7483 CALL_BK_FN callback;
7484 PSCCBMgr_tar_info currTar_Info;
7486 SCSIcmd = p_sccb->Cdb[0];
7489 if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED)) {
7491 if ((p_sccb->ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN)) &&
7492 (p_sccb->HostStatus == SCCB_COMPLETE) &&
7493 (p_sccb->TargetStatus != SSCHECK))
7495 if ((SCSIcmd == SCSI_READ) ||
7496 (SCSIcmd == SCSI_WRITE) ||
7497 (SCSIcmd == SCSI_READ_EXTENDED) ||
7498 (SCSIcmd == SCSI_WRITE_EXTENDED) ||
7499 (SCSIcmd == SCSI_WRITE_AND_VERIFY) ||
7500 (SCSIcmd == SCSI_START_STOP_UNIT) ||
7501 (pCurrCard->globalFlags & F_NO_FILTER)
7503 p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
7507 if(p_sccb->SccbStatus == SCCB_IN_PROCESS)
7509 if (p_sccb->HostStatus || p_sccb->TargetStatus)
7510 p_sccb->SccbStatus = SCCB_ERROR;
7511 else
7512 p_sccb->SccbStatus = SCCB_SUCCESS;
7515 if (p_sccb->Sccb_XferState & F_AUTO_SENSE) {
7517 p_sccb->CdbLength = p_sccb->Save_CdbLen;
7518 for (i=0; i < 6; i++) {
7519 p_sccb->Cdb[i] = p_sccb->Save_Cdb[i];
7523 if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
7524 (p_sccb->OperationCode == RESIDUAL_COMMAND)) {
7526 FPT_utilUpdateResidual(p_sccb);
7529 pCurrCard->cmdCounter--;
7530 if (!pCurrCard->cmdCounter) {
7532 if (pCurrCard->globalFlags & F_GREEN_PC) {
7533 WR_HARPOON(pCurrCard->ioPort+hp_clkctrl_0,(PWR_DWN | CLKCTRL_DEFAULT));
7534 WR_HARPOON(pCurrCard->ioPort+hp_sys_ctrl, STOP_CLK);
7537 WR_HARPOON(pCurrCard->ioPort+hp_semaphore,
7538 (RD_HARPOON(pCurrCard->ioPort+hp_semaphore) & ~SCCB_MGR_ACTIVE));
7542 if(pCurrCard->discQCount != 0)
7544 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
7545 if(((pCurrCard->globalFlags & F_CONLUN_IO) &&
7546 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
7548 pCurrCard->discQCount--;
7549 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_sccb->Lun]] = NULL;
7551 else
7553 if(p_sccb->Sccb_tag)
7555 pCurrCard->discQCount--;
7556 pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
7557 }else
7559 pCurrCard->discQCount--;
7560 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = NULL;
7566 callback = (CALL_BK_FN)p_sccb->SccbCallback;
7567 callback(p_sccb);
7568 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
7569 pCurrCard->currentSCCB = NULL;
7573 /*---------------------------------------------------------------------
7575 * Function: Queue Disconnect
7577 * Description: Add SCCB to our disconnect array.
7579 *---------------------------------------------------------------------*/
7580 static void FPT_queueDisconnect(PSCCB p_sccb, UCHAR p_card)
7582 PSCCBMgr_tar_info currTar_Info;
7584 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
7586 if(((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
7587 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
7589 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_sccb->Lun]] = p_sccb;
7591 else
7593 if (p_sccb->Sccb_tag)
7595 FPT_BL_Card[p_card].discQ_Tbl[p_sccb->Sccb_tag] = p_sccb;
7596 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarLUNBusy[0] = 0;
7597 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarTagQ_Cnt++;
7598 }else
7600 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = p_sccb;
7603 FPT_BL_Card[p_card].currentSCCB = NULL;
7607 /*---------------------------------------------------------------------
7609 * Function: Queue Flush SCCB
7611 * Description: Flush all SCCB's back to the host driver for this target.
7613 *---------------------------------------------------------------------*/
7615 static void FPT_queueFlushSccb(UCHAR p_card, UCHAR error_code)
7617 UCHAR qtag,thisTarg;
7618 PSCCB currSCCB;
7619 PSCCBMgr_tar_info currTar_Info;
7621 currSCCB = FPT_BL_Card[p_card].currentSCCB;
7622 if(currSCCB != NULL)
7624 thisTarg = (UCHAR)currSCCB->TargID;
7625 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7627 for (qtag=0; qtag<QUEUE_DEPTH; qtag++) {
7629 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7630 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg))
7633 FPT_BL_Card[p_card].discQ_Tbl[qtag]->HostStatus = (UCHAR)error_code;
7635 FPT_queueCmdComplete(&FPT_BL_Card[p_card],FPT_BL_Card[p_card].discQ_Tbl[qtag], p_card);
7637 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7638 currTar_Info->TarTagQ_Cnt--;
7646 /*---------------------------------------------------------------------
7648 * Function: Queue Flush Target SCCB
7650 * Description: Flush all SCCB's back to the host driver for this target.
7652 *---------------------------------------------------------------------*/
7654 static void FPT_queueFlushTargSccb(UCHAR p_card, UCHAR thisTarg,
7655 UCHAR error_code)
7657 UCHAR qtag;
7658 PSCCBMgr_tar_info currTar_Info;
7660 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7662 for (qtag=0; qtag<QUEUE_DEPTH; qtag++) {
7664 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7665 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg))
7668 FPT_BL_Card[p_card].discQ_Tbl[qtag]->HostStatus = (UCHAR)error_code;
7670 FPT_queueCmdComplete(&FPT_BL_Card[p_card],FPT_BL_Card[p_card].discQ_Tbl[qtag], p_card);
7672 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7673 currTar_Info->TarTagQ_Cnt--;
7684 static void FPT_queueAddSccb(PSCCB p_SCCB, UCHAR p_card)
7686 PSCCBMgr_tar_info currTar_Info;
7687 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7689 p_SCCB->Sccb_forwardlink = NULL;
7691 p_SCCB->Sccb_backlink = currTar_Info->TarSelQ_Tail;
7693 if (currTar_Info->TarSelQ_Cnt == 0) {
7695 currTar_Info->TarSelQ_Head = p_SCCB;
7698 else {
7700 currTar_Info->TarSelQ_Tail->Sccb_forwardlink = p_SCCB;
7704 currTar_Info->TarSelQ_Tail = p_SCCB;
7705 currTar_Info->TarSelQ_Cnt++;
7709 /*---------------------------------------------------------------------
7711 * Function: Queue Find SCCB
7713 * Description: Search the target select Queue for this SCCB, and
7714 * remove it if found.
7716 *---------------------------------------------------------------------*/
7718 static UCHAR FPT_queueFindSccb(PSCCB p_SCCB, UCHAR p_card)
7720 PSCCB q_ptr;
7721 PSCCBMgr_tar_info currTar_Info;
7723 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7725 q_ptr = currTar_Info->TarSelQ_Head;
7727 while(q_ptr != NULL) {
7729 if (q_ptr == p_SCCB) {
7732 if (currTar_Info->TarSelQ_Head == q_ptr) {
7734 currTar_Info->TarSelQ_Head = q_ptr->Sccb_forwardlink;
7737 if (currTar_Info->TarSelQ_Tail == q_ptr) {
7739 currTar_Info->TarSelQ_Tail = q_ptr->Sccb_backlink;
7742 if (q_ptr->Sccb_forwardlink != NULL) {
7743 q_ptr->Sccb_forwardlink->Sccb_backlink = q_ptr->Sccb_backlink;
7746 if (q_ptr->Sccb_backlink != NULL) {
7747 q_ptr->Sccb_backlink->Sccb_forwardlink = q_ptr->Sccb_forwardlink;
7750 currTar_Info->TarSelQ_Cnt--;
7752 return(1);
7755 else {
7756 q_ptr = q_ptr->Sccb_forwardlink;
7761 return(0);
7766 /*---------------------------------------------------------------------
7768 * Function: Utility Update Residual Count
7770 * Description: Update the XferCnt to the remaining byte count.
7771 * If we transferred all the data then just write zero.
7772 * If Non-SG transfer then report Total Cnt - Actual Transfer
7773 * Cnt. For SG transfers add the count fields of all
7774 * remaining SG elements, as well as any partial remaining
7775 * element.
7777 *---------------------------------------------------------------------*/
7779 static void FPT_utilUpdateResidual(PSCCB p_SCCB)
7781 ULONG partial_cnt;
7782 UINT sg_index;
7783 ULONG *sg_ptr;
7785 if (p_SCCB->Sccb_XferState & F_ALL_XFERRED) {
7787 p_SCCB->DataLength = 0x0000;
7790 else if (p_SCCB->Sccb_XferState & F_SG_XFER) {
7792 partial_cnt = 0x0000;
7794 sg_index = p_SCCB->Sccb_sgseg;
7796 sg_ptr = (ULONG *)p_SCCB->DataPointer;
7798 if (p_SCCB->Sccb_SGoffset) {
7800 partial_cnt = p_SCCB->Sccb_SGoffset;
7801 sg_index++;
7804 while ( ((ULONG)sg_index * (ULONG)SG_ELEMENT_SIZE) <
7805 p_SCCB->DataLength ) {
7807 partial_cnt += *(sg_ptr+(sg_index * 2));
7808 sg_index++;
7811 p_SCCB->DataLength = partial_cnt;
7814 else {
7816 p_SCCB->DataLength -= p_SCCB->Sccb_ATC;
7821 /*---------------------------------------------------------------------
7823 * Function: Wait 1 Second
7825 * Description: Wait for 1 second.
7827 *---------------------------------------------------------------------*/
7829 static void FPT_Wait1Second(ULONG p_port)
7831 UCHAR i;
7833 for(i=0; i < 4; i++) {
7835 FPT_Wait(p_port, TO_250ms);
7837 if ((RD_HARPOON(p_port+hp_scsictrl_0) & SCSI_RST))
7838 break;
7840 if((RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL))
7841 break;
7846 /*---------------------------------------------------------------------
7848 * Function: FPT_Wait
7850 * Description: Wait the desired delay.
7852 *---------------------------------------------------------------------*/
7854 static void FPT_Wait(ULONG p_port, UCHAR p_delay)
7856 UCHAR old_timer;
7857 UCHAR green_flag;
7859 old_timer = RD_HARPOON(p_port+hp_seltimeout);
7861 green_flag=RD_HARPOON(p_port+hp_clkctrl_0);
7862 WR_HARPOON(p_port+hp_clkctrl_0, CLKCTRL_DEFAULT);
7864 WR_HARPOON(p_port+hp_seltimeout,p_delay);
7865 WRW_HARPOON((p_port+hp_intstat), TIMEOUT);
7866 WRW_HARPOON((p_port+hp_intena), (FPT_default_intena & ~TIMEOUT));
7869 WR_HARPOON(p_port+hp_portctrl_0,
7870 (RD_HARPOON(p_port+hp_portctrl_0) | START_TO));
7872 while (!(RDW_HARPOON((p_port+hp_intstat)) & TIMEOUT)) {
7874 if ((RD_HARPOON(p_port+hp_scsictrl_0) & SCSI_RST))
7875 break;
7877 if ((RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL))
7878 break;
7881 WR_HARPOON(p_port+hp_portctrl_0,
7882 (RD_HARPOON(p_port+hp_portctrl_0) & ~START_TO));
7884 WRW_HARPOON((p_port+hp_intstat), TIMEOUT);
7885 WRW_HARPOON((p_port+hp_intena), FPT_default_intena);
7887 WR_HARPOON(p_port+hp_clkctrl_0,green_flag);
7889 WR_HARPOON(p_port+hp_seltimeout,old_timer);
7893 /*---------------------------------------------------------------------
7895 * Function: Enable/Disable Write to EEPROM
7897 * Description: The EEPROM must first be enabled for writes
7898 * A total of 9 clocks are needed.
7900 *---------------------------------------------------------------------*/
7902 static void FPT_utilEEWriteOnOff(ULONG p_port,UCHAR p_mode)
7904 UCHAR ee_value;
7906 ee_value = (UCHAR)(RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H));
7908 if (p_mode)
7910 FPT_utilEESendCmdAddr(p_port, EWEN, EWEN_ADDR);
7912 else
7915 FPT_utilEESendCmdAddr(p_port, EWDS, EWDS_ADDR);
7917 WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
7918 WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /*Turn off Master Select */
7922 /*---------------------------------------------------------------------
7924 * Function: Write EEPROM
7926 * Description: Write a word to the EEPROM at the specified
7927 * address.
7929 *---------------------------------------------------------------------*/
7931 static void FPT_utilEEWrite(ULONG p_port, USHORT ee_data, USHORT ee_addr)
7934 UCHAR ee_value;
7935 USHORT i;
7937 ee_value = (UCHAR)((RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H))|
7938 (SEE_MS | SEE_CS));
7942 FPT_utilEESendCmdAddr(p_port, EE_WRITE, ee_addr);
7945 ee_value |= (SEE_MS + SEE_CS);
7947 for(i = 0x8000; i != 0; i>>=1) {
7949 if (i & ee_data)
7950 ee_value |= SEE_DO;
7951 else
7952 ee_value &= ~SEE_DO;
7954 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7955 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7956 ee_value |= SEE_CLK; /* Clock data! */
7957 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7958 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7959 ee_value &= ~SEE_CLK;
7960 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7961 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
7963 ee_value &= (EXT_ARB_ACK | SCSI_TERM_ENA_H);
7964 WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS));
7966 FPT_Wait(p_port, TO_10ms);
7968 WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS | SEE_CS)); /* Set CS to EEPROM */
7969 WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /* Turn off CS */
7970 WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /* Turn off Master Select */
7973 /*---------------------------------------------------------------------
7975 * Function: Read EEPROM
7977 * Description: Read a word from the EEPROM at the desired
7978 * address.
7980 *---------------------------------------------------------------------*/
7982 static USHORT FPT_utilEERead(ULONG p_port, USHORT ee_addr)
7984 USHORT i, ee_data1, ee_data2;
7986 i = 0;
7987 ee_data1 = FPT_utilEEReadOrg(p_port, ee_addr);
7990 ee_data2 = FPT_utilEEReadOrg(p_port, ee_addr);
7992 if(ee_data1 == ee_data2)
7993 return(ee_data1);
7995 ee_data1 = ee_data2;
7996 i++;
7998 }while(i < 4);
8000 return(ee_data1);
8003 /*---------------------------------------------------------------------
8005 * Function: Read EEPROM Original
8007 * Description: Read a word from the EEPROM at the desired
8008 * address.
8010 *---------------------------------------------------------------------*/
8012 static USHORT FPT_utilEEReadOrg(ULONG p_port, USHORT ee_addr)
8015 UCHAR ee_value;
8016 USHORT i, ee_data;
8018 ee_value = (UCHAR)((RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H))|
8019 (SEE_MS | SEE_CS));
8022 FPT_utilEESendCmdAddr(p_port, EE_READ, ee_addr);
8025 ee_value |= (SEE_MS + SEE_CS);
8026 ee_data = 0;
8028 for(i = 1; i <= 16; i++) {
8030 ee_value |= SEE_CLK; /* Clock data! */
8031 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8032 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8033 ee_value &= ~SEE_CLK;
8034 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8035 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8037 ee_data <<= 1;
8039 if (RD_HARPOON(p_port+hp_ee_ctrl) & SEE_DI)
8040 ee_data |= 1;
8043 ee_value &= ~(SEE_MS + SEE_CS);
8044 WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
8045 WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /*Turn off Master Select */
8047 return(ee_data);
8051 /*---------------------------------------------------------------------
8053 * Function: Send EE command and Address to the EEPROM
8055 * Description: Transfers the correct command and sends the address
8056 * to the eeprom.
8058 *---------------------------------------------------------------------*/
8060 static void FPT_utilEESendCmdAddr(ULONG p_port, UCHAR ee_cmd, USHORT ee_addr)
8062 UCHAR ee_value;
8063 UCHAR narrow_flg;
8065 USHORT i;
8068 narrow_flg= (UCHAR)(RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD);
8071 ee_value = SEE_MS;
8072 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8074 ee_value |= SEE_CS; /* Set CS to EEPROM */
8075 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8078 for(i = 0x04; i != 0; i>>=1) {
8080 if (i & ee_cmd)
8081 ee_value |= SEE_DO;
8082 else
8083 ee_value &= ~SEE_DO;
8085 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8086 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8087 ee_value |= SEE_CLK; /* Clock data! */
8088 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8089 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8090 ee_value &= ~SEE_CLK;
8091 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8092 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8096 if (narrow_flg)
8097 i = 0x0080;
8099 else
8100 i = 0x0200;
8103 while (i != 0) {
8105 if (i & ee_addr)
8106 ee_value |= SEE_DO;
8107 else
8108 ee_value &= ~SEE_DO;
8110 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8111 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8112 ee_value |= SEE_CLK; /* Clock data! */
8113 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8114 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8115 ee_value &= ~SEE_CLK;
8116 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8117 WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
8119 i >>= 1;
8123 static USHORT FPT_CalcCrc16(UCHAR buffer[])
8125 USHORT crc=0;
8126 int i,j;
8127 USHORT ch;
8128 for (i=0; i < ID_STRING_LENGTH; i++)
8130 ch = (USHORT) buffer[i];
8131 for(j=0; j < 8; j++)
8133 if ((crc ^ ch) & 1)
8134 crc = (crc >> 1) ^ CRCMASK;
8135 else
8136 crc >>= 1;
8137 ch >>= 1;
8140 return(crc);
8143 static UCHAR FPT_CalcLrc(UCHAR buffer[])
8145 int i;
8146 UCHAR lrc;
8147 lrc = 0;
8148 for(i = 0; i < ID_STRING_LENGTH; i++)
8149 lrc ^= buffer[i];
8150 return(lrc);
8156 The following inline definitions avoid type conflicts.
8159 static inline unsigned char
8160 FlashPoint__ProbeHostAdapter(struct FlashPoint_Info *FlashPointInfo)
8162 return FlashPoint_ProbeHostAdapter((PSCCBMGR_INFO) FlashPointInfo);
8166 static inline FlashPoint_CardHandle_T
8167 FlashPoint__HardwareResetHostAdapter(struct FlashPoint_Info *FlashPointInfo)
8169 return FlashPoint_HardwareResetHostAdapter((PSCCBMGR_INFO) FlashPointInfo);
8172 static inline void
8173 FlashPoint__ReleaseHostAdapter(FlashPoint_CardHandle_T CardHandle)
8175 FlashPoint_ReleaseHostAdapter(CardHandle);
8179 static inline void
8180 FlashPoint__StartCCB(FlashPoint_CardHandle_T CardHandle, struct BusLogic_CCB *CCB)
8182 FlashPoint_StartCCB(CardHandle, (PSCCB) CCB);
8186 static inline void
8187 FlashPoint__AbortCCB(FlashPoint_CardHandle_T CardHandle, struct BusLogic_CCB *CCB)
8189 FlashPoint_AbortCCB(CardHandle, (PSCCB) CCB);
8193 static inline boolean
8194 FlashPoint__InterruptPending(FlashPoint_CardHandle_T CardHandle)
8196 return FlashPoint_InterruptPending(CardHandle);
8200 static inline int
8201 FlashPoint__HandleInterrupt(FlashPoint_CardHandle_T CardHandle)
8203 return FlashPoint_HandleInterrupt(CardHandle);
8207 #define FlashPoint_ProbeHostAdapter FlashPoint__ProbeHostAdapter
8208 #define FlashPoint_HardwareResetHostAdapter FlashPoint__HardwareResetHostAdapter
8209 #define FlashPoint_ReleaseHostAdapter FlashPoint__ReleaseHostAdapter
8210 #define FlashPoint_StartCCB FlashPoint__StartCCB
8211 #define FlashPoint_AbortCCB FlashPoint__AbortCCB
8212 #define FlashPoint_InterruptPending FlashPoint__InterruptPending
8213 #define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
8216 #else /* CONFIG_SCSI_OMIT_FLASHPOINT */
8220 Define prototypes for the FlashPoint SCCB Manager Functions.
8223 extern unsigned char FlashPoint_ProbeHostAdapter(struct FlashPoint_Info *);
8224 extern FlashPoint_CardHandle_T
8225 FlashPoint_HardwareResetHostAdapter(struct FlashPoint_Info *);
8226 extern void FlashPoint_StartCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
8227 extern int FlashPoint_AbortCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
8228 extern boolean FlashPoint_InterruptPending(FlashPoint_CardHandle_T);
8229 extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T);
8230 extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T);
8233 #endif /* CONFIG_SCSI_OMIT_FLASHPOINT */