blob: 20e01229854b84342932dbf9e719adcc7feab7e6 [file] [log] [blame]
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -07001/**********************************************************************
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#include <linux/version.h>
23#include <linux/types.h>
24#include <linux/list.h>
25#include <linux/interrupt.h>
26#include <linux/pci.h>
27#include <linux/kthread.h>
28#include <linux/netdevice.h>
29#include "octeon_config.h"
30#include "liquidio_common.h"
31#include "octeon_droq.h"
32#include "octeon_iq.h"
33#include "response_manager.h"
34#include "octeon_device.h"
35#include "octeon_nic.h"
36#include "octeon_main.h"
37#include "octeon_network.h"
38#include "cn66xx_regs.h"
39#include "cn66xx_device.h"
40#include "cn68xx_regs.h"
41#include "cn68xx_device.h"
42#include "liquidio_image.h"
43#include "octeon_mem_ops.h"
44
45void *
46octeon_alloc_soft_command_resp(struct octeon_device *oct,
47 struct octeon_instr_64B *cmd,
48 size_t rdatasize)
49{
50 struct octeon_soft_command *sc;
51 struct octeon_instr_ih *ih;
52 struct octeon_instr_irh *irh;
53 struct octeon_instr_rdp *rdp;
54
55 sc = (struct octeon_soft_command *)
56 octeon_alloc_soft_command(oct, 0, rdatasize, 0);
57
58 if (!sc)
59 return NULL;
60
61 /* Copy existing command structure into the soft command */
62 memcpy(&sc->cmd, cmd, sizeof(struct octeon_instr_64B));
63
64 /* Add in the response related fields. Opcode and Param are already
65 * there.
66 */
67 ih = (struct octeon_instr_ih *)&sc->cmd.ih;
68 ih->fsz = 40; /* irh + ossp[0] + ossp[1] + rdp + rptr = 40 bytes */
69
70 irh = (struct octeon_instr_irh *)&sc->cmd.irh;
71 irh->rflag = 1; /* a response is required */
72 irh->len = 4; /* means four 64-bit words immediately follow irh */
73
74 rdp = (struct octeon_instr_rdp *)&sc->cmd.rdp;
75 rdp->pcie_port = oct->pcie_port;
76 rdp->rlen = rdatasize;
77
78 *sc->status_word = COMPLETION_WORD_INIT;
79
80 sc->wait_time = 1000;
81 sc->timeout = jiffies + sc->wait_time;
82
83 return sc;
84}
85
86int octnet_send_nic_data_pkt(struct octeon_device *oct,
87 struct octnic_data_pkt *ndata,
88 u32 xmit_more)
89{
90 int ring_doorbell;
91
92 ring_doorbell = !xmit_more;
93
94 return octeon_send_command(oct, ndata->q_no, ring_doorbell, &ndata->cmd,
95 ndata->buf, ndata->datasize,
96 ndata->reqtype);
97}
98
99static void octnet_link_ctrl_callback(struct octeon_device *oct,
100 u32 status,
101 void *sc_ptr)
102{
103 struct octeon_soft_command *sc = (struct octeon_soft_command *)sc_ptr;
104 struct octnic_ctrl_pkt *nctrl;
105
106 nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;
107
108 /* Call the callback function if status is OK.
109 * Status is OK only if a response was expected and core returned
110 * success.
111 * If no response was expected, status is OK if the command was posted
112 * successfully.
113 */
114 if (!status && nctrl->cb_fn)
115 nctrl->cb_fn(nctrl);
116
117 octeon_free_soft_command(oct, sc);
118}
119
120static inline struct octeon_soft_command
121*octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700122 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700123{
124 struct octeon_soft_command *sc = NULL;
125 u8 *data;
126 size_t rdatasize;
127 u32 uddsize = 0, datasize = 0;
128
129 uddsize = (u32)(nctrl->ncmd.s.more * 8);
130
131 datasize = OCTNET_CMD_SIZE + uddsize;
132 rdatasize = (nctrl->wait_time) ? 16 : 0;
133
134 sc = (struct octeon_soft_command *)
135 octeon_alloc_soft_command(oct, datasize, rdatasize,
136 sizeof(struct octnic_ctrl_pkt));
137
138 if (!sc)
139 return NULL;
140
141 memcpy(sc->ctxptr, nctrl, sizeof(struct octnic_ctrl_pkt));
142
143 data = (u8 *)sc->virtdptr;
144
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700145 memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700146
147 octeon_swap_8B_data((u64 *)data, (OCTNET_CMD_SIZE >> 3));
148
149 if (uddsize) {
150 /* Endian-Swap for UDD should have been done by caller. */
151 memcpy(data + OCTNET_CMD_SIZE, nctrl->udd, uddsize);
152 }
153
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700154 sc->iq_no = (u32)nctrl->iq_no;
155
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700156 octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD,
157 0, 0, 0);
158
159 sc->callback = octnet_link_ctrl_callback;
160 sc->callback_arg = sc;
161 sc->wait_time = nctrl->wait_time;
162
163 return sc;
164}
165
166int
167octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700168 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700169{
170 int retval;
171 struct octeon_soft_command *sc = NULL;
172
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700173 sc = octnic_alloc_ctrl_pkt_sc(oct, nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700174 if (!sc) {
175 dev_err(&oct->pci_dev->dev, "%s soft command alloc failed\n",
176 __func__);
177 return -1;
178 }
179
180 retval = octeon_send_soft_command(oct, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -0700181 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700182 octeon_free_soft_command(oct, sc);
183 dev_err(&oct->pci_dev->dev, "%s soft command send failed status: %x\n",
184 __func__, retval);
185 return -1;
186 }
187
188 return retval;
189}