[SCSI] qla2xxx: Cache swl during fabric discovery.
[GitHub/mt8127/android_kernel_alcatel_ttab.git] / drivers / scsi / qla2xxx / qla_os.c
1 /*
2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2011 QLogic Corporation
4 *
5 * See LICENSE.qla2xxx for copyright and licensing details.
6 */
7 #include "qla_def.h"
8
9 #include <linux/moduleparam.h>
10 #include <linux/vmalloc.h>
11 #include <linux/delay.h>
12 #include <linux/kthread.h>
13 #include <linux/mutex.h>
14 #include <linux/kobject.h>
15 #include <linux/slab.h>
16
17 #include <scsi/scsi_tcq.h>
18 #include <scsi/scsicam.h>
19 #include <scsi/scsi_transport.h>
20 #include <scsi/scsi_transport_fc.h>
21
22 /*
23 * Driver version
24 */
25 char qla2x00_version_str[40];
26
27 static int apidev_major;
28
29 /*
30 * SRB allocation cache
31 */
32 static struct kmem_cache *srb_cachep;
33
34 /*
35 * CT6 CTX allocation cache
36 */
37 static struct kmem_cache *ctx_cachep;
38 /*
39 * error level for logging
40 */
41 int ql_errlev = ql_log_all;
42
43 int ql2xlogintimeout = 20;
44 module_param(ql2xlogintimeout, int, S_IRUGO);
45 MODULE_PARM_DESC(ql2xlogintimeout,
46 "Login timeout value in seconds.");
47
48 int qlport_down_retry;
49 module_param(qlport_down_retry, int, S_IRUGO);
50 MODULE_PARM_DESC(qlport_down_retry,
51 "Maximum number of command retries to a port that returns "
52 "a PORT-DOWN status.");
53
54 int ql2xplogiabsentdevice;
55 module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
56 MODULE_PARM_DESC(ql2xplogiabsentdevice,
57 "Option to enable PLOGI to devices that are not present after "
58 "a Fabric scan. This is needed for several broken switches. "
59 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
60
61 int ql2xloginretrycount = 0;
62 module_param(ql2xloginretrycount, int, S_IRUGO);
63 MODULE_PARM_DESC(ql2xloginretrycount,
64 "Specify an alternate value for the NVRAM login retry count.");
65
66 int ql2xallocfwdump = 1;
67 module_param(ql2xallocfwdump, int, S_IRUGO);
68 MODULE_PARM_DESC(ql2xallocfwdump,
69 "Option to enable allocation of memory for a firmware dump "
70 "during HBA initialization. Memory allocation requirements "
71 "vary by ISP type. Default is 1 - allocate memory.");
72
73 int ql2xextended_error_logging;
74 module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
75 MODULE_PARM_DESC(ql2xextended_error_logging,
76 "Option to enable extended error logging,\n"
77 "\t\tDefault is 0 - no logging. 0x40000000 - Module Init & Probe.\n"
78 "\t\t0x20000000 - Mailbox Cmnds. 0x10000000 - Device Discovery.\n"
79 "\t\t0x08000000 - IO tracing. 0x04000000 - DPC Thread.\n"
80 "\t\t0x02000000 - Async events. 0x01000000 - Timer routines.\n"
81 "\t\t0x00800000 - User space. 0x00400000 - Task Management.\n"
82 "\t\t0x00200000 - AER/EEH. 0x00100000 - Multi Q.\n"
83 "\t\t0x00080000 - P3P Specific. 0x00040000 - Virtual Port.\n"
84 "\t\t0x00020000 - Buffer Dump. 0x00010000 - Misc.\n"
85 "\t\t0x7fffffff - For enabling all logs, can be too many logs.\n"
86 "\t\t0x1e400000 - Preferred value for capturing essential "
87 "debug information (equivalent to old "
88 "ql2xextended_error_logging=1).\n"
89 "\t\tDo LOGICAL OR of the value to enable more than one level");
90
91 int ql2xshiftctondsd = 6;
92 module_param(ql2xshiftctondsd, int, S_IRUGO);
93 MODULE_PARM_DESC(ql2xshiftctondsd,
94 "Set to control shifting of command type processing "
95 "based on total number of SG elements.");
96
97 static void qla2x00_free_device(scsi_qla_host_t *);
98
99 int ql2xfdmienable=1;
100 module_param(ql2xfdmienable, int, S_IRUGO);
101 MODULE_PARM_DESC(ql2xfdmienable,
102 "Enables FDMI registrations. "
103 "0 - no FDMI. Default is 1 - perform FDMI.");
104
105 #define MAX_Q_DEPTH 32
106 static int ql2xmaxqdepth = MAX_Q_DEPTH;
107 module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
108 MODULE_PARM_DESC(ql2xmaxqdepth,
109 "Maximum queue depth to report for target devices.");
110
111 /* Do not change the value of this after module load */
112 int ql2xenabledif = 0;
113 module_param(ql2xenabledif, int, S_IRUGO|S_IWUSR);
114 MODULE_PARM_DESC(ql2xenabledif,
115 " Enable T10-CRC-DIF "
116 " Default is 0 - No DIF Support. 1 - Enable it"
117 ", 2 - Enable DIF for all types, except Type 0.");
118
119 int ql2xenablehba_err_chk = 2;
120 module_param(ql2xenablehba_err_chk, int, S_IRUGO|S_IWUSR);
121 MODULE_PARM_DESC(ql2xenablehba_err_chk,
122 " Enable T10-CRC-DIF Error isolation by HBA:\n"
123 " Default is 1.\n"
124 " 0 -- Error isolation disabled\n"
125 " 1 -- Error isolation enabled only for DIX Type 0\n"
126 " 2 -- Error isolation enabled for all Types\n");
127
128 int ql2xiidmaenable=1;
129 module_param(ql2xiidmaenable, int, S_IRUGO);
130 MODULE_PARM_DESC(ql2xiidmaenable,
131 "Enables iIDMA settings "
132 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
133
134 int ql2xmaxqueues = 1;
135 module_param(ql2xmaxqueues, int, S_IRUGO);
136 MODULE_PARM_DESC(ql2xmaxqueues,
137 "Enables MQ settings "
138 "Default is 1 for single queue. Set it to number "
139 "of queues in MQ mode.");
140
141 int ql2xmultique_tag;
142 module_param(ql2xmultique_tag, int, S_IRUGO);
143 MODULE_PARM_DESC(ql2xmultique_tag,
144 "Enables CPU affinity settings for the driver "
145 "Default is 0 for no affinity of request and response IO. "
146 "Set it to 1 to turn on the cpu affinity.");
147
148 int ql2xfwloadbin;
149 module_param(ql2xfwloadbin, int, S_IRUGO|S_IWUSR);
150 MODULE_PARM_DESC(ql2xfwloadbin,
151 "Option to specify location from which to load ISP firmware:.\n"
152 " 2 -- load firmware via the request_firmware() (hotplug).\n"
153 " interface.\n"
154 " 1 -- load firmware from flash.\n"
155 " 0 -- use default semantics.\n");
156
157 int ql2xetsenable;
158 module_param(ql2xetsenable, int, S_IRUGO);
159 MODULE_PARM_DESC(ql2xetsenable,
160 "Enables firmware ETS burst."
161 "Default is 0 - skip ETS enablement.");
162
163 int ql2xdbwr = 1;
164 module_param(ql2xdbwr, int, S_IRUGO|S_IWUSR);
165 MODULE_PARM_DESC(ql2xdbwr,
166 "Option to specify scheme for request queue posting.\n"
167 " 0 -- Regular doorbell.\n"
168 " 1 -- CAMRAM doorbell (faster).\n");
169
170 int ql2xtargetreset = 1;
171 module_param(ql2xtargetreset, int, S_IRUGO);
172 MODULE_PARM_DESC(ql2xtargetreset,
173 "Enable target reset."
174 "Default is 1 - use hw defaults.");
175
176 int ql2xgffidenable;
177 module_param(ql2xgffidenable, int, S_IRUGO);
178 MODULE_PARM_DESC(ql2xgffidenable,
179 "Enables GFF_ID checks of port type. "
180 "Default is 0 - Do not use GFF_ID information.");
181
182 int ql2xasynctmfenable;
183 module_param(ql2xasynctmfenable, int, S_IRUGO);
184 MODULE_PARM_DESC(ql2xasynctmfenable,
185 "Enables issue of TM IOCBs asynchronously via IOCB mechanism"
186 "Default is 0 - Issue TM IOCBs via mailbox mechanism.");
187
188 int ql2xdontresethba;
189 module_param(ql2xdontresethba, int, S_IRUGO|S_IWUSR);
190 MODULE_PARM_DESC(ql2xdontresethba,
191 "Option to specify reset behaviour.\n"
192 " 0 (Default) -- Reset on failure.\n"
193 " 1 -- Do not reset on failure.\n");
194
195 uint ql2xmaxlun = MAX_LUNS;
196 module_param(ql2xmaxlun, uint, S_IRUGO);
197 MODULE_PARM_DESC(ql2xmaxlun,
198 "Defines the maximum LU number to register with the SCSI "
199 "midlayer. Default is 65535.");
200
201 int ql2xmdcapmask = 0x1F;
202 module_param(ql2xmdcapmask, int, S_IRUGO);
203 MODULE_PARM_DESC(ql2xmdcapmask,
204 "Set the Minidump driver capture mask level. "
205 "Default is 0x1F - Can be set to 0x3, 0x7, 0xF, 0x1F, 0x7F.");
206
207 int ql2xmdenable = 1;
208 module_param(ql2xmdenable, int, S_IRUGO);
209 MODULE_PARM_DESC(ql2xmdenable,
210 "Enable/disable MiniDump. "
211 "0 - MiniDump disabled. "
212 "1 (Default) - MiniDump enabled.");
213
214 /*
215 * SCSI host template entry points
216 */
217 static int qla2xxx_slave_configure(struct scsi_device * device);
218 static int qla2xxx_slave_alloc(struct scsi_device *);
219 static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
220 static void qla2xxx_scan_start(struct Scsi_Host *);
221 static void qla2xxx_slave_destroy(struct scsi_device *);
222 static int qla2xxx_queuecommand(struct Scsi_Host *h, struct scsi_cmnd *cmd);
223 static int qla2xxx_eh_abort(struct scsi_cmnd *);
224 static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
225 static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
226 static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
227 static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
228
229 static int qla2x00_change_queue_depth(struct scsi_device *, int, int);
230 static int qla2x00_change_queue_type(struct scsi_device *, int);
231
232 struct scsi_host_template qla2xxx_driver_template = {
233 .module = THIS_MODULE,
234 .name = QLA2XXX_DRIVER_NAME,
235 .queuecommand = qla2xxx_queuecommand,
236
237 .eh_abort_handler = qla2xxx_eh_abort,
238 .eh_device_reset_handler = qla2xxx_eh_device_reset,
239 .eh_target_reset_handler = qla2xxx_eh_target_reset,
240 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
241 .eh_host_reset_handler = qla2xxx_eh_host_reset,
242
243 .slave_configure = qla2xxx_slave_configure,
244
245 .slave_alloc = qla2xxx_slave_alloc,
246 .slave_destroy = qla2xxx_slave_destroy,
247 .scan_finished = qla2xxx_scan_finished,
248 .scan_start = qla2xxx_scan_start,
249 .change_queue_depth = qla2x00_change_queue_depth,
250 .change_queue_type = qla2x00_change_queue_type,
251 .this_id = -1,
252 .cmd_per_lun = 3,
253 .use_clustering = ENABLE_CLUSTERING,
254 .sg_tablesize = SG_ALL,
255
256 .max_sectors = 0xFFFF,
257 .shost_attrs = qla2x00_host_attrs,
258 };
259
260 static struct scsi_transport_template *qla2xxx_transport_template = NULL;
261 struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
262
263 /* TODO Convert to inlines
264 *
265 * Timer routines
266 */
267
268 __inline__ void
269 qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
270 {
271 init_timer(&vha->timer);
272 vha->timer.expires = jiffies + interval * HZ;
273 vha->timer.data = (unsigned long)vha;
274 vha->timer.function = (void (*)(unsigned long))func;
275 add_timer(&vha->timer);
276 vha->timer_active = 1;
277 }
278
279 static inline void
280 qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
281 {
282 /* Currently used for 82XX only. */
283 if (vha->device_flags & DFLG_DEV_FAILED) {
284 ql_dbg(ql_dbg_timer, vha, 0x600d,
285 "Device in a failed state, returning.\n");
286 return;
287 }
288
289 mod_timer(&vha->timer, jiffies + interval * HZ);
290 }
291
292 static __inline__ void
293 qla2x00_stop_timer(scsi_qla_host_t *vha)
294 {
295 del_timer_sync(&vha->timer);
296 vha->timer_active = 0;
297 }
298
299 static int qla2x00_do_dpc(void *data);
300
301 static void qla2x00_rst_aen(scsi_qla_host_t *);
302
303 static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
304 struct req_que **, struct rsp_que **);
305 static void qla2x00_free_fw_dump(struct qla_hw_data *);
306 static void qla2x00_mem_free(struct qla_hw_data *);
307
308 /* -------------------------------------------------------------------------- */
309 static int qla2x00_alloc_queues(struct qla_hw_data *ha)
310 {
311 scsi_qla_host_t *vha = pci_get_drvdata(ha->pdev);
312 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
313 GFP_KERNEL);
314 if (!ha->req_q_map) {
315 ql_log(ql_log_fatal, vha, 0x003b,
316 "Unable to allocate memory for request queue ptrs.\n");
317 goto fail_req_map;
318 }
319
320 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
321 GFP_KERNEL);
322 if (!ha->rsp_q_map) {
323 ql_log(ql_log_fatal, vha, 0x003c,
324 "Unable to allocate memory for response queue ptrs.\n");
325 goto fail_rsp_map;
326 }
327 set_bit(0, ha->rsp_qid_map);
328 set_bit(0, ha->req_qid_map);
329 return 1;
330
331 fail_rsp_map:
332 kfree(ha->req_q_map);
333 ha->req_q_map = NULL;
334 fail_req_map:
335 return -ENOMEM;
336 }
337
338 static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
339 {
340 if (req && req->ring)
341 dma_free_coherent(&ha->pdev->dev,
342 (req->length + 1) * sizeof(request_t),
343 req->ring, req->dma);
344
345 kfree(req);
346 req = NULL;
347 }
348
349 static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
350 {
351 if (rsp && rsp->ring)
352 dma_free_coherent(&ha->pdev->dev,
353 (rsp->length + 1) * sizeof(response_t),
354 rsp->ring, rsp->dma);
355
356 kfree(rsp);
357 rsp = NULL;
358 }
359
360 static void qla2x00_free_queues(struct qla_hw_data *ha)
361 {
362 struct req_que *req;
363 struct rsp_que *rsp;
364 int cnt;
365
366 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
367 req = ha->req_q_map[cnt];
368 qla2x00_free_req_que(ha, req);
369 }
370 kfree(ha->req_q_map);
371 ha->req_q_map = NULL;
372
373 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
374 rsp = ha->rsp_q_map[cnt];
375 qla2x00_free_rsp_que(ha, rsp);
376 }
377 kfree(ha->rsp_q_map);
378 ha->rsp_q_map = NULL;
379 }
380
381 static int qla25xx_setup_mode(struct scsi_qla_host *vha)
382 {
383 uint16_t options = 0;
384 int ques, req, ret;
385 struct qla_hw_data *ha = vha->hw;
386
387 if (!(ha->fw_attributes & BIT_6)) {
388 ql_log(ql_log_warn, vha, 0x00d8,
389 "Firmware is not multi-queue capable.\n");
390 goto fail;
391 }
392 if (ql2xmultique_tag) {
393 /* create a request queue for IO */
394 options |= BIT_7;
395 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
396 QLA_DEFAULT_QUE_QOS);
397 if (!req) {
398 ql_log(ql_log_warn, vha, 0x00e0,
399 "Failed to create request queue.\n");
400 goto fail;
401 }
402 ha->wq = alloc_workqueue("qla2xxx_wq", WQ_MEM_RECLAIM, 1);
403 vha->req = ha->req_q_map[req];
404 options |= BIT_1;
405 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
406 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
407 if (!ret) {
408 ql_log(ql_log_warn, vha, 0x00e8,
409 "Failed to create response queue.\n");
410 goto fail2;
411 }
412 }
413 ha->flags.cpu_affinity_enabled = 1;
414 ql_dbg(ql_dbg_multiq, vha, 0xc007,
415 "CPU affinity mode enalbed, "
416 "no. of response queues:%d no. of request queues:%d.\n",
417 ha->max_rsp_queues, ha->max_req_queues);
418 ql_dbg(ql_dbg_init, vha, 0x00e9,
419 "CPU affinity mode enalbed, "
420 "no. of response queues:%d no. of request queues:%d.\n",
421 ha->max_rsp_queues, ha->max_req_queues);
422 }
423 return 0;
424 fail2:
425 qla25xx_delete_queues(vha);
426 destroy_workqueue(ha->wq);
427 ha->wq = NULL;
428 vha->req = ha->req_q_map[0];
429 fail:
430 ha->mqenable = 0;
431 kfree(ha->req_q_map);
432 kfree(ha->rsp_q_map);
433 ha->max_req_queues = ha->max_rsp_queues = 1;
434 return 1;
435 }
436
437 static char *
438 qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
439 {
440 struct qla_hw_data *ha = vha->hw;
441 static char *pci_bus_modes[] = {
442 "33", "66", "100", "133",
443 };
444 uint16_t pci_bus;
445
446 strcpy(str, "PCI");
447 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
448 if (pci_bus) {
449 strcat(str, "-X (");
450 strcat(str, pci_bus_modes[pci_bus]);
451 } else {
452 pci_bus = (ha->pci_attr & BIT_8) >> 8;
453 strcat(str, " (");
454 strcat(str, pci_bus_modes[pci_bus]);
455 }
456 strcat(str, " MHz)");
457
458 return (str);
459 }
460
461 static char *
462 qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
463 {
464 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
465 struct qla_hw_data *ha = vha->hw;
466 uint32_t pci_bus;
467 int pcie_reg;
468
469 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
470 if (pcie_reg) {
471 char lwstr[6];
472 uint16_t pcie_lstat, lspeed, lwidth;
473
474 pcie_reg += 0x12;
475 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
476 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
477 lwidth = (pcie_lstat &
478 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
479
480 strcpy(str, "PCIe (");
481 if (lspeed == 1)
482 strcat(str, "2.5GT/s ");
483 else if (lspeed == 2)
484 strcat(str, "5.0GT/s ");
485 else
486 strcat(str, "<unknown> ");
487 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
488 strcat(str, lwstr);
489
490 return str;
491 }
492
493 strcpy(str, "PCI");
494 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
495 if (pci_bus == 0 || pci_bus == 8) {
496 strcat(str, " (");
497 strcat(str, pci_bus_modes[pci_bus >> 3]);
498 } else {
499 strcat(str, "-X ");
500 if (pci_bus & BIT_2)
501 strcat(str, "Mode 2");
502 else
503 strcat(str, "Mode 1");
504 strcat(str, " (");
505 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
506 }
507 strcat(str, " MHz)");
508
509 return str;
510 }
511
512 static char *
513 qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
514 {
515 char un_str[10];
516 struct qla_hw_data *ha = vha->hw;
517
518 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
519 ha->fw_minor_version,
520 ha->fw_subminor_version);
521
522 if (ha->fw_attributes & BIT_9) {
523 strcat(str, "FLX");
524 return (str);
525 }
526
527 switch (ha->fw_attributes & 0xFF) {
528 case 0x7:
529 strcat(str, "EF");
530 break;
531 case 0x17:
532 strcat(str, "TP");
533 break;
534 case 0x37:
535 strcat(str, "IP");
536 break;
537 case 0x77:
538 strcat(str, "VI");
539 break;
540 default:
541 sprintf(un_str, "(%x)", ha->fw_attributes);
542 strcat(str, un_str);
543 break;
544 }
545 if (ha->fw_attributes & 0x100)
546 strcat(str, "X");
547
548 return (str);
549 }
550
551 static char *
552 qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
553 {
554 struct qla_hw_data *ha = vha->hw;
555
556 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
557 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
558 return str;
559 }
560
561 void
562 qla2x00_sp_free_dma(void *vha, void *ptr)
563 {
564 srb_t *sp = (srb_t *)ptr;
565 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
566 struct qla_hw_data *ha = sp->fcport->vha->hw;
567 void *ctx = GET_CMD_CTX_SP(sp);
568
569 if (sp->flags & SRB_DMA_VALID) {
570 scsi_dma_unmap(cmd);
571 sp->flags &= ~SRB_DMA_VALID;
572 }
573
574 if (sp->flags & SRB_CRC_PROT_DMA_VALID) {
575 dma_unmap_sg(&ha->pdev->dev, scsi_prot_sglist(cmd),
576 scsi_prot_sg_count(cmd), cmd->sc_data_direction);
577 sp->flags &= ~SRB_CRC_PROT_DMA_VALID;
578 }
579
580 if (sp->flags & SRB_CRC_CTX_DSD_VALID) {
581 /* List assured to be having elements */
582 qla2x00_clean_dsd_pool(ha, sp);
583 sp->flags &= ~SRB_CRC_CTX_DSD_VALID;
584 }
585
586 if (sp->flags & SRB_CRC_CTX_DMA_VALID) {
587 dma_pool_free(ha->dl_dma_pool, ctx,
588 ((struct crc_context *)ctx)->crc_ctx_dma);
589 sp->flags &= ~SRB_CRC_CTX_DMA_VALID;
590 }
591
592 if (sp->flags & SRB_FCP_CMND_DMA_VALID) {
593 struct ct6_dsd *ctx1 = (struct ct6_dsd *)ctx;
594
595 dma_pool_free(ha->fcp_cmnd_dma_pool, ctx1->fcp_cmnd,
596 ctx1->fcp_cmnd_dma);
597 list_splice(&ctx1->dsd_list, &ha->gbl_dsd_list);
598 ha->gbl_dsd_inuse -= ctx1->dsd_use_cnt;
599 ha->gbl_dsd_avail += ctx1->dsd_use_cnt;
600 mempool_free(ctx1, ha->ctx_mempool);
601 ctx1 = NULL;
602 }
603
604 CMD_SP(cmd) = NULL;
605 mempool_free(sp, ha->srb_mempool);
606 }
607
608 static void
609 qla2x00_sp_compl(void *data, void *ptr, int res)
610 {
611 struct qla_hw_data *ha = (struct qla_hw_data *)data;
612 srb_t *sp = (srb_t *)ptr;
613 struct scsi_cmnd *cmd = GET_CMD_SP(sp);
614
615 cmd->result = res;
616
617 if (atomic_read(&sp->ref_count) == 0) {
618 ql_dbg(ql_dbg_io, sp->fcport->vha, 0x3015,
619 "SP reference-count to ZERO -- sp=%p cmd=%p.\n",
620 sp, GET_CMD_SP(sp));
621 if (ql2xextended_error_logging & ql_dbg_io)
622 BUG();
623 return;
624 }
625 if (!atomic_dec_and_test(&sp->ref_count))
626 return;
627
628 qla2x00_sp_free_dma(ha, sp);
629 cmd->scsi_done(cmd);
630 }
631
632 static int
633 qla2xxx_queuecommand(struct Scsi_Host *host, struct scsi_cmnd *cmd)
634 {
635 scsi_qla_host_t *vha = shost_priv(host);
636 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
637 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
638 struct qla_hw_data *ha = vha->hw;
639 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
640 srb_t *sp;
641 int rval;
642
643 if (ha->flags.eeh_busy) {
644 if (ha->flags.pci_channel_io_perm_failure) {
645 ql_dbg(ql_dbg_io, vha, 0x3001,
646 "PCI Channel IO permanent failure, exiting "
647 "cmd=%p.\n", cmd);
648 cmd->result = DID_NO_CONNECT << 16;
649 } else {
650 ql_dbg(ql_dbg_io, vha, 0x3002,
651 "EEH_Busy, Requeuing the cmd=%p.\n", cmd);
652 cmd->result = DID_REQUEUE << 16;
653 }
654 goto qc24_fail_command;
655 }
656
657 rval = fc_remote_port_chkready(rport);
658 if (rval) {
659 cmd->result = rval;
660 ql_dbg(ql_dbg_io, vha, 0x3003,
661 "fc_remote_port_chkready failed for cmd=%p, rval=0x%x.\n",
662 cmd, rval);
663 goto qc24_fail_command;
664 }
665
666 if (!vha->flags.difdix_supported &&
667 scsi_get_prot_op(cmd) != SCSI_PROT_NORMAL) {
668 ql_dbg(ql_dbg_io, vha, 0x3004,
669 "DIF Cap not reg, fail DIF capable cmd's:%p.\n",
670 cmd);
671 cmd->result = DID_NO_CONNECT << 16;
672 goto qc24_fail_command;
673 }
674
675 if (!fcport) {
676 cmd->result = DID_NO_CONNECT << 16;
677 goto qc24_fail_command;
678 }
679
680 if (atomic_read(&fcport->state) != FCS_ONLINE) {
681 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
682 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
683 ql_dbg(ql_dbg_io, vha, 0x3005,
684 "Returning DNC, fcport_state=%d loop_state=%d.\n",
685 atomic_read(&fcport->state),
686 atomic_read(&base_vha->loop_state));
687 cmd->result = DID_NO_CONNECT << 16;
688 goto qc24_fail_command;
689 }
690 goto qc24_target_busy;
691 }
692
693 sp = qla2x00_get_sp(base_vha, fcport, GFP_ATOMIC);
694 if (!sp)
695 goto qc24_host_busy;
696
697 sp->u.scmd.cmd = cmd;
698 sp->type = SRB_SCSI_CMD;
699 atomic_set(&sp->ref_count, 1);
700 CMD_SP(cmd) = (void *)sp;
701 sp->free = qla2x00_sp_free_dma;
702 sp->done = qla2x00_sp_compl;
703
704 rval = ha->isp_ops->start_scsi(sp);
705 if (rval != QLA_SUCCESS) {
706 ql_dbg(ql_dbg_io, vha, 0x3013,
707 "Start scsi failed rval=%d for cmd=%p.\n", rval, cmd);
708 goto qc24_host_busy_free_sp;
709 }
710
711 return 0;
712
713 qc24_host_busy_free_sp:
714 qla2x00_sp_free_dma(ha, sp);
715
716 qc24_host_busy:
717 return SCSI_MLQUEUE_HOST_BUSY;
718
719 qc24_target_busy:
720 return SCSI_MLQUEUE_TARGET_BUSY;
721
722 qc24_fail_command:
723 cmd->scsi_done(cmd);
724
725 return 0;
726 }
727
728 /*
729 * qla2x00_eh_wait_on_command
730 * Waits for the command to be returned by the Firmware for some
731 * max time.
732 *
733 * Input:
734 * cmd = Scsi Command to wait on.
735 *
736 * Return:
737 * Not Found : 0
738 * Found : 1
739 */
740 static int
741 qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
742 {
743 #define ABORT_POLLING_PERIOD 1000
744 #define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
745 unsigned long wait_iter = ABORT_WAIT_ITER;
746 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
747 struct qla_hw_data *ha = vha->hw;
748 int ret = QLA_SUCCESS;
749
750 if (unlikely(pci_channel_offline(ha->pdev)) || ha->flags.eeh_busy) {
751 ql_dbg(ql_dbg_taskm, vha, 0x8005,
752 "Return:eh_wait.\n");
753 return ret;
754 }
755
756 while (CMD_SP(cmd) && wait_iter--) {
757 msleep(ABORT_POLLING_PERIOD);
758 }
759 if (CMD_SP(cmd))
760 ret = QLA_FUNCTION_FAILED;
761
762 return ret;
763 }
764
765 /*
766 * qla2x00_wait_for_hba_online
767 * Wait till the HBA is online after going through
768 * <= MAX_RETRIES_OF_ISP_ABORT or
769 * finally HBA is disabled ie marked offline
770 *
771 * Input:
772 * ha - pointer to host adapter structure
773 *
774 * Note:
775 * Does context switching-Release SPIN_LOCK
776 * (if any) before calling this routine.
777 *
778 * Return:
779 * Success (Adapter is online) : 0
780 * Failed (Adapter is offline/disabled) : 1
781 */
782 int
783 qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
784 {
785 int return_status;
786 unsigned long wait_online;
787 struct qla_hw_data *ha = vha->hw;
788 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
789
790 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
791 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
792 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
793 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
794 ha->dpc_active) && time_before(jiffies, wait_online)) {
795
796 msleep(1000);
797 }
798 if (base_vha->flags.online)
799 return_status = QLA_SUCCESS;
800 else
801 return_status = QLA_FUNCTION_FAILED;
802
803 return (return_status);
804 }
805
806 /*
807 * qla2x00_wait_for_reset_ready
808 * Wait till the HBA is online after going through
809 * <= MAX_RETRIES_OF_ISP_ABORT or
810 * finally HBA is disabled ie marked offline or flash
811 * operations are in progress.
812 *
813 * Input:
814 * ha - pointer to host adapter structure
815 *
816 * Note:
817 * Does context switching-Release SPIN_LOCK
818 * (if any) before calling this routine.
819 *
820 * Return:
821 * Success (Adapter is online/no flash ops) : 0
822 * Failed (Adapter is offline/disabled/flash ops in progress) : 1
823 */
824 static int
825 qla2x00_wait_for_reset_ready(scsi_qla_host_t *vha)
826 {
827 int return_status;
828 unsigned long wait_online;
829 struct qla_hw_data *ha = vha->hw;
830 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
831
832 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
833 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
834 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
835 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
836 ha->optrom_state != QLA_SWAITING ||
837 ha->dpc_active) && time_before(jiffies, wait_online))
838 msleep(1000);
839
840 if (base_vha->flags.online && ha->optrom_state == QLA_SWAITING)
841 return_status = QLA_SUCCESS;
842 else
843 return_status = QLA_FUNCTION_FAILED;
844
845 ql_dbg(ql_dbg_taskm, vha, 0x8019,
846 "%s return status=%d.\n", __func__, return_status);
847
848 return return_status;
849 }
850
851 int
852 qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
853 {
854 int return_status;
855 unsigned long wait_reset;
856 struct qla_hw_data *ha = vha->hw;
857 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
858
859 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
860 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
861 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
862 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
863 ha->dpc_active) && time_before(jiffies, wait_reset)) {
864
865 msleep(1000);
866
867 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
868 ha->flags.chip_reset_done)
869 break;
870 }
871 if (ha->flags.chip_reset_done)
872 return_status = QLA_SUCCESS;
873 else
874 return_status = QLA_FUNCTION_FAILED;
875
876 return return_status;
877 }
878
879 static void
880 sp_get(struct srb *sp)
881 {
882 atomic_inc(&sp->ref_count);
883 }
884
885 /**************************************************************************
886 * qla2xxx_eh_abort
887 *
888 * Description:
889 * The abort function will abort the specified command.
890 *
891 * Input:
892 * cmd = Linux SCSI command packet to be aborted.
893 *
894 * Returns:
895 * Either SUCCESS or FAILED.
896 *
897 * Note:
898 * Only return FAILED if command not returned by firmware.
899 **************************************************************************/
900 static int
901 qla2xxx_eh_abort(struct scsi_cmnd *cmd)
902 {
903 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
904 srb_t *sp;
905 int ret;
906 unsigned int id, lun;
907 unsigned long flags;
908 int wait = 0;
909 struct qla_hw_data *ha = vha->hw;
910
911 if (!CMD_SP(cmd))
912 return SUCCESS;
913
914 ret = fc_block_scsi_eh(cmd);
915 if (ret != 0)
916 return ret;
917 ret = SUCCESS;
918
919 id = cmd->device->id;
920 lun = cmd->device->lun;
921
922 spin_lock_irqsave(&ha->hardware_lock, flags);
923 sp = (srb_t *) CMD_SP(cmd);
924 if (!sp) {
925 spin_unlock_irqrestore(&ha->hardware_lock, flags);
926 return SUCCESS;
927 }
928
929 ql_dbg(ql_dbg_taskm, vha, 0x8002,
930 "Aborting from RISC nexus=%ld:%d:%d sp=%p cmd=%p\n",
931 vha->host_no, id, lun, sp, cmd);
932
933 /* Get a reference to the sp and drop the lock.*/
934 sp_get(sp);
935
936 spin_unlock_irqrestore(&ha->hardware_lock, flags);
937 if (ha->isp_ops->abort_command(sp)) {
938 ret = FAILED;
939 ql_dbg(ql_dbg_taskm, vha, 0x8003,
940 "Abort command mbx failed cmd=%p.\n", cmd);
941 } else {
942 ql_dbg(ql_dbg_taskm, vha, 0x8004,
943 "Abort command mbx success cmd=%p.\n", cmd);
944 wait = 1;
945 }
946
947 spin_lock_irqsave(&ha->hardware_lock, flags);
948 sp->done(ha, sp, 0);
949 spin_unlock_irqrestore(&ha->hardware_lock, flags);
950
951 /* Did the command return during mailbox execution? */
952 if (ret == FAILED && !CMD_SP(cmd))
953 ret = SUCCESS;
954
955 /* Wait for the command to be returned. */
956 if (wait) {
957 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
958 ql_log(ql_log_warn, vha, 0x8006,
959 "Abort handler timed out cmd=%p.\n", cmd);
960 ret = FAILED;
961 }
962 }
963
964 ql_log(ql_log_info, vha, 0x801c,
965 "Abort command issued nexus=%ld:%d:%d -- %d %x.\n",
966 vha->host_no, id, lun, wait, ret);
967
968 return ret;
969 }
970
971 int
972 qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
973 unsigned int l, enum nexus_wait_type type)
974 {
975 int cnt, match, status;
976 unsigned long flags;
977 struct qla_hw_data *ha = vha->hw;
978 struct req_que *req;
979 srb_t *sp;
980 struct scsi_cmnd *cmd;
981
982 status = QLA_SUCCESS;
983
984 spin_lock_irqsave(&ha->hardware_lock, flags);
985 req = vha->req;
986 for (cnt = 1; status == QLA_SUCCESS &&
987 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
988 sp = req->outstanding_cmds[cnt];
989 if (!sp)
990 continue;
991 if (sp->type != SRB_SCSI_CMD)
992 continue;
993 if (vha->vp_idx != sp->fcport->vha->vp_idx)
994 continue;
995 match = 0;
996 cmd = GET_CMD_SP(sp);
997 switch (type) {
998 case WAIT_HOST:
999 match = 1;
1000 break;
1001 case WAIT_TARGET:
1002 match = cmd->device->id == t;
1003 break;
1004 case WAIT_LUN:
1005 match = (cmd->device->id == t &&
1006 cmd->device->lun == l);
1007 break;
1008 }
1009 if (!match)
1010 continue;
1011
1012 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1013 status = qla2x00_eh_wait_on_command(cmd);
1014 spin_lock_irqsave(&ha->hardware_lock, flags);
1015 }
1016 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1017
1018 return status;
1019 }
1020
1021 static char *reset_errors[] = {
1022 "HBA not online",
1023 "HBA not ready",
1024 "Task management failed",
1025 "Waiting for command completions",
1026 };
1027
1028 static int
1029 __qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
1030 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
1031 {
1032 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1033 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1034 int err;
1035
1036 if (!fcport) {
1037 return FAILED;
1038 }
1039
1040 err = fc_block_scsi_eh(cmd);
1041 if (err != 0)
1042 return err;
1043
1044 ql_log(ql_log_info, vha, 0x8009,
1045 "%s RESET ISSUED nexus=%ld:%d:%d cmd=%p.\n", name, vha->host_no,
1046 cmd->device->id, cmd->device->lun, cmd);
1047
1048 err = 0;
1049 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1050 ql_log(ql_log_warn, vha, 0x800a,
1051 "Wait for hba online failed for cmd=%p.\n", cmd);
1052 goto eh_reset_failed;
1053 }
1054 err = 2;
1055 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
1056 != QLA_SUCCESS) {
1057 ql_log(ql_log_warn, vha, 0x800c,
1058 "do_reset failed for cmd=%p.\n", cmd);
1059 goto eh_reset_failed;
1060 }
1061 err = 3;
1062 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
1063 cmd->device->lun, type) != QLA_SUCCESS) {
1064 ql_log(ql_log_warn, vha, 0x800d,
1065 "wait for peding cmds failed for cmd=%p.\n", cmd);
1066 goto eh_reset_failed;
1067 }
1068
1069 ql_log(ql_log_info, vha, 0x800e,
1070 "%s RESET SUCCEEDED nexus:%ld:%d:%d cmd=%p.\n", name,
1071 vha->host_no, cmd->device->id, cmd->device->lun, cmd);
1072
1073 return SUCCESS;
1074
1075 eh_reset_failed:
1076 ql_log(ql_log_info, vha, 0x800f,
1077 "%s RESET FAILED: %s nexus=%ld:%d:%d cmd=%p.\n", name,
1078 reset_errors[err], vha->host_no, cmd->device->id, cmd->device->lun,
1079 cmd);
1080 return FAILED;
1081 }
1082
1083 static int
1084 qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
1085 {
1086 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1087 struct qla_hw_data *ha = vha->hw;
1088
1089 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
1090 ha->isp_ops->lun_reset);
1091 }
1092
1093 static int
1094 qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
1095 {
1096 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1097 struct qla_hw_data *ha = vha->hw;
1098
1099 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
1100 ha->isp_ops->target_reset);
1101 }
1102
1103 /**************************************************************************
1104 * qla2xxx_eh_bus_reset
1105 *
1106 * Description:
1107 * The bus reset function will reset the bus and abort any executing
1108 * commands.
1109 *
1110 * Input:
1111 * cmd = Linux SCSI command packet of the command that cause the
1112 * bus reset.
1113 *
1114 * Returns:
1115 * SUCCESS/FAILURE (defined as macro in scsi.h).
1116 *
1117 **************************************************************************/
1118 static int
1119 qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
1120 {
1121 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1122 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
1123 int ret = FAILED;
1124 unsigned int id, lun;
1125
1126 id = cmd->device->id;
1127 lun = cmd->device->lun;
1128
1129 if (!fcport) {
1130 return ret;
1131 }
1132
1133 ret = fc_block_scsi_eh(cmd);
1134 if (ret != 0)
1135 return ret;
1136 ret = FAILED;
1137
1138 ql_log(ql_log_info, vha, 0x8012,
1139 "BUS RESET ISSUED nexus=%ld:%d%d.\n", vha->host_no, id, lun);
1140
1141 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1142 ql_log(ql_log_fatal, vha, 0x8013,
1143 "Wait for hba online failed board disabled.\n");
1144 goto eh_bus_reset_done;
1145 }
1146
1147 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
1148 ret = SUCCESS;
1149
1150 if (ret == FAILED)
1151 goto eh_bus_reset_done;
1152
1153 /* Flush outstanding commands. */
1154 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) !=
1155 QLA_SUCCESS) {
1156 ql_log(ql_log_warn, vha, 0x8014,
1157 "Wait for pending commands failed.\n");
1158 ret = FAILED;
1159 }
1160
1161 eh_bus_reset_done:
1162 ql_log(ql_log_warn, vha, 0x802b,
1163 "BUS RESET %s nexus=%ld:%d:%d.\n",
1164 (ret == FAILED) ? "FAILED" : "SUCCEDED", vha->host_no, id, lun);
1165
1166 return ret;
1167 }
1168
1169 /**************************************************************************
1170 * qla2xxx_eh_host_reset
1171 *
1172 * Description:
1173 * The reset function will reset the Adapter.
1174 *
1175 * Input:
1176 * cmd = Linux SCSI command packet of the command that cause the
1177 * adapter reset.
1178 *
1179 * Returns:
1180 * Either SUCCESS or FAILED.
1181 *
1182 * Note:
1183 **************************************************************************/
1184 static int
1185 qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1186 {
1187 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
1188 struct qla_hw_data *ha = vha->hw;
1189 int ret = FAILED;
1190 unsigned int id, lun;
1191 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
1192
1193 id = cmd->device->id;
1194 lun = cmd->device->lun;
1195
1196 ql_log(ql_log_info, vha, 0x8018,
1197 "ADAPTER RESET ISSUED nexus=%ld:%d:%d.\n", vha->host_no, id, lun);
1198
1199 if (qla2x00_wait_for_reset_ready(vha) != QLA_SUCCESS)
1200 goto eh_host_reset_lock;
1201
1202 if (vha != base_vha) {
1203 if (qla2x00_vp_abort_isp(vha))
1204 goto eh_host_reset_lock;
1205 } else {
1206 if (IS_QLA82XX(vha->hw)) {
1207 if (!qla82xx_fcoe_ctx_reset(vha)) {
1208 /* Ctx reset success */
1209 ret = SUCCESS;
1210 goto eh_host_reset_lock;
1211 }
1212 /* fall thru if ctx reset failed */
1213 }
1214 if (ha->wq)
1215 flush_workqueue(ha->wq);
1216
1217 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1218 if (ha->isp_ops->abort_isp(base_vha)) {
1219 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1220 /* failed. schedule dpc to try */
1221 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1222
1223 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
1224 ql_log(ql_log_warn, vha, 0x802a,
1225 "wait for hba online failed.\n");
1226 goto eh_host_reset_lock;
1227 }
1228 }
1229 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1230 }
1231
1232 /* Waiting for command to be returned to OS.*/
1233 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST) ==
1234 QLA_SUCCESS)
1235 ret = SUCCESS;
1236
1237 eh_host_reset_lock:
1238 ql_log(ql_log_info, vha, 0x8017,
1239 "ADAPTER RESET %s nexus=%ld:%d:%d.\n",
1240 (ret == FAILED) ? "FAILED" : "SUCCEEDED", vha->host_no, id, lun);
1241
1242 return ret;
1243 }
1244
1245 /*
1246 * qla2x00_loop_reset
1247 * Issue loop reset.
1248 *
1249 * Input:
1250 * ha = adapter block pointer.
1251 *
1252 * Returns:
1253 * 0 = success
1254 */
1255 int
1256 qla2x00_loop_reset(scsi_qla_host_t *vha)
1257 {
1258 int ret;
1259 struct fc_port *fcport;
1260 struct qla_hw_data *ha = vha->hw;
1261
1262 if (ql2xtargetreset == 1 && ha->flags.enable_target_reset) {
1263 list_for_each_entry(fcport, &vha->vp_fcports, list) {
1264 if (fcport->port_type != FCT_TARGET)
1265 continue;
1266
1267 ret = ha->isp_ops->target_reset(fcport, 0, 0);
1268 if (ret != QLA_SUCCESS) {
1269 ql_dbg(ql_dbg_taskm, vha, 0x802c,
1270 "Bus Reset failed: Target Reset=%d "
1271 "d_id=%x.\n", ret, fcport->d_id.b24);
1272 }
1273 }
1274 }
1275
1276 if (ha->flags.enable_lip_full_login && !IS_CNA_CAPABLE(ha)) {
1277 ret = qla2x00_full_login_lip(vha);
1278 if (ret != QLA_SUCCESS) {
1279 ql_dbg(ql_dbg_taskm, vha, 0x802d,
1280 "full_login_lip=%d.\n", ret);
1281 }
1282 atomic_set(&vha->loop_state, LOOP_DOWN);
1283 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1284 qla2x00_mark_all_devices_lost(vha, 0);
1285 }
1286
1287 if (ha->flags.enable_lip_reset) {
1288 ret = qla2x00_lip_reset(vha);
1289 if (ret != QLA_SUCCESS)
1290 ql_dbg(ql_dbg_taskm, vha, 0x802e,
1291 "lip_reset failed (%d).\n", ret);
1292 }
1293
1294 /* Issue marker command only when we are going to start the I/O */
1295 vha->marker_needed = 1;
1296
1297 return QLA_SUCCESS;
1298 }
1299
1300 void
1301 qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
1302 {
1303 int que, cnt;
1304 unsigned long flags;
1305 srb_t *sp;
1306 struct qla_hw_data *ha = vha->hw;
1307 struct req_que *req;
1308
1309 spin_lock_irqsave(&ha->hardware_lock, flags);
1310 for (que = 0; que < ha->max_req_queues; que++) {
1311 req = ha->req_q_map[que];
1312 if (!req)
1313 continue;
1314 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1315 sp = req->outstanding_cmds[cnt];
1316 if (sp) {
1317 req->outstanding_cmds[cnt] = NULL;
1318 sp->done(vha, sp, res);
1319 }
1320 }
1321 }
1322 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1323 }
1324
1325 static int
1326 qla2xxx_slave_alloc(struct scsi_device *sdev)
1327 {
1328 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
1329
1330 if (!rport || fc_remote_port_chkready(rport))
1331 return -ENXIO;
1332
1333 sdev->hostdata = *(fc_port_t **)rport->dd_data;
1334
1335 return 0;
1336 }
1337
1338 static int
1339 qla2xxx_slave_configure(struct scsi_device *sdev)
1340 {
1341 scsi_qla_host_t *vha = shost_priv(sdev->host);
1342 struct req_que *req = vha->req;
1343
1344 if (sdev->tagged_supported)
1345 scsi_activate_tcq(sdev, req->max_q_depth);
1346 else
1347 scsi_deactivate_tcq(sdev, req->max_q_depth);
1348 return 0;
1349 }
1350
1351 static void
1352 qla2xxx_slave_destroy(struct scsi_device *sdev)
1353 {
1354 sdev->hostdata = NULL;
1355 }
1356
1357 static void qla2x00_handle_queue_full(struct scsi_device *sdev, int qdepth)
1358 {
1359 fc_port_t *fcport = (struct fc_port *) sdev->hostdata;
1360
1361 if (!scsi_track_queue_full(sdev, qdepth))
1362 return;
1363
1364 ql_dbg(ql_dbg_io, fcport->vha, 0x3029,
1365 "Queue depth adjusted-down to %d for nexus=%ld:%d:%d.\n",
1366 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1367 }
1368
1369 static void qla2x00_adjust_sdev_qdepth_up(struct scsi_device *sdev, int qdepth)
1370 {
1371 fc_port_t *fcport = sdev->hostdata;
1372 struct scsi_qla_host *vha = fcport->vha;
1373 struct req_que *req = NULL;
1374
1375 req = vha->req;
1376 if (!req)
1377 return;
1378
1379 if (req->max_q_depth <= sdev->queue_depth || req->max_q_depth < qdepth)
1380 return;
1381
1382 if (sdev->ordered_tags)
1383 scsi_adjust_queue_depth(sdev, MSG_ORDERED_TAG, qdepth);
1384 else
1385 scsi_adjust_queue_depth(sdev, MSG_SIMPLE_TAG, qdepth);
1386
1387 ql_dbg(ql_dbg_io, vha, 0x302a,
1388 "Queue depth adjusted-up to %d for nexus=%ld:%d:%d.\n",
1389 sdev->queue_depth, fcport->vha->host_no, sdev->id, sdev->lun);
1390 }
1391
1392 static int
1393 qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth, int reason)
1394 {
1395 switch (reason) {
1396 case SCSI_QDEPTH_DEFAULT:
1397 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1398 break;
1399 case SCSI_QDEPTH_QFULL:
1400 qla2x00_handle_queue_full(sdev, qdepth);
1401 break;
1402 case SCSI_QDEPTH_RAMP_UP:
1403 qla2x00_adjust_sdev_qdepth_up(sdev, qdepth);
1404 break;
1405 default:
1406 return -EOPNOTSUPP;
1407 }
1408
1409 return sdev->queue_depth;
1410 }
1411
1412 static int
1413 qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1414 {
1415 if (sdev->tagged_supported) {
1416 scsi_set_tag_type(sdev, tag_type);
1417 if (tag_type)
1418 scsi_activate_tcq(sdev, sdev->queue_depth);
1419 else
1420 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1421 } else
1422 tag_type = 0;
1423
1424 return tag_type;
1425 }
1426
1427 /**
1428 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1429 * @ha: HA context
1430 *
1431 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1432 * supported addressing method.
1433 */
1434 static void
1435 qla2x00_config_dma_addressing(struct qla_hw_data *ha)
1436 {
1437 /* Assume a 32bit DMA mask. */
1438 ha->flags.enable_64bit_addressing = 0;
1439
1440 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
1441 /* Any upper-dword bits set? */
1442 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
1443 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
1444 /* Ok, a 64bit DMA mask is applicable. */
1445 ha->flags.enable_64bit_addressing = 1;
1446 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1447 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
1448 return;
1449 }
1450 }
1451
1452 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1453 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
1454 }
1455
1456 static void
1457 qla2x00_enable_intrs(struct qla_hw_data *ha)
1458 {
1459 unsigned long flags = 0;
1460 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1461
1462 spin_lock_irqsave(&ha->hardware_lock, flags);
1463 ha->interrupts_on = 1;
1464 /* enable risc and host interrupts */
1465 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1466 RD_REG_WORD(&reg->ictrl);
1467 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1468
1469 }
1470
1471 static void
1472 qla2x00_disable_intrs(struct qla_hw_data *ha)
1473 {
1474 unsigned long flags = 0;
1475 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1476
1477 spin_lock_irqsave(&ha->hardware_lock, flags);
1478 ha->interrupts_on = 0;
1479 /* disable risc and host interrupts */
1480 WRT_REG_WORD(&reg->ictrl, 0);
1481 RD_REG_WORD(&reg->ictrl);
1482 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1483 }
1484
1485 static void
1486 qla24xx_enable_intrs(struct qla_hw_data *ha)
1487 {
1488 unsigned long flags = 0;
1489 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1490
1491 spin_lock_irqsave(&ha->hardware_lock, flags);
1492 ha->interrupts_on = 1;
1493 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1494 RD_REG_DWORD(&reg->ictrl);
1495 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1496 }
1497
1498 static void
1499 qla24xx_disable_intrs(struct qla_hw_data *ha)
1500 {
1501 unsigned long flags = 0;
1502 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1503
1504 if (IS_NOPOLLING_TYPE(ha))
1505 return;
1506 spin_lock_irqsave(&ha->hardware_lock, flags);
1507 ha->interrupts_on = 0;
1508 WRT_REG_DWORD(&reg->ictrl, 0);
1509 RD_REG_DWORD(&reg->ictrl);
1510 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1511 }
1512
1513 static int
1514 qla2x00_iospace_config(struct qla_hw_data *ha)
1515 {
1516 resource_size_t pio;
1517 uint16_t msix;
1518 int cpus;
1519
1520 if (pci_request_selected_regions(ha->pdev, ha->bars,
1521 QLA2XXX_DRIVER_NAME)) {
1522 ql_log_pci(ql_log_fatal, ha->pdev, 0x0011,
1523 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1524 pci_name(ha->pdev));
1525 goto iospace_error_exit;
1526 }
1527 if (!(ha->bars & 1))
1528 goto skip_pio;
1529
1530 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1531 pio = pci_resource_start(ha->pdev, 0);
1532 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1533 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1534 ql_log_pci(ql_log_warn, ha->pdev, 0x0012,
1535 "Invalid pci I/O region size (%s).\n",
1536 pci_name(ha->pdev));
1537 pio = 0;
1538 }
1539 } else {
1540 ql_log_pci(ql_log_warn, ha->pdev, 0x0013,
1541 "Region #0 no a PIO resource (%s).\n",
1542 pci_name(ha->pdev));
1543 pio = 0;
1544 }
1545 ha->pio_address = pio;
1546 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0014,
1547 "PIO address=%llu.\n",
1548 (unsigned long long)ha->pio_address);
1549
1550 skip_pio:
1551 /* Use MMIO operations for all accesses. */
1552 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
1553 ql_log_pci(ql_log_fatal, ha->pdev, 0x0015,
1554 "Region #1 not an MMIO resource (%s), aborting.\n",
1555 pci_name(ha->pdev));
1556 goto iospace_error_exit;
1557 }
1558 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
1559 ql_log_pci(ql_log_fatal, ha->pdev, 0x0016,
1560 "Invalid PCI mem region size (%s), aborting.\n",
1561 pci_name(ha->pdev));
1562 goto iospace_error_exit;
1563 }
1564
1565 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
1566 if (!ha->iobase) {
1567 ql_log_pci(ql_log_fatal, ha->pdev, 0x0017,
1568 "Cannot remap MMIO (%s), aborting.\n",
1569 pci_name(ha->pdev));
1570 goto iospace_error_exit;
1571 }
1572
1573 /* Determine queue resources */
1574 ha->max_req_queues = ha->max_rsp_queues = 1;
1575 if ((ql2xmaxqueues <= 1 && !ql2xmultique_tag) ||
1576 (ql2xmaxqueues > 1 && ql2xmultique_tag) ||
1577 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
1578 goto mqiobase_exit;
1579
1580 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1581 pci_resource_len(ha->pdev, 3));
1582 if (ha->mqiobase) {
1583 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0018,
1584 "MQIO Base=%p.\n", ha->mqiobase);
1585 /* Read MSIX vector size of the board */
1586 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1587 ha->msix_count = msix;
1588 /* Max queues are bounded by available msix vectors */
1589 /* queue 0 uses two msix vectors */
1590 if (ql2xmultique_tag) {
1591 cpus = num_online_cpus();
1592 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1593 (cpus + 1) : (ha->msix_count - 1);
1594 ha->max_req_queues = 2;
1595 } else if (ql2xmaxqueues > 1) {
1596 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1597 QLA_MQ_SIZE : ql2xmaxqueues;
1598 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc008,
1599 "QoS mode set, max no of request queues:%d.\n",
1600 ha->max_req_queues);
1601 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0019,
1602 "QoS mode set, max no of request queues:%d.\n",
1603 ha->max_req_queues);
1604 }
1605 ql_log_pci(ql_log_info, ha->pdev, 0x001a,
1606 "MSI-X vector count: %d.\n", msix);
1607 } else
1608 ql_log_pci(ql_log_info, ha->pdev, 0x001b,
1609 "BAR 3 not enabled.\n");
1610
1611 mqiobase_exit:
1612 ha->msix_count = ha->max_rsp_queues + 1;
1613 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x001c,
1614 "MSIX Count:%d.\n", ha->msix_count);
1615 return (0);
1616
1617 iospace_error_exit:
1618 return (-ENOMEM);
1619 }
1620
1621
1622 static int
1623 qla83xx_iospace_config(struct qla_hw_data *ha)
1624 {
1625 uint16_t msix;
1626 int cpus;
1627
1628 if (pci_request_selected_regions(ha->pdev, ha->bars,
1629 QLA2XXX_DRIVER_NAME)) {
1630 ql_log_pci(ql_log_fatal, ha->pdev, 0x0117,
1631 "Failed to reserve PIO/MMIO regions (%s), aborting.\n",
1632 pci_name(ha->pdev));
1633
1634 goto iospace_error_exit;
1635 }
1636
1637 /* Use MMIO operations for all accesses. */
1638 if (!(pci_resource_flags(ha->pdev, 0) & IORESOURCE_MEM)) {
1639 ql_log_pci(ql_log_warn, ha->pdev, 0x0118,
1640 "Invalid pci I/O region size (%s).\n",
1641 pci_name(ha->pdev));
1642 goto iospace_error_exit;
1643 }
1644 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
1645 ql_log_pci(ql_log_warn, ha->pdev, 0x0119,
1646 "Invalid PCI mem region size (%s), aborting\n",
1647 pci_name(ha->pdev));
1648 goto iospace_error_exit;
1649 }
1650
1651 ha->iobase = ioremap(pci_resource_start(ha->pdev, 0), MIN_IOBASE_LEN);
1652 if (!ha->iobase) {
1653 ql_log_pci(ql_log_fatal, ha->pdev, 0x011a,
1654 "Cannot remap MMIO (%s), aborting.\n",
1655 pci_name(ha->pdev));
1656 goto iospace_error_exit;
1657 }
1658
1659 /* 64bit PCI BAR - BAR2 will correspoond to region 4 */
1660 /* 83XX 26XX always use MQ type access for queues
1661 * - mbar 2, a.k.a region 4 */
1662 ha->max_req_queues = ha->max_rsp_queues = 1;
1663 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 4),
1664 pci_resource_len(ha->pdev, 4));
1665
1666 if (!ha->mqiobase) {
1667 ql_log_pci(ql_log_fatal, ha->pdev, 0x011d,
1668 "BAR2/region4 not enabled\n");
1669 goto mqiobase_exit;
1670 }
1671
1672 ha->msixbase = ioremap(pci_resource_start(ha->pdev, 2),
1673 pci_resource_len(ha->pdev, 2));
1674 if (ha->msixbase) {
1675 /* Read MSIX vector size of the board */
1676 pci_read_config_word(ha->pdev,
1677 QLA_83XX_PCI_MSIX_CONTROL, &msix);
1678 ha->msix_count = msix;
1679 /* Max queues are bounded by available msix vectors */
1680 /* queue 0 uses two msix vectors */
1681 if (ql2xmultique_tag) {
1682 cpus = num_online_cpus();
1683 ha->max_rsp_queues = (ha->msix_count - 1 > cpus) ?
1684 (cpus + 1) : (ha->msix_count - 1);
1685 ha->max_req_queues = 2;
1686 } else if (ql2xmaxqueues > 1) {
1687 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1688 QLA_MQ_SIZE : ql2xmaxqueues;
1689 ql_dbg_pci(ql_dbg_multiq, ha->pdev, 0xc00c,
1690 "QoS mode set, max no of request queues:%d.\n",
1691 ha->max_req_queues);
1692 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011b,
1693 "QoS mode set, max no of request queues:%d.\n",
1694 ha->max_req_queues);
1695 }
1696 ql_log_pci(ql_log_info, ha->pdev, 0x011c,
1697 "MSI-X vector count: %d.\n", msix);
1698 } else
1699 ql_log_pci(ql_log_info, ha->pdev, 0x011e,
1700 "BAR 1 not enabled.\n");
1701
1702 mqiobase_exit:
1703 ha->msix_count = ha->max_rsp_queues + 1;
1704 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x011f,
1705 "MSIX Count:%d.\n", ha->msix_count);
1706 return 0;
1707
1708 iospace_error_exit:
1709 return -ENOMEM;
1710 }
1711
1712 static struct isp_operations qla2100_isp_ops = {
1713 .pci_config = qla2100_pci_config,
1714 .reset_chip = qla2x00_reset_chip,
1715 .chip_diag = qla2x00_chip_diag,
1716 .config_rings = qla2x00_config_rings,
1717 .reset_adapter = qla2x00_reset_adapter,
1718 .nvram_config = qla2x00_nvram_config,
1719 .update_fw_options = qla2x00_update_fw_options,
1720 .load_risc = qla2x00_load_risc,
1721 .pci_info_str = qla2x00_pci_info_str,
1722 .fw_version_str = qla2x00_fw_version_str,
1723 .intr_handler = qla2100_intr_handler,
1724 .enable_intrs = qla2x00_enable_intrs,
1725 .disable_intrs = qla2x00_disable_intrs,
1726 .abort_command = qla2x00_abort_command,
1727 .target_reset = qla2x00_abort_target,
1728 .lun_reset = qla2x00_lun_reset,
1729 .fabric_login = qla2x00_login_fabric,
1730 .fabric_logout = qla2x00_fabric_logout,
1731 .calc_req_entries = qla2x00_calc_iocbs_32,
1732 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1733 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1734 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1735 .read_nvram = qla2x00_read_nvram_data,
1736 .write_nvram = qla2x00_write_nvram_data,
1737 .fw_dump = qla2100_fw_dump,
1738 .beacon_on = NULL,
1739 .beacon_off = NULL,
1740 .beacon_blink = NULL,
1741 .read_optrom = qla2x00_read_optrom_data,
1742 .write_optrom = qla2x00_write_optrom_data,
1743 .get_flash_version = qla2x00_get_flash_version,
1744 .start_scsi = qla2x00_start_scsi,
1745 .abort_isp = qla2x00_abort_isp,
1746 .iospace_config = qla2x00_iospace_config,
1747 };
1748
1749 static struct isp_operations qla2300_isp_ops = {
1750 .pci_config = qla2300_pci_config,
1751 .reset_chip = qla2x00_reset_chip,
1752 .chip_diag = qla2x00_chip_diag,
1753 .config_rings = qla2x00_config_rings,
1754 .reset_adapter = qla2x00_reset_adapter,
1755 .nvram_config = qla2x00_nvram_config,
1756 .update_fw_options = qla2x00_update_fw_options,
1757 .load_risc = qla2x00_load_risc,
1758 .pci_info_str = qla2x00_pci_info_str,
1759 .fw_version_str = qla2x00_fw_version_str,
1760 .intr_handler = qla2300_intr_handler,
1761 .enable_intrs = qla2x00_enable_intrs,
1762 .disable_intrs = qla2x00_disable_intrs,
1763 .abort_command = qla2x00_abort_command,
1764 .target_reset = qla2x00_abort_target,
1765 .lun_reset = qla2x00_lun_reset,
1766 .fabric_login = qla2x00_login_fabric,
1767 .fabric_logout = qla2x00_fabric_logout,
1768 .calc_req_entries = qla2x00_calc_iocbs_32,
1769 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1770 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1771 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1772 .read_nvram = qla2x00_read_nvram_data,
1773 .write_nvram = qla2x00_write_nvram_data,
1774 .fw_dump = qla2300_fw_dump,
1775 .beacon_on = qla2x00_beacon_on,
1776 .beacon_off = qla2x00_beacon_off,
1777 .beacon_blink = qla2x00_beacon_blink,
1778 .read_optrom = qla2x00_read_optrom_data,
1779 .write_optrom = qla2x00_write_optrom_data,
1780 .get_flash_version = qla2x00_get_flash_version,
1781 .start_scsi = qla2x00_start_scsi,
1782 .abort_isp = qla2x00_abort_isp,
1783 .iospace_config = qla2x00_iospace_config,
1784 };
1785
1786 static struct isp_operations qla24xx_isp_ops = {
1787 .pci_config = qla24xx_pci_config,
1788 .reset_chip = qla24xx_reset_chip,
1789 .chip_diag = qla24xx_chip_diag,
1790 .config_rings = qla24xx_config_rings,
1791 .reset_adapter = qla24xx_reset_adapter,
1792 .nvram_config = qla24xx_nvram_config,
1793 .update_fw_options = qla24xx_update_fw_options,
1794 .load_risc = qla24xx_load_risc,
1795 .pci_info_str = qla24xx_pci_info_str,
1796 .fw_version_str = qla24xx_fw_version_str,
1797 .intr_handler = qla24xx_intr_handler,
1798 .enable_intrs = qla24xx_enable_intrs,
1799 .disable_intrs = qla24xx_disable_intrs,
1800 .abort_command = qla24xx_abort_command,
1801 .target_reset = qla24xx_abort_target,
1802 .lun_reset = qla24xx_lun_reset,
1803 .fabric_login = qla24xx_login_fabric,
1804 .fabric_logout = qla24xx_fabric_logout,
1805 .calc_req_entries = NULL,
1806 .build_iocbs = NULL,
1807 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1808 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1809 .read_nvram = qla24xx_read_nvram_data,
1810 .write_nvram = qla24xx_write_nvram_data,
1811 .fw_dump = qla24xx_fw_dump,
1812 .beacon_on = qla24xx_beacon_on,
1813 .beacon_off = qla24xx_beacon_off,
1814 .beacon_blink = qla24xx_beacon_blink,
1815 .read_optrom = qla24xx_read_optrom_data,
1816 .write_optrom = qla24xx_write_optrom_data,
1817 .get_flash_version = qla24xx_get_flash_version,
1818 .start_scsi = qla24xx_start_scsi,
1819 .abort_isp = qla2x00_abort_isp,
1820 .iospace_config = qla2x00_iospace_config,
1821 };
1822
1823 static struct isp_operations qla25xx_isp_ops = {
1824 .pci_config = qla25xx_pci_config,
1825 .reset_chip = qla24xx_reset_chip,
1826 .chip_diag = qla24xx_chip_diag,
1827 .config_rings = qla24xx_config_rings,
1828 .reset_adapter = qla24xx_reset_adapter,
1829 .nvram_config = qla24xx_nvram_config,
1830 .update_fw_options = qla24xx_update_fw_options,
1831 .load_risc = qla24xx_load_risc,
1832 .pci_info_str = qla24xx_pci_info_str,
1833 .fw_version_str = qla24xx_fw_version_str,
1834 .intr_handler = qla24xx_intr_handler,
1835 .enable_intrs = qla24xx_enable_intrs,
1836 .disable_intrs = qla24xx_disable_intrs,
1837 .abort_command = qla24xx_abort_command,
1838 .target_reset = qla24xx_abort_target,
1839 .lun_reset = qla24xx_lun_reset,
1840 .fabric_login = qla24xx_login_fabric,
1841 .fabric_logout = qla24xx_fabric_logout,
1842 .calc_req_entries = NULL,
1843 .build_iocbs = NULL,
1844 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1845 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1846 .read_nvram = qla25xx_read_nvram_data,
1847 .write_nvram = qla25xx_write_nvram_data,
1848 .fw_dump = qla25xx_fw_dump,
1849 .beacon_on = qla24xx_beacon_on,
1850 .beacon_off = qla24xx_beacon_off,
1851 .beacon_blink = qla24xx_beacon_blink,
1852 .read_optrom = qla25xx_read_optrom_data,
1853 .write_optrom = qla24xx_write_optrom_data,
1854 .get_flash_version = qla24xx_get_flash_version,
1855 .start_scsi = qla24xx_dif_start_scsi,
1856 .abort_isp = qla2x00_abort_isp,
1857 .iospace_config = qla2x00_iospace_config,
1858 };
1859
1860 static struct isp_operations qla81xx_isp_ops = {
1861 .pci_config = qla25xx_pci_config,
1862 .reset_chip = qla24xx_reset_chip,
1863 .chip_diag = qla24xx_chip_diag,
1864 .config_rings = qla24xx_config_rings,
1865 .reset_adapter = qla24xx_reset_adapter,
1866 .nvram_config = qla81xx_nvram_config,
1867 .update_fw_options = qla81xx_update_fw_options,
1868 .load_risc = qla81xx_load_risc,
1869 .pci_info_str = qla24xx_pci_info_str,
1870 .fw_version_str = qla24xx_fw_version_str,
1871 .intr_handler = qla24xx_intr_handler,
1872 .enable_intrs = qla24xx_enable_intrs,
1873 .disable_intrs = qla24xx_disable_intrs,
1874 .abort_command = qla24xx_abort_command,
1875 .target_reset = qla24xx_abort_target,
1876 .lun_reset = qla24xx_lun_reset,
1877 .fabric_login = qla24xx_login_fabric,
1878 .fabric_logout = qla24xx_fabric_logout,
1879 .calc_req_entries = NULL,
1880 .build_iocbs = NULL,
1881 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1882 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1883 .read_nvram = NULL,
1884 .write_nvram = NULL,
1885 .fw_dump = qla81xx_fw_dump,
1886 .beacon_on = qla24xx_beacon_on,
1887 .beacon_off = qla24xx_beacon_off,
1888 .beacon_blink = qla83xx_beacon_blink,
1889 .read_optrom = qla25xx_read_optrom_data,
1890 .write_optrom = qla24xx_write_optrom_data,
1891 .get_flash_version = qla24xx_get_flash_version,
1892 .start_scsi = qla24xx_dif_start_scsi,
1893 .abort_isp = qla2x00_abort_isp,
1894 .iospace_config = qla2x00_iospace_config,
1895 };
1896
1897 static struct isp_operations qla82xx_isp_ops = {
1898 .pci_config = qla82xx_pci_config,
1899 .reset_chip = qla82xx_reset_chip,
1900 .chip_diag = qla24xx_chip_diag,
1901 .config_rings = qla82xx_config_rings,
1902 .reset_adapter = qla24xx_reset_adapter,
1903 .nvram_config = qla81xx_nvram_config,
1904 .update_fw_options = qla24xx_update_fw_options,
1905 .load_risc = qla82xx_load_risc,
1906 .pci_info_str = qla82xx_pci_info_str,
1907 .fw_version_str = qla24xx_fw_version_str,
1908 .intr_handler = qla82xx_intr_handler,
1909 .enable_intrs = qla82xx_enable_intrs,
1910 .disable_intrs = qla82xx_disable_intrs,
1911 .abort_command = qla24xx_abort_command,
1912 .target_reset = qla24xx_abort_target,
1913 .lun_reset = qla24xx_lun_reset,
1914 .fabric_login = qla24xx_login_fabric,
1915 .fabric_logout = qla24xx_fabric_logout,
1916 .calc_req_entries = NULL,
1917 .build_iocbs = NULL,
1918 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1919 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1920 .read_nvram = qla24xx_read_nvram_data,
1921 .write_nvram = qla24xx_write_nvram_data,
1922 .fw_dump = qla24xx_fw_dump,
1923 .beacon_on = qla82xx_beacon_on,
1924 .beacon_off = qla82xx_beacon_off,
1925 .beacon_blink = NULL,
1926 .read_optrom = qla82xx_read_optrom_data,
1927 .write_optrom = qla82xx_write_optrom_data,
1928 .get_flash_version = qla24xx_get_flash_version,
1929 .start_scsi = qla82xx_start_scsi,
1930 .abort_isp = qla82xx_abort_isp,
1931 .iospace_config = qla82xx_iospace_config,
1932 };
1933
1934 static struct isp_operations qla83xx_isp_ops = {
1935 .pci_config = qla25xx_pci_config,
1936 .reset_chip = qla24xx_reset_chip,
1937 .chip_diag = qla24xx_chip_diag,
1938 .config_rings = qla24xx_config_rings,
1939 .reset_adapter = qla24xx_reset_adapter,
1940 .nvram_config = qla81xx_nvram_config,
1941 .update_fw_options = qla81xx_update_fw_options,
1942 .load_risc = qla81xx_load_risc,
1943 .pci_info_str = qla24xx_pci_info_str,
1944 .fw_version_str = qla24xx_fw_version_str,
1945 .intr_handler = qla24xx_intr_handler,
1946 .enable_intrs = qla24xx_enable_intrs,
1947 .disable_intrs = qla24xx_disable_intrs,
1948 .abort_command = qla24xx_abort_command,
1949 .target_reset = qla24xx_abort_target,
1950 .lun_reset = qla24xx_lun_reset,
1951 .fabric_login = qla24xx_login_fabric,
1952 .fabric_logout = qla24xx_fabric_logout,
1953 .calc_req_entries = NULL,
1954 .build_iocbs = NULL,
1955 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1956 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1957 .read_nvram = NULL,
1958 .write_nvram = NULL,
1959 .fw_dump = qla83xx_fw_dump,
1960 .beacon_on = qla24xx_beacon_on,
1961 .beacon_off = qla24xx_beacon_off,
1962 .beacon_blink = qla83xx_beacon_blink,
1963 .read_optrom = qla25xx_read_optrom_data,
1964 .write_optrom = qla24xx_write_optrom_data,
1965 .get_flash_version = qla24xx_get_flash_version,
1966 .start_scsi = qla24xx_dif_start_scsi,
1967 .abort_isp = qla2x00_abort_isp,
1968 .iospace_config = qla83xx_iospace_config,
1969 };
1970
1971 static inline void
1972 qla2x00_set_isp_flags(struct qla_hw_data *ha)
1973 {
1974 ha->device_type = DT_EXTENDED_IDS;
1975 switch (ha->pdev->device) {
1976 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1977 ha->device_type |= DT_ISP2100;
1978 ha->device_type &= ~DT_EXTENDED_IDS;
1979 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1980 break;
1981 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1982 ha->device_type |= DT_ISP2200;
1983 ha->device_type &= ~DT_EXTENDED_IDS;
1984 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
1985 break;
1986 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1987 ha->device_type |= DT_ISP2300;
1988 ha->device_type |= DT_ZIO_SUPPORTED;
1989 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1990 break;
1991 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1992 ha->device_type |= DT_ISP2312;
1993 ha->device_type |= DT_ZIO_SUPPORTED;
1994 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
1995 break;
1996 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1997 ha->device_type |= DT_ISP2322;
1998 ha->device_type |= DT_ZIO_SUPPORTED;
1999 if (ha->pdev->subsystem_vendor == 0x1028 &&
2000 ha->pdev->subsystem_device == 0x0170)
2001 ha->device_type |= DT_OEM_001;
2002 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2003 break;
2004 case PCI_DEVICE_ID_QLOGIC_ISP6312:
2005 ha->device_type |= DT_ISP6312;
2006 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2007 break;
2008 case PCI_DEVICE_ID_QLOGIC_ISP6322:
2009 ha->device_type |= DT_ISP6322;
2010 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
2011 break;
2012 case PCI_DEVICE_ID_QLOGIC_ISP2422:
2013 ha->device_type |= DT_ISP2422;
2014 ha->device_type |= DT_ZIO_SUPPORTED;
2015 ha->device_type |= DT_FWI2;
2016 ha->device_type |= DT_IIDMA;
2017 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2018 break;
2019 case PCI_DEVICE_ID_QLOGIC_ISP2432:
2020 ha->device_type |= DT_ISP2432;
2021 ha->device_type |= DT_ZIO_SUPPORTED;
2022 ha->device_type |= DT_FWI2;
2023 ha->device_type |= DT_IIDMA;
2024 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2025 break;
2026 case PCI_DEVICE_ID_QLOGIC_ISP8432:
2027 ha->device_type |= DT_ISP8432;
2028 ha->device_type |= DT_ZIO_SUPPORTED;
2029 ha->device_type |= DT_FWI2;
2030 ha->device_type |= DT_IIDMA;
2031 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2032 break;
2033 case PCI_DEVICE_ID_QLOGIC_ISP5422:
2034 ha->device_type |= DT_ISP5422;
2035 ha->device_type |= DT_FWI2;
2036 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2037 break;
2038 case PCI_DEVICE_ID_QLOGIC_ISP5432:
2039 ha->device_type |= DT_ISP5432;
2040 ha->device_type |= DT_FWI2;
2041 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2042 break;
2043 case PCI_DEVICE_ID_QLOGIC_ISP2532:
2044 ha->device_type |= DT_ISP2532;
2045 ha->device_type |= DT_ZIO_SUPPORTED;
2046 ha->device_type |= DT_FWI2;
2047 ha->device_type |= DT_IIDMA;
2048 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2049 break;
2050 case PCI_DEVICE_ID_QLOGIC_ISP8001:
2051 ha->device_type |= DT_ISP8001;
2052 ha->device_type |= DT_ZIO_SUPPORTED;
2053 ha->device_type |= DT_FWI2;
2054 ha->device_type |= DT_IIDMA;
2055 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2056 break;
2057 case PCI_DEVICE_ID_QLOGIC_ISP8021:
2058 ha->device_type |= DT_ISP8021;
2059 ha->device_type |= DT_ZIO_SUPPORTED;
2060 ha->device_type |= DT_FWI2;
2061 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2062 /* Initialize 82XX ISP flags */
2063 qla82xx_init_flags(ha);
2064 break;
2065 case PCI_DEVICE_ID_QLOGIC_ISP2031:
2066 ha->device_type |= DT_ISP2031;
2067 ha->device_type |= DT_ZIO_SUPPORTED;
2068 ha->device_type |= DT_FWI2;
2069 ha->device_type |= DT_IIDMA;
2070 ha->device_type |= DT_T10_PI;
2071 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2072 break;
2073 case PCI_DEVICE_ID_QLOGIC_ISP8031:
2074 ha->device_type |= DT_ISP8031;
2075 ha->device_type |= DT_ZIO_SUPPORTED;
2076 ha->device_type |= DT_FWI2;
2077 ha->device_type |= DT_IIDMA;
2078 ha->device_type |= DT_T10_PI;
2079 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
2080 break;
2081 }
2082
2083 if (IS_QLA82XX(ha))
2084 ha->port_no = !(ha->portnum & 1);
2085 else
2086 /* Get adapter physical port no from interrupt pin register. */
2087 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
2088
2089 if (ha->port_no & 1)
2090 ha->flags.port0 = 1;
2091 else
2092 ha->flags.port0 = 0;
2093 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x000b,
2094 "device_type=0x%x port=%d fw_srisc_address=0x%x.\n",
2095 ha->device_type, ha->flags.port0, ha->fw_srisc_address);
2096 }
2097
2098 static void
2099 qla2xxx_scan_start(struct Scsi_Host *shost)
2100 {
2101 scsi_qla_host_t *vha = shost_priv(shost);
2102
2103 if (vha->hw->flags.running_gold_fw)
2104 return;
2105
2106 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
2107 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
2108 set_bit(RSCN_UPDATE, &vha->dpc_flags);
2109 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
2110 }
2111
2112 static int
2113 qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
2114 {
2115 scsi_qla_host_t *vha = shost_priv(shost);
2116
2117 if (!vha->host)
2118 return 1;
2119 if (time > vha->hw->loop_reset_delay * HZ)
2120 return 1;
2121
2122 return atomic_read(&vha->loop_state) == LOOP_READY;
2123 }
2124
2125 /*
2126 * PCI driver interface
2127 */
2128 static int __devinit
2129 qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
2130 {
2131 int ret = -ENODEV;
2132 struct Scsi_Host *host;
2133 scsi_qla_host_t *base_vha = NULL;
2134 struct qla_hw_data *ha;
2135 char pci_info[30];
2136 char fw_str[30];
2137 struct scsi_host_template *sht;
2138 int bars, max_id, mem_only = 0;
2139 uint16_t req_length = 0, rsp_length = 0;
2140 struct req_que *req = NULL;
2141 struct rsp_que *rsp = NULL;
2142
2143 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
2144 sht = &qla2xxx_driver_template;
2145 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
2146 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
2147 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
2148 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
2149 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
2150 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
2151 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001 ||
2152 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8021 ||
2153 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2031 ||
2154 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8031) {
2155 bars = pci_select_bars(pdev, IORESOURCE_MEM);
2156 mem_only = 1;
2157 ql_dbg_pci(ql_dbg_init, pdev, 0x0007,
2158 "Mem only adapter.\n");
2159 }
2160 ql_dbg_pci(ql_dbg_init, pdev, 0x0008,
2161 "Bars=%d.\n", bars);
2162
2163 if (mem_only) {
2164 if (pci_enable_device_mem(pdev))
2165 goto probe_out;
2166 } else {
2167 if (pci_enable_device(pdev))
2168 goto probe_out;
2169 }
2170
2171 /* This may fail but that's ok */
2172 pci_enable_pcie_error_reporting(pdev);
2173
2174 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
2175 if (!ha) {
2176 ql_log_pci(ql_log_fatal, pdev, 0x0009,
2177 "Unable to allocate memory for ha.\n");
2178 goto probe_out;
2179 }
2180 ql_dbg_pci(ql_dbg_init, pdev, 0x000a,
2181 "Memory allocated for ha=%p.\n", ha);
2182 ha->pdev = pdev;
2183
2184 /* Clear our data area */
2185 ha->bars = bars;
2186 ha->mem_only = mem_only;
2187 spin_lock_init(&ha->hardware_lock);
2188 spin_lock_init(&ha->vport_slock);
2189
2190 /* Set ISP-type information. */
2191 qla2x00_set_isp_flags(ha);
2192
2193 /* Set EEH reset type to fundamental if required by hba */
2194 if (IS_QLA24XX(ha) || IS_QLA25XX(ha) || IS_QLA81XX(ha))
2195 pdev->needs_freset = 1;
2196
2197 ha->prev_topology = 0;
2198 ha->init_cb_size = sizeof(init_cb_t);
2199 ha->link_data_rate = PORT_SPEED_UNKNOWN;
2200 ha->optrom_size = OPTROM_SIZE_2300;
2201
2202 /* Assign ISP specific operations. */
2203 max_id = MAX_TARGETS_2200;
2204 if (IS_QLA2100(ha)) {
2205 max_id = MAX_TARGETS_2100;
2206 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
2207 req_length = REQUEST_ENTRY_CNT_2100;
2208 rsp_length = RESPONSE_ENTRY_CNT_2100;
2209 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2210 ha->gid_list_info_size = 4;
2211 ha->flash_conf_off = ~0;
2212 ha->flash_data_off = ~0;
2213 ha->nvram_conf_off = ~0;
2214 ha->nvram_data_off = ~0;
2215 ha->isp_ops = &qla2100_isp_ops;
2216 } else if (IS_QLA2200(ha)) {
2217 ha->mbx_count = MAILBOX_REGISTER_COUNT_2200;
2218 req_length = REQUEST_ENTRY_CNT_2200;
2219 rsp_length = RESPONSE_ENTRY_CNT_2100;
2220 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
2221 ha->gid_list_info_size = 4;
2222 ha->flash_conf_off = ~0;
2223 ha->flash_data_off = ~0;
2224 ha->nvram_conf_off = ~0;
2225 ha->nvram_data_off = ~0;
2226 ha->isp_ops = &qla2100_isp_ops;
2227 } else if (IS_QLA23XX(ha)) {
2228 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2229 req_length = REQUEST_ENTRY_CNT_2200;
2230 rsp_length = RESPONSE_ENTRY_CNT_2300;
2231 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2232 ha->gid_list_info_size = 6;
2233 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2234 ha->optrom_size = OPTROM_SIZE_2322;
2235 ha->flash_conf_off = ~0;
2236 ha->flash_data_off = ~0;
2237 ha->nvram_conf_off = ~0;
2238 ha->nvram_data_off = ~0;
2239 ha->isp_ops = &qla2300_isp_ops;
2240 } else if (IS_QLA24XX_TYPE(ha)) {
2241 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2242 req_length = REQUEST_ENTRY_CNT_24XX;
2243 rsp_length = RESPONSE_ENTRY_CNT_2300;
2244 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2245 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2246 ha->gid_list_info_size = 8;
2247 ha->optrom_size = OPTROM_SIZE_24XX;
2248 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
2249 ha->isp_ops = &qla24xx_isp_ops;
2250 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2251 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2252 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2253 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2254 } else if (IS_QLA25XX(ha)) {
2255 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2256 req_length = REQUEST_ENTRY_CNT_24XX;
2257 rsp_length = RESPONSE_ENTRY_CNT_2300;
2258 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2259 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
2260 ha->gid_list_info_size = 8;
2261 ha->optrom_size = OPTROM_SIZE_25XX;
2262 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2263 ha->isp_ops = &qla25xx_isp_ops;
2264 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2265 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2266 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2267 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2268 } else if (IS_QLA81XX(ha)) {
2269 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2270 req_length = REQUEST_ENTRY_CNT_24XX;
2271 rsp_length = RESPONSE_ENTRY_CNT_2300;
2272 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2273 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2274 ha->gid_list_info_size = 8;
2275 ha->optrom_size = OPTROM_SIZE_81XX;
2276 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2277 ha->isp_ops = &qla81xx_isp_ops;
2278 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2279 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2280 ha->nvram_conf_off = ~0;
2281 ha->nvram_data_off = ~0;
2282 } else if (IS_QLA82XX(ha)) {
2283 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2284 req_length = REQUEST_ENTRY_CNT_82XX;
2285 rsp_length = RESPONSE_ENTRY_CNT_82XX;
2286 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2287 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2288 ha->gid_list_info_size = 8;
2289 ha->optrom_size = OPTROM_SIZE_82XX;
2290 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2291 ha->isp_ops = &qla82xx_isp_ops;
2292 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
2293 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
2294 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
2295 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
2296 } else if (IS_QLA83XX(ha)) {
2297 ha->mbx_count = MAILBOX_REGISTER_COUNT;
2298 req_length = REQUEST_ENTRY_CNT_24XX;
2299 rsp_length = RESPONSE_ENTRY_CNT_2300;
2300 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
2301 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
2302 ha->gid_list_info_size = 8;
2303 ha->optrom_size = OPTROM_SIZE_83XX;
2304 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
2305 ha->isp_ops = &qla83xx_isp_ops;
2306 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
2307 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
2308 ha->nvram_conf_off = ~0;
2309 ha->nvram_data_off = ~0;
2310 }
2311
2312 ql_dbg_pci(ql_dbg_init, pdev, 0x001e,
2313 "mbx_count=%d, req_length=%d, "
2314 "rsp_length=%d, max_loop_id=%d, init_cb_size=%d, "
2315 "gid_list_info_size=%d, optrom_size=%d, nvram_npiv_size=%d, .\n",
2316 ha->mbx_count, req_length, rsp_length, ha->max_loop_id,
2317 ha->init_cb_size, ha->gid_list_info_size, ha->optrom_size,
2318 ha->nvram_npiv_size);
2319 ql_dbg_pci(ql_dbg_init, pdev, 0x001f,
2320 "isp_ops=%p, flash_conf_off=%d, "
2321 "flash_data_off=%d, nvram_conf_off=%d, nvram_data_off=%d.\n",
2322 ha->isp_ops, ha->flash_conf_off, ha->flash_data_off,
2323 ha->nvram_conf_off, ha->nvram_data_off);
2324
2325 /* Configure PCI I/O space */
2326 ret = ha->isp_ops->iospace_config(ha);
2327 if (ret)
2328 goto probe_hw_failed;
2329
2330 ql_log_pci(ql_log_info, pdev, 0x001d,
2331 "Found an ISP%04X irq %d iobase 0x%p.\n",
2332 pdev->device, pdev->irq, ha->iobase);
2333 mutex_init(&ha->vport_lock);
2334 init_completion(&ha->mbx_cmd_comp);
2335 complete(&ha->mbx_cmd_comp);
2336 init_completion(&ha->mbx_intr_comp);
2337 init_completion(&ha->dcbx_comp);
2338
2339 set_bit(0, (unsigned long *) ha->vp_idx_map);
2340
2341 qla2x00_config_dma_addressing(ha);
2342 ql_dbg_pci(ql_dbg_init, pdev, 0x0020,
2343 "64 Bit addressing is %s.\n",
2344 ha->flags.enable_64bit_addressing ? "enable" :
2345 "disable");
2346 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
2347 if (!ret) {
2348 ql_log_pci(ql_log_fatal, pdev, 0x0031,
2349 "Failed to allocate memory for adapter, aborting.\n");
2350
2351 goto probe_hw_failed;
2352 }
2353
2354 req->max_q_depth = MAX_Q_DEPTH;
2355 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
2356 req->max_q_depth = ql2xmaxqdepth;
2357
2358
2359 base_vha = qla2x00_create_host(sht, ha);
2360 if (!base_vha) {
2361 ret = -ENOMEM;
2362 qla2x00_mem_free(ha);
2363 qla2x00_free_req_que(ha, req);
2364 qla2x00_free_rsp_que(ha, rsp);
2365 goto probe_hw_failed;
2366 }
2367
2368 pci_set_drvdata(pdev, base_vha);
2369
2370 host = base_vha->host;
2371 base_vha->req = req;
2372 host->can_queue = req->length + 128;
2373 if (IS_QLA2XXX_MIDTYPE(ha))
2374 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
2375 else
2376 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
2377 base_vha->vp_idx;
2378
2379 /* Set the SG table size based on ISP type */
2380 if (!IS_FWI2_CAPABLE(ha)) {
2381 if (IS_QLA2100(ha))
2382 host->sg_tablesize = 32;
2383 } else {
2384 if (!IS_QLA82XX(ha))
2385 host->sg_tablesize = QLA_SG_ALL;
2386 }
2387 ql_dbg(ql_dbg_init, base_vha, 0x0032,
2388 "can_queue=%d, req=%p, "
2389 "mgmt_svr_loop_id=%d, sg_tablesize=%d.\n",
2390 host->can_queue, base_vha->req,
2391 base_vha->mgmt_svr_loop_id, host->sg_tablesize);
2392 host->max_id = max_id;
2393 host->this_id = 255;
2394 host->cmd_per_lun = 3;
2395 host->unique_id = host->host_no;
2396 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif)
2397 host->max_cmd_len = 32;
2398 else
2399 host->max_cmd_len = MAX_CMDSZ;
2400 host->max_channel = MAX_BUSES - 1;
2401 host->max_lun = ql2xmaxlun;
2402 host->transportt = qla2xxx_transport_template;
2403 sht->vendor_id = (SCSI_NL_VID_TYPE_PCI | PCI_VENDOR_ID_QLOGIC);
2404
2405 ql_dbg(ql_dbg_init, base_vha, 0x0033,
2406 "max_id=%d this_id=%d "
2407 "cmd_per_len=%d unique_id=%d max_cmd_len=%d max_channel=%d "
2408 "max_lun=%d transportt=%p, vendor_id=%llu.\n", host->max_id,
2409 host->this_id, host->cmd_per_lun, host->unique_id,
2410 host->max_cmd_len, host->max_channel, host->max_lun,
2411 host->transportt, sht->vendor_id);
2412
2413 /* Set up the irqs */
2414 ret = qla2x00_request_irqs(ha, rsp);
2415 if (ret)
2416 goto probe_init_failed;
2417
2418 pci_save_state(pdev);
2419
2420 /* Alloc arrays of request and response ring ptrs */
2421 que_init:
2422 if (!qla2x00_alloc_queues(ha)) {
2423 ql_log(ql_log_fatal, base_vha, 0x003d,
2424 "Failed to allocate memory for queue pointers.. aborting.\n");
2425 goto probe_init_failed;
2426 }
2427
2428 ha->rsp_q_map[0] = rsp;
2429 ha->req_q_map[0] = req;
2430 rsp->req = req;
2431 req->rsp = rsp;
2432 set_bit(0, ha->req_qid_map);
2433 set_bit(0, ha->rsp_qid_map);
2434 /* FWI2-capable only. */
2435 req->req_q_in = &ha->iobase->isp24.req_q_in;
2436 req->req_q_out = &ha->iobase->isp24.req_q_out;
2437 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
2438 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
2439 if (ha->mqenable || IS_QLA83XX(ha)) {
2440 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
2441 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
2442 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
2443 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
2444 }
2445
2446 if (IS_QLA82XX(ha)) {
2447 req->req_q_out = &ha->iobase->isp82.req_q_out[0];
2448 rsp->rsp_q_in = &ha->iobase->isp82.rsp_q_in[0];
2449 rsp->rsp_q_out = &ha->iobase->isp82.rsp_q_out[0];
2450 }
2451
2452 ql_dbg(ql_dbg_multiq, base_vha, 0xc009,
2453 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2454 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2455 ql_dbg(ql_dbg_multiq, base_vha, 0xc00a,
2456 "req->req_q_in=%p req->req_q_out=%p "
2457 "rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2458 req->req_q_in, req->req_q_out,
2459 rsp->rsp_q_in, rsp->rsp_q_out);
2460 ql_dbg(ql_dbg_init, base_vha, 0x003e,
2461 "rsp_q_map=%p req_q_map=%p rsp->req=%p req->rsp=%p.\n",
2462 ha->rsp_q_map, ha->req_q_map, rsp->req, req->rsp);
2463 ql_dbg(ql_dbg_init, base_vha, 0x003f,
2464 "req->req_q_in=%p req->req_q_out=%p rsp->rsp_q_in=%p rsp->rsp_q_out=%p.\n",
2465 req->req_q_in, req->req_q_out, rsp->rsp_q_in, rsp->rsp_q_out);
2466
2467 if (qla2x00_initialize_adapter(base_vha)) {
2468 ql_log(ql_log_fatal, base_vha, 0x00d6,
2469 "Failed to initialize adapter - Adapter flags %x.\n",
2470 base_vha->device_flags);
2471
2472 if (IS_QLA82XX(ha)) {
2473 qla82xx_idc_lock(ha);
2474 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
2475 QLA82XX_DEV_FAILED);
2476 qla82xx_idc_unlock(ha);
2477 ql_log(ql_log_fatal, base_vha, 0x00d7,
2478 "HW State: FAILED.\n");
2479 }
2480
2481 ret = -ENODEV;
2482 goto probe_failed;
2483 }
2484
2485 if (ha->mqenable) {
2486 if (qla25xx_setup_mode(base_vha)) {
2487 ql_log(ql_log_warn, base_vha, 0x00ec,
2488 "Failed to create queues, falling back to single queue mode.\n");
2489 goto que_init;
2490 }
2491 }
2492
2493 if (ha->flags.running_gold_fw)
2494 goto skip_dpc;
2495
2496 /*
2497 * Startup the kernel thread for this host adapter
2498 */
2499 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
2500 "%s_dpc", base_vha->host_str);
2501 if (IS_ERR(ha->dpc_thread)) {
2502 ql_log(ql_log_fatal, base_vha, 0x00ed,
2503 "Failed to start DPC thread.\n");
2504 ret = PTR_ERR(ha->dpc_thread);
2505 goto probe_failed;
2506 }
2507 ql_dbg(ql_dbg_init, base_vha, 0x00ee,
2508 "DPC thread started successfully.\n");
2509
2510 skip_dpc:
2511 list_add_tail(&base_vha->list, &ha->vp_list);
2512 base_vha->host->irq = ha->pdev->irq;
2513
2514 /* Initialized the timer */
2515 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
2516 ql_dbg(ql_dbg_init, base_vha, 0x00ef,
2517 "Started qla2x00_timer with "
2518 "interval=%d.\n", WATCH_INTERVAL);
2519 ql_dbg(ql_dbg_init, base_vha, 0x00f0,
2520 "Detected hba at address=%p.\n",
2521 ha);
2522
2523 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
2524 if (ha->fw_attributes & BIT_4) {
2525 int prot = 0;
2526 base_vha->flags.difdix_supported = 1;
2527 ql_dbg(ql_dbg_init, base_vha, 0x00f1,
2528 "Registering for DIF/DIX type 1 and 3 protection.\n");
2529 if (ql2xenabledif == 1)
2530 prot = SHOST_DIX_TYPE0_PROTECTION;
2531 scsi_host_set_prot(host,
2532 prot | SHOST_DIF_TYPE1_PROTECTION
2533 | SHOST_DIF_TYPE2_PROTECTION
2534 | SHOST_DIF_TYPE3_PROTECTION
2535 | SHOST_DIX_TYPE1_PROTECTION
2536 | SHOST_DIX_TYPE2_PROTECTION
2537 | SHOST_DIX_TYPE3_PROTECTION);
2538 scsi_host_set_guard(host, SHOST_DIX_GUARD_CRC);
2539 } else
2540 base_vha->flags.difdix_supported = 0;
2541 }
2542
2543 ha->isp_ops->enable_intrs(ha);
2544
2545 ret = scsi_add_host(host, &pdev->dev);
2546 if (ret)
2547 goto probe_failed;
2548
2549 base_vha->flags.init_done = 1;
2550 base_vha->flags.online = 1;
2551
2552 ql_dbg(ql_dbg_init, base_vha, 0x00f2,
2553 "Init done and hba is online.\n");
2554
2555 scsi_scan_host(host);
2556
2557 qla2x00_alloc_sysfs_attr(base_vha);
2558
2559 qla2x00_init_host_attr(base_vha);
2560
2561 qla2x00_dfs_setup(base_vha);
2562
2563 ql_log(ql_log_info, base_vha, 0x00fb,
2564 "QLogic %s - %s.\n",
2565 ha->model_number, ha->model_desc ? ha->model_desc : "");
2566 ql_log(ql_log_info, base_vha, 0x00fc,
2567 "ISP%04X: %s @ %s hdma%c host#=%ld fw=%s.\n",
2568 pdev->device, ha->isp_ops->pci_info_str(base_vha, pci_info),
2569 pci_name(pdev), ha->flags.enable_64bit_addressing ? '+' : '-',
2570 base_vha->host_no,
2571 ha->isp_ops->fw_version_str(base_vha, fw_str));
2572
2573 return 0;
2574
2575 probe_init_failed:
2576 qla2x00_free_req_que(ha, req);
2577 qla2x00_free_rsp_que(ha, rsp);
2578 ha->max_req_queues = ha->max_rsp_queues = 0;
2579
2580 probe_failed:
2581 if (base_vha->timer_active)
2582 qla2x00_stop_timer(base_vha);
2583 base_vha->flags.online = 0;
2584 if (ha->dpc_thread) {
2585 struct task_struct *t = ha->dpc_thread;
2586
2587 ha->dpc_thread = NULL;
2588 kthread_stop(t);
2589 }
2590
2591 qla2x00_free_device(base_vha);
2592
2593 scsi_host_put(base_vha->host);
2594
2595 probe_hw_failed:
2596 if (IS_QLA82XX(ha)) {
2597 qla82xx_idc_lock(ha);
2598 qla82xx_clear_drv_active(ha);
2599 qla82xx_idc_unlock(ha);
2600 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2601 if (!ql2xdbwr)
2602 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2603 } else {
2604 if (ha->iobase)
2605 iounmap(ha->iobase);
2606 }
2607 pci_release_selected_regions(ha->pdev, ha->bars);
2608 kfree(ha);
2609 ha = NULL;
2610
2611 probe_out:
2612 pci_disable_device(pdev);
2613 return ret;
2614 }
2615
2616 static void
2617 qla2x00_shutdown(struct pci_dev *pdev)
2618 {
2619 scsi_qla_host_t *vha;
2620 struct qla_hw_data *ha;
2621
2622 vha = pci_get_drvdata(pdev);
2623 ha = vha->hw;
2624
2625 /* Turn-off FCE trace */
2626 if (ha->flags.fce_enabled) {
2627 qla2x00_disable_fce_trace(vha, NULL, NULL);
2628 ha->flags.fce_enabled = 0;
2629 }
2630
2631 /* Turn-off EFT trace */
2632 if (ha->eft)
2633 qla2x00_disable_eft_trace(vha);
2634
2635 /* Stop currently executing firmware. */
2636 qla2x00_try_to_stop_firmware(vha);
2637
2638 /* Turn adapter off line */
2639 vha->flags.online = 0;
2640
2641 /* turn-off interrupts on the card */
2642 if (ha->interrupts_on) {
2643 vha->flags.init_done = 0;
2644 ha->isp_ops->disable_intrs(ha);
2645 }
2646
2647 qla2x00_free_irqs(vha);
2648
2649 qla2x00_free_fw_dump(ha);
2650 }
2651
2652 static void
2653 qla2x00_remove_one(struct pci_dev *pdev)
2654 {
2655 scsi_qla_host_t *base_vha, *vha;
2656 struct qla_hw_data *ha;
2657 unsigned long flags;
2658
2659 base_vha = pci_get_drvdata(pdev);
2660 ha = base_vha->hw;
2661
2662 mutex_lock(&ha->vport_lock);
2663 while (ha->cur_vport_count) {
2664 struct Scsi_Host *scsi_host;
2665
2666 spin_lock_irqsave(&ha->vport_slock, flags);
2667
2668 BUG_ON(base_vha->list.next == &ha->vp_list);
2669 /* This assumes first entry in ha->vp_list is always base vha */
2670 vha = list_first_entry(&base_vha->list, scsi_qla_host_t, list);
2671 scsi_host = scsi_host_get(vha->host);
2672
2673 spin_unlock_irqrestore(&ha->vport_slock, flags);
2674 mutex_unlock(&ha->vport_lock);
2675
2676 fc_vport_terminate(vha->fc_vport);
2677 scsi_host_put(vha->host);
2678
2679 mutex_lock(&ha->vport_lock);
2680 }
2681 mutex_unlock(&ha->vport_lock);
2682
2683 set_bit(UNLOADING, &base_vha->dpc_flags);
2684
2685 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2686
2687 qla2x00_dfs_remove(base_vha);
2688
2689 qla84xx_put_chip(base_vha);
2690
2691 /* Disable timer */
2692 if (base_vha->timer_active)
2693 qla2x00_stop_timer(base_vha);
2694
2695 base_vha->flags.online = 0;
2696
2697 /* Flush the work queue and remove it */
2698 if (ha->wq) {
2699 flush_workqueue(ha->wq);
2700 destroy_workqueue(ha->wq);
2701 ha->wq = NULL;
2702 }
2703
2704 /* Kill the kernel thread for this host */
2705 if (ha->dpc_thread) {
2706 struct task_struct *t = ha->dpc_thread;
2707
2708 /*
2709 * qla2xxx_wake_dpc checks for ->dpc_thread
2710 * so we need to zero it out.
2711 */
2712 ha->dpc_thread = NULL;
2713 kthread_stop(t);
2714 }
2715
2716 qla2x00_free_sysfs_attr(base_vha);
2717
2718 fc_remove_host(base_vha->host);
2719
2720 scsi_remove_host(base_vha->host);
2721
2722 qla2x00_free_device(base_vha);
2723
2724 scsi_host_put(base_vha->host);
2725
2726 if (IS_QLA82XX(ha)) {
2727 qla82xx_idc_lock(ha);
2728 qla82xx_clear_drv_active(ha);
2729 qla82xx_idc_unlock(ha);
2730
2731 iounmap((device_reg_t __iomem *)ha->nx_pcibase);
2732 if (!ql2xdbwr)
2733 iounmap((device_reg_t __iomem *)ha->nxdb_wr_ptr);
2734 } else {
2735 if (ha->iobase)
2736 iounmap(ha->iobase);
2737
2738 if (ha->mqiobase)
2739 iounmap(ha->mqiobase);
2740
2741 if (IS_QLA83XX(ha) && ha->msixbase)
2742 iounmap(ha->msixbase);
2743 }
2744
2745 pci_release_selected_regions(ha->pdev, ha->bars);
2746 kfree(ha);
2747 ha = NULL;
2748
2749 pci_disable_pcie_error_reporting(pdev);
2750
2751 pci_disable_device(pdev);
2752 pci_set_drvdata(pdev, NULL);
2753 }
2754
2755 static void
2756 qla2x00_free_device(scsi_qla_host_t *vha)
2757 {
2758 struct qla_hw_data *ha = vha->hw;
2759
2760 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
2761
2762 /* Disable timer */
2763 if (vha->timer_active)
2764 qla2x00_stop_timer(vha);
2765
2766 /* Kill the kernel thread for this host */
2767 if (ha->dpc_thread) {
2768 struct task_struct *t = ha->dpc_thread;
2769
2770 /*
2771 * qla2xxx_wake_dpc checks for ->dpc_thread
2772 * so we need to zero it out.
2773 */
2774 ha->dpc_thread = NULL;
2775 kthread_stop(t);
2776 }
2777
2778 qla25xx_delete_queues(vha);
2779
2780 if (ha->flags.fce_enabled)
2781 qla2x00_disable_fce_trace(vha, NULL, NULL);
2782
2783 if (ha->eft)
2784 qla2x00_disable_eft_trace(vha);
2785
2786 /* Stop currently executing firmware. */
2787 qla2x00_try_to_stop_firmware(vha);
2788
2789 vha->flags.online = 0;
2790
2791 /* turn-off interrupts on the card */
2792 if (ha->interrupts_on) {
2793 vha->flags.init_done = 0;
2794 ha->isp_ops->disable_intrs(ha);
2795 }
2796
2797 qla2x00_free_irqs(vha);
2798
2799 qla2x00_free_fcports(vha);
2800
2801 qla2x00_mem_free(ha);
2802
2803 qla82xx_md_free(vha);
2804
2805 qla2x00_free_queues(ha);
2806 }
2807
2808 void qla2x00_free_fcports(struct scsi_qla_host *vha)
2809 {
2810 fc_port_t *fcport, *tfcport;
2811
2812 list_for_each_entry_safe(fcport, tfcport, &vha->vp_fcports, list) {
2813 list_del(&fcport->list);
2814 kfree(fcport);
2815 fcport = NULL;
2816 }
2817 }
2818
2819 static inline void
2820 qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
2821 int defer)
2822 {
2823 struct fc_rport *rport;
2824 scsi_qla_host_t *base_vha;
2825 unsigned long flags;
2826
2827 if (!fcport->rport)
2828 return;
2829
2830 rport = fcport->rport;
2831 if (defer) {
2832 base_vha = pci_get_drvdata(vha->hw->pdev);
2833 spin_lock_irqsave(vha->host->host_lock, flags);
2834 fcport->drport = rport;
2835 spin_unlock_irqrestore(vha->host->host_lock, flags);
2836 set_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
2837 qla2xxx_wake_dpc(base_vha);
2838 } else
2839 fc_remote_port_delete(rport);
2840 }
2841
2842 /*
2843 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2844 *
2845 * Input: ha = adapter block pointer. fcport = port structure pointer.
2846 *
2847 * Return: None.
2848 *
2849 * Context:
2850 */
2851 void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
2852 int do_login, int defer)
2853 {
2854 if (atomic_read(&fcport->state) == FCS_ONLINE &&
2855 vha->vp_idx == fcport->vp_idx) {
2856 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2857 qla2x00_schedule_rport_del(vha, fcport, defer);
2858 }
2859 /*
2860 * We may need to retry the login, so don't change the state of the
2861 * port but do the retries.
2862 */
2863 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2864 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2865
2866 if (!do_login)
2867 return;
2868
2869 if (fcport->login_retry == 0) {
2870 fcport->login_retry = vha->hw->login_retry_count;
2871 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2872
2873 ql_dbg(ql_dbg_disc, vha, 0x2067,
2874 "Port login retry "
2875 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2876 "id = 0x%04x retry cnt=%d.\n",
2877 fcport->port_name[0], fcport->port_name[1],
2878 fcport->port_name[2], fcport->port_name[3],
2879 fcport->port_name[4], fcport->port_name[5],
2880 fcport->port_name[6], fcport->port_name[7],
2881 fcport->loop_id, fcport->login_retry);
2882 }
2883 }
2884
2885 /*
2886 * qla2x00_mark_all_devices_lost
2887 * Updates fcport state when device goes offline.
2888 *
2889 * Input:
2890 * ha = adapter block pointer.
2891 * fcport = port structure pointer.
2892 *
2893 * Return:
2894 * None.
2895 *
2896 * Context:
2897 */
2898 void
2899 qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
2900 {
2901 fc_port_t *fcport;
2902
2903 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2904 if (vha->vp_idx != 0 && vha->vp_idx != fcport->vp_idx)
2905 continue;
2906
2907 /*
2908 * No point in marking the device as lost, if the device is
2909 * already DEAD.
2910 */
2911 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2912 continue;
2913 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2914 qla2x00_set_fcport_state(fcport, FCS_DEVICE_LOST);
2915 if (defer)
2916 qla2x00_schedule_rport_del(vha, fcport, defer);
2917 else if (vha->vp_idx == fcport->vp_idx)
2918 qla2x00_schedule_rport_del(vha, fcport, defer);
2919 }
2920 }
2921 }
2922
2923 /*
2924 * qla2x00_mem_alloc
2925 * Allocates adapter memory.
2926 *
2927 * Returns:
2928 * 0 = success.
2929 * !0 = failure.
2930 */
2931 static int
2932 qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2933 struct req_que **req, struct rsp_que **rsp)
2934 {
2935 char name[16];
2936
2937 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
2938 &ha->init_cb_dma, GFP_KERNEL);
2939 if (!ha->init_cb)
2940 goto fail;
2941
2942 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2943 &ha->gid_list_dma, GFP_KERNEL);
2944 if (!ha->gid_list)
2945 goto fail_free_init_cb;
2946
2947 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2948 if (!ha->srb_mempool)
2949 goto fail_free_gid_list;
2950
2951 if (IS_QLA82XX(ha)) {
2952 /* Allocate cache for CT6 Ctx. */
2953 if (!ctx_cachep) {
2954 ctx_cachep = kmem_cache_create("qla2xxx_ctx",
2955 sizeof(struct ct6_dsd), 0,
2956 SLAB_HWCACHE_ALIGN, NULL);
2957 if (!ctx_cachep)
2958 goto fail_free_gid_list;
2959 }
2960 ha->ctx_mempool = mempool_create_slab_pool(SRB_MIN_REQ,
2961 ctx_cachep);
2962 if (!ha->ctx_mempool)
2963 goto fail_free_srb_mempool;
2964 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0021,
2965 "ctx_cachep=%p ctx_mempool=%p.\n",
2966 ctx_cachep, ha->ctx_mempool);
2967 }
2968
2969 /* Get memory for cached NVRAM */
2970 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2971 if (!ha->nvram)
2972 goto fail_free_ctx_mempool;
2973
2974 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2975 ha->pdev->device);
2976 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2977 DMA_POOL_SIZE, 8, 0);
2978 if (!ha->s_dma_pool)
2979 goto fail_free_nvram;
2980
2981 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0022,
2982 "init_cb=%p gid_list=%p, srb_mempool=%p s_dma_pool=%p.\n",
2983 ha->init_cb, ha->gid_list, ha->srb_mempool, ha->s_dma_pool);
2984
2985 if (IS_QLA82XX(ha) || ql2xenabledif) {
2986 ha->dl_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2987 DSD_LIST_DMA_POOL_SIZE, 8, 0);
2988 if (!ha->dl_dma_pool) {
2989 ql_log_pci(ql_log_fatal, ha->pdev, 0x0023,
2990 "Failed to allocate memory for dl_dma_pool.\n");
2991 goto fail_s_dma_pool;
2992 }
2993
2994 ha->fcp_cmnd_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2995 FCP_CMND_DMA_POOL_SIZE, 8, 0);
2996 if (!ha->fcp_cmnd_dma_pool) {
2997 ql_log_pci(ql_log_fatal, ha->pdev, 0x0024,
2998 "Failed to allocate memory for fcp_cmnd_dma_pool.\n");
2999 goto fail_dl_dma_pool;
3000 }
3001 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0025,
3002 "dl_dma_pool=%p fcp_cmnd_dma_pool=%p.\n",
3003 ha->dl_dma_pool, ha->fcp_cmnd_dma_pool);
3004 }
3005
3006 /* Allocate memory for SNS commands */
3007 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3008 /* Get consistent memory allocated for SNS commands */
3009 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
3010 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
3011 if (!ha->sns_cmd)
3012 goto fail_dma_pool;
3013 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0026,
3014 "sns_cmd: %p.\n", ha->sns_cmd);
3015 } else {
3016 /* Get consistent memory allocated for MS IOCB */
3017 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3018 &ha->ms_iocb_dma);
3019 if (!ha->ms_iocb)
3020 goto fail_dma_pool;
3021 /* Get consistent memory allocated for CT SNS commands */
3022 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
3023 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
3024 if (!ha->ct_sns)
3025 goto fail_free_ms_iocb;
3026 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x0027,
3027 "ms_iocb=%p ct_sns=%p.\n",
3028 ha->ms_iocb, ha->ct_sns);
3029 }
3030
3031 /* Allocate memory for request ring */
3032 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
3033 if (!*req) {
3034 ql_log_pci(ql_log_fatal, ha->pdev, 0x0028,
3035 "Failed to allocate memory for req.\n");
3036 goto fail_req;
3037 }
3038 (*req)->length = req_len;
3039 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
3040 ((*req)->length + 1) * sizeof(request_t),
3041 &(*req)->dma, GFP_KERNEL);
3042 if (!(*req)->ring) {
3043 ql_log_pci(ql_log_fatal, ha->pdev, 0x0029,
3044 "Failed to allocate memory for req_ring.\n");
3045 goto fail_req_ring;
3046 }
3047 /* Allocate memory for response ring */
3048 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
3049 if (!*rsp) {
3050 ql_log_pci(ql_log_fatal, ha->pdev, 0x002a,
3051 "Failed to allocate memory for rsp.\n");
3052 goto fail_rsp;
3053 }
3054 (*rsp)->hw = ha;
3055 (*rsp)->length = rsp_len;
3056 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
3057 ((*rsp)->length + 1) * sizeof(response_t),
3058 &(*rsp)->dma, GFP_KERNEL);
3059 if (!(*rsp)->ring) {
3060 ql_log_pci(ql_log_fatal, ha->pdev, 0x002b,
3061 "Failed to allocate memory for rsp_ring.\n");
3062 goto fail_rsp_ring;
3063 }
3064 (*req)->rsp = *rsp;
3065 (*rsp)->req = *req;
3066 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002c,
3067 "req=%p req->length=%d req->ring=%p rsp=%p "
3068 "rsp->length=%d rsp->ring=%p.\n",
3069 *req, (*req)->length, (*req)->ring, *rsp, (*rsp)->length,
3070 (*rsp)->ring);
3071 /* Allocate memory for NVRAM data for vports */
3072 if (ha->nvram_npiv_size) {
3073 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
3074 ha->nvram_npiv_size, GFP_KERNEL);
3075 if (!ha->npiv_info) {
3076 ql_log_pci(ql_log_fatal, ha->pdev, 0x002d,
3077 "Failed to allocate memory for npiv_info.\n");
3078 goto fail_npiv_info;
3079 }
3080 } else
3081 ha->npiv_info = NULL;
3082
3083 /* Get consistent memory allocated for EX-INIT-CB. */
3084 if (IS_CNA_CAPABLE(ha) || IS_QLA2031(ha)) {
3085 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3086 &ha->ex_init_cb_dma);
3087 if (!ha->ex_init_cb)
3088 goto fail_ex_init_cb;
3089 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002e,
3090 "ex_init_cb=%p.\n", ha->ex_init_cb);
3091 }
3092
3093 INIT_LIST_HEAD(&ha->gbl_dsd_list);
3094
3095 /* Get consistent memory allocated for Async Port-Database. */
3096 if (!IS_FWI2_CAPABLE(ha)) {
3097 ha->async_pd = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
3098 &ha->async_pd_dma);
3099 if (!ha->async_pd)
3100 goto fail_async_pd;
3101 ql_dbg_pci(ql_dbg_init, ha->pdev, 0x002f,
3102 "async_pd=%p.\n", ha->async_pd);
3103 }
3104
3105 INIT_LIST_HEAD(&ha->vp_list);
3106 return 1;
3107
3108 fail_async_pd:
3109 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
3110 fail_ex_init_cb:
3111 kfree(ha->npiv_info);
3112 fail_npiv_info:
3113 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
3114 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
3115 (*rsp)->ring = NULL;
3116 (*rsp)->dma = 0;
3117 fail_rsp_ring:
3118 kfree(*rsp);
3119 fail_rsp:
3120 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
3121 sizeof(request_t), (*req)->ring, (*req)->dma);
3122 (*req)->ring = NULL;
3123 (*req)->dma = 0;
3124 fail_req_ring:
3125 kfree(*req);
3126 fail_req:
3127 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3128 ha->ct_sns, ha->ct_sns_dma);
3129 ha->ct_sns = NULL;
3130 ha->ct_sns_dma = 0;
3131 fail_free_ms_iocb:
3132 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3133 ha->ms_iocb = NULL;
3134 ha->ms_iocb_dma = 0;
3135 fail_dma_pool:
3136 if (IS_QLA82XX(ha) || ql2xenabledif) {
3137 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3138 ha->fcp_cmnd_dma_pool = NULL;
3139 }
3140 fail_dl_dma_pool:
3141 if (IS_QLA82XX(ha) || ql2xenabledif) {
3142 dma_pool_destroy(ha->dl_dma_pool);
3143 ha->dl_dma_pool = NULL;
3144 }
3145 fail_s_dma_pool:
3146 dma_pool_destroy(ha->s_dma_pool);
3147 ha->s_dma_pool = NULL;
3148 fail_free_nvram:
3149 kfree(ha->nvram);
3150 ha->nvram = NULL;
3151 fail_free_ctx_mempool:
3152 mempool_destroy(ha->ctx_mempool);
3153 ha->ctx_mempool = NULL;
3154 fail_free_srb_mempool:
3155 mempool_destroy(ha->srb_mempool);
3156 ha->srb_mempool = NULL;
3157 fail_free_gid_list:
3158 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
3159 ha->gid_list_dma);
3160 ha->gid_list = NULL;
3161 ha->gid_list_dma = 0;
3162 fail_free_init_cb:
3163 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
3164 ha->init_cb_dma);
3165 ha->init_cb = NULL;
3166 ha->init_cb_dma = 0;
3167 fail:
3168 ql_log(ql_log_fatal, NULL, 0x0030,
3169 "Memory allocation failure.\n");
3170 return -ENOMEM;
3171 }
3172
3173 /*
3174 * qla2x00_free_fw_dump
3175 * Frees fw dump stuff.
3176 *
3177 * Input:
3178 * ha = adapter block pointer.
3179 */
3180 static void
3181 qla2x00_free_fw_dump(struct qla_hw_data *ha)
3182 {
3183 if (ha->fce)
3184 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
3185 ha->fce_dma);
3186
3187 if (ha->fw_dump) {
3188 if (ha->eft)
3189 dma_free_coherent(&ha->pdev->dev,
3190 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
3191 vfree(ha->fw_dump);
3192 }
3193 ha->fce = NULL;
3194 ha->fce_dma = 0;
3195 ha->eft = NULL;
3196 ha->eft_dma = 0;
3197 ha->fw_dump = NULL;
3198 ha->fw_dumped = 0;
3199 ha->fw_dump_reading = 0;
3200 }
3201
3202 /*
3203 * qla2x00_mem_free
3204 * Frees all adapter allocated memory.
3205 *
3206 * Input:
3207 * ha = adapter block pointer.
3208 */
3209 static void
3210 qla2x00_mem_free(struct qla_hw_data *ha)
3211 {
3212 qla2x00_free_fw_dump(ha);
3213
3214 if (ha->srb_mempool)
3215 mempool_destroy(ha->srb_mempool);
3216
3217 if (ha->dcbx_tlv)
3218 dma_free_coherent(&ha->pdev->dev, DCBX_TLV_DATA_SIZE,
3219 ha->dcbx_tlv, ha->dcbx_tlv_dma);
3220
3221 if (ha->xgmac_data)
3222 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
3223 ha->xgmac_data, ha->xgmac_data_dma);
3224
3225 if (ha->sns_cmd)
3226 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
3227 ha->sns_cmd, ha->sns_cmd_dma);
3228
3229 if (ha->ct_sns)
3230 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
3231 ha->ct_sns, ha->ct_sns_dma);
3232
3233 if (ha->sfp_data)
3234 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
3235
3236 if (ha->ms_iocb)
3237 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
3238
3239 if (ha->ex_init_cb)
3240 dma_pool_free(ha->s_dma_pool,
3241 ha->ex_init_cb, ha->ex_init_cb_dma);
3242
3243 if (ha->async_pd)
3244 dma_pool_free(ha->s_dma_pool, ha->async_pd, ha->async_pd_dma);
3245
3246 if (ha->s_dma_pool)
3247 dma_pool_destroy(ha->s_dma_pool);
3248
3249 if (ha->gid_list)
3250 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
3251 ha->gid_list_dma);
3252
3253 if (IS_QLA82XX(ha)) {
3254 if (!list_empty(&ha->gbl_dsd_list)) {
3255 struct dsd_dma *dsd_ptr, *tdsd_ptr;
3256
3257 /* clean up allocated prev pool */
3258 list_for_each_entry_safe(dsd_ptr,
3259 tdsd_ptr, &ha->gbl_dsd_list, list) {
3260 dma_pool_free(ha->dl_dma_pool,
3261 dsd_ptr->dsd_addr, dsd_ptr->dsd_list_dma);
3262 list_del(&dsd_ptr->list);
3263 kfree(dsd_ptr);
3264 }
3265 }
3266 }
3267
3268 if (ha->dl_dma_pool)
3269 dma_pool_destroy(ha->dl_dma_pool);
3270
3271 if (ha->fcp_cmnd_dma_pool)
3272 dma_pool_destroy(ha->fcp_cmnd_dma_pool);
3273
3274 if (ha->ctx_mempool)
3275 mempool_destroy(ha->ctx_mempool);
3276
3277 if (ha->init_cb)
3278 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
3279 ha->init_cb, ha->init_cb_dma);
3280 vfree(ha->optrom_buffer);
3281 kfree(ha->nvram);
3282 kfree(ha->npiv_info);
3283 kfree(ha->swl);
3284
3285 ha->srb_mempool = NULL;
3286 ha->ctx_mempool = NULL;
3287 ha->sns_cmd = NULL;
3288 ha->sns_cmd_dma = 0;
3289 ha->ct_sns = NULL;
3290 ha->ct_sns_dma = 0;
3291 ha->ms_iocb = NULL;
3292 ha->ms_iocb_dma = 0;
3293 ha->init_cb = NULL;
3294 ha->init_cb_dma = 0;
3295 ha->ex_init_cb = NULL;
3296 ha->ex_init_cb_dma = 0;
3297 ha->async_pd = NULL;
3298 ha->async_pd_dma = 0;
3299
3300 ha->s_dma_pool = NULL;
3301 ha->dl_dma_pool = NULL;
3302 ha->fcp_cmnd_dma_pool = NULL;
3303
3304 ha->gid_list = NULL;
3305 ha->gid_list_dma = 0;
3306 }
3307
3308 struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
3309 struct qla_hw_data *ha)
3310 {
3311 struct Scsi_Host *host;
3312 struct scsi_qla_host *vha = NULL;
3313
3314 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
3315 if (host == NULL) {
3316 ql_log_pci(ql_log_fatal, ha->pdev, 0x0107,
3317 "Failed to allocate host from the scsi layer, aborting.\n");
3318 goto fail;
3319 }
3320
3321 /* Clear our data area */
3322 vha = shost_priv(host);
3323 memset(vha, 0, sizeof(scsi_qla_host_t));
3324
3325 vha->host = host;
3326 vha->host_no = host->host_no;
3327 vha->hw = ha;
3328
3329 INIT_LIST_HEAD(&vha->vp_fcports);
3330 INIT_LIST_HEAD(&vha->work_list);
3331 INIT_LIST_HEAD(&vha->list);
3332
3333 spin_lock_init(&vha->work_lock);
3334
3335 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
3336 ql_dbg(ql_dbg_init, vha, 0x0041,
3337 "Allocated the host=%p hw=%p vha=%p dev_name=%s",
3338 vha->host, vha->hw, vha,
3339 dev_name(&(ha->pdev->dev)));
3340
3341 return vha;
3342
3343 fail:
3344 return vha;
3345 }
3346
3347 static struct qla_work_evt *
3348 qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type)
3349 {
3350 struct qla_work_evt *e;
3351 uint8_t bail;
3352
3353 QLA_VHA_MARK_BUSY(vha, bail);
3354 if (bail)
3355 return NULL;
3356
3357 e = kzalloc(sizeof(struct qla_work_evt), GFP_ATOMIC);
3358 if (!e) {
3359 QLA_VHA_MARK_NOT_BUSY(vha);
3360 return NULL;
3361 }
3362
3363 INIT_LIST_HEAD(&e->list);
3364 e->type = type;
3365 e->flags = QLA_EVT_FLAG_FREE;
3366 return e;
3367 }
3368
3369 static int
3370 qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e)
3371 {
3372 unsigned long flags;
3373
3374 spin_lock_irqsave(&vha->work_lock, flags);
3375 list_add_tail(&e->list, &vha->work_list);
3376 spin_unlock_irqrestore(&vha->work_lock, flags);
3377 qla2xxx_wake_dpc(vha);
3378
3379 return QLA_SUCCESS;
3380 }
3381
3382 int
3383 qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
3384 u32 data)
3385 {
3386 struct qla_work_evt *e;
3387
3388 e = qla2x00_alloc_work(vha, QLA_EVT_AEN);
3389 if (!e)
3390 return QLA_FUNCTION_FAILED;
3391
3392 e->u.aen.code = code;
3393 e->u.aen.data = data;
3394 return qla2x00_post_work(vha, e);
3395 }
3396
3397 int
3398 qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
3399 {
3400 struct qla_work_evt *e;
3401
3402 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK);
3403 if (!e)
3404 return QLA_FUNCTION_FAILED;
3405
3406 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
3407 return qla2x00_post_work(vha, e);
3408 }
3409
3410 #define qla2x00_post_async_work(name, type) \
3411 int qla2x00_post_async_##name##_work( \
3412 struct scsi_qla_host *vha, \
3413 fc_port_t *fcport, uint16_t *data) \
3414 { \
3415 struct qla_work_evt *e; \
3416 \
3417 e = qla2x00_alloc_work(vha, type); \
3418 if (!e) \
3419 return QLA_FUNCTION_FAILED; \
3420 \
3421 e->u.logio.fcport = fcport; \
3422 if (data) { \
3423 e->u.logio.data[0] = data[0]; \
3424 e->u.logio.data[1] = data[1]; \
3425 } \
3426 return qla2x00_post_work(vha, e); \
3427 }
3428
3429 qla2x00_post_async_work(login, QLA_EVT_ASYNC_LOGIN);
3430 qla2x00_post_async_work(login_done, QLA_EVT_ASYNC_LOGIN_DONE);
3431 qla2x00_post_async_work(logout, QLA_EVT_ASYNC_LOGOUT);
3432 qla2x00_post_async_work(logout_done, QLA_EVT_ASYNC_LOGOUT_DONE);
3433 qla2x00_post_async_work(adisc, QLA_EVT_ASYNC_ADISC);
3434 qla2x00_post_async_work(adisc_done, QLA_EVT_ASYNC_ADISC_DONE);
3435
3436 int
3437 qla2x00_post_uevent_work(struct scsi_qla_host *vha, u32 code)
3438 {
3439 struct qla_work_evt *e;
3440
3441 e = qla2x00_alloc_work(vha, QLA_EVT_UEVENT);
3442 if (!e)
3443 return QLA_FUNCTION_FAILED;
3444
3445 e->u.uevent.code = code;
3446 return qla2x00_post_work(vha, e);
3447 }
3448
3449 static void
3450 qla2x00_uevent_emit(struct scsi_qla_host *vha, u32 code)
3451 {
3452 char event_string[40];
3453 char *envp[] = { event_string, NULL };
3454
3455 switch (code) {
3456 case QLA_UEVENT_CODE_FW_DUMP:
3457 snprintf(event_string, sizeof(event_string), "FW_DUMP=%ld",
3458 vha->host_no);
3459 break;
3460 default:
3461 /* do nothing */
3462 break;
3463 }
3464 kobject_uevent_env(&vha->hw->pdev->dev.kobj, KOBJ_CHANGE, envp);
3465 }
3466
3467 void
3468 qla2x00_do_work(struct scsi_qla_host *vha)
3469 {
3470 struct qla_work_evt *e, *tmp;
3471 unsigned long flags;
3472 LIST_HEAD(work);
3473
3474 spin_lock_irqsave(&vha->work_lock, flags);
3475 list_splice_init(&vha->work_list, &work);
3476 spin_unlock_irqrestore(&vha->work_lock, flags);
3477
3478 list_for_each_entry_safe(e, tmp, &work, list) {
3479 list_del_init(&e->list);
3480
3481 switch (e->type) {
3482 case QLA_EVT_AEN:
3483 fc_host_post_event(vha->host, fc_get_event_number(),
3484 e->u.aen.code, e->u.aen.data);
3485 break;
3486 case QLA_EVT_IDC_ACK:
3487 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
3488 break;
3489 case QLA_EVT_ASYNC_LOGIN:
3490 qla2x00_async_login(vha, e->u.logio.fcport,
3491 e->u.logio.data);
3492 break;
3493 case QLA_EVT_ASYNC_LOGIN_DONE:
3494 qla2x00_async_login_done(vha, e->u.logio.fcport,
3495 e->u.logio.data);
3496 break;
3497 case QLA_EVT_ASYNC_LOGOUT:
3498 qla2x00_async_logout(vha, e->u.logio.fcport);
3499 break;
3500 case QLA_EVT_ASYNC_LOGOUT_DONE:
3501 qla2x00_async_logout_done(vha, e->u.logio.fcport,
3502 e->u.logio.data);
3503 break;
3504 case QLA_EVT_ASYNC_ADISC:
3505 qla2x00_async_adisc(vha, e->u.logio.fcport,
3506 e->u.logio.data);
3507 break;
3508 case QLA_EVT_ASYNC_ADISC_DONE:
3509 qla2x00_async_adisc_done(vha, e->u.logio.fcport,
3510 e->u.logio.data);
3511 break;
3512 case QLA_EVT_UEVENT:
3513 qla2x00_uevent_emit(vha, e->u.uevent.code);
3514 break;
3515 }
3516 if (e->flags & QLA_EVT_FLAG_FREE)
3517 kfree(e);
3518
3519 /* For each work completed decrement vha ref count */
3520 QLA_VHA_MARK_NOT_BUSY(vha);
3521 }
3522 }
3523
3524 /* Relogins all the fcports of a vport
3525 * Context: dpc thread
3526 */
3527 void qla2x00_relogin(struct scsi_qla_host *vha)
3528 {
3529 fc_port_t *fcport;
3530 int status;
3531 uint16_t next_loopid = 0;
3532 struct qla_hw_data *ha = vha->hw;
3533 uint16_t data[2];
3534
3535 list_for_each_entry(fcport, &vha->vp_fcports, list) {
3536 /*
3537 * If the port is not ONLINE then try to login
3538 * to it if we haven't run out of retries.
3539 */
3540 if (atomic_read(&fcport->state) != FCS_ONLINE &&
3541 fcport->login_retry && !(fcport->flags & FCF_ASYNC_SENT)) {
3542 fcport->login_retry--;
3543 if (fcport->flags & FCF_FABRIC_DEVICE) {
3544 if (fcport->flags & FCF_FCP2_DEVICE)
3545 ha->isp_ops->fabric_logout(vha,
3546 fcport->loop_id,
3547 fcport->d_id.b.domain,
3548 fcport->d_id.b.area,
3549 fcport->d_id.b.al_pa);
3550
3551 if (fcport->loop_id == FC_NO_LOOP_ID) {
3552 fcport->loop_id = next_loopid =
3553 ha->min_external_loopid;
3554 status = qla2x00_find_new_loop_id(
3555 vha, fcport);
3556 if (status != QLA_SUCCESS) {
3557 /* Ran out of IDs to use */
3558 break;
3559 }
3560 }
3561
3562 if (IS_ALOGIO_CAPABLE(ha)) {
3563 fcport->flags |= FCF_ASYNC_SENT;
3564 data[0] = 0;
3565 data[1] = QLA_LOGIO_LOGIN_RETRIED;
3566 status = qla2x00_post_async_login_work(
3567 vha, fcport, data);
3568 if (status == QLA_SUCCESS)
3569 continue;
3570 /* Attempt a retry. */
3571 status = 1;
3572 } else
3573 status = qla2x00_fabric_login(vha,
3574 fcport, &next_loopid);
3575 } else
3576 status = qla2x00_local_device_login(vha,
3577 fcport);
3578
3579 if (status == QLA_SUCCESS) {
3580 fcport->old_loop_id = fcport->loop_id;
3581
3582 ql_dbg(ql_dbg_disc, vha, 0x2003,
3583 "Port login OK: logged in ID 0x%x.\n",
3584 fcport->loop_id);
3585
3586 qla2x00_update_fcport(vha, fcport);
3587
3588 } else if (status == 1) {
3589 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
3590 /* retry the login again */
3591 ql_dbg(ql_dbg_disc, vha, 0x2007,
3592 "Retrying %d login again loop_id 0x%x.\n",
3593 fcport->login_retry, fcport->loop_id);
3594 } else {
3595 fcport->login_retry = 0;
3596 }
3597
3598 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
3599 fcport->loop_id = FC_NO_LOOP_ID;
3600 }
3601 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
3602 break;
3603 }
3604 }
3605
3606 /**************************************************************************
3607 * qla2x00_do_dpc
3608 * This kernel thread is a task that is schedule by the interrupt handler
3609 * to perform the background processing for interrupts.
3610 *
3611 * Notes:
3612 * This task always run in the context of a kernel thread. It
3613 * is kick-off by the driver's detect code and starts up
3614 * up one per adapter. It immediately goes to sleep and waits for
3615 * some fibre event. When either the interrupt handler or
3616 * the timer routine detects a event it will one of the task
3617 * bits then wake us up.
3618 **************************************************************************/
3619 static int
3620 qla2x00_do_dpc(void *data)
3621 {
3622 int rval;
3623 scsi_qla_host_t *base_vha;
3624 struct qla_hw_data *ha;
3625
3626 ha = (struct qla_hw_data *)data;
3627 base_vha = pci_get_drvdata(ha->pdev);
3628
3629 set_user_nice(current, -20);
3630
3631 set_current_state(TASK_INTERRUPTIBLE);
3632 while (!kthread_should_stop()) {
3633 ql_dbg(ql_dbg_dpc, base_vha, 0x4000,
3634 "DPC handler sleeping.\n");
3635
3636 schedule();
3637 __set_current_state(TASK_RUNNING);
3638
3639 if (!base_vha->flags.init_done || ha->flags.mbox_busy)
3640 goto end_loop;
3641
3642 if (ha->flags.eeh_busy) {
3643 ql_dbg(ql_dbg_dpc, base_vha, 0x4003,
3644 "eeh_busy=%d.\n", ha->flags.eeh_busy);
3645 goto end_loop;
3646 }
3647
3648 ha->dpc_active = 1;
3649
3650 ql_dbg(ql_dbg_dpc, base_vha, 0x4001,
3651 "DPC handler waking up.\n");
3652 ql_dbg(ql_dbg_dpc, base_vha, 0x4002,
3653 "dpc_flags=0x%lx.\n", base_vha->dpc_flags);
3654
3655 qla2x00_do_work(base_vha);
3656
3657 if (IS_QLA82XX(ha)) {
3658 if (test_and_clear_bit(ISP_UNRECOVERABLE,
3659 &base_vha->dpc_flags)) {
3660 qla82xx_idc_lock(ha);
3661 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
3662 QLA82XX_DEV_FAILED);
3663 qla82xx_idc_unlock(ha);
3664 ql_log(ql_log_info, base_vha, 0x4004,
3665 "HW State: FAILED.\n");
3666 qla82xx_device_state_handler(base_vha);
3667 continue;
3668 }
3669
3670 if (test_and_clear_bit(FCOE_CTX_RESET_NEEDED,
3671 &base_vha->dpc_flags)) {
3672
3673 ql_dbg(ql_dbg_dpc, base_vha, 0x4005,
3674 "FCoE context reset scheduled.\n");
3675 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3676 &base_vha->dpc_flags))) {
3677 if (qla82xx_fcoe_ctx_reset(base_vha)) {
3678 /* FCoE-ctx reset failed.
3679 * Escalate to chip-reset
3680 */
3681 set_bit(ISP_ABORT_NEEDED,
3682 &base_vha->dpc_flags);
3683 }
3684 clear_bit(ABORT_ISP_ACTIVE,
3685 &base_vha->dpc_flags);
3686 }
3687
3688 ql_dbg(ql_dbg_dpc, base_vha, 0x4006,
3689 "FCoE context reset end.\n");
3690 }
3691 }
3692
3693 if (test_and_clear_bit(ISP_ABORT_NEEDED,
3694 &base_vha->dpc_flags)) {
3695
3696 ql_dbg(ql_dbg_dpc, base_vha, 0x4007,
3697 "ISP abort scheduled.\n");
3698 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
3699 &base_vha->dpc_flags))) {
3700
3701 if (ha->isp_ops->abort_isp(base_vha)) {
3702 /* failed. retry later */
3703 set_bit(ISP_ABORT_NEEDED,
3704 &base_vha->dpc_flags);
3705 }
3706 clear_bit(ABORT_ISP_ACTIVE,
3707 &base_vha->dpc_flags);
3708 }
3709
3710 ql_dbg(ql_dbg_dpc, base_vha, 0x4008,
3711 "ISP abort end.\n");
3712 }
3713
3714 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
3715 qla2x00_update_fcports(base_vha);
3716 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
3717 }
3718
3719 if (test_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags)) {
3720 ql_dbg(ql_dbg_dpc, base_vha, 0x4009,
3721 "Quiescence mode scheduled.\n");
3722 qla82xx_device_state_handler(base_vha);
3723 clear_bit(ISP_QUIESCE_NEEDED, &base_vha->dpc_flags);
3724 if (!ha->flags.quiesce_owner) {
3725 qla2x00_perform_loop_resync(base_vha);
3726
3727 qla82xx_idc_lock(ha);
3728 qla82xx_clear_qsnt_ready(base_vha);
3729 qla82xx_idc_unlock(ha);
3730 }
3731 ql_dbg(ql_dbg_dpc, base_vha, 0x400a,
3732 "Quiescence mode end.\n");
3733 }
3734
3735 if (test_and_clear_bit(RESET_MARKER_NEEDED,
3736 &base_vha->dpc_flags) &&
3737 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
3738
3739 ql_dbg(ql_dbg_dpc, base_vha, 0x400b,
3740 "Reset marker scheduled.\n");
3741 qla2x00_rst_aen(base_vha);
3742 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
3743 ql_dbg(ql_dbg_dpc, base_vha, 0x400c,
3744 "Reset marker end.\n");
3745 }
3746
3747 /* Retry each device up to login retry count */
3748 if ((test_and_clear_bit(RELOGIN_NEEDED,
3749 &base_vha->dpc_flags)) &&
3750 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
3751 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
3752
3753 ql_dbg(ql_dbg_dpc, base_vha, 0x400d,
3754 "Relogin scheduled.\n");
3755 qla2x00_relogin(base_vha);
3756 ql_dbg(ql_dbg_dpc, base_vha, 0x400e,
3757 "Relogin end.\n");
3758 }
3759
3760 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
3761 &base_vha->dpc_flags)) {
3762
3763 ql_dbg(ql_dbg_dpc, base_vha, 0x400f,
3764 "Loop resync scheduled.\n");
3765
3766 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
3767 &base_vha->dpc_flags))) {
3768
3769 rval = qla2x00_loop_resync(base_vha);
3770
3771 clear_bit(LOOP_RESYNC_ACTIVE,
3772 &base_vha->dpc_flags);
3773 }
3774
3775 ql_dbg(ql_dbg_dpc, base_vha, 0x4010,
3776 "Loop resync end.\n");
3777 }
3778
3779 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
3780 atomic_read(&base_vha->loop_state) == LOOP_READY) {
3781 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
3782 qla2xxx_flash_npiv_conf(base_vha);
3783 }
3784
3785 if (!ha->interrupts_on)
3786 ha->isp_ops->enable_intrs(ha);
3787
3788 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
3789 &base_vha->dpc_flags))
3790 ha->isp_ops->beacon_blink(base_vha);
3791
3792 qla2x00_do_dpc_all_vps(base_vha);
3793
3794 ha->dpc_active = 0;
3795 end_loop:
3796 set_current_state(TASK_INTERRUPTIBLE);
3797 } /* End of while(1) */
3798 __set_current_state(TASK_RUNNING);
3799
3800 ql_dbg(ql_dbg_dpc, base_vha, 0x4011,
3801 "DPC handler exiting.\n");
3802
3803 /*
3804 * Make sure that nobody tries to wake us up again.
3805 */
3806 ha->dpc_active = 0;
3807
3808 /* Cleanup any residual CTX SRBs. */
3809 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
3810
3811 return 0;
3812 }
3813
3814 void
3815 qla2xxx_wake_dpc(struct scsi_qla_host *vha)
3816 {
3817 struct qla_hw_data *ha = vha->hw;
3818 struct task_struct *t = ha->dpc_thread;
3819
3820 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
3821 wake_up_process(t);
3822 }
3823
3824 /*
3825 * qla2x00_rst_aen
3826 * Processes asynchronous reset.
3827 *
3828 * Input:
3829 * ha = adapter block pointer.
3830 */
3831 static void
3832 qla2x00_rst_aen(scsi_qla_host_t *vha)
3833 {
3834 if (vha->flags.online && !vha->flags.reset_active &&
3835 !atomic_read(&vha->loop_down_timer) &&
3836 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
3837 do {
3838 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
3839
3840 /*
3841 * Issue marker command only when we are going to start
3842 * the I/O.
3843 */
3844 vha->marker_needed = 1;
3845 } while (!atomic_read(&vha->loop_down_timer) &&
3846 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
3847 }
3848 }
3849
3850 /**************************************************************************
3851 * qla2x00_timer
3852 *
3853 * Description:
3854 * One second timer
3855 *
3856 * Context: Interrupt
3857 ***************************************************************************/
3858 void
3859 qla2x00_timer(scsi_qla_host_t *vha)
3860 {
3861 unsigned long cpu_flags = 0;
3862 int start_dpc = 0;
3863 int index;
3864 srb_t *sp;
3865 uint16_t w;
3866 struct qla_hw_data *ha = vha->hw;
3867 struct req_que *req;
3868
3869 if (ha->flags.eeh_busy) {
3870 ql_dbg(ql_dbg_timer, vha, 0x6000,
3871 "EEH = %d, restarting timer.\n",
3872 ha->flags.eeh_busy);
3873 qla2x00_restart_timer(vha, WATCH_INTERVAL);
3874 return;
3875 }
3876
3877 /* Hardware read to raise pending EEH errors during mailbox waits. */
3878 if (!pci_channel_offline(ha->pdev))
3879 pci_read_config_word(ha->pdev, PCI_VENDOR_ID, &w);
3880
3881 /* Make sure qla82xx_watchdog is run only for physical port */
3882 if (!vha->vp_idx && IS_QLA82XX(ha)) {
3883 if (test_bit(ISP_QUIESCE_NEEDED, &vha->dpc_flags))
3884 start_dpc++;
3885 qla82xx_watchdog(vha);
3886 }
3887
3888 /* Loop down handler. */
3889 if (atomic_read(&vha->loop_down_timer) > 0 &&
3890 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags)) &&
3891 !(test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags))
3892 && vha->flags.online) {
3893
3894 if (atomic_read(&vha->loop_down_timer) ==
3895 vha->loop_down_abort_time) {
3896
3897 ql_log(ql_log_info, vha, 0x6008,
3898 "Loop down - aborting the queues before time expires.\n");
3899
3900 if (!IS_QLA2100(ha) && vha->link_down_timeout)
3901 atomic_set(&vha->loop_state, LOOP_DEAD);
3902
3903 /*
3904 * Schedule an ISP abort to return any FCP2-device
3905 * commands.
3906 */
3907 /* NPIV - scan physical port only */
3908 if (!vha->vp_idx) {
3909 spin_lock_irqsave(&ha->hardware_lock,
3910 cpu_flags);
3911 req = ha->req_q_map[0];
3912 for (index = 1;
3913 index < MAX_OUTSTANDING_COMMANDS;
3914 index++) {
3915 fc_port_t *sfcp;
3916
3917 sp = req->outstanding_cmds[index];
3918 if (!sp)
3919 continue;
3920 if (sp->type != SRB_SCSI_CMD)
3921 continue;
3922 sfcp = sp->fcport;
3923 if (!(sfcp->flags & FCF_FCP2_DEVICE))
3924 continue;
3925
3926 if (IS_QLA82XX(ha))
3927 set_bit(FCOE_CTX_RESET_NEEDED,
3928 &vha->dpc_flags);
3929 else
3930 set_bit(ISP_ABORT_NEEDED,
3931 &vha->dpc_flags);
3932 break;
3933 }
3934 spin_unlock_irqrestore(&ha->hardware_lock,
3935 cpu_flags);
3936 }
3937 start_dpc++;
3938 }
3939
3940 /* if the loop has been down for 4 minutes, reinit adapter */
3941 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
3942 if (!(vha->device_flags & DFLG_NO_CABLE)) {
3943 ql_log(ql_log_warn, vha, 0x6009,
3944 "Loop down - aborting ISP.\n");
3945
3946 if (IS_QLA82XX(ha))
3947 set_bit(FCOE_CTX_RESET_NEEDED,
3948 &vha->dpc_flags);
3949 else
3950 set_bit(ISP_ABORT_NEEDED,
3951 &vha->dpc_flags);
3952 }
3953 }
3954 ql_dbg(ql_dbg_timer, vha, 0x600a,
3955 "Loop down - seconds remaining %d.\n",
3956 atomic_read(&vha->loop_down_timer));
3957 }
3958
3959 /* Check if beacon LED needs to be blinked for physical host only */
3960 if (!vha->vp_idx && (ha->beacon_blink_led == 1)) {
3961 /* There is no beacon_blink function for ISP82xx */
3962 if (!IS_QLA82XX(ha)) {
3963 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
3964 start_dpc++;
3965 }
3966 }
3967
3968 /* Process any deferred work. */
3969 if (!list_empty(&vha->work_list))
3970 start_dpc++;
3971
3972 /* Schedule the DPC routine if needed */
3973 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3974 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3975 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
3976 start_dpc ||
3977 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3978 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3979 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags) ||
3980 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags) ||
3981 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3982 test_bit(RELOGIN_NEEDED, &vha->dpc_flags))) {
3983 ql_dbg(ql_dbg_timer, vha, 0x600b,
3984 "isp_abort_needed=%d loop_resync_needed=%d "
3985 "fcport_update_needed=%d start_dpc=%d "
3986 "reset_marker_needed=%d",
3987 test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags),
3988 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags),
3989 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags),
3990 start_dpc,
3991 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags));
3992 ql_dbg(ql_dbg_timer, vha, 0x600c,
3993 "beacon_blink_needed=%d isp_unrecoverable=%d "
3994 "fcoe_ctx_reset_needed=%d vp_dpc_needed=%d "
3995 "relogin_needed=%d.\n",
3996 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags),
3997 test_bit(ISP_UNRECOVERABLE, &vha->dpc_flags),
3998 test_bit(FCOE_CTX_RESET_NEEDED, &vha->dpc_flags),
3999 test_bit(VP_DPC_NEEDED, &vha->dpc_flags),
4000 test_bit(RELOGIN_NEEDED, &vha->dpc_flags));
4001 qla2xxx_wake_dpc(vha);
4002 }
4003
4004 qla2x00_restart_timer(vha, WATCH_INTERVAL);
4005 }
4006
4007 /* Firmware interface routines. */
4008
4009 #define FW_BLOBS 10
4010 #define FW_ISP21XX 0
4011 #define FW_ISP22XX 1
4012 #define FW_ISP2300 2
4013 #define FW_ISP2322 3
4014 #define FW_ISP24XX 4
4015 #define FW_ISP25XX 5
4016 #define FW_ISP81XX 6
4017 #define FW_ISP82XX 7
4018 #define FW_ISP2031 8
4019 #define FW_ISP8031 9
4020
4021 #define FW_FILE_ISP21XX "ql2100_fw.bin"
4022 #define FW_FILE_ISP22XX "ql2200_fw.bin"
4023 #define FW_FILE_ISP2300 "ql2300_fw.bin"
4024 #define FW_FILE_ISP2322 "ql2322_fw.bin"
4025 #define FW_FILE_ISP24XX "ql2400_fw.bin"
4026 #define FW_FILE_ISP25XX "ql2500_fw.bin"
4027 #define FW_FILE_ISP81XX "ql8100_fw.bin"
4028 #define FW_FILE_ISP82XX "ql8200_fw.bin"
4029 #define FW_FILE_ISP2031 "ql2600_fw.bin"
4030 #define FW_FILE_ISP8031 "ql8300_fw.bin"
4031
4032 static DEFINE_MUTEX(qla_fw_lock);
4033
4034 static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
4035 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
4036 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
4037 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
4038 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
4039 { .name = FW_FILE_ISP24XX, },
4040 { .name = FW_FILE_ISP25XX, },
4041 { .name = FW_FILE_ISP81XX, },
4042 { .name = FW_FILE_ISP82XX, },
4043 { .name = FW_FILE_ISP2031, },
4044 { .name = FW_FILE_ISP8031, },
4045 };
4046
4047 struct fw_blob *
4048 qla2x00_request_firmware(scsi_qla_host_t *vha)
4049 {
4050 struct qla_hw_data *ha = vha->hw;
4051 struct fw_blob *blob;
4052
4053 blob = NULL;
4054 if (IS_QLA2100(ha)) {
4055 blob = &qla_fw_blobs[FW_ISP21XX];
4056 } else if (IS_QLA2200(ha)) {
4057 blob = &qla_fw_blobs[FW_ISP22XX];
4058 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
4059 blob = &qla_fw_blobs[FW_ISP2300];
4060 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
4061 blob = &qla_fw_blobs[FW_ISP2322];
4062 } else if (IS_QLA24XX_TYPE(ha)) {
4063 blob = &qla_fw_blobs[FW_ISP24XX];
4064 } else if (IS_QLA25XX(ha)) {
4065 blob = &qla_fw_blobs[FW_ISP25XX];
4066 } else if (IS_QLA81XX(ha)) {
4067 blob = &qla_fw_blobs[FW_ISP81XX];
4068 } else if (IS_QLA82XX(ha)) {
4069 blob = &qla_fw_blobs[FW_ISP82XX];
4070 } else if (IS_QLA2031(ha)) {
4071 blob = &qla_fw_blobs[FW_ISP2031];
4072 } else if (IS_QLA8031(ha)) {
4073 blob = &qla_fw_blobs[FW_ISP8031];
4074 }
4075
4076 mutex_lock(&qla_fw_lock);
4077 if (blob->fw)
4078 goto out;
4079
4080 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
4081 ql_log(ql_log_warn, vha, 0x0063,
4082 "Failed to load firmware image (%s).\n", blob->name);
4083 blob->fw = NULL;
4084 blob = NULL;
4085 goto out;
4086 }
4087
4088 out:
4089 mutex_unlock(&qla_fw_lock);
4090 return blob;
4091 }
4092
4093 static void
4094 qla2x00_release_firmware(void)
4095 {
4096 int idx;
4097
4098 mutex_lock(&qla_fw_lock);
4099 for (idx = 0; idx < FW_BLOBS; idx++)
4100 if (qla_fw_blobs[idx].fw)
4101 release_firmware(qla_fw_blobs[idx].fw);
4102 mutex_unlock(&qla_fw_lock);
4103 }
4104
4105 static pci_ers_result_t
4106 qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
4107 {
4108 scsi_qla_host_t *vha = pci_get_drvdata(pdev);
4109 struct qla_hw_data *ha = vha->hw;
4110
4111 ql_dbg(ql_dbg_aer, vha, 0x9000,
4112 "PCI error detected, state %x.\n", state);
4113
4114 switch (state) {
4115 case pci_channel_io_normal:
4116 ha->flags.eeh_busy = 0;
4117 return PCI_ERS_RESULT_CAN_RECOVER;
4118 case pci_channel_io_frozen:
4119 ha->flags.eeh_busy = 1;
4120 /* For ISP82XX complete any pending mailbox cmd */
4121 if (IS_QLA82XX(ha)) {
4122 ha->flags.isp82xx_fw_hung = 1;
4123 ql_dbg(ql_dbg_aer, vha, 0x9001, "Pci channel io frozen\n");
4124 qla82xx_clear_pending_mbx(vha);
4125 }
4126 qla2x00_free_irqs(vha);
4127 pci_disable_device(pdev);
4128 /* Return back all IOs */
4129 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
4130 return PCI_ERS_RESULT_NEED_RESET;
4131 case pci_channel_io_perm_failure:
4132 ha->flags.pci_channel_io_perm_failure = 1;
4133 qla2x00_abort_all_cmds(vha, DID_NO_CONNECT << 16);
4134 return PCI_ERS_RESULT_DISCONNECT;
4135 }
4136 return PCI_ERS_RESULT_NEED_RESET;
4137 }
4138
4139 static pci_ers_result_t
4140 qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
4141 {
4142 int risc_paused = 0;
4143 uint32_t stat;
4144 unsigned long flags;
4145 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4146 struct qla_hw_data *ha = base_vha->hw;
4147 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4148 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
4149
4150 if (IS_QLA82XX(ha))
4151 return PCI_ERS_RESULT_RECOVERED;
4152
4153 spin_lock_irqsave(&ha->hardware_lock, flags);
4154 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
4155 stat = RD_REG_DWORD(&reg->hccr);
4156 if (stat & HCCR_RISC_PAUSE)
4157 risc_paused = 1;
4158 } else if (IS_QLA23XX(ha)) {
4159 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
4160 if (stat & HSR_RISC_PAUSED)
4161 risc_paused = 1;
4162 } else if (IS_FWI2_CAPABLE(ha)) {
4163 stat = RD_REG_DWORD(&reg24->host_status);
4164 if (stat & HSRX_RISC_PAUSED)
4165 risc_paused = 1;
4166 }
4167 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4168
4169 if (risc_paused) {
4170 ql_log(ql_log_info, base_vha, 0x9003,
4171 "RISC paused -- mmio_enabled, Dumping firmware.\n");
4172 ha->isp_ops->fw_dump(base_vha, 0);
4173
4174 return PCI_ERS_RESULT_NEED_RESET;
4175 } else
4176 return PCI_ERS_RESULT_RECOVERED;
4177 }
4178
4179 uint32_t qla82xx_error_recovery(scsi_qla_host_t *base_vha)
4180 {
4181 uint32_t rval = QLA_FUNCTION_FAILED;
4182 uint32_t drv_active = 0;
4183 struct qla_hw_data *ha = base_vha->hw;
4184 int fn;
4185 struct pci_dev *other_pdev = NULL;
4186
4187 ql_dbg(ql_dbg_aer, base_vha, 0x9006,
4188 "Entered %s.\n", __func__);
4189
4190 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4191
4192 if (base_vha->flags.online) {
4193 /* Abort all outstanding commands,
4194 * so as to be requeued later */
4195 qla2x00_abort_isp_cleanup(base_vha);
4196 }
4197
4198
4199 fn = PCI_FUNC(ha->pdev->devfn);
4200 while (fn > 0) {
4201 fn--;
4202 ql_dbg(ql_dbg_aer, base_vha, 0x9007,
4203 "Finding pci device at function = 0x%x.\n", fn);
4204 other_pdev =
4205 pci_get_domain_bus_and_slot(pci_domain_nr(ha->pdev->bus),
4206 ha->pdev->bus->number, PCI_DEVFN(PCI_SLOT(ha->pdev->devfn),
4207 fn));
4208
4209 if (!other_pdev)
4210 continue;
4211 if (atomic_read(&other_pdev->enable_cnt)) {
4212 ql_dbg(ql_dbg_aer, base_vha, 0x9008,
4213 "Found PCI func available and enable at 0x%x.\n",
4214 fn);
4215 pci_dev_put(other_pdev);
4216 break;
4217 }
4218 pci_dev_put(other_pdev);
4219 }
4220
4221 if (!fn) {
4222 /* Reset owner */
4223 ql_dbg(ql_dbg_aer, base_vha, 0x9009,
4224 "This devfn is reset owner = 0x%x.\n",
4225 ha->pdev->devfn);
4226 qla82xx_idc_lock(ha);
4227
4228 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4229 QLA82XX_DEV_INITIALIZING);
4230
4231 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_IDC_VERSION,
4232 QLA82XX_IDC_VERSION);
4233
4234 drv_active = qla82xx_rd_32(ha, QLA82XX_CRB_DRV_ACTIVE);
4235 ql_dbg(ql_dbg_aer, base_vha, 0x900a,
4236 "drv_active = 0x%x.\n", drv_active);
4237
4238 qla82xx_idc_unlock(ha);
4239 /* Reset if device is not already reset
4240 * drv_active would be 0 if a reset has already been done
4241 */
4242 if (drv_active)
4243 rval = qla82xx_start_firmware(base_vha);
4244 else
4245 rval = QLA_SUCCESS;
4246 qla82xx_idc_lock(ha);
4247
4248 if (rval != QLA_SUCCESS) {
4249 ql_log(ql_log_info, base_vha, 0x900b,
4250 "HW State: FAILED.\n");
4251 qla82xx_clear_drv_active(ha);
4252 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4253 QLA82XX_DEV_FAILED);
4254 } else {
4255 ql_log(ql_log_info, base_vha, 0x900c,
4256 "HW State: READY.\n");
4257 qla82xx_wr_32(ha, QLA82XX_CRB_DEV_STATE,
4258 QLA82XX_DEV_READY);
4259 qla82xx_idc_unlock(ha);
4260 ha->flags.isp82xx_fw_hung = 0;
4261 rval = qla82xx_restart_isp(base_vha);
4262 qla82xx_idc_lock(ha);
4263 /* Clear driver state register */
4264 qla82xx_wr_32(ha, QLA82XX_CRB_DRV_STATE, 0);
4265 qla82xx_set_drv_active(base_vha);
4266 }
4267 qla82xx_idc_unlock(ha);
4268 } else {
4269 ql_dbg(ql_dbg_aer, base_vha, 0x900d,
4270 "This devfn is not reset owner = 0x%x.\n",
4271 ha->pdev->devfn);
4272 if ((qla82xx_rd_32(ha, QLA82XX_CRB_DEV_STATE) ==
4273 QLA82XX_DEV_READY)) {
4274 ha->flags.isp82xx_fw_hung = 0;
4275 rval = qla82xx_restart_isp(base_vha);
4276 qla82xx_idc_lock(ha);
4277 qla82xx_set_drv_active(base_vha);
4278 qla82xx_idc_unlock(ha);
4279 }
4280 }
4281 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4282
4283 return rval;
4284 }
4285
4286 static pci_ers_result_t
4287 qla2xxx_pci_slot_reset(struct pci_dev *pdev)
4288 {
4289 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
4290 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4291 struct qla_hw_data *ha = base_vha->hw;
4292 struct rsp_que *rsp;
4293 int rc, retries = 10;
4294
4295 ql_dbg(ql_dbg_aer, base_vha, 0x9004,
4296 "Slot Reset.\n");
4297
4298 /* Workaround: qla2xxx driver which access hardware earlier
4299 * needs error state to be pci_channel_io_online.
4300 * Otherwise mailbox command timesout.
4301 */
4302 pdev->error_state = pci_channel_io_normal;
4303
4304 pci_restore_state(pdev);
4305
4306 /* pci_restore_state() clears the saved_state flag of the device
4307 * save restored state which resets saved_state flag
4308 */
4309 pci_save_state(pdev);
4310
4311 if (ha->mem_only)
4312 rc = pci_enable_device_mem(pdev);
4313 else
4314 rc = pci_enable_device(pdev);
4315
4316 if (rc) {
4317 ql_log(ql_log_warn, base_vha, 0x9005,
4318 "Can't re-enable PCI device after reset.\n");
4319 goto exit_slot_reset;
4320 }
4321
4322 rsp = ha->rsp_q_map[0];
4323 if (qla2x00_request_irqs(ha, rsp))
4324 goto exit_slot_reset;
4325
4326 if (ha->isp_ops->pci_config(base_vha))
4327 goto exit_slot_reset;
4328
4329 if (IS_QLA82XX(ha)) {
4330 if (qla82xx_error_recovery(base_vha) == QLA_SUCCESS) {
4331 ret = PCI_ERS_RESULT_RECOVERED;
4332 goto exit_slot_reset;
4333 } else
4334 goto exit_slot_reset;
4335 }
4336
4337 while (ha->flags.mbox_busy && retries--)
4338 msleep(1000);
4339
4340 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4341 if (ha->isp_ops->abort_isp(base_vha) == QLA_SUCCESS)
4342 ret = PCI_ERS_RESULT_RECOVERED;
4343 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
4344
4345
4346 exit_slot_reset:
4347 ql_dbg(ql_dbg_aer, base_vha, 0x900e,
4348 "slot_reset return %x.\n", ret);
4349
4350 return ret;
4351 }
4352
4353 static void
4354 qla2xxx_pci_resume(struct pci_dev *pdev)
4355 {
4356 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
4357 struct qla_hw_data *ha = base_vha->hw;
4358 int ret;
4359
4360 ql_dbg(ql_dbg_aer, base_vha, 0x900f,
4361 "pci_resume.\n");
4362
4363 ret = qla2x00_wait_for_hba_online(base_vha);
4364 if (ret != QLA_SUCCESS) {
4365 ql_log(ql_log_fatal, base_vha, 0x9002,
4366 "The device failed to resume I/O from slot/link_reset.\n");
4367 }
4368
4369 pci_cleanup_aer_uncorrect_error_status(pdev);
4370
4371 ha->flags.eeh_busy = 0;
4372 }
4373
4374 static struct pci_error_handlers qla2xxx_err_handler = {
4375 .error_detected = qla2xxx_pci_error_detected,
4376 .mmio_enabled = qla2xxx_pci_mmio_enabled,
4377 .slot_reset = qla2xxx_pci_slot_reset,
4378 .resume = qla2xxx_pci_resume,
4379 };
4380
4381 static struct pci_device_id qla2xxx_pci_tbl[] = {
4382 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
4383 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
4384 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
4385 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
4386 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
4387 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
4388 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
4389 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
4390 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
4391 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
4392 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
4393 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
4394 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
4395 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2031) },
4396 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
4397 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8021) },
4398 { 0 },
4399 };
4400 MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
4401
4402 static struct pci_driver qla2xxx_pci_driver = {
4403 .name = QLA2XXX_DRIVER_NAME,
4404 .driver = {
4405 .owner = THIS_MODULE,
4406 },
4407 .id_table = qla2xxx_pci_tbl,
4408 .probe = qla2x00_probe_one,
4409 .remove = qla2x00_remove_one,
4410 .shutdown = qla2x00_shutdown,
4411 .err_handler = &qla2xxx_err_handler,
4412 };
4413
4414 static struct file_operations apidev_fops = {
4415 .owner = THIS_MODULE,
4416 .llseek = noop_llseek,
4417 };
4418
4419 /**
4420 * qla2x00_module_init - Module initialization.
4421 **/
4422 static int __init
4423 qla2x00_module_init(void)
4424 {
4425 int ret = 0;
4426
4427 /* Allocate cache for SRBs. */
4428 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
4429 SLAB_HWCACHE_ALIGN, NULL);
4430 if (srb_cachep == NULL) {
4431 ql_log(ql_log_fatal, NULL, 0x0001,
4432 "Unable to allocate SRB cache...Failing load!.\n");
4433 return -ENOMEM;
4434 }
4435
4436 /* Derive version string. */
4437 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
4438 if (ql2xextended_error_logging)
4439 strcat(qla2x00_version_str, "-debug");
4440
4441 qla2xxx_transport_template =
4442 fc_attach_transport(&qla2xxx_transport_functions);
4443 if (!qla2xxx_transport_template) {
4444 kmem_cache_destroy(srb_cachep);
4445 ql_log(ql_log_fatal, NULL, 0x0002,
4446 "fc_attach_transport failed...Failing load!.\n");
4447 return -ENODEV;
4448 }
4449
4450 apidev_major = register_chrdev(0, QLA2XXX_APIDEV, &apidev_fops);
4451 if (apidev_major < 0) {
4452 ql_log(ql_log_fatal, NULL, 0x0003,
4453 "Unable to register char device %s.\n", QLA2XXX_APIDEV);
4454 }
4455
4456 qla2xxx_transport_vport_template =
4457 fc_attach_transport(&qla2xxx_transport_vport_functions);
4458 if (!qla2xxx_transport_vport_template) {
4459 kmem_cache_destroy(srb_cachep);
4460 fc_release_transport(qla2xxx_transport_template);
4461 ql_log(ql_log_fatal, NULL, 0x0004,
4462 "fc_attach_transport vport failed...Failing load!.\n");
4463 return -ENODEV;
4464 }
4465 ql_log(ql_log_info, NULL, 0x0005,
4466 "QLogic Fibre Channel HBA Driver: %s.\n",
4467 qla2x00_version_str);
4468 ret = pci_register_driver(&qla2xxx_pci_driver);
4469 if (ret) {
4470 kmem_cache_destroy(srb_cachep);
4471 fc_release_transport(qla2xxx_transport_template);
4472 fc_release_transport(qla2xxx_transport_vport_template);
4473 ql_log(ql_log_fatal, NULL, 0x0006,
4474 "pci_register_driver failed...ret=%d Failing load!.\n",
4475 ret);
4476 }
4477 return ret;
4478 }
4479
4480 /**
4481 * qla2x00_module_exit - Module cleanup.
4482 **/
4483 static void __exit
4484 qla2x00_module_exit(void)
4485 {
4486 unregister_chrdev(apidev_major, QLA2XXX_APIDEV);
4487 pci_unregister_driver(&qla2xxx_pci_driver);
4488 qla2x00_release_firmware();
4489 kmem_cache_destroy(srb_cachep);
4490 if (ctx_cachep)
4491 kmem_cache_destroy(ctx_cachep);
4492 fc_release_transport(qla2xxx_transport_template);
4493 fc_release_transport(qla2xxx_transport_vport_template);
4494 }
4495
4496 module_init(qla2x00_module_init);
4497 module_exit(qla2x00_module_exit);
4498
4499 MODULE_AUTHOR("QLogic Corporation");
4500 MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
4501 MODULE_LICENSE("GPL");
4502 MODULE_VERSION(QLA2XXX_VERSION);
4503 MODULE_FIRMWARE(FW_FILE_ISP21XX);
4504 MODULE_FIRMWARE(FW_FILE_ISP22XX);
4505 MODULE_FIRMWARE(FW_FILE_ISP2300);
4506 MODULE_FIRMWARE(FW_FILE_ISP2322);
4507 MODULE_FIRMWARE(FW_FILE_ISP24XX);
4508 MODULE_FIRMWARE(FW_FILE_ISP25XX);