1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163#include <config.h>
164
165
166
167
168static const char SysKonnectFileId[] =
169 "@(#)$Id: skvpd.c,v 1.37 2003/01/13 10:42:45 rschmidt Exp $ (C) SK";
170
171#include "h/skdrv1st.h"
172#include "h/sktypes.h"
173#include "h/skdebug.h"
174#include "h/skdrv2nd.h"
175
176
177
178
179#ifndef SK_KR_PROTO
180static SK_VPD_PARA *vpd_find_para(
181 SK_AC *pAC,
182 const char *key,
183 SK_VPD_PARA *p);
184#else
185static SK_VPD_PARA *vpd_find_para();
186#endif
187
188
189
190
191
192
193
194
195static int VpdWait(
196SK_AC *pAC,
197SK_IOC IoC,
198int event)
199{
200 SK_U64 start_time;
201 SK_U16 state;
202
203 SK_DBG_MSG(pAC,SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
204 ("VPD wait for %s\n", event?"Write":"Read"));
205 start_time = SkOsGetTime(pAC);
206 do {
207 if (SkOsGetTime(pAC) - start_time > SK_TICKS_PER_SEC) {
208
209
210
211
212
213
214
215
216
217
218
219
220
221 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_FATAL | SK_DBGCAT_ERR,
222 ("ERROR:VPD wait timeout\n"));
223 return(1);
224 }
225
226 VPD_IN16(pAC, IoC, PCI_VPD_ADR_REG, &state);
227
228 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
229 ("state = %x, event %x\n",state,event));
230 } while((int)(state & PCI_VPD_FLAG) == event);
231
232 return(0);
233}
234
235#ifdef SKDIAG
236
237
238
239
240
241
242
243
244
245
246
247SK_U32 VpdReadDWord(
248SK_AC *pAC,
249SK_IOC IoC,
250int addr)
251{
252 SK_U32 Rtv;
253
254
255 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
256 ("VPD read dword at 0x%x\n",addr));
257 addr &= ~VPD_WRITE;
258
259 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, (SK_U16)addr);
260
261
262 (void)VpdWait(pAC, IoC, VPD_READ);
263
264
265 Rtv = 0;
266
267 VPD_IN32(pAC, IoC, PCI_VPD_DAT_REG, &Rtv);
268
269 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
270 ("VPD read dword data = 0x%x\n",Rtv));
271 return(Rtv);
272}
273
274#endif
275
276#if 0
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301static int VpdWriteDWord(
302SK_AC *pAC,
303SK_IOC IoC,
304int addr,
305SK_U32 data)
306{
307
308
309 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
310 ("VPD write dword at addr 0x%x, data = 0x%x\n",addr,data));
311 VPD_OUT32(pAC, IoC, PCI_VPD_DAT_REG, (SK_U32)data);
312
313 addr |= VPD_WRITE;
314
315 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, (SK_U16)(addr | VPD_WRITE));
316
317
318 if (VpdWait(pAC, IoC, VPD_WRITE)) {
319 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
320 ("Write Timed Out\n"));
321 return(1);
322 };
323
324
325 if (VpdReadDWord(pAC, IoC, addr) != data) {
326 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
327 ("Data Verify Error\n"));
328 return(2);
329 }
330 return(0);
331}
332
333#endif
334
335
336
337
338
339
340
341static int VpdWriteStream(
342SK_AC *pAC,
343SK_IOC IoC,
344char *buf,
345int Addr,
346int Len)
347{
348 int i;
349 int j;
350 SK_U16 AdrReg;
351 int Rtv;
352 SK_U8 * pComp;
353 SK_U8 Data;
354
355
356 pComp = (SK_U8 *) buf;
357
358 for (i = 0; i < Len; i++, buf++) {
359 if ((i%sizeof(SK_U32)) == 0) {
360
361
362
363
364
365 AdrReg = (SK_U16) Addr;
366 AdrReg &= ~VPD_WRITE;
367
368 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
369
370
371 Rtv = VpdWait(pAC, IoC, VPD_READ);
372 if (Rtv != 0) {
373 return(i);
374 }
375 }
376
377
378 VPD_OUT8(pAC, IoC, PCI_VPD_DAT_REG + (i%sizeof(SK_U32)),
379 *(SK_U8*)buf);
380
381 if (((i%sizeof(SK_U32)) == 3) || (i == (Len - 1))) {
382
383 AdrReg = (SK_U16) Addr;
384 Addr += sizeof(SK_U32);
385 AdrReg |= VPD_WRITE;
386
387 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
388
389
390 Rtv = VpdWait(pAC, IoC, VPD_WRITE);
391 if (Rtv != 0) {
392 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
393 ("Write Timed Out\n"));
394 return(i - (i%sizeof(SK_U32)));
395 }
396
397
398
399
400 AdrReg &= ~VPD_WRITE;
401
402 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
403
404
405 Rtv = VpdWait(pAC, IoC, VPD_READ);
406 if (Rtv != 0) {
407 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
408 ("Verify Timed Out\n"));
409 return(i - (i%sizeof(SK_U32)));
410 }
411
412 for (j = 0; j <= (int)(i%sizeof(SK_U32)); j++, pComp++) {
413
414 VPD_IN8(pAC, IoC, PCI_VPD_DAT_REG + j, &Data);
415
416 if (Data != *pComp) {
417
418 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
419 ("WriteStream Verify Error\n"));
420 return(i - (i%sizeof(SK_U32)) + j);
421 }
422 }
423 }
424 }
425
426 return(Len);
427}
428
429
430
431
432
433
434
435
436static int VpdReadStream(
437SK_AC *pAC,
438SK_IOC IoC,
439char *buf,
440int Addr,
441int Len)
442{
443 int i;
444 SK_U16 AdrReg;
445 int Rtv;
446
447 for (i = 0; i < Len; i++, buf++) {
448 if ((i%sizeof(SK_U32)) == 0) {
449
450 AdrReg = (SK_U16) Addr;
451 Addr += sizeof(SK_U32);
452 AdrReg &= ~VPD_WRITE;
453
454 VPD_OUT16(pAC, IoC, PCI_VPD_ADR_REG, AdrReg);
455
456
457 Rtv = VpdWait(pAC, IoC, VPD_READ);
458 if (Rtv != 0) {
459 return(i);
460 }
461 }
462 VPD_IN8(pAC, IoC, PCI_VPD_DAT_REG + (i%sizeof(SK_U32)),
463 (SK_U8 *)buf);
464 }
465
466 return(Len);
467}
468
469
470
471
472
473
474
475static int VpdTransferBlock(
476SK_AC *pAC,
477SK_IOC IoC,
478char *buf,
479int addr,
480int len,
481int dir)
482{
483 int Rtv;
484 int vpd_rom_size;
485
486 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
487 ("VPD %s block, addr = 0x%x, len = %d\n",
488 dir ? "write" : "read", addr, len));
489
490 if (len == 0)
491 return(0);
492
493 vpd_rom_size = pAC->vpd.rom_size;
494
495 if (addr > vpd_rom_size - 4) {
496 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
497 ("Address error: 0x%x, exp. < 0x%x\n",
498 addr, vpd_rom_size - 4));
499 return(0);
500 }
501
502 if (addr + len > vpd_rom_size) {
503 len = vpd_rom_size - addr;
504 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
505 ("Warning: len was cut to %d\n", len));
506 }
507
508 if (dir == VPD_READ) {
509 Rtv = VpdReadStream(pAC, IoC, buf, addr, len);
510 }
511 else {
512 Rtv = VpdWriteStream(pAC, IoC, buf, addr, len);
513 }
514
515 return(Rtv);
516}
517
518#ifdef SKDIAG
519
520
521
522
523
524
525int VpdReadBlock(
526SK_AC *pAC,
527SK_IOC IoC,
528char *buf,
529int addr,
530int len)
531{
532 return(VpdTransferBlock(pAC, IoC, buf, addr, len, VPD_READ));
533}
534
535
536
537
538
539
540int VpdWriteBlock(
541SK_AC *pAC,
542SK_IOC IoC,
543char *buf,
544int addr,
545int len)
546{
547 return(VpdTransferBlock(pAC, IoC, buf, addr, len, VPD_WRITE));
548}
549#endif
550
551
552
553
554
555
556
557
558
559
560static int VpdInit(
561SK_AC *pAC,
562SK_IOC IoC)
563{
564 SK_VPD_PARA *r, rp;
565 int i;
566 unsigned char x;
567 int vpd_size;
568 SK_U16 dev_id;
569 SK_U32 our_reg2;
570
571 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_INIT, ("VpdInit .. "));
572
573 VPD_IN16(pAC, IoC, PCI_DEVICE_ID, &dev_id);
574
575 VPD_IN32(pAC, IoC, PCI_OUR_REG_2, &our_reg2);
576
577 pAC->vpd.rom_size = 256 << ((our_reg2 & PCI_VPD_ROM_SZ) >> 14);
578
579
580
581
582
583 if (((pAC->vpd.v.vpd_status & VPD_VALID) == 0 &&
584 dev_id != VPD_DEV_ID_GENESIS) ||
585 ((pAC->vpd.v.vpd_status & VPD_VALID) != 0 &&
586 !pAC->GIni.GIGenesis)) {
587
588
589 vpd_size = VPD_SIZE_YUKON;
590 }
591 else {
592
593 if (pAC->vpd.rom_size > VPD_SIZE_GENESIS) {
594 vpd_size = VPD_SIZE_GENESIS;
595 }
596 else {
597 vpd_size = pAC->vpd.rom_size;
598 }
599 }
600
601
602 if (VpdTransferBlock(pAC, IoC, pAC->vpd.vpd_buf, 0, vpd_size, VPD_READ)
603 != vpd_size) {
604
605 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
606 ("Block Read Error\n"));
607 return(1);
608 }
609
610 pAC->vpd.vpd_size = vpd_size;
611
612
613 if (!(r = vpd_find_para(pAC, VPD_RV, &rp))) {
614 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
615 ("Encoding Error: RV Tag not found\n"));
616 return(1);
617 }
618
619 if (r->p_val + r->p_len > pAC->vpd.vpd_buf + vpd_size/2) {
620 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
621 ("Encoding Error: Invalid VPD struct size\n"));
622 return(1);
623 }
624 pAC->vpd.v.vpd_free_ro = r->p_len - 1;
625
626
627 for (i = 0, x = 0; (unsigned)i <= (unsigned)vpd_size/2 - r->p_len; i++) {
628 x += pAC->vpd.vpd_buf[i];
629 }
630
631 if (x != 0) {
632
633 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
634 ("VPD Checksum Error\n"));
635 return(1);
636 }
637
638
639 if (!(r = vpd_find_para(pAC, VPD_RW, &rp))) {
640 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
641 ("Encoding Error: RV Tag not found\n"));
642 return(1);
643 }
644
645 if (r->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
646 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
647 ("Encoding Error: Invalid VPD struct size\n"));
648 return(1);
649 }
650 pAC->vpd.v.vpd_free_rw = r->p_len;
651
652
653 if (pAC->GIni.GIChipId != 0) {
654 pAC->vpd.v.vpd_status |= VPD_VALID;
655 }
656
657 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_INIT,
658 ("done. Free RO = %d, Free RW = %d\n",
659 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
660
661 return(0);
662}
663
664
665
666
667
668
669
670
671static SK_VPD_PARA *vpd_find_para(
672SK_AC *pAC,
673const char *key,
674SK_VPD_PARA *p)
675{
676 char *v ;
677 int max;
678
679 v = pAC->vpd.vpd_buf;
680 max = 128;
681
682 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
683 ("VPD find para %s .. ",key));
684
685
686 if (*v != (char)RES_ID) {
687 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
688 ("Error: 0x%x missing\n", RES_ID));
689 return(0);
690 }
691
692 if (strcmp(key, VPD_NAME) == 0) {
693 p->p_len = VPD_GET_RES_LEN(v);
694 p->p_val = VPD_GET_VAL(v);
695 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
696 ("found, len = %d\n", p->p_len));
697 return(p);
698 }
699
700 v += 3 + VPD_GET_RES_LEN(v) + 3;
701 for (;; ) {
702 if (SK_MEMCMP(key,v,2) == 0) {
703 p->p_len = VPD_GET_VPD_LEN(v);
704 p->p_val = VPD_GET_VAL(v);
705 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
706 ("found, len = %d\n",p->p_len));
707 return(p);
708 }
709
710
711 max--;
712 if (SK_MEMCMP(VPD_RW,v,2) == 0 || max == 0) {
713 break;
714 }
715
716 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
717 v += 3 + VPD_GET_VPD_LEN(v) + 3;
718 }
719 else {
720 v += 3 + VPD_GET_VPD_LEN(v);
721 }
722 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
723 ("scanning '%c%c' len = %d\n",v[0],v[1],v[2]));
724 }
725
726#ifdef DEBUG
727 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL, ("not found\n"));
728 if (max == 0) {
729 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
730 ("Key/Len Encoding error\n"));
731 }
732#endif
733 return(0);
734}
735
736
737
738
739
740
741
742static void vpd_move_para(
743char *start,
744char *end,
745int n)
746{
747 char *p;
748 int i;
749
750 if (n == 0)
751 return;
752
753 i = (int) (end - start + 1);
754 if (n < 0) {
755 p = start + n;
756 while (i != 0) {
757 *p++ = *start++;
758 i--;
759 }
760 }
761 else {
762 p = end + n;
763 while (i != 0) {
764 *p-- = *end--;
765 i--;
766 }
767 }
768}
769
770
771
772
773
774
775static void vpd_insert_key(
776const char *key,
777const char *buf,
778int len,
779char *ip)
780{
781 SK_VPD_KEY *p;
782
783 p = (SK_VPD_KEY *) ip;
784 p->p_key[0] = key[0];
785 p->p_key[1] = key[1];
786 p->p_len = (unsigned char) len;
787 SK_MEMCPY(&p->p_val,buf,len);
788}
789
790
791
792
793
794
795
796
797static int vpd_mod_endtag(
798SK_AC *pAC,
799char *etp)
800{
801 SK_VPD_KEY *p;
802 unsigned char x;
803 int i;
804 int vpd_size;
805
806 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
807 ("VPD modify endtag at 0x%x = '%c%c'\n",etp,etp[0],etp[1]));
808
809 vpd_size = pAC->vpd.vpd_size;
810
811 p = (SK_VPD_KEY *) etp;
812
813 if (p->p_key[0] != 'R' || (p->p_key[1] != 'V' && p->p_key[1] != 'W')) {
814
815 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR | SK_DBGCAT_FATAL,
816 ("Encoding Error: invalid end tag\n"));
817 return(1);
818 }
819 if (etp > pAC->vpd.vpd_buf + vpd_size/2) {
820
821 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size-etp-3-1);
822 pAC->vpd.v.vpd_free_rw = (int) p->p_len;
823 i = pAC->vpd.v.vpd_free_rw;
824 etp += 3;
825 }
826 else {
827
828 p->p_len = (unsigned char)(pAC->vpd.vpd_buf+vpd_size/2-etp-3);
829 pAC->vpd.v.vpd_free_ro = (int) p->p_len - 1;
830
831
832 for (i = 0, x = 0; i < vpd_size/2 - p->p_len; i++) {
833 x += pAC->vpd.vpd_buf[i];
834 }
835 p->p_val = (char) 0 - x;
836 i = pAC->vpd.v.vpd_free_ro;
837 etp += 4;
838 }
839 while (i) {
840 *etp++ = 0x00;
841 i--;
842 }
843
844 return(0);
845}
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861int VpdSetupPara(
862SK_AC *pAC,
863const char *key,
864const char *buf,
865int len,
866int type,
867int op)
868{
869 SK_VPD_PARA vp;
870 char *etp;
871 int free;
872 char *ip;
873 int rtv;
874 int head;
875 int found;
876 int vpd_size;
877
878 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
879 ("VPD setup para key = %s, val = %s\n",key,buf));
880
881 vpd_size = pAC->vpd.vpd_size;
882
883 rtv = 0;
884 ip = 0;
885 if (type == VPD_RW_KEY) {
886
887 free = pAC->vpd.v.vpd_free_rw;
888 etp = pAC->vpd.vpd_buf + (vpd_size - free - 1 - 3);
889 }
890 else {
891
892 free = pAC->vpd.v.vpd_free_ro;
893 etp = pAC->vpd.vpd_buf + (vpd_size/2 - free - 4);
894 }
895 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
896 ("Free RO = %d, Free RW = %d\n",
897 pAC->vpd.v.vpd_free_ro, pAC->vpd.v.vpd_free_rw));
898
899 head = 0;
900 found = 0;
901 if (op == OWR_KEY) {
902 if (vpd_find_para(pAC, key, &vp)) {
903 found = 3;
904 ip = vp.p_val - 3;
905 free += vp.p_len + 3;
906 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
907 ("Overwrite Key\n"));
908 }
909 else {
910 op = ADD_KEY;
911 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_CTRL,
912 ("Add Key\n"));
913 }
914 }
915 if (op == ADD_KEY) {
916 ip = etp;
917 vp.p_len = 0;
918 head = 3;
919 }
920
921 if (len + 3 > free) {
922 if (free < 7) {
923 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
924 ("VPD Buffer Overflow, keyword not written\n"));
925 return(4);
926 }
927
928 len = free - 3;
929 rtv = 2;
930 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
931 ("VPD Buffer Full, Keyword was cut\n"));
932 }
933
934 vpd_move_para(ip + vp.p_len + found, etp+2, len-vp.p_len+head);
935 vpd_insert_key(key, buf, len, ip);
936 if (vpd_mod_endtag(pAC, etp + len - vp.p_len + head)) {
937 pAC->vpd.v.vpd_status &= ~VPD_VALID;
938 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
939 ("VPD Encoding Error\n"));
940 return(6);
941 }
942
943 return(rtv);
944}
945
946
947
948
949
950
951
952
953
954SK_VPD_STATUS *VpdStat(
955SK_AC *pAC,
956SK_IOC IoC)
957{
958 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
959 (void)VpdInit(pAC, IoC);
960 }
961 return(&pAC->vpd.v);
962}
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987int VpdKeys(
988SK_AC *pAC,
989SK_IOC IoC,
990char *buf,
991int *len,
992int *elements)
993{
994 char *v;
995 int n;
996
997 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("list VPD keys .. "));
998 *elements = 0;
999 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1000 if (VpdInit(pAC, IoC) != 0) {
1001 *len = 0;
1002 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1003 ("VPD Init Error, terminated\n"));
1004 return(6);
1005 }
1006 }
1007
1008 if ((signed)strlen(VPD_NAME) + 1 <= *len) {
1009 v = pAC->vpd.vpd_buf;
1010 strcpy(buf,VPD_NAME);
1011 n = strlen(VPD_NAME) + 1;
1012 buf += n;
1013 *elements = 1;
1014 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
1015 ("'%c%c' ",v[0],v[1]));
1016 }
1017 else {
1018 *len = 0;
1019 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_ERR,
1020 ("buffer overflow\n"));
1021 return(2);
1022 }
1023
1024 v += 3 + VPD_GET_RES_LEN(v) + 3;
1025 for (;; ) {
1026
1027 if (SK_MEMCMP(VPD_RW,v,2) == 0) {
1028 break;
1029 }
1030
1031 if (SK_MEMCMP(VPD_RV,v,2) == 0) {
1032 v += 3 + VPD_GET_VPD_LEN(v) + 3;
1033 continue;
1034 }
1035
1036 if (n+3 <= *len) {
1037 SK_MEMCPY(buf,v,2);
1038 buf += 2;
1039 *buf++ = '\0';
1040 n += 3;
1041 v += 3 + VPD_GET_VPD_LEN(v);
1042 *elements += 1;
1043 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
1044 ("'%c%c' ",v[0],v[1]));
1045 }
1046 else {
1047 *len = n;
1048 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1049 ("buffer overflow\n"));
1050 return(2);
1051 }
1052 }
1053
1054 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("\n"));
1055 *len = n;
1056 return(0);
1057}
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073int VpdRead(
1074SK_AC *pAC,
1075SK_IOC IoC,
1076const char *key,
1077char *buf,
1078int *len)
1079{
1080 SK_VPD_PARA *p, vp;
1081
1082 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX, ("VPD read %s .. ", key));
1083 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1084 if (VpdInit(pAC, IoC) != 0) {
1085 *len = 0;
1086 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1087 ("VPD init error\n"));
1088 return(6);
1089 }
1090 }
1091
1092 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
1093 if (p->p_len > (*(unsigned *)len)-1) {
1094 p->p_len = *len - 1;
1095 }
1096 SK_MEMCPY(buf, p->p_val, p->p_len);
1097 buf[p->p_len] = '\0';
1098 *len = p->p_len;
1099 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_RX,
1100 ("%c%c%c%c.., len = %d\n",
1101 buf[0],buf[1],buf[2],buf[3],*len));
1102 }
1103 else {
1104 *len = 0;
1105 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR, ("not found\n"));
1106 return(1);
1107 }
1108 return(0);
1109}
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119SK_BOOL VpdMayWrite(
1120char *key)
1121{
1122 if ((*key != 'Y' && *key != 'V') ||
1123 key[1] < '0' || key[1] > 'Z' ||
1124 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
1125
1126 return(SK_FALSE);
1127 }
1128 return(SK_TRUE);
1129}
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144int VpdWrite(
1145SK_AC *pAC,
1146SK_IOC IoC,
1147const char *key,
1148const char *buf)
1149{
1150 int len;
1151 int rtv;
1152 int rtv2;
1153
1154 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1155 ("VPD write %s = %s\n",key,buf));
1156
1157 if ((*key != 'Y' && *key != 'V') ||
1158 key[1] < '0' || key[1] > 'Z' ||
1159 (key[1] > '9' && key[1] < 'A') || strlen(key) != 2) {
1160
1161 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1162 ("illegal key tag, keyword not written\n"));
1163 return(5);
1164 }
1165
1166 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1167 if (VpdInit(pAC, IoC) != 0) {
1168 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1169 ("VPD init error\n"));
1170 return(6);
1171 }
1172 }
1173
1174 rtv = 0;
1175 len = strlen(buf);
1176 if (len > VPD_MAX_LEN) {
1177
1178 len = VPD_MAX_LEN;
1179 rtv = 2;
1180 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1181 ("keyword too long, cut after %d bytes\n",VPD_MAX_LEN));
1182 }
1183 if ((rtv2 = VpdSetupPara(pAC, key, buf, len, VPD_RW_KEY, OWR_KEY)) != 0) {
1184 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1185 ("VPD write error\n"));
1186 return(rtv2);
1187 }
1188
1189 return(rtv);
1190}
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204int VpdDelete(
1205SK_AC *pAC,
1206SK_IOC IoC,
1207char *key)
1208{
1209 SK_VPD_PARA *p, vp;
1210 char *etp;
1211 int vpd_size;
1212
1213 vpd_size = pAC->vpd.vpd_size;
1214
1215 SK_DBG_MSG(pAC,SK_DBGMOD_VPD,SK_DBGCAT_TX,("VPD delete key %s\n",key));
1216 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1217 if (VpdInit(pAC, IoC) != 0) {
1218 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1219 ("VPD init error\n"));
1220 return(6);
1221 }
1222 }
1223
1224 if ((p = vpd_find_para(pAC, key, &vp)) != NULL) {
1225 if (p->p_val < pAC->vpd.vpd_buf + vpd_size/2) {
1226
1227 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1228 ("cannot delete RO keyword\n"));
1229 return(5);
1230 }
1231
1232 etp = pAC->vpd.vpd_buf + (vpd_size-pAC->vpd.v.vpd_free_rw-1-3);
1233
1234 vpd_move_para(vp.p_val+vp.p_len, etp+2,
1235 - ((int)(vp.p_len + 3)));
1236 if (vpd_mod_endtag(pAC, etp - vp.p_len - 3)) {
1237 pAC->vpd.v.vpd_status &= ~VPD_VALID;
1238 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1239 ("VPD encoding error\n"));
1240 return(6);
1241 }
1242 }
1243 else {
1244 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1245 ("keyword not found\n"));
1246 return(1);
1247 }
1248
1249 return(0);
1250}
1251
1252
1253
1254
1255
1256
1257
1258
1259int VpdUpdate(
1260SK_AC *pAC,
1261SK_IOC IoC)
1262{
1263 int vpd_size;
1264
1265 vpd_size = pAC->vpd.vpd_size;
1266
1267 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("VPD update .. "));
1268 if ((pAC->vpd.v.vpd_status & VPD_VALID) != 0) {
1269 if (VpdTransferBlock(pAC, IoC, pAC->vpd.vpd_buf + vpd_size/2,
1270 vpd_size/2, vpd_size/2, VPD_WRITE) != vpd_size/2) {
1271
1272 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1273 ("transfer timed out\n"));
1274 return(3);
1275 }
1276 }
1277 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("done\n"));
1278 return(0);
1279}
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292void VpdErrLog(
1293SK_AC *pAC,
1294SK_IOC IoC,
1295char *msg)
1296{
1297 SK_VPD_PARA *v, vf;
1298 int len;
1299
1300 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX,
1301 ("VPD error log msg %s\n", msg));
1302 if ((pAC->vpd.v.vpd_status & VPD_VALID) == 0) {
1303 if (VpdInit(pAC, IoC) != 0) {
1304 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_ERR,
1305 ("VPD init error\n"));
1306 return;
1307 }
1308 }
1309
1310 len = strlen(msg);
1311 if (len > VPD_MAX_LEN) {
1312
1313 len = VPD_MAX_LEN;
1314 }
1315 if ((v = vpd_find_para(pAC, VPD_VF, &vf)) != NULL) {
1316 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("overwrite VL\n"));
1317 (void)VpdSetupPara(pAC, VPD_VL, msg, len, VPD_RW_KEY, OWR_KEY);
1318 }
1319 else {
1320 SK_DBG_MSG(pAC, SK_DBGMOD_VPD, SK_DBGCAT_TX, ("write VF\n"));
1321 (void)VpdSetupPara(pAC, VPD_VF, msg, len, VPD_RW_KEY, ADD_KEY);
1322 }
1323
1324 (void)VpdUpdate(pAC, IoC);
1325}
1326