3 FlashPoint.c -- FlashPoint SCCB Manager for Linux
5 This file contains the FlashPoint SCCB Manager from BusLogic's FlashPoint
6 Driver Developer's Kit, with minor modifications by Leonard N. Zubkoff for
7 Linux compatibility. It was provided by BusLogic in the form of 16 separate
8 source files, which would have unnecessarily cluttered the scsi directory, so
9 the individual files have been combined into this single file.
11 Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
13 This file is available under both the GNU General Public License
14 and a BSD-style copyright; see LICENSE.FlashPoint for details.
19 #ifdef CONFIG_SCSI_FLASHPOINT
24 #define CRCMASK 0xA001
26 #define FAILURE 0xFFFFFFFFL
29 typedef void (*CALL_BK_FN) (struct sccb *);
31 struct sccb_mgr_info {
33 unsigned char si_present;
34 unsigned char si_intvect;
38 u16 si_per_targ_init_sync;
39 u16 si_per_targ_fast_nego;
40 u16 si_per_targ_ultra_nego;
41 u16 si_per_targ_no_disc;
42 u16 si_per_targ_wide_nego;
44 unsigned char si_card_family;
45 unsigned char si_bustype;
46 unsigned char si_card_model[3];
47 unsigned char si_relative_cardnum;
48 unsigned char si_reserved[4];
50 unsigned char si_XlatInfo[4];
52 u32 si_secondary_range;
55 #define SCSI_PARITY_ENA 0x0001
56 #define LOW_BYTE_TERM 0x0010
57 #define HIGH_BYTE_TERM 0x0020
58 #define BUSTYPE_PCI 0x3
60 #define SUPPORT_16TAR_32LUN 0x0002
61 #define SOFT_RESET 0x0004
62 #define EXTENDED_TRANSLATION 0x0008
63 #define POST_ALL_UNDERRRUNS 0x0040
64 #define FLAG_SCAM_ENABLED 0x0080
65 #define FLAG_SCAM_LEVEL2 0x0100
67 #define HARPOON_FAMILY 0x02
69 /* SCCB struct used for both SCCB and UCB manager compiles!
70 * The UCB Manager treats the SCCB as it's 'native hardware structure'
75 unsigned char OperationCode;
76 unsigned char ControlByte;
77 unsigned char CdbLength;
78 unsigned char RequestSenseLength;
81 unsigned char CcbRes[2];
82 unsigned char HostStatus;
83 unsigned char TargetStatus;
86 unsigned char Cdb[12];
87 unsigned char CcbRes1;
88 unsigned char Reserved1;
92 CALL_BK_FN SccbCallback; /* VOID (*SccbCallback)(); */
93 u32 SccbIOPort; /* Identifies board base port */
94 unsigned char SccbStatus;
95 unsigned char SCCBRes2;
98 u32 Sccb_XferCnt; /* actual transfer count */
100 u32 SccbVirtDataPtr; /* virtual addr for OS/2 */
104 unsigned char Sccb_scsimsg; /* identify msg for selection */
105 unsigned char Sccb_tag;
106 unsigned char Sccb_scsistat;
107 unsigned char Sccb_idmsg; /* image of last msg in */
108 struct sccb *Sccb_forwardlink;
109 struct sccb *Sccb_backlink;
111 unsigned char Save_Cdb[6];
112 unsigned char Save_CdbLen;
113 unsigned char Sccb_XferState;
119 #define SCATTER_GATHER_COMMAND 0x02
120 #define RESIDUAL_COMMAND 0x03
121 #define RESIDUAL_SG_COMMAND 0x04
122 #define RESET_COMMAND 0x81
124 #define F_USE_CMD_Q 0x20 /*Inidcates TAGGED command. */
125 #define TAG_TYPE_MASK 0xC0 /*Type of tag msg to send. */
126 #define SCCB_DATA_XFER_OUT 0x10 /* Write */
127 #define SCCB_DATA_XFER_IN 0x08 /* Read */
129 #define NO_AUTO_REQUEST_SENSE 0x01 /* No Request Sense Buffer */
131 #define BUS_FREE_ST 0
133 #define SELECT_BDR_ST 2 /* Select w\ Bus Device Reset */
134 #define SELECT_SN_ST 3 /* Select w\ Sync Nego */
135 #define SELECT_WN_ST 4 /* Select w\ Wide Data Nego */
136 #define SELECT_Q_ST 5 /* Select w\ Tagged Q'ing */
138 #define DATA_OUT_ST 7
140 #define DISCONNECT_ST 9
143 #define F_HOST_XFER_DIR 0x01
144 #define F_ALL_XFERRED 0x02
145 #define F_SG_XFER 0x04
146 #define F_AUTO_SENSE 0x08
147 #define F_ODD_BALL_CNT 0x10
148 #define F_NO_DATA_YET 0x80
150 #define F_STATUSLOADED 0x01
151 #define F_DEV_SELECTED 0x04
153 #define SCCB_COMPLETE 0x00 /* SCCB completed without error */
154 #define SCCB_DATA_UNDER_RUN 0x0C
155 #define SCCB_SELECTION_TIMEOUT 0x11 /* Set SCSI selection timed out */
156 #define SCCB_DATA_OVER_RUN 0x12
157 #define SCCB_PHASE_SEQUENCE_FAIL 0x14 /* Target bus phase sequence failure */
159 #define SCCB_GROSS_FW_ERR 0x27 /* Major problem! */
160 #define SCCB_BM_ERR 0x30 /* BusMaster error. */
161 #define SCCB_PARITY_ERR 0x34 /* SCSI parity error */
163 #define SCCB_IN_PROCESS 0x00
164 #define SCCB_SUCCESS 0x01
165 #define SCCB_ABORT 0x02
166 #define SCCB_ERROR 0x04
168 #define ORION_FW_REV 3110
170 #define QUEUE_DEPTH 254+1 /*1 for Normal disconnect 32 for Q'ing. */
172 #define MAX_MB_CARDS 4 /* Max. no of cards suppoerted on Mother Board */
174 #define MAX_SCSI_TAR 16
176 #define LUN_MASK 0x1f
178 #define SG_BUF_CNT 16 /*Number of prefetched elements. */
180 #define SG_ELEMENT_SIZE 8 /*Eight byte per element. */
182 #define RD_HARPOON(ioport) inb((u32)ioport)
183 #define RDW_HARPOON(ioport) inw((u32)ioport)
184 #define RD_HARP32(ioport,offset,data) (data = inl((u32)(ioport + offset)))
185 #define WR_HARPOON(ioport,val) outb((u8) val, (u32)ioport)
186 #define WRW_HARPOON(ioport,val) outw((u16)val, (u32)ioport)
187 #define WR_HARP32(ioport,offset,data) outl(data, (u32)(ioport + offset))
189 #define TAR_SYNC_MASK (BIT(7)+BIT(6))
190 #define SYNC_TRYING BIT(6)
191 #define SYNC_SUPPORTED (BIT(7)+BIT(6))
193 #define TAR_WIDE_MASK (BIT(5)+BIT(4))
194 #define WIDE_ENABLED BIT(4)
195 #define WIDE_NEGOCIATED BIT(5)
197 #define TAR_TAG_Q_MASK (BIT(3)+BIT(2))
198 #define TAG_Q_TRYING BIT(2)
199 #define TAG_Q_REJECT BIT(3)
201 #define TAR_ALLOW_DISC BIT(0)
203 #define EE_SYNC_MASK (BIT(0)+BIT(1))
204 #define EE_SYNC_5MB BIT(0)
205 #define EE_SYNC_10MB BIT(1)
206 #define EE_SYNC_20MB (BIT(0)+BIT(1))
208 #define EE_WIDE_SCSI BIT(7)
210 struct sccb_mgr_tar_info {
212 struct sccb *TarSelQ_Head;
213 struct sccb *TarSelQ_Tail;
214 unsigned char TarLUN_CA; /*Contingent Allgiance */
215 unsigned char TarTagQ_Cnt;
216 unsigned char TarSelQ_Cnt;
217 unsigned char TarStatus;
218 unsigned char TarEEValue;
219 unsigned char TarSyncCtrl;
220 unsigned char TarReserved[2]; /* for alignment */
221 unsigned char LunDiscQ_Idx[MAX_LUN];
222 unsigned char TarLUNBusy[MAX_LUN];
226 unsigned char niModel; /* Model No. of card */
227 unsigned char niCardNo; /* Card no. */
228 u32 niBaseAddr; /* Port Address of card */
229 unsigned char niSysConf; /* Adapter Configuration byte -
230 Byte 16 of eeprom map */
231 unsigned char niScsiConf; /* SCSI Configuration byte -
232 Byte 17 of eeprom map */
233 unsigned char niScamConf; /* SCAM Configuration byte -
234 Byte 20 of eeprom map */
235 unsigned char niAdapId; /* Host Adapter ID -
236 Byte 24 of eerpom map */
237 unsigned char niSyncTbl[MAX_SCSI_TAR / 2]; /* Sync/Wide byte
239 unsigned char niScamTbl[MAX_SCSI_TAR][4]; /* Compressed Scam name
249 struct sccb *currentSCCB;
250 struct sccb_mgr_info *cardInfo;
254 unsigned short cmdCounter;
255 unsigned char discQCount;
256 unsigned char tagQ_Lst;
257 unsigned char cardIndex;
258 unsigned char scanIndex;
259 unsigned char globalFlags;
261 struct nvram_info *pNvRamInfo;
262 struct sccb *discQ_Tbl[QUEUE_DEPTH];
266 #define F_TAG_STARTED 0x01
267 #define F_CONLUN_IO 0x02
268 #define F_DO_RENEGO 0x04
269 #define F_NO_FILTER 0x08
270 #define F_GREEN_PC 0x10
271 #define F_HOST_XFER_ACT 0x20
272 #define F_NEW_SCCB_CMD 0x40
273 #define F_UPDATE_EEPROM 0x80
275 #define ID_STRING_LENGTH 32
276 #define TYPE_CODE0 0x63 /*Level2 Mstr (bits 7-6), */
278 #define SLV_TYPE_CODE0 0xA3 /*Priority Bit set (bits 7-6), */
280 #define ASSIGN_ID 0x00
281 #define SET_P_FLAG 0x01
282 #define CFG_CMPLT 0x03
283 #define DOM_MSTR 0x0F
284 #define SYNC_PTRN 0x1F
288 #define MISC_CODE 0x14
289 #define CLR_P_FLAG 0x18
291 #define INIT_SELTD 0x01
292 #define LEVEL2_TAR 0x02
294 enum scam_id_st { ID0, ID1, ID2, ID3, ID4, ID5, ID6, ID7, ID8, ID9, ID10, ID11,
296 ID13, ID14, ID15, ID_UNUSED, ID_UNASSIGNED, ID_ASSIGNED, LEGACY,
297 CLR_PRIORITY, NO_ID_AVAIL
300 typedef struct SCCBscam_info {
302 unsigned char id_string[ID_STRING_LENGTH];
303 enum scam_id_st state;
307 #define SCSI_REQUEST_SENSE 0x03
308 #define SCSI_READ 0x08
309 #define SCSI_WRITE 0x0A
310 #define SCSI_START_STOP_UNIT 0x1B
311 #define SCSI_READ_EXTENDED 0x28
312 #define SCSI_WRITE_EXTENDED 0x2A
313 #define SCSI_WRITE_AND_VERIFY 0x2E
317 #define SSQ_FULL 0x28
319 #define SMCMD_COMP 0x00
321 #define SMSAVE_DATA_PTR 0x02
322 #define SMREST_DATA_PTR 0x03
325 #define SMREJECT 0x07
327 #define SMPARITY 0x09
328 #define SMDEV_RESET 0x0C
329 #define SMABORT_TAG 0x0D
330 #define SMINIT_RECOVERY 0x0F
331 #define SMREL_RECOVERY 0x10
334 #define DISC_PRIV 0x40
340 #define SMIGNORWR 0x23 /* Ignore Wide Residue */
342 #define SIX_BYTE_CMD 0x06
343 #define TWELVE_BYTE_CMD 0x0C
346 #define MAX_OFFSET 0x0F /* Maxbyteoffset for Sync Xfers */
348 #define EEPROM_WD_CNT 256
350 #define EEPROM_CHECK_SUM 0
351 #define FW_SIGNATURE 2
352 #define MODEL_NUMB_0 4
353 #define MODEL_NUMB_2 6
354 #define MODEL_NUMB_4 8
355 #define SYSTEM_CONFIG 16
356 #define SCSI_CONFIG 17
357 #define BIOS_CONFIG 18
358 #define SCAM_CONFIG 20
359 #define ADAPTER_SCSI_ID 24
361 #define IGNORE_B_SCAN 32
362 #define SEND_START_ENA 34
363 #define DEVICE_ENABLE 36
365 #define SYNC_RATE_TBL 38
366 #define SYNC_RATE_TBL01 38
367 #define SYNC_RATE_TBL23 40
368 #define SYNC_RATE_TBL45 42
369 #define SYNC_RATE_TBL67 44
370 #define SYNC_RATE_TBL89 46
371 #define SYNC_RATE_TBLab 48
372 #define SYNC_RATE_TBLcd 50
373 #define SYNC_RATE_TBLef 52
375 #define EE_SCAMBASE 256
377 #define SCAM_ENABLED BIT(2)
378 #define SCAM_LEVEL2 BIT(3)
380 #define RENEGO_ENA BIT(10)
381 #define CONNIO_ENA BIT(11)
382 #define GREEN_PC_ENA BIT(12)
384 #define AUTO_RATE_00 00
385 #define AUTO_RATE_05 01
386 #define AUTO_RATE_10 02
387 #define AUTO_RATE_20 03
389 #define WIDE_NEGO_BIT BIT(7)
390 #define DISC_ENABLE_BIT BIT(6)
392 #define hp_vendor_id_0 0x00 /* LSB */
393 #define ORION_VEND_0 0x4B
395 #define hp_vendor_id_1 0x01 /* MSB */
396 #define ORION_VEND_1 0x10
398 #define hp_device_id_0 0x02 /* LSB */
399 #define ORION_DEV_0 0x30
401 #define hp_device_id_1 0x03 /* MSB */
402 #define ORION_DEV_1 0x81
404 /* Sub Vendor ID and Sub Device ID only available in
405 Harpoon Version 2 and higher */
407 #define hp_sub_device_id_0 0x06 /* LSB */
409 #define hp_semaphore 0x0C
410 #define SCCB_MGR_ACTIVE BIT(0)
411 #define TICKLE_ME BIT(1)
412 #define SCCB_MGR_PRESENT BIT(3)
413 #define BIOS_IN_USE BIT(4)
415 #define hp_sys_ctrl 0x0F
417 #define STOP_CLK BIT(0) /*Turn off BusMaster Clock */
418 #define DRVR_RST BIT(1) /*Firmware Reset to 80C15 chip */
419 #define HALT_MACH BIT(3) /*Halt State Machine */
420 #define HARD_ABORT BIT(4) /*Hard Abort */
422 #define hp_host_blk_cnt 0x13
424 #define XFER_BLK64 0x06 /* 1 1 0 64 byte per block */
426 #define BM_THRESHOLD 0x40 /* PCI mode can only xfer 16 bytes */
428 #define hp_int_mask 0x17
430 #define INT_CMD_COMPL BIT(0) /* DMA command complete */
431 #define INT_EXT_STATUS BIT(1) /* Extended Status Set */
433 #define hp_xfer_cnt_lo 0x18
434 #define hp_xfer_cnt_hi 0x1A
435 #define hp_xfer_cmd 0x1B
437 #define XFER_HOST_DMA 0x00 /* 0 0 0 Transfer Host -> DMA */
438 #define XFER_DMA_HOST 0x01 /* 0 0 1 Transfer DMA -> Host */
440 #define XFER_HOST_AUTO 0x00 /* 0 0 Auto Transfer Size */
442 #define XFER_DMA_8BIT 0x20 /* 0 1 8 BIT Transfer Size */
444 #define DISABLE_INT BIT(7) /*Do not interrupt at end of cmd. */
446 #define HOST_WRT_CMD ((DISABLE_INT + XFER_HOST_DMA + XFER_HOST_AUTO + XFER_DMA_8BIT))
447 #define HOST_RD_CMD ((DISABLE_INT + XFER_DMA_HOST + XFER_HOST_AUTO + XFER_DMA_8BIT))
449 #define hp_host_addr_lo 0x1C
450 #define hp_host_addr_hmi 0x1E
452 #define hp_ee_ctrl 0x22
454 #define EXT_ARB_ACK BIT(7)
455 #define SCSI_TERM_ENA_H BIT(6) /* SCSI high byte terminator */
456 #define SEE_MS BIT(5)
457 #define SEE_CS BIT(3)
458 #define SEE_CLK BIT(2)
459 #define SEE_DO BIT(1)
460 #define SEE_DI BIT(0)
463 #define EE_WRITE 0x05
465 #define EWEN_ADDR 0x03C0
467 #define EWDS_ADDR 0x0000
469 #define hp_bm_ctrl 0x26
471 #define SCSI_TERM_ENA_L BIT(0) /*Enable/Disable external terminators */
472 #define FLUSH_XFER_CNTR BIT(1) /*Flush transfer counter */
473 #define FORCE1_XFER BIT(5) /*Always xfer one byte in byte mode */
474 #define FAST_SINGLE BIT(6) /*?? */
476 #define BMCTRL_DEFAULT (FORCE1_XFER|FAST_SINGLE|SCSI_TERM_ENA_L)
478 #define hp_sg_addr 0x28
479 #define hp_page_ctrl 0x29
481 #define SCATTER_EN BIT(0)
482 #define SGRAM_ARAM BIT(1)
483 #define G_INT_DISABLE BIT(3) /* Enable/Disable all Interrupts */
484 #define NARROW_SCSI_CARD BIT(4) /* NARROW/WIDE SCSI config pin */
486 #define hp_pci_stat_cfg 0x2D
488 #define REC_MASTER_ABORT BIT(5) /*received Master abort */
490 #define hp_rev_num 0x33
492 #define hp_stack_data 0x34
493 #define hp_stack_addr 0x35
495 #define hp_ext_status 0x36
497 #define BM_FORCE_OFF BIT(0) /*Bus Master is forced to get off */
498 #define PCI_TGT_ABORT BIT(0) /*PCI bus master transaction aborted */
499 #define PCI_DEV_TMOUT BIT(1) /*PCI Device Time out */
500 #define CMD_ABORTED BIT(4) /*Command aborted */
501 #define BM_PARITY_ERR BIT(5) /*parity error on data received */
502 #define PIO_OVERRUN BIT(6) /*Slave data overrun */
503 #define BM_CMD_BUSY BIT(7) /*Bus master transfer command busy */
504 #define BAD_EXT_STATUS (BM_FORCE_OFF | PCI_DEV_TMOUT | CMD_ABORTED | \
505 BM_PARITY_ERR | PIO_OVERRUN)
507 #define hp_int_status 0x37
509 #define EXT_STATUS_ON BIT(1) /*Extended status is valid */
510 #define SCSI_INTERRUPT BIT(2) /*Global indication of a SCSI int. */
511 #define INT_ASSERTED BIT(5) /* */
513 #define hp_fifo_cnt 0x38
515 #define hp_intena 0x40
518 #define PROG_HLT BIT(6)
519 #define PARITY BIT(5)
522 #define SCAM_SEL BIT(2)
524 #define TIMEOUT BIT(0)
525 #define BUS_FREE BIT(15)
526 #define XFER_CNT_0 BIT(14)
527 #define PHASE BIT(13)
528 #define IUNKWN BIT(12)
529 #define ICMD_COMP BIT(11)
530 #define ITICKLE BIT(10)
531 #define IDO_STRT BIT(9)
532 #define ITAR_DISC BIT(8)
533 #define AUTO_INT (BIT(12)+BIT(11)+BIT(10)+BIT(9)+BIT(8))
534 #define CLR_ALL_INT 0xFFFF
535 #define CLR_ALL_INT_1 0xFF00
537 #define hp_intstat 0x42
539 #define hp_scsisig 0x44
541 #define SCSI_SEL BIT(7)
542 #define SCSI_BSY BIT(6)
543 #define SCSI_REQ BIT(5)
544 #define SCSI_ACK BIT(4)
545 #define SCSI_ATN BIT(3)
546 #define SCSI_CD BIT(2)
547 #define SCSI_MSG BIT(1)
548 #define SCSI_IOBIT BIT(0)
550 #define S_SCSI_PHZ (BIT(2)+BIT(1)+BIT(0))
551 #define S_MSGO_PH (BIT(2)+BIT(1) )
552 #define S_MSGI_PH (BIT(2)+BIT(1)+BIT(0))
553 #define S_DATAI_PH ( BIT(0))
554 #define S_DATAO_PH 0x00
555 #define S_ILL_PH ( BIT(1) )
557 #define hp_scsictrl_0 0x45
559 #define SEL_TAR BIT(6)
560 #define ENA_ATN BIT(4)
561 #define ENA_RESEL BIT(2)
562 #define SCSI_RST BIT(1)
563 #define ENA_SCAM_SEL BIT(0)
565 #define hp_portctrl_0 0x46
567 #define SCSI_PORT BIT(7)
568 #define SCSI_INBIT BIT(6)
569 #define DMA_PORT BIT(5)
570 #define DMA_RD BIT(4)
571 #define HOST_PORT BIT(3)
572 #define HOST_WRT BIT(2)
573 #define SCSI_BUS_EN BIT(1)
574 #define START_TO BIT(0)
576 #define hp_scsireset 0x47
578 #define SCSI_INI BIT(6)
579 #define SCAM_EN BIT(5)
580 #define DMA_RESET BIT(3)
581 #define HPSCSI_RESET BIT(2)
582 #define PROG_RESET BIT(1)
583 #define FIFO_CLR BIT(0)
585 #define hp_xfercnt_0 0x48
586 #define hp_xfercnt_2 0x4A
588 #define hp_fifodata_0 0x4C
589 #define hp_addstat 0x4E
591 #define SCAM_TIMER BIT(7)
592 #define SCSI_MODE8 BIT(3)
593 #define SCSI_PAR_ERR BIT(0)
595 #define hp_prgmcnt_0 0x4F
597 #define hp_selfid_0 0x50
598 #define hp_selfid_1 0x51
599 #define hp_arb_id 0x52
601 #define hp_select_id 0x53
603 #define hp_synctarg_base 0x54
604 #define hp_synctarg_12 0x54
605 #define hp_synctarg_13 0x55
606 #define hp_synctarg_14 0x56
607 #define hp_synctarg_15 0x57
609 #define hp_synctarg_8 0x58
610 #define hp_synctarg_9 0x59
611 #define hp_synctarg_10 0x5A
612 #define hp_synctarg_11 0x5B
614 #define hp_synctarg_4 0x5C
615 #define hp_synctarg_5 0x5D
616 #define hp_synctarg_6 0x5E
617 #define hp_synctarg_7 0x5F
619 #define hp_synctarg_0 0x60
620 #define hp_synctarg_1 0x61
621 #define hp_synctarg_2 0x62
622 #define hp_synctarg_3 0x63
624 #define NARROW_SCSI BIT(4)
625 #define DEFAULT_OFFSET 0x0F
627 #define hp_autostart_0 0x64
628 #define hp_autostart_1 0x65
629 #define hp_autostart_3 0x67
631 #define AUTO_IMMED BIT(5)
632 #define SELECT BIT(6)
633 #define END_DATA (BIT(7)+BIT(6))
635 #define hp_gp_reg_0 0x68
636 #define hp_gp_reg_1 0x69
637 #define hp_gp_reg_3 0x6B
639 #define hp_seltimeout 0x6C
641 #define TO_4ms 0x67 /* 3.9959ms */
643 #define TO_5ms 0x03 /* 4.9152ms */
644 #define TO_10ms 0x07 /* 11.xxxms */
645 #define TO_250ms 0x99 /* 250.68ms */
646 #define TO_290ms 0xB1 /* 289.99ms */
648 #define hp_clkctrl_0 0x6D
650 #define PWR_DWN BIT(6)
651 #define ACTdeassert BIT(4)
652 #define CLK_40MHZ (BIT(1) + BIT(0))
654 #define CLKCTRL_DEFAULT (ACTdeassert | CLK_40MHZ)
656 #define hp_fiforead 0x6E
657 #define hp_fifowrite 0x6F
659 #define hp_offsetctr 0x70
660 #define hp_xferstat 0x71
662 #define FIFO_EMPTY BIT(6)
664 #define hp_portctrl_1 0x72
666 #define CHK_SCSI_P BIT(3)
667 #define HOST_MODE8 BIT(0)
669 #define hp_xfer_pad 0x73
671 #define ID_UNLOCK BIT(3)
673 #define hp_scsidata_0 0x74
674 #define hp_scsidata_1 0x75
676 #define hp_aramBase 0x80
677 #define BIOS_DATA_OFFSET 0x60
678 #define BIOS_RELATIVE_CARD 0x64
680 #define AR3 (BIT(9) + BIT(8))
681 #define SDATA BIT(10)
683 #define CRD_OP BIT(11) /* Cmp Reg. w/ Data */
685 #define CRR_OP BIT(12) /* Cmp Reg. w. Reg. */
687 #define CPE_OP (BIT(14)+BIT(11)) /* Cmp SCSI phs & Branch EQ */
689 #define CPN_OP (BIT(14)+BIT(12)) /* Cmp SCSI phs & Branch NOT EQ */
691 #define ADATA_OUT 0x00
692 #define ADATA_IN BIT(8)
693 #define ACOMMAND BIT(10)
694 #define ASTATUS (BIT(10)+BIT(8))
695 #define AMSG_OUT (BIT(10)+BIT(9))
696 #define AMSG_IN (BIT(10)+BIT(9)+BIT(8))
698 #define BRH_OP BIT(13) /* Branch */
702 #define NOT_EQ BIT(9)
704 #define TCB_OP (BIT(13)+BIT(11)) /* Test condition & branch */
706 #define FIFO_0 BIT(10)
708 #define MPM_OP BIT(15) /* Match phase and move data */
710 #define MRR_OP BIT(14) /* Move DReg. to Reg. */
712 #define S_IDREG (BIT(2)+BIT(1)+BIT(0))
716 #define D_BUCKET (BIT(2) + BIT(1) + BIT(0))
718 #define RAT_OP (BIT(14)+BIT(13)+BIT(11))
720 #define SSI_OP (BIT(15)+BIT(11))
722 #define SSI_ITAR_DISC (ITAR_DISC >> 8)
723 #define SSI_IDO_STRT (IDO_STRT >> 8)
725 #define SSI_ICMD_COMP (ICMD_COMP >> 8)
726 #define SSI_ITICKLE (ITICKLE >> 8)
728 #define SSI_IUNKWN (IUNKWN >> 8)
729 #define SSI_INO_CC (IUNKWN >> 8)
730 #define SSI_IRFAIL (IUNKWN >> 8)
732 #define NP 0x10 /*Next Phase */
733 #define NTCMD 0x02 /*Non- Tagged Command start */
734 #define CMDPZ 0x04 /*Command phase */
735 #define DINT 0x12 /*Data Out/In interrupt */
736 #define DI 0x13 /*Data Out */
737 #define DC 0x19 /*Disconnect Message */
738 #define ST 0x1D /*Status Phase */
739 #define UNKNWN 0x24 /*Unknown bus action */
740 #define CC 0x25 /*Command Completion failure */
741 #define TICK 0x26 /*New target reselected us. */
742 #define SELCHK 0x28 /*Select & Check SCSI ID latch reg */
744 #define ID_MSG_STRT hp_aramBase + 0x00
745 #define NON_TAG_ID_MSG hp_aramBase + 0x06
746 #define CMD_STRT hp_aramBase + 0x08
747 #define SYNC_MSGS hp_aramBase + 0x08
749 #define TAG_STRT 0x00
750 #define DISCONNECT_START 0x10/2
751 #define END_DATA_START 0x14/2
752 #define CMD_ONLY_STRT CMDPZ/2
753 #define SELCHK_STRT SELCHK/2
755 #define GET_XFER_CNT(port, xfercnt) {RD_HARP32(port,hp_xfercnt_0,xfercnt); xfercnt &= 0xFFFFFF;}
756 /* #define GET_XFER_CNT(port, xfercnt) (xfercnt = RD_HARPOON(port+hp_xfercnt_2), \
758 xfercnt |= RDW_HARPOON((unsigned short)(port+hp_xfercnt_0)))
760 #define HP_SETUP_ADDR_CNT(port,addr,count) (WRW_HARPOON((port+hp_host_addr_lo), (unsigned short)(addr & 0x0000FFFFL)),\
762 WRW_HARPOON((port+hp_host_addr_hmi), (unsigned short)(addr & 0x0000FFFFL)),\
763 WR_HARP32(port,hp_xfercnt_0,count),\
764 WRW_HARPOON((port+hp_xfer_cnt_lo), (unsigned short)(count & 0x0000FFFFL)),\
766 WR_HARPOON(port+hp_xfer_cnt_hi, (count & 0xFF)))
768 #define ACCEPT_MSG(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
769 WR_HARPOON(port+hp_scsisig, S_ILL_PH);}
771 #define ACCEPT_MSG_ATN(port) {while(RD_HARPOON(port+hp_scsisig) & SCSI_REQ){}\
772 WR_HARPOON(port+hp_scsisig, (S_ILL_PH|SCSI_ATN));}
774 #define DISABLE_AUTO(port) (WR_HARPOON(port+hp_scsireset, PROG_RESET),\
775 WR_HARPOON(port+hp_scsireset, 0x00))
777 #define ARAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
778 (RD_HARPOON(p_port+hp_page_ctrl) | SGRAM_ARAM)))
780 #define SGRAM_ACCESS(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
781 (RD_HARPOON(p_port+hp_page_ctrl) & ~SGRAM_ARAM)))
783 #define MDISABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
784 (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE)))
786 #define MENABLE_INT(p_port) (WR_HARPOON(p_port+hp_page_ctrl, \
787 (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE)))
789 static unsigned char FPT_sisyncn(u32 port, unsigned char p_card,
790 unsigned char syncFlag);
791 static void FPT_ssel(u32 port, unsigned char p_card);
792 static void FPT_sres(u32 port, unsigned char p_card,
793 struct sccb_card *pCurrCard);
794 static void FPT_shandem(u32 port, unsigned char p_card,
795 struct sccb *pCurrSCCB);
796 static void FPT_stsyncn(u32 port, unsigned char p_card);
797 static void FPT_sisyncr(u32 port, unsigned char sync_pulse,
798 unsigned char offset);
799 static void FPT_sssyncv(u32 p_port, unsigned char p_id,
800 unsigned char p_sync_value,
801 struct sccb_mgr_tar_info *currTar_Info);
802 static void FPT_sresb(u32 port, unsigned char p_card);
803 static void FPT_sxfrp(u32 p_port, unsigned char p_card);
804 static void FPT_schkdd(u32 port, unsigned char p_card);
805 static unsigned char FPT_RdStack(u32 port, unsigned char index);
806 static void FPT_WrStack(u32 portBase, unsigned char index,
808 static unsigned char FPT_ChkIfChipInitialized(u32 ioPort);
810 static void FPT_SendMsg(u32 port, unsigned char message);
811 static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
812 unsigned char error_code);
814 static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card);
815 static void FPT_RNVRamData(struct nvram_info *pNvRamInfo);
817 static unsigned char FPT_siwidn(u32 port, unsigned char p_card);
818 static void FPT_stwidn(u32 port, unsigned char p_card);
819 static void FPT_siwidr(u32 port, unsigned char width);
821 static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
822 unsigned char p_card);
823 static void FPT_queueDisconnect(struct sccb *p_SCCB, unsigned char p_card);
824 static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
825 struct sccb *p_SCCB, unsigned char p_card);
826 static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
827 unsigned char p_card);
828 static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code);
829 static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char card);
830 static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
831 unsigned char p_card);
832 static void FPT_utilUpdateResidual(struct sccb *p_SCCB);
833 static unsigned short FPT_CalcCrc16(unsigned char buffer[]);
834 static unsigned char FPT_CalcLrc(unsigned char buffer[]);
836 static void FPT_Wait1Second(u32 p_port);
837 static void FPT_Wait(u32 p_port, unsigned char p_delay);
838 static void FPT_utilEEWriteOnOff(u32 p_port, unsigned char p_mode);
839 static void FPT_utilEEWrite(u32 p_port, unsigned short ee_data,
840 unsigned short ee_addr);
841 static unsigned short FPT_utilEERead(u32 p_port,
842 unsigned short ee_addr);
843 static unsigned short FPT_utilEEReadOrg(u32 p_port,
844 unsigned short ee_addr);
845 static void FPT_utilEESendCmdAddr(u32 p_port, unsigned char ee_cmd,
846 unsigned short ee_addr);
848 static void FPT_phaseDataOut(u32 port, unsigned char p_card);
849 static void FPT_phaseDataIn(u32 port, unsigned char p_card);
850 static void FPT_phaseCommand(u32 port, unsigned char p_card);
851 static void FPT_phaseStatus(u32 port, unsigned char p_card);
852 static void FPT_phaseMsgOut(u32 port, unsigned char p_card);
853 static void FPT_phaseMsgIn(u32 port, unsigned char p_card);
854 static void FPT_phaseIllegal(u32 port, unsigned char p_card);
856 static void FPT_phaseDecode(u32 port, unsigned char p_card);
857 static void FPT_phaseChkFifo(u32 port, unsigned char p_card);
858 static void FPT_phaseBusFree(u32 p_port, unsigned char p_card);
860 static void FPT_XbowInit(u32 port, unsigned char scamFlg);
861 static void FPT_BusMasterInit(u32 p_port);
862 static void FPT_DiagEEPROM(u32 p_port);
864 static void FPT_dataXferProcessor(u32 port,
865 struct sccb_card *pCurrCard);
866 static void FPT_busMstrSGDataXferStart(u32 port,
867 struct sccb *pCurrSCCB);
868 static void FPT_busMstrDataXferStart(u32 port,
869 struct sccb *pCurrSCCB);
870 static void FPT_hostDataXferAbort(u32 port, unsigned char p_card,
871 struct sccb *pCurrSCCB);
872 static void FPT_hostDataXferRestart(struct sccb *currSCCB);
874 static unsigned char FPT_SccbMgr_bad_isr(u32 p_port,
875 unsigned char p_card,
876 struct sccb_card *pCurrCard,
877 unsigned short p_int);
879 static void FPT_SccbMgrTableInitAll(void);
880 static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
881 unsigned char p_card);
882 static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
883 unsigned char target);
885 static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
886 unsigned char p_power_up);
888 static int FPT_scarb(u32 p_port, unsigned char p_sel_type);
889 static void FPT_scbusf(u32 p_port);
890 static void FPT_scsel(u32 p_port);
891 static void FPT_scasid(unsigned char p_card, u32 p_port);
892 static unsigned char FPT_scxferc(u32 p_port, unsigned char p_data);
893 static unsigned char FPT_scsendi(u32 p_port,
894 unsigned char p_id_string[]);
895 static unsigned char FPT_sciso(u32 p_port,
896 unsigned char p_id_string[]);
897 static void FPT_scwirod(u32 p_port, unsigned char p_data_bit);
898 static void FPT_scwiros(u32 p_port, unsigned char p_data_bit);
899 static unsigned char FPT_scvalq(unsigned char p_quintet);
900 static unsigned char FPT_scsell(u32 p_port, unsigned char targ_id);
901 static void FPT_scwtsel(u32 p_port);
902 static void FPT_inisci(unsigned char p_card, u32 p_port,
903 unsigned char p_our_id);
904 static void FPT_scsavdi(unsigned char p_card, u32 p_port);
905 static unsigned char FPT_scmachid(unsigned char p_card,
906 unsigned char p_id_string[]);
908 static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card);
909 static void FPT_autoLoadDefaultMap(u32 p_port);
911 static struct sccb_mgr_tar_info FPT_sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR] =
913 static struct sccb_card FPT_BL_Card[MAX_CARDS] = { {0} };
914 static SCCBSCAM_INFO FPT_scamInfo[MAX_SCSI_TAR] = { {{0}} };
915 static struct nvram_info FPT_nvRamInfo[MAX_MB_CARDS] = { {0} };
917 static unsigned char FPT_mbCards = 0;
918 static unsigned char FPT_scamHAString[] =
919 { 0x63, 0x07, 'B', 'U', 'S', 'L', 'O', 'G', 'I', 'C',
920 ' ', 'B', 'T', '-', '9', '3', '0',
921 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
922 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20
925 static unsigned short FPT_default_intena = 0;
927 static void (*FPT_s_PhaseTbl[8]) (u32, unsigned char) = {
930 /*---------------------------------------------------------------------
932 * Function: FlashPoint_ProbeHostAdapter
934 * Description: Setup and/or Search for cards and return info to caller.
936 *---------------------------------------------------------------------*/
938 static int FlashPoint_ProbeHostAdapter(struct sccb_mgr_info *pCardInfo)
940 static unsigned char first_time = 1;
942 unsigned char i, j, id, ScamFlg;
943 unsigned short temp, temp2, temp3, temp4, temp5, temp6;
945 struct nvram_info *pCurrNvRam;
947 ioport = pCardInfo->si_baseaddr;
949 if (RD_HARPOON(ioport + hp_vendor_id_0) != ORION_VEND_0)
952 if ((RD_HARPOON(ioport + hp_vendor_id_1) != ORION_VEND_1))
955 if ((RD_HARPOON(ioport + hp_device_id_0) != ORION_DEV_0))
958 if ((RD_HARPOON(ioport + hp_device_id_1) != ORION_DEV_1))
961 if (RD_HARPOON(ioport + hp_rev_num) != 0x0f) {
963 /* For new Harpoon then check for sub_device ID LSB
964 the bits(0-3) must be all ZERO for compatible with
965 current version of SCCBMgr, else skip this Harpoon
968 if (RD_HARPOON(ioport + hp_sub_device_id_0) & 0x0f)
973 FPT_SccbMgrTableInitAll();
978 if (FPT_RdStack(ioport, 0) != 0x00) {
979 if (FPT_ChkIfChipInitialized(ioport) == 0) {
981 WR_HARPOON(ioport + hp_semaphore, 0x00);
982 FPT_XbowInit(ioport, 0); /*Must Init the SCSI before attempting */
983 FPT_DiagEEPROM(ioport);
985 if (FPT_mbCards < MAX_MB_CARDS) {
986 pCurrNvRam = &FPT_nvRamInfo[FPT_mbCards];
988 pCurrNvRam->niBaseAddr = ioport;
989 FPT_RNVRamData(pCurrNvRam);
996 WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
997 WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
1000 pCardInfo->si_id = pCurrNvRam->niAdapId;
1004 char)(FPT_utilEERead(ioport,
1006 2)) & (unsigned char)0x0FF);
1008 pCardInfo->si_lun = 0x00;
1009 pCardInfo->si_fw_revision = ORION_FW_REV;
1016 for (id = 0; id < (16 / 2); id++) {
1019 temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
1020 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1021 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1024 FPT_utilEERead(ioport,
1025 (unsigned short)((SYNC_RATE_TBL / 2)
1028 for (i = 0; i < 2; temp >>= 8, i++) {
1035 switch (temp & 0x3) {
1036 case AUTO_RATE_20: /* Synchronous, 20 mega-transfers/second */
1039 case AUTO_RATE_10: /* Synchronous, 10 mega-transfers/second */
1042 case AUTO_RATE_05: /* Synchronous, 5 mega-transfers/second */
1045 case AUTO_RATE_00: /* Asynchronous */
1049 if (temp & DISC_ENABLE_BIT)
1052 if (temp & WIDE_NEGO_BIT)
1058 pCardInfo->si_per_targ_init_sync = temp2;
1059 pCardInfo->si_per_targ_no_disc = temp3;
1060 pCardInfo->si_per_targ_wide_nego = temp4;
1061 pCardInfo->si_per_targ_fast_nego = temp5;
1062 pCardInfo->si_per_targ_ultra_nego = temp6;
1065 i = pCurrNvRam->niSysConf;
1068 char)(FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)));
1071 ScamFlg = pCurrNvRam->niScamConf;
1074 (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
1076 pCardInfo->si_flags = 0x0000;
1079 pCardInfo->si_flags |= SCSI_PARITY_ENA;
1082 pCardInfo->si_flags |= SOFT_RESET;
1085 pCardInfo->si_flags |= EXTENDED_TRANSLATION;
1087 if (ScamFlg & SCAM_ENABLED)
1088 pCardInfo->si_flags |= FLAG_SCAM_ENABLED;
1090 if (ScamFlg & SCAM_LEVEL2)
1091 pCardInfo->si_flags |= FLAG_SCAM_LEVEL2;
1093 j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1095 j |= SCSI_TERM_ENA_L;
1097 WR_HARPOON(ioport + hp_bm_ctrl, j);
1099 j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1101 j |= SCSI_TERM_ENA_H;
1103 WR_HARPOON(ioport + hp_ee_ctrl, j);
1105 if (!(RD_HARPOON(ioport + hp_page_ctrl) & NARROW_SCSI_CARD))
1107 pCardInfo->si_flags |= SUPPORT_16TAR_32LUN;
1109 pCardInfo->si_card_family = HARPOON_FAMILY;
1110 pCardInfo->si_bustype = BUSTYPE_PCI;
1113 pCardInfo->si_card_model[0] = '9';
1114 switch (pCurrNvRam->niModel & 0x0f) {
1116 pCardInfo->si_card_model[1] = '3';
1117 pCardInfo->si_card_model[2] = '0';
1120 pCardInfo->si_card_model[1] = '5';
1121 pCardInfo->si_card_model[2] = '0';
1124 pCardInfo->si_card_model[1] = '3';
1125 pCardInfo->si_card_model[2] = '2';
1128 pCardInfo->si_card_model[1] = '5';
1129 pCardInfo->si_card_model[2] = '2';
1133 temp = FPT_utilEERead(ioport, (MODEL_NUMB_0 / 2));
1134 pCardInfo->si_card_model[0] = (unsigned char)(temp >> 8);
1135 temp = FPT_utilEERead(ioport, (MODEL_NUMB_2 / 2));
1137 pCardInfo->si_card_model[1] = (unsigned char)(temp & 0x00FF);
1138 pCardInfo->si_card_model[2] = (unsigned char)(temp >> 8);
1141 if (pCardInfo->si_card_model[1] == '3') {
1142 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1143 pCardInfo->si_flags |= LOW_BYTE_TERM;
1144 } else if (pCardInfo->si_card_model[2] == '0') {
1145 temp = RD_HARPOON(ioport + hp_xfer_pad);
1146 WR_HARPOON(ioport + hp_xfer_pad, (temp & ~BIT(4)));
1147 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1148 pCardInfo->si_flags |= LOW_BYTE_TERM;
1149 WR_HARPOON(ioport + hp_xfer_pad, (temp | BIT(4)));
1150 if (RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7))
1151 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1152 WR_HARPOON(ioport + hp_xfer_pad, temp);
1154 temp = RD_HARPOON(ioport + hp_ee_ctrl);
1155 temp2 = RD_HARPOON(ioport + hp_xfer_pad);
1156 WR_HARPOON(ioport + hp_ee_ctrl, (temp | SEE_CS));
1157 WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
1159 for (i = 0; i < 8; i++) {
1161 if (!(RD_HARPOON(ioport + hp_ee_ctrl) & BIT(7)))
1163 WR_HARPOON(ioport + hp_xfer_pad, (temp2 & ~BIT(4)));
1164 WR_HARPOON(ioport + hp_xfer_pad, (temp2 | BIT(4)));
1166 WR_HARPOON(ioport + hp_ee_ctrl, temp);
1167 WR_HARPOON(ioport + hp_xfer_pad, temp2);
1168 if (!(temp3 & BIT(7)))
1169 pCardInfo->si_flags |= LOW_BYTE_TERM;
1170 if (!(temp3 & BIT(6)))
1171 pCardInfo->si_flags |= HIGH_BYTE_TERM;
1174 ARAM_ACCESS(ioport);
1176 for (i = 0; i < 4; i++) {
1178 pCardInfo->si_XlatInfo[i] =
1179 RD_HARPOON(ioport + hp_aramBase + BIOS_DATA_OFFSET + i);
1182 /* return with -1 if no sort, else return with
1183 logical card number sorted by BIOS (zero-based) */
1185 pCardInfo->si_relative_cardnum =
1187 char)(RD_HARPOON(ioport + hp_aramBase + BIOS_RELATIVE_CARD) - 1);
1189 SGRAM_ACCESS(ioport);
1191 FPT_s_PhaseTbl[0] = FPT_phaseDataOut;
1192 FPT_s_PhaseTbl[1] = FPT_phaseDataIn;
1193 FPT_s_PhaseTbl[2] = FPT_phaseIllegal;
1194 FPT_s_PhaseTbl[3] = FPT_phaseIllegal;
1195 FPT_s_PhaseTbl[4] = FPT_phaseCommand;
1196 FPT_s_PhaseTbl[5] = FPT_phaseStatus;
1197 FPT_s_PhaseTbl[6] = FPT_phaseMsgOut;
1198 FPT_s_PhaseTbl[7] = FPT_phaseMsgIn;
1200 pCardInfo->si_present = 0x01;
1205 /*---------------------------------------------------------------------
1207 * Function: FlashPoint_HardwareResetHostAdapter
1209 * Description: Setup adapter for normal operation (hard reset).
1211 *---------------------------------------------------------------------*/
1213 static void *FlashPoint_HardwareResetHostAdapter(struct sccb_mgr_info
1216 struct sccb_card *CurrCard = NULL;
1217 struct nvram_info *pCurrNvRam;
1218 unsigned char i, j, thisCard, ScamFlg;
1219 unsigned short temp, sync_bit_map, id;
1222 ioport = pCardInfo->si_baseaddr;
1224 for (thisCard = 0; thisCard <= MAX_CARDS; thisCard++) {
1226 if (thisCard == MAX_CARDS)
1227 return (void *)FAILURE;
1229 if (FPT_BL_Card[thisCard].ioPort == ioport) {
1231 CurrCard = &FPT_BL_Card[thisCard];
1232 FPT_SccbMgrTableInitCard(CurrCard, thisCard);
1236 else if (FPT_BL_Card[thisCard].ioPort == 0x00) {
1238 FPT_BL_Card[thisCard].ioPort = ioport;
1239 CurrCard = &FPT_BL_Card[thisCard];
1242 for (i = 0; i < FPT_mbCards; i++) {
1243 if (CurrCard->ioPort ==
1244 FPT_nvRamInfo[i].niBaseAddr)
1245 CurrCard->pNvRamInfo =
1248 FPT_SccbMgrTableInitCard(CurrCard, thisCard);
1249 CurrCard->cardIndex = thisCard;
1250 CurrCard->cardInfo = pCardInfo;
1256 pCurrNvRam = CurrCard->pNvRamInfo;
1259 ScamFlg = pCurrNvRam->niScamConf;
1262 (unsigned char)FPT_utilEERead(ioport, SCAM_CONFIG / 2);
1265 FPT_BusMasterInit(ioport);
1266 FPT_XbowInit(ioport, ScamFlg);
1268 FPT_autoLoadDefaultMap(ioport);
1270 for (i = 0, id = 0x01; i != pCardInfo->si_id; i++, id <<= 1) {
1273 WR_HARPOON(ioport + hp_selfid_0, id);
1274 WR_HARPOON(ioport + hp_selfid_1, 0x00);
1275 WR_HARPOON(ioport + hp_arb_id, pCardInfo->si_id);
1276 CurrCard->ourId = pCardInfo->si_id;
1278 i = (unsigned char)pCardInfo->si_flags;
1279 if (i & SCSI_PARITY_ENA)
1280 WR_HARPOON(ioport + hp_portctrl_1, (HOST_MODE8 | CHK_SCSI_P));
1282 j = (RD_HARPOON(ioport + hp_bm_ctrl) & ~SCSI_TERM_ENA_L);
1283 if (i & LOW_BYTE_TERM)
1284 j |= SCSI_TERM_ENA_L;
1285 WR_HARPOON(ioport + hp_bm_ctrl, j);
1287 j = (RD_HARPOON(ioport + hp_ee_ctrl) & ~SCSI_TERM_ENA_H);
1288 if (i & HIGH_BYTE_TERM)
1289 j |= SCSI_TERM_ENA_H;
1290 WR_HARPOON(ioport + hp_ee_ctrl, j);
1292 if (!(pCardInfo->si_flags & SOFT_RESET)) {
1294 FPT_sresb(ioport, thisCard);
1296 FPT_scini(thisCard, pCardInfo->si_id, 0);
1299 if (pCardInfo->si_flags & POST_ALL_UNDERRRUNS)
1300 CurrCard->globalFlags |= F_NO_FILTER;
1303 if (pCurrNvRam->niSysConf & 0x10)
1304 CurrCard->globalFlags |= F_GREEN_PC;
1306 if (FPT_utilEERead(ioport, (SYSTEM_CONFIG / 2)) & GREEN_PC_ENA)
1307 CurrCard->globalFlags |= F_GREEN_PC;
1310 /* Set global flag to indicate Re-Negotiation to be done on all
1313 if (pCurrNvRam->niScsiConf & 0x04)
1314 CurrCard->globalFlags |= F_DO_RENEGO;
1316 if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & RENEGO_ENA)
1317 CurrCard->globalFlags |= F_DO_RENEGO;
1321 if (pCurrNvRam->niScsiConf & 0x08)
1322 CurrCard->globalFlags |= F_CONLUN_IO;
1324 if (FPT_utilEERead(ioport, (SCSI_CONFIG / 2)) & CONNIO_ENA)
1325 CurrCard->globalFlags |= F_CONLUN_IO;
1328 temp = pCardInfo->si_per_targ_no_disc;
1330 for (i = 0, id = 1; i < MAX_SCSI_TAR; i++, id <<= 1) {
1333 FPT_sccbMgrTbl[thisCard][i].TarStatus |= TAR_ALLOW_DISC;
1336 sync_bit_map = 0x0001;
1338 for (id = 0; id < (MAX_SCSI_TAR / 2); id++) {
1341 temp = (unsigned short)pCurrNvRam->niSyncTbl[id];
1342 temp = ((temp & 0x03) + ((temp << 4) & 0xc0)) +
1343 (((temp << 4) & 0x0300) + ((temp << 8) & 0xc000));
1346 FPT_utilEERead(ioport,
1347 (unsigned short)((SYNC_RATE_TBL / 2)
1350 for (i = 0; i < 2; temp >>= 8, i++) {
1352 if (pCardInfo->si_per_targ_init_sync & sync_bit_map) {
1354 FPT_sccbMgrTbl[thisCard][id * 2 +
1356 (unsigned char)temp;
1360 FPT_sccbMgrTbl[thisCard][id * 2 +
1363 FPT_sccbMgrTbl[thisCard][id * 2 +
1365 (unsigned char)(temp & ~EE_SYNC_MASK);
1368 /* if ((pCardInfo->si_per_targ_wide_nego & sync_bit_map) ||
1371 if (pCardInfo->si_per_targ_wide_nego & sync_bit_map) {
1373 FPT_sccbMgrTbl[thisCard][id * 2 +
1379 else { /* NARROW SCSI */
1380 FPT_sccbMgrTbl[thisCard][id * 2 +
1390 WR_HARPOON((ioport + hp_semaphore),
1391 (unsigned char)(RD_HARPOON((ioport + hp_semaphore)) |
1394 return (void *)CurrCard;
1397 static void FlashPoint_ReleaseHostAdapter(void *pCurrCard)
1404 struct nvram_info *pCurrNvRam;
1406 pCurrNvRam = ((struct sccb_card *)pCurrCard)->pNvRamInfo;
1409 FPT_WrStack(pCurrNvRam->niBaseAddr, 0, pCurrNvRam->niModel);
1410 FPT_WrStack(pCurrNvRam->niBaseAddr, 1, pCurrNvRam->niSysConf);
1411 FPT_WrStack(pCurrNvRam->niBaseAddr, 2, pCurrNvRam->niScsiConf);
1412 FPT_WrStack(pCurrNvRam->niBaseAddr, 3, pCurrNvRam->niScamConf);
1413 FPT_WrStack(pCurrNvRam->niBaseAddr, 4, pCurrNvRam->niAdapId);
1415 for (i = 0; i < MAX_SCSI_TAR / 2; i++)
1416 FPT_WrStack(pCurrNvRam->niBaseAddr,
1417 (unsigned char)(i + 5),
1418 pCurrNvRam->niSyncTbl[i]);
1420 portBase = pCurrNvRam->niBaseAddr;
1422 for (i = 0; i < MAX_SCSI_TAR; i++) {
1423 regOffset = hp_aramBase + 64 + i * 4;
1424 pScamTbl = (u32 *)&pCurrNvRam->niScamTbl[i];
1425 scamData = *pScamTbl;
1426 WR_HARP32(portBase, regOffset, scamData);
1430 FPT_WrStack(((struct sccb_card *)pCurrCard)->ioPort, 0, 0);
1434 static void FPT_RNVRamData(struct nvram_info *pNvRamInfo)
1442 pNvRamInfo->niModel = FPT_RdStack(pNvRamInfo->niBaseAddr, 0);
1443 pNvRamInfo->niSysConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 1);
1444 pNvRamInfo->niScsiConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 2);
1445 pNvRamInfo->niScamConf = FPT_RdStack(pNvRamInfo->niBaseAddr, 3);
1446 pNvRamInfo->niAdapId = FPT_RdStack(pNvRamInfo->niBaseAddr, 4);
1448 for (i = 0; i < MAX_SCSI_TAR / 2; i++)
1449 pNvRamInfo->niSyncTbl[i] =
1450 FPT_RdStack(pNvRamInfo->niBaseAddr, (unsigned char)(i + 5));
1452 portBase = pNvRamInfo->niBaseAddr;
1454 for (i = 0; i < MAX_SCSI_TAR; i++) {
1455 regOffset = hp_aramBase + 64 + i * 4;
1456 RD_HARP32(portBase, regOffset, scamData);
1457 pScamTbl = (u32 *)&pNvRamInfo->niScamTbl[i];
1458 *pScamTbl = scamData;
1463 static unsigned char FPT_RdStack(u32 portBase, unsigned char index)
1465 WR_HARPOON(portBase + hp_stack_addr, index);
1466 return RD_HARPOON(portBase + hp_stack_data);
1469 static void FPT_WrStack(u32 portBase, unsigned char index, unsigned char data)
1471 WR_HARPOON(portBase + hp_stack_addr, index);
1472 WR_HARPOON(portBase + hp_stack_data, data);
1475 static unsigned char FPT_ChkIfChipInitialized(u32 ioPort)
1477 if ((RD_HARPOON(ioPort + hp_arb_id) & 0x0f) != FPT_RdStack(ioPort, 4))
1479 if ((RD_HARPOON(ioPort + hp_clkctrl_0) & CLKCTRL_DEFAULT)
1482 if ((RD_HARPOON(ioPort + hp_seltimeout) == TO_250ms) ||
1483 (RD_HARPOON(ioPort + hp_seltimeout) == TO_290ms))
1489 /*---------------------------------------------------------------------
1491 * Function: FlashPoint_StartCCB
1493 * Description: Start a command pointed to by p_Sccb. When the
1494 * command is completed it will be returned via the
1495 * callback function.
1497 *---------------------------------------------------------------------*/
1498 static void FlashPoint_StartCCB(void *curr_card, struct sccb *p_Sccb)
1501 unsigned char thisCard, lun;
1502 struct sccb *pSaveSccb;
1503 CALL_BK_FN callback;
1504 struct sccb_card *pCurrCard = curr_card;
1506 thisCard = pCurrCard->cardIndex;
1507 ioport = pCurrCard->ioPort;
1509 if ((p_Sccb->TargID >= MAX_SCSI_TAR) || (p_Sccb->Lun >= MAX_LUN)) {
1511 p_Sccb->HostStatus = SCCB_COMPLETE;
1512 p_Sccb->SccbStatus = SCCB_ERROR;
1513 callback = (CALL_BK_FN) p_Sccb->SccbCallback;
1520 FPT_sinits(p_Sccb, thisCard);
1522 if (!pCurrCard->cmdCounter) {
1523 WR_HARPOON(ioport + hp_semaphore,
1524 (RD_HARPOON(ioport + hp_semaphore)
1525 | SCCB_MGR_ACTIVE));
1527 if (pCurrCard->globalFlags & F_GREEN_PC) {
1528 WR_HARPOON(ioport + hp_clkctrl_0, CLKCTRL_DEFAULT);
1529 WR_HARPOON(ioport + hp_sys_ctrl, 0x00);
1533 pCurrCard->cmdCounter++;
1535 if (RD_HARPOON(ioport + hp_semaphore) & BIOS_IN_USE) {
1537 WR_HARPOON(ioport + hp_semaphore,
1538 (RD_HARPOON(ioport + hp_semaphore)
1540 if (p_Sccb->OperationCode == RESET_COMMAND) {
1542 pCurrCard->currentSCCB;
1543 pCurrCard->currentSCCB = p_Sccb;
1544 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
1545 pCurrCard->currentSCCB =
1548 FPT_queueAddSccb(p_Sccb, thisCard);
1552 else if ((RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
1554 if (p_Sccb->OperationCode == RESET_COMMAND) {
1556 pCurrCard->currentSCCB;
1557 pCurrCard->currentSCCB = p_Sccb;
1558 FPT_queueSelectFail(&FPT_BL_Card[thisCard], thisCard);
1559 pCurrCard->currentSCCB =
1562 FPT_queueAddSccb(p_Sccb, thisCard);
1568 MDISABLE_INT(ioport);
1570 if ((pCurrCard->globalFlags & F_CONLUN_IO) &&
1571 ((FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].
1572 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
1576 if ((pCurrCard->currentSCCB == NULL) &&
1577 (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarSelQ_Cnt == 0)
1578 && (FPT_sccbMgrTbl[thisCard][p_Sccb->TargID].TarLUNBusy[lun]
1581 pCurrCard->currentSCCB = p_Sccb;
1582 FPT_ssel(p_Sccb->SccbIOPort, thisCard);
1587 if (p_Sccb->OperationCode == RESET_COMMAND) {
1588 pSaveSccb = pCurrCard->currentSCCB;
1589 pCurrCard->currentSCCB = p_Sccb;
1590 FPT_queueSelectFail(&FPT_BL_Card[thisCard],
1592 pCurrCard->currentSCCB = pSaveSccb;
1594 FPT_queueAddSccb(p_Sccb, thisCard);
1598 MENABLE_INT(ioport);
1603 /*---------------------------------------------------------------------
1605 * Function: FlashPoint_AbortCCB
1607 * Description: Abort the command pointed to by p_Sccb. When the
1608 * command is completed it will be returned via the
1609 * callback function.
1611 *---------------------------------------------------------------------*/
1612 static int FlashPoint_AbortCCB(void *pCurrCard, struct sccb *p_Sccb)
1616 unsigned char thisCard;
1617 CALL_BK_FN callback;
1619 struct sccb *pSaveSCCB;
1620 struct sccb_mgr_tar_info *currTar_Info;
1622 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1624 thisCard = ((struct sccb_card *)pCurrCard)->cardIndex;
1626 if (!(RD_HARPOON(ioport + hp_page_ctrl) & G_INT_DISABLE)) {
1628 if (FPT_queueFindSccb(p_Sccb, thisCard)) {
1630 ((struct sccb_card *)pCurrCard)->cmdCounter--;
1632 if (!((struct sccb_card *)pCurrCard)->cmdCounter)
1633 WR_HARPOON(ioport + hp_semaphore,
1634 (RD_HARPOON(ioport + hp_semaphore)
1636 char)(~(SCCB_MGR_ACTIVE |
1639 p_Sccb->SccbStatus = SCCB_ABORT;
1640 callback = p_Sccb->SccbCallback;
1647 if (((struct sccb_card *)pCurrCard)->currentSCCB ==
1649 p_Sccb->SccbStatus = SCCB_ABORT;
1656 TID = p_Sccb->TargID;
1658 if (p_Sccb->Sccb_tag) {
1659 MDISABLE_INT(ioport);
1660 if (((struct sccb_card *)pCurrCard)->
1661 discQ_Tbl[p_Sccb->Sccb_tag] ==
1663 p_Sccb->SccbStatus = SCCB_ABORT;
1664 p_Sccb->Sccb_scsistat =
1666 p_Sccb->Sccb_scsimsg =
1669 if (((struct sccb_card *)
1670 pCurrCard)->currentSCCB ==
1672 ((struct sccb_card *)
1674 currentSCCB = p_Sccb;
1682 ((struct sccb_card *)
1684 currentSCCB = p_Sccb;
1685 FPT_queueSelectFail((struct sccb_card *)pCurrCard, thisCard);
1686 ((struct sccb_card *)
1688 currentSCCB = pSaveSCCB;
1691 MENABLE_INT(ioport);
1695 &FPT_sccbMgrTbl[thisCard][p_Sccb->
1698 if (FPT_BL_Card[thisCard].
1699 discQ_Tbl[currTar_Info->
1700 LunDiscQ_Idx[p_Sccb->Lun]]
1702 p_Sccb->SccbStatus = SCCB_ABORT;
1712 /*---------------------------------------------------------------------
1714 * Function: FlashPoint_InterruptPending
1716 * Description: Do a quick check to determine if there is a pending
1717 * interrupt for this card and disable the IRQ Pin if so.
1719 *---------------------------------------------------------------------*/
1720 static unsigned char FlashPoint_InterruptPending(void *pCurrCard)
1724 ioport = ((struct sccb_card *)pCurrCard)->ioPort;
1726 if (RD_HARPOON(ioport + hp_int_status) & INT_ASSERTED) {
1735 /*---------------------------------------------------------------------
1737 * Function: FlashPoint_HandleInterrupt
1739 * Description: This is our entry point when an interrupt is generated
1740 * by the card and the upper level driver passes it on to
1743 *---------------------------------------------------------------------*/
1744 static int FlashPoint_HandleInterrupt(void *pcard)
1746 struct sccb *currSCCB;
1747 unsigned char thisCard, result, bm_status, bm_int_st;
1748 unsigned short hp_int;
1749 unsigned char i, target;
1750 struct sccb_card *pCurrCard = pcard;
1753 thisCard = pCurrCard->cardIndex;
1754 ioport = pCurrCard->ioPort;
1756 MDISABLE_INT(ioport);
1758 if ((bm_int_st = RD_HARPOON(ioport + hp_int_status)) & EXT_STATUS_ON)
1759 bm_status = RD_HARPOON(ioport + hp_ext_status) &
1760 (unsigned char)BAD_EXT_STATUS;
1764 WR_HARPOON(ioport + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
1766 while ((hp_int = RDW_HARPOON((ioport + hp_intstat)) &
1767 FPT_default_intena) | bm_status) {
1769 currSCCB = pCurrCard->currentSCCB;
1771 if (hp_int & (FIFO | TIMEOUT | RESET | SCAM_SEL) || bm_status) {
1773 FPT_SccbMgr_bad_isr(ioport, thisCard, pCurrCard,
1775 WRW_HARPOON((ioport + hp_intstat),
1776 (FIFO | TIMEOUT | RESET | SCAM_SEL));
1781 MENABLE_INT(ioport);
1786 else if (hp_int & ICMD_COMP) {
1788 if (!(hp_int & BUS_FREE)) {
1789 /* Wait for the BusFree before starting a new command. We
1790 must also check for being reselected since the BusFree
1791 may not show up if another device reselects us in 1.5us or
1792 less. SRR Wednesday, 3/8/1995.
1795 (RDW_HARPOON((ioport + hp_intstat)) &
1796 (BUS_FREE | RSEL))) ;
1799 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
1801 FPT_phaseChkFifo(ioport, thisCard);
1803 /* WRW_HARPOON((ioport+hp_intstat),
1804 (BUS_FREE | ICMD_COMP | ITAR_DISC | XFER_CNT_0));
1807 WRW_HARPOON((ioport + hp_intstat), CLR_ALL_INT_1);
1809 FPT_autoCmdCmplt(ioport, thisCard);
1813 else if (hp_int & ITAR_DISC) {
1815 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
1816 FPT_phaseChkFifo(ioport, thisCard);
1818 if (RD_HARPOON(ioport + hp_gp_reg_1) ==
1821 WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
1822 currSCCB->Sccb_XferState |= F_NO_DATA_YET;
1824 currSCCB->Sccb_savedATC = currSCCB->Sccb_ATC;
1827 currSCCB->Sccb_scsistat = DISCONNECT_ST;
1828 FPT_queueDisconnect(currSCCB, thisCard);
1830 /* Wait for the BusFree before starting a new command. We
1831 must also check for being reselected since the BusFree
1832 may not show up if another device reselects us in 1.5us or
1833 less. SRR Wednesday, 3/8/1995.
1836 (RDW_HARPOON((ioport + hp_intstat)) &
1838 && !((RDW_HARPOON((ioport + hp_intstat)) & PHASE)
1839 && RD_HARPOON((ioport + hp_scsisig)) ==
1840 (SCSI_BSY | SCSI_REQ | SCSI_CD | SCSI_MSG |
1844 The additional loop exit condition above detects a timing problem
1845 with the revision D/E harpoon chips. The caller should reset the
1846 host adapter to recover when 0xFE is returned.
1849 (RDW_HARPOON((ioport + hp_intstat)) &
1850 (BUS_FREE | RSEL))) {
1851 MENABLE_INT(ioport);
1855 WRW_HARPOON((ioport + hp_intstat),
1856 (BUS_FREE | ITAR_DISC));
1858 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
1862 else if (hp_int & RSEL) {
1864 WRW_HARPOON((ioport + hp_intstat),
1865 (PROG_HLT | RSEL | PHASE | BUS_FREE));
1867 if (RDW_HARPOON((ioport + hp_intstat)) & ITAR_DISC) {
1868 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
1869 FPT_phaseChkFifo(ioport, thisCard);
1871 if (RD_HARPOON(ioport + hp_gp_reg_1) ==
1873 WR_HARPOON(ioport + hp_gp_reg_1, 0x00);
1874 currSCCB->Sccb_XferState |=
1876 currSCCB->Sccb_savedATC =
1880 WRW_HARPOON((ioport + hp_intstat),
1881 (BUS_FREE | ITAR_DISC));
1882 currSCCB->Sccb_scsistat = DISCONNECT_ST;
1883 FPT_queueDisconnect(currSCCB, thisCard);
1886 FPT_sres(ioport, thisCard, pCurrCard);
1887 FPT_phaseDecode(ioport, thisCard);
1891 else if ((hp_int & IDO_STRT) && (!(hp_int & BUS_FREE))) {
1893 WRW_HARPOON((ioport + hp_intstat),
1894 (IDO_STRT | XFER_CNT_0));
1895 FPT_phaseDecode(ioport, thisCard);
1899 else if ((hp_int & IUNKWN) || (hp_int & PROG_HLT)) {
1900 WRW_HARPOON((ioport + hp_intstat),
1901 (PHASE | IUNKWN | PROG_HLT));
1902 if ((RD_HARPOON(ioport + hp_prgmcnt_0) & (unsigned char)
1903 0x3f) < (unsigned char)SELCHK) {
1904 FPT_phaseDecode(ioport, thisCard);
1906 /* Harpoon problem some SCSI target device respond to selection
1907 with short BUSY pulse (<400ns) this will make the Harpoon is not able
1908 to latch the correct Target ID into reg. x53.
1909 The work around require to correct this reg. But when write to this
1910 reg. (0x53) also increment the FIFO write addr reg (0x6f), thus we
1911 need to read this reg first then restore it later. After update to 0x53 */
1914 char)(RD_HARPOON(ioport + hp_fifowrite));
1917 char)(RD_HARPOON(ioport + hp_gp_reg_3));
1918 WR_HARPOON(ioport + hp_xfer_pad,
1919 (unsigned char)ID_UNLOCK);
1920 WR_HARPOON(ioport + hp_select_id,
1921 (unsigned char)(target | target <<
1923 WR_HARPOON(ioport + hp_xfer_pad,
1924 (unsigned char)0x00);
1925 WR_HARPOON(ioport + hp_fifowrite, i);
1926 WR_HARPOON(ioport + hp_autostart_3,
1927 (AUTO_IMMED + TAG_STRT));
1931 else if (hp_int & XFER_CNT_0) {
1933 WRW_HARPOON((ioport + hp_intstat), XFER_CNT_0);
1935 FPT_schkdd(ioport, thisCard);
1939 else if (hp_int & BUS_FREE) {
1941 WRW_HARPOON((ioport + hp_intstat), BUS_FREE);
1943 if (pCurrCard->globalFlags & F_HOST_XFER_ACT) {
1945 FPT_hostDataXferAbort(ioport, thisCard,
1949 FPT_phaseBusFree(ioport, thisCard);
1952 else if (hp_int & ITICKLE) {
1954 WRW_HARPOON((ioport + hp_intstat), ITICKLE);
1955 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
1958 if (((struct sccb_card *)pCurrCard)->
1959 globalFlags & F_NEW_SCCB_CMD) {
1961 pCurrCard->globalFlags &= ~F_NEW_SCCB_CMD;
1963 if (pCurrCard->currentSCCB == NULL)
1964 FPT_queueSearchSelect(pCurrCard, thisCard);
1966 if (pCurrCard->currentSCCB != NULL) {
1967 pCurrCard->globalFlags &= ~F_NEW_SCCB_CMD;
1968 FPT_ssel(ioport, thisCard);
1977 MENABLE_INT(ioport);
1982 /*---------------------------------------------------------------------
1984 * Function: Sccb_bad_isr
1986 * Description: Some type of interrupt has occurred which is slightly
1987 * out of the ordinary. We will now decode it fully, in
1988 * this routine. This is broken up in an attempt to save
1991 *---------------------------------------------------------------------*/
1992 static unsigned char FPT_SccbMgr_bad_isr(u32 p_port, unsigned char p_card,
1993 struct sccb_card *pCurrCard,
1994 unsigned short p_int)
1996 unsigned char temp, ScamFlg;
1997 struct sccb_mgr_tar_info *currTar_Info;
1998 struct nvram_info *pCurrNvRam;
2000 if (RD_HARPOON(p_port + hp_ext_status) &
2001 (BM_FORCE_OFF | PCI_DEV_TMOUT | BM_PARITY_ERR | PIO_OVERRUN)) {
2003 if (pCurrCard->globalFlags & F_HOST_XFER_ACT) {
2005 FPT_hostDataXferAbort(p_port, p_card,
2006 pCurrCard->currentSCCB);
2009 if (RD_HARPOON(p_port + hp_pci_stat_cfg) & REC_MASTER_ABORT)
2011 WR_HARPOON(p_port + hp_pci_stat_cfg,
2012 (RD_HARPOON(p_port + hp_pci_stat_cfg) &
2013 ~REC_MASTER_ABORT));
2015 WR_HARPOON(p_port + hp_host_blk_cnt, 0x00);
2019 if (pCurrCard->currentSCCB != NULL) {
2021 if (!pCurrCard->currentSCCB->HostStatus)
2022 pCurrCard->currentSCCB->HostStatus =
2025 FPT_sxfrp(p_port, p_card);
2027 temp = (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
2028 (EXT_ARB_ACK | SCSI_TERM_ENA_H));
2029 WR_HARPOON(p_port + hp_ee_ctrl,
2030 ((unsigned char)temp | SEE_MS | SEE_CS));
2031 WR_HARPOON(p_port + hp_ee_ctrl, temp);
2034 (RDW_HARPOON((p_port + hp_intstat)) &
2035 (BUS_FREE | RESET))) {
2036 FPT_phaseDecode(p_port, p_card);
2041 else if (p_int & RESET) {
2043 WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
2044 WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
2045 if (pCurrCard->currentSCCB != NULL) {
2047 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
2049 FPT_hostDataXferAbort(p_port, p_card,
2050 pCurrCard->currentSCCB);
2053 DISABLE_AUTO(p_port);
2055 FPT_sresb(p_port, p_card);
2057 while (RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST) {
2060 pCurrNvRam = pCurrCard->pNvRamInfo;
2062 ScamFlg = pCurrNvRam->niScamConf;
2065 (unsigned char)FPT_utilEERead(p_port,
2069 FPT_XbowInit(p_port, ScamFlg);
2071 FPT_scini(p_card, pCurrCard->ourId, 0);
2076 else if (p_int & FIFO) {
2078 WRW_HARPOON((p_port + hp_intstat), FIFO);
2080 if (pCurrCard->currentSCCB != NULL)
2081 FPT_sxfrp(p_port, p_card);
2084 else if (p_int & TIMEOUT) {
2086 DISABLE_AUTO(p_port);
2088 WRW_HARPOON((p_port + hp_intstat),
2089 (PROG_HLT | TIMEOUT | SEL | BUS_FREE | PHASE |
2092 pCurrCard->currentSCCB->HostStatus = SCCB_SELECTION_TIMEOUT;
2095 &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
2096 if ((pCurrCard->globalFlags & F_CONLUN_IO)
2097 && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
2099 currTar_Info->TarLUNBusy[pCurrCard->currentSCCB->Lun] =
2102 currTar_Info->TarLUNBusy[0] = 0;
2104 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
2105 currTar_Info->TarSyncCtrl = 0;
2106 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2109 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
2110 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2113 FPT_sssyncv(p_port, pCurrCard->currentSCCB->TargID, NARROW_SCSI,
2116 FPT_queueCmdComplete(pCurrCard, pCurrCard->currentSCCB, p_card);
2120 else if (p_int & SCAM_SEL) {
2122 FPT_scarb(p_port, LEVEL2_TAR);
2124 FPT_scasid(p_card, p_port);
2128 WRW_HARPOON((p_port + hp_intstat), SCAM_SEL);
2134 /*---------------------------------------------------------------------
2136 * Function: SccbMgrTableInit
2138 * Description: Initialize all Sccb manager data structures.
2140 *---------------------------------------------------------------------*/
2142 static void FPT_SccbMgrTableInitAll(void)
2144 unsigned char thisCard;
2146 for (thisCard = 0; thisCard < MAX_CARDS; thisCard++) {
2147 FPT_SccbMgrTableInitCard(&FPT_BL_Card[thisCard], thisCard);
2149 FPT_BL_Card[thisCard].ioPort = 0x00;
2150 FPT_BL_Card[thisCard].cardInfo = NULL;
2151 FPT_BL_Card[thisCard].cardIndex = 0xFF;
2152 FPT_BL_Card[thisCard].ourId = 0x00;
2153 FPT_BL_Card[thisCard].pNvRamInfo = NULL;
2157 /*---------------------------------------------------------------------
2159 * Function: SccbMgrTableInit
2161 * Description: Initialize all Sccb manager data structures.
2163 *---------------------------------------------------------------------*/
2165 static void FPT_SccbMgrTableInitCard(struct sccb_card *pCurrCard,
2166 unsigned char p_card)
2168 unsigned char scsiID, qtag;
2170 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
2171 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2174 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
2175 FPT_sccbMgrTbl[p_card][scsiID].TarStatus = 0;
2176 FPT_sccbMgrTbl[p_card][scsiID].TarEEValue = 0;
2177 FPT_SccbMgrTableInitTarget(p_card, scsiID);
2180 pCurrCard->scanIndex = 0x00;
2181 pCurrCard->currentSCCB = NULL;
2182 pCurrCard->globalFlags = 0x00;
2183 pCurrCard->cmdCounter = 0x00;
2184 pCurrCard->tagQ_Lst = 0x01;
2185 pCurrCard->discQCount = 0;
2189 /*---------------------------------------------------------------------
2191 * Function: SccbMgrTableInit
2193 * Description: Initialize all Sccb manager data structures.
2195 *---------------------------------------------------------------------*/
2197 static void FPT_SccbMgrTableInitTarget(unsigned char p_card,
2198 unsigned char target)
2201 unsigned char lun, qtag;
2202 struct sccb_mgr_tar_info *currTar_Info;
2204 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2206 currTar_Info->TarSelQ_Cnt = 0;
2207 currTar_Info->TarSyncCtrl = 0;
2209 currTar_Info->TarSelQ_Head = NULL;
2210 currTar_Info->TarSelQ_Tail = NULL;
2211 currTar_Info->TarTagQ_Cnt = 0;
2212 currTar_Info->TarLUN_CA = 0;
2214 for (lun = 0; lun < MAX_LUN; lun++) {
2215 currTar_Info->TarLUNBusy[lun] = 0;
2216 currTar_Info->LunDiscQ_Idx[lun] = 0;
2219 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
2220 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] != NULL) {
2221 if (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
2223 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
2224 FPT_BL_Card[p_card].discQCount--;
2230 /*---------------------------------------------------------------------
2234 * Description: Read in a message byte from the SCSI bus, and check
2235 * for a parity error.
2237 *---------------------------------------------------------------------*/
2239 static unsigned char FPT_sfm(u32 port, struct sccb *pCurrSCCB)
2241 unsigned char message;
2242 unsigned short TimeOutLoop;
2245 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2246 (TimeOutLoop++ < 20000)) {
2249 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
2251 message = RD_HARPOON(port + hp_scsidata_0);
2253 WR_HARPOON(port + hp_scsisig, SCSI_ACK + S_MSGI_PH);
2255 if (TimeOutLoop > 20000)
2256 message = 0x00; /* force message byte = 0 if Time Out on Req */
2258 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
2259 (RD_HARPOON(port + hp_addstat) & SCSI_PAR_ERR)) {
2260 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2261 WR_HARPOON(port + hp_xferstat, 0);
2262 WR_HARPOON(port + hp_fiforead, 0);
2263 WR_HARPOON(port + hp_fifowrite, 0);
2264 if (pCurrSCCB != NULL) {
2265 pCurrSCCB->Sccb_scsimsg = SMPARITY;
2269 ACCEPT_MSG_ATN(port);
2271 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2272 (TimeOutLoop++ < 20000)) {
2274 if (TimeOutLoop > 20000) {
2275 WRW_HARPOON((port + hp_intstat), PARITY);
2278 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) !=
2280 WRW_HARPOON((port + hp_intstat), PARITY);
2283 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
2285 RD_HARPOON(port + hp_scsidata_0);
2287 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2292 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2293 WR_HARPOON(port + hp_xferstat, 0);
2294 WR_HARPOON(port + hp_fiforead, 0);
2295 WR_HARPOON(port + hp_fifowrite, 0);
2299 /*---------------------------------------------------------------------
2301 * Function: FPT_ssel
2303 * Description: Load up automation and select target device.
2305 *---------------------------------------------------------------------*/
2307 static void FPT_ssel(u32 port, unsigned char p_card)
2310 unsigned char auto_loaded, i, target, *theCCB;
2313 struct sccb_card *CurrCard;
2314 struct sccb *currSCCB;
2315 struct sccb_mgr_tar_info *currTar_Info;
2316 unsigned char lastTag, lun;
2318 CurrCard = &FPT_BL_Card[p_card];
2319 currSCCB = CurrCard->currentSCCB;
2320 target = currSCCB->TargID;
2321 currTar_Info = &FPT_sccbMgrTbl[p_card][target];
2322 lastTag = CurrCard->tagQ_Lst;
2326 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
2327 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2329 if (((CurrCard->globalFlags & F_CONLUN_IO) &&
2330 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
2332 lun = currSCCB->Lun;
2336 if (CurrCard->globalFlags & F_TAG_STARTED) {
2337 if (!(currSCCB->ControlByte & F_USE_CMD_Q)) {
2338 if ((currTar_Info->TarLUN_CA == 0)
2339 && ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
2342 if (currTar_Info->TarTagQ_Cnt != 0) {
2343 currTar_Info->TarLUNBusy[lun] = 1;
2344 FPT_queueSelectFail(CurrCard, p_card);
2350 currTar_Info->TarLUNBusy[lun] = 1;
2356 currTar_Info->TarLUNBusy[lun] = 1;
2360 /*!Use cmd Q Tagged */
2362 if (currTar_Info->TarLUN_CA == 1) {
2363 FPT_queueSelectFail(CurrCard, p_card);
2368 currTar_Info->TarLUNBusy[lun] = 1;
2370 } /*else use cmd Q tagged */
2373 /*if glob tagged started */
2375 currTar_Info->TarLUNBusy[lun] = 1;
2378 if ((((CurrCard->globalFlags & F_CONLUN_IO) &&
2379 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
2380 || (!(currSCCB->ControlByte & F_USE_CMD_Q)))) {
2381 if (CurrCard->discQCount >= QUEUE_DEPTH) {
2382 currTar_Info->TarLUNBusy[lun] = 1;
2383 FPT_queueSelectFail(CurrCard, p_card);
2387 for (i = 1; i < QUEUE_DEPTH; i++) {
2388 if (++lastTag >= QUEUE_DEPTH)
2390 if (CurrCard->discQ_Tbl[lastTag] == NULL) {
2391 CurrCard->tagQ_Lst = lastTag;
2392 currTar_Info->LunDiscQ_Idx[lun] = lastTag;
2393 CurrCard->discQ_Tbl[lastTag] = currSCCB;
2394 CurrCard->discQCount++;
2398 if (i == QUEUE_DEPTH) {
2399 currTar_Info->TarLUNBusy[lun] = 1;
2400 FPT_queueSelectFail(CurrCard, p_card);
2408 WR_HARPOON(port + hp_select_id, target);
2409 WR_HARPOON(port + hp_gp_reg_3, target); /* Use by new automation logic */
2411 if (currSCCB->OperationCode == RESET_COMMAND) {
2412 WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
2414 Sccb_idmsg & ~DISC_PRIV)));
2416 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + NP);
2418 currSCCB->Sccb_scsimsg = SMDEV_RESET;
2420 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
2422 currSCCB->Sccb_scsistat = SELECT_BDR_ST;
2424 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
2425 currTar_Info->TarSyncCtrl = 0;
2426 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2429 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
2430 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2433 FPT_sssyncv(port, target, NARROW_SCSI, currTar_Info);
2434 FPT_SccbMgrTableInitTarget(p_card, target);
2438 else if (currSCCB->Sccb_scsistat == ABORT_ST) {
2439 WRW_HARPOON((port + ID_MSG_STRT), (MPM_OP + AMSG_OUT +
2441 Sccb_idmsg & ~DISC_PRIV)));
2443 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
2445 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT +
2450 >> 6) | (unsigned char)
2452 WRW_HARPOON((port + SYNC_MSGS + 2),
2453 (MPM_OP + AMSG_OUT + currSCCB->Sccb_tag));
2454 WRW_HARPOON((port + SYNC_MSGS + 4), (BRH_OP + ALWAYS + NP));
2456 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
2461 else if (!(currTar_Info->TarStatus & WIDE_NEGOCIATED)) {
2462 auto_loaded = FPT_siwidn(port, p_card);
2463 currSCCB->Sccb_scsistat = SELECT_WN_ST;
2466 else if (!((currTar_Info->TarStatus & TAR_SYNC_MASK)
2467 == SYNC_SUPPORTED)) {
2468 auto_loaded = FPT_sisyncn(port, p_card, 0);
2469 currSCCB->Sccb_scsistat = SELECT_SN_ST;
2474 if (currSCCB->ControlByte & F_USE_CMD_Q) {
2476 CurrCard->globalFlags |= F_TAG_STARTED;
2478 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK)
2480 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2482 /* Fix up the start instruction with a jump to
2483 Non-Tag-CMD handling */
2484 WRW_HARPOON((port + ID_MSG_STRT),
2485 BRH_OP + ALWAYS + NTCMD);
2487 WRW_HARPOON((port + NON_TAG_ID_MSG),
2488 (MPM_OP + AMSG_OUT +
2489 currSCCB->Sccb_idmsg));
2491 WR_HARPOON(port + hp_autostart_3,
2492 (SELECT + SELCHK_STRT));
2494 /* Setup our STATE so we know what happened when
2495 the wheels fall off. */
2496 currSCCB->Sccb_scsistat = SELECT_ST;
2498 currTar_Info->TarLUNBusy[lun] = 1;
2502 WRW_HARPOON((port + ID_MSG_STRT),
2503 (MPM_OP + AMSG_OUT +
2504 currSCCB->Sccb_idmsg));
2506 WRW_HARPOON((port + ID_MSG_STRT + 2),
2507 (MPM_OP + AMSG_OUT +
2508 (((unsigned char)(currSCCB->
2511 >> 6) | (unsigned char)0x20)));
2513 for (i = 1; i < QUEUE_DEPTH; i++) {
2514 if (++lastTag >= QUEUE_DEPTH)
2516 if (CurrCard->discQ_Tbl[lastTag] ==
2520 (MPM_OP + AMSG_OUT +
2522 CurrCard->tagQ_Lst = lastTag;
2523 currSCCB->Sccb_tag = lastTag;
2524 CurrCard->discQ_Tbl[lastTag] =
2526 CurrCard->discQCount++;
2531 if (i == QUEUE_DEPTH) {
2532 currTar_Info->TarLUNBusy[lun] = 1;
2533 FPT_queueSelectFail(CurrCard, p_card);
2538 currSCCB->Sccb_scsistat = SELECT_Q_ST;
2540 WR_HARPOON(port + hp_autostart_3,
2541 (SELECT + SELCHK_STRT));
2547 WRW_HARPOON((port + ID_MSG_STRT),
2548 BRH_OP + ALWAYS + NTCMD);
2550 WRW_HARPOON((port + NON_TAG_ID_MSG),
2551 (MPM_OP + AMSG_OUT + currSCCB->Sccb_idmsg));
2553 currSCCB->Sccb_scsistat = SELECT_ST;
2555 WR_HARPOON(port + hp_autostart_3,
2556 (SELECT + SELCHK_STRT));
2559 theCCB = (unsigned char *)&currSCCB->Cdb[0];
2561 cdb_reg = port + CMD_STRT;
2563 for (i = 0; i < currSCCB->CdbLength; i++) {
2564 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + *theCCB));
2569 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
2570 WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
2574 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
2575 WR_HARPOON(port + hp_xferstat, 0x00);
2577 WRW_HARPOON((port + hp_intstat), (PROG_HLT | TIMEOUT | SEL | BUS_FREE));
2579 WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT));
2581 if (!(currSCCB->Sccb_MGRFlags & F_DEV_SELECTED)) {
2582 WR_HARPOON(port + hp_scsictrl_0,
2583 (SEL_TAR | ENA_ATN | ENA_RESEL | ENA_SCAM_SEL));
2586 /* auto_loaded = (RD_HARPOON(port+hp_autostart_3) & (unsigned char)0x1F);
2587 auto_loaded |= AUTO_IMMED; */
2588 auto_loaded = AUTO_IMMED;
2592 WR_HARPOON(port + hp_autostart_3, auto_loaded);
2598 /*---------------------------------------------------------------------
2600 * Function: FPT_sres
2602 * Description: Hookup the correct CCB and handle the incoming messages.
2604 *---------------------------------------------------------------------*/
2606 static void FPT_sres(u32 port, unsigned char p_card,
2607 struct sccb_card *pCurrCard)
2610 unsigned char our_target, message, lun = 0, tag, msgRetryCount;
2612 struct sccb_mgr_tar_info *currTar_Info;
2613 struct sccb *currSCCB;
2615 if (pCurrCard->currentSCCB != NULL) {
2617 &FPT_sccbMgrTbl[p_card][pCurrCard->currentSCCB->TargID];
2620 WR_HARPOON((port + hp_scsictrl_0), (ENA_RESEL | ENA_SCAM_SEL));
2622 currSCCB = pCurrCard->currentSCCB;
2623 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
2624 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
2625 currSCCB->Sccb_scsistat = BUS_FREE_ST;
2627 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
2628 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
2629 currSCCB->Sccb_scsistat = BUS_FREE_ST;
2631 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
2632 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
2634 currTar_Info->TarLUNBusy[currSCCB->Lun] = 0;
2635 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2636 pCurrCard->discQCount--;
2637 pCurrCard->discQ_Tbl[currTar_Info->
2638 LunDiscQ_Idx[currSCCB->
2643 currTar_Info->TarLUNBusy[0] = 0;
2644 if (currSCCB->Sccb_tag) {
2645 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2646 pCurrCard->discQCount--;
2647 pCurrCard->discQ_Tbl[currSCCB->
2651 if (currSCCB->Sccb_scsistat != ABORT_ST) {
2652 pCurrCard->discQCount--;
2653 pCurrCard->discQ_Tbl[currTar_Info->
2660 FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
2663 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
2665 our_target = (unsigned char)(RD_HARPOON(port + hp_select_id) >> 4);
2666 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
2671 currTar_Info = &FPT_sccbMgrTbl[p_card][our_target];
2674 while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
2675 if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
2677 WRW_HARPOON((port + hp_intstat), PHASE);
2682 WRW_HARPOON((port + hp_intstat), PHASE);
2683 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGI_PH) {
2685 message = FPT_sfm(port, pCurrCard->currentSCCB);
2688 if (message <= (0x80 | LUN_MASK)) {
2689 lun = message & (unsigned char)LUN_MASK;
2692 TarStatus & TAR_TAG_Q_MASK) ==
2694 if (currTar_Info->TarTagQ_Cnt !=
2700 ACCEPT_MSG(port); /*Release the ACK for ID msg. */
2736 /*End Tag cmds supported! */
2738 /*End valid ID message. */
2741 ACCEPT_MSG_ATN(port);
2745 /* End good id message. */
2751 ACCEPT_MSG_ATN(port);
2754 (RDW_HARPOON((port + hp_intstat)) &
2756 && !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
2757 && (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
2764 if (msgRetryCount == 1) {
2765 FPT_SendMsg(port, SMPARITY);
2767 FPT_SendMsg(port, SMDEV_RESET);
2769 FPT_sssyncv(port, our_target, NARROW_SCSI,
2772 if (FPT_sccbMgrTbl[p_card][our_target].
2773 TarEEValue & EE_SYNC_MASK) {
2775 FPT_sccbMgrTbl[p_card][our_target].
2776 TarStatus &= ~TAR_SYNC_MASK;
2780 if (FPT_sccbMgrTbl[p_card][our_target].
2781 TarEEValue & EE_WIDE_SCSI) {
2783 FPT_sccbMgrTbl[p_card][our_target].
2784 TarStatus &= ~TAR_WIDE_MASK;
2787 FPT_queueFlushTargSccb(p_card, our_target,
2789 FPT_SccbMgrTableInitTarget(p_card, our_target);
2793 } while (message == 0);
2795 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
2796 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
2797 currTar_Info->TarLUNBusy[lun] = 1;
2798 pCurrCard->currentSCCB =
2799 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[lun]];
2800 if (pCurrCard->currentSCCB != NULL) {
2803 ACCEPT_MSG_ATN(port);
2806 currTar_Info->TarLUNBusy[0] = 1;
2809 if (pCurrCard->discQ_Tbl[tag] != NULL) {
2810 pCurrCard->currentSCCB =
2811 pCurrCard->discQ_Tbl[tag];
2812 currTar_Info->TarTagQ_Cnt--;
2815 ACCEPT_MSG_ATN(port);
2818 pCurrCard->currentSCCB =
2819 pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]];
2820 if (pCurrCard->currentSCCB != NULL) {
2823 ACCEPT_MSG_ATN(port);
2828 if (pCurrCard->currentSCCB != NULL) {
2829 if (pCurrCard->currentSCCB->Sccb_scsistat == ABORT_ST) {
2830 /* During Abort Tag command, the target could have got re-selected
2831 and completed the command. Check the select Q and remove the CCB
2832 if it is in the Select Q */
2833 FPT_queueFindSccb(pCurrCard->currentSCCB, p_card);
2837 while (!(RDW_HARPOON((port + hp_intstat)) & (PHASE | RESET)) &&
2838 !(RD_HARPOON(port + hp_scsisig) & SCSI_REQ) &&
2839 (RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ;
2842 static void FPT_SendMsg(u32 port, unsigned char message)
2844 while (!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) {
2845 if (!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) {
2847 WRW_HARPOON((port + hp_intstat), PHASE);
2852 WRW_HARPOON((port + hp_intstat), PHASE);
2853 if ((RD_HARPOON(port + hp_scsisig) & S_SCSI_PHZ) == S_MSGO_PH) {
2854 WRW_HARPOON((port + hp_intstat),
2855 (BUS_FREE | PHASE | XFER_CNT_0));
2857 WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
2859 WR_HARPOON(port + hp_scsidata_0, message);
2861 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
2865 WR_HARPOON(port + hp_portctrl_0, 0x00);
2867 if ((message == SMABORT) || (message == SMDEV_RESET) ||
2868 (message == SMABORT_TAG)) {
2870 (RDW_HARPOON((port + hp_intstat)) &
2871 (BUS_FREE | PHASE))) {
2874 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
2875 WRW_HARPOON((port + hp_intstat), BUS_FREE);
2881 /*---------------------------------------------------------------------
2883 * Function: FPT_sdecm
2885 * Description: Determine the proper response to the message from the
2888 *---------------------------------------------------------------------*/
2889 static void FPT_sdecm(unsigned char message, u32 port, unsigned char p_card)
2891 struct sccb *currSCCB;
2892 struct sccb_card *CurrCard;
2893 struct sccb_mgr_tar_info *currTar_Info;
2895 CurrCard = &FPT_BL_Card[p_card];
2896 currSCCB = CurrCard->currentSCCB;
2898 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
2900 if (message == SMREST_DATA_PTR) {
2901 if (!(currSCCB->Sccb_XferState & F_NO_DATA_YET)) {
2902 currSCCB->Sccb_ATC = currSCCB->Sccb_savedATC;
2904 FPT_hostDataXferRestart(currSCCB);
2908 WR_HARPOON(port + hp_autostart_1,
2909 (AUTO_IMMED + DISCONNECT_START));
2912 else if (message == SMCMD_COMP) {
2914 if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
2915 currTar_Info->TarStatus &=
2916 ~(unsigned char)TAR_TAG_Q_MASK;
2917 currTar_Info->TarStatus |= (unsigned char)TAG_Q_REJECT;
2924 else if ((message == SMNO_OP) || (message >= SMIDENT)
2925 || (message == SMINIT_RECOVERY) || (message == SMREL_RECOVERY)) {
2928 WR_HARPOON(port + hp_autostart_1,
2929 (AUTO_IMMED + DISCONNECT_START));
2932 else if (message == SMREJECT) {
2934 if ((currSCCB->Sccb_scsistat == SELECT_SN_ST) ||
2935 (currSCCB->Sccb_scsistat == SELECT_WN_ST) ||
2936 ((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)
2937 || ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) ==
2940 WRW_HARPOON((port + hp_intstat), BUS_FREE);
2944 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
2945 (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
2949 if (currSCCB->Lun == 0x00) {
2950 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
2952 currTar_Info->TarStatus |=
2953 (unsigned char)SYNC_SUPPORTED;
2955 currTar_Info->TarEEValue &=
2959 else if (currSCCB->Sccb_scsistat ==
2962 currTar_Info->TarStatus =
2964 TarStatus & ~WIDE_ENABLED) |
2967 currTar_Info->TarEEValue &=
2972 else if ((currTar_Info->
2973 TarStatus & TAR_TAG_Q_MASK) ==
2975 currTar_Info->TarStatus =
2977 TarStatus & ~(unsigned char)
2978 TAR_TAG_Q_MASK) | TAG_Q_REJECT;
2980 currSCCB->ControlByte &= ~F_USE_CMD_Q;
2981 CurrCard->discQCount--;
2982 CurrCard->discQ_Tbl[currSCCB->
2984 currSCCB->Sccb_tag = 0x00;
2989 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
2991 if (currSCCB->Lun == 0x00) {
2992 WRW_HARPOON((port + hp_intstat),
2994 CurrCard->globalFlags |= F_NEW_SCCB_CMD;
3000 if ((CurrCard->globalFlags & F_CONLUN_IO) &&
3002 TarStatus & TAR_TAG_Q_MASK) !=
3004 currTar_Info->TarLUNBusy[currSCCB->
3007 currTar_Info->TarLUNBusy[0] = 1;
3009 currSCCB->ControlByte &=
3010 ~(unsigned char)F_USE_CMD_Q;
3012 WR_HARPOON(port + hp_autostart_1,
3013 (AUTO_IMMED + DISCONNECT_START));
3021 while ((!(RD_HARPOON(port + hp_scsisig) & SCSI_REQ)) &&
3022 (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)))
3026 if (!(RDW_HARPOON((port + hp_intstat)) & BUS_FREE)) {
3027 WR_HARPOON(port + hp_autostart_1,
3028 (AUTO_IMMED + DISCONNECT_START));
3033 else if (message == SMEXT) {
3036 FPT_shandem(port, p_card, currSCCB);
3039 else if (message == SMIGNORWR) {
3041 ACCEPT_MSG(port); /* ACK the RESIDUE MSG */
3043 message = FPT_sfm(port, currSCCB);
3045 if (currSCCB->Sccb_scsimsg != SMPARITY)
3047 WR_HARPOON(port + hp_autostart_1,
3048 (AUTO_IMMED + DISCONNECT_START));
3053 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
3054 currSCCB->Sccb_scsimsg = SMREJECT;
3056 ACCEPT_MSG_ATN(port);
3057 WR_HARPOON(port + hp_autostart_1,
3058 (AUTO_IMMED + DISCONNECT_START));
3062 /*---------------------------------------------------------------------
3064 * Function: FPT_shandem
3066 * Description: Decide what to do with the extended message.
3068 *---------------------------------------------------------------------*/
3069 static void FPT_shandem(u32 port, unsigned char p_card, struct sccb *pCurrSCCB)
3071 unsigned char length, message;
3073 length = FPT_sfm(port, pCurrSCCB);
3077 message = FPT_sfm(port, pCurrSCCB);
3080 if (message == SMSYNC) {
3082 if (length == 0x03) {
3085 FPT_stsyncn(port, p_card);
3088 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3089 ACCEPT_MSG_ATN(port);
3091 } else if (message == SMWDTR) {
3093 if (length == 0x02) {
3096 FPT_stwidn(port, p_card);
3099 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3100 ACCEPT_MSG_ATN(port);
3102 WR_HARPOON(port + hp_autostart_1,
3108 pCurrSCCB->Sccb_scsimsg = SMREJECT;
3109 ACCEPT_MSG_ATN(port);
3111 WR_HARPOON(port + hp_autostart_1,
3112 (AUTO_IMMED + DISCONNECT_START));
3115 if (pCurrSCCB->Sccb_scsimsg != SMPARITY)
3117 WR_HARPOON(port + hp_autostart_1,
3118 (AUTO_IMMED + DISCONNECT_START));
3121 if (pCurrSCCB->Sccb_scsimsg == SMPARITY)
3122 WR_HARPOON(port + hp_autostart_1,
3123 (AUTO_IMMED + DISCONNECT_START));
3127 /*---------------------------------------------------------------------
3129 * Function: FPT_sisyncn
3131 * Description: Read in a message byte from the SCSI bus, and check
3132 * for a parity error.
3134 *---------------------------------------------------------------------*/
3136 static unsigned char FPT_sisyncn(u32 port, unsigned char p_card,
3137 unsigned char syncFlag)
3139 struct sccb *currSCCB;
3140 struct sccb_mgr_tar_info *currTar_Info;
3142 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3143 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3145 if (!((currTar_Info->TarStatus & TAR_SYNC_MASK) == SYNC_TRYING)) {
3147 WRW_HARPOON((port + ID_MSG_STRT),
3148 (MPM_OP + AMSG_OUT +
3150 Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
3152 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
3154 WRW_HARPOON((port + SYNC_MSGS + 0),
3155 (MPM_OP + AMSG_OUT + SMEXT));
3156 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
3157 WRW_HARPOON((port + SYNC_MSGS + 4),
3158 (MPM_OP + AMSG_OUT + SMSYNC));
3160 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3162 WRW_HARPOON((port + SYNC_MSGS + 6),
3163 (MPM_OP + AMSG_OUT + 12));
3165 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
3168 WRW_HARPOON((port + SYNC_MSGS + 6),
3169 (MPM_OP + AMSG_OUT + 25));
3171 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) ==
3174 WRW_HARPOON((port + SYNC_MSGS + 6),
3175 (MPM_OP + AMSG_OUT + 50));
3178 WRW_HARPOON((port + SYNC_MSGS + 6),
3179 (MPM_OP + AMSG_OUT + 00));
3181 WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
3182 WRW_HARPOON((port + SYNC_MSGS + 10),
3183 (MPM_OP + AMSG_OUT + DEFAULT_OFFSET));
3184 WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
3186 if (syncFlag == 0) {
3187 WR_HARPOON(port + hp_autostart_3,
3188 (SELECT + SELCHK_STRT));
3189 currTar_Info->TarStatus =
3191 TarStatus & ~(unsigned char)TAR_SYNC_MASK) |
3192 (unsigned char)SYNC_TRYING);
3194 WR_HARPOON(port + hp_autostart_3,
3195 (AUTO_IMMED + CMD_ONLY_STRT));
3203 currTar_Info->TarStatus |= (unsigned char)SYNC_SUPPORTED;
3204 currTar_Info->TarEEValue &= ~EE_SYNC_MASK;
3209 /*---------------------------------------------------------------------
3211 * Function: FPT_stsyncn
3213 * Description: The has sent us a Sync Nego message so handle it as
3216 *---------------------------------------------------------------------*/
3217 static void FPT_stsyncn(u32 port, unsigned char p_card)
3219 unsigned char sync_msg, offset, sync_reg, our_sync_msg;
3220 struct sccb *currSCCB;
3221 struct sccb_mgr_tar_info *currTar_Info;
3223 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3224 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3226 sync_msg = FPT_sfm(port, currSCCB);
3228 if ((sync_msg == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3229 WR_HARPOON(port + hp_autostart_1,
3230 (AUTO_IMMED + DISCONNECT_START));
3236 offset = FPT_sfm(port, currSCCB);
3238 if ((offset == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3239 WR_HARPOON(port + hp_autostart_1,
3240 (AUTO_IMMED + DISCONNECT_START));
3244 if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_20MB)
3246 our_sync_msg = 12; /* Setup our Message to 20mb/s */
3248 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_10MB)
3250 our_sync_msg = 25; /* Setup our Message to 10mb/s */
3252 else if ((currTar_Info->TarEEValue & EE_SYNC_MASK) == EE_SYNC_5MB)
3254 our_sync_msg = 50; /* Setup our Message to 5mb/s */
3257 our_sync_msg = 0; /* Message = Async */
3259 if (sync_msg < our_sync_msg) {
3260 sync_msg = our_sync_msg; /*if faster, then set to max. */
3263 if (offset == ASYNC)
3266 if (offset > MAX_OFFSET)
3267 offset = MAX_OFFSET;
3273 sync_reg = 0x20; /* Use 10MB/s */
3277 sync_reg = 0x40; /* Use 6.6MB/s */
3281 sync_reg = 0x60; /* Use 5MB/s */
3285 sync_reg = 0x80; /* Use 4MB/s */
3289 sync_reg = 0xA0; /* Use 3.33MB/s */
3293 sync_reg = 0xC0; /* Use 2.85MB/s */
3297 sync_reg = 0xE0; /* Use 2.5MB/s */
3299 if (sync_msg > 100) {
3301 sync_reg = 0x00; /* Use ASYNC */
3305 if (currTar_Info->TarStatus & WIDE_ENABLED)
3311 sync_reg |= (offset | NARROW_SCSI);
3313 FPT_sssyncv(port, currSCCB->TargID, sync_reg, currTar_Info);
3315 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
3319 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3320 ~(unsigned char)TAR_SYNC_MASK) |
3321 (unsigned char)SYNC_SUPPORTED);
3323 WR_HARPOON(port + hp_autostart_1,
3324 (AUTO_IMMED + DISCONNECT_START));
3329 ACCEPT_MSG_ATN(port);
3331 FPT_sisyncr(port, sync_msg, offset);
3333 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3334 ~(unsigned char)TAR_SYNC_MASK) |
3335 (unsigned char)SYNC_SUPPORTED);
3339 /*---------------------------------------------------------------------
3341 * Function: FPT_sisyncr
3343 * Description: Answer the targets sync message.
3345 *---------------------------------------------------------------------*/
3346 static void FPT_sisyncr(u32 port, unsigned char sync_pulse,
3347 unsigned char offset)
3350 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT));
3351 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x03));
3352 WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMSYNC));
3353 WRW_HARPOON((port + SYNC_MSGS + 6), (MPM_OP + AMSG_OUT + sync_pulse));
3354 WRW_HARPOON((port + SYNC_MSGS + 8), (RAT_OP));
3355 WRW_HARPOON((port + SYNC_MSGS + 10), (MPM_OP + AMSG_OUT + offset));
3356 WRW_HARPOON((port + SYNC_MSGS + 12), (BRH_OP + ALWAYS + NP));
3359 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3360 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
3362 WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
3364 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
3368 /*---------------------------------------------------------------------
3370 * Function: FPT_siwidn
3372 * Description: Read in a message byte from the SCSI bus, and check
3373 * for a parity error.
3375 *---------------------------------------------------------------------*/
3377 static unsigned char FPT_siwidn(u32 port, unsigned char p_card)
3379 struct sccb *currSCCB;
3380 struct sccb_mgr_tar_info *currTar_Info;
3382 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3383 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3385 if (!((currTar_Info->TarStatus & TAR_WIDE_MASK) == WIDE_NEGOCIATED)) {
3387 WRW_HARPOON((port + ID_MSG_STRT),
3388 (MPM_OP + AMSG_OUT +
3390 Sccb_idmsg & ~(unsigned char)DISC_PRIV)));
3392 WRW_HARPOON((port + ID_MSG_STRT + 2), BRH_OP + ALWAYS + CMDPZ);
3394 WRW_HARPOON((port + SYNC_MSGS + 0),
3395 (MPM_OP + AMSG_OUT + SMEXT));
3396 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
3397 WRW_HARPOON((port + SYNC_MSGS + 4),
3398 (MPM_OP + AMSG_OUT + SMWDTR));
3399 WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
3400 WRW_HARPOON((port + SYNC_MSGS + 8),
3401 (MPM_OP + AMSG_OUT + SM16BIT));
3402 WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
3404 WR_HARPOON(port + hp_autostart_3, (SELECT + SELCHK_STRT));
3406 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3407 ~(unsigned char)TAR_WIDE_MASK) |
3408 (unsigned char)WIDE_ENABLED);
3415 currTar_Info->TarStatus = ((currTar_Info->TarStatus &
3416 ~(unsigned char)TAR_WIDE_MASK) |
3419 currTar_Info->TarEEValue &= ~EE_WIDE_SCSI;
3424 /*---------------------------------------------------------------------
3426 * Function: FPT_stwidn
3428 * Description: The has sent us a Wide Nego message so handle it as
3431 *---------------------------------------------------------------------*/
3432 static void FPT_stwidn(u32 port, unsigned char p_card)
3434 unsigned char width;
3435 struct sccb *currSCCB;
3436 struct sccb_mgr_tar_info *currTar_Info;
3438 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3439 currTar_Info = &FPT_sccbMgrTbl[p_card][currSCCB->TargID];
3441 width = FPT_sfm(port, currSCCB);
3443 if ((width == 0x00) && (currSCCB->Sccb_scsimsg == SMPARITY)) {
3444 WR_HARPOON(port + hp_autostart_1,
3445 (AUTO_IMMED + DISCONNECT_START));
3449 if (!(currTar_Info->TarEEValue & EE_WIDE_SCSI))
3453 currTar_Info->TarStatus |= WIDE_ENABLED;
3456 width = NARROW_SCSI;
3457 currTar_Info->TarStatus &= ~WIDE_ENABLED;
3460 FPT_sssyncv(port, currSCCB->TargID, width, currTar_Info);
3462 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
3464 currTar_Info->TarStatus |= WIDE_NEGOCIATED;
3467 ((currTar_Info->TarStatus & TAR_SYNC_MASK) ==
3469 ACCEPT_MSG_ATN(port);
3471 FPT_sisyncn(port, p_card, 1);
3472 currSCCB->Sccb_scsistat = SELECT_SN_ST;
3476 WR_HARPOON(port + hp_autostart_1,
3477 (AUTO_IMMED + DISCONNECT_START));
3483 ACCEPT_MSG_ATN(port);
3485 if (currTar_Info->TarEEValue & EE_WIDE_SCSI)
3490 FPT_siwidr(port, width);
3492 currTar_Info->TarStatus |= (WIDE_NEGOCIATED | WIDE_ENABLED);
3496 /*---------------------------------------------------------------------
3498 * Function: FPT_siwidr
3500 * Description: Answer the targets Wide nego message.
3502 *---------------------------------------------------------------------*/
3503 static void FPT_siwidr(u32 port, unsigned char width)
3506 WRW_HARPOON((port + SYNC_MSGS + 0), (MPM_OP + AMSG_OUT + SMEXT));
3507 WRW_HARPOON((port + SYNC_MSGS + 2), (MPM_OP + AMSG_OUT + 0x02));
3508 WRW_HARPOON((port + SYNC_MSGS + 4), (MPM_OP + AMSG_OUT + SMWDTR));
3509 WRW_HARPOON((port + SYNC_MSGS + 6), (RAT_OP));
3510 WRW_HARPOON((port + SYNC_MSGS + 8), (MPM_OP + AMSG_OUT + width));
3511 WRW_HARPOON((port + SYNC_MSGS + 10), (BRH_OP + ALWAYS + NP));
3514 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3515 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT_1);
3517 WR_HARPOON(port + hp_autostart_3, (AUTO_IMMED + CMD_ONLY_STRT));
3519 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | AUTO_INT))) {
3523 /*---------------------------------------------------------------------
3525 * Function: FPT_sssyncv
3527 * Description: Write the desired value to the Sync Register for the
3530 *---------------------------------------------------------------------*/
3531 static void FPT_sssyncv(u32 p_port, unsigned char p_id,
3532 unsigned char p_sync_value,
3533 struct sccb_mgr_tar_info *currTar_Info)
3535 unsigned char index;
3542 index = 12; /* hp_synctarg_0 */
3545 index = 13; /* hp_synctarg_1 */
3548 index = 14; /* hp_synctarg_2 */
3551 index = 15; /* hp_synctarg_3 */
3554 index = 8; /* hp_synctarg_4 */
3557 index = 9; /* hp_synctarg_5 */
3560 index = 10; /* hp_synctarg_6 */
3563 index = 11; /* hp_synctarg_7 */
3566 index = 4; /* hp_synctarg_8 */
3569 index = 5; /* hp_synctarg_9 */
3572 index = 6; /* hp_synctarg_10 */
3575 index = 7; /* hp_synctarg_11 */
3578 index = 0; /* hp_synctarg_12 */
3581 index = 1; /* hp_synctarg_13 */
3584 index = 2; /* hp_synctarg_14 */
3587 index = 3; /* hp_synctarg_15 */
3591 WR_HARPOON(p_port + hp_synctarg_base + index, p_sync_value);
3593 currTar_Info->TarSyncCtrl = p_sync_value;
3596 /*---------------------------------------------------------------------
3598 * Function: FPT_sresb
3600 * Description: Reset the desired card's SCSI bus.
3602 *---------------------------------------------------------------------*/
3603 static void FPT_sresb(u32 port, unsigned char p_card)
3605 unsigned char scsiID, i;
3607 struct sccb_mgr_tar_info *currTar_Info;
3609 WR_HARPOON(port + hp_page_ctrl,
3610 (RD_HARPOON(port + hp_page_ctrl) | G_INT_DISABLE));
3611 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
3613 WR_HARPOON(port + hp_scsictrl_0, SCSI_RST);
3615 scsiID = RD_HARPOON(port + hp_seltimeout);
3616 WR_HARPOON(port + hp_seltimeout, TO_5ms);
3617 WRW_HARPOON((port + hp_intstat), TIMEOUT);
3619 WR_HARPOON(port + hp_portctrl_0, (SCSI_PORT | START_TO));
3621 while (!(RDW_HARPOON((port + hp_intstat)) & TIMEOUT)) {
3624 WR_HARPOON(port + hp_seltimeout, scsiID);
3626 WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
3628 FPT_Wait(port, TO_5ms);
3630 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
3632 WR_HARPOON(port + hp_int_mask, (RD_HARPOON(port + hp_int_mask) | 0x00));
3634 for (scsiID = 0; scsiID < MAX_SCSI_TAR; scsiID++) {
3635 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
3637 if (currTar_Info->TarEEValue & EE_SYNC_MASK) {
3638 currTar_Info->TarSyncCtrl = 0;
3639 currTar_Info->TarStatus &= ~TAR_SYNC_MASK;
3642 if (currTar_Info->TarEEValue & EE_WIDE_SCSI) {
3643 currTar_Info->TarStatus &= ~TAR_WIDE_MASK;
3646 FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
3648 FPT_SccbMgrTableInitTarget(p_card, scsiID);
3651 FPT_BL_Card[p_card].scanIndex = 0x00;
3652 FPT_BL_Card[p_card].currentSCCB = NULL;
3653 FPT_BL_Card[p_card].globalFlags &= ~(F_TAG_STARTED | F_HOST_XFER_ACT
3655 FPT_BL_Card[p_card].cmdCounter = 0x00;
3656 FPT_BL_Card[p_card].discQCount = 0x00;
3657 FPT_BL_Card[p_card].tagQ_Lst = 0x01;
3659 for (i = 0; i < QUEUE_DEPTH; i++)
3660 FPT_BL_Card[p_card].discQ_Tbl[i] = NULL;
3662 WR_HARPOON(port + hp_page_ctrl,
3663 (RD_HARPOON(port + hp_page_ctrl) & ~G_INT_DISABLE));
3667 /*---------------------------------------------------------------------
3669 * Function: FPT_ssenss
3671 * Description: Setup for the Auto Sense command.
3673 *---------------------------------------------------------------------*/
3674 static void FPT_ssenss(struct sccb_card *pCurrCard)
3677 struct sccb *currSCCB;
3679 currSCCB = pCurrCard->currentSCCB;
3681 currSCCB->Save_CdbLen = currSCCB->CdbLength;
3683 for (i = 0; i < 6; i++) {
3685 currSCCB->Save_Cdb[i] = currSCCB->Cdb[i];
3688 currSCCB->CdbLength = SIX_BYTE_CMD;
3689 currSCCB->Cdb[0] = SCSI_REQUEST_SENSE;
3690 currSCCB->Cdb[1] = currSCCB->Cdb[1] & (unsigned char)0xE0; /*Keep LUN. */
3691 currSCCB->Cdb[2] = 0x00;
3692 currSCCB->Cdb[3] = 0x00;
3693 currSCCB->Cdb[4] = currSCCB->RequestSenseLength;
3694 currSCCB->Cdb[5] = 0x00;
3696 currSCCB->Sccb_XferCnt = (u32)currSCCB->RequestSenseLength;
3698 currSCCB->Sccb_ATC = 0x00;
3700 currSCCB->Sccb_XferState |= F_AUTO_SENSE;
3702 currSCCB->Sccb_XferState &= ~F_SG_XFER;
3704 currSCCB->Sccb_idmsg = currSCCB->Sccb_idmsg & ~(unsigned char)DISC_PRIV;
3706 currSCCB->ControlByte = 0x00;
3708 currSCCB->Sccb_MGRFlags &= F_STATUSLOADED;
3711 /*---------------------------------------------------------------------
3713 * Function: FPT_sxfrp
3715 * Description: Transfer data into the bit bucket until the device
3716 * decides to switch phase.
3718 *---------------------------------------------------------------------*/
3720 static void FPT_sxfrp(u32 p_port, unsigned char p_card)
3722 unsigned char curr_phz;
3724 DISABLE_AUTO(p_port);
3726 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
3728 FPT_hostDataXferAbort(p_port, p_card,
3729 FPT_BL_Card[p_card].currentSCCB);
3733 /* If the Automation handled the end of the transfer then do not
3734 match the phase or we will get out of sync with the ISR. */
3736 if (RDW_HARPOON((p_port + hp_intstat)) &
3737 (BUS_FREE | XFER_CNT_0 | AUTO_INT))
3740 WR_HARPOON(p_port + hp_xfercnt_0, 0x00);
3742 curr_phz = RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ;
3744 WRW_HARPOON((p_port + hp_intstat), XFER_CNT_0);
3746 WR_HARPOON(p_port + hp_scsisig, curr_phz);
3748 while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET)) &&
3750 (RD_HARPOON(p_port + hp_scsisig) & (unsigned char)S_SCSI_PHZ)))
3752 if (curr_phz & (unsigned char)SCSI_IOBIT) {
3753 WR_HARPOON(p_port + hp_portctrl_0,
3754 (SCSI_PORT | HOST_PORT | SCSI_INBIT));
3756 if (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
3757 RD_HARPOON(p_port + hp_fifodata_0);
3760 WR_HARPOON(p_port + hp_portctrl_0,
3761 (SCSI_PORT | HOST_PORT | HOST_WRT));
3762 if (RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY) {
3763 WR_HARPOON(p_port + hp_fifodata_0, 0xFA);
3766 } /* End of While loop for padding data I/O phase */
3768 while (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
3769 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ)
3773 WR_HARPOON(p_port + hp_portctrl_0,
3774 (SCSI_PORT | HOST_PORT | SCSI_INBIT));
3775 while (!(RD_HARPOON(p_port + hp_xferstat) & FIFO_EMPTY)) {
3776 RD_HARPOON(p_port + hp_fifodata_0);
3779 if (!(RDW_HARPOON((p_port + hp_intstat)) & (BUS_FREE | RESET))) {
3780 WR_HARPOON(p_port + hp_autostart_0,
3781 (AUTO_IMMED + DISCONNECT_START));
3782 while (!(RDW_HARPOON((p_port + hp_intstat)) & AUTO_INT)) {
3785 if (RDW_HARPOON((p_port + hp_intstat)) &
3786 (ICMD_COMP | ITAR_DISC))
3788 (RDW_HARPOON((p_port + hp_intstat)) &
3789 (BUS_FREE | RSEL))) ;
3793 /*---------------------------------------------------------------------
3795 * Function: FPT_schkdd
3797 * Description: Make sure data has been flushed from both FIFOs and abort
3798 * the operations if necessary.
3800 *---------------------------------------------------------------------*/
3802 static void FPT_schkdd(u32 port, unsigned char p_card)
3804 unsigned short TimeOutLoop;
3805 unsigned char sPhase;
3807 struct sccb *currSCCB;
3809 currSCCB = FPT_BL_Card[p_card].currentSCCB;
3811 if ((currSCCB->Sccb_scsistat != DATA_OUT_ST) &&
3812 (currSCCB->Sccb_scsistat != DATA_IN_ST)) {
3816 if (currSCCB->Sccb_XferState & F_ODD_BALL_CNT) {
3818 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - 1);
3820 currSCCB->Sccb_XferCnt = 1;
3822 currSCCB->Sccb_XferState &= ~F_ODD_BALL_CNT;
3823 WRW_HARPOON((port + hp_fiforead), (unsigned short)0x00);
3824 WR_HARPOON(port + hp_xferstat, 0x00);
3829 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
3831 currSCCB->Sccb_XferCnt = 0;
3834 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
3835 (currSCCB->HostStatus == SCCB_COMPLETE)) {
3837 currSCCB->HostStatus = SCCB_PARITY_ERR;
3838 WRW_HARPOON((port + hp_intstat), PARITY);
3841 FPT_hostDataXferAbort(port, p_card, currSCCB);
3843 while (RD_HARPOON(port + hp_scsisig) & SCSI_ACK) {
3848 while (RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY) {
3849 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
3852 if (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) {
3855 if (RDW_HARPOON((port + hp_intstat)) & RESET) {
3858 if ((RD_HARPOON(port + hp_scsisig) & SCSI_REQ)
3859 || (TimeOutLoop++ > 0x3000))
3863 sPhase = RD_HARPOON(port + hp_scsisig) & (SCSI_BSY | S_SCSI_PHZ);
3864 if ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) ||
3865 (RD_HARPOON(port + hp_offsetctr) & (unsigned char)0x1F) ||
3866 (sPhase == (SCSI_BSY | S_DATAO_PH)) ||
3867 (sPhase == (SCSI_BSY | S_DATAI_PH))) {
3869 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
3871 if (!(currSCCB->Sccb_XferState & F_ALL_XFERRED)) {
3872 if (currSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
3873 FPT_phaseDataIn(port, p_card);
3877 FPT_phaseDataOut(port, p_card);
3880 FPT_sxfrp(port, p_card);
3881 if (!(RDW_HARPOON((port + hp_intstat)) &
3882 (BUS_FREE | ICMD_COMP | ITAR_DISC | RESET))) {
3883 WRW_HARPOON((port + hp_intstat), AUTO_INT);
3884 FPT_phaseDecode(port, p_card);
3891 WR_HARPOON(port + hp_portctrl_0, 0x00);
3895 /*---------------------------------------------------------------------
3897 * Function: FPT_sinits
3899 * Description: Setup SCCB manager fields in this SCCB.
3901 *---------------------------------------------------------------------*/
3903 static void FPT_sinits(struct sccb *p_sccb, unsigned char p_card)
3905 struct sccb_mgr_tar_info *currTar_Info;
3907 if ((p_sccb->TargID >= MAX_SCSI_TAR) || (p_sccb->Lun >= MAX_LUN)) {
3910 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
3912 p_sccb->Sccb_XferState = 0x00;
3913 p_sccb->Sccb_XferCnt = p_sccb->DataLength;
3915 if ((p_sccb->OperationCode == SCATTER_GATHER_COMMAND) ||
3916 (p_sccb->OperationCode == RESIDUAL_SG_COMMAND)) {
3918 p_sccb->Sccb_SGoffset = 0;
3919 p_sccb->Sccb_XferState = F_SG_XFER;
3920 p_sccb->Sccb_XferCnt = 0x00;
3923 if (p_sccb->DataLength == 0x00)
3925 p_sccb->Sccb_XferState |= F_ALL_XFERRED;
3927 if (p_sccb->ControlByte & F_USE_CMD_Q) {
3928 if ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) == TAG_Q_REJECT)
3929 p_sccb->ControlByte &= ~F_USE_CMD_Q;
3932 currTar_Info->TarStatus |= TAG_Q_TRYING;
3935 /* For !single SCSI device in system & device allow Disconnect
3936 or command is tag_q type then send Cmd with Disconnect Enable
3937 else send Cmd with Disconnect Disable */
3940 if (((!(FPT_BL_Card[p_card].globalFlags & F_SINGLE_DEVICE)) &&
3941 (currTar_Info->TarStatus & TAR_ALLOW_DISC)) ||
3942 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
3944 if ((currTar_Info->TarStatus & TAR_ALLOW_DISC) ||
3945 (currTar_Info->TarStatus & TAG_Q_TRYING)) {
3946 p_sccb->Sccb_idmsg =
3947 (unsigned char)(SMIDENT | DISC_PRIV) | p_sccb->Lun;
3952 p_sccb->Sccb_idmsg = (unsigned char)SMIDENT | p_sccb->Lun;
3955 p_sccb->HostStatus = 0x00;
3956 p_sccb->TargetStatus = 0x00;
3957 p_sccb->Sccb_tag = 0x00;
3958 p_sccb->Sccb_MGRFlags = 0x00;
3959 p_sccb->Sccb_sgseg = 0x00;
3960 p_sccb->Sccb_ATC = 0x00;
3961 p_sccb->Sccb_savedATC = 0x00;
3963 p_sccb->SccbVirtDataPtr = 0x00;
3964 p_sccb->Sccb_forwardlink = NULL;
3965 p_sccb->Sccb_backlink = NULL;
3967 p_sccb->Sccb_scsistat = BUS_FREE_ST;
3968 p_sccb->SccbStatus = SCCB_IN_PROCESS;
3969 p_sccb->Sccb_scsimsg = SMNO_OP;
3973 /*---------------------------------------------------------------------
3975 * Function: Phase Decode
3977 * Description: Determine the phase and call the appropriate function.
3979 *---------------------------------------------------------------------*/
3981 static void FPT_phaseDecode(u32 p_port, unsigned char p_card)
3983 unsigned char phase_ref;
3984 void (*phase) (u32, unsigned char);
3986 DISABLE_AUTO(p_port);
3989 (unsigned char)(RD_HARPOON(p_port + hp_scsisig) & S_SCSI_PHZ);
3991 phase = FPT_s_PhaseTbl[phase_ref];
3993 (*phase) (p_port, p_card); /* Call the correct phase func */
3996 /*---------------------------------------------------------------------
3998 * Function: Data Out Phase
4000 * Description: Start up both the BusMaster and Xbow.
4002 *---------------------------------------------------------------------*/
4004 static void FPT_phaseDataOut(u32 port, unsigned char p_card)
4007 struct sccb *currSCCB;
4009 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4010 if (currSCCB == NULL) {
4011 return; /* Exit if No SCCB record */
4014 currSCCB->Sccb_scsistat = DATA_OUT_ST;
4015 currSCCB->Sccb_XferState &= ~(F_HOST_XFER_DIR | F_NO_DATA_YET);
4017 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
4019 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4021 WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
4023 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4025 if (currSCCB->Sccb_XferCnt == 0) {
4027 if ((currSCCB->ControlByte & SCCB_DATA_XFER_OUT) &&
4028 (currSCCB->HostStatus == SCCB_COMPLETE))
4029 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4031 FPT_sxfrp(port, p_card);
4032 if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
4033 FPT_phaseDecode(port, p_card);
4037 /*---------------------------------------------------------------------
4039 * Function: Data In Phase
4041 * Description: Startup the BusMaster and the XBOW.
4043 *---------------------------------------------------------------------*/
4045 static void FPT_phaseDataIn(u32 port, unsigned char p_card)
4048 struct sccb *currSCCB;
4050 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4052 if (currSCCB == NULL) {
4053 return; /* Exit if No SCCB record */
4056 currSCCB->Sccb_scsistat = DATA_IN_ST;
4057 currSCCB->Sccb_XferState |= F_HOST_XFER_DIR;
4058 currSCCB->Sccb_XferState &= ~F_NO_DATA_YET;
4060 WR_HARPOON(port + hp_portctrl_0, SCSI_PORT);
4062 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4064 WR_HARPOON(port + hp_autostart_0, (END_DATA + END_DATA_START));
4066 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4068 if (currSCCB->Sccb_XferCnt == 0) {
4070 if ((currSCCB->ControlByte & SCCB_DATA_XFER_IN) &&
4071 (currSCCB->HostStatus == SCCB_COMPLETE))
4072 currSCCB->HostStatus = SCCB_DATA_OVER_RUN;
4074 FPT_sxfrp(port, p_card);
4075 if (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | RESET)))
4076 FPT_phaseDecode(port, p_card);
4081 /*---------------------------------------------------------------------
4083 * Function: Command Phase
4085 * Description: Load the CDB into the automation and start it up.
4087 *---------------------------------------------------------------------*/
4089 static void FPT_phaseCommand(u32 p_port, unsigned char p_card)
4091 struct sccb *currSCCB;
4095 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4097 if (currSCCB->OperationCode == RESET_COMMAND) {
4099 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4100 currSCCB->CdbLength = SIX_BYTE_CMD;
4103 WR_HARPOON(p_port + hp_scsisig, 0x00);
4105 ARAM_ACCESS(p_port);
4107 cdb_reg = p_port + CMD_STRT;
4109 for (i = 0; i < currSCCB->CdbLength; i++) {
4111 if (currSCCB->OperationCode == RESET_COMMAND)
4113 WRW_HARPOON(cdb_reg, (MPM_OP + ACOMMAND + 0x00));
4116 WRW_HARPOON(cdb_reg,
4117 (MPM_OP + ACOMMAND + currSCCB->Cdb[i]));
4121 if (currSCCB->CdbLength != TWELVE_BYTE_CMD)
4122 WRW_HARPOON(cdb_reg, (BRH_OP + ALWAYS + NP));
4124 WR_HARPOON(p_port + hp_portctrl_0, (SCSI_PORT));
4126 currSCCB->Sccb_scsistat = COMMAND_ST;
4128 WR_HARPOON(p_port + hp_autostart_3, (AUTO_IMMED | CMD_ONLY_STRT));
4129 SGRAM_ACCESS(p_port);
4132 /*---------------------------------------------------------------------
4134 * Function: Status phase
4136 * Description: Bring in the status and command complete message bytes
4138 *---------------------------------------------------------------------*/
4140 static void FPT_phaseStatus(u32 port, unsigned char p_card)
4142 /* Start-up the automation to finish off this command and let the
4143 isr handle the interrupt for command complete when it comes in.
4144 We could wait here for the interrupt to be generated?
4147 WR_HARPOON(port + hp_scsisig, 0x00);
4149 WR_HARPOON(port + hp_autostart_0, (AUTO_IMMED + END_DATA_START));
4152 /*---------------------------------------------------------------------
4154 * Function: Phase Message Out
4156 * Description: Send out our message (if we have one) and handle whatever
4159 *---------------------------------------------------------------------*/
4161 static void FPT_phaseMsgOut(u32 port, unsigned char p_card)
4163 unsigned char message, scsiID;
4164 struct sccb *currSCCB;
4165 struct sccb_mgr_tar_info *currTar_Info;
4167 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4169 if (currSCCB != NULL) {
4171 message = currSCCB->Sccb_scsimsg;
4172 scsiID = currSCCB->TargID;
4174 if (message == SMDEV_RESET) {
4176 currTar_Info = &FPT_sccbMgrTbl[p_card][scsiID];
4177 currTar_Info->TarSyncCtrl = 0;
4178 FPT_sssyncv(port, scsiID, NARROW_SCSI, currTar_Info);
4180 if (FPT_sccbMgrTbl[p_card][scsiID].
4181 TarEEValue & EE_SYNC_MASK) {
4183 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
4188 if (FPT_sccbMgrTbl[p_card][scsiID].
4189 TarEEValue & EE_WIDE_SCSI) {
4191 FPT_sccbMgrTbl[p_card][scsiID].TarStatus &=
4195 FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
4196 FPT_SccbMgrTableInitTarget(p_card, scsiID);
4197 } else if (currSCCB->Sccb_scsistat == ABORT_ST) {
4198 currSCCB->HostStatus = SCCB_COMPLETE;
4199 if (FPT_BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] !=
4201 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4203 FPT_sccbMgrTbl[p_card][scsiID].TarTagQ_Cnt--;
4208 else if (currSCCB->Sccb_scsistat < COMMAND_ST) {
4210 if (message == SMNO_OP) {
4211 currSCCB->Sccb_MGRFlags |= F_DEV_SELECTED;
4213 FPT_ssel(port, p_card);
4218 if (message == SMABORT)
4220 FPT_queueFlushSccb(p_card, SCCB_COMPLETE);
4227 WRW_HARPOON((port + hp_intstat), (BUS_FREE | PHASE | XFER_CNT_0));
4229 WR_HARPOON(port + hp_portctrl_0, SCSI_BUS_EN);
4231 WR_HARPOON(port + hp_scsidata_0, message);
4233 WR_HARPOON(port + hp_scsisig, (SCSI_ACK + S_ILL_PH));
4237 WR_HARPOON(port + hp_portctrl_0, 0x00);
4239 if ((message == SMABORT) || (message == SMDEV_RESET) ||
4240 (message == SMABORT_TAG)) {
4242 while (!(RDW_HARPOON((port + hp_intstat)) & (BUS_FREE | PHASE))) {
4245 if (RDW_HARPOON((port + hp_intstat)) & BUS_FREE) {
4246 WRW_HARPOON((port + hp_intstat), BUS_FREE);
4248 if (currSCCB != NULL) {
4250 if ((FPT_BL_Card[p_card].
4251 globalFlags & F_CONLUN_IO)
4253 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4254 TarStatus & TAR_TAG_Q_MASK) !=
4256 FPT_sccbMgrTbl[p_card][currSCCB->
4258 TarLUNBusy[currSCCB->Lun] = 0;
4260 FPT_sccbMgrTbl[p_card][currSCCB->
4264 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
4269 FPT_BL_Card[p_card].globalFlags |=
4276 FPT_sxfrp(port, p_card);
4282 if (message == SMPARITY) {
4283 currSCCB->Sccb_scsimsg = SMNO_OP;
4284 WR_HARPOON(port + hp_autostart_1,
4285 (AUTO_IMMED + DISCONNECT_START));
4287 FPT_sxfrp(port, p_card);
4292 /*---------------------------------------------------------------------
4294 * Function: Message In phase
4296 * Description: Bring in the message and determine what to do with it.
4298 *---------------------------------------------------------------------*/
4300 static void FPT_phaseMsgIn(u32 port, unsigned char p_card)
4302 unsigned char message;
4303 struct sccb *currSCCB;
4305 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4307 if (FPT_BL_Card[p_card].globalFlags & F_HOST_XFER_ACT) {
4309 FPT_phaseChkFifo(port, p_card);
4312 message = RD_HARPOON(port + hp_scsidata_0);
4313 if ((message == SMDISC) || (message == SMSAVE_DATA_PTR)) {
4315 WR_HARPOON(port + hp_autostart_1,
4316 (AUTO_IMMED + END_DATA_START));
4322 message = FPT_sfm(port, currSCCB);
4325 FPT_sdecm(message, port, p_card);
4328 if (currSCCB->Sccb_scsimsg != SMPARITY)
4330 WR_HARPOON(port + hp_autostart_1,
4331 (AUTO_IMMED + DISCONNECT_START));
4337 /*---------------------------------------------------------------------
4339 * Function: Illegal phase
4341 * Description: Target switched to some illegal phase, so all we can do
4342 * is report an error back to the host (if that is possible)
4343 * and send an ABORT message to the misbehaving target.
4345 *---------------------------------------------------------------------*/
4347 static void FPT_phaseIllegal(u32 port, unsigned char p_card)
4349 struct sccb *currSCCB;
4351 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4353 WR_HARPOON(port + hp_scsisig, RD_HARPOON(port + hp_scsisig));
4354 if (currSCCB != NULL) {
4356 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4357 currSCCB->Sccb_scsistat = ABORT_ST;
4358 currSCCB->Sccb_scsimsg = SMABORT;
4361 ACCEPT_MSG_ATN(port);
4364 /*---------------------------------------------------------------------
4366 * Function: Phase Check FIFO
4368 * Description: Make sure data has been flushed from both FIFOs and abort
4369 * the operations if necessary.
4371 *---------------------------------------------------------------------*/
4373 static void FPT_phaseChkFifo(u32 port, unsigned char p_card)
4376 struct sccb *currSCCB;
4378 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4380 if (currSCCB->Sccb_scsistat == DATA_IN_ST) {
4382 while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) &&
4383 (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)) {
4386 if (!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY)) {
4387 currSCCB->Sccb_ATC += currSCCB->Sccb_XferCnt;
4389 currSCCB->Sccb_XferCnt = 0;
4391 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
4392 (currSCCB->HostStatus == SCCB_COMPLETE)) {
4393 currSCCB->HostStatus = SCCB_PARITY_ERR;
4394 WRW_HARPOON((port + hp_intstat), PARITY);
4397 FPT_hostDataXferAbort(port, p_card, currSCCB);
4399 FPT_dataXferProcessor(port, &FPT_BL_Card[p_card]);
4401 while ((!(RD_HARPOON(port + hp_xferstat) & FIFO_EMPTY))
4402 && (RD_HARPOON(port + hp_ext_status) &
4409 /*End Data In specific code. */
4410 GET_XFER_CNT(port, xfercnt);
4412 WR_HARPOON(port + hp_xfercnt_0, 0x00);
4414 WR_HARPOON(port + hp_portctrl_0, 0x00);
4416 currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - xfercnt);
4418 currSCCB->Sccb_XferCnt = xfercnt;
4420 if ((RDW_HARPOON((port + hp_intstat)) & PARITY) &&
4421 (currSCCB->HostStatus == SCCB_COMPLETE)) {
4423 currSCCB->HostStatus = SCCB_PARITY_ERR;
4424 WRW_HARPOON((port + hp_intstat), PARITY);
4427 FPT_hostDataXferAbort(port, p_card, currSCCB);
4429 WR_HARPOON(port + hp_fifowrite, 0x00);
4430 WR_HARPOON(port + hp_fiforead, 0x00);
4431 WR_HARPOON(port + hp_xferstat, 0x00);
4433 WRW_HARPOON((port + hp_intstat), XFER_CNT_0);
4436 /*---------------------------------------------------------------------
4438 * Function: Phase Bus Free
4440 * Description: We just went bus free so figure out if it was
4441 * because of command complete or from a disconnect.
4443 *---------------------------------------------------------------------*/
4444 static void FPT_phaseBusFree(u32 port, unsigned char p_card)
4446 struct sccb *currSCCB;
4448 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4450 if (currSCCB != NULL) {
4454 if (currSCCB->OperationCode == RESET_COMMAND) {
4456 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4457 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4458 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4459 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4460 TarLUNBusy[currSCCB->Lun] = 0;
4462 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4465 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
4468 FPT_queueSearchSelect(&FPT_BL_Card[p_card], p_card);
4472 else if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
4473 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
4474 (unsigned char)SYNC_SUPPORTED;
4475 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4479 else if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
4480 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
4481 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4482 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
4484 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4488 else if (currSCCB->Sccb_scsistat == SELECT_Q_ST) {
4489 /* Make sure this is not a phony BUS_FREE. If we were
4490 reselected or if BUSY is NOT on then this is a
4491 valid BUS FREE. SRR Wednesday, 5/10/1995. */
4493 if ((!(RD_HARPOON(port + hp_scsisig) & SCSI_BSY)) ||
4494 (RDW_HARPOON((port + hp_intstat)) & RSEL)) {
4495 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4496 TarStatus &= ~TAR_TAG_Q_MASK;
4497 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4498 TarStatus |= TAG_Q_REJECT;
4508 currSCCB->Sccb_scsistat = BUS_FREE_ST;
4510 if (!currSCCB->HostStatus) {
4511 currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
4514 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4515 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4516 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4517 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4518 TarLUNBusy[currSCCB->Lun] = 0;
4520 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4523 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB,
4528 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4530 } /*end if !=null */
4533 /*---------------------------------------------------------------------
4535 * Function: Auto Load Default Map
4537 * Description: Load the Automation RAM with the default map values.
4539 *---------------------------------------------------------------------*/
4540 static void FPT_autoLoadDefaultMap(u32 p_port)
4544 ARAM_ACCESS(p_port);
4545 map_addr = p_port + hp_aramBase;
4547 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0xC0)); /*ID MESSAGE */
4549 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x20)); /*SIMPLE TAG QUEUEING MSG */
4551 WRW_HARPOON(map_addr, RAT_OP); /*RESET ATTENTION */
4553 WRW_HARPOON(map_addr, (MPM_OP + AMSG_OUT + 0x00)); /*TAG ID MSG */
4555 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 0 */
4557 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 1 */
4559 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 2 */
4561 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 3 */
4563 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 4 */
4565 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 5 */
4567 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 6 */
4569 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 7 */
4571 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 8 */
4573 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 9 */
4575 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 10 */
4577 WRW_HARPOON(map_addr, (MPM_OP + ACOMMAND + 0x00)); /*CDB BYTE 11 */
4579 WRW_HARPOON(map_addr, (CPE_OP + ADATA_OUT + DINT)); /*JUMP IF DATA OUT */
4581 WRW_HARPOON(map_addr, (TCB_OP + FIFO_0 + DI)); /*JUMP IF NO DATA IN FIFO */
4582 map_addr += 2; /*This means AYNC DATA IN */
4583 WRW_HARPOON(map_addr, (SSI_OP + SSI_IDO_STRT)); /*STOP AND INTERRUPT */
4585 WRW_HARPOON(map_addr, (CPE_OP + ADATA_IN + DINT)); /*JUMP IF NOT DATA IN PHZ */
4587 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK 4 DATA IN */
4589 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x02)); /*SAVE DATA PTR MSG? */
4591 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + DC)); /*GO CHECK FOR DISCONNECT MSG */
4593 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR1)); /*SAVE DATA PTRS MSG */
4595 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + ST)); /*IF NOT MSG IN CHECK DATA IN */
4597 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x04)); /*DISCONNECT MSG? */
4599 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + UNKNWN)); /*UKNKNOWN MSG */
4601 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*XFER DISCONNECT MSG */
4603 WRW_HARPOON(map_addr, (SSI_OP + SSI_ITAR_DISC)); /*STOP AND INTERRUPT */
4605 WRW_HARPOON(map_addr, (CPN_OP + ASTATUS + UNKNWN)); /*JUMP IF NOT STATUS PHZ. */
4607 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_AR0)); /*GET STATUS BYTE */
4609 WRW_HARPOON(map_addr, (CPN_OP + AMSG_IN + CC)); /*ERROR IF NOT MSG IN PHZ */
4611 WRW_HARPOON(map_addr, (CRD_OP + SDATA + 0x00)); /*CHECK FOR CMD COMPLETE MSG. */
4613 WRW_HARPOON(map_addr, (BRH_OP + NOT_EQ + CC)); /*ERROR IF NOT CMD COMPLETE MSG. */
4615 WRW_HARPOON(map_addr, (MRR_OP + SDATA + D_BUCKET)); /*GET CMD COMPLETE MSG */
4617 WRW_HARPOON(map_addr, (SSI_OP + SSI_ICMD_COMP)); /*END OF COMMAND */
4620 WRW_HARPOON(map_addr, (SSI_OP + SSI_IUNKWN)); /*RECEIVED UNKNOWN MSG BYTE */
4622 WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
4624 WRW_HARPOON(map_addr, (SSI_OP + SSI_ITICKLE)); /*BIOS Tickled the Mgr */
4626 WRW_HARPOON(map_addr, (SSI_OP + SSI_IRFAIL)); /*EXPECTED ID/TAG MESSAGES AND */
4627 map_addr += 2; /* DIDN'T GET ONE */
4628 WRW_HARPOON(map_addr, (CRR_OP + AR3 + S_IDREG)); /* comp SCSI SEL ID & AR3 */
4630 WRW_HARPOON(map_addr, (BRH_OP + EQUAL + 0x00)); /*SEL ID OK then Conti. */
4632 WRW_HARPOON(map_addr, (SSI_OP + SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
4634 SGRAM_ACCESS(p_port);
4637 /*---------------------------------------------------------------------
4639 * Function: Auto Command Complete
4641 * Description: Post command back to host and find another command
4644 *---------------------------------------------------------------------*/
4646 static void FPT_autoCmdCmplt(u32 p_port, unsigned char p_card)
4648 struct sccb *currSCCB;
4649 unsigned char status_byte;
4651 currSCCB = FPT_BL_Card[p_card].currentSCCB;
4653 status_byte = RD_HARPOON(p_port + hp_gp_reg_0);
4655 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = 0;
4657 if (status_byte != SSGOOD) {
4659 if (status_byte == SSQ_FULL) {
4661 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4662 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4663 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4664 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4665 TarLUNBusy[currSCCB->Lun] = 1;
4666 if (FPT_BL_Card[p_card].discQCount != 0)
4667 FPT_BL_Card[p_card].discQCount--;
4668 FPT_BL_Card[p_card].
4669 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4671 LunDiscQ_Idx[currSCCB->Lun]] =
4674 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4676 if (currSCCB->Sccb_tag) {
4677 if (FPT_BL_Card[p_card].discQCount != 0)
4678 FPT_BL_Card[p_card].
4680 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4684 if (FPT_BL_Card[p_card].discQCount != 0)
4685 FPT_BL_Card[p_card].
4687 FPT_BL_Card[p_card].
4688 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4690 LunDiscQ_Idx[0]] = NULL;
4694 currSCCB->Sccb_MGRFlags |= F_STATUSLOADED;
4696 FPT_queueSelectFail(&FPT_BL_Card[p_card], p_card);
4701 if (currSCCB->Sccb_scsistat == SELECT_SN_ST) {
4702 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
4703 (unsigned char)SYNC_SUPPORTED;
4705 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4707 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4709 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4710 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4711 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4712 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4713 TarLUNBusy[currSCCB->Lun] = 1;
4714 if (FPT_BL_Card[p_card].discQCount != 0)
4715 FPT_BL_Card[p_card].discQCount--;
4716 FPT_BL_Card[p_card].
4717 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4719 LunDiscQ_Idx[currSCCB->Lun]] =
4722 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4724 if (currSCCB->Sccb_tag) {
4725 if (FPT_BL_Card[p_card].discQCount != 0)
4726 FPT_BL_Card[p_card].
4728 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4732 if (FPT_BL_Card[p_card].discQCount != 0)
4733 FPT_BL_Card[p_card].
4735 FPT_BL_Card[p_card].
4736 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4738 LunDiscQ_Idx[0]] = NULL;
4745 if (currSCCB->Sccb_scsistat == SELECT_WN_ST) {
4747 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
4748 (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4749 TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
4751 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &=
4753 FPT_BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
4755 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4756 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4757 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
4758 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4759 TarLUNBusy[currSCCB->Lun] = 1;
4760 if (FPT_BL_Card[p_card].discQCount != 0)
4761 FPT_BL_Card[p_card].discQCount--;
4762 FPT_BL_Card[p_card].
4763 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4765 LunDiscQ_Idx[currSCCB->Lun]] =
4768 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4770 if (currSCCB->Sccb_tag) {
4771 if (FPT_BL_Card[p_card].discQCount != 0)
4772 FPT_BL_Card[p_card].
4774 FPT_BL_Card[p_card].discQ_Tbl[currSCCB->
4778 if (FPT_BL_Card[p_card].discQCount != 0)
4779 FPT_BL_Card[p_card].
4781 FPT_BL_Card[p_card].
4782 discQ_Tbl[FPT_sccbMgrTbl[p_card]
4784 LunDiscQ_Idx[0]] = NULL;
4791 if (status_byte == SSCHECK) {
4792 if (FPT_BL_Card[p_card].globalFlags & F_DO_RENEGO) {
4793 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4794 TarEEValue & EE_SYNC_MASK) {
4795 FPT_sccbMgrTbl[p_card][currSCCB->
4797 TarStatus &= ~TAR_SYNC_MASK;
4799 if (FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4800 TarEEValue & EE_WIDE_SCSI) {
4801 FPT_sccbMgrTbl[p_card][currSCCB->
4803 TarStatus &= ~TAR_WIDE_MASK;
4808 if (!(currSCCB->Sccb_XferState & F_AUTO_SENSE)) {
4810 currSCCB->SccbStatus = SCCB_ERROR;
4811 currSCCB->TargetStatus = status_byte;
4813 if (status_byte == SSCHECK) {
4815 FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4818 if (currSCCB->RequestSenseLength !=
4819 NO_AUTO_REQUEST_SENSE) {
4821 if (currSCCB->RequestSenseLength == 0)
4822 currSCCB->RequestSenseLength =
4825 FPT_ssenss(&FPT_BL_Card[p_card]);
4826 FPT_BL_Card[p_card].globalFlags |=
4829 if (((FPT_BL_Card[p_card].
4830 globalFlags & F_CONLUN_IO)
4832 ((FPT_sccbMgrTbl[p_card]
4834 TarStatus & TAR_TAG_Q_MASK) !=
4836 FPT_sccbMgrTbl[p_card]
4838 TarLUNBusy[currSCCB->Lun] =
4840 if (FPT_BL_Card[p_card].
4842 FPT_BL_Card[p_card].
4844 FPT_BL_Card[p_card].
4845 discQ_Tbl[FPT_sccbMgrTbl
4853 FPT_sccbMgrTbl[p_card]
4856 if (currSCCB->Sccb_tag) {
4857 if (FPT_BL_Card[p_card].
4862 FPT_BL_Card[p_card].
4863 discQ_Tbl[currSCCB->
4867 if (FPT_BL_Card[p_card].
4872 FPT_BL_Card[p_card].
4887 if ((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
4888 ((FPT_sccbMgrTbl[p_card][currSCCB->TargID].
4889 TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
4890 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->
4893 FPT_sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = 0;
4895 FPT_queueCmdComplete(&FPT_BL_Card[p_card], currSCCB, p_card);
4898 #define SHORT_WAIT 0x0000000F
4899 #define LONG_WAIT 0x0000FFFFL
4901 /*---------------------------------------------------------------------
4903 * Function: Data Transfer Processor
4905 * Description: This routine performs two tasks.
4906 * (1) Start data transfer by calling HOST_DATA_XFER_START
4907 * function. Once data transfer is started, (2) Depends
4908 * on the type of data transfer mode Scatter/Gather mode
4909 * or NON Scatter/Gather mode. In NON Scatter/Gather mode,
4910 * this routine checks Sccb_MGRFlag (F_HOST_XFER_ACT bit) for
4911 * data transfer done. In Scatter/Gather mode, this routine
4912 * checks bus master command complete and dual rank busy
4913 * bit to keep chaining SC transfer command. Similarly,
4914 * in Scatter/Gather mode, it checks Sccb_MGRFlag
4915 * (F_HOST_XFER_ACT bit) for data transfer done.
4917 *---------------------------------------------------------------------*/
4919 static void FPT_dataXferProcessor(u32 port, struct sccb_card *pCurrCard)
4921 struct sccb *currSCCB;
4923 currSCCB = pCurrCard->currentSCCB;
4925 if (currSCCB->Sccb_XferState & F_SG_XFER) {
4926 if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
4928 currSCCB->Sccb_sgseg += (unsigned char)SG_BUF_CNT;
4929 currSCCB->Sccb_SGoffset = 0x00;
4931 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
4933 FPT_busMstrSGDataXferStart(port, currSCCB);
4937 if (!(pCurrCard->globalFlags & F_HOST_XFER_ACT)) {
4938 pCurrCard->globalFlags |= F_HOST_XFER_ACT;
4940 FPT_busMstrDataXferStart(port, currSCCB);
4945 /*---------------------------------------------------------------------
4947 * Function: BusMaster Scatter Gather Data Transfer Start
4951 *---------------------------------------------------------------------*/
4952 static void FPT_busMstrSGDataXferStart(u32 p_port, struct sccb *pcurrSCCB)
4954 u32 count, addr, tmpSGCnt;
4955 unsigned int sg_index;
4956 unsigned char sg_count, i;
4958 struct blogic_sg_seg *segp;
4960 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)
4961 count = ((u32)HOST_RD_CMD) << 24;
4963 count = ((u32)HOST_WRT_CMD) << 24;
4967 sg_index = pcurrSCCB->Sccb_sgseg;
4968 reg_offset = hp_aramBase;
4970 i = (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
4971 ~(SGRAM_ARAM | SCATTER_EN));
4973 WR_HARPOON(p_port + hp_page_ctrl, i);
4975 while ((sg_count < (unsigned char)SG_BUF_CNT) &&
4976 ((sg_index * (unsigned int)SG_ELEMENT_SIZE) <
4977 pcurrSCCB->DataLength)) {
4979 segp = (struct blogic_sg_seg *)(pcurrSCCB->DataPointer) +
4981 tmpSGCnt += segp->segbytes;
4982 count |= segp->segbytes;
4983 addr = segp->segdata;
4985 if ((!sg_count) && (pcurrSCCB->Sccb_SGoffset)) {
4987 ((count & 0x00FFFFFFL) - pcurrSCCB->Sccb_SGoffset);
4989 (count & 0xFF000000L) | pcurrSCCB->Sccb_SGoffset;
4990 tmpSGCnt = count & 0x00FFFFFFL;
4993 WR_HARP32(p_port, reg_offset, addr);
4996 WR_HARP32(p_port, reg_offset, count);
4999 count &= 0xFF000000L;
5005 pcurrSCCB->Sccb_XferCnt = tmpSGCnt;
5007 WR_HARPOON(p_port + hp_sg_addr, (sg_count << 4));
5009 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5011 WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
5013 WR_HARPOON(p_port + hp_portctrl_0,
5014 (DMA_PORT | SCSI_PORT | SCSI_INBIT));
5015 WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
5020 if ((!(RD_HARPOON(p_port + hp_synctarg_0) & NARROW_SCSI)) &&
5021 (tmpSGCnt & 0x000000001)) {
5023 pcurrSCCB->Sccb_XferState |= F_ODD_BALL_CNT;
5027 WR_HARP32(p_port, hp_xfercnt_0, tmpSGCnt);
5029 WR_HARPOON(p_port + hp_portctrl_0,
5030 (SCSI_PORT | DMA_PORT | DMA_RD));
5031 WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
5034 WR_HARPOON(p_port + hp_page_ctrl, (unsigned char)(i | SCATTER_EN));
5038 /*---------------------------------------------------------------------
5040 * Function: BusMaster Data Transfer Start
5044 *---------------------------------------------------------------------*/
5045 static void FPT_busMstrDataXferStart(u32 p_port, struct sccb *pcurrSCCB)
5049 if (!(pcurrSCCB->Sccb_XferState & F_AUTO_SENSE)) {
5051 count = pcurrSCCB->Sccb_XferCnt;
5053 addr = (u32)(unsigned long)pcurrSCCB->DataPointer + pcurrSCCB->Sccb_ATC;
5057 addr = pcurrSCCB->SensePointer;
5058 count = pcurrSCCB->RequestSenseLength;
5062 HP_SETUP_ADDR_CNT(p_port, addr, count);
5064 if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
5066 WR_HARPOON(p_port + hp_portctrl_0,
5067 (DMA_PORT | SCSI_PORT | SCSI_INBIT));
5068 WR_HARPOON(p_port + hp_scsisig, S_DATAI_PH);
5070 WR_HARPOON(p_port + hp_xfer_cmd,
5071 (XFER_DMA_HOST | XFER_HOST_AUTO | XFER_DMA_8BIT));
5076 WR_HARPOON(p_port + hp_portctrl_0,
5077 (SCSI_PORT | DMA_PORT | DMA_RD));
5078 WR_HARPOON(p_port + hp_scsisig, S_DATAO_PH);
5080 WR_HARPOON(p_port + hp_xfer_cmd,
5081 (XFER_HOST_DMA | XFER_HOST_AUTO | XFER_DMA_8BIT));
5086 /*---------------------------------------------------------------------
5088 * Function: BusMaster Timeout Handler
5090 * Description: This function is called after a bus master command busy time
5091 * out is detected. This routines issue halt state machine
5092 * with a software time out for command busy. If command busy
5093 * is still asserted at the end of the time out, it issues
5094 * hard abort with another software time out. It hard abort
5095 * command busy is also time out, it'll just give up.
5097 *---------------------------------------------------------------------*/
5098 static unsigned char FPT_busMstrTimeOut(u32 p_port)
5100 unsigned long timeout;
5102 timeout = LONG_WAIT;
5104 WR_HARPOON(p_port + hp_sys_ctrl, HALT_MACH);
5106 while ((!(RD_HARPOON(p_port + hp_ext_status) & CMD_ABORTED))
5110 if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
5111 WR_HARPOON(p_port + hp_sys_ctrl, HARD_ABORT);
5113 timeout = LONG_WAIT;
5114 while ((RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY)
5119 RD_HARPOON(p_port + hp_int_status); /*Clear command complete */
5121 if (RD_HARPOON(p_port + hp_ext_status) & BM_CMD_BUSY) {
5130 /*---------------------------------------------------------------------
5132 * Function: Host Data Transfer Abort
5134 * Description: Abort any in progress transfer.
5136 *---------------------------------------------------------------------*/
5137 static void FPT_hostDataXferAbort(u32 port, unsigned char p_card,
5138 struct sccb *pCurrSCCB)
5141 unsigned long timeout;
5142 unsigned long remain_cnt;
5144 struct blogic_sg_seg *segp;
5146 FPT_BL_Card[p_card].globalFlags &= ~F_HOST_XFER_ACT;
5148 if (pCurrSCCB->Sccb_XferState & F_AUTO_SENSE) {
5150 if (!(RD_HARPOON(port + hp_int_status) & INT_CMD_COMPL)) {
5152 WR_HARPOON(port + hp_bm_ctrl,
5153 (RD_HARPOON(port + hp_bm_ctrl) |
5155 timeout = LONG_WAIT;
5157 while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
5161 WR_HARPOON(port + hp_bm_ctrl,
5162 (RD_HARPOON(port + hp_bm_ctrl) &
5165 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5167 if (FPT_busMstrTimeOut(port)) {
5169 if (pCurrSCCB->HostStatus == 0x00)
5171 pCurrSCCB->HostStatus =
5176 if (RD_HARPOON(port + hp_int_status) &
5179 if (RD_HARPOON(port + hp_ext_status) &
5182 if (pCurrSCCB->HostStatus ==
5185 pCurrSCCB->HostStatus =
5192 else if (pCurrSCCB->Sccb_XferCnt) {
5194 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5196 WR_HARPOON(port + hp_page_ctrl,
5197 (RD_HARPOON(port + hp_page_ctrl) &
5200 WR_HARPOON(port + hp_sg_addr, 0x00);
5202 sg_ptr = pCurrSCCB->Sccb_sgseg + SG_BUF_CNT;
5205 (unsigned int)(pCurrSCCB->DataLength /
5208 sg_ptr = (u32)(pCurrSCCB->DataLength /
5212 remain_cnt = pCurrSCCB->Sccb_XferCnt;
5214 while (remain_cnt < 0x01000000L) {
5217 segp = (struct blogic_sg_seg *)(pCurrSCCB->
5218 DataPointer) + (sg_ptr * 2);
5219 if (remain_cnt > (unsigned long)segp->segbytes)
5221 (unsigned long)segp->segbytes;
5226 if (remain_cnt < 0x01000000L) {
5228 pCurrSCCB->Sccb_SGoffset = remain_cnt;
5230 pCurrSCCB->Sccb_sgseg = (unsigned short)sg_ptr;
5232 if ((unsigned long)(sg_ptr * SG_ELEMENT_SIZE) ==
5233 pCurrSCCB->DataLength && (remain_cnt == 0))
5235 pCurrSCCB->Sccb_XferState |=
5241 if (pCurrSCCB->HostStatus == 0x00) {
5243 pCurrSCCB->HostStatus =
5249 if (!(pCurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)) {
5251 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5253 FPT_busMstrTimeOut(port);
5258 if (RD_HARPOON(port + hp_int_status) &
5261 if (RD_HARPOON(port + hp_ext_status) &
5264 if (pCurrSCCB->HostStatus ==
5267 pCurrSCCB->HostStatus =
5278 if ((RD_HARPOON(port + hp_fifo_cnt)) >= BM_THRESHOLD) {
5280 timeout = SHORT_WAIT;
5282 while ((RD_HARPOON(port + hp_ext_status) &
5284 && ((RD_HARPOON(port + hp_fifo_cnt)) >=
5285 BM_THRESHOLD) && timeout--) {
5289 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5291 WR_HARPOON(port + hp_bm_ctrl,
5292 (RD_HARPOON(port + hp_bm_ctrl) |
5295 timeout = LONG_WAIT;
5297 while ((RD_HARPOON(port + hp_ext_status) &
5298 BM_CMD_BUSY) && timeout--) {
5301 WR_HARPOON(port + hp_bm_ctrl,
5302 (RD_HARPOON(port + hp_bm_ctrl) &
5305 if (RD_HARPOON(port + hp_ext_status) &
5308 if (pCurrSCCB->HostStatus == 0x00) {
5310 pCurrSCCB->HostStatus =
5314 FPT_busMstrTimeOut(port);
5318 if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
5320 if (RD_HARPOON(port + hp_ext_status) &
5323 if (pCurrSCCB->HostStatus == 0x00) {
5325 pCurrSCCB->HostStatus =
5336 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5338 timeout = LONG_WAIT;
5340 while ((RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY)
5344 if (RD_HARPOON(port + hp_ext_status) & BM_CMD_BUSY) {
5346 if (pCurrSCCB->HostStatus == 0x00) {
5348 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5351 FPT_busMstrTimeOut(port);
5355 if (RD_HARPOON(port + hp_int_status) & INT_EXT_STATUS) {
5357 if (RD_HARPOON(port + hp_ext_status) & BAD_EXT_STATUS) {
5359 if (pCurrSCCB->HostStatus == 0x00) {
5361 pCurrSCCB->HostStatus = SCCB_BM_ERR;
5367 if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
5369 WR_HARPOON(port + hp_page_ctrl,
5370 (RD_HARPOON(port + hp_page_ctrl) &
5373 WR_HARPOON(port + hp_sg_addr, 0x00);
5375 pCurrSCCB->Sccb_sgseg += SG_BUF_CNT;
5377 pCurrSCCB->Sccb_SGoffset = 0x00;
5379 if ((u32)(pCurrSCCB->Sccb_sgseg * SG_ELEMENT_SIZE) >=
5380 pCurrSCCB->DataLength) {
5382 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5383 pCurrSCCB->Sccb_sgseg =
5384 (unsigned short)(pCurrSCCB->DataLength /
5390 if (!(pCurrSCCB->Sccb_XferState & F_AUTO_SENSE))
5391 pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
5395 WR_HARPOON(port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
5398 /*---------------------------------------------------------------------
5400 * Function: Host Data Transfer Restart
5402 * Description: Reset the available count due to a restore data
5405 *---------------------------------------------------------------------*/
5406 static void FPT_hostDataXferRestart(struct sccb *currSCCB)
5408 unsigned long data_count;
5409 unsigned int sg_index;
5410 struct blogic_sg_seg *segp;
5412 if (currSCCB->Sccb_XferState & F_SG_XFER) {
5414 currSCCB->Sccb_XferCnt = 0;
5416 sg_index = 0xffff; /*Index by long words into sg list. */
5417 data_count = 0; /*Running count of SG xfer counts. */
5420 while (data_count < currSCCB->Sccb_ATC) {
5423 segp = (struct blogic_sg_seg *)(currSCCB->DataPointer) +
5425 data_count += segp->segbytes;
5428 if (data_count == currSCCB->Sccb_ATC) {
5430 currSCCB->Sccb_SGoffset = 0;
5435 currSCCB->Sccb_SGoffset =
5436 data_count - currSCCB->Sccb_ATC;
5439 currSCCB->Sccb_sgseg = (unsigned short)sg_index;
5443 currSCCB->Sccb_XferCnt =
5444 currSCCB->DataLength - currSCCB->Sccb_ATC;
5448 /*---------------------------------------------------------------------
5450 * Function: FPT_scini
5452 * Description: Setup all data structures necessary for SCAM selection.
5454 *---------------------------------------------------------------------*/
5456 static void FPT_scini(unsigned char p_card, unsigned char p_our_id,
5457 unsigned char p_power_up)
5460 unsigned char loser, assigned_id;
5463 unsigned char i, k, ScamFlg;
5464 struct sccb_card *currCard;
5465 struct nvram_info *pCurrNvRam;
5467 currCard = &FPT_BL_Card[p_card];
5468 p_port = currCard->ioPort;
5469 pCurrNvRam = currCard->pNvRamInfo;
5472 ScamFlg = pCurrNvRam->niScamConf;
5473 i = pCurrNvRam->niSysConf;
5476 (unsigned char)FPT_utilEERead(p_port, SCAM_CONFIG / 2);
5478 char)(FPT_utilEERead(p_port, (SYSTEM_CONFIG / 2)));
5480 if (!(i & 0x02)) /* check if reset bus in AutoSCSI parameter set */
5483 FPT_inisci(p_card, p_port, p_our_id);
5485 /* Force to wait 1 sec after SCSI bus reset. Some SCAM device FW
5486 too slow to return to SCAM selection */
5489 FPT_Wait1Second(p_port);
5491 FPT_Wait(p_port, TO_250ms); */
5493 FPT_Wait1Second(p_port);
5495 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2)) {
5496 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5502 FPT_scxferc(p_port, SYNC_PTRN);
5503 FPT_scxferc(p_port, DOM_MSTR);
5506 &FPT_scamInfo[p_our_id].id_string[0]);
5507 } while (loser == 0xFF);
5511 if ((p_power_up) && (!loser)) {
5512 FPT_sresb(p_port, p_card);
5513 FPT_Wait(p_port, TO_250ms);
5515 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5521 FPT_scxferc(p_port, SYNC_PTRN);
5522 FPT_scxferc(p_port, DOM_MSTR);
5525 &FPT_scamInfo[p_our_id].
5527 } while (loser == 0xFF);
5539 FPT_scamInfo[p_our_id].state = ID_ASSIGNED;
5541 if (ScamFlg & SCAM_ENABLED) {
5543 for (i = 0; i < MAX_SCSI_TAR; i++) {
5544 if ((FPT_scamInfo[i].state == ID_UNASSIGNED) ||
5545 (FPT_scamInfo[i].state == ID_UNUSED)) {
5546 if (FPT_scsell(p_port, i)) {
5547 FPT_scamInfo[i].state = LEGACY;
5548 if ((FPT_scamInfo[i].
5549 id_string[0] != 0xFF)
5550 || (FPT_scamInfo[i].
5551 id_string[1] != 0xFA)) {
5554 id_string[0] = 0xFF;
5556 id_string[1] = 0xFA;
5557 if (pCurrNvRam == NULL)
5567 FPT_sresb(p_port, p_card);
5568 FPT_Wait1Second(p_port);
5569 while (!(FPT_scarb(p_port, INIT_SELTD))) {
5572 FPT_scasid(p_card, p_port);
5577 else if ((loser) && (ScamFlg & SCAM_ENABLED)) {
5578 FPT_scamInfo[p_our_id].id_string[0] = SLV_TYPE_CODE0;
5580 FPT_scwtsel(p_port);
5583 while (FPT_scxferc(p_port, 0x00) != SYNC_PTRN) {
5586 i = FPT_scxferc(p_port, 0x00);
5587 if (i == ASSIGN_ID) {
5591 &FPT_scamInfo[p_our_id].id_string[0]))) {
5592 i = FPT_scxferc(p_port, 0x00);
5593 if (FPT_scvalq(i)) {
5594 k = FPT_scxferc(p_port, 0x00);
5596 if (FPT_scvalq(k)) {
5609 FPT_scamInfo[currCard->
5611 state = ID_ASSIGNED;
5612 FPT_scamInfo[currCard->
5622 else if (i == SET_P_FLAG) {
5623 if (!(FPT_scsendi(p_port,
5624 &FPT_scamInfo[p_our_id].
5626 FPT_scamInfo[p_our_id].id_string[0] |=
5629 } while (!assigned_id);
5631 while (FPT_scxferc(p_port, 0x00) != CFG_CMPLT) {
5635 if (ScamFlg & SCAM_ENABLED) {
5637 if (currCard->globalFlags & F_UPDATE_EEPROM) {
5638 FPT_scsavdi(p_card, p_port);
5639 currCard->globalFlags &= ~F_UPDATE_EEPROM;
5644 for (i=0,k=0; i < MAX_SCSI_TAR; i++)
5646 if ((FPT_scamInfo[i].state == ID_ASSIGNED) ||
5647 (FPT_scamInfo[i].state == LEGACY))
5652 currCard->globalFlags |= F_SINGLE_DEVICE;
5654 currCard->globalFlags &= ~F_SINGLE_DEVICE;
5658 /*---------------------------------------------------------------------
5660 * Function: FPT_scarb
5662 * Description: Gain control of the bus and wait SCAM select time (250ms)
5664 *---------------------------------------------------------------------*/
5666 static int FPT_scarb(u32 p_port, unsigned char p_sel_type)
5668 if (p_sel_type == INIT_SELTD) {
5670 while (RD_HARPOON(p_port + hp_scsisig) & (SCSI_SEL | SCSI_BSY)) {
5673 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL)
5676 if (RD_HARPOON(p_port + hp_scsidata_0) != 00)
5679 WR_HARPOON(p_port + hp_scsisig,
5680 (RD_HARPOON(p_port + hp_scsisig) | SCSI_BSY));
5682 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_SEL) {
5684 WR_HARPOON(p_port + hp_scsisig,
5685 (RD_HARPOON(p_port + hp_scsisig) &
5690 WR_HARPOON(p_port + hp_scsisig,
5691 (RD_HARPOON(p_port + hp_scsisig) | SCSI_SEL));
5693 if (RD_HARPOON(p_port + hp_scsidata_0) != 00) {
5695 WR_HARPOON(p_port + hp_scsisig,
5696 (RD_HARPOON(p_port + hp_scsisig) &
5697 ~(SCSI_BSY | SCSI_SEL)));
5702 WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
5704 WR_HARPOON(p_port + hp_scsireset, SCAM_EN);
5705 WR_HARPOON(p_port + hp_scsidata_0, 0x00);
5706 WR_HARPOON(p_port + hp_scsidata_1, 0x00);
5707 WR_HARPOON(p_port + hp_portctrl_0, SCSI_BUS_EN);
5709 WR_HARPOON(p_port + hp_scsisig,
5710 (RD_HARPOON(p_port + hp_scsisig) | SCSI_MSG));
5712 WR_HARPOON(p_port + hp_scsisig, (RD_HARPOON(p_port + hp_scsisig)
5715 FPT_Wait(p_port, TO_250ms);
5720 /*---------------------------------------------------------------------
5722 * Function: FPT_scbusf
5724 * Description: Release the SCSI bus and disable SCAM selection.
5726 *---------------------------------------------------------------------*/
5728 static void FPT_scbusf(u32 p_port)
5730 WR_HARPOON(p_port + hp_page_ctrl,
5731 (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
5733 WR_HARPOON(p_port + hp_scsidata_0, 0x00);
5735 WR_HARPOON(p_port + hp_portctrl_0, (RD_HARPOON(p_port + hp_portctrl_0)
5738 WR_HARPOON(p_port + hp_scsisig, 0x00);
5740 WR_HARPOON(p_port + hp_scsireset, (RD_HARPOON(p_port + hp_scsireset)
5743 WR_HARPOON(p_port + hp_clkctrl_0, (RD_HARPOON(p_port + hp_clkctrl_0)
5746 WRW_HARPOON((p_port + hp_intstat), (BUS_FREE | AUTO_INT | SCAM_SEL));
5748 WR_HARPOON(p_port + hp_page_ctrl,
5749 (RD_HARPOON(p_port + hp_page_ctrl) & ~G_INT_DISABLE));
5752 /*---------------------------------------------------------------------
5754 * Function: FPT_scasid
5756 * Description: Assign an ID to all the SCAM devices.
5758 *---------------------------------------------------------------------*/
5760 static void FPT_scasid(unsigned char p_card, u32 p_port)
5762 unsigned char temp_id_string[ID_STRING_LENGTH];
5764 unsigned char i, k, scam_id;
5765 unsigned char crcBytes[3];
5766 struct nvram_info *pCurrNvRam;
5767 unsigned short *pCrcBytes;
5769 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
5775 for (k = 0; k < ID_STRING_LENGTH; k++) {
5776 temp_id_string[k] = (unsigned char)0x00;
5779 FPT_scxferc(p_port, SYNC_PTRN);
5780 FPT_scxferc(p_port, ASSIGN_ID);
5782 if (!(FPT_sciso(p_port, &temp_id_string[0]))) {
5784 pCrcBytes = (unsigned short *)&crcBytes[0];
5785 *pCrcBytes = FPT_CalcCrc16(&temp_id_string[0]);
5786 crcBytes[2] = FPT_CalcLrc(&temp_id_string[0]);
5787 temp_id_string[1] = crcBytes[2];
5788 temp_id_string[2] = crcBytes[0];
5789 temp_id_string[3] = crcBytes[1];
5790 for (k = 4; k < ID_STRING_LENGTH; k++)
5791 temp_id_string[k] = (unsigned char)0x00;
5793 i = FPT_scmachid(p_card, temp_id_string);
5795 if (i == CLR_PRIORITY) {
5796 FPT_scxferc(p_port, MISC_CODE);
5797 FPT_scxferc(p_port, CLR_P_FLAG);
5798 i = 0; /*Not the last ID yet. */
5801 else if (i != NO_ID_AVAIL) {
5803 FPT_scxferc(p_port, ID_0_7);
5805 FPT_scxferc(p_port, ID_8_F);
5807 scam_id = (i & (unsigned char)0x07);
5809 for (k = 1; k < 0x08; k <<= 1)
5811 scam_id += 0x08; /*Count number of zeros in DB0-3. */
5813 FPT_scxferc(p_port, scam_id);
5815 i = 0; /*Not the last ID yet. */
5825 FPT_scxferc(p_port, SYNC_PTRN);
5826 FPT_scxferc(p_port, CFG_CMPLT);
5829 /*---------------------------------------------------------------------
5831 * Function: FPT_scsel
5833 * Description: Select all the SCAM devices.
5835 *---------------------------------------------------------------------*/
5837 static void FPT_scsel(u32 p_port)
5840 WR_HARPOON(p_port + hp_scsisig, SCSI_SEL);
5841 FPT_scwiros(p_port, SCSI_MSG);
5843 WR_HARPOON(p_port + hp_scsisig, (SCSI_SEL | SCSI_BSY));
5845 WR_HARPOON(p_port + hp_scsisig,
5846 (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5847 WR_HARPOON(p_port + hp_scsidata_0,
5848 (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) |
5849 (unsigned char)(BIT(7) + BIT(6))));
5851 WR_HARPOON(p_port + hp_scsisig, (SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5852 FPT_scwiros(p_port, SCSI_SEL);
5854 WR_HARPOON(p_port + hp_scsidata_0,
5855 (unsigned char)(RD_HARPOON(p_port + hp_scsidata_0) &
5856 ~(unsigned char)BIT(6)));
5857 FPT_scwirod(p_port, BIT(6));
5859 WR_HARPOON(p_port + hp_scsisig,
5860 (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
5863 /*---------------------------------------------------------------------
5865 * Function: FPT_scxferc
5867 * Description: Handshake the p_data (DB4-0) across the bus.
5869 *---------------------------------------------------------------------*/
5871 static unsigned char FPT_scxferc(u32 p_port, unsigned char p_data)
5873 unsigned char curr_data, ret_data;
5875 curr_data = p_data | BIT(7) | BIT(5); /*Start with DB7 & DB5 asserted. */
5877 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5879 curr_data &= ~BIT(7);
5881 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5883 FPT_scwirod(p_port, BIT(7)); /*Wait for DB7 to be released. */
5884 while (!(RD_HARPOON(p_port + hp_scsidata_0) & BIT(5))) ;
5886 ret_data = (RD_HARPOON(p_port + hp_scsidata_0) & (unsigned char)0x1F);
5888 curr_data |= BIT(6);
5890 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5892 curr_data &= ~BIT(5);
5894 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5896 FPT_scwirod(p_port, BIT(5)); /*Wait for DB5 to be released. */
5898 curr_data &= ~(BIT(4) | BIT(3) | BIT(2) | BIT(1) | BIT(0)); /*Release data bits */
5899 curr_data |= BIT(7);
5901 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5903 curr_data &= ~BIT(6);
5905 WR_HARPOON(p_port + hp_scsidata_0, curr_data);
5907 FPT_scwirod(p_port, BIT(6)); /*Wait for DB6 to be released. */
5912 /*---------------------------------------------------------------------
5914 * Function: FPT_scsendi
5916 * Description: Transfer our Identification string to determine if we
5917 * will be the dominant master.
5919 *---------------------------------------------------------------------*/
5921 static unsigned char FPT_scsendi(u32 p_port, unsigned char p_id_string[])
5923 unsigned char ret_data, byte_cnt, bit_cnt, defer;
5927 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
5929 for (bit_cnt = 0x80; bit_cnt != 0; bit_cnt >>= 1) {
5932 ret_data = FPT_scxferc(p_port, 00);
5934 else if (p_id_string[byte_cnt] & bit_cnt)
5936 ret_data = FPT_scxferc(p_port, 02);
5940 ret_data = FPT_scxferc(p_port, 01);
5945 if ((ret_data & 0x1C) == 0x10)
5946 return 0x00; /*End of isolation stage, we won! */
5948 if (ret_data & 0x1C)
5951 if ((defer) && (!(ret_data & 0x1F)))
5952 return 0x01; /*End of isolation stage, we lost. */
5959 return 0x01; /*We lost */
5961 return 0; /*We WON! Yeeessss! */
5964 /*---------------------------------------------------------------------
5966 * Function: FPT_sciso
5968 * Description: Transfer the Identification string.
5970 *---------------------------------------------------------------------*/
5972 static unsigned char FPT_sciso(u32 p_port, unsigned char p_id_string[])
5974 unsigned char ret_data, the_data, byte_cnt, bit_cnt;
5978 for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
5980 for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
5982 ret_data = FPT_scxferc(p_port, 0);
5984 if (ret_data & 0xFC)
5990 if (ret_data & BIT(1)) {
5995 if ((ret_data & 0x1F) == 0) {
5997 if(bit_cnt != 0 || bit_cnt != 8)
6001 FPT_scxferc(p_port, SYNC_PTRN);
6002 FPT_scxferc(p_port, ASSIGN_ID);
6014 p_id_string[byte_cnt] = the_data;
6021 /*---------------------------------------------------------------------
6023 * Function: FPT_scwirod
6025 * Description: Sample the SCSI data bus making sure the signal has been
6026 * deasserted for the correct number of consecutive samples.
6028 *---------------------------------------------------------------------*/
6030 static void FPT_scwirod(u32 p_port, unsigned char p_data_bit)
6035 while (i < MAX_SCSI_TAR) {
6037 if (RD_HARPOON(p_port + hp_scsidata_0) & p_data_bit)
6048 /*---------------------------------------------------------------------
6050 * Function: FPT_scwiros
6052 * Description: Sample the SCSI Signal lines making sure the signal has been
6053 * deasserted for the correct number of consecutive samples.
6055 *---------------------------------------------------------------------*/
6057 static void FPT_scwiros(u32 p_port, unsigned char p_data_bit)
6062 while (i < MAX_SCSI_TAR) {
6064 if (RD_HARPOON(p_port + hp_scsisig) & p_data_bit)
6075 /*---------------------------------------------------------------------
6077 * Function: FPT_scvalq
6079 * Description: Make sure we received a valid data byte.
6081 *---------------------------------------------------------------------*/
6083 static unsigned char FPT_scvalq(unsigned char p_quintet)
6085 unsigned char count;
6087 for (count = 1; count < 0x08; count <<= 1) {
6088 if (!(p_quintet & count))
6092 if (p_quintet & 0x18)
6099 /*---------------------------------------------------------------------
6101 * Function: FPT_scsell
6103 * Description: Select the specified device ID using a selection timeout
6104 * less than 4ms. If somebody responds then it is a legacy
6105 * drive and this ID must be marked as such.
6107 *---------------------------------------------------------------------*/
6109 static unsigned char FPT_scsell(u32 p_port, unsigned char targ_id)
6113 WR_HARPOON(p_port + hp_page_ctrl,
6114 (RD_HARPOON(p_port + hp_page_ctrl) | G_INT_DISABLE));
6116 ARAM_ACCESS(p_port);
6118 WR_HARPOON(p_port + hp_addstat,
6119 (RD_HARPOON(p_port + hp_addstat) | SCAM_TIMER));
6120 WR_HARPOON(p_port + hp_seltimeout, TO_4ms);
6122 for (i = p_port + CMD_STRT; i < p_port + CMD_STRT + 12; i += 2) {
6123 WRW_HARPOON(i, (MPM_OP + ACOMMAND));
6125 WRW_HARPOON(i, (BRH_OP + ALWAYS + NP));
6127 WRW_HARPOON((p_port + hp_intstat),
6128 (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
6130 WR_HARPOON(p_port + hp_select_id, targ_id);
6132 WR_HARPOON(p_port + hp_portctrl_0, SCSI_PORT);
6133 WR_HARPOON(p_port + hp_autostart_3, (SELECT | CMD_ONLY_STRT));
6134 WR_HARPOON(p_port + hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
6136 while (!(RDW_HARPOON((p_port + hp_intstat)) &
6137 (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {
6140 if (RDW_HARPOON((p_port + hp_intstat)) & RESET)
6141 FPT_Wait(p_port, TO_250ms);
6143 DISABLE_AUTO(p_port);
6145 WR_HARPOON(p_port + hp_addstat,
6146 (RD_HARPOON(p_port + hp_addstat) & ~SCAM_TIMER));
6147 WR_HARPOON(p_port + hp_seltimeout, TO_290ms);
6149 SGRAM_ACCESS(p_port);
6151 if (RDW_HARPOON((p_port + hp_intstat)) & (RESET | TIMEOUT)) {
6153 WRW_HARPOON((p_port + hp_intstat),
6154 (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
6156 WR_HARPOON(p_port + hp_page_ctrl,
6157 (RD_HARPOON(p_port + hp_page_ctrl) &
6160 return 0; /*No legacy device */
6165 while (!(RDW_HARPOON((p_port + hp_intstat)) & BUS_FREE)) {
6166 if (RD_HARPOON(p_port + hp_scsisig) & SCSI_REQ) {
6167 WR_HARPOON(p_port + hp_scsisig,
6168 (SCSI_ACK + S_ILL_PH));
6173 WRW_HARPOON((p_port + hp_intstat), CLR_ALL_INT_1);
6175 WR_HARPOON(p_port + hp_page_ctrl,
6176 (RD_HARPOON(p_port + hp_page_ctrl) &
6179 return 1; /*Found one of them oldies! */
6183 /*---------------------------------------------------------------------
6185 * Function: FPT_scwtsel
6187 * Description: Wait to be selected by another SCAM initiator.
6189 *---------------------------------------------------------------------*/
6191 static void FPT_scwtsel(u32 p_port)
6193 while (!(RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL)) {
6197 /*---------------------------------------------------------------------
6199 * Function: FPT_inisci
6201 * Description: Setup the data Structure with the info from the EEPROM.
6203 *---------------------------------------------------------------------*/
6205 static void FPT_inisci(unsigned char p_card, u32 p_port, unsigned char p_our_id)
6207 unsigned char i, k, max_id;
6208 unsigned short ee_data;
6209 struct nvram_info *pCurrNvRam;
6211 pCurrNvRam = FPT_BL_Card[p_card].pNvRamInfo;
6213 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6220 for (i = 0; i < max_id; i++) {
6222 for (k = 0; k < 4; k++)
6223 FPT_scamInfo[i].id_string[k] =
6224 pCurrNvRam->niScamTbl[i][k];
6225 for (k = 4; k < ID_STRING_LENGTH; k++)
6226 FPT_scamInfo[i].id_string[k] =
6227 (unsigned char)0x00;
6229 if (FPT_scamInfo[i].id_string[0] == 0x00)
6230 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6232 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6236 for (i = 0; i < max_id; i++) {
6237 for (k = 0; k < ID_STRING_LENGTH; k += 2) {
6239 FPT_utilEERead(p_port,
6241 short)((EE_SCAMBASE / 2) +
6242 (unsigned short)(i *
6243 ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
6244 FPT_scamInfo[i].id_string[k] =
6245 (unsigned char)ee_data;
6247 FPT_scamInfo[i].id_string[k + 1] =
6248 (unsigned char)ee_data;
6251 if ((FPT_scamInfo[i].id_string[0] == 0x00) ||
6252 (FPT_scamInfo[i].id_string[0] == 0xFF))
6254 FPT_scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
6257 FPT_scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
6261 for (k = 0; k < ID_STRING_LENGTH; k++)
6262 FPT_scamInfo[p_our_id].id_string[k] = FPT_scamHAString[k];
6266 /*---------------------------------------------------------------------
6268 * Function: FPT_scmachid
6270 * Description: Match the Device ID string with our values stored in
6273 *---------------------------------------------------------------------*/
6275 static unsigned char FPT_scmachid(unsigned char p_card,
6276 unsigned char p_id_string[])
6279 unsigned char i, k, match;
6281 for (i = 0; i < MAX_SCSI_TAR; i++) {
6285 for (k = 0; k < ID_STRING_LENGTH; k++) {
6286 if (p_id_string[k] != FPT_scamInfo[i].id_string[k])
6291 FPT_scamInfo[i].state = ID_ASSIGNED;
6297 if (p_id_string[0] & BIT(5))
6302 if (((p_id_string[0] & 0x06) == 0x02)
6303 || ((p_id_string[0] & 0x06) == 0x04))
6304 match = p_id_string[1] & (unsigned char)0x1F;
6311 if (FPT_scamInfo[match].state == ID_UNUSED) {
6312 for (k = 0; k < ID_STRING_LENGTH; k++) {
6313 FPT_scamInfo[match].id_string[k] =
6317 FPT_scamInfo[match].state = ID_ASSIGNED;
6319 if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
6320 FPT_BL_Card[p_card].globalFlags |=
6328 if (match == 0xFF) {
6329 if (p_id_string[0] & BIT(5))
6332 match = MAX_SCSI_TAR - 1;
6336 if (p_id_string[0] & BIT(7)) {
6337 return CLR_PRIORITY;
6340 if (p_id_string[0] & BIT(5))
6345 if (((p_id_string[0] & 0x06) == 0x02)
6346 || ((p_id_string[0] & 0x06) == 0x04))
6347 match = p_id_string[1] & (unsigned char)0x1F;
6355 if (FPT_scamInfo[match].state == ID_UNASSIGNED) {
6356 for (k = 0; k < ID_STRING_LENGTH; k++) {
6357 FPT_scamInfo[match].id_string[k] =
6361 FPT_scamInfo[match].id_string[0] |= BIT(7);
6362 FPT_scamInfo[match].state = ID_ASSIGNED;
6363 if (FPT_BL_Card[p_card].pNvRamInfo == NULL)
6364 FPT_BL_Card[p_card].globalFlags |=
6372 if (match == 0xFF) {
6373 if (p_id_string[0] & BIT(5))
6376 match = MAX_SCSI_TAR - 1;
6383 /*---------------------------------------------------------------------
6385 * Function: FPT_scsavdi
6387 * Description: Save off the device SCAM ID strings.
6389 *---------------------------------------------------------------------*/
6391 static void FPT_scsavdi(unsigned char p_card, u32 p_port)
6393 unsigned char i, k, max_id;
6394 unsigned short ee_data, sum_data;
6398 for (i = 1; i < EE_SCAMBASE / 2; i++) {
6399 sum_data += FPT_utilEERead(p_port, i);
6402 FPT_utilEEWriteOnOff(p_port, 1); /* Enable write access to the EEPROM */
6404 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6410 for (i = 0; i < max_id; i++) {
6412 for (k = 0; k < ID_STRING_LENGTH; k += 2) {
6413 ee_data = FPT_scamInfo[i].id_string[k + 1];
6415 ee_data |= FPT_scamInfo[i].id_string[k];
6416 sum_data += ee_data;
6417 FPT_utilEEWrite(p_port, ee_data,
6418 (unsigned short)((EE_SCAMBASE / 2) +
6419 (unsigned short)(i *
6420 ((unsigned short)ID_STRING_LENGTH / 2)) + (unsigned short)(k / 2)));
6424 FPT_utilEEWrite(p_port, sum_data, EEPROM_CHECK_SUM / 2);
6425 FPT_utilEEWriteOnOff(p_port, 0); /* Turn off write access */
6428 /*---------------------------------------------------------------------
6430 * Function: FPT_XbowInit
6432 * Description: Setup the Xbow for normal operation.
6434 *---------------------------------------------------------------------*/
6436 static void FPT_XbowInit(u32 port, unsigned char ScamFlg)
6440 i = RD_HARPOON(port + hp_page_ctrl);
6441 WR_HARPOON(port + hp_page_ctrl, (unsigned char)(i | G_INT_DISABLE));
6443 WR_HARPOON(port + hp_scsireset, 0x00);
6444 WR_HARPOON(port + hp_portctrl_1, HOST_MODE8);
6446 WR_HARPOON(port + hp_scsireset, (DMA_RESET | HPSCSI_RESET | PROG_RESET |
6449 WR_HARPOON(port + hp_scsireset, SCSI_INI);
6451 WR_HARPOON(port + hp_clkctrl_0, CLKCTRL_DEFAULT);
6453 WR_HARPOON(port + hp_scsisig, 0x00); /* Clear any signals we might */
6454 WR_HARPOON(port + hp_scsictrl_0, ENA_SCAM_SEL);
6456 WRW_HARPOON((port + hp_intstat), CLR_ALL_INT);
6458 FPT_default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
6459 BUS_FREE | XFER_CNT_0 | AUTO_INT;
6461 if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
6462 FPT_default_intena |= SCAM_SEL;
6464 WRW_HARPOON((port + hp_intena), FPT_default_intena);
6466 WR_HARPOON(port + hp_seltimeout, TO_290ms);
6468 /* Turn on SCSI_MODE8 for narrow cards to fix the
6469 strapping issue with the DUAL CHANNEL card */
6470 if (RD_HARPOON(port + hp_page_ctrl) & NARROW_SCSI_CARD)
6471 WR_HARPOON(port + hp_addstat, SCSI_MODE8);
6473 WR_HARPOON(port + hp_page_ctrl, i);
6477 /*---------------------------------------------------------------------
6479 * Function: FPT_BusMasterInit
6481 * Description: Initialize the BusMaster for normal operations.
6483 *---------------------------------------------------------------------*/
6485 static void FPT_BusMasterInit(u32 p_port)
6488 WR_HARPOON(p_port + hp_sys_ctrl, DRVR_RST);
6489 WR_HARPOON(p_port + hp_sys_ctrl, 0x00);
6491 WR_HARPOON(p_port + hp_host_blk_cnt, XFER_BLK64);
6493 WR_HARPOON(p_port + hp_bm_ctrl, (BMCTRL_DEFAULT));
6495 WR_HARPOON(p_port + hp_ee_ctrl, (SCSI_TERM_ENA_H));
6497 RD_HARPOON(p_port + hp_int_status); /*Clear interrupts. */
6498 WR_HARPOON(p_port + hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
6499 WR_HARPOON(p_port + hp_page_ctrl, (RD_HARPOON(p_port + hp_page_ctrl) &
6503 /*---------------------------------------------------------------------
6505 * Function: FPT_DiagEEPROM
6507 * Description: Verfiy checksum and 'Key' and initialize the EEPROM if
6510 *---------------------------------------------------------------------*/
6512 static void FPT_DiagEEPROM(u32 p_port)
6514 unsigned short index, temp, max_wd_cnt;
6516 if (RD_HARPOON(p_port + hp_page_ctrl) & NARROW_SCSI_CARD)
6517 max_wd_cnt = EEPROM_WD_CNT;
6519 max_wd_cnt = EEPROM_WD_CNT * 2;
6521 temp = FPT_utilEERead(p_port, FW_SIGNATURE / 2);
6523 if (temp == 0x4641) {
6525 for (index = 2; index < max_wd_cnt; index++) {
6527 temp += FPT_utilEERead(p_port, index);
6531 if (temp == FPT_utilEERead(p_port, EEPROM_CHECK_SUM / 2)) {
6533 return; /*EEPROM is Okay so return now! */
6537 FPT_utilEEWriteOnOff(p_port, (unsigned char)1);
6539 for (index = 0; index < max_wd_cnt; index++) {
6541 FPT_utilEEWrite(p_port, 0x0000, index);
6546 FPT_utilEEWrite(p_port, 0x4641, FW_SIGNATURE / 2);
6548 FPT_utilEEWrite(p_port, 0x3920, MODEL_NUMB_0 / 2);
6550 FPT_utilEEWrite(p_port, 0x3033, MODEL_NUMB_2 / 2);
6552 FPT_utilEEWrite(p_port, 0x2020, MODEL_NUMB_4 / 2);
6554 FPT_utilEEWrite(p_port, 0x70D3, SYSTEM_CONFIG / 2);
6556 FPT_utilEEWrite(p_port, 0x0010, BIOS_CONFIG / 2);
6558 FPT_utilEEWrite(p_port, 0x0003, SCAM_CONFIG / 2);
6560 FPT_utilEEWrite(p_port, 0x0007, ADAPTER_SCSI_ID / 2);
6563 FPT_utilEEWrite(p_port, 0x0000, IGNORE_B_SCAN / 2);
6565 FPT_utilEEWrite(p_port, 0x0000, SEND_START_ENA / 2);
6567 FPT_utilEEWrite(p_port, 0x0000, DEVICE_ENABLE / 2);
6570 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL01 / 2);
6572 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL23 / 2);
6574 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL45 / 2);
6576 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL67 / 2);
6578 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL89 / 2);
6580 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLab / 2);
6582 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLcd / 2);
6584 FPT_utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLef / 2);
6587 FPT_utilEEWrite(p_port, 0x6C46, 64 / 2); /*PRODUCT ID */
6589 FPT_utilEEWrite(p_port, 0x7361, 66 / 2); /* FlashPoint LT */
6591 FPT_utilEEWrite(p_port, 0x5068, 68 / 2);
6593 FPT_utilEEWrite(p_port, 0x696F, 70 / 2);
6595 FPT_utilEEWrite(p_port, 0x746E, 72 / 2);
6597 FPT_utilEEWrite(p_port, 0x4C20, 74 / 2);
6599 FPT_utilEEWrite(p_port, 0x2054, 76 / 2);
6601 FPT_utilEEWrite(p_port, 0x2020, 78 / 2);
6604 index = ((EE_SCAMBASE / 2) + (7 * 16));
6605 FPT_utilEEWrite(p_port, (0x0700 + TYPE_CODE0), index);
6606 temp += (0x0700 + TYPE_CODE0);
6608 FPT_utilEEWrite(p_port, 0x5542, index); /*Vendor ID code */
6609 temp += 0x5542; /* BUSLOGIC */
6611 FPT_utilEEWrite(p_port, 0x4C53, index);
6614 FPT_utilEEWrite(p_port, 0x474F, index);
6617 FPT_utilEEWrite(p_port, 0x4349, index);
6620 FPT_utilEEWrite(p_port, 0x5442, index); /*Vendor unique code */
6621 temp += 0x5442; /* BT- 930 */
6623 FPT_utilEEWrite(p_port, 0x202D, index);
6626 FPT_utilEEWrite(p_port, 0x3339, index);
6628 index++; /*Serial # */
6629 FPT_utilEEWrite(p_port, 0x2030, index); /* 01234567 */
6632 FPT_utilEEWrite(p_port, 0x5453, index);
6635 FPT_utilEEWrite(p_port, 0x5645, index);
6638 FPT_utilEEWrite(p_port, 0x2045, index);
6641 FPT_utilEEWrite(p_port, 0x202F, index);
6644 FPT_utilEEWrite(p_port, 0x4F4A, index);
6647 FPT_utilEEWrite(p_port, 0x204E, index);
6650 FPT_utilEEWrite(p_port, 0x3539, index);
6653 FPT_utilEEWrite(p_port, temp, EEPROM_CHECK_SUM / 2);
6655 FPT_utilEEWriteOnOff(p_port, (unsigned char)0);
6659 /*---------------------------------------------------------------------
6661 * Function: Queue Search Select
6663 * Description: Try to find a new command to execute.
6665 *---------------------------------------------------------------------*/
6667 static void FPT_queueSearchSelect(struct sccb_card *pCurrCard,
6668 unsigned char p_card)
6670 unsigned char scan_ptr, lun;
6671 struct sccb_mgr_tar_info *currTar_Info;
6672 struct sccb *pOldSccb;
6674 scan_ptr = pCurrCard->scanIndex;
6676 currTar_Info = &FPT_sccbMgrTbl[p_card][scan_ptr];
6677 if ((pCurrCard->globalFlags & F_CONLUN_IO) &&
6678 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
6680 if (currTar_Info->TarSelQ_Cnt != 0) {
6683 if (scan_ptr == MAX_SCSI_TAR)
6686 for (lun = 0; lun < MAX_LUN; lun++) {
6687 if (currTar_Info->TarLUNBusy[lun] == 0) {
6689 pCurrCard->currentSCCB =
6690 currTar_Info->TarSelQ_Head;
6694 currentSCCB != NULL)
6697 currentSCCB->Lun)) {
6701 pCurrCard->currentSCCB =
6707 if (pCurrCard->currentSCCB ==
6710 if (pOldSccb != NULL) {
6753 pCurrCard->scanIndex = scan_ptr;
6755 pCurrCard->globalFlags |=
6765 if (scan_ptr == MAX_SCSI_TAR) {
6771 if ((currTar_Info->TarSelQ_Cnt != 0) &&
6772 (currTar_Info->TarLUNBusy[0] == 0)) {
6774 pCurrCard->currentSCCB =
6775 currTar_Info->TarSelQ_Head;
6777 currTar_Info->TarSelQ_Head =
6778 (struct sccb *)(pCurrCard->currentSCCB)->
6781 if (currTar_Info->TarSelQ_Head == NULL) {
6782 currTar_Info->TarSelQ_Tail = NULL;
6783 currTar_Info->TarSelQ_Cnt = 0;
6785 currTar_Info->TarSelQ_Cnt--;
6786 currTar_Info->TarSelQ_Head->
6787 Sccb_backlink = (struct sccb *)NULL;
6791 if (scan_ptr == MAX_SCSI_TAR)
6794 pCurrCard->scanIndex = scan_ptr;
6796 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
6803 if (scan_ptr == MAX_SCSI_TAR) {
6808 } while (scan_ptr != pCurrCard->scanIndex);
6811 /*---------------------------------------------------------------------
6813 * Function: Queue Select Fail
6815 * Description: Add the current SCCB to the head of the Queue.
6817 *---------------------------------------------------------------------*/
6819 static void FPT_queueSelectFail(struct sccb_card *pCurrCard,
6820 unsigned char p_card)
6822 unsigned char thisTarg;
6823 struct sccb_mgr_tar_info *currTar_Info;
6825 if (pCurrCard->currentSCCB != NULL) {
6827 (unsigned char)(((struct sccb *)(pCurrCard->currentSCCB))->
6829 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
6831 pCurrCard->currentSCCB->Sccb_backlink = (struct sccb *)NULL;
6833 pCurrCard->currentSCCB->Sccb_forwardlink =
6834 currTar_Info->TarSelQ_Head;
6836 if (currTar_Info->TarSelQ_Cnt == 0) {
6837 currTar_Info->TarSelQ_Tail = pCurrCard->currentSCCB;
6841 currTar_Info->TarSelQ_Head->Sccb_backlink =
6842 pCurrCard->currentSCCB;
6845 currTar_Info->TarSelQ_Head = pCurrCard->currentSCCB;
6847 pCurrCard->currentSCCB = NULL;
6848 currTar_Info->TarSelQ_Cnt++;
6852 /*---------------------------------------------------------------------
6854 * Function: Queue Command Complete
6856 * Description: Call the callback function with the current SCCB.
6858 *---------------------------------------------------------------------*/
6860 static void FPT_queueCmdComplete(struct sccb_card *pCurrCard,
6861 struct sccb *p_sccb, unsigned char p_card)
6864 unsigned char i, SCSIcmd;
6865 CALL_BK_FN callback;
6866 struct sccb_mgr_tar_info *currTar_Info;
6868 SCSIcmd = p_sccb->Cdb[0];
6870 if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED)) {
6873 ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN))
6874 && (p_sccb->HostStatus == SCCB_COMPLETE)
6875 && (p_sccb->TargetStatus != SSCHECK))
6877 if ((SCSIcmd == SCSI_READ) ||
6878 (SCSIcmd == SCSI_WRITE) ||
6879 (SCSIcmd == SCSI_READ_EXTENDED) ||
6880 (SCSIcmd == SCSI_WRITE_EXTENDED) ||
6881 (SCSIcmd == SCSI_WRITE_AND_VERIFY) ||
6882 (SCSIcmd == SCSI_START_STOP_UNIT) ||
6883 (pCurrCard->globalFlags & F_NO_FILTER)
6885 p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
6888 if (p_sccb->SccbStatus == SCCB_IN_PROCESS) {
6889 if (p_sccb->HostStatus || p_sccb->TargetStatus)
6890 p_sccb->SccbStatus = SCCB_ERROR;
6892 p_sccb->SccbStatus = SCCB_SUCCESS;
6895 if (p_sccb->Sccb_XferState & F_AUTO_SENSE) {
6897 p_sccb->CdbLength = p_sccb->Save_CdbLen;
6898 for (i = 0; i < 6; i++) {
6899 p_sccb->Cdb[i] = p_sccb->Save_Cdb[i];
6903 if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
6904 (p_sccb->OperationCode == RESIDUAL_COMMAND)) {
6906 FPT_utilUpdateResidual(p_sccb);
6909 pCurrCard->cmdCounter--;
6910 if (!pCurrCard->cmdCounter) {
6912 if (pCurrCard->globalFlags & F_GREEN_PC) {
6913 WR_HARPOON(pCurrCard->ioPort + hp_clkctrl_0,
6914 (PWR_DWN | CLKCTRL_DEFAULT));
6915 WR_HARPOON(pCurrCard->ioPort + hp_sys_ctrl, STOP_CLK);
6918 WR_HARPOON(pCurrCard->ioPort + hp_semaphore,
6919 (RD_HARPOON(pCurrCard->ioPort + hp_semaphore) &
6924 if (pCurrCard->discQCount != 0) {
6925 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
6926 if (((pCurrCard->globalFlags & F_CONLUN_IO) &&
6927 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) !=
6929 pCurrCard->discQCount--;
6930 pCurrCard->discQ_Tbl[currTar_Info->
6931 LunDiscQ_Idx[p_sccb->Lun]] = NULL;
6933 if (p_sccb->Sccb_tag) {
6934 pCurrCard->discQCount--;
6935 pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
6937 pCurrCard->discQCount--;
6938 pCurrCard->discQ_Tbl[currTar_Info->
6939 LunDiscQ_Idx[0]] = NULL;
6945 callback = (CALL_BK_FN) p_sccb->SccbCallback;
6947 pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
6948 pCurrCard->currentSCCB = NULL;
6951 /*---------------------------------------------------------------------
6953 * Function: Queue Disconnect
6955 * Description: Add SCCB to our disconnect array.
6957 *---------------------------------------------------------------------*/
6958 static void FPT_queueDisconnect(struct sccb *p_sccb, unsigned char p_card)
6960 struct sccb_mgr_tar_info *currTar_Info;
6962 currTar_Info = &FPT_sccbMgrTbl[p_card][p_sccb->TargID];
6964 if (((FPT_BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
6965 ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))) {
6966 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
6967 LunDiscQ_Idx[p_sccb->Lun]] =
6970 if (p_sccb->Sccb_tag) {
6971 FPT_BL_Card[p_card].discQ_Tbl[p_sccb->Sccb_tag] =
6973 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarLUNBusy[0] =
6975 FPT_sccbMgrTbl[p_card][p_sccb->TargID].TarTagQ_Cnt++;
6977 FPT_BL_Card[p_card].discQ_Tbl[currTar_Info->
6978 LunDiscQ_Idx[0]] = p_sccb;
6981 FPT_BL_Card[p_card].currentSCCB = NULL;
6984 /*---------------------------------------------------------------------
6986 * Function: Queue Flush SCCB
6988 * Description: Flush all SCCB's back to the host driver for this target.
6990 *---------------------------------------------------------------------*/
6992 static void FPT_queueFlushSccb(unsigned char p_card, unsigned char error_code)
6994 unsigned char qtag, thisTarg;
6995 struct sccb *currSCCB;
6996 struct sccb_mgr_tar_info *currTar_Info;
6998 currSCCB = FPT_BL_Card[p_card].currentSCCB;
6999 if (currSCCB != NULL) {
7000 thisTarg = (unsigned char)currSCCB->TargID;
7001 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7003 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
7005 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7006 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID ==
7009 FPT_BL_Card[p_card].discQ_Tbl[qtag]->
7010 HostStatus = (unsigned char)error_code;
7012 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
7013 FPT_BL_Card[p_card].
7014 discQ_Tbl[qtag], p_card);
7016 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7017 currTar_Info->TarTagQ_Cnt--;
7025 /*---------------------------------------------------------------------
7027 * Function: Queue Flush Target SCCB
7029 * Description: Flush all SCCB's back to the host driver for this target.
7031 *---------------------------------------------------------------------*/
7033 static void FPT_queueFlushTargSccb(unsigned char p_card, unsigned char thisTarg,
7034 unsigned char error_code)
7037 struct sccb_mgr_tar_info *currTar_Info;
7039 currTar_Info = &FPT_sccbMgrTbl[p_card][thisTarg];
7041 for (qtag = 0; qtag < QUEUE_DEPTH; qtag++) {
7043 if (FPT_BL_Card[p_card].discQ_Tbl[qtag] &&
7044 (FPT_BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg)) {
7046 FPT_BL_Card[p_card].discQ_Tbl[qtag]->HostStatus =
7047 (unsigned char)error_code;
7049 FPT_queueCmdComplete(&FPT_BL_Card[p_card],
7050 FPT_BL_Card[p_card].
7051 discQ_Tbl[qtag], p_card);
7053 FPT_BL_Card[p_card].discQ_Tbl[qtag] = NULL;
7054 currTar_Info->TarTagQ_Cnt--;
7061 static void FPT_queueAddSccb(struct sccb *p_SCCB, unsigned char p_card)
7063 struct sccb_mgr_tar_info *currTar_Info;
7064 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7066 p_SCCB->Sccb_forwardlink = NULL;
7068 p_SCCB->Sccb_backlink = currTar_Info->TarSelQ_Tail;
7070 if (currTar_Info->TarSelQ_Cnt == 0) {
7072 currTar_Info->TarSelQ_Head = p_SCCB;
7077 currTar_Info->TarSelQ_Tail->Sccb_forwardlink = p_SCCB;
7080 currTar_Info->TarSelQ_Tail = p_SCCB;
7081 currTar_Info->TarSelQ_Cnt++;
7084 /*---------------------------------------------------------------------
7086 * Function: Queue Find SCCB
7088 * Description: Search the target select Queue for this SCCB, and
7089 * remove it if found.
7091 *---------------------------------------------------------------------*/
7093 static unsigned char FPT_queueFindSccb(struct sccb *p_SCCB,
7094 unsigned char p_card)
7097 struct sccb_mgr_tar_info *currTar_Info;
7099 currTar_Info = &FPT_sccbMgrTbl[p_card][p_SCCB->TargID];
7101 q_ptr = currTar_Info->TarSelQ_Head;
7103 while (q_ptr != NULL) {
7105 if (q_ptr == p_SCCB) {
7107 if (currTar_Info->TarSelQ_Head == q_ptr) {
7109 currTar_Info->TarSelQ_Head =
7110 q_ptr->Sccb_forwardlink;
7113 if (currTar_Info->TarSelQ_Tail == q_ptr) {
7115 currTar_Info->TarSelQ_Tail =
7116 q_ptr->Sccb_backlink;
7119 if (q_ptr->Sccb_forwardlink != NULL) {
7120 q_ptr->Sccb_forwardlink->Sccb_backlink =
7121 q_ptr->Sccb_backlink;
7124 if (q_ptr->Sccb_backlink != NULL) {
7125 q_ptr->Sccb_backlink->Sccb_forwardlink =
7126 q_ptr->Sccb_forwardlink;
7129 currTar_Info->TarSelQ_Cnt--;
7135 q_ptr = q_ptr->Sccb_forwardlink;
7143 /*---------------------------------------------------------------------
7145 * Function: Utility Update Residual Count
7147 * Description: Update the XferCnt to the remaining byte count.
7148 * If we transferred all the data then just write zero.
7149 * If Non-SG transfer then report Total Cnt - Actual Transfer
7150 * Cnt. For SG transfers add the count fields of all
7151 * remaining SG elements, as well as any partial remaining
7154 *---------------------------------------------------------------------*/
7156 static void FPT_utilUpdateResidual(struct sccb *p_SCCB)
7158 unsigned long partial_cnt;
7159 unsigned int sg_index;
7160 struct blogic_sg_seg *segp;
7162 if (p_SCCB->Sccb_XferState & F_ALL_XFERRED) {
7164 p_SCCB->DataLength = 0x0000;
7167 else if (p_SCCB->Sccb_XferState & F_SG_XFER) {
7169 partial_cnt = 0x0000;
7171 sg_index = p_SCCB->Sccb_sgseg;
7174 if (p_SCCB->Sccb_SGoffset) {
7176 partial_cnt = p_SCCB->Sccb_SGoffset;
7180 while (((unsigned long)sg_index *
7181 (unsigned long)SG_ELEMENT_SIZE) < p_SCCB->DataLength) {
7182 segp = (struct blogic_sg_seg *)(p_SCCB->DataPointer) +
7184 partial_cnt += segp->segbytes;
7188 p_SCCB->DataLength = partial_cnt;
7193 p_SCCB->DataLength -= p_SCCB->Sccb_ATC;
7197 /*---------------------------------------------------------------------
7199 * Function: Wait 1 Second
7201 * Description: Wait for 1 second.
7203 *---------------------------------------------------------------------*/
7205 static void FPT_Wait1Second(u32 p_port)
7209 for (i = 0; i < 4; i++) {
7211 FPT_Wait(p_port, TO_250ms);
7213 if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
7216 if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
7221 /*---------------------------------------------------------------------
7223 * Function: FPT_Wait
7225 * Description: Wait the desired delay.
7227 *---------------------------------------------------------------------*/
7229 static void FPT_Wait(u32 p_port, unsigned char p_delay)
7231 unsigned char old_timer;
7232 unsigned char green_flag;
7234 old_timer = RD_HARPOON(p_port + hp_seltimeout);
7236 green_flag = RD_HARPOON(p_port + hp_clkctrl_0);
7237 WR_HARPOON(p_port + hp_clkctrl_0, CLKCTRL_DEFAULT);
7239 WR_HARPOON(p_port + hp_seltimeout, p_delay);
7240 WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
7241 WRW_HARPOON((p_port + hp_intena), (FPT_default_intena & ~TIMEOUT));
7243 WR_HARPOON(p_port + hp_portctrl_0,
7244 (RD_HARPOON(p_port + hp_portctrl_0) | START_TO));
7246 while (!(RDW_HARPOON((p_port + hp_intstat)) & TIMEOUT)) {
7248 if ((RD_HARPOON(p_port + hp_scsictrl_0) & SCSI_RST))
7251 if ((RDW_HARPOON((p_port + hp_intstat)) & SCAM_SEL))
7255 WR_HARPOON(p_port + hp_portctrl_0,
7256 (RD_HARPOON(p_port + hp_portctrl_0) & ~START_TO));
7258 WRW_HARPOON((p_port + hp_intstat), TIMEOUT);
7259 WRW_HARPOON((p_port + hp_intena), FPT_default_intena);
7261 WR_HARPOON(p_port + hp_clkctrl_0, green_flag);
7263 WR_HARPOON(p_port + hp_seltimeout, old_timer);
7266 /*---------------------------------------------------------------------
7268 * Function: Enable/Disable Write to EEPROM
7270 * Description: The EEPROM must first be enabled for writes
7271 * A total of 9 clocks are needed.
7273 *---------------------------------------------------------------------*/
7275 static void FPT_utilEEWriteOnOff(u32 p_port, unsigned char p_mode)
7277 unsigned char ee_value;
7280 (unsigned char)(RD_HARPOON(p_port + hp_ee_ctrl) &
7281 (EXT_ARB_ACK | SCSI_TERM_ENA_H));
7285 FPT_utilEESendCmdAddr(p_port, EWEN, EWEN_ADDR);
7289 FPT_utilEESendCmdAddr(p_port, EWDS, EWDS_ADDR);
7291 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
7292 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
7295 /*---------------------------------------------------------------------
7297 * Function: Write EEPROM
7299 * Description: Write a word to the EEPROM at the specified
7302 *---------------------------------------------------------------------*/
7304 static void FPT_utilEEWrite(u32 p_port, unsigned short ee_data,
7305 unsigned short ee_addr)
7308 unsigned char ee_value;
7313 char)((RD_HARPOON(p_port + hp_ee_ctrl) &
7314 (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
7316 FPT_utilEESendCmdAddr(p_port, EE_WRITE, ee_addr);
7318 ee_value |= (SEE_MS + SEE_CS);
7320 for (i = 0x8000; i != 0; i >>= 1) {
7325 ee_value &= ~SEE_DO;
7327 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7328 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7329 ee_value |= SEE_CLK; /* Clock data! */
7330 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7331 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7332 ee_value &= ~SEE_CLK;
7333 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7334 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7336 ee_value &= (EXT_ARB_ACK | SCSI_TERM_ENA_H);
7337 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS));
7339 FPT_Wait(p_port, TO_10ms);
7341 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS | SEE_CS)); /* Set CS to EEPROM */
7342 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /* Turn off CS */
7343 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /* Turn off Master Select */
7346 /*---------------------------------------------------------------------
7348 * Function: Read EEPROM
7350 * Description: Read a word from the EEPROM at the desired
7353 *---------------------------------------------------------------------*/
7355 static unsigned short FPT_utilEERead(u32 p_port,
7356 unsigned short ee_addr)
7358 unsigned short i, ee_data1, ee_data2;
7361 ee_data1 = FPT_utilEEReadOrg(p_port, ee_addr);
7363 ee_data2 = FPT_utilEEReadOrg(p_port, ee_addr);
7365 if (ee_data1 == ee_data2)
7368 ee_data1 = ee_data2;
7376 /*---------------------------------------------------------------------
7378 * Function: Read EEPROM Original
7380 * Description: Read a word from the EEPROM at the desired
7383 *---------------------------------------------------------------------*/
7385 static unsigned short FPT_utilEEReadOrg(u32 p_port, unsigned short ee_addr)
7388 unsigned char ee_value;
7389 unsigned short i, ee_data;
7393 char)((RD_HARPOON(p_port + hp_ee_ctrl) &
7394 (EXT_ARB_ACK | SCSI_TERM_ENA_H)) | (SEE_MS | SEE_CS));
7396 FPT_utilEESendCmdAddr(p_port, EE_READ, ee_addr);
7398 ee_value |= (SEE_MS + SEE_CS);
7401 for (i = 1; i <= 16; i++) {
7403 ee_value |= SEE_CLK; /* Clock data! */
7404 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7405 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7406 ee_value &= ~SEE_CLK;
7407 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7408 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7412 if (RD_HARPOON(p_port + hp_ee_ctrl) & SEE_DI)
7416 ee_value &= ~(SEE_MS + SEE_CS);
7417 WR_HARPOON(p_port + hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
7418 WR_HARPOON(p_port + hp_ee_ctrl, ee_value); /*Turn off Master Select */
7423 /*---------------------------------------------------------------------
7425 * Function: Send EE command and Address to the EEPROM
7427 * Description: Transfers the correct command and sends the address
7430 *---------------------------------------------------------------------*/
7432 static void FPT_utilEESendCmdAddr(u32 p_port, unsigned char ee_cmd,
7433 unsigned short ee_addr)
7435 unsigned char ee_value;
7436 unsigned char narrow_flg;
7441 (unsigned char)(RD_HARPOON(p_port + hp_page_ctrl) &
7445 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7447 ee_value |= SEE_CS; /* Set CS to EEPROM */
7448 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7450 for (i = 0x04; i != 0; i >>= 1) {
7455 ee_value &= ~SEE_DO;
7457 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7458 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7459 ee_value |= SEE_CLK; /* Clock data! */
7460 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7461 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7462 ee_value &= ~SEE_CLK;
7463 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7464 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7478 ee_value &= ~SEE_DO;
7480 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7481 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7482 ee_value |= SEE_CLK; /* Clock data! */
7483 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7484 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7485 ee_value &= ~SEE_CLK;
7486 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7487 WR_HARPOON(p_port + hp_ee_ctrl, ee_value);
7493 static unsigned short FPT_CalcCrc16(unsigned char buffer[])
7495 unsigned short crc = 0;
7498 for (i = 0; i < ID_STRING_LENGTH; i++) {
7499 ch = (unsigned short)buffer[i];
7500 for (j = 0; j < 8; j++) {
7502 crc = (crc >> 1) ^ CRCMASK;
7511 static unsigned char FPT_CalcLrc(unsigned char buffer[])
7516 for (i = 0; i < ID_STRING_LENGTH; i++)
7522 The following inline definitions avoid type conflicts.
7525 static inline unsigned char
7526 FlashPoint__ProbeHostAdapter(struct fpoint_info *FlashPointInfo)
7528 return FlashPoint_ProbeHostAdapter((struct sccb_mgr_info *)
7532 static inline void *
7533 FlashPoint__HardwareResetHostAdapter(struct fpoint_info *FlashPointInfo)
7535 return FlashPoint_HardwareResetHostAdapter((struct sccb_mgr_info *)
7540 FlashPoint__ReleaseHostAdapter(void *CardHandle)
7542 FlashPoint_ReleaseHostAdapter(CardHandle);
7546 FlashPoint__StartCCB(void *CardHandle, struct blogic_ccb *CCB)
7548 FlashPoint_StartCCB(CardHandle, (struct sccb *)CCB);
7552 FlashPoint__AbortCCB(void *CardHandle, struct blogic_ccb *CCB)
7554 FlashPoint_AbortCCB(CardHandle, (struct sccb *)CCB);
7558 FlashPoint__InterruptPending(void *CardHandle)
7560 return FlashPoint_InterruptPending(CardHandle);
7564 FlashPoint__HandleInterrupt(void *CardHandle)
7566 return FlashPoint_HandleInterrupt(CardHandle);
7569 #define FlashPoint_ProbeHostAdapter FlashPoint__ProbeHostAdapter
7570 #define FlashPoint_HardwareResetHostAdapter FlashPoint__HardwareResetHostAdapter
7571 #define FlashPoint_ReleaseHostAdapter FlashPoint__ReleaseHostAdapter
7572 #define FlashPoint_StartCCB FlashPoint__StartCCB
7573 #define FlashPoint_AbortCCB FlashPoint__AbortCCB
7574 #define FlashPoint_InterruptPending FlashPoint__InterruptPending
7575 #define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
7577 #else /* !CONFIG_SCSI_FLASHPOINT */
7580 Define prototypes for the FlashPoint SCCB Manager Functions.
7583 extern unsigned char FlashPoint_ProbeHostAdapter(struct fpoint_info *);
7584 extern void *FlashPoint_HardwareResetHostAdapter(struct fpoint_info *);
7585 extern void FlashPoint_StartCCB(void *, struct blogic_ccb *);
7586 extern int FlashPoint_AbortCCB(void *, struct blogic_ccb *);
7587 extern bool FlashPoint_InterruptPending(void *);
7588 extern int FlashPoint_HandleInterrupt(void *);
7589 extern void FlashPoint_ReleaseHostAdapter(void *);
7591 #endif /* CONFIG_SCSI_FLASHPOINT */