target/linux/realtek/files-5.10/drivers/net/dsa/rtl83xx/rtl930x.c
static void rtl930x_write_pie_templated(u32 r[], struct pie_rule *pr, enum template_field_id t[])
{
	int i;
	enum template_field_id field_type;
	u16 data, data_m;

	for (i = 0; i < N_FIXED_FIELDS; i++) {
		field_type = t[i];
		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_warn("Warning: TEMPLATE_FIELD_RANGE_CHK: not configured\n");
			break;
		default:
			pr_info("%s: unknown field %d\n", __func__, field_type);
		}

		// On the RTL9300, the mask fields are not word aligned!
		if (!(i % 2)) {
			r[5 - i / 2] = data;
			r[12 - i / 2] |= ((u32)data_m << 8);
		} else {
			r[5 - i / 2] |= ((u32)data) << 16;
			r[12 - i / 2] |= ((u32)data_m) << 24;
			r[11 - i / 2] |= ((u32)data_m) >> 8;
		}
	}
}
/*
 * Reads the intermediate representation of the templated match-fields of the
 * PIE rule in the pie_rule structure and fills in the raw data fields in the
 * raw register space r[].
 * The register space configuration size is identical for the RTL8380/90 and RTL9300,
 * however the RTL9310 has 2 more registers / fields and the physical field-ids are different
 * on all SoCs
 * On the RTL9300 the mask fields are not word-aligend!
 */
Reads the intermediate representation of the templated match-fields of the
PIE rule in the pie_rule structure and fills in the raw data fields in the
raw register space r[].
The register space configuration size is identical for the RTL8380/90 and RTL9300,
however the RTL9310 has 2 more registers / fields and the physical field-ids are different
on all SoCs
On the RTL9300 the mask fields are not word-aligend!
Reads the intermediate representation of the templated match - fields of the PIE rule in the pie_rule structure and fills in the raw data fields in the raw register space r [] . The register space configuration size is identical for the RTL8380 / 90 and RTL9300 however the RTL9310 has 2 more registers / fields and the physical field - ids are different on all SoCs On the RTL9300 the mask fields are not word - aligend!
static void rtl930x_write_pie_templated(u32 r[], struct pie_rule *pr, enum template_field_id t[])
{
	int i;
	enum template_field_id field_type;
	u16 data, data_m;
	for (i = 0; i < N_FIXED_FIELDS; i++) {
		field_type = t[i];
		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_warn("Warning: TEMPLATE_FIELD_RANGE_CHK: not configured\n");
			break;
		default:
			pr_info("%s: unknown field %d\n", __func__, field_type);
		}
		if (!(i % 2)) {
			r[5 - i / 2] = data;
			r[12 - i / 2] |= ((u32)data_m << 8);
		} else {
			r[5 - i / 2] |= ((u32)data) << 16;
			r[12 - i / 2] |= ((u32)data_m) << 24;
			r[11 - i / 2] |= ((u32)data_m) >> 8;
		}
	}
}
static void rtl930x_write_pie_templated ( u32 r [ ] , struct pie_rule * pr , enum template_field_id t [ ] ) { int i ; enum template_field_id field_type ; u16 data , data_m ; for ( i = 0 ; i < N_FIXED_FIELDS ; i ++ ) { field_type = t [ i ] ; 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_warn ( " \n " ) ; break ; default : pr_info ( " \n " , __func__ , field_type ) ; } if ( ! ( i % 2 ) ) { r [ 5 - i / 2 ] = data ; r [ 12 - i / 2 ] |= ( ( u32 ) data_m << 8 ) ; } else { r [ 5 - i / 2 ] |= ( ( u32 ) data ) << 16 ; r [ 12 - i / 2 ] |= ( ( u32 ) data_m ) << 24 ; r [ 11 - i / 2 ] |= ( ( u32 ) data_m ) >> 8 ; } } }
Reads the intermediate representation of the templated match-fields of the
 PIE rule in the pie_rule structure and fills in the raw data fields in the
 raw register space r[].
Reads the intermediate representation of the templated match - fields of the PIE rule in the pie_rule structure and fills in the raw data fields in the raw register space r [] .
// On the RTL9300, the mask fields are not word aligned!