mirror of
https://github.com/Mange/rtl8192eu-linux-driver
synced 2024-11-22 05:25:03 +00:00
use actual request type as parameter
At the moment, usbctrl_vendorreq's requesttype parameter must be set to 1 for reading and 0 for writing. It's then converted to the actual bmRequestType for the USB control request. We can simplify the code and avoid this conversion if the caller passes the actual bmRequestType. This patch is an adaptation of commit 788fde031027 ("staging: rtl8188eu: use actual request type as parameter") for the new r8188eu driver. Link: https://lore.kernel.org/r/20210821164859.4351-3-martin@kaiser.cx
This commit is contained in:
parent
a0549c5041
commit
4ddd7165fb
@ -261,18 +261,16 @@ void usb_c2h_hisr_hdl(_adapter *adapter, u8 *buf)
|
|||||||
int usb_write_async(struct usb_device *udev, u32 addr, void *pdata, u16 len)
|
int usb_write_async(struct usb_device *udev, u32 addr, void *pdata, u16 len)
|
||||||
{
|
{
|
||||||
u8 request;
|
u8 request;
|
||||||
u8 requesttype;
|
|
||||||
u16 wvalue;
|
u16 wvalue;
|
||||||
u16 index;
|
u16 index;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
requesttype = VENDOR_WRITE;/* write_out */
|
|
||||||
request = REALTEK_USB_VENQT_CMD_REQ;
|
request = REALTEK_USB_VENQT_CMD_REQ;
|
||||||
index = REALTEK_USB_VENQT_CMD_IDX;/* n/a */
|
index = REALTEK_USB_VENQT_CMD_IDX;/* n/a */
|
||||||
|
|
||||||
wvalue = (u16)(addr & 0x0000ffff);
|
wvalue = (u16)(addr & 0x0000ffff);
|
||||||
|
|
||||||
ret = _usbctrl_vendorreq_async_write(udev, request, wvalue, index, pdata, len, requesttype);
|
ret = _usbctrl_vendorreq_async_write(udev, request, wvalue, index, pdata, len, REALTEK_USB_VENQT_WRITE);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
@ -329,7 +327,7 @@ u8 usb_read8(struct intf_hdl *pintfhdl, u32 addr)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 1, VENDOR_READ);
|
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 1, REALTEK_USB_VENQT_READ);
|
||||||
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -346,7 +344,7 @@ u16 usb_read16(struct intf_hdl *pintfhdl, u32 addr)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 2, VENDOR_READ);
|
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 2, REALTEK_USB_VENQT_READ);
|
||||||
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -364,7 +362,7 @@ u32 usb_read32(struct intf_hdl *pintfhdl, u32 addr)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 4, VENDOR_READ);
|
usbctrl_vendorreq(pintfhdl, wvalue, 0, &data, 4, REALTEK_USB_VENQT_READ);
|
||||||
|
|
||||||
|
|
||||||
return data;
|
return data;
|
||||||
@ -380,7 +378,7 @@ int usb_write8(struct intf_hdl *pintfhdl, u32 addr, u8 val)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 1, VENDOR_WRITE);
|
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 1, REALTEK_USB_VENQT_WRITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -394,7 +392,7 @@ int usb_write16(struct intf_hdl *pintfhdl, u32 addr, u16 val)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 2, VENDOR_WRITE);
|
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 2, REALTEK_USB_VENQT_WRITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -408,7 +406,7 @@ int usb_write32(struct intf_hdl *pintfhdl, u32 addr, u32 val)
|
|||||||
wvalue |= 0x8000;
|
wvalue |= 0x8000;
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 4, VENDOR_WRITE);
|
return usbctrl_vendorreq(pintfhdl, wvalue, 0, &val, 4, REALTEK_USB_VENQT_WRITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -421,7 +419,7 @@ int usb_writeN(struct intf_hdl *pintfhdl, u32 addr, u32 length, u8 *pdata)
|
|||||||
return -EINVAL;
|
return -EINVAL;
|
||||||
|
|
||||||
memcpy(buf, pdata, length);
|
memcpy(buf, pdata, length);
|
||||||
return usbctrl_vendorreq(pintfhdl, wvalue, 0, buf, (length & 0xffff), VENDOR_WRITE);
|
return usbctrl_vendorreq(pintfhdl, wvalue, 0, buf, (length & 0xffff), REALTEK_USB_VENQT_WRITE);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,6 @@
|
|||||||
#define REALTEK_USB_VENQT_CMD_IDX 0x00
|
#define REALTEK_USB_VENQT_CMD_IDX 0x00
|
||||||
#define REALTEK_USB_IN_INT_EP_IDX 1
|
#define REALTEK_USB_IN_INT_EP_IDX 1
|
||||||
|
|
||||||
enum {
|
|
||||||
VENDOR_WRITE = 0x00,
|
|
||||||
VENDOR_READ = 0x01,
|
|
||||||
};
|
|
||||||
#define ALIGNMENT_UNIT 16
|
#define ALIGNMENT_UNIT 16
|
||||||
#define MAX_VENDOR_REQ_CMD_SIZE 254 /* 8188cu SIE Support */
|
#define MAX_VENDOR_REQ_CMD_SIZE 254 /* 8188cu SIE Support */
|
||||||
#define MAX_USB_IO_CTL_SIZE (MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
|
#define MAX_USB_IO_CTL_SIZE (MAX_VENDOR_REQ_CMD_SIZE + ALIGNMENT_UNIT)
|
||||||
|
@ -34,7 +34,6 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda
|
|||||||
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
|
#ifdef CONFIG_USB_VENDOR_REQ_BUFFER_DYNAMIC_ALLOCATE
|
||||||
u32 tmp_buflen = 0;
|
u32 tmp_buflen = 0;
|
||||||
#endif
|
#endif
|
||||||
u8 reqtype;
|
|
||||||
u8 *pIo_buf;
|
u8 *pIo_buf;
|
||||||
int vendorreq_times = 0;
|
int vendorreq_times = 0;
|
||||||
|
|
||||||
@ -94,32 +93,30 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda
|
|||||||
goto release_mutex;
|
goto release_mutex;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (requesttype == VENDOR_READ)
|
if (requesttype == REALTEK_USB_VENQT_READ)
|
||||||
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
|
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
|
||||||
else
|
else
|
||||||
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
||||||
|
|
||||||
while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
|
while (++vendorreq_times <= MAX_USBCTRL_VENDORREQ_TIMES) {
|
||||||
|
|
||||||
if (requesttype == VENDOR_READ) {
|
if (requesttype == REALTEK_USB_VENQT_READ) {
|
||||||
memset(pIo_buf, 0, len);
|
memset(pIo_buf, 0, len);
|
||||||
reqtype = REALTEK_USB_VENQT_READ;
|
|
||||||
} else {
|
} else {
|
||||||
reqtype = REALTEK_USB_VENQT_WRITE;
|
|
||||||
memcpy(pIo_buf, pdata, len);
|
memcpy(pIo_buf, pdata, len);
|
||||||
}
|
}
|
||||||
|
|
||||||
status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ, reqtype, value, index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
|
status = usb_control_msg(udev, pipe, REALTEK_USB_VENQT_CMD_REQ, requesttype, value, index, pIo_buf, len, RTW_USB_CONTROL_MSG_TIMEOUT);
|
||||||
|
|
||||||
if (status == len) { /* Success this control transfer. */
|
if (status == len) { /* Success this control transfer. */
|
||||||
rtw_reset_continual_io_error(pdvobjpriv);
|
rtw_reset_continual_io_error(pdvobjpriv);
|
||||||
if (requesttype == VENDOR_READ) {
|
if (requesttype == REALTEK_USB_VENQT_READ) {
|
||||||
/* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */
|
/* For Control read transfer, we have to copy the read data from pIo_buf to pdata. */
|
||||||
memcpy(pdata, pIo_buf, len);
|
memcpy(pdata, pIo_buf, len);
|
||||||
}
|
}
|
||||||
} else { /* error cases */
|
} else { /* error cases */
|
||||||
RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
|
RTW_INFO("reg 0x%x, usb %s %u fail, status:%d value=0x%x, vendorreq_times:%d\n"
|
||||||
, value, (requesttype == VENDOR_READ) ? "read" : "write" , len, status, *(u32 *)pdata, vendorreq_times);
|
, value, (requesttype == REALTEK_USB_VENQT_READ) ? "read" : "write" , len, status, *(u32 *)pdata, vendorreq_times);
|
||||||
|
|
||||||
if (status < 0) {
|
if (status < 0) {
|
||||||
if (status == (-ESHUTDOWN) || status == -ENODEV)
|
if (status == (-ESHUTDOWN) || status == -ENODEV)
|
||||||
@ -168,7 +165,6 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda
|
|||||||
|
|
||||||
if (current_reg_sec == REG_ON_SEC) {
|
if (current_reg_sec == REG_ON_SEC) {
|
||||||
unsigned int t_pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
unsigned int t_pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
||||||
u8 t_reqtype = REALTEK_USB_VENQT_WRITE;
|
|
||||||
u8 t_len = 1;
|
u8 t_len = 1;
|
||||||
u8 t_req = 0x05;
|
u8 t_req = 0x05;
|
||||||
u16 t_reg = 0;
|
u16 t_reg = 0;
|
||||||
@ -176,7 +172,7 @@ int usbctrl_vendorreq(struct intf_hdl *pintfhdl, u16 value, u16 index, void *pda
|
|||||||
|
|
||||||
t_reg = 0x4e0;
|
t_reg = 0x4e0;
|
||||||
|
|
||||||
status = usb_control_msg(udev, t_pipe, t_req, t_reqtype, t_reg, t_index, pIo_buf, t_len, RTW_USB_CONTROL_MSG_TIMEOUT);
|
status = usb_control_msg(udev, t_pipe, t_req, REALTEK_USB_VENQT_WRITE, t_reg, t_index, pIo_buf, t_len, RTW_USB_CONTROL_MSG_TIMEOUT);
|
||||||
|
|
||||||
if (status == t_len)
|
if (status == t_len)
|
||||||
rtw_reset_continual_io_error(pdvobjpriv);
|
rtw_reset_continual_io_error(pdvobjpriv);
|
||||||
@ -215,18 +211,15 @@ int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
|
|||||||
{
|
{
|
||||||
int rc;
|
int rc;
|
||||||
unsigned int pipe;
|
unsigned int pipe;
|
||||||
u8 reqtype;
|
|
||||||
struct usb_ctrlrequest *dr;
|
struct usb_ctrlrequest *dr;
|
||||||
struct urb *urb;
|
struct urb *urb;
|
||||||
struct rtw_async_write_data *buf;
|
struct rtw_async_write_data *buf;
|
||||||
|
|
||||||
|
|
||||||
if (requesttype == VENDOR_READ) {
|
if (requesttype == REALTEK_USB_VENQT_READ) {
|
||||||
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
|
pipe = usb_rcvctrlpipe(udev, 0);/* read_in */
|
||||||
reqtype = REALTEK_USB_VENQT_READ;
|
|
||||||
} else {
|
} else {
|
||||||
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
pipe = usb_sndctrlpipe(udev, 0);/* write_out */
|
||||||
reqtype = REALTEK_USB_VENQT_WRITE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
buf = (struct rtl819x_async_write_data *)rtw_zmalloc(sizeof(*buf));
|
buf = (struct rtl819x_async_write_data *)rtw_zmalloc(sizeof(*buf));
|
||||||
@ -244,7 +237,7 @@ int _usbctrl_vendorreq_async_write(struct usb_device *udev, u8 request,
|
|||||||
|
|
||||||
dr = &buf->dr;
|
dr = &buf->dr;
|
||||||
|
|
||||||
dr->bRequestType = reqtype;
|
dr->bRequestType = requesttype;
|
||||||
dr->bRequest = request;
|
dr->bRequest = request;
|
||||||
dr->wValue = cpu_to_le16(value);
|
dr->wValue = cpu_to_le16(value);
|
||||||
dr->wIndex = cpu_to_le16(index);
|
dr->wIndex = cpu_to_le16(index);
|
||||||
|
Loading…
Reference in New Issue
Block a user