1 /******************************************************************************
2 * QLOGIC LINUX SOFTWARE
4 * QLogic ISP2x00 device driver for Linux 2.6.x
5 * Copyright (C) 2003-2004 QLogic Corporation
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2, or (at your option) any
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
18 ******************************************************************************/
20 /* Management functions for various lists */
22 /* __add_to_done_queue()
24 * Place SRB command on done queue.
30 * this function assumes the ha->list_lock is already taken
33 __add_to_done_queue(struct scsi_qla_host * ha, srb_t * sp)
36 if (sp->state != SRB_NO_QUEUE_STATE &&
37 sp->state != SRB_ACTIVE_STATE)
41 /* Place block on done queue */
42 sp->cmd->host_scribble = (unsigned char *) NULL;
43 sp->state = SRB_DONE_STATE;
44 list_add_tail(&sp->list,&ha->done_queue);
50 __add_to_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
53 if( sp->state != SRB_NO_QUEUE_STATE &&
54 sp->state != SRB_ACTIVE_STATE)
58 /* Place block on retry queue */
59 list_add_tail(&sp->list,&ha->retry_queue);
61 sp->flags |= SRB_WATCHDOG;
62 sp->state = SRB_RETRY_STATE;
67 __add_to_scsi_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
70 if( sp->state != SRB_NO_QUEUE_STATE &&
71 sp->state != SRB_ACTIVE_STATE)
75 /* Place block on retry queue */
76 list_add_tail(&sp->list,&ha->scsi_retry_queue);
77 ha->scsi_retry_q_cnt++;
78 sp->state = SRB_SCSI_RETRY_STATE;
83 add_to_done_queue(struct scsi_qla_host * ha, srb_t * sp)
87 spin_lock_irqsave(&ha->list_lock, flags);
88 __add_to_done_queue(ha,sp);
89 spin_unlock_irqrestore(&ha->list_lock, flags);
93 add_to_free_queue(struct scsi_qla_host * ha, srb_t * sp)
95 mempool_free(sp, ha->srb_mempool);
99 add_to_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
103 spin_lock_irqsave(&ha->list_lock, flags);
104 __add_to_retry_queue(ha,sp);
105 spin_unlock_irqrestore(&ha->list_lock, flags);
109 add_to_scsi_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
113 spin_lock_irqsave(&ha->list_lock, flags);
114 __add_to_scsi_retry_queue(ha,sp);
115 spin_unlock_irqrestore(&ha->list_lock, flags);
119 * __del_from_retry_queue
120 * Function used to remove a command block from the
121 * watchdog timer queue.
123 * Note: Must insure that command is on watchdog
124 * list before calling del_from_retry_queue
125 * if (sp->flags & SRB_WATCHDOG)
128 * ha = adapter block pointer.
131 * this function assumes the list_lock is already taken
134 __del_from_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
136 list_del_init(&sp->list);
138 sp->flags &= ~(SRB_WATCHDOG | SRB_BUSY);
139 sp->state = SRB_NO_QUEUE_STATE;
144 * __del_from_scsi_retry_queue
145 * Function used to remove a command block from the
149 * ha = adapter block pointer.
152 * this function assumes the list_lock is already taken
155 __del_from_scsi_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
157 list_del_init(&sp->list);
159 ha->scsi_retry_q_cnt--;
160 sp->state = SRB_NO_QUEUE_STATE;
164 * del_from_retry_queue
165 * Function used to remove a command block from the
166 * watchdog timer queue.
168 * Note: Must insure that command is on watchdog
169 * list before calling del_from_retry_queue
170 * if (sp->flags & SRB_WATCHDOG)
173 * ha = adapter block pointer.
176 * this function takes and releases the list_lock
179 del_from_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
183 /* if (unlikely(!(sp->flags & SRB_WATCHDOG)))
185 spin_lock_irqsave(&ha->list_lock, flags);
187 /* if (unlikely(list_empty(&ha->retry_queue)))
190 __del_from_retry_queue(ha,sp);
192 spin_unlock_irqrestore(&ha->list_lock, flags);
195 * del_from_scsi_retry_queue
196 * Function used to remove a command block from the
200 * ha = adapter block pointer.
203 * this function takes and releases the list_lock
206 del_from_scsi_retry_queue(struct scsi_qla_host * ha, srb_t * sp)
210 spin_lock_irqsave(&ha->list_lock, flags);
212 /* if (unlikely(list_empty(&ha->scsi_retry_queue)))
215 __del_from_scsi_retry_queue(ha,sp);
217 spin_unlock_irqrestore(&ha->list_lock, flags);
221 * __add_to_pending_queue
222 * Add the standard SCB job to the bottom of standard SCB commands.
226 * q = SCSI LU pointer.
228 * SCSI_LU_Q lock must be already obtained.
231 __add_to_pending_queue(struct scsi_qla_host *ha, srb_t * sp)
235 if( sp->state != SRB_NO_QUEUE_STATE &&
236 sp->state != SRB_FREE_STATE &&
237 sp->state != SRB_ACTIVE_STATE)
241 empty = list_empty(&ha->pending_queue);
242 list_add_tail(&sp->list, &ha->pending_queue);
244 sp->state = SRB_PENDING_STATE;
250 __add_to_pending_queue_head(struct scsi_qla_host *ha, srb_t * sp)
253 if( sp->state != SRB_NO_QUEUE_STATE &&
254 sp->state != SRB_FREE_STATE &&
255 sp->state != SRB_ACTIVE_STATE)
259 list_add(&sp->list, &ha->pending_queue);
261 sp->state = SRB_PENDING_STATE;
265 add_to_pending_queue(struct scsi_qla_host *ha, srb_t *sp)
270 spin_lock_irqsave(&ha->list_lock, flags);
271 empty = __add_to_pending_queue(ha, sp);
272 spin_unlock_irqrestore(&ha->list_lock, flags);
277 add_to_pending_queue_head(struct scsi_qla_host *ha, srb_t *sp)
281 spin_lock_irqsave(&ha->list_lock, flags);
282 __add_to_pending_queue_head(ha, sp);
283 spin_unlock_irqrestore(&ha->list_lock, flags);
287 __del_from_pending_queue(struct scsi_qla_host *ha, srb_t *sp)
289 list_del_init(&sp->list);
291 sp->state = SRB_NO_QUEUE_STATE;
298 __add_to_failover_queue(struct scsi_qla_host * ha, srb_t * sp)
301 if( sp->state != SRB_NO_QUEUE_STATE &&
302 sp->state != SRB_ACTIVE_STATE)
306 list_add_tail(&sp->list,&ha->failover_queue);
308 sp->state = SRB_FAILOVER_STATE;
312 static inline void add_to_failover_queue(struct scsi_qla_host * ha, srb_t * sp)
316 spin_lock_irqsave(&ha->list_lock, flags);
318 __add_to_failover_queue(ha,sp);
320 spin_unlock_irqrestore(&ha->list_lock, flags);
322 static inline void __del_from_failover_queue(struct scsi_qla_host * ha, srb_t *
326 list_del_init(&sp->list);
327 sp->state = SRB_NO_QUEUE_STATE;
330 static inline void del_from_failover_queue(struct scsi_qla_host * ha, srb_t * sp)
334 spin_lock_irqsave(&ha->list_lock, flags);
336 __del_from_failover_queue(ha,sp);
338 spin_unlock_irqrestore(&ha->list_lock, flags);
342 del_from_pending_queue(struct scsi_qla_host * ha, srb_t * sp)
346 spin_lock_irqsave(&ha->list_lock, flags);
348 __del_from_pending_queue(ha,sp);
350 spin_unlock_irqrestore(&ha->list_lock, flags);