usnic_fwd.h 3.5 KB

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