Path: blob/master/drivers/infiniband/hw/ehca/ehca_hca.c
15112 views
/*1* IBM eServer eHCA Infiniband device driver for Linux on POWER2*3* HCA query functions4*5* Authors: Heiko J Schick <[email protected]>6* Christoph Raisch <[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 <linux/gfp.h>4243#include "ehca_tools.h"44#include "ehca_iverbs.h"45#include "hcp_if.h"4647static unsigned int limit_uint(unsigned int value)48{49return min_t(unsigned int, value, INT_MAX);50}5152int ehca_query_device(struct ib_device *ibdev, struct ib_device_attr *props)53{54int i, ret = 0;55struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,56ib_device);57struct hipz_query_hca *rblock;5859static const u32 cap_mapping[] = {60IB_DEVICE_RESIZE_MAX_WR, HCA_CAP_WQE_RESIZE,61IB_DEVICE_BAD_PKEY_CNTR, HCA_CAP_BAD_P_KEY_CTR,62IB_DEVICE_BAD_QKEY_CNTR, HCA_CAP_Q_KEY_VIOL_CTR,63IB_DEVICE_RAW_MULTI, HCA_CAP_RAW_PACKET_MCAST,64IB_DEVICE_AUTO_PATH_MIG, HCA_CAP_AUTO_PATH_MIG,65IB_DEVICE_CHANGE_PHY_PORT, HCA_CAP_SQD_RTS_PORT_CHANGE,66IB_DEVICE_UD_AV_PORT_ENFORCE, HCA_CAP_AH_PORT_NR_CHECK,67IB_DEVICE_CURR_QP_STATE_MOD, HCA_CAP_CUR_QP_STATE_MOD,68IB_DEVICE_SHUTDOWN_PORT, HCA_CAP_SHUTDOWN_PORT,69IB_DEVICE_INIT_TYPE, HCA_CAP_INIT_TYPE,70IB_DEVICE_PORT_ACTIVE_EVENT, HCA_CAP_PORT_ACTIVE_EVENT,71};7273rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);74if (!rblock) {75ehca_err(&shca->ib_device, "Can't allocate rblock memory.");76return -ENOMEM;77}7879if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {80ehca_err(&shca->ib_device, "Can't query device properties");81ret = -EINVAL;82goto query_device1;83}8485memset(props, 0, sizeof(struct ib_device_attr));86props->page_size_cap = shca->hca_cap_mr_pgsize;87props->fw_ver = rblock->hw_ver;88props->max_mr_size = rblock->max_mr_size;89props->vendor_id = rblock->vendor_id >> 8;90props->vendor_part_id = rblock->vendor_part_id >> 16;91props->hw_ver = rblock->hw_ver;92props->max_qp = limit_uint(rblock->max_qp);93props->max_qp_wr = limit_uint(rblock->max_wqes_wq);94props->max_sge = limit_uint(rblock->max_sge);95props->max_sge_rd = limit_uint(rblock->max_sge_rd);96props->max_cq = limit_uint(rblock->max_cq);97props->max_cqe = limit_uint(rblock->max_cqe);98props->max_mr = limit_uint(rblock->max_mr);99props->max_mw = limit_uint(rblock->max_mw);100props->max_pd = limit_uint(rblock->max_pd);101props->max_ah = limit_uint(rblock->max_ah);102props->max_ee = limit_uint(rblock->max_rd_ee_context);103props->max_rdd = limit_uint(rblock->max_rd_domain);104props->max_fmr = limit_uint(rblock->max_mr);105props->max_qp_rd_atom = limit_uint(rblock->max_rr_qp);106props->max_ee_rd_atom = limit_uint(rblock->max_rr_ee_context);107props->max_res_rd_atom = limit_uint(rblock->max_rr_hca);108props->max_qp_init_rd_atom = limit_uint(rblock->max_act_wqs_qp);109props->max_ee_init_rd_atom = limit_uint(rblock->max_act_wqs_ee_context);110111if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {112props->max_srq = limit_uint(props->max_qp);113props->max_srq_wr = limit_uint(props->max_qp_wr);114props->max_srq_sge = 3;115}116117props->max_pkeys = 16;118/* Some FW versions say 0 here; insert sensible value in that case */119props->local_ca_ack_delay = rblock->local_ca_ack_delay ?120min_t(u8, rblock->local_ca_ack_delay, 255) : 12;121props->max_raw_ipv6_qp = limit_uint(rblock->max_raw_ipv6_qp);122props->max_raw_ethy_qp = limit_uint(rblock->max_raw_ethy_qp);123props->max_mcast_grp = limit_uint(rblock->max_mcast_grp);124props->max_mcast_qp_attach = limit_uint(rblock->max_mcast_qp_attach);125props->max_total_mcast_qp_attach126= limit_uint(rblock->max_total_mcast_qp_attach);127128/* translate device capabilities */129props->device_cap_flags = IB_DEVICE_SYS_IMAGE_GUID |130IB_DEVICE_RC_RNR_NAK_GEN | IB_DEVICE_N_NOTIFY_CQ;131for (i = 0; i < ARRAY_SIZE(cap_mapping); i += 2)132if (rblock->hca_cap_indicators & cap_mapping[i + 1])133props->device_cap_flags |= cap_mapping[i];134135query_device1:136ehca_free_fw_ctrlblock(rblock);137138return ret;139}140141static enum ib_mtu map_mtu(struct ehca_shca *shca, u32 fw_mtu)142{143switch (fw_mtu) {144case 0x1:145return IB_MTU_256;146case 0x2:147return IB_MTU_512;148case 0x3:149return IB_MTU_1024;150case 0x4:151return IB_MTU_2048;152case 0x5:153return IB_MTU_4096;154default:155ehca_err(&shca->ib_device, "Unknown MTU size: %x.",156fw_mtu);157return 0;158}159}160161static u8 map_number_of_vls(struct ehca_shca *shca, u32 vl_cap)162{163switch (vl_cap) {164case 0x1:165return 1;166case 0x2:167return 2;168case 0x3:169return 4;170case 0x4:171return 8;172case 0x5:173return 15;174default:175ehca_err(&shca->ib_device, "invalid Vl Capability: %x.",176vl_cap);177return 0;178}179}180181int ehca_query_port(struct ib_device *ibdev,182u8 port, struct ib_port_attr *props)183{184int ret = 0;185u64 h_ret;186struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,187ib_device);188struct hipz_query_port *rblock;189190rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);191if (!rblock) {192ehca_err(&shca->ib_device, "Can't allocate rblock memory.");193return -ENOMEM;194}195196h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);197if (h_ret != H_SUCCESS) {198ehca_err(&shca->ib_device, "Can't query port properties");199ret = -EINVAL;200goto query_port1;201}202203memset(props, 0, sizeof(struct ib_port_attr));204205props->active_mtu = props->max_mtu = map_mtu(shca, rblock->max_mtu);206props->port_cap_flags = rblock->capability_mask;207props->gid_tbl_len = rblock->gid_tbl_len;208if (rblock->max_msg_sz)209props->max_msg_sz = rblock->max_msg_sz;210else211props->max_msg_sz = 0x1 << 31;212props->bad_pkey_cntr = rblock->bad_pkey_cntr;213props->qkey_viol_cntr = rblock->qkey_viol_cntr;214props->pkey_tbl_len = rblock->pkey_tbl_len;215props->lid = rblock->lid;216props->sm_lid = rblock->sm_lid;217props->lmc = rblock->lmc;218props->sm_sl = rblock->sm_sl;219props->subnet_timeout = rblock->subnet_timeout;220props->init_type_reply = rblock->init_type_reply;221props->max_vl_num = map_number_of_vls(shca, rblock->vl_cap);222223if (rblock->state && rblock->phys_width) {224props->phys_state = rblock->phys_pstate;225props->state = rblock->phys_state;226props->active_width = rblock->phys_width;227props->active_speed = rblock->phys_speed;228} else {229/* old firmware releases don't report physical230* port info, so use default values231*/232props->phys_state = 5;233props->state = rblock->state;234props->active_width = IB_WIDTH_12X;235props->active_speed = 0x1;236}237238query_port1:239ehca_free_fw_ctrlblock(rblock);240241return ret;242}243244int ehca_query_sma_attr(struct ehca_shca *shca,245u8 port, struct ehca_sma_attr *attr)246{247int ret = 0;248u64 h_ret;249struct hipz_query_port *rblock;250251rblock = ehca_alloc_fw_ctrlblock(GFP_ATOMIC);252if (!rblock) {253ehca_err(&shca->ib_device, "Can't allocate rblock memory.");254return -ENOMEM;255}256257h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);258if (h_ret != H_SUCCESS) {259ehca_err(&shca->ib_device, "Can't query port properties");260ret = -EINVAL;261goto query_sma_attr1;262}263264memset(attr, 0, sizeof(struct ehca_sma_attr));265266attr->lid = rblock->lid;267attr->lmc = rblock->lmc;268attr->sm_sl = rblock->sm_sl;269attr->sm_lid = rblock->sm_lid;270271attr->pkey_tbl_len = rblock->pkey_tbl_len;272memcpy(attr->pkeys, rblock->pkey_entries, sizeof(attr->pkeys));273274query_sma_attr1:275ehca_free_fw_ctrlblock(rblock);276277return ret;278}279280int ehca_query_pkey(struct ib_device *ibdev, u8 port, u16 index, u16 *pkey)281{282int ret = 0;283u64 h_ret;284struct ehca_shca *shca;285struct hipz_query_port *rblock;286287shca = container_of(ibdev, struct ehca_shca, ib_device);288if (index > 16) {289ehca_err(&shca->ib_device, "Invalid index: %x.", index);290return -EINVAL;291}292293rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);294if (!rblock) {295ehca_err(&shca->ib_device, "Can't allocate rblock memory.");296return -ENOMEM;297}298299h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);300if (h_ret != H_SUCCESS) {301ehca_err(&shca->ib_device, "Can't query port properties");302ret = -EINVAL;303goto query_pkey1;304}305306memcpy(pkey, &rblock->pkey_entries + index, sizeof(u16));307308query_pkey1:309ehca_free_fw_ctrlblock(rblock);310311return ret;312}313314int ehca_query_gid(struct ib_device *ibdev, u8 port,315int index, union ib_gid *gid)316{317int ret = 0;318u64 h_ret;319struct ehca_shca *shca = container_of(ibdev, struct ehca_shca,320ib_device);321struct hipz_query_port *rblock;322323if (index < 0 || index > 255) {324ehca_err(&shca->ib_device, "Invalid index: %x.", index);325return -EINVAL;326}327328rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);329if (!rblock) {330ehca_err(&shca->ib_device, "Can't allocate rblock memory.");331return -ENOMEM;332}333334h_ret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);335if (h_ret != H_SUCCESS) {336ehca_err(&shca->ib_device, "Can't query port properties");337ret = -EINVAL;338goto query_gid1;339}340341memcpy(&gid->raw[0], &rblock->gid_prefix, sizeof(u64));342memcpy(&gid->raw[8], &rblock->guid_entries[index], sizeof(u64));343344query_gid1:345ehca_free_fw_ctrlblock(rblock);346347return ret;348}349350static const u32 allowed_port_caps = (351IB_PORT_SM | IB_PORT_LED_INFO_SUP | IB_PORT_CM_SUP |352IB_PORT_SNMP_TUNNEL_SUP | IB_PORT_DEVICE_MGMT_SUP |353IB_PORT_VENDOR_CLASS_SUP);354355int ehca_modify_port(struct ib_device *ibdev,356u8 port, int port_modify_mask,357struct ib_port_modify *props)358{359int ret = 0;360struct ehca_shca *shca;361struct hipz_query_port *rblock;362u32 cap;363u64 hret;364365shca = container_of(ibdev, struct ehca_shca, ib_device);366if ((props->set_port_cap_mask | props->clr_port_cap_mask)367& ~allowed_port_caps) {368ehca_err(&shca->ib_device, "Non-changeable bits set in masks "369"set=%x clr=%x allowed=%x", props->set_port_cap_mask,370props->clr_port_cap_mask, allowed_port_caps);371return -EINVAL;372}373374if (mutex_lock_interruptible(&shca->modify_mutex))375return -ERESTARTSYS;376377rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);378if (!rblock) {379ehca_err(&shca->ib_device, "Can't allocate rblock memory.");380ret = -ENOMEM;381goto modify_port1;382}383384hret = hipz_h_query_port(shca->ipz_hca_handle, port, rblock);385if (hret != H_SUCCESS) {386ehca_err(&shca->ib_device, "Can't query port properties");387ret = -EINVAL;388goto modify_port2;389}390391cap = (rblock->capability_mask | props->set_port_cap_mask)392& ~props->clr_port_cap_mask;393394hret = hipz_h_modify_port(shca->ipz_hca_handle, port,395cap, props->init_type, port_modify_mask);396if (hret != H_SUCCESS) {397ehca_err(&shca->ib_device, "Modify port failed h_ret=%lli",398hret);399ret = -EINVAL;400}401402modify_port2:403ehca_free_fw_ctrlblock(rblock);404405modify_port1:406mutex_unlock(&shca->modify_mutex);407408return ret;409}410411412