[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[cdi-devel] [PATCH 2/7] e1000: Make descriptors volatile



The hardware is supposed to write to these, so let's make sure that the
compiler doesn't cache any values. While at it, assert the right
alignment.

Signed-off-by: Kevin Wolf <kevin@xxxxxxxxxx>
---
 e1000/device.h | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/e1000/device.h b/e1000/device.h
index 314ba87..7b0ae03 100644
--- a/e1000/device.h
+++ b/e1000/device.h
@@ -144,6 +144,7 @@ struct e1000_tx_descriptor {
     uint8_t             checksum_start;
     uint16_t            special;
 } __attribute__((packed)) __attribute__((aligned (4)));
+CDI_BUILD_BUG_ON((sizeof(struct e1000_tx_descriptor) * TX_BUFFER_NUM) % 128);
 
 enum {
     TX_CMD_EOP  = 0x01,
@@ -158,17 +159,18 @@ struct e1000_rx_descriptor {
     uint8_t             error;
     uint16_t            padding2;
 } __attribute__((packed)) __attribute__((aligned (4)));
+CDI_BUILD_BUG_ON((sizeof(struct e1000_rx_descriptor) * RX_BUFFER_NUM) % 128);
 
 struct e1000_device {
     struct cdi_net_device       net;
 
     uintptr_t                   phys;
 
-    struct e1000_tx_descriptor  tx_desc[TX_BUFFER_NUM] __attribute__((aligned(16)));
+    volatile struct e1000_tx_descriptor  tx_desc[TX_BUFFER_NUM] __attribute__((aligned(16)));
     uint8_t                     tx_buffer[TX_BUFFER_NUM * TX_BUFFER_SIZE];
     uint32_t                    tx_cur_buffer;
 
-    struct e1000_rx_descriptor  rx_desc[RX_BUFFER_NUM] __attribute__((aligned(16)));
+    volatile struct e1000_rx_descriptor  rx_desc[RX_BUFFER_NUM] __attribute__((aligned(16)));
     uint8_t                     rx_buffer[RX_BUFFER_NUM * RX_BUFFER_SIZE];
     uint32_t                    rx_cur_buffer;
 
-- 
2.1.4