blob: 11e27b84f59d0d0a185b235d1d36872433956cd0 [file] [log] [blame]
/*
<:copyright-BRCM:2016:DUAL/GPL:standard
Broadcom Proprietary and Confidential.(c) 2016 Broadcom
All Rights Reserved
Unless you and Broadcom execute a separate written software license
agreement governing use of this software, this software is licensed
to you under the terms of the GNU General Public License version 2
(the "GPL"), available at http://www.broadcom.com/licenses/GPLv2.php,
with the following added to such license:
As a special exception, the copyright holders of this software give
you permission to link this software with independent modules, and
to copy and distribute the resulting executable under terms of your
choice, provided that you also meet, for each linked independent
module, the terms and conditions of the license of that module.
An independent module is a module which is not derived from this
software. The special exception does not apply to any modifications
of the software.
Not withstanding the above, under no circumstances may you combine
this software in any way with any other Broadcom software provided
under a license other than the GPL, without Broadcom's express prior
written consent.
:>
*/
#ifndef BCMTR_PCIE_H_
#define BCMTR_PCIE_H_
#include "bcmos_system.h"
#define DDR_PACKET_LOW_INDEX 0
#define DDR_PACKET_HIGH_INDEX 7
#define PCI_PACKET_LOW_INDEX 1
#define PCI_PACKET_HIGH_INDEX 2
typedef struct
{
uint32_t rx_counter;
uint32_t tx_counter;
uint32_t rx_done_isr_counter;
uint32_t rx_err_isr_counter;
uint32_t tx_done_isr_counter;
uint32_t tx_err_isr_counter;
uint32_t rx_pcie_empty_counter;
uint32_t tx_pcie_full_counter;
} bcm_pcied_stat;
typedef struct
{
unsigned long pcie_reg_base;
uint32_t rx_irq;
uint32_t device;
uint32_t rx_done_num;
uint32_t rx_err_num;
uint32_t tx_done_num;
uint32_t tx_err_num;
} bcm_pcied_isr_data;
/** Initialize PCIe low level transport module
* \returns: 0 in case of success or error code < 0
*/
#ifdef IN_BAND
bcmos_errno bcmtr_pcie_init(uint8_t device, bcmos_ipv4_address ip_address, uint16_t udp_port);
#else
bcmos_errno bcmtr_pcie_init(uint8_t max_devices);
#endif
/** Cleanup PCIe low level transport module
* \returns: 0 in case of success or error code < 0
*/
void bcmtr_pcie_exit(void);
/** PCIe pre-connect configuration parameters */
typedef struct
{
uint32_t txq_size; /**< Transmit queue size */
uint32_t rxq_size; /**< Receive queue size */
uint32_t max_mtu; /**< Max MTU size */
uint32_t rx_irq; /**< Rx interrupt number */
unsigned long pcie_reg_base; /**< Maple PCIe register block address in host addrss space */
unsigned long ddr_win_base; /**< Maple DDR address in host addrss space */
} bcmtr_pcie_pre_connect_cfg;
/** PCIe pre-connect data - information returned by bcmtr_pcie_pre_connect().
* Device control driver should store data from this structure
* in the boot record in Maple SRAM
*/
typedef struct bcmtr_pcie_opaque_data bcmtr_pcie_opaque_data;
/** Prepare to connect
* On Maple returns into opaque_data pointers of the
* transmit and receive PacketDescriptors
* On Host opaque_data is NULL
* \param[in] device Maple device index
* \param[in] cfg Connection configuration
* \param[out] opaque_data Pointer to memory block
* where pcie driver put opaque data to be conveyed to the
* other side
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_pre_connect(uint8_t device, const bcmtr_pcie_pre_connect_cfg *cfg,
bcmtr_pcie_opaque_data *data);
/** Connect
* On Maple opaque_data is NULL
* On Host opaque_data contains the pointers to PDs in
* Maple
* \param[in] device Maple device index
* \param[in] opaque_data Pointer to opaque data block
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_connect(uint8_t device, const bcmtr_pcie_opaque_data *data);
/** Disconnect. All buffers are released
* \param[in] device Maple device index
* \param[in] opaque_data Pointer to opaque data block
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_disconnect(uint8_t device);
/*
* Receive callback registration.
* Attention PCIe driver implementer!!
* Received packets must stay in the queue until receive callback is registered.
*/
/** PCIe interface interrupt receive callback */
typedef void (*f_bcmtr_int)(uint8_t device);
/** Register receive callback
* \param[in] rx_isr Interrupt Receive callback
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_rx_irq_cblk_register(f_bcmtr_int user_rx_isr_clbk);
/** Unregister receive callback.
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_rx_irq_cblk_unregister(void);
/** Register transmit completion interrupt callback
* \param[in] tx_isr Transfer completed interrupt callback
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_tx_irq_cblk_register(f_bcmtr_int user_tx_isr_clbk);
/** Unregister transmit completed interrupt callback.
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_tx_irq_cblk_unregister(void);
/** Tx done callback */
typedef void (*f_bcmtr_done)(uint8_t device, bcmos_buf *buf);
/** Register buffer transmit completion callback
* \param[in] tx_done Transfer completed callback
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_tx_done_cblk_register(f_bcmtr_done tx_done_cb);
/** Unregister buffer transmit completion callback
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_tx_done_cblk_unregister(void);
/** Send buffer to the peer
* \param[in] device Maple device index
* \param[in] channel Channel id (opaque to the bcmtr_pcie driver)
* \param[in] buf Buffer to be transferred
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_send(uint8_t device, uint8_t channel, bcmos_buf *buf);
/** Reclaim buffers that have already been transmitted
* \param[in] device Maple device index
* \returns: number of reclaimed TX buffers >= 0 or bcmos_errno error code <0
*/
int bcmtr_pcie_tx_collect(uint8_t device);
/** Fetch received buffer from h/w queue
* \param[in] device Maple device index
* \param[out] channel message channel from the BD
* \param[out] buf pointer to network buffer containing the received packet
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_receive(uint8_t device, uint8_t *channel, bcmos_buf **buf);
/** Enable DMA_RX interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_rxint_enable(uint8_t device);
/** Disable DMA_RX interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_rxint_disable(uint8_t device);
/** Clear DMA_RX interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_rxint_clear(uint8_t device);
/** Enable "TX handled" interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_txint_enable(uint8_t device);
/** Disable "TX handled" interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_txint_disable(uint8_t device);
/** Clear "TX handled" interrupt
* \param[in] device Maple device index
* \returns: 0 in case of success or error code < 0
*/
bcmos_errno bcmtr_pcie_txint_clear(uint8_t device);
/** Returns statistics
* \param[in] device Maple device index
* \param[in] clear if set, clear statistics, otherwise
* accumulate
*/
bcmos_errno bcmtr_pcie_get_statistics(uint8_t device, uint32_t clear, bcm_pcied_stat *stat);
/** Dump data base
* \param[in] output NULL(will print to stdout) or pointer to
* buffer
* \param[in] device Maple device index
* \param[in] start index of the start entry in ring, -1
* means current
* \param[in] number_of_entries how many entries from the
* start
* \returns: 0 if output is NULL or buffer length
*/
bcmos_errno bcmtr_pcie_tx_dump(char *output, uint8_t device, int32_t start, int32_t number_of_entries);
bcmos_errno bcmtr_pcie_rx_dump(char *output, uint8_t device, int32_t start, int32_t number_of_entries);
#endif /* BCMTR_PCIE_H_ */