Lines Matching refs:linecard
33 struct devlink_linecard *linecard; in devlink_linecard_get_from_attrs() local
35 linecard = devlink_linecard_get_by_index(devlink, linecard_index); in devlink_linecard_get_from_attrs()
36 if (!linecard) in devlink_linecard_get_from_attrs()
38 return linecard; in devlink_linecard_get_from_attrs()
74 struct devlink_linecard *linecard, in devlink_nl_linecard_fill() argument
90 if (nla_put_u32(msg, DEVLINK_ATTR_LINECARD_INDEX, linecard->index)) in devlink_nl_linecard_fill()
92 if (nla_put_u8(msg, DEVLINK_ATTR_LINECARD_STATE, linecard->state)) in devlink_nl_linecard_fill()
94 if (linecard->type && in devlink_nl_linecard_fill()
95 nla_put_string(msg, DEVLINK_ATTR_LINECARD_TYPE, linecard->type)) in devlink_nl_linecard_fill()
98 if (linecard->types_count) { in devlink_nl_linecard_fill()
103 for (i = 0; i < linecard->types_count; i++) { in devlink_nl_linecard_fill()
104 linecard_type = &linecard->types[i]; in devlink_nl_linecard_fill()
114 if (linecard->nested_devlink && in devlink_nl_linecard_fill()
115 devlink_nl_put_nested_handle(msg, linecard->nested_devlink)) in devlink_nl_linecard_fill()
126 static void devlink_linecard_notify(struct devlink_linecard *linecard, in devlink_linecard_notify() argument
129 struct devlink *devlink = linecard->devlink; in devlink_linecard_notify()
143 err = devlink_nl_linecard_fill(msg, devlink, linecard, cmd, 0, 0, 0, in devlink_linecard_notify()
156 struct devlink_linecard *linecard; in devlink_linecards_notify_register() local
158 list_for_each_entry(linecard, &devlink->linecard_list, list) in devlink_linecards_notify_register()
159 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecards_notify_register()
164 struct devlink_linecard *linecard; in devlink_linecards_notify_unregister() local
166 list_for_each_entry_reverse(linecard, &devlink->linecard_list, list) in devlink_linecards_notify_unregister()
167 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); in devlink_linecards_notify_unregister()
173 struct devlink_linecard *linecard; in devlink_nl_linecard_get_doit() local
177 linecard = devlink_linecard_get_from_info(devlink, info); in devlink_nl_linecard_get_doit()
178 if (IS_ERR(linecard)) in devlink_nl_linecard_get_doit()
179 return PTR_ERR(linecard); in devlink_nl_linecard_get_doit()
185 mutex_lock(&linecard->state_lock); in devlink_nl_linecard_get_doit()
186 err = devlink_nl_linecard_fill(msg, devlink, linecard, in devlink_nl_linecard_get_doit()
190 mutex_unlock(&linecard->state_lock); in devlink_nl_linecard_get_doit()
205 struct devlink_linecard *linecard; in devlink_nl_linecard_get_dump_one() local
209 list_for_each_entry(linecard, &devlink->linecard_list, list) { in devlink_nl_linecard_get_dump_one()
214 mutex_lock(&linecard->state_lock); in devlink_nl_linecard_get_dump_one()
215 err = devlink_nl_linecard_fill(msg, devlink, linecard, in devlink_nl_linecard_get_dump_one()
220 mutex_unlock(&linecard->state_lock); in devlink_nl_linecard_get_dump_one()
238 devlink_linecard_type_lookup(struct devlink_linecard *linecard, in devlink_linecard_type_lookup() argument
244 for (i = 0; i < linecard->types_count; i++) { in devlink_linecard_type_lookup()
245 linecard_type = &linecard->types[i]; in devlink_linecard_type_lookup()
252 static int devlink_linecard_type_set(struct devlink_linecard *linecard, in devlink_linecard_type_set() argument
256 const struct devlink_linecard_ops *ops = linecard->ops; in devlink_linecard_type_set()
260 mutex_lock(&linecard->state_lock); in devlink_linecard_type_set()
261 if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { in devlink_linecard_type_set()
266 if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { in devlink_linecard_type_set()
272 linecard_type = devlink_linecard_type_lookup(linecard, type); in devlink_linecard_type_set()
279 if (linecard->state != DEVLINK_LINECARD_STATE_UNPROVISIONED && in devlink_linecard_type_set()
280 linecard->state != DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) { in devlink_linecard_type_set()
288 ops->same_provision(linecard, linecard->priv, in devlink_linecard_type_set()
295 linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING; in devlink_linecard_type_set()
296 linecard->type = linecard_type->type; in devlink_linecard_type_set()
297 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_type_set()
298 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_set()
299 err = ops->provision(linecard, linecard->priv, linecard_type->type, in devlink_linecard_type_set()
305 mutex_lock(&linecard->state_lock); in devlink_linecard_type_set()
306 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; in devlink_linecard_type_set()
307 linecard->type = NULL; in devlink_linecard_type_set()
308 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_type_set()
309 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_set()
314 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_set()
318 static int devlink_linecard_type_unset(struct devlink_linecard *linecard, in devlink_linecard_type_unset() argument
323 mutex_lock(&linecard->state_lock); in devlink_linecard_type_unset()
324 if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING) { in devlink_linecard_type_unset()
329 if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONING) { in devlink_linecard_type_unset()
334 if (linecard->state == DEVLINK_LINECARD_STATE_PROVISIONING_FAILED) { in devlink_linecard_type_unset()
335 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; in devlink_linecard_type_unset()
336 linecard->type = NULL; in devlink_linecard_type_unset()
337 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_type_unset()
342 if (linecard->state == DEVLINK_LINECARD_STATE_UNPROVISIONED) { in devlink_linecard_type_unset()
347 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONING; in devlink_linecard_type_unset()
348 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_type_unset()
349 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_unset()
350 err = linecard->ops->unprovision(linecard, linecard->priv, in devlink_linecard_type_unset()
356 mutex_lock(&linecard->state_lock); in devlink_linecard_type_unset()
357 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; in devlink_linecard_type_unset()
358 linecard->type = NULL; in devlink_linecard_type_unset()
359 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_type_unset()
360 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_unset()
365 mutex_unlock(&linecard->state_lock); in devlink_linecard_type_unset()
374 struct devlink_linecard *linecard; in devlink_nl_cmd_linecard_set_doit() local
377 linecard = devlink_linecard_get_from_info(devlink, info); in devlink_nl_cmd_linecard_set_doit()
378 if (IS_ERR(linecard)) in devlink_nl_cmd_linecard_set_doit()
379 return PTR_ERR(linecard); in devlink_nl_cmd_linecard_set_doit()
386 err = devlink_linecard_type_set(linecard, type, extack); in devlink_nl_cmd_linecard_set_doit()
390 err = devlink_linecard_type_unset(linecard, extack); in devlink_nl_cmd_linecard_set_doit()
399 static int devlink_linecard_types_init(struct devlink_linecard *linecard) in devlink_linecard_types_init() argument
405 count = linecard->ops->types_count(linecard, linecard->priv); in devlink_linecard_types_init()
406 linecard->types = kmalloc_array(count, sizeof(*linecard_type), in devlink_linecard_types_init()
408 if (!linecard->types) in devlink_linecard_types_init()
410 linecard->types_count = count; in devlink_linecard_types_init()
413 linecard_type = &linecard->types[i]; in devlink_linecard_types_init()
414 linecard->ops->types_get(linecard, linecard->priv, i, in devlink_linecard_types_init()
421 static void devlink_linecard_types_fini(struct devlink_linecard *linecard) in devlink_linecard_types_fini() argument
423 kfree(linecard->types); in devlink_linecard_types_fini()
443 struct devlink_linecard *linecard; in devl_linecard_create() local
453 linecard = kzalloc(sizeof(*linecard), GFP_KERNEL); in devl_linecard_create()
454 if (!linecard) in devl_linecard_create()
457 linecard->devlink = devlink; in devl_linecard_create()
458 linecard->index = linecard_index; in devl_linecard_create()
459 linecard->ops = ops; in devl_linecard_create()
460 linecard->priv = priv; in devl_linecard_create()
461 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; in devl_linecard_create()
462 mutex_init(&linecard->state_lock); in devl_linecard_create()
464 err = devlink_linecard_types_init(linecard); in devl_linecard_create()
466 mutex_destroy(&linecard->state_lock); in devl_linecard_create()
467 kfree(linecard); in devl_linecard_create()
471 list_add_tail(&linecard->list, &devlink->linecard_list); in devl_linecard_create()
472 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devl_linecard_create()
473 return linecard; in devl_linecard_create()
482 void devl_linecard_destroy(struct devlink_linecard *linecard) in devl_linecard_destroy() argument
484 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_DEL); in devl_linecard_destroy()
485 list_del(&linecard->list); in devl_linecard_destroy()
486 devlink_linecard_types_fini(linecard); in devl_linecard_destroy()
487 mutex_destroy(&linecard->state_lock); in devl_linecard_destroy()
488 kfree(linecard); in devl_linecard_destroy()
501 void devlink_linecard_provision_set(struct devlink_linecard *linecard, in devlink_linecard_provision_set() argument
504 mutex_lock(&linecard->state_lock); in devlink_linecard_provision_set()
505 WARN_ON(linecard->type && strcmp(linecard->type, type)); in devlink_linecard_provision_set()
506 linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; in devlink_linecard_provision_set()
507 linecard->type = type; in devlink_linecard_provision_set()
508 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_provision_set()
509 mutex_unlock(&linecard->state_lock); in devlink_linecard_provision_set()
521 void devlink_linecard_provision_clear(struct devlink_linecard *linecard) in devlink_linecard_provision_clear() argument
523 mutex_lock(&linecard->state_lock); in devlink_linecard_provision_clear()
524 WARN_ON(linecard->nested_devlink); in devlink_linecard_provision_clear()
525 linecard->state = DEVLINK_LINECARD_STATE_UNPROVISIONED; in devlink_linecard_provision_clear()
526 linecard->type = NULL; in devlink_linecard_provision_clear()
527 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_provision_clear()
528 mutex_unlock(&linecard->state_lock); in devlink_linecard_provision_clear()
540 void devlink_linecard_provision_fail(struct devlink_linecard *linecard) in devlink_linecard_provision_fail() argument
542 mutex_lock(&linecard->state_lock); in devlink_linecard_provision_fail()
543 WARN_ON(linecard->nested_devlink); in devlink_linecard_provision_fail()
544 linecard->state = DEVLINK_LINECARD_STATE_PROVISIONING_FAILED; in devlink_linecard_provision_fail()
545 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_provision_fail()
546 mutex_unlock(&linecard->state_lock); in devlink_linecard_provision_fail()
555 void devlink_linecard_activate(struct devlink_linecard *linecard) in devlink_linecard_activate() argument
557 mutex_lock(&linecard->state_lock); in devlink_linecard_activate()
558 WARN_ON(linecard->state != DEVLINK_LINECARD_STATE_PROVISIONED); in devlink_linecard_activate()
559 linecard->state = DEVLINK_LINECARD_STATE_ACTIVE; in devlink_linecard_activate()
560 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_activate()
561 mutex_unlock(&linecard->state_lock); in devlink_linecard_activate()
570 void devlink_linecard_deactivate(struct devlink_linecard *linecard) in devlink_linecard_deactivate() argument
572 mutex_lock(&linecard->state_lock); in devlink_linecard_deactivate()
573 switch (linecard->state) { in devlink_linecard_deactivate()
575 linecard->state = DEVLINK_LINECARD_STATE_PROVISIONED; in devlink_linecard_deactivate()
576 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_deactivate()
587 mutex_unlock(&linecard->state_lock); in devlink_linecard_deactivate()
598 void devlink_linecard_nested_dl_set(struct devlink_linecard *linecard, in devlink_linecard_nested_dl_set() argument
601 mutex_lock(&linecard->state_lock); in devlink_linecard_nested_dl_set()
602 linecard->nested_devlink = nested_devlink; in devlink_linecard_nested_dl_set()
603 devlink_linecard_notify(linecard, DEVLINK_CMD_LINECARD_NEW); in devlink_linecard_nested_dl_set()
604 mutex_unlock(&linecard->state_lock); in devlink_linecard_nested_dl_set()