octeon_fpavar.h revision 1.4 1 /* $NetBSD: octeon_fpavar.h,v 1.4 2020/05/31 06:27:06 simonb Exp $ */
2
3 /*
4 * Copyright (c) 2007 Internet Initiative Japan, Inc.
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28
29 #ifndef _OCTEON_FPAVAR_H_
30 #define _OCTEON_FPAVAR_H_
31
32 struct octfpa_buf {
33 int fb_poolno; /* pool # */
34
35 size_t fb_size; /* element size */
36 size_t fb_nelems; /* # of elements */
37
38 paddr_t fb_paddr; /* physical address */
39 vaddr_t fb_addr; /* virtual address */
40 size_t fb_len; /* total length */
41
42 bus_dma_tag_t fb_dmat;
43 bus_dmamap_t fb_dmah;
44 bus_dma_segment_t
45 *fb_dma_segs;
46 int fb_dma_nsegs;
47 };
48
49 uint64_t octfpa_int_summary(void);
50 int octfpa_buf_init(int, size_t, size_t, struct octfpa_buf **);
51 void *octfpa_buf_get(struct octfpa_buf *);
52 uint64_t octfpa_query(int);
53 int octfpa_available_fpa_pool(int *available, int pool_no);
54
55 #ifdef CNMAC_DEBUG
56 void octfpa_dump(void);
57 #endif
58
59 #define OCTEON_CACHE_LINE_SIZE (128)
60
61 /* Pool sizes in bytes, must be multiple of a cache line */
62 #define FPA_POOL_0_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
63 #define FPA_POOL_1_SIZE (1 * OCTEON_CACHE_LINE_SIZE)
64 #define FPA_POOL_2_SIZE (8 * OCTEON_CACHE_LINE_SIZE)
65 #define FPA_POOL_3_SIZE (4 * OCTEON_CACHE_LINE_SIZE)
66
67 #define FPA_POOL_4_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
68 #define FPA_POOL_5_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
69 #define FPA_POOL_6_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
70 #define FPA_POOL_7_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
71
72 /* Pools in use */
73 #define FPA_RECV_PKT_POOL (0) /* Receive Packet buffers */
74 #define FPA_RECV_PKT_POOL_SIZE FPA_POOL_0_SIZE
75 #define FPA_RECV_PKT_POOL_LINE 16
76 #define FPA_WQE_POOL (1) /* Work queue entrys */
77 #define FPA_WQE_POOL_SIZE FPA_POOL_1_SIZE
78 #define FPA_WQE_POOL_LINE 1
79 #define FPA_COMMAND_BUFFER_POOL (2) /* PKO queue command buffers */
80 #define FPA_COMMAND_BUFFER_POOL_SIZE FPA_POOL_2_SIZE
81 #define FPA_COMMAND_BUFFER_POOL_LINE 8
82 #define FPA_GATHER_BUFFER_POOL (3) /* PKO gather list buffers */
83 #define FPA_GATHER_BUFFER_POOL_SIZE FPA_POOL_3_SIZE
84 #define FPA_GATHER_BUFFER_POOL_LINE 4
85
86 #ifndef FPA_OUTPUT_BUFFER_POOL
87 #define FPA_OUTPUT_BUFFER_POOL FPA_COMMAND_BUFFER_POOL
88 #define FPA_OUTPUT_BUFFER_POOL_SIZE FPA_COMMAND_BUFFER_POOL_SIZE
89 #endif
90
91 /*
92 * operations
93 */
94
95 static __inline uint64_t
96 octfpa_load(uint64_t fpapool)
97 {
98 uint64_t addr;
99
100 addr =
101 (0x1ULL << 48) |
102 (0x5ULL << 43) |
103 (fpapool & 0x07ULL) << 40;
104
105 return octeon_read_csr(addr);
106 }
107
108 #ifdef notyet
109 static __inline uint64_t
110 octfpa_iobdma(struct octfpa_softc *sc, int srcaddr, int len)
111 {
112 /* XXX */
113 return 0ULL;
114 }
115 #endif
116
117 static __inline void
118 octfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount)
119 {
120 uint64_t ptr;
121
122 ptr =
123 (0x1ULL << 48) |
124 (0x5ULL << 43) |
125 (fpapool & 0x07ULL) << 40 |
126 (addr & 0xffffffffffULL);
127
128 OCTEON_SYNCWS;
129 octeon_write_csr(ptr, (dwbcount & 0x0ffULL));
130 }
131
132 static __inline paddr_t
133 octfpa_buf_get_paddr(struct octfpa_buf *fb)
134 {
135 return octfpa_load(fb->fb_poolno);
136 }
137
138 static __inline void
139 octfpa_buf_put_paddr(struct octfpa_buf *fb, paddr_t paddr)
140 {
141 KASSERT(paddr >= fb->fb_paddr);
142 KASSERT(paddr < fb->fb_paddr + fb->fb_len);
143 octfpa_store(paddr, fb->fb_poolno, fb->fb_size / 128);
144 }
145
146 static __inline void
147 octfpa_buf_put(struct octfpa_buf *fb, void *addr)
148 {
149 paddr_t paddr;
150
151 KASSERT((vaddr_t)addr >= fb->fb_addr);
152 KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len);
153 paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr);
154 octfpa_buf_put_paddr(fb, paddr);
155 }
156
157 #endif
158