Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

5515 lines
141 KiB

  1. //
  2. // Copyright (c) 1998-1999, Microsoft Corporation, all rights reserved
  3. //
  4. // cm.c
  5. //
  6. // IEEE1394 mini-port/call-manager driver
  7. //
  8. // Call Manager routines
  9. //
  10. // 12/28/1998 JosephJ Created
  11. // 01/01/1999 ADube modified - Added Remote Node Capability
  12. //
  13. #include "precomp.h"
  14. //-----------------------------------------------------------------------------
  15. // Call-manager handlers and completers
  16. //-----------------------------------------------------------------------------
  17. NDIS_STATUS
  18. NicCmOpenAf(
  19. IN NDIS_HANDLE CallMgrBindingContext,
  20. IN PCO_ADDRESS_FAMILY AddressFamily,
  21. IN NDIS_HANDLE NdisAfHandle,
  22. OUT PNDIS_HANDLE CallMgrAfContext )
  23. // Standard 'CmCmOpenAfHandler' routine called by NDIS when a client
  24. // requests to open an address family. See DDK doc.
  25. //
  26. {
  27. ADAPTERCB* pAdapter;
  28. NDIS_HANDLE hExistingAf;
  29. NDIS_STATUS Status = NDIS_STATUS_SUCCESS;
  30. TIMESTAMP_ENTRY ("==>Open Af");
  31. TRACE( TL_T, TM_Cm, ( "==>NicCmOpenAf" ) );
  32. pAdapter = (ADAPTERCB* )CallMgrBindingContext;
  33. if (pAdapter->ulTag != MTAG_ADAPTERCB)
  34. {
  35. ASSERT( !"Atag?" );
  36. return NDIS_STATUS_INVALID_DATA;
  37. }
  38. if (AddressFamily->AddressFamily != CO_ADDRESS_FAMILY_1394
  39. || AddressFamily->MajorVersion != NDIS_MajorVersion
  40. || AddressFamily->MinorVersion != NDIS_MinorVersion)
  41. {
  42. return NDIS_STATUS_BAD_VERSION;
  43. }
  44. do
  45. {
  46. AFCB *pAF = NULL;
  47. // Allocate and initialize the adress family structure.
  48. //
  49. pAF = ALLOC_NONPAGED( sizeof(*pAF), MTAG_AFCB );
  50. if (!pAF)
  51. {
  52. Status = NDIS_STATUS_RESOURCES;
  53. break;
  54. }
  55. NdisZeroMemory( pAF, sizeof(*pAF) );
  56. // Set a marker for easier memory dump browsing and future assertions.
  57. //
  58. pAF->ulTag = MTAG_AFCB;
  59. // Save the NDIS handle associated with this AF for use in future
  60. // NdisXxx calls.
  61. //
  62. ADAPTER_ACQUIRE_LOCK( pAdapter );
  63. pAF->NdisAfHandle = NdisAfHandle;
  64. // Initialize the VC list for this AF.
  65. //
  66. InitializeListHead( &pAF->AFVCList );
  67. // Set up linkages and references.
  68. //
  69. pAF->pAdapter = pAdapter;
  70. nicReferenceAF( pAF ); // OpenAF
  71. nicReferenceAdapter( pAdapter ,"NicCmOpenAf "); // OpenAF
  72. InsertHeadList(&pAdapter->AFList, &pAF->linkAFCB);
  73. // Return pAF as the address family context.
  74. //
  75. *CallMgrAfContext = (PNDIS_HANDLE )pAF;
  76. ADAPTER_RELEASE_LOCK (pAdapter);
  77. } while (FALSE);
  78. TRACE( TL_T, TM_Cm, ( "NicCmOpenAf Status %x", Status ) );
  79. TIMESTAMP_EXIT("<==Open Af ");
  80. return Status;
  81. }
  82. NDIS_STATUS
  83. NicCmCloseAf(
  84. IN NDIS_HANDLE CallMgrAfContext )
  85. // Standard 'CmCloseAfHandler' routine called by NDIS when a client
  86. // requests to close an address family. See DDK doc.
  87. //
  88. {
  89. AFCB* pAF;
  90. TIMESTAMP_ENTRY ("==>CloseAf");
  91. TRACE( TL_T, TM_Cm, ( "NicCmCloseAf" ) );
  92. pAF = (AFCB* )CallMgrAfContext;
  93. if (pAF->ulTag != MTAG_AFCB)
  94. {
  95. ASSERT( !"AFCB?" );
  96. return NDIS_STATUS_INVALID_DATA;
  97. }
  98. nicSetFlags (&pAF->ulFlags, ACBF_ClosePending);
  99. // This dereference will eventually lead to us calling
  100. // NdisMCmCloseAfComplete.
  101. //
  102. //
  103. // The references that were made in OpenAf
  104. //
  105. nicDereferenceAF( pAF );
  106. TRACE( TL_T, TM_Cm, ( "NicCmCloseAf pending" ) );
  107. TIMESTAMP_EXIT ("<==Close Af");
  108. return NDIS_STATUS_PENDING;
  109. }
  110. NDIS_STATUS
  111. NicCmCreateVc(
  112. IN NDIS_HANDLE ProtocolAfContext,
  113. IN NDIS_HANDLE NdisVcHandle,
  114. OUT PNDIS_HANDLE ProtocolVcContext )
  115. // Standard 'CmCreateVc' routine called by NDIS in response to a
  116. // client's request to create a virtual circuit. This
  117. // call must return synchronously.
  118. //
  119. {
  120. NDIS_STATUS status;
  121. AFCB* pAF;
  122. VCCB* pVc;
  123. TRACE( TL_T, TM_Cm, ( "==>NicCmCreateVc, Af %x",ProtocolAfContext) );
  124. pAF = (AFCB* )ProtocolAfContext;
  125. if (pAF->ulTag != MTAG_AFCB)
  126. {
  127. ASSERT( !"Atag?" );
  128. return NDIS_STATUS_INVALID_DATA;
  129. }
  130. // Allocate and zero a VC control block, then make any non-zero
  131. // initializations.
  132. //
  133. pVc = ALLOC_VCCB( pAdapter );
  134. if (!pVc)
  135. {
  136. ASSERT( !"Alloc VC?" );
  137. return NDIS_STATUS_RESOURCES;
  138. }
  139. NdisZeroMemory( pVc, sizeof(*pVc) );
  140. TRACE( TL_I, TM_Cm, ( "NicCmCreateVc $%p", pVc ) );
  141. // Set a marker for easier memory dump browsing.
  142. //
  143. pVc->Hdr.ulTag = MTAG_VCCB;
  144. // Save the NDIS handle of this VC for use in indications to NDIS later.
  145. //
  146. pVc->Hdr.NdisVcHandle = NdisVcHandle;
  147. #if TODO // Adapt to 1394
  148. // Initialize link capabilities to the defaults for the adapter.
  149. //
  150. {
  151. NDIS_WAN_CO_INFO* pwci = &pAdapter->info;
  152. NDIS_WAN_CO_GET_LINK_INFO* pwcgli = &pVc->linkinfo;
  153. NdisZeroMemory( &pVc->linkinfo, sizeof(pVc->linkinfo) );
  154. pwcgli->MaxSendFrameSize = pwci->MaxFrameSize;
  155. pwcgli->MaxRecvFrameSize = pwci->MaxFrameSize;
  156. pwcgli->SendFramingBits = pwci->FramingBits;
  157. pwcgli->RecvFramingBits = pwci->FramingBits;
  158. pwcgli->SendACCM = pwci->DesiredACCM;
  159. pwcgli->RecvACCM = pwci->DesiredACCM;
  160. }
  161. #endif // TODO
  162. // The VC control block's address is the VC context we return to NDIS.
  163. //
  164. *ProtocolVcContext = (NDIS_HANDLE )pVc;
  165. // Add a reference to the control block and the associated address family
  166. // that is removed by LmpCoDeleteVc. Add the linkages.
  167. //
  168. pVc->Hdr.pAF = pAF;
  169. // Initialize the VC's copy of the spinlock to point to the Adapter's spinlock.
  170. //
  171. pVc->Hdr.plock = &pAF->pAdapter->lock;
  172. nicReferenceVc( pVc ); // Create VC
  173. nicReferenceAF( pAF ); // Create VC
  174. VC_SET_FLAG (pVc, VCBF_VcCreated);
  175. // Add to list of VC's associated with this AF
  176. //
  177. AF_ACQUIRE_LOCK (pAF);
  178. InsertHeadList(&pAF->AFVCList, &pVc->Hdr.linkAFVcs);
  179. AF_RELEASE_LOCK (pAF);
  180. TRACE( TL_T, TM_Cm, ( "<==NicCmCreateVc=0" ) );
  181. return NDIS_STATUS_SUCCESS;
  182. }
  183. NDIS_STATUS
  184. NicCmDeleteVc(
  185. IN NDIS_HANDLE ProtocolVcContext )
  186. // Standard 'CmDeleteVc' routine called by NDIS in response to a
  187. // client's request to delete a virtual circuit. This
  188. // call must return synchronously.
  189. //
  190. {
  191. VCCB* pVc = NULL;
  192. AFCB *pAF = NULL;
  193. PADAPTERCB pAdapter = NULL;
  194. TRACE( TL_T, TM_Cm, ( "==>NicCmDelVc($%p)", ProtocolVcContext ) );
  195. pVc = (VCCB* )ProtocolVcContext;
  196. if (pVc->Hdr.ulTag != MTAG_VCCB)
  197. {
  198. ASSERT( !"Vtag?" );
  199. return NDIS_STATUS_INVALID_DATA;
  200. }
  201. VC_ACQUIRE_LOCK (pVc);
  202. // Set vc flag to deleted, and remove back pointer to AF
  203. //
  204. {
  205. // This flag catches attempts by the client to delete the VC twice.
  206. //
  207. if (nicReadFlags( &pVc->Hdr.ulFlags ) & VCBF_VcDeleted)
  208. {
  209. TRACE( TL_A, TM_Cm, ( "VC $%p re-deleted?", pVc ) );
  210. VC_RELEASE_LOCK ( pVc );
  211. ASSERT (0);
  212. return NDIS_STATUS_FAILURE;
  213. }
  214. nicSetFlags( &pVc->Hdr.ulFlags, VCBF_VcDeleted );
  215. pAF = pVc->Hdr.pAF;
  216. }
  217. // Unlink from the AF vc list.
  218. //
  219. {
  220. nicRemoveEntryList (&pVc->Hdr.linkAFVcs);
  221. InitializeListHead (&pVc->Hdr.linkAFVcs);
  222. pVc->Hdr.pAF = NULL;
  223. }
  224. VC_RELEASE_LOCK (pVc);
  225. // Remove the references added by NicCmCreateVc.
  226. //
  227. nicDereferenceAF( pAF );
  228. //
  229. // This deref could cause the Vc to be deleted. Don't touch the Vc after that
  230. //
  231. nicDereferenceVc( pVc );
  232. TRACE( TL_T, TM_Cm, ( "<==NicCmDelVc 0" ) );
  233. return NDIS_STATUS_SUCCESS;
  234. }
  235. NDIS_STATUS
  236. NicCmDeleteVcSpecificType(
  237. IN PVCCB pVc)
  238. // The purpose of this function is to delete all the
  239. // buffers and structures that have allocated by the VC block
  240. // This will be expanded to more than one function as we
  241. // implement more VC types and
  242. {
  243. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
  244. TRACE( TL_T, TM_Cm, ( "==>NicCmDelVc, pVc %x",pVc) );
  245. #ifdef TODO
  246. // switch on VCTYpe
  247. // if RecvFIFOVc
  248. // Send the Free Address Range Irb to the bus driver, so it stops issueing callbacks
  249. // Free all the memory on the Fifo S-List
  250. // Make sure to dereference for each MDL freed. Also will need to make a change in
  251. // allocation routine to increment the refcount when a NEW mdl is pushed into the SLISt
  252. #endif
  253. TRACE( TL_T, TM_Cm, ( "<==NicCmDelVc, Status %x", NdisStatus ) );
  254. return NdisStatus;
  255. }
  256. NDIS_STATUS
  257. NicCmMakeCall(
  258. IN NDIS_HANDLE CallMgrVcContext,
  259. IN OUT PCO_CALL_PARAMETERS pCallParameters,
  260. IN NDIS_HANDLE NdisPartyHandle,
  261. OUT PNDIS_HANDLE CallMgrPartyContext )
  262. // Function Description:
  263. //
  264. // Standard 'CmMakeCallHandler' routine called by NDIS when the a client
  265. // has requested to connect to a remote end-point. See DDK doc.
  266. //
  267. // Arguments
  268. // Call Mge context:
  269. // Call Parameters
  270. // Optiuonal NdisPartyHandle
  271. // Return Value:
  272. //
  273. //
  274. {
  275. PVCCB pVc = (VCCB* )CallMgrVcContext;
  276. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  277. PADAPTERCB pAdapter = NULL;
  278. NDIS_WORK_ITEM* pMakeCallCompleteWorkItem = NULL;
  279. PCO_MEDIA_PARAMETERS pMediaParams = pCallParameters->MediaParameters;
  280. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS) pMediaParams->MediaSpecific.Parameters;
  281. TRACE( TL_T, TM_Cm, ( "==>NicCmMakeCall" ) );
  282. nicInterceptMakeCallParameters(pMediaParams);
  283. do
  284. {
  285. if (NdisPartyHandle != NULL ||
  286. pVc == NULL ||
  287. pCallParameters == NULL ||
  288. pCallParameters->MediaParameters == NULL ||
  289. pCallParameters->MediaParameters->MediaSpecific.ParamType != NIC1394_MEDIA_SPECIFIC ||
  290. pN1394Params->MTU == 0)
  291. {
  292. //
  293. // We do not support these parameters
  294. //
  295. return NDIS_STATUS_FAILURE;
  296. }
  297. pAdapter = pVc->Hdr.pAF->pAdapter;
  298. ASSERT (pAdapter != NULL);
  299. //
  300. // Reference the Vc so it does not go during this makeCall
  301. // This is decremented in the failure code path or the workitem or
  302. // when the call is closed
  303. VC_ACQUIRE_LOCK (pVc);
  304. nicReferenceVc (pVc);
  305. //
  306. // Erase all references to past calls
  307. //
  308. VC_CLEAR_FLAGS (pVc, VCBM_NoActiveCall);
  309. VC_SET_FLAG (pVc, VCBF_MakeCallPending);
  310. //
  311. // Initialize the Call's refcount to 1 beacuse we are about to begin to allocate resources to the MakeCall
  312. // This will be decremented in the closecall handler. Or in the failure code path
  313. //
  314. nicInitializeCallRef (pVc);
  315. VC_RELEASE_LOCK (pVc);
  316. pVc->Hdr.pCallParameters = pCallParameters;
  317. NdisStatus = nicCmGenericMakeCallInit (pVc);
  318. if (NdisStatus != NDIS_STATUS_SUCCESS)
  319. {
  320. TRACE( TL_A, TM_Cm, ( "nicCmGenericMakeCallInit did not succeed- Make Call FAILED($%p)", CallMgrVcContext ) );
  321. break;
  322. }
  323. //
  324. // If status is pending it means that we want to make this an asynchronous call
  325. // The completing th
  326. pMakeCallCompleteWorkItem = ALLOC_NONPAGED (sizeof(NDIS_WORK_ITEM), MTAG_WORKITEM);
  327. if (pMakeCallCompleteWorkItem == NULL)
  328. {
  329. TRACE( TL_A, TM_Cm, ( "Local Alloc failed for WorkItem - Make Call FAILED($%p)", CallMgrVcContext ) );
  330. NdisStatus = NDIS_STATUS_RESOURCES;
  331. break;
  332. }
  333. //
  334. // Now schedule the work item so it runs at passive level and pass the Vc as
  335. // an argument
  336. //
  337. NdisInitializeWorkItem ( pMakeCallCompleteWorkItem,
  338. (NDIS_PROC)nicCmMakeCallComplete,
  339. (PVOID)pVc );
  340. NdisInterlockedIncrement(&pAdapter->OutstandingWorkItems);
  341. NdisScheduleWorkItem (pMakeCallCompleteWorkItem);
  342. NdisStatus = NDIS_STATUS_PENDING;
  343. } while (FALSE);
  344. if (!NT_SUCCESS (NdisStatus))
  345. {
  346. //
  347. // Clean up, close the ref on the Calls, Deref the Call. And Update the Vc
  348. // to show that we have failed the make call
  349. //
  350. nicCmGenrericMakeCallFailure (pVc);
  351. }
  352. TRACE( TL_T, TM_Cm, ( "<==NicCmMakeCall, Vc %x, Status%x", pVc, NdisStatus ) );
  353. return NdisStatus;
  354. }
  355. #if SEPERATE_CHANNEL_TYPE
  356. NDIS_STATUS
  357. nicCmGenericMakeCallInitChannels (
  358. IN PCHANNEL_VCCB pChannelVc,
  359. VC_SEND_RECEIVE VcType
  360. )
  361. /*++
  362. Routine Description:
  363. Initialze handlers for Send / Recv Channels
  364. Arguments:
  365. Return Value:
  366. --*/
  367. {
  368. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS; // As there are no allocations
  369. PCO_MEDIA_PARAMETERS pMediaParams = pChannelVc->Hdr.pCallParameters->MediaParameters;
  370. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS) pMediaParams->MediaSpecific.Parameters;
  371. if ((pN1394Params->Flags & NIC1394_VCFLAG_ALLOCATE) == NIC1394_VCFLAG_ALLOCATE)
  372. {
  373. TRACE( TL_V, TM_Cm, ( " MakeCall- Channel Vc %x nneds to allocate channel %x",
  374. pChannelVc,
  375. pN1394Params->Destination.Channel) );
  376. VC_SET_FLAG (pChannelVc, VCBF_NeedsToAllocateChannel);
  377. }
  378. switch (VcType)
  379. {
  380. case TransmitAndReceiveVc:
  381. {
  382. //
  383. // Channels will be defaulted to have Send And Receive Capabilities
  384. //
  385. TRACE( TL_V, TM_Cm, ( " MakeCall- Channel Transmit and Receive Vc Vc %x", pChannelVc ) );
  386. pChannelVc->Hdr.VcType = NIC1394_SendRecvChannel;
  387. pChannelVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitSendRecvChannelVc;
  388. pChannelVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendRecvChannel;
  389. pChannelVc->Hdr.VcHandlers.SendPackets = AsyncStreamSendPacketsHandler;
  390. break;
  391. }
  392. case ReceiveVc:
  393. {
  394. TRACE( TL_V, TM_Cm, ( " MakeCall- Channel Receive Vc %x", pChannelVc ) );
  395. pChannelVc->Hdr.VcType = NIC1394_RecvChannel;
  396. pChannelVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitSendRecvChannelVc;
  397. pChannelVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendRecvChannel;
  398. pChannelVc->Hdr.VcHandlers.SendPackets = DummySendPacketsHandler;
  399. break;
  400. }
  401. case TransmitVc:
  402. {
  403. TRACE( TL_V, TM_Cm, ( " MakeCall- Channel Transmit Vc Vc %x", pChannelVc ) );
  404. pChannelVc->Hdr.VcType = NIC1394_SendChannel;
  405. pChannelVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallSendChannel ;
  406. pChannelVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendChannel;
  407. pChannelVc->Hdr.VcHandlers.SendPackets = AsyncStreamSendPacketsHandler;
  408. break;
  409. }
  410. default:
  411. {
  412. NdisStatus = NDIS_STATUS_FAILURE;
  413. }
  414. }
  415. return NdisStatus;
  416. }
  417. NDIS_STATUS
  418. nicCmGenericMakeCallInitFifo (
  419. IN PVCCB pVc,
  420. VC_SEND_RECEIVE VcType
  421. )
  422. /*++
  423. Routine Description:
  424. Initializes Fifo Vcs'. This only fails a recv fifo is asked for and the
  425. adapter already has one.
  426. Arguments:
  427. pVc
  428. Return Value:
  429. --*/
  430. {
  431. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS; //As there are no allocations
  432. PCO_MEDIA_PARAMETERS pMediaParams = pVc->Hdr.pCallParameters->MediaParameters;
  433. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS) pMediaParams->MediaSpecific.Parameters;
  434. switch (VcType)
  435. {
  436. case ReceiveVc:
  437. {
  438. //
  439. // Recv FifoVcs
  440. //
  441. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  442. PRECVFIFO_VCCB pRecvFIFOVc = (PRECVFIFO_VCCB) pVc;
  443. ASSERT(pMediaParams->Flags & RECEIVE_VC);
  444. TRACE( TL_V, TM_Cm, ( " MakeCall - AsyncReceiveVc Vc %x", pVc ) );
  445. pVc->Hdr.VcType = NIC1394_RecvFIFO;
  446. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitRecvFIFOVc;
  447. pVc->Hdr.VcHandlers.SendPackets = DummySendPacketsHandler;
  448. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallRecvFIFO;
  449. //
  450. // There are two reasons to fail a RecvFIFO Make call.
  451. // One, a REcvFIFO already exists and second UniqueId != 0
  452. //
  453. if (pAdapter->pRecvFIFOVc == NULL && pN1394Params->Destination.FifoAddress.UniqueID == 0 )
  454. {
  455. ADAPTER_ACQUIRE_LOCK (pAdapter);
  456. pAdapter->pRecvFIFOVc = (PRECVFIFO_VCCB)pVc;
  457. //
  458. // Since the adapter now has a pointer to the Vc, increment the Refcount.
  459. // This will be decremented in the CloseCall
  460. //
  461. nicReferenceVc (pVc);
  462. ADAPTER_RELEASE_LOCK (pAdapter);
  463. }
  464. else
  465. {
  466. TRACE( TL_A, TM_Cm, ( "Adapter at %x, already has a recvFIFO. Field is at %x", pAdapter, &pAdapter->pRecvFIFOVc ) );
  467. ASSERT (pAdapter->pRecvFIFOVc == NULL);
  468. NdisStatus = NDIS_STATUS_FAILURE;
  469. pVc->Hdr.VcHandlers.MakeCallHandler = NULL;
  470. pVc->Hdr.VcHandlers.CloseCallHandler = NULL;
  471. }
  472. break;
  473. }
  474. case TransmitVc:
  475. {
  476. //
  477. // Send Fifo Vcs
  478. //
  479. TRACE( TL_V, TM_Cm, ( " MakeCall - AsyncTransmitVc Vc %x", pVc ) );
  480. pVc->Hdr.VcType = NIC1394_SendFIFO;
  481. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitSendFIFOVc;
  482. pVc->Hdr.VcHandlers.SendPackets = AsyncWriteSendPacketsHandler;
  483. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendFIFO;
  484. break;
  485. }
  486. case TransmitAndReceiveVc:
  487. default:
  488. {
  489. NdisStatus = NDIS_STATUS_FAILURE;
  490. }
  491. }
  492. return NdisStatus;
  493. }
  494. NDIS_STATUS
  495. nicCmGenericMakeCallMutilChannel (
  496. IN PVCCB pVc,
  497. VC_SEND_RECEIVE VcType
  498. )
  499. /*++
  500. Routine Description:
  501. Init the handlers
  502. Arguments:
  503. Return Value:
  504. --*/
  505. {
  506. TRACE( TL_A, TM_Cm, ( "Make Call Recvd for MultiChannel %x ", pVc) );
  507. pVc->Hdr.VcType = NIC1394_MultiChannel;
  508. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallMultiChannel ;
  509. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallMultiChannel ;
  510. pVc->Hdr.VcHandlers.SendPackets = AsyncStreamSendPacketsHandler;
  511. return NDIS_STATUS_SUCCESS;
  512. }
  513. NDIS_STATUS
  514. nicCmGenericMakeCallEthernet(
  515. IN PVCCB pVc,
  516. IN VC_SEND_RECEIVE VcType
  517. )
  518. /*++
  519. Routine Description:
  520. Init the handlers
  521. Arguments:
  522. Return Value:
  523. --*/
  524. {
  525. TRACE( TL_A, TM_Cm, ( "Make Call Recvd for Ethernet %x ", pVc) );
  526. pVc->Hdr.VcType = NIC1394_Ethernet;
  527. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitEthernet;
  528. pVc->Hdr.VcHandlers.SendPackets = nicEthernetVcSend;
  529. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallEthernet ;
  530. return NDIS_STATUS_SUCCESS;
  531. }
  532. NDIS_STATUS
  533. nicCmGenericMakeCallInit (
  534. IN PVCCB pVc
  535. )
  536. // Function Description:
  537. //
  538. // This initializes the VcType and Copied the Media Parameters over
  539. // Initialized VCType to SendChannel, RecvChannel, SendAndRecvChanne,
  540. // SendFifo,
  541. //
  542. // Arguments
  543. // Vc - Vc that needs to be initalized
  544. //
  545. // Return Value:
  546. // Success - as no memory allocation takes place
  547. // This function should not do anything that can fail.
  548. {
  549. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
  550. VC_SEND_RECEIVE VcType = InvalidType;
  551. PCO_MEDIA_PARAMETERS pMediaParams = pVc->Hdr.pCallParameters->MediaParameters;
  552. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS) pMediaParams->MediaSpecific.Parameters;
  553. TRACE( TL_T, TM_Cm, ( "==>nicCmGenericMakeCallInit pVc %x", pVc ) );
  554. pVc->Hdr.Nic1394MediaParams = *pN1394Params;
  555. ASSERT(pVc->Hdr.pAF!=NULL);
  556. pVc->Hdr.pGeneration = &pVc->Hdr.pAF->pAdapter->Generation;
  557. //
  558. // Figure out if this is send or receive Vc Or both
  559. //
  560. do
  561. {
  562. if ((pMediaParams->Flags & (TRANSMIT_VC |RECEIVE_VC)) == TRANSMIT_VC)
  563. {
  564. VcType = TransmitVc;
  565. break;
  566. }
  567. if ((pMediaParams->Flags & (TRANSMIT_VC |RECEIVE_VC)) == RECEIVE_VC)
  568. {
  569. VcType = ReceiveVc;
  570. break;
  571. }
  572. if ((pMediaParams->Flags & (TRANSMIT_VC |RECEIVE_VC)) == (TRANSMIT_VC |RECEIVE_VC) )
  573. {
  574. VcType = TransmitAndReceiveVc;
  575. break;
  576. }
  577. } while (FALSE);
  578. ASSERT (VcType <= TransmitAndReceiveVc);
  579. switch (pN1394Params->Destination.AddressType)
  580. {
  581. case NIC1394AddressType_Channel:
  582. {
  583. NdisStatus = nicCmGenericMakeCallInitChannels ((PCHANNEL_VCCB)pVc, VcType);
  584. break;
  585. }
  586. case NIC1394AddressType_FIFO:
  587. {
  588. //
  589. // Now we are in FIFO land.
  590. //
  591. NdisStatus = nicCmGenericMakeCallInitFifo (pVc, VcType );
  592. break;
  593. }
  594. case NIC1394AddressType_MultiChannel:
  595. {
  596. NdisStatus = nicCmGenericMakeCallMutilChannel (pVc, VcType );
  597. break;
  598. }
  599. case NIC1394AddressType_Ethernet:
  600. {
  601. NdisStatus = nicCmGenericMakeCallEthernet(pVc, VcType );
  602. break;
  603. }
  604. default:
  605. {
  606. ASSERT (pN1394Params->Destination.AddressType<=NIC1394AddressType_Ethernet);
  607. NdisStatus = NDIS_STATUS_FAILURE;
  608. break;
  609. }
  610. }
  611. TRACE( TL_T, TM_Cm, ( "<==nicCmGenericMakeCallInit pVc %x, Status %x",pVc , NdisStatus) );
  612. return NdisStatus;
  613. }
  614. #else
  615. NDIS_STATUS
  616. nicCmGenericMakeCallInit (
  617. IN PVCCB pVc
  618. )
  619. // Function Description:
  620. //
  621. // This initializes the VcType and Copied the Media Parameters over
  622. // Initialized VCType to SendChannel, RecvChannel, SendAndRecvChanne,
  623. // SendFifo,
  624. //
  625. // Arguments
  626. // Vc - Vc that needs to be initalized
  627. //
  628. // Return Value:
  629. // Success - as no memory allocation takes place
  630. // This function should not do anything that can fail.
  631. {
  632. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
  633. PCO_MEDIA_PARAMETERS pMediaParams = pVc->Hdr.pCallParameters->MediaParameters;
  634. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS) pMediaParams->MediaSpecific.Parameters;
  635. TRACE( TL_T, TM_Cm, ( "==>nicCmGenericMakeCallInit pVc %x", pVc ) );
  636. pVc->Hdr.Nic1394MediaParams = *pN1394Params;
  637. ASSERT(pVc->Hdr.pAF!=NULL);
  638. pVc->Hdr.pGeneration = &pVc->Hdr.pAF->pAdapter->Generation;
  639. //
  640. // Unfortunately we do not have a switch statement, so we'll have to use
  641. // if statements and do it the hard way
  642. //
  643. switch (pN1394Params->Destination.AddressType)
  644. {
  645. case NIC1394AddressType_Channel:
  646. {
  647. //
  648. // Channels will be defaulted to have Send And Receive Capabilities
  649. //
  650. TRACE( TL_V, TM_Cm, ( " MakeCall- Channel Transmit and Receive Vc Vc %x", pVc ) );
  651. pVc->Hdr.VcType = NIC1394_SendRecvChannel;
  652. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitSendRecvChannelVc;
  653. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendRecvChannel;
  654. pVc->Hdr.VcHandlers.SendPackets = AsyncStreamSendPacketsHandler;
  655. break;
  656. }
  657. case NIC1394AddressType_FIFO:
  658. {
  659. //
  660. // Now we are in FIFO land.
  661. //
  662. if (pMediaParams->Flags & TRANSMIT_VC)
  663. {
  664. //
  665. // Send Fifo Vcs
  666. //
  667. PSENDFIFO_VCCB pSendFIFOVc = (PSENDFIFO_VCCB)pVc;
  668. TRACE( TL_V, TM_Cm, ( " MakeCall - AsyncTransmitVc Vc %x", pVc ) );
  669. pVc->Hdr.VcType = NIC1394_SendFIFO;
  670. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitSendFIFOVc;
  671. pVc->Hdr.VcHandlers.SendPackets = AsyncWriteSendPacketsHandler;
  672. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallSendFIFO;
  673. }
  674. else
  675. {
  676. //
  677. // Recv FifoVcs
  678. //
  679. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  680. PRECVFIFO_VCCB pRecvFIFOVc = (PRECVFIFO_VCCB) pVc;
  681. ASSERT(pMediaParams->Flags & RECEIVE_VC);
  682. TRACE( TL_V, TM_Cm, ( " MakeCall - AsyncReceiveVc Vc %x", pVc ) );
  683. pVc->Hdr.VcType = NIC1394_RecvFIFO;
  684. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitRecvFIFOVc;
  685. pVc->Hdr.VcHandlers.SendPackets = DummySendPacketsHandler;
  686. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallRecvFIFO;
  687. //
  688. // There are two reasons to fail a RecvFIFO Make call.
  689. // One, a REcvFIFO already exists and second UniqueId != 0
  690. //
  691. if (pAdapter->pRecvFIFOVc == NULL && pN1394Params->Destination.FifoAddress.UniqueID == 0 )
  692. {
  693. ADAPTER_ACQUIRE_LOCK (pAdapter);
  694. pAdapter->pRecvFIFOVc = (PRECVFIFO_VCCB)pVc;
  695. //
  696. // Since the adapter now has a pointer to the Vc, increment the Refcount.
  697. // This will be decremented in the CloseCall
  698. //
  699. nicReferenceVc (pVc);
  700. ADAPTER_RELEASE_LOCK (pAdapter);
  701. }
  702. else
  703. {
  704. TRACE( TL_A, TM_Cm, ( "Adapter at %x, already has a recvFIFO. Field is at %x", pAdapter, &pAdapter->pRecvFIFOVc ) );
  705. ASSERT (pAdapter->pRecvFIFOVc == NULL);
  706. NdisStatus = NDIS_STATUS_FAILURE;
  707. pVc->Hdr.VcHandlers.MakeCallHandler = NULL;
  708. pVc->Hdr.VcHandlers.CloseCallHandler = NULL;
  709. }
  710. }
  711. break;
  712. }
  713. case NIC1394AddressType_MultiChannel:
  714. {
  715. TRACE( TL_A, TM_Cm, ( "Make Call Recvd for MultiChannel %x ", pVc) );
  716. pVc->Hdr.VcType = NIC1394_MultiChannel;
  717. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallMultiChannel ;
  718. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallMultiChannel ;
  719. pVc->Hdr.VcHandlers.SendPackets = AsyncStreamSendPacketsHandler;
  720. break;
  721. }
  722. case NIC1394AddressType_Ethernet:
  723. {
  724. TRACE( TL_A, TM_Cm, ( "Make Call Recvd for Ethernet %x ", pVc) );
  725. pVc->Hdr.VcType = NIC1394_Ethernet;
  726. pVc->Hdr.VcHandlers.MakeCallHandler = nicCmMakeCallInitEthernet;
  727. pVc->Hdr.VcHandlers.SendPackets = nicEthernetVcSend;
  728. pVc->Hdr.VcHandlers.CloseCallHandler = nicCmCloseCallEthernet ;
  729. break;
  730. }
  731. default:
  732. {
  733. ASSERT (pN1394Params->Destination.AddressType<=NIC1394AddressType_Ethernet);
  734. NdisStatus = NDIS_STATUS_FAILURE;
  735. break;
  736. }
  737. }
  738. TRACE( TL_T, TM_Cm, ( "<==nicCmGenericMakeCallInit pVc %x, Status %x",pVc , NdisStatus) );
  739. return NdisStatus;
  740. }
  741. #endif
  742. VOID
  743. nicCmGenrericMakeCallFailure (
  744. IN PVCCB pVc
  745. )
  746. // Function Description:
  747. // Does the clean up on the VcHDr structure. Will cleanup the Destination, VcType
  748. // and Vc. Initialize Handler. Special case - Recv VC
  749. // Arguments
  750. // PVCCB : Vc on which cleanup need to be done.
  751. // Return Value:
  752. // None
  753. {
  754. TRACE( TL_T, TM_Cm, ( "==>nicGenrericMakeCallFailure pVc %x, ",pVc ) );
  755. pVc->Hdr.VcHandlers.MakeCallHandler = NULL;
  756. pVc->Hdr.VcHandlers.CloseCallHandler = NULL;
  757. //
  758. // First, we need to make sure if adapter's VC is the same as this VC,
  759. // otherwise the adapters'recv VC is Valid Vc currently in Use. Do not touch it.
  760. //
  761. if (pVc->Hdr.VcType == NIC1394_RecvFIFO &&
  762. pVc->Hdr.pAF->pAdapter->pRecvFIFOVc == (PRECVFIFO_VCCB)pVc)
  763. {
  764. //
  765. // This is the reference that was added GenericInitVc function
  766. // and only applied to Recv VC's
  767. //
  768. VC_ACQUIRE_LOCK (pVc);
  769. nicDereferenceVc (pVc);
  770. VC_RELEASE_LOCK (pVc);
  771. }
  772. pVc->Hdr.VcType = NIC1394_Invalid_Type;
  773. NdisZeroMemory (&pVc->Hdr.Nic1394MediaParams ,
  774. sizeof (pVc->Hdr.Nic1394MediaParams) );
  775. VC_ACQUIRE_LOCK(pVc)
  776. nicCloseCallRef (pVc);
  777. //
  778. // Mark the Vc Flags, with a MakeCall Failed
  779. //
  780. VC_CLEAR_FLAGS(pVc ,VCBF_MakeCallPending);
  781. VC_SET_FLAG (pVc, VCBF_MakeCallFailed);
  782. VC_RELEASE_LOCK (pVc);
  783. TRACE( TL_T, TM_Cm, ( "<==nicGenrericMakeCallFailure pVc %x, ",pVc ) );
  784. }
  785. VOID
  786. nicCmMakeCallComplete (
  787. NDIS_WORK_ITEM* pMakeCallCompleteWorkItem,
  788. IN PVOID Context
  789. )
  790. // Function:
  791. // This function is used to complete a Make Call. This can be done synchronously
  792. // or asynchronous. If a status pending was passed to this function, it will complete using
  793. // the asynchronous route
  794. //
  795. // If everytrhing succeeds, one Ref to the Vc will be passed through and that will be decremented
  796. // when the call is closed
  797. // This function should never return NDIS_STATUS_PENDING. Will be called as a WorkItem
  798. {
  799. PVCCB pVc = (PVCCB)Context;
  800. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  801. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  802. STORE_CURRENT_IRQL;
  803. TRACE( TL_T, TM_Cm, ( "==>NicCmMakeCallComplete ,pVc %x",pVc ) );
  804. //
  805. // Reference the Vc as we want the Vc structure to stay alive till
  806. // the end of the make call complete
  807. //
  808. nicReferenceVc (pVc);
  809. //
  810. // Call the Initialize handler for the VC so that it can be initialized
  811. //
  812. ASSERT (pVc->Hdr.VcHandlers.MakeCallHandler != NULL);
  813. NdisStatus = (*pVc->Hdr.VcHandlers.MakeCallHandler) (pVc);
  814. MATCH_IRQL;
  815. if (NdisStatus == NDIS_STATUS_SUCCESS)
  816. {
  817. VC_ACQUIRE_LOCK(pVc);
  818. //
  819. // Now mark the Vc as active
  820. //
  821. VC_SET_FLAG( pVc, VCBF_VcActivated);
  822. VC_CLEAR_FLAGS(pVc ,VCBF_MakeCallPending);
  823. VC_RELEASE_LOCK (pVc);
  824. }
  825. else
  826. {
  827. //
  828. // call the clean up routine to bring the Vc back to its old state
  829. //
  830. nicCmMakeCallCompleteFailureCleanUp (pVc);
  831. //
  832. // Dereference the call that we are about to fail. This reference was made in
  833. // the beginning of make call routine. when the callref ==0, the Vc will be
  834. // dereferenced as well
  835. //
  836. VC_ACQUIRE_LOCK (pVc);
  837. VC_SET_FLAG (pVc, VCBF_MakeCallFailed);
  838. VC_CLEAR_FLAGS(pVc ,VCBF_MakeCallPending);
  839. nicDereferenceCall (pVc, "nicCmMakeCallComplete");
  840. VC_RELEASE_LOCK (pVc);
  841. }
  842. MATCH_IRQL;
  843. //
  844. // Complete the call with the correct status
  845. //
  846. TRACE( TL_N, TM_Cm, ( "Completing the Make Call , Vc %x, Status %x", pVc, NdisStatus ) );
  847. NdisCmMakeCallComplete(NdisStatus,
  848. pVc->Hdr.NdisVcHandle,
  849. NULL,
  850. NULL,
  851. pVc->Hdr.pCallParameters );
  852. TRACE( TL_I, TM_Cm, ( "Called NdisCmMakeCallComplete, Vc %x, Status%x", pVc, NdisStatus ) );
  853. #if 0
  854. {
  855. if (pVc->Hdr.VcType == NIC1394_MultiChannel)
  856. {
  857. NIC1394_CHANNEL_CHARACTERISTICS McChar;
  858. McChar.ChannelMap.QuadPart = 0x80000000; // Must be zero unless specifying a Multi-channel VC.
  859. McChar.Speed = SCODE_400_RATE ; // Same units as NIC1394_MEDIA_PARAMETERS.MaxSendSpeed.
  860. nicChangeChannelChar (pVc, &McChar);
  861. }
  862. }
  863. #endif
  864. TRACE( TL_T, TM_Cm, ( "<==NicCmMakeCallComplete, Vc %x, Status%x", pVc, NdisStatus ) );
  865. FREE_NONPAGED (pMakeCallCompleteWorkItem);
  866. NdisInterlockedDecrement(&pAdapter->OutstandingWorkItems);
  867. //
  868. // This will cause the Vc Refcount to go to zero if the Make Call fails
  869. //
  870. nicDereferenceVc (pVc);
  871. MATCH_IRQL;
  872. }
  873. NDIS_STATUS
  874. nicCmMakeCallInitRecvFIFOVc(
  875. IN OUT PVCCB pVc
  876. )
  877. // Function Description:
  878. //
  879. // This function allocates, packet pool, populates the Slist
  880. // allocates the address range and
  881. // inserts the Vc into the Adapter->pRecvFifoVc field
  882. //
  883. // Will succeed the call, if this process was successful on 1 remote node
  884. // Arguments
  885. // PVCCB : pVc that the call is made on
  886. //
  887. //
  888. // Return Value:
  889. // Success: If all allocations succeeded for just 1 remote node
  890. {
  891. PRECVFIFO_VCCB pRecvFIFOVc = (PRECVFIFO_VCCB) pVc;
  892. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
  893. REMOTE_NODE *pRemoteNode = NULL;
  894. PADAPTERCB pAdapter = pRecvFIFOVc->Hdr.pAF->pAdapter;
  895. PNIC1394_MEDIA_PARAMETERS pN1394Params = &pVc->Hdr.Nic1394MediaParams;
  896. UINT64 UniqueId = pN1394Params->Destination.FifoAddress.UniqueID;
  897. PLIST_ENTRY pPdoListEntry = NULL;
  898. BOOLEAN fWaitSuccessful = FALSE;
  899. BOOLEAN fInitRecvFifoDataStructures = FALSE;
  900. BOOLEAN fNeedToWait = FALSE;
  901. PNIC1394_FIFO_ADDRESS pFifoAddress = NULL;
  902. STORE_CURRENT_IRQL;
  903. TRACE( TL_T, TM_Cm, ( "==>nicCmMakeCallInitRecvFIFOVc pRecvFIFOVc %x ", pRecvFIFOVc) );
  904. ASSERT (pAdapter != NULL);
  905. ASSERT (KeGetCurrentIrql()==PASSIVE_LEVEL);
  906. pFifoAddress = &pN1394Params->Destination.FifoAddress;
  907. UniqueId = pFifoAddress->UniqueID;
  908. do
  909. {
  910. NdisStatus = nicInitRecvFifoDataStructures (pRecvFIFOVc);
  911. if (NdisStatus != NDIS_STATUS_SUCCESS)
  912. {
  913. TRACE( TL_A, TM_Cm, ( " nicInitRecvFifoDataStructures FAILED pRecvFIFOVc is %x, UniqueId %I64x ", pRecvFIFOVc) );
  914. break;
  915. }
  916. fInitRecvFifoDataStructures = TRUE;
  917. // ADAPTER_ACQUIRE_LOCK (pAdapter);
  918. //
  919. // This field is not used by a RecvFIFO because it has multiple Pdos
  920. //
  921. pRecvFIFOVc->Hdr.pRemoteNode = NULL;
  922. NdisStatus = nicAllocateAddressRange(pAdapter, pRecvFIFOVc);
  923. if(NdisStatus != NDIS_STATUS_SUCCESS)
  924. {
  925. TRACE( TL_A, TM_Cm, ( "Unable to get Pdo and allocate addresses, call FAILED ,pRecvFIFOVc is %x", pRecvFIFOVc) );
  926. ASSERT(NdisStatus == NDIS_STATUS_SUCCESS);
  927. break;
  928. }
  929. ASSERT(pRecvFIFOVc->PacketPool.Handle != NULL);
  930. ASSERT(pRecvFIFOVc->Hdr.MTU != 0);
  931. } while (FALSE);
  932. if (NdisStatus != NDIS_STATUS_SUCCESS)
  933. {
  934. //
  935. // Undo all allocated memory
  936. //
  937. TRACE( TL_A, TM_Cm, ( "Failing the Make Call for Vc %x" , pVc) );
  938. if (fInitRecvFifoDataStructures == TRUE)
  939. {
  940. nicUnInitRecvFifoDataStructures (pRecvFIFOVc);
  941. }
  942. }
  943. TRACE( TL_I, TM_Cm, ( "pVc's Offset High %4x",pVc->Hdr.Nic1394MediaParams.Destination.FifoAddress.Off_High ) );
  944. TRACE( TL_I, TM_Cm, ( "pVc's Offset Low %x",pVc->Hdr.Nic1394MediaParams.Destination.FifoAddress.Off_Low ) );
  945. TRACE( TL_T, TM_Cm, ( "<==nicCmMakeCallInitRecvFIFOVc %x",NdisStatus ) );
  946. MATCH_IRQL;
  947. return NdisStatus;
  948. }
  949. NDIS_STATUS
  950. nicCmMakeCallInitSendFIFOVc(
  951. IN OUT PVCCB pVc
  952. )
  953. /*++
  954. Routine Description:
  955. This initializes a Send Fifo Make Call.
  956. It
  957. i) finds the remote node using the make call parameters
  958. ii) inititalizes strcutures
  959. Arguments:
  960. pVc - Vc that the make call is done on.
  961. Return Value:
  962. --*/
  963. //
  964. {
  965. PSENDFIFO_VCCB pSendFIFOVc = (PSENDFIFO_VCCB) pVc;
  966. NDIS_STATUS NdisStatus = NDIS_STATUS_SUCCESS;
  967. UINT Generation = 0;
  968. PREMOTE_NODE pRemoteNode = NULL;
  969. PADAPTERCB pAdapter = pSendFIFOVc->Hdr.pAF->pAdapter;
  970. PNIC1394_MEDIA_PARAMETERS pN1394Params = NULL;
  971. UINT64 UniqueId = 0;
  972. PNIC1394_FIFO_ADDRESS pFifoAddress = NULL;
  973. ULONG Speed;
  974. ULONG MaxBufferSize;
  975. ULONG RemoteMaxRec;
  976. BOOLEAN fDeRefRemoteNode = FALSE;
  977. STORE_CURRENT_IRQL;
  978. TRACE( TL_T, TM_Cm, ( "==>NicCmMakeCallInitSendFIFOVc pSendFIFOVc %x", pSendFIFOVc ) );
  979. pN1394Params = (PNIC1394_MEDIA_PARAMETERS)&pVc->Hdr.pCallParameters->MediaParameters->MediaSpecific.Parameters[0];
  980. ASSERT (pN1394Params->Destination.AddressType == NIC1394AddressType_FIFO);
  981. pFifoAddress = &pN1394Params->Destination.FifoAddress;
  982. UniqueId = pFifoAddress->UniqueID;
  983. TRACE( TL_V, TM_Cm, ( "FifoAddress %x, UniqueId %I64x, Hi %.4x, Lo %x",
  984. pFifoAddress, pFifoAddress->UniqueID,
  985. pFifoAddress->Off_High, pFifoAddress->Off_Low ) );
  986. do
  987. {
  988. //
  989. // Get the Pdo that corresponds with the UniqueId
  990. //
  991. ASSERT(pSendFIFOVc->Hdr.pAF->pAdapter != NULL);
  992. NdisStatus = nicFindRemoteNodeFromAdapter( pSendFIFOVc->Hdr.pAF->pAdapter,
  993. NULL,
  994. UniqueId,
  995. &pRemoteNode);
  996. if(NdisStatus != NDIS_STATUS_SUCCESS)
  997. {
  998. TRACE( TL_A, TM_Cm, ( "Unable to Find Pdo, call FAILED ,pSendFIFOVc is %x, UniqueId %I64x ", pSendFIFOVc, UniqueId ) );
  999. break;
  1000. }
  1001. ASSERT (pRemoteNode != NULL);
  1002. //
  1003. // nicFindRemoteNodeFromAdapter ref's pRemoteNode on success.
  1004. // We need to deref it if we're not going to be using it.
  1005. // Let's start by assuming we aren't.
  1006. //
  1007. fDeRefRemoteNode = TRUE;
  1008. //
  1009. // Get the Generation Count of the device
  1010. //
  1011. NdisStatus = nicGetGenerationCount ( pRemoteNode->pAdapter, &Generation);
  1012. if(NdisStatus != NDIS_STATUS_SUCCESS)
  1013. {
  1014. TRACE( TL_A, TM_Cm, ( "GET GENERATION FAILED ,pSendFIFOVc is %x", pSendFIFOVc ) );
  1015. ASSERT(NdisStatus == NDIS_STATUS_SUCCESS);
  1016. break;
  1017. }
  1018. TRACE( TL_V, TM_Cm, ( "Found PdoCb %x for pSendFIFOVc %x", pRemoteNode,pSendFIFOVc ) );
  1019. //
  1020. // We check if the remote node's pdo is active. if so, then insert the Vc into the
  1021. // PdoCb's list. Now responsibility for any removals has moved to the remove remote node code path
  1022. //
  1023. //
  1024. // Get the max buffer size that can be transmitted on this link
  1025. //
  1026. NdisStatus = nicQueryRemoteNodeCaps (pAdapter,
  1027. pRemoteNode,
  1028. // FALSE, // FALSE== not from cache.
  1029. &Speed,
  1030. &MaxBufferSize,
  1031. &RemoteMaxRec);
  1032. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1033. {
  1034. break;
  1035. }
  1036. ADAPTER_ACQUIRE_LOCK (pAdapter);
  1037. if (REMOTE_NODE_ACTIVE (pRemoteNode) == FALSE)
  1038. {
  1039. NdisStatus = NDIS_STATUS_DEST_OUT_OF_ORDER;
  1040. ADAPTER_RELEASE_LOCK (pAdapter);
  1041. break;
  1042. }
  1043. //
  1044. // Reference the call in the Vc as the RemoteNodePdo is about to have a pointer to it., This is dereferenced
  1045. // in the CloseCallComplete Send Fifo Function. we have the lock
  1046. //
  1047. nicReferenceCall (pVc, "nicCmMakeCallInitSendFIFOVc");
  1048. //
  1049. // We keep the reference to pRemoteNode that was added by FindRemoteNode.
  1050. // Derefed in SendFifoCloseCall when the pointer is nulled
  1051. //
  1052. fDeRefRemoteNode = FALSE;
  1053. //
  1054. // Insert the Vc into the Pdo's List
  1055. //
  1056. InsertTailList (&pRemoteNode->VcList, &pSendFIFOVc->Hdr.SinglePdoVcLink);
  1057. TRACE( TL_V, TM_Cm, ( "Inserted Vc %x into Pdo List %x ", pSendFIFOVc, pRemoteNode) );
  1058. //
  1059. // This is not protected by the lock, but we are gauranteed that the Call will not be closed
  1060. // and the Pdo will not be be removed from the system at this point, So we can update
  1061. // this field.
  1062. //
  1063. pSendFIFOVc->Hdr.pRemoteNode = pRemoteNode;
  1064. ADAPTER_RELEASE_LOCK (pAdapter);
  1065. //
  1066. // Acquire the spin lock and initialize the structures
  1067. //
  1068. VC_ACQUIRE_LOCK (pSendFIFOVc);
  1069. pSendFIFOVc->Hdr.MTU = pN1394Params->MTU;
  1070. pSendFIFOVc->Hdr.pGeneration = &pAdapter->Generation;
  1071. pSendFIFOVc->FifoAddress = pN1394Params->Destination.FifoAddress;
  1072. pSendFIFOVc->MaxSendSpeed = pN1394Params->MaxSendSpeed;
  1073. pSendFIFOVc->Hdr.MaxPayload = min (pN1394Params->MTU, (ULONG)pN1394Params->MaxSendBlockSize);
  1074. VC_RELEASE_LOCK (pSendFIFOVc);
  1075. //
  1076. // Validate the parameters for the Vc
  1077. //
  1078. ASSERT(pSendFIFOVc->Hdr.pRemoteNode != NULL);
  1079. ASSERT(pSendFIFOVc->Hdr.pRemoteNode->pPdo != NULL);
  1080. ASSERT(pSendFIFOVc->Hdr.pGeneration != NULL);
  1081. ASSERT(pSendFIFOVc->MaxSendSpeed != 0);
  1082. ASSERT(pSendFIFOVc->Hdr.MTU != 0);
  1083. TRACE( TL_V, TM_Cm, ( " Generation is %x", *pSendFIFOVc->Hdr.pGeneration ) );
  1084. TRACE( TL_N, TM_Cm, ( " Pdo in the Send VC is %x", pSendFIFOVc->Hdr.pRemoteNode->pPdo) );
  1085. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1086. {
  1087. break;
  1088. }
  1089. pSendFIFOVc->MaxSendSpeed = min(pSendFIFOVc->MaxSendSpeed,Speed);
  1090. pSendFIFOVc->Hdr.MaxPayload = min (pSendFIFOVc->Hdr.MaxPayload, MaxBufferSize);
  1091. #ifdef LOWER_SEND_SPEED
  1092. pSendFIFOVc->MaxSendSpeed = SCODE_200_RATE;//min(pSendFIFOVc->MaxSendSpeed,Speed);
  1093. pSendFIFOVc->Hdr.MaxPayload = ASYNC_PAYLOAD_200_RATE ;// min(pSendFIFOVc->Hdr.MaxPayload, MaxBufferSize);
  1094. #endif
  1095. TRACE( TL_V, TM_Cm, ( " MaxSendSpeed is %x", pSendFIFOVc->MaxSendSpeed) );
  1096. TRACE( TL_V, TM_Cm, ( " MaxPayload is %d", pSendFIFOVc->Hdr.MaxPayload ) );
  1097. } while (FALSE);
  1098. if ( NdisStatus != NDIS_STATUS_SUCCESS)
  1099. {
  1100. //
  1101. // The Make is going to be failed asynchrnously
  1102. // If we allocated in resources, we must free them
  1103. // In this case, there have been no Resources allocated
  1104. //
  1105. }
  1106. TRACE( TL_I, TM_Cm, ( " pVc's Offset High %4x",pVc->Hdr.Nic1394MediaParams.Destination.FifoAddress.Off_High ) );
  1107. TRACE( TL_I, TM_Cm, ( " pVc's Offset Low %x",pVc->Hdr.Nic1394MediaParams.Destination.FifoAddress.Off_Low ) );
  1108. TRACE( TL_T, TM_Cm, ( "<==NicCmMakeCallInitSendFIFOVc %x",NdisStatus ) );
  1109. if (fDeRefRemoteNode)
  1110. {
  1111. nicDereferenceRemoteNode (pRemoteNode, "NicCmMakeCallInitSendFIFOVc");
  1112. }
  1113. MATCH_IRQL;
  1114. return NdisStatus;
  1115. }
  1116. NDIS_STATUS
  1117. nicCmMakeCallInitSendRecvChannelVc(
  1118. IN OUT PVCCB pVc
  1119. )
  1120. // Function Description:
  1121. //
  1122. // Arguments
  1123. // pVc, This is the send fifo that needs to be initilaized
  1124. //
  1125. //
  1126. // Return Value:
  1127. //
  1128. // Success if the irps sent to the driver succeed
  1129. //
  1130. //
  1131. {
  1132. PCHANNEL_VCCB pChannelVc = (PCHANNEL_VCCB)pVc;
  1133. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1134. PNIC1394_MEDIA_PARAMETERS pN1394Params = NULL;
  1135. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1136. ULONG Channel = 64;
  1137. HANDLE hResource=NULL;
  1138. ULONG MaxBufferSize = 0;
  1139. ULONG QuadletsToStrip = 0;
  1140. PISOCH_DESCRIPTOR pIsochDescriptor = NULL;
  1141. CYCLE_TIME CycleTime;
  1142. PDEVICE_OBJECT ArrayRemotePDO[64];
  1143. //NDIS_HANDLE hPacketPoolHandle=NULL;
  1144. BOOLEAN fAnyChannel = FALSE;
  1145. NIC_PACKET_POOL PacketPool;
  1146. STORE_CURRENT_IRQL;
  1147. TRACE( TL_T, TM_Cm, ( "==>NicCmMakeCallInitSendRecvChannelVc pVc %x", pVc ) );
  1148. ASSERT (pAdapter != NULL);
  1149. pN1394Params = (PNIC1394_MEDIA_PARAMETERS)&pVc->Hdr.pCallParameters->MediaParameters->MediaSpecific.Parameters[0];
  1150. Channel = pN1394Params->Destination.Channel;
  1151. TRACE( TL_V, TM_Cm, ( "Channel %x", Channel ) );
  1152. do
  1153. {
  1154. PacketPool.Handle = NULL;
  1155. ADAPTER_ACQUIRE_LOCK( pAdapter );
  1156. //
  1157. // This is to reference the call so that it will be around until the end of this function
  1158. //
  1159. nicReferenceCall ( (PVCCB)pChannelVc, "nicCmMakeCallInitSendRecvChannelVc");
  1160. //
  1161. // Set up the the VDO, so that all channel operations can use it
  1162. //
  1163. pVc->Hdr.pLocalHostVDO = pAdapter->pNdisDeviceObject;
  1164. ADAPTER_RELEASE_LOCK( pAdapter );
  1165. NdisAllocatePacketPoolEx ( &NdisStatus,
  1166. &PacketPool.Handle,
  1167. MIN_PACKET_POOL_SIZE,
  1168. MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
  1169. sizeof (RSVD) );
  1170. if (PacketPool.Handle == NULL || NdisStatus != NDIS_STATUS_SUCCESS)
  1171. {
  1172. BREAK (TM_Cm, ( "NdisAllocatePacketPoolEx FAILED" ) );
  1173. }
  1174. //
  1175. // Reference Call for Packet Pool Handle
  1176. //
  1177. nicReferenceCall ((PVCCB)pChannelVc, "nicCmMakeCallInitSendRecvChannelVc - packet pool ");
  1178. PacketPool.AllocatedPackets = 0;
  1179. pChannelVc->Hdr.MTU = pN1394Params->MTU;
  1180. pChannelVc->PacketPool= PacketPool;
  1181. KeInitializeSpinLock (&pChannelVc->PacketPool.Lock);
  1182. NdisInitializeEvent(&pChannelVc->LastDescReturned);
  1183. //
  1184. // This function should do its own cleanup
  1185. //
  1186. NdisStatus = nicAllocateChannelResourcesAndListen (pAdapter,
  1187. pChannelVc );
  1188. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1189. {
  1190. BREAK (TM_Cm, ( "nicAllocateChannelResourcesAndListen FAILED" ) );
  1191. }
  1192. //
  1193. // Return the allocated channel number, if this is an any channel
  1194. // or broadcast channel call
  1195. //
  1196. if ((pN1394Params->Destination.Channel == NIC1394_ANY_CHANNEL) &&
  1197. (pN1394Params->Destination.AddressType == NIC1394AddressType_Channel))
  1198. {
  1199. pN1394Params->Destination.Channel = pChannelVc->Channel;
  1200. }
  1201. //
  1202. // Make the same change for broadcast channels
  1203. //
  1204. if ((pN1394Params->Destination.Channel == NIC1394_BROADCAST_CHANNEL) &&
  1205. (pN1394Params->Destination.AddressType == NIC1394AddressType_Channel))
  1206. {
  1207. pN1394Params->Destination.Channel = pChannelVc->Channel;
  1208. }
  1209. } while (FALSE);
  1210. //
  1211. // Time to do clean up based on what resources were allocated
  1212. //
  1213. if (NdisStatus != NDIS_STATUS_SUCCESS )
  1214. {
  1215. //Undo all resources acquired
  1216. if (PacketPool.Handle != NULL)
  1217. {
  1218. //
  1219. // Free the pool
  1220. //
  1221. nicFreePacketPool(&PacketPool);
  1222. nicDereferenceCall ((PVCCB)pChannelVc, "nicCmMakeCallInitSendRecvChannelVc - packet pool ");
  1223. NdisZeroMemory (&pChannelVc->PacketPool, sizeof (pChannelVc->PacketPool));
  1224. }
  1225. #if 0
  1226. nicChannelCallFreeResources ( pChannelVc,
  1227. pAdapter,
  1228. NULL, //hResource,
  1229. 0, //NumDescriptors,
  1230. NULL, //pIsochDescriptor,
  1231. (BOOLEAN)VC_TEST_FLAGS( pChannelVc, VCBF_AllocatedChannel),
  1232. Channel,
  1233. &PacketPool);
  1234. #endif
  1235. //
  1236. // Do not decrement any ref counts because if Status != success
  1237. // then we have not incremented refcounts.
  1238. //
  1239. }
  1240. //
  1241. // This dereference was added in the beginning of the function
  1242. //
  1243. nicDereferenceCall ((PVCCB) pChannelVc, "NicCmMakeCallInitSendRecvChannelVc ");
  1244. TRACE( TL_T, TM_Cm, ( "<==NicCmMakeCallInitSendRecvChannelVc %x", NdisStatus) );
  1245. return NdisStatus;
  1246. }
  1247. NDIS_STATUS
  1248. nicCmMakeCallInitEthernet (
  1249. IN PVCCB pVc
  1250. )
  1251. /*++
  1252. Routine Description:
  1253. Do nothing for now. Just succeed
  1254. Arguments:
  1255. Return Value:
  1256. --*/
  1257. {
  1258. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1259. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1260. PETHERNET_VCCB pEthernetVc = (PETHERNET_VCCB)pVc;
  1261. NIC_PACKET_POOL PacketPool;
  1262. TRACE( TL_T, TM_Cm, ( "==>nicCmMakeCallInitEthernet %x", pVc) );
  1263. do
  1264. {
  1265. PacketPool.Handle = NULL;
  1266. //
  1267. // Initialize the PacketPool
  1268. //
  1269. NdisAllocatePacketPoolEx ( &NdisStatus,
  1270. &PacketPool.Handle,
  1271. MIN_PACKET_POOL_SIZE,
  1272. MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
  1273. sizeof (RSVD) );
  1274. if (NdisStatus!= NDIS_STATUS_SUCCESS)
  1275. {
  1276. ASSERT(NdisStatus != NDIS_STATUS_SUCCESS);
  1277. pEthernetVc->PacketPool.Handle = NULL;
  1278. PacketPool.Handle = NULL;
  1279. break;
  1280. }
  1281. NdisStatus = NDIS_STATUS_SUCCESS;
  1282. //
  1283. // No more failures
  1284. //
  1285. nicReferenceCall ((PVCCB)pEthernetVc, "Alloc PacketPool - Ethernet VC " ) ;
  1286. ADAPTER_ACQUIRE_LOCK (pAdapter);
  1287. //
  1288. // Reference the VC as the adapter has a pointer to it
  1289. //
  1290. nicReferenceCall (pVc, "nicCmMakeCallEthernet ");
  1291. pAdapter->pEthernetVc = (PETHERNET_VCCB)pVc;
  1292. pEthernetVc->PacketPool= PacketPool;
  1293. pEthernetVc->PacketPool.AllocatedPackets = 0;
  1294. KeInitializeSpinLock (&pEthernetVc->PacketPool.Lock);
  1295. ADAPTER_RELEASE_LOCK (pAdapter);
  1296. } while (FALSE);
  1297. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1298. {
  1299. if (PacketPool.Handle != NULL)
  1300. {
  1301. //
  1302. // Free the pool
  1303. //
  1304. nicFreePacketPool(&PacketPool);
  1305. }
  1306. }
  1307. TRACE( TL_T, TM_Cm, ( "<==nicCmMakeCallEthernet %x", NdisStatus) );
  1308. return NdisStatus;
  1309. }
  1310. NDIS_STATUS
  1311. nicCmMakeCallMultiChannel (
  1312. IN PVCCB pVc
  1313. )
  1314. /*++
  1315. Routine Description:
  1316. Do whatever the channel Vc does
  1317. Arguments:
  1318. Return Value:
  1319. --*/
  1320. {
  1321. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1322. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1323. PCHANNEL_VCCB pMcVc = (PCHANNEL_VCCB)pVc;
  1324. NIC_PACKET_POOL PacketPool;
  1325. TRACE( TL_T, TM_Cm, ( "==>nicCmMakeCallMultiChannel %x", pVc) );
  1326. do
  1327. {
  1328. PacketPool.Handle = NULL;
  1329. //
  1330. // Initialize the PacketPool
  1331. //
  1332. NdisAllocatePacketPoolEx ( &NdisStatus,
  1333. &PacketPool.Handle,
  1334. MIN_PACKET_POOL_SIZE,
  1335. MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
  1336. sizeof (RSVD) );
  1337. if (NdisStatus!= NDIS_STATUS_SUCCESS)
  1338. {
  1339. ASSERT(NdisStatus != NDIS_STATUS_SUCCESS);
  1340. pMcVc->PacketPool.Handle = NULL;
  1341. break;
  1342. }
  1343. NdisStatus = NDIS_STATUS_SUCCESS;
  1344. //
  1345. // No more failures
  1346. //
  1347. nicReferenceCall ((PVCCB)pMcVc, "Alloc PacketPool - MultiChannel VC " ) ;
  1348. ADAPTER_ACQUIRE_LOCK (pAdapter);
  1349. pMcVc->PacketPool= PacketPool;
  1350. pMcVc->PacketPool.AllocatedPackets = 0;
  1351. KeInitializeSpinLock (&pMcVc->PacketPool.Lock);
  1352. pMcVc->Hdr.MTU = pMcVc->Hdr.Nic1394MediaParams.MTU;
  1353. ADAPTER_RELEASE_LOCK (pAdapter);
  1354. if (pMcVc->Hdr.Nic1394MediaParams.Destination.ChannnelMap.QuadPart == 0)
  1355. {
  1356. pMcVc->Channel = 0xff;
  1357. NdisStatus = NDIS_STATUS_SUCCESS;
  1358. break;
  1359. }
  1360. //
  1361. // This portion Not Implemented yet. ChannelMap != 0
  1362. // Should use nicAllocateResourcesAndListen after updating the
  1363. // Nic1394MediaParams to make it look like a regular ChannelMake Call
  1364. //
  1365. NdisStatus = NDIS_STATUS_FAILURE;
  1366. ASSERT (0);
  1367. } while (FALSE);
  1368. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1369. {
  1370. if (PacketPool.Handle != NULL)
  1371. {
  1372. //
  1373. // Free the pool
  1374. //
  1375. nicFreePacketPool(&PacketPool);
  1376. }
  1377. }
  1378. TRACE( TL_T, TM_Cm, ( "<==nicCmMakeCallMultiChannel %x", NdisStatus) );
  1379. return NdisStatus;
  1380. }
  1381. NDIS_STATUS
  1382. nicCmMakeCallSendChannel (
  1383. IN PVCCB pVc
  1384. )
  1385. /*++
  1386. Routine Description:
  1387. This function allocates the channel but does nothing else.
  1388. It is only used to send data and therefore needs no other data
  1389. It needs to update pChannelVc->Channel; ulSynch; Speed;
  1390. all of which are needed to do an AsyncStream Irb
  1391. Arguments:
  1392. Return Value:
  1393. --*/
  1394. {
  1395. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1396. PCHANNEL_VCCB pChannelVc = (PCHANNEL_VCCB)pVc;
  1397. BOOLEAN fNeedToAllocate = VC_TEST_FLAG (pChannelVc, VCBF_NeedsToAllocateChannel);
  1398. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1399. ULONG Speed = 0;
  1400. UINT MaxPacketSize = 0;
  1401. PNIC1394_MEDIA_PARAMETERS pN1394Params = (PNIC1394_MEDIA_PARAMETERS)&pChannelVc->Hdr.Nic1394MediaParams;
  1402. ULONG Channel = pN1394Params->Destination.Channel;
  1403. TRACE( TL_T, TM_Cm, ( "==>nicCmMakeCallSendChannel pVc %x", pVc) );
  1404. do
  1405. {
  1406. //
  1407. // Allocate the channel
  1408. //
  1409. if (fNeedToAllocate == TRUE)
  1410. {
  1411. NdisStatus = nicAllocateRequestedChannelMakeCallComplete (pAdapter,
  1412. pChannelVc,
  1413. &Channel);
  1414. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1415. {
  1416. BREAK (TM_Cm, ("Unable to allocate Channel on Send Only Vc" ) );
  1417. }
  1418. }
  1419. //
  1420. // Find out the Speed.
  1421. //
  1422. if (pAdapter->Speed == 0)
  1423. {
  1424. nicUpdateLocalHostSpeed (pAdapter);
  1425. }
  1426. pChannelVc->Speed = pAdapter->Speed;
  1427. Speed = pAdapter->Speed;
  1428. switch (pChannelVc->Speed)
  1429. {
  1430. case SPEED_FLAGS_100 :
  1431. {
  1432. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_100_RATE;
  1433. break;
  1434. }
  1435. case SPEED_FLAGS_200 :
  1436. {
  1437. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_200_RATE ;
  1438. break;
  1439. }
  1440. case SPEED_FLAGS_400 :
  1441. {
  1442. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  1443. break;
  1444. }
  1445. case SPEED_FLAGS_800:
  1446. {
  1447. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  1448. break;
  1449. }
  1450. case SPEED_FLAGS_1600:
  1451. {
  1452. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  1453. break;
  1454. }
  1455. case SPEED_FLAGS_3200 :
  1456. {
  1457. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  1458. break;
  1459. }
  1460. default :
  1461. {
  1462. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  1463. break;
  1464. }
  1465. }
  1466. pChannelVc->Channel = Channel ;
  1467. MaxPacketSize = min(pN1394Params->MTU + sizeof(GASP_HEADER) , pChannelVc->Hdr.MaxPayload);
  1468. //
  1469. // If broadcast channel, then decrease the speed setting, and fragment
  1470. //
  1471. pChannelVc->Channel = Channel;
  1472. pChannelVc->MaxBufferSize = 0;
  1473. pChannelVc->Speed = Speed;
  1474. pChannelVc->Hdr.MaxPayload = MaxPacketSize;
  1475. pChannelVc->Hdr.MTU = pN1394Params->MTU ;
  1476. pChannelVc->NumDescriptors = 0;
  1477. pChannelVc->pIsochDescriptor = NULL;
  1478. NdisStatus = NDIS_STATUS_SUCCESS;
  1479. } while (FALSE);
  1480. TRACE( TL_T, TM_Cm, ( "<==nicCmMakeCallSendChannel %x", NdisStatus) );
  1481. return NdisStatus;
  1482. }
  1483. VOID
  1484. nicCmMakeCallCompleteFailureCleanUp(
  1485. IN OUT PVCCB pVc
  1486. )
  1487. // Function Description:
  1488. // This function cleans up, if the makecallcomplete fails for whatever reason.
  1489. // Maybe this should be split up as well
  1490. // In the RecvFIFOVc case: it needs to deallocate the Slist and PacketPool,
  1491. // Common:
  1492. // Also delete the VcType and nic1394 destination in the Vc Hdr
  1493. // Arguments
  1494. // PVCCB pVc - Vc that needs to be cleaned up
  1495. //
  1496. // Return Value:
  1497. //
  1498. //
  1499. {
  1500. STORE_CURRENT_IRQL;
  1501. TRACE( TL_T, TM_Cm, ( "==>nicCmMakeCallCompleteFailureCleanUp pVc %x", pVc ) );
  1502. switch (pVc->Hdr.VcType)
  1503. {
  1504. case NIC1394_RecvFIFO:
  1505. {
  1506. PRECVFIFO_VCCB pRecvFIFOVc = (PRECVFIFO_VCCB )pVc;
  1507. TRACE( TL_V, TM_Cm, ( "Cleaning up a recv FIFo %x", pVc ) );
  1508. if (pRecvFIFOVc->PacketPool.Handle != NULL)
  1509. {
  1510. nicFreePacketPool (&pRecvFIFOVc->PacketPool);
  1511. }
  1512. pRecvFIFOVc->PacketPool.Handle = NULL;
  1513. if (pRecvFIFOVc->FifoSListHead.Alignment != 0)
  1514. {
  1515. nicFreeAllocateAddressRangeSList (pRecvFIFOVc);
  1516. }
  1517. pRecvFIFOVc->FifoSListHead.Alignment = 0;
  1518. break;
  1519. }
  1520. case NIC1394_SendFIFO:
  1521. case NIC1394_SendRecvChannel:
  1522. case NIC1394_SendChannel:
  1523. case NIC1394_RecvChannel:
  1524. default:
  1525. break;
  1526. }
  1527. //
  1528. // This call does the generic clean up
  1529. //
  1530. nicCmGenrericMakeCallFailure (pVc);
  1531. TRACE( TL_T, TM_Cm, ( "<==nicCmMakeCallCompleteFailureCleanUp ") );
  1532. MATCH_IRQL;
  1533. return ;
  1534. }
  1535. NDIS_STATUS
  1536. NicCmCloseCall(
  1537. IN NDIS_HANDLE CallMgrVcContext,
  1538. IN NDIS_HANDLE CallMgrPartyContext,
  1539. IN PVOID CloseData,
  1540. IN UINT Size )
  1541. // Standard 'CmCloseCallHandler' routine called by NDIS when the a client
  1542. // has requested to tear down a call. See DDK doc.
  1543. //
  1544. {
  1545. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1546. ADAPTERCB* pAdapter = NULL;
  1547. VCCB* pVc = NULL;
  1548. NDIS_WORK_ITEM* pCloseCallCompleteWorkItem = NULL;
  1549. STORE_CURRENT_IRQL;
  1550. TRACE( TL_T, TM_Cm, ( "==>NicCmCloseCall($%p)", CallMgrVcContext ) );
  1551. pVc = (VCCB* )CallMgrVcContext;
  1552. if (pVc->Hdr.ulTag != MTAG_VCCB)
  1553. {
  1554. ASSERT( !"Vtag?" );
  1555. return NDIS_STATUS_INVALID_DATA;
  1556. }
  1557. do
  1558. {
  1559. pAdapter = pVc->Hdr.pAF->pAdapter;
  1560. if (pAdapter == NULL)
  1561. {
  1562. TRACE( TL_A, TM_Cm, ( "pAdpater is NULL - Make Call FAILED($%p)", CallMgrVcContext ) );
  1563. NdisStatus = NDIS_STATUS_FAILURE;
  1564. break;
  1565. }
  1566. VC_ACQUIRE_LOCK (pVc);
  1567. //
  1568. // If the Make Call is Pending, then fail the CloseCall.
  1569. // Or if there call is already closing then fail this close call
  1570. //
  1571. if ( VC_ACTIVE (pVc) == FALSE )
  1572. {
  1573. TRACE( TL_A, TM_Cm, ( "NicCmCloseCall Invalid flags - Close Call FAILED Vc $%p, flags %x", pVc, pVc->Hdr.ulFlags ) );
  1574. ASSERT ( ! "MakeCallPending or Call already closed?");
  1575. VC_RELEASE_LOCK (pVc);
  1576. break;
  1577. }
  1578. //
  1579. //
  1580. // Reference the Vc so we can gaurantee its presence till the end of the work item
  1581. // to CloseCallComplete. we have the lock
  1582. //
  1583. nicReferenceVc (pVc);
  1584. //
  1585. // Mark the Call as closing, and close the refcount, so no one can increment it
  1586. //
  1587. VC_SET_FLAG ( pVc, VCBF_CloseCallPending);
  1588. nicCloseCallRef (pVc);
  1589. VC_RELEASE_LOCK (pVc);
  1590. pCloseCallCompleteWorkItem = ALLOC_NONPAGED (sizeof(NDIS_WORK_ITEM), MTAG_WORKITEM);
  1591. if (pCloseCallCompleteWorkItem == NULL)
  1592. {
  1593. TRACE( TL_A, TM_Cm, ( "Local Alloc failed for WorkItem - Close Call FAILED($%p)", CallMgrVcContext ) );
  1594. NdisStatus = NDIS_STATUS_RESOURCES;
  1595. break;
  1596. }
  1597. NdisInitializeWorkItem ( pCloseCallCompleteWorkItem,
  1598. (NDIS_PROC)nicCmCloseCallComplete,
  1599. (PVOID)pVc );
  1600. NdisInterlockedIncrement(&pAdapter->OutstandingWorkItems);
  1601. NdisScheduleWorkItem (pCloseCallCompleteWorkItem);
  1602. } while (FALSE);
  1603. MATCH_IRQL;
  1604. TRACE( TL_T, TM_Cm, ( "<==NicCmCloseCall pending" ) );
  1605. return NDIS_STATUS_PENDING;
  1606. }
  1607. VOID
  1608. nicCmCloseCallComplete(
  1609. NDIS_WORK_ITEM* pCloseCallCompleteWorkItem,
  1610. IN PVOID Context
  1611. )
  1612. // Function Description:
  1613. // This function completes the close call. The qor Item gaurantees that all work will be
  1614. // done at passive level
  1615. //
  1616. // Arguments
  1617. // Context : Which is VCCB for which the close call was requested
  1618. //
  1619. //
  1620. // Return Value:
  1621. // None
  1622. // However an NdisStatus is passed in the call to Ndis' close call complete function
  1623. //
  1624. //
  1625. {
  1626. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1627. PVCCB pVc = (PVCCB) Context;
  1628. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1629. BOOLEAN fCallClosable = FALSE;
  1630. BOOLEAN fWaitSucceeded = FALSE;
  1631. STORE_CURRENT_IRQL;
  1632. TRACE( TL_T, TM_Cm, ( "==>nicCmCloseCallComplete pVc %x", pVc ) );
  1633. //
  1634. // Invoke the close call handler of the VC
  1635. //
  1636. ASSERT (pVc->Hdr.VcHandlers.CloseCallHandler != NULL);
  1637. NdisStatus = (*pVc->Hdr.VcHandlers.CloseCallHandler) (pVc);
  1638. //
  1639. // right now, we do not fail a close call because the bus driver failed us.
  1640. //
  1641. NdisStatus = NDIS_STATUS_SUCCESS;
  1642. //
  1643. // Made it so far, we now need to dereference the call. We made the reference in
  1644. // MakeCall. This will complete the call if it gets down to zero
  1645. //
  1646. if (NdisStatus == NDIS_STATUS_SUCCESS)
  1647. {
  1648. //
  1649. // Derefercence the call ref and Vc Refs that were added at the end of
  1650. // a successful make call
  1651. //
  1652. nicDereferenceCall (pVc, "nicCmCloseCallComplete");
  1653. }
  1654. //
  1655. // Important : THIS WAIT is for the REFCOUNT on the CALL , not the VC
  1656. //
  1657. TRACE( TL_N, TM_Cm, ( "About to Wait for CallRefs to go to zero pVc %x ", pVc) );
  1658. fWaitSucceeded = NdisWaitEvent (&pVc->Hdr.CallRef.RefZeroEvent, WAIT_INFINITE );
  1659. if (fWaitSucceeded == FALSE)
  1660. {
  1661. TRACE( TL_A, TM_Cm, ( "Wait Timed Out Call, Vc %x, RefCount %x ", pVc , pVc->Hdr.CallRef.ReferenceCount) );
  1662. ASSERT (fWaitSucceeded == TRUE);
  1663. }
  1664. ASSERT (KeGetCurrentIrql() <= DISPATCH_LEVEL);
  1665. //
  1666. // Succeed the Close call as all references have gone to zero
  1667. // The call has no more outstanding resources
  1668. //
  1669. TRACE( TL_N, TM_Cm, ( "About to Close Call on pVc %x", pVc ) );
  1670. NdisMCmCloseCallComplete( NDIS_STATUS_SUCCESS,
  1671. pVc->Hdr.NdisVcHandle, NULL );
  1672. VC_ACQUIRE_LOCK (pVc);
  1673. VC_CLEAR_FLAGS (pVc, VCBF_CloseCallPending);
  1674. VC_SET_FLAG (pVc, VCBF_CloseCallCompleted);
  1675. VC_RELEASE_LOCK (pVc);
  1676. FREE_NONPAGED (pCloseCallCompleteWorkItem);
  1677. NdisInterlockedDecrement(&pAdapter->OutstandingWorkItems);
  1678. //
  1679. // Release the reference made when entering the Close Call function above. so the Vc can disappear if it wants to
  1680. // Remember that delete Vc can already have gone through at this time, and the Vc will be freed after the deref
  1681. //
  1682. nicDereferenceVc (pVc);
  1683. TRACE( TL_T, TM_Cm, ( "<==nicCmCloseCallComplete pVc %x, Status %x", pVc, NdisStatus ) );
  1684. MATCH_IRQL;
  1685. }
  1686. NDIS_STATUS
  1687. nicCmCloseCallEthernet (
  1688. IN PVCCB pVc
  1689. )
  1690. /*++
  1691. Routine Description:
  1692. Do nothing for now. Just succeed
  1693. Arguments:
  1694. Return Value:
  1695. --*/
  1696. {
  1697. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1698. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1699. PETHERNET_VCCB pEthernetVc = (PETHERNET_VCCB)pVc;
  1700. NIC_PACKET_POOL PacketPool;
  1701. TRACE( TL_T, TM_Cm, ( "==>nicCmCloseCallEthernet %x", pVc) );
  1702. ADAPTER_ACQUIRE_LOCK (pAdapter);
  1703. PacketPool = pEthernetVc->PacketPool;
  1704. pEthernetVc->PacketPool.Handle = 0;
  1705. pEthernetVc->PacketPool.AllocatedPackets = 0;
  1706. ADAPTER_RELEASE_LOCK (pAdapter);
  1707. if (PacketPool.Handle != NULL)
  1708. {
  1709. nicDereferenceCall ((PVCCB)pEthernetVc, "pEthernetVc - Free PacketPool" );
  1710. nicFreePacketPool (&PacketPool);
  1711. }
  1712. ADAPTER_ACQUIRE_LOCK (pAdapter);
  1713. //
  1714. // Dereference the VC as the adapter's pointer has been cleared
  1715. //
  1716. nicDereferenceCall (pVc, "nicCmMakeCallEthernet ");
  1717. pAdapter->pEthernetVc = NULL;
  1718. ADAPTER_RELEASE_LOCK (pAdapter);
  1719. NdisStatus = NDIS_STATUS_SUCCESS;
  1720. TRACE( TL_T, TM_Cm, ( "<==nicCmCloseCallEthernet %x", NdisStatus) );
  1721. return NdisStatus;
  1722. }
  1723. NDIS_STATUS
  1724. nicCmCloseCallMultiChannel (
  1725. IN PVCCB pVc
  1726. )
  1727. /*++
  1728. Routine Description:
  1729. Free the packet pool and Just succeed
  1730. Arguments:
  1731. Return Value:
  1732. --*/
  1733. {
  1734. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1735. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1736. PCHANNEL_VCCB pMcVc = (PCHANNEL_VCCB)pVc;
  1737. NIC_PACKET_POOL PacketPool;
  1738. TRACE( TL_T, TM_Cm, ( "==>nicCmCloseCallMultiChannel %x", pVc) );
  1739. ASSERT (VC_TEST_FLAG (pVc, VCBF_BroadcastVc) == FALSE);
  1740. //
  1741. // Mask the fact that this is a multichannel Call
  1742. //
  1743. NdisStatus = nicCmCloseCallSendRecvChannel (pVc);
  1744. //
  1745. // Nothing to fail
  1746. //
  1747. NdisStatus = NDIS_STATUS_SUCCESS;
  1748. TRACE( TL_T, TM_Cm, ( "<==nicCmCloseCallMultiChannel %x", NdisStatus) );
  1749. return NdisStatus;
  1750. }
  1751. NDIS_STATUS
  1752. nicCmCloseCallSendRecvChannel (
  1753. IN PVCCB pVc
  1754. )
  1755. // Function Description:
  1756. // This function will do clean up for RecvFifos
  1757. // Includes removing the VC pointer from Pdo Adapter structure.
  1758. // And needs to go through all active remote nodes and free the address ranges on them
  1759. // The BCM Vc has the added overhead of having an address range associated with it.
  1760. // which we need to free
  1761. //
  1762. // Arguments
  1763. // PVCCB pVc - The Channel VC that needs to be closed
  1764. //
  1765. // Return Value:
  1766. // Success for now
  1767. //
  1768. // Called with the lock held
  1769. {
  1770. PCHANNEL_VCCB pChannelVc = (PCHANNEL_VCCB ) pVc;
  1771. PCHANNEL_VCCB pTempVc = NULL;
  1772. BOOLEAN fIsBroadcastVc = FALSE;
  1773. PLIST_ENTRY pVcListEntry = NULL;
  1774. PADAPTERCB pAdapter = NULL;
  1775. ULONG NumDereferenced ;
  1776. HANDLE hResource ;
  1777. ULONG NumDescriptors ;
  1778. PISOCH_DESCRIPTOR pIsochDescriptor;
  1779. BOOLEAN fAllocatedChannel ;
  1780. ULONG Channel ;
  1781. NIC_PACKET_POOL PacketPool;
  1782. STORE_CURRENT_IRQL;
  1783. TRACE( TL_T, TM_Cm, ( "==> nicCmCloseCallSendRecvChannel pVc %x", pVc) );
  1784. ASSERT (pVc!=NULL);
  1785. pAdapter = pChannelVc->Hdr.pAF->pAdapter;
  1786. ASSERT (pAdapter != NULL);
  1787. do
  1788. {
  1789. VC_ACQUIRE_LOCK (pChannelVc);
  1790. if (VC_TEST_FLAG (pChannelVc, VCBF_BroadcastVc) == TRUE)
  1791. {
  1792. PADDRESS_RANGE_CONTEXT pBCRAddress = &pAdapter->BCRData.AddressRangeContext;
  1793. //
  1794. // Free the allocated address renge for the Broadcast Channel Register
  1795. //
  1796. if ( BCR_TEST_FLAG (pAdapter, BCR_Initialized) == TRUE)
  1797. {
  1798. //
  1799. // Clear out the Broadcast VC in the BCRData structure, Derereference the call. and clear the flag
  1800. // The ref was made in the MakeCallAllocateChannel function
  1801. //
  1802. if (pAdapter->BCRData.pBroadcastChanneVc != NULL)
  1803. {
  1804. pAdapter->BCRData.pBroadcastChanneVc = NULL;
  1805. nicDereferenceCall((PVCCB) pChannelVc, "nicCmCloseCallSendRecvChannel Broadcast VC");
  1806. }
  1807. VC_CLEAR_FLAGS (pChannelVc, VCBF_BroadcastVc) ;
  1808. }
  1809. }
  1810. VC_RELEASE_LOCK (pChannelVc);
  1811. nicIsochStop (pAdapter,
  1812. pChannelVc->hResource);
  1813. VC_ACQUIRE_LOCK (pChannelVc);
  1814. PacketPool = pChannelVc->PacketPool;
  1815. hResource = pChannelVc->hResource;
  1816. NumDescriptors = pChannelVc->NumDescriptors;
  1817. pIsochDescriptor = pChannelVc->pIsochDescriptor;
  1818. fAllocatedChannel = VC_TEST_FLAGS( pChannelVc, VCBF_AllocatedChannel);
  1819. Channel = pChannelVc->Channel;
  1820. PacketPool = pChannelVc->PacketPool;
  1821. //
  1822. // Clean out the VC structure and then call NDIS or the bus driver to free all
  1823. // the resources
  1824. //
  1825. nicChannelCallCleanDataStructure (pChannelVc,
  1826. pChannelVc->hResource,
  1827. pChannelVc->NumDescriptors,
  1828. pChannelVc->pIsochDescriptor,
  1829. fAllocatedChannel,
  1830. pChannelVc->Channel,
  1831. pChannelVc->PacketPool.Handle,
  1832. &NumDereferenced );
  1833. VC_RELEASE_LOCK (pChannelVc);
  1834. nicChannelCallFreeResources ( pChannelVc,
  1835. pAdapter,
  1836. hResource,
  1837. NumDescriptors,
  1838. pIsochDescriptor,
  1839. fAllocatedChannel,
  1840. Channel,
  1841. &PacketPool);
  1842. } while (FALSE);
  1843. TRACE( TL_T, TM_Cm, ( "<== nicCmCloseCallSendRecvChannel Status %x(always success)" ) );
  1844. MATCH_IRQL;
  1845. return NDIS_STATUS_SUCCESS;
  1846. }
  1847. NDIS_STATUS
  1848. nicCmCloseCallRecvFIFO (
  1849. IN PVCCB pVc
  1850. )
  1851. // Function Description:
  1852. // This function will do clean up for RecvFifos
  1853. // Includes removing the VC pointer from Pdo Adapter structure.
  1854. // And needs to go through all active remote nodes and free the address ranges on them
  1855. //
  1856. //
  1857. // Arguments
  1858. // PVCCB pVc - The SendFifo that needs to be closed
  1859. //
  1860. // Return Value:
  1861. // Success for now
  1862. //
  1863. {
  1864. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1865. PRECVFIFO_VCCB pRecvFIFOVc = (PRECVFIFO_VCCB)pVc;
  1866. PADDRESS_FIFO pAddressFifo = NULL;
  1867. PSINGLE_LIST_ENTRY pAddressFifoEntry = NULL;
  1868. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  1869. TRACE( TL_T, TM_Cm, ( "==> nicCmCloseCallRecvFIFO pVc %x", pVc) );
  1870. //NdisStatus = nicFreeRecvFifoAddressRangeOnAllRemoteNodes (pAdapter);
  1871. NdisStatus = nicFreeAddressRange( pAdapter,
  1872. pRecvFIFOVc->AddressesReturned,
  1873. &pRecvFIFOVc->VcAddressRange,
  1874. &pRecvFIFOVc->hAddressRange );
  1875. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1876. {
  1877. TRACE( TL_I, TM_Cm, ( "Call to Free Address Range Failed pVc at %x",pVc ) );
  1878. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  1879. //
  1880. // Do not Break. Continue
  1881. //
  1882. NdisStatus = NDIS_STATUS_SUCCESS;
  1883. }
  1884. pRecvFIFOVc->hAddressRange = NULL;
  1885. pRecvFIFOVc->AddressesReturned = 0;
  1886. pRecvFIFOVc->VcAddressRange.AR_Off_High = 0;
  1887. pRecvFIFOVc->VcAddressRange.AR_Off_Low = 0;
  1888. nicDereferenceCall ((PVCCB)pRecvFIFOVc,
  1889. "nicCmCloseCallRecvFIFO - Free address range" );
  1890. nicFreePacketPool (&pRecvFIFOVc->PacketPool);
  1891. //
  1892. // Free the Slist Entries (AddressFifo, Mdl's) and their associated memory
  1893. // and decrease the refcount for each entry
  1894. //
  1895. NdisStatus = nicFreeAllocateAddressRangeSList (pRecvFIFOVc);
  1896. if (NdisStatus != NDIS_STATUS_SUCCESS)
  1897. {
  1898. TRACE( TL_I, TM_Cm, ( "Call to Free SList Failed pVc at %x",pVc ) );
  1899. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  1900. //
  1901. // Don't break out. Continue
  1902. //
  1903. NdisStatus = NDIS_STATUS_SUCCESS;
  1904. }
  1905. //
  1906. // At this point all the resources of the call have been exhuasted and we can del the pointer in the adapter structure
  1907. //
  1908. VC_ACQUIRE_LOCK (pVc);
  1909. pVc->Hdr.pAF->pAdapter->pRecvFIFOVc = NULL;
  1910. VC_RELEASE_LOCK (pVc);
  1911. //
  1912. // Decrement the Vc Refcount as the adapter no longer has a pointer to it
  1913. //
  1914. nicDereferenceVc (pVc);
  1915. TRACE( TL_T, TM_Cm, ( "<== nicCmCloseCallRecvFIFO Status %x", NdisStatus) );
  1916. return NdisStatus;
  1917. }
  1918. NDIS_STATUS
  1919. nicCmCloseCallSendFIFO (
  1920. IN PVCCB pVc
  1921. )
  1922. // Function Description:
  1923. // This function will do clean up for Send Fifos
  1924. // Includes removing the pointer to the Vc that is in Pdo Adapter structure.
  1925. // For the Send FIFO, the Pdo block is in the pVc->Hdr.pRemoteNode location, so
  1926. // this does not try and find the pRemoteNode
  1927. // Arguments
  1928. // PVCCB pVc - The SendFifo that needs to be closed
  1929. //
  1930. // Return Value:
  1931. // Success for now
  1932. //
  1933. {
  1934. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  1935. REMOTE_NODE * pRemoteNode = pVc->Hdr.pRemoteNode;
  1936. PLIST_ENTRY pVcListEntry = NULL;
  1937. PSENDFIFO_VCCB pTempVc = NULL;
  1938. BOOLEAN fVcFound = FALSE;
  1939. TRACE( TL_T, TM_Cm, ( "==> nicCmCloseCallSendFIFO pVc %x", pVc) );
  1940. //
  1941. // SendComplete Handler will complete the close call.
  1942. // This thread should not do it
  1943. // Called in nicFreeSendPacketDataStructures
  1944. //
  1945. #ifdef TODO
  1946. // Free all the structures allocated for the SendFIFO. for now they are none
  1947. #endif
  1948. //
  1949. // Go through the PdoCb structure and remove the VC from it's VC List
  1950. //
  1951. ASSERT (pRemoteNode != NULL);
  1952. VC_ACQUIRE_LOCK (pVc);
  1953. for (pVcListEntry = pRemoteNode->VcList.Flink;
  1954. pVcListEntry != &pRemoteNode->VcList;
  1955. pVcListEntry = pVcListEntry->Flink)
  1956. {
  1957. pTempVc = (PSENDFIFO_VCCB) CONTAINING_RECORD (pVcListEntry, VCHDR, SinglePdoVcLink);
  1958. //
  1959. // Now remove the Vc from that linked list
  1960. //
  1961. if (pTempVc == (PSENDFIFO_VCCB) pVc )
  1962. {
  1963. nicRemoveEntryList (pVcListEntry);
  1964. TRACE( TL_V, TM_Cm, ( "==> Removed Vc %x From Pdo's Vc List ", pVc) );
  1965. //
  1966. // Remove the reference from the Vc as the Pdo no longer
  1967. // has a pointer to it. This ref was made in MakeCallInitSendFifo
  1968. //
  1969. nicDereferenceCall (pVc, "nicCmCloseCallSendFIFO ");
  1970. NdisStatus = NDIS_STATUS_SUCCESS;
  1971. break;
  1972. }
  1973. }
  1974. //
  1975. // Decerement the Ref on the Pdo as the Vc no longer has a pointer to it.
  1976. // This Ref was made in MakeCallSendFifo function
  1977. //
  1978. nicDereferenceRemoteNode (pRemoteNode, "nicCmCloseCallSendFIFO ");
  1979. //
  1980. // Null, it so that if we try to access this pointer, we bugcheck
  1981. //
  1982. pVc->Hdr.pRemoteNode = NULL;
  1983. VC_RELEASE_LOCK (pVc);
  1984. //
  1985. // There is no reason why we should not have found the Vc in the Pdo list
  1986. //
  1987. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  1988. TRACE( TL_T, TM_Cm, ( "<== nicCmCloseCallSendFIFO Status %x", NdisStatus) );
  1989. NdisStatus = NDIS_STATUS_SUCCESS;
  1990. return NdisStatus;
  1991. }
  1992. NDIS_STATUS
  1993. nicCmCloseCallSendChannel(
  1994. IN PVCCB pVc
  1995. )
  1996. /*++
  1997. Routine Description:
  1998. Free the channel, if its been allocated
  1999. Arguments:
  2000. Return Value:
  2001. --*/
  2002. {
  2003. PADAPTERCB pAdapter = (PADAPTERCB) pVc->Hdr.pAF->pAdapter;
  2004. PCHANNEL_VCCB pChannelVc = (PCHANNEL_VCCB)pVc;
  2005. TRACE( TL_T, TM_Cm, ( "==>nicCmCloseCallSendChannel " ) );
  2006. if (VC_TEST_FLAG (pVc,VCBF_AllocatedChannel) == TRUE)
  2007. {
  2008. nicFreeChannel (pAdapter, pChannelVc->Channel);
  2009. nicDereferenceCall ((PVCCB)pChannelVc, "Close Call - Send Channel - Freeing Channel" );
  2010. }
  2011. TRACE( TL_T, TM_Cm, ( "<==nicCmCloseCallSendChannel " ) );
  2012. return NDIS_STATUS_SUCCESS;
  2013. }
  2014. VOID
  2015. nicChannelCallFreeResources (
  2016. IN PCHANNEL_VCCB pChannelVc,
  2017. IN PADAPTERCB pAdapter,
  2018. IN HANDLE hResource,
  2019. IN ULONG NumDescriptors,
  2020. IN PISOCH_DESCRIPTOR pIsochDescriptor,
  2021. IN BOOLEAN fChannelAllocated,
  2022. IN ULONG Channel,
  2023. IN PNIC_PACKET_POOL pPacketPool
  2024. )
  2025. // Function Description:
  2026. // This function is called from Close call or MakeCall Failure code path.
  2027. // It will detach buffers, free resources, free channel and free bandwdith.
  2028. // It is the responsibility of the caller to do all the appropriate ref counting
  2029. //
  2030. // Arguments
  2031. //
  2032. // pAdapter contains the VDO to which all the IRPs were sent
  2033. // hResource resource handle to be used by the bus driver,
  2034. // NumDescriptors Number of descriptors attached to the buffer,
  2035. // pIsochDesciptor Original pointer to the start of the Buffer Descriptor ,
  2036. // Channel, - Channel that was allocated
  2037. //
  2038. // Return Value:
  2039. // Success if all irps completed succeesfully. Wil be ignored by called
  2040. //
  2041. {
  2042. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  2043. STORE_CURRENT_IRQL;
  2044. TRACE( TL_T, TM_Cm, ( "==>nicChannelCallFreeResources " ) );
  2045. TRACE( TL_V, TM_Cm, ( "hResource %x, NumDescriptors %.2x, pIsochDescriptor %x, Channel Allocated %.2x, Channel %x",
  2046. hResource, NumDescriptors, pIsochDescriptor, fChannelAllocated, Channel ) )
  2047. //
  2048. // Reference the pdo structure so it will be around until the end
  2049. // of this function
  2050. // Reference decremented at the end of this function
  2051. //
  2052. ADAPTER_ACQUIRE_LOCK (pAdapter);
  2053. nicReferenceAdapter (pAdapter, "nicChannelCallFreeResources ");
  2054. ADAPTER_RELEASE_LOCK (pAdapter);
  2055. //
  2056. // Do not break out of the loop. We need to try and free as much as possible
  2057. //
  2058. if (pIsochDescriptor != NULL)
  2059. {
  2060. // Detach Buffers
  2061. //
  2062. while (pChannelVc->NumIndicatedIsochDesc != 0 )
  2063. {
  2064. //
  2065. // we will wait for ever, checking periodically for all the packets to return
  2066. //
  2067. TRACE( TL_V, TM_Cm, ( " nicChannelCallFreeResources - Sleeping to wait for packets to be retuerned " ) );
  2068. NdisMSleep ( FIFTY_MILLISECONDS );
  2069. }
  2070. NdisStatus = nicIsochDetachBuffers( pAdapter,
  2071. hResource,
  2072. NumDescriptors,
  2073. pIsochDescriptor );
  2074. if (NdisStatus != NDIS_STATUS_SUCCESS)
  2075. {
  2076. TRACE( TL_A, TM_Cm, ( "nicIsochDetachBuffers FAILED " ) );
  2077. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  2078. }
  2079. // First Free Isoch Descriptors and their associated MDLs
  2080. //
  2081. nicFreeIsochDescriptors (NumDescriptors, pIsochDescriptor, (PVCCB)pChannelVc);
  2082. }
  2083. if (hResource != NULL)
  2084. {
  2085. // Free resources
  2086. //
  2087. NdisStatus = nicIsochFreeResources( pAdapter,
  2088. hResource );
  2089. if (NdisStatus != NDIS_STATUS_SUCCESS)
  2090. {
  2091. TRACE( TL_A, TM_Cm, ( "nicIsochFreeResources FAILED " ) );
  2092. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  2093. }
  2094. }
  2095. if (fChannelAllocated == TRUE)
  2096. {
  2097. PULONGLONG pLocalHostChannels = &pAdapter->ChannelsAllocatedByLocalHost;
  2098. ASSERT (Channel < 64);
  2099. // Free the Channel
  2100. //
  2101. NdisStatus = nicFreeChannel (pAdapter,
  2102. Channel);
  2103. if (NdisStatus != NDIS_STATUS_SUCCESS)
  2104. {
  2105. TRACE( TL_A, TM_Cm, ( "nicIsochFreeChannel FAILED " ) );
  2106. ASSERT (NdisStatus == NDIS_STATUS_SUCCESS);
  2107. }
  2108. //
  2109. // Clear the bit in the adapter;s channel bitmap
  2110. //
  2111. VC_ACQUIRE_LOCK (pChannelVc);
  2112. (*pLocalHostChannels)= ((*pLocalHostChannels) & (~(g_ullOne <<Channel)));
  2113. VC_CLEAR_FLAGS( pChannelVc, VCBF_AllocatedChannel);
  2114. VC_RELEASE_LOCK (pChannelVc);
  2115. }
  2116. if (pPacketPool->Handle != NULL)
  2117. {
  2118. nicFreePacketPool(pPacketPool);
  2119. }
  2120. //
  2121. // Remove The Ref that was added in the beginning of the function
  2122. //
  2123. nicDereferenceAdapter (pAdapter, "nicChannelCallFreeResources ");
  2124. MATCH_IRQL;
  2125. TRACE( TL_T, TM_Cm, ( "<==nicChannelCallFreeResources " ) );
  2126. }
  2127. VOID
  2128. nicChannelCallCleanDataStructure (
  2129. IN PCHANNEL_VCCB pChannelVc,
  2130. IN HANDLE hResource,
  2131. IN ULONG NumDescriptors,
  2132. IN PISOCH_DESCRIPTOR pIsochDescriptor,
  2133. IN BOOLEAN fChannelAllocated,
  2134. IN ULONG Channel,
  2135. IN NDIS_HANDLE hPacketPoolHandle,
  2136. OUT PULONG pNumRefsDecremented
  2137. )
  2138. // Function Description:
  2139. // If any of the data fields in the ChannelVc match the
  2140. // corresponding argument in this structure it will be
  2141. // NULLed out and the call dereferenced
  2142. //
  2143. // Called with the lock held.
  2144. //
  2145. // Arguments
  2146. // PCHANNEL_VCCB pChannelVc, - Channel Vc
  2147. // HANDLE hResource, - Handle to resource
  2148. // ULONG NumDescriptors, - Num descriptors will be set to zero
  2149. // PISOCH_DESCRIPTOR pIsochDesciptor, - Pointer to array of isoch descriptors
  2150. // BOOLEAN fChannelAllocated, - Was the Channel allocated
  2151. // ULONG Channel, - channel number
  2152. // NDIS_HANDLE hPacketPoolHandle - Packet pool handle
  2153. //
  2154. //
  2155. //
  2156. // Return Value:
  2157. //
  2158. //
  2159. //
  2160. //
  2161. {
  2162. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  2163. ULONG NumRefsDecremented = 0;
  2164. TRACE( TL_T, TM_Cm, ( "==>nicChannelCallCleanDataStructure " ) );
  2165. TRACE( TL_V, TM_Cm, ( "hResource %x, NumDescriptors %.2x, pIsochDescriptor %x, Channel Allocated %.2x, Channel %x",
  2166. hResource, NumDescriptors, pIsochDescriptor, fChannelAllocated, Channel ) )
  2167. if (pChannelVc == NULL)
  2168. {
  2169. return ;
  2170. }
  2171. if ((pChannelVc->NumDescriptors == NumDescriptors )&&
  2172. (pChannelVc->pIsochDescriptor == pIsochDescriptor ) &&
  2173. pIsochDescriptor != NULL )
  2174. {
  2175. pChannelVc->NumDescriptors = 0;
  2176. pChannelVc->pIsochDescriptor = NULL;
  2177. nicDereferenceCall ((PVCCB)pChannelVc, "nicChannelCallCleanDataStructure Detach Buffers ");
  2178. NumRefsDecremented ++;
  2179. }
  2180. if (hResource != NULL && pChannelVc->hResource == hResource)
  2181. {
  2182. pChannelVc->hResource = NULL;
  2183. nicDereferenceCall ((PVCCB)pChannelVc, "nicChannelCallCleanDataStructure Free Resource ");
  2184. NumRefsDecremented ++;
  2185. }
  2186. if (fChannelAllocated == TRUE)
  2187. {
  2188. ASSERT ( VC_TEST_FLAG (pChannelVc, VCBF_AllocatedChannel) == TRUE);
  2189. VC_CLEAR_FLAGS (pChannelVc, VCBF_AllocatedChannel);
  2190. pChannelVc->Channel = INVALID_CHANNEL;
  2191. nicDereferenceCall ((PVCCB)pChannelVc, "nicChannelCallCleanDataStructure - Free Channel");
  2192. NumRefsDecremented ++;
  2193. }
  2194. if (hPacketPoolHandle != NULL && pChannelVc->PacketPool.Handle == hPacketPoolHandle)
  2195. {
  2196. pChannelVc->PacketPool.Handle = NULL;
  2197. nicDereferenceCall ((PVCCB)pChannelVc, "nicChannelCallCleanDataStructure - Packet Pool");
  2198. NumRefsDecremented ++;
  2199. }
  2200. //REMOTE_NODE_RELEASE_LOCK (pRemoteNodePdoCb);
  2201. //
  2202. // Remove The Ref that was added in the beginning of the function
  2203. //
  2204. NdisStatus = NDIS_STATUS_SUCCESS;
  2205. if (pNumRefsDecremented != NULL)
  2206. {
  2207. *pNumRefsDecremented = NumRefsDecremented ;
  2208. }
  2209. TRACE( TL_T, TM_Cm, ( "<==nicChannelCallCleanDataStructure %x", *pNumRefsDecremented ) );
  2210. }
  2211. NDIS_STATUS
  2212. NicCmModifyCallQoS(
  2213. IN NDIS_HANDLE CallMgrVcContext,
  2214. IN PCO_CALL_PARAMETERS CallParameters )
  2215. // Standard 'CmModifyQoSCallHandler' routine called by NDIS when a client
  2216. // requests a modification in the quality of service provided by the
  2217. // virtual circuit. See DDK doc.
  2218. //
  2219. {
  2220. TRACE( TL_T, TM_Cm, ( "NicCmModQoS" ) );
  2221. // There is no useful concept of quality of service for IP media.
  2222. //
  2223. return NDIS_STATUS_NOT_SUPPORTED;
  2224. }
  2225. NDIS_STATUS
  2226. NicCmRequest(
  2227. IN NDIS_HANDLE CallMgrAfContext,
  2228. IN NDIS_HANDLE CallMgrVcContext,
  2229. IN NDIS_HANDLE CallMgrPartyContext,
  2230. IN OUT PNDIS_REQUEST pNdisRequest )
  2231. // Standard 'CmRequestHandler' routine called by NDIS in response to a
  2232. // client's request for information from the call manager.
  2233. //
  2234. {
  2235. AFCB* pAF;
  2236. VCCB* pVc;
  2237. NDIS_STATUS NdisStatus;
  2238. TRACE( TL_T, TM_Cm, ( "==>NicCmReq" ) );
  2239. pAF = (AFCB*) CallMgrAfContext;
  2240. if (pAF->ulTag != MTAG_AFCB )
  2241. {
  2242. ASSERT( !"Atag?" );
  2243. return NDIS_STATUS_INVALID_DATA;
  2244. }
  2245. pVc = (VCCB* )CallMgrVcContext;
  2246. if (pVc && pVc->Hdr.ulTag != MTAG_VCCB)
  2247. {
  2248. ASSERT( !"Vtag?" );
  2249. return NDIS_STATUS_INVALID_DATA;
  2250. }
  2251. #if TODO // Add 1394-specific functionality here.
  2252. #endif
  2253. ASSERT(pNdisRequest != NULL);
  2254. switch (pNdisRequest->RequestType)
  2255. {
  2256. case NdisRequestQueryStatistics:
  2257. case NdisRequestQueryInformation:
  2258. {
  2259. NdisStatus = nicCmQueryInformation(
  2260. CallMgrAfContext,
  2261. CallMgrVcContext,
  2262. CallMgrPartyContext,
  2263. pNdisRequest->DATA.QUERY_INFORMATION.Oid,
  2264. pNdisRequest->DATA.QUERY_INFORMATION.InformationBuffer,
  2265. pNdisRequest->DATA.QUERY_INFORMATION.InformationBufferLength,
  2266. &pNdisRequest->DATA.QUERY_INFORMATION.BytesWritten,
  2267. &pNdisRequest->DATA.QUERY_INFORMATION.BytesNeeded );
  2268. break;
  2269. }
  2270. case NdisRequestSetInformation:
  2271. {
  2272. NdisStatus = nicCmSetInformation(
  2273. CallMgrAfContext,
  2274. CallMgrVcContext,
  2275. CallMgrPartyContext,
  2276. pNdisRequest->DATA.SET_INFORMATION.Oid,
  2277. pNdisRequest->DATA.SET_INFORMATION.InformationBuffer,
  2278. pNdisRequest->DATA.SET_INFORMATION.InformationBufferLength,
  2279. &pNdisRequest->DATA.SET_INFORMATION.BytesRead,
  2280. &pNdisRequest->DATA.SET_INFORMATION.BytesNeeded );
  2281. break;
  2282. }
  2283. default:
  2284. {
  2285. NdisStatus = NDIS_STATUS_NOT_SUPPORTED;
  2286. TRACE( TL_A, TM_Mp, ( "type=%d?", pNdisRequest->RequestType ) );
  2287. break;
  2288. }
  2289. }
  2290. TRACE( TL_T, TM_Cm, ( "<==NicCmReq" ) );
  2291. return NdisStatus;
  2292. }
  2293. VOID
  2294. nicDereferenceAF(
  2295. IN AFCB* pAF )
  2296. // Removes a reference from the address family of adapter control block
  2297. // 'pAdapter', and when frees the block when the last reference is
  2298. // removed.
  2299. //
  2300. {
  2301. LONG lRef;
  2302. lRef = NdisInterlockedDecrement (&pAF->lRef);
  2303. TRACE( TL_T, TM_Ref, ( "DerefAf to %d", lRef ) );
  2304. ASSERT( lRef >= 0 );
  2305. if (lRef == 0)
  2306. {
  2307. ADAPTERCB* pAdapter = pAF->pAdapter;
  2308. // Remove linkages.
  2309. //
  2310. ADAPTER_ACQUIRE_LOCK (pAdapter);
  2311. pAF->pAdapter = NULL;
  2312. nicRemoveEntryList (&pAF->linkAFCB);
  2313. InitializeListHead (&pAF->linkAFCB);
  2314. ADAPTER_RELEASE_LOCK (pAdapter);
  2315. // Tell NDIS it's close is complete.
  2316. //
  2317. ASSERT ( nicReadFlags (&pAF->ulFlags) & ACBF_ClosePending);
  2318. TRACE( TL_I, TM_Cm, ( "NdisMCmCloseAfComp Af %x",pAF ) );
  2319. NdisMCmCloseAddressFamilyComplete(
  2320. NDIS_STATUS_SUCCESS, pAF->NdisAfHandle );
  2321. //
  2322. // Update State information to show that we have called CloseComplete
  2323. //
  2324. nicSetFlags ( &pAF->ulFlags, ACBF_CloseComplete);
  2325. nicClearFlags ( &pAF->ulFlags, ACBF_ClosePending);
  2326. nicDereferenceAdapter (pAdapter, "NdisMCmCloseAfComp "); // nicDereferenceFA (CloseAfComp)
  2327. nicFreeAF (pAF);
  2328. TRACE( TL_I, TM_Cm, ( "NdisMCmCloseAfComp done Af %x", pAF ) );
  2329. }
  2330. }
  2331. BOOLEAN
  2332. nicDereferenceCall(
  2333. IN VCCB* pVc,
  2334. IN PCHAR pDebugPrint
  2335. )
  2336. // Removes a reference from the call active on 'pVc', invoking call clean
  2337. // up when the value reaches zero.
  2338. //
  2339. // CAlled with the lock held
  2340. {
  2341. BOOLEAN bRefZero = FALSE;
  2342. //
  2343. // If the Ref goes to zero, derefref return true
  2344. //
  2345. bRefZero = nicDereferenceRef (&pVc->Hdr.CallRef);
  2346. TRACE( TL_V, TM_Ref, ( "***DerefCall %x to %d , %s" , pVc, pVc->Hdr.CallRef.ReferenceCount, pDebugPrint ) );
  2347. if ( bRefZero == TRUE)
  2348. {
  2349. //
  2350. // Dereference the Vc as the Call no longer exists. This reference was
  2351. // added in the beginning of the make call
  2352. nicDereferenceVc (pVc);
  2353. }
  2354. return bRefZero;
  2355. }
  2356. VOID
  2357. nicDereferenceVc(
  2358. IN VCCB* pVc )
  2359. // Removes a reference to the VC control block 'pVc', and when frees the
  2360. // block when the last reference is removed.
  2361. //
  2362. {
  2363. LONG lRef;
  2364. lRef = NdisInterlockedDecrement( &pVc->Hdr.lRef );
  2365. TRACE( TL_V, TM_Ref, ( "DerefVC to %d", lRef ) );
  2366. ASSERT( lRef >= 0 );
  2367. if (lRef == 0 )
  2368. {
  2369. // If close call is pending and the refcount has gone to zero, then call
  2370. //
  2371. ASSERT( pVc->Hdr.ulTag == MTAG_VCCB );
  2372. pVc->Hdr.ulTag = MTAG_FREED;
  2373. FREE_VCCB( pAdapter, pVc );
  2374. TRACE( TL_I, TM_Mp, ( "VCB freed $%p", pVc ) );
  2375. }
  2376. }
  2377. VOID
  2378. nicFreeAF(
  2379. IN AFCB* pAF )
  2380. // Frees all resources allocated for address family 'pAF', including
  2381. // 'pAF' itself.
  2382. //
  2383. {
  2384. #if TODO
  2385. Assert that the various lists (such as pAF->AFVCList) and resources are empty.
  2386. #endif // TODO
  2387. pAF->ulTag = MTAG_FREED;
  2388. FREE_NONPAGED (pAF);
  2389. }
  2390. VOID
  2391. nicReferenceAF(
  2392. IN AFCB* pAF )
  2393. // Adds areference to the address family of adapter block, 'pAdapter'.
  2394. //
  2395. {
  2396. LONG lRef=0;
  2397. lRef = NdisInterlockedIncrement (&pAF->lRef);
  2398. TRACE( TL_V, TM_Ref, ( "RefAf to %d", lRef ) );
  2399. }
  2400. BOOLEAN
  2401. nicReferenceCall(
  2402. IN VCCB* pVc,
  2403. IN PCHAR pDebugPrint
  2404. )
  2405. // Returns true if a reference is added to the active call on VC control
  2406. // block, 'pVc', or false if no reference was added because no call is
  2407. // active.
  2408. //
  2409. {
  2410. BOOLEAN fActive;
  2411. fActive = nicReferenceRef (&pVc->Hdr.CallRef);
  2412. TRACE( TL_V, TM_Ref, ( "***RefCall %x to %d , %s" , pVc, pVc->Hdr.CallRef.ReferenceCount, pDebugPrint ) );
  2413. if ( fActive==FALSE)
  2414. {
  2415. TRACE( TL_N, TM_Ref, ( "RefC Inactive" ) );
  2416. }
  2417. return fActive;
  2418. }
  2419. VOID
  2420. nicReferenceVc(
  2421. IN VCCB* pVc )
  2422. // Adds a reference to the VC control block 'pVc'.
  2423. //
  2424. {
  2425. LONG lRef;
  2426. lRef = NdisInterlockedIncrement (&pVc->Hdr.lRef);
  2427. TRACE( TL_I, TM_Ref, ( "RefVc to %d", lRef ) );
  2428. }
  2429. NDIS_STATUS
  2430. nicAllocateRequestedChannelMakeCallComplete (
  2431. IN PADAPTERCB pAdapter,
  2432. IN PCHANNEL_VCCB pChannelVc,
  2433. IN OUT PULONG pChannel
  2434. )
  2435. // Function Description:
  2436. // This function allocates the channel requested in the make
  2437. // If any channel is requested it will try all 64.
  2438. // If the broadcast channel is requested, it will look for
  2439. // for the channel allocated by the BCM
  2440. // Other wise it will simply try and allocate the requested channel
  2441. //
  2442. // This can be called from the AddFirstRemoteNode code path.
  2443. //
  2444. // Arguments
  2445. // Channel Vc - The channel Vc in question
  2446. // Channel - the channel requested
  2447. //
  2448. // Return Value:
  2449. // Success : if allocate channel succeeds
  2450. // pChannel - contains the allocated channel
  2451. //
  2452. {
  2453. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  2454. ULONG Channel = *pChannel;
  2455. BOOLEAN fAnyChannel = FALSE;
  2456. BOOLEAN fFailCall = FALSE;
  2457. TRACE( TL_T, TM_Cm, ( " ==>nicAllocateRequestedChannelMakeCallComplete pAdapter, pVc %x, Channel %x ",
  2458. pAdapter, pChannelVc, *pChannel ) );
  2459. do
  2460. {
  2461. //
  2462. // First make sure we have a good channel number
  2463. //
  2464. if ( (signed long)Channel < (signed long)NIC1394_BROADCAST_CHANNEL ||
  2465. (signed long)Channel >(signed long)MAX_CHANNEL_NUMBER)
  2466. {
  2467. TRACE( TL_A, TM_Cm, ( "Invalid Channel Number, channel %x", Channel) );
  2468. NdisStatus = NDIS_STATUS_INVALID_DATA;
  2469. ASSERT (!(signed long)Channel < (signed long)NIC1394_BROADCAST_CHANNEL ||
  2470. (signed long)Channel >(signed long)MAX_CHANNEL_NUMBER);
  2471. break;
  2472. }
  2473. if ((signed long)Channel == NIC1394_BROADCAST_CHANNEL )
  2474. {
  2475. NETWORK_CHANNELSR* pBCR;
  2476. ULONG i = 0;
  2477. pBCR = &pAdapter->BCRData.IRM_BCR;
  2478. ADAPTER_ACQUIRE_LOCK (pAdapter);
  2479. if (BCR_IS_VALID (pBCR) == FALSE)
  2480. {
  2481. BOOLEAN bWaitSuccessful = FALSE;
  2482. BOOLEAN fIsTheBCRFree = FALSE;
  2483. //
  2484. // BCM algorithm has not completed yet, we need to wait
  2485. //
  2486. TRACE( TL_I, TM_Cm, ( " nicAllocateRequestedChannelMakeCallComplete : BCR Has not completed. About to wait BCR %x ", *pBCR ) );
  2487. BCR_SET_FLAG (pAdapter, BCR_MakeCallPending);
  2488. ADAPTER_RELEASE_LOCK (pAdapter);
  2489. //
  2490. // If we don't have a BCR then we should wait until the BCM algorithm completes
  2491. //
  2492. //
  2493. // Now wait for the BCM algorithm to complete. First we will wait for
  2494. // 5 seconds. (5*1)
  2495. // If we still don't see it, we will reset the bus and hope that the new
  2496. // iteration of BCM will succeed.
  2497. //
  2498. //
  2499. // There can 2 reasons to stop waiting, the BCR is being freed because of a
  2500. // standby or BCR is correct. We check both conditions
  2501. //
  2502. NdisWaitEvent (&pAdapter->BCRData.MakeCallWaitEvent.NdisEvent, (5000));
  2503. //
  2504. // We reset the bus - if the BCR is not getting freed and we
  2505. // still do not have a valid BCR . and than we wait
  2506. // for the BCR to complete
  2507. //
  2508. if (BCR_IS_VALID(pBCR) == FALSE &&
  2509. (BCR_TEST_FLAGS (pAdapter, BCR_BCRNeedsToBeFreed | BCR_Freed)== FALSE))
  2510. {
  2511. TRACE( TL_I, TM_Cm, ( " nicAllocateRequestedChannelMakeCallComplete WaitCompleted - About to RESET THE BUS" ) );
  2512. nicIssueBusReset (pAdapter, BUS_RESET_FLAGS_FORCE_ROOT );
  2513. //
  2514. // Wait for 5 minutes before failing the Make Call
  2515. // (5 minutes is an experimental number)
  2516. //
  2517. {
  2518. BOOLEAN bWait;
  2519. bWait = NdisWaitEvent (
  2520. &pAdapter->BCRData.MakeCallWaitEvent.NdisEvent,
  2521. ONE_MINUTE * 5 );
  2522. }
  2523. }
  2524. ADAPTER_ACQUIRE_LOCK (pAdapter);
  2525. NdisResetEvent (&pAdapter->BCRData.MakeCallWaitEvent.NdisEvent);
  2526. pAdapter->BCRData.MakeCallWaitEvent.EventCode = Nic1394EventCode_InvalidEventCode;
  2527. BCR_CLEAR_FLAG (pAdapter, BCR_MakeCallPending);
  2528. //
  2529. // if we have not got a valid BCR, then fail the call
  2530. //
  2531. if (BCR_IS_VALID(pBCR) == FALSE ||
  2532. BCR_TEST_FLAGS (pAdapter, BCR_BCRNeedsToBeFreed | BCR_Freed))
  2533. {
  2534. fFailCall = TRUE;
  2535. ADAPTER_RELEASE_LOCK(pAdapter);
  2536. NdisStatus = NDIS_STATUS_FAILURE;
  2537. break;
  2538. }
  2539. }
  2540. Channel = pBCR->NC_Channel;
  2541. //
  2542. // Update the VC structure and break .
  2543. // Do not add a reference. Do not set the flag
  2544. //
  2545. pChannelVc->Channel = Channel;
  2546. pChannelVc->Hdr.Nic1394MediaParams.Destination.Channel = Channel;
  2547. //
  2548. // Reference that this Vc now has a pointer in the BCRData. This is dereferneced
  2549. // in the channel close call complete.
  2550. //
  2551. nicReferenceCall ((PVCCB)pChannelVc, "nicAllocateRequestedChannelMakeCallComplete Broadcast VC");
  2552. pAdapter->BCRData.pBroadcastChanneVc = pChannelVc;
  2553. VC_SET_FLAG (pChannelVc, VCBF_BroadcastVc);
  2554. pAdapter->ChannelsAllocatedByLocalHost = pAdapter->ChannelsAllocatedByLocalHost | (g_ullOne<<Channel);
  2555. ADAPTER_RELEASE_LOCK (pAdapter);
  2556. NdisStatus = NDIS_STATUS_SUCCESS;
  2557. break;
  2558. }
  2559. if ((signed long)Channel == NIC1394_ANY_CHANNEL )
  2560. {
  2561. TRACE( TL_V, TM_Cm, ( "Requesting Any Channel %x", Channel) );
  2562. fAnyChannel = TRUE;
  2563. Channel = MAX_CHANNEL_NUMBER;
  2564. }
  2565. //
  2566. // Now begin the request to allocate a channel
  2567. //
  2568. if (fAnyChannel == FALSE)
  2569. {
  2570. TRACE( TL_V, TM_Cm, ( "Requesting Channel %x, on remote node ", Channel ) );
  2571. NdisStatus = nicAllocateChannel ( pAdapter,
  2572. Channel,
  2573. NULL);
  2574. }
  2575. else
  2576. {
  2577. //
  2578. // we need to go through all 64 channels.
  2579. //
  2580. do
  2581. {
  2582. NdisStatus = nicAllocateChannel ( pAdapter,
  2583. Channel,
  2584. NULL);
  2585. if (NdisStatus != NDIS_STATUS_SUCCESS)
  2586. {
  2587. if (Channel == 0 )
  2588. {
  2589. //
  2590. // We now need to fail the make call as the user asked for any channel
  2591. // and none are available
  2592. //
  2593. break;
  2594. }
  2595. Channel --;
  2596. }
  2597. else
  2598. {
  2599. //
  2600. // We succeeded in allocating a channel .. break
  2601. //
  2602. break;
  2603. }
  2604. } while (TRUE);
  2605. }
  2606. //
  2607. // Status of Channel allocation. If AnyChannel == TRUE then we need to make sure that
  2608. // a channel was allocated
  2609. //
  2610. if (NdisStatus == NDIS_STATUS_SUCCESS)
  2611. {
  2612. VC_ACQUIRE_LOCK (pChannelVc);
  2613. VC_SET_FLAG( pChannelVc, VCBF_AllocatedChannel);
  2614. pChannelVc->Channel = Channel;
  2615. pChannelVc->Hdr.Nic1394MediaParams.Destination.Channel = Channel;
  2616. //
  2617. // Record the channel number in the adpater structure
  2618. //
  2619. pAdapter->ChannelsAllocatedByLocalHost = pAdapter->ChannelsAllocatedByLocalHost | (g_ullOne<<Channel);
  2620. VC_RELEASE_LOCK (pChannelVc);
  2621. nicReferenceCall ((PVCCB)pChannelVc, "nicAllocateRequestedChannelMakeCallComplete -Allocated Channel");
  2622. }
  2623. else
  2624. {
  2625. //
  2626. // we failed to allocate any channel and are going to fail
  2627. //
  2628. if (fAnyChannel == TRUE)
  2629. {
  2630. Channel = 0xff;
  2631. NdisStatus = NDIS_STATUS_RESOURCES;
  2632. break;
  2633. }
  2634. else
  2635. {
  2636. //
  2637. // If the Call specifically wants the channel to
  2638. // be allocated, we return the correct channel allocate
  2639. // status to it,
  2640. //
  2641. // Otherwise we overwrite and presume that another node may
  2642. // already have allocated the channel
  2643. //
  2644. if (VC_TEST_FLAG (pChannelVc,VCBF_NeedsToAllocateChannel) == FALSE)
  2645. {
  2646. NdisStatus = NDIS_STATUS_SUCCESS;
  2647. }
  2648. else
  2649. {
  2650. ASSERT (!"Failing make call because channel was allocated, Hit 'g'");
  2651. }
  2652. }
  2653. }
  2654. } while (FALSE);
  2655. *pChannel = Channel;
  2656. TRACE( TL_T, TM_Cm, ( "<==nicAllocateRequestedChannelMakeCallComplete Status %x Channel %x", NdisStatus, *pChannel ) );
  2657. return NdisStatus;
  2658. }
  2659. NDIS_STATUS
  2660. nicFindRemoteNodeFromAdapter(
  2661. IN PADAPTERCB pAdapter,
  2662. IN PDEVICE_OBJECT pRemotePdo,
  2663. IN UINT64 UniqueId,
  2664. IN OUT REMOTE_NODE ** ppRemoteNode
  2665. )
  2666. /*++
  2667. Routine Description:
  2668. This routine matches either a Remote Node' pdo OR unique
  2669. Id to the Remote node's on the adapter
  2670. It walks the RemoteNode List in the Adapter Structure
  2671. and tries to find a match for the Unique Id,
  2672. or match the remote Pdo from the adapter's PdoList
  2673. Arguments:
  2674. pAdapter - pAdapter on which to search
  2675. pRemoptePdo - Remote Pdo to find
  2676. UniqueId - Unique Id to find
  2677. ppRemoteNode - Remote Node structure
  2678. Return Value:
  2679. Success if the node is found
  2680. --*/
  2681. {
  2682. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  2683. PLIST_ENTRY pPdoListEntry = NULL;
  2684. PREMOTE_NODE pRemoteNode = NULL;
  2685. BOOLEAN fPdoFound = FALSE;
  2686. STORE_CURRENT_IRQL;
  2687. TRACE( TL_T, TM_Cm, ( "==>nicFindRemoteNodeFromAdapter pAdapter is %x, ,Pdo %x, UniqueId %I64x ", pAdapter, pRemotePdo, UniqueId ) );
  2688. //
  2689. // Validate the parameters
  2690. //
  2691. ASSERT (pAdapter != NULL);
  2692. TRACE( TL_I, TM_Cm, ( " Request to Match UniqueID %I64x or pRemotePdo %x", UniqueId, pRemotePdo) );
  2693. do
  2694. {
  2695. (*ppRemoteNode) = NULL;
  2696. ADAPTER_ACQUIRE_LOCK (pAdapter);
  2697. //
  2698. // Check for empty list
  2699. //
  2700. if (pAdapter->PDOList.Flink == &pAdapter->PDOList)
  2701. {
  2702. ADAPTER_RELEASE_LOCK (pAdapter);
  2703. MATCH_IRQL;
  2704. NdisStatus = NDIS_STATUS_FAILURE;
  2705. (*ppRemoteNode) = NULL;
  2706. TRACE( TL_A, TM_Cm, ( " NO REMOTE NODES PRESENT FAILING MAKE CALL ") );
  2707. break;
  2708. }
  2709. //
  2710. // go through all the Pdo's on the adapter
  2711. //
  2712. for (pPdoListEntry = pAdapter->PDOList.Flink;
  2713. pPdoListEntry!= &pAdapter->PDOList;
  2714. pPdoListEntry = pPdoListEntry->Flink)
  2715. {
  2716. pRemoteNode = CONTAINING_RECORD( pPdoListEntry,
  2717. REMOTE_NODE,
  2718. linkPdo);
  2719. //
  2720. // Check for the two cases, i.e unique Id's match or Pdo's match
  2721. //
  2722. if ( pRemoteNode->UniqueId == UniqueId || pRemoteNode->pPdo == pRemotePdo)
  2723. {
  2724. TRACE( TL_I, TM_Cm, ( " Matched UniqueID or pRemotePdo for Pdo%x",pRemoteNode->pPdo) );
  2725. *ppRemoteNode = pRemoteNode;
  2726. nicReferenceRemoteNode (pRemoteNode, "nicFindRemoteNodeFromAdapter");
  2727. //
  2728. // We ref pRemoteNode to keep it alive once we release the lock.
  2729. // Caller is responsible for derefing pRemoteNode.
  2730. //
  2731. fPdoFound = TRUE;
  2732. NdisStatus = NDIS_STATUS_SUCCESS;
  2733. break;
  2734. }
  2735. else
  2736. {
  2737. TRACE( TL_A, TM_Cm, ( "remote node's Unique ID's %I64x, given UniqueID %I64x ", pRemoteNode->UniqueId, UniqueId ) );
  2738. }
  2739. }
  2740. ADAPTER_RELEASE_LOCK (pAdapter);
  2741. MATCH_IRQL;
  2742. TRACE( TL_V, TM_Cm, ( "Is PdoFound %.2x, RemoteNode at %x ", fPdoFound, &fPdoFound ) );
  2743. if (fPdoFound ==FALSE)
  2744. {
  2745. TRACE( TL_A, TM_Cm, ( "Remote Node was NOT Found: Make Call failed " ) );
  2746. ASSERT ((*ppRemoteNode) == NULL);
  2747. }
  2748. } while (FALSE);
  2749. TRACE( TL_T, TM_Cm, ( "<==nicFindRemoteNodeFromAdapter pPdoBlock %x",(*ppRemoteNode) ) );
  2750. MATCH_IRQL;
  2751. return NdisStatus;
  2752. }
  2753. NDIS_STATUS
  2754. nicCmQueryInformation(
  2755. IN NDIS_HANDLE CallMgrAfContext,
  2756. IN NDIS_HANDLE CallMgrVcContext,
  2757. IN NDIS_HANDLE CallMgrPartyContext,
  2758. IN NDIS_OID Oid,
  2759. IN PVOID InformationBuffer,
  2760. IN ULONG InformationBufferLength,
  2761. OUT PULONG BytesWritten,
  2762. OUT PULONG BytesNeeded
  2763. )
  2764. // Handle QueryInformation requests. Arguments are as for the standard
  2765. // NDIS 'CallMgrQueryInformation' handler except this routine does not
  2766. // count on being serialized with respect to other requests.
  2767. //
  2768. {
  2769. NDIS_STATUS NdisStatus;
  2770. ULONG ulInfo;
  2771. VOID* pInfo;
  2772. ULONG ulInfoLen;
  2773. USHORT usInfo;
  2774. // The next variables are used to setup the data structures that are
  2775. // used to respond to the OIDs they correspond to
  2776. //
  2777. NDIS_CO_LINK_SPEED CoLinkSpeed;
  2778. NIC1394_LOCAL_NODE_INFO LocalNodeInfo;
  2779. NIC1394_VC_INFO VcInfo;
  2780. PVCCB pVc;
  2781. TRACE( TL_T, TM_Cm, ( "==>nicCmQueryInformation %x, Vc %x", Oid, CallMgrVcContext ) );
  2782. // The cases in this switch statement find or create a buffer containing
  2783. // the requested information and point 'pInfo' at it, noting it's length
  2784. // in 'ulInfoLen'. Since many of the OIDs return a ULONG, a 'ulInfo'
  2785. // buffer is set up as the default.
  2786. //
  2787. ulInfo = 0;
  2788. pInfo = &ulInfo;
  2789. ulInfoLen = sizeof (ulInfo);
  2790. NdisStatus = NDIS_STATUS_SUCCESS;
  2791. // Validate the arguments
  2792. //
  2793. pVc = (VCCB* )CallMgrVcContext;
  2794. if (pVc && pVc->Hdr.ulTag != MTAG_VCCB)
  2795. {
  2796. ASSERT( !"Vtag?" );
  2797. return NDIS_STATUS_INVALID_DATA;
  2798. }
  2799. // Perform the request
  2800. //
  2801. switch (Oid)
  2802. {
  2803. case OID_1394_VC_INFO:
  2804. {
  2805. // Returns information about the VC that is being queried
  2806. //
  2807. TRACE( TL_N, TM_Mp, ("QInfo(OID_1394_VC_INFO)") );
  2808. VcInfo.Destination = pVc->Hdr.Nic1394MediaParams.Destination;
  2809. pInfo = &VcInfo;
  2810. ulInfoLen = sizeof (VcInfo);
  2811. break;
  2812. }
  2813. case OID_1394_ISSUE_BUS_RESET:
  2814. {
  2815. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  2816. TRACE( TL_V, TM_Mp, ( " OID_1394_ISSUE_BUS_RESET" ) );
  2817. if (InformationBufferLength == sizeof(ULONG))
  2818. {
  2819. nicIssueBusReset (pAdapter, (*(PULONG)InformationBuffer));
  2820. }
  2821. else
  2822. {
  2823. nicIssueBusReset (pAdapter, BUS_RESET_FLAGS_FORCE_ROOT );
  2824. }
  2825. break;
  2826. }
  2827. default:
  2828. {
  2829. TRACE( TL_A, TM_Cm, ( "Q-OID=$%08x?", Oid ) );
  2830. NdisStatus = NDIS_STATUS_NOT_SUPPORTED;
  2831. ulInfoLen = 0;
  2832. break;
  2833. }
  2834. }
  2835. if (ulInfoLen > InformationBufferLength)
  2836. {
  2837. // Caller's buffer is too small. Tell him what he needs.
  2838. //
  2839. *BytesNeeded = ulInfoLen;
  2840. *BytesWritten = 0;
  2841. NdisStatus = NDIS_STATUS_INVALID_LENGTH;
  2842. }
  2843. else
  2844. {
  2845. // Copy the found result to caller's buffer.
  2846. //
  2847. if (ulInfoLen > 0)
  2848. {
  2849. NdisMoveMemory (InformationBuffer, pInfo, ulInfoLen );
  2850. DUMPDW( TL_N, TM_Mp, pInfo, ulInfoLen );
  2851. }
  2852. *BytesNeeded = *BytesWritten = ulInfoLen;
  2853. }
  2854. TRACE( TL_T, TM_Cm, ( "<==nicCmQueryInformation %x",NdisStatus ) );
  2855. return NdisStatus;
  2856. }
  2857. NDIS_STATUS
  2858. nicCmSetInformation(
  2859. IN NDIS_HANDLE CallMgrAfContext,
  2860. IN NDIS_HANDLE CallMgrVcContext,
  2861. IN NDIS_HANDLE CallMgrPartyContext,
  2862. IN NDIS_OID Oid,
  2863. IN PVOID InformationBuffer,
  2864. IN ULONG InformationBufferLength,
  2865. OUT PULONG BytesRead,
  2866. OUT PULONG BytesNeeded
  2867. )
  2868. //
  2869. // Not implemented yet. Will be used to set information
  2870. //
  2871. {
  2872. NDIS_STATUS NdisStatus = NDIS_STATUS_NOT_SUPPORTED;
  2873. PVCCB pVc;
  2874. TRACE( TL_T, TM_Cm, ( "==>NicCmMakeCallInitVc Oid %x",Oid ) );
  2875. // Validate the arguments
  2876. //
  2877. pVc = (VCCB* )CallMgrVcContext;
  2878. if (pVc->Hdr.ulTag != MTAG_VCCB)
  2879. {
  2880. return NDIS_STATUS_FAILURE;
  2881. }
  2882. switch (Oid)
  2883. {
  2884. case OID_1394_CHANGE_CHANNEL_CHARACTERISTICS :
  2885. {
  2886. PNIC1394_CHANNEL_CHARACTERISTICS pMcChar = NULL;
  2887. ULONG Channel = 0;
  2888. UINT64 ChannelMap = 0;
  2889. ULONG i = 0;
  2890. if (InformationBufferLength != sizeof (PNIC1394_CHANNEL_CHARACTERISTICS) )
  2891. {
  2892. NdisStatus = NDIS_STATUS_INVALID_DATA;
  2893. break;
  2894. }
  2895. pMcChar = (PNIC1394_CHANNEL_CHARACTERISTICS )InformationBuffer;
  2896. nicChangeChannelChar (pVc ,
  2897. pMcChar);
  2898. }
  2899. case OID_1394_ISSUE_BUS_RESET:
  2900. {
  2901. PADAPTERCB pAdapter = pVc->Hdr.pAF->pAdapter;
  2902. TRACE( TL_V, TM_Mp, ( " OID_1394_ISSUE_BUS_RESET" ) );
  2903. if (InformationBufferLength == sizeof(ULONG))
  2904. {
  2905. nicIssueBusReset (pAdapter, (*(PULONG)InformationBuffer));
  2906. }
  2907. else
  2908. {
  2909. nicIssueBusReset (pAdapter, BUS_RESET_FLAGS_FORCE_ROOT );
  2910. }
  2911. break;
  2912. }
  2913. }
  2914. TRACE( TL_T, TM_Cm, ( "<==NicCmMakeCallInitVc %x",NdisStatus ) );
  2915. return NDIS_STATUS_FAILURE;
  2916. }
  2917. UINT
  2918. nicNumOfActiveRemoteNodes(
  2919. IN PADAPTERCB pAdapter
  2920. )
  2921. // Function Description:
  2922. //
  2923. // This returns the number of active Remote Nodes on an Adapter block
  2924. //
  2925. // Arguments
  2926. // pAdapter - Adapter structure on which the remote nodes exist
  2927. //
  2928. // Return Value:
  2929. // Num Of Active Nodes on the current adapter
  2930. //
  2931. // Called with the lock held
  2932. {
  2933. UINT NumRemoteNodes = 0;
  2934. PLIST_ENTRY pPdoListEntry;
  2935. REMOTE_NODE *pRemoteNode = NULL;
  2936. TRACE( TL_T, TM_Cm, ( "==>nicNumOfActiveRemoteNodes Adapter %x",pAdapter) );
  2937. pPdoListEntry = ListNext(&pAdapter->PDOList);
  2938. while (pPdoListEntry != &pAdapter->PDOList)
  2939. {
  2940. pRemoteNode = CONTAINING_RECORD (pPdoListEntry, REMOTE_NODE, linkPdo);
  2941. if (REMOTE_NODE_ACTIVE (pRemoteNode))
  2942. {
  2943. NdisInterlockedIncrement (&NumRemoteNodes);
  2944. }
  2945. pPdoListEntry = ListNext (pPdoListEntry);
  2946. }
  2947. TRACE( TL_T, TM_Cm, ( "<==nicNumOfActiveRemoteNodes Num %d" , NumRemoteNodes) );
  2948. return NumRemoteNodes;
  2949. }
  2950. NDIS_STATUS
  2951. nicGetActiveRemoteNode (
  2952. PADAPTERCB pAdapter,
  2953. PREMOTE_NODE* ppRemoteNode
  2954. )
  2955. // Function Description:
  2956. //
  2957. // This returns the first active Remote Node on an Adapter block
  2958. //
  2959. // Arguments
  2960. // pAdapter - Adapter structure on which the remote nodes exist
  2961. //
  2962. // Return Value:
  2963. // Succes if it finds an active remote node
  2964. //
  2965. // Called with the lock held.
  2966. {
  2967. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  2968. PLIST_ENTRY pPdoListEntry = NULL;
  2969. TRACE( TL_T, TM_Cm, ( "==>nicGetActiveRemoteNode Adapter %x",pAdapter) );
  2970. //
  2971. // Search the linked list to find an active node.
  2972. //
  2973. pPdoListEntry = pAdapter->PDOList.Flink ;
  2974. while (pPdoListEntry != &pAdapter->PDOList )
  2975. {
  2976. *ppRemoteNode = CONTAINING_RECORD (pPdoListEntry,
  2977. REMOTE_NODE,
  2978. linkPdo);
  2979. if (REMOTE_NODE_ACTIVE(*ppRemoteNode) )
  2980. {
  2981. TRACE( TL_V, TM_Cm, ( " Active Remote Node at %x", *ppRemoteNode) );
  2982. NdisStatus = NDIS_STATUS_SUCCESS;
  2983. break;
  2984. }
  2985. else
  2986. {
  2987. *ppRemoteNode = NULL;
  2988. }
  2989. pPdoListEntry = pPdoListEntry->Flink;
  2990. }
  2991. TRACE( TL_T, TM_Cm, ( "==>nicGetActiveRemoteNode Status %x, RemoteNodePdoCb %x",
  2992. NdisStatus, *ppRemoteNode) );
  2993. return NdisStatus;
  2994. }
  2995. NDIS_STATUS
  2996. nicInitRecvFifoDataStructures (
  2997. IN PRECVFIFO_VCCB pRecvFIFOVc
  2998. )
  2999. // Function Description:
  3000. // This function will initialize the data structures, buffers etc that are needed on
  3001. // all the allocate address range Irps that will be called because of the RecvFifo Vc
  3002. //
  3003. // Arguments
  3004. // pRecvFIFOVc - RecvFifo Vc structure
  3005. //
  3006. // Return Value:
  3007. // SUCCESS: If all the values are initiaized successfully
  3008. // Appropriate error code otherwise
  3009. {
  3010. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  3011. NDIS_HANDLE PacketPoolHandle = NULL;
  3012. PSLIST_HEADER pSlistHead = NULL;
  3013. extern UINT NumRecvFifos ;
  3014. UINT AllocateNumBuffers = NumRecvFifos;
  3015. NIC_PACKET_POOL PacketPool;
  3016. TRACE( TL_T, TM_Cm, ( "==> nicInitRecvFifoDataStructures pVc %x",pRecvFIFOVc ) );
  3017. do
  3018. {
  3019. PacketPool.Handle = NULL;
  3020. //
  3021. // Initialize the PacketPool
  3022. //
  3023. NdisAllocatePacketPoolEx ( &NdisStatus,
  3024. &PacketPool.Handle,
  3025. MIN_PACKET_POOL_SIZE,
  3026. MAX_PACKET_POOL_SIZE - MIN_PACKET_POOL_SIZE,
  3027. sizeof (RSVD) );
  3028. if (NdisStatus!= NDIS_STATUS_SUCCESS)
  3029. {
  3030. ASSERT(NdisStatus != NDIS_STATUS_SUCCESS);
  3031. pRecvFIFOVc->PacketPool.Handle = NULL;
  3032. break;
  3033. }
  3034. //
  3035. // Do not acquire the lock as we cannot have two make
  3036. // calls for the same Vc at the same time
  3037. //
  3038. //
  3039. // Create an S-list and intialize its structures
  3040. //
  3041. ExInitializeSListHead (&pRecvFIFOVc->FifoSListHead);
  3042. KeInitializeSpinLock (&pRecvFIFOVc->FifoSListSpinLock);
  3043. pRecvFIFOVc->Hdr.MTU = pRecvFIFOVc->Hdr.Nic1394MediaParams.MTU ;
  3044. TRACE( TL_I, TM_Cm, ( " Recv FIFO MTU is %d ", pRecvFIFOVc->Hdr.MTU ) );
  3045. ASSERT (pRecvFIFOVc->Hdr.MTU >= 512);
  3046. //
  3047. // Now, fill the Slist with buffers. This will be common to
  3048. // all the allocated address ranges on all RecvFifoVcs
  3049. //
  3050. NdisStatus = nicFillAllocateAddressRangeSList (pRecvFIFOVc, &AllocateNumBuffers);
  3051. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3052. {
  3053. //
  3054. // nicFillAllocateAddressRangeSlist does its own clean up
  3055. // but we should free the Packet Pool Allocated above
  3056. //
  3057. if (PacketPool.Handle != NULL)
  3058. {
  3059. nicFreePacketPool (&PacketPool);
  3060. }
  3061. break;
  3062. }
  3063. ASSERT(AllocateNumBuffers == NumRecvFifos );
  3064. pRecvFIFOVc->PacketPool= PacketPool;
  3065. pRecvFIFOVc->PacketPool.AllocatedPackets = 0;
  3066. pRecvFIFOVc->NumAllocatedFifos = AllocateNumBuffers ;
  3067. KeInitializeSpinLock (&pRecvFIFOVc->PacketPool.Lock);
  3068. TRACE( TL_V, TM_Cm, ( "PacketPool allocated at %x", PacketPool.Handle) );
  3069. } while (FALSE);
  3070. TRACE( TL_T, TM_Cm, ( "<== nicInitRecvFifoDataStructures Status %x", NdisStatus ) );
  3071. return NdisStatus;
  3072. }
  3073. VOID
  3074. nicUnInitRecvFifoDataStructures (
  3075. IN PRECVFIFO_VCCB pRecvFIFOVc
  3076. )
  3077. /*++
  3078. Routine Description:
  3079. Frees all the resources that were allocated in nicInitRecvFifoDataStructures
  3080. Arguments:
  3081. Return Value:
  3082. --*/
  3083. {
  3084. if (pRecvFIFOVc->PacketPool.Handle != NULL)
  3085. {
  3086. ASSERT (pRecvFIFOVc->PacketPool.AllocatedPackets == 0);
  3087. nicFreePacketPool (&pRecvFIFOVc->PacketPool);
  3088. }
  3089. pRecvFIFOVc->PacketPool.Handle = NULL;
  3090. if (pRecvFIFOVc->FifoSListHead.Alignment != 0)
  3091. {
  3092. nicFreeAllocateAddressRangeSList(pRecvFIFOVc);
  3093. ASSERT (pRecvFIFOVc->FifoSListHead.Alignment == 0)
  3094. }
  3095. pRecvFIFOVc->FifoSListHead.Alignment = 0;
  3096. }
  3097. ULONG
  3098. nicGetMaxPayLoadForSpeed(
  3099. IN ULONG Speed,
  3100. IN ULONG mtu
  3101. )
  3102. // Function Description:
  3103. // The purpose is to map a speed to the max payload that
  3104. // can be delivered at that speed . this is limited by the Bytes PerFrameAvailable
  3105. //
  3106. // Arguments
  3107. // Speed - the speed supported by the Bus driver or the Max speed between devices
  3108. // BytesPerFrameAvailable Bytes per frame available on the bus.
  3109. //
  3110. //
  3111. // Return Value:
  3112. // Minimin of the Size determined by the payload and the size determined by the
  3113. // byte per frame available.
  3114. {
  3115. ULONG maxIsochPayload = ISOCH_PAYLOAD_400_RATE;
  3116. TRACE( TL_T, TM_Cm, ( "<==nicGetMaxPayLoadForSpeed %x", Speed ) );
  3117. switch (Speed)
  3118. {
  3119. case SPEED_FLAGS_100:
  3120. maxIsochPayload = ISOCH_PAYLOAD_100_RATE;
  3121. break;
  3122. case SPEED_FLAGS_200:
  3123. maxIsochPayload = ISOCH_PAYLOAD_200_RATE;
  3124. break;
  3125. case SPEED_FLAGS_400:
  3126. maxIsochPayload = ISOCH_PAYLOAD_400_RATE;
  3127. break;
  3128. case SPEED_FLAGS_800:
  3129. maxIsochPayload = ISOCH_PAYLOAD_800_RATE;
  3130. break;
  3131. case SPEED_FLAGS_1600:
  3132. maxIsochPayload = ISOCH_PAYLOAD_1600_RATE;
  3133. break;
  3134. default :
  3135. TRACE( TL_A, TM_Cm, ( "Invalid Speed %x", Speed ) );
  3136. ASSERT (Speed < SPEED_FLAGS_1600);
  3137. maxIsochPayload = ISOCH_PAYLOAD_1600_RATE;
  3138. break;
  3139. }
  3140. if (maxIsochPayload > mtu)
  3141. {
  3142. maxIsochPayload = mtu;
  3143. }
  3144. TRACE( TL_T, TM_Cm, ( "<==nicGetMaxPayLoadForSpeed, payload %x", maxIsochPayload ) );
  3145. return maxIsochPayload;
  3146. }
  3147. //---------------------------------------------------------------------------------
  3148. // SAP function - all of them return failure
  3149. //-------------------------------------------------------------------------------
  3150. NDIS_STATUS
  3151. nicRegisterSapHandler(
  3152. IN NDIS_HANDLE CallMgrAfContext,
  3153. IN PCO_SAP Sap,
  3154. IN NDIS_HANDLE NdisSapHandle,
  3155. OUT PNDIS_HANDLE CallMgrSapContext
  3156. )
  3157. {
  3158. *CallMgrSapContext = NULL;
  3159. return NDIS_STATUS_FAILURE;
  3160. }
  3161. NDIS_STATUS
  3162. nicDeregisterSapHandler(
  3163. IN NDIS_HANDLE CallMgrSapContext
  3164. )
  3165. {
  3166. return NDIS_STATUS_FAILURE;
  3167. }
  3168. NDIS_STATUS
  3169. nicCmDropPartyHandler(
  3170. IN NDIS_HANDLE CallMgrPartyContext,
  3171. IN PVOID CloseData OPTIONAL,
  3172. IN UINT Size OPTIONAL
  3173. )
  3174. {
  3175. return NDIS_STATUS_FAILURE;
  3176. }
  3177. NDIS_STATUS
  3178. nicCmAddPartyHandler(
  3179. IN NDIS_HANDLE CallMgrVcContext,
  3180. IN OUT PCO_CALL_PARAMETERS CallParameters,
  3181. IN NDIS_HANDLE NdisPartyHandle,
  3182. OUT PNDIS_HANDLE CallMgrPartyContext
  3183. )
  3184. {
  3185. *CallMgrPartyContext = NULL;
  3186. return NDIS_STATUS_FAILURE;
  3187. }
  3188. NDIS_STATUS
  3189. nicAllocateChannelResourcesAndListen (
  3190. IN PADAPTERCB pAdapter,
  3191. IN PCHANNEL_VCCB pChannelVc
  3192. )
  3193. // Function Description:
  3194. // This function isolated the reource and channel allocation portion
  3195. // of initializing a MakeCall. This lets us do the same work when the
  3196. // AddRemoteNode code path is hit and there is an existing Channel Vc
  3197. //
  3198. // Arguments
  3199. // pChannelVc, This is the send fifo that needs to be initilaized
  3200. //
  3201. // Return Value:
  3202. //
  3203. // Success if the irps sent to the driver succeed
  3204. //
  3205. //
  3206. {
  3207. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  3208. PDEVICE_OBJECT ArrayRemotePDO[64];
  3209. ULONG Channel = INVALID_CHANNEL;
  3210. ULONG Speed;
  3211. PNIC1394_MEDIA_PARAMETERS pN1394Params;
  3212. ULONG NumDescriptors = MAX_NUM_ISOCH_DESCRIPTOR;
  3213. PISOCH_DESCRIPTOR pIsochDescriptor = NULL;
  3214. ULONG MaxBufferSize;
  3215. ULONG MaxBytesPerFrame;
  3216. HANDLE hResource;
  3217. CYCLE_TIME CycleTime;
  3218. ULARGE_INTEGER uliChannelMap;
  3219. ULONG ResourceFlags = 0;
  3220. ULONG State = 0;
  3221. BOOLEAN fBroadcastVc = FALSE;
  3222. BOOLEAN fChannelAllocate = FALSE;
  3223. BOOLEAN fIsMultiChannel = FALSE;
  3224. enum
  3225. {
  3226. StartState,
  3227. AllocatedResources,
  3228. AllocatedBuffers,
  3229. AttachedBuffers,
  3230. IsochListen
  3231. };
  3232. STORE_CURRENT_IRQL;
  3233. TRACE( TL_T, TM_Cm, ( "==> nicAllocateChannelResourcesAndListen pAdapter %x, pChannelVc %x ",
  3234. pAdapter,pChannelVc ) );
  3235. State = StartState;
  3236. pN1394Params = (PNIC1394_MEDIA_PARAMETERS)&pChannelVc->Hdr.Nic1394MediaParams;
  3237. //
  3238. // Use the original request to figure out which channel needs to be allocated
  3239. //
  3240. fIsMultiChannel = (pN1394Params->Destination.AddressType == NIC1394AddressType_MultiChannel);
  3241. if (fIsMultiChannel == FALSE)
  3242. {
  3243. Channel = pN1394Params->Destination.Channel;
  3244. }
  3245. do
  3246. {
  3247. if (pAdapter == NULL)
  3248. {
  3249. BREAK (TM_Cm, ("nicAllocateChannelResourcesAndListen : pAdapter == NULL ") );
  3250. }
  3251. //
  3252. // Get the max payload that is possible for isoch receives
  3253. //
  3254. if (pAdapter->Speed == 0)
  3255. {
  3256. nicUpdateLocalHostSpeed (pAdapter);
  3257. }
  3258. Speed = pAdapter->Speed;
  3259. switch (Speed)
  3260. {
  3261. case SPEED_FLAGS_100 :
  3262. {
  3263. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_100_RATE;
  3264. break;
  3265. }
  3266. case SPEED_FLAGS_200 :
  3267. {
  3268. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_200_RATE ;
  3269. break;
  3270. }
  3271. case SPEED_FLAGS_400 :
  3272. {
  3273. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  3274. break;
  3275. }
  3276. case SPEED_FLAGS_800 :
  3277. {
  3278. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  3279. break;
  3280. }
  3281. case SPEED_FLAGS_1600 :
  3282. {
  3283. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  3284. break;
  3285. }
  3286. case SPEED_FLAGS_3200 :
  3287. {
  3288. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  3289. break;
  3290. }
  3291. default :
  3292. {
  3293. ASSERT (Speed <= SPEED_FLAGS_3200 && Speed != 0 );
  3294. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_400_RATE;
  3295. break;
  3296. }
  3297. }
  3298. //
  3299. // If the make call wants the channel to allocate we try and allocate the channel,
  3300. // In the Multichannel case, we do not allocate the channel (as this is
  3301. // for listening purposes only )
  3302. //
  3303. fBroadcastVc = (Channel == NIC1394_BROADCAST_CHANNEL);
  3304. fChannelAllocate = VC_TEST_FLAG (pChannelVc,VCBF_NeedsToAllocateChannel);
  3305. if (fChannelAllocate || fBroadcastVc )
  3306. {
  3307. ASSERT (pChannelVc->Hdr.VcType != NIC1394_MultiChannel);
  3308. NdisStatus = nicAllocateRequestedChannelMakeCallComplete( pAdapter,
  3309. pChannelVc,
  3310. &Channel );
  3311. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3312. {
  3313. BREAK( TM_Cm, ( " nicAllocateChannelResourcesAndListen : nicAllocateRequestedChannelMakeCallComplete FAILED") );
  3314. }
  3315. TRACE( TL_I, TM_Cm, ( "Using Channel %x, on remote node ", Channel ) );
  3316. ASSERT (Channel < 64);
  3317. ResourceFlags = 0;
  3318. uliChannelMap.QuadPart = 0;
  3319. }
  3320. else
  3321. {
  3322. //
  3323. // Multichannels - no allocation just update the ullChannelMap
  3324. //
  3325. uliChannelMap = pChannelVc->uliChannelMap;
  3326. if (fIsMultiChannel == TRUE)
  3327. {
  3328. ResourceFlags = RESOURCE_USE_MULTICHANNEL;
  3329. }
  3330. else
  3331. {
  3332. pChannelVc->Channel = Channel ;
  3333. }
  3334. }
  3335. MaxBufferSize = min(pN1394Params->MTU + sizeof(GASP_HEADER) , pChannelVc->Hdr.MaxPayload);
  3336. MaxBytesPerFrame = MaxBufferSize;
  3337. TRACE( TL_V, TM_Cm, ( " MAxBufferSize %x, MaxBytesPerFrame %x", MaxBufferSize, MaxBytesPerFrame ) );
  3338. //
  3339. // Add the flags used for resources allocation
  3340. //
  3341. ResourceFlags |= (RESOURCE_USED_IN_LISTENING | RESOURCE_USE_PACKET_BASED | RESOURCE_BUFFERS_CIRCULAR);
  3342. //
  3343. // MaxBufferSize should be an integral mutiple of MaxBytesPerFram
  3344. //
  3345. ASSERT (MaxBufferSize % MaxBytesPerFrame == 0);
  3346. //
  3347. // Noe allocate the resource
  3348. //
  3349. NdisStatus = nicIsochAllocateResources( pAdapter,
  3350. Speed,
  3351. ResourceFlags,
  3352. Channel,
  3353. MaxBytesPerFrame,
  3354. NumDescriptors,
  3355. MaxBufferSize,
  3356. 0, //QuadletsToStrip,
  3357. uliChannelMap,
  3358. &hResource);
  3359. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3360. {
  3361. hResource = NULL;
  3362. BREAK(TM_Cm, ( "Allocate Resources Failed. Make Call failed ") );
  3363. }
  3364. State = AllocatedResources;
  3365. ASSERT (NumDescriptors != 0);
  3366. ASSERT (pChannelVc->Hdr.MTU != 0);
  3367. //
  3368. // Get Isoch Descriptors that will be submitted to the Bus drivers
  3369. //
  3370. //
  3371. // Add room for the Isoch Header and Isoch prefix
  3372. //
  3373. MaxBufferSize += ISOCH_PREFIX_LENGTH ;
  3374. NdisStatus = nicAllocateAndInitializeIsochDescriptors (pChannelVc,
  3375. NumDescriptors,
  3376. MaxBufferSize,
  3377. &pIsochDescriptor );
  3378. if(NdisStatus != NDIS_STATUS_SUCCESS)
  3379. {
  3380. BREAK (TM_Cm, (" nicAllocateAndInitializeIsochDescriptors failed, Make Call Failed") );
  3381. }
  3382. ASSERT (pIsochDescriptor != NULL);
  3383. State = AllocatedBuffers;
  3384. NdisStatus = nicIsochAttachBuffers( pAdapter,
  3385. hResource,
  3386. NumDescriptors,
  3387. pIsochDescriptor);
  3388. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3389. {
  3390. BREAK (TM_Cm, "nicIsochAttachBuffers FAILED");
  3391. }
  3392. State = AttachedBuffers;
  3393. //
  3394. // Start the Listen
  3395. //
  3396. NdisZeroMemory (&CycleTime, sizeof(CycleTime));
  3397. NdisStatus = nicIsochListen (pAdapter,
  3398. hResource,
  3399. 0,
  3400. CycleTime ); // Cycle Time is Zero
  3401. //
  3402. // Update the Vc structure, because we have now succeeded
  3403. //
  3404. State = IsochListen;
  3405. VC_ACQUIRE_LOCK (pChannelVc);
  3406. //
  3407. // If broadcast channel, then decrease the speed setting, and fragment
  3408. //
  3409. if (Channel == NIC1394_BROADCAST_CHANNEL)
  3410. {
  3411. Speed = SPEED_FLAGS_200 ;
  3412. pChannelVc->Hdr.MaxPayload = ISOCH_PAYLOAD_200_RATE ;
  3413. }
  3414. pChannelVc->Channel = Channel;
  3415. pChannelVc->MaxBufferSize = MaxBufferSize - ISOCH_PREFIX_LENGTH;
  3416. pChannelVc->Speed = Speed;
  3417. pChannelVc->hResource = hResource;
  3418. //
  3419. // Reference Call for allocated resource handle
  3420. //
  3421. nicReferenceCall ( (PVCCB) pChannelVc, "nicAllocateRequestedChannelMakeCallComplete - allocate resources ");
  3422. pChannelVc->NumDescriptors = NumDescriptors;
  3423. pChannelVc->pIsochDescriptor = pIsochDescriptor;
  3424. //
  3425. // Reference the call because we will now need to detach buffers
  3426. //
  3427. nicReferenceCall ( (PVCCB) pChannelVc, "nicAllocateRequestedChannelMakeCallComplete - Attach Buffers");
  3428. //
  3429. // We have succeded in allocating all resources.
  3430. // If the Freed Resources flag is set it needs to be cleared
  3431. //
  3432. VC_CLEAR_FLAGS (pChannelVc, VCBF_FreedResources);
  3433. VC_RELEASE_LOCK (pChannelVc);
  3434. //
  3435. // No more failures
  3436. //
  3437. } while (FALSE);
  3438. //
  3439. // Time to do clean up based on what resources were allocated.
  3440. // There are no failures after the point where the refs for
  3441. // Allocate Resources and Attach Buffers are added, so
  3442. // No Derefs in the following code except in ( FreeIsochDesc)
  3443. //
  3444. if (NdisStatus != NDIS_STATUS_SUCCESS )
  3445. {
  3446. BOOLEAN fAllocatedChannel = FALSE;
  3447. switch (State)
  3448. {
  3449. case IsochListen:
  3450. {
  3451. nicIsochStop(pAdapter, hResource);
  3452. FALL_THROUGH
  3453. }
  3454. case AttachedBuffers:
  3455. {
  3456. nicIsochDetachBuffers( pAdapter,
  3457. hResource,
  3458. NumDescriptors,
  3459. pIsochDescriptor );
  3460. FALL_THROUGH;
  3461. }
  3462. case AllocatedBuffers:
  3463. {
  3464. //
  3465. // Free the isoch Buffers and Descriptors that were
  3466. // allocated
  3467. //
  3468. nicFreeIsochDescriptors(NumDescriptors,
  3469. pIsochDescriptor,
  3470. (PVCCB) pChannelVc);
  3471. FALL_THROUGH
  3472. }
  3473. case AllocatedResources:
  3474. {
  3475. //
  3476. // Free the Isoch Resources Handle
  3477. //
  3478. nicIsochFreeResources (pAdapter, hResource);
  3479. FALL_THROUGH
  3480. }
  3481. case StartState:
  3482. {
  3483. FALL_THROUGH
  3484. }
  3485. default:
  3486. {
  3487. break;
  3488. }
  3489. }
  3490. VC_ACQUIRE_LOCK (pChannelVc);
  3491. //
  3492. // Update Flags in the VC structure
  3493. //
  3494. VC_SET_FLAG (pChannelVc, VCBF_FreedResources);
  3495. fAllocatedChannel = VC_TEST_FLAGS( pChannelVc, VCBF_AllocatedChannel);
  3496. //
  3497. // Do we need to free a channel as well
  3498. //
  3499. if (fAllocatedChannel == TRUE)
  3500. {
  3501. Channel = pChannelVc->Channel;
  3502. pChannelVc->Channel = INVALID_CHANNEL;
  3503. nicDereferenceCall ((PVCCB) pChannelVc, "Free Allocated Channel");
  3504. }
  3505. VC_RELEASE_LOCK (pChannelVc);
  3506. if (fAllocatedChannel)
  3507. {
  3508. nicFreeChannel (pAdapter, pChannelVc->Channel);
  3509. }
  3510. } // end of failure code path
  3511. TRACE( TL_T, TM_Cm, ( "<== nicAllocateChannelResourcesAndListen NdisStatus %x ",NdisStatus) );
  3512. MATCH_IRQL;
  3513. return NdisStatus;
  3514. }
  3515. NDIS_STATUS
  3516. nicQueryRemoteNodeCaps (
  3517. IN PADAPTERCB pAdapter,
  3518. IN PREMOTE_NODE pRemoteNode,
  3519. OUT PULONG pSpeedTo,
  3520. OUT PULONG pMaxBufferSize,
  3521. OUT PULONG pMaxRec
  3522. )
  3523. /*++
  3524. Routine Description:
  3525. Queries the remote Node for speed and max size
  3526. Arguments:
  3527. pSpeedTo -- max speed to the remote node. From nodes config rom.
  3528. in units of SCODE_XXX_RATE.
  3529. pMaxBufferSize -- max buffer size to use ( this is the min of local,
  3530. remote and max allowed by *pSpeedTo).
  3531. pMaxRec -- maxrec of the remote node -- from the node's config
  3532. rom.
  3533. Return Value:
  3534. --*/
  3535. {
  3536. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  3537. ULONG Speed = 0; // Speed in units of SPEED_FLAG_XXX
  3538. ULONG MaxBufferSize;
  3539. PVOID pCRom = NULL;
  3540. PCONFIG_ROM pBusInfo = NULL;
  3541. ULONG SpeedMaxRec = 0;
  3542. ULONG MaxRec= 0;
  3543. ULONG MinMaxRec= 0;
  3544. TRACE( TL_T, TM_Cm, ( "==> nicQueryRemoteNodeCaps pRemoteNode%x ",pRemoteNode) );
  3545. do
  3546. {
  3547. ASSERT (KeGetCurrentIrql()==PASSIVE_LEVEL);
  3548. ADAPTER_ACQUIRE_LOCK (pAdapter);
  3549. if (REMOTE_NODE_ACTIVE (pRemoteNode) == FALSE)
  3550. {
  3551. NdisStatus = NDIS_STATUS_DEST_OUT_OF_ORDER;
  3552. ADAPTER_RELEASE_LOCK (pAdapter);
  3553. break;
  3554. }
  3555. ADAPTER_RELEASE_LOCK (pAdapter);
  3556. NdisStatus = nicGetMaxSpeedBetweenDevices (pAdapter,
  3557. 1 ,
  3558. &pRemoteNode->pPdo,
  3559. &Speed);
  3560. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3561. {
  3562. BREAK (TM_Cm, (" nicQueryRemoteNodeCaps : nicGetMaxSpeedBetweenDevices FAILED") );
  3563. }
  3564. TRACE( TL_V, TM_Cm, ( "nicGetMaxSpeedBetweenDevices Speed %x ",Speed) );
  3565. //
  3566. // This is the MaxRec from the Actual speed of
  3567. // the link.
  3568. //
  3569. SpeedMaxRec = nicGetMaxRecFromSpeed(Speed);
  3570. //
  3571. // Now get the max rec from the config rom
  3572. //
  3573. NdisStatus = nicGetConfigRom (pRemoteNode->pPdo, &pCRom);
  3574. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3575. {
  3576. BREAK (TM_Cm, (" nicQueryRemoteNodeCaps : nicGetMaxSpeedBetweenDevices FAILED") );
  3577. }
  3578. //
  3579. // Now extract the bus info, and get the remoteNode's MaxRec
  3580. // The max rec is a 4-bit field at location 0x0000f000.
  3581. // See for example Figure 11-3: Format of the Bus_Info_Block in
  3582. // the Mind Share Inc's FireWire System Architecture book.
  3583. //
  3584. //
  3585. pBusInfo = (PCONFIG_ROM) pCRom;
  3586. MaxRec = SWAPBYTES_ULONG (pBusInfo->CR_BusInfoBlockCaps);
  3587. MaxRec &= 0xf000;
  3588. MaxRec = MaxRec >> 12;
  3589. //
  3590. // Take the minimum of the adapter, the remote node
  3591. // and the link's maxRec
  3592. //
  3593. MinMaxRec = min (MaxRec, pAdapter->MaxRec);
  3594. MinMaxRec = min (MinMaxRec, SpeedMaxRec);
  3595. switch (MinMaxRec)
  3596. {
  3597. case MAX_REC_100_RATE:
  3598. {
  3599. MaxBufferSize = ASYNC_PAYLOAD_100_RATE ;
  3600. break;
  3601. }
  3602. case MAX_REC_200_RATE:
  3603. {
  3604. MaxBufferSize = ASYNC_PAYLOAD_200_RATE;
  3605. break;
  3606. }
  3607. case MAX_REC_400_RATE :
  3608. {
  3609. MaxBufferSize = ASYNC_PAYLOAD_400_RATE;
  3610. break;
  3611. }
  3612. default:
  3613. {
  3614. //
  3615. // Use the 400 size for all larger payloads.
  3616. //
  3617. MaxBufferSize = ASYNC_PAYLOAD_400_RATE;
  3618. break;
  3619. }
  3620. }
  3621. TRACE( TL_N, TM_Cm, (" MaxRec %x\n", MaxRec ) );
  3622. } while (FALSE);
  3623. if (NdisStatus == NDIS_STATUS_SUCCESS)
  3624. {
  3625. Speed = nicSpeedFlagsToSCode(Speed);
  3626. *pSpeedTo = Speed;
  3627. *pMaxBufferSize = MaxBufferSize;
  3628. *pMaxRec = MaxRec;
  3629. // Update the remote node's cached caps.
  3630. //
  3631. REMOTE_NODE_ACQUIRE_LOCK (pRemoteNode);
  3632. pRemoteNode->CachedCaps.SpeedTo = Speed;
  3633. pRemoteNode->CachedCaps.EffectiveMaxBufferSize = MaxBufferSize;
  3634. pRemoteNode->CachedCaps.MaxRec = MaxRec;
  3635. REMOTE_NODE_RELEASE_LOCK (pRemoteNode);
  3636. }
  3637. if (pCRom != NULL)
  3638. {
  3639. FREE_NONPAGED (pCRom);
  3640. }
  3641. TRACE( TL_T, TM_Cm, ( "<== nicQueryRemoteNodeCaps pRemoteNode%x , NdisStatus %x",pRemoteNode, NdisStatus) );
  3642. return NdisStatus;
  3643. }
  3644. NDIS_STATUS
  3645. nicChangeChannelChar (
  3646. PVCCB pVc,
  3647. PNIC1394_CHANNEL_CHARACTERISTICS pMcChar
  3648. )
  3649. /*++
  3650. Routine Description:
  3651. If a channel has been allocated it sends Isoch Modify Irp Down to the bus driver
  3652. else
  3653. it sets up the call parameters and calls the AllocateResourcesAndListen function:
  3654. This is called through an Ndis Request which is gauranteed to be serialized. this function is not re-entrant
  3655. Return Value:
  3656. Success - if all operations succeed
  3657. --*/
  3658. {
  3659. NDIS_STATUS NdisStatus = NDIS_STATUS_FAILURE;
  3660. PCHANNEL_VCCB pMcVc = (PCHANNEL_VCCB) pVc;
  3661. BOOLEAN fVcActive = TRUE;
  3662. ULONG AllocatedChannel = 0xff;
  3663. ULARGE_INTEGER uliPrevMap ;
  3664. ULARGE_INTEGER uliChannelMap ;
  3665. PULARGE_INTEGER pChannelNum = NULL;
  3666. ULONG ulPrevSpeed;
  3667. STORE_CURRENT_IRQL;
  3668. TRACE( TL_T, TM_Cm, ( "==> nicChangeChannelChar pVc %x , Channel %x, Speed %x ",pMcVc, pMcChar->ChannelMap, pMcVc->Speed) );
  3669. do
  3670. {
  3671. //
  3672. // Validate
  3673. //
  3674. /* if ( pMcVc->ulTag != MTAG_VCCB ||
  3675. pMcVc->Hdr.Nic1394MediaParams.Destination.AddressType != NIC1394AddressType_MultiChannel)
  3676. {
  3677. BREAK( TM_Cm, ("Tag or AddressType is invalid "));
  3678. }
  3679. */ //
  3680. uliChannelMap = pMcChar->ChannelMap;
  3681. TRACE ( TL_V, TM_Cm, ("MultiChannel Modify Isoch Map %I64x, Speed %x",
  3682. uliChannelMap, pMcChar->Speed ) );
  3683. //
  3684. // Check to see if this is a zero to N transition
  3685. //
  3686. VC_ACQUIRE_LOCK (pMcVc);
  3687. uliPrevMap = pMcVc->uliChannelMap;
  3688. pMcVc->uliChannelMap = uliChannelMap;
  3689. ulPrevSpeed = pMcVc->Speed;
  3690. pMcVc->Speed = pMcChar->Speed;
  3691. VC_RELEASE_LOCK (pMcVc);
  3692. if (pMcVc->hResource == NULL)
  3693. {
  3694. //
  3695. // No Resources have been allocated. Allocate resources
  3696. //
  3697. NdisStatus = nicAllocateChannelResourcesAndListen (pMcVc->Hdr.pAF->pAdapter, pMcVc );
  3698. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3699. {
  3700. BREAK( TM_Cm, ("MultiChannel AllocateChannelResourcesAnd Listen FAILED") ) ;
  3701. }
  3702. }
  3703. //
  3704. // A Channel has been previously allocated, we need to change it
  3705. // and use the new channel instead
  3706. //
  3707. NdisStatus = nicIsochModifyStreamProperties (pMcVc->Hdr.pAF->pAdapter,
  3708. pMcVc->hResource,
  3709. uliChannelMap,
  3710. pMcChar->Speed);
  3711. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3712. {
  3713. BREAK (TM_Cm, ("Modify Isoch Properties failed" ) );
  3714. }
  3715. } while (FALSE);
  3716. if (NdisStatus != NDIS_STATUS_SUCCESS)
  3717. {
  3718. VC_ACQUIRE_LOCK (pMcVc);
  3719. pMcVc->uliChannelMap = uliPrevMap;
  3720. pMcVc->Speed = ulPrevSpeed;
  3721. VC_RELEASE_LOCK (pMcVc);
  3722. }
  3723. TRACE( TL_T, TM_Cm, ( "<== nicChangeChannelChar NdisStatus %x ",NdisStatus) );
  3724. MATCH_IRQL;
  3725. return NdisStatus;
  3726. }
  3727. VOID
  3728. nicInterceptMakeCallParameters (
  3729. PCO_MEDIA_PARAMETERS pMedia
  3730. )
  3731. {
  3732. PNIC1394_MEDIA_PARAMETERS p1394Params = (PNIC1394_MEDIA_PARAMETERS )(pMedia->MediaSpecific.Parameters);
  3733. #if INTERCEPT_MAKE_CALL
  3734. if (p1394Params->Destination.AddressType == NIC1394AddressType_MultiChannel)
  3735. {
  3736. p1394Params->Destination.AddressType = NIC1394AddressType_Channel;
  3737. p1394Params->Destination.Channel = 0x3a;
  3738. p1394Params->Flags |= NIC1394_VCFLAG_ALLOCATE;
  3739. pMedia->Flags |= TRANSMIT_VC;
  3740. pMedia->Flags &= (~RECEIVE_VC);
  3741. return;
  3742. }
  3743. if (p1394Params->Destination.AddressType == NIC1394AddressType_Ethernet)
  3744. {
  3745. p1394Params->Destination.AddressType = NIC1394AddressType_Channel;
  3746. p1394Params->Destination.Channel = 0x3a;
  3747. pMedia->Flags |= RECEIVE_VC;
  3748. pMedia->Flags &= (~TRANSMIT_VC);
  3749. return;
  3750. }
  3751. #endif
  3752. }
  3753. UINT
  3754. nicSpeedFlagsToSCode(
  3755. IN UINT SpeedFlags
  3756. )
  3757. {
  3758. UINT SCode = SCODE_400_RATE;
  3759. switch (SpeedFlags)
  3760. {
  3761. case SPEED_FLAGS_100 :
  3762. {
  3763. SCode = SCODE_100_RATE;
  3764. break;
  3765. }
  3766. case SPEED_FLAGS_200 :
  3767. {
  3768. SCode = SCODE_200_RATE;
  3769. break;
  3770. }
  3771. case SPEED_FLAGS_400 :
  3772. {
  3773. SCode = SCODE_400_RATE;
  3774. break;
  3775. }
  3776. case SPEED_FLAGS_800 :
  3777. {
  3778. SCode = SCODE_800_RATE;
  3779. break;
  3780. }
  3781. case SPEED_FLAGS_1600 :
  3782. {
  3783. SCode = SCODE_1600_RATE;
  3784. break;
  3785. }
  3786. case SPEED_FLAGS_3200 :
  3787. {
  3788. SCode = SCODE_3200_RATE;
  3789. break;
  3790. }
  3791. default :
  3792. {
  3793. ASSERT (!"SpeedFlags out of range");
  3794. break;
  3795. }
  3796. }
  3797. return SCode;
  3798. }