InterfaceTx.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198
  1. #include "headers.h"
  2. /*this is transmit call-back(BULK OUT)*/
  3. static void write_bulk_callback(struct urb *urb/*, struct pt_regs *regs*/)
  4. {
  5. PUSB_TCB pTcb= (PUSB_TCB)urb->context;
  6. PS_INTERFACE_ADAPTER psIntfAdapter = pTcb->psIntfAdapter;
  7. CONTROL_MESSAGE *pControlMsg = (CONTROL_MESSAGE *)urb->transfer_buffer;
  8. PMINI_ADAPTER psAdapter = psIntfAdapter->psAdapter ;
  9. BOOLEAN bpowerDownMsg = FALSE ;
  10. PMINI_ADAPTER Adapter = GET_BCM_ADAPTER(gblpnetdev);
  11. if (unlikely(netif_msg_tx_done(Adapter)))
  12. pr_info(PFX "%s: transmit status %d\n", Adapter->dev->name, urb->status);
  13. if(urb->status != STATUS_SUCCESS)
  14. {
  15. if(urb->status == -EPIPE)
  16. {
  17. psIntfAdapter->psAdapter->bEndPointHalted = TRUE ;
  18. wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
  19. }
  20. else
  21. {
  22. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,"Tx URB has got cancelled. status :%d", urb->status);
  23. }
  24. }
  25. pTcb->bUsed = FALSE;
  26. atomic_dec(&psIntfAdapter->uNumTcbUsed);
  27. if(TRUE == psAdapter->bPreparingForLowPowerMode)
  28. {
  29. if(((pControlMsg->szData[0] == GO_TO_IDLE_MODE_PAYLOAD) &&
  30. (pControlMsg->szData[1] == TARGET_CAN_GO_TO_IDLE_MODE)))
  31. {
  32. bpowerDownMsg = TRUE ;
  33. //This covers the bus err while Idle Request msg sent down.
  34. if(urb->status != STATUS_SUCCESS)
  35. {
  36. psAdapter->bPreparingForLowPowerMode = FALSE ;
  37. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,"Idle Mode Request msg failed to reach to Modem");
  38. //Signalling the cntrl pkt path in Ioctl
  39. wake_up(&psAdapter->lowpower_mode_wait_queue);
  40. StartInterruptUrb(psIntfAdapter);
  41. goto err_exit;
  42. }
  43. if(psAdapter->bDoSuspend == FALSE)
  44. {
  45. psAdapter->IdleMode = TRUE;
  46. //since going in Idle mode completed hence making this var false;
  47. psAdapter->bPreparingForLowPowerMode = FALSE ;
  48. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Host Entered in Idle Mode State...");
  49. //Signalling the cntrl pkt path in Ioctl
  50. wake_up(&psAdapter->lowpower_mode_wait_queue);
  51. }
  52. }
  53. else if((pControlMsg->Leader.Status == LINK_UP_CONTROL_REQ) &&
  54. (pControlMsg->szData[0] == LINK_UP_ACK) &&
  55. (pControlMsg->szData[1] == LINK_SHUTDOWN_REQ_FROM_FIRMWARE) &&
  56. (pControlMsg->szData[2] == SHUTDOWN_ACK_FROM_DRIVER))
  57. {
  58. //This covers the bus err while shutdown Request msg sent down.
  59. if(urb->status != STATUS_SUCCESS)
  60. {
  61. psAdapter->bPreparingForLowPowerMode = FALSE ;
  62. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,"Shutdown Request Msg failed to reach to Modem");
  63. //Signalling the cntrl pkt path in Ioctl
  64. wake_up(&psAdapter->lowpower_mode_wait_queue);
  65. StartInterruptUrb(psIntfAdapter);
  66. goto err_exit;
  67. }
  68. bpowerDownMsg = TRUE ;
  69. if(psAdapter->bDoSuspend == FALSE)
  70. {
  71. psAdapter->bShutStatus = TRUE;
  72. //since going in shutdown mode completed hence making this var false;
  73. psAdapter->bPreparingForLowPowerMode = FALSE ;
  74. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,"Host Entered in shutdown Mode State...");
  75. //Signalling the cntrl pkt path in Ioctl
  76. wake_up(&psAdapter->lowpower_mode_wait_queue);
  77. }
  78. }
  79. if(psAdapter->bDoSuspend && bpowerDownMsg)
  80. {
  81. //issuing bus suspend request
  82. BCM_DEBUG_PRINT(Adapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL,"Issuing the Bus suspend request to USB stack");
  83. psIntfAdapter->bPreparingForBusSuspend = TRUE;
  84. schedule_work(&psIntfAdapter->usbSuspendWork);
  85. }
  86. }
  87. err_exit :
  88. usb_free_coherent(urb->dev, urb->transfer_buffer_length,
  89. urb->transfer_buffer, urb->transfer_dma);
  90. }
  91. static PUSB_TCB GetBulkOutTcb(PS_INTERFACE_ADAPTER psIntfAdapter)
  92. {
  93. PUSB_TCB pTcb = NULL;
  94. UINT index = 0;
  95. if((atomic_read(&psIntfAdapter->uNumTcbUsed) < MAXIMUM_USB_TCB) &&
  96. (psIntfAdapter->psAdapter->StopAllXaction ==FALSE))
  97. {
  98. index = atomic_read(&psIntfAdapter->uCurrTcb);
  99. pTcb = &psIntfAdapter->asUsbTcb[index];
  100. pTcb->bUsed = TRUE;
  101. pTcb->psIntfAdapter= psIntfAdapter;
  102. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Got Tx desc %d used %d",
  103. index, atomic_read(&psIntfAdapter->uNumTcbUsed));
  104. index = (index + 1) % MAXIMUM_USB_TCB;
  105. atomic_set(&psIntfAdapter->uCurrTcb, index);
  106. atomic_inc(&psIntfAdapter->uNumTcbUsed);
  107. }
  108. return pTcb;
  109. }
  110. static int TransmitTcb(PS_INTERFACE_ADAPTER psIntfAdapter, PUSB_TCB pTcb, PVOID data, int len)
  111. {
  112. struct urb *urb = pTcb->urb;
  113. int retval = 0;
  114. urb->transfer_buffer = usb_alloc_coherent(psIntfAdapter->udev, len,
  115. GFP_ATOMIC, &urb->transfer_dma);
  116. if (!urb->transfer_buffer)
  117. {
  118. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Error allocating memory\n");
  119. return -ENOMEM;
  120. }
  121. memcpy(urb->transfer_buffer, data, len);
  122. urb->transfer_buffer_length = len;
  123. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "Sending Bulk out packet\n");
  124. //For T3B,INT OUT end point will be used as bulk out end point
  125. if((psIntfAdapter->psAdapter->chip_id == T3B) && (psIntfAdapter->bHighSpeedDevice == TRUE))
  126. {
  127. usb_fill_int_urb(urb, psIntfAdapter->udev,
  128. psIntfAdapter->sBulkOut.bulk_out_pipe,
  129. urb->transfer_buffer, len, write_bulk_callback, pTcb,
  130. psIntfAdapter->sBulkOut.int_out_interval);
  131. }
  132. else
  133. {
  134. usb_fill_bulk_urb(urb, psIntfAdapter->udev,
  135. psIntfAdapter->sBulkOut.bulk_out_pipe,
  136. urb->transfer_buffer, len, write_bulk_callback, pTcb);
  137. }
  138. urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; /* For DMA transfer */
  139. if(FALSE == psIntfAdapter->psAdapter->device_removed &&
  140. FALSE == psIntfAdapter->psAdapter->bEndPointHalted &&
  141. FALSE == psIntfAdapter->bSuspended &&
  142. FALSE == psIntfAdapter->bPreparingForBusSuspend)
  143. {
  144. retval = usb_submit_urb(urb, GFP_ATOMIC);
  145. if (retval)
  146. {
  147. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_TX, NEXT_SEND, DBG_LVL_ALL, "failed submitting write urb, error %d", retval);
  148. if(retval == -EPIPE)
  149. {
  150. psIntfAdapter->psAdapter->bEndPointHalted = TRUE ;
  151. wake_up(&psIntfAdapter->psAdapter->tx_packet_wait_queue);
  152. }
  153. }
  154. }
  155. return retval;
  156. }
  157. int InterfaceTransmitPacket(PVOID arg, PVOID data, UINT len)
  158. {
  159. PUSB_TCB pTcb= NULL;
  160. PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)arg;
  161. pTcb= GetBulkOutTcb(psIntfAdapter);
  162. if(pTcb == NULL)
  163. {
  164. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "No URB to transmit packet, dropping packet");
  165. return -EFAULT;
  166. }
  167. return TransmitTcb(psIntfAdapter, pTcb, data, len);
  168. }