1 /* SPDX-License-Identifier: GPL-2.0-only */
3 * Copyright 2008-2010 Cisco Systems, Inc. All rights reserved.
4 * Copyright 2007 Nuova Systems, Inc. All rights reserved.
10 #include <linux/pci.h>
15 /* Work queue control */
17 u64 ring_base
; /* 0x00 */
18 u32 ring_size
; /* 0x08 */
20 u32 posted_index
; /* 0x10 */
22 u32 cq_index
; /* 0x18 */
24 u32 enable
; /* 0x20 */
26 u32 running
; /* 0x28 */
28 u32 fetch_index
; /* 0x30 */
30 u32 dca_value
; /* 0x38 */
32 u32 error_interrupt_enable
; /* 0x40 */
34 u32 error_interrupt_offset
; /* 0x48 */
36 u32 error_status
; /* 0x50 */
41 struct vnic_wq_buf
*next
;
48 uint64_t wr_id
; /* Cookie */
49 uint8_t cq_entry
; /* Gets completion event from hw */
50 uint8_t desc_skip_cnt
; /* Num descs to occupy */
51 uint8_t compressed_send
; /* Both hdr and payload in one desc */
52 struct vnic_wq_buf
*prev
;
55 /* Break the vnic_wq_buf allocations into blocks of 32/64 entries */
56 #define VNIC_WQ_BUF_MIN_BLK_ENTRIES 32
57 #define VNIC_WQ_BUF_DFLT_BLK_ENTRIES 64
58 #define VNIC_WQ_BUF_BLK_ENTRIES(entries) \
59 ((unsigned int)((entries < VNIC_WQ_BUF_DFLT_BLK_ENTRIES) ? \
60 VNIC_WQ_BUF_MIN_BLK_ENTRIES : VNIC_WQ_BUF_DFLT_BLK_ENTRIES))
61 #define VNIC_WQ_BUF_BLK_SZ(entries) \
62 (VNIC_WQ_BUF_BLK_ENTRIES(entries) * sizeof(struct vnic_wq_buf))
63 #define VNIC_WQ_BUF_BLKS_NEEDED(entries) \
64 DIV_ROUND_UP(entries, VNIC_WQ_BUF_BLK_ENTRIES(entries))
65 #define VNIC_WQ_BUF_BLKS_MAX VNIC_WQ_BUF_BLKS_NEEDED(4096)
69 struct vnic_dev
*vdev
;
70 struct vnic_wq_ctrl __iomem
*ctrl
; /* memory-mapped */
71 struct vnic_dev_ring ring
;
72 struct vnic_wq_buf
*bufs
[VNIC_WQ_BUF_BLKS_MAX
];
73 struct vnic_wq_buf
*to_use
;
74 struct vnic_wq_buf
*to_clean
;
75 unsigned int pkts_outstanding
;
78 struct devcmd2_controller
{
79 struct vnic_wq_ctrl __iomem
*wq_ctrl
;
80 struct vnic_devcmd2
*cmd_ring
;
81 struct devcmd2_result
*result
;
85 struct vnic_dev_ring results_ring
;
90 static inline unsigned int vnic_wq_desc_avail(struct vnic_wq
*wq
)
92 /* how many does SW own? */
93 return wq
->ring
.desc_avail
;
96 static inline unsigned int vnic_wq_desc_used(struct vnic_wq
*wq
)
98 /* how many does HW own? */
99 return wq
->ring
.desc_count
- wq
->ring
.desc_avail
- 1;
102 static inline void *vnic_wq_next_desc(struct vnic_wq
*wq
)
104 return wq
->to_use
->desc
;
107 static inline void vnic_wq_doorbell(struct vnic_wq
*wq
)
109 /* Adding write memory barrier prevents compiler and/or CPU
110 * reordering, thus avoiding descriptor posting before
111 * descriptor is initialized. Otherwise, hardware can read
112 * stale descriptor fields.
115 iowrite32(wq
->to_use
->index
, &wq
->ctrl
->posted_index
);
118 static inline void vnic_wq_post(struct vnic_wq
*wq
,
119 void *os_buf
, dma_addr_t dma_addr
,
120 unsigned int len
, int sop
, int eop
,
121 uint8_t desc_skip_cnt
, uint8_t cq_entry
,
122 uint8_t compressed_send
, uint64_t wrid
)
124 struct vnic_wq_buf
*buf
= wq
->to_use
;
127 buf
->cq_entry
= cq_entry
;
128 buf
->compressed_send
= compressed_send
;
129 buf
->desc_skip_cnt
= desc_skip_cnt
;
130 buf
->os_buf
= eop
? os_buf
: NULL
;
131 buf
->dma_addr
= dma_addr
;
138 wq
->ring
.desc_avail
-= desc_skip_cnt
;
141 static inline void vnic_wq_service(struct vnic_wq
*wq
,
142 struct cq_desc
*cq_desc
, u16 completed_index
,
143 void (*buf_service
)(struct vnic_wq
*wq
,
144 struct cq_desc
*cq_desc
, struct vnic_wq_buf
*buf
, void *opaque
),
147 struct vnic_wq_buf
*buf
;
152 (*buf_service
)(wq
, cq_desc
, buf
, opaque
);
154 wq
->ring
.desc_avail
++;
156 wq
->to_clean
= buf
->next
;
158 if (buf
->index
== completed_index
)
165 void vnic_wq_free(struct vnic_wq
*wq
);
166 int vnic_wq_alloc(struct vnic_dev
*vdev
, struct vnic_wq
*wq
, unsigned int index
,
167 unsigned int desc_count
, unsigned int desc_size
);
168 void vnic_wq_init(struct vnic_wq
*wq
, unsigned int cq_index
,
169 unsigned int error_interrupt_enable
,
170 unsigned int error_interrupt_offset
);
171 unsigned int vnic_wq_error_status(struct vnic_wq
*wq
);
172 void vnic_wq_enable(struct vnic_wq
*wq
);
173 int vnic_wq_disable(struct vnic_wq
*wq
);
174 void vnic_wq_clean(struct vnic_wq
*wq
,
175 void (*buf_clean
)(struct vnic_wq
*wq
, struct vnic_wq_buf
*buf
));
176 int enic_wq_devcmd2_alloc(struct vnic_dev
*vdev
, struct vnic_wq
*wq
,
177 unsigned int desc_count
, unsigned int desc_size
);
178 void enic_wq_init_start(struct vnic_wq
*wq
, unsigned int cq_index
,
179 unsigned int fetch_index
, unsigned int posted_index
,
180 unsigned int error_interrupt_enable
,
181 unsigned int error_interrupt_offset
);
183 #endif /* _VNIC_WQ_H_ */