Commit 62210a26 authored by Manivannan Sadhasivam's avatar Manivannan Sadhasivam

bus: mhi: ep: Use slab allocator where applicable

Use slab allocator for allocating the memory for objects used frequently
and are of fixed size. This reduces the overheard associated with
kmalloc().
Suggested-by: default avatarAlex Elder <elder@linaro.org>
Link: https://lore.kernel.org/r/20231018122812.47261-1-manivannan.sadhasivam@linaro.orgSigned-off-by: default avatarManivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
parent eff9704f
...@@ -74,7 +74,7 @@ static int mhi_ep_send_completion_event(struct mhi_ep_cntrl *mhi_cntrl, struct m ...@@ -74,7 +74,7 @@ static int mhi_ep_send_completion_event(struct mhi_ep_cntrl *mhi_cntrl, struct m
struct mhi_ring_element *event; struct mhi_ring_element *event;
int ret; int ret;
event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL); event = kmem_cache_zalloc(mhi_cntrl->ev_ring_el_cache, GFP_KERNEL | GFP_DMA);
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
...@@ -83,7 +83,7 @@ static int mhi_ep_send_completion_event(struct mhi_ep_cntrl *mhi_cntrl, struct m ...@@ -83,7 +83,7 @@ static int mhi_ep_send_completion_event(struct mhi_ep_cntrl *mhi_cntrl, struct m
event->dword[1] = MHI_TRE_EV_DWORD1(ring->ch_id, MHI_PKT_TYPE_TX_EVENT); event->dword[1] = MHI_TRE_EV_DWORD1(ring->ch_id, MHI_PKT_TYPE_TX_EVENT);
ret = mhi_ep_send_event(mhi_cntrl, ring->er_index, event, MHI_TRE_DATA_GET_BEI(tre)); ret = mhi_ep_send_event(mhi_cntrl, ring->er_index, event, MHI_TRE_DATA_GET_BEI(tre));
kfree(event); kmem_cache_free(mhi_cntrl->ev_ring_el_cache, event);
return ret; return ret;
} }
...@@ -93,7 +93,7 @@ int mhi_ep_send_state_change_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_stat ...@@ -93,7 +93,7 @@ int mhi_ep_send_state_change_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_stat
struct mhi_ring_element *event; struct mhi_ring_element *event;
int ret; int ret;
event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL); event = kmem_cache_zalloc(mhi_cntrl->ev_ring_el_cache, GFP_KERNEL | GFP_DMA);
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
...@@ -101,7 +101,7 @@ int mhi_ep_send_state_change_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_stat ...@@ -101,7 +101,7 @@ int mhi_ep_send_state_change_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_stat
event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_STATE_CHANGE_EVENT); event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_STATE_CHANGE_EVENT);
ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0); ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
kfree(event); kmem_cache_free(mhi_cntrl->ev_ring_el_cache, event);
return ret; return ret;
} }
...@@ -111,7 +111,7 @@ int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_e ...@@ -111,7 +111,7 @@ int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_e
struct mhi_ring_element *event; struct mhi_ring_element *event;
int ret; int ret;
event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL); event = kmem_cache_zalloc(mhi_cntrl->ev_ring_el_cache, GFP_KERNEL | GFP_DMA);
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
...@@ -119,7 +119,7 @@ int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_e ...@@ -119,7 +119,7 @@ int mhi_ep_send_ee_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_ee_type exec_e
event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_EE_EVENT); event->dword[1] = MHI_SC_EV_DWORD1(MHI_PKT_TYPE_EE_EVENT);
ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0); ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
kfree(event); kmem_cache_free(mhi_cntrl->ev_ring_el_cache, event);
return ret; return ret;
} }
...@@ -130,7 +130,7 @@ static int mhi_ep_send_cmd_comp_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_e ...@@ -130,7 +130,7 @@ static int mhi_ep_send_cmd_comp_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_e
struct mhi_ring_element *event; struct mhi_ring_element *event;
int ret; int ret;
event = kzalloc(sizeof(struct mhi_ring_element), GFP_KERNEL); event = kmem_cache_zalloc(mhi_cntrl->ev_ring_el_cache, GFP_KERNEL | GFP_DMA);
if (!event) if (!event)
return -ENOMEM; return -ENOMEM;
...@@ -139,7 +139,7 @@ static int mhi_ep_send_cmd_comp_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_e ...@@ -139,7 +139,7 @@ static int mhi_ep_send_cmd_comp_event(struct mhi_ep_cntrl *mhi_cntrl, enum mhi_e
event->dword[1] = MHI_CC_EV_DWORD1(MHI_PKT_TYPE_CMD_COMPLETION_EVENT); event->dword[1] = MHI_CC_EV_DWORD1(MHI_PKT_TYPE_CMD_COMPLETION_EVENT);
ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0); ret = mhi_ep_send_event(mhi_cntrl, 0, event, 0);
kfree(event); kmem_cache_free(mhi_cntrl->ev_ring_el_cache, event);
return ret; return ret;
} }
...@@ -451,7 +451,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem ...@@ -451,7 +451,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem
mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result); mhi_chan->xfer_cb(mhi_chan->mhi_dev, &result);
} else { } else {
/* UL channel */ /* UL channel */
result.buf_addr = kzalloc(len, GFP_KERNEL); result.buf_addr = kmem_cache_zalloc(mhi_cntrl->tre_buf_cache, GFP_KERNEL | GFP_DMA);
if (!result.buf_addr) if (!result.buf_addr)
return -ENOMEM; return -ENOMEM;
...@@ -459,7 +459,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem ...@@ -459,7 +459,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem
ret = mhi_ep_read_channel(mhi_cntrl, ring, &result, len); ret = mhi_ep_read_channel(mhi_cntrl, ring, &result, len);
if (ret < 0) { if (ret < 0) {
dev_err(&mhi_chan->mhi_dev->dev, "Failed to read channel\n"); dev_err(&mhi_chan->mhi_dev->dev, "Failed to read channel\n");
kfree(result.buf_addr); kmem_cache_free(mhi_cntrl->tre_buf_cache, result.buf_addr);
return ret; return ret;
} }
...@@ -471,7 +471,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem ...@@ -471,7 +471,7 @@ static int mhi_ep_process_ch_ring(struct mhi_ep_ring *ring, struct mhi_ring_elem
/* Read until the ring becomes empty */ /* Read until the ring becomes empty */
} while (!mhi_ep_queue_is_empty(mhi_chan->mhi_dev, DMA_TO_DEVICE)); } while (!mhi_ep_queue_is_empty(mhi_chan->mhi_dev, DMA_TO_DEVICE));
kfree(result.buf_addr); kmem_cache_free(mhi_cntrl->tre_buf_cache, result.buf_addr);
} }
return 0; return 0;
...@@ -780,14 +780,14 @@ static void mhi_ep_ch_ring_worker(struct work_struct *work) ...@@ -780,14 +780,14 @@ static void mhi_ep_ch_ring_worker(struct work_struct *work)
if (ret) { if (ret) {
dev_err(dev, "Error updating write offset for ring\n"); dev_err(dev, "Error updating write offset for ring\n");
mutex_unlock(&chan->lock); mutex_unlock(&chan->lock);
kfree(itr); kmem_cache_free(mhi_cntrl->ring_item_cache, itr);
continue; continue;
} }
/* Sanity check to make sure there are elements in the ring */ /* Sanity check to make sure there are elements in the ring */
if (ring->rd_offset == ring->wr_offset) { if (ring->rd_offset == ring->wr_offset) {
mutex_unlock(&chan->lock); mutex_unlock(&chan->lock);
kfree(itr); kmem_cache_free(mhi_cntrl->ring_item_cache, itr);
continue; continue;
} }
...@@ -799,12 +799,12 @@ static void mhi_ep_ch_ring_worker(struct work_struct *work) ...@@ -799,12 +799,12 @@ static void mhi_ep_ch_ring_worker(struct work_struct *work)
dev_err(dev, "Error processing ring for channel (%u): %d\n", dev_err(dev, "Error processing ring for channel (%u): %d\n",
ring->ch_id, ret); ring->ch_id, ret);
mutex_unlock(&chan->lock); mutex_unlock(&chan->lock);
kfree(itr); kmem_cache_free(mhi_cntrl->ring_item_cache, itr);
continue; continue;
} }
mutex_unlock(&chan->lock); mutex_unlock(&chan->lock);
kfree(itr); kmem_cache_free(mhi_cntrl->ring_item_cache, itr);
} }
} }
...@@ -860,7 +860,7 @@ static void mhi_ep_queue_channel_db(struct mhi_ep_cntrl *mhi_cntrl, unsigned lon ...@@ -860,7 +860,7 @@ static void mhi_ep_queue_channel_db(struct mhi_ep_cntrl *mhi_cntrl, unsigned lon
u32 ch_id = ch_idx + i; u32 ch_id = ch_idx + i;
ring = &mhi_cntrl->mhi_chan[ch_id].ring; ring = &mhi_cntrl->mhi_chan[ch_id].ring;
item = kzalloc(sizeof(*item), GFP_ATOMIC); item = kmem_cache_zalloc(mhi_cntrl->ring_item_cache, GFP_ATOMIC);
if (!item) if (!item)
return; return;
...@@ -1407,6 +1407,29 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl, ...@@ -1407,6 +1407,29 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
goto err_free_ch; goto err_free_ch;
} }
mhi_cntrl->ev_ring_el_cache = kmem_cache_create("mhi_ep_event_ring_el",
sizeof(struct mhi_ring_element), 0,
SLAB_CACHE_DMA, NULL);
if (!mhi_cntrl->ev_ring_el_cache) {
ret = -ENOMEM;
goto err_free_cmd;
}
mhi_cntrl->tre_buf_cache = kmem_cache_create("mhi_ep_tre_buf", MHI_EP_DEFAULT_MTU, 0,
SLAB_CACHE_DMA, NULL);
if (!mhi_cntrl->tre_buf_cache) {
ret = -ENOMEM;
goto err_destroy_ev_ring_el_cache;
}
mhi_cntrl->ring_item_cache = kmem_cache_create("mhi_ep_ring_item",
sizeof(struct mhi_ep_ring_item), 0,
0, NULL);
if (!mhi_cntrl->ev_ring_el_cache) {
ret = -ENOMEM;
goto err_destroy_tre_buf_cache;
}
INIT_WORK(&mhi_cntrl->state_work, mhi_ep_state_worker); INIT_WORK(&mhi_cntrl->state_work, mhi_ep_state_worker);
INIT_WORK(&mhi_cntrl->reset_work, mhi_ep_reset_worker); INIT_WORK(&mhi_cntrl->reset_work, mhi_ep_reset_worker);
INIT_WORK(&mhi_cntrl->cmd_ring_work, mhi_ep_cmd_ring_worker); INIT_WORK(&mhi_cntrl->cmd_ring_work, mhi_ep_cmd_ring_worker);
...@@ -1415,7 +1438,7 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl, ...@@ -1415,7 +1438,7 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
mhi_cntrl->wq = alloc_workqueue("mhi_ep_wq", 0, 0); mhi_cntrl->wq = alloc_workqueue("mhi_ep_wq", 0, 0);
if (!mhi_cntrl->wq) { if (!mhi_cntrl->wq) {
ret = -ENOMEM; ret = -ENOMEM;
goto err_free_cmd; goto err_destroy_ring_item_cache;
} }
INIT_LIST_HEAD(&mhi_cntrl->st_transition_list); INIT_LIST_HEAD(&mhi_cntrl->st_transition_list);
...@@ -1474,6 +1497,12 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl, ...@@ -1474,6 +1497,12 @@ int mhi_ep_register_controller(struct mhi_ep_cntrl *mhi_cntrl,
ida_free(&mhi_ep_cntrl_ida, mhi_cntrl->index); ida_free(&mhi_ep_cntrl_ida, mhi_cntrl->index);
err_destroy_wq: err_destroy_wq:
destroy_workqueue(mhi_cntrl->wq); destroy_workqueue(mhi_cntrl->wq);
err_destroy_ring_item_cache:
kmem_cache_destroy(mhi_cntrl->ring_item_cache);
err_destroy_ev_ring_el_cache:
kmem_cache_destroy(mhi_cntrl->ev_ring_el_cache);
err_destroy_tre_buf_cache:
kmem_cache_destroy(mhi_cntrl->tre_buf_cache);
err_free_cmd: err_free_cmd:
kfree(mhi_cntrl->mhi_cmd); kfree(mhi_cntrl->mhi_cmd);
err_free_ch: err_free_ch:
...@@ -1495,6 +1524,9 @@ void mhi_ep_unregister_controller(struct mhi_ep_cntrl *mhi_cntrl) ...@@ -1495,6 +1524,9 @@ void mhi_ep_unregister_controller(struct mhi_ep_cntrl *mhi_cntrl)
free_irq(mhi_cntrl->irq, mhi_cntrl); free_irq(mhi_cntrl->irq, mhi_cntrl);
kmem_cache_destroy(mhi_cntrl->tre_buf_cache);
kmem_cache_destroy(mhi_cntrl->ev_ring_el_cache);
kmem_cache_destroy(mhi_cntrl->ring_item_cache);
kfree(mhi_cntrl->mhi_cmd); kfree(mhi_cntrl->mhi_cmd);
kfree(mhi_cntrl->mhi_chan); kfree(mhi_cntrl->mhi_chan);
......
...@@ -128,6 +128,9 @@ struct mhi_ep_cntrl { ...@@ -128,6 +128,9 @@ struct mhi_ep_cntrl {
struct work_struct reset_work; struct work_struct reset_work;
struct work_struct cmd_ring_work; struct work_struct cmd_ring_work;
struct work_struct ch_ring_work; struct work_struct ch_ring_work;
struct kmem_cache *ring_item_cache;
struct kmem_cache *ev_ring_el_cache;
struct kmem_cache *tre_buf_cache;
void (*raise_irq)(struct mhi_ep_cntrl *mhi_cntrl, u32 vector); void (*raise_irq)(struct mhi_ep_cntrl *mhi_cntrl, u32 vector);
int (*alloc_map)(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, phys_addr_t *phys_ptr, int (*alloc_map)(struct mhi_ep_cntrl *mhi_cntrl, u64 pci_addr, phys_addr_t *phys_ptr,
......
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