123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
#ifndef _TSO_H
#define _TSO_H
#include <linux/skbuff.h>
#include <linux/dma-mapping.h>
#include <net/ip.h>
#define TSO_HEADER_SIZE 256
struct tso_t {
int next_frag_idx;
int size;
void *data;
u16 ip_id;
u8 tlen;
bool ipv6;
u32 tcp_seq;
};
static inline int tso_count_descs(const struct sk_buff *skb)
{
return skb_shinfo(skb)->gso_segs * 2 + skb_shinfo(skb)->nr_frags;
}
void tso_build_hdr(const struct sk_buff *skb, char *hdr, struct tso_t *tso,
int size, bool is_last);
void tso_build_data(const struct sk_buff *skb, struct tso_t *tso, int size);
int tso_start(struct sk_buff *skb, struct tso_t *tso);
struct tso_dma_map {
struct device *dev;
const struct sk_buff *skb;
unsigned int hdr_len;
struct dma_iova_state iova_state;
size_t iova_offset;
size_t total_len;
int frag_idx;
unsigned int offset;
dma_addr_t linear_dma;
unsigned int linear_len;
unsigned int nr_frags;
struct {
dma_addr_t dma;
unsigned int len;
} frags[MAX_SKB_FRAGS];
};
struct tso_dma_map_completion_state {
struct dma_iova_state iova_state;
size_t total_len;
};
int tso_dma_map_init(struct tso_dma_map *map, struct device *dev,
const struct sk_buff *skb, unsigned int hdr_len);
void tso_dma_map_cleanup(struct tso_dma_map *map);
unsigned int tso_dma_map_count(struct tso_dma_map *map, unsigned int len);
bool tso_dma_map_next(struct tso_dma_map *map, dma_addr_t *addr,
unsigned int *chunk_len, unsigned int *mapping_len,
unsigned int seg_remaining);
static inline void
tso_dma_map_completion_save(const struct tso_dma_map *map,
struct tso_dma_map_completion_state *cstate)
{
cstate->iova_state = map->iova_state;
cstate->total_len = map->total_len;
}
static inline bool
tso_dma_map_complete(struct device *dev,
struct tso_dma_map_completion_state *cstate)
{
if (dma_use_iova(&cstate->iova_state)) {
dma_iova_destroy(dev, &cstate->iova_state, cstate->total_len,
DMA_TO_DEVICE, 0);
return true;
}
return false;
}
#endif /* _TSO_H */