Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/klassert/ipsec...
[deliverable/linux.git] / drivers / net / ethernet / altera / altera_msgdma.c
CommitLineData
94fb0ef4
VB
1/* Altera TSE SGDMA and MSGDMA Linux driver
2 * Copyright (C) 2014 Altera Corporation. All rights reserved
3 *
4 * This program is free software; you can redistribute it and/or modify it
5 * under the terms and conditions of the GNU General Public License,
6 * version 2, as published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope it will be useful, but WITHOUT
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
11 * more details.
12 *
13 * You should have received a copy of the GNU General Public License along with
14 * this program. If not, see <http://www.gnu.org/licenses/>.
15 */
16
17#include <linux/netdevice.h>
18#include "altera_utils.h"
19#include "altera_tse.h"
20#include "altera_msgdmahw.h"
652f99ea 21#include "altera_msgdma.h"
94fb0ef4
VB
22
23/* No initialization work to do for MSGDMA */
24int msgdma_initialize(struct altera_tse_private *priv)
25{
26 return 0;
27}
28
29void msgdma_uninitialize(struct altera_tse_private *priv)
30{
31}
32
37c0ffaa
VB
33void msgdma_start_rxdma(struct altera_tse_private *priv)
34{
35}
36
94fb0ef4
VB
37void msgdma_reset(struct altera_tse_private *priv)
38{
39 int counter;
d42f157b
TK
40 struct msgdma_csr *txcsr = priv->tx_dma_csr;
41 struct msgdma_csr *rxcsr = priv->rx_dma_csr;
94fb0ef4
VB
42
43 /* Reset Rx mSGDMA */
44 iowrite32(MSGDMA_CSR_STAT_MASK, &rxcsr->status);
45 iowrite32(MSGDMA_CSR_CTL_RESET, &rxcsr->control);
46
47 counter = 0;
48 while (counter++ < ALTERA_TSE_SW_RESET_WATCHDOG_CNTR) {
49 if (tse_bit_is_clear(&rxcsr->status,
50 MSGDMA_CSR_STAT_RESETTING))
51 break;
52 udelay(1);
53 }
54
55 if (counter >= ALTERA_TSE_SW_RESET_WATCHDOG_CNTR)
56 netif_warn(priv, drv, priv->dev,
57 "TSE Rx mSGDMA resetting bit never cleared!\n");
58
59 /* clear all status bits */
60 iowrite32(MSGDMA_CSR_STAT_MASK, &rxcsr->status);
61
62 /* Reset Tx mSGDMA */
63 iowrite32(MSGDMA_CSR_STAT_MASK, &txcsr->status);
64 iowrite32(MSGDMA_CSR_CTL_RESET, &txcsr->control);
65
66 counter = 0;
67 while (counter++ < ALTERA_TSE_SW_RESET_WATCHDOG_CNTR) {
68 if (tse_bit_is_clear(&txcsr->status,
69 MSGDMA_CSR_STAT_RESETTING))
70 break;
71 udelay(1);
72 }
73
74 if (counter >= ALTERA_TSE_SW_RESET_WATCHDOG_CNTR)
75 netif_warn(priv, drv, priv->dev,
76 "TSE Tx mSGDMA resetting bit never cleared!\n");
77
78 /* clear all status bits */
79 iowrite32(MSGDMA_CSR_STAT_MASK, &txcsr->status);
80}
81
82void msgdma_disable_rxirq(struct altera_tse_private *priv)
83{
84 struct msgdma_csr *csr = priv->rx_dma_csr;
85 tse_clear_bit(&csr->control, MSGDMA_CSR_CTL_GLOBAL_INTR);
86}
87
88void msgdma_enable_rxirq(struct altera_tse_private *priv)
89{
90 struct msgdma_csr *csr = priv->rx_dma_csr;
91 tse_set_bit(&csr->control, MSGDMA_CSR_CTL_GLOBAL_INTR);
92}
93
94void msgdma_disable_txirq(struct altera_tse_private *priv)
95{
96 struct msgdma_csr *csr = priv->tx_dma_csr;
97 tse_clear_bit(&csr->control, MSGDMA_CSR_CTL_GLOBAL_INTR);
98}
99
100void msgdma_enable_txirq(struct altera_tse_private *priv)
101{
102 struct msgdma_csr *csr = priv->tx_dma_csr;
103 tse_set_bit(&csr->control, MSGDMA_CSR_CTL_GLOBAL_INTR);
104}
105
106void msgdma_clear_rxirq(struct altera_tse_private *priv)
107{
108 struct msgdma_csr *csr = priv->rx_dma_csr;
109 iowrite32(MSGDMA_CSR_STAT_IRQ, &csr->status);
110}
111
112void msgdma_clear_txirq(struct altera_tse_private *priv)
113{
114 struct msgdma_csr *csr = priv->tx_dma_csr;
115 iowrite32(MSGDMA_CSR_STAT_IRQ, &csr->status);
116}
117
118/* return 0 to indicate transmit is pending */
119int msgdma_tx_buffer(struct altera_tse_private *priv, struct tse_buffer *buffer)
120{
121 struct msgdma_extended_desc *desc = priv->tx_dma_desc;
122
123 iowrite32(lower_32_bits(buffer->dma_addr), &desc->read_addr_lo);
124 iowrite32(upper_32_bits(buffer->dma_addr), &desc->read_addr_hi);
125 iowrite32(0, &desc->write_addr_lo);
126 iowrite32(0, &desc->write_addr_hi);
127 iowrite32(buffer->len, &desc->len);
128 iowrite32(0, &desc->burst_seq_num);
129 iowrite32(MSGDMA_DESC_TX_STRIDE, &desc->stride);
130 iowrite32(MSGDMA_DESC_CTL_TX_SINGLE, &desc->control);
131 return 0;
132}
133
134u32 msgdma_tx_completions(struct altera_tse_private *priv)
135{
136 u32 ready = 0;
137 u32 inuse;
138 u32 status;
d42f157b 139 struct msgdma_csr *txcsr = priv->tx_dma_csr;
94fb0ef4
VB
140
141 /* Get number of sent descriptors */
142 inuse = ioread32(&txcsr->rw_fill_level) & 0xffff;
143
144 if (inuse) { /* Tx FIFO is not empty */
145 ready = priv->tx_prod - priv->tx_cons - inuse - 1;
146 } else {
147 /* Check for buffered last packet */
148 status = ioread32(&txcsr->status);
149 if (status & MSGDMA_CSR_STAT_BUSY)
150 ready = priv->tx_prod - priv->tx_cons - 1;
151 else
152 ready = priv->tx_prod - priv->tx_cons;
153 }
154 return ready;
155}
156
157/* Put buffer to the mSGDMA RX FIFO
158 */
37c0ffaa 159void msgdma_add_rx_desc(struct altera_tse_private *priv,
94fb0ef4
VB
160 struct tse_buffer *rxbuffer)
161{
162 struct msgdma_extended_desc *desc = priv->rx_dma_desc;
163 u32 len = priv->rx_dma_buf_sz;
164 dma_addr_t dma_addr = rxbuffer->dma_addr;
165 u32 control = (MSGDMA_DESC_CTL_END_ON_EOP
166 | MSGDMA_DESC_CTL_END_ON_LEN
167 | MSGDMA_DESC_CTL_TR_COMP_IRQ
168 | MSGDMA_DESC_CTL_EARLY_IRQ
169 | MSGDMA_DESC_CTL_TR_ERR_IRQ
170 | MSGDMA_DESC_CTL_GO);
171
172 iowrite32(0, &desc->read_addr_lo);
173 iowrite32(0, &desc->read_addr_hi);
174 iowrite32(lower_32_bits(dma_addr), &desc->write_addr_lo);
175 iowrite32(upper_32_bits(dma_addr), &desc->write_addr_hi);
176 iowrite32(len, &desc->len);
177 iowrite32(0, &desc->burst_seq_num);
178 iowrite32(0x00010001, &desc->stride);
179 iowrite32(control, &desc->control);
94fb0ef4
VB
180}
181
182/* status is returned on upper 16 bits,
183 * length is returned in lower 16 bits
184 */
185u32 msgdma_rx_status(struct altera_tse_private *priv)
186{
187 u32 rxstatus = 0;
188 u32 pktlength;
189 u32 pktstatus;
d42f157b
TK
190 struct msgdma_csr *rxcsr = priv->rx_dma_csr;
191 struct msgdma_response *rxresp = priv->rx_dma_resp;
94fb0ef4
VB
192
193 if (ioread32(&rxcsr->resp_fill_level) & 0xffff) {
194 pktlength = ioread32(&rxresp->bytes_transferred);
195 pktstatus = ioread32(&rxresp->status);
196 rxstatus = pktstatus;
197 rxstatus = rxstatus << 16;
198 rxstatus |= (pktlength & 0xffff);
199 }
200 return rxstatus;
201}
This page took 0.085546 seconds and 5 git commands to generate.