| 198 | } |
| 199 | |
| 200 | int |
| 201 | sfc_mae_assign_switch_domain(struct sfc_adapter *sa, |
| 202 | uint16_t *switch_domain_id) |
| 203 | { |
| 204 | struct sfc_hw_switch_id *hw_switch_id; |
| 205 | struct sfc_mae_switch_domain *domain; |
| 206 | int rc; |
| 207 | |
| 208 | rte_spinlock_lock(&sfc_mae_switch.lock); |
| 209 | |
| 210 | rc = sfc_hw_switch_id_init(sa, &hw_switch_id); |
| 211 | if (rc != 0) |
| 212 | goto fail_hw_switch_id_init; |
| 213 | |
| 214 | domain = sfc_mae_find_switch_domain_by_hw_switch_id(hw_switch_id); |
| 215 | if (domain != NULL) { |
| 216 | sfc_hw_switch_id_fini(sa, hw_switch_id); |
| 217 | goto done; |
| 218 | } |
| 219 | |
| 220 | domain = rte_zmalloc("sfc_mae_switch_domain", sizeof(*domain), 0); |
| 221 | if (domain == NULL) { |
| 222 | rc = ENOMEM; |
| 223 | goto fail_mem_alloc; |
| 224 | } |
| 225 | |
| 226 | /* |
| 227 | * This code belongs to driver init path, that is, negation is |
| 228 | * done at the end of the path by sfc_eth_dev_init(). RTE APIs |
| 229 | * negate error codes, so drop negation here. |
| 230 | */ |
| 231 | rc = -rte_eth_switch_domain_alloc(&domain->id); |
| 232 | if (rc != 0) |
| 233 | goto fail_domain_alloc; |
| 234 | |
| 235 | domain->hw_switch_id = hw_switch_id; |
| 236 | |
| 237 | TAILQ_INIT(&domain->ports); |
| 238 | |
| 239 | TAILQ_INSERT_TAIL(&sfc_mae_switch.domains, domain, entries); |
| 240 | |
| 241 | done: |
| 242 | *switch_domain_id = domain->id; |
| 243 | |
| 244 | rte_spinlock_unlock(&sfc_mae_switch.lock); |
| 245 | |
| 246 | return 0; |
| 247 | |
| 248 | fail_domain_alloc: |
| 249 | rte_free(domain); |
| 250 | |
| 251 | fail_mem_alloc: |
| 252 | sfc_hw_switch_id_fini(sa, hw_switch_id); |
| 253 | |
| 254 | fail_hw_switch_id_init: |
| 255 | rte_spinlock_unlock(&sfc_mae_switch.lock); |
| 256 | return rc; |
| 257 | } |
no test coverage detected