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 /* Asus K8V Se Deluxe bugfix. Correct VPD content */
473 if (((unsigned char)pAC->vpd.vpd_buf[0x3f] == 0x38) &&
474 ((unsigned char)pAC->vpd.vpd_buf[0x40] == 0x3c) &&
475 ((unsigned char)pAC->vpd.vpd_buf[0x41] == 0x45)) {
476 printk("sk98lin: Asus mainboard with buggy VPD? "
477 "Correcting data.\n");
478 pAC->vpd.vpd_buf[0x40] = 0x38;
482 /* find the end tag of the RO area */
483 if (!(r = vpd_find_para(pAC, VPD_RV, &rp))) {
484 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
485 ("Encoding Error: RV Tag not found\n"));
489 if (r->p_val + r->p_len > pAC->vpd.vpd_buf + vpd_size/2) {
490 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
491 ("Encoding Error: Invalid VPD struct size\n"));
494 pAC->vpd.v.vpd_free_ro = r->p_len - 1;
496 /* test the checksum */
497 for (i = 0, x = 0; (unsigned)i <= (unsigned)vpd_size/2 - r->p_len; i++) {
498 x += pAC->vpd.vpd_buf[i];
503 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
504 ("VPD Checksum Error\n"));
508 /* find and check the end tag of the RW area */
509 if (!(r = vpd_find_para(pAC, VPD_RW, &rp))) {
510 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
511 ("Encoding Error: RV Tag not found\n"));
515 if (r->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
516 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
517 ("Encoding Error: Invalid VPD struct size\n"));
520 pAC->vpd.v.vpd_free_rw = r->p_len;
522 /* everything seems to be ok */
523 if (pAC->GIni.GIChipId != 0) {
524 pAC->vpd.v.vpd_status |= VPD_VALID;
527 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_INIT,
528 ("done. Free RO = %d, Free RW = %d\n",
529 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
535 * find the Keyword 'key' in the VPD buffer and fills the
536 * parameter struct 'p' with it's values
539 * 0: parameter was not found or VPD encoding error
541 static SK_VPD_PARA *vpd_find_para(
542 SK_AC *pAC, /* common data base */
543 const char *key, /* keyword to find (e.g. "MN") */
544 SK_VPD_PARA *p) /* parameter description struct */
546 char *v ; /* points to VPD buffer */
547 int max; /* Maximum Number of Iterations */
549 v = pAC->vpd.vpd_buf;
552 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
553 ("VPD find para %s .. ",key));
555 /* check mandatory resource type ID string (Product Name) */
556 if (*v != (char)RES_ID) {
557 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
558 ("Error: 0x%x missing\n", RES_ID));
562 if (strcmp(key, VPD_NAME) == 0) {
563 p->p_len = VPD_GET_RES_LEN(v);
564 p->p_val = VPD_GET_VAL(v);
565 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
566 ("found, len = %d\n", p->p_len));
570 v += 3 + VPD_GET_RES_LEN(v) + 3;
572 if (SK_MEMCMP(key,v,2) == 0) {
573 p->p_len = VPD_GET_VPD_LEN(v);
574 p->p_val = VPD_GET_VAL(v);
575 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
576 ("found, len = %d\n",p->p_len));
580 /* exit when reaching the "RW" Tag or the maximum of itera. */
582 if (SK_MEMCMP(VPD_RW,v,2) == 0 || max == 0) {
586 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
587 v += 3 + VPD_GET_VPD_LEN(v) + 3; /* skip VPD-W */
590 v += 3 + VPD_GET_VPD_LEN(v);
592 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
593 ("scanning '%c%c' len = %d\n",v[0],v[1],v[2]));
597 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL, ("not found\n"));
599 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
600 ("Key/Len Encoding error\n"));
607 * Move 'n' bytes. Begin with the last byte if 'n' is > 0,
608 * Start with the last byte if n is < 0.
612 static void vpd_move_para(
613 char *start, /* start of memory block */
614 char *end, /* end of memory block to move */
615 int n) /* number of bytes the memory block has to be moved */
618 int i; /* number of byte copied */
623 i = (int) (end - start + 1);
641 * setup the VPD keyword 'key' at 'ip'.
645 static void vpd_insert_key(
646 const char *key, /* keyword to insert */
647 const char *buf, /* buffer with the keyword value */
648 int len, /* length of the value string */
649 char *ip) /* inseration point */
653 p = (SK_VPD_KEY *) ip;
654 p->p_key[0] = key[0];
655 p->p_key[1] = key[1];
656 p->p_len = (unsigned char) len;
657 SK_MEMCPY(&p->p_val,buf,len);
661 * Setup the VPD end tag "RV" / "RW".
662 * Also correct the remaining space variables vpd_free_ro / vpd_free_rw.
667 static int vpd_mod_endtag(
668 SK_AC *pAC, /* common data base */
669 char *etp) /* end pointer input position */
676 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
677 ("VPD modify endtag at 0x%x = '%c%c'\n",etp,etp[0],etp[1]));
679 vpd_size = pAC->vpd.vpd_size;
681 p = (SK_VPD_KEY *) etp;
683 if (p->p_key[0] != 'R' || (p->p_key[1] != 'V' && p->p_key[1] != 'W')) {
684 /* something wrong here, encoding error */
685 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
686 ("Encoding Error: invalid end tag\n"));
689 if (etp > pAC->vpd.vpd_buf + vpd_size/2) {
690 /* create "RW" tag */
691 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size-etp-3-1);
692 pAC->vpd.v.vpd_free_rw = (int) p->p_len;
693 i = pAC->vpd.v.vpd_free_rw;
697 /* create "RV" tag */
698 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size/2-etp-3);
699 pAC->vpd.v.vpd_free_ro = (int) p->p_len - 1;
702 for (i = 0, x = 0; i < vpd_size/2 - p->p_len; i++) {
703 x += pAC->vpd.vpd_buf[i];
705 p->p_val = (char) 0 - x;
706 i = pAC->vpd.v.vpd_free_ro;
718 * Insert a VPD keyword into the VPD buffer.
720 * The keyword 'key' is inserted at the position 'ip' in the
722 * The keywords behind the input position will
723 * be moved. The VPD end tag "RV" or "RW" is generated again.
726 * 2: value string was cut
727 * 4: VPD full, keyword was not written
732 SK_AC *pAC, /* common data base */
733 const char *key, /* keyword to insert */
734 const char *buf, /* buffer with the keyword value */
735 int len, /* length of the keyword value */
736 int type, /* VPD_RO_KEY or VPD_RW_KEY */
737 int op) /* operation to do: ADD_KEY or OWR_KEY */
740 char *etp; /* end tag position */
741 int free; /* remaining space in selected area */
742 char *ip; /* input position inside the VPD buffer */
743 int rtv; /* return code */
744 int head; /* additional haeder bytes to move */
745 int found; /* additinoal bytes if the keyword was found */
748 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
749 ("VPD setup para key = %s, val = %s\n",key,buf));
751 vpd_size = pAC->vpd.vpd_size;
755 if (type == VPD_RW_KEY) {
756 /* end tag is "RW" */
757 free = pAC->vpd.v.vpd_free_rw;
758 etp = pAC->vpd.vpd_buf + (vpd_size - free - 1 - 3);
761 /* end tag is "RV" */
762 free = pAC->vpd.v.vpd_free_ro;
763 etp = pAC->vpd.vpd_buf + (vpd_size/2 - free - 4);
765 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
766 ("Free RO = %d, Free RW = %d\n",
767 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
772 if (vpd_find_para(pAC, key, &vp)) {
775 free += vp.p_len + 3;
776 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
777 ("Overwrite Key\n"));
781 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
791 if (len + 3 > free) {
793 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
794 ("VPD Buffer Overflow, keyword not written\n"));
800 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
801 ("VPD Buffer Full, Keyword was cut\n"));
804 vpd_move_para(ip + vp.p_len + found, etp+2, len-vp.p_len+head);
805 vpd_insert_key(key, buf, len, ip);
806 if (vpd_mod_endtag(pAC, etp + len - vp.p_len + head)) {
807 pAC->vpd.v.vpd_status &= ~VPD_VALID;
808 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
809 ("VPD Encoding Error\n"));
818 * Read the contents of the VPD EEPROM and copy it to the
819 * VPD buffer if not already done.
821 * return: A pointer to the vpd_status structure. The structure contains
824 SK_VPD_STATUS *VpdStat(
825 SK_AC *pAC, /* Adapters context */
826 SK_IOC IoC) /* IO Context */
828 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
829 (void)VpdInit(pAC, IoC);
836 * Read the contents of the VPD EEPROM and copy it to the VPD
837 * buffer if not already done.
838 * Scan the VPD buffer for VPD keywords and create the VPD
839 * keyword list by copying the keywords to 'buf', all after
840 * each other and terminated with a '\0'.
842 * Exceptions: o The Resource Type ID String (product name) is called "Name"
843 * o The VPD end tags 'RV' and 'RW' are not listed
845 * The number of copied keywords is counted in 'elements'.
848 * 2: buffer overfull, one or more keywords are missing
851 * example values after returning:
853 * buf = "Name\0PN\0EC\0MN\0SN\0CP\0VF\0VL\0YA\0"
858 SK_AC *pAC, /* common data base */
859 SK_IOC IoC, /* IO Context */
860 char *buf, /* buffer where to copy the keywords */
861 int *len, /* buffer length */
862 int *elements) /* number of keywords returned */
867 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("list VPD keys .. "));
869 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
870 if (VpdInit(pAC, IoC) != 0) {
872 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
873 ("VPD Init Error, terminated\n"));
878 if ((signed)strlen(VPD_NAME) + 1 <= *len) {
879 v = pAC->vpd.vpd_buf;
880 strcpy(buf,VPD_NAME);
881 n = strlen(VPD_NAME) + 1;
884 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
885 ("'%c%c' ",v[0],v[1]));
889 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,
890 ("buffer overflow\n"));
894 v += 3 + VPD_GET_RES_LEN(v) + 3;
896 /* exit when reaching the "RW" Tag */
897 if (SK_MEMCMP(VPD_RW,v,2) == 0) {
901 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
902 v += 3 + VPD_GET_VPD_LEN(v) + 3; /* skip VPD-W */
911 v += 3 + VPD_GET_VPD_LEN(v);
913 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
914 ("'%c%c' ",v[0],v[1]));
918 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
919 ("buffer overflow\n"));
924 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("\n"));
931 * Read the contents of the VPD EEPROM and copy it to the
932 * VPD buffer if not already done. Search for the VPD keyword
933 * 'key' and copy its value to 'buf'. Add a terminating '\0'.
934 * If the value does not fit into the buffer cut it after
938 * 1: keyword not found
939 * 2: value string was cut
940 * 3: VPD transfer timeout
944 SK_AC *pAC, /* common data base */
945 SK_IOC IoC, /* IO Context */
946 const char *key, /* keyword to read (e.g. "MN") */
947 char *buf, /* buffer where to copy the keyword value */
948 int *len) /* buffer length */
952 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("VPD read %s .. ", key));
953 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
954 if (VpdInit(pAC, IoC) != 0) {
956 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
957 ("VPD init error\n"));
962 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
963 if (p->p_len > (*(unsigned *)len)-1) {
966 SK_MEMCPY(buf, p->p_val, p->p_len);
967 buf[p->p_len] = '\0';
969 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
970 ("%c%c%c%c.., len = %d\n",
971 buf[0],buf[1],buf[2],buf[3],*len));
975 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR, ("not found\n"));
983 * Check whether a given key may be written
986 * SK_TRUE Yes it may be written
987 * SK_FALSE No it may be written
990 char *key) /* keyword to write (allowed values "Yx", "Vx") */
992 if ((*key != 'Y' && *key != 'V') ||
993 key[1] < '0' || key[1] > 'Z' ||
994 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
1002 * Read the contents of the VPD EEPROM and copy it to the VPD
1003 * buffer if not already done. Insert/overwrite the keyword 'key'
1004 * in the VPD buffer. Cut the keyword value if it does not fit
1005 * into the VPD read / write area.
1007 * returns 0: success
1008 * 2: value string was cut
1009 * 3: VPD transfer timeout
1010 * 4: VPD full, keyword was not written
1011 * 5: keyword cannot be written
1012 * 6: fatal VPD error
1015 SK_AC *pAC, /* common data base */
1016 SK_IOC IoC, /* IO Context */
1017 const char *key, /* keyword to write (allowed values "Yx", "Vx") */
1018 const char *buf) /* buffer where the keyword value can be read from */
1020 int len; /* length of the keyword to write */
1021 int rtv; /* return code */
1024 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1025 ("VPD write %s = %s\n",key,buf));
1027 if ((*key != 'Y' && *key != 'V') ||
1028 key[1] < '0' || key[1] > 'Z' ||
1029 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
1031 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1032 ("illegal key tag, keyword not written\n"));
1036 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1037 if (VpdInit(pAC, IoC) != 0) {
1038 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1039 ("VPD init error\n"));
1046 if (len > VPD_MAX_LEN) {
1050 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1051 ("keyword too long, cut after %d bytes\n",VPD_MAX_LEN));
1053 if ((rtv2 = VpdSetupPara(pAC, key, buf, len, VPD_RW_KEY, OWR_KEY)) != 0) {
1054 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1055 ("VPD write error\n"));
1063 * Read the contents of the VPD EEPROM and copy it to the
1064 * VPD buffer if not already done. Remove the VPD keyword
1065 * 'key' from the VPD buffer.
1066 * Only the keywords in the read/write area can be deleted.
1067 * Keywords in the read only area cannot be deleted.
1069 * returns 0: success, keyword was removed
1070 * 1: keyword not found
1071 * 5: keyword cannot be deleted
1072 * 6: fatal VPD error
1075 SK_AC *pAC, /* common data base */
1076 SK_IOC IoC, /* IO Context */
1077 char *key) /* keyword to read (e.g. "MN") */
1083 vpd_size = pAC->vpd.vpd_size;
1085 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("VPD delete key %s\n",key));
1086 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1087 if (VpdInit(pAC, IoC) != 0) {
1088 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1089 ("VPD init error\n"));
1094 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
1095 if (p->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
1096 /* try to delete read only keyword */
1097 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1098 ("cannot delete RO keyword\n"));
1102 etp = pAC->vpd.vpd_buf + (vpd_size-pAC->vpd.v.vpd_free_rw-1-3);
1104 vpd_move_para(vp.p_val+vp.p_len, etp+2,
1105 - ((int)(vp.p_len + 3)));
1106 if (vpd_mod_endtag(pAC, etp - vp.p_len - 3)) {
1107 pAC->vpd.v.vpd_status &= ~VPD_VALID;
1108 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1109 ("VPD encoding error\n"));
1114 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1115 ("keyword not found\n"));
1123 * If the VPD buffer contains valid data write the VPD
1124 * read/write area back to the VPD EEPROM.
1126 * returns 0: success
1127 * 3: VPD transfer timeout
1130 SK_AC *pAC, /* Adapters context */
1131 SK_IOC IoC) /* IO Context */
1135 vpd_size = pAC->vpd.vpd_size;
1137 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("VPD update .. "));
1138 if ((pAC->vpd.v.vpd_status & VPD_VALID) != 0) {
1139 if (VpdTransferBlock(pAC, IoC, pAC->vpd.vpd_buf + vpd_size/2,
1140 vpd_size/2, vpd_size/2, VPD_WRITE) != vpd_size/2) {
1142 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1143 ("transfer timed out\n"));
1147 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("done\n"));
1154 * Read the contents of the VPD EEPROM and copy it to the VPD buffer
1155 * if not already done. If the keyword "VF" is not present it will be
1156 * created and the error log message will be stored to this keyword.
1157 * If "VF" is not present the error log message will be stored to the
1158 * keyword "VL". "VL" will created or overwritten if "VF" is present.
1159 * The VPD read/write area is saved to the VPD EEPROM.
1161 * returns nothing, errors will be ignored.
1164 SK_AC *pAC, /* common data base */
1165 SK_IOC IoC, /* IO Context */
1166 char *msg) /* error log message */
1168 SK_VPD_PARA *v, vf; /* VF */
1171 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1172 ("VPD error log msg %s\n", msg));
1173 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1174 if (VpdInit(pAC, IoC) != 0) {
1175 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1176 ("VPD init error\n"));
1182 if (len > VPD_MAX_LEN) {
1186 if ((v = vpd_find_para(pAC, VPD_VF, &vf)) != NULL) {
1187 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("overwrite VL\n"));
1188 (void)VpdSetupPara(pAC, VPD_VL, msg, len, VPD_RW_KEY, OWR_KEY);
1191 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("write VF\n"));
1192 (void)VpdSetupPara(pAC, VPD_VF, msg, len, VPD_RW_KEY, ADD_KEY);
1195 (void)VpdUpdate(pAC, IoC);