blob: 7e038e4107a5d28597b0e30fcb30591f9b6413bb [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <scsi/scsi_tcq.h>
16#include <scsi/scsicam.h>
17#include <scsi/scsi_transport.h>
18#include <scsi/scsi_transport_fc.h>
19
20/*
21 * Driver version
22 */
23char qla2x00_version_str[40];
24
25/*
26 * SRB allocation cache
27 */
Christoph Lametere18b8902006-12-06 20:33:20 -080028static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030int ql2xlogintimeout = 20;
31module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
34
Andrew Vasqueza7b61842007-05-07 07:42:59 -070035int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070038 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 "a PORT-DOWN status.");
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041int ql2xplogiabsentdevice;
42module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070045 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int ql2xloginretrycount = 0;
49module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
52
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053int ql2xallocfwdump = 1;
54module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
59
Andrew Vasquez11010fe2006-10-06 09:54:59 -070060int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070061module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070062MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070063 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static void qla2x00_free_device(scsi_qla_host_t *);
67
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070068int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070069module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
70MODULE_PARM_DESC(ql2xfdmienable,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
73
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070074#define MAX_Q_DEPTH 32
75static int ql2xmaxqdepth = MAX_Q_DEPTH;
76module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
77MODULE_PARM_DESC(ql2xmaxqdepth,
78 "Maximum queue depth to report for target devices.");
79
80int ql2xqfullrampup = 120;
81module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
82MODULE_PARM_DESC(ql2xqfullrampup,
83 "Number of seconds to wait to begin to ramp-up the queue "
84 "depth for a device after a queue-full condition has been "
85 "detected. Default is 120 seconds.");
86
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070087int ql2xiidmaenable=1;
88module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
89MODULE_PARM_DESC(ql2xiidmaenable,
90 "Enables iIDMA settings "
91 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
92
Anirban Chakraborty73208df2008-12-09 16:45:39 -080093int ql2xmaxqueues = 1;
94module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
95MODULE_PARM_DESC(ql2xmaxqueues,
96 "Enables MQ settings "
97 "Default is 1 for single queue. Set it to number \
98 of queues in MQ mode.");
Linus Torvalds1da177e2005-04-16 15:20:36 -070099/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700100 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700101 */
102static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500103static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800104static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
105static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500106static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700107static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700108 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700109static int qla2xxx_eh_abort(struct scsi_cmnd *);
110static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700111static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
113static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700115static int qla2x00_change_queue_depth(struct scsi_device *, int);
116static int qla2x00_change_queue_type(struct scsi_device *, int);
117
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700118struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700120 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700121 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700122
123 .eh_abort_handler = qla2xxx_eh_abort,
124 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700125 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700126 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
127 .eh_host_reset_handler = qla2xxx_eh_host_reset,
128
129 .slave_configure = qla2xxx_slave_configure,
130
131 .slave_alloc = qla2xxx_slave_alloc,
132 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700133 .scan_finished = qla2xxx_scan_finished,
134 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700135 .change_queue_depth = qla2x00_change_queue_depth,
136 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700137 .this_id = -1,
138 .cmd_per_lun = 3,
139 .use_clustering = ENABLE_CLUSTERING,
140 .sg_tablesize = SG_ALL,
141
142 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700143 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700144};
145
Linus Torvalds1da177e2005-04-16 15:20:36 -0700146static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700147struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700148
Linus Torvalds1da177e2005-04-16 15:20:36 -0700149/* TODO Convert to inlines
150 *
151 * Timer routines
152 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700153
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700154__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800155qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800157 init_timer(&vha->timer);
158 vha->timer.expires = jiffies + interval * HZ;
159 vha->timer.data = (unsigned long)vha;
160 vha->timer.function = (void (*)(unsigned long))func;
161 add_timer(&vha->timer);
162 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700163}
164
165static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800166qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700167{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800168 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169}
170
Adrian Bunka824ebb2008-01-17 09:02:15 -0800171static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800172qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800174 del_timer_sync(&vha->timer);
175 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700176}
177
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178static int qla2x00_do_dpc(void *data);
179
180static void qla2x00_rst_aen(scsi_qla_host_t *);
181
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800182static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
183 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800184static void qla2x00_mem_free(struct qla_hw_data *);
185static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700186
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800188static int qla2x00_alloc_queues(struct qla_hw_data *ha)
189{
190 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_queues,
191 GFP_KERNEL);
192 if (!ha->req_q_map) {
193 qla_printk(KERN_WARNING, ha,
194 "Unable to allocate memory for request queue ptrs\n");
195 goto fail_req_map;
196 }
197
198 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_queues,
199 GFP_KERNEL);
200 if (!ha->rsp_q_map) {
201 qla_printk(KERN_WARNING, ha,
202 "Unable to allocate memory for response queue ptrs\n");
203 goto fail_rsp_map;
204 }
205 set_bit(0, ha->rsp_qid_map);
206 set_bit(0, ha->req_qid_map);
207 return 1;
208
209fail_rsp_map:
210 kfree(ha->req_q_map);
211 ha->req_q_map = NULL;
212fail_req_map:
213 return -ENOMEM;
214}
215
216static void qla2x00_free_que(struct qla_hw_data *ha, struct req_que *req,
217 struct rsp_que *rsp)
218{
219 if (rsp && rsp->ring)
220 dma_free_coherent(&ha->pdev->dev,
221 (rsp->length + 1) * sizeof(response_t),
222 rsp->ring, rsp->dma);
223
224 kfree(rsp);
225 rsp = NULL;
226 if (req && req->ring)
227 dma_free_coherent(&ha->pdev->dev,
228 (req->length + 1) * sizeof(request_t),
229 req->ring, req->dma);
230
231 kfree(req);
232 req = NULL;
233}
234
235static void qla2x00_free_queues(struct qla_hw_data *ha)
236{
237 struct req_que *req;
238 struct rsp_que *rsp;
239 int cnt;
240
241 for (cnt = 0; cnt < ha->max_queues; cnt++) {
242 rsp = ha->rsp_q_map[cnt];
243 req = ha->req_q_map[cnt];
244 qla2x00_free_que(ha, req, rsp);
245 }
246 kfree(ha->rsp_q_map);
247 ha->rsp_q_map = NULL;
248
249 kfree(ha->req_q_map);
250 ha->req_q_map = NULL;
251}
252
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800254qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800256 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700257 static char *pci_bus_modes[] = {
258 "33", "66", "100", "133",
259 };
260 uint16_t pci_bus;
261
262 strcpy(str, "PCI");
263 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
264 if (pci_bus) {
265 strcat(str, "-X (");
266 strcat(str, pci_bus_modes[pci_bus]);
267 } else {
268 pci_bus = (ha->pci_attr & BIT_8) >> 8;
269 strcat(str, " (");
270 strcat(str, pci_bus_modes[pci_bus]);
271 }
272 strcat(str, " MHz)");
273
274 return (str);
275}
276
Andrew Vasquezfca29702005-07-06 10:31:47 -0700277static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800278qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700279{
280 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800281 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700282 uint32_t pci_bus;
283 int pcie_reg;
284
285 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
286 if (pcie_reg) {
287 char lwstr[6];
288 uint16_t pcie_lstat, lspeed, lwidth;
289
290 pcie_reg += 0x12;
291 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
292 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
293 lwidth = (pcie_lstat &
294 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
295
296 strcpy(str, "PCIe (");
297 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700298 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700299 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700300 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700301 else
302 strcat(str, "<unknown> ");
303 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
304 strcat(str, lwstr);
305
306 return str;
307 }
308
309 strcpy(str, "PCI");
310 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
311 if (pci_bus == 0 || pci_bus == 8) {
312 strcat(str, " (");
313 strcat(str, pci_bus_modes[pci_bus >> 3]);
314 } else {
315 strcat(str, "-X ");
316 if (pci_bus & BIT_2)
317 strcat(str, "Mode 2");
318 else
319 strcat(str, "Mode 1");
320 strcat(str, " (");
321 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
322 }
323 strcat(str, " MHz)");
324
325 return str;
326}
327
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800328static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800329qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800332 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700333
Linus Torvalds1da177e2005-04-16 15:20:36 -0700334 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
335 ha->fw_minor_version,
336 ha->fw_subminor_version);
337
338 if (ha->fw_attributes & BIT_9) {
339 strcat(str, "FLX");
340 return (str);
341 }
342
343 switch (ha->fw_attributes & 0xFF) {
344 case 0x7:
345 strcat(str, "EF");
346 break;
347 case 0x17:
348 strcat(str, "TP");
349 break;
350 case 0x37:
351 strcat(str, "IP");
352 break;
353 case 0x77:
354 strcat(str, "VI");
355 break;
356 default:
357 sprintf(un_str, "(%x)", ha->fw_attributes);
358 strcat(str, un_str);
359 break;
360 }
361 if (ha->fw_attributes & 0x100)
362 strcat(str, "X");
363
364 return (str);
365}
366
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800367static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800368qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700369{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800370 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700371
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800372 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
373 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700374 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700375}
376
377static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800378qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700379 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
380{
381 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800382 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700383
384 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
385 if (!sp)
386 return sp;
387
Andrew Vasquezfca29702005-07-06 10:31:47 -0700388 sp->fcport = fcport;
389 sp->cmd = cmd;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800390 sp->que = ha->req_q_map[0];
Andrew Vasquezfca29702005-07-06 10:31:47 -0700391 sp->flags = 0;
392 CMD_SP(cmd) = (void *)sp;
393 cmd->scsi_done = done;
394
395 return sp;
396}
397
Linus Torvalds1da177e2005-04-16 15:20:36 -0700398static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700399qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700400{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800401 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700402 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400403 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404 struct qla_hw_data *ha = vha->hw;
405 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700406 srb_t *sp;
407 int rval;
408
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800409 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Ju14e660e2007-09-20 14:07:36 -0700410 cmd->result = DID_REQUEUE << 16;
411 goto qc24_fail_command;
412 }
413
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400414 rval = fc_remote_port_chkready(rport);
415 if (rval) {
416 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700417 goto qc24_fail_command;
418 }
419
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800420 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500421 if (fcport->drport)
422 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800423
Andrew Vasquezfca29702005-07-06 10:31:47 -0700424 if (atomic_read(&fcport->state) != FCS_ONLINE) {
425 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800426 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700427 cmd->result = DID_NO_CONNECT << 16;
428 goto qc24_fail_command;
429 }
Mike Christie7b594132008-08-17 15:24:40 -0500430 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700431 }
432
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800433 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700434
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800435 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700436 if (!sp)
437 goto qc24_host_busy_lock;
438
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800439 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700440 if (rval != QLA_SUCCESS)
441 goto qc24_host_busy_free_sp;
442
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800443 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700444
445 return 0;
446
447qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800448 qla2x00_sp_free_dma(sp);
449 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700450
451qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800452 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700453 return SCSI_MLQUEUE_HOST_BUSY;
454
Mike Christie7b594132008-08-17 15:24:40 -0500455qc24_target_busy:
456 return SCSI_MLQUEUE_TARGET_BUSY;
457
Andrew Vasquezfca29702005-07-06 10:31:47 -0700458qc24_fail_command:
459 done(cmd);
460
461 return 0;
462}
463
464
Linus Torvalds1da177e2005-04-16 15:20:36 -0700465/*
466 * qla2x00_eh_wait_on_command
467 * Waits for the command to be returned by the Firmware for some
468 * max time.
469 *
470 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472 *
473 * Return:
474 * Not Found : 0
475 * Found : 1
476 */
477static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800478qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700479{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700480#define ABORT_POLLING_PERIOD 1000
481#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500482 unsigned long wait_iter = ABORT_WAIT_ITER;
483 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700484
f4f051e2005-04-17 15:02:26 -0500485 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700486 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700487
f4f051e2005-04-17 15:02:26 -0500488 if (--wait_iter)
489 break;
490 }
491 if (CMD_SP(cmd))
492 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700493
f4f051e2005-04-17 15:02:26 -0500494 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700495}
496
497/*
498 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700499 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700500 * <= MAX_RETRIES_OF_ISP_ABORT or
501 * finally HBA is disabled ie marked offline
502 *
503 * Input:
504 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700505 *
506 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507 * Does context switching-Release SPIN_LOCK
508 * (if any) before calling this routine.
509 *
510 * Return:
511 * Success (Adapter is online) : 0
512 * Failed (Adapter is offline/disabled) : 1
513 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800514int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800515qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700516{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700517 int return_status;
518 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800519 struct qla_hw_data *ha = vha->hw;
520 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700521
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700522 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800523 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
524 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
525 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
526 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700527
528 msleep(1000);
529 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800530 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700531 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532 else
533 return_status = QLA_FUNCTION_FAILED;
534
Linus Torvalds1da177e2005-04-16 15:20:36 -0700535 return (return_status);
536}
537
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700538int
539qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
540{
541 int return_status;
542 unsigned long wait_reset;
543 struct qla_hw_data *ha = vha->hw;
544 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
545
546 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
547 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
548 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
549 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
550 ha->dpc_active) && time_before(jiffies, wait_reset)) {
551
552 msleep(1000);
553
554 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
555 ha->flags.chip_reset_done)
556 break;
557 }
558 if (ha->flags.chip_reset_done)
559 return_status = QLA_SUCCESS;
560 else
561 return_status = QLA_FUNCTION_FAILED;
562
563 return return_status;
564}
565
Linus Torvalds1da177e2005-04-16 15:20:36 -0700566/*
567 * qla2x00_wait_for_loop_ready
568 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700569 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700570 * Input:
571 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700572 *
573 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 * Does context switching-Release SPIN_LOCK
575 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700576 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 *
578 * Return:
579 * Success (LOOP_READY) : 0
580 * Failed (LOOP_NOT_READY) : 1
581 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700582static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800583qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700584{
585 int return_status = QLA_SUCCESS;
586 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800587 struct qla_hw_data *ha = vha->hw;
588 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
590 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700591 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700592
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800593 while ((!atomic_read(&base_vha->loop_down_timer) &&
594 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
595 atomic_read(&base_vha->loop_state) != LOOP_READY) {
596 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700597 return_status = QLA_FUNCTION_FAILED;
598 break;
599 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700600 msleep(1000);
601 if (time_after_eq(jiffies, loop_timeout)) {
602 return_status = QLA_FUNCTION_FAILED;
603 break;
604 }
605 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700606 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700607}
608
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700609void
610qla2x00_abort_fcport_cmds(fc_port_t *fcport)
611{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800612 int cnt, que, id;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700613 unsigned long flags;
614 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800615 scsi_qla_host_t *vha = fcport->vha;
616 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800617 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700618
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800619 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800620 for (que = 0; que < QLA_MAX_HOST_QUES; que++) {
621 id = vha->req_ques[que];
622 req = ha->req_q_map[id];
623 if (!req)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700624 continue;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800625 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
626 sp = req->outstanding_cmds[cnt];
627 if (!sp)
628 continue;
629 if (sp->fcport != fcport)
630 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700631
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800632 spin_unlock_irqrestore(&ha->hardware_lock, flags);
633 if (ha->isp_ops->abort_command(vha, sp, req)) {
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700634 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800635 "Abort failed -- %lx\n",
636 sp->cmd->serial_number));
637 } else {
638 if (qla2x00_eh_wait_on_command(sp->cmd) !=
639 QLA_SUCCESS)
640 DEBUG2(qla_printk(KERN_WARNING, ha,
641 "Abort failed while waiting -- %lx\n",
642 sp->cmd->serial_number));
643 }
644 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700645 }
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700646 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800647 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700648}
649
Andrew Vasquez07db5182006-10-02 12:00:49 -0700650static void
651qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
652{
653 struct Scsi_Host *shost = cmnd->device->host;
654 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
655 unsigned long flags;
656
657 spin_lock_irqsave(shost->host_lock, flags);
658 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
659 spin_unlock_irqrestore(shost->host_lock, flags);
660 msleep(1000);
661 spin_lock_irqsave(shost->host_lock, flags);
662 }
663 spin_unlock_irqrestore(shost->host_lock, flags);
664 return;
665}
666
Linus Torvalds1da177e2005-04-16 15:20:36 -0700667/**************************************************************************
668* qla2xxx_eh_abort
669*
670* Description:
671* The abort function will abort the specified command.
672*
673* Input:
674* cmd = Linux SCSI command packet to be aborted.
675*
676* Returns:
677* Either SUCCESS or FAILED.
678*
679* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700680* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800682static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683qla2xxx_eh_abort(struct scsi_cmnd *cmd)
684{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800685 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500686 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800687 int ret, i;
f4f051e2005-04-17 15:02:26 -0500688 unsigned int id, lun;
689 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700690 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700691 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800692 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800693 struct req_que *req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800694 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700695
Andrew Vasquez07db5182006-10-02 12:00:49 -0700696 qla2x00_block_error_handler(cmd);
697
f4f051e2005-04-17 15:02:26 -0500698 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700699 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
Michael Reed2ea00202006-04-27 16:25:30 -0700701 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700702
f4f051e2005-04-17 15:02:26 -0500703 id = cmd->device->id;
704 lun = cmd->device->lun;
705 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800706 spt = (srb_t *) CMD_SP(cmd);
707 if (!spt)
708 return SUCCESS;
709 req = spt->que;
f4f051e2005-04-17 15:02:26 -0500710
711 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800712 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800713 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
714 sp = req->outstanding_cmds[i];
715
716 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500717 continue;
718
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800719 if (sp->cmd != cmd)
720 continue;
f4f051e2005-04-17 15:02:26 -0500721
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800722 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
723 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500724
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
726 if (ha->isp_ops->abort_command(vha, sp, req)) {
727 DEBUG2(printk("%s(%ld): abort_command "
728 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800729 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800730 } else {
731 DEBUG3(printk("%s(%ld): abort_command "
732 "mbx success.\n", __func__, vha->host_no));
733 wait = 1;
f4f051e2005-04-17 15:02:26 -0500734 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800735 spin_lock_irqsave(&ha->hardware_lock, flags);
736 break;
f4f051e2005-04-17 15:02:26 -0500737 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800738 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500739
740 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700741 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800742 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700743 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500744 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800745 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700746 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500747 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700748 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700749
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700750 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700751 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800752 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700753
f4f051e2005-04-17 15:02:26 -0500754 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700755}
756
Andrew Vasquez523ec772008-04-03 13:13:24 -0700757enum nexus_wait_type {
758 WAIT_HOST = 0,
759 WAIT_TARGET,
760 WAIT_LUN,
761};
762
Linus Torvalds1da177e2005-04-16 15:20:36 -0700763static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800764qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800765 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700766{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800767 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700768 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800769 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800770 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
Andrew Vasquez523ec772008-04-03 13:13:24 -0700772 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800773 if (!sp)
774 return status;
775
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800776 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800777 req = sp->que;
778 for (cnt = 1; status == QLA_SUCCESS &&
779 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
780 sp = req->outstanding_cmds[cnt];
781 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700782 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700783
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800784 if (vha->vp_idx != sp->fcport->vha->vp_idx)
785 continue;
786 match = 0;
787 switch (type) {
788 case WAIT_HOST:
789 match = 1;
790 break;
791 case WAIT_TARGET:
792 match = sp->cmd->device->id == t;
793 break;
794 case WAIT_LUN:
795 match = (sp->cmd->device->id == t &&
796 sp->cmd->device->lun == l);
797 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700798 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800799 if (!match)
800 continue;
801
802 spin_unlock_irqrestore(&ha->hardware_lock, flags);
803 status = qla2x00_eh_wait_on_command(sp->cmd);
804 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700807
808 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700809}
810
Andrew Vasquez523ec772008-04-03 13:13:24 -0700811static char *reset_errors[] = {
812 "HBA not online",
813 "HBA not ready",
814 "Task management failed",
815 "Waiting for command completions",
816};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Andrew Vasquez523ec772008-04-03 13:13:24 -0700818static int
819__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
820 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int))
821{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800822 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700823 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
824 int err;
825
826 qla2x00_block_error_handler(cmd);
827
828 if (!fcport)
829 return FAILED;
830
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800831 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
832 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700833
834 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800835 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700836 goto eh_reset_failed;
837 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800838 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700839 goto eh_reset_failed;
840 err = 2;
841 if (do_reset(fcport, cmd->device->lun) != QLA_SUCCESS)
842 goto eh_reset_failed;
843 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800845 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700846 goto eh_reset_failed;
847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800848 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
849 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700850
851 return SUCCESS;
852
853 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800854 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
855 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700856 reset_errors[err]);
857 return FAILED;
858}
859
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800860static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
862{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800863 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
864 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865
Andrew Vasquez523ec772008-04-03 13:13:24 -0700866 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
867 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700868}
869
Linus Torvalds1da177e2005-04-16 15:20:36 -0700870static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700871qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700872{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800873 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
874 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700875
Andrew Vasquez523ec772008-04-03 13:13:24 -0700876 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
877 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700878}
879
Linus Torvalds1da177e2005-04-16 15:20:36 -0700880/**************************************************************************
881* qla2xxx_eh_bus_reset
882*
883* Description:
884* The bus reset function will reset the bus and abort any executing
885* commands.
886*
887* Input:
888* cmd = Linux SCSI command packet of the command that cause the
889* bus reset.
890*
891* Returns:
892* SUCCESS/FAILURE (defined as macro in scsi.h).
893*
894**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800895static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
897{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800898 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500899 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700900 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500901 unsigned int id, lun;
902 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800903 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700904
Andrew Vasquez07db5182006-10-02 12:00:49 -0700905 qla2x00_block_error_handler(cmd);
906
f4f051e2005-04-17 15:02:26 -0500907 id = cmd->device->id;
908 lun = cmd->device->lun;
909 serial = cmd->serial_number;
910
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700911 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500912 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700913
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800914 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800915 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500919 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700920 }
921
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800922 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
923 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500924 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 }
f4f051e2005-04-17 15:02:26 -0500926 if (ret == FAILED)
927 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700928
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700929 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800930 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -0700931 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700932 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933
f4f051e2005-04-17 15:02:26 -0500934eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800935 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -0500936 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937
f4f051e2005-04-17 15:02:26 -0500938 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939}
940
941/**************************************************************************
942* qla2xxx_eh_host_reset
943*
944* Description:
945* The reset function will reset the Adapter.
946*
947* Input:
948* cmd = Linux SCSI command packet of the command that cause the
949* adapter reset.
950*
951* Returns:
952* Either SUCCESS or FAILED.
953*
954* Note:
955**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800956static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700957qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
958{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800959 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500960 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800961 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700962 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500963 unsigned int id, lun;
964 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800965 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800966 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700967
Andrew Vasquez07db5182006-10-02 12:00:49 -0700968 qla2x00_block_error_handler(cmd);
969
f4f051e2005-04-17 15:02:26 -0500970 id = cmd->device->id;
971 lun = cmd->device->lun;
972 serial = cmd->serial_number;
973
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700974 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500975 return ret;
976
Linus Torvalds1da177e2005-04-16 15:20:36 -0700977 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800978 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700979
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800980 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500981 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
983 /*
984 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700985 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -0700986 * be completed and then issue big hammer.Otherwise
987 * it may cause I/O failure as big hammer marks the
988 * devices as lost kicking of the port_down_timer
989 * while dpc is stuck for the mailbox to complete.
990 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 qla2x00_wait_for_loop_ready(vha);
992 if (vha != base_vha) {
993 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -0500994 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800995 } else {
996 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
997 if (qla2x00_abort_isp(base_vha)) {
998 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
999 /* failed. schedule dpc to try */
1000 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1001
1002 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1003 goto eh_host_reset_lock;
1004 }
1005 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001006 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001007
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001008 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001009 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001010 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001011 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012
f4f051e2005-04-17 15:02:26 -05001013eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001014 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1015 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001016
f4f051e2005-04-17 15:02:26 -05001017 return ret;
1018}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001019
1020/*
1021* qla2x00_loop_reset
1022* Issue loop reset.
1023*
1024* Input:
1025* ha = adapter block pointer.
1026*
1027* Returns:
1028* 0 = success
1029*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001030int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001031qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001032{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001033 int ret;
bdf79622005-04-17 15:06:53 -05001034 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001037 if (ha->flags.enable_lip_full_login && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001038 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001039 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001040 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001041 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001042 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001043 }
1044 atomic_set(&vha->loop_state, LOOP_DOWN);
1045 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1046 qla2x00_mark_all_devices_lost(vha, 0);
1047 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048 }
1049
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001050 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001051 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001052 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001053 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001054 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1055 } else
1056 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001057 }
1058
1059 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001061 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001062 continue;
1063
Andrew Vasquez523ec772008-04-03 13:13:24 -07001064 ret = ha->isp_ops->target_reset(fcport, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001065 if (ret != QLA_SUCCESS) {
1066 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1067 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001069 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001070 }
1071 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001072 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001073 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001074
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001075 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001076}
1077
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001078void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001079qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001080{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001081 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001082 unsigned long flags;
1083 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001084 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001085 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001086
1087 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001088 for (que = 0; que < ha->max_queues; que++) {
1089 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001090 if (!req)
1091 continue;
1092 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1093 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001094 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001095 req->outstanding_cmds[cnt] = NULL;
1096 sp->cmd->result = res;
1097 qla2x00_sp_compl(ha, sp);
1098 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001099 }
1100 }
1101 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1102}
1103
f4f051e2005-04-17 15:02:26 -05001104static int
1105qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001106{
bdf79622005-04-17 15:06:53 -05001107 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001109 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001110 return -ENXIO;
1111
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001112 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001113
1114 return 0;
1115}
1116
1117static int
1118qla2xxx_slave_configure(struct scsi_device *sdev)
1119{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001120 scsi_qla_host_t *vha = shost_priv(sdev->host);
1121 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001122 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001123 struct req_que *req = ha->req_q_map[vha->req_ques[0]];
8482e1182005-04-17 15:04:54 -05001124
f4f051e2005-04-17 15:02:26 -05001125 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001126 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001127 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001128 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001129
Andrew Vasquez85821c92008-07-10 16:55:48 -07001130 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001131
f4f051e2005-04-17 15:02:26 -05001132 return 0;
1133}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001134
f4f051e2005-04-17 15:02:26 -05001135static void
1136qla2xxx_slave_destroy(struct scsi_device *sdev)
1137{
1138 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001139}
1140
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001141static int
1142qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1143{
1144 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1145 return sdev->queue_depth;
1146}
1147
1148static int
1149qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1150{
1151 if (sdev->tagged_supported) {
1152 scsi_set_tag_type(sdev, tag_type);
1153 if (tag_type)
1154 scsi_activate_tcq(sdev, sdev->queue_depth);
1155 else
1156 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1157 } else
1158 tag_type = 0;
1159
1160 return tag_type;
1161}
1162
Linus Torvalds1da177e2005-04-16 15:20:36 -07001163/**
1164 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1165 * @ha: HA context
1166 *
1167 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1168 * supported addressing method.
1169 */
1170static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001171qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001172{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001173 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001174 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001175
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001176 if (!dma_set_mask(&ha->pdev->dev, DMA_64BIT_MASK)) {
1177 /* Any upper-dword bits set? */
1178 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1179 !pci_set_consistent_dma_mask(ha->pdev, DMA_64BIT_MASK)) {
1180 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001182 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1183 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001184 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001185 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001186 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001187
1188 dma_set_mask(&ha->pdev->dev, DMA_32BIT_MASK);
1189 pci_set_consistent_dma_mask(ha->pdev, DMA_32BIT_MASK);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001190}
1191
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001192static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001193qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001194{
1195 unsigned long flags = 0;
1196 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1197
1198 spin_lock_irqsave(&ha->hardware_lock, flags);
1199 ha->interrupts_on = 1;
1200 /* enable risc and host interrupts */
1201 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1202 RD_REG_WORD(&reg->ictrl);
1203 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1204
1205}
1206
1207static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001208qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001209{
1210 unsigned long flags = 0;
1211 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1212
1213 spin_lock_irqsave(&ha->hardware_lock, flags);
1214 ha->interrupts_on = 0;
1215 /* disable risc and host interrupts */
1216 WRT_REG_WORD(&reg->ictrl, 0);
1217 RD_REG_WORD(&reg->ictrl);
1218 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1219}
1220
1221static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001222qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001223{
1224 unsigned long flags = 0;
1225 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1226
1227 spin_lock_irqsave(&ha->hardware_lock, flags);
1228 ha->interrupts_on = 1;
1229 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1230 RD_REG_DWORD(&reg->ictrl);
1231 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1232}
1233
1234static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001235qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001236{
1237 unsigned long flags = 0;
1238 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1239
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001240 if (IS_NOPOLLING_TYPE(ha))
1241 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001242 spin_lock_irqsave(&ha->hardware_lock, flags);
1243 ha->interrupts_on = 0;
1244 WRT_REG_DWORD(&reg->ictrl, 0);
1245 RD_REG_DWORD(&reg->ictrl);
1246 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1247}
1248
1249static struct isp_operations qla2100_isp_ops = {
1250 .pci_config = qla2100_pci_config,
1251 .reset_chip = qla2x00_reset_chip,
1252 .chip_diag = qla2x00_chip_diag,
1253 .config_rings = qla2x00_config_rings,
1254 .reset_adapter = qla2x00_reset_adapter,
1255 .nvram_config = qla2x00_nvram_config,
1256 .update_fw_options = qla2x00_update_fw_options,
1257 .load_risc = qla2x00_load_risc,
1258 .pci_info_str = qla2x00_pci_info_str,
1259 .fw_version_str = qla2x00_fw_version_str,
1260 .intr_handler = qla2100_intr_handler,
1261 .enable_intrs = qla2x00_enable_intrs,
1262 .disable_intrs = qla2x00_disable_intrs,
1263 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001264 .target_reset = qla2x00_abort_target,
1265 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001266 .fabric_login = qla2x00_login_fabric,
1267 .fabric_logout = qla2x00_fabric_logout,
1268 .calc_req_entries = qla2x00_calc_iocbs_32,
1269 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1270 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1271 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1272 .read_nvram = qla2x00_read_nvram_data,
1273 .write_nvram = qla2x00_write_nvram_data,
1274 .fw_dump = qla2100_fw_dump,
1275 .beacon_on = NULL,
1276 .beacon_off = NULL,
1277 .beacon_blink = NULL,
1278 .read_optrom = qla2x00_read_optrom_data,
1279 .write_optrom = qla2x00_write_optrom_data,
1280 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001282};
1283
1284static struct isp_operations qla2300_isp_ops = {
1285 .pci_config = qla2300_pci_config,
1286 .reset_chip = qla2x00_reset_chip,
1287 .chip_diag = qla2x00_chip_diag,
1288 .config_rings = qla2x00_config_rings,
1289 .reset_adapter = qla2x00_reset_adapter,
1290 .nvram_config = qla2x00_nvram_config,
1291 .update_fw_options = qla2x00_update_fw_options,
1292 .load_risc = qla2x00_load_risc,
1293 .pci_info_str = qla2x00_pci_info_str,
1294 .fw_version_str = qla2x00_fw_version_str,
1295 .intr_handler = qla2300_intr_handler,
1296 .enable_intrs = qla2x00_enable_intrs,
1297 .disable_intrs = qla2x00_disable_intrs,
1298 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001299 .target_reset = qla2x00_abort_target,
1300 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001301 .fabric_login = qla2x00_login_fabric,
1302 .fabric_logout = qla2x00_fabric_logout,
1303 .calc_req_entries = qla2x00_calc_iocbs_32,
1304 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1305 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1306 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1307 .read_nvram = qla2x00_read_nvram_data,
1308 .write_nvram = qla2x00_write_nvram_data,
1309 .fw_dump = qla2300_fw_dump,
1310 .beacon_on = qla2x00_beacon_on,
1311 .beacon_off = qla2x00_beacon_off,
1312 .beacon_blink = qla2x00_beacon_blink,
1313 .read_optrom = qla2x00_read_optrom_data,
1314 .write_optrom = qla2x00_write_optrom_data,
1315 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001316 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001317};
1318
1319static struct isp_operations qla24xx_isp_ops = {
1320 .pci_config = qla24xx_pci_config,
1321 .reset_chip = qla24xx_reset_chip,
1322 .chip_diag = qla24xx_chip_diag,
1323 .config_rings = qla24xx_config_rings,
1324 .reset_adapter = qla24xx_reset_adapter,
1325 .nvram_config = qla24xx_nvram_config,
1326 .update_fw_options = qla24xx_update_fw_options,
1327 .load_risc = qla24xx_load_risc,
1328 .pci_info_str = qla24xx_pci_info_str,
1329 .fw_version_str = qla24xx_fw_version_str,
1330 .intr_handler = qla24xx_intr_handler,
1331 .enable_intrs = qla24xx_enable_intrs,
1332 .disable_intrs = qla24xx_disable_intrs,
1333 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001334 .target_reset = qla24xx_abort_target,
1335 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001336 .fabric_login = qla24xx_login_fabric,
1337 .fabric_logout = qla24xx_fabric_logout,
1338 .calc_req_entries = NULL,
1339 .build_iocbs = NULL,
1340 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1341 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1342 .read_nvram = qla24xx_read_nvram_data,
1343 .write_nvram = qla24xx_write_nvram_data,
1344 .fw_dump = qla24xx_fw_dump,
1345 .beacon_on = qla24xx_beacon_on,
1346 .beacon_off = qla24xx_beacon_off,
1347 .beacon_blink = qla24xx_beacon_blink,
1348 .read_optrom = qla24xx_read_optrom_data,
1349 .write_optrom = qla24xx_write_optrom_data,
1350 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001351 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001352};
1353
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001354static struct isp_operations qla25xx_isp_ops = {
1355 .pci_config = qla25xx_pci_config,
1356 .reset_chip = qla24xx_reset_chip,
1357 .chip_diag = qla24xx_chip_diag,
1358 .config_rings = qla24xx_config_rings,
1359 .reset_adapter = qla24xx_reset_adapter,
1360 .nvram_config = qla24xx_nvram_config,
1361 .update_fw_options = qla24xx_update_fw_options,
1362 .load_risc = qla24xx_load_risc,
1363 .pci_info_str = qla24xx_pci_info_str,
1364 .fw_version_str = qla24xx_fw_version_str,
1365 .intr_handler = qla24xx_intr_handler,
1366 .enable_intrs = qla24xx_enable_intrs,
1367 .disable_intrs = qla24xx_disable_intrs,
1368 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001369 .target_reset = qla24xx_abort_target,
1370 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001371 .fabric_login = qla24xx_login_fabric,
1372 .fabric_logout = qla24xx_fabric_logout,
1373 .calc_req_entries = NULL,
1374 .build_iocbs = NULL,
1375 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1376 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1377 .read_nvram = qla25xx_read_nvram_data,
1378 .write_nvram = qla25xx_write_nvram_data,
1379 .fw_dump = qla25xx_fw_dump,
1380 .beacon_on = qla24xx_beacon_on,
1381 .beacon_off = qla24xx_beacon_off,
1382 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001383 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001384 .write_optrom = qla24xx_write_optrom_data,
1385 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001386 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001387};
1388
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001389static struct isp_operations qla81xx_isp_ops = {
1390 .pci_config = qla25xx_pci_config,
1391 .reset_chip = qla24xx_reset_chip,
1392 .chip_diag = qla24xx_chip_diag,
1393 .config_rings = qla24xx_config_rings,
1394 .reset_adapter = qla24xx_reset_adapter,
1395 .nvram_config = qla81xx_nvram_config,
1396 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001397 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001398 .pci_info_str = qla24xx_pci_info_str,
1399 .fw_version_str = qla24xx_fw_version_str,
1400 .intr_handler = qla24xx_intr_handler,
1401 .enable_intrs = qla24xx_enable_intrs,
1402 .disable_intrs = qla24xx_disable_intrs,
1403 .abort_command = qla24xx_abort_command,
1404 .target_reset = qla24xx_abort_target,
1405 .lun_reset = qla24xx_lun_reset,
1406 .fabric_login = qla24xx_login_fabric,
1407 .fabric_logout = qla24xx_fabric_logout,
1408 .calc_req_entries = NULL,
1409 .build_iocbs = NULL,
1410 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1411 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001412 .read_nvram = NULL,
1413 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001414 .fw_dump = qla81xx_fw_dump,
1415 .beacon_on = qla24xx_beacon_on,
1416 .beacon_off = qla24xx_beacon_off,
1417 .beacon_blink = qla24xx_beacon_blink,
1418 .read_optrom = qla25xx_read_optrom_data,
1419 .write_optrom = qla24xx_write_optrom_data,
1420 .get_flash_version = qla24xx_get_flash_version,
1421 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001422};
1423
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001424static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001425qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001426{
1427 ha->device_type = DT_EXTENDED_IDS;
1428 switch (ha->pdev->device) {
1429 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1430 ha->device_type |= DT_ISP2100;
1431 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001432 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001433 break;
1434 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1435 ha->device_type |= DT_ISP2200;
1436 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001437 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001438 break;
1439 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1440 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001441 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001442 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001443 break;
1444 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1445 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001446 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001447 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001448 break;
1449 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1450 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001451 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001452 if (ha->pdev->subsystem_vendor == 0x1028 &&
1453 ha->pdev->subsystem_device == 0x0170)
1454 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001455 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001456 break;
1457 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1458 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001459 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001460 break;
1461 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1462 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001463 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001464 break;
1465 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1466 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001467 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001468 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001469 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001470 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001471 break;
1472 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1473 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001474 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001475 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001476 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001477 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001478 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001479 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1480 ha->device_type |= DT_ISP8432;
1481 ha->device_type |= DT_ZIO_SUPPORTED;
1482 ha->device_type |= DT_FWI2;
1483 ha->device_type |= DT_IIDMA;
1484 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1485 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001486 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1487 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001488 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001489 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001490 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001491 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1492 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001493 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001494 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001495 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001496 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1497 ha->device_type |= DT_ISP2532;
1498 ha->device_type |= DT_ZIO_SUPPORTED;
1499 ha->device_type |= DT_FWI2;
1500 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001501 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1502 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001503 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1504 ha->device_type |= DT_ISP8001;
1505 ha->device_type |= DT_ZIO_SUPPORTED;
1506 ha->device_type |= DT_FWI2;
1507 ha->device_type |= DT_IIDMA;
1508 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1509 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001510 }
1511}
1512
Linus Torvalds1da177e2005-04-16 15:20:36 -07001513static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001514qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001515{
Andrew Vasquez37765412008-01-17 09:02:09 -08001516 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001517 uint16_t msix;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001518
Andrew Vasquez285d0322007-10-19 15:59:17 -07001519 if (pci_request_selected_regions(ha->pdev, ha->bars,
1520 QLA2XXX_DRIVER_NAME)) {
1521 qla_printk(KERN_WARNING, ha,
1522 "Failed to reserve PIO/MMIO regions (%s)\n",
1523 pci_name(ha->pdev));
1524
1525 goto iospace_error_exit;
1526 }
1527 if (!(ha->bars & 1))
1528 goto skip_pio;
1529
Linus Torvalds1da177e2005-04-16 15:20:36 -07001530 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1531 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001532 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1533 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001534 qla_printk(KERN_WARNING, ha,
1535 "Invalid PCI I/O region size (%s)...\n",
1536 pci_name(ha->pdev));
1537 pio = 0;
1538 }
1539 } else {
1540 qla_printk(KERN_WARNING, ha,
1541 "region #0 not a PIO resource (%s)...\n",
1542 pci_name(ha->pdev));
1543 pio = 0;
1544 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001545 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001546
Andrew Vasquez285d0322007-10-19 15:59:17 -07001547skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001548 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001549 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001550 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001551 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001552 pci_name(ha->pdev));
1553 goto iospace_error_exit;
1554 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001555 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001556 qla_printk(KERN_ERR, ha,
1557 "Invalid PCI mem region size (%s), aborting\n",
1558 pci_name(ha->pdev));
1559 goto iospace_error_exit;
1560 }
1561
Andrew Vasquez37765412008-01-17 09:02:09 -08001562 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001563 if (!ha->iobase) {
1564 qla_printk(KERN_ERR, ha,
1565 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1566
1567 goto iospace_error_exit;
1568 }
1569
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001570 /* Determine queue resources */
1571 ha->max_queues = 1;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001572 if (ql2xmaxqueues <= 1 || (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001573 goto mqiobase_exit;
1574 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1575 pci_resource_len(ha->pdev, 3));
1576 if (ha->mqiobase) {
1577 /* Read MSIX vector size of the board */
1578 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1579 ha->msix_count = msix;
1580 /* Max queues are bounded by available msix vectors */
1581 /* queue 0 uses two msix vectors */
1582 if (ha->msix_count - 1 < ql2xmaxqueues)
1583 ha->max_queues = ha->msix_count - 1;
1584 else if (ql2xmaxqueues > QLA_MQ_SIZE)
1585 ha->max_queues = QLA_MQ_SIZE;
1586 else
1587 ha->max_queues = ql2xmaxqueues;
1588 qla_printk(KERN_INFO, ha,
1589 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001590 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001591
1592mqiobase_exit:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001593 ha->msix_count = ha->max_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001594 return (0);
1595
1596iospace_error_exit:
1597 return (-ENOMEM);
1598}
1599
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001600static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001601qla2xxx_scan_start(struct Scsi_Host *shost)
1602{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001603 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001604
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001605 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1606 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1607 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1608 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001609}
1610
1611static int
1612qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1613{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001614 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001615
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001616 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001617 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001618 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001619 return 1;
1620
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001621 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001622}
1623
Linus Torvalds1da177e2005-04-16 15:20:36 -07001624/*
1625 * PCI driver interface
1626 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001627static int __devinit
1628qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001630 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001632 scsi_qla_host_t *base_vha = NULL;
1633 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001634 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001635 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001636 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001637 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001638 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001639 struct req_que *req = NULL;
1640 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001641
Andrew Vasquez285d0322007-10-19 15:59:17 -07001642 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001643 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001644 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1645 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001646 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001647 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1648 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001649 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1650 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001651 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001652 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001653 }
1654
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001655 if (mem_only) {
1656 if (pci_enable_device_mem(pdev))
1657 goto probe_out;
1658 } else {
1659 if (pci_enable_device(pdev))
1660 goto probe_out;
1661 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001662
Jesse Barnes09276782008-10-18 17:33:19 -07001663 /* This may fail but that's ok */
1664 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001665
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001666 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1667 if (!ha) {
1668 DEBUG(printk("Unable to allocate memory for ha\n"));
1669 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001670 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001671 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001672
1673 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001674 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001675 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001676 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001677
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001678 /* Set ISP-type information. */
1679 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001680 /* Configure PCI I/O space */
1681 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001682 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001683 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001684
Linus Torvalds1da177e2005-04-16 15:20:36 -07001685 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001686 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1687 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001688
Linus Torvalds1da177e2005-04-16 15:20:36 -07001689 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001690 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001691 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001692 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001693
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001694 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001695 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001696 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001697 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001698 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001699 req_length = REQUEST_ENTRY_CNT_2100;
1700 rsp_length = RESPONSE_ENTRY_CNT_2100;
1701 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001702 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001703 ha->flash_conf_off = ~0;
1704 ha->flash_data_off = ~0;
1705 ha->nvram_conf_off = ~0;
1706 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001707 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001708 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001709 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001710 req_length = REQUEST_ENTRY_CNT_2200;
1711 rsp_length = RESPONSE_ENTRY_CNT_2100;
1712 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001713 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001714 ha->flash_conf_off = ~0;
1715 ha->flash_data_off = ~0;
1716 ha->nvram_conf_off = ~0;
1717 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001718 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001719 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001720 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001721 req_length = REQUEST_ENTRY_CNT_2200;
1722 rsp_length = RESPONSE_ENTRY_CNT_2300;
1723 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001724 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001725 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1726 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001727 ha->flash_conf_off = ~0;
1728 ha->flash_data_off = ~0;
1729 ha->nvram_conf_off = ~0;
1730 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001731 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001732 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001733 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001734 req_length = REQUEST_ENTRY_CNT_24XX;
1735 rsp_length = RESPONSE_ENTRY_CNT_2300;
1736 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001737 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001738 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001739 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001740 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001741 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001742 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1743 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1744 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1745 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001746 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001747 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001748 req_length = REQUEST_ENTRY_CNT_24XX;
1749 rsp_length = RESPONSE_ENTRY_CNT_2300;
1750 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001751 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001752 ha->gid_list_info_size = 8;
1753 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001754 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001755 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001756 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1757 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1758 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1759 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1760 } else if (IS_QLA81XX(ha)) {
1761 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1762 req_length = REQUEST_ENTRY_CNT_24XX;
1763 rsp_length = RESPONSE_ENTRY_CNT_2300;
1764 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1765 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1766 ha->gid_list_info_size = 8;
1767 ha->optrom_size = OPTROM_SIZE_81XX;
1768 ha->isp_ops = &qla81xx_isp_ops;
1769 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1770 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1771 ha->nvram_conf_off = ~0;
1772 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001774
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001775 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001776 init_completion(&ha->mbx_cmd_comp);
1777 complete(&ha->mbx_cmd_comp);
1778 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001779
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001780 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Andrew Vasquez53303c42009-01-22 09:45:37 -08001782 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001783 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001784 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001785 qla_printk(KERN_WARNING, ha,
1786 "[ERROR] Failed to allocate memory for adapter\n");
1787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001788 goto probe_hw_failed;
1789 }
1790
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001791 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001792 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001793 req->max_q_depth = ql2xmaxqdepth;
1794
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001795
1796 base_vha = qla2x00_create_host(sht, ha);
1797 if (!base_vha) {
1798 qla_printk(KERN_WARNING, ha,
1799 "[ERROR] Failed to allocate memory for scsi_host\n");
1800
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001801 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001802 qla2x00_mem_free(ha);
1803 qla2x00_free_que(ha, req, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001804 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001805 }
1806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001807 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 host = base_vha->host;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001810 base_vha->req_ques[0] = req->id;
1811 host->can_queue = req->length + 128;
1812 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001813 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001814 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001815 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1816 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001817 if (IS_QLA2100(ha))
1818 host->sg_tablesize = 32;
1819 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001820 host->this_id = 255;
1821 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001822 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001823 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001824 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001825 host->max_lun = MAX_LUNS;
1826 host->transportt = qla2xxx_transport_template;
1827
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001828 /* Set up the irqs */
1829 ret = qla2x00_request_irqs(ha, rsp);
1830 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001831 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001832 /* Alloc arrays of request and response ring ptrs */
1833 if (!qla2x00_alloc_queues(ha)) {
1834 qla_printk(KERN_WARNING, ha,
1835 "[ERROR] Failed to allocate memory for queue"
1836 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001837 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001838 }
1839 ha->rsp_q_map[0] = rsp;
1840 ha->req_q_map[0] = req;
1841
Andrew Vasquez08029992009-03-24 09:07:55 -07001842 /* FWI2-capable only. */
1843 req->req_q_in = &ha->iobase->isp24.req_q_in;
1844 req->req_q_out = &ha->iobase->isp24.req_q_out;
1845 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1846 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001847 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001848 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1849 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1850 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1851 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001852 }
1853
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001854 if (qla2x00_initialize_adapter(base_vha)) {
1855 qla_printk(KERN_WARNING, ha,
1856 "Failed to initialize adapter\n");
1857
1858 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1859 "Adapter flags %x.\n",
1860 base_vha->host_no, base_vha->device_flags));
1861
1862 ret = -ENODEV;
1863 goto probe_failed;
1864 }
1865
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001866 /*
1867 * Startup the kernel thread for this host adapter
1868 */
1869 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1870 "%s_dpc", base_vha->host_str);
1871 if (IS_ERR(ha->dpc_thread)) {
1872 qla_printk(KERN_WARNING, ha,
1873 "Unable to start DPC thread!\n");
1874 ret = PTR_ERR(ha->dpc_thread);
1875 goto probe_failed;
1876 }
1877
1878 list_add_tail(&base_vha->list, &ha->vp_list);
1879 base_vha->host->irq = ha->pdev->irq;
1880
Linus Torvalds1da177e2005-04-16 15:20:36 -07001881 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001882 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001883
1884 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001885 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001886
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001887 base_vha->flags.init_done = 1;
1888 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001889
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001890 ret = scsi_add_host(host, &pdev->dev);
1891 if (ret)
1892 goto probe_failed;
1893
Andrew Vasquez048feec2008-09-11 22:19:45 -07001894 ha->isp_ops->enable_intrs(ha);
1895
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001896 scsi_scan_host(host);
1897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001899
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001900 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001901
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001903
Linus Torvalds1da177e2005-04-16 15:20:36 -07001904 qla_printk(KERN_INFO, ha, "\n"
1905 " QLogic Fibre Channel HBA Driver: %s\n"
1906 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08001907 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
1908 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001909 ha->model_desc ? ha->model_desc : "", pdev->device,
1910 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
1911 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
1912 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001913
Linus Torvalds1da177e2005-04-16 15:20:36 -07001914 return 0;
1915
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001916probe_init_failed:
1917 qla2x00_free_que(ha, req, rsp);
1918 ha->max_queues = 0;
1919
Linus Torvalds1da177e2005-04-16 15:20:36 -07001920probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07001921 if (base_vha->timer_active)
1922 qla2x00_stop_timer(base_vha);
1923 base_vha->flags.online = 0;
1924 if (ha->dpc_thread) {
1925 struct task_struct *t = ha->dpc_thread;
1926
1927 ha->dpc_thread = NULL;
1928 kthread_stop(t);
1929 }
1930
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001931 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001932
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001933 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001934
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001935probe_hw_failed:
1936 if (ha->iobase)
1937 iounmap(ha->iobase);
1938
1939 pci_release_selected_regions(ha->pdev, ha->bars);
1940 kfree(ha);
1941 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001942
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001943probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001944 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001945 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001946}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001947
Adrian Bunk4c993f72008-01-14 00:55:16 -08001948static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001949qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001950{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001951 scsi_qla_host_t *base_vha, *vha, *temp;
1952 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001953
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001954 base_vha = pci_get_drvdata(pdev);
1955 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001956
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001957 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
1958 if (vha && vha->fc_vport)
1959 fc_vport_terminate(vha->fc_vport);
1960 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001961
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001962 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07001963
Andrew Vasquezb9978762009-03-24 09:08:05 -07001964 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
1965
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001966 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08001967
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001968 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001969
Andrew Vasquezb9978762009-03-24 09:08:05 -07001970 /* Disable timer */
1971 if (base_vha->timer_active)
1972 qla2x00_stop_timer(base_vha);
1973
1974 base_vha->flags.online = 0;
1975
1976 /* Kill the kernel thread for this host */
1977 if (ha->dpc_thread) {
1978 struct task_struct *t = ha->dpc_thread;
1979
1980 /*
1981 * qla2xxx_wake_dpc checks for ->dpc_thread
1982 * so we need to zero it out.
1983 */
1984 ha->dpc_thread = NULL;
1985 kthread_stop(t);
1986 }
1987
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001988 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001989
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001990 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05001991
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001992 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001993
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001994 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001996 scsi_host_put(base_vha->host);
1997
1998 if (ha->iobase)
1999 iounmap(ha->iobase);
2000
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002001 if (ha->mqiobase)
2002 iounmap(ha->mqiobase);
2003
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002004 pci_release_selected_regions(ha->pdev, ha->bars);
2005 kfree(ha);
2006 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002007
Bernhard Walle665db932007-03-28 00:49:49 +02002008 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002009 pci_set_drvdata(pdev, NULL);
2010}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
2012static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002013qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002014{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002015 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002016
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002017 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002018 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002019
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002020 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002021 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002022
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002023 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002024 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002025
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002026 /* turn-off interrupts on the card */
2027 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002028 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002029
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 qla2x00_free_irqs(vha);
2031
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002032 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002033
2034 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002035}
2036
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002037static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002038qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002039 int defer)
2040{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002041 struct fc_rport *rport;
2042
2043 if (!fcport->rport)
2044 return;
2045
2046 rport = fcport->rport;
2047 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002048 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002049 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 spin_unlock_irq(vha->host->host_lock);
2051 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2052 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002053 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002054 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002055}
2056
Linus Torvalds1da177e2005-04-16 15:20:36 -07002057/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002058 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2059 *
2060 * Input: ha = adapter block pointer. fcport = port structure pointer.
2061 *
2062 * Return: None.
2063 *
2064 * Context:
2065 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002066void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002067 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002068{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002069 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002070 vha->vp_idx == fcport->vp_idx) {
2071 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2072 qla2x00_schedule_rport_del(vha, fcport, defer);
2073 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002074 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002075 * We may need to retry the login, so don't change the state of the
2076 * port but do the retries.
2077 */
2078 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2079 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2080
2081 if (!do_login)
2082 return;
2083
2084 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002085 fcport->login_retry = vha->hw->login_retry_count;
2086 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002087
2088 DEBUG(printk("scsi(%ld): Port login retry: "
2089 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2090 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002091 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002092 fcport->port_name[0],
2093 fcport->port_name[1],
2094 fcport->port_name[2],
2095 fcport->port_name[3],
2096 fcport->port_name[4],
2097 fcport->port_name[5],
2098 fcport->port_name[6],
2099 fcport->port_name[7],
2100 fcport->loop_id,
2101 fcport->login_retry));
2102 }
2103}
2104
2105/*
2106 * qla2x00_mark_all_devices_lost
2107 * Updates fcport state when device goes offline.
2108 *
2109 * Input:
2110 * ha = adapter block pointer.
2111 * fcport = port structure pointer.
2112 *
2113 * Return:
2114 * None.
2115 *
2116 * Context:
2117 */
2118void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
2121 fc_port_t *fcport;
2122
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002123 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2124 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002125 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002126 /*
2127 * No point in marking the device as lost, if the device is
2128 * already DEAD.
2129 */
2130 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2131 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002132 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2133 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2134 qla2x00_schedule_rport_del(vha, fcport, defer);
2135 } else
2136 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002137 }
2138}
2139
2140/*
2141* qla2x00_mem_alloc
2142* Allocates adapter memory.
2143*
2144* Returns:
2145* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002146* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002147*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002148static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002149qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2150 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002151{
2152 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002153
Andrew Vasqueze8711082008-01-31 12:33:48 -08002154 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002155 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002156 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002157 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002158
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002159 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2160 &ha->gid_list_dma, GFP_KERNEL);
2161 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002162 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002163
Andrew Vasqueze8711082008-01-31 12:33:48 -08002164 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2165 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002166 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002167
Andrew Vasqueze8711082008-01-31 12:33:48 -08002168 /* Get memory for cached NVRAM */
2169 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2170 if (!ha->nvram)
2171 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002172
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002173 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2174 ha->pdev->device);
2175 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2176 DMA_POOL_SIZE, 8, 0);
2177 if (!ha->s_dma_pool)
2178 goto fail_free_nvram;
2179
Andrew Vasqueze8711082008-01-31 12:33:48 -08002180 /* Allocate memory for SNS commands */
2181 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002182 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002183 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002184 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002185 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002186 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002187 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002188 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002189 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002190 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002191 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002192 goto fail_dma_pool;
2193 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002194 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002195 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002196 if (!ha->ct_sns)
2197 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002198 }
2199
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002200 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002201 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2202 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002203 DEBUG(printk("Unable to allocate memory for req\n"));
2204 goto fail_req;
2205 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002206 (*req)->length = req_len;
2207 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2208 ((*req)->length + 1) * sizeof(request_t),
2209 &(*req)->dma, GFP_KERNEL);
2210 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002211 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2212 goto fail_req_ring;
2213 }
2214 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002215 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2216 if (!*rsp) {
2217 qla_printk(KERN_WARNING, ha,
2218 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002219 goto fail_rsp;
2220 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002221 (*rsp)->hw = ha;
2222 (*rsp)->length = rsp_len;
2223 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2224 ((*rsp)->length + 1) * sizeof(response_t),
2225 &(*rsp)->dma, GFP_KERNEL);
2226 if (!(*rsp)->ring) {
2227 qla_printk(KERN_WARNING, ha,
2228 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002229 goto fail_rsp_ring;
2230 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002231 (*req)->rsp = *rsp;
2232 (*rsp)->req = *req;
2233 /* Allocate memory for NVRAM data for vports */
2234 if (ha->nvram_npiv_size) {
2235 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2236 ha->nvram_npiv_size, GFP_KERNEL);
2237 if (!ha->npiv_info) {
2238 qla_printk(KERN_WARNING, ha,
2239 "Unable to allocate memory for npiv info\n");
2240 goto fail_npiv_info;
2241 }
2242 } else
2243 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002244
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002245 /* Get consistent memory allocated for EX-INIT-CB. */
2246 if (IS_QLA81XX(ha)) {
2247 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2248 &ha->ex_init_cb_dma);
2249 if (!ha->ex_init_cb)
2250 goto fail_ex_init_cb;
2251 }
2252
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002253 INIT_LIST_HEAD(&ha->vp_list);
2254 return 1;
2255
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002256fail_ex_init_cb:
2257 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002258fail_npiv_info:
2259 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2260 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2261 (*rsp)->ring = NULL;
2262 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002264 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002266 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2267 sizeof(request_t), (*req)->ring, (*req)->dma);
2268 (*req)->ring = NULL;
2269 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002270fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002271 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002272fail_req:
2273 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2274 ha->ct_sns, ha->ct_sns_dma);
2275 ha->ct_sns = NULL;
2276 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002277fail_free_ms_iocb:
2278 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2279 ha->ms_iocb = NULL;
2280 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281fail_dma_pool:
2282 dma_pool_destroy(ha->s_dma_pool);
2283 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002284fail_free_nvram:
2285 kfree(ha->nvram);
2286 ha->nvram = NULL;
2287fail_free_srb_mempool:
2288 mempool_destroy(ha->srb_mempool);
2289 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002290fail_free_gid_list:
2291 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002293 ha->gid_list = NULL;
2294 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002295fail_free_init_cb:
2296 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2297 ha->init_cb_dma);
2298 ha->init_cb = NULL;
2299 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002300fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002301 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002302 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002303}
2304
2305/*
2306* qla2x00_mem_free
2307* Frees all adapter allocated memory.
2308*
2309* Input:
2310* ha = adapter block pointer.
2311*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002312static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002313qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002314{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002315 if (ha->srb_mempool)
2316 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002317
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002318 if (ha->fce)
2319 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002320 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002321
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002322 if (ha->fw_dump) {
2323 if (ha->eft)
2324 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002325 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002326 vfree(ha->fw_dump);
2327 }
2328
Linus Torvalds1da177e2005-04-16 15:20:36 -07002329 if (ha->sns_cmd)
2330 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002331 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002332
2333 if (ha->ct_sns)
2334 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002335 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002336
Andrew Vasquez88729e52006-06-23 16:10:50 -07002337 if (ha->sfp_data)
2338 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2339
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002340 if (ha->edc_data)
2341 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2342
Linus Torvalds1da177e2005-04-16 15:20:36 -07002343 if (ha->ms_iocb)
2344 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2345
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002346 if (ha->ex_init_cb)
2347 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2348
Linus Torvalds1da177e2005-04-16 15:20:36 -07002349 if (ha->s_dma_pool)
2350 dma_pool_destroy(ha->s_dma_pool);
2351
Linus Torvalds1da177e2005-04-16 15:20:36 -07002352 if (ha->gid_list)
2353 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002354 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002355
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002356 if (ha->init_cb)
2357 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2358 ha->init_cb, ha->init_cb_dma);
2359 vfree(ha->optrom_buffer);
2360 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002361 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002362
Andrew Vasqueze8711082008-01-31 12:33:48 -08002363 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002364 ha->eft = NULL;
2365 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002366 ha->sns_cmd = NULL;
2367 ha->sns_cmd_dma = 0;
2368 ha->ct_sns = NULL;
2369 ha->ct_sns_dma = 0;
2370 ha->ms_iocb = NULL;
2371 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002372 ha->init_cb = NULL;
2373 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002374 ha->ex_init_cb = NULL;
2375 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002376
2377 ha->s_dma_pool = NULL;
2378
Linus Torvalds1da177e2005-04-16 15:20:36 -07002379 ha->gid_list = NULL;
2380 ha->gid_list_dma = 0;
2381
Linus Torvalds1da177e2005-04-16 15:20:36 -07002382 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002383 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002384 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002385}
2386
2387struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2388 struct qla_hw_data *ha)
2389{
2390 struct Scsi_Host *host;
2391 struct scsi_qla_host *vha = NULL;
2392
2393 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2394 if (host == NULL) {
2395 printk(KERN_WARNING
2396 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2397 goto fail;
2398 }
2399
2400 /* Clear our data area */
2401 vha = shost_priv(host);
2402 memset(vha, 0, sizeof(scsi_qla_host_t));
2403
2404 vha->host = host;
2405 vha->host_no = host->host_no;
2406 vha->hw = ha;
2407
2408 INIT_LIST_HEAD(&vha->vp_fcports);
2409 INIT_LIST_HEAD(&vha->work_list);
2410 INIT_LIST_HEAD(&vha->list);
2411
2412 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2413 return vha;
2414
2415fail:
2416 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002417}
2418
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002419static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002420qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002421 int locked)
2422{
2423 struct qla_work_evt *e;
2424
2425 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2426 GFP_KERNEL);
2427 if (!e)
2428 return NULL;
2429
2430 INIT_LIST_HEAD(&e->list);
2431 e->type = type;
2432 e->flags = QLA_EVT_FLAG_FREE;
2433 return e;
2434}
2435
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002436static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002437qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002438{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002439 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002440 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002441
2442 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 spin_lock_irqsave(&ha->hardware_lock, flags);
2444 list_add_tail(&e->list, &vha->work_list);
2445 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002446 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002448 return QLA_SUCCESS;
2449}
2450
2451int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002452qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002453 u32 data)
2454{
2455 struct qla_work_evt *e;
2456
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002457 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002458 if (!e)
2459 return QLA_FUNCTION_FAILED;
2460
2461 e->u.aen.code = code;
2462 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002463 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002464}
2465
Andrew Vasquez8a659572009-02-08 20:50:12 -08002466int
2467qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2468{
2469 struct qla_work_evt *e;
2470
2471 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1);
2472 if (!e)
2473 return QLA_FUNCTION_FAILED;
2474
2475 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2476 return qla2x00_post_work(vha, e, 1);
2477}
2478
Andrew Vasquez0971de72008-04-03 13:13:18 -07002479static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002480qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002481{
2482 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002483 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002484
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002485 spin_lock_irq(&ha->hardware_lock);
2486 while (!list_empty(&vha->work_list)) {
2487 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002488 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002489 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002490
2491 switch (e->type) {
2492 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002493 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002494 e->u.aen.code, e->u.aen.data);
2495 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002496 case QLA_EVT_IDC_ACK:
2497 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2498 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002499 }
2500 if (e->flags & QLA_EVT_FLAG_FREE)
2501 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002502 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002503 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002504 spin_unlock_irq(&ha->hardware_lock);
2505}
2506/* Relogins all the fcports of a vport
2507 * Context: dpc thread
2508 */
2509void qla2x00_relogin(struct scsi_qla_host *vha)
2510{
2511 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002512 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002513 uint16_t next_loopid = 0;
2514 struct qla_hw_data *ha = vha->hw;
2515
2516 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2517 /*
2518 * If the port is not ONLINE then try to login
2519 * to it if we haven't run out of retries.
2520 */
2521 if (atomic_read(&fcport->state) !=
2522 FCS_ONLINE && fcport->login_retry) {
2523
2524 if (fcport->flags & FCF_FABRIC_DEVICE) {
2525 if (fcport->flags & FCF_TAPE_PRESENT)
2526 ha->isp_ops->fabric_logout(vha,
2527 fcport->loop_id,
2528 fcport->d_id.b.domain,
2529 fcport->d_id.b.area,
2530 fcport->d_id.b.al_pa);
2531
2532 status = qla2x00_fabric_login(vha, fcport,
2533 &next_loopid);
2534 } else
2535 status = qla2x00_local_device_login(vha,
2536 fcport);
2537
2538 fcport->login_retry--;
2539 if (status == QLA_SUCCESS) {
2540 fcport->old_loop_id = fcport->loop_id;
2541
2542 DEBUG(printk("scsi(%ld): port login OK: logged "
2543 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2544
2545 qla2x00_update_fcport(vha, fcport);
2546
2547 } else if (status == 1) {
2548 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2549 /* retry the login again */
2550 DEBUG(printk("scsi(%ld): Retrying"
2551 " %d login again loop_id 0x%x\n",
2552 vha->host_no, fcport->login_retry,
2553 fcport->loop_id));
2554 } else {
2555 fcport->login_retry = 0;
2556 }
2557
2558 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2559 fcport->loop_id = FC_NO_LOOP_ID;
2560 }
2561 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2562 break;
2563 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002564}
2565
Linus Torvalds1da177e2005-04-16 15:20:36 -07002566/**************************************************************************
2567* qla2x00_do_dpc
2568* This kernel thread is a task that is schedule by the interrupt handler
2569* to perform the background processing for interrupts.
2570*
2571* Notes:
2572* This task always run in the context of a kernel thread. It
2573* is kick-off by the driver's detect code and starts up
2574* up one per adapter. It immediately goes to sleep and waits for
2575* some fibre event. When either the interrupt handler or
2576* the timer routine detects a event it will one of the task
2577* bits then wake us up.
2578**************************************************************************/
2579static int
2580qla2x00_do_dpc(void *data)
2581{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002582 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002583 scsi_qla_host_t *base_vha;
2584 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002585
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002586 ha = (struct qla_hw_data *)data;
2587 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002588
Linus Torvalds1da177e2005-04-16 15:20:36 -07002589 set_user_nice(current, -20);
2590
Christoph Hellwig39a11242006-02-14 18:46:22 +01002591 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002592 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2593
Christoph Hellwig39a11242006-02-14 18:46:22 +01002594 set_current_state(TASK_INTERRUPTIBLE);
2595 schedule();
2596 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002597
2598 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2599
2600 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002602 continue;
2603
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002604 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002605
2606 ha->dpc_active = 1;
2607
Linus Torvalds1da177e2005-04-16 15:20:36 -07002608 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002609 ha->dpc_active = 0;
2610 continue;
2611 }
2612
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002613 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002614
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002615 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2616 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002617
2618 DEBUG(printk("scsi(%ld): dpc: sched "
2619 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002620 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002621 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002622 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002623
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002624 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002625 /* failed. retry later */
2626 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002627 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002628 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002629 clear_bit(ABORT_ISP_ACTIVE,
2630 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002631 }
2632
Linus Torvalds1da177e2005-04-16 15:20:36 -07002633 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002634 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002635 }
2636
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002637 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2638 qla2x00_update_fcports(base_vha);
2639 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002640 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002641
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002642 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2643 &base_vha->dpc_flags) &&
2644 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002645
2646 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002647 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002648
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002649 qla2x00_rst_aen(base_vha);
2650 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002651 }
2652
2653 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002654 if ((test_and_clear_bit(RELOGIN_NEEDED,
2655 &base_vha->dpc_flags)) &&
2656 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2657 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002658
2659 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002660 base_vha->host_no));
2661 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002662
Linus Torvalds1da177e2005-04-16 15:20:36 -07002663 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002664 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002665 }
2666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002667 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2668 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002669
2670 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002671 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002672
2673 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002674 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002675
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002676 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002677
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002678 clear_bit(LOOP_RESYNC_ACTIVE,
2679 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002680 }
2681
2682 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002683 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002684 }
2685
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002686 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2687 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2688 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2689 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002690 }
2691
Linus Torvalds1da177e2005-04-16 15:20:36 -07002692 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002693 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002694
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2696 &base_vha->dpc_flags))
2697 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002698
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002699 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 ha->dpc_active = 0;
2702 } /* End of while(1) */
2703
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002704 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002705
2706 /*
2707 * Make sure that nobody tries to wake us up again.
2708 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709 ha->dpc_active = 0;
2710
Christoph Hellwig39a11242006-02-14 18:46:22 +01002711 return 0;
2712}
2713
2714void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002715qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002716{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002717 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002718 struct task_struct *t = ha->dpc_thread;
2719
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002720 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002721 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002722}
2723
2724/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002725* qla2x00_rst_aen
2726* Processes asynchronous reset.
2727*
2728* Input:
2729* ha = adapter block pointer.
2730*/
2731static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 if (vha->flags.online && !vha->flags.reset_active &&
2735 !atomic_read(&vha->loop_down_timer) &&
2736 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002738 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002739
2740 /*
2741 * Issue marker command only when we are going to start
2742 * the I/O.
2743 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002744 vha->marker_needed = 1;
2745 } while (!atomic_read(&vha->loop_down_timer) &&
2746 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 }
2748}
2749
f4f051e2005-04-17 15:02:26 -05002750static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002751qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002752{
2753 struct scsi_cmnd *cmd = sp->cmd;
2754
2755 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002756 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002757 sp->flags &= ~SRB_DMA_VALID;
2758 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002759 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002760}
2761
2762void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002763qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002764{
2765 struct scsi_cmnd *cmd = sp->cmd;
2766
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002767 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002768
f4f051e2005-04-17 15:02:26 -05002769 mempool_free(sp, ha->srb_mempool);
2770
2771 cmd->scsi_done(cmd);
2772}
bdf79622005-04-17 15:06:53 -05002773
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774/**************************************************************************
2775* qla2x00_timer
2776*
2777* Description:
2778* One second timer
2779*
2780* Context: Interrupt
2781***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002782void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002785 unsigned long cpu_flags = 0;
2786 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787 int start_dpc = 0;
2788 int index;
2789 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002790 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002791 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002792 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002793 /*
2794 * Ports - Port down timer.
2795 *
2796 * Whenever, a port is in the LOST state we start decrementing its port
2797 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002798 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002799 */
2800 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002801 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002802 if (fcport->port_type != FCT_TARGET)
2803 continue;
2804
2805 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2806
2807 if (atomic_read(&fcport->port_down_timer) == 0)
2808 continue;
2809
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002810 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002811 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002812
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002814 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002815 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002816 t, atomic_read(&fcport->port_down_timer)));
2817 }
2818 t++;
2819 } /* End of for fcport */
2820
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821
2822 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002823 if (atomic_read(&vha->loop_down_timer) > 0 &&
2824 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2825 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002826
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827 if (atomic_read(&vha->loop_down_timer) ==
2828 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002829
2830 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2831 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002833
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002834 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2835 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002836
2837 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002838 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002839 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002840 spin_lock_irqsave(&ha->hardware_lock,
2841 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002842 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002843 for (index = 1;
2844 index < MAX_OUTSTANDING_COMMANDS;
2845 index++) {
2846 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002847
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002848 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002849 if (!sp)
2850 continue;
2851 sfcp = sp->fcport;
2852 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2853 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002854
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002855 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002857 break;
2858 }
2859 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002860 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002862 start_dpc++;
2863 }
2864
2865 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002866 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002867 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2868 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002869 DEBUG(printk("scsi(%ld): Loop down - "
2870 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002871 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002872 qla_printk(KERN_WARNING, ha,
2873 "Loop down - aborting ISP.\n");
2874
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002875 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002876 }
2877 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002878 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 vha->host_no,
2880 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002881 }
2882
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002883 /* Check if beacon LED needs to be blinked */
2884 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002885 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002886 start_dpc++;
2887 }
2888
Andrew Vasquez550bf572008-04-24 15:21:23 -07002889 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002890 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07002891 start_dpc++;
2892
Linus Torvalds1da177e2005-04-16 15:20:36 -07002893 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002894 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
2895 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
2896 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002898 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
2899 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
2900 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
2901 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
2902 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002903
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002904 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905}
2906
Andrew Vasquez54333832005-11-09 15:49:04 -08002907/* Firmware interface routines. */
2908
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002909#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08002910#define FW_ISP21XX 0
2911#define FW_ISP22XX 1
2912#define FW_ISP2300 2
2913#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002914#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002915#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002916#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08002917
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002918#define FW_FILE_ISP21XX "ql2100_fw.bin"
2919#define FW_FILE_ISP22XX "ql2200_fw.bin"
2920#define FW_FILE_ISP2300 "ql2300_fw.bin"
2921#define FW_FILE_ISP2322 "ql2322_fw.bin"
2922#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002923#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002924#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002925
Daniel Walkere1e82b62008-05-12 22:21:10 -07002926static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002927
2928static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07002929 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
2930 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
2931 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
2932 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
2933 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002934 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002935 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08002936};
2937
2938struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08002940{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002941 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08002942 struct fw_blob *blob;
2943
2944 blob = NULL;
2945 if (IS_QLA2100(ha)) {
2946 blob = &qla_fw_blobs[FW_ISP21XX];
2947 } else if (IS_QLA2200(ha)) {
2948 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002949 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002950 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08002951 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002952 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002953 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08002954 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07002955 } else if (IS_QLA25XX(ha)) {
2956 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08002957 } else if (IS_QLA81XX(ha)) {
2958 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08002959 }
2960
Daniel Walkere1e82b62008-05-12 22:21:10 -07002961 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002962 if (blob->fw)
2963 goto out;
2964
2965 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
2966 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002967 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08002968 blob->fw = NULL;
2969 blob = NULL;
2970 goto out;
2971 }
2972
2973out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07002974 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002975 return blob;
2976}
2977
2978static void
2979qla2x00_release_firmware(void)
2980{
2981 int idx;
2982
Daniel Walkere1e82b62008-05-12 22:21:10 -07002983 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002984 for (idx = 0; idx < FW_BLOBS; idx++)
2985 if (qla_fw_blobs[idx].fw)
2986 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07002987 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08002988}
2989
Seokmann Ju14e660e2007-09-20 14:07:36 -07002990static pci_ers_result_t
2991qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
2992{
2993 switch (state) {
2994 case pci_channel_io_normal:
2995 return PCI_ERS_RESULT_CAN_RECOVER;
2996 case pci_channel_io_frozen:
2997 pci_disable_device(pdev);
2998 return PCI_ERS_RESULT_NEED_RESET;
2999 case pci_channel_io_perm_failure:
3000 qla2x00_remove_one(pdev);
3001 return PCI_ERS_RESULT_DISCONNECT;
3002 }
3003 return PCI_ERS_RESULT_NEED_RESET;
3004}
3005
3006static pci_ers_result_t
3007qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3008{
3009 int risc_paused = 0;
3010 uint32_t stat;
3011 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003012 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3013 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003014 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3015 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3016
3017 spin_lock_irqsave(&ha->hardware_lock, flags);
3018 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3019 stat = RD_REG_DWORD(&reg->hccr);
3020 if (stat & HCCR_RISC_PAUSE)
3021 risc_paused = 1;
3022 } else if (IS_QLA23XX(ha)) {
3023 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3024 if (stat & HSR_RISC_PAUSED)
3025 risc_paused = 1;
3026 } else if (IS_FWI2_CAPABLE(ha)) {
3027 stat = RD_REG_DWORD(&reg24->host_status);
3028 if (stat & HSRX_RISC_PAUSED)
3029 risc_paused = 1;
3030 }
3031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3032
3033 if (risc_paused) {
3034 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3035 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003036 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003037
3038 return PCI_ERS_RESULT_NEED_RESET;
3039 } else
3040 return PCI_ERS_RESULT_RECOVERED;
3041}
3042
3043static pci_ers_result_t
3044qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3045{
3046 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003047 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3048 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003049 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003050
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003051 if (ha->mem_only)
3052 rc = pci_enable_device_mem(pdev);
3053 else
3054 rc = pci_enable_device(pdev);
3055
3056 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003057 qla_printk(KERN_WARNING, ha,
3058 "Can't re-enable PCI device after reset.\n");
3059
3060 return ret;
3061 }
3062 pci_set_master(pdev);
3063
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003064 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003065 return ret;
3066
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003067 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3068 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003069 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003070 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003071
3072 return ret;
3073}
3074
3075static void
3076qla2xxx_pci_resume(struct pci_dev *pdev)
3077{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003078 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3079 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003080 int ret;
3081
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003082 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003083 if (ret != QLA_SUCCESS) {
3084 qla_printk(KERN_ERR, ha,
3085 "the device failed to resume I/O "
3086 "from slot/link_reset");
3087 }
3088 pci_cleanup_aer_uncorrect_error_status(pdev);
3089}
3090
3091static struct pci_error_handlers qla2xxx_err_handler = {
3092 .error_detected = qla2xxx_pci_error_detected,
3093 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3094 .slot_reset = qla2xxx_pci_slot_reset,
3095 .resume = qla2xxx_pci_resume,
3096};
3097
Andrew Vasquez54333832005-11-09 15:49:04 -08003098static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003099 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3100 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3101 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3102 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3103 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3104 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3105 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3106 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3107 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003108 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003109 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3110 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003111 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003112 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003113 { 0 },
3114};
3115MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3116
Andrew Vasquezfca29702005-07-06 10:31:47 -07003117static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003118 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003119 .driver = {
3120 .owner = THIS_MODULE,
3121 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003122 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003123 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003124 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003125 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003126};
3127
Linus Torvalds1da177e2005-04-16 15:20:36 -07003128/**
3129 * qla2x00_module_init - Module initialization.
3130 **/
3131static int __init
3132qla2x00_module_init(void)
3133{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003134 int ret = 0;
3135
Linus Torvalds1da177e2005-04-16 15:20:36 -07003136 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003137 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003138 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003139 if (srb_cachep == NULL) {
3140 printk(KERN_ERR
3141 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3142 return -ENOMEM;
3143 }
3144
3145 /* Derive version string. */
3146 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003147 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003148 strcat(qla2x00_version_str, "-debug");
3149
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003150 qla2xxx_transport_template =
3151 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003152 if (!qla2xxx_transport_template) {
3153 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003154 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003155 }
3156 qla2xxx_transport_vport_template =
3157 fc_attach_transport(&qla2xxx_transport_vport_functions);
3158 if (!qla2xxx_transport_vport_template) {
3159 kmem_cache_destroy(srb_cachep);
3160 fc_release_transport(qla2xxx_transport_template);
3161 return -ENODEV;
3162 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003163
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003164 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3165 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003166 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003167 if (ret) {
3168 kmem_cache_destroy(srb_cachep);
3169 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003170 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003171 }
3172 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003173}
3174
3175/**
3176 * qla2x00_module_exit - Module cleanup.
3177 **/
3178static void __exit
3179qla2x00_module_exit(void)
3180{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003181 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003182 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003183 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003184 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003185 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003186}
3187
3188module_init(qla2x00_module_init);
3189module_exit(qla2x00_module_exit);
3190
3191MODULE_AUTHOR("QLogic Corporation");
3192MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3193MODULE_LICENSE("GPL");
3194MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003195MODULE_FIRMWARE(FW_FILE_ISP21XX);
3196MODULE_FIRMWARE(FW_FILE_ISP22XX);
3197MODULE_FIRMWARE(FW_FILE_ISP2300);
3198MODULE_FIRMWARE(FW_FILE_ISP2322);
3199MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003200MODULE_FIRMWARE(FW_FILE_ISP25XX);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003201MODULE_FIRMWARE(FW_FILE_ISP81XX);