-
Notifications
You must be signed in to change notification settings - Fork 102
/
myrs.c
3168 lines (2815 loc) · 89 KB
/
myrs.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
// SPDX-License-Identifier: GPL-2.0
/*
* Linux Driver for Mylex DAC960/AcceleRAID/eXtremeRAID PCI RAID Controllers
*
* This driver supports the newer, SCSI-based firmware interface only.
*
* Copyright 2017 Hannes Reinecke, SUSE Linux GmbH <hare@suse.com>
*
* Based on the original DAC960 driver, which has
* Copyright 1998-2001 by Leonard N. Zubkoff <lnz@dandelion.com>
* Portions Copyright 2002 by Mylex (An IBM Business Unit)
*/
#include <linux/module.h>
#include <linux/types.h>
#include <linux/delay.h>
#include <linux/interrupt.h>
#include <linux/pci.h>
#include <linux/raid_class.h>
#include <asm/unaligned.h>
#include <scsi/scsi.h>
#include <scsi/scsi_host.h>
#include <scsi/scsi_device.h>
#include <scsi/scsi_cmnd.h>
#include <scsi/scsi_tcq.h>
#include "myrs.h"
static struct raid_template *myrs_raid_template;
static struct myrs_devstate_name_entry {
enum myrs_devstate state;
char *name;
} myrs_devstate_name_list[] = {
{ MYRS_DEVICE_UNCONFIGURED, "Unconfigured" },
{ MYRS_DEVICE_ONLINE, "Online" },
{ MYRS_DEVICE_REBUILD, "Rebuild" },
{ MYRS_DEVICE_MISSING, "Missing" },
{ MYRS_DEVICE_SUSPECTED_CRITICAL, "SuspectedCritical" },
{ MYRS_DEVICE_OFFLINE, "Offline" },
{ MYRS_DEVICE_CRITICAL, "Critical" },
{ MYRS_DEVICE_SUSPECTED_DEAD, "SuspectedDead" },
{ MYRS_DEVICE_COMMANDED_OFFLINE, "CommandedOffline" },
{ MYRS_DEVICE_STANDBY, "Standby" },
{ MYRS_DEVICE_INVALID_STATE, "Invalid" },
};
static char *myrs_devstate_name(enum myrs_devstate state)
{
struct myrs_devstate_name_entry *entry = myrs_devstate_name_list;
int i;
for (i = 0; i < ARRAY_SIZE(myrs_devstate_name_list); i++) {
if (entry[i].state == state)
return entry[i].name;
}
return NULL;
}
static struct myrs_raid_level_name_entry {
enum myrs_raid_level level;
char *name;
} myrs_raid_level_name_list[] = {
{ MYRS_RAID_LEVEL0, "RAID0" },
{ MYRS_RAID_LEVEL1, "RAID1" },
{ MYRS_RAID_LEVEL3, "RAID3 right asymmetric parity" },
{ MYRS_RAID_LEVEL5, "RAID5 right asymmetric parity" },
{ MYRS_RAID_LEVEL6, "RAID6" },
{ MYRS_RAID_JBOD, "JBOD" },
{ MYRS_RAID_NEWSPAN, "New Mylex SPAN" },
{ MYRS_RAID_LEVEL3F, "RAID3 fixed parity" },
{ MYRS_RAID_LEVEL3L, "RAID3 left symmetric parity" },
{ MYRS_RAID_SPAN, "Mylex SPAN" },
{ MYRS_RAID_LEVEL5L, "RAID5 left symmetric parity" },
{ MYRS_RAID_LEVELE, "RAIDE (concatenation)" },
{ MYRS_RAID_PHYSICAL, "Physical device" },
};
static char *myrs_raid_level_name(enum myrs_raid_level level)
{
struct myrs_raid_level_name_entry *entry = myrs_raid_level_name_list;
int i;
for (i = 0; i < ARRAY_SIZE(myrs_raid_level_name_list); i++) {
if (entry[i].level == level)
return entry[i].name;
}
return NULL;
}
/*
* myrs_reset_cmd - clears critical fields in struct myrs_cmdblk
*/
static inline void myrs_reset_cmd(struct myrs_cmdblk *cmd_blk)
{
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
memset(mbox, 0, sizeof(union myrs_cmd_mbox));
cmd_blk->status = 0;
}
/*
* myrs_qcmd - queues Command for DAC960 V2 Series Controllers.
*/
static void myrs_qcmd(struct myrs_hba *cs, struct myrs_cmdblk *cmd_blk)
{
void __iomem *base = cs->io_base;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
union myrs_cmd_mbox *next_mbox = cs->next_cmd_mbox;
cs->write_cmd_mbox(next_mbox, mbox);
if (cs->prev_cmd_mbox1->words[0] == 0 ||
cs->prev_cmd_mbox2->words[0] == 0)
cs->get_cmd_mbox(base);
cs->prev_cmd_mbox2 = cs->prev_cmd_mbox1;
cs->prev_cmd_mbox1 = next_mbox;
if (++next_mbox > cs->last_cmd_mbox)
next_mbox = cs->first_cmd_mbox;
cs->next_cmd_mbox = next_mbox;
}
/*
* myrs_exec_cmd - executes V2 Command and waits for completion.
*/
static void myrs_exec_cmd(struct myrs_hba *cs,
struct myrs_cmdblk *cmd_blk)
{
DECLARE_COMPLETION_ONSTACK(complete);
unsigned long flags;
cmd_blk->complete = &complete;
spin_lock_irqsave(&cs->queue_lock, flags);
myrs_qcmd(cs, cmd_blk);
spin_unlock_irqrestore(&cs->queue_lock, flags);
wait_for_completion(&complete);
}
/*
* myrs_report_progress - prints progress message
*/
static void myrs_report_progress(struct myrs_hba *cs, unsigned short ldev_num,
unsigned char *msg, unsigned long blocks,
unsigned long size)
{
shost_printk(KERN_INFO, cs->host,
"Logical Drive %d: %s in Progress: %d%% completed\n",
ldev_num, msg,
(100 * (int)(blocks >> 7)) / (int)(size >> 7));
}
/*
* myrs_get_ctlr_info - executes a Controller Information IOCTL Command
*/
static unsigned char myrs_get_ctlr_info(struct myrs_hba *cs)
{
struct myrs_cmdblk *cmd_blk = &cs->dcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
dma_addr_t ctlr_info_addr;
union myrs_sgl *sgl;
unsigned char status;
unsigned short ldev_present, ldev_critical, ldev_offline;
ldev_present = cs->ctlr_info->ldev_present;
ldev_critical = cs->ctlr_info->ldev_critical;
ldev_offline = cs->ctlr_info->ldev_offline;
ctlr_info_addr = dma_map_single(&cs->pdev->dev, cs->ctlr_info,
sizeof(struct myrs_ctlr_info),
DMA_FROM_DEVICE);
if (dma_mapping_error(&cs->pdev->dev, ctlr_info_addr))
return MYRS_STATUS_FAILED;
mutex_lock(&cs->dcmd_mutex);
myrs_reset_cmd(cmd_blk);
mbox->ctlr_info.id = MYRS_DCMD_TAG;
mbox->ctlr_info.opcode = MYRS_CMD_OP_IOCTL;
mbox->ctlr_info.control.dma_ctrl_to_host = true;
mbox->ctlr_info.control.no_autosense = true;
mbox->ctlr_info.dma_size = sizeof(struct myrs_ctlr_info);
mbox->ctlr_info.ctlr_num = 0;
mbox->ctlr_info.ioctl_opcode = MYRS_IOCTL_GET_CTLR_INFO;
sgl = &mbox->ctlr_info.dma_addr;
sgl->sge[0].sge_addr = ctlr_info_addr;
sgl->sge[0].sge_count = mbox->ctlr_info.dma_size;
dev_dbg(&cs->host->shost_gendev, "Sending GetControllerInfo\n");
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
mutex_unlock(&cs->dcmd_mutex);
dma_unmap_single(&cs->pdev->dev, ctlr_info_addr,
sizeof(struct myrs_ctlr_info), DMA_FROM_DEVICE);
if (status == MYRS_STATUS_SUCCESS) {
if (cs->ctlr_info->bg_init_active +
cs->ctlr_info->ldev_init_active +
cs->ctlr_info->pdev_init_active +
cs->ctlr_info->cc_active +
cs->ctlr_info->rbld_active +
cs->ctlr_info->exp_active != 0)
cs->needs_update = true;
if (cs->ctlr_info->ldev_present != ldev_present ||
cs->ctlr_info->ldev_critical != ldev_critical ||
cs->ctlr_info->ldev_offline != ldev_offline)
shost_printk(KERN_INFO, cs->host,
"Logical drive count changes (%d/%d/%d)\n",
cs->ctlr_info->ldev_critical,
cs->ctlr_info->ldev_offline,
cs->ctlr_info->ldev_present);
}
return status;
}
/*
* myrs_get_ldev_info - executes a Logical Device Information IOCTL Command
*/
static unsigned char myrs_get_ldev_info(struct myrs_hba *cs,
unsigned short ldev_num, struct myrs_ldev_info *ldev_info)
{
struct myrs_cmdblk *cmd_blk = &cs->dcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
dma_addr_t ldev_info_addr;
struct myrs_ldev_info ldev_info_orig;
union myrs_sgl *sgl;
unsigned char status;
memcpy(&ldev_info_orig, ldev_info, sizeof(struct myrs_ldev_info));
ldev_info_addr = dma_map_single(&cs->pdev->dev, ldev_info,
sizeof(struct myrs_ldev_info),
DMA_FROM_DEVICE);
if (dma_mapping_error(&cs->pdev->dev, ldev_info_addr))
return MYRS_STATUS_FAILED;
mutex_lock(&cs->dcmd_mutex);
myrs_reset_cmd(cmd_blk);
mbox->ldev_info.id = MYRS_DCMD_TAG;
mbox->ldev_info.opcode = MYRS_CMD_OP_IOCTL;
mbox->ldev_info.control.dma_ctrl_to_host = true;
mbox->ldev_info.control.no_autosense = true;
mbox->ldev_info.dma_size = sizeof(struct myrs_ldev_info);
mbox->ldev_info.ldev.ldev_num = ldev_num;
mbox->ldev_info.ioctl_opcode = MYRS_IOCTL_GET_LDEV_INFO_VALID;
sgl = &mbox->ldev_info.dma_addr;
sgl->sge[0].sge_addr = ldev_info_addr;
sgl->sge[0].sge_count = mbox->ldev_info.dma_size;
dev_dbg(&cs->host->shost_gendev,
"Sending GetLogicalDeviceInfoValid for ldev %d\n", ldev_num);
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
mutex_unlock(&cs->dcmd_mutex);
dma_unmap_single(&cs->pdev->dev, ldev_info_addr,
sizeof(struct myrs_ldev_info), DMA_FROM_DEVICE);
if (status == MYRS_STATUS_SUCCESS) {
unsigned short ldev_num = ldev_info->ldev_num;
struct myrs_ldev_info *new = ldev_info;
struct myrs_ldev_info *old = &ldev_info_orig;
unsigned long ldev_size = new->cfg_devsize;
if (new->dev_state != old->dev_state) {
const char *name;
name = myrs_devstate_name(new->dev_state);
shost_printk(KERN_INFO, cs->host,
"Logical Drive %d is now %s\n",
ldev_num, name ? name : "Invalid");
}
if ((new->soft_errs != old->soft_errs) ||
(new->cmds_failed != old->cmds_failed) ||
(new->deferred_write_errs != old->deferred_write_errs))
shost_printk(KERN_INFO, cs->host,
"Logical Drive %d Errors: Soft = %d, Failed = %d, Deferred Write = %d\n",
ldev_num, new->soft_errs,
new->cmds_failed,
new->deferred_write_errs);
if (new->bg_init_active)
myrs_report_progress(cs, ldev_num,
"Background Initialization",
new->bg_init_lba, ldev_size);
else if (new->fg_init_active)
myrs_report_progress(cs, ldev_num,
"Foreground Initialization",
new->fg_init_lba, ldev_size);
else if (new->migration_active)
myrs_report_progress(cs, ldev_num,
"Data Migration",
new->migration_lba, ldev_size);
else if (new->patrol_active)
myrs_report_progress(cs, ldev_num,
"Patrol Operation",
new->patrol_lba, ldev_size);
if (old->bg_init_active && !new->bg_init_active)
shost_printk(KERN_INFO, cs->host,
"Logical Drive %d: Background Initialization %s\n",
ldev_num,
(new->ldev_control.ldev_init_done ?
"Completed" : "Failed"));
}
return status;
}
/*
* myrs_get_pdev_info - executes a "Read Physical Device Information" Command
*/
static unsigned char myrs_get_pdev_info(struct myrs_hba *cs,
unsigned char channel, unsigned char target, unsigned char lun,
struct myrs_pdev_info *pdev_info)
{
struct myrs_cmdblk *cmd_blk = &cs->dcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
dma_addr_t pdev_info_addr;
union myrs_sgl *sgl;
unsigned char status;
pdev_info_addr = dma_map_single(&cs->pdev->dev, pdev_info,
sizeof(struct myrs_pdev_info),
DMA_FROM_DEVICE);
if (dma_mapping_error(&cs->pdev->dev, pdev_info_addr))
return MYRS_STATUS_FAILED;
mutex_lock(&cs->dcmd_mutex);
myrs_reset_cmd(cmd_blk);
mbox->pdev_info.opcode = MYRS_CMD_OP_IOCTL;
mbox->pdev_info.id = MYRS_DCMD_TAG;
mbox->pdev_info.control.dma_ctrl_to_host = true;
mbox->pdev_info.control.no_autosense = true;
mbox->pdev_info.dma_size = sizeof(struct myrs_pdev_info);
mbox->pdev_info.pdev.lun = lun;
mbox->pdev_info.pdev.target = target;
mbox->pdev_info.pdev.channel = channel;
mbox->pdev_info.ioctl_opcode = MYRS_IOCTL_GET_PDEV_INFO_VALID;
sgl = &mbox->pdev_info.dma_addr;
sgl->sge[0].sge_addr = pdev_info_addr;
sgl->sge[0].sge_count = mbox->pdev_info.dma_size;
dev_dbg(&cs->host->shost_gendev,
"Sending GetPhysicalDeviceInfoValid for pdev %d:%d:%d\n",
channel, target, lun);
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
mutex_unlock(&cs->dcmd_mutex);
dma_unmap_single(&cs->pdev->dev, pdev_info_addr,
sizeof(struct myrs_pdev_info), DMA_FROM_DEVICE);
return status;
}
/*
* myrs_dev_op - executes a "Device Operation" Command
*/
static unsigned char myrs_dev_op(struct myrs_hba *cs,
enum myrs_ioctl_opcode opcode, enum myrs_opdev opdev)
{
struct myrs_cmdblk *cmd_blk = &cs->dcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
unsigned char status;
mutex_lock(&cs->dcmd_mutex);
myrs_reset_cmd(cmd_blk);
mbox->dev_op.opcode = MYRS_CMD_OP_IOCTL;
mbox->dev_op.id = MYRS_DCMD_TAG;
mbox->dev_op.control.dma_ctrl_to_host = true;
mbox->dev_op.control.no_autosense = true;
mbox->dev_op.ioctl_opcode = opcode;
mbox->dev_op.opdev = opdev;
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
mutex_unlock(&cs->dcmd_mutex);
return status;
}
/*
* myrs_translate_pdev - translates a Physical Device Channel and
* TargetID into a Logical Device.
*/
static unsigned char myrs_translate_pdev(struct myrs_hba *cs,
unsigned char channel, unsigned char target, unsigned char lun,
struct myrs_devmap *devmap)
{
struct pci_dev *pdev = cs->pdev;
dma_addr_t devmap_addr;
struct myrs_cmdblk *cmd_blk;
union myrs_cmd_mbox *mbox;
union myrs_sgl *sgl;
unsigned char status;
memset(devmap, 0x0, sizeof(struct myrs_devmap));
devmap_addr = dma_map_single(&pdev->dev, devmap,
sizeof(struct myrs_devmap),
DMA_FROM_DEVICE);
if (dma_mapping_error(&pdev->dev, devmap_addr))
return MYRS_STATUS_FAILED;
mutex_lock(&cs->dcmd_mutex);
cmd_blk = &cs->dcmd_blk;
mbox = &cmd_blk->mbox;
mbox->pdev_info.opcode = MYRS_CMD_OP_IOCTL;
mbox->pdev_info.control.dma_ctrl_to_host = true;
mbox->pdev_info.control.no_autosense = true;
mbox->pdev_info.dma_size = sizeof(struct myrs_devmap);
mbox->pdev_info.pdev.target = target;
mbox->pdev_info.pdev.channel = channel;
mbox->pdev_info.pdev.lun = lun;
mbox->pdev_info.ioctl_opcode = MYRS_IOCTL_XLATE_PDEV_TO_LDEV;
sgl = &mbox->pdev_info.dma_addr;
sgl->sge[0].sge_addr = devmap_addr;
sgl->sge[0].sge_count = mbox->pdev_info.dma_size;
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
mutex_unlock(&cs->dcmd_mutex);
dma_unmap_single(&pdev->dev, devmap_addr,
sizeof(struct myrs_devmap), DMA_FROM_DEVICE);
return status;
}
/*
* myrs_get_event - executes a Get Event Command
*/
static unsigned char myrs_get_event(struct myrs_hba *cs,
unsigned int event_num, struct myrs_event *event_buf)
{
struct pci_dev *pdev = cs->pdev;
dma_addr_t event_addr;
struct myrs_cmdblk *cmd_blk = &cs->mcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
union myrs_sgl *sgl;
unsigned char status;
event_addr = dma_map_single(&pdev->dev, event_buf,
sizeof(struct myrs_event), DMA_FROM_DEVICE);
if (dma_mapping_error(&pdev->dev, event_addr))
return MYRS_STATUS_FAILED;
mbox->get_event.opcode = MYRS_CMD_OP_IOCTL;
mbox->get_event.dma_size = sizeof(struct myrs_event);
mbox->get_event.evnum_upper = event_num >> 16;
mbox->get_event.ctlr_num = 0;
mbox->get_event.ioctl_opcode = MYRS_IOCTL_GET_EVENT;
mbox->get_event.evnum_lower = event_num & 0xFFFF;
sgl = &mbox->get_event.dma_addr;
sgl->sge[0].sge_addr = event_addr;
sgl->sge[0].sge_count = mbox->get_event.dma_size;
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
dma_unmap_single(&pdev->dev, event_addr,
sizeof(struct myrs_event), DMA_FROM_DEVICE);
return status;
}
/*
* myrs_get_fwstatus - executes a Get Health Status Command
*/
static unsigned char myrs_get_fwstatus(struct myrs_hba *cs)
{
struct myrs_cmdblk *cmd_blk = &cs->mcmd_blk;
union myrs_cmd_mbox *mbox = &cmd_blk->mbox;
union myrs_sgl *sgl;
unsigned char status = cmd_blk->status;
myrs_reset_cmd(cmd_blk);
mbox->common.opcode = MYRS_CMD_OP_IOCTL;
mbox->common.id = MYRS_MCMD_TAG;
mbox->common.control.dma_ctrl_to_host = true;
mbox->common.control.no_autosense = true;
mbox->common.dma_size = sizeof(struct myrs_fwstat);
mbox->common.ioctl_opcode = MYRS_IOCTL_GET_HEALTH_STATUS;
sgl = &mbox->common.dma_addr;
sgl->sge[0].sge_addr = cs->fwstat_addr;
sgl->sge[0].sge_count = mbox->ctlr_info.dma_size;
dev_dbg(&cs->host->shost_gendev, "Sending GetHealthStatus\n");
myrs_exec_cmd(cs, cmd_blk);
status = cmd_blk->status;
return status;
}
/*
* myrs_enable_mmio_mbox - enables the Memory Mailbox Interface
*/
static bool myrs_enable_mmio_mbox(struct myrs_hba *cs,
enable_mbox_t enable_mbox_fn)
{
void __iomem *base = cs->io_base;
struct pci_dev *pdev = cs->pdev;
union myrs_cmd_mbox *cmd_mbox;
struct myrs_stat_mbox *stat_mbox;
union myrs_cmd_mbox *mbox;
dma_addr_t mbox_addr;
unsigned char status = MYRS_STATUS_FAILED;
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(64)))
if (dma_set_mask(&pdev->dev, DMA_BIT_MASK(32))) {
dev_err(&pdev->dev, "DMA mask out of range\n");
return false;
}
/* Temporary dma mapping, used only in the scope of this function */
mbox = dma_alloc_coherent(&pdev->dev, sizeof(union myrs_cmd_mbox),
&mbox_addr, GFP_KERNEL);
if (dma_mapping_error(&pdev->dev, mbox_addr))
return false;
/* These are the base addresses for the command memory mailbox array */
cs->cmd_mbox_size = MYRS_MAX_CMD_MBOX * sizeof(union myrs_cmd_mbox);
cmd_mbox = dma_alloc_coherent(&pdev->dev, cs->cmd_mbox_size,
&cs->cmd_mbox_addr, GFP_KERNEL);
if (dma_mapping_error(&pdev->dev, cs->cmd_mbox_addr)) {
dev_err(&pdev->dev, "Failed to map command mailbox\n");
goto out_free;
}
cs->first_cmd_mbox = cmd_mbox;
cmd_mbox += MYRS_MAX_CMD_MBOX - 1;
cs->last_cmd_mbox = cmd_mbox;
cs->next_cmd_mbox = cs->first_cmd_mbox;
cs->prev_cmd_mbox1 = cs->last_cmd_mbox;
cs->prev_cmd_mbox2 = cs->last_cmd_mbox - 1;
/* These are the base addresses for the status memory mailbox array */
cs->stat_mbox_size = MYRS_MAX_STAT_MBOX * sizeof(struct myrs_stat_mbox);
stat_mbox = dma_alloc_coherent(&pdev->dev, cs->stat_mbox_size,
&cs->stat_mbox_addr, GFP_KERNEL);
if (dma_mapping_error(&pdev->dev, cs->stat_mbox_addr)) {
dev_err(&pdev->dev, "Failed to map status mailbox\n");
goto out_free;
}
cs->first_stat_mbox = stat_mbox;
stat_mbox += MYRS_MAX_STAT_MBOX - 1;
cs->last_stat_mbox = stat_mbox;
cs->next_stat_mbox = cs->first_stat_mbox;
cs->fwstat_buf = dma_alloc_coherent(&pdev->dev,
sizeof(struct myrs_fwstat),
&cs->fwstat_addr, GFP_KERNEL);
if (dma_mapping_error(&pdev->dev, cs->fwstat_addr)) {
dev_err(&pdev->dev, "Failed to map firmware health buffer\n");
cs->fwstat_buf = NULL;
goto out_free;
}
cs->ctlr_info = kzalloc(sizeof(struct myrs_ctlr_info), GFP_KERNEL);
if (!cs->ctlr_info)
goto out_free;
cs->event_buf = kzalloc(sizeof(struct myrs_event), GFP_KERNEL);
if (!cs->event_buf)
goto out_free;
/* Enable the Memory Mailbox Interface. */
memset(mbox, 0, sizeof(union myrs_cmd_mbox));
mbox->set_mbox.id = 1;
mbox->set_mbox.opcode = MYRS_CMD_OP_IOCTL;
mbox->set_mbox.control.no_autosense = true;
mbox->set_mbox.first_cmd_mbox_size_kb =
(MYRS_MAX_CMD_MBOX * sizeof(union myrs_cmd_mbox)) >> 10;
mbox->set_mbox.first_stat_mbox_size_kb =
(MYRS_MAX_STAT_MBOX * sizeof(struct myrs_stat_mbox)) >> 10;
mbox->set_mbox.second_cmd_mbox_size_kb = 0;
mbox->set_mbox.second_stat_mbox_size_kb = 0;
mbox->set_mbox.sense_len = 0;
mbox->set_mbox.ioctl_opcode = MYRS_IOCTL_SET_MEM_MBOX;
mbox->set_mbox.fwstat_buf_size_kb = 1;
mbox->set_mbox.fwstat_buf_addr = cs->fwstat_addr;
mbox->set_mbox.first_cmd_mbox_addr = cs->cmd_mbox_addr;
mbox->set_mbox.first_stat_mbox_addr = cs->stat_mbox_addr;
status = enable_mbox_fn(base, mbox_addr);
out_free:
dma_free_coherent(&pdev->dev, sizeof(union myrs_cmd_mbox),
mbox, mbox_addr);
if (status != MYRS_STATUS_SUCCESS)
dev_err(&pdev->dev, "Failed to enable mailbox, status %X\n",
status);
return (status == MYRS_STATUS_SUCCESS);
}
/*
* myrs_get_config - reads the Configuration Information
*/
static int myrs_get_config(struct myrs_hba *cs)
{
struct myrs_ctlr_info *info = cs->ctlr_info;
struct Scsi_Host *shost = cs->host;
unsigned char status;
unsigned char model[20];
unsigned char fw_version[12];
int i, model_len;
/* Get data into dma-able area, then copy into permanent location */
mutex_lock(&cs->cinfo_mutex);
status = myrs_get_ctlr_info(cs);
mutex_unlock(&cs->cinfo_mutex);
if (status != MYRS_STATUS_SUCCESS) {
shost_printk(KERN_ERR, shost,
"Failed to get controller information\n");
return -ENODEV;
}
/* Initialize the Controller Model Name and Full Model Name fields. */
model_len = sizeof(info->ctlr_name);
if (model_len > sizeof(model)-1)
model_len = sizeof(model)-1;
memcpy(model, info->ctlr_name, model_len);
model_len--;
while (model[model_len] == ' ' || model[model_len] == '\0')
model_len--;
model[++model_len] = '\0';
strcpy(cs->model_name, "DAC960 ");
strcat(cs->model_name, model);
/* Initialize the Controller Firmware Version field. */
sprintf(fw_version, "%d.%02d-%02d",
info->fw_major_version, info->fw_minor_version,
info->fw_turn_number);
if (info->fw_major_version == 6 &&
info->fw_minor_version == 0 &&
info->fw_turn_number < 1) {
shost_printk(KERN_WARNING, shost,
"FIRMWARE VERSION %s DOES NOT PROVIDE THE CONTROLLER\n"
"STATUS MONITORING FUNCTIONALITY NEEDED BY THIS DRIVER.\n"
"PLEASE UPGRADE TO VERSION 6.00-01 OR ABOVE.\n",
fw_version);
return -ENODEV;
}
/* Initialize the Controller Channels and Targets. */
shost->max_channel = info->physchan_present + info->virtchan_present;
shost->max_id = info->max_targets[0];
for (i = 1; i < 16; i++) {
if (!info->max_targets[i])
continue;
if (shost->max_id < info->max_targets[i])
shost->max_id = info->max_targets[i];
}
/*
* Initialize the Controller Queue Depth, Driver Queue Depth,
* Logical Drive Count, Maximum Blocks per Command, Controller
* Scatter/Gather Limit, and Driver Scatter/Gather Limit.
* The Driver Queue Depth must be at most three less than
* the Controller Queue Depth; tag '1' is reserved for
* direct commands, and tag '2' for monitoring commands.
*/
shost->can_queue = info->max_tcq - 3;
if (shost->can_queue > MYRS_MAX_CMD_MBOX - 3)
shost->can_queue = MYRS_MAX_CMD_MBOX - 3;
shost->max_sectors = info->max_transfer_size;
shost->sg_tablesize = info->max_sge;
if (shost->sg_tablesize > MYRS_SG_LIMIT)
shost->sg_tablesize = MYRS_SG_LIMIT;
shost_printk(KERN_INFO, shost,
"Configuring %s PCI RAID Controller\n", model);
shost_printk(KERN_INFO, shost,
" Firmware Version: %s, Channels: %d, Memory Size: %dMB\n",
fw_version, info->physchan_present, info->mem_size_mb);
shost_printk(KERN_INFO, shost,
" Controller Queue Depth: %d, Maximum Blocks per Command: %d\n",
shost->can_queue, shost->max_sectors);
shost_printk(KERN_INFO, shost,
" Driver Queue Depth: %d, Scatter/Gather Limit: %d of %d Segments\n",
shost->can_queue, shost->sg_tablesize, MYRS_SG_LIMIT);
for (i = 0; i < info->physchan_max; i++) {
if (!info->max_targets[i])
continue;
shost_printk(KERN_INFO, shost,
" Device Channel %d: max %d devices\n",
i, info->max_targets[i]);
}
shost_printk(KERN_INFO, shost,
" Physical: %d/%d channels, %d disks, %d devices\n",
info->physchan_present, info->physchan_max,
info->pdisk_present, info->pdev_present);
shost_printk(KERN_INFO, shost,
" Logical: %d/%d channels, %d disks\n",
info->virtchan_present, info->virtchan_max,
info->ldev_present);
return 0;
}
/*
* myrs_log_event - prints a Controller Event message
*/
static struct {
int ev_code;
unsigned char *ev_msg;
} myrs_ev_list[] = {
/* Physical Device Events (0x0000 - 0x007F) */
{ 0x0001, "P Online" },
{ 0x0002, "P Standby" },
{ 0x0005, "P Automatic Rebuild Started" },
{ 0x0006, "P Manual Rebuild Started" },
{ 0x0007, "P Rebuild Completed" },
{ 0x0008, "P Rebuild Cancelled" },
{ 0x0009, "P Rebuild Failed for Unknown Reasons" },
{ 0x000A, "P Rebuild Failed due to New Physical Device" },
{ 0x000B, "P Rebuild Failed due to Logical Drive Failure" },
{ 0x000C, "S Offline" },
{ 0x000D, "P Found" },
{ 0x000E, "P Removed" },
{ 0x000F, "P Unconfigured" },
{ 0x0010, "P Expand Capacity Started" },
{ 0x0011, "P Expand Capacity Completed" },
{ 0x0012, "P Expand Capacity Failed" },
{ 0x0013, "P Command Timed Out" },
{ 0x0014, "P Command Aborted" },
{ 0x0015, "P Command Retried" },
{ 0x0016, "P Parity Error" },
{ 0x0017, "P Soft Error" },
{ 0x0018, "P Miscellaneous Error" },
{ 0x0019, "P Reset" },
{ 0x001A, "P Active Spare Found" },
{ 0x001B, "P Warm Spare Found" },
{ 0x001C, "S Sense Data Received" },
{ 0x001D, "P Initialization Started" },
{ 0x001E, "P Initialization Completed" },
{ 0x001F, "P Initialization Failed" },
{ 0x0020, "P Initialization Cancelled" },
{ 0x0021, "P Failed because Write Recovery Failed" },
{ 0x0022, "P Failed because SCSI Bus Reset Failed" },
{ 0x0023, "P Failed because of Double Check Condition" },
{ 0x0024, "P Failed because Device Cannot Be Accessed" },
{ 0x0025, "P Failed because of Gross Error on SCSI Processor" },
{ 0x0026, "P Failed because of Bad Tag from Device" },
{ 0x0027, "P Failed because of Command Timeout" },
{ 0x0028, "P Failed because of System Reset" },
{ 0x0029, "P Failed because of Busy Status or Parity Error" },
{ 0x002A, "P Failed because Host Set Device to Failed State" },
{ 0x002B, "P Failed because of Selection Timeout" },
{ 0x002C, "P Failed because of SCSI Bus Phase Error" },
{ 0x002D, "P Failed because Device Returned Unknown Status" },
{ 0x002E, "P Failed because Device Not Ready" },
{ 0x002F, "P Failed because Device Not Found at Startup" },
{ 0x0030, "P Failed because COD Write Operation Failed" },
{ 0x0031, "P Failed because BDT Write Operation Failed" },
{ 0x0039, "P Missing at Startup" },
{ 0x003A, "P Start Rebuild Failed due to Physical Drive Too Small" },
{ 0x003C, "P Temporarily Offline Device Automatically Made Online" },
{ 0x003D, "P Standby Rebuild Started" },
/* Logical Device Events (0x0080 - 0x00FF) */
{ 0x0080, "M Consistency Check Started" },
{ 0x0081, "M Consistency Check Completed" },
{ 0x0082, "M Consistency Check Cancelled" },
{ 0x0083, "M Consistency Check Completed With Errors" },
{ 0x0084, "M Consistency Check Failed due to Logical Drive Failure" },
{ 0x0085, "M Consistency Check Failed due to Physical Device Failure" },
{ 0x0086, "L Offline" },
{ 0x0087, "L Critical" },
{ 0x0088, "L Online" },
{ 0x0089, "M Automatic Rebuild Started" },
{ 0x008A, "M Manual Rebuild Started" },
{ 0x008B, "M Rebuild Completed" },
{ 0x008C, "M Rebuild Cancelled" },
{ 0x008D, "M Rebuild Failed for Unknown Reasons" },
{ 0x008E, "M Rebuild Failed due to New Physical Device" },
{ 0x008F, "M Rebuild Failed due to Logical Drive Failure" },
{ 0x0090, "M Initialization Started" },
{ 0x0091, "M Initialization Completed" },
{ 0x0092, "M Initialization Cancelled" },
{ 0x0093, "M Initialization Failed" },
{ 0x0094, "L Found" },
{ 0x0095, "L Deleted" },
{ 0x0096, "M Expand Capacity Started" },
{ 0x0097, "M Expand Capacity Completed" },
{ 0x0098, "M Expand Capacity Failed" },
{ 0x0099, "L Bad Block Found" },
{ 0x009A, "L Size Changed" },
{ 0x009B, "L Type Changed" },
{ 0x009C, "L Bad Data Block Found" },
{ 0x009E, "L Read of Data Block in BDT" },
{ 0x009F, "L Write Back Data for Disk Block Lost" },
{ 0x00A0, "L Temporarily Offline RAID-5/3 Drive Made Online" },
{ 0x00A1, "L Temporarily Offline RAID-6/1/0/7 Drive Made Online" },
{ 0x00A2, "L Standby Rebuild Started" },
/* Fault Management Events (0x0100 - 0x017F) */
{ 0x0140, "E Fan %d Failed" },
{ 0x0141, "E Fan %d OK" },
{ 0x0142, "E Fan %d Not Present" },
{ 0x0143, "E Power Supply %d Failed" },
{ 0x0144, "E Power Supply %d OK" },
{ 0x0145, "E Power Supply %d Not Present" },
{ 0x0146, "E Temperature Sensor %d Temperature Exceeds Safe Limit" },
{ 0x0147, "E Temperature Sensor %d Temperature Exceeds Working Limit" },
{ 0x0148, "E Temperature Sensor %d Temperature Normal" },
{ 0x0149, "E Temperature Sensor %d Not Present" },
{ 0x014A, "E Enclosure Management Unit %d Access Critical" },
{ 0x014B, "E Enclosure Management Unit %d Access OK" },
{ 0x014C, "E Enclosure Management Unit %d Access Offline" },
/* Controller Events (0x0180 - 0x01FF) */
{ 0x0181, "C Cache Write Back Error" },
{ 0x0188, "C Battery Backup Unit Found" },
{ 0x0189, "C Battery Backup Unit Charge Level Low" },
{ 0x018A, "C Battery Backup Unit Charge Level OK" },
{ 0x0193, "C Installation Aborted" },
{ 0x0195, "C Battery Backup Unit Physically Removed" },
{ 0x0196, "C Memory Error During Warm Boot" },
{ 0x019E, "C Memory Soft ECC Error Corrected" },
{ 0x019F, "C Memory Hard ECC Error Corrected" },
{ 0x01A2, "C Battery Backup Unit Failed" },
{ 0x01AB, "C Mirror Race Recovery Failed" },
{ 0x01AC, "C Mirror Race on Critical Drive" },
/* Controller Internal Processor Events */
{ 0x0380, "C Internal Controller Hung" },
{ 0x0381, "C Internal Controller Firmware Breakpoint" },
{ 0x0390, "C Internal Controller i960 Processor Specific Error" },
{ 0x03A0, "C Internal Controller StrongARM Processor Specific Error" },
{ 0, "" }
};
static void myrs_log_event(struct myrs_hba *cs, struct myrs_event *ev)
{
unsigned char msg_buf[MYRS_LINE_BUFFER_SIZE];
int ev_idx = 0, ev_code;
unsigned char ev_type, *ev_msg;
struct Scsi_Host *shost = cs->host;
struct scsi_device *sdev;
struct scsi_sense_hdr sshdr = {0};
unsigned char sense_info[4];
unsigned char cmd_specific[4];
if (ev->ev_code == 0x1C) {
if (!scsi_normalize_sense(ev->sense_data, 40, &sshdr)) {
memset(&sshdr, 0x0, sizeof(sshdr));
memset(sense_info, 0x0, sizeof(sense_info));
memset(cmd_specific, 0x0, sizeof(cmd_specific));
} else {
memcpy(sense_info, &ev->sense_data[3], 4);
memcpy(cmd_specific, &ev->sense_data[7], 4);
}
}
if (sshdr.sense_key == VENDOR_SPECIFIC &&
(sshdr.asc == 0x80 || sshdr.asc == 0x81))
ev->ev_code = ((sshdr.asc - 0x80) << 8 | sshdr.ascq);
while (true) {
ev_code = myrs_ev_list[ev_idx].ev_code;
if (ev_code == ev->ev_code || ev_code == 0)
break;
ev_idx++;
}
ev_type = myrs_ev_list[ev_idx].ev_msg[0];
ev_msg = &myrs_ev_list[ev_idx].ev_msg[2];
if (ev_code == 0) {
shost_printk(KERN_WARNING, shost,
"Unknown Controller Event Code %04X\n",
ev->ev_code);
return;
}
switch (ev_type) {
case 'P':
sdev = scsi_device_lookup(shost, ev->channel,
ev->target, 0);
sdev_printk(KERN_INFO, sdev, "event %d: Physical Device %s\n",
ev->ev_seq, ev_msg);
if (sdev && sdev->hostdata &&
sdev->channel < cs->ctlr_info->physchan_present) {
struct myrs_pdev_info *pdev_info = sdev->hostdata;
switch (ev->ev_code) {
case 0x0001:
case 0x0007:
pdev_info->dev_state = MYRS_DEVICE_ONLINE;
break;
case 0x0002:
pdev_info->dev_state = MYRS_DEVICE_STANDBY;
break;
case 0x000C:
pdev_info->dev_state = MYRS_DEVICE_OFFLINE;
break;
case 0x000E:
pdev_info->dev_state = MYRS_DEVICE_MISSING;
break;
case 0x000F:
pdev_info->dev_state = MYRS_DEVICE_UNCONFIGURED;
break;
}
}
break;
case 'L':
shost_printk(KERN_INFO, shost,
"event %d: Logical Drive %d %s\n",
ev->ev_seq, ev->lun, ev_msg);
cs->needs_update = true;
break;
case 'M':
shost_printk(KERN_INFO, shost,
"event %d: Logical Drive %d %s\n",
ev->ev_seq, ev->lun, ev_msg);
cs->needs_update = true;
break;
case 'S':
if (sshdr.sense_key == NO_SENSE ||
(sshdr.sense_key == NOT_READY &&
sshdr.asc == 0x04 && (sshdr.ascq == 0x01 ||
sshdr.ascq == 0x02)))
break;
shost_printk(KERN_INFO, shost,
"event %d: Physical Device %d:%d %s\n",
ev->ev_seq, ev->channel, ev->target, ev_msg);
shost_printk(KERN_INFO, shost,
"Physical Device %d:%d Sense Key = %X, ASC = %02X, ASCQ = %02X\n",
ev->channel, ev->target,
sshdr.sense_key, sshdr.asc, sshdr.ascq);
shost_printk(KERN_INFO, shost,
"Physical Device %d:%d Sense Information = %02X%02X%02X%02X %02X%02X%02X%02X\n",
ev->channel, ev->target,
sense_info[0], sense_info[1],
sense_info[2], sense_info[3],
cmd_specific[0], cmd_specific[1],
cmd_specific[2], cmd_specific[3]);
break;
case 'E':
if (cs->disable_enc_msg)
break;
sprintf(msg_buf, ev_msg, ev->lun);
shost_printk(KERN_INFO, shost, "event %d: Enclosure %d %s\n",
ev->ev_seq, ev->target, msg_buf);
break;
case 'C':
shost_printk(KERN_INFO, shost, "event %d: Controller %s\n",
ev->ev_seq, ev_msg);
break;
default:
shost_printk(KERN_INFO, shost,
"event %d: Unknown Event Code %04X\n",
ev->ev_seq, ev->ev_code);
break;
}
}
/*
* SCSI sysfs interface functions
*/
static ssize_t raid_state_show(struct device *dev,
struct device_attribute *attr, char *buf)
{
struct scsi_device *sdev = to_scsi_device(dev);
struct myrs_hba *cs = shost_priv(sdev->host);
int ret;
if (!sdev->hostdata)
return snprintf(buf, 16, "Unknown\n");
if (sdev->channel >= cs->ctlr_info->physchan_present) {
struct myrs_ldev_info *ldev_info = sdev->hostdata;
const char *name;
name = myrs_devstate_name(ldev_info->dev_state);
if (name)
ret = snprintf(buf, 64, "%s\n", name);
else
ret = snprintf(buf, 64, "Invalid (%02X)\n",
ldev_info->dev_state);
} else {
struct myrs_pdev_info *pdev_info;
const char *name;
pdev_info = sdev->hostdata;
name = myrs_devstate_name(pdev_info->dev_state);
if (name)
ret = snprintf(buf, 64, "%s\n", name);
else
ret = snprintf(buf, 64, "Invalid (%02X)\n",
pdev_info->dev_state);
}
return ret;
}
static ssize_t raid_state_store(struct device *dev,
struct device_attribute *attr, const char *buf, size_t count)
{
struct scsi_device *sdev = to_scsi_device(dev);
struct myrs_hba *cs = shost_priv(sdev->host);
struct myrs_cmdblk *cmd_blk;
union myrs_cmd_mbox *mbox;
enum myrs_devstate new_state;
unsigned short ldev_num;
unsigned char status;
if (!strncmp(buf, "offline", 7) ||
!strncmp(buf, "kill", 4))
new_state = MYRS_DEVICE_OFFLINE;
else if (!strncmp(buf, "online", 6))
new_state = MYRS_DEVICE_ONLINE;
else if (!strncmp(buf, "standby", 7))
new_state = MYRS_DEVICE_STANDBY;
else
return -EINVAL;
if (sdev->channel < cs->ctlr_info->physchan_present) {
struct myrs_pdev_info *pdev_info = sdev->hostdata;
struct myrs_devmap *pdev_devmap =
(struct myrs_devmap *)&pdev_info->rsvd13;
if (pdev_info->dev_state == new_state) {
sdev_printk(KERN_INFO, sdev,
"Device already in %s\n",
myrs_devstate_name(new_state));
return count;
}