usnic_fwd.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. /*
  2. * Copyright (c) 2013, Cisco Systems, Inc. All rights reserved.
  3. *
  4. * This software is available to you under a choice of one of two
  5. * licenses. You may choose to be licensed under the terms of the GNU
  6. * General Public License (GPL) Version 2, available from the file
  7. * COPYING in the main directory of this source tree, or the
  8. * BSD license below:
  9. *
  10. * Redistribution and use in source and binary forms, with or
  11. * without modification, are permitted provided that the following
  12. * conditions are met:
  13. *
  14. * - Redistributions of source code must retain the above
  15. * copyright notice, this list of conditions and the following
  16. * disclaimer.
  17. *
  18. * - Redistributions in binary form must reproduce the above
  19. * copyright notice, this list of conditions and the following
  20. * disclaimer in the documentation and/or other materials
  21. * provided with the distribution.
  22. *
  23. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
  24. * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
  25. * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
  26. * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
  27. * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
  28. * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
  29. * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  30. * SOFTWARE.
  31. *
  32. */
  33. #ifndef USNIC_FWD_H_
  34. #define USNIC_FWD_H_
  35. #include <linux/if.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/pci.h>
  38. #include <linux/in.h>
  39. #include "usnic_abi.h"
  40. #include "usnic_common_pkt_hdr.h"
  41. #include "vnic_devcmd.h"
  42. struct usnic_fwd_dev {
  43. struct pci_dev *pdev;
  44. struct net_device *netdev;
  45. spinlock_t lock;
  46. /*
  47. * The following fields can be read directly off the device.
  48. * However, they should be set by a accessor function, except name,
  49. * which cannot be changed.
  50. */
  51. bool link_up;
  52. char mac[ETH_ALEN];
  53. unsigned int mtu;
  54. __be32 inaddr;
  55. char name[IFNAMSIZ+1];
  56. };
  57. struct usnic_fwd_flow {
  58. uint32_t flow_id;
  59. struct usnic_fwd_dev *ufdev;
  60. unsigned int vnic_idx;
  61. };
  62. struct usnic_filter_action {
  63. int vnic_idx;
  64. struct filter_action action;
  65. };
  66. struct usnic_fwd_dev *usnic_fwd_dev_alloc(struct pci_dev *pdev);
  67. void usnic_fwd_dev_free(struct usnic_fwd_dev *ufdev);
  68. void usnic_fwd_set_mac(struct usnic_fwd_dev *ufdev, char mac[ETH_ALEN]);
  69. int usnic_fwd_add_ipaddr(struct usnic_fwd_dev *ufdev, __be32 inaddr);
  70. void usnic_fwd_del_ipaddr(struct usnic_fwd_dev *ufdev);
  71. void usnic_fwd_carrier_up(struct usnic_fwd_dev *ufdev);
  72. void usnic_fwd_carrier_down(struct usnic_fwd_dev *ufdev);
  73. void usnic_fwd_set_mtu(struct usnic_fwd_dev *ufdev, unsigned int mtu);
  74. /*
  75. * Allocate a flow on this forwarding device. Whoever calls this function,
  76. * must monitor netdev events on ufdev's netdevice. If NETDEV_REBOOT or
  77. * NETDEV_DOWN is seen, flow will no longer function and must be
  78. * immediately freed by calling usnic_dealloc_flow.
  79. */
  80. struct usnic_fwd_flow*
  81. usnic_fwd_alloc_flow(struct usnic_fwd_dev *ufdev, struct filter *filter,
  82. struct usnic_filter_action *action);
  83. int usnic_fwd_dealloc_flow(struct usnic_fwd_flow *flow);
  84. int usnic_fwd_enable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
  85. int usnic_fwd_disable_qp(struct usnic_fwd_dev *ufdev, int vnic_idx, int qp_idx);
  86. static inline void usnic_fwd_init_usnic_filter(struct filter *filter,
  87. uint32_t usnic_id)
  88. {
  89. filter->type = FILTER_USNIC_ID;
  90. filter->u.usnic.ethtype = USNIC_ROCE_ETHERTYPE;
  91. filter->u.usnic.flags = FILTER_FIELD_USNIC_ETHTYPE |
  92. FILTER_FIELD_USNIC_ID |
  93. FILTER_FIELD_USNIC_PROTO;
  94. filter->u.usnic.proto_version = (USNIC_ROCE_GRH_VER <<
  95. USNIC_ROCE_GRH_VER_SHIFT) |
  96. USNIC_PROTO_VER;
  97. filter->u.usnic.usnic_id = usnic_id;
  98. }
  99. static inline void usnic_fwd_init_udp_filter(struct filter *filter,
  100. uint32_t daddr, uint16_t dport)
  101. {
  102. filter->type = FILTER_IPV4_5TUPLE;
  103. filter->u.ipv4.flags = FILTER_FIELD_5TUP_PROTO;
  104. filter->u.ipv4.protocol = PROTO_UDP;
  105. if (daddr) {
  106. filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_AD;
  107. filter->u.ipv4.dst_addr = daddr;
  108. }
  109. if (dport) {
  110. filter->u.ipv4.flags |= FILTER_FIELD_5TUP_DST_PT;
  111. filter->u.ipv4.dst_port = dport;
  112. }
  113. }
  114. #endif /* !USNIC_FWD_H_ */