Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / scsi / FlashPoint.c
blob8e3d949b7118ac54b9d6864cdd3915deaa8197d3
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.
18 #include <linux/config.h>
20 #ifndef CONFIG_SCSI_OMIT_FLASHPOINT
22 #define MAX_CARDS 8
23 #undef BUSTYPE_PCI
25 #define CRCMASK 0xA001
27 #define FAILURE 0xFFFFFFFFL
29 #define BIT(x) ((unsigned char)(1<<(x))) /* single-bit mask in bit position x */
30 #define BITW(x) ((unsigned short)(1<<(x))) /* single-bit mask in bit position x */
32 struct sccb;
33 typedef void (*CALL_BK_FN) (struct sccb *);
35 struct sccb_mgr_info {
36 unsigned long si_baseaddr;
37 unsigned char si_present;
38 unsigned char si_intvect;
39 unsigned char si_id;
40 unsigned char si_lun;
41 unsigned short si_fw_revision;
42 unsigned short si_per_targ_init_sync;
43 unsigned short si_per_targ_fast_nego;
44 unsigned short si_per_targ_ultra_nego;
45 unsigned short si_per_targ_no_disc;
46 unsigned short si_per_targ_wide_nego;
47 unsigned short si_flags;
48 unsigned char si_card_family;
49 unsigned char si_bustype;
50 unsigned char si_card_model[3];
51 unsigned char si_relative_cardnum;
52 unsigned char si_reserved[4];
53 unsigned long si_OS_reserved;
54 unsigned char si_XlatInfo[4];
55 unsigned long si_reserved2[5];
56 unsigned long si_secondary_range;
59 #define SCSI_PARITY_ENA 0x0001
60 #define LOW_BYTE_TERM 0x0010
61 #define HIGH_BYTE_TERM 0x0020
62 #define BUSTYPE_PCI 0x3
64 #define SUPPORT_16TAR_32LUN 0x0002
65 #define SOFT_RESET 0x0004
66 #define EXTENDED_TRANSLATION 0x0008
67 #define POST_ALL_UNDERRRUNS 0x0040
68 #define FLAG_SCAM_ENABLED 0x0080
69 #define FLAG_SCAM_LEVEL2 0x0100
71 #define HARPOON_FAMILY 0x02
73 /* SCCB struct used for both SCCB and UCB manager compiles!
74 * The UCB Manager treats the SCCB as it's 'native hardware structure'
77 #pragma pack(1)
78 struct sccb {
79 unsigned char OperationCode;
80 unsigned char ControlByte;
81 unsigned char CdbLength;
82 unsigned char RequestSenseLength;
83 unsigned long DataLength;
84 unsigned long DataPointer;
85 unsigned char CcbRes[2];
86 unsigned char HostStatus;
87 unsigned char TargetStatus;
88 unsigned char TargID;
89 unsigned char Lun;
90 unsigned char Cdb[12];
91 unsigned char CcbRes1;
92 unsigned char Reserved1;
93 unsigned long Reserved2;
94 unsigned long SensePointer;
96 CALL_BK_FN SccbCallback; /* VOID (*SccbCallback)(); */
97 unsigned long SccbIOPort; /* Identifies board base port */
98 unsigned char SccbStatus;
99 unsigned char SCCBRes2;
100 unsigned short SccbOSFlags;
102 unsigned long Sccb_XferCnt; /* actual transfer count */
103 unsigned long Sccb_ATC;
104 unsigned long SccbVirtDataPtr; /* virtual addr for OS/2 */
105 unsigned long Sccb_res1;
106 unsigned short Sccb_MGRFlags;
107 unsigned short Sccb_sgseg;
108 unsigned char Sccb_scsimsg; /* identify msg for selection */
109 unsigned char Sccb_tag;
110 unsigned char Sccb_scsistat;
111 unsigned char Sccb_idmsg; /* image of last msg in */
112 struct sccb *Sccb_forwardlink;
113 struct sccb *Sccb_backlink;
114 unsigned long Sccb_savedATC;
115 unsigned char Save_Cdb[6];
116 unsigned char Save_CdbLen;
117 unsigned char Sccb_XferState;
118 unsigned long Sccb_SGoffset;
121 #pragma pack()
123 #define SCATTER_GATHER_COMMAND 0x02
124 #define RESIDUAL_COMMAND 0x03
125 #define RESIDUAL_SG_COMMAND 0x04
126 #define RESET_COMMAND 0x81
128 #define F_USE_CMD_Q 0x20 /*Inidcates TAGGED command. */
129 #define TAG_TYPE_MASK 0xC0 /*Type of tag msg to send. */
130 #define SCCB_DATA_XFER_OUT 0x10 /* Write */
131 #define SCCB_DATA_XFER_IN 0x08 /* Read */
133 #define NO_AUTO_REQUEST_SENSE 0x01 /* No Request Sense Buffer */
135 #define BUS_FREE_ST 0
136 #define SELECT_ST 1
137 #define SELECT_BDR_ST 2 /* Select w\ Bus Device Reset */
138 #define SELECT_SN_ST 3 /* Select w\ Sync Nego */
139 #define SELECT_WN_ST 4 /* Select w\ Wide Data Nego */
140 #define SELECT_Q_ST 5 /* Select w\ Tagged Q'ing */
141 #define COMMAND_ST 6
142 #define DATA_OUT_ST 7
143 #define DATA_IN_ST 8
144 #define DISCONNECT_ST 9
145 #define ABORT_ST 11
147 #define F_HOST_XFER_DIR 0x01
148 #define F_ALL_XFERRED 0x02
149 #define F_SG_XFER 0x04
150 #define F_AUTO_SENSE 0x08
151 #define F_ODD_BALL_CNT 0x10
152 #define F_NO_DATA_YET 0x80
154 #define F_STATUSLOADED 0x01
155 #define F_DEV_SELECTED 0x04
157 #define SCCB_COMPLETE 0x00 /* SCCB completed without error */
158 #define SCCB_DATA_UNDER_RUN 0x0C
159 #define SCCB_SELECTION_TIMEOUT 0x11 /* Set SCSI selection timed out */
160 #define SCCB_DATA_OVER_RUN 0x12
161 #define SCCB_PHASE_SEQUENCE_FAIL 0x14 /* Target bus phase sequence failure */
163 #define SCCB_GROSS_FW_ERR 0x27 /* Major problem! */
164 #define SCCB_BM_ERR 0x30 /* BusMaster error. */
165 #define SCCB_PARITY_ERR 0x34 /* SCSI parity error */
167 #define SCCB_IN_PROCESS 0x00
168 #define SCCB_SUCCESS 0x01
169 #define SCCB_ABORT 0x02
170 #define SCCB_ERROR 0x04
172 #define ORION_FW_REV 3110
174 #define QUEUE_DEPTH 254+1 /*1 for Normal disconnect 32 for Q'ing. */
176 #define MAX_MB_CARDS 4 /* Max. no of cards suppoerted on Mother Board */
178 #define MAX_SCSI_TAR 16
179 #define MAX_LUN 32
180 #define LUN_MASK 0x1f
182 #define SG_BUF_CNT 16 /*Number of prefetched elements. */
184 #define SG_ELEMENT_SIZE 8 /*Eight byte per element. */
186 #define RD_HARPOON(ioport) inb((u32)ioport)
187 #define RDW_HARPOON(ioport) inw((u32)ioport)
188 #define RD_HARP32(ioport,offset,data) (data = inl((u32)(ioport + offset)))
189 #define WR_HARPOON(ioport,val) outb((u8) val, (u32)ioport)
190 #define WRW_HARPOON(ioport,val) outw((u16)val, (u32)ioport)
191 #define WR_HARP32(ioport,offset,data) outl(data, (u32)(ioport + offset))
193 #define TAR_SYNC_MASK (BIT(7)+BIT(6))
194 #define SYNC_TRYING BIT(6)
195 #define SYNC_SUPPORTED (BIT(7)+BIT(6))
197 #define TAR_WIDE_MASK (BIT(5)+BIT(4))
198 #define WIDE_ENABLED BIT(4)
199 #define WIDE_NEGOCIATED BIT(5)
201 #define TAR_TAG_Q_MASK (BIT(3)+BIT(2))
202 #define TAG_Q_TRYING BIT(2)
203 #define TAG_Q_REJECT BIT(3)
205 #define TAR_ALLOW_DISC BIT(0)
207 #define EE_SYNC_MASK (BIT(0)+BIT(1))
208 #define EE_SYNC_5MB BIT(0)
209 #define EE_SYNC_10MB BIT(1)
210 #define EE_SYNC_20MB (BIT(0)+BIT(1))
212 #define EE_WIDE_SCSI BIT(7)
214 struct sccb_mgr_tar_info {
216 struct sccb *TarSelQ_Head;
217 struct sccb *TarSelQ_Tail;
218 unsigned char TarLUN_CA; /*Contingent Allgiance */
219 unsigned char TarTagQ_Cnt;
220 unsigned char TarSelQ_Cnt;
221 unsigned char TarStatus;
222 unsigned char TarEEValue;
223 unsigned char TarSyncCtrl;
224 unsigned char TarReserved[2]; /* for alignment */
225 unsigned char LunDiscQ_Idx[MAX_LUN];
226 unsigned char TarLUNBusy[MAX_LUN];
229 struct nvram_info {
230 unsigned char niModel; /* Model No. of card */
231 unsigned char niCardNo; /* Card no. */
232 unsigned long niBaseAddr; /* Port Address of card */
233 unsigned char niSysConf; /* Adapter Configuration byte - Byte 16 of eeprom map */
234 unsigned char niScsiConf; /* SCSI Configuration byte - Byte 17 of eeprom map */
235 unsigned char niScamConf; /* SCAM Configuration byte - Byte 20 of eeprom map */
236 unsigned char niAdapId; /* Host Adapter ID - Byte 24 of eerpom map */
237 unsigned char niSyncTbl[MAX_SCSI_TAR / 2]; /* Sync/Wide byte of targets */
238 unsigned char niScamTbl[MAX_SCSI_TAR][4]; /* Compressed Scam name string of Targets */
241 #define MODEL_LT 1
242 #define MODEL_DL 2
243 #define MODEL_LW 3
244 #define MODEL_DW 4
246 struct sccb_card {
247 struct sccb *currentSCCB;
248 struct sccb_mgr_info *cardInfo;
250 unsigned long ioPort;
252 unsigned short cmdCounter;
253 unsigned char discQCount;
254 unsigned char tagQ_Lst;
255 unsigned char cardIndex;
256 unsigned char scanIndex;
257 unsigned char globalFlags;
258 unsigned char ourId;
259 struct nvram_info *pNvRamInfo;
260 struct sccb *discQ_Tbl[QUEUE_DEPTH];
264 #define F_TAG_STARTED 0x01
265 #define F_CONLUN_IO 0x02
266 #define F_DO_RENEGO 0x04
267 #define F_NO_FILTER 0x08
268 #define F_GREEN_PC 0x10
269 #define F_HOST_XFER_ACT 0x20
270 #define F_NEW_SCCB_CMD 0x40
271 #define F_UPDATE_EEPROM 0x80
273 #define ID_STRING_LENGTH 32
274 #define TYPE_CODE0 0x63 /*Level2 Mstr (bits 7-6), */
276 #define SLV_TYPE_CODE0 0xA3 /*Priority Bit set (bits 7-6), */
278 #define ASSIGN_ID 0x00
279 #define SET_P_FLAG 0x01
280 #define CFG_CMPLT 0x03
281 #define DOM_MSTR 0x0F
282 #define SYNC_PTRN 0x1F
284 #define ID_0_7 0x18
285 #define ID_8_F 0x11
286 #define MISC_CODE 0x14
287 #define CLR_P_FLAG 0x18
289 #define INIT_SELTD 0x01
290 #define LEVEL2_TAR 0x02
292 enum scam_id_st { ID0, ID1, ID2, ID3, ID4, ID5, ID6, ID7, ID8, ID9, ID10, ID11,
293 ID12,
294 ID13, ID14, ID15, ID_UNUSED, ID_UNASSIGNED, ID_ASSIGNED, LEGACY,
295 CLR_PRIORITY, NO_ID_AVAIL
298 typedef struct SCCBscam_info {
300 unsigned char id_string[ID_STRING_LENGTH];
301 enum scam_id_st state;
303 } SCCBSCAM_INFO;
305 #define SCSI_REQUEST_SENSE 0x03
306 #define SCSI_READ 0x08
307 #define SCSI_WRITE 0x0A
308 #define SCSI_START_STOP_UNIT 0x1B
309 #define SCSI_READ_EXTENDED 0x28
310 #define SCSI_WRITE_EXTENDED 0x2A
311 #define SCSI_WRITE_AND_VERIFY 0x2E
313 #define SSGOOD 0x00
314 #define SSCHECK 0x02
315 #define SSQ_FULL 0x28
317 #define SMCMD_COMP 0x00
318 #define SMEXT 0x01
319 #define SMSAVE_DATA_PTR 0x02
320 #define SMREST_DATA_PTR 0x03
321 #define SMDISC 0x04
322 #define SMABORT 0x06
323 #define SMREJECT 0x07
324 #define SMNO_OP 0x08
325 #define SMPARITY 0x09
326 #define SMDEV_RESET 0x0C
327 #define SMABORT_TAG 0x0D
328 #define SMINIT_RECOVERY 0x0F
329 #define SMREL_RECOVERY 0x10
331 #define SMIDENT 0x80
332 #define DISC_PRIV 0x40
334 #define SMSYNC 0x01
335 #define SMWDTR 0x03
336 #define SM8BIT 0x00
337 #define SM16BIT 0x01
338 #define SMIGNORWR 0x23 /* Ignore Wide Residue */
340 #define SIX_BYTE_CMD 0x06
341 #define TWELVE_BYTE_CMD 0x0C
343 #define ASYNC 0x00
344 #define MAX_OFFSET 0x0F /* Maxbyteoffset for Sync Xfers */
346 #define EEPROM_WD_CNT 256
348 #define EEPROM_CHECK_SUM 0
349 #define FW_SIGNATURE 2
350 #define MODEL_NUMB_0 4
351 #define MODEL_NUMB_2 6
352 #define MODEL_NUMB_4 8
353 #define SYSTEM_CONFIG 16
354 #define SCSI_CONFIG 17
355 #define BIOS_CONFIG 18
356 #define SCAM_CONFIG 20
357 #define ADAPTER_SCSI_ID 24
359 #define IGNORE_B_SCAN 32
360 #define SEND_START_ENA 34
361 #define DEVICE_ENABLE 36
363 #define SYNC_RATE_TBL 38
364 #define SYNC_RATE_TBL01 38
365 #define SYNC_RATE_TBL23 40
366 #define SYNC_RATE_TBL45 42
367 #define SYNC_RATE_TBL67 44
368 #define SYNC_RATE_TBL89 46
369 #define SYNC_RATE_TBLab 48
370 #define SYNC_RATE_TBLcd 50
371 #define SYNC_RATE_TBLef 52
373 #define EE_SCAMBASE 256
375 #define SCAM_ENABLED BIT(2)
376 #define SCAM_LEVEL2 BIT(3)
378 #define RENEGO_ENA BITW(10)
379 #define CONNIO_ENA BITW(11)
380 #define GREEN_PC_ENA BITW(12)
382 #define AUTO_RATE_00 00
383 #define AUTO_RATE_05 01
384 #define AUTO_RATE_10 02
385 #define AUTO_RATE_20 03
387 #define WIDE_NEGO_BIT BIT(7)
388 #define DISC_ENABLE_BIT BIT(6)
390 #define hp_vendor_id_0 0x00 /* LSB */
391 #define ORION_VEND_0 0x4B
393 #define hp_vendor_id_1 0x01 /* MSB */
394 #define ORION_VEND_1 0x10
396 #define hp_device_id_0 0x02 /* LSB */
397 #define ORION_DEV_0 0x30
399 #define hp_device_id_1 0x03 /* MSB */
400 #define ORION_DEV_1 0x81
402 /* Sub Vendor ID and Sub Device ID only available in
403 Harpoon Version 2 and higher */
405 #define hp_sub_device_id_0 0x06 /* LSB */
407 #define hp_semaphore 0x0C
408 #define SCCB_MGR_ACTIVE BIT(0)
409 #define TICKLE_ME BIT(1)
410 #define SCCB_MGR_PRESENT BIT(3)
411 #define BIOS_IN_USE BIT(4)
413 #define hp_sys_ctrl 0x0F
415 #define STOP_CLK BIT(0) /*Turn off BusMaster Clock */
416 #define DRVR_RST BIT(1) /*Firmware Reset to 80C15 chip */
417 #define HALT_MACH BIT(3) /*Halt State Machine */
418 #define HARD_ABORT BIT(4) /*Hard Abort */
420 #define hp_host_blk_cnt 0x13
422 #define XFER_BLK64 0x06 /* 1 1 0 64 byte per block */
424 #define BM_THRESHOLD 0x40 /* PCI mode can only xfer 16 bytes */
426 #define hp_int_mask 0x17
428 #define INT_CMD_COMPL BIT(0) /* DMA command complete */
429 #define INT_EXT_STATUS BIT(1) /* Extended Status Set */
431 #define hp_xfer_cnt_lo 0x18
432 #define hp_xfer_cnt_hi 0x1A
433 #define hp_xfer_cmd 0x1B
435 #define XFER_HOST_DMA 0x00 /* 0 0 0 Transfer Host -> DMA */
436 #define XFER_DMA_HOST 0x01 /* 0 0 1 Transfer DMA -> Host */
438 #define XFER_HOST_AUTO 0x00 /* 0 0 Auto Transfer Size */
440 #define XFER_DMA_8BIT 0x20 /* 0 1 8 BIT Transfer Size */
442 #define DISABLE_INT BIT(7) /*Do not interrupt at end of cmd. */
444 #define HOST_WRT_CMD ((DISABLE_INT + XFER_HOST_DMA + XFER_HOST_AUTO + XFER_DMA_8BIT))
445 #define HOST_RD_CMD ((DISABLE_INT + XFER_DMA_HOST + XFER_HOST_AUTO + XFER_DMA_8BIT))
447 #define hp_host_addr_lo 0x1C
448 #define hp_host_addr_hmi 0x1E
450 #define hp_ee_ctrl 0x22
452 #define EXT_ARB_ACK BIT(7)
453 #define SCSI_TERM_ENA_H BIT(6) /* SCSI high byte terminator */
454 #define SEE_MS BIT(5)
455 #define SEE_CS BIT(3)
456 #define SEE_CLK BIT(2)
457 #define SEE_DO BIT(1)
458 #define SEE_DI BIT(0)
460 #define EE_READ 0x06
461 #define EE_WRITE 0x05
462 #define EWEN 0x04
463 #define EWEN_ADDR 0x03C0
464 #define EWDS 0x04
465 #define EWDS_ADDR 0x0000
467 #define hp_bm_ctrl 0x26
469 #define SCSI_TERM_ENA_L BIT(0) /*Enable/Disable external terminators */
470 #define FLUSH_XFER_CNTR BIT(1) /*Flush transfer counter */
471 #define FORCE1_XFER BIT(5) /*Always xfer one byte in byte mode */
472 #define FAST_SINGLE BIT(6) /*?? */
474 #define BMCTRL_DEFAULT (FORCE1_XFER|FAST_SINGLE|SCSI_TERM_ENA_L)
476 #define hp_sg_addr 0x28
477 #define hp_page_ctrl 0x29
479 #define SCATTER_EN BIT(0)
480 #define SGRAM_ARAM BIT(1)
481 #define G_INT_DISABLE BIT(3) /* Enable/Disable all Interrupts */
482 #define NARROW_SCSI_CARD BIT(4) /* NARROW/WIDE SCSI config pin */
484 #define hp_pci_stat_cfg 0x2D
486 #define REC_MASTER_ABORT BIT(5) /*received Master abort */
488 #define hp_rev_num 0x33
490 #define hp_stack_data 0x34
491 #define hp_stack_addr 0x35
493 #define hp_ext_status 0x36
495 #define BM_FORCE_OFF BIT(0) /*Bus Master is forced to get off */
496 #define PCI_TGT_ABORT BIT(0) /*PCI bus master transaction aborted */
497 #define PCI_DEV_TMOUT BIT(1) /*PCI Device Time out */
498 #define CMD_ABORTED BIT(4) /*Command aborted */
499 #define BM_PARITY_ERR BIT(5) /*parity error on data received */
500 #define PIO_OVERRUN BIT(6) /*Slave data overrun */
501 #define BM_CMD_BUSY BIT(7) /*Bus master transfer command busy */
502 #define BAD_EXT_STATUS (BM_FORCE_OFF | PCI_DEV_TMOUT | CMD_ABORTED | \
503 BM_PARITY_ERR | PIO_OVERRUN)
505 #define hp_int_status 0x37
507 #define EXT_STATUS_ON BIT(1) /*Extended status is valid */
508 #define SCSI_INTERRUPT BIT(2) /*Global indication of a SCSI int. */
509 #define INT_ASSERTED BIT(5) /* */
511 #define hp_fifo_cnt 0x38
513 #define hp_intena 0x40
515 #define RESET BITW(7)
516 #define PROG_HLT BITW(6)
517 #define PARITY BITW(5)
518 #define FIFO BITW(4)
519 #define SEL BITW(3)
520 #define SCAM_SEL BITW(2)
521 #define RSEL BITW(1)
522 #define TIMEOUT BITW(0)
523 #define BUS_FREE BITW(15)
524 #define XFER_CNT_0 BITW(14)
525 #define PHASE BITW(13)
526 #define IUNKWN BITW(12)
527 #define ICMD_COMP BITW(11)
528 #define ITICKLE BITW(10)
529 #define IDO_STRT BITW(9)
530 #define ITAR_DISC BITW(8)
531 #define AUTO_INT (BITW(12)+BITW(11)+BITW(10)+BITW(9)+BITW(8))
532 #define CLR_ALL_INT 0xFFFF
533 #define CLR_ALL_INT_1 0xFF00
535 #define hp_intstat 0x42
537 #define hp_scsisig 0x44
539 #define SCSI_SEL BIT(7)
540 #define SCSI_BSY BIT(6)
541 #define SCSI_REQ BIT(5)
542 #define SCSI_ACK BIT(4)
543 #define SCSI_ATN BIT(3)
544 #define SCSI_CD BIT(2)
545 #define SCSI_MSG BIT(1)
546 #define SCSI_IOBIT BIT(0)
548 #define S_SCSI_PHZ (BIT(2)+BIT(1)+BIT(0))
549 #define S_MSGO_PH (BIT(2)+BIT(1) )
550 #define S_MSGI_PH (BIT(2)+BIT(1)+BIT(0))
551 #define S_DATAI_PH ( BIT(0))
552 #define S_DATAO_PH 0x00
553 #define S_ILL_PH ( BIT(1) )
555 #define hp_scsictrl_0 0x45
557 #define SEL_TAR BIT(6)
558 #define ENA_ATN BIT(4)
559 #define ENA_RESEL BIT(2)
560 #define SCSI_RST BIT(1)
561 #define ENA_SCAM_SEL BIT(0)
563 #define hp_portctrl_0 0x46
565 #define SCSI_PORT BIT(7)
566 #define SCSI_INBIT BIT(6)
567 #define DMA_PORT BIT(5)
568 #define DMA_RD BIT(4)
569 #define HOST_PORT BIT(3)
570 #define HOST_WRT BIT(2)
571 #define SCSI_BUS_EN BIT(1)
572 #define START_TO BIT(0)
574 #define hp_scsireset 0x47
576 #define SCSI_INI BIT(6)
577 #define SCAM_EN BIT(5)
578 #define DMA_RESET BIT(3)
579 #define HPSCSI_RESET BIT(2)
580 #define PROG_RESET BIT(1)
581 #define FIFO_CLR BIT(0)
583 #define hp_xfercnt_0 0x48
584 #define hp_xfercnt_2 0x4A
586 #define hp_fifodata_0 0x4C
587 #define hp_addstat 0x4E
589 #define SCAM_TIMER BIT(7)
590 #define SCSI_MODE8 BIT(3)
591 #define SCSI_PAR_ERR BIT(0)
593 #define hp_prgmcnt_0 0x4F
595 #define hp_selfid_0 0x50
596 #define hp_selfid_1 0x51
597 #define hp_arb_id 0x52
599 #define hp_select_id 0x53
601 #define hp_synctarg_base 0x54
602 #define hp_synctarg_12 0x54
603 #define hp_synctarg_13 0x55
604 #define hp_synctarg_14 0x56
605 #define hp_synctarg_15 0x57
607 #define hp_synctarg_8 0x58
608 #define hp_synctarg_9 0x59
609 #define hp_synctarg_10 0x5A
610 #define hp_synctarg_11 0x5B
612 #define hp_synctarg_4 0x5C
613 #define hp_synctarg_5 0x5D
614 #define hp_synctarg_6 0x5E
615 #define hp_synctarg_7 0x5F
617 #define hp_synctarg_0 0x60
618 #define hp_synctarg_1 0x61
619 #define hp_synctarg_2 0x62
620 #define hp_synctarg_3 0x63
622 #define NARROW_SCSI BIT(4)
623 #define DEFAULT_OFFSET 0x0F
625 #define hp_autostart_0 0x64
626 #define hp_autostart_1 0x65
627 #define hp_autostart_3 0x67
629 #define AUTO_IMMED BIT(5)
630 #define SELECT BIT(6)
631 #define END_DATA (BIT(7)+BIT(6))
633 #define hp_gp_reg_0 0x68
634 #define hp_gp_reg_1 0x69
635 #define hp_gp_reg_3 0x6B
637 #define hp_seltimeout 0x6C
639 #define TO_4ms 0x67 /* 3.9959ms */
641 #define TO_5ms 0x03 /* 4.9152ms */
642 #define TO_10ms 0x07 /* 11.xxxms */
643 #define TO_250ms 0x99 /* 250.68ms */
644 #define TO_290ms 0xB1 /* 289.99ms */
646 #define hp_clkctrl_0 0x6D
648 #define PWR_DWN BIT(6)
649 #define ACTdeassert BIT(4)
650 #define CLK_40MHZ (BIT(1) + BIT(0))
652 #define CLKCTRL_DEFAULT (ACTdeassert | CLK_40MHZ)
654 #define hp_fiforead 0x6E
655 #define hp_fifowrite 0x6F
657 #define hp_offsetctr 0x70
658 #define hp_xferstat 0x71
660 #define FIFO_EMPTY BIT(6)
662 #define hp_portctrl_1 0x72
664 #define CHK_SCSI_P BIT(3)
665 #define HOST_MODE8 BIT(0)
667 #define hp_xfer_pad 0x73
669 #define ID_UNLOCK BIT(3)
671 #define hp_scsidata_0 0x74
672 #define hp_scsidata_1 0x75
674 #define hp_aramBase 0x80
675 #define BIOS_DATA_OFFSET 0x60
676 #define BIOS_RELATIVE_CARD 0x64
678 #define AR3 (BITW(9) + BITW(8))
679 #define SDATA BITW(10)
681 #define CRD_OP BITW(11) /* Cmp Reg. w/ Data */
683 #define CRR_OP BITW(12) /* Cmp Reg. w. Reg. */
685 #define CPE_OP (BITW(14)+BITW(11)) /* Cmp SCSI phs & Branch EQ */
687 #define CPN_OP (BITW(14)+BITW(12)) /* Cmp SCSI phs & Branch NOT EQ */
689 #define ADATA_OUT 0x00
690 #define ADATA_IN BITW(8)
691 #define ACOMMAND BITW(10)
692 #define ASTATUS (BITW(10)+BITW(8))
693 #define AMSG_OUT (BITW(10)+BITW(9))
694 #define AMSG_IN (BITW(10)+BITW(9)+BITW(8))
696 #define BRH_OP BITW(13) /* Branch */
698 #define ALWAYS 0x00
699 #define EQUAL BITW(8)
700 #define NOT_EQ BITW(9)
702 #define TCB_OP (BITW(13)+BITW(11)) /* Test condition & branch */
704 #define FIFO_0 BITW(10)
706 #define MPM_OP BITW(15) /* Match phase and move data */
708 #define MRR_OP BITW(14) /* Move DReg. to Reg. */
710 #define S_IDREG (BIT(2)+BIT(1)+BIT(0))
712 #define D_AR0 0x00
713 #define D_AR1 BIT(0)
714 #define D_BUCKET (BIT(2) + BIT(1) + BIT(0))
716 #define RAT_OP (BITW(14)+BITW(13)+BITW(11))
718 #define SSI_OP (BITW(15)+BITW(11))
720 #define SSI_ITAR_DISC (ITAR_DISC >> 8)
721 #define SSI_IDO_STRT (IDO_STRT >> 8)
723 #define SSI_ICMD_COMP (ICMD_COMP >> 8)
724 #define SSI_ITICKLE (ITICKLE >> 8)
726 #define SSI_IUNKWN (IUNKWN >> 8)
727 #define SSI_INO_CC (IUNKWN >> 8)
728 #define SSI_IRFAIL (IUNKWN >> 8)
730 #define NP 0x10 /*Next Phase */
731 #define NTCMD 0x02 /*Non- Tagged Command start */
732 #define CMDPZ 0x04 /*Command phase */
733 #define DINT 0x12 /*Data Out/In interrupt */
734 #define DI 0x13 /*Data Out */
735 #define DC 0x19 /*Disconnect Message */
736 #define ST 0x1D /*Status Phase */
737 #define UNKNWN 0x24 /*Unknown bus action */
738 #define CC 0x25 /*Command Completion failure */
739 #define TICK 0x26 /*New target reselected us. */
740 #define SELCHK 0x28 /*Select & Check SCSI ID latch reg */
742 #define ID_MSG_STRT hp_aramBase + 0x00
743 #define NON_TAG_ID_MSG hp_aramBase + 0x06
744 #define CMD_STRT hp_aramBase + 0x08
745 #define SYNC_MSGS hp_aramBase + 0x08
747 #define TAG_STRT 0x00
748 #define DISCONNECT_START 0x10/2
749 #define END_DATA_START 0x14/2
750 #define CMD_ONLY_STRT CMDPZ/2
751 #define SELCHK_STRT SELCHK/2
753 #define GET_XFER_CNT(port, xfercnt) {RD_HARP32(port,hp_xfercnt_0,xfercnt); xfercnt &= 0xFFFFFF;}
754 /* #define GET_XFER_CNT(port, xfercnt) (xfercnt = RD_HARPOON(port+hp_xfercnt_2), \
755 xfercnt <<= 16,\
756 xfercnt |= RDW_HARPOON((unsigned short)(port+hp_xfercnt_0)))
758 #define HP_SETUP_ADDR_CNT(port,addr,count) (WRW_HARPOON((port+hp_host_addr_lo), (unsigned short)(addr & 0x0000FFFFL)),\
759 addr >>= 16,\
760 WRW_HARPOON((port+hp_host_addr_hmi), (unsigned short)(addr & 0x0000FFFFL)),\
761 WR_HARP32(port,hp_xfercnt_0,count),\
762 WRW_HARPOON((port+hp_xfer_cnt_lo), (unsigned short)(count & 0x0000FFFFL)),\
763 count >>= 16,\
764 WR_HARPOON(port+hp_xfer_cnt_hi, (count & 0xFF)))
766 #define ACCEPT_MSG(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
767 WR_HARPOON(port+hp_scsisig, S_ILL_PH);}
769 #define ACCEPT_MSG_ATN(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
770 WR_HARPOON(port+hp_scsisig, (S_ILL_PH|SCSI_ATN));}
772 #define DISABLE_AUTO(port) (WR_HARPOON(port+hp_scsireset, PROG_RESET),\
773 WR_HARPOON(port+hp_scsireset, 0x00))
775 #define ARAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
776 (RD_HARPOON(p_port+hp_page_ctrl) | SGRAM_ARAM)))
778 #define SGRAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
779 (RD_HARPOON(p_port+hp_page_ctrl) & ~SGRAM_ARAM)))
781 #define MDISABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
782 (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE)))
784 #define MENABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
785 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE)))
787 static unsigned char FPT_sisyncn(unsigned long port, unsigned char p_card,
788 unsigned char syncFlag);
789 static void FPT_ssel(unsigned long port, unsigned char p_card);
790 static void FPT_sres(unsigned long port, unsigned char p_card,
791 struct sccb_card *pCurrCard);
792 static void FPT_shandem(unsigned long port, unsigned char p_card,
793 struct sccb *pCurrSCCB);
794 static void FPT_stsyncn(unsigned long port, unsigned char p_card);
795 static void FPT_sisyncr(unsigned long port, unsigned char sync_pulse,
796 unsigned char offset);
797 static void FPT_sssyncv(unsigned long p_port, unsigned char p_id,
798 unsigned char p_sync_value,
799 struct sccb_mgr_tar_info *currTar_Info);
800 static void FPT_sresb(unsigned long port, unsigned char p_card);
801 static void FPT_sxfrp(unsigned long p_port, unsigned char p_card);
802 static void FPT_schkdd(unsigned long port, unsigned char p_card);
803 static unsigned char FPT_RdStack(unsigned long port, unsigned char index);
804 static void FPT_WrStack(unsigned long portBase, unsigned char index,
805 unsigned char data);
806 static unsigned char FPT_ChkIfChipInitialized(unsigned long ioPort);
808 static void FPT_SendMsg(unsigned long port, unsigned char message);
809 static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
810 unsigned char error_code);
812 static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card);
813 static void FPT_RNVRamData(struct nvram_info *pNvRamInfo);
815 static unsigned char FPT_siwidn(unsigned long port, unsigned char p_card);
816 static void FPT_stwidn(unsigned long port, unsigned char p_card);
817 static void FPT_siwidr(unsigned long port, unsigned char width);
819 static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
820 unsigned char p_card);
821 static void FPT_queueDisconnect(struct sccb *p_SCCB, unsigned char p_card);
822 static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
823 struct sccb *p_SCCB, unsigned char p_card);
824 static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
825 unsigned char p_card);
826 static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code);
827 static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char card);
828 static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
829 unsigned char p_card);
830 static void FPT_utilUpdateResidual(struct sccb *p_SCCB);
831 static unsigned short FPT_CalcCrc16(unsigned char buffer[]);
832 static unsigned char FPT_CalcLrc(unsigned char buffer[]);
834 static void FPT_Wait1Second(unsigned long p_port);
835 static void FPT_Wait(unsigned long p_port, unsigned char p_delay);
836 static void FPT_utilEEWriteOnOff(unsigned long p_port, unsigned char p_mode);
837 static void FPT_utilEEWrite(unsigned long p_port, unsigned short ee_data,
838 unsigned short ee_addr);
839 static unsigned short FPT_utilEERead(unsigned long p_port,
840 unsigned short ee_addr);
841 static unsigned short FPT_utilEEReadOrg(unsigned long p_port,
842 unsigned short ee_addr);
843 static void FPT_utilEESendCmdAddr(unsigned long p_port, unsigned char ee_cmd,
844 unsigned short ee_addr);
846 static void FPT_phaseDataOut(unsigned long port, unsigned char p_card);
847 static void FPT_phaseDataIn(unsigned long port, unsigned char p_card);
848 static void FPT_phaseCommand(unsigned long port, unsigned char p_card);
849 static void FPT_phaseStatus(unsigned long port, unsigned char p_card);
850 static void FPT_phaseMsgOut(unsigned long port, unsigned char p_card);
851 static void FPT_phaseMsgIn(unsigned long port, unsigned char p_card);
852 static void FPT_phaseIllegal(unsigned long port, unsigned char p_card);
854 static void FPT_phaseDecode(unsigned long port, unsigned char p_card);
855 static void FPT_phaseChkFifo(unsigned long port, unsigned char p_card);
856 static void FPT_phaseBusFree(unsigned long p_port, unsigned char p_card);
858 static void FPT_XbowInit(unsigned long port, unsigned char scamFlg);
859 static void FPT_BusMasterInit(unsigned long p_port);
860 static void FPT_DiagEEPROM(unsigned long p_port);
862 static void FPT_dataXferProcessor(unsigned long port,
863 struct sccb_card *pCurrCard);
864 static void FPT_busMstrSGDataXferStart(unsigned long port,
865 struct sccb *pCurrSCCB);
866 static void FPT_busMstrDataXferStart(unsigned long port,
867 struct sccb *pCurrSCCB);
868 static void FPT_hostDataXferAbort(unsigned long port, unsigned char p_card,
869 struct sccb *pCurrSCCB);
870 static void FPT_hostDataXferRestart(struct sccb *currSCCB);
872 static unsigned char FPT_SccbMgr_bad_isr(unsigned long p_port,
873 unsigned char p_card,
874 struct sccb_card *pCurrCard,
875 unsigned short p_int);
877 static void FPT_SccbMgrTableInitAll(void);
878 static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
879 unsigned char p_card);
880 static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
881 unsigned char target);
883 static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
884 unsigned char p_power_up);
886 static int FPT_scarb(unsigned long p_port, unsigned char p_sel_type);
887 static void FPT_scbusf(unsigned long p_port);
888 static void FPT_scsel(unsigned long p_port);
889 static void FPT_scasid(unsigned char p_card, unsigned long p_port);
890 static unsigned char FPT_scxferc(unsigned long p_port, unsigned char p_data);
891 static unsigned char FPT_scsendi(unsigned long p_port,
892 unsigned char p_id_string[]);
893 static unsigned char FPT_sciso(unsigned long p_port,
894 unsigned char p_id_string[]);
895 static void FPT_scwirod(unsigned long p_port, unsigned char p_data_bit);
896 static void FPT_scwiros(unsigned long p_port, unsigned char p_data_bit);
897 static unsigned char FPT_scvalq(unsigned char p_quintet);
898 static unsigned char FPT_scsell(unsigned long p_port, unsigned char targ_id);
899 static void FPT_scwtsel(unsigned long p_port);
900 static void FPT_inisci(unsigned char p_card, unsigned long p_port,
901 unsigned char p_our_id);
902 static void FPT_scsavdi(unsigned char p_card, unsigned long p_port);
903 static unsigned char FPT_scmachid(unsigned char p_card,
904 unsigned char p_id_string[]);
906 static void FPT_autoCmdCmplt(unsigned long p_port, unsigned char p_card);
907 static void FPT_autoLoadDefaultMap(unsigned long p_port);
909 static struct sccb_mgr_tar_info FPT_sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR] =
910 { {{0}} };
911 static struct sccb_card FPT_BL_Card[MAX_CARDS] = { {0} };
912 static SCCBSCAM_INFO FPT_scamInfo[MAX_SCSI_TAR] = { {{0}} };
913 static struct nvram_info FPT_nvRamInfo[MAX_MB_CARDS] = { {0} };
915 static unsigned char FPT_mbCards = 0;
916 static unsigned char FPT_scamHAString[] =
917 { 0x63, 0x07, 'B', 'U', 'S', 'L', 'O', 'G', 'I', 'C',
918 ' ', 'B', 'T', '-', '9', '3', '0',
919 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
920 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
923 static unsigned short FPT_default_intena = 0;
925 static void (*FPT_s_PhaseTbl[8]) (unsigned long, unsigned char) = {
928 /*---------------------------------------------------------------------
930 * Function: FlashPoint_ProbeHostAdapter
932 * Description: Setup and/or Search for cards and return info to caller.
934 *---------------------------------------------------------------------*/
936 static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo)
938 static unsigned char first_time = 1;
940 unsigned char i, j, id, ScamFlg;
941 unsigned short temp, temp2, temp3, temp4, temp5, temp6;
942 unsigned long ioport;
943 struct nvram_info *pCurrNvRam;
945 ioport = pCardInfo->si_baseaddr;
947 if (RD_HARPOON(ioport + hp_vendor_id_0) != ORION_VEND_0)
948 return (int)FAILURE;
950 if ((RD_HARPOON(ioport + hp_vendor_id_1) != ORION_VEND_1))
951 return (int)FAILURE;
953 if ((RD_HARPOON(ioport + hp_device_id_0) != ORION_DEV_0))
954 return (int)FAILURE;
956 if ((RD_HARPOON(ioport + hp_device_id_1) != ORION_DEV_1))
957 return (int)FAILURE;
959 if (RD_HARPOON(ioport + hp_rev_num) != 0x0f) {
961 /* For new Harpoon then check for sub_device ID LSB
962 the bits(0-3) must be all ZERO for compatible with
963 current version of SCCBMgr, else skip this Harpoon
964 device. */
966 if (RD_HARPOON(ioport + hp_sub_device_id_0) & 0x0f)
967 return (int)FAILURE;
970 if (first_time) {
971 FPT_SccbMgrTableInitAll();
972 first_time = 0;
973 FPT_mbCards = 0;
976 if (FPT_RdStack(ioport, 0) != 0x00) {
977 if (FPT_ChkIfChipInitialized(ioport) == 0) {
978 pCurrNvRam = NULL;
979 WR_HARPOON(ioport + hp_semaphore, 0x00);
980 FPT_XbowInit(ioport, 0); /*Must Init the SCSI before attempting */
981 FPT_DiagEEPROM(ioport);
982 } else {
983 if (FPT_mbCards < MAX_MB_CARDS) {
984 pCurrNvRam = &FPT_nvRamInfo[FPT_mbCards];
985 FPT_mbCards++;
986 pCurrNvRam->niBaseAddr = ioport;
987 FPT_RNVRamData(pCurrNvRam);
988 } else
989 return (int)FAILURE;
991 } else
992 pCurrNvRam = NULL;
994 WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
995 WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
997 if (pCurrNvRam)
998 pCardInfo->si_id = pCurrNvRam->niAdapId;
999 else
1000 pCardInfo->si_id =
1001 (unsigned
1002 char)(FPT_utilEERead(ioport,
1003 (ADAPTER_SCSI_ID /
1004 2)) & (unsigned char)0x0FF);
1006 pCardInfo->si_lun = 0x00;
1007 pCardInfo->si_fw_revision = ORION_FW_REV;
1008 temp2 = 0x0000;
1009 temp3 = 0x0000;
1010 temp4 = 0x0000;
1011 temp5 = 0x0000;
1012 temp6 = 0x0000;
1014 for (id = 0; id < (16 / 2); id++) {
1016 if (pCurrNvRam) {
1017 temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
1018 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1019 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1020 } else
1021 temp =
1022 FPT_utilEERead(ioport,
1023 (unsigned short)((SYNC_RATE_TBL / 2)
1024 + id));
1026 for (i = 0; i < 2; temp >>= 8, i++) {
1028 temp2 >>= 1;
1029 temp3 >>= 1;
1030 temp4 >>= 1;
1031 temp5 >>= 1;
1032 temp6 >>= 1;
1033 switch (temp & 0x3) {
1034 case AUTO_RATE_20: /* Synchronous, 20 mega-transfers/second */
1035 temp6 |= 0x8000; /* Fall through */
1036 case AUTO_RATE_10: /* Synchronous, 10 mega-transfers/second */
1037 temp5 |= 0x8000; /* Fall through */
1038 case AUTO_RATE_05: /* Synchronous, 5 mega-transfers/second */
1039 temp2 |= 0x8000; /* Fall through */
1040 case AUTO_RATE_00: /* Asynchronous */
1041 break;
1044 if (temp & DISC_ENABLE_BIT)
1045 temp3 |= 0x8000;
1047 if (temp & WIDE_NEGO_BIT)
1048 temp4 |= 0x8000;
1053 pCardInfo->si_per_targ_init_sync = temp2;
1054 pCardInfo->si_per_targ_no_disc = temp3;
1055 pCardInfo->si_per_targ_wide_nego = temp4;
1056 pCardInfo->si_per_targ_fast_nego = temp5;
1057 pCardInfo->si_per_targ_ultra_nego = temp6;
1059 if (pCurrNvRam)
1060 i = pCurrNvRam->niSysConf;
1061 else
1062 i = (unsigned
1063 char)(FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)));
1065 if (pCurrNvRam)
1066 ScamFlg = pCurrNvRam->niScamConf;
1067 else
1068 ScamFlg =
1069 (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
1071 pCardInfo->si_flags = 0x0000;
1073 if (i & 0x01)
1074 pCardInfo->si_flags |= SCSI_PARITY_ENA;
1076 if (!(i & 0x02))
1077 pCardInfo->si_flags |= SOFT_RESET;
1079 if (i & 0x10)
1080 pCardInfo->si_flags |= EXTENDED_TRANSLATION;
1082 if (ScamFlg & SCAM_ENABLED)
1083 pCardInfo->si_flags |= FLAG_SCAM_ENABLED;
1085 if (ScamFlg & SCAM_LEVEL2)
1086 pCardInfo->si_flags |= FLAG_SCAM_LEVEL2;
1088 j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1089 if (i & 0x04) {
1090 j |= SCSI_TERM_ENA_L;
1092 WR_HARPOON(ioport + hp_bm_ctrl, j);
1094 j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1095 if (i & 0x08) {
1096 j |= SCSI_TERM_ENA_H;
1098 WR_HARPOON(ioport + hp_ee_ctrl, j);
1100 if (!(RD_HARPOON(ioport + hp_page_ctrl) & NARROW_SCSI_CARD))
1102 pCardInfo->si_flags |= SUPPORT_16TAR_32LUN;
1104 pCardInfo->si_card_family = HARPOON_FAMILY;
1105 pCardInfo->si_bustype = BUSTYPE_PCI;
1107 if (pCurrNvRam) {
1108 pCardInfo->si_card_model[0] = '9';
1109 switch (pCurrNvRam->niModel & 0x0f) {
1110 case MODEL_LT:
1111 pCardInfo->si_card_model[1] = '3';
1112 pCardInfo->si_card_model[2] = '0';
1113 break;
1114 case MODEL_LW:
1115 pCardInfo->si_card_model[1] = '5';
1116 pCardInfo->si_card_model[2] = '0';
1117 break;
1118 case MODEL_DL:
1119 pCardInfo->si_card_model[1] = '3';
1120 pCardInfo->si_card_model[2] = '2';
1121 break;
1122 case MODEL_DW:
1123 pCardInfo->si_card_model[1] = '5';
1124 pCardInfo->si_card_model[2] = '2';
1125 break;
1127 } else {
1128 temp = FPT_utilEERead(ioport, (MODEL_NUMB_0 / 2));
1129 pCardInfo->si_card_model[0] = (unsigned char)(temp >> 8);
1130 temp = FPT_utilEERead(ioport, (MODEL_NUMB_2 / 2));
1132 pCardInfo->si_card_model[1] = (unsigned char)(temp & 0x00FF);
1133 pCardInfo->si_card_model[2] = (unsigned char)(temp >> 8);
1136 if (pCardInfo->si_card_model[1] == '3') {
1137 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1138 pCardInfo->si_flags |= LOW_BYTE_TERM;
1139 } else if (pCardInfo->si_card_model[2] == '0') {
1140 temp = RD_HARPOON(ioport + hp_xfer_pad);
1141 WR_HARPOON(ioport + hp_xfer_pad, (temp & ~BIT(4)));
1142 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1143 pCardInfo->si_flags |= LOW_BYTE_TERM;
1144 WR_HARPOON(ioport + hp_xfer_pad, (temp | BIT(4)));
1145 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1146 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1147 WR_HARPOON(ioport + hp_xfer_pad, temp);
1148 } else {
1149 temp = RD_HARPOON(ioport + hp_ee_ctrl);
1150 temp2 = RD_HARPOON(ioport + hp_xfer_pad);
1151 WR_HARPOON(ioport + hp_ee_ctrl, (temp | SEE_CS));
1152 WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
1153 temp3 = 0;
1154 for (i = 0; i < 8; i++) {
1155 temp3 <<= 1;
1156 if (!(RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)))
1157 temp3 |= 1;
1158 WR_HARPOON(ioport + hp_xfer_pad, (temp2 & ~BIT(4)));
1159 WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
1161 WR_HARPOON(ioport + hp_ee_ctrl, temp);
1162 WR_HARPOON(ioport + hp_xfer_pad, temp2);
1163 if (!(temp3 & BIT(7)))
1164 pCardInfo->si_flags |= LOW_BYTE_TERM;
1165 if (!(temp3 & BIT(6)))
1166 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1169 ARAM_ACCESS(ioport);
1171 for (i = 0; i < 4; i++) {
1173 pCardInfo->si_XlatInfo[i] =
1174 RD_HARPOON(ioport + hp_aramBase + BIOS_DATA_OFFSET + i);
1177 /* return with -1 if no sort, else return with
1178 logical card number sorted by BIOS (zero-based) */
1180 pCardInfo->si_relative_cardnum =
1181 (unsigned
1182 char)(RD_HARPOON(ioport + hp_aramBase + BIOS_RELATIVE_CARD) - 1);
1184 SGRAM_ACCESS(ioport);
1186 FPT_s_PhaseTbl[0] = FPT_phaseDataOut;
1187 FPT_s_PhaseTbl[1] = FPT_phaseDataIn;
1188 FPT_s_PhaseTbl[2] = FPT_phaseIllegal;
1189 FPT_s_PhaseTbl[3] = FPT_phaseIllegal;
1190 FPT_s_PhaseTbl[4] = FPT_phaseCommand;
1191 FPT_s_PhaseTbl[5] = FPT_phaseStatus;
1192 FPT_s_PhaseTbl[6] = FPT_phaseMsgOut;
1193 FPT_s_PhaseTbl[7] = FPT_phaseMsgIn;
1195 pCardInfo->si_present = 0x01;
1197 return 0;
1200 /*---------------------------------------------------------------------
1202 * Function: FlashPoint_HardwareResetHostAdapter
1204 * Description: Setup adapter for normal operation (hard reset).
1206 *---------------------------------------------------------------------*/
1208 static unsigned long FlashPoint_HardwareResetHostAdapter(struct sccb_mgr_info
1209 *pCardInfo)
1211 struct sccb_card *CurrCard = NULL;
1212 struct nvram_info *pCurrNvRam;
1213 unsigned char i, j, thisCard, ScamFlg;
1214 unsigned short temp, sync_bit_map, id;
1215 unsigned long ioport;
1217 ioport = pCardInfo->si_baseaddr;
1219 for (thisCard = 0; thisCard <= MAX_CARDS; thisCard++) {
1221 if (thisCard == MAX_CARDS) {
1223 return FAILURE;
1226 if (FPT_BL_Card[thisCard].ioPort == ioport) {
1228 CurrCard = &FPT_BL_Card[thisCard];
1229 FPT_SccbMgrTableInitCard(CurrCard, thisCard);
1230 break;
1233 else if (FPT_BL_Card[thisCard].ioPort == 0x00) {
1235 FPT_BL_Card[thisCard].ioPort = ioport;
1236 CurrCard = &FPT_BL_Card[thisCard];
1238 if (FPT_mbCards)
1239 for (i = 0; i < FPT_mbCards; i++) {
1240 if (CurrCard->ioPort ==
1241 FPT_nvRamInfo[i].niBaseAddr)
1242 CurrCard->pNvRamInfo =
1243 &FPT_nvRamInfo[i];
1245 FPT_SccbMgrTableInitCard(CurrCard, thisCard);
1246 CurrCard->cardIndex = thisCard;
1247 CurrCard->cardInfo = pCardInfo;
1249 break;
1253 pCurrNvRam = CurrCard->pNvRamInfo;
1255 if (pCurrNvRam) {
1256 ScamFlg = pCurrNvRam->niScamConf;
1257 } else {
1258 ScamFlg =
1259 (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
1262 FPT_BusMasterInit(ioport);
1263 FPT_XbowInit(ioport, ScamFlg);
1265 FPT_autoLoadDefaultMap(ioport);
1267 for (i = 0, id = 0x01; i != pCardInfo->si_id; i++, id <<= 1) {
1270 WR_HARPOON(ioport + hp_selfid_0, id);
1271 WR_HARPOON(ioport + hp_selfid_1, 0x00);
1272 WR_HARPOON(ioport + hp_arb_id, pCardInfo->si_id);
1273 CurrCard->ourId = pCardInfo->si_id;
1275 i = (unsigned char)pCardInfo->si_flags;
1276 if (i & SCSI_PARITY_ENA)
1277 WR_HARPOON(ioport + hp_portctrl_1, (HOST_MODE8 | CHK_SCSI_P));
1279 j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1280 if (i & LOW_BYTE_TERM)
1281 j |= SCSI_TERM_ENA_L;
1282 WR_HARPOON(ioport + hp_bm_ctrl, j);
1284 j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1285 if (i & HIGH_BYTE_TERM)
1286 j |= SCSI_TERM_ENA_H;
1287 WR_HARPOON(ioport + hp_ee_ctrl, j);
1289 if (!(pCardInfo->si_flags & SOFT_RESET)) {
1291 FPT_sresb(ioport, thisCard);
1293 FPT_scini(thisCard, pCardInfo->si_id, 0);
1296 if (pCardInfo->si_flags & POST_ALL_UNDERRRUNS)
1297 CurrCard->globalFlags |= F_NO_FILTER;
1299 if (pCurrNvRam) {
1300 if (pCurrNvRam->niSysConf & 0x10)
1301 CurrCard->globalFlags |= F_GREEN_PC;
1302 } else {
1303 if (FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)) & GREEN_PC_ENA)
1304 CurrCard->globalFlags |= F_GREEN_PC;
1307 /* Set global flag to indicate Re-Negotiation to be done on all
1308 ckeck condition */
1309 if (pCurrNvRam) {
1310 if (pCurrNvRam->niScsiConf & 0x04)
1311 CurrCard->globalFlags |= F_DO_RENEGO;
1312 } else {
1313 if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & RENEGO_ENA)
1314 CurrCard->globalFlags |= F_DO_RENEGO;
1317 if (pCurrNvRam) {
1318 if (pCurrNvRam->niScsiConf & 0x08)
1319 CurrCard->globalFlags |= F_CONLUN_IO;
1320 } else {
1321 if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & CONNIO_ENA)
1322 CurrCard->globalFlags |= F_CONLUN_IO;
1325 temp = pCardInfo->si_per_targ_no_disc;
1327 for (i = 0, id = 1; i < MAX_SCSI_TAR; i++, id <<= 1) {
1329 if (temp & id)
1330 FPT_sccbMgrTbl[thisCard][i].TarStatus |= TAR_ALLOW_DISC;
1333 sync_bit_map = 0x0001;
1335 for (id = 0; id < (MAX_SCSI_TAR / 2); id++) {
1337 if (pCurrNvRam) {
1338 temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
1339 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1340 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1341 } else
1342 temp =
1343 FPT_utilEERead(ioport,
1344 (unsigned short)((SYNC_RATE_TBL / 2)
1345 + id));
1347 for (i = 0; i < 2; temp >>= 8, i++) {
1349 if (pCardInfo->si_per_targ_init_sync & sync_bit_map) {
1351 FPT_sccbMgrTbl[thisCard][id * 2 +
1352 i].TarEEValue =
1353 (unsigned char)temp;
1356 else {
1357 FPT_sccbMgrTbl[thisCard][id * 2 +
1358 i].TarStatus |=
1359 SYNC_SUPPORTED;
1360 FPT_sccbMgrTbl[thisCard][id * 2 +
1361 i].TarEEValue =
1362 (unsigned char)(temp & ~EE_SYNC_MASK);
1365 /* if ((pCardInfo->si_per_targ_wide_nego & sync_bit_map) ||
1366 (id*2+i >= 8)){
1368 if (pCardInfo->si_per_targ_wide_nego & sync_bit_map) {
1370 FPT_sccbMgrTbl[thisCard][id * 2 +
1371 i].TarEEValue |=
1372 EE_WIDE_SCSI;
1376 else { /* NARROW SCSI */
1377 FPT_sccbMgrTbl[thisCard][id * 2 +
1378 i].TarStatus |=
1379 WIDE_NEGOCIATED;
1382 sync_bit_map <<= 1;
1387 WR_HARPOON((ioport + hp_semaphore),
1388 (unsigned char)(RD_HARPOON((ioport + hp_semaphore)) |
1389 SCCB_MGR_PRESENT));
1391 return (unsigned long)CurrCard;
1394 static void FlashPoint_ReleaseHostAdapter(unsigned long pCurrCard)
1396 unsigned char i;
1397 unsigned long portBase;
1398 unsigned long regOffset;
1399 unsigned long scamData;
1400 unsigned long *pScamTbl;
1401 struct nvram_info *pCurrNvRam;
1403 pCurrNvRam = ((struct sccb_card *)pCurrCard)->pNvRamInfo;
1405 if (pCurrNvRam) {
1406 FPT_WrStack(pCurrNvRam->niBaseAddr, 0, pCurrNvRam->niModel);
1407 FPT_WrStack(pCurrNvRam->niBaseAddr, 1, pCurrNvRam->niSysConf);
1408 FPT_WrStack(pCurrNvRam->niBaseAddr, 2, pCurrNvRam->niScsiConf);
1409 FPT_WrStack(pCurrNvRam->niBaseAddr, 3, pCurrNvRam->niScamConf);
1410 FPT_WrStack(pCurrNvRam->niBaseAddr, 4, pCurrNvRam->niAdapId);
1412 for (i = 0; i < MAX_SCSI_TAR / 2; i++)
1413 FPT_WrStack(pCurrNvRam->niBaseAddr,
1414 (unsigned char)(i + 5),
1415 pCurrNvRam->niSyncTbl[i]);
1417 portBase = pCurrNvRam->niBaseAddr;
1419 for (i = 0; i < MAX_SCSI_TAR; i++) {
1420 regOffset = hp_aramBase + 64 + i * 4;
1421 pScamTbl = (unsigned long *)&pCurrNvRam->niScamTbl[i];
1422 scamData = *pScamTbl;
1423 WR_HARP32(portBase, regOffset, scamData);
1426 } else {
1427 FPT_WrStack(((struct sccb_card *)pCurrCard)->ioPort, 0, 0);
1431 static void FPT_RNVRamData(struct nvram_info *pNvRamInfo)
1433 unsigned char i;
1434 unsigned long portBase;
1435 unsigned long regOffset;
1436 unsigned long scamData;
1437 unsigned long *pScamTbl;
1439 pNvRamInfo->niModel = FPT_RdStack(pNvRamInfo->niBaseAddr, 0);
1440 pNvRamInfo->niSysConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 1);
1441 pNvRamInfo->niScsiConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 2);
1442 pNvRamInfo->niScamConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 3);
1443 pNvRamInfo->niAdapId = FPT_RdStack(pNvRamInfo->niBaseAddr, 4);
1445 for (i = 0; i < MAX_SCSI_TAR / 2; i++)
1446 pNvRamInfo->niSyncTbl[i] =
1447 FPT_RdStack(pNvRamInfo->niBaseAddr, (unsigned char)(i + 5));
1449 portBase = pNvRamInfo->niBaseAddr;
1451 for (i = 0; i < MAX_SCSI_TAR; i++) {
1452 regOffset = hp_aramBase + 64 + i * 4;
1453 RD_HARP32(portBase, regOffset, scamData);
1454 pScamTbl = (unsigned long *)&pNvRamInfo->niScamTbl[i];
1455 *pScamTbl = scamData;
1460 static unsigned char FPT_RdStack(unsigned long portBase, unsigned char index)
1462 WR_HARPOON(portBase + hp_stack_addr, index);
1463 return RD_HARPOON(portBase + hp_stack_data);
1466 static void FPT_WrStack(unsigned long portBase, unsigned char index,
1467 unsigned char data)
1469 WR_HARPOON(portBase + hp_stack_addr, index);
1470 WR_HARPOON(portBase + hp_stack_data, data);
1473 static unsigned char FPT_ChkIfChipInitialized(unsigned long ioPort)
1475 if ((RD_HARPOON(ioPort + hp_arb_id) & 0x0f) != FPT_RdStack(ioPort, 4))
1476 return 0;
1477 if ((RD_HARPOON(ioPort + hp_clkctrl_0) & CLKCTRL_DEFAULT)
1478 != CLKCTRL_DEFAULT)
1479 return 0;
1480 if ((RD_HARPOON(ioPort + hp_seltimeout) == TO_250ms) ||
1481 (RD_HARPOON(ioPort + hp_seltimeout) == TO_290ms))
1482 return 1;
1483 return 0;
1487 /*---------------------------------------------------------------------
1489 * Function: FlashPoint_StartCCB
1491 * Description: Start a command pointed to by p_Sccb. When the
1492 * command is completed it will be returned via the
1493 * callback function.
1495 *---------------------------------------------------------------------*/
1496 static void FlashPoint_StartCCB(unsigned long pCurrCard, struct sccb *p_Sccb)
1498 unsigned long ioport;
1499 unsigned char thisCard, lun;
1500 struct sccb *pSaveSccb;
1501 CALL_BK_FN callback;
1503 thisCard = ((struct sccb_card *)pCurrCard)->cardIndex;
1504 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1506 if ((p_Sccb->TargID > MAX_SCSI_TAR) || (p_Sccb->Lun > MAX_LUN)) {
1508 p_Sccb->HostStatus = SCCB_COMPLETE;
1509 p_Sccb->SccbStatus = SCCB_ERROR;
1510 callback = (CALL_BK_FN) p_Sccb->SccbCallback;
1511 if (callback)
1512 callback(p_Sccb);
1514 return;
1517 FPT_sinits(p_Sccb, thisCard);
1519 if (!((struct sccb_card *)pCurrCard)->cmdCounter) {
1520 WR_HARPOON(ioport + hp_semaphore,
1521 (RD_HARPOON(ioport + hp_semaphore)
1522 | SCCB_MGR_ACTIVE));
1524 if (((struct sccb_card *)pCurrCard)->globalFlags & F_GREEN_PC) {
1525 WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
1526 WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
1530 ((struct sccb_card *)pCurrCard)->cmdCounter++;
1532 if (RD_HARPOON(ioport + hp_semaphore) & BIOS_IN_USE) {
1534 WR_HARPOON(ioport + hp_semaphore,
1535 (RD_HARPOON(ioport + hp_semaphore)
1536 | TICKLE_ME));
1537 if (p_Sccb->OperationCode == RESET_COMMAND) {
1538 pSaveSccb =
1539 ((struct sccb_card *)pCurrCard)->currentSCCB;
1540 ((struct sccb_card *)pCurrCard)->currentSCCB = p_Sccb;
1541 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
1542 ((struct sccb_card *)pCurrCard)->currentSCCB =
1543 pSaveSccb;
1544 } else {
1545 FPT_queueAddSccb(p_Sccb, thisCard);
1549 else if ((RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
1551 if (p_Sccb->OperationCode == RESET_COMMAND) {
1552 pSaveSccb =
1553 ((struct sccb_card *)pCurrCard)->currentSCCB;
1554 ((struct sccb_card *)pCurrCard)->currentSCCB = p_Sccb;
1555 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
1556 ((struct sccb_card *)pCurrCard)->currentSCCB =
1557 pSaveSccb;
1558 } else {
1559 FPT_queueAddSccb(p_Sccb, thisCard);
1563 else {
1565 MDISABLE_INT(ioport);
1567 if ((((struct sccb_card *)pCurrCard)->globalFlags & F_CONLUN_IO)
1569 ((FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].
1570 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
1571 lun = p_Sccb->Lun;
1572 else
1573 lun = 0;
1574 if ((((struct sccb_card *)pCurrCard)->currentSCCB == NULL) &&
1575 (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarSelQ_Cnt == 0)
1576 && (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarLUNBusy[lun]
1577 == 0)) {
1579 ((struct sccb_card *)pCurrCard)->currentSCCB = p_Sccb;
1580 FPT_ssel(p_Sccb->SccbIOPort, thisCard);
1583 else {
1585 if (p_Sccb->OperationCode == RESET_COMMAND) {
1586 pSaveSccb =
1587 ((struct sccb_card *)pCurrCard)->
1588 currentSCCB;
1589 ((struct sccb_card *)pCurrCard)->currentSCCB =
1590 p_Sccb;
1591 FPT_queueSelectFail(&FPT_BL_Card[thisCard],
1592 thisCard);
1593 ((struct sccb_card *)pCurrCard)->currentSCCB =
1594 pSaveSccb;
1595 } else {
1596 FPT_queueAddSccb(p_Sccb, thisCard);
1600 MENABLE_INT(ioport);
1605 /*---------------------------------------------------------------------
1607 * Function: FlashPoint_AbortCCB
1609 * Description: Abort the command pointed to by p_Sccb. When the
1610 * command is completed it will be returned via the
1611 * callback function.
1613 *---------------------------------------------------------------------*/
1614 static int FlashPoint_AbortCCB(unsigned long pCurrCard, struct sccb *p_Sccb)
1616 unsigned long ioport;
1618 unsigned char thisCard;
1619 CALL_BK_FN callback;
1620 unsigned char TID;
1621 struct sccb *pSaveSCCB;
1622 struct sccb_mgr_tar_info *currTar_Info;
1624 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1626 thisCard = ((struct sccb_card *)pCurrCard)->cardIndex;
1628 if (!(RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
1630 if (FPT_queueFindSccb(p_Sccb, thisCard)) {
1632 ((struct sccb_card *)pCurrCard)->cmdCounter--;
1634 if (!((struct sccb_card *)pCurrCard)->cmdCounter)
1635 WR_HARPOON(ioport + hp_semaphore,
1636 (RD_HARPOON(ioport + hp_semaphore)
1637 & (unsigned
1638 char)(~(SCCB_MGR_ACTIVE |
1639 TICKLE_ME))));
1641 p_Sccb->SccbStatus = SCCB_ABORT;
1642 callback = p_Sccb->SccbCallback;
1643 callback(p_Sccb);
1645 return 0;
1648 else {
1649 if (((struct sccb_card *)pCurrCard)->currentSCCB ==
1650 p_Sccb) {
1651 p_Sccb->SccbStatus = SCCB_ABORT;
1652 return 0;
1656 else {
1658 TID = p_Sccb->TargID;
1660 if (p_Sccb->Sccb_tag) {
1661 MDISABLE_INT(ioport);
1662 if (((struct sccb_card *)pCurrCard)->
1663 discQ_Tbl[p_Sccb->Sccb_tag] ==
1664 p_Sccb) {
1665 p_Sccb->SccbStatus = SCCB_ABORT;
1666 p_Sccb->Sccb_scsistat =
1667 ABORT_ST;
1668 p_Sccb->Sccb_scsimsg =
1669 SMABORT_TAG;
1671 if (((struct sccb_card *)
1672 pCurrCard)->currentSCCB ==
1673 NULL) {
1674 ((struct sccb_card *)
1675 pCurrCard)->
1676 currentSCCB = p_Sccb;
1677 FPT_ssel(ioport,
1678 thisCard);
1679 } else {
1680 pSaveSCCB =
1681 ((struct sccb_card
1682 *)pCurrCard)->
1683 currentSCCB;
1684 ((struct sccb_card *)
1685 pCurrCard)->
1686 currentSCCB = p_Sccb;
1687 FPT_queueSelectFail((struct sccb_card *)pCurrCard, thisCard);
1688 ((struct sccb_card *)
1689 pCurrCard)->
1690 currentSCCB = pSaveSCCB;
1693 MENABLE_INT(ioport);
1694 return 0;
1695 } else {
1696 currTar_Info =
1697 &FPT_sccbMgrTbl[thisCard][p_Sccb->
1698 TargID];
1700 if (FPT_BL_Card[thisCard].
1701 discQ_Tbl[currTar_Info->
1702 LunDiscQ_Idx[p_Sccb->Lun]]
1703 == p_Sccb) {
1704 p_Sccb->SccbStatus = SCCB_ABORT;
1705 return 0;
1711 return -1;
1714 /*---------------------------------------------------------------------
1716 * Function: FlashPoint_InterruptPending
1718 * Description: Do a quick check to determine if there is a pending
1719 * interrupt for this card and disable the IRQ Pin if so.
1721 *---------------------------------------------------------------------*/
1722 static unsigned char FlashPoint_InterruptPending(unsigned long pCurrCard)
1724 unsigned long ioport;
1726 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1728 if (RD_HARPOON(ioport + hp_int_status) & INT_ASSERTED) {
1729 return 1;
1732 else
1734 return 0;
1737 /*---------------------------------------------------------------------
1739 * Function: FlashPoint_HandleInterrupt
1741 * Description: This is our entry point when an interrupt is generated
1742 * by the card and the upper level driver passes it on to
1743 * us.
1745 *---------------------------------------------------------------------*/
1746 static int FlashPoint_HandleInterrupt(unsigned long pCurrCard)
1748 struct sccb *currSCCB;
1749 unsigned char thisCard, result, bm_status, bm_int_st;
1750 unsigned short hp_int;
1751 unsigned char i, target;
1752 unsigned long ioport;
1754 thisCard = ((struct sccb_card *)pCurrCard)->cardIndex;
1755 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1757 MDISABLE_INT(ioport);
1759 if ((bm_int_st = RD_HARPOON(ioport + hp_int_status)) & EXT_STATUS_ON)
1760 bm_status =
1761 RD_HARPOON(ioport +
1762 hp_ext_status) & (unsigned char)BAD_EXT_STATUS;
1763 else
1764 bm_status = 0;
1766 WR_HARPOON(ioport + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
1768 while ((hp_int =
1769 RDW_HARPOON((ioport +
1770 hp_intstat)) & FPT_default_intena) | bm_status) {
1772 currSCCB = ((struct sccb_card *)pCurrCard)->currentSCCB;
1774 if (hp_int & (FIFO | TIMEOUT | RESET | SCAM_SEL) || bm_status) {
1775 result =
1776 FPT_SccbMgr_bad_isr(ioport, thisCard,
1777 ((struct sccb_card *)pCurrCard),
1778 hp_int);
1779 WRW_HARPOON((ioport + hp_intstat),
1780 (FIFO | TIMEOUT | RESET | SCAM_SEL));
1781 bm_status = 0;
1783 if (result) {
1785 MENABLE_INT(ioport);
1786 return result;
1790 else if (hp_int & ICMD_COMP) {
1792 if (!(hp_int & BUS_FREE)) {
1793 /* Wait for the BusFree before starting a new command. We
1794 must also check for being reselected since the BusFree
1795 may not show up if another device reselects us in 1.5us or
1796 less. SRR Wednesday, 3/8/1995.
1798 while (!
1799 (RDW_HARPOON((ioport + hp_intstat)) &
1800 (BUS_FREE | RSEL))) ;
1803 if (((struct sccb_card *)pCurrCard)->
1804 globalFlags & F_HOST_XFER_ACT)
1806 FPT_phaseChkFifo(ioport, thisCard);
1808 /* WRW_HARPOON((ioport+hp_intstat),
1809 (BUS_FREE | ICMD_COMP | ITAR_DISC | XFER_CNT_0));
1812 WRW_HARPOON((ioport + hp_intstat), CLR_ALL_INT_1);
1814 FPT_autoCmdCmplt(ioport, thisCard);
1818 else if (hp_int & ITAR_DISC) {
1820 if (((struct sccb_card *)pCurrCard)->
1821 globalFlags & F_HOST_XFER_ACT) {
1823 FPT_phaseChkFifo(ioport, thisCard);
1827 if (RD_HARPOON(ioport + hp_gp_reg_1) == SMSAVE_DATA_PTR) {
1829 WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
1830 currSCCB->Sccb_XferState |= F_NO_DATA_YET;
1832 currSCCB->Sccb_savedATC = currSCCB->Sccb_ATC;
1835 currSCCB->Sccb_scsistat = DISCONNECT_ST;
1836 FPT_queueDisconnect(currSCCB, thisCard);
1838 /* Wait for the BusFree before starting a new command. We
1839 must also check for being reselected since the BusFree
1840 may not show up if another device reselects us in 1.5us or
1841 less. SRR Wednesday, 3/8/1995.
1843 while (!
1844 (RDW_HARPOON((ioport + hp_intstat)) &
1845 (BUS_FREE | RSEL))
1846 && !((RDW_HARPOON((ioport + hp_intstat)) & PHASE)
1847 && RD_HARPOON((ioport + hp_scsisig)) ==
1848 (SCSI_BSY | SCSI_REQ | SCSI_CD | SCSI_MSG |
1849 SCSI_IOBIT))) ;
1852 The additional loop exit condition above detects a timing problem
1853 with the revision D/E harpoon chips. The caller should reset the
1854 host adapter to recover when 0xFE is returned.
1856 if (!
1857 (RDW_HARPOON((ioport + hp_intstat)) &
1858 (BUS_FREE | RSEL))) {
1859 MENABLE_INT(ioport);
1860 return 0xFE;
1863 WRW_HARPOON((ioport + hp_intstat),
1864 (BUS_FREE | ITAR_DISC));
1866 ((struct sccb_card *)pCurrCard)->globalFlags |=
1867 F_NEW_SCCB_CMD;
1871 else if (hp_int & RSEL) {
1873 WRW_HARPOON((ioport + hp_intstat),
1874 (PROG_HLT | RSEL | PHASE | BUS_FREE));
1876 if (RDW_HARPOON((ioport + hp_intstat)) & ITAR_DISC) {
1877 if (((struct sccb_card *)pCurrCard)->
1878 globalFlags & F_HOST_XFER_ACT) {
1879 FPT_phaseChkFifo(ioport, thisCard);
1882 if (RD_HARPOON(ioport + hp_gp_reg_1) ==
1883 SMSAVE_DATA_PTR) {
1884 WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
1885 currSCCB->Sccb_XferState |=
1886 F_NO_DATA_YET;
1887 currSCCB->Sccb_savedATC =
1888 currSCCB->Sccb_ATC;
1891 WRW_HARPOON((ioport + hp_intstat),
1892 (BUS_FREE | ITAR_DISC));
1893 currSCCB->Sccb_scsistat = DISCONNECT_ST;
1894 FPT_queueDisconnect(currSCCB, thisCard);
1897 FPT_sres(ioport, thisCard,
1898 ((struct sccb_card *)pCurrCard));
1899 FPT_phaseDecode(ioport, thisCard);
1903 else if ((hp_int & IDO_STRT) && (!(hp_int & BUS_FREE))) {
1905 WRW_HARPOON((ioport + hp_intstat),
1906 (IDO_STRT | XFER_CNT_0));
1907 FPT_phaseDecode(ioport, thisCard);
1911 else if ((hp_int & IUNKWN) || (hp_int & PROG_HLT)) {
1912 WRW_HARPOON((ioport + hp_intstat),
1913 (PHASE | IUNKWN | PROG_HLT));
1914 if ((RD_HARPOON(ioport + hp_prgmcnt_0) & (unsigned char)
1915 0x3f) < (unsigned char)SELCHK) {
1916 FPT_phaseDecode(ioport, thisCard);
1917 } else {
1918 /* Harpoon problem some SCSI target device respond to selection
1919 with short BUSY pulse (<400ns) this will make the Harpoon is not able
1920 to latch the correct Target ID into reg. x53.
1921 The work around require to correct this reg. But when write to this
1922 reg. (0x53) also increment the FIFO write addr reg (0x6f), thus we
1923 need to read this reg first then restore it later. After update to 0x53 */
1925 i = (unsigned
1926 char)(RD_HARPOON(ioport + hp_fifowrite));
1927 target =
1928 (unsigned
1929 char)(RD_HARPOON(ioport + hp_gp_reg_3));
1930 WR_HARPOON(ioport + hp_xfer_pad,
1931 (unsigned char)ID_UNLOCK);
1932 WR_HARPOON(ioport + hp_select_id,
1933 (unsigned char)(target | target <<
1934 4));
1935 WR_HARPOON(ioport + hp_xfer_pad,
1936 (unsigned char)0x00);
1937 WR_HARPOON(ioport + hp_fifowrite, i);
1938 WR_HARPOON(ioport + hp_autostart_3,
1939 (AUTO_IMMED + TAG_STRT));
1943 else if (hp_int & XFER_CNT_0) {
1945 WRW_HARPOON((ioport + hp_intstat), XFER_CNT_0);
1947 FPT_schkdd(ioport, thisCard);
1951 else if (hp_int & BUS_FREE) {
1953 WRW_HARPOON((ioport + hp_intstat), BUS_FREE);
1955 if (((struct sccb_card *)pCurrCard)->
1956 globalFlags & F_HOST_XFER_ACT) {
1958 FPT_hostDataXferAbort(ioport, thisCard,
1959 currSCCB);
1962 FPT_phaseBusFree(ioport, thisCard);
1965 else if (hp_int & ITICKLE) {
1967 WRW_HARPOON((ioport + hp_intstat), ITICKLE);
1968 ((struct sccb_card *)pCurrCard)->globalFlags |=
1969 F_NEW_SCCB_CMD;
1972 if (((struct sccb_card *)pCurrCard)->
1973 globalFlags & F_NEW_SCCB_CMD) {
1975 ((struct sccb_card *)pCurrCard)->globalFlags &=
1976 ~F_NEW_SCCB_CMD;
1978 if (((struct sccb_card *)pCurrCard)->currentSCCB ==
1979 NULL) {
1981 FPT_queueSearchSelect(((struct sccb_card *)
1982 pCurrCard), thisCard);
1985 if (((struct sccb_card *)pCurrCard)->currentSCCB !=
1986 NULL) {
1987 ((struct sccb_card *)pCurrCard)->globalFlags &=
1988 ~F_NEW_SCCB_CMD;
1989 FPT_ssel(ioport, thisCard);
1992 break;
1996 } /*end while */
1998 MENABLE_INT(ioport);
2000 return 0;
2003 /*---------------------------------------------------------------------
2005 * Function: Sccb_bad_isr
2007 * Description: Some type of interrupt has occurred which is slightly
2008 * out of the ordinary. We will now decode it fully, in
2009 * this routine. This is broken up in an attempt to save
2010 * processing time.
2012 *---------------------------------------------------------------------*/
2013 static unsigned char FPT_SccbMgr_bad_isr(unsigned long p_port,
2014 unsigned char p_card,
2015 struct sccb_card *pCurrCard,
2016 unsigned short p_int)
2018 unsigned char temp, ScamFlg;
2019 struct sccb_mgr_tar_info *currTar_Info;
2020 struct nvram_info *pCurrNvRam;
2022 if (RD_HARPOON(p_port + hp_ext_status) &
2023 (BM_FORCE_OFF | PCI_DEV_TMOUT | BM_PARITY_ERR | PIO_OVERRUN)) {
2025 if (pCurrCard->globalFlags & F_HOST_XFER_ACT) {
2027 FPT_hostDataXferAbort(p_port, p_card,
2028 pCurrCard->currentSCCB);
2031 if (RD_HARPOON(p_port + hp_pci_stat_cfg) & REC_MASTER_ABORT)
2033 WR_HARPOON(p_port + hp_pci_stat_cfg,
2034 (RD_HARPOON(p_port + hp_pci_stat_cfg) &
2035 ~REC_MASTER_ABORT));
2037 WR_HARPOON(p_port + hp_host_blk_cnt, 0x00);
2041 if (pCurrCard->currentSCCB != NULL) {
2043 if (!pCurrCard->currentSCCB->HostStatus)
2044 pCurrCard->currentSCCB->HostStatus =
2045 SCCB_BM_ERR;
2047 FPT_sxfrp(p_port, p_card);
2049 temp = (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
2050 (EXT_ARB_ACK | SCSI_TERM_ENA_H));
2051 WR_HARPOON(p_port + hp_ee_ctrl,
2052 ((unsigned char)temp | SEE_MS | SEE_CS));
2053 WR_HARPOON(p_port + hp_ee_ctrl, temp);
2055 if (!
2056 (RDW_HARPOON((p_port + hp_intstat)) &
2057 (BUS_FREE | RESET))) {
2058 FPT_phaseDecode(p_port, p_card);
2063 else if (p_int & RESET) {
2065 WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
2066 WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
2067 if (pCurrCard->currentSCCB != NULL) {
2069 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
2071 FPT_hostDataXferAbort(p_port, p_card,
2072 pCurrCard->currentSCCB);
2075 DISABLE_AUTO(p_port);
2077 FPT_sresb(p_port, p_card);
2079 while (RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST) {
2082 pCurrNvRam = pCurrCard->pNvRamInfo;
2083 if (pCurrNvRam) {
2084 ScamFlg = pCurrNvRam->niScamConf;
2085 } else {
2086 ScamFlg =
2087 (unsigned char)FPT_utilEERead(p_port,
2088 SCAM_CONFIG / 2);
2091 FPT_XbowInit(p_port, ScamFlg);
2093 FPT_scini(p_card, pCurrCard->ourId, 0);
2095 return 0xFF;
2098 else if (p_int & FIFO) {
2100 WRW_HARPOON((p_port + hp_intstat), FIFO);
2102 if (pCurrCard->currentSCCB != NULL)
2103 FPT_sxfrp(p_port, p_card);
2106 else if (p_int & TIMEOUT) {
2108 DISABLE_AUTO(p_port);
2110 WRW_HARPOON((p_port + hp_intstat),
2111 (PROG_HLT | TIMEOUT | SEL | BUS_FREE | PHASE |
2112 IUNKWN));
2114 pCurrCard->currentSCCB->HostStatus = SCCB_SELECTION_TIMEOUT;
2116 currTar_Info =
2117 &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
2118 if ((pCurrCard->globalFlags & F_CONLUN_IO)
2119 && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
2120 TAG_Q_TRYING))
2121 currTar_Info->TarLUNBusy[pCurrCard->currentSCCB->Lun] =
2123 else
2124 currTar_Info->TarLUNBusy[0] = 0;
2126 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
2127 currTar_Info->TarSyncCtrl = 0;
2128 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2131 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
2132 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2135 FPT_sssyncv(p_port, pCurrCard->currentSCCB->TargID, NARROW_SCSI,
2136 currTar_Info);
2138 FPT_queueCmdComplete(pCurrCard, pCurrCard->currentSCCB, p_card);
2142 else if (p_int & SCAM_SEL) {
2144 FPT_scarb(p_port, LEVEL2_TAR);
2145 FPT_scsel(p_port);
2146 FPT_scasid(p_card, p_port);
2148 FPT_scbusf(p_port);
2150 WRW_HARPOON((p_port + hp_intstat), SCAM_SEL);
2153 return 0x00;
2156 /*---------------------------------------------------------------------
2158 * Function: SccbMgrTableInit
2160 * Description: Initialize all Sccb manager data structures.
2162 *---------------------------------------------------------------------*/
2164 static void FPT_SccbMgrTableInitAll()
2166 unsigned char thisCard;
2168 for (thisCard = 0; thisCard < MAX_CARDS; thisCard++) {
2169 FPT_SccbMgrTableInitCard(&FPT_BL_Card[thisCard], thisCard);
2171 FPT_BL_Card[thisCard].ioPort = 0x00;
2172 FPT_BL_Card[thisCard].cardInfo = NULL;
2173 FPT_BL_Card[thisCard].cardIndex = 0xFF;
2174 FPT_BL_Card[thisCard].ourId = 0x00;
2175 FPT_BL_Card[thisCard].pNvRamInfo = NULL;
2179 /*---------------------------------------------------------------------
2181 * Function: SccbMgrTableInit
2183 * Description: Initialize all Sccb manager data structures.
2185 *---------------------------------------------------------------------*/
2187 static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
2188 unsigned char p_card)
2190 unsigned char scsiID, qtag;
2192 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
2193 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2196 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
2197 FPT_sccbMgrTbl[p_card][scsiID].TarStatus = 0;
2198 FPT_sccbMgrTbl[p_card][scsiID].TarEEValue = 0;
2199 FPT_SccbMgrTableInitTarget(p_card, scsiID);
2202 pCurrCard->scanIndex = 0x00;
2203 pCurrCard->currentSCCB = NULL;
2204 pCurrCard->globalFlags = 0x00;
2205 pCurrCard->cmdCounter = 0x00;
2206 pCurrCard->tagQ_Lst = 0x01;
2207 pCurrCard->discQCount = 0;
2211 /*---------------------------------------------------------------------
2213 * Function: SccbMgrTableInit
2215 * Description: Initialize all Sccb manager data structures.
2217 *---------------------------------------------------------------------*/
2219 static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
2220 unsigned char target)
2223 unsigned char lun, qtag;
2224 struct sccb_mgr_tar_info *currTar_Info;
2226 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2228 currTar_Info->TarSelQ_Cnt = 0;
2229 currTar_Info->TarSyncCtrl = 0;
2231 currTar_Info->TarSelQ_Head = NULL;
2232 currTar_Info->TarSelQ_Tail = NULL;
2233 currTar_Info->TarTagQ_Cnt = 0;
2234 currTar_Info->TarLUN_CA = 0;
2236 for (lun = 0; lun < MAX_LUN; lun++) {
2237 currTar_Info->TarLUNBusy[lun] = 0;
2238 currTar_Info->LunDiscQ_Idx[lun] = 0;
2241 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
2242 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] != NULL) {
2243 if (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
2244 target) {
2245 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2246 FPT_BL_Card[p_card].discQCount--;
2252 /*---------------------------------------------------------------------
2254 * Function: sfetm
2256 * Description: Read in a message byte from the SCSI bus, and check
2257 * for a parity error.
2259 *---------------------------------------------------------------------*/
2261 static unsigned char FPT_sfm(unsigned long port, struct sccb *pCurrSCCB)
2263 unsigned char message;
2264 unsigned short TimeOutLoop;
2266 TimeOutLoop = 0;
2267 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2268 (TimeOutLoop++ < 20000)) {
2271 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
2273 message = RD_HARPOON(port + hp_scsidata_0);
2275 WR_HARPOON(port + hp_scsisig, SCSI_ACK + S_MSGI_PH);
2277 if (TimeOutLoop > 20000)
2278 message = 0x00; /* force message byte = 0 if Time Out on Req */
2280 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
2281 (RD_HARPOON(port + hp_addstat) & SCSI_PAR_ERR)) {
2282 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2283 WR_HARPOON(port + hp_xferstat, 0);
2284 WR_HARPOON(port + hp_fiforead, 0);
2285 WR_HARPOON(port + hp_fifowrite, 0);
2286 if (pCurrSCCB != NULL) {
2287 pCurrSCCB->Sccb_scsimsg = SMPARITY;
2289 message = 0x00;
2290 do {
2291 ACCEPT_MSG_ATN(port);
2292 TimeOutLoop = 0;
2293 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2294 (TimeOutLoop++ < 20000)) {
2296 if (TimeOutLoop > 20000) {
2297 WRW_HARPOON((port + hp_intstat), PARITY);
2298 return message;
2300 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) !=
2301 S_MSGI_PH) {
2302 WRW_HARPOON((port + hp_intstat), PARITY);
2303 return message;
2305 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
2307 RD_HARPOON(port + hp_scsidata_0);
2309 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2311 } while (1);
2314 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2315 WR_HARPOON(port + hp_xferstat, 0);
2316 WR_HARPOON(port + hp_fiforead, 0);
2317 WR_HARPOON(port + hp_fifowrite, 0);
2318 return message;
2321 /*---------------------------------------------------------------------
2323 * Function: FPT_ssel
2325 * Description: Load up automation and select target device.
2327 *---------------------------------------------------------------------*/
2329 static void FPT_ssel(unsigned long port, unsigned char p_card)
2332 unsigned char auto_loaded, i, target, *theCCB;
2334 unsigned long cdb_reg;
2335 struct sccb_card *CurrCard;
2336 struct sccb *currSCCB;
2337 struct sccb_mgr_tar_info *currTar_Info;
2338 unsigned char lastTag, lun;
2340 CurrCard = &FPT_BL_Card[p_card];
2341 currSCCB = CurrCard->currentSCCB;
2342 target = currSCCB->TargID;
2343 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2344 lastTag = CurrCard->tagQ_Lst;
2346 ARAM_ACCESS(port);
2348 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
2349 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2351 if (((CurrCard->globalFlags & F_CONLUN_IO) &&
2352 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
2354 lun = currSCCB->Lun;
2355 else
2356 lun = 0;
2358 if (CurrCard->globalFlags & F_TAG_STARTED) {
2359 if (!(currSCCB->ControlByte & F_USE_CMD_Q)) {
2360 if ((currTar_Info->TarLUN_CA == 0)
2361 && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
2362 == TAG_Q_TRYING)) {
2364 if (currTar_Info->TarTagQ_Cnt != 0) {
2365 currTar_Info->TarLUNBusy[lun] = 1;
2366 FPT_queueSelectFail(CurrCard, p_card);
2367 SGRAM_ACCESS(port);
2368 return;
2371 else {
2372 currTar_Info->TarLUNBusy[lun] = 1;
2376 /*End non-tagged */
2377 else {
2378 currTar_Info->TarLUNBusy[lun] = 1;
2382 /*!Use cmd Q Tagged */
2383 else {
2384 if (currTar_Info->TarLUN_CA == 1) {
2385 FPT_queueSelectFail(CurrCard, p_card);
2386 SGRAM_ACCESS(port);
2387 return;
2390 currTar_Info->TarLUNBusy[lun] = 1;
2392 } /*else use cmd Q tagged */
2395 /*if glob tagged started */
2396 else {
2397 currTar_Info->TarLUNBusy[lun] = 1;
2400 if ((((CurrCard->globalFlags & F_CONLUN_IO) &&
2401 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
2402 || (!(currSCCB->ControlByte & F_USE_CMD_Q)))) {
2403 if (CurrCard->discQCount >= QUEUE_DEPTH) {
2404 currTar_Info->TarLUNBusy[lun] = 1;
2405 FPT_queueSelectFail(CurrCard, p_card);
2406 SGRAM_ACCESS(port);
2407 return;
2409 for (i = 1; i < QUEUE_DEPTH; i++) {
2410 if (++lastTag >= QUEUE_DEPTH)
2411 lastTag = 1;
2412 if (CurrCard->discQ_Tbl[lastTag] == NULL) {
2413 CurrCard->tagQ_Lst = lastTag;
2414 currTar_Info->LunDiscQ_Idx[lun] = lastTag;
2415 CurrCard->discQ_Tbl[lastTag] = currSCCB;
2416 CurrCard->discQCount++;
2417 break;
2420 if (i == QUEUE_DEPTH) {
2421 currTar_Info->TarLUNBusy[lun] = 1;
2422 FPT_queueSelectFail(CurrCard, p_card);
2423 SGRAM_ACCESS(port);
2424 return;
2428 auto_loaded = 0;
2430 WR_HARPOON(port + hp_select_id, target);
2431 WR_HARPOON(port + hp_gp_reg_3, target); /* Use by new automation logic */
2433 if (currSCCB->OperationCode == RESET_COMMAND) {
2434 WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
2435 (currSCCB->
2436 Sccb_idmsg & ~DISC_PRIV)));
2438 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + NP);
2440 currSCCB->Sccb_scsimsg = SMDEV_RESET;
2442 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
2443 auto_loaded = 1;
2444 currSCCB->Sccb_scsistat = SELECT_BDR_ST;
2446 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
2447 currTar_Info->TarSyncCtrl = 0;
2448 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2451 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
2452 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2455 FPT_sssyncv(port, target, NARROW_SCSI, currTar_Info);
2456 FPT_SccbMgrTableInitTarget(p_card, target);
2460 else if (currSCCB->Sccb_scsistat == ABORT_ST) {
2461 WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
2462 (currSCCB->
2463 Sccb_idmsg & ~DISC_PRIV)));
2465 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
2467 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT +
2468 (((unsigned
2469 char)(currSCCB->
2470 ControlByte &
2471 TAG_TYPE_MASK)
2472 >> 6) | (unsigned char)
2473 0x20)));
2474 WRW_HARPOON((port + SYNC_MSGS + 2),
2475 (MPM_OP + AMSG_OUT + currSCCB->Sccb_tag));
2476 WRW_HARPOON((port + SYNC_MSGS + 4), (BRH_OP + ALWAYS + NP));
2478 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
2479 auto_loaded = 1;
2483 else if (!(currTar_Info->TarStatus & WIDE_NEGOCIATED)) {
2484 auto_loaded = FPT_siwidn(port, p_card);
2485 currSCCB->Sccb_scsistat = SELECT_WN_ST;
2488 else if (!((currTar_Info->TarStatus & TAR_SYNC_MASK)
2489 == SYNC_SUPPORTED)) {
2490 auto_loaded = FPT_sisyncn(port, p_card, 0);
2491 currSCCB->Sccb_scsistat = SELECT_SN_ST;
2494 if (!auto_loaded) {
2496 if (currSCCB->ControlByte & F_USE_CMD_Q) {
2498 CurrCard->globalFlags |= F_TAG_STARTED;
2500 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
2501 == TAG_Q_REJECT) {
2502 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2504 /* Fix up the start instruction with a jump to
2505 Non-Tag-CMD handling */
2506 WRW_HARPOON((port + ID_MSG_STRT),
2507 BRH_OP + ALWAYS + NTCMD);
2509 WRW_HARPOON((port + NON_TAG_ID_MSG),
2510 (MPM_OP + AMSG_OUT +
2511 currSCCB->Sccb_idmsg));
2513 WR_HARPOON(port + hp_autostart_3,
2514 (SELECT + SELCHK_STRT));
2516 /* Setup our STATE so we know what happend when
2517 the wheels fall off. */
2518 currSCCB->Sccb_scsistat = SELECT_ST;
2520 currTar_Info->TarLUNBusy[lun] = 1;
2523 else {
2524 WRW_HARPOON((port + ID_MSG_STRT),
2525 (MPM_OP + AMSG_OUT +
2526 currSCCB->Sccb_idmsg));
2528 WRW_HARPOON((port + ID_MSG_STRT + 2),
2529 (MPM_OP + AMSG_OUT +
2530 (((unsigned char)(currSCCB->
2531 ControlByte &
2532 TAG_TYPE_MASK)
2533 >> 6) | (unsigned char)0x20)));
2535 for (i = 1; i < QUEUE_DEPTH; i++) {
2536 if (++lastTag >= QUEUE_DEPTH)
2537 lastTag = 1;
2538 if (CurrCard->discQ_Tbl[lastTag] ==
2539 NULL) {
2540 WRW_HARPOON((port +
2541 ID_MSG_STRT + 6),
2542 (MPM_OP + AMSG_OUT +
2543 lastTag));
2544 CurrCard->tagQ_Lst = lastTag;
2545 currSCCB->Sccb_tag = lastTag;
2546 CurrCard->discQ_Tbl[lastTag] =
2547 currSCCB;
2548 CurrCard->discQCount++;
2549 break;
2553 if (i == QUEUE_DEPTH) {
2554 currTar_Info->TarLUNBusy[lun] = 1;
2555 FPT_queueSelectFail(CurrCard, p_card);
2556 SGRAM_ACCESS(port);
2557 return;
2560 currSCCB->Sccb_scsistat = SELECT_Q_ST;
2562 WR_HARPOON(port + hp_autostart_3,
2563 (SELECT + SELCHK_STRT));
2567 else {
2569 WRW_HARPOON((port + ID_MSG_STRT),
2570 BRH_OP + ALWAYS + NTCMD);
2572 WRW_HARPOON((port + NON_TAG_ID_MSG),
2573 (MPM_OP + AMSG_OUT + currSCCB->Sccb_idmsg));
2575 currSCCB->Sccb_scsistat = SELECT_ST;
2577 WR_HARPOON(port + hp_autostart_3,
2578 (SELECT + SELCHK_STRT));
2581 theCCB = (unsigned char *)&currSCCB->Cdb[0];
2583 cdb_reg = port + CMD_STRT;
2585 for (i = 0; i < currSCCB->CdbLength; i++) {
2586 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + *theCCB));
2587 cdb_reg += 2;
2588 theCCB++;
2591 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
2592 WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
2595 /* auto_loaded */
2596 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
2597 WR_HARPOON(port + hp_xferstat, 0x00);
2599 WRW_HARPOON((port + hp_intstat), (PROG_HLT | TIMEOUT | SEL | BUS_FREE));
2601 WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT));
2603 if (!(currSCCB->Sccb_MGRFlags & F_DEV_SELECTED)) {
2604 WR_HARPOON(port + hp_scsictrl_0,
2605 (SEL_TAR | ENA_ATN | ENA_RESEL | ENA_SCAM_SEL));
2606 } else {
2608 /* auto_loaded = (RD_HARPOON(port+hp_autostart_3) & (unsigned char)0x1F);
2609 auto_loaded |= AUTO_IMMED; */
2610 auto_loaded = AUTO_IMMED;
2612 DISABLE_AUTO(port);
2614 WR_HARPOON(port + hp_autostart_3, auto_loaded);
2617 SGRAM_ACCESS(port);
2620 /*---------------------------------------------------------------------
2622 * Function: FPT_sres
2624 * Description: Hookup the correct CCB and handle the incoming messages.
2626 *---------------------------------------------------------------------*/
2628 static void FPT_sres(unsigned long port, unsigned char p_card,
2629 struct sccb_card *pCurrCard)
2632 unsigned char our_target, message, lun = 0, tag, msgRetryCount;
2634 struct sccb_mgr_tar_info *currTar_Info;
2635 struct sccb *currSCCB;
2637 if (pCurrCard->currentSCCB != NULL) {
2638 currTar_Info =
2639 &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
2640 DISABLE_AUTO(port);
2642 WR_HARPOON((port + hp_scsictrl_0), (ENA_RESEL | ENA_SCAM_SEL));
2644 currSCCB = pCurrCard->currentSCCB;
2645 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
2646 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2647 currSCCB->Sccb_scsistat = BUS_FREE_ST;
2649 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
2650 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2651 currSCCB->Sccb_scsistat = BUS_FREE_ST;
2653 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
2654 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
2655 TAG_Q_TRYING))) {
2656 currTar_Info->TarLUNBusy[currSCCB->Lun] = 0;
2657 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2658 pCurrCard->discQCount--;
2659 pCurrCard->discQ_Tbl[currTar_Info->
2660 LunDiscQ_Idx[currSCCB->
2661 Lun]]
2662 = NULL;
2664 } else {
2665 currTar_Info->TarLUNBusy[0] = 0;
2666 if (currSCCB->Sccb_tag) {
2667 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2668 pCurrCard->discQCount--;
2669 pCurrCard->discQ_Tbl[currSCCB->
2670 Sccb_tag] = NULL;
2672 } else {
2673 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2674 pCurrCard->discQCount--;
2675 pCurrCard->discQ_Tbl[currTar_Info->
2676 LunDiscQ_Idx[0]] =
2677 NULL;
2682 FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
2685 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
2687 our_target = (unsigned char)(RD_HARPOON(port + hp_select_id) >> 4);
2688 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
2690 msgRetryCount = 0;
2691 do {
2693 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
2694 tag = 0;
2696 while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
2697 if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
2699 WRW_HARPOON((port + hp_intstat), PHASE);
2700 return;
2704 WRW_HARPOON((port + hp_intstat), PHASE);
2705 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGI_PH) {
2707 message = FPT_sfm(port, pCurrCard->currentSCCB);
2708 if (message) {
2710 if (message <= (0x80 | LUN_MASK)) {
2711 lun = message & (unsigned char)LUN_MASK;
2713 if ((currTar_Info->
2714 TarStatus & TAR_TAG_Q_MASK) ==
2715 TAG_Q_TRYING) {
2716 if (currTar_Info->TarTagQ_Cnt !=
2717 0) {
2719 if (!
2720 (currTar_Info->
2721 TarLUN_CA)) {
2722 ACCEPT_MSG(port); /*Release the ACK for ID msg. */
2724 message =
2725 FPT_sfm
2726 (port,
2727 pCurrCard->
2728 currentSCCB);
2729 if (message) {
2730 ACCEPT_MSG
2731 (port);
2734 else
2735 message
2736 = 0;
2738 if (message !=
2739 0) {
2740 tag =
2741 FPT_sfm
2742 (port,
2743 pCurrCard->
2744 currentSCCB);
2746 if (!
2747 (tag))
2748 message
2754 /*C.A. exists! */
2756 /*End Q cnt != 0 */
2758 /*End Tag cmds supported! */
2760 /*End valid ID message. */
2761 else {
2763 ACCEPT_MSG_ATN(port);
2767 /* End good id message. */
2768 else {
2770 message = 0;
2772 } else {
2773 ACCEPT_MSG_ATN(port);
2775 while (!
2776 (RDW_HARPOON((port + hp_intstat)) &
2777 (PHASE | RESET))
2778 && !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
2779 && (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
2781 return;
2784 if (message == 0) {
2785 msgRetryCount++;
2786 if (msgRetryCount == 1) {
2787 FPT_SendMsg(port, SMPARITY);
2788 } else {
2789 FPT_SendMsg(port, SMDEV_RESET);
2791 FPT_sssyncv(port, our_target, NARROW_SCSI,
2792 currTar_Info);
2794 if (FPT_sccbMgrTbl[p_card][our_target].
2795 TarEEValue & EE_SYNC_MASK) {
2797 FPT_sccbMgrTbl[p_card][our_target].
2798 TarStatus &= ~TAR_SYNC_MASK;
2802 if (FPT_sccbMgrTbl[p_card][our_target].
2803 TarEEValue & EE_WIDE_SCSI) {
2805 FPT_sccbMgrTbl[p_card][our_target].
2806 TarStatus &= ~TAR_WIDE_MASK;
2809 FPT_queueFlushTargSccb(p_card, our_target,
2810 SCCB_COMPLETE);
2811 FPT_SccbMgrTableInitTarget(p_card, our_target);
2812 return;
2815 } while (message == 0);
2817 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
2818 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
2819 currTar_Info->TarLUNBusy[lun] = 1;
2820 pCurrCard->currentSCCB =
2821 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[lun]];
2822 if (pCurrCard->currentSCCB != NULL) {
2823 ACCEPT_MSG(port);
2824 } else {
2825 ACCEPT_MSG_ATN(port);
2827 } else {
2828 currTar_Info->TarLUNBusy[0] = 1;
2830 if (tag) {
2831 if (pCurrCard->discQ_Tbl[tag] != NULL) {
2832 pCurrCard->currentSCCB =
2833 pCurrCard->discQ_Tbl[tag];
2834 currTar_Info->TarTagQ_Cnt--;
2835 ACCEPT_MSG(port);
2836 } else {
2837 ACCEPT_MSG_ATN(port);
2839 } else {
2840 pCurrCard->currentSCCB =
2841 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]];
2842 if (pCurrCard->currentSCCB != NULL) {
2843 ACCEPT_MSG(port);
2844 } else {
2845 ACCEPT_MSG_ATN(port);
2850 if (pCurrCard->currentSCCB != NULL) {
2851 if (pCurrCard->currentSCCB->Sccb_scsistat == ABORT_ST) {
2852 /* During Abort Tag command, the target could have got re-selected
2853 and completed the command. Check the select Q and remove the CCB
2854 if it is in the Select Q */
2855 FPT_queueFindSccb(pCurrCard->currentSCCB, p_card);
2859 while (!(RDW_HARPOON((port + hp_intstat)) & (PHASE | RESET)) &&
2860 !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ) &&
2861 (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
2864 static void FPT_SendMsg(unsigned long port, unsigned char message)
2866 while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
2867 if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
2869 WRW_HARPOON((port + hp_intstat), PHASE);
2870 return;
2874 WRW_HARPOON((port + hp_intstat), PHASE);
2875 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGO_PH) {
2876 WRW_HARPOON((port + hp_intstat),
2877 (BUS_FREE | PHASE | XFER_CNT_0));
2879 WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
2881 WR_HARPOON(port + hp_scsidata_0, message);
2883 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2885 ACCEPT_MSG(port);
2887 WR_HARPOON(port + hp_portctrl_0, 0x00);
2889 if ((message == SMABORT) || (message == SMDEV_RESET) ||
2890 (message == SMABORT_TAG)) {
2891 while (!
2892 (RDW_HARPOON((port + hp_intstat)) &
2893 (BUS_FREE | PHASE))) {
2896 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
2897 WRW_HARPOON((port + hp_intstat), BUS_FREE);
2903 /*---------------------------------------------------------------------
2905 * Function: FPT_sdecm
2907 * Description: Determine the proper responce to the message from the
2908 * target device.
2910 *---------------------------------------------------------------------*/
2911 static void FPT_sdecm(unsigned char message, unsigned long port,
2912 unsigned char p_card)
2914 struct sccb *currSCCB;
2915 struct sccb_card *CurrCard;
2916 struct sccb_mgr_tar_info *currTar_Info;
2918 CurrCard = &FPT_BL_Card[p_card];
2919 currSCCB = CurrCard->currentSCCB;
2921 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
2923 if (message == SMREST_DATA_PTR) {
2924 if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET)) {
2925 currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC;
2927 FPT_hostDataXferRestart(currSCCB);
2930 ACCEPT_MSG(port);
2931 WR_HARPOON(port + hp_autostart_1,
2932 (AUTO_IMMED + DISCONNECT_START));
2935 else if (message == SMCMD_COMP) {
2937 if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
2938 currTar_Info->TarStatus &=
2939 ~(unsigned char)TAR_TAG_Q_MASK;
2940 currTar_Info->TarStatus |= (unsigned char)TAG_Q_REJECT;
2943 ACCEPT_MSG(port);
2947 else if ((message == SMNO_OP) || (message >= SMIDENT)
2948 || (message == SMINIT_RECOVERY) || (message == SMREL_RECOVERY)) {
2950 ACCEPT_MSG(port);
2951 WR_HARPOON(port + hp_autostart_1,
2952 (AUTO_IMMED + DISCONNECT_START));
2955 else if (message == SMREJECT) {
2957 if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) ||
2958 (currSCCB->Sccb_scsistat == SELECT_WN_ST) ||
2959 ((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)
2960 || ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) ==
2961 TAG_Q_TRYING))
2963 WRW_HARPOON((port + hp_intstat), BUS_FREE);
2965 ACCEPT_MSG(port);
2967 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2968 (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
2972 if (currSCCB->Lun == 0x00) {
2973 if ((currSCCB->Sccb_scsistat == SELECT_SN_ST)) {
2975 currTar_Info->TarStatus |=
2976 (unsigned char)SYNC_SUPPORTED;
2978 currTar_Info->TarEEValue &=
2979 ~EE_SYNC_MASK;
2982 else if ((currSCCB->Sccb_scsistat ==
2983 SELECT_WN_ST)) {
2985 currTar_Info->TarStatus =
2986 (currTar_Info->
2987 TarStatus & ~WIDE_ENABLED) |
2988 WIDE_NEGOCIATED;
2990 currTar_Info->TarEEValue &=
2991 ~EE_WIDE_SCSI;
2995 else if ((currTar_Info->
2996 TarStatus & TAR_TAG_Q_MASK) ==
2997 TAG_Q_TRYING) {
2998 currTar_Info->TarStatus =
2999 (currTar_Info->
3000 TarStatus & ~(unsigned char)
3001 TAR_TAG_Q_MASK) | TAG_Q_REJECT;
3003 currSCCB->ControlByte &= ~F_USE_CMD_Q;
3004 CurrCard->discQCount--;
3005 CurrCard->discQ_Tbl[currSCCB->
3006 Sccb_tag] = NULL;
3007 currSCCB->Sccb_tag = 0x00;
3012 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
3014 if (currSCCB->Lun == 0x00) {
3015 WRW_HARPOON((port + hp_intstat),
3016 BUS_FREE);
3017 CurrCard->globalFlags |= F_NEW_SCCB_CMD;
3021 else {
3023 if ((CurrCard->globalFlags & F_CONLUN_IO) &&
3024 ((currTar_Info->
3025 TarStatus & TAR_TAG_Q_MASK) !=
3026 TAG_Q_TRYING))
3027 currTar_Info->TarLUNBusy[currSCCB->
3028 Lun] = 1;
3029 else
3030 currTar_Info->TarLUNBusy[0] = 1;
3032 currSCCB->ControlByte &=
3033 ~(unsigned char)F_USE_CMD_Q;
3035 WR_HARPOON(port + hp_autostart_1,
3036 (AUTO_IMMED + DISCONNECT_START));
3041 else {
3042 ACCEPT_MSG(port);
3044 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
3045 (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
3049 if (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)) {
3050 WR_HARPOON(port + hp_autostart_1,
3051 (AUTO_IMMED + DISCONNECT_START));
3056 else if (message == SMEXT) {
3058 ACCEPT_MSG(port);
3059 FPT_shandem(port, p_card, currSCCB);
3062 else if (message == SMIGNORWR) {
3064 ACCEPT_MSG(port); /* ACK the RESIDUE MSG */
3066 message = FPT_sfm(port, currSCCB);
3068 if (currSCCB->Sccb_scsimsg != SMPARITY)
3069 ACCEPT_MSG(port);
3070 WR_HARPOON(port + hp_autostart_1,
3071 (AUTO_IMMED + DISCONNECT_START));
3074 else {
3076 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
3077 currSCCB->Sccb_scsimsg = SMREJECT;
3079 ACCEPT_MSG_ATN(port);
3080 WR_HARPOON(port + hp_autostart_1,
3081 (AUTO_IMMED + DISCONNECT_START));
3085 /*---------------------------------------------------------------------
3087 * Function: FPT_shandem
3089 * Description: Decide what to do with the extended message.
3091 *---------------------------------------------------------------------*/
3092 static void FPT_shandem(unsigned long port, unsigned char p_card,
3093 struct sccb *pCurrSCCB)
3095 unsigned char length, message;
3097 length = FPT_sfm(port, pCurrSCCB);
3098 if (length) {
3100 ACCEPT_MSG(port);
3101 message = FPT_sfm(port, pCurrSCCB);
3102 if (message) {
3104 if (message == SMSYNC) {
3106 if (length == 0x03) {
3108 ACCEPT_MSG(port);
3109 FPT_stsyncn(port, p_card);
3110 } else {
3112 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3113 ACCEPT_MSG_ATN(port);
3115 } else if (message == SMWDTR) {
3117 if (length == 0x02) {
3119 ACCEPT_MSG(port);
3120 FPT_stwidn(port, p_card);
3121 } else {
3123 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3124 ACCEPT_MSG_ATN(port);
3126 WR_HARPOON(port + hp_autostart_1,
3127 (AUTO_IMMED +
3128 DISCONNECT_START));
3130 } else {
3132 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3133 ACCEPT_MSG_ATN(port);
3135 WR_HARPOON(port + hp_autostart_1,
3136 (AUTO_IMMED + DISCONNECT_START));
3138 } else {
3139 if (pCurrSCCB->Sccb_scsimsg != SMPARITY)
3140 ACCEPT_MSG(port);
3141 WR_HARPOON(port + hp_autostart_1,
3142 (AUTO_IMMED + DISCONNECT_START));
3144 } else {
3145 if (pCurrSCCB->Sccb_scsimsg == SMPARITY)
3146 WR_HARPOON(port + hp_autostart_1,
3147 (AUTO_IMMED + DISCONNECT_START));
3151 /*---------------------------------------------------------------------
3153 * Function: FPT_sisyncn
3155 * Description: Read in a message byte from the SCSI bus, and check
3156 * for a parity error.
3158 *---------------------------------------------------------------------*/
3160 static unsigned char FPT_sisyncn(unsigned long port, unsigned char p_card,
3161 unsigned char syncFlag)
3163 struct sccb *currSCCB;
3164 struct sccb_mgr_tar_info *currTar_Info;
3166 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3167 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3169 if (!((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)) {
3171 WRW_HARPOON((port + ID_MSG_STRT),
3172 (MPM_OP + AMSG_OUT +
3173 (currSCCB->
3174 Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
3176 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
3178 WRW_HARPOON((port + SYNC_MSGS + 0),
3179 (MPM_OP + AMSG_OUT + SMEXT));
3180 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
3181 WRW_HARPOON((port + SYNC_MSGS + 4),
3182 (MPM_OP + AMSG_OUT + SMSYNC));
3184 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3186 WRW_HARPOON((port + SYNC_MSGS + 6),
3187 (MPM_OP + AMSG_OUT + 12));
3189 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
3190 EE_SYNC_10MB)
3192 WRW_HARPOON((port + SYNC_MSGS + 6),
3193 (MPM_OP + AMSG_OUT + 25));
3195 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
3196 EE_SYNC_5MB)
3198 WRW_HARPOON((port + SYNC_MSGS + 6),
3199 (MPM_OP + AMSG_OUT + 50));
3201 else
3202 WRW_HARPOON((port + SYNC_MSGS + 6),
3203 (MPM_OP + AMSG_OUT + 00));
3205 WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
3206 WRW_HARPOON((port + SYNC_MSGS + 10),
3207 (MPM_OP + AMSG_OUT + DEFAULT_OFFSET));
3208 WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
3210 if (syncFlag == 0) {
3211 WR_HARPOON(port + hp_autostart_3,
3212 (SELECT + SELCHK_STRT));
3213 currTar_Info->TarStatus =
3214 ((currTar_Info->
3215 TarStatus & ~(unsigned char)TAR_SYNC_MASK) |
3216 (unsigned char)SYNC_TRYING);
3217 } else {
3218 WR_HARPOON(port + hp_autostart_3,
3219 (AUTO_IMMED + CMD_ONLY_STRT));
3222 return 1;
3225 else {
3227 currTar_Info->TarStatus |= (unsigned char)SYNC_SUPPORTED;
3228 currTar_Info->TarEEValue &= ~EE_SYNC_MASK;
3229 return 0;
3233 /*---------------------------------------------------------------------
3235 * Function: FPT_stsyncn
3237 * Description: The has sent us a Sync Nego message so handle it as
3238 * necessary.
3240 *---------------------------------------------------------------------*/
3241 static void FPT_stsyncn(unsigned long port, unsigned char p_card)
3243 unsigned char sync_msg, offset, sync_reg, our_sync_msg;
3244 struct sccb *currSCCB;
3245 struct sccb_mgr_tar_info *currTar_Info;
3247 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3248 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3250 sync_msg = FPT_sfm(port, currSCCB);
3252 if ((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3253 WR_HARPOON(port + hp_autostart_1,
3254 (AUTO_IMMED + DISCONNECT_START));
3255 return;
3258 ACCEPT_MSG(port);
3260 offset = FPT_sfm(port, currSCCB);
3262 if ((offset == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3263 WR_HARPOON(port + hp_autostart_1,
3264 (AUTO_IMMED + DISCONNECT_START));
3265 return;
3268 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3270 our_sync_msg = 12; /* Setup our Message to 20mb/s */
3272 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_10MB)
3274 our_sync_msg = 25; /* Setup our Message to 10mb/s */
3276 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_5MB)
3278 our_sync_msg = 50; /* Setup our Message to 5mb/s */
3279 else
3281 our_sync_msg = 0; /* Message = Async */
3283 if (sync_msg < our_sync_msg) {
3284 sync_msg = our_sync_msg; /*if faster, then set to max. */
3287 if (offset == ASYNC)
3288 sync_msg = ASYNC;
3290 if (offset > MAX_OFFSET)
3291 offset = MAX_OFFSET;
3293 sync_reg = 0x00;
3295 if (sync_msg > 12)
3297 sync_reg = 0x20; /* Use 10MB/s */
3299 if (sync_msg > 25)
3301 sync_reg = 0x40; /* Use 6.6MB/s */
3303 if (sync_msg > 38)
3305 sync_reg = 0x60; /* Use 5MB/s */
3307 if (sync_msg > 50)
3309 sync_reg = 0x80; /* Use 4MB/s */
3311 if (sync_msg > 62)
3313 sync_reg = 0xA0; /* Use 3.33MB/s */
3315 if (sync_msg > 75)
3317 sync_reg = 0xC0; /* Use 2.85MB/s */
3319 if (sync_msg > 87)
3321 sync_reg = 0xE0; /* Use 2.5MB/s */
3323 if (sync_msg > 100) {
3325 sync_reg = 0x00; /* Use ASYNC */
3326 offset = 0x00;
3329 if (currTar_Info->TarStatus & WIDE_ENABLED)
3331 sync_reg |= offset;
3333 else
3335 sync_reg |= (offset | NARROW_SCSI);
3337 FPT_sssyncv(port, currSCCB->TargID, sync_reg, currTar_Info);
3339 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
3341 ACCEPT_MSG(port);
3343 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3344 ~(unsigned char)TAR_SYNC_MASK) |
3345 (unsigned char)SYNC_SUPPORTED);
3347 WR_HARPOON(port + hp_autostart_1,
3348 (AUTO_IMMED + DISCONNECT_START));
3351 else {
3353 ACCEPT_MSG_ATN(port);
3355 FPT_sisyncr(port, sync_msg, offset);
3357 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3358 ~(unsigned char)TAR_SYNC_MASK) |
3359 (unsigned char)SYNC_SUPPORTED);
3363 /*---------------------------------------------------------------------
3365 * Function: FPT_sisyncr
3367 * Description: Answer the targets sync message.
3369 *---------------------------------------------------------------------*/
3370 static void FPT_sisyncr(unsigned long port, unsigned char sync_pulse,
3371 unsigned char offset)
3373 ARAM_ACCESS(port);
3374 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT));
3375 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
3376 WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMSYNC));
3377 WRW_HARPOON((port + SYNC_MSGS + 6), (MPM_OP + AMSG_OUT + sync_pulse));
3378 WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
3379 WRW_HARPOON((port + SYNC_MSGS + 10), (MPM_OP + AMSG_OUT + offset));
3380 WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
3381 SGRAM_ACCESS(port);
3383 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3384 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
3386 WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
3388 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
3392 /*---------------------------------------------------------------------
3394 * Function: FPT_siwidn
3396 * Description: Read in a message byte from the SCSI bus, and check
3397 * for a parity error.
3399 *---------------------------------------------------------------------*/
3401 static unsigned char FPT_siwidn(unsigned long port, unsigned char p_card)
3403 struct sccb *currSCCB;
3404 struct sccb_mgr_tar_info *currTar_Info;
3406 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3407 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3409 if (!((currTar_Info->TarStatus & TAR_WIDE_MASK) == WIDE_NEGOCIATED)) {
3411 WRW_HARPOON((port + ID_MSG_STRT),
3412 (MPM_OP + AMSG_OUT +
3413 (currSCCB->
3414 Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
3416 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
3418 WRW_HARPOON((port + SYNC_MSGS + 0),
3419 (MPM_OP + AMSG_OUT + SMEXT));
3420 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
3421 WRW_HARPOON((port + SYNC_MSGS + 4),
3422 (MPM_OP + AMSG_OUT + SMWDTR));
3423 WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
3424 WRW_HARPOON((port + SYNC_MSGS + 8),
3425 (MPM_OP + AMSG_OUT + SM16BIT));
3426 WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
3428 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
3430 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3431 ~(unsigned char)TAR_WIDE_MASK) |
3432 (unsigned char)WIDE_ENABLED);
3434 return 1;
3437 else {
3439 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3440 ~(unsigned char)TAR_WIDE_MASK) |
3441 WIDE_NEGOCIATED);
3443 currTar_Info->TarEEValue &= ~EE_WIDE_SCSI;
3444 return 0;
3448 /*---------------------------------------------------------------------
3450 * Function: FPT_stwidn
3452 * Description: The has sent us a Wide Nego message so handle it as
3453 * necessary.
3455 *---------------------------------------------------------------------*/
3456 static void FPT_stwidn(unsigned long port, unsigned char p_card)
3458 unsigned char width;
3459 struct sccb *currSCCB;
3460 struct sccb_mgr_tar_info *currTar_Info;
3462 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3463 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3465 width = FPT_sfm(port, currSCCB);
3467 if ((width == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3468 WR_HARPOON(port + hp_autostart_1,
3469 (AUTO_IMMED + DISCONNECT_START));
3470 return;
3473 if (!(currTar_Info->TarEEValue & EE_WIDE_SCSI))
3474 width = 0;
3476 if (width) {
3477 currTar_Info->TarStatus |= WIDE_ENABLED;
3478 width = 0;
3479 } else {
3480 width = NARROW_SCSI;
3481 currTar_Info->TarStatus &= ~WIDE_ENABLED;
3484 FPT_sssyncv(port, currSCCB->TargID, width, currTar_Info);
3486 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
3488 currTar_Info->TarStatus |= WIDE_NEGOCIATED;
3490 if (!
3491 ((currTar_Info->TarStatus & TAR_SYNC_MASK) ==
3492 SYNC_SUPPORTED)) {
3493 ACCEPT_MSG_ATN(port);
3494 ARAM_ACCESS(port);
3495 FPT_sisyncn(port, p_card, 1);
3496 currSCCB->Sccb_scsistat = SELECT_SN_ST;
3497 SGRAM_ACCESS(port);
3498 } else {
3499 ACCEPT_MSG(port);
3500 WR_HARPOON(port + hp_autostart_1,
3501 (AUTO_IMMED + DISCONNECT_START));
3505 else {
3507 ACCEPT_MSG_ATN(port);
3509 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
3510 width = SM16BIT;
3511 else
3512 width = SM8BIT;
3514 FPT_siwidr(port, width);
3516 currTar_Info->TarStatus |= (WIDE_NEGOCIATED | WIDE_ENABLED);
3520 /*---------------------------------------------------------------------
3522 * Function: FPT_siwidr
3524 * Description: Answer the targets Wide nego message.
3526 *---------------------------------------------------------------------*/
3527 static void FPT_siwidr(unsigned long port, unsigned char width)
3529 ARAM_ACCESS(port);
3530 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT));
3531 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
3532 WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMWDTR));
3533 WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
3534 WRW_HARPOON((port + SYNC_MSGS + 8), (MPM_OP + AMSG_OUT + width));
3535 WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
3536 SGRAM_ACCESS(port);
3538 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3539 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
3541 WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
3543 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
3547 /*---------------------------------------------------------------------
3549 * Function: FPT_sssyncv
3551 * Description: Write the desired value to the Sync Register for the
3552 * ID specified.
3554 *---------------------------------------------------------------------*/
3555 static void FPT_sssyncv(unsigned long p_port, unsigned char p_id,
3556 unsigned char p_sync_value,
3557 struct sccb_mgr_tar_info *currTar_Info)
3559 unsigned char index;
3561 index = p_id;
3563 switch (index) {
3565 case 0:
3566 index = 12; /* hp_synctarg_0 */
3567 break;
3568 case 1:
3569 index = 13; /* hp_synctarg_1 */
3570 break;
3571 case 2:
3572 index = 14; /* hp_synctarg_2 */
3573 break;
3574 case 3:
3575 index = 15; /* hp_synctarg_3 */
3576 break;
3577 case 4:
3578 index = 8; /* hp_synctarg_4 */
3579 break;
3580 case 5:
3581 index = 9; /* hp_synctarg_5 */
3582 break;
3583 case 6:
3584 index = 10; /* hp_synctarg_6 */
3585 break;
3586 case 7:
3587 index = 11; /* hp_synctarg_7 */
3588 break;
3589 case 8:
3590 index = 4; /* hp_synctarg_8 */
3591 break;
3592 case 9:
3593 index = 5; /* hp_synctarg_9 */
3594 break;
3595 case 10:
3596 index = 6; /* hp_synctarg_10 */
3597 break;
3598 case 11:
3599 index = 7; /* hp_synctarg_11 */
3600 break;
3601 case 12:
3602 index = 0; /* hp_synctarg_12 */
3603 break;
3604 case 13:
3605 index = 1; /* hp_synctarg_13 */
3606 break;
3607 case 14:
3608 index = 2; /* hp_synctarg_14 */
3609 break;
3610 case 15:
3611 index = 3; /* hp_synctarg_15 */
3615 WR_HARPOON(p_port + hp_synctarg_base + index, p_sync_value);
3617 currTar_Info->TarSyncCtrl = p_sync_value;
3620 /*---------------------------------------------------------------------
3622 * Function: FPT_sresb
3624 * Description: Reset the desired card's SCSI bus.
3626 *---------------------------------------------------------------------*/
3627 static void FPT_sresb(unsigned long port, unsigned char p_card)
3629 unsigned char scsiID, i;
3631 struct sccb_mgr_tar_info *currTar_Info;
3633 WR_HARPOON(port + hp_page_ctrl,
3634 (RD_HARPOON(port + hp_page_ctrl) | G_INT_DISABLE));
3635 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
3637 WR_HARPOON(port + hp_scsictrl_0, SCSI_RST);
3639 scsiID = RD_HARPOON(port + hp_seltimeout);
3640 WR_HARPOON(port + hp_seltimeout, TO_5ms);
3641 WRW_HARPOON((port + hp_intstat), TIMEOUT);
3643 WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT | START_TO));
3645 while (!(RDW_HARPOON((port + hp_intstat)) & TIMEOUT)) {
3648 WR_HARPOON(port + hp_seltimeout, scsiID);
3650 WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
3652 FPT_Wait(port, TO_5ms);
3654 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
3656 WR_HARPOON(port + hp_int_mask, (RD_HARPOON(port + hp_int_mask) | 0x00));
3658 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
3659 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
3661 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
3662 currTar_Info->TarSyncCtrl = 0;
3663 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
3666 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
3667 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
3670 FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
3672 FPT_SccbMgrTableInitTarget(p_card, scsiID);
3675 FPT_BL_Card[p_card].scanIndex = 0x00;
3676 FPT_BL_Card[p_card].currentSCCB = NULL;
3677 FPT_BL_Card[p_card].globalFlags &= ~(F_TAG_STARTED | F_HOST_XFER_ACT
3678 | F_NEW_SCCB_CMD);
3679 FPT_BL_Card[p_card].cmdCounter = 0x00;
3680 FPT_BL_Card[p_card].discQCount = 0x00;
3681 FPT_BL_Card[p_card].tagQ_Lst = 0x01;
3683 for (i = 0; i < QUEUE_DEPTH; i++)
3684 FPT_BL_Card[p_card].discQ_Tbl[i] = NULL;
3686 WR_HARPOON(port + hp_page_ctrl,
3687 (RD_HARPOON(port + hp_page_ctrl) & ~G_INT_DISABLE));
3691 /*---------------------------------------------------------------------
3693 * Function: FPT_ssenss
3695 * Description: Setup for the Auto Sense command.
3697 *---------------------------------------------------------------------*/
3698 static void FPT_ssenss(struct sccb_card *pCurrCard)
3700 unsigned char i;
3701 struct sccb *currSCCB;
3703 currSCCB = pCurrCard->currentSCCB;
3705 currSCCB->Save_CdbLen = currSCCB->CdbLength;
3707 for (i = 0; i < 6; i++) {
3709 currSCCB->Save_Cdb[i] = currSCCB->Cdb[i];
3712 currSCCB->CdbLength = SIX_BYTE_CMD;
3713 currSCCB->Cdb[0] = SCSI_REQUEST_SENSE;
3714 currSCCB->Cdb[1] = currSCCB->Cdb[1] & (unsigned char)0xE0; /*Keep LUN. */
3715 currSCCB->Cdb[2] = 0x00;
3716 currSCCB->Cdb[3] = 0x00;
3717 currSCCB->Cdb[4] = currSCCB->RequestSenseLength;
3718 currSCCB->Cdb[5] = 0x00;
3720 currSCCB->Sccb_XferCnt = (unsigned long)currSCCB->RequestSenseLength;
3722 currSCCB->Sccb_ATC = 0x00;
3724 currSCCB->Sccb_XferState |= F_AUTO_SENSE;
3726 currSCCB->Sccb_XferState &= ~F_SG_XFER;
3728 currSCCB->Sccb_idmsg = currSCCB->Sccb_idmsg & ~(unsigned char)DISC_PRIV;
3730 currSCCB->ControlByte = 0x00;
3732 currSCCB->Sccb_MGRFlags &= F_STATUSLOADED;
3735 /*---------------------------------------------------------------------
3737 * Function: FPT_sxfrp
3739 * Description: Transfer data into the bit bucket until the device
3740 * decides to switch phase.
3742 *---------------------------------------------------------------------*/
3744 static void FPT_sxfrp(unsigned long p_port, unsigned char p_card)
3746 unsigned char curr_phz;
3748 DISABLE_AUTO(p_port);
3750 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
3752 FPT_hostDataXferAbort(p_port, p_card,
3753 FPT_BL_Card[p_card].currentSCCB);
3757 /* If the Automation handled the end of the transfer then do not
3758 match the phase or we will get out of sync with the ISR. */
3760 if (RDW_HARPOON((p_port + hp_intstat)) &
3761 (BUS_FREE | XFER_CNT_0 | AUTO_INT))
3762 return;
3764 WR_HARPOON(p_port + hp_xfercnt_0, 0x00);
3766 curr_phz = RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ;
3768 WRW_HARPOON((p_port + hp_intstat), XFER_CNT_0);
3770 WR_HARPOON(p_port + hp_scsisig, curr_phz);
3772 while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET)) &&
3773 (curr_phz ==
3774 (RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ)))
3776 if (curr_phz & (unsigned char)SCSI_IOBIT) {
3777 WR_HARPOON(p_port + hp_portctrl_0,
3778 (SCSI_PORT | HOST_PORT | SCSI_INBIT));
3780 if (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
3781 RD_HARPOON(p_port + hp_fifodata_0);
3783 } else {
3784 WR_HARPOON(p_port + hp_portctrl_0,
3785 (SCSI_PORT | HOST_PORT | HOST_WRT));
3786 if (RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY) {
3787 WR_HARPOON(p_port + hp_fifodata_0, 0xFA);
3790 } /* End of While loop for padding data I/O phase */
3792 while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
3793 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ)
3794 break;
3797 WR_HARPOON(p_port + hp_portctrl_0,
3798 (SCSI_PORT | HOST_PORT | SCSI_INBIT));
3799 while (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
3800 RD_HARPOON(p_port + hp_fifodata_0);
3803 if (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
3804 WR_HARPOON(p_port + hp_autostart_0,
3805 (AUTO_IMMED + DISCONNECT_START));
3806 while (!(RDW_HARPOON((p_port + hp_intstat)) & AUTO_INT)) {
3809 if (RDW_HARPOON((p_port + hp_intstat)) &
3810 (ICMD_COMP | ITAR_DISC))
3811 while (!
3812 (RDW_HARPOON((p_port + hp_intstat)) &
3813 (BUS_FREE | RSEL))) ;
3817 /*---------------------------------------------------------------------
3819 * Function: FPT_schkdd
3821 * Description: Make sure data has been flushed from both FIFOs and abort
3822 * the operations if necessary.
3824 *---------------------------------------------------------------------*/
3826 static void FPT_schkdd(unsigned long port, unsigned char p_card)
3828 unsigned short TimeOutLoop;
3829 unsigned char sPhase;
3831 struct sccb *currSCCB;
3833 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3835 if ((currSCCB->Sccb_scsistat != DATA_OUT_ST) &&
3836 (currSCCB->Sccb_scsistat != DATA_IN_ST)) {
3837 return;
3840 if (currSCCB->Sccb_XferState & F_ODD_BALL_CNT) {
3842 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - 1);
3844 currSCCB->Sccb_XferCnt = 1;
3846 currSCCB->Sccb_XferState &= ~F_ODD_BALL_CNT;
3847 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
3848 WR_HARPOON(port + hp_xferstat, 0x00);
3851 else {
3853 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
3855 currSCCB->Sccb_XferCnt = 0;
3858 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
3859 (currSCCB->HostStatus == SCCB_COMPLETE)) {
3861 currSCCB->HostStatus = SCCB_PARITY_ERR;
3862 WRW_HARPOON((port + hp_intstat), PARITY);
3865 FPT_hostDataXferAbort(port, p_card, currSCCB);
3867 while (RD_HARPOON(port + hp_scsisig) & SCSI_ACK) {
3870 TimeOutLoop = 0;
3872 while (RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY) {
3873 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
3874 return;
3876 if (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) {
3877 break;
3879 if (RDW_HARPOON((port + hp_intstat)) & RESET) {
3880 return;
3882 if ((RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
3883 || (TimeOutLoop++ > 0x3000))
3884 break;
3887 sPhase = RD_HARPOON(port + hp_scsisig) & (SCSI_BSY | S_SCSI_PHZ);
3888 if ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) ||
3889 (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) ||
3890 (sPhase == (SCSI_BSY | S_DATAO_PH)) ||
3891 (sPhase == (SCSI_BSY | S_DATAI_PH))) {
3893 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3895 if (!(currSCCB->Sccb_XferState & F_ALL_XFERRED)) {
3896 if (currSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
3897 FPT_phaseDataIn(port, p_card);
3900 else {
3901 FPT_phaseDataOut(port, p_card);
3903 } else {
3904 FPT_sxfrp(port, p_card);
3905 if (!(RDW_HARPOON((port + hp_intstat)) &
3906 (BUS_FREE | ICMD_COMP | ITAR_DISC | RESET))) {
3907 WRW_HARPOON((port + hp_intstat), AUTO_INT);
3908 FPT_phaseDecode(port, p_card);
3914 else {
3915 WR_HARPOON(port + hp_portctrl_0, 0x00);
3919 /*---------------------------------------------------------------------
3921 * Function: FPT_sinits
3923 * Description: Setup SCCB manager fields in this SCCB.
3925 *---------------------------------------------------------------------*/
3927 static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card)
3929 struct sccb_mgr_tar_info *currTar_Info;
3931 if ((p_sccb->TargID > MAX_SCSI_TAR) || (p_sccb->Lun > MAX_LUN)) {
3932 return;
3934 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
3936 p_sccb->Sccb_XferState = 0x00;
3937 p_sccb->Sccb_XferCnt = p_sccb->DataLength;
3939 if ((p_sccb->OperationCode == SCATTER_GATHER_COMMAND) ||
3940 (p_sccb->OperationCode == RESIDUAL_SG_COMMAND)) {
3942 p_sccb->Sccb_SGoffset = 0;
3943 p_sccb->Sccb_XferState = F_SG_XFER;
3944 p_sccb->Sccb_XferCnt = 0x00;
3947 if (p_sccb->DataLength == 0x00)
3949 p_sccb->Sccb_XferState |= F_ALL_XFERRED;
3951 if (p_sccb->ControlByte & F_USE_CMD_Q) {
3952 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
3953 p_sccb->ControlByte &= ~F_USE_CMD_Q;
3955 else
3956 currTar_Info->TarStatus |= TAG_Q_TRYING;
3959 /* For !single SCSI device in system & device allow Disconnect
3960 or command is tag_q type then send Cmd with Disconnect Enable
3961 else send Cmd with Disconnect Disable */
3964 if (((!(FPT_BL_Card[p_card].globalFlags & F_SINGLE_DEVICE)) &&
3965 (currTar_Info->TarStatus & TAR_ALLOW_DISC)) ||
3966 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
3968 if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) ||
3969 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
3970 p_sccb->Sccb_idmsg =
3971 (unsigned char)(SMIDENT | DISC_PRIV) | p_sccb->Lun;
3974 else {
3976 p_sccb->Sccb_idmsg = (unsigned char)SMIDENT | p_sccb->Lun;
3979 p_sccb->HostStatus = 0x00;
3980 p_sccb->TargetStatus = 0x00;
3981 p_sccb->Sccb_tag = 0x00;
3982 p_sccb->Sccb_MGRFlags = 0x00;
3983 p_sccb->Sccb_sgseg = 0x00;
3984 p_sccb->Sccb_ATC = 0x00;
3985 p_sccb->Sccb_savedATC = 0x00;
3987 p_sccb->SccbVirtDataPtr = 0x00;
3988 p_sccb->Sccb_forwardlink = NULL;
3989 p_sccb->Sccb_backlink = NULL;
3991 p_sccb->Sccb_scsistat = BUS_FREE_ST;
3992 p_sccb->SccbStatus = SCCB_IN_PROCESS;
3993 p_sccb->Sccb_scsimsg = SMNO_OP;
3997 /*---------------------------------------------------------------------
3999 * Function: Phase Decode
4001 * Description: Determine the phase and call the appropriate function.
4003 *---------------------------------------------------------------------*/
4005 static void FPT_phaseDecode(unsigned long p_port, unsigned char p_card)
4007 unsigned char phase_ref;
4008 void (*phase) (unsigned long, unsigned char);
4010 DISABLE_AUTO(p_port);
4012 phase_ref =
4013 (unsigned char)(RD_HARPOON(p_port + hp_scsisig) & S_SCSI_PHZ);
4015 phase = FPT_s_PhaseTbl[phase_ref];
4017 (*phase) (p_port, p_card); /* Call the correct phase func */
4020 /*---------------------------------------------------------------------
4022 * Function: Data Out Phase
4024 * Description: Start up both the BusMaster and Xbow.
4026 *---------------------------------------------------------------------*/
4028 static void FPT_phaseDataOut(unsigned long port, unsigned char p_card)
4031 struct sccb *currSCCB;
4033 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4034 if (currSCCB == NULL) {
4035 return; /* Exit if No SCCB record */
4038 currSCCB->Sccb_scsistat = DATA_OUT_ST;
4039 currSCCB->Sccb_XferState &= ~(F_HOST_XFER_DIR | F_NO_DATA_YET);
4041 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
4043 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4045 WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
4047 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4049 if (currSCCB->Sccb_XferCnt == 0) {
4051 if ((currSCCB->ControlByte & SCCB_DATA_XFER_OUT) &&
4052 (currSCCB->HostStatus == SCCB_COMPLETE))
4053 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4055 FPT_sxfrp(port, p_card);
4056 if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
4057 FPT_phaseDecode(port, p_card);
4061 /*---------------------------------------------------------------------
4063 * Function: Data In Phase
4065 * Description: Startup the BusMaster and the XBOW.
4067 *---------------------------------------------------------------------*/
4069 static void FPT_phaseDataIn(unsigned long port, unsigned char p_card)
4072 struct sccb *currSCCB;
4074 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4076 if (currSCCB == NULL) {
4077 return; /* Exit if No SCCB record */
4080 currSCCB->Sccb_scsistat = DATA_IN_ST;
4081 currSCCB->Sccb_XferState |= F_HOST_XFER_DIR;
4082 currSCCB->Sccb_XferState &= ~F_NO_DATA_YET;
4084 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
4086 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4088 WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
4090 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4092 if (currSCCB->Sccb_XferCnt == 0) {
4094 if ((currSCCB->ControlByte & SCCB_DATA_XFER_IN) &&
4095 (currSCCB->HostStatus == SCCB_COMPLETE))
4096 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4098 FPT_sxfrp(port, p_card);
4099 if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
4100 FPT_phaseDecode(port, p_card);
4105 /*---------------------------------------------------------------------
4107 * Function: Command Phase
4109 * Description: Load the CDB into the automation and start it up.
4111 *---------------------------------------------------------------------*/
4113 static void FPT_phaseCommand(unsigned long p_port, unsigned char p_card)
4115 struct sccb *currSCCB;
4116 unsigned long cdb_reg;
4117 unsigned char i;
4119 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4121 if (currSCCB->OperationCode == RESET_COMMAND) {
4123 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4124 currSCCB->CdbLength = SIX_BYTE_CMD;
4127 WR_HARPOON(p_port + hp_scsisig, 0x00);
4129 ARAM_ACCESS(p_port);
4131 cdb_reg = p_port + CMD_STRT;
4133 for (i = 0; i < currSCCB->CdbLength; i++) {
4135 if (currSCCB->OperationCode == RESET_COMMAND)
4137 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + 0x00));
4139 else
4140 WRW_HARPOON(cdb_reg,
4141 (MPM_OP + ACOMMAND + currSCCB->Cdb[i]));
4142 cdb_reg += 2;
4145 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
4146 WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
4148 WR_HARPOON(p_port + hp_portctrl_0, (SCSI_PORT));
4150 currSCCB->Sccb_scsistat = COMMAND_ST;
4152 WR_HARPOON(p_port + hp_autostart_3, (AUTO_IMMED | CMD_ONLY_STRT));
4153 SGRAM_ACCESS(p_port);
4156 /*---------------------------------------------------------------------
4158 * Function: Status phase
4160 * Description: Bring in the status and command complete message bytes
4162 *---------------------------------------------------------------------*/
4164 static void FPT_phaseStatus(unsigned long port, unsigned char p_card)
4166 /* Start-up the automation to finish off this command and let the
4167 isr handle the interrupt for command complete when it comes in.
4168 We could wait here for the interrupt to be generated?
4171 WR_HARPOON(port + hp_scsisig, 0x00);
4173 WR_HARPOON(port + hp_autostart_0, (AUTO_IMMED + END_DATA_START));
4176 /*---------------------------------------------------------------------
4178 * Function: Phase Message Out
4180 * Description: Send out our message (if we have one) and handle whatever
4181 * else is involed.
4183 *---------------------------------------------------------------------*/
4185 static void FPT_phaseMsgOut(unsigned long port, unsigned char p_card)
4187 unsigned char message, scsiID;
4188 struct sccb *currSCCB;
4189 struct sccb_mgr_tar_info *currTar_Info;
4191 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4193 if (currSCCB != NULL) {
4195 message = currSCCB->Sccb_scsimsg;
4196 scsiID = currSCCB->TargID;
4198 if (message == SMDEV_RESET) {
4200 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
4201 currTar_Info->TarSyncCtrl = 0;
4202 FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
4204 if (FPT_sccbMgrTbl[p_card][scsiID].
4205 TarEEValue & EE_SYNC_MASK) {
4207 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
4208 ~TAR_SYNC_MASK;
4212 if (FPT_sccbMgrTbl[p_card][scsiID].
4213 TarEEValue & EE_WIDE_SCSI) {
4215 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
4216 ~TAR_WIDE_MASK;
4219 FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
4220 FPT_SccbMgrTableInitTarget(p_card, scsiID);
4221 } else if (currSCCB->Sccb_scsistat == ABORT_ST) {
4222 currSCCB->HostStatus = SCCB_COMPLETE;
4223 if (FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] !=
4224 NULL) {
4225 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4226 Sccb_tag] = NULL;
4227 FPT_sccbMgrTbl[p_card][scsiID].TarTagQ_Cnt--;
4232 else if (currSCCB->Sccb_scsistat < COMMAND_ST) {
4234 if (message == SMNO_OP) {
4235 currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED;
4237 FPT_ssel(port, p_card);
4238 return;
4240 } else {
4242 if (message == SMABORT)
4244 FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
4247 } else {
4248 message = SMABORT;
4251 WRW_HARPOON((port + hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0));
4253 WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
4255 WR_HARPOON(port + hp_scsidata_0, message);
4257 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
4259 ACCEPT_MSG(port);
4261 WR_HARPOON(port + hp_portctrl_0, 0x00);
4263 if ((message == SMABORT) || (message == SMDEV_RESET) ||
4264 (message == SMABORT_TAG)) {
4266 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | PHASE))) {
4269 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
4270 WRW_HARPOON((port + hp_intstat), BUS_FREE);
4272 if (currSCCB != NULL) {
4274 if ((FPT_BL_Card[p_card].
4275 globalFlags & F_CONLUN_IO)
4277 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4278 TarStatus & TAR_TAG_Q_MASK) !=
4279 TAG_Q_TRYING))
4280 FPT_sccbMgrTbl[p_card][currSCCB->
4281 TargID].
4282 TarLUNBusy[currSCCB->Lun] = 0;
4283 else
4284 FPT_sccbMgrTbl[p_card][currSCCB->
4285 TargID].
4286 TarLUNBusy[0] = 0;
4288 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
4289 currSCCB, p_card);
4292 else {
4293 FPT_BL_Card[p_card].globalFlags |=
4294 F_NEW_SCCB_CMD;
4298 else {
4300 FPT_sxfrp(port, p_card);
4304 else {
4306 if (message == SMPARITY) {
4307 currSCCB->Sccb_scsimsg = SMNO_OP;
4308 WR_HARPOON(port + hp_autostart_1,
4309 (AUTO_IMMED + DISCONNECT_START));
4310 } else {
4311 FPT_sxfrp(port, p_card);
4316 /*---------------------------------------------------------------------
4318 * Function: Message In phase
4320 * Description: Bring in the message and determine what to do with it.
4322 *---------------------------------------------------------------------*/
4324 static void FPT_phaseMsgIn(unsigned long port, unsigned char p_card)
4326 unsigned char message;
4327 struct sccb *currSCCB;
4329 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4331 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
4333 FPT_phaseChkFifo(port, p_card);
4336 message = RD_HARPOON(port + hp_scsidata_0);
4337 if ((message == SMDISC) || (message == SMSAVE_DATA_PTR)) {
4339 WR_HARPOON(port + hp_autostart_1,
4340 (AUTO_IMMED + END_DATA_START));
4344 else {
4346 message = FPT_sfm(port, currSCCB);
4347 if (message) {
4349 FPT_sdecm(message, port, p_card);
4351 } else {
4352 if (currSCCB->Sccb_scsimsg != SMPARITY)
4353 ACCEPT_MSG(port);
4354 WR_HARPOON(port + hp_autostart_1,
4355 (AUTO_IMMED + DISCONNECT_START));
4361 /*---------------------------------------------------------------------
4363 * Function: Illegal phase
4365 * Description: Target switched to some illegal phase, so all we can do
4366 * is report an error back to the host (if that is possible)
4367 * and send an ABORT message to the misbehaving target.
4369 *---------------------------------------------------------------------*/
4371 static void FPT_phaseIllegal(unsigned long port, unsigned char p_card)
4373 struct sccb *currSCCB;
4375 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4377 WR_HARPOON(port + hp_scsisig, RD_HARPOON(port + hp_scsisig));
4378 if (currSCCB != NULL) {
4380 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4381 currSCCB->Sccb_scsistat = ABORT_ST;
4382 currSCCB->Sccb_scsimsg = SMABORT;
4385 ACCEPT_MSG_ATN(port);
4388 /*---------------------------------------------------------------------
4390 * Function: Phase Check FIFO
4392 * Description: Make sure data has been flushed from both FIFOs and abort
4393 * the operations if necessary.
4395 *---------------------------------------------------------------------*/
4397 static void FPT_phaseChkFifo(unsigned long port, unsigned char p_card)
4399 unsigned long xfercnt;
4400 struct sccb *currSCCB;
4402 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4404 if (currSCCB->Sccb_scsistat == DATA_IN_ST) {
4406 while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) &&
4407 (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)) {
4410 if (!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) {
4411 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
4413 currSCCB->Sccb_XferCnt = 0;
4415 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
4416 (currSCCB->HostStatus == SCCB_COMPLETE)) {
4417 currSCCB->HostStatus = SCCB_PARITY_ERR;
4418 WRW_HARPOON((port + hp_intstat), PARITY);
4421 FPT_hostDataXferAbort(port, p_card, currSCCB);
4423 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4425 while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY))
4426 && (RD_HARPOON(port + hp_ext_status) &
4427 BM_CMD_BUSY)) {
4433 /*End Data In specific code. */
4434 GET_XFER_CNT(port, xfercnt);
4436 WR_HARPOON(port + hp_xfercnt_0, 0x00);
4438 WR_HARPOON(port + hp_portctrl_0, 0x00);
4440 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - xfercnt);
4442 currSCCB->Sccb_XferCnt = xfercnt;
4444 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
4445 (currSCCB->HostStatus == SCCB_COMPLETE)) {
4447 currSCCB->HostStatus = SCCB_PARITY_ERR;
4448 WRW_HARPOON((port + hp_intstat), PARITY);
4451 FPT_hostDataXferAbort(port, p_card, currSCCB);
4453 WR_HARPOON(port + hp_fifowrite, 0x00);
4454 WR_HARPOON(port + hp_fiforead, 0x00);
4455 WR_HARPOON(port + hp_xferstat, 0x00);
4457 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4460 /*---------------------------------------------------------------------
4462 * Function: Phase Bus Free
4464 * Description: We just went bus free so figure out if it was
4465 * because of command complete or from a disconnect.
4467 *---------------------------------------------------------------------*/
4468 static void FPT_phaseBusFree(unsigned long port, unsigned char p_card)
4470 struct sccb *currSCCB;
4472 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4474 if (currSCCB != NULL) {
4476 DISABLE_AUTO(port);
4478 if (currSCCB->OperationCode == RESET_COMMAND) {
4480 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4481 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4482 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4483 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4484 TarLUNBusy[currSCCB->Lun] = 0;
4485 else
4486 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4487 TarLUNBusy[0] = 0;
4489 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
4490 p_card);
4492 FPT_queueSearchSelect(&FPT_BL_Card[p_card], p_card);
4496 else if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
4497 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
4498 (unsigned char)SYNC_SUPPORTED;
4499 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4500 ~EE_SYNC_MASK;
4503 else if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
4504 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
4505 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4506 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
4508 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4509 ~EE_WIDE_SCSI;
4512 else if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
4513 /* Make sure this is not a phony BUS_FREE. If we were
4514 reselected or if BUSY is NOT on then this is a
4515 valid BUS FREE. SRR Wednesday, 5/10/1995. */
4517 if ((!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ||
4518 (RDW_HARPOON((port + hp_intstat)) & RSEL)) {
4519 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4520 TarStatus &= ~TAR_TAG_Q_MASK;
4521 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4522 TarStatus |= TAG_Q_REJECT;
4525 else {
4526 return;
4530 else {
4532 currSCCB->Sccb_scsistat = BUS_FREE_ST;
4534 if (!currSCCB->HostStatus) {
4535 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4538 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4539 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4540 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4541 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4542 TarLUNBusy[currSCCB->Lun] = 0;
4543 else
4544 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4545 TarLUNBusy[0] = 0;
4547 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
4548 p_card);
4549 return;
4552 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4554 } /*end if !=null */
4557 /*---------------------------------------------------------------------
4559 * Function: Auto Load Default Map
4561 * Description: Load the Automation RAM with the defualt map values.
4563 *---------------------------------------------------------------------*/
4564 static void FPT_autoLoadDefaultMap(unsigned long p_port)
4566 unsigned long map_addr;
4568 ARAM_ACCESS(p_port);
4569 map_addr = p_port + hp_aramBase;
4571 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0xC0)); /*ID MESSAGE */
4572 map_addr += 2;
4573 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x20)); /*SIMPLE TAG QUEUEING MSG */
4574 map_addr += 2;
4575 WRW_HARPOON(map_addr, RAT_OP); /*RESET ATTENTION */
4576 map_addr += 2;
4577 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x00)); /*TAG ID MSG */
4578 map_addr += 2;
4579 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 0 */
4580 map_addr += 2;
4581 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 1 */
4582 map_addr += 2;
4583 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 2 */
4584 map_addr += 2;
4585 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 3 */
4586 map_addr += 2;
4587 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 4 */
4588 map_addr += 2;
4589 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 5 */
4590 map_addr += 2;
4591 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 6 */
4592 map_addr += 2;
4593 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 7 */
4594 map_addr += 2;
4595 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 8 */
4596 map_addr += 2;
4597 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 9 */
4598 map_addr += 2;
4599 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 10 */
4600 map_addr += 2;
4601 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 11 */
4602 map_addr += 2;
4603 WRW_HARPOON(map_addr, (CPE_OP + ADATA_OUT + DINT)); /*JUMP IF DATA OUT */
4604 map_addr += 2;
4605 WRW_HARPOON(map_addr, (TCB_OP + FIFO_0 + DI)); /*JUMP IF NO DATA IN FIFO */
4606 map_addr += 2; /*This means AYNC DATA IN */
4607 WRW_HARPOON(map_addr, (SSI_OP + SSI_IDO_STRT)); /*STOP AND INTERRUPT */
4608 map_addr += 2;
4609 WRW_HARPOON(map_addr, (CPE_OP + ADATA_IN + DINT)); /*JUMP IF NOT DATA IN PHZ */
4610 map_addr += 2;
4611 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK 4 DATA IN */
4612 map_addr += 2;
4613 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x02)); /*SAVE DATA PTR MSG? */
4614 map_addr += 2;
4615 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + DC)); /*GO CHECK FOR DISCONNECT MSG */
4616 map_addr += 2;
4617 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR1)); /*SAVE DATA PTRS MSG */
4618 map_addr += 2;
4619 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK DATA IN */
4620 map_addr += 2;
4621 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x04)); /*DISCONNECT MSG? */
4622 map_addr += 2;
4623 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + UNKNWN)); /*UKNKNOWN MSG */
4624 map_addr += 2;
4625 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*XFER DISCONNECT MSG */
4626 map_addr += 2;
4627 WRW_HARPOON(map_addr, (SSI_OP + SSI_ITAR_DISC)); /*STOP AND INTERRUPT */
4628 map_addr += 2;
4629 WRW_HARPOON(map_addr, (CPN_OP + ASTATUS + UNKNWN)); /*JUMP IF NOT STATUS PHZ. */
4630 map_addr += 2;
4631 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR0)); /*GET STATUS BYTE */
4632 map_addr += 2;
4633 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + CC)); /*ERROR IF NOT MSG IN PHZ */
4634 map_addr += 2;
4635 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x00)); /*CHECK FOR CMD COMPLETE MSG. */
4636 map_addr += 2;
4637 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + CC)); /*ERROR IF NOT CMD COMPLETE MSG. */
4638 map_addr += 2;
4639 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*GET CMD COMPLETE MSG */
4640 map_addr += 2;
4641 WRW_HARPOON(map_addr, (SSI_OP + SSI_ICMD_COMP)); /*END OF COMMAND */
4642 map_addr += 2;
4644 WRW_HARPOON(map_addr, (SSI_OP + SSI_IUNKWN)); /*RECEIVED UNKNOWN MSG BYTE */
4645 map_addr += 2;
4646 WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
4647 map_addr += 2;
4648 WRW_HARPOON(map_addr, (SSI_OP + SSI_ITICKLE)); /*BIOS Tickled the Mgr */
4649 map_addr += 2;
4650 WRW_HARPOON(map_addr, (SSI_OP + SSI_IRFAIL)); /*EXPECTED ID/TAG MESSAGES AND */
4651 map_addr += 2; /* DIDN'T GET ONE */
4652 WRW_HARPOON(map_addr, (CRR_OP + AR3 + S_IDREG)); /* comp SCSI SEL ID & AR3 */
4653 map_addr += 2;
4654 WRW_HARPOON(map_addr, (BRH_OP + EQUAL + 0x00)); /*SEL ID OK then Conti. */
4655 map_addr += 2;
4656 WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
4658 SGRAM_ACCESS(p_port);
4661 /*---------------------------------------------------------------------
4663 * Function: Auto Command Complete
4665 * Description: Post command back to host and find another command
4666 * to execute.
4668 *---------------------------------------------------------------------*/
4670 static void FPT_autoCmdCmplt(unsigned long p_port, unsigned char p_card)
4672 struct sccb *currSCCB;
4673 unsigned char status_byte;
4675 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4677 status_byte = RD_HARPOON(p_port + hp_gp_reg_0);
4679 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0;
4681 if (status_byte != SSGOOD) {
4683 if (status_byte == SSQ_FULL) {
4685 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4686 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4687 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4688 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4689 TarLUNBusy[currSCCB->Lun] = 1;
4690 if (FPT_BL_Card[p_card].discQCount != 0)
4691 FPT_BL_Card[p_card].discQCount--;
4692 FPT_BL_Card[p_card].
4693 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4694 [currSCCB->TargID].
4695 LunDiscQ_Idx[currSCCB->Lun]] =
4696 NULL;
4697 } else {
4698 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4699 TarLUNBusy[0] = 1;
4700 if (currSCCB->Sccb_tag) {
4701 if (FPT_BL_Card[p_card].discQCount != 0)
4702 FPT_BL_Card[p_card].
4703 discQCount--;
4704 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4705 Sccb_tag]
4706 = NULL;
4707 } else {
4708 if (FPT_BL_Card[p_card].discQCount != 0)
4709 FPT_BL_Card[p_card].
4710 discQCount--;
4711 FPT_BL_Card[p_card].
4712 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4713 [currSCCB->TargID].
4714 LunDiscQ_Idx[0]] = NULL;
4718 currSCCB->Sccb_MGRFlags |= F_STATUSLOADED;
4720 FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
4722 return;
4725 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
4726 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
4727 (unsigned char)SYNC_SUPPORTED;
4729 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4730 ~EE_SYNC_MASK;
4731 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4733 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4734 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4735 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4736 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4737 TarLUNBusy[currSCCB->Lun] = 1;
4738 if (FPT_BL_Card[p_card].discQCount != 0)
4739 FPT_BL_Card[p_card].discQCount--;
4740 FPT_BL_Card[p_card].
4741 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4742 [currSCCB->TargID].
4743 LunDiscQ_Idx[currSCCB->Lun]] =
4744 NULL;
4745 } else {
4746 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4747 TarLUNBusy[0] = 1;
4748 if (currSCCB->Sccb_tag) {
4749 if (FPT_BL_Card[p_card].discQCount != 0)
4750 FPT_BL_Card[p_card].
4751 discQCount--;
4752 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4753 Sccb_tag]
4754 = NULL;
4755 } else {
4756 if (FPT_BL_Card[p_card].discQCount != 0)
4757 FPT_BL_Card[p_card].
4758 discQCount--;
4759 FPT_BL_Card[p_card].
4760 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4761 [currSCCB->TargID].
4762 LunDiscQ_Idx[0]] = NULL;
4765 return;
4769 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
4771 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
4772 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4773 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
4775 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4776 ~EE_WIDE_SCSI;
4777 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4779 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4780 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4781 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4782 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4783 TarLUNBusy[currSCCB->Lun] = 1;
4784 if (FPT_BL_Card[p_card].discQCount != 0)
4785 FPT_BL_Card[p_card].discQCount--;
4786 FPT_BL_Card[p_card].
4787 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4788 [currSCCB->TargID].
4789 LunDiscQ_Idx[currSCCB->Lun]] =
4790 NULL;
4791 } else {
4792 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4793 TarLUNBusy[0] = 1;
4794 if (currSCCB->Sccb_tag) {
4795 if (FPT_BL_Card[p_card].discQCount != 0)
4796 FPT_BL_Card[p_card].
4797 discQCount--;
4798 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4799 Sccb_tag]
4800 = NULL;
4801 } else {
4802 if (FPT_BL_Card[p_card].discQCount != 0)
4803 FPT_BL_Card[p_card].
4804 discQCount--;
4805 FPT_BL_Card[p_card].
4806 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4807 [currSCCB->TargID].
4808 LunDiscQ_Idx[0]] = NULL;
4811 return;
4815 if (status_byte == SSCHECK) {
4816 if (FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO) {
4817 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4818 TarEEValue & EE_SYNC_MASK) {
4819 FPT_sccbMgrTbl[p_card][currSCCB->
4820 TargID].
4821 TarStatus &= ~TAR_SYNC_MASK;
4823 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4824 TarEEValue & EE_WIDE_SCSI) {
4825 FPT_sccbMgrTbl[p_card][currSCCB->
4826 TargID].
4827 TarStatus &= ~TAR_WIDE_MASK;
4832 if (!(currSCCB->Sccb_XferState & F_AUTO_SENSE)) {
4834 currSCCB->SccbStatus = SCCB_ERROR;
4835 currSCCB->TargetStatus = status_byte;
4837 if (status_byte == SSCHECK) {
4839 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4840 TarLUN_CA = 1;
4842 if (currSCCB->RequestSenseLength !=
4843 NO_AUTO_REQUEST_SENSE) {
4845 if (currSCCB->RequestSenseLength == 0)
4846 currSCCB->RequestSenseLength =
4849 FPT_ssenss(&FPT_BL_Card[p_card]);
4850 FPT_BL_Card[p_card].globalFlags |=
4851 F_NEW_SCCB_CMD;
4853 if (((FPT_BL_Card[p_card].
4854 globalFlags & F_CONLUN_IO)
4856 ((FPT_sccbMgrTbl[p_card]
4857 [currSCCB->TargID].
4858 TarStatus & TAR_TAG_Q_MASK) !=
4859 TAG_Q_TRYING))) {
4860 FPT_sccbMgrTbl[p_card]
4861 [currSCCB->TargID].
4862 TarLUNBusy[currSCCB->Lun] =
4864 if (FPT_BL_Card[p_card].
4865 discQCount != 0)
4866 FPT_BL_Card[p_card].
4867 discQCount--;
4868 FPT_BL_Card[p_card].
4869 discQ_Tbl[FPT_sccbMgrTbl
4870 [p_card]
4871 [currSCCB->
4872 TargID].
4873 LunDiscQ_Idx
4874 [currSCCB->Lun]] =
4875 NULL;
4876 } else {
4877 FPT_sccbMgrTbl[p_card]
4878 [currSCCB->TargID].
4879 TarLUNBusy[0] = 1;
4880 if (currSCCB->Sccb_tag) {
4881 if (FPT_BL_Card[p_card].
4882 discQCount != 0)
4883 FPT_BL_Card
4884 [p_card].
4885 discQCount--;
4886 FPT_BL_Card[p_card].
4887 discQ_Tbl[currSCCB->
4888 Sccb_tag]
4889 = NULL;
4890 } else {
4891 if (FPT_BL_Card[p_card].
4892 discQCount != 0)
4893 FPT_BL_Card
4894 [p_card].
4895 discQCount--;
4896 FPT_BL_Card[p_card].
4897 discQ_Tbl
4898 [FPT_sccbMgrTbl
4899 [p_card][currSCCB->
4900 TargID].
4901 LunDiscQ_Idx[0]] =
4902 NULL;
4905 return;
4911 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4912 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4913 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4914 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->
4915 Lun] = 0;
4916 else
4917 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
4919 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
4922 #define SHORT_WAIT 0x0000000F
4923 #define LONG_WAIT 0x0000FFFFL
4925 /*---------------------------------------------------------------------
4927 * Function: Data Transfer Processor
4929 * Description: This routine performs two tasks.
4930 * (1) Start data transfer by calling HOST_DATA_XFER_START
4931 * function. Once data transfer is started, (2) Depends
4932 * on the type of data transfer mode Scatter/Gather mode
4933 * or NON Scatter/Gather mode. In NON Scatter/Gather mode,
4934 * this routine checks Sccb_MGRFlag (F_HOST_XFER_ACT bit) for
4935 * data transfer done. In Scatter/Gather mode, this routine
4936 * checks bus master command complete and dual rank busy
4937 * bit to keep chaining SC transfer command. Similarly,
4938 * in Scatter/Gather mode, it checks Sccb_MGRFlag
4939 * (F_HOST_XFER_ACT bit) for data transfer done.
4941 *---------------------------------------------------------------------*/
4943 static void FPT_dataXferProcessor(unsigned long port,
4944 struct sccb_card *pCurrCard)
4946 struct sccb *currSCCB;
4948 currSCCB = pCurrCard->currentSCCB;
4950 if (currSCCB->Sccb_XferState & F_SG_XFER) {
4951 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
4953 currSCCB->Sccb_sgseg += (unsigned char)SG_BUF_CNT;
4954 currSCCB->Sccb_SGoffset = 0x00;
4956 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
4958 FPT_busMstrSGDataXferStart(port, currSCCB);
4961 else {
4962 if (!(pCurrCard->globalFlags & F_HOST_XFER_ACT)) {
4963 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
4965 FPT_busMstrDataXferStart(port, currSCCB);
4970 /*---------------------------------------------------------------------
4972 * Function: BusMaster Scatter Gather Data Transfer Start
4974 * Description:
4976 *---------------------------------------------------------------------*/
4977 static void FPT_busMstrSGDataXferStart(unsigned long p_port,
4978 struct sccb *pcurrSCCB)
4980 unsigned long count, addr, tmpSGCnt;
4981 unsigned int sg_index;
4982 unsigned char sg_count, i;
4983 unsigned long reg_offset;
4985 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
4987 count = ((unsigned long)HOST_RD_CMD) << 24;
4990 else {
4991 count = ((unsigned long)HOST_WRT_CMD) << 24;
4994 sg_count = 0;
4995 tmpSGCnt = 0;
4996 sg_index = pcurrSCCB->Sccb_sgseg;
4997 reg_offset = hp_aramBase;
4999 i = (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
5000 ~(SGRAM_ARAM | SCATTER_EN));
5002 WR_HARPOON(p_port + hp_page_ctrl, i);
5004 while ((sg_count < (unsigned char)SG_BUF_CNT) &&
5005 ((unsigned long)(sg_index * (unsigned int)SG_ELEMENT_SIZE) <
5006 pcurrSCCB->DataLength)) {
5008 tmpSGCnt += *(((unsigned long *)pcurrSCCB->DataPointer) +
5009 (sg_index * 2));
5011 count |= *(((unsigned long *)pcurrSCCB->DataPointer) +
5012 (sg_index * 2));
5014 addr = *(((unsigned long *)pcurrSCCB->DataPointer) +
5015 ((sg_index * 2) + 1));
5017 if ((!sg_count) && (pcurrSCCB->Sccb_SGoffset)) {
5019 addr +=
5020 ((count & 0x00FFFFFFL) - pcurrSCCB->Sccb_SGoffset);
5021 count =
5022 (count & 0xFF000000L) | pcurrSCCB->Sccb_SGoffset;
5024 tmpSGCnt = count & 0x00FFFFFFL;
5027 WR_HARP32(p_port, reg_offset, addr);
5028 reg_offset += 4;
5030 WR_HARP32(p_port, reg_offset, count);
5031 reg_offset += 4;
5033 count &= 0xFF000000L;
5034 sg_index++;
5035 sg_count++;
5037 } /*End While */
5039 pcurrSCCB->Sccb_XferCnt = tmpSGCnt;
5041 WR_HARPOON(p_port + hp_sg_addr, (sg_count << 4));
5043 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5045 WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
5047 WR_HARPOON(p_port + hp_portctrl_0,
5048 (DMA_PORT | SCSI_PORT | SCSI_INBIT));
5049 WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
5052 else {
5054 if ((!(RD_HARPOON(p_port + hp_synctarg_0) & NARROW_SCSI)) &&
5055 (tmpSGCnt & 0x000000001)) {
5057 pcurrSCCB->Sccb_XferState |= F_ODD_BALL_CNT;
5058 tmpSGCnt--;
5061 WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
5063 WR_HARPOON(p_port + hp_portctrl_0,
5064 (SCSI_PORT | DMA_PORT | DMA_RD));
5065 WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
5068 WR_HARPOON(p_port + hp_page_ctrl, (unsigned char)(i | SCATTER_EN));
5072 /*---------------------------------------------------------------------
5074 * Function: BusMaster Data Transfer Start
5076 * Description:
5078 *---------------------------------------------------------------------*/
5079 static void FPT_busMstrDataXferStart(unsigned long p_port,
5080 struct sccb *pcurrSCCB)
5082 unsigned long addr, count;
5084 if (!(pcurrSCCB->Sccb_XferState & F_AUTO_SENSE)) {
5086 count = pcurrSCCB->Sccb_XferCnt;
5088 addr =
5089 (unsigned long)pcurrSCCB->DataPointer + pcurrSCCB->Sccb_ATC;
5092 else {
5093 addr = pcurrSCCB->SensePointer;
5094 count = pcurrSCCB->RequestSenseLength;
5098 HP_SETUP_ADDR_CNT(p_port, addr, count);
5100 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5102 WR_HARPOON(p_port + hp_portctrl_0,
5103 (DMA_PORT | SCSI_PORT | SCSI_INBIT));
5104 WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
5106 WR_HARPOON(p_port + hp_xfer_cmd,
5107 (XFER_DMA_HOST | XFER_HOST_AUTO | XFER_DMA_8BIT));
5110 else {
5112 WR_HARPOON(p_port + hp_portctrl_0,
5113 (SCSI_PORT | DMA_PORT | DMA_RD));
5114 WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
5116 WR_HARPOON(p_port + hp_xfer_cmd,
5117 (XFER_HOST_DMA | XFER_HOST_AUTO | XFER_DMA_8BIT));
5122 /*---------------------------------------------------------------------
5124 * Function: BusMaster Timeout Handler
5126 * Description: This function is called after a bus master command busy time
5127 * out is detected. This routines issue halt state machine
5128 * with a software time out for command busy. If command busy
5129 * is still asserted at the end of the time out, it issues
5130 * hard abort with another software time out. It hard abort
5131 * command busy is also time out, it'll just give up.
5133 *---------------------------------------------------------------------*/
5134 static unsigned char FPT_busMstrTimeOut(unsigned long p_port)
5136 unsigned long timeout;
5138 timeout = LONG_WAIT;
5140 WR_HARPOON(p_port + hp_sys_ctrl, HALT_MACH);
5142 while ((!(RD_HARPOON(p_port + hp_ext_status) & CMD_ABORTED))
5143 && timeout--) {
5146 if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
5147 WR_HARPOON(p_port + hp_sys_ctrl, HARD_ABORT);
5149 timeout = LONG_WAIT;
5150 while ((RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY)
5151 && timeout--) {
5155 RD_HARPOON(p_port + hp_int_status); /*Clear command complete */
5157 if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
5158 return 1;
5161 else {
5162 return 0;
5166 /*---------------------------------------------------------------------
5168 * Function: Host Data Transfer Abort
5170 * Description: Abort any in progress transfer.
5172 *---------------------------------------------------------------------*/
5173 static void FPT_hostDataXferAbort(unsigned long port, unsigned char p_card,
5174 struct sccb *pCurrSCCB)
5177 unsigned long timeout;
5178 unsigned long remain_cnt;
5179 unsigned int sg_ptr;
5181 FPT_BL_Card[p_card].globalFlags &= ~F_HOST_XFER_ACT;
5183 if (pCurrSCCB->Sccb_XferState & F_AUTO_SENSE) {
5185 if (!(RD_HARPOON(port + hp_int_status) & INT_CMD_COMPL)) {
5187 WR_HARPOON(port + hp_bm_ctrl,
5188 (RD_HARPOON(port + hp_bm_ctrl) |
5189 FLUSH_XFER_CNTR));
5190 timeout = LONG_WAIT;
5192 while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
5193 && timeout--) {
5196 WR_HARPOON(port + hp_bm_ctrl,
5197 (RD_HARPOON(port + hp_bm_ctrl) &
5198 ~FLUSH_XFER_CNTR));
5200 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5202 if (FPT_busMstrTimeOut(port)) {
5204 if (pCurrSCCB->HostStatus == 0x00)
5206 pCurrSCCB->HostStatus =
5207 SCCB_BM_ERR;
5211 if (RD_HARPOON(port + hp_int_status) &
5212 INT_EXT_STATUS)
5214 if (RD_HARPOON(port + hp_ext_status) &
5215 BAD_EXT_STATUS)
5217 if (pCurrSCCB->HostStatus ==
5218 0x00)
5220 pCurrSCCB->HostStatus =
5221 SCCB_BM_ERR;
5227 else if (pCurrSCCB->Sccb_XferCnt) {
5229 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5231 WR_HARPOON(port + hp_page_ctrl,
5232 (RD_HARPOON(port + hp_page_ctrl) &
5233 ~SCATTER_EN));
5235 WR_HARPOON(port + hp_sg_addr, 0x00);
5237 sg_ptr = pCurrSCCB->Sccb_sgseg + SG_BUF_CNT;
5239 if (sg_ptr >
5240 (unsigned int)(pCurrSCCB->DataLength /
5241 SG_ELEMENT_SIZE)) {
5243 sg_ptr =
5244 (unsigned int)(pCurrSCCB->DataLength /
5245 SG_ELEMENT_SIZE);
5248 remain_cnt = pCurrSCCB->Sccb_XferCnt;
5250 while (remain_cnt < 0x01000000L) {
5252 sg_ptr--;
5254 if (remain_cnt >
5255 (unsigned
5256 long)(*(((unsigned long *)pCurrSCCB->
5257 DataPointer) + (sg_ptr * 2)))) {
5259 remain_cnt -=
5260 (unsigned
5261 long)(*(((unsigned long *)
5262 pCurrSCCB->DataPointer) +
5263 (sg_ptr * 2)));
5266 else {
5268 break;
5272 if (remain_cnt < 0x01000000L) {
5274 pCurrSCCB->Sccb_SGoffset = remain_cnt;
5276 pCurrSCCB->Sccb_sgseg = (unsigned short)sg_ptr;
5278 if ((unsigned long)(sg_ptr * SG_ELEMENT_SIZE) ==
5279 pCurrSCCB->DataLength && (remain_cnt == 0))
5281 pCurrSCCB->Sccb_XferState |=
5282 F_ALL_XFERRED;
5285 else {
5287 if (pCurrSCCB->HostStatus == 0x00) {
5289 pCurrSCCB->HostStatus =
5290 SCCB_GROSS_FW_ERR;
5295 if (!(pCurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)) {
5297 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5299 FPT_busMstrTimeOut(port);
5302 else {
5304 if (RD_HARPOON(port + hp_int_status) &
5305 INT_EXT_STATUS) {
5307 if (RD_HARPOON(port + hp_ext_status) &
5308 BAD_EXT_STATUS) {
5310 if (pCurrSCCB->HostStatus ==
5311 0x00) {
5313 pCurrSCCB->HostStatus =
5314 SCCB_BM_ERR;
5322 else {
5324 if ((RD_HARPOON(port + hp_fifo_cnt)) >= BM_THRESHOLD) {
5326 timeout = SHORT_WAIT;
5328 while ((RD_HARPOON(port + hp_ext_status) &
5329 BM_CMD_BUSY)
5330 && ((RD_HARPOON(port + hp_fifo_cnt)) >=
5331 BM_THRESHOLD) && timeout--) {
5335 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5337 WR_HARPOON(port + hp_bm_ctrl,
5338 (RD_HARPOON(port + hp_bm_ctrl) |
5339 FLUSH_XFER_CNTR));
5341 timeout = LONG_WAIT;
5343 while ((RD_HARPOON(port + hp_ext_status) &
5344 BM_CMD_BUSY) && timeout--) {
5347 WR_HARPOON(port + hp_bm_ctrl,
5348 (RD_HARPOON(port + hp_bm_ctrl) &
5349 ~FLUSH_XFER_CNTR));
5351 if (RD_HARPOON(port + hp_ext_status) &
5352 BM_CMD_BUSY) {
5354 if (pCurrSCCB->HostStatus == 0x00) {
5356 pCurrSCCB->HostStatus =
5357 SCCB_BM_ERR;
5360 FPT_busMstrTimeOut(port);
5364 if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
5366 if (RD_HARPOON(port + hp_ext_status) &
5367 BAD_EXT_STATUS) {
5369 if (pCurrSCCB->HostStatus == 0x00) {
5371 pCurrSCCB->HostStatus =
5372 SCCB_BM_ERR;
5380 else {
5382 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5384 timeout = LONG_WAIT;
5386 while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
5387 && timeout--) {
5390 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5392 if (pCurrSCCB->HostStatus == 0x00) {
5394 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5397 FPT_busMstrTimeOut(port);
5401 if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
5403 if (RD_HARPOON(port + hp_ext_status) & BAD_EXT_STATUS) {
5405 if (pCurrSCCB->HostStatus == 0x00) {
5407 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5413 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5415 WR_HARPOON(port + hp_page_ctrl,
5416 (RD_HARPOON(port + hp_page_ctrl) &
5417 ~SCATTER_EN));
5419 WR_HARPOON(port + hp_sg_addr, 0x00);
5421 pCurrSCCB->Sccb_sgseg += SG_BUF_CNT;
5423 pCurrSCCB->Sccb_SGoffset = 0x00;
5425 if ((unsigned long)(pCurrSCCB->Sccb_sgseg *
5426 SG_ELEMENT_SIZE) >=
5427 pCurrSCCB->DataLength) {
5429 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5431 pCurrSCCB->Sccb_sgseg =
5432 (unsigned short)(pCurrSCCB->DataLength /
5433 SG_ELEMENT_SIZE);
5438 else {
5440 if (!(pCurrSCCB->Sccb_XferState & F_AUTO_SENSE))
5442 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5446 WR_HARPOON(port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
5449 /*---------------------------------------------------------------------
5451 * Function: Host Data Transfer Restart
5453 * Description: Reset the available count due to a restore data
5454 * pointers message.
5456 *---------------------------------------------------------------------*/
5457 static void FPT_hostDataXferRestart(struct sccb *currSCCB)
5459 unsigned long data_count;
5460 unsigned int sg_index;
5461 unsigned long *sg_ptr;
5463 if (currSCCB->Sccb_XferState & F_SG_XFER) {
5465 currSCCB->Sccb_XferCnt = 0;
5467 sg_index = 0xffff; /*Index by long words into sg list. */
5468 data_count = 0; /*Running count of SG xfer counts. */
5470 sg_ptr = (unsigned long *)currSCCB->DataPointer;
5472 while (data_count < currSCCB->Sccb_ATC) {
5474 sg_index++;
5475 data_count += *(sg_ptr + (sg_index * 2));
5478 if (data_count == currSCCB->Sccb_ATC) {
5480 currSCCB->Sccb_SGoffset = 0;
5481 sg_index++;
5484 else {
5485 currSCCB->Sccb_SGoffset =
5486 data_count - currSCCB->Sccb_ATC;
5489 currSCCB->Sccb_sgseg = (unsigned short)sg_index;
5492 else {
5493 currSCCB->Sccb_XferCnt =
5494 currSCCB->DataLength - currSCCB->Sccb_ATC;
5498 /*---------------------------------------------------------------------
5500 * Function: FPT_scini
5502 * Description: Setup all data structures necessary for SCAM selection.
5504 *---------------------------------------------------------------------*/
5506 static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
5507 unsigned char p_power_up)
5510 unsigned char loser, assigned_id;
5511 unsigned long p_port;
5513 unsigned char i, k, ScamFlg;
5514 struct sccb_card *currCard;
5515 struct nvram_info *pCurrNvRam;
5517 currCard = &FPT_BL_Card[p_card];
5518 p_port = currCard->ioPort;
5519 pCurrNvRam = currCard->pNvRamInfo;
5521 if (pCurrNvRam) {
5522 ScamFlg = pCurrNvRam->niScamConf;
5523 i = pCurrNvRam->niSysConf;
5524 } else {
5525 ScamFlg =
5526 (unsigned char)FPT_utilEERead(p_port, SCAM_CONFIG / 2);
5527 i = (unsigned
5528 char)(FPT_utilEERead(p_port, (SYSTEM_CONFIG / 2)));
5530 if (!(i & 0x02)) /* check if reset bus in AutoSCSI parameter set */
5531 return;
5533 FPT_inisci(p_card, p_port, p_our_id);
5535 /* Force to wait 1 sec after SCSI bus reset. Some SCAM device FW
5536 too slow to return to SCAM selection */
5538 /* if (p_power_up)
5539 FPT_Wait1Second(p_port);
5540 else
5541 FPT_Wait(p_port, TO_250ms); */
5543 FPT_Wait1Second(p_port);
5545 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2)) {
5546 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5549 FPT_scsel(p_port);
5551 do {
5552 FPT_scxferc(p_port, SYNC_PTRN);
5553 FPT_scxferc(p_port, DOM_MSTR);
5554 loser =
5555 FPT_scsendi(p_port,
5556 &FPT_scamInfo[p_our_id].id_string[0]);
5557 } while (loser == 0xFF);
5559 FPT_scbusf(p_port);
5561 if ((p_power_up) && (!loser)) {
5562 FPT_sresb(p_port, p_card);
5563 FPT_Wait(p_port, TO_250ms);
5565 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5568 FPT_scsel(p_port);
5570 do {
5571 FPT_scxferc(p_port, SYNC_PTRN);
5572 FPT_scxferc(p_port, DOM_MSTR);
5573 loser =
5574 FPT_scsendi(p_port,
5575 &FPT_scamInfo[p_our_id].
5576 id_string[0]);
5577 } while (loser == 0xFF);
5579 FPT_scbusf(p_port);
5583 else {
5584 loser = 0;
5587 if (!loser) {
5589 FPT_scamInfo[p_our_id].state = ID_ASSIGNED;
5591 if (ScamFlg & SCAM_ENABLED) {
5593 for (i = 0; i < MAX_SCSI_TAR; i++) {
5594 if ((FPT_scamInfo[i].state == ID_UNASSIGNED) ||
5595 (FPT_scamInfo[i].state == ID_UNUSED)) {
5596 if (FPT_scsell(p_port, i)) {
5597 FPT_scamInfo[i].state = LEGACY;
5598 if ((FPT_scamInfo[i].
5599 id_string[0] != 0xFF)
5600 || (FPT_scamInfo[i].
5601 id_string[1] != 0xFA)) {
5603 FPT_scamInfo[i].
5604 id_string[0] = 0xFF;
5605 FPT_scamInfo[i].
5606 id_string[1] = 0xFA;
5607 if (pCurrNvRam == NULL)
5608 currCard->
5609 globalFlags
5611 F_UPDATE_EEPROM;
5617 FPT_sresb(p_port, p_card);
5618 FPT_Wait1Second(p_port);
5619 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5621 FPT_scsel(p_port);
5622 FPT_scasid(p_card, p_port);
5627 else if ((loser) && (ScamFlg & SCAM_ENABLED)) {
5628 FPT_scamInfo[p_our_id].id_string[0] = SLV_TYPE_CODE0;
5629 assigned_id = 0;
5630 FPT_scwtsel(p_port);
5632 do {
5633 while (FPT_scxferc(p_port, 0x00) != SYNC_PTRN) {
5636 i = FPT_scxferc(p_port, 0x00);
5637 if (i == ASSIGN_ID) {
5638 if (!
5639 (FPT_scsendi
5640 (p_port,
5641 &FPT_scamInfo[p_our_id].id_string[0]))) {
5642 i = FPT_scxferc(p_port, 0x00);
5643 if (FPT_scvalq(i)) {
5644 k = FPT_scxferc(p_port, 0x00);
5646 if (FPT_scvalq(k)) {
5647 currCard->ourId =
5648 ((unsigned char)(i
5652 (k &
5653 (unsigned char)7))
5654 & (unsigned char)
5655 0x3F;
5656 FPT_inisci(p_card,
5657 p_port,
5658 p_our_id);
5659 FPT_scamInfo[currCard->
5660 ourId].
5661 state = ID_ASSIGNED;
5662 FPT_scamInfo[currCard->
5663 ourId].
5664 id_string[0]
5665 = SLV_TYPE_CODE0;
5666 assigned_id = 1;
5672 else if (i == SET_P_FLAG) {
5673 if (!(FPT_scsendi(p_port,
5674 &FPT_scamInfo[p_our_id].
5675 id_string[0])))
5676 FPT_scamInfo[p_our_id].id_string[0] |=
5677 0x80;
5679 } while (!assigned_id);
5681 while (FPT_scxferc(p_port, 0x00) != CFG_CMPLT) {
5685 if (ScamFlg & SCAM_ENABLED) {
5686 FPT_scbusf(p_port);
5687 if (currCard->globalFlags & F_UPDATE_EEPROM) {
5688 FPT_scsavdi(p_card, p_port);
5689 currCard->globalFlags &= ~F_UPDATE_EEPROM;
5694 for (i=0,k=0; i < MAX_SCSI_TAR; i++)
5696 if ((FPT_scamInfo[i].state == ID_ASSIGNED) ||
5697 (FPT_scamInfo[i].state == LEGACY))
5698 k++;
5701 if (k==2)
5702 currCard->globalFlags |= F_SINGLE_DEVICE;
5703 else
5704 currCard->globalFlags &= ~F_SINGLE_DEVICE;
5708 /*---------------------------------------------------------------------
5710 * Function: FPT_scarb
5712 * Description: Gain control of the bus and wait SCAM select time (250ms)
5714 *---------------------------------------------------------------------*/
5716 static int FPT_scarb(unsigned long p_port, unsigned char p_sel_type)
5718 if (p_sel_type == INIT_SELTD) {
5720 while (RD_HARPOON(p_port + hp_scsisig) & (SCSI_SEL | SCSI_BSY)) {
5723 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL)
5724 return 0;
5726 if (RD_HARPOON(p_port + hp_scsidata_0) != 00)
5727 return 0;
5729 WR_HARPOON(p_port + hp_scsisig,
5730 (RD_HARPOON(p_port + hp_scsisig) | SCSI_BSY));
5732 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL) {
5734 WR_HARPOON(p_port + hp_scsisig,
5735 (RD_HARPOON(p_port + hp_scsisig) &
5736 ~SCSI_BSY));
5737 return 0;
5740 WR_HARPOON(p_port + hp_scsisig,
5741 (RD_HARPOON(p_port + hp_scsisig) | SCSI_SEL));
5743 if (RD_HARPOON(p_port + hp_scsidata_0) != 00) {
5745 WR_HARPOON(p_port + hp_scsisig,
5746 (RD_HARPOON(p_port + hp_scsisig) &
5747 ~(SCSI_BSY | SCSI_SEL)));
5748 return 0;
5752 WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
5753 & ~ACTdeassert));
5754 WR_HARPOON(p_port + hp_scsireset, SCAM_EN);
5755 WR_HARPOON(p_port + hp_scsidata_0, 0x00);
5756 WR_HARPOON(p_port + hp_scsidata_1, 0x00);
5757 WR_HARPOON(p_port + hp_portctrl_0, SCSI_BUS_EN);
5759 WR_HARPOON(p_port + hp_scsisig,
5760 (RD_HARPOON(p_port + hp_scsisig) | SCSI_MSG));
5762 WR_HARPOON(p_port + hp_scsisig, (RD_HARPOON(p_port + hp_scsisig)
5763 & ~SCSI_BSY));
5765 FPT_Wait(p_port, TO_250ms);
5767 return 1;
5770 /*---------------------------------------------------------------------
5772 * Function: FPT_scbusf
5774 * Description: Release the SCSI bus and disable SCAM selection.
5776 *---------------------------------------------------------------------*/
5778 static void FPT_scbusf(unsigned long p_port)
5780 WR_HARPOON(p_port + hp_page_ctrl,
5781 (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
5783 WR_HARPOON(p_port + hp_scsidata_0, 0x00);
5785 WR_HARPOON(p_port + hp_portctrl_0, (RD_HARPOON(p_port + hp_portctrl_0)
5786 & ~SCSI_BUS_EN));
5788 WR_HARPOON(p_port + hp_scsisig, 0x00);
5790 WR_HARPOON(p_port + hp_scsireset, (RD_HARPOON(p_port + hp_scsireset)
5791 & ~SCAM_EN));
5793 WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
5794 | ACTdeassert));
5796 WRW_HARPOON((p_port + hp_intstat), (BUS_FREE | AUTO_INT | SCAM_SEL));
5798 WR_HARPOON(p_port + hp_page_ctrl,
5799 (RD_HARPOON(p_port + hp_page_ctrl) & ~G_INT_DISABLE));
5802 /*---------------------------------------------------------------------
5804 * Function: FPT_scasid
5806 * Description: Assign an ID to all the SCAM devices.
5808 *---------------------------------------------------------------------*/
5810 static void FPT_scasid(unsigned char p_card, unsigned long p_port)
5812 unsigned char temp_id_string[ID_STRING_LENGTH];
5814 unsigned char i, k, scam_id;
5815 unsigned char crcBytes[3];
5816 struct nvram_info *pCurrNvRam;
5817 unsigned short *pCrcBytes;
5819 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
5821 i = 0;
5823 while (!i) {
5825 for (k = 0; k < ID_STRING_LENGTH; k++) {
5826 temp_id_string[k] = (unsigned char)0x00;
5829 FPT_scxferc(p_port, SYNC_PTRN);
5830 FPT_scxferc(p_port, ASSIGN_ID);
5832 if (!(FPT_sciso(p_port, &temp_id_string[0]))) {
5833 if (pCurrNvRam) {
5834 pCrcBytes = (unsigned short *)&crcBytes[0];
5835 *pCrcBytes = FPT_CalcCrc16(&temp_id_string[0]);
5836 crcBytes[2] = FPT_CalcLrc(&temp_id_string[0]);
5837 temp_id_string[1] = crcBytes[2];
5838 temp_id_string[2] = crcBytes[0];
5839 temp_id_string[3] = crcBytes[1];
5840 for (k = 4; k < ID_STRING_LENGTH; k++)
5841 temp_id_string[k] = (unsigned char)0x00;
5843 i = FPT_scmachid(p_card, temp_id_string);
5845 if (i == CLR_PRIORITY) {
5846 FPT_scxferc(p_port, MISC_CODE);
5847 FPT_scxferc(p_port, CLR_P_FLAG);
5848 i = 0; /*Not the last ID yet. */
5851 else if (i != NO_ID_AVAIL) {
5852 if (i < 8)
5853 FPT_scxferc(p_port, ID_0_7);
5854 else
5855 FPT_scxferc(p_port, ID_8_F);
5857 scam_id = (i & (unsigned char)0x07);
5859 for (k = 1; k < 0x08; k <<= 1)
5860 if (!(k & i))
5861 scam_id += 0x08; /*Count number of zeros in DB0-3. */
5863 FPT_scxferc(p_port, scam_id);
5865 i = 0; /*Not the last ID yet. */
5869 else {
5870 i = 1;
5873 } /*End while */
5875 FPT_scxferc(p_port, SYNC_PTRN);
5876 FPT_scxferc(p_port, CFG_CMPLT);
5879 /*---------------------------------------------------------------------
5881 * Function: FPT_scsel
5883 * Description: Select all the SCAM devices.
5885 *---------------------------------------------------------------------*/
5887 static void FPT_scsel(unsigned long p_port)
5890 WR_HARPOON(p_port + hp_scsisig, SCSI_SEL);
5891 FPT_scwiros(p_port, SCSI_MSG);
5893 WR_HARPOON(p_port + hp_scsisig, (SCSI_SEL | SCSI_BSY));
5895 WR_HARPOON(p_port + hp_scsisig,
5896 (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5897 WR_HARPOON(p_port + hp_scsidata_0,
5898 (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) |
5899 (unsigned char)(BIT(7) + BIT(6))));
5901 WR_HARPOON(p_port + hp_scsisig, (SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5902 FPT_scwiros(p_port, SCSI_SEL);
5904 WR_HARPOON(p_port + hp_scsidata_0,
5905 (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) &
5906 ~(unsigned char)BIT(6)));
5907 FPT_scwirod(p_port, BIT(6));
5909 WR_HARPOON(p_port + hp_scsisig,
5910 (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5913 /*---------------------------------------------------------------------
5915 * Function: FPT_scxferc
5917 * Description: Handshake the p_data (DB4-0) across the bus.
5919 *---------------------------------------------------------------------*/
5921 static unsigned char FPT_scxferc(unsigned long p_port, unsigned char p_data)
5923 unsigned char curr_data, ret_data;
5925 curr_data = p_data | BIT(7) | BIT(5); /*Start with DB7 & DB5 asserted. */
5927 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5929 curr_data &= ~BIT(7);
5931 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5933 FPT_scwirod(p_port, BIT(7)); /*Wait for DB7 to be released. */
5934 while (!(RD_HARPOON(p_port + hp_scsidata_0) & BIT(5))) ;
5936 ret_data = (RD_HARPOON(p_port + hp_scsidata_0) & (unsigned char)0x1F);
5938 curr_data |= BIT(6);
5940 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5942 curr_data &= ~BIT(5);
5944 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5946 FPT_scwirod(p_port, BIT(5)); /*Wait for DB5 to be released. */
5948 curr_data &= ~(BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0)); /*Release data bits */
5949 curr_data |= BIT(7);
5951 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5953 curr_data &= ~BIT(6);
5955 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5957 FPT_scwirod(p_port, BIT(6)); /*Wait for DB6 to be released. */
5959 return ret_data;
5962 /*---------------------------------------------------------------------
5964 * Function: FPT_scsendi
5966 * Description: Transfer our Identification string to determine if we
5967 * will be the dominant master.
5969 *---------------------------------------------------------------------*/
5971 static unsigned char FPT_scsendi(unsigned long p_port,
5972 unsigned char p_id_string[])
5974 unsigned char ret_data, byte_cnt, bit_cnt, defer;
5976 defer = 0;
5978 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
5980 for (bit_cnt = 0x80; bit_cnt != 0; bit_cnt >>= 1) {
5982 if (defer)
5983 ret_data = FPT_scxferc(p_port, 00);
5985 else if (p_id_string[byte_cnt] & bit_cnt)
5987 ret_data = FPT_scxferc(p_port, 02);
5989 else {
5991 ret_data = FPT_scxferc(p_port, 01);
5992 if (ret_data & 02)
5993 defer = 1;
5996 if ((ret_data & 0x1C) == 0x10)
5997 return 0x00; /*End of isolation stage, we won! */
5999 if (ret_data & 0x1C)
6000 return 0xFF;
6002 if ((defer) && (!(ret_data & 0x1F)))
6003 return 0x01; /*End of isolation stage, we lost. */
6005 } /*bit loop */
6007 } /*byte loop */
6009 if (defer)
6010 return 0x01; /*We lost */
6011 else
6012 return 0; /*We WON! Yeeessss! */
6015 /*---------------------------------------------------------------------
6017 * Function: FPT_sciso
6019 * Description: Transfer the Identification string.
6021 *---------------------------------------------------------------------*/
6023 static unsigned char FPT_sciso(unsigned long p_port,
6024 unsigned char p_id_string[])
6026 unsigned char ret_data, the_data, byte_cnt, bit_cnt;
6028 the_data = 0;
6030 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
6032 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
6034 ret_data = FPT_scxferc(p_port, 0);
6036 if (ret_data & 0xFC)
6037 return 0xFF;
6039 else {
6041 the_data <<= 1;
6042 if (ret_data & BIT(1)) {
6043 the_data |= 1;
6047 if ((ret_data & 0x1F) == 0) {
6049 if(bit_cnt != 0 || bit_cnt != 8)
6051 byte_cnt = 0;
6052 bit_cnt = 0;
6053 FPT_scxferc(p_port, SYNC_PTRN);
6054 FPT_scxferc(p_port, ASSIGN_ID);
6055 continue;
6058 if (byte_cnt)
6059 return 0x00;
6060 else
6061 return 0xFF;
6064 } /*bit loop */
6066 p_id_string[byte_cnt] = the_data;
6068 } /*byte loop */
6070 return 0;
6073 /*---------------------------------------------------------------------
6075 * Function: FPT_scwirod
6077 * Description: Sample the SCSI data bus making sure the signal has been
6078 * deasserted for the correct number of consecutive samples.
6080 *---------------------------------------------------------------------*/
6082 static void FPT_scwirod(unsigned long p_port, unsigned char p_data_bit)
6084 unsigned char i;
6086 i = 0;
6087 while (i < MAX_SCSI_TAR) {
6089 if (RD_HARPOON(p_port + hp_scsidata_0) & p_data_bit)
6091 i = 0;
6093 else
6095 i++;
6100 /*---------------------------------------------------------------------
6102 * Function: FPT_scwiros
6104 * Description: Sample the SCSI Signal lines making sure the signal has been
6105 * deasserted for the correct number of consecutive samples.
6107 *---------------------------------------------------------------------*/
6109 static void FPT_scwiros(unsigned long p_port, unsigned char p_data_bit)
6111 unsigned char i;
6113 i = 0;
6114 while (i < MAX_SCSI_TAR) {
6116 if (RD_HARPOON(p_port + hp_scsisig) & p_data_bit)
6118 i = 0;
6120 else
6122 i++;
6127 /*---------------------------------------------------------------------
6129 * Function: FPT_scvalq
6131 * Description: Make sure we received a valid data byte.
6133 *---------------------------------------------------------------------*/
6135 static unsigned char FPT_scvalq(unsigned char p_quintet)
6137 unsigned char count;
6139 for (count = 1; count < 0x08; count <<= 1) {
6140 if (!(p_quintet & count))
6141 p_quintet -= 0x80;
6144 if (p_quintet & 0x18)
6145 return 0;
6147 else
6148 return 1;
6151 /*---------------------------------------------------------------------
6153 * Function: FPT_scsell
6155 * Description: Select the specified device ID using a selection timeout
6156 * less than 4ms. If somebody responds then it is a legacy
6157 * drive and this ID must be marked as such.
6159 *---------------------------------------------------------------------*/
6161 static unsigned char FPT_scsell(unsigned long p_port, unsigned char targ_id)
6163 unsigned long i;
6165 WR_HARPOON(p_port + hp_page_ctrl,
6166 (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
6168 ARAM_ACCESS(p_port);
6170 WR_HARPOON(p_port + hp_addstat,
6171 (RD_HARPOON(p_port + hp_addstat) | SCAM_TIMER));
6172 WR_HARPOON(p_port + hp_seltimeout, TO_4ms);
6174 for (i = p_port + CMD_STRT; i < p_port + CMD_STRT + 12; i += 2) {
6175 WRW_HARPOON(i, (MPM_OP + ACOMMAND));
6177 WRW_HARPOON(i, (BRH_OP + ALWAYS + NP));
6179 WRW_HARPOON((p_port + hp_intstat),
6180 (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
6182 WR_HARPOON(p_port + hp_select_id, targ_id);
6184 WR_HARPOON(p_port + hp_portctrl_0, SCSI_PORT);
6185 WR_HARPOON(p_port + hp_autostart_3, (SELECT | CMD_ONLY_STRT));
6186 WR_HARPOON(p_port + hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
6188 while (!(RDW_HARPOON((p_port + hp_intstat)) &
6189 (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {
6192 if (RDW_HARPOON((p_port + hp_intstat)) & RESET)
6193 FPT_Wait(p_port, TO_250ms);
6195 DISABLE_AUTO(p_port);
6197 WR_HARPOON(p_port + hp_addstat,
6198 (RD_HARPOON(p_port + hp_addstat) & ~SCAM_TIMER));
6199 WR_HARPOON(p_port + hp_seltimeout, TO_290ms);
6201 SGRAM_ACCESS(p_port);
6203 if (RDW_HARPOON((p_port + hp_intstat)) & (RESET | TIMEOUT)) {
6205 WRW_HARPOON((p_port + hp_intstat),
6206 (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
6208 WR_HARPOON(p_port + hp_page_ctrl,
6209 (RD_HARPOON(p_port + hp_page_ctrl) &
6210 ~G_INT_DISABLE));
6212 return 0; /*No legacy device */
6215 else {
6217 while (!(RDW_HARPOON((p_port + hp_intstat)) & BUS_FREE)) {
6218 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ) {
6219 WR_HARPOON(p_port + hp_scsisig,
6220 (SCSI_ACK + S_ILL_PH));
6221 ACCEPT_MSG(p_port);
6225 WRW_HARPOON((p_port + hp_intstat), CLR_ALL_INT_1);
6227 WR_HARPOON(p_port + hp_page_ctrl,
6228 (RD_HARPOON(p_port + hp_page_ctrl) &
6229 ~G_INT_DISABLE));
6231 return 1; /*Found one of them oldies! */
6235 /*---------------------------------------------------------------------
6237 * Function: FPT_scwtsel
6239 * Description: Wait to be selected by another SCAM initiator.
6241 *---------------------------------------------------------------------*/
6243 static void FPT_scwtsel(unsigned long p_port)
6245 while (!(RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL)) {
6249 /*---------------------------------------------------------------------
6251 * Function: FPT_inisci
6253 * Description: Setup the data Structure with the info from the EEPROM.
6255 *---------------------------------------------------------------------*/
6257 static void FPT_inisci(unsigned char p_card, unsigned long p_port,
6258 unsigned char p_our_id)
6260 unsigned char i, k, max_id;
6261 unsigned short ee_data;
6262 struct nvram_info *pCurrNvRam;
6264 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
6266 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6267 max_id = 0x08;
6269 else
6270 max_id = 0x10;
6272 if (pCurrNvRam) {
6273 for (i = 0; i < max_id; i++) {
6275 for (k = 0; k < 4; k++)
6276 FPT_scamInfo[i].id_string[k] =
6277 pCurrNvRam->niScamTbl[i][k];
6278 for (k = 4; k < ID_STRING_LENGTH; k++)
6279 FPT_scamInfo[i].id_string[k] =
6280 (unsigned char)0x00;
6282 if (FPT_scamInfo[i].id_string[0] == 0x00)
6283 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6284 else
6285 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6288 } else {
6289 for (i = 0; i < max_id; i++) {
6290 for (k = 0; k < ID_STRING_LENGTH; k += 2) {
6291 ee_data =
6292 FPT_utilEERead(p_port,
6293 (unsigned
6294 short)((EE_SCAMBASE / 2) +
6295 (unsigned short)(i *
6296 ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
6297 FPT_scamInfo[i].id_string[k] =
6298 (unsigned char)ee_data;
6299 ee_data >>= 8;
6300 FPT_scamInfo[i].id_string[k + 1] =
6301 (unsigned char)ee_data;
6304 if ((FPT_scamInfo[i].id_string[0] == 0x00) ||
6305 (FPT_scamInfo[i].id_string[0] == 0xFF))
6307 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6309 else
6310 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6314 for (k = 0; k < ID_STRING_LENGTH; k++)
6315 FPT_scamInfo[p_our_id].id_string[k] = FPT_scamHAString[k];
6319 /*---------------------------------------------------------------------
6321 * Function: FPT_scmachid
6323 * Description: Match the Device ID string with our values stored in
6324 * the EEPROM.
6326 *---------------------------------------------------------------------*/
6328 static unsigned char FPT_scmachid(unsigned char p_card,
6329 unsigned char p_id_string[])
6332 unsigned char i, k, match;
6334 for (i = 0; i < MAX_SCSI_TAR; i++) {
6336 match = 1;
6338 for (k = 0; k < ID_STRING_LENGTH; k++) {
6339 if (p_id_string[k] != FPT_scamInfo[i].id_string[k])
6340 match = 0;
6343 if (match) {
6344 FPT_scamInfo[i].state = ID_ASSIGNED;
6345 return i;
6350 if (p_id_string[0] & BIT(5))
6351 i = 8;
6352 else
6353 i = MAX_SCSI_TAR;
6355 if (((p_id_string[0] & 0x06) == 0x02)
6356 || ((p_id_string[0] & 0x06) == 0x04))
6357 match = p_id_string[1] & (unsigned char)0x1F;
6358 else
6359 match = 7;
6361 while (i > 0) {
6362 i--;
6364 if (FPT_scamInfo[match].state == ID_UNUSED) {
6365 for (k = 0; k < ID_STRING_LENGTH; k++) {
6366 FPT_scamInfo[match].id_string[k] =
6367 p_id_string[k];
6370 FPT_scamInfo[match].state = ID_ASSIGNED;
6372 if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
6373 FPT_BL_Card[p_card].globalFlags |=
6374 F_UPDATE_EEPROM;
6375 return match;
6379 match--;
6381 if (match == 0xFF) {
6382 if (p_id_string[0] & BIT(5))
6383 match = 7;
6384 else
6385 match = MAX_SCSI_TAR - 1;
6389 if (p_id_string[0] & BIT(7)) {
6390 return CLR_PRIORITY;
6393 if (p_id_string[0] & BIT(5))
6394 i = 8;
6395 else
6396 i = MAX_SCSI_TAR;
6398 if (((p_id_string[0] & 0x06) == 0x02)
6399 || ((p_id_string[0] & 0x06) == 0x04))
6400 match = p_id_string[1] & (unsigned char)0x1F;
6401 else
6402 match = 7;
6404 while (i > 0) {
6406 i--;
6408 if (FPT_scamInfo[match].state == ID_UNASSIGNED) {
6409 for (k = 0; k < ID_STRING_LENGTH; k++) {
6410 FPT_scamInfo[match].id_string[k] =
6411 p_id_string[k];
6414 FPT_scamInfo[match].id_string[0] |= BIT(7);
6415 FPT_scamInfo[match].state = ID_ASSIGNED;
6416 if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
6417 FPT_BL_Card[p_card].globalFlags |=
6418 F_UPDATE_EEPROM;
6419 return match;
6423 match--;
6425 if (match == 0xFF) {
6426 if (p_id_string[0] & BIT(5))
6427 match = 7;
6428 else
6429 match = MAX_SCSI_TAR - 1;
6433 return NO_ID_AVAIL;
6436 /*---------------------------------------------------------------------
6438 * Function: FPT_scsavdi
6440 * Description: Save off the device SCAM ID strings.
6442 *---------------------------------------------------------------------*/
6444 static void FPT_scsavdi(unsigned char p_card, unsigned long p_port)
6446 unsigned char i, k, max_id;
6447 unsigned short ee_data, sum_data;
6449 sum_data = 0x0000;
6451 for (i = 1; i < EE_SCAMBASE / 2; i++) {
6452 sum_data += FPT_utilEERead(p_port, i);
6455 FPT_utilEEWriteOnOff(p_port, 1); /* Enable write access to the EEPROM */
6457 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6458 max_id = 0x08;
6460 else
6461 max_id = 0x10;
6463 for (i = 0; i < max_id; i++) {
6465 for (k = 0; k < ID_STRING_LENGTH; k += 2) {
6466 ee_data = FPT_scamInfo[i].id_string[k + 1];
6467 ee_data <<= 8;
6468 ee_data |= FPT_scamInfo[i].id_string[k];
6469 sum_data += ee_data;
6470 FPT_utilEEWrite(p_port, ee_data,
6471 (unsigned short)((EE_SCAMBASE / 2) +
6472 (unsigned short)(i *
6473 ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
6477 FPT_utilEEWrite(p_port, sum_data, EEPROM_CHECK_SUM / 2);
6478 FPT_utilEEWriteOnOff(p_port, 0); /* Turn off write access */
6481 /*---------------------------------------------------------------------
6483 * Function: FPT_XbowInit
6485 * Description: Setup the Xbow for normal operation.
6487 *---------------------------------------------------------------------*/
6489 static void FPT_XbowInit(unsigned long port, unsigned char ScamFlg)
6491 unsigned char i;
6493 i = RD_HARPOON(port + hp_page_ctrl);
6494 WR_HARPOON(port + hp_page_ctrl, (unsigned char)(i | G_INT_DISABLE));
6496 WR_HARPOON(port + hp_scsireset, 0x00);
6497 WR_HARPOON(port + hp_portctrl_1, HOST_MODE8);
6499 WR_HARPOON(port + hp_scsireset, (DMA_RESET | HPSCSI_RESET | PROG_RESET |
6500 FIFO_CLR));
6502 WR_HARPOON(port + hp_scsireset, SCSI_INI);
6504 WR_HARPOON(port + hp_clkctrl_0, CLKCTRL_DEFAULT);
6506 WR_HARPOON(port + hp_scsisig, 0x00); /* Clear any signals we might */
6507 WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
6509 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
6511 FPT_default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
6512 BUS_FREE | XFER_CNT_0 | AUTO_INT;
6514 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
6515 FPT_default_intena |= SCAM_SEL;
6517 WRW_HARPOON((port + hp_intena), FPT_default_intena);
6519 WR_HARPOON(port + hp_seltimeout, TO_290ms);
6521 /* Turn on SCSI_MODE8 for narrow cards to fix the
6522 strapping issue with the DUAL CHANNEL card */
6523 if (RD_HARPOON(port + hp_page_ctrl) & NARROW_SCSI_CARD)
6524 WR_HARPOON(port + hp_addstat, SCSI_MODE8);
6526 WR_HARPOON(port + hp_page_ctrl, i);
6530 /*---------------------------------------------------------------------
6532 * Function: FPT_BusMasterInit
6534 * Description: Initialize the BusMaster for normal operations.
6536 *---------------------------------------------------------------------*/
6538 static void FPT_BusMasterInit(unsigned long p_port)
6541 WR_HARPOON(p_port + hp_sys_ctrl, DRVR_RST);
6542 WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
6544 WR_HARPOON(p_port + hp_host_blk_cnt, XFER_BLK64);
6546 WR_HARPOON(p_port + hp_bm_ctrl, (BMCTRL_DEFAULT));
6548 WR_HARPOON(p_port + hp_ee_ctrl, (SCSI_TERM_ENA_H));
6550 RD_HARPOON(p_port + hp_int_status); /*Clear interrupts. */
6551 WR_HARPOON(p_port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
6552 WR_HARPOON(p_port + hp_page_ctrl, (RD_HARPOON(p_port + hp_page_ctrl) &
6553 ~SCATTER_EN));
6556 /*---------------------------------------------------------------------
6558 * Function: FPT_DiagEEPROM
6560 * Description: Verfiy checksum and 'Key' and initialize the EEPROM if
6561 * necessary.
6563 *---------------------------------------------------------------------*/
6565 static void FPT_DiagEEPROM(unsigned long p_port)
6567 unsigned short index, temp, max_wd_cnt;
6569 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6570 max_wd_cnt = EEPROM_WD_CNT;
6571 else
6572 max_wd_cnt = EEPROM_WD_CNT * 2;
6574 temp = FPT_utilEERead(p_port, FW_SIGNATURE / 2);
6576 if (temp == 0x4641) {
6578 for (index = 2; index < max_wd_cnt; index++) {
6580 temp += FPT_utilEERead(p_port, index);
6584 if (temp == FPT_utilEERead(p_port, EEPROM_CHECK_SUM / 2)) {
6586 return; /*EEPROM is Okay so return now! */
6590 FPT_utilEEWriteOnOff(p_port, (unsigned char)1);
6592 for (index = 0; index < max_wd_cnt; index++) {
6594 FPT_utilEEWrite(p_port, 0x0000, index);
6597 temp = 0;
6599 FPT_utilEEWrite(p_port, 0x4641, FW_SIGNATURE / 2);
6600 temp += 0x4641;
6601 FPT_utilEEWrite(p_port, 0x3920, MODEL_NUMB_0 / 2);
6602 temp += 0x3920;
6603 FPT_utilEEWrite(p_port, 0x3033, MODEL_NUMB_2 / 2);
6604 temp += 0x3033;
6605 FPT_utilEEWrite(p_port, 0x2020, MODEL_NUMB_4 / 2);
6606 temp += 0x2020;
6607 FPT_utilEEWrite(p_port, 0x70D3, SYSTEM_CONFIG / 2);
6608 temp += 0x70D3;
6609 FPT_utilEEWrite(p_port, 0x0010, BIOS_CONFIG / 2);
6610 temp += 0x0010;
6611 FPT_utilEEWrite(p_port, 0x0003, SCAM_CONFIG / 2);
6612 temp += 0x0003;
6613 FPT_utilEEWrite(p_port, 0x0007, ADAPTER_SCSI_ID / 2);
6614 temp += 0x0007;
6616 FPT_utilEEWrite(p_port, 0x0000, IGNORE_B_SCAN / 2);
6617 temp += 0x0000;
6618 FPT_utilEEWrite(p_port, 0x0000, SEND_START_ENA / 2);
6619 temp += 0x0000;
6620 FPT_utilEEWrite(p_port, 0x0000, DEVICE_ENABLE / 2);
6621 temp += 0x0000;
6623 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL01 / 2);
6624 temp += 0x4242;
6625 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL23 / 2);
6626 temp += 0x4242;
6627 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL45 / 2);
6628 temp += 0x4242;
6629 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL67 / 2);
6630 temp += 0x4242;
6631 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL89 / 2);
6632 temp += 0x4242;
6633 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLab / 2);
6634 temp += 0x4242;
6635 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLcd / 2);
6636 temp += 0x4242;
6637 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLef / 2);
6638 temp += 0x4242;
6640 FPT_utilEEWrite(p_port, 0x6C46, 64 / 2); /*PRODUCT ID */
6641 temp += 0x6C46;
6642 FPT_utilEEWrite(p_port, 0x7361, 66 / 2); /* FlashPoint LT */
6643 temp += 0x7361;
6644 FPT_utilEEWrite(p_port, 0x5068, 68 / 2);
6645 temp += 0x5068;
6646 FPT_utilEEWrite(p_port, 0x696F, 70 / 2);
6647 temp += 0x696F;
6648 FPT_utilEEWrite(p_port, 0x746E, 72 / 2);
6649 temp += 0x746E;
6650 FPT_utilEEWrite(p_port, 0x4C20, 74 / 2);
6651 temp += 0x4C20;
6652 FPT_utilEEWrite(p_port, 0x2054, 76 / 2);
6653 temp += 0x2054;
6654 FPT_utilEEWrite(p_port, 0x2020, 78 / 2);
6655 temp += 0x2020;
6657 index = ((EE_SCAMBASE / 2) + (7 * 16));
6658 FPT_utilEEWrite(p_port, (0x0700 + TYPE_CODE0), index);
6659 temp += (0x0700 + TYPE_CODE0);
6660 index++;
6661 FPT_utilEEWrite(p_port, 0x5542, index); /*Vendor ID code */
6662 temp += 0x5542; /* BUSLOGIC */
6663 index++;
6664 FPT_utilEEWrite(p_port, 0x4C53, index);
6665 temp += 0x4C53;
6666 index++;
6667 FPT_utilEEWrite(p_port, 0x474F, index);
6668 temp += 0x474F;
6669 index++;
6670 FPT_utilEEWrite(p_port, 0x4349, index);
6671 temp += 0x4349;
6672 index++;
6673 FPT_utilEEWrite(p_port, 0x5442, index); /*Vendor unique code */
6674 temp += 0x5442; /* BT- 930 */
6675 index++;
6676 FPT_utilEEWrite(p_port, 0x202D, index);
6677 temp += 0x202D;
6678 index++;
6679 FPT_utilEEWrite(p_port, 0x3339, index);
6680 temp += 0x3339;
6681 index++; /*Serial # */
6682 FPT_utilEEWrite(p_port, 0x2030, index); /* 01234567 */
6683 temp += 0x2030;
6684 index++;
6685 FPT_utilEEWrite(p_port, 0x5453, index);
6686 temp += 0x5453;
6687 index++;
6688 FPT_utilEEWrite(p_port, 0x5645, index);
6689 temp += 0x5645;
6690 index++;
6691 FPT_utilEEWrite(p_port, 0x2045, index);
6692 temp += 0x2045;
6693 index++;
6694 FPT_utilEEWrite(p_port, 0x202F, index);
6695 temp += 0x202F;
6696 index++;
6697 FPT_utilEEWrite(p_port, 0x4F4A, index);
6698 temp += 0x4F4A;
6699 index++;
6700 FPT_utilEEWrite(p_port, 0x204E, index);
6701 temp += 0x204E;
6702 index++;
6703 FPT_utilEEWrite(p_port, 0x3539, index);
6704 temp += 0x3539;
6706 FPT_utilEEWrite(p_port, temp, EEPROM_CHECK_SUM / 2);
6708 FPT_utilEEWriteOnOff(p_port, (unsigned char)0);
6712 /*---------------------------------------------------------------------
6714 * Function: Queue Search Select
6716 * Description: Try to find a new command to execute.
6718 *---------------------------------------------------------------------*/
6720 static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
6721 unsigned char p_card)
6723 unsigned char scan_ptr, lun;
6724 struct sccb_mgr_tar_info *currTar_Info;
6725 struct sccb *pOldSccb;
6727 scan_ptr = pCurrCard->scanIndex;
6728 do {
6729 currTar_Info = &FPT_sccbMgrTbl[p_card][scan_ptr];
6730 if ((pCurrCard->globalFlags & F_CONLUN_IO) &&
6731 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
6732 TAG_Q_TRYING)) {
6733 if (currTar_Info->TarSelQ_Cnt != 0) {
6735 scan_ptr++;
6736 if (scan_ptr == MAX_SCSI_TAR)
6737 scan_ptr = 0;
6739 for (lun = 0; lun < MAX_LUN; lun++) {
6740 if (currTar_Info->TarLUNBusy[lun] == 0) {
6742 pCurrCard->currentSCCB =
6743 currTar_Info->TarSelQ_Head;
6744 pOldSccb = NULL;
6746 while ((pCurrCard->
6747 currentSCCB != NULL)
6748 && (lun !=
6749 pCurrCard->
6750 currentSCCB->Lun)) {
6751 pOldSccb =
6752 pCurrCard->
6753 currentSCCB;
6754 pCurrCard->currentSCCB =
6755 (struct sccb
6756 *)(pCurrCard->
6757 currentSCCB)->
6758 Sccb_forwardlink;
6760 if (pCurrCard->currentSCCB ==
6761 NULL)
6762 continue;
6763 if (pOldSccb != NULL) {
6764 pOldSccb->
6765 Sccb_forwardlink =
6766 (struct sccb
6767 *)(pCurrCard->
6768 currentSCCB)->
6769 Sccb_forwardlink;
6770 pOldSccb->
6771 Sccb_backlink =
6772 (struct sccb
6773 *)(pCurrCard->
6774 currentSCCB)->
6775 Sccb_backlink;
6776 currTar_Info->
6777 TarSelQ_Cnt--;
6778 } else {
6779 currTar_Info->
6780 TarSelQ_Head =
6781 (struct sccb
6782 *)(pCurrCard->
6783 currentSCCB)->
6784 Sccb_forwardlink;
6786 if (currTar_Info->
6787 TarSelQ_Head ==
6788 NULL) {
6789 currTar_Info->
6790 TarSelQ_Tail
6791 = NULL;
6792 currTar_Info->
6793 TarSelQ_Cnt
6794 = 0;
6795 } else {
6796 currTar_Info->
6797 TarSelQ_Cnt--;
6798 currTar_Info->
6799 TarSelQ_Head->
6800 Sccb_backlink
6802 (struct sccb
6803 *)NULL;
6806 pCurrCard->scanIndex = scan_ptr;
6808 pCurrCard->globalFlags |=
6809 F_NEW_SCCB_CMD;
6811 break;
6816 else {
6817 scan_ptr++;
6818 if (scan_ptr == MAX_SCSI_TAR) {
6819 scan_ptr = 0;
6823 } else {
6824 if ((currTar_Info->TarSelQ_Cnt != 0) &&
6825 (currTar_Info->TarLUNBusy[0] == 0)) {
6827 pCurrCard->currentSCCB =
6828 currTar_Info->TarSelQ_Head;
6830 currTar_Info->TarSelQ_Head =
6831 (struct sccb *)(pCurrCard->currentSCCB)->
6832 Sccb_forwardlink;
6834 if (currTar_Info->TarSelQ_Head == NULL) {
6835 currTar_Info->TarSelQ_Tail = NULL;
6836 currTar_Info->TarSelQ_Cnt = 0;
6837 } else {
6838 currTar_Info->TarSelQ_Cnt--;
6839 currTar_Info->TarSelQ_Head->
6840 Sccb_backlink = (struct sccb *)NULL;
6843 scan_ptr++;
6844 if (scan_ptr == MAX_SCSI_TAR)
6845 scan_ptr = 0;
6847 pCurrCard->scanIndex = scan_ptr;
6849 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
6851 break;
6854 else {
6855 scan_ptr++;
6856 if (scan_ptr == MAX_SCSI_TAR) {
6857 scan_ptr = 0;
6861 } while (scan_ptr != pCurrCard->scanIndex);
6864 /*---------------------------------------------------------------------
6866 * Function: Queue Select Fail
6868 * Description: Add the current SCCB to the head of the Queue.
6870 *---------------------------------------------------------------------*/
6872 static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
6873 unsigned char p_card)
6875 unsigned char thisTarg;
6876 struct sccb_mgr_tar_info *currTar_Info;
6878 if (pCurrCard->currentSCCB != NULL) {
6879 thisTarg =
6880 (unsigned char)(((struct sccb *)(pCurrCard->currentSCCB))->
6881 TargID);
6882 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
6884 pCurrCard->currentSCCB->Sccb_backlink = (struct sccb *)NULL;
6886 pCurrCard->currentSCCB->Sccb_forwardlink =
6887 currTar_Info->TarSelQ_Head;
6889 if (currTar_Info->TarSelQ_Cnt == 0) {
6890 currTar_Info->TarSelQ_Tail = pCurrCard->currentSCCB;
6893 else {
6894 currTar_Info->TarSelQ_Head->Sccb_backlink =
6895 pCurrCard->currentSCCB;
6898 currTar_Info->TarSelQ_Head = pCurrCard->currentSCCB;
6900 pCurrCard->currentSCCB = NULL;
6901 currTar_Info->TarSelQ_Cnt++;
6905 /*---------------------------------------------------------------------
6907 * Function: Queue Command Complete
6909 * Description: Call the callback function with the current SCCB.
6911 *---------------------------------------------------------------------*/
6913 static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
6914 struct sccb *p_sccb, unsigned char p_card)
6917 unsigned char i, SCSIcmd;
6918 CALL_BK_FN callback;
6919 struct sccb_mgr_tar_info *currTar_Info;
6921 SCSIcmd = p_sccb->Cdb[0];
6923 if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED)) {
6925 if ((p_sccb->
6926 ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN))
6927 && (p_sccb->HostStatus == SCCB_COMPLETE)
6928 && (p_sccb->TargetStatus != SSCHECK))
6930 if ((SCSIcmd == SCSI_READ) ||
6931 (SCSIcmd == SCSI_WRITE) ||
6932 (SCSIcmd == SCSI_READ_EXTENDED) ||
6933 (SCSIcmd == SCSI_WRITE_EXTENDED) ||
6934 (SCSIcmd == SCSI_WRITE_AND_VERIFY) ||
6935 (SCSIcmd == SCSI_START_STOP_UNIT) ||
6936 (pCurrCard->globalFlags & F_NO_FILTER)
6938 p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
6941 if (p_sccb->SccbStatus == SCCB_IN_PROCESS) {
6942 if (p_sccb->HostStatus || p_sccb->TargetStatus)
6943 p_sccb->SccbStatus = SCCB_ERROR;
6944 else
6945 p_sccb->SccbStatus = SCCB_SUCCESS;
6948 if (p_sccb->Sccb_XferState & F_AUTO_SENSE) {
6950 p_sccb->CdbLength = p_sccb->Save_CdbLen;
6951 for (i = 0; i < 6; i++) {
6952 p_sccb->Cdb[i] = p_sccb->Save_Cdb[i];
6956 if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
6957 (p_sccb->OperationCode == RESIDUAL_COMMAND)) {
6959 FPT_utilUpdateResidual(p_sccb);
6962 pCurrCard->cmdCounter--;
6963 if (!pCurrCard->cmdCounter) {
6965 if (pCurrCard->globalFlags & F_GREEN_PC) {
6966 WR_HARPOON(pCurrCard->ioPort + hp_clkctrl_0,
6967 (PWR_DWN | CLKCTRL_DEFAULT));
6968 WR_HARPOON(pCurrCard->ioPort + hp_sys_ctrl, STOP_CLK);
6971 WR_HARPOON(pCurrCard->ioPort + hp_semaphore,
6972 (RD_HARPOON(pCurrCard->ioPort + hp_semaphore) &
6973 ~SCCB_MGR_ACTIVE));
6977 if (pCurrCard->discQCount != 0) {
6978 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
6979 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
6980 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
6981 TAG_Q_TRYING))) {
6982 pCurrCard->discQCount--;
6983 pCurrCard->discQ_Tbl[currTar_Info->
6984 LunDiscQ_Idx[p_sccb->Lun]] = NULL;
6985 } else {
6986 if (p_sccb->Sccb_tag) {
6987 pCurrCard->discQCount--;
6988 pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
6989 } else {
6990 pCurrCard->discQCount--;
6991 pCurrCard->discQ_Tbl[currTar_Info->
6992 LunDiscQ_Idx[0]] = NULL;
6998 callback = (CALL_BK_FN) p_sccb->SccbCallback;
6999 callback(p_sccb);
7000 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
7001 pCurrCard->currentSCCB = NULL;
7004 /*---------------------------------------------------------------------
7006 * Function: Queue Disconnect
7008 * Description: Add SCCB to our disconnect array.
7010 *---------------------------------------------------------------------*/
7011 static void FPT_queueDisconnect(struct sccb *p_sccb, unsigned char p_card)
7013 struct sccb_mgr_tar_info *currTar_Info;
7015 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
7017 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
7018 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
7019 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
7020 LunDiscQ_Idx[p_sccb->Lun]] =
7021 p_sccb;
7022 } else {
7023 if (p_sccb->Sccb_tag) {
7024 FPT_BL_Card[p_card].discQ_Tbl[p_sccb->Sccb_tag] =
7025 p_sccb;
7026 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarLUNBusy[0] =
7028 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarTagQ_Cnt++;
7029 } else {
7030 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
7031 LunDiscQ_Idx[0]] = p_sccb;
7034 FPT_BL_Card[p_card].currentSCCB = NULL;
7037 /*---------------------------------------------------------------------
7039 * Function: Queue Flush SCCB
7041 * Description: Flush all SCCB's back to the host driver for this target.
7043 *---------------------------------------------------------------------*/
7045 static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code)
7047 unsigned char qtag, thisTarg;
7048 struct sccb *currSCCB;
7049 struct sccb_mgr_tar_info *currTar_Info;
7051 currSCCB = FPT_BL_Card[p_card].currentSCCB;
7052 if (currSCCB != NULL) {
7053 thisTarg = (unsigned char)currSCCB->TargID;
7054 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7056 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
7058 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7059 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
7060 thisTarg)) {
7062 FPT_BL_Card[p_card].discQ_Tbl[qtag]->
7063 HostStatus = (unsigned char)error_code;
7065 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
7066 FPT_BL_Card[p_card].
7067 discQ_Tbl[qtag], p_card);
7069 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7070 currTar_Info->TarTagQ_Cnt--;
7078 /*---------------------------------------------------------------------
7080 * Function: Queue Flush Target SCCB
7082 * Description: Flush all SCCB's back to the host driver for this target.
7084 *---------------------------------------------------------------------*/
7086 static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
7087 unsigned char error_code)
7089 unsigned char qtag;
7090 struct sccb_mgr_tar_info *currTar_Info;
7092 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7094 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
7096 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7097 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg)) {
7099 FPT_BL_Card[p_card].discQ_Tbl[qtag]->HostStatus =
7100 (unsigned char)error_code;
7102 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
7103 FPT_BL_Card[p_card].
7104 discQ_Tbl[qtag], p_card);
7106 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7107 currTar_Info->TarTagQ_Cnt--;
7114 static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char p_card)
7116 struct sccb_mgr_tar_info *currTar_Info;
7117 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7119 p_SCCB->Sccb_forwardlink = NULL;
7121 p_SCCB->Sccb_backlink = currTar_Info->TarSelQ_Tail;
7123 if (currTar_Info->TarSelQ_Cnt == 0) {
7125 currTar_Info->TarSelQ_Head = p_SCCB;
7128 else {
7130 currTar_Info->TarSelQ_Tail->Sccb_forwardlink = p_SCCB;
7133 currTar_Info->TarSelQ_Tail = p_SCCB;
7134 currTar_Info->TarSelQ_Cnt++;
7137 /*---------------------------------------------------------------------
7139 * Function: Queue Find SCCB
7141 * Description: Search the target select Queue for this SCCB, and
7142 * remove it if found.
7144 *---------------------------------------------------------------------*/
7146 static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
7147 unsigned char p_card)
7149 struct sccb *q_ptr;
7150 struct sccb_mgr_tar_info *currTar_Info;
7152 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7154 q_ptr = currTar_Info->TarSelQ_Head;
7156 while (q_ptr != NULL) {
7158 if (q_ptr == p_SCCB) {
7160 if (currTar_Info->TarSelQ_Head == q_ptr) {
7162 currTar_Info->TarSelQ_Head =
7163 q_ptr->Sccb_forwardlink;
7166 if (currTar_Info->TarSelQ_Tail == q_ptr) {
7168 currTar_Info->TarSelQ_Tail =
7169 q_ptr->Sccb_backlink;
7172 if (q_ptr->Sccb_forwardlink != NULL) {
7173 q_ptr->Sccb_forwardlink->Sccb_backlink =
7174 q_ptr->Sccb_backlink;
7177 if (q_ptr->Sccb_backlink != NULL) {
7178 q_ptr->Sccb_backlink->Sccb_forwardlink =
7179 q_ptr->Sccb_forwardlink;
7182 currTar_Info->TarSelQ_Cnt--;
7184 return 1;
7187 else {
7188 q_ptr = q_ptr->Sccb_forwardlink;
7192 return 0;
7196 /*---------------------------------------------------------------------
7198 * Function: Utility Update Residual Count
7200 * Description: Update the XferCnt to the remaining byte count.
7201 * If we transferred all the data then just write zero.
7202 * If Non-SG transfer then report Total Cnt - Actual Transfer
7203 * Cnt. For SG transfers add the count fields of all
7204 * remaining SG elements, as well as any partial remaining
7205 * element.
7207 *---------------------------------------------------------------------*/
7209 static void FPT_utilUpdateResidual(struct sccb *p_SCCB)
7211 unsigned long partial_cnt;
7212 unsigned int sg_index;
7213 unsigned long *sg_ptr;
7215 if (p_SCCB->Sccb_XferState & F_ALL_XFERRED) {
7217 p_SCCB->DataLength = 0x0000;
7220 else if (p_SCCB->Sccb_XferState & F_SG_XFER) {
7222 partial_cnt = 0x0000;
7224 sg_index = p_SCCB->Sccb_sgseg;
7226 sg_ptr = (unsigned long *)p_SCCB->DataPointer;
7228 if (p_SCCB->Sccb_SGoffset) {
7230 partial_cnt = p_SCCB->Sccb_SGoffset;
7231 sg_index++;
7234 while (((unsigned long)sg_index *
7235 (unsigned long)SG_ELEMENT_SIZE) < p_SCCB->DataLength) {
7237 partial_cnt += *(sg_ptr + (sg_index * 2));
7238 sg_index++;
7241 p_SCCB->DataLength = partial_cnt;
7244 else {
7246 p_SCCB->DataLength -= p_SCCB->Sccb_ATC;
7250 /*---------------------------------------------------------------------
7252 * Function: Wait 1 Second
7254 * Description: Wait for 1 second.
7256 *---------------------------------------------------------------------*/
7258 static void FPT_Wait1Second(unsigned long p_port)
7260 unsigned char i;
7262 for (i = 0; i < 4; i++) {
7264 FPT_Wait(p_port, TO_250ms);
7266 if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
7267 break;
7269 if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
7270 break;
7274 /*---------------------------------------------------------------------
7276 * Function: FPT_Wait
7278 * Description: Wait the desired delay.
7280 *---------------------------------------------------------------------*/
7282 static void FPT_Wait(unsigned long p_port, unsigned char p_delay)
7284 unsigned char old_timer;
7285 unsigned char green_flag;
7287 old_timer = RD_HARPOON(p_port + hp_seltimeout);
7289 green_flag = RD_HARPOON(p_port + hp_clkctrl_0);
7290 WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
7292 WR_HARPOON(p_port + hp_seltimeout, p_delay);
7293 WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
7294 WRW_HARPOON((p_port + hp_intena), (FPT_default_intena & ~TIMEOUT));
7296 WR_HARPOON(p_port + hp_portctrl_0,
7297 (RD_HARPOON(p_port + hp_portctrl_0) | START_TO));
7299 while (!(RDW_HARPOON((p_port + hp_intstat)) & TIMEOUT)) {
7301 if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
7302 break;
7304 if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
7305 break;
7308 WR_HARPOON(p_port + hp_portctrl_0,
7309 (RD_HARPOON(p_port + hp_portctrl_0) & ~START_TO));
7311 WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
7312 WRW_HARPOON((p_port + hp_intena), FPT_default_intena);
7314 WR_HARPOON(p_port + hp_clkctrl_0, green_flag);
7316 WR_HARPOON(p_port + hp_seltimeout, old_timer);
7319 /*---------------------------------------------------------------------
7321 * Function: Enable/Disable Write to EEPROM
7323 * Description: The EEPROM must first be enabled for writes
7324 * A total of 9 clocks are needed.
7326 *---------------------------------------------------------------------*/
7328 static void FPT_utilEEWriteOnOff(unsigned long p_port, unsigned char p_mode)
7330 unsigned char ee_value;
7332 ee_value =
7333 (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
7334 (EXT_ARB_ACK | SCSI_TERM_ENA_H));
7336 if (p_mode)
7338 FPT_utilEESendCmdAddr(p_port, EWEN, EWEN_ADDR);
7340 else
7342 FPT_utilEESendCmdAddr(p_port, EWDS, EWDS_ADDR);
7344 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
7345 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
7348 /*---------------------------------------------------------------------
7350 * Function: Write EEPROM
7352 * Description: Write a word to the EEPROM at the specified
7353 * address.
7355 *---------------------------------------------------------------------*/
7357 static void FPT_utilEEWrite(unsigned long p_port, unsigned short ee_data,
7358 unsigned short ee_addr)
7361 unsigned char ee_value;
7362 unsigned short i;
7364 ee_value =
7365 (unsigned
7366 char)((RD_HARPOON(p_port + hp_ee_ctrl) &
7367 (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
7369 FPT_utilEESendCmdAddr(p_port, EE_WRITE, ee_addr);
7371 ee_value |= (SEE_MS + SEE_CS);
7373 for (i = 0x8000; i != 0; i >>= 1) {
7375 if (i & ee_data)
7376 ee_value |= SEE_DO;
7377 else
7378 ee_value &= ~SEE_DO;
7380 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7381 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7382 ee_value |= SEE_CLK; /* Clock data! */
7383 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7384 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7385 ee_value &= ~SEE_CLK;
7386 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7387 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7389 ee_value &= (EXT_ARB_ACK | SCSI_TERM_ENA_H);
7390 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS));
7392 FPT_Wait(p_port, TO_10ms);
7394 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS | SEE_CS)); /* Set CS to EEPROM */
7395 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /* Turn off CS */
7396 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /* Turn off Master Select */
7399 /*---------------------------------------------------------------------
7401 * Function: Read EEPROM
7403 * Description: Read a word from the EEPROM at the desired
7404 * address.
7406 *---------------------------------------------------------------------*/
7408 static unsigned short FPT_utilEERead(unsigned long p_port,
7409 unsigned short ee_addr)
7411 unsigned short i, ee_data1, ee_data2;
7413 i = 0;
7414 ee_data1 = FPT_utilEEReadOrg(p_port, ee_addr);
7415 do {
7416 ee_data2 = FPT_utilEEReadOrg(p_port, ee_addr);
7418 if (ee_data1 == ee_data2)
7419 return ee_data1;
7421 ee_data1 = ee_data2;
7422 i++;
7424 } while (i < 4);
7426 return ee_data1;
7429 /*---------------------------------------------------------------------
7431 * Function: Read EEPROM Original
7433 * Description: Read a word from the EEPROM at the desired
7434 * address.
7436 *---------------------------------------------------------------------*/
7438 static unsigned short FPT_utilEEReadOrg(unsigned long p_port,
7439 unsigned short ee_addr)
7442 unsigned char ee_value;
7443 unsigned short i, ee_data;
7445 ee_value =
7446 (unsigned
7447 char)((RD_HARPOON(p_port + hp_ee_ctrl) &
7448 (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
7450 FPT_utilEESendCmdAddr(p_port, EE_READ, ee_addr);
7452 ee_value |= (SEE_MS + SEE_CS);
7453 ee_data = 0;
7455 for (i = 1; i <= 16; i++) {
7457 ee_value |= SEE_CLK; /* Clock data! */
7458 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7459 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7460 ee_value &= ~SEE_CLK;
7461 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7462 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7464 ee_data <<= 1;
7466 if (RD_HARPOON(p_port + hp_ee_ctrl) & SEE_DI)
7467 ee_data |= 1;
7470 ee_value &= ~(SEE_MS + SEE_CS);
7471 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
7472 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
7474 return ee_data;
7477 /*---------------------------------------------------------------------
7479 * Function: Send EE command and Address to the EEPROM
7481 * Description: Transfers the correct command and sends the address
7482 * to the eeprom.
7484 *---------------------------------------------------------------------*/
7486 static void FPT_utilEESendCmdAddr(unsigned long p_port, unsigned char ee_cmd,
7487 unsigned short ee_addr)
7489 unsigned char ee_value;
7490 unsigned char narrow_flg;
7492 unsigned short i;
7494 narrow_flg =
7495 (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
7496 NARROW_SCSI_CARD);
7498 ee_value = SEE_MS;
7499 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7501 ee_value |= SEE_CS; /* Set CS to EEPROM */
7502 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7504 for (i = 0x04; i != 0; i >>= 1) {
7506 if (i & ee_cmd)
7507 ee_value |= SEE_DO;
7508 else
7509 ee_value &= ~SEE_DO;
7511 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7512 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7513 ee_value |= SEE_CLK; /* Clock data! */
7514 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7515 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7516 ee_value &= ~SEE_CLK;
7517 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7518 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7521 if (narrow_flg)
7522 i = 0x0080;
7524 else
7525 i = 0x0200;
7527 while (i != 0) {
7529 if (i & ee_addr)
7530 ee_value |= SEE_DO;
7531 else
7532 ee_value &= ~SEE_DO;
7534 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7535 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7536 ee_value |= SEE_CLK; /* Clock data! */
7537 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7538 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7539 ee_value &= ~SEE_CLK;
7540 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7541 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7543 i >>= 1;
7547 static unsigned short FPT_CalcCrc16(unsigned char buffer[])
7549 unsigned short crc = 0;
7550 int i, j;
7551 unsigned short ch;
7552 for (i = 0; i < ID_STRING_LENGTH; i++) {
7553 ch = (unsigned short)buffer[i];
7554 for (j = 0; j < 8; j++) {
7555 if ((crc ^ ch) & 1)
7556 crc = (crc >> 1) ^ CRCMASK;
7557 else
7558 crc >>= 1;
7559 ch >>= 1;
7562 return crc;
7565 static unsigned char FPT_CalcLrc(unsigned char buffer[])
7567 int i;
7568 unsigned char lrc;
7569 lrc = 0;
7570 for (i = 0; i < ID_STRING_LENGTH; i++)
7571 lrc ^= buffer[i];
7572 return lrc;
7576 The following inline definitions avoid type conflicts.
7579 static inline unsigned char
7580 FlashPoint__ProbeHostAdapter(struct FlashPoint_Info *FlashPointInfo)
7582 return FlashPoint_ProbeHostAdapter((struct sccb_mgr_info *)
7583 FlashPointInfo);
7586 static inline FlashPoint_CardHandle_T
7587 FlashPoint__HardwareResetHostAdapter(struct FlashPoint_Info *FlashPointInfo)
7589 return FlashPoint_HardwareResetHostAdapter((struct sccb_mgr_info *)
7590 FlashPointInfo);
7593 static inline void
7594 FlashPoint__ReleaseHostAdapter(FlashPoint_CardHandle_T CardHandle)
7596 FlashPoint_ReleaseHostAdapter(CardHandle);
7599 static inline void
7600 FlashPoint__StartCCB(FlashPoint_CardHandle_T CardHandle,
7601 struct BusLogic_CCB *CCB)
7603 FlashPoint_StartCCB(CardHandle, (struct sccb *)CCB);
7606 static inline void
7607 FlashPoint__AbortCCB(FlashPoint_CardHandle_T CardHandle,
7608 struct BusLogic_CCB *CCB)
7610 FlashPoint_AbortCCB(CardHandle, (struct sccb *)CCB);
7613 static inline boolean
7614 FlashPoint__InterruptPending(FlashPoint_CardHandle_T CardHandle)
7616 return FlashPoint_InterruptPending(CardHandle);
7619 static inline int
7620 FlashPoint__HandleInterrupt(FlashPoint_CardHandle_T CardHandle)
7622 return FlashPoint_HandleInterrupt(CardHandle);
7625 #define FlashPoint_ProbeHostAdapter FlashPoint__ProbeHostAdapter
7626 #define FlashPoint_HardwareResetHostAdapter FlashPoint__HardwareResetHostAdapter
7627 #define FlashPoint_ReleaseHostAdapter FlashPoint__ReleaseHostAdapter
7628 #define FlashPoint_StartCCB FlashPoint__StartCCB
7629 #define FlashPoint_AbortCCB FlashPoint__AbortCCB
7630 #define FlashPoint_InterruptPending FlashPoint__InterruptPending
7631 #define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
7633 #else /* CONFIG_SCSI_OMIT_FLASHPOINT */
7636 Define prototypes for the FlashPoint SCCB Manager Functions.
7639 extern unsigned char FlashPoint_ProbeHostAdapter(struct FlashPoint_Info *);
7640 extern FlashPoint_CardHandle_T
7641 FlashPoint_HardwareResetHostAdapter(struct FlashPoint_Info *);
7642 extern void FlashPoint_StartCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
7643 extern int FlashPoint_AbortCCB(FlashPoint_CardHandle_T, struct BusLogic_CCB *);
7644 extern boolean FlashPoint_InterruptPending(FlashPoint_CardHandle_T);
7645 extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T);
7646 extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T);
7648 #endif /* CONFIG_SCSI_OMIT_FLASHPOINT */