1/*
2  File: AppleSCSIEmulatorAdapter.h
3
4  Contains:
5
6  Version: 1.0.0
7
8  Copyright: Copyright (c) 2007 by Apple Inc., All Rights Reserved.
9
10Disclaimer:IMPORTANT:  This Apple software is supplied to you by Apple Inc.
11("Apple") in consideration of your agreement to the following terms, and your use,
12installation, modification or redistribution of this Apple software constitutes acceptance
13of these terms.  If you do not agree with these terms, please do not use, install, modify or
14redistribute this Apple software.
15
16In consideration of your agreement to abide by the following terms, and subject
17to these terms, Apple grants you a personal, non-exclusive license, under Apple's
18copyrights in this original Apple software (the "Apple Software"), to use, reproduce,
19modify and redistribute the Apple Software, with or without modifications, in source and/or
20binary forms; provided that if you redistribute the Apple Software in its entirety
21and without modifications, you must retain this notice and the following text
22and disclaimers in all such redistributions of the Apple Software.  Neither the
23name, trademarks, service marks or logos of Apple Inc. may be used to
24endorse or promote products derived from the Apple Software without specific prior
25written permission from Apple.  Except as expressly stated in this notice, no
26other rights or licenses, express or implied, are granted by Apple herein,
27including but not limited to any patent rights that may be infringed by your derivative
28works or by other works in which the Apple Software may be incorporated.
29
30The Apple Software is provided by Apple on an "AS IS" basis.  APPLE MAKES NO WARRANTIES,
31EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION THE IMPLIED WARRANTIES OF NON-INFRINGEMENT,
32MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, REGARDING THE APPLE SOFTWARE
33OR ITS USE AND OPERATION ALONE OR IN COMBINATION WITH YOUR PRODUCTS. IN NO EVENT SHALL APPLE
34BE LIABLE FOR ANY SPECIAL, INDIRECT, INCIDENTAL OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
35NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
36OR PROFITS; OR BUSINESS INTERRUPTION) ARISING IN ANY WAY OUT OF THE USE,
37REPRODUCTION, MODIFICATION AND/OR DISTRIBUTION OF THE APPLE SOFTWARE, HOWEVER CAUSED
38AND WHETHER UNDER THEORY OF CONTRACT, TORT (INCLUDING NEGLIGENCE), STRICT
39LIABILITY OR OTHERWISE, EVEN IF APPLE HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
40*/
41
42// Code to implement a basic Parallel Tasking SCSI HBA.  In this case, a SCSI-based RAM disk.
43
44#ifndef __APPLE_SCSI_EMULATOR_ADAPTER_H__
45#define __APPLE_SCSI_EMULATOR_ADAPTER_H__
46
47
48//-----------------------------------------------------------------------------
49//	Includes
50//-----------------------------------------------------------------------------
51
52#include <IOKit/scsi/spi/IOSCSIParallelInterfaceController.h>
53#include <IOKit/scsi/SCSITask.h>
54
55#include "AppleSCSIEmulatorAdapterUC.h"
56
57// Forward declarations
58class AppleSCSIEmulatorEventSource;
59
60
61//-----------------------------------------------------------------------------
62//	Class declaration
63//-----------------------------------------------------------------------------
64
65class AppleSCSIEmulatorAdapter : public IOSCSIParallelInterfaceController
66{
67
68	OSDeclareDefaultStructors ( AppleSCSIEmulatorAdapter )
69
70public:
71
72	SCSILogicalUnitNumber	ReportHBAHighestLogicalUnitNumber ( void );
73
74	bool	DoesHBASupportSCSIParallelFeature (
75							SCSIParallelFeature 		theFeature );
76
77	bool	InitializeTargetForID (
78							SCSITargetIdentifier 		targetID );
79
80	SCSIServiceResponse	AbortTaskRequest (
81							SCSITargetIdentifier 		theT,
82							SCSILogicalUnitNumber		theL,
83							SCSITaggedTaskIdentifier	theQ );
84
85	SCSIServiceResponse AbortTaskSetRequest (
86							SCSITargetIdentifier 		theT,
87							SCSILogicalUnitNumber		theL );
88
89	SCSIServiceResponse ClearACARequest (
90							SCSITargetIdentifier 		theT,
91							SCSILogicalUnitNumber		theL );
92
93	SCSIServiceResponse ClearTaskSetRequest (
94							SCSITargetIdentifier 		theT,
95							SCSILogicalUnitNumber		theL );
96
97	SCSIServiceResponse LogicalUnitResetRequest (
98							SCSITargetIdentifier 		theT,
99							SCSILogicalUnitNumber		theL );
100
101	SCSIServiceResponse TargetResetRequest (
102							SCSITargetIdentifier 		theT );
103
104	// Methods the user client calls
105	IOReturn	CreateLUN ( EmulatorTargetParamsStruct * targetParameters, task_t task );
106	IOReturn	DestroyLUN ( SCSITargetIdentifier targetID, SCSILogicalUnitNumber logicalUnit );
107	IOReturn	DestroyTarget ( SCSITargetIdentifier targetID );
108
109
110protected:
111
112	void SetControllerProperties ( void );
113
114	void TaskComplete ( SCSIParallelTaskIdentifier parallelRequest );
115
116	void CompleteTaskOnWorkloopThread (
117							SCSIParallelTaskIdentifier		parallelRequest,
118							bool							transportSuccessful,
119							SCSITaskStatus					scsiStatus,
120							UInt64							actuallyTransferred,
121							SCSI_Sense_Data *				senseBuffer,
122							UInt8							senseLength );
123
124	SCSIInitiatorIdentifier	ReportInitiatorIdentifier ( void );
125
126	SCSIDeviceIdentifier	ReportHighestSupportedDeviceID ( void );
127
128	UInt32		ReportMaximumTaskCount ( void );
129
130	UInt32		ReportHBASpecificTaskDataSize ( void );
131
132	UInt32		ReportHBASpecificDeviceDataSize ( void );
133
134	void		ReportHBAConstraints ( OSDictionary * constraints );
135
136	bool		DoesHBAPerformDeviceManagement ( void );
137
138	bool	InitializeController ( void );
139
140	void	TerminateController ( void );
141
142	bool	StartController ( void );
143
144	void	StopController ( void );
145
146	void	HandleInterruptRequest ( void );
147
148	SCSIServiceResponse ProcessParallelTask (
149							SCSIParallelTaskIdentifier parallelRequest );
150
151	IOInterruptEventSource * CreateDeviceInterrupt (
152											IOInterruptEventSource::Action			action,
153											IOFilterInterruptEventSource::Filter	filter,
154											IOService *								provider );
155
156private:
157
158	AppleSCSIEmulatorEventSource *	fEventSource;
159	OSArray *						fTargetEmulators;
160
161};
162
163
164#endif	/* __APPLE_SCSI_EMULATOR_ADAPTER_H__ */