-
Notifications
You must be signed in to change notification settings - Fork 39
Expand file tree
/
Copy pathrc_msg.c
More file actions
executable file
·2720 lines (2268 loc) · 74.2 KB
/
Copy pathrc_msg.c
File metadata and controls
executable file
·2720 lines (2268 loc) · 74.2 KB
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 "rc.h"
#include "rc_ahci.h"
#include "asm/msr.h"
#include <linux/version.h>
#include <linux/page-flags.h>
#include <linux/vmalloc.h>
#include <linux/sysrq.h>
#include <linux/nmi.h>
#include <scsi/sg.h>
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,18,0)
#include <linux/dma-mapping.h>
#endif
int rc_setup_communications(void);
void rc_send_msg(struct rc_send_arg_s *p_send_arg);
void rc_msg_process_srb(rc_srb_t *srb);
void rc_receive_msg(void);
void rc_send_test(void);
int rc_msg_send_srb(struct scsi_cmnd * scp);
void rc_msg_check_int_tasklet(unsigned long arg);
void rc_msg_send_srb_function (rc_softstate_t *state, int function_code);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)
void rc_msg_timer(unsigned long data);
#else
void rc_msg_timer(struct timer_list * t);
#endif
void rc_msg_timeout(int to);
#if LINUX_VERSION_CODE < KERNEL_VERSION(4,15,0)
void rc_msg_timeout_done(unsigned long data);
#else
void rc_msg_timeout_done(struct timer_list * t);
#endif
void rc_msg_isr(rc_adapter_t *adapter);
void rc_msg_schedule_dpc(void);
void rc_msg_srb_done(struct rc_srb_s *srb);
void rc_msg_srb_complete(struct rc_srb_s *srb);
void rc_msg_build_sg(rc_srb_t *srb);
void rc_msg_map_phys_to_virt(struct map_memory_s *map);
void rc_msg_get_dma_memory(alloc_dma_address_t *dma_address);
void rc_msg_map_mem(struct map_memory_s *map);
void rc_msg_unmap_mem(struct unmap_memory_s *unmap);
void rc_msg_shutdown(rc_softstate_t *statep);
void rc_msg_access_ok(rc_access_ok_t accessOk);
void rc_msg_srb_q_tasklet(unsigned long arg);
void rc_msg_srb_done_tasklet(unsigned long arg);
void rc_dump_scp(struct scsi_cmnd * scp );
void rc_clear_stack(void);
int rc_msg_stats(char *buf, int buf_size);
int rc_mop_stats(char *buf, int buf_size);
void rc_wakeup_all_threads(void);
void
rc_add_dmaMemoryList(void *cpu_addr, dma_addr_t* dmaHandle, rc_uint32_t bytes,
rc_adapter_t *adapter);
extern struct rc_interface_s RC_OurInterfaceStruct;
static struct rc_interface_s *rc_interface_header = &RC_OurInterfaceStruct;
int rc_srb_seq_num = 0;
static void rc_sysrq_intr (int key
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
,struct pt_regs *pt_regs
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
,struct tty_struct * tty
#endif
);
static void rc_sysrq_state (int key
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19)
,struct pt_regs *pt_regs
#endif
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,36)
,struct tty_struct * tty
#endif
);
struct sysrq_key_op rc_skey_ops_intr = {
handler: rc_sysrq_intr,
help_msg: "rcraid-Force-interrupt",
action_msg: "forcing rcraid interrupt",
};
struct sysrq_key_op rc_skey_ops_dump = {
handler: rc_sysrq_state,
help_msg: "rcraid-Dump-state",
action_msg: "Dumping rcraid state",
};
#define check_lock(sp) { \
if (sp->osic_locked) { \
rc_printk(RC_WARN, "%s: osic already locked by %s\n", __FUNCTION__, \
sp->osic_lock_holder); \
panic("osic_lock already held\n"); \
} \
}
void
rc_set_sense_data (char *sense, uint8_t sense_key, uint8_t sense_code,
uint8_t add_sense_code, uint8_t incorrect_len,
uint8_t bit_ptr, uint32_t field_ptr, uint32_t residue);
static char rc_stats_buf[1024];
#define TWO_TRIP_WRITE_RATE_DEFAULT 16
#define TWO_TRIP_WRITE_RATE_MIN 8
#define TWO_TRIP_WRITE_RATE_MAX 1024
static int TwoTripWriteRate = TWO_TRIP_WRITE_RATE_DEFAULT;
#ifdef module_param_named
module_param_named(TwoTripWriteRate, TwoTripWriteRate, int, 0);
#else
MODULE_PARM (TwoTripWriteRate, "i");
#endif
MODULE_PARM_DESC (TwoTripWriteRate, "min write rate (kb/s) to bypass cache");
#define ONE_TRIP_WRITE_RATE_DEFAULT 8
#define ONE_TRIP_WRITE_RATE_MIN 4
#define ONE_TRIP_WRITE_RATE_MAX 256
static int OneTripWriteRate = ONE_TRIP_WRITE_RATE_DEFAULT;
#ifdef module_param_named
module_param_named(OneTripWriteRate, OneTripWriteRate, int, 0);
#else
MODULE_PARM (OneTripWriteRate, "i");
#endif
MODULE_PARM_DESC (OneTripWriteRate, "min write rate (kb/s) to bypass cache");;
#define WRITE_BYPASS_THRESHOLD_DEFAULT 50
#define WRITE_BYPASS_THRESHOLD_MIN 4
#define WRITE_BYPASS_THRESHOLD_MAX 128
static int WriteBypassThreshold = WRITE_BYPASS_THRESHOLD_DEFAULT;
#ifdef module_param_named
module_param_named(WriteBypassThreshold, WriteBypassThreshold, int, 0);
#else
MODULE_PARM (WriteBypassThreshold, "i");
#endif
MODULE_PARM_DESC (WriteBypassThreshold, "min write size (kb) to bypass cache");
#define ACTIVE_RAID5_FLUSHES_LIMIT_DEFAULT 64
#define ACTIVE_RAID5_FLUSHES_LIMIT_MIN 8
#define ACTIVE_RAID5_FLUSHES_LIMIT_MAX 128
static int ActiveRaid5FlushesLimit = ACTIVE_RAID5_FLUSHES_LIMIT_DEFAULT;
#ifdef module_param_named
module_param_named(ActiveRaid5FlushesLimit, ActiveRaid5FlushesLimit, int, 0);
#else
MODULE_PARM (ActiveRaid5FlushesLimit, "i");
#endif
MODULE_PARM_DESC (ActiveRaid5FlushesLimit, "Active Raid5 Flushes Limit");
static int ForcePhysAddr = 0;
#ifdef module_param_named
module_param_named(ForcePhysAddr, ForcePhysAddr, int, 0);
#else
MODULE_PARM (ForcePhysAddr, "i");
#endif
MODULE_PARM_DESC (ForcePhysAddr,
"force all memory references to use physical addresses");
static unsigned int DoSmart = 1;
#ifdef module_param_named
module_param_named(DoSmart, DoSmart, uint, 0444);
#else
MODULE_PARM (DoSmart, "i");
#endif
MODULE_PARM_DESC (DoSmart, "Do SMART polling");
#define SMART_POLL_INTERVAL_DEFAULT 900
static unsigned int SmartPollInterval = SMART_POLL_INTERVAL_DEFAULT;
#ifdef module_param_named
module_param_named(SmartPollInterval, SmartPollInterval, uint, 0444);
#else
MODULE_PARM (SmartPollInterval, "i");
#endif
MODULE_PARM_DESC (SmartPollInterval, "SMART poll interval in seconds");
/*
* Simple wrapper function to map printf calls from the core to vprintk
*/
int32_t
rc_vprintf(uint32_t severity, const char *format, va_list ar)
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(5,0,0)
struct timespec64 ts;
struct __kernel_old_timeval tv;
#else
struct timeval tv;
#endif
static int rc_saw_newline=1;
if (severity > rc_msg_level)
return 0;
if (severity && rc_saw_newline) {
#if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 0, 0))
ktime_get_real_ts64(&ts);
tv.tv_sec = ts.tv_sec;
tv.tv_usec = ts.tv_nsec / 1000;
#else
do_gettimeofday(&tv);
#endif
printk("rcraid: (%li.%06li) ", tv.tv_sec, tv.tv_usec);
}
rc_saw_newline = strchr(format, '\n') ? 1 : 0;
return vprintk(format, ar);
}
/*
*
* ROUTINE: rc_setup_communications
*
* This routine sets up the communications with the code that is
* installed in CPU memory.
*
* Returns:
* 1 = Success
* 0 = Failure
*/
int
rc_setup_communications(void)
{
if ( (rc_interface_header->cookie_lo == RC_COOKIE_VALUE_LO)
&& (rc_interface_header->cookie_hi == RC_COOKIE_VALUE_HI)
&& (rc_interface_header->version == RC_INTERFACE_VERSION)
&& (rc_interface_header->checksum == RC_INTERFACE_CHECKSUM)) {
//
// We found the interface structure!! Fill in the values
// with what we will use!
//
rc_printk(RC_DEBUG, "send_function: offset: %p\n", rc_interface_header->send_function);
rc_interface_header->receive_function = &rc_receive_msg;
rc_interface_header->schedule_dpc_function = & rc_msg_schedule_dpc;
return 1;
}
return 0;
}
void
rc_check_interrupt(rc_adapter_t* adapter)
{
preempt_disable();
rc_interface_header->check_interrupt_arg = adapter->private_mem.vaddr;
(*rc_interface_header->check_interrupt_function)();
preempt_enable();
}
/*
*
* ROUTINE: rc_send_msg
*
* This routine sends a command to the hardware communications
*
* Returns:
* None
*
*/
void
rc_send_msg(struct rc_send_arg_s *args)
{
preempt_disable();
rc_interface_header->send_arg = args;
(*rc_interface_header->send_function)();
preempt_enable();
}
/*
*
* ROUTINE: rc_send_test
*
* send a test command to the hardware communications
*
* Returns:
* None
*
*/
void
rc_send_test(void)
{
struct rc_send_arg_s args;
args.call_type = RC_CTS_TEST;
rc_send_msg(&args);
}
void rc_msg_free_all_dma_memory(rc_adapter_t *adapter);
/*
*
* ROUTINE: rc_msg_suspend
*
* Take actions when hibernating
*
* Returns:
* None
*
*/
void rc_msg_suspend(rc_softstate_t *state, rc_adapter_t* adapter)
{
rc_send_arg_t args;
int i;
rc_printk(RC_NOTE, "%s\n",__FUNCTION__);
state->is_suspended = 1;
// flush the logical disk cache
rc_printk(RC_ALERT, "rc_msg_suspend: flushing cache\n");
rc_msg_send_srb_function(state, RC_SRB_FLUSH);
rc_printk(RC_ALERT, "rc_msg_suspend: shutting down\n");
rc_msg_send_srb_function(state, RC_SRB_SHUTDOWN);
if ((state->state & ENABLE_TIMER) == ENABLE_TIMER)
{
rc_printk(RC_INFO2, "rc_msg_shutdown: stop OSIC timer\n");
state->state &= ~ENABLE_TIMER;
del_timer_sync(&state->timer);
}
rc_printk(RC_ALERT, "rc_msg_suspend: pausing for 1/4 second\n");
rc_msg_timeout(HZ>>2);
// make sure all IOs are completed
spin_lock(&state->osic_lock);
check_lock(state);
state->osic_locked = 1;
state->osic_lock_holder = "rc_msg_suspend";
for (i = state->num_hba - 1; i >= 0; i--)
{
if (rc_dev[i]->private_mem.vaddr) {
args.call_type = RC_CTS_STOP_ADAPTER;
args.u.adapterMemory = rc_dev[i]->private_mem.vaddr;
rc_send_msg(&args);
}
else {
rc_printk(RC_ERROR, "%s: no adapter memory :( \n",__FUNCTION__);
}
}
state->osic_locked = 0;
spin_unlock(&state->osic_lock);
for (i = state->num_hba - 1; i >= 0; i--)
{
rc_msg_free_all_dma_memory(rc_dev[i]);
}
}
/*
*
* ROUTINE: rc_msg_resume
*
* Take actions when resuming
*
* Returns:
* None
*
*/
void rc_msg_resume(rc_softstate_t *state, rc_adapter_t* adapter)
{
rc_send_arg_t args;
int i;
rc_printk(RC_NOTE, "%s\n",__FUNCTION__);
// don't lock, holding a spinlock while restarting the controller makes linux unhappy
// since the timer and interrupts are disable this should be fine
for (i = state->num_hba - 1; i >= 0; i--)
{
if (rc_dev[i]->private_mem.vaddr) {
args.call_type = RC_CTS_RESART_ADAPTER;
args.u.adapterMemory = rc_dev[i]->private_mem.vaddr;
rc_send_msg(&args);
}
else {
rc_printk(RC_ERROR, "%s: no adapter memory :( \n",__FUNCTION__);
}
}
if ((state->state & ENABLE_TIMER) != ENABLE_TIMER)
{
state->state |= ENABLE_TIMER;
add_timer(&state->timer);
}
if (state->is_suspended)
{
rc_msg_send_srb_function(state, RC_SRB_RESTART);
state->is_suspended = 0;
}
}
void
rc_msg_shutdown( rc_softstate_t *statep)
{
/*
* send a message to the OSIC to shutdown
* have to wait for it to stop doing IO.
*/
rc_printk(RC_INFO2, "rc_msg_shutdown: flushing cache OSIC\n");
rc_msg_send_srb_function(statep, RC_SRB_FLUSH);
rc_printk(RC_INFO2, "rc_msg_shutdown: shutting down OSIC\n");
rc_msg_send_srb_function(statep, RC_SRB_SHUTDOWN);
rc_printk(RC_INFO2, "rc_msg_shutdown: stop OSIC timer\n");
statep->state &= ~ENABLE_TIMER;
del_timer_sync(&statep->timer);
rc_printk(RC_DEBUG, "rc_msg_shutdown: pausing for 1/4 second\n");
rc_msg_timeout(HZ>>2);
rc_printk(RC_INFO2, "rc_msg_shutdown: OSIC disabled \n");
statep->state &= ~USE_OSIC;
rc_stop_all_threads();
rc_event_shutdown();
rc_printk(RC_INFO2, "rc_msg_shutdown: shutting down srb tasklets\n");
tasklet_kill(&statep->srb_done.tasklet);
tasklet_kill(&statep->srb_q.tasklet);
if (statep->virtual_memory) {
rc_printk(RC_DEBUG, "rc_msg_shutdown: free virtual memory %p\n",
statep->virtual_memory);
vfree(statep->virtual_memory);
statep->virtual_memory_size = 0;
statep->virtual_memory = (void *)0;
}
if (statep->cache_memory) {
rc_printk(RC_DEBUG, "rc_msg_shutdown: free cache memory %p\n",
statep->cache_memory);
vfree(statep->cache_memory);
statep->cache_memory_size = 0;
statep->cache_memory = (void *)0;
}
unregister_sysrq_key('f', &rc_skey_ops_intr);
unregister_sysrq_key('d', &rc_skey_ops_dump);
}
/*
* read or write PCI device configuration space
* - dword and byte (32 bit, 8 bit) support only
* - word (16 bit) support to be added if/when needed
*/
void rc_msg_pci_config(rc_pci_op_t *pci_op, rc_uint32_t call_type)
{
struct pci_dev *pdev = (struct pci_dev *) NULL;
rc_uint8_t tmp = 0x00;
if (pci_op &&
(pci_op->adapter < MAX_HBA) &&
(pci_op->adapter < rc_state.num_hba) &&
rc_dev[pci_op->adapter] &&
(rc_dev[pci_op->adapter])->pdev) {
// grab the pci device from the list of adapters
pdev = (rc_dev[pci_op->adapter])->pdev;
switch (call_type) {
case RC_PCI_READ_CONFIG_BYTE:
pci_op->status = pci_read_config_byte(pdev, pci_op->offset, &tmp);
if (!pci_op->status) {
pci_op->val = tmp;
}
break;
case RC_PCI_READ_CONFIG_DWORD:
pci_op->status = pci_read_config_dword(pdev, pci_op->offset, &(pci_op->val));
break;
case RC_PCI_WRITE_CONFIG_BYTE:
tmp = (rc_uint8_t) (pci_op->val);
pci_op->status = pci_write_config_byte(pdev, pci_op->offset, tmp);
break;
case RC_PCI_WRITE_CONFIG_DWORD:
pci_op->status = pci_write_config_dword(pdev, pci_op->offset, pci_op->val);
break;
default:
// set error status, anything non-zero will do
pci_op->status = call_type;
break;
}
}
if (!pdev || !pci_op || pci_op->status) {
if (!pdev && pci_op) {
// set error status, anything non-zero will do
pci_op->status = call_type;
}
rc_printk(RC_WARN, "%s: error: call_type: %d\n", __FUNCTION__, call_type);
//} else {
//RC_PRINTK(RC_WARN, "%s: call_type=%d, offset=0x%02X, val=0x%08X\n",
// __FUNCTION__, call_type, pci_op->offset, pci_op->val);
}
}
/*
*
*
*
*/
int rc_wq_handler(void *work)
{
rc_work_t *rc_work = (rc_work_t *) work;
struct rc_receive_arg_s *args;
set_current_state(TASK_INTERRUPTIBLE);
while (!kthread_should_stop())
{
//
// FIXME: We might not process these fast enough to be ready for the next request.
// Make this into a queue and keep processing while the queue isn't empty.
//
while (acpi_work_item_head)
{
//set_current_state(TASK_RUNNING);
rc_work = (rc_work_t *) acpi_work_item_head;
args = (struct rc_receive_arg_s *) rc_work->args;
switch (rc_work->call_type)
{
case RC_ACPI_INVOKE:
rc_printk(RC_INFO, "### %s(): Invoke ACPI method \"%s\"\n", __FUNCTION__, rc_work->method);
if (args->u.acpi.inPtr == NULL && args->u.acpi.outPtr == NULL &&
args->u.acpi.inSize == 0 && args->u.acpi.outSize == 0)
{
//#if LINUX_VERSION_CODE >= KERNEL_VERSION(3,2,1)
//
// Somewhere after 3.2.0, ACPI no longer enables GPE's if the device
// is WAKE capable. Instead, ACPI relies on the power management system
// to handle this. Since power management more or less requires the module
// to have a GPL license to call many of the required APIs, we need to
// deal with the GPE clear/enable here...
//
// Check if we're trying to turn off the power. If so, handle the GPE.
// (Don't want to deal with OS, especially Linux, calls in the blob. Push
// the call here so that everytime the interface changes we can add yet
// another hack... Sigh.)
//
if (strncmp((char *) &rc_work->method[strlen(rc_work->method) - 4], "_PS3", 4) == 0)
{
acpi_status ac_stat;
// Clear any pending notifcations
#if LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0)
ac_stat = acpi_clear_gpe(NULL, RC_ODD_GpeNumber, ACPI_NOT_ISR);
#else
ac_stat = acpi_clear_gpe(NULL, RC_ODD_GpeNumber);
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(3,0,0) */
// Arm for notification
ac_stat = acpi_enable_gpe(NULL, RC_ODD_GpeNumber);
}
//#endif
// Invoke only
args->u.acpi.status =
acpi_evaluate_object((acpi_handle) rc_work->handle, rc_work->method, NULL, NULL);
} else {
union acpi_object *out_object;
struct acpi_buffer outBuf = { ACPI_ALLOCATE_BUFFER, NULL };
if (args->u.acpi.inPtr)
{
if (args->u.acpi.outPtr) {
// Input and Output
args->u.acpi.status =
acpi_evaluate_object((acpi_handle) rc_work->handle, rc_work->method, args->u.acpi.inPtr, args->u.acpi.outPtr);
} else {
// Input, no Output
args->u.acpi.status =
acpi_evaluate_object((acpi_handle) rc_work->handle, rc_work->method, args->u.acpi.inPtr, NULL);
}
} else {
// Output, no Input
args->u.acpi.status =
acpi_evaluate_object((acpi_handle) rc_work->handle, rc_work->method, NULL, &outBuf);
out_object = outBuf.pointer;
if (ACPI_SUCCESS(args->u.acpi.status))
{
switch (out_object->type)
{
case ACPI_TYPE_INTEGER:
args->u.acpi.outSize = min((u64) args->u.acpi.outSize, (u64) sizeof(u64));
memcpy(args->u.acpi.outPtr, &out_object->integer.value, args->u.acpi.outSize);
break;
case ACPI_TYPE_BUFFER:
args->u.acpi.outSize = min(args->u.acpi.outSize, out_object->buffer.length);
memcpy(args->u.acpi.outPtr, out_object->buffer.pointer,
args->u.acpi.outSize);
break;
default:
;
}
}
if (outBuf.pointer)
kfree(outBuf.pointer);
}
}
break;
default:
// Only other call really is RC_QUEUE_WORK which is just a way
// to have the callback executed. Falling through allows that.
;
}
if (args->u.acpi.callback)
{
(*args->u.acpi.callback)(rc_work->args);
}
kfree((void *) rc_work->method);
spin_lock(&acpi_work_item_lock);
if (acpi_work_item_head == acpi_work_item_tail)
{
acpi_work_item_head = acpi_work_item_tail = NULL;
} else {
acpi_work_item_head = acpi_work_item_head->next;
}
spin_unlock(&acpi_work_item_lock);
kfree((void *) rc_work); // Make sure this is rc_work as kthread passes NULL for parameter work!
}
// (acpi_work_item)
schedule();
set_current_state(TASK_INTERRUPTIBLE);
}
set_current_state(TASK_RUNNING);
return 0;
}
/*
*
* ROUTINE: rc_receive_msg(void)
*
* This routine receives a message call from the hardware.
*
* Returns:
* None
*
*/
void
rc_receive_msg(void)
{
struct rc_receive_arg_s *args;
rc_softstate_t *state;
int delay;
args = rc_interface_header->receive_arg;
state = &rc_state;
preempt_enable();
switch (args->call_type) {
case RC_CTR_TEST:
rc_printk(RC_DEBUG, "rc_receive_msg Send/Receive test passed\n");
break;
case RC_CTR_SRB_DONE:
rc_msg_srb_done(args->u.srb_done.srb);
break;
case RC_CTR_INIT_DONE:
rc_printk(RC_DEBUG, "rc_receive_msg: init done callback\n");
up(&state->init_sema);
break;
case RC_CTR_ASSERTION_FAILURE:
break;
case RC_CTR_EVENT:
rc_event(args->u.event.rc_notification_type,
args->u.event.rc_bus_changed,
RC_SRB_GLOBAL_UPDATE);
break;
case RC_CTR_VMAP_MEMORY:
rc_msg_map_phys_to_virt(&args->u.map_memory);
break;
case RC_CTR_MAP_MEMORY:
rc_msg_map_mem(&args->u.map_memory);
break;
case RC_CTR_GET_DMA_ADDRESS:
rc_msg_get_dma_memory(&args->u.get_dma_memory);
break;
case RC_CTR_UNMAP_MEMORY:
rc_msg_unmap_mem(&args->u.unmap_memory);
break;
case RC_CTR_PRINT_VA:
rc_vprintf(args->u.print_va.severity, args->u.print_va.format, args->u.print_va.va_l);
break;
case RC_CTR_SCHEDULE_DPC:
rc_msg_schedule_dpc();
break;
case RC_CTR_WAIT_MICROSECONDS:
delay = args->u.wait_microseconds.microseconds;
// rc_printk(RC_DEBUG2, "delay %d microseconds\n", delay);
// Touch ALL cpu's touch_timestamp to avoid
// erroneous Soft CPU lockup's.
// Note touch_nmi_watchdog() implies touch_softlockup_watchdog() on all
// architectures that support it, and does nothing on those that don't.
// SUSE 10.1 exports it in header file, but fails to link it in...
// Works on 10.2.... Hmmm - Well Spinlocks never observed on any
// SUSE and this is a simple way to exclude it - so lets
// just exclude it from all SUSE kernels.
#ifndef CONFIG_SUSE_KERNEL
touch_nmi_watchdog();
#endif
if (delay <= 1000) {
preempt_disable();
udelay(delay);
preempt_enable();
break;
}
//
// We need to honor the osic_lock, which is implicitly telling us
// there is a msg pending on OSIC. We don't want to suspend a thread
// from bottom that the OSIC is waiting for a response from via a
// timer. However, we also cannot be doing huge udelays or we will
// get soft lock errors (udelay will overflow with large delay times
// and cause erratic behavior.).
// This msg can be received from both top and bottom, which makes it
// more confusing....
// The only time the huge udelays seem to occur during an osic_lock is
// during initialization. The initial spinup that is not induced from
// the OSIC. So I have added a state to indicate the msg_init callback
// has occured.
// So: if the OSIC is locked and delay is reasonable - use udelay.
// : if the OSIC is locked and we are done with initialization - use
// udelay.
// : Otherwise use the msg_timeout timer.
if ((state->osic_locked) && ((delay < 15000) ||
(state->state & INIT_DONE))) {
preempt_disable();
udelay(delay);
preempt_enable();
} else {
int ticks;
int usec_per_tick;
usec_per_tick = 1000000/HZ;
delay += usec_per_tick >> 1; /* round up by 1/2 clock tick */
ticks = delay / usec_per_tick;
if (ticks == 0)
ticks = 1;
rc_msg_timeout(ticks);
}
break;
case RC_CTR_MEMORY_OP:
rc_msg_mem_op(args->u.mem_op);
break;
case RC_CTR_ACCESS_OK:
rc_msg_access_ok(args->u.isAccessOk);
break;
case RC_PCI_READ_CONFIG_BYTE:
case RC_PCI_READ_CONFIG_DWORD:
case RC_PCI_WRITE_CONFIG_BYTE:
case RC_PCI_WRITE_CONFIG_DWORD:
rc_msg_pci_config(&(args->u.pci_op), args->call_type);
break;
case RC_ACPI_INVOKE:
{
#if LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0)
rc_adapter_t *adapter = rc_dev[0]; // FIXME
struct pci_dev *pdev = adapter->pdev;
acpi_handle handle = DEVICE_ACPI_HANDLE(&pdev->dev);
rc_work_t *work;
args->u.acpi.status = -1;
if (rc_wq)
{
work = (rc_work_t *) kmalloc(sizeof(rc_work_t), GFP_KERNEL);
if (work)
{
int ret;
memset(work, 0, sizeof(rc_work_t));
work->call_type = args->call_type;
work->method = (char *) kmalloc(strlen(args->u.acpi.method) + 1, GFP_KERNEL);
work->handle = handle;
work->args = args;
if (work->method)
{
memcpy(work->method, args->u.acpi.method, strlen(args->u.acpi.method) + 1);
ret = 0;
//
// FIXME: acpi_work_item might not be NULL -- need to make a queue for these...
//
spin_lock(&acpi_work_item_lock);
if (acpi_work_item_tail != NULL)
{
acpi_work_item_tail->next = work;
acpi_work_item_tail = work;
} else {
acpi_work_item_head = acpi_work_item_tail = work;
}
spin_unlock(&acpi_work_item_lock);
wake_up_process(rc_wq);
} else {
// Failed to queue -- free memory
kfree((void *) work);
}
}
}
#endif /* LINUX_VERSION_CODE >= KERNEL_VERSION(3, 13, 0) */
}
break;
case RC_ACPI_REGISTER:
{
acpi_handle handle;
switch (RC_ODD_Device)
{
case RC_ODD_DEVICE_ODDZ:
args->u.acpi.status = acpi_get_handle(NULL, "\\_SB.PCI0.SATA.ODDZ", &handle);
break;
case RC_ODD_DEVICE_ODDL:
args->u.acpi.status = acpi_get_handle(NULL, "\\_SB.PCI0.SATA.ODDL", &handle);
break;
case RC_ODD_DEVICE_ODD8:
args->u.acpi.status = acpi_get_handle(NULL, "\\_SB.PCI0.SATA.ODD8", &handle);
break;
}
if (ACPI_SUCCESS(args->u.acpi.status))
{
//
// When configured in RAID mode, the notify returns 0x80 -- that is a DEVICE
// notification. In AHCI mode, the return is 0x02 which is a SYSTEM notify.
//
args->u.acpi.status = acpi_install_notify_handler(handle, ACPI_DEVICE_NOTIFY,
args->u.acpi.context, NULL);
// Apparently, Ubuntu 13.04 sends SYSTEM notifications...
args->u.acpi.status |= acpi_install_notify_handler(handle, ACPI_SYSTEM_NOTIFY,
args->u.acpi.context, NULL);
}
}
break;
default:
rc_printk(RC_WARN,"rc_receive_msg: unknown msg type 0x%x\n",
args->call_type);
break;
}
preempt_disable();
}
/*
Tasklets for resuming and suspending. Work must be done in tasklets or Linux will hang
*/
void rc_msg_resume_work(void)
{
rc_adapter_t* adapter;
adapter = rc_dev[0];
rc_printk(RC_ERROR, "%s: schedule resume tasklet\n",__FUNCTION__);
rc_msg_resume(&rc_state, adapter);
}
void rc_msg_suspend_work(rc_adapter_t *adapter)
{
rc_printk(RC_ERROR, "%s: schedule suspend tasklet\n",__FUNCTION__);
rc_msg_suspend(&rc_state, adapter);
}
void rc_msg_init_tasklets(rc_softstate_t *state)
{
tasklet_init(&state->srb_done.tasklet, rc_msg_srb_done_tasklet,
(unsigned long)state);
tasklet_init(&state->srb_q.tasklet, rc_msg_srb_q_tasklet,
(unsigned long)state);
tasklet_init(&state->intr_tasklet, rc_msg_check_int_tasklet,
(unsigned long)state);
}
void rc_msg_kill_tasklets(rc_softstate_t *state)
{
tasklet_kill(&state->srb_done.tasklet);
tasklet_kill(&state->srb_q.tasklet);
tasklet_kill(&state->intr_tasklet);
}
/*
* setup the whole message passing system
*/
int
rc_msg_init(rc_softstate_t *state)
{
rc_send_arg_t args;
int i, size, period;
rc_adapter_t *adapter;
/*
* find the initialization struct and fill in our function pointer
*/
if (rc_setup_communications() == 0) {
rc_printk(RC_ERROR,"rc_msg_init: could not find init structure\n");
return(1);
}
rc_send_test();
/*
* setup lock and counter for processing pending interrupts
*/
atomic_set(&state->intr_pending, 0);
/*
* setup tasklet for srb q processing;
*/
state->srb_q.head = (rc_srb_t *)0;
state->srb_q.tail = (rc_srb_t *)0;
spin_lock_init(&state->srb_q.lock);
INIT_DELAYED_WORK(&state->resume_work, (void *) rc_msg_resume_work);
/*
* setup tasklet for srb done processing;
*/
state->srb_done.head = (rc_srb_t *)0;
state->srb_done.tail = (rc_srb_t *)0;
spin_lock_init(&state->srb_done.lock);
rc_msg_init_tasklets(state);
state->mop_done.head = (rc_mem_op_t *)0;
state->mop_done.tail = (rc_mem_op_t *)0;
spin_lock_init(&state->mop_done.lock);
state->osic_locked = 0;