linux-stable/drivers/scsi/elx/libefc/efc_sm.c
James Smart 5aa09c4868 scsi: elx: libefc: Generic state machine framework
Start the population of the libefc library.

The library will contain common tasks usable by a target or initiator
driver. The library will also contain a FC discovery state machine
interface.

Creates the library directory and add definitions for the discovery state
machine interface.

Link: https://lore.kernel.org/r/20210601235512.20104-9-jsmart2021@gmail.com
Reviewed-by: Hannes Reinecke <hare@suse.de>
Reviewed-by: Daniel Wagner <dwagner@suse.de>
Co-developed-by: Ram Vegesna <ram.vegesna@broadcom.com>
Signed-off-by: Ram Vegesna <ram.vegesna@broadcom.com>
Signed-off-by: James Smart <jsmart2021@gmail.com>
Signed-off-by: Martin K. Petersen <martin.petersen@oracle.com>
2021-06-15 23:39:29 -04:00

54 lines
1.1 KiB
C

// SPDX-License-Identifier: GPL-2.0
/*
* Copyright (C) 2021 Broadcom. All Rights Reserved. The term
* “Broadcom” refers to Broadcom Inc. and/or its subsidiaries.
*/
/*
* Generic state machine framework.
*/
#include "efc.h"
#include "efc_sm.h"
/**
* efc_sm_post_event() - Post an event to a context.
*
* @ctx: State machine context
* @evt: Event to post
* @data: Event-specific data (if any)
*/
int
efc_sm_post_event(struct efc_sm_ctx *ctx,
enum efc_sm_event evt, void *data)
{
if (!ctx->current_state)
return -EIO;
ctx->current_state(ctx, evt, data);
return 0;
}
void
efc_sm_transition(struct efc_sm_ctx *ctx,
void (*state)(struct efc_sm_ctx *,
enum efc_sm_event, void *), void *data)
{
if (ctx->current_state == state) {
efc_sm_post_event(ctx, EFC_EVT_REENTER, data);
} else {
efc_sm_post_event(ctx, EFC_EVT_EXIT, data);
ctx->current_state = state;
efc_sm_post_event(ctx, EFC_EVT_ENTER, data);
}
}
static char *event_name[] = EFC_SM_EVENT_NAME;
const char *efc_sm_event_name(enum efc_sm_event evt)
{
if (evt > EFC_EVT_LAST)
return "unknown";
return event_name[evt];
}