⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ehca_main.c

📁 linux内核源码
💻 C
📖 第 1 页 / 共 2 页
字号:
/* *  IBM eServer eHCA Infiniband device driver for Linux on POWER * *  module start stop, hca detection * *  Authors: Heiko J Schick <schickhj@de.ibm.com> *           Hoang-Nam Nguyen <hnguyen@de.ibm.com> *           Joachim Fenkes <fenkes@de.ibm.com> * *  Copyright (c) 2005 IBM Corporation * *  All rights reserved. * *  This source code is distributed under a dual license of GPL v2.0 and OpenIB *  BSD. * * OpenIB BSD License * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions are met: * * Redistributions of source code must retain the above copyright notice, this * list of conditions and the following disclaimer. * * Redistributions in binary form must reproduce the above copyright notice, * this list of conditions and the following disclaimer in the documentation * and/or other materials * provided with the distribution. * * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER * IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE * POSSIBILITY OF SUCH DAMAGE. */#ifdef CONFIG_PPC_64K_PAGES#include <linux/slab.h>#endif#include "ehca_classes.h"#include "ehca_iverbs.h"#include "ehca_mrmw.h"#include "ehca_tools.h"#include "hcp_if.h"#define HCAD_VERSION "0025"MODULE_LICENSE("Dual BSD/GPL");MODULE_AUTHOR("Christoph Raisch <raisch@de.ibm.com>");MODULE_DESCRIPTION("IBM eServer HCA InfiniBand Device Driver");MODULE_VERSION(HCAD_VERSION);int ehca_open_aqp1     = 0;int ehca_debug_level   = 0;int ehca_hw_level      = 0;int ehca_nr_ports      = 2;int ehca_use_hp_mr     = 0;int ehca_port_act_time = 30;int ehca_poll_all_eqs  = 1;int ehca_static_rate   = -1;int ehca_scaling_code  = 0;int ehca_mr_largepage  = 1;int ehca_lock_hcalls   = -1;module_param_named(open_aqp1,     ehca_open_aqp1,     int, S_IRUGO);module_param_named(debug_level,   ehca_debug_level,   int, S_IRUGO);module_param_named(hw_level,      ehca_hw_level,      int, S_IRUGO);module_param_named(nr_ports,      ehca_nr_ports,      int, S_IRUGO);module_param_named(use_hp_mr,     ehca_use_hp_mr,     int, S_IRUGO);module_param_named(port_act_time, ehca_port_act_time, int, S_IRUGO);module_param_named(poll_all_eqs,  ehca_poll_all_eqs,  int, S_IRUGO);module_param_named(static_rate,   ehca_static_rate,   int, S_IRUGO);module_param_named(scaling_code,  ehca_scaling_code,  int, S_IRUGO);module_param_named(mr_largepage,  ehca_mr_largepage,  int, S_IRUGO);module_param_named(lock_hcalls,   ehca_lock_hcalls,   bool, S_IRUGO);MODULE_PARM_DESC(open_aqp1,		 "AQP1 on startup (0: no (default), 1: yes)");MODULE_PARM_DESC(debug_level,		 "debug level"		 " (0: no debug traces (default), 1: with debug traces)");MODULE_PARM_DESC(hw_level,		 "hardware level"		 " (0: autosensing (default), 1: v. 0.20, 2: v. 0.21)");MODULE_PARM_DESC(nr_ports,		 "number of connected ports (default: 2)");MODULE_PARM_DESC(use_hp_mr,		 "high performance MRs (0: no (default), 1: yes)");MODULE_PARM_DESC(port_act_time,		 "time to wait for port activation (default: 30 sec)");MODULE_PARM_DESC(poll_all_eqs,		 "polls all event queues periodically"		 " (0: no, 1: yes (default))");MODULE_PARM_DESC(static_rate,		 "set permanent static rate (default: disabled)");MODULE_PARM_DESC(scaling_code,		 "set scaling code (0: disabled/default, 1: enabled)");MODULE_PARM_DESC(mr_largepage,		 "use large page for MR (0: use PAGE_SIZE (default), "		 "1: use large page depending on MR size");MODULE_PARM_DESC(lock_hcalls,		 "serialize all hCalls made by the driver "		 "(default: autodetect)");DEFINE_RWLOCK(ehca_qp_idr_lock);DEFINE_RWLOCK(ehca_cq_idr_lock);DEFINE_IDR(ehca_qp_idr);DEFINE_IDR(ehca_cq_idr);static LIST_HEAD(shca_list); /* list of all registered ehcas */static DEFINE_SPINLOCK(shca_list_lock);static struct timer_list poll_eqs_timer;#ifdef CONFIG_PPC_64K_PAGESstatic struct kmem_cache *ctblk_cache;void *ehca_alloc_fw_ctrlblock(gfp_t flags){	void *ret = kmem_cache_zalloc(ctblk_cache, flags);	if (!ret)		ehca_gen_err("Out of memory for ctblk");	return ret;}void ehca_free_fw_ctrlblock(void *ptr){	if (ptr)		kmem_cache_free(ctblk_cache, ptr);}#endifint ehca2ib_return_code(u64 ehca_rc){	switch (ehca_rc) {	case H_SUCCESS:		return 0;	case H_RESOURCE:             /* Resource in use */	case H_BUSY:		return -EBUSY;	case H_NOT_ENOUGH_RESOURCES: /* insufficient resources */	case H_CONSTRAINED:          /* resource constraint */	case H_NO_MEM:		return -ENOMEM;	default:		return -EINVAL;	}}static int ehca_create_slab_caches(void){	int ret;	ret = ehca_init_pd_cache();	if (ret) {		ehca_gen_err("Cannot create PD SLAB cache.");		return ret;	}	ret = ehca_init_cq_cache();	if (ret) {		ehca_gen_err("Cannot create CQ SLAB cache.");		goto create_slab_caches2;	}	ret = ehca_init_qp_cache();	if (ret) {		ehca_gen_err("Cannot create QP SLAB cache.");		goto create_slab_caches3;	}	ret = ehca_init_av_cache();	if (ret) {		ehca_gen_err("Cannot create AV SLAB cache.");		goto create_slab_caches4;	}	ret = ehca_init_mrmw_cache();	if (ret) {		ehca_gen_err("Cannot create MR&MW SLAB cache.");		goto create_slab_caches5;	}	ret = ehca_init_small_qp_cache();	if (ret) {		ehca_gen_err("Cannot create small queue SLAB cache.");		goto create_slab_caches6;	}#ifdef CONFIG_PPC_64K_PAGES	ctblk_cache = kmem_cache_create("ehca_cache_ctblk",					EHCA_PAGESIZE, H_CB_ALIGNMENT,					SLAB_HWCACHE_ALIGN,					NULL);	if (!ctblk_cache) {		ehca_gen_err("Cannot create ctblk SLAB cache.");		ehca_cleanup_small_qp_cache();		goto create_slab_caches6;	}#endif	return 0;create_slab_caches6:	ehca_cleanup_mrmw_cache();create_slab_caches5:	ehca_cleanup_av_cache();create_slab_caches4:	ehca_cleanup_qp_cache();create_slab_caches3:	ehca_cleanup_cq_cache();create_slab_caches2:	ehca_cleanup_pd_cache();	return ret;}static void ehca_destroy_slab_caches(void){	ehca_cleanup_small_qp_cache();	ehca_cleanup_mrmw_cache();	ehca_cleanup_av_cache();	ehca_cleanup_qp_cache();	ehca_cleanup_cq_cache();	ehca_cleanup_pd_cache();#ifdef CONFIG_PPC_64K_PAGES	if (ctblk_cache)		kmem_cache_destroy(ctblk_cache);#endif}#define EHCA_HCAAVER  EHCA_BMASK_IBM(32, 39)#define EHCA_REVID    EHCA_BMASK_IBM(40, 63)static struct cap_descr {	u64 mask;	char *descr;} hca_cap_descr[] = {	{ HCA_CAP_AH_PORT_NR_CHECK, "HCA_CAP_AH_PORT_NR_CHECK" },	{ HCA_CAP_ATOMIC, "HCA_CAP_ATOMIC" },	{ HCA_CAP_AUTO_PATH_MIG, "HCA_CAP_AUTO_PATH_MIG" },	{ HCA_CAP_BAD_P_KEY_CTR, "HCA_CAP_BAD_P_KEY_CTR" },	{ HCA_CAP_SQD_RTS_PORT_CHANGE, "HCA_CAP_SQD_RTS_PORT_CHANGE" },	{ HCA_CAP_CUR_QP_STATE_MOD, "HCA_CAP_CUR_QP_STATE_MOD" },	{ HCA_CAP_INIT_TYPE, "HCA_CAP_INIT_TYPE" },	{ HCA_CAP_PORT_ACTIVE_EVENT, "HCA_CAP_PORT_ACTIVE_EVENT" },	{ HCA_CAP_Q_KEY_VIOL_CTR, "HCA_CAP_Q_KEY_VIOL_CTR" },	{ HCA_CAP_WQE_RESIZE, "HCA_CAP_WQE_RESIZE" },	{ HCA_CAP_RAW_PACKET_MCAST, "HCA_CAP_RAW_PACKET_MCAST" },	{ HCA_CAP_SHUTDOWN_PORT, "HCA_CAP_SHUTDOWN_PORT" },	{ HCA_CAP_RC_LL_QP, "HCA_CAP_RC_LL_QP" },	{ HCA_CAP_SRQ, "HCA_CAP_SRQ" },	{ HCA_CAP_UD_LL_QP, "HCA_CAP_UD_LL_QP" },	{ HCA_CAP_RESIZE_MR, "HCA_CAP_RESIZE_MR" },	{ HCA_CAP_MINI_QP, "HCA_CAP_MINI_QP" },	{ HCA_CAP_H_ALLOC_RES_SYNC, "HCA_CAP_H_ALLOC_RES_SYNC" },};static int ehca_sense_attributes(struct ehca_shca *shca){	int i, ret = 0;	u64 h_ret;	struct hipz_query_hca *rblock;	struct hipz_query_port *port;	static const u32 pgsize_map[] = {		HCA_CAP_MR_PGSIZE_4K,  0x1000,		HCA_CAP_MR_PGSIZE_64K, 0x10000,		HCA_CAP_MR_PGSIZE_1M,  0x100000,		HCA_CAP_MR_PGSIZE_16M, 0x1000000,	};	rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);	if (!rblock) {		ehca_gen_err("Cannot allocate rblock memory.");		return -ENOMEM;	}	h_ret = hipz_h_query_hca(shca->ipz_hca_handle, rblock);	if (h_ret != H_SUCCESS) {		ehca_gen_err("Cannot query device properties. h_ret=%li",			     h_ret);		ret = -EPERM;		goto sense_attributes1;	}	if (ehca_nr_ports == 1)		shca->num_ports = 1;	else		shca->num_ports = (u8)rblock->num_ports;	ehca_gen_dbg(" ... found %x ports", rblock->num_ports);	if (ehca_hw_level == 0) {		u32 hcaaver;		u32 revid;		hcaaver = EHCA_BMASK_GET(EHCA_HCAAVER, rblock->hw_ver);		revid   = EHCA_BMASK_GET(EHCA_REVID, rblock->hw_ver);		ehca_gen_dbg(" ... hardware version=%x:%x", hcaaver, revid);		if (hcaaver == 1) {			if (revid <= 3)				shca->hw_level = 0x10 | (revid + 1);			else				shca->hw_level = 0x14;		} else if (hcaaver == 2) {			if (revid == 0)				shca->hw_level = 0x21;			else if (revid == 0x10)				shca->hw_level = 0x22;			else if (revid == 0x20 || revid == 0x21)				shca->hw_level = 0x23;		}		if (!shca->hw_level) {			ehca_gen_warn("unknown hardware version"				      " - assuming default level");			shca->hw_level = 0x22;		}	} else		shca->hw_level = ehca_hw_level;	ehca_gen_dbg(" ... hardware level=%x", shca->hw_level);	shca->hca_cap = rblock->hca_cap_indicators;	ehca_gen_dbg(" ... HCA capabilities:");	for (i = 0; i < ARRAY_SIZE(hca_cap_descr); i++)		if (EHCA_BMASK_GET(hca_cap_descr[i].mask, shca->hca_cap))			ehca_gen_dbg("   %s", hca_cap_descr[i].descr);	/* Autodetect hCall locking -- the "H_ALLOC_RESOURCE synced" flag is	 * a firmware property, so it's valid across all adapters	 */	if (ehca_lock_hcalls == -1)		ehca_lock_hcalls = !(shca->hca_cap & HCA_CAP_H_ALLOC_RES_SYNC);	/* translate supported MR page sizes; always support 4K */	shca->hca_cap_mr_pgsize = EHCA_PAGESIZE;	if (ehca_mr_largepage) { /* support extra sizes only if enabled */		for (i = 0; i < ARRAY_SIZE(pgsize_map); i += 2)			if (rblock->memory_page_size_supported & pgsize_map[i])				shca->hca_cap_mr_pgsize |= pgsize_map[i + 1];	}	/* query max MTU from first port -- it's the same for all ports */	port = (struct hipz_query_port *)rblock;	h_ret = hipz_h_query_port(shca->ipz_hca_handle, 1, port);	if (h_ret != H_SUCCESS) {		ehca_gen_err("Cannot query port properties. h_ret=%li",			     h_ret);		ret = -EPERM;		goto sense_attributes1;	}	shca->max_mtu = port->max_mtu;sense_attributes1:	ehca_free_fw_ctrlblock(rblock);	return ret;}static int init_node_guid(struct ehca_shca *shca){	int ret = 0;	struct hipz_query_hca *rblock;	rblock = ehca_alloc_fw_ctrlblock(GFP_KERNEL);	if (!rblock) {		ehca_err(&shca->ib_device, "Can't allocate rblock memory.");		return -ENOMEM;	}	if (hipz_h_query_hca(shca->ipz_hca_handle, rblock) != H_SUCCESS) {		ehca_err(&shca->ib_device, "Can't query device properties");		ret = -EINVAL;		goto init_node_guid1;	}	memcpy(&shca->ib_device.node_guid, &rblock->node_guid, sizeof(u64));init_node_guid1:	ehca_free_fw_ctrlblock(rblock);	return ret;}int ehca_init_device(struct ehca_shca *shca){	int ret;	ret = init_node_guid(shca);	if (ret)		return ret;	strlcpy(shca->ib_device.name, "ehca%d", IB_DEVICE_NAME_MAX);	shca->ib_device.owner               = THIS_MODULE;	shca->ib_device.uverbs_abi_ver	    = 8;	shca->ib_device.uverbs_cmd_mask	    =		(1ull << IB_USER_VERBS_CMD_GET_CONTEXT)		|		(1ull << IB_USER_VERBS_CMD_QUERY_DEVICE)	|		(1ull << IB_USER_VERBS_CMD_QUERY_PORT)		|		(1ull << IB_USER_VERBS_CMD_ALLOC_PD)		|		(1ull << IB_USER_VERBS_CMD_DEALLOC_PD)		|		(1ull << IB_USER_VERBS_CMD_REG_MR)		|		(1ull << IB_USER_VERBS_CMD_DEREG_MR)		|		(1ull << IB_USER_VERBS_CMD_CREATE_COMP_CHANNEL)	|		(1ull << IB_USER_VERBS_CMD_CREATE_CQ)		|		(1ull << IB_USER_VERBS_CMD_DESTROY_CQ)		|		(1ull << IB_USER_VERBS_CMD_CREATE_QP)		|		(1ull << IB_USER_VERBS_CMD_MODIFY_QP)		|		(1ull << IB_USER_VERBS_CMD_QUERY_QP)		|		(1ull << IB_USER_VERBS_CMD_DESTROY_QP)		|		(1ull << IB_USER_VERBS_CMD_ATTACH_MCAST)	|		(1ull << IB_USER_VERBS_CMD_DETACH_MCAST);	shca->ib_device.node_type           = RDMA_NODE_IB_CA;	shca->ib_device.phys_port_cnt       = shca->num_ports;	shca->ib_device.num_comp_vectors    = 1;	shca->ib_device.dma_device          = &shca->ofdev->dev;	shca->ib_device.query_device        = ehca_query_device;	shca->ib_device.query_port          = ehca_query_port;	shca->ib_device.query_gid           = ehca_query_gid;	shca->ib_device.query_pkey          = ehca_query_pkey;	/* shca->in_device.modify_device    = ehca_modify_device    */	shca->ib_device.modify_port         = ehca_modify_port;	shca->ib_device.alloc_ucontext      = ehca_alloc_ucontext;	shca->ib_device.dealloc_ucontext    = ehca_dealloc_ucontext;	shca->ib_device.alloc_pd            = ehca_alloc_pd;	shca->ib_device.dealloc_pd          = ehca_dealloc_pd;	shca->ib_device.create_ah	    = ehca_create_ah;	/* shca->ib_device.modify_ah	    = ehca_modify_ah;	    */	shca->ib_device.query_ah	    = ehca_query_ah;	shca->ib_device.destroy_ah	    = ehca_destroy_ah;	shca->ib_device.create_qp	    = ehca_create_qp;	shca->ib_device.modify_qp	    = ehca_modify_qp;	shca->ib_device.query_qp	    = ehca_query_qp;	shca->ib_device.destroy_qp	    = ehca_destroy_qp;	shca->ib_device.post_send	    = ehca_post_send;	shca->ib_device.post_recv	    = ehca_post_recv;	shca->ib_device.create_cq	    = ehca_create_cq;	shca->ib_device.destroy_cq	    = ehca_destroy_cq;	shca->ib_device.resize_cq	    = ehca_resize_cq;	shca->ib_device.poll_cq		    = ehca_poll_cq;	/* shca->ib_device.peek_cq	    = ehca_peek_cq;	    */	shca->ib_device.req_notify_cq	    = ehca_req_notify_cq;	/* shca->ib_device.req_ncomp_notif  = ehca_req_ncomp_notif; */	shca->ib_device.get_dma_mr	    = ehca_get_dma_mr;	shca->ib_device.reg_phys_mr	    = ehca_reg_phys_mr;	shca->ib_device.reg_user_mr	    = ehca_reg_user_mr;	shca->ib_device.query_mr	    = ehca_query_mr;	shca->ib_device.dereg_mr	    = ehca_dereg_mr;	shca->ib_device.rereg_phys_mr	    = ehca_rereg_phys_mr;	shca->ib_device.alloc_mw	    = ehca_alloc_mw;	shca->ib_device.bind_mw		    = ehca_bind_mw;	shca->ib_device.dealloc_mw	    = ehca_dealloc_mw;	shca->ib_device.alloc_fmr	    = ehca_alloc_fmr;	shca->ib_device.map_phys_fmr	    = ehca_map_phys_fmr;	shca->ib_device.unmap_fmr	    = ehca_unmap_fmr;	shca->ib_device.dealloc_fmr	    = ehca_dealloc_fmr;	shca->ib_device.attach_mcast	    = ehca_attach_mcast;	shca->ib_device.detach_mcast	    = ehca_detach_mcast;	/* shca->ib_device.process_mad	    = ehca_process_mad;	    */	shca->ib_device.mmap		    = ehca_mmap;	if (EHCA_BMASK_GET(HCA_CAP_SRQ, shca->hca_cap)) {		shca->ib_device.uverbs_cmd_mask |=			(1ull << IB_USER_VERBS_CMD_CREATE_SRQ) |			(1ull << IB_USER_VERBS_CMD_MODIFY_SRQ) |			(1ull << IB_USER_VERBS_CMD_QUERY_SRQ) |			(1ull << IB_USER_VERBS_CMD_DESTROY_SRQ);		shca->ib_device.create_srq          = ehca_create_srq;		shca->ib_device.modify_srq          = ehca_modify_srq;		shca->ib_device.query_srq           = ehca_query_srq;		shca->ib_device.destroy_srq         = ehca_destroy_srq;		shca->ib_device.post_srq_recv       = ehca_post_srq_recv;	}	return ret;}static int ehca_create_aqp1(struct ehca_shca *shca, u32 port){	struct ehca_sport *sport = &shca->sport[port - 1];	struct ib_cq *ibcq;	struct ib_qp *ibqp;	struct ib_qp_init_attr qp_init_attr;	int ret;

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -