18700e3e7SMoni Shoua /* 28700e3e7SMoni Shoua * Copyright (c) 2016 Mellanox Technologies Ltd. All rights reserved. 38700e3e7SMoni Shoua * Copyright (c) 2015 System Fabric Works, Inc. All rights reserved. 48700e3e7SMoni Shoua * 58700e3e7SMoni Shoua * This software is available to you under a choice of one of two 68700e3e7SMoni Shoua * licenses. You may choose to be licensed under the terms of the GNU 78700e3e7SMoni Shoua * General Public License (GPL) Version 2, available from the file 88700e3e7SMoni Shoua * COPYING in the main directory of this source tree, or the 98700e3e7SMoni Shoua * OpenIB.org BSD license below: 108700e3e7SMoni Shoua * 118700e3e7SMoni Shoua * Redistribution and use in source and binary forms, with or 128700e3e7SMoni Shoua * without modification, are permitted provided that the following 138700e3e7SMoni Shoua * conditions are met: 148700e3e7SMoni Shoua * 158700e3e7SMoni Shoua * - Redistributions of source code must retain the above 168700e3e7SMoni Shoua * copyright notice, this list of conditions and the following 178700e3e7SMoni Shoua * disclaimer. 188700e3e7SMoni Shoua * 198700e3e7SMoni Shoua * - Redistributions in binary form must reproduce the above 208700e3e7SMoni Shoua * copyright notice, this list of conditions and the following 218700e3e7SMoni Shoua * disclaimer in the documentation and/or other materials 228700e3e7SMoni Shoua * provided with the distribution. 238700e3e7SMoni Shoua * 248700e3e7SMoni Shoua * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 258700e3e7SMoni Shoua * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 268700e3e7SMoni Shoua * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 278700e3e7SMoni Shoua * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS 288700e3e7SMoni Shoua * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN 298700e3e7SMoni Shoua * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN 308700e3e7SMoni Shoua * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 318700e3e7SMoni Shoua * SOFTWARE. 328700e3e7SMoni Shoua */ 338700e3e7SMoni Shoua 348700e3e7SMoni Shoua #ifndef RXE_TASK_H 358700e3e7SMoni Shoua #define RXE_TASK_H 368700e3e7SMoni Shoua 378700e3e7SMoni Shoua enum { 388700e3e7SMoni Shoua TASK_STATE_START = 0, 398700e3e7SMoni Shoua TASK_STATE_BUSY = 1, 408700e3e7SMoni Shoua TASK_STATE_ARMED = 2, 418700e3e7SMoni Shoua }; 428700e3e7SMoni Shoua 438700e3e7SMoni Shoua /* 448700e3e7SMoni Shoua * data structure to describe a 'task' which is a short 458700e3e7SMoni Shoua * function that returns 0 as long as it needs to be 468700e3e7SMoni Shoua * called again. 478700e3e7SMoni Shoua */ 488700e3e7SMoni Shoua struct rxe_task { 498700e3e7SMoni Shoua void *obj; 508700e3e7SMoni Shoua struct tasklet_struct tasklet; 518700e3e7SMoni Shoua int state; 528700e3e7SMoni Shoua spinlock_t state_lock; /* spinlock for task state */ 538700e3e7SMoni Shoua void *arg; 548700e3e7SMoni Shoua int (*func)(void *arg); 558700e3e7SMoni Shoua int ret; 568700e3e7SMoni Shoua char name[16]; 578700e3e7SMoni Shoua }; 588700e3e7SMoni Shoua 598700e3e7SMoni Shoua /* 608700e3e7SMoni Shoua * init rxe_task structure 618700e3e7SMoni Shoua * arg => parameter to pass to fcn 628700e3e7SMoni Shoua * fcn => function to call until it returns != 0 638700e3e7SMoni Shoua */ 648700e3e7SMoni Shoua int rxe_init_task(void *obj, struct rxe_task *task, 658700e3e7SMoni Shoua void *arg, int (*func)(void *), char *name); 668700e3e7SMoni Shoua 678700e3e7SMoni Shoua /* cleanup task */ 688700e3e7SMoni Shoua void rxe_cleanup_task(struct rxe_task *task); 698700e3e7SMoni Shoua 708700e3e7SMoni Shoua /* 718700e3e7SMoni Shoua * raw call to func in loop without any checking 728700e3e7SMoni Shoua * can call when tasklets are disabled 738700e3e7SMoni Shoua */ 748700e3e7SMoni Shoua int __rxe_do_task(struct rxe_task *task); 758700e3e7SMoni Shoua 768700e3e7SMoni Shoua /* 778700e3e7SMoni Shoua * common function called by any of the main tasklets 788700e3e7SMoni Shoua * If there is any chance that there is additional 798700e3e7SMoni Shoua * work to do someone must reschedule the task before 808700e3e7SMoni Shoua * leaving 818700e3e7SMoni Shoua */ 828700e3e7SMoni Shoua void rxe_do_task(unsigned long data); 838700e3e7SMoni Shoua 848700e3e7SMoni Shoua /* run a task, else schedule it to run as a tasklet, The decision 858700e3e7SMoni Shoua * to run or schedule tasklet is based on the parameter sched. 868700e3e7SMoni Shoua */ 878700e3e7SMoni Shoua void rxe_run_task(struct rxe_task *task, int sched); 888700e3e7SMoni Shoua 898700e3e7SMoni Shoua /* keep a task from scheduling */ 908700e3e7SMoni Shoua void rxe_disable_task(struct rxe_task *task); 918700e3e7SMoni Shoua 928700e3e7SMoni Shoua /* allow task to run */ 938700e3e7SMoni Shoua void rxe_enable_task(struct rxe_task *task); 948700e3e7SMoni Shoua 958700e3e7SMoni Shoua #endif /* RXE_TASK_H */ 96