0001
0002
0003
0004
0005
0006 #include "iavf.h"
0007
0008
0009
0010
0011
0012
0013 static void
0014 iavf_fill_adv_rss_ip4_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
0015 {
0016 VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV4);
0017
0018 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_IPV4_SA)
0019 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV4, SRC);
0020
0021 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_IPV4_DA)
0022 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV4, DST);
0023 }
0024
0025
0026
0027
0028
0029
0030 static void
0031 iavf_fill_adv_rss_ip6_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
0032 {
0033 VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, IPV6);
0034
0035 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_IPV6_SA)
0036 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV6, SRC);
0037
0038 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_IPV6_DA)
0039 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, IPV6, DST);
0040 }
0041
0042
0043
0044
0045
0046
0047 static void
0048 iavf_fill_adv_rss_tcp_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
0049 {
0050 VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, TCP);
0051
0052 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT)
0053 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, TCP, SRC_PORT);
0054
0055 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT)
0056 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, TCP, DST_PORT);
0057 }
0058
0059
0060
0061
0062
0063
0064 static void
0065 iavf_fill_adv_rss_udp_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
0066 {
0067 VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, UDP);
0068
0069 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT)
0070 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, UDP, SRC_PORT);
0071
0072 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT)
0073 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, UDP, DST_PORT);
0074 }
0075
0076
0077
0078
0079
0080
0081 static void
0082 iavf_fill_adv_rss_sctp_hdr(struct virtchnl_proto_hdr *hdr, u64 hash_flds)
0083 {
0084 VIRTCHNL_SET_PROTO_HDR_TYPE(hdr, SCTP);
0085
0086 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT)
0087 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, SCTP, SRC_PORT);
0088
0089 if (hash_flds & IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT)
0090 VIRTCHNL_ADD_PROTO_HDR_FIELD_BIT(hdr, SCTP, DST_PORT);
0091 }
0092
0093
0094
0095
0096
0097
0098
0099
0100
0101 int
0102 iavf_fill_adv_rss_cfg_msg(struct virtchnl_rss_cfg *rss_cfg,
0103 u32 packet_hdrs, u64 hash_flds)
0104 {
0105 struct virtchnl_proto_hdrs *proto_hdrs = &rss_cfg->proto_hdrs;
0106 struct virtchnl_proto_hdr *hdr;
0107
0108 rss_cfg->rss_algorithm = VIRTCHNL_RSS_ALG_TOEPLITZ_ASYMMETRIC;
0109
0110 proto_hdrs->tunnel_level = 0;
0111
0112 hdr = &proto_hdrs->proto_hdr[proto_hdrs->count++];
0113 switch (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_L3) {
0114 case IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4:
0115 iavf_fill_adv_rss_ip4_hdr(hdr, hash_flds);
0116 break;
0117 case IAVF_ADV_RSS_FLOW_SEG_HDR_IPV6:
0118 iavf_fill_adv_rss_ip6_hdr(hdr, hash_flds);
0119 break;
0120 default:
0121 return -EINVAL;
0122 }
0123
0124 hdr = &proto_hdrs->proto_hdr[proto_hdrs->count++];
0125 switch (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_L4) {
0126 case IAVF_ADV_RSS_FLOW_SEG_HDR_TCP:
0127 iavf_fill_adv_rss_tcp_hdr(hdr, hash_flds);
0128 break;
0129 case IAVF_ADV_RSS_FLOW_SEG_HDR_UDP:
0130 iavf_fill_adv_rss_udp_hdr(hdr, hash_flds);
0131 break;
0132 case IAVF_ADV_RSS_FLOW_SEG_HDR_SCTP:
0133 iavf_fill_adv_rss_sctp_hdr(hdr, hash_flds);
0134 break;
0135 default:
0136 return -EINVAL;
0137 }
0138
0139 return 0;
0140 }
0141
0142
0143
0144
0145
0146
0147
0148
0149 struct iavf_adv_rss *
0150 iavf_find_adv_rss_cfg_by_hdrs(struct iavf_adapter *adapter, u32 packet_hdrs)
0151 {
0152 struct iavf_adv_rss *rss;
0153
0154 list_for_each_entry(rss, &adapter->adv_rss_list_head, list)
0155 if (rss->packet_hdrs == packet_hdrs)
0156 return rss;
0157
0158 return NULL;
0159 }
0160
0161
0162
0163
0164
0165
0166
0167
0168
0169
0170 void
0171 iavf_print_adv_rss_cfg(struct iavf_adapter *adapter, struct iavf_adv_rss *rss,
0172 const char *action, const char *result)
0173 {
0174 u32 packet_hdrs = rss->packet_hdrs;
0175 u64 hash_flds = rss->hash_flds;
0176 static char hash_opt[300];
0177 const char *proto;
0178
0179 if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_TCP)
0180 proto = "TCP";
0181 else if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_UDP)
0182 proto = "UDP";
0183 else if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_SCTP)
0184 proto = "SCTP";
0185 else
0186 return;
0187
0188 memset(hash_opt, 0, sizeof(hash_opt));
0189
0190 strcat(hash_opt, proto);
0191 if (packet_hdrs & IAVF_ADV_RSS_FLOW_SEG_HDR_IPV4)
0192 strcat(hash_opt, "v4 ");
0193 else
0194 strcat(hash_opt, "v6 ");
0195
0196 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_SA |
0197 IAVF_ADV_RSS_HASH_FLD_IPV6_SA))
0198 strcat(hash_opt, "IP SA,");
0199 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_IPV4_DA |
0200 IAVF_ADV_RSS_HASH_FLD_IPV6_DA))
0201 strcat(hash_opt, "IP DA,");
0202 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_SRC_PORT |
0203 IAVF_ADV_RSS_HASH_FLD_UDP_SRC_PORT |
0204 IAVF_ADV_RSS_HASH_FLD_SCTP_SRC_PORT))
0205 strcat(hash_opt, "src port,");
0206 if (hash_flds & (IAVF_ADV_RSS_HASH_FLD_TCP_DST_PORT |
0207 IAVF_ADV_RSS_HASH_FLD_UDP_DST_PORT |
0208 IAVF_ADV_RSS_HASH_FLD_SCTP_DST_PORT))
0209 strcat(hash_opt, "dst port,");
0210
0211 if (!action)
0212 action = "";
0213
0214 if (!result)
0215 result = "";
0216
0217 dev_info(&adapter->pdev->dev, "%s %s %s\n", action, hash_opt, result);
0218 }