Linux 4.19.133
[linux/fpc-iii.git] / drivers / net / ethernet / cavium / liquidio / octeon_nic.h
blobde4130d26a988ca113dd0bef751dd2808b8afc17
1 /**********************************************************************
2 * Author: Cavium, Inc.
4 * Contact: support@cavium.com
5 * Please include "LiquidIO" in the subject.
7 * Copyright (c) 2003-2016 Cavium, Inc.
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.
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 **********************************************************************/
20 /*! \file octeon_nic.h
21 * \brief Host NIC Driver: Routine to send network data &
22 * control packet to Octeon.
25 #ifndef __OCTEON_NIC_H__
26 #define __OCTEON_NIC_H__
28 /* Maximum number of 8-byte words can be sent in a NIC control message.
30 #define MAX_NCTRL_UDD 32
32 typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *);
34 /* Structure of control information passed by the NIC module to the OSI
35 * layer when sending control commands to Octeon device software.
37 struct octnic_ctrl_pkt {
38 /** Command to be passed to the Octeon device software. */
39 union octnet_cmd ncmd;
41 /** Send buffer */
42 void *data;
43 u64 dmadata;
45 /** Response buffer */
46 void *rdata;
47 u64 dmardata;
49 /** Additional data that may be needed by some commands. */
50 u64 udd[MAX_NCTRL_UDD];
52 /** Input queue to use to send this command. */
53 u64 iq_no;
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.
58 size_t wait_time;
60 /** The network device that issued the control command. */
61 u64 netpndev;
63 /** Callback function called when the command has been fetched */
64 octnic_ctrl_pkt_cb_fn_t cb_fn;
66 u32 status;
67 u16 *response_code;
68 struct completion *completion;
71 #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
73 /** Structure of data information passed by the NIC module to the OSI
74 * layer when forwarding data to Octeon device software.
76 struct octnic_data_pkt {
77 /** Pointer to information maintained by NIC module for this packet. The
78 * OSI layer passes this as-is to the driver.
80 void *buf;
82 /** Type of buffer passed in "buf" above. */
83 u32 reqtype;
85 /** Total data bytes to be transferred in this command. */
86 u32 datasize;
88 /** Command to be passed to the Octeon device software. */
89 union octeon_instr_64B cmd;
91 /** Input queue to use to send this command. */
92 u32 q_no;
96 /** Structure passed by NIC module to OSI layer to prepare a command to send
97 * network data to Octeon.
99 union octnic_cmd_setup {
100 struct {
101 u32 iq_no:8;
102 u32 gather:1;
103 u32 timestamp:1;
104 u32 ip_csum:1;
105 u32 transport_csum:1;
106 u32 tnl_csum:1;
107 u32 rsvd:19;
109 union {
110 u32 datasize;
111 u32 gatherptrs;
112 } u;
113 } s;
115 u64 u64;
119 static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
121 return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
122 >= (oct->instr_queue[q_no]->max_count - 2));
125 static inline void
126 octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
127 union octeon_instr_64B *cmd,
128 union octnic_cmd_setup *setup, u32 tag)
130 struct octeon_instr_ih2 *ih2;
131 struct octeon_instr_irh *irh;
132 union octnic_packet_params packet_params;
133 int port;
135 memset(cmd, 0, sizeof(union octeon_instr_64B));
137 ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
139 /* assume that rflag is cleared so therefore front data will only have
140 * irh and ossp[0], ossp[1] for a total of 32 bytes
142 ih2->fsz = LIO_PCICMD_O2;
144 ih2->tagtype = ORDERED_TAG;
145 ih2->grp = DEFAULT_POW_GRP;
147 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
149 if (tag)
150 ih2->tag = tag;
151 else
152 ih2->tag = LIO_DATA(port);
154 ih2->raw = 1;
155 ih2->qos = (port & 3) + 4; /* map qos based on interface */
157 if (!setup->s.gather) {
158 ih2->dlengsz = setup->s.u.datasize;
159 } else {
160 ih2->gather = 1;
161 ih2->dlengsz = setup->s.u.gatherptrs;
164 irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
166 irh->opcode = OPCODE_NIC;
167 irh->subcode = OPCODE_NIC_NW_DATA;
169 packet_params.u32 = 0;
171 packet_params.s.ip_csum = setup->s.ip_csum;
172 packet_params.s.transport_csum = setup->s.transport_csum;
173 packet_params.s.tnl_csum = setup->s.tnl_csum;
174 packet_params.s.tsflag = setup->s.timestamp;
176 irh->ossp = packet_params.u32;
179 static inline void
180 octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
181 union octeon_instr_64B *cmd,
182 union octnic_cmd_setup *setup, u32 tag)
184 struct octeon_instr_irh *irh;
185 struct octeon_instr_ih3 *ih3;
186 struct octeon_instr_pki_ih3 *pki_ih3;
187 union octnic_packet_params packet_params;
188 int port;
190 memset(cmd, 0, sizeof(union octeon_instr_64B));
192 ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
193 pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
195 /* assume that rflag is cleared so therefore front data will only have
196 * irh and ossp[1] and ossp[2] for a total of 24 bytes
198 ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
199 /*PKI IH*/
200 ih3->fsz = LIO_PCICMD_O3;
202 if (!setup->s.gather) {
203 ih3->dlengsz = setup->s.u.datasize;
204 } else {
205 ih3->gather = 1;
206 ih3->dlengsz = setup->s.u.gatherptrs;
209 pki_ih3->w = 1;
210 pki_ih3->raw = 1;
211 pki_ih3->utag = 1;
212 pki_ih3->utt = 1;
213 pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
215 port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
217 if (tag)
218 pki_ih3->tag = tag;
219 else
220 pki_ih3->tag = LIO_DATA(port);
222 pki_ih3->tagtype = ORDERED_TAG;
223 pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
224 pki_ih3->pm = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/
225 pki_ih3->sl = 8; /* sl will be sizeof(pki_ih3)*/
227 irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
229 irh->opcode = OPCODE_NIC;
230 irh->subcode = OPCODE_NIC_NW_DATA;
232 packet_params.u32 = 0;
234 packet_params.s.ip_csum = setup->s.ip_csum;
235 packet_params.s.transport_csum = setup->s.transport_csum;
236 packet_params.s.tnl_csum = setup->s.tnl_csum;
237 packet_params.s.tsflag = setup->s.timestamp;
239 irh->ossp = packet_params.u32;
242 /** Utility function to prepare a 64B NIC instruction based on a setup command
243 * @param cmd - pointer to instruction to be filled in.
244 * @param setup - pointer to the setup structure
245 * @param q_no - which queue for back pressure
247 * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
249 static inline void
250 octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
251 union octnic_cmd_setup *setup, u32 tag)
253 if (OCTEON_CN6XXX(oct))
254 octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
255 else
256 octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
259 /** Allocate and a soft command with space for a response immediately following
260 * the commnad.
261 * @param oct - octeon device pointer
262 * @param cmd - pointer to the command structure, pre-filled for everything
263 * except the response.
264 * @param rdatasize - size in bytes of the response.
266 * @returns pointer to allocated buffer with command copied into it, and
267 * response space immediately following.
269 void *
270 octeon_alloc_soft_command_resp(struct octeon_device *oct,
271 union octeon_instr_64B *cmd,
272 u32 rdatasize);
274 /** Send a NIC data packet to the device
275 * @param oct - octeon device pointer
276 * @param ndata - control structure with queueing, and buffer information
278 * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
279 * queue should be stopped, and IQ_SEND_OK if it sent okay.
281 int octnet_send_nic_data_pkt(struct octeon_device *oct,
282 struct octnic_data_pkt *ndata,
283 int xmit_more);
285 /** Send a NIC control packet to the device
286 * @param oct - octeon device pointer
287 * @param nctrl - control structure with command, timout, and callback info
288 * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
289 * queue should be stopped, and IQ_SEND_OK if it sent okay.
292 octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
293 struct octnic_ctrl_pkt *nctrl);
295 #endif