xref: /OK3568_Linux_fs/kernel/drivers/net/ethernet/cavium/liquidio/octeon_nic.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /**********************************************************************
2*4882a593Smuzhiyun  * Author: Cavium, Inc.
3*4882a593Smuzhiyun  *
4*4882a593Smuzhiyun  * Contact: support@cavium.com
5*4882a593Smuzhiyun  *          Please include "LiquidIO" in the subject.
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  * Copyright (c) 2003-2016 Cavium, Inc.
8*4882a593Smuzhiyun  *
9*4882a593Smuzhiyun  * This file is free software; you can redistribute it and/or modify
10*4882a593Smuzhiyun  * it under the terms of the GNU General Public License, Version 2, as
11*4882a593Smuzhiyun  * published by the Free Software Foundation.
12*4882a593Smuzhiyun  *
13*4882a593Smuzhiyun  * This file is distributed in the hope that it will be useful, but
14*4882a593Smuzhiyun  * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15*4882a593Smuzhiyun  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16*4882a593Smuzhiyun  * NONINFRINGEMENT.  See the GNU General Public License for more
17*4882a593Smuzhiyun  * details.
18*4882a593Smuzhiyun  **********************************************************************/
19*4882a593Smuzhiyun 
20*4882a593Smuzhiyun /*!  \file octeon_nic.h
21*4882a593Smuzhiyun  *   \brief Host NIC Driver: Routine to send network data &
22*4882a593Smuzhiyun  *   control packet to Octeon.
23*4882a593Smuzhiyun  */
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun #ifndef __OCTEON_NIC_H__
26*4882a593Smuzhiyun #define  __OCTEON_NIC_H__
27*4882a593Smuzhiyun 
28*4882a593Smuzhiyun /* Maximum number of 8-byte words can be sent in a NIC control message.
29*4882a593Smuzhiyun  */
30*4882a593Smuzhiyun #define  MAX_NCTRL_UDD  32
31*4882a593Smuzhiyun 
32*4882a593Smuzhiyun typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *);
33*4882a593Smuzhiyun 
34*4882a593Smuzhiyun /* Structure of control information passed by the NIC module to the OSI
35*4882a593Smuzhiyun  * layer when sending control commands to Octeon device software.
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun struct octnic_ctrl_pkt {
38*4882a593Smuzhiyun 	/** Command to be passed to the Octeon device software. */
39*4882a593Smuzhiyun 	union octnet_cmd ncmd;
40*4882a593Smuzhiyun 
41*4882a593Smuzhiyun 	/** Send buffer  */
42*4882a593Smuzhiyun 	void *data;
43*4882a593Smuzhiyun 	u64 dmadata;
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun 	/** Response buffer */
46*4882a593Smuzhiyun 	void *rdata;
47*4882a593Smuzhiyun 	u64 dmardata;
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun 	/** Additional data that may be needed by some commands. */
50*4882a593Smuzhiyun 	u64 udd[MAX_NCTRL_UDD];
51*4882a593Smuzhiyun 
52*4882a593Smuzhiyun 	/** Input queue to use to send this command. */
53*4882a593Smuzhiyun 	u64 iq_no;
54*4882a593Smuzhiyun 
55*4882a593Smuzhiyun 	/** The network device that issued the control command. */
56*4882a593Smuzhiyun 	u64 netpndev;
57*4882a593Smuzhiyun 
58*4882a593Smuzhiyun 	/** Callback function called when the command has been fetched */
59*4882a593Smuzhiyun 	octnic_ctrl_pkt_cb_fn_t cb_fn;
60*4882a593Smuzhiyun 
61*4882a593Smuzhiyun 	u32 sc_status;
62*4882a593Smuzhiyun };
63*4882a593Smuzhiyun 
64*4882a593Smuzhiyun #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
65*4882a593Smuzhiyun 
66*4882a593Smuzhiyun /** Structure of data information passed by the NIC module to the OSI
67*4882a593Smuzhiyun  * layer when forwarding data to Octeon device software.
68*4882a593Smuzhiyun  */
69*4882a593Smuzhiyun struct octnic_data_pkt {
70*4882a593Smuzhiyun 	/** Pointer to information maintained by NIC module for this packet. The
71*4882a593Smuzhiyun 	 *  OSI layer passes this as-is to the driver.
72*4882a593Smuzhiyun 	 */
73*4882a593Smuzhiyun 	void *buf;
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun 	/** Type of buffer passed in "buf" above. */
76*4882a593Smuzhiyun 	u32 reqtype;
77*4882a593Smuzhiyun 
78*4882a593Smuzhiyun 	/** Total data bytes to be transferred in this command. */
79*4882a593Smuzhiyun 	u32 datasize;
80*4882a593Smuzhiyun 
81*4882a593Smuzhiyun 	/** Command to be passed to the Octeon device software. */
82*4882a593Smuzhiyun 	union octeon_instr_64B cmd;
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun 	/** Input queue to use to send this command. */
85*4882a593Smuzhiyun 	u32 q_no;
86*4882a593Smuzhiyun 
87*4882a593Smuzhiyun };
88*4882a593Smuzhiyun 
89*4882a593Smuzhiyun /** Structure passed by NIC module to OSI layer to prepare a command to send
90*4882a593Smuzhiyun  * network data to Octeon.
91*4882a593Smuzhiyun  */
92*4882a593Smuzhiyun union octnic_cmd_setup {
93*4882a593Smuzhiyun 	struct {
94*4882a593Smuzhiyun 		u32 iq_no:8;
95*4882a593Smuzhiyun 		u32 gather:1;
96*4882a593Smuzhiyun 		u32 timestamp:1;
97*4882a593Smuzhiyun 		u32 ip_csum:1;
98*4882a593Smuzhiyun 		u32 transport_csum:1;
99*4882a593Smuzhiyun 		u32 tnl_csum:1;
100*4882a593Smuzhiyun 		u32 rsvd:19;
101*4882a593Smuzhiyun 
102*4882a593Smuzhiyun 		union {
103*4882a593Smuzhiyun 			u32 datasize;
104*4882a593Smuzhiyun 			u32 gatherptrs;
105*4882a593Smuzhiyun 		} u;
106*4882a593Smuzhiyun 	} s;
107*4882a593Smuzhiyun 
108*4882a593Smuzhiyun 	u64 u64;
109*4882a593Smuzhiyun 
110*4882a593Smuzhiyun };
111*4882a593Smuzhiyun 
octnet_iq_is_full(struct octeon_device * oct,u32 q_no)112*4882a593Smuzhiyun static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
113*4882a593Smuzhiyun {
114*4882a593Smuzhiyun 	return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
115*4882a593Smuzhiyun 		>= (oct->instr_queue[q_no]->max_count - 2));
116*4882a593Smuzhiyun }
117*4882a593Smuzhiyun 
118*4882a593Smuzhiyun static inline void
octnet_prepare_pci_cmd_o2(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)119*4882a593Smuzhiyun octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
120*4882a593Smuzhiyun 			  union octeon_instr_64B *cmd,
121*4882a593Smuzhiyun 			  union octnic_cmd_setup *setup, u32 tag)
122*4882a593Smuzhiyun {
123*4882a593Smuzhiyun 	struct octeon_instr_ih2 *ih2;
124*4882a593Smuzhiyun 	struct octeon_instr_irh *irh;
125*4882a593Smuzhiyun 	union octnic_packet_params packet_params;
126*4882a593Smuzhiyun 	int port;
127*4882a593Smuzhiyun 
128*4882a593Smuzhiyun 	memset(cmd, 0, sizeof(union octeon_instr_64B));
129*4882a593Smuzhiyun 
130*4882a593Smuzhiyun 	ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
131*4882a593Smuzhiyun 
132*4882a593Smuzhiyun 	/* assume that rflag is cleared so therefore front data will only have
133*4882a593Smuzhiyun 	 * irh and ossp[0], ossp[1] for a total of 32 bytes
134*4882a593Smuzhiyun 	 */
135*4882a593Smuzhiyun 	ih2->fsz = LIO_PCICMD_O2;
136*4882a593Smuzhiyun 
137*4882a593Smuzhiyun 	ih2->tagtype = ORDERED_TAG;
138*4882a593Smuzhiyun 	ih2->grp = DEFAULT_POW_GRP;
139*4882a593Smuzhiyun 
140*4882a593Smuzhiyun 	port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
141*4882a593Smuzhiyun 
142*4882a593Smuzhiyun 	if (tag)
143*4882a593Smuzhiyun 		ih2->tag = tag;
144*4882a593Smuzhiyun 	else
145*4882a593Smuzhiyun 		ih2->tag = LIO_DATA(port);
146*4882a593Smuzhiyun 
147*4882a593Smuzhiyun 	ih2->raw = 1;
148*4882a593Smuzhiyun 	ih2->qos = (port & 3) + 4;	/* map qos based on interface */
149*4882a593Smuzhiyun 
150*4882a593Smuzhiyun 	if (!setup->s.gather) {
151*4882a593Smuzhiyun 		ih2->dlengsz = setup->s.u.datasize;
152*4882a593Smuzhiyun 	} else {
153*4882a593Smuzhiyun 		ih2->gather = 1;
154*4882a593Smuzhiyun 		ih2->dlengsz = setup->s.u.gatherptrs;
155*4882a593Smuzhiyun 	}
156*4882a593Smuzhiyun 
157*4882a593Smuzhiyun 	irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
158*4882a593Smuzhiyun 
159*4882a593Smuzhiyun 	irh->opcode = OPCODE_NIC;
160*4882a593Smuzhiyun 	irh->subcode = OPCODE_NIC_NW_DATA;
161*4882a593Smuzhiyun 
162*4882a593Smuzhiyun 	packet_params.u32 = 0;
163*4882a593Smuzhiyun 
164*4882a593Smuzhiyun 	packet_params.s.ip_csum = setup->s.ip_csum;
165*4882a593Smuzhiyun 	packet_params.s.transport_csum = setup->s.transport_csum;
166*4882a593Smuzhiyun 	packet_params.s.tnl_csum = setup->s.tnl_csum;
167*4882a593Smuzhiyun 	packet_params.s.tsflag = setup->s.timestamp;
168*4882a593Smuzhiyun 
169*4882a593Smuzhiyun 	irh->ossp = packet_params.u32;
170*4882a593Smuzhiyun }
171*4882a593Smuzhiyun 
172*4882a593Smuzhiyun static inline void
octnet_prepare_pci_cmd_o3(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)173*4882a593Smuzhiyun octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
174*4882a593Smuzhiyun 			  union octeon_instr_64B *cmd,
175*4882a593Smuzhiyun 			  union octnic_cmd_setup *setup, u32 tag)
176*4882a593Smuzhiyun {
177*4882a593Smuzhiyun 	struct octeon_instr_irh *irh;
178*4882a593Smuzhiyun 	struct octeon_instr_ih3     *ih3;
179*4882a593Smuzhiyun 	struct octeon_instr_pki_ih3 *pki_ih3;
180*4882a593Smuzhiyun 	union octnic_packet_params packet_params;
181*4882a593Smuzhiyun 	int port;
182*4882a593Smuzhiyun 
183*4882a593Smuzhiyun 	memset(cmd, 0, sizeof(union octeon_instr_64B));
184*4882a593Smuzhiyun 
185*4882a593Smuzhiyun 	ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
186*4882a593Smuzhiyun 	pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
187*4882a593Smuzhiyun 
188*4882a593Smuzhiyun 	/* assume that rflag is cleared so therefore front data will only have
189*4882a593Smuzhiyun 	 * irh and ossp[1] and ossp[2] for a total of 24 bytes
190*4882a593Smuzhiyun 	 */
191*4882a593Smuzhiyun 	ih3->pkind       = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
192*4882a593Smuzhiyun 	/*PKI IH*/
193*4882a593Smuzhiyun 	ih3->fsz = LIO_PCICMD_O3;
194*4882a593Smuzhiyun 
195*4882a593Smuzhiyun 	if (!setup->s.gather) {
196*4882a593Smuzhiyun 		ih3->dlengsz = setup->s.u.datasize;
197*4882a593Smuzhiyun 	} else {
198*4882a593Smuzhiyun 		ih3->gather = 1;
199*4882a593Smuzhiyun 		ih3->dlengsz = setup->s.u.gatherptrs;
200*4882a593Smuzhiyun 	}
201*4882a593Smuzhiyun 
202*4882a593Smuzhiyun 	pki_ih3->w       = 1;
203*4882a593Smuzhiyun 	pki_ih3->raw     = 1;
204*4882a593Smuzhiyun 	pki_ih3->utag    = 1;
205*4882a593Smuzhiyun 	pki_ih3->utt     = 1;
206*4882a593Smuzhiyun 	pki_ih3->uqpg    = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
207*4882a593Smuzhiyun 
208*4882a593Smuzhiyun 	port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
209*4882a593Smuzhiyun 
210*4882a593Smuzhiyun 	if (tag)
211*4882a593Smuzhiyun 		pki_ih3->tag = tag;
212*4882a593Smuzhiyun 	else
213*4882a593Smuzhiyun 		pki_ih3->tag     = LIO_DATA(port);
214*4882a593Smuzhiyun 
215*4882a593Smuzhiyun 	pki_ih3->tagtype = ORDERED_TAG;
216*4882a593Smuzhiyun 	pki_ih3->qpg     = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
217*4882a593Smuzhiyun 	pki_ih3->pm      = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/
218*4882a593Smuzhiyun 	pki_ih3->sl      = 8;   /* sl will be sizeof(pki_ih3)*/
219*4882a593Smuzhiyun 
220*4882a593Smuzhiyun 	irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
221*4882a593Smuzhiyun 
222*4882a593Smuzhiyun 	irh->opcode = OPCODE_NIC;
223*4882a593Smuzhiyun 	irh->subcode = OPCODE_NIC_NW_DATA;
224*4882a593Smuzhiyun 
225*4882a593Smuzhiyun 	packet_params.u32 = 0;
226*4882a593Smuzhiyun 
227*4882a593Smuzhiyun 	packet_params.s.ip_csum = setup->s.ip_csum;
228*4882a593Smuzhiyun 	packet_params.s.transport_csum = setup->s.transport_csum;
229*4882a593Smuzhiyun 	packet_params.s.tnl_csum = setup->s.tnl_csum;
230*4882a593Smuzhiyun 	packet_params.s.tsflag = setup->s.timestamp;
231*4882a593Smuzhiyun 
232*4882a593Smuzhiyun 	irh->ossp = packet_params.u32;
233*4882a593Smuzhiyun }
234*4882a593Smuzhiyun 
235*4882a593Smuzhiyun /** Utility function to prepare a 64B NIC instruction based on a setup command
236*4882a593Smuzhiyun  * @param cmd - pointer to instruction to be filled in.
237*4882a593Smuzhiyun  * @param setup - pointer to the setup structure
238*4882a593Smuzhiyun  * @param q_no - which queue for back pressure
239*4882a593Smuzhiyun  *
240*4882a593Smuzhiyun  * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
241*4882a593Smuzhiyun  */
242*4882a593Smuzhiyun static inline void
octnet_prepare_pci_cmd(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)243*4882a593Smuzhiyun octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
244*4882a593Smuzhiyun 		       union octnic_cmd_setup *setup, u32 tag)
245*4882a593Smuzhiyun {
246*4882a593Smuzhiyun 	if (OCTEON_CN6XXX(oct))
247*4882a593Smuzhiyun 		octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
248*4882a593Smuzhiyun 	else
249*4882a593Smuzhiyun 		octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
250*4882a593Smuzhiyun }
251*4882a593Smuzhiyun 
252*4882a593Smuzhiyun /** Allocate and a soft command with space for a response immediately following
253*4882a593Smuzhiyun  * the commnad.
254*4882a593Smuzhiyun  * @param oct - octeon device pointer
255*4882a593Smuzhiyun  * @param cmd - pointer to the command structure, pre-filled for everything
256*4882a593Smuzhiyun  * except the response.
257*4882a593Smuzhiyun  * @param rdatasize - size in bytes of the response.
258*4882a593Smuzhiyun  *
259*4882a593Smuzhiyun  * @returns pointer to allocated buffer with command copied into it, and
260*4882a593Smuzhiyun  * response space immediately following.
261*4882a593Smuzhiyun  */
262*4882a593Smuzhiyun void *
263*4882a593Smuzhiyun octeon_alloc_soft_command_resp(struct octeon_device    *oct,
264*4882a593Smuzhiyun 			       union octeon_instr_64B *cmd,
265*4882a593Smuzhiyun 			       u32		       rdatasize);
266*4882a593Smuzhiyun 
267*4882a593Smuzhiyun /** Send a NIC data packet to the device
268*4882a593Smuzhiyun  * @param oct - octeon device pointer
269*4882a593Smuzhiyun  * @param ndata - control structure with queueing, and buffer information
270*4882a593Smuzhiyun  *
271*4882a593Smuzhiyun  * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
272*4882a593Smuzhiyun  * queue should be stopped, and IQ_SEND_OK if it sent okay.
273*4882a593Smuzhiyun  */
274*4882a593Smuzhiyun int octnet_send_nic_data_pkt(struct octeon_device *oct,
275*4882a593Smuzhiyun 			     struct octnic_data_pkt *ndata,
276*4882a593Smuzhiyun 			     int xmit_more);
277*4882a593Smuzhiyun 
278*4882a593Smuzhiyun /** Send a NIC control packet to the device
279*4882a593Smuzhiyun  * @param oct - octeon device pointer
280*4882a593Smuzhiyun  * @param nctrl - control structure with command, timout, and callback info
281*4882a593Smuzhiyun  * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
282*4882a593Smuzhiyun  * queue should be stopped, and IQ_SEND_OK if it sent okay.
283*4882a593Smuzhiyun  */
284*4882a593Smuzhiyun int
285*4882a593Smuzhiyun octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
286*4882a593Smuzhiyun 			 struct octnic_ctrl_pkt *nctrl);
287*4882a593Smuzhiyun 
288*4882a593Smuzhiyun #endif
289