4 * Copyright(c) 2017 Cavium, Inc.. All rights reserved.
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
11 * * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * * Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in
15 * the documentation and/or other materials provided with the
17 * * Neither the name of Cavium, Inc. nor the names of its
18 * contributors may be used to endorse or promote products derived
19 * from this software without specific prior written permission.
21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
25 * OWNER(S) OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 #include "lio_common.h"
39 #include "lio_response_manager.h"
40 #include "lio_device.h"
45 lio_send_data_pkt(struct octeon_device *oct, struct lio_data_pkt *ndata)
47 int ring_doorbell = 1;
49 return (lio_send_command(oct, ndata->q_no, ring_doorbell, &ndata->cmd,
50 ndata->buf, ndata->datasize, ndata->reqtype));
54 lio_ctrl_callback(struct octeon_device *oct, uint32_t status, void *sc_ptr)
56 struct lio_soft_command *sc = (struct lio_soft_command *)sc_ptr;
57 struct lio_ctrl_pkt *nctrl;
59 nctrl = (struct lio_ctrl_pkt *)sc->ctxptr;
62 * Call the callback function if status is OK.
63 * Status is OK only if a response was expected and core returned
65 * If no response was expected, status is OK if the command was posted
68 if (!status && nctrl->cb_fn)
71 lio_free_soft_command(oct, sc);
74 static inline struct lio_soft_command *
75 lio_alloc_ctrl_pkt_sc(struct octeon_device *oct, struct lio_ctrl_pkt *nctrl)
77 struct lio_soft_command *sc = NULL;
78 uint32_t datasize = 0, rdatasize, uddsize = 0;
81 uddsize = (uint32_t)(nctrl->ncmd.s.more * 8);
83 datasize = OCTEON_CMD_SIZE + uddsize;
84 rdatasize = (nctrl->wait_time) ? 16 : 0;
86 sc = lio_alloc_soft_command(oct, datasize, rdatasize,
87 sizeof(struct lio_ctrl_pkt));
92 memcpy(sc->ctxptr, nctrl, sizeof(struct lio_ctrl_pkt));
94 data = (uint8_t *)sc->virtdptr;
96 memcpy(data, &nctrl->ncmd, OCTEON_CMD_SIZE);
98 lio_swap_8B_data((uint64_t *)data, (OCTEON_CMD_SIZE >> 3));
101 /* Endian-Swap for UDD should have been done by caller. */
102 memcpy(data + OCTEON_CMD_SIZE, nctrl->udd, uddsize);
104 sc->iq_no = (uint32_t)nctrl->iq_no;
106 lio_prepare_soft_command(oct, sc, LIO_OPCODE_NIC, LIO_OPCODE_NIC_CMD, 0,
109 sc->callback = lio_ctrl_callback;
110 sc->callback_arg = sc;
111 sc->wait_time = nctrl->wait_time;
117 lio_send_ctrl_pkt(struct octeon_device *oct, struct lio_ctrl_pkt *nctrl)
119 struct lio_soft_command *sc = NULL;
122 mtx_lock(&oct->cmd_resp_wqlock);
124 * Allow only rx ctrl command to stop traffic on the chip
125 * during offline operations
127 if ((oct->cmd_resp_state == LIO_DRV_OFFLINE) &&
128 (nctrl->ncmd.s.cmd != LIO_CMD_RX_CTL)) {
129 mtx_unlock(&oct->cmd_resp_wqlock);
130 lio_dev_err(oct, "%s cmd:%d not processed since driver offline\n",
131 __func__, nctrl->ncmd.s.cmd);
135 sc = lio_alloc_ctrl_pkt_sc(oct, nctrl);
137 lio_dev_err(oct, "%s soft command alloc failed\n", __func__);
138 mtx_unlock(&oct->cmd_resp_wqlock);
142 retval = lio_send_soft_command(oct, sc);
143 if (retval == LIO_IQ_SEND_FAILED) {
144 lio_free_soft_command(oct, sc);
145 lio_dev_err(oct, "%s pf_num:%d soft command:%d send failed status: %x\n",
146 __func__, oct->pf_num, nctrl->ncmd.s.cmd, retval);
147 mtx_unlock(&oct->cmd_resp_wqlock);
151 mtx_unlock(&oct->cmd_resp_wqlock);