1 /******************************************************************************
4 * Project: GEnesis, PCI Gigabit Ethernet Adapter
5 * Version: $Revision: 1.37 $
6 * Date: $Date: 2003/01/13 10:42:45 $
7 * Purpose: Shared software to read and write VPD data
9 ******************************************************************************/
11 /******************************************************************************
13 * (C)Copyright 1998-2003 SysKonnect GmbH.
15 * This program is free software; you can redistribute it and/or modify
16 * it under the terms of the GNU General Public License as published by
17 * the Free Software Foundation; either version 2 of the License, or
18 * (at your option) any later version.
20 * The information in this file is provided "AS IS" without warranty.
22 ******************************************************************************/
25 Please refer skvpd.txt for infomation how to include this module
27 static const char SysKonnectFileId[] =
28 "@(#)$Id: skvpd.c,v 1.37 2003/01/13 10:42:45 rschmidt Exp $ (C) SK";
30 #include "h/skdrv1st.h"
31 #include "h/sktypes.h"
32 #include "h/skdebug.h"
33 #include "h/skdrv2nd.h"
39 static SK_VPD_PARA *vpd_find_para(
43 #else /* SK_KR_PROTO */
44 static SK_VPD_PARA *vpd_find_para();
45 #endif /* SK_KR_PROTO */
48 * waits for a completion of a VPD transfer
49 * The VPD transfer must complete within SK_TICKS_PER_SEC/16
51 * returns 0: success, transfer completes
52 * error exit(9) with a error message
55 SK_AC *pAC, /* Adapters context */
56 SK_IOC IoC, /* IO Context */
57 int event) /* event to wait for (VPD_READ / VPD_write) completion*/
62 SK_DBG_MSG(pAC,SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
63 ("VPD wait for %s\n", event?"Write":"Read"));
64 start_time = SkOsGetTime(pAC);
66 if (SkOsGetTime(pAC) - start_time > SK_TICKS_PER_SEC) {
68 /* Bug fix AF: Thu Mar 28 2002
69 * Do not call: VPD_STOP(pAC, IoC);
70 * A pending VPD read cycle can not be aborted by writing
71 * VPD_WRITE to the PCI_VPD_ADR_REG (VPD address register).
72 * Although the write threshold in the OUR-register protects
73 * VPD read only space from being overwritten this does not
74 * protect a VPD read from being `converted` into a VPD write
75 * operation (on the fly). As a consequence the VPD_STOP would
76 * delete VPD read only data. In case of any problems with the
77 * I2C bus we exit the loop here. The I2C read operation can
78 * not be aborted except by a reset (->LR).
80 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_FATAL | SK_DBGCAT_ERR,
81 ("ERROR:VPD wait timeout\n"));
85 VPD_IN16(pAC, IoC, PCI_VPD_ADR_REG, &state);
87 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
88 ("state = %x, event %x\n",state,event));
89 } while((int)(state & PCI_VPD_FLAG) == event);
97 * Read the dword at address 'addr' from the VPD EEPROM.
99 * Needed Time: MIN 1,3 ms MAX 2,6 ms
101 * Note: The DWord is returned in the endianess of the machine the routine
104 * Returns the data read.
107 SK_AC *pAC, /* Adapters context */
108 SK_IOC IoC, /* IO Context */
109 int addr) /* VPD address */
114 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
115 ("VPD read dword at 0x%x\n",addr));
116 addr &= ~VPD_WRITE; /* ensure the R/W bit is set to read */
118 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, (SK_U16)addr);
120 /* ignore return code here */
121 (void)VpdWait(pAC, IoC, VPD_READ);
123 /* Don't swap here, it's a data stream of bytes */
126 VPD_IN32(pAC, IoC, PCI_VPD_DAT_REG, &Rtv);
128 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
129 ("VPD read dword data = 0x%x\n",Rtv));
138 Write the dword 'data' at address 'addr' into the VPD EEPROM, and
139 verify that the data is written.
144 . -------------------------------------------------------------------
145 . write 1.8 ms 3.6 ms
146 . internal write cyles 0.7 ms 7.0 ms
147 . -------------------------------------------------------------------
148 . over all program time 2.5 ms 10.6 ms
150 . -------------------------------------------------------------------
151 . over all 3.8 ms 13.2 ms
156 1: error, I2C transfer does not terminate
157 2: error, data verify error
160 static int VpdWriteDWord(
161 SK_AC *pAC, /* pAC pointer */
162 SK_IOC IoC, /* IO Context */
163 int addr, /* VPD address */
164 SK_U32 data) /* VPD data to write */
166 /* start VPD write */
167 /* Don't swap here, it's a data stream of bytes */
168 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
169 ("VPD write dword at addr 0x%x, data = 0x%x\n",addr,data));
170 VPD_OUT32(pAC, IoC, PCI_VPD_DAT_REG, (SK_U32)data);
174 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, (SK_U16)(addr | VPD_WRITE));
176 /* this may take up to 10,6 ms */
177 if (VpdWait(pAC, IoC, VPD_WRITE)) {
178 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
179 ("Write Timed Out\n"));
184 if (VpdReadDWord(pAC, IoC, addr) != data) {
185 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
186 ("Data Verify Error\n"));
190 } /* VpdWriteDWord */
195 * Read one Stream of 'len' bytes of VPD data, starting at 'addr' from
196 * or to the I2C EEPROM.
198 * Returns number of bytes read / written.
200 static int VpdWriteStream(
201 SK_AC *pAC, /* Adapters context */
202 SK_IOC IoC, /* IO Context */
203 char *buf, /* data buffer */
204 int Addr, /* VPD start address */
205 int Len) /* number of bytes to read / to write */
211 SK_U8 * pComp; /* Compare pointer */
212 SK_U8 Data; /* Input Data for Compare */
214 /* Init Compare Pointer */
215 pComp = (SK_U8 *) buf;
217 for (i = 0; i < Len; i++, buf++) {
218 if ((i%sizeof(SK_U32)) == 0) {
220 * At the begin of each cycle read the Data Reg
221 * So it is initialized even if only a few bytes
224 AdrReg = (SK_U16) Addr;
225 AdrReg &= ~VPD_WRITE; /* READ operation */
227 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
229 /* Wait for termination */
230 Rtv = VpdWait(pAC, IoC, VPD_READ);
236 /* Write current Byte */
237 VPD_OUT8(pAC, IoC, PCI_VPD_DAT_REG + (i%sizeof(SK_U32)),
240 if (((i%sizeof(SK_U32)) == 3) || (i == (Len - 1))) {
241 /* New Address needs to be written to VPD_ADDR reg */
242 AdrReg = (SK_U16) Addr;
243 Addr += sizeof(SK_U32);
244 AdrReg |= VPD_WRITE; /* WRITE operation */
246 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
248 /* Wait for termination */
249 Rtv = VpdWait(pAC, IoC, VPD_WRITE);
251 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
252 ("Write Timed Out\n"));
253 return(i - (i%sizeof(SK_U32)));
257 * Now re-read to verify
259 AdrReg &= ~VPD_WRITE; /* READ operation */
261 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
263 /* Wait for termination */
264 Rtv = VpdWait(pAC, IoC, VPD_READ);
266 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
267 ("Verify Timed Out\n"));
268 return(i - (i%sizeof(SK_U32)));
271 for (j = 0; j <= (int)(i%sizeof(SK_U32)); j++, pComp++) {
273 VPD_IN8(pAC, IoC, PCI_VPD_DAT_REG + j, &Data);
275 if (Data != *pComp) {
277 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
278 ("WriteStream Verify Error\n"));
279 return(i - (i%sizeof(SK_U32)) + j);
290 * Read one Stream of 'len' bytes of VPD data, starting at 'addr' from
291 * or to the I2C EEPROM.
293 * Returns number of bytes read / written.
295 static int VpdReadStream(
296 SK_AC *pAC, /* Adapters context */
297 SK_IOC IoC, /* IO Context */
298 char *buf, /* data buffer */
299 int Addr, /* VPD start address */
300 int Len) /* number of bytes to read / to write */
306 for (i = 0; i < Len; i++, buf++) {
307 if ((i%sizeof(SK_U32)) == 0) {
308 /* New Address needs to be written to VPD_ADDR reg */
309 AdrReg = (SK_U16) Addr;
310 Addr += sizeof(SK_U32);
311 AdrReg &= ~VPD_WRITE; /* READ operation */
313 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
315 /* Wait for termination */
316 Rtv = VpdWait(pAC, IoC, VPD_READ);
321 VPD_IN8(pAC, IoC, PCI_VPD_DAT_REG + (i%sizeof(SK_U32)),
329 * Read ore writes 'len' bytes of VPD data, starting at 'addr' from
330 * or to the I2C EEPROM.
332 * Returns number of bytes read / written.
334 static int VpdTransferBlock(
335 SK_AC *pAC, /* Adapters context */
336 SK_IOC IoC, /* IO Context */
337 char *buf, /* data buffer */
338 int addr, /* VPD start address */
339 int len, /* number of bytes to read / to write */
340 int dir) /* transfer direction may be VPD_READ or VPD_WRITE */
342 int Rtv; /* Return value */
345 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
346 ("VPD %s block, addr = 0x%x, len = %d\n",
347 dir ? "write" : "read", addr, len));
352 vpd_rom_size = pAC->vpd.rom_size;
354 if (addr > vpd_rom_size - 4) {
355 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
356 ("Address error: 0x%x, exp. < 0x%x\n",
357 addr, vpd_rom_size - 4));
361 if (addr + len > vpd_rom_size) {
362 len = vpd_rom_size - addr;
363 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
364 ("Warning: len was cut to %d\n", len));
367 if (dir == VPD_READ) {
368 Rtv = VpdReadStream(pAC, IoC, buf, addr, len);
371 Rtv = VpdWriteStream(pAC, IoC, buf, addr, len);
380 * Read 'len' bytes of VPD data, starting at 'addr'.
382 * Returns number of bytes read.
385 SK_AC *pAC, /* pAC pointer */
386 SK_IOC IoC, /* IO Context */
387 char *buf, /* buffer were the data should be stored */
388 int addr, /* start reading at the VPD address */
389 int len) /* number of bytes to read */
391 return(VpdTransferBlock(pAC, IoC, buf, addr, len, VPD_READ));
395 * Write 'len' bytes of *but to the VPD EEPROM, starting at 'addr'.
397 * Returns number of bytes writes.
400 SK_AC *pAC, /* pAC pointer */
401 SK_IOC IoC, /* IO Context */
402 char *buf, /* buffer, holds the data to write */
403 int addr, /* start writing at the VPD address */
404 int len) /* number of bytes to write */
406 return(VpdTransferBlock(pAC, IoC, buf, addr, len, VPD_WRITE));
411 * (re)initialize the VPD buffer
413 * Reads the VPD data from the EEPROM into the VPD buffer.
414 * Get the remaining read only and read / write space.
420 SK_AC *pAC, /* Adapters context */
421 SK_IOC IoC) /* IO Context */
423 SK_VPD_PARA *r, rp; /* RW or RV */
430 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_INIT, ("VpdInit .. "));
432 VPD_IN16(pAC, IoC, PCI_DEVICE_ID, &dev_id);
434 VPD_IN32(pAC, IoC, PCI_OUR_REG_2, &our_reg2);
436 pAC->vpd.rom_size = 256 << ((our_reg2 & PCI_VPD_ROM_SZ) >> 14);
439 * this function might get used before the hardware is initialized
440 * therefore we cannot always trust in GIChipId
442 if (((pAC->vpd.v.vpd_status & VPD_VALID) == 0 &&
443 dev_id != VPD_DEV_ID_GENESIS) ||
444 ((pAC->vpd.v.vpd_status & VPD_VALID) != 0 &&
445 !pAC->GIni.GIGenesis)) {
447 /* for Yukon the VPD size is always 256 */
448 vpd_size = VPD_SIZE_YUKON;
451 /* Genesis uses the maximum ROM size up to 512 for VPD */
452 if (pAC->vpd.rom_size > VPD_SIZE_GENESIS) {
453 vpd_size = VPD_SIZE_GENESIS;
456 vpd_size = pAC->vpd.rom_size;
460 /* read the VPD data into the VPD buffer */
461 if (VpdTransferBlock(pAC, IoC, pAC->vpd.vpd_buf, 0, vpd_size, VPD_READ)
464 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
465 ("Block Read Error\n"));
469 pAC->vpd.vpd_size = vpd_size;
471 /* find the end tag of the RO area */
472 if (!(r = vpd_find_para(pAC, VPD_RV, &rp))) {
473 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
474 ("Encoding Error: RV Tag not found\n"));
478 if (r->p_val + r->p_len > pAC->vpd.vpd_buf + vpd_size/2) {
479 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
480 ("Encoding Error: Invalid VPD struct size\n"));
483 pAC->vpd.v.vpd_free_ro = r->p_len - 1;
485 /* test the checksum */
486 for (i = 0, x = 0; (unsigned)i <= (unsigned)vpd_size/2 - r->p_len; i++) {
487 x += pAC->vpd.vpd_buf[i];
492 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
493 ("VPD Checksum Error\n"));
497 /* find and check the end tag of the RW area */
498 if (!(r = vpd_find_para(pAC, VPD_RW, &rp))) {
499 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
500 ("Encoding Error: RV Tag not found\n"));
504 if (r->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
505 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
506 ("Encoding Error: Invalid VPD struct size\n"));
509 pAC->vpd.v.vpd_free_rw = r->p_len;
511 /* everything seems to be ok */
512 if (pAC->GIni.GIChipId != 0) {
513 pAC->vpd.v.vpd_status |= VPD_VALID;
516 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_INIT,
517 ("done. Free RO = %d, Free RW = %d\n",
518 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
524 * find the Keyword 'key' in the VPD buffer and fills the
525 * parameter struct 'p' with it's values
528 * 0: parameter was not found or VPD encoding error
530 static SK_VPD_PARA *vpd_find_para(
531 SK_AC *pAC, /* common data base */
532 const char *key, /* keyword to find (e.g. "MN") */
533 SK_VPD_PARA *p) /* parameter description struct */
535 char *v ; /* points to VPD buffer */
536 int max; /* Maximum Number of Iterations */
538 v = pAC->vpd.vpd_buf;
541 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
542 ("VPD find para %s .. ",key));
544 /* check mandatory resource type ID string (Product Name) */
545 if (*v != (char)RES_ID) {
546 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
547 ("Error: 0x%x missing\n", RES_ID));
551 if (strcmp(key, VPD_NAME) == 0) {
552 p->p_len = VPD_GET_RES_LEN(v);
553 p->p_val = VPD_GET_VAL(v);
554 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
555 ("found, len = %d\n", p->p_len));
559 v += 3 + VPD_GET_RES_LEN(v) + 3;
561 if (SK_MEMCMP(key,v,2) == 0) {
562 p->p_len = VPD_GET_VPD_LEN(v);
563 p->p_val = VPD_GET_VAL(v);
564 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
565 ("found, len = %d\n",p->p_len));
569 /* exit when reaching the "RW" Tag or the maximum of itera. */
571 if (SK_MEMCMP(VPD_RW,v,2) == 0 || max == 0) {
575 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
576 v += 3 + VPD_GET_VPD_LEN(v) + 3; /* skip VPD-W */
579 v += 3 + VPD_GET_VPD_LEN(v);
581 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
582 ("scanning '%c%c' len = %d\n",v[0],v[1],v[2]));
586 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL, ("not found\n"));
588 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
589 ("Key/Len Encoding error\n"));
596 * Move 'n' bytes. Begin with the last byte if 'n' is > 0,
597 * Start with the last byte if n is < 0.
601 static void vpd_move_para(
602 char *start, /* start of memory block */
603 char *end, /* end of memory block to move */
604 int n) /* number of bytes the memory block has to be moved */
607 int i; /* number of byte copied */
612 i = (int) (end - start + 1);
630 * setup the VPD keyword 'key' at 'ip'.
634 static void vpd_insert_key(
635 const char *key, /* keyword to insert */
636 const char *buf, /* buffer with the keyword value */
637 int len, /* length of the value string */
638 char *ip) /* inseration point */
642 p = (SK_VPD_KEY *) ip;
643 p->p_key[0] = key[0];
644 p->p_key[1] = key[1];
645 p->p_len = (unsigned char) len;
646 SK_MEMCPY(&p->p_val,buf,len);
650 * Setup the VPD end tag "RV" / "RW".
651 * Also correct the remaining space variables vpd_free_ro / vpd_free_rw.
656 static int vpd_mod_endtag(
657 SK_AC *pAC, /* common data base */
658 char *etp) /* end pointer input position */
665 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
666 ("VPD modify endtag at 0x%x = '%c%c'\n",etp,etp[0],etp[1]));
668 vpd_size = pAC->vpd.vpd_size;
670 p = (SK_VPD_KEY *) etp;
672 if (p->p_key[0] != 'R' || (p->p_key[1] != 'V' && p->p_key[1] != 'W')) {
673 /* something wrong here, encoding error */
674 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
675 ("Encoding Error: invalid end tag\n"));
678 if (etp > pAC->vpd.vpd_buf + vpd_size/2) {
679 /* create "RW" tag */
680 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size-etp-3-1);
681 pAC->vpd.v.vpd_free_rw = (int) p->p_len;
682 i = pAC->vpd.v.vpd_free_rw;
686 /* create "RV" tag */
687 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size/2-etp-3);
688 pAC->vpd.v.vpd_free_ro = (int) p->p_len - 1;
691 for (i = 0, x = 0; i < vpd_size/2 - p->p_len; i++) {
692 x += pAC->vpd.vpd_buf[i];
694 p->p_val = (char) 0 - x;
695 i = pAC->vpd.v.vpd_free_ro;
707 * Insert a VPD keyword into the VPD buffer.
709 * The keyword 'key' is inserted at the position 'ip' in the
711 * The keywords behind the input position will
712 * be moved. The VPD end tag "RV" or "RW" is generated again.
715 * 2: value string was cut
716 * 4: VPD full, keyword was not written
721 SK_AC *pAC, /* common data base */
722 const char *key, /* keyword to insert */
723 const char *buf, /* buffer with the keyword value */
724 int len, /* length of the keyword value */
725 int type, /* VPD_RO_KEY or VPD_RW_KEY */
726 int op) /* operation to do: ADD_KEY or OWR_KEY */
729 char *etp; /* end tag position */
730 int free; /* remaining space in selected area */
731 char *ip; /* input position inside the VPD buffer */
732 int rtv; /* return code */
733 int head; /* additional haeder bytes to move */
734 int found; /* additinoal bytes if the keyword was found */
737 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
738 ("VPD setup para key = %s, val = %s\n",key,buf));
740 vpd_size = pAC->vpd.vpd_size;
744 if (type == VPD_RW_KEY) {
745 /* end tag is "RW" */
746 free = pAC->vpd.v.vpd_free_rw;
747 etp = pAC->vpd.vpd_buf + (vpd_size - free - 1 - 3);
750 /* end tag is "RV" */
751 free = pAC->vpd.v.vpd_free_ro;
752 etp = pAC->vpd.vpd_buf + (vpd_size/2 - free - 4);
754 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
755 ("Free RO = %d, Free RW = %d\n",
756 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
761 if (vpd_find_para(pAC, key, &vp)) {
764 free += vp.p_len + 3;
765 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
766 ("Overwrite Key\n"));
770 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
780 if (len + 3 > free) {
782 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
783 ("VPD Buffer Overflow, keyword not written\n"));
789 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
790 ("VPD Buffer Full, Keyword was cut\n"));
793 vpd_move_para(ip + vp.p_len + found, etp+2, len-vp.p_len+head);
794 vpd_insert_key(key, buf, len, ip);
795 if (vpd_mod_endtag(pAC, etp + len - vp.p_len + head)) {
796 pAC->vpd.v.vpd_status &= ~VPD_VALID;
797 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
798 ("VPD Encoding Error\n"));
807 * Read the contents of the VPD EEPROM and copy it to the
808 * VPD buffer if not already done.
810 * return: A pointer to the vpd_status structure. The structure contains
813 SK_VPD_STATUS *VpdStat(
814 SK_AC *pAC, /* Adapters context */
815 SK_IOC IoC) /* IO Context */
817 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
818 (void)VpdInit(pAC, IoC);
825 * Read the contents of the VPD EEPROM and copy it to the VPD
826 * buffer if not already done.
827 * Scan the VPD buffer for VPD keywords and create the VPD
828 * keyword list by copying the keywords to 'buf', all after
829 * each other and terminated with a '\0'.
831 * Exceptions: o The Resource Type ID String (product name) is called "Name"
832 * o The VPD end tags 'RV' and 'RW' are not listed
834 * The number of copied keywords is counted in 'elements'.
837 * 2: buffer overfull, one or more keywords are missing
840 * example values after returning:
842 * buf = "Name\0PN\0EC\0MN\0SN\0CP\0VF\0VL\0YA\0"
847 SK_AC *pAC, /* common data base */
848 SK_IOC IoC, /* IO Context */
849 char *buf, /* buffer where to copy the keywords */
850 int *len, /* buffer length */
851 int *elements) /* number of keywords returned */
856 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("list VPD keys .. "));
858 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
859 if (VpdInit(pAC, IoC) != 0) {
861 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
862 ("VPD Init Error, terminated\n"));
867 if ((signed)strlen(VPD_NAME) + 1 <= *len) {
868 v = pAC->vpd.vpd_buf;
869 strcpy(buf,VPD_NAME);
870 n = strlen(VPD_NAME) + 1;
873 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
874 ("'%c%c' ",v[0],v[1]));
878 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,
879 ("buffer overflow\n"));
883 v += 3 + VPD_GET_RES_LEN(v) + 3;
885 /* exit when reaching the "RW" Tag */
886 if (SK_MEMCMP(VPD_RW,v,2) == 0) {
890 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
891 v += 3 + VPD_GET_VPD_LEN(v) + 3; /* skip VPD-W */
900 v += 3 + VPD_GET_VPD_LEN(v);
902 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
903 ("'%c%c' ",v[0],v[1]));
907 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
908 ("buffer overflow\n"));
913 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("\n"));
920 * Read the contents of the VPD EEPROM and copy it to the
921 * VPD buffer if not already done. Search for the VPD keyword
922 * 'key' and copy its value to 'buf'. Add a terminating '\0'.
923 * If the value does not fit into the buffer cut it after
927 * 1: keyword not found
928 * 2: value string was cut
929 * 3: VPD transfer timeout
933 SK_AC *pAC, /* common data base */
934 SK_IOC IoC, /* IO Context */
935 const char *key, /* keyword to read (e.g. "MN") */
936 char *buf, /* buffer where to copy the keyword value */
937 int *len) /* buffer length */
941 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("VPD read %s .. ", key));
942 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
943 if (VpdInit(pAC, IoC) != 0) {
945 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
946 ("VPD init error\n"));
951 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
952 if (p->p_len > (*(unsigned *)len)-1) {
955 SK_MEMCPY(buf, p->p_val, p->p_len);
956 buf[p->p_len] = '\0';
958 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
959 ("%c%c%c%c.., len = %d\n",
960 buf[0],buf[1],buf[2],buf[3],*len));
964 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR, ("not found\n"));
972 * Check whether a given key may be written
975 * SK_TRUE Yes it may be written
976 * SK_FALSE No it may be written
979 char *key) /* keyword to write (allowed values "Yx", "Vx") */
981 if ((*key != 'Y' && *key != 'V') ||
982 key[1] < '0' || key[1] > 'Z' ||
983 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
991 * Read the contents of the VPD EEPROM and copy it to the VPD
992 * buffer if not already done. Insert/overwrite the keyword 'key'
993 * in the VPD buffer. Cut the keyword value if it does not fit
994 * into the VPD read / write area.
997 * 2: value string was cut
998 * 3: VPD transfer timeout
999 * 4: VPD full, keyword was not written
1000 * 5: keyword cannot be written
1001 * 6: fatal VPD error
1004 SK_AC *pAC, /* common data base */
1005 SK_IOC IoC, /* IO Context */
1006 const char *key, /* keyword to write (allowed values "Yx", "Vx") */
1007 const char *buf) /* buffer where the keyword value can be read from */
1009 int len; /* length of the keyword to write */
1010 int rtv; /* return code */
1013 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1014 ("VPD write %s = %s\n",key,buf));
1016 if ((*key != 'Y' && *key != 'V') ||
1017 key[1] < '0' || key[1] > 'Z' ||
1018 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
1020 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1021 ("illegal key tag, keyword not written\n"));
1025 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1026 if (VpdInit(pAC, IoC) != 0) {
1027 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1028 ("VPD init error\n"));
1035 if (len > VPD_MAX_LEN) {
1039 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1040 ("keyword too long, cut after %d bytes\n",VPD_MAX_LEN));
1042 if ((rtv2 = VpdSetupPara(pAC, key, buf, len, VPD_RW_KEY, OWR_KEY)) != 0) {
1043 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1044 ("VPD write error\n"));
1052 * Read the contents of the VPD EEPROM and copy it to the
1053 * VPD buffer if not already done. Remove the VPD keyword
1054 * 'key' from the VPD buffer.
1055 * Only the keywords in the read/write area can be deleted.
1056 * Keywords in the read only area cannot be deleted.
1058 * returns 0: success, keyword was removed
1059 * 1: keyword not found
1060 * 5: keyword cannot be deleted
1061 * 6: fatal VPD error
1064 SK_AC *pAC, /* common data base */
1065 SK_IOC IoC, /* IO Context */
1066 char *key) /* keyword to read (e.g. "MN") */
1072 vpd_size = pAC->vpd.vpd_size;
1074 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("VPD delete key %s\n",key));
1075 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1076 if (VpdInit(pAC, IoC) != 0) {
1077 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1078 ("VPD init error\n"));
1083 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
1084 if (p->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
1085 /* try to delete read only keyword */
1086 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1087 ("cannot delete RO keyword\n"));
1091 etp = pAC->vpd.vpd_buf + (vpd_size-pAC->vpd.v.vpd_free_rw-1-3);
1093 vpd_move_para(vp.p_val+vp.p_len, etp+2,
1094 - ((int)(vp.p_len + 3)));
1095 if (vpd_mod_endtag(pAC, etp - vp.p_len - 3)) {
1096 pAC->vpd.v.vpd_status &= ~VPD_VALID;
1097 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1098 ("VPD encoding error\n"));
1103 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1104 ("keyword not found\n"));
1112 * If the VPD buffer contains valid data write the VPD
1113 * read/write area back to the VPD EEPROM.
1115 * returns 0: success
1116 * 3: VPD transfer timeout
1119 SK_AC *pAC, /* Adapters context */
1120 SK_IOC IoC) /* IO Context */
1124 vpd_size = pAC->vpd.vpd_size;
1126 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("VPD update .. "));
1127 if ((pAC->vpd.v.vpd_status & VPD_VALID) != 0) {
1128 if (VpdTransferBlock(pAC, IoC, pAC->vpd.vpd_buf + vpd_size/2,
1129 vpd_size/2, vpd_size/2, VPD_WRITE) != vpd_size/2) {
1131 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1132 ("transfer timed out\n"));
1136 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("done\n"));
1143 * Read the contents of the VPD EEPROM and copy it to the VPD buffer
1144 * if not already done. If the keyword "VF" is not present it will be
1145 * created and the error log message will be stored to this keyword.
1146 * If "VF" is not present the error log message will be stored to the
1147 * keyword "VL". "VL" will created or overwritten if "VF" is present.
1148 * The VPD read/write area is saved to the VPD EEPROM.
1150 * returns nothing, errors will be ignored.
1153 SK_AC *pAC, /* common data base */
1154 SK_IOC IoC, /* IO Context */
1155 char *msg) /* error log message */
1157 SK_VPD_PARA *v, vf; /* VF */
1160 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1161 ("VPD error log msg %s\n", msg));
1162 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1163 if (VpdInit(pAC, IoC) != 0) {
1164 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1165 ("VPD init error\n"));
1171 if (len > VPD_MAX_LEN) {
1175 if ((v = vpd_find_para(pAC, VPD_VF, &vf)) != NULL) {
1176 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("overwrite VL\n"));
1177 (void)VpdSetupPara(pAC, VPD_VL, msg, len, VPD_RW_KEY, OWR_KEY);
1180 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("write VF\n"));
1181 (void)VpdSetupPara(pAC, VPD_VF, msg, len, VPD_RW_KEY, ADD_KEY);
1184 (void)VpdUpdate(pAC, IoC);