xref: /OK3568_Linux_fs/kernel/drivers/scsi/arm/msgqueue.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  linux/drivers/acorn/scsi/msgqueue.h
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 1997 Russell King
6*4882a593Smuzhiyun  *
7*4882a593Smuzhiyun  *  message queue handling
8*4882a593Smuzhiyun  */
9*4882a593Smuzhiyun #ifndef MSGQUEUE_H
10*4882a593Smuzhiyun #define MSGQUEUE_H
11*4882a593Smuzhiyun 
12*4882a593Smuzhiyun struct message {
13*4882a593Smuzhiyun     char msg[8];
14*4882a593Smuzhiyun     int length;
15*4882a593Smuzhiyun     int fifo;
16*4882a593Smuzhiyun };
17*4882a593Smuzhiyun 
18*4882a593Smuzhiyun struct msgqueue_entry {
19*4882a593Smuzhiyun     struct message msg;
20*4882a593Smuzhiyun     struct msgqueue_entry *next;
21*4882a593Smuzhiyun };
22*4882a593Smuzhiyun 
23*4882a593Smuzhiyun #define NR_MESSAGES 4
24*4882a593Smuzhiyun 
25*4882a593Smuzhiyun typedef struct {
26*4882a593Smuzhiyun     struct msgqueue_entry *qe;
27*4882a593Smuzhiyun     struct msgqueue_entry *free;
28*4882a593Smuzhiyun     struct msgqueue_entry entries[NR_MESSAGES];
29*4882a593Smuzhiyun } MsgQueue_t;
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun  * Function: void msgqueue_initialise(MsgQueue_t *msgq)
33*4882a593Smuzhiyun  * Purpose : initialise a message queue
34*4882a593Smuzhiyun  * Params  : msgq - queue to initialise
35*4882a593Smuzhiyun  */
36*4882a593Smuzhiyun extern void msgqueue_initialise(MsgQueue_t *msgq);
37*4882a593Smuzhiyun 
38*4882a593Smuzhiyun /*
39*4882a593Smuzhiyun  * Function: void msgqueue_free(MsgQueue_t *msgq)
40*4882a593Smuzhiyun  * Purpose : free a queue
41*4882a593Smuzhiyun  * Params  : msgq - queue to free
42*4882a593Smuzhiyun  */
43*4882a593Smuzhiyun extern void msgqueue_free(MsgQueue_t *msgq);
44*4882a593Smuzhiyun 
45*4882a593Smuzhiyun /*
46*4882a593Smuzhiyun  * Function: int msgqueue_msglength(MsgQueue_t *msgq)
47*4882a593Smuzhiyun  * Purpose : calculate the total length of all messages on the message queue
48*4882a593Smuzhiyun  * Params  : msgq - queue to examine
49*4882a593Smuzhiyun  * Returns : number of bytes of messages in queue
50*4882a593Smuzhiyun  */
51*4882a593Smuzhiyun extern int msgqueue_msglength(MsgQueue_t *msgq);
52*4882a593Smuzhiyun 
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  * Function: struct message *msgqueue_getmsg(MsgQueue_t *msgq, int msgno)
55*4882a593Smuzhiyun  * Purpose : return a message & its length
56*4882a593Smuzhiyun  * Params  : msgq   - queue to obtain message from
57*4882a593Smuzhiyun  *         : msgno  - message number
58*4882a593Smuzhiyun  * Returns : pointer to message string, or NULL
59*4882a593Smuzhiyun  */
60*4882a593Smuzhiyun extern struct message *msgqueue_getmsg(MsgQueue_t *msgq, int msgno);
61*4882a593Smuzhiyun 
62*4882a593Smuzhiyun /*
63*4882a593Smuzhiyun  * Function: int msgqueue_addmsg(MsgQueue_t *msgq, int length, ...)
64*4882a593Smuzhiyun  * Purpose : add a message onto a message queue
65*4882a593Smuzhiyun  * Params  : msgq   - queue to add message on
66*4882a593Smuzhiyun  *	     length - length of message
67*4882a593Smuzhiyun  *	     ...    - message bytes
68*4882a593Smuzhiyun  * Returns : != 0 if successful
69*4882a593Smuzhiyun  */
70*4882a593Smuzhiyun extern int msgqueue_addmsg(MsgQueue_t *msgq, int length, ...);
71*4882a593Smuzhiyun 
72*4882a593Smuzhiyun /*
73*4882a593Smuzhiyun  * Function: void msgqueue_flush(MsgQueue_t *msgq)
74*4882a593Smuzhiyun  * Purpose : flush all messages from message queue
75*4882a593Smuzhiyun  * Params  : msgq - queue to flush
76*4882a593Smuzhiyun  */
77*4882a593Smuzhiyun extern void msgqueue_flush(MsgQueue_t *msgq);
78*4882a593Smuzhiyun 
79*4882a593Smuzhiyun #endif
80