1*eb61b502Ssimonb /* $NetBSD: octeon_fauvar.h,v 1.4 2020/06/23 05:14:18 simonb Exp $ */
2f693c922Shikaru
3f693c922Shikaru /*
4f693c922Shikaru * Copyright (c) 2007 Internet Initiative Japan, Inc.
5f693c922Shikaru * All rights reserved.
6f693c922Shikaru *
7f693c922Shikaru * Redistribution and use in source and binary forms, with or without
8f693c922Shikaru * modification, are permitted provided that the following conditions
9f693c922Shikaru * are met:
10f693c922Shikaru * 1. Redistributions of source code must retain the above copyright
11f693c922Shikaru * notice, this list of conditions and the following disclaimer.
12f693c922Shikaru * 2. Redistributions in binary form must reproduce the above copyright
13f693c922Shikaru * notice, this list of conditions and the following disclaimer in the
14f693c922Shikaru * documentation and/or other materials provided with the distribution.
15f693c922Shikaru *
16f693c922Shikaru * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
17f693c922Shikaru * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18f693c922Shikaru * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19f693c922Shikaru * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20f693c922Shikaru * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21f693c922Shikaru * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22f693c922Shikaru * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23f693c922Shikaru * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24f693c922Shikaru * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25f693c922Shikaru * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26f693c922Shikaru * SUCH DAMAGE.
27f693c922Shikaru */
28f693c922Shikaru
29f693c922Shikaru #ifndef _OCTEON_FAUVAR_H_
30f693c922Shikaru #define _OCTEON_FAUVAR_H_
31f693c922Shikaru
32b9fcd28bSsimonb #include <mips/cavium/octeonreg.h>
33b9fcd28bSsimonb
34f693c922Shikaru /* ---- API */
35f693c922Shikaru
363f508e4dSsimonb struct octfau_desc {
37f693c922Shikaru /* offset in scratch buffer */
38f693c922Shikaru size_t fd_scroff; /* XXX offset_t */
39f693c922Shikaru /* FAU register number */
40f693c922Shikaru size_t fd_regno; /* XXX offset_t */
41f693c922Shikaru };
42f693c922Shikaru
433f508e4dSsimonb void octfau_op_init(struct octfau_desc *, size_t, size_t);
443f508e4dSsimonb uint64_t octfau_op_save(struct octfau_desc *);
453f508e4dSsimonb void octfau_op_restore(struct octfau_desc *, uint64_t);
463f508e4dSsimonb int64_t octfau_op_inc_8(struct octfau_desc *, int64_t);
473f508e4dSsimonb int32_t octfau_op_inc_4(struct octfau_desc *, int32_t);
483f508e4dSsimonb int16_t octfau_op_inc_2(struct octfau_desc *, int16_t);
493f508e4dSsimonb int8_t octfau_op_inc_1(struct octfau_desc *, int8_t);
503f508e4dSsimonb int64_t octfau_op_incwait_8(struct octfau_desc *, int);
513f508e4dSsimonb int32_t octfau_op_incwait_4(struct octfau_desc *, int);
523f508e4dSsimonb int16_t octfau_op_incwait_2(struct octfau_desc *, int);
533f508e4dSsimonb int8_t octfau_op_incwait_1(struct octfau_desc *, int);
543f508e4dSsimonb int64_t octfau_op_get_8(struct octfau_desc *);
553f508e4dSsimonb int32_t octfau_op_get_4(struct octfau_desc *);
563f508e4dSsimonb int16_t octfau_op_get_2(struct octfau_desc *);
573f508e4dSsimonb int8_t octfau_op_get_1(struct octfau_desc *);
583f508e4dSsimonb int64_t octfau_op_getwait_8(struct octfau_desc *);
593f508e4dSsimonb int32_t octfau_op_getwait_4(struct octfau_desc *);
603f508e4dSsimonb int16_t octfau_op_getwait_2(struct octfau_desc *);
613f508e4dSsimonb int8_t octfau_op_getwait_1(struct octfau_desc *);
623f508e4dSsimonb void octfau_op_add_8(struct octfau_desc *, int64_t);
633f508e4dSsimonb void octfau_op_add_4(struct octfau_desc *, int32_t);
643f508e4dSsimonb void octfau_op_add_2(struct octfau_desc *, int16_t);
653f508e4dSsimonb void octfau_op_add_1(struct octfau_desc *, int8_t);
663f508e4dSsimonb void octfau_op_set_8(struct octfau_desc *, int64_t);
673f508e4dSsimonb void octfau_op_set_4(struct octfau_desc *, int32_t);
683f508e4dSsimonb void octfau_op_set_2(struct octfau_desc *, int16_t);
693f508e4dSsimonb void octfau_op_set_1(struct octfau_desc *, int8_t);
70f693c922Shikaru
71f693c922Shikaru /* ---- old API */
72f693c922Shikaru
73f693c922Shikaru /* XXX */
74f693c922Shikaru #define OCT_FAU_REG_OQ_ADDR_INDEX (0)
75f693c922Shikaru #define OCT_FAU_REG_ADDR_END (256)
76f693c922Shikaru /* XXX */
77f693c922Shikaru
78f693c922Shikaru /* XXX */
79f693c922Shikaru typedef enum {
80f693c922Shikaru OCT_FAU_OP_SIZE_8 = 0,
81f693c922Shikaru OCT_FAU_OP_SIZE_16 = 1,
82f693c922Shikaru OCT_FAU_OP_SIZE_32 = 2,
83f693c922Shikaru OCT_FAU_OP_SIZE_64 = 3
84f693c922Shikaru } fau_op_size_t;
85f693c922Shikaru /* XXX */
86f693c922Shikaru
87f693c922Shikaru /*
88f693c922Shikaru * XXX
89f693c922Shikaru * `scraddr' parameter of IOBDMA operation is actually `index';
90f693c922Shikaru */
91f693c922Shikaru static inline void
octfau_op_iobdma(int index,uint64_t args)923f508e4dSsimonb octfau_op_iobdma(int index, uint64_t args)
93f693c922Shikaru {
94b9fcd28bSsimonb uint64_t value = IOBDMA_CREATE(FAU_MAJOR_DID, FAU_SUB_DID,
95b9fcd28bSsimonb index, POW_IOBDMA_LEN, args);
96f693c922Shikaru
97f693c922Shikaru octeon_iobdma_write_8(value);
98f693c922Shikaru }
99f693c922Shikaru
100f693c922Shikaru /* IOBDMA Operations */
101f693c922Shikaru
102f693c922Shikaru /* IOBDMA Store Data for FAU Operations */
103f693c922Shikaru
104f693c922Shikaru static inline void
octfau_op_iobdma_store_data(int scraddr,int incval,int tagwait,int size,int reg)1053f508e4dSsimonb octfau_op_iobdma_store_data(int scraddr, int incval, int tagwait,
106f693c922Shikaru int size, int reg)
107f693c922Shikaru {
108b9fcd28bSsimonb uint64_t args =
109b9fcd28bSsimonb __SHIFTIN(incval, POW_IOBDMA_INCVAL) |
110b9fcd28bSsimonb __SHIFTIN(tagwait, POW_IOBDMA_TAGWAIT) |
111b9fcd28bSsimonb __SHIFTIN(size, POW_IOBDMA_SIZE) |
112b9fcd28bSsimonb __SHIFTIN(reg, POW_IOBDMA_REG);
113f693c922Shikaru
114b9fcd28bSsimonb /* `scraddr' parameter of IOBDMA operation is actually `index' */
115b9fcd28bSsimonb octfau_op_iobdma(scraddr / sizeof(uint64_t), args);
116f693c922Shikaru }
117f693c922Shikaru
118f693c922Shikaru static inline void
octfau_op_inc_fetch_8(struct octfau_desc * fd,int64_t v)1193f508e4dSsimonb octfau_op_inc_fetch_8(struct octfau_desc *fd, int64_t v)
120f693c922Shikaru {
121*eb61b502Ssimonb
122b9fcd28bSsimonb octfau_op_iobdma_store_data(fd->fd_scroff, v, 0,
123b9fcd28bSsimonb OCT_FAU_OP_SIZE_64/* XXX */, fd->fd_regno);
124f693c922Shikaru }
125f693c922Shikaru
126f693c922Shikaru static inline int64_t
octfau_op_inc_read_8(struct octfau_desc * fd)1273f508e4dSsimonb octfau_op_inc_read_8(struct octfau_desc *fd)
128f693c922Shikaru {
129*eb61b502Ssimonb
130f693c922Shikaru OCTEON_SYNCIOBDMA;
131f693c922Shikaru return octeon_cvmseg_read_8(fd->fd_scroff);
132f693c922Shikaru }
133f693c922Shikaru
134f693c922Shikaru #endif /* _OCTEON_FAUVAR_H_ */
135