summaryrefslogtreecommitdiff
path: root/sys/dev/liquidio/lio_main.h
blob: 9993bdc3ec0cc2c68f328ee56aa62c926a9f5099 (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
/*
 *   BSD LICENSE
 *
 *   Copyright(c) 2017 Cavium, Inc.. All rights reserved.
 *   All rights reserved.
 *
 *   Redistribution and use in source and binary forms, with or without
 *   modification, are permitted provided that the following conditions
 *   are met:
 *
 *     * Redistributions of source code must retain the above copyright
 *       notice, this list of conditions and the following disclaimer.
 *     * Redistributions in binary form must reproduce the above copyright
 *       notice, this list of conditions and the following disclaimer in
 *       the documentation and/or other materials provided with the
 *       distribution.
 *     * Neither the name of Cavium, Inc. nor the names of its
 *       contributors may be used to endorse or promote products derived
 *       from this software without specific prior written permission.
 *
 *   THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 *   "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 *   LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 *   A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 *   OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 *   SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 *   LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 *   DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 *   THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 *   (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 *   OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 */

/*
 *  \file lio_main.h
 *  \brief Host Driver: This file is included by all host driver source files
 *  to include common definitions.
 */

#ifndef _LIO_MAIN_H_
#define  _LIO_MAIN_H_

extern unsigned int    lio_hwlro;

#define LIO_CAST64(v)	((long long)(long)(v))

#define LIO_DRV_NAME	"lio"

/** Swap 8B blocks */
static inline void
lio_swap_8B_data(uint64_t *data, uint32_t blocks)
{

	while (blocks) {
		*data = htobe64(*data);
		blocks--;
		data++;
	}
}

/*
 * \brief unmaps a PCI BAR
 * @param oct Pointer to Octeon device
 * @param baridx bar index
 */
static inline void
lio_unmap_pci_barx(struct octeon_device *oct, int baridx)
{

	lio_dev_dbg(oct, "Freeing PCI mapped regions for Bar%d\n", baridx);

	if (oct->mem_bus_space[baridx].pci_mem != NULL) {
		bus_release_resource(oct->device, SYS_RES_MEMORY,
				     PCIR_BAR(baridx * 2),
				     oct->mem_bus_space[baridx].pci_mem);
		oct->mem_bus_space[baridx].pci_mem = NULL;
	}
}

/*
 * \brief maps a PCI BAR
 * @param oct Pointer to Octeon device
 * @param baridx bar index
 */
static inline int
lio_map_pci_barx(struct octeon_device *oct, int baridx)
{
	int	rid = PCIR_BAR(baridx * 2);

	oct->mem_bus_space[baridx].pci_mem =
		bus_alloc_resource_any(oct->device, SYS_RES_MEMORY, &rid,
				       RF_ACTIVE);

	if (oct->mem_bus_space[baridx].pci_mem == NULL) {
		lio_dev_err(oct, "Unable to allocate bus resource: memory\n");
		return (ENXIO);
	}

	/* Save bus_space values for READ/WRITE_REG macros */
	oct->mem_bus_space[baridx].tag =
		rman_get_bustag(oct->mem_bus_space[baridx].pci_mem);
	oct->mem_bus_space[baridx].handle =
		rman_get_bushandle(oct->mem_bus_space[baridx].pci_mem);

	lio_dev_dbg(oct, "BAR%d Tag 0x%llx Handle 0x%llx\n",
		    baridx, LIO_CAST64(oct->mem_bus_space[baridx].tag),
		    LIO_CAST64(oct->mem_bus_space[baridx].handle));

	return (0);
}

static inline void
lio_sleep_cond(struct octeon_device *oct, volatile int *condition)
{

	while (!(*condition)) {
		lio_mdelay(1);
		lio_flush_iq(oct, oct->instr_queue[0], 0);
		lio_process_ordered_list(oct, 0);
	}
}

int	lio_console_debug_enabled(uint32_t console);

#ifndef ROUNDUP4
#define ROUNDUP4(val)	(((val) + 3) & 0xfffffffc)
#endif

#ifndef ROUNDUP8
#define ROUNDUP8(val)	(((val) + 7) & 0xfffffff8)
#endif

#define BIT_ULL(nr)	(1ULL << (nr))

void	lio_free_mbuf(struct lio_instr_queue *iq,
		      struct lio_mbuf_free_info *finfo);
void	lio_free_sgmbuf(struct lio_instr_queue *iq,
			struct lio_mbuf_free_info *finfo);

#endif	/* _LIO_MAIN_H_ */