Home | History | Annotate | Line # | Download | only in dev
octeon_fpavar.h revision 1.5
      1 /*	$NetBSD: octeon_fpavar.h,v 1.5 2020/06/18 13:52:08 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 #ifndef _OCTEON_FPAVAR_H_
     30 #define _OCTEON_FPAVAR_H_
     31 
     32 #include <mips/cavium/octeonreg.h>
     33 
     34 struct octfpa_buf {
     35 	int		fb_poolno;	/* pool # */
     36 
     37 	size_t		fb_size;	/* element size */
     38 	size_t		fb_nelems;	/* # of elements */
     39 
     40 	paddr_t		fb_paddr;	/* physical address */
     41 	vaddr_t		fb_addr;	/* virtual address */
     42 	size_t		fb_len;		/* total length */
     43 
     44 	bus_dma_tag_t	fb_dmat;
     45 	bus_dmamap_t	fb_dmah;
     46 	bus_dma_segment_t
     47 			*fb_dma_segs;
     48 	int		fb_dma_nsegs;
     49 };
     50 
     51 uint64_t	octfpa_int_summary(void);
     52 int		octfpa_buf_init(int, size_t, size_t, struct octfpa_buf **);
     53 void		*octfpa_buf_get(struct octfpa_buf *);
     54 uint64_t	octfpa_query(int);
     55 int		octfpa_available_fpa_pool(int *available, int pool_no);
     56 
     57 #ifdef CNMAC_DEBUG
     58 void	octfpa_dump(void);
     59 #endif
     60 
     61 #define OCTEON_CACHE_LINE_SIZE (128)
     62 
     63 /* Pool sizes in bytes, must be multiple of a cache line */
     64 #define FPA_POOL_0_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
     65 #define FPA_POOL_1_SIZE (1 * OCTEON_CACHE_LINE_SIZE)
     66 #define FPA_POOL_2_SIZE (8 * OCTEON_CACHE_LINE_SIZE)
     67 #define FPA_POOL_3_SIZE (4 * OCTEON_CACHE_LINE_SIZE)
     68 
     69 #define FPA_POOL_4_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
     70 #define FPA_POOL_5_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
     71 #define FPA_POOL_6_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
     72 #define FPA_POOL_7_SIZE (16 * OCTEON_CACHE_LINE_SIZE)
     73 
     74 /* Pools in use */
     75 #define FPA_RECV_PKT_POOL		(0)	/* Receive Packet buffers */
     76 #define FPA_RECV_PKT_POOL_SIZE		FPA_POOL_0_SIZE
     77 #define FPA_RECV_PKT_POOL_LINE		16
     78 #define FPA_WQE_POOL			(1)	/* Work queue entrys */
     79 #define FPA_WQE_POOL_SIZE		FPA_POOL_1_SIZE
     80 #define FPA_WQE_POOL_LINE		1
     81 #define FPA_COMMAND_BUFFER_POOL		(2)	/* PKO queue command buffers */
     82 #define FPA_COMMAND_BUFFER_POOL_SIZE	FPA_POOL_2_SIZE
     83 #define FPA_COMMAND_BUFFER_POOL_LINE	8
     84 #define FPA_GATHER_BUFFER_POOL		(3)	/* PKO gather list buffers */
     85 #define FPA_GATHER_BUFFER_POOL_SIZE	FPA_POOL_3_SIZE
     86 #define FPA_GATHER_BUFFER_POOL_LINE	4
     87 
     88 #ifndef FPA_OUTPUT_BUFFER_POOL
     89 #define FPA_OUTPUT_BUFFER_POOL		FPA_COMMAND_BUFFER_POOL
     90 #define FPA_OUTPUT_BUFFER_POOL_SIZE	FPA_COMMAND_BUFFER_POOL_SIZE
     91 #endif
     92 
     93 /*
     94  * operations
     95  */
     96 
     97 static __inline uint64_t
     98 octfpa_load(uint64_t fpapool)
     99 {
    100 	/* for FPA operations, subdid == pool number */
    101 	uint64_t addr = OCTEON_ADDR_IO_DID(FPA_MAJOR_DID, fpapool);
    102 
    103 	return octeon_read_csr(addr);
    104 }
    105 
    106 #ifdef notyet
    107 static __inline uint64_t
    108 octfpa_iobdma(struct octfpa_softc *sc, int srcaddr, int len)
    109 {
    110 
    111 	/* XXX */
    112 	return 0ULL;
    113 }
    114 #endif
    115 
    116 static __inline void
    117 octfpa_store(uint64_t addr, uint64_t fpapool, uint64_t dwbcount)
    118 {
    119 	/* for FPA operations, subdid == pool number */
    120 	uint64_t ptr =
    121 	    OCTEON_ADDR_IO_DID(FPA_MAJOR_DID, fpapool) |
    122 	    __SHIFTIN(addr, FPA_OPS_STORE_ADDR);
    123 
    124 	OCTEON_SYNCWS;
    125 	octeon_write_csr(ptr, __SHIFTIN(dwbcount, FPA_OPS_STORE_DATA_DWBCOUNT));
    126 }
    127 
    128 static __inline paddr_t
    129 octfpa_buf_get_paddr(struct octfpa_buf *fb)
    130 {
    131 
    132 	return octfpa_load(fb->fb_poolno);
    133 }
    134 
    135 static __inline void
    136 octfpa_buf_put_paddr(struct octfpa_buf *fb, paddr_t paddr)
    137 {
    138 
    139 	KASSERT(paddr >= fb->fb_paddr);
    140 	KASSERT(paddr < fb->fb_paddr + fb->fb_len);
    141 	octfpa_store(paddr, fb->fb_poolno, fb->fb_size / 128);
    142 }
    143 
    144 static __inline void
    145 octfpa_buf_put(struct octfpa_buf *fb, void *addr)
    146 {
    147 	paddr_t paddr;
    148 
    149 	KASSERT((vaddr_t)addr >= fb->fb_addr);
    150 	KASSERT((vaddr_t)addr < fb->fb_addr + fb->fb_len);
    151 	paddr = fb->fb_paddr + (paddr_t/* XXX */)((vaddr_t)addr - fb->fb_addr);
    152 	octfpa_buf_put_paddr(fb, paddr);
    153 }
    154 
    155 #endif /* _OCTEON_FPAVAR_H_ */
    156