4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 /* \file lio_network.h
36 * \brief Host NIC Driver: Structure and Macro definitions used by NIC Module.
39 #ifndef __LIO_NETWORK_H__
40 #define __LIO_NETWORK_H__
44 #define LIO_MIN_MTU_SIZE 72
45 #define LIO_MAX_MTU_SIZE (LIO_MAX_FRM_SIZE - LIO_FRM_HEADER_SIZE)
48 #define LIO_MAX_FRAME_SIZE 60000
50 struct lio_fw_stats_resp {
52 struct octeon_link_stats stats;
56 /* LiquidIO per-interface network private data */
58 /* State of the interface. Rx/Tx happens only in the RUNNING state. */
62 * Octeon Interface index number. This device will be represented as
63 * oct<ifidx> in the system.
67 /* Octeon Input queue to use to transmit for this network interface. */
71 * Octeon Output queue from which pkts arrive
72 * for this network interface.
76 /* Guards each glist */
77 struct mtx *glist_lock;
79 #define LIO_DEFAULT_STATS_INTERVAL 10000
80 /* callout timer for stats */
81 struct callout stats_timer;
83 /* Stats Update Interval in milli Seconds */
84 uint16_t stats_interval;
86 /* IRQ coalescing driver stats */
87 struct octeon_intrmod_cfg intrmod_cfg;
89 /* Array of gather component linked lists */
90 struct lio_stailq_head *ghead;
91 void **glists_virt_base;
92 vm_paddr_t *glists_dma_base;
93 uint32_t glist_entry_size;
95 /* Pointer to the octeon device structure. */
96 struct octeon_device *oct_dev;
99 struct ifmedia ifmedia;
102 /* Link information sent by the core application for this interface. */
103 struct octeon_link_info linfo;
105 /* counter of link changes */
106 uint64_t link_changes;
108 /* Size of Tx queue for this octeon device. */
111 /* Size of Rx queue for this octeon device. */
114 /* Size of MTU this octeon device. */
117 /* msg level flag per interface. */
123 /* task queue for rx oom status */
124 struct lio_tq rx_status_tq;
126 /* VLAN Filtering related */
127 eventhandler_tag vlan_attach;
128 eventhandler_tag vlan_detach;
130 struct lio_rss_params_set rss_set;
134 #define LIO_MAX_CORES 12
137 * \brief Enable or disable feature
138 * @param ifp pointer to network device
139 * @param cmd Command that just requires acknowledgment
140 * @param param1 Parameter to command
142 int lio_set_feature(if_t ifp, int cmd, uint16_t param1);
145 * \brief Link control command completion callback
146 * @param nctrl_ptr pointer to control packet structure
148 * This routine is called by the callback function when a ctrl pkt sent to
149 * core app completes. The nctrl_ptr contains a copy of the command type
150 * and data sent to the core app. This routine is only called if the ctrl
151 * pkt was sent successfully to the core app.
153 void lio_ctrl_cmd_completion(void *nctrl_ptr);
155 int lio_setup_io_queues(struct octeon_device *octeon_dev, int ifidx,
156 uint32_t num_iqs, uint32_t num_oqs);
158 int lio_setup_interrupt(struct octeon_device *oct, uint32_t num_ioqs);
161 lio_recv_buffer_alloc(uint32_t size)
163 struct mbuf *mb = NULL;
165 mb = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, size);
167 mb->m_pkthdr.len = mb->m_len = size;
173 lio_recv_buffer_free(void *buffer)
176 m_freem((struct mbuf *)buffer);
180 lio_get_order(unsigned long size)
184 size = (size - 1) >> PAGE_SHIFT;
195 lio_dma_alloc(size_t size, vm_paddr_t *dma_handle)
200 align = PAGE_SIZE << lio_get_order(size);
201 mem = kmem_alloc_contig(size, M_WAITOK, 0, ~0ul, align, 0,
204 *dma_handle = vtophys(mem);
212 lio_dma_free(size_t size, void *cpu_addr)
215 kmem_free(cpu_addr, size);
218 static inline uint64_t
219 lio_map_ring(device_t dev, void *buf, uint32_t size)
223 dma_addr = vtophys(((struct mbuf *)buf)->m_data);
224 return ((uint64_t)dma_addr);
228 * \brief check interface state
229 * @param lio per-network private data
230 * @param state_flag flag state to check
233 lio_ifstate_check(struct lio *lio, int state_flag)
236 return (atomic_load_acq_int(&lio->ifstate) & state_flag);
240 * \brief set interface state
241 * @param lio per-network private data
242 * @param state_flag flag state to set
245 lio_ifstate_set(struct lio *lio, int state_flag)
248 atomic_store_rel_int(&lio->ifstate,
249 (atomic_load_acq_int(&lio->ifstate) | state_flag));
253 * \brief clear interface state
254 * @param lio per-network private data
255 * @param state_flag flag state to clear
258 lio_ifstate_reset(struct lio *lio, int state_flag)
261 atomic_store_rel_int(&lio->ifstate,
262 (atomic_load_acq_int(&lio->ifstate) &
267 * \brief wait for all pending requests to complete
268 * @param oct Pointer to Octeon device
270 * Called during shutdown sequence
273 lio_wait_for_pending_requests(struct octeon_device *oct)
277 for (i = 0; i < 100; i++) {
278 pcount = atomic_load_acq_int(
279 &oct->response_list[LIO_ORDERED_SC_LIST].
282 lio_sleep_timeout(100);
293 #endif /* __LIO_NETWORK_H__ */