📄 skvpd.c
字号:
/****************************************************************************** * * Name: skvpd.c * Project: GEnesis, PCI Gigabit Ethernet Adapter * Version: $Revision: 1.26 $ * Date: $Date: 2000/06/13 08:00:01 $ * Purpose: Shared software to read and write VPD data * ******************************************************************************//****************************************************************************** * * (C)Copyright 1998,1999 SysKonnect, * a business unit of Schneider & Koch & Co. Datensysteme GmbH. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * The information in this file is provided "AS IS" without warranty. * ******************************************************************************//****************************************************************************** * * History: * * $Log: skvpd.c,v $ * Revision 1.26 2000/06/13 08:00:01 mkarl * additional cast to avoid compile problems in 64 bit environment * * Revision 1.25 1999/11/22 13:39:32 cgoos * Changed license header to GPL. * * Revision 1.24 1999/03/11 14:25:49 malthoff * Replace __STDC__ with SK_KR_PROTO. * * Revision 1.23 1999/01/11 15:13:11 gklug * fix: syntax error * * Revision 1.22 1998/10/30 06:41:15 gklug * rmv: WARNING * * Revision 1.21 1998/10/29 07:15:14 gklug * fix: Write Stream function needs verify. * * Revision 1.20 1998/10/28 18:05:08 gklug * chg: no DEBUG in VpdMayWrite * * Revision 1.19 1998/10/28 15:56:11 gklug * fix: Return len at end of ReadStream * fix: Write even less than 4 bytes correctly * * Revision 1.18 1998/10/28 09:00:47 gklug * fix: unreferenced local vars * * Revision 1.17 1998/10/28 08:25:45 gklug * fix: WARNING * * Revision 1.16 1998/10/28 08:17:30 gklug * fix: typo * * Revision 1.15 1998/10/28 07:50:32 gklug * fix: typo * * Revision 1.14 1998/10/28 07:20:38 gklug * chg: Interface functions to use IoC as parameter as well * fix: VpdRead/WriteDWord now return SK_U32 * chg: VPD_IN/OUT names conform to SK_IN/OUT * add: usage of VPD_IN/OUT8 macros * add: VpdRead/Write Stream functions to r/w a stream of data * fix: VpdTransferBlock swapped illeagal * add: VpdMayWrite * * Revision 1.13 1998/10/22 10:02:37 gklug * fix: SysKonnectFileId typo * * Revision 1.12 1998/10/20 10:01:01 gklug * fix: parameter to SkOsGetTime * * Revision 1.11 1998/10/15 12:51:48 malthoff * Remove unrequired parameter p in vpd_setup_para(). * * Revision 1.10 1998/10/08 14:52:43 malthoff * Remove CvsId by SysKonnectFileId. * * Revision 1.9 1998/09/16 07:33:52 malthoff * remove memcmp() by SK_MEMCMP and * memcpy() by SK_MEMCPY() to be * independant from the 'C' Standard Library. * * Revision 1.8 1998/08/19 12:52:35 malthoff * compiler fix: use SK_VPD_KEY instead of S_VPD. * * Revision 1.7 1998/08/19 08:14:01 gklug * fix: remove struct keyword as much as possible from the c-code (see CCC) * * Revision 1.6 1998/08/18 13:03:58 gklug * SkOsGetTime now returns SK_U64 * * Revision 1.5 1998/08/18 08:17:29 malthoff * Ensure we issue a VPD read in vpd_read_dword(). * Discard all VPD keywords other than Vx or Yx, where * x is '0..9' or 'A..Z'. * * Revision 1.4 1998/07/03 14:52:19 malthoff * Add category SK_DBGCAT_FATAL to some debug macros. * bug fix: correct the keyword name check in vpd_write(). * * Revision 1.3 1998/06/26 11:16:53 malthoff * Correct the modified File Identifier. * * Revision 1.2 1998/06/26 11:13:43 malthoff * Modify the File Identifier. * * Revision 1.1 1998/06/19 14:11:08 malthoff * Created, Tests with AIX were performed successfully * * ******************************************************************************//* Please refer skvpd.txt for infomation how to include this module */static const char SysKonnectFileId[] = "@(#)$Id: skvpd.c,v 1.26 2000/06/13 08:00:01 mkarl Exp $ (C) SK" ;#include "h/skdrv1st.h"#include "h/sktypes.h"#include "h/skdebug.h"#include "h/skdrv2nd.h"/* * Static functions */#ifndef SK_KR_PROTOstatic SK_VPD_PARA *vpd_find_para( SK_AC *pAC, char *key, SK_VPD_PARA *p) ;#else /* SK_KR_PROTO */static SK_VPD_PARA *vpd_find_para() ;#endif /* SK_KR_PROTO *//* * waits for a completetion of a VPD transfer * The VPD transfer must complete within SK_TICKS_PER_SEC/16 * * returns 0: success, transfer completes * error exit(9) with a error message */static int VpdWait(SK_AC *pAC, /* Adapters context */SK_IOC IoC, /* IO Context */int event) /* event to wait for (VPD_READ / VPD_write) completion*/{ SK_U64 start_time ; SK_U16 state ; SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_CTRL, ("vpd wait for %s\n",event?"Write":"Read")) ; start_time = SkOsGetTime(pAC) ; do { if (SkOsGetTime(pAC) - start_time > SK_TICKS_PER_SEC/16) { VPD_STOP(pAC,IoC) ; SK_DBG_MSG(pAC,SK_DBGMOD_VPD, SK_DBGCAT_FATAL|SK_DBGCAT_ERR, ("ERROR:vpd wait timeout\n")) ; return(1) ; } VPD_IN16(pAC,IoC,PCI_VPD_ADR_REG,&state) ; SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_CTRL, ("state = %x, event %x\n",state,event)) ; } while((int)(state & PCI_VPD_FLAG) == event) ; return(0) ;}/* * Read the dword at address 'addr' from the VPD EEPROM. * * Needed Time: MIN 1,3 ms MAX 2,6 ms * * Note: The DWord is returned in the endianess of the machine the routine * is running on. * * Returns the data read. */SK_U32 VpdReadDWord(SK_AC *pAC, /* Adapters context */SK_IOC IoC, /* IO Context */int addr) /* VPD address */{ SK_U32 Rtv ; /* start VPD read */ SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_CTRL, ("vpd read dword at 0x%x\n",addr)) ; addr &= ~VPD_WRITE ; /* ensure the R/W bit is set to read */ VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, (SK_U16) addr) ; /* ignore return code here */ (void)VpdWait(pAC,IoC,VPD_READ) ; /* Don't swap here, it's a data stream of bytes */ Rtv = 0 ; VPD_IN32(pAC,IoC,PCI_VPD_DAT_REG,&Rtv) ; SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_CTRL, ("vpd read dword data = 0x%x\n",Rtv)) ; return (Rtv) ;}/* Write the dword 'data' at address 'addr' into the VPD EEPROM, and verify that the data is written. Needed Time:. MIN MAX. -------------------------------------------------------------------. write 1.8 ms 3.6 ms. internal write cyles 0.7 ms 7.0 ms. -------------------------------------------------------------------. over all program time 2.5 ms 10.6 ms. read 1.3 ms 2.6 ms. -------------------------------------------------------------------. over all 3.8 ms 13.2 ms. Returns 0: success 1: error, I2C transfer does not terminate 2: error, data verify error */#if 0 /* Unused at the moment */static int VpdWriteDWord(SK_AC *pAC, /* pAC pointer */SK_IOC IoC, /* IO Context */int addr, /* VPD address */SK_U32 data) /* VPD data to write */{ /* start VPD write */ /* Don't swap here, it's a data stream of bytes */ SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_CTRL, ("vpd write dword at addr 0x%x, data = 0x%x\n",addr,data)) ; VPD_OUT32(pAC,IoC,PCI_VPD_DAT_REG, (SK_U32)data) ; /* But do it here */ addr |= VPD_WRITE ; VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, (SK_U16)(addr | VPD_WRITE)) ; /* this may take up to 10,6 ms */ if (VpdWait(pAC,IoC,VPD_WRITE)) { SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR, ("Write Timed Out\n")) ; return(1) ; } ; /* verify data */ if (VpdReadDWord(pAC,IoC,addr) != data) { SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR|SK_DBGCAT_FATAL, ("Data Verify Error\n")) ; return(2) ; } return(0) ;}#endif/* * Read one Stream of 'len' bytes of VPD data, starting at 'addr' from * or to the I2C EEPROM. * * Returns number of bytes read / written. */static int VpdWriteStream(SK_AC *pAC, /* Adapters context */SK_IOC IoC, /* IO Context */char *buf, /* data buffer */int Addr, /* VPD start address */int Len) /* number of bytes to read / to write */{ int i ; int j ; SK_U16 AdrReg ; int Rtv ; SK_U8 * pComp; /* Compare pointer */ SK_U8 Data ; /* Input Data for Compare */ /* Init Compare Pointer */ pComp = (SK_U8 *) buf; for (i=0; i < Len; i ++, buf++) { if ((i%sizeof(SK_U32)) == 0) { /* * At the begin of each cycle read the Data Reg * So it is initialized even if only a few bytes * are written. */ AdrReg = (SK_U16) Addr ; AdrReg &= ~VPD_WRITE ; /* READ operation */ VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, AdrReg) ; /* ignore return code here */ Rtv = VpdWait(pAC,IoC,VPD_READ) ; if (Rtv != 0) { return(i) ; } } /* Write current Byte */ VPD_OUT8(pAC,IoC,PCI_VPD_DAT_REG+(i%sizeof(SK_U32)), *(SK_U8*)buf) ; if (((i%sizeof(SK_U32)) == 3) || (i == (Len - 1))) { /* New Address needs to be written to VPD_ADDR reg */ AdrReg = (SK_U16) Addr ; Addr += sizeof(SK_U32); AdrReg |= VPD_WRITE ; /* WRITE operation */ VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, AdrReg) ; /* Wait for termination */ Rtv = VpdWait(pAC,IoC,VPD_WRITE) ; if (Rtv != 0) { SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR, ("Write Timed Out\n")) ; return(i - (i%sizeof(SK_U32))) ; } /* * Now re-read to verify */ AdrReg &= ~VPD_WRITE ; /* READ operation */ VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, AdrReg) ; /* Wait for termination */ Rtv = VpdWait(pAC,IoC,VPD_READ) ; if (Rtv != 0) { SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR, ("Verify Timed Out\n")) ; return(i - (i%sizeof(SK_U32))) ; } for (j = 0; j <= (int) (i%sizeof(SK_U32)); j ++, pComp ++ ) { VPD_IN8(pAC,IoC,PCI_VPD_DAT_REG+j, &Data) ; if (Data != *pComp) { /* Verify Error */ SK_DBG_MSG(pAC,SK_DBGMOD_VPD, SK_DBGCAT_ERR, ("WriteStream Verify Error\n")); return(i - (i%sizeof(SK_U32)) + j); } } } } return(Len);} /* * Read one Stream of 'len' bytes of VPD data, starting at 'addr' from * or to the I2C EEPROM. * * Returns number of bytes read / written. */static int VpdReadStream(SK_AC *pAC, /* Adapters context */SK_IOC IoC, /* IO Context */char *buf, /* data buffer */int Addr, /* VPD start address */int Len) /* number of bytes to read / to write */{ int i ; SK_U16 AdrReg ; int Rtv ; for (i=0; i < Len; i ++, buf++) { if ((i%sizeof(SK_U32)) == 0) { /* New Address needs to be written to VPD_ADDR reg */ AdrReg = (SK_U16) Addr ; Addr += sizeof(SK_U32); AdrReg &= ~VPD_WRITE ; /* READ operation */ VPD_OUT16(pAC,IoC,PCI_VPD_ADR_REG, AdrReg) ; /* ignore return code here */ Rtv = VpdWait(pAC,IoC,VPD_READ) ; if (Rtv != 0) { return(i) ; } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -