xref: /netbsd-src/sys/arch/mips/cavium/dev/octeon_pkovar.h (revision bdc22b2e01993381dcefeff2bc9b56ca75a4235c)
1 /*	$NetBSD: octeon_pkovar.h,v 1.2 2018/04/19 21:50:06 christos 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 /*
30  * PKO Registers
31  */
32 
33 #ifndef _OCTEON_PKOVAR_H_
34 #define _OCTEON_PKOVAR_H_
35 
36 #include <mips/cavium/dev/octeon_fauvar.h>
37 #include <mips/cavium/dev/octeon_pkoreg.h>
38 
39 #define FAU_OP_SIZE_8	0
40 #define FAU_OP_SIZE_16	1
41 #define FAU_OP_SIZE_32	2
42 #define FAU_OP_SIZE_64	3
43 
44 #define PKO_OUTPUT_PORTS_NUM		5
45 #define PKO_OUTPUT_PORTS_PKTIF_NUM	3
46 #define PKO_OUTPUT_PORTS_PCIIF_NUM	2
47 #define	PKO_MEM_QUEUE_PTRS_ILLEGAL_PID	63
48 
49 /* XXX */
50 struct octeon_pko_cmdptr_desc {
51 	uint64_t	cmdptr;
52 	uint64_t	cmdptr_idx;
53 };
54 
55 /* XXX */
56 struct octeon_pko_softc {
57 	int			sc_port;
58 	bus_space_tag_t		sc_regt;
59 	bus_space_handle_t	sc_regh;
60 	struct octeon_pko_cmdptr_desc
61 				*sc_cmdptr;
62 	int			sc_cmd_buf_pool;
63 	size_t			sc_cmd_buf_size;
64 
65 #ifdef OCTEON_ETH_DEBUG
66 	struct evcnt		sc_ev_pkoerrdbell;
67 	struct evcnt		sc_ev_pkoerrparity;
68 #endif
69 };
70 
71 /* XXX */
72 struct octeon_pko_attach_args {
73 	int				aa_port;
74 	bus_space_tag_t			aa_regt;
75 	struct octeon_pko_cmdptr_desc	*aa_cmdptr;
76 	int				aa_cmd_buf_pool;
77 	size_t				aa_cmd_buf_size;
78 };
79 
80 /* XXX */
81 void			octeon_pko_init(struct octeon_pko_attach_args *,
82 			    struct octeon_pko_softc **);
83 int			octeon_pko_enable(struct octeon_pko_softc *);
84 int			octeon_pko_reset(struct octeon_pko_softc *);
85 void			octeon_pko_config(struct octeon_pko_softc *);
86 int			octeon_pko_port_enable(struct octeon_pko_softc *, int);
87 int			octeon_pko_port_config(struct octeon_pko_softc *);
88 void			octeon_pko_int_enable(struct octeon_pko_softc *, int);
89 uint64_t		octeon_pko_int_summary(struct octeon_pko_softc *);
90 static __inline uint64_t	octeon_pko_cmd_word0(int, int, int, int, int, int,
91 			    int, int, int, int, int, int, int, int, int, int);
92 static __inline uint64_t	octeon_pko_cmd_word1(int, int, int, int, paddr_t);
93 
94 
95 static __inline uint64_t
96 octeon_pko_cmd_word0(int sz1, int sz0, int s1, int reg1, int s0, int reg0,
97     int le, int n2, int q, int r, int g, int ipoffp1, int ii, int df, int segs,
98     int totalbytes)
99 {
100 	uint64_t cmd = 0;
101 
102 	SET(cmd, (((uint64_t)sz1 << 62) & PKO_CMD_WORD0_SZ1)
103  	    | (((uint64_t)sz0 << 60) & PKO_CMD_WORD0_SZ0)
104 	    | (((uint64_t)s1 << 59) & PKO_CMD_WORD0_S1)
105 	    | (((uint64_t)reg1 << 48) & PKO_CMD_WORD0_REG1)
106 	    | (((uint64_t)s0 << 47) & PKO_CMD_WORD0_S0)
107 	    | (((uint64_t)reg0 << 36) & PKO_CMD_WORD0_REG0)
108 	    | (((uint64_t)le << 35) & PKO_CMD_WORD0_LE)
109 	    | (((uint64_t)n2 << 34) & PKO_CMD_WORD0_N2)
110 	    | (((uint64_t)q << 33) & PKO_CMD_WORD0_Q)
111 	    | (((uint64_t)r << 32) & PKO_CMD_WORD0_R)
112 	    | (((uint64_t)g << 31) & PKO_CMD_WORD0_G)
113 	    | (((uint64_t)ipoffp1 << 24) & PKO_CMD_WORD0_IPOFFP1)
114 	    | (((uint64_t)ii << 23) & PKO_CMD_WORD0_II)
115 	    | (((uint64_t)df << 22) & PKO_CMD_WORD0_DF)
116 	    | (((uint64_t)segs << 16) & PKO_CMD_WORD0_SEGS)
117 	    | (((uint64_t)totalbytes << 0) & PKO_CMD_WORD0_TOTALBYTES));
118 	return cmd;
119 }
120 
121 static __inline uint64_t
122 octeon_pko_cmd_word1(int i, int back, int pool, int size, paddr_t addr)
123 {
124 	uint64_t cmd = 0;
125 
126 	SET(cmd, (((uint64_t)i << 63) & PKO_CMD_WORD1_I)
127 	    | (((uint64_t)back << 59) & PKO_CMD_WORD1_BACK)
128 	    | (((uint64_t)pool << 56) & PKO_CMD_WORD1_POOL)
129 	    | (((uint64_t)size << 40) & PKO_CMD_WORD1_SIZE)
130 	    | (((uint64_t)addr << 0) & PKO_CMD_WORD1_ADDR));
131 	return cmd;
132 }
133 
134 /* ---- operation primitives */
135 
136 /* Store Operations */
137 
138 static __inline void
139 octeon_pko_op_store(uint64_t args, uint64_t value)
140 {
141 	paddr_t addr;
142 
143 	addr =
144 	    ((uint64_t)1 << 48) |
145 	    ((uint64_t)(CN30XXPKO_MAJORDID & 0x1f) << 43) |
146 	    ((uint64_t)(CN30XXPKO_SUBDID & 0x7) << 40) |
147 	    ((uint64_t)args);
148 	/* XXX */
149 	OCTEON_SYNCW;
150 	octeon_write_csr(addr, value);
151 }
152 
153 static __inline void
154 octeon_pko_op_doorbell_write(int pid, int qid, int wdc)
155 {
156 	uint64_t args, value;
157 
158 	args =
159 	    ((uint64_t)(pid & 0x3f) << 12) |
160 	    ((uint64_t)(qid & 0x1ff) << 3);
161 	value = wdc & 0xfffff;
162 	octeon_pko_op_store(args, value);
163 }
164 
165 #endif
166