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.
34 /* \file lio_network.h
35 * \brief Host NIC Driver: Structure and Macro definitions used by NIC Module.
38 #ifndef __LIO_NETWORK_H__
39 #define __LIO_NETWORK_H__
43 #define LIO_MIN_MTU_SIZE 72
44 #define LIO_MAX_MTU_SIZE (LIO_MAX_FRM_SIZE - LIO_FRM_HEADER_SIZE)
47 #define LIO_MAX_FRAME_SIZE 60000
49 struct lio_fw_stats_resp {
51 struct octeon_link_stats stats;
55 /* LiquidIO per-interface network private data */
57 /* State of the interface. Rx/Tx happens only in the RUNNING state. */
61 * Octeon Interface index number. This device will be represented as
62 * oct<ifidx> in the system.
66 /* Octeon Input queue to use to transmit for this network interface. */
70 * Octeon Output queue from which pkts arrive
71 * for this network interface.
75 /* Guards each glist */
76 struct mtx *glist_lock;
78 #define LIO_DEFAULT_STATS_INTERVAL 10000
79 /* callout timer for stats */
80 struct callout stats_timer;
82 /* Stats Update Interval in milli Seconds */
83 uint16_t stats_interval;
85 /* IRQ coalescing driver stats */
86 struct octeon_intrmod_cfg intrmod_cfg;
88 /* Array of gather component linked lists */
89 struct lio_stailq_head *ghead;
90 void **glists_virt_base;
91 vm_paddr_t *glists_dma_base;
92 uint32_t glist_entry_size;
94 /* Pointer to the octeon device structure. */
95 struct octeon_device *oct_dev;
98 struct ifmedia ifmedia;
101 /* Link information sent by the core application for this interface. */
102 struct octeon_link_info linfo;
104 /* counter of link changes */
105 uint64_t link_changes;
107 /* Size of Tx queue for this octeon device. */
110 /* Size of Rx queue for this octeon device. */
113 /* Size of MTU this octeon device. */
116 /* msg level flag per interface. */
122 /* task queue for rx oom status */
123 struct lio_tq rx_status_tq;
125 /* VLAN Filtering related */
126 eventhandler_tag vlan_attach;
127 eventhandler_tag vlan_detach;
129 struct lio_rss_params_set rss_set;
133 #define LIO_MAX_CORES 12
136 * \brief Enable or disable feature
137 * @param ifp pointer to network device
138 * @param cmd Command that just requires acknowledgment
139 * @param param1 Parameter to command
141 int lio_set_feature(if_t ifp, int cmd, uint16_t param1);
144 * \brief Link control command completion callback
145 * @param nctrl_ptr pointer to control packet structure
147 * This routine is called by the callback function when a ctrl pkt sent to
148 * core app completes. The nctrl_ptr contains a copy of the command type
149 * and data sent to the core app. This routine is only called if the ctrl
150 * pkt was sent successfully to the core app.
152 void lio_ctrl_cmd_completion(void *nctrl_ptr);
154 int lio_setup_io_queues(struct octeon_device *octeon_dev, int ifidx,
155 uint32_t num_iqs, uint32_t num_oqs);
157 int lio_setup_interrupt(struct octeon_device *oct, uint32_t num_ioqs);
160 lio_recv_buffer_alloc(uint32_t size)
162 struct mbuf *mb = NULL;
164 mb = m_getjcl(M_NOWAIT, MT_DATA, M_PKTHDR, size);
166 mb->m_pkthdr.len = mb->m_len = size;
172 lio_recv_buffer_free(void *buffer)
175 m_freem((struct mbuf *)buffer);
179 lio_get_order(unsigned long size)
183 size = (size - 1) >> PAGE_SHIFT;
194 lio_dma_alloc(size_t size, vm_paddr_t *dma_handle)
199 align = PAGE_SIZE << lio_get_order(size);
200 mem = kmem_alloc_contig(size, M_WAITOK, 0, ~0ul, align, 0,
203 *dma_handle = vtophys(mem);
211 lio_dma_free(size_t size, void *cpu_addr)
214 kmem_free(cpu_addr, size);
217 static inline uint64_t
218 lio_map_ring(device_t dev, void *buf, uint32_t size)
222 dma_addr = vtophys(((struct mbuf *)buf)->m_data);
223 return ((uint64_t)dma_addr);
227 * \brief check interface state
228 * @param lio per-network private data
229 * @param state_flag flag state to check
232 lio_ifstate_check(struct lio *lio, int state_flag)
235 return (atomic_load_acq_int(&lio->ifstate) & state_flag);
239 * \brief set interface state
240 * @param lio per-network private data
241 * @param state_flag flag state to set
244 lio_ifstate_set(struct lio *lio, int state_flag)
247 atomic_store_rel_int(&lio->ifstate,
248 (atomic_load_acq_int(&lio->ifstate) | state_flag));
252 * \brief clear interface state
253 * @param lio per-network private data
254 * @param state_flag flag state to clear
257 lio_ifstate_reset(struct lio *lio, int state_flag)
260 atomic_store_rel_int(&lio->ifstate,
261 (atomic_load_acq_int(&lio->ifstate) &
266 * \brief wait for all pending requests to complete
267 * @param oct Pointer to Octeon device
269 * Called during shutdown sequence
272 lio_wait_for_pending_requests(struct octeon_device *oct)
276 for (i = 0; i < 100; i++) {
277 pcount = atomic_load_acq_int(
278 &oct->response_list[LIO_ORDERED_SC_LIST].
281 lio_sleep_timeout(100);
292 #endif /* __LIO_NETWORK_H__ */