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