Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 /*
0003  * Shared Memory Communications over RDMA (SMC-R) and RoCE
0004  *
0005  *  Definitions for IB environment
0006  *
0007  *  Copyright IBM Corp. 2016
0008  *
0009  *  Author(s):  Ursula Braun <Ursula Braun@linux.vnet.ibm.com>
0010  */
0011 
0012 #ifndef _SMC_IB_H
0013 #define _SMC_IB_H
0014 
0015 #include <linux/interrupt.h>
0016 #include <linux/if_ether.h>
0017 #include <linux/mutex.h>
0018 #include <linux/wait.h>
0019 #include <rdma/ib_verbs.h>
0020 #include <net/smc.h>
0021 
0022 #define SMC_MAX_PORTS           2   /* Max # of ports */
0023 #define SMC_GID_SIZE            sizeof(union ib_gid)
0024 
0025 #define SMC_IB_MAX_SEND_SGE     2
0026 
0027 struct smc_ib_devices {         /* list of smc ib devices definition */
0028     struct list_head    list;
0029     struct mutex        mutex;  /* protects list of smc ib devices */
0030 };
0031 
0032 extern struct smc_ib_devices    smc_ib_devices; /* list of smc ib devices */
0033 extern struct smc_lgr_list smc_lgr_list; /* list of linkgroups */
0034 
0035 struct smc_ib_device {              /* ib-device infos for smc */
0036     struct list_head    list;
0037     struct ib_device    *ibdev;
0038     struct ib_port_attr pattr[SMC_MAX_PORTS];   /* ib dev. port attrs */
0039     struct ib_event_handler event_handler;  /* global ib_event handler */
0040     struct ib_cq        *roce_cq_send;  /* send completion queue */
0041     struct ib_cq        *roce_cq_recv;  /* recv completion queue */
0042     struct tasklet_struct   send_tasklet;   /* called by send cq handler */
0043     struct tasklet_struct   recv_tasklet;   /* called by recv cq handler */
0044     char            mac[SMC_MAX_PORTS][ETH_ALEN];
0045                         /* mac address per port*/
0046     u8          pnetid[SMC_MAX_PORTS][SMC_MAX_PNETID_LEN];
0047                         /* pnetid per port */
0048     bool            pnetid_by_user[SMC_MAX_PORTS];
0049                         /* pnetid defined by user? */
0050     u8          initialized : 1; /* ib dev CQ, evthdl done */
0051     struct work_struct  port_event_work;
0052     unsigned long       port_event_mask;
0053     DECLARE_BITMAP(ports_going_away, SMC_MAX_PORTS);
0054     atomic_t        lnk_cnt;    /* number of links on ibdev */
0055     wait_queue_head_t   lnks_deleted;   /* wait 4 removal of all links*/
0056     struct mutex        mutex;      /* protect dev setup+cleanup */
0057     atomic_t        lnk_cnt_by_port[SMC_MAX_PORTS];
0058                         /* number of links per port */
0059     int         ndev_ifidx[SMC_MAX_PORTS]; /* ndev if indexes */
0060 };
0061 
0062 static inline __be32 smc_ib_gid_to_ipv4(u8 gid[SMC_GID_SIZE])
0063 {
0064     struct in6_addr *addr6 = (struct in6_addr *)gid;
0065 
0066     if (ipv6_addr_v4mapped(addr6) ||
0067         !(addr6->s6_addr32[0] | addr6->s6_addr32[1] | addr6->s6_addr32[2]))
0068         return addr6->s6_addr32[3];
0069     return cpu_to_be32(INADDR_NONE);
0070 }
0071 
0072 static inline struct net *smc_ib_net(struct smc_ib_device *smcibdev)
0073 {
0074     if (smcibdev && smcibdev->ibdev)
0075         return read_pnet(&smcibdev->ibdev->coredev.rdma_net);
0076     return NULL;
0077 }
0078 
0079 struct smc_init_info_smcrv2;
0080 struct smc_buf_desc;
0081 struct smc_link;
0082 
0083 void smc_ib_ndev_change(struct net_device *ndev, unsigned long event);
0084 int smc_ib_register_client(void) __init;
0085 void smc_ib_unregister_client(void);
0086 bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport);
0087 int smc_ib_buf_map_sg(struct smc_link *lnk,
0088               struct smc_buf_desc *buf_slot,
0089               enum dma_data_direction data_direction);
0090 void smc_ib_buf_unmap_sg(struct smc_link *lnk,
0091              struct smc_buf_desc *buf_slot,
0092              enum dma_data_direction data_direction);
0093 void smc_ib_dealloc_protection_domain(struct smc_link *lnk);
0094 int smc_ib_create_protection_domain(struct smc_link *lnk);
0095 void smc_ib_destroy_queue_pair(struct smc_link *lnk);
0096 int smc_ib_create_queue_pair(struct smc_link *lnk);
0097 int smc_ib_ready_link(struct smc_link *lnk);
0098 int smc_ib_modify_qp_rts(struct smc_link *lnk);
0099 int smc_ib_modify_qp_reset(struct smc_link *lnk);
0100 int smc_ib_modify_qp_error(struct smc_link *lnk);
0101 long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev);
0102 int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
0103                  struct smc_buf_desc *buf_slot, u8 link_idx);
0104 void smc_ib_put_memory_region(struct ib_mr *mr);
0105 bool smc_ib_is_sg_need_sync(struct smc_link *lnk,
0106                 struct smc_buf_desc *buf_slot);
0107 void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
0108                 struct smc_buf_desc *buf_slot,
0109                 enum dma_data_direction data_direction);
0110 void smc_ib_sync_sg_for_device(struct smc_link *lnk,
0111                    struct smc_buf_desc *buf_slot,
0112                    enum dma_data_direction data_direction);
0113 int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
0114              unsigned short vlan_id, u8 gid[], u8 *sgid_index,
0115              struct smc_init_info_smcrv2 *smcrv2);
0116 int smc_ib_find_route(__be32 saddr, __be32 daddr,
0117               u8 nexthop_mac[], u8 *uses_gateway);
0118 bool smc_ib_is_valid_local_systemid(void);
0119 int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
0120 #endif