1 /*- 2 * Copyright (c) 2011-2012 Semihalf. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24 * SUCH DAMAGE. 25 */ 26 27 #ifndef FMAN_H_ 28 #define FMAN_H_ 29 30 #include <dev/fdt/simplebus.h> 31 #include <sys/vmem.h> 32 33 #define FMAN_BMI_FIFO_UNITS 0x100 34 #define FMAN_BMI_FIFO_ALIGN 0x100 35 36 #define FM_FD_ERR_DMA 0x01000000 37 #define FM_FD_ERR_FPE 0x00080000 38 #define FM_FD_ERR_FSE 0x00040000 39 #define FM_FD_ERR_DIS 0x00020000 40 #define FM_FD_ERR_EOF 0x00008000 41 #define FM_FD_ERR_NSS 0x00004000 42 #define FM_FD_ERR_KSO 0x00002000 43 #define FM_FD_ERR_IPP 0x00000200 44 #define FM_FD_ERR_PTE 0x00000080 45 #define FM_FD_ERR_ISP 0x00000040 46 #define FM_FD_ERR_PHE 0x00000020 47 #define FM_FD_ERR_BLE 0x00000008 48 49 /* Common defines (Next Invoked Action) */ 50 #define NIA_ORDER_RESTORE 0x00800000 51 #define NIA_ENG_BMI 0x00500000 52 #define NIA_ENG_QMI_DEQ 0x00580000 53 #define NIA_ENG_QMI_ENQ 0x00540000 54 #define NIA_ENG_HWP 0x00440000 55 #define NIA_ENG_HWK 0x00480000 56 #define NIA_BMI_AC_TX_RELEASE 0x000002c0 57 #define NIA_BMI_AC_TX 0x00000274 58 #define NIA_BMI_AC_RELEASE 0x000000c0 59 #define NIA_BMI_AC_ENQ_FRAME 0x00000002 60 #define NIA_BMI_AC_FETCH_ALLFRAME 0x0000020c 61 62 /** 63 * FMan driver instance data. 64 */ 65 struct fman_softc { 66 struct simplebus_softc sc_base; 67 struct resource *mem_res; 68 struct resource *irq_res; 69 struct resource *err_irq_res; 70 struct rman rman; 71 vmem_t *muram_vmem; 72 int mem_rid; 73 int irq_rid; 74 int err_irq_rid; 75 void *irq_cookie; 76 int qman_chan_base; 77 int qman_chan_count; 78 int fm_id; 79 80 int sc_revision_major; 81 int sc_revision_minor; 82 83 uint16_t clock; 84 bool timestamps; 85 86 uint32_t iram_size; 87 uint32_t dma_thresh_max_commq; 88 uint32_t dma_thresh_max_buf; 89 uint32_t dma_cam_num_entries; 90 uint32_t max_open_dmas; 91 92 uint32_t qmi_max_tnums; 93 uint32_t qmi_def_tnums_thresh; 94 95 uint32_t bmi_max_tasks; 96 uint32_t bmi_max_fifo_size; 97 uint32_t bmi_fifo_base; 98 99 uint32_t port_cgs; 100 uint32_t rx_ports; 101 uint32_t total_fifo_size; 102 103 uint32_t qman_channel_base; 104 uint32_t qman_channels; 105 106 /* 107 * FMan KeyGen (Parse-Classify-Distribute) state. See 108 * fman_keygen.c. 32 KG schemes fit in a u32 bitmap; the 109 * port->scheme table is sized to the KG hardware limit of 110 * 64 possible port IDs. 111 */ 112 uint32_t sc_kg_schemes_used; 113 int8_t sc_kg_port_scheme[64]; 114 }; 115 116 struct fman_port_init_params { 117 int port_id; 118 bool is_rx_port; 119 uint8_t num_tasks; 120 uint8_t extra_tasks; 121 uint8_t open_dmas; 122 uint8_t extra_dmas; 123 uint32_t fifo_size; 124 uint32_t extra_fifo_size; 125 uint8_t deq_pipeline_size; 126 uint16_t max_frame_length; 127 uint16_t liodn; 128 }; 129 130 struct fman_parse_result { 131 uint8_t lpid; 132 uint8_t shimr; 133 uint16_t l2r; 134 uint16_t l3r; 135 uint8_t l4r; 136 uint8_t cpid; 137 uint16_t nxthdr; 138 uint16_t cksum; 139 uint32_t lcv; 140 uint8_t shim_off[2]; 141 uint8_t ip_pid_off; 142 uint8_t eth_off; 143 uint8_t llc_snap_off; 144 uint8_t vlan_tic_off[2]; 145 uint8_t last_e_type_off; 146 uint8_t pppoe_off; 147 uint8_t mpls_off[2]; 148 uint8_t ip_off[2]; 149 uint8_t gre_off; 150 uint8_t l4_off; 151 uint8_t nxthdr_off; 152 }; 153 154 struct fman_internal_context { 155 struct fman_parse_result prs; 156 uint64_t timestamp; 157 uint64_t hash; 158 }; 159 160 /** 161 * @group FMan bus interface. 162 * @{ 163 */ 164 struct resource *fman_alloc_resource(device_t bus, device_t child, int type, 165 int rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags); 166 int fman_activate_resource(device_t bus, device_t child, 167 struct resource *res); 168 int fman_release_resource(device_t bus, device_t child, struct resource *res); 169 int fman_attach(device_t dev); 170 int fman_detach(device_t dev); 171 int fman_suspend(device_t dev); 172 int fman_resume_dev(device_t dev); 173 int fman_shutdown(device_t dev); 174 int fman_read_ivar(device_t dev, device_t child, int index, 175 uintptr_t *result); 176 int fman_qman_channel_id(device_t, int); 177 void fman_get_revision(device_t, int *, int *); 178 /** @} */ 179 180 uint32_t fman_get_clock(struct fman_softc *sc); 181 int fman_get_bushandle(device_t dev, vm_offset_t *fm_base); 182 size_t fman_get_bmi_max_fifo_size(device_t); 183 int fman_reset_mac(device_t, int); 184 int fman_set_port_params(device_t dev, struct fman_port_init_params *params); 185 int fman_qman_channel_id(device_t, int); 186 int fman_set_mac_intr_handler(device_t, int, driver_intr_t, void *); 187 int fman_set_mac_err_handler(device_t, int, driver_intr_t, void *); 188 189 #endif /* FMAN_H_ */ 190