Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 2 | /* |
| 3 | * Shared Memory Communications over RDMA (SMC-R) and RoCE |
| 4 | * |
| 5 | * Definitions for IB environment |
| 6 | * |
| 7 | * Copyright IBM Corp. 2016 |
| 8 | * |
| 9 | * Author(s): Ursula Braun <Ursula Braun@linux.vnet.ibm.com> |
| 10 | */ |
| 11 | |
| 12 | #ifndef _SMC_IB_H |
| 13 | #define _SMC_IB_H |
| 14 | |
Florian Westphal | 282ccf6 | 2017-03-29 17:17:31 +0200 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 16 | #include <linux/if_ether.h> |
Ursula Braun | 92f3cb0 | 2020-07-08 17:05:13 +0200 | [diff] [blame] | 17 | #include <linux/mutex.h> |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 18 | #include <linux/wait.h> |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 19 | #include <rdma/ib_verbs.h> |
Ursula Braun | 0afff91 | 2018-06-28 19:05:05 +0200 | [diff] [blame] | 20 | #include <net/smc.h> |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 21 | |
| 22 | #define SMC_MAX_PORTS 2 /* Max # of ports */ |
| 23 | #define SMC_GID_SIZE sizeof(union ib_gid) |
| 24 | |
Ursula Braun | f38ba179 | 2017-01-09 16:55:19 +0100 | [diff] [blame] | 25 | #define SMC_IB_MAX_SEND_SGE 2 |
| 26 | |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 27 | struct smc_ib_devices { /* list of smc ib devices definition */ |
| 28 | struct list_head list; |
Ursula Braun | 92f3cb0 | 2020-07-08 17:05:13 +0200 | [diff] [blame] | 29 | struct mutex mutex; /* protects list of smc ib devices */ |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 30 | }; |
| 31 | |
| 32 | extern struct smc_ib_devices smc_ib_devices; /* list of smc ib devices */ |
Guvenc Gulce | a3db10e | 2020-12-01 20:20:49 +0100 | [diff] [blame] | 33 | extern struct smc_lgr_list smc_lgr_list; /* list of linkgroups */ |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 34 | |
| 35 | struct smc_ib_device { /* ib-device infos for smc */ |
| 36 | struct list_head list; |
| 37 | struct ib_device *ibdev; |
| 38 | struct ib_port_attr pattr[SMC_MAX_PORTS]; /* ib dev. port attrs */ |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 39 | struct ib_event_handler event_handler; /* global ib_event handler */ |
Ursula Braun | f38ba179 | 2017-01-09 16:55:19 +0100 | [diff] [blame] | 40 | struct ib_cq *roce_cq_send; /* send completion queue */ |
| 41 | struct ib_cq *roce_cq_recv; /* recv completion queue */ |
| 42 | struct tasklet_struct send_tasklet; /* called by send cq handler */ |
| 43 | struct tasklet_struct recv_tasklet; /* called by recv cq handler */ |
Ursula Braun | 143c017 | 2017-01-12 14:57:15 +0100 | [diff] [blame] | 44 | char mac[SMC_MAX_PORTS][ETH_ALEN]; |
| 45 | /* mac address per port*/ |
Ursula Braun | 0afff91 | 2018-06-28 19:05:05 +0200 | [diff] [blame] | 46 | u8 pnetid[SMC_MAX_PORTS][SMC_MAX_PNETID_LEN]; |
| 47 | /* pnetid per port */ |
Hans Wippel | 890a2cb | 2019-02-21 13:01:00 +0100 | [diff] [blame] | 48 | bool pnetid_by_user[SMC_MAX_PORTS]; |
| 49 | /* pnetid defined by user? */ |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 50 | u8 initialized : 1; /* ib dev CQ, evthdl done */ |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 51 | struct work_struct port_event_work; |
| 52 | unsigned long port_event_mask; |
Ursula Braun | c3d9494 | 2019-10-09 10:07:46 +0200 | [diff] [blame] | 53 | DECLARE_BITMAP(ports_going_away, SMC_MAX_PORTS); |
Ursula Braun | 6dabd40 | 2019-11-16 17:47:29 +0100 | [diff] [blame] | 54 | atomic_t lnk_cnt; /* number of links on ibdev */ |
| 55 | wait_queue_head_t lnks_deleted; /* wait 4 removal of all links*/ |
Karsten Graul | 6367359 | 2020-07-18 15:06:12 +0200 | [diff] [blame] | 56 | struct mutex mutex; /* protect dev setup+cleanup */ |
Guvenc Gulce | ddc9928 | 2020-12-01 20:20:39 +0100 | [diff] [blame] | 57 | atomic_t lnk_cnt_by_port[SMC_MAX_PORTS]; |
| 58 | /* number of links per port */ |
Guvenc Gulce | 3d453f5 | 2020-12-01 20:20:40 +0100 | [diff] [blame] | 59 | int ndev_ifidx[SMC_MAX_PORTS]; /* ndev if indexes */ |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 60 | }; |
| 61 | |
Karsten Graul | e5c4744 | 2021-10-16 11:37:45 +0200 | [diff] [blame] | 62 | static inline __be32 smc_ib_gid_to_ipv4(u8 gid[SMC_GID_SIZE]) |
| 63 | { |
| 64 | struct in6_addr *addr6 = (struct in6_addr *)gid; |
| 65 | |
| 66 | if (ipv6_addr_v4mapped(addr6) || |
| 67 | !(addr6->s6_addr32[0] | addr6->s6_addr32[1] | addr6->s6_addr32[2])) |
| 68 | return addr6->s6_addr32[3]; |
| 69 | return cpu_to_be32(INADDR_NONE); |
| 70 | } |
| 71 | |
Tony Lu | 0237a3a | 2021-12-28 21:06:09 +0800 | [diff] [blame] | 72 | static inline struct net *smc_ib_net(struct smc_ib_device *smcibdev) |
| 73 | { |
| 74 | if (smcibdev && smcibdev->ibdev) |
| 75 | return read_pnet(&smcibdev->ibdev->coredev.rdma_net); |
| 76 | return NULL; |
| 77 | } |
| 78 | |
Karsten Graul | e5c4744 | 2021-10-16 11:37:45 +0200 | [diff] [blame] | 79 | struct smc_init_info_smcrv2; |
Ursula Braun | cd6851f | 2017-01-09 16:55:18 +0100 | [diff] [blame] | 80 | struct smc_buf_desc; |
Ursula Braun | f38ba179 | 2017-01-09 16:55:19 +0100 | [diff] [blame] | 81 | struct smc_link; |
Ursula Braun | cd6851f | 2017-01-09 16:55:18 +0100 | [diff] [blame] | 82 | |
Guvenc Gulce | 3d453f5 | 2020-12-01 20:20:40 +0100 | [diff] [blame] | 83 | void smc_ib_ndev_change(struct net_device *ndev, unsigned long event); |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 84 | int smc_ib_register_client(void) __init; |
| 85 | void smc_ib_unregister_client(void); |
| 86 | bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport); |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 87 | int smc_ib_buf_map_sg(struct smc_link *lnk, |
Ursula Braun | a3fe3d0 | 2017-07-28 13:56:15 +0200 | [diff] [blame] | 88 | struct smc_buf_desc *buf_slot, |
| 89 | enum dma_data_direction data_direction); |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 90 | void smc_ib_buf_unmap_sg(struct smc_link *lnk, |
Ursula Braun | a3fe3d0 | 2017-07-28 13:56:15 +0200 | [diff] [blame] | 91 | struct smc_buf_desc *buf_slot, |
| 92 | enum dma_data_direction data_direction); |
Ursula Braun | f38ba179 | 2017-01-09 16:55:19 +0100 | [diff] [blame] | 93 | void smc_ib_dealloc_protection_domain(struct smc_link *lnk); |
| 94 | int smc_ib_create_protection_domain(struct smc_link *lnk); |
| 95 | void smc_ib_destroy_queue_pair(struct smc_link *lnk); |
| 96 | int smc_ib_create_queue_pair(struct smc_link *lnk); |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 97 | int smc_ib_ready_link(struct smc_link *lnk); |
| 98 | int smc_ib_modify_qp_rts(struct smc_link *lnk); |
| 99 | int smc_ib_modify_qp_reset(struct smc_link *lnk); |
Dust Li | 349d431 | 2021-12-28 17:03:25 +0800 | [diff] [blame] | 100 | int smc_ib_modify_qp_error(struct smc_link *lnk); |
Ursula Braun | bd4ad57 | 2017-01-09 16:55:20 +0100 | [diff] [blame] | 101 | long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev); |
Ursula Braun | 897e1c2 | 2017-07-28 13:56:16 +0200 | [diff] [blame] | 102 | int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags, |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 103 | struct smc_buf_desc *buf_slot, u8 link_idx); |
Ursula Braun | 897e1c2 | 2017-07-28 13:56:16 +0200 | [diff] [blame] | 104 | void smc_ib_put_memory_region(struct ib_mr *mr); |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 105 | void smc_ib_sync_sg_for_cpu(struct smc_link *lnk, |
Ursula Braun | 10428dd | 2017-07-28 13:56:22 +0200 | [diff] [blame] | 106 | struct smc_buf_desc *buf_slot, |
| 107 | enum dma_data_direction data_direction); |
Karsten Graul | 387707f | 2020-04-29 17:10:40 +0200 | [diff] [blame] | 108 | void smc_ib_sync_sg_for_device(struct smc_link *lnk, |
Ursula Braun | 10428dd | 2017-07-28 13:56:22 +0200 | [diff] [blame] | 109 | struct smc_buf_desc *buf_slot, |
| 110 | enum dma_data_direction data_direction); |
Ursula Braun | 7005ada | 2018-07-25 16:35:31 +0200 | [diff] [blame] | 111 | int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport, |
Karsten Graul | 24fb681 | 2021-10-16 11:37:48 +0200 | [diff] [blame] | 112 | unsigned short vlan_id, u8 gid[], u8 *sgid_index, |
| 113 | struct smc_init_info_smcrv2 *smcrv2); |
Karsten Graul | e5c4744 | 2021-10-16 11:37:45 +0200 | [diff] [blame] | 114 | int smc_ib_find_route(__be32 saddr, __be32 daddr, |
| 115 | u8 nexthop_mac[], u8 *uses_gateway); |
Hans Wippel | a082ec8 | 2020-02-25 22:41:22 +0100 | [diff] [blame] | 116 | bool smc_ib_is_valid_local_systemid(void); |
Guvenc Gulce | a3db10e | 2020-12-01 20:20:49 +0100 | [diff] [blame] | 117 | int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb); |
Ursula Braun | a4cf044 | 2017-01-09 16:55:14 +0100 | [diff] [blame] | 118 | #endif |