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