Merge branch 'upstream' of git://git.linux-mips.org/pub/scm/upstream-linus
[linux-btrfs-devel.git] / drivers / staging / bcm / InterfaceMisc.c
bloba51185b522cf9e8ee7bb8c708f3bc2b93afd6a48
1 #include "headers.h"
3 INT
4 InterfaceRDM(PS_INTERFACE_ADAPTER psIntfAdapter,
5 UINT addr,
6 PVOID buff,
7 INT len)
9 int retval = 0;
10 USHORT usRetries = 0 ;
11 if(psIntfAdapter == NULL )
13 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0,"Interface Adapter is NULL");
14 return -EINVAL ;
17 if(psIntfAdapter->psAdapter->device_removed == TRUE)
19 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0,"Device got removed");
20 return -ENODEV;
23 if((psIntfAdapter->psAdapter->StopAllXaction == TRUE) && (psIntfAdapter->psAdapter->chip_id >= T3LPB))
25 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, RDM, DBG_LVL_ALL,"Currently Xaction is not allowed on the bus");
26 return -EACCES;
29 if(psIntfAdapter->bSuspended ==TRUE || psIntfAdapter->bPreparingForBusSuspend == TRUE)
31 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, RDM, DBG_LVL_ALL,"Bus is in suspended states hence RDM not allowed..");
32 return -EACCES;
34 psIntfAdapter->psAdapter->DeviceAccess = TRUE ;
35 do {
36 retval = usb_control_msg(psIntfAdapter->udev,
37 usb_rcvctrlpipe(psIntfAdapter->udev,0),
38 0x02,
39 0xC2,
40 (addr & 0xFFFF),
41 ((addr >> 16) & 0xFFFF),
42 buff,
43 len,
44 5000);
46 usRetries++ ;
47 if(-ENODEV == retval)
49 psIntfAdapter->psAdapter->device_removed =TRUE;
50 break;
53 }while((retval < 0) && (usRetries < MAX_RDM_WRM_RETIRES ) );
55 if(retval < 0)
57 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, RDM, DBG_LVL_ALL, "RDM failed status :%d, retires :%d", retval,usRetries);
58 psIntfAdapter->psAdapter->DeviceAccess = FALSE ;
59 return retval;
61 else
63 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, RDM, DBG_LVL_ALL, "RDM sent %d", retval);
64 psIntfAdapter->psAdapter->DeviceAccess = FALSE ;
65 return STATUS_SUCCESS;
69 INT
70 InterfaceWRM(PS_INTERFACE_ADAPTER psIntfAdapter,
71 UINT addr,
72 PVOID buff,
73 INT len)
75 int retval = 0;
76 USHORT usRetries = 0 ;
78 if(psIntfAdapter == NULL )
80 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0, "Interface Adapter is NULL");
81 return -EINVAL;
83 if(psIntfAdapter->psAdapter->device_removed == TRUE)
86 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_PRINTK, 0, 0,"Device got removed");
87 return -ENODEV;
90 if((psIntfAdapter->psAdapter->StopAllXaction == TRUE) && (psIntfAdapter->psAdapter->chip_id >= T3LPB))
92 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL,"Currently Xaction is not allowed on the bus...");
93 return -EACCES;
96 if(psIntfAdapter->bSuspended ==TRUE || psIntfAdapter->bPreparingForBusSuspend == TRUE)
98 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL,"Bus is in suspended states hence RDM not allowed..");
99 return -EACCES;
101 psIntfAdapter->psAdapter->DeviceAccess = TRUE ;
103 retval = usb_control_msg(psIntfAdapter->udev,
104 usb_sndctrlpipe(psIntfAdapter->udev,0),
105 0x01,
106 0x42,
107 (addr & 0xFFFF),
108 ((addr >> 16) & 0xFFFF),
109 buff,
110 len,
111 5000);
113 usRetries++ ;
114 if(-ENODEV == retval)
116 psIntfAdapter->psAdapter->device_removed = TRUE ;
117 break;
120 }while((retval < 0) && ( usRetries < MAX_RDM_WRM_RETIRES));
122 if(retval < 0)
124 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL, "WRM failed status :%d, retires :%d", retval, usRetries);
125 psIntfAdapter->psAdapter->DeviceAccess = FALSE ;
126 return retval;
128 else
130 psIntfAdapter->psAdapter->DeviceAccess = FALSE ;
131 BCM_DEBUG_PRINT(psIntfAdapter->psAdapter,DBG_TYPE_OTHERS, WRM, DBG_LVL_ALL, "WRM sent %d", retval);
132 return STATUS_SUCCESS;
139 BcmRDM(PVOID arg,
140 UINT addr,
141 PVOID buff,
142 INT len)
144 return InterfaceRDM((PS_INTERFACE_ADAPTER)arg, addr, buff, len);
148 BcmWRM(PVOID arg,
149 UINT addr,
150 PVOID buff,
151 INT len)
153 return InterfaceWRM((PS_INTERFACE_ADAPTER)arg, addr, buff, len);
158 INT Bcm_clear_halt_of_endpoints(PMINI_ADAPTER Adapter)
160 PS_INTERFACE_ADAPTER psIntfAdapter = (PS_INTERFACE_ADAPTER)(Adapter->pvInterfaceAdapter);
161 INT status = STATUS_SUCCESS ;
164 usb_clear_halt - tells device to clear endpoint halt/stall condition
165 @dev: device whose endpoint is halted
166 @pipe: endpoint "pipe" being cleared
167 @ Context: !in_interrupt ()
169 usb_clear_halt is the synchrnous call and returns 0 on success else returns with error code.
170 This is used to clear halt conditions for bulk and interrupt endpoints only.
171 Control and isochronous endpoints never halts.
173 Any URBs queued for such an endpoint should normally be unlinked by the driver
174 before clearing the halt condition.
178 //Killing all the submitted urbs to different end points.
179 Bcm_kill_all_URBs(psIntfAdapter);
182 //clear the halted/stalled state for every end point
183 status = usb_clear_halt(psIntfAdapter->udev,psIntfAdapter->sIntrIn.int_in_pipe);
184 if(status != STATUS_SUCCESS)
185 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL, "Unable to Clear Halt of Interrupt IN end point. :%d ", status);
187 status = usb_clear_halt(psIntfAdapter->udev,psIntfAdapter->sBulkIn.bulk_in_pipe);
188 if(status != STATUS_SUCCESS)
189 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL, "Unable to Clear Halt of Bulk IN end point. :%d ", status);
191 status = usb_clear_halt(psIntfAdapter->udev,psIntfAdapter->sBulkOut.bulk_out_pipe);
192 if(status != STATUS_SUCCESS)
193 BCM_DEBUG_PRINT(Adapter,DBG_TYPE_OTHERS, INTF_INIT, DBG_LVL_ALL, "Unable to Clear Halt of Bulk OUT end point. :%d ", status);
195 return status ;
199 VOID Bcm_kill_all_URBs(PS_INTERFACE_ADAPTER psIntfAdapter)
201 struct urb *tempUrb = NULL;
202 UINT i;
205 * usb_kill_urb - cancel a transfer request and wait for it to finish
206 * @urb: pointer to URB describing a previously submitted request,
207 * returns nothing as it is void returned API.
209 * This routine cancels an in-progress request. It is guaranteed that
210 * upon return all completion handlers will have finished and the URB
211 * will be totally idle and available for reuse
213 * This routine may not be used in an interrupt context (such as a bottom
214 * half or a completion handler), or when holding a spinlock, or in other
215 * situations where the caller can't schedule().
219 /* Cancel submitted Interrupt-URB's */
220 if(psIntfAdapter->psInterruptUrb != NULL)
222 if(psIntfAdapter->psInterruptUrb->status == -EINPROGRESS)
223 usb_kill_urb(psIntfAdapter->psInterruptUrb);
226 /* Cancel All submitted TX URB's */
227 for(i = 0; i < MAXIMUM_USB_TCB; i++)
229 tempUrb = psIntfAdapter->asUsbTcb[i].urb;
230 if(tempUrb)
232 if(tempUrb->status == -EINPROGRESS)
233 usb_kill_urb(tempUrb);
237 for(i = 0; i < MAXIMUM_USB_RCB; i++)
239 tempUrb = psIntfAdapter->asUsbRcb[i].urb;
240 if(tempUrb)
242 if(tempUrb->status == -EINPROGRESS)
243 usb_kill_urb(tempUrb);
247 atomic_set(&psIntfAdapter->uNumTcbUsed, 0);
248 atomic_set(&psIntfAdapter->uCurrTcb, 0);
250 atomic_set(&psIntfAdapter->uNumRcbUsed, 0);
251 atomic_set(&psIntfAdapter->uCurrRcb, 0);
254 VOID putUsbSuspend(struct work_struct *work)
256 PS_INTERFACE_ADAPTER psIntfAdapter = NULL ;
257 struct usb_interface *intf = NULL ;
258 psIntfAdapter = container_of(work, S_INTERFACE_ADAPTER,usbSuspendWork);
259 intf=psIntfAdapter->interface ;
261 if(psIntfAdapter->bSuspended == FALSE)
262 usb_autopm_put_interface(intf);