blob: 9d41bc2b1fd9206519171d86633dbbcb1d4919f3 (
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
|
/*
*
* 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_H_
#define _HAL_H_
#include <stdint.h>
#include "nsfw_hal_api.h"
#ifdef __cplusplus
/* *INDENT-OFF* */
extern "C" {
/* *INDENT-ON* */
#endif
#define HAL_DRV_MAX 32
#define HAL_MAX_PCI_ADDR_LEN 16
#define HAL_SCRIPT_LENGTH 256
#define HAL_HDL_TO_ID(hdl) (hdl.id)
extern netif_inst_t netif_tbl[HAL_MAX_NIC_NUM];
static inline netif_inst_t *alloc_netif_inst()
{
int i;
netif_inst_t *inst;
for (i = 0; i < HAL_MAX_NIC_NUM; ++i)
{
inst = &netif_tbl[i];
if (NETIF_STATE_FREE == inst->state)
{
inst->state = NETIF_STATE_ACTIVE;
inst->hdl.id = i;
return inst;
}
}
return NULL;
}
static inline netif_inst_t *get_netif_inst(hal_hdl_t hdl)
{
netif_inst_t *inst;
if (unlikely(!hal_is_valid(hdl)))
{
NSHAL_LOGERR("inst id is not valid]inst=%i, HAL_MAX_NIC_NUM=%d",
HAL_HDL_TO_ID(hdl), HAL_MAX_NIC_NUM);
return NULL;
}
inst = &netif_tbl[HAL_HDL_TO_ID(hdl)];
if (unlikely((NETIF_STATE_ACTIVE != inst->state) || (NULL == inst->ops)))
{
NSHAL_LOGERR("netif is not active]inst=%i", HAL_HDL_TO_ID(hdl));
return NULL;
}
return inst;
}
static inline netif_inst_t *get_netif_inst_by_name(const char *name)
{
int i;
netif_inst_t *inst;
if (!name)
{
return NULL;
}
for (i = 0; i < HAL_MAX_NIC_NUM; ++i)
{
inst = &netif_tbl[i];
if (NETIF_STATE_ACTIVE == inst->state
&& 0 == strncmp(name, inst->data.dpdk_if.nic_name,
HAL_MAX_NIC_NAME_LEN))
{
return inst;
}
}
return NULL;
}
#ifdef __cplusplus
/* *INDENT-OFF* */
}
/* *INDENT-ON* */
#endif
#endif
|