mirror of
https://github.com/ipxe/ipxe
synced 2025-12-15 09:04:37 +03:00
[exanic] Replace uses of userptr_t with direct pointer dereferences
Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -540,26 +540,23 @@ static void exanic_poll_tx ( struct net_device *netdev ) {
|
|||||||
static void exanic_poll_rx ( struct net_device *netdev ) {
|
static void exanic_poll_rx ( struct net_device *netdev ) {
|
||||||
struct exanic_port *port = netdev->priv;
|
struct exanic_port *port = netdev->priv;
|
||||||
struct exanic_rx_chunk *rx;
|
struct exanic_rx_chunk *rx;
|
||||||
struct exanic_rx_descriptor desc;
|
unsigned int index;
|
||||||
uint8_t current;
|
uint8_t current;
|
||||||
uint8_t previous;
|
uint8_t previous;
|
||||||
size_t offset;
|
|
||||||
size_t len;
|
size_t len;
|
||||||
|
|
||||||
for ( ; ; port->rx_cons++ ) {
|
for ( ; ; port->rx_cons++ ) {
|
||||||
|
|
||||||
/* Fetch descriptor */
|
/* Fetch descriptor */
|
||||||
offset = ( ( port->rx_cons * sizeof ( *rx ) ) % EXANIC_RX_LEN );
|
index = ( port->rx_cons % EXANIC_RX_COUNT );
|
||||||
copy_from_user ( &desc, port->rx,
|
rx = &port->rx[index];
|
||||||
( offset + offsetof ( typeof ( *rx ), desc ) ),
|
|
||||||
sizeof ( desc ) );
|
|
||||||
|
|
||||||
/* Calculate generation */
|
/* Calculate generation */
|
||||||
current = ( port->rx_cons / ( EXANIC_RX_LEN / sizeof ( *rx ) ));
|
current = ( port->rx_cons / EXANIC_RX_COUNT );
|
||||||
previous = ( current - 1 );
|
previous = ( current - 1 );
|
||||||
|
|
||||||
/* Do nothing if no chunk is ready */
|
/* Do nothing if no chunk is ready */
|
||||||
if ( desc.generation == previous )
|
if ( rx->desc.generation == previous )
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/* Allocate I/O buffer if needed */
|
/* Allocate I/O buffer if needed */
|
||||||
@@ -573,14 +570,12 @@ static void exanic_poll_rx ( struct net_device *netdev ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Calculate chunk length */
|
/* 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 */
|
/* Append data to I/O buffer */
|
||||||
if ( len <= iob_tailroom ( port->rx_iobuf ) ) {
|
if ( len <= iob_tailroom ( port->rx_iobuf ) ) {
|
||||||
copy_from_user ( iob_put ( port->rx_iobuf, len ),
|
memcpy ( iob_put ( port->rx_iobuf, len ),
|
||||||
port->rx,
|
rx->data, len );
|
||||||
( offset + offsetof ( typeof ( *rx ),
|
|
||||||
data ) ), len );
|
|
||||||
} else {
|
} else {
|
||||||
DBGC ( port, "EXANIC %s RX too large\n",
|
DBGC ( port, "EXANIC %s RX too large\n",
|
||||||
netdev->name );
|
netdev->name );
|
||||||
@@ -589,23 +584,19 @@ static void exanic_poll_rx ( struct net_device *netdev ) {
|
|||||||
|
|
||||||
/* Check for overrun */
|
/* Check for overrun */
|
||||||
rmb();
|
rmb();
|
||||||
copy_from_user ( &desc.generation, port->rx,
|
if ( rx->desc.generation != current ) {
|
||||||
( offset + offsetof ( typeof ( *rx ),
|
|
||||||
desc.generation ) ),
|
|
||||||
sizeof ( desc.generation ) );
|
|
||||||
if ( desc.generation != current ) {
|
|
||||||
DBGC ( port, "EXANIC %s RX overrun\n", netdev->name );
|
DBGC ( port, "EXANIC %s RX overrun\n", netdev->name );
|
||||||
port->rx_rc = -ENOBUFS;
|
port->rx_rc = -ENOBUFS;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Wait for end of packet */
|
/* Wait for end of packet */
|
||||||
if ( ! desc.len )
|
if ( ! rx->desc.len )
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
/* Check for receive errors */
|
/* Check for receive errors */
|
||||||
if ( desc.status & EXANIC_STATUS_ERROR_MASK ) {
|
if ( rx->desc.status & EXANIC_STATUS_ERROR_MASK ) {
|
||||||
port->rx_rc = -EIO_STATUS ( desc.status );
|
port->rx_rc = -EIO_STATUS ( rx->desc.status );
|
||||||
DBGC ( port, "EXANIC %s RX %04x error: %s\n",
|
DBGC ( port, "EXANIC %s RX %04x error: %s\n",
|
||||||
netdev->name, port->rx_cons,
|
netdev->name, port->rx_cons,
|
||||||
strerror ( port->rx_rc ) );
|
strerror ( port->rx_rc ) );
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
|
|||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <ipxe/pci.h>
|
#include <ipxe/pci.h>
|
||||||
#include <ipxe/ethernet.h>
|
#include <ipxe/ethernet.h>
|
||||||
#include <ipxe/uaccess.h>
|
|
||||||
#include <ipxe/retry.h>
|
#include <ipxe/retry.h>
|
||||||
#include <ipxe/i2c.h>
|
#include <ipxe/i2c.h>
|
||||||
#include <ipxe/bitbash.h>
|
#include <ipxe/bitbash.h>
|
||||||
@@ -158,6 +157,9 @@ struct exanic_rx_chunk {
|
|||||||
/** Receive status error mask */
|
/** Receive status error mask */
|
||||||
#define EXANIC_STATUS_ERROR_MASK 0x0f
|
#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 */
|
/** An ExaNIC I2C bus configuration */
|
||||||
struct exanic_i2c_config {
|
struct exanic_i2c_config {
|
||||||
/** GPIO bit for pulling SCL low */
|
/** GPIO bit for pulling SCL low */
|
||||||
@@ -194,7 +196,7 @@ struct exanic_port {
|
|||||||
uint16_t *txf;
|
uint16_t *txf;
|
||||||
|
|
||||||
/** Receive region */
|
/** Receive region */
|
||||||
userptr_t rx;
|
struct exanic_rx_chunk *rx;
|
||||||
/** Receive consumer counter */
|
/** Receive consumer counter */
|
||||||
unsigned int rx_cons;
|
unsigned int rx_cons;
|
||||||
/** Receive I/O buffer (if any) */
|
/** Receive I/O buffer (if any) */
|
||||||
|
|||||||
Reference in New Issue
Block a user