2 * Copyright (c) 2017 Broadcom. All rights reserved.
3 * The term "Broadcom" refers to Broadcom Limited and/or its subsidiaries.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are met:
8 * 1. Redistributions of source code must retain the above copyright notice,
9 * this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright notice,
12 * this list of conditions and the following disclaimer in the documentation
13 * and/or other materials provided with the distribution.
15 * 3. Neither the name of the copyright holder nor the names of its contributors
16 * may be used to endorse or promote products derived from this software
17 * without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
20 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
23 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 * POSSIBILITY OF SUCH DAMAGE.
36 * Handles the domain object callback from the HW.
40 @defgroup domain_sm Domain State Machine: States
45 #include "ocs_fabric.h"
46 #include "ocs_device.h"
48 #define domain_sm_trace(domain) \
50 if (OCS_LOG_ENABLE_DOMAIN_SM_TRACE(domain->ocs)) \
51 ocs_log_info(domain->ocs, "[domain] %-20s %-20s\n", __func__, ocs_sm_event_name(evt)); \
54 #define domain_trace(domain, fmt, ...) \
56 if (OCS_LOG_ENABLE_DOMAIN_SM_TRACE(domain ? domain->ocs : NULL)) \
57 ocs_log_info(domain ? domain->ocs : NULL, fmt, ##__VA_ARGS__); \
60 #define domain_printf(domain, fmt, ...) \
62 ocs_log_info(domain ? domain->ocs : NULL, fmt, ##__VA_ARGS__); \
65 void ocs_mgmt_domain_list(ocs_textbuf_t *textbuf, void *domain);
66 void ocs_mgmt_domain_get_all(ocs_textbuf_t *textbuf, void *domain);
67 int ocs_mgmt_domain_get(ocs_textbuf_t *textbuf, char *parent, char *name, void *domain);
68 int ocs_mgmt_domain_set(char *parent, char *name, char *value, void *domain);
69 int ocs_mgmt_domain_exec(char *parent, char *action, void *arg_in, uint32_t arg_in_length,
70 void *arg_out, uint32_t arg_out_length, void *domain);
72 static ocs_mgmt_functions_t domain_mgmt_functions = {
73 .get_list_handler = ocs_mgmt_domain_list,
74 .get_handler = ocs_mgmt_domain_get,
75 .get_all_handler = ocs_mgmt_domain_get_all,
76 .set_handler = ocs_mgmt_domain_set,
77 .exec_handler = ocs_mgmt_domain_exec,
81 * @brief Accept domain callback events from the HW.
83 * <h3 class="desc">Description</h3>
84 * HW calls this function with various domain-related events.
86 * @param arg Application-specified argument.
87 * @param event Domain event.
88 * @param data Event specific data.
90 * @return Returns 0 on success; or a negative error value on failure.
94 ocs_domain_cb(void *arg, ocs_hw_domain_event_e event, void *data)
97 ocs_domain_t *domain = NULL;
100 ocs_assert(data, -1);
102 if (event != OCS_HW_DOMAIN_FOUND) {
107 case OCS_HW_DOMAIN_FOUND: {
108 uint64_t fcf_wwn = 0;
109 ocs_domain_record_t *drec = data;
110 ocs_assert(drec, -1);
112 /* extract the fcf_wwn */
113 fcf_wwn = ocs_be64toh(*((uint64_t*)drec->wwn));
115 /* lookup domain, or allocate a new one if one doesn't exist already */
116 domain = ocs_domain_find(ocs, fcf_wwn);
117 if (domain == NULL) {
118 domain = ocs_domain_alloc(ocs, fcf_wwn);
119 if (domain == NULL) {
120 ocs_log_err(ocs, "ocs_domain_alloc() failed\n");
124 ocs_sm_transition(&domain->drvsm, __ocs_domain_init, NULL);
126 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_FOUND, drec);
130 case OCS_HW_DOMAIN_LOST:
131 domain_trace(domain, "OCS_HW_DOMAIN_LOST:\n");
132 ocs_domain_hold_frames(domain);
133 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_LOST, NULL);
136 case OCS_HW_DOMAIN_ALLOC_OK: {
137 domain_trace(domain, "OCS_HW_DOMAIN_ALLOC_OK:\n");
138 domain->instance_index = 0;
139 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_ALLOC_OK, NULL);
143 case OCS_HW_DOMAIN_ALLOC_FAIL:
144 domain_trace(domain, "OCS_HW_DOMAIN_ALLOC_FAIL:\n");
145 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_ALLOC_FAIL, NULL);
148 case OCS_HW_DOMAIN_ATTACH_OK:
149 domain_trace(domain, "OCS_HW_DOMAIN_ATTACH_OK:\n");
150 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_ATTACH_OK, NULL);
153 case OCS_HW_DOMAIN_ATTACH_FAIL:
154 domain_trace(domain, "OCS_HW_DOMAIN_ATTACH_FAIL:\n");
155 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_ATTACH_FAIL, NULL);
158 case OCS_HW_DOMAIN_FREE_OK:
159 domain_trace(domain, "OCS_HW_DOMAIN_FREE_OK:\n");
160 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_FREE_OK, NULL);
163 case OCS_HW_DOMAIN_FREE_FAIL:
164 domain_trace(domain, "OCS_HW_DOMAIN_FREE_FAIL:\n");
165 ocs_domain_post_event(domain, OCS_EVT_DOMAIN_FREE_FAIL, NULL);
169 ocs_log_warn(ocs, "unsupported event %#x\n", event);
176 * @brief Find the domain, given its FCF_WWN.
178 * <h3 class="desc">Description</h3>
179 * Search the domain_list to find a matching domain object.
181 * @param ocs Pointer to the OCS device.
182 * @param fcf_wwn FCF WWN to find.
184 * @return Returns the pointer to the domain if found; or NULL otherwise.
188 ocs_domain_find(ocs_t *ocs, uint64_t fcf_wwn)
190 ocs_domain_t *domain = NULL;
192 /* Check to see if this domain is already allocated */
193 ocs_device_lock(ocs);
194 ocs_list_foreach(&ocs->domain_list, domain) {
195 if (fcf_wwn == domain->fcf_wwn) {
199 ocs_device_unlock(ocs);
204 * @brief Allocate a domain object.
206 * <h3 class="desc">Description</h3>
207 * A domain object is allocated and initialized. It is associated with the
210 * @param ocs Pointer to the OCS device.
211 * @param fcf_wwn FCF WWN of the domain.
213 * @return Returns a pointer to the ocs_domain_t object; or NULL.
217 ocs_domain_alloc(ocs_t *ocs, uint64_t fcf_wwn)
219 ocs_domain_t *domain;
221 ocs_assert(ocs, NULL);
223 domain = ocs_malloc(ocs, sizeof(*domain), OCS_M_NOWAIT | OCS_M_ZERO);
226 domain->instance_index = ocs->domain_instance_count++;
227 domain->drvsm.app = domain;
228 ocs_domain_lock_init(domain);
229 ocs_lock_init(ocs, &domain->lookup_lock, "Domain lookup[%d]", domain->instance_index);
231 /* Allocate a sparse vector for sport FC_ID's */
232 domain->lookup = spv_new(ocs);
233 if (domain->lookup == NULL) {
234 ocs_log_err(ocs, "spv_new() failed\n");
235 ocs_free(ocs, domain, sizeof(*domain));
239 ocs_list_init(&domain->sport_list, ocs_sport_t, link);
240 domain->fcf_wwn = fcf_wwn;
241 ocs_log_debug(ocs, "Domain allocated: wwn %016" PRIX64 "\n", domain->fcf_wwn);
242 domain->femul_enable = (ocs->ctrlmask & OCS_CTRLMASK_ENABLE_FABRIC_EMULATION) != 0;
244 ocs_device_lock(ocs);
245 /* if this is the first domain, then assign it as the "root" domain */
246 if (ocs_list_empty(&ocs->domain_list)) {
247 ocs->domain = domain;
249 ocs_list_add_tail(&ocs->domain_list, domain);
250 ocs_device_unlock(ocs);
252 domain->mgmt_functions = &domain_mgmt_functions;
254 ocs_log_err(ocs, "domain allocation failed\n");
261 * @brief Free a domain object.
263 * <h3 class="desc">Description</h3>
264 * The domain object is freed.
266 * @param domain Domain object to free.
272 ocs_domain_free(ocs_domain_t *domain)
277 ocs_assert(domain->ocs);
279 /* Hold frames to clear the domain pointer from the xport lookup */
280 ocs_domain_hold_frames(domain);
284 ocs_log_debug(ocs, "Domain free: wwn %016" PRIX64 "\n", domain->fcf_wwn);
286 spv_del(domain->lookup);
287 domain->lookup = NULL;
289 ocs_device_lock(ocs);
290 ocs_list_remove(&ocs->domain_list, domain);
291 if (domain == ocs->domain) {
292 /* set global domain to the new head */
293 ocs->domain = ocs_list_get_head(&ocs->domain_list);
295 ocs_log_debug(ocs, "setting new domain, old=%p new=%p\n",
296 domain, ocs->domain);
300 if (ocs_list_empty(&ocs->domain_list) && ocs->domain_list_empty_cb ) {
301 (*ocs->domain_list_empty_cb)(ocs, ocs->domain_list_empty_cb_arg);
303 ocs_device_unlock(ocs);
305 ocs_lock_free(&domain->lookup_lock);
307 ocs_free(ocs, domain, sizeof(*domain));
311 * @brief Free memory resources of a domain object.
313 * <h3 class="desc">Description</h3>
314 * After the domain object is freed, its child objects are also freed.
316 * @param domain Pointer to a domain object.
322 ocs_domain_force_free(ocs_domain_t *domain)
327 /* Shutdown domain sm */
328 ocs_sm_disable(&domain->drvsm);
330 ocs_scsi_notify_domain_force_free(domain);
332 ocs_domain_lock(domain);
333 ocs_list_foreach_safe(&domain->sport_list, sport, next) {
334 ocs_sport_force_free(sport);
336 ocs_domain_unlock(domain);
337 ocs_hw_domain_force_free(&domain->ocs->hw, domain);
338 ocs_domain_free(domain);
342 * @brief Register a callback when the domain_list goes empty.
344 * <h3 class="desc">Description</h3>
345 * A function callback may be registered when the domain_list goes empty.
347 * @param ocs Pointer to a device object.
348 * @param callback Callback function.
349 * @param arg Callback argument.
355 ocs_register_domain_list_empty_cb(ocs_t *ocs, void (*callback)(ocs_t *ocs, void *arg), void *arg)
357 ocs_device_lock(ocs);
358 ocs->domain_list_empty_cb = callback;
359 ocs->domain_list_empty_cb_arg = arg;
360 if (ocs_list_empty(&ocs->domain_list) && callback) {
361 (*callback)(ocs, arg);
363 ocs_device_unlock(ocs);
367 * @brief Return a pointer to the domain, given the instance index.
369 * <h3 class="desc">Description</h3>
370 * A pointer to the domain context, given by the index, is returned.
372 * @param ocs Pointer to the driver instance context.
373 * @param index Instance index.
375 * @return Returns a pointer to the domain; or NULL.
379 ocs_domain_get_instance(ocs_t *ocs, uint32_t index)
381 ocs_domain_t *domain = NULL;
383 if (index >= OCS_MAX_DOMAINS) {
384 ocs_log_err(ocs, "invalid index: %d\n", index);
387 ocs_device_lock(ocs);
388 ocs_list_foreach(&ocs->domain_list, domain) {
389 if (domain->instance_index == index) {
393 ocs_device_unlock(ocs);
399 * @brief Domain state machine: Common event handler.
401 * <h3 class="desc">Description</h3>
402 * Common/shared events are handled here for the domain state machine.
404 * @param funcname Function name text.
405 * @param ctx Domain state machine context.
406 * @param evt Event to process.
407 * @param arg Per event optional argument.
409 * @return Returns NULL.
413 __ocs_domain_common(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
415 ocs_domain_t *domain = ctx->app;
419 case OCS_EVT_REENTER:
421 case OCS_EVT_ALL_CHILD_NODES_FREE:
422 /* this can arise if an FLOGI fails on the SPORT, and the SPORT is shutdown */
425 ocs_log_warn(domain->ocs, "%-20s %-20s not handled\n", funcname, ocs_sm_event_name(evt));
434 * @brief Domain state machine: Common shutdown.
436 * <h3 class="desc">Description</h3>
437 * Handles common shutdown events.
439 * @param funcname Function name text.
440 * @param ctx Remote node state machine context.
441 * @param evt Event to process.
442 * @param arg Per event optional argument.
444 * @return Returns NULL.
448 __ocs_domain_common_shutdown(const char *funcname, ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
450 ocs_domain_t *domain = ctx->app;
454 case OCS_EVT_REENTER:
457 case OCS_EVT_DOMAIN_FOUND:
458 ocs_assert(arg, NULL);
459 /* sm: / save drec, mark domain_found_pending */
460 ocs_memcpy(&domain->pending_drec, arg, sizeof(domain->pending_drec));
461 domain->domain_found_pending = TRUE;
463 case OCS_EVT_DOMAIN_LOST:
464 /* clear drec available
465 * sm: unmark domain_found_pending */
466 domain->domain_found_pending = FALSE;
470 ocs_log_warn(domain->ocs, "%-20s %-20s not handled\n", funcname, ocs_sm_event_name(evt));
477 #define std_domain_state_decl(...) \
478 ocs_domain_t *domain = NULL; \
481 ocs_assert(ctx, NULL); \
482 ocs_assert(ctx->app, NULL); \
484 ocs_assert(domain->ocs, NULL); \
486 ocs_assert(ocs->xport, NULL);
490 * @brief Domain state machine: Initial state.
492 * <h3 class="desc">Description</h3>
493 * The initial state for a domain. Each domain is initialized to
494 * this state at start of day (SOD).
496 * @param ctx Domain state machine context.
497 * @param evt Event to process.
498 * @param arg Per event optional argument.
500 * @return Returns NULL.
504 __ocs_domain_init(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
506 std_domain_state_decl();
508 domain_sm_trace(domain);
512 domain->attached = 0;
515 case OCS_EVT_DOMAIN_FOUND: {
518 ocs_domain_record_t *drec = arg;
521 uint64_t my_wwnn = ocs->xport->req_wwnn;
522 uint64_t my_wwpn = ocs->xport->req_wwpn;
525 /* For now, user must specify both port name and node name, or we let firmware
526 * pick both (same as for vports).
527 * TODO: do we want to allow setting only port name or only node name?
529 if ((my_wwpn == 0) || (my_wwnn == 0)) {
530 ocs_log_debug(ocs, "using default hardware WWN configuration \n");
531 my_wwpn = ocs_get_wwn(&ocs->hw, OCS_HW_WWN_PORT);
532 my_wwnn = ocs_get_wwn(&ocs->hw, OCS_HW_WWN_NODE);
535 ocs_log_debug(ocs, "Creating base sport using WWPN %016" PRIx64 " WWNN %016" PRIx64 "\n",
538 /* Allocate a sport and transition to __ocs_sport_allocated */
539 sport = ocs_sport_alloc(domain, my_wwpn, my_wwnn, UINT32_MAX, ocs->enable_ini, ocs->enable_tgt);
542 ocs_log_err(ocs, "ocs_sport_alloc() failed\n");
545 ocs_sm_transition(&sport->sm, __ocs_sport_allocated, NULL);
547 /* If domain is ethernet, then fetch the vlan id value */
548 if (drec->is_ethernet) {
549 vlan = ocs_bitmap_search((void *)drec->map.vlan, TRUE, 512 * 8);
551 ocs_log_err(ocs, "no VLAN id available (FCF=%d)\n",
557 be_wwpn = ocs_htobe64(sport->wwpn);
559 /* allocate ocs_sli_port_t object for local port
560 * Note: drec->fc_id is ALPA from read_topology only if loop
562 if (ocs_hw_port_alloc(&ocs->hw, sport, NULL, (uint8_t *)&be_wwpn)) {
563 ocs_log_err(ocs, "Can't allocate port\n");
564 ocs_sport_free(sport);
568 /* initialize domain object */
569 domain->is_loop = drec->is_loop;
570 domain->is_fc = drec->is_fc;
573 * If the loop position map includes ALPA == 0, then we are in a public loop (NL_PORT)
574 * Note that the first element of the loopmap[] contains the count of elements, and if
575 * ALPA == 0 is present, it will occupy the first location after the count.
577 domain->is_nlport = drec->map.loop[1] == 0x00;
579 if (domain->is_loop) {
580 ocs_log_debug(ocs, "%s fc_id=%#x speed=%d\n",
581 drec->is_loop ? (domain->is_nlport ? "public-loop" : "loop") : "other",
582 drec->fc_id, drec->speed);
584 sport->fc_id = drec->fc_id;
585 sport->topology = OCS_SPORT_TOPOLOGY_LOOP;
586 ocs_snprintf(sport->display_name, sizeof(sport->display_name), "s%06x", drec->fc_id);
588 if (ocs->enable_ini) {
589 uint32_t count = drec->map.loop[0];
590 ocs_log_debug(ocs, "%d position map entries\n", count);
591 for (i = 1; i <= count; i++) {
592 if (drec->map.loop[i] != drec->fc_id) {
595 ocs_log_debug(ocs, "%#x -> %#x\n",
596 drec->fc_id, drec->map.loop[i]);
597 node = ocs_node_alloc(sport, drec->map.loop[i], FALSE, TRUE);
599 ocs_log_err(ocs, "ocs_node_alloc() failed\n");
602 ocs_node_transition(node, __ocs_d_wait_loop, NULL);
608 /* Initiate HW domain alloc */
609 if (ocs_hw_domain_alloc(&ocs->hw, domain, drec->index, vlan)) {
610 ocs_log_err(ocs, "Failed to initiate HW domain allocation\n");
613 ocs_sm_transition(ctx, __ocs_domain_wait_alloc, arg);
617 __ocs_domain_common(__func__, ctx, evt, arg);
626 * @brief Domain state machine: Wait for the domain allocation to complete.
628 * <h3 class="desc">Description</h3>
629 * Waits for the domain state to be allocated. After the HW domain
630 * allocation process has been initiated, this state waits for
631 * that process to complete (i.e. a domain-alloc-ok event).
633 * @param ctx Domain state machine context.
634 * @param evt Event to process.
635 * @param arg Per event optional argument.
637 * @return Returns NULL.
641 __ocs_domain_wait_alloc(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
644 std_domain_state_decl();
646 domain_sm_trace(domain);
649 case OCS_EVT_DOMAIN_ALLOC_OK: {
651 uint64_t wwn_bump = 0;
652 fc_plogi_payload_t *sp;
654 if (ocs_get_property("wwn_bump", prop_buf, sizeof(prop_buf)) == 0) {
655 wwn_bump = ocs_strtoull(prop_buf, 0, 0);
658 sport = domain->sport;
659 ocs_assert(sport, NULL);
660 sp = (fc_plogi_payload_t*) sport->service_params;
662 /* Save the domain service parameters */
663 ocs_memcpy(domain->service_params + 4, domain->dma.virt, sizeof(fc_plogi_payload_t) - 4);
664 ocs_memcpy(sport->service_params + 4, domain->dma.virt, sizeof(fc_plogi_payload_t) - 4);
666 /* If we're in fabric emulation mode, the flogi service parameters have not been setup yet,
667 * so we need some reasonable BB credit value
669 if (domain->femul_enable) {
670 ocs_memcpy(domain->flogi_service_params + 4, domain->service_params + 4, sizeof(fc_plogi_payload_t) - 4);
673 /* Update the sport's service parameters, user might have specified non-default names */
674 sp->port_name_hi = ocs_htobe32((uint32_t) (sport->wwpn >> 32ll));
675 sp->port_name_lo = ocs_htobe32((uint32_t) sport->wwpn);
676 sp->node_name_hi = ocs_htobe32((uint32_t) (sport->wwnn >> 32ll));
677 sp->node_name_lo = ocs_htobe32((uint32_t) sport->wwnn);
680 sp->port_name_lo = ocs_htobe32(ocs_be32toh(sp->port_name_lo) ^ ((uint32_t)(wwn_bump)));
681 sp->port_name_hi = ocs_htobe32(ocs_be32toh(sp->port_name_hi) ^ ((uint32_t)(wwn_bump >> 32)));
682 sp->node_name_lo = ocs_htobe32(ocs_be32toh(sp->node_name_lo) ^ ((uint32_t)(wwn_bump)));
683 sp->node_name_hi = ocs_htobe32(ocs_be32toh(sp->node_name_hi) ^ ((uint32_t)(wwn_bump >> 32)));
684 ocs_log_info(ocs, "Overriding WWN\n");
687 /* Take the loop topology path, unless we are an NL_PORT (public loop) */
688 if (domain->is_loop && !domain->is_nlport) {
690 * For loop, we already have our FC ID and don't need fabric login.
691 * Transition to the allocated state and post an event to attach to
692 * the domain. Note that this breaks the normal action/transition
693 * pattern here to avoid a race with the domain attach callback.
695 /* sm: is_loop / domain_attach */
696 ocs_sm_transition(ctx, __ocs_domain_allocated, NULL);
697 __ocs_domain_attach_internal(domain, sport->fc_id);
702 /* alloc fabric node, send FLOGI */
703 node = ocs_node_find(sport, FC_ADDR_FABRIC);
705 ocs_log_err(ocs, "Hmmmm ... Fabric Controller node already exists\n");
708 node = ocs_node_alloc(sport, FC_ADDR_FABRIC, FALSE, FALSE);
710 ocs_log_err(ocs, "Error: ocs_node_alloc() failed\n");
712 if (ocs->nodedb_mask & OCS_NODEDB_PAUSE_FABRIC_LOGIN) {
713 ocs_node_pause(node, __ocs_fabric_init);
715 ocs_node_transition(node, __ocs_fabric_init, NULL);
719 domain->req_accept_frames = 1;
721 /* sm: start fabric logins */
722 ocs_sm_transition(ctx, __ocs_domain_allocated, NULL);
726 case OCS_EVT_DOMAIN_ALLOC_FAIL:
727 /* TODO: hw/device reset */
728 ocs_log_err(ocs, "%s recv'd waiting for DOMAIN_ALLOC_OK; shutting down domain\n",
729 ocs_sm_event_name(evt));
730 domain->req_domain_free = 1;
733 case OCS_EVT_DOMAIN_FOUND:
734 /* Should not happen */
735 ocs_assert(evt, NULL);
738 case OCS_EVT_DOMAIN_LOST:
739 ocs_log_debug(ocs, "%s received while waiting for ocs_hw_domain_alloc() to complete\n", ocs_sm_event_name(evt));
740 ocs_sm_transition(ctx, __ocs_domain_wait_domain_lost, NULL);
744 __ocs_domain_common(__func__, ctx, evt, arg);
753 * @brief Domain state machine: Wait for the domain attach request.
755 * <h3 class="desc">Description</h3>
756 * In this state, the domain has been allocated and is waiting for a domain attach request.
757 * The attach request comes from a node instance completing the fabric login,
758 * or from a point-to-point negotiation and login.
760 * @param ctx Remote node state machine context.
761 * @param evt Event to process.
762 * @param arg Per event optional argument.
764 * @return Returns NULL.
768 __ocs_domain_allocated(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
771 std_domain_state_decl();
773 domain_sm_trace(domain);
776 case OCS_EVT_DOMAIN_REQ_ATTACH: {
779 ocs_assert(arg, NULL);
781 fc_id = *((uint32_t*)arg);
782 ocs_log_debug(ocs, "Requesting hw domain attach fc_id x%x\n", fc_id);
783 /* Update sport lookup */
784 ocs_lock(&domain->lookup_lock);
785 spv_set(domain->lookup, fc_id, domain->sport);
786 ocs_unlock(&domain->lookup_lock);
788 /* Update display name for the sport */
789 ocs_node_fcid_display(fc_id, domain->sport->display_name, sizeof(domain->sport->display_name));
791 /* Issue domain attach call */
792 rc = ocs_hw_domain_attach(&ocs->hw, domain, fc_id);
794 ocs_log_err(ocs, "ocs_hw_domain_attach failed: %d\n", rc);
797 /* sm: / domain_attach */
798 ocs_sm_transition(ctx, __ocs_domain_wait_attach, NULL);
802 case OCS_EVT_DOMAIN_FOUND:
803 /* Should not happen */
804 ocs_assert(evt, NULL);
807 case OCS_EVT_DOMAIN_LOST: {
809 ocs_log_debug(ocs, "%s received while waiting for OCS_EVT_DOMAIN_REQ_ATTACH\n",
810 ocs_sm_event_name(evt));
811 ocs_domain_lock(domain);
812 if (!ocs_list_empty(&domain->sport_list)) {
813 /* if there are sports, transition to wait state and
814 * send shutdown to each sport */
815 ocs_sport_t *sport = NULL;
816 ocs_sport_t *sport_next = NULL;
817 ocs_sm_transition(ctx, __ocs_domain_wait_sports_free, NULL);
818 ocs_list_foreach_safe(&domain->sport_list, sport, sport_next) {
819 ocs_sm_post_event(&sport->sm, OCS_EVT_SHUTDOWN, NULL);
821 ocs_domain_unlock(domain);
823 ocs_domain_unlock(domain);
824 /* no sports exist, free domain */
825 ocs_sm_transition(ctx, __ocs_domain_wait_shutdown, NULL);
826 rc = ocs_hw_domain_free(&ocs->hw, domain);
828 ocs_log_err(ocs, "ocs_hw_domain_free() failed: %d\n", rc);
829 /* TODO: hw/device reset needed */
837 __ocs_domain_common(__func__, ctx, evt, arg);
846 * @brief Domain state machine: Wait for the HW domain attach to complete.
848 * <h3 class="desc">Description</h3>
849 * Waits for the HW domain attach to complete. Forwards attach ok event to the
850 * fabric node state machine.
852 * @param ctx Remote node state machine context.
853 * @param evt Event to process.
854 * @param arg Per event optional argument.
856 * @return Returns NULL.
860 __ocs_domain_wait_attach(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
862 std_domain_state_decl();
864 domain_sm_trace(domain);
867 case OCS_EVT_DOMAIN_ATTACH_OK: {
868 ocs_node_t *node = NULL;
869 ocs_node_t *next_node = NULL;
871 ocs_sport_t *next_sport;
873 /* Mark as attached */
874 domain->attached = 1;
876 /* Register with SCSI API */
878 ocs_scsi_tgt_new_domain(domain);
880 ocs_scsi_ini_new_domain(domain);
882 /* Transition to ready */
883 /* sm: / forward event to all sports and nodes */
884 ocs_sm_transition(ctx, __ocs_domain_ready, NULL);
886 /* We have an FCFI, so we can accept frames */
887 domain->req_accept_frames = 1;
888 /* Set domain notify pending state to avoid duplicate domain event post */
889 domain->domain_notify_pend = 1;
891 /* Notify all nodes that the domain attach request has completed
892 * Note: sport will have already received notification of sport attached
893 * as a result of the HW's port attach.
895 ocs_domain_lock(domain);
896 ocs_list_foreach_safe(&domain->sport_list, sport, next_sport) {
897 ocs_sport_lock(sport);
898 ocs_list_foreach_safe(&sport->node_list, node, next_node) {
899 ocs_node_post_event(node, OCS_EVT_DOMAIN_ATTACH_OK, NULL);
901 ocs_sport_unlock(sport);
903 ocs_domain_unlock(domain);
904 domain->domain_notify_pend = 0;
908 case OCS_EVT_DOMAIN_ATTACH_FAIL:
909 ocs_log_debug(ocs, "%s received while waiting for hw attach to complete\n", ocs_sm_event_name(evt));
910 /* TODO: hw/device reset */
913 case OCS_EVT_DOMAIN_FOUND:
914 /* Should not happen */
915 ocs_assert(evt, NULL);
918 case OCS_EVT_DOMAIN_LOST:
919 /* Domain lost while waiting for an attach to complete, go to a state that waits for
920 * the domain attach to complete, then handle domain lost
922 ocs_sm_transition(ctx, __ocs_domain_wait_domain_lost, NULL);
925 case OCS_EVT_DOMAIN_REQ_ATTACH:
926 /* In P2P we can get an attach request from the other FLOGI path, so drop this one */
930 __ocs_domain_common(__func__, ctx, evt, arg);
939 * @brief Domain state machine: Ready state.
941 * <h3 class="desc">Description</h3>
942 * This is a domain ready state. It waits for a domain-lost event, and initiates shutdown.
944 * @param ctx Remote node state machine context.
945 * @param evt Event to process.
946 * @param arg Per event optional argument.
948 * @return Returns NULL.
952 __ocs_domain_ready(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
954 std_domain_state_decl();
956 domain_sm_trace(domain);
959 case OCS_EVT_ENTER: {
960 /* start any pending vports */
961 if (ocs_vport_start(domain)) {
962 ocs_log_debug(domain->ocs, "ocs_vport_start() did not start all vports\n");
966 case OCS_EVT_DOMAIN_LOST: {
968 ocs_domain_lock(domain);
969 if (!ocs_list_empty(&domain->sport_list)) {
970 /* if there are sports, transition to wait state and send
971 * shutdown to each sport */
972 ocs_sport_t *sport = NULL;
973 ocs_sport_t *sport_next = NULL;
974 ocs_sm_transition(ctx, __ocs_domain_wait_sports_free, NULL);
975 ocs_list_foreach_safe(&domain->sport_list, sport, sport_next) {
976 ocs_sm_post_event(&sport->sm, OCS_EVT_SHUTDOWN, NULL);
978 ocs_domain_unlock(domain);
980 ocs_domain_unlock(domain);
981 /* no sports exist, free domain */
982 ocs_sm_transition(ctx, __ocs_domain_wait_shutdown, NULL);
983 rc = ocs_hw_domain_free(&ocs->hw, domain);
985 ocs_log_err(ocs, "ocs_hw_domain_free() failed: %d\n", rc);
986 /* TODO: hw/device reset needed */
992 case OCS_EVT_DOMAIN_FOUND:
993 /* Should not happen */
994 ocs_assert(evt, NULL);
997 case OCS_EVT_DOMAIN_REQ_ATTACH: {
998 /* can happen during p2p */
1001 ocs_assert(arg, NULL);
1002 fc_id = *((uint32_t*)arg);
1004 /* Assume that the domain is attached */
1005 ocs_assert(domain->attached, NULL);
1007 /* Verify that the requested FC_ID is the same as the one we're working with */
1008 ocs_assert(domain->sport->fc_id == fc_id, NULL);
1013 __ocs_domain_common(__func__, ctx, evt, arg);
1021 * @ingroup domain_sm
1022 * @brief Domain state machine: Wait for nodes to free prior to the domain shutdown.
1024 * <h3 class="desc">Description</h3>
1025 * All nodes are freed, and ready for a domain shutdown.
1027 * @param ctx Remote node sm context.
1028 * @param evt Event to process.
1029 * @param arg Per event optional argument.
1031 * @return Returns NULL.
1035 __ocs_domain_wait_sports_free(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
1037 std_domain_state_decl();
1039 domain_sm_trace(domain);
1042 case OCS_EVT_ALL_CHILD_NODES_FREE: {
1045 /* sm: ocs_hw_domain_free */
1046 ocs_sm_transition(ctx, __ocs_domain_wait_shutdown, NULL);
1048 /* Request ocs_hw_domain_free and wait for completion */
1049 rc = ocs_hw_domain_free(&ocs->hw, domain);
1051 ocs_log_err(ocs, "ocs_hw_domain_free() failed: %d\n", rc);
1056 __ocs_domain_common_shutdown(__func__, ctx, evt, arg);
1064 * @ingroup domain_sm
1065 * @brief Domain state machine: Complete the domain shutdown.
1067 * <h3 class="desc">Description</h3>
1068 * Waits for a HW domain free to complete.
1070 * @param ctx Remote node state machine context.
1071 * @param evt Event to process.
1072 * @param arg Per event optional argument.
1074 * @return Returns NULL.
1078 __ocs_domain_wait_shutdown(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
1080 std_domain_state_decl();
1082 domain_sm_trace(domain);
1085 case OCS_EVT_DOMAIN_FREE_OK: {
1086 if (ocs->enable_ini)
1087 ocs_scsi_ini_del_domain(domain);
1088 if (ocs->enable_tgt)
1089 ocs_scsi_tgt_del_domain(domain);
1091 /* sm: domain_free */
1092 if (domain->domain_found_pending) {
1093 /* save fcf_wwn and drec from this domain, free current domain and allocate
1094 * a new one with the same fcf_wwn
1095 * TODO: could use a SLI-4 "re-register VPI" operation here
1097 uint64_t fcf_wwn = domain->fcf_wwn;
1098 ocs_domain_record_t drec = domain->pending_drec;
1100 ocs_log_debug(ocs, "Reallocating domain\n");
1101 domain->req_domain_free = 1;
1102 domain = ocs_domain_alloc(ocs, fcf_wwn);
1104 if (domain == NULL) {
1105 ocs_log_err(ocs, "ocs_domain_alloc() failed\n");
1106 /* TODO: hw/device reset needed */
1110 * got a new domain; at this point, there are at least two domains
1111 * once the req_domain_free flag is processed, the associated domain
1114 ocs_sm_transition(&domain->drvsm, __ocs_domain_init, NULL);
1115 ocs_sm_post_event(&domain->drvsm, OCS_EVT_DOMAIN_FOUND, &drec);
1117 domain->req_domain_free = 1;
1123 __ocs_domain_common_shutdown(__func__, ctx, evt, arg);
1131 * @ingroup domain_sm
1132 * @brief Domain state machine: Wait for the domain alloc/attach completion
1133 * after receiving a domain lost.
1135 * <h3 class="desc">Description</h3>
1136 * This state is entered when receiving a domain lost while waiting for a domain alloc
1137 * or a domain attach to complete.
1139 * @param ctx Remote node state machine context.
1140 * @param evt Event to process.
1141 * @param arg Per event optional argument.
1143 * @return Returns NULL.
1147 __ocs_domain_wait_domain_lost(ocs_sm_ctx_t *ctx, ocs_sm_event_t evt, void *arg)
1149 std_domain_state_decl();
1151 domain_sm_trace(domain);
1154 case OCS_EVT_DOMAIN_ALLOC_OK:
1155 case OCS_EVT_DOMAIN_ATTACH_OK: {
1157 ocs_domain_lock(domain);
1158 if (!ocs_list_empty(&domain->sport_list)) {
1159 /* if there are sports, transition to wait state and send
1160 * shutdown to each sport */
1161 ocs_sport_t *sport = NULL;
1162 ocs_sport_t *sport_next = NULL;
1163 ocs_sm_transition(ctx, __ocs_domain_wait_sports_free, NULL);
1164 ocs_list_foreach_safe(&domain->sport_list, sport, sport_next) {
1165 ocs_sm_post_event(&sport->sm, OCS_EVT_SHUTDOWN, NULL);
1167 ocs_domain_unlock(domain);
1169 ocs_domain_unlock(domain);
1170 /* no sports exist, free domain */
1171 ocs_sm_transition(ctx, __ocs_domain_wait_shutdown, NULL);
1172 rc = ocs_hw_domain_free(&ocs->hw, domain);
1174 ocs_log_err(ocs, "ocs_hw_domain_free() failed: %d\n", rc);
1175 /* TODO: hw/device reset needed */
1180 case OCS_EVT_DOMAIN_ALLOC_FAIL:
1181 case OCS_EVT_DOMAIN_ATTACH_FAIL:
1182 ocs_log_err(ocs, "[domain] %-20s: failed\n", ocs_sm_event_name(evt));
1183 /* TODO: hw/device reset needed */
1187 __ocs_domain_common_shutdown(__func__, ctx, evt, arg);
1195 * @brief Save the port's service parameters.
1197 * <h3 class="desc">Description</h3>
1198 * Service parameters from the fabric FLOGI are saved in the domain's
1199 * flogi_service_params array.
1201 * @param domain Pointer to the domain.
1202 * @param payload Service parameters to save.
1208 ocs_domain_save_sparms(ocs_domain_t *domain, void *payload)
1210 ocs_memcpy(domain->flogi_service_params, payload, sizeof (fc_plogi_payload_t));
1213 * @brief Initiator domain attach. (internal call only)
1215 * Assumes that the domain SM lock is already locked
1217 * <h3 class="desc">Description</h3>
1218 * The HW domain attach function is started.
1220 * @param domain Pointer to the domain object.
1221 * @param s_id FC_ID of which to register this domain.
1227 __ocs_domain_attach_internal(ocs_domain_t *domain, uint32_t s_id)
1229 ocs_memcpy(domain->dma.virt, ((uint8_t*)domain->flogi_service_params)+4, sizeof (fc_plogi_payload_t) - 4);
1230 (void)ocs_sm_post_event(&domain->drvsm, OCS_EVT_DOMAIN_REQ_ATTACH, &s_id);
1234 * @brief Initiator domain attach.
1236 * <h3 class="desc">Description</h3>
1237 * The HW domain attach function is started.
1239 * @param domain Pointer to the domain object.
1240 * @param s_id FC_ID of which to register this domain.
1246 ocs_domain_attach(ocs_domain_t *domain, uint32_t s_id)
1248 __ocs_domain_attach_internal(domain, s_id);
1252 ocs_domain_post_event(ocs_domain_t *domain, ocs_sm_event_t event, void *arg)
1256 int req_domain_free;
1258 rc = ocs_sm_post_event(&domain->drvsm, event, arg);
1260 req_domain_free = domain->req_domain_free;
1261 domain->req_domain_free = 0;
1263 accept_frames = domain->req_accept_frames;
1264 domain->req_accept_frames = 0;
1266 if (accept_frames) {
1267 ocs_domain_accept_frames(domain);
1270 if (req_domain_free) {
1271 ocs_domain_free(domain);
1278 * @brief Return the WWN as a uint64_t.
1280 * <h3 class="desc">Description</h3>
1281 * Calls the HW property function for the WWNN or WWPN, and returns the value
1284 * @param hw Pointer to the HW object.
1285 * @param prop HW property.
1287 * @return Returns uint64_t request value.
1291 ocs_get_wwn(ocs_hw_t *hw, ocs_hw_property_e prop)
1293 uint8_t *p = ocs_hw_get_ptr(hw, prop);
1298 for (i = 0; i < sizeof(value); i++) {
1299 value = (value << 8) | p[i];
1306 * @brief Generate a domain ddump.
1308 * <h3 class="desc">Description</h3>
1309 * Generates a domain ddump.
1311 * @param textbuf Pointer to the text buffer.
1312 * @param domain Pointer to the domain context.
1314 * @return Returns 0 on success, or a negative value on failure.
1318 ocs_ddump_domain(ocs_textbuf_t *textbuf, ocs_domain_t *domain)
1323 ocs_ddump_section(textbuf, "domain", domain->instance_index);
1324 ocs_ddump_value(textbuf, "display_name", "%s", domain->display_name);
1326 ocs_ddump_value(textbuf, "fcf", "%#x", domain->fcf);
1327 ocs_ddump_value(textbuf, "fcf_indicator", "%#x", domain->fcf_indicator);
1328 ocs_ddump_value(textbuf, "vlan_id", "%#x", domain->vlan_id);
1329 ocs_ddump_value(textbuf, "indicator", "%#x", domain->indicator);
1330 ocs_ddump_value(textbuf, "attached", "%d", domain->attached);
1331 ocs_ddump_value(textbuf, "is_loop", "%d", domain->is_loop);
1332 ocs_ddump_value(textbuf, "is_nlport", "%d", domain->is_nlport);
1334 ocs_scsi_ini_ddump(textbuf, OCS_SCSI_DDUMP_DOMAIN, domain);
1335 ocs_scsi_tgt_ddump(textbuf, OCS_SCSI_DDUMP_DOMAIN, domain);
1337 ocs_display_sparams(NULL, "domain_sparms", 1, textbuf, domain->dma.virt);
1339 if (ocs_domain_lock_try(domain) != TRUE) {
1340 /* Didn't get the lock */
1343 ocs_list_foreach(&domain->sport_list, sport) {
1344 retval = ocs_ddump_sport(textbuf, sport);
1350 #if defined(ENABLE_FABRIC_EMULATION)
1351 ocs_ddump_ns(textbuf, domain->ocs_ns);
1354 ocs_domain_unlock(domain);
1356 ocs_ddump_endsection(textbuf, "domain", domain->instance_index);
1362 ocs_mgmt_domain_list(ocs_textbuf_t *textbuf, void *object)
1365 ocs_domain_t *domain = (ocs_domain_t *)object;
1367 ocs_mgmt_start_section(textbuf, "domain", domain->instance_index);
1369 /* Add my status values to textbuf */
1370 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "fcf");
1371 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "fcf_indicator");
1372 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "vlan_id");
1373 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "indicator");
1374 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "attached");
1375 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "is_loop");
1376 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "display_name");
1377 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RD, "num_sports");
1378 #if defined(ENABLE_FABRIC_EMULATION)
1379 ocs_mgmt_emit_property_name(textbuf, MGMT_MODE_RW, "femul_enable");
1382 if (ocs_domain_lock_try(domain) == TRUE) {
1383 /* If we get here, then we are holding the domain lock */
1384 ocs_list_foreach(&domain->sport_list, sport) {
1385 if ((sport->mgmt_functions) && (sport->mgmt_functions->get_list_handler)) {
1386 sport->mgmt_functions->get_list_handler(textbuf, sport);
1389 ocs_domain_unlock(domain);
1392 ocs_mgmt_end_section(textbuf, "domain", domain->instance_index);
1396 ocs_mgmt_domain_get(ocs_textbuf_t *textbuf, char *parent, char *name, void *object)
1399 ocs_domain_t *domain = (ocs_domain_t *)object;
1403 ocs_mgmt_start_section(textbuf, "domain", domain->instance_index);
1405 snprintf(qualifier, sizeof(qualifier), "%s/domain[%d]", parent, domain->instance_index);
1407 /* If it doesn't start with my qualifier I don't know what to do with it */
1408 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
1409 char *unqualified_name = name + strlen(qualifier) +1;
1411 /* See if it's a value I can supply */
1412 if (ocs_strcmp(unqualified_name, "display_name") == 0) {
1413 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "display_name", domain->display_name);
1415 } else if (ocs_strcmp(unqualified_name, "fcf") == 0) {
1416 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fcf", "%#x", domain->fcf);
1418 } else if (ocs_strcmp(unqualified_name, "fcf_indicator") == 0) {
1419 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fcf_indicator", "%#x", domain->fcf_indicator);
1421 } else if (ocs_strcmp(unqualified_name, "vlan_id") == 0) {
1422 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "vlan_id", "%#x", domain->vlan_id);
1424 } else if (ocs_strcmp(unqualified_name, "indicator") == 0) {
1425 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "indicator", "%#x", domain->indicator);
1427 } else if (ocs_strcmp(unqualified_name, "attached") == 0) {
1428 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "attached", domain->attached);
1430 } else if (ocs_strcmp(unqualified_name, "is_loop") == 0) {
1431 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "is_loop", domain->is_loop);
1433 } else if (ocs_strcmp(unqualified_name, "is_nlport") == 0) {
1434 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "is_nlport", domain->is_nlport);
1436 } else if (ocs_strcmp(unqualified_name, "display_name") == 0) {
1437 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "display_name", domain->display_name);
1439 #if defined(ENABLE_FABRIC_EMULATION)
1440 } else if (ocs_strcmp(unqualified_name, "femul_enable") == 0) {
1441 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "femul_enable", "%d", domain->femul_enable);
1444 } else if (ocs_strcmp(unqualified_name, "num_sports") == 0) {
1445 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "num_sports", "%d", domain->sport_instance_count);
1448 /* If I didn't know the value of this status pass the request to each of my children */
1450 ocs_domain_lock(domain);
1451 ocs_list_foreach(&domain->sport_list, sport) {
1452 if ((sport->mgmt_functions) && (sport->mgmt_functions->get_handler)) {
1453 retval = sport->mgmt_functions->get_handler(textbuf, qualifier, name, sport);
1460 ocs_domain_unlock(domain);
1464 ocs_mgmt_end_section(textbuf, "domain", domain->instance_index);
1469 ocs_mgmt_domain_get_all(ocs_textbuf_t *textbuf, void *object)
1472 ocs_domain_t *domain = (ocs_domain_t *)object;
1474 ocs_mgmt_start_section(textbuf, "domain", domain->instance_index);
1476 ocs_mgmt_emit_string(textbuf, MGMT_MODE_RD, "display_name", domain->display_name);
1477 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fcf", "%#x", domain->fcf);
1478 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "fcf_indicator", "%#x", domain->fcf_indicator);
1479 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "vlan_id", "%#x", domain->vlan_id);
1480 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "indicator", "%#x", domain->indicator);
1481 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "attached", domain->attached);
1482 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "is_loop", domain->is_loop);
1483 ocs_mgmt_emit_boolean(textbuf, MGMT_MODE_RD, "is_nlport", domain->is_nlport);
1484 #if defined(ENABLE_FABRIC_EMULATION)
1485 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RW, "femul_enable", "%d", domain->femul_enable);
1487 ocs_mgmt_emit_int(textbuf, MGMT_MODE_RD, "num_sports", "%d", domain->sport_instance_count);
1489 ocs_domain_lock(domain);
1490 ocs_list_foreach(&domain->sport_list, sport) {
1491 if ((sport->mgmt_functions) && (sport->mgmt_functions->get_all_handler)) {
1492 sport->mgmt_functions->get_all_handler(textbuf, sport);
1495 ocs_domain_unlock(domain);
1497 ocs_mgmt_end_unnumbered_section(textbuf, "domain");
1502 ocs_mgmt_domain_set(char *parent, char *name, char *value, void *object)
1505 ocs_domain_t *domain = (ocs_domain_t *)object;
1509 snprintf(qualifier, sizeof(qualifier), "%s/domain[%d]", parent, domain->instance_index);
1511 /* If it doesn't start with my qualifier I don't know what to do with it */
1512 if (ocs_strncmp(name, qualifier, strlen(qualifier)) == 0) {
1513 /* See if it's a value I can supply */
1515 /* if (ocs_strcmp(unqualified_name, "display_name") == 0) {
1518 /* If I didn't know the value of this status pass the request to each of my children */
1519 ocs_domain_lock(domain);
1520 ocs_list_foreach(&domain->sport_list, sport) {
1521 if ((sport->mgmt_functions) && (sport->mgmt_functions->set_handler)) {
1522 retval = sport->mgmt_functions->set_handler(qualifier, name, value, sport);
1529 ocs_domain_unlock(domain);
1537 ocs_mgmt_domain_exec(char *parent, char *action, void *arg_in, uint32_t arg_in_length,
1538 void *arg_out, uint32_t arg_out_length, void *object)
1541 ocs_domain_t *domain = (ocs_domain_t *)object;
1545 snprintf(qualifier, sizeof(qualifier), "%s.domain%d", parent, domain->instance_index);
1547 /* If it doesn't start with my qualifier I don't know what to do with it */
1548 if (ocs_strncmp(action, qualifier, strlen(qualifier)) == 0) {
1550 /* If I didn't know how to do this action pass the request to each of my children */
1551 ocs_domain_lock(domain);
1552 ocs_list_foreach(&domain->sport_list, sport) {
1553 if ((sport->mgmt_functions) && (sport->mgmt_functions->exec_handler)) {
1554 retval = sport->mgmt_functions->exec_handler(qualifier, action, arg_in, arg_in_length, arg_out, arg_out_length, sport);
1561 ocs_domain_unlock(domain);