blob: 7843b8a05dcfd973f6df57fa40e7c8b8a895e709 [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,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070047 union octeon_instr_64B *cmd,
48 u32 rdatasize)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070049{
50 struct octeon_soft_command *sc;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070051 struct octeon_instr_ih2 *ih2;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070052 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 */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070062 memcpy(&sc->cmd, cmd, sizeof(union octeon_instr_64B));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070063
64 /* Add in the response related fields. Opcode and Param are already
65 * there.
66 */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070067 ih2 = (struct octeon_instr_ih2 *)&sc->cmd.cmd2.ih2;
68 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
69 irh = (struct octeon_instr_irh *)&sc->cmd.cmd2.irh;
70 ih2->fsz = 40; /* irh + ossp[0] + ossp[1] + rdp + rptr = 40 bytes */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070071
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070072 irh->rflag = 1; /* a response is required */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070073
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070074 rdp->pcie_port = oct->pcie_port;
75 rdp->rlen = rdatasize;
76
77 *sc->status_word = COMPLETION_WORD_INIT;
78
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070079 sc->cmd.cmd2.rptr = sc->dmarptr;
80
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070081 sc->wait_time = 1000;
82 sc->timeout = jiffies + sc->wait_time;
83
84 return sc;
85}
86
87int octnet_send_nic_data_pkt(struct octeon_device *oct,
88 struct octnic_data_pkt *ndata,
89 u32 xmit_more)
90{
91 int ring_doorbell;
92
93 ring_doorbell = !xmit_more;
94
95 return octeon_send_command(oct, ndata->q_no, ring_doorbell, &ndata->cmd,
96 ndata->buf, ndata->datasize,
97 ndata->reqtype);
98}
99
100static void octnet_link_ctrl_callback(struct octeon_device *oct,
101 u32 status,
102 void *sc_ptr)
103{
104 struct octeon_soft_command *sc = (struct octeon_soft_command *)sc_ptr;
105 struct octnic_ctrl_pkt *nctrl;
106
107 nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;
108
109 /* Call the callback function if status is OK.
110 * Status is OK only if a response was expected and core returned
111 * success.
112 * If no response was expected, status is OK if the command was posted
113 * successfully.
114 */
115 if (!status && nctrl->cb_fn)
116 nctrl->cb_fn(nctrl);
117
118 octeon_free_soft_command(oct, sc);
119}
120
121static inline struct octeon_soft_command
122*octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700123 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700124{
125 struct octeon_soft_command *sc = NULL;
126 u8 *data;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700127 u32 rdatasize;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700128 u32 uddsize = 0, datasize = 0;
129
130 uddsize = (u32)(nctrl->ncmd.s.more * 8);
131
132 datasize = OCTNET_CMD_SIZE + uddsize;
133 rdatasize = (nctrl->wait_time) ? 16 : 0;
134
135 sc = (struct octeon_soft_command *)
136 octeon_alloc_soft_command(oct, datasize, rdatasize,
137 sizeof(struct octnic_ctrl_pkt));
138
139 if (!sc)
140 return NULL;
141
142 memcpy(sc->ctxptr, nctrl, sizeof(struct octnic_ctrl_pkt));
143
144 data = (u8 *)sc->virtdptr;
145
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700146 memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700147
148 octeon_swap_8B_data((u64 *)data, (OCTNET_CMD_SIZE >> 3));
149
150 if (uddsize) {
151 /* Endian-Swap for UDD should have been done by caller. */
152 memcpy(data + OCTNET_CMD_SIZE, nctrl->udd, uddsize);
153 }
154
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700155 sc->iq_no = (u32)nctrl->iq_no;
156
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700157 octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD,
158 0, 0, 0);
159
160 sc->callback = octnet_link_ctrl_callback;
161 sc->callback_arg = sc;
162 sc->wait_time = nctrl->wait_time;
163
164 return sc;
165}
166
167int
168octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700169 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700170{
171 int retval;
172 struct octeon_soft_command *sc = NULL;
173
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700174 sc = octnic_alloc_ctrl_pkt_sc(oct, nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700175 if (!sc) {
176 dev_err(&oct->pci_dev->dev, "%s soft command alloc failed\n",
177 __func__);
178 return -1;
179 }
180
181 retval = octeon_send_soft_command(oct, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -0700182 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700183 octeon_free_soft_command(oct, sc);
184 dev_err(&oct->pci_dev->dev, "%s soft command send failed status: %x\n",
185 __func__, retval);
186 return -1;
187 }
188
189 return retval;
190}