NDN-DPDK
High-Speed Named Data Networking Forwarder
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
bdev.h
Go to the documentation of this file.
1 #ifndef NDNDPDK_DPDK_BDEV_H
2 #define NDNDPDK_DPDK_BDEV_H
3 
6 #include "bdev-enum.h"
7 #include "mbuf.h"
8 #include <spdk/bdev.h>
9 
10 enum {
13 
16 };
17 
18 extern uint8_t* BdevFiller_;
19 
21 typedef struct BdevStoredPacket {
22  uint16_t pktLen;
23  uint16_t saveTotal;
27 
28 __attribute__((nonnull)) static __rte_always_inline void
29 BdevStoredPacket_Copy(BdevStoredPacket* restrict dst, const BdevStoredPacket* restrict src) {
30  if (src->pktLen == src->saveTotal) { // no head or tail
31  goto COPY0;
32  } else if (src->saveLen[1] == 0) { // single segment
33  dst->headTail[0] = src->headTail[0];
34  dst->headTail[1] = src->headTail[1];
35  COPY0:
36  dst->pktLen = src->pktLen;
37  dst->saveTotal = src->saveTotal;
38  dst->saveLen[0] = src->saveLen[0];
39  dst->saveLen[1] = src->saveLen[1];
40  } else { // multiple segments
41  *dst = *src;
42  }
43 }
44 
46 __attribute__((nonnull)) static inline uint32_t
47 BdevStoredPacket_ComputeBlockCount(BdevStoredPacket* sp) {
48  return SPDK_CEIL_DIV(sp->saveTotal, BdevBlockSize);
49 }
50 
51 typedef struct BdevRequest BdevRequest;
52 typedef void (*BdevRequestCb)(BdevRequest* req, int res);
53 
55 struct BdevRequest {
56  struct rte_mbuf* pkt;
59  struct rte_mbuf* bounce_;
60  struct iovec iov_[BdevMaxMbufSegs + 1];
61 };
62 
64 typedef struct Bdev {
65  struct spdk_bdev_desc* desc;
66  struct rte_mempool* bounceMp;
67  uint32_t bufAlign;
69 } Bdev;
70 
81 __attribute__((nonnull)) void
82 Bdev_ReadPacket(Bdev* bd, struct spdk_io_channel* ch, uint64_t blockOffset, BdevRequest* req);
83 
90 __attribute__((nonnull)) bool
91 Bdev_WritePrepare(Bdev* bd, struct rte_mbuf* pkt, BdevStoredPacket* sp);
92 
104 __attribute__((nonnull)) void
105 Bdev_WritePacket(Bdev* bd, struct spdk_io_channel* ch, uint64_t blockOffset, BdevRequest* req);
106 
107 #endif // NDNDPDK_SPDK_BDEV_H
BdevWriteMode
Definition: bdev-enum.h:6
@ BdevMaxMbufSegs
Maximum packet segments acceptable to Bdev_ReadPacket and Bdev_WritePacket.
Definition: bdev.h:15
@ BdevBlockSize
Expected block size; other block sizes are not supported.
Definition: bdev.h:12
bool Bdev_WritePrepare(Bdev *bd, struct rte_mbuf *pkt, BdevStoredPacket *sp)
Prepare writing according to bdev alignment requirements.
Definition: bdev.c:252
void Bdev_ReadPacket(Bdev *bd, struct spdk_io_channel *ch, uint64_t blockOffset, BdevRequest *req)
Read block device into mbuf.
Definition: bdev.c:80
void Bdev_WritePacket(Bdev *bd, struct spdk_io_channel *ch, uint64_t blockOffset, BdevRequest *req)
Write block device from mbuf via scatter gather list.
Definition: bdev.c:272
struct Bdev Bdev
Block device and related information.
uint8_t * BdevFiller_
Definition: bdev.c:3
void(* BdevRequestCb)(BdevRequest *req, int res)
Definition: bdev.h:52
struct BdevStoredPacket BdevStoredPacket
Length and alignment descriptor of a stored packet.
Bdev I/O request.
Definition: bdev.h:55
struct iovec iov_[BdevMaxMbufSegs+1]
Definition: bdev.h:60
BdevStoredPacket * sp
Definition: bdev.h:57
struct rte_mbuf * pkt
Definition: bdev.h:56
struct rte_mbuf * bounce_
Definition: bdev.h:59
BdevRequestCb cb
Definition: bdev.h:58
Length and alignment descriptor of a stored packet.
Definition: bdev.h:21
uint8_t headTail[BdevMaxMbufSegs]
per-segment (headLen << 4) | (headLen + tailLen)
Definition: bdev.h:25
uint16_t pktLen
original packet length
Definition: bdev.h:22
uint16_t saveTotal
saved total length
Definition: bdev.h:23
uint16_t saveLen[BdevMaxMbufSegs]
per-segment saved length, zero denotes ending
Definition: bdev.h:24
Block device and related information.
Definition: bdev.h:64
uint32_t bufAlign
Definition: bdev.h:67
struct spdk_bdev_desc * desc
Definition: bdev.h:65
BdevWriteMode writeMode
Definition: bdev.h:68
struct rte_mempool * bounceMp
Definition: bdev.h:66