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 23#ifndef _IOKIT_IOFIREWIREIP_H 24#define _IOKIT_IOFIREWIREIP_H 25 26extern "C"{ 27#include <sys/param.h> 28#include <sys/kernel.h> 29#include <sys/malloc.h> 30#include <sys/mbuf.h> 31#include <sys/socket.h> 32#include <sys/sockio.h> 33#include <net/dlil.h> 34#include <sys/sysctl.h> 35#include <sys/syslog.h> 36#include <sys/kern_event.h> 37 38#include <net/if.h> 39#include <net/route.h> 40#include <net/if_dl.h> 41#include <net/if_types.h> 42#include <firewire.h> 43#include <if_firewire.h> 44#include <sys/kpi_mbuf.h> /* For MBUF_LOOP */ 45#include <netinet/in_var.h> 46#include <netinet/icmp6.h> 47#include <netinet/ip6.h> 48 49#include <sys/socketvar.h> 50#include <net/dlil.h> 51 52#include <libkern/version.h> 53} 54 55#include <IOKit/assert.h> 56#include <IOKit/IOLib.h> 57#include <IOKit/IOBSD.h> 58#include <IOKit/IOMessage.h> 59#include <IOKit/IOCommandPool.h> 60#include <IOKit/IOBufferMemoryDescriptor.h> 61#include <IOKit/IOTimerEventSource.h> 62#include <IOKit/IOInterruptEventSource.h> 63#include <IOKit/IOService.h> 64 65#include <IOKit/firewire/IOFWRegs.h> 66#include <IOKit/firewire/IOFWAddressSpace.h> 67#include <IOKit/firewire/IOLocalConfigDirectory.h> 68#include <IOKit/firewire/IOFireWireBus.h> 69#include <IOKit/firewire/IOFWDCLProgram.h> 70#include <IOKit/firewire/IOFireWireUnit.h> 71#include <IOKit/firewire/IOFireWireDevice.h> 72 73#include <IOKit/network/IOGatedOutputQueue.h> 74#include <IOFWController.h> 75#include <IOFWInterface.h> 76 77#include "IOFireWireIPCommand.h" 78#include "IOFWIPDefinitions.h" 79#include "IOFireWireIPDiagnostics.h" 80 81 82class IOFireWireNub; 83 84typedef UInt32 (*IOTransmitPacket)(mbuf_t m, void *param); 85typedef bool (*IOUpdateARPCache)(void *refcon, IP1394_ARP *fwa); 86typedef bool (*IOUpdateMulticastCache)(void *refcon, IOFWAddress *addrs, UInt32 count); 87 88typedef struct IOFireWireIPPrivateHandlers 89{ 90 OSObject *newService; 91 IOTransmitPacket transmitPacket; 92 IOUpdateARPCache updateARPCache; 93 IOUpdateMulticastCache updateMulticastCache; 94}; 95 96#include "IOFWIPBusInterface.h" 97 98const UInt32 kUnicastHi = 0x0001; 99const UInt32 kUnicastLo = 0x00000000; 100 101const UInt32 kIOFireWireIPNoResources = 0xe0009001; 102 103#define TRANSMIT_QUEUE_SIZE 256 // Overridden by IORegistry value 104 105#define NETWORK_STAT_ADD( x ) (fpNetStats->x++) 106#define ETHERNET_STAT_ADD( x ) (fpEtherStats->x++) 107 108#define GUID_TYPE 0x1 109 110 111#define kIOFireWireIPClassKey "IOFireWireIP" 112 113/*! @defined kIOFWHWAddr 114 @abstract kIOFWHWAddr is a property of IOFireWireIP 115 objects. It has an OSData value. 116 @discussion The kIOFWHWAddr property describes the hardware 117 16 byte address containing eui64, maxrec, spd & fifo address */ 118#define kIOFWHWAddr "IOFWHWAddr" 119 120/*! 121@class IOFireWireIP 122@abstract nub for IP1394 devices 123*/ 124class IOFireWireIP : public IOFWController 125{ 126 OSDeclareDefaultStructors(IOFireWireIP) 127 128friend class IOFireWireIPDiagnostics; 129friend class IOFWIPBusInterface; 130 131// Instance methods: 132private: 133 IOFWInterface *networkInterface; 134 IOBasicOutputQueue *transmitQueue; 135 IOPacketQueue *debugQueue; 136 IONetworkStats *fpNetStats; 137 IOFWStats *fpEtherStats; 138 IOFWAddress myAddress; 139 bool isPromiscuous; 140 bool multicastEnabled; 141 bool isFullDuplex; 142 bool netifEnabled; 143 bool busifEnabled; 144 bool fBuiltin; // builtin = 1; PCI card = 0 145 UInt32 linkStatusPrev; 146 UInt16 phyStatusPrev; 147 OSDictionary *mediumDict; 148 bool fClientStarting; 149 150protected: 151 IOFireWireNub *fDevice; 152 IOFireWireController *fControl; 153 IOLocalConfigDirectory *fLocalIP1394ConfigDirectory; 154 IOLocalConfigDirectory *fLocalIP1394v6ConfigDirectory; 155 OSData *fwOwnAddr; // Own hardware address of type IP1394_HDW_ADDR 156 IORecursiveLock *ipLock; 157 IOWorkLoop *workLoop; 158 IONotifier *fIPUnitNotifier; 159 IONotifier *fIPv6UnitNotifier; 160 LCB *fLcb; 161 UInt8 macAddr[kIOFWAddressSize]; 162 bool fStarted; 163 bool fPacketsQueued; 164 165 OSObject *fDiagnostics; 166 167 OSObject *fPrivateInterface; 168 IOTransmitPacket fOutAction; 169 IOUpdateARPCache fUpdateARPCache; 170 IOUpdateMulticastCache fUpdateMulticastCache; 171 172 const OSSymbol *fDiagnostics_Symbol; 173 174 /*! 175 @struct ExpansionData 176 @discussion This structure will be used to expand the capablilties of the class in the future. 177 */ 178 struct ExpansionData { }; 179 180 /*! 181 @var reserved 182 Reserved for future use. (Internal use only) 183 */ 184 ExpansionData *reserved; 185 186 187public: 188 typedef struct { 189 UInt32 fActiveBcastCmds; 190 UInt32 fInActiveBcastCmds; 191 UInt32 fActiveCmds; 192 UInt32 fInActiveCmds; 193 UInt32 fNoCommands; 194 UInt32 fNoBCastCommands; 195 UInt32 fDoubleCompletes; 196 UInt32 fCallErrs; 197 UInt32 fServiceInOutput; 198 UInt32 fServiceInCallback; 199 UInt32 fRxFragmentPkts; 200 UInt32 fTxFragmentPkts; 201 UInt16 fMaxPktSize; 202 UInt16 fMaxInputCount; 203 UInt32 fTxBcast; 204 UInt32 fRxBcast; 205 UInt32 fTxUni; 206 UInt32 fRxUni; 207 UInt32 fMaxQueueSize; 208 UInt32 fLastStarted; 209 UInt32 fMaxPacketSize; 210 211 UInt32 fGaspTagError; 212 UInt32 fGaspHeaderError; 213 UInt32 fNonRFC2734Gasp; 214 UInt32 fRemoteGaspError; // not from local bus 215 UInt32 fEncapsulationHeaderError; 216 UInt32 fNoMbufs; 217 UInt32 fInCorrectMCAPDesc; 218 UInt32 fUnknownMCAPDesc; 219 UInt32 fUnknownGroupAddress; 220 UInt32 fSubmitErrs; 221 UInt32 fNoResources; 222 223 UInt32 activeMbufs; 224 UInt32 inActiveMbufs; 225 UInt32 fBusyAcks; 226 UInt32 fFastRetryBusyAcks; 227 UInt32 fDoFastRetry; 228 UInt32 fNoRCBCommands; 229 UInt32 fRxFragmentPktsDropped; 230 }IPoFWDiagnostics; 231 232 IPoFWDiagnostics fIPoFWDiagnostics; 233 234 // IOService overrides 235 virtual bool start(IOService *provider); 236 virtual void stop(IOService *provider); 237 virtual void free(); 238 virtual bool finalize(IOOptionBits options); 239 virtual IOReturn message(UInt32 type, IOService *provider, void *argument); 240 virtual bool matchPropertyTable(OSDictionary * table); 241 242 243 #pragma mark - 244 #pragma mark ��� IOFWController defs ��� 245 virtual IOReturn setMaxPacketSize(UInt32 maxSize); 246 virtual IOReturn getMaxPacketSize(UInt32 * maxSize) const; 247 virtual bool createWorkLoop(); 248 virtual IOWorkLoop *getWorkLoop() const; 249 virtual IOOutputAction getOutputHandler() const; 250 251 virtual IOReturn enable(IONetworkInterface * netif); 252 virtual IOReturn disable(IONetworkInterface * netif); 253 254 virtual IOReturn setWakeOnMagicPacket( bool active ); 255 virtual IOReturn getPacketFilters(const OSSymbol *group, UInt32 *filters ) const; 256 257 virtual IOReturn getHardwareAddress(IOFWAddress *addr); 258 259 virtual IOReturn setMulticastMode(IOEnetMulticastMode mode); 260 virtual IOReturn setMulticastList(IOFWAddress *addrs, UInt32 count); 261 virtual IOReturn setPromiscuousMode(IOEnetPromiscuousMode mode); 262 263 virtual IOOutputQueue *createOutputQueue(); 264 265 virtual const OSString *newVendorString() const; 266 virtual const OSString *newModelString() const; 267 virtual const OSString *newRevisionString() const; 268 269 virtual bool configureInterface(IONetworkInterface *netif); 270 271 virtual void receivePackets(mbuf_t pkt, UInt32 pkt_len, UInt32 options); 272 virtual UInt32 outputPacket(mbuf_t m, void * param); 273 274 virtual bool arpCacheHandler(IP1394_ARP *fwa); 275 virtual UInt32 transmitPacket(mbuf_t m, void * param); 276 277 virtual bool multicastCacheHandler(IOFWAddress *addrs, UInt32 count); 278 279 void networkStatAdd(UInt32 *x) const 280 {(*x)++;}; 281 282 IONetworkStats* getNetStats() const 283 {return fpNetStats;}; 284 285 /*! 286 @function createMediumState 287 @abstract 288 @param none. 289 @result create a supported medium information and 290 attach to the IONetworkingFamily. 291 */ 292 bool createMediumState(); 293 294 /*! 295 @function getFeatures 296 @abstract 297 @param none. 298 @result Tell family we can handle multipage mbufs. kIONetworkFeatureMultiPages 299 */ 300 UInt32 getFeatures() const; 301 302 #pragma mark - 303 #pragma mark ��� IOFireWireIP defs ��� 304 305 UInt32 getMaxARDMAPacketSize(); 306 UInt8 getMaxARDMARec(UInt32 size); 307 308 void updateMTU(UInt32 mtu); 309 310 /*! 311 @function getDevice 312 @abstract Returns the FireWire device nub that is this object's provider . 313 */ 314 IOFireWireNub* getDevice() const 315 {return fDevice;}; 316 317 IOFireWireController *getController() const 318 {return fControl;}; 319 320 /*! 321 @function getLcb 322 @abstract Returns the link control block for the IOLocalNode 323 */ 324 LCB* getLcb() const 325 {return fLcb;}; 326 327 /*! 328 @function getIPLock 329 @abstract Returns lock from the link control block 330 */ 331 IORecursiveLock *getIPLock() const 332 {return ipLock;}; 333 334 inline void closeIPoFWGate() 335 { 336 IORecursiveLockLock(ipLock); 337 } 338 339 inline void openIPoFWGate() 340 { 341 IORecursiveLockUnlock(ipLock); 342 } 343 344 /*! 345 @function createIPConfigRomEntry 346 @abstract creates the config rom entry for IP over Firewire. 347 @param none 348 @result IOReturn - kIOReturnSuccess or error if failure. 349 */ 350 IOReturn createIPConfigRomEntry(); 351 352 /*! 353 @function fwIPUnitAttach 354 @abstract Callback for a Unit attached of type IP1394 355 @param target - callback data. 356 @param refcon - callback data. 357 @param newService - handle to the new IP1394 unit created. 358 @param notifier - handle to the notification request. 359 @result bool. 360 */ 361 static bool fwIPUnitAttach(void *target, void *refCon, IOService *newService, IONotifier * notifier); 362 363 void registerFWIPPrivateHandlers(IOFireWireIPPrivateHandlers *service); 364 365 /*! 366 @function deRegisterFWIPPrivateHandlers 367 @abstract Callback for a detaching FWIPPrivateHandlers 368 @result void. 369 */ 370 void deRegisterFWIPPrivateHandlers(); 371 372 /*! 373 @function getBytesFromGUID 374 @abstract constructs byte array from the GUID. 375 @param fwuid - GUID of the node. 376 @param bufAddr - pointer to the buffer. 377 @result void. 378 */ 379 void getBytesFromGUID(void *guid, UInt8 *bufAddr, UInt8 type); 380 381 /*! 382 @function makeEthernetAddress 383 @abstract constructs mac address from the GUID. 384 @param fwuid - GUID of the node. 385 @param bufAddr - pointer to the buffer. 386 @param vendorID - vendorID. 387 @result void. 388 */ 389 void makeEthernetAddress(CSRNodeUniqueID *fwuid, UInt8 *bufAddr, UInt32 vendorID); 390 391 bool clientStarting(); 392}; 393 394class recursiveScopeLock 395{ 396private: 397 IORecursiveLock *fLock; 398public: 399 recursiveScopeLock(IORecursiveLock *lock){fLock = lock; IORecursiveLockLock(fLock);}; 400 ~recursiveScopeLock(){IORecursiveLockUnlock(fLock);}; 401}; 402 403#endif // _IOKIT_IOFIREWIREIP_H 404 405