blob: 8fff93a75a927e0d69cd8528ada8d8616ac78151 [file] [log] [blame]
Alex Dewardbddf422019-08-25 10:49:16 +01001/* SPDX-License-Identifier: GPL-2.0 */
Anton Ivanov49da7e62017-11-20 21:17:59 +00002/*
3 * Copyright (C) 2002 2007 Jeff Dike (jdike@{addtoit,linux.intel}.com)
Anton Ivanov49da7e62017-11-20 21:17:59 +00004 */
5
6#ifndef __UM_VECTOR_KERN_H
7#define __UM_VECTOR_KERN_H
8
9#include <linux/netdevice.h>
10#include <linux/platform_device.h>
11#include <linux/skbuff.h>
12#include <linux/socket.h>
13#include <linux/list.h>
14#include <linux/ctype.h>
15#include <linux/workqueue.h>
16#include <linux/interrupt.h>
17#include "vector_user.h"
18
19/* Queue structure specially adapted for multiple enqueue/dequeue
20 * in a mmsgrecv/mmsgsend context
21 */
22
23/* Dequeue method */
24
25#define QUEUE_SENDMSG 0
26#define QUEUE_SENDMMSG 1
27
28#define VECTOR_RX 1
29#define VECTOR_TX (1 << 1)
30#define VECTOR_BPF (1 << 2)
Anton Ivanove40238d2018-03-05 13:29:05 +000031#define VECTOR_QDISC_BYPASS (1 << 3)
Anton Ivanov98070192019-10-02 11:26:45 +010032#define VECTOR_BPF_FLASH (1 << 4)
Anton Ivanov49da7e62017-11-20 21:17:59 +000033
34#define ETH_MAX_PACKET 1500
35#define ETH_HEADER_OTHER 32 /* just in case someone decides to go mad on QnQ */
36
Anton Ivanov98070192019-10-02 11:26:45 +010037#define MAX_FILTER_PROG (2 << 16)
38
Anton Ivanov49da7e62017-11-20 21:17:59 +000039struct vector_queue {
40 struct mmsghdr *mmsg_vector;
41 void **skbuff_vector;
42 /* backlink to device which owns us */
43 struct net_device *dev;
44 spinlock_t head_lock;
45 spinlock_t tail_lock;
46 int queue_depth, head, tail, max_depth, max_iov_frags;
47 short options;
48};
49
50struct vector_estats {
51 uint64_t rx_queue_max;
52 uint64_t rx_queue_running_average;
53 uint64_t tx_queue_max;
54 uint64_t tx_queue_running_average;
55 uint64_t rx_encaps_errors;
56 uint64_t tx_timeout_count;
57 uint64_t tx_restart_queue;
58 uint64_t tx_kicks;
59 uint64_t tx_flow_control_xon;
60 uint64_t tx_flow_control_xoff;
61 uint64_t rx_csum_offload_good;
62 uint64_t rx_csum_offload_errors;
63 uint64_t sg_ok;
64 uint64_t sg_linearized;
65};
66
67#define VERIFY_HEADER_NOK -1
68#define VERIFY_HEADER_OK 0
69#define VERIFY_CSUM_OK 1
70
71struct vector_private {
72 struct list_head list;
73 spinlock_t lock;
74 struct net_device *dev;
75
76 int unit;
77
78 /* Timeout timer in TX */
79
80 struct timer_list tl;
81
82 /* Scheduled "remove device" work */
83 struct work_struct reset_tx;
84 struct vector_fds *fds;
85
86 struct vector_queue *rx_queue;
87 struct vector_queue *tx_queue;
88
89 int rx_irq;
90 int tx_irq;
91
92 struct arglist *parsed;
93
94 void *transport_data; /* transport specific params if needed */
95
96 int max_packet;
97 int req_size; /* different from max packet - used for TSO */
98 int headroom;
99
100 int options;
101
102 /* remote address if any - some transports will leave this as null */
103
104 int header_size;
105 int rx_header_size;
106 int coalesce;
107
108 void *header_rxbuffer;
109 void *header_txbuffer;
110
111 int (*form_header)(uint8_t *header,
112 struct sk_buff *skb, struct vector_private *vp);
113 int (*verify_header)(uint8_t *header,
114 struct sk_buff *skb, struct vector_private *vp);
115
116 spinlock_t stats_lock;
117
118 struct tasklet_struct tx_poll;
119 bool rexmit_scheduled;
120 bool opened;
121 bool in_write_poll;
Anton Ivanovd47761d2019-08-09 08:40:20 +0100122 bool in_error;
Anton Ivanov49da7e62017-11-20 21:17:59 +0000123
Anton Ivanov98070192019-10-02 11:26:45 +0100124 /* guest allowed to use ethtool flash to load bpf */
125 bool bpf_via_flash;
126
Anton Ivanov49da7e62017-11-20 21:17:59 +0000127 /* ethtool stats */
128
129 struct vector_estats estats;
Anton Ivanov98070192019-10-02 11:26:45 +0100130 struct sock_fprog *bpf;
Anton Ivanov49da7e62017-11-20 21:17:59 +0000131
Gustavo A. R. Silvaf6e8c472020-05-07 14:26:52 -0500132 char user[];
Anton Ivanov49da7e62017-11-20 21:17:59 +0000133};
134
135extern int build_transport_data(struct vector_private *vp);
136
137#endif