diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-01-08 07:53:22 -0500 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2012-02-09 10:37:53 -0500 |
commit | 885767ca4ce0800c5d02eb66cc10a0494b7bf312 (patch) | |
tree | 011b654d7f0e7d5d627e9280a20e365f41cfcfc7 /drivers/net/irda | |
parent | e556fdbde38f68d87f689473b112cc65ddacd6a4 (diff) |
NET: sa11x0-ir: containerize DMA data
Both the transmit and receive DMA store identical data: the skb, dma
address, and the dma registers. Move this data into its own data
structure. The following replacements were used:
rxskb -> dma_rx.skb
rxbuf_dma -> dma_rx.dma
rxdma -> dma_rx.regs
txskb -> dma_tx.skb
txbuf_dma -> dma_tx.dma
txdma -> dma_tx.regs
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'drivers/net/irda')
-rw-r--r-- | drivers/net/irda/sa1100_ir.c | 94 |
1 files changed, 48 insertions, 46 deletions
diff --git a/drivers/net/irda/sa1100_ir.c b/drivers/net/irda/sa1100_ir.c index 2f5bf0bc8458..adb7fea78c2d 100644 --- a/drivers/net/irda/sa1100_ir.c +++ b/drivers/net/irda/sa1100_ir.c | |||
@@ -43,6 +43,12 @@ static int power_level = 3; | |||
43 | static int tx_lpm; | 43 | static int tx_lpm; |
44 | static int max_rate = 4000000; | 44 | static int max_rate = 4000000; |
45 | 45 | ||
46 | struct sa1100_buf { | ||
47 | struct sk_buff *skb; | ||
48 | dma_addr_t dma; | ||
49 | dma_regs_t *regs; | ||
50 | }; | ||
51 | |||
46 | struct sa1100_irda { | 52 | struct sa1100_irda { |
47 | unsigned char hscr0; | 53 | unsigned char hscr0; |
48 | unsigned char utcr4; | 54 | unsigned char utcr4; |
@@ -52,12 +58,8 @@ struct sa1100_irda { | |||
52 | int speed; | 58 | int speed; |
53 | int newspeed; | 59 | int newspeed; |
54 | 60 | ||
55 | struct sk_buff *txskb; | 61 | struct sa1100_buf dma_rx; |
56 | struct sk_buff *rxskb; | 62 | struct sa1100_buf dma_tx; |
57 | dma_addr_t txbuf_dma; | ||
58 | dma_addr_t rxbuf_dma; | ||
59 | dma_regs_t *txdma; | ||
60 | dma_regs_t *rxdma; | ||
61 | 63 | ||
62 | struct device *dev; | 64 | struct device *dev; |
63 | struct irda_platform_data *pdata; | 65 | struct irda_platform_data *pdata; |
@@ -77,11 +79,11 @@ struct sa1100_irda { | |||
77 | */ | 79 | */ |
78 | static int sa1100_irda_rx_alloc(struct sa1100_irda *si) | 80 | static int sa1100_irda_rx_alloc(struct sa1100_irda *si) |
79 | { | 81 | { |
80 | if (si->rxskb) | 82 | if (si->dma_rx.skb) |
81 | return 0; | 83 | return 0; |
82 | 84 | ||
83 | si->rxskb = alloc_skb(HPSIR_MAX_RXLEN + 1, GFP_ATOMIC); | 85 | si->dma_rx.skb = alloc_skb(HPSIR_MAX_RXLEN + 1, GFP_ATOMIC); |
84 | if (!si->rxskb) { | 86 | if (!si->dma_rx.skb) { |
85 | printk(KERN_ERR "sa1100_ir: out of memory for RX SKB\n"); | 87 | printk(KERN_ERR "sa1100_ir: out of memory for RX SKB\n"); |
86 | return -ENOMEM; | 88 | return -ENOMEM; |
87 | } | 89 | } |
@@ -90,13 +92,13 @@ static int sa1100_irda_rx_alloc(struct sa1100_irda *si) | |||
90 | * Align any IP headers that may be contained | 92 | * Align any IP headers that may be contained |
91 | * within the frame. | 93 | * within the frame. |
92 | */ | 94 | */ |
93 | skb_reserve(si->rxskb, 1); | 95 | skb_reserve(si->dma_rx.skb, 1); |
94 | 96 | ||
95 | si->rxbuf_dma = dma_map_single(si->dev, si->rxskb->data, | 97 | si->dma_rx.dma = dma_map_single(si->dev, si->dma_rx.skb->data, |
96 | HPSIR_MAX_RXLEN, | 98 | HPSIR_MAX_RXLEN, |
97 | DMA_FROM_DEVICE); | 99 | DMA_FROM_DEVICE); |
98 | if (dma_mapping_error(si->dev, si->rxbuf_dma)) { | 100 | if (dma_mapping_error(si->dev, si->dma_rx.dma)) { |
99 | dev_kfree_skb_any(si->rxskb); | 101 | dev_kfree_skb_any(si->dma_rx.skb); |
100 | return -ENOMEM; | 102 | return -ENOMEM; |
101 | } | 103 | } |
102 | 104 | ||
@@ -109,7 +111,7 @@ static int sa1100_irda_rx_alloc(struct sa1100_irda *si) | |||
109 | */ | 111 | */ |
110 | static void sa1100_irda_rx_dma_start(struct sa1100_irda *si) | 112 | static void sa1100_irda_rx_dma_start(struct sa1100_irda *si) |
111 | { | 113 | { |
112 | if (!si->rxskb) { | 114 | if (!si->dma_rx.skb) { |
113 | printk(KERN_ERR "sa1100_ir: rx buffer went missing\n"); | 115 | printk(KERN_ERR "sa1100_ir: rx buffer went missing\n"); |
114 | return; | 116 | return; |
115 | } | 117 | } |
@@ -122,8 +124,8 @@ static void sa1100_irda_rx_dma_start(struct sa1100_irda *si) | |||
122 | /* | 124 | /* |
123 | * Enable the DMA, receiver and receive interrupt. | 125 | * Enable the DMA, receiver and receive interrupt. |
124 | */ | 126 | */ |
125 | sa1100_clear_dma(si->rxdma); | 127 | sa1100_clear_dma(si->dma_rx.regs); |
126 | sa1100_start_dma(si->rxdma, si->rxbuf_dma, HPSIR_MAX_RXLEN); | 128 | sa1100_start_dma(si->dma_rx.regs, si->dma_rx.dma, HPSIR_MAX_RXLEN); |
127 | Ser2HSCR0 = si->hscr0 | HSCR0_HSSP | HSCR0_RXE; | 129 | Ser2HSCR0 = si->hscr0 | HSCR0_HSSP | HSCR0_RXE; |
128 | } | 130 | } |
129 | 131 | ||
@@ -144,7 +146,7 @@ static int sa1100_irda_set_speed(struct sa1100_irda *si, int speed) | |||
144 | * Stop the receive DMA. | 146 | * Stop the receive DMA. |
145 | */ | 147 | */ |
146 | if (IS_FIR(si)) | 148 | if (IS_FIR(si)) |
147 | sa1100_stop_dma(si->rxdma); | 149 | sa1100_stop_dma(si->dma_rx.regs); |
148 | 150 | ||
149 | local_irq_save(flags); | 151 | local_irq_save(flags); |
150 | 152 | ||
@@ -280,8 +282,8 @@ static void sa1100_irda_shutdown(struct sa1100_irda *si) | |||
280 | /* | 282 | /* |
281 | * Stop all DMA activity. | 283 | * Stop all DMA activity. |
282 | */ | 284 | */ |
283 | sa1100_stop_dma(si->rxdma); | 285 | sa1100_stop_dma(si->dma_rx.regs); |
284 | sa1100_stop_dma(si->txdma); | 286 | sa1100_stop_dma(si->dma_tx.regs); |
285 | 287 | ||
286 | /* Disable the port. */ | 288 | /* Disable the port. */ |
287 | Ser2UTCR3 = 0; | 289 | Ser2UTCR3 = 0; |
@@ -460,7 +462,7 @@ static void sa1100_irda_hpsir_irq(struct net_device *dev) | |||
460 | 462 | ||
461 | static void sa1100_irda_fir_error(struct sa1100_irda *si, struct net_device *dev) | 463 | static void sa1100_irda_fir_error(struct sa1100_irda *si, struct net_device *dev) |
462 | { | 464 | { |
463 | struct sk_buff *skb = si->rxskb; | 465 | struct sk_buff *skb = si->dma_rx.skb; |
464 | dma_addr_t dma_addr; | 466 | dma_addr_t dma_addr; |
465 | unsigned int len, stat, data; | 467 | unsigned int len, stat, data; |
466 | 468 | ||
@@ -472,11 +474,11 @@ static void sa1100_irda_fir_error(struct sa1100_irda *si, struct net_device *dev | |||
472 | /* | 474 | /* |
473 | * Get the current data position. | 475 | * Get the current data position. |
474 | */ | 476 | */ |
475 | dma_addr = sa1100_get_dma_pos(si->rxdma); | 477 | dma_addr = sa1100_get_dma_pos(si->dma_rx.regs); |
476 | len = dma_addr - si->rxbuf_dma; | 478 | len = dma_addr - si->dma_rx.dma; |
477 | if (len > HPSIR_MAX_RXLEN) | 479 | if (len > HPSIR_MAX_RXLEN) |
478 | len = HPSIR_MAX_RXLEN; | 480 | len = HPSIR_MAX_RXLEN; |
479 | dma_unmap_single(si->dev, si->rxbuf_dma, len, DMA_FROM_DEVICE); | 481 | dma_unmap_single(si->dev, si->dma_rx.dma, len, DMA_FROM_DEVICE); |
480 | 482 | ||
481 | do { | 483 | do { |
482 | /* | 484 | /* |
@@ -504,7 +506,7 @@ static void sa1100_irda_fir_error(struct sa1100_irda *si, struct net_device *dev | |||
504 | } while (Ser2HSSR0 & HSSR0_EIF); | 506 | } while (Ser2HSSR0 & HSSR0_EIF); |
505 | 507 | ||
506 | if (stat & HSSR1_EOF) { | 508 | if (stat & HSSR1_EOF) { |
507 | si->rxskb = NULL; | 509 | si->dma_rx.skb = NULL; |
508 | 510 | ||
509 | skb_put(skb, len); | 511 | skb_put(skb, len); |
510 | skb->dev = dev; | 512 | skb->dev = dev; |
@@ -524,7 +526,7 @@ static void sa1100_irda_fir_error(struct sa1100_irda *si, struct net_device *dev | |||
524 | * Remap the buffer - it was previously mapped, and we | 526 | * Remap the buffer - it was previously mapped, and we |
525 | * hope that this succeeds. | 527 | * hope that this succeeds. |
526 | */ | 528 | */ |
527 | si->rxbuf_dma = dma_map_single(si->dev, si->rxskb->data, | 529 | si->dma_rx.dma = dma_map_single(si->dev, si->dma_rx.skb->data, |
528 | HPSIR_MAX_RXLEN, | 530 | HPSIR_MAX_RXLEN, |
529 | DMA_FROM_DEVICE); | 531 | DMA_FROM_DEVICE); |
530 | } | 532 | } |
@@ -543,7 +545,7 @@ static void sa1100_irda_fir_irq(struct net_device *dev) | |||
543 | /* | 545 | /* |
544 | * Stop RX DMA | 546 | * Stop RX DMA |
545 | */ | 547 | */ |
546 | sa1100_stop_dma(si->rxdma); | 548 | sa1100_stop_dma(si->dma_rx.regs); |
547 | 549 | ||
548 | /* | 550 | /* |
549 | * Framing error - we throw away the packet completely. | 551 | * Framing error - we throw away the packet completely. |
@@ -600,9 +602,9 @@ static void sa1100_irda_txdma_irq(void *id) | |||
600 | { | 602 | { |
601 | struct net_device *dev = id; | 603 | struct net_device *dev = id; |
602 | struct sa1100_irda *si = netdev_priv(dev); | 604 | struct sa1100_irda *si = netdev_priv(dev); |
603 | struct sk_buff *skb = si->txskb; | 605 | struct sk_buff *skb = si->dma_tx.skb; |
604 | 606 | ||
605 | si->txskb = NULL; | 607 | si->dma_tx.skb = NULL; |
606 | 608 | ||
607 | /* | 609 | /* |
608 | * Wait for the transmission to complete. Unfortunately, | 610 | * Wait for the transmission to complete. Unfortunately, |
@@ -620,7 +622,7 @@ static void sa1100_irda_txdma_irq(void *id) | |||
620 | 622 | ||
621 | /* | 623 | /* |
622 | * Do we need to change speed? Note that we're lazy | 624 | * Do we need to change speed? Note that we're lazy |
623 | * here - we don't free the old rxskb. We don't need | 625 | * here - we don't free the old dma_rx.skb. We don't need |
624 | * to allocate a buffer either. | 626 | * to allocate a buffer either. |
625 | */ | 627 | */ |
626 | if (si->newspeed) { | 628 | if (si->newspeed) { |
@@ -638,7 +640,7 @@ static void sa1100_irda_txdma_irq(void *id) | |||
638 | * Account and free the packet. | 640 | * Account and free the packet. |
639 | */ | 641 | */ |
640 | if (skb) { | 642 | if (skb) { |
641 | dma_unmap_single(si->dev, si->txbuf_dma, skb->len, DMA_TO_DEVICE); | 643 | dma_unmap_single(si->dev, si->dma_tx.dma, skb->len, DMA_TO_DEVICE); |
642 | dev->stats.tx_packets ++; | 644 | dev->stats.tx_packets ++; |
643 | dev->stats.tx_bytes += skb->len; | 645 | dev->stats.tx_bytes += skb->len; |
644 | dev_kfree_skb_irq(skb); | 646 | dev_kfree_skb_irq(skb); |
@@ -698,22 +700,22 @@ static int sa1100_irda_hard_xmit(struct sk_buff *skb, struct net_device *dev) | |||
698 | /* | 700 | /* |
699 | * We must not be transmitting... | 701 | * We must not be transmitting... |
700 | */ | 702 | */ |
701 | BUG_ON(si->txskb); | 703 | BUG_ON(si->dma_tx.skb); |
702 | 704 | ||
703 | netif_stop_queue(dev); | 705 | netif_stop_queue(dev); |
704 | 706 | ||
705 | si->txskb = skb; | 707 | si->dma_tx.skb = skb; |
706 | si->txbuf_dma = dma_map_single(si->dev, skb->data, | 708 | si->dma_tx.dma = dma_map_single(si->dev, skb->data, |
707 | skb->len, DMA_TO_DEVICE); | 709 | skb->len, DMA_TO_DEVICE); |
708 | if (dma_mapping_error(si->dev, si->txbuf_dma)) { | 710 | if (dma_mapping_error(si->dev, si->dma_tx.dma)) { |
709 | si->txskb = NULL; | 711 | si->dma_tx.skb = NULL; |
710 | netif_wake_queue(dev); | 712 | netif_wake_queue(dev); |
711 | dev->stats.tx_dropped++; | 713 | dev->stats.tx_dropped++; |
712 | dev_kfree_skb(skb); | 714 | dev_kfree_skb(skb); |
713 | return NETDEV_TX_OK; | 715 | return NETDEV_TX_OK; |
714 | } | 716 | } |
715 | 717 | ||
716 | sa1100_start_dma(si->txdma, si->txbuf_dma, skb->len); | 718 | sa1100_start_dma(si->dma_tx.regs, si->dma_tx.dma, skb->len); |
717 | 719 | ||
718 | /* | 720 | /* |
719 | * If we have a mean turn-around time, impose the specified | 721 | * If we have a mean turn-around time, impose the specified |
@@ -785,12 +787,12 @@ static int sa1100_irda_start(struct net_device *dev) | |||
785 | goto err_irq; | 787 | goto err_irq; |
786 | 788 | ||
787 | err = sa1100_request_dma(DMA_Ser2HSSPRd, "IrDA receive", | 789 | err = sa1100_request_dma(DMA_Ser2HSSPRd, "IrDA receive", |
788 | NULL, NULL, &si->rxdma); | 790 | NULL, NULL, &si->dma_rx.regs); |
789 | if (err) | 791 | if (err) |
790 | goto err_rx_dma; | 792 | goto err_rx_dma; |
791 | 793 | ||
792 | err = sa1100_request_dma(DMA_Ser2HSSPWr, "IrDA transmit", | 794 | err = sa1100_request_dma(DMA_Ser2HSSPWr, "IrDA transmit", |
793 | sa1100_irda_txdma_irq, dev, &si->txdma); | 795 | sa1100_irda_txdma_irq, dev, &si->dma_tx.regs); |
794 | if (err) | 796 | if (err) |
795 | goto err_tx_dma; | 797 | goto err_tx_dma; |
796 | 798 | ||
@@ -827,9 +829,9 @@ err_irlap: | |||
827 | si->open = 0; | 829 | si->open = 0; |
828 | sa1100_irda_shutdown(si); | 830 | sa1100_irda_shutdown(si); |
829 | err_startup: | 831 | err_startup: |
830 | sa1100_free_dma(si->txdma); | 832 | sa1100_free_dma(si->dma_tx.regs); |
831 | err_tx_dma: | 833 | err_tx_dma: |
832 | sa1100_free_dma(si->rxdma); | 834 | sa1100_free_dma(si->dma_rx.regs); |
833 | err_rx_dma: | 835 | err_rx_dma: |
834 | free_irq(dev->irq, dev); | 836 | free_irq(dev->irq, dev); |
835 | err_irq: | 837 | err_irq: |
@@ -847,11 +849,11 @@ static int sa1100_irda_stop(struct net_device *dev) | |||
847 | * If we have been doing DMA receive, make sure we | 849 | * If we have been doing DMA receive, make sure we |
848 | * tidy that up cleanly. | 850 | * tidy that up cleanly. |
849 | */ | 851 | */ |
850 | if (si->rxskb) { | 852 | if (si->dma_rx.skb) { |
851 | dma_unmap_single(si->dev, si->rxbuf_dma, HPSIR_MAX_RXLEN, | 853 | dma_unmap_single(si->dev, si->dma_rx.dma, HPSIR_MAX_RXLEN, |
852 | DMA_FROM_DEVICE); | 854 | DMA_FROM_DEVICE); |
853 | dev_kfree_skb(si->rxskb); | 855 | dev_kfree_skb(si->dma_rx.skb); |
854 | si->rxskb = NULL; | 856 | si->dma_rx.skb = NULL; |
855 | } | 857 | } |
856 | 858 | ||
857 | /* Stop IrLAP */ | 859 | /* Stop IrLAP */ |
@@ -866,8 +868,8 @@ static int sa1100_irda_stop(struct net_device *dev) | |||
866 | /* | 868 | /* |
867 | * Free resources | 869 | * Free resources |
868 | */ | 870 | */ |
869 | sa1100_free_dma(si->txdma); | 871 | sa1100_free_dma(si->dma_tx.regs); |
870 | sa1100_free_dma(si->rxdma); | 872 | sa1100_free_dma(si->dma_rx.regs); |
871 | free_irq(dev->irq, dev); | 873 | free_irq(dev->irq, dev); |
872 | 874 | ||
873 | sa1100_set_power(si, 0); | 875 | sa1100_set_power(si, 0); |