17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * CDDL HEADER START
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * The contents of this file are subject to the terms of the
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Common Development and Distribution License (the "License").
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * You may not use this file except in compliance with the License.
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * See the License for the specific language governing permissions
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * and limitations under the License.
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * When distributing Covered Code, include this CDDL HEADER in each
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * If applicable, add the following below this CDDL HEADER, with the
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * fields enclosed by brackets "[]" replaced with your own identifying
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * information: Portions Copyright [yyyy] [name of copyright owner]
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * CDDL HEADER END
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Copyright (c) 2010, Oracle and/or its affiliates. All rights reserved.
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Hermon Fibre Channel over IB routines
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Implements all the routines necessary for setting up, using, and
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * (later) tearing down all the FCoIB state.
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_enable()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_enable(hermon_state_t *state, int port)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor port--; /* passed in as 1 or 2, used as 0 or 1 */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* Configure FCoIB on the port */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor bzero(&config_fc_basic, sizeof (config_fc_basic));
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor config_fc_basic.fexch_base_hi = fcoib->hfc_fexch_base[port] >> 16;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor config_fc_basic.fx_base_mpt_hi = fcoib->hfc_mpt_base[port] >> 17;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor state->hs_ibtfinfo.hca_attr->hca_rfci_max_log2_qp;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor config_fc_basic.rfci_base = fcoib->hfc_rfci_qps_per_port * port +
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_config_fc_cmd_post(state, &config_fc_basic, 1,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor HERMON_HW_FC_CONF_BASIC, 0, port + 1, HERMON_CMD_NOSLEEP_SPIN);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_config_fc_cmd_post(state, &config_fc_basic, 1,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor HERMON_HW_FC_CONF_BASIC, 0, 0, HERMON_CMD_NOSLEEP_SPIN);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor cmn_err(CE_CONT, "fcoib_enable failed: status 0x%x\n", status);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_set_id()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_set_id(hermon_state_t *state, int port, uint32_t rfci_qpn,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor port--; /* passed in as 1 or 2, used as 0 or 1 */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (hermon_fcoib_enable(state, port + 1) != DDI_SUCCESS) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor ASSERT(offset >= 0 && offset < fcoib->hfc_rfci_qps_per_port);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_config_fc_cmd_post(state, n_port_ids, 1,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor HERMON_HW_FC_CONF_NPORT, fcoib->hfc_rfci_qps_per_port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_get_id_idx()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_get_id_idx(hermon_state_t *state, int port, ibt_fc_attr_t *fcp)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor port--; /* passed in as 1 or 2, used as 0 or 1 */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor idx = fcp->fc_rfci_qpn - fcoib->hfc_rfci_base[port];
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (idx < 0 || idx >= fcoib->hfc_rfci_qps_per_port)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_get_exch_base()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_check_exch_base_off(hermon_state_t *state, int port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor port--; /* passed in as 1 or 2, used as 0 or 1 */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (exch_base_off >= fcoib->hfc_fexch_qps_per_port)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_qpnum_from_fexch()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user, kernel, or interrupt context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_is_fexch_qpn(hermon_state_t *state, uint_t qpnum)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor return (qpnum < fcoib->hfc_nports * fcoib->hfc_fexch_qps_per_port);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_qpnum_from_fexch()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user, kernel, or interrupt context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_qpnum_from_fexch(hermon_state_t *state, int port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor port--; /* passed in as 1 or 2, used as 0 or 1 */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_qpn_to_mkey
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_qpn_to_mkey(hermon_state_t *state, uint_t qpnum)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor return ((qp_indx + fcoib->hfc_mpt_base[i]) << 8);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor return ((uint32_t)-1); /* cannot get here with valid qpnum argument */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_fexch_relative_qpn()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_fexch_relative_qpn(hermon_state_t *state, uint8_t port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor qp_indx -= state->hs_fcoib.hfc_fexch_base[port];
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_fexch_mkey_init()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_fexch_mkey_init(hermon_state_t *state, hermon_pdhdl_t pd,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor qp_indx -= fcoib->hfc_fexch_base[port]; /* relative to FEXCH base */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor mtt_addr = ((uint64_t)qp_indx * nummtt + fcoib->hfc_mtt_base[port]) <<
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_mr_fexch_mpt_init(state, pd, mpt_indx,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_fexch_mkey_fini()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_fexch_mkey_fini(hermon_state_t *state, hermon_pdhdl_t pd,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor for (port = 0; port < fcoib->hfc_nports; port++) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* qp_indx relative to FEXCH base */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_mr_fexch_mpt_fini(state, pd, mpt_indx, sleep);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_query_fc()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: user or kernel context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylorhermon_fcoib_query_fc(hermon_state_t *state, hermon_fcoib_t *fcoib)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor status = hermon_cmn_query_cmd_post(state, QUERY_FC, 0, 0, &query_fc,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_log2_max_port_ids_queried = query_fc.log2_max_nports;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_log2_max_fexch_queried = query_fc.log2_max_fexch;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_log2_max_rfci_queried = query_fc.log2_max_rfci;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor cmn_err(CE_CONT, "!query_fc status 0x%x\n", status);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_init()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: Only called from attach() path context
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* used for fast checking for FCoIB during cqe_consume */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if ((state->hs_ibtfinfo.hca_attr->hca_flags2 & IBT_HCA2_FC) == 0)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor mutex_init(&fcoib->hfc_lock, NULL, MUTEX_DRIVER, NULL);
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* use a ROUND value that works on both 32 and 64-bit kernels */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_nports = numports = state->hs_cfg_profile->cp_num_ports;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor 1 << state->hs_ibtfinfo.hca_attr->hca_fexch_max_log2_qp;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_mpts_per_port = fcoib->hfc_fexch_qps_per_port * 2;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (1 << state->hs_ibtfinfo.hca_attr->hca_fexch_max_log2_mem) >>
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor 1 << state->hs_ibtfinfo.hca_attr->hca_rfci_max_log2_qp;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (hermon_rsrc_reserve(state, HERMON_DMPT, numports *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Only reserve MTTs for the Primary MPTs (first half of the
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * range for each port).
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (hermon_rsrc_reserve(state, HERMON_MTT, numports *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_mpts_per_port * fcoib->hfc_mtts_per_mpt / 2,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor HERMON_SLEEP, &fcoib->hfc_mtt_rsrc) != DDI_SUCCESS) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (hermon_rsrc_reserve(state, HERMON_QPC, numports *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if (hermon_rsrc_reserve(state, HERMON_QPC, numports *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor for (i = 0; i < numports; i++) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_n_port_ids[i] = kmem_zalloc(sizeof (uint32_t) *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_mpt_base[i] = i * fcoib->hfc_mpts_per_port +
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* "/ 2" is for Secondary MKEYs never used on Client side */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_mtt_base[i] = (i * fcoib->hfc_mpts_per_port *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_mtts_per_mpt / 2) + fcoib->hfc_mtt_rsrc->hr_indx;
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_fexch_base[i] = i * fcoib->hfc_fexch_qps_per_port +
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor fcoib->hfc_rfci_base[i] = i * fcoib->hfc_rfci_qps_per_port +
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* init FEXCH QP rsrc pool */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (void) sprintf(string, "hermon%d_port%d_fexch_vmem",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (void *)vmemstart, fcoib->hfc_fexch_qps_per_port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* init RFCI QP rsrc pool */
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (void) sprintf(string, "hermon%d_port%d_rfci_vmem",
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor (void *)vmemstart, fcoib->hfc_rfci_qps_per_port,
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * hermon_fcoib_fini()
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor * Context: Only called from attach() and/or detach() path contexts
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor if ((state->hs_ibtfinfo.hca_attr->hca_flags2 & IBT_HCA2_FC) == 0)
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor for (i = 0; i < numports; i++) {
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor kmem_free(fcoib->hfc_n_port_ids[i], sizeof (uint32_t) *
17a2b317610f531d565bf4e940433aab2d9e6985Bill Taylor /* XXX --- should we issue HERMON_HW_FC_CONF_BASIC disable? */