[exanic] 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 10:56:21 +01:00
parent e8ffe2cd64
commit 8ac03b4a73
2 changed files with 16 additions and 23 deletions

View File

@@ -540,26 +540,23 @@ static void exanic_poll_tx ( struct net_device *netdev ) {
static void exanic_poll_rx ( struct net_device *netdev ) {
struct exanic_port *port = netdev->priv;
struct exanic_rx_chunk *rx;
struct exanic_rx_descriptor desc;
unsigned int index;
uint8_t current;
uint8_t previous;
size_t offset;
size_t len;
for ( ; ; port->rx_cons++ ) {
/* Fetch descriptor */
offset = ( ( port->rx_cons * sizeof ( *rx ) ) % EXANIC_RX_LEN );
copy_from_user ( &desc, port->rx,
( offset + offsetof ( typeof ( *rx ), desc ) ),
sizeof ( desc ) );
index = ( port->rx_cons % EXANIC_RX_COUNT );
rx = &port->rx[index];
/* Calculate generation */
current = ( port->rx_cons / ( EXANIC_RX_LEN / sizeof ( *rx ) ));
current = ( port->rx_cons / EXANIC_RX_COUNT );
previous = ( current - 1 );
/* Do nothing if no chunk is ready */
if ( desc.generation == previous )
if ( rx->desc.generation == previous )
break;
/* Allocate I/O buffer if needed */
@@ -573,14 +570,12 @@ static void exanic_poll_rx ( struct net_device *netdev ) {
}
/* Calculate chunk length */
len = ( desc.len ? desc.len : sizeof ( rx->data ) );
len = ( rx->desc.len ? rx->desc.len : sizeof ( rx->data ) );
/* Append data to I/O buffer */
if ( len <= iob_tailroom ( port->rx_iobuf ) ) {
copy_from_user ( iob_put ( port->rx_iobuf, len ),
port->rx,
( offset + offsetof ( typeof ( *rx ),
data ) ), len );
memcpy ( iob_put ( port->rx_iobuf, len ),
rx->data, len );
} else {
DBGC ( port, "EXANIC %s RX too large\n",
netdev->name );
@@ -589,23 +584,19 @@ static void exanic_poll_rx ( struct net_device *netdev ) {
/* Check for overrun */
rmb();
copy_from_user ( &desc.generation, port->rx,
( offset + offsetof ( typeof ( *rx ),
desc.generation ) ),
sizeof ( desc.generation ) );
if ( desc.generation != current ) {
if ( rx->desc.generation != current ) {
DBGC ( port, "EXANIC %s RX overrun\n", netdev->name );
port->rx_rc = -ENOBUFS;
continue;
}
/* Wait for end of packet */
if ( ! desc.len )
if ( ! rx->desc.len )
continue;
/* Check for receive errors */
if ( desc.status & EXANIC_STATUS_ERROR_MASK ) {
port->rx_rc = -EIO_STATUS ( desc.status );
if ( rx->desc.status & EXANIC_STATUS_ERROR_MASK ) {
port->rx_rc = -EIO_STATUS ( rx->desc.status );
DBGC ( port, "EXANIC %s RX %04x error: %s\n",
netdev->name, port->rx_cons,
strerror ( port->rx_rc ) );

View File

@@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
#include <stdint.h>
#include <ipxe/pci.h>
#include <ipxe/ethernet.h>
#include <ipxe/uaccess.h>
#include <ipxe/retry.h>
#include <ipxe/i2c.h>
#include <ipxe/bitbash.h>
@@ -158,6 +157,9 @@ struct exanic_rx_chunk {
/** Receive status error mask */
#define EXANIC_STATUS_ERROR_MASK 0x0f
/** Number of receive chunks */
#define EXANIC_RX_COUNT ( EXANIC_RX_LEN / sizeof ( struct exanic_rx_chunk ) )
/** An ExaNIC I2C bus configuration */
struct exanic_i2c_config {
/** GPIO bit for pulling SCL low */
@@ -194,7 +196,7 @@ struct exanic_port {
uint16_t *txf;
/** Receive region */
userptr_t rx;
struct exanic_rx_chunk *rx;
/** Receive consumer counter */
unsigned int rx_cons;
/** Receive I/O buffer (if any) */