-
Notifications
You must be signed in to change notification settings - Fork 8
/
SEAforth24.cpp
executable file
·156 lines (122 loc) · 4.32 KB
/
SEAforth24.cpp
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
// (C) 2009 Wager Labs, SA
// Author: Joel Reymont
// Web: http://tinyco.de
#include <AssertMacros.h>
#include <IOKit/storage/IOBlockStorageDriver.h>
#include "SEAforth24.h"
#ifdef DEBUG
#define DEBUG_LOG IOLog
#else
#define DEBUG_LOG(...)
#endif
#define super IOSCSIPeripheralDeviceType00
OSDefineMetaClassAndStructors(com_wagerlabs_driver_SEAforth24, IOSCSIPeripheralDeviceType00)
bool com_wagerlabs_driver_SEAforth24::start(IOService *provider)
{
bool result = false;
require ( super::start ( provider ), ErrorExit );
result = true;
registerService();
ErrorExit:
return result;
}
bool com_wagerlabs_driver_SEAforth24::InitializeDeviceSupport(void)
{
bool result = false;
result = super::InitializeDeviceSupport();
if ( result == true )
result = (S24Init() == kIOReturnSuccess);
return result;
}
IOReturn com_wagerlabs_driver_SEAforth24::S24Read(IOMemoryDescriptor *buffer, UInt16 bits)
{
return S24SyncIO(kS24Read, buffer, bits);
}
IOReturn com_wagerlabs_driver_SEAforth24::S24Write(IOMemoryDescriptor *buffer, UInt16 bits)
{
return S24SyncIO(kS24Write, buffer, bits);
}
IOReturn com_wagerlabs_driver_SEAforth24::S24WriteLast(IOMemoryDescriptor *buffer, UInt16 bits)
{
return S24SyncIO(kS24WriteLast, buffer, bits);
}
IOReturn com_wagerlabs_driver_SEAforth24::S24Init(void)
{
return S24SyncIO(kS24Init, NULL, 0);
}
IOReturn com_wagerlabs_driver_SEAforth24::S24SyncIO(S24Kind kind, IOMemoryDescriptor *buffer, UInt16 bits)
{
IOReturn err = kIOReturnBadArgument;
UInt8 direction, b1, b2, hi = bits >> 8, lo = bits & 0xff;
UInt64 count = 0;
SCSITaskIdentifier req = NULL;
SCSITaskStatus taskStatus = kSCSITaskStatus_No_Status;
SCSIServiceResponse serviceResponse = kSCSIServiceResponse_SERVICE_DELIVERY_OR_TARGET_FAILURE;
DEBUG_LOG("%s[%p]::%s(%d, %p)\n", getName(), this, __FUNCTION__, direction, buffer);
if (kind != kS24Init)
{
require(buffer != NULL, ErrorExit);
}
req = GetSCSITask();
require(req != NULL, ErrorExit);
switch (kind)
{
case kS24Write:
direction = kSCSIDataTransfer_FromInitiatorToTarget;
b1 = 0xFB;
b2 = 0x00;
break;
case kS24WriteLast:
direction = kSCSIDataTransfer_FromInitiatorToTarget;
b1 = 0xFB;
b2 = 0x02;
break;
case kS24Read:
direction = kSCSIDataTransfer_FromTargetToInitiator;
b1 = 0xFB;
b2 = 0x01;
break;
default: // kS24Init
direction = kSCSIDataTransfer_NoDataTransfer;
b1 = 0xFA;
b2 = 0x00;
}
SetCommandDescriptorBlock(req, 0x20, b1, b2, 0x00, 0x00, 0x00, 0x00, hi, lo, 0x00);
SetTimeoutDuration(req, 10000);
SetDataTransferDirection(req, direction);
if (buffer != NULL)
{
buffer->prepare();
SetDataBuffer(req, buffer);
SetRequestedDataTransferCount(req, buffer->getLength());
}
serviceResponse = SendCommand(req, 10000);
if (buffer != NULL)
{
buffer->complete();
}
taskStatus = GetTaskStatus(req);
count = GetRealizedDataTransferCount(req);
DEBUG_LOG("%s[%p]::%s(): service response: %lu, task status: %lu, transfer count: %lu\n",
getName(), this, __FUNCTION__, serviceResponse, taskStatus, count);
if ((serviceResponse == kSCSIServiceResponse_TASK_COMPLETE)
&& taskStatus == kSCSITaskStatus_GOOD)
err = kIOReturnSuccess;
else
err = kIOReturnError;
ReleaseSCSITask(req);
req = NULL;
ErrorExit:
return err;
}
// Padding for future binary compatibility.
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 0);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 1);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 2);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 3);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 4);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 5);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 6);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 7);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 8);
OSMetaClassDefineReservedUnused(com_wagerlabs_driver_SEAforth24, 9);