aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAl Viro <viro@ftp.linux.org.uk>2007-12-16 18:30:08 -0500
committerDavid S. Miller <davem@davemloft.net>2008-01-28 18:07:09 -0500
commitf3ec33e587df02e25963755989cc473e3f07bf0d (patch)
tree5f176f664af9b9b8ad76ca5fdfd8fd68de6a1fe5
parentb710b43c306650261c01ad08100791afec78a7db (diff)
sunhme endianness annotations
This one is interesting - SBUS and PCI variants have opposite endianness in descriptors (SBUS is sparc-only, so there host-endian == big-endian). Solution: declare a bitwise type (hme32) and in accessor helpers do typechecking and force-casts (once we know that the type is right). Signed-off-by: Al Viro <viro@zeniv.linux.org.uk> Signed-off-by: Jeff Garzik <jeff@garzik.org>
-rw-r--r--drivers/net/sunhme.c49
-rw-r--r--drivers/net/sunhme.h12
2 files changed, 33 insertions, 28 deletions
diff --git a/drivers/net/sunhme.c b/drivers/net/sunhme.c
index 9cc13dd8a821..25ce26a882d1 100644
--- a/drivers/net/sunhme.c
+++ b/drivers/net/sunhme.c
@@ -194,21 +194,21 @@ static u32 sbus_hme_read32(void __iomem *reg)
194 194
195static void sbus_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr) 195static void sbus_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr)
196{ 196{
197 rxd->rx_addr = addr; 197 rxd->rx_addr = (__force hme32)addr;
198 wmb(); 198 wmb();
199 rxd->rx_flags = flags; 199 rxd->rx_flags = (__force hme32)flags;
200} 200}
201 201
202static void sbus_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr) 202static void sbus_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr)
203{ 203{
204 txd->tx_addr = addr; 204 txd->tx_addr = (__force hme32)addr;
205 wmb(); 205 wmb();
206 txd->tx_flags = flags; 206 txd->tx_flags = (__force hme32)flags;
207} 207}
208 208
209static u32 sbus_hme_read_desc32(u32 *p) 209static u32 sbus_hme_read_desc32(hme32 *p)
210{ 210{
211 return *p; 211 return (__force u32)*p;
212} 212}
213 213
214static void pci_hme_write32(void __iomem *reg, u32 val) 214static void pci_hme_write32(void __iomem *reg, u32 val)
@@ -223,21 +223,21 @@ static u32 pci_hme_read32(void __iomem *reg)
223 223
224static void pci_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr) 224static void pci_hme_write_rxd(struct happy_meal_rxd *rxd, u32 flags, u32 addr)
225{ 225{
226 rxd->rx_addr = cpu_to_le32(addr); 226 rxd->rx_addr = (__force hme32)cpu_to_le32(addr);
227 wmb(); 227 wmb();
228 rxd->rx_flags = cpu_to_le32(flags); 228 rxd->rx_flags = (__force hme32)cpu_to_le32(flags);
229} 229}
230 230
231static void pci_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr) 231static void pci_hme_write_txd(struct happy_meal_txd *txd, u32 flags, u32 addr)
232{ 232{
233 txd->tx_addr = cpu_to_le32(addr); 233 txd->tx_addr = (__force hme32)cpu_to_le32(addr);
234 wmb(); 234 wmb();
235 txd->tx_flags = cpu_to_le32(flags); 235 txd->tx_flags = (__force hme32)cpu_to_le32(flags);
236} 236}
237 237
238static u32 pci_hme_read_desc32(u32 *p) 238static u32 pci_hme_read_desc32(hme32 *p)
239{ 239{
240 return cpu_to_le32p(p); 240 return le32_to_cpup((__le32 *)p);
241} 241}
242 242
243#define hme_write32(__hp, __reg, __val) \ 243#define hme_write32(__hp, __reg, __val) \
@@ -266,16 +266,16 @@ static u32 pci_hme_read_desc32(u32 *p)
266#define hme_read32(__hp, __reg) \ 266#define hme_read32(__hp, __reg) \
267 sbus_readl(__reg) 267 sbus_readl(__reg)
268#define hme_write_rxd(__hp, __rxd, __flags, __addr) \ 268#define hme_write_rxd(__hp, __rxd, __flags, __addr) \
269do { (__rxd)->rx_addr = (__addr); \ 269do { (__rxd)->rx_addr = (__force hme32)(u32)(__addr); \
270 wmb(); \ 270 wmb(); \
271 (__rxd)->rx_flags = (__flags); \ 271 (__rxd)->rx_flags = (__force hme32)(u32)(__flags); \
272} while(0) 272} while(0)
273#define hme_write_txd(__hp, __txd, __flags, __addr) \ 273#define hme_write_txd(__hp, __txd, __flags, __addr) \
274do { (__txd)->tx_addr = (__addr); \ 274do { (__txd)->tx_addr = (__force hme32)(u32)(__addr); \
275 wmb(); \ 275 wmb(); \
276 (__txd)->tx_flags = (__flags); \ 276 (__txd)->tx_flags = (__force hme32)(u32)(__flags); \
277} while(0) 277} while(0)
278#define hme_read_desc32(__hp, __p) (*(__p)) 278#define hme_read_desc32(__hp, __p) ((__force u32)(hme32)*(__p))
279#define hme_dma_map(__hp, __ptr, __size, __dir) \ 279#define hme_dma_map(__hp, __ptr, __size, __dir) \
280 sbus_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir)) 280 sbus_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir))
281#define hme_dma_unmap(__hp, __addr, __size, __dir) \ 281#define hme_dma_unmap(__hp, __addr, __size, __dir) \
@@ -291,16 +291,19 @@ do { (__txd)->tx_addr = (__addr); \
291#define hme_read32(__hp, __reg) \ 291#define hme_read32(__hp, __reg) \
292 readl(__reg) 292 readl(__reg)
293#define hme_write_rxd(__hp, __rxd, __flags, __addr) \ 293#define hme_write_rxd(__hp, __rxd, __flags, __addr) \
294do { (__rxd)->rx_addr = cpu_to_le32(__addr); \ 294do { (__rxd)->rx_addr = (__force hme32)cpu_to_le32(__addr); \
295 wmb(); \ 295 wmb(); \
296 (__rxd)->rx_flags = cpu_to_le32(__flags); \ 296 (__rxd)->rx_flags = (__force hme32)cpu_to_le32(__flags); \
297} while(0) 297} while(0)
298#define hme_write_txd(__hp, __txd, __flags, __addr) \ 298#define hme_write_txd(__hp, __txd, __flags, __addr) \
299do { (__txd)->tx_addr = cpu_to_le32(__addr); \ 299do { (__txd)->tx_addr = (__force hme32)cpu_to_le32(__addr); \
300 wmb(); \ 300 wmb(); \
301 (__txd)->tx_flags = cpu_to_le32(__flags); \ 301 (__txd)->tx_flags = (__force hme32)cpu_to_le32(__flags); \
302} while(0) 302} while(0)
303#define hme_read_desc32(__hp, __p) cpu_to_le32p(__p) 303static inline u32 hme_read_desc32(struct happy_meal *hp, hme32 *p)
304{
305 return le32_to_cpup((__le32 *)p);
306}
304#define hme_dma_map(__hp, __ptr, __size, __dir) \ 307#define hme_dma_map(__hp, __ptr, __size, __dir) \
305 pci_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir)) 308 pci_map_single((__hp)->happy_dev, (__ptr), (__size), (__dir))
306#define hme_dma_unmap(__hp, __addr, __size, __dir) \ 309#define hme_dma_unmap(__hp, __addr, __size, __dir) \
@@ -2075,7 +2078,7 @@ static void happy_meal_rx(struct happy_meal *hp, struct net_device *dev)
2075 } 2078 }
2076 2079
2077 /* This card is _fucking_ hot... */ 2080 /* This card is _fucking_ hot... */
2078 skb->csum = ntohs(csum ^ 0xffff); 2081 skb->csum = csum_unfold(~(__force __sum16)htons(csum));
2079 skb->ip_summed = CHECKSUM_COMPLETE; 2082 skb->ip_summed = CHECKSUM_COMPLETE;
2080 2083
2081 RXD(("len=%d csum=%4x]", len, csum)); 2084 RXD(("len=%d csum=%4x]", len, csum));
diff --git a/drivers/net/sunhme.h b/drivers/net/sunhme.h
index 90f446db9ba2..4da5539fac7b 100644
--- a/drivers/net/sunhme.h
+++ b/drivers/net/sunhme.h
@@ -302,9 +302,11 @@
302 * Always write the address first before setting the ownership 302 * Always write the address first before setting the ownership
303 * bits to avoid races with the hardware scanning the ring. 303 * bits to avoid races with the hardware scanning the ring.
304 */ 304 */
305typedef u32 __bitwise__ hme32;
306
305struct happy_meal_rxd { 307struct happy_meal_rxd {
306 u32 rx_flags; 308 hme32 rx_flags;
307 u32 rx_addr; 309 hme32 rx_addr;
308}; 310};
309 311
310#define RXFLAG_OWN 0x80000000 /* 1 = hardware, 0 = software */ 312#define RXFLAG_OWN 0x80000000 /* 1 = hardware, 0 = software */
@@ -313,8 +315,8 @@ struct happy_meal_rxd {
313#define RXFLAG_CSUM 0x0000ffff /* HW computed checksum */ 315#define RXFLAG_CSUM 0x0000ffff /* HW computed checksum */
314 316
315struct happy_meal_txd { 317struct happy_meal_txd {
316 u32 tx_flags; 318 hme32 tx_flags;
317 u32 tx_addr; 319 hme32 tx_addr;
318}; 320};
319 321
320#define TXFLAG_OWN 0x80000000 /* 1 = hardware, 0 = software */ 322#define TXFLAG_OWN 0x80000000 /* 1 = hardware, 0 = software */
@@ -400,7 +402,7 @@ struct happy_meal {
400 struct hmeal_init_block *happy_block; /* RX and TX descriptors (CPU addr) */ 402 struct hmeal_init_block *happy_block; /* RX and TX descriptors (CPU addr) */
401 403
402#if defined(CONFIG_SBUS) && defined(CONFIG_PCI) 404#if defined(CONFIG_SBUS) && defined(CONFIG_PCI)
403 u32 (*read_desc32)(u32 *); 405 u32 (*read_desc32)(hme32 *);
404 void (*write_txd)(struct happy_meal_txd *, u32, u32); 406 void (*write_txd)(struct happy_meal_txd *, u32, u32);
405 void (*write_rxd)(struct happy_meal_rxd *, u32, u32); 407 void (*write_rxd)(struct happy_meal_rxd *, u32, u32);
406 u32 (*dma_map)(void *, void *, long, int); 408 u32 (*dma_map)(void *, void *, long, int);