FlashPoint.c
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:308k
- dataXferProcessor(port, &BL_Card[p_card]);
- while((!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY)) &&
- (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY)) {}
- }
- } /*End Data In specific code. */
- #if defined(DOS)
- asm { mov dx,port;
- add dx,hp_xfercnt_2;
- in al,dx;
- dec dx;
- xor ah,ah;
- mov word ptr xfercnt+2,ax;
- in al,dx;
- dec dx;
- mov ah,al;
- in al,dx;
- mov word ptr xfercnt,ax;
- }
- #else
- GET_XFER_CNT(port,xfercnt);
- #endif
- WR_HARPOON(port+hp_xfercnt_0, 0x00);
- WR_HARPOON(port+hp_portctrl_0, 0x00);
- currSCCB->Sccb_ATC += (currSCCB->Sccb_XferCnt - xfercnt);
- currSCCB->Sccb_XferCnt = xfercnt;
- if ((RDW_HARPOON((port+hp_intstat)) & PARITY) &&
- (currSCCB->HostStatus == SCCB_COMPLETE)) {
- currSCCB->HostStatus = SCCB_PARITY_ERR;
- WRW_HARPOON((port+hp_intstat), PARITY);
- }
- hostDataXferAbort(port,p_card,currSCCB);
- WR_HARPOON(port+hp_fifowrite, 0x00);
- WR_HARPOON(port+hp_fiforead, 0x00);
- WR_HARPOON(port+hp_xferstat, 0x00);
- WRW_HARPOON((port+hp_intstat), XFER_CNT_0);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Phase Bus Free
- *
- * Description: We just went bus free so figure out if it was
- * because of command complete or from a disconnect.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void phaseBusFree(USHORT port, UCHAR p_card)
- #else
- void phaseBusFree(ULONG port, UCHAR p_card)
- #endif
- {
- PSCCB currSCCB;
- currSCCB = BL_Card[p_card].currentSCCB;
- if (currSCCB != NULL)
- {
- DISABLE_AUTO(port);
- if (currSCCB->OperationCode == RESET_COMMAND)
- {
- if((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = FALSE;
- else
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = FALSE;
- queueCmdComplete(&BL_Card[p_card], currSCCB, p_card);
- queueSearchSelect(&BL_Card[p_card],p_card);
- }
- else if(currSCCB->Sccb_scsistat == SELECT_SN_ST)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
- (UCHAR)SYNC_SUPPORTED;
- sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_SYNC_MASK;
- }
- else if(currSCCB->Sccb_scsistat == SELECT_WN_ST)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
- (sccbMgrTbl[p_card][currSCCB->TargID].
- TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
- sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_WIDE_SCSI;
- }
- #if !defined(DOS)
- else if(currSCCB->Sccb_scsistat == SELECT_Q_ST)
- {
- /* Make sure this is not a phony BUS_FREE. If we were
- reselected or if BUSY is NOT on then this is a
- valid BUS FREE. SRR Wednesday, 5/10/1995. */
- if ((!(RD_HARPOON(port+hp_scsisig) & SCSI_BSY)) ||
- (RDW_HARPOON((port+hp_intstat)) & RSEL))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_TAG_Q_MASK;
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |= TAG_Q_REJECT;
- }
- else
- {
- return;
- }
- }
- #endif
- else
- {
- currSCCB->Sccb_scsistat = BUS_FREE_ST;
- if (!currSCCB->HostStatus)
- {
- currSCCB->HostStatus = SCCB_PHASE_SEQUENCE_FAIL;
- }
- if((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = FALSE;
- else
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = FALSE;
- queueCmdComplete(&BL_Card[p_card], currSCCB, p_card);
- return;
- }
- BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
- } /*end if !=null */
- }
- #ident "$Id: automate.c 1.14 1997/01/31 02:11:46 mohan Exp $"
- /*----------------------------------------------------------------------
- *
- *
- * Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
- *
- * This file is available under both the GNU General Public License
- * and a BSD-style copyright; see LICENSE.FlashPoint for details.
- *
- * $Workfile: automate.c $
- *
- * Description: Functions relating to programming the automation of
- * the HARPOON.
- *
- * $Date: 1997/01/31 02:11:46 $
- *
- * $Revision: 1.14 $
- *
- *----------------------------------------------------------------------*/
- /*#include <globals.h>*/
- #if (FW_TYPE==_UCB_MGR_)
- /*#include <budi.h>*/
- #endif
- /*#include <sccbmgr.h>*/
- /*#include <blx30.h>*/
- /*#include <target.h>*/
- /*#include <scsi2.h>*/
- /*#include <harpoon.h>*/
- /*
- extern SCCBCARD BL_Card[MAX_CARDS];
- extern SCCBMGR_TAR_INFO sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR];
- extern SCCBCARD BL_Card[MAX_CARDS];
- */
- /*---------------------------------------------------------------------
- *
- * Function: Auto Load Default Map
- *
- * Description: Load the Automation RAM with the defualt map values.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void autoLoadDefaultMap(USHORT p_port)
- #else
- void autoLoadDefaultMap(ULONG p_port)
- #endif
- {
- #if defined(DOS)
- USHORT map_addr;
- #else
- ULONG map_addr;
- #endif
- ARAM_ACCESS(p_port);
- map_addr = p_port + hp_aramBase;
- WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0xC0)); /*ID MESSAGE */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0x20)); /*SIMPLE TAG QUEUEING MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, RAT_OP); /*RESET ATTENTION */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+AMSG_OUT+ 0x00)); /*TAG ID MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 0 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 1 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 2 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 3 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 4 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 5 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 6 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 7 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 8 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 9 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 10 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MPM_OP+ACOMMAND+ 0x00)); /*CDB BYTE 11 */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPE_OP+ADATA_OUT+ DINT)); /*JUMP IF DATA OUT */
- map_addr +=2;
- WRW_HARPOON(map_addr, (TCB_OP+FIFO_0+ DI)); /*JUMP IF NO DATA IN FIFO */
- map_addr +=2; /*This means AYNC DATA IN */
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_IDO_STRT)); /*STOP AND INTERRUPT */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPE_OP+ADATA_IN+DINT)); /*JUMP IF NOT DATA IN PHZ */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ ST)); /*IF NOT MSG IN CHECK 4 DATA IN */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x02)); /*SAVE DATA PTR MSG? */
- map_addr +=2;
- WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ DC)); /*GO CHECK FOR DISCONNECT MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_AR1)); /*SAVE DATA PTRS MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ ST)); /*IF NOT MSG IN CHECK DATA IN */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x04)); /*DISCONNECT MSG? */
- map_addr +=2;
- WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ UNKNWN));/*UKNKNOWN MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_BUCKET));/*XFER DISCONNECT MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_ITAR_DISC));/*STOP AND INTERRUPT */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPN_OP+ASTATUS+ UNKNWN));/*JUMP IF NOT STATUS PHZ. */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_AR0)); /*GET STATUS BYTE */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CPN_OP+AMSG_IN+ CC)); /*ERROR IF NOT MSG IN PHZ */
- map_addr +=2;
- WRW_HARPOON(map_addr, (CRD_OP+SDATA+ 0x00)); /*CHECK FOR CMD COMPLETE MSG. */
- map_addr +=2;
- WRW_HARPOON(map_addr, (BRH_OP+NOT_EQ+ CC)); /*ERROR IF NOT CMD COMPLETE MSG. */
- map_addr +=2;
- WRW_HARPOON(map_addr, (MRR_OP+SDATA+ D_BUCKET));/*GET CMD COMPLETE MSG */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_ICMD_COMP));/*END OF COMMAND */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_IUNKWN)); /*RECEIVED UNKNOWN MSG BYTE */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_ITICKLE)); /*BIOS Tickled the Mgr */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_IRFAIL)); /*EXPECTED ID/TAG MESSAGES AND */
- map_addr +=2; /* DIDN'T GET ONE */
- WRW_HARPOON(map_addr, (CRR_OP+AR3+ S_IDREG)); /* comp SCSI SEL ID & AR3*/
- map_addr +=2;
- WRW_HARPOON(map_addr, (BRH_OP+EQUAL+ 0x00)); /*SEL ID OK then Conti. */
- map_addr +=2;
- WRW_HARPOON(map_addr, (SSI_OP+ SSI_INO_CC)); /*NO COMMAND COMPLETE AFTER STATUS */
- SGRAM_ACCESS(p_port);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Auto Command Complete
- *
- * Description: Post command back to host and find another command
- * to execute.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void autoCmdCmplt(USHORT p_port, UCHAR p_card)
- #else
- void autoCmdCmplt(ULONG p_port, UCHAR p_card)
- #endif
- {
- PSCCB currSCCB;
- UCHAR status_byte;
- currSCCB = BL_Card[p_card].currentSCCB;
- status_byte = RD_HARPOON(p_port+hp_gp_reg_0);
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA = FALSE;
- if (status_byte != SSGOOD) {
- if (status_byte == SSQ_FULL) {
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = TRUE;
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
- }
- else
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = TRUE;
- if(currSCCB->Sccb_tag)
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
- }else
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
- }
- }
- currSCCB->Sccb_MGRFlags |= F_STATUSLOADED;
- queueSelectFail(&BL_Card[p_card],p_card);
- return;
- }
- if(currSCCB->Sccb_scsistat == SELECT_SN_ST)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus |=
- (UCHAR)SYNC_SUPPORTED;
- sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_SYNC_MASK;
- BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = TRUE;
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
- }
- else
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = TRUE;
- if(currSCCB->Sccb_tag)
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
- }else
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
- }
- }
- return;
- }
- if(currSCCB->Sccb_scsistat == SELECT_WN_ST)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus =
- (sccbMgrTbl[p_card][currSCCB->TargID].
- TarStatus & ~WIDE_ENABLED) | WIDE_NEGOCIATED;
- sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue &= ~EE_WIDE_SCSI;
- BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = TRUE;
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
- }
- else
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = TRUE;
- if(currSCCB->Sccb_tag)
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
- }else
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
- }
- }
- return;
-
- }
-
- if (status_byte == SSCHECK)
- {
- if(BL_Card[p_card].globalFlags & F_DO_RENEGO)
- {
- if (sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue & EE_SYNC_MASK)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_SYNC_MASK;
- }
- if (sccbMgrTbl[p_card][currSCCB->TargID].TarEEValue & EE_WIDE_SCSI)
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarStatus &= ~TAR_WIDE_MASK;
- }
- }
- }
- if (!(currSCCB->Sccb_XferState & F_AUTO_SENSE)) {
- currSCCB->SccbStatus = SCCB_ERROR;
- currSCCB->TargetStatus = status_byte;
- if (status_byte == SSCHECK) {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUN_CA
- = TRUE;
-
- #if (FW_TYPE==_SCCB_MGR_)
- if (currSCCB->RequestSenseLength != NO_AUTO_REQUEST_SENSE) {
- if (currSCCB->RequestSenseLength == 0)
- currSCCB->RequestSenseLength = 14;
- ssenss(&BL_Card[p_card]);
- BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = TRUE;
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
- }
- else
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = TRUE;
- if(currSCCB->Sccb_tag)
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
- }else
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
- }
- }
- return;
- }
- #else
- if ((!(currSCCB->Sccb_ucb_ptr->UCB_opcode & OPC_NO_AUTO_SENSE)) &&
- (currSCCB->RequestSenseLength))
- {
- ssenss(&BL_Card[p_card]);
- BL_Card[p_card].globalFlags |= F_NEW_SCCB_CMD;
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = TRUE;
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[currSCCB->Lun]] = NULL;
- }
- else
- {
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = TRUE;
- if(currSCCB->Sccb_tag)
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[currSCCB->Sccb_tag] = NULL;
- }else
- {
- if(BL_Card[p_card].discQCount != 0)
- BL_Card[p_card].discQCount--;
- BL_Card[p_card].discQ_Tbl[sccbMgrTbl[p_card][currSCCB->TargID].LunDiscQ_Idx[0]] = NULL;
- }
- }
- return;
- }
- #endif
- }
- }
- }
- if((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((sccbMgrTbl[p_card][currSCCB->TargID].TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[currSCCB->Lun] = FALSE;
- else
- sccbMgrTbl[p_card][currSCCB->TargID].TarLUNBusy[0] = FALSE;
- queueCmdComplete(&BL_Card[p_card], currSCCB, p_card);
- }
- #ident "$Id: busmstr.c 1.8 1997/01/31 02:10:27 mohan Exp $"
- /*----------------------------------------------------------------------
- *
- *
- * Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
- *
- * This file is available under both the GNU General Public License
- * and a BSD-style copyright; see LICENSE.FlashPoint for details.
- *
- * $Workfile: busmstr.c $
- *
- * Description: Functions to start, stop, and abort BusMaster operations.
- *
- * $Date: 1997/01/31 02:10:27 $
- *
- * $Revision: 1.8 $
- *
- *----------------------------------------------------------------------*/
- /*#include <globals.h>*/
- #if (FW_TYPE==_UCB_MGR_)
- /*#include <budi.h>*/
- #endif
- /*#include <sccbmgr.h>*/
- /*#include <blx30.h>*/
- /*#include <target.h>*/
- /*#include <scsi2.h>*/
- /*#include <harpoon.h>*/
- /*
- extern SCCBCARD BL_Card[MAX_CARDS];
- extern SCCBMGR_TAR_INFO sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR];
- */
- #define SHORT_WAIT 0x0000000F
- #define LONG_WAIT 0x0000FFFFL
- #if defined(BUGBUG)
- void Debug_Load(UCHAR p_card, UCHAR p_bug_data);
- #endif
- /*---------------------------------------------------------------------
- *
- * Function: Data Transfer Processor
- *
- * Description: This routine performs two tasks.
- * (1) Start data transfer by calling HOST_DATA_XFER_START
- * function. Once data transfer is started, (2) Depends
- * on the type of data transfer mode Scatter/Gather mode
- * or NON Scatter/Gather mode. In NON Scatter/Gather mode,
- * this routine checks Sccb_MGRFlag (F_HOST_XFER_ACT bit) for
- * data transfer done. In Scatter/Gather mode, this routine
- * checks bus master command complete and dual rank busy
- * bit to keep chaining SC transfer command. Similarly,
- * in Scatter/Gather mode, it checks Sccb_MGRFlag
- * (F_HOST_XFER_ACT bit) for data transfer done.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void dataXferProcessor(USHORT port, PSCCBcard pCurrCard)
- #else
- void dataXferProcessor(ULONG port, PSCCBcard pCurrCard)
- #endif
- {
- PSCCB currSCCB;
- currSCCB = pCurrCard->currentSCCB;
- if (currSCCB->Sccb_XferState & F_SG_XFER)
- {
- if (pCurrCard->globalFlags & F_HOST_XFER_ACT)
- {
- currSCCB->Sccb_sgseg += (UCHAR)SG_BUF_CNT;
- currSCCB->Sccb_SGoffset = 0x00;
- }
- pCurrCard->globalFlags |= F_HOST_XFER_ACT;
-
- busMstrSGDataXferStart(port, currSCCB);
- }
- else
- {
- if (!(pCurrCard->globalFlags & F_HOST_XFER_ACT))
- {
- pCurrCard->globalFlags |= F_HOST_XFER_ACT;
-
- busMstrDataXferStart(port, currSCCB);
- }
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: BusMaster Scatter Gather Data Transfer Start
- *
- * Description:
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void busMstrSGDataXferStart(USHORT p_port, PSCCB pcurrSCCB)
- #else
- void busMstrSGDataXferStart(ULONG p_port, PSCCB pcurrSCCB)
- #endif
- {
- ULONG count,addr,tmpSGCnt;
- UINT sg_index;
- UCHAR sg_count, i;
- #if defined(DOS)
- USHORT reg_offset;
- #else
- ULONG reg_offset;
- #endif
- if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
- count = ((ULONG) HOST_RD_CMD)<<24;
- }
- else {
- count = ((ULONG) HOST_WRT_CMD)<<24;
- }
- sg_count = 0;
- tmpSGCnt = 0;
- sg_index = pcurrSCCB->Sccb_sgseg;
- reg_offset = hp_aramBase;
- i = (UCHAR) (RD_HARPOON(p_port+hp_page_ctrl) & ~(SGRAM_ARAM|SCATTER_EN));
- WR_HARPOON(p_port+hp_page_ctrl, i);
- while ((sg_count < (UCHAR)SG_BUF_CNT) &&
- ((ULONG)(sg_index * (UINT)SG_ELEMENT_SIZE) < pcurrSCCB->DataLength) ) {
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- tmpSGCnt += *(((ULONG far *)pcurrSCCB->DataPointer)+
- (sg_index * 2));
- count |= *(((ULONG far *)pcurrSCCB->DataPointer)+
- (sg_index * 2));
- addr = *(((ULONG far *)pcurrSCCB->DataPointer)+
- ((sg_index * 2) + 1));
- #else
- tmpSGCnt += *(((ULONG *)pcurrSCCB->DataPointer)+
- (sg_index * 2));
- count |= *(((ULONG *)pcurrSCCB->DataPointer)+
- (sg_index * 2));
- addr = *(((ULONG *)pcurrSCCB->DataPointer)+
- ((sg_index * 2) + 1));
- #endif
- if ((!sg_count) && (pcurrSCCB->Sccb_SGoffset)) {
- addr += ((count & 0x00FFFFFFL) - pcurrSCCB->Sccb_SGoffset);
- count = (count & 0xFF000000L) | pcurrSCCB->Sccb_SGoffset;
- tmpSGCnt = count & 0x00FFFFFFL;
- }
- WR_HARP32(p_port,reg_offset,addr);
- reg_offset +=4;
- WR_HARP32(p_port,reg_offset,count);
- reg_offset +=4;
- count &= 0xFF000000L;
- sg_index++;
- sg_count++;
- } /*End While */
- pcurrSCCB->Sccb_XferCnt = tmpSGCnt;
- WR_HARPOON(p_port+hp_sg_addr,(sg_count<<4));
- if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
- WR_HARP32(p_port,hp_xfercnt_0,tmpSGCnt);
- WR_HARPOON(p_port+hp_portctrl_0,(DMA_PORT | SCSI_PORT | SCSI_INBIT));
- WR_HARPOON(p_port+hp_scsisig, S_DATAI_PH);
- }
- else {
- if ((!(RD_HARPOON(p_port+hp_synctarg_0) & NARROW_SCSI)) &&
- (tmpSGCnt & 0x000000001))
- {
- pcurrSCCB->Sccb_XferState |= F_ODD_BALL_CNT;
- tmpSGCnt--;
- }
- WR_HARP32(p_port,hp_xfercnt_0,tmpSGCnt);
- WR_HARPOON(p_port+hp_portctrl_0,(SCSI_PORT | DMA_PORT | DMA_RD));
- WR_HARPOON(p_port+hp_scsisig, S_DATAO_PH);
- }
- WR_HARPOON(p_port+hp_page_ctrl, (UCHAR) (i | SCATTER_EN));
- }
- /*---------------------------------------------------------------------
- *
- * Function: BusMaster Data Transfer Start
- *
- * Description:
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void busMstrDataXferStart(USHORT p_port, PSCCB pcurrSCCB)
- #else
- void busMstrDataXferStart(ULONG p_port, PSCCB pcurrSCCB)
- #endif
- {
- ULONG addr,count;
- if (!(pcurrSCCB->Sccb_XferState & F_AUTO_SENSE)) {
- count = pcurrSCCB->Sccb_XferCnt;
- addr = (ULONG) pcurrSCCB->DataPointer + pcurrSCCB->Sccb_ATC;
- }
- else {
- addr = pcurrSCCB->SensePointer;
- count = pcurrSCCB->RequestSenseLength;
- }
- #if defined(DOS)
- asm { mov dx,p_port;
- mov ax,word ptr count;
- add dx,hp_xfer_cnt_lo;
- out dx,al;
- inc dx;
- xchg ah,al
- out dx,al;
- inc dx;
- mov ax,word ptr count+2;
- out dx,al;
- inc dx;
- inc dx;
- mov ax,word ptr addr;
- out dx,al;
- inc dx;
- xchg ah,al
- out dx,al;
- inc dx;
- mov ax,word ptr addr+2;
- out dx,al;
- inc dx;
- xchg ah,al
- out dx,al;
- }
- WR_HARP32(p_port,hp_xfercnt_0,count);
- #else
- HP_SETUP_ADDR_CNT(p_port,addr,count);
- #endif
- if (pcurrSCCB->Sccb_XferState & F_HOST_XFER_DIR) {
- WR_HARPOON(p_port+hp_portctrl_0,(DMA_PORT | SCSI_PORT | SCSI_INBIT));
- WR_HARPOON(p_port+hp_scsisig, S_DATAI_PH);
- WR_HARPOON(p_port+hp_xfer_cmd,
- (XFER_DMA_HOST | XFER_HOST_AUTO | XFER_DMA_8BIT));
- }
- else {
- WR_HARPOON(p_port+hp_portctrl_0,(SCSI_PORT | DMA_PORT | DMA_RD));
- WR_HARPOON(p_port+hp_scsisig, S_DATAO_PH);
- WR_HARPOON(p_port+hp_xfer_cmd,
- (XFER_HOST_DMA | XFER_HOST_AUTO | XFER_DMA_8BIT));
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: BusMaster Timeout Handler
- *
- * Description: This function is called after a bus master command busy time
- * out is detected. This routines issue halt state machine
- * with a software time out for command busy. If command busy
- * is still asserted at the end of the time out, it issues
- * hard abort with another software time out. It hard abort
- * command busy is also time out, it'll just give up.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- UCHAR busMstrTimeOut(USHORT p_port)
- #else
- UCHAR busMstrTimeOut(ULONG p_port)
- #endif
- {
- ULONG timeout;
- timeout = LONG_WAIT;
- WR_HARPOON(p_port+hp_sys_ctrl, HALT_MACH);
- while ((!(RD_HARPOON(p_port+hp_ext_status) & CMD_ABORTED)) && timeout--) {}
-
-
- if (RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) {
- WR_HARPOON(p_port+hp_sys_ctrl, HARD_ABORT);
- timeout = LONG_WAIT;
- while ((RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
- }
- RD_HARPOON(p_port+hp_int_status); /*Clear command complete */
- if (RD_HARPOON(p_port+hp_ext_status) & BM_CMD_BUSY) {
- return(TRUE);
- }
- else {
- return(FALSE);
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: Host Data Transfer Abort
- *
- * Description: Abort any in progress transfer.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void hostDataXferAbort(USHORT port, UCHAR p_card, PSCCB pCurrSCCB)
- #else
- void hostDataXferAbort(ULONG port, UCHAR p_card, PSCCB pCurrSCCB)
- #endif
- {
- ULONG timeout;
- ULONG remain_cnt;
- UINT sg_ptr;
- BL_Card[p_card].globalFlags &= ~F_HOST_XFER_ACT;
- if (pCurrSCCB->Sccb_XferState & F_AUTO_SENSE) {
- if (!(RD_HARPOON(port+hp_int_status) & INT_CMD_COMPL)) {
- WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) | FLUSH_XFER_CNTR));
- timeout = LONG_WAIT;
- while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
- WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) & ~FLUSH_XFER_CNTR));
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- if (busMstrTimeOut(port)) {
- if (pCurrSCCB->HostStatus == 0x00)
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- }
- if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS)
- if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS)
- if (pCurrSCCB->HostStatus == 0x00)
- {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- #if defined(BUGBUG)
- WR_HARPOON(port+hp_dual_addr_lo,
- RD_HARPOON(port+hp_ext_status));
- #endif
- }
- }
- }
- }
- else if (pCurrSCCB->Sccb_XferCnt) {
- if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
- WR_HARPOON(port+hp_page_ctrl, (RD_HARPOON(port+hp_page_ctrl) &
- ~SCATTER_EN));
- WR_HARPOON(port+hp_sg_addr,0x00);
- sg_ptr = pCurrSCCB->Sccb_sgseg + SG_BUF_CNT;
- if (sg_ptr > (UINT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE)) {
- sg_ptr = (UINT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE);
- }
- remain_cnt = pCurrSCCB->Sccb_XferCnt;
- while (remain_cnt < 0x01000000L) {
- sg_ptr--;
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- if (remain_cnt > (ULONG)(*(((ULONG far *)pCurrSCCB->
- DataPointer) + (sg_ptr * 2)))) {
- remain_cnt -= (ULONG)(*(((ULONG far *)pCurrSCCB->
- DataPointer) + (sg_ptr * 2)));
- }
- #else
- if (remain_cnt > (ULONG)(*(((ULONG *)pCurrSCCB->
- DataPointer) + (sg_ptr * 2)))) {
- remain_cnt -= (ULONG)(*(((ULONG *)pCurrSCCB->
- DataPointer) + (sg_ptr * 2)));
- }
- #endif
- else {
- break;
- }
- }
- if (remain_cnt < 0x01000000L) {
- pCurrSCCB->Sccb_SGoffset = remain_cnt;
- pCurrSCCB->Sccb_sgseg = (USHORT)sg_ptr;
- if ((ULONG)(sg_ptr * SG_ELEMENT_SIZE) == pCurrSCCB->DataLength
- && (remain_cnt == 0))
- pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
- }
- else {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_GROSS_FW_ERR;
- }
- }
- }
- if (!(pCurrSCCB->Sccb_XferState & F_HOST_XFER_DIR)) {
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- busMstrTimeOut(port);
- }
- else {
- if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
- if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- #if defined(BUGBUG)
- WR_HARPOON(port+hp_dual_addr_lo,
- RD_HARPOON(port+hp_ext_status));
- #endif
- }
- }
- }
- }
- }
- else {
- if ((RD_HARPOON(port+hp_fifo_cnt)) >= BM_THRESHOLD) {
- timeout = SHORT_WAIT;
- while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) &&
- ((RD_HARPOON(port+hp_fifo_cnt)) >= BM_THRESHOLD) &&
- timeout--) {}
- }
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) |
- FLUSH_XFER_CNTR));
- timeout = LONG_WAIT;
- while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) &&
- timeout--) {}
- WR_HARPOON(port+hp_bm_ctrl, (RD_HARPOON(port+hp_bm_ctrl) &
- ~FLUSH_XFER_CNTR));
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- }
- busMstrTimeOut(port);
- }
- }
- if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
- if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- #if defined(BUGBUG)
- WR_HARPOON(port+hp_dual_addr_lo,
- RD_HARPOON(port+hp_ext_status));
- #endif
- }
- }
- }
- }
- }
- else {
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- timeout = LONG_WAIT;
- while ((RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) && timeout--) {}
- if (RD_HARPOON(port+hp_ext_status) & BM_CMD_BUSY) {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- }
- busMstrTimeOut(port);
- }
- }
- if (RD_HARPOON(port+hp_int_status) & INT_EXT_STATUS) {
- if (RD_HARPOON(port+hp_ext_status) & BAD_EXT_STATUS) {
- if (pCurrSCCB->HostStatus == 0x00) {
- pCurrSCCB->HostStatus = SCCB_BM_ERR;
- #if defined(BUGBUG)
- WR_HARPOON(port+hp_dual_addr_lo,
- RD_HARPOON(port+hp_ext_status));
- #endif
- }
- }
- }
- if (pCurrSCCB->Sccb_XferState & F_SG_XFER) {
- WR_HARPOON(port+hp_page_ctrl, (RD_HARPOON(port+hp_page_ctrl) &
- ~SCATTER_EN));
- WR_HARPOON(port+hp_sg_addr,0x00);
- pCurrSCCB->Sccb_sgseg += SG_BUF_CNT;
- pCurrSCCB->Sccb_SGoffset = 0x00;
- if ((ULONG)(pCurrSCCB->Sccb_sgseg * SG_ELEMENT_SIZE) >=
- pCurrSCCB->DataLength) {
- pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
- pCurrSCCB->Sccb_sgseg = (USHORT)(pCurrSCCB->DataLength / SG_ELEMENT_SIZE);
- }
- }
- else {
- if (!(pCurrSCCB->Sccb_XferState & F_AUTO_SENSE))
- pCurrSCCB->Sccb_XferState |= F_ALL_XFERRED;
- }
- }
- WR_HARPOON(port+hp_int_mask,(INT_CMD_COMPL | SCSI_INTERRUPT));
- }
- /*---------------------------------------------------------------------
- *
- * Function: Host Data Transfer Restart
- *
- * Description: Reset the available count due to a restore data
- * pointers message.
- *
- *---------------------------------------------------------------------*/
- void hostDataXferRestart(PSCCB currSCCB)
- {
- ULONG data_count;
- UINT sg_index;
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- ULONG far *sg_ptr;
- #else
- ULONG *sg_ptr;
- #endif
- if (currSCCB->Sccb_XferState & F_SG_XFER) {
- currSCCB->Sccb_XferCnt = 0;
- sg_index = 0xffff; /*Index by long words into sg list. */
- data_count = 0; /*Running count of SG xfer counts. */
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- sg_ptr = (ULONG far *)currSCCB->DataPointer;
- #else
- sg_ptr = (ULONG *)currSCCB->DataPointer;
- #endif
- while (data_count < currSCCB->Sccb_ATC) {
- sg_index++;
- data_count += *(sg_ptr+(sg_index * 2));
- }
- if (data_count == currSCCB->Sccb_ATC) {
- currSCCB->Sccb_SGoffset = 0;
- sg_index++;
- }
- else {
- currSCCB->Sccb_SGoffset = data_count - currSCCB->Sccb_ATC;
- }
- currSCCB->Sccb_sgseg = (USHORT)sg_index;
- }
- else {
- currSCCB->Sccb_XferCnt = currSCCB->DataLength - currSCCB->Sccb_ATC;
- }
- }
- #ident "$Id: scam.c 1.17 1997/03/20 23:49:37 mohan Exp $"
- /*----------------------------------------------------------------------
- *
- *
- * Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
- *
- * This file is available under both the GNU General Public License
- * and a BSD-style copyright; see LICENSE.FlashPoint for details.
- *
- * $Workfile: scam.c $
- *
- * Description: Functions relating to handling of the SCAM selection
- * and the determination of the SCSI IDs to be assigned
- * to all perspective SCSI targets.
- *
- * $Date: 1997/03/20 23:49:37 $
- *
- * $Revision: 1.17 $
- *
- *----------------------------------------------------------------------*/
- /*#include <globals.h>*/
- #if (FW_TYPE==_UCB_MGR_)
- /*#include <budi.h>*/
- #endif
- /*#include <sccbmgr.h>*/
- /*#include <blx30.h>*/
- /*#include <target.h>*/
- /*#include <scsi2.h>*/
- /*#include <eeprom.h>*/
- /*#include <harpoon.h>*/
- /*
- extern SCCBMGR_TAR_INFO sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR];
- extern SCCBCARD BL_Card[MAX_CARDS];
- extern SCCBSCAM_INFO scamInfo[MAX_SCSI_TAR];
- extern NVRAMINFO nvRamInfo[MAX_MB_CARDS];
- #if defined(DOS) || defined(OS2)
- extern UCHAR temp_id_string[ID_STRING_LENGTH];
- #endif
- extern UCHAR scamHAString[];
- */
- /*---------------------------------------------------------------------
- *
- * Function: scini
- *
- * Description: Setup all data structures necessary for SCAM selection.
- *
- *---------------------------------------------------------------------*/
- void scini(UCHAR p_card, UCHAR p_our_id, UCHAR p_power_up)
- {
- #if defined(SCAM_LEV_2)
- UCHAR loser,assigned_id;
- #endif
- #if defined(DOS)
- USHORT p_port;
- #else
- ULONG p_port;
- #endif
- UCHAR i,k,ScamFlg ;
- PSCCBcard currCard;
- PNVRamInfo pCurrNvRam;
- currCard = &BL_Card[p_card];
- p_port = currCard->ioPort;
- pCurrNvRam = currCard->pNvRamInfo;
- if(pCurrNvRam){
- ScamFlg = pCurrNvRam->niScamConf;
- i = pCurrNvRam->niSysConf;
- }
- else{
- ScamFlg = (UCHAR) utilEERead(p_port, SCAM_CONFIG/2);
- i = (UCHAR)(utilEERead(p_port, (SYSTEM_CONFIG/2)));
- }
- if(!(i & 0x02)) /* check if reset bus in AutoSCSI parameter set */
- return;
- inisci(p_card,p_port, p_our_id);
- /* Force to wait 1 sec after SCSI bus reset. Some SCAM device FW
- too slow to return to SCAM selection */
- /* if (p_power_up)
- Wait1Second(p_port);
- else
- Wait(p_port, TO_250ms); */
- Wait1Second(p_port);
- #if defined(SCAM_LEV_2)
- if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
- {
- while (!(scarb(p_port,INIT_SELTD))) {}
- scsel(p_port);
- do {
- scxferc(p_port,SYNC_PTRN);
- scxferc(p_port,DOM_MSTR);
- loser = scsendi(p_port,&scamInfo[p_our_id].id_string[0]);
- } while ( loser == 0xFF );
- scbusf(p_port);
- if ((p_power_up) && (!loser))
- {
- sresb(p_port,p_card);
- Wait(p_port, TO_250ms);
- while (!(scarb(p_port,INIT_SELTD))) {}
- scsel(p_port);
- do {
- scxferc(p_port, SYNC_PTRN);
- scxferc(p_port, DOM_MSTR);
- loser = scsendi(p_port,&scamInfo[p_our_id].
- id_string[0]);
- } while ( loser == 0xFF );
- scbusf(p_port);
- }
- }
- else
- {
- loser = FALSE;
- }
- if (!loser)
- {
- #endif /* SCAM_LEV_2 */
- scamInfo[p_our_id].state = ID_ASSIGNED;
- if (ScamFlg & SCAM_ENABLED)
- {
- for (i=0; i < MAX_SCSI_TAR; i++)
- {
- if ((scamInfo[i].state == ID_UNASSIGNED) ||
- (scamInfo[i].state == ID_UNUSED))
- {
- if (scsell(p_port,i))
- {
- scamInfo[i].state = LEGACY;
- if ((scamInfo[i].id_string[0] != 0xFF) ||
- (scamInfo[i].id_string[1] != 0xFA))
- {
- scamInfo[i].id_string[0] = 0xFF;
- scamInfo[i].id_string[1] = 0xFA;
- if(pCurrNvRam == NULL)
- currCard->globalFlags |= F_UPDATE_EEPROM;
- }
- }
- }
- }
- sresb(p_port,p_card);
- Wait1Second(p_port);
- while (!(scarb(p_port,INIT_SELTD))) {}
- scsel(p_port);
- scasid(p_card, p_port);
- }
- #if defined(SCAM_LEV_2)
- }
- else if ((loser) && (ScamFlg & SCAM_ENABLED))
- {
- scamInfo[p_our_id].id_string[0] = SLV_TYPE_CODE0;
- assigned_id = FALSE;
- scwtsel(p_port);
- do {
- while (scxferc(p_port,0x00) != SYNC_PTRN) {}
- i = scxferc(p_port,0x00);
- if (i == ASSIGN_ID)
- {
- if (!(scsendi(p_port,&scamInfo[p_our_id].id_string[0])))
- {
- i = scxferc(p_port,0x00);
- if (scvalq(i))
- {
- k = scxferc(p_port,0x00);
- if (scvalq(k))
- {
- currCard->ourId =
- ((UCHAR)(i<<3)+(k & (UCHAR)7)) & (UCHAR) 0x3F;
- inisci(p_card, p_port, p_our_id);
- scamInfo[currCard->ourId].state = ID_ASSIGNED;
- scamInfo[currCard->ourId].id_string[0]
- = SLV_TYPE_CODE0;
- assigned_id = TRUE;
- }
- }
- }
- }
- else if (i == SET_P_FLAG)
- {
- if (!(scsendi(p_port,
- &scamInfo[p_our_id].id_string[0])))
- scamInfo[p_our_id].id_string[0] |= 0x80;
- }
- }while (!assigned_id);
- while (scxferc(p_port,0x00) != CFG_CMPLT) {}
- }
- #endif /* SCAM_LEV_2 */
- if (ScamFlg & SCAM_ENABLED)
- {
- scbusf(p_port);
- if (currCard->globalFlags & F_UPDATE_EEPROM)
- {
- scsavdi(p_card, p_port);
- currCard->globalFlags &= ~F_UPDATE_EEPROM;
- }
- }
- #if defined(DOS)
- for (i=0; i < MAX_SCSI_TAR; i++)
- {
- if (((ScamFlg & SCAM_ENABLED) && (scamInfo[i].state == LEGACY))
- || (i != p_our_id))
- {
- scsellDOS(p_port,i);
- }
- }
- #endif
- /*
- for (i=0,k=0; i < MAX_SCSI_TAR; i++)
- {
- if ((scamInfo[i].state == ID_ASSIGNED) ||
- (scamInfo[i].state == LEGACY))
- k++;
- }
- if (k==2)
- currCard->globalFlags |= F_SINGLE_DEVICE;
- else
- currCard->globalFlags &= ~F_SINGLE_DEVICE;
- */
- }
- /*---------------------------------------------------------------------
- *
- * Function: scarb
- *
- * Description: Gain control of the bus and wait SCAM select time (250ms)
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- int scarb(USHORT p_port, UCHAR p_sel_type)
- #else
- int scarb(ULONG p_port, UCHAR p_sel_type)
- #endif
- {
- if (p_sel_type == INIT_SELTD)
- {
- while (RD_HARPOON(p_port+hp_scsisig) & (SCSI_SEL | SCSI_BSY)) {}
- if (RD_HARPOON(p_port+hp_scsisig) & SCSI_SEL)
- return(FALSE);
- if (RD_HARPOON(p_port+hp_scsidata_0) != 00)
- return(FALSE);
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_BSY));
- if (RD_HARPOON(p_port+hp_scsisig) & SCSI_SEL) {
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) &
- ~SCSI_BSY));
- return(FALSE);
- }
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_SEL));
- if (RD_HARPOON(p_port+hp_scsidata_0) != 00) {
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) &
- ~(SCSI_BSY | SCSI_SEL)));
- return(FALSE);
- }
- }
- WR_HARPOON(p_port+hp_clkctrl_0, (RD_HARPOON(p_port+hp_clkctrl_0)
- & ~ACTdeassert));
- WR_HARPOON(p_port+hp_scsireset, SCAM_EN);
- WR_HARPOON(p_port+hp_scsidata_0, 0x00);
- #if defined(WIDE_SCSI)
- WR_HARPOON(p_port+hp_scsidata_1, 0x00);
- #endif
- WR_HARPOON(p_port+hp_portctrl_0, SCSI_BUS_EN);
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig) | SCSI_MSG));
- WR_HARPOON(p_port+hp_scsisig, (RD_HARPOON(p_port+hp_scsisig)
- & ~SCSI_BSY));
- Wait(p_port,TO_250ms);
- return(TRUE);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scbusf
- *
- * Description: Release the SCSI bus and disable SCAM selection.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scbusf(USHORT p_port)
- #else
- void scbusf(ULONG p_port)
- #endif
- {
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE));
- WR_HARPOON(p_port+hp_scsidata_0, 0x00);
- WR_HARPOON(p_port+hp_portctrl_0, (RD_HARPOON(p_port+hp_portctrl_0)
- & ~SCSI_BUS_EN));
- WR_HARPOON(p_port+hp_scsisig, 0x00);
- WR_HARPOON(p_port+hp_scsireset, (RD_HARPOON(p_port+hp_scsireset)
- & ~SCAM_EN));
- WR_HARPOON(p_port+hp_clkctrl_0, (RD_HARPOON(p_port+hp_clkctrl_0)
- | ACTdeassert));
- #if defined(SCAM_LEV_2)
- WRW_HARPOON((p_port+hp_intstat), (BUS_FREE | AUTO_INT | SCAM_SEL));
- #else
- WRW_HARPOON((p_port+hp_intstat), (BUS_FREE | AUTO_INT));
- #endif
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
- }
- /*---------------------------------------------------------------------
- *
- * Function: scasid
- *
- * Description: Assign an ID to all the SCAM devices.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scasid(UCHAR p_card, USHORT p_port)
- #else
- void scasid(UCHAR p_card, ULONG p_port)
- #endif
- {
- #if defined(DOS) || defined(OS2)
- /* Use external defined in global space area, instead of Stack
- space. WIN/95 DOS doesnot work TINY mode. The OS doesnot intialize
- SS equal to DS. Thus the array allocated on stack doesnot get
- access correctly */
- #else
- UCHAR temp_id_string[ID_STRING_LENGTH];
- #endif
- UCHAR i,k,scam_id;
- UCHAR crcBytes[3];
- PNVRamInfo pCurrNvRam;
- ushort_ptr pCrcBytes;
- pCurrNvRam = BL_Card[p_card].pNvRamInfo;
- i=FALSE;
- while (!i)
- {
- for (k=0; k < ID_STRING_LENGTH; k++)
- {
- temp_id_string[k] = (UCHAR) 0x00;
- }
- scxferc(p_port,SYNC_PTRN);
- scxferc(p_port,ASSIGN_ID);
- if (!(sciso(p_port,&temp_id_string[0])))
- {
- if(pCurrNvRam){
- pCrcBytes = (ushort_ptr)&crcBytes[0];
- *pCrcBytes = CalcCrc16(&temp_id_string[0]);
- crcBytes[2] = CalcLrc(&temp_id_string[0]);
- temp_id_string[1] = crcBytes[2];
- temp_id_string[2] = crcBytes[0];
- temp_id_string[3] = crcBytes[1];
- for(k = 4; k < ID_STRING_LENGTH; k++)
- temp_id_string[k] = (UCHAR) 0x00;
- }
- i = scmachid(p_card,temp_id_string);
- if (i == CLR_PRIORITY)
- {
- scxferc(p_port,MISC_CODE);
- scxferc(p_port,CLR_P_FLAG);
- i = FALSE; /*Not the last ID yet. */
- }
- else if (i != NO_ID_AVAIL)
- {
- if (i < 8 )
- scxferc(p_port,ID_0_7);
- else
- scxferc(p_port,ID_8_F);
- scam_id = (i & (UCHAR) 0x07);
- for (k=1; k < 0x08; k <<= 1)
- if (!( k & i ))
- scam_id += 0x08; /*Count number of zeros in DB0-3. */
- scxferc(p_port,scam_id);
- i = FALSE; /*Not the last ID yet. */
- }
- }
- else
- {
- i = TRUE;
- }
- } /*End while */
- scxferc(p_port,SYNC_PTRN);
- scxferc(p_port,CFG_CMPLT);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scsel
- *
- * Description: Select all the SCAM devices.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scsel(USHORT p_port)
- #else
- void scsel(ULONG p_port)
- #endif
- {
- WR_HARPOON(p_port+hp_scsisig, SCSI_SEL);
- scwiros(p_port, SCSI_MSG);
- WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY));
- WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
- WR_HARPOON(p_port+hp_scsidata_0, (UCHAR)(RD_HARPOON(p_port+hp_scsidata_0) |
- (UCHAR)(BIT(7)+BIT(6))));
- WR_HARPOON(p_port+hp_scsisig, (SCSI_BSY | SCSI_IOBIT | SCSI_CD));
- scwiros(p_port, SCSI_SEL);
- WR_HARPOON(p_port+hp_scsidata_0, (UCHAR)(RD_HARPOON(p_port+hp_scsidata_0) &
- ~(UCHAR)BIT(6)));
- scwirod(p_port, BIT(6));
- WR_HARPOON(p_port+hp_scsisig, (SCSI_SEL | SCSI_BSY | SCSI_IOBIT | SCSI_CD));
- }
- /*---------------------------------------------------------------------
- *
- * Function: scxferc
- *
- * Description: Handshake the p_data (DB4-0) across the bus.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- UCHAR scxferc(USHORT p_port, UCHAR p_data)
- #else
- UCHAR scxferc(ULONG p_port, UCHAR p_data)
- #endif
- {
- UCHAR curr_data, ret_data;
- curr_data = p_data | BIT(7) | BIT(5); /*Start with DB7 & DB5 asserted. */
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- curr_data &= ~BIT(7);
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- scwirod(p_port,BIT(7)); /*Wait for DB7 to be released. */
- while (!(RD_HARPOON(p_port+hp_scsidata_0) & BIT(5)));
- ret_data = (RD_HARPOON(p_port+hp_scsidata_0) & (UCHAR) 0x1F);
- curr_data |= BIT(6);
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- curr_data &= ~BIT(5);
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- scwirod(p_port,BIT(5)); /*Wait for DB5 to be released. */
- curr_data &= ~(BIT(4)|BIT(3)|BIT(2)|BIT(1)|BIT(0)); /*Release data bits */
- curr_data |= BIT(7);
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- curr_data &= ~BIT(6);
- WR_HARPOON(p_port+hp_scsidata_0, curr_data);
- scwirod(p_port,BIT(6)); /*Wait for DB6 to be released. */
- return(ret_data);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scsendi
- *
- * Description: Transfer our Identification string to determine if we
- * will be the dominant master.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- UCHAR scsendi(USHORT p_port, UCHAR p_id_string[])
- #else
- UCHAR scsendi(ULONG p_port, UCHAR p_id_string[])
- #endif
- {
- UCHAR ret_data,byte_cnt,bit_cnt,defer;
- defer = FALSE;
- for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
- for (bit_cnt = 0x80; bit_cnt != 0 ; bit_cnt >>= 1) {
- if (defer)
- ret_data = scxferc(p_port,00);
- else if (p_id_string[byte_cnt] & bit_cnt)
- ret_data = scxferc(p_port,02);
- else {
- ret_data = scxferc(p_port,01);
- if (ret_data & 02)
- defer = TRUE;
- }
- if ((ret_data & 0x1C) == 0x10)
- return(0x00); /*End of isolation stage, we won! */
- if (ret_data & 0x1C)
- return(0xFF);
- if ((defer) && (!(ret_data & 0x1F)))
- return(0x01); /*End of isolation stage, we lost. */
- } /*bit loop */
- } /*byte loop */
- if (defer)
- return(0x01); /*We lost */
- else
- return(0); /*We WON! Yeeessss! */
- }
- /*---------------------------------------------------------------------
- *
- * Function: sciso
- *
- * Description: Transfer the Identification string.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- UCHAR sciso(USHORT p_port, UCHAR p_id_string[])
- #else
- UCHAR sciso(ULONG p_port, UCHAR p_id_string[])
- #endif
- {
- UCHAR ret_data,the_data,byte_cnt,bit_cnt;
- the_data = 0;
- for (byte_cnt = 0; byte_cnt < ID_STRING_LENGTH; byte_cnt++) {
- for (bit_cnt = 0; bit_cnt < 8; bit_cnt++) {
- ret_data = scxferc(p_port,0);
- if (ret_data & 0xFC)
- return(0xFF);
- else {
- the_data <<= 1;
- if (ret_data & BIT(1)) {
- the_data |= 1;
- }
- }
- if ((ret_data & 0x1F) == 0)
- {
- /*
- if(bit_cnt != 0 || bit_cnt != 8)
- {
- byte_cnt = 0;
- bit_cnt = 0;
- scxferc(p_port, SYNC_PTRN);
- scxferc(p_port, ASSIGN_ID);
- continue;
- }
- */
- if (byte_cnt)
- return(0x00);
- else
- return(0xFF);
- }
- } /*bit loop */
- p_id_string[byte_cnt] = the_data;
- } /*byte loop */
- return(0);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scwirod
- *
- * Description: Sample the SCSI data bus making sure the signal has been
- * deasserted for the correct number of consecutive samples.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scwirod(USHORT p_port, UCHAR p_data_bit)
- #else
- void scwirod(ULONG p_port, UCHAR p_data_bit)
- #endif
- {
- UCHAR i;
- i = 0;
- while ( i < MAX_SCSI_TAR ) {
- if (RD_HARPOON(p_port+hp_scsidata_0) & p_data_bit)
- i = 0;
- else
- i++;
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: scwiros
- *
- * Description: Sample the SCSI Signal lines making sure the signal has been
- * deasserted for the correct number of consecutive samples.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scwiros(USHORT p_port, UCHAR p_data_bit)
- #else
- void scwiros(ULONG p_port, UCHAR p_data_bit)
- #endif
- {
- UCHAR i;
- i = 0;
- while ( i < MAX_SCSI_TAR ) {
- if (RD_HARPOON(p_port+hp_scsisig) & p_data_bit)
- i = 0;
- else
- i++;
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: scvalq
- *
- * Description: Make sure we received a valid data byte.
- *
- *---------------------------------------------------------------------*/
- UCHAR scvalq(UCHAR p_quintet)
- {
- UCHAR count;
- for (count=1; count < 0x08; count<<=1) {
- if (!(p_quintet & count))
- p_quintet -= 0x80;
- }
- if (p_quintet & 0x18)
- return(FALSE);
- else
- return(TRUE);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scsell
- *
- * Description: Select the specified device ID using a selection timeout
- * less than 4ms. If somebody responds then it is a legacy
- * drive and this ID must be marked as such.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- UCHAR scsell(USHORT p_port, UCHAR targ_id)
- #else
- UCHAR scsell(ULONG p_port, UCHAR targ_id)
- #endif
- {
- #if defined(DOS)
- USHORT i;
- #else
- ULONG i;
- #endif
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE));
- ARAM_ACCESS(p_port);
- WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) | SCAM_TIMER));
- WR_HARPOON(p_port+hp_seltimeout,TO_4ms);
- for (i = p_port+CMD_STRT; i < p_port+CMD_STRT+12; i+=2) {
- WRW_HARPOON(i, (MPM_OP+ACOMMAND));
- }
- WRW_HARPOON(i, (BRH_OP+ALWAYS+ NP));
- WRW_HARPOON((p_port+hp_intstat),
- (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
- WR_HARPOON(p_port+hp_select_id, targ_id);
- WR_HARPOON(p_port+hp_portctrl_0, SCSI_PORT);
- WR_HARPOON(p_port+hp_autostart_3, (SELECT | CMD_ONLY_STRT));
- WR_HARPOON(p_port+hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
- while (!(RDW_HARPOON((p_port+hp_intstat)) &
- (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {}
- if (RDW_HARPOON((p_port+hp_intstat)) & RESET)
- Wait(p_port, TO_250ms);
- DISABLE_AUTO(p_port);
- WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) & ~SCAM_TIMER));
- WR_HARPOON(p_port+hp_seltimeout,TO_290ms);
- SGRAM_ACCESS(p_port);
- if (RDW_HARPOON((p_port+hp_intstat)) & (RESET | TIMEOUT) ) {
- WRW_HARPOON((p_port+hp_intstat),
- (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
- return(FALSE); /*No legacy device */
- }
- else {
- while(!(RDW_HARPOON((p_port+hp_intstat)) & BUS_FREE)) {
- if (RD_HARPOON(p_port+hp_scsisig) & SCSI_REQ)
- {
- WR_HARPOON(p_port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
- ACCEPT_MSG(p_port);
- }
- }
- WRW_HARPOON((p_port+hp_intstat), CLR_ALL_INT_1);
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
- return(TRUE); /*Found one of them oldies! */
- }
- }
- #if defined(DOS)
- /*---------------------------------------------------------------------
- *
- * Function: scsell for DOS
- *
- * Description: Select the specified device ID using a selection timeout
- * less than 2ms. This was specially required to solve
- * the problem with Plextor 12X CD-ROM drive. This drive
- * was responding the Selection at the end of 4ms and
- * hanging the system.
- *
- *---------------------------------------------------------------------*/
- UCHAR scsellDOS(USHORT p_port, UCHAR targ_id)
- {
- USHORT i;
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) | G_INT_DISABLE));
- ARAM_ACCESS(p_port);
- WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) | SCAM_TIMER));
- WR_HARPOON(p_port+hp_seltimeout,TO_2ms);
- for (i = p_port+CMD_STRT; i < p_port+CMD_STRT+12; i+=2) {
- WRW_HARPOON(i, (MPM_OP+ACOMMAND));
- }
- WRW_HARPOON(i, (BRH_OP+ALWAYS+ NP));
- WRW_HARPOON((p_port+hp_intstat),
- (RESET | TIMEOUT | SEL | BUS_FREE | AUTO_INT));
- WR_HARPOON(p_port+hp_select_id, targ_id);
- WR_HARPOON(p_port+hp_portctrl_0, SCSI_PORT);
- WR_HARPOON(p_port+hp_autostart_3, (SELECT | CMD_ONLY_STRT));
- WR_HARPOON(p_port+hp_scsictrl_0, (SEL_TAR | ENA_RESEL));
- while (!(RDW_HARPOON((p_port+hp_intstat)) &
- (RESET | PROG_HLT | TIMEOUT | AUTO_INT))) {}
- if (RDW_HARPOON((p_port+hp_intstat)) & RESET)
- Wait(p_port, TO_250ms);
- DISABLE_AUTO(p_port);
- WR_HARPOON(p_port+hp_addstat,(RD_HARPOON(p_port+hp_addstat) & ~SCAM_TIMER));
- WR_HARPOON(p_port+hp_seltimeout,TO_290ms);
- SGRAM_ACCESS(p_port);
- if (RDW_HARPOON((p_port+hp_intstat)) & (RESET | TIMEOUT) ) {
- WRW_HARPOON((p_port+hp_intstat),
- (RESET | TIMEOUT | SEL | BUS_FREE | PHASE));
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
- return(FALSE); /*No legacy device */
- }
- else {
- while(!(RDW_HARPOON((p_port+hp_intstat)) & BUS_FREE)) {
- if (RD_HARPOON(p_port+hp_scsisig) & SCSI_REQ)
- {
- WR_HARPOON(p_port+hp_scsisig, (SCSI_ACK + S_ILL_PH));
- ACCEPT_MSG(p_port);
- }
- }
- WRW_HARPOON((p_port+hp_intstat), CLR_ALL_INT_1);
- WR_HARPOON(p_port+hp_page_ctrl,
- (RD_HARPOON(p_port+hp_page_ctrl) & ~G_INT_DISABLE));
- return(TRUE); /*Found one of them oldies! */
- }
- }
- #endif /* DOS */
- /*---------------------------------------------------------------------
- *
- * Function: scwtsel
- *
- * Description: Wait to be selected by another SCAM initiator.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scwtsel(USHORT p_port)
- #else
- void scwtsel(ULONG p_port)
- #endif
- {
- while(!(RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL)) {}
- }
- /*---------------------------------------------------------------------
- *
- * Function: inisci
- *
- * Description: Setup the data Structure with the info from the EEPROM.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void inisci(UCHAR p_card, USHORT p_port, UCHAR p_our_id)
- #else
- void inisci(UCHAR p_card, ULONG p_port, UCHAR p_our_id)
- #endif
- {
- UCHAR i,k,max_id;
- USHORT ee_data;
- PNVRamInfo pCurrNvRam;
- pCurrNvRam = BL_Card[p_card].pNvRamInfo;
- if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
- max_id = 0x08;
- else
- max_id = 0x10;
- if(pCurrNvRam){
- for(i = 0; i < max_id; i++){
- for(k = 0; k < 4; k++)
- scamInfo[i].id_string[k] = pCurrNvRam->niScamTbl[i][k];
- for(k = 4; k < ID_STRING_LENGTH; k++)
- scamInfo[i].id_string[k] = (UCHAR) 0x00;
- if(scamInfo[i].id_string[0] == 0x00)
- scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
- else
- scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
- }
- }else {
- for (i=0; i < max_id; i++)
- {
- for (k=0; k < ID_STRING_LENGTH; k+=2)
- {
- ee_data = utilEERead(p_port, (USHORT)((EE_SCAMBASE/2) +
- (USHORT) (i*((USHORT)ID_STRING_LENGTH/2)) + (USHORT)(k/2)));
- scamInfo[i].id_string[k] = (UCHAR) ee_data;
- ee_data >>= 8;
- scamInfo[i].id_string[k+1] = (UCHAR) ee_data;
- }
- if ((scamInfo[i].id_string[0] == 0x00) ||
- (scamInfo[i].id_string[0] == 0xFF))
- scamInfo[i].state = ID_UNUSED; /*Default to unused ID. */
- else
- scamInfo[i].state = ID_UNASSIGNED; /*Default to unassigned ID. */
- }
- }
- for(k = 0; k < ID_STRING_LENGTH; k++)
- scamInfo[p_our_id].id_string[k] = scamHAString[k];
- }
- /*---------------------------------------------------------------------
- *
- * Function: scmachid
- *
- * Description: Match the Device ID string with our values stored in
- * the EEPROM.
- *
- *---------------------------------------------------------------------*/
- UCHAR scmachid(UCHAR p_card, UCHAR p_id_string[])
- {
- UCHAR i,k,match;
- for (i=0; i < MAX_SCSI_TAR; i++) {
- #if !defined(SCAM_LEV_2)
- if (scamInfo[i].state == ID_UNASSIGNED)
- {
- #endif
- match = TRUE;
- for (k=0; k < ID_STRING_LENGTH; k++)
- {
- if (p_id_string[k] != scamInfo[i].id_string[k])
- match = FALSE;
- }
- if (match)
- {
- scamInfo[i].state = ID_ASSIGNED;
- return(i);
- }
- #if !defined(SCAM_LEV_2)
- }
- #endif
- }
- if (p_id_string[0] & BIT(5))
- i = 8;
- else
- i = MAX_SCSI_TAR;
- if (((p_id_string[0] & 0x06) == 0x02) || ((p_id_string[0] & 0x06) == 0x04))
- match = p_id_string[1] & (UCHAR) 0x1F;
- else
- match = 7;
- while (i > 0)
- {
- i--;
- if (scamInfo[match].state == ID_UNUSED)
- {
- for (k=0; k < ID_STRING_LENGTH; k++)
- {
- scamInfo[match].id_string[k] = p_id_string[k];
- }
- scamInfo[match].state = ID_ASSIGNED;
- if(BL_Card[p_card].pNvRamInfo == NULL)
- BL_Card[p_card].globalFlags |= F_UPDATE_EEPROM;
- return(match);
- }
- match--;
- if (match == 0xFF)
- {
- if (p_id_string[0] & BIT(5))
- match = 7;
- else
- match = MAX_SCSI_TAR-1;
- }
- }
- if (p_id_string[0] & BIT(7))
- {
- return(CLR_PRIORITY);
- }
- if (p_id_string[0] & BIT(5))
- i = 8;
- else
- i = MAX_SCSI_TAR;
- if (((p_id_string[0] & 0x06) == 0x02) || ((p_id_string[0] & 0x06) == 0x04))
- match = p_id_string[1] & (UCHAR) 0x1F;
- else
- match = 7;
- while (i > 0)
- {
- i--;
- if (scamInfo[match].state == ID_UNASSIGNED)
- {
- for (k=0; k < ID_STRING_LENGTH; k++)
- {
- scamInfo[match].id_string[k] = p_id_string[k];
- }
- scamInfo[match].id_string[0] |= BIT(7);
- scamInfo[match].state = ID_ASSIGNED;
- if(BL_Card[p_card].pNvRamInfo == NULL)
- BL_Card[p_card].globalFlags |= F_UPDATE_EEPROM;
- return(match);
- }
- match--;
- if (match == 0xFF)
- {
- if (p_id_string[0] & BIT(5))
- match = 7;
- else
- match = MAX_SCSI_TAR-1;
- }
- }
- return(NO_ID_AVAIL);
- }
- /*---------------------------------------------------------------------
- *
- * Function: scsavdi
- *
- * Description: Save off the device SCAM ID strings.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void scsavdi(UCHAR p_card, USHORT p_port)
- #else
- void scsavdi(UCHAR p_card, ULONG p_port)
- #endif
- {
- UCHAR i,k,max_id;
- USHORT ee_data,sum_data;
- sum_data = 0x0000;
- for (i = 1; i < EE_SCAMBASE/2; i++)
- {
- sum_data += utilEERead(p_port, i);
- }
- utilEEWriteOnOff(p_port,1); /* Enable write access to the EEPROM */
- if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
- max_id = 0x08;
- else
- max_id = 0x10;
- for (i=0; i < max_id; i++)
- {
- for (k=0; k < ID_STRING_LENGTH; k+=2)
- {
- ee_data = scamInfo[i].id_string[k+1];
- ee_data <<= 8;
- ee_data |= scamInfo[i].id_string[k];
- sum_data += ee_data;
- utilEEWrite(p_port, ee_data, (USHORT)((EE_SCAMBASE/2) +
- (USHORT)(i*((USHORT)ID_STRING_LENGTH/2)) + (USHORT)(k/2)));
- }
- }
- utilEEWrite(p_port, sum_data, EEPROM_CHECK_SUM/2);
- utilEEWriteOnOff(p_port,0); /* Turn off write access */
- }
- #ident "$Id: diagnose.c 1.10 1997/06/10 16:51:47 mohan Exp $"
- /*----------------------------------------------------------------------
- *
- *
- * Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
- *
- * This file is available under both the GNU General Public License
- * and a BSD-style copyright; see LICENSE.FlashPoint for details.
- *
- * $Workfile: diagnose.c $
- *
- * Description: Diagnostic funtions for testing the integrity of
- * the HARPOON.
- *
- * $Date: 1997/06/10 16:51:47 $
- *
- * $Revision: 1.10 $
- *
- *----------------------------------------------------------------------*/
- /*#include <globals.h>*/
- #if (FW_TYPE==_UCB_MGR_)
- /*#include <budi.h>*/
- #endif
- /*#include <sccbmgr.h>*/
- /*#include <blx30.h>*/
- /*#include <target.h>*/
- /*#include <eeprom.h>*/
- /*#include <harpoon.h>*/
- /*---------------------------------------------------------------------
- *
- * Function: XbowInit
- *
- * Description: Setup the Xbow for normal operation.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void XbowInit(USHORT port, UCHAR ScamFlg)
- #else
- void XbowInit(ULONG port, UCHAR ScamFlg)
- #endif
- {
- UCHAR i;
- i = RD_HARPOON(port+hp_page_ctrl);
- WR_HARPOON(port+hp_page_ctrl, (UCHAR) (i | G_INT_DISABLE));
- WR_HARPOON(port+hp_scsireset,0x00);
- WR_HARPOON(port+hp_portctrl_1,HOST_MODE8);
- WR_HARPOON(port+hp_scsireset,(DMA_RESET | HPSCSI_RESET | PROG_RESET |
- FIFO_CLR));
- WR_HARPOON(port+hp_scsireset,SCSI_INI);
- WR_HARPOON(port+hp_clkctrl_0,CLKCTRL_DEFAULT);
- WR_HARPOON(port+hp_scsisig,0x00); /* Clear any signals we might */
- WR_HARPOON(port+hp_scsictrl_0,ENA_SCAM_SEL);
- WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
- #if defined(SCAM_LEV_2)
- default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
- BUS_FREE | XFER_CNT_0 | AUTO_INT;
- if ((ScamFlg & SCAM_ENABLED) && (ScamFlg & SCAM_LEVEL2))
- default_intena |= SCAM_SEL;
- #else
- default_intena = RESET | RSEL | PROG_HLT | TIMEOUT |
- BUS_FREE | XFER_CNT_0 | AUTO_INT;
- #endif
- WRW_HARPOON((port+hp_intena), default_intena);
- WR_HARPOON(port+hp_seltimeout,TO_290ms);
- /* Turn on SCSI_MODE8 for narrow cards to fix the
- strapping issue with the DUAL CHANNEL card */
- if (RD_HARPOON(port+hp_page_ctrl) & NARROW_SCSI_CARD)
- WR_HARPOON(port+hp_addstat,SCSI_MODE8);
- #if defined(NO_BIOS_OPTION)
- WR_HARPOON(port+hp_synctarg_0,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_1,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_2,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_3,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_4,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_5,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_6,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_7,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_8,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_9,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_10,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_11,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_12,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_13,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_14,NARROW_SCSI);
- WR_HARPOON(port+hp_synctarg_15,NARROW_SCSI);
- #endif
- WR_HARPOON(port+hp_page_ctrl, i);
- }
- /*---------------------------------------------------------------------
- *
- * Function: BusMasterInit
- *
- * Description: Initialize the BusMaster for normal operations.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void BusMasterInit(USHORT p_port)
- #else
- void BusMasterInit(ULONG p_port)
- #endif
- {
- WR_HARPOON(p_port+hp_sys_ctrl, DRVR_RST);
- WR_HARPOON(p_port+hp_sys_ctrl, 0x00);
- WR_HARPOON(p_port+hp_host_blk_cnt, XFER_BLK64);
- WR_HARPOON(p_port+hp_bm_ctrl, (BMCTRL_DEFAULT));
- WR_HARPOON(p_port+hp_ee_ctrl, (SCSI_TERM_ENA_H));
- #if defined(NT)
- WR_HARPOON(p_port+hp_pci_cmd_cfg, (RD_HARPOON(p_port+hp_pci_cmd_cfg)
- & ~MEM_SPACE_ENA));
- #endif
- RD_HARPOON(p_port+hp_int_status); /*Clear interrupts. */
- WR_HARPOON(p_port+hp_int_mask, (INT_CMD_COMPL | SCSI_INTERRUPT));
- WR_HARPOON(p_port+hp_page_ctrl, (RD_HARPOON(p_port+hp_page_ctrl) &
- ~SCATTER_EN));
- }
- /*---------------------------------------------------------------------
- *
- * Function: DiagXbow
- *
- * Description: Test Xbow integrity. Non-zero return indicates an error.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- int DiagXbow(USHORT port)
- #else
- int DiagXbow(ULONG port)
- #endif
- {
- unsigned char fifo_cnt,loop_cnt;
- unsigned char fifodata[5];
- fifodata[0] = 0x00;
- fifodata[1] = 0xFF;
- fifodata[2] = 0x55;
- fifodata[3] = 0xAA;
- fifodata[4] = 0x00;
- WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
- WRW_HARPOON((port+hp_intena), 0x0000);
- WR_HARPOON(port+hp_seltimeout,TO_5ms);
- WR_HARPOON(port+hp_portctrl_0,START_TO);
- for(fifodata[4] = 0x01; fifodata[4] != (UCHAR) 0; fifodata[4] = fifodata[4] << 1) {
- WR_HARPOON(port+hp_selfid_0,fifodata[4]);
- WR_HARPOON(port+hp_selfid_1,fifodata[4]);
- if ((RD_HARPOON(port+hp_selfid_0) != fifodata[4]) ||
- (RD_HARPOON(port+hp_selfid_1) != fifodata[4]))
- return(1);
- }
- for(loop_cnt = 0; loop_cnt < 4; loop_cnt++) {
- WR_HARPOON(port+hp_portctrl_0,(HOST_PORT | HOST_WRT | START_TO));
- for (fifo_cnt = 0; fifo_cnt < FIFO_LEN; fifo_cnt++) {
- WR_HARPOON(port+hp_fifodata_0, fifodata[loop_cnt]);
- }
- if (!(RD_HARPOON(port+hp_xferstat) & FIFO_FULL))
- return(1);
- WR_HARPOON(port+hp_portctrl_0,(HOST_PORT | START_TO));
- for (fifo_cnt = 0; fifo_cnt < FIFO_LEN; fifo_cnt++) {
- if (RD_HARPOON(port+hp_fifodata_0) != fifodata[loop_cnt])
- return(1);
- }
- if (!(RD_HARPOON(port+hp_xferstat) & FIFO_EMPTY))
- return(1);
- }
- while(!(RDW_HARPOON((port+hp_intstat)) & TIMEOUT)) {}
- WR_HARPOON(port+hp_seltimeout,TO_290ms);
- WRW_HARPOON((port+hp_intstat), CLR_ALL_INT);
- WRW_HARPOON((port+hp_intena), default_intena);
- return(0);
- }
- /*---------------------------------------------------------------------
- *
- * Function: DiagBusMaster
- *
- * Description: Test BusMaster integrity. Non-zero return indicates an
- * error.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- int DiagBusMaster(USHORT port)
- #else
- int DiagBusMaster(ULONG port)
- #endif
- {
- UCHAR testdata;
- for(testdata = (UCHAR) 1; testdata != (UCHAR)0; testdata = testdata << 1) {
- WR_HARPOON(port+hp_xfer_cnt_lo,testdata);
- WR_HARPOON(port+hp_xfer_cnt_mi,testdata);
- WR_HARPOON(port+hp_xfer_cnt_hi,testdata);
- WR_HARPOON(port+hp_host_addr_lo,testdata);
- WR_HARPOON(port+hp_host_addr_lmi,testdata);
- WR_HARPOON(port+hp_host_addr_hmi,testdata);
- WR_HARPOON(port+hp_host_addr_hi,testdata);
- if ((RD_HARPOON(port+hp_xfer_cnt_lo) != testdata) ||
- (RD_HARPOON(port+hp_xfer_cnt_mi) != testdata) ||
- (RD_HARPOON(port+hp_xfer_cnt_hi) != testdata) ||
- (RD_HARPOON(port+hp_host_addr_lo) != testdata) ||
- (RD_HARPOON(port+hp_host_addr_lmi) != testdata) ||
- (RD_HARPOON(port+hp_host_addr_hmi) != testdata) ||
- (RD_HARPOON(port+hp_host_addr_hi) != testdata))
- return(1);
- }
- RD_HARPOON(port+hp_int_status); /*Clear interrupts. */
- return(0);
- }
- /*---------------------------------------------------------------------
- *
- * Function: DiagEEPROM
- *
- * Description: Verfiy checksum and 'Key' and initialize the EEPROM if
- * neccessary.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void DiagEEPROM(USHORT p_port)
- #else
- void DiagEEPROM(ULONG p_port)
- #endif
- {
- USHORT index,temp,max_wd_cnt;
- if (RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD)
- max_wd_cnt = EEPROM_WD_CNT;
- else
- max_wd_cnt = EEPROM_WD_CNT * 2;
- temp = utilEERead(p_port, FW_SIGNATURE/2);
- if (temp == 0x4641) {
- for (index = 2; index < max_wd_cnt; index++) {
- temp += utilEERead(p_port, index);
- }
- if (temp == utilEERead(p_port, EEPROM_CHECK_SUM/2)) {
- return; /*EEPROM is Okay so return now! */
- }
- }
- utilEEWriteOnOff(p_port,(UCHAR)1);
- for (index = 0; index < max_wd_cnt; index++) {
- utilEEWrite(p_port, 0x0000, index);
- }
- temp = 0;
- utilEEWrite(p_port, 0x4641, FW_SIGNATURE/2);
- temp += 0x4641;
- utilEEWrite(p_port, 0x3920, MODEL_NUMB_0/2);
- temp += 0x3920;
- utilEEWrite(p_port, 0x3033, MODEL_NUMB_2/2);
- temp += 0x3033;
- utilEEWrite(p_port, 0x2020, MODEL_NUMB_4/2);
- temp += 0x2020;
- utilEEWrite(p_port, 0x70D3, SYSTEM_CONFIG/2);
- temp += 0x70D3;
- utilEEWrite(p_port, 0x0010, BIOS_CONFIG/2);
- temp += 0x0010;
- utilEEWrite(p_port, 0x0003, SCAM_CONFIG/2);
- temp += 0x0003;
- utilEEWrite(p_port, 0x0007, ADAPTER_SCSI_ID/2);
- temp += 0x0007;
- utilEEWrite(p_port, 0x0000, IGNORE_B_SCAN/2);
- temp += 0x0000;
- utilEEWrite(p_port, 0x0000, SEND_START_ENA/2);
- temp += 0x0000;
- utilEEWrite(p_port, 0x0000, DEVICE_ENABLE/2);
- temp += 0x0000;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL01/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL23/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL45/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL67/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBL89/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLab/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLcd/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x4242, SYNC_RATE_TBLef/2);
- temp += 0x4242;
- utilEEWrite(p_port, 0x6C46, 64/2); /*PRODUCT ID */
- temp += 0x6C46;
- utilEEWrite(p_port, 0x7361, 66/2); /* FlashPoint LT */
- temp += 0x7361;
- utilEEWrite(p_port, 0x5068, 68/2);
- temp += 0x5068;
- utilEEWrite(p_port, 0x696F, 70/2);
- temp += 0x696F;
- utilEEWrite(p_port, 0x746E, 72/2);
- temp += 0x746E;
- utilEEWrite(p_port, 0x4C20, 74/2);
- temp += 0x4C20;
- utilEEWrite(p_port, 0x2054, 76/2);
- temp += 0x2054;
- utilEEWrite(p_port, 0x2020, 78/2);
- temp += 0x2020;
- index = ((EE_SCAMBASE/2)+(7*16));
- utilEEWrite(p_port, (0x0700+TYPE_CODE0), index);
- temp += (0x0700+TYPE_CODE0);
- index++;
- utilEEWrite(p_port, 0x5542, index); /*Vendor ID code */
- temp += 0x5542; /* BUSLOGIC */
- index++;
- utilEEWrite(p_port, 0x4C53, index);
- temp += 0x4C53;
- index++;
- utilEEWrite(p_port, 0x474F, index);
- temp += 0x474F;
- index++;
- utilEEWrite(p_port, 0x4349, index);
- temp += 0x4349;
- index++;
- utilEEWrite(p_port, 0x5442, index); /*Vendor unique code */
- temp += 0x5442; /* BT- 930 */
- index++;
- utilEEWrite(p_port, 0x202D, index);
- temp += 0x202D;
- index++;
- utilEEWrite(p_port, 0x3339, index);
- temp += 0x3339;
- index++; /*Serial # */
- utilEEWrite(p_port, 0x2030, index); /* 01234567 */
- temp += 0x2030;
- index++;
- utilEEWrite(p_port, 0x5453, index);
- temp += 0x5453;
- index++;
- utilEEWrite(p_port, 0x5645, index);
- temp += 0x5645;
- index++;
- utilEEWrite(p_port, 0x2045, index);
- temp += 0x2045;
- index++;
- utilEEWrite(p_port, 0x202F, index);
- temp += 0x202F;
- index++;
- utilEEWrite(p_port, 0x4F4A, index);
- temp += 0x4F4A;
- index++;
- utilEEWrite(p_port, 0x204E, index);
- temp += 0x204E;
- index++;
- utilEEWrite(p_port, 0x3539, index);
- temp += 0x3539;
- utilEEWrite(p_port, temp, EEPROM_CHECK_SUM/2);
- utilEEWriteOnOff(p_port,(UCHAR)0);
- }
- #ident "$Id: utility.c 1.23 1997/06/10 16:55:06 mohan Exp $"
- /*----------------------------------------------------------------------
- *
- *
- * Copyright 1995-1996 by Mylex Corporation. All Rights Reserved
- *
- * This file is available under both the GNU General Public License
- * and a BSD-style copyright; see LICENSE.FlashPoint for details.
- *
- * $Workfile: utility.c $
- *
- * Description: Utility functions relating to queueing and EEPROM
- * manipulation and any other garbage functions.
- *
- * $Date: 1997/06/10 16:55:06 $
- *
- * $Revision: 1.23 $
- *
- *----------------------------------------------------------------------*/
- /*#include <globals.h>*/
- #if (FW_TYPE==_UCB_MGR_)
- /*#include <budi.h>*/
- #endif
- /*#include <sccbmgr.h>*/
- /*#include <blx30.h>*/
- /*#include <target.h>*/
- /*#include <scsi2.h>*/
- /*#include <harpoon.h>*/
- /*
- extern SCCBCARD BL_Card[MAX_CARDS];
- extern SCCBMGR_TAR_INFO sccbMgrTbl[MAX_CARDS][MAX_SCSI_TAR];
- extern unsigned int SccbGlobalFlags;
- */
- /*---------------------------------------------------------------------
- *
- * Function: Queue Search Select
- *
- * Description: Try to find a new command to execute.
- *
- *---------------------------------------------------------------------*/
- void queueSearchSelect(PSCCBcard pCurrCard, UCHAR p_card)
- {
- UCHAR scan_ptr, lun;
- PSCCBMgr_tar_info currTar_Info;
- PSCCB pOldSccb;
- scan_ptr = pCurrCard->scanIndex;
- do
- {
- currTar_Info = &sccbMgrTbl[p_card][scan_ptr];
- if((pCurrCard->globalFlags & F_CONLUN_IO) &&
- ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING))
- {
- if (currTar_Info->TarSelQ_Cnt != 0)
- {
- scan_ptr++;
- if (scan_ptr == MAX_SCSI_TAR)
- scan_ptr = 0;
-
- for(lun=0; lun < MAX_LUN; lun++)
- {
- if(currTar_Info->TarLUNBusy[lun] == FALSE)
- {
- pCurrCard->currentSCCB = currTar_Info->TarSelQ_Head;
- pOldSccb = NULL;
- while((pCurrCard->currentSCCB != NULL) &&
- (lun != pCurrCard->currentSCCB->Lun))
- {
- pOldSccb = pCurrCard->currentSCCB;
- pCurrCard->currentSCCB = (PSCCB)(pCurrCard->currentSCCB)->
- Sccb_forwardlink;
- }
- if(pCurrCard->currentSCCB == NULL)
- continue;
- if(pOldSccb != NULL)
- {
- pOldSccb->Sccb_forwardlink = (PSCCB)(pCurrCard->currentSCCB)->
- Sccb_forwardlink;
- pOldSccb->Sccb_backlink = (PSCCB)(pCurrCard->currentSCCB)->
- Sccb_backlink;
- currTar_Info->TarSelQ_Cnt--;
- }
- else
- {
- currTar_Info->TarSelQ_Head = (PSCCB)(pCurrCard->currentSCCB)->Sccb_forwardlink;
-
- if (currTar_Info->TarSelQ_Head == NULL)
- {
- currTar_Info->TarSelQ_Tail = NULL;
- currTar_Info->TarSelQ_Cnt = 0;
- }
- else
- {
- currTar_Info->TarSelQ_Cnt--;
- currTar_Info->TarSelQ_Head->Sccb_backlink = (PSCCB)NULL;
- }
- }
- pCurrCard->scanIndex = scan_ptr;
- pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
- break;
- }
- }
- }
- else
- {
- scan_ptr++;
- if (scan_ptr == MAX_SCSI_TAR) {
- scan_ptr = 0;
- }
- }
- }
- else
- {
- if ((currTar_Info->TarSelQ_Cnt != 0) &&
- (currTar_Info->TarLUNBusy[0] == FALSE))
- {
- pCurrCard->currentSCCB = currTar_Info->TarSelQ_Head;
- currTar_Info->TarSelQ_Head = (PSCCB)(pCurrCard->currentSCCB)->Sccb_forwardlink;
- if (currTar_Info->TarSelQ_Head == NULL)
- {
- currTar_Info->TarSelQ_Tail = NULL;
- currTar_Info->TarSelQ_Cnt = 0;
- }
- else
- {
- currTar_Info->TarSelQ_Cnt--;
- currTar_Info->TarSelQ_Head->Sccb_backlink = (PSCCB)NULL;
- }
- scan_ptr++;
- if (scan_ptr == MAX_SCSI_TAR)
- scan_ptr = 0;
- pCurrCard->scanIndex = scan_ptr;
- pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
- break;
- }
- else
- {
- scan_ptr++;
- if (scan_ptr == MAX_SCSI_TAR)
- {
- scan_ptr = 0;
- }
- }
- }
- } while (scan_ptr != pCurrCard->scanIndex);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Queue Select Fail
- *
- * Description: Add the current SCCB to the head of the Queue.
- *
- *---------------------------------------------------------------------*/
- void queueSelectFail(PSCCBcard pCurrCard, UCHAR p_card)
- {
- UCHAR thisTarg;
- PSCCBMgr_tar_info currTar_Info;
- if (pCurrCard->currentSCCB != NULL)
- {
- thisTarg = (UCHAR)(((PSCCB)(pCurrCard->currentSCCB))->TargID);
- currTar_Info = &sccbMgrTbl[p_card][thisTarg];
- pCurrCard->currentSCCB->Sccb_backlink = (PSCCB)NULL;
- pCurrCard->currentSCCB->Sccb_forwardlink = currTar_Info->TarSelQ_Head;
- if (currTar_Info->TarSelQ_Cnt == 0)
- {
- currTar_Info->TarSelQ_Tail = pCurrCard->currentSCCB;
- }
- else
- {
- currTar_Info->TarSelQ_Head->Sccb_backlink = pCurrCard->currentSCCB;
- }
- currTar_Info->TarSelQ_Head = pCurrCard->currentSCCB;
- pCurrCard->currentSCCB = NULL;
- currTar_Info->TarSelQ_Cnt++;
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: Queue Command Complete
- *
- * Description: Call the callback function with the current SCCB.
- *
- *---------------------------------------------------------------------*/
- void queueCmdComplete(PSCCBcard pCurrCard, PSCCB p_sccb, UCHAR p_card)
- {
- #if (FW_TYPE==_UCB_MGR_)
- u08bits SCSIcmd;
- CALL_BK_FN callback;
- PSCCBMgr_tar_info currTar_Info;
- PUCB p_ucb;
- p_ucb=p_sccb->Sccb_ucb_ptr;
- SCSIcmd = p_sccb->Cdb[0];
- if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED))
- {
- if ((p_ucb->UCB_opcode & OPC_CHK_UNDER_OVER_RUN) &&
- (p_sccb->HostStatus == SCCB_COMPLETE) &&
- (p_sccb->TargetStatus != SSCHECK))
- if ((SCSIcmd == SCSI_READ) ||
- (SCSIcmd == SCSI_WRITE) ||
- (SCSIcmd == SCSI_READ_EXTENDED) ||
- (SCSIcmd == SCSI_WRITE_EXTENDED) ||
- (SCSIcmd == SCSI_WRITE_AND_VERIFY) ||
- (SCSIcmd == SCSI_START_STOP_UNIT) ||
- (pCurrCard->globalFlags & F_NO_FILTER)
- )
- p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
- }
- p_ucb->UCB_status=SCCB_SUCCESS;
- if ((p_ucb->UCB_hbastat=p_sccb->HostStatus) || (p_ucb->UCB_scsistat=p_sccb->TargetStatus))
- {
- p_ucb->UCB_status=SCCB_ERROR;
- }
- if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
- (p_sccb->OperationCode == RESIDUAL_COMMAND))
- {
- utilUpdateResidual(p_sccb);
- p_ucb->UCB_datalen=p_sccb->DataLength;
- }
- pCurrCard->cmdCounter--;
- if (!pCurrCard->cmdCounter)
- {
- if (pCurrCard->globalFlags & F_GREEN_PC)
- {
- WR_HARPOON(pCurrCard->ioPort+hp_clkctrl_0,(PWR_DWN | CLKCTRL_DEFAULT));
- WR_HARPOON(pCurrCard->ioPort+hp_sys_ctrl, STOP_CLK);
- }
- WR_HARPOON(pCurrCard->ioPort+hp_semaphore,
- (RD_HARPOON(pCurrCard->ioPort+hp_semaphore) & ~SCCB_MGR_ACTIVE));
- }
- if(pCurrCard->discQCount != 0)
- {
- currTar_Info = &sccbMgrTbl[p_card][p_sccb->TargID];
- if(((pCurrCard->globalFlags & F_CONLUN_IO) &&
- ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_sccb->Lun]] = NULL;
- }
- else
- {
- if(p_sccb->Sccb_tag)
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
- }else
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = NULL;
- }
- }
- }
- callback = (CALL_BK_FN)p_ucb->UCB_callback;
- callback(p_ucb);
- pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
- pCurrCard->currentSCCB = NULL;
- }
- #else
- UCHAR i, SCSIcmd;
- CALL_BK_FN callback;
- PSCCBMgr_tar_info currTar_Info;
- SCSIcmd = p_sccb->Cdb[0];
- if (!(p_sccb->Sccb_XferState & F_ALL_XFERRED)) {
- if ((p_sccb->ControlByte & (SCCB_DATA_XFER_OUT | SCCB_DATA_XFER_IN)) &&
- (p_sccb->HostStatus == SCCB_COMPLETE) &&
- (p_sccb->TargetStatus != SSCHECK))
- if ((SCSIcmd == SCSI_READ) ||
- (SCSIcmd == SCSI_WRITE) ||
- (SCSIcmd == SCSI_READ_EXTENDED) ||
- (SCSIcmd == SCSI_WRITE_EXTENDED) ||
- (SCSIcmd == SCSI_WRITE_AND_VERIFY) ||
- (SCSIcmd == SCSI_START_STOP_UNIT) ||
- (pCurrCard->globalFlags & F_NO_FILTER)
- )
- p_sccb->HostStatus = SCCB_DATA_UNDER_RUN;
- }
- if(p_sccb->SccbStatus == SCCB_IN_PROCESS)
- {
- if (p_sccb->HostStatus || p_sccb->TargetStatus)
- p_sccb->SccbStatus = SCCB_ERROR;
- else
- p_sccb->SccbStatus = SCCB_SUCCESS;
- }
- if (p_sccb->Sccb_XferState & F_AUTO_SENSE) {
- p_sccb->CdbLength = p_sccb->Save_CdbLen;
- for (i=0; i < 6; i++) {
- p_sccb->Cdb[i] = p_sccb->Save_Cdb[i];
- }
- }
- if ((p_sccb->OperationCode == RESIDUAL_SG_COMMAND) ||
- (p_sccb->OperationCode == RESIDUAL_COMMAND)) {
- utilUpdateResidual(p_sccb);
- }
- pCurrCard->cmdCounter--;
- if (!pCurrCard->cmdCounter) {
- if (pCurrCard->globalFlags & F_GREEN_PC) {
- WR_HARPOON(pCurrCard->ioPort+hp_clkctrl_0,(PWR_DWN | CLKCTRL_DEFAULT));
- WR_HARPOON(pCurrCard->ioPort+hp_sys_ctrl, STOP_CLK);
- }
- WR_HARPOON(pCurrCard->ioPort+hp_semaphore,
- (RD_HARPOON(pCurrCard->ioPort+hp_semaphore) & ~SCCB_MGR_ACTIVE));
- }
- if(pCurrCard->discQCount != 0)
- {
- currTar_Info = &sccbMgrTbl[p_card][p_sccb->TargID];
- if(((pCurrCard->globalFlags & F_CONLUN_IO) &&
- ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_sccb->Lun]] = NULL;
- }
- else
- {
- if(p_sccb->Sccb_tag)
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[p_sccb->Sccb_tag] = NULL;
- }else
- {
- pCurrCard->discQCount--;
- pCurrCard->discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = NULL;
- }
- }
- }
- callback = (CALL_BK_FN)p_sccb->SccbCallback;
- callback(p_sccb);
- pCurrCard->globalFlags |= F_NEW_SCCB_CMD;
- pCurrCard->currentSCCB = NULL;
- }
- #endif /* ( if FW_TYPE==...) */
- /*---------------------------------------------------------------------
- *
- * Function: Queue Disconnect
- *
- * Description: Add SCCB to our disconnect array.
- *
- *---------------------------------------------------------------------*/
- void queueDisconnect(PSCCB p_sccb, UCHAR p_card)
- {
- PSCCBMgr_tar_info currTar_Info;
- currTar_Info = &sccbMgrTbl[p_card][p_sccb->TargID];
- if(((BL_Card[p_card].globalFlags & F_CONLUN_IO) &&
- ((currTar_Info->TarStatus & TAR_TAG_Q_MASK) != TAG_Q_TRYING)))
- {
- BL_Card[p_card].discQ_Tbl[currTar_Info->LunDiscQ_Idx[p_sccb->Lun]] = p_sccb;
- }
- else
- {
- if (p_sccb->Sccb_tag)
- {
- BL_Card[p_card].discQ_Tbl[p_sccb->Sccb_tag] = p_sccb;
- sccbMgrTbl[p_card][p_sccb->TargID].TarLUNBusy[0] = FALSE;
- sccbMgrTbl[p_card][p_sccb->TargID].TarTagQ_Cnt++;
- }else
- {
- BL_Card[p_card].discQ_Tbl[currTar_Info->LunDiscQ_Idx[0]] = p_sccb;
- }
- }
- BL_Card[p_card].currentSCCB = NULL;
- }
- /*---------------------------------------------------------------------
- *
- * Function: Queue Flush SCCB
- *
- * Description: Flush all SCCB's back to the host driver for this target.
- *
- *---------------------------------------------------------------------*/
- void queueFlushSccb(UCHAR p_card, UCHAR error_code)
- {
- UCHAR qtag,thisTarg;
- PSCCB currSCCB;
- PSCCBMgr_tar_info currTar_Info;
- currSCCB = BL_Card[p_card].currentSCCB;
- if(currSCCB != NULL)
- {
- thisTarg = (UCHAR)currSCCB->TargID;
- currTar_Info = &sccbMgrTbl[p_card][thisTarg];
- for (qtag=0; qtag<QUEUE_DEPTH; qtag++) {
- if (BL_Card[p_card].discQ_Tbl[qtag] &&
- (BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg))
- {
- BL_Card[p_card].discQ_Tbl[qtag]->HostStatus = (UCHAR)error_code;
-
- queueCmdComplete(&BL_Card[p_card],BL_Card[p_card].discQ_Tbl[qtag], p_card);
- BL_Card[p_card].discQ_Tbl[qtag] = NULL;
- currTar_Info->TarTagQ_Cnt--;
- }
- }
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: Queue Flush Target SCCB
- *
- * Description: Flush all SCCB's back to the host driver for this target.
- *
- *---------------------------------------------------------------------*/
- void queueFlushTargSccb(UCHAR p_card, UCHAR thisTarg, UCHAR error_code)
- {
- UCHAR qtag;
- PSCCBMgr_tar_info currTar_Info;
- currTar_Info = &sccbMgrTbl[p_card][thisTarg];
- for (qtag=0; qtag<QUEUE_DEPTH; qtag++) {
- if (BL_Card[p_card].discQ_Tbl[qtag] &&
- (BL_Card[p_card].discQ_Tbl[qtag]->TargID == thisTarg))
- {
- BL_Card[p_card].discQ_Tbl[qtag]->HostStatus = (UCHAR)error_code;
- queueCmdComplete(&BL_Card[p_card],BL_Card[p_card].discQ_Tbl[qtag], p_card);
- BL_Card[p_card].discQ_Tbl[qtag] = NULL;
- currTar_Info->TarTagQ_Cnt--;
- }
- }
- }
- void queueAddSccb(PSCCB p_SCCB, UCHAR p_card)
- {
- PSCCBMgr_tar_info currTar_Info;
- currTar_Info = &sccbMgrTbl[p_card][p_SCCB->TargID];
- p_SCCB->Sccb_forwardlink = NULL;
- p_SCCB->Sccb_backlink = currTar_Info->TarSelQ_Tail;
- if (currTar_Info->TarSelQ_Cnt == 0) {
- currTar_Info->TarSelQ_Head = p_SCCB;
- }
- else {
- currTar_Info->TarSelQ_Tail->Sccb_forwardlink = p_SCCB;
- }
- currTar_Info->TarSelQ_Tail = p_SCCB;
- currTar_Info->TarSelQ_Cnt++;
- }
- /*---------------------------------------------------------------------
- *
- * Function: Queue Find SCCB
- *
- * Description: Search the target select Queue for this SCCB, and
- * remove it if found.
- *
- *---------------------------------------------------------------------*/
- UCHAR queueFindSccb(PSCCB p_SCCB, UCHAR p_card)
- {
- PSCCB q_ptr;
- PSCCBMgr_tar_info currTar_Info;
- currTar_Info = &sccbMgrTbl[p_card][p_SCCB->TargID];
- q_ptr = currTar_Info->TarSelQ_Head;
- while(q_ptr != NULL) {
- if (q_ptr == p_SCCB) {
- if (currTar_Info->TarSelQ_Head == q_ptr) {
- currTar_Info->TarSelQ_Head = q_ptr->Sccb_forwardlink;
- }
- if (currTar_Info->TarSelQ_Tail == q_ptr) {
- currTar_Info->TarSelQ_Tail = q_ptr->Sccb_backlink;
- }
- if (q_ptr->Sccb_forwardlink != NULL) {
- q_ptr->Sccb_forwardlink->Sccb_backlink = q_ptr->Sccb_backlink;
- }
- if (q_ptr->Sccb_backlink != NULL) {
- q_ptr->Sccb_backlink->Sccb_forwardlink = q_ptr->Sccb_forwardlink;
- }
- currTar_Info->TarSelQ_Cnt--;
- return(TRUE);
- }
- else {
- q_ptr = q_ptr->Sccb_forwardlink;
- }
- }
- return(FALSE);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Utility Update Residual Count
- *
- * Description: Update the XferCnt to the remaining byte count.
- * If we transferred all the data then just write zero.
- * If Non-SG transfer then report Total Cnt - Actual Transfer
- * Cnt. For SG transfers add the count fields of all
- * remaining SG elements, as well as any partial remaining
- * element.
- *
- *---------------------------------------------------------------------*/
- void utilUpdateResidual(PSCCB p_SCCB)
- {
- ULONG partial_cnt;
- UINT sg_index;
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- ULONG far *sg_ptr;
- #else
- ULONG *sg_ptr;
- #endif
- if (p_SCCB->Sccb_XferState & F_ALL_XFERRED) {
- p_SCCB->DataLength = 0x0000;
- }
- else if (p_SCCB->Sccb_XferState & F_SG_XFER) {
- partial_cnt = 0x0000;
- sg_index = p_SCCB->Sccb_sgseg;
- #if defined(COMPILER_16_BIT) && !defined(DOS)
- sg_ptr = (ULONG far *)p_SCCB->DataPointer;
- #else
- sg_ptr = (ULONG *)p_SCCB->DataPointer;
- #endif
- if (p_SCCB->Sccb_SGoffset) {
- partial_cnt = p_SCCB->Sccb_SGoffset;
- sg_index++;
- }
- while ( ((ULONG)sg_index * (ULONG)SG_ELEMENT_SIZE) <
- p_SCCB->DataLength ) {
- partial_cnt += *(sg_ptr+(sg_index * 2));
- sg_index++;
- }
- p_SCCB->DataLength = partial_cnt;
- }
- else {
- p_SCCB->DataLength -= p_SCCB->Sccb_ATC;
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: Wait 1 Second
- *
- * Description: Wait for 1 second.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void Wait1Second(USHORT p_port)
- #else
- void Wait1Second(ULONG p_port)
- #endif
- {
- UCHAR i;
- for(i=0; i < 4; i++) {
- Wait(p_port, TO_250ms);
- if ((RD_HARPOON(p_port+hp_scsictrl_0) & SCSI_RST))
- break;
- if((RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL))
- break;
- }
- }
- /*---------------------------------------------------------------------
- *
- * Function: Wait
- *
- * Description: Wait the desired delay.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void Wait(USHORT p_port, UCHAR p_delay)
- #else
- void Wait(ULONG p_port, UCHAR p_delay)
- #endif
- {
- UCHAR old_timer;
- UCHAR green_flag;
- old_timer = RD_HARPOON(p_port+hp_seltimeout);
- green_flag=RD_HARPOON(p_port+hp_clkctrl_0);
- WR_HARPOON(p_port+hp_clkctrl_0, CLKCTRL_DEFAULT);
- WR_HARPOON(p_port+hp_seltimeout,p_delay);
- WRW_HARPOON((p_port+hp_intstat), TIMEOUT);
- WRW_HARPOON((p_port+hp_intena), (default_intena & ~TIMEOUT));
- WR_HARPOON(p_port+hp_portctrl_0,
- (RD_HARPOON(p_port+hp_portctrl_0) | START_TO));
- while (!(RDW_HARPOON((p_port+hp_intstat)) & TIMEOUT)) {
- if ((RD_HARPOON(p_port+hp_scsictrl_0) & SCSI_RST))
- break;
- if ((RDW_HARPOON((p_port+hp_intstat)) & SCAM_SEL))
- break;
- }
- WR_HARPOON(p_port+hp_portctrl_0,
- (RD_HARPOON(p_port+hp_portctrl_0) & ~START_TO));
- WRW_HARPOON((p_port+hp_intstat), TIMEOUT);
- WRW_HARPOON((p_port+hp_intena), default_intena);
- WR_HARPOON(p_port+hp_clkctrl_0,green_flag);
- WR_HARPOON(p_port+hp_seltimeout,old_timer);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Enable/Disable Write to EEPROM
- *
- * Description: The EEPROM must first be enabled for writes
- * A total of 9 clocks are needed.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void utilEEWriteOnOff(USHORT p_port,UCHAR p_mode)
- #else
- void utilEEWriteOnOff(ULONG p_port,UCHAR p_mode)
- #endif
- {
- UCHAR ee_value;
- ee_value = (UCHAR)(RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H));
- if (p_mode)
- utilEESendCmdAddr(p_port, EWEN, EWEN_ADDR);
- else
- utilEESendCmdAddr(p_port, EWDS, EWDS_ADDR);
- WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /*Turn off Master Select */
- }
- /*---------------------------------------------------------------------
- *
- * Function: Write EEPROM
- *
- * Description: Write a word to the EEPROM at the specified
- * address.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void utilEEWrite(USHORT p_port, USHORT ee_data, USHORT ee_addr)
- #else
- void utilEEWrite(ULONG p_port, USHORT ee_data, USHORT ee_addr)
- #endif
- {
- UCHAR ee_value;
- USHORT i;
- ee_value = (UCHAR)((RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H))|
- (SEE_MS | SEE_CS));
- utilEESendCmdAddr(p_port, EE_WRITE, ee_addr);
- ee_value |= (SEE_MS + SEE_CS);
- for(i = 0x8000; i != 0; i>>=1) {
- if (i & ee_data)
- ee_value |= SEE_DO;
- else
- ee_value &= ~SEE_DO;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value |= SEE_CLK; /* Clock data! */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value &= ~SEE_CLK;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- }
- ee_value &= (EXT_ARB_ACK | SCSI_TERM_ENA_H);
- WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS));
- Wait(p_port, TO_10ms);
- WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS | SEE_CS)); /* Set CS to EEPROM */
- WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /* Turn off CS */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /* Turn off Master Select */
- }
- /*---------------------------------------------------------------------
- *
- * Function: Read EEPROM
- *
- * Description: Read a word from the EEPROM at the desired
- * address.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- USHORT utilEERead(USHORT p_port, USHORT ee_addr)
- #else
- USHORT utilEERead(ULONG p_port, USHORT ee_addr)
- #endif
- {
- USHORT i, ee_data1, ee_data2;
- i = 0;
- ee_data1 = utilEEReadOrg(p_port, ee_addr);
- do
- {
- ee_data2 = utilEEReadOrg(p_port, ee_addr);
- if(ee_data1 == ee_data2)
- return(ee_data1);
- ee_data1 = ee_data2;
- i++;
- }while(i < 4);
- return(ee_data1);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Read EEPROM Original
- *
- * Description: Read a word from the EEPROM at the desired
- * address.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- USHORT utilEEReadOrg(USHORT p_port, USHORT ee_addr)
- #else
- USHORT utilEEReadOrg(ULONG p_port, USHORT ee_addr)
- #endif
- {
- UCHAR ee_value;
- USHORT i, ee_data;
- ee_value = (UCHAR)((RD_HARPOON(p_port+hp_ee_ctrl) & (EXT_ARB_ACK | SCSI_TERM_ENA_H))|
- (SEE_MS | SEE_CS));
- utilEESendCmdAddr(p_port, EE_READ, ee_addr);
- ee_value |= (SEE_MS + SEE_CS);
- ee_data = 0;
- for(i = 1; i <= 16; i++) {
- ee_value |= SEE_CLK; /* Clock data! */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value &= ~SEE_CLK;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_data <<= 1;
- if (RD_HARPOON(p_port+hp_ee_ctrl) & SEE_DI)
- ee_data |= 1;
- }
- ee_value &= ~(SEE_MS + SEE_CS);
- WR_HARPOON(p_port+hp_ee_ctrl, (ee_value | SEE_MS)); /*Turn off CS */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value); /*Turn off Master Select */
- return(ee_data);
- }
- /*---------------------------------------------------------------------
- *
- * Function: Send EE command and Address to the EEPROM
- *
- * Description: Transfers the correct command and sends the address
- * to the eeprom.
- *
- *---------------------------------------------------------------------*/
- #if defined(DOS)
- void utilEESendCmdAddr(USHORT p_port, UCHAR ee_cmd, USHORT ee_addr)
- #else
- void utilEESendCmdAddr(ULONG p_port, UCHAR ee_cmd, USHORT ee_addr)
- #endif
- {
- UCHAR ee_value;
- UCHAR narrow_flg;
- USHORT i;
- narrow_flg= (UCHAR)(RD_HARPOON(p_port+hp_page_ctrl) & NARROW_SCSI_CARD);
- ee_value = SEE_MS;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value |= SEE_CS; /* Set CS to EEPROM */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- for(i = 0x04; i != 0; i>>=1) {
- if (i & ee_cmd)
- ee_value |= SEE_DO;
- else
- ee_value &= ~SEE_DO;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value |= SEE_CLK; /* Clock data! */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value &= ~SEE_CLK;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- }
- if (narrow_flg)
- i = 0x0080;
- else
- i = 0x0200;
- while (i != 0) {
- if (i & ee_addr)
- ee_value |= SEE_DO;
- else
- ee_value &= ~SEE_DO;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value |= SEE_CLK; /* Clock data! */
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- ee_value &= ~SEE_CLK;
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- WR_HARPOON(p_port+hp_ee_ctrl, ee_value);
- i >>= 1;
- }
- }
- USHORT CalcCrc16(UCHAR buffer[])
- {
- USHORT crc=0;
- int i,j;
- USHORT ch;
- for (i=0; i < ID_STRING_LENGTH; i++)
- {
- ch = (USHORT) buffer[i];
- for(j=0; j < 8; j++)
- {
- if ((crc ^ ch) & 1)
- crc = (crc >> 1) ^ CRCMASK;
- else
- crc >>= 1;
- ch >>= 1;
- }
- }
- return(crc);
- }
- UCHAR CalcLrc(UCHAR buffer[])
- {
- int i;
- UCHAR lrc;
- lrc = 0;
- for(i = 0; i < ID_STRING_LENGTH; i++)
- lrc ^= buffer[i];
- return(lrc);
- }
- /*
- The following inline definitions avoid type conflicts.
- */
- static inline unsigned char
- FlashPoint__ProbeHostAdapter(FlashPoint_Info_T *FlashPointInfo)
- {
- return FlashPoint_ProbeHostAdapter((PSCCBMGR_INFO) FlashPointInfo);
- }
- static inline FlashPoint_CardHandle_T
- FlashPoint__HardwareResetHostAdapter(FlashPoint_Info_T *FlashPointInfo)
- {
- return FlashPoint_HardwareResetHostAdapter((PSCCBMGR_INFO) FlashPointInfo);
- }
- static inline void
- FlashPoint__ReleaseHostAdapter(FlashPoint_CardHandle_T CardHandle)
- {
- FlashPoint_ReleaseHostAdapter(CardHandle);
- }
- static inline void
- FlashPoint__StartCCB(FlashPoint_CardHandle_T CardHandle, BusLogic_CCB_T *CCB)
- {
- FlashPoint_StartCCB(CardHandle, (PSCCB) CCB);
- }
- static inline void
- FlashPoint__AbortCCB(FlashPoint_CardHandle_T CardHandle, BusLogic_CCB_T *CCB)
- {
- FlashPoint_AbortCCB(CardHandle, (PSCCB) CCB);
- }
- static inline boolean
- FlashPoint__InterruptPending(FlashPoint_CardHandle_T CardHandle)
- {
- return FlashPoint_InterruptPending(CardHandle);
- }
- static inline int
- FlashPoint__HandleInterrupt(FlashPoint_CardHandle_T CardHandle)
- {
- return FlashPoint_HandleInterrupt(CardHandle);
- }
- #define FlashPoint_ProbeHostAdapter FlashPoint__ProbeHostAdapter
- #define FlashPoint_HardwareResetHostAdapter FlashPoint__HardwareResetHostAdapter
- #define FlashPoint_ReleaseHostAdapter FlashPoint__ReleaseHostAdapter
- #define FlashPoint_StartCCB FlashPoint__StartCCB
- #define FlashPoint_AbortCCB FlashPoint__AbortCCB
- #define FlashPoint_InterruptPending FlashPoint__InterruptPending
- #define FlashPoint_HandleInterrupt FlashPoint__HandleInterrupt
- /*
- FlashPoint_InquireTargetInfo returns the Synchronous Period, Synchronous
- Offset, and Wide Transfers Active information for TargetID on CardHandle.
- */
- void FlashPoint_InquireTargetInfo(FlashPoint_CardHandle_T CardHandle,
- int TargetID,
- unsigned char *SynchronousPeriod,
- unsigned char *SynchronousOffset,
- unsigned char *WideTransfersActive)
- {
- SCCBMGR_TAR_INFO *TargetInfo =
- &sccbMgrTbl[((SCCBCARD *)CardHandle)->cardIndex][TargetID];
- if ((TargetInfo->TarSyncCtrl & SYNC_OFFSET) > 0)
- {
- *SynchronousPeriod = 5 * ((TargetInfo->TarSyncCtrl >> 5) + 1);
- *SynchronousOffset = TargetInfo->TarSyncCtrl & SYNC_OFFSET;
- }
- else
- {
- *SynchronousPeriod = 0;
- *SynchronousOffset = 0;
- }
- *WideTransfersActive = (TargetInfo->TarSyncCtrl & NARROW_SCSI ? 0 : 1);
- }
- #else /* CONFIG_SCSI_OMIT_FLASHPOINT */
- /*
- Define prototypes for the FlashPoint SCCB Manager Functions.
- */
- extern unsigned char FlashPoint_ProbeHostAdapter(FlashPoint_Info_T *);
- extern FlashPoint_CardHandle_T
- FlashPoint_HardwareResetHostAdapter(FlashPoint_Info_T *);
- extern void FlashPoint_StartCCB(FlashPoint_CardHandle_T, BusLogic_CCB_T *);
- extern int FlashPoint_AbortCCB(FlashPoint_CardHandle_T, BusLogic_CCB_T *);
- extern boolean FlashPoint_InterruptPending(FlashPoint_CardHandle_T);
- extern int FlashPoint_HandleInterrupt(FlashPoint_CardHandle_T);
- extern void FlashPoint_ReleaseHostAdapter(FlashPoint_CardHandle_T);
- extern void FlashPoint_InquireTargetInfo(FlashPoint_CardHandle_T,
- int, unsigned char *,
- unsigned char *, unsigned char *);
- #endif /* CONFIG_SCSI_OMIT_FLASHPOINT */