1f21fb3edSRaghu Vatsavayi /**********************************************************************
2f21fb3edSRaghu Vatsavayi * Author: Cavium, Inc.
3f21fb3edSRaghu Vatsavayi *
4f21fb3edSRaghu Vatsavayi * Contact: support@cavium.com
5f21fb3edSRaghu Vatsavayi * Please include "LiquidIO" in the subject.
6f21fb3edSRaghu Vatsavayi *
750579d3dSRaghu Vatsavayi * Copyright (c) 2003-2016 Cavium, Inc.
8f21fb3edSRaghu Vatsavayi *
9f21fb3edSRaghu Vatsavayi * This file is free software; you can redistribute it and/or modify
10f21fb3edSRaghu Vatsavayi * it under the terms of the GNU General Public License, Version 2, as
11f21fb3edSRaghu Vatsavayi * published by the Free Software Foundation.
12f21fb3edSRaghu Vatsavayi *
13f21fb3edSRaghu Vatsavayi * This file is distributed in the hope that it will be useful, but
14f21fb3edSRaghu Vatsavayi * AS-IS and WITHOUT ANY WARRANTY; without even the implied warranty
15f21fb3edSRaghu Vatsavayi * of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, TITLE, or
16f21fb3edSRaghu Vatsavayi * NONINFRINGEMENT. See the GNU General Public License for more
17f21fb3edSRaghu Vatsavayi * details.
18f21fb3edSRaghu Vatsavayi **********************************************************************/
19f21fb3edSRaghu Vatsavayi
20f21fb3edSRaghu Vatsavayi /*! \file octeon_nic.h
21f21fb3edSRaghu Vatsavayi * \brief Host NIC Driver: Routine to send network data &
22f21fb3edSRaghu Vatsavayi * control packet to Octeon.
23f21fb3edSRaghu Vatsavayi */
24f21fb3edSRaghu Vatsavayi
25f21fb3edSRaghu Vatsavayi #ifndef __OCTEON_NIC_H__
26f21fb3edSRaghu Vatsavayi #define __OCTEON_NIC_H__
27f21fb3edSRaghu Vatsavayi
28f21fb3edSRaghu Vatsavayi /* Maximum number of 8-byte words can be sent in a NIC control message.
29f21fb3edSRaghu Vatsavayi */
30f21fb3edSRaghu Vatsavayi #define MAX_NCTRL_UDD 32
31f21fb3edSRaghu Vatsavayi
32f21fb3edSRaghu Vatsavayi typedef void (*octnic_ctrl_pkt_cb_fn_t) (void *);
33f21fb3edSRaghu Vatsavayi
34f21fb3edSRaghu Vatsavayi /* Structure of control information passed by the NIC module to the OSI
35f21fb3edSRaghu Vatsavayi * layer when sending control commands to Octeon device software.
36f21fb3edSRaghu Vatsavayi */
37f21fb3edSRaghu Vatsavayi struct octnic_ctrl_pkt {
38f21fb3edSRaghu Vatsavayi /** Command to be passed to the Octeon device software. */
39f21fb3edSRaghu Vatsavayi union octnet_cmd ncmd;
40f21fb3edSRaghu Vatsavayi
41f21fb3edSRaghu Vatsavayi /** Send buffer */
42f21fb3edSRaghu Vatsavayi void *data;
43f21fb3edSRaghu Vatsavayi u64 dmadata;
44f21fb3edSRaghu Vatsavayi
45f21fb3edSRaghu Vatsavayi /** Response buffer */
46f21fb3edSRaghu Vatsavayi void *rdata;
47f21fb3edSRaghu Vatsavayi u64 dmardata;
48f21fb3edSRaghu Vatsavayi
49f21fb3edSRaghu Vatsavayi /** Additional data that may be needed by some commands. */
50f21fb3edSRaghu Vatsavayi u64 udd[MAX_NCTRL_UDD];
51f21fb3edSRaghu Vatsavayi
520cece6c5SRaghu Vatsavayi /** Input queue to use to send this command. */
530cece6c5SRaghu Vatsavayi u64 iq_no;
540cece6c5SRaghu Vatsavayi
55f21fb3edSRaghu Vatsavayi /** The network device that issued the control command. */
56f21fb3edSRaghu Vatsavayi u64 netpndev;
57f21fb3edSRaghu Vatsavayi
58f21fb3edSRaghu Vatsavayi /** Callback function called when the command has been fetched */
59f21fb3edSRaghu Vatsavayi octnic_ctrl_pkt_cb_fn_t cb_fn;
600c264588SFelix Manlunas
61*edd572d7SFelix Manlunas u32 sc_status;
62f21fb3edSRaghu Vatsavayi };
63f21fb3edSRaghu Vatsavayi
6497a25326SRaghu Vatsavayi #define MAX_UDD_SIZE(nctrl) (sizeof((nctrl)->udd))
65f21fb3edSRaghu Vatsavayi
66f21fb3edSRaghu Vatsavayi /** Structure of data information passed by the NIC module to the OSI
67f21fb3edSRaghu Vatsavayi * layer when forwarding data to Octeon device software.
68f21fb3edSRaghu Vatsavayi */
69f21fb3edSRaghu Vatsavayi struct octnic_data_pkt {
70f21fb3edSRaghu Vatsavayi /** Pointer to information maintained by NIC module for this packet. The
71f21fb3edSRaghu Vatsavayi * OSI layer passes this as-is to the driver.
72f21fb3edSRaghu Vatsavayi */
73f21fb3edSRaghu Vatsavayi void *buf;
74f21fb3edSRaghu Vatsavayi
75f21fb3edSRaghu Vatsavayi /** Type of buffer passed in "buf" above. */
76f21fb3edSRaghu Vatsavayi u32 reqtype;
77f21fb3edSRaghu Vatsavayi
78f21fb3edSRaghu Vatsavayi /** Total data bytes to be transferred in this command. */
79f21fb3edSRaghu Vatsavayi u32 datasize;
80f21fb3edSRaghu Vatsavayi
81f21fb3edSRaghu Vatsavayi /** Command to be passed to the Octeon device software. */
826a885b60SRaghu Vatsavayi union octeon_instr_64B cmd;
83f21fb3edSRaghu Vatsavayi
84f21fb3edSRaghu Vatsavayi /** Input queue to use to send this command. */
85f21fb3edSRaghu Vatsavayi u32 q_no;
86f21fb3edSRaghu Vatsavayi
87f21fb3edSRaghu Vatsavayi };
88f21fb3edSRaghu Vatsavayi
89f21fb3edSRaghu Vatsavayi /** Structure passed by NIC module to OSI layer to prepare a command to send
90f21fb3edSRaghu Vatsavayi * network data to Octeon.
91f21fb3edSRaghu Vatsavayi */
92f21fb3edSRaghu Vatsavayi union octnic_cmd_setup {
93f21fb3edSRaghu Vatsavayi struct {
947275ebfcSRaghu Vatsavayi u32 iq_no:8;
95f21fb3edSRaghu Vatsavayi u32 gather:1;
96f21fb3edSRaghu Vatsavayi u32 timestamp:1;
97f21fb3edSRaghu Vatsavayi u32 ip_csum:1;
987275ebfcSRaghu Vatsavayi u32 transport_csum:1;
99f21fb3edSRaghu Vatsavayi u32 tnl_csum:1;
1000cece6c5SRaghu Vatsavayi u32 rsvd:19;
1017275ebfcSRaghu Vatsavayi
102f21fb3edSRaghu Vatsavayi union {
103f21fb3edSRaghu Vatsavayi u32 datasize;
104f21fb3edSRaghu Vatsavayi u32 gatherptrs;
105f21fb3edSRaghu Vatsavayi } u;
106f21fb3edSRaghu Vatsavayi } s;
107f21fb3edSRaghu Vatsavayi
108f21fb3edSRaghu Vatsavayi u64 u64;
109f21fb3edSRaghu Vatsavayi
110f21fb3edSRaghu Vatsavayi };
111f21fb3edSRaghu Vatsavayi
octnet_iq_is_full(struct octeon_device * oct,u32 q_no)112f21fb3edSRaghu Vatsavayi static inline int octnet_iq_is_full(struct octeon_device *oct, u32 q_no)
113f21fb3edSRaghu Vatsavayi {
114f21fb3edSRaghu Vatsavayi return ((u32)atomic_read(&oct->instr_queue[q_no]->instr_pending)
115f21fb3edSRaghu Vatsavayi >= (oct->instr_queue[q_no]->max_count - 2));
116f21fb3edSRaghu Vatsavayi }
117f21fb3edSRaghu Vatsavayi
118f21fb3edSRaghu Vatsavayi static inline void
octnet_prepare_pci_cmd_o2(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)1196a885b60SRaghu Vatsavayi octnet_prepare_pci_cmd_o2(struct octeon_device *oct,
1206a885b60SRaghu Vatsavayi union octeon_instr_64B *cmd,
121f21fb3edSRaghu Vatsavayi union octnic_cmd_setup *setup, u32 tag)
122f21fb3edSRaghu Vatsavayi {
1236a885b60SRaghu Vatsavayi struct octeon_instr_ih2 *ih2;
124f21fb3edSRaghu Vatsavayi struct octeon_instr_irh *irh;
125f21fb3edSRaghu Vatsavayi union octnic_packet_params packet_params;
1260cece6c5SRaghu Vatsavayi int port;
127f21fb3edSRaghu Vatsavayi
1286a885b60SRaghu Vatsavayi memset(cmd, 0, sizeof(union octeon_instr_64B));
129f21fb3edSRaghu Vatsavayi
1306a885b60SRaghu Vatsavayi ih2 = (struct octeon_instr_ih2 *)&cmd->cmd2.ih2;
131f21fb3edSRaghu Vatsavayi
132f21fb3edSRaghu Vatsavayi /* assume that rflag is cleared so therefore front data will only have
1336a885b60SRaghu Vatsavayi * irh and ossp[0], ossp[1] for a total of 32 bytes
134f21fb3edSRaghu Vatsavayi */
1355b823514SRaghu Vatsavayi ih2->fsz = LIO_PCICMD_O2;
136f21fb3edSRaghu Vatsavayi
1376a885b60SRaghu Vatsavayi ih2->tagtype = ORDERED_TAG;
1386a885b60SRaghu Vatsavayi ih2->grp = DEFAULT_POW_GRP;
139f21fb3edSRaghu Vatsavayi
1400cece6c5SRaghu Vatsavayi port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
1410cece6c5SRaghu Vatsavayi
142f21fb3edSRaghu Vatsavayi if (tag)
1436a885b60SRaghu Vatsavayi ih2->tag = tag;
144f21fb3edSRaghu Vatsavayi else
1456a885b60SRaghu Vatsavayi ih2->tag = LIO_DATA(port);
146f21fb3edSRaghu Vatsavayi
1476a885b60SRaghu Vatsavayi ih2->raw = 1;
1486a885b60SRaghu Vatsavayi ih2->qos = (port & 3) + 4; /* map qos based on interface */
149f21fb3edSRaghu Vatsavayi
150f21fb3edSRaghu Vatsavayi if (!setup->s.gather) {
1516a885b60SRaghu Vatsavayi ih2->dlengsz = setup->s.u.datasize;
152f21fb3edSRaghu Vatsavayi } else {
1536a885b60SRaghu Vatsavayi ih2->gather = 1;
1546a885b60SRaghu Vatsavayi ih2->dlengsz = setup->s.u.gatherptrs;
155f21fb3edSRaghu Vatsavayi }
156f21fb3edSRaghu Vatsavayi
1576a885b60SRaghu Vatsavayi irh = (struct octeon_instr_irh *)&cmd->cmd2.irh;
158f21fb3edSRaghu Vatsavayi
159f21fb3edSRaghu Vatsavayi irh->opcode = OPCODE_NIC;
160f21fb3edSRaghu Vatsavayi irh->subcode = OPCODE_NIC_NW_DATA;
161f21fb3edSRaghu Vatsavayi
162f21fb3edSRaghu Vatsavayi packet_params.u32 = 0;
163f21fb3edSRaghu Vatsavayi
164f21fb3edSRaghu Vatsavayi packet_params.s.ip_csum = setup->s.ip_csum;
1657275ebfcSRaghu Vatsavayi packet_params.s.transport_csum = setup->s.transport_csum;
166f21fb3edSRaghu Vatsavayi packet_params.s.tnl_csum = setup->s.tnl_csum;
167f21fb3edSRaghu Vatsavayi packet_params.s.tsflag = setup->s.timestamp;
168f21fb3edSRaghu Vatsavayi
169f21fb3edSRaghu Vatsavayi irh->ossp = packet_params.u32;
170f21fb3edSRaghu Vatsavayi }
171f21fb3edSRaghu Vatsavayi
1726a885b60SRaghu Vatsavayi static inline void
octnet_prepare_pci_cmd_o3(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)1736a885b60SRaghu Vatsavayi octnet_prepare_pci_cmd_o3(struct octeon_device *oct,
1746a885b60SRaghu Vatsavayi union octeon_instr_64B *cmd,
1756a885b60SRaghu Vatsavayi union octnic_cmd_setup *setup, u32 tag)
1766a885b60SRaghu Vatsavayi {
1776a885b60SRaghu Vatsavayi struct octeon_instr_irh *irh;
1786a885b60SRaghu Vatsavayi struct octeon_instr_ih3 *ih3;
1796a885b60SRaghu Vatsavayi struct octeon_instr_pki_ih3 *pki_ih3;
1806a885b60SRaghu Vatsavayi union octnic_packet_params packet_params;
1816a885b60SRaghu Vatsavayi int port;
1826a885b60SRaghu Vatsavayi
1836a885b60SRaghu Vatsavayi memset(cmd, 0, sizeof(union octeon_instr_64B));
1846a885b60SRaghu Vatsavayi
1856a885b60SRaghu Vatsavayi ih3 = (struct octeon_instr_ih3 *)&cmd->cmd3.ih3;
1866a885b60SRaghu Vatsavayi pki_ih3 = (struct octeon_instr_pki_ih3 *)&cmd->cmd3.pki_ih3;
1876a885b60SRaghu Vatsavayi
1886a885b60SRaghu Vatsavayi /* assume that rflag is cleared so therefore front data will only have
1896a885b60SRaghu Vatsavayi * irh and ossp[1] and ossp[2] for a total of 24 bytes
1906a885b60SRaghu Vatsavayi */
1916a885b60SRaghu Vatsavayi ih3->pkind = oct->instr_queue[setup->s.iq_no]->txpciq.s.pkind;
1926a885b60SRaghu Vatsavayi /*PKI IH*/
1935b823514SRaghu Vatsavayi ih3->fsz = LIO_PCICMD_O3;
1946a885b60SRaghu Vatsavayi
1956a885b60SRaghu Vatsavayi if (!setup->s.gather) {
1966a885b60SRaghu Vatsavayi ih3->dlengsz = setup->s.u.datasize;
1976a885b60SRaghu Vatsavayi } else {
1986a885b60SRaghu Vatsavayi ih3->gather = 1;
1996a885b60SRaghu Vatsavayi ih3->dlengsz = setup->s.u.gatherptrs;
2006a885b60SRaghu Vatsavayi }
2016a885b60SRaghu Vatsavayi
2026a885b60SRaghu Vatsavayi pki_ih3->w = 1;
2036a885b60SRaghu Vatsavayi pki_ih3->raw = 1;
2046a885b60SRaghu Vatsavayi pki_ih3->utag = 1;
2056a885b60SRaghu Vatsavayi pki_ih3->utt = 1;
2066a885b60SRaghu Vatsavayi pki_ih3->uqpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.use_qpg;
2076a885b60SRaghu Vatsavayi
2086a885b60SRaghu Vatsavayi port = (int)oct->instr_queue[setup->s.iq_no]->txpciq.s.port;
2096a885b60SRaghu Vatsavayi
2106a885b60SRaghu Vatsavayi if (tag)
2116a885b60SRaghu Vatsavayi pki_ih3->tag = tag;
2126a885b60SRaghu Vatsavayi else
2136a885b60SRaghu Vatsavayi pki_ih3->tag = LIO_DATA(port);
2146a885b60SRaghu Vatsavayi
2156a885b60SRaghu Vatsavayi pki_ih3->tagtype = ORDERED_TAG;
2166a885b60SRaghu Vatsavayi pki_ih3->qpg = oct->instr_queue[setup->s.iq_no]->txpciq.s.qpg;
2176a885b60SRaghu Vatsavayi pki_ih3->pm = 0x7; /*0x7 - meant for Parse nothing, uninterpreted*/
2186a885b60SRaghu Vatsavayi pki_ih3->sl = 8; /* sl will be sizeof(pki_ih3)*/
2196a885b60SRaghu Vatsavayi
2206a885b60SRaghu Vatsavayi irh = (struct octeon_instr_irh *)&cmd->cmd3.irh;
2216a885b60SRaghu Vatsavayi
2226a885b60SRaghu Vatsavayi irh->opcode = OPCODE_NIC;
2236a885b60SRaghu Vatsavayi irh->subcode = OPCODE_NIC_NW_DATA;
2246a885b60SRaghu Vatsavayi
2256a885b60SRaghu Vatsavayi packet_params.u32 = 0;
2266a885b60SRaghu Vatsavayi
2276a885b60SRaghu Vatsavayi packet_params.s.ip_csum = setup->s.ip_csum;
2286a885b60SRaghu Vatsavayi packet_params.s.transport_csum = setup->s.transport_csum;
2296a885b60SRaghu Vatsavayi packet_params.s.tnl_csum = setup->s.tnl_csum;
2306a885b60SRaghu Vatsavayi packet_params.s.tsflag = setup->s.timestamp;
2316a885b60SRaghu Vatsavayi
2326a885b60SRaghu Vatsavayi irh->ossp = packet_params.u32;
2336a885b60SRaghu Vatsavayi }
2346a885b60SRaghu Vatsavayi
2356a885b60SRaghu Vatsavayi /** Utility function to prepare a 64B NIC instruction based on a setup command
2366a885b60SRaghu Vatsavayi * @param cmd - pointer to instruction to be filled in.
2376a885b60SRaghu Vatsavayi * @param setup - pointer to the setup structure
2386a885b60SRaghu Vatsavayi * @param q_no - which queue for back pressure
2396a885b60SRaghu Vatsavayi *
2406a885b60SRaghu Vatsavayi * Assumes the cmd instruction is pre-allocated, but no fields are filled in.
2416a885b60SRaghu Vatsavayi */
2426a885b60SRaghu Vatsavayi static inline void
octnet_prepare_pci_cmd(struct octeon_device * oct,union octeon_instr_64B * cmd,union octnic_cmd_setup * setup,u32 tag)2436a885b60SRaghu Vatsavayi octnet_prepare_pci_cmd(struct octeon_device *oct, union octeon_instr_64B *cmd,
2446a885b60SRaghu Vatsavayi union octnic_cmd_setup *setup, u32 tag)
2456a885b60SRaghu Vatsavayi {
2466a885b60SRaghu Vatsavayi if (OCTEON_CN6XXX(oct))
2476a885b60SRaghu Vatsavayi octnet_prepare_pci_cmd_o2(oct, cmd, setup, tag);
2486a885b60SRaghu Vatsavayi else
2496a885b60SRaghu Vatsavayi octnet_prepare_pci_cmd_o3(oct, cmd, setup, tag);
2506a885b60SRaghu Vatsavayi }
2516a885b60SRaghu Vatsavayi
252f21fb3edSRaghu Vatsavayi /** Allocate and a soft command with space for a response immediately following
253f21fb3edSRaghu Vatsavayi * the commnad.
254f21fb3edSRaghu Vatsavayi * @param oct - octeon device pointer
255f21fb3edSRaghu Vatsavayi * @param cmd - pointer to the command structure, pre-filled for everything
256f21fb3edSRaghu Vatsavayi * except the response.
257f21fb3edSRaghu Vatsavayi * @param rdatasize - size in bytes of the response.
258f21fb3edSRaghu Vatsavayi *
259f21fb3edSRaghu Vatsavayi * @returns pointer to allocated buffer with command copied into it, and
260f21fb3edSRaghu Vatsavayi * response space immediately following.
261f21fb3edSRaghu Vatsavayi */
262f21fb3edSRaghu Vatsavayi void *
263f21fb3edSRaghu Vatsavayi octeon_alloc_soft_command_resp(struct octeon_device *oct,
2646a885b60SRaghu Vatsavayi union octeon_instr_64B *cmd,
2656a885b60SRaghu Vatsavayi u32 rdatasize);
266f21fb3edSRaghu Vatsavayi
267f21fb3edSRaghu Vatsavayi /** Send a NIC data packet to the device
268f21fb3edSRaghu Vatsavayi * @param oct - octeon device pointer
269f21fb3edSRaghu Vatsavayi * @param ndata - control structure with queueing, and buffer information
270f21fb3edSRaghu Vatsavayi *
271f21fb3edSRaghu Vatsavayi * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
272f21fb3edSRaghu Vatsavayi * queue should be stopped, and IQ_SEND_OK if it sent okay.
273f21fb3edSRaghu Vatsavayi */
274f21fb3edSRaghu Vatsavayi int octnet_send_nic_data_pkt(struct octeon_device *oct,
275c859e21aSIntiyaz Basha struct octnic_data_pkt *ndata,
276c859e21aSIntiyaz Basha int xmit_more);
277f21fb3edSRaghu Vatsavayi
278f21fb3edSRaghu Vatsavayi /** Send a NIC control packet to the device
279f21fb3edSRaghu Vatsavayi * @param oct - octeon device pointer
280f21fb3edSRaghu Vatsavayi * @param nctrl - control structure with command, timout, and callback info
281f21fb3edSRaghu Vatsavayi * @returns IQ_FAILED if it failed to add to the input queue. IQ_STOP if it the
282f21fb3edSRaghu Vatsavayi * queue should be stopped, and IQ_SEND_OK if it sent okay.
283f21fb3edSRaghu Vatsavayi */
284f21fb3edSRaghu Vatsavayi int
285f21fb3edSRaghu Vatsavayi octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
2860cece6c5SRaghu Vatsavayi struct octnic_ctrl_pkt *nctrl);
287f21fb3edSRaghu Vatsavayi
288f21fb3edSRaghu Vatsavayi #endif
289