blob: 642e976083e81b93c4208221728c6715a1396525 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Andrew Vasquezfa90c542005-10-27 11:10:08 -07002 * QLogic Fibre Channel HBA Driver
Andrew Vasquez01e58d82008-04-03 13:13:13 -07003 * Copyright (c) 2003-2008 QLogic Corporation
Linus Torvalds1da177e2005-04-16 15:20:36 -07004 *
Andrew Vasquezfa90c542005-10-27 11:10:08 -07005 * See LICENSE.qla2xxx for copyright and licensing details.
Linus Torvalds1da177e2005-04-16 15:20:36 -07006 */
7#include "qla_def.h"
8
9#include <linux/moduleparam.h>
10#include <linux/vmalloc.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070011#include <linux/delay.h>
Christoph Hellwig39a11242006-02-14 18:46:22 +010012#include <linux/kthread.h>
Daniel Walkere1e82b62008-05-12 22:21:10 -070013#include <linux/mutex.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070014
15#include <scsi/scsi_tcq.h>
16#include <scsi/scsicam.h>
17#include <scsi/scsi_transport.h>
18#include <scsi/scsi_transport_fc.h>
19
20/*
21 * Driver version
22 */
23char qla2x00_version_str[40];
24
25/*
26 * SRB allocation cache
27 */
Christoph Lametere18b8902006-12-06 20:33:20 -080028static struct kmem_cache *srb_cachep;
Linus Torvalds1da177e2005-04-16 15:20:36 -070029
Linus Torvalds1da177e2005-04-16 15:20:36 -070030int ql2xlogintimeout = 20;
31module_param(ql2xlogintimeout, int, S_IRUGO|S_IRUSR);
32MODULE_PARM_DESC(ql2xlogintimeout,
33 "Login timeout value in seconds.");
34
Andrew Vasqueza7b61842007-05-07 07:42:59 -070035int qlport_down_retry;
Linus Torvalds1da177e2005-04-16 15:20:36 -070036module_param(qlport_down_retry, int, S_IRUGO|S_IRUSR);
37MODULE_PARM_DESC(qlport_down_retry,
Jesper Juhl900d9f92006-06-30 02:33:07 -070038 "Maximum number of command retries to a port that returns "
Linus Torvalds1da177e2005-04-16 15:20:36 -070039 "a PORT-DOWN status.");
40
Linus Torvalds1da177e2005-04-16 15:20:36 -070041int ql2xplogiabsentdevice;
42module_param(ql2xplogiabsentdevice, int, S_IRUGO|S_IWUSR);
43MODULE_PARM_DESC(ql2xplogiabsentdevice,
44 "Option to enable PLOGI to devices that are not present after "
Jesper Juhl900d9f92006-06-30 02:33:07 -070045 "a Fabric scan. This is needed for several broken switches. "
Linus Torvalds1da177e2005-04-16 15:20:36 -070046 "Default is 0 - no PLOGI. 1 - perfom PLOGI.");
47
Linus Torvalds1da177e2005-04-16 15:20:36 -070048int ql2xloginretrycount = 0;
49module_param(ql2xloginretrycount, int, S_IRUGO|S_IRUSR);
50MODULE_PARM_DESC(ql2xloginretrycount,
51 "Specify an alternate value for the NVRAM login retry count.");
52
Andrew Vasqueza7a167b2006-06-23 16:10:29 -070053int ql2xallocfwdump = 1;
54module_param(ql2xallocfwdump, int, S_IRUGO|S_IRUSR);
55MODULE_PARM_DESC(ql2xallocfwdump,
56 "Option to enable allocation of memory for a firmware dump "
57 "during HBA initialization. Memory allocation requirements "
58 "vary by ISP type. Default is 1 - allocate memory.");
59
Andrew Vasquez11010fe2006-10-06 09:54:59 -070060int ql2xextended_error_logging;
Andrew Vasquez27d94032007-03-12 10:41:30 -070061module_param(ql2xextended_error_logging, int, S_IRUGO|S_IWUSR);
Andrew Vasquez11010fe2006-10-06 09:54:59 -070062MODULE_PARM_DESC(ql2xextended_error_logging,
Andrew Vasquez01819442006-06-23 16:11:10 -070063 "Option to enable extended error logging, "
64 "Default is 0 - no logging. 1 - log errors.");
65
Linus Torvalds1da177e2005-04-16 15:20:36 -070066static void qla2x00_free_device(scsi_qla_host_t *);
67
Andrew Vasquez7e47e5c2008-04-24 15:21:26 -070068int ql2xfdmienable=1;
Andrew Vasquezcca53352005-08-26 19:08:30 -070069module_param(ql2xfdmienable, int, S_IRUGO|S_IRUSR);
70MODULE_PARM_DESC(ql2xfdmienable,
71 "Enables FDMI registratons "
72 "Default is 0 - no FDMI. 1 - perfom FDMI.");
73
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070074#define MAX_Q_DEPTH 32
75static int ql2xmaxqdepth = MAX_Q_DEPTH;
76module_param(ql2xmaxqdepth, int, S_IRUGO|S_IWUSR);
77MODULE_PARM_DESC(ql2xmaxqdepth,
78 "Maximum queue depth to report for target devices.");
79
Michael Reeda13d8ac2009-04-06 22:33:47 -070080int ql2xqfulltracking = 1;
81module_param(ql2xqfulltracking, int, S_IRUGO|S_IWUSR);
82MODULE_PARM_DESC(ql2xqfulltracking,
83 "Controls whether the driver tracks queue full status "
84 "returns and dynamically adjusts a scsi device's queue "
85 "depth. Default is 1, perform tracking. Set to 0 to "
86 "disable dynamic tracking and adjustment of queue depth.");
87
Andrew Vasquezdf7baa52006-10-13 09:33:39 -070088int ql2xqfullrampup = 120;
89module_param(ql2xqfullrampup, int, S_IRUGO|S_IWUSR);
90MODULE_PARM_DESC(ql2xqfullrampup,
91 "Number of seconds to wait to begin to ramp-up the queue "
92 "depth for a device after a queue-full condition has been "
93 "detected. Default is 120 seconds.");
94
Andrew Vasqueze5896bd2008-07-10 16:55:52 -070095int ql2xiidmaenable=1;
96module_param(ql2xiidmaenable, int, S_IRUGO|S_IRUSR);
97MODULE_PARM_DESC(ql2xiidmaenable,
98 "Enables iIDMA settings "
99 "Default is 1 - perform iIDMA. 0 - no iIDMA.");
100
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800101int ql2xmaxqueues = 1;
102module_param(ql2xmaxqueues, int, S_IRUGO|S_IRUSR);
103MODULE_PARM_DESC(ql2xmaxqueues,
104 "Enables MQ settings "
105 "Default is 1 for single queue. Set it to number \
106 of queues in MQ mode.");
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700107
108int ql2xmultique_tag;
109module_param(ql2xmultique_tag, int, S_IRUGO|S_IRUSR);
110MODULE_PARM_DESC(ql2xmultique_tag,
111 "Enables CPU affinity settings for the driver "
112 "Default is 0 for no affinity of request and response IO. "
113 "Set it to 1 to turn on the cpu affinity.");
Andrew Vasqueze337d902009-04-06 22:33:49 -0700114
115int ql2xfwloadbin;
116module_param(ql2xfwloadbin, int, S_IRUGO|S_IRUSR);
117MODULE_PARM_DESC(ql2xfwloadbin,
118 "Option to specify location from which to load ISP firmware:\n"
119 " 2 -- load firmware via the request_firmware() (hotplug)\n"
120 " interface.\n"
121 " 1 -- load firmware from flash.\n"
122 " 0 -- use default semantics.\n");
123
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124/*
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700125 * SCSI host template entry points
Linus Torvalds1da177e2005-04-16 15:20:36 -0700126 */
127static int qla2xxx_slave_configure(struct scsi_device * device);
f4f051e2005-04-17 15:02:26 -0500128static int qla2xxx_slave_alloc(struct scsi_device *);
Andrew Vasquez1e99e332006-11-22 08:24:48 -0800129static int qla2xxx_scan_finished(struct Scsi_Host *, unsigned long time);
130static void qla2xxx_scan_start(struct Scsi_Host *);
f4f051e2005-04-17 15:02:26 -0500131static void qla2xxx_slave_destroy(struct scsi_device *);
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700132static int qla2xxx_queuecommand(struct scsi_cmnd *cmd,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700133 void (*fn)(struct scsi_cmnd *));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134static int qla2xxx_eh_abort(struct scsi_cmnd *);
135static int qla2xxx_eh_device_reset(struct scsi_cmnd *);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700136static int qla2xxx_eh_target_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700137static int qla2xxx_eh_bus_reset(struct scsi_cmnd *);
138static int qla2xxx_eh_host_reset(struct scsi_cmnd *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700139
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700140static int qla2x00_change_queue_depth(struct scsi_device *, int);
141static int qla2x00_change_queue_type(struct scsi_device *, int);
142
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700143struct scsi_host_template qla2xxx_driver_template = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700144 .module = THIS_MODULE,
Andrew Vasquezcb630672006-05-17 15:09:45 -0700145 .name = QLA2XXX_DRIVER_NAME,
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700146 .queuecommand = qla2xxx_queuecommand,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700147
148 .eh_abort_handler = qla2xxx_eh_abort,
149 .eh_device_reset_handler = qla2xxx_eh_device_reset,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700150 .eh_target_reset_handler = qla2xxx_eh_target_reset,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700151 .eh_bus_reset_handler = qla2xxx_eh_bus_reset,
152 .eh_host_reset_handler = qla2xxx_eh_host_reset,
153
154 .slave_configure = qla2xxx_slave_configure,
155
156 .slave_alloc = qla2xxx_slave_alloc,
157 .slave_destroy = qla2xxx_slave_destroy,
Andrew Vasquezed677082007-03-12 10:41:27 -0700158 .scan_finished = qla2xxx_scan_finished,
159 .scan_start = qla2xxx_scan_start,
Andrew Vasquezce7e4af2005-08-26 19:09:30 -0700160 .change_queue_depth = qla2x00_change_queue_depth,
161 .change_queue_type = qla2x00_change_queue_type,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700162 .this_id = -1,
163 .cmd_per_lun = 3,
164 .use_clustering = ENABLE_CLUSTERING,
165 .sg_tablesize = SG_ALL,
166
167 .max_sectors = 0xFFFF,
Andrew Vasquezafb046e2005-08-26 19:09:40 -0700168 .shost_attrs = qla2x00_host_attrs,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700169};
170
Linus Torvalds1da177e2005-04-16 15:20:36 -0700171static struct scsi_transport_template *qla2xxx_transport_template = NULL;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700172struct scsi_transport_template *qla2xxx_transport_vport_template = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Linus Torvalds1da177e2005-04-16 15:20:36 -0700174/* TODO Convert to inlines
175 *
176 * Timer routines
177 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700179__inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800180qla2x00_start_timer(scsi_qla_host_t *vha, void *func, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700181{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800182 init_timer(&vha->timer);
183 vha->timer.expires = jiffies + interval * HZ;
184 vha->timer.data = (unsigned long)vha;
185 vha->timer.function = (void (*)(unsigned long))func;
186 add_timer(&vha->timer);
187 vha->timer_active = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700188}
189
190static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800191qla2x00_restart_timer(scsi_qla_host_t *vha, unsigned long interval)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700192{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800193 mod_timer(&vha->timer, jiffies + interval * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194}
195
Adrian Bunka824ebb2008-01-17 09:02:15 -0800196static __inline__ void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800197qla2x00_stop_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700198{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800199 del_timer_sync(&vha->timer);
200 vha->timer_active = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700201}
202
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203static int qla2x00_do_dpc(void *data);
204
205static void qla2x00_rst_aen(scsi_qla_host_t *);
206
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800207static int qla2x00_mem_alloc(struct qla_hw_data *, uint16_t, uint16_t,
208 struct req_que **, struct rsp_que **);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800209static void qla2x00_mem_free(struct qla_hw_data *);
210static void qla2x00_sp_free_dma(srb_t *);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Linus Torvalds1da177e2005-04-16 15:20:36 -0700212/* -------------------------------------------------------------------------- */
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800213static int qla2x00_alloc_queues(struct qla_hw_data *ha)
214{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700215 ha->req_q_map = kzalloc(sizeof(struct req_que *) * ha->max_req_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800216 GFP_KERNEL);
217 if (!ha->req_q_map) {
218 qla_printk(KERN_WARNING, ha,
219 "Unable to allocate memory for request queue ptrs\n");
220 goto fail_req_map;
221 }
222
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700223 ha->rsp_q_map = kzalloc(sizeof(struct rsp_que *) * ha->max_rsp_queues,
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800224 GFP_KERNEL);
225 if (!ha->rsp_q_map) {
226 qla_printk(KERN_WARNING, ha,
227 "Unable to allocate memory for response queue ptrs\n");
228 goto fail_rsp_map;
229 }
230 set_bit(0, ha->rsp_qid_map);
231 set_bit(0, ha->req_qid_map);
232 return 1;
233
234fail_rsp_map:
235 kfree(ha->req_q_map);
236 ha->req_q_map = NULL;
237fail_req_map:
238 return -ENOMEM;
239}
240
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700241static void qla2x00_free_req_que(struct qla_hw_data *ha, struct req_que *req)
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800242{
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800243 if (req && req->ring)
244 dma_free_coherent(&ha->pdev->dev,
245 (req->length + 1) * sizeof(request_t),
246 req->ring, req->dma);
247
248 kfree(req);
249 req = NULL;
250}
251
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700252static void qla2x00_free_rsp_que(struct qla_hw_data *ha, struct rsp_que *rsp)
253{
254 if (rsp && rsp->ring)
255 dma_free_coherent(&ha->pdev->dev,
256 (rsp->length + 1) * sizeof(response_t),
257 rsp->ring, rsp->dma);
258
259 kfree(rsp);
260 rsp = NULL;
261}
262
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800263static void qla2x00_free_queues(struct qla_hw_data *ha)
264{
265 struct req_que *req;
266 struct rsp_que *rsp;
267 int cnt;
268
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700269 for (cnt = 0; cnt < ha->max_req_queues; cnt++) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800270 req = ha->req_q_map[cnt];
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700271 qla2x00_free_req_que(ha, req);
272 }
273 kfree(ha->req_q_map);
274 ha->req_q_map = NULL;
275
276 for (cnt = 0; cnt < ha->max_rsp_queues; cnt++) {
277 rsp = ha->rsp_q_map[cnt];
278 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800279 }
280 kfree(ha->rsp_q_map);
281 ha->rsp_q_map = NULL;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800282}
283
Anirban Chakraborty68ca9492009-04-06 22:33:41 -0700284static int qla25xx_setup_mode(struct scsi_qla_host *vha)
285{
286 uint16_t options = 0;
287 int ques, req, ret;
288 struct qla_hw_data *ha = vha->hw;
289
290 if (ql2xmultique_tag) {
291 /* CPU affinity mode */
292 ha->wq = create_workqueue("qla2xxx_wq");
293 /* create a request queue for IO */
294 options |= BIT_7;
295 req = qla25xx_create_req_que(ha, options, 0, 0, -1,
296 QLA_DEFAULT_QUE_QOS);
297 if (!req) {
298 qla_printk(KERN_WARNING, ha,
299 "Can't create request queue\n");
300 goto fail;
301 }
302 vha->req = ha->req_q_map[req];
303 options |= BIT_1;
304 for (ques = 1; ques < ha->max_rsp_queues; ques++) {
305 ret = qla25xx_create_rsp_que(ha, options, 0, 0, req);
306 if (!ret) {
307 qla_printk(KERN_WARNING, ha,
308 "Response Queue create failed\n");
309 goto fail2;
310 }
311 }
312 DEBUG2(qla_printk(KERN_INFO, ha,
313 "CPU affinity mode enabled, no. of response"
314 " queues:%d, no. of request queues:%d\n",
315 ha->max_rsp_queues, ha->max_req_queues));
316 }
317 return 0;
318fail2:
319 qla25xx_delete_queues(vha);
320fail:
321 ha->mqenable = 0;
322 return 1;
323}
324
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800326qla2x00_pci_info_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800328 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700329 static char *pci_bus_modes[] = {
330 "33", "66", "100", "133",
331 };
332 uint16_t pci_bus;
333
334 strcpy(str, "PCI");
335 pci_bus = (ha->pci_attr & (BIT_9 | BIT_10)) >> 9;
336 if (pci_bus) {
337 strcat(str, "-X (");
338 strcat(str, pci_bus_modes[pci_bus]);
339 } else {
340 pci_bus = (ha->pci_attr & BIT_8) >> 8;
341 strcat(str, " (");
342 strcat(str, pci_bus_modes[pci_bus]);
343 }
344 strcat(str, " MHz)");
345
346 return (str);
347}
348
Andrew Vasquezfca29702005-07-06 10:31:47 -0700349static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800350qla24xx_pci_info_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700351{
352 static char *pci_bus_modes[] = { "33", "66", "100", "133", };
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800353 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700354 uint32_t pci_bus;
355 int pcie_reg;
356
357 pcie_reg = pci_find_capability(ha->pdev, PCI_CAP_ID_EXP);
358 if (pcie_reg) {
359 char lwstr[6];
360 uint16_t pcie_lstat, lspeed, lwidth;
361
362 pcie_reg += 0x12;
363 pci_read_config_word(ha->pdev, pcie_reg, &pcie_lstat);
364 lspeed = pcie_lstat & (BIT_0 | BIT_1 | BIT_2 | BIT_3);
365 lwidth = (pcie_lstat &
366 (BIT_4 | BIT_5 | BIT_6 | BIT_7 | BIT_8 | BIT_9)) >> 4;
367
368 strcpy(str, "PCIe (");
369 if (lspeed == 1)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700370 strcat(str, "2.5GT/s ");
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -0700371 else if (lspeed == 2)
Andrew Vasquezc87a0d82008-04-03 13:13:21 -0700372 strcat(str, "5.0GT/s ");
Andrew Vasquezfca29702005-07-06 10:31:47 -0700373 else
374 strcat(str, "<unknown> ");
375 snprintf(lwstr, sizeof(lwstr), "x%d)", lwidth);
376 strcat(str, lwstr);
377
378 return str;
379 }
380
381 strcpy(str, "PCI");
382 pci_bus = (ha->pci_attr & CSRX_PCIX_BUS_MODE_MASK) >> 8;
383 if (pci_bus == 0 || pci_bus == 8) {
384 strcat(str, " (");
385 strcat(str, pci_bus_modes[pci_bus >> 3]);
386 } else {
387 strcat(str, "-X ");
388 if (pci_bus & BIT_2)
389 strcat(str, "Mode 2");
390 else
391 strcat(str, "Mode 1");
392 strcat(str, " (");
393 strcat(str, pci_bus_modes[pci_bus & ~BIT_2]);
394 }
395 strcat(str, " MHz)");
396
397 return str;
398}
399
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800400static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800401qla2x00_fw_version_str(struct scsi_qla_host *vha, char *str)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700402{
403 char un_str[10];
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800404 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700405
Linus Torvalds1da177e2005-04-16 15:20:36 -0700406 sprintf(str, "%d.%02d.%02d ", ha->fw_major_version,
407 ha->fw_minor_version,
408 ha->fw_subminor_version);
409
410 if (ha->fw_attributes & BIT_9) {
411 strcat(str, "FLX");
412 return (str);
413 }
414
415 switch (ha->fw_attributes & 0xFF) {
416 case 0x7:
417 strcat(str, "EF");
418 break;
419 case 0x17:
420 strcat(str, "TP");
421 break;
422 case 0x37:
423 strcat(str, "IP");
424 break;
425 case 0x77:
426 strcat(str, "VI");
427 break;
428 default:
429 sprintf(un_str, "(%x)", ha->fw_attributes);
430 strcat(str, un_str);
431 break;
432 }
433 if (ha->fw_attributes & 0x100)
434 strcat(str, "X");
435
436 return (str);
437}
438
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800439static char *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800440qla24xx_fw_version_str(struct scsi_qla_host *vha, char *str)
Andrew Vasquezfca29702005-07-06 10:31:47 -0700441{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800442 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezf0883ac2005-07-08 17:58:43 -0700443
Andrew Vasquez3a03eb72009-01-05 11:18:11 -0800444 sprintf(str, "%d.%02d.%02d (%x)", ha->fw_major_version,
445 ha->fw_minor_version, ha->fw_subminor_version, ha->fw_attributes);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700446 return str;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700447}
448
449static inline srb_t *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800450qla2x00_get_new_sp(scsi_qla_host_t *vha, fc_port_t *fcport,
Andrew Vasquezfca29702005-07-06 10:31:47 -0700451 struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
452{
453 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800454 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700455
456 sp = mempool_alloc(ha->srb_mempool, GFP_ATOMIC);
457 if (!sp)
458 return sp;
459
Andrew Vasquezfca29702005-07-06 10:31:47 -0700460 sp->fcport = fcport;
461 sp->cmd = cmd;
462 sp->flags = 0;
463 CMD_SP(cmd) = (void *)sp;
464 cmd->scsi_done = done;
465
466 return sp;
467}
468
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469static int
Giridhar Malavalia5326f82009-03-24 09:07:56 -0700470qla2xxx_queuecommand(struct scsi_cmnd *cmd, void (*done)(struct scsi_cmnd *))
Andrew Vasquezfca29702005-07-06 10:31:47 -0700471{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800472 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700473 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400474 struct fc_rport *rport = starget_to_rport(scsi_target(cmd->device));
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800475 struct qla_hw_data *ha = vha->hw;
476 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700477 srb_t *sp;
478 int rval;
479
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800480 if (unlikely(pci_channel_offline(ha->pdev))) {
Seokmann Jub9b12f72009-03-24 09:08:18 -0700481 if (ha->pdev->error_state == pci_channel_io_frozen)
482 cmd->result = DID_REQUEUE << 16;
483 else
484 cmd->result = DID_NO_CONNECT << 16;
Seokmann Ju14e660e2007-09-20 14:07:36 -0700485 goto qc24_fail_command;
486 }
487
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -0400488 rval = fc_remote_port_chkready(rport);
489 if (rval) {
490 cmd->result = rval;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700491 goto qc24_fail_command;
492 }
493
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800494 /* Close window on fcport/rport state-transitioning. */
Mike Christie7b594132008-08-17 15:24:40 -0500495 if (fcport->drport)
496 goto qc24_target_busy;
andrew.vasquez@qlogic.com387f96b2006-02-07 08:45:45 -0800497
Andrew Vasquezfca29702005-07-06 10:31:47 -0700498 if (atomic_read(&fcport->state) != FCS_ONLINE) {
499 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800500 atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Andrew Vasquezfca29702005-07-06 10:31:47 -0700501 cmd->result = DID_NO_CONNECT << 16;
502 goto qc24_fail_command;
503 }
Mike Christie7b594132008-08-17 15:24:40 -0500504 goto qc24_target_busy;
Andrew Vasquezfca29702005-07-06 10:31:47 -0700505 }
506
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800507 spin_unlock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700508
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800509 sp = qla2x00_get_new_sp(base_vha, fcport, cmd, done);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700510 if (!sp)
511 goto qc24_host_busy_lock;
512
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800513 rval = ha->isp_ops->start_scsi(sp);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700514 if (rval != QLA_SUCCESS)
515 goto qc24_host_busy_free_sp;
516
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800517 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700518
519 return 0;
520
521qc24_host_busy_free_sp:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800522 qla2x00_sp_free_dma(sp);
523 mempool_free(sp, ha->srb_mempool);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700524
525qc24_host_busy_lock:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800526 spin_lock_irq(vha->host->host_lock);
Andrew Vasquezfca29702005-07-06 10:31:47 -0700527 return SCSI_MLQUEUE_HOST_BUSY;
528
Mike Christie7b594132008-08-17 15:24:40 -0500529qc24_target_busy:
530 return SCSI_MLQUEUE_TARGET_BUSY;
531
Andrew Vasquezfca29702005-07-06 10:31:47 -0700532qc24_fail_command:
533 done(cmd);
534
535 return 0;
536}
537
538
Linus Torvalds1da177e2005-04-16 15:20:36 -0700539/*
540 * qla2x00_eh_wait_on_command
541 * Waits for the command to be returned by the Firmware for some
542 * max time.
543 *
544 * Input:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 * cmd = Scsi Command to wait on.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700546 *
547 * Return:
548 * Not Found : 0
549 * Found : 1
550 */
551static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800552qla2x00_eh_wait_on_command(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553{
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700554#define ABORT_POLLING_PERIOD 1000
555#define ABORT_WAIT_ITER ((10 * 1000) / (ABORT_POLLING_PERIOD))
f4f051e2005-04-17 15:02:26 -0500556 unsigned long wait_iter = ABORT_WAIT_ITER;
557 int ret = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700558
f4f051e2005-04-17 15:02:26 -0500559 while (CMD_SP(cmd)) {
Andrew Vasquezfe74c712005-08-26 19:10:10 -0700560 msleep(ABORT_POLLING_PERIOD);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700561
f4f051e2005-04-17 15:02:26 -0500562 if (--wait_iter)
563 break;
564 }
565 if (CMD_SP(cmd))
566 ret = QLA_FUNCTION_FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700567
f4f051e2005-04-17 15:02:26 -0500568 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700569}
570
571/*
572 * qla2x00_wait_for_hba_online
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700573 * Wait till the HBA is online after going through
Linus Torvalds1da177e2005-04-16 15:20:36 -0700574 * <= MAX_RETRIES_OF_ISP_ABORT or
575 * finally HBA is disabled ie marked offline
576 *
577 * Input:
578 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700579 *
580 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700581 * Does context switching-Release SPIN_LOCK
582 * (if any) before calling this routine.
583 *
584 * Return:
585 * Success (Adapter is online) : 0
586 * Failed (Adapter is offline/disabled) : 1
587 */
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -0800588int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800589qla2x00_wait_for_hba_online(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700590{
Andrew Vasquezfca29702005-07-06 10:31:47 -0700591 int return_status;
592 unsigned long wait_online;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800593 struct qla_hw_data *ha = vha->hw;
594 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700596 wait_online = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800597 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
598 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
599 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
600 ha->dpc_active) && time_before(jiffies, wait_online)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601
602 msleep(1000);
603 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800604 if (base_vha->flags.online)
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700605 return_status = QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606 else
607 return_status = QLA_FUNCTION_FAILED;
608
Linus Torvalds1da177e2005-04-16 15:20:36 -0700609 return (return_status);
610}
611
Lalit Chandivade2533cf62009-03-24 09:08:07 -0700612int
613qla2x00_wait_for_chip_reset(scsi_qla_host_t *vha)
614{
615 int return_status;
616 unsigned long wait_reset;
617 struct qla_hw_data *ha = vha->hw;
618 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
619
620 wait_reset = jiffies + (MAX_LOOP_TIMEOUT * HZ);
621 while (((test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags)) ||
622 test_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags) ||
623 test_bit(ISP_ABORT_RETRY, &base_vha->dpc_flags) ||
624 ha->dpc_active) && time_before(jiffies, wait_reset)) {
625
626 msleep(1000);
627
628 if (!test_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags) &&
629 ha->flags.chip_reset_done)
630 break;
631 }
632 if (ha->flags.chip_reset_done)
633 return_status = QLA_SUCCESS;
634 else
635 return_status = QLA_FUNCTION_FAILED;
636
637 return return_status;
638}
639
Linus Torvalds1da177e2005-04-16 15:20:36 -0700640/*
641 * qla2x00_wait_for_loop_ready
642 * Wait for MAX_LOOP_TIMEOUT(5 min) value for loop
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700643 * to be in LOOP_READY state.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 * Input:
645 * ha - pointer to host adapter structure
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700646 *
647 * Note:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648 * Does context switching-Release SPIN_LOCK
649 * (if any) before calling this routine.
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700650 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700651 *
652 * Return:
653 * Success (LOOP_READY) : 0
654 * Failed (LOOP_NOT_READY) : 1
655 */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700656static inline int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800657qla2x00_wait_for_loop_ready(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700658{
659 int return_status = QLA_SUCCESS;
660 unsigned long loop_timeout ;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800661 struct qla_hw_data *ha = vha->hw;
662 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700663
664 /* wait for 5 min at the max for loop to be ready */
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700665 loop_timeout = jiffies + (MAX_LOOP_TIMEOUT * HZ);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800667 while ((!atomic_read(&base_vha->loop_down_timer) &&
668 atomic_read(&base_vha->loop_state) == LOOP_DOWN) ||
669 atomic_read(&base_vha->loop_state) != LOOP_READY) {
670 if (atomic_read(&base_vha->loop_state) == LOOP_DEAD) {
Ravi Anand57680082006-05-17 15:08:44 -0700671 return_status = QLA_FUNCTION_FAILED;
672 break;
673 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674 msleep(1000);
675 if (time_after_eq(jiffies, loop_timeout)) {
676 return_status = QLA_FUNCTION_FAILED;
677 break;
678 }
679 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700680 return (return_status);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681}
682
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700683void
684qla2x00_abort_fcport_cmds(fc_port_t *fcport)
685{
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700686 int cnt;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700687 unsigned long flags;
688 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800689 scsi_qla_host_t *vha = fcport->vha;
690 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800691 struct req_que *req;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800693 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700694 req = vha->req;
695 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
696 sp = req->outstanding_cmds[cnt];
697 if (!sp)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700698 continue;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700699 if (sp->fcport != fcport)
700 continue;
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700701
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700702 spin_unlock_irqrestore(&ha->hardware_lock, flags);
703 if (ha->isp_ops->abort_command(sp)) {
704 DEBUG2(qla_printk(KERN_WARNING, ha,
705 "Abort failed -- %lx\n",
706 sp->cmd->serial_number));
707 } else {
708 if (qla2x00_eh_wait_on_command(sp->cmd) !=
709 QLA_SUCCESS)
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700710 DEBUG2(qla_printk(KERN_WARNING, ha,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700711 "Abort failed while waiting -- %lx\n",
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800712 sp->cmd->serial_number));
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700713 }
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700714 spin_lock_irqsave(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700715 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800716 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -0700717}
718
Andrew Vasquez07db5182006-10-02 12:00:49 -0700719static void
720qla2x00_block_error_handler(struct scsi_cmnd *cmnd)
721{
722 struct Scsi_Host *shost = cmnd->device->host;
723 struct fc_rport *rport = starget_to_rport(scsi_target(cmnd->device));
724 unsigned long flags;
725
726 spin_lock_irqsave(shost->host_lock, flags);
727 while (rport->port_state == FC_PORTSTATE_BLOCKED) {
728 spin_unlock_irqrestore(shost->host_lock, flags);
729 msleep(1000);
730 spin_lock_irqsave(shost->host_lock, flags);
731 }
732 spin_unlock_irqrestore(shost->host_lock, flags);
733 return;
734}
735
Linus Torvalds1da177e2005-04-16 15:20:36 -0700736/**************************************************************************
737* qla2xxx_eh_abort
738*
739* Description:
740* The abort function will abort the specified command.
741*
742* Input:
743* cmd = Linux SCSI command packet to be aborted.
744*
745* Returns:
746* Either SUCCESS or FAILED.
747*
748* Note:
Michael Reed2ea00202006-04-27 16:25:30 -0700749* Only return FAILED if command not returned by firmware.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800751static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700752qla2xxx_eh_abort(struct scsi_cmnd *cmd)
753{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800754 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
f4f051e2005-04-17 15:02:26 -0500755 srb_t *sp;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800756 int ret, i;
f4f051e2005-04-17 15:02:26 -0500757 unsigned int id, lun;
758 unsigned long serial;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700759 unsigned long flags;
Michael Reed2ea00202006-04-27 16:25:30 -0700760 int wait = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800761 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700762 struct req_que *req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800763 srb_t *spt;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
Andrew Vasquez07db5182006-10-02 12:00:49 -0700765 qla2x00_block_error_handler(cmd);
766
f4f051e2005-04-17 15:02:26 -0500767 if (!CMD_SP(cmd))
Michael Reed2ea00202006-04-27 16:25:30 -0700768 return SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769
Michael Reed2ea00202006-04-27 16:25:30 -0700770 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700771
f4f051e2005-04-17 15:02:26 -0500772 id = cmd->device->id;
773 lun = cmd->device->lun;
774 serial = cmd->serial_number;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800775 spt = (srb_t *) CMD_SP(cmd);
776 if (!spt)
777 return SUCCESS;
f4f051e2005-04-17 15:02:26 -0500778
779 /* Check active list for command command. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800780 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800781 for (i = 1; i < MAX_OUTSTANDING_COMMANDS; i++) {
782 sp = req->outstanding_cmds[i];
783
784 if (sp == NULL)
f4f051e2005-04-17 15:02:26 -0500785 continue;
786
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800787 if (sp->cmd != cmd)
788 continue;
f4f051e2005-04-17 15:02:26 -0500789
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800790 DEBUG2(printk("%s(%ld): aborting sp %p from RISC."
791 " pid=%ld.\n", __func__, vha->host_no, sp, serial));
f4f051e2005-04-17 15:02:26 -0500792
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800793 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700794 if (ha->isp_ops->abort_command(sp)) {
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800795 DEBUG2(printk("%s(%ld): abort_command "
796 "mbx failed.\n", __func__, vha->host_no));
Andrew Vasquez2ac4b642009-01-22 09:45:35 -0800797 ret = FAILED;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800798 } else {
799 DEBUG3(printk("%s(%ld): abort_command "
800 "mbx success.\n", __func__, vha->host_no));
801 wait = 1;
f4f051e2005-04-17 15:02:26 -0500802 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800803 spin_lock_irqsave(&ha->hardware_lock, flags);
804 break;
f4f051e2005-04-17 15:02:26 -0500805 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
f4f051e2005-04-17 15:02:26 -0500807
808 /* Wait for the command to be returned. */
Michael Reed2ea00202006-04-27 16:25:30 -0700809 if (wait) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800810 if (qla2x00_eh_wait_on_command(cmd) != QLA_SUCCESS) {
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700811 qla_printk(KERN_ERR, ha,
f4f051e2005-04-17 15:02:26 -0500812 "scsi(%ld:%d:%d): Abort handler timed out -- %lx "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800813 "%x.\n", vha->host_no, id, lun, serial, ret);
Michael Reed2ea00202006-04-27 16:25:30 -0700814 ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500815 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700816 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700817
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -0700818 qla_printk(KERN_INFO, ha,
Michael Reed2ea00202006-04-27 16:25:30 -0700819 "scsi(%ld:%d:%d): Abort command issued -- %d %lx %x.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800820 vha->host_no, id, lun, wait, serial, ret);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
f4f051e2005-04-17 15:02:26 -0500822 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700823}
824
Andrew Vasquez523ec772008-04-03 13:13:24 -0700825enum nexus_wait_type {
826 WAIT_HOST = 0,
827 WAIT_TARGET,
828 WAIT_LUN,
829};
830
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800832qla2x00_eh_wait_for_pending_commands(scsi_qla_host_t *vha, unsigned int t,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800833 unsigned int l, srb_t *sp, enum nexus_wait_type type)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834{
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800835 int cnt, match, status;
Andrew Vasquez18e144d2005-05-27 15:04:47 -0700836 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800837 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -0800838 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700839
Andrew Vasquez523ec772008-04-03 13:13:24 -0700840 status = QLA_SUCCESS;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800841 if (!sp)
842 return status;
843
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800844 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty67c2e932009-04-06 22:33:42 -0700845 req = vha->req;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800846 for (cnt = 1; status == QLA_SUCCESS &&
847 cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
848 sp = req->outstanding_cmds[cnt];
849 if (!sp)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700850 continue;
Andrew Vasquez19851f12008-08-13 21:37:00 -0700851
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800852 if (vha->vp_idx != sp->fcport->vha->vp_idx)
853 continue;
854 match = 0;
855 switch (type) {
856 case WAIT_HOST:
857 match = 1;
858 break;
859 case WAIT_TARGET:
860 match = sp->cmd->device->id == t;
861 break;
862 case WAIT_LUN:
863 match = (sp->cmd->device->id == t &&
864 sp->cmd->device->lun == l);
865 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700866 }
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800867 if (!match)
868 continue;
869
870 spin_unlock_irqrestore(&ha->hardware_lock, flags);
871 status = qla2x00_eh_wait_on_command(sp->cmd);
872 spin_lock_irqsave(&ha->hardware_lock, flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800874 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700875
876 return status;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877}
878
Andrew Vasquez523ec772008-04-03 13:13:24 -0700879static char *reset_errors[] = {
880 "HBA not online",
881 "HBA not ready",
882 "Task management failed",
883 "Waiting for command completions",
884};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885
Andrew Vasquez523ec772008-04-03 13:13:24 -0700886static int
887__qla2xxx_eh_generic_reset(char *name, enum nexus_wait_type type,
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700888 struct scsi_cmnd *cmd, int (*do_reset)(struct fc_port *, unsigned int, int))
Andrew Vasquez523ec772008-04-03 13:13:24 -0700889{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800890 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700891 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
892 int err;
893
894 qla2x00_block_error_handler(cmd);
895
896 if (!fcport)
897 return FAILED;
898
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800899 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET ISSUED.\n",
900 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700901
902 err = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800903 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700904 goto eh_reset_failed;
905 err = 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800906 if (qla2x00_wait_for_loop_ready(vha) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700907 goto eh_reset_failed;
908 err = 2;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -0700909 if (do_reset(fcport, cmd->device->lun, cmd->request->cpu + 1)
910 != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700911 goto eh_reset_failed;
912 err = 3;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800913 if (qla2x00_eh_wait_for_pending_commands(vha, cmd->device->id,
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800914 cmd->device->lun, (srb_t *) CMD_SP(cmd), type) != QLA_SUCCESS)
Andrew Vasquez523ec772008-04-03 13:13:24 -0700915 goto eh_reset_failed;
916
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800917 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET SUCCEEDED.\n",
918 vha->host_no, cmd->device->id, cmd->device->lun, name);
Andrew Vasquez523ec772008-04-03 13:13:24 -0700919
920 return SUCCESS;
921
922 eh_reset_failed:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800923 qla_printk(KERN_INFO, vha->hw, "scsi(%ld:%d:%d): %s RESET FAILED: %s.\n"
924 , vha->host_no, cmd->device->id, cmd->device->lun, name,
Andrew Vasquez523ec772008-04-03 13:13:24 -0700925 reset_errors[err]);
926 return FAILED;
927}
928
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800929static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700930qla2xxx_eh_device_reset(struct scsi_cmnd *cmd)
931{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800932 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
933 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
Andrew Vasquez523ec772008-04-03 13:13:24 -0700935 return __qla2xxx_eh_generic_reset("DEVICE", WAIT_LUN, cmd,
936 ha->isp_ops->lun_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700937}
938
Linus Torvalds1da177e2005-04-16 15:20:36 -0700939static int
Andrew Vasquez523ec772008-04-03 13:13:24 -0700940qla2xxx_eh_target_reset(struct scsi_cmnd *cmd)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700941{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800942 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
943 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700944
Andrew Vasquez523ec772008-04-03 13:13:24 -0700945 return __qla2xxx_eh_generic_reset("TARGET", WAIT_TARGET, cmd,
946 ha->isp_ops->target_reset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947}
948
Linus Torvalds1da177e2005-04-16 15:20:36 -0700949/**************************************************************************
950* qla2xxx_eh_bus_reset
951*
952* Description:
953* The bus reset function will reset the bus and abort any executing
954* commands.
955*
956* Input:
957* cmd = Linux SCSI command packet of the command that cause the
958* bus reset.
959*
960* Returns:
961* SUCCESS/FAILURE (defined as macro in scsi.h).
962*
963**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -0800964static int
Linus Torvalds1da177e2005-04-16 15:20:36 -0700965qla2xxx_eh_bus_reset(struct scsi_cmnd *cmd)
966{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800967 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -0500968 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -0700969 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -0500970 unsigned int id, lun;
971 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800972 srb_t *sp = (srb_t *) CMD_SP(cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700973
Andrew Vasquez07db5182006-10-02 12:00:49 -0700974 qla2x00_block_error_handler(cmd);
975
f4f051e2005-04-17 15:02:26 -0500976 id = cmd->device->id;
977 lun = cmd->device->lun;
978 serial = cmd->serial_number;
979
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -0700980 if (!fcport)
f4f051e2005-04-17 15:02:26 -0500981 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700982
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800983 qla_printk(KERN_INFO, vha->hw,
Anirban Chakraborty749af3d2008-11-14 13:48:12 -0800984 "scsi(%ld:%d:%d): BUS RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700985
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800986 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700987 DEBUG2(printk("%s failed:board disabled\n",__func__));
f4f051e2005-04-17 15:02:26 -0500988 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700989 }
990
Anirban Chakrabortye315cd22008-11-06 10:40:51 -0800991 if (qla2x00_wait_for_loop_ready(vha) == QLA_SUCCESS) {
992 if (qla2x00_loop_reset(vha) == QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -0500993 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700994 }
f4f051e2005-04-17 15:02:26 -0500995 if (ret == FAILED)
996 goto eh_bus_reset_done;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700997
Andrew Vasquez9a41a622005-09-20 13:25:53 -0700998 /* Flush outstanding commands. */
Anirban Chakraborty17d98632008-12-18 10:06:15 -0800999 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) !=
Andrew Vasquez523ec772008-04-03 13:13:24 -07001000 QLA_SUCCESS)
Andrew Vasquez9a41a622005-09-20 13:25:53 -07001001 ret = FAILED;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001002
f4f051e2005-04-17 15:02:26 -05001003eh_bus_reset_done:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001004 qla_printk(KERN_INFO, vha->hw, "%s: reset %s\n", __func__,
f4f051e2005-04-17 15:02:26 -05001005 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001006
f4f051e2005-04-17 15:02:26 -05001007 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001008}
1009
1010/**************************************************************************
1011* qla2xxx_eh_host_reset
1012*
1013* Description:
1014* The reset function will reset the Adapter.
1015*
1016* Input:
1017* cmd = Linux SCSI command packet of the command that cause the
1018* adapter reset.
1019*
1020* Returns:
1021* Either SUCCESS or FAILED.
1022*
1023* Note:
1024**************************************************************************/
Adrian Bunke5f82ab2006-11-08 19:55:50 -08001025static int
Linus Torvalds1da177e2005-04-16 15:20:36 -07001026qla2xxx_eh_host_reset(struct scsi_cmnd *cmd)
1027{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001028 scsi_qla_host_t *vha = shost_priv(cmd->device->host);
bdf79622005-04-17 15:06:53 -05001029 fc_port_t *fcport = (struct fc_port *) cmd->device->hostdata;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001030 struct qla_hw_data *ha = vha->hw;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001031 int ret = FAILED;
f4f051e2005-04-17 15:02:26 -05001032 unsigned int id, lun;
1033 unsigned long serial;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001034 srb_t *sp = (srb_t *) CMD_SP(cmd);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001035 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001036
Andrew Vasquez07db5182006-10-02 12:00:49 -07001037 qla2x00_block_error_handler(cmd);
1038
f4f051e2005-04-17 15:02:26 -05001039 id = cmd->device->id;
1040 lun = cmd->device->lun;
1041 serial = cmd->serial_number;
1042
Vladislav Bolkhovitinb0328be2006-08-01 13:48:15 -07001043 if (!fcport)
f4f051e2005-04-17 15:02:26 -05001044 return ret;
1045
Linus Torvalds1da177e2005-04-16 15:20:36 -07001046 qla_printk(KERN_INFO, ha,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001047 "scsi(%ld:%d:%d): ADAPTER RESET ISSUED.\n", vha->host_no, id, lun);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001048
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001049 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001050 goto eh_host_reset_lock;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001051
1052 /*
1053 * Fixme-may be dpc thread is active and processing
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001054 * loop_resync,so wait a while for it to
Linus Torvalds1da177e2005-04-16 15:20:36 -07001055 * be completed and then issue big hammer.Otherwise
1056 * it may cause I/O failure as big hammer marks the
1057 * devices as lost kicking of the port_down_timer
1058 * while dpc is stuck for the mailbox to complete.
1059 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001060 qla2x00_wait_for_loop_ready(vha);
1061 if (vha != base_vha) {
1062 if (qla2x00_vp_abort_isp(vha))
f4f051e2005-04-17 15:02:26 -05001063 goto eh_host_reset_lock;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001064 } else {
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001065 if (ha->wq)
1066 flush_workqueue(ha->wq);
1067
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001068 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1069 if (qla2x00_abort_isp(base_vha)) {
1070 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
1071 /* failed. schedule dpc to try */
1072 set_bit(ISP_ABORT_NEEDED, &base_vha->dpc_flags);
1073
1074 if (qla2x00_wait_for_hba_online(vha) != QLA_SUCCESS)
1075 goto eh_host_reset_lock;
1076 }
1077 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07001078 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001079
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001080 /* Waiting for command to be returned to OS.*/
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001081 if (qla2x00_eh_wait_for_pending_commands(vha, 0, 0, sp, WAIT_HOST) ==
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001082 QLA_SUCCESS)
f4f051e2005-04-17 15:02:26 -05001083 ret = SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001084
f4f051e2005-04-17 15:02:26 -05001085eh_host_reset_lock:
f4f051e2005-04-17 15:02:26 -05001086 qla_printk(KERN_INFO, ha, "%s: reset %s\n", __func__,
1087 (ret == FAILED) ? "failed" : "succeded");
Linus Torvalds1da177e2005-04-16 15:20:36 -07001088
f4f051e2005-04-17 15:02:26 -05001089 return ret;
1090}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001091
1092/*
1093* qla2x00_loop_reset
1094* Issue loop reset.
1095*
1096* Input:
1097* ha = adapter block pointer.
1098*
1099* Returns:
1100* 0 = success
1101*/
Andrew Vasqueza4722cf2008-01-17 09:02:12 -08001102int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001103qla2x00_loop_reset(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001104{
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001105 int ret;
bdf79622005-04-17 15:06:53 -05001106 struct fc_port *fcport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001107 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001108
Seokmann Jud53b48d2009-04-06 22:33:37 -07001109 if (ha->flags.enable_lip_full_login && !vha->vp_idx &&
1110 !IS_QLA81XX(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001111 ret = qla2x00_full_login_lip(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001112 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001113 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001114 "full_login_lip=%d.\n", __func__, vha->host_no,
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001115 ret));
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001116 }
1117 atomic_set(&vha->loop_state, LOOP_DOWN);
1118 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1119 qla2x00_mark_all_devices_lost(vha, 0);
1120 qla2x00_wait_for_loop_ready(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001121 }
1122
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001123 if (ha->flags.enable_lip_reset && !vha->vp_idx) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001124 ret = qla2x00_lip_reset(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001125 if (ret != QLA_SUCCESS) {
Anirban Chakraborty749af3d2008-11-14 13:48:12 -08001126 DEBUG2_3(printk("%s(%ld): failed: "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001127 "lip_reset=%d.\n", __func__, vha->host_no, ret));
1128 } else
1129 qla2x00_wait_for_loop_ready(vha);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001130 }
1131
1132 if (ha->flags.enable_target_reset) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001133 list_for_each_entry(fcport, &vha->vp_fcports, list) {
bdf79622005-04-17 15:06:53 -05001134 if (fcport->port_type != FCT_TARGET)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001135 continue;
1136
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001137 ret = ha->isp_ops->target_reset(fcport, 0, 0);
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001138 if (ret != QLA_SUCCESS) {
1139 DEBUG2_3(printk("%s(%ld): bus_reset failed: "
1140 "target_reset=%d d_id=%x.\n", __func__,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001141 vha->host_no, ret, fcport->d_id.b24));
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001142 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001143 }
1144 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001145 /* Issue marker command only when we are going to start the I/O */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001146 vha->marker_needed = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001147
Andrew Vasquez0c8c39a2006-12-13 19:20:30 -08001148 return QLA_SUCCESS;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001149}
1150
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001151void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001152qla2x00_abort_all_cmds(scsi_qla_host_t *vha, int res)
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001153{
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001154 int que, cnt;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001155 unsigned long flags;
1156 srb_t *sp;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001157 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001158 struct req_que *req;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001159
1160 spin_lock_irqsave(&ha->hardware_lock, flags);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001161 for (que = 0; que < ha->max_req_queues; que++) {
Anirban Chakraborty29bdccb2009-01-08 15:41:08 -08001162 req = ha->req_q_map[que];
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001163 if (!req)
1164 continue;
1165 for (cnt = 1; cnt < MAX_OUTSTANDING_COMMANDS; cnt++) {
1166 sp = req->outstanding_cmds[cnt];
Andrew Vasqueze612d462009-03-24 09:08:04 -07001167 if (sp) {
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001168 req->outstanding_cmds[cnt] = NULL;
1169 sp->cmd->result = res;
1170 qla2x00_sp_compl(ha, sp);
1171 }
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001172 }
1173 }
1174 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1175}
1176
f4f051e2005-04-17 15:02:26 -05001177static int
1178qla2xxx_slave_alloc(struct scsi_device *sdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001179{
bdf79622005-04-17 15:06:53 -05001180 struct fc_rport *rport = starget_to_rport(scsi_target(sdev));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001181
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001182 if (!rport || fc_remote_port_chkready(rport))
f4f051e2005-04-17 15:02:26 -05001183 return -ENXIO;
1184
James.Smart@Emulex.Com19a7b4a2005-10-18 12:03:35 -04001185 sdev->hostdata = *(fc_port_t **)rport->dd_data;
f4f051e2005-04-17 15:02:26 -05001186
1187 return 0;
1188}
1189
1190static int
1191qla2xxx_slave_configure(struct scsi_device *sdev)
1192{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001193 scsi_qla_host_t *vha = shost_priv(sdev->host);
1194 struct qla_hw_data *ha = vha->hw;
8482e1182005-04-17 15:04:54 -05001195 struct fc_rport *rport = starget_to_rport(sdev->sdev_target);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001196 struct req_que *req = vha->req;
8482e1182005-04-17 15:04:54 -05001197
f4f051e2005-04-17 15:02:26 -05001198 if (sdev->tagged_supported)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001199 scsi_activate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001200 else
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001201 scsi_deactivate_tcq(sdev, req->max_q_depth);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001202
Andrew Vasquez85821c92008-07-10 16:55:48 -07001203 rport->dev_loss_tmo = ha->port_down_retry_count;
8482e1182005-04-17 15:04:54 -05001204
f4f051e2005-04-17 15:02:26 -05001205 return 0;
1206}
Linus Torvalds1da177e2005-04-16 15:20:36 -07001207
f4f051e2005-04-17 15:02:26 -05001208static void
1209qla2xxx_slave_destroy(struct scsi_device *sdev)
1210{
1211 sdev->hostdata = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001212}
1213
Andrew Vasquezce7e4af2005-08-26 19:09:30 -07001214static int
1215qla2x00_change_queue_depth(struct scsi_device *sdev, int qdepth)
1216{
1217 scsi_adjust_queue_depth(sdev, scsi_get_tag_type(sdev), qdepth);
1218 return sdev->queue_depth;
1219}
1220
1221static int
1222qla2x00_change_queue_type(struct scsi_device *sdev, int tag_type)
1223{
1224 if (sdev->tagged_supported) {
1225 scsi_set_tag_type(sdev, tag_type);
1226 if (tag_type)
1227 scsi_activate_tcq(sdev, sdev->queue_depth);
1228 else
1229 scsi_deactivate_tcq(sdev, sdev->queue_depth);
1230 } else
1231 tag_type = 0;
1232
1233 return tag_type;
1234}
1235
Linus Torvalds1da177e2005-04-16 15:20:36 -07001236/**
1237 * qla2x00_config_dma_addressing() - Configure OS DMA addressing method.
1238 * @ha: HA context
1239 *
1240 * At exit, the @ha's flags.enable_64bit_addressing set to indicated
1241 * supported addressing method.
1242 */
1243static void
Andrew Vasquez53303c42009-01-22 09:45:37 -08001244qla2x00_config_dma_addressing(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001245{
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001246 /* Assume a 32bit DMA mask. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001247 ha->flags.enable_64bit_addressing = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001248
Yang Hongyang6a355282009-04-06 19:01:13 -07001249 if (!dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001250 /* Any upper-dword bits set? */
1251 if (MSD(dma_get_required_mask(&ha->pdev->dev)) &&
Yang Hongyang6a355282009-04-06 19:01:13 -07001252 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001253 /* Ok, a 64bit DMA mask is applicable. */
Linus Torvalds1da177e2005-04-16 15:20:36 -07001254 ha->flags.enable_64bit_addressing = 1;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001255 ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
1256 ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001258 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001259 }
Andrew Vasquez7524f9b2005-08-26 19:08:00 -07001260
Yang Hongyang284901a2009-04-06 19:01:15 -07001261 dma_set_mask(&ha->pdev->dev, DMA_BIT_MASK(32));
1262 pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(32));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001263}
1264
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001265static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001266qla2x00_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001267{
1268 unsigned long flags = 0;
1269 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1270
1271 spin_lock_irqsave(&ha->hardware_lock, flags);
1272 ha->interrupts_on = 1;
1273 /* enable risc and host interrupts */
1274 WRT_REG_WORD(&reg->ictrl, ICR_EN_INT | ICR_EN_RISC);
1275 RD_REG_WORD(&reg->ictrl);
1276 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1277
1278}
1279
1280static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001281qla2x00_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001282{
1283 unsigned long flags = 0;
1284 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
1285
1286 spin_lock_irqsave(&ha->hardware_lock, flags);
1287 ha->interrupts_on = 0;
1288 /* disable risc and host interrupts */
1289 WRT_REG_WORD(&reg->ictrl, 0);
1290 RD_REG_WORD(&reg->ictrl);
1291 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1292}
1293
1294static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001295qla24xx_enable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001296{
1297 unsigned long flags = 0;
1298 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1299
1300 spin_lock_irqsave(&ha->hardware_lock, flags);
1301 ha->interrupts_on = 1;
1302 WRT_REG_DWORD(&reg->ictrl, ICRX_EN_RISC_INT);
1303 RD_REG_DWORD(&reg->ictrl);
1304 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1305}
1306
1307static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001308qla24xx_disable_intrs(struct qla_hw_data *ha)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001309{
1310 unsigned long flags = 0;
1311 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
1312
Andrew Vasquez124f85e2009-01-05 11:18:06 -08001313 if (IS_NOPOLLING_TYPE(ha))
1314 return;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001315 spin_lock_irqsave(&ha->hardware_lock, flags);
1316 ha->interrupts_on = 0;
1317 WRT_REG_DWORD(&reg->ictrl, 0);
1318 RD_REG_DWORD(&reg->ictrl);
1319 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1320}
1321
1322static struct isp_operations qla2100_isp_ops = {
1323 .pci_config = qla2100_pci_config,
1324 .reset_chip = qla2x00_reset_chip,
1325 .chip_diag = qla2x00_chip_diag,
1326 .config_rings = qla2x00_config_rings,
1327 .reset_adapter = qla2x00_reset_adapter,
1328 .nvram_config = qla2x00_nvram_config,
1329 .update_fw_options = qla2x00_update_fw_options,
1330 .load_risc = qla2x00_load_risc,
1331 .pci_info_str = qla2x00_pci_info_str,
1332 .fw_version_str = qla2x00_fw_version_str,
1333 .intr_handler = qla2100_intr_handler,
1334 .enable_intrs = qla2x00_enable_intrs,
1335 .disable_intrs = qla2x00_disable_intrs,
1336 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001337 .target_reset = qla2x00_abort_target,
1338 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001339 .fabric_login = qla2x00_login_fabric,
1340 .fabric_logout = qla2x00_fabric_logout,
1341 .calc_req_entries = qla2x00_calc_iocbs_32,
1342 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1343 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1344 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1345 .read_nvram = qla2x00_read_nvram_data,
1346 .write_nvram = qla2x00_write_nvram_data,
1347 .fw_dump = qla2100_fw_dump,
1348 .beacon_on = NULL,
1349 .beacon_off = NULL,
1350 .beacon_blink = NULL,
1351 .read_optrom = qla2x00_read_optrom_data,
1352 .write_optrom = qla2x00_write_optrom_data,
1353 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001354 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001355};
1356
1357static struct isp_operations qla2300_isp_ops = {
1358 .pci_config = qla2300_pci_config,
1359 .reset_chip = qla2x00_reset_chip,
1360 .chip_diag = qla2x00_chip_diag,
1361 .config_rings = qla2x00_config_rings,
1362 .reset_adapter = qla2x00_reset_adapter,
1363 .nvram_config = qla2x00_nvram_config,
1364 .update_fw_options = qla2x00_update_fw_options,
1365 .load_risc = qla2x00_load_risc,
1366 .pci_info_str = qla2x00_pci_info_str,
1367 .fw_version_str = qla2x00_fw_version_str,
1368 .intr_handler = qla2300_intr_handler,
1369 .enable_intrs = qla2x00_enable_intrs,
1370 .disable_intrs = qla2x00_disable_intrs,
1371 .abort_command = qla2x00_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001372 .target_reset = qla2x00_abort_target,
1373 .lun_reset = qla2x00_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001374 .fabric_login = qla2x00_login_fabric,
1375 .fabric_logout = qla2x00_fabric_logout,
1376 .calc_req_entries = qla2x00_calc_iocbs_32,
1377 .build_iocbs = qla2x00_build_scsi_iocbs_32,
1378 .prep_ms_iocb = qla2x00_prep_ms_iocb,
1379 .prep_ms_fdmi_iocb = qla2x00_prep_ms_fdmi_iocb,
1380 .read_nvram = qla2x00_read_nvram_data,
1381 .write_nvram = qla2x00_write_nvram_data,
1382 .fw_dump = qla2300_fw_dump,
1383 .beacon_on = qla2x00_beacon_on,
1384 .beacon_off = qla2x00_beacon_off,
1385 .beacon_blink = qla2x00_beacon_blink,
1386 .read_optrom = qla2x00_read_optrom_data,
1387 .write_optrom = qla2x00_write_optrom_data,
1388 .get_flash_version = qla2x00_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001389 .start_scsi = qla2x00_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001390};
1391
1392static struct isp_operations qla24xx_isp_ops = {
1393 .pci_config = qla24xx_pci_config,
1394 .reset_chip = qla24xx_reset_chip,
1395 .chip_diag = qla24xx_chip_diag,
1396 .config_rings = qla24xx_config_rings,
1397 .reset_adapter = qla24xx_reset_adapter,
1398 .nvram_config = qla24xx_nvram_config,
1399 .update_fw_options = qla24xx_update_fw_options,
1400 .load_risc = qla24xx_load_risc,
1401 .pci_info_str = qla24xx_pci_info_str,
1402 .fw_version_str = qla24xx_fw_version_str,
1403 .intr_handler = qla24xx_intr_handler,
1404 .enable_intrs = qla24xx_enable_intrs,
1405 .disable_intrs = qla24xx_disable_intrs,
1406 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001407 .target_reset = qla24xx_abort_target,
1408 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001409 .fabric_login = qla24xx_login_fabric,
1410 .fabric_logout = qla24xx_fabric_logout,
1411 .calc_req_entries = NULL,
1412 .build_iocbs = NULL,
1413 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1414 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1415 .read_nvram = qla24xx_read_nvram_data,
1416 .write_nvram = qla24xx_write_nvram_data,
1417 .fw_dump = qla24xx_fw_dump,
1418 .beacon_on = qla24xx_beacon_on,
1419 .beacon_off = qla24xx_beacon_off,
1420 .beacon_blink = qla24xx_beacon_blink,
1421 .read_optrom = qla24xx_read_optrom_data,
1422 .write_optrom = qla24xx_write_optrom_data,
1423 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001424 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001425};
1426
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001427static struct isp_operations qla25xx_isp_ops = {
1428 .pci_config = qla25xx_pci_config,
1429 .reset_chip = qla24xx_reset_chip,
1430 .chip_diag = qla24xx_chip_diag,
1431 .config_rings = qla24xx_config_rings,
1432 .reset_adapter = qla24xx_reset_adapter,
1433 .nvram_config = qla24xx_nvram_config,
1434 .update_fw_options = qla24xx_update_fw_options,
1435 .load_risc = qla24xx_load_risc,
1436 .pci_info_str = qla24xx_pci_info_str,
1437 .fw_version_str = qla24xx_fw_version_str,
1438 .intr_handler = qla24xx_intr_handler,
1439 .enable_intrs = qla24xx_enable_intrs,
1440 .disable_intrs = qla24xx_disable_intrs,
1441 .abort_command = qla24xx_abort_command,
Andrew Vasquez523ec772008-04-03 13:13:24 -07001442 .target_reset = qla24xx_abort_target,
1443 .lun_reset = qla24xx_lun_reset,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001444 .fabric_login = qla24xx_login_fabric,
1445 .fabric_logout = qla24xx_fabric_logout,
1446 .calc_req_entries = NULL,
1447 .build_iocbs = NULL,
1448 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1449 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
1450 .read_nvram = qla25xx_read_nvram_data,
1451 .write_nvram = qla25xx_write_nvram_data,
1452 .fw_dump = qla25xx_fw_dump,
1453 .beacon_on = qla24xx_beacon_on,
1454 .beacon_off = qla24xx_beacon_off,
1455 .beacon_blink = qla24xx_beacon_blink,
Andrew Vasquez338c9162007-09-20 14:07:33 -07001456 .read_optrom = qla25xx_read_optrom_data,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001457 .write_optrom = qla24xx_write_optrom_data,
1458 .get_flash_version = qla24xx_get_flash_version,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001459 .start_scsi = qla24xx_start_scsi,
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001460};
1461
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001462static struct isp_operations qla81xx_isp_ops = {
1463 .pci_config = qla25xx_pci_config,
1464 .reset_chip = qla24xx_reset_chip,
1465 .chip_diag = qla24xx_chip_diag,
1466 .config_rings = qla24xx_config_rings,
1467 .reset_adapter = qla24xx_reset_adapter,
1468 .nvram_config = qla81xx_nvram_config,
1469 .update_fw_options = qla81xx_update_fw_options,
Andrew Vasquezeaac30b2009-01-22 09:45:32 -08001470 .load_risc = qla81xx_load_risc,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001471 .pci_info_str = qla24xx_pci_info_str,
1472 .fw_version_str = qla24xx_fw_version_str,
1473 .intr_handler = qla24xx_intr_handler,
1474 .enable_intrs = qla24xx_enable_intrs,
1475 .disable_intrs = qla24xx_disable_intrs,
1476 .abort_command = qla24xx_abort_command,
1477 .target_reset = qla24xx_abort_target,
1478 .lun_reset = qla24xx_lun_reset,
1479 .fabric_login = qla24xx_login_fabric,
1480 .fabric_logout = qla24xx_fabric_logout,
1481 .calc_req_entries = NULL,
1482 .build_iocbs = NULL,
1483 .prep_ms_iocb = qla24xx_prep_ms_iocb,
1484 .prep_ms_fdmi_iocb = qla24xx_prep_ms_fdmi_iocb,
Andrew Vasquez3d79038f2009-03-24 09:08:14 -07001485 .read_nvram = NULL,
1486 .write_nvram = NULL,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001487 .fw_dump = qla81xx_fw_dump,
1488 .beacon_on = qla24xx_beacon_on,
1489 .beacon_off = qla24xx_beacon_off,
1490 .beacon_blink = qla24xx_beacon_blink,
1491 .read_optrom = qla25xx_read_optrom_data,
1492 .write_optrom = qla24xx_write_optrom_data,
1493 .get_flash_version = qla24xx_get_flash_version,
1494 .start_scsi = qla24xx_start_scsi,
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001495};
1496
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001497static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001498qla2x00_set_isp_flags(struct qla_hw_data *ha)
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001499{
1500 ha->device_type = DT_EXTENDED_IDS;
1501 switch (ha->pdev->device) {
1502 case PCI_DEVICE_ID_QLOGIC_ISP2100:
1503 ha->device_type |= DT_ISP2100;
1504 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001505 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001506 break;
1507 case PCI_DEVICE_ID_QLOGIC_ISP2200:
1508 ha->device_type |= DT_ISP2200;
1509 ha->device_type &= ~DT_EXTENDED_IDS;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001510 ha->fw_srisc_address = RISC_START_ADDRESS_2100;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001511 break;
1512 case PCI_DEVICE_ID_QLOGIC_ISP2300:
1513 ha->device_type |= DT_ISP2300;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001514 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001515 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001516 break;
1517 case PCI_DEVICE_ID_QLOGIC_ISP2312:
1518 ha->device_type |= DT_ISP2312;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001519 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001520 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001521 break;
1522 case PCI_DEVICE_ID_QLOGIC_ISP2322:
1523 ha->device_type |= DT_ISP2322;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001524 ha->device_type |= DT_ZIO_SUPPORTED;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001525 if (ha->pdev->subsystem_vendor == 0x1028 &&
1526 ha->pdev->subsystem_device == 0x0170)
1527 ha->device_type |= DT_OEM_001;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001528 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001529 break;
1530 case PCI_DEVICE_ID_QLOGIC_ISP6312:
1531 ha->device_type |= DT_ISP6312;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001532 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001533 break;
1534 case PCI_DEVICE_ID_QLOGIC_ISP6322:
1535 ha->device_type |= DT_ISP6322;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001536 ha->fw_srisc_address = RISC_START_ADDRESS_2300;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001537 break;
1538 case PCI_DEVICE_ID_QLOGIC_ISP2422:
1539 ha->device_type |= DT_ISP2422;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001540 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001541 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001542 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001543 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001544 break;
1545 case PCI_DEVICE_ID_QLOGIC_ISP2432:
1546 ha->device_type |= DT_ISP2432;
andrew.vasquez@qlogic.com4a59f712006-03-09 14:27:39 -08001547 ha->device_type |= DT_ZIO_SUPPORTED;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001548 ha->device_type |= DT_FWI2;
Andrew Vasquezc76f2c02007-07-19 15:05:57 -07001549 ha->device_type |= DT_IIDMA;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001550 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001551 break;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001552 case PCI_DEVICE_ID_QLOGIC_ISP8432:
1553 ha->device_type |= DT_ISP8432;
1554 ha->device_type |= DT_ZIO_SUPPORTED;
1555 ha->device_type |= DT_FWI2;
1556 ha->device_type |= DT_IIDMA;
1557 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1558 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001559 case PCI_DEVICE_ID_QLOGIC_ISP5422:
1560 ha->device_type |= DT_ISP5422;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001561 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001562 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001563 break;
andrew.vasquez@qlogic.com044cc6c2006-03-09 14:27:13 -08001564 case PCI_DEVICE_ID_QLOGIC_ISP5432:
1565 ha->device_type |= DT_ISP5432;
Andrew Vasqueze4289242007-07-19 15:05:56 -07001566 ha->device_type |= DT_FWI2;
Andrew Vasquez441d1072006-05-17 15:09:34 -07001567 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001568 break;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001569 case PCI_DEVICE_ID_QLOGIC_ISP2532:
1570 ha->device_type |= DT_ISP2532;
1571 ha->device_type |= DT_ZIO_SUPPORTED;
1572 ha->device_type |= DT_FWI2;
1573 ha->device_type |= DT_IIDMA;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001574 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1575 break;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001576 case PCI_DEVICE_ID_QLOGIC_ISP8001:
1577 ha->device_type |= DT_ISP8001;
1578 ha->device_type |= DT_ZIO_SUPPORTED;
1579 ha->device_type |= DT_FWI2;
1580 ha->device_type |= DT_IIDMA;
1581 ha->fw_srisc_address = RISC_START_ADDRESS_2400;
1582 break;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001583 }
Anirban Chakrabortye5b68a62009-04-06 22:33:50 -07001584
1585 /* Get adapter physical port no from interrupt pin register. */
1586 pci_read_config_byte(ha->pdev, PCI_INTERRUPT_PIN, &ha->port_no);
1587 if (ha->port_no & 1)
1588 ha->flags.port0 = 1;
1589 else
1590 ha->flags.port0 = 0;
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001591}
1592
Linus Torvalds1da177e2005-04-16 15:20:36 -07001593static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001594qla2x00_iospace_config(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001595{
Andrew Vasquez37765412008-01-17 09:02:09 -08001596 resource_size_t pio;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001597 uint16_t msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001598 int cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001599
Andrew Vasquez285d0322007-10-19 15:59:17 -07001600 if (pci_request_selected_regions(ha->pdev, ha->bars,
1601 QLA2XXX_DRIVER_NAME)) {
1602 qla_printk(KERN_WARNING, ha,
1603 "Failed to reserve PIO/MMIO regions (%s)\n",
1604 pci_name(ha->pdev));
1605
1606 goto iospace_error_exit;
1607 }
1608 if (!(ha->bars & 1))
1609 goto skip_pio;
1610
Linus Torvalds1da177e2005-04-16 15:20:36 -07001611 /* We only need PIO for Flash operations on ISP2312 v2 chips. */
1612 pio = pci_resource_start(ha->pdev, 0);
Andrew Vasquez37765412008-01-17 09:02:09 -08001613 if (pci_resource_flags(ha->pdev, 0) & IORESOURCE_IO) {
1614 if (pci_resource_len(ha->pdev, 0) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001615 qla_printk(KERN_WARNING, ha,
1616 "Invalid PCI I/O region size (%s)...\n",
1617 pci_name(ha->pdev));
1618 pio = 0;
1619 }
1620 } else {
1621 qla_printk(KERN_WARNING, ha,
1622 "region #0 not a PIO resource (%s)...\n",
1623 pci_name(ha->pdev));
1624 pio = 0;
1625 }
Andrew Vasquez285d0322007-10-19 15:59:17 -07001626 ha->pio_address = pio;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001627
Andrew Vasquez285d0322007-10-19 15:59:17 -07001628skip_pio:
Linus Torvalds1da177e2005-04-16 15:20:36 -07001629 /* Use MMIO operations for all accesses. */
Andrew Vasquez37765412008-01-17 09:02:09 -08001630 if (!(pci_resource_flags(ha->pdev, 1) & IORESOURCE_MEM)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001631 qla_printk(KERN_ERR, ha,
Andrew Vasquez37765412008-01-17 09:02:09 -08001632 "region #1 not an MMIO resource (%s), aborting\n",
Linus Torvalds1da177e2005-04-16 15:20:36 -07001633 pci_name(ha->pdev));
1634 goto iospace_error_exit;
1635 }
Andrew Vasquez37765412008-01-17 09:02:09 -08001636 if (pci_resource_len(ha->pdev, 1) < MIN_IOBASE_LEN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001637 qla_printk(KERN_ERR, ha,
1638 "Invalid PCI mem region size (%s), aborting\n",
1639 pci_name(ha->pdev));
1640 goto iospace_error_exit;
1641 }
1642
Andrew Vasquez37765412008-01-17 09:02:09 -08001643 ha->iobase = ioremap(pci_resource_start(ha->pdev, 1), MIN_IOBASE_LEN);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001644 if (!ha->iobase) {
1645 qla_printk(KERN_ERR, ha,
1646 "cannot remap MMIO (%s), aborting\n", pci_name(ha->pdev));
1647
1648 goto iospace_error_exit;
1649 }
1650
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001651 /* Determine queue resources */
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001652 ha->max_req_queues = ha->max_rsp_queues = 1;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001653 if ((ql2xmaxqueues <= 1 || ql2xmultique_tag < 1) &&
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001654 (!IS_QLA25XX(ha) && !IS_QLA81XX(ha)))
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001655 goto mqiobase_exit;
1656 ha->mqiobase = ioremap(pci_resource_start(ha->pdev, 3),
1657 pci_resource_len(ha->pdev, 3));
1658 if (ha->mqiobase) {
1659 /* Read MSIX vector size of the board */
1660 pci_read_config_word(ha->pdev, QLA_PCI_MSIX_CONTROL, &msix);
1661 ha->msix_count = msix;
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001662 /* Max queues are bounded by available msix vectors */
1663 /* queue 0 uses two msix vectors */
1664 if (ql2xmultique_tag) {
1665 cpus = num_online_cpus();
1666 ha->max_rsp_queues = (ha->msix_count - 1 - cpus) ?
1667 (cpus + 1) : (ha->msix_count - 1);
1668 ha->max_req_queues = 2;
1669 } else if (ql2xmaxqueues > 1) {
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001670 ha->max_req_queues = ql2xmaxqueues > QLA_MQ_SIZE ?
1671 QLA_MQ_SIZE : ql2xmaxqueues;
1672 DEBUG2(qla_printk(KERN_INFO, ha, "QoS mode set, max no"
1673 " of request queues:%d\n", ha->max_req_queues));
1674 }
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001675 qla_printk(KERN_INFO, ha,
1676 "MSI-X vector count: %d\n", msix);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001677 } else
1678 qla_printk(KERN_INFO, ha, "BAR 3 not enabled\n");
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001679
1680mqiobase_exit:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001681 ha->msix_count = ha->max_rsp_queues + 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001682 return (0);
1683
1684iospace_error_exit:
1685 return (-ENOMEM);
1686}
1687
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001688static void
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001689qla2xxx_scan_start(struct Scsi_Host *shost)
1690{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001691 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001692
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001693 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1694 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1695 set_bit(RSCN_UPDATE, &vha->dpc_flags);
1696 set_bit(NPIV_CONFIG_NEEDED, &vha->dpc_flags);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001697}
1698
1699static int
1700qla2xxx_scan_finished(struct Scsi_Host *shost, unsigned long time)
1701{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001702 scsi_qla_host_t *vha = shost_priv(shost);
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001703
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001704 if (!vha->host)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001705 return 1;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001706 if (time > vha->hw->loop_reset_delay * HZ)
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001707 return 1;
1708
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001709 return atomic_read(&vha->loop_state) == LOOP_READY;
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001710}
1711
Linus Torvalds1da177e2005-04-16 15:20:36 -07001712/*
1713 * PCI driver interface
1714 */
Andrew Vasquez7ee61392006-06-23 16:11:22 -07001715static int __devinit
1716qla2x00_probe_one(struct pci_dev *pdev, const struct pci_device_id *id)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001717{
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001718 int ret = -ENODEV;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001719 struct Scsi_Host *host;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001720 scsi_qla_host_t *base_vha = NULL;
1721 struct qla_hw_data *ha;
Andrew Vasquez29856e22007-08-12 18:22:52 -07001722 char pci_info[30];
Linus Torvalds1da177e2005-04-16 15:20:36 -07001723 char fw_str[30];
Andrew Vasquez54333832005-11-09 15:49:04 -08001724 struct scsi_host_template *sht;
Anirban Chakrabortyc51da4e2008-11-10 15:53:20 -08001725 int bars, max_id, mem_only = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001726 uint16_t req_length = 0, rsp_length = 0;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001727 struct req_que *req = NULL;
1728 struct rsp_que *rsp = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001729
Andrew Vasquez285d0322007-10-19 15:59:17 -07001730 bars = pci_select_bars(pdev, IORESOURCE_MEM | IORESOURCE_IO);
Giridhar Malavalia5326f82009-03-24 09:07:56 -07001731 sht = &qla2xxx_driver_template;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001732 if (pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2422 ||
1733 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2432 ||
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001734 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8432 ||
Andrew Vasquez285d0322007-10-19 15:59:17 -07001735 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5422 ||
1736 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP5432 ||
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001737 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP2532 ||
1738 pdev->device == PCI_DEVICE_ID_QLOGIC_ISP8001) {
Andrew Vasquez285d0322007-10-19 15:59:17 -07001739 bars = pci_select_bars(pdev, IORESOURCE_MEM);
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001740 mem_only = 1;
Andrew Vasquez285d0322007-10-19 15:59:17 -07001741 }
1742
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001743 if (mem_only) {
1744 if (pci_enable_device_mem(pdev))
1745 goto probe_out;
1746 } else {
1747 if (pci_enable_device(pdev))
1748 goto probe_out;
1749 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001750
Jesse Barnes09276782008-10-18 17:33:19 -07001751 /* This may fail but that's ok */
1752 pci_enable_pcie_error_reporting(pdev);
Seokmann Ju14e660e2007-09-20 14:07:36 -07001753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001754 ha = kzalloc(sizeof(struct qla_hw_data), GFP_KERNEL);
1755 if (!ha) {
1756 DEBUG(printk("Unable to allocate memory for ha\n"));
1757 goto probe_out;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001758 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001759 ha->pdev = pdev;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001760
1761 /* Clear our data area */
Andrew Vasquez285d0322007-10-19 15:59:17 -07001762 ha->bars = bars;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11001763 ha->mem_only = mem_only;
Andrew Vasquezdf4bf0b2008-01-31 12:33:46 -08001764 spin_lock_init(&ha->hardware_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001765
andrew.vasquez@qlogic.comea5b6382006-03-09 14:27:08 -08001766 /* Set ISP-type information. */
1767 qla2x00_set_isp_flags(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001768 /* Configure PCI I/O space */
1769 ret = qla2x00_iospace_config(ha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001770 if (ret)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001771 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001772
Linus Torvalds1da177e2005-04-16 15:20:36 -07001773 qla_printk(KERN_INFO, ha,
Andrew Vasquez54333832005-11-09 15:49:04 -08001774 "Found an ISP%04X, irq %d, iobase 0x%p\n", pdev->device, pdev->irq,
1775 ha->iobase);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001776
Linus Torvalds1da177e2005-04-16 15:20:36 -07001777 ha->prev_topology = 0;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001778 ha->init_cb_size = sizeof(init_cb_t);
Andrew Vasquezd8b45212006-10-02 12:00:43 -07001779 ha->link_data_rate = PORT_SPEED_UNKNOWN;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001780 ha->optrom_size = OPTROM_SIZE_2300;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001781
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001782 /* Assign ISP specific operations. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001783 max_id = MAX_TARGETS_2200;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001784 if (IS_QLA2100(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001785 max_id = MAX_TARGETS_2100;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001786 ha->mbx_count = MAILBOX_REGISTER_COUNT_2100;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001787 req_length = REQUEST_ENTRY_CNT_2100;
1788 rsp_length = RESPONSE_ENTRY_CNT_2100;
1789 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001790 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001791 ha->flash_conf_off = ~0;
1792 ha->flash_data_off = ~0;
1793 ha->nvram_conf_off = ~0;
1794 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001795 ha->isp_ops = &qla2100_isp_ops;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001796 } else if (IS_QLA2200(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001797 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001798 req_length = REQUEST_ENTRY_CNT_2200;
1799 rsp_length = RESPONSE_ENTRY_CNT_2100;
1800 ha->max_loop_id = SNS_LAST_LOOP_ID_2100;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001801 ha->gid_list_info_size = 4;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001802 ha->flash_conf_off = ~0;
1803 ha->flash_data_off = ~0;
1804 ha->nvram_conf_off = ~0;
1805 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001806 ha->isp_ops = &qla2100_isp_ops;
Andrew Vasquezfca29702005-07-06 10:31:47 -07001807 } else if (IS_QLA23XX(ha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001808 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001809 req_length = REQUEST_ENTRY_CNT_2200;
1810 rsp_length = RESPONSE_ENTRY_CNT_2300;
1811 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezabbd8872005-07-06 10:30:05 -07001812 ha->gid_list_info_size = 6;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001813 if (IS_QLA2322(ha) || IS_QLA6322(ha))
1814 ha->optrom_size = OPTROM_SIZE_2322;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001815 ha->flash_conf_off = ~0;
1816 ha->flash_data_off = ~0;
1817 ha->nvram_conf_off = ~0;
1818 ha->nvram_data_off = ~0;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001819 ha->isp_ops = &qla2300_isp_ops;
Harihara Kadayam4d4df192008-04-03 13:13:26 -07001820 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquezfca29702005-07-06 10:31:47 -07001821 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001822 req_length = REQUEST_ENTRY_CNT_24XX;
1823 rsp_length = RESPONSE_ENTRY_CNT_2300;
1824 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001825 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezfca29702005-07-06 10:31:47 -07001826 ha->gid_list_info_size = 8;
andrew.vasquez@qlogic.com854165f2006-01-31 16:05:17 -08001827 ha->optrom_size = OPTROM_SIZE_24XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001828 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA24XX;
Andrew Vasquezfd34f552007-07-19 15:06:00 -07001829 ha->isp_ops = &qla24xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001830 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1831 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1832 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1833 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001834 } else if (IS_QLA25XX(ha)) {
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001835 ha->mbx_count = MAILBOX_REGISTER_COUNT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001836 req_length = REQUEST_ENTRY_CNT_24XX;
1837 rsp_length = RESPONSE_ENTRY_CNT_2300;
1838 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001839 ha->init_cb_size = sizeof(struct mid_init_cb_24xx);
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001840 ha->gid_list_info_size = 8;
1841 ha->optrom_size = OPTROM_SIZE_25XX;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001842 ha->nvram_npiv_size = QLA_MAX_VPORTS_QLA25XX;
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07001843 ha->isp_ops = &qla25xx_isp_ops;
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08001844 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF;
1845 ha->flash_data_off = FARX_ACCESS_FLASH_DATA;
1846 ha->nvram_conf_off = FARX_ACCESS_NVRAM_CONF;
1847 ha->nvram_data_off = FARX_ACCESS_NVRAM_DATA;
1848 } else if (IS_QLA81XX(ha)) {
1849 ha->mbx_count = MAILBOX_REGISTER_COUNT;
1850 req_length = REQUEST_ENTRY_CNT_24XX;
1851 rsp_length = RESPONSE_ENTRY_CNT_2300;
1852 ha->max_loop_id = SNS_LAST_LOOP_ID_2300;
1853 ha->init_cb_size = sizeof(struct mid_init_cb_81xx);
1854 ha->gid_list_info_size = 8;
1855 ha->optrom_size = OPTROM_SIZE_81XX;
1856 ha->isp_ops = &qla81xx_isp_ops;
1857 ha->flash_conf_off = FARX_ACCESS_FLASH_CONF_81XX;
1858 ha->flash_data_off = FARX_ACCESS_FLASH_DATA_81XX;
1859 ha->nvram_conf_off = ~0;
1860 ha->nvram_data_off = ~0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001861 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07001862
matthias@kaehlcke.net6c2f5272008-05-12 22:21:11 -07001863 mutex_init(&ha->vport_lock);
Marcus Barrow0b05a1f2008-01-17 09:02:13 -08001864 init_completion(&ha->mbx_cmd_comp);
1865 complete(&ha->mbx_cmd_comp);
1866 init_completion(&ha->mbx_intr_comp);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001867
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07001868 set_bit(0, (unsigned long *) ha->vp_idx_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001869
Andrew Vasquez53303c42009-01-22 09:45:37 -08001870 qla2x00_config_dma_addressing(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001871 ret = qla2x00_mem_alloc(ha, req_length, rsp_length, &req, &rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001872 if (!ret) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001873 qla_printk(KERN_WARNING, ha,
1874 "[ERROR] Failed to allocate memory for adapter\n");
1875
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001876 goto probe_hw_failed;
1877 }
1878
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001879 req->max_q_depth = MAX_Q_DEPTH;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001880 if (ql2xmaxqdepth != 0 && ql2xmaxqdepth <= 0xffffU)
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001881 req->max_q_depth = ql2xmaxqdepth;
1882
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001883
1884 base_vha = qla2x00_create_host(sht, ha);
1885 if (!base_vha) {
1886 qla_printk(KERN_WARNING, ha,
1887 "[ERROR] Failed to allocate memory for scsi_host\n");
1888
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001889 ret = -ENOMEM;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001890 qla2x00_mem_free(ha);
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001891 qla2x00_free_req_que(ha, req);
1892 qla2x00_free_rsp_que(ha, rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001893 goto probe_hw_failed;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001894 }
1895
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001896 pci_set_drvdata(pdev, base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001897
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001898 host = base_vha->host;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001899 base_vha->req = req;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001900 host->can_queue = req->length + 128;
1901 if (IS_QLA2XXX_MIDTYPE(ha))
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001902 base_vha->mgmt_svr_loop_id = 10 + base_vha->vp_idx;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001903 else
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001904 base_vha->mgmt_svr_loop_id = MANAGEMENT_SERVER +
1905 base_vha->vp_idx;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001906 if (IS_QLA2100(ha))
1907 host->sg_tablesize = 32;
1908 host->max_id = max_id;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001909 host->this_id = 255;
1910 host->cmd_per_lun = 3;
Seokmann Ju711c1d92008-07-10 16:55:51 -07001911 host->unique_id = host->host_no;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001912 host->max_cmd_len = MAX_CMDSZ;
Andrew Vasquez75bc4192006-05-17 15:09:22 -07001913 host->max_channel = MAX_BUSES - 1;
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001914 host->max_lun = MAX_LUNS;
1915 host->transportt = qla2xxx_transport_template;
1916
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001917 /* Set up the irqs */
1918 ret = qla2x00_request_irqs(ha, rsp);
1919 if (ret)
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001920 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001921 /* Alloc arrays of request and response ring ptrs */
1922 if (!qla2x00_alloc_queues(ha)) {
1923 qla_printk(KERN_WARNING, ha,
1924 "[ERROR] Failed to allocate memory for queue"
1925 " pointers\n");
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08001926 goto probe_init_failed;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08001927 }
1928 ha->rsp_q_map[0] = rsp;
1929 ha->req_q_map[0] = req;
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07001930 rsp->req = req;
1931 req->rsp = rsp;
1932 set_bit(0, ha->req_qid_map);
1933 set_bit(0, ha->rsp_qid_map);
Andrew Vasquez08029992009-03-24 09:07:55 -07001934 /* FWI2-capable only. */
1935 req->req_q_in = &ha->iobase->isp24.req_q_in;
1936 req->req_q_out = &ha->iobase->isp24.req_q_out;
1937 rsp->rsp_q_in = &ha->iobase->isp24.rsp_q_in;
1938 rsp->rsp_q_out = &ha->iobase->isp24.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001939 if (ha->mqenable) {
Andrew Vasquez08029992009-03-24 09:07:55 -07001940 req->req_q_in = &ha->mqiobase->isp25mq.req_q_in;
1941 req->req_q_out = &ha->mqiobase->isp25mq.req_q_out;
1942 rsp->rsp_q_in = &ha->mqiobase->isp25mq.rsp_q_in;
1943 rsp->rsp_q_out = &ha->mqiobase->isp25mq.rsp_q_out;
Anirban Chakraborty17d98632008-12-18 10:06:15 -08001944 }
1945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001946 if (qla2x00_initialize_adapter(base_vha)) {
1947 qla_printk(KERN_WARNING, ha,
1948 "Failed to initialize adapter\n");
1949
1950 DEBUG2(printk("scsi(%ld): Failed to initialize adapter - "
1951 "Adapter flags %x.\n",
1952 base_vha->host_no, base_vha->device_flags));
1953
1954 ret = -ENODEV;
1955 goto probe_failed;
1956 }
1957
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07001958 if (ha->mqenable)
1959 if (qla25xx_setup_mode(base_vha))
1960 qla_printk(KERN_WARNING, ha,
1961 "Can't create queues, falling back to single"
1962 " queue mode\n");
1963
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001964 /*
1965 * Startup the kernel thread for this host adapter
1966 */
1967 ha->dpc_thread = kthread_create(qla2x00_do_dpc, ha,
1968 "%s_dpc", base_vha->host_str);
1969 if (IS_ERR(ha->dpc_thread)) {
1970 qla_printk(KERN_WARNING, ha,
1971 "Unable to start DPC thread!\n");
1972 ret = PTR_ERR(ha->dpc_thread);
1973 goto probe_failed;
1974 }
1975
1976 list_add_tail(&base_vha->list, &ha->vp_list);
1977 base_vha->host->irq = ha->pdev->irq;
1978
Linus Torvalds1da177e2005-04-16 15:20:36 -07001979 /* Initialized the timer */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001980 qla2x00_start_timer(base_vha, qla2x00_timer, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001981
1982 DEBUG2(printk("DEBUG: detect hba %ld at address = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001983 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07001984
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001985 base_vha->flags.init_done = 1;
1986 base_vha->flags.online = 1;
Andrew Vasquezd19044c2006-11-22 08:22:19 -08001987
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001988 ret = scsi_add_host(host, &pdev->dev);
1989 if (ret)
1990 goto probe_failed;
1991
Andrew Vasquez048feec2008-09-11 22:19:45 -07001992 ha->isp_ops->enable_intrs(ha);
1993
Andrew Vasquez1e99e332006-11-22 08:24:48 -08001994 scsi_scan_host(host);
1995
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001996 qla2x00_alloc_sysfs_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001997
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08001998 qla2x00_init_host_attr(base_vha);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07001999
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002000 qla2x00_dfs_setup(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002001
Linus Torvalds1da177e2005-04-16 15:20:36 -07002002 qla_printk(KERN_INFO, ha, "\n"
2003 " QLogic Fibre Channel HBA Driver: %s\n"
2004 " QLogic %s - %s\n"
Andrew Vasquez54333832005-11-09 15:49:04 -08002005 " ISP%04X: %s @ %s hdma%c, host#=%ld, fw=%s\n",
2006 qla2x00_version_str, ha->model_number,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002007 ha->model_desc ? ha->model_desc : "", pdev->device,
2008 ha->isp_ops->pci_info_str(base_vha, pci_info), pci_name(pdev),
2009 ha->flags.enable_64bit_addressing ? '+' : '-', base_vha->host_no,
2010 ha->isp_ops->fw_version_str(base_vha, fw_str));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002011
Linus Torvalds1da177e2005-04-16 15:20:36 -07002012 return 0;
2013
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002014probe_init_failed:
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002015 qla2x00_free_req_que(ha, req);
2016 qla2x00_free_rsp_que(ha, rsp);
2017 ha->max_req_queues = ha->max_rsp_queues = 0;
Anirban Chakraborty6e9f21f2009-01-22 09:45:28 -08002018
Linus Torvalds1da177e2005-04-16 15:20:36 -07002019probe_failed:
Andrew Vasquezb9978762009-03-24 09:08:05 -07002020 if (base_vha->timer_active)
2021 qla2x00_stop_timer(base_vha);
2022 base_vha->flags.online = 0;
2023 if (ha->dpc_thread) {
2024 struct task_struct *t = ha->dpc_thread;
2025
2026 ha->dpc_thread = NULL;
2027 kthread_stop(t);
2028 }
2029
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002030 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002031
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002032 scsi_host_put(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002033
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002034probe_hw_failed:
2035 if (ha->iobase)
2036 iounmap(ha->iobase);
2037
2038 pci_release_selected_regions(ha->pdev, ha->bars);
2039 kfree(ha);
2040 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002041
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002042probe_out:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002043 pci_disable_device(pdev);
Andrew Vasqueza1541d52005-06-09 17:21:28 -07002044 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002045}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002046
Adrian Bunk4c993f72008-01-14 00:55:16 -08002047static void
Andrew Vasquez7ee61392006-06-23 16:11:22 -07002048qla2x00_remove_one(struct pci_dev *pdev)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002049{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002050 scsi_qla_host_t *base_vha, *vha, *temp;
2051 struct qla_hw_data *ha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002052
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002053 base_vha = pci_get_drvdata(pdev);
2054 ha = base_vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002055
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002056 list_for_each_entry_safe(vha, temp, &ha->vp_list, list) {
2057 if (vha && vha->fc_vport)
2058 fc_vport_terminate(vha->fc_vport);
2059 }
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002060
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002061 set_bit(UNLOADING, &base_vha->dpc_flags);
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002062
Andrew Vasquezb9978762009-03-24 09:08:05 -07002063 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
2064
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002065 qla2x00_dfs_remove(base_vha);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002066
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002067 qla84xx_put_chip(base_vha);
Harihara Kadayam4d4df192008-04-03 13:13:26 -07002068
Andrew Vasquezb9978762009-03-24 09:08:05 -07002069 /* Disable timer */
2070 if (base_vha->timer_active)
2071 qla2x00_stop_timer(base_vha);
2072
2073 base_vha->flags.online = 0;
2074
Anirban Chakraborty68ca9492009-04-06 22:33:41 -07002075 /* Flush the work queue and remove it */
2076 if (ha->wq) {
2077 flush_workqueue(ha->wq);
2078 destroy_workqueue(ha->wq);
2079 ha->wq = NULL;
2080 }
2081
Andrew Vasquezb9978762009-03-24 09:08:05 -07002082 /* Kill the kernel thread for this host */
2083 if (ha->dpc_thread) {
2084 struct task_struct *t = ha->dpc_thread;
2085
2086 /*
2087 * qla2xxx_wake_dpc checks for ->dpc_thread
2088 * so we need to zero it out.
2089 */
2090 ha->dpc_thread = NULL;
2091 kthread_stop(t);
2092 }
2093
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002094 qla2x00_free_sysfs_attr(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002095
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002096 fc_remove_host(base_vha->host);
bdf79622005-04-17 15:06:53 -05002097
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002098 scsi_remove_host(base_vha->host);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002099
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002100 qla2x00_free_device(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002101
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002102 scsi_host_put(base_vha->host);
2103
2104 if (ha->iobase)
2105 iounmap(ha->iobase);
2106
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002107 if (ha->mqiobase)
2108 iounmap(ha->mqiobase);
2109
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002110 pci_release_selected_regions(ha->pdev, ha->bars);
2111 kfree(ha);
2112 ha = NULL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002113
Bernhard Walle665db932007-03-28 00:49:49 +02002114 pci_disable_device(pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002115 pci_set_drvdata(pdev, NULL);
2116}
Linus Torvalds1da177e2005-04-16 15:20:36 -07002117
2118static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002119qla2x00_free_device(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002120{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002121 struct qla_hw_data *ha = vha->hw;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002122
Anirban Chakraborty2afa19a2009-04-06 22:33:40 -07002123 qla25xx_delete_queues(vha);
2124
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002125 if (ha->flags.fce_enabled)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002126 qla2x00_disable_fce_trace(vha, NULL, NULL);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002127
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002128 if (ha->eft)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002129 qla2x00_disable_eft_trace(vha);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002130
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002131 /* Stop currently executing firmware. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002132 qla2x00_try_to_stop_firmware(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002133
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002134 /* turn-off interrupts on the card */
2135 if (ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002136 ha->isp_ops->disable_intrs(ha);
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002137
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002138 qla2x00_free_irqs(vha);
2139
Andrew Vasquezf6ef3b12005-08-26 19:10:20 -07002140 qla2x00_mem_free(ha);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002141
2142 qla2x00_free_queues(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002143}
2144
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002145static inline void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002146qla2x00_schedule_rport_del(struct scsi_qla_host *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002147 int defer)
2148{
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002149 struct fc_rport *rport;
2150
2151 if (!fcport->rport)
2152 return;
2153
2154 rport = fcport->rport;
2155 if (defer) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002156 spin_lock_irq(vha->host->host_lock);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002157 fcport->drport = rport;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002158 spin_unlock_irq(vha->host->host_lock);
2159 set_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags);
2160 qla2xxx_wake_dpc(vha);
Seokmann Ju5f3a9a22008-07-10 16:55:47 -07002161 } else
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002162 fc_remote_port_delete(rport);
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002163}
2164
Linus Torvalds1da177e2005-04-16 15:20:36 -07002165/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002166 * qla2x00_mark_device_lost Updates fcport state when device goes offline.
2167 *
2168 * Input: ha = adapter block pointer. fcport = port structure pointer.
2169 *
2170 * Return: None.
2171 *
2172 * Context:
2173 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002174void qla2x00_mark_device_lost(scsi_qla_host_t *vha, fc_port_t *fcport,
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002175 int do_login, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002176{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002177 if (atomic_read(&fcport->state) == FCS_ONLINE &&
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002178 vha->vp_idx == fcport->vp_idx) {
2179 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2180 qla2x00_schedule_rport_del(vha, fcport, defer);
2181 }
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002182 /*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002183 * We may need to retry the login, so don't change the state of the
2184 * port but do the retries.
2185 */
2186 if (atomic_read(&fcport->state) != FCS_DEVICE_DEAD)
2187 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2188
2189 if (!do_login)
2190 return;
2191
2192 if (fcport->login_retry == 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002193 fcport->login_retry = vha->hw->login_retry_count;
2194 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002195
2196 DEBUG(printk("scsi(%ld): Port login retry: "
2197 "%02x%02x%02x%02x%02x%02x%02x%02x, "
2198 "id = 0x%04x retry cnt=%d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002199 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002200 fcport->port_name[0],
2201 fcport->port_name[1],
2202 fcport->port_name[2],
2203 fcport->port_name[3],
2204 fcport->port_name[4],
2205 fcport->port_name[5],
2206 fcport->port_name[6],
2207 fcport->port_name[7],
2208 fcport->loop_id,
2209 fcport->login_retry));
2210 }
2211}
2212
2213/*
2214 * qla2x00_mark_all_devices_lost
2215 * Updates fcport state when device goes offline.
2216 *
2217 * Input:
2218 * ha = adapter block pointer.
2219 * fcport = port structure pointer.
2220 *
2221 * Return:
2222 * None.
2223 *
2224 * Context:
2225 */
2226void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002227qla2x00_mark_all_devices_lost(scsi_qla_host_t *vha, int defer)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002228{
2229 fc_port_t *fcport;
2230
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002231 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2232 if (vha->vp_idx != fcport->vp_idx)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002233 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002234 /*
2235 * No point in marking the device as lost, if the device is
2236 * already DEAD.
2237 */
2238 if (atomic_read(&fcport->state) == FCS_DEVICE_DEAD)
2239 continue;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002240 if (atomic_read(&fcport->state) == FCS_ONLINE) {
2241 atomic_set(&fcport->state, FCS_DEVICE_LOST);
2242 qla2x00_schedule_rport_del(vha, fcport, defer);
2243 } else
2244 atomic_set(&fcport->state, FCS_DEVICE_LOST);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002245 }
2246}
2247
2248/*
2249* qla2x00_mem_alloc
2250* Allocates adapter memory.
2251*
2252* Returns:
2253* 0 = success.
Andrew Vasqueze8711082008-01-31 12:33:48 -08002254* !0 = failure.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002255*/
Andrew Vasqueze8711082008-01-31 12:33:48 -08002256static int
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002257qla2x00_mem_alloc(struct qla_hw_data *ha, uint16_t req_len, uint16_t rsp_len,
2258 struct req_que **req, struct rsp_que **rsp)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002259{
2260 char name[16];
Linus Torvalds1da177e2005-04-16 15:20:36 -07002261
Andrew Vasqueze8711082008-01-31 12:33:48 -08002262 ha->init_cb = dma_alloc_coherent(&ha->pdev->dev, ha->init_cb_size,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002263 &ha->init_cb_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002264 if (!ha->init_cb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002265 goto fail;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002266
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002267 ha->gid_list = dma_alloc_coherent(&ha->pdev->dev, GID_LIST_SIZE,
2268 &ha->gid_list_dma, GFP_KERNEL);
2269 if (!ha->gid_list)
Andrew Vasqueze8711082008-01-31 12:33:48 -08002270 goto fail_free_init_cb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002271
Andrew Vasqueze8711082008-01-31 12:33:48 -08002272 ha->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
2273 if (!ha->srb_mempool)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002274 goto fail_free_gid_list;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002275
Andrew Vasqueze8711082008-01-31 12:33:48 -08002276 /* Get memory for cached NVRAM */
2277 ha->nvram = kzalloc(MAX_NVRAM_SIZE, GFP_KERNEL);
2278 if (!ha->nvram)
2279 goto fail_free_srb_mempool;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002280
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002281 snprintf(name, sizeof(name), "%s_%d", QLA2XXX_DRIVER_NAME,
2282 ha->pdev->device);
2283 ha->s_dma_pool = dma_pool_create(name, &ha->pdev->dev,
2284 DMA_POOL_SIZE, 8, 0);
2285 if (!ha->s_dma_pool)
2286 goto fail_free_nvram;
2287
Andrew Vasqueze8711082008-01-31 12:33:48 -08002288 /* Allocate memory for SNS commands */
2289 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002290 /* Get consistent memory allocated for SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002291 ha->sns_cmd = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002292 sizeof(struct sns_cmd_pkt), &ha->sns_cmd_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002293 if (!ha->sns_cmd)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002294 goto fail_dma_pool;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002295 } else {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002296 /* Get consistent memory allocated for MS IOCB */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002297 ha->ms_iocb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002298 &ha->ms_iocb_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002299 if (!ha->ms_iocb)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002300 goto fail_dma_pool;
2301 /* Get consistent memory allocated for CT SNS commands */
Andrew Vasqueze8711082008-01-31 12:33:48 -08002302 ha->ct_sns = dma_alloc_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002303 sizeof(struct ct_sns_pkt), &ha->ct_sns_dma, GFP_KERNEL);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002304 if (!ha->ct_sns)
2305 goto fail_free_ms_iocb;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002306 }
2307
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002308 /* Allocate memory for request ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002309 *req = kzalloc(sizeof(struct req_que), GFP_KERNEL);
2310 if (!*req) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002311 DEBUG(printk("Unable to allocate memory for req\n"));
2312 goto fail_req;
2313 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002314 (*req)->length = req_len;
2315 (*req)->ring = dma_alloc_coherent(&ha->pdev->dev,
2316 ((*req)->length + 1) * sizeof(request_t),
2317 &(*req)->dma, GFP_KERNEL);
2318 if (!(*req)->ring) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002319 DEBUG(printk("Unable to allocate memory for req_ring\n"));
2320 goto fail_req_ring;
2321 }
2322 /* Allocate memory for response ring */
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002323 *rsp = kzalloc(sizeof(struct rsp_que), GFP_KERNEL);
2324 if (!*rsp) {
2325 qla_printk(KERN_WARNING, ha,
2326 "Unable to allocate memory for rsp\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002327 goto fail_rsp;
2328 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002329 (*rsp)->hw = ha;
2330 (*rsp)->length = rsp_len;
2331 (*rsp)->ring = dma_alloc_coherent(&ha->pdev->dev,
2332 ((*rsp)->length + 1) * sizeof(response_t),
2333 &(*rsp)->dma, GFP_KERNEL);
2334 if (!(*rsp)->ring) {
2335 qla_printk(KERN_WARNING, ha,
2336 "Unable to allocate memory for rsp_ring\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002337 goto fail_rsp_ring;
2338 }
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002339 (*req)->rsp = *rsp;
2340 (*rsp)->req = *req;
2341 /* Allocate memory for NVRAM data for vports */
2342 if (ha->nvram_npiv_size) {
2343 ha->npiv_info = kzalloc(sizeof(struct qla_npiv_entry) *
2344 ha->nvram_npiv_size, GFP_KERNEL);
2345 if (!ha->npiv_info) {
2346 qla_printk(KERN_WARNING, ha,
2347 "Unable to allocate memory for npiv info\n");
2348 goto fail_npiv_info;
2349 }
2350 } else
2351 ha->npiv_info = NULL;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002352
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002353 /* Get consistent memory allocated for EX-INIT-CB. */
2354 if (IS_QLA81XX(ha)) {
2355 ha->ex_init_cb = dma_pool_alloc(ha->s_dma_pool, GFP_KERNEL,
2356 &ha->ex_init_cb_dma);
2357 if (!ha->ex_init_cb)
2358 goto fail_ex_init_cb;
2359 }
2360
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002361 INIT_LIST_HEAD(&ha->vp_list);
2362 return 1;
2363
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002364fail_ex_init_cb:
2365 kfree(ha->npiv_info);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002366fail_npiv_info:
2367 dma_free_coherent(&ha->pdev->dev, ((*rsp)->length + 1) *
2368 sizeof(response_t), (*rsp)->ring, (*rsp)->dma);
2369 (*rsp)->ring = NULL;
2370 (*rsp)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002371fail_rsp_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002372 kfree(*rsp);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002373fail_rsp:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002374 dma_free_coherent(&ha->pdev->dev, ((*req)->length + 1) *
2375 sizeof(request_t), (*req)->ring, (*req)->dma);
2376 (*req)->ring = NULL;
2377 (*req)->dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002378fail_req_ring:
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002379 kfree(*req);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002380fail_req:
2381 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
2382 ha->ct_sns, ha->ct_sns_dma);
2383 ha->ct_sns = NULL;
2384 ha->ct_sns_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002385fail_free_ms_iocb:
2386 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2387 ha->ms_iocb = NULL;
2388 ha->ms_iocb_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002389fail_dma_pool:
2390 dma_pool_destroy(ha->s_dma_pool);
2391 ha->s_dma_pool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002392fail_free_nvram:
2393 kfree(ha->nvram);
2394 ha->nvram = NULL;
2395fail_free_srb_mempool:
2396 mempool_destroy(ha->srb_mempool);
2397 ha->srb_mempool = NULL;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002398fail_free_gid_list:
2399 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002400 ha->gid_list_dma);
Andrew Vasqueze8711082008-01-31 12:33:48 -08002401 ha->gid_list = NULL;
2402 ha->gid_list_dma = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002403fail_free_init_cb:
2404 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size, ha->init_cb,
2405 ha->init_cb_dma);
2406 ha->init_cb = NULL;
2407 ha->init_cb_dma = 0;
Andrew Vasqueze8711082008-01-31 12:33:48 -08002408fail:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002409 DEBUG(printk("%s: Memory allocation failure\n", __func__));
Andrew Vasqueze8711082008-01-31 12:33:48 -08002410 return -ENOMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002411}
2412
2413/*
2414* qla2x00_mem_free
2415* Frees all adapter allocated memory.
2416*
2417* Input:
2418* ha = adapter block pointer.
2419*/
Adrian Bunka824ebb2008-01-17 09:02:15 -08002420static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002421qla2x00_mem_free(struct qla_hw_data *ha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002422{
Andrew Vasqueze8711082008-01-31 12:33:48 -08002423 if (ha->srb_mempool)
2424 mempool_destroy(ha->srb_mempool);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002425
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002426 if (ha->fce)
2427 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, ha->fce,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002428 ha->fce_dma);
Andrew Vasquezdf613b92008-01-17 09:02:17 -08002429
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002430 if (ha->fw_dump) {
2431 if (ha->eft)
2432 dma_free_coherent(&ha->pdev->dev,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002433 ntohl(ha->fw_dump->eft_size), ha->eft, ha->eft_dma);
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002434 vfree(ha->fw_dump);
2435 }
2436
Andrew Vasquezce0423f2009-06-03 09:55:13 -07002437 if (ha->xgmac_data)
2438 dma_free_coherent(&ha->pdev->dev, XGMAC_DATA_SIZE,
2439 ha->xgmac_data, ha->xgmac_data_dma);
2440
Linus Torvalds1da177e2005-04-16 15:20:36 -07002441 if (ha->sns_cmd)
2442 dma_free_coherent(&ha->pdev->dev, sizeof(struct sns_cmd_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002443 ha->sns_cmd, ha->sns_cmd_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002444
2445 if (ha->ct_sns)
2446 dma_free_coherent(&ha->pdev->dev, sizeof(struct ct_sns_pkt),
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002447 ha->ct_sns, ha->ct_sns_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002448
Andrew Vasquez88729e52006-06-23 16:10:50 -07002449 if (ha->sfp_data)
2450 dma_pool_free(ha->s_dma_pool, ha->sfp_data, ha->sfp_data_dma);
2451
Joe Carnuccioad0ecd62009-03-24 09:08:12 -07002452 if (ha->edc_data)
2453 dma_pool_free(ha->s_dma_pool, ha->edc_data, ha->edc_data_dma);
2454
Linus Torvalds1da177e2005-04-16 15:20:36 -07002455 if (ha->ms_iocb)
2456 dma_pool_free(ha->s_dma_pool, ha->ms_iocb, ha->ms_iocb_dma);
2457
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002458 if (ha->ex_init_cb)
2459 dma_pool_free(ha->s_dma_pool, ha->ex_init_cb, ha->ex_init_cb_dma);
2460
Linus Torvalds1da177e2005-04-16 15:20:36 -07002461 if (ha->s_dma_pool)
2462 dma_pool_destroy(ha->s_dma_pool);
2463
Linus Torvalds1da177e2005-04-16 15:20:36 -07002464 if (ha->gid_list)
2465 dma_free_coherent(&ha->pdev->dev, GID_LIST_SIZE, ha->gid_list,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002466 ha->gid_list_dma);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002467
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002468 if (ha->init_cb)
2469 dma_free_coherent(&ha->pdev->dev, ha->init_cb_size,
2470 ha->init_cb, ha->init_cb_dma);
2471 vfree(ha->optrom_buffer);
2472 kfree(ha->nvram);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002473 kfree(ha->npiv_info);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002474
Andrew Vasqueze8711082008-01-31 12:33:48 -08002475 ha->srb_mempool = NULL;
Andrew Vasqueza7a167b2006-06-23 16:10:29 -07002476 ha->eft = NULL;
2477 ha->eft_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002478 ha->sns_cmd = NULL;
2479 ha->sns_cmd_dma = 0;
2480 ha->ct_sns = NULL;
2481 ha->ct_sns_dma = 0;
2482 ha->ms_iocb = NULL;
2483 ha->ms_iocb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002484 ha->init_cb = NULL;
2485 ha->init_cb_dma = 0;
Andrew Vasquezb64b0e82009-03-24 09:08:01 -07002486 ha->ex_init_cb = NULL;
2487 ha->ex_init_cb_dma = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002488
2489 ha->s_dma_pool = NULL;
2490
Linus Torvalds1da177e2005-04-16 15:20:36 -07002491 ha->gid_list = NULL;
2492 ha->gid_list_dma = 0;
2493
Linus Torvalds1da177e2005-04-16 15:20:36 -07002494 ha->fw_dump = NULL;
Andrew Vasquezfca29702005-07-06 10:31:47 -07002495 ha->fw_dumped = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002496 ha->fw_dump_reading = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002497}
2498
2499struct scsi_qla_host *qla2x00_create_host(struct scsi_host_template *sht,
2500 struct qla_hw_data *ha)
2501{
2502 struct Scsi_Host *host;
2503 struct scsi_qla_host *vha = NULL;
2504
2505 host = scsi_host_alloc(sht, sizeof(scsi_qla_host_t));
2506 if (host == NULL) {
2507 printk(KERN_WARNING
2508 "qla2xxx: Couldn't allocate host from scsi layer!\n");
2509 goto fail;
2510 }
2511
2512 /* Clear our data area */
2513 vha = shost_priv(host);
2514 memset(vha, 0, sizeof(scsi_qla_host_t));
2515
2516 vha->host = host;
2517 vha->host_no = host->host_no;
2518 vha->hw = ha;
2519
2520 INIT_LIST_HEAD(&vha->vp_fcports);
2521 INIT_LIST_HEAD(&vha->work_list);
2522 INIT_LIST_HEAD(&vha->list);
2523
2524 sprintf(vha->host_str, "%s_%ld", QLA2XXX_DRIVER_NAME, vha->host_no);
2525 return vha;
2526
2527fail:
2528 return vha;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002529}
2530
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002531static struct qla_work_evt *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002532qla2x00_alloc_work(struct scsi_qla_host *vha, enum qla_work_type type,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002533 int locked)
2534{
2535 struct qla_work_evt *e;
2536
2537 e = kzalloc(sizeof(struct qla_work_evt), locked ? GFP_ATOMIC:
2538 GFP_KERNEL);
2539 if (!e)
2540 return NULL;
2541
2542 INIT_LIST_HEAD(&e->list);
2543 e->type = type;
2544 e->flags = QLA_EVT_FLAG_FREE;
2545 return e;
2546}
2547
Adrian Bunk01ef66b2008-04-24 15:21:27 -07002548static int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002549qla2x00_post_work(struct scsi_qla_host *vha, struct qla_work_evt *e, int locked)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002550{
Andrew Mortonbf6583b2008-07-24 08:31:48 -07002551 unsigned long uninitialized_var(flags);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002552 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002553
2554 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002555 spin_lock_irqsave(&ha->hardware_lock, flags);
2556 list_add_tail(&e->list, &vha->work_list);
2557 qla2xxx_wake_dpc(vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002558 if (!locked)
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002559 spin_unlock_irqrestore(&ha->hardware_lock, flags);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002560 return QLA_SUCCESS;
2561}
2562
2563int
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002564qla2x00_post_aen_work(struct scsi_qla_host *vha, enum fc_host_event_code code,
Andrew Vasquez0971de72008-04-03 13:13:18 -07002565 u32 data)
2566{
2567 struct qla_work_evt *e;
2568
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002569 e = qla2x00_alloc_work(vha, QLA_EVT_AEN, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002570 if (!e)
2571 return QLA_FUNCTION_FAILED;
2572
2573 e->u.aen.code = code;
2574 e->u.aen.data = data;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002575 return qla2x00_post_work(vha, e, 1);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002576}
2577
Andrew Vasquez8a659572009-02-08 20:50:12 -08002578int
2579qla2x00_post_idc_ack_work(struct scsi_qla_host *vha, uint16_t *mb)
2580{
2581 struct qla_work_evt *e;
2582
2583 e = qla2x00_alloc_work(vha, QLA_EVT_IDC_ACK, 1);
2584 if (!e)
2585 return QLA_FUNCTION_FAILED;
2586
2587 memcpy(e->u.idc_ack.mb, mb, QLA_IDC_ACK_REGS * sizeof(uint16_t));
2588 return qla2x00_post_work(vha, e, 1);
2589}
2590
Andrew Vasquez0971de72008-04-03 13:13:18 -07002591static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002592qla2x00_do_work(struct scsi_qla_host *vha)
Andrew Vasquez0971de72008-04-03 13:13:18 -07002593{
2594 struct qla_work_evt *e;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002595 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002596
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002597 spin_lock_irq(&ha->hardware_lock);
2598 while (!list_empty(&vha->work_list)) {
2599 e = list_entry(vha->work_list.next, struct qla_work_evt, list);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002600 list_del_init(&e->list);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002601 spin_unlock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002602
2603 switch (e->type) {
2604 case QLA_EVT_AEN:
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002605 fc_host_post_event(vha->host, fc_get_event_number(),
Andrew Vasquez0971de72008-04-03 13:13:18 -07002606 e->u.aen.code, e->u.aen.data);
2607 break;
Andrew Vasquez8a659572009-02-08 20:50:12 -08002608 case QLA_EVT_IDC_ACK:
2609 qla81xx_idc_ack(vha, e->u.idc_ack.mb);
2610 break;
Andrew Vasquez0971de72008-04-03 13:13:18 -07002611 }
2612 if (e->flags & QLA_EVT_FLAG_FREE)
2613 kfree(e);
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002614 spin_lock_irq(&ha->hardware_lock);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002615 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002616 spin_unlock_irq(&ha->hardware_lock);
2617}
2618/* Relogins all the fcports of a vport
2619 * Context: dpc thread
2620 */
2621void qla2x00_relogin(struct scsi_qla_host *vha)
2622{
2623 fc_port_t *fcport;
Andrew Vasquezc6b2fca2009-03-05 11:07:03 -08002624 int status;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002625 uint16_t next_loopid = 0;
2626 struct qla_hw_data *ha = vha->hw;
2627
2628 list_for_each_entry(fcport, &vha->vp_fcports, list) {
2629 /*
2630 * If the port is not ONLINE then try to login
2631 * to it if we haven't run out of retries.
2632 */
2633 if (atomic_read(&fcport->state) !=
2634 FCS_ONLINE && fcport->login_retry) {
2635
2636 if (fcport->flags & FCF_FABRIC_DEVICE) {
2637 if (fcport->flags & FCF_TAPE_PRESENT)
2638 ha->isp_ops->fabric_logout(vha,
2639 fcport->loop_id,
2640 fcport->d_id.b.domain,
2641 fcport->d_id.b.area,
2642 fcport->d_id.b.al_pa);
2643
2644 status = qla2x00_fabric_login(vha, fcport,
2645 &next_loopid);
2646 } else
2647 status = qla2x00_local_device_login(vha,
2648 fcport);
2649
2650 fcport->login_retry--;
2651 if (status == QLA_SUCCESS) {
2652 fcport->old_loop_id = fcport->loop_id;
2653
2654 DEBUG(printk("scsi(%ld): port login OK: logged "
2655 "in ID 0x%x\n", vha->host_no, fcport->loop_id));
2656
2657 qla2x00_update_fcport(vha, fcport);
2658
2659 } else if (status == 1) {
2660 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2661 /* retry the login again */
2662 DEBUG(printk("scsi(%ld): Retrying"
2663 " %d login again loop_id 0x%x\n",
2664 vha->host_no, fcport->login_retry,
2665 fcport->loop_id));
2666 } else {
2667 fcport->login_retry = 0;
2668 }
2669
2670 if (fcport->login_retry == 0 && status != QLA_SUCCESS)
2671 fcport->loop_id = FC_NO_LOOP_ID;
2672 }
2673 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
2674 break;
2675 }
Andrew Vasquez0971de72008-04-03 13:13:18 -07002676}
2677
Linus Torvalds1da177e2005-04-16 15:20:36 -07002678/**************************************************************************
2679* qla2x00_do_dpc
2680* This kernel thread is a task that is schedule by the interrupt handler
2681* to perform the background processing for interrupts.
2682*
2683* Notes:
2684* This task always run in the context of a kernel thread. It
2685* is kick-off by the driver's detect code and starts up
2686* up one per adapter. It immediately goes to sleep and waits for
2687* some fibre event. When either the interrupt handler or
2688* the timer routine detects a event it will one of the task
2689* bits then wake us up.
2690**************************************************************************/
2691static int
2692qla2x00_do_dpc(void *data)
2693{
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002694 int rval;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002695 scsi_qla_host_t *base_vha;
2696 struct qla_hw_data *ha;
Seokmann Ju99363ef2008-01-31 12:33:51 -08002697
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002698 ha = (struct qla_hw_data *)data;
2699 base_vha = pci_get_drvdata(ha->pdev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002700
Linus Torvalds1da177e2005-04-16 15:20:36 -07002701 set_user_nice(current, -20);
2702
Christoph Hellwig39a11242006-02-14 18:46:22 +01002703 while (!kthread_should_stop()) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002704 DEBUG3(printk("qla2x00: DPC handler sleeping\n"));
2705
Christoph Hellwig39a11242006-02-14 18:46:22 +01002706 set_current_state(TASK_INTERRUPTIBLE);
2707 schedule();
2708 __set_current_state(TASK_RUNNING);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002709
2710 DEBUG3(printk("qla2x00: DPC handler waking up\n"));
2711
2712 /* Initialization not yet finished. Don't do anything yet. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002713 if (!base_vha->flags.init_done)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002714 continue;
2715
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002716 DEBUG3(printk("scsi(%ld): DPC handler\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002717
2718 ha->dpc_active = 1;
2719
Linus Torvalds1da177e2005-04-16 15:20:36 -07002720 if (ha->flags.mbox_busy) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002721 ha->dpc_active = 0;
2722 continue;
2723 }
2724
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002725 qla2x00_do_work(base_vha);
Andrew Vasquez0971de72008-04-03 13:13:18 -07002726
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002727 if (test_and_clear_bit(ISP_ABORT_NEEDED,
2728 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002729
2730 DEBUG(printk("scsi(%ld): dpc: sched "
2731 "qla2x00_abort_isp ha = %p\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002732 base_vha->host_no, ha));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002733 if (!(test_and_set_bit(ABORT_ISP_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002734 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002735
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002736 if (qla2x00_abort_isp(base_vha)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002737 /* failed. retry later */
2738 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002739 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002740 }
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002741 clear_bit(ABORT_ISP_ACTIVE,
2742 &base_vha->dpc_flags);
Seokmann Ju99363ef2008-01-31 12:33:51 -08002743 }
2744
Linus Torvalds1da177e2005-04-16 15:20:36 -07002745 DEBUG(printk("scsi(%ld): dpc: qla2x00_abort_isp end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002746 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002747 }
2748
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002749 if (test_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags)) {
2750 qla2x00_update_fcports(base_vha);
2751 clear_bit(FCPORT_UPDATE_NEEDED, &base_vha->dpc_flags);
Andrew Vasquezc9c5ced2008-07-24 08:31:49 -07002752 }
andrew.vasquez@qlogic.comd97994d2006-01-20 14:53:13 -08002753
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002754 if (test_and_clear_bit(RESET_MARKER_NEEDED,
2755 &base_vha->dpc_flags) &&
2756 (!(test_and_set_bit(RESET_ACTIVE, &base_vha->dpc_flags)))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002757
2758 DEBUG(printk("scsi(%ld): qla2x00_reset_marker()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002759 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002760
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002761 qla2x00_rst_aen(base_vha);
2762 clear_bit(RESET_ACTIVE, &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002763 }
2764
2765 /* Retry each device up to login retry count */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002766 if ((test_and_clear_bit(RELOGIN_NEEDED,
2767 &base_vha->dpc_flags)) &&
2768 !test_bit(LOOP_RESYNC_NEEDED, &base_vha->dpc_flags) &&
2769 atomic_read(&base_vha->loop_state) != LOOP_DOWN) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002770
2771 DEBUG(printk("scsi(%ld): qla2x00_port_login()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002772 base_vha->host_no));
2773 qla2x00_relogin(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002774
Linus Torvalds1da177e2005-04-16 15:20:36 -07002775 DEBUG(printk("scsi(%ld): qla2x00_port_login - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002776 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002777 }
2778
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002779 if (test_and_clear_bit(LOOP_RESYNC_NEEDED,
2780 &base_vha->dpc_flags)) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002781
2782 DEBUG(printk("scsi(%ld): qla2x00_loop_resync()\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002783 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002784
2785 if (!(test_and_set_bit(LOOP_RESYNC_ACTIVE,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002786 &base_vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002787
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002788 rval = qla2x00_loop_resync(base_vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002789
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002790 clear_bit(LOOP_RESYNC_ACTIVE,
2791 &base_vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002792 }
2793
2794 DEBUG(printk("scsi(%ld): qla2x00_loop_resync - end\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002795 base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002796 }
2797
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002798 if (test_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags) &&
2799 atomic_read(&base_vha->loop_state) == LOOP_READY) {
2800 clear_bit(NPIV_CONFIG_NEEDED, &base_vha->dpc_flags);
2801 qla2xxx_flash_npiv_conf(base_vha);
Andrew Vasquez272976c2008-09-11 21:22:50 -07002802 }
2803
Linus Torvalds1da177e2005-04-16 15:20:36 -07002804 if (!ha->interrupts_on)
Andrew Vasquezfd34f552007-07-19 15:06:00 -07002805 ha->isp_ops->enable_intrs(ha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002806
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002807 if (test_and_clear_bit(BEACON_BLINK_NEEDED,
2808 &base_vha->dpc_flags))
2809 ha->isp_ops->beacon_blink(base_vha);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002810
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002811 qla2x00_do_dpc_all_vps(base_vha);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002812
Linus Torvalds1da177e2005-04-16 15:20:36 -07002813 ha->dpc_active = 0;
2814 } /* End of while(1) */
2815
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002816 DEBUG(printk("scsi(%ld): DPC handler exiting\n", base_vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002817
2818 /*
2819 * Make sure that nobody tries to wake us up again.
2820 */
Linus Torvalds1da177e2005-04-16 15:20:36 -07002821 ha->dpc_active = 0;
2822
Christoph Hellwig39a11242006-02-14 18:46:22 +01002823 return 0;
2824}
2825
2826void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002827qla2xxx_wake_dpc(struct scsi_qla_host *vha)
Christoph Hellwig39a11242006-02-14 18:46:22 +01002828{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002829 struct qla_hw_data *ha = vha->hw;
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002830 struct task_struct *t = ha->dpc_thread;
2831
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002832 if (!test_bit(UNLOADING, &vha->dpc_flags) && t)
Andrew Vasquezc795c1e2008-08-13 21:37:01 -07002833 wake_up_process(t);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002834}
2835
2836/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07002837* qla2x00_rst_aen
2838* Processes asynchronous reset.
2839*
2840* Input:
2841* ha = adapter block pointer.
2842*/
2843static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002844qla2x00_rst_aen(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002845{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002846 if (vha->flags.online && !vha->flags.reset_active &&
2847 !atomic_read(&vha->loop_down_timer) &&
2848 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002849 do {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002850 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002851
2852 /*
2853 * Issue marker command only when we are going to start
2854 * the I/O.
2855 */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002856 vha->marker_needed = 1;
2857 } while (!atomic_read(&vha->loop_down_timer) &&
2858 (test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002859 }
2860}
2861
f4f051e2005-04-17 15:02:26 -05002862static void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002863qla2x00_sp_free_dma(srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002864{
2865 struct scsi_cmnd *cmd = sp->cmd;
2866
2867 if (sp->flags & SRB_DMA_VALID) {
FUJITA Tomonori385d70b2007-05-26 01:55:38 +09002868 scsi_dma_unmap(cmd);
f4f051e2005-04-17 15:02:26 -05002869 sp->flags &= ~SRB_DMA_VALID;
2870 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002871 CMD_SP(cmd) = NULL;
f4f051e2005-04-17 15:02:26 -05002872}
2873
2874void
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002875qla2x00_sp_compl(struct qla_hw_data *ha, srb_t *sp)
f4f051e2005-04-17 15:02:26 -05002876{
2877 struct scsi_cmnd *cmd = sp->cmd;
2878
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002879 qla2x00_sp_free_dma(sp);
f4f051e2005-04-17 15:02:26 -05002880
f4f051e2005-04-17 15:02:26 -05002881 mempool_free(sp, ha->srb_mempool);
2882
2883 cmd->scsi_done(cmd);
2884}
bdf79622005-04-17 15:06:53 -05002885
Linus Torvalds1da177e2005-04-16 15:20:36 -07002886/**************************************************************************
2887* qla2x00_timer
2888*
2889* Description:
2890* One second timer
2891*
2892* Context: Interrupt
2893***************************************************************************/
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002894void
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002895qla2x00_timer(scsi_qla_host_t *vha)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002896{
Linus Torvalds1da177e2005-04-16 15:20:36 -07002897 unsigned long cpu_flags = 0;
2898 fc_port_t *fcport;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002899 int start_dpc = 0;
2900 int index;
2901 srb_t *sp;
f4f051e2005-04-17 15:02:26 -05002902 int t;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002903 struct qla_hw_data *ha = vha->hw;
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002904 struct req_que *req;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002905 /*
2906 * Ports - Port down timer.
2907 *
2908 * Whenever, a port is in the LOST state we start decrementing its port
2909 * down timer every second until it reaches zero. Once it reaches zero
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002910 * the port it marked DEAD.
Linus Torvalds1da177e2005-04-16 15:20:36 -07002911 */
2912 t = 0;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002913 list_for_each_entry(fcport, &vha->vp_fcports, list) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002914 if (fcport->port_type != FCT_TARGET)
2915 continue;
2916
2917 if (atomic_read(&fcport->state) == FCS_DEVICE_LOST) {
2918
2919 if (atomic_read(&fcport->port_down_timer) == 0)
2920 continue;
2921
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002922 if (atomic_dec_and_test(&fcport->port_down_timer) != 0)
Linus Torvalds1da177e2005-04-16 15:20:36 -07002923 atomic_set(&fcport->state, FCS_DEVICE_DEAD);
Andrew Vasquezfa2a1ce2005-07-06 10:32:07 -07002924
Linus Torvalds1da177e2005-04-16 15:20:36 -07002925 DEBUG(printk("scsi(%ld): fcport-%d - port retry count: "
Andrew Vasquezfca29702005-07-06 10:31:47 -07002926 "%d remaining\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002927 vha->host_no,
Linus Torvalds1da177e2005-04-16 15:20:36 -07002928 t, atomic_read(&fcport->port_down_timer)));
2929 }
2930 t++;
2931 } /* End of for fcport */
2932
Linus Torvalds1da177e2005-04-16 15:20:36 -07002933
2934 /* Loop down handler. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002935 if (atomic_read(&vha->loop_down_timer) > 0 &&
2936 !(test_bit(ABORT_ISP_ACTIVE, &vha->dpc_flags))
2937 && vha->flags.online) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002938
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002939 if (atomic_read(&vha->loop_down_timer) ==
2940 vha->loop_down_abort_time) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002941
2942 DEBUG(printk("scsi(%ld): Loop Down - aborting the "
2943 "queues before time expire\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002944 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002945
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002946 if (!IS_QLA2100(ha) && vha->link_down_timeout)
2947 atomic_set(&vha->loop_state, LOOP_DEAD);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002948
2949 /* Schedule an ISP abort to return any tape commands. */
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002950 /* NPIV - scan physical port only */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002951 if (!vha->vp_idx) {
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002952 spin_lock_irqsave(&ha->hardware_lock,
2953 cpu_flags);
Anirban Chakraborty73208df2008-12-09 16:45:39 -08002954 req = ha->req_q_map[0];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002955 for (index = 1;
2956 index < MAX_OUTSTANDING_COMMANDS;
2957 index++) {
2958 fc_port_t *sfcp;
bdf79622005-04-17 15:06:53 -05002959
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002960 sp = req->outstanding_cmds[index];
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002961 if (!sp)
2962 continue;
2963 sfcp = sp->fcport;
2964 if (!(sfcp->flags & FCF_TAPE_PRESENT))
2965 continue;
Linus Torvalds1da177e2005-04-16 15:20:36 -07002966
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002967 set_bit(ISP_ABORT_NEEDED,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002968 &vha->dpc_flags);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07002969 break;
2970 }
2971 spin_unlock_irqrestore(&ha->hardware_lock,
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002972 cpu_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002973 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07002974 start_dpc++;
2975 }
2976
2977 /* if the loop has been down for 4 minutes, reinit adapter */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002978 if (atomic_dec_and_test(&vha->loop_down_timer) != 0) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002979 if (!(vha->device_flags & DFLG_NO_CABLE) &&
2980 !vha->vp_idx) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07002981 DEBUG(printk("scsi(%ld): Loop down - "
2982 "aborting ISP.\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002983 vha->host_no));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002984 qla_printk(KERN_WARNING, ha,
2985 "Loop down - aborting ISP.\n");
2986
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002987 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
Linus Torvalds1da177e2005-04-16 15:20:36 -07002988 }
2989 }
Andrew Vasquezfca29702005-07-06 10:31:47 -07002990 DEBUG3(printk("scsi(%ld): Loop Down - seconds remaining %d\n",
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002991 vha->host_no,
2992 atomic_read(&vha->loop_down_timer)));
Linus Torvalds1da177e2005-04-16 15:20:36 -07002993 }
2994
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002995 /* Check if beacon LED needs to be blinked */
2996 if (ha->beacon_blink_led == 1) {
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08002997 set_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags);
andrew.vasquez@qlogic.comf6df1442006-01-31 16:05:07 -08002998 start_dpc++;
2999 }
3000
Andrew Vasquez550bf572008-04-24 15:21:23 -07003001 /* Process any deferred work. */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003002 if (!list_empty(&vha->work_list))
Andrew Vasquez550bf572008-04-24 15:21:23 -07003003 start_dpc++;
3004
Linus Torvalds1da177e2005-04-16 15:20:36 -07003005 /* Schedule the DPC routine if needed */
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003006 if ((test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags) ||
3007 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags) ||
3008 test_bit(FCPORT_UPDATE_NEEDED, &vha->dpc_flags) ||
Linus Torvalds1da177e2005-04-16 15:20:36 -07003009 start_dpc ||
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003010 test_bit(RESET_MARKER_NEEDED, &vha->dpc_flags) ||
3011 test_bit(BEACON_BLINK_NEEDED, &vha->dpc_flags) ||
3012 test_bit(VP_DPC_NEEDED, &vha->dpc_flags) ||
3013 test_bit(RELOGIN_NEEDED, &vha->dpc_flags)))
3014 qla2xxx_wake_dpc(vha);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003015
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003016 qla2x00_restart_timer(vha, WATCH_INTERVAL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003017}
3018
Andrew Vasquez54333832005-11-09 15:49:04 -08003019/* Firmware interface routines. */
3020
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003021#define FW_BLOBS 7
Andrew Vasquez54333832005-11-09 15:49:04 -08003022#define FW_ISP21XX 0
3023#define FW_ISP22XX 1
3024#define FW_ISP2300 2
3025#define FW_ISP2322 3
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003026#define FW_ISP24XX 4
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003027#define FW_ISP25XX 5
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003028#define FW_ISP81XX 6
Andrew Vasquez54333832005-11-09 15:49:04 -08003029
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003030#define FW_FILE_ISP21XX "ql2100_fw.bin"
3031#define FW_FILE_ISP22XX "ql2200_fw.bin"
3032#define FW_FILE_ISP2300 "ql2300_fw.bin"
3033#define FW_FILE_ISP2322 "ql2322_fw.bin"
3034#define FW_FILE_ISP24XX "ql2400_fw.bin"
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003035#define FW_FILE_ISP25XX "ql2500_fw.bin"
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003036#define FW_FILE_ISP81XX "ql8100_fw.bin"
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003037
Daniel Walkere1e82b62008-05-12 22:21:10 -07003038static DEFINE_MUTEX(qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003039
3040static struct fw_blob qla_fw_blobs[FW_BLOBS] = {
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003041 { .name = FW_FILE_ISP21XX, .segs = { 0x1000, 0 }, },
3042 { .name = FW_FILE_ISP22XX, .segs = { 0x1000, 0 }, },
3043 { .name = FW_FILE_ISP2300, .segs = { 0x800, 0 }, },
3044 { .name = FW_FILE_ISP2322, .segs = { 0x800, 0x1c000, 0x1e000, 0 }, },
3045 { .name = FW_FILE_ISP24XX, },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003046 { .name = FW_FILE_ISP25XX, },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003047 { .name = FW_FILE_ISP81XX, },
Andrew Vasquez54333832005-11-09 15:49:04 -08003048};
3049
3050struct fw_blob *
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003051qla2x00_request_firmware(scsi_qla_host_t *vha)
Andrew Vasquez54333832005-11-09 15:49:04 -08003052{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003053 struct qla_hw_data *ha = vha->hw;
Andrew Vasquez54333832005-11-09 15:49:04 -08003054 struct fw_blob *blob;
3055
3056 blob = NULL;
3057 if (IS_QLA2100(ha)) {
3058 blob = &qla_fw_blobs[FW_ISP21XX];
3059 } else if (IS_QLA2200(ha)) {
3060 blob = &qla_fw_blobs[FW_ISP22XX];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003061 } else if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003062 blob = &qla_fw_blobs[FW_ISP2300];
andrew.vasquez@qlogic.com48c02fd2006-03-09 14:27:18 -08003063 } else if (IS_QLA2322(ha) || IS_QLA6322(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003064 blob = &qla_fw_blobs[FW_ISP2322];
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003065 } else if (IS_QLA24XX_TYPE(ha)) {
Andrew Vasquez54333832005-11-09 15:49:04 -08003066 blob = &qla_fw_blobs[FW_ISP24XX];
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003067 } else if (IS_QLA25XX(ha)) {
3068 blob = &qla_fw_blobs[FW_ISP25XX];
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003069 } else if (IS_QLA81XX(ha)) {
3070 blob = &qla_fw_blobs[FW_ISP81XX];
Andrew Vasquez54333832005-11-09 15:49:04 -08003071 }
3072
Daniel Walkere1e82b62008-05-12 22:21:10 -07003073 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003074 if (blob->fw)
3075 goto out;
3076
3077 if (request_firmware(&blob->fw, blob->name, &ha->pdev->dev)) {
3078 DEBUG2(printk("scsi(%ld): Failed to load firmware image "
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003079 "(%s).\n", vha->host_no, blob->name));
Andrew Vasquez54333832005-11-09 15:49:04 -08003080 blob->fw = NULL;
3081 blob = NULL;
3082 goto out;
3083 }
3084
3085out:
Daniel Walkere1e82b62008-05-12 22:21:10 -07003086 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003087 return blob;
3088}
3089
3090static void
3091qla2x00_release_firmware(void)
3092{
3093 int idx;
3094
Daniel Walkere1e82b62008-05-12 22:21:10 -07003095 mutex_lock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003096 for (idx = 0; idx < FW_BLOBS; idx++)
3097 if (qla_fw_blobs[idx].fw)
3098 release_firmware(qla_fw_blobs[idx].fw);
Daniel Walkere1e82b62008-05-12 22:21:10 -07003099 mutex_unlock(&qla_fw_lock);
Andrew Vasquez54333832005-11-09 15:49:04 -08003100}
3101
Seokmann Ju14e660e2007-09-20 14:07:36 -07003102static pci_ers_result_t
3103qla2xxx_pci_error_detected(struct pci_dev *pdev, pci_channel_state_t state)
3104{
Seokmann Jub9b12f72009-03-24 09:08:18 -07003105 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3106
Seokmann Ju14e660e2007-09-20 14:07:36 -07003107 switch (state) {
3108 case pci_channel_io_normal:
3109 return PCI_ERS_RESULT_CAN_RECOVER;
3110 case pci_channel_io_frozen:
3111 pci_disable_device(pdev);
3112 return PCI_ERS_RESULT_NEED_RESET;
3113 case pci_channel_io_perm_failure:
Seokmann Jub9b12f72009-03-24 09:08:18 -07003114 qla2x00_abort_all_cmds(base_vha, DID_NO_CONNECT << 16);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003115 return PCI_ERS_RESULT_DISCONNECT;
3116 }
3117 return PCI_ERS_RESULT_NEED_RESET;
3118}
3119
3120static pci_ers_result_t
3121qla2xxx_pci_mmio_enabled(struct pci_dev *pdev)
3122{
3123 int risc_paused = 0;
3124 uint32_t stat;
3125 unsigned long flags;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003126 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3127 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003128 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3129 struct device_reg_24xx __iomem *reg24 = &ha->iobase->isp24;
3130
3131 spin_lock_irqsave(&ha->hardware_lock, flags);
3132 if (IS_QLA2100(ha) || IS_QLA2200(ha)){
3133 stat = RD_REG_DWORD(&reg->hccr);
3134 if (stat & HCCR_RISC_PAUSE)
3135 risc_paused = 1;
3136 } else if (IS_QLA23XX(ha)) {
3137 stat = RD_REG_DWORD(&reg->u.isp2300.host_status);
3138 if (stat & HSR_RISC_PAUSED)
3139 risc_paused = 1;
3140 } else if (IS_FWI2_CAPABLE(ha)) {
3141 stat = RD_REG_DWORD(&reg24->host_status);
3142 if (stat & HSRX_RISC_PAUSED)
3143 risc_paused = 1;
3144 }
3145 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3146
3147 if (risc_paused) {
3148 qla_printk(KERN_INFO, ha, "RISC paused -- mmio_enabled, "
3149 "Dumping firmware!\n");
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003150 ha->isp_ops->fw_dump(base_vha, 0);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003151
3152 return PCI_ERS_RESULT_NEED_RESET;
3153 } else
3154 return PCI_ERS_RESULT_RECOVERED;
3155}
3156
3157static pci_ers_result_t
3158qla2xxx_pci_slot_reset(struct pci_dev *pdev)
3159{
3160 pci_ers_result_t ret = PCI_ERS_RESULT_DISCONNECT;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003161 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3162 struct qla_hw_data *ha = base_vha->hw;
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003163 int rc;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003164
Benjamin Herrenschmidt09483912007-12-20 15:28:09 +11003165 if (ha->mem_only)
3166 rc = pci_enable_device_mem(pdev);
3167 else
3168 rc = pci_enable_device(pdev);
3169
3170 if (rc) {
Seokmann Ju14e660e2007-09-20 14:07:36 -07003171 qla_printk(KERN_WARNING, ha,
3172 "Can't re-enable PCI device after reset.\n");
3173
3174 return ret;
3175 }
3176 pci_set_master(pdev);
3177
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003178 if (ha->isp_ops->pci_config(base_vha))
Seokmann Ju14e660e2007-09-20 14:07:36 -07003179 return ret;
3180
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003181 set_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
3182 if (qla2x00_abort_isp(base_vha) == QLA_SUCCESS)
Seokmann Ju14e660e2007-09-20 14:07:36 -07003183 ret = PCI_ERS_RESULT_RECOVERED;
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003184 clear_bit(ABORT_ISP_ACTIVE, &base_vha->dpc_flags);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003185
3186 return ret;
3187}
3188
3189static void
3190qla2xxx_pci_resume(struct pci_dev *pdev)
3191{
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003192 scsi_qla_host_t *base_vha = pci_get_drvdata(pdev);
3193 struct qla_hw_data *ha = base_vha->hw;
Seokmann Ju14e660e2007-09-20 14:07:36 -07003194 int ret;
3195
Anirban Chakrabortye315cd22008-11-06 10:40:51 -08003196 ret = qla2x00_wait_for_hba_online(base_vha);
Seokmann Ju14e660e2007-09-20 14:07:36 -07003197 if (ret != QLA_SUCCESS) {
3198 qla_printk(KERN_ERR, ha,
3199 "the device failed to resume I/O "
3200 "from slot/link_reset");
3201 }
3202 pci_cleanup_aer_uncorrect_error_status(pdev);
3203}
3204
3205static struct pci_error_handlers qla2xxx_err_handler = {
3206 .error_detected = qla2xxx_pci_error_detected,
3207 .mmio_enabled = qla2xxx_pci_mmio_enabled,
3208 .slot_reset = qla2xxx_pci_slot_reset,
3209 .resume = qla2xxx_pci_resume,
3210};
3211
Andrew Vasquez54333832005-11-09 15:49:04 -08003212static struct pci_device_id qla2xxx_pci_tbl[] = {
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003213 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2100) },
3214 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2200) },
3215 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2300) },
3216 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2312) },
3217 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2322) },
3218 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6312) },
3219 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP6322) },
3220 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2422) },
3221 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2432) },
Harihara Kadayam4d4df192008-04-03 13:13:26 -07003222 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8432) },
Andrew Vasquez47f5e062006-05-17 15:09:39 -07003223 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5422) },
3224 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP5432) },
Andrew Vasquezc3a2f0d2007-07-19 20:37:34 -07003225 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP2532) },
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003226 { PCI_DEVICE(PCI_VENDOR_ID_QLOGIC, PCI_DEVICE_ID_QLOGIC_ISP8001) },
Andrew Vasquez54333832005-11-09 15:49:04 -08003227 { 0 },
3228};
3229MODULE_DEVICE_TABLE(pci, qla2xxx_pci_tbl);
3230
Andrew Vasquezfca29702005-07-06 10:31:47 -07003231static struct pci_driver qla2xxx_pci_driver = {
Andrew Vasquezcb630672006-05-17 15:09:45 -07003232 .name = QLA2XXX_DRIVER_NAME,
James Bottomley0a21ef12005-12-01 12:51:50 -06003233 .driver = {
3234 .owner = THIS_MODULE,
3235 },
Andrew Vasquezfca29702005-07-06 10:31:47 -07003236 .id_table = qla2xxx_pci_tbl,
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003237 .probe = qla2x00_probe_one,
Adrian Bunk4c993f72008-01-14 00:55:16 -08003238 .remove = qla2x00_remove_one,
Seokmann Ju14e660e2007-09-20 14:07:36 -07003239 .err_handler = &qla2xxx_err_handler,
Andrew Vasquezfca29702005-07-06 10:31:47 -07003240};
3241
Linus Torvalds1da177e2005-04-16 15:20:36 -07003242/**
3243 * qla2x00_module_init - Module initialization.
3244 **/
3245static int __init
3246qla2x00_module_init(void)
3247{
Andrew Vasquezfca29702005-07-06 10:31:47 -07003248 int ret = 0;
3249
Linus Torvalds1da177e2005-04-16 15:20:36 -07003250 /* Allocate cache for SRBs. */
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003251 srb_cachep = kmem_cache_create("qla2xxx_srbs", sizeof(srb_t), 0,
Paul Mundt20c2df82007-07-20 10:11:58 +09003252 SLAB_HWCACHE_ALIGN, NULL);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003253 if (srb_cachep == NULL) {
3254 printk(KERN_ERR
3255 "qla2xxx: Unable to allocate SRB cache...Failing load!\n");
3256 return -ENOMEM;
3257 }
3258
3259 /* Derive version string. */
3260 strcpy(qla2x00_version_str, QLA2XXX_VERSION);
Andrew Vasquez11010fe2006-10-06 09:54:59 -07003261 if (ql2xextended_error_logging)
Andrew Vasquez01819442006-06-23 16:11:10 -07003262 strcat(qla2x00_version_str, "-debug");
3263
Andrew Vasquez1c97a122005-04-21 16:13:36 -04003264 qla2xxx_transport_template =
3265 fc_attach_transport(&qla2xxx_transport_functions);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003266 if (!qla2xxx_transport_template) {
3267 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003268 return -ENODEV;
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003269 }
3270 qla2xxx_transport_vport_template =
3271 fc_attach_transport(&qla2xxx_transport_vport_functions);
3272 if (!qla2xxx_transport_vport_template) {
3273 kmem_cache_destroy(srb_cachep);
3274 fc_release_transport(qla2xxx_transport_template);
3275 return -ENODEV;
3276 }
Linus Torvalds1da177e2005-04-16 15:20:36 -07003277
Andrew Vasquezfd9a29f02008-05-12 22:21:08 -07003278 printk(KERN_INFO "QLogic Fibre Channel HBA Driver: %s\n",
3279 qla2x00_version_str);
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003280 ret = pci_register_driver(&qla2xxx_pci_driver);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003281 if (ret) {
3282 kmem_cache_destroy(srb_cachep);
3283 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003284 fc_release_transport(qla2xxx_transport_vport_template);
Andrew Vasquezfca29702005-07-06 10:31:47 -07003285 }
3286 return ret;
Linus Torvalds1da177e2005-04-16 15:20:36 -07003287}
3288
3289/**
3290 * qla2x00_module_exit - Module cleanup.
3291 **/
3292static void __exit
3293qla2x00_module_exit(void)
3294{
Andrew Vasquez7ee61392006-06-23 16:11:22 -07003295 pci_unregister_driver(&qla2xxx_pci_driver);
Andrew Vasquez54333832005-11-09 15:49:04 -08003296 qla2x00_release_firmware();
Andrew Vasquez 354d6b22005-04-23 02:47:27 -04003297 kmem_cache_destroy(srb_cachep);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003298 fc_release_transport(qla2xxx_transport_template);
Seokmann Ju2c3dfe32007-07-05 13:16:51 -07003299 fc_release_transport(qla2xxx_transport_vport_template);
Linus Torvalds1da177e2005-04-16 15:20:36 -07003300}
3301
3302module_init(qla2x00_module_init);
3303module_exit(qla2x00_module_exit);
3304
3305MODULE_AUTHOR("QLogic Corporation");
3306MODULE_DESCRIPTION("QLogic Fibre Channel HBA Driver");
3307MODULE_LICENSE("GPL");
3308MODULE_VERSION(QLA2XXX_VERSION);
Andrew Vasquezbb8ee492006-10-02 12:00:48 -07003309MODULE_FIRMWARE(FW_FILE_ISP21XX);
3310MODULE_FIRMWARE(FW_FILE_ISP22XX);
3311MODULE_FIRMWARE(FW_FILE_ISP2300);
3312MODULE_FIRMWARE(FW_FILE_ISP2322);
3313MODULE_FIRMWARE(FW_FILE_ISP24XX);
Andrew Vasquez61623fc2008-01-31 12:33:45 -08003314MODULE_FIRMWARE(FW_FILE_ISP25XX);
Andrew Vasquez3a03eb72009-01-05 11:18:11 -08003315MODULE_FIRMWARE(FW_FILE_ISP81XX);