Path: blob/master/drivers/infiniband/hw/ehca/ehca_classes.h
15112 views
/*1* IBM eServer eHCA Infiniband device driver for Linux on POWER2*3* Struct definition for eHCA internal structures4*5* Authors: Heiko J Schick <[email protected]>6* Christoph Raisch <[email protected]>7* Joachim Fenkes <[email protected]>8*9* Copyright (c) 2005 IBM Corporation10*11* All rights reserved.12*13* This source code is distributed under a dual license of GPL v2.0 and OpenIB14* BSD.15*16* OpenIB BSD License17*18* Redistribution and use in source and binary forms, with or without19* modification, are permitted provided that the following conditions are met:20*21* Redistributions of source code must retain the above copyright notice, this22* list of conditions and the following disclaimer.23*24* Redistributions in binary form must reproduce the above copyright notice,25* this list of conditions and the following disclaimer in the documentation26* and/or other materials27* provided with the distribution.28*29* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"30* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE31* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE32* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE33* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR34* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF35* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR36* BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER37* IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)38* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE39* POSSIBILITY OF SUCH DAMAGE.40*/4142#ifndef __EHCA_CLASSES_H__43#define __EHCA_CLASSES_H__4445struct ehca_module;46struct ehca_qp;47struct ehca_cq;48struct ehca_eq;49struct ehca_mr;50struct ehca_mw;51struct ehca_pd;52struct ehca_av;5354#include <linux/wait.h>55#include <linux/mutex.h>5657#include <rdma/ib_verbs.h>58#include <rdma/ib_user_verbs.h>5960#ifdef CONFIG_PPC6461#include "ehca_classes_pSeries.h"62#endif63#include "ipz_pt_fn.h"64#include "ehca_qes.h"65#include "ehca_irq.h"6667#define EHCA_EQE_CACHE_SIZE 2068#define EHCA_MAX_NUM_QUEUES 0xffff6970struct ehca_eqe_cache_entry {71struct ehca_eqe *eqe;72struct ehca_cq *cq;73};7475struct ehca_eq {76u32 length;77struct ipz_queue ipz_queue;78struct ipz_eq_handle ipz_eq_handle;79struct work_struct work;80struct h_galpas galpas;81int is_initialized;82struct ehca_pfeq pf;83spinlock_t spinlock;84struct tasklet_struct interrupt_task;85u32 ist;86spinlock_t irq_spinlock;87struct ehca_eqe_cache_entry eqe_cache[EHCA_EQE_CACHE_SIZE];88};8990struct ehca_sma_attr {91u16 lid, lmc, sm_sl, sm_lid;92u16 pkey_tbl_len, pkeys[16];93};9495struct ehca_sport {96struct ib_cq *ibcq_aqp1;97struct ib_qp *ibqp_sqp[2];98/* lock to serialze modify_qp() calls for sqp in normal99* and irq path (when event PORT_ACTIVE is received first time)100*/101spinlock_t mod_sqp_lock;102enum ib_port_state port_state;103struct ehca_sma_attr saved_attr;104u32 pma_qp_nr;105};106107#define HCA_CAP_MR_PGSIZE_4K 0x80000000108#define HCA_CAP_MR_PGSIZE_64K 0x40000000109#define HCA_CAP_MR_PGSIZE_1M 0x20000000110#define HCA_CAP_MR_PGSIZE_16M 0x10000000111112struct ehca_shca {113struct ib_device ib_device;114struct platform_device *ofdev;115u8 num_ports;116int hw_level;117struct list_head shca_list;118struct ipz_adapter_handle ipz_hca_handle;119struct ehca_sport sport[2];120struct ehca_eq eq;121struct ehca_eq neq;122struct ehca_mr *maxmr;123struct ehca_pd *pd;124struct h_galpas galpas;125struct mutex modify_mutex;126u64 hca_cap;127/* MR pgsize: bit 0-3 means 4K, 64K, 1M, 16M respectively */128u32 hca_cap_mr_pgsize;129int max_mtu;130int max_num_qps;131int max_num_cqs;132atomic_t num_cqs;133atomic_t num_qps;134};135136struct ehca_pd {137struct ib_pd ib_pd;138struct ipz_pd fw_pd;139/* small queue mgmt */140struct mutex lock;141struct list_head free[2];142struct list_head full[2];143};144145enum ehca_ext_qp_type {146EQPT_NORMAL = 0,147EQPT_LLQP = 1,148EQPT_SRQBASE = 2,149EQPT_SRQ = 3,150};151152/* struct to cache modify_qp()'s parms for GSI/SMI qp */153struct ehca_mod_qp_parm {154int mask;155struct ib_qp_attr attr;156};157158#define EHCA_MOD_QP_PARM_MAX 4159160#define QMAP_IDX_MASK 0xFFFFULL161162/* struct for tracking if cqes have been reported to the application */163struct ehca_qmap_entry {164u16 app_wr_id;165u8 reported;166u8 cqe_req;167};168169struct ehca_queue_map {170struct ehca_qmap_entry *map;171unsigned int entries;172unsigned int tail;173unsigned int left_to_poll;174unsigned int next_wqe_idx; /* Idx to first wqe to be flushed */175};176177/* function to calculate the next index for the qmap */178static inline unsigned int next_index(unsigned int cur_index, unsigned int limit)179{180unsigned int temp = cur_index + 1;181return (temp == limit) ? 0 : temp;182}183184struct ehca_qp {185union {186struct ib_qp ib_qp;187struct ib_srq ib_srq;188};189u32 qp_type;190enum ehca_ext_qp_type ext_type;191enum ib_qp_state state;192struct ipz_queue ipz_squeue;193struct ehca_queue_map sq_map;194struct ipz_queue ipz_rqueue;195struct ehca_queue_map rq_map;196struct h_galpas galpas;197u32 qkey;198u32 real_qp_num;199u32 token;200spinlock_t spinlock_s;201spinlock_t spinlock_r;202u32 sq_max_inline_data_size;203struct ipz_qp_handle ipz_qp_handle;204struct ehca_pfqp pf;205struct ib_qp_init_attr init_attr;206struct ehca_cq *send_cq;207struct ehca_cq *recv_cq;208unsigned int sqerr_purgeflag;209struct hlist_node list_entries;210/* array to cache modify_qp()'s parms for GSI/SMI qp */211struct ehca_mod_qp_parm *mod_qp_parm;212int mod_qp_parm_idx;213/* mmap counter for resources mapped into user space */214u32 mm_count_squeue;215u32 mm_count_rqueue;216u32 mm_count_galpa;217/* unsolicited ack circumvention */218int unsol_ack_circ;219int mtu_shift;220u32 message_count;221u32 packet_count;222atomic_t nr_events; /* events seen */223wait_queue_head_t wait_completion;224int mig_armed;225struct list_head sq_err_node;226struct list_head rq_err_node;227};228229#define IS_SRQ(qp) (qp->ext_type == EQPT_SRQ)230#define HAS_SQ(qp) (qp->ext_type != EQPT_SRQ)231#define HAS_RQ(qp) (qp->ext_type != EQPT_SRQBASE)232233/* must be power of 2 */234#define QP_HASHTAB_LEN 8235236struct ehca_cq {237struct ib_cq ib_cq;238struct ipz_queue ipz_queue;239struct h_galpas galpas;240spinlock_t spinlock;241u32 cq_number;242u32 token;243u32 nr_of_entries;244struct ipz_cq_handle ipz_cq_handle;245struct ehca_pfcq pf;246spinlock_t cb_lock;247struct hlist_head qp_hashtab[QP_HASHTAB_LEN];248struct list_head entry;249u32 nr_callbacks; /* #events assigned to cpu by scaling code */250atomic_t nr_events; /* #events seen */251wait_queue_head_t wait_completion;252spinlock_t task_lock;253/* mmap counter for resources mapped into user space */254u32 mm_count_queue;255u32 mm_count_galpa;256struct list_head sqp_err_list;257struct list_head rqp_err_list;258};259260enum ehca_mr_flag {261EHCA_MR_FLAG_FMR = 0x80000000, /* FMR, created with ehca_alloc_fmr */262EHCA_MR_FLAG_MAXMR = 0x40000000, /* max-MR */263};264265struct ehca_mr {266union {267struct ib_mr ib_mr; /* must always be first in ehca_mr */268struct ib_fmr ib_fmr; /* must always be first in ehca_mr */269} ib;270struct ib_umem *umem;271spinlock_t mrlock;272273enum ehca_mr_flag flags;274u32 num_kpages; /* number of kernel pages */275u32 num_hwpages; /* number of hw pages to form MR */276u64 hwpage_size; /* hw page size used for this MR */277int acl; /* ACL (stored here for usage in reregister) */278u64 *start; /* virtual start address (stored here for */279/* usage in reregister) */280u64 size; /* size (stored here for usage in reregister) */281u32 fmr_page_size; /* page size for FMR */282u32 fmr_max_pages; /* max pages for FMR */283u32 fmr_max_maps; /* max outstanding maps for FMR */284u32 fmr_map_cnt; /* map counter for FMR */285/* fw specific data */286struct ipz_mrmw_handle ipz_mr_handle; /* MR handle for h-calls */287struct h_galpas galpas;288};289290struct ehca_mw {291struct ib_mw ib_mw; /* gen2 mw, must always be first in ehca_mw */292spinlock_t mwlock;293294u8 never_bound; /* indication MW was never bound */295struct ipz_mrmw_handle ipz_mw_handle; /* MW handle for h-calls */296struct h_galpas galpas;297};298299enum ehca_mr_pgi_type {300EHCA_MR_PGI_PHYS = 1, /* type of ehca_reg_phys_mr,301* ehca_rereg_phys_mr,302* ehca_reg_internal_maxmr */303EHCA_MR_PGI_USER = 2, /* type of ehca_reg_user_mr */304EHCA_MR_PGI_FMR = 3 /* type of ehca_map_phys_fmr */305};306307struct ehca_mr_pginfo {308enum ehca_mr_pgi_type type;309u64 num_kpages;310u64 kpage_cnt;311u64 hwpage_size; /* hw page size used for this MR */312u64 num_hwpages; /* number of hw pages */313u64 hwpage_cnt; /* counter for hw pages */314u64 next_hwpage; /* next hw page in buffer/chunk/listelem */315316union {317struct { /* type EHCA_MR_PGI_PHYS section */318int num_phys_buf;319struct ib_phys_buf *phys_buf_array;320u64 next_buf;321} phy;322struct { /* type EHCA_MR_PGI_USER section */323struct ib_umem *region;324struct ib_umem_chunk *next_chunk;325u64 next_nmap;326} usr;327struct { /* type EHCA_MR_PGI_FMR section */328u64 fmr_pgsize;329u64 *page_list;330u64 next_listelem;331} fmr;332} u;333};334335/* output parameters for MR/FMR hipz calls */336struct ehca_mr_hipzout_parms {337struct ipz_mrmw_handle handle;338u32 lkey;339u32 rkey;340u64 len;341u64 vaddr;342u32 acl;343};344345/* output parameters for MW hipz calls */346struct ehca_mw_hipzout_parms {347struct ipz_mrmw_handle handle;348u32 rkey;349};350351struct ehca_av {352struct ib_ah ib_ah;353struct ehca_ud_av av;354};355356struct ehca_ucontext {357struct ib_ucontext ib_ucontext;358};359360int ehca_init_pd_cache(void);361void ehca_cleanup_pd_cache(void);362int ehca_init_cq_cache(void);363void ehca_cleanup_cq_cache(void);364int ehca_init_qp_cache(void);365void ehca_cleanup_qp_cache(void);366int ehca_init_av_cache(void);367void ehca_cleanup_av_cache(void);368int ehca_init_mrmw_cache(void);369void ehca_cleanup_mrmw_cache(void);370int ehca_init_small_qp_cache(void);371void ehca_cleanup_small_qp_cache(void);372373extern rwlock_t ehca_qp_idr_lock;374extern rwlock_t ehca_cq_idr_lock;375extern struct idr ehca_qp_idr;376extern struct idr ehca_cq_idr;377extern spinlock_t shca_list_lock;378379extern int ehca_static_rate;380extern int ehca_port_act_time;381extern int ehca_use_hp_mr;382extern int ehca_scaling_code;383extern int ehca_lock_hcalls;384extern int ehca_nr_ports;385extern int ehca_max_cq;386extern int ehca_max_qp;387388struct ipzu_queue_resp {389u32 qe_size; /* queue entry size */390u32 act_nr_of_sg;391u32 queue_length; /* queue length allocated in bytes */392u32 pagesize;393u32 toggle_state;394u32 offset; /* save offset within a page for small_qp */395};396397struct ehca_create_cq_resp {398u32 cq_number;399u32 token;400struct ipzu_queue_resp ipz_queue;401u32 fw_handle_ofs;402u32 dummy;403};404405struct ehca_create_qp_resp {406u32 qp_num;407u32 token;408u32 qp_type;409u32 ext_type;410u32 qkey;411/* qp_num assigned by ehca: sqp0/1 may have got different numbers */412u32 real_qp_num;413u32 fw_handle_ofs;414u32 dummy;415struct ipzu_queue_resp ipz_squeue;416struct ipzu_queue_resp ipz_rqueue;417};418419struct ehca_alloc_cq_parms {420u32 nr_cqe;421u32 act_nr_of_entries;422u32 act_pages;423struct ipz_eq_handle eq_handle;424};425426enum ehca_service_type {427ST_RC = 0,428ST_UC = 1,429ST_RD = 2,430ST_UD = 3,431};432433enum ehca_ll_comp_flags {434LLQP_SEND_COMP = 0x20,435LLQP_RECV_COMP = 0x40,436LLQP_COMP_MASK = 0x60,437};438439struct ehca_alloc_queue_parms {440/* input parameters */441int max_wr;442int max_sge;443int page_size;444int is_small;445446/* output parameters */447u16 act_nr_wqes;448u8 act_nr_sges;449u32 queue_size; /* bytes for small queues, pages otherwise */450};451452struct ehca_alloc_qp_parms {453struct ehca_alloc_queue_parms squeue;454struct ehca_alloc_queue_parms rqueue;455456/* input parameters */457enum ehca_service_type servicetype;458int qp_storage;459int sigtype;460enum ehca_ext_qp_type ext_type;461enum ehca_ll_comp_flags ll_comp_flags;462int ud_av_l_key_ctl;463464u32 token;465struct ipz_eq_handle eq_handle;466struct ipz_pd pd;467struct ipz_cq_handle send_cq_handle, recv_cq_handle;468469u32 srq_qpn, srq_token, srq_limit;470471/* output parameters */472u32 real_qp_num;473struct ipz_qp_handle qp_handle;474struct h_galpas galpas;475};476477int ehca_cq_assign_qp(struct ehca_cq *cq, struct ehca_qp *qp);478int ehca_cq_unassign_qp(struct ehca_cq *cq, unsigned int qp_num);479struct ehca_qp *ehca_cq_get_qp(struct ehca_cq *cq, int qp_num);480481#endif482483484