1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright 2014-2016 Freescale Semiconductor Inc. 4 * Copyright 2017-2018 NXP 5 * 6 */ 7 8 #ifndef __FSL_DPSW_CMD_H 9 #define __FSL_DPSW_CMD_H 10 11 /* DPSW Version */ 12 #define DPSW_VER_MAJOR 8 13 #define DPSW_VER_MINOR 1 14 15 #define DPSW_CMD_BASE_VERSION 1 16 #define DPSW_CMD_ID_OFFSET 4 17 18 #define DPSW_CMD_ID(id) (((id) << DPSW_CMD_ID_OFFSET) | DPSW_CMD_BASE_VERSION) 19 20 /* Command IDs */ 21 #define DPSW_CMDID_CLOSE DPSW_CMD_ID(0x800) 22 #define DPSW_CMDID_OPEN DPSW_CMD_ID(0x802) 23 24 #define DPSW_CMDID_GET_API_VERSION DPSW_CMD_ID(0xa02) 25 26 #define DPSW_CMDID_ENABLE DPSW_CMD_ID(0x002) 27 #define DPSW_CMDID_DISABLE DPSW_CMD_ID(0x003) 28 #define DPSW_CMDID_GET_ATTR DPSW_CMD_ID(0x004) 29 #define DPSW_CMDID_RESET DPSW_CMD_ID(0x005) 30 31 #define DPSW_CMDID_SET_IRQ_ENABLE DPSW_CMD_ID(0x012) 32 33 #define DPSW_CMDID_SET_IRQ_MASK DPSW_CMD_ID(0x014) 34 35 #define DPSW_CMDID_GET_IRQ_STATUS DPSW_CMD_ID(0x016) 36 #define DPSW_CMDID_CLEAR_IRQ_STATUS DPSW_CMD_ID(0x017) 37 38 #define DPSW_CMDID_IF_SET_TCI DPSW_CMD_ID(0x030) 39 #define DPSW_CMDID_IF_SET_STP DPSW_CMD_ID(0x031) 40 41 #define DPSW_CMDID_IF_GET_COUNTER DPSW_CMD_ID(0x034) 42 43 #define DPSW_CMDID_IF_ENABLE DPSW_CMD_ID(0x03D) 44 #define DPSW_CMDID_IF_DISABLE DPSW_CMD_ID(0x03E) 45 46 #define DPSW_CMDID_IF_SET_MAX_FRAME_LENGTH DPSW_CMD_ID(0x044) 47 48 #define DPSW_CMDID_IF_GET_LINK_STATE DPSW_CMD_ID(0x046) 49 #define DPSW_CMDID_IF_SET_FLOODING DPSW_CMD_ID(0x047) 50 #define DPSW_CMDID_IF_SET_BROADCAST DPSW_CMD_ID(0x048) 51 52 #define DPSW_CMDID_IF_GET_TCI DPSW_CMD_ID(0x04A) 53 54 #define DPSW_CMDID_IF_SET_LINK_CFG DPSW_CMD_ID(0x04C) 55 56 #define DPSW_CMDID_VLAN_ADD DPSW_CMD_ID(0x060) 57 #define DPSW_CMDID_VLAN_ADD_IF DPSW_CMD_ID(0x061) 58 #define DPSW_CMDID_VLAN_ADD_IF_UNTAGGED DPSW_CMD_ID(0x062) 59 60 #define DPSW_CMDID_VLAN_REMOVE_IF DPSW_CMD_ID(0x064) 61 #define DPSW_CMDID_VLAN_REMOVE_IF_UNTAGGED DPSW_CMD_ID(0x065) 62 #define DPSW_CMDID_VLAN_REMOVE_IF_FLOODING DPSW_CMD_ID(0x066) 63 #define DPSW_CMDID_VLAN_REMOVE DPSW_CMD_ID(0x067) 64 65 #define DPSW_CMDID_FDB_ADD_UNICAST DPSW_CMD_ID(0x084) 66 #define DPSW_CMDID_FDB_REMOVE_UNICAST DPSW_CMD_ID(0x085) 67 #define DPSW_CMDID_FDB_ADD_MULTICAST DPSW_CMD_ID(0x086) 68 #define DPSW_CMDID_FDB_REMOVE_MULTICAST DPSW_CMD_ID(0x087) 69 #define DPSW_CMDID_FDB_SET_LEARNING_MODE DPSW_CMD_ID(0x088) 70 #define DPSW_CMDID_FDB_DUMP DPSW_CMD_ID(0x08A) 71 72 #define DPSW_CMDID_IF_GET_PORT_MAC_ADDR DPSW_CMD_ID(0x0A7) 73 #define DPSW_CMDID_IF_GET_PRIMARY_MAC_ADDR DPSW_CMD_ID(0x0A8) 74 #define DPSW_CMDID_IF_SET_PRIMARY_MAC_ADDR DPSW_CMD_ID(0x0A9) 75 76 /* Macros for accessing command fields smaller than 1byte */ 77 #define DPSW_MASK(field) \ 78 GENMASK(DPSW_##field##_SHIFT + DPSW_##field##_SIZE - 1, \ 79 DPSW_##field##_SHIFT) 80 #define dpsw_set_field(var, field, val) \ 81 ((var) |= (((val) << DPSW_##field##_SHIFT) & DPSW_MASK(field))) 82 #define dpsw_get_field(var, field) \ 83 (((var) & DPSW_MASK(field)) >> DPSW_##field##_SHIFT) 84 #define dpsw_get_bit(var, bit) \ 85 (((var) >> (bit)) & GENMASK(0, 0)) 86 87 struct dpsw_cmd_open { 88 __le32 dpsw_id; 89 }; 90 91 #define DPSW_COMPONENT_TYPE_SHIFT 0 92 #define DPSW_COMPONENT_TYPE_SIZE 4 93 94 struct dpsw_cmd_create { 95 /* cmd word 0 */ 96 __le16 num_ifs; 97 u8 max_fdbs; 98 u8 max_meters_per_if; 99 /* from LSB: only the first 4 bits */ 100 u8 component_type; 101 u8 pad[3]; 102 /* cmd word 1 */ 103 __le16 max_vlans; 104 __le16 max_fdb_entries; 105 __le16 fdb_aging_time; 106 __le16 max_fdb_mc_groups; 107 /* cmd word 2 */ 108 __le64 options; 109 }; 110 111 struct dpsw_cmd_destroy { 112 __le32 dpsw_id; 113 }; 114 115 #define DPSW_ENABLE_SHIFT 0 116 #define DPSW_ENABLE_SIZE 1 117 118 struct dpsw_rsp_is_enabled { 119 /* from LSB: enable:1 */ 120 u8 enabled; 121 }; 122 123 struct dpsw_cmd_set_irq_enable { 124 u8 enable_state; 125 u8 pad[3]; 126 u8 irq_index; 127 }; 128 129 struct dpsw_cmd_get_irq_enable { 130 __le32 pad; 131 u8 irq_index; 132 }; 133 134 struct dpsw_rsp_get_irq_enable { 135 u8 enable_state; 136 }; 137 138 struct dpsw_cmd_set_irq_mask { 139 __le32 mask; 140 u8 irq_index; 141 }; 142 143 struct dpsw_cmd_get_irq_mask { 144 __le32 pad; 145 u8 irq_index; 146 }; 147 148 struct dpsw_rsp_get_irq_mask { 149 __le32 mask; 150 }; 151 152 struct dpsw_cmd_get_irq_status { 153 __le32 status; 154 u8 irq_index; 155 }; 156 157 struct dpsw_rsp_get_irq_status { 158 __le32 status; 159 }; 160 161 struct dpsw_cmd_clear_irq_status { 162 __le32 status; 163 u8 irq_index; 164 }; 165 166 #define DPSW_COMPONENT_TYPE_SHIFT 0 167 #define DPSW_COMPONENT_TYPE_SIZE 4 168 169 struct dpsw_rsp_get_attr { 170 /* cmd word 0 */ 171 __le16 num_ifs; 172 u8 max_fdbs; 173 u8 num_fdbs; 174 __le16 max_vlans; 175 __le16 num_vlans; 176 /* cmd word 1 */ 177 __le16 max_fdb_entries; 178 __le16 fdb_aging_time; 179 __le32 dpsw_id; 180 /* cmd word 2 */ 181 __le16 mem_size; 182 __le16 max_fdb_mc_groups; 183 u8 max_meters_per_if; 184 /* from LSB only the first 4 bits */ 185 u8 component_type; 186 __le16 pad; 187 /* cmd word 3 */ 188 __le64 options; 189 }; 190 191 struct dpsw_cmd_if_set_flooding { 192 __le16 if_id; 193 /* from LSB: enable:1 */ 194 u8 enable; 195 }; 196 197 struct dpsw_cmd_if_set_broadcast { 198 __le16 if_id; 199 /* from LSB: enable:1 */ 200 u8 enable; 201 }; 202 203 #define DPSW_VLAN_ID_SHIFT 0 204 #define DPSW_VLAN_ID_SIZE 12 205 #define DPSW_DEI_SHIFT 12 206 #define DPSW_DEI_SIZE 1 207 #define DPSW_PCP_SHIFT 13 208 #define DPSW_PCP_SIZE 3 209 210 struct dpsw_cmd_if_set_tci { 211 __le16 if_id; 212 /* from LSB: VLAN_ID:12 DEI:1 PCP:3 */ 213 __le16 conf; 214 }; 215 216 struct dpsw_cmd_if_get_tci { 217 __le16 if_id; 218 }; 219 220 struct dpsw_rsp_if_get_tci { 221 __le16 pad; 222 __le16 vlan_id; 223 u8 dei; 224 u8 pcp; 225 }; 226 227 #define DPSW_STATE_SHIFT 0 228 #define DPSW_STATE_SIZE 4 229 230 struct dpsw_cmd_if_set_stp { 231 __le16 if_id; 232 __le16 vlan_id; 233 /* only the first LSB 4 bits */ 234 u8 state; 235 }; 236 237 #define DPSW_COUNTER_TYPE_SHIFT 0 238 #define DPSW_COUNTER_TYPE_SIZE 5 239 240 struct dpsw_cmd_if_get_counter { 241 __le16 if_id; 242 /* from LSB: type:5 */ 243 u8 type; 244 }; 245 246 struct dpsw_rsp_if_get_counter { 247 __le64 pad; 248 __le64 counter; 249 }; 250 251 struct dpsw_cmd_if { 252 __le16 if_id; 253 }; 254 255 struct dpsw_cmd_if_set_max_frame_length { 256 __le16 if_id; 257 __le16 frame_length; 258 }; 259 260 struct dpsw_cmd_if_set_link_cfg { 261 /* cmd word 0 */ 262 __le16 if_id; 263 u8 pad[6]; 264 /* cmd word 1 */ 265 __le32 rate; 266 __le32 pad1; 267 /* cmd word 2 */ 268 __le64 options; 269 }; 270 271 struct dpsw_cmd_if_get_link_state { 272 __le16 if_id; 273 }; 274 275 #define DPSW_UP_SHIFT 0 276 #define DPSW_UP_SIZE 1 277 278 struct dpsw_rsp_if_get_link_state { 279 /* cmd word 0 */ 280 __le32 pad0; 281 u8 up; 282 u8 pad1[3]; 283 /* cmd word 1 */ 284 __le32 rate; 285 __le32 pad2; 286 /* cmd word 2 */ 287 __le64 options; 288 }; 289 290 struct dpsw_vlan_add { 291 __le16 fdb_id; 292 __le16 vlan_id; 293 }; 294 295 struct dpsw_cmd_vlan_manage_if { 296 /* cmd word 0 */ 297 __le16 pad0; 298 __le16 vlan_id; 299 __le32 pad1; 300 /* cmd word 1-4 */ 301 __le64 if_id[4]; 302 }; 303 304 struct dpsw_cmd_vlan_remove { 305 __le16 pad; 306 __le16 vlan_id; 307 }; 308 309 struct dpsw_cmd_fdb_add { 310 __le32 pad; 311 __le16 fdb_aging_time; 312 __le16 num_fdb_entries; 313 }; 314 315 struct dpsw_rsp_fdb_add { 316 __le16 fdb_id; 317 }; 318 319 struct dpsw_cmd_fdb_remove { 320 __le16 fdb_id; 321 }; 322 323 #define DPSW_ENTRY_TYPE_SHIFT 0 324 #define DPSW_ENTRY_TYPE_SIZE 4 325 326 struct dpsw_cmd_fdb_unicast_op { 327 /* cmd word 0 */ 328 __le16 fdb_id; 329 u8 mac_addr[6]; 330 /* cmd word 1 */ 331 __le16 if_egress; 332 /* only the first 4 bits from LSB */ 333 u8 type; 334 }; 335 336 struct dpsw_cmd_fdb_multicast_op { 337 /* cmd word 0 */ 338 __le16 fdb_id; 339 __le16 num_ifs; 340 /* only the first 4 bits from LSB */ 341 u8 type; 342 u8 pad[3]; 343 /* cmd word 1 */ 344 u8 mac_addr[6]; 345 __le16 pad2; 346 /* cmd word 2-5 */ 347 __le64 if_id[4]; 348 }; 349 350 #define DPSW_LEARNING_MODE_SHIFT 0 351 #define DPSW_LEARNING_MODE_SIZE 4 352 353 struct dpsw_cmd_fdb_set_learning_mode { 354 __le16 fdb_id; 355 /* only the first 4 bits from LSB */ 356 u8 mode; 357 }; 358 359 struct dpsw_cmd_fdb_dump { 360 __le16 fdb_id; 361 __le16 pad0; 362 __le32 pad1; 363 __le64 iova_addr; 364 __le32 iova_size; 365 }; 366 367 struct dpsw_rsp_fdb_dump { 368 __le16 num_entries; 369 }; 370 371 struct dpsw_rsp_get_api_version { 372 __le16 version_major; 373 __le16 version_minor; 374 }; 375 376 struct dpsw_rsp_if_get_mac_addr { 377 __le16 pad; 378 u8 mac_addr[6]; 379 }; 380 381 struct dpsw_cmd_if_set_mac_addr { 382 __le16 if_id; 383 u8 mac_addr[6]; 384 }; 385 386 #endif /* __FSL_DPSW_CMD_H */ 387