From: Dongsheng Yang <dongsheng.yang@linux.dev>
To: axboe@kernel.dk, dan.j.williams@intel.com,
gregory.price@memverge.com, John@groves.net,
Jonathan.Cameron@Huawei.com, bbhushan2@marvell.com,
chaitanyak@nvidia.com, rdunlap@infradead.org
Cc: linux-block@vger.kernel.org, linux-kernel@vger.kernel.org,
linux-cxl@vger.kernel.org,
Dongsheng Yang <dongsheng.yang@linux.dev>
Subject: [PATCH v1 4/7] cbd: introduce cbd_channel
Date: Tue, 9 Jul 2024 13:03:40 +0000 [thread overview]
Message-ID: <20240709130343.858363-5-dongsheng.yang@linux.dev> (raw)
In-Reply-To: <20240709130343.858363-1-dongsheng.yang@linux.dev>
The "cbd_channel" is the component responsible for the interaction
between the blkdev and the backend. It mainly provides the functions
"cbdc_copy_to_bio", "cbdc_copy_from_bio" and "cbd_channel_crc"
If the blkdev or backend is alive, that means there is active
user for this channel, then channel is alive.
Signed-off-by: Dongsheng Yang <dongsheng.yang@linux.dev>
---
drivers/block/cbd/cbd_channel.c | 153 ++++++++++++++++++++++++++++++++
1 file changed, 153 insertions(+)
create mode 100644 drivers/block/cbd/cbd_channel.c
diff --git a/drivers/block/cbd/cbd_channel.c b/drivers/block/cbd/cbd_channel.c
new file mode 100644
index 000000000000..9a63e98b0c13
--- /dev/null
+++ b/drivers/block/cbd/cbd_channel.c
@@ -0,0 +1,153 @@
+#include "cbd_internal.h"
+
+static void channel_format(struct cbd_transport *cbdt, u32 id)
+{
+ struct cbd_channel_info *channel_info = cbdt_get_channel_info(cbdt, id);
+
+ cbdt_zero_range(cbdt, channel_info, CBDC_META_SIZE);
+}
+
+int cbd_get_empty_channel_id(struct cbd_transport *cbdt, u32 *id)
+{
+ int ret;
+
+ ret = cbdt_get_empty_segment_id(cbdt, id);
+ if (ret)
+ return ret;
+
+ channel_format(cbdt, *id);
+
+ return 0;
+}
+
+void cbdc_copy_to_bio(struct cbd_channel *channel,
+ u64 data_off, u32 data_len, struct bio *bio)
+{
+ struct bio_vec bv;
+ struct bvec_iter iter;
+ void *src, *dst;
+ u64 data_head = data_off;
+ u32 to_copy, page_off = 0;
+
+next:
+ bio_for_each_segment(bv, bio, iter) {
+ dst = kmap_local_page(bv.bv_page);
+ page_off = bv.bv_offset;
+again:
+ if (data_head >= CBDC_DATA_SIZE)
+ data_head %= CBDC_DATA_SIZE;
+
+ flush_dcache_page(bv.bv_page);
+ src = channel->data + data_head;
+ to_copy = min(bv.bv_offset + bv.bv_len - page_off,
+ CBDC_DATA_SIZE - data_head);
+ memcpy_flushcache(dst + page_off, src, to_copy);
+
+ /* advance */
+ data_head += to_copy;
+ page_off += to_copy;
+
+ /* more data in this bv page */
+ if (page_off < bv.bv_offset + bv.bv_len)
+ goto again;
+ kunmap_local(dst);
+ }
+
+ if (bio->bi_next) {
+ bio = bio->bi_next;
+ goto next;
+ }
+}
+
+void cbdc_copy_from_bio(struct cbd_channel *channel,
+ u64 data_off, u32 data_len, struct bio *bio)
+{
+ struct bio_vec bv;
+ struct bvec_iter iter;
+ void *src, *dst;
+ u64 data_head = data_off;
+ u32 to_copy, page_off = 0;
+
+next:
+ bio_for_each_segment(bv, bio, iter) {
+ src = kmap_local_page(bv.bv_page);
+ page_off = bv.bv_offset;
+again:
+ if (data_head >= CBDC_DATA_SIZE)
+ data_head %= CBDC_DATA_SIZE;
+
+ dst = channel->data + data_head;
+ to_copy = min(bv.bv_offset + bv.bv_len - page_off,
+ CBDC_DATA_SIZE - data_head);
+
+ memcpy_flushcache(dst, src + page_off, to_copy);
+ flush_dcache_page(bv.bv_page);
+
+ /* advance */
+ data_head += to_copy;
+ page_off += to_copy;
+
+ /* more data in this bv page */
+ if (page_off < bv.bv_offset + bv.bv_len)
+ goto again;
+ kunmap_local(src);
+ }
+
+ if (bio->bi_next) {
+ bio = bio->bi_next;
+ goto next;
+ }
+}
+
+u32 cbd_channel_crc(struct cbd_channel *channel, u64 data_off, u32 data_len)
+{
+ u32 crc = 0;
+ u32 crc_size;
+ u64 data_head = data_off;
+
+ while (data_len) {
+ if (data_head >= CBDC_DATA_SIZE)
+ data_head %= CBDC_DATA_SIZE;
+
+ crc_size = min(CBDC_DATA_SIZE - data_head, data_len);
+
+ crc = crc32(crc, channel->data + data_head, crc_size);
+
+ data_len -= crc_size;
+ data_head += crc_size;
+ }
+
+ return crc;
+}
+
+ssize_t cbd_channel_seg_detail_show(struct cbd_channel_info *channel_info, char *buf)
+{
+ return sprintf(buf, "channel backend id: %u\n"
+ "channel blkdev id: %u\n",
+ channel_info->backend_id,
+ channel_info->blkdev_id);
+}
+
+
+void cbd_channel_init(struct cbd_channel *channel, struct cbd_transport *cbdt, u32 seg_id)
+{
+ struct cbd_channel_info *channel_info = cbdt_get_channel_info(cbdt, seg_id);
+
+ cbd_segment_init(&channel->segment, cbdt, seg_id);
+
+ channel->cbdt = cbdt;
+ channel->channel_info = channel_info;
+ channel->seg_id = seg_id;
+ channel->submr = (void *)channel_info + CBDC_SUBMR_OFF;
+ channel->compr = (void *)channel_info + CBDC_COMPR_OFF;
+ channel->data = (void *)channel_info + CBDC_DATA_OFF;
+ channel->data_size = CBDC_DATA_SIZE;
+
+ spin_lock_init(&channel->submr_lock);
+ spin_lock_init(&channel->compr_lock);
+}
+
+void cbd_channel_exit(struct cbd_channel *channel)
+{
+ cbd_segment_exit(&channel->segment);
+}
--
2.34.1
next prev parent reply other threads:[~2024-07-09 13:04 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-07-09 13:03 [PATCH v1 0/7] Introduce CBD (CXL Block Device) Dongsheng Yang
2024-07-09 13:03 ` [PATCH v1 1/7] cbd: introduce cbd_transport Dongsheng Yang
2024-07-09 13:03 ` [PATCH v1 2/7] cbd: introduce cbd_host Dongsheng Yang
2024-07-09 13:03 ` [PATCH v1 3/7] cbd: introduce cbd_segment Dongsheng Yang
2024-07-09 13:03 ` Dongsheng Yang [this message]
2024-07-09 13:03 ` [PATCH v1 5/7] cbd: introduce cbd_blkdev Dongsheng Yang
2024-07-09 13:03 ` [PATCH v1 6/7] cbd: introduce cbd_backend Dongsheng Yang
2024-07-09 13:03 ` [PATCH v1 7/7] block: Init for CBD(CXL Block Device) module Dongsheng Yang
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20240709130343.858363-5-dongsheng.yang@linux.dev \
--to=dongsheng.yang@linux.dev \
--cc=John@groves.net \
--cc=Jonathan.Cameron@Huawei.com \
--cc=axboe@kernel.dk \
--cc=bbhushan2@marvell.com \
--cc=chaitanyak@nvidia.com \
--cc=dan.j.williams@intel.com \
--cc=gregory.price@memverge.com \
--cc=linux-block@vger.kernel.org \
--cc=linux-cxl@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=rdunlap@infradead.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox