Browse Source

[vmxnet3] Avoid completely filling the TX descriptor ring

Modified-by: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Carl Henrik Lunde 8 years ago
parent
commit
3f8da985aa
2 changed files with 12 additions and 4 deletions
  1. 9
    4
      src/drivers/net/vmxnet3.c
  2. 3
    0
      src/drivers/net/vmxnet3.h

+ 9
- 4
src/drivers/net/vmxnet3.c View File

@@ -92,19 +92,24 @@ static int vmxnet3_transmit ( struct net_device *netdev,
92 92
 			      struct io_buffer *iobuf ) {
93 93
 	struct vmxnet3_nic *vmxnet = netdev_priv ( netdev );
94 94
 	struct vmxnet3_tx_desc *tx_desc;
95
+	unsigned int fill;
95 96
 	unsigned int desc_idx;
96 97
 	unsigned int generation;
97 98
 
98 99
 	/* Check that we have a free transmit descriptor */
99
-	desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC );
100
-	generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ?
101
-		       0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) );
102
-	if ( vmxnet->tx_iobuf[desc_idx] ) {
100
+	fill = ( vmxnet->count.tx_prod - vmxnet->count.tx_cons );
101
+	if ( fill >= VMXNET3_TX_FILL ) {
103 102
 		DBGC ( vmxnet, "VMXNET3 %p out of transmit descriptors\n",
104 103
 		       vmxnet );
105 104
 		return -ENOBUFS;
106 105
 	}
107 106
 
107
+	/* Locate transmit descriptor */
108
+	desc_idx = ( vmxnet->count.tx_prod % VMXNET3_NUM_TX_DESC );
109
+	generation = ( ( vmxnet->count.tx_prod & VMXNET3_NUM_TX_DESC ) ?
110
+		       0 : cpu_to_le32 ( VMXNET3_TXF_GEN ) );
111
+	assert ( vmxnet->tx_iobuf[desc_idx] == NULL );
112
+
108 113
 	/* Increment producer counter */
109 114
 	vmxnet->count.tx_prod++;
110 115
 

+ 3
- 0
src/drivers/net/vmxnet3.h View File

@@ -493,6 +493,9 @@ struct vmxnet3_nic {
493 493
 /** MTU size */
494 494
 #define VMXNET3_MTU ( ETH_FRAME_LEN + 4 /* VLAN */ + 4 /* FCS */ )
495 495
 
496
+/** Transmit ring maximum fill level */
497
+#define VMXNET3_TX_FILL ( VMXNET3_NUM_TX_DESC - 1 )
498
+
496 499
 /** Receive ring maximum fill level */
497 500
 #define VMXNET3_RX_FILL 8
498 501
 

Loading…
Cancel
Save