xref: /openbsd/sys/arch/octeon/dev/cn30xxpkovar.h (revision e5dd7070)
1 /*	$OpenBSD: cn30xxpkovar.h,v 1.5 2014/08/11 18:29:56 miod 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  * Cavium Networks OCTEON CN30XX Hardware Reference Manual
31  * CN30XX-HM-1.0
32  * 8.9 PKO Registers
33  */
34 
35 #ifndef _CN30XXPKOVAR_H_
36 #define _CN30XXPKOVAR_H_
37 
38 #include <octeon/dev/cn30xxfauvar.h>
39 #include <octeon/dev/cn30xxpkoreg.h>
40 
41 #define FAU_OP_SIZE_8	0
42 #define FAU_OP_SIZE_16	1
43 #define FAU_OP_SIZE_32	2
44 #define FAU_OP_SIZE_64	3
45 
46 #define PKO_OUTPUT_PORTS_NUM		5
47 #define PKO_OUTPUT_PORTS_PKTIF_NUM	3
48 #define PKO_OUTPUT_PORTS_PCIIF_NUM	2
49 #define	PKO_MEM_QUEUE_PTRS_ILLEGAL_PID	63
50 
51 /* XXX */
52 struct cn30xxpko_cmdptr_desc {
53 	uint64_t	cmdptr;
54 	uint64_t	cmdptr_idx;
55 };
56 
57 /* XXX */
58 struct cn30xxpko_softc {
59 	int			sc_port;
60 	bus_space_tag_t		sc_regt;
61 	bus_space_handle_t	sc_regh;
62 	struct cn30xxpko_cmdptr_desc
63 				*sc_cmdptr;
64 	int			sc_cmd_buf_pool;
65 	size_t			sc_cmd_buf_size;
66 };
67 
68 /* XXX */
69 struct cn30xxpko_attach_args {
70 	int				aa_port;
71 	bus_space_tag_t			aa_regt;
72 	struct cn30xxpko_cmdptr_desc	*aa_cmdptr;
73 	int				aa_cmd_buf_pool;
74 	size_t				aa_cmd_buf_size;
75 };
76 
77 /* XXX */
78 void			cn30xxpko_init(struct cn30xxpko_attach_args *,
79 			    struct cn30xxpko_softc **);
80 int			cn30xxpko_enable(struct cn30xxpko_softc *);
81 int			cn30xxpko_reset(struct cn30xxpko_softc *);
82 void			cn30xxpko_config(struct cn30xxpko_softc *);
83 int			cn30xxpko_port_enable(struct cn30xxpko_softc *, int);
84 int			cn30xxpko_port_config(struct cn30xxpko_softc *);
85 void			cn30xxpko_int_enable(struct cn30xxpko_softc *, int);
86 uint64_t		cn30xxpko_int_summary(struct cn30xxpko_softc *);
87 static inline uint64_t	cn30xxpko_cmd_word0(int, int, int, int, int, int,
88 			    int, int, int, int, int, int, int, int, int, int);
89 static inline uint64_t	cn30xxpko_cmd_word1(int, int, int, int, paddr_t);
90 
91 
92 static inline uint64_t
93 cn30xxpko_cmd_word0(int sz1, int sz0, int s1, int reg1, int s0, int reg0,
94     int le, int n2, int q, int r, int g, int ipoffp1, int ii, int df, int segs,
95     int totalbytes)
96 {
97 	uint64_t cmd = 0;
98 
99 	SET(cmd, (((uint64_t)sz1 << 62) & PKO_CMD_WORD0_SZ1)
100  	    | (((uint64_t)sz0 << 60) & PKO_CMD_WORD0_SZ0)
101 	    | (((uint64_t)s1 << 59) & PKO_CMD_WORD0_S1)
102 	    | (((uint64_t)reg1 << 48) & PKO_CMD_WORD0_REG1)
103 	    | (((uint64_t)s0 << 47) & PKO_CMD_WORD0_S0)
104 	    | (((uint64_t)reg0 << 36) & PKO_CMD_WORD0_REG0)
105 	    | (((uint64_t)le << 35) & PKO_CMD_WORD0_LE)
106 	    | (((uint64_t)n2 << 34) & PKO_CMD_WORD0_N2)
107 	    | (((uint64_t)q << 33) & PKO_CMD_WORD0_Q)
108 	    | (((uint64_t)r << 32) & PKO_CMD_WORD0_R)
109 	    | (((uint64_t)g << 31) & PKO_CMD_WORD0_G)
110 	    | (((uint64_t)ipoffp1 << 24) & PKO_CMD_WORD0_IPOFFP1)
111 	    | (((uint64_t)ii << 23) & PKO_CMD_WORD0_II)
112 	    | (((uint64_t)df << 22) & PKO_CMD_WORD0_DF)
113 	    | (((uint64_t)segs << 16) & PKO_CMD_WORD0_SEGS)
114 	    | (((uint64_t)totalbytes << 0) & PKO_CMD_WORD0_TOTALBYTES));
115 	return cmd;
116 }
117 
118 static inline uint64_t
119 cn30xxpko_cmd_word1(int i, int back, int pool, int size, paddr_t addr)
120 {
121 	uint64_t cmd = 0;
122 
123 	SET(cmd, (((uint64_t)i << 63) & PKO_CMD_WORD1_I)
124 	    | (((uint64_t)back << 59) & PKO_CMD_WORD1_BACK)
125 	    | (((uint64_t)pool << 56) & PKO_CMD_WORD1_POOL)
126 	    | (((uint64_t)size << 40) & PKO_CMD_WORD1_SIZE)
127 	    | (((uint64_t)addr << 0) & PKO_CMD_WORD1_ADDR));
128 	return cmd;
129 }
130 
131 /* ---- operation primitives */
132 
133 /* 8.8.1 Store Operations */
134 
135 static inline void
136 cn30xxpko_op_store(uint64_t args, uint64_t value)
137 {
138 	paddr_t addr;
139 
140 	addr =
141 	    ((uint64_t)1 << 48) |
142 	    ((uint64_t)(CN30XXPKO_MAJORDID & 0x1f) << 43) |
143 	    ((uint64_t)(CN30XXPKO_SUBDID & 0x7) << 40) |
144 	    ((uint64_t)args);
145 	/* XXX */
146 	mips_sync();
147 	octeon_xkphys_write_8(addr, value);
148 }
149 
150 static inline void
151 cn30xxpko_op_doorbell_write(int pid, int qid, int wdc)
152 {
153 	uint64_t args, value;
154 
155 	args =
156 	    ((uint64_t)(pid & 0x3f) << 12) |
157 	    ((uint64_t)(qid & 0x1ff) << 3);
158 	value = wdc & 0xfffff;
159 	cn30xxpko_op_store(args, value);
160 }
161 
162 #endif
163