target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl931x.c
int rtl931x_pie_data_fill(enum template_field_id field_type, struct pie_rule *pr, u16 *data, u16 *data_m)
{
	*data = *data_m = 0;

	switch (field_type) {
	case TEMPLATE_FIELD_SPM0:
		*data = pr->spm;
		*data_m = pr->spm_m;
		break;
	case TEMPLATE_FIELD_SPM1:
		*data = pr->spm >> 16;
		*data_m = pr->spm_m >> 16;
		break;
	case TEMPLATE_FIELD_OTAG:
		*data = pr->otag;
		*data_m = pr->otag_m;
		break;
	case TEMPLATE_FIELD_SMAC0:
		*data = pr->smac[4];
		*data = (*data << 8) | pr->smac[5];
		*data_m = pr->smac_m[4];
		*data_m = (*data_m << 8) | pr->smac_m[5];
		break;
	case TEMPLATE_FIELD_SMAC1:
		*data = pr->smac[2];
		*data = (*data << 8) | pr->smac[3];
		*data_m = pr->smac_m[2];
		*data_m = (*data_m << 8) | pr->smac_m[3];
		break;
	case TEMPLATE_FIELD_SMAC2:
		*data = pr->smac[0];
		*data = (*data << 8) | pr->smac[1];
		*data_m = pr->smac_m[0];
		*data_m = (*data_m << 8) | pr->smac_m[1];
		break;
	case TEMPLATE_FIELD_DMAC0:
		*data = pr->dmac[4];
		*data = (*data << 8) | pr->dmac[5];
		*data_m = pr->dmac_m[4];
		*data_m = (*data_m << 8) | pr->dmac_m[5];
		break;
	case TEMPLATE_FIELD_DMAC1:
		*data = pr->dmac[2];
		*data = (*data << 8) | pr->dmac[3];
		*data_m = pr->dmac_m[2];
		*data_m = (*data_m << 8) | pr->dmac_m[3];
		break;
	case TEMPLATE_FIELD_DMAC2:
		*data = pr->dmac[0];
		*data = (*data << 8) | pr->dmac[1];
		*data_m = pr->dmac_m[0];
		*data_m = (*data_m << 8) | pr->dmac_m[1];
		break;
	case TEMPLATE_FIELD_ETHERTYPE:
		*data = pr->ethertype;
		*data_m = pr->ethertype_m;
		break;
	case TEMPLATE_FIELD_ITAG:
		*data = pr->itag;
		*data_m = pr->itag_m;
		break;
	case TEMPLATE_FIELD_SIP0:
		if (pr->is_ipv6) {
			*data = pr->sip6.s6_addr16[7];
			*data_m = pr->sip6_m.s6_addr16[7];
		} else {
			*data = pr->sip;
			*data_m = pr->sip_m;
		}
		break;
	case TEMPLATE_FIELD_SIP1:
		if (pr->is_ipv6) {
			*data = pr->sip6.s6_addr16[6];
			*data_m = pr->sip6_m.s6_addr16[6];
		} else {
			*data = pr->sip >> 16;
			*data_m = pr->sip_m >> 16;
		}
		break;
	case TEMPLATE_FIELD_SIP2:
	case TEMPLATE_FIELD_SIP3:
	case TEMPLATE_FIELD_SIP4:
	case TEMPLATE_FIELD_SIP5:
	case TEMPLATE_FIELD_SIP6:
	case TEMPLATE_FIELD_SIP7:
		*data = pr->sip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
		*data_m = pr->sip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
		break;

	case TEMPLATE_FIELD_DIP0:
		if (pr->is_ipv6) {
			*data = pr->dip6.s6_addr16[7];
			*data_m = pr->dip6_m.s6_addr16[7];
		} else {
			*data = pr->dip;
			*data_m = pr->dip_m;
		}
		break;
		case TEMPLATE_FIELD_DIP1:
		if (pr->is_ipv6) {
			*data = pr->dip6.s6_addr16[6];
			*data_m = pr->dip6_m.s6_addr16[6];
		} else {
			*data = pr->dip >> 16;
			*data_m = pr->dip_m >> 16;
		}
		break;

	case TEMPLATE_FIELD_DIP2:
	case TEMPLATE_FIELD_DIP3:
	case TEMPLATE_FIELD_DIP4:
	case TEMPLATE_FIELD_DIP5:
	case TEMPLATE_FIELD_DIP6:
	case TEMPLATE_FIELD_DIP7:
		*data = pr->dip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
		*data_m = pr->dip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
		break;

	case TEMPLATE_FIELD_IP_TOS_PROTO:
		*data = pr->tos_proto;
		*data_m = pr->tos_proto_m;
		break;
	case TEMPLATE_FIELD_L4_SPORT:
		*data = pr->sport;
		*data_m = pr->sport_m;
		break;
	case TEMPLATE_FIELD_L4_DPORT:
		*data = pr->dport;
		*data_m = pr->dport_m;
		break;
	case TEMPLATE_FIELD_DSAP_SSAP:
		*data = pr->dsap_ssap;
		*data_m = pr->dsap_ssap_m;
		break;
	case TEMPLATE_FIELD_TCP_INFO:
		*data = pr->tcp_info;
		*data_m = pr->tcp_info_m;
		break;
	case TEMPLATE_FIELD_RANGE_CHK:
		pr_info("TEMPLATE_FIELD_RANGE_CHK: not configured\n");
		break;
	default:
		pr_info("%s: unknown field %d\n", __func__, field_type);
		return -1;
	}

	return 0;
}
/*
 * Fills the data in the intermediate representation in the pie_rule structure
 * into a data field for a given template field field_type
 * TODO: This function looks very similar to the function of the rtl9300, but
 * since it uses the physical template_field_id, which are different for each
 * SoC and there are other field types, it is actually not. If we would also use
 * an intermediate representation for a field type, we would could have one
 * pie_data_fill function for all SoCs, provided we have also for each SoC a
 * function to map between physical and intermediate field type
 */
Fills the data in the intermediate representation in the pie_rule structure
into a data field for a given template field field_type
TODO: This function looks very similar to the function of the rtl9300, but
since it uses the physical template_field_id, which are different for each
SoC and there are other field types, it is actually not. If we would also use
an intermediate representation for a field type, we would could have one
pie_data_fill function for all SoCs, provided we have also for each SoC a
function to map between physical and intermediate field type
Fills the data in the intermediate representation in the pie_rule structure into a data field for a given template field field_type TODO : This function looks very similar to the function of the rtl9300 but since it uses the physical template_field_id which are different for each SoC and there are other field types it is actually not . If we would also use an intermediate representation for a field type we would could have one pie_data_fill function for all SoCs provided we have also for each SoC a function to map between physical and intermediate field type
int rtl931x_pie_data_fill(enum template_field_id field_type, struct pie_rule *pr, u16 *data, u16 *data_m)
{
	*data = *data_m = 0;
	switch (field_type) {
	case TEMPLATE_FIELD_SPM0:
		*data = pr->spm;
		*data_m = pr->spm_m;
		break;
	case TEMPLATE_FIELD_SPM1:
		*data = pr->spm >> 16;
		*data_m = pr->spm_m >> 16;
		break;
	case TEMPLATE_FIELD_OTAG:
		*data = pr->otag;
		*data_m = pr->otag_m;
		break;
	case TEMPLATE_FIELD_SMAC0:
		*data = pr->smac[4];
		*data = (*data << 8) | pr->smac[5];
		*data_m = pr->smac_m[4];
		*data_m = (*data_m << 8) | pr->smac_m[5];
		break;
	case TEMPLATE_FIELD_SMAC1:
		*data = pr->smac[2];
		*data = (*data << 8) | pr->smac[3];
		*data_m = pr->smac_m[2];
		*data_m = (*data_m << 8) | pr->smac_m[3];
		break;
	case TEMPLATE_FIELD_SMAC2:
		*data = pr->smac[0];
		*data = (*data << 8) | pr->smac[1];
		*data_m = pr->smac_m[0];
		*data_m = (*data_m << 8) | pr->smac_m[1];
		break;
	case TEMPLATE_FIELD_DMAC0:
		*data = pr->dmac[4];
		*data = (*data << 8) | pr->dmac[5];
		*data_m = pr->dmac_m[4];
		*data_m = (*data_m << 8) | pr->dmac_m[5];
		break;
	case TEMPLATE_FIELD_DMAC1:
		*data = pr->dmac[2];
		*data = (*data << 8) | pr->dmac[3];
		*data_m = pr->dmac_m[2];
		*data_m = (*data_m << 8) | pr->dmac_m[3];
		break;
	case TEMPLATE_FIELD_DMAC2:
		*data = pr->dmac[0];
		*data = (*data << 8) | pr->dmac[1];
		*data_m = pr->dmac_m[0];
		*data_m = (*data_m << 8) | pr->dmac_m[1];
		break;
	case TEMPLATE_FIELD_ETHERTYPE:
		*data = pr->ethertype;
		*data_m = pr->ethertype_m;
		break;
	case TEMPLATE_FIELD_ITAG:
		*data = pr->itag;
		*data_m = pr->itag_m;
		break;
	case TEMPLATE_FIELD_SIP0:
		if (pr->is_ipv6) {
			*data = pr->sip6.s6_addr16[7];
			*data_m = pr->sip6_m.s6_addr16[7];
		} else {
			*data = pr->sip;
			*data_m = pr->sip_m;
		}
		break;
	case TEMPLATE_FIELD_SIP1:
		if (pr->is_ipv6) {
			*data = pr->sip6.s6_addr16[6];
			*data_m = pr->sip6_m.s6_addr16[6];
		} else {
			*data = pr->sip >> 16;
			*data_m = pr->sip_m >> 16;
		}
		break;
	case TEMPLATE_FIELD_SIP2:
	case TEMPLATE_FIELD_SIP3:
	case TEMPLATE_FIELD_SIP4:
	case TEMPLATE_FIELD_SIP5:
	case TEMPLATE_FIELD_SIP6:
	case TEMPLATE_FIELD_SIP7:
		*data = pr->sip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
		*data_m = pr->sip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_SIP2)];
		break;
	case TEMPLATE_FIELD_DIP0:
		if (pr->is_ipv6) {
			*data = pr->dip6.s6_addr16[7];
			*data_m = pr->dip6_m.s6_addr16[7];
		} else {
			*data = pr->dip;
			*data_m = pr->dip_m;
		}
		break;
		case TEMPLATE_FIELD_DIP1:
		if (pr->is_ipv6) {
			*data = pr->dip6.s6_addr16[6];
			*data_m = pr->dip6_m.s6_addr16[6];
		} else {
			*data = pr->dip >> 16;
			*data_m = pr->dip_m >> 16;
		}
		break;
	case TEMPLATE_FIELD_DIP2:
	case TEMPLATE_FIELD_DIP3:
	case TEMPLATE_FIELD_DIP4:
	case TEMPLATE_FIELD_DIP5:
	case TEMPLATE_FIELD_DIP6:
	case TEMPLATE_FIELD_DIP7:
		*data = pr->dip6.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
		*data_m = pr->dip6_m.s6_addr16[5 - (field_type - TEMPLATE_FIELD_DIP2)];
		break;
	case TEMPLATE_FIELD_IP_TOS_PROTO:
		*data = pr->tos_proto;
		*data_m = pr->tos_proto_m;
		break;
	case TEMPLATE_FIELD_L4_SPORT:
		*data = pr->sport;
		*data_m = pr->sport_m;
		break;
	case TEMPLATE_FIELD_L4_DPORT:
		*data = pr->dport;
		*data_m = pr->dport_m;
		break;
	case TEMPLATE_FIELD_DSAP_SSAP:
		*data = pr->dsap_ssap;
		*data_m = pr->dsap_ssap_m;
		break;
	case TEMPLATE_FIELD_TCP_INFO:
		*data = pr->tcp_info;
		*data_m = pr->tcp_info_m;
		break;
	case TEMPLATE_FIELD_RANGE_CHK:
		pr_info("TEMPLATE_FIELD_RANGE_CHK: not configured\n");
		break;
	default:
		pr_info("%s: unknown field %d\n", __func__, field_type);
		return -1;
	}
	return 0;
}
int rtl931x_pie_data_fill ( enum template_field_id field_type , struct pie_rule * pr , u16 * data , u16 * data_m ) { * data = * data_m = 0 ; switch ( field_type ) { case TEMPLATE_FIELD_SPM0 : * data = pr -> spm ; * data_m = pr -> spm_m ; break ; case TEMPLATE_FIELD_SPM1 : * data = pr -> spm >> 16 ; * data_m = pr -> spm_m >> 16 ; break ; case TEMPLATE_FIELD_OTAG : * data = pr -> otag ; * data_m = pr -> otag_m ; break ; case TEMPLATE_FIELD_SMAC0 : * data = pr -> smac [ 4 ] ; * data = ( * data << 8 ) | pr -> smac [ 5 ] ; * data_m = pr -> smac_m [ 4 ] ; * data_m = ( * data_m << 8 ) | pr -> smac_m [ 5 ] ; break ; case TEMPLATE_FIELD_SMAC1 : * data = pr -> smac [ 2 ] ; * data = ( * data << 8 ) | pr -> smac [ 3 ] ; * data_m = pr -> smac_m [ 2 ] ; * data_m = ( * data_m << 8 ) | pr -> smac_m [ 3 ] ; break ; case TEMPLATE_FIELD_SMAC2 : * data = pr -> smac [ 0 ] ; * data = ( * data << 8 ) | pr -> smac [ 1 ] ; * data_m = pr -> smac_m [ 0 ] ; * data_m = ( * data_m << 8 ) | pr -> smac_m [ 1 ] ; break ; case TEMPLATE_FIELD_DMAC0 : * data = pr -> dmac [ 4 ] ; * data = ( * data << 8 ) | pr -> dmac [ 5 ] ; * data_m = pr -> dmac_m [ 4 ] ; * data_m = ( * data_m << 8 ) | pr -> dmac_m [ 5 ] ; break ; case TEMPLATE_FIELD_DMAC1 : * data = pr -> dmac [ 2 ] ; * data = ( * data << 8 ) | pr -> dmac [ 3 ] ; * data_m = pr -> dmac_m [ 2 ] ; * data_m = ( * data_m << 8 ) | pr -> dmac_m [ 3 ] ; break ; case TEMPLATE_FIELD_DMAC2 : * data = pr -> dmac [ 0 ] ; * data = ( * data << 8 ) | pr -> dmac [ 1 ] ; * data_m = pr -> dmac_m [ 0 ] ; * data_m = ( * data_m << 8 ) | pr -> dmac_m [ 1 ] ; break ; case TEMPLATE_FIELD_ETHERTYPE : * data = pr -> ethertype ; * data_m = pr -> ethertype_m ; break ; case TEMPLATE_FIELD_ITAG : * data = pr -> itag ; * data_m = pr -> itag_m ; break ; case TEMPLATE_FIELD_SIP0 : if ( pr -> is_ipv6 ) { * data = pr -> sip6 . s6_addr16 [ 7 ] ; * data_m = pr -> sip6_m . s6_addr16 [ 7 ] ; } else { * data = pr -> sip ; * data_m = pr -> sip_m ; } break ; case TEMPLATE_FIELD_SIP1 : if ( pr -> is_ipv6 ) { * data = pr -> sip6 . s6_addr16 [ 6 ] ; * data_m = pr -> sip6_m . s6_addr16 [ 6 ] ; } else { * data = pr -> sip >> 16 ; * data_m = pr -> sip_m >> 16 ; } break ; case TEMPLATE_FIELD_SIP2 : case TEMPLATE_FIELD_SIP3 : case TEMPLATE_FIELD_SIP4 : case TEMPLATE_FIELD_SIP5 : case TEMPLATE_FIELD_SIP6 : case TEMPLATE_FIELD_SIP7 : * data = pr -> sip6 . s6_addr16 [ 5 - ( field_type - TEMPLATE_FIELD_SIP2 ) ] ; * data_m = pr -> sip6_m . s6_addr16 [ 5 - ( field_type - TEMPLATE_FIELD_SIP2 ) ] ; break ; case TEMPLATE_FIELD_DIP0 : if ( pr -> is_ipv6 ) { * data = pr -> dip6 . s6_addr16 [ 7 ] ; * data_m = pr -> dip6_m . s6_addr16 [ 7 ] ; } else { * data = pr -> dip ; * data_m = pr -> dip_m ; } break ; case TEMPLATE_FIELD_DIP1 : if ( pr -> is_ipv6 ) { * data = pr -> dip6 . s6_addr16 [ 6 ] ; * data_m = pr -> dip6_m . s6_addr16 [ 6 ] ; } else { * data = pr -> dip >> 16 ; * data_m = pr -> dip_m >> 16 ; } break ; case TEMPLATE_FIELD_DIP2 : case TEMPLATE_FIELD_DIP3 : case TEMPLATE_FIELD_DIP4 : case TEMPLATE_FIELD_DIP5 : case TEMPLATE_FIELD_DIP6 : case TEMPLATE_FIELD_DIP7 : * data = pr -> dip6 . s6_addr16 [ 5 - ( field_type - TEMPLATE_FIELD_DIP2 ) ] ; * data_m = pr -> dip6_m . s6_addr16 [ 5 - ( field_type - TEMPLATE_FIELD_DIP2 ) ] ; break ; case TEMPLATE_FIELD_IP_TOS_PROTO : * data = pr -> tos_proto ; * data_m = pr -> tos_proto_m ; break ; case TEMPLATE_FIELD_L4_SPORT : * data = pr -> sport ; * data_m = pr -> sport_m ; break ; case TEMPLATE_FIELD_L4_DPORT : * data = pr -> dport ; * data_m = pr -> dport_m ; break ; case TEMPLATE_FIELD_DSAP_SSAP : * data = pr -> dsap_ssap ; * data_m = pr -> dsap_ssap_m ; break ; case TEMPLATE_FIELD_TCP_INFO : * data = pr -> tcp_info ; * data_m = pr -> tcp_info_m ; break ; case TEMPLATE_FIELD_RANGE_CHK : pr_info ( " \n " ) ; break ; default : pr_info ( " \n " , __func__ , field_type ) ; return -1 ; } return 0 ; }
Fills the data in the intermediate representation in the pie_rule structure
 into a data field for a given template field field_type
 TODO: This function looks very similar to the function of the rtl9300, but
 since it uses the physical template_field_id, which are different for each
 SoC and there are other field types, it is actually not.
Fills the data in the intermediate representation in the pie_rule structure into a data field for a given template field field_type TODO : This function looks very similar to the function of the rtl9300 but since it uses the physical template_field_id which are different for each SoC and there are other field types it is actually not .