xref: /OK3568_Linux_fs/kernel/drivers/scsi/arm/queue.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun /* SPDX-License-Identifier: GPL-2.0-only */
2*4882a593Smuzhiyun /*
3*4882a593Smuzhiyun  *  linux/drivers/acorn/scsi/queue.h: queue handling
4*4882a593Smuzhiyun  *
5*4882a593Smuzhiyun  *  Copyright (C) 1997 Russell King
6*4882a593Smuzhiyun  */
7*4882a593Smuzhiyun #ifndef QUEUE_H
8*4882a593Smuzhiyun #define QUEUE_H
9*4882a593Smuzhiyun 
10*4882a593Smuzhiyun typedef struct {
11*4882a593Smuzhiyun 	struct list_head head;
12*4882a593Smuzhiyun 	struct list_head free;
13*4882a593Smuzhiyun 	spinlock_t queue_lock;
14*4882a593Smuzhiyun 	void *alloc;			/* start of allocated mem */
15*4882a593Smuzhiyun } Queue_t;
16*4882a593Smuzhiyun 
17*4882a593Smuzhiyun /*
18*4882a593Smuzhiyun  * Function: void queue_initialise (Queue_t *queue)
19*4882a593Smuzhiyun  * Purpose : initialise a queue
20*4882a593Smuzhiyun  * Params  : queue - queue to initialise
21*4882a593Smuzhiyun  */
22*4882a593Smuzhiyun extern int queue_initialise (Queue_t *queue);
23*4882a593Smuzhiyun 
24*4882a593Smuzhiyun /*
25*4882a593Smuzhiyun  * Function: void queue_free (Queue_t *queue)
26*4882a593Smuzhiyun  * Purpose : free a queue
27*4882a593Smuzhiyun  * Params  : queue - queue to free
28*4882a593Smuzhiyun  */
29*4882a593Smuzhiyun extern void queue_free (Queue_t *queue);
30*4882a593Smuzhiyun 
31*4882a593Smuzhiyun /*
32*4882a593Smuzhiyun  * Function: struct scsi_cmnd *queue_remove (queue)
33*4882a593Smuzhiyun  * Purpose : removes first SCSI command from a queue
34*4882a593Smuzhiyun  * Params  : queue   - queue to remove command from
35*4882a593Smuzhiyun  * Returns : struct scsi_cmnd if successful (and a reference), or NULL if no command available
36*4882a593Smuzhiyun  */
37*4882a593Smuzhiyun extern struct scsi_cmnd *queue_remove (Queue_t *queue);
38*4882a593Smuzhiyun 
39*4882a593Smuzhiyun /*
40*4882a593Smuzhiyun  * Function: struct scsi_cmnd *queue_remove_exclude_ref (queue, exclude)
41*4882a593Smuzhiyun  * Purpose : remove a SCSI command from a queue
42*4882a593Smuzhiyun  * Params  : queue   - queue to remove command from
43*4882a593Smuzhiyun  *	     exclude - array of busy LUNs
44*4882a593Smuzhiyun  * Returns : struct scsi_cmnd if successful (and a reference), or NULL if no command available
45*4882a593Smuzhiyun  */
46*4882a593Smuzhiyun extern struct scsi_cmnd *queue_remove_exclude(Queue_t *queue,
47*4882a593Smuzhiyun 					      unsigned long *exclude);
48*4882a593Smuzhiyun 
49*4882a593Smuzhiyun #define queue_add_cmd_ordered(queue,SCpnt) \
50*4882a593Smuzhiyun 	__queue_add(queue,SCpnt,(SCpnt)->cmnd[0] == REQUEST_SENSE)
51*4882a593Smuzhiyun #define queue_add_cmd_tail(queue,SCpnt) \
52*4882a593Smuzhiyun 	__queue_add(queue,SCpnt,0)
53*4882a593Smuzhiyun /*
54*4882a593Smuzhiyun  * Function: int __queue_add(Queue_t *queue, struct scsi_cmnd *SCpnt, int head)
55*4882a593Smuzhiyun  * Purpose : Add a new command onto a queue
56*4882a593Smuzhiyun  * Params  : queue - destination queue
57*4882a593Smuzhiyun  *	     SCpnt - command to add
58*4882a593Smuzhiyun  *	     head  - add command to head of queue
59*4882a593Smuzhiyun  * Returns : 0 on error, !0 on success
60*4882a593Smuzhiyun  */
61*4882a593Smuzhiyun extern int __queue_add(Queue_t *queue, struct scsi_cmnd *SCpnt, int head);
62*4882a593Smuzhiyun 
63*4882a593Smuzhiyun /*
64*4882a593Smuzhiyun  * Function: struct scsi_cmnd *queue_remove_tgtluntag (queue, target, lun, tag)
65*4882a593Smuzhiyun  * Purpose : remove a SCSI command from the queue for a specified target/lun/tag
66*4882a593Smuzhiyun  * Params  : queue  - queue to remove command from
67*4882a593Smuzhiyun  *	     target - target that we want
68*4882a593Smuzhiyun  *	     lun    - lun on device
69*4882a593Smuzhiyun  *	     tag    - tag on device
70*4882a593Smuzhiyun  * Returns : struct scsi_cmnd if successful, or NULL if no command satisfies requirements
71*4882a593Smuzhiyun  */
72*4882a593Smuzhiyun extern struct scsi_cmnd *queue_remove_tgtluntag(Queue_t *queue, int target,
73*4882a593Smuzhiyun 						int lun, int tag);
74*4882a593Smuzhiyun 
75*4882a593Smuzhiyun /*
76*4882a593Smuzhiyun  * Function: queue_remove_all_target(queue, target)
77*4882a593Smuzhiyun  * Purpose : remove all SCSI commands from the queue for a specified target
78*4882a593Smuzhiyun  * Params  : queue  - queue to remove command from
79*4882a593Smuzhiyun  *           target - target device id
80*4882a593Smuzhiyun  * Returns : nothing
81*4882a593Smuzhiyun  */
82*4882a593Smuzhiyun extern void queue_remove_all_target(Queue_t *queue, int target);
83*4882a593Smuzhiyun 
84*4882a593Smuzhiyun /*
85*4882a593Smuzhiyun  * Function: int queue_probetgtlun (queue, target, lun)
86*4882a593Smuzhiyun  * Purpose : check to see if we have a command in the queue for the specified
87*4882a593Smuzhiyun  *	     target/lun.
88*4882a593Smuzhiyun  * Params  : queue  - queue to look in
89*4882a593Smuzhiyun  *	     target - target we want to probe
90*4882a593Smuzhiyun  *	     lun    - lun on target
91*4882a593Smuzhiyun  * Returns : 0 if not found, != 0 if found
92*4882a593Smuzhiyun  */
93*4882a593Smuzhiyun extern int queue_probetgtlun (Queue_t *queue, int target, int lun);
94*4882a593Smuzhiyun 
95*4882a593Smuzhiyun /*
96*4882a593Smuzhiyun  * Function: int queue_remove_cmd (Queue_t *queue, struct scsi_cmnd *SCpnt)
97*4882a593Smuzhiyun  * Purpose : remove a specific command from the queues
98*4882a593Smuzhiyun  * Params  : queue - queue to look in
99*4882a593Smuzhiyun  *	     SCpnt - command to find
100*4882a593Smuzhiyun  * Returns : 0 if not found
101*4882a593Smuzhiyun  */
102*4882a593Smuzhiyun int queue_remove_cmd(Queue_t *queue, struct scsi_cmnd *SCpnt);
103*4882a593Smuzhiyun 
104*4882a593Smuzhiyun #endif /* QUEUE_H */
105