Skip to content

Commit 945df9b

Browse files
committed
[gve] Replace uses of userptr_t with direct pointer dereferences
Signed-off-by: Michael Brown <mcb30@ipxe.org>
1 parent 839540c commit 945df9b

File tree

2 files changed

+67
-64
lines changed

2 files changed

+67
-64
lines changed

src/drivers/net/gve.c

Lines changed: 52 additions & 60 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,8 @@ static void gve_create_tx_param ( struct gve_queue *queue,
578578

579579
/* Construct request parameters */
580580
create->res = cpu_to_be64 ( dma ( &queue->res_map, queue->res ) );
581-
create->desc = cpu_to_be64 ( dma ( &queue->desc_map, queue->desc ) );
581+
create->desc =
582+
cpu_to_be64 ( dma ( &queue->desc_map, queue->desc.tx ) );
582583
create->qpl_id = cpu_to_be32 ( type->qpl );
583584
create->notify_id = cpu_to_be32 ( type->irq );
584585
}
@@ -597,8 +598,10 @@ static void gve_create_rx_param ( struct gve_queue *queue,
597598
/* Construct request parameters */
598599
create->notify_id = cpu_to_be32 ( type->irq );
599600
create->res = cpu_to_be64 ( dma ( &queue->res_map, queue->res ) );
600-
create->desc = cpu_to_be64 ( dma ( &queue->desc_map, queue->desc ) );
601-
create->cmplt = cpu_to_be64 ( dma ( &queue->cmplt_map, queue->cmplt ));
601+
create->desc =
602+
cpu_to_be64 ( dma ( &queue->desc_map, queue->desc.rx ) );
603+
create->cmplt =
604+
cpu_to_be64 ( dma ( &queue->cmplt_map, queue->cmplt.rx ) );
602605
create->qpl_id = cpu_to_be32 ( type->qpl );
603606
create->bufsz = cpu_to_be16 ( GVE_BUF_SIZE );
604607
}
@@ -800,7 +803,7 @@ gve_address ( struct gve_queue *queue, unsigned int index ) {
800803
* @v index Buffer index
801804
* @ret addr Buffer address
802805
*/
803-
static inline __attribute__ (( always_inline )) userptr_t
806+
static inline __attribute__ (( always_inline )) void *
804807
gve_buffer ( struct gve_queue *queue, unsigned int index ) {
805808

806809
/* Pages are currently allocated as a single contiguous block */
@@ -845,8 +848,7 @@ static int gve_alloc_queue ( struct gve_nic *gve, struct gve_queue *queue ) {
845848
size_t desc_len = ( queue->count * type->desc_len );
846849
size_t cmplt_len = ( queue->count * type->cmplt_len );
847850
size_t res_len = sizeof ( *queue->res );
848-
struct gve_buffer buf;
849-
size_t offset;
851+
struct gve_buffer *buf;
850852
unsigned int i;
851853
int rc;
852854

@@ -873,27 +875,27 @@ static int gve_alloc_queue ( struct gve_nic *gve, struct gve_queue *queue ) {
873875
goto err_qpl;
874876

875877
/* Allocate descriptors */
876-
queue->desc = dma_umalloc ( dma, &queue->desc_map, desc_len,
877-
GVE_ALIGN );
878-
if ( ! queue->desc ) {
878+
queue->desc.raw = dma_umalloc ( dma, &queue->desc_map, desc_len,
879+
GVE_ALIGN );
880+
if ( ! queue->desc.raw ) {
879881
rc = -ENOMEM;
880882
goto err_desc;
881883
}
882884
DBGC ( gve, "GVE %p %s descriptors at [%08lx,%08lx)\n",
883-
gve, type->name, virt_to_phys ( queue->desc ),
884-
( virt_to_phys ( queue->desc ) + desc_len ) );
885+
gve, type->name, virt_to_phys ( queue->desc.raw ),
886+
( virt_to_phys ( queue->desc.raw ) + desc_len ) );
885887

886888
/* Allocate completions */
887889
if ( cmplt_len ) {
888-
queue->cmplt = dma_umalloc ( dma, &queue->cmplt_map, cmplt_len,
889-
GVE_ALIGN );
890-
if ( ! queue->cmplt ) {
890+
queue->cmplt.raw = dma_umalloc ( dma, &queue->cmplt_map,
891+
cmplt_len, GVE_ALIGN );
892+
if ( ! queue->cmplt.raw ) {
891893
rc = -ENOMEM;
892894
goto err_cmplt;
893895
}
894896
DBGC ( gve, "GVE %p %s completions at [%08lx,%08lx)\n",
895-
gve, type->name, virt_to_phys ( queue->cmplt ),
896-
( virt_to_phys ( queue->cmplt ) + cmplt_len ) );
897+
gve, type->name, virt_to_phys ( queue->cmplt.raw ),
898+
( virt_to_phys ( queue->cmplt.raw ) + cmplt_len ) );
897899
}
898900

899901
/* Allocate queue resources */
@@ -905,21 +907,20 @@ static int gve_alloc_queue ( struct gve_nic *gve, struct gve_queue *queue ) {
905907
memset ( queue->res, 0, res_len );
906908

907909
/* Populate descriptor offsets */
908-
offset = ( type->desc_len - sizeof ( buf ) );
910+
buf = ( queue->desc.raw + type->desc_len - sizeof ( *buf ) );
909911
for ( i = 0 ; i < queue->count ; i++ ) {
910-
buf.addr = cpu_to_be64 ( gve_address ( queue, i ) );
911-
copy_to_user ( queue->desc, offset, &buf, sizeof ( buf ) );
912-
offset += type->desc_len;
912+
buf->addr = cpu_to_be64 ( gve_address ( queue, i ) );
913+
buf = ( ( ( void * ) buf ) + type->desc_len );
913914
}
914915

915916
return 0;
916917

917918
dma_free ( &queue->res_map, queue->res, res_len );
918919
err_res:
919920
if ( cmplt_len )
920-
dma_ufree ( &queue->cmplt_map, queue->cmplt, cmplt_len );
921+
dma_ufree ( &queue->cmplt_map, queue->cmplt.raw, cmplt_len );
921922
err_cmplt:
922-
dma_ufree ( &queue->desc_map, queue->desc, desc_len );
923+
dma_ufree ( &queue->desc_map, queue->desc.raw, desc_len );
923924
err_desc:
924925
gve_free_qpl ( gve, &queue->qpl );
925926
err_qpl:
@@ -944,10 +945,10 @@ static void gve_free_queue ( struct gve_nic *gve, struct gve_queue *queue ) {
944945

945946
/* Free completions, if applicable */
946947
if ( cmplt_len )
947-
dma_ufree ( &queue->cmplt_map, queue->cmplt, cmplt_len );
948+
dma_ufree ( &queue->cmplt_map, queue->cmplt.raw, cmplt_len );
948949

949950
/* Free descriptors */
950-
dma_ufree ( &queue->desc_map, queue->desc, desc_len );
951+
dma_ufree ( &queue->desc_map, queue->desc.raw, desc_len );
951952

952953
/* Free queue page list */
953954
gve_free_qpl ( gve, &queue->qpl );
@@ -977,7 +978,7 @@ static int gve_start ( struct gve_nic *gve ) {
977978
}
978979

979980
/* Invalidate receive completions */
980-
memset ( rx->cmplt, 0, ( rx->count * rx->type->cmplt_len ) );
981+
memset ( rx->cmplt.raw, 0, ( rx->count * rx->type->cmplt_len ) );
981982

982983
/* Reset receive sequence */
983984
gve->seq = gve_next ( 0 );
@@ -1209,7 +1210,7 @@ static void gve_close ( struct net_device *netdev ) {
12091210
static int gve_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
12101211
struct gve_nic *gve = netdev->priv;
12111212
struct gve_queue *tx = &gve->tx;
1212-
struct gve_tx_descriptor desc;
1213+
struct gve_tx_descriptor *desc;
12131214
unsigned int count;
12141215
unsigned int index;
12151216
size_t frag_len;
@@ -1238,26 +1239,25 @@ static int gve_transmit ( struct net_device *netdev, struct io_buffer *iobuf ) {
12381239
frag_len = ( len - offset );
12391240
if ( frag_len > GVE_BUF_SIZE )
12401241
frag_len = GVE_BUF_SIZE;
1241-
copy_to_user ( gve_buffer ( tx, tx->prod ), 0,
1242-
( iobuf->data + offset ), frag_len );
1242+
memcpy ( gve_buffer ( tx, tx->prod ),
1243+
( iobuf->data + offset ), frag_len );
12431244

12441245
/* Populate descriptor */
12451246
index = ( tx->prod++ & ( tx->count - 1 ) );
1246-
memset ( &desc.pkt, 0, sizeof ( desc.pkt ) );
1247+
desc = &tx->desc.tx[index];
1248+
memset ( &desc->pkt, 0, sizeof ( desc->pkt ) );
12471249
if ( offset ) {
1248-
desc.pkt.type = GVE_TX_TYPE_CONT;
1250+
desc->pkt.type = GVE_TX_TYPE_CONT;
12491251
} else {
1250-
desc.pkt.type = GVE_TX_TYPE_START;
1251-
desc.pkt.count = count;
1252-
desc.pkt.total = cpu_to_be16 ( len );
1252+
desc->pkt.type = GVE_TX_TYPE_START;
1253+
desc->pkt.count = count;
1254+
desc->pkt.total = cpu_to_be16 ( len );
12531255
}
1254-
desc.pkt.len = cpu_to_be16 ( frag_len );
1255-
copy_to_user ( tx->desc, ( index * sizeof ( desc ) ), &desc,
1256-
sizeof ( desc.pkt ) );
1256+
desc->pkt.len = cpu_to_be16 ( frag_len );
12571257
DBGC2 ( gve, "GVE %p TX %#04x %#02x:%#02x len %#04x/%#04x at "
1258-
"%#08zx\n", gve, index, desc.pkt.type, desc.pkt.count,
1259-
be16_to_cpu ( desc.pkt.len ),
1260-
be16_to_cpu ( desc.pkt.total ),
1258+
"%#08zx\n", gve, index, desc->pkt.type,
1259+
desc->pkt.count, be16_to_cpu ( desc->pkt.len ),
1260+
be16_to_cpu ( desc->pkt.total ),
12611261
gve_address ( tx, index ) );
12621262
}
12631263
assert ( ( tx->prod - tx->cons ) <= tx->fill );
@@ -1305,12 +1305,11 @@ static void gve_poll_tx ( struct net_device *netdev ) {
13051305
static void gve_poll_rx ( struct net_device *netdev ) {
13061306
struct gve_nic *gve = netdev->priv;
13071307
struct gve_queue *rx = &gve->rx;
1308-
struct gve_rx_completion cmplt;
1308+
struct gve_rx_completion *cmplt;
13091309
struct io_buffer *iobuf;
13101310
unsigned int index;
13111311
unsigned int seq;
13121312
uint32_t cons;
1313-
size_t offset;
13141313
size_t total;
13151314
size_t len;
13161315
int rc;
@@ -1323,28 +1322,25 @@ static void gve_poll_rx ( struct net_device *netdev ) {
13231322

13241323
/* Read next possible completion */
13251324
index = ( cons++ & ( rx->count - 1 ) );
1326-
offset = ( ( index * sizeof ( cmplt ) ) +
1327-
offsetof ( typeof ( cmplt ), pkt ) );
1328-
copy_from_user ( &cmplt.pkt, rx->cmplt, offset,
1329-
sizeof ( cmplt.pkt ) );
1325+
cmplt = &rx->cmplt.rx[index];
13301326

13311327
/* Check sequence number */
1332-
if ( ( cmplt.pkt.seq & GVE_RX_SEQ_MASK ) != seq )
1328+
if ( ( cmplt->pkt.seq & GVE_RX_SEQ_MASK ) != seq )
13331329
break;
13341330
seq = gve_next ( seq );
13351331

13361332
/* Parse completion */
1337-
len = be16_to_cpu ( cmplt.pkt.len );
1333+
len = be16_to_cpu ( cmplt->pkt.len );
13381334
DBGC2 ( gve, "GVE %p RX %#04x %#02x:%#02x len %#04zx at "
1339-
"%#08zx\n", gve, index, cmplt.pkt.seq, cmplt.pkt.flags,
1340-
len, gve_address ( rx, index ) );
1335+
"%#08zx\n", gve, index, cmplt->pkt.seq,
1336+
cmplt->pkt.flags, len, gve_address ( rx, index ) );
13411337

13421338
/* Accumulate a complete packet */
1343-
if ( cmplt.pkt.flags & GVE_RXF_ERROR ) {
1339+
if ( cmplt->pkt.flags & GVE_RXF_ERROR ) {
13441340
total = 0;
13451341
} else {
13461342
total += len;
1347-
if ( cmplt.pkt.flags & GVE_RXF_MORE )
1343+
if ( cmplt->pkt.flags & GVE_RXF_MORE )
13481344
continue;
13491345
}
13501346
gve->seq = seq;
@@ -1355,17 +1351,13 @@ static void gve_poll_rx ( struct net_device *netdev ) {
13551351

13561352
/* Re-read completion length */
13571353
index = ( rx->cons & ( rx->count - 1 ) );
1358-
offset = ( ( index * sizeof ( cmplt ) ) +
1359-
offsetof ( typeof ( cmplt ), pkt.len ) );
1360-
copy_from_user ( &cmplt.pkt, rx->cmplt, offset,
1361-
sizeof ( cmplt.pkt.len ) );
1354+
cmplt = &rx->cmplt.rx[index];
13621355

13631356
/* Copy data */
13641357
if ( iobuf ) {
1365-
len = be16_to_cpu ( cmplt.pkt.len );
1366-
copy_from_user ( iob_put ( iobuf, len ),
1367-
gve_buffer ( rx, rx->cons ),
1368-
0, len );
1358+
len = be16_to_cpu ( cmplt->pkt.len );
1359+
memcpy ( iob_put ( iobuf, len ),
1360+
gve_buffer ( rx, rx->cons ), len );
13691361
}
13701362
}
13711363
assert ( ( iobuf == NULL ) || ( iob_len ( iobuf ) == total ) );
@@ -1376,7 +1368,7 @@ static void gve_poll_rx ( struct net_device *netdev ) {
13761368
iob_pull ( iobuf, GVE_RX_PAD );
13771369
netdev_rx ( netdev, iobuf );
13781370
} else {
1379-
rc = ( ( cmplt.pkt.flags & GVE_RXF_ERROR ) ?
1371+
rc = ( ( cmplt->pkt.flags & GVE_RXF_ERROR ) ?
13801372
-EIO : -ENOMEM );
13811373
netdev_rx_err ( netdev, NULL, rc );
13821374
}

src/drivers/net/gve.h

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
1717
#include <ipxe/dma.h>
1818
#include <ipxe/pci.h>
1919
#include <ipxe/in.h>
20-
#include <ipxe/uaccess.h>
2120
#include <ipxe/process.h>
2221
#include <ipxe/retry.h>
2322

@@ -459,7 +458,7 @@ struct gve_resources {
459458
*/
460459
struct gve_qpl {
461460
/** Page addresses */
462-
userptr_t data;
461+
void *data;
463462
/** Page mapping */
464463
struct dma_mapping map;
465464
/** Number of pages */
@@ -569,9 +568,21 @@ struct gve_rx_completion {
569568
/** A descriptor queue */
570569
struct gve_queue {
571570
/** Descriptor ring */
572-
userptr_t desc;
571+
union {
572+
/** Transmit descriptors */
573+
struct gve_tx_descriptor *tx;
574+
/** Receive descriptors */
575+
struct gve_rx_descriptor *rx;
576+
/** Raw data */
577+
void *raw;
578+
} desc;
573579
/** Completion ring */
574-
userptr_t cmplt;
580+
union {
581+
/** Receive completions */
582+
struct gve_rx_completion *rx;
583+
/** Raw data */
584+
void *raw;
585+
} cmplt;
575586
/** Queue resources */
576587
struct gve_resources *res;
577588

0 commit comments

Comments
 (0)