smc_ib.h 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. /* SPDX-License-Identifier: GPL-2.0 */
  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 [email protected]>
  10. */
  11. #ifndef _SMC_IB_H
  12. #define _SMC_IB_H
  13. #include <linux/interrupt.h>
  14. #include <linux/if_ether.h>
  15. #include <linux/mutex.h>
  16. #include <linux/wait.h>
  17. #include <rdma/ib_verbs.h>
  18. #include <net/smc.h>
  19. #define SMC_MAX_PORTS 2 /* Max # of ports */
  20. #define SMC_GID_SIZE sizeof(union ib_gid)
  21. #define SMC_IB_MAX_SEND_SGE 2
  22. struct smc_ib_devices { /* list of smc ib devices definition */
  23. struct list_head list;
  24. struct mutex mutex; /* protects list of smc ib devices */
  25. };
  26. extern struct smc_ib_devices smc_ib_devices; /* list of smc ib devices */
  27. extern struct smc_lgr_list smc_lgr_list; /* list of linkgroups */
  28. struct smc_ib_device { /* ib-device infos for smc */
  29. struct list_head list;
  30. struct ib_device *ibdev;
  31. struct ib_port_attr pattr[SMC_MAX_PORTS]; /* ib dev. port attrs */
  32. struct ib_event_handler event_handler; /* global ib_event handler */
  33. struct ib_cq *roce_cq_send; /* send completion queue */
  34. struct ib_cq *roce_cq_recv; /* recv completion queue */
  35. struct tasklet_struct send_tasklet; /* called by send cq handler */
  36. struct tasklet_struct recv_tasklet; /* called by recv cq handler */
  37. char mac[SMC_MAX_PORTS][ETH_ALEN];
  38. /* mac address per port*/
  39. u8 pnetid[SMC_MAX_PORTS][SMC_MAX_PNETID_LEN];
  40. /* pnetid per port */
  41. bool pnetid_by_user[SMC_MAX_PORTS];
  42. /* pnetid defined by user? */
  43. u8 initialized : 1; /* ib dev CQ, evthdl done */
  44. struct work_struct port_event_work;
  45. unsigned long port_event_mask;
  46. DECLARE_BITMAP(ports_going_away, SMC_MAX_PORTS);
  47. atomic_t lnk_cnt; /* number of links on ibdev */
  48. wait_queue_head_t lnks_deleted; /* wait 4 removal of all links*/
  49. struct mutex mutex; /* protect dev setup+cleanup */
  50. atomic_t lnk_cnt_by_port[SMC_MAX_PORTS];
  51. /* number of links per port */
  52. int ndev_ifidx[SMC_MAX_PORTS]; /* ndev if indexes */
  53. };
  54. static inline __be32 smc_ib_gid_to_ipv4(u8 gid[SMC_GID_SIZE])
  55. {
  56. struct in6_addr *addr6 = (struct in6_addr *)gid;
  57. if (ipv6_addr_v4mapped(addr6) ||
  58. !(addr6->s6_addr32[0] | addr6->s6_addr32[1] | addr6->s6_addr32[2]))
  59. return addr6->s6_addr32[3];
  60. return cpu_to_be32(INADDR_NONE);
  61. }
  62. static inline struct net *smc_ib_net(struct smc_ib_device *smcibdev)
  63. {
  64. if (smcibdev && smcibdev->ibdev)
  65. return read_pnet(&smcibdev->ibdev->coredev.rdma_net);
  66. return NULL;
  67. }
  68. struct smc_init_info_smcrv2;
  69. struct smc_buf_desc;
  70. struct smc_link;
  71. void smc_ib_ndev_change(struct net_device *ndev, unsigned long event);
  72. int smc_ib_register_client(void) __init;
  73. void smc_ib_unregister_client(void);
  74. bool smc_ib_port_active(struct smc_ib_device *smcibdev, u8 ibport);
  75. int smc_ib_buf_map_sg(struct smc_link *lnk,
  76. struct smc_buf_desc *buf_slot,
  77. enum dma_data_direction data_direction);
  78. void smc_ib_buf_unmap_sg(struct smc_link *lnk,
  79. struct smc_buf_desc *buf_slot,
  80. enum dma_data_direction data_direction);
  81. void smc_ib_dealloc_protection_domain(struct smc_link *lnk);
  82. int smc_ib_create_protection_domain(struct smc_link *lnk);
  83. void smc_ib_destroy_queue_pair(struct smc_link *lnk);
  84. int smc_ib_create_queue_pair(struct smc_link *lnk);
  85. int smc_ib_ready_link(struct smc_link *lnk);
  86. int smc_ib_modify_qp_rts(struct smc_link *lnk);
  87. int smc_ib_modify_qp_reset(struct smc_link *lnk);
  88. int smc_ib_modify_qp_error(struct smc_link *lnk);
  89. long smc_ib_setup_per_ibdev(struct smc_ib_device *smcibdev);
  90. int smc_ib_get_memory_region(struct ib_pd *pd, int access_flags,
  91. struct smc_buf_desc *buf_slot, u8 link_idx);
  92. void smc_ib_put_memory_region(struct ib_mr *mr);
  93. bool smc_ib_is_sg_need_sync(struct smc_link *lnk,
  94. struct smc_buf_desc *buf_slot);
  95. void smc_ib_sync_sg_for_cpu(struct smc_link *lnk,
  96. struct smc_buf_desc *buf_slot,
  97. enum dma_data_direction data_direction);
  98. void smc_ib_sync_sg_for_device(struct smc_link *lnk,
  99. struct smc_buf_desc *buf_slot,
  100. enum dma_data_direction data_direction);
  101. int smc_ib_determine_gid(struct smc_ib_device *smcibdev, u8 ibport,
  102. unsigned short vlan_id, u8 gid[], u8 *sgid_index,
  103. struct smc_init_info_smcrv2 *smcrv2);
  104. int smc_ib_find_route(struct net *net, __be32 saddr, __be32 daddr,
  105. u8 nexthop_mac[], u8 *uses_gateway);
  106. bool smc_ib_is_valid_local_systemid(void);
  107. int smcr_nl_get_device(struct sk_buff *skb, struct netlink_callback *cb);
  108. #endif