xref: /freebsd/sys/dev/smartpqi/smartpqi_cmd.c (revision 9fac68fc3853b696c8479bb3a8181d62cb9f59c9)
11e66f787SSean Bruno /*-
2*9fac68fcSPAPANI SRIKANTH  * Copyright 2016-2021 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 /* $FreeBSD$ */
271e66f787SSean Bruno 
281e66f787SSean Bruno #include "smartpqi_includes.h"
291e66f787SSean Bruno 
301e66f787SSean Bruno /*
311e66f787SSean Bruno  * Function to submit the request to the adapter.
321e66f787SSean Bruno  */
331e66f787SSean Bruno 
34*9fac68fcSPAPANI SRIKANTH int
35*9fac68fcSPAPANI SRIKANTH pqisrc_submit_cmnd(pqisrc_softstate_t *softs, ib_queue_t *ib_q, void *req)
361e66f787SSean Bruno {
371e66f787SSean Bruno 	char *slot = NULL;
381e66f787SSean Bruno 	uint32_t offset;
391e66f787SSean Bruno 	iu_header_t *hdr = (iu_header_t *)req;
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 
441e66f787SSean Bruno 	PQI_LOCK(&ib_q->lock);
451e66f787SSean Bruno 
461e66f787SSean Bruno 	/* Check queue full */
471e66f787SSean Bruno 	if ((ib_q->pi_local + 1) % ib_q->num_elem == *(ib_q->ci_virt_addr)) {
481e66f787SSean Bruno 		DBG_WARN("OUT Q full\n");
491e66f787SSean Bruno 	PQI_UNLOCK(&ib_q->lock);
501e66f787SSean Bruno 		return PQI_STATUS_QFULL;
511e66f787SSean Bruno 	}
521e66f787SSean Bruno 
531e66f787SSean Bruno 	/* Get the slot */
541e66f787SSean Bruno 	offset = ib_q->pi_local * ib_q->elem_size;
551e66f787SSean Bruno 	slot = ib_q->array_virt_addr + offset;
561e66f787SSean Bruno 
571e66f787SSean Bruno 	/* Copy the IU */
581e66f787SSean Bruno 	memcpy(slot, req, iu_len);
591e66f787SSean Bruno 	DBG_INFO("IU : \n");
601e66f787SSean Bruno 	for(i = 0; i< iu_len; i++)
611e66f787SSean Bruno 		DBG_INFO(" IU [ %d ] : %x\n", i, *((unsigned char *)(slot + i)));
621e66f787SSean Bruno 
631e66f787SSean Bruno 	/* Update the local PI */
641e66f787SSean Bruno 	ib_q->pi_local = (ib_q->pi_local + 1) % ib_q->num_elem;
651e66f787SSean Bruno 	DBG_INFO("ib_q->pi_local : %x IU size : %d\n",
661e66f787SSean Bruno 			 ib_q->pi_local, hdr->iu_length);
671e66f787SSean Bruno 	DBG_INFO("*ib_q->ci_virt_addr: %x\n",
681e66f787SSean Bruno 				*(ib_q->ci_virt_addr));
691e66f787SSean Bruno 
701e66f787SSean Bruno 	/* Inform the fw about the new IU */
711e66f787SSean Bruno 	PCI_MEM_PUT32(softs, ib_q->pi_register_abs, ib_q->pi_register_offset, ib_q->pi_local);
721e66f787SSean Bruno 	PQI_UNLOCK(&ib_q->lock);
731e66f787SSean Bruno 	DBG_FUNC("OUT\n");
741e66f787SSean Bruno 	return PQI_STATUS_SUCCESS;
751e66f787SSean Bruno }
76