📄 skvpd.c
字号:
/****************************************************************************** * * Name: skvpd.c * Project: GEnesis, PCI Gigabit Ethernet Adapter * Version: $Revision: 1.1.1.1 $ * Date: $Date: 2005/06/27 17:05:03 $ * Purpose: Shared software to read and write VPD data * ******************************************************************************//****************************************************************************** * * (C)Copyright 1998-2003 SysKonnect 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.1.1.1 2005/06/27 17:05:03 linuxpark * Initial import. * * Revision 1.37 2003/01/13 10:42:45 rschmidt * Replaced check for PCI device Id from YUKON with GENESIS * to set the VPD size in VpdInit() * Editorial changes * * Revision 1.36 2002/11/14 15:16:56 gheinig * Added const specifier to key and buf parameters for VpdPara, VpdRead * and VpdWrite for Diag 7 GUI * * Revision 1.35 2002/10/21 14:31:59 gheinig * Took out CVS web garbage at head of file * * Revision 1.34 2002/10/21 11:47:24 gheinig * Reverted to version 1.32 due to unwanted commit * * Revision 1.32 2002/10/14 16:04:29 rschmidt * Added saving of VPD ROM Size from PCI_OUR_REG_2 * Avoid reading of PCI_OUR_REG_2 in VpdTransferBlock() * Editorial changes * * Revision 1.31 2002/09/10 09:21:32 mkarl * Replaced all if(GIChipId == CHIP_ID_GENESIS) with new entry GIGenesis * * Revision 1.30 2002/09/09 14:43:03 mkarl * changes for diagnostics in order to read VPD data before the adapter * has been initialized * editorial changes * * Revision 1.29 2002/07/26 13:20:43 mkarl * added Yukon support * save size of VPD in pAC->vpd.vpd_size * * Revision 1.28 2002/04/02 15:31:47 afischer * Bug fix in VpdWait() * * Revision 1.27 2000/08/10 11:29:06 rassmann * Editorial changes. * Preserving 32-bit alignment in structs for the adapter context. * Removed unused function VpdWriteDword() (#if 0). * Made VpdReadKeyword() available for SKDIAG only. * * 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 returns 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 illegal * 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 * replace memcmp() by SK_MEMCMP and * memcpy() by SK_MEMCPY() to be * independent 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 * * ******************************************************************************/#include <config.h>#ifdef CONFIG_SK98/* Please refer skvpd.txt for infomation how to include this module */static const char SysKonnectFileId[] = "@(#)$Id: skvpd.c,v 1.1.1.1 2005/06/27 17:05:03 linuxpark 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, const char *key, SK_VPD_PARA *p);#else /* SK_KR_PROTO */static SK_VPD_PARA *vpd_find_para();#endif /* SK_KR_PROTO *//* * waits for a completion 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) { /* Bug fix AF: Thu Mar 28 2002 * Do not call: VPD_STOP(pAC, IoC); * A pending VPD read cycle can not be aborted by writing * VPD_WRITE to the PCI_VPD_ADR_REG (VPD address register). * Although the write threshold in the OUR-register protects * VPD read only space from being overwritten this does not * protect a VPD read from being `converted` into a VPD write * operation (on the fly). As a consequence the VPD_STOP would * delete VPD read only data. In case of any problems with the * I2C bus we exit the loop here. The I2C read operation can * not be aborted except by a reset (->LR). */ 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);}#ifdef SKDIAG/* * 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);}#endif /* SKDIAG */#if 0/* 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 */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);} /* VpdWriteDWord */#endif /* 0 *//* * 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); /* Wait for termination */ 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 */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -