-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmpt_tabified.c
2631 lines (2162 loc) · 63.7 KB
/
mpt_tabified.c
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
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
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
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* mpt -- simple driver for MPT adapters (FC, SCSI, and SAS/SATA)
*
* Written by Stephen F. Shirron, August 9, 2005
*/
#ifdef DISABLE_TIMEOUTS
static time_t local_time = 0;
#define time(x) (local_time)
#endif
#define NUM_REPLIES 7
#define REPLY_FREE_SIZE 8
#define REPLY_POST_SIZE 16
#define COMMAND_CONTEXT 0x111111
#define PASS_THRU_CONTEXT 0x555555
#define mpi1 (adap->mpt_version < MPI2_VERSION_02_00)
#define mpi2 (adap->mpt_version >= MPI2_VERSION_02_00)
typedef struct mpt_io_rep
{
union
{
SCSIIOReply_t default_reply;
U32 reply[32];
} mf;
} mpt_io_rep_t;
typedef struct mpt_shared
{
mpt_io_rep_t replies[NUM_REPLIES];
U32 message[32];
U32 free_queue[REPLY_FREE_SIZE];
MPI2_DEFAULT_REPLY_DESCRIPTOR
post_queue[REPLY_POST_SIZE];
U16 data[64];
U32 config[256];
U8 scratch[1024*1024];
U32 hrsm_value;
} mpt_shared_t;
typedef struct mpt_adap
{
MPT_PORT *port;
HANDLE partner_adap;
char *name;
U16 vendor_id;
U16 device_id;
U8 revision_id;
U8 segment_number;
U8 bus_number;
U8 device_function;
int mpt_version;
int hrsm_capable;
U32 hrsm_value;
U32 msg_context;
int restart_needed;
int port_enable_needed;
int config_active;
int command_active;
mpt_shared_t *shared;
mpt_bus_addr_t shared_ba;
int message_size;
int reply_depth;
int credits;
int port_count;
int block_size;
int port_type;
int host_id;
U32 interrupt_mask;
int max_targets;
int bus_reset_needed;
U32 capabilities[16];
int ioc_online;
int port_online;
int bootloader;
int loaddevice;
U8 *fw_image;
int fw_image_size;
int fw_image_asked;
U32 mem_size;
U32 diagmem_size;
#if DOS
U32 io_addr;
U32 mem_addr;
U32 mem_virt;
U32 diagmem_addr;
U32 diagmem_virt;
CONTIGUOUS_MEMORY shared_contig_mem;
#endif
#if EFI
EFI_HANDLE handle;
EFI_PCI_IO_PROTOCOL *pci_io;
void *buffer_mapping;
int disconnected;
#endif
int io;
int mem;
int diagmem;
int free_index;
int post_index;
} mpt_adap_t;
#define rl(x) mpt_read32(adap, MPI_##x##_OFFSET, adap->mem)
#define wl(x,y) mpt_write32(adap, MPI_##x##_OFFSET, y, adap->mem)
#define rl2(x) mpt_read32(adap, MPI2_##x##_OFFSET, adap->mem)
#define wl2(x,y) mpt_write32(adap, MPI2_##x##_OFFSET, y, adap->mem)
#define rlio(x) mpt_read32(adap, MPI_##x##_OFFSET, adap->io)
#define wlio(x,y) mpt_write32(adap, MPI_##x##_OFFSET, y, adap->io)
#define rldiag(x,y) wl(TEST_BASE_ADDRESS, x & ~mask); y = mpt_read32(adap, x & mask, adap->diagmem)
#define wldiag(x,y) wl(TEST_BASE_ADDRESS, x & ~mask); mpt_write32(adap, x & mask, y, adap->diagmem)
U32 mpt_read32(mpt_adap_t *adap, int offset, int bar)
{
U32 data;
#if DOS
if (bar == adap->mem)
data = *(U32 *)(adap->mem_virt + offset);
else if (bar == adap->diagmem)
data = *(U32 *)(adap->diagmem_virt + offset);
else
data = inpd(adap->io_addr + offset);
#endif
#if EFI
if (bar == adap->mem || bar == adap->diagmem)
adap->pci_io->Mem.Read(adap->pci_io, EfiPciIoWidthUint32, (char)bar, offset, 1, &data);
else
adap->pci_io->Io.Read(adap->pci_io, EfiPciIoWidthUint32, (char)bar, offset, 1, &data);
#endif
return data;
}
void mpt_write32(mpt_adap_t *adap, int offset, U32 data, int bar)
{
#if DOS
if (bar == adap->mem)
*(U32 *)(adap->mem_virt + offset) = data;
else if (bar == adap->diagmem)
*(U32 *)(adap->diagmem_virt + offset) = data;
else
outpd(adap->io_addr + offset, data);
#endif
#if EFI
if (bar == adap->mem || bar == adap->diagmem)
adap->pci_io->Mem.Write(adap->pci_io, EfiPciIoWidthUint32, (char)bar, offset, 1, &data);
else
adap->pci_io->Io.Write(adap->pci_io, EfiPciIoWidthUint32, (char)bar, offset, 1, &data);
#endif
}
void mpt_write8(mpt_adap_t *adap, int offset, U8 data)
{
#if DOS
*(U8 *)(adap->diagmem_virt + offset) = data;
#endif
#if EFI
adap->pci_io->Mem.Write(adap->pci_io, EfiPciIoWidthUint8, (char)adap->diagmem, offset, 1, &data);
#endif
}
#define MPI_DEBUG_OFFSET 0x18
#define MPI_FC909_BUG_OFFSET 0x90
#define MPI_SAS1078_RESET_OFFSET 0x10FC
int mpt_adjust_delay(mpt_adap_t *adap, int n);
void mpt_delay(mpt_adap_t *adap, int n);
int mpt_get_doorbell(mpt_adap_t *adap);
int mpt_get_state(mpt_adap_t *adap);
int mpt_verify_enabled(mpt_adap_t *adap);
int mpt_verify_ready(mpt_adap_t *adap);
int mpt_verify_operational(mpt_adap_t *adap);
int mpt_wait_for_ready(mpt_adap_t *adap);
int mpt_restart(mpt_adap_t *adap);
int mpt_stop(mpt_adap_t *adap, int wait);
int mpt_start(mpt_adap_t *adap);
int mpt_port_online(mpt_adap_t *adap);
int mpt_wait_for_doorbell(mpt_adap_t *adap, time_t limit);
int mpt_wait_for_response(mpt_adap_t *adap, time_t limit);
int mpt_send_message(mpt_adap_t *adap, int length, time_t limit);
int mpt_receive_data(mpt_adap_t *adap, int length, time_t limit);
int mpt_issue_command_and_wait(mpt_adap_t *adap, int wait);
int mpt_issue_config_and_wait(mpt_adap_t *adap, int wait);
int mpt_issue_ioc_facts(mpt_adap_t *adap);
int mpt2_issue_ioc_facts(mpt_adap_t *adap);
int mpt_issue_ioc_init(mpt_adap_t *adap);
int mpt2_issue_ioc_init(mpt_adap_t *adap);
int mpt_initialize(mpt_adap_t *adap);
int mpt_issue_port_facts(mpt_adap_t *adap, int port);
int mpt2_issue_port_facts(mpt_adap_t *adap, int port);
int mpt_issue_port_enable(mpt_adap_t *adap, int port);
int mpt2_issue_port_enable(mpt_adap_t *adap, int port);
int mpt_issue_event_notification(mpt_adap_t *adap);
int mpt2_issue_event_notification(mpt_adap_t *adap);
int mpt_watchdog(mpt_adap_t *adap);
int mpt_init_device_capabilities(mpt_adap_t *adap);
int mpt_set_device_capabilities(mpt_adap_t *adap, int targ);
int mpt_set_on_bus_timer(mpt_adap_t *adap, int timeout);
int mpt_get_config_page(mpt_adap_t *adap, int type, int number, int address);
int mpt_set_config_page(mpt_adap_t *adap, int type, int number, int address);
int mpt_do_config_action(mpt_adap_t *adap, int action, int type, int number, int address, int length);
void mpt_bus_reset(mpt_adap_t *adap);
void mpt_interrupt(mpt_adap_t *adap);
void mpt2_interrupt(mpt_adap_t *adap);
int mpt_handle_reply(mpt_adap_t *adap, MPIDefaultReply_t *reply, U32 reply_ba);
void mpt2_handle_scsi_io_success(mpt_adap_t *adap, Mpi2DefaultReplyDescriptor_t *reply_desc);
void mpt2_handle_address_reply(mpt_adap_t *adap, Mpi2DefaultReplyDescriptor_t *reply_desc);
int mpt_fwdownloadboot(mpt_adap_t *adap);
int mpt_directdownload(mpt_adap_t *adap);
int
mpt_adjust_delay(mpt_adap_t *adap, int n)
{
if (adap->revision_id == 0xff)
return n * 10;
return n;
}
void
mpt_delay(mpt_adap_t *adap, int n)
{
#if DOS
int i;
for (i = 0; i < mpt_adjust_delay(adap, n); i++)
{
PciReadConfigWord(adap->bus_number, adap->device_function, PCI_CONFIG_DEVICE_ID);
}
#endif
#if EFI
udelay(mpt_adjust_delay(adap, n));
#endif
}
int
mpt_get_doorbell(mpt_adap_t *adap)
{
return rl(DOORBELL);
}
int
mpt_get_state(mpt_adap_t *adap)
{
return rl(DOORBELL) & MPI_IOC_STATE_MASK;
}
int
mpt_verify_enabled(mpt_adap_t *adap)
{
if (rl(DIAGNOSTIC) & MPI_DIAG_DISABLE_ARM)
if (mpt_stop(adap, TRUE))
return mpt_restart(adap);
return 1;
}
int
mpt_verify_ready(mpt_adap_t *adap)
{
if (adap->restart_needed == TRUE)
return 0;
if ((rl(DOORBELL) & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_READY)
return 0;
return 1;
}
int
mpt_verify_operational(mpt_adap_t *adap)
{
if (adap->restart_needed == TRUE)
return 0;
if ((rl(DOORBELL) & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_OPERATIONAL)
return 0;
return 1;
}
int
mpt_wait_for_ready(mpt_adap_t *adap)
{
U32 doorbell;
U32 diagnostic;
int state;
time_t limit = time(NULL) + mpt_adjust_delay(adap, 50);
while (time(NULL) < limit)
{
doorbell = rl(DOORBELL);
state = doorbell & MPI_IOC_STATE_MASK;
if (state == MPI_IOC_STATE_FAULT)
{
printf("\n%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
if (wFlag)
fprintf(logFile, "%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
printf("\nDo you want to continue? [Yes or No, default is No] ");
if (getYesNoAnswer(0) != 1)
break;
printf("\n");
adap->restart_needed = TRUE;
return 0;
}
if (state == MPI_IOC_STATE_READY)
{
adap->restart_needed = FALSE;
return 1;
}
diagnostic = rl(DIAGNOSTIC);
if (diagnostic & MPI_DIAG_FLASH_BAD_SIG)
{
if (adap->fw_image == NULL)
{
printf("\n%s: FLASH does not contain a valid image\n", adap->name);
if (wFlag)
fprintf(logFile, "%s: FLASH does not contain a valid image\n",
adap->name);
}
adap->restart_needed = TRUE;
return 0;
}
if (diagnostic & MPI_DIAG_DISABLE_ARM)
{
printf("\n%s: IOP ARM is disabled\n", adap->name);
if (wFlag)
fprintf(logFile, "%s: IOP ARM is disabled\n",
adap->name);
adap->restart_needed = TRUE;
return 0;
}
DELAY(1);
}
return 0;
}
/*
* mpt_restart - completely restart the IOC and any outstanding commands.
*/
int
mpt_restart(mpt_adap_t *adap)
{
int targ;
// printf("mpt_restart called\n");
if (!mpt_verify_ready(adap))
{
adap->restart_needed = FALSE;
adap->bus_reset_needed = FALSE;
if (!mpt_stop(adap, TRUE))
return 0;
}
adap->config_active = FALSE;
adap->command_active = FALSE;
if (!mpt_start(adap))
return 0;
if (adap->port_type == MPI_PORTFACTS_PORTTYPE_SCSI)
{
mpt_init_device_capabilities(adap);
for (targ = 0; targ < adap->max_targets; targ++)
{
mpt_set_device_capabilities(adap, targ);
}
}
return 1;
}
/*
* mpt_stop - stop the IOC (reset it).
*/
int
mpt_stop(mpt_adap_t *adap, int wait)
{
time_t limit = time(NULL) + mpt_adjust_delay(adap, 30);
// printf("mpt_stop called\n");
#if EFI
if (adap->disconnected == FALSE)
{
EFI_PCI_IO_PROTOCOL *pci_io;
if (wait == FALSE)
{
return 1;
}
if (adap->loaddevice == TRUE)
{
printf("This chip controls the device that this utility was loaded from.\n");
printf("After this command, the load device cannot be accessed again\n");
printf("to open files, until this utility has been exited and restarted.\n\n");
}
if (!EFI_ERROR(BS->DisconnectController(adap->handle, NULL, NULL)))
{
adap->disconnected = TRUE;
pci_io = adap->pci_io;
pci_io->Attributes(pci_io, EfiPciIoAttributeOperationEnable,
EFI_PCI_IO_ATTRIBUTE_IO |
EFI_PCI_IO_ATTRIBUTE_MEMORY |
EFI_PCI_IO_ATTRIBUTE_BUS_MASTER |
EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE, NULL);
}
if (adap->partner_adap)
{
if (!EFI_ERROR(BS->DisconnectController(adap->partner_adap->handle, NULL, NULL)))
{
adap->partner_adap->disconnected = TRUE;
pci_io = adap->partner_adap->pci_io;
pci_io->Attributes(pci_io, EfiPciIoAttributeOperationEnable,
EFI_PCI_IO_ATTRIBUTE_IO |
EFI_PCI_IO_ATTRIBUTE_MEMORY |
EFI_PCI_IO_ATTRIBUTE_BUS_MASTER |
EFI_PCI_IO_ATTRIBUTE_DUAL_ADDRESS_CYCLE, NULL);
}
}
}
#endif
adap->port_online = FALSE;
adap->interrupt_mask = MPI_HIM_RIM | MPI_HIM_DIM;
wl(HOST_INTERRUPT_MASK, rl(HOST_INTERRUPT_MASK) | adap->interrupt_mask);
/*
* Reset the chip.
*/
if (adap->device_id == MPI_MANUFACTPAGE_DEVICEID_FC909)
{
rl(FC909_BUG); /* work around FC909 bug */
}
if (!(rl(DIAGNOSTIC) & MPI_DIAG_DRWE))
{
wl(WRITE_SEQUENCE, 0);
wl(WRITE_SEQUENCE, MPI_WRSEQ_KEY_VALUE_MASK);
wl(WRITE_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE);
DELAY(100);
}
if (!(rl(DIAGNOSTIC) & MPI_DIAG_RESET_HISTORY) ||
((rl(DOORBELL) & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_RESET &&
(rl(DOORBELL) & MPI_IOC_STATE_MASK) != MPI_IOC_STATE_READY))
{
if (adap->device_id == MPI_MANUFACTPAGE_DEVID_SAS1078)
{
wl(SAS1078_RESET, 0x7);
}
else
{
wl(DIAGNOSTIC, MPI_DIAG_RESET_ADAPTER);
}
DELAY(20000);
wl(WRITE_SEQUENCE, 0);
wl(WRITE_SEQUENCE, MPI_WRSEQ_KEY_VALUE_MASK);
wl(WRITE_SEQUENCE, MPI_WRSEQ_1ST_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_2ND_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_3RD_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_4TH_KEY_VALUE);
wl(WRITE_SEQUENCE, MPI_WRSEQ_5TH_KEY_VALUE);
DELAY(100);
}
wl(DIAGNOSTIC, 0);
if (wait == FALSE)
{
while (time(NULL) < limit)
{
if (rl(DOORBELL) & MPI_IOC_STATE_MASK)
break;
if (rl(DIAGNOSTIC) & MPI_DIAG_DISABLE_ARM)
break;
DELAY(100);
}
return 1;
}
if (rl(DIAGNOSTIC) & MPI_DIAG_RESET_ADAPTER)
{
printf("\n%s: Failed to clear RESET ADAPTER\n", adap->name);
if (wFlag)
fprintf(logFile, "%s: Failed to clear RESET ADAPTER\n",
adap->name);
adap->restart_needed = TRUE;
return 0;
}
adap->bootloader = FALSE;
if (mpt_wait_for_ready(adap))
return 1;
if (mpt_fwdownloadboot(adap))
return 1;
if ((rl(DOORBELL) & MPI_IOC_STATE_MASK) == MPI_IOC_STATE_RESET)
{
adap->restart_needed = FALSE;
printf("\n%s: Failed to leave the RESET state\n", adap->name);
if (wFlag)
fprintf(logFile, "%s: Failed to leave the RESET state\n",
adap->name);
}
else
{
adap->restart_needed = TRUE;
printf("\n%s: Failed to reset properly\n", adap->name);
if (wFlag)
fprintf(logFile, "%s: Failed to reset properly\n",
adap->name);
}
return 0;
}
/*
* mpt_start - start the IOC (completely initialize it).
*/
int
mpt_start(mpt_adap_t *adap)
{
int port;
// printf("mpt_start called\n");
if (adap->bootloader == TRUE)
{
printf("\nBootLoader firmware cannot be made fully operational!\n");
return 0;
}
if (!mpt_issue_ioc_facts(adap))
{
printf("%s: Failed to send IOCFacts\n", adap->name);
return 0;
}
if (!mpt_issue_ioc_init(adap))
{
printf("%s: Failed to send IOCInit\n", adap->name);
return 0;
}
if (!mpt_initialize(adap))
{
printf("%s: Failed to finish initialization of IOC\n", adap->name);
return 0;
}
for (port = 0; port < adap->port_count; port++)
{
if (!mpt_issue_port_facts(adap, port))
{
printf("%s: Failed to send PortFacts to port %d\n", adap->name, port);
continue;
}
}
if (adap->port_enable_needed)
{
adap->port_online = mpt_port_online(adap);
}
#if 0 // skip this for DOS and EFI, as it doesn't really help
if (!mpt_issue_event_notification(adap))
{
printf("%s: failed to send EventNotification\n", adap->name);
}
#endif
if (adap->port_type == MPI_PORTFACTS_PORTTYPE_SCSI)
{
if (!mpt_set_on_bus_timer(adap, 1000))
{
printf("%s: Failed to set SCSI On Bus Timer\n", adap->name);
}
}
return 1;
}
/*
* mpt_port_online - bring the port online.
*/
int
mpt_port_online(mpt_adap_t *adap)
{
int port;
// printf("mpt_port_online called\n");
for (port = 0; port < adap->port_count; port++)
{
if (adap->port_type == MPI_PORTFACTS_PORTTYPE_SAS)
{
if (doSasChangeWwid(adap->port, 1) == 1)
{
printf("\nThe SAS WWID is zero -- the port will not be enabled\n");
printf("\nUse menu option 18 then option 99 to fix this problem\n");
continue;
}
}
if (!mpt_issue_port_enable(adap, port))
{
printf("%s: Failed to send PortEnable to port %d\n", adap->name, port);
continue;
}
}
return 1;
}
int
mpt_wait_for_doorbell(mpt_adap_t *adap, time_t limit)
{
U32 doorbell;
int state;
while (time(NULL) < limit)
{
if (adap->restart_needed == TRUE)
{
return 0;
}
doorbell = rl(DOORBELL);
state = doorbell & MPI_IOC_STATE_MASK;
if (state == MPI_IOC_STATE_FAULT)
{
printf("\n%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
if (wFlag)
fprintf(logFile, "%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
printf("\nDo you want to continue? [Yes or No, default is No] ");
if (getYesNoAnswer(0) != 1)
break;
printf("\n");
adap->restart_needed = TRUE;
return 0;
}
if (rl(HOST_INTERRUPT_STATUS) & MPI_HIS_DOORBELL_INTERRUPT)
{
return 1;
}
DELAY(1);
}
printf("%s: Failed in mpt_wait_for_doorbell, Doorbell = %08x\n",
adap->name, doorbell);
return 0;
}
int
mpt_wait_for_response(mpt_adap_t *adap, time_t limit)
{
U32 doorbell;
int state;
while (time(NULL) < limit)
{
if (adap->restart_needed == TRUE)
{
return 0;
}
doorbell = rl(DOORBELL);
state = doorbell & MPI_IOC_STATE_MASK;
if (state == MPI_IOC_STATE_FAULT)
{
printf("\n%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
if (wFlag)
fprintf(logFile, "%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
printf("\nHit Enter to continue ");
getYesNoAnswer(0);
printf("\n");
adap->restart_needed = TRUE;
return 0;
}
if (!(rl(HOST_INTERRUPT_STATUS) & MPI_HIS_IOP_DOORBELL_STATUS))
{
return 1;
}
DELAY(1);
}
printf("%s: Failed in mpt_wait_for_response, Doorbell = %08x\n",
adap->name, doorbell);
return 0;
}
int
mpt_send_message(mpt_adap_t *adap, int length, time_t limit)
{
U32 doorbell;
U32 *message = adap->shared->message;
int state;
int i;
doorbell = rl(DOORBELL);
state = doorbell & MPI_IOC_STATE_MASK;
if (state == MPI_IOC_STATE_FAULT)
{
printf("\n%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
if (wFlag)
fprintf(logFile, "%s: MPT Firmware Fault, code %04x\n",
adap->name, doorbell & MPI_DOORBELL_DATA_MASK);
printf("\nHit Enter to continue ");
getYesNoAnswer(0);
printf("\n");
adap->restart_needed = TRUE;
return 0;
}
if (state == MPI_IOC_STATE_RESET)
{
adap->restart_needed = TRUE;
return 0;
}
if (doorbell & MPI_DOORBELL_USED)
{
printf("%s: Doorbell already active\n", adap->name);
adap->restart_needed = TRUE;
return 0;
}
wl(HOST_INTERRUPT_STATUS, 0);
wl(DOORBELL, (MPI_FUNCTION_HANDSHAKE << MPI_DOORBELL_FUNCTION_SHIFT) |
((length / 4) << MPI_DOORBELL_ADD_DWORDS_SHIFT));
if (!mpt_wait_for_doorbell(adap, limit))
return 0;
wl(HOST_INTERRUPT_STATUS, 0);
if (!mpt_wait_for_response(adap, limit))
return 0;
for (i = 0; i < length / 4; i++)
{
wl(DOORBELL, get32x(message[i]));
if (!mpt_wait_for_response(adap, limit))
return 0;
}
return 1;
}
int
mpt_receive_data(mpt_adap_t *adap, int length, time_t limit)
{
int i;
int real_length;
U16 value;
U16 *data = adap->shared->data;
MPIDefaultReply_t *reply = (MPIDefaultReply_t *)data;
U16 status;
bzero(data, length);
real_length = 4; /* enough for the header to start, fix up later */
for (i = 0; i < real_length / 2; i++)
{
if (!mpt_wait_for_doorbell(adap, limit))
return 0;
value = (U16)rl(DOORBELL);
if (i == 1)
real_length = (value & ~0xff00) * 4;
if (i < length / 2)
data[i] = get16x(value);
wl(HOST_INTERRUPT_STATUS, 0);
}
if (!mpt_wait_for_doorbell(adap, limit))
return 0;
wl(HOST_INTERRUPT_STATUS, 0);
status = get16(reply->IOCStatus) & MPI_IOCSTATUS_MASK;
if (status == MPI_IOCSTATUS_SUCCESS ||
status == MPI_IOCSTATUS_CONFIG_INVALID_PAGE ||
status == MPI_IOCSTATUS_CONFIG_INVALID_DATA)
return 1;
else
return 0;
}
int
mpt_issue_command_and_wait(mpt_adap_t *adap, int wait)
{
U8 function = ((MPIHeader_t *)adap->shared->message)->Function;
int handle;
time_t limit = time(NULL) + wait;
adap->command_active = TRUE;
if (mpi1)
{
if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
{
if (mpt_send_message(adap, sizeof(SCSITaskMgmt_t), limit) != 1)
{
printf("mpt_send_message failed!\n");
return 0;
}
}
else
{
wl(REQUEST_QUEUE, (U32)adap->shared_ba + (U32)offsetof(mpt_shared_t, message));
}
}
else
{
if (function == MPI_FUNCTION_SCSI_TASK_MGMT)
{
/* SCSI Task Mgmt requests have to use high priority */
wl2(REQUEST_DESCRIPTOR_POST_LOW, (1 << 16) + MPI2_REQ_DESCRIPT_FLAGS_HIGH_PRIORITY);
wl2(REQUEST_DESCRIPTOR_POST_HIGH, 0);
}
else if (function == MPI_FUNCTION_SCSI_IO_REQUEST ||
function == MPI_FUNCTION_RAID_SCSI_IO_PASSTHROUGH)
{
handle = get16(((Mpi2SCSIIORequest_t *)adap->shared->message)->DevHandle);
/* SCSI requests have to use SCSI IO and supply a handle */
wl2(REQUEST_DESCRIPTOR_POST_LOW, (1 << 16) + MPI2_REQ_DESCRIPT_FLAGS_SCSI_IO);
wl2(REQUEST_DESCRIPTOR_POST_HIGH, handle << 16);
}
else
{
wl2(REQUEST_DESCRIPTOR_POST_LOW, (1 << 16) + MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE);
wl2(REQUEST_DESCRIPTOR_POST_HIGH, 0);
}
}
while (time(NULL) < limit)
{
if (mpt_watchdog(adap))
{
break;
}
mpt_interrupt(adap);
if (adap->command_active == TRUE)
{
DELAY(1);
}
else
{
break;
}
}
if (adap->command_active == TRUE)
{
if (time(NULL) >= limit)
printf("timeout occurred!\n");
return 0;
}
return 1;
}
int
mpt_issue_config_and_wait(mpt_adap_t *adap, int wait)
{
time_t limit = time(NULL) + wait;
adap->config_active = TRUE;
if (mpi1)
{
wl(REQUEST_QUEUE, (U32)adap->shared_ba + (U32)offsetof(mpt_shared_t, message));
}
else
{
wl2(REQUEST_DESCRIPTOR_POST_LOW, (1 << 16) + MPI2_REQ_DESCRIPT_FLAGS_DEFAULT_TYPE);
wl2(REQUEST_DESCRIPTOR_POST_HIGH, 0);
}
while (time(NULL) < limit)
{
if (adap->restart_needed == TRUE)
{
return 0;
}
mpt_interrupt(adap);
if (adap->config_active == TRUE)
{
DELAY(1);
}
else
{
break;
}
}
if (adap->config_active == TRUE)
return 0;
return 1;
}
/*
* mpt_issue_ioc_facts - issue an IOCFacts command to the IOC.
*/
int
mpt_issue_ioc_facts(mpt_adap_t *adap)
{
IOCFacts_t *request = (IOCFacts_t *)adap->shared->message;
IOCFactsReply_t *reply = (IOCFactsReply_t *)adap->shared->data;
time_t limit = time(NULL) + 10;
int t;
// printf("%s: sending IOCFacts\n", adap->name);
bzero(request, sizeof(*request));
request->Function = MPI_FUNCTION_IOC_FACTS;
logMptCommandReq(adap->port, request, sizeof(*request));
if (!mpt_send_message(adap, sizeof(*request), limit))
{
printf("%s: mpt_send_message / IOCFacts failed\n", adap->name);
return 0;
}
t = mpt_receive_data(adap, sizeof(*reply), limit);
logMptCommandRep(adap->port, request, sizeof(*request), reply, sizeof(*reply), t);
if (!t)
{
printf("%s: mpt_receive_data / IOCFacts failed\n", adap->name);
return 0;
}
adap->mpt_version = get16(reply->MsgVersion);
if (mpi2)
{
return mpt2_issue_ioc_facts(adap);
}
if (reply->WhoInit == MPI_WHOINIT_PCI_PEER)