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.31.13)


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