xf.li | bfc6e71 | 2025-02-07 01:54:34 -0800 | [diff] [blame^] | 1 | /*******************************************************************************
|
| 2 | * Copyright (C) 2007, ZTE Corporation.
|
| 3 | *
|
| 4 | * File Name:io_request.h
|
| 5 | * File Mark:
|
| 6 | * Description:
|
| 7 | * Others:
|
| 8 | * Version: 1.0
|
| 9 | * Author: geanfeng
|
| 10 | * Date: 2013-09-25
|
| 11 | * History 1:
|
| 12 | * Date:
|
| 13 | * Version:
|
| 14 | * Author:
|
| 15 | * Modification:
|
| 16 | * History 2:
|
| 17 | ********************************************************************************/
|
| 18 |
|
| 19 | #ifndef _IO_REQUEST_H
|
| 20 | #define _IO_REQUEST_H
|
| 21 |
|
| 22 | /****************************************************************************
|
| 23 | * Include files
|
| 24 | ****************************************************************************/
|
| 25 | #include "drvs_list.h"
|
| 26 | #include "ring_queue.h"
|
| 27 | #include "request_queue.h"
|
| 28 | /****************************************************************************
|
| 29 | * Macros
|
| 30 | ****************************************************************************/
|
| 31 | /****************************************************************************
|
| 32 | * Types
|
| 33 | ****************************************************************************/
|
| 34 | typedef enum _T_DONE_STATE {
|
| 35 | REQUEST_SUCCESS = 0,
|
| 36 | REQUEST_NODEV,
|
| 37 | REQUEST_ERROR,
|
| 38 | }T_DONE_STATE;
|
| 39 |
|
| 40 | typedef enum _T_IO_HND_STATE
|
| 41 | {
|
| 42 | IO_REQUEST_UNCREATED = 0,
|
| 43 | IO_REQUEST_CREATED,
|
| 44 | IO_REQUEST_FORCE_EXIT,
|
| 45 | }
|
| 46 | T_IO_HND_STATE;
|
| 47 |
|
| 48 | typedef enum _T_IO_REQUEST_STATE
|
| 49 | {
|
| 50 | IO_REQUEST_STOP = 0,
|
| 51 | IO_REQUEST_START,
|
| 52 | IO_REQUEST_START_TO_SUSPEND,
|
| 53 | IO_REQUEST_STOP_TO_SUSPEND,
|
| 54 | }
|
| 55 | T_IO_REQUEST_STATE;
|
| 56 |
|
| 57 |
|
| 58 | typedef enum _T_IO_REQUEST_DIRECTION
|
| 59 | {
|
| 60 | IO_REQUEST_READ = 0,
|
| 61 | IO_REQUEST_WRITE,
|
| 62 | IO_REQUEST_READ_WRITE,
|
| 63 | }
|
| 64 | T_IO_REQUEST_DIRECTION;
|
| 65 |
|
| 66 |
|
| 67 | typedef enum _T_IO_REQUEST_BLOCK_TYPE
|
| 68 | {
|
| 69 | IO_REQUEST_NO_WAIT = 0,
|
| 70 | IO_REQUEST_WAIT_FOREVER,
|
| 71 | }
|
| 72 | T_IO_REQUEST_BLOCK_TYPE;
|
| 73 |
|
| 74 | typedef struct _T_IO_RequestOps
|
| 75 | {
|
| 76 | SINT32 (*hal_enable)(VOID *reqHndData);
|
| 77 | SINT32 (*hal_disable)(VOID *reqHndData);
|
| 78 | SINT32 (*start_request)(VOID *reqHndData, T_IO_REQUEST_DIRECTION reqDirection);
|
| 79 | VOID (*free_request) (VOID *reqHndData, T_IO_REQUEST_DIRECTION reqDirection, T_Request *req);
|
| 80 | SINT32 (*request_done)(VOID *reqHndData, T_Request *req, T_DONE_STATE doneState);
|
| 81 | }
|
| 82 | T_IO_RequestOps;
|
| 83 |
|
| 84 | typedef struct _T_Request_SgList
|
| 85 | {
|
| 86 | UINT8 *reqBuffer;
|
| 87 | UINT32 reqCount;
|
| 88 | }
|
| 89 | T_Request_SgList;
|
| 90 |
|
| 91 |
|
| 92 | typedef struct _T_IO_RequestHnd T_IO_RequestHnd;
|
| 93 |
|
| 94 | typedef SINT32 (*RequestDoneHnd)(T_IO_RequestHnd *, T_Request_SgList *, T_DONE_STATE);
|
| 95 |
|
| 96 |
|
| 97 | typedef struct _T_IO_RequestHnd
|
| 98 | {
|
| 99 | struct list_head node; /* node*/
|
| 100 | UINT8 *name;
|
| 101 | T_IO_REQUEST_DIRECTION reqDirection;
|
| 102 | UINT32 reqSize;
|
| 103 | volatile T_IO_HND_STATE hndState;
|
| 104 | UINT32 isSuspend;
|
| 105 | UINT32 halEnabled;
|
| 106 | T_IO_RequestOps *ops;
|
| 107 | VOID *reqHndData;
|
| 108 |
|
| 109 | /*read*/
|
| 110 | UINT32 readReqCount;
|
| 111 | T_Request_Queue *readQ;
|
| 112 | T_Ring_Queue *readDoneBuffer;
|
| 113 | T_IO_REQUEST_STATE readReqState;
|
| 114 | ZOSS_SEMAPHORE_ID readReqSem;
|
| 115 | RequestDoneHnd readDoneFn;
|
| 116 | T_Request_SgList readSgList;
|
| 117 | UINT32 readSgListMaxCount;
|
| 118 | UINT32 readFreeCnt;
|
| 119 |
|
| 120 | /*write*/
|
| 121 | UINT32 writeReqCount;
|
| 122 | T_Request_Queue *writeQ;
|
| 123 | T_IO_REQUEST_STATE writeReqState;
|
| 124 | ZOSS_SEMAPHORE_ID writeReqSem;
|
| 125 | RequestDoneHnd writeDoneFn;
|
| 126 | T_Request_SgList writeSgList;
|
| 127 | UINT32 writeSgListMaxCount;
|
| 128 | UINT32 writeFreeCnt;
|
| 129 |
|
| 130 | }
|
| 131 | T_IO_RequestHnd;
|
| 132 |
|
| 133 |
|
| 134 | /****************************************************************************
|
| 135 | * Constants
|
| 136 | ****************************************************************************/
|
| 137 |
|
| 138 | /****************************************************************************
|
| 139 | * Global Variables
|
| 140 | ****************************************************************************/
|
| 141 |
|
| 142 | /****************************************************************************
|
| 143 | * Function Prototypes
|
| 144 | ****************************************************************************/
|
| 145 |
|
| 146 | /*******************************************************************************
|
| 147 | * Function: IORequest_Create
|
| 148 | * Description:create the IO request handle, configure the params.
|
| 149 | * Input:
|
| 150 | * Output:None
|
| 151 | *
|
| 152 | * Returns:
|
| 153 | DRV_SUCCESS: success.
|
| 154 | DRV_ERROR: error.
|
| 155 | * Others:.
|
| 156 | ********************************************************************************/
|
| 157 | T_IO_RequestHnd * IORequest_Create(UINT8* name,
|
| 158 | T_IO_REQUEST_DIRECTION reqDirection, UINT32 reqSize,
|
| 159 | VOID *reqHndData, T_IO_RequestOps *ops,
|
| 160 | UINT32 readReqCount, UINT32 readSgListMaxCount,
|
| 161 | UINT32 writeReqCount, UINT32 writeSgListMaxCount);
|
| 162 |
|
| 163 | /*******************************************************************************
|
| 164 | * Function: IORequest_SubmitReadRequest
|
| 165 | * Description:submit the read request.
|
| 166 | * Input:
|
| 167 | * reqHnd: the handle of request.
|
| 168 | * req: the submit request.
|
| 169 | * Output:None
|
| 170 | *
|
| 171 | * Returns:
|
| 172 | * DRV_SUCCESS: success
|
| 173 | ********************************************************************************/
|
| 174 | SINT32 IORequest_SubmitReadRequest(T_IO_RequestHnd *reqHnd, T_Request *req);
|
| 175 |
|
| 176 | /*******************************************************************************
|
| 177 | * Function: IORequest_FetchDoneRequest
|
| 178 | * Description:fetch the completed read request.
|
| 179 | * Input:
|
| 180 | * reqHnd: the handle of request.
|
| 181 | * blockType: the block type of this operation. no wait or wait forever.
|
| 182 | * Output:None
|
| 183 | * req: the complete read request.
|
| 184 | * Returns:
|
| 185 | * DRV_SUCCESS: success
|
| 186 | * DRV_ERROR_AGAIN: no wait, need fetch again.
|
| 187 | * DRV_ERROR_ABORT: force exit.
|
| 188 | * Others:
|
| 189 | ********************************************************************************/
|
| 190 | SINT32 IORequest_FetchDoneRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType);
|
| 191 |
|
| 192 | /*******************************************************************************
|
| 193 | * Function: IORequest_SubmitWriteRequest
|
| 194 | * Description:submit the write request.
|
| 195 | * Input:
|
| 196 | * reqHnd: the handle of request.
|
| 197 | * req: the submit request.
|
| 198 | * blockType: the block type of this operation. no wait or wait forever.
|
| 199 | * Output:None
|
| 200 | *
|
| 201 | * Returns:
|
| 202 | * DRV_SUCCESS: success
|
| 203 | * DRV_ERROR_AGAIN: no wait, submit again.
|
| 204 | * DRV_ERROR_ABORT: force exit.
|
| 205 | * Others:
|
| 206 | ********************************************************************************/
|
| 207 | SINT32 IORequest_SubmitWriteRequest(T_IO_RequestHnd *reqHnd, T_Request *req, T_IO_REQUEST_BLOCK_TYPE blockType);
|
| 208 |
|
| 209 | /*******************************************************************************
|
| 210 | * Function: IORequest_WaitRequestDone
|
| 211 | * Description:wait the write request done.
|
| 212 | * Input:
|
| 213 | * reqHnd: the handle of request.
|
| 214 | * Output:None
|
| 215 | *
|
| 216 | * Returns:
|
| 217 | * DRV_SUCCESS: success
|
| 218 | * DRV_ERROR_ABORT: force exit.
|
| 219 | * Others:
|
| 220 | ********************************************************************************/
|
| 221 | SINT32 IORequest_WaitRequestDone(T_IO_RequestHnd *reqHnd);
|
| 222 |
|
| 223 | /*******************************************************************************
|
| 224 | * Function: IORequest_GetSgList
|
| 225 | * Description:get the current requests scatter list.
|
| 226 | * Input:
|
| 227 | * Output:None
|
| 228 | *
|
| 229 | * Returns:
|
| 230 | T_Request_SgList* : success.
|
| 231 | NULL: error
|
| 232 | * Others:
|
| 233 | ********************************************************************************/
|
| 234 | T_Request_SgList* IORequest_GetSgList(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection);
|
| 235 |
|
| 236 | /*******************************************************************************
|
| 237 | * Function: IORequest_Done
|
| 238 | * Description:has complete the request, take next proccess .
|
| 239 | * Input:
|
| 240 | * Output:None
|
| 241 | *
|
| 242 | * Returns:
|
| 243 | DRV_SUCCESS: success.
|
| 244 | DRV_ERROR: error.
|
| 245 | * Others:×¢Òâ:µ÷Óô˽ӿڵÄÓÅÏȼ¶Ò»¶¨¸ßÓÚÄ£¿éÄ򵀮äËû½Ó¿Ú£¬²»¿É±»´ò¶Ï¡£
|
| 246 | ********************************************************************************/
|
| 247 | SINT32 IORequest_Done(T_IO_RequestHnd *reqHnd, T_IO_REQUEST_DIRECTION reqDirection);
|
| 248 |
|
| 249 | /*******************************************************************************
|
| 250 | * Function: IORequest_Suspend
|
| 251 | * Description:suspend the request process, stop the hal operation.
|
| 252 | * Input:
|
| 253 | * Output:None
|
| 254 | *
|
| 255 | * Returns:
|
| 256 | DRV_SUCCESS: success.
|
| 257 | DRV_ERROR: error.
|
| 258 | * Others:
|
| 259 | ********************************************************************************/
|
| 260 | SINT32 IORequest_Suspend(T_IO_RequestHnd *reqHnd);
|
| 261 |
|
| 262 | /*******************************************************************************
|
| 263 | * Function: IORequest_Resume
|
| 264 | * Description:resume the request process, and restart the stopped hal operation.
|
| 265 | * Input:
|
| 266 | * Output:None
|
| 267 | *
|
| 268 | * Returns:
|
| 269 | DRV_SUCCESS: success.
|
| 270 | DRV_ERROR: error.
|
| 271 | * Others:
|
| 272 | ********************************************************************************/
|
| 273 | VOID IORequest_Resume(T_IO_RequestHnd *reqHnd);
|
| 274 |
|
| 275 | /*******************************************************************************
|
| 276 | * Function: IORequest_ForceExit
|
| 277 | * Description: force the higher process exit.
|
| 278 | * Input:
|
| 279 | * Output:None
|
| 280 | *
|
| 281 | * Returns:
|
| 282 | DRV_SUCCESS: success.
|
| 283 | DRV_ERROR: error.
|
| 284 | * Others:
|
| 285 | ********************************************************************************/
|
| 286 | VOID IORequest_ForceExit(T_IO_RequestHnd *reqHnd);
|
| 287 | /*******************************************************************************
|
| 288 | * Function: IORequest_CancelExit
|
| 289 | * Description: cancel exit mode, alloc higher process enter iorequest module.
|
| 290 | * Input:
|
| 291 | * Output:None
|
| 292 | *
|
| 293 | * Returns:
|
| 294 | * Others:
|
| 295 | ********************************************************************************/
|
| 296 | VOID IORequest_CancelExit(T_IO_RequestHnd *reqHnd);
|
| 297 | /*******************************************************************************
|
| 298 | * Function: IORequest_Destroy
|
| 299 | * Description:release the IO Request Handle, and inform the higher layer.
|
| 300 | * Input:
|
| 301 | * Output:None
|
| 302 | *
|
| 303 | * Returns:
|
| 304 |
|
| 305 | * Others:×¢Òâ:º¯Êý²»¸ºÔðÊÍ·ÅreqHnd¿Õ¼ä£¬½öÉèÖúÏÊÊ״̬.
|
| 306 | ÔÚÉϲãÈ·±£Ê±»ú°²È«ºó£¬²Å¿ÉÊͷŸÿռ䡣
|
| 307 | ********************************************************************************/
|
| 308 | VOID IORequest_Destroy(T_IO_RequestHnd *reqHnd);
|
| 309 |
|
| 310 | /*******************************************************************************
|
| 311 | * Function: IORequest_Print
|
| 312 | * Description:print the debug info.
|
| 313 | * Input:
|
| 314 | * Output:None
|
| 315 | *
|
| 316 | * Returns:
|
| 317 |
|
| 318 | * Others:
|
| 319 | ********************************************************************************/
|
| 320 | VOID IORequest_Print(T_IO_RequestHnd *reqHnd);
|
| 321 |
|
| 322 | /*******************************************************************************
|
| 323 | * Function: IORequest_PrintAll
|
| 324 | * Description:print the debug info.
|
| 325 | * Input:
|
| 326 | * Output:None
|
| 327 | *
|
| 328 | * Returns:
|
| 329 |
|
| 330 | * Others:
|
| 331 | ********************************************************************************/
|
| 332 | VOID IORequest_PrintAll(VOID);
|
| 333 |
|
| 334 | #endif/*_IO_REQUEST_H*/
|
| 335 |
|