Path: blob/master/drivers/infiniband/hw/ehca/ehca_sqp.c
15112 views
/*1* IBM eServer eHCA Infiniband device driver for Linux on POWER2*3* SQP functions4*5* Authors: Khadija Souissi <[email protected]>6* Heiko J Schick <[email protected]>7*8* Copyright (c) 2005 IBM Corporation9*10* All rights reserved.11*12* This source code is distributed under a dual license of GPL v2.0 and OpenIB13* BSD.14*15* OpenIB BSD License16*17* Redistribution and use in source and binary forms, with or without18* modification, are permitted provided that the following conditions are met:19*20* Redistributions of source code must retain the above copyright notice, this21* list of conditions and the following disclaimer.22*23* Redistributions in binary form must reproduce the above copyright notice,24* this list of conditions and the following disclaimer in the documentation25* and/or other materials26* provided with the distribution.27*28* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"29* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE30* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE31* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE32* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR33* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF34* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR35* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER36* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)37* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE38* POSSIBILITY OF SUCH DAMAGE.39*/4041#include <rdma/ib_mad.h>4243#include "ehca_classes.h"44#include "ehca_tools.h"45#include "ehca_iverbs.h"46#include "hcp_if.h"4748#define IB_MAD_STATUS_REDIRECT cpu_to_be16(0x0002)49#define IB_MAD_STATUS_UNSUP_VERSION cpu_to_be16(0x0004)50#define IB_MAD_STATUS_UNSUP_METHOD cpu_to_be16(0x0008)5152#define IB_PMA_CLASS_PORT_INFO cpu_to_be16(0x0001)5354/**55* ehca_define_sqp - Defines special queue pair 1 (GSI QP). When special queue56* pair is created successfully, the corresponding port gets active.57*58* Define Special Queue pair 0 (SMI QP) is still not supported.59*60* @qp_init_attr: Queue pair init attributes with port and queue pair type61*/6263u64 ehca_define_sqp(struct ehca_shca *shca,64struct ehca_qp *ehca_qp,65struct ib_qp_init_attr *qp_init_attr)66{67u32 pma_qp_nr, bma_qp_nr;68u64 ret;69u8 port = qp_init_attr->port_num;70int counter;7172shca->sport[port - 1].port_state = IB_PORT_DOWN;7374switch (qp_init_attr->qp_type) {75case IB_QPT_SMI:76/* function not supported yet */77break;78case IB_QPT_GSI:79ret = hipz_h_define_aqp1(shca->ipz_hca_handle,80ehca_qp->ipz_qp_handle,81ehca_qp->galpas.kernel,82(u32) qp_init_attr->port_num,83&pma_qp_nr, &bma_qp_nr);8485if (ret != H_SUCCESS) {86ehca_err(&shca->ib_device,87"Can't define AQP1 for port %x. h_ret=%lli",88port, ret);89return ret;90}91shca->sport[port - 1].pma_qp_nr = pma_qp_nr;92ehca_dbg(&shca->ib_device, "port=%x pma_qp_nr=%x",93port, pma_qp_nr);94break;95default:96ehca_err(&shca->ib_device, "invalid qp_type=%x",97qp_init_attr->qp_type);98return H_PARAMETER;99}100101if (ehca_nr_ports < 0) /* autodetect mode */102return H_SUCCESS;103104for (counter = 0;105shca->sport[port - 1].port_state != IB_PORT_ACTIVE &&106counter < ehca_port_act_time;107counter++) {108ehca_dbg(&shca->ib_device, "... wait until port %x is active",109port);110msleep_interruptible(1000);111}112113if (counter == ehca_port_act_time) {114ehca_err(&shca->ib_device, "Port %x is not active.", port);115return H_HARDWARE;116}117118return H_SUCCESS;119}120121struct ib_perf {122struct ib_mad_hdr mad_hdr;123u8 reserved[40];124u8 data[192];125} __attribute__ ((packed));126127/* TC/SL/FL packed into 32 bits, as in ClassPortInfo */128struct tcslfl {129u32 tc:8;130u32 sl:4;131u32 fl:20;132} __attribute__ ((packed));133134/* IP Version/TC/FL packed into 32 bits, as in GRH */135struct vertcfl {136u32 ver:4;137u32 tc:8;138u32 fl:20;139} __attribute__ ((packed));140141static int ehca_process_perf(struct ib_device *ibdev, u8 port_num,142struct ib_wc *in_wc, struct ib_grh *in_grh,143struct ib_mad *in_mad, struct ib_mad *out_mad)144{145struct ib_perf *in_perf = (struct ib_perf *)in_mad;146struct ib_perf *out_perf = (struct ib_perf *)out_mad;147struct ib_class_port_info *poi =148(struct ib_class_port_info *)out_perf->data;149struct tcslfl *tcslfl =150(struct tcslfl *)&poi->redirect_tcslfl;151struct ehca_shca *shca =152container_of(ibdev, struct ehca_shca, ib_device);153struct ehca_sport *sport = &shca->sport[port_num - 1];154155ehca_dbg(ibdev, "method=%x", in_perf->mad_hdr.method);156157*out_mad = *in_mad;158159if (in_perf->mad_hdr.class_version != 1) {160ehca_warn(ibdev, "Unsupported class_version=%x",161in_perf->mad_hdr.class_version);162out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_VERSION;163goto perf_reply;164}165166switch (in_perf->mad_hdr.method) {167case IB_MGMT_METHOD_GET:168case IB_MGMT_METHOD_SET:169/* set class port info for redirection */170out_perf->mad_hdr.attr_id = IB_PMA_CLASS_PORT_INFO;171out_perf->mad_hdr.status = IB_MAD_STATUS_REDIRECT;172memset(poi, 0, sizeof(*poi));173poi->base_version = 1;174poi->class_version = 1;175poi->resp_time_value = 18;176177/* copy local routing information from WC where applicable */178tcslfl->sl = in_wc->sl;179poi->redirect_lid =180sport->saved_attr.lid | in_wc->dlid_path_bits;181poi->redirect_qp = sport->pma_qp_nr;182poi->redirect_qkey = IB_QP1_QKEY;183184ehca_query_pkey(ibdev, port_num, in_wc->pkey_index,185&poi->redirect_pkey);186187/* if request was globally routed, copy route info */188if (in_grh) {189struct vertcfl *vertcfl =190(struct vertcfl *)&in_grh->version_tclass_flow;191memcpy(poi->redirect_gid, in_grh->dgid.raw,192sizeof(poi->redirect_gid));193tcslfl->tc = vertcfl->tc;194tcslfl->fl = vertcfl->fl;195} else196/* else only fill in default GID */197ehca_query_gid(ibdev, port_num, 0,198(union ib_gid *)&poi->redirect_gid);199200ehca_dbg(ibdev, "ehca_pma_lid=%x ehca_pma_qp=%x",201sport->saved_attr.lid, sport->pma_qp_nr);202break;203204case IB_MGMT_METHOD_GET_RESP:205return IB_MAD_RESULT_FAILURE;206207default:208out_perf->mad_hdr.status = IB_MAD_STATUS_UNSUP_METHOD;209break;210}211212perf_reply:213out_perf->mad_hdr.method = IB_MGMT_METHOD_GET_RESP;214215return IB_MAD_RESULT_SUCCESS | IB_MAD_RESULT_REPLY;216}217218int ehca_process_mad(struct ib_device *ibdev, int mad_flags, u8 port_num,219struct ib_wc *in_wc, struct ib_grh *in_grh,220struct ib_mad *in_mad, struct ib_mad *out_mad)221{222int ret;223224if (!port_num || port_num > ibdev->phys_port_cnt || !in_wc)225return IB_MAD_RESULT_FAILURE;226227/* accept only pma request */228if (in_mad->mad_hdr.mgmt_class != IB_MGMT_CLASS_PERF_MGMT)229return IB_MAD_RESULT_SUCCESS;230231ehca_dbg(ibdev, "port_num=%x src_qp=%x", port_num, in_wc->src_qp);232ret = ehca_process_perf(ibdev, port_num, in_wc, in_grh,233in_mad, out_mad);234235return ret;236}237238239