1 /* $OpenBSD: cn30xxpkovar.h,v 1.7 2024/05/20 23:13:33 jsg 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 AUTHORS 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 AUTHORS 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 static inline uint64_t cn30xxpko_cmd_word0(int, int, int, int, int, int,
86 int, int, int, int, int, int, int, int, int, int);
87 static inline uint64_t cn30xxpko_cmd_word1(int, int, int, int, paddr_t);
88
89
90 static inline uint64_t
cn30xxpko_cmd_word0(int sz1,int sz0,int s1,int reg1,int s0,int reg0,int le,int n2,int q,int r,int g,int ipoffp1,int ii,int df,int segs,int totalbytes)91 cn30xxpko_cmd_word0(int sz1, int sz0, int s1, int reg1, int s0, int reg0,
92 int le, int n2, int q, int r, int g, int ipoffp1, int ii, int df, int segs,
93 int totalbytes)
94 {
95 uint64_t cmd = 0;
96
97 SET(cmd, (((uint64_t)sz1 << 62) & PKO_CMD_WORD0_SZ1)
98 | (((uint64_t)sz0 << 60) & PKO_CMD_WORD0_SZ0)
99 | (((uint64_t)s1 << 59) & PKO_CMD_WORD0_S1)
100 | (((uint64_t)reg1 << 48) & PKO_CMD_WORD0_REG1)
101 | (((uint64_t)s0 << 47) & PKO_CMD_WORD0_S0)
102 | (((uint64_t)reg0 << 36) & PKO_CMD_WORD0_REG0)
103 | (((uint64_t)le << 35) & PKO_CMD_WORD0_LE)
104 | (((uint64_t)n2 << 34) & PKO_CMD_WORD0_N2)
105 | (((uint64_t)q << 33) & PKO_CMD_WORD0_Q)
106 | (((uint64_t)r << 32) & PKO_CMD_WORD0_R)
107 | (((uint64_t)g << 31) & PKO_CMD_WORD0_G)
108 | (((uint64_t)ipoffp1 << 24) & PKO_CMD_WORD0_IPOFFP1)
109 | (((uint64_t)ii << 23) & PKO_CMD_WORD0_II)
110 | (((uint64_t)df << 22) & PKO_CMD_WORD0_DF)
111 | (((uint64_t)segs << 16) & PKO_CMD_WORD0_SEGS)
112 | (((uint64_t)totalbytes << 0) & PKO_CMD_WORD0_TOTALBYTES));
113 return cmd;
114 }
115
116 static inline uint64_t
cn30xxpko_cmd_word1(int i,int back,int pool,int size,paddr_t addr)117 cn30xxpko_cmd_word1(int i, int back, int pool, int size, paddr_t addr)
118 {
119 uint64_t cmd = 0;
120
121 SET(cmd, (((uint64_t)i << 63) & PKO_CMD_WORD1_I)
122 | (((uint64_t)back << 59) & PKO_CMD_WORD1_BACK)
123 | (((uint64_t)pool << 56) & PKO_CMD_WORD1_POOL)
124 | (((uint64_t)size << 40) & PKO_CMD_WORD1_SIZE)
125 | (((uint64_t)addr << 0) & PKO_CMD_WORD1_ADDR));
126 return cmd;
127 }
128
129 /* ---- operation primitives */
130
131 /* 8.8.1 Store Operations */
132
133 static inline void
cn30xxpko_op_store(uint64_t args,uint64_t value)134 cn30xxpko_op_store(uint64_t args, uint64_t value)
135 {
136 paddr_t addr;
137
138 addr =
139 ((uint64_t)1 << 48) |
140 ((uint64_t)(CN30XXPKO_MAJORDID & 0x1f) << 43) |
141 ((uint64_t)(CN30XXPKO_SUBDID & 0x7) << 40) |
142 ((uint64_t)args);
143 /* XXX */
144 mips_sync();
145 octeon_xkphys_write_8(addr, value);
146 }
147
148 static inline void
cn30xxpko_op_doorbell_write(int pid,int qid,int wdc)149 cn30xxpko_op_doorbell_write(int pid, int qid, int wdc)
150 {
151 uint64_t args, value;
152
153 args =
154 ((uint64_t)(pid & 0x3f) << 12) |
155 ((uint64_t)(qid & 0x1ff) << 3);
156 value = wdc & 0xfffff;
157 cn30xxpko_op_store(args, value);
158 }
159
160 #endif
161