Skip to content

Commit 8659520

Browse files
tianx666NipaLocal
authored andcommitted
xsc: Add eth needed qp and cq apis
1. For Ethernet data transmission and reception, this patch adds APIs for using QP and CQ. For QPs, it includes Create QP, Modify QP Status, and Destroy QP. For CQs, it includes Create CQ and Destroy CQ. Since these operations are common to both Ethernet and RDMA, they are added to the xsc_pci driver. In the xsc_eth driver, Ethernet-specific operations are added, including create RSS RQ and modify QP. 2. Ethernet QP and CQ ring buffer allocation functions are added: xsc_eth_cqwq_create for CQ and xsc_eth_wq_cyc_create for QP. Corresponding DMA buffer allocation functions are also added in alloc.c. Co-developed-by: Honggang Wei <[email protected]> Signed-off-by: Honggang Wei <[email protected]> Co-developed-by: Lei Yan <[email protected]> Signed-off-by: Lei Yan <[email protected]> Signed-off-by: Xin Tian <[email protected]> Signed-off-by: NipaLocal <nipa@local>
1 parent 09b4719 commit 8659520

File tree

7 files changed

+628
-1
lines changed

7 files changed

+628
-1
lines changed

drivers/net/ethernet/yunsilicon/xsc/common/xsc_core.h

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,9 +401,36 @@ int xsc_core_create_resource_common(struct xsc_core_device *xdev,
401401
struct xsc_core_qp *qp);
402402
void xsc_core_destroy_resource_common(struct xsc_core_device *xdev,
403403
struct xsc_core_qp *qp);
404+
int xsc_core_eth_create_qp(struct xsc_core_device *xdev,
405+
struct xsc_create_qp_mbox_in *in,
406+
int insize, u32 *p_qpn);
407+
int xsc_core_eth_modify_qp_status(struct xsc_core_device *xdev,
408+
u32 qpn, u16 status);
409+
int xsc_core_eth_destroy_qp(struct xsc_core_device *xdev, u32 qpn);
410+
int xsc_core_eth_create_rss_qp_rqs(struct xsc_core_device *xdev,
411+
struct xsc_create_multiqp_mbox_in *in,
412+
int insize,
413+
u32 *p_qpn_base);
414+
int xsc_core_eth_modify_raw_qp(struct xsc_core_device *xdev,
415+
struct xsc_modify_raw_qp_mbox_in *in);
416+
int xsc_core_eth_create_cq(struct xsc_core_device *xdev,
417+
struct xsc_core_cq *xcq,
418+
struct xsc_create_cq_mbox_in *in,
419+
int insize);
420+
int xsc_core_eth_destroy_cq(struct xsc_core_device *xdev,
421+
struct xsc_core_cq *xcq);
422+
404423
struct xsc_eq *xsc_core_eq_get(struct xsc_core_device *xdev, int i);
405424
int xsc_core_vector2eqn(struct xsc_core_device *xdev, int vector, u32 *eqn,
406425
unsigned int *irqn);
426+
void xsc_core_fill_page_frag_array(struct xsc_frag_buf *buf,
427+
__be64 *pas, unsigned int npages);
428+
int xsc_core_frag_buf_alloc_node(struct xsc_core_device *xdev,
429+
unsigned long size,
430+
struct xsc_frag_buf *buf,
431+
int node);
432+
void xsc_core_frag_buf_free(struct xsc_core_device *xdev,
433+
struct xsc_frag_buf *buf);
407434

408435
static inline void *xsc_buf_offset(struct xsc_buf *buf, unsigned long offset)
409436
{

drivers/net/ethernet/yunsilicon/xsc/net/Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,4 @@ ccflags-y += -I$(srctree)/drivers/net/ethernet/yunsilicon/xsc
66

77
obj-$(CONFIG_YUNSILICON_XSC_ETH) += xsc_eth.o
88

9-
xsc_eth-y := main.o
9+
xsc_eth-y := main.o xsc_eth_wq.o
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// SPDX-License-Identifier: GPL-2.0
2+
/*
3+
* Copyright (c) 2021-2025, Shanghai Yunsilicon Technology Co., Ltd. All
4+
* rights reserved.
5+
* Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
6+
*/
7+
8+
#include "xsc_eth_wq.h"
9+
#include "xsc_eth.h"
10+
11+
u32 xsc_wq_cyc_get_size(struct xsc_wq_cyc *wq)
12+
{
13+
return (u32)wq->fbc.sz_m1 + 1;
14+
}
15+
16+
static u32 wq_get_byte_sz(u8 log_sz, u8 log_stride)
17+
{
18+
return ((u32)1 << log_sz) << log_stride;
19+
}
20+
21+
int xsc_eth_cqwq_create(struct xsc_core_device *xdev,
22+
struct xsc_wq_param *param,
23+
u8 q_log_size,
24+
u8 ele_log_size,
25+
struct xsc_cqwq *wq,
26+
struct xsc_wq_ctrl *wq_ctrl)
27+
{
28+
u8 log_wq_stride = ele_log_size;
29+
u8 log_wq_sz = q_log_size;
30+
struct net_device *netdev;
31+
int err;
32+
33+
netdev = ((struct xsc_adapter *)xdev->eth_priv)->netdev;
34+
35+
err = xsc_core_frag_buf_alloc_node(xdev,
36+
wq_get_byte_sz(log_wq_sz,
37+
log_wq_stride),
38+
&wq_ctrl->buf,
39+
param->buf_numa_node);
40+
if (err) {
41+
netdev_err(netdev,
42+
"xsc_core_frag_buf_alloc_node failed, %d\n", err);
43+
return err;
44+
}
45+
46+
xsc_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, &wq->fbc);
47+
wq_ctrl->xdev = xdev;
48+
return 0;
49+
}
50+
51+
int xsc_eth_wq_cyc_create(struct xsc_core_device *xdev,
52+
struct xsc_wq_param *param,
53+
u8 q_log_size,
54+
u8 ele_log_size,
55+
struct xsc_wq_cyc *wq,
56+
struct xsc_wq_ctrl *wq_ctrl)
57+
{
58+
struct xsc_frag_buf_ctrl *fbc = &wq->fbc;
59+
u8 log_wq_stride = ele_log_size;
60+
u8 log_wq_sz = q_log_size;
61+
struct net_device *netdev;
62+
int err;
63+
64+
netdev = ((struct xsc_adapter *)xdev->eth_priv)->netdev;
65+
66+
err = xsc_core_frag_buf_alloc_node(xdev,
67+
wq_get_byte_sz(log_wq_sz,
68+
log_wq_stride),
69+
&wq_ctrl->buf,
70+
param->buf_numa_node);
71+
if (err) {
72+
netdev_err(netdev,
73+
"xsc_core_frag_buf_alloc_node failed, %d\n", err);
74+
return err;
75+
}
76+
77+
xsc_init_fbc(wq_ctrl->buf.frags, log_wq_stride, log_wq_sz, fbc);
78+
wq->sz = xsc_wq_cyc_get_size(wq);
79+
wq_ctrl->xdev = xdev;
80+
return 0;
81+
}
82+
83+
void xsc_eth_wq_destroy(struct xsc_wq_ctrl *wq_ctrl)
84+
{
85+
xsc_core_frag_buf_free(wq_ctrl->xdev, &wq_ctrl->buf);
86+
}
Lines changed: 187 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,187 @@
1+
/* SPDX-License-Identifier: GPL-2.0 */
2+
/*
3+
* Copyright (c) 2021-2025, Shanghai Yunsilicon Technology Co., Ltd. All
4+
* rights reserved.
5+
* Copyright (c) 2013-2015, Mellanox Technologies, Ltd. All rights reserved.
6+
*/
7+
8+
#ifndef __XSC_WQ_H
9+
#define __XSC_WQ_H
10+
11+
#include "common/xsc_core.h"
12+
13+
struct xsc_wq_param {
14+
int buf_numa_node;
15+
int db_numa_node;
16+
};
17+
18+
struct xsc_wq_ctrl {
19+
struct xsc_core_device *xdev;
20+
struct xsc_frag_buf buf;
21+
};
22+
23+
struct xsc_wq_cyc {
24+
struct xsc_frag_buf_ctrl fbc;
25+
u16 sz;
26+
u16 wqe_ctr;
27+
u16 cur_sz;
28+
};
29+
30+
struct xsc_cqwq {
31+
struct xsc_frag_buf_ctrl fbc;
32+
__be32 *db;
33+
u32 cc; /* consumer counter */
34+
};
35+
36+
enum xsc_res_type {
37+
XSC_RES_UND = 0,
38+
XSC_RES_RQ,
39+
XSC_RES_SQ,
40+
XSC_RES_MAX,
41+
};
42+
43+
u32 xsc_wq_cyc_get_size(struct xsc_wq_cyc *wq);
44+
45+
/*api for eth driver*/
46+
int xsc_eth_cqwq_create(struct xsc_core_device *xdev,
47+
struct xsc_wq_param *param,
48+
u8 q_log_size,
49+
u8 ele_log_size,
50+
struct xsc_cqwq *wq,
51+
struct xsc_wq_ctrl *wq_ctrl);
52+
53+
int xsc_eth_wq_cyc_create(struct xsc_core_device *xdev,
54+
struct xsc_wq_param *param,
55+
u8 q_log_size,
56+
u8 ele_log_size,
57+
struct xsc_wq_cyc *wq,
58+
struct xsc_wq_ctrl *wq_ctrl);
59+
void xsc_eth_wq_destroy(struct xsc_wq_ctrl *wq_ctrl);
60+
61+
static inline void xsc_init_fbc_offset(struct xsc_buf_list *frags,
62+
u8 log_stride, u8 log_sz,
63+
u16 strides_offset,
64+
struct xsc_frag_buf_ctrl *fbc)
65+
{
66+
fbc->frags = frags;
67+
fbc->log_stride = log_stride;
68+
fbc->log_sz = log_sz;
69+
fbc->sz_m1 = (1 << fbc->log_sz) - 1;
70+
fbc->log_frag_strides = PAGE_SHIFT - fbc->log_stride;
71+
fbc->frag_sz_m1 = (1 << fbc->log_frag_strides) - 1;
72+
fbc->strides_offset = strides_offset;
73+
}
74+
75+
static inline void xsc_init_fbc(struct xsc_buf_list *frags,
76+
u8 log_stride, u8 log_sz,
77+
struct xsc_frag_buf_ctrl *fbc)
78+
{
79+
xsc_init_fbc_offset(frags, log_stride, log_sz, 0, fbc);
80+
}
81+
82+
static inline void *xsc_frag_buf_get_wqe(struct xsc_frag_buf_ctrl *fbc,
83+
u32 ix)
84+
{
85+
unsigned int frag;
86+
87+
ix += fbc->strides_offset;
88+
frag = ix >> fbc->log_frag_strides;
89+
90+
return fbc->frags[frag].buf +
91+
((fbc->frag_sz_m1 & ix) << fbc->log_stride);
92+
}
93+
94+
static inline u32
95+
xsc_frag_buf_get_idx_last_contig_stride(struct xsc_frag_buf_ctrl *fbc, u32 ix)
96+
{
97+
u32 last_frag_stride_idx = (ix + fbc->strides_offset) | fbc->frag_sz_m1;
98+
99+
return min_t(u32, last_frag_stride_idx - fbc->strides_offset,
100+
fbc->sz_m1);
101+
}
102+
103+
static inline int xsc_wq_cyc_missing(struct xsc_wq_cyc *wq)
104+
{
105+
return wq->sz - wq->cur_sz;
106+
}
107+
108+
static inline int xsc_wq_cyc_is_empty(struct xsc_wq_cyc *wq)
109+
{
110+
return !wq->cur_sz;
111+
}
112+
113+
static inline void xsc_wq_cyc_push(struct xsc_wq_cyc *wq)
114+
{
115+
wq->wqe_ctr++;
116+
wq->cur_sz++;
117+
}
118+
119+
static inline void xsc_wq_cyc_push_n(struct xsc_wq_cyc *wq, u8 n)
120+
{
121+
wq->wqe_ctr += n;
122+
wq->cur_sz += n;
123+
}
124+
125+
static inline void xsc_wq_cyc_pop(struct xsc_wq_cyc *wq)
126+
{
127+
wq->cur_sz--;
128+
}
129+
130+
static inline u16 xsc_wq_cyc_ctr2ix(struct xsc_wq_cyc *wq, u16 ctr)
131+
{
132+
return ctr & wq->fbc.sz_m1;
133+
}
134+
135+
static inline u16 xsc_wq_cyc_get_head(struct xsc_wq_cyc *wq)
136+
{
137+
return xsc_wq_cyc_ctr2ix(wq, wq->wqe_ctr);
138+
}
139+
140+
static inline u16 xsc_wq_cyc_get_tail(struct xsc_wq_cyc *wq)
141+
{
142+
return xsc_wq_cyc_ctr2ix(wq, wq->wqe_ctr - wq->cur_sz);
143+
}
144+
145+
static inline void *xsc_wq_cyc_get_wqe(struct xsc_wq_cyc *wq, u16 ix)
146+
{
147+
return xsc_frag_buf_get_wqe(&wq->fbc, ix);
148+
}
149+
150+
static inline u32 xsc_cqwq_ctr2ix(struct xsc_cqwq *wq, u32 ctr)
151+
{
152+
return ctr & wq->fbc.sz_m1;
153+
}
154+
155+
static inline u32 xsc_cqwq_get_ci(struct xsc_cqwq *wq)
156+
{
157+
return xsc_cqwq_ctr2ix(wq, wq->cc);
158+
}
159+
160+
static inline u32 xsc_cqwq_get_ctr_wrap_cnt(struct xsc_cqwq *wq, u32 ctr)
161+
{
162+
return ctr >> wq->fbc.log_sz;
163+
}
164+
165+
static inline u32 xsc_cqwq_get_wrap_cnt(struct xsc_cqwq *wq)
166+
{
167+
return xsc_cqwq_get_ctr_wrap_cnt(wq, wq->cc);
168+
}
169+
170+
static inline void xsc_cqwq_pop(struct xsc_cqwq *wq)
171+
{
172+
wq->cc++;
173+
}
174+
175+
static inline u32 xsc_cqwq_get_size(struct xsc_cqwq *wq)
176+
{
177+
return wq->fbc.sz_m1 + 1;
178+
}
179+
180+
static inline struct xsc_cqe *xsc_cqwq_get_wqe(struct xsc_cqwq *wq, u32 ix)
181+
{
182+
struct xsc_cqe *cqe = xsc_frag_buf_get_wqe(&wq->fbc, ix);
183+
184+
return cqe;
185+
}
186+
187+
#endif /* __XSC_WQ_H */

0 commit comments

Comments
 (0)