📄 sec2_request.c
字号:
/**************************************************************************** * sec2_request.c - request/response handler **************************************************************************** * Copyright (c) 2003-2005 Freescale Semiconductor * All Rights Reserved. Proprietary and Confidential. * * NOTICE: The information contained in this file is proprietary * to Freescale Semiconductor, and is being made available to * Freescale's customers under strict license agreements. * Use or disclosure of this information is permissible only * under the terms of the existing license agreement. ***************************************************************************//* Revision History: * 1.0 Aug 24,2003 dgs - adapted from the final version of mpc18x * Jun 04,2004 sec - add completion cleanup for scatter pointers * 1.1.0 Nov 16,2004 sec - integrate linux changes from prior versions, eliminate * StartDescriptor() function * 1.1.1 Dec 16,2004 sec - remove lock variable, remove old diagnostics, add * minor optimizations * 1.2 Jan 27,2005 sec - add CHA details to error dump */#include <stdio.h>#include "drvlib/include/drv_comm.h"#include "Sec2Driver.h"#include "sec2_const.h"#include "sec2_algo.h"#include "Sec2Descriptors.h"#include "sec2_dpd_Table.h"#ifdef printf#undef printf#endif/**********************************计数值***********************************/static int drv_RequestAddInGlobalQueue(GENERIC_REQ *req, int callingTaskId, DPD_DETAILS_ENTRY *pDesc);static int sec2_processing_Intime(GENERIC_REQ * req, int callingTaskId, DPD_DETAILS_ENTRY *pDesc);extern int sec2_VerifyRequest(void *request, DPD_DETAILS_ENTRY *pDesc);extern DPD_DETAILS_ENTRY *sec2_GetRequestDescEntry(unsigned long opId);extern VOID drv_sec2_error_callback(DRV_SEC2_CONTEXT *ctx);extern VOID drv_sec2_callback(DRV_SEC2_CONTEXT *ctx);/********************************************************************************//* Function Name: drv_RequestAddInGlobalQueue *//* Purpose:将不能及时处理的申请加入到IPSEC 队列中 *//* 加入队列时需要重新匹配一下OpId */ /* Input: algoType - type of algo *//* req - the pointer of the IO request *//* callingTaskId - the task Id *//* Output: req - the pointer of the IO request buffer *//* Return: SEC2_Success if success, otherwise error code *//*将不能及时处理的申请加入到IPSEC 队列中*//*加入队列时需要重新匹配一下OpId*//********************************************************************************/static int drv_RequestAddInGlobalQueue(GENERIC_REQ *req, int callingTaskId, DPD_DETAILS_ENTRY *pDesc){ QUEUE_ENTRY *newEntry; if (sec2_QueueEntryDepth >= SEC2_HANDLE_QUEUE_DEPTH) return (SEC2_INSUFFICIENT_REQS); pgsec2_global_debug->pkt_in++; semTake (sec2_QueueSemId, WAIT_FOREVER); newEntry = sec2_ProcessQueueBottom; sec2_ProcessQueueBottom = sec2_ProcessQueueBottom->next; /* fill in the queue structure */ newEntry->pReq = req; newEntry->requestingTaskId = callingTaskId; newEntry->pDesc = pDesc; sec2_QueueEntryDepth++; semGive (sec2_QueueSemId); SEC2Dump(DBGTXT_SETRQ, ("Queueing Up->newEntry=0x%lx\n", (unsigned long)newEntry)); return SEC2_SUCCESS;}UINT32 sec2_queue_max = 0;/********************************************************************************//* Function Name: sec2_addfwdQueue *//* Purpose:将不能及时处理的申请加入到IPSEC 队列中 *//* 加入队列时需要重新匹配一下OpId */ /* Input: algoType - type of algo *//* req - the pointer of the IO request *//* callingTaskId - the task Id *//* Output: req - the pointer of the IO request buffer *//* Return: SEC2_Success if success, otherwise error code *//*将不能及时处理的申请加入到IPSEC 队列中*//*加入队列时需要重新匹配一下OpId*//********************************************************************************/unsigned long sec2_add_rx_queue_err_cnt = 0;unsigned long sec2_add_fwd_err_cnt = 0;int sec2_addfwdQueue(GENERIC_REQ *req, int callingTaskId){ SEC2_FWD_QUEUE *newEntry; newEntry = gpSec2_FwdQueueBottom; if(newEntry->used == SEC2_PKT_UNUSED_FLAG) { gpSec2_FwdQueueBottom = newEntry->next; /* fill in the queue structure */ newEntry->pReq = req; newEntry->requestingTaskId = callingTaskId; newEntry->used = SEC2_PKT_USED_FLAG; /*需要上送fwd*/ if(gpDrvSec2End->rxFwdFlag == 0) { if(fwdJobAdd ((FUNCPTR)sec2_complete_handle,0,0,0,0,0) != OK) { sec2_add_fwd_err_cnt++; /*直接返回有点问题,增加一个计数*/ return SEC2_ERROR; } else { gpDrvSec2End->rxFwdFlag = 1; return SEC2_SUCCESS; } } else { return SEC2_SUCCESS; } } if(gpDrvSec2End->rxFwdFlag == 0) { if (fwdJobAdd ((FUNCPTR)sec2_complete_handle,0,0,0,0,0) == OK) { logMsg("add fwd err 2\n",0,0,0,0,0,0); gpDrvSec2End->rxFwdFlag = 1; } } /*添加不到fwd队列,因为它已满,返回错误*/ sec2_add_rx_queue_err_cnt++; return SEC2_ERROR;}/********************************************************************************//* Function Name: sec2_processing_Intime *//* Purpose: To handle the IO request routine *//* Input: algoType - type of algo *//* req - the pointer of the IO request *//* callingTaskId - the task Id *//* Output: req - the pointer of the IO request buffer *//* Return: SEC2_Success if success, otherwise error code *//********************************************************************************/static int sec2_processing_Intime(GENERIC_REQ *req, int callingTaskId, DPD_DETAILS_ENTRY *pDesc){ register int freeChannel; int status = -1; BOOLEAN bAvailableCHA; /* check to see if the required CHA is available */ bAvailableCHA = FALSE; if (Sec2_CheckChas(req->opId) == SEC2_SUCCESS) { bAvailableCHA = TRUE; } IOLockChannelAssignment(); /*如果有空闲通道,并且CHA 可得*/ if (bAvailableCHA && sec2_FreeChannels > 0) { /* dynamic request, see if there are any free channels */ for (freeChannel=0;freeChannel<SEC2_NUM_CHANNELS;freeChannel++) { if (Sec2_ChannelAssignments[freeChannel].assignment == CHANNEL_FREE) { SEC2Dump(DBGTXT_SETRQ, ("Sec2_ProcessRequest(): free channel = %d\n", freeChannel)); /* only for debug */ pgsec2_global_debug->pkt_in++; pgsec2_channel_debug[freeChannel].channel_DynamicCnt++; /* reserve this free channel for this operation */ Sec2_ChannelAssignments[freeChannel].assignment = CHANNEL_DYNAMIC; Sec2_ChannelAssignments[freeChannel].ownerTaskId = callingTaskId; Sec2_ChannelAssignments[freeChannel].pReq = req; sec2_FreeChannels--; /* translate this request into DPD's */ status = sec2_RequestToDpd(req, freeChannel,pDesc); if (status != SEC2_SUCCESS) { status = sec2_CompleteRequest(freeChannel, status); continue; } /* write the address of the first DPD to the channel */ /* this starts the request */ *(sec2_ChannelNextDescriptorRegister[freeChannel]+1) = __vpa((unsigned long)(Sec2_ChannelAssignments[freeChannel].Dpds[0])); IOUnLockChannelAssignment(); /*处理过程的解锁*/ return status; } } } IOUnLockChannelAssignment(); /*处理过程的解锁*/ return status;}/********************************************************************************//* Function Name: Sec2_ProcessRequest *//* Purpose: To handle the IO request routine *//* Input: req - the pointer of the IO request *//* callingTaskId - the task Id *//* Output: req - the pointer of the IO request buffer *//* Return: SEC2_Success if success, otherwise error code *//********************************************************************************/int Sec2_ProcessRequest(GENERIC_REQ *req, int callingTaskId){ register DPD_DETAILS_ENTRY *pDesc; pDesc = sec2_GetRequestDescEntry (req->opId); if (pDesc == NULL) return SEC2_INVALID_OPERATION_ID; /* Validate the contents of the request */ if(SEC2_SUCCESS != sec2_VerifyRequest(req, pDesc)) return SEC2_ERROR; if(SEC2_SUCCESS != sec2_processing_Intime(req, callingTaskId, pDesc)) { if(SEC2_SUCCESS != drv_RequestAddInGlobalQueue(req, callingTaskId, pDesc)) return ERROR; } return SEC2_SUCCESS;} /* end of Sec2_ProcessRequest() *//********************************************************************************//* Function Name: Sec2_ProcessingComplete *//* Purpose: 中断处理结束后,向FWD队列中添加的任务 *//* Input: regsPtr - 保存芯片状态寄存器的结构 *//* currentReg - 中断中分配内存数组的一个参数 *//* Output: none *//* Return: SEC2_Success if success, otherwise error code *//********************************************************************************/void Sec2_ProcessingComplete(SEC2_DEVICE_REGS *regsPtr,UINT8 currentReg){ register int channel; register int cha; int status[SEC2_NUM_CHANNELS]; /* The status for the channel */ BOOLEAN bIsComplete[SEC2_NUM_CHANNELS]; /* Indicates that the channel is done */ SEC2_DEVICE_REGS *pRegs; /* register? */ pRegs = regsPtr; /* we sit here forever, waiting for register content messages from the ISR */ for (channel = 0; channel < SEC2_NUM_CHANNELS; channel++) { bIsComplete[channel] = FALSE; status[channel] = SEC2_SUCCESS; } /* deal with any channel done interrupts */ if ((pRegs->IntStatus[0] & ALL_CHANNEL_INT_DONE_MASK) != 0) /*20060920*/ /* found at least one channel done interrupt */ for (channel = 0; channel < SEC2_NUM_CHANNELS; channel++) if ((pRegs->IntStatus[0] & Sec2ChannelDoneInterruptMasks[channel]) != 0) /* found a channel done interrupt */ bIsComplete[channel] = TRUE; /* deal with any error interrupts 错误中断处理*/ if (((pRegs->IntStatus[0] & ALL_INT_ERRORS_MASK_LOW) != 0) || /*20060920*/ ((pRegs->IntStatus[1] & ALL_INT_ERRORS_MASK_HIGH) != 0)) { /* need to find the channel */ /* deal with CHA error interrupts */ for (cha=0; cha<NUM_CHAS; cha++) { if (cha < 4) channel = (pRegs->ChaAssignmentStatus[0] >> (cha * 8)) & 0xF; else channel = (pRegs->ChaAssignmentStatus[1] >> ((cha - 4) * 8)) & 0xF; if (channel > 0 && channel < (SEC2_NUM_CHANNELS+1) && (pRegs->IntStatus[0] & Sec2ChannelErrorInterruptMasks[channel-1]) != 0) { status[channel-1] = SEC2_CHA_ERROR; bIsComplete[channel-1] = TRUE; } } /* end for cha loop */ for (channel=0; channel<SEC2_NUM_CHANNELS; channel++) { if ((pRegs->IntStatus[0] & Sec2ChannelErrorInterruptMasks[channel]) != 0) { bIsComplete[channel] = TRUE; /* this was a channel error then */ /* return the error code with some sort of quasi-priority, since */ /* multiples could occur */ status[channel] = SEC2_UNKNOWN_ERROR; if ((pRegs->ChannelError[channel][1] & CHANNEL_CHA_ERROR) || (pRegs->ChannelError[channel][1] & CHANNEL_CHA_ASSIGN_ERROR)) status[channel] = SEC2_CHA_ERROR; if (pRegs->ChannelError[channel][1] & CHANNEL_UNRECOGNIZED_HEADER_ERROR) status[channel] = SEC2_INVALID_OPERATION_ID; if (pRegs->ChannelError[channel][1] & CHA_PARITY_SYSTEM_ERROR) status[channel] = SEC2_PARITY_SYSTEM_ERROR; if (pRegs->ChannelError[channel][1] & CHANNEL_NULL_FETCH_POINTER) status[channel] = SEC2_INCOMPLETE_POINTER;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -