1 /* SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause */
2 /* Copyright(c) 2007 - 2011 Realtek Corporation. */
3 
4 #ifndef __USB_OPS_H_
5 #define __USB_OPS_H_
6 
7 #include "osdep_service.h"
8 #include "drv_types.h"
9 #include "osdep_intf.h"
10 
11 #define REALTEK_USB_VENQT_READ		(USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
12 #define REALTEK_USB_VENQT_WRITE		(USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE)
13 #define REALTEK_USB_VENQT_CMD_REQ	0x05
14 #define REALTEK_USB_VENQT_CMD_IDX	0x00
15 
16 #define ALIGNMENT_UNIT			16
17 #define MAX_VENDOR_REQ_CMD_SIZE	254	/* 8188cu SIE Support */
18 #define MAX_USB_IO_CTL_SIZE	(MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
19 
20 #include "usb_ops_linux.h"
21 
22 /*
23  * Increase and check if the continual_urb_error of this @param dvobjprivei
24  * is larger than MAX_CONTINUAL_URB_ERR
25  * @return true:
26  * @return false:
27  */
rtw_inc_and_chk_continual_urb_error(struct dvobj_priv * dvobj)28 static inline bool rtw_inc_and_chk_continual_urb_error(struct dvobj_priv *dvobj)
29 {
30 	int value = atomic_inc_return(&dvobj->continual_urb_error);
31 
32 	if (value > MAX_CONTINUAL_URB_ERR)
33 		return true;
34 
35 	return false;
36 }
37 
38 /*
39 * Set the continual_urb_error of this @param dvobjprive to 0
40 */
rtw_reset_continual_urb_error(struct dvobj_priv * dvobj)41 static inline void rtw_reset_continual_urb_error(struct dvobj_priv *dvobj)
42 {
43 	atomic_set(&dvobj->continual_urb_error, 0);
44 }
45 
46 #define USB_HIGH_SPEED_BULK_SIZE	512
47 #define USB_FULL_SPEED_BULK_SIZE	64
48 
rtw_usb_bulk_size_boundary(struct adapter * padapter,int buf_len)49 static inline bool rtw_usb_bulk_size_boundary(struct adapter *padapter, int buf_len)
50 {
51 	struct dvobj_priv *pdvobjpriv = adapter_to_dvobj(padapter);
52 
53 	if (pdvobjpriv->pusbdev->speed == USB_SPEED_HIGH)
54 		return buf_len % USB_HIGH_SPEED_BULK_SIZE == 0;
55 	else
56 		return buf_len % USB_FULL_SPEED_BULK_SIZE == 0;
57 }
58 
59 #endif /* __USB_OPS_H_ */
60