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 /** 50 * FMan driver instance data. 51 */ 52 struct fman_softc { 53 struct simplebus_softc sc_base; 54 struct resource *mem_res; 55 struct resource *irq_res; 56 struct resource *err_irq_res; 57 struct rman rman; 58 vmem_t *muram_vmem; 59 int mem_rid; 60 int irq_rid; 61 int err_irq_rid; 62 void *irq_cookie; 63 int qman_chan_base; 64 int qman_chan_count; 65 int fm_id; 66 67 int sc_revision_major; 68 int sc_revision_minor; 69 70 uint16_t clock; 71 bool timestamps; 72 73 uint32_t iram_size; 74 uint32_t dma_thresh_max_commq; 75 uint32_t dma_thresh_max_buf; 76 uint32_t dma_cam_num_entries; 77 uint32_t max_open_dmas; 78 79 uint32_t qmi_max_tnums; 80 uint32_t qmi_def_tnums_thresh; 81 82 uint32_t bmi_max_tasks; 83 uint32_t bmi_max_fifo_size; 84 uint32_t bmi_fifo_base; 85 86 uint32_t port_cgs; 87 uint32_t rx_ports; 88 uint32_t total_fifo_size; 89 90 uint32_t qman_channel_base; 91 uint32_t qman_channels; 92 }; 93 94 struct fman_port_init_params { 95 int port_id; 96 bool is_rx_port; 97 uint8_t num_tasks; 98 uint8_t extra_tasks; 99 uint8_t open_dmas; 100 uint8_t extra_dmas; 101 uint32_t fifo_size; 102 uint32_t extra_fifo_size; 103 uint8_t deq_pipeline_size; 104 uint16_t max_frame_length; 105 uint16_t liodn; 106 }; 107 108 struct fman_parse_result { 109 uint8_t lpid; 110 uint8_t shimr; 111 uint16_t l2r; 112 uint16_t l3r; 113 uint8_t l4r; 114 uint8_t cpid; 115 uint16_t nxthdr; 116 uint16_t cksum; 117 uint32_t lcv; 118 uint8_t shim_off[2]; 119 uint8_t ip_pid_off; 120 uint8_t eth_off; 121 uint8_t llc_snap_off; 122 uint8_t vlan_tic_off[2]; 123 uint8_t last_e_type_off; 124 uint8_t pppoe_off; 125 uint8_t mpls_off[2]; 126 uint8_t ip_off[2]; 127 uint8_t gre_off; 128 uint8_t l4_off; 129 uint8_t nxthdr_off; 130 }; 131 132 struct fman_internal_context { 133 struct fman_parse_result prs; 134 uint64_t timestamp; 135 uint64_t hash; 136 }; 137 138 /** 139 * @group FMan bus interface. 140 * @{ 141 */ 142 struct resource *fman_alloc_resource(device_t bus, device_t child, int type, 143 int rid, rman_res_t start, rman_res_t end, rman_res_t count, u_int flags); 144 int fman_activate_resource(device_t bus, device_t child, 145 struct resource *res); 146 int fman_release_resource(device_t bus, device_t child, struct resource *res); 147 int fman_attach(device_t dev); 148 int fman_detach(device_t dev); 149 int fman_suspend(device_t dev); 150 int fman_resume_dev(device_t dev); 151 int fman_shutdown(device_t dev); 152 int fman_read_ivar(device_t dev, device_t child, int index, 153 uintptr_t *result); 154 int fman_qman_channel_id(device_t, int); 155 void fman_get_revision(device_t, int *, int *); 156 /** @} */ 157 158 uint32_t fman_get_clock(struct fman_softc *sc); 159 int fman_get_bushandle(device_t dev, vm_offset_t *fm_base); 160 size_t fman_get_bmi_max_fifo_size(device_t); 161 int fman_reset_mac(device_t, int); 162 int fman_set_port_params(device_t dev, struct fman_port_init_params *params); 163 int fman_qman_channel_id(device_t, int); 164 int fman_set_mac_intr_handler(device_t, int, driver_intr_t, void *); 165 int fman_set_mac_err_handler(device_t, int, driver_intr_t, void *); 166 167 #endif /* FMAN_H_ */ 168