octeon_fpavar.h revision 1.6 1 /* $NetBSD: octeon_fpavar.h,v 1.6 2020/06/22 02:26:20 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 #include <mips/cavium/octeonreg.h>
33
34 struct octfpa_buf {
35 int fb_poolno; /* pool # */
36
37 size_t fb_size; /* element size */
38 size_t fb_nelems; /* # of elements */
39
40 paddr_t fb_paddr; /* physical address */
41 vaddr_t fb_addr; /* virtual address */
42 size_t fb_len; /* total length */
43
44 bus_dma_tag_t fb_dmat;
45 bus_dmamap_t fb_dmah;
46 bus_dma_segment_t
47 *fb_dma_segs;
48 int fb_dma_nsegs;
49 };
50
51 uint64_t octfpa_int_summary(void);
52 int octfpa_buf_init(int, size_t, size_t, struct octfpa_buf **);
53 void *octfpa_buf_get(struct octfpa_buf *);
54 uint64_t octfpa_query(int);
55 int octfpa_available_fpa_pool(int *available, int pool_no);
56
57 #define OCTEON_CACHE_LINE_SIZE (128)
58
59 /* Pool sizes in bytes, must be multiple of a cache line */
60 #define FPA_POOL_0_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
61 #define FPA_POOL_1_SIZE (1 * OCTEON_CACHE_LINE_SIZE)
62 #define FPA_POOL_2_SIZE (8 * OCTEON_CACHE_LINE_SIZE)
63 #define FPA_POOL_3_SIZE (4 * OCTEON_CACHE_LINE_SIZE)
64
65 #define FPA_POOL_4_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
66 #define FPA_POOL_5_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
67 #define FPA_POOL_6_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
68 #define FPA_POOL_7_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
69
70 /* Pools in use */
71 #define FPA_RECV_PKT_POOL (0) /* Receive Packet buffers */
72 #define FPA_RECV_PKT_POOL_SIZE FPA_POOL_0_SIZE
73 #define FPA_RECV_PKT_POOL_LINE 16
74 #define FPA_WQE_POOL (1) /* Work queue entrys */
75 #define FPA_WQE_POOL_SIZE FPA_POOL_1_SIZE
76 #define FPA_WQE_POOL_LINE 1
77 #define FPA_COMMAND_BUFFER_POOL (2) /* PKO queue command buffers */
78 #define FPA_COMMAND_BUFFER_POOL_SIZE FPA_POOL_2_SIZE
79 #define FPA_COMMAND_BUFFER_POOL_LINE 8
80 #define FPA_GATHER_BUFFER_POOL (3) /* PKO gather list buffers */
81 #define FPA_GATHER_BUFFER_POOL_SIZE FPA_POOL_3_SIZE
82 #define FPA_GATHER_BUFFER_POOL_LINE 4
83
84 #ifndef FPA_OUTPUT_BUFFER_POOL
85 #define FPA_OUTPUT_BUFFER_POOL FPA_COMMAND_BUFFER_POOL
86 #define FPA_OUTPUT_BUFFER_POOL_SIZE FPA_COMMAND_BUFFER_POOL_SIZE
87 #endif
88
89 /*
90 * operations
91 */
92
93 static __inline uint64_t
94 octfpa_load(uint64_t fpapool)
95 {
96 /* for FPA operations, subdid == pool number */
97 uint64_t addr = OCTEON_ADDR_IO_DID(FPA_MAJOR_DID, fpapool);
98
99 return octeon_read_csr(addr);
100 }
101
102 #ifdef notyet
103 static __inline uint64_t
104 octfpa_iobdma(struct octfpa_softc *sc, int srcaddr, int len)
105 {
106
107 /* XXX */
108 return 0ULL;
109 }
110 #endif
111
112 static __inline void
113 octfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount)
114 {
115 /* for FPA operations, subdid == pool number */
116 uint64_t ptr =
117 OCTEON_ADDR_IO_DID(FPA_MAJOR_DID, fpapool) |
118 __SHIFTIN(addr, FPA_OPS_STORE_ADDR);
119
120 OCTEON_SYNCWS;
121 octeon_write_csr(ptr, __SHIFTIN(dwbcount, FPA_OPS_STORE_DATA_DWBCOUNT));
122 }
123
124 static __inline paddr_t
125 octfpa_buf_get_paddr(struct octfpa_buf *fb)
126 {
127
128 return octfpa_load(fb->fb_poolno);
129 }
130
131 static __inline void
132 octfpa_buf_put_paddr(struct octfpa_buf *fb, paddr_t paddr)
133 {
134
135 KASSERT(paddr >= fb->fb_paddr);
136 KASSERT(paddr < fb->fb_paddr + fb->fb_len);
137 octfpa_store(paddr, fb->fb_poolno, fb->fb_size / 128);
138 }
139
140 static __inline void
141 octfpa_buf_put(struct octfpa_buf *fb, void *addr)
142 {
143 paddr_t paddr;
144
145 KASSERT((vaddr_t)addr >= fb->fb_addr);
146 KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len);
147 paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr);
148 octfpa_buf_put_paddr(fb, paddr);
149 }
150
151 #endif /* _OCTEON_FPAVAR_H_ */
152