aboutsummaryrefslogtreecommitdiffstats
path: root/src/framework/include/hal_api.h
blob: a5d7725c93a00261244ac1707596e1a7ac094444 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
/*
*
* Copyright (c) 2018 Huawei Technologies Co.,Ltd.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at:
*
*     http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

#ifndef _HAL_API_H_
#define _HAL_API_H_

#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif

typedef void hal_mempool_t;
typedef void hal_mbuf_t;

#define HAL_ETH_MAX_QUEUE_NUM    4

#define HAL_ETH_QUEUE_STAT_CNTRS 16

#define HAL_MAX_NIC_NUM 4096
COMPAT_PROTECT (HAL_MAX_NIC_NUM, 4096);

#define HAL_MAX_SLAVES_PER_BOND 2

#define HAL_MAX_NIC_NAME_LEN 256

/**
 * TX offload capabilities of a device.
 */
#define HAL_ETH_TX_OFFLOAD_IPV4_CKSUM  0x00000002
#define HAL_ETH_TX_OFFLOAD_UDP_CKSUM   0x00000004
#define HAL_ETH_TX_OFFLOAD_TCP_CKSUM   0x00000008

/**
 * Hal Instance Handler
 */
typedef struct hal_hdl
{
  int id;
} hal_hdl_t;

/**
 * Ethernet device capability
 */
typedef struct hal_netif_capa
{
  uint32_t tx_offload_capa;   /**< Device TX offload capabilities. */
} hal_netif_capa_t;

/**
 * A structure used to retrieve statistics for an Ethernet port.
 */
typedef struct hal_netif_stats
{
  uint64_t ipackets;    /**< Total no.of packets that are successfully received . */
  uint64_t opackets;    /**< Total no.of packets that are successfully transmitted .*/
  uint64_t ibytes;    /**< Total no.of bytes that are successfully received . */
  uint64_t obytes;    /**< Total no.of bytes that are successfully transmitted . */
  uint64_t imissed;    /**< Total no.of RX packets that are dropped by the HW. */
  uint64_t ierrors;    /**< Total no.of packets that are received as erroneous. */
  uint64_t oerrors;    /**< Total no.of failed transmitted packets. */
  uint64_t rx_nombuf;    /**< Total no.of RX mbuf allocation failures. */

  uint64_t q_ipackets[HAL_ETH_QUEUE_STAT_CNTRS];   /**< Total no.of queue RX packets. */
  uint64_t q_opackets[HAL_ETH_QUEUE_STAT_CNTRS];   /**< Total no.of queue TX packets. */
  uint64_t q_ibytes[HAL_ETH_QUEUE_STAT_CNTRS];       /**< Total no.of successfully received queue bytes. */
  uint64_t q_obytes[HAL_ETH_QUEUE_STAT_CNTRS];       /**< Total no.of successfully transmitted queue bytes. */
  uint64_t q_errors[HAL_ETH_QUEUE_STAT_CNTRS];       /**< Total no.of queue packets received that are dropped. */
} hal_netif_stats_t;

/**
 * Ethernet device config
 */
typedef struct hal_netif_config
{
  struct
  {
    uint32_t hw_vlan_filter:1;
    uint32_t hw_vlan_strip:1;
    uint32_t rsv30:30;
  } bit;

  struct
  {
    uint32_t queue_num;
    uint32_t ring_size[HAL_ETH_MAX_QUEUE_NUM];
    hal_mempool_t *ring_pool[HAL_ETH_MAX_QUEUE_NUM];
  } rx;

  struct
  {
    uint32_t queue_num;
    uint32_t ring_size[HAL_ETH_MAX_QUEUE_NUM];
  } tx;

} hal_netif_config_t;

int hal_init_global (int argc, char **argv);
int hal_init_local ();
hal_hdl_t hal_create (const char *name, const char *nic_type,
                      hal_netif_config_t * conf);
hal_hdl_t hal_bond (const char *bond_name, uint8_t slave_num,
                    hal_hdl_t slave_hdl[]);

#define hal_is_valid(hdl) ((hdl.id >= 0) && (hdl.id < HAL_MAX_NIC_NUM))

#define hal_is_equal(hdl_left, hdl_right) (hdl_left.id == hdl_right.id)

int hal_close (hal_hdl_t hdl);
int hal_stop (hal_hdl_t hdl);
uint32_t hal_get_mtu (hal_hdl_t hdl);
void hal_get_macaddr (hal_hdl_t hdl, void *mac_addr);
void hal_get_capability (hal_hdl_t hdl, hal_netif_capa_t * info);
uint16_t hal_recv_packet (hal_hdl_t hdl, uint16_t queue_id,
                          hal_mbuf_t ** rx_pkts, uint16_t nb_pkts);
uint16_t hal_send_packet (hal_hdl_t hdl, uint16_t queue_id,
                          hal_mbuf_t ** tx_pkts, uint16_t nb_pkts);
uint32_t hal_link_status (hal_hdl_t hdl);
int hal_stats (hal_hdl_t hdl, hal_netif_stats_t * stats);
void hal_stats_reset (hal_hdl_t hdl);
int hal_add_mcastaddr (hal_hdl_t hdl, void *mc_addr_set,
                       void *mc_addr, uint32_t nb_mc_addr);
int hal_del_mcastaddr (hal_hdl_t hdl, void *mc_addr_set,
                       void *mc_addr, uint32_t nb_mc_addr);
void hal_set_allmulti_mode (hal_hdl_t hdl, uint8_t enable);
uint32_t hal_is_nic_exist (const char *name);
hal_hdl_t hal_get_invalid_hdl ();

#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif

#endif