Orange Pi5 kernel

Deprecated Linux kernel 5.10.110 for OrangePi 5/5B/5+ boards

3 Commits   0 Branches   0 Tags   |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   1) // SPDX-License-Identifier: GPL-2.0-only
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   3)  *  linux/drivers/acorn/scsi/queue.c: queue handling primitives
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   4)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   5)  *  Copyright (C) 1997-2000 Russell King
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   6)  *
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   7)  *  Changelog:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   8)  *   15-Sep-1997 RMK	Created.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300   9)  *   11-Oct-1997 RMK	Corrected problem with queue_remove_exclude
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  10)  *			not updating internal linked list properly
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  11)  *			(was causing commands to go missing).
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  12)  *   30-Aug-2000 RMK	Use Linux list handling and spinlocks
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  13)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  14) #include <linux/module.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  15) #include <linux/blkdev.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  16) #include <linux/kernel.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  17) #include <linux/string.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  18) #include <linux/slab.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  19) #include <linux/spinlock.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  20) #include <linux/list.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  21) #include <linux/init.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  22) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  23) #include "../scsi.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  24) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  25) #define DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  26) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  27) typedef struct queue_entry {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  28) 	struct list_head   list;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  29) 	struct scsi_cmnd   *SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  30) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  31) 	unsigned long	   magic;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  32) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  33) } QE_t;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  34) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  35) #ifdef DEBUG
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  36) #define QUEUE_MAGIC_FREE	0xf7e1c9a3
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  37) #define QUEUE_MAGIC_USED	0xf7e1cc33
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  38) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  39) #define SET_MAGIC(q,m)	((q)->magic = (m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  40) #define BAD_MAGIC(q,m)	((q)->magic != (m))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  41) #else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  42) #define SET_MAGIC(q,m)	do { } while (0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  43) #define BAD_MAGIC(q,m)	(0)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  44) #endif
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  45) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  46) #include "queue.h"
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  47) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  48) #define NR_QE	32
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  49) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  50) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  51)  * Function: void queue_initialise (Queue_t *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  52)  * Purpose : initialise a queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  53)  * Params  : queue - queue to initialise
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  54)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  55) int queue_initialise (Queue_t *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  56) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  57) 	unsigned int nqueues = NR_QE;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  58) 	QE_t *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  59) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  60) 	spin_lock_init(&queue->queue_lock);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  61) 	INIT_LIST_HEAD(&queue->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  62) 	INIT_LIST_HEAD(&queue->free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  63) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  64) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  65) 	 * If life was easier, then SCpnt would have a
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  66) 	 * host-available list head, and we wouldn't
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  67) 	 * need to keep free lists or allocate this
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  68) 	 * memory.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  69) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  70) 	queue->alloc = q = kmalloc_array(nqueues, sizeof(QE_t), GFP_KERNEL);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  71) 	if (q) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  72) 		for (; nqueues; q++, nqueues--) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  73) 			SET_MAGIC(q, QUEUE_MAGIC_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  74) 			q->SCpnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  75) 			list_add(&q->list, &queue->free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  76) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  77) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  78) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  79) 	return queue->alloc != NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  80) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  81) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  82) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  83)  * Function: void queue_free (Queue_t *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  84)  * Purpose : free a queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  85)  * Params  : queue - queue to free
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  86)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  87) void queue_free (Queue_t *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  88) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  89) 	if (!list_empty(&queue->head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  90) 		printk(KERN_WARNING "freeing non-empty queue %p\n", queue);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  91) 	kfree(queue->alloc);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  92) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  93)      
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  94) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  95) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  96)  * Function: int __queue_add(Queue_t *queue, struct scsi_cmnd *SCpnt, int head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  97)  * Purpose : Add a new command onto a queue, adding REQUEST_SENSE to head.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  98)  * Params  : queue - destination queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300  99)  *	     SCpnt - command to add
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 100)  *	     head  - add command to head of queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 101)  * Returns : 0 on error, !0 on success
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 102)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 103) int __queue_add(Queue_t *queue, struct scsi_cmnd *SCpnt, int head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 104) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 105) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 106) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 107) 	QE_t *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 108) 	int ret = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 109) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 110) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 111) 	if (list_empty(&queue->free))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 112) 		goto empty;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 113) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 114) 	l = queue->free.next;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 115) 	list_del(l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 116) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 117) 	q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 118) 	BUG_ON(BAD_MAGIC(q, QUEUE_MAGIC_FREE));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 119) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 120) 	SET_MAGIC(q, QUEUE_MAGIC_USED);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 121) 	q->SCpnt = SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 122) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 123) 	if (head)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 124) 		list_add(l, &queue->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 125) 	else
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 126) 		list_add_tail(l, &queue->head);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 127) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 128) 	ret = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 129) empty:
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 130) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 131) 	return ret;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 132) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 133) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 134) static struct scsi_cmnd *__queue_remove(Queue_t *queue, struct list_head *ent)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 135) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 136) 	QE_t *q;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 137) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 138) 	/*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 139) 	 * Move the entry from the "used" list onto the "free" list
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 140) 	 */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 141) 	list_del(ent);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 142) 	q = list_entry(ent, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 143) 	BUG_ON(BAD_MAGIC(q, QUEUE_MAGIC_USED));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 144) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 145) 	SET_MAGIC(q, QUEUE_MAGIC_FREE);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 146) 	list_add(ent, &queue->free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 147) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 148) 	return q->SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 149) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 150) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 151) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 152)  * Function: struct scsi_cmnd *queue_remove_exclude (queue, exclude)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 153)  * Purpose : remove a SCSI command from a queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 154)  * Params  : queue   - queue to remove command from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 155)  *	     exclude - bit array of target&lun which is busy
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 156)  * Returns : struct scsi_cmnd if successful (and a reference), or NULL if no command available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 157)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 158) struct scsi_cmnd *queue_remove_exclude(Queue_t *queue, unsigned long *exclude)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 159) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 160) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 161) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 162) 	struct scsi_cmnd *SCpnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 163) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 164) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 165) 	list_for_each(l, &queue->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 166) 		QE_t *q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 167) 		if (!test_bit(q->SCpnt->device->id * 8 +
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 168) 			      (u8)(q->SCpnt->device->lun & 0x7), exclude)) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 169) 			SCpnt = __queue_remove(queue, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 170) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 171) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 172) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 173) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 174) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 175) 	return SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 176) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 177) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 178) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 179)  * Function: struct scsi_cmnd *queue_remove (queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 180)  * Purpose : removes first SCSI command from a queue
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 181)  * Params  : queue   - queue to remove command from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 182)  * Returns : struct scsi_cmnd if successful (and a reference), or NULL if no command available
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 183)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 184) struct scsi_cmnd *queue_remove(Queue_t *queue)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 185) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 186) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 187) 	struct scsi_cmnd *SCpnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 188) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 189) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 190) 	if (!list_empty(&queue->head))
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 191) 		SCpnt = __queue_remove(queue, queue->head.next);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 192) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 193) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 194) 	return SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 195) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 196) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 197) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 198)  * Function: struct scsi_cmnd *queue_remove_tgtluntag (queue, target, lun, tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 199)  * Purpose : remove a SCSI command from the queue for a specified target/lun/tag
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 200)  * Params  : queue  - queue to remove command from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 201)  *	     target - target that we want
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 202)  *	     lun    - lun on device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 203)  *	     tag    - tag on device
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 204)  * Returns : struct scsi_cmnd if successful, or NULL if no command satisfies requirements
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 205)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 206) struct scsi_cmnd *queue_remove_tgtluntag(Queue_t *queue, int target, int lun,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 207) 					 int tag)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 208) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 209) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 210) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 211) 	struct scsi_cmnd *SCpnt = NULL;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 212) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 213) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 214) 	list_for_each(l, &queue->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 215) 		QE_t *q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 216) 		if (q->SCpnt->device->id == target && q->SCpnt->device->lun == lun &&
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 217) 		    q->SCpnt->tag == tag) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 218) 			SCpnt = __queue_remove(queue, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 219) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 220) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 221) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 222) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 223) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 224) 	return SCpnt;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 225) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 226) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 227) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 228)  * Function: queue_remove_all_target(queue, target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 229)  * Purpose : remove all SCSI commands from the queue for a specified target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 230)  * Params  : queue  - queue to remove command from
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 231)  *           target - target device id
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 232)  * Returns : nothing
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 233)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 234) void queue_remove_all_target(Queue_t *queue, int target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 235) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 236) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 237) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 238) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 239) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 240) 	list_for_each(l, &queue->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 241) 		QE_t *q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 242) 		if (q->SCpnt->device->id == target)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 243) 			__queue_remove(queue, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 244) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 245) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 246) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 247) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 248) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 249)  * Function: int queue_probetgtlun (queue, target, lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 250)  * Purpose : check to see if we have a command in the queue for the specified
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 251)  *	     target/lun.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 252)  * Params  : queue  - queue to look in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 253)  *	     target - target we want to probe
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 254)  *	     lun    - lun on target
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 255)  * Returns : 0 if not found, != 0 if found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 256)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 257) int queue_probetgtlun (Queue_t *queue, int target, int lun)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 258) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 259) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 260) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 261) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 262) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 263) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 264) 	list_for_each(l, &queue->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 265) 		QE_t *q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 266) 		if (q->SCpnt->device->id == target && q->SCpnt->device->lun == lun) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 267) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 268) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 269) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 270) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 271) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 272) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 273) 	return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 274) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 275) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 276) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 277)  * Function: int queue_remove_cmd(Queue_t *queue, struct scsi_cmnd *SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 278)  * Purpose : remove a specific command from the queues
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 279)  * Params  : queue - queue to look in
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 280)  *	     SCpnt - command to find
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 281)  * Returns : 0 if not found
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 282)  */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 283) int queue_remove_cmd(Queue_t *queue, struct scsi_cmnd *SCpnt)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 284) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 285) 	unsigned long flags;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 286) 	struct list_head *l;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 287) 	int found = 0;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 288) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 289) 	spin_lock_irqsave(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 290) 	list_for_each(l, &queue->head) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 291) 		QE_t *q = list_entry(l, QE_t, list);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 292) 		if (q->SCpnt == SCpnt) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 293) 			__queue_remove(queue, l);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 294) 			found = 1;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 295) 			break;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 296) 		}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 297) 	}
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 298) 	spin_unlock_irqrestore(&queue->queue_lock, flags);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 299) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 300) 	return found;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 301) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 302) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 303) EXPORT_SYMBOL(queue_initialise);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 304) EXPORT_SYMBOL(queue_free);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 305) EXPORT_SYMBOL(__queue_add);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 306) EXPORT_SYMBOL(queue_remove);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 307) EXPORT_SYMBOL(queue_remove_exclude);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 308) EXPORT_SYMBOL(queue_remove_tgtluntag);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 309) EXPORT_SYMBOL(queue_remove_cmd);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 310) EXPORT_SYMBOL(queue_remove_all_target);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 311) EXPORT_SYMBOL(queue_probetgtlun);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 312) 
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 313) MODULE_AUTHOR("Russell King");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 314) MODULE_DESCRIPTION("SCSI command queueing");
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 315) MODULE_LICENSE("GPL");