11849Swollman/* SPDX-License-Identifier: BSD-3-Clause */
21849Swollman/* Copyright(c) 2007-2022 Intel Corporation */
31849Swollman
41849Swollman/**
51849Swollman ***************************************************************************
61849Swollman * @file lac_sym_partial.c   common partial packet functions
71849Swollman *
81849Swollman * @ingroup LacSym
91849Swollman *
101849Swollman ***************************************************************************/
111849Swollman
121849Swollman/*
131849Swollman*******************************************************************************
141849Swollman* Include public/global header files
151849Swollman*******************************************************************************
161849Swollman*/
171849Swollman#include "cpa.h"
181849Swollman
191849Swollman#include "icp_accel_devices.h"
201849Swollman#include "icp_adf_debug.h"
211849Swollman
221849Swollman#include "lac_log.h"
231849Swollman#include "lac_sym.h"
241849Swollman#include "cpa_cy_sym.h"
251849Swollman#include "lac_common.h"
261849Swollman
271849Swollman#include "lac_sym_partial.h"
281849Swollman
291849SwollmanCpaStatus
301849SwollmanLacSym_PartialPacketStateCheck(CpaCySymPacketType packetType,
311849Swollman			       CpaCySymPacketType partialState)
321849Swollman{
3392999Sobrien	CpaStatus status = CPA_STATUS_SUCCESS;
3492999Sobrien
3592999Sobrien	/* ASSUMPTION - partial requests on a given session must be issued
3692999Sobrien	 * sequentially to guarantee ordering
3792999Sobrien	 * (i.e. issuing partials on concurrent threads for a particular session
381849Swollman	 * just wouldn't work)
391849Swollman	 */
401849Swollman
411849Swollman	/* state is no partial - only a partial is allowed */
4215634Speter	if (((CPA_CY_SYM_PACKET_TYPE_FULL == partialState) &&
4315634Speter	     (CPA_CY_SYM_PACKET_TYPE_PARTIAL == packetType)) ||
441849Swollman
451849Swollman	    /* state is partial - only a partial or final partial is allowed */
4685160Sru	    ((CPA_CY_SYM_PACKET_TYPE_PARTIAL == partialState) &&
47217106Skib	     ((CPA_CY_SYM_PACKET_TYPE_PARTIAL == packetType) ||
48217106Skib	      (CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL == packetType)))) {
49		status = CPA_STATUS_SUCCESS;
50	} else /* invalid sequence */
51	{
52		LAC_INVALID_PARAM_LOG("invalid partial packet sequence");
53		status = CPA_STATUS_INVALID_PARAM;
54	}
55
56	return status;
57}
58
59void
60LacSym_PartialPacketStateUpdate(CpaCySymPacketType packetType,
61				CpaCySymPacketType *pPartialState)
62{
63	/* if previous packet was either a full or ended a partial stream,
64	 * update
65	 * state to partial to indicate a new partial stream was created */
66	if (CPA_CY_SYM_PACKET_TYPE_FULL == *pPartialState) {
67		*pPartialState = CPA_CY_SYM_PACKET_TYPE_PARTIAL;
68	} else {
69		/* if packet type is final - reset the partial state */
70		if (CPA_CY_SYM_PACKET_TYPE_LAST_PARTIAL == packetType) {
71			*pPartialState = CPA_CY_SYM_PACKET_TYPE_FULL;
72		}
73	}
74}
75