-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathlsp_util.c
1098 lines (941 loc) · 27.4 KB
/
lsp_util.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
#include "linux_ver.h"
#include "lsp_type_internal.h"
#include "lsp_binparm.h"
#include "lsp_debug.h"
#include "inc/lspx/lsp_hash.h"
#include "inc/lspx/lsp_util.h"
#include "inc/lspx/lsp.h"
#include "inc/lspx/lsp_ide_def.h"
lsp_status_t
lsp_call
lsp_complete_request(
lsp_handle_context_t* h,
lsp_request_packet_t* request,
lsp_status_t status);
typedef enum _lsp_ide_base_command_t {
LSP_IDE_BASE_READ,
LSP_IDE_BASE_WRITE,
LSP_IDE_BASE_VERIFY,
LSP_IDE_BASE_FLUSH,
LSP_IDE_BASE_PACKET_CMD,
LSP_IDE_BASE_PACKET_CMD_READ,
LSP_IDE_BASE_PACKET_CMD_WRITE
} lsp_ide_base_command_t;
enum { LSP_DISK_SECTOR_SIZE = 512 };
lsp_status_t
lsp_call
lsp_ide_write(
lsp_handle_t h,
const lsp_large_integer_t* location,
lsp_uint16_t sectors,
void* mutable_data,
lsp_uint32_t len)
{
lsp_request_packet_t* request;
LSP_ASSERT(NULL != h);
request = &h->session.internal_packets[0];
lsp_build_ide_write(request, h, location, sectors, mutable_data, len);
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_read(
lsp_handle_t h,
const lsp_large_integer_t* location,
lsp_uint16_t sectors,
void* mutable_data,
lsp_uint32_t len)
{
lsp_request_packet_t* request;
LSP_ASSERT(NULL != h);
request = &h->session.internal_packets[0];
lsp_build_ide_read(request, h, location, sectors, mutable_data, len);
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_verify(
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__reserved void* reserved_1,
__reserved lsp_uint32_t reserved_2)
{
lsp_request_packet_t* request;
LSP_UNREFERENCED_PARAMETER(reserved_1);
LSP_UNREFERENCED_PARAMETER(reserved_2);
LSP_ASSERT(NULL != h);
request = &h->session.internal_packets[0];
lsp_build_ide_verify(request, h, location, sectors, 0, 0);
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_flush(
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__reserved void* reserved_1,
__reserved lsp_uint32_t reserved_2)
{
lsp_request_packet_t* request;
LSP_UNREFERENCED_PARAMETER(reserved_1);
LSP_UNREFERENCED_PARAMETER(reserved_2);
LSP_ASSERT(NULL != h);
request = &h->session.internal_packets[0];
lsp_build_ide_flush(request, h, location, sectors, 0, 0);
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_setfeatures(
lsp_handle_t h,
lsp_uint8_t subcommand_code,
lsp_uint8_t subcommand_specific_0 /* sector count register */,
lsp_uint8_t subcommand_specific_1 /* lba low register */,
lsp_uint8_t subcommand_specific_2 /* lba mid register */,
lsp_uint8_t subcommand_specific_3 /* lba high register */)
{
lsp_ide_register_param_t idereg;
lsp_io_data_buffer_t data_buf;
lsp_memset(&idereg, 0, sizeof(lsp_ide_register_param_t));
lsp_memset(&data_buf, 0, sizeof(lsp_io_data_buffer_t));
/* set registers */
idereg.device.s.dev = (0 == h->session.login_info.unit_no) ? 0 : 1;
idereg.device.s.lba = 0;
idereg.command.command = LSP_IDE_CMD_SET_FEATURES;
idereg.reg.basic.reg[0] = subcommand_code;
idereg.reg.basic.reg[1] = subcommand_specific_0;
idereg.reg.basic.reg[2] = subcommand_specific_1;
idereg.reg.basic.reg[3] = subcommand_specific_2;
idereg.reg.basic.reg[4] = subcommand_specific_3;
return lsp_ide_command(h, &idereg, &data_buf, 0);
}
lsp_status_t
lsp_call
lsp_ide_atapassthrough(
lsp_handle_t h,
lsp_ide_register_param_t * idereg,
lsp_io_data_buffer_t * data_buf
)
{
/* set registers */
idereg->device.s.dev = (0 == h->session.login_info.unit_no) ? 0 : 1;
idereg->device.s.lba = 0;
return lsp_ide_command(h, idereg, data_buf, 0);
}
lsp_status_t
lsp_call
lsp_ide_identify(
lsp_handle_t h,
lsp_ide_identify_device_data_t* identify_data)
{
lsp_request_packet_t* request;
lsp_status_t status;
request = &h->session.internal_packets[0];
status = lsp_build_ide_identify(
request,
h,
identify_data);
if (LSP_STATUS_SUCCESS != status)
{
return status;
}
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_identify_packet_device(
__in lsp_handle_t h,
__out lsp_ide_identify_packet_device_data_t* ident)
{
lsp_request_packet_t* request;
request = &h->session.internal_packets[0];
lsp_build_ide_identify_packet_device(
request,
h,
ident);
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_ide_packet_cmd(
__in lsp_handle_t h,
__in void* cdb,
__inout void* mutable_data,
__in lsp_uint32_t len,
__in lsp_uint8_t data_to_target)
{
lsp_request_packet_t* request;
LSP_ASSERT(NULL != h);
request = &h->session.internal_packets[0];
lsp_build_ide_packet_cmd(request, h, cdb, mutable_data, len, data_to_target);
return lsp_request(h, request);
}
/*
returns
1 : if capacity is ok
0 : otherwise
*/
static
lsp_uint32_t
lspp_is_valid_lba24(
__in const lsp_ide_identify_device_data_t* devdata,
__out lsp_uint32_t* fixed_lba24)
{
lsp_uint32_t lba24, chs_sects, head, tail;
*fixed_lba24 = lsp_letohl(devdata->lba28_capacity);
/* If the drive is capable of handling 48 Bit LBA Address 0400h
and it is enabled, we assume that there is no restrictions
on the capacity */
if (devdata->command_set_support.big_lba &&
devdata->command_set_active.big_lba)
{
return 1;
}
/*
The ATA spec tells large drivers to return
C/H/S = 16383/16/63 independent of their size.
Some drives can be jumpered to use 15 heads instead of 16.
Some drives can be jumpered to use 4092 cyls instead of 16383
*/
/*
if((info->cyls == 16383 || (info->cyls == 4092 && info->cur_cyls== 16383)) &&
info->sectors == 63 &&
(info->heads == 15 || info->heads == 16) &&
info->lba_capacity >= (unsigned)(16383 * 63 * info->heads))
*/
if ((devdata->num_cylinders == 16383 ||
(devdata->num_cylinders == 4092 &&
devdata->number_of_current_cylinders == 16383)) &&
devdata->num_sectors_per_track == 63 &&
(devdata->num_heads == 15 || devdata->num_heads == 16) &&
devdata->lba28_capacity >= (lsp_uint32_t)(
16383 * 63 * devdata->num_heads))
{
return 1;
}
/* lba_sects = info->lba_capacity; */
lba24 = devdata->lba28_capacity;
/* chs_sects = info->cyls * info->heads * info->sectors; */
chs_sects =
devdata->num_cylinders *
devdata->num_heads *
devdata->num_sectors_per_track;
/* Perform a rough sanity check on lba_sects: within 10% is OK */
if((lba24 - chs_sects) < chs_sects / 10)
{
return 1;
}
/* Some drives have the word order reversed */
head = ((lba24 >> 16) & 0xffff);
tail = (lba24 & 0xffff);
lba24 = (head | (tail << 16));
if((lba24 - chs_sects) < chs_sects / 10)
{
/* info->lba_capacity = lba_sects; */
*fixed_lba24 = lba24;
/* Capacity reversed.... */
return 1;
}
return 0;
}
/*
if(*packet_device)
{
// 0x00: // Direct-access device
// 0x01: // Sequential-access device
// 0x02: // Printer device
// 0x03: // Processor device
// 0x04: // Write-once device
// 0x05: // CD-ROM device
// 0x06: // Scanner device
// 0x07: // Optical memory device
// 0x08: // Medium changer device
// 0x09: // Communications device
// 0x0A: 0x0B: // Reserved for ACS IT8 (Graphic arts pre-press devices)
// 0x0C: // Array controller device
// 0x0D: // Enclosure services device
// 0x0E: // Reduced block command devices
// 0x0F: // Optical card reader/writer device
// 0x1F: // Unknown or no device type
*packet_device_type = (info.config >> 8) & 0x1f; // Bits(12:8)
// nothing to do anymore
return LSP_ERR_SUCCESS;
}
*/
/*++
Parameters:
lsp_verify_hddrive_capacity
Return values:
Flags set none or more of LSP_SCF_48BIT_LBA or LSP_SCF_LBA
--*/
lsp_uint32_t
lsp_verify_hddrive_capacity(
__in const void *_info,
__out lsp_large_integer_t* capacity)
{
lsp_uint32_t flags = 0;
lsp_ide_identify_device_data_t *info;
lsp_uint64_t capacity64;
info = (lsp_ide_identify_device_data_t *)_info;
/* determine lba mode according to disk capacity. */
if (info->command_set_support.big_lba &&
info->command_set_active.big_lba)
{
/* support LBA 48 mode */
flags |= (LSP_SCF_48BIT_LBA | LSP_SCF_LBA);
/* identify data is little endian */
capacity64 = (lsp_uint64_t) lsp_letohl(info->lba48_capacity_lsw) +
((lsp_uint64_t) lsp_letohl(info->lba48_capacity_msw) << 32);
}
else if (info->capabilities.lba_supported)
{
lsp_uint32_t fixed_lba28;
if (lspp_is_valid_lba24(info, &fixed_lba28))
{
/* support LBA 28 mode */
flags |= LSP_SCF_LBA;
capacity->u.low = fixed_lba28;
capacity->u.high = 0;
}
}
else
{
/* CHS mode */
capacity64 = info->num_cylinders;
capacity64 *= info->num_heads;
capacity64 *= info->num_sectors_per_track;
capacity->u.low = (lsp_uint32_t)(capacity64 & 0x00000000FFFFFFFF);
capacity->u.high = (lsp_uint32_t)(capacity64 >> 32);
/* we do not support CHS mode */
}
return flags;
}
lsp_status_t
lsp_call
lsp_acquire_lock(lsp_handle_t h, lsp_uint8_t lock_number)
{
lsp_request_packet_t* request;
lsp_vendor_command_request_t* vc_request;
request = &h->session.internal_packets[0];
lsp_memset(request, 0, sizeof(lsp_request_packet_t));
request->type = LSP_REQUEST_VENDOR_COMMAND;
vc_request = &request->u.vendor_command.request;
vc_request->vendor_id = LSP_VENDOR_ID_XIMETA;
vc_request->vop_code = LSP_VCMD_SET_SEMA;
vc_request->vop_ver = LSP_VENDOR_OP_VERSION_1_0;
vc_request->param[0] = lock_number;
return lsp_request(h, request);
}
lsp_status_t
lsp_call
lsp_release_lock(lsp_handle_t h, lsp_uint8_t lock_number)
{
lsp_request_packet_t* request;
lsp_vendor_command_request_t* vc_request;
request = &h->session.internal_packets[0];
lsp_memset(request, 0, sizeof(lsp_request_packet_t));
request->type = LSP_REQUEST_VENDOR_COMMAND;
vc_request = &request->u.vendor_command.request;
vc_request->vendor_id = LSP_VENDOR_ID_XIMETA;
vc_request->vop_code = LSP_VCMD_FREE_SEMA;
vc_request->vop_ver = LSP_VENDOR_OP_VERSION_1_0;
vc_request->param[0] = lock_number;
return lsp_request(h, request);
}
void
lsp_call
lsp_build_login(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_login_info_t* login_info)
{
lsp_login_request_t* subreq;
h = h;
request->type = LSP_REQUEST_LOGIN;
subreq = &request->u.login.request;
subreq->login_info = *login_info;
}
void
lsp_call
lsp_build_logout(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h)
{
lsp_logout_request_t* subreq;
h = h;
request->type = LSP_REQUEST_LOGOUT;
subreq = &request->u.logout.request;
}
lsp_status_t
lsp_call
lsp_ata_handshake(
__in lsp_handle_t h)
{
lsp_request_packet_t* request;
lsp_status_t status;
request = &h->session.internal_packets[0];
lsp_build_ata_handshake(request, h);
status = lsp_request(h, request);
return status;
}
const lsp_ata_handshake_data_t*
lsp_call
lsp_get_ata_handshake_data(
__in lsp_handle_t h)
{
return &h->session.handshake_data;
}
const lsp_ide_identify_device_data_t*
lsp_call
lsp_get_ide_identify_device_data(
__in lsp_handle_t h)
{
return &h->session.identify_data.ata;
}
const lsp_hardware_data_t*
lsp_call
lsp_get_hardware_data(
__in lsp_handle_t h)
{
return &h->session.hardware_data;
}
void
lsp_call
lsp_build_ata_handshake(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h)
{
lsp_ata_handshake_request_t* subreq;
LSP_UNREFERENCED_PARAMETER(h);
request->type = LSP_REQUEST_EX_ATA_HANDSHAKE_COMMAND;
subreq = &request->u.ata_handshake_command.request;
}
lsp_status_t
lsp_call
lsp_build_ide_base_command(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__in void* buf,
__in lsp_uint32_t buflen,
__in lsp_ide_base_command_t basecmd,
__in void* cdb)
{
lsp_session_data_t* session;
lsp_ide_register_param_t idereg;
lsp_io_data_buffer_t data_buf;
lsp_extended_command_t ext_cmd;
session = &h->session;
if (!session->handshake_data.valid)
{
return LSP_STATUS_REQUIRES_HANDSHAKE;
}
if (session->handshake_data.lba)
{
if (session->handshake_data.lba48)
{
if (location->u.high >= 0x00010000)
{
return LSP_STATUS_INVALID_PARAMETER;
}
}
else
{
if (location->u.high >= 0x00000001 ||
location->u.low >= 0x10000000)
{
return LSP_STATUS_INVALID_PARAMETER;
}
}
}
else
{
LSP_ASSERT(FALSE);
}
/* parameter validation */
switch (basecmd)
{
case LSP_IDE_BASE_READ:
case LSP_IDE_BASE_WRITE:
if (0 == sectors)
{
return LSP_STATUS_INVALID_PARAMETER;
}
if (!buf)
{
return LSP_STATUS_INVALID_PARAMETER;
}
if (sectors > session->hardware_data.maximum_transfer_blocks ||
buflen != (lsp_uint32_t) sectors * LSP_DISK_SECTOR_SIZE)
{
return LSP_STATUS_INVALID_PARAMETER;
}
break;
case LSP_IDE_BASE_PACKET_CMD_READ:
case LSP_IDE_BASE_PACKET_CMD_WRITE:
if (!buf)
{
return LSP_STATUS_INVALID_PARAMETER;
}
break;
case LSP_IDE_BASE_VERIFY:
case LSP_IDE_BASE_FLUSH:
case LSP_IDE_BASE_PACKET_CMD:
break;
}
/* set registers */
lsp_memset(&idereg, 0, sizeof(lsp_ide_register_param_t));
lsp_memset(&ext_cmd, 0, sizeof(lsp_extended_command_t));
if (LSP_IDE_BASE_PACKET_CMD == basecmd ||
LSP_IDE_BASE_PACKET_CMD_READ == basecmd ||
LSP_IDE_BASE_PACKET_CMD_WRITE == basecmd)
{
/* set cdb to ext_cmd. this will be copied to ahs later */
ext_cmd.cmd_buffer = cdb;
ext_cmd.cmd_size = LSP_PACKET_COMMAND_SIZE;
/* see the spec of PACKET section in ATA-ATAPI */
/* this will set com_type_p to 1 */
idereg.command.command = LSP_IDE_CMD_PACKET;
idereg.device.s.dev = (0 == session->login_info.unit_no) ? 0 : 1;
switch (((unsigned char *)cdb)[0])
{
// Read Data.
case 0x28://kSCSICmd_READ_10:
case 0xA8://kSCSICmd_READ_12:
case 0xBE://kSCSICmd_READ_CD:
case 0x3C://kSCSICmd_Read_Buffer:
if (session->handshake_data.dma_supported)
{
// use DMA.
idereg.reg.named.features = 0x01;
}
break;
// Write Data.
case 0x2A://kSCSICmd_WRITE_10:
case 0xAA://kSCSICmd_WRITE_12:
case 0x2E://kSCSICmd_WRITE_AND_VERIFY_10:
case 0x15://kSCSICmd_MODE_SELECT_6:
case 0x55://kSCSICmd_MODE_SELECT_10:
case 0x3B://kSCSICmd_Write_Buffer:
if (session->handshake_data.dma_supported)
{
// use DMA.
idereg.reg.named.features = 0x01;
}
break;
// DVD Key
case 0xA3://kSCSICmd_SEND_KEY:
break;
default:
break;
}
}
else
{
idereg.device.s.dev = (0 == session->login_info.unit_no) ? 0 : 1;
idereg.device.s.lba = session->handshake_data.lba;
if (session->handshake_data.dma_supported)
{
if (session->handshake_data.lba48)
{
switch (basecmd)
{
case LSP_IDE_BASE_READ:
idereg.command.command = LSP_IDE_CMD_READ_DMA_EXT;
break;
case LSP_IDE_BASE_WRITE:
idereg.command.command = LSP_IDE_CMD_WRITE_DMA_EXT;
break;
case LSP_IDE_BASE_VERIFY:
idereg.command.command = LSP_IDE_CMD_READ_VERIFY_SECTORS_EXT;
break;
case LSP_IDE_BASE_FLUSH:
idereg.command.command = LSP_IDE_CMD_FLUSH_CACHE_EXT;
break;
default:
LSP_ASSERT(0);
break;
}
}
else
{
switch (basecmd)
{
case LSP_IDE_BASE_READ:
idereg.command.command = LSP_IDE_CMD_READ_DMA;
break;
case LSP_IDE_BASE_WRITE:
idereg.command.command = LSP_IDE_CMD_WRITE_DMA;
break;
case LSP_IDE_BASE_VERIFY:
idereg.command.command = LSP_IDE_CMD_READ_VERIFY_SECTORS;
break;
case LSP_IDE_BASE_FLUSH:
idereg.command.command = LSP_IDE_CMD_FLUSH_CACHE;
break;
default:
LSP_ASSERT(0);
break;
}
}
}
else
{
if (session->handshake_data.lba48)
{
switch (basecmd)
{
case LSP_IDE_BASE_READ:
idereg.command.command = LSP_IDE_CMD_READ_SECTORS_EXT;
break;
case LSP_IDE_BASE_WRITE:
idereg.command.command = LSP_IDE_CMD_WRITE_SECTORS_EXT;
break;
case LSP_IDE_BASE_VERIFY:
idereg.command.command = LSP_IDE_CMD_READ_VERIFY_SECTORS_EXT;
break;
case LSP_IDE_BASE_FLUSH:
idereg.command.command = LSP_IDE_CMD_FLUSH_CACHE_EXT;
break;
default:
LSP_ASSERT(0);
break;
}
}
else
{
switch (basecmd)
{
case LSP_IDE_BASE_READ:
idereg.command.command = LSP_IDE_CMD_READ_SECTORS;
break;
case LSP_IDE_BASE_WRITE:
idereg.command.command = LSP_IDE_CMD_WRITE_SECTORS;
break;
case LSP_IDE_BASE_VERIFY:
idereg.command.command = LSP_IDE_CMD_READ_VERIFY_SECTORS;
break;
case LSP_IDE_BASE_FLUSH:
idereg.command.command = LSP_IDE_CMD_FLUSH_CACHE;
break;
default:
LSP_ASSERT(0);
break;
}
}
}
}
if (session->handshake_data.lba48)
{
idereg.reg.named_48.cur.sector_count = (lsp_uint8_t)((sectors & 0x00FF) >> 0);
idereg.reg.named_48.prev.sector_count = (lsp_uint8_t)((sectors & 0xFF00) >> 8);
idereg.reg.named_48.cur.lba_low = (lsp_uint8_t)((location->u.low & 0x000000FF) >> 0);
idereg.reg.named_48.cur.lba_mid = (lsp_uint8_t)((location->u.low & 0x0000FF00) >> 8);
idereg.reg.named_48.cur.lba_high = (lsp_uint8_t)((location->u.low & 0x00FF0000) >> 16);
idereg.reg.named_48.prev.lba_low = (lsp_uint8_t)((location->u.low & 0xFF000000) >> 24);
idereg.reg.named_48.prev.lba_mid = (lsp_uint8_t)((location->u.high & 0x000000FF) >> 0);
idereg.reg.named_48.prev.lba_high = (lsp_uint8_t)((location->u.high & 0x0000FF00) >> 8);
}
else
{
idereg.reg.named.sector_count = (lsp_uint8_t)((sectors & 0x00FF) >> 0);
idereg.reg.named.lba_low = (lsp_uint8_t)((location->u.low & 0x000000FF) >> 0);
idereg.reg.named.lba_mid = (lsp_uint8_t)((location->u.low & 0x0000FF00) >> 8);
idereg.reg.named.lba_high = (lsp_uint8_t)((location->u.low & 0x00FF0000) >> 16);
idereg.device.s.lba_head_nr = (lsp_uint8_t)((location->u.low & 0x0F000000) >> 24);
}
/* set data buffer */
lsp_memset(&data_buf, 0, sizeof(lsp_io_data_buffer_t));
switch (basecmd)
{
case LSP_IDE_BASE_READ:
case LSP_IDE_BASE_PACKET_CMD_READ:
data_buf.recv_buffer = (lsp_uint8_t*) buf;
data_buf.recv_size = buflen;
break;
case LSP_IDE_BASE_WRITE:
case LSP_IDE_BASE_PACKET_CMD_WRITE:
data_buf.send_buffer = (lsp_uint8_t*) buf;
data_buf.send_size = buflen;
break;
case LSP_IDE_BASE_VERIFY:
case LSP_IDE_BASE_FLUSH:
case LSP_IDE_BASE_PACKET_CMD:
break;
}
lsp_build_ide_command(
request,
h,
&idereg,
&data_buf,
&ext_cmd);
return LSP_STATUS_SUCCESS;
}
lsp_status_t
lsp_call
lsp_build_ide_write(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__in void* buf,
__in lsp_uint32_t buflen)
{
return lsp_build_ide_base_command(
request, h, location, sectors,
buf, buflen,
LSP_IDE_BASE_WRITE, NULL);
}
lsp_status_t
lsp_call
lsp_build_ide_read(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__in void* buf,
__in lsp_uint32_t buflen)
{
return lsp_build_ide_base_command(
request, h, location, sectors,
buf, buflen,
LSP_IDE_BASE_READ, NULL);
}
lsp_status_t
lsp_call
lsp_build_ide_verify(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__reserved void* reserved_1,
__reserved lsp_uint32_t reserved_2)
{
return lsp_build_ide_base_command(
request, h, location, sectors,
reserved_1, reserved_2,
LSP_IDE_BASE_VERIFY, NULL);
}
lsp_status_t
lsp_call
lsp_build_ide_flush(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__reserved void* reserved_1,
__reserved lsp_uint32_t reserved_2)
{
return lsp_build_ide_base_command(
request, h, location, sectors,
reserved_1, reserved_2,
LSP_IDE_BASE_FLUSH, NULL);
}
lsp_status_t
lsp_call
lsp_build_ide_packet_cmd(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in void* cdb,
__inout void* buf,
__in lsp_uint32_t buflen,
__in lsp_uint8_t buf_to_target)
{
lsp_large_integer_t location;
lsp_memset(&location, 0, sizeof(lsp_large_integer_t));
/* see the spec of PACKET section in ATA-ATAPI */
location.u.low = buflen << 8;
return lsp_build_ide_base_command(
request,
h,
&location,
0,
buf,
buflen,
(NULL == buf) ?
LSP_IDE_BASE_PACKET_CMD :
(buf_to_target) ?
LSP_IDE_BASE_PACKET_CMD_WRITE : LSP_IDE_BASE_PACKET_CMD_READ,
cdb);
}
lsp_status_t
lsp_call
lsp_build_ide_write_fua(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in const lsp_large_integer_t* location,
__in lsp_uint16_t sectors,
__inout_bcount(len) void* buf,
__in lsp_uint32_t buf_len)
{
lsp_session_data_t* session;
lsp_ide_register_param_t idereg;
lsp_io_data_buffer_t data_buf;
session = &h->session;
if (!session->handshake_data.valid)
{
return LSP_STATUS_REQUIRES_HANDSHAKE;
}
if (!h->session.handshake_data.support.write_fua ||
!h->session.handshake_data.lba48)
{
return LSP_STATUS_NOT_SUPPORTED;
}
lsp_memset(&idereg, 0, sizeof(lsp_ide_register_param_t));
idereg.device.s.dev = (0 == session->login_info.unit_no) ? 0 : 1;
idereg.device.s.lba = session->handshake_data.lba;
LSP_ASSERT(session->handshake_data.lba48);
if (session->handshake_data.dma_supported)
{
idereg.command.command = LSP_IDE_CMD_WRITE_DMA_FUA_EXT;
}
else
{
idereg.command.command = LSP_IDE_CMD_WRITE_MULTIPLE_FUA_EXT;
}
idereg.reg.named_48.cur.sector_count = (lsp_uint8_t)((sectors & 0x00FF) >> 0);
idereg.reg.named_48.prev.sector_count = (lsp_uint8_t)((sectors & 0xFF00) >> 8);
idereg.reg.named_48.cur.lba_low = (lsp_uint8_t)((location->u.low & 0x000000FF) >> 0);
idereg.reg.named_48.cur.lba_mid = (lsp_uint8_t)((location->u.low & 0x0000FF00) >> 8);
idereg.reg.named_48.cur.lba_high = (lsp_uint8_t)((location->u.low & 0x00FF0000) >> 16);
idereg.reg.named_48.prev.lba_low = (lsp_uint8_t)((location->u.low & 0xFF000000) >> 24);
idereg.reg.named_48.prev.lba_mid = (lsp_uint8_t)((location->u.high & 0x000000FF) >> 0);
idereg.reg.named_48.prev.lba_high = (lsp_uint8_t)((location->u.high & 0x0000FF00) >> 8);
/* set data buffer */
lsp_memset(&data_buf, 0, sizeof(lsp_io_data_buffer_t));
data_buf.send_buffer = (lsp_uint8_t*) buf;
data_buf.send_size = buf_len;
lsp_build_ide_command(
request,
h,
&idereg,
&data_buf,
0);
return LSP_STATUS_SUCCESS;
}
lsp_status_t
lsp_call
lsp_build_ide_identify(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__out_bcount(sizeof(lsp_ide_identify_device_data_t))
lsp_ide_identify_device_data_t* ident)
{
lsp_ide_register_param_t idereg;
lsp_io_data_buffer_t data_buf;
/* set registers */
lsp_memset(&idereg, 0, sizeof(lsp_ide_register_param_t));
idereg.device.s.dev = (0 == h->session.login_info.unit_no) ? 0 : 1;
idereg.command.command = LSP_IDE_CMD_IDENTIFY_DEVICE;
/* set data buffer */
lsp_memset(&data_buf, 0, sizeof(lsp_io_data_buffer_t));
data_buf.recv_buffer = (lsp_uint8_t *) ident;
data_buf.recv_size = sizeof(lsp_ide_identify_device_data_t);
lsp_build_ide_command(
request,
h,
&idereg,
&data_buf, 0);
return LSP_STATUS_SUCCESS;
}
void
lsp_call
lsp_build_ide_identify_packet_device(
__inout lsp_request_packet_t* request,
__in lsp_handle_t h,
__in lsp_ide_identify_packet_device_data_t* ident)
{
lsp_ide_register_param_t idereg;
lsp_io_data_buffer_t data_buf;
/* set registers */
lsp_memset(&idereg, 0, sizeof(lsp_ide_register_param_t));
idereg.device.s.dev = (0 == h->session.login_info.unit_no) ? 0 : 1;
idereg.command.command = LSP_IDE_CMD_IDENTIFY_PACKET_DEVICE;
/* set data buffer */
lsp_memset(&data_buf, 0, sizeof(lsp_io_data_buffer_t));
data_buf.recv_buffer = (lsp_uint8_t *) ident;
data_buf.recv_size = sizeof(lsp_ide_identify_device_data_t);