rsi: USB tx headroom cleanup
authorKarun Eagalapati <karun256@gmail.com>
Thu, 6 Jul 2017 14:37:10 +0000 (20:07 +0530)
committerKalle Valo <kvalo@codeaurora.org>
Fri, 28 Jul 2017 14:22:35 +0000 (17:22 +0300)
USB headroom is added while submitting the data to URB as per
firmware's requirement. This logic is moved to rsi_usb_card_write() so
that caller need not worry about it.

Signed-off-by: Karun Eagalapati <karun256@gmail.com>
Signed-off-by: Amitkumar Karwar <amit.karwar@redpinesignals.com>
Signed-off-by: Kalle Valo <kvalo@codeaurora.org>
drivers/net/wireless/rsi/rsi_91x_usb.c

index 1d7bb9d9d09b48d7df3626e4ea5464f5dedc3aaa..25f619506b5888f0cd2ace54536defd544f53234 100644 (file)
  * Return: status: 0 on success, a negative error code on failure.
  */
 static int rsi_usb_card_write(struct rsi_hw *adapter,
-                             void *buf,
+                             u8 *buf,
                              u16 len,
                              u8 endpoint)
 {
        struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
        int status;
-       s32 transfer;
+       u8 *seg = dev->tx_buffer;
+       int transfer;
+       int ep = dev->bulkout_endpoint_addr[endpoint - 1];
 
+       memset(seg, 0, len + RSI_USB_TX_HEAD_ROOM);
+       memcpy(seg + RSI_USB_TX_HEAD_ROOM, buf, len);
+       len += RSI_USB_TX_HEAD_ROOM;
+       transfer = len;
        status = usb_bulk_msg(dev->usbdev,
-                             usb_sndbulkpipe(dev->usbdev,
-                             dev->bulkout_endpoint_addr[endpoint - 1]),
-                             buf,
-                             len,
+                             usb_sndbulkpipe(dev->usbdev, ep),
+                             (void *)seg,
+                             (int)len,
                              &transfer,
                              HZ * 5);
 
@@ -68,23 +73,19 @@ static int rsi_write_multiple(struct rsi_hw *adapter,
                              u8 *data,
                              u32 count)
 {
-       struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
-       u8 *seg = dev->tx_buffer;
+       struct rsi_91x_usbdev *dev =
+               (struct rsi_91x_usbdev *)adapter->rsi_dev;
 
-       if (dev->write_fail)
-               return 0;
+       if (!adapter)
+               return -ENODEV;
 
-       if (endpoint == MGMT_EP) {
-               memset(seg, 0, RSI_USB_TX_HEAD_ROOM);
-               memcpy(seg + RSI_USB_TX_HEAD_ROOM, data, count);
-       } else {
-               seg = ((u8 *)data - RSI_USB_TX_HEAD_ROOM);
-       }
+       if (endpoint == 0)
+               return -EINVAL;
+
+       if (dev->write_fail)
+               return -ENETDOWN;
 
-       return rsi_usb_card_write(adapter,
-                                 seg,
-                                 count + RSI_USB_TX_HEAD_ROOM,
-                                 endpoint);
+       return rsi_usb_card_write(adapter, data, count, endpoint);
 }
 
 /**