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 */
}
/* 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 );
/* 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 ) );
#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>
/** 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 */
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) */