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.
36 * \brief Host NIC Driver: Routine to send network data &
37 * control packet to Octeon.
40 #ifndef __LIO_CTRL_H__
41 #define __LIO_CTRL_H__
43 /* Maximum number of 8-byte words can be sent in a NIC control message. */
44 #define LIO_MAX_NCTRL_UDD 32
46 typedef void (*lio_ctrl_pkt_cb_fn_t)(void *);
49 * Structure of control information passed by the NIC module to the OSI
50 * layer when sending control commands to Octeon device software.
53 /* Command to be passed to the Octeon device software. */
54 union octeon_cmd ncmd;
64 /* Additional data that may be needed by some commands. */
65 uint64_t udd[LIO_MAX_NCTRL_UDD];
67 /* Input queue to use to send this command. */
71 * Time to wait for Octeon software to respond to this control command.
72 * If wait_time is 0, OSI assumes no response is expected.
76 /* The network device that issued the control command. */
79 /* Callback function called when the command has been fetched */
80 lio_ctrl_pkt_cb_fn_t cb_fn;
84 * Structure of data information passed by the NIC module to the OSI
85 * layer when forwarding data to Octeon device software.
89 * Pointer to information maintained by NIC module for this packet. The
90 * OSI layer passes this as-is to the driver.
94 /* Type of buffer passed in "buf" above. */
97 /* Total data bytes to be transferred in this command. */
100 /* Command to be passed to the Octeon device software. */
101 union lio_instr_64B cmd;
103 /* Input queue to use to send this command. */
109 * Structure passed by NIC module to OSI layer to prepare a command to send
110 * network data to Octeon.
112 union lio_cmd_setup {
116 uint32_t timestamp:1;
118 uint32_t transport_csum:1;
128 uint64_t cmd_setup64;
133 lio_iq_is_full(struct octeon_device *oct, uint32_t q_no)
136 return (atomic_load_acq_int(&oct->instr_queue[q_no]->instr_pending) >=
137 (oct->instr_queue[q_no]->max_count - 2));
141 lio_prepare_pci_cmd_o3(struct octeon_device *oct, union lio_instr_64B *cmd,
142 union lio_cmd_setup *setup, uint32_t tag)
144 union octeon_packet_params packet_params;
145 struct octeon_instr_irh *irh;
146 struct octeon_instr_ih3 *ih3;
147 struct octeon_instr_pki_ih3 *pki_ih3;
150 bzero(cmd, sizeof(union lio_instr_64B));
152 ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
153 pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
156 * assume that rflag is cleared so therefore front data will only have
157 * irh and ossp[1] and ossp[2] for a total of 24 bytes
159 ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
161 ih3->fsz = LIO_PCICMD_O3;
163 if (!setup->s.gather) {
164 ih3->dlengsz = setup->s.u.datasize;
167 ih3->dlengsz = setup->s.u.gatherptrs;
174 pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
176 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
181 pki_ih3->tag = LIO_DATA(port);
183 pki_ih3->tagtype = LIO_ORDERED_TAG;
184 pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
185 pki_ih3->pm = 0x0; /* parse from L2 */
186 /* sl will be sizeof(pki_ih3) + irh + ossp0 + ossp1 */
189 irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
191 irh->opcode = LIO_OPCODE_NIC;
192 irh->subcode = LIO_OPCODE_NIC_NW_DATA;
194 packet_params.pkt_params32 = 0;
196 packet_params.s.ip_csum = setup->s.ip_csum;
197 packet_params.s.transport_csum = setup->s.transport_csum;
198 packet_params.s.tnl_csum = setup->s.tnl_csum;
199 packet_params.s.tsflag = setup->s.timestamp;
201 irh->ossp = packet_params.pkt_params32;
205 * Utility function to prepare a 64B NIC instruction based on a setup command
206 * @param oct - Pointer to current octeon device
207 * @param cmd - pointer to instruction to be filled in.
208 * @param setup - pointer to the setup structure
209 * @param q_no - which queue for back pressure
211 * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
214 lio_prepare_pci_cmd(struct octeon_device *oct, union lio_instr_64B *cmd,
215 union lio_cmd_setup *setup, uint32_t tag)
218 lio_prepare_pci_cmd_o3(oct, cmd, setup, tag);
222 * Send a NIC data packet to the device
223 * @param oct - octeon device pointer
224 * @param ndata - control structure with queueing, and buffer information
226 * @returns LIO_IQ_FAILED if it failed to add to the input queue.
227 * LIO_IQ_STOP if it the queue should be stopped,
228 * and LIO_IQ_SEND_OK if it sent okay.
230 int lio_send_data_pkt(struct octeon_device *oct,
231 struct lio_data_pkt *ndata);
234 * Send a NIC control packet to the device
235 * @param oct - octeon device pointer
236 * @param nctrl - control structure with command, timeout, and callback info
237 * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
238 * queue should be stopped, and LIO_IQ_SEND_OK if it sent okay.
240 int lio_send_ctrl_pkt(struct octeon_device *oct,
241 struct lio_ctrl_pkt *nctrl);
243 #endif /* __LIO_CTRL_H__ */