30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * CDDL HEADER START
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * The contents of this file are subject to the terms of the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Common Development and Distribution License (the "License").
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * You may not use this file except in compliance with the License.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * See the License for the specific language governing permissions
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * and limitations under the License.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * When distributing Covered Code, include this CDDL HEADER in each
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * If applicable, add the following below this CDDL HEADER, with the
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * fields enclosed by brackets "[]" replaced with your own identifying
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * information: Portions Copyright [yyyy] [name of copyright owner]
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * CDDL HEADER END
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Use is subject to license terms.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_hello_msg: no hca handle found");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_hello_msg: iser message cache "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "alloc failed");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Send iSER Hello Message to declare iSER parameters to the target */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap hdr = (iser_hello_hdr_t *)(uintptr_t)msg->msg_ds.ds_va;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Allocate an iSER WR handle and tuck this msg into it */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_hello_msg: unable to allocate "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iser wr handle");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Use the address of our generic iser_wr handle as our WRID */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Populate the rest of the work request */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan * Avoid race condition by incrementing this channel's
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan * SQ posted count prior to calling ibt_post_send
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if (chan->ic_sq_post_count > chan->ic_sq_max_post_count)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan chan->ic_sq_max_post_count = chan->ic_sq_post_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = ibt_post_send(chan->ic_chanhdl, &wr, 1, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_hello_msg: ibt_post_send "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "Posting iSER Hello message: chan (0x%p): "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "IP [%x to %x]", (void *)chan, chan->ic_localip.un.ip4addr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_helloreply_msg: no hca handle "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_helloreply_msg: iser message "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "cache alloc failed");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Use the iSER Hello Reply Message */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap hdr = (iser_helloreply_hdr_t *)(uintptr_t)msg->msg_ds.ds_va;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Allocate an iSER WR handle and tuck this msg into it */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_helloreply_msg: unable to "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "allocate iser wr handle");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Use the address of our generic iser_wr handle as our WRID */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Populate the rest of the work request */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if (chan->ic_sq_post_count > chan->ic_sq_max_post_count)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan chan->ic_sq_max_post_count = chan->ic_sq_post_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = ibt_post_send(chan->ic_chanhdl, &wr, 1, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_helloreply_msg: ibt_post_send "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "Posting iSER HelloReply message: chan (0x%p): "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "IP [%x to %x]", (void *)chan, chan->ic_localip.un.ip4addr,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iser_xfer_ctrlpdu
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This is iSER's implementation of the 'Send_control' operational primitive.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This iSER layer uses the Send Message type of RCaP to transfer the iSCSI
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Control-type PDU. A special case is that the transfer of SCSI Data-out PDUs
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * carrying unsolicited data are also treated as iSCSI Control-Type PDUs. The
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * message payload contains an iSER header followed by the iSCSI Control-type
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * the iSCSI Control-type PDU.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This function is invoked by an initiator iSCSI layer requesting the transfer
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * of a iSCSI command PDU or a target iSCSI layer requesting the transfer of a
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iSCSI response PDU.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiser_xfer_ctrlpdu(iser_chan_t *chan, idm_pdu_t *pdu)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Bail out if the connection is closed */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if ((chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSING) ||
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan (chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSED)) {
60220f10412f6a7c5b45f950f6f6aa364658a179Priya Krishnan /* Pull the BHS out of the PDU handle */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * All SCSI command PDU (except SCSI Read and SCSI Write) and the SCSI
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Response PDU are sent to the remote end using the SendSE Message.
60220f10412f6a7c5b45f950f6f6aa364658a179Priya Krishnan * The StatSN may need to be sent (and possibly advanced) at this time
60220f10412f6a7c5b45f950f6f6aa364658a179Priya Krishnan * for some PDUs, identified by the IDM_PDU_SET_STATSN flag.
60220f10412f6a7c5b45f950f6f6aa364658a179Priya Krishnan (ic->ic_conn_ops.icb_update_statsn)(NULL, pdu);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Setup a Send Message for carrying the iSCSI control-type PDU
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * preceeded by an iSER header.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_ctrlpdu: no hca handle found");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_ctrlpdu: iser message cache "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "alloc failed");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap hdr = (iser_ctrl_hdr_t *)(uintptr_t)msg->msg_ds.ds_va;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Initialize header assuming no transfers
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * On the initiator side, the task buffers will be used to identify
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * if there are any buffers to be advertised
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ((bhs->opcode & ISCSI_OPCODE_MASK) == ISCSI_OP_SCSI_CMD) &&
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ((idt = idm_task_find(ic, bhs->itt, bhs->ttt)) != NULL)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Release our reference on the task */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Copy the BHS after the iSER header */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap (uint8_t *)(uintptr_t)msg->msg_ds.ds_va + ISER_HEADER_LENGTH,
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Copy the isp_data after the PDU header */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Set the SGE's ds_len */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap msg->msg_ds.ds_len = ISER_HEADER_LENGTH + pdu->isp_hdrlen +
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* No data, so set the SGE's ds_len to the headers length */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap msg->msg_ds.ds_len = ISER_HEADER_LENGTH + pdu->isp_hdrlen;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Build Work Request to be posted on the Send Queue.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Allocate an iSER WR handle and tuck the msg and pdu into it */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_ctrlpdu: unable to allocate "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iser wr handle");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * Use the address of our generic iser_wr handle as our WRID
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * and populate the rest of the work request
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Increment this channel's SQ posted count */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if (chan->ic_sq_post_count > chan->ic_sq_max_post_count)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan chan->ic_sq_max_post_count = chan->ic_sq_post_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Post Send Work Request on the specified channel */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = ibt_post_send(chan->ic_chanhdl, &wr, 1, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_ctrlpdu: ibt_post_send "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iser_xfer_buf_to_ini
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This is iSER's implementation of the 'Put_Data' operational primitive.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * The iSCSI layer at the target invokes this function when it is ready to
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * return the SCSI Read Data to the initiator. This function generates and
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * sends an RDMA Write Message containing the read data to the initiator.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiser_xfer_buf_to_ini(idm_task_t *idt, idm_buf_t *buf)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Grab the iSER resources from the task and buf handles */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iser_conn = (iser_conn_t *)idt->idt_ic->ic_transport_private;
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Bail out if the connection is closed */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if ((iser_chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSING) ||
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan (iser_chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSED)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iser_hdr = (iser_ctrl_hdr_t *)idt->idt_transport_hdr;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Pull the Read STag data out of the iSER header in the task hdl */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Set up the WR raddr and rkey based upon the Read iSER STag */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap wr.wr.rc.rcwr.rdma.rdma_raddr = reg_raddr + buf->idb_bufoffset;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Set the transfer length from the IDM buf handle */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Allocate an iSER WR handle and tuck the IDM buf handle into it */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_buf_to_ini: unable to allocate "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iser wr handle");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Use the address of our generic iser_wr handle as our WRID */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Populate the rest of the work request */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&wr, &iser_buf->buf_wr, sizeof (ibt_send_wr_t));
a668b114487acbb725f522170849c39f8e844673Priya Krishnan DTRACE_ISCSI_8(xfer__start, idm_conn_t *, idt->idt_ic,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uintptr_t, buf->idb_buf, uint32_t, buf->idb_bufoffset,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uint64_t, reg_raddr, uint32_t, buf->idb_bufoffset,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uint32_t, buf->idb_xfer_len, int, XFER_BUF_TX_TO_INI);
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Increment this channel's SQ posted count */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if (iser_chan->ic_sq_post_count > iser_chan->ic_sq_max_post_count)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan iser_chan->ic_sq_max_post_count = iser_chan->ic_sq_post_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = ibt_post_send(iser_chan->ic_chanhdl, &wr, 1, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_buf_to_ini: ibt_post_send "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * iser_xfer_buf_from_ini
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * This is iSER's implementation of the 'Get_Data' operational primitive.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * The iSCSI layer at the target invokes this function when it is ready to
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * receive the SCSI Write Data from the initiator. This function generates and
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * sends an RDMA Read Message to get the data from the initiator. No R2T PDUs
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap * are generated.
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlapiser_xfer_buf_from_ini(idm_task_t *idt, idm_buf_t *buf)
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Grab the iSER resources from the task and buf handles */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iser_conn = (iser_conn_t *)idt->idt_ic->ic_transport_private;
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Bail out if the connection is closed */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if ((iser_chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSING) ||
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan (iser_chan->ic_conn->ic_stage == ISER_CONN_STAGE_CLOSED)) {
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap iser_hdr = (iser_ctrl_hdr_t *)idt->idt_transport_hdr;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Pull the Write STag data out of the iSER header in the task hdl */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Set up the WR raddr and rkey based upon the iSER Write STag */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap wr.wr.rc.rcwr.rdma.rdma_raddr = reg_raddr + buf->idb_bufoffset;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Set the transfer length from the IDM buf handle */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Allocate an iSER WR handle and tuck the IDM buf handle into it */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_buf_from_ini: unable to allocate "
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap "iser wr handle");
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Use the address of our generic iser_wr handle as our WRID */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap /* Populate the rest of the work request */
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap bcopy(&wr, &iser_buf->buf_wr, sizeof (ibt_send_wr_t));
a668b114487acbb725f522170849c39f8e844673Priya Krishnan DTRACE_ISCSI_8(xfer__start, idm_conn_t *, idt->idt_ic,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uintptr_t, buf->idb_buf, uint32_t, buf->idb_bufoffset,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uint64_t, reg_raddr, uint32_t, buf->idb_bufoffset,
a668b114487acbb725f522170849c39f8e844673Priya Krishnan uint32_t, buf->idb_xfer_len, int, XFER_BUF_RX_FROM_INI);
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan /* Increment this channel's SQ posted count */
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan if (iser_chan->ic_sq_post_count > iser_chan->ic_sq_max_post_count)
a82ec3cf2b07d0f2ebb2e60f41370b7c39a5e71ePriya Krishnan iser_chan->ic_sq_max_post_count = iser_chan->ic_sq_post_count;
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap status = ibt_post_send(iser_chan->ic_chanhdl, &wr, 1, NULL);
30e7468f8f41aa30ada067b2c1d5d284046514daPeter Dunlap ISER_LOG(CE_NOTE, "iser_xfer_buf_from_ini: ibt_post_send "