Commit 1100f81b authored by Prameela Rani Garnepudi's avatar Prameela Rani Garnepudi Committed by Kalle Valo

rsi: add rx control block to handle rx packets in USB

Rx bluetooth endpoint shall be added in further patches. Rx control
block is introduced here to handle Rx packets properly. Separate
function is written to initialize the RX control blocks.
Signed-off-by: default avatarPrameela Rani Garnepudi <prameela.j04cs@gmail.com>
Signed-off-by: default avatarSiva Rebbagondla <siva.rebbagondla@redpinesignals.com>
Signed-off-by: default avatarAmitkumar Karwar <amit.karwar@redpinesignals.com>
Signed-off-by: default avatarKalle Valo <kvalo@codeaurora.org>
parent a9eab62d
...@@ -137,7 +137,7 @@ static struct sk_buff *rsi_prepare_skb(struct rsi_common *common, ...@@ -137,7 +137,7 @@ static struct sk_buff *rsi_prepare_skb(struct rsi_common *common,
* *
* Return: 0 on success, -1 on failure. * Return: 0 on success, -1 on failure.
*/ */
int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len) int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len)
{ {
u8 *frame_desc = NULL, extended_desc = 0; u8 *frame_desc = NULL, extended_desc = 0;
u32 index, length = 0, queueno = 0; u32 index, length = 0, queueno = 0;
...@@ -146,7 +146,7 @@ int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len) ...@@ -146,7 +146,7 @@ int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len)
index = 0; index = 0;
do { do {
frame_desc = &common->rx_data_pkt[index]; frame_desc = &rx_pkt[index];
actual_length = *(u16 *)&frame_desc[0]; actual_length = *(u16 *)&frame_desc[0];
offset = *(u16 *)&frame_desc[2]; offset = *(u16 *)&frame_desc[2];
......
...@@ -118,7 +118,7 @@ static int rsi_process_pkt(struct rsi_common *common) ...@@ -118,7 +118,7 @@ static int rsi_process_pkt(struct rsi_common *common)
goto fail; goto fail;
} }
status = rsi_read_pkt(common, rcv_pkt_len); status = rsi_read_pkt(common, common->rx_data_pkt, rcv_pkt_len);
fail: fail:
kfree(common->rx_data_pkt); kfree(common->rx_data_pkt);
......
...@@ -247,12 +247,13 @@ static int rsi_usb_reg_write(struct usb_device *usbdev, ...@@ -247,12 +247,13 @@ static int rsi_usb_reg_write(struct usb_device *usbdev,
*/ */
static void rsi_rx_done_handler(struct urb *urb) static void rsi_rx_done_handler(struct urb *urb)
{ {
struct rsi_hw *adapter = urb->context; struct rx_usb_ctrl_block *rx_cb = urb->context;
struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev; struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)rx_cb->data;
if (urb->status) if (urb->status)
return; return;
rx_cb->pend = 1;
rsi_set_event(&dev->rx_thread.event); rsi_set_event(&dev->rx_thread.event);
} }
...@@ -262,10 +263,11 @@ static void rsi_rx_done_handler(struct urb *urb) ...@@ -262,10 +263,11 @@ static void rsi_rx_done_handler(struct urb *urb)
* *
* Return: 0 on success, a negative error code on failure. * Return: 0 on success, a negative error code on failure.
*/ */
static int rsi_rx_urb_submit(struct rsi_hw *adapter) static int rsi_rx_urb_submit(struct rsi_hw *adapter, u8 ep_num)
{ {
struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev; struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
struct urb *urb = dev->rx_usb_urb[0]; struct rx_usb_ctrl_block *rx_cb = &dev->rx_cb[ep_num - 1];
struct urb *urb = rx_cb->rx_urb;
int status; int status;
usb_fill_bulk_urb(urb, usb_fill_bulk_urb(urb,
...@@ -275,7 +277,7 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter) ...@@ -275,7 +277,7 @@ static int rsi_rx_urb_submit(struct rsi_hw *adapter)
urb->transfer_buffer, urb->transfer_buffer,
3000, 3000,
rsi_rx_done_handler, rsi_rx_done_handler,
adapter); rx_cb);
status = usb_submit_urb(urb, GFP_KERNEL); status = usb_submit_urb(urb, GFP_KERNEL);
if (status) if (status)
...@@ -484,14 +486,54 @@ static struct rsi_host_intf_ops usb_host_intf_ops = { ...@@ -484,14 +486,54 @@ static struct rsi_host_intf_ops usb_host_intf_ops = {
*/ */
static void rsi_deinit_usb_interface(struct rsi_hw *adapter) static void rsi_deinit_usb_interface(struct rsi_hw *adapter)
{ {
u8 idx;
struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev; struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
rsi_kill_thread(&dev->rx_thread); rsi_kill_thread(&dev->rx_thread);
usb_free_urb(dev->rx_usb_urb[0]);
for (idx = 0; idx < MAX_RX_URBS; idx++) {
usb_free_urb(dev->rx_cb[idx].rx_urb);
kfree(dev->rx_cb[idx].rx_buffer);
}
kfree(adapter->priv->rx_data_pkt); kfree(adapter->priv->rx_data_pkt);
kfree(dev->tx_buffer); kfree(dev->tx_buffer);
} }
static int rsi_usb_init_rx(struct rsi_hw *adapter)
{
struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
struct rx_usb_ctrl_block *rx_cb;
u8 idx;
for (idx = 0; idx < MAX_RX_URBS; idx++) {
rx_cb = &dev->rx_cb[idx];
rx_cb->rx_buffer = kzalloc(RSI_USB_BUF_SIZE * 2,
GFP_KERNEL);
if (!rx_cb->rx_buffer)
goto err;
rx_cb->rx_urb = usb_alloc_urb(0, GFP_KERNEL);
if (!rx_cb->rx_urb) {
rsi_dbg(ERR_ZONE, "Failed alloc rx urb[%d]\n", idx);
goto err;
}
rx_cb->rx_urb->transfer_buffer = rx_cb->rx_buffer;
rx_cb->ep_num = idx + 1;
rx_cb->data = (void *)dev;
}
return 0;
err:
for (idx = 0; idx < MAX_RX_URBS; idx++) {
kfree(dev->rx_cb[idx].rx_buffer);
kfree(dev->rx_cb[idx].rx_urb);
}
return -1;
}
/** /**
* rsi_init_usb_interface() - This function initializes the usb interface. * rsi_init_usb_interface() - This function initializes the usb interface.
* @adapter: Pointer to the adapter structure. * @adapter: Pointer to the adapter structure.
...@@ -504,7 +546,7 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter, ...@@ -504,7 +546,7 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
{ {
struct rsi_91x_usbdev *rsi_dev; struct rsi_91x_usbdev *rsi_dev;
struct rsi_common *common = adapter->priv; struct rsi_common *common = adapter->priv;
int status; int status, i;
rsi_dev = kzalloc(sizeof(*rsi_dev), GFP_KERNEL); rsi_dev = kzalloc(sizeof(*rsi_dev), GFP_KERNEL);
if (!rsi_dev) if (!rsi_dev)
...@@ -531,12 +573,12 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter, ...@@ -531,12 +573,12 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
status = -ENOMEM; status = -ENOMEM;
goto fail_tx; goto fail_tx;
} }
rsi_dev->rx_usb_urb[0] = usb_alloc_urb(0, GFP_KERNEL);
if (!rsi_dev->rx_usb_urb[0]) { if (rsi_usb_init_rx(adapter)) {
status = -ENOMEM; rsi_dbg(ERR_ZONE, "Failed to init RX handle\n");
goto fail_rx; return -ENOMEM;
} }
rsi_dev->rx_usb_urb[0]->transfer_buffer = adapter->priv->rx_data_pkt;
rsi_dev->tx_blk_size = 252; rsi_dev->tx_blk_size = 252;
adapter->block_size = rsi_dev->tx_blk_size; adapter->block_size = rsi_dev->tx_blk_size;
...@@ -564,9 +606,10 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter, ...@@ -564,9 +606,10 @@ static int rsi_init_usb_interface(struct rsi_hw *adapter,
return 0; return 0;
fail_thread: fail_thread:
usb_free_urb(rsi_dev->rx_usb_urb[0]); for (i = 0; i < MAX_RX_URBS; i++) {
fail_rx: kfree(rsi_dev->rx_cb[i].rx_buffer);
kfree(rsi_dev->tx_buffer); kfree(rsi_dev->rx_cb[i].rx_urb);
}
fail_tx: fail_tx:
kfree(common->rx_data_pkt); kfree(common->rx_data_pkt);
return status; return status;
...@@ -698,7 +741,7 @@ static int rsi_probe(struct usb_interface *pfunction, ...@@ -698,7 +741,7 @@ static int rsi_probe(struct usb_interface *pfunction,
rsi_dbg(INIT_ZONE, "%s: Device Init Done\n", __func__); rsi_dbg(INIT_ZONE, "%s: Device Init Done\n", __func__);
} }
status = rsi_rx_urb_submit(adapter); status = rsi_rx_urb_submit(adapter, WLAN_EP);
if (status) if (status)
goto err1; goto err1;
......
...@@ -29,7 +29,8 @@ void rsi_usb_rx_thread(struct rsi_common *common) ...@@ -29,7 +29,8 @@ void rsi_usb_rx_thread(struct rsi_common *common)
{ {
struct rsi_hw *adapter = common->priv; struct rsi_hw *adapter = common->priv;
struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev; struct rsi_91x_usbdev *dev = (struct rsi_91x_usbdev *)adapter->rsi_dev;
int status; struct rx_usb_ctrl_block *rx_cb;
int status, idx;
do { do {
rsi_wait_event(&dev->rx_thread.event, EVENT_WAIT_FOREVER); rsi_wait_event(&dev->rx_thread.event, EVENT_WAIT_FOREVER);
...@@ -37,20 +38,30 @@ void rsi_usb_rx_thread(struct rsi_common *common) ...@@ -37,20 +38,30 @@ void rsi_usb_rx_thread(struct rsi_common *common)
if (atomic_read(&dev->rx_thread.thread_done)) if (atomic_read(&dev->rx_thread.thread_done))
goto out; goto out;
mutex_lock(&common->rx_lock); for (idx = 0; idx < MAX_RX_URBS; idx++) {
status = rsi_read_pkt(common, 0); rx_cb = &dev->rx_cb[idx];
if (status) { if (!rx_cb->pend)
rsi_dbg(ERR_ZONE, "%s: Failed To read data", __func__); continue;
mutex_lock(&common->rx_lock);
status = rsi_read_pkt(common, rx_cb->rx_buffer, 0);
if (status) {
rsi_dbg(ERR_ZONE, "%s: Failed To read data",
__func__);
mutex_unlock(&common->rx_lock);
break;
}
rx_cb->pend = 0;
mutex_unlock(&common->rx_lock); mutex_unlock(&common->rx_lock);
return;
if (adapter->rx_urb_submit(adapter, rx_cb->ep_num)) {
rsi_dbg(ERR_ZONE,
"%s: Failed in urb submission",
__func__);
return;
}
} }
mutex_unlock(&common->rx_lock);
rsi_reset_event(&dev->rx_thread.event); rsi_reset_event(&dev->rx_thread.event);
if (adapter->rx_urb_submit(adapter)) {
rsi_dbg(ERR_ZONE,
"%s: Failed in urb submission", __func__);
return;
}
} while (1); } while (1);
out: out:
......
...@@ -82,7 +82,7 @@ void rsi_mac80211_detach(struct rsi_hw *hw); ...@@ -82,7 +82,7 @@ void rsi_mac80211_detach(struct rsi_hw *hw);
u16 rsi_get_connected_channel(struct ieee80211_vif *vif); u16 rsi_get_connected_channel(struct ieee80211_vif *vif);
struct rsi_hw *rsi_91x_init(void); struct rsi_hw *rsi_91x_init(void);
void rsi_91x_deinit(struct rsi_hw *adapter); void rsi_91x_deinit(struct rsi_hw *adapter);
int rsi_read_pkt(struct rsi_common *common, s32 rcv_pkt_len); int rsi_read_pkt(struct rsi_common *common, u8 *rx_pkt, s32 rcv_pkt_len);
#ifdef CONFIG_PM #ifdef CONFIG_PM
int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan); int rsi_config_wowlan(struct rsi_hw *adapter, struct cfg80211_wowlan *wowlan);
#endif #endif
......
...@@ -343,7 +343,7 @@ struct rsi_hw { ...@@ -343,7 +343,7 @@ struct rsi_hw {
void *rsi_dev; void *rsi_dev;
struct rsi_host_intf_ops *host_intf_ops; struct rsi_host_intf_ops *host_intf_ops;
int (*check_hw_queue_status)(struct rsi_hw *adapter, u8 q_num); int (*check_hw_queue_status)(struct rsi_hw *adapter, u8 q_num);
int (*rx_urb_submit)(struct rsi_hw *adapter); int (*rx_urb_submit)(struct rsi_hw *adapter, u8 ep_num);
int (*determine_event_timeout)(struct rsi_hw *adapter); int (*determine_event_timeout)(struct rsi_hw *adapter);
}; };
......
...@@ -39,12 +39,20 @@ ...@@ -39,12 +39,20 @@
#define RSI_USB_BUF_SIZE 4096 #define RSI_USB_BUF_SIZE 4096
#define RSI_USB_CTRL_BUF_SIZE 0x04 #define RSI_USB_CTRL_BUF_SIZE 0x04
struct rx_usb_ctrl_block {
u8 *data;
struct urb *rx_urb;
u8 *rx_buffer;
u8 ep_num;
u8 pend;
};
struct rsi_91x_usbdev { struct rsi_91x_usbdev {
struct rsi_thread rx_thread; struct rsi_thread rx_thread;
u8 endpoint; u8 endpoint;
struct usb_device *usbdev; struct usb_device *usbdev;
struct usb_interface *pfunction; struct usb_interface *pfunction;
struct urb *rx_usb_urb[MAX_RX_URBS]; struct rx_usb_ctrl_block rx_cb[MAX_RX_URBS];
u8 *tx_buffer; u8 *tx_buffer;
__le16 bulkin_size; __le16 bulkin_size;
u8 bulkin_endpoint_addr; u8 bulkin_endpoint_addr;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment