1 /* SPDX-License-Identifier: BSD-3-Clause 2 * Copyright (c) 2016-2018, NXP Semiconductors 3 * Copyright (c) 2018-2019, Vladimir Oltean <olteanv@gmail.com> 4 */ 5 #ifndef _SJA1105_STATIC_CONFIG_H 6 #define _SJA1105_STATIC_CONFIG_H 7 8 #include <linux/packing.h> 9 #include <linux/types.h> 10 #include <asm/types.h> 11 12 #define SJA1105_SIZE_DEVICE_ID 4 13 #define SJA1105_SIZE_TABLE_HEADER 12 14 #define SJA1105_SIZE_L2_POLICING_ENTRY 8 15 #define SJA1105_SIZE_VLAN_LOOKUP_ENTRY 8 16 #define SJA1105_SIZE_L2_FORWARDING_ENTRY 8 17 #define SJA1105_SIZE_L2_FORWARDING_PARAMS_ENTRY 12 18 #define SJA1105_SIZE_XMII_PARAMS_ENTRY 4 19 #define SJA1105ET_SIZE_L2_LOOKUP_ENTRY 12 20 #define SJA1105ET_SIZE_MAC_CONFIG_ENTRY 28 21 #define SJA1105ET_SIZE_L2_LOOKUP_PARAMS_ENTRY 4 22 #define SJA1105ET_SIZE_GENERAL_PARAMS_ENTRY 40 23 #define SJA1105PQRS_SIZE_L2_LOOKUP_ENTRY 20 24 #define SJA1105PQRS_SIZE_MAC_CONFIG_ENTRY 32 25 #define SJA1105PQRS_SIZE_L2_LOOKUP_PARAMS_ENTRY 16 26 #define SJA1105PQRS_SIZE_GENERAL_PARAMS_ENTRY 44 27 28 /* UM10944.pdf Page 11, Table 2. Configuration Blocks */ 29 enum { 30 BLKID_L2_LOOKUP = 0x05, 31 BLKID_L2_POLICING = 0x06, 32 BLKID_VLAN_LOOKUP = 0x07, 33 BLKID_L2_FORWARDING = 0x08, 34 BLKID_MAC_CONFIG = 0x09, 35 BLKID_L2_LOOKUP_PARAMS = 0x0D, 36 BLKID_L2_FORWARDING_PARAMS = 0x0E, 37 BLKID_GENERAL_PARAMS = 0x11, 38 BLKID_XMII_PARAMS = 0x4E, 39 }; 40 41 enum sja1105_blk_idx { 42 BLK_IDX_L2_LOOKUP = 0, 43 BLK_IDX_L2_POLICING, 44 BLK_IDX_VLAN_LOOKUP, 45 BLK_IDX_L2_FORWARDING, 46 BLK_IDX_MAC_CONFIG, 47 BLK_IDX_L2_LOOKUP_PARAMS, 48 BLK_IDX_L2_FORWARDING_PARAMS, 49 BLK_IDX_GENERAL_PARAMS, 50 BLK_IDX_XMII_PARAMS, 51 BLK_IDX_MAX, 52 /* Fake block indices that are only valid for dynamic access */ 53 BLK_IDX_MGMT_ROUTE, 54 BLK_IDX_MAX_DYN, 55 BLK_IDX_INVAL = -1, 56 }; 57 58 #define SJA1105_MAX_L2_LOOKUP_COUNT 1024 59 #define SJA1105_MAX_L2_POLICING_COUNT 45 60 #define SJA1105_MAX_VLAN_LOOKUP_COUNT 4096 61 #define SJA1105_MAX_L2_FORWARDING_COUNT 13 62 #define SJA1105_MAX_MAC_CONFIG_COUNT 5 63 #define SJA1105_MAX_L2_LOOKUP_PARAMS_COUNT 1 64 #define SJA1105_MAX_L2_FORWARDING_PARAMS_COUNT 1 65 #define SJA1105_MAX_GENERAL_PARAMS_COUNT 1 66 #define SJA1105_MAX_XMII_PARAMS_COUNT 1 67 68 #define SJA1105_MAX_FRAME_MEMORY 929 69 70 #define SJA1105E_DEVICE_ID 0x9C00000Cull 71 #define SJA1105T_DEVICE_ID 0x9E00030Eull 72 #define SJA1105PR_DEVICE_ID 0xAF00030Eull 73 #define SJA1105QS_DEVICE_ID 0xAE00030Eull 74 75 #define SJA1105ET_PART_NO 0x9A83 76 #define SJA1105P_PART_NO 0x9A84 77 #define SJA1105Q_PART_NO 0x9A85 78 #define SJA1105R_PART_NO 0x9A86 79 #define SJA1105S_PART_NO 0x9A87 80 81 struct sja1105_general_params_entry { 82 u64 vllupformat; 83 u64 mirr_ptacu; 84 u64 switchid; 85 u64 hostprio; 86 u64 mac_fltres1; 87 u64 mac_fltres0; 88 u64 mac_flt1; 89 u64 mac_flt0; 90 u64 incl_srcpt1; 91 u64 incl_srcpt0; 92 u64 send_meta1; 93 u64 send_meta0; 94 u64 casc_port; 95 u64 host_port; 96 u64 mirr_port; 97 u64 vlmarker; 98 u64 vlmask; 99 u64 tpid; 100 u64 ignore2stf; 101 u64 tpid2; 102 /* P/Q/R/S only */ 103 u64 queue_ts; 104 u64 egrmirrvid; 105 u64 egrmirrpcp; 106 u64 egrmirrdei; 107 u64 replay_port; 108 }; 109 110 struct sja1105_vlan_lookup_entry { 111 u64 ving_mirr; 112 u64 vegr_mirr; 113 u64 vmemb_port; 114 u64 vlan_bc; 115 u64 tag_port; 116 u64 vlanid; 117 }; 118 119 struct sja1105_l2_lookup_entry { 120 u64 vlanid; 121 u64 macaddr; 122 u64 destports; 123 u64 enfport; 124 u64 index; 125 }; 126 127 struct sja1105_l2_lookup_params_entry { 128 u64 maxage; /* Shared */ 129 u64 dyn_tbsz; /* E/T only */ 130 u64 poly; /* E/T only */ 131 u64 shared_learn; /* Shared */ 132 u64 no_enf_hostprt; /* Shared */ 133 u64 no_mgmt_learn; /* Shared */ 134 }; 135 136 struct sja1105_l2_forwarding_entry { 137 u64 bc_domain; 138 u64 reach_port; 139 u64 fl_domain; 140 u64 vlan_pmap[8]; 141 }; 142 143 struct sja1105_l2_forwarding_params_entry { 144 u64 max_dynp; 145 u64 part_spc[8]; 146 }; 147 148 struct sja1105_l2_policing_entry { 149 u64 sharindx; 150 u64 smax; 151 u64 rate; 152 u64 maxlen; 153 u64 partition; 154 }; 155 156 struct sja1105_mac_config_entry { 157 u64 top[8]; 158 u64 base[8]; 159 u64 enabled[8]; 160 u64 ifg; 161 u64 speed; 162 u64 tp_delin; 163 u64 tp_delout; 164 u64 maxage; 165 u64 vlanprio; 166 u64 vlanid; 167 u64 ing_mirr; 168 u64 egr_mirr; 169 u64 drpnona664; 170 u64 drpdtag; 171 u64 drpuntag; 172 u64 retag; 173 u64 dyn_learn; 174 u64 egress; 175 u64 ingress; 176 }; 177 178 struct sja1105_xmii_params_entry { 179 u64 phy_mac[5]; 180 u64 xmii_mode[5]; 181 }; 182 183 struct sja1105_table_header { 184 u64 block_id; 185 u64 len; 186 u64 crc; 187 }; 188 189 struct sja1105_table_ops { 190 size_t (*packing)(void *buf, void *entry_ptr, enum packing_op op); 191 size_t unpacked_entry_size; 192 size_t packed_entry_size; 193 size_t max_entry_count; 194 }; 195 196 struct sja1105_table { 197 const struct sja1105_table_ops *ops; 198 size_t entry_count; 199 void *entries; 200 }; 201 202 struct sja1105_static_config { 203 u64 device_id; 204 struct sja1105_table tables[BLK_IDX_MAX]; 205 }; 206 207 extern struct sja1105_table_ops sja1105e_table_ops[BLK_IDX_MAX]; 208 extern struct sja1105_table_ops sja1105t_table_ops[BLK_IDX_MAX]; 209 extern struct sja1105_table_ops sja1105p_table_ops[BLK_IDX_MAX]; 210 extern struct sja1105_table_ops sja1105q_table_ops[BLK_IDX_MAX]; 211 extern struct sja1105_table_ops sja1105r_table_ops[BLK_IDX_MAX]; 212 extern struct sja1105_table_ops sja1105s_table_ops[BLK_IDX_MAX]; 213 214 size_t sja1105_table_header_packing(void *buf, void *hdr, enum packing_op op); 215 void 216 sja1105_table_header_pack_with_crc(void *buf, struct sja1105_table_header *hdr); 217 size_t 218 sja1105_static_config_get_length(const struct sja1105_static_config *config); 219 220 typedef enum { 221 SJA1105_CONFIG_OK = 0, 222 SJA1105_MISSING_L2_POLICING_TABLE, 223 SJA1105_MISSING_L2_FORWARDING_TABLE, 224 SJA1105_MISSING_L2_FORWARDING_PARAMS_TABLE, 225 SJA1105_MISSING_GENERAL_PARAMS_TABLE, 226 SJA1105_MISSING_VLAN_TABLE, 227 SJA1105_MISSING_XMII_TABLE, 228 SJA1105_MISSING_MAC_TABLE, 229 SJA1105_OVERCOMMITTED_FRAME_MEMORY, 230 } sja1105_config_valid_t; 231 232 extern const char *sja1105_static_config_error_msg[]; 233 234 sja1105_config_valid_t 235 sja1105_static_config_check_valid(const struct sja1105_static_config *config); 236 void 237 sja1105_static_config_pack(void *buf, struct sja1105_static_config *config); 238 int sja1105_static_config_init(struct sja1105_static_config *config, 239 const struct sja1105_table_ops *static_ops, 240 u64 device_id); 241 void sja1105_static_config_free(struct sja1105_static_config *config); 242 243 int sja1105_table_delete_entry(struct sja1105_table *table, int i); 244 int sja1105_table_resize(struct sja1105_table *table, size_t new_count); 245 246 u32 sja1105_crc32(const void *buf, size_t len); 247 248 void sja1105_pack(void *buf, const u64 *val, int start, int end, size_t len); 249 void sja1105_unpack(const void *buf, u64 *val, int start, int end, size_t len); 250 void sja1105_packing(void *buf, u64 *val, int start, int end, 251 size_t len, enum packing_op op); 252 253 #endif 254