1 /* devcommon.c - common device code
2 * Linux CAN-bus device driver.
3 * New CAN queues by Pavel Pisa - OCERA team member
4 * email:pisa@cmp.felk.cvut.cz
5 * This software is released under the GPL-License.
6 * Version lincan-0.2 9 Jul 2003
9 #include "../include/can.h"
10 #include "../include/can_sysdep.h"
11 #include "../include/can_queue.h"
12 #include "../include/main.h"
13 #include "../include/devcommon.h"
16 * canqueue_notify_chip - notification callback handler for CAN chips ends of queues
17 * @qends: pointer to the callback side ends structure
18 * @qedge: edge which invoked notification
19 * @what: notification type
21 * This function has to deal with more possible cases. It can be called from
22 * the kernel or interrupt context for Linux only compilation of driver.
23 * The function can be called from kernel context or RT-Linux thread context
24 * for mixed mode Linux/RT-Linux compilation.
26 void canqueue_notify_chip(struct canque_ends_t *qends, struct canque_edge_t *qedge, int what)
28 struct chip_t *chip=qends->endinfo.chipinfo.chip;
29 struct msgobj_t *obj=qends->endinfo.chipinfo.msgobj;
31 DEBUGMSG("canqueue_notify_chip for edge %d and event %d\n",qedge->edge_num,what);
33 /*case CANQUEUE_NOTIFY_EMPTY:*/
34 /*case CANQUEUE_NOTIFY_SPACE:*/
35 /*case CANQUEUE_NOTIFY_NOUSR:
36 wake_up(&qends->endinfo.chipinfo.daemonq);
38 case CANQUEUE_NOTIFY_PROC:
40 /*wake_up(&qends->endinfo.chipinfo.daemonq);*/
41 chip->chipspecops->wakeup_tx(chip, obj);
42 #else /*CAN_WITH_RTL*/
43 can_msgobj_set_fl(obj,TX_REQUEST);
44 if(qends->endinfo.chipinfo.worker_thread){
45 can_msgobj_set_fl(obj,WORKER_WAKE);
46 pthread_kill(qends->endinfo.chipinfo.worker_thread,RTL_SIGNAL_WAKEUP);
49 set_bit(MSGOBJ_TX_REQUEST_b,&chip->pend_flags);
51 if(chip->worker_thread) {
52 set_bit(MSGOBJ_WORKER_WAKE_b,&chip->pend_flags);
53 pthread_kill(chip->worker_thread,RTL_SIGNAL_WAKEUP);
57 #endif /*CAN_WITH_RTL*/
59 case CANQUEUE_NOTIFY_DEAD_WANTED:
60 case CANQUEUE_NOTIFY_DEAD:
61 if(canque_fifo_test_and_clear_fl(&qedge->fifo, READY))
62 canque_edge_decref(qedge);
64 case CANQUEUE_NOTIFY_ATTACH:
71 * canqueue_ends_init_chip - CAN chip specific ends initialization
72 * @qends: pointer to the ends structure
73 * @chip: pointer to the corresponding CAN chip structure
74 * @obj: pointer to the corresponding message object structure
76 int canqueue_ends_init_chip(struct canque_ends_t *qends, struct chip_t *chip, struct msgobj_t *obj)
79 ret=canqueue_ends_init_gen(qends);
84 init_waitqueue_head(&qends->endinfo.chipinfo.daemonq);
85 #endif /*CAN_WITH_RTL*/
86 qends->endinfo.chipinfo.chip=chip;
87 qends->endinfo.chipinfo.msgobj=obj;
88 qends->notify=canqueue_notify_chip;
90 DEBUGMSG("canqueue_ends_init_chip\n");
96 * canqueue_ends_done_chip - finalizing of the ends structure for CAN chips
97 * @qends: pointer to ends structure
99 * Return Value: Function should be designed such way to not fail.
101 int canqueue_ends_done_chip(struct canque_ends_t *qends)
105 /* Finish or kill all outgoing edges listed in inends */
106 delayed=canqueue_ends_kill_inlist(qends, 1);
107 /* Kill all incoming edges listed in outends */
108 delayed|=canqueue_ends_kill_outlist(qends);