Shad Ansari | 2f7f9be | 2017-06-07 13:34:53 -0700 | [diff] [blame^] | 1 | /* |
| 2 | <:copyright-BRCM:2016:DUAL/GPL:standard |
| 3 | |
| 4 | Broadcom Proprietary and Confidential.(c) 2016 Broadcom |
| 5 | All Rights Reserved |
| 6 | |
| 7 | Unless you and Broadcom execute a separate written software license |
| 8 | agreement governing use of this software, this software is licensed |
| 9 | to you under the terms of the GNU General Public License version 2 |
| 10 | (the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php, |
| 11 | with the following added to such license: |
| 12 | |
| 13 | As a special exception, the copyright holders of this software give |
| 14 | you permission to link this software with independent modules, and |
| 15 | to copy and distribute the resulting executable under terms of your |
| 16 | choice, provided that you also meet, for each linked independent |
| 17 | module, the terms and conditions of the license of that module. |
| 18 | An independent module is a module which is not derived from this |
| 19 | software. The special exception does not apply to any modifications |
| 20 | of the software. |
| 21 | |
| 22 | Not withstanding the above, under no circumstances may you combine |
| 23 | this software in any way with any other Broadcom software provided |
| 24 | under a license other than the GPL, without Broadcom's express prior |
| 25 | written consent. |
| 26 | |
| 27 | :> |
| 28 | */ |
| 29 | |
| 30 | #ifndef BCMTR_PCIE_H_ |
| 31 | #define BCMTR_PCIE_H_ |
| 32 | |
| 33 | #include "bcmos_system.h" |
| 34 | |
| 35 | #define DDR_PACKET_LOW_INDEX 0 |
| 36 | #define DDR_PACKET_HIGH_INDEX 7 |
| 37 | #define PCI_PACKET_LOW_INDEX 1 |
| 38 | #define PCI_PACKET_HIGH_INDEX 2 |
| 39 | |
| 40 | typedef struct |
| 41 | { |
| 42 | uint32_t rx_counter; |
| 43 | uint32_t tx_counter; |
| 44 | uint32_t rx_done_isr_counter; |
| 45 | uint32_t rx_err_isr_counter; |
| 46 | uint32_t tx_done_isr_counter; |
| 47 | uint32_t tx_err_isr_counter; |
| 48 | uint32_t rx_pcie_empty_counter; |
| 49 | uint32_t tx_pcie_full_counter; |
| 50 | } bcm_pcied_stat; |
| 51 | |
| 52 | typedef struct |
| 53 | { |
| 54 | unsigned long pcie_reg_base; |
| 55 | uint32_t rx_irq; |
| 56 | uint32_t device; |
| 57 | uint32_t rx_done_num; |
| 58 | uint32_t rx_err_num; |
| 59 | uint32_t tx_done_num; |
| 60 | uint32_t tx_err_num; |
| 61 | } bcm_pcied_isr_data; |
| 62 | |
| 63 | /** Initialize PCIe low level transport module |
| 64 | * \returns: 0 in case of success or error code < 0 |
| 65 | */ |
| 66 | #ifdef IN_BAND |
| 67 | bcmos_errno bcmtr_pcie_init(uint8_t device, bcmos_ipv4_address ip_address, uint16_t udp_port); |
| 68 | #else |
| 69 | bcmos_errno bcmtr_pcie_init(uint8_t max_devices); |
| 70 | #endif |
| 71 | |
| 72 | /** Cleanup PCIe low level transport module |
| 73 | * \returns: 0 in case of success or error code < 0 |
| 74 | */ |
| 75 | void bcmtr_pcie_exit(void); |
| 76 | |
| 77 | /** PCIe pre-connect configuration parameters */ |
| 78 | typedef struct |
| 79 | { |
| 80 | uint32_t txq_size; /**< Transmit queue size */ |
| 81 | uint32_t rxq_size; /**< Receive queue size */ |
| 82 | uint32_t max_mtu; /**< Max MTU size */ |
| 83 | uint32_t rx_irq; /**< Rx interrupt number */ |
| 84 | unsigned long pcie_reg_base; /**< Maple PCIe register block address in host addrss space */ |
| 85 | unsigned long ddr_win_base; /**< Maple DDR address in host addrss space */ |
| 86 | } bcmtr_pcie_pre_connect_cfg; |
| 87 | |
| 88 | /** PCIe pre-connect data - information returned by bcmtr_pcie_pre_connect(). |
| 89 | * Device control driver should store data from this structure |
| 90 | * in the boot record in Maple SRAM |
| 91 | */ |
| 92 | typedef struct bcmtr_pcie_opaque_data bcmtr_pcie_opaque_data; |
| 93 | |
| 94 | /** Prepare to connect |
| 95 | * On Maple returns into opaque_data pointers of the |
| 96 | * transmit and receive PacketDescriptors |
| 97 | * On Host opaque_data is NULL |
| 98 | * \param[in] device Maple device index |
| 99 | * \param[in] cfg Connection configuration |
| 100 | * \param[out] opaque_data Pointer to memory block |
| 101 | * where pcie driver put opaque data to be conveyed to the |
| 102 | * other side |
| 103 | * \returns: 0 in case of success or error code < 0 |
| 104 | */ |
| 105 | bcmos_errno bcmtr_pcie_pre_connect(uint8_t device, const bcmtr_pcie_pre_connect_cfg *cfg, |
| 106 | bcmtr_pcie_opaque_data *data); |
| 107 | |
| 108 | /** Connect |
| 109 | * On Maple opaque_data is NULL |
| 110 | * On Host opaque_data contains the pointers to PDs in |
| 111 | * Maple |
| 112 | * \param[in] device Maple device index |
| 113 | * \param[in] opaque_data Pointer to opaque data block |
| 114 | * \returns: 0 in case of success or error code < 0 |
| 115 | */ |
| 116 | bcmos_errno bcmtr_pcie_connect(uint8_t device, const bcmtr_pcie_opaque_data *data); |
| 117 | |
| 118 | /** Disconnect. All buffers are released |
| 119 | * \param[in] device Maple device index |
| 120 | * \param[in] opaque_data Pointer to opaque data block |
| 121 | * \returns: 0 in case of success or error code < 0 |
| 122 | */ |
| 123 | bcmos_errno bcmtr_pcie_disconnect(uint8_t device); |
| 124 | |
| 125 | /* |
| 126 | * Receive callback registration. |
| 127 | * Attention PCIe driver implementer!! |
| 128 | * Received packets must stay in the queue until receive callback is registered. |
| 129 | */ |
| 130 | |
| 131 | /** PCIe interface interrupt receive callback */ |
| 132 | typedef void (*f_bcmtr_int)(uint8_t device); |
| 133 | |
| 134 | /** Register receive callback |
| 135 | * \param[in] rx_isr Interrupt Receive callback |
| 136 | * \returns: 0 in case of success or error code < 0 |
| 137 | */ |
| 138 | bcmos_errno bcmtr_pcie_rx_irq_cblk_register(f_bcmtr_int user_rx_isr_clbk); |
| 139 | |
| 140 | /** Unregister receive callback. |
| 141 | * \returns: 0 in case of success or error code < 0 |
| 142 | */ |
| 143 | bcmos_errno bcmtr_pcie_rx_irq_cblk_unregister(void); |
| 144 | |
| 145 | /** Register transmit completion interrupt callback |
| 146 | * \param[in] tx_isr Transfer completed interrupt callback |
| 147 | * \returns: 0 in case of success or error code < 0 |
| 148 | */ |
| 149 | bcmos_errno bcmtr_pcie_tx_irq_cblk_register(f_bcmtr_int user_tx_isr_clbk); |
| 150 | |
| 151 | /** Unregister transmit completed interrupt callback. |
| 152 | * \returns: 0 in case of success or error code < 0 |
| 153 | */ |
| 154 | bcmos_errno bcmtr_pcie_tx_irq_cblk_unregister(void); |
| 155 | |
| 156 | /** Tx done callback */ |
| 157 | typedef void (*f_bcmtr_done)(uint8_t device, bcmos_buf *buf); |
| 158 | |
| 159 | /** Register buffer transmit completion callback |
| 160 | * \param[in] tx_done Transfer completed callback |
| 161 | * \returns: 0 in case of success or error code < 0 |
| 162 | */ |
| 163 | bcmos_errno bcmtr_pcie_tx_done_cblk_register(f_bcmtr_done tx_done_cb); |
| 164 | |
| 165 | /** Unregister buffer transmit completion callback |
| 166 | * \returns: 0 in case of success or error code < 0 |
| 167 | */ |
| 168 | bcmos_errno bcmtr_pcie_tx_done_cblk_unregister(void); |
| 169 | |
| 170 | /** Send buffer to the peer |
| 171 | * \param[in] device Maple device index |
| 172 | * \param[in] channel Channel id (opaque to the bcmtr_pcie driver) |
| 173 | * \param[in] buf Buffer to be transferred |
| 174 | * \returns: 0 in case of success or error code < 0 |
| 175 | */ |
| 176 | bcmos_errno bcmtr_pcie_send(uint8_t device, uint8_t channel, bcmos_buf *buf); |
| 177 | |
| 178 | /** Reclaim buffers that have already been transmitted |
| 179 | * \param[in] device Maple device index |
| 180 | * \returns: number of reclaimed TX buffers >= 0 or bcmos_errno error code <0 |
| 181 | */ |
| 182 | int bcmtr_pcie_tx_collect(uint8_t device); |
| 183 | |
| 184 | /** Fetch received buffer from h/w queue |
| 185 | * \param[in] device Maple device index |
| 186 | * \param[out] channel message channel from the BD |
| 187 | * \param[out] buf pointer to network buffer containing the received packet |
| 188 | * \returns: 0 in case of success or error code < 0 |
| 189 | */ |
| 190 | bcmos_errno bcmtr_pcie_receive(uint8_t device, uint8_t *channel, bcmos_buf **buf); |
| 191 | |
| 192 | /** Enable DMA_RX interrupt |
| 193 | * \param[in] device Maple device index |
| 194 | * \returns: 0 in case of success or error code < 0 |
| 195 | */ |
| 196 | bcmos_errno bcmtr_pcie_rxint_enable(uint8_t device); |
| 197 | |
| 198 | /** Disable DMA_RX interrupt |
| 199 | * \param[in] device Maple device index |
| 200 | * \returns: 0 in case of success or error code < 0 |
| 201 | */ |
| 202 | bcmos_errno bcmtr_pcie_rxint_disable(uint8_t device); |
| 203 | |
| 204 | /** Clear DMA_RX interrupt |
| 205 | * \param[in] device Maple device index |
| 206 | * \returns: 0 in case of success or error code < 0 |
| 207 | */ |
| 208 | bcmos_errno bcmtr_pcie_rxint_clear(uint8_t device); |
| 209 | |
| 210 | /** Enable "TX handled" interrupt |
| 211 | * \param[in] device Maple device index |
| 212 | * \returns: 0 in case of success or error code < 0 |
| 213 | */ |
| 214 | bcmos_errno bcmtr_pcie_txint_enable(uint8_t device); |
| 215 | |
| 216 | /** Disable "TX handled" interrupt |
| 217 | * \param[in] device Maple device index |
| 218 | * \returns: 0 in case of success or error code < 0 |
| 219 | */ |
| 220 | bcmos_errno bcmtr_pcie_txint_disable(uint8_t device); |
| 221 | |
| 222 | /** Clear "TX handled" interrupt |
| 223 | * \param[in] device Maple device index |
| 224 | * \returns: 0 in case of success or error code < 0 |
| 225 | */ |
| 226 | bcmos_errno bcmtr_pcie_txint_clear(uint8_t device); |
| 227 | |
| 228 | /** Returns statistics |
| 229 | * \param[in] device Maple device index |
| 230 | * \param[in] clear if set, clear statistics, otherwise |
| 231 | * accumulate |
| 232 | */ |
| 233 | bcmos_errno bcmtr_pcie_get_statistics(uint8_t device, uint32_t clear, bcm_pcied_stat *stat); |
| 234 | |
| 235 | /** Dump data base |
| 236 | * \param[in] output NULL(will print to stdout) or pointer to |
| 237 | * buffer |
| 238 | * \param[in] device Maple device index |
| 239 | * \param[in] start index of the start entry in ring, -1 |
| 240 | * means current |
| 241 | * \param[in] number_of_entries how many entries from the |
| 242 | * start |
| 243 | * \returns: 0 if output is NULL or buffer length |
| 244 | */ |
| 245 | bcmos_errno bcmtr_pcie_tx_dump(char *output, uint8_t device, int32_t start, int32_t number_of_entries); |
| 246 | bcmos_errno bcmtr_pcie_rx_dump(char *output, uint8_t device, int32_t start, int32_t number_of_entries); |
| 247 | |
| 248 | |
| 249 | #endif /* BCMTR_PCIE_H_ */ |