InterfaceMisc.c 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  1. #include "headers.h"
  2. static int adapter_err_occurred(const struct bcm_interface_adapter *ad)
  3. {
  4. if (ad->psAdapter->device_removed == TRUE) {
  5. BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_PRINTK, 0, 0,
  6. "Device got removed");
  7. return -ENODEV;
  8. }
  9. if ((ad->psAdapter->StopAllXaction == TRUE) &&
  10. (ad->psAdapter->chip_id >= T3LPB)) {
  11. BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
  12. DBG_LVL_ALL,
  13. "Currently Xaction is not allowed on the bus");
  14. return -EACCES;
  15. }
  16. if (ad->bSuspended == TRUE || ad->bPreparingForBusSuspend == TRUE) {
  17. BCM_DEBUG_PRINT(ad->psAdapter, DBG_TYPE_OTHERS, RDM,
  18. DBG_LVL_ALL,
  19. "Bus is in suspended states hence RDM not allowed..");
  20. return -EACCES;
  21. }
  22. return 0;
  23. }
  24. int InterfaceRDM(struct bcm_interface_adapter *psIntfAdapter,
  25. unsigned int addr,
  26. void *buff,
  27. int len)
  28. {
  29. int bytes;
  30. int err = 0;
  31. if (!psIntfAdapter)
  32. return -EINVAL;
  33. err = adapter_err_occurred(psIntfAdapter);
  34. if (err)
  35. return err;
  36. psIntfAdapter->psAdapter->DeviceAccess = TRUE;
  37. bytes = usb_control_msg(psIntfAdapter->udev,
  38. usb_rcvctrlpipe(psIntfAdapter->udev, 0),
  39. 0x02,
  40. 0xC2,
  41. (addr & 0xFFFF),
  42. ((addr >> 16) & 0xFFFF),
  43. buff,
  44. len,
  45. 5000);
  46. if (-ENODEV == bytes)
  47. psIntfAdapter->psAdapter->device_removed = TRUE;
  48. if (bytes < 0)
  49. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
  50. DBG_LVL_ALL, "RDM failed status :%d", bytes);
  51. else
  52. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, RDM,
  53. DBG_LVL_ALL, "RDM sent %d", bytes);
  54. psIntfAdapter->psAdapter->DeviceAccess = false;
  55. return bytes;
  56. }
  57. int InterfaceWRM(struct bcm_interface_adapter *psIntfAdapter,
  58. unsigned int addr,
  59. void *buff,
  60. int len)
  61. {
  62. int retval = 0;
  63. int err = 0;
  64. if (!psIntfAdapter)
  65. return -EINVAL;
  66. err = adapter_err_occurred(psIntfAdapter);
  67. if (err)
  68. return err;
  69. psIntfAdapter->psAdapter->DeviceAccess = TRUE;
  70. retval = usb_control_msg(psIntfAdapter->udev,
  71. usb_sndctrlpipe(psIntfAdapter->udev, 0),
  72. 0x01,
  73. 0x42,
  74. (addr & 0xFFFF),
  75. ((addr >> 16) & 0xFFFF),
  76. buff,
  77. len,
  78. 5000);
  79. if (-ENODEV == retval)
  80. psIntfAdapter->psAdapter->device_removed = TRUE;
  81. if (retval < 0) {
  82. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
  83. DBG_LVL_ALL, "WRM failed status :%d", retval);
  84. psIntfAdapter->psAdapter->DeviceAccess = false;
  85. return retval;
  86. } else {
  87. psIntfAdapter->psAdapter->DeviceAccess = false;
  88. BCM_DEBUG_PRINT(psIntfAdapter->psAdapter, DBG_TYPE_OTHERS, WRM,
  89. DBG_LVL_ALL, "WRM sent %d", retval);
  90. return STATUS_SUCCESS;
  91. }
  92. }
  93. int BcmRDM(void *arg,
  94. unsigned int addr,
  95. void *buff,
  96. int len)
  97. {
  98. return InterfaceRDM((struct bcm_interface_adapter *)arg, addr, buff,
  99. len);
  100. }
  101. int BcmWRM(void *arg,
  102. unsigned int addr,
  103. void *buff,
  104. int len)
  105. {
  106. return InterfaceWRM((struct bcm_interface_adapter *)arg, addr, buff,
  107. len);
  108. }
  109. int Bcm_clear_halt_of_endpoints(struct bcm_mini_adapter *Adapter)
  110. {
  111. struct bcm_interface_adapter *psIntfAdapter =
  112. (struct bcm_interface_adapter *)(Adapter->pvInterfaceAdapter);
  113. int status = STATUS_SUCCESS;
  114. /*
  115. * usb_clear_halt - tells device to clear endpoint halt/stall condition
  116. * @dev: device whose endpoint is halted
  117. * @pipe: endpoint "pipe" being cleared
  118. * @ Context: !in_interrupt ()
  119. *
  120. * usb_clear_halt is the synchrnous call and returns 0 on success else
  121. * returns with error code.
  122. * This is used to clear halt conditions for bulk and interrupt
  123. * endpoints only.
  124. * Control and isochronous endpoints never halts.
  125. *
  126. * Any URBs queued for such an endpoint should normally be unlinked by
  127. * the driver before clearing the halt condition.
  128. *
  129. */
  130. /* Killing all the submitted urbs to different end points. */
  131. Bcm_kill_all_URBs(psIntfAdapter);
  132. /* clear the halted/stalled state for every end point */
  133. status = usb_clear_halt(psIntfAdapter->udev,
  134. psIntfAdapter->sIntrIn.int_in_pipe);
  135. if (status != STATUS_SUCCESS)
  136. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
  137. DBG_LVL_ALL,
  138. "Unable to Clear Halt of Interrupt IN end point. :%d ",
  139. status);
  140. status = usb_clear_halt(psIntfAdapter->udev,
  141. psIntfAdapter->sBulkIn.bulk_in_pipe);
  142. if (status != STATUS_SUCCESS)
  143. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
  144. DBG_LVL_ALL,
  145. "Unable to Clear Halt of Bulk IN end point. :%d ",
  146. status);
  147. status = usb_clear_halt(psIntfAdapter->udev,
  148. psIntfAdapter->sBulkOut.bulk_out_pipe);
  149. if (status != STATUS_SUCCESS)
  150. BCM_DEBUG_PRINT(Adapter, DBG_TYPE_OTHERS, INTF_INIT,
  151. DBG_LVL_ALL,
  152. "Unable to Clear Halt of Bulk OUT end point. :%d ",
  153. status);
  154. return status;
  155. }
  156. void Bcm_kill_all_URBs(struct bcm_interface_adapter *psIntfAdapter)
  157. {
  158. struct urb *tempUrb = NULL;
  159. unsigned int i;
  160. /*
  161. * usb_kill_urb - cancel a transfer request and wait for it to finish
  162. * @urb: pointer to URB describing a previously submitted request,
  163. * returns nothing as it is void returned API.
  164. *
  165. * This routine cancels an in-progress request. It is guaranteed that
  166. * upon return all completion handlers will have finished and the URB
  167. * will be totally idle and available for reuse
  168. *
  169. * This routine may not be used in an interrupt context (such as a
  170. * bottom half or a completion handler), or when holding a spinlock, or
  171. * in other situations where the caller can't schedule().
  172. *
  173. */
  174. /* Cancel submitted Interrupt-URB's */
  175. if (psIntfAdapter->psInterruptUrb) {
  176. if (psIntfAdapter->psInterruptUrb->status == -EINPROGRESS)
  177. usb_kill_urb(psIntfAdapter->psInterruptUrb);
  178. }
  179. /* Cancel All submitted TX URB's */
  180. for (i = 0; i < MAXIMUM_USB_TCB; i++) {
  181. tempUrb = psIntfAdapter->asUsbTcb[i].urb;
  182. if (tempUrb) {
  183. if (tempUrb->status == -EINPROGRESS)
  184. usb_kill_urb(tempUrb);
  185. }
  186. }
  187. for (i = 0; i < MAXIMUM_USB_RCB; i++) {
  188. tempUrb = psIntfAdapter->asUsbRcb[i].urb;
  189. if (tempUrb) {
  190. if (tempUrb->status == -EINPROGRESS)
  191. usb_kill_urb(tempUrb);
  192. }
  193. }
  194. atomic_set(&psIntfAdapter->uNumTcbUsed, 0);
  195. atomic_set(&psIntfAdapter->uCurrTcb, 0);
  196. atomic_set(&psIntfAdapter->uNumRcbUsed, 0);
  197. atomic_set(&psIntfAdapter->uCurrRcb, 0);
  198. }
  199. void putUsbSuspend(struct work_struct *work)
  200. {
  201. struct bcm_interface_adapter *psIntfAdapter = NULL;
  202. struct usb_interface *intf = NULL;
  203. psIntfAdapter = container_of(work, struct bcm_interface_adapter,
  204. usbSuspendWork);
  205. intf = psIntfAdapter->interface;
  206. if (psIntfAdapter->bSuspended == false)
  207. usb_autopm_put_interface(intf);
  208. }