1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 /* Copyright (C) 2024-2025 Intel Corporation */ 3 4 #ifndef __LIBETH_TYPES_H 5 #define __LIBETH_TYPES_H 6 7 #include <linux/workqueue.h> 8 9 /* Stats */ 10 11 /** 12 * struct libeth_rq_napi_stats - "hot" counters to update in Rx polling loop 13 * @packets: received frames counter 14 * @bytes: sum of bytes of received frames above 15 * @fragments: sum of fragments of received S/G frames 16 * @hsplit: number of frames the device performed the header split for 17 * @raw: alias to access all the fields as an array 18 */ 19 struct libeth_rq_napi_stats { 20 union { 21 struct { 22 u32 packets; 23 u32 bytes; 24 u32 fragments; 25 u32 hsplit; 26 }; 27 DECLARE_FLEX_ARRAY(u32, raw); 28 }; 29 }; 30 31 /** 32 * struct libeth_sq_napi_stats - "hot" counters to update in Tx completion loop 33 * @packets: completed frames counter 34 * @bytes: sum of bytes of completed frames above 35 * @raw: alias to access all the fields as an array 36 */ 37 struct libeth_sq_napi_stats { 38 union { 39 struct { 40 u32 packets; 41 u32 bytes; 42 }; 43 DECLARE_FLEX_ARRAY(u32, raw); 44 }; 45 }; 46 47 /** 48 * struct libeth_xdpsq_napi_stats - "hot" counters to update in XDP Tx 49 * completion loop 50 * @packets: completed frames counter 51 * @bytes: sum of bytes of completed frames above 52 * @fragments: sum of fragments of completed S/G frames 53 * @raw: alias to access all the fields as an array 54 */ 55 struct libeth_xdpsq_napi_stats { 56 union { 57 struct { 58 u32 packets; 59 u32 bytes; 60 u32 fragments; 61 }; 62 DECLARE_FLEX_ARRAY(u32, raw); 63 }; 64 }; 65 66 /* XDP */ 67 68 /* 69 * The following structures should be embedded into driver's queue structure 70 * and passed to the libeth_xdp helpers, never used directly. 71 */ 72 73 /* XDPSQ sharing */ 74 75 /** 76 * struct libeth_xdpsq_lock - locking primitive for sharing XDPSQs 77 * @lock: spinlock for locking the queue 78 * @share: whether this particular queue is shared 79 */ 80 struct libeth_xdpsq_lock { 81 spinlock_t lock; 82 bool share; 83 }; 84 85 /* XDPSQ clean-up timers */ 86 87 /** 88 * struct libeth_xdpsq_timer - timer for cleaning up XDPSQs w/o interrupts 89 * @xdpsq: queue this timer belongs to 90 * @lock: lock for the queue 91 * @dwork: work performing cleanups 92 * 93 * XDPSQs not using interrupts but lazy cleaning, i.e. only when there's no 94 * space for sending the current queued frame/bulk, must fire up timers to 95 * make sure there are no stale buffers to free. 96 */ 97 struct libeth_xdpsq_timer { 98 void *xdpsq; 99 struct libeth_xdpsq_lock *lock; 100 101 struct delayed_work dwork; 102 }; 103 104 /* Rx polling path */ 105 106 /** 107 * struct libeth_xdp_buff_stash - struct for stashing &xdp_buff onto a queue 108 * @data: pointer to the start of the frame, xdp_buff.data 109 * @headroom: frame headroom, xdp_buff.data - xdp_buff.data_hard_start 110 * @len: frame linear space length, xdp_buff.data_end - xdp_buff.data 111 * @frame_sz: truesize occupied by the frame, xdp_buff.frame_sz 112 * @flags: xdp_buff.flags 113 * 114 * &xdp_buff is 56 bytes long on x64, &libeth_xdp_buff is 64 bytes. This 115 * structure carries only necessary fields to save/restore a partially built 116 * frame on the queue structure to finish it during the next NAPI poll. 117 */ 118 struct libeth_xdp_buff_stash { 119 void *data; 120 u16 headroom; 121 u16 len; 122 123 u32 frame_sz:24; 124 u32 flags:8; 125 } __aligned_largest; 126 127 #endif /* __LIBETH_TYPES_H */ 128