提交 1c9de08f 编写于 作者: A Andrea Parri (Microsoft) 提交者: Wei Liu

Drivers: hv: vmbus: Refactor the ring-buffer iterator functions

With no users of hv_pkt_iter_next_raw() and no "external" users of
hv_pkt_iter_first_raw(), the iterator functions can be refactored
and simplified to remove some indirection/code.
Signed-off-by: NAndrea Parri (Microsoft) <parri.andrea@gmail.com>
Reviewed-by: NMichael Kelley <mikelley@microsoft.com>
Link: https://lore.kernel.org/r/20220428145107.7878-6-parri.andrea@gmail.comSigned-off-by: NWei Liu <wei.liu@kernel.org>
上级 da795eb2
...@@ -429,7 +429,7 @@ int hv_ringbuffer_read(struct vmbus_channel *channel, ...@@ -429,7 +429,7 @@ int hv_ringbuffer_read(struct vmbus_channel *channel,
memcpy(buffer, (const char *)desc + offset, packetlen); memcpy(buffer, (const char *)desc + offset, packetlen);
/* Advance ring index to next packet descriptor */ /* Advance ring index to next packet descriptor */
__hv_pkt_iter_next(channel, desc, true); __hv_pkt_iter_next(channel, desc);
/* Notify host of update */ /* Notify host of update */
hv_pkt_iter_close(channel); hv_pkt_iter_close(channel);
...@@ -464,22 +464,6 @@ static u32 hv_pkt_iter_avail(const struct hv_ring_buffer_info *rbi) ...@@ -464,22 +464,6 @@ static u32 hv_pkt_iter_avail(const struct hv_ring_buffer_info *rbi)
return (rbi->ring_datasize - priv_read_loc) + write_loc; return (rbi->ring_datasize - priv_read_loc) + write_loc;
} }
/*
* Get first vmbus packet without copying it out of the ring buffer
*/
struct vmpacket_descriptor *hv_pkt_iter_first_raw(struct vmbus_channel *channel)
{
struct hv_ring_buffer_info *rbi = &channel->inbound;
hv_debug_delay_test(channel, MESSAGE_DELAY);
if (hv_pkt_iter_avail(rbi) < sizeof(struct vmpacket_descriptor))
return NULL;
return (struct vmpacket_descriptor *)(hv_get_ring_buffer(rbi) + rbi->priv_read_index);
}
EXPORT_SYMBOL_GPL(hv_pkt_iter_first_raw);
/* /*
* Get first vmbus packet from ring buffer after read_index * Get first vmbus packet from ring buffer after read_index
* *
...@@ -491,11 +475,14 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel) ...@@ -491,11 +475,14 @@ struct vmpacket_descriptor *hv_pkt_iter_first(struct vmbus_channel *channel)
struct vmpacket_descriptor *desc, *desc_copy; struct vmpacket_descriptor *desc, *desc_copy;
u32 bytes_avail, pkt_len, pkt_offset; u32 bytes_avail, pkt_len, pkt_offset;
desc = hv_pkt_iter_first_raw(channel); hv_debug_delay_test(channel, MESSAGE_DELAY);
if (!desc)
bytes_avail = hv_pkt_iter_avail(rbi);
if (bytes_avail < sizeof(struct vmpacket_descriptor))
return NULL; return NULL;
bytes_avail = min(rbi->pkt_buffer_size, bytes_avail);
bytes_avail = min(rbi->pkt_buffer_size, hv_pkt_iter_avail(rbi)); desc = (struct vmpacket_descriptor *)(hv_get_ring_buffer(rbi) + rbi->priv_read_index);
/* /*
* Ensure the compiler does not use references to incoming Hyper-V values (which * Ensure the compiler does not use references to incoming Hyper-V values (which
...@@ -542,8 +529,7 @@ EXPORT_SYMBOL_GPL(hv_pkt_iter_first); ...@@ -542,8 +529,7 @@ EXPORT_SYMBOL_GPL(hv_pkt_iter_first);
*/ */
struct vmpacket_descriptor * struct vmpacket_descriptor *
__hv_pkt_iter_next(struct vmbus_channel *channel, __hv_pkt_iter_next(struct vmbus_channel *channel,
const struct vmpacket_descriptor *desc, const struct vmpacket_descriptor *desc)
bool copy)
{ {
struct hv_ring_buffer_info *rbi = &channel->inbound; struct hv_ring_buffer_info *rbi = &channel->inbound;
u32 packetlen = desc->len8 << 3; u32 packetlen = desc->len8 << 3;
...@@ -556,7 +542,7 @@ __hv_pkt_iter_next(struct vmbus_channel *channel, ...@@ -556,7 +542,7 @@ __hv_pkt_iter_next(struct vmbus_channel *channel,
rbi->priv_read_index -= dsize; rbi->priv_read_index -= dsize;
/* more data? */ /* more data? */
return copy ? hv_pkt_iter_first(channel) : hv_pkt_iter_first_raw(channel); return hv_pkt_iter_first(channel);
} }
EXPORT_SYMBOL_GPL(__hv_pkt_iter_next); EXPORT_SYMBOL_GPL(__hv_pkt_iter_next);
......
...@@ -1706,55 +1706,28 @@ static inline u32 hv_pkt_len(const struct vmpacket_descriptor *desc) ...@@ -1706,55 +1706,28 @@ static inline u32 hv_pkt_len(const struct vmpacket_descriptor *desc)
return desc->len8 << 3; return desc->len8 << 3;
} }
struct vmpacket_descriptor *
hv_pkt_iter_first_raw(struct vmbus_channel *channel);
struct vmpacket_descriptor * struct vmpacket_descriptor *
hv_pkt_iter_first(struct vmbus_channel *channel); hv_pkt_iter_first(struct vmbus_channel *channel);
struct vmpacket_descriptor * struct vmpacket_descriptor *
__hv_pkt_iter_next(struct vmbus_channel *channel, __hv_pkt_iter_next(struct vmbus_channel *channel,
const struct vmpacket_descriptor *pkt, const struct vmpacket_descriptor *pkt);
bool copy);
void hv_pkt_iter_close(struct vmbus_channel *channel); void hv_pkt_iter_close(struct vmbus_channel *channel);
static inline struct vmpacket_descriptor * static inline struct vmpacket_descriptor *
hv_pkt_iter_next_pkt(struct vmbus_channel *channel, hv_pkt_iter_next(struct vmbus_channel *channel,
const struct vmpacket_descriptor *pkt, const struct vmpacket_descriptor *pkt)
bool copy)
{ {
struct vmpacket_descriptor *nxt; struct vmpacket_descriptor *nxt;
nxt = __hv_pkt_iter_next(channel, pkt, copy); nxt = __hv_pkt_iter_next(channel, pkt);
if (!nxt) if (!nxt)
hv_pkt_iter_close(channel); hv_pkt_iter_close(channel);
return nxt; return nxt;
} }
/*
* Get next packet descriptor without copying it out of the ring buffer
* If at end of list, return NULL and update host.
*/
static inline struct vmpacket_descriptor *
hv_pkt_iter_next_raw(struct vmbus_channel *channel,
const struct vmpacket_descriptor *pkt)
{
return hv_pkt_iter_next_pkt(channel, pkt, false);
}
/*
* Get next packet descriptor from iterator
* If at end of list, return NULL and update host.
*/
static inline struct vmpacket_descriptor *
hv_pkt_iter_next(struct vmbus_channel *channel,
const struct vmpacket_descriptor *pkt)
{
return hv_pkt_iter_next_pkt(channel, pkt, true);
}
#define foreach_vmbus_pkt(pkt, channel) \ #define foreach_vmbus_pkt(pkt, channel) \
for (pkt = hv_pkt_iter_first(channel); pkt; \ for (pkt = hv_pkt_iter_first(channel); pkt; \
pkt = hv_pkt_iter_next(channel, pkt)) pkt = hv_pkt_iter_next(channel, pkt))
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册