-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathrc_init.c
2745 lines (2305 loc) · 70.6 KB
/
rc_init.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
/****************************************************************************
*
* Copyright © 2006-2008 Ciprico Inc. All rights reserved.
* Copyright © 2008-2015 Dot Hill Systems Corp. All rights reserved.
* Copyright © 2015-2016 Seagate Technology LLC. All rights reserved.
*
* Use of this software is subject to the terms and conditions of the written
* software license agreement between you and DHS (the "License"),
* including, without limitation, the following (as further elaborated in the
* License): (i) THIS SOFTWARE IS PROVIDED "AS IS", AND DHS DISCLAIMS
* ANY AND ALL WARRANTIES OF ANY KIND, WHETHER EXPRESS, IMPLIED, STATUTORY,
* BY CONDUCT, OR OTHERWISE; (ii) this software may be used only in connection
* with the integrated circuit product and storage software with which it was
* designed to be used; (iii) this source code is the confidential information
* of DHS and may not be disclosed to any third party; and (iv) you may not
* make any modification or take any action that would cause this software,
* or any other Dot Hill software, to fall under any GPL license or any other
* open source license.
*
****************************************************************************/
#include "version.h"
#define RC_DRIVER_VERSION RC_VERSION_STR
#if !defined(RC_DRIVER_BUILD_DATE)
#define RC_DRIVER_BUILD_DATE __DATE__
#endif /* !defined(RC_DRIVER_BUILD_DATE) */
#define RC_DRIVER_BUILD_TIME __TIME__
#define RC_DRIVER_NAME "rcraid"
#define RC_MAX_CMD_Q_DEPTH 1024
#define RC_DEFAULT_CMD_Q_DEPTH 512
#define RC_MAX_TAG_Q_DEPTH 255
#define RC_DEFAULT_TAG_Q_DEPTH 16
//#define RC_SUPPORT_V60_DRIVERS_ON_INTEL_PLATFORMS
//#define RC_SUPPORT_V60_DRIVERS_ON_HUDSON_PLATFORMS
#include "rc.h"
#include "version.h"
#include "build_number.h"
#include "rc_pci_ids.h"
#include <linux/hdreg.h>
#include <linux/reboot.h>
#include <linux/pci.h>
#include <linux/interrupt.h>
#include <asm/uaccess.h>
#include <linux/miscdevice.h>
#include <linux/spinlock_types.h>
#include <linux/sysctl.h>
#include <linux/pm_runtime.h>
// FIXME: some older kernels still supported by RAIDCore do not have
// DMA_BIT_MASK(). Remove once support for them has been dropped.
#ifndef DMA_BIT_MASK
#define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
#endif
MODULE_AUTHOR(VER_COMPANYNAME_STR);
MODULE_DESCRIPTION("AMD-RAID controller");
MODULE_LICENSE("GPL");
static int debug = 0;
#ifdef module_param_named
module_param_named(debug, debug, int, 0444);
#else
MODULE_PARM (debug, "i");
#endif
MODULE_PARM_DESC (debug, "debug print level");
static int cmd_q_depth = RC_DEFAULT_CMD_Q_DEPTH;
#ifdef module_param_named
module_param_named(cmd_q_depth, cmd_q_depth, int, 0444);
#else
MODULE_PARM (cmd_q_depth, "i");
#endif
MODULE_PARM_DESC (cmd_q_depth, "total command queue depth");
static int tag_q_depth = RC_DEFAULT_TAG_Q_DEPTH;
#ifdef module_param_named
module_param_named(tag_q_depth, tag_q_depth, int, 0444);
#else
MODULE_PARM (tag_q_depth, "i");
#endif
MODULE_PARM_DESC (tag_q_depth, "individual tagged command queue depth");
static int max_xfer = 448; // AHCI PRD limit is 224K or 448 sectors
#ifdef module_param_named
module_param_named(max_xfer, max_xfer, int, 0444);
#else
MODULE_PARM (max_xfer, "i");
#endif
MODULE_PARM_DESC (max_xfer, "max sectors per transfer");
// Default is to use all supported motherboard chip sets and adapter cards.
static int use_swl = RC_SHWL_TYPE_ALL;
#ifdef module_param_named
module_param_named(use_swl, use_swl, int, 0444);
#else
MODULE_PARM (use_swl, "i");
#endif
MODULE_PARM_DESC (use_swl, "Specify SWL chipsets");
// Set the number of adapters for spanning. Issues with "hot insert"
// so force this to be passed every time...
static int rc_adapter_count = 999; // Bogus value
#ifdef module_param_named
module_param_named(rc_adapter_count, rc_adapter_count, int, 0444);
#else
MODULE_PARM (rc_adapter_count, "i");
#endif /* module_param_named */
MODULE_PARM_DESC (rc_adapter_count, "Specify number of spanned adapters");
//
// Delay prior to suspend improves chance of success (from failing
// under load on second cycle to working until manually stopped).
// Add as parameter so we can vary without rebuilding/installing.
//
static int rc_suspend_delay = 5000;
#ifdef module_param_named
module_param_named(rc_suspend_delay, rc_suspend_delay, int, 0444);
#else
MODULE_PARM(rc_suspend_delay, "i");
#endif /* module_param_named */
MODULE_PARM_DESC(rc_suspend_delay, "suspend delay");
/*
* Globals
*/
int rc_config_debug = 0;
rc_softstate_t rc_state;
int rc_cntl_num = 0;
int rc_msg_level = RC_DEFAULT_ERR_LEVEL;
rc_adapter_t *rc_dev[MAX_HBA];
struct mutex ioctl_mutex;
static unsigned adapter_count = 0; /* Number of adapters on the PCI bus,
Used to determine when the last
adapter has been initialized. */
extern struct miscdevice rccfg_api_dev;
extern unsigned int RC_EnableDIPM;
extern unsigned int RC_EnableHIPM;
extern unsigned int RC_EnableAN;
extern unsigned int RC_EnableNCQ;
extern unsigned int RC_EnableZPODD;
#define RCRAID_DEFAULT_DIPM 0x00000000; /* Turn OFF DIPM for all ports by default for Linux */
#define RCRAID_DEFAULT_HIPM 0x00000000; /* Turn OFF HIPM for all ports by default for Linux */
#define RCRAID_DEFAULT_AN 0x00000001; /* Turn ON Asynchronous Notification by default for Linux */
#define RCRAID_DEFAULT_NCQ 0x00000001; /* Turn ON NCQ by default for Linux */
#define RCRAID_DEFAULT_ZPODD 0x00000001; /* Turn ON Zero Power Optical Disk Device by default for Linux */
struct task_struct *rc_wq = NULL;
rc_work_t *acpi_work_item_head = NULL;
rc_work_t *acpi_work_item_tail = NULL;
spinlock_t acpi_work_item_lock;
extern int rc_wq_handler(void *work);
/*
* function prototypes
*/
static int rc_eh_abort_cmd(struct scsi_cmnd * scmd);
static int rc_eh_dev_reset(struct scsi_cmnd * scmd);
static int rc_eh_bus_reset(struct scsi_cmnd * scmd);
static int rc_eh_hba_reset(struct scsi_cmnd * scmd);
void rc_shutdown_adapter(rc_adapter_t *adapter);
int rc_ioctl(struct scsi_device * scsi_dev_ptr, int cmd, void *arg);
void rc_dump_scp(struct scsi_cmnd * scp);
const char *rc_info(struct Scsi_Host *host_ptr);
void rc_timeout(int to);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)
void rc_timeout_done(unsigned long data);
#else
void rc_timeout_done(struct timer_list * t);
#endif
static int rc_slave_cfg(struct scsi_device *sdev);
int rc_bios_params(struct scsi_device *sdev, struct block_device *bdev,
sector_t capacity, int geom[]);
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
int rc_queue_cmd(struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *));
#else
int rc_queue_cmd_lck(struct scsi_cmnd * scp, void (*CompletionRoutine) (struct scsi_cmnd *));
#endif
#ifdef RC_AHCI_SUPPORT
// Additions for AHCI driver
static inline void rc_ahci_disable_irq(rc_adapter_t *adapter);
int rc_ahci_init(rc_adapter_t *adapter);
int rc_ahci_start(rc_adapter_t *adapter);
int rc_ahci_shutdown(rc_adapter_t *adapter);
irqreturn_t rc_ahci_isr(int irq, void *arg, struct pt_regs *regs);
#endif // RC_AHCI_SUPPORT
#if defined(RC_LSI1068) || defined(RC_MPT2)
// Additions for LSI MPT driver
int rc_mpt_init(rc_adapter_t *adapter);
int rc_mpt_start(rc_adapter_t *adapter);
int rc_mpt_shutdown(rc_adapter_t *adapter);
irqreturn_t rc_mpt_isr(int irq, void *arg, struct pt_regs *regs);
#endif // RC_LSI1068 || RC_MPT2
#ifdef RC_MPT2
int rc_mpt2_init(rc_adapter_t *adapter);
int rc_mpt2_shutdown(rc_adapter_t *adapter);
irqreturn_t rc_mpt2_isr(int irq, void *arg, struct pt_regs *regs);
#endif
void rc_remove_proc(void);
void rc_msg_isr( rc_adapter_t *adapter);
int rc_msg_send_srb(struct scsi_cmnd * scp);
int rc_msg_init(rc_softstate_t *state);
void rc_msg_shutdown(rc_softstate_t *statep);
int rc_reboot_notify(struct notifier_block *nb, ulong event, void *buf);
int rc_msg_stats(char *buf, int buf_size);
int rc_mop_stats(char *buf, int buf_size);
void rc_send_msg(struct rc_send_arg_s *p_send_arg);
void rc_msg_resume(rc_softstate_t *state, rc_adapter_t* adapter);
struct rc_pci_bar {
struct {
rc_uint32_t low;
rc_uint32_t high;
} addr;
rc_uint32_t len;
rc_uint32_t flags;
};
#ifdef RC_AHCI_SUPPORT
static rc_version_t rc_ahci_version =
{
.init_func = rc_ahci_init,
.start_func = rc_ahci_start,
.shutdown_func = rc_ahci_shutdown,
.isr_func = rc_ahci_isr,
.device_name = "rcraid",
.vendor = VER_COMPANYNAME_STR,
.model = VER_AHCI_STR,
.num_ports = 6,
.window_size = 0,
.which_bar = 5,
.swl_type = RC_SHWL_TYPE_AHCI
};
#endif
static struct pci_device_id rcraid_id_tbl[] = {
#ifdef RC_AHCI_SUPPORT
{
.vendor = RC_PD_VID_AMD,
.device = RC_PD_DID_BRISTOL,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.class = 0,
.class_mask = 0,
.driver_data = (unsigned long)&rc_ahci_version
},
{
.vendor = RC_PD_VID_AMD,
.device = RC_PD_DID_PROMONTORY,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.class = 0,
.class_mask = 0,
.driver_data = (unsigned long)&rc_ahci_version
},
{
.vendor = RC_PD_VID_AMD,
.device = RC_PD_DID_SUMMIT,
.subvendor = PCI_ANY_ID,
.subdevice = PCI_ANY_ID,
.class = 0,
.class_mask = 0,
.driver_data = (unsigned long)&rc_ahci_version
},
#endif // RC_AHCI_SUPPORT
{0,}
};
typedef struct rc_bios_disk_parameters
{
int heads;
int sectors;
int cylinders;
} rc_bios_disk_parameters_t;
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0)
typedef struct rc_proc_entry {
char *name;
struct proc_dir_entry *proc_dir;
int mode;
int which;
} rc_proc_entry_t;
static rc_proc_entry_t rc_proc_dir_entries[] = {
#define RC_PROC_DEBUG 1
{ "debug", NULL, S_IRUGO|S_IWUSR, RC_PROC_DEBUG},
#define RC_PROC_VERSION 2
{ "version", NULL, 0, RC_PROC_VERSION},
#define RC_PROC_DIPM 3
{ "dipm", NULL, S_IRUGO|S_IWUSR, RC_PROC_DIPM},
#define RC_PROC_HIPM 4
{ "hipm", NULL, S_IRUGO|S_IWUSR, RC_PROC_HIPM},
#define RC_PROC_AN 5
{ "an", NULL, S_IRUGO|S_IWUSR, RC_PROC_AN},
#define RC_PROC_NCQ 6
{ "ncq", NULL, S_IRUGO|S_IWUSR, RC_PROC_NCQ},
#define RC_PROC_ZPODD 7
{ "zpodd", NULL, S_IRUGO|S_IWUSR, RC_PROC_ZPODD},
#define RC_PROC_SLEEP 8
{ "suspend_delay", NULL, S_IRUGO | S_IWUSR, RC_PROC_SLEEP },
};
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,10,0) */
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,35)
static DEF_SCSI_QCMD(rc_queue_cmd)
#endif
static Scsi_Host_Template driver_template = {
.module = THIS_MODULE,
.name = RC_DRIVER_NAME,
.proc_name = RC_DRIVER_NAME,
.proc_dir = NULL,
.info = rc_info,
.ioctl = rc_ioctl,
.queuecommand = rc_queue_cmd,
.bios_param = rc_bios_params,
.can_queue = 1,
.this_id = -1,
.sg_tablesize = 1,
.max_sectors = 128, // 64K
.eh_abort_handler = rc_eh_abort_cmd,
.eh_device_reset_handler = rc_eh_dev_reset,
.eh_bus_reset_handler = rc_eh_bus_reset,
.eh_host_reset_handler = rc_eh_hba_reset,
#if LINUX_VERSION_CODE == KERNEL_VERSION(2,6,24)
.use_sg_chaining = ENABLE_SG_CHAINING,
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(5, 0, 0)
.use_clustering = ENABLE_CLUSTERING,
#endif
.slave_configure = rc_slave_cfg,
};
/*
* rc_init_module()
*
* One time initialization stuff, called from the module init function
* in 2.6 kernels.
*/
static void
rc_init_module(void)
{
extern char *rc_ident;
rc_printk(RC_NOTE, "%s %s raid driver version %s build_number %s built "
"%s\n", VER_COMPANYNAME_STR, RC_DRIVER_NAME,
RC_DRIVER_VERSION, RC_BUILD_NUMBER, RC_DRIVER_BUILD_DATE);
rc_printk(RC_NOTE, "%s %s\n", RC_DRIVER_NAME, rc_ident);
/*
* enforce reasonable limits on module parameters
*/
if (cmd_q_depth < 0)
cmd_q_depth = 1;
if (cmd_q_depth > RC_MAX_CMD_Q_DEPTH)
cmd_q_depth = RC_MAX_CMD_Q_DEPTH;
if (tag_q_depth < 0)
tag_q_depth = 1;
if (tag_q_depth > cmd_q_depth)
tag_q_depth = cmd_q_depth;
if (max_xfer < 8)
max_xfer = 8;
use_swl |= RC_SHWL_TYPE_CARD; // always support cards
rc_printk(RC_NOTE, "rcraid: cmd_q_depth %d, tag_q_depth %d, max_xfer "
"%d, use_swl 0x%x\n", cmd_q_depth, tag_q_depth, max_xfer,
use_swl);
rc_msg_level += debug;
if (rc_msg_level < 0)
rc_msg_level = 0;
/* Initialize the global state variable */
memset(&rc_state, 0, sizeof(rc_softstate_t));
spin_lock_init(&rc_state.osic_lock);
//rc_state.osic_lock = __SPIN_LOCK_UNLOCKED(rc_state.osic_lock);
sema_init(&rc_state.rc_timeout_sema, 0);
/* Initialize Power Management DIPM & HIPM settings */
RC_EnableDIPM = RCRAID_DEFAULT_DIPM;
RC_EnableHIPM = RCRAID_DEFAULT_HIPM;
RC_EnableAN = RCRAID_DEFAULT_AN;
RC_EnableNCQ = RCRAID_DEFAULT_NCQ;
RC_EnableZPODD = RCRAID_DEFAULT_ZPODD;
// Setup ACPI work handler
{
char thread_name[64];
sprintf(thread_name, "%s ACPI thread", RC_DRIVER_NAME);
rc_wq = kthread_run(rc_wq_handler, NULL, thread_name);
spin_lock_init(&acpi_work_item_lock);
}
}
/*
* Takes into account 64-bit bars.
* If linux changes how pci_resource_ works, this code will have to change
*/
static void
rc_get_bar(struct pci_dev *dev, int which_bar, struct rc_pci_bar *result)
{
int i, index;
struct rc_pci_bar bar;
memset(&bar, 0, sizeof(bar));
for (i = 0, index = 0; i <= which_bar; i++, index++) {
bar.addr.low = pci_resource_start(dev,index);
bar.len = pci_resource_len(dev,index);
bar.flags = pci_resource_flags(dev,index);
if (bar.flags & 0x4) {
index++;
bar.addr.high = pci_resource_start(dev,index);
} else {
bar.addr.high = 0;
}
rc_printk(RC_DEBUG, "bar %d addr 0x%x.%x len %d flags 0x%x\n",
i, bar.addr.high, bar.addr.low, bar.len, bar.flags);
}
*result = bar;
}
/*
* rc_init_adapter()
*
* Initialize a single adapter, returns 0 on success or a negative
* error code on failure.
*/
#ifdef NO_IRQ_HANDLER_T
typedef irqreturn_t (*irq_handler_t)(int, void *, struct pt_regs *);
#define RC_IRQF SA_INTERRUPT | SA_SHIRQ
#else
#define RC_IRQF IRQF_SHARED // IRQF_DISABLED | IRQF_SHARED
#endif
static int
rc_init_adapter(struct pci_dev *dev, const struct pci_device_id *id)
{
rc_adapter_t *adapter;
rc_hw_info_t *hw;
int i;
struct rc_pci_bar bar;
rc_printk(RC_DEBUG, "%s: Matched %.04x/%.04x/%.04x/%.04x\n", __FUNCTION__,
id->vendor, id->device, id->subvendor, id->subdevice);
if (rc_state.num_hba == MAX_HBA) {
rc_printk(RC_ERROR, "%s: Exceeded maximum adapter count of %d",
__FUNCTION__, MAX_HBA);
return -ENODEV;
}
if (pci_enable_device(dev))
return -ENODEV;
adapter = kmalloc(sizeof(rc_adapter_t), GFP_KERNEL);
if (adapter == NULL) {
rc_printk(RC_ERROR, "%s: can't alloc memory\n", __FUNCTION__);
return -ENODEV;
}
memset(adapter, 0, sizeof (*adapter));
adapter->pdev = dev;
adapter->instance = rc_state.num_hba;
adapter->version = (rc_version_t *)id->driver_data;
adapter->name = adapter->version->device_name;
adapter->hardware.adapter_number = rc_state.num_hba;
hw = &adapter->hardware;
hw->pci_bus = dev->bus->number;
hw->pci_slot = PCI_SLOT(dev->devfn);
rc_get_bar(dev, adapter->version->which_bar, &bar);
hw->phys_addr = bar.addr.low;
hw->mem_len = bar.len;
if (hw->phys_addr == 0) { /* No pci memory */
rc_printk(RC_ERROR, RC_DRIVER_NAME ": %s %s with pci IDs %x/%x/%x/%x "
"has no pci address space assigned\n",
adapter->version->vendor, adapter->version->model,
id->vendor, id->device, id->subvendor, id->subdevice);
rc_printk(RC_ERROR, "Check BIOS PCI settings\n");
rc_shutdown_adapter(adapter);
return -ENODEV;
}
/*
* make a copy of pci config space
*/
for (i = 0; i < (2 * PCI_CFG_SIZE); i++) { // Allow for extended pci config space
pci_read_config_byte(dev, i, &hw->pci_config_space[i]);
}
/*
* set dma_mask to 64 bit capabilities but if that fails, try 32 bit
*/
if (!pci_set_dma_mask(dev, DMA_BIT_MASK(64)) &&
!pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(64))) {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": %s 64 bit DMA enabled\n",
__FUNCTION__);
} else if (!pci_set_dma_mask(dev, DMA_BIT_MASK(32)) &&
!pci_set_consistent_dma_mask(dev, DMA_BIT_MASK(32))) {
rc_printk(RC_NOTE, RC_DRIVER_NAME ": %s 64 bit DMA disabled\n",
__FUNCTION__);
} else {
rc_printk(RC_ERROR, RC_DRIVER_NAME ": %s failed to "
"set usable DMA mask\n", __FUNCTION__);
rc_shutdown_adapter(adapter);
return -ENODEV;
}
/*
* map in the adapter MMIO space
*/
adapter->hardware.vaddr = (void *) ioremap(hw->phys_addr, hw->mem_len);
if (adapter->hardware.vaddr == NULL) {
rc_printk(RC_ERROR, RC_DRIVER_NAME ": %s can't map %s "
"adapter %d at 0x%lx\n", __FUNCTION__,
adapter->name, adapter->instance, hw->phys_addr);
rc_shutdown_adapter(adapter);
return -ENODEV;
}
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
// Check for device before calling init_func to ensure RC_EnableZPODD properly set.
{
acpi_handle handle = DEVICE_ACPI_HANDLE(&adapter->pdev->dev);
acpi_status ac_stat;
unsigned int devStat = (unsigned int) -1;
unsigned int devAddr = (unsigned int) -1;
unsigned char package[96];
int size;
//
// Initialize default GPE number. If there's a _PRW() method, we'll update
// this with what the BIOS ACPI reports.
//
// _PRW() should return a package with two integers -- 1st is GPE number (expect 6),
// 2nd is lowest sleep state (expect 3)
//
RC_ODD_GpeNumber = RC_DEFAULT_ZPODD_GPE_NUMBER;
//
// ._STA
//
// Bit 5-31 Reserved
// Bit 4 Battery present
// Bit 3 Device functioning properly
// Bit 2 Device should be shown in UI
// Bit 1 Device is enabled
// Bit 0 Device is present
//
size = sizeof(devStat);
ac_stat = rc_acpi_evaluate_object(handle, "ODDZ._STA", &devStat, &size);
if (ACPI_SUCCESS(ac_stat) && (devStat & 0xB) == 0xB)
{
RC_ODD_Device = RC_ODD_DEVICE_ODDZ;
size = sizeof(devAddr);
ac_stat = rc_acpi_evaluate_object(handle, "ODDZ._ADR", &devAddr, &size);
if (ACPI_SUCCESS(ac_stat))
{
RC_ODDZDevAddr = devAddr;
size = sizeof(package);
ac_stat = rc_acpi_evaluate_object(handle, "ODDZ._PRW", package, &size);
if (ACPI_SUCCESS(ac_stat))
{
union acpi_object *acpi_obj = (union acpi_object *) package;
union acpi_object *aObj = &acpi_obj->package.elements[0];
if (acpi_obj->type == ACPI_TYPE_PACKAGE && acpi_obj->package.count == 2)
{
RC_ODD_GpeNumber = (unsigned int) aObj->integer.value;
}
}
}
} else {
size = sizeof(devStat);
ac_stat = rc_acpi_evaluate_object(handle, "ODDL._STA", &devStat, &size);
if (ACPI_SUCCESS(ac_stat) && (devStat & 0xB) == 0xB)
{
RC_ODD_Device = RC_ODD_DEVICE_ODDL;
size = sizeof(devAddr);
ac_stat = rc_acpi_evaluate_object(handle, "ODDL._ADR", &devAddr, &size);
if (ACPI_SUCCESS(ac_stat))
{
RC_ODDZDevAddr = devAddr;
size = sizeof(package);
ac_stat = rc_acpi_evaluate_object(handle, "ODDL._PRW", package, &size);
if (ACPI_SUCCESS(ac_stat))
{
union acpi_object *acpi_obj = (union acpi_object *) package;
union acpi_object *aObj = &acpi_obj->package.elements[0];
if (acpi_obj->type == ACPI_TYPE_PACKAGE && acpi_obj->package.count == 2)
{
RC_ODD_GpeNumber = (unsigned int) aObj->integer.value;
}
}
}
} else {
size = sizeof(devStat);
ac_stat = rc_acpi_evaluate_object(handle, "ODD8._STA", &devStat, &size);
if (ACPI_SUCCESS(ac_stat) && (devStat & 0xB) == 0xB)
{
RC_ODD_Device = RC_ODD_DEVICE_ODD8;
size = sizeof(devAddr);
ac_stat = rc_acpi_evaluate_object(handle, "ODD8._ADR", &devAddr, &size);
if (ACPI_SUCCESS(ac_stat))
{
RC_ODDZDevAddr = devAddr;
size = sizeof(package);
ac_stat = rc_acpi_evaluate_object(handle, "ODD8._PRW", package, &size);
if (ACPI_SUCCESS(ac_stat))
{
union acpi_object *acpi_obj = (union acpi_object *) package;
union acpi_object *aObj = &acpi_obj->package.elements[0];
if (acpi_obj->type == ACPI_TYPE_PACKAGE && acpi_obj->package.count == 2)
{
RC_ODD_GpeNumber = (unsigned int) aObj->integer.value;
}
}
}
} else {
RC_EnableZPODD = 0;
}
}
}
}
if (RC_ODD_Device > RC_ODD_DEVICE_ODD8)
RC_ODD_Device = RC_ODD_DEVICE_INVALID;
if (!RC_EnableZPODD)
{
rc_printk(RC_INFO, "### %s(): RC_EnableZPODD = %d\n", __FUNCTION__, RC_EnableZPODD);
} else {
char ODD_Devices[4] = { '?', 'Z', 'L', '8' };
rc_printk(RC_INFO, "### %s(): RC_EnableZPODD = %d, RC_ODD_Device = ODD%c, RC_ODDZDevAddr = 0x%x, RC_ODD_GpeNumber = %d\n",
__FUNCTION__, RC_EnableZPODD, ODD_Devices[RC_ODD_Device], RC_ODDZDevAddr, RC_ODD_GpeNumber);
}
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
/* Call initialization routine */
rc_printk(RC_DEBUG, "%s: Initializing hardware...\n", __FUNCTION__);
if ((*adapter->version->init_func)(adapter) != 0) {
/* Device initialization failed */
rc_printk(RC_ERROR, RC_DRIVER_NAME ":%d Device initialization failed\n",
adapter->instance);
rc_shutdown_adapter(adapter);
return -ENODEV;
}
/* attach the interrupt */
if (request_irq(dev->irq, (void *)adapter->version->isr_func,
RC_IRQF,
adapter->version->model, (void *)adapter ) < 0) {
rc_printk(RC_ERROR, RC_DRIVER_NAME ":%d request_irq failed\n",
adapter->instance);
rc_shutdown_adapter(adapter);
return -ENODEV;
} else
rc_printk(RC_ERROR, RC_DRIVER_NAME ":%d request_threaded_irq irq %d\n",
adapter->instance,dev->irq);
hw->irq = dev->irq;
if ((*adapter->version->start_func)(adapter) != 0) {
/* Device initialization failed */
rc_printk(RC_ERROR, RC_DRIVER_NAME ":%d Device start failed\n",
adapter->instance);
rc_shutdown_adapter(adapter);
return -ENODEV;
}
pci_set_drvdata(dev, adapter);
rc_dev[rc_state.num_hba++] = adapter;
rc_printk(RC_NOTE, RC_DRIVER_NAME ": card %d: %s %s\n", adapter->instance,
adapter->version->vendor, adapter->version->model);
return 0;
}
/*
* rc_init_host()
*
* Final stage of initialization is called after the last adapter
* has been initialized. and the core started. finializes the host
* parameters.
*/
static int
rc_init_host(struct pci_dev *pdev)
{
int error;
struct Scsi_Host *host_ptr;
/* start the raid core. */
if (0 != (error = rc_msg_init(&rc_state)))
return error;
rc_printk(RC_DEBUG, "rc_init_host: calling scsi_host_alloc\n");
host_ptr = scsi_host_alloc (&driver_template, 32);
if (!host_ptr)
return -ENOMEM;
if (rc_state.state & USE_OSIC) {
host_ptr->max_id = RC_MAX_SCSI_TARGETS;
host_ptr->max_channel = 1;
host_ptr->can_queue = cmd_q_depth;
host_ptr->sg_tablesize = 32;
host_ptr->max_sectors = max_xfer;
host_ptr->cmd_per_lun = 1; // untagged queue depth
} else {
host_ptr->max_id = 9;
host_ptr->max_channel = rc_state.num_hba - 1;
host_ptr->can_queue = 1;
host_ptr->sg_tablesize = 1;
host_ptr->max_sectors = 128;
host_ptr->cmd_per_lun = 1; // untagged queue depth
}
host_ptr->max_lun = 1;
host_ptr->irq = 0;
host_ptr->base = 0;
host_ptr->max_cmd_len = 16;
host_ptr->unique_id = 0;
host_ptr->this_id = -1; /* SCSI Id for the adapter itself */
driver_template.present = 1; /* one virtual adapter */
error = scsi_add_host(host_ptr, &pdev->dev);
if (error) {
rc_printk(RC_ERROR, "Failed to add scsi host");
scsi_host_put(host_ptr);
return error;
}
rc_state.host_ptr = host_ptr;
rc_state.is_suspended = 0;
scsi_scan_host(host_ptr);
rc_printk(RC_DEBUG, "rc_init_host: completed\n");
return 0;
}
/*
* rcraid_probe_one()
*
* Called once by the 2.6 kernel for each adapter discovered.
* Returns 0 if successful or a negative error code if the
* device couldn't be initalized.
*/
static int
rcraid_probe_one(struct pci_dev *dev, const struct pci_device_id *id)
{
int ret = -ENODEV;
struct pci_device_id *probe_id;
struct pci_dev *probe_dev;
/* Count the number adapters on the bus that we will claim. */
rc_printk(RC_DEBUG, "%s rcraid ENTER\n", __FUNCTION__);
if (!adapter_count) {
for (probe_id = &rcraid_id_tbl[0]; probe_id->vendor != 0; probe_id++) {
probe_dev = NULL;
while ((probe_dev = pci_get_subsys(probe_id->vendor,
probe_id->device,
probe_id->subvendor,
probe_id->subdevice,
probe_dev))) {
rc_printk(RC_NOTE, "%s: vendor = 0x%x device 0x%x\n", __FUNCTION__,
probe_id->vendor,
probe_id->device
);
/* Found an adapter */
if (use_swl &
((rc_version_t *)probe_id->driver_data)->swl_type) {
adapter_count++;
}
}
}
rc_printk(RC_NOTE, "%s: Total adapters matched %u\n", __FUNCTION__,
adapter_count);
}
if (use_swl & ((rc_version_t *)id->driver_data)->swl_type) {
ret = rc_init_adapter(dev, id);
}
if (ret < 0) return ret;
/*
* Finished with all of the adapters, start the core and
* initialize the one virtual scsi host. The PCI device information for
* the last adapter initialized will be used for all arrays.
*/
if ((adapter_count && rc_adapter_count == rc_state.num_hba) ||
(rc_adapter_count == 999 && adapter_count == rc_state.num_hba)) {
int err;
err = rc_init_host(dev);
if (!err) {
if (misc_register(&rccfg_api_dev))
rc_printk(RC_ERROR, "%s: failed to register rc_api\n",__FUNCTION__);
mutex_init(&ioctl_mutex);
} else
return err;
}
return ret;
}
/*
* rc_shutdown_host()
*
* Shuts down the core.
*
*/
void
rc_shutdown_host(struct Scsi_Host *host_ptr)
{
if ((rc_state.state & USE_OSIC) == 0) return;
rc_state.state |= SHUTDOWN;
rc_printk(RC_DEBUG, "rc_shutdown_host\n" );
rc_msg_shutdown(&rc_state);
}
/*
* rc_shutdown_adapter()
*
* Shuts down an adapter card and frees all of its' resources.
*
*/
void
rc_shutdown_adapter(rc_adapter_t *adapter)
{
if (adapter == (rc_adapter_t *) 0) {
rc_printk(RC_DEBUG, "%s: NULL adapter\n", __FUNCTION__);
return;
}
rc_printk(RC_DEBUG, "%s: adapter %d addr 0x%p\n",
__FUNCTION__, adapter->instance, adapter);
/* Call the adapter specific shutdown function. */
if (adapter->version->shutdown_func)
(*adapter->version->shutdown_func)(adapter);
rc_printk(RC_DEBUG, "%s: free_irq\n", __FUNCTION__);
if (adapter->hardware.irq)
free_irq(adapter->hardware.irq, adapter);
rc_printk(RC_DEBUG, "%s: unmap MMIO space 0x%p\n",
__FUNCTION__, adapter->hardware.vaddr);
if (adapter->hardware.vaddr)
iounmap((void *)adapter->hardware.vaddr);
rc_printk(RC_DEBUG, "%s: free private_mem 0x%p\n",
__FUNCTION__, adapter->private_mem.vaddr);
if (adapter->private_mem.vaddr) {
pci_free_consistent(adapter->pdev,
rc_state.memsize_per_controller,
adapter->private_mem.vaddr,
adapter->private_mem.dma_address);
}
/* pci_disable_device(adapter->pdev); */
rc_printk(RC_DEBUG, "%s: free adapter 0x%p\n",
__FUNCTION__, adapter);
kfree(adapter);
}
void rc_stop_all_threads(void);
void rc_start_all_threads(void);
void rc_msg_suspend_work(rc_adapter_t *adapter);
void rc_msg_init_tasklets(rc_softstate_t *state);
void rc_msg_kill_tasklets(rc_softstate_t *state);
void rc_msg_suspend(rc_softstate_t *state, rc_adapter_t* adapter);
void rc_msg_free_all_dma_memory(rc_adapter_t *adapter);
#ifdef CONFIG_PM
/*
* rcraid_suspend_one()
*
* Called to suspend. Should do as little work as possible
* Any long running tasks should be done in the tasklet to prevent Linux from hanging
*
*/
static int rcraid_suspend_one(struct pci_dev *pdev, pm_message_t mesg)
{
rc_softstate_t *state;
rc_adapter_t *adapter;
int i;
if (pdev == NULL)
{
return 0;
}
#if 1
//
// Looks like a race condition somewhere... this delay
// seems to solve the issue with suspend/hibernate cycles.
// Placement of the delay seems to matter -- after
// scsi_block_requests() doesn't work...
//
msleep(rc_suspend_delay);
#endif /* 1 */
//
// Get adapter associated with this pci_dev
//
adapter = pci_get_drvdata(pdev);
if (!adapter)
{
return 0;
}
//
// If not master adapter (instance 0), then do nothing
//
if (adapter->instance != 0)
{
return 0;
}
//
// Inform the SCSI layer to stop sending requests down...
//
scsi_block_requests(rc_state.host_ptr);
//
// If we made it here then we're the master adapter/controller
//
state = &rc_state;
rc_printk(RC_NOTE, RC_DRIVER_NAME ": suspend pdev %p\n",
pdev);
pdev->dev.power.power_state = mesg;
rc_printk(RC_ERROR, "%s: event=%d \n",__FUNCTION__, mesg.event);
//
// Shutdown the core
//
rc_msg_suspend_work(adapter);
rc_stop_all_threads();
rc_msg_kill_tasklets(state);
rc_event_shutdown();