emlxs_pkt.c revision 728bdc9be5faf84b5dca42f545967bd4910d608e
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * or http://www.opensolaris.org/os/licensing.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/*
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Emulex. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to License terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#include "emlxs.h"
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn ForteEMLXS_MSG_DEF(EMLXS_PKT_C);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct _emlxs_pkt_cookie_t {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_dma_cookie_t pkt_cmd_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_dma_cookie_t pkt_resp_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte ddi_dma_cookie_t pkt_data_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} emlxs_pkt_cookie_t;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_thread(void *arg)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* emlxs_hba_t *hba; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_port_t *port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_packet_t *pkt = (fc_packet_t *)arg;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int32_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_buf_t *sbp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbp = PKT2PRIV(pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte port = sbp->port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* hba = HBA; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Send the pkt now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = emlxs_pkt_send(pkt, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rval != FC_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EMLXS_MSGF(EMLXS_CONTEXT, &emlxs_pkt_trans_msg,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Deferred emlxs_pkt_send failed: status=%x pkt=%p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval, pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_comp) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_set_pkt_state(sbp, IOSTAT_LOCAL_REJECT, 0, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (*pkt->pkt_comp) (pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_pkt_free(pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_thread() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern int32_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_send(fc_packet_t *pkt, uint32_t now)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int32_t rval;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (now) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = emlxs_transport((opaque_t)pkt->pkt_ulp_private, pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte } else {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Spawn a thread to send the pkt */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) thread_create(NULL, 0, emlxs_pkt_thread, (char *)pkt, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &p0, TS_RUN, v.v_maxsyspri - 2);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = FC_SUCCESS;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (rval);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_send() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_free(fc_packet_t *pkt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_port_t *port = (emlxs_port_t *)pkt->pkt_ulp_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* emlxs_hba_t *hba = HBA; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) emlxs_pkt_uninit((opaque_t)port, pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_datalen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_data_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_rsplen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_resp_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_cmdlen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_cmd_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pkt, (sizeof (fc_packet_t) + sizeof (emlxs_buf_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (emlxs_pkt_cookie_t)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pkt, (sizeof (fc_packet_t) + sizeof (emlxs_buf_t)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_free() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Default pkt callback routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern void
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_callback(fc_packet_t *pkt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_pkt_free(pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_callback() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteextern fc_packet_t *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_alloc(emlxs_port_t *port, uint32_t cmdlen, uint32_t rsplen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t datalen, int32_t sleep)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte{
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_hba_t *hba = HBA;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte fc_packet_t *pkt;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte int32_t(*cb) (caddr_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long real_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t pkt_size;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_buf_t *sbp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_pkt_cookie_t *pkt_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_size = sizeof (fc_packet_t) + sizeof (emlxs_buf_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (emlxs_pkt_cookie_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte uint32_t num_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_size = sizeof (fc_packet_t) + sizeof (emlxs_buf_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate some space */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(pkt = (fc_packet_t *)kmem_alloc(pkt_size, sleep))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(pkt, pkt_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb = (sleep == KM_SLEEP) ? DDI_DMA_SLEEP : DDI_DMA_DONTWAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_ulp_private = (opaque_t)port;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_fca_private = (opaque_t)((uintptr_t)pkt +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (fc_packet_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_comp = emlxs_pkt_callback;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_tran_flags = (FC_TRAN_CLASS3 | FC_TRAN_INTR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_cmdlen = cmdlen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_rsplen = rsplen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_datalen = datalen;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_cookie = (emlxs_pkt_cookie_t *)((uintptr_t)pkt +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sizeof (fc_packet_t) + sizeof (emlxs_buf_t));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_cmd_cookie = &pkt_cookie->pkt_cmd_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_resp_cookie = &pkt_cookie->pkt_resp_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_data_cookie = &pkt_cookie->pkt_data_cookie;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmdlen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the cmd buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, &pkt->pkt_cmd_dma) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_mem_alloc(pkt->pkt_cmd_dma, cmdlen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &emlxs_data_acc_attr, DDI_DMA_CONSISTENT, cb, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (caddr_t *)&pkt->pkt_cmd, &real_len, &pkt->pkt_cmd_acc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (real_len < cmdlen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_cmd_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_cmd_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_cmd, real_len, DDI_DMA_WRITE | DDI_DMA_CONSISTENT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb, NULL, pkt->pkt_cmd_cookie, &pkt->pkt_cmd_cookie_cnt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_cmd_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_cmd, real_len, DDI_DMA_WRITE | DDI_DMA_CONSISTENT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb, NULL, &pkt->pkt_cmd_cookie, &num_cookie)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_cmd_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cmdlen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_cmd_cookie_cnt != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_cookie != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(pkt->pkt_cmd, cmdlen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsplen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the rsp buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, &pkt->pkt_resp_dma) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_mem_alloc(pkt->pkt_resp_dma, rsplen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &emlxs_data_acc_attr, DDI_DMA_CONSISTENT, cb, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (caddr_t *)&pkt->pkt_resp, &real_len, &pkt->pkt_resp_acc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (real_len < rsplen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_resp_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_resp_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_resp, real_len, DDI_DMA_READ | DDI_DMA_CONSISTENT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb, NULL, pkt->pkt_resp_cookie, &pkt->pkt_resp_cookie_cnt)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_resp_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_resp, real_len, DDI_DMA_READ | DDI_DMA_CONSISTENT,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb, NULL, &pkt->pkt_resp_cookie, &num_cookie)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_resp_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rsplen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_resp_cookie_cnt != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_cookie != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(pkt->pkt_resp, rsplen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the data buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (datalen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the rsp buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte NULL, &pkt->pkt_data_dma) != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_mem_alloc(pkt->pkt_data_dma, datalen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &emlxs_data_acc_attr, DDI_DMA_CONSISTENT, cb, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (caddr_t *)&pkt->pkt_data, &real_len, &pkt->pkt_data_acc)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte != DDI_SUCCESS) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (real_len < datalen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_data_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_data_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_data, real_len, DDI_DMA_READ | DDI_DMA_WRITE |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_DMA_CONSISTENT, cb, NULL, pkt->pkt_data_cookie,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &pkt->pkt_data_cookie_cnt) != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_addr_bind_handle(pkt->pkt_data_dma, NULL,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_data, real_len, DDI_DMA_READ | DDI_DMA_WRITE |
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte DDI_DMA_CONSISTENT, cb, NULL, &pkt->pkt_data_cookie,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte &num_cookie) != DDI_DMA_MAPPED)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_data_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte datalen = 0;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#if (EMLXS_MODREV >= EMLXS_MODREV3)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt->pkt_data_cookie_cnt != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#else
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (num_cookie != 1)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte goto failed;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte bzero(pkt->pkt_data, datalen);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte sbp = PKT2PRIV(pkt);
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan bzero((void *)sbp, sizeof (emlxs_buf_t));
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan mutex_init(&sbp->mtx, NULL, MUTEX_DRIVER, (void *)hba->intr_arg);
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan sbp->pkt_flags = PACKET_VALID | PACKET_RETURNED | PACKET_ALLOCATED;
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan sbp->port = port;
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan sbp->pkt = pkt;
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan sbp->iocbq.sbp = sbp;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortefailed:
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (datalen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_data_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_data_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (rsplen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_resp_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_resp_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (cmdlen) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_unbind_handle(pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_mem_free(&pkt->pkt_cmd_acc);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) ddi_dma_free_handle(&pkt->pkt_cmd_dma);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (pkt) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pkt, pkt_size);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte }
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte return (NULL);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_alloc() */