Commit | Line | Data |
---|---|---|
f21fb3ed RV |
1 | /********************************************************************** |
2 | * Author: Cavium, Inc. | |
3 | * | |
4 | * Contact: support@cavium.com | |
5 | * Please include "LiquidIO" in the subject. | |
6 | * | |
7 | * Copyright (c) 2003-2015 Cavium, Inc. | |
8 | * | |
9 | * This file is free software; you can redistribute it and/or modify | |
10 | * it under the terms of the GNU General Public License, Version 2, as | |
11 | * published by the Free Software Foundation. | |
12 | * | |
13 | * This file is distributed in the hope that it will be useful, but | |
14 | * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty | |
15 | * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or | |
16 | * NONINFRINGEMENT. See the GNU General Public License for more | |
17 | * details. | |
18 | * | |
19 | * This file may also be available under a different license from Cavium. | |
20 | * Contact Cavium, Inc. for more information | |
21 | **********************************************************************/ | |
22 | ||
23 | /*! \file octeon_nic.h | |
24 | * \brief Host NIC Driver: Routine to send network data & | |
25 | * control packet to Octeon. | |
26 | */ | |
27 | ||
28 | #ifndef __OCTEON_NIC_H__ | |
29 | #define __OCTEON_NIC_H__ | |
30 | ||
31 | /* Maximum number of 8-byte words can be sent in a NIC control message. | |
32 | */ | |
33 | #define MAX_NCTRL_UDD 32 | |
34 | ||
35 | typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *); | |
36 | ||
37 | /* Structure of control information passed by the NIC module to the OSI | |
38 | * layer when sending control commands to Octeon device software. | |
39 | */ | |
40 | struct octnic_ctrl_pkt { | |
41 | /** Command to be passed to the Octeon device software. */ | |
42 | union octnet_cmd ncmd; | |
43 | ||
44 | /** Send buffer */ | |
45 | void *data; | |
46 | u64 dmadata; | |
47 | ||
48 | /** Response buffer */ | |
49 | void *rdata; | |
50 | u64 dmardata; | |
51 | ||
52 | /** Additional data that may be needed by some commands. */ | |
53 | u64 udd[MAX_NCTRL_UDD]; | |
54 | ||
55 | /** Time to wait for Octeon software to respond to this control command. | |
56 | * If wait_time is 0, OSI assumes no response is expected. | |
57 | */ | |
58 | size_t wait_time; | |
59 | ||
60 | /** The network device that issued the control command. */ | |
61 | u64 netpndev; | |
62 | ||
63 | /** Callback function called when the command has been fetched */ | |
64 | octnic_ctrl_pkt_cb_fn_t cb_fn; | |
65 | }; | |
66 | ||
67 | #define MAX_UDD_SIZE(nctrl) (sizeof(nctrl->udd)) | |
68 | ||
69 | /** Structure of data information passed by the NIC module to the OSI | |
70 | * layer when forwarding data to Octeon device software. | |
71 | */ | |
72 | struct octnic_data_pkt { | |
73 | /** Pointer to information maintained by NIC module for this packet. The | |
74 | * OSI layer passes this as-is to the driver. | |
75 | */ | |
76 | void *buf; | |
77 | ||
78 | /** Type of buffer passed in "buf" above. */ | |
79 | u32 reqtype; | |
80 | ||
81 | /** Total data bytes to be transferred in this command. */ | |
82 | u32 datasize; | |
83 | ||
84 | /** Command to be passed to the Octeon device software. */ | |
85 | struct octeon_instr_64B cmd; | |
86 | ||
87 | /** Input queue to use to send this command. */ | |
88 | u32 q_no; | |
89 | ||
90 | }; | |
91 | ||
92 | /** Structure passed by NIC module to OSI layer to prepare a command to send | |
93 | * network data to Octeon. | |
94 | */ | |
95 | union octnic_cmd_setup { | |
96 | struct { | |
97 | u32 ifidx:8; | |
98 | u32 cksum_offset:7; | |
99 | u32 gather:1; | |
100 | u32 timestamp:1; | |
101 | u32 ipv4opts_ipv6exthdr:2; | |
102 | u32 ip_csum:1; | |
103 | u32 tnl_csum:1; | |
104 | ||
105 | u32 rsvd:11; | |
106 | union { | |
107 | u32 datasize; | |
108 | u32 gatherptrs; | |
109 | } u; | |
110 | } s; | |
111 | ||
112 | u64 u64; | |
113 | ||
114 | }; | |
115 | ||
116 | struct octnic_ctrl_params { | |
117 | u32 resp_order; | |
118 | }; | |
119 | ||
120 | static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no) | |
121 | { | |
122 | return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending) | |
123 | >= (oct->instr_queue[q_no]->max_count - 2)); | |
124 | } | |
125 | ||
126 | /** Utility function to prepare a 64B NIC instruction based on a setup command | |
127 | * @param cmd - pointer to instruction to be filled in. | |
128 | * @param setup - pointer to the setup structure | |
129 | * @param q_no - which queue for back pressure | |
130 | * | |
131 | * Assumes the cmd instruction is pre-allocated, but no fields are filled in. | |
132 | */ | |
133 | static inline void | |
134 | octnet_prepare_pci_cmd(struct octeon_instr_64B *cmd, | |
135 | union octnic_cmd_setup *setup, u32 tag) | |
136 | { | |
137 | struct octeon_instr_ih *ih; | |
138 | struct octeon_instr_irh *irh; | |
139 | union octnic_packet_params packet_params; | |
140 | ||
141 | memset(cmd, 0, sizeof(struct octeon_instr_64B)); | |
142 | ||
143 | ih = (struct octeon_instr_ih *)&cmd->ih; | |
144 | ||
145 | /* assume that rflag is cleared so therefore front data will only have | |
146 | * irh and ossp[1] and ossp[2] for a total of 24 bytes | |
147 | */ | |
148 | ih->fsz = 24; | |
149 | ||
150 | ih->tagtype = ORDERED_TAG; | |
151 | ih->grp = DEFAULT_POW_GRP; | |
152 | ||
153 | if (tag) | |
154 | ih->tag = tag; | |
155 | else | |
156 | ih->tag = LIO_DATA(setup->s.ifidx); | |
157 | ||
158 | ih->raw = 1; | |
159 | ih->qos = (setup->s.ifidx & 3) + 4; /* map qos based on interface */ | |
160 | ||
161 | if (!setup->s.gather) { | |
162 | ih->dlengsz = setup->s.u.datasize; | |
163 | } else { | |
164 | ih->gather = 1; | |
165 | ih->dlengsz = setup->s.u.gatherptrs; | |
166 | } | |
167 | ||
168 | irh = (struct octeon_instr_irh *)&cmd->irh; | |
169 | ||
170 | irh->opcode = OPCODE_NIC; | |
171 | irh->subcode = OPCODE_NIC_NW_DATA; | |
172 | ||
173 | packet_params.u32 = 0; | |
174 | ||
175 | if (setup->s.cksum_offset) { | |
176 | packet_params.s.csoffset = setup->s.cksum_offset; | |
177 | packet_params.s.ipv4opts_ipv6exthdr = | |
178 | setup->s.ipv4opts_ipv6exthdr; | |
179 | } | |
180 | ||
181 | packet_params.s.ip_csum = setup->s.ip_csum; | |
182 | packet_params.s.tnl_csum = setup->s.tnl_csum; | |
183 | packet_params.s.ifidx = setup->s.ifidx; | |
184 | packet_params.s.tsflag = setup->s.timestamp; | |
185 | ||
186 | irh->ossp = packet_params.u32; | |
187 | } | |
188 | ||
189 | /** Allocate and a soft command with space for a response immediately following | |
190 | * the commnad. | |
191 | * @param oct - octeon device pointer | |
192 | * @param cmd - pointer to the command structure, pre-filled for everything | |
193 | * except the response. | |
194 | * @param rdatasize - size in bytes of the response. | |
195 | * | |
196 | * @returns pointer to allocated buffer with command copied into it, and | |
197 | * response space immediately following. | |
198 | */ | |
199 | void * | |
200 | octeon_alloc_soft_command_resp(struct octeon_device *oct, | |
201 | struct octeon_instr_64B *cmd, | |
202 | size_t rdatasize); | |
203 | ||
204 | /** Send a NIC data packet to the device | |
205 | * @param oct - octeon device pointer | |
206 | * @param ndata - control structure with queueing, and buffer information | |
207 | * | |
208 | * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the | |
209 | * queue should be stopped, and IQ_SEND_OK if it sent okay. | |
210 | */ | |
211 | int octnet_send_nic_data_pkt(struct octeon_device *oct, | |
212 | struct octnic_data_pkt *ndata, u32 xmit_more); | |
213 | ||
214 | /** Send a NIC control packet to the device | |
215 | * @param oct - octeon device pointer | |
216 | * @param nctrl - control structure with command, timout, and callback info | |
217 | * @param nparams - response control structure | |
218 | * | |
219 | * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the | |
220 | * queue should be stopped, and IQ_SEND_OK if it sent okay. | |
221 | */ | |
222 | int | |
223 | octnet_send_nic_ctrl_pkt(struct octeon_device *oct, | |
224 | struct octnic_ctrl_pkt *nctrl, | |
225 | struct octnic_ctrl_params nparams); | |
226 | ||
227 | #endif |