diff options
author | Masakazu Mokuno <mokuno@sm.sony.co.jp> | 2008-02-07 05:57:54 -0500 |
---|---|---|
committer | Jeff Garzik <jeff@garzik.org> | 2008-02-11 10:29:41 -0500 |
commit | 100e1d891902e432951e88bffba0dc49005a216c (patch) | |
tree | 909d20fac03d21a5692e31896b5b11eb629dda8b | |
parent | b94e1d47684b0bee6088d848e29154697ea4c4bd (diff) |
PS3: gelic: Add endianness macros
Mark the members of the structure for DMA descriptors with proper endian
annotations and use the appropriate accessor macros.
As the gelic driver works only on PS3, all these macros will be
expanded to null.
Signed-off-by: Masakazu Mokuno <mokuno@sm.sony.co.jp>
Signed-off-by: Jeff Garzik <jeff@garzik.org>
-rw-r--r-- | drivers/net/ps3_gelic_net.c | 70 | ||||
-rw-r--r-- | drivers/net/ps3_gelic_net.h | 16 |
2 files changed, 47 insertions, 39 deletions
diff --git a/drivers/net/ps3_gelic_net.c b/drivers/net/ps3_gelic_net.c index f6fb556a0f59..81e77d3d7804 100644 --- a/drivers/net/ps3_gelic_net.c +++ b/drivers/net/ps3_gelic_net.c | |||
@@ -98,7 +98,7 @@ gelic_net_get_descr_status(struct gelic_net_descr *descr) | |||
98 | { | 98 | { |
99 | u32 cmd_status; | 99 | u32 cmd_status; |
100 | 100 | ||
101 | cmd_status = descr->dmac_cmd_status; | 101 | cmd_status = be32_to_cpu(descr->dmac_cmd_status); |
102 | cmd_status >>= GELIC_NET_DESCR_IND_PROC_SHIFT; | 102 | cmd_status >>= GELIC_NET_DESCR_IND_PROC_SHIFT; |
103 | return cmd_status; | 103 | return cmd_status; |
104 | } | 104 | } |
@@ -117,13 +117,13 @@ static void gelic_net_set_descr_status(struct gelic_net_descr *descr, | |||
117 | u32 cmd_status; | 117 | u32 cmd_status; |
118 | 118 | ||
119 | /* read the status */ | 119 | /* read the status */ |
120 | cmd_status = descr->dmac_cmd_status; | 120 | cmd_status = be32_to_cpu(descr->dmac_cmd_status); |
121 | /* clean the upper 4 bits */ | 121 | /* clean the upper 4 bits */ |
122 | cmd_status &= GELIC_NET_DESCR_IND_PROC_MASKO; | 122 | cmd_status &= GELIC_NET_DESCR_IND_PROC_MASKO; |
123 | /* add the status to it */ | 123 | /* add the status to it */ |
124 | cmd_status |= ((u32)status) << GELIC_NET_DESCR_IND_PROC_SHIFT; | 124 | cmd_status |= ((u32)status) << GELIC_NET_DESCR_IND_PROC_SHIFT; |
125 | /* and write it back */ | 125 | /* and write it back */ |
126 | descr->dmac_cmd_status = cmd_status; | 126 | descr->dmac_cmd_status = cpu_to_be32(cmd_status); |
127 | /* | 127 | /* |
128 | * dma_cmd_status field is used to indicate whether the descriptor | 128 | * dma_cmd_status field is used to indicate whether the descriptor |
129 | * is valid or not. | 129 | * is valid or not. |
@@ -193,7 +193,7 @@ static int gelic_net_init_chain(struct gelic_net_card *card, | |||
193 | /* chain bus addr of hw descriptor */ | 193 | /* chain bus addr of hw descriptor */ |
194 | descr = start_descr; | 194 | descr = start_descr; |
195 | for (i = 0; i < no; i++, descr++) { | 195 | for (i = 0; i < no; i++, descr++) { |
196 | descr->next_descr_addr = descr->next->bus_addr; | 196 | descr->next_descr_addr = cpu_to_be32(descr->next->bus_addr); |
197 | } | 197 | } |
198 | 198 | ||
199 | chain->head = start_descr; | 199 | chain->head = start_descr; |
@@ -245,7 +245,7 @@ static int gelic_net_prepare_rx_descr(struct gelic_net_card *card, | |||
245 | "%s:allocate skb failed !!\n", __func__); | 245 | "%s:allocate skb failed !!\n", __func__); |
246 | return -ENOMEM; | 246 | return -ENOMEM; |
247 | } | 247 | } |
248 | descr->buf_size = bufsize; | 248 | descr->buf_size = cpu_to_be32(bufsize); |
249 | descr->dmac_cmd_status = 0; | 249 | descr->dmac_cmd_status = 0; |
250 | descr->result_size = 0; | 250 | descr->result_size = 0; |
251 | descr->valid_size = 0; | 251 | descr->valid_size = 0; |
@@ -256,9 +256,10 @@ static int gelic_net_prepare_rx_descr(struct gelic_net_card *card, | |||
256 | if (offset) | 256 | if (offset) |
257 | skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset); | 257 | skb_reserve(descr->skb, GELIC_NET_RXBUF_ALIGN - offset); |
258 | /* io-mmu-map the skb */ | 258 | /* io-mmu-map the skb */ |
259 | descr->buf_addr = dma_map_single(ctodev(card), descr->skb->data, | 259 | descr->buf_addr = cpu_to_be32(dma_map_single(ctodev(card), |
260 | GELIC_NET_MAX_MTU, | 260 | descr->skb->data, |
261 | DMA_FROM_DEVICE); | 261 | GELIC_NET_MAX_MTU, |
262 | DMA_FROM_DEVICE)); | ||
262 | if (!descr->buf_addr) { | 263 | if (!descr->buf_addr) { |
263 | dev_kfree_skb_any(descr->skb); | 264 | dev_kfree_skb_any(descr->skb); |
264 | descr->skb = NULL; | 265 | descr->skb = NULL; |
@@ -284,7 +285,7 @@ static void gelic_net_release_rx_chain(struct gelic_net_card *card) | |||
284 | do { | 285 | do { |
285 | if (descr->skb) { | 286 | if (descr->skb) { |
286 | dma_unmap_single(ctodev(card), | 287 | dma_unmap_single(ctodev(card), |
287 | descr->buf_addr, | 288 | be32_to_cpu(descr->buf_addr), |
288 | descr->skb->len, | 289 | descr->skb->len, |
289 | DMA_FROM_DEVICE); | 290 | DMA_FROM_DEVICE); |
290 | descr->buf_addr = 0; | 291 | descr->buf_addr = 0; |
@@ -353,10 +354,11 @@ static void gelic_net_release_tx_descr(struct gelic_net_card *card, | |||
353 | { | 354 | { |
354 | struct sk_buff *skb = descr->skb; | 355 | struct sk_buff *skb = descr->skb; |
355 | 356 | ||
356 | BUG_ON(!(descr->data_status & (1 << GELIC_NET_TXDESC_TAIL))); | 357 | BUG_ON(!(be32_to_cpu(descr->data_status) & |
358 | (1 << GELIC_NET_TXDESC_TAIL))); | ||
357 | 359 | ||
358 | dma_unmap_single(ctodev(card), descr->buf_addr, skb->len, | 360 | dma_unmap_single(ctodev(card), |
359 | DMA_TO_DEVICE); | 361 | be32_to_cpu(descr->buf_addr), skb->len, DMA_TO_DEVICE); |
360 | dev_kfree_skb_any(skb); | 362 | dev_kfree_skb_any(skb); |
361 | 363 | ||
362 | descr->buf_addr = 0; | 364 | descr->buf_addr = 0; |
@@ -610,28 +612,29 @@ static void gelic_net_set_txdescr_cmdstat(struct gelic_net_descr *descr, | |||
610 | struct sk_buff *skb) | 612 | struct sk_buff *skb) |
611 | { | 613 | { |
612 | if (skb->ip_summed != CHECKSUM_PARTIAL) | 614 | if (skb->ip_summed != CHECKSUM_PARTIAL) |
613 | descr->dmac_cmd_status = GELIC_NET_DMAC_CMDSTAT_NOCS | | 615 | descr->dmac_cmd_status = |
614 | GELIC_NET_DMAC_CMDSTAT_END_FRAME; | 616 | cpu_to_be32(GELIC_NET_DMAC_CMDSTAT_NOCS | |
617 | GELIC_NET_DMAC_CMDSTAT_END_FRAME); | ||
615 | else { | 618 | else { |
616 | /* is packet ip? | 619 | /* is packet ip? |
617 | * if yes: tcp? udp? */ | 620 | * if yes: tcp? udp? */ |
618 | if (skb->protocol == htons(ETH_P_IP)) { | 621 | if (skb->protocol == htons(ETH_P_IP)) { |
619 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) | 622 | if (ip_hdr(skb)->protocol == IPPROTO_TCP) |
620 | descr->dmac_cmd_status = | 623 | descr->dmac_cmd_status = |
621 | GELIC_NET_DMAC_CMDSTAT_TCPCS | | 624 | cpu_to_be32(GELIC_NET_DMAC_CMDSTAT_TCPCS | |
622 | GELIC_NET_DMAC_CMDSTAT_END_FRAME; | 625 | GELIC_NET_DMAC_CMDSTAT_END_FRAME); |
623 | 626 | ||
624 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) | 627 | else if (ip_hdr(skb)->protocol == IPPROTO_UDP) |
625 | descr->dmac_cmd_status = | 628 | descr->dmac_cmd_status = |
626 | GELIC_NET_DMAC_CMDSTAT_UDPCS | | 629 | cpu_to_be32(GELIC_NET_DMAC_CMDSTAT_UDPCS | |
627 | GELIC_NET_DMAC_CMDSTAT_END_FRAME; | 630 | GELIC_NET_DMAC_CMDSTAT_END_FRAME); |
628 | else /* | 631 | else /* |
629 | * the stack should checksum non-tcp and non-udp | 632 | * the stack should checksum non-tcp and non-udp |
630 | * packets on his own: NETIF_F_IP_CSUM | 633 | * packets on his own: NETIF_F_IP_CSUM |
631 | */ | 634 | */ |
632 | descr->dmac_cmd_status = | 635 | descr->dmac_cmd_status = |
633 | GELIC_NET_DMAC_CMDSTAT_NOCS | | 636 | cpu_to_be32(GELIC_NET_DMAC_CMDSTAT_NOCS | |
634 | GELIC_NET_DMAC_CMDSTAT_END_FRAME; | 637 | GELIC_NET_DMAC_CMDSTAT_END_FRAME); |
635 | } | 638 | } |
636 | } | 639 | } |
637 | } | 640 | } |
@@ -694,8 +697,8 @@ static int gelic_net_prepare_tx_descr_v(struct gelic_net_card *card, | |||
694 | return -ENOMEM; | 697 | return -ENOMEM; |
695 | } | 698 | } |
696 | 699 | ||
697 | descr->buf_addr = buf; | 700 | descr->buf_addr = cpu_to_be32(buf); |
698 | descr->buf_size = skb->len; | 701 | descr->buf_size = cpu_to_be32(skb->len); |
699 | descr->skb = skb; | 702 | descr->skb = skb; |
700 | descr->data_status = 0; | 703 | descr->data_status = 0; |
701 | descr->next_descr_addr = 0; /* terminate hw descr */ | 704 | descr->next_descr_addr = 0; /* terminate hw descr */ |
@@ -774,7 +777,7 @@ static int gelic_net_xmit(struct sk_buff *skb, struct net_device *netdev) | |||
774 | * link this prepared descriptor to previous one | 777 | * link this prepared descriptor to previous one |
775 | * to achieve high performance | 778 | * to achieve high performance |
776 | */ | 779 | */ |
777 | descr->prev->next_descr_addr = descr->bus_addr; | 780 | descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr); |
778 | /* | 781 | /* |
779 | * as hardware descriptor is modified in the above lines, | 782 | * as hardware descriptor is modified in the above lines, |
780 | * ensure that the hardware sees it | 783 | * ensure that the hardware sees it |
@@ -814,19 +817,23 @@ static void gelic_net_pass_skb_up(struct gelic_net_descr *descr, | |||
814 | struct net_device *netdev; | 817 | struct net_device *netdev; |
815 | u32 data_status, data_error; | 818 | u32 data_status, data_error; |
816 | 819 | ||
817 | data_status = descr->data_status; | 820 | data_status = be32_to_cpu(descr->data_status); |
818 | data_error = descr->data_error; | 821 | data_error = be32_to_cpu(descr->data_error); |
819 | netdev = card->netdev; | 822 | netdev = card->netdev; |
820 | /* unmap skb buffer */ | 823 | /* unmap skb buffer */ |
821 | skb = descr->skb; | 824 | skb = descr->skb; |
822 | dma_unmap_single(ctodev(card), descr->buf_addr, GELIC_NET_MAX_MTU, | 825 | dma_unmap_single(ctodev(card), |
826 | be32_to_cpu(descr->buf_addr), GELIC_NET_MAX_MTU, | ||
823 | DMA_FROM_DEVICE); | 827 | DMA_FROM_DEVICE); |
824 | 828 | ||
825 | skb_put(skb, descr->valid_size? descr->valid_size : descr->result_size); | 829 | skb_put(skb, descr->valid_size ? |
830 | be32_to_cpu(descr->valid_size) : | ||
831 | be32_to_cpu(descr->result_size)); | ||
826 | if (!descr->valid_size) | 832 | if (!descr->valid_size) |
827 | dev_info(ctodev(card), "buffer full %x %x %x\n", | 833 | dev_info(ctodev(card), "buffer full %x %x %x\n", |
828 | descr->result_size, descr->buf_size, | 834 | be32_to_cpu(descr->result_size), |
829 | descr->dmac_cmd_status); | 835 | be32_to_cpu(descr->buf_size), |
836 | be32_to_cpu(descr->dmac_cmd_status)); | ||
830 | 837 | ||
831 | descr->skb = NULL; | 838 | descr->skb = NULL; |
832 | /* | 839 | /* |
@@ -873,7 +880,8 @@ static int gelic_net_decode_one_descr(struct gelic_net_card *card) | |||
873 | status = gelic_net_get_descr_status(descr); | 880 | status = gelic_net_get_descr_status(descr); |
874 | /* is this descriptor terminated with next_descr == NULL? */ | 881 | /* is this descriptor terminated with next_descr == NULL? */ |
875 | dmac_chain_ended = | 882 | dmac_chain_ended = |
876 | descr->dmac_cmd_status & GELIC_NET_DMAC_CMDSTAT_RXDCEIS; | 883 | be32_to_cpu(descr->dmac_cmd_status) & |
884 | GELIC_NET_DMAC_CMDSTAT_RXDCEIS; | ||
877 | 885 | ||
878 | if (status == GELIC_NET_DESCR_CARDOWNED) | 886 | if (status == GELIC_NET_DESCR_CARDOWNED) |
879 | return 0; | 887 | return 0; |
@@ -940,7 +948,7 @@ refill: | |||
940 | /* | 948 | /* |
941 | * Set this descriptor the end of the chain. | 949 | * Set this descriptor the end of the chain. |
942 | */ | 950 | */ |
943 | descr->prev->next_descr_addr = descr->bus_addr; | 951 | descr->prev->next_descr_addr = cpu_to_be32(descr->bus_addr); |
944 | 952 | ||
945 | /* | 953 | /* |
946 | * If dmac chain was met, DMAC stopped. | 954 | * If dmac chain was met, DMAC stopped. |
diff --git a/drivers/net/ps3_gelic_net.h b/drivers/net/ps3_gelic_net.h index 968560269a3b..80b0a3db7479 100644 --- a/drivers/net/ps3_gelic_net.h +++ b/drivers/net/ps3_gelic_net.h | |||
@@ -169,14 +169,14 @@ enum gelic_net_descr_status { | |||
169 | #define GELIC_NET_DESCR_SIZE (32) | 169 | #define GELIC_NET_DESCR_SIZE (32) |
170 | struct gelic_net_descr { | 170 | struct gelic_net_descr { |
171 | /* as defined by the hardware */ | 171 | /* as defined by the hardware */ |
172 | u32 buf_addr; | 172 | __be32 buf_addr; |
173 | u32 buf_size; | 173 | __be32 buf_size; |
174 | u32 next_descr_addr; | 174 | __be32 next_descr_addr; |
175 | u32 dmac_cmd_status; | 175 | __be32 dmac_cmd_status; |
176 | u32 result_size; | 176 | __be32 result_size; |
177 | u32 valid_size; /* all zeroes for tx */ | 177 | __be32 valid_size; /* all zeroes for tx */ |
178 | u32 data_status; | 178 | __be32 data_status; |
179 | u32 data_error; /* all zeroes for tx */ | 179 | __be32 data_error; /* all zeroes for tx */ |
180 | 180 | ||
181 | /* used in the driver */ | 181 | /* used in the driver */ |
182 | struct sk_buff *skb; | 182 | struct sk_buff *skb; |