11e66f787SSean Bruno /*-
2*7ea28254SJohn Hall * Copyright 2016-2023 Microchip Technology, Inc. and/or its subsidiaries.
31e66f787SSean Bruno *
41e66f787SSean Bruno * Redistribution and use in source and binary forms, with or without
51e66f787SSean Bruno * modification, are permitted provided that the following conditions
61e66f787SSean Bruno * are met:
71e66f787SSean Bruno * 1. Redistributions of source code must retain the above copyright
81e66f787SSean Bruno * notice, this list of conditions and the following disclaimer.
91e66f787SSean Bruno * 2. Redistributions in binary form must reproduce the above copyright
101e66f787SSean Bruno * notice, this list of conditions and the following disclaimer in the
111e66f787SSean Bruno * documentation and/or other materials provided with the distribution.
121e66f787SSean Bruno *
131e66f787SSean Bruno * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
141e66f787SSean Bruno * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
151e66f787SSean Bruno * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
161e66f787SSean Bruno * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
171e66f787SSean Bruno * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
181e66f787SSean Bruno * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
191e66f787SSean Bruno * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
201e66f787SSean Bruno * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
211e66f787SSean Bruno * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
221e66f787SSean Bruno * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
231e66f787SSean Bruno * SUCH DAMAGE.
241e66f787SSean Bruno */
251e66f787SSean Bruno
261e66f787SSean Bruno
271e66f787SSean Bruno #include "smartpqi_includes.h"
281e66f787SSean Bruno
291e66f787SSean Bruno /*
301e66f787SSean Bruno * Function to submit the request to the adapter.
311e66f787SSean Bruno */
321e66f787SSean Bruno
339fac68fcSPAPANI SRIKANTH int
pqisrc_submit_cmnd(pqisrc_softstate_t * softs,ib_queue_t * ib_q,void * req)349fac68fcSPAPANI SRIKANTH pqisrc_submit_cmnd(pqisrc_softstate_t *softs, ib_queue_t *ib_q, void *req)
351e66f787SSean Bruno {
361e66f787SSean Bruno char *slot = NULL;
371e66f787SSean Bruno uint32_t offset;
381e66f787SSean Bruno iu_header_t *hdr = (iu_header_t *)req;
39*7ea28254SJohn Hall /*TODO : Can be fixed a size copying of IU ? */
401e66f787SSean Bruno uint32_t iu_len = hdr->iu_length + 4 ; /* header size */
411e66f787SSean Bruno int i = 0;
421e66f787SSean Bruno DBG_FUNC("IN\n");
431e66f787SSean Bruno
44*7ea28254SJohn Hall /* The code below assumes we only take 1 element (no spanning) */
45*7ea28254SJohn Hall ASSERT(iu_len <= ib_q->elem_size);
46*7ea28254SJohn Hall
471e66f787SSean Bruno PQI_LOCK(&ib_q->lock);
481e66f787SSean Bruno
491e66f787SSean Bruno /* Check queue full */
501e66f787SSean Bruno if ((ib_q->pi_local + 1) % ib_q->num_elem == *(ib_q->ci_virt_addr)) {
511e66f787SSean Bruno DBG_WARN("OUT Q full\n");
521e66f787SSean Bruno PQI_UNLOCK(&ib_q->lock);
531e66f787SSean Bruno return PQI_STATUS_QFULL;
541e66f787SSean Bruno }
551e66f787SSean Bruno
561e66f787SSean Bruno /* Get the slot */
571e66f787SSean Bruno offset = ib_q->pi_local * ib_q->elem_size;
581e66f787SSean Bruno slot = ib_q->array_virt_addr + offset;
591e66f787SSean Bruno
601e66f787SSean Bruno /* Copy the IU */
611e66f787SSean Bruno memcpy(slot, req, iu_len);
62*7ea28254SJohn Hall DBG_IO("IU : \n");
631e66f787SSean Bruno for(i = 0; i< iu_len; i++)
64*7ea28254SJohn Hall DBG_IO(" IU [ %d ] : %x\n", i, *((unsigned char *)(slot + i)));
651e66f787SSean Bruno
661e66f787SSean Bruno /* Update the local PI */
671e66f787SSean Bruno ib_q->pi_local = (ib_q->pi_local + 1) % ib_q->num_elem;
68*7ea28254SJohn Hall DBG_IO("ib_q->pi_local : %x IU size : %d\n",
691e66f787SSean Bruno ib_q->pi_local, hdr->iu_length);
70*7ea28254SJohn Hall DBG_IO("*ib_q->ci_virt_addr: %x\n",
711e66f787SSean Bruno *(ib_q->ci_virt_addr));
721e66f787SSean Bruno
731e66f787SSean Bruno /* Inform the fw about the new IU */
741e66f787SSean Bruno PCI_MEM_PUT32(softs, ib_q->pi_register_abs, ib_q->pi_register_offset, ib_q->pi_local);
751e66f787SSean Bruno PQI_UNLOCK(&ib_q->lock);
761e66f787SSean Bruno DBG_FUNC("OUT\n");
771e66f787SSean Bruno return PQI_STATUS_SUCCESS;
781e66f787SSean Bruno }
79