emlxs_pkt.c revision 728bdc9be5faf84b5dca42f545967bd4910d608e
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
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 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
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 * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2008 Emulex. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to License terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Required for EMLXS_CONTEXT in EMLXS_MSGF calls */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* emlxs_hba_t *hba; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* hba = HBA; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Send the pkt now */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte "Deferred emlxs_pkt_send failed: status=%x pkt=%p",
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_set_pkt_state(sbp, IOSTAT_LOCAL_REJECT, 0, 1);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_thread() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte rval = emlxs_transport((opaque_t)pkt->pkt_ulp_private, pkt);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Spawn a thread to send the pkt */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte (void) thread_create(NULL, 0, emlxs_pkt_thread, (char *)pkt, 0,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_send() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte emlxs_port_t *port = (emlxs_port_t *)pkt->pkt_ulp_private;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* emlxs_hba_t *hba = HBA; */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pkt, (sizeof (fc_packet_t) + sizeof (emlxs_buf_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte kmem_free(pkt, (sizeof (fc_packet_t) + sizeof (emlxs_buf_t)));
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_free() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte/* Default pkt callback routine */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_callback() */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteemlxs_pkt_alloc(emlxs_port_t *port, uint32_t cmdlen, uint32_t rsplen,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte unsigned long real_len;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_size = sizeof (fc_packet_t) + sizeof (emlxs_buf_t) +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_size = sizeof (fc_packet_t) + sizeof (emlxs_buf_t);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate some space */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (!(pkt = (fc_packet_t *)kmem_alloc(pkt_size, sleep))) {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte cb = (sleep == KM_SLEEP) ? DDI_DMA_SLEEP : DDI_DMA_DONTWAIT;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_fca_private = (opaque_t)((uintptr_t)pkt +
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt->pkt_tran_flags = (FC_TRAN_CLASS3 | FC_TRAN_INTR);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte pkt_cookie = (emlxs_pkt_cookie_t *)((uintptr_t)pkt +
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 /* Allocate the cmd buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
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 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 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#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the rsp buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
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 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 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#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the data buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Allocate the rsp buf */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (ddi_dma_alloc_handle(hba->dip, &emlxs_dma_attr_1sg, cb,
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 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 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#endif /* >= EMLXS_MODREV3 */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte#endif /* >= EMLXS_MODREV3 */
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan bzero((void *)sbp, sizeof (emlxs_buf_t));
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan mutex_init(&sbp->mtx, NULL, MUTEX_DRIVER, (void *)hba->intr_arg);
728bdc9be5faf84b5dca42f545967bd4910d608eSukumar Swaminathan sbp->pkt_flags = PACKET_VALID | PACKET_RETURNED | PACKET_ALLOCATED;
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte} /* emlxs_pkt_alloc() */