xref: /openbsd/sys/arch/octeon/dev/cn30xxfpavar.h (revision a6445c1d)
1 /*	$OpenBSD: cn30xxfpavar.h,v 1.3 2013/06/01 22:20:35 jasper Exp $	*/
2 /*
3  * Copyright (c) 2007 Internet Initiative Japan, Inc.
4  * All rights reserved.
5  *
6  * Redistribution and use in source and binary forms, with or without
7  * modification, are permitted provided that the following conditions
8  * are met:
9  * 1. Redistributions of source code must retain the above copyright
10  *    notice, this list of conditions and the following disclaimer.
11  * 2. Redistributions in binary form must reproduce the above copyright
12  *    notice, this list of conditions and the following disclaimer in the
13  *    documentation and/or other materials provided with the distribution.
14  *
15  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
16  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
19  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25  * SUCH DAMAGE.
26  */
27 
28 #ifndef _CN30XXFPAVAR_H_
29 #define _CN30XXFPAVAR_H_
30 
31 struct cn30xxfpa_buf {
32 	int		fb_poolno;	/* pool # */
33 
34 	size_t		fb_size;	/* element size */
35 	size_t		fb_nelems;	/* # of elements */
36 
37 	paddr_t		fb_paddr;	/* physical address */
38 	vaddr_t		fb_addr;	/* virtual address */
39 	size_t		fb_len;		/* total length */
40 
41 	bus_dma_tag_t	fb_dmat;
42 	bus_dmamap_t	fb_dmah;
43 	bus_dma_segment_t
44 			*fb_dma_segs;
45 	int		fb_dma_nsegs;
46 };
47 
48 uint64_t	cn30xxfpa_int_summary(void);
49 int		cn30xxfpa_buf_init(int, size_t, size_t, struct cn30xxfpa_buf **);
50 void		*cn30xxfpa_buf_get(struct cn30xxfpa_buf *);
51 uint64_t	cn30xxfpa_query(int);
52 
53 #ifdef OCTEON_ETH_DEBUG
54 void	cn30xxfpa_dump(void);
55 #endif
56 
57 #define CACHE_LINE_SIZE (128)
58 
59 /* Pool sizes in bytes, must be multiple of a cache line */
60 #define FPA_POOL_0_SIZE (16 * CACHE_LINE_SIZE)
61 #define FPA_POOL_1_SIZE (1 * CACHE_LINE_SIZE)
62 #define FPA_POOL_2_SIZE (8 * CACHE_LINE_SIZE)
63 #define FPA_POOL_3_SIZE (4 * CACHE_LINE_SIZE)
64 
65 #define FPA_POOL_4_SIZE (16 * CACHE_LINE_SIZE)
66 #define FPA_POOL_5_SIZE (16 * CACHE_LINE_SIZE)
67 #define FPA_POOL_6_SIZE (16 * CACHE_LINE_SIZE)
68 #define FPA_POOL_7_SIZE (16 * CACHE_LINE_SIZE)
69 
70 /* Pools in use */
71 #define FPA_RECV_PKT_POOL		(0)	/* Recieve 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 cn30xxfpa_load(uint64_t fpapool)
95 {
96 	uint64_t addr;
97 
98 	addr =
99 	    (0x1ULL << 48) |
100 	    (0x5ULL << 43) |
101 	    (fpapool & 0x07ULL) << 40;
102 
103 	return octeon_xkphys_read_8(addr);
104 }
105 
106 #ifdef notyet
107 static inline uint64_t
108 cn30xxfpa_iobdma(struct cn30xxfpa_softc *sc, int srcaddr, int len)
109 {
110 	/* XXX */
111 	return 0ULL;
112 }
113 #endif
114 
115 static inline void
116 cn30xxfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount)
117 {
118 	uint64_t ptr;
119 
120 	ptr =
121 	    (0x1ULL << 48) |
122 	    (0x5ULL << 43) |
123 	    (fpapool & 0x07ULL) << 40 |
124 	    (addr & 0xffffffffffULL);
125 
126 	mips_sync();
127 	octeon_xkphys_write_8(ptr, (dwbcount & 0x0ffULL));
128 }
129 
130 static inline paddr_t
131 cn30xxfpa_buf_get_paddr(struct cn30xxfpa_buf *fb)
132 {
133 	return cn30xxfpa_load(fb->fb_poolno);
134 }
135 
136 static inline void
137 cn30xxfpa_buf_put_paddr(struct cn30xxfpa_buf *fb, paddr_t paddr)
138 {
139 	KASSERT(paddr >= fb->fb_paddr);
140 	KASSERT(paddr < fb->fb_paddr + fb->fb_len);
141 	cn30xxfpa_store(paddr, fb->fb_poolno, fb->fb_size / 128);
142 }
143 
144 static inline void
145 cn30xxfpa_buf_put(struct cn30xxfpa_buf *fb, void *addr)
146 {
147 	paddr_t paddr;
148 
149 	KASSERT((vaddr_t)addr >= fb->fb_addr);
150 	KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len);
151 	paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr);
152 	cn30xxfpa_buf_put_paddr(fb, paddr);
153 }
154 
155 #endif
156