|
12 | 12 | */ |
13 | 13 | #define TNL_SEG_CNT(_TNL_) ((_TNL_) + 1) |
14 | 14 |
|
| 15 | +/** |
| 16 | + * ice_fltr_to_ethtool_flow - convert filter type values to ethtool |
| 17 | + * flow type values |
| 18 | + * @flow: filter type to be converted |
| 19 | + * |
| 20 | + * Returns the corresponding ethtool flow type. |
| 21 | + */ |
| 22 | +static int ice_fltr_to_ethtool_flow(enum ice_fltr_ptype flow) |
| 23 | +{ |
| 24 | + switch (flow) { |
| 25 | + case ICE_FLTR_PTYPE_NONF_IPV4_TCP: |
| 26 | + return TCP_V4_FLOW; |
| 27 | + case ICE_FLTR_PTYPE_NONF_IPV4_UDP: |
| 28 | + return UDP_V4_FLOW; |
| 29 | + case ICE_FLTR_PTYPE_NONF_IPV4_SCTP: |
| 30 | + return SCTP_V4_FLOW; |
| 31 | + case ICE_FLTR_PTYPE_NONF_IPV4_OTHER: |
| 32 | + return IPV4_USER_FLOW; |
| 33 | + default: |
| 34 | + /* 0 is undefined ethtool flow */ |
| 35 | + return 0; |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * ice_ethtool_flow_to_fltr - convert ethtool flow type to filter enum |
| 41 | + * @eth: Ethtool flow type to be converted |
| 42 | + * |
| 43 | + * Returns flow enum |
| 44 | + */ |
| 45 | +static enum ice_fltr_ptype ice_ethtool_flow_to_fltr(int eth) |
| 46 | +{ |
| 47 | + switch (eth) { |
| 48 | + case TCP_V4_FLOW: |
| 49 | + return ICE_FLTR_PTYPE_NONF_IPV4_TCP; |
| 50 | + case UDP_V4_FLOW: |
| 51 | + return ICE_FLTR_PTYPE_NONF_IPV4_UDP; |
| 52 | + case SCTP_V4_FLOW: |
| 53 | + return ICE_FLTR_PTYPE_NONF_IPV4_SCTP; |
| 54 | + case IPV4_USER_FLOW: |
| 55 | + return ICE_FLTR_PTYPE_NONF_IPV4_OTHER; |
| 56 | + default: |
| 57 | + return ICE_FLTR_PTYPE_NONF_NONE; |
| 58 | + } |
| 59 | +} |
| 60 | + |
| 61 | +/** |
| 62 | + * ice_get_ethtool_fdir_entry - fill ethtool structure with fdir filter data |
| 63 | + * @hw: hardware structure that contains filter list |
| 64 | + * @cmd: ethtool command data structure to receive the filter data |
| 65 | + * |
| 66 | + * Returns 0 on success and -EINVAL on failure |
| 67 | + */ |
| 68 | +int ice_get_ethtool_fdir_entry(struct ice_hw *hw, struct ethtool_rxnfc *cmd) |
| 69 | +{ |
| 70 | + struct ethtool_rx_flow_spec *fsp; |
| 71 | + struct ice_fdir_fltr *rule; |
| 72 | + int ret = 0; |
| 73 | + u16 idx; |
| 74 | + |
| 75 | + fsp = (struct ethtool_rx_flow_spec *)&cmd->fs; |
| 76 | + |
| 77 | + mutex_lock(&hw->fdir_fltr_lock); |
| 78 | + |
| 79 | + rule = ice_fdir_find_fltr_by_idx(hw, fsp->location); |
| 80 | + |
| 81 | + if (!rule || fsp->location != rule->fltr_id) { |
| 82 | + ret = -EINVAL; |
| 83 | + goto release_lock; |
| 84 | + } |
| 85 | + |
| 86 | + fsp->flow_type = ice_fltr_to_ethtool_flow(rule->flow_type); |
| 87 | + |
| 88 | + memset(&fsp->m_u, 0, sizeof(fsp->m_u)); |
| 89 | + memset(&fsp->m_ext, 0, sizeof(fsp->m_ext)); |
| 90 | + |
| 91 | + switch (fsp->flow_type) { |
| 92 | + case IPV4_USER_FLOW: |
| 93 | + fsp->h_u.usr_ip4_spec.ip_ver = ETH_RX_NFC_IP4; |
| 94 | + fsp->h_u.usr_ip4_spec.proto = 0; |
| 95 | + fsp->h_u.usr_ip4_spec.l4_4_bytes = rule->ip.l4_header; |
| 96 | + fsp->h_u.usr_ip4_spec.tos = rule->ip.tos; |
| 97 | + fsp->h_u.usr_ip4_spec.ip4src = rule->ip.src_ip; |
| 98 | + fsp->h_u.usr_ip4_spec.ip4dst = rule->ip.dst_ip; |
| 99 | + fsp->m_u.usr_ip4_spec.ip4src = rule->mask.src_ip; |
| 100 | + fsp->m_u.usr_ip4_spec.ip4dst = rule->mask.dst_ip; |
| 101 | + fsp->m_u.usr_ip4_spec.ip_ver = 0xFF; |
| 102 | + fsp->m_u.usr_ip4_spec.proto = 0; |
| 103 | + fsp->m_u.usr_ip4_spec.l4_4_bytes = rule->mask.l4_header; |
| 104 | + fsp->m_u.usr_ip4_spec.tos = rule->mask.tos; |
| 105 | + break; |
| 106 | + case TCP_V4_FLOW: |
| 107 | + case UDP_V4_FLOW: |
| 108 | + case SCTP_V4_FLOW: |
| 109 | + fsp->h_u.tcp_ip4_spec.psrc = rule->ip.src_port; |
| 110 | + fsp->h_u.tcp_ip4_spec.pdst = rule->ip.dst_port; |
| 111 | + fsp->h_u.tcp_ip4_spec.ip4src = rule->ip.src_ip; |
| 112 | + fsp->h_u.tcp_ip4_spec.ip4dst = rule->ip.dst_ip; |
| 113 | + fsp->m_u.tcp_ip4_spec.psrc = rule->mask.src_port; |
| 114 | + fsp->m_u.tcp_ip4_spec.pdst = rule->mask.dst_port; |
| 115 | + fsp->m_u.tcp_ip4_spec.ip4src = rule->mask.src_ip; |
| 116 | + fsp->m_u.tcp_ip4_spec.ip4dst = rule->mask.dst_ip; |
| 117 | + break; |
| 118 | + default: |
| 119 | + break; |
| 120 | + } |
| 121 | + |
| 122 | + if (rule->dest_ctl == ICE_FLTR_PRGM_DESC_DEST_DROP_PKT) |
| 123 | + fsp->ring_cookie = RX_CLS_FLOW_DISC; |
| 124 | + else |
| 125 | + fsp->ring_cookie = rule->q_index; |
| 126 | + |
| 127 | + idx = ice_ethtool_flow_to_fltr(fsp->flow_type); |
| 128 | + if (idx == ICE_FLTR_PTYPE_NONF_NONE) { |
| 129 | + dev_err(ice_hw_to_dev(hw), "Missing input index for flow_type %d\n", |
| 130 | + rule->flow_type); |
| 131 | + ret = -EINVAL; |
| 132 | + } |
| 133 | + |
| 134 | +release_lock: |
| 135 | + mutex_unlock(&hw->fdir_fltr_lock); |
| 136 | + return ret; |
| 137 | +} |
| 138 | + |
| 139 | +/** |
| 140 | + * ice_get_fdir_fltr_ids - fill buffer with filter IDs of active filters |
| 141 | + * @hw: hardware structure containing the filter list |
| 142 | + * @cmd: ethtool command data structure |
| 143 | + * @rule_locs: ethtool array passed in from OS to receive filter IDs |
| 144 | + * |
| 145 | + * Returns 0 as expected for success by ethtool |
| 146 | + */ |
| 147 | +int |
| 148 | +ice_get_fdir_fltr_ids(struct ice_hw *hw, struct ethtool_rxnfc *cmd, |
| 149 | + u32 *rule_locs) |
| 150 | +{ |
| 151 | + struct ice_fdir_fltr *f_rule; |
| 152 | + unsigned int cnt = 0; |
| 153 | + int val = 0; |
| 154 | + |
| 155 | + /* report total rule count */ |
| 156 | + cmd->data = ice_get_fdir_cnt_all(hw); |
| 157 | + |
| 158 | + mutex_lock(&hw->fdir_fltr_lock); |
| 159 | + |
| 160 | + list_for_each_entry(f_rule, &hw->fdir_list_head, fltr_node) { |
| 161 | + if (cnt == cmd->rule_cnt) { |
| 162 | + val = -EMSGSIZE; |
| 163 | + goto release_lock; |
| 164 | + } |
| 165 | + rule_locs[cnt] = f_rule->fltr_id; |
| 166 | + cnt++; |
| 167 | + } |
| 168 | + |
| 169 | +release_lock: |
| 170 | + mutex_unlock(&hw->fdir_fltr_lock); |
| 171 | + if (!val) |
| 172 | + cmd->rule_cnt = cnt; |
| 173 | + return val; |
| 174 | +} |
| 175 | + |
15 | 176 | /** |
16 | 177 | * ice_fdir_get_hw_prof - return the ice_fd_hw_proc associated with a flow |
17 | 178 | * @hw: hardware structure containing the filter list |
|
0 commit comments