1 /*
2  * Applied Micro X-Gene SoC Ethernet v2 Driver
3  *
4  * Copyright (c) 2017, Applied Micro Circuits Corporation
5  * Author(s): Iyappan Subramanian <isubramanian@apm.com>
6  *	      Keyur Chudgar <kchudgar@apm.com>
7  *
8  * This program is free software; you can redistribute  it and/or modify it
9  * under  the terms of  the GNU General  Public License as published by the
10  * Free Software Foundation;  either version 2 of the  License, or (at your
11  * option) any later version.
12  *
13  * This program is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16  * GNU General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
20  */
21 
22 #include "main.h"
23 
24 /* create circular linked list of descriptors */
25 void xge_setup_desc(struct xge_desc_ring *ring)
26 {
27 	struct xge_raw_desc *raw_desc;
28 	dma_addr_t dma_h, next_dma;
29 	u16 offset;
30 	int i;
31 
32 	for (i = 0; i < XGENE_ENET_NUM_DESC; i++) {
33 		raw_desc = &ring->raw_desc[i];
34 
35 		offset = (i + 1) & (XGENE_ENET_NUM_DESC - 1);
36 		next_dma = ring->dma_addr + (offset * XGENE_ENET_DESC_SIZE);
37 
38 		raw_desc->m0 = cpu_to_le64(SET_BITS(E, 1) |
39 					   SET_BITS(PKT_SIZE, SLOT_EMPTY));
40 		dma_h = upper_32_bits(next_dma);
41 		raw_desc->m1 = cpu_to_le64(SET_BITS(NEXT_DESC_ADDRL, next_dma) |
42 					   SET_BITS(NEXT_DESC_ADDRH, dma_h));
43 	}
44 }
45 
46 void xge_update_tx_desc_addr(struct xge_pdata *pdata)
47 {
48 	struct xge_desc_ring *ring = pdata->tx_ring;
49 	dma_addr_t dma_addr = ring->dma_addr;
50 
51 	xge_wr_csr(pdata, DMATXDESCL, dma_addr);
52 	xge_wr_csr(pdata, DMATXDESCH, upper_32_bits(dma_addr));
53 
54 	ring->head = 0;
55 	ring->tail = 0;
56 }
57 
58 void xge_update_rx_desc_addr(struct xge_pdata *pdata)
59 {
60 	struct xge_desc_ring *ring = pdata->rx_ring;
61 	dma_addr_t dma_addr = ring->dma_addr;
62 
63 	xge_wr_csr(pdata, DMARXDESCL, dma_addr);
64 	xge_wr_csr(pdata, DMARXDESCH, upper_32_bits(dma_addr));
65 
66 	ring->head = 0;
67 	ring->tail = 0;
68 }
69 
70 void xge_intr_enable(struct xge_pdata *pdata)
71 {
72 	u32 data;
73 
74 	data = RX_PKT_RCVD | TX_PKT_SENT;
75 	xge_wr_csr(pdata, DMAINTRMASK, data);
76 }
77 
78 void xge_intr_disable(struct xge_pdata *pdata)
79 {
80 	xge_wr_csr(pdata, DMAINTRMASK, 0);
81 }
82