Home | History | Annotate | Line # | Download | only in dev
      1 /*	$NetBSD: octeon_pkovar.h,v 1.6 2020/06/23 05:15:33 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 /*
     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 octpko_cmdptr_desc {
     51 	uint64_t	cmdptr;
     52 	uint64_t	cmdptr_idx;
     53 };
     54 
     55 /* XXX */
     56 struct octpko_softc {
     57 	int			sc_port;
     58 	bus_space_tag_t		sc_regt;
     59 	bus_space_handle_t	sc_regh;
     60 	struct octpko_cmdptr_desc
     61 				*sc_cmdptr;
     62 	int			sc_cmd_buf_pool;
     63 	size_t			sc_cmd_buf_size;
     64 };
     65 
     66 /* XXX */
     67 struct octpko_attach_args {
     68 	int				aa_port;
     69 	bus_space_tag_t			aa_regt;
     70 	struct octpko_cmdptr_desc	*aa_cmdptr;
     71 	int				aa_cmd_buf_pool;
     72 	size_t				aa_cmd_buf_size;
     73 };
     74 
     75 /* XXX */
     76 void			octpko_init(struct octpko_attach_args *,
     77 			    struct octpko_softc **);
     78 int			octpko_enable(struct octpko_softc *);
     79 int			octpko_reset(struct octpko_softc *);
     80 void			octpko_config(struct octpko_softc *);
     81 int			octpko_port_enable(struct octpko_softc *, int);
     82 int			octpko_port_config(struct octpko_softc *);
     83 void			octpko_int_enable(struct octpko_softc *, int);
     84 uint64_t		octpko_int_summary(struct octpko_softc *);
     85 static __inline uint64_t	octpko_cmd_word0(int, int, int, int, int, int,
     86 			    int, int, int, int, int, int, int, int, int, int);
     87 static __inline uint64_t	octpko_cmd_word1(int, int, int, int, paddr_t);
     88 
     89 
     90 static __inline uint64_t
     91 octpko_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 =
     96 	    __SHIFTIN(sz1, PKO_CMD_WORD0_SZ1) |
     97 	    __SHIFTIN(sz0, PKO_CMD_WORD0_SZ0) |
     98 	    __SHIFTIN(s1, PKO_CMD_WORD0_S1) |
     99 	    __SHIFTIN(reg1, PKO_CMD_WORD0_REG1) |
    100 	    __SHIFTIN(s0, PKO_CMD_WORD0_S0) |
    101 	    __SHIFTIN(reg0, PKO_CMD_WORD0_REG0) |
    102 	    __SHIFTIN(le, PKO_CMD_WORD0_LE) |
    103 	    __SHIFTIN(n2, PKO_CMD_WORD0_N2) |
    104 	    __SHIFTIN(q, PKO_CMD_WORD0_Q) |
    105 	    __SHIFTIN(r, PKO_CMD_WORD0_R) |
    106 	    __SHIFTIN(g, PKO_CMD_WORD0_G) |
    107 	    __SHIFTIN(ipoffp1, PKO_CMD_WORD0_IPOFFP1) |
    108 	    __SHIFTIN(ii, PKO_CMD_WORD0_II) |
    109 	    __SHIFTIN(df, PKO_CMD_WORD0_DF) |
    110 	    __SHIFTIN(segs, PKO_CMD_WORD0_SEGS) |
    111 	    __SHIFTIN(totalbytes, PKO_CMD_WORD0_TOTALBYTES);
    112 
    113 	return cmd;
    114 }
    115 
    116 static __inline uint64_t
    117 octpko_cmd_word1(int i, int back, int pool, int size, paddr_t addr)
    118 {
    119 	uint64_t cmd =
    120 	    __SHIFTIN(i, PKO_CMD_WORD1_I) |
    121 	    __SHIFTIN(back, PKO_CMD_WORD1_BACK) |
    122 	    __SHIFTIN(pool, PKO_CMD_WORD1_POOL) |
    123 	    __SHIFTIN(size, PKO_CMD_WORD1_SIZE) |
    124 	    __SHIFTIN(addr, PKO_CMD_WORD1_ADDR);
    125 
    126 	return cmd;
    127 }
    128 
    129 /* ---- operation primitives */
    130 
    131 /* Store Operations */
    132 
    133 static __inline void
    134 octpko_op_store(uint64_t args, uint64_t value)
    135 {
    136 	paddr_t addr;
    137 
    138 	addr = OCTEON_ADDR_IO_DID(PKO_MAJOR_DID, PKO_SUB_DID) | args;
    139 	/* XXX */
    140 	OCTEON_SYNCW;
    141 	octeon_xkphys_write_8(addr, value);
    142 }
    143 
    144 static __inline void
    145 octpko_op_doorbell_write(int pid, int qid, int wdc)
    146 {
    147 	uint64_t args, value;
    148 
    149 	args =
    150 	    __SHIFTIN(pid, PKO_DOORBELL_WRITE_PID) |
    151 	    __SHIFTIN(qid, PKO_DOORBELL_WRITE_QID);
    152 	value = __SHIFTIN(wdc, PKO_DOORBELL_WRITE_WDC);
    153 	octpko_op_store(args, value);
    154 }
    155 
    156 #endif /* _OCTEON_PKOVAR_H_ */
    157