tc.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /****************************************************************************
  3. * Driver for Solarflare network controllers and boards
  4. * Copyright 2019 Solarflare Communications Inc.
  5. * Copyright 2020-2022 Xilinx Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or modify it
  8. * under the terms of the GNU General Public License version 2 as published
  9. * by the Free Software Foundation, incorporated herein by reference.
  10. */
  11. #ifndef EFX_TC_H
  12. #define EFX_TC_H
  13. #include <net/flow_offload.h>
  14. #include <linux/rhashtable.h>
  15. #include "net_driver.h"
  16. /* Error reporting: convenience macros. For indicating why a given filter
  17. * insertion is not supported; errors in internal operation or in the
  18. * hardware should be netif_err()s instead.
  19. */
  20. /* Used when error message is constant. */
  21. #define EFX_TC_ERR_MSG(efx, extack, message) do { \
  22. NL_SET_ERR_MSG_MOD(extack, message); \
  23. if (efx->log_tc_errs) \
  24. netif_info(efx, drv, efx->net_dev, "%s\n", message); \
  25. } while (0)
  26. /* Used when error message is not constant; caller should also supply a
  27. * constant extack message with NL_SET_ERR_MSG_MOD().
  28. */
  29. #define efx_tc_err(efx, fmt, args...) do { \
  30. if (efx->log_tc_errs) \
  31. netif_info(efx, drv, efx->net_dev, fmt, ##args);\
  32. } while (0)
  33. struct efx_tc_action_set {
  34. u16 deliver:1;
  35. u32 dest_mport;
  36. u32 fw_id; /* index of this entry in firmware actions table */
  37. struct list_head list;
  38. };
  39. struct efx_tc_match_fields {
  40. /* L1 */
  41. u32 ingress_port;
  42. u8 recirc_id;
  43. };
  44. struct efx_tc_match {
  45. struct efx_tc_match_fields value;
  46. struct efx_tc_match_fields mask;
  47. };
  48. struct efx_tc_action_set_list {
  49. struct list_head list;
  50. u32 fw_id;
  51. };
  52. struct efx_tc_flow_rule {
  53. unsigned long cookie;
  54. struct rhash_head linkage;
  55. struct efx_tc_match match;
  56. struct efx_tc_action_set_list acts;
  57. u32 fw_id;
  58. };
  59. enum efx_tc_rule_prios {
  60. EFX_TC_PRIO_TC, /* Rule inserted by TC */
  61. EFX_TC_PRIO_DFLT, /* Default switch rule; one of efx_tc_default_rules */
  62. EFX_TC_PRIO__NUM
  63. };
  64. /**
  65. * struct efx_tc_state - control plane data for TC offload
  66. *
  67. * @caps: MAE capabilities reported by MCDI
  68. * @block_list: List of &struct efx_tc_block_binding
  69. * @mutex: Used to serialise operations on TC hashtables
  70. * @match_action_ht: Hashtable of TC match-action rules
  71. * @reps_mport_id: MAE port allocated for representor RX
  72. * @reps_filter_uc: VNIC filter for representor unicast RX (promisc)
  73. * @reps_filter_mc: VNIC filter for representor multicast RX (allmulti)
  74. * @reps_mport_vport_id: vport_id for representor RX filters
  75. * @dflt: Match-action rules for default switching; at priority
  76. * %EFX_TC_PRIO_DFLT. Named by *ingress* port
  77. * @dflt.pf: rule for traffic ingressing from PF (egresses to wire)
  78. * @dflt.wire: rule for traffic ingressing from wire (egresses to PF)
  79. * @up: have TC datastructures been set up?
  80. */
  81. struct efx_tc_state {
  82. struct mae_caps *caps;
  83. struct list_head block_list;
  84. struct mutex mutex;
  85. struct rhashtable match_action_ht;
  86. u32 reps_mport_id, reps_mport_vport_id;
  87. s32 reps_filter_uc, reps_filter_mc;
  88. struct {
  89. struct efx_tc_flow_rule pf;
  90. struct efx_tc_flow_rule wire;
  91. } dflt;
  92. bool up;
  93. };
  94. struct efx_rep;
  95. int efx_tc_configure_default_rule_rep(struct efx_rep *efv);
  96. void efx_tc_deconfigure_default_rule(struct efx_nic *efx,
  97. struct efx_tc_flow_rule *rule);
  98. int efx_tc_flower(struct efx_nic *efx, struct net_device *net_dev,
  99. struct flow_cls_offload *tc, struct efx_rep *efv);
  100. int efx_tc_insert_rep_filters(struct efx_nic *efx);
  101. void efx_tc_remove_rep_filters(struct efx_nic *efx);
  102. int efx_init_tc(struct efx_nic *efx);
  103. void efx_fini_tc(struct efx_nic *efx);
  104. int efx_init_struct_tc(struct efx_nic *efx);
  105. void efx_fini_struct_tc(struct efx_nic *efx);
  106. #endif /* EFX_TC_H */