1/*
2 * Copyright (c) 1998-2001 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License").  You may not use this file except in compliance with the
9 * License.  Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
11 *
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT.  Please see the
17 * License for the specific language governing rights and limitations
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22#ifndef _IOKIT_IOFIREWIREIPCOMMAND_H
23#define _IOKIT_IOFIREWIREIPCOMMAND_H
24
25extern "C"{
26#include <sys/param.h>
27#include <sys/kernel.h>
28#include <sys/malloc.h>
29#include <sys/mbuf.h>
30}
31
32#include <IOKit/firewire/IOFWCommand.h>
33#include <IOKit/IOBufferMemoryDescriptor.h>
34
35#include "IOFWIPDefinitions.h"
36#include "IOFireWireIP.h"
37
38#define MAX_ALLOWED_SEGS	7
39
40class IOFireWireIP;
41class IOFWIPMBufCommand;
42class IOFWIPBusInterface;
43
44/*! @class IOFWIPAsyncWriteCommand
45*/
46class IOFWIPAsyncWriteCommand : public IOFWWriteCommand
47{
48    OSDeclareDefaultStructors(IOFWIPAsyncWriteCommand)
49
50
51protected:
52    IOBufferMemoryDescriptor	*fBuffer;
53	IOMemoryDescriptor			*fMem;
54    const UInt8					*fCommand;
55    // Maximum length for the pre allocated buffer, can be changed dynamically
56    UInt32						maxBufLen;
57	IOFWIPMBufCommand			*fMBufCommand;
58    mbuf_t						fTailMbuf;
59	UInt8*						fCursorBuf;
60	UInt32						fOffset;
61	bool						fCopy;
62	IOAddressRange				fVirtualRange[MAX_ALLOWED_SEGS];
63	UInt32						fIndex;
64	UInt32						fLength;
65	UInt32						fHeaderSize;
66	FragmentType				fLinkFragmentType;
67    IOFireWireIP				*fIPLocalNode;
68	IOFWIPBusInterface			*fIPBusIf;
69	UInt32						reInitCount;
70	UInt32						resetCount;
71
72/*! @struct ExpansionData
73    @discussion This structure will be used to expand the capablilties of the class in the future.
74    */
75    struct ExpansionData { };
76
77/*! @var reserved
78    Reserved for future use.  (Internal use only)  */
79    ExpansionData *reserved;
80
81    virtual void		free();
82
83public:
84
85	/*!
86        @function initAll
87		Initializes the Asynchronous write command object
88        @result true if successfull.
89    */
90	bool initAll(IOFireWireIP *networkObject, IOFWIPBusInterface *fwIPBusIfObject,
91					UInt32 cmdLen,FWAddress devAddress, FWDeviceCallback completion, void *refcon, bool failOnReset);
92
93	/*!
94        @function reinit
95		reinit will re-initialize all the variables for this command object, good
96		when we have to reconfigure our outgoing command objects.
97        @result true if successfull.
98    */
99    IOReturn reinit(IOFireWireNub *device, UInt32 cmdLen, FWAddress devAddress,
100					FWDeviceCallback completion, void *refcon, bool failOnReset,
101					bool deferNotify);
102
103	IOReturn transmit(IOFireWireNub *device, UInt32 cmdLen, FWAddress devAddress,
104					  FWDeviceCallback completion, void *refcon, bool failOnReset,
105					  bool deferNotify, bool doQueue, FragmentType fragmentType);
106
107	IOReturn transmit(IOFireWireNub *device, UInt32 cmdLen, FWAddress devAddress,
108					  FWDeviceCallback completion, void *refcon, bool failOnReset,
109					  bool deferNotify, bool doQueue);
110
111	void wait();
112
113	bool notDoubleComplete();
114
115	void gotAck(int ackCode);
116
117	/*!
118		@function createFragmentedDescriptors
119		@abstract creates IOVirtual ranges for fragmented Mbuf packets.
120		@param length - length to copy.
121		@result 0 if copied successfully else non-negative value
122	*/
123	IOReturn createFragmentedDescriptors();
124
125	/*!
126		@function createUnFragmentedDescriptors
127		@abstract creates IOVirtual ranges for fragmented Mbuf packets.
128		@param none.
129		@result kIOReturnSuccess if successfull, else kIOReturnError.
130	*/
131	IOReturn createUnFragmentedDescriptors();
132
133	/*!
134		@function copyToBufferDescriptors
135		@abstract copies mbuf data into the buffer pointed by IOMemoryDescriptor.
136		@param none.
137		@result 0 if copied successfully else non-negative value
138	*/
139	IOReturn copyToBufferDescriptors();
140
141	/*!
142		@function initDescriptor
143		@abstract copies mbuf data into the buffer pointed by IOMemoryDescriptor.
144		@param unfragmented - indicates whether the packet is fragmented or unfragmented.
145		@param length - length to copy.
146		@result kIOReturnSuccess, if successfull.
147	*/
148	IOReturn initDescriptor(UInt32 length);
149
150	/*!
151		@function resetDescriptor
152		@abstract resets the IOMemoryDescriptor & reinitializes the cursorbuf.
153		@result void.
154	*/
155	void resetDescriptor(IOReturn status);
156
157	/*!
158		@function initPacketHeader
159		@abstract returns a descriptor header based on fragmentation and copying
160				  of payload.
161		@result void.
162	*/
163	void* initPacketHeader(IOFWIPMBufCommand *mBufCommand, bool doCopy, FragmentType unfragmented, UInt32 headerSize, UInt32 offset);
164
165	/*!
166		@function getCursorBuf
167		@abstract returns the pointer from the current position of fBuffer.
168		@result void* - pre-allocated buffer pointer
169	*/
170	void* getCursorBuf();
171
172	/*!
173		@function getBufferFromDescriptor
174		@abstract returns the head pointer position of fBuffer.
175		@result void* - pre-allocated buffer pointer
176	*/
177	void* getBufferFromDescriptor();
178
179	/*!
180		@function getMaxBufLen
181		@abstract Usefull when MTU changes to a greater value and we need to
182				accomodate more data in the buffer without a 1394 fragmentation
183		@result UInt32 - size of the pre-allocated buffer
184	*/
185	UInt32 getMaxBufLen();
186
187private:
188    OSMetaClassDeclareReservedUnused(IOFWIPAsyncWriteCommand, 0);
189    OSMetaClassDeclareReservedUnused(IOFWIPAsyncWriteCommand, 1);
190    OSMetaClassDeclareReservedUnused(IOFWIPAsyncWriteCommand, 2);
191    OSMetaClassDeclareReservedUnused(IOFWIPAsyncWriteCommand, 3);
192};
193
194
195/*! @class IOFWIPAsyncStreamTxCommand
196*/
197class IOFWIPAsyncStreamTxCommand : public IOFWAsyncStreamCommand
198{
199    OSDeclareDefaultStructors(IOFWIPAsyncStreamTxCommand)
200
201
202protected:
203    IOBufferMemoryDescriptor	*fBuffer;
204    IOMemoryDescriptor			*fMem;
205    const UInt8					*fCommand;
206    // Maximum length for the pre allocated buffer, can be changed dynamically
207    UInt32						maxBufLen;
208    IOFireWireIP				*fIPLocalNode;
209	IOFWIPBusInterface			*fIPBusIf;
210
211/*! @struct ExpansionData
212    @discussion This structure will be used to expand the capablilties of the class in the future.
213    */
214    struct ExpansionData { };
215
216/*! @var reserved
217    Reserved for future use.  (Internal use only)  */
218    ExpansionData *reserved;
219
220    virtual void		free();
221
222public:
223	/*!
224        @function initAll
225		Initializes the Asynchronous transmit command object
226        @result true if successfull.
227    */
228    virtual bool	initAll(
229							IOFireWireIP			*networkObject,
230  							IOFireWireController 	*control,
231							IOFWIPBusInterface		*fwIPBusIfObject,
232                            UInt32 					generation,
233                            UInt32 					channel,
234                            UInt32 					sync,
235                            UInt32 					tag,
236							UInt32					cmdLen,
237                            int						speed,
238                            FWAsyncStreamCallback	completion,
239                            void 					*refcon);
240	/*!
241        @function reinit
242		reinit will re-initialize all the variables for this command object, good
243		when we have to reconfigure our outgoing command objects.
244        @result true if successfull.
245    */
246    virtual IOReturn	reinit(	UInt32 					generation,
247                                UInt32 					channel,
248                                UInt32					cmdLen,
249                                int						speed,
250                               	FWAsyncStreamCallback	completion,
251                                void 					*refcon);
252
253	void wait();
254
255	/*!
256        @function getBufferFromDesc
257		Usefull for copying data from the mbuf
258		@result void* - pre-allocated buffer pointer
259    */
260	void* getBufferFromDesc();
261
262
263	/*!
264        @function getMaxBufLen
265		Usefull when MTU changes to a greater value and we need to
266		accomodate more data in the buffer without a 1394 fragmentation
267		@result UInt32 - size of the pre-allocated buffer
268    */
269    UInt32 getMaxBufLen();
270
271private:
272    OSMetaClassDeclareReservedUnused(IOFWIPAsyncStreamTxCommand, 0);
273    OSMetaClassDeclareReservedUnused(IOFWIPAsyncStreamTxCommand, 1);
274    OSMetaClassDeclareReservedUnused(IOFWIPAsyncStreamTxCommand, 2);
275    OSMetaClassDeclareReservedUnused(IOFWIPAsyncStreamTxCommand, 3);
276};
277
278#endif // _IOKIT_IOFIREWIREIPCOMMAND_H
279
280