blob: 166727be928f97f607ca2a041e272562fc48f689 [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 **********************************************************************/
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070022#include <linux/interrupt.h>
23#include <linux/pci.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070024#include <linux/netdevice.h>
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070025#include "liquidio_common.h"
26#include "octeon_droq.h"
27#include "octeon_iq.h"
28#include "response_manager.h"
29#include "octeon_device.h"
30#include "octeon_nic.h"
31#include "octeon_main.h"
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070032
33void *
34octeon_alloc_soft_command_resp(struct octeon_device *oct,
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070035 union octeon_instr_64B *cmd,
36 u32 rdatasize)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070037{
38 struct octeon_soft_command *sc;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070039 struct octeon_instr_ih2 *ih2;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070040 struct octeon_instr_irh *irh;
41 struct octeon_instr_rdp *rdp;
42
43 sc = (struct octeon_soft_command *)
44 octeon_alloc_soft_command(oct, 0, rdatasize, 0);
45
46 if (!sc)
47 return NULL;
48
49 /* Copy existing command structure into the soft command */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070050 memcpy(&sc->cmd, cmd, sizeof(union octeon_instr_64B));
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070051
52 /* Add in the response related fields. Opcode and Param are already
53 * there.
54 */
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070055 ih2 = (struct octeon_instr_ih2 *)&sc->cmd.cmd2.ih2;
56 rdp = (struct octeon_instr_rdp *)&sc->cmd.cmd2.rdp;
57 irh = (struct octeon_instr_irh *)&sc->cmd.cmd2.irh;
58 ih2->fsz = 40; /* irh + ossp[0] + ossp[1] + rdp + rptr = 40 bytes */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070059
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070060 irh->rflag = 1; /* a response is required */
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070061
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070062 rdp->pcie_port = oct->pcie_port;
63 rdp->rlen = rdatasize;
64
65 *sc->status_word = COMPLETION_WORD_INIT;
66
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -070067 sc->cmd.cmd2.rptr = sc->dmarptr;
68
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -070069 sc->wait_time = 1000;
70 sc->timeout = jiffies + sc->wait_time;
71
72 return sc;
73}
74
75int octnet_send_nic_data_pkt(struct octeon_device *oct,
76 struct octnic_data_pkt *ndata,
77 u32 xmit_more)
78{
79 int ring_doorbell;
80
81 ring_doorbell = !xmit_more;
82
83 return octeon_send_command(oct, ndata->q_no, ring_doorbell, &ndata->cmd,
84 ndata->buf, ndata->datasize,
85 ndata->reqtype);
86}
87
88static void octnet_link_ctrl_callback(struct octeon_device *oct,
89 u32 status,
90 void *sc_ptr)
91{
92 struct octeon_soft_command *sc = (struct octeon_soft_command *)sc_ptr;
93 struct octnic_ctrl_pkt *nctrl;
94
95 nctrl = (struct octnic_ctrl_pkt *)sc->ctxptr;
96
97 /* Call the callback function if status is OK.
98 * Status is OK only if a response was expected and core returned
99 * success.
100 * If no response was expected, status is OK if the command was posted
101 * successfully.
102 */
103 if (!status && nctrl->cb_fn)
104 nctrl->cb_fn(nctrl);
105
106 octeon_free_soft_command(oct, sc);
107}
108
109static inline struct octeon_soft_command
110*octnic_alloc_ctrl_pkt_sc(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700111 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700112{
113 struct octeon_soft_command *sc = NULL;
114 u8 *data;
Raghu Vatsavayi6a885b62016-06-14 16:54:51 -0700115 u32 rdatasize;
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700116 u32 uddsize = 0, datasize = 0;
117
118 uddsize = (u32)(nctrl->ncmd.s.more * 8);
119
120 datasize = OCTNET_CMD_SIZE + uddsize;
121 rdatasize = (nctrl->wait_time) ? 16 : 0;
122
123 sc = (struct octeon_soft_command *)
124 octeon_alloc_soft_command(oct, datasize, rdatasize,
125 sizeof(struct octnic_ctrl_pkt));
126
127 if (!sc)
128 return NULL;
129
130 memcpy(sc->ctxptr, nctrl, sizeof(struct octnic_ctrl_pkt));
131
132 data = (u8 *)sc->virtdptr;
133
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700134 memcpy(data, &nctrl->ncmd, OCTNET_CMD_SIZE);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700135
136 octeon_swap_8B_data((u64 *)data, (OCTNET_CMD_SIZE >> 3));
137
138 if (uddsize) {
139 /* Endian-Swap for UDD should have been done by caller. */
140 memcpy(data + OCTNET_CMD_SIZE, nctrl->udd, uddsize);
141 }
142
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700143 sc->iq_no = (u32)nctrl->iq_no;
144
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700145 octeon_prepare_soft_command(oct, sc, OPCODE_NIC, OPCODE_NIC_CMD,
146 0, 0, 0);
147
148 sc->callback = octnet_link_ctrl_callback;
149 sc->callback_arg = sc;
150 sc->wait_time = nctrl->wait_time;
151
152 return sc;
153}
154
155int
156octnet_send_nic_ctrl_pkt(struct octeon_device *oct,
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700157 struct octnic_ctrl_pkt *nctrl)
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700158{
159 int retval;
160 struct octeon_soft_command *sc = NULL;
161
Raghu Vatsavayi60441882016-06-21 22:53:08 -0700162 spin_lock_bh(&oct->cmd_resp_wqlock);
163 /* Allow only rx ctrl command to stop traffic on the chip
164 * during offline operations
165 */
166 if ((oct->cmd_resp_state == OCT_DRV_OFFLINE) &&
167 (nctrl->ncmd.s.cmd != OCTNET_CMD_RX_CTL)) {
168 spin_unlock_bh(&oct->cmd_resp_wqlock);
169 dev_err(&oct->pci_dev->dev,
170 "%s cmd:%d not processed since driver offline\n",
171 __func__, nctrl->ncmd.s.cmd);
172 return -1;
173 }
174
Raghu Vatsavayi0cece6c2016-06-14 16:54:50 -0700175 sc = octnic_alloc_ctrl_pkt_sc(oct, nctrl);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700176 if (!sc) {
177 dev_err(&oct->pci_dev->dev, "%s soft command alloc failed\n",
178 __func__);
Raghu Vatsavayi60441882016-06-21 22:53:08 -0700179 spin_unlock_bh(&oct->cmd_resp_wqlock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700180 return -1;
181 }
182
183 retval = octeon_send_soft_command(oct, sc);
Raghu Vatsavayiddc173a2016-06-14 16:54:43 -0700184 if (retval == IQ_SEND_FAILED) {
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700185 octeon_free_soft_command(oct, sc);
Raghu Vatsavayi60441882016-06-21 22:53:08 -0700186 dev_err(&oct->pci_dev->dev, "%s soft command:%d send failed status: %x\n",
187 __func__, nctrl->ncmd.s.cmd, retval);
188 spin_unlock_bh(&oct->cmd_resp_wqlock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700189 return -1;
190 }
191
Raghu Vatsavayi60441882016-06-21 22:53:08 -0700192 spin_unlock_bh(&oct->cmd_resp_wqlock);
Raghu Vatsavayif21fb3e2015-06-09 18:15:23 -0700193 return retval;
194}