Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]

Diff markup

Differences between /linux/drivers/scsi/qla4xxx/ql4_os.c (Version 2.6.25) and /linux/drivers/scsi/qla4xxx/ql4_os.c (Version 2.6.11.8)


  1 /*                                                  1 
  2  * QLogic iSCSI HBA Driver                        
  3  * Copyright (c)  2003-2006 QLogic Corporation    
  4  *                                                
  5  * See LICENSE.qla4xxx for copyright and licen    
  6  */                                               
  7 #include <linux/moduleparam.h>                    
  8                                                   
  9 #include <scsi/scsi_tcq.h>                        
 10 #include <scsi/scsicam.h>                         
 11                                                   
 12 #include "ql4_def.h"                              
 13 #include "ql4_version.h"                          
 14 #include "ql4_glbl.h"                             
 15 #include "ql4_dbg.h"                              
 16 #include "ql4_inline.h"                           
 17                                                   
 18 /*                                                
 19  * Driver version                                 
 20  */                                               
 21 static char qla4xxx_version_str[40];              
 22                                                   
 23 /*                                                
 24  * SRB allocation cache                           
 25  */                                               
 26 static struct kmem_cache *srb_cachep;             
 27                                                   
 28 /*                                                
 29  * Module parameter information and variables     
 30  */                                               
 31 int ql4xdiscoverywait = 60;                       
 32 module_param(ql4xdiscoverywait, int, S_IRUGO |    
 33 MODULE_PARM_DESC(ql4xdiscoverywait, "Discovery    
 34 int ql4xdontresethba = 0;                         
 35 module_param(ql4xdontresethba, int, S_IRUGO |     
 36 MODULE_PARM_DESC(ql4xdontresethba,                
 37                  "Dont reset the HBA when the     
 38                  " default it will reset hba :    
 39                  " set to 1 to avoid resetting    
 40                                                   
 41 int ql4xextended_error_logging = 0; /* 0 = off    
 42 module_param(ql4xextended_error_logging, int,     
 43 MODULE_PARM_DESC(ql4xextended_error_logging,      
 44                  "Option to enable extended er    
 45                  "Default is 0 - no logging, 1    
 46                                                   
 47 int ql4_mod_unload = 0;                           
 48                                                   
 49 /*                                                
 50  * SCSI host template entry points                
 51  */                                               
 52 static void qla4xxx_config_dma_addressing(stru    
 53                                                   
 54 /*                                                
 55  * iSCSI template entry points                    
 56  */                                               
 57 static int qla4xxx_tgt_dscvr(struct Scsi_Host     
 58                              enum iscsi_tgt_ds    
 59                              struct sockaddr *    
 60 static int qla4xxx_conn_get_param(struct iscsi    
 61                                   enum iscsi_p    
 62 static int qla4xxx_sess_get_param(struct iscsi    
 63                                   enum iscsi_p    
 64 static int qla4xxx_host_get_param(struct Scsi_    
 65                                   enum iscsi_h    
 66 static void qla4xxx_recovery_timedout(struct i    
 67                                                   
 68 /*                                                
 69  * SCSI host template entry points                
 70  */                                               
 71 static int qla4xxx_queuecommand(struct scsi_cm    
 72                                 void (*done) (    
 73 static int qla4xxx_eh_device_reset(struct scsi    
 74 static int qla4xxx_eh_host_reset(struct scsi_c    
 75 static int qla4xxx_slave_alloc(struct scsi_dev    
 76 static int qla4xxx_slave_configure(struct scsi    
 77 static void qla4xxx_slave_destroy(struct scsi_    
 78 static void qla4xxx_scan_start(struct Scsi_Hos    
 79                                                   
 80 static struct scsi_host_template qla4xxx_drive    
 81         .module                 = THIS_MODULE,    
 82         .name                   = DRIVER_NAME,    
 83         .proc_name              = DRIVER_NAME,    
 84         .queuecommand           = qla4xxx_queu    
 85                                                   
 86         .eh_device_reset_handler = qla4xxx_eh_    
 87         .eh_host_reset_handler  = qla4xxx_eh_h    
 88                                                   
 89         .slave_configure        = qla4xxx_slav    
 90         .slave_alloc            = qla4xxx_slav    
 91         .slave_destroy          = qla4xxx_slav    
 92                                                   
 93         .scan_finished          = iscsi_scan_f    
 94         .scan_start             = qla4xxx_scan    
 95                                                   
 96         .this_id                = -1,             
 97         .cmd_per_lun            = 3,              
 98         .use_clustering         = ENABLE_CLUST    
 99         .sg_tablesize           = SG_ALL,         
100                                                   
101         .max_sectors            = 0xFFFF,         
102 };                                                
103                                                   
104 static struct iscsi_transport qla4xxx_iscsi_tr    
105         .owner                  = THIS_MODULE,    
106         .name                   = DRIVER_NAME,    
107         .caps                   = CAP_FW_DB |     
108                                   CAP_DATA_PAT    
109         .param_mask             = ISCSI_CONN_P    
110                                   ISCSI_TARGET    
111         .host_param_mask        = ISCSI_HOST_H    
112                                   ISCSI_HOST_I    
113                                   ISCSI_HOST_I    
114         .sessiondata_size       = sizeof(struc    
115         .host_template          = &qla4xxx_dri    
116                                                   
117         .tgt_dscvr              = qla4xxx_tgt_    
118         .get_conn_param         = qla4xxx_conn    
119         .get_session_param      = qla4xxx_sess    
120         .get_host_param         = qla4xxx_host    
121         .session_recovery_timedout = qla4xxx_r    
122 };                                                
123                                                   
124 static struct scsi_transport_template *qla4xxx    
125                                                   
126 static void qla4xxx_recovery_timedout(struct i    
127 {                                                 
128         struct ddb_entry *ddb_entry = session-    
129         struct scsi_qla_host *ha = ddb_entry->    
130                                                   
131         if (atomic_read(&ddb_entry->state) !=     
132                 atomic_set(&ddb_entry->state,     
133                                                   
134                 DEBUG2(printk("scsi%ld: %s: in    
135                               "of (%d) secs ex    
136                               ha->host_no, __f    
137                               ha->port_down_re    
138                                                   
139                 DEBUG2(printk("scsi%ld: %s: sc    
140                               "flags = 0x%lx\n    
141                               ha->host_no, __f    
142                 queue_work(ha->dpc_thread, &ha    
143         }                                         
144 }                                                 
145                                                   
146 static int qla4xxx_host_get_param(struct Scsi_    
147                                   enum iscsi_h    
148 {                                                 
149         struct scsi_qla_host *ha = to_qla_host    
150         int len;                                  
151                                                   
152         switch (param) {                          
153         case ISCSI_HOST_PARAM_HWADDRESS:          
154                 len = sysfs_format_mac(buf, ha    
155                 break;                            
156         case ISCSI_HOST_PARAM_IPADDRESS:          
157                 len = sprintf(buf, "%d.%d.%d.%    
158                               ha->ip_address[1    
159                               ha->ip_address[3    
160                 break;                            
161         case ISCSI_HOST_PARAM_INITIATOR_NAME:     
162                 len = sprintf(buf, "%s\n", ha-    
163                 break;                            
164         default:                                  
165                 return -ENOSYS;                   
166         }                                         
167                                                   
168         return len;                               
169 }                                                 
170                                                   
171 static int qla4xxx_sess_get_param(struct iscsi    
172                                   enum iscsi_p    
173 {                                                 
174         struct ddb_entry *ddb_entry = sess->dd    
175         int len;                                  
176                                                   
177         switch (param) {                          
178         case ISCSI_PARAM_TARGET_NAME:             
179                 len = snprintf(buf, PAGE_SIZE     
180                                ddb_entry->iscs    
181                 break;                            
182         case ISCSI_PARAM_TPGT:                    
183                 len = sprintf(buf, "%u\n", ddb    
184                 break;                            
185         default:                                  
186                 return -ENOSYS;                   
187         }                                         
188                                                   
189         return len;                               
190 }                                                 
191                                                   
192 static int qla4xxx_conn_get_param(struct iscsi    
193                                   enum iscsi_p    
194 {                                                 
195         struct iscsi_cls_session *session;        
196         struct ddb_entry *ddb_entry;              
197         int len;                                  
198                                                   
199         session = iscsi_dev_to_session(conn->d    
200         ddb_entry = session->dd_data;             
201                                                   
202         switch (param) {                          
203         case ISCSI_PARAM_CONN_PORT:               
204                 len = sprintf(buf, "%hu\n", dd    
205                 break;                            
206         case ISCSI_PARAM_CONN_ADDRESS:            
207                 /* TODO: what are the ipv6 bit    
208                 len = sprintf(buf, "%u.%u.%u.%    
209                               NIPQUAD(ddb_entr    
210                 break;                            
211         default:                                  
212                 return -ENOSYS;                   
213         }                                         
214                                                   
215         return len;                               
216 }                                                 
217                                                   
218 static int qla4xxx_tgt_dscvr(struct Scsi_Host     
219                              enum iscsi_tgt_ds    
220                              struct sockaddr *    
221 {                                                 
222         struct scsi_qla_host *ha;                 
223         struct sockaddr_in *addr;                 
224         struct sockaddr_in6 *addr6;               
225         int ret = 0;                              
226                                                   
227         ha = (struct scsi_qla_host *) shost->h    
228                                                   
229         switch (type) {                           
230         case ISCSI_TGT_DSCVR_SEND_TARGETS:        
231                 if (dst_addr->sa_family == AF_    
232                         addr = (struct sockadd    
233                         if (qla4xxx_send_tgts(    
234                                                   
235                                 ret = -EIO;       
236                 } else if (dst_addr->sa_family    
237                         /*                        
238                          * TODO: fix qla4xxx_s    
239                          */                       
240                         addr6 = (struct sockad    
241                         if (qla4xxx_send_tgts(    
242                                                   
243                                 ret = -EIO;       
244                 } else                            
245                         ret = -ENOSYS;            
246                 break;                            
247         default:                                  
248                 ret = -ENOSYS;                    
249         }                                         
250         return ret;                               
251 }                                                 
252                                                   
253 void qla4xxx_destroy_sess(struct ddb_entry *dd    
254 {                                                 
255         if (!ddb_entry->sess)                     
256                 return;                           
257                                                   
258         if (ddb_entry->conn) {                    
259                 atomic_set(&ddb_entry->state,     
260                 iscsi_remove_session(ddb_entry    
261         }                                         
262         iscsi_free_session(ddb_entry->sess);      
263 }                                                 
264                                                   
265 int qla4xxx_add_sess(struct ddb_entry *ddb_ent    
266 {                                                 
267         int err;                                  
268                                                   
269         ddb_entry->sess->recovery_tmo = ddb_en    
270         err = iscsi_add_session(ddb_entry->ses    
271         if (err) {                                
272                 DEBUG2(printk(KERN_ERR "Could     
273                 return err;                       
274         }                                         
275                                                   
276         ddb_entry->conn = iscsi_create_conn(dd    
277         if (!ddb_entry->conn) {                   
278                 iscsi_remove_session(ddb_entry    
279                 DEBUG2(printk(KERN_ERR "Could     
280                 return -ENOMEM;                   
281         }                                         
282                                                   
283         /* finally ready to go */                 
284         iscsi_unblock_session(ddb_entry->sess)    
285         return 0;                                 
286 }                                                 
287                                                   
288 struct ddb_entry *qla4xxx_alloc_sess(struct sc    
289 {                                                 
290         struct ddb_entry *ddb_entry;              
291         struct iscsi_cls_session *sess;           
292                                                   
293         sess = iscsi_alloc_session(ha->host, &    
294         if (!sess)                                
295                 return NULL;                      
296                                                   
297         ddb_entry = sess->dd_data;                
298         memset(ddb_entry, 0, sizeof(*ddb_entry    
299         ddb_entry->ha = ha;                       
300         ddb_entry->sess = sess;                   
301         return ddb_entry;                         
302 }                                                 
303                                                   
304 static void qla4xxx_scan_start(struct Scsi_Hos    
305 {                                                 
306         struct scsi_qla_host *ha = shost_priv(    
307         struct ddb_entry *ddb_entry, *ddbtemp;    
308                                                   
309         /* finish setup of sessions that were     
310         list_for_each_entry_safe(ddb_entry, dd    
311                 if (ddb_entry->fw_ddb_device_s    
312                         qla4xxx_add_sess(ddb_e    
313         }                                         
314 }                                                 
315                                                   
316 /*                                                
317  * Timer routines                                 
318  */                                               
319                                                   
320 static void qla4xxx_start_timer(struct scsi_ql    
321                                 unsigned long     
322 {                                                 
323         DEBUG(printk("scsi: %s: Starting timer    
324                      __func__, ha->host->host_    
325         init_timer(&ha->timer);                   
326         ha->timer.expires = jiffies + interval    
327         ha->timer.data = (unsigned long)ha;       
328         ha->timer.function = (void (*)(unsigne    
329         add_timer(&ha->timer);                    
330         ha->timer_active = 1;                     
331 }                                                 
332                                                   
333 static void qla4xxx_stop_timer(struct scsi_qla    
334 {                                                 
335         del_timer_sync(&ha->timer);               
336         ha->timer_active = 0;                     
337 }                                                 
338                                                   
339 /***                                              
340  * qla4xxx_mark_device_missing - mark a device    
341  * @ha: Pointer to host adapter structure.        
342  * @ddb_entry: Pointer to device database entr    
343  *                                                
344  * This routine marks a device missing and res    
345  **/                                              
346 void qla4xxx_mark_device_missing(struct scsi_q    
347                                  struct ddb_en    
348 {                                                 
349         atomic_set(&ddb_entry->state, DDB_STAT    
350         DEBUG3(printk("scsi%d:%d:%d: index [%d    
351                       ha->host_no, ddb_entry->    
352                       ddb_entry->fw_ddb_index)    
353         iscsi_block_session(ddb_entry->sess);     
354         iscsi_conn_error(ddb_entry->conn, ISCS    
355 }                                                 
356                                                   
357 static struct srb* qla4xxx_get_new_srb(struct     
358                                        struct     
359                                        struct     
360                                        void (*    
361 {                                                 
362         struct srb *srb;                          
363                                                   
364         srb = mempool_alloc(ha->srb_mempool, G    
365         if (!srb)                                 
366                 return srb;                       
367                                                   
368         atomic_set(&srb->ref_count, 1);           
369         srb->ha = ha;                             
370         srb->ddb = ddb_entry;                     
371         srb->cmd = cmd;                           
372         srb->flags = 0;                           
373         cmd->SCp.ptr = (void *)srb;               
374         cmd->scsi_done = done;                    
375                                                   
376         return srb;                               
377 }                                                 
378                                                   
379 static void qla4xxx_srb_free_dma(struct scsi_q    
380 {                                                 
381         struct scsi_cmnd *cmd = srb->cmd;         
382                                                   
383         if (srb->flags & SRB_DMA_VALID) {         
384                 scsi_dma_unmap(cmd);              
385                 srb->flags &= ~SRB_DMA_VALID;     
386         }                                         
387         cmd->SCp.ptr = NULL;                      
388 }                                                 
389                                                   
390 void qla4xxx_srb_compl(struct scsi_qla_host *h    
391 {                                                 
392         struct scsi_cmnd *cmd = srb->cmd;         
393                                                   
394         qla4xxx_srb_free_dma(ha, srb);            
395                                                   
396         mempool_free(srb, ha->srb_mempool);       
397                                                   
398         cmd->scsi_done(cmd);                      
399 }                                                 
400                                                   
401 /**                                               
402  * qla4xxx_queuecommand - scsi layer issues sc    
403  * @cmd: Pointer to Linux's SCSI command struc    
404  * @done_fn: Function that the driver calls to    
405  *      that the command has been processed.      
406  *                                                
407  * Remarks:                                       
408  * This routine is invoked by Linux to send a     
409  * The mid-level driver tries to ensure that q    
410  * invoked concurrently with itself or the int    
411  * the interrupt handler may call this routine    
412  * completion handling).   Unfortunely, it som    
413  * in interrupt context which is a big NO! NO!    
414  **/                                              
415 static int qla4xxx_queuecommand(struct scsi_cm    
416                                 void (*done)(s    
417 {                                                 
418         struct scsi_qla_host *ha = to_qla_host    
419         struct ddb_entry *ddb_entry = cmd->dev    
420         struct iscsi_cls_session *sess = ddb_e    
421         struct srb *srb;                          
422         int rval;                                 
423                                                   
424         if (!sess) {                              
425                 cmd->result = DID_IMM_RETRY <<    
426                 goto qc_fail_command;             
427         }                                         
428                                                   
429         rval = iscsi_session_chkready(sess);      
430         if (rval) {                               
431                 cmd->result = rval;               
432                 goto qc_fail_command;             
433         }                                         
434                                                   
435         if (atomic_read(&ddb_entry->state) !=     
436                 if (atomic_read(&ddb_entry->st    
437                         cmd->result = DID_NO_C    
438                         goto qc_fail_command;     
439                 }                                 
440                 goto qc_host_busy;                
441         }                                         
442                                                   
443         if (test_bit(DPC_RESET_HA_INTR, &ha->d    
444                 goto qc_host_busy;                
445                                                   
446         spin_unlock_irq(ha->host->host_lock);     
447                                                   
448         srb = qla4xxx_get_new_srb(ha, ddb_entr    
449         if (!srb)                                 
450                 goto qc_host_busy_lock;           
451                                                   
452         rval = qla4xxx_send_command_to_isp(ha,    
453         if (rval != QLA_SUCCESS)                  
454                 goto qc_host_busy_free_sp;        
455                                                   
456         spin_lock_irq(ha->host->host_lock);       
457         return 0;                                 
458                                                   
459 qc_host_busy_free_sp:                             
460         qla4xxx_srb_free_dma(ha, srb);            
461         mempool_free(srb, ha->srb_mempool);       
462                                                   
463 qc_host_busy_lock:                                
464         spin_lock_irq(ha->host->host_lock);       
465                                                   
466 qc_host_busy:                                     
467         return SCSI_MLQUEUE_HOST_BUSY;            
468                                                   
469 qc_fail_command:                                  
470         done(cmd);                                
471                                                   
472         return 0;                                 
473 }                                                 
474                                                   
475 /**                                               
476  * qla4xxx_mem_free - frees memory allocated t    
477  * @ha: Pointer to host adapter structure.        
478  *                                                
479  * Frees memory previously allocated by qla4xx    
480  **/                                              
481 static void qla4xxx_mem_free(struct scsi_qla_h    
482 {                                                 
483         if (ha->queues)                           
484                 dma_free_coherent(&ha->pdev->d    
485                                   ha->queues_d    
486                                                   
487         ha->queues_len = 0;                       
488         ha->queues = NULL;                        
489         ha->queues_dma = 0;                       
490         ha->request_ring = NULL;                  
491         ha->request_dma = 0;                      
492         ha->response_ring = NULL;                 
493         ha->response_dma = 0;                     
494         ha->shadow_regs = NULL;                   
495         ha->shadow_regs_dma = 0;                  
496                                                   
497         /* Free srb pool. */                      
498         if (ha->srb_mempool)                      
499                 mempool_destroy(ha->srb_mempoo    
500                                                   
501         ha->srb_mempool = NULL;                   
502                                                   
503         /* release io space registers  */         
504         if (ha->reg)                              
505                 iounmap(ha->reg);                 
506         pci_release_regions(ha->pdev);            
507 }                                                 
508                                                   
509 /**                                               
510  * qla4xxx_mem_alloc - allocates memory for us    
511  * @ha: Pointer to host adapter structure         
512  *                                                
513  * Allocates DMA memory for request and respon    
514  * for srbs.                                      
515  **/                                              
516 static int qla4xxx_mem_alloc(struct scsi_qla_h    
517 {                                                 
518         unsigned long align;                      
519                                                   
520         /* Allocate contiguous block of DMA me    
521         ha->queues_len = ((REQUEST_QUEUE_DEPTH    
522                           (RESPONSE_QUEUE_DEPT    
523                           sizeof(struct shadow    
524                           MEM_ALIGN_VALUE +       
525                           (PAGE_SIZE - 1)) & ~    
526         ha->queues = dma_alloc_coherent(&ha->p    
527                                         &ha->q    
528         if (ha->queues == NULL) {                 
529                 dev_warn(&ha->pdev->dev,          
530                         "Memory Allocation fai    
531                                                   
532                 goto mem_alloc_error_exit;        
533         }                                         
534         memset(ha->queues, 0, ha->queues_len);    
535                                                   
536         /*                                        
537          * As per RISC alignment requirements     
538          * multiple of the request-ring size (    
539          */                                       
540         align = 0;                                
541         if ((unsigned long)ha->queues_dma & (M    
542                 align = MEM_ALIGN_VALUE - ((un    
543                                            (ME    
544                                                   
545         /* Update request and response queue p    
546         ha->request_dma = ha->queues_dma + ali    
547         ha->request_ring = (struct queue_entry    
548         ha->response_dma = ha->queues_dma + al    
549                 (REQUEST_QUEUE_DEPTH * QUEUE_S    
550         ha->response_ring = (struct queue_entr    
551                                                   
552                                                   
553         ha->shadow_regs_dma = ha->queues_dma +    
554                 (REQUEST_QUEUE_DEPTH * QUEUE_S    
555                 (RESPONSE_QUEUE_DEPTH * QUEUE_    
556         ha->shadow_regs = (struct shadow_regs     
557                                                   
558                                                   
559                                                   
560                                                   
561                                                   
562         /* Allocate memory for srb pool. */       
563         ha->srb_mempool = mempool_create(SRB_M    
564                                          mempo    
565         if (ha->srb_mempool == NULL) {            
566                 dev_warn(&ha->pdev->dev,          
567                         "Memory Allocation fai    
568                                                   
569                 goto mem_alloc_error_exit;        
570         }                                         
571                                                   
572         return QLA_SUCCESS;                       
573                                                   
574 mem_alloc_error_exit:                             
575         qla4xxx_mem_free(ha);                     
576         return QLA_ERROR;                         
577 }                                                 
578                                                   
579 /**                                               
580  * qla4xxx_timer - checks every second for wor    
581  * @ha: Pointer to host adapter structure.        
582  **/                                              
583 static void qla4xxx_timer(struct scsi_qla_host    
584 {                                                 
585         struct ddb_entry *ddb_entry, *dtemp;      
586         int start_dpc = 0;                        
587                                                   
588         /* Search for relogin's to time-out an    
589         list_for_each_entry_safe(ddb_entry, dt    
590                 /* Count down time between sen    
591                 if (adapter_up(ha) &&             
592                     !test_bit(DF_RELOGIN, &ddb    
593                     atomic_read(&ddb_entry->st    
594                         if (atomic_read(&ddb_e    
595                             INVALID_ENTRY) {      
596                                 if (atomic_rea    
597                                                   
598                                         atomic    
599                                                   
600                                                   
601                                         set_bi    
602                                                   
603                                         set_bi    
604                                         DEBUG2    
605                                                   
606                                                   
607                                                   
608                                 } else            
609                                         atomic    
610                                                   
611                         }                         
612                 }                                 
613                                                   
614                 /* Wait for relogin to timeout    
615                 if (atomic_read(&ddb_entry->re    
616                     (atomic_dec_and_test(&ddb_    
617                         /*                        
618                          * If the relogin time    
619                          * still NOT ONLINE th    
620                          */                       
621                         if (atomic_read(&ddb_e    
622                             DDB_STATE_ONLINE &    
623                             ddb_entry->fw_ddb_    
624                             DDB_DS_SESSION_FAI    
625                                 /* Reset retry    
626                                 atomic_inc(&dd    
627                                 DEBUG2(printk(    
628                                                   
629                                                   
630                                                   
631                                                   
632                                                   
633                                                   
634                                         );        
635                                 start_dpc++;      
636                                 DEBUG(printk("    
637                                              "    
638                                              "    
639                                              h    
640                                              d    
641                                              d    
642                                              d    
643                                         );        
644                                                   
645                                 atomic_set(&dd    
646                                            ddb    
647                         }                         
648                 }                                 
649         }                                         
650                                                   
651         /* Check for heartbeat interval. */       
652         if (ha->firmware_options & FWOPT_HEART    
653             ha->heartbeat_interval != 0) {        
654                 ha->seconds_since_last_heartbe    
655                 if (ha->seconds_since_last_hea    
656                     ha->heartbeat_interval + 2    
657                         set_bit(DPC_RESET_HA,     
658         }                                         
659                                                   
660                                                   
661         /* Wakeup the dpc routine for this ada    
662         if ((start_dpc ||                         
663              test_bit(DPC_RESET_HA, &ha->dpc_f    
664              test_bit(DPC_RETRY_RESET_HA, &ha-    
665              test_bit(DPC_RELOGIN_DEVICE, &ha-    
666              test_bit(DPC_RESET_HA_DESTROY_DDB    
667              test_bit(DPC_RESET_HA_INTR, &ha->    
668              test_bit(DPC_GET_DHCP_IP_ADDR, &h    
669              test_bit(DPC_AEN, &ha->dpc_flags)    
670              ha->dpc_thread) {                    
671                 DEBUG2(printk("scsi%ld: %s: sc    
672                               " - dpc flags =     
673                               ha->host_no, __f    
674                 queue_work(ha->dpc_thread, &ha    
675         }                                         
676                                                   
677         /* Reschedule timer thread to call us     
678         mod_timer(&ha->timer, jiffies + HZ);      
679                                                   
680         DEBUG2(ha->seconds_since_last_intr++);    
681 }                                                 
682                                                   
683 /**                                               
684  * qla4xxx_cmd_wait - waits for all outstandin    
685  * @ha: Pointer to host adapter structure.        
686  *                                                
687  * This routine stalls the driver until all ou    
688  * Caller must release the Hardware Lock prior    
689  **/                                              
690 static int qla4xxx_cmd_wait(struct scsi_qla_ho    
691 {                                                 
692         uint32_t index = 0;                       
693         int stat = QLA_SUCCESS;                   
694         unsigned long flags;                      
695         struct scsi_cmnd *cmd;                    
696         int wait_cnt = WAIT_CMD_TOV;    /*        
697                                          * Ini    
698                                          * exp    
699                                          * ASA    
700                                          */       
701                                                   
702         while (wait_cnt) {                        
703                 spin_lock_irqsave(&ha->hardwar    
704                 /* Find a command that hasn't     
705                 for (index = 0; index < ha->ho    
706                         cmd = scsi_host_find_t    
707                         if (cmd != NULL)          
708                                 break;            
709                 }                                 
710                 spin_unlock_irqrestore(&ha->ha    
711                                                   
712                 /* If No Commands are pending,    
713                 if (index == ha->host->can_que    
714                         break;                    
715                 }                                 
716                                                   
717                 /* If we timed out on waiting     
718                  * return ERROR.                  
719                  */                               
720                 wait_cnt--;                       
721                 if (wait_cnt == 0)                
722                         stat = QLA_ERROR;         
723                 else {                            
724                         msleep(1000);             
725                 }                                 
726         }                       /* End of Whil    
727                                                   
728         return stat;                              
729 }                                                 
730                                                   
731 void qla4xxx_hw_reset(struct scsi_qla_host *ha    
732 {                                                 
733         uint32_t ctrl_status;                     
734         unsigned long flags = 0;                  
735                                                   
736         DEBUG2(printk(KERN_ERR "scsi%ld: %s\n"    
737                                                   
738         spin_lock_irqsave(&ha->hardware_lock,     
739                                                   
740         /*                                        
741          * If the SCSI Reset Interrupt bit is     
742          * Otherwise, the Soft Reset won't wor    
743          */                                       
744         ctrl_status = readw(&ha->reg->ctrl_sta    
745         if ((ctrl_status & CSR_SCSI_RESET_INTR    
746                 writel(set_rmask(CSR_SCSI_RESE    
747                                                   
748         /* Issue Soft Reset */                    
749         writel(set_rmask(CSR_SOFT_RESET), &ha-    
750         readl(&ha->reg->ctrl_status);             
751                                                   
752         spin_unlock_irqrestore(&ha->hardware_l    
753 }                                                 
754                                                   
755 /**                                               
756  * qla4xxx_soft_reset - performs soft reset.      
757  * @ha: Pointer to host adapter structure.        
758  **/                                              
759 int qla4xxx_soft_reset(struct scsi_qla_host *h    
760 {                                                 
761         uint32_t max_wait_time;                   
762         unsigned long flags = 0;                  
763         int status = QLA_ERROR;                   
764         uint32_t ctrl_status;                     
765                                                   
766         qla4xxx_hw_reset(ha);                     
767                                                   
768         /* Wait until the Network Reset Intr b    
769         max_wait_time = RESET_INTR_TOV;           
770         do {                                      
771                 spin_lock_irqsave(&ha->hardwar    
772                 ctrl_status = readw(&ha->reg->    
773                 spin_unlock_irqrestore(&ha->ha    
774                                                   
775                 if ((ctrl_status & CSR_NET_RES    
776                         break;                    
777                                                   
778                 msleep(1000);                     
779         } while ((--max_wait_time));              
780                                                   
781         if ((ctrl_status & CSR_NET_RESET_INTR)    
782                 DEBUG2(printk(KERN_WARNING        
783                               "scsi%ld: Networ    
784                               "Network functio    
785                               ha->host_no));      
786                 spin_lock_irqsave(&ha->hardwar    
787                 writel(set_rmask(CSR_NET_RESET    
788                 readl(&ha->reg->ctrl_status);     
789                 spin_unlock_irqrestore(&ha->ha    
790         }                                         
791                                                   
792         /* Wait until the firmware tells us th    
793         max_wait_time = SOFT_RESET_TOV;           
794         do {                                      
795                 spin_lock_irqsave(&ha->hardwar    
796                 ctrl_status = readw(&ha->reg->    
797                 spin_unlock_irqrestore(&ha->ha    
798                                                   
799                 if ((ctrl_status & CSR_SOFT_RE    
800                         status = QLA_SUCCESS;     
801                         break;                    
802                 }                                 
803                                                   
804                 msleep(1000);                     
805         } while ((--max_wait_time));              
806                                                   
807         /*                                        
808          * Also, make sure that the SCSI Reset    
809          * after the soft reset has taken plac    
810          */                                       
811         spin_lock_irqsave(&ha->hardware_lock,     
812         ctrl_status = readw(&ha->reg->ctrl_sta    
813         if ((ctrl_status & CSR_SCSI_RESET_INTR    
814                 writel(set_rmask(CSR_SCSI_RESE    
815                 readl(&ha->reg->ctrl_status);     
816         }                                         
817         spin_unlock_irqrestore(&ha->hardware_l    
818                                                   
819         /* If soft reset fails then most proba    
820          * function is also enabled.              
821          * Since the initialization is sequent    
822          * wont be able to acknowledge the sof    
823          * Issue a force soft reset to workaro    
824          */                                       
825         if (max_wait_time == 0) {                 
826                 /* Issue Force Soft Reset */      
827                 spin_lock_irqsave(&ha->hardwar    
828                 writel(set_rmask(CSR_FORCE_SOF    
829                 readl(&ha->reg->ctrl_status);     
830                 spin_unlock_irqrestore(&ha->ha    
831                 /* Wait until the firmware tel    
832                 max_wait_time = SOFT_RESET_TOV    
833                 do {                              
834                         spin_lock_irqsave(&ha-    
835                         ctrl_status = readw(&h    
836                         spin_unlock_irqrestore    
837                                                   
838                         if ((ctrl_status & CSR    
839                                 status = QLA_S    
840                                 break;            
841                         }                         
842                                                   
843                         msleep(1000);             
844                 } while ((--max_wait_time));      
845         }                                         
846                                                   
847         return status;                            
848 }                                                 
849                                                   
850 /**                                               
851  * qla4xxx_flush_active_srbs - returns all out    
852  * @ha: Pointer to host adapter structure.        
853  *                                                
854  * This routine is called just prior to a HARD    
855  * outstanding commands back to the Operating     
856  * Caller should make sure that the following     
857  * before this calling routine: Hardware lock,    
858  **/                                              
859 static void qla4xxx_flush_active_srbs(struct s    
860 {                                                 
861         struct srb *srb;                          
862         int i;                                    
863         unsigned long flags;                      
864                                                   
865         spin_lock_irqsave(&ha->hardware_lock,     
866         for (i = 0; i < ha->host->can_queue; i    
867                 srb = qla4xxx_del_from_active_    
868                 if (srb != NULL) {                
869                         srb->cmd->result = DID    
870                         qla4xxx_srb_compl(ha,     
871                 }                                 
872         }                                         
873         spin_unlock_irqrestore(&ha->hardware_l    
874                                                   
875 }                                                 
876                                                   
877 /**                                               
878  * qla4xxx_recover_adapter - recovers adapter     
879  * @ha: Pointer to host adapter structure.        
880  * @renew_ddb_list: Indicates what to do with     
881  *                                                
882  * renew_ddb_list value can be 0=preserve ddb     
883  * ddb list.                                      
884  **/                                              
885 static int qla4xxx_recover_adapter(struct scsi    
886                                 uint8_t renew_    
887 {                                                 
888         int status;                               
889                                                   
890         /* Stall incoming I/O until we are don    
891         clear_bit(AF_ONLINE, &ha->flags);         
892                                                   
893         DEBUG2(printk("scsi%ld: %s calling qla    
894                       __func__));                 
895                                                   
896         /* Wait for outstanding commands to co    
897          * Stalls the driver for max 30 secs      
898          */                                       
899         status = qla4xxx_cmd_wait(ha);            
900                                                   
901         qla4xxx_disable_intrs(ha);                
902                                                   
903         /* Flush any pending ddb changed AENs     
904         qla4xxx_process_aen(ha, FLUSH_DDB_CHAN    
905                                                   
906         /* Reset the firmware.  If successful,    
907          * returns with ISP interrupts enabled    
908          */                                       
909         if (status == QLA_SUCCESS) {              
910                 DEBUG2(printk("scsi%ld: %s - P    
911                               ha->host_no, __f    
912                 qla4xxx_flush_active_srbs(ha);    
913                 if (ql4xxx_lock_drvr_wait(ha)     
914                         status = qla4xxx_soft_    
915                 else                              
916                         status = QLA_ERROR;       
917         }                                         
918                                                   
919         /* Flush any pending ddb changed AENs     
920         qla4xxx_process_aen(ha, FLUSH_DDB_CHAN    
921                                                   
922         /* Re-initialize firmware. If successf    
923          * with ISP interrupts enabled */         
924         if (status == QLA_SUCCESS) {              
925                 DEBUG2(printk("scsi%ld: %s - I    
926                               ha->host_no, __f    
927                                                   
928                 /* If successful, AF_ONLINE fl    
929                  * qla4xxx_initialize_adapter     
930                 status = qla4xxx_initialize_ad    
931         }                                         
932                                                   
933         /* Failed adapter initialization?         
934          * Retry reset_ha only if invoked via     
935         if ((test_bit(AF_ONLINE, &ha->flags) =    
936             (test_bit(DPC_RESET_HA, &ha->dpc_f    
937                 /* Adapter initialization fail    
938                  * resetting the ha */            
939                 if (!test_bit(DPC_RETRY_RESET_    
940                         ha->retry_reset_ha_cnt    
941                         DEBUG2(printk("scsi%ld    
942                                       "(%d) mo    
943                                       ha->retr    
944                         set_bit(DPC_RETRY_RESE    
945                         status = QLA_ERROR;       
946                 } else {                          
947                         if (ha->retry_reset_ha    
948                                 /* Schedule an    
949                                 ha->retry_rese    
950                                 DEBUG2(printk(    
951                                                   
952                                                   
953                                                   
954                                 status = QLA_E    
955                         }                         
956                                                   
957                         if (ha->retry_reset_ha    
958                                 /* Recover ada    
959                                  * Adapter DEA    
960                                 DEBUG2(printk(    
961                                                   
962                                                   
963                                 qla4xxx_flush_    
964                                 clear_bit(DPC_    
965                                 clear_bit(DPC_    
966                                 clear_bit(DPC_    
967                                           &ha-    
968                                 status = QLA_E    
969                         }                         
970                 }                                 
971         } else {                                  
972                 clear_bit(DPC_RESET_HA, &ha->d    
973                 clear_bit(DPC_RESET_HA_DESTROY    
974                 clear_bit(DPC_RETRY_RESET_HA,     
975         }                                         
976                                                   
977         ha->adapter_error_count++;                
978                                                   
979         if (status == QLA_SUCCESS)                
980                 qla4xxx_enable_intrs(ha);         
981                                                   
982         DEBUG2(printk("scsi%ld: recover adapte    
983         return status;                            
984 }                                                 
985                                                   
986 /**                                               
987  * qla4xxx_do_dpc - dpc routine                   
988  * @data: in our case pointer to adapter struc    
989  *                                                
990  * This routine is a task that is schedule by     
991  * to perform the background processing for in    
992  * on a task queue that is consumed whenever t    
993  * so you can do anything (i.e. put the proces    
994  * the mid-level tries to sleep when it reache    
995  * "host->can_queue". This can cause a panic i    
996  **/                                              
997 static void qla4xxx_do_dpc(struct work_struct     
998 {                                                 
999         struct scsi_qla_host *ha =                
1000                 container_of(work, struct scs    
1001         struct ddb_entry *ddb_entry, *dtemp;     
1002         int status = QLA_ERROR;                  
1003                                                  
1004         DEBUG2(printk("scsi%ld: %s: DPC handl    
1005                 "flags = 0x%08lx, dpc_flags =    
1006                 ha->host_no, __func__, ha->fl    
1007                 readw(&ha->reg->ctrl_status))    
1008                                                  
1009         /* Initialization not yet finished. D    
1010         if (!test_bit(AF_INIT_DONE, &ha->flag    
1011                 return;                          
1012                                                  
1013         if (adapter_up(ha) ||                    
1014             test_bit(DPC_RESET_HA, &ha->dpc_f    
1015             test_bit(DPC_RESET_HA_INTR, &ha->    
1016             test_bit(DPC_RESET_HA_DESTROY_DDB    
1017                 if (test_bit(DPC_RESET_HA_DES    
1018                         test_bit(DPC_RESET_HA    
1019                         qla4xxx_recover_adapt    
1020                                                  
1021                 if (test_bit(DPC_RESET_HA_INT    
1022                         uint8_t wait_time = R    
1023                                                  
1024                         while ((readw(&ha->re    
1025                                 (CSR_SOFT_RES    
1026                                 if (--wait_ti    
1027                                         break    
1028                                 msleep(1000);    
1029                         }                        
1030                         if (wait_time == 0)      
1031                                 DEBUG2(printk    
1032                                                  
1033                                                  
1034                         qla4xxx_flush_active_    
1035                         if (ql4xxx_lock_drvr_    
1036                                 qla4xxx_proce    
1037                                 status = qla4    
1038                                                  
1039                         }                        
1040                         clear_bit(DPC_RESET_H    
1041                         if (status == QLA_SUC    
1042                                 qla4xxx_enabl    
1043                 }                                
1044         }                                        
1045                                                  
1046         /* ---- process AEN? --- */              
1047         if (test_and_clear_bit(DPC_AEN, &ha->    
1048                 qla4xxx_process_aen(ha, PROCE    
1049                                                  
1050         /* ---- Get DHCP IP Address? --- */      
1051         if (test_and_clear_bit(DPC_GET_DHCP_I    
1052                 qla4xxx_get_dhcp_ip_address(h    
1053                                                  
1054         /* ---- relogin device? --- */           
1055         if (adapter_up(ha) &&                    
1056             test_and_clear_bit(DPC_RELOGIN_DE    
1057                 list_for_each_entry_safe(ddb_    
1058                                          &ha-    
1059                         if (test_and_clear_bi    
1060                             atomic_read(&ddb_    
1061                                 qla4xxx_relog    
1062                                                  
1063                         /*                       
1064                          * If mbx cmd times o    
1065                          * in continuing furt    
1066                          * With large no of t    
1067                          * the system.           
1068                          */                      
1069                         if (test_bit(DPC_RESE    
1070                                 printk(KERN_W    
1071                                        "need     
1072                                        ha->ho    
1073                                 break;           
1074                         }                        
1075                 }                                
1076         }                                        
1077 }                                                
1078                                                  
1079 /**                                              
1080  * qla4xxx_free_adapter - release the adapter    
1081  * @ha: pointer to adapter structure             
1082  **/                                             
1083 static void qla4xxx_free_adapter(struct scsi_    
1084 {                                                
1085                                                  
1086         if (test_bit(AF_INTERRUPTS_ON, &ha->f    
1087                 /* Turn-off interrupts on the    
1088                 qla4xxx_disable_intrs(ha);       
1089         }                                        
1090                                                  
1091         /* Kill the kernel thread for this ho    
1092         if (ha->dpc_thread)                      
1093                 destroy_workqueue(ha->dpc_thr    
1094                                                  
1095         /* Issue Soft Reset to put firmware i    
1096         if (ql4xxx_lock_drvr_wait(ha) == QLA_    
1097                 qla4xxx_hw_reset(ha);            
1098                                                  
1099         /* Remove timer thread, if present */    
1100         if (ha->timer_active)                    
1101                 qla4xxx_stop_timer(ha);          
1102                                                  
1103         /* Detach interrupts */                  
1104         if (test_and_clear_bit(AF_IRQ_ATTACHE    
1105                 free_irq(ha->pdev->irq, ha);     
1106                                                  
1107         /* free extra memory */                  
1108         qla4xxx_mem_free(ha);                    
1109                                                  
1110         pci_disable_device(ha->pdev);            
1111                                                  
1112 }                                                
1113                                                  
1114 /***                                             
1115  * qla4xxx_iospace_config - maps registers       
1116  * @ha: pointer to adapter structure             
1117  *                                               
1118  * This routines maps HBA's registers from th    
1119  * into the kernel virtual address space for     
1120  **/                                             
1121 static int qla4xxx_iospace_config(struct scsi    
1122 {                                                
1123         unsigned long pio, pio_len, pio_flags    
1124         unsigned long mmio, mmio_len, mmio_fl    
1125                                                  
1126         pio = pci_resource_start(ha->pdev, 0)    
1127         pio_len = pci_resource_len(ha->pdev,     
1128         pio_flags = pci_resource_flags(ha->pd    
1129         if (pio_flags & IORESOURCE_IO) {         
1130                 if (pio_len < MIN_IOBASE_LEN)    
1131                         dev_warn(&ha->pdev->d    
1132                                 "Invalid PCI     
1133                         pio = 0;                 
1134                 }                                
1135         } else {                                 
1136                 dev_warn(&ha->pdev->dev, "reg    
1137                 pio = 0;                         
1138         }                                        
1139                                                  
1140         /* Use MMIO operations for all access    
1141         mmio = pci_resource_start(ha->pdev, 1    
1142         mmio_len = pci_resource_len(ha->pdev,    
1143         mmio_flags = pci_resource_flags(ha->p    
1144                                                  
1145         if (!(mmio_flags & IORESOURCE_MEM)) {    
1146                 dev_err(&ha->pdev->dev,          
1147                         "region #0 not an MMI    
1148                                                  
1149                 goto iospace_error_exit;         
1150         }                                        
1151         if (mmio_len < MIN_IOBASE_LEN) {         
1152                 dev_err(&ha->pdev->dev,          
1153                         "Invalid PCI mem regi    
1154                 goto iospace_error_exit;         
1155         }                                        
1156                                                  
1157         if (pci_request_regions(ha->pdev, DRI    
1158                 dev_warn(&ha->pdev->dev,         
1159                         "Failed to reserve PI    
1160                                                  
1161                 goto iospace_error_exit;         
1162         }                                        
1163                                                  
1164         ha->pio_address = pio;                   
1165         ha->pio_length = pio_len;                
1166         ha->reg = ioremap(mmio, MIN_IOBASE_LE    
1167         if (!ha->reg) {                          
1168                 dev_err(&ha->pdev->dev,          
1169                         "cannot remap MMIO, a    
1170                                                  
1171                 goto iospace_error_exit;         
1172         }                                        
1173                                                  
1174         return 0;                                
1175                                                  
1176 iospace_error_exit:                              
1177         return -ENOMEM;                          
1178 }                                                
1179                                                  
1180 /**                                              
1181  * qla4xxx_probe_adapter - callback function     
1182  * @pdev: pointer to pci_dev structure           
1183  * @pci_device_id: pointer to pci_device entr    
1184  *                                               
1185  * This routine will probe for Qlogic 4xxx iS    
1186  * It returns zero if successful. It also ini    
1187  * the driver.                                   
1188  **/                                             
1189 static int __devinit qla4xxx_probe_adapter(st    
1190                                            co    
1191 {                                                
1192         int ret = -ENODEV, status;               
1193         struct Scsi_Host *host;                  
1194         struct scsi_qla_host *ha;                
1195         uint8_t init_retry_count = 0;            
1196         char buf[34];                            
1197                                                  
1198         if (pci_enable_device(pdev))             
1199                 return -1;                       
1200                                                  
1201         host = scsi_host_alloc(&qla4xxx_drive    
1202         if (host == NULL) {                      
1203                 printk(KERN_WARNING              
1204                        "qla4xxx: Couldn't all    
1205                 goto probe_disable_device;       
1206         }                                        
1207                                                  
1208         /* Clear our data area */                
1209         ha = (struct scsi_qla_host *) host->h    
1210         memset(ha, 0, sizeof(*ha));              
1211                                                  
1212         /* Save the information from PCI BIOS    
1213         ha->pdev = pdev;                         
1214         ha->host = host;                         
1215         ha->host_no = host->host_no;             
1216                                                  
1217         /* Configure PCI I/O space. */           
1218         ret = qla4xxx_iospace_config(ha);        
1219         if (ret)                                 
1220                 goto probe_failed;               
1221                                                  
1222         dev_info(&ha->pdev->dev, "Found an IS    
1223                    pdev->device, pdev->irq, h    
1224                                                  
1225         qla4xxx_config_dma_addressing(ha);       
1226                                                  
1227         /* Initialize lists and spinlocks. */    
1228         INIT_LIST_HEAD(&ha->ddb_list);           
1229         INIT_LIST_HEAD(&ha->free_srb_q);         
1230                                                  
1231         mutex_init(&ha->mbox_sem);               
1232                                                  
1233         spin_lock_init(&ha->hardware_lock);      
1234                                                  
1235         /* Allocate dma buffers */               
1236         if (qla4xxx_mem_alloc(ha)) {             
1237                 dev_warn(&ha->pdev->dev,         
1238                            "[ERROR] Failed to    
1239                                                  
1240                 ret = -ENOMEM;                   
1241                 goto probe_failed;               
1242         }                                        
1243                                                  
1244         /*                                       
1245          * Initialize the Host adapter reques    
1246          * firmware                              
1247          * NOTE: interrupts enabled upon succ    
1248          */                                      
1249         status = qla4xxx_initialize_adapter(h    
1250         while (status == QLA_ERROR && init_re    
1251                 DEBUG2(printk("scsi: %s: retr    
1252                               "(%d)\n", __fun    
1253                 qla4xxx_soft_reset(ha);          
1254                 status = qla4xxx_initialize_a    
1255         }                                        
1256         if (status == QLA_ERROR) {               
1257                 dev_warn(&ha->pdev->dev, "Fai    
1258                                                  
1259                 ret = -ENODEV;                   
1260                 goto probe_failed;               
1261         }                                        
1262                                                  
1263         host->cmd_per_lun = 3;                   
1264         host->max_channel = 0;                   
1265         host->max_lun = MAX_LUNS - 1;            
1266         host->max_id = MAX_TARGETS;              
1267         host->max_cmd_len = IOCB_MAX_CDB_LEN;    
1268         host->can_queue = MAX_SRBS ;             
1269         host->transportt = qla4xxx_scsi_trans    
1270                                                  
1271         ret = scsi_init_shared_tag_map(host,     
1272         if (ret) {                               
1273                 dev_warn(&ha->pdev->dev, "scs    
1274                 goto probe_failed;               
1275         }                                        
1276                                                  
1277         /* Startup the kernel thread for this    
1278         DEBUG2(printk("scsi: %s: Starting ker    
1279                       "qla4xxx_dpc\n", __func    
1280         sprintf(buf, "qla4xxx_%lu_dpc", ha->h    
1281         ha->dpc_thread = create_singlethread_    
1282         if (!ha->dpc_thread) {                   
1283                 dev_warn(&ha->pdev->dev, "Una    
1284                 ret = -ENODEV;                   
1285                 goto probe_failed;               
1286         }                                        
1287         INIT_WORK(&ha->dpc_work, qla4xxx_do_d    
1288                                                  
1289         ret = request_irq(pdev->irq, qla4xxx_    
1290                           IRQF_DISABLED | IRQ    
1291         if (ret) {                               
1292                 dev_warn(&ha->pdev->dev, "Fai    
1293                         " already in use.\n",    
1294                 goto probe_failed;               
1295         }                                        
1296         set_bit(AF_IRQ_ATTACHED, &ha->flags);    
1297         host->irq = pdev->irq;                   
1298         DEBUG(printk("scsi%d: irq %d attached    
1299                                                  
1300         qla4xxx_enable_intrs(ha);                
1301                                                  
1302         /* Start timer thread. */                
1303         qla4xxx_start_timer(ha, qla4xxx_timer    
1304                                                  
1305         set_bit(AF_INIT_DONE, &ha->flags);       
1306                                                  
1307         pci_set_drvdata(pdev, ha);               
1308                                                  
1309         ret = scsi_add_host(host, &pdev->dev)    
1310         if (ret)                                 
1311                 goto probe_failed;               
1312                                                  
1313         printk(KERN_INFO                         
1314                " QLogic iSCSI HBA Driver vers    
1315                "  QLogic ISP%04x @ %s, host#=    
1316                qla4xxx_version_str, ha->pdev-    
1317                ha->host_no, ha->firmware_vers    
1318                ha->patch_number, ha->build_nu    
1319         scsi_scan_host(host);                    
1320         return 0;                                
1321                                                  
1322 probe_failed:                                    
1323         qla4xxx_free_adapter(ha);                
1324         scsi_host_put(ha->host);                 
1325                                                  
1326 probe_disable_device:                            
1327         pci_disable_device(pdev);                
1328                                                  
1329         return ret;                              
1330 }                                                
1331                                                  
1332 /**                                              
1333  * qla4xxx_remove_adapter - calback function     
1334  * @pci_dev: PCI device pointer                  
1335  **/                                             
1336 static void __devexit qla4xxx_remove_adapter(    
1337 {                                                
1338         struct scsi_qla_host *ha;                
1339                                                  
1340         ha = pci_get_drvdata(pdev);              
1341                                                  
1342         qla4xxx_disable_intrs(ha);               
1343                                                  
1344         while (test_bit(DPC_RESET_HA_INTR, &h    
1345                 ssleep(1);                       
1346                                                  
1347         /* remove devs from iscsi_sessions to    
1348         qla4xxx_free_ddb_list(ha);               
1349                                                  
1350         scsi_remove_host(ha->host);              
1351                                                  
1352         qla4xxx_free_adapter(ha);                
1353                                                  
1354         scsi_host_put(ha->host);                 
1355                                                  
1356         pci_set_drvdata(pdev, NULL);             
1357 }                                                
1358                                                  
1359 /**                                              
1360  * qla4xxx_config_dma_addressing() - Configur    
1361  * @ha: HA context                               
1362  *                                               
1363  * At exit, the @ha's flags.enable_64bit_addr    
1364  * supported addressing method.                  
1365  */                                              
1366 static void qla4xxx_config_dma_addressing(str    
1367 {                                                
1368         int retval;                              
1369                                                  
1370         /* Update our PCI device dma_mask for    
1371         if (pci_set_dma_mask(ha->pdev, DMA_64    
1372                 if (pci_set_consistent_dma_ma    
1373                         dev_dbg(&ha->pdev->de    
1374                                   "Failed to     
1375                                    "using 32     
1376                         retval = pci_set_cons    
1377                                                  
1378                 }                                
1379         } else                                   
1380                 retval = pci_set_dma_mask(ha-    
1381 }                                                
1382                                                  
1383 static int qla4xxx_slave_alloc(struct scsi_de    
1384 {                                                
1385         struct iscsi_cls_session *sess = star    
1386         struct ddb_entry *ddb = sess->dd_data    
1387                                                  
1388         sdev->hostdata = ddb;                    
1389         sdev->tagged_supported = 1;              
1390         scsi_activate_tcq(sdev, sdev->host->c    
1391         return 0;                                
1392 }                                                
1393                                                  
1394 static int qla4xxx_slave_configure(struct scs    
1395 {                                                
1396         sdev->tagged_supported = 1;              
1397         return 0;                                
1398 }                                                
1399                                                  
1400 static void qla4xxx_slave_destroy(struct scsi    
1401 {                                                
1402         scsi_deactivate_tcq(sdev, 1);            
1403 }                                                
1404                                                  
1405 /**                                              
1406  * qla4xxx_del_from_active_array - returns an    
1407  * @ha: Pointer to host adapter structure.       
1408  * @index: index into to the active_array        
1409  *                                               
1410  * This routine removes and returns the srb a    
1411  **/                                             
1412 struct srb * qla4xxx_del_from_active_array(st    
1413 {                                                
1414         struct srb *srb = NULL;                  
1415         struct scsi_cmnd *cmd;                   
1416                                                  
1417         if (!(cmd = scsi_host_find_tag(ha->ho    
1418                 return srb;                      
1419                                                  
1420         if (!(srb = (struct srb *)cmd->host_s    
1421                 return srb;                      
1422                                                  
1423         /* update counters */                    
1424         if (srb->flags & SRB_DMA_VALID) {        
1425                 ha->req_q_count += srb->iocb_    
1426                 ha->iocb_cnt -= srb->iocb_cnt    
1427                 if (srb->cmd)                    
1428                         srb->cmd->host_scribb    
1429         }                                        
1430         return srb;                              
1431 }                                                
1432                                                  
1433 /**                                              
1434  * qla4xxx_eh_wait_on_command - waits for com    
1435  * @ha: actual ha whose done queue will conta    
1436  * @cmd: Scsi Command to wait on.                
1437  *                                               
1438  * This routine waits for the command to be r    
1439  * for some max time.                            
1440  **/                                             
1441 static int qla4xxx_eh_wait_on_command(struct     
1442                                       struct     
1443 {                                                
1444         int done = 0;                            
1445         struct srb *rp;                          
1446         uint32_t max_wait_time = EH_WAIT_CMD_    
1447                                                  
1448         do {                                     
1449                 /* Checking to see if its ret    
1450                 rp = (struct srb *) cmd->SCp.    
1451                 if (rp == NULL) {                
1452                         done++;                  
1453                         break;                   
1454                 }                                
1455                                                  
1456                 msleep(2000);                    
1457         } while (max_wait_time--);               
1458                                                  
1459         return done;                             
1460 }                                                
1461                                                  
1462 /**                                              
1463  * qla4xxx_wait_for_hba_online - waits for HB    
1464  * @ha: Pointer to host adapter structure        
1465  **/                                             
1466 static int qla4xxx_wait_for_hba_online(struct    
1467 {                                                
1468         unsigned long wait_online;               
1469                                                  
1470         wait_online = jiffies + (30 * HZ);       
1471         while (time_before(jiffies, wait_onli    
1472                                                  
1473                 if (adapter_up(ha))              
1474                         return QLA_SUCCESS;      
1475                 else if (ha->retry_reset_ha_c    
1476                         return QLA_ERROR;        
1477                                                  
1478                 msleep(2000);                    
1479         }                                        
1480                                                  
1481         return QLA_ERROR;                        
1482 }                                                
1483                                                  
1484 /**                                              
1485  * qla4xxx_eh_wait_for_active_target_commands    
1486  * @ha: pointer to to HBA                        
1487  * @t: target id                                 
1488  * @l: lun id                                    
1489  *                                               
1490  * This function waits for all outstanding co    
1491  * returns 0 if all pending commands are retu    
1492  **/                                             
1493 static int qla4xxx_eh_wait_for_active_target_    
1494                                                  
1495 {                                                
1496         int cnt;                                 
1497         int status = 0;                          
1498         struct scsi_cmnd *cmd;                   
1499                                                  
1500         /*                                       
1501          * Waiting for all commands for the d    
1502          * array                                 
1503          */                                      
1504         for (cnt = 0; cnt < ha->host->can_que    
1505                 cmd = scsi_host_find_tag(ha->    
1506                 if (cmd && cmd->device->id ==    
1507                         if (!qla4xxx_eh_wait_    
1508                                 status++;        
1509                                 break;           
1510                         }                        
1511                 }                                
1512         }                                        
1513         return status;                           
1514 }                                                
1515                                                  
1516 /**                                              
1517  * qla4xxx_eh_device_reset - callback for tar    
1518  * @cmd: Pointer to Linux's SCSI command stru    
1519  *                                               
1520  * This routine is called by the Linux OS to     
1521  * specified target.                             
1522  **/                                             
1523 static int qla4xxx_eh_device_reset(struct scs    
1524 {                                                
1525         struct scsi_qla_host *ha = to_qla_hos    
1526         struct ddb_entry *ddb_entry = cmd->de    
1527         struct srb *sp;                          
1528         int ret = FAILED, stat;                  
1529                                                  
1530         sp = (struct srb *) cmd->SCp.ptr;        
1531         if (!sp || !ddb_entry)                   
1532                 return ret;                      
1533                                                  
1534         dev_info(&ha->pdev->dev,                 
1535                    "scsi%ld:%d:%d:%d: DEVICE     
1536                    cmd->device->channel, cmd-    
1537                                                  
1538         DEBUG2(printk(KERN_INFO                  
1539                       "scsi%ld: DEVICE_RESET     
1540                       "dpc_flags=%lx, status=    
1541                       cmd, jiffies, cmd->time    
1542                       ha->dpc_flags, cmd->res    
1543                                                  
1544         /* FIXME: wait for hba to go online *    
1545         stat = qla4xxx_reset_lun(ha, ddb_entr    
1546         if (stat != QLA_SUCCESS) {               
1547                 dev_info(&ha->pdev->dev, "DEV    
1548                 goto eh_dev_reset_done;          
1549         }                                        
1550                                                  
1551         /* Send marker. */                       
1552         ha->marker_needed = 1;                   
1553                                                  
1554         /*                                       
1555          * If we are coming down the EH path,    
1556          * for the device.                       
1557          */                                      
1558         if (cmd->device->host->shost_state ==    
1559                 if (qla4xxx_eh_wait_for_activ    
1560                                                  
1561                                                  
1562                         dev_info(&ha->pdev->d    
1563                                    "DEVICE RE    
1564                                    "commands.    
1565                         goto eh_dev_reset_don    
1566                 }                                
1567         }                                        
1568                                                  
1569         dev_info(&ha->pdev->dev,                 
1570                    "scsi(%ld:%d:%d:%d): DEVIC    
1571                    ha->host_no, cmd->device->    
1572                    cmd->device->lun);            
1573                                                  
1574         ret = SUCCESS;                           
1575                                                  
1576 eh_dev_reset_done:                               
1577                                                  
1578         return ret;                              
1579 }                                                
1580                                                  
1581 /**                                              
1582  * qla4xxx_eh_host_reset - kernel callback       
1583  * @cmd: Pointer to Linux's SCSI command stru    
1584  *                                               
1585  * This routine is invoked by the Linux kerne    
1586  * recovery on the specified adapter.            
1587  **/                                             
1588 static int qla4xxx_eh_host_reset(struct scsi_    
1589 {                                                
1590         int return_status = FAILED;              
1591         struct scsi_qla_host *ha;                
1592                                                  
1593         ha = (struct scsi_qla_host *) cmd->de    
1594                                                  
1595         dev_info(&ha->pdev->dev,                 
1596                    "scsi(%ld:%d:%d:%d): ADAPT    
1597                    cmd->device->channel, cmd-    
1598                                                  
1599         if (qla4xxx_wait_for_hba_online(ha) !    
1600                 DEBUG2(printk("scsi%ld:%d: %s    
1601                               "DEAD.\n", ha->    
1602                               __func__));        
1603                                                  
1604                 return FAILED;                   
1605         }                                        
1606                                                  
1607         /* make sure the dpc thread is stoppe    
1608         clear_bit(AF_ONLINE, &ha->flags);        
1609         flush_workqueue(ha->dpc_thread);         
1610                                                  
1611         if (qla4xxx_recover_adapter(ha, PRESE    
1612                 return_status = SUCCESS;         
1613                                                  
1614         dev_info(&ha->pdev->dev, "HOST RESET     
1615                    return_status == FAILED ?     
1616                                                  
1617         return return_status;                    
1618 }                                                
1619                                                  
1620                                                  
1621 static struct pci_device_id qla4xxx_pci_tbl[]    
1622         {                                        
1623                 .vendor         = PCI_VENDOR_    
1624                 .device         = PCI_DEVICE_    
1625                 .subvendor      = PCI_ANY_ID,    
1626                 .subdevice      = PCI_ANY_ID,    
1627         },                                       
1628         {                                        
1629                 .vendor         = PCI_VENDOR_    
1630                 .device         = PCI_DEVICE_    
1631                 .subvendor      = PCI_ANY_ID,    
1632                 .subdevice      = PCI_ANY_ID,    
1633         },                                       
1634         {                                        
1635                 .vendor         = PCI_VENDOR_    
1636                 .device         = PCI_DEVICE_    
1637                 .subvendor      = PCI_ANY_ID,    
1638                 .subdevice      = PCI_ANY_ID,    
1639         },                                       
1640         {0, 0},                                  
1641 };                                               
1642 MODULE_DEVICE_TABLE(pci, qla4xxx_pci_tbl);       
1643                                                  
1644 static struct pci_driver qla4xxx_pci_driver =    
1645         .name           = DRIVER_NAME,           
1646         .id_table       = qla4xxx_pci_tbl,       
1647         .probe          = qla4xxx_probe_adapt    
1648         .remove         = qla4xxx_remove_adap    
1649 };                                               
1650                                                  
1651 static int __init qla4xxx_module_init(void)      
1652 {                                                
1653         int ret;                                 
1654                                                  
1655         /* Allocate cache for SRBs. */           
1656         srb_cachep = kmem_cache_create("qla4x    
1657                                        SLAB_H    
1658         if (srb_cachep == NULL) {                
1659                 printk(KERN_ERR                  
1660                        "%s: Unable to allocat    
1661                        "Failing load!\n", DRI    
1662                 ret = -ENOMEM;                   
1663                 goto no_srp_cache;               
1664         }                                        
1665                                                  
1666         /* Derive version string. */             
1667         strcpy(qla4xxx_version_str, QLA4XXX_D    
1668         if (ql4xextended_error_logging)          
1669                 strcat(qla4xxx_version_str, "    
1670                                                  
1671         qla4xxx_scsi_transport =                 
1672                 iscsi_register_transport(&qla    
1673         if (!qla4xxx_scsi_transport){            
1674                 ret = -ENODEV;                   
1675                 goto release_srb_cache;          
1676         }                                        
1677                                                  
1678         ret = pci_register_driver(&qla4xxx_pc    
1679         if (ret)                                 
1680                 goto unregister_transport;       
1681                                                  
1682         printk(KERN_INFO "QLogic iSCSI HBA Dr    
1683         return 0;                                
1684                                                  
1685 unregister_transport:                            
1686         iscsi_unregister_transport(&qla4xxx_i    
1687 release_srb_cache:                               
1688         kmem_cache_destroy(srb_cachep);          
1689 no_srp_cache:                                    
1690         return ret;                              
1691 }                                                
1692                                                  
1693 static void __exit qla4xxx_module_exit(void)     
1694 {                                                
1695         ql4_mod_unload = 1;                      
1696         pci_unregister_driver(&qla4xxx_pci_dr    
1697         iscsi_unregister_transport(&qla4xxx_i    
1698         kmem_cache_destroy(srb_cachep);          
1699 }                                                
1700                                                  
1701 module_init(qla4xxx_module_init);                
1702 module_exit(qla4xxx_module_exit);                
1703                                                  
1704 MODULE_AUTHOR("QLogic Corporation");             
1705 MODULE_DESCRIPTION("QLogic iSCSI HBA Driver")    
1706 MODULE_LICENSE("GPL");                           
1707 MODULE_VERSION(QLA4XXX_DRIVER_VERSION);          
1708                                                  
  This page was automatically generated by the LXR engine.