[thunderx] Replace uses of userptr_t with direct pointer dereferences

Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
Michael Brown
2025-04-24 13:01:03 +01:00
parent 8ac03b4a73
commit f18c1472e3
2 changed files with 28 additions and 36 deletions

View File

@@ -89,7 +89,7 @@ static __attribute__ (( unused )) void txnic_diag ( struct txnic *vnic ) {
( ( vnic->rq.cons % TXNIC_RQES ) * TXNIC_RQ_STRIDE ), ( ( vnic->rq.cons % TXNIC_RQES ) * TXNIC_RQ_STRIDE ),
readq ( vnic->regs + TXNIC_QS_RBDR_HEAD(0) ), readq ( vnic->regs + TXNIC_QS_RBDR_HEAD(0) ),
readq ( vnic->regs + TXNIC_QS_RBDR_STATUS0(0) ) ); readq ( vnic->regs + TXNIC_QS_RBDR_STATUS0(0) ) );
DBGC ( vnic, "TXNIC %s CQ xxxxx(%05llx)/%05x(%05llx) %08llx:%08llx\n", DBGC ( vnic, "TXNIC %s CQ xxxxx(%05llx)/%05zx(%05llx) %08llx:%08llx\n",
vnic->name, readq ( vnic->regs + TXNIC_QS_CQ_TAIL(0) ), vnic->name, readq ( vnic->regs + TXNIC_QS_CQ_TAIL(0) ),
( ( vnic->cq.cons % TXNIC_CQES ) * TXNIC_CQ_STRIDE ), ( ( vnic->cq.cons % TXNIC_CQES ) * TXNIC_CQ_STRIDE ),
readq ( vnic->regs + TXNIC_QS_CQ_HEAD(0) ), readq ( vnic->regs + TXNIC_QS_CQ_HEAD(0) ),
@@ -184,9 +184,8 @@ static void txnic_destroy_sq ( struct txnic *vnic ) {
* @ret rc Return status code * @ret rc Return status code
*/ */
static int txnic_send ( struct txnic *vnic, struct io_buffer *iobuf ) { static int txnic_send ( struct txnic *vnic, struct io_buffer *iobuf ) {
struct txnic_sqe sqe; struct txnic_sqe *sqe;
unsigned int sq_idx; unsigned int sq_idx;
size_t offset;
size_t len; size_t len;
/* Get next send queue entry */ /* Get next send queue entry */
@@ -196,24 +195,21 @@ static int txnic_send ( struct txnic *vnic, struct io_buffer *iobuf ) {
return -ENOBUFS; return -ENOBUFS;
} }
sq_idx = ( vnic->sq.prod++ % TXNIC_SQES ); sq_idx = ( vnic->sq.prod++ % TXNIC_SQES );
offset = ( sq_idx * TXNIC_SQ_STRIDE ); sqe = &vnic->sq.sqe[sq_idx];
/* Populate send descriptor */ /* Populate send descriptor */
len = iob_len ( iobuf ); len = iob_len ( iobuf );
memset ( &sqe, 0, sizeof ( sqe ) ); memset ( sqe, 0, sizeof ( *sqe ) );
sqe.hdr.total = cpu_to_le32 ( ( len >= ETH_ZLEN ) ? len : ETH_ZLEN ); sqe->hdr.total = cpu_to_le32 ( ( len >= ETH_ZLEN ) ? len : ETH_ZLEN );
sqe.hdr.subdcnt = ( TXNIC_SQE_SUBDESCS - 1 ); sqe->hdr.subdcnt = ( TXNIC_SQE_SUBDESCS - 1 );
sqe.hdr.flags = TXNIC_SEND_HDR_FLAGS; sqe->hdr.flags = TXNIC_SEND_HDR_FLAGS;
sqe.gather.size = cpu_to_le16 ( len ); sqe->gather.size = cpu_to_le16 ( len );
sqe.gather.flags = TXNIC_SEND_GATHER_FLAGS; sqe->gather.flags = TXNIC_SEND_GATHER_FLAGS;
sqe.gather.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) ); sqe->gather.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
DBGC2 ( vnic, "TXNIC %s SQE %#03x is [%08lx,%08lx)\n", DBGC2 ( vnic, "TXNIC %s SQE %#03x is [%08lx,%08lx)\n",
vnic->name, sq_idx, virt_to_bus ( iobuf->data ), vnic->name, sq_idx, virt_to_bus ( iobuf->data ),
( virt_to_bus ( iobuf->data ) + len ) ); ( virt_to_bus ( iobuf->data ) + len ) );
/* Copy send descriptor to ring */
copy_to_user ( vnic->sq.sqe, offset, &sqe, sizeof ( sqe ) );
/* Ring doorbell */ /* Ring doorbell */
wmb(); wmb();
writeq ( TXNIC_SQE_SUBDESCS, ( vnic->regs + TXNIC_QS_SQ_DOOR(0) ) ); writeq ( TXNIC_SQE_SUBDESCS, ( vnic->regs + TXNIC_QS_SQ_DOOR(0) ) );
@@ -359,11 +355,10 @@ static void txnic_destroy_rq ( struct txnic *vnic ) {
*/ */
static void txnic_refill_rq ( struct txnic *vnic ) { static void txnic_refill_rq ( struct txnic *vnic ) {
struct io_buffer *iobuf; struct io_buffer *iobuf;
struct txnic_rqe rqe; struct txnic_rqe *rqe;
unsigned int rq_idx; unsigned int rq_idx;
unsigned int rq_iobuf_idx; unsigned int rq_iobuf_idx;
unsigned int refilled = 0; unsigned int refilled = 0;
size_t offset;
/* Refill ring */ /* Refill ring */
while ( ( vnic->rq.prod - vnic->rq.cons ) < TXNIC_RQ_FILL ) { while ( ( vnic->rq.prod - vnic->rq.cons ) < TXNIC_RQ_FILL ) {
@@ -377,16 +372,15 @@ static void txnic_refill_rq ( struct txnic *vnic ) {
/* Get next receive descriptor */ /* Get next receive descriptor */
rq_idx = ( vnic->rq.prod++ % TXNIC_RQES ); rq_idx = ( vnic->rq.prod++ % TXNIC_RQES );
offset = ( rq_idx * TXNIC_RQ_STRIDE ); rqe = &vnic->rq.rqe[rq_idx];
/* Populate receive descriptor */ /* Populate receive descriptor */
rqe.rbdre.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) ); rqe->rbdre.addr = cpu_to_le64 ( virt_to_bus ( iobuf->data ) );
DBGC2 ( vnic, "TXNIC %s RQE %#03x is [%08lx,%08lx)\n", DBGC2 ( vnic, "TXNIC %s RQE %#03x is [%08lx,%08lx)\n",
vnic->name, rq_idx, virt_to_bus ( iobuf->data ), vnic->name, rq_idx, virt_to_bus ( iobuf->data ),
( virt_to_bus ( iobuf->data ) + TXNIC_RQE_SIZE ) ); ( virt_to_bus ( iobuf->data ) + TXNIC_RQE_SIZE ) );
/* Copy receive descriptor to ring */ /* Record number of refills for doorbell */
copy_to_user ( vnic->rq.rqe, offset, &rqe, sizeof ( rqe ) );
refilled++; refilled++;
/* Record I/O buffer */ /* Record I/O buffer */
@@ -527,9 +521,8 @@ static void txnic_destroy_cq ( struct txnic *vnic ) {
* @v vnic Virtual NIC * @v vnic Virtual NIC
*/ */
static void txnic_poll_cq ( struct txnic *vnic ) { static void txnic_poll_cq ( struct txnic *vnic ) {
union txnic_cqe cqe; union txnic_cqe *cqe;
uint64_t status; uint64_t status;
size_t offset;
unsigned int qcount; unsigned int qcount;
unsigned int cq_idx; unsigned int cq_idx;
unsigned int i; unsigned int i;
@@ -545,23 +538,21 @@ static void txnic_poll_cq ( struct txnic *vnic ) {
/* Get completion queue entry */ /* Get completion queue entry */
cq_idx = ( vnic->cq.cons++ % TXNIC_CQES ); cq_idx = ( vnic->cq.cons++ % TXNIC_CQES );
offset = ( cq_idx * TXNIC_CQ_STRIDE ); cqe = &vnic->cq.cqe[cq_idx];
copy_from_user ( &cqe, vnic->cq.cqe, offset, sizeof ( cqe ) );
/* Process completion queue entry */ /* Process completion queue entry */
switch ( cqe.common.cqe_type ) { switch ( cqe->common.cqe_type ) {
case TXNIC_CQE_TYPE_SEND: case TXNIC_CQE_TYPE_SEND:
txnic_complete_sqe ( vnic, &cqe.send ); txnic_complete_sqe ( vnic, &cqe->send );
break; break;
case TXNIC_CQE_TYPE_RX: case TXNIC_CQE_TYPE_RX:
txnic_complete_rqe ( vnic, &cqe.rx ); txnic_complete_rqe ( vnic, &cqe->rx );
break; break;
default: default:
DBGC ( vnic, "TXNIC %s unknown completion type %d\n", DBGC ( vnic, "TXNIC %s unknown completion type %d\n",
vnic->name, cqe.common.cqe_type ); vnic->name, cqe->common.cqe_type );
DBGC_HDA ( vnic, DBGC_HDA ( vnic, virt_to_phys ( cqe ), cqe,
( virt_to_phys ( vnic->cq.cqe ) + offset ), sizeof ( *cqe ) );
&cqe, sizeof ( cqe ) );
break; break;
} }
} }

View File

@@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h> #include <stdint.h>
#include <ipxe/list.h> #include <ipxe/list.h>
#include <ipxe/netdevice.h> #include <ipxe/netdevice.h>
#include <ipxe/uaccess.h>
/****************************************************************************** /******************************************************************************
* *
@@ -188,7 +187,7 @@ struct txnic_sq {
/** Consumer counter */ /** Consumer counter */
unsigned int cons; unsigned int cons;
/** Send queue entries */ /** Send queue entries */
userptr_t sqe; struct txnic_sqe *sqe;
}; };
/****************************************************************************** /******************************************************************************
@@ -280,7 +279,7 @@ struct txnic_rq {
/** Consumer counter */ /** Consumer counter */
unsigned int cons; unsigned int cons;
/** Receive queue entries */ /** Receive queue entries */
userptr_t rqe; struct txnic_rqe *rqe;
/** I/O buffers */ /** I/O buffers */
struct io_buffer *iobuf[TXNIC_RQ_FILL]; struct io_buffer *iobuf[TXNIC_RQ_FILL];
}; };
@@ -381,6 +380,8 @@ union txnic_cqe {
struct txnic_cqe_send send; struct txnic_cqe_send send;
/** Receive completion */ /** Receive completion */
struct txnic_cqe_rx rx; struct txnic_cqe_rx rx;
/** Padding */
uint8_t pad[512];
}; };
/** Number of completion queue entries /** Number of completion queue entries
@@ -393,7 +394,7 @@ union txnic_cqe {
#define TXNIC_CQ_ALIGN 512 #define TXNIC_CQ_ALIGN 512
/** Completion queue stride */ /** Completion queue stride */
#define TXNIC_CQ_STRIDE 512 #define TXNIC_CQ_STRIDE sizeof ( union txnic_cqe )
/** Completion queue size */ /** Completion queue size */
#define TXNIC_CQ_SIZE ( TXNIC_CQES * TXNIC_CQ_STRIDE ) #define TXNIC_CQ_SIZE ( TXNIC_CQES * TXNIC_CQ_STRIDE )
@@ -403,7 +404,7 @@ struct txnic_cq {
/** Consumer counter */ /** Consumer counter */
unsigned int cons; unsigned int cons;
/** Completion queue entries */ /** Completion queue entries */
userptr_t cqe; union txnic_cqe *cqe;
}; };
/****************************************************************************** /******************************************************************************